@temporalio/ai-sdk 1.14.1 → 1.14.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.
@@ -1,46 +1,36 @@
1
- import type { LanguageModelV3CallOptions, LanguageModelV3GenerateResult, EmbeddingModelV3Result, SharedV3ProviderOptions, SharedV3Headers, ProviderV3 } from '@ai-sdk/provider';
2
- import type { FlexibleSchema, ToolExecutionOptions } from 'ai';
1
+ import type { LanguageModelV2CallOptions, LanguageModelV2CallWarning, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2ResponseMetadata, LanguageModelV2Usage, ProviderV2, SharedV2Headers, SharedV2ProviderMetadata } from '@ai-sdk/provider';
2
+ import type { ToolCallOptions } from 'ai';
3
3
  import type { McpClientFactories } from './mcp';
4
- /**
5
- * Arguments for invoking a language model activity.
6
- */
7
4
  export interface InvokeModelArgs {
8
5
  modelId: string;
9
- options: LanguageModelV3CallOptions;
6
+ options: LanguageModelV2CallOptions;
10
7
  }
11
- /**
12
- * Result from a language model invocation.
13
- * This is an alias to the AI SDK's LanguageModelV3GenerateResult for type safety.
14
- */
15
- export type InvokeModelResult = LanguageModelV3GenerateResult;
16
- /**
17
- * Arguments for invoking an embedding model activity.
18
- * Note: AbortSignal is not included as it cannot be serialized across activity boundaries.
19
- * Temporal's workflow cancellation provides equivalent functionality.
20
- */
21
- export interface InvokeEmbeddingModelArgs {
22
- modelId: string;
23
- values: string[];
24
- providerOptions?: SharedV3ProviderOptions;
25
- headers?: SharedV3Headers;
8
+ export interface InvokeModelResult {
9
+ content: Array<LanguageModelV2Content>;
10
+ finishReason: LanguageModelV2FinishReason;
11
+ usage: LanguageModelV2Usage;
12
+ providerMetadata?: SharedV2ProviderMetadata;
13
+ request?: {
14
+ body?: unknown;
15
+ };
16
+ response?: LanguageModelV2ResponseMetadata & {
17
+ headers?: SharedV2Headers;
18
+ body?: unknown;
19
+ };
20
+ warnings: Array<LanguageModelV2CallWarning>;
26
21
  }
27
- /**
28
- * Result from an embedding model invocation.
29
- * This is an alias to the AI SDK's EmbeddingModelV3Result for type safety.
30
- */
31
- export type InvokeEmbeddingModelResult = EmbeddingModelV3Result;
32
22
  export interface ListToolResult {
33
23
  description?: string;
34
- inputSchema: FlexibleSchema<unknown>;
24
+ inputSchema: any;
35
25
  }
36
26
  export interface ListToolArgs {
37
- clientArgs?: unknown;
27
+ clientArgs?: any;
38
28
  }
39
29
  export interface CallToolArgs {
40
- clientArgs?: unknown;
30
+ clientArgs?: any;
41
31
  name: string;
42
- input: unknown;
43
- options: ToolExecutionOptions;
32
+ args: any;
33
+ options: ToolCallOptions;
44
34
  }
45
35
  /**
46
36
  * Creates Temporal activities for AI model invocation using the provided AI SDK provider.
@@ -53,4 +43,4 @@ export interface CallToolArgs {
53
43
  *
54
44
  * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
55
45
  */
56
- export declare function createActivities(provider: ProviderV3, mcpClientFactories?: McpClientFactories): object;
46
+ export declare function createActivities(provider: ProviderV2, mcpClientFactories?: McpClientFactories): object;
package/lib/activities.js CHANGED
@@ -19,14 +19,6 @@ function createActivities(provider, mcpClientFactories) {
19
19
  const model = provider.languageModel(args.modelId);
20
20
  return await model.doGenerate(args.options);
21
21
  },
22
- async invokeEmbeddingModel(args) {
23
- const model = provider.embeddingModel(args.modelId);
24
- return await model.doEmbed({
25
- values: args.values,
26
- providerOptions: args.providerOptions,
27
- headers: args.headers,
28
- });
29
- },
30
22
  };
31
23
  if (mcpClientFactories !== undefined) {
32
24
  Object.entries(mcpClientFactories).forEach(([name, func]) => {
@@ -63,7 +55,7 @@ function activitiesForName(name, mcpClientFactory) {
63
55
  if (tool === undefined) {
64
56
  throw common_1.ApplicationFailure.retryable(`Tool ${args.name} not found.`);
65
57
  }
66
- return tool.execute(args.input, args.options);
58
+ return tool.execute(args.args, args.options);
67
59
  }
68
60
  finally {
69
61
  await mcpClient.close();
@@ -1 +1 @@
1
- {"version":3,"file":"activities.js","sourceRoot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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,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/C,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"}
package/lib/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import './load-polyfills';
2
- export * from './activities';
3
2
  export * from './mcp';
4
3
  export * from './plugin';
5
4
  export * from './provider';
package/lib/index.js CHANGED
@@ -16,7 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  // eslint-disable-next-line import/no-unassigned-import
18
18
  require("./load-polyfills");
19
- __exportStar(require("./activities"), exports);
20
19
  __exportStar(require("./mcp"), exports);
21
20
  __exportStar(require("./plugin"), exports);
22
21
  __exportStar(require("./provider"), exports);
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,4BAA0B;AAE1B,+CAA6B;AAC7B,wCAAsB;AACtB,2CAAyB;AACzB,6CAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,4BAA0B;AAE1B,wCAAsB;AACtB,2CAAyB;AACzB,6CAA2B"}
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>;
@@ -12,7 +12,7 @@ export type McpClientFactories = {
12
12
  */
13
13
  export interface TemporalMCPClientOptions {
14
14
  readonly name: string;
15
- readonly clientArgs?: unknown;
15
+ readonly clientArgs?: any;
16
16
  readonly activityOptions?: ActivityOptions;
17
17
  }
18
18
  /**
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.
@@ -41,25 +40,29 @@ class TemporalMCPClient {
41
40
  this.options = options;
42
41
  }
43
42
  async tools() {
44
- const activities = workflow.proxyActivities({
45
- startToCloseTimeout: '10 minutes',
46
- ...this.options.activityOptions,
47
- });
43
+ workflow.log.info(`Options: ${this.options.activityOptions}`);
44
+ const activities = workflow.proxyActivities({ startToCloseTimeout: '10 minutes', ...this.options.activityOptions });
48
45
  const listActivity = activities[this.options.name + '-listTools'];
49
46
  const tools = await listActivity({ clientArgs: this.options.clientArgs });
50
47
  return Object.fromEntries(Object.entries(tools).map(([toolName, toolResult]) => [
51
48
  toolName,
52
49
  {
53
- execute: async (input, options) => {
50
+ execute: async (args, options) => {
54
51
  const activities = workflow.proxyActivities({
55
52
  summary: toolName,
56
53
  startToCloseTimeout: '10 minutes',
57
54
  ...this.options,
58
55
  });
59
56
  const callActivity = activities[this.options.name + '-callTool'];
60
- return await callActivity({ name: toolName, input, options, clientArgs: this.options.clientArgs });
57
+ return await callActivity({ name: toolName, args, options, clientArgs: this.options.clientArgs });
58
+ },
59
+ inputSchema: {
60
+ ...toolResult.inputSchema,
61
+ _type: undefined,
62
+ validate: undefined,
63
+ [Symbol.for('vercel.ai.schema')]: true,
64
+ [Symbol.for('vercel.ai.validator')]: true,
61
65
  },
62
- inputSchema: (0, ai_1.jsonSchema)(toolResult.inputSchema),
63
66
  type: 'dynamic',
64
67
  },
65
68
  ]));
package/lib/mcp.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2BAA8C;AAG9C,+DAAiD;AAkBjD;;;;;;;;GAQG;AACH,MAAa,iBAAiB;IACP;IAArB,YAAqB,OAAiC;QAAjC,YAAO,GAAP,OAAO,CAA0B;IAAG,CAAC;IAE1D,KAAK,CAAC,KAAK;QACT,MAAM,UAAU,GAAG,QAAQ,CAAC,eAAe,CAAC;YAC1C,mBAAmB,EAAE,YAAY;YACjC,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe;SAChC,CAAC,CAAC;QAEH,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,YAAY,CAAC,CAAC;QAClE,MAAM,KAAK,GAAmC,MAAM,YAAa,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QAC3G,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC;YACpD,QAAQ;YACR;gBACE,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,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QAC3G,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC;YACpD,QAAQ;YACR;gBACE,OAAO,EAAE,KAAK,EAAE,IAAS,EAAE,OAAO,EAAE,EAAE;oBACpC,MAAM,UAAU,GAAG,QAAQ,CAAC,eAAe,CAAC;wBAC1C,OAAO,EAAE,QAAQ;wBACjB,mBAAmB,EAAE,YAAY;wBACjC,GAAG,IAAI,CAAC,OAAO;qBAChB,CAAC,CAAC;oBACH,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,WAAW,CAAE,CAAC;oBAClE,OAAO,MAAM,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;gBACpG,CAAC;gBACD,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;AAlCD,8CAkCC"}
package/lib/plugin.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ProviderV3 } from '@ai-sdk/provider';
1
+ import type { ProviderV2 } from '@ai-sdk/provider';
2
2
  import { SimplePlugin } from '@temporalio/plugin';
3
3
  import type { McpClientFactories } from './mcp';
4
4
  /**
@@ -7,7 +7,7 @@ import type { McpClientFactories } from './mcp';
7
7
  * @experimental The AI SDK plugin is an experimental feature; APIs may change without notice.
8
8
  */
9
9
  export interface AiSdkPluginOptions {
10
- modelProvider: ProviderV3;
10
+ modelProvider: ProviderV2;
11
11
  /**
12
12
  * This object contains a mapping of server names to functions which create MCP clients.
13
13
  * Any TemporalMCPClient used in a workflow should have its associated servername listed in this object.
package/lib/provider.d.ts CHANGED
@@ -1,63 +1,29 @@
1
- import type { EmbeddingModelV3, EmbeddingModelV3CallOptions, EmbeddingModelV3Result, ImageModelV3, LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, ProviderV3, TranscriptionModelV3 } from '@ai-sdk/provider';
2
- import type { ActivityOptions } from '@temporalio/workflow';
3
- /**
4
- * Options for configuring the TemporalProvider with per-model activity settings.
5
- */
6
- export interface TemporalProviderOptions {
7
- /**
8
- * Default activity options applied to all model types.
9
- * These can be overridden by model-specific options.
10
- */
11
- default?: ActivityOptions;
12
- /**
13
- * Activity options specific to language model calls.
14
- * Merged with default options, with these taking precedence.
15
- */
16
- languageModel?: ActivityOptions;
17
- /**
18
- * Activity options specific to embedding model calls.
19
- * Merged with default options, with these taking precedence.
20
- */
21
- embeddingModel?: ActivityOptions;
22
- }
1
+ import type { EmbeddingModelV2, ImageModelV2, LanguageModelV2, LanguageModelV2CallOptions, ProviderV2, SharedV2Headers } from '@ai-sdk/provider';
2
+ import { ActivityOptions } from '@temporalio/workflow';
3
+ import { InvokeModelResult } from './activities';
23
4
  /**
24
5
  * A language model implementation that delegates AI model calls to Temporal activities.
25
6
  * This allows workflows to invoke AI models through the Temporal execution model.
26
7
  *
27
8
  * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
28
9
  */
29
- export declare class TemporalLanguageModel implements LanguageModelV3 {
10
+ export declare class TemporalLanguageModel implements LanguageModelV2 {
30
11
  readonly modelId: string;
31
12
  readonly options?: ActivityOptions | undefined;
32
- readonly specificationVersion = "v3";
13
+ readonly specificationVersion = "v2";
33
14
  readonly provider = "temporal";
15
+ readonly supportedUrls: {};
34
16
  constructor(modelId: string, options?: ActivityOptions | undefined);
35
- get supportedUrls(): Record<string, RegExp[]>;
36
- doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
37
- doStream(_options: LanguageModelV3CallOptions): PromiseLike<LanguageModelV3StreamResult>;
38
- }
39
- /**
40
- * An embedding model implementation that delegates embedding generation to Temporal activities.
41
- * This allows workflows to generate embeddings through the Temporal execution model.
42
- *
43
- * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
44
- */
45
- export declare class TemporalEmbeddingModel implements EmbeddingModelV3 {
46
- readonly modelId: string;
47
- readonly options?: ActivityOptions | undefined;
48
- readonly specificationVersion = "v3";
49
- readonly provider = "temporal";
50
- /**
51
- * Undefined to let the underlying provider handle chunking, as it knows its own limits.
52
- */
53
- readonly maxEmbeddingsPerCall: undefined;
54
- /**
55
- * Indicates the underlying embedding model API can handle concurrent requests.
56
- * Set to true since we delegate to the actual provider which manages its own concurrency.
57
- */
58
- readonly supportsParallelCalls = true;
59
- constructor(modelId: string, options?: ActivityOptions | undefined);
60
- doEmbed(options: EmbeddingModelV3CallOptions): Promise<EmbeddingModelV3Result>;
17
+ doGenerate(options: LanguageModelV2CallOptions): Promise<InvokeModelResult>;
18
+ doStream(_options: LanguageModelV2CallOptions): PromiseLike<{
19
+ stream: any;
20
+ request?: {
21
+ body?: unknown;
22
+ };
23
+ response?: {
24
+ headers?: SharedV2Headers;
25
+ };
26
+ }>;
61
27
  }
62
28
  /**
63
29
  * A Temporal-specific provider implementation that creates AI models which execute
@@ -66,14 +32,12 @@ export declare class TemporalEmbeddingModel implements EmbeddingModelV3 {
66
32
  *
67
33
  * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
68
34
  */
69
- export declare class TemporalProvider implements ProviderV3 {
70
- readonly options?: TemporalProviderOptions | undefined;
71
- readonly specificationVersion = "v3";
72
- constructor(options?: TemporalProviderOptions | undefined);
73
- imageModel(_modelId: string): ImageModelV3;
74
- languageModel(modelId: string): LanguageModelV3;
75
- embeddingModel(modelId: string): EmbeddingModelV3;
76
- transcriptionModel(_modelId: string): TranscriptionModelV3;
35
+ export declare class TemporalProvider implements ProviderV2 {
36
+ readonly options?: ActivityOptions | undefined;
37
+ constructor(options?: ActivityOptions | undefined);
38
+ imageModel(_modelId: string): ImageModelV2;
39
+ languageModel(modelId: string): LanguageModelV2;
40
+ textEmbeddingModel(_modelId: string): EmbeddingModelV2<string>;
77
41
  }
78
42
  /**
79
43
  * A singleton instance of TemporalProvider for convenient use in applications.
package/lib/provider.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.temporalProvider = exports.TemporalProvider = exports.TemporalEmbeddingModel = exports.TemporalLanguageModel = void 0;
26
+ exports.temporalProvider = exports.TemporalProvider = exports.TemporalLanguageModel = void 0;
27
27
  const workflow = __importStar(require("@temporalio/workflow"));
28
28
  const common_1 = require("@temporalio/common");
29
29
  /**
@@ -35,30 +35,21 @@ const common_1 = require("@temporalio/common");
35
35
  class TemporalLanguageModel {
36
36
  modelId;
37
37
  options;
38
- specificationVersion = 'v3';
38
+ specificationVersion = 'v2';
39
39
  provider = 'temporal';
40
+ supportedUrls = {};
40
41
  constructor(modelId, options) {
41
42
  this.modelId = modelId;
42
43
  this.options = options;
43
44
  }
44
- get supportedUrls() {
45
- return {};
46
- }
47
45
  async doGenerate(options) {
48
- const activities = workflow.proxyActivities({
49
- startToCloseTimeout: '10 minutes',
50
- ...this.options,
51
- });
46
+ const activities = workflow.proxyActivities({ startToCloseTimeout: '10 minutes', ...this.options });
52
47
  const result = await activities.invokeModel({ modelId: this.modelId, options });
53
48
  if (result === undefined) {
54
49
  throw common_1.ApplicationFailure.nonRetryable('Received undefined response from model activity.');
55
50
  }
56
- if (result.response !== undefined && result.response.timestamp) {
57
- const timestamp = new Date(result.response.timestamp);
58
- // Only set if it's a valid date
59
- if (!isNaN(timestamp.getTime())) {
60
- result.response.timestamp = timestamp;
61
- }
51
+ if (result.response !== undefined) {
52
+ result.response.timestamp = new Date(result.response.timestamp);
62
53
  }
63
54
  return result;
64
55
  }
@@ -67,49 +58,6 @@ class TemporalLanguageModel {
67
58
  }
68
59
  }
69
60
  exports.TemporalLanguageModel = TemporalLanguageModel;
70
- /**
71
- * An embedding model implementation that delegates embedding generation to Temporal activities.
72
- * This allows workflows to generate embeddings through the Temporal execution model.
73
- *
74
- * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
75
- */
76
- class TemporalEmbeddingModel {
77
- modelId;
78
- options;
79
- specificationVersion = 'v3';
80
- provider = 'temporal';
81
- /**
82
- * Undefined to let the underlying provider handle chunking, as it knows its own limits.
83
- */
84
- maxEmbeddingsPerCall = undefined;
85
- /**
86
- * Indicates the underlying embedding model API can handle concurrent requests.
87
- * Set to true since we delegate to the actual provider which manages its own concurrency.
88
- */
89
- supportsParallelCalls = true;
90
- constructor(modelId, options) {
91
- this.modelId = modelId;
92
- this.options = options;
93
- }
94
- async doEmbed(options) {
95
- const activities = workflow.proxyActivities({
96
- startToCloseTimeout: '10 minutes',
97
- ...this.options,
98
- });
99
- const result = await activities.invokeEmbeddingModel({
100
- modelId: this.modelId,
101
- values: options.values,
102
- providerOptions: options.providerOptions,
103
- headers: options.headers,
104
- // Note: abortSignal is not serializable, Temporal's cancellation handles this
105
- });
106
- if (result === undefined) {
107
- throw common_1.ApplicationFailure.nonRetryable('Received undefined response from embedding model activity.');
108
- }
109
- return result;
110
- }
111
- }
112
- exports.TemporalEmbeddingModel = TemporalEmbeddingModel;
113
61
  /**
114
62
  * A Temporal-specific provider implementation that creates AI models which execute
115
63
  * through Temporal activities. This provider integrates AI SDK models with Temporal's
@@ -119,7 +67,6 @@ exports.TemporalEmbeddingModel = TemporalEmbeddingModel;
119
67
  */
120
68
  class TemporalProvider {
121
69
  options;
122
- specificationVersion = 'v3';
123
70
  constructor(options) {
124
71
  this.options = options;
125
72
  }
@@ -127,18 +74,9 @@ class TemporalProvider {
127
74
  throw new Error('Not implemented');
128
75
  }
129
76
  languageModel(modelId) {
130
- return new TemporalLanguageModel(modelId, {
131
- ...this.options?.default,
132
- ...this.options?.languageModel,
133
- });
134
- }
135
- embeddingModel(modelId) {
136
- return new TemporalEmbeddingModel(modelId, {
137
- ...this.options?.default,
138
- ...this.options?.embeddingModel,
139
- });
77
+ return new TemporalLanguageModel(modelId, this.options);
140
78
  }
141
- transcriptionModel(_modelId) {
79
+ textEmbeddingModel(_modelId) {
142
80
  throw new Error('Not implemented');
143
81
  }
144
82
  }
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,+DAAiD;AAEjD,+CAAwD;AAyBxD;;;;;GAKG;AACH,MAAa,qBAAqB;IAKrB;IACA;IALF,oBAAoB,GAAG,IAAI,CAAC;IAC5B,QAAQ,GAAG,UAAU,CAAC;IAE/B,YACW,OAAe,EACf,OAAyB;QADzB,YAAO,GAAP,OAAO,CAAQ;QACf,YAAO,GAAP,OAAO,CAAkB;IACjC,CAAC;IAEJ,IAAI,aAAa;QACf,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAAmC;QAClD,MAAM,UAAU,GAAG,QAAQ,CAAC,eAAe,CAAC;YAC1C,mBAAmB,EAAE,YAAY;YACjC,GAAG,IAAI,CAAC,OAAO;SAChB,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,WAAY,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QACjF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,MAAM,2BAAkB,CAAC,YAAY,CAAC,kDAAkD,CAAC,CAAC;QAC5F,CAAC;QACD,IAAI,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AAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temporalio/ai-sdk",
3
- "version": "1.14.1",
3
+ "version": "1.14.2",
4
4
  "description": "Temporal AI SDK integration package",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -9,22 +9,21 @@
9
9
  "workflow",
10
10
  "ai",
11
11
  "ai-sdk",
12
- "llm",
13
- "embeddings"
12
+ "llm"
14
13
  ],
15
14
  "author": "Temporal Technologies Inc. <sdk@temporal.io>",
16
15
  "license": "MIT",
17
16
  "dependencies": {
18
- "@temporalio/plugin": "1.14.1",
19
- "@temporalio/workflow": "1.14.1",
20
17
  "@ungap/structured-clone": "^1.3.0",
21
18
  "headers-polyfill": "^4.0.3",
22
- "web-streams-polyfill": "^4.2.0"
19
+ "web-streams-polyfill": "^4.2.0",
20
+ "@temporalio/plugin": "1.14.2",
21
+ "@temporalio/workflow": "1.14.2"
23
22
  },
24
23
  "peerDependencies": {
25
- "@ai-sdk/mcp": "^1.0.0",
26
- "@ai-sdk/provider": "^3.0.0",
27
- "ai": "^6.0.0"
24
+ "@ai-sdk/mcp": "^0.0.8",
25
+ "@ai-sdk/provider": "^2.0.0",
26
+ "ai": "^5.0.91"
28
27
  },
29
28
  "engines": {
30
29
  "node": ">= 18.0.0"
@@ -44,6 +43,5 @@
44
43
  "files": [
45
44
  "src",
46
45
  "lib"
47
- ],
48
- "gitHead": "42bf6087946b7bbda61c7856bc0723c1616f9973"
49
- }
46
+ ]
47
+ }
package/src/activities.ts CHANGED
@@ -1,61 +1,47 @@
1
1
  import type {
2
- LanguageModelV3CallOptions,
3
- LanguageModelV3GenerateResult,
4
- EmbeddingModelV3Result,
5
- SharedV3ProviderOptions,
6
- SharedV3Headers,
7
- ProviderV3,
2
+ LanguageModelV2CallOptions,
3
+ LanguageModelV2CallWarning,
4
+ LanguageModelV2Content,
5
+ LanguageModelV2FinishReason,
6
+ LanguageModelV2ResponseMetadata,
7
+ LanguageModelV2Usage,
8
+ ProviderV2,
9
+ SharedV2Headers,
10
+ SharedV2ProviderMetadata,
8
11
  } from '@ai-sdk/provider';
9
- import type { FlexibleSchema, ToolExecutionOptions } from 'ai';
12
+ import type { ToolCallOptions } from 'ai';
10
13
  import { ApplicationFailure } from '@temporalio/common';
11
14
  import type { McpClientFactories, McpClientFactory } from './mcp';
12
15
 
13
- /**
14
- * Arguments for invoking a language model activity.
15
- */
16
16
  export interface InvokeModelArgs {
17
17
  modelId: string;
18
- options: LanguageModelV3CallOptions;
18
+ options: LanguageModelV2CallOptions;
19
19
  }
20
20
 
21
- /**
22
- * Result from a language model invocation.
23
- * This is an alias to the AI SDK's LanguageModelV3GenerateResult for type safety.
24
- */
25
- export type InvokeModelResult = LanguageModelV3GenerateResult;
26
-
27
- /**
28
- * Arguments for invoking an embedding model activity.
29
- * Note: AbortSignal is not included as it cannot be serialized across activity boundaries.
30
- * Temporal's workflow cancellation provides equivalent functionality.
31
- */
32
- export interface InvokeEmbeddingModelArgs {
33
- modelId: string;
34
- values: string[];
35
- providerOptions?: SharedV3ProviderOptions;
36
- headers?: SharedV3Headers;
21
+ export interface InvokeModelResult {
22
+ content: Array<LanguageModelV2Content>;
23
+ finishReason: LanguageModelV2FinishReason;
24
+ usage: LanguageModelV2Usage;
25
+ providerMetadata?: SharedV2ProviderMetadata;
26
+ request?: { body?: unknown };
27
+ response?: LanguageModelV2ResponseMetadata & { headers?: SharedV2Headers; body?: unknown };
28
+ warnings: Array<LanguageModelV2CallWarning>;
37
29
  }
38
30
 
39
- /**
40
- * Result from an embedding model invocation.
41
- * This is an alias to the AI SDK's EmbeddingModelV3Result for type safety.
42
- */
43
- export type InvokeEmbeddingModelResult = EmbeddingModelV3Result;
44
-
45
31
  export interface ListToolResult {
46
32
  description?: string;
47
- inputSchema: FlexibleSchema<unknown>;
33
+ inputSchema: any;
48
34
  }
49
35
 
50
36
  export interface ListToolArgs {
51
- clientArgs?: unknown;
37
+ clientArgs?: any;
52
38
  }
53
39
 
54
40
  export interface CallToolArgs {
55
- clientArgs?: unknown;
41
+ clientArgs?: any;
56
42
  name: string;
57
- input: unknown;
58
- options: ToolExecutionOptions;
43
+ args: any;
44
+ options: ToolCallOptions;
59
45
  }
60
46
 
61
47
  /**
@@ -69,20 +55,12 @@ export interface CallToolArgs {
69
55
  *
70
56
  * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
71
57
  */
72
- export function createActivities(provider: ProviderV3, mcpClientFactories?: McpClientFactories): object {
58
+ export function createActivities(provider: ProviderV2, mcpClientFactories?: McpClientFactories): object {
73
59
  let activities = {
74
60
  async invokeModel(args: InvokeModelArgs): Promise<InvokeModelResult> {
75
61
  const model = provider.languageModel(args.modelId);
76
62
  return await model.doGenerate(args.options);
77
63
  },
78
- async invokeEmbeddingModel(args: InvokeEmbeddingModelArgs): Promise<InvokeEmbeddingModelResult> {
79
- const model = provider.embeddingModel(args.modelId);
80
- return await model.doEmbed({
81
- values: args.values,
82
- providerOptions: args.providerOptions,
83
- headers: args.headers,
84
- });
85
- },
86
64
  };
87
65
  if (mcpClientFactories !== undefined) {
88
66
  Object.entries(mcpClientFactories).forEach(([name, func]) => {
@@ -114,7 +92,7 @@ function activitiesForName(name: string, mcpClientFactory: McpClientFactory): ob
114
92
  await mcpClient.close();
115
93
  }
116
94
  }
117
- async function callToolActivity(args: CallToolArgs): Promise<unknown> {
95
+ async function callToolActivity(args: CallToolArgs): Promise<any> {
118
96
  const mcpClient = await mcpClientFactory(args.clientArgs);
119
97
  try {
120
98
  const tools = await mcpClient.tools();
@@ -122,7 +100,7 @@ function activitiesForName(name: string, mcpClientFactory: McpClientFactory): ob
122
100
  if (tool === undefined) {
123
101
  throw ApplicationFailure.retryable(`Tool ${args.name} not found.`);
124
102
  }
125
- return tool.execute(args.input, args.options);
103
+ return tool.execute(args.args, args.options);
126
104
  } finally {
127
105
  await mcpClient.close();
128
106
  }
package/src/index.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  // eslint-disable-next-line import/no-unassigned-import
2
2
  import './load-polyfills';
3
3
 
4
- export * from './activities';
5
4
  export * from './mcp';
6
5
  export * from './plugin';
7
6
  export * from './provider';
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';
@@ -15,7 +14,8 @@ export type McpClientFactories = { [serviceName: string]: McpClientFactory };
15
14
  */
16
15
  export interface TemporalMCPClientOptions {
17
16
  readonly name: string;
18
- readonly clientArgs?: unknown;
17
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
18
+ readonly clientArgs?: any;
19
19
  readonly activityOptions?: ActivityOptions;
20
20
  }
21
21
 
@@ -32,10 +32,8 @@ export class TemporalMCPClient {
32
32
  constructor(readonly options: TemporalMCPClientOptions) {}
33
33
 
34
34
  async tools(): Promise<ToolSet> {
35
- const activities = workflow.proxyActivities({
36
- startToCloseTimeout: '10 minutes',
37
- ...this.options.activityOptions,
38
- });
35
+ workflow.log.info(`Options: ${this.options.activityOptions}`);
36
+ const activities = workflow.proxyActivities({ startToCloseTimeout: '10 minutes', ...this.options.activityOptions });
39
37
 
40
38
  const listActivity = activities[this.options.name + '-listTools'];
41
39
  const tools: Record<string, ListToolResult> = await listActivity!({ clientArgs: this.options.clientArgs });
@@ -43,16 +41,22 @@ export class TemporalMCPClient {
43
41
  Object.entries(tools).map(([toolName, toolResult]) => [
44
42
  toolName,
45
43
  {
46
- execute: async (input, options) => {
44
+ execute: async (args: any, options) => {
47
45
  const activities = workflow.proxyActivities({
48
46
  summary: toolName,
49
47
  startToCloseTimeout: '10 minutes',
50
48
  ...this.options,
51
49
  });
52
50
  const callActivity = activities[this.options.name + '-callTool']!;
53
- return await callActivity({ name: toolName, input, options, clientArgs: this.options.clientArgs });
51
+ return await callActivity({ name: toolName, args, options, clientArgs: this.options.clientArgs });
52
+ },
53
+ inputSchema: {
54
+ ...toolResult.inputSchema,
55
+ _type: undefined,
56
+ validate: undefined,
57
+ [Symbol.for('vercel.ai.schema')]: true,
58
+ [Symbol.for('vercel.ai.validator')]: true,
54
59
  },
55
- inputSchema: jsonSchema(toolResult.inputSchema as JSONSchema7),
56
60
  type: 'dynamic',
57
61
  },
58
62
  ])
package/src/plugin.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ProviderV3 } from '@ai-sdk/provider';
1
+ import type { ProviderV2 } from '@ai-sdk/provider';
2
2
  import { SimplePlugin } from '@temporalio/plugin';
3
3
  import { createActivities } from './activities';
4
4
  import type { McpClientFactories } from './mcp';
@@ -9,7 +9,7 @@ import type { McpClientFactories } from './mcp';
9
9
  * @experimental The AI SDK plugin is an experimental feature; APIs may change without notice.
10
10
  */
11
11
  export interface AiSdkPluginOptions {
12
- modelProvider: ProviderV3;
12
+ modelProvider: ProviderV2;
13
13
 
14
14
  /**
15
15
  * This object contains a mapping of server names to functions which create MCP clients.
package/src/provider.ts CHANGED
@@ -1,41 +1,15 @@
1
1
  import type {
2
- EmbeddingModelV3,
3
- EmbeddingModelV3CallOptions,
4
- EmbeddingModelV3Result,
5
- ImageModelV3,
6
- LanguageModelV3,
7
- LanguageModelV3CallOptions,
8
- LanguageModelV3GenerateResult,
9
- LanguageModelV3StreamResult,
10
- ProviderV3,
11
- TranscriptionModelV3,
2
+ EmbeddingModelV2,
3
+ ImageModelV2,
4
+ LanguageModelV2,
5
+ LanguageModelV2CallOptions,
6
+ ProviderV2,
7
+ SharedV2Headers,
12
8
  } from '@ai-sdk/provider';
13
9
  import * as workflow from '@temporalio/workflow';
14
- import type { ActivityOptions } from '@temporalio/workflow';
10
+ import { ActivityOptions } from '@temporalio/workflow';
15
11
  import { ApplicationFailure } from '@temporalio/common';
16
-
17
- /**
18
- * Options for configuring the TemporalProvider with per-model activity settings.
19
- */
20
- export interface TemporalProviderOptions {
21
- /**
22
- * Default activity options applied to all model types.
23
- * These can be overridden by model-specific options.
24
- */
25
- default?: ActivityOptions;
26
-
27
- /**
28
- * Activity options specific to language model calls.
29
- * Merged with default options, with these taking precedence.
30
- */
31
- languageModel?: ActivityOptions;
32
-
33
- /**
34
- * Activity options specific to embedding model calls.
35
- * Merged with default options, with these taking precedence.
36
- */
37
- embeddingModel?: ActivityOptions;
38
- }
12
+ import { InvokeModelResult } from './activities';
39
13
 
40
14
  /**
41
15
  * A language model implementation that delegates AI model calls to Temporal activities.
@@ -43,86 +17,37 @@ export interface TemporalProviderOptions {
43
17
  *
44
18
  * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
45
19
  */
46
- export class TemporalLanguageModel implements LanguageModelV3 {
47
- readonly specificationVersion = 'v3';
20
+ export class TemporalLanguageModel implements LanguageModelV2 {
21
+ readonly specificationVersion = 'v2';
48
22
  readonly provider = 'temporal';
23
+ readonly supportedUrls = {};
49
24
 
50
25
  constructor(
51
26
  readonly modelId: string,
52
27
  readonly options?: ActivityOptions
53
28
  ) {}
54
29
 
55
- get supportedUrls(): Record<string, RegExp[]> {
56
- return {};
57
- }
58
-
59
- async doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult> {
60
- const activities = workflow.proxyActivities({
61
- startToCloseTimeout: '10 minutes',
62
- ...this.options,
63
- });
30
+ async doGenerate(options: LanguageModelV2CallOptions): Promise<InvokeModelResult> {
31
+ const activities = workflow.proxyActivities({ startToCloseTimeout: '10 minutes', ...this.options });
64
32
  const result = await activities.invokeModel!({ modelId: this.modelId, options });
65
33
  if (result === undefined) {
66
34
  throw ApplicationFailure.nonRetryable('Received undefined response from model activity.');
67
35
  }
68
- if (result.response !== undefined && result.response.timestamp) {
69
- const timestamp = new Date(result.response.timestamp);
70
- // Only set if it's a valid date
71
- if (!isNaN(timestamp.getTime())) {
72
- result.response.timestamp = timestamp;
73
- }
36
+ if (result.response !== undefined) {
37
+ result.response.timestamp = new Date(result.response.timestamp);
74
38
  }
75
39
  return result;
76
40
  }
77
41
 
78
- doStream(_options: LanguageModelV3CallOptions): PromiseLike<LanguageModelV3StreamResult> {
42
+ doStream(_options: LanguageModelV2CallOptions): PromiseLike<{
43
+ stream: any;
44
+ request?: { body?: unknown };
45
+ response?: { headers?: SharedV2Headers };
46
+ }> {
79
47
  throw ApplicationFailure.nonRetryable('Streaming not supported.');
80
48
  }
81
49
  }
82
50
 
83
- /**
84
- * An embedding model implementation that delegates embedding generation to Temporal activities.
85
- * This allows workflows to generate embeddings through the Temporal execution model.
86
- *
87
- * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
88
- */
89
- export class TemporalEmbeddingModel implements EmbeddingModelV3 {
90
- readonly specificationVersion = 'v3';
91
- readonly provider = 'temporal';
92
- /**
93
- * Undefined to let the underlying provider handle chunking, as it knows its own limits.
94
- */
95
- readonly maxEmbeddingsPerCall = undefined;
96
- /**
97
- * Indicates the underlying embedding model API can handle concurrent requests.
98
- * Set to true since we delegate to the actual provider which manages its own concurrency.
99
- */
100
- readonly supportsParallelCalls = true;
101
-
102
- constructor(
103
- readonly modelId: string,
104
- readonly options?: ActivityOptions
105
- ) {}
106
-
107
- async doEmbed(options: EmbeddingModelV3CallOptions): Promise<EmbeddingModelV3Result> {
108
- const activities = workflow.proxyActivities({
109
- startToCloseTimeout: '10 minutes',
110
- ...this.options,
111
- });
112
- const result = await activities.invokeEmbeddingModel!({
113
- modelId: this.modelId,
114
- values: options.values,
115
- providerOptions: options.providerOptions,
116
- headers: options.headers,
117
- // Note: abortSignal is not serializable, Temporal's cancellation handles this
118
- });
119
- if (result === undefined) {
120
- throw ApplicationFailure.nonRetryable('Received undefined response from embedding model activity.');
121
- }
122
- return result;
123
- }
124
- }
125
-
126
51
  /**
127
52
  * A Temporal-specific provider implementation that creates AI models which execute
128
53
  * through Temporal activities. This provider integrates AI SDK models with Temporal's
@@ -130,30 +55,18 @@ export class TemporalEmbeddingModel implements EmbeddingModelV3 {
130
55
  *
131
56
  * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
132
57
  */
133
- export class TemporalProvider implements ProviderV3 {
134
- readonly specificationVersion = 'v3';
58
+ export class TemporalProvider implements ProviderV2 {
59
+ constructor(readonly options?: ActivityOptions) {}
135
60
 
136
- constructor(readonly options?: TemporalProviderOptions) {}
137
-
138
- imageModel(_modelId: string): ImageModelV3 {
61
+ imageModel(_modelId: string): ImageModelV2 {
139
62
  throw new Error('Not implemented');
140
63
  }
141
64
 
142
- languageModel(modelId: string): LanguageModelV3 {
143
- return new TemporalLanguageModel(modelId, {
144
- ...this.options?.default,
145
- ...this.options?.languageModel,
146
- });
147
- }
148
-
149
- embeddingModel(modelId: string): EmbeddingModelV3 {
150
- return new TemporalEmbeddingModel(modelId, {
151
- ...this.options?.default,
152
- ...this.options?.embeddingModel,
153
- });
65
+ languageModel(modelId: string): LanguageModelV2 {
66
+ return new TemporalLanguageModel(modelId, this.options);
154
67
  }
155
68
 
156
- transcriptionModel(_modelId: string): TranscriptionModelV3 {
69
+ textEmbeddingModel(_modelId: string): EmbeddingModelV2<string> {
157
70
  throw new Error('Not implemented');
158
71
  }
159
72
  }