@temporalio/ai-sdk 1.14.0 → 1.14.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.
@@ -1,36 +1,46 @@
1
- import type { LanguageModelV2CallOptions, LanguageModelV2CallWarning, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2ResponseMetadata, LanguageModelV2Usage, ProviderV2, SharedV2Headers, SharedV2ProviderMetadata } from '@ai-sdk/provider';
2
- import type { ToolCallOptions } from 'ai';
1
+ import type { LanguageModelV3CallOptions, LanguageModelV3GenerateResult, EmbeddingModelV3Result, SharedV3ProviderOptions, SharedV3Headers, ProviderV3 } from '@ai-sdk/provider';
2
+ import type { FlexibleSchema, ToolExecutionOptions } from 'ai';
3
3
  import type { McpClientFactories } from './mcp';
4
+ /**
5
+ * Arguments for invoking a language model activity.
6
+ */
4
7
  export interface InvokeModelArgs {
5
8
  modelId: string;
6
- options: LanguageModelV2CallOptions;
9
+ options: LanguageModelV3CallOptions;
7
10
  }
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>;
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;
21
26
  }
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;
22
32
  export interface ListToolResult {
23
33
  description?: string;
24
- inputSchema: any;
34
+ inputSchema: FlexibleSchema<unknown>;
25
35
  }
26
36
  export interface ListToolArgs {
27
- clientArgs?: any;
37
+ clientArgs?: unknown;
28
38
  }
29
39
  export interface CallToolArgs {
30
- clientArgs?: any;
40
+ clientArgs?: unknown;
31
41
  name: string;
32
- args: any;
33
- options: ToolCallOptions;
42
+ input: unknown;
43
+ options: ToolExecutionOptions;
34
44
  }
35
45
  /**
36
46
  * Creates Temporal activities for AI model invocation using the provided AI SDK provider.
@@ -43,4 +53,4 @@ export interface CallToolArgs {
43
53
  *
44
54
  * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
45
55
  */
46
- export declare function createActivities(provider: ProviderV2, mcpClientFactories?: McpClientFactories): object;
56
+ export declare function createActivities(provider: ProviderV3, mcpClientFactories?: McpClientFactories): object;
package/lib/activities.js CHANGED
@@ -19,6 +19,14 @@ 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
+ },
22
30
  };
23
31
  if (mcpClientFactories !== undefined) {
24
32
  Object.entries(mcpClientFactories).forEach(([name, func]) => {
@@ -55,7 +63,7 @@ function activitiesForName(name, mcpClientFactory) {
55
63
  if (tool === undefined) {
56
64
  throw common_1.ApplicationFailure.retryable(`Tool ${args.name} not found.`);
57
65
  }
58
- return tool.execute(args.args, args.options);
66
+ return tool.execute(args.input, args.options);
59
67
  }
60
68
  finally {
61
69
  await mcpClient.close();
@@ -1 +1 @@
1
- {"version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AkB;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,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAChD,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,4 +1,5 @@
1
1
  import './load-polyfills';
2
+ export * from './activities';
2
3
  export * from './mcp';
3
4
  export * from './plugin';
4
5
  export * from './provider';
package/lib/index.js CHANGED
@@ -16,6 +16,7 @@ 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);
19
20
  __exportStar(require("./mcp"), exports);
20
21
  __exportStar(require("./plugin"), exports);
21
22
  __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,wCAAsB;AACtB,2CAAyB;AACzB,6CAA2B"}
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"}
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?: any;
15
+ readonly clientArgs?: unknown;
16
16
  readonly activityOptions?: ActivityOptions;
17
17
  }
18
18
  /**
package/lib/mcp.js CHANGED
@@ -24,6 +24,7 @@ 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");
27
28
  const workflow = __importStar(require("@temporalio/workflow"));
28
29
  /**
29
30
  * A Temporal MCP Client which uses activities to execute list tools and call tools.
@@ -40,29 +41,25 @@ class TemporalMCPClient {
40
41
  this.options = options;
41
42
  }
42
43
  async tools() {
43
- workflow.log.info(`Options: ${this.options.activityOptions}`);
44
- const activities = workflow.proxyActivities({ startToCloseTimeout: '10 minutes', ...this.options.activityOptions });
44
+ const activities = workflow.proxyActivities({
45
+ startToCloseTimeout: '10 minutes',
46
+ ...this.options.activityOptions,
47
+ });
45
48
  const listActivity = activities[this.options.name + '-listTools'];
46
49
  const tools = await listActivity({ clientArgs: this.options.clientArgs });
47
50
  return Object.fromEntries(Object.entries(tools).map(([toolName, toolResult]) => [
48
51
  toolName,
49
52
  {
50
- execute: async (args, options) => {
53
+ execute: async (input, options) => {
51
54
  const activities = workflow.proxyActivities({
52
55
  summary: toolName,
53
56
  startToCloseTimeout: '10 minutes',
54
57
  ...this.options,
55
58
  });
56
59
  const callActivity = activities[this.options.name + '-callTool'];
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,
60
+ return await callActivity({ name: toolName, input, options, clientArgs: this.options.clientArgs });
65
61
  },
62
+ inputSchema: (0, ai_1.jsonSchema)(toolResult.inputSchema),
66
63
  type: 'dynamic',
67
64
  },
68
65
  ]));
package/lib/mcp.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,+DAAiD;AAmBjD;;;;;;;;GAQG;AACH,MAAa,iBAAiB;IACP;IAArB,YAAqB,OAAiC;QAAjC,YAAO,GAAP,OAAO,CAA0B;IAAG,CAAC;IAE1D,KAAK,CAAC,KAAK;QACT,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;QAC9D,MAAM,UAAU,GAAG,QAAQ,CAAC,eAAe,CAAC,EAAE,mBAAmB,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;QAEpH,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,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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,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;oBAChC,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,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;gBACrG,CAAC;gBACD,WAAW,EAAE,IAAA,eAAU,EAAC,UAAU,CAAC,WAA0B,CAAC;gBAC9D,IAAI,EAAE,SAAS;aAChB;SACF,CAAC,CACH,CAAC;IACJ,CAAC;CACF;AA9BD,8CA8BC"}
package/lib/plugin.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ProviderV2 } from '@ai-sdk/provider';
1
+ import type { ProviderV3 } 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: ProviderV2;
10
+ modelProvider: ProviderV3;
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,29 +1,63 @@
1
- import type { EmbeddingModelV2, ImageModelV2, LanguageModelV2, LanguageModelV2CallOptions, ProviderV2, SharedV2Headers } from '@ai-sdk/provider';
2
- import { ActivityOptions } from '@temporalio/workflow';
3
- import { InvokeModelResult } from './activities';
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
+ }
4
23
  /**
5
24
  * A language model implementation that delegates AI model calls to Temporal activities.
6
25
  * This allows workflows to invoke AI models through the Temporal execution model.
7
26
  *
8
27
  * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
9
28
  */
10
- export declare class TemporalLanguageModel implements LanguageModelV2 {
29
+ export declare class TemporalLanguageModel implements LanguageModelV3 {
11
30
  readonly modelId: string;
12
31
  readonly options?: ActivityOptions | undefined;
13
- readonly specificationVersion = "v2";
32
+ readonly specificationVersion = "v3";
14
33
  readonly provider = "temporal";
15
- readonly supportedUrls: {};
16
34
  constructor(modelId: string, options?: ActivityOptions | undefined);
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
- }>;
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>;
27
61
  }
28
62
  /**
29
63
  * A Temporal-specific provider implementation that creates AI models which execute
@@ -32,12 +66,14 @@ export declare class TemporalLanguageModel implements LanguageModelV2 {
32
66
  *
33
67
  * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
34
68
  */
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>;
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;
41
77
  }
42
78
  /**
43
79
  * 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.TemporalLanguageModel = void 0;
26
+ exports.temporalProvider = exports.TemporalProvider = exports.TemporalEmbeddingModel = exports.TemporalLanguageModel = void 0;
27
27
  const workflow = __importStar(require("@temporalio/workflow"));
28
28
  const common_1 = require("@temporalio/common");
29
29
  /**
@@ -35,21 +35,30 @@ const common_1 = require("@temporalio/common");
35
35
  class TemporalLanguageModel {
36
36
  modelId;
37
37
  options;
38
- specificationVersion = 'v2';
38
+ specificationVersion = 'v3';
39
39
  provider = 'temporal';
40
- supportedUrls = {};
41
40
  constructor(modelId, options) {
42
41
  this.modelId = modelId;
43
42
  this.options = options;
44
43
  }
44
+ get supportedUrls() {
45
+ return {};
46
+ }
45
47
  async doGenerate(options) {
46
- const activities = workflow.proxyActivities({ startToCloseTimeout: '10 minutes', ...this.options });
48
+ const activities = workflow.proxyActivities({
49
+ startToCloseTimeout: '10 minutes',
50
+ ...this.options,
51
+ });
47
52
  const result = await activities.invokeModel({ modelId: this.modelId, options });
48
53
  if (result === undefined) {
49
54
  throw common_1.ApplicationFailure.nonRetryable('Received undefined response from model activity.');
50
55
  }
51
- if (result.response !== undefined) {
52
- result.response.timestamp = new Date(result.response.timestamp);
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
+ }
53
62
  }
54
63
  return result;
55
64
  }
@@ -58,6 +67,49 @@ class TemporalLanguageModel {
58
67
  }
59
68
  }
60
69
  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;
61
113
  /**
62
114
  * A Temporal-specific provider implementation that creates AI models which execute
63
115
  * through Temporal activities. This provider integrates AI SDK models with Temporal's
@@ -67,6 +119,7 @@ exports.TemporalLanguageModel = TemporalLanguageModel;
67
119
  */
68
120
  class TemporalProvider {
69
121
  options;
122
+ specificationVersion = 'v3';
70
123
  constructor(options) {
71
124
  this.options = options;
72
125
  }
@@ -74,9 +127,18 @@ class TemporalProvider {
74
127
  throw new Error('Not implemented');
75
128
  }
76
129
  languageModel(modelId) {
77
- return new TemporalLanguageModel(modelId, this.options);
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
+ });
78
140
  }
79
- textEmbeddingModel(_modelId) {
141
+ transcriptionModel(_modelId) {
80
142
  throw new Error('Not implemented');
81
143
  }
82
144
  }
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,+DAAiD;AAEjD,+CAAwD;AAGxD;;;;;GAKG;AACH,MAAa,qBAAqB;IAMrB;IACA;IANF,oBAAoB,GAAG,IAAI,CAAC;IAC5B,QAAQ,GAAG,UAAU,CAAC;IACtB,aAAa,GAAG,EAAE,CAAC;IAE5B,YACW,OAAe,EACf,OAAyB;QADzB,YAAO,GAAP,OAAO,CAAQ;QACf,YAAO,GAAP,OAAO,CAAkB;IACjC,CAAC;IAEJ,KAAK,CAAC,UAAU,CAAC,OAAmC;QAClD,MAAM,UAAU,GAAG,QAAQ,CAAC,eAAe,CAAC,EAAE,mBAAmB,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACpG,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,WAAY,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QACjF,IAAI,MAAM,K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,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CACF;AA1BD,4CA0BC;AAED;;;;GAIG;AACU,QAAA,gBAAgB,GAAqB,IAAI,gBAAgB,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temporalio/ai-sdk",
3
- "version": "1.14.0",
3
+ "version": "1.14.1",
4
4
  "description": "Temporal AI SDK integration package",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -9,21 +9,22 @@
9
9
  "workflow",
10
10
  "ai",
11
11
  "ai-sdk",
12
- "llm"
12
+ "llm",
13
+ "embeddings"
13
14
  ],
14
15
  "author": "Temporal Technologies Inc. <sdk@temporal.io>",
15
16
  "license": "MIT",
16
17
  "dependencies": {
17
- "@temporalio/plugin": "1.14.0",
18
- "@temporalio/workflow": "1.14.0",
18
+ "@temporalio/plugin": "1.14.1",
19
+ "@temporalio/workflow": "1.14.1",
19
20
  "@ungap/structured-clone": "^1.3.0",
20
21
  "headers-polyfill": "^4.0.3",
21
22
  "web-streams-polyfill": "^4.2.0"
22
23
  },
23
24
  "peerDependencies": {
24
- "@ai-sdk/mcp": "^0.0.8",
25
- "@ai-sdk/provider": "^2.0.0",
26
- "ai": "^5.0.91"
25
+ "@ai-sdk/mcp": "^1.0.0",
26
+ "@ai-sdk/provider": "^3.0.0",
27
+ "ai": "^6.0.0"
27
28
  },
28
29
  "engines": {
29
30
  "node": ">= 18.0.0"
@@ -44,5 +45,5 @@
44
45
  "src",
45
46
  "lib"
46
47
  ],
47
- "gitHead": "eb428ac36568b48be67fdba662c38631867b932d"
48
+ "gitHead": "42bf6087946b7bbda61c7856bc0723c1616f9973"
48
49
  }
package/src/activities.ts CHANGED
@@ -1,47 +1,61 @@
1
1
  import type {
2
- LanguageModelV2CallOptions,
3
- LanguageModelV2CallWarning,
4
- LanguageModelV2Content,
5
- LanguageModelV2FinishReason,
6
- LanguageModelV2ResponseMetadata,
7
- LanguageModelV2Usage,
8
- ProviderV2,
9
- SharedV2Headers,
10
- SharedV2ProviderMetadata,
2
+ LanguageModelV3CallOptions,
3
+ LanguageModelV3GenerateResult,
4
+ EmbeddingModelV3Result,
5
+ SharedV3ProviderOptions,
6
+ SharedV3Headers,
7
+ ProviderV3,
11
8
  } from '@ai-sdk/provider';
12
- import type { ToolCallOptions } from 'ai';
9
+ import type { FlexibleSchema, ToolExecutionOptions } from 'ai';
13
10
  import { ApplicationFailure } from '@temporalio/common';
14
11
  import type { McpClientFactories, McpClientFactory } from './mcp';
15
12
 
13
+ /**
14
+ * Arguments for invoking a language model activity.
15
+ */
16
16
  export interface InvokeModelArgs {
17
17
  modelId: string;
18
- options: LanguageModelV2CallOptions;
18
+ options: LanguageModelV3CallOptions;
19
19
  }
20
20
 
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>;
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;
29
37
  }
30
38
 
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
+
31
45
  export interface ListToolResult {
32
46
  description?: string;
33
- inputSchema: any;
47
+ inputSchema: FlexibleSchema<unknown>;
34
48
  }
35
49
 
36
50
  export interface ListToolArgs {
37
- clientArgs?: any;
51
+ clientArgs?: unknown;
38
52
  }
39
53
 
40
54
  export interface CallToolArgs {
41
- clientArgs?: any;
55
+ clientArgs?: unknown;
42
56
  name: string;
43
- args: any;
44
- options: ToolCallOptions;
57
+ input: unknown;
58
+ options: ToolExecutionOptions;
45
59
  }
46
60
 
47
61
  /**
@@ -55,12 +69,20 @@ export interface CallToolArgs {
55
69
  *
56
70
  * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
57
71
  */
58
- export function createActivities(provider: ProviderV2, mcpClientFactories?: McpClientFactories): object {
72
+ export function createActivities(provider: ProviderV3, mcpClientFactories?: McpClientFactories): object {
59
73
  let activities = {
60
74
  async invokeModel(args: InvokeModelArgs): Promise<InvokeModelResult> {
61
75
  const model = provider.languageModel(args.modelId);
62
76
  return await model.doGenerate(args.options);
63
77
  },
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
+ },
64
86
  };
65
87
  if (mcpClientFactories !== undefined) {
66
88
  Object.entries(mcpClientFactories).forEach(([name, func]) => {
@@ -92,7 +114,7 @@ function activitiesForName(name: string, mcpClientFactory: McpClientFactory): ob
92
114
  await mcpClient.close();
93
115
  }
94
116
  }
95
- async function callToolActivity(args: CallToolArgs): Promise<any> {
117
+ async function callToolActivity(args: CallToolArgs): Promise<unknown> {
96
118
  const mcpClient = await mcpClientFactory(args.clientArgs);
97
119
  try {
98
120
  const tools = await mcpClient.tools();
@@ -100,7 +122,7 @@ function activitiesForName(name: string, mcpClientFactory: McpClientFactory): ob
100
122
  if (tool === undefined) {
101
123
  throw ApplicationFailure.retryable(`Tool ${args.name} not found.`);
102
124
  }
103
- return tool.execute(args.args, args.options);
125
+ return tool.execute(args.input, args.options);
104
126
  } finally {
105
127
  await mcpClient.close();
106
128
  }
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  // eslint-disable-next-line import/no-unassigned-import
2
2
  import './load-polyfills';
3
3
 
4
+ export * from './activities';
4
5
  export * from './mcp';
5
6
  export * from './plugin';
6
7
  export * from './provider';
package/src/mcp.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { ToolSet } from 'ai';
1
+ import { jsonSchema, type ToolSet } from 'ai';
2
+ import type { JSONSchema7 } from '@ai-sdk/provider';
2
3
  import type { experimental_MCPClient as MCPClient } from '@ai-sdk/mcp';
3
4
  import * as workflow from '@temporalio/workflow';
4
5
  import type { ActivityOptions } from '@temporalio/workflow';
@@ -14,8 +15,7 @@ export type McpClientFactories = { [serviceName: string]: McpClientFactory };
14
15
  */
15
16
  export interface TemporalMCPClientOptions {
16
17
  readonly name: string;
17
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
18
- readonly clientArgs?: any;
18
+ readonly clientArgs?: unknown;
19
19
  readonly activityOptions?: ActivityOptions;
20
20
  }
21
21
 
@@ -32,8 +32,10 @@ export class TemporalMCPClient {
32
32
  constructor(readonly options: TemporalMCPClientOptions) {}
33
33
 
34
34
  async tools(): Promise<ToolSet> {
35
- workflow.log.info(`Options: ${this.options.activityOptions}`);
36
- const activities = workflow.proxyActivities({ startToCloseTimeout: '10 minutes', ...this.options.activityOptions });
35
+ const activities = workflow.proxyActivities({
36
+ startToCloseTimeout: '10 minutes',
37
+ ...this.options.activityOptions,
38
+ });
37
39
 
38
40
  const listActivity = activities[this.options.name + '-listTools'];
39
41
  const tools: Record<string, ListToolResult> = await listActivity!({ clientArgs: this.options.clientArgs });
@@ -41,22 +43,16 @@ export class TemporalMCPClient {
41
43
  Object.entries(tools).map(([toolName, toolResult]) => [
42
44
  toolName,
43
45
  {
44
- execute: async (args: any, options) => {
46
+ execute: async (input, options) => {
45
47
  const activities = workflow.proxyActivities({
46
48
  summary: toolName,
47
49
  startToCloseTimeout: '10 minutes',
48
50
  ...this.options,
49
51
  });
50
52
  const callActivity = activities[this.options.name + '-callTool']!;
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,
53
+ return await callActivity({ name: toolName, input, options, clientArgs: this.options.clientArgs });
59
54
  },
55
+ inputSchema: jsonSchema(toolResult.inputSchema as JSONSchema7),
60
56
  type: 'dynamic',
61
57
  },
62
58
  ])
package/src/plugin.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ProviderV2 } from '@ai-sdk/provider';
1
+ import type { ProviderV3 } 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: ProviderV2;
12
+ modelProvider: ProviderV3;
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,15 +1,41 @@
1
1
  import type {
2
- EmbeddingModelV2,
3
- ImageModelV2,
4
- LanguageModelV2,
5
- LanguageModelV2CallOptions,
6
- ProviderV2,
7
- SharedV2Headers,
2
+ EmbeddingModelV3,
3
+ EmbeddingModelV3CallOptions,
4
+ EmbeddingModelV3Result,
5
+ ImageModelV3,
6
+ LanguageModelV3,
7
+ LanguageModelV3CallOptions,
8
+ LanguageModelV3GenerateResult,
9
+ LanguageModelV3StreamResult,
10
+ ProviderV3,
11
+ TranscriptionModelV3,
8
12
  } from '@ai-sdk/provider';
9
13
  import * as workflow from '@temporalio/workflow';
10
- import { ActivityOptions } from '@temporalio/workflow';
14
+ import type { ActivityOptions } from '@temporalio/workflow';
11
15
  import { ApplicationFailure } from '@temporalio/common';
12
- import { InvokeModelResult } from './activities';
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
+ }
13
39
 
14
40
  /**
15
41
  * A language model implementation that delegates AI model calls to Temporal activities.
@@ -17,37 +43,86 @@ import { InvokeModelResult } from './activities';
17
43
  *
18
44
  * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
19
45
  */
20
- export class TemporalLanguageModel implements LanguageModelV2 {
21
- readonly specificationVersion = 'v2';
46
+ export class TemporalLanguageModel implements LanguageModelV3 {
47
+ readonly specificationVersion = 'v3';
22
48
  readonly provider = 'temporal';
23
- readonly supportedUrls = {};
24
49
 
25
50
  constructor(
26
51
  readonly modelId: string,
27
52
  readonly options?: ActivityOptions
28
53
  ) {}
29
54
 
30
- async doGenerate(options: LanguageModelV2CallOptions): Promise<InvokeModelResult> {
31
- const activities = workflow.proxyActivities({ startToCloseTimeout: '10 minutes', ...this.options });
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
+ });
32
64
  const result = await activities.invokeModel!({ modelId: this.modelId, options });
33
65
  if (result === undefined) {
34
66
  throw ApplicationFailure.nonRetryable('Received undefined response from model activity.');
35
67
  }
36
- if (result.response !== undefined) {
37
- result.response.timestamp = new Date(result.response.timestamp);
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
+ }
38
74
  }
39
75
  return result;
40
76
  }
41
77
 
42
- doStream(_options: LanguageModelV2CallOptions): PromiseLike<{
43
- stream: any;
44
- request?: { body?: unknown };
45
- response?: { headers?: SharedV2Headers };
46
- }> {
78
+ doStream(_options: LanguageModelV3CallOptions): PromiseLike<LanguageModelV3StreamResult> {
47
79
  throw ApplicationFailure.nonRetryable('Streaming not supported.');
48
80
  }
49
81
  }
50
82
 
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
+
51
126
  /**
52
127
  * A Temporal-specific provider implementation that creates AI models which execute
53
128
  * through Temporal activities. This provider integrates AI SDK models with Temporal's
@@ -55,18 +130,30 @@ export class TemporalLanguageModel implements LanguageModelV2 {
55
130
  *
56
131
  * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
57
132
  */
58
- export class TemporalProvider implements ProviderV2 {
59
- constructor(readonly options?: ActivityOptions) {}
133
+ export class TemporalProvider implements ProviderV3 {
134
+ readonly specificationVersion = 'v3';
60
135
 
61
- imageModel(_modelId: string): ImageModelV2 {
136
+ constructor(readonly options?: TemporalProviderOptions) {}
137
+
138
+ imageModel(_modelId: string): ImageModelV3 {
62
139
  throw new Error('Not implemented');
63
140
  }
64
141
 
65
- languageModel(modelId: string): LanguageModelV2 {
66
- return new TemporalLanguageModel(modelId, this.options);
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
+ });
67
154
  }
68
155
 
69
- textEmbeddingModel(_modelId: string): EmbeddingModelV2<string> {
156
+ transcriptionModel(_modelId: string): TranscriptionModelV3 {
70
157
  throw new Error('Not implemented');
71
158
  }
72
159
  }