@temporalio/strands-agents 1.24.0 → 2.0.0-rc.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.
Files changed (52) hide show
  1. package/LICENSE +6 -6
  2. package/README.md +112 -15
  3. package/lib/empty-module.d.ts +1 -1
  4. package/lib/empty-module.js +6 -1
  5. package/lib/empty-module.js.map +1 -1
  6. package/lib/index.d.ts +2 -2
  7. package/lib/index.js +21 -11
  8. package/lib/index.js.map +1 -1
  9. package/lib/load-polyfills.js +15 -0
  10. package/lib/load-polyfills.js.map +1 -1
  11. package/lib/model-activity.d.ts +57 -2
  12. package/lib/model-activity.js +100 -6
  13. package/lib/model-activity.js.map +1 -1
  14. package/lib/plugin.d.ts +33 -12
  15. package/lib/plugin.js +127 -26
  16. package/lib/plugin.js.map +1 -1
  17. package/lib/strands-errors.d.ts +39 -0
  18. package/lib/strands-errors.js +130 -0
  19. package/lib/strands-errors.js.map +1 -0
  20. package/lib/temporal-activity-tool.d.ts +18 -10
  21. package/lib/temporal-activity-tool.js +50 -29
  22. package/lib/temporal-activity-tool.js.map +1 -1
  23. package/lib/temporal-agent.d.ts +38 -4
  24. package/lib/temporal-agent.js +68 -16
  25. package/lib/temporal-agent.js.map +1 -1
  26. package/lib/temporal-mcp-client.d.ts +113 -17
  27. package/lib/temporal-mcp-client.js +376 -102
  28. package/lib/temporal-mcp-client.js.map +1 -1
  29. package/lib/temporal-mcp-tool.d.ts +3 -1
  30. package/lib/temporal-mcp-tool.js +26 -16
  31. package/lib/temporal-mcp-tool.js.map +1 -1
  32. package/lib/temporal-model.d.ts +32 -0
  33. package/lib/temporal-model.js +108 -24
  34. package/lib/temporal-model.js.map +1 -1
  35. package/lib/workflow.js +17 -7
  36. package/lib/workflow.js.map +1 -1
  37. package/package.json +46 -22
  38. package/src/empty-module.ts +5 -0
  39. package/src/index.ts +3 -1
  40. package/src/load-polyfills.ts +20 -1
  41. package/src/model-activity.ts +153 -8
  42. package/src/plugin.ts +159 -31
  43. package/src/strands-errors.ts +147 -0
  44. package/src/temporal-activity-tool.ts +43 -32
  45. package/src/temporal-agent.ts +77 -19
  46. package/src/temporal-mcp-client.ts +407 -91
  47. package/src/temporal-mcp-tool.ts +9 -9
  48. package/src/temporal-model.ts +111 -18
  49. package/lib/failure-converter.d.ts +0 -14
  50. package/lib/failure-converter.js +0 -61
  51. package/lib/failure-converter.js.map +0 -1
  52. package/src/failure-converter.ts +0 -77
@@ -18,7 +18,9 @@ export declare class TemporalMCPTool extends Tool {
18
18
  readonly description: string;
19
19
  readonly toolSpec: ToolSpec;
20
20
  readonly server: string;
21
+ /** The tool's name on the MCP server, which a `prefix` does not change. */
22
+ readonly serverToolName: string;
21
23
  private readonly activityOptions;
22
- constructor(server: string, info: McpToolInfo, activityOptions: ActivityOptions);
24
+ constructor(server: string, info: McpToolInfo, activityOptions: ActivityOptions, prefix?: string);
23
25
  stream(toolContext: ToolContext): ToolStreamGenerator;
24
26
  }
@@ -15,18 +15,29 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.TemporalMCPTool = void 0;
27
37
  const sdk_1 = require("@strands-agents/sdk");
28
38
  const workflow = __importStar(require("@temporalio/workflow"));
29
39
  const temporal_mcp_client_1 = require("./temporal-mcp-client");
40
+ const temporal_activity_tool_1 = require("./temporal-activity-tool");
30
41
  const json_schema_1 = require("./json-schema");
31
42
  /**
32
43
  * Workflow-side stub for a single MCP tool. Each invocation dispatches the
@@ -44,14 +55,17 @@ class TemporalMCPTool extends sdk_1.Tool {
44
55
  description;
45
56
  toolSpec;
46
57
  server;
58
+ /** The tool's name on the MCP server, which a `prefix` does not change. */
59
+ serverToolName;
47
60
  activityOptions;
48
- constructor(server, info, activityOptions) {
61
+ constructor(server, info, activityOptions, prefix) {
49
62
  super();
50
63
  this.server = server;
51
- this.name = info.name;
64
+ this.serverToolName = info.name;
65
+ this.name = prefix ? `${prefix}_${info.name}` : info.name;
52
66
  this.description = info.description || `Tool which performs ${info.name}`;
53
67
  this.toolSpec = {
54
- name: info.name,
68
+ name: this.name,
55
69
  description: this.description,
56
70
  inputSchema: (0, json_schema_1.toJsonSchema)(info.inputSchema),
57
71
  };
@@ -67,7 +81,7 @@ class TemporalMCPTool extends sdk_1.Tool {
67
81
  });
68
82
  try {
69
83
  const raw = await activities[(0, temporal_mcp_client_1.callToolActivityName)(this.server)]({
70
- toolName: this.name,
84
+ toolName: this.serverToolName,
71
85
  args: input,
72
86
  });
73
87
  const result = raw;
@@ -88,11 +102,7 @@ class TemporalMCPTool extends sdk_1.Tool {
88
102
  });
89
103
  }
90
104
  catch (err) {
91
- return new sdk_1.ToolResultBlock({
92
- toolUseId,
93
- status: 'error',
94
- content: [new sdk_1.TextBlock(String(err instanceof Error ? err.message : err))],
95
- });
105
+ return (0, temporal_activity_tool_1.activityErrorResult)(toolUseId, err);
96
106
  }
97
107
  }
98
108
  }
@@ -1 +1 @@
1
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CAAC;YACb,OAAO,IAAA,4CAAmB,EAAC,SAAS,EAAE,GAAG,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;CACF;AA1DD,0CA0DC;AAED,SAAS,aAAa,CAAC,IAAa;IAClC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAC9C,MAAM,GAAG,GAAG,IAA0C,CAAC;QACvD,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACxD,OAAO,IAAI,eAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IACD,OAAO,IAAI,eAAS,CAAC,EAAE,IAAI,EAAE,IAAiB,EAAE,CAAC,CAAC;AACpD,CAAC"}
@@ -2,6 +2,11 @@ import { Model } from '@strands-agents/sdk';
2
2
  import type { BaseModelConfig, Message, ModelStreamEvent, StreamOptions } from '@strands-agents/sdk';
3
3
  import type { ActivityOptions } from '@temporalio/workflow';
4
4
  import type { Duration } from '@temporalio/common/lib/time';
5
+ /** Name of the activity that returns the worker model's {@link ModelConfigInfo}. */
6
+ export declare const GET_MODEL_CONFIG_ACTIVITY = "strandsGetModelConfig";
7
+ /** Names of the activities that run a stateful model with the agent's model state. */
8
+ export declare const INVOKE_STATEFUL_MODEL_ACTIVITY = "strandsInvokeStatefulModel";
9
+ export declare const INVOKE_STATEFUL_MODEL_STREAMING_ACTIVITY = "strandsInvokeStatefulModelStreaming";
5
10
  /**
6
11
  * Options for {@link TemporalModel}.
7
12
  *
@@ -24,14 +29,41 @@ export interface TemporalModelOptions {
24
29
  * The `modelName` selects which factory the plugin will invoke worker-side;
25
30
  * it must match a key in {@link StrandsPlugin}'s `models` map. A name not
26
31
  * present in `models` raises an error inside the model activity at first call.
32
+ *
33
+ * `activityOptions.heartbeatTimeout` defaults to 10 seconds. The model activities heartbeat on a
34
+ * timer at half of it, so a cancel reaches a running model call and a lost worker is noticed. Pass
35
+ * `heartbeatTimeout: 0` to turn heartbeats off. The config read runs synchronously and can't
36
+ * heartbeat, so it's scheduled without a heartbeat timeout.
37
+ *
38
+ * `TemporalAgent` reads the worker model's config before its first call. With a plain Strands
39
+ * `Agent`, call `await model.loadConfig()` before building the agent: without it, the model reports
40
+ * itself as stateless, and a stateful worker model fails every call.
27
41
  */
28
42
  export declare class TemporalModel extends Model<BaseModelConfig> {
29
43
  private readonly modelName?;
30
44
  private readonly activityOptions;
31
45
  private readonly streamingTopic?;
32
46
  private readonly streamingBatchInterval;
47
+ private config;
48
+ private isStateful;
49
+ private configLoaded;
33
50
  constructor(options?: TemporalModelOptions);
34
51
  updateConfig(_config: BaseModelConfig): void;
52
+ /**
53
+ * The worker model's id and context window, once {@link loadConfig} has read them; otherwise
54
+ * empty.
55
+ */
35
56
  getConfig(): BaseModelConfig;
57
+ /** Whether the worker model keeps the conversation server-side, once {@link loadConfig} has read it. */
58
+ get stateful(): boolean;
59
+ /**
60
+ * Read the worker model's id, context window and stateful flag through an activity, once per
61
+ * instance, so that Strands' traces, proactive compression and stateful handling use the real
62
+ * model's values. {@link TemporalAgent} calls this before Strands initializes the agent.
63
+ *
64
+ * Returns `undefined`, without awaiting anything, when the config was already read, so callers
65
+ * can go on synchronously.
66
+ */
67
+ loadConfig(): Promise<void> | undefined;
36
68
  stream(messages: Message[], options?: StreamOptions): AsyncIterable<ModelStreamEvent>;
37
69
  }
@@ -15,17 +15,33 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.TemporalModel = void 0;
36
+ exports.TemporalModel = exports.INVOKE_STATEFUL_MODEL_STREAMING_ACTIVITY = exports.INVOKE_STATEFUL_MODEL_ACTIVITY = exports.GET_MODEL_CONFIG_ACTIVITY = void 0;
27
37
  const sdk_1 = require("@strands-agents/sdk");
28
38
  const workflow = __importStar(require("@temporalio/workflow"));
39
+ const strands_errors_1 = require("./strands-errors");
40
+ /** Name of the activity that returns the worker model's {@link ModelConfigInfo}. */
41
+ exports.GET_MODEL_CONFIG_ACTIVITY = 'strandsGetModelConfig';
42
+ /** Names of the activities that run a stateful model with the agent's model state. */
43
+ exports.INVOKE_STATEFUL_MODEL_ACTIVITY = 'strandsInvokeStatefulModel';
44
+ exports.INVOKE_STATEFUL_MODEL_STREAMING_ACTIVITY = 'strandsInvokeStatefulModelStreaming';
29
45
  /**
30
46
  * A Strands {@link Model} whose {@link Model.stream} runs as a Temporal
31
47
  * activity. Constructing a `TemporalModel` does no I/O, so instances are
@@ -34,12 +50,24 @@ const workflow = __importStar(require("@temporalio/workflow"));
34
50
  * The `modelName` selects which factory the plugin will invoke worker-side;
35
51
  * it must match a key in {@link StrandsPlugin}'s `models` map. A name not
36
52
  * present in `models` raises an error inside the model activity at first call.
53
+ *
54
+ * `activityOptions.heartbeatTimeout` defaults to 10 seconds. The model activities heartbeat on a
55
+ * timer at half of it, so a cancel reaches a running model call and a lost worker is noticed. Pass
56
+ * `heartbeatTimeout: 0` to turn heartbeats off. The config read runs synchronously and can't
57
+ * heartbeat, so it's scheduled without a heartbeat timeout.
58
+ *
59
+ * `TemporalAgent` reads the worker model's config before its first call. With a plain Strands
60
+ * `Agent`, call `await model.loadConfig()` before building the agent: without it, the model reports
61
+ * itself as stateless, and a stateful worker model fails every call.
37
62
  */
38
63
  class TemporalModel extends sdk_1.Model {
39
64
  modelName;
40
65
  activityOptions;
41
66
  streamingTopic;
42
67
  streamingBatchInterval;
68
+ config = {};
69
+ isStateful = false;
70
+ configLoaded = false;
43
71
  constructor(options = {}) {
44
72
  super();
45
73
  this.modelName = options.modelName;
@@ -50,30 +78,86 @@ class TemporalModel extends sdk_1.Model {
50
78
  updateConfig(_config) {
51
79
  // No-op; the real model is configured worker-side via the plugin's factories.
52
80
  }
81
+ /**
82
+ * The worker model's id and context window, once {@link loadConfig} has read them; otherwise
83
+ * empty.
84
+ */
53
85
  getConfig() {
54
- return {};
86
+ return { ...this.config };
87
+ }
88
+ /** Whether the worker model keeps the conversation server-side, once {@link loadConfig} has read it. */
89
+ get stateful() {
90
+ return this.isStateful;
91
+ }
92
+ /**
93
+ * Read the worker model's id, context window and stateful flag through an activity, once per
94
+ * instance, so that Strands' traces, proactive compression and stateful handling use the real
95
+ * model's values. {@link TemporalAgent} calls this before Strands initializes the agent.
96
+ *
97
+ * Returns `undefined`, without awaiting anything, when the config was already read, so callers
98
+ * can go on synchronously.
99
+ */
100
+ loadConfig() {
101
+ if (this.configLoaded)
102
+ return undefined;
103
+ // The config read runs synchronously, so it can't heartbeat.
104
+ const activities = workflow.proxyActivities({
105
+ startToCloseTimeout: '10 minutes',
106
+ ...this.activityOptions,
107
+ heartbeatTimeout: undefined,
108
+ });
109
+ return activities[exports.GET_MODEL_CONFIG_ACTIVITY]({ modelName: this.modelName }).then(({ stateful, ...config }) => {
110
+ this.config = config;
111
+ // A result recorded before the flag existed has none: the model ran as stateless then.
112
+ this.isStateful = stateful === true;
113
+ this.configLoaded = true;
114
+ });
55
115
  }
56
116
  async *stream(messages, options) {
57
117
  const proxiedActivities = workflow.proxyActivities({
58
118
  startToCloseTimeout: '10 minutes',
59
119
  ...this.activityOptions,
120
+ heartbeatTimeout: this.activityOptions.heartbeatTimeout ?? '10 seconds',
60
121
  });
61
- const events = this.streamingTopic
62
- ? await proxiedActivities.invokeModelStreaming({
63
- modelName: this.modelName,
64
- messages,
65
- options,
66
- streamingTopic: this.streamingTopic,
67
- streamingBatchInterval: this.streamingBatchInterval,
68
- })
69
- : await proxiedActivities.invokeModel({
70
- modelName: this.modelName,
71
- messages,
72
- options,
73
- });
74
- for (const event of events) {
75
- yield event;
122
+ const { modelState, ...rest } = options ?? {};
123
+ const input = { modelName: this.modelName, messages, options: this.isStateful ? rest : options };
124
+ const streaming = this.streamingTopic
125
+ ? { streamingTopic: this.streamingTopic, streamingBatchInterval: this.streamingBatchInterval }
126
+ : undefined;
127
+ if (!this.isStateful) {
128
+ let events;
129
+ try {
130
+ events = streaming
131
+ ? await proxiedActivities.invokeModelStreaming({ ...input, ...streaming })
132
+ : await proxiedActivities.invokeModel(input);
133
+ }
134
+ catch (err) {
135
+ // Give the agent Strands' own error for a context overflow, so its conversation manager can
136
+ // trim the conversation and call the model again. Keep the activity failure as its cause.
137
+ if (err instanceof workflow.ActivityFailure &&
138
+ (0, strands_errors_1.applicationFailureType)(err.cause) === strands_errors_1.CONTEXT_WINDOW_OVERFLOW_TYPE) {
139
+ throw Object.assign(new sdk_1.ContextWindowOverflowError(err.cause?.message ?? ''), { cause: err });
140
+ }
141
+ throw err;
142
+ }
143
+ yield* events;
144
+ return;
145
+ }
146
+ // A stateful model's overflow is not rethrown as Strands' error: its conversation is on the
147
+ // server, and the default manager the agent keeps would trim and retry where Strands, which
148
+ // gives a stateful agent no manager, fails the turn.
149
+ // The agent's model state is a live store; send a copy of its values, and copy the updated
150
+ // values back, as the model would have written them natively.
151
+ const statefulInput = { ...input, modelState: modelState?.getAll() ?? {} };
152
+ const result = streaming
153
+ ? await proxiedActivities[exports.INVOKE_STATEFUL_MODEL_STREAMING_ACTIVITY]({ ...statefulInput, ...streaming })
154
+ : await proxiedActivities[exports.INVOKE_STATEFUL_MODEL_ACTIVITY](statefulInput);
155
+ if (modelState) {
156
+ modelState.clear();
157
+ for (const [key, value] of Object.entries(result.modelState))
158
+ modelState.set(key, value);
76
159
  }
160
+ yield* result.events;
77
161
  }
78
162
  }
79
163
  exports.TemporalModel = TemporalModel;
@@ -1 +1 @@
1
- {"version":3,"file":"temporal-model.js","sourceRoot":"","sources":["../src/temporal-model.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA4C;AAE5C,+DAAiD;AAoBjD;;;;;;;;GAQG;AACH,MAAa,aAAc,SAAQ,WAAsB;IACtC,SAAS,CAAU;IACnB,eAAe,CAAkB;IACjC,cAAc,CAAU;IACxB,sBAAsB,CAAW;IAElD,YAAY,UAAgC,EAAE;QAC5C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC;QACrD,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;QAC7C,IAAI,CAAC,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,IAAI,kBAAkB,CAAC;IACrF,CAAC;IAEQ,YAAY,CAAC,OAAwB;QAC5C,8EAA8E;IAChF,CAAC;IAEQ,SAAS;QAChB,OAAO,EAAE,CAAC;IACZ,CAAC;IAEQ,KAAK,CAAC,CAAC,MAAM,CAAC,QAAmB,EAAE,OAAuB;QACjE,MAAM,iBAAiB,GAAG,QAAQ,CAAC,eAAe,CAG/C;YACD,mBAAmB,EAAE,YAAY;YACjC,GAAG,IAAI,CAAC,eAAe;SACxB,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc;YAChC,CAAC,C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AE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC;QAC3E,MAAM,MAAM,GAAG,SAAS;YACtB,CAAC,CAAC,MAAM,iBAAiB,CAAC,gDAAwC,CAAC,CAAC,EAAE,GAAG,aAAa,EAAE,GAAG,SAAS,EAAE,CAAC;YACvG,CAAC,CAAC,MAAM,iBAAiB,CAAC,sCAA8B,CAAC,CAAC,aAAa,CAAC,CAAC;QAC3E,IAAI,UAAU,EAAE,CAAC;YACf,UAAU,CAAC,KAAK,EAAE,CAAC;YACnB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;gBAAE,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC3F,CAAC;QACD,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;IACvB,CAAC;CACF;AArHD,sCAqHC"}
package/lib/workflow.js CHANGED
@@ -24,13 +24,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
24
24
  }) : function(o, v) {
25
25
  o["default"] = v;
26
26
  });
27
- var __importStar = (this && this.__importStar) || function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
27
+ var __importStar = (this && this.__importStar) || (function () {
28
+ var ownKeys = function(o) {
29
+ ownKeys = Object.getOwnPropertyNames || function (o) {
30
+ var ar = [];
31
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
32
+ return ar;
33
+ };
34
+ return ownKeys(o);
35
+ };
36
+ return function (mod) {
37
+ if (mod && mod.__esModule) return mod;
38
+ var result = {};
39
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
40
+ __setModuleDefault(result, mod);
41
+ return result;
42
+ };
43
+ })();
34
44
  Object.defineProperty(exports, "__esModule", { value: true });
35
45
  exports.activityAsTool = activityAsTool;
36
46
  exports.activityAsHook = activityAsHook;
@@ -1 +1 @@
1
- {"version":3,"file":"workflow.js","sourceRoot":"","sources":["../src/workflow.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;;;;;;;;;AAcH,wCAEC;AAqBD,wCAcC;AAhDD,+DAAiD;AAEjD,qEAA4F;AAE5F;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,YAAoB,EAAE,UAAiC,EAAE;IACtF,OAAO,IAAI,6CAAoB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC;AAcD;;;;;;GAMG;AACH,SAAgB,cAAc,CAC5B,YAAoB,EACpB,OAAoC;IAEpC,MAAM,eAAe,GAAoB;QACvC,mBAAmB,EAAE,YAAY;QACjC,GAAG,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC;KACnC,CAAC;IACF,OAAO,KAAK,UAAU,oBAAoB,CAAC,KAAQ;QACjD,MAAM,UAAU,GAAG,QAAQ,CAAC,eAAe,CAExC,eAAe,CAAC,CAAC;QACpB,MAAM,UAAU,CAAC,YAAY,CAAE,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IAChE,CAAC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"workflow.js","sourceRoot":"","sources":["../src/workflow.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcH,wCAEC;AAqBD,wCAcC;AAhDD,+DAAiD;AAEjD,qEAA4F;AAE5F;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,YAAoB,EAAE,UAAiC,EAAE;IACtF,OAAO,IAAI,6CAAoB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC;AAcD;;;;;;GAMG;AACH,SAAgB,cAAc,CAC5B,YAAoB,EACpB,OAAoC;IAEpC,MAAM,eAAe,GAAoB;QACvC,mBAAmB,EAAE,YAAY;QACjC,GAAG,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC;KACnC,CAAC;IACF,OAAO,KAAK,UAAU,oBAAoB,CAAC,KAAQ;QACjD,MAAM,UAAU,GAAG,QAAQ,CAAC,eAAe,CAExC,eAAe,CAAC,CAAC;QACpB,MAAM,UAAU,CAAC,YAAY,CAAE,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IAChE,CAAC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temporalio/strands-agents",
3
- "version": "1.24.0",
3
+ "version": "2.0.0-rc.1",
4
4
  "description": "Temporal Strands Agents integration package",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -18,45 +18,66 @@
18
18
  "ava": {
19
19
  "timeout": "120s",
20
20
  "concurrency": 1,
21
- "workerThreads": false
21
+ "workerThreads": false,
22
+ "files": [
23
+ "./lib/__tests__/**/*.test.js",
24
+ "./lib/__tests__/test-*.js"
25
+ ]
22
26
  },
23
27
  "dependencies": {
24
- "@temporalio/activity": "1.24.0",
25
- "@temporalio/common": "1.24.0",
26
- "@temporalio/plugin": "1.24.0",
27
- "@temporalio/workflow": "1.24.0",
28
- "@temporalio/workflow-streams": "1.24.0",
28
+ "@temporalio/activity": "^1.24.0",
29
+ "@temporalio/common": "^1.24.0",
30
+ "@temporalio/plugin": "^1.24.0",
31
+ "@temporalio/workflow": "^1.24.0",
32
+ "@temporalio/workflow-streams": "^1.24.0",
29
33
  "@ungap/structured-clone": "^1.3.1",
30
34
  "headers-polyfill": "^4.0.3",
31
35
  "web-streams-polyfill": "^4.2.0"
32
36
  },
33
37
  "peerDependencies": {
34
38
  "@strands-agents/sdk": "^1.3.0",
39
+ "long": "^5.3.2",
40
+ "protobufjs": "^8.7.1",
35
41
  "zod": "^4.0.0"
36
42
  },
37
43
  "devDependencies": {
38
- "@modelcontextprotocol/sdk": "^1.25.2",
44
+ "@modelcontextprotocol/sdk": "^1.32.0",
39
45
  "@strands-agents/sdk": "^1.3.0",
40
- "@temporalio/client": "1.24.0",
41
- "@temporalio/proto": "1.24.0",
42
- "@temporalio/test-helpers": "1.24.0",
43
- "@temporalio/testing": "1.24.0",
44
- "@temporalio/worker": "1.24.0",
46
+ "@temporalio/client": "^1.24.0",
47
+ "@temporalio/proto": "^1.24.0",
48
+ "@temporalio/test-helpers": "link:tests/helpers",
49
+ "@temporalio/testing": "^1.24.0",
50
+ "@temporalio/worker": "^1.24.0",
45
51
  "ava": "^5.3.1",
46
- "zod": "^4.1.12"
52
+ "long": "^5.3.2",
53
+ "protobufjs": "^8.7.1",
54
+ "zod": "^4.1.12",
55
+ "@tsconfig/node20": "^20.1.4",
56
+ "@types/node": "^20.19.39",
57
+ "typescript": "^5.9.3",
58
+ "tsx": "^4.20.6",
59
+ "eslint": "^9.26.0",
60
+ "@eslint/js": "^9.26.0",
61
+ "typescript-eslint": "^8.10.0",
62
+ "eslint-plugin-import": "^2.31.0",
63
+ "eslint-import-resolver-typescript": "^3.6.1",
64
+ "eslint-config-prettier": "^9.1.0",
65
+ "@temporalio/envconfig": "^1.24.0",
66
+ "@types/stack-utils": "^2.0.3",
67
+ "stack-utils": "^2.0.6"
47
68
  },
48
69
  "engines": {
49
- "node": ">= 20.3.0"
70
+ "node": ">=22.12.0"
50
71
  },
51
72
  "bugs": {
52
- "url": "https://github.com/temporalio/sdk-typescript/issues"
73
+ "url": "https://github.com/temporalio/ai-integrations/issues"
53
74
  },
54
75
  "repository": {
55
76
  "type": "git",
56
- "url": "git+https://github.com/temporalio/sdk-typescript.git",
57
- "directory": "contrib/strands"
77
+ "url": "git+https://github.com/temporalio/ai-integrations.git",
78
+ "directory": "typescript/strands-agents"
58
79
  },
59
- "homepage": "https://github.com/temporalio/sdk-typescript/tree/main/contrib/strands",
80
+ "homepage": "https://github.com/temporalio/ai-integrations/tree/main/typescript/strands-agents",
60
81
  "publishConfig": {
61
82
  "access": "public"
62
83
  },
@@ -64,10 +85,13 @@
64
85
  "src",
65
86
  "lib",
66
87
  "!src/__tests__",
67
- "!lib/__tests__"
88
+ "!lib/__tests__",
89
+ "LICENSE"
68
90
  ],
69
91
  "scripts": {
70
- "build": "tsc --build",
71
- "test": "tsx ../../scripts/ava-ci.ts ./lib/__tests__/test-*.js"
92
+ "build": "tsc --build tests/helpers tsconfig.json",
93
+ "lint": "pnpm run build && eslint --config ../_shared/eslint.config.mjs src",
94
+ "test": "ava",
95
+ "pack": "pnpm pack --pack-destination dist"
72
96
  }
73
97
  }
@@ -9,6 +9,9 @@
9
9
  // at build time. Export every name MCP/Strands' static imports reach as a
10
10
  // no-op class. Workflow code never instantiates these — the real transports
11
11
  // run worker-side from the user's `mcpClients` factories.
12
+ // MCP v2 bundles its HTTP transport into the client entrypoint and statically
13
+ // imports EventSourceParserStream from the rewritten eventsource-parser/stream
14
+ // module, so that name must also remain available to the bundler.
12
15
 
13
16
  class WorkflowSandboxStub {}
14
17
 
@@ -16,5 +19,7 @@ export {
16
19
  WorkflowSandboxStub as StreamableHTTPClientTransport,
17
20
  WorkflowSandboxStub as StdioClientTransport,
18
21
  WorkflowSandboxStub as SSEClientTransport,
22
+ WorkflowSandboxStub as EventSource,
23
+ WorkflowSandboxStub as EventSourceParserStream,
19
24
  };
20
25
  export default WorkflowSandboxStub;
package/src/index.ts CHANGED
@@ -7,10 +7,12 @@ export { TemporalModel, type TemporalModelOptions } from './temporal-model';
7
7
  export {
8
8
  TemporalMCPClient,
9
9
  type TemporalMCPClientOptions,
10
+ type McpToolFilters,
11
+ type McpToolMatcher,
10
12
  type McpToolInfo,
11
13
  type CallToolInput,
12
14
  } from './temporal-mcp-client';
13
15
  export { TemporalMCPTool } from './temporal-mcp-tool';
14
16
  export { TemporalActivityTool, type ActivityAsToolOptions } from './temporal-activity-tool';
15
- export { STRANDS_INTERRUPT_TYPE, StrandsFailureConverter } from './failure-converter';
17
+ export { STRANDS_INTERRUPT_TYPE, STRANDS_MALFORMED_INTERRUPT_TYPE } from './strands-errors';
16
18
  export * as workflow from './workflow';
@@ -1,7 +1,26 @@
1
1
  import { Headers } from 'headers-polyfill';
2
- import { inWorkflowContext, uuid4 } from '@temporalio/workflow';
2
+ import { DeterminismViolationError, inWorkflowContext, uuid4 } from '@temporalio/workflow';
3
3
 
4
4
  if (inWorkflowContext()) {
5
+ // Strands composes the parent's cancellation signal with the subagent's via AbortSignal.any().
6
+ // Keep native signal composition, but refuse timeout's timer outside Temporal history.
7
+ // Subclass instead of changing the constructor shared with the worker and other workflows.
8
+ if (typeof globalThis.AbortSignal === 'undefined') {
9
+ const NativeAbortSignal = new AbortController().signal.constructor as typeof AbortSignal;
10
+ globalThis.AbortSignal = class extends NativeAbortSignal {
11
+ static override timeout(_milliseconds: number): never {
12
+ throw new DeterminismViolationError(
13
+ 'AbortSignal.timeout() is not supported in workflows. Use Temporal sleep() and AbortController instead.'
14
+ );
15
+ }
16
+
17
+ // AbortController and the inherited helpers still return native signals.
18
+ static override [Symbol.hasInstance](value: unknown): boolean {
19
+ return value instanceof NativeAbortSignal;
20
+ }
21
+ };
22
+ }
23
+
5
24
  if (typeof globalThis.Headers === 'undefined') {
6
25
  globalThis.Headers = Headers;
7
26
  }