@tanstack/ai-skills 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source
|
|
4
|
+
media="(prefers-color-scheme: dark)"
|
|
5
|
+
srcset="https://tanstack.com/api/readme/ai.png?theme=dark"
|
|
6
|
+
/>
|
|
7
|
+
<source
|
|
8
|
+
media="(prefers-color-scheme: light)"
|
|
9
|
+
srcset="https://tanstack.com/api/readme/ai.png"
|
|
10
|
+
/>
|
|
11
|
+
<img
|
|
12
|
+
src="https://tanstack.com/api/readme/ai.png"
|
|
13
|
+
alt="TanStack AI"
|
|
14
|
+
width="900"
|
|
15
|
+
/>
|
|
16
|
+
</picture>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<br />
|
|
20
|
+
|
|
21
|
+
# @tanstack/ai-skills
|
|
22
|
+
|
|
23
|
+
Portable Agent Skills (SKILL.md) as a first-class `chat()` middleware for TanStack AI
|
|
24
|
+
|
|
25
|
+
`withSkills` renders a short catalog of the skills you offer into the system prompt and gives the model a `load_skill` tool. The model reads the catalog, picks a skill, and pulls the full instructions only when it needs them — so a large skill library does not tax every request. This is the _portable_ path: it runs on any tool-calling model, with no provider sandbox. For skills that run in a provider's own sandbox, see [Provider Skills](https://tanstack.com/ai/latest/docs/tools/provider-skills); the two do not mix in one call.
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @tanstack/ai-skills
|
|
31
|
+
# or
|
|
32
|
+
pnpm add @tanstack/ai-skills
|
|
33
|
+
# or
|
|
34
|
+
yarn add @tanstack/ai-skills
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
Define a skill and pass it to `withSkills` in the `middleware` array. The middleware handles the catalog and the `load_skill` tool for you.
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { chat, toServerSentEventsResponse } from '@tanstack/ai'
|
|
43
|
+
import { anthropicText } from '@tanstack/ai-anthropic'
|
|
44
|
+
import { inlineSkill, withSkills } from '@tanstack/ai-skills'
|
|
45
|
+
|
|
46
|
+
const pptx = inlineSkill({
|
|
47
|
+
name: 'pptx-builder',
|
|
48
|
+
description: 'Build and edit PowerPoint decks with python-pptx.',
|
|
49
|
+
instructions: '# Building a deck\nUse python-pptx. Edit slides, then save.',
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
export async function POST(request: Request) {
|
|
53
|
+
const { messages } = await request.json()
|
|
54
|
+
|
|
55
|
+
const stream = chat({
|
|
56
|
+
adapter: anthropicText('claude-sonnet-4-5'),
|
|
57
|
+
messages,
|
|
58
|
+
middleware: [withSkills(pptx)],
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
return toServerSentEventsResponse(stream)
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Pass an array to offer several; they are sorted by name and deduped. Loading the same skill twice in one conversation returns a short "already loaded" marker instead of repeating the body.
|
|
66
|
+
|
|
67
|
+
### Tuning the catalog
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
withSkills(sources, {
|
|
71
|
+
// Cap the catalog so a big library doesn't tax every request.
|
|
72
|
+
// Default 4000 tokens; throws if exceeded unless you supply a reducer.
|
|
73
|
+
maxCatalogTokens: 4000,
|
|
74
|
+
// Require a human approval before load_skill runs. Default false.
|
|
75
|
+
requireApproval: true,
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The catalog is rendered per model family — Anthropic models get the `<available_skills>` XML they are tuned for, everything else a plain markdown list — and you can override that with `renderCatalog` or an `instructionTemplate`.
|
|
80
|
+
|
|
81
|
+
## Where skills come from
|
|
82
|
+
|
|
83
|
+
Inline skills are the quickest start, but skills usually live somewhere else. Each source is on its own entry point:
|
|
84
|
+
|
|
85
|
+
| Source | Import | Use when |
|
|
86
|
+
| ----------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
87
|
+
| `inlineSkill(...)` | `@tanstack/ai-skills` | Defining a skill in code |
|
|
88
|
+
| `skillDirectory(...)` | `@tanstack/ai-skills/node` | Walking a folder of `SKILL.md` files — reads the filesystem, so server only |
|
|
89
|
+
| `staticSkills(catalog)` | `@tanstack/ai-skills/static` | A build-time bundle, no filesystem at runtime (edge-safe). Pair with `skillsCatalogPlugin` from `/node` in your Vite config |
|
|
90
|
+
| Your own `SkillSource` | — | Skills in S3, a database, a registry |
|
|
91
|
+
|
|
92
|
+
`aggregate`, `dedupe`, `filter`, `cache`, and `combineSources` compose these.
|
|
93
|
+
|
|
94
|
+
### Writing your own source
|
|
95
|
+
|
|
96
|
+
Implement the `SkillSource` contract, then prove it with the conformance suite the package ships:
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { runSkillSourceConformance } from '@tanstack/ai-skills/testing'
|
|
100
|
+
import { s3Skills } from './s3-skills'
|
|
101
|
+
|
|
102
|
+
runSkillSourceConformance(() => s3Skills(makeTestBucket()), 's3')
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
It checks the things that break in production: a missing skill throws rather than returning empty, resources load while a path like `../../etc/passwd` is rejected, `revision()` is stable across identical content, and concurrent `list()` calls stay consistent. The optional parts of the contract are only checked when you implement them — the resource cases need both `listResources` and `readResource`, and the revision case needs `revision` — so a source that cannot represent them is skipped rather than failed. `vitest` is an optional peer dependency for this entry point.
|
|
106
|
+
|
|
107
|
+
## Documentation
|
|
108
|
+
|
|
109
|
+
- [Portable Agent Skills](https://tanstack.com/ai/latest/docs/skills/agent-skills): what the model sees, catalog options, reading a skill's bundled files
|
|
110
|
+
- [Skill sources](https://tanstack.com/ai/latest/docs/skills/skill-sources): folder, build-time bundle, your own store, and combining them
|
|
111
|
+
- [Writing a skill source](https://tanstack.com/ai/latest/docs/skills/writing-adapters): the `SkillSource` contract and the conformance suite
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
MIT
|