@agentproto/adapter-ai-sdk 0.1.1
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/LICENSE +21 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.mjs +35 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jeremy André and agentproto contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Tool } from 'ai';
|
|
2
|
+
import { ToolContext } from '@agentproto/tool';
|
|
3
|
+
import { DriverContext, ToolImplementation } from '@agentproto/driver';
|
|
4
|
+
export { ToolImplementation } from '@agentproto/driver';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @agentproto/adapter-ai-sdk — AI SDK adapter for AIP-30
|
|
8
|
+
* `ToolImplementation`s.
|
|
9
|
+
*
|
|
10
|
+
* One function: {@link toAiSdkTool} takes a typed `ToolImplementation`
|
|
11
|
+
* (an `(contract, body)` pair produced by
|
|
12
|
+
* {@link "@agentproto/driver".implementTool}) and returns an AI SDK
|
|
13
|
+
* `Tool` that drops into `streamText({ tools })`, `generateText`, or
|
|
14
|
+
* any downstream consumer that speaks the AI SDK tool surface (Mastra
|
|
15
|
+
* wraps it, LangChain has interop, …).
|
|
16
|
+
*
|
|
17
|
+
* Same shape and semantics as `@agentproto/adapter-mastra` so apps
|
|
18
|
+
* authoring tools once via `defineTool` + `implementTool` can ship
|
|
19
|
+
* to either runtime — or both — without re-writing the body.
|
|
20
|
+
*
|
|
21
|
+
* Spec: https://agentproto.sh/docs/aip-14, https://agentproto.sh/docs/aip-30
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
interface ToAiSdkToolOptions<TContext extends ToolContext> {
|
|
25
|
+
/** Per-request context passed through to the body's `context` arg. */
|
|
26
|
+
context: TContext;
|
|
27
|
+
/**
|
|
28
|
+
* Optional provider context — typically only needed for non-builtin
|
|
29
|
+
* adapters that read `driverCtx.secrets` or `driverCtx.region`.
|
|
30
|
+
* Builtin bodies usually leave this defaulted.
|
|
31
|
+
*/
|
|
32
|
+
driverCtx?: DriverContext;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Adapt a {@link ToolImplementation} into an AI SDK v5 `Tool`.
|
|
36
|
+
*
|
|
37
|
+
* Type inference: `TContext` is inferred from `impl` only —
|
|
38
|
+
* `bind.context` is wrapped in `NoInfer<>` so a literal like
|
|
39
|
+
* `{ locale: "en" }` doesn't narrow the contract's
|
|
40
|
+
* `{ locale: "en" | "fr" }` and reject the impl via TS's
|
|
41
|
+
* contravariant-position function check.
|
|
42
|
+
*
|
|
43
|
+
* Implementation note: we dispatch through `dynamicTool` rather than
|
|
44
|
+
* the typed `tool` overloads. The static `Tool<INPUT, OUTPUT>` type
|
|
45
|
+
* uses a `NeverOptional<OUTPUT, …>` conditional that TS can't
|
|
46
|
+
* evaluate through generic type parameters — the structural
|
|
47
|
+
* assignment fails at the overload-resolution level even though the
|
|
48
|
+
* shape is valid. `dynamicTool` accepts `FlexibleSchema<unknown>` +
|
|
49
|
+
* `ToolExecuteFn<unknown, unknown>` directly (no NeverOptional gate),
|
|
50
|
+
* runs the same identity adapter at runtime, and returns a marked
|
|
51
|
+
* Tool that AI SDK's streamText / generateText accept everywhere.
|
|
52
|
+
* Schema-level validation is preserved because we pass the contract's
|
|
53
|
+
* Zod inputSchema through unchanged.
|
|
54
|
+
*/
|
|
55
|
+
declare function toAiSdkTool<TInput, TOutput, TContext extends ToolContext>(impl: ToolImplementation<TInput, TOutput, TContext>, bind: ToAiSdkToolOptions<NoInfer<TContext>>): Tool<unknown, unknown> & {
|
|
56
|
+
type: "dynamic";
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export { type ToAiSdkToolOptions, toAiSdkTool };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { dynamicTool } from 'ai';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @agentproto/adapter-ai-sdk v0.1.0-alpha
|
|
5
|
+
* AI SDK adapter for AIP-30 ToolImplementations.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
var DEFAULT_PROVIDER_CTX = Object.freeze({
|
|
9
|
+
secrets: {},
|
|
10
|
+
authState: "authed",
|
|
11
|
+
providerId: "ai-sdk-adapter",
|
|
12
|
+
driverKind: "builtin",
|
|
13
|
+
implementsEntry: { tool: "ai-sdk-adapter", version: "0.0.0" }
|
|
14
|
+
});
|
|
15
|
+
function toAiSdkTool(impl, bind) {
|
|
16
|
+
return dynamicTool({
|
|
17
|
+
description: impl.tool.description,
|
|
18
|
+
// AI SDK v5 uses `inputSchema` and accepts Zod schemas natively
|
|
19
|
+
// via `FlexibleSchema<unknown>`; our Zod handle widens cleanly.
|
|
20
|
+
inputSchema: impl.tool.inputSchema,
|
|
21
|
+
execute: async (input, options) => {
|
|
22
|
+
const typedInput = input;
|
|
23
|
+
return impl.body({
|
|
24
|
+
input: typedInput,
|
|
25
|
+
context: bind.context,
|
|
26
|
+
driverCtx: bind.driverCtx ?? DEFAULT_PROVIDER_CTX,
|
|
27
|
+
signal: options.abortSignal ?? new AbortController().signal
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { toAiSdkTool };
|
|
34
|
+
//# sourceMappingURL=index.mjs.map
|
|
35
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;AAgCA,IAAM,oBAAA,GAAsC,OAAO,MAAA,CAAO;AAAA,EACxD,SAAS,EAAC;AAAA,EACV,SAAA,EAAW,QAAA;AAAA,EACX,UAAA,EAAY,gBAAA;AAAA,EACZ,UAAA,EAAY,SAAA;AAAA,EACZ,eAAA,EAAiB,EAAE,IAAA,EAAM,gBAAA,EAAkB,SAAS,OAAA;AACtD,CAAC,CAAA;AAkCM,SAAS,WAAA,CACd,MACA,IAAA,EACgD;AAChD,EAAA,OAAO,WAAA,CAAY;AAAA,IACjB,WAAA,EAAa,KAAK,IAAA,CAAK,WAAA;AAAA;AAAA;AAAA,IAGvB,WAAA,EAAa,KAAK,IAAA,CAAK,WAAA;AAAA,IACvB,OAAA,EAAS,OAAO,KAAA,EAAgB,OAAA,KAA6B;AAQ3D,MAAA,MAAM,UAAA,GAAqB,KAAA;AAC3B,MAAA,OAAO,KAAK,IAAA,CAAK;AAAA,QACf,KAAA,EAAO,UAAA;AAAA,QACP,SAAS,IAAA,CAAK,OAAA;AAAA,QACd,SAAA,EAAW,KAAK,SAAA,IAAa,oBAAA;AAAA,QAC7B,MAAA,EAAQ,OAAA,CAAQ,WAAA,IAAe,IAAI,iBAAgB,CAAE;AAAA,OACtD,CAAA;AAAA,IACH;AAAA,GACD,CAAA;AACH","file":"index.mjs","sourcesContent":["/**\n * @agentproto/adapter-ai-sdk — AI SDK adapter for AIP-30\n * `ToolImplementation`s.\n *\n * One function: {@link toAiSdkTool} takes a typed `ToolImplementation`\n * (an `(contract, body)` pair produced by\n * {@link \"@agentproto/driver\".implementTool}) and returns an AI SDK\n * `Tool` that drops into `streamText({ tools })`, `generateText`, or\n * any downstream consumer that speaks the AI SDK tool surface (Mastra\n * wraps it, LangChain has interop, …).\n *\n * Same shape and semantics as `@agentproto/adapter-mastra` so apps\n * authoring tools once via `defineTool` + `implementTool` can ship\n * to either runtime — or both — without re-writing the body.\n *\n * Spec: https://agentproto.sh/docs/aip-14, https://agentproto.sh/docs/aip-30\n */\n\nimport { dynamicTool } from \"ai\"\nimport type { Tool as AiTool, ToolCallOptions } from \"ai\"\nimport type { ToolContext } from \"@agentproto/tool\"\nimport type {\n DriverContext,\n ToolImplementation,\n} from \"@agentproto/driver\"\n\n/**\n * Default {@link DriverContext} used when the caller doesn't pass\n * one. `kind: \"builtin\"` reflects the typical adapter use-case\n * (in-process bodies that don't read provider secrets / sandbox\n * handles). Override via `bind.driverCtx` for non-builtin bodies.\n */\nconst DEFAULT_PROVIDER_CTX: DriverContext = Object.freeze({\n secrets: {},\n authState: \"authed\",\n providerId: \"ai-sdk-adapter\",\n driverKind: \"builtin\",\n implementsEntry: { tool: \"ai-sdk-adapter\", version: \"0.0.0\" },\n})\n\nexport interface ToAiSdkToolOptions<TContext extends ToolContext> {\n /** Per-request context passed through to the body's `context` arg. */\n context: TContext\n /**\n * Optional provider context — typically only needed for non-builtin\n * adapters that read `driverCtx.secrets` or `driverCtx.region`.\n * Builtin bodies usually leave this defaulted.\n */\n driverCtx?: DriverContext\n}\n\n/**\n * Adapt a {@link ToolImplementation} into an AI SDK v5 `Tool`.\n *\n * Type inference: `TContext` is inferred from `impl` only —\n * `bind.context` is wrapped in `NoInfer<>` so a literal like\n * `{ locale: \"en\" }` doesn't narrow the contract's\n * `{ locale: \"en\" | \"fr\" }` and reject the impl via TS's\n * contravariant-position function check.\n *\n * Implementation note: we dispatch through `dynamicTool` rather than\n * the typed `tool` overloads. The static `Tool<INPUT, OUTPUT>` type\n * uses a `NeverOptional<OUTPUT, …>` conditional that TS can't\n * evaluate through generic type parameters — the structural\n * assignment fails at the overload-resolution level even though the\n * shape is valid. `dynamicTool` accepts `FlexibleSchema<unknown>` +\n * `ToolExecuteFn<unknown, unknown>` directly (no NeverOptional gate),\n * runs the same identity adapter at runtime, and returns a marked\n * Tool that AI SDK's streamText / generateText accept everywhere.\n * Schema-level validation is preserved because we pass the contract's\n * Zod inputSchema through unchanged.\n */\nexport function toAiSdkTool<TInput, TOutput, TContext extends ToolContext>(\n impl: ToolImplementation<TInput, TOutput, TContext>,\n bind: ToAiSdkToolOptions<NoInfer<TContext>>\n): AiTool<unknown, unknown> & { type: \"dynamic\" } {\n return dynamicTool({\n description: impl.tool.description,\n // AI SDK v5 uses `inputSchema` and accepts Zod schemas natively\n // via `FlexibleSchema<unknown>`; our Zod handle widens cleanly.\n inputSchema: impl.tool.inputSchema,\n execute: async (input: unknown, options: ToolCallOptions) => {\n // AI SDK validates `input` against `inputSchema` BEFORE calling\n // execute (per its docs and verified in `@ai-sdk/provider-\n // utils@3.0.20` source). At this point `input` is structurally\n // `TInput`; TS's `unknown` here reflects only the dynamicTool\n // signature, not the runtime contract. Narrowing via a noop\n // assignment to a TInput-typed variable expresses the post-\n // validation type without adding a runtime parse.\n const typedInput: TInput = input as TInput\n return impl.body({\n input: typedInput,\n context: bind.context,\n driverCtx: bind.driverCtx ?? DEFAULT_PROVIDER_CTX,\n signal: options.abortSignal ?? new AbortController().signal,\n })\n },\n })\n}\n\nexport type { ToolImplementation } from \"@agentproto/driver\"\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentproto/adapter-ai-sdk",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "AI SDK adapter for AIP-30 ToolImplementations. Wraps any `@agentproto/driver` ToolImplementation into a Vercel AI SDK Tool ready to drop into `streamText({ tools })`, `generateText`, or any downstream consumer that speaks the AI SDK tool surface.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agentproto",
|
|
7
|
+
"aip-30",
|
|
8
|
+
"ai-sdk",
|
|
9
|
+
"vercel-ai",
|
|
10
|
+
"tool",
|
|
11
|
+
"adapter",
|
|
12
|
+
"open-standard"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://agentproto.sh/docs/aip-30",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/agentproto/ts"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/agentproto/ts/issues"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "dist/index.mjs",
|
|
25
|
+
"module": "dist/index.mjs",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.mjs",
|
|
31
|
+
"default": "./dist/index.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./package.json": "./package.json"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@agentproto/driver": "0.1.1",
|
|
45
|
+
"@agentproto/tool": "0.1.1"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"ai": "^5.0.0 || ^6.0.0",
|
|
49
|
+
"zod": "^4.0.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/node": "^25.6.2",
|
|
53
|
+
"ai": "^6.0.204",
|
|
54
|
+
"tsup": "^8.5.1",
|
|
55
|
+
"typescript": "^5.9.3",
|
|
56
|
+
"vitest": "^3.2.4",
|
|
57
|
+
"zod": "^4.4.3",
|
|
58
|
+
"@agentproto/tooling": "0.1.0-alpha.0"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"dev": "tsup --watch",
|
|
62
|
+
"build": "tsup",
|
|
63
|
+
"clean": "rm -rf dist",
|
|
64
|
+
"check-types": "tsc --noEmit",
|
|
65
|
+
"test": "vitest run",
|
|
66
|
+
"test:watch": "vitest"
|
|
67
|
+
}
|
|
68
|
+
}
|