@temporalio/ai-sdk 1.14.1 → 1.16.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.
@@ -1,5 +1,5 @@
1
1
  import type { LanguageModelV3CallOptions, LanguageModelV3GenerateResult, EmbeddingModelV3Result, SharedV3ProviderOptions, SharedV3Headers, ProviderV3 } from '@ai-sdk/provider';
2
- import type { FlexibleSchema, ToolExecutionOptions } from 'ai';
2
+ import { type Schema, type ToolExecutionOptions } from 'ai';
3
3
  import type { McpClientFactories } from './mcp';
4
4
  /**
5
5
  * Arguments for invoking a language model activity.
@@ -31,7 +31,7 @@ export interface InvokeEmbeddingModelArgs {
31
31
  export type InvokeEmbeddingModelResult = EmbeddingModelV3Result;
32
32
  export interface ListToolResult {
33
33
  description?: string;
34
- inputSchema: FlexibleSchema<unknown>;
34
+ inputSchema: Schema<unknown>;
35
35
  }
36
36
  export interface ListToolArgs {
37
37
  clientArgs?: unknown;
package/lib/activities.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createActivities = createActivities;
4
+ const ai_1 = require("ai");
4
5
  const common_1 = require("@temporalio/common");
5
6
  /**
6
7
  * Creates Temporal activities for AI model invocation using the provided AI SDK provider.
@@ -47,7 +48,8 @@ function activitiesForName(name, mcpClientFactory) {
47
48
  k,
48
49
  {
49
50
  description: v.description,
50
- inputSchema: v.inputSchema,
51
+ // Convert the FlexibleSchema to a Schema so that the shape is known outside the activity
52
+ inputSchema: (0, ai_1.asSchema)(v.inputSchema),
51
53
  },
52
54
  ]));
53
55
  }
@@ -63,7 +65,7 @@ function activitiesForName(name, mcpClientFactory) {
63
65
  if (tool === undefined) {
64
66
  throw common_1.ApplicationFailure.retryable(`Tool ${args.name} not found.`);
65
67
  }
66
- return tool.execute(args.input, args.options);
68
+ return await tool.execute(args.input, args.options);
67
69
  }
68
70
  finally {
69
71
  await mcpClient.close();
@@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AAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;gBACpC,CAAC;gBACD;oBACE,WAAW,EAAE,CAAC,CAAC,WAAW;oBAC1B,yFAAyF;oBACzF,WAAW,EAAE,IAAA,aAAQ,EAAC,CAAC,CAAC,WAAW,CAAC;iBACrC;aACF,CAAC,CACH,CAAC;QACJ,CAAC;gBAAS,CAAC;YACT,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;QAC1B,CAAC;IACH,CAAC;IACD,KAAK,UAAU,gBAAgB,CAAC,IAAkB;QAChD,MAAM,SAAS,GAAG,MAAM,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1D,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;YACtC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC9B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,MAAM,2BAAkB,CAAC,SAAS,CAAC,QAAQ,IAAI,CAAC,IAAI,aAAa,CAAC,CAAC;YACrE,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACtD,CAAC;gBAAS,CAAC;YACT,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;QAC1B,CAAC;IACH,CAAC;IACD,OAAO;QACL,CAAC,IAAI,GAAG,YAAY,CAAC,EAAE,iBAAiB;QACxC,CAAC,IAAI,GAAG,WAAW,CAAC,EAAE,gBAAgB;KACvC,CAAC;AACJ,CAAC"}
@@ -11,7 +11,7 @@ if ((0, workflow_1.inWorkflowContext)()) {
11
11
  require('web-streams-polyfill/polyfill');
12
12
  // Attach the polyfill as a Global function
13
13
  if (!('structuredClone' in globalThis)) {
14
- // eslint-disable-next-line @typescript-eslint/no-require-imports,import/no-unassigned-import
14
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
15
15
  const structuredClone = require('@ungap/structured-clone');
16
16
  globalThis.structuredClone = structuredClone.default;
17
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"load-polyfills.js","sourceRoot":"","sources":["../src/load-polyfills.ts"],"names":[],"mappings":";;AAAA,uDAA2C;AAC3C,mDAAyD;AAEzD,IAAI,IAAA,4BAAiB,GAAE,EAAE,CAAC;IACxB,yBAAyB;IACzB,IAAI,OAAO,UAAU,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC;QAC9C,UAAU,CAAC,OAAO,GAAG,0BAAO,CAAC;IAC/B,CAAC;IAED,6FAA6F;IAC7F,OAAO,CAAC,+BAA+B,CAAC,CAAC;IACzC,2CAA2C;IAC3C,IAAI,CAAC,CAAC,iBAAiB,IAAI,UAAU,CAAC,EAAE,CAAC;QACvC,6FAA6F;QAC7F,MAAM,eAAe,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAC3D,UAAU,CAAC,eAAe,GAAG,eAAe,CAAC,OAAO,CAAC;IACvD,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"load-polyfills.js","sourceRoot":"","sources":["../src/load-polyfills.ts"],"names":[],"mappings":";;AAAA,uDAA2C;AAC3C,mDAAyD;AAEzD,IAAI,IAAA,4BAAiB,GAAE,EAAE,CAAC;IACxB,yBAAyB;IACzB,IAAI,OAAO,UAAU,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC;QAC9C,UAAU,CAAC,OAAO,GAAG,0BAAO,CAAC;IAC/B,CAAC;IAED,6FAA6F;IAC7F,OAAO,CAAC,+BAA+B,CAAC,CAAC;IACzC,2CAA2C;IAC3C,IAAI,CAAC,CAAC,iBAAiB,IAAI,UAAU,CAAC,EAAE,CAAC;QACvC,iEAAiE;QACjE,MAAM,eAAe,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAC3D,UAAU,CAAC,eAAe,GAAG,eAAe,CAAC,OAAO,CAAC;IACvD,CAAC;AACH,CAAC"}
package/lib/mcp.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type ToolSet } from 'ai';
1
+ import type { ToolSet } from 'ai';
2
2
  import type { experimental_MCPClient as MCPClient } from '@ai-sdk/mcp';
3
3
  import type { ActivityOptions } from '@temporalio/workflow';
4
4
  export type McpClientFactory = (args: unknown) => Promise<MCPClient>;
package/lib/mcp.js CHANGED
@@ -24,7 +24,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.TemporalMCPClient = void 0;
27
- const ai_1 = require("ai");
28
27
  const workflow = __importStar(require("@temporalio/workflow"));
29
28
  /**
30
29
  * A Temporal MCP Client which uses activities to execute list tools and call tools.
@@ -50,16 +49,24 @@ class TemporalMCPClient {
50
49
  return Object.fromEntries(Object.entries(tools).map(([toolName, toolResult]) => [
51
50
  toolName,
52
51
  {
52
+ description: toolResult.description,
53
53
  execute: async (input, options) => {
54
54
  const activities = workflow.proxyActivities({
55
55
  summary: toolName,
56
56
  startToCloseTimeout: '10 minutes',
57
- ...this.options,
57
+ ...this.options.activityOptions,
58
58
  });
59
59
  const callActivity = activities[this.options.name + '-callTool'];
60
60
  return await callActivity({ name: toolName, input, options, clientArgs: this.options.clientArgs });
61
61
  },
62
- inputSchema: (0, ai_1.jsonSchema)(toolResult.inputSchema),
62
+ // Symbols and undefined values are lost on serialization, and need to be replaced to ensure the schema is used correctly
63
+ inputSchema: {
64
+ ...toolResult.inputSchema,
65
+ _type: undefined,
66
+ validate: undefined,
67
+ [Symbol.for('vercel.ai.schema')]: true,
68
+ [Symbol.for('vercel.ai.validator')]: true,
69
+ },
63
70
  type: 'dynamic',
64
71
  },
65
72
  ]));
package/lib/mcp.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2BAA8C;A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U,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;gBACrG,CAAC;gBACD,yHAAyH;gBACzH,WAAW,EAAE;oBACX,GAAG,UAAU,CAAC,WAAW;oBACzB,KAAK,EAAE,SAAS;oBAChB,QAAQ,EAAE,SAAS;oBACnB,CAAC,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,EAAE,IAAI;oBACtC,CAAC,MAAM,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC,EAAE,IAAI;iBAC1C;gBACD,IAAI,EAAE,SAAS;aAChB;SACF,CAAC,CACH,CAAC;IACJ,CAAC;CACF;AAvCD,8CAuCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temporalio/ai-sdk",
3
- "version": "1.14.1",
3
+ "version": "1.16.0",
4
4
  "description": "Temporal AI SDK integration package",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -15,11 +15,12 @@
15
15
  "author": "Temporal Technologies Inc. <sdk@temporal.io>",
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
- "@temporalio/plugin": "1.14.1",
19
- "@temporalio/workflow": "1.14.1",
20
18
  "@ungap/structured-clone": "^1.3.0",
21
19
  "headers-polyfill": "^4.0.3",
22
- "web-streams-polyfill": "^4.2.0"
20
+ "web-streams-polyfill": "^4.2.0",
21
+ "@temporalio/common": "1.16.0",
22
+ "@temporalio/workflow": "1.16.0",
23
+ "@temporalio/plugin": "1.16.0"
23
24
  },
24
25
  "peerDependencies": {
25
26
  "@ai-sdk/mcp": "^1.0.0",
@@ -27,7 +28,7 @@
27
28
  "ai": "^6.0.0"
28
29
  },
29
30
  "engines": {
30
- "node": ">= 18.0.0"
31
+ "node": ">= 20.0.0"
31
32
  },
32
33
  "bugs": {
33
34
  "url": "https://github.com/temporalio/sdk-typescript/issues"
@@ -44,6 +45,5 @@
44
45
  "files": [
45
46
  "src",
46
47
  "lib"
47
- ],
48
- "gitHead": "42bf6087946b7bbda61c7856bc0723c1616f9973"
49
- }
48
+ ]
49
+ }
package/src/activities.ts CHANGED
@@ -6,7 +6,7 @@ import type {
6
6
  SharedV3Headers,
7
7
  ProviderV3,
8
8
  } from '@ai-sdk/provider';
9
- import type { FlexibleSchema, ToolExecutionOptions } from 'ai';
9
+ import { asSchema, type Schema, type ToolExecutionOptions } from 'ai';
10
10
  import { ApplicationFailure } from '@temporalio/common';
11
11
  import type { McpClientFactories, McpClientFactory } from './mcp';
12
12
 
@@ -44,7 +44,7 @@ export type InvokeEmbeddingModelResult = EmbeddingModelV3Result;
44
44
 
45
45
  export interface ListToolResult {
46
46
  description?: string;
47
- inputSchema: FlexibleSchema<unknown>;
47
+ inputSchema: Schema<unknown>;
48
48
  }
49
49
 
50
50
  export interface ListToolArgs {
@@ -100,13 +100,13 @@ function activitiesForName(name: string, mcpClientFactory: McpClientFactory): ob
100
100
  const mcpClient = await mcpClientFactory(args.clientArgs);
101
101
  try {
102
102
  const tools = await mcpClient.tools();
103
-
104
103
  return Object.fromEntries(
105
104
  Object.entries(tools).map(([k, v]) => [
106
105
  k,
107
106
  {
108
107
  description: v.description,
109
- inputSchema: v.inputSchema,
108
+ // Convert the FlexibleSchema to a Schema so that the shape is known outside the activity
109
+ inputSchema: asSchema(v.inputSchema),
110
110
  },
111
111
  ])
112
112
  );
@@ -122,7 +122,7 @@ function activitiesForName(name: string, mcpClientFactory: McpClientFactory): ob
122
122
  if (tool === undefined) {
123
123
  throw ApplicationFailure.retryable(`Tool ${args.name} not found.`);
124
124
  }
125
- return tool.execute(args.input, args.options);
125
+ return await tool.execute(args.input, args.options);
126
126
  } finally {
127
127
  await mcpClient.close();
128
128
  }
@@ -11,7 +11,7 @@ if (inWorkflowContext()) {
11
11
  require('web-streams-polyfill/polyfill');
12
12
  // Attach the polyfill as a Global function
13
13
  if (!('structuredClone' in globalThis)) {
14
- // eslint-disable-next-line @typescript-eslint/no-require-imports,import/no-unassigned-import
14
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
15
15
  const structuredClone = require('@ungap/structured-clone');
16
16
  globalThis.structuredClone = structuredClone.default;
17
17
  }
package/src/mcp.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { jsonSchema, type ToolSet } from 'ai';
2
- import type { JSONSchema7 } from '@ai-sdk/provider';
1
+ import type { ToolSet } from 'ai';
3
2
  import type { experimental_MCPClient as MCPClient } from '@ai-sdk/mcp';
4
3
  import * as workflow from '@temporalio/workflow';
5
4
  import type { ActivityOptions } from '@temporalio/workflow';
@@ -39,20 +38,29 @@ export class TemporalMCPClient {
39
38
 
40
39
  const listActivity = activities[this.options.name + '-listTools'];
41
40
  const tools: Record<string, ListToolResult> = await listActivity!({ clientArgs: this.options.clientArgs });
41
+
42
42
  return Object.fromEntries(
43
43
  Object.entries(tools).map(([toolName, toolResult]) => [
44
44
  toolName,
45
45
  {
46
+ description: toolResult.description,
46
47
  execute: async (input, options) => {
47
48
  const activities = workflow.proxyActivities({
48
49
  summary: toolName,
49
50
  startToCloseTimeout: '10 minutes',
50
- ...this.options,
51
+ ...this.options.activityOptions,
51
52
  });
52
53
  const callActivity = activities[this.options.name + '-callTool']!;
53
54
  return await callActivity({ name: toolName, input, options, clientArgs: this.options.clientArgs });
54
55
  },
55
- inputSchema: jsonSchema(toolResult.inputSchema as JSONSchema7),
56
+ // Symbols and undefined values are lost on serialization, and need to be replaced to ensure the schema is used correctly
57
+ inputSchema: {
58
+ ...toolResult.inputSchema,
59
+ _type: undefined,
60
+ validate: undefined,
61
+ [Symbol.for('vercel.ai.schema')]: true,
62
+ [Symbol.for('vercel.ai.validator')]: true,
63
+ },
56
64
  type: 'dynamic',
57
65
  },
58
66
  ])