@temporalio/langsmith 1.20.3 → 1.21.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.
- package/README.md +8 -12
- package/lib/async-hooks-shim.d.ts +13 -0
- package/lib/async-hooks-shim.js +17 -0
- package/lib/async-hooks-shim.js.map +1 -0
- package/lib/plugin.d.ts +1 -0
- package/lib/plugin.js +11 -7
- package/lib/plugin.js.map +1 -1
- package/lib/workflow-interceptors.d.ts +6 -8
- package/lib/workflow-interceptors.js +31 -127
- package/lib/workflow-interceptors.js.map +1 -1
- package/package.json +8 -8
- package/src/async-hooks-shim.ts +16 -0
- package/src/plugin.ts +11 -7
- package/src/workflow-interceptors.ts +47 -145
package/README.md
CHANGED
|
@@ -171,23 +171,19 @@ below. Each row is exercised by the plugin's test suite.
|
|
|
171
171
|
| Inside a **Workflow** body | ✅ | Replay-safe: deterministic IDs, emitted out-of-isolate, suppressed on replay. Works whether or not a parent trace is propagated in. |
|
|
172
172
|
| Inside **signal / query / update** handlers | ✅ | Handler-body `traceable` runs nest under the handler's run (workflow-body semantics). Temporal-internal queries (`__temporal*`, `__stack_trace`) are never traced. |
|
|
173
173
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
made _after_ an `await` in the same scope, parenting falls back to the workflow
|
|
179
|
-
run. This affects only the visual shape of the trace, never workflow history or
|
|
180
|
-
control flow. Activity-body and client-side `traceable` use LangSmith's real
|
|
181
|
-
async context and are unaffected.
|
|
174
|
+
Inside a Workflow, parent resolution rides the SDK-provided `AsyncLocalStorage`
|
|
175
|
+
the worker injects onto the workflow-sandbox global, so context propagates
|
|
176
|
+
across `await` boundaries and `Promise.all(...)` fan-out exactly as it does
|
|
177
|
+
outside the isolate — the same deterministic run tree replays identically.
|
|
182
178
|
|
|
183
179
|
## Process-wide effects to be aware of
|
|
184
180
|
|
|
185
181
|
- **Workflow context provider.** Loading the plugin's workflow interceptor
|
|
186
182
|
module installs a global LangSmith async-context provider inside the workflow
|
|
187
|
-
isolate (via `AsyncLocalStorageProviderSingleton.initializeGlobalInstance`)
|
|
188
|
-
|
|
189
|
-
Workflow. It is scoped to the
|
|
190
|
-
client/worker process context.
|
|
183
|
+
isolate (via `AsyncLocalStorageProviderSingleton.initializeGlobalInstance`),
|
|
184
|
+
backed by the SDK-provided `AsyncLocalStorage`. This is what lets unchanged
|
|
185
|
+
`traceable` calls find their parent inside a Workflow. It is scoped to the
|
|
186
|
+
workflow bundle and does not affect your client/worker process context.
|
|
191
187
|
|
|
192
188
|
## Composing with other plugins
|
|
193
189
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundle-time stand-in for `node:async_hooks` inside the workflow isolate, where
|
|
3
|
+
* that builtin is unavailable. The plugin's bundler aliases `node:async_hooks`
|
|
4
|
+
* to this module (see {@link bundleRewritesPlugin} in `plugin.ts`) so LangSmith's
|
|
5
|
+
* `import { AsyncLocalStorage } from "node:async_hooks"` — including its
|
|
6
|
+
* `new AsyncLocalStorage()` and static `AsyncLocalStorage.snapshot()` — resolves
|
|
7
|
+
* to the real, async-context-tracking `AsyncLocalStorage` the SDK worker injects
|
|
8
|
+
* onto the workflow-sandbox global.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare const AsyncLocalStorage: typeof import("async_hooks").AsyncLocalStorage;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bundle-time stand-in for `node:async_hooks` inside the workflow isolate, where
|
|
4
|
+
* that builtin is unavailable. The plugin's bundler aliases `node:async_hooks`
|
|
5
|
+
* to this module (see {@link bundleRewritesPlugin} in `plugin.ts`) so LangSmith's
|
|
6
|
+
* `import { AsyncLocalStorage } from "node:async_hooks"` — including its
|
|
7
|
+
* `new AsyncLocalStorage()` and static `AsyncLocalStorage.snapshot()` — resolves
|
|
8
|
+
* to the real, async-context-tracking `AsyncLocalStorage` the SDK worker injects
|
|
9
|
+
* onto the workflow-sandbox global.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AsyncLocalStorage = void 0;
|
|
16
|
+
exports.AsyncLocalStorage = globalThis.AsyncLocalStorage;
|
|
17
|
+
//# sourceMappingURL=async-hooks-shim.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-hooks-shim.js","sourceRoot":"","sources":["../src/async-hooks-shim.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAIU,QAAA,iBAAiB,GAAG,UAAU,CAAC,iBAAiB,CAAC"}
|
package/lib/plugin.d.ts
CHANGED
|
@@ -73,6 +73,7 @@ export declare class LangSmithPlugin extends SimplePlugin {
|
|
|
73
73
|
private readonly emitter;
|
|
74
74
|
private readonly workflowConfig;
|
|
75
75
|
private readonly workflowInterceptorModule;
|
|
76
|
+
private readonly asyncHooksShimModule;
|
|
76
77
|
constructor(options?: LangSmithPluginOptions);
|
|
77
78
|
configureClient(options: ClientOptions): ClientOptions;
|
|
78
79
|
configureWorker(options: WorkerOptions): WorkerOptions;
|
package/lib/plugin.js
CHANGED
|
@@ -48,8 +48,10 @@ class LangSmithPlugin extends plugin_1.SimplePlugin {
|
|
|
48
48
|
client;
|
|
49
49
|
emitter;
|
|
50
50
|
workflowConfig;
|
|
51
|
-
// Absolute
|
|
51
|
+
// Absolute paths so the workflow bundler resolves them under strict pnpm.
|
|
52
52
|
workflowInterceptorModule = require.resolve('./workflow-interceptors');
|
|
53
|
+
// Target of the `node:async_hooks` rewrite; re-exports the runtime-injected ALS.
|
|
54
|
+
asyncHooksShimModule = require.resolve('./async-hooks-shim');
|
|
53
55
|
constructor(options = {}) {
|
|
54
56
|
// super() reads options.name immediately
|
|
55
57
|
super({ name: 'langchain.LangSmithPlugin' });
|
|
@@ -118,7 +120,7 @@ class LangSmithPlugin extends plugin_1.SimplePlugin {
|
|
|
118
120
|
// Double-encode so the injected token is a string literal in the bundle.
|
|
119
121
|
const definitions = { [CONFIG_GLOBAL]: JSON.stringify(JSON.stringify(this.workflowConfig)) };
|
|
120
122
|
const plugins = [...(merged.plugins ?? [])];
|
|
121
|
-
plugins.push(bundleRewritesPlugin(this.
|
|
123
|
+
plugins.push(bundleRewritesPlugin(this.asyncHooksShimModule, definitions));
|
|
122
124
|
return { ...merged, plugins };
|
|
123
125
|
};
|
|
124
126
|
return { ...base, workflowInterceptorModules, ignoreModules, webpackConfigHook };
|
|
@@ -149,13 +151,15 @@ exports.LangSmithPlugin = LangSmithPlugin;
|
|
|
149
151
|
/**
|
|
150
152
|
* A webpack plugin that installs the three Workflow-bundle rewrites LangSmith needs:
|
|
151
153
|
*
|
|
152
|
-
* - redirect `node:async_hooks` to the
|
|
154
|
+
* - redirect `node:async_hooks` to the shim module that re-exports the
|
|
155
|
+
* runtime-injected `AsyncLocalStorage`, so LangSmith's `new AsyncLocalStorage()`
|
|
156
|
+
* and `AsyncLocalStorage.snapshot()` resolve to the real SDK-provided ALS.
|
|
153
157
|
* webpack routes `node:` requests through a scheme handler before alias
|
|
154
158
|
* resolution, so `resolve.alias` can't do this; `NormalModuleReplacementPlugin`
|
|
155
159
|
* rewrites the request in `beforeResolve`. Paired with the `ignoreModules`
|
|
156
160
|
* whitelist (see {@link LangSmithPlugin.configureBundler}). The rewrite target
|
|
157
|
-
* is the resolved absolute module path so webpack dedupes to one
|
|
158
|
-
*
|
|
161
|
+
* is the resolved absolute module path so webpack dedupes to one instance
|
|
162
|
+
* regardless of issuer.
|
|
159
163
|
* - redirect langsmith's node-only `utils/{fs,worker_threads}.cjs` to their
|
|
160
164
|
* `.browser.cjs` siblings so node builtins stay out of the isolate. Scoped to
|
|
161
165
|
* langsmith so a user's own `fs.cjs` is never rewritten.
|
|
@@ -167,13 +171,13 @@ exports.LangSmithPlugin = LangSmithPlugin;
|
|
|
167
171
|
* installers (e.g. pnpm with `hoist=false`). Using the compiler's own webpack
|
|
168
172
|
* also guarantees the exact instance running the bundle — never a second copy.
|
|
169
173
|
*/
|
|
170
|
-
function bundleRewritesPlugin(
|
|
174
|
+
function bundleRewritesPlugin(asyncHooksShimModule, definitions) {
|
|
171
175
|
const swap = (s) => s.replace(/\.cjs$/, '.browser.cjs');
|
|
172
176
|
return {
|
|
173
177
|
apply(compiler) {
|
|
174
178
|
const { NormalModuleReplacementPlugin, DefinePlugin } = compiler.webpack;
|
|
175
179
|
new NormalModuleReplacementPlugin(/^node:async_hooks$/, (resource) => {
|
|
176
|
-
resource.request =
|
|
180
|
+
resource.request = asyncHooksShimModule;
|
|
177
181
|
}).apply(compiler);
|
|
178
182
|
new NormalModuleReplacementPlugin(/[/\\]utils[/\\](?:fs|worker_threads)\.cjs$/, (resource) => {
|
|
179
183
|
// Resolved sibling-relative requires (`./fs.cjs`) carry the absolute
|
package/lib/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAEH,yCAAmC;AAGnC,+CAAkD;AAGlD,iEAAyG;AACzG,6DAA+D;AAC/D,mCAA+C;AAO/C,sEAAsE;AACtE,MAAM,aAAa,GAAG,+BAA+B,CAAC;AAEtD,gFAAgF;AAChF,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAmCzC;;;;;;;;;;;;;GAaG;AACH,MAAa,eAAgB,SAAQ,qBAAY;IAC9B,MAAM,CAAS;IACf,OAAO,CAAgB;IACvB,cAAc,CAA0B;IACzD,
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAEH,yCAAmC;AAGnC,+CAAkD;AAGlD,iEAA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AAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC5C,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAEnB,IAAI,YAAY,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAChD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Workflow-isolate interceptors and the
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* LangSmith's
|
|
7
|
-
*
|
|
8
|
-
* Internal: the worker loads this module by specifier and the bundler aliases
|
|
9
|
-
* `node:async_hooks` to it — it is not a hand-import API.
|
|
2
|
+
* Workflow-isolate interceptors and the LangSmith context provider. Loaded into
|
|
3
|
+
* the workflow bundle (via the plugin's `workflowModules`) and runs entirely
|
|
4
|
+
* inside the V8 isolate. Trace context propagates through the real,
|
|
5
|
+
* async-context-tracking `AsyncLocalStorage` the SDK worker injects onto the
|
|
6
|
+
* workflow-sandbox global; the plugin and LangSmith's own load-time init
|
|
7
|
+
* converge on one shared store (see {@link sharedStore}).
|
|
10
8
|
*
|
|
11
9
|
* @module
|
|
12
10
|
* @internal
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Workflow-isolate interceptors and the
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* LangSmith's
|
|
8
|
-
*
|
|
9
|
-
* Internal: the worker loads this module by specifier and the bundler aliases
|
|
10
|
-
* `node:async_hooks` to it — it is not a hand-import API.
|
|
3
|
+
* Workflow-isolate interceptors and the LangSmith context provider. Loaded into
|
|
4
|
+
* the workflow bundle (via the plugin's `workflowModules`) and runs entirely
|
|
5
|
+
* inside the V8 isolate. Trace context propagates through the real,
|
|
6
|
+
* async-context-tracking `AsyncLocalStorage` the SDK worker injects onto the
|
|
7
|
+
* workflow-sandbox global; the plugin and LangSmith's own load-time init
|
|
8
|
+
* converge on one shared store (see {@link sharedStore}).
|
|
11
9
|
*
|
|
12
10
|
* @module
|
|
13
11
|
* @internal
|
|
14
12
|
*/
|
|
15
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.AsyncLocalStorage = void 0;
|
|
17
14
|
exports.interceptors = interceptors;
|
|
18
15
|
const traceable_1 = require("langsmith/singletons/traceable");
|
|
19
16
|
const workflow_1 = require("@temporalio/workflow");
|
|
@@ -30,94 +27,8 @@ function readConfig() {
|
|
|
30
27
|
}
|
|
31
28
|
return { addTemporalRuns: false };
|
|
32
29
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* shared by the installed provider, the {@link AsyncLocalStorage} shim, and
|
|
36
|
-
* every interceptor so they all read and write one store. `workflowAmbient`
|
|
37
|
-
* persists across `await` boundaries; `stack` tracks synchronous `traceable`
|
|
38
|
-
* nesting. Under `Promise.all` fan-out parenting falls back to the ambient —
|
|
39
|
-
* trace-shape-only non-determinism, never workflow history.
|
|
40
|
-
*/
|
|
41
|
-
class WorkflowContextManager {
|
|
42
|
-
workflowAmbient;
|
|
43
|
-
stack = [];
|
|
44
|
-
getStore() {
|
|
45
|
-
return this.stack.length > 0 ? this.stack[this.stack.length - 1] : this.workflowAmbient;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Push `context`, run `fn`, pop in `finally`, and return `fn`'s result — the
|
|
49
|
-
* `AsyncLocalStorage.run` contract langsmith relies on.
|
|
50
|
-
*/
|
|
51
|
-
run(context, fn) {
|
|
52
|
-
this.stack.push(context);
|
|
53
|
-
try {
|
|
54
|
-
return fn();
|
|
55
|
-
}
|
|
56
|
-
finally {
|
|
57
|
-
this.stack.pop();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
/** The ambient run an outbound interceptor should propagate / parent under. */
|
|
61
|
-
ambient() {
|
|
62
|
-
return this.getStore();
|
|
63
|
-
}
|
|
64
|
-
/** Run an async scope with a dedicated ambient (workflow execute / handler). */
|
|
65
|
-
async withAmbient(run, fn) {
|
|
66
|
-
const prev = this.workflowAmbient;
|
|
67
|
-
this.workflowAmbient = run;
|
|
68
|
-
try {
|
|
69
|
-
return await fn();
|
|
70
|
-
}
|
|
71
|
-
finally {
|
|
72
|
-
this.workflowAmbient = prev;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
let providerInstalled = false;
|
|
77
|
-
function ensureProviderInstalled(manager) {
|
|
78
|
-
if (providerInstalled) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
providerInstalled = true;
|
|
82
|
-
// LangSmith's `AsyncLocalStorageInterface` requires exactly two members,
|
|
83
|
-
// `getStore` and `run` (it never calls `enterWith`), so we provide only those.
|
|
84
|
-
// The cast bridges the generic `run<T>` signature to the interface's
|
|
85
|
-
// `run: (ctx, () => void) => void`.
|
|
86
|
-
traceable_1.AsyncLocalStorageProviderSingleton.initializeGlobalInstance({
|
|
87
|
-
getStore: () => manager.getStore(),
|
|
88
|
-
run: (context, fn) => manager.run(context, fn),
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
const sharedManager = new WorkflowContextManager();
|
|
92
|
-
ensureProviderInstalled(sharedManager);
|
|
93
|
-
/**
|
|
94
|
-
* Isolate-safe stand-in for Node's `AsyncLocalStorage`. The plugin's bundler
|
|
95
|
-
* aliases `node:async_hooks` (absent in the isolate) to this module so
|
|
96
|
-
* LangSmith's `import { AsyncLocalStorage } from "node:async_hooks"` resolves
|
|
97
|
-
* here. Every instance delegates to {@link sharedManager}.
|
|
98
|
-
*
|
|
99
|
-
* @internal
|
|
100
|
-
*/
|
|
101
|
-
class AsyncLocalStorage {
|
|
102
|
-
getStore() {
|
|
103
|
-
return sharedManager.getStore();
|
|
104
|
-
}
|
|
105
|
-
run(store, fn) {
|
|
106
|
-
return sharedManager.run(store, fn);
|
|
107
|
-
}
|
|
108
|
-
enterWith(_store) {
|
|
109
|
-
/* no-op: parenting inside the isolate is stack-scoped via run() */
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Best-effort equivalent of `AsyncLocalStorage.snapshot()` (used only by
|
|
113
|
-
* LangSmith's async-generator streaming paths). Runs the callback in the
|
|
114
|
-
* current synchronous scope; the isolate has no async context to capture.
|
|
115
|
-
*/
|
|
116
|
-
static snapshot() {
|
|
117
|
-
return (fn, ...args) => fn(...args);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.AsyncLocalStorage = AsyncLocalStorage;
|
|
30
|
+
traceable_1.AsyncLocalStorageProviderSingleton.initializeGlobalInstance(new globalThis.AsyncLocalStorage());
|
|
31
|
+
const sharedStore = traceable_1.AsyncLocalStorageProviderSingleton.getInstance();
|
|
121
32
|
/** Reconstruct the propagated parent run from a Payload-keyed header map. */
|
|
122
33
|
function reconstructParent(headers) {
|
|
123
34
|
return (0, run_tree_1.runTreeFromContext)((0, propagation_1.readContextHeader)(headers));
|
|
@@ -167,10 +78,8 @@ function buildReplaySafeRunTree(config, params) {
|
|
|
167
78
|
}, params.generateNewUuid4);
|
|
168
79
|
}
|
|
169
80
|
class LangSmithWorkflowInbound {
|
|
170
|
-
ctx;
|
|
171
81
|
config;
|
|
172
|
-
constructor(
|
|
173
|
-
this.ctx = ctx;
|
|
82
|
+
constructor(config) {
|
|
174
83
|
this.config = config;
|
|
175
84
|
}
|
|
176
85
|
async execute(input, next) {
|
|
@@ -179,21 +88,21 @@ class LangSmithWorkflowInbound {
|
|
|
179
88
|
}
|
|
180
89
|
async handleSignal(input, next) {
|
|
181
90
|
const parent = reconstructParent(input.headers);
|
|
182
|
-
await this.runInbound((0, run_tree_1.handleSignalRunName)(input.signalName), run_tree_1.RUN_TYPE.CHAIN, parent, { args: input.args }, () => next(input)
|
|
91
|
+
await this.runInbound((0, run_tree_1.handleSignalRunName)(input.signalName), run_tree_1.RUN_TYPE.CHAIN, parent, { args: input.args }, () => next(input));
|
|
183
92
|
}
|
|
184
93
|
async handleQuery(input, next) {
|
|
185
94
|
if ((0, propagation_1.isInternalQuery)(input.queryName)) {
|
|
186
95
|
return next(input);
|
|
187
96
|
}
|
|
188
97
|
const parent = reconstructParent(input.headers);
|
|
189
|
-
return this.runInbound((0, run_tree_1.handleQueryRunName)(input.queryName), run_tree_1.RUN_TYPE.CHAIN, parent, { args: input.args }, () => next(input),
|
|
98
|
+
return this.runInbound((0, run_tree_1.handleQueryRunName)(input.queryName), run_tree_1.RUN_TYPE.CHAIN, parent, { args: input.args }, () => next(input),
|
|
190
99
|
// Read-only: mint run ids from the nondeterministic unsafe random source so the
|
|
191
100
|
// handler never draws from the Workflow main PRNG (which a clean replay would not advance).
|
|
192
101
|
(0, workflow_1.workflowInfo)().unsafe.random.uuid4);
|
|
193
102
|
}
|
|
194
103
|
async handleUpdate(input, next) {
|
|
195
104
|
const parent = reconstructParent(input.headers);
|
|
196
|
-
return this.runInbound((0, run_tree_1.handleUpdateRunName)(input.name), run_tree_1.RUN_TYPE.CHAIN, parent, { args: input.args }, () => next(input)
|
|
105
|
+
return this.runInbound((0, run_tree_1.handleUpdateRunName)(input.name), run_tree_1.RUN_TYPE.CHAIN, parent, { args: input.args }, () => next(input));
|
|
197
106
|
}
|
|
198
107
|
validateUpdate(input, next) {
|
|
199
108
|
// Read-only: mint run ids from the nondeterministic unsafe random source so the validator
|
|
@@ -203,10 +112,9 @@ class LangSmithWorkflowInbound {
|
|
|
203
112
|
// Propagation only: install the reconstructed parent (or a placeholder parent
|
|
204
113
|
// when none was propagated, to keep a validator-body `traceable` off the
|
|
205
114
|
// no-parent `crypto` path) so the validator body nests under the update's
|
|
206
|
-
// trace.
|
|
207
|
-
// not the async `withAmbient`.
|
|
115
|
+
// trace.
|
|
208
116
|
const ambient = asReplaySafeParent(reconstructParent(input.headers), generateNewUuid4) ?? placeholderRoot(generateNewUuid4);
|
|
209
|
-
|
|
117
|
+
sharedStore.run(ambient, () => next(input));
|
|
210
118
|
return;
|
|
211
119
|
}
|
|
212
120
|
const run = buildReplaySafeRunTree(this.config, {
|
|
@@ -217,11 +125,11 @@ class LangSmithWorkflowInbound {
|
|
|
217
125
|
generateNewUuid4,
|
|
218
126
|
});
|
|
219
127
|
// Validators are synchronous and must not be made async; emit start/end
|
|
220
|
-
// around the synchronous call, with the run installed
|
|
221
|
-
// `traceable` in the validator body nests under it.
|
|
128
|
+
// around the synchronous call, with the run installed as the active store so
|
|
129
|
+
// a `traceable` in the validator body nests under it.
|
|
222
130
|
void run.postRun();
|
|
223
131
|
try {
|
|
224
|
-
|
|
132
|
+
sharedStore.run(run, () => next(input));
|
|
225
133
|
void run.end({});
|
|
226
134
|
}
|
|
227
135
|
catch (err) {
|
|
@@ -232,14 +140,12 @@ class LangSmithWorkflowInbound {
|
|
|
232
140
|
void run.patchRun();
|
|
233
141
|
}
|
|
234
142
|
/**
|
|
235
|
-
* Open the inbound run, install it as the active run for `next
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
* `execute` (scoped: false) installs a persistent ambient that survives the body's
|
|
240
|
-
* awaits.
|
|
143
|
+
* Open the inbound run, install it as the active run for the whole `next`
|
|
144
|
+
* async scope, and close it. The real ALS scopes the run to this branch, so a
|
|
145
|
+
* handler running concurrently with the workflow body never leaks its run into
|
|
146
|
+
* the body's context.
|
|
241
147
|
*/
|
|
242
|
-
async runInbound(name, runType, parent, inputs, next,
|
|
148
|
+
async runInbound(name, runType, parent, inputs, next, generateNewUuid4) {
|
|
243
149
|
if (!this.config.addTemporalRuns) {
|
|
244
150
|
// Propagation only: install the reconstructed parent as the active run so
|
|
245
151
|
// user `traceable` runs nest under it; never emit a Temporal-operation run.
|
|
@@ -248,7 +154,7 @@ class LangSmithWorkflowInbound {
|
|
|
248
154
|
// `createChild` branch (deterministic id) rather than the no-parent branch
|
|
249
155
|
// that mints a uuid via `crypto`, which the isolate lacks.
|
|
250
156
|
const ambient = asReplaySafeParent(parent, generateNewUuid4) ?? placeholderRoot(generateNewUuid4);
|
|
251
|
-
return
|
|
157
|
+
return sharedStore.run(ambient, next);
|
|
252
158
|
}
|
|
253
159
|
const run = buildReplaySafeRunTree(this.config, {
|
|
254
160
|
name,
|
|
@@ -271,14 +177,12 @@ class LangSmithWorkflowInbound {
|
|
|
271
177
|
throw err;
|
|
272
178
|
}
|
|
273
179
|
};
|
|
274
|
-
return
|
|
180
|
+
return sharedStore.run(run, body);
|
|
275
181
|
}
|
|
276
182
|
}
|
|
277
183
|
class LangSmithWorkflowOutbound {
|
|
278
|
-
ctx;
|
|
279
184
|
config;
|
|
280
|
-
constructor(
|
|
281
|
-
this.ctx = ctx;
|
|
185
|
+
constructor(config) {
|
|
282
186
|
this.config = config;
|
|
283
187
|
}
|
|
284
188
|
async scheduleActivity(input, next) {
|
|
@@ -293,7 +197,7 @@ class LangSmithWorkflowOutbound {
|
|
|
293
197
|
continueAsNew(input, next) {
|
|
294
198
|
// Don't propagate a placeholder root: it is never emitted, so the successor's
|
|
295
199
|
// runs would dangle under a nonexistent parent. Let it install its own.
|
|
296
|
-
const ambient =
|
|
200
|
+
const ambient = sharedStore.getStore();
|
|
297
201
|
const context = ambient instanceof run_tree_1._RootReplaySafeRunTreeFactory ? undefined : (0, run_tree_1.runHeaders)(ambient);
|
|
298
202
|
const headers = (0, propagation_1.withContextHeader)(input.headers, context);
|
|
299
203
|
return next({ ...input, headers });
|
|
@@ -306,7 +210,7 @@ class LangSmithWorkflowOutbound {
|
|
|
306
210
|
return this.parentMarker(name, input, (headers) => next({ ...input, headers }));
|
|
307
211
|
}
|
|
308
212
|
async startNexusOperation(input, next) {
|
|
309
|
-
const ambient =
|
|
213
|
+
const ambient = sharedStore.getStore();
|
|
310
214
|
if (this.config.addTemporalRuns && ambient instanceof run_tree_1.ReplaySafeRunTree) {
|
|
311
215
|
await emitMarker(ambient, (0, run_tree_1.startNexusOperationRunName)(input.service, input.operation), {});
|
|
312
216
|
}
|
|
@@ -316,7 +220,7 @@ class LangSmithWorkflowOutbound {
|
|
|
316
220
|
}
|
|
317
221
|
/** Sibling-marker operations: marker is a peer of the remote run; propagate ambient. */
|
|
318
222
|
async peerMarker(name, input, next) {
|
|
319
|
-
const ambient =
|
|
223
|
+
const ambient = sharedStore.getStore();
|
|
320
224
|
if (this.config.addTemporalRuns && ambient instanceof run_tree_1.ReplaySafeRunTree) {
|
|
321
225
|
await emitMarker(ambient, name, { args: input.args ?? [] });
|
|
322
226
|
}
|
|
@@ -325,7 +229,7 @@ class LangSmithWorkflowOutbound {
|
|
|
325
229
|
}
|
|
326
230
|
/** Parent-marker operations: remote handler nests under the marker; propagate marker. */
|
|
327
231
|
async parentMarker(name, input, next) {
|
|
328
|
-
const ambient =
|
|
232
|
+
const ambient = sharedStore.getStore();
|
|
329
233
|
let propagate = ambient;
|
|
330
234
|
if (this.config.addTemporalRuns && ambient instanceof run_tree_1.ReplaySafeRunTree) {
|
|
331
235
|
propagate = await emitMarker(ambient, name, { args: input.args ?? [] });
|
|
@@ -343,8 +247,8 @@ class LangSmithWorkflowOutbound {
|
|
|
343
247
|
function interceptors() {
|
|
344
248
|
const config = readConfig();
|
|
345
249
|
return {
|
|
346
|
-
inbound: [new LangSmithWorkflowInbound(
|
|
347
|
-
outbound: [new LangSmithWorkflowOutbound(
|
|
250
|
+
inbound: [new LangSmithWorkflowInbound(config)],
|
|
251
|
+
outbound: [new LangSmithWorkflowOutbound(config)],
|
|
348
252
|
};
|
|
349
253
|
}
|
|
350
254
|
//# sourceMappingURL=workflow-interceptors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-interceptors.js","sourceRoot":"","sources":["../src/workflow-interceptors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAigBH,oCAMC;AApgBD,8DAAoF;AASpF,mDAY8B;AAC9B,+CAOuB;AACvB,yCAmBoB;AAqBpB,SAAS,UAAU;IACjB,IAAI,CAAC;QACH,IAAI,OAAO,6BAA6B,KAAK,QAAQ,EAAE,CAAC;YAC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AI,EAAE,EAAE,CAAC,CAAC;QAC1E,CAAC;QACD,MAAM,OAAO,GAAG,IAAA,+BAAiB,EAAC,KAAK,CAAC,OAAO,EAAE,IAAA,qBAAU,EAAC,SAAS,CAAC,CAAC,CAAC;QACxE,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;CACF;AAED;;;;;GAKG;AACH,SAAgB,YAAY;IAC1B,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,OAAO;QACL,OAAO,EAAE,CAAC,IAAI,wBAAwB,CAAC,MAAM,CAAC,CAAC;QAC/C,QAAQ,EAAE,CAAC,IAAI,yBAAyB,CAAC,MAAM,CAAC,CAAC;KAClD,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporalio/langsmith",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.1",
|
|
4
4
|
"description": "Temporal LangSmith observability integration package",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"author": "Temporal Technologies Inc. <sdk@temporal.io>",
|
|
45
45
|
"license": "MIT",
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@temporalio/client": "1.
|
|
48
|
-
"@temporalio/
|
|
49
|
-
"@temporalio/
|
|
50
|
-
"@temporalio/
|
|
51
|
-
"@temporalio/
|
|
52
|
-
"@temporalio/
|
|
47
|
+
"@temporalio/client": "1.21.1",
|
|
48
|
+
"@temporalio/worker": "1.21.1",
|
|
49
|
+
"@temporalio/plugin": "1.21.1",
|
|
50
|
+
"@temporalio/common": "1.21.1",
|
|
51
|
+
"@temporalio/activity": "1.21.1",
|
|
52
|
+
"@temporalio/workflow": "1.21.1"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"langsmith": "^0.7.9"
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"ava": "^5.3.1",
|
|
59
59
|
"langsmith": "^0.7.9",
|
|
60
60
|
"nexus-rpc": "^0.0.2",
|
|
61
|
-
"@temporalio/testing": "1.
|
|
61
|
+
"@temporalio/testing": "1.21.1"
|
|
62
62
|
},
|
|
63
63
|
"engines": {
|
|
64
64
|
"node": ">= 20.0.0"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundle-time stand-in for `node:async_hooks` inside the workflow isolate, where
|
|
3
|
+
* that builtin is unavailable. The plugin's bundler aliases `node:async_hooks`
|
|
4
|
+
* to this module (see {@link bundleRewritesPlugin} in `plugin.ts`) so LangSmith's
|
|
5
|
+
* `import { AsyncLocalStorage } from "node:async_hooks"` — including its
|
|
6
|
+
* `new AsyncLocalStorage()` and static `AsyncLocalStorage.snapshot()` — resolves
|
|
7
|
+
* to the real, async-context-tracking `AsyncLocalStorage` the SDK worker injects
|
|
8
|
+
* onto the workflow-sandbox global.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
declare const globalThis: { AsyncLocalStorage: typeof import('node:async_hooks').AsyncLocalStorage };
|
|
15
|
+
|
|
16
|
+
export const AsyncLocalStorage = globalThis.AsyncLocalStorage;
|
package/src/plugin.ts
CHANGED
|
@@ -91,8 +91,10 @@ export class LangSmithPlugin extends SimplePlugin {
|
|
|
91
91
|
private readonly client: Client;
|
|
92
92
|
private readonly emitter: EmitterConfig;
|
|
93
93
|
private readonly workflowConfig: WorkflowLangSmithConfig;
|
|
94
|
-
// Absolute
|
|
94
|
+
// Absolute paths so the workflow bundler resolves them under strict pnpm.
|
|
95
95
|
private readonly workflowInterceptorModule = require.resolve('./workflow-interceptors');
|
|
96
|
+
// Target of the `node:async_hooks` rewrite; re-exports the runtime-injected ALS.
|
|
97
|
+
private readonly asyncHooksShimModule = require.resolve('./async-hooks-shim');
|
|
96
98
|
|
|
97
99
|
constructor(options: LangSmithPluginOptions = {}) {
|
|
98
100
|
// super() reads options.name immediately
|
|
@@ -172,7 +174,7 @@ export class LangSmithPlugin extends SimplePlugin {
|
|
|
172
174
|
// Double-encode so the injected token is a string literal in the bundle.
|
|
173
175
|
const definitions = { [CONFIG_GLOBAL]: JSON.stringify(JSON.stringify(this.workflowConfig)) };
|
|
174
176
|
const plugins = [...(merged.plugins ?? [])];
|
|
175
|
-
plugins.push(bundleRewritesPlugin(this.
|
|
177
|
+
plugins.push(bundleRewritesPlugin(this.asyncHooksShimModule, definitions) as (typeof plugins)[number]);
|
|
176
178
|
return { ...merged, plugins };
|
|
177
179
|
};
|
|
178
180
|
return { ...base, workflowInterceptorModules, ignoreModules, webpackConfigHook };
|
|
@@ -228,13 +230,15 @@ interface WebpackCompiler {
|
|
|
228
230
|
/**
|
|
229
231
|
* A webpack plugin that installs the three Workflow-bundle rewrites LangSmith needs:
|
|
230
232
|
*
|
|
231
|
-
* - redirect `node:async_hooks` to the
|
|
233
|
+
* - redirect `node:async_hooks` to the shim module that re-exports the
|
|
234
|
+
* runtime-injected `AsyncLocalStorage`, so LangSmith's `new AsyncLocalStorage()`
|
|
235
|
+
* and `AsyncLocalStorage.snapshot()` resolve to the real SDK-provided ALS.
|
|
232
236
|
* webpack routes `node:` requests through a scheme handler before alias
|
|
233
237
|
* resolution, so `resolve.alias` can't do this; `NormalModuleReplacementPlugin`
|
|
234
238
|
* rewrites the request in `beforeResolve`. Paired with the `ignoreModules`
|
|
235
239
|
* whitelist (see {@link LangSmithPlugin.configureBundler}). The rewrite target
|
|
236
|
-
* is the resolved absolute module path so webpack dedupes to one
|
|
237
|
-
*
|
|
240
|
+
* is the resolved absolute module path so webpack dedupes to one instance
|
|
241
|
+
* regardless of issuer.
|
|
238
242
|
* - redirect langsmith's node-only `utils/{fs,worker_threads}.cjs` to their
|
|
239
243
|
* `.browser.cjs` siblings so node builtins stay out of the isolate. Scoped to
|
|
240
244
|
* langsmith so a user's own `fs.cjs` is never rewritten.
|
|
@@ -246,14 +250,14 @@ interface WebpackCompiler {
|
|
|
246
250
|
* installers (e.g. pnpm with `hoist=false`). Using the compiler's own webpack
|
|
247
251
|
* also guarantees the exact instance running the bundle — never a second copy.
|
|
248
252
|
*/
|
|
249
|
-
function bundleRewritesPlugin(
|
|
253
|
+
function bundleRewritesPlugin(asyncHooksShimModule: string, definitions: Record<string, string>): WebpackPlugin {
|
|
250
254
|
const swap = (s: string): string => s.replace(/\.cjs$/, '.browser.cjs');
|
|
251
255
|
return {
|
|
252
256
|
apply(compiler) {
|
|
253
257
|
const { NormalModuleReplacementPlugin, DefinePlugin } = compiler.webpack;
|
|
254
258
|
|
|
255
259
|
new NormalModuleReplacementPlugin(/^node:async_hooks$/, (resource) => {
|
|
256
|
-
resource.request =
|
|
260
|
+
resource.request = asyncHooksShimModule;
|
|
257
261
|
}).apply(compiler);
|
|
258
262
|
|
|
259
263
|
new NormalModuleReplacementPlugin(/[/\\]utils[/\\](?:fs|worker_threads)\.cjs$/, (resource) => {
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Workflow-isolate interceptors and the
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* LangSmith's
|
|
7
|
-
*
|
|
8
|
-
* Internal: the worker loads this module by specifier and the bundler aliases
|
|
9
|
-
* `node:async_hooks` to it — it is not a hand-import API.
|
|
2
|
+
* Workflow-isolate interceptors and the LangSmith context provider. Loaded into
|
|
3
|
+
* the workflow bundle (via the plugin's `workflowModules`) and runs entirely
|
|
4
|
+
* inside the V8 isolate. Trace context propagates through the real,
|
|
5
|
+
* async-context-tracking `AsyncLocalStorage` the SDK worker injects onto the
|
|
6
|
+
* workflow-sandbox global; the plugin and LangSmith's own load-time init
|
|
7
|
+
* converge on one shared store (see {@link sharedStore}).
|
|
10
8
|
*
|
|
11
9
|
* @module
|
|
12
10
|
* @internal
|
|
@@ -94,101 +92,26 @@ function readConfig(): WorkflowLangSmithConfig {
|
|
|
94
92
|
return { addTemporalRuns: false };
|
|
95
93
|
}
|
|
96
94
|
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
* persists across `await` boundaries; `stack` tracks synchronous `traceable`
|
|
102
|
-
* nesting. Under `Promise.all` fan-out parenting falls back to the ambient —
|
|
103
|
-
* trace-shape-only non-determinism, never workflow history.
|
|
104
|
-
*/
|
|
105
|
-
class WorkflowContextManager {
|
|
106
|
-
private workflowAmbient: RunTree | undefined;
|
|
107
|
-
private readonly stack: (RunTree | undefined)[] = [];
|
|
108
|
-
|
|
109
|
-
getStore(): RunTree | undefined {
|
|
110
|
-
return this.stack.length > 0 ? this.stack[this.stack.length - 1] : this.workflowAmbient;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Push `context`, run `fn`, pop in `finally`, and return `fn`'s result — the
|
|
115
|
-
* `AsyncLocalStorage.run` contract langsmith relies on.
|
|
116
|
-
*/
|
|
117
|
-
run<T>(context: RunTree | undefined, fn: () => T): T {
|
|
118
|
-
this.stack.push(context);
|
|
119
|
-
try {
|
|
120
|
-
return fn();
|
|
121
|
-
} finally {
|
|
122
|
-
this.stack.pop();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/** The ambient run an outbound interceptor should propagate / parent under. */
|
|
127
|
-
ambient(): RunTree | undefined {
|
|
128
|
-
return this.getStore();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** Run an async scope with a dedicated ambient (workflow execute / handler). */
|
|
132
|
-
async withAmbient<T>(run: RunTree | undefined, fn: () => Promise<T>): Promise<T> {
|
|
133
|
-
const prev = this.workflowAmbient;
|
|
134
|
-
this.workflowAmbient = run;
|
|
135
|
-
try {
|
|
136
|
-
return await fn();
|
|
137
|
-
} finally {
|
|
138
|
-
this.workflowAmbient = prev;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
let providerInstalled = false;
|
|
144
|
-
function ensureProviderInstalled(manager: WorkflowContextManager): void {
|
|
145
|
-
if (providerInstalled) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
providerInstalled = true;
|
|
149
|
-
// LangSmith's `AsyncLocalStorageInterface` requires exactly two members,
|
|
150
|
-
// `getStore` and `run` (it never calls `enterWith`), so we provide only those.
|
|
151
|
-
// The cast bridges the generic `run<T>` signature to the interface's
|
|
152
|
-
// `run: (ctx, () => void) => void`.
|
|
153
|
-
AsyncLocalStorageProviderSingleton.initializeGlobalInstance({
|
|
154
|
-
getStore: () => manager.getStore(),
|
|
155
|
-
run: <T>(context: RunTree | undefined, fn: () => T): T => manager.run(context as RunTree | undefined, fn),
|
|
156
|
-
} as Parameters<typeof AsyncLocalStorageProviderSingleton.initializeGlobalInstance>[0]);
|
|
95
|
+
/** The `getStore`/`run` slice of `AsyncLocalStorage` the interceptors and LangSmith share. */
|
|
96
|
+
interface RunTreeStore {
|
|
97
|
+
getStore(): RunTree | undefined;
|
|
98
|
+
run<T>(store: RunTree | undefined, fn: () => T): T;
|
|
157
99
|
}
|
|
158
100
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
run<R>(store: T, fn: (...args: never[]) => R): R {
|
|
176
|
-
return sharedManager.run(store as unknown as RunTree | undefined, fn as () => R);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
enterWith(_store: T): void {
|
|
180
|
-
/* no-op: parenting inside the isolate is stack-scoped via run() */
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Best-effort equivalent of `AsyncLocalStorage.snapshot()` (used only by
|
|
185
|
-
* LangSmith's async-generator streaming paths). Runs the callback in the
|
|
186
|
-
* current synchronous scope; the isolate has no async context to capture.
|
|
187
|
-
*/
|
|
188
|
-
static snapshot(): (fn: (...args: unknown[]) => unknown, ...args: unknown[]) => unknown {
|
|
189
|
-
return (fn, ...args) => fn(...args);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
101
|
+
// The SDK worker injects a real, async-context-tracking `AsyncLocalStorage` onto
|
|
102
|
+
// the workflow-sandbox global before the bundle evaluates. Bundler aliases (see
|
|
103
|
+
// plugin.ts) also route LangSmith's `new AsyncLocalStorage()` there, so both the
|
|
104
|
+
// plugin and LangSmith's load-time `initializeGlobalInstance` compete for one
|
|
105
|
+
// global slot (first writer wins). Install our instance, then read back whichever
|
|
106
|
+
// won so interceptors and `traceable` read/write the same store regardless of
|
|
107
|
+
// load order.
|
|
108
|
+
declare const globalThis: { AsyncLocalStorage: new () => RunTreeStore };
|
|
109
|
+
AsyncLocalStorageProviderSingleton.initializeGlobalInstance(
|
|
110
|
+
new globalThis.AsyncLocalStorage() as Parameters<
|
|
111
|
+
typeof AsyncLocalStorageProviderSingleton.initializeGlobalInstance
|
|
112
|
+
>[0]
|
|
113
|
+
);
|
|
114
|
+
const sharedStore = AsyncLocalStorageProviderSingleton.getInstance() as RunTreeStore;
|
|
192
115
|
|
|
193
116
|
/** Reconstruct the propagated parent run from a Payload-keyed header map. */
|
|
194
117
|
function reconstructParent(headers: Record<string, unknown> | undefined): RunTree | undefined {
|
|
@@ -269,10 +192,7 @@ function buildReplaySafeRunTree(
|
|
|
269
192
|
}
|
|
270
193
|
|
|
271
194
|
class LangSmithWorkflowInbound implements WorkflowInboundCallsInterceptor {
|
|
272
|
-
constructor(
|
|
273
|
-
private readonly ctx: WorkflowContextManager,
|
|
274
|
-
private readonly config: WorkflowLangSmithConfig
|
|
275
|
-
) {}
|
|
195
|
+
constructor(private readonly config: WorkflowLangSmithConfig) {}
|
|
276
196
|
|
|
277
197
|
async execute(input: WorkflowExecuteInput, next: Next<WorkflowInboundCallsInterceptor, 'execute'>): Promise<unknown> {
|
|
278
198
|
const parent = reconstructParent(input.headers);
|
|
@@ -287,13 +207,8 @@ class LangSmithWorkflowInbound implements WorkflowInboundCallsInterceptor {
|
|
|
287
207
|
|
|
288
208
|
async handleSignal(input: SignalInput, next: Next<WorkflowInboundCallsInterceptor, 'handleSignal'>): Promise<void> {
|
|
289
209
|
const parent = reconstructParent(input.headers);
|
|
290
|
-
await this.runInbound(
|
|
291
|
-
|
|
292
|
-
RUN_TYPE.CHAIN,
|
|
293
|
-
parent,
|
|
294
|
-
{ args: input.args },
|
|
295
|
-
() => next(input),
|
|
296
|
-
true
|
|
210
|
+
await this.runInbound(handleSignalRunName(input.signalName), RUN_TYPE.CHAIN, parent, { args: input.args }, () =>
|
|
211
|
+
next(input)
|
|
297
212
|
);
|
|
298
213
|
}
|
|
299
214
|
|
|
@@ -308,7 +223,6 @@ class LangSmithWorkflowInbound implements WorkflowInboundCallsInterceptor {
|
|
|
308
223
|
parent,
|
|
309
224
|
{ args: input.args },
|
|
310
225
|
() => next(input),
|
|
311
|
-
true,
|
|
312
226
|
// Read-only: mint run ids from the nondeterministic unsafe random source so the
|
|
313
227
|
// handler never draws from the Workflow main PRNG (which a clean replay would not advance).
|
|
314
228
|
workflowInfo().unsafe.random.uuid4
|
|
@@ -320,13 +234,8 @@ class LangSmithWorkflowInbound implements WorkflowInboundCallsInterceptor {
|
|
|
320
234
|
next: Next<WorkflowInboundCallsInterceptor, 'handleUpdate'>
|
|
321
235
|
): Promise<unknown> {
|
|
322
236
|
const parent = reconstructParent(input.headers);
|
|
323
|
-
return this.runInbound(
|
|
324
|
-
|
|
325
|
-
RUN_TYPE.CHAIN,
|
|
326
|
-
parent,
|
|
327
|
-
{ args: input.args },
|
|
328
|
-
() => next(input),
|
|
329
|
-
true
|
|
237
|
+
return this.runInbound(handleUpdateRunName(input.name), RUN_TYPE.CHAIN, parent, { args: input.args }, () =>
|
|
238
|
+
next(input)
|
|
330
239
|
);
|
|
331
240
|
}
|
|
332
241
|
|
|
@@ -338,11 +247,10 @@ class LangSmithWorkflowInbound implements WorkflowInboundCallsInterceptor {
|
|
|
338
247
|
// Propagation only: install the reconstructed parent (or a placeholder parent
|
|
339
248
|
// when none was propagated, to keep a validator-body `traceable` off the
|
|
340
249
|
// no-parent `crypto` path) so the validator body nests under the update's
|
|
341
|
-
// trace.
|
|
342
|
-
// not the async `withAmbient`.
|
|
250
|
+
// trace.
|
|
343
251
|
const ambient =
|
|
344
252
|
asReplaySafeParent(reconstructParent(input.headers), generateNewUuid4) ?? placeholderRoot(generateNewUuid4);
|
|
345
|
-
|
|
253
|
+
sharedStore.run(ambient, () => next(input));
|
|
346
254
|
return;
|
|
347
255
|
}
|
|
348
256
|
const run = buildReplaySafeRunTree(this.config, {
|
|
@@ -353,11 +261,11 @@ class LangSmithWorkflowInbound implements WorkflowInboundCallsInterceptor {
|
|
|
353
261
|
generateNewUuid4,
|
|
354
262
|
});
|
|
355
263
|
// Validators are synchronous and must not be made async; emit start/end
|
|
356
|
-
// around the synchronous call, with the run installed
|
|
357
|
-
// `traceable` in the validator body nests under it.
|
|
264
|
+
// around the synchronous call, with the run installed as the active store so
|
|
265
|
+
// a `traceable` in the validator body nests under it.
|
|
358
266
|
void run.postRun();
|
|
359
267
|
try {
|
|
360
|
-
|
|
268
|
+
sharedStore.run(run, () => next(input));
|
|
361
269
|
void run.end({});
|
|
362
270
|
} catch (err) {
|
|
363
271
|
void run.end(undefined, describeError(err));
|
|
@@ -368,12 +276,10 @@ class LangSmithWorkflowInbound implements WorkflowInboundCallsInterceptor {
|
|
|
368
276
|
}
|
|
369
277
|
|
|
370
278
|
/**
|
|
371
|
-
* Open the inbound run, install it as the active run for `next
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
* `execute` (scoped: false) installs a persistent ambient that survives the body's
|
|
376
|
-
* awaits.
|
|
279
|
+
* Open the inbound run, install it as the active run for the whole `next`
|
|
280
|
+
* async scope, and close it. The real ALS scopes the run to this branch, so a
|
|
281
|
+
* handler running concurrently with the workflow body never leaks its run into
|
|
282
|
+
* the body's context.
|
|
377
283
|
*/
|
|
378
284
|
private async runInbound(
|
|
379
285
|
name: string,
|
|
@@ -381,7 +287,6 @@ class LangSmithWorkflowInbound implements WorkflowInboundCallsInterceptor {
|
|
|
381
287
|
parent: RunTree | undefined,
|
|
382
288
|
inputs: Record<string, unknown>,
|
|
383
289
|
next: () => Promise<unknown>,
|
|
384
|
-
scoped = false,
|
|
385
290
|
generateNewUuid4?: () => string
|
|
386
291
|
): Promise<unknown> {
|
|
387
292
|
if (!this.config.addTemporalRuns) {
|
|
@@ -392,7 +297,7 @@ class LangSmithWorkflowInbound implements WorkflowInboundCallsInterceptor {
|
|
|
392
297
|
// `createChild` branch (deterministic id) rather than the no-parent branch
|
|
393
298
|
// that mints a uuid via `crypto`, which the isolate lacks.
|
|
394
299
|
const ambient = asReplaySafeParent(parent, generateNewUuid4) ?? placeholderRoot(generateNewUuid4);
|
|
395
|
-
return
|
|
300
|
+
return sharedStore.run(ambient, next);
|
|
396
301
|
}
|
|
397
302
|
const run = buildReplaySafeRunTree(this.config, {
|
|
398
303
|
name,
|
|
@@ -414,15 +319,12 @@ class LangSmithWorkflowInbound implements WorkflowInboundCallsInterceptor {
|
|
|
414
319
|
throw err;
|
|
415
320
|
}
|
|
416
321
|
};
|
|
417
|
-
return
|
|
322
|
+
return sharedStore.run(run, body);
|
|
418
323
|
}
|
|
419
324
|
}
|
|
420
325
|
|
|
421
326
|
class LangSmithWorkflowOutbound implements WorkflowOutboundCallsInterceptor {
|
|
422
|
-
constructor(
|
|
423
|
-
private readonly ctx: WorkflowContextManager,
|
|
424
|
-
private readonly config: WorkflowLangSmithConfig
|
|
425
|
-
) {}
|
|
327
|
+
constructor(private readonly config: WorkflowLangSmithConfig) {}
|
|
426
328
|
|
|
427
329
|
async scheduleActivity(
|
|
428
330
|
input: ActivityInput,
|
|
@@ -457,7 +359,7 @@ class LangSmithWorkflowOutbound implements WorkflowOutboundCallsInterceptor {
|
|
|
457
359
|
): Promise<never> {
|
|
458
360
|
// Don't propagate a placeholder root: it is never emitted, so the successor's
|
|
459
361
|
// runs would dangle under a nonexistent parent. Let it install its own.
|
|
460
|
-
const ambient =
|
|
362
|
+
const ambient = sharedStore.getStore();
|
|
461
363
|
const context = ambient instanceof _RootReplaySafeRunTreeFactory ? undefined : runHeaders(ambient);
|
|
462
364
|
const headers = withContextHeader(input.headers, context);
|
|
463
365
|
return next({ ...input, headers });
|
|
@@ -478,7 +380,7 @@ class LangSmithWorkflowOutbound implements WorkflowOutboundCallsInterceptor {
|
|
|
478
380
|
input: StartNexusOperationInput,
|
|
479
381
|
next: Next<WorkflowOutboundCallsInterceptor, 'startNexusOperation'>
|
|
480
382
|
): Promise<StartNexusOperationOutput> {
|
|
481
|
-
const ambient =
|
|
383
|
+
const ambient = sharedStore.getStore();
|
|
482
384
|
if (this.config.addTemporalRuns && ambient instanceof ReplaySafeRunTree) {
|
|
483
385
|
await emitMarker(ambient, startNexusOperationRunName(input.service, input.operation), {});
|
|
484
386
|
}
|
|
@@ -493,7 +395,7 @@ class LangSmithWorkflowOutbound implements WorkflowOutboundCallsInterceptor {
|
|
|
493
395
|
input: { headers: Headers; args?: unknown[] },
|
|
494
396
|
next: (headers: Headers) => Promise<R>
|
|
495
397
|
): Promise<R> {
|
|
496
|
-
const ambient =
|
|
398
|
+
const ambient = sharedStore.getStore();
|
|
497
399
|
if (this.config.addTemporalRuns && ambient instanceof ReplaySafeRunTree) {
|
|
498
400
|
await emitMarker(ambient, name, { args: input.args ?? [] });
|
|
499
401
|
}
|
|
@@ -507,7 +409,7 @@ class LangSmithWorkflowOutbound implements WorkflowOutboundCallsInterceptor {
|
|
|
507
409
|
input: { headers: Headers; args?: unknown[] },
|
|
508
410
|
next: (headers: Headers) => Promise<R>
|
|
509
411
|
): Promise<R> {
|
|
510
|
-
const ambient =
|
|
412
|
+
const ambient = sharedStore.getStore();
|
|
511
413
|
let propagate: RunTree | undefined = ambient;
|
|
512
414
|
if (this.config.addTemporalRuns && ambient instanceof ReplaySafeRunTree) {
|
|
513
415
|
propagate = await emitMarker(ambient, name, { args: input.args ?? [] });
|
|
@@ -526,7 +428,7 @@ class LangSmithWorkflowOutbound implements WorkflowOutboundCallsInterceptor {
|
|
|
526
428
|
export function interceptors(): WorkflowInterceptors {
|
|
527
429
|
const config = readConfig();
|
|
528
430
|
return {
|
|
529
|
-
inbound: [new LangSmithWorkflowInbound(
|
|
530
|
-
outbound: [new LangSmithWorkflowOutbound(
|
|
431
|
+
inbound: [new LangSmithWorkflowInbound(config)],
|
|
432
|
+
outbound: [new LangSmithWorkflowOutbound(config)],
|
|
531
433
|
};
|
|
532
434
|
}
|