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>
3.4 KiB
3.4 KiB
@tpmjs/tools-rows-sort
Sort an array of objects by one or more fields with support for ascending and descending order.
Features
- Multi-level sorting: Sort by multiple fields with priority order
- Flexible directions: Choose ascending or descending for each field
- Nested field support: Use dot notation to sort by nested properties
- Smart comparisons: Type-aware sorting for numbers, strings, dates, and booleans
- Locale-aware: String sorting uses natural language comparison with numeric awareness
Installation
npm install @tpmjs/tools-rows-sort ai
Usage
import { rowsSortTool } from '@tpmjs/tools-rows-sort';
import { generateText } from 'ai';
const result = await generateText({
model: yourModel,
tools: {
rowsSort: rowsSortTool,
},
prompt: 'Sort the users by age descending, then by name ascending',
});
Parameters
rows(array, required): Array of objects to sortsortBy(array, required): Array of sort specifications, each containing:field(string, required): Field name to sort by (supports dot notation)direction(string, required): Sort direction -ascordesc
Returns
{
rows: Record<string, unknown>[], // Sorted array
sortedBy: SortSpec[] // Sort criteria that was applied
}
Examples
Single field sort
const data = [
{ name: 'Charlie', age: 35 },
{ name: 'Alice', age: 30 },
{ name: 'Bob', age: 25 },
];
// Returns: [Bob(25), Alice(30), Charlie(35)]
await rowsSortTool.execute({
rows: data,
sortBy: [{ field: 'age', direction: 'asc' }],
});
Multi-level sort
const products = [
{ name: 'Laptop', category: 'electronics', price: 999 },
{ name: 'Phone', category: 'electronics', price: 699 },
{ name: 'Desk', category: 'furniture', price: 299 },
{ name: 'Chair', category: 'furniture', price: 199 },
];
// Sort by category (asc), then price (desc) within each category
// Returns: [Phone(699), Laptop(999), Desk(299), Chair(199)]
await rowsSortTool.execute({
rows: products,
sortBy: [
{ field: 'category', direction: 'asc' },
{ field: 'price', direction: 'desc' },
],
});
Sort by nested field
const orders = [
{ id: 1, customer: { name: 'Charlie', tier: 'basic' } },
{ id: 2, customer: { name: 'Alice', tier: 'premium' } },
{ id: 3, customer: { name: 'Bob', tier: 'premium' } },
];
// Sort by tier (desc), then customer name (asc)
// Returns: [Alice(premium), Bob(premium), Charlie(basic)]
await rowsSortTool.execute({
rows: orders,
sortBy: [
{ field: 'customer.tier', direction: 'desc' },
{ field: 'customer.name', direction: 'asc' },
],
});
Natural language sorting
const files = [
{ name: 'file10.txt', size: 1024 },
{ name: 'file2.txt', size: 512 },
{ name: 'file1.txt', size: 256 },
];
// Natural sort handles numbers in strings correctly
// Returns: [file1.txt, file2.txt, file10.txt]
await rowsSortTool.execute({
rows: files,
sortBy: [{ field: 'name', direction: 'asc' }],
});
Type Handling
The tool intelligently compares values based on their types:
- Numbers: Numeric comparison
- Strings: Locale-aware comparison with numeric awareness
- Booleans: false < true
- Dates: Chronological comparison
- null/undefined: Sorts before all other values
- Mixed types: Converted to strings for comparison
License
MIT