@ai-sdk-tool/parser 3.0.0 → 3.1.0
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 +7 -9
- package/dist/{v6.cjs → chunk-JVQVEA3K.js} +1874 -1793
- package/dist/chunk-JVQVEA3K.js.map +1 -0
- package/dist/community.cjs +308 -284
- package/dist/community.cjs.map +1 -1
- package/dist/community.d.cts +0 -14
- package/dist/community.d.ts +0 -14
- package/dist/community.js +9 -10
- package/dist/community.js.map +1 -1
- package/dist/index.cjs +325 -294
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +152 -18
- package/dist/index.d.ts +152 -18
- package/dist/index.js +24 -21
- package/package.json +3 -17
- package/dist/chunk-DFOXAWP6.js +0 -1
- package/dist/chunk-DFOXAWP6.js.map +0 -1
- package/dist/chunk-NOYHOQOL.js +0 -2489
- package/dist/chunk-NOYHOQOL.js.map +0 -1
- package/dist/chunk-QPJA5CS6.js +0 -1289
- package/dist/chunk-QPJA5CS6.js.map +0 -1
- package/dist/tool-call-protocol-Bn2CBcD-.d.cts +0 -84
- package/dist/tool-call-protocol-Bn2CBcD-.d.ts +0 -84
- package/dist/v5.cjs +0 -2816
- package/dist/v5.cjs.map +0 -1
- package/dist/v5.d.cts +0 -14
- package/dist/v5.d.ts +0 -14
- package/dist/v5.js +0 -476
- package/dist/v5.js.map +0 -1
- package/dist/v6.cjs.map +0 -1
- package/dist/v6.d.cts +0 -16
- package/dist/v6.d.ts +0 -16
- package/dist/v6.js +0 -16
- package/dist/v6.js.map +0 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://codecov.io/gh/minpeter/ai-sdk-tool-call-middleware)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> Requires AI SDK v5. For AI SDK v4, pin `@ai-sdk-tool/parser@1.0.0`.
|
|
10
|
+
> Requires AI SDK v6. For AI SDK v5, use `@ai-sdk-tool/parser@3.x`. For AI SDK v4, pin `@ai-sdk-tool/parser@1.0.0`.
|
|
11
11
|
|
|
12
12
|
Middleware that enables tool calling with models that don’t natively support OpenAI‑style `tools`. Works with any provider (OpenRouter, vLLM, Ollama, etc.) via AI SDK middleware.
|
|
13
13
|
|
|
@@ -31,7 +31,7 @@ pnpm add @ai-sdk-tool/parser
|
|
|
31
31
|
```typescript
|
|
32
32
|
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
33
33
|
import { wrapLanguageModel, stepCountIs, streamText } from "ai";
|
|
34
|
-
import {
|
|
34
|
+
import { xmlToolMiddleware } from "@ai-sdk-tool/parser";
|
|
35
35
|
|
|
36
36
|
const openrouter = createOpenAICompatible({
|
|
37
37
|
/* ... */
|
|
@@ -40,8 +40,8 @@ const openrouter = createOpenAICompatible({
|
|
|
40
40
|
async function main() {
|
|
41
41
|
const result = streamText({
|
|
42
42
|
model: wrapLanguageModel({
|
|
43
|
-
model: openrouter("
|
|
44
|
-
middleware:
|
|
43
|
+
model: openrouter("your-model-name"),
|
|
44
|
+
middleware: xmlToolMiddleware,
|
|
45
45
|
}),
|
|
46
46
|
system: "You are a helpful assistant.",
|
|
47
47
|
prompt: "What is the weather in my city?",
|
|
@@ -97,14 +97,13 @@ main().catch(console.error);
|
|
|
97
97
|
|
|
98
98
|
## Prebuilt middlewares
|
|
99
99
|
|
|
100
|
-
- `gemmaToolMiddleware` — JSON‑mix format inside markdown fences (markdown code fences)
|
|
101
100
|
- `hermesToolMiddleware` — JSON‑mix format wrapped in `<tool_call>` XML tags.
|
|
102
|
-
- `
|
|
101
|
+
- `xmlToolMiddleware` — XML format (Morph‑XML protocol).
|
|
103
102
|
|
|
104
103
|
## Protocols
|
|
105
104
|
|
|
106
|
-
- `
|
|
107
|
-
- `
|
|
105
|
+
- `jsonProtocol` — JSON function calls in flexible text wrappers.
|
|
106
|
+
- `xmlProtocol` — XML element per call, robust to streaming.
|
|
108
107
|
|
|
109
108
|
## Tool choice support
|
|
110
109
|
|
|
@@ -118,7 +117,6 @@ See `examples/parser-core/src/*` for runnable demos (streaming/non‑streaming,
|
|
|
118
117
|
|
|
119
118
|
## [dev] Contributor notes
|
|
120
119
|
|
|
121
|
-
- Exported API: `createToolMiddleware`, `gemmaToolMiddleware`, `hermesToolMiddleware`, `morphXmlToolMiddleware`, `jsonMixProtocol`, `morphXmlProtocol`.
|
|
122
120
|
- Debugging:
|
|
123
121
|
- Set `DEBUG_PARSER_MW=stream` to log raw/parsed chunks during runs.
|
|
124
122
|
- Set `DEBUG_PARSER_MW=parse` to log original matched text and parsed summary.
|