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
80
packages/tools/official/diff-text-unified/README.md
Normal file
80
packages/tools/official/diff-text-unified/README.md
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
# @tpmjs/tools-diff-text-unified
|
||||
|
||||
Creates unified diff between two text strings with context lines.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install @tpmjs/tools-diff-text-unified
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```typescript
|
||||
import { diffTextUnified } from '@tpmjs/tools-diff-text-unified';
|
||||
import { generateText } from 'ai';
|
||||
|
||||
const result = await generateText({
|
||||
model: yourModel,
|
||||
tools: {
|
||||
diffTextUnified,
|
||||
},
|
||||
prompt: 'Compare these two versions and show me what changed',
|
||||
});
|
||||
```
|
||||
|
||||
## Tool Details
|
||||
|
||||
### diffTextUnified
|
||||
|
||||
Creates a unified diff between two text strings, showing additions, deletions, and context lines.
|
||||
|
||||
**Parameters:**
|
||||
|
||||
- `original` (string, required) - The original text to compare from
|
||||
- `modified` (string, required) - The modified text to compare to
|
||||
- `contextLines` (number, optional) - Number of context lines to show around changes (default: 3)
|
||||
|
||||
**Returns:**
|
||||
|
||||
```typescript
|
||||
{
|
||||
diff: string; // The unified diff string
|
||||
additions: number; // Number of lines added
|
||||
deletions: number; // Number of lines deleted
|
||||
changes: number; // Total changes (additions + deletions)
|
||||
hasChanges: boolean; // Whether any changes were detected
|
||||
summary: string; // Human-readable summary
|
||||
}
|
||||
```
|
||||
|
||||
## Example Output
|
||||
|
||||
```typescript
|
||||
{
|
||||
diff: `--- original
|
||||
+++ modified
|
||||
@@ -1,3 +1,3 @@
|
||||
function hello() {
|
||||
- console.log('Hello');
|
||||
+ console.log('Hello, World!');
|
||||
}`,
|
||||
additions: 1,
|
||||
deletions: 1,
|
||||
changes: 2,
|
||||
hasChanges: true,
|
||||
summary: "1 addition, 1 deletion"
|
||||
}
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Creates standard unified diff format
|
||||
- Configurable context lines
|
||||
- Counts additions and deletions
|
||||
- Provides human-readable summary
|
||||
- Works with any text content (code, documents, etc.)
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
74
packages/tools/official/diff-text-unified/package.json
Normal file
74
packages/tools/official/diff-text-unified/package.json
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
{
|
||||
"name": "@tpmjs/tools-diff-text-unified",
|
||||
"version": "0.1.0",
|
||||
"description": "Creates unified diff between two text strings with context lines",
|
||||
"type": "module",
|
||||
"keywords": ["tpmjs", "engineering", "diff", "text", "unified"],
|
||||
"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:*",
|
||||
"@types/diff": "^6.0.0",
|
||||
"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/diff-text-unified"
|
||||
},
|
||||
"homepage": "https://tpmjs.com",
|
||||
"license": "MIT",
|
||||
"tpmjs": {
|
||||
"category": "engineering",
|
||||
"frameworks": ["vercel-ai"],
|
||||
"tools": [
|
||||
{
|
||||
"name": "diffTextUnified",
|
||||
"description": "Creates unified diff between two text strings with context lines",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "original",
|
||||
"type": "string",
|
||||
"description": "The original text",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "modified",
|
||||
"type": "string",
|
||||
"description": "The modified text",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "contextLines",
|
||||
"type": "number",
|
||||
"description": "Number of context lines to show around changes (default: 3)",
|
||||
"required": false
|
||||
}
|
||||
],
|
||||
"returns": {
|
||||
"type": "DiffResult",
|
||||
"description": "Object with diff string, additions, deletions, and changes count"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"ai": "6.0.0-beta.124",
|
||||
"diff": "^7.0.0"
|
||||
}
|
||||
}
|
||||
126
packages/tools/official/diff-text-unified/src/index.ts
Normal file
126
packages/tools/official/diff-text-unified/src/index.ts
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
/**
|
||||
* Diff Text Unified Tool for TPMJS
|
||||
* Creates unified diff between two text strings with context lines
|
||||
*/
|
||||
|
||||
import { jsonSchema, tool } from 'ai';
|
||||
import { createTwoFilesPatch } from 'diff';
|
||||
|
||||
/**
|
||||
* Output interface for the diff result
|
||||
*/
|
||||
export interface DiffResult {
|
||||
diff: string;
|
||||
additions: number;
|
||||
deletions: number;
|
||||
changes: number;
|
||||
hasChanges: boolean;
|
||||
summary: string;
|
||||
}
|
||||
|
||||
type DiffTextUnifiedInput = {
|
||||
original: string;
|
||||
modified: string;
|
||||
contextLines?: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Counts additions and deletions from a unified diff
|
||||
*/
|
||||
function analyzeDiff(diffString: string): {
|
||||
additions: number;
|
||||
deletions: number;
|
||||
} {
|
||||
const lines = diffString.split('\n');
|
||||
let additions = 0;
|
||||
let deletions = 0;
|
||||
|
||||
for (const line of lines) {
|
||||
if (line.startsWith('+') && !line.startsWith('+++')) {
|
||||
additions++;
|
||||
} else if (line.startsWith('-') && !line.startsWith('---')) {
|
||||
deletions++;
|
||||
}
|
||||
}
|
||||
|
||||
return { additions, deletions };
|
||||
}
|
||||
|
||||
/**
|
||||
* Diff Text Unified Tool
|
||||
* Creates unified diff between two text strings
|
||||
*/
|
||||
export const diffTextUnified = tool({
|
||||
description:
|
||||
'Creates a unified diff between two text strings, showing additions, deletions, and context lines. Returns the diff in unified format along with statistics about changes. Useful for comparing versions of code, documents, or any text content.',
|
||||
inputSchema: jsonSchema<DiffTextUnifiedInput>({
|
||||
type: 'object',
|
||||
properties: {
|
||||
original: {
|
||||
type: 'string',
|
||||
description: 'The original text to compare from',
|
||||
},
|
||||
modified: {
|
||||
type: 'string',
|
||||
description: 'The modified text to compare to',
|
||||
},
|
||||
contextLines: {
|
||||
type: 'number',
|
||||
description: 'Number of context lines to show around changes (default: 3)',
|
||||
default: 3,
|
||||
},
|
||||
},
|
||||
required: ['original', 'modified'],
|
||||
additionalProperties: false,
|
||||
}),
|
||||
async execute({ original, modified, contextLines = 3 }): Promise<DiffResult> {
|
||||
// Validate inputs
|
||||
if (typeof original !== 'string') {
|
||||
throw new Error('original must be a string');
|
||||
}
|
||||
if (typeof modified !== 'string') {
|
||||
throw new Error('modified must be a string');
|
||||
}
|
||||
if (contextLines !== undefined && (typeof contextLines !== 'number' || contextLines < 0)) {
|
||||
throw new Error('contextLines must be a non-negative number');
|
||||
}
|
||||
|
||||
// Create unified diff
|
||||
const diff = createTwoFilesPatch(
|
||||
'original',
|
||||
'modified',
|
||||
original,
|
||||
modified,
|
||||
undefined,
|
||||
undefined,
|
||||
{ context: contextLines }
|
||||
);
|
||||
|
||||
// Analyze the diff
|
||||
const { additions, deletions } = analyzeDiff(diff);
|
||||
const changes = additions + deletions;
|
||||
const hasChanges = changes > 0;
|
||||
|
||||
// Create summary
|
||||
let summary: string;
|
||||
if (!hasChanges) {
|
||||
summary = 'No changes detected';
|
||||
} else {
|
||||
const parts: string[] = [];
|
||||
if (additions > 0) parts.push(`${additions} addition${additions !== 1 ? 's' : ''}`);
|
||||
if (deletions > 0) parts.push(`${deletions} deletion${deletions !== 1 ? 's' : ''}`);
|
||||
summary = parts.join(', ');
|
||||
}
|
||||
|
||||
return {
|
||||
diff,
|
||||
additions,
|
||||
deletions,
|
||||
changes,
|
||||
hasChanges,
|
||||
summary,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default diffTextUnified;
|
||||
11
packages/tools/official/diff-text-unified/tsconfig.json
Normal file
11
packages/tools/official/diff-text-unified/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/diff-text-unified/tsup.config.ts
Normal file
10
packages/tools/official/diff-text-unified/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