feat: add 100+ official TPMJS tools
Implements a comprehensive suite of AI SDK v6 tools across multiple categories: - Research (5): page-brief, compare-pages, source-credibility, claim-checklist, timeline-from-text - Web (10): fetch-text, links-catalog, extract-meta, extract-json-ld, redirect-trace, sitemap-read, rss-read, table-extract, robots-policy, url-normalize - Data (15): csv-parse, csv-stringify, json-repair, json-schema-validate, yaml-parse, yaml-stringify, text-chunk, normalize-whitespace, dedupe-by-key, pivot, rows-filter, rows-sort, rows-group-aggregate, rows-join, schema-infer - Doc (12): toc-generate, glossary-build, faq-from-text, executive-brief, decision-record-adr, prd-outline, acceptance-criteria, style-rewrite - Eng (12): diff-text-unified, env-var-docs-generate, dependency-audit-lite, conventional-commit-suggest, markdown-lint-basic, test-case-generate, stacktrace-parse, release-notes, changelog-entry, release-checklist - Security (7): redact-secrets, secret-scan-text, url-risk-heuristic, csp-compose, hardening-checklist-web, access-control-matrix, data-classification-heuristic - Stats (9): effect-size-suite, bootstrap-ci, permutation-test, multiple-testing-adjust, linear-regression-ols, logistic-regression, time-series-decompose-lite, anomaly-detect-mad - Ops (7): slo-draft, runbook-draft, postmortem-draft, postmortem-action-extractor, error-log-triage, coverage-tracker, monitoring-gap-analysis - Agent (15): prompt-to-workflow-skeleton, workflow-validate-io, workflow-explain, workflow-cost-estimate, tool-call-accuracy-score, eval-fixture-build, guardrail-policy-draft, workflow-auto-repair, tool-selection-plan, novelty-score-workflow, workflow-variant-generate, config-normalize, recipe-* - Utility (8): base64-encode, base64-decode, hash-text, regex-extract, template-render, date-parse, json-path-query, url-parse - HTML (3): html-sanitize, html-to-markdown, markdown-to-html All tools follow AI SDK v6 pattern with tool() and jsonSchema<T>(). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
2d9b06020d
commit
5d2096fb5d
499 changed files with 50782 additions and 238 deletions
173
packages/tools/official/config-normalize/README.md
Normal file
173
packages/tools/official/config-normalize/README.md
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
# @tpmjs/tools-config-normalize
|
||||
|
||||
Normalizes configuration objects by sorting keys, removing nulls, and cleaning empty values.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install @tpmjs/tools-config-normalize
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```typescript
|
||||
import { configNormalize } from '@tpmjs/tools-config-normalize';
|
||||
import { generateText } from 'ai';
|
||||
|
||||
const result = await generateText({
|
||||
model: yourModel,
|
||||
tools: { configNormalize },
|
||||
prompt: 'Normalize this config object: ...',
|
||||
});
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Sorts object keys alphabetically for consistent ordering
|
||||
- Removes null and undefined values
|
||||
- Removes empty objects and empty arrays
|
||||
- Recursively processes nested structures
|
||||
- Tracks all changes made during normalization
|
||||
- Provides before/after key counts
|
||||
|
||||
## Input
|
||||
|
||||
- `config` (object): The configuration object to normalize
|
||||
- `options` (object, optional): Normalization options
|
||||
- `sortKeys` (boolean, default: true): Sort object keys alphabetically
|
||||
- `removeNulls` (boolean, default: true): Remove null and undefined values
|
||||
- `removeEmpty` (boolean, default: true): Remove empty objects and arrays
|
||||
|
||||
## Output
|
||||
|
||||
Returns an object with:
|
||||
|
||||
- `normalized` (object): The normalized configuration object
|
||||
- `changes` (array): List of changes made during normalization
|
||||
- `type`: 'removed' | 'sorted' | 'cleaned'
|
||||
- `path`: Path to the changed property (e.g., "database.options")
|
||||
- `reason`: Human-readable explanation
|
||||
- `oldValue`: The original value (for removals)
|
||||
- `keyCount` (number): Total keys in normalized config
|
||||
- `originalKeyCount` (number): Total keys in original config
|
||||
|
||||
## Example
|
||||
|
||||
```typescript
|
||||
const config = {
|
||||
name: "my-app",
|
||||
version: null,
|
||||
database: {
|
||||
port: 5432,
|
||||
host: "localhost",
|
||||
options: {}
|
||||
},
|
||||
cache: {
|
||||
enabled: true,
|
||||
ttl: undefined
|
||||
},
|
||||
features: []
|
||||
};
|
||||
|
||||
const result = await configNormalize.execute({ config });
|
||||
|
||||
console.log(result.normalized);
|
||||
// {
|
||||
// cache: {
|
||||
// enabled: true
|
||||
// },
|
||||
// database: {
|
||||
// host: "localhost",
|
||||
// port: 5432
|
||||
// },
|
||||
// name: "my-app"
|
||||
// }
|
||||
|
||||
console.log(result.changes);
|
||||
// [
|
||||
// {
|
||||
// type: 'removed',
|
||||
// path: 'version',
|
||||
// reason: 'null value',
|
||||
// oldValue: null
|
||||
// },
|
||||
// {
|
||||
// type: 'removed',
|
||||
// path: 'database.options',
|
||||
// reason: 'empty object',
|
||||
// oldValue: {}
|
||||
// },
|
||||
// {
|
||||
// type: 'removed',
|
||||
// path: 'cache.ttl',
|
||||
// reason: 'undefined value',
|
||||
// oldValue: undefined
|
||||
// },
|
||||
// {
|
||||
// type: 'removed',
|
||||
// path: 'features',
|
||||
// reason: 'empty array',
|
||||
// oldValue: []
|
||||
// },
|
||||
// {
|
||||
// type: 'sorted',
|
||||
// path: 'root',
|
||||
// reason: 'keys sorted alphabetically'
|
||||
// }
|
||||
// ]
|
||||
|
||||
console.log(result.keyCount); // 4
|
||||
console.log(result.originalKeyCount); // 9
|
||||
```
|
||||
|
||||
## Custom Options
|
||||
|
||||
```typescript
|
||||
// Only sort keys, don't remove anything
|
||||
const result = await configNormalize.execute({
|
||||
config,
|
||||
options: {
|
||||
sortKeys: true,
|
||||
removeNulls: false,
|
||||
removeEmpty: false
|
||||
}
|
||||
});
|
||||
|
||||
// Remove nulls but keep empty objects/arrays
|
||||
const result = await configNormalize.execute({
|
||||
config,
|
||||
options: {
|
||||
sortKeys: true,
|
||||
removeNulls: true,
|
||||
removeEmpty: false
|
||||
}
|
||||
});
|
||||
|
||||
// Don't sort, just clean
|
||||
const result = await configNormalize.execute({
|
||||
config,
|
||||
options: {
|
||||
sortKeys: false,
|
||||
removeNulls: true,
|
||||
removeEmpty: true
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Use Cases
|
||||
|
||||
- Cleaning up generated configuration files
|
||||
- Normalizing user-provided config for comparison
|
||||
- Preparing config for version control (consistent key ordering)
|
||||
- Removing test/debug values before deployment
|
||||
- Standardizing API responses
|
||||
|
||||
## Change Types
|
||||
|
||||
- **removed**: A key was removed due to null/undefined/empty value
|
||||
- **sorted**: Keys in an object were reordered alphabetically
|
||||
- **cleaned**: A nested structure became empty after normalization and was removed
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
66
packages/tools/official/config-normalize/package.json
Normal file
66
packages/tools/official/config-normalize/package.json
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
"name": "@tpmjs/tools-config-normalize",
|
||||
"version": "0.1.0",
|
||||
"description": "Normalizes configuration objects by sorting keys, removing nulls, and cleaning empty values",
|
||||
"type": "module",
|
||||
"keywords": ["tpmjs", "engineering", "ai", "config", "normalization"],
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"files": ["dist"],
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"dev": "tsup --watch",
|
||||
"type-check": "tsc --noEmit",
|
||||
"clean": "rm -rf dist .turbo"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tpmjs/tsconfig": "workspace:*",
|
||||
"tsup": "^8.3.5",
|
||||
"typescript": "^5.9.3"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/anthropics/tpmjs.git",
|
||||
"directory": "packages/tools/official/config-normalize"
|
||||
},
|
||||
"homepage": "https://tpmjs.com",
|
||||
"license": "MIT",
|
||||
"tpmjs": {
|
||||
"category": "engineering",
|
||||
"frameworks": ["vercel-ai"],
|
||||
"tools": [
|
||||
{
|
||||
"name": "configNormalize",
|
||||
"description": "Normalizes configuration objects by sorting keys, removing nulls, and cleaning empty values",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "config",
|
||||
"type": "object",
|
||||
"description": "The configuration object to normalize",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "options",
|
||||
"type": "object",
|
||||
"description": "Normalization options (sortKeys, removeNulls, removeEmpty)",
|
||||
"required": false
|
||||
}
|
||||
],
|
||||
"returns": {
|
||||
"type": "ConfigNormalizeResult",
|
||||
"description": "Object with normalized config, changes array, and key count"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"ai": "6.0.0-beta.124"
|
||||
}
|
||||
}
|
||||
300
packages/tools/official/config-normalize/src/index.ts
Normal file
300
packages/tools/official/config-normalize/src/index.ts
Normal file
|
|
@ -0,0 +1,300 @@
|
|||
/**
|
||||
* Config Normalize Tool for TPMJS
|
||||
* Normalizes configuration objects by sorting keys, removing null/undefined values,
|
||||
* removing empty objects/arrays, and tracking changes made during normalization.
|
||||
*/
|
||||
|
||||
import { jsonSchema, tool } from 'ai';
|
||||
|
||||
/**
|
||||
* Represents a change made during normalization
|
||||
*/
|
||||
export interface ConfigChange {
|
||||
type: 'removed' | 'sorted' | 'cleaned';
|
||||
path: string;
|
||||
reason: string;
|
||||
oldValue?: unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for configuration normalization
|
||||
*/
|
||||
export interface NormalizeOptions {
|
||||
sortKeys?: boolean;
|
||||
removeNulls?: boolean;
|
||||
removeEmpty?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output interface for config normalization
|
||||
*/
|
||||
export interface ConfigNormalizeResult {
|
||||
normalized: Record<string, unknown>;
|
||||
changes: ConfigChange[];
|
||||
keyCount: number;
|
||||
originalKeyCount: number;
|
||||
}
|
||||
|
||||
type ConfigNormalizeInput = {
|
||||
config: Record<string, unknown>;
|
||||
options?: NormalizeOptions;
|
||||
};
|
||||
|
||||
/**
|
||||
* Default normalization options
|
||||
*/
|
||||
const DEFAULT_OPTIONS: Required<NormalizeOptions> = {
|
||||
sortKeys: true,
|
||||
removeNulls: true,
|
||||
removeEmpty: true,
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if a value is null or undefined
|
||||
*/
|
||||
function isNullOrUndefined(value: unknown): value is null | undefined {
|
||||
return value === null || value === undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a value is an empty object
|
||||
*/
|
||||
function isEmptyObject(value: unknown): boolean {
|
||||
return (
|
||||
typeof value === 'object' &&
|
||||
value !== null &&
|
||||
!Array.isArray(value) &&
|
||||
Object.keys(value).length === 0
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a value is an empty array
|
||||
*/
|
||||
function isEmptyArray(value: unknown): boolean {
|
||||
return Array.isArray(value) && value.length === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a value should be considered empty based on options
|
||||
*/
|
||||
function isEmpty(value: unknown, options: Required<NormalizeOptions>): boolean {
|
||||
if (options.removeNulls && isNullOrUndefined(value)) {
|
||||
return true;
|
||||
}
|
||||
if (options.removeEmpty) {
|
||||
return isEmptyObject(value) || isEmptyArray(value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the reason why a value is being removed
|
||||
*/
|
||||
function getRemovalReason(value: unknown): string {
|
||||
if (value === null) return 'null value';
|
||||
if (value === undefined) return 'undefined value';
|
||||
if (isEmptyObject(value)) return 'empty object';
|
||||
if (isEmptyArray(value)) return 'empty array';
|
||||
return 'empty value';
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts total keys in a nested object
|
||||
*/
|
||||
function countKeys(obj: unknown): number {
|
||||
if (typeof obj !== 'object' || obj === null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let count = 0;
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
for (const item of obj) {
|
||||
count += countKeys(item);
|
||||
}
|
||||
} else {
|
||||
const keys = Object.keys(obj);
|
||||
count += keys.length;
|
||||
|
||||
for (const key of keys) {
|
||||
count += countKeys((obj as Record<string, unknown>)[key]);
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a configuration object recursively
|
||||
*/
|
||||
function normalizeConfig(
|
||||
config: unknown,
|
||||
options: Required<NormalizeOptions>,
|
||||
changes: ConfigChange[],
|
||||
path = ''
|
||||
): unknown {
|
||||
// Handle null/undefined
|
||||
if (isNullOrUndefined(config)) {
|
||||
return config;
|
||||
}
|
||||
|
||||
// Handle arrays
|
||||
if (Array.isArray(config)) {
|
||||
const normalized: unknown[] = [];
|
||||
|
||||
for (let i = 0; i < config.length; i++) {
|
||||
const item = config[i];
|
||||
const itemPath = `${path}[${i}]`;
|
||||
|
||||
if (isEmpty(item, options)) {
|
||||
changes.push({
|
||||
type: 'removed',
|
||||
path: itemPath,
|
||||
reason: getRemovalReason(item),
|
||||
oldValue: item,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
normalized.push(normalizeConfig(item, options, changes, itemPath));
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
// Handle objects
|
||||
if (typeof config === 'object') {
|
||||
const obj = config as Record<string, unknown>;
|
||||
const keys = Object.keys(obj);
|
||||
|
||||
// Sort keys if requested
|
||||
const sortedKeys = options.sortKeys ? keys.sort() : keys;
|
||||
|
||||
// Track if keys were reordered
|
||||
if (options.sortKeys && keys.length > 1) {
|
||||
const wasReordered = sortedKeys.some((key, index) => keys[index] !== key);
|
||||
if (wasReordered) {
|
||||
changes.push({
|
||||
type: 'sorted',
|
||||
path: path || 'root',
|
||||
reason: 'keys sorted alphabetically',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const normalized: Record<string, unknown> = {};
|
||||
|
||||
for (const key of sortedKeys) {
|
||||
const value = obj[key];
|
||||
const valuePath = path ? `${path}.${key}` : key;
|
||||
|
||||
// Remove empty values if requested
|
||||
if (isEmpty(value, options)) {
|
||||
changes.push({
|
||||
type: 'removed',
|
||||
path: valuePath,
|
||||
reason: getRemovalReason(value),
|
||||
oldValue: value,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
// Recursively normalize nested objects
|
||||
const normalizedValue = normalizeConfig(value, options, changes, valuePath);
|
||||
|
||||
// After normalization, check again if it became empty
|
||||
if (isEmpty(normalizedValue, options)) {
|
||||
changes.push({
|
||||
type: 'cleaned',
|
||||
path: valuePath,
|
||||
reason: 'became empty after normalization',
|
||||
oldValue: value,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
normalized[key] = normalizedValue;
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
// Return primitives as-is
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Config Normalize Tool
|
||||
* Normalizes configuration objects with various options
|
||||
*/
|
||||
export const configNormalize = tool({
|
||||
description:
|
||||
'Normalize configuration objects by sorting keys alphabetically, removing null/undefined values, and removing empty objects/arrays. Returns the normalized config along with a list of changes made and key counts.',
|
||||
inputSchema: jsonSchema<ConfigNormalizeInput>({
|
||||
type: 'object',
|
||||
properties: {
|
||||
config: {
|
||||
type: 'object',
|
||||
description: 'The configuration object to normalize',
|
||||
},
|
||||
options: {
|
||||
type: 'object',
|
||||
description: 'Normalization options',
|
||||
properties: {
|
||||
sortKeys: {
|
||||
type: 'boolean',
|
||||
description: 'Sort object keys alphabetically (default: true)',
|
||||
},
|
||||
removeNulls: {
|
||||
type: 'boolean',
|
||||
description: 'Remove null and undefined values (default: true)',
|
||||
},
|
||||
removeEmpty: {
|
||||
type: 'boolean',
|
||||
description: 'Remove empty objects and arrays (default: true)',
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
},
|
||||
required: ['config'],
|
||||
additionalProperties: false,
|
||||
}),
|
||||
async execute({ config, options = {} }): Promise<ConfigNormalizeResult> {
|
||||
// Validate input
|
||||
if (!config || typeof config !== 'object' || Array.isArray(config)) {
|
||||
throw new Error('config must be a non-null object (not an array)');
|
||||
}
|
||||
|
||||
// Merge with default options
|
||||
const normalizeOptions: Required<NormalizeOptions> = {
|
||||
...DEFAULT_OPTIONS,
|
||||
...options,
|
||||
};
|
||||
|
||||
// Count original keys
|
||||
const originalKeyCount = countKeys(config);
|
||||
|
||||
// Track changes
|
||||
const changes: ConfigChange[] = [];
|
||||
|
||||
// Normalize the config
|
||||
const normalized = normalizeConfig(config, normalizeOptions, changes) as Record<
|
||||
string,
|
||||
unknown
|
||||
>;
|
||||
|
||||
// Count normalized keys
|
||||
const keyCount = countKeys(normalized);
|
||||
|
||||
return {
|
||||
normalized,
|
||||
changes,
|
||||
keyCount,
|
||||
originalKeyCount,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default configNormalize;
|
||||
11
packages/tools/official/config-normalize/tsconfig.json
Normal file
11
packages/tools/official/config-normalize/tsconfig.json
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"extends": "@tpmjs/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"incremental": false,
|
||||
"composite": false
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
10
packages/tools/official/config-normalize/tsup.config.ts
Normal file
10
packages/tools/official/config-normalize/tsup.config.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { defineConfig } from 'tsup';
|
||||
|
||||
export default defineConfig({
|
||||
entry: ['src/index.ts'],
|
||||
format: ['esm'],
|
||||
dts: true,
|
||||
clean: true,
|
||||
treeshake: true,
|
||||
splitting: false,
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue