@temporalio/ai-sdk 1.14.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2021-2025 Temporal Technologies Inc. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ import type { LanguageModelV2CallOptions, LanguageModelV2CallWarning, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2ResponseMetadata, LanguageModelV2Usage, ProviderV2, SharedV2Headers, SharedV2ProviderMetadata } from '@ai-sdk/provider';
2
+ import type { ToolCallOptions } from 'ai';
3
+ import type { McpClientFactories } from './mcp';
4
+ export interface InvokeModelArgs {
5
+ modelId: string;
6
+ options: LanguageModelV2CallOptions;
7
+ }
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>;
21
+ }
22
+ export interface ListToolResult {
23
+ description?: string;
24
+ inputSchema: any;
25
+ }
26
+ export interface ListToolArgs {
27
+ clientArgs?: any;
28
+ }
29
+ export interface CallToolArgs {
30
+ clientArgs?: any;
31
+ name: string;
32
+ args: any;
33
+ options: ToolCallOptions;
34
+ }
35
+ /**
36
+ * Creates Temporal activities for AI model invocation using the provided AI SDK provider.
37
+ * These activities allow workflows to call AI models while maintaining Temporal's
38
+ * execution guarantees and replay safety.
39
+ *
40
+ * @param provider The AI SDK provider to use for model invocations
41
+ * @param mcpClientFactories A mapping of server names to functions to create mcp clients
42
+ * @returns An object containing the activity functions
43
+ *
44
+ * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
45
+ */
46
+ export declare function createActivities(provider: ProviderV2, mcpClientFactories?: McpClientFactories): object;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createActivities = createActivities;
4
+ const common_1 = require("@temporalio/common");
5
+ /**
6
+ * Creates Temporal activities for AI model invocation using the provided AI SDK provider.
7
+ * These activities allow workflows to call AI models while maintaining Temporal's
8
+ * execution guarantees and replay safety.
9
+ *
10
+ * @param provider The AI SDK provider to use for model invocations
11
+ * @param mcpClientFactories A mapping of server names to functions to create mcp clients
12
+ * @returns An object containing the activity functions
13
+ *
14
+ * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
15
+ */
16
+ function createActivities(provider, mcpClientFactories) {
17
+ let activities = {
18
+ async invokeModel(args) {
19
+ const model = provider.languageModel(args.modelId);
20
+ return await model.doGenerate(args.options);
21
+ },
22
+ };
23
+ if (mcpClientFactories !== undefined) {
24
+ Object.entries(mcpClientFactories).forEach(([name, func]) => {
25
+ activities = {
26
+ ...activities,
27
+ ...activitiesForName(name, func),
28
+ };
29
+ });
30
+ }
31
+ return activities;
32
+ }
33
+ function activitiesForName(name, mcpClientFactory) {
34
+ async function listToolsActivity(args) {
35
+ const mcpClient = await mcpClientFactory(args.clientArgs);
36
+ try {
37
+ const tools = await mcpClient.tools();
38
+ return Object.fromEntries(Object.entries(tools).map(([k, v]) => [
39
+ k,
40
+ {
41
+ description: v.description,
42
+ inputSchema: v.inputSchema,
43
+ },
44
+ ]));
45
+ }
46
+ finally {
47
+ await mcpClient.close();
48
+ }
49
+ }
50
+ async function callToolActivity(args) {
51
+ const mcpClient = await mcpClientFactory(args.clientArgs);
52
+ try {
53
+ const tools = await mcpClient.tools();
54
+ const tool = tools[args.name];
55
+ if (tool === undefined) {
56
+ throw common_1.ApplicationFailure.retryable(`Tool ${args.name} not found.`);
57
+ }
58
+ return tool.execute(args.args, args.options);
59
+ }
60
+ finally {
61
+ await mcpClient.close();
62
+ }
63
+ }
64
+ return {
65
+ [name + '-listTools']: listToolsActivity,
66
+ [name + '-callTool']: callToolActivity,
67
+ };
68
+ }
69
+ //# sourceMappingURL=activities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activities.js","sourceRoot":"","sources":["../src/activities.ts"],"names":[],"mappings":";;AAyDA,4CAgBC;AA7DD,+CAAwD;AAkCxD;;;;;;;;;;GAUG;AACH,SAAgB,gBAAgB,CAAC,QAAoB,EAAE,kBAAuC;IAC5F,IAAI,UAAU,GAAG;QACf,KAAK,CAAC,WAAW,CAAC,IAAqB;YACrC,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACnD,OAAO,MAAM,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9C,CAAC;KACF,CAAC;IACF,IAAI,kBAAkB,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;YAC1D,UAAU,GAAG;gBACX,GAAG,UAAU;gBACb,GAAG,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC;aACjC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAY,EAAE,gBAAkC;IACzE,KAAK,UAAU,iBAAiB,CAAC,IAAkB;QACjD,MAAM,SAAS,GAAG,MAAM,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1D,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;YAEtC,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;gBACpC,CAAC;gBACD;oBACE,WAAW,EAAE,CAAC,CAAC,WAAW;oBAC1B,WAAW,EAAE,CAAC,CAAC,WAAW;iBAC3B;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,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 ADDED
@@ -0,0 +1,4 @@
1
+ import './load-polyfills';
2
+ export * from './mcp';
3
+ export * from './plugin';
4
+ export * from './provider';
package/lib/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // eslint-disable-next-line import/no-unassigned-import
18
+ require("./load-polyfills");
19
+ __exportStar(require("./mcp"), exports);
20
+ __exportStar(require("./plugin"), exports);
21
+ __exportStar(require("./provider"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,4BAA0B;AAE1B,wCAAsB;AACtB,2CAAyB;AACzB,6CAA2B"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const headers_polyfill_1 = require("headers-polyfill");
4
+ const workflow_1 = require("@temporalio/workflow");
5
+ if ((0, workflow_1.inWorkflowContext)()) {
6
+ // Apply Headers polyfill
7
+ if (typeof globalThis.Headers === 'undefined') {
8
+ globalThis.Headers = headers_polyfill_1.Headers;
9
+ }
10
+ // eslint-disable-next-line @typescript-eslint/no-require-imports,import/no-unassigned-import
11
+ require('web-streams-polyfill/polyfill');
12
+ // Attach the polyfill as a Global function
13
+ if (!('structuredClone' in globalThis)) {
14
+ // eslint-disable-next-line @typescript-eslint/no-require-imports,import/no-unassigned-import
15
+ const structuredClone = require('@ungap/structured-clone');
16
+ globalThis.structuredClone = structuredClone.default;
17
+ }
18
+ }
19
+ //# sourceMappingURL=load-polyfills.js.map
@@ -0,0 +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"}
package/lib/mcp.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import type { ToolSet } from 'ai';
2
+ import type { experimental_MCPClient as MCPClient } from '@ai-sdk/mcp';
3
+ import type { ActivityOptions } from '@temporalio/workflow';
4
+ export type McpClientFactory = (args: unknown) => Promise<MCPClient>;
5
+ export type McpClientFactories = {
6
+ [serviceName: string]: McpClientFactory;
7
+ };
8
+ /**
9
+ * Options for the Temporal MCP Client
10
+ *
11
+ * @experimental The AI SDK plugin is an experimental feature; APIs may change without notice.
12
+ */
13
+ export interface TemporalMCPClientOptions {
14
+ readonly name: string;
15
+ readonly clientArgs?: any;
16
+ readonly activityOptions?: ActivityOptions;
17
+ }
18
+ /**
19
+ * A Temporal MCP Client which uses activities to execute list tools and call tools.
20
+ * This should match by name an MCPClientFactory registered with the AI SDK plugin to function.
21
+ *
22
+ * This is intentionally similar to the AI SDK's ``MCPClient``, but is lacking functions not used by the framework.
23
+ * It doesn't close either since the underlying clients are created in activities.
24
+ *
25
+ * @experimental The AI SDK plugin is an experimental feature; APIs may change without notice.
26
+ */
27
+ export declare class TemporalMCPClient {
28
+ readonly options: TemporalMCPClientOptions;
29
+ constructor(options: TemporalMCPClientOptions);
30
+ tools(): Promise<ToolSet>;
31
+ }
package/lib/mcp.js ADDED
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.TemporalMCPClient = void 0;
27
+ const workflow = __importStar(require("@temporalio/workflow"));
28
+ /**
29
+ * A Temporal MCP Client which uses activities to execute list tools and call tools.
30
+ * This should match by name an MCPClientFactory registered with the AI SDK plugin to function.
31
+ *
32
+ * This is intentionally similar to the AI SDK's ``MCPClient``, but is lacking functions not used by the framework.
33
+ * It doesn't close either since the underlying clients are created in activities.
34
+ *
35
+ * @experimental The AI SDK plugin is an experimental feature; APIs may change without notice.
36
+ */
37
+ class TemporalMCPClient {
38
+ options;
39
+ constructor(options) {
40
+ this.options = options;
41
+ }
42
+ async tools() {
43
+ workflow.log.info(`Options: ${this.options.activityOptions}`);
44
+ const activities = workflow.proxyActivities({ startToCloseTimeout: '10 minutes', ...this.options.activityOptions });
45
+ const listActivity = activities[this.options.name + '-listTools'];
46
+ const tools = await listActivity({ clientArgs: this.options.clientArgs });
47
+ return Object.fromEntries(Object.entries(tools).map(([toolName, toolResult]) => [
48
+ toolName,
49
+ {
50
+ execute: async (args, options) => {
51
+ const activities = workflow.proxyActivities({
52
+ summary: toolName,
53
+ startToCloseTimeout: '10 minutes',
54
+ ...this.options,
55
+ });
56
+ 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,
65
+ },
66
+ type: 'dynamic',
67
+ },
68
+ ]));
69
+ }
70
+ }
71
+ exports.TemporalMCPClient = TemporalMCPClient;
72
+ //# sourceMappingURL=mcp.js.map
package/lib/mcp.js.map ADDED
@@ -0,0 +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,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"}
@@ -0,0 +1,25 @@
1
+ import type { ProviderV2 } from '@ai-sdk/provider';
2
+ import { SimplePlugin } from '@temporalio/plugin';
3
+ import type { McpClientFactories } from './mcp';
4
+ /**
5
+ * Options for the AI SDK plugin
6
+ *
7
+ * @experimental The AI SDK plugin is an experimental feature; APIs may change without notice.
8
+ */
9
+ export interface AiSdkPluginOptions {
10
+ modelProvider: ProviderV2;
11
+ /**
12
+ * This object contains a mapping of server names to functions which create MCP clients.
13
+ * Any TemporalMCPClient used in a workflow should have its associated servername listed in this object.
14
+ */
15
+ mcpClientFactories?: McpClientFactories;
16
+ }
17
+ /**
18
+ * A Temporal plugin that integrates AI SDK providers for use in workflows.
19
+ * This plugin creates activities that allow workflows to invoke AI models.
20
+ *
21
+ * @experimental The AI SDK plugin is an experimental feature; APIs may change without notice.
22
+ */
23
+ export declare class AiSdkPlugin extends SimplePlugin {
24
+ constructor(options: AiSdkPluginOptions);
25
+ }
package/lib/plugin.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AiSdkPlugin = void 0;
4
+ const plugin_1 = require("@temporalio/plugin");
5
+ const activities_1 = require("./activities");
6
+ /**
7
+ * A Temporal plugin that integrates AI SDK providers for use in workflows.
8
+ * This plugin creates activities that allow workflows to invoke AI models.
9
+ *
10
+ * @experimental The AI SDK plugin is an experimental feature; APIs may change without notice.
11
+ */
12
+ class AiSdkPlugin extends plugin_1.SimplePlugin {
13
+ constructor(options) {
14
+ super({
15
+ name: 'AiSDKPlugin',
16
+ activities: (0, activities_1.createActivities)(options.modelProvider, options.mcpClientFactories),
17
+ });
18
+ }
19
+ }
20
+ exports.AiSdkPlugin = AiSdkPlugin;
21
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;AACA,+CAAkD;AAClD,6CAAgD;AAkBhD;;;;;GAKG;AACH,MAAa,WAAY,SAAQ,qBAAY;IAC3C,YAAY,OAA2B;QACrC,KAAK,CAAC;YACJ,IAAI,EAAE,aAAa;YACnB,UAAU,EAAE,IAAA,6BAAgB,EAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,kBAAkB,CAAC;SAChF,CAAC,CAAC;IACL,CAAC;CACF;AAPD,kCAOC"}
@@ -0,0 +1,47 @@
1
+ import type { EmbeddingModelV2, ImageModelV2, LanguageModelV2, LanguageModelV2CallOptions, ProviderV2, SharedV2Headers } from '@ai-sdk/provider';
2
+ import { ActivityOptions } from '@temporalio/workflow';
3
+ import { InvokeModelResult } from './activities';
4
+ /**
5
+ * A language model implementation that delegates AI model calls to Temporal activities.
6
+ * This allows workflows to invoke AI models through the Temporal execution model.
7
+ *
8
+ * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
9
+ */
10
+ export declare class TemporalLanguageModel implements LanguageModelV2 {
11
+ readonly modelId: string;
12
+ readonly options?: ActivityOptions | undefined;
13
+ readonly specificationVersion = "v2";
14
+ readonly provider = "temporal";
15
+ readonly supportedUrls: {};
16
+ 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
+ }>;
27
+ }
28
+ /**
29
+ * A Temporal-specific provider implementation that creates AI models which execute
30
+ * through Temporal activities. This provider integrates AI SDK models with Temporal's
31
+ * execution model to ensure reliable, durable AI model invocations.
32
+ *
33
+ * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
34
+ */
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>;
41
+ }
42
+ /**
43
+ * A singleton instance of TemporalProvider for convenient use in applications.
44
+ *
45
+ * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
46
+ */
47
+ export declare const temporalProvider: TemporalProvider;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.temporalProvider = exports.TemporalProvider = exports.TemporalLanguageModel = void 0;
27
+ const workflow = __importStar(require("@temporalio/workflow"));
28
+ const common_1 = require("@temporalio/common");
29
+ /**
30
+ * A language model implementation that delegates AI model calls to Temporal activities.
31
+ * This allows workflows to invoke AI models through the Temporal execution model.
32
+ *
33
+ * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
34
+ */
35
+ class TemporalLanguageModel {
36
+ modelId;
37
+ options;
38
+ specificationVersion = 'v2';
39
+ provider = 'temporal';
40
+ supportedUrls = {};
41
+ constructor(modelId, options) {
42
+ this.modelId = modelId;
43
+ this.options = options;
44
+ }
45
+ async doGenerate(options) {
46
+ const activities = workflow.proxyActivities({ startToCloseTimeout: '10 minutes', ...this.options });
47
+ const result = await activities.invokeModel({ modelId: this.modelId, options });
48
+ if (result === undefined) {
49
+ throw common_1.ApplicationFailure.nonRetryable('Received undefined response from model activity.');
50
+ }
51
+ if (result.response !== undefined) {
52
+ result.response.timestamp = new Date(result.response.timestamp);
53
+ }
54
+ return result;
55
+ }
56
+ doStream(_options) {
57
+ throw common_1.ApplicationFailure.nonRetryable('Streaming not supported.');
58
+ }
59
+ }
60
+ exports.TemporalLanguageModel = TemporalLanguageModel;
61
+ /**
62
+ * A Temporal-specific provider implementation that creates AI models which execute
63
+ * through Temporal activities. This provider integrates AI SDK models with Temporal's
64
+ * execution model to ensure reliable, durable AI model invocations.
65
+ *
66
+ * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
67
+ */
68
+ class TemporalProvider {
69
+ options;
70
+ constructor(options) {
71
+ this.options = options;
72
+ }
73
+ imageModel(_modelId) {
74
+ throw new Error('Not implemented');
75
+ }
76
+ languageModel(modelId) {
77
+ return new TemporalLanguageModel(modelId, this.options);
78
+ }
79
+ textEmbeddingModel(_modelId) {
80
+ throw new Error('Not implemented');
81
+ }
82
+ }
83
+ exports.TemporalProvider = TemporalProvider;
84
+ /**
85
+ * A singleton instance of TemporalProvider for convenient use in applications.
86
+ *
87
+ * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
88
+ */
89
+ exports.temporalProvider = new TemporalProvider();
90
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +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,KAAK,SAAS,EAAE,CAAC;YACzB,MAAM,2BAAkB,CAAC,YAAY,CAAC,kDAAkD,CAAC,CAAC;QAC5F,CAAC;QACD,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YAClC,MAAM,CAAC,QAAQ,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAClE,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,QAAQ,CAAC,QAAoC;QAK3C,MAAM,2BAAkB,CAAC,YAAY,CAAC,0BAA0B,CAAC,CAAC;IACpE,CAAC;CACF;AA7BD,sDA6BC;AAED;;;;;;GAMG;AACH,MAAa,gBAAgB;IACN;IAArB,YAAqB,OAAyB;QAAzB,YAAO,GAAP,OAAO,CAAkB;IAAG,CAAC;IAElD,UAAU,CAAC,QAAgB;QACzB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,aAAa,CAAC,OAAe;QAC3B,OAAO,IAAI,qBAAqB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,kBAAkB,CAAC,QAAgB;QACjC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CACF;AAdD,4CAcC;AAED;;;;GAIG;AACU,QAAA,gBAAgB,GAAqB,IAAI,gBAAgB,EAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@temporalio/ai-sdk",
3
+ "version": "1.14.0",
4
+ "description": "Temporal AI SDK integration package",
5
+ "main": "lib/index.js",
6
+ "types": "./lib/index.d.ts",
7
+ "keywords": [
8
+ "temporal",
9
+ "workflow",
10
+ "ai",
11
+ "ai-sdk",
12
+ "llm"
13
+ ],
14
+ "author": "Temporal Technologies Inc. <sdk@temporal.io>",
15
+ "license": "MIT",
16
+ "dependencies": {
17
+ "@temporalio/plugin": "1.14.0",
18
+ "@temporalio/workflow": "1.14.0",
19
+ "@ungap/structured-clone": "^1.3.0",
20
+ "headers-polyfill": "^4.0.3",
21
+ "web-streams-polyfill": "^4.2.0"
22
+ },
23
+ "peerDependencies": {
24
+ "@ai-sdk/mcp": "^0.0.8",
25
+ "@ai-sdk/provider": "^2.0.0",
26
+ "ai": "^5.0.91"
27
+ },
28
+ "engines": {
29
+ "node": ">= 18.0.0"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/temporalio/sdk-typescript/issues"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/temporalio/sdk-typescript.git",
37
+ "directory": "packages/ai-sdk"
38
+ },
39
+ "homepage": "https://github.com/temporalio/sdk-typescript/tree/main/packages/ai-sdk",
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "files": [
44
+ "src",
45
+ "lib"
46
+ ],
47
+ "gitHead": "eb428ac36568b48be67fdba662c38631867b932d"
48
+ }
@@ -0,0 +1,112 @@
1
+ import type {
2
+ LanguageModelV2CallOptions,
3
+ LanguageModelV2CallWarning,
4
+ LanguageModelV2Content,
5
+ LanguageModelV2FinishReason,
6
+ LanguageModelV2ResponseMetadata,
7
+ LanguageModelV2Usage,
8
+ ProviderV2,
9
+ SharedV2Headers,
10
+ SharedV2ProviderMetadata,
11
+ } from '@ai-sdk/provider';
12
+ import type { ToolCallOptions } from 'ai';
13
+ import { ApplicationFailure } from '@temporalio/common';
14
+ import type { McpClientFactories, McpClientFactory } from './mcp';
15
+
16
+ export interface InvokeModelArgs {
17
+ modelId: string;
18
+ options: LanguageModelV2CallOptions;
19
+ }
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>;
29
+ }
30
+
31
+ export interface ListToolResult {
32
+ description?: string;
33
+ inputSchema: any;
34
+ }
35
+
36
+ export interface ListToolArgs {
37
+ clientArgs?: any;
38
+ }
39
+
40
+ export interface CallToolArgs {
41
+ clientArgs?: any;
42
+ name: string;
43
+ args: any;
44
+ options: ToolCallOptions;
45
+ }
46
+
47
+ /**
48
+ * Creates Temporal activities for AI model invocation using the provided AI SDK provider.
49
+ * These activities allow workflows to call AI models while maintaining Temporal's
50
+ * execution guarantees and replay safety.
51
+ *
52
+ * @param provider The AI SDK provider to use for model invocations
53
+ * @param mcpClientFactories A mapping of server names to functions to create mcp clients
54
+ * @returns An object containing the activity functions
55
+ *
56
+ * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
57
+ */
58
+ export function createActivities(provider: ProviderV2, mcpClientFactories?: McpClientFactories): object {
59
+ let activities = {
60
+ async invokeModel(args: InvokeModelArgs): Promise<InvokeModelResult> {
61
+ const model = provider.languageModel(args.modelId);
62
+ return await model.doGenerate(args.options);
63
+ },
64
+ };
65
+ if (mcpClientFactories !== undefined) {
66
+ Object.entries(mcpClientFactories).forEach(([name, func]) => {
67
+ activities = {
68
+ ...activities,
69
+ ...activitiesForName(name, func),
70
+ };
71
+ });
72
+ }
73
+ return activities;
74
+ }
75
+
76
+ function activitiesForName(name: string, mcpClientFactory: McpClientFactory): object {
77
+ async function listToolsActivity(args: ListToolArgs): Promise<Record<string, ListToolResult>> {
78
+ const mcpClient = await mcpClientFactory(args.clientArgs);
79
+ try {
80
+ const tools = await mcpClient.tools();
81
+
82
+ return Object.fromEntries(
83
+ Object.entries(tools).map(([k, v]) => [
84
+ k,
85
+ {
86
+ description: v.description,
87
+ inputSchema: v.inputSchema,
88
+ },
89
+ ])
90
+ );
91
+ } finally {
92
+ await mcpClient.close();
93
+ }
94
+ }
95
+ async function callToolActivity(args: CallToolArgs): Promise<any> {
96
+ const mcpClient = await mcpClientFactory(args.clientArgs);
97
+ try {
98
+ const tools = await mcpClient.tools();
99
+ const tool = tools[args.name];
100
+ if (tool === undefined) {
101
+ throw ApplicationFailure.retryable(`Tool ${args.name} not found.`);
102
+ }
103
+ return tool.execute(args.args, args.options);
104
+ } finally {
105
+ await mcpClient.close();
106
+ }
107
+ }
108
+ return {
109
+ [name + '-listTools']: listToolsActivity,
110
+ [name + '-callTool']: callToolActivity,
111
+ };
112
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ // eslint-disable-next-line import/no-unassigned-import
2
+ import './load-polyfills';
3
+
4
+ export * from './mcp';
5
+ export * from './plugin';
6
+ export * from './provider';
@@ -0,0 +1,18 @@
1
+ import { Headers } from 'headers-polyfill';
2
+ import { inWorkflowContext } from '@temporalio/workflow';
3
+
4
+ if (inWorkflowContext()) {
5
+ // Apply Headers polyfill
6
+ if (typeof globalThis.Headers === 'undefined') {
7
+ globalThis.Headers = Headers;
8
+ }
9
+
10
+ // eslint-disable-next-line @typescript-eslint/no-require-imports,import/no-unassigned-import
11
+ require('web-streams-polyfill/polyfill');
12
+ // Attach the polyfill as a Global function
13
+ if (!('structuredClone' in globalThis)) {
14
+ // eslint-disable-next-line @typescript-eslint/no-require-imports,import/no-unassigned-import
15
+ const structuredClone = require('@ungap/structured-clone');
16
+ globalThis.structuredClone = structuredClone.default;
17
+ }
18
+ }
package/src/mcp.ts ADDED
@@ -0,0 +1,65 @@
1
+ import type { ToolSet } from 'ai';
2
+ import type { experimental_MCPClient as MCPClient } from '@ai-sdk/mcp';
3
+ import * as workflow from '@temporalio/workflow';
4
+ import type { ActivityOptions } from '@temporalio/workflow';
5
+ import type { ListToolResult } from './activities';
6
+
7
+ export type McpClientFactory = (args: unknown) => Promise<MCPClient>;
8
+ export type McpClientFactories = { [serviceName: string]: McpClientFactory };
9
+
10
+ /**
11
+ * Options for the Temporal MCP Client
12
+ *
13
+ * @experimental The AI SDK plugin is an experimental feature; APIs may change without notice.
14
+ */
15
+ export interface TemporalMCPClientOptions {
16
+ readonly name: string;
17
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
18
+ readonly clientArgs?: any;
19
+ readonly activityOptions?: ActivityOptions;
20
+ }
21
+
22
+ /**
23
+ * A Temporal MCP Client which uses activities to execute list tools and call tools.
24
+ * This should match by name an MCPClientFactory registered with the AI SDK plugin to function.
25
+ *
26
+ * This is intentionally similar to the AI SDK's ``MCPClient``, but is lacking functions not used by the framework.
27
+ * It doesn't close either since the underlying clients are created in activities.
28
+ *
29
+ * @experimental The AI SDK plugin is an experimental feature; APIs may change without notice.
30
+ */
31
+ export class TemporalMCPClient {
32
+ constructor(readonly options: TemporalMCPClientOptions) {}
33
+
34
+ async tools(): Promise<ToolSet> {
35
+ workflow.log.info(`Options: ${this.options.activityOptions}`);
36
+ const activities = workflow.proxyActivities({ startToCloseTimeout: '10 minutes', ...this.options.activityOptions });
37
+
38
+ const listActivity = activities[this.options.name + '-listTools'];
39
+ const tools: Record<string, ListToolResult> = await listActivity!({ clientArgs: this.options.clientArgs });
40
+ return Object.fromEntries(
41
+ Object.entries(tools).map(([toolName, toolResult]) => [
42
+ toolName,
43
+ {
44
+ execute: async (args: any, options) => {
45
+ const activities = workflow.proxyActivities({
46
+ summary: toolName,
47
+ startToCloseTimeout: '10 minutes',
48
+ ...this.options,
49
+ });
50
+ 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,
59
+ },
60
+ type: 'dynamic',
61
+ },
62
+ ])
63
+ );
64
+ }
65
+ }
package/src/plugin.ts ADDED
@@ -0,0 +1,34 @@
1
+ import type { ProviderV2 } from '@ai-sdk/provider';
2
+ import { SimplePlugin } from '@temporalio/plugin';
3
+ import { createActivities } from './activities';
4
+ import type { McpClientFactories } from './mcp';
5
+
6
+ /**
7
+ * Options for the AI SDK plugin
8
+ *
9
+ * @experimental The AI SDK plugin is an experimental feature; APIs may change without notice.
10
+ */
11
+ export interface AiSdkPluginOptions {
12
+ modelProvider: ProviderV2;
13
+
14
+ /**
15
+ * This object contains a mapping of server names to functions which create MCP clients.
16
+ * Any TemporalMCPClient used in a workflow should have its associated servername listed in this object.
17
+ */
18
+ mcpClientFactories?: McpClientFactories;
19
+ }
20
+
21
+ /**
22
+ * A Temporal plugin that integrates AI SDK providers for use in workflows.
23
+ * This plugin creates activities that allow workflows to invoke AI models.
24
+ *
25
+ * @experimental The AI SDK plugin is an experimental feature; APIs may change without notice.
26
+ */
27
+ export class AiSdkPlugin extends SimplePlugin {
28
+ constructor(options: AiSdkPluginOptions) {
29
+ super({
30
+ name: 'AiSDKPlugin',
31
+ activities: createActivities(options.modelProvider, options.mcpClientFactories),
32
+ });
33
+ }
34
+ }
@@ -0,0 +1,79 @@
1
+ import type {
2
+ EmbeddingModelV2,
3
+ ImageModelV2,
4
+ LanguageModelV2,
5
+ LanguageModelV2CallOptions,
6
+ ProviderV2,
7
+ SharedV2Headers,
8
+ } from '@ai-sdk/provider';
9
+ import * as workflow from '@temporalio/workflow';
10
+ import { ActivityOptions } from '@temporalio/workflow';
11
+ import { ApplicationFailure } from '@temporalio/common';
12
+ import { InvokeModelResult } from './activities';
13
+
14
+ /**
15
+ * A language model implementation that delegates AI model calls to Temporal activities.
16
+ * This allows workflows to invoke AI models through the Temporal execution model.
17
+ *
18
+ * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
19
+ */
20
+ export class TemporalLanguageModel implements LanguageModelV2 {
21
+ readonly specificationVersion = 'v2';
22
+ readonly provider = 'temporal';
23
+ readonly supportedUrls = {};
24
+
25
+ constructor(
26
+ readonly modelId: string,
27
+ readonly options?: ActivityOptions
28
+ ) {}
29
+
30
+ async doGenerate(options: LanguageModelV2CallOptions): Promise<InvokeModelResult> {
31
+ const activities = workflow.proxyActivities({ startToCloseTimeout: '10 minutes', ...this.options });
32
+ const result = await activities.invokeModel!({ modelId: this.modelId, options });
33
+ if (result === undefined) {
34
+ throw ApplicationFailure.nonRetryable('Received undefined response from model activity.');
35
+ }
36
+ if (result.response !== undefined) {
37
+ result.response.timestamp = new Date(result.response.timestamp);
38
+ }
39
+ return result;
40
+ }
41
+
42
+ doStream(_options: LanguageModelV2CallOptions): PromiseLike<{
43
+ stream: any;
44
+ request?: { body?: unknown };
45
+ response?: { headers?: SharedV2Headers };
46
+ }> {
47
+ throw ApplicationFailure.nonRetryable('Streaming not supported.');
48
+ }
49
+ }
50
+
51
+ /**
52
+ * A Temporal-specific provider implementation that creates AI models which execute
53
+ * through Temporal activities. This provider integrates AI SDK models with Temporal's
54
+ * execution model to ensure reliable, durable AI model invocations.
55
+ *
56
+ * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
57
+ */
58
+ export class TemporalProvider implements ProviderV2 {
59
+ constructor(readonly options?: ActivityOptions) {}
60
+
61
+ imageModel(_modelId: string): ImageModelV2 {
62
+ throw new Error('Not implemented');
63
+ }
64
+
65
+ languageModel(modelId: string): LanguageModelV2 {
66
+ return new TemporalLanguageModel(modelId, this.options);
67
+ }
68
+
69
+ textEmbeddingModel(_modelId: string): EmbeddingModelV2<string> {
70
+ throw new Error('Not implemented');
71
+ }
72
+ }
73
+
74
+ /**
75
+ * A singleton instance of TemporalProvider for convenient use in applications.
76
+ *
77
+ * @experimental The AI SDK integration is an experimental feature; APIs may change without notice.
78
+ */
79
+ export const temporalProvider: TemporalProvider = new TemporalProvider();