@temporalio/strands-agents 1.21.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 +21 -0
- package/README.md +351 -0
- package/lib/empty-module.d.ts +4 -0
- package/lib/empty-module.js +21 -0
- package/lib/empty-module.js.map +1 -0
- package/lib/failure-converter.d.ts +14 -0
- package/lib/failure-converter.js +60 -0
- package/lib/failure-converter.js.map +1 -0
- package/lib/heartbeat.d.ts +6 -0
- package/lib/heartbeat.js +27 -0
- package/lib/heartbeat.js.map +1 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +45 -0
- package/lib/index.js.map +1 -0
- package/lib/json-schema.d.ts +10 -0
- package/lib/json-schema.js +17 -0
- package/lib/json-schema.js.map +1 -0
- package/lib/load-polyfills.d.ts +1 -0
- package/lib/load-polyfills.js +23 -0
- package/lib/load-polyfills.js.map +1 -0
- package/lib/model-activity.d.ts +41 -0
- package/lib/model-activity.js +100 -0
- package/lib/model-activity.js.map +1 -0
- package/lib/plugin.d.ts +79 -0
- package/lib/plugin.js +152 -0
- package/lib/plugin.js.map +1 -0
- package/lib/temporal-activity-tool.d.ts +42 -0
- package/lib/temporal-activity-tool.js +109 -0
- package/lib/temporal-activity-tool.js.map +1 -0
- package/lib/temporal-agent.d.ts +41 -0
- package/lib/temporal-agent.js +80 -0
- package/lib/temporal-agent.js.map +1 -0
- package/lib/temporal-mcp-client.d.ts +107 -0
- package/lib/temporal-mcp-client.js +237 -0
- package/lib/temporal-mcp-client.js.map +1 -0
- package/lib/temporal-mcp-tool.d.ts +24 -0
- package/lib/temporal-mcp-tool.js +109 -0
- package/lib/temporal-mcp-tool.js.map +1 -0
- package/lib/temporal-model.d.ts +41 -0
- package/lib/temporal-model.js +88 -0
- package/lib/temporal-model.js.map +1 -0
- package/lib/workflow.d.ts +39 -0
- package/lib/workflow.js +66 -0
- package/lib/workflow.js.map +1 -0
- package/package.json +72 -0
- package/src/empty-module.ts +20 -0
- package/src/failure-converter.ts +76 -0
- package/src/heartbeat.ts +24 -0
- package/src/index.ts +16 -0
- package/src/json-schema.ts +14 -0
- package/src/load-polyfills.ts +24 -0
- package/src/model-activity.ts +124 -0
- package/src/plugin.ts +215 -0
- package/src/temporal-activity-tool.ts +127 -0
- package/src/temporal-agent.ts +103 -0
- package/src/temporal-mcp-client.ts +274 -0
- package/src/temporal-mcp-tool.ts +89 -0
- package/src/temporal-model.ts +94 -0
- package/src/workflow.ts +60 -0
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
# Strands Agents
|
|
2
|
+
|
|
3
|
+
⚠️ **This package is currently at an experimental release stage.** ⚠️
|
|
4
|
+
|
|
5
|
+
This Temporal [Plugin](https://docs.temporal.io/develop/plugins-guide) allows you to run [Strands Agents](https://strandsagents.com/) inside Temporal Workflows, routing model invocations, tool calls, and MCP tool calls through Temporal Activities for durable execution, Temporal-managed retries, and timeouts.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @temporalio/strands-agents @strands-agents/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quickstart
|
|
14
|
+
|
|
15
|
+
`workflow.ts` defines the workflow:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { proxyActivities, defineWorkflow } from '@temporalio/workflow';
|
|
19
|
+
import { TemporalAgent } from '@temporalio/strands-agents';
|
|
20
|
+
|
|
21
|
+
export async function myWorkflow(prompt: string): Promise<string> {
|
|
22
|
+
const agent = new TemporalAgent({
|
|
23
|
+
activityOptions: { startToCloseTimeout: '60 seconds' },
|
|
24
|
+
});
|
|
25
|
+
const result = await agent.invoke(prompt);
|
|
26
|
+
return result.lastMessage?.toString() ?? '';
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`worker.ts` runs the worker:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { Worker, NativeConnection } from '@temporalio/worker';
|
|
34
|
+
import { StrandsPlugin } from '@temporalio/strands-agents';
|
|
35
|
+
|
|
36
|
+
const connection = await NativeConnection.connect({ address: 'localhost:7233' });
|
|
37
|
+
const worker = await Worker.create({
|
|
38
|
+
connection,
|
|
39
|
+
taskQueue: 'strands',
|
|
40
|
+
workflowsPath: require.resolve('./workflow'),
|
|
41
|
+
plugins: [new StrandsPlugin()],
|
|
42
|
+
});
|
|
43
|
+
await worker.run();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`client.ts` starts the workflow:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { Client } from '@temporalio/client';
|
|
50
|
+
import { myWorkflow } from './workflow';
|
|
51
|
+
|
|
52
|
+
const client = new Client();
|
|
53
|
+
const result = await client.workflow.execute(myWorkflow, {
|
|
54
|
+
args: ['Hello'],
|
|
55
|
+
taskQueue: 'strands',
|
|
56
|
+
workflowId: 'strands-quickstart',
|
|
57
|
+
});
|
|
58
|
+
console.log(result);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Models
|
|
62
|
+
|
|
63
|
+
`new StrandsPlugin({ models })` takes a mapping of `name → factory`. Each factory is called lazily on first use (on the worker, outside the workflow sandbox) and the constructed model is cached for the worker's lifetime. `new TemporalAgent({ model: 'name', ... })` selects which factory to invoke and carries the activity options for that agent's model calls. If `models` is omitted, the plugin registers a single `BedrockModel` factory under the name `"bedrock"`, matching Strands' own implicit default.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { BedrockModel } from '@strands-agents/sdk/models/bedrock';
|
|
67
|
+
import { AnthropicModel } from '@strands-agents/sdk/models/anthropic';
|
|
68
|
+
import { TemporalAgent, StrandsPlugin } from '@temporalio/strands-agents';
|
|
69
|
+
|
|
70
|
+
// workflow
|
|
71
|
+
export async function multiModelWorkflow(prompt: string): Promise<string> {
|
|
72
|
+
const a = new TemporalAgent({
|
|
73
|
+
model: 'claude',
|
|
74
|
+
activityOptions: { startToCloseTimeout: '60 seconds' },
|
|
75
|
+
});
|
|
76
|
+
const b = new TemporalAgent({
|
|
77
|
+
model: 'bedrock',
|
|
78
|
+
activityOptions: { startToCloseTimeout: '60 seconds' },
|
|
79
|
+
});
|
|
80
|
+
// ...
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// worker
|
|
84
|
+
new StrandsPlugin({
|
|
85
|
+
models: {
|
|
86
|
+
claude: () => new AnthropicModel({ apiKey: '...' }),
|
|
87
|
+
bedrock: () => new BedrockModel({}),
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Each `TemporalAgent` carries its own activity options (timeouts, retry policy, task queue, streaming topic) and dispatches to the shared model activity, which resolves the model name against the registered factories at runtime. A name not present in `models` throws inside the activity.
|
|
93
|
+
|
|
94
|
+
## Retries
|
|
95
|
+
|
|
96
|
+
`TemporalAgent` disables Strands' built-in `ModelRetryStrategy` so retries are handled exclusively by Temporal. Configure retries via `activityOptions.retry` on `TemporalAgent`, and on the activity options accepted by `workflow.activityAsTool`, `workflow.activityAsHook`, and `TemporalMCPClient`:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
new TemporalAgent({
|
|
100
|
+
activityOptions: {
|
|
101
|
+
startToCloseTimeout: '60 seconds',
|
|
102
|
+
retry: { maximumAttempts: 3 },
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Passing `retryStrategy` to `new TemporalAgent(...)` throws; remove the argument and put the retry config on the activity options instead.
|
|
108
|
+
|
|
109
|
+
## Snapshots
|
|
110
|
+
|
|
111
|
+
`TemporalAgent.takeSnapshot()` and `TemporalAgent.loadSnapshot()` throw. Temporal's event history already persists workflow state durably at a finer granularity than Strands snapshots, so calling either inside a workflow is redundant.
|
|
112
|
+
|
|
113
|
+
## Structured Output
|
|
114
|
+
|
|
115
|
+
Like Strands' `Agent`, `TemporalAgent` supports structured output via `structuredOutputSchema`. The values flow through the model activity unchanged; supply any Zod schema:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import { z } from 'zod';
|
|
119
|
+
|
|
120
|
+
const PersonInfo = z.object({ name: z.string(), age: z.number() });
|
|
121
|
+
|
|
122
|
+
export async function myWorkflow(prompt: string) {
|
|
123
|
+
const agent = new TemporalAgent({
|
|
124
|
+
activityOptions: { startToCloseTimeout: '60 seconds' },
|
|
125
|
+
structuredOutputSchema: PersonInfo,
|
|
126
|
+
});
|
|
127
|
+
const result = await agent.invoke(prompt);
|
|
128
|
+
return result.structuredOutput;
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Streaming
|
|
133
|
+
|
|
134
|
+
To forward model chunks to external consumers, pass `streamingTopic: '...'` to `TemporalAgent` and host a workflow stream on the workflow via [`@temporalio/workflow-streams`](../workflow-streams). Each model stream event is published on the named topic from inside the model activity; subscribers read via `WorkflowStreamClient`. Chunks are batched on `streamingBatchInterval` (default `'100 milliseconds'`).
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
import { WorkflowStream } from '@temporalio/workflow-streams/workflow';
|
|
138
|
+
import { WorkflowStreamClient } from '@temporalio/workflow-streams/client';
|
|
139
|
+
|
|
140
|
+
// workflow
|
|
141
|
+
export async function streamingWorkflow(prompt: string) {
|
|
142
|
+
new WorkflowStream();
|
|
143
|
+
const agent = new TemporalAgent({
|
|
144
|
+
activityOptions: { startToCloseTimeout: '60 seconds' },
|
|
145
|
+
streamingTopic: 'events',
|
|
146
|
+
});
|
|
147
|
+
await agent.invoke(prompt);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// client
|
|
151
|
+
const stream = WorkflowStreamClient.create(client, workflowId);
|
|
152
|
+
for await (const item of stream.subscribe(['events'])) {
|
|
153
|
+
console.log(item);
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Tools
|
|
158
|
+
|
|
159
|
+
Wrap an activity registered on the worker with `workflow.activityAsTool(name, options)`:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
// activities/index.ts
|
|
163
|
+
export async function fetchUser(userId: string): Promise<{ name: string }> {
|
|
164
|
+
// ...
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// workflow.ts
|
|
168
|
+
import { workflow as strandsWorkflow, TemporalAgent } from '@temporalio/strands-agents';
|
|
169
|
+
import { z } from 'zod';
|
|
170
|
+
|
|
171
|
+
export async function toolsWorkflow(prompt: string) {
|
|
172
|
+
const agent = new TemporalAgent({
|
|
173
|
+
activityOptions: { startToCloseTimeout: '60 seconds' },
|
|
174
|
+
tools: [
|
|
175
|
+
strandsWorkflow.activityAsTool('fetchUser', {
|
|
176
|
+
description: 'Fetch user by id',
|
|
177
|
+
inputSchema: z.object({ userId: z.string() }),
|
|
178
|
+
activityOptions: { startToCloseTimeout: '30 seconds' },
|
|
179
|
+
}),
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
return await agent.invoke(prompt);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// worker.ts
|
|
186
|
+
new Worker({
|
|
187
|
+
// ...
|
|
188
|
+
activities: { fetchUser },
|
|
189
|
+
plugins: [new StrandsPlugin({ models })],
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Hooks
|
|
194
|
+
|
|
195
|
+
Strands' [hook system](https://strandsagents.com/) lets you subscribe callbacks to events in the agent lifecycle — invocation start/end, model call before/after, tool call before/after, message added. Pass `hooks=[...]` via Strands' standard plugin API to `TemporalAgent`: every hook event fires in workflow context, so deterministic callbacks just work.
|
|
196
|
+
|
|
197
|
+
Callbacks run in workflow context, so they must be deterministic: no `Date.now()`, `randomUUID()`, or I/O — same rules as workflow code. For callbacks that need I/O (audit logging, metrics, alerting), use `workflow.activityAsHook()` to dispatch the work as a Temporal activity:
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
// activities/index.ts
|
|
201
|
+
export async function persistToolCall(toolName: string): Promise<void> {
|
|
202
|
+
// I/O safely in an activity.
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// workflow.ts
|
|
206
|
+
import { workflow as strandsWorkflow } from '@temporalio/strands-agents';
|
|
207
|
+
import { AfterToolCallEvent } from '@strands-agents/sdk';
|
|
208
|
+
|
|
209
|
+
const auditCallback = strandsWorkflow.activityAsHook<AfterToolCallEvent, string>('persistToolCall', {
|
|
210
|
+
activityInput: (event) => event.toolUse.name,
|
|
211
|
+
activityOptions: { startToCloseTimeout: '10 seconds' },
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
agent.addHook(AfterToolCallEvent, auditCallback);
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
`activityInput` extracts serializable values from the event to pass as the activity's input. Events themselves are not serializable because they hold references to the `Agent`, `Tool` instances, etc.
|
|
218
|
+
|
|
219
|
+
## Human-in-the-loop interrupts
|
|
220
|
+
|
|
221
|
+
Strands supports interrupts via `toolContext.interrupt(...)` and `event.interrupt(...)`. Both work with the plugin: `agent.invoke()` returns `AgentResult` with `stopReason: 'interrupt'` and `interrupts: [...]`. Pair this with a signal handler that supplies responses, then resume by calling `agent.invoke(responses)`.
|
|
222
|
+
|
|
223
|
+
Interrupts also survive the activity boundary when raised from an `activityAsTool`-wrapped activity. The plugin's failure converter packages the interrupt as a typed `ApplicationFailure`, and `TemporalActivityTool` re-raises it through the agent's interrupt machinery on the workflow side, so `AgentResult.interrupts` is populated just like the in-workflow case.
|
|
224
|
+
|
|
225
|
+
This relies on the plugin's failure converter, which is installed via the client's data converter. **Attach `StrandsPlugin` to the client** (not just the worker) for activity-tool interrupts to work — workers built from that client pick up the plugin automatically.
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
const client = new Client({ /* ... */, plugins: [new StrandsPlugin({ models })] });
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Continue-as-new
|
|
232
|
+
|
|
233
|
+
A chat-style workflow accumulates history with every turn and will eventually hit Temporal's per-workflow history limit. `workflowInfo().continueAsNewSuggested` flips true once the server decides history has grown large enough; check it after each turn and hand off to a fresh run, carrying `agent.messages` as input:
|
|
234
|
+
|
|
235
|
+
```ts
|
|
236
|
+
import { defineSignal, setHandler, condition, continueAsNew, workflowInfo } from '@temporalio/workflow';
|
|
237
|
+
import { TemporalAgent } from '@temporalio/strands-agents';
|
|
238
|
+
import type { Message } from '@strands-agents/sdk';
|
|
239
|
+
|
|
240
|
+
export const userSays = defineSignal<[string]>('userSays');
|
|
241
|
+
export const endChat = defineSignal('endChat');
|
|
242
|
+
|
|
243
|
+
export interface ChatInput {
|
|
244
|
+
messages?: Message[];
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export async function chatWorkflow(input: ChatInput = {}): Promise<void> {
|
|
248
|
+
const agent = new TemporalAgent({
|
|
249
|
+
activityOptions: { startToCloseTimeout: '60 seconds' },
|
|
250
|
+
messages: input.messages,
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
const pending: string[] = [];
|
|
254
|
+
let done = false;
|
|
255
|
+
setHandler(userSays, (prompt) => void pending.push(prompt));
|
|
256
|
+
setHandler(endChat, () => void (done = true));
|
|
257
|
+
|
|
258
|
+
while (true) {
|
|
259
|
+
await condition(() => pending.length > 0 || done);
|
|
260
|
+
if (done) return;
|
|
261
|
+
await agent.invoke(pending.shift()!);
|
|
262
|
+
if (workflowInfo().continueAsNewSuggested) {
|
|
263
|
+
await continueAsNew<typeof chatWorkflow>({ messages: agent.messages });
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## MCP
|
|
270
|
+
|
|
271
|
+
`new StrandsPlugin({ mcpClients })` takes a mapping of `name → McpClient factory`, mirroring the `models` pattern. The plugin registers per-server `{name}-listTools` and `{name}-callTool` activities. Workflow-side, `new TemporalMCPClient({ server: 'name' })` is a thin handle: it references the server by name and carries the per-call activity options.
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
import { McpClient } from '@strands-agents/sdk';
|
|
275
|
+
import { TemporalMCPClient } from '@temporalio/strands-agents';
|
|
276
|
+
|
|
277
|
+
// workflow
|
|
278
|
+
export async function mcpWorkflow(prompt: string) {
|
|
279
|
+
const echo = new TemporalMCPClient({
|
|
280
|
+
server: 'echo',
|
|
281
|
+
activityOptions: { startToCloseTimeout: '30 seconds' },
|
|
282
|
+
});
|
|
283
|
+
const agent = new TemporalAgent({
|
|
284
|
+
activityOptions: { startToCloseTimeout: '60 seconds' },
|
|
285
|
+
tools: [echo],
|
|
286
|
+
});
|
|
287
|
+
return await agent.invoke(prompt);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// worker
|
|
291
|
+
new Worker({
|
|
292
|
+
// ...
|
|
293
|
+
plugins: [
|
|
294
|
+
new StrandsPlugin({
|
|
295
|
+
mcpClients: {
|
|
296
|
+
echo: () => new McpClient({ url: 'http://localhost:8765/mcp' }),
|
|
297
|
+
},
|
|
298
|
+
}),
|
|
299
|
+
],
|
|
300
|
+
});
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
Each factory returns a fully configured `McpClient`. The connection is opened lazily on first use rather than at worker startup.
|
|
304
|
+
|
|
305
|
+
By default, `TemporalMCPClient` re-lists the server's tools (via `{name}-listTools`) on every agent turn, so an MCP server that is restarted or redeployed mid-workflow — with tools added, removed, or renamed — is picked up. To list the tools just once at the beginning of the workflow and reuse that schema for the workflow's lifetime (one fewer activity per turn), set `cacheTools: true`:
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
const echo = new TemporalMCPClient({
|
|
309
|
+
server: 'echo',
|
|
310
|
+
cacheTools: true,
|
|
311
|
+
activityOptions: { startToCloseTimeout: '30 seconds' },
|
|
312
|
+
});
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
To amortize connection setup, the `{name}-listTools` and `{name}-callTool` activities share one worker-process MCP connection and reuse it across calls. The connection is disconnected after it sits idle for `mcpConnectionIdleTimeout` (default 5 minutes); the timer resets on every reuse. `mcpConnectionIdleTimeout` accepts a millisecond number or a duration string (e.g. `'30 seconds'`), like `startToCloseTimeout`:
|
|
316
|
+
|
|
317
|
+
```ts
|
|
318
|
+
new StrandsPlugin({
|
|
319
|
+
mcpClients: { echo: () => new McpClient({ url: 'http://localhost:8765/mcp' }) },
|
|
320
|
+
mcpConnectionIdleTimeout: '30 seconds',
|
|
321
|
+
});
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## Observability
|
|
325
|
+
|
|
326
|
+
`StrandsPlugin` composes cleanly with [`OpenTelemetryPlugin`](../interceptors-opentelemetry). Register both on the client and the worker. You'll get OTel spans around the model, tool, and MCP activities the plugin schedules, plus any spans Strands itself emits inside `invoke`:
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
import { OpenTelemetryPlugin } from '@temporalio/interceptors-opentelemetry';
|
|
330
|
+
import { Resource } from '@opentelemetry/resources';
|
|
331
|
+
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
332
|
+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
|
|
333
|
+
|
|
334
|
+
const otel = new OpenTelemetryPlugin({
|
|
335
|
+
resource: new Resource({ 'service.name': 'strands-worker' }),
|
|
336
|
+
spanProcessor: new SimpleSpanProcessor(new OTLPTraceExporter()),
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
// client
|
|
340
|
+
const client = new Client({ plugins: [otel] });
|
|
341
|
+
|
|
342
|
+
// worker
|
|
343
|
+
const worker = await Worker.create({
|
|
344
|
+
connection,
|
|
345
|
+
taskQueue: 'strands',
|
|
346
|
+
workflowsPath: require.resolve('./workflow'),
|
|
347
|
+
plugins: [otel, new StrandsPlugin({ models })],
|
|
348
|
+
});
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
See the [OpenTelemetry interceptor README](../interceptors-opentelemetry) for exporter setup.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Stub module that the StrandsPlugin's bundler config uses to replace
|
|
3
|
+
// worker-only transport modules and `node:*` schemes that
|
|
4
|
+
// `@strands-agents/sdk/mcp.js`/`mcp-config.js` import statically but that
|
|
5
|
+
// the workflow never reaches at runtime.
|
|
6
|
+
//
|
|
7
|
+
// `@strands-agents/sdk/mcp.js` does named imports like
|
|
8
|
+
// `import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'`,
|
|
9
|
+
// so a pure-empty module would fail webpack's ES-module named-export check
|
|
10
|
+
// at build time. Export every name MCP/Strands' static imports reach as a
|
|
11
|
+
// no-op class. Workflow code never instantiates these — the real transports
|
|
12
|
+
// run worker-side from the user's `mcpClients` factories.
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.SSEClientTransport = exports.StdioClientTransport = exports.StreamableHTTPClientTransport = void 0;
|
|
15
|
+
class WorkflowSandboxStub {
|
|
16
|
+
}
|
|
17
|
+
exports.StreamableHTTPClientTransport = WorkflowSandboxStub;
|
|
18
|
+
exports.StdioClientTransport = WorkflowSandboxStub;
|
|
19
|
+
exports.SSEClientTransport = WorkflowSandboxStub;
|
|
20
|
+
exports.default = WorkflowSandboxStub;
|
|
21
|
+
//# sourceMappingURL=empty-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"empty-module.js","sourceRoot":"","sources":["../src/empty-module.ts"],"names":[],"mappings":";AAAA,sEAAsE;AACtE,0DAA0D;AAC1D,0EAA0E;AAC1E,yCAAyC;AACzC,EAAE;AACF,uDAAuD;AACvD,wGAAwG;AACxG,2EAA2E;AAC3E,0EAA0E;AAC1E,4EAA4E;AAC5E,0DAA0D;;;AAE1D,MAAM,mBAAmB;CAAG;AAGH,4DAA6B;AAC7B,mDAAoB;AACpB,iDAAkB;AAE3C,kBAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DefaultFailureConverter, type FailureConverter, type PayloadConverter, type ProtoFailure, type SerializationContext } from '@temporalio/common';
|
|
2
|
+
export declare const STRANDS_INTERRUPT_TYPE = "StrandsInterrupt";
|
|
3
|
+
/**
|
|
4
|
+
* Failure converter that preserves Strands `InterruptError` payloads across the
|
|
5
|
+
* activity boundary as typed, non-retryable {@link ApplicationFailure}s and
|
|
6
|
+
* marks deterministic Strands model errors as non-retryable.
|
|
7
|
+
*
|
|
8
|
+
* Read by the worker and client via {@link DataConverter.failureConverterPath};
|
|
9
|
+
* the named export below is what {@link StrandsPlugin} wires in.
|
|
10
|
+
*/
|
|
11
|
+
export declare class StrandsFailureConverter extends DefaultFailureConverter implements FailureConverter {
|
|
12
|
+
errorToFailure(err: unknown, payloadConverter: PayloadConverter, context?: SerializationContext): ProtoFailure;
|
|
13
|
+
}
|
|
14
|
+
export declare const failureConverter: FailureConverter;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.failureConverter = exports.StrandsFailureConverter = exports.STRANDS_INTERRUPT_TYPE = void 0;
|
|
4
|
+
const sdk_1 = require("@strands-agents/sdk");
|
|
5
|
+
const common_1 = require("@temporalio/common");
|
|
6
|
+
exports.STRANDS_INTERRUPT_TYPE = 'StrandsInterrupt';
|
|
7
|
+
function isInterruptError(err) {
|
|
8
|
+
if (err === null || typeof err !== 'object')
|
|
9
|
+
return false;
|
|
10
|
+
const candidate = err;
|
|
11
|
+
if (!Array.isArray(candidate.interrupts) || candidate.interrupts.length === 0)
|
|
12
|
+
return false;
|
|
13
|
+
const first = candidate.interrupts[0];
|
|
14
|
+
return typeof first?.toJSON === 'function';
|
|
15
|
+
}
|
|
16
|
+
const TERMINAL_ERROR_TYPES = [
|
|
17
|
+
{ ctor: sdk_1.ContextWindowOverflowError, name: 'ContextWindowOverflowError' },
|
|
18
|
+
{ ctor: sdk_1.MaxTokensError, name: 'MaxTokensError' },
|
|
19
|
+
{ ctor: sdk_1.StructuredOutputError, name: 'StructuredOutputError' },
|
|
20
|
+
];
|
|
21
|
+
function rewriteError(err) {
|
|
22
|
+
if (isInterruptError(err)) {
|
|
23
|
+
const details = err.interrupts.map((i) => i.toJSON());
|
|
24
|
+
const names = err.interrupts.map((i) => i.toJSON().name).join(',');
|
|
25
|
+
return common_1.ApplicationFailure.create({
|
|
26
|
+
message: `interrupt:${names}`,
|
|
27
|
+
type: exports.STRANDS_INTERRUPT_TYPE,
|
|
28
|
+
nonRetryable: true,
|
|
29
|
+
details,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (err instanceof Error) {
|
|
33
|
+
for (const { ctor, name } of TERMINAL_ERROR_TYPES) {
|
|
34
|
+
if (err instanceof ctor) {
|
|
35
|
+
return common_1.ApplicationFailure.create({
|
|
36
|
+
message: err.message,
|
|
37
|
+
type: name,
|
|
38
|
+
nonRetryable: true,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return err;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Failure converter that preserves Strands `InterruptError` payloads across the
|
|
47
|
+
* activity boundary as typed, non-retryable {@link ApplicationFailure}s and
|
|
48
|
+
* marks deterministic Strands model errors as non-retryable.
|
|
49
|
+
*
|
|
50
|
+
* Read by the worker and client via {@link DataConverter.failureConverterPath};
|
|
51
|
+
* the named export below is what {@link StrandsPlugin} wires in.
|
|
52
|
+
*/
|
|
53
|
+
class StrandsFailureConverter extends common_1.DefaultFailureConverter {
|
|
54
|
+
errorToFailure(err, payloadConverter, context) {
|
|
55
|
+
return super.errorToFailure(rewriteError(err), payloadConverter, context);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.StrandsFailureConverter = StrandsFailureConverter;
|
|
59
|
+
exports.failureConverter = new StrandsFailureConverter();
|
|
60
|
+
//# sourceMappingURL=failure-converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failure-converter.js","sourceRoot":"","sources":["../src/failure-converter.ts"],"names":[],"mappings":";;;AAAA,6CAAwG;AACxG,+CAO4B;AAEf,QAAA,sBAAsB,GAAG,kBAAkB,CAAC;AAQzD,SAAS,gBAAgB,CAAC,GAAY;IACpC,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC1D,MAAM,SAAS,GAAG,GAA+B,CAAC;IAClD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5F,MAAM,KAAK,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,CAAqC,CAAC;IAC1E,OAAO,OAAO,KAAK,EAAE,MAAM,KAAK,UAAU,CAAC;AAC7C,CAAC;AAED,MAAM,oBAAoB,GAAG;IAC3B,EAAE,IAAI,EAAE,gCAA0B,EAAE,IAAI,EAAE,4BAA4B,EAAE;IACxE,EAAE,IAAI,EAAE,oBAAc,EAAE,IAAI,EAAE,gBAAgB,EAAE;IAChD,EAAE,IAAI,EAAE,2BAAqB,EAAE,IAAI,EAAE,uBAAuB,EAAE;CAC/D,CAAC;AAEF,SAAS,YAAY,CAAC,GAAY;IAChC,IAAI,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;QACtD,MAAM,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnE,OAAO,2BAAkB,CAAC,MAAM,CAAC;YAC/B,OAAO,EAAE,aAAa,KAAK,EAAE;YAC7B,IAAI,EAAE,8BAAsB;YAC5B,YAAY,EAAE,IAAI;YAClB,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IACD,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACzB,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,oBAAoB,EAAE,CAAC;YAClD,IAAI,GAAG,YAAY,IAAI,EAAE,CAAC;gBACxB,OAAO,2BAAkB,CAAC,MAAM,CAAC;oBAC/B,OAAO,EAAE,GAAG,CAAC,OAAO;oBACpB,IAAI,EAAE,IAAI;oBACV,YAAY,EAAE,IAAI;iBACnB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;;GAOG;AACH,MAAa,uBAAwB,SAAQ,gCAAuB;IACzD,cAAc,CACrB,GAAY,EACZ,gBAAkC,EAClC,OAA8B;QAE9B,OAAO,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;IAC5E,CAAC;CACF;AARD,0DAQC;AAEY,QAAA,gBAAgB,GAAqB,IAAI,uBAAuB,EAAE,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps an async function so it heartbeats at half the activity's
|
|
3
|
+
* heartbeat timeout for the duration of the call. No-op when the
|
|
4
|
+
* activity has no heartbeat timeout configured.
|
|
5
|
+
*/
|
|
6
|
+
export declare function autoHeartbeat<Args extends unknown[], Ret>(fn: (...args: Args) => Promise<Ret>): (...args: Args) => Promise<Ret>;
|
package/lib/heartbeat.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.autoHeartbeat = autoHeartbeat;
|
|
4
|
+
const activity_1 = require("@temporalio/activity");
|
|
5
|
+
/**
|
|
6
|
+
* Wraps an async function so it heartbeats at half the activity's
|
|
7
|
+
* heartbeat timeout for the duration of the call. No-op when the
|
|
8
|
+
* activity has no heartbeat timeout configured.
|
|
9
|
+
*/
|
|
10
|
+
function autoHeartbeat(fn) {
|
|
11
|
+
return async function autoHeartbeatWrapper(...args) {
|
|
12
|
+
const heartbeatTimeoutMs = activity_1.Context.current().info.heartbeatTimeoutMs;
|
|
13
|
+
let timer;
|
|
14
|
+
if (heartbeatTimeoutMs && heartbeatTimeoutMs > 0) {
|
|
15
|
+
const interval = heartbeatTimeoutMs / 2;
|
|
16
|
+
timer = setInterval(() => activity_1.Context.current().heartbeat(), interval);
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
return await fn.apply(this, args);
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
if (timer !== undefined)
|
|
23
|
+
clearInterval(timer);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=heartbeat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heartbeat.js","sourceRoot":"","sources":["../src/heartbeat.ts"],"names":[],"mappings":";;AAOA,sCAgBC;AAvBD,mDAA+C;AAE/C;;;;GAIG;AACH,SAAgB,aAAa,CAC3B,EAAmC;IAEnC,OAAO,KAAK,UAAU,oBAAoB,CAAgB,GAAG,IAAU;QACrE,MAAM,kBAAkB,GAAG,kBAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC;QACrE,IAAI,KAAiC,CAAC;QACtC,IAAI,kBAAkB,IAAI,kBAAkB,GAAG,CAAC,EAAE,CAAC;YACjD,MAAM,QAAQ,GAAG,kBAAkB,GAAG,CAAC,CAAC;YACxC,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,kBAAO,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,EAAE,QAAQ,CAAC,CAAC;QACrE,CAAC;QACD,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACpC,CAAC;gBAAS,CAAC;YACT,IAAI,KAAK,KAAK,SAAS;gBAAE,aAAa,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import './load-polyfills';
|
|
2
|
+
export { StrandsPlugin, type StrandsPluginOptions } from './plugin';
|
|
3
|
+
export { TemporalAgent, type TemporalAgentOptions } from './temporal-agent';
|
|
4
|
+
export { TemporalModel, type TemporalModelOptions } from './temporal-model';
|
|
5
|
+
export { TemporalMCPClient, type TemporalMCPClientOptions, type McpToolInfo, type CallToolInput, } from './temporal-mcp-client';
|
|
6
|
+
export { TemporalMCPTool } from './temporal-mcp-tool';
|
|
7
|
+
export { TemporalActivityTool, type ActivityAsToolOptions } from './temporal-activity-tool';
|
|
8
|
+
export { STRANDS_INTERRUPT_TYPE, StrandsFailureConverter } from './failure-converter';
|
|
9
|
+
export * as workflow from './workflow';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
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.workflow = exports.StrandsFailureConverter = exports.STRANDS_INTERRUPT_TYPE = exports.TemporalActivityTool = exports.TemporalMCPTool = exports.TemporalMCPClient = exports.TemporalModel = exports.TemporalAgent = exports.StrandsPlugin = void 0;
|
|
27
|
+
// eslint-disable-next-line import/no-unassigned-import
|
|
28
|
+
require("./load-polyfills");
|
|
29
|
+
var plugin_1 = require("./plugin");
|
|
30
|
+
Object.defineProperty(exports, "StrandsPlugin", { enumerable: true, get: function () { return plugin_1.StrandsPlugin; } });
|
|
31
|
+
var temporal_agent_1 = require("./temporal-agent");
|
|
32
|
+
Object.defineProperty(exports, "TemporalAgent", { enumerable: true, get: function () { return temporal_agent_1.TemporalAgent; } });
|
|
33
|
+
var temporal_model_1 = require("./temporal-model");
|
|
34
|
+
Object.defineProperty(exports, "TemporalModel", { enumerable: true, get: function () { return temporal_model_1.TemporalModel; } });
|
|
35
|
+
var temporal_mcp_client_1 = require("./temporal-mcp-client");
|
|
36
|
+
Object.defineProperty(exports, "TemporalMCPClient", { enumerable: true, get: function () { return temporal_mcp_client_1.TemporalMCPClient; } });
|
|
37
|
+
var temporal_mcp_tool_1 = require("./temporal-mcp-tool");
|
|
38
|
+
Object.defineProperty(exports, "TemporalMCPTool", { enumerable: true, get: function () { return temporal_mcp_tool_1.TemporalMCPTool; } });
|
|
39
|
+
var temporal_activity_tool_1 = require("./temporal-activity-tool");
|
|
40
|
+
Object.defineProperty(exports, "TemporalActivityTool", { enumerable: true, get: function () { return temporal_activity_tool_1.TemporalActivityTool; } });
|
|
41
|
+
var failure_converter_1 = require("./failure-converter");
|
|
42
|
+
Object.defineProperty(exports, "STRANDS_INTERRUPT_TYPE", { enumerable: true, get: function () { return failure_converter_1.STRANDS_INTERRUPT_TYPE; } });
|
|
43
|
+
Object.defineProperty(exports, "StrandsFailureConverter", { enumerable: true, get: function () { return failure_converter_1.StrandsFailureConverter; } });
|
|
44
|
+
exports.workflow = __importStar(require("./workflow"));
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,4BAA0B;AAE1B,mCAAoE;AAA3D,uGAAA,aAAa,OAAA;AACtB,mDAA4E;AAAnE,+GAAA,aAAa,OAAA;AACtB,mDAA4E;AAAnE,+GAAA,aAAa,OAAA;AACtB,6DAK+B;AAJ7B,wHAAA,iBAAiB,OAAA;AAKnB,yDAAsD;AAA7C,oHAAA,eAAe,OAAA;AACxB,mEAA4F;AAAnF,8HAAA,oBAAoB,OAAA;AAC7B,yDAAsF;AAA7E,2HAAA,sBAAsB,OAAA;AAAE,4HAAA,uBAAuB,OAAA;AACxD,uDAAuC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { JSONSchema } from '@strands-agents/sdk';
|
|
3
|
+
/**
|
|
4
|
+
* Normalize a tool input schema to a JSON Schema.
|
|
5
|
+
*
|
|
6
|
+
* A literal JSON Schema is returned unchanged; a Zod schema is converted via
|
|
7
|
+
* zod 4's native {@link z.toJSONSchema}. The conversion is pure and
|
|
8
|
+
* deterministic, so this is safe to call from workflow code.
|
|
9
|
+
*/
|
|
10
|
+
export declare function toJsonSchema(schema: JSONSchema | z.ZodType | undefined): JSONSchema | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toJsonSchema = toJsonSchema;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Normalize a tool input schema to a JSON Schema.
|
|
7
|
+
*
|
|
8
|
+
* A literal JSON Schema is returned unchanged; a Zod schema is converted via
|
|
9
|
+
* zod 4's native {@link z.toJSONSchema}. The conversion is pure and
|
|
10
|
+
* deterministic, so this is safe to call from workflow code.
|
|
11
|
+
*/
|
|
12
|
+
function toJsonSchema(schema) {
|
|
13
|
+
if (schema === undefined)
|
|
14
|
+
return undefined;
|
|
15
|
+
return schema instanceof zod_1.z.ZodType ? zod_1.z.toJSONSchema(schema) : schema;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=json-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.js","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":";;AAUA,oCAGC;AAbD,6BAAwB;AAGxB;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,MAA0C;IACrE,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC3C,OAAO,MAAM,YAAY,OAAC,CAAC,OAAO,CAAC,CAAC,CAAE,OAAC,CAAC,YAAY,CAAC,MAAM,CAAgB,CAAC,CAAC,CAAC,MAAM,CAAC;AACvF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
if (typeof globalThis.Headers === 'undefined') {
|
|
7
|
+
globalThis.Headers = headers_polyfill_1.Headers;
|
|
8
|
+
}
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports,import/no-unassigned-import
|
|
10
|
+
require('web-streams-polyfill/polyfill');
|
|
11
|
+
if (!('structuredClone' in globalThis)) {
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
13
|
+
const structuredClone = require('@ungap/structured-clone');
|
|
14
|
+
globalThis.structuredClone = structuredClone.default;
|
|
15
|
+
}
|
|
16
|
+
// `@ungap/structured-clone` calls `crypto.randomUUID()` internally, but the
|
|
17
|
+
// workflow sandbox bans the real `crypto` module. Use the SDK's
|
|
18
|
+
// deterministic `uuid4` so the polyfill still works at replay.
|
|
19
|
+
if (typeof globalThis.crypto?.randomUUID !== 'function') {
|
|
20
|
+
globalThis.crypto = { ...(globalThis.crypto ?? {}), randomUUID: workflow_1.uuid4 };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# 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,mDAAgE;AAEhE,IAAI,IAAA,4BAAiB,GAAE,EAAE,CAAC;IACxB,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;IAEzC,IAAI,CAAC,CAAC,iBAAiB,IAAI,UAAU,CAAC,EAAE,CAAC;QACvC,iEAAiE;QACjE,MAAM,eAAe,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAC3D,UAAU,CAAC,eAAe,GAAG,eAAe,CAAC,OAAO,CAAC;IACvD,CAAC;IAED,4EAA4E;IAC5E,gEAAgE;IAChE,+DAA+D;IAC/D,IAAI,OAAO,UAAU,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,EAAE,CAAC;QACxD,UAAU,CAAC,MAAM,GAAG,EAAE,GAAG,CAAC,UAAU,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,gBAAK,EAAW,CAAC;IACnF,CAAC;AACH,CAAC"}
|