@agentproto/adapter-ai-sdk 0.1.1 → 0.1.2
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/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { dynamicTool } from 'ai';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @agentproto/adapter-ai-sdk v0.1.0-alpha
|
|
@@ -17,7 +18,7 @@ function toAiSdkTool(impl, bind) {
|
|
|
17
18
|
description: impl.tool.description,
|
|
18
19
|
// AI SDK v5 uses `inputSchema` and accepts Zod schemas natively
|
|
19
20
|
// via `FlexibleSchema<unknown>`; our Zod handle widens cleanly.
|
|
20
|
-
inputSchema: impl.tool.inputSchema,
|
|
21
|
+
inputSchema: impl.tool.inputSchema ?? z.unknown(),
|
|
21
22
|
execute: async (input, options) => {
|
|
22
23
|
const typedInput = input;
|
|
23
24
|
return impl.body({
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;AAiCA,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,IAAA,CAAK,IAAA,CAAK,WAAA,IAAe,EAAE,OAAA,EAAQ;AAAA,IAChD,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 { z } from \"zod\"\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 ?? z.unknown(),\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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentproto/adapter-ai-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
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
5
|
"keywords": [
|
|
6
6
|
"agentproto",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@agentproto/driver": "0.1.
|
|
45
|
-
"@agentproto/tool": "0.
|
|
44
|
+
"@agentproto/driver": "0.1.2",
|
|
45
|
+
"@agentproto/tool": "0.2.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"ai": "^5.0.0 || ^6.0.0",
|