@temporalio/langsmith 1.23.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.
- package/LICENSE +6 -6
- package/README.md +79 -6
- package/lib/activity-interceptor.js +38 -47
- package/lib/activity-interceptor.js.map +1 -1
- package/lib/client-interceptor.d.ts +4 -4
- package/lib/client-interceptor.js +28 -47
- package/lib/client-interceptor.js.map +1 -1
- package/lib/plugin.d.ts +7 -6
- package/lib/plugin.js +85 -9
- package/lib/plugin.js.map +1 -1
- package/lib/propagation.js +1 -1
- package/lib/routing.d.ts +14 -0
- package/lib/routing.js +101 -0
- package/lib/routing.js.map +1 -0
- package/lib/run-tree.d.ts +48 -13
- package/lib/run-tree.js +106 -166
- package/lib/run-tree.js.map +1 -1
- package/lib/sinks.d.ts +19 -4
- package/lib/sinks.js +33 -50
- package/lib/sinks.js.map +1 -1
- package/lib/worker-run-tree.d.ts +6 -0
- package/lib/worker-run-tree.js +43 -0
- package/lib/worker-run-tree.js.map +1 -0
- package/lib/workflow-interceptors.js +104 -151
- package/lib/workflow-interceptors.js.map +1 -1
- package/lib/workflow-run-tree.d.ts +7 -0
- package/lib/workflow-run-tree.js +112 -0
- package/lib/workflow-run-tree.js.map +1 -0
- package/package.json +36 -17
- package/src/activity-interceptor.ts +47 -51
- package/src/client-interceptor.ts +37 -59
- package/src/plugin.ts +99 -14
- package/src/propagation.ts +1 -1
- package/src/routing.ts +110 -0
- package/src/run-tree.ts +139 -185
- package/src/sinks.ts +46 -52
- package/src/worker-run-tree.ts +47 -0
- package/src/workflow-interceptors.ts +131 -217
- package/src/workflow-run-tree.ts +127 -0
package/lib/run-tree.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* run-name builders shared by every interceptor.
|
|
5
5
|
*
|
|
6
6
|
* Inside the workflow isolate LangSmith's default `RunTree` is unsafe on two
|
|
7
|
-
* counts that
|
|
7
|
+
* counts that the workflow lifecycle overrides fix:
|
|
8
8
|
*
|
|
9
9
|
* 1. **Non-deterministic ids.** Its default random-tailed uuid7 would mint a
|
|
10
10
|
* fresh id on every replay, flooding the backend with duplicates.
|
|
@@ -18,20 +18,23 @@
|
|
|
18
18
|
* @internal
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.
|
|
21
|
+
exports.startUpdateWithStartRunName = exports.startWorkflowUpdateRunName = exports.queryWorkflowRunName = exports.signalWithStartRunName = exports.signalExternalWorkflowRunName = exports.signalChildWorkflowRunName = exports.signalWorkflowRunName = exports.validateUpdateRunName = exports.handleUpdateRunName = exports.handleQueryRunName = exports.handleSignalRunName = exports.runCancelNexusHandlerRunName = exports.runStartNexusHandlerRunName = exports.startNexusOperationRunName = exports.startChildWorkflowRunName = exports.runActivityRunName = exports.startActivityRunName = exports.runWorkflowRunName = exports.startWorkflowRunName = exports.RUN_TYPE = void 0;
|
|
22
|
+
exports.requireRunTreeMembers = requireRunTreeMembers;
|
|
23
|
+
exports.patchRunTree = patchRunTree;
|
|
24
|
+
exports.serializeRun = serializeRun;
|
|
22
25
|
exports.describeError = describeError;
|
|
23
|
-
exports.
|
|
26
|
+
exports.statusOutputs = statusOutputs;
|
|
27
|
+
exports.thrownEnd = thrownEnd;
|
|
28
|
+
exports.wrapWithRun = wrapWithRun;
|
|
29
|
+
exports.isUntraced = isUntraced;
|
|
30
|
+
exports.suppressRun = suppressRun;
|
|
24
31
|
exports.runHeaders = runHeaders;
|
|
25
|
-
exports.emitMarkerRun = emitMarkerRun;
|
|
26
32
|
exports.runTreeFromContext = runTreeFromContext;
|
|
27
33
|
exports.buildRunTree = buildRunTree;
|
|
34
|
+
const langsmith_1 = require("langsmith");
|
|
28
35
|
const run_trees_1 = require("langsmith/run_trees");
|
|
29
36
|
const common_1 = require("@temporalio/common");
|
|
30
|
-
const
|
|
31
|
-
const propagation_1 = require("./propagation");
|
|
32
|
-
const sinks_1 = require("./sinks");
|
|
33
|
-
/** Named random stream for recorded-path run ids; isolated from the workflow's main RNG. */
|
|
34
|
-
const LANGSMITH_RUN_TREE_STREAM = 'package-langsmith-tracing';
|
|
37
|
+
const routing_1 = require("./routing");
|
|
35
38
|
/** LangSmith run-type constants used for Temporal-operation runs. */
|
|
36
39
|
exports.RUN_TYPE = {
|
|
37
40
|
/** Workflow / child-workflow / scheduling / handler spans. */
|
|
@@ -93,48 +96,41 @@ exports.queryWorkflowRunName = queryWorkflowRunName;
|
|
|
93
96
|
/** `StartWorkflowUpdate:<name>` — client update-start marker. */
|
|
94
97
|
const startWorkflowUpdateRunName = (updateName) => `StartWorkflowUpdate:${updateName}`;
|
|
95
98
|
exports.startWorkflowUpdateRunName = startWorkflowUpdateRunName;
|
|
96
|
-
/** `StartUpdateWithStartWorkflow:<
|
|
97
|
-
const startUpdateWithStartRunName = (
|
|
99
|
+
/** `StartUpdateWithStartWorkflow:<type>` — client update-with-start marker. */
|
|
100
|
+
const startUpdateWithStartRunName = (workflowType) => `StartUpdateWithStartWorkflow:${workflowType}`;
|
|
98
101
|
exports.startUpdateWithStartRunName = startUpdateWithStartRunName;
|
|
102
|
+
const runTreeOwners = (overrides) => [
|
|
103
|
+
['RunTree.', run_trees_1.RunTree, overrides.statics],
|
|
104
|
+
['RunTree.prototype.', run_trees_1.RunTree.prototype, overrides.methods],
|
|
105
|
+
];
|
|
99
106
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* live read-only handlers (queries, update validators) `isReplaying` is `true`
|
|
103
|
-
* but `isReplayingHistoryEvents` is `false`, so their runs still emit. Matches
|
|
104
|
-
* how the SDK gates `callDuringReplay: false` sinks.
|
|
107
|
+
* Throw, naming each one, unless every member the overrides replace is a function. The Workflow bundle may carry a
|
|
108
|
+
* different LangSmith copy than the Worker, so both check.
|
|
105
109
|
*/
|
|
106
|
-
function
|
|
107
|
-
|
|
110
|
+
function requireRunTreeMembers(...overrides) {
|
|
111
|
+
const missing = new Set(overrides.flatMap((override) => runTreeOwners(override).flatMap(([label, owner, members]) => Object.keys(members)
|
|
112
|
+
.filter((name) => typeof owner[name] !== 'function')
|
|
113
|
+
.map((name) => `${label}${name}`))));
|
|
114
|
+
if (missing.size > 0) {
|
|
115
|
+
throw new Error(`@temporalio/langsmith does not support LangSmith ${langsmith_1.__version__}: missing ${[...missing].join(', ')}`);
|
|
116
|
+
}
|
|
108
117
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
118
|
+
/** Replace the overridden RunTree members, or none if any is missing. */
|
|
119
|
+
function patchRunTree(overrides) {
|
|
120
|
+
requireRunTreeMembers(overrides);
|
|
121
|
+
for (const [, owner, members] of runTreeOwners(overrides)) {
|
|
122
|
+
for (const [name, override] of Object.entries(members)) {
|
|
123
|
+
owner[name] = override(owner[name]);
|
|
124
|
+
}
|
|
114
125
|
}
|
|
115
|
-
return cachedSinks;
|
|
116
126
|
}
|
|
117
|
-
/**
|
|
118
|
-
* A no-op LangSmith client. {@link ReplaySafeRunTree} never lets the underlying
|
|
119
|
-
* `RunTree` perform network I/O — emission goes through the Sink — so the
|
|
120
|
-
* client it carries must do nothing and must never read env / open sockets
|
|
121
|
-
* inside the isolate.
|
|
122
|
-
*/
|
|
123
|
-
const NOOP_CLIENT = {
|
|
124
|
-
createRun: async () => { },
|
|
125
|
-
updateRun: async () => { },
|
|
126
|
-
};
|
|
127
127
|
/** Flatten a {@link RunTree} into the plain wire shape consumed by the Sink. */
|
|
128
128
|
function serializeRun(run) {
|
|
129
|
-
const extra = run.extra ? { ...run.extra } : undefined;
|
|
130
|
-
if (extra && extra.metadata && typeof extra.metadata === 'object') {
|
|
131
|
-
extra.metadata = (0, propagation_1.scrubSensitive)(extra.metadata);
|
|
132
|
-
}
|
|
133
129
|
return {
|
|
134
130
|
id: run.id,
|
|
135
131
|
trace_id: run.trace_id,
|
|
136
132
|
dotted_order: run.dotted_order,
|
|
137
|
-
parent_run_id: run.parent_run_id,
|
|
133
|
+
parent_run_id: run.parent_run?.id ?? run.parent_run_id,
|
|
138
134
|
name: run.name,
|
|
139
135
|
run_type: run.run_type,
|
|
140
136
|
start_time: run.start_time,
|
|
@@ -142,9 +138,12 @@ function serializeRun(run) {
|
|
|
142
138
|
inputs: run.inputs,
|
|
143
139
|
outputs: run.outputs,
|
|
144
140
|
error: run.error,
|
|
145
|
-
extra,
|
|
141
|
+
extra: run.extra ? { ...run.extra } : undefined,
|
|
146
142
|
tags: run.tags,
|
|
147
143
|
project_name: run.project_name,
|
|
144
|
+
address: run.address,
|
|
145
|
+
replicas: (0, routing_1.replicaRouting)(run.replicas),
|
|
146
|
+
distributedParentId: run.distributedParentId,
|
|
148
147
|
events: run.events,
|
|
149
148
|
};
|
|
150
149
|
}
|
|
@@ -157,41 +156,83 @@ function serializeRun(run) {
|
|
|
157
156
|
* failures produce `"<type>: <message>"`.
|
|
158
157
|
*/
|
|
159
158
|
function describeError(err) {
|
|
160
|
-
if (err instanceof common_1.ApplicationFailure) {
|
|
161
|
-
|
|
162
|
-
return undefined;
|
|
163
|
-
}
|
|
164
|
-
return `${err.type ?? 'ApplicationError'}: ${err.message}`;
|
|
159
|
+
if (err instanceof common_1.ApplicationFailure && err.category === common_1.ApplicationFailureCategory.BENIGN) {
|
|
160
|
+
return undefined;
|
|
165
161
|
}
|
|
166
162
|
if (err instanceof Error) {
|
|
167
163
|
return `${err.name}: ${err.message}`;
|
|
168
164
|
}
|
|
169
165
|
return String(err);
|
|
170
166
|
}
|
|
171
|
-
/**
|
|
172
|
-
function
|
|
173
|
-
|
|
174
|
-
|
|
167
|
+
/** Outputs of a plugin run that ends without an error. Plugin runs never record Temporal arguments or results. */
|
|
168
|
+
function statusOutputs(status) {
|
|
169
|
+
return { status };
|
|
170
|
+
}
|
|
171
|
+
/** The `RunTree.end` arguments for a plugin run whose operation threw `err`; cancellation isn't an error. */
|
|
172
|
+
function thrownEnd(err) {
|
|
173
|
+
if (err instanceof common_1.CancelledFailure) {
|
|
174
|
+
return [statusOutputs('cancelled'), undefined];
|
|
175
175
|
}
|
|
176
|
-
return
|
|
176
|
+
return [undefined, describeError(err)];
|
|
177
177
|
}
|
|
178
|
-
/**
|
|
179
|
-
function
|
|
180
|
-
|
|
178
|
+
/** Run `fn`, then end and patch the already-posted `run` with an ok status, or with `endThrown` of what `fn` threw. */
|
|
179
|
+
async function wrapWithRun(run, fn, endThrown = thrownEnd) {
|
|
180
|
+
let end = [statusOutputs('ok'), undefined];
|
|
181
|
+
try {
|
|
182
|
+
return await fn();
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
end = endThrown(err);
|
|
186
|
+
throw err;
|
|
187
|
+
}
|
|
188
|
+
finally {
|
|
189
|
+
await run.end(...end);
|
|
190
|
+
await run.patchRun();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/** Runs suppressed because the worker has no usable destination, or its env turns off a trace starting here. */
|
|
194
|
+
const untracedRuns = new WeakSet();
|
|
195
|
+
function isUntraced(run) {
|
|
196
|
+
return untracedRuns.has(run);
|
|
181
197
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
198
|
+
function suppressRun(run) {
|
|
199
|
+
untracedRuns.add(run);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* The trace context to propagate for `run`, or `undefined` when no LangSmith run exists to parent under: no run, a
|
|
203
|
+
* run with no destination, or a run LangSmith won't trace (`tracingEnabled: false`). LangSmith turns tracing off for
|
|
204
|
+
* a run built in an env it can't use, such as a client marker.
|
|
205
|
+
*/
|
|
206
|
+
function runHeaders(run) {
|
|
207
|
+
if (!run || run.tracingEnabled === false || isUntraced(run)) {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
const headers = run.toHeaders();
|
|
211
|
+
const baggage = headers.baggage.split(',').filter((item) => !item.startsWith('langsmith-replicas=') && !item.startsWith('langsmith-metadata='));
|
|
212
|
+
const metadata = run.extra?.metadata;
|
|
213
|
+
if (metadata && Object.keys(metadata).length > 0) {
|
|
214
|
+
baggage.push(`langsmith-metadata=${encodeURIComponent(JSON.stringify(metadata))}`);
|
|
215
|
+
}
|
|
216
|
+
const replicas = (0, routing_1.replicaRouting)(run.replicas);
|
|
217
|
+
if (replicas !== undefined)
|
|
218
|
+
baggage.push(`langsmith-replicas=${encodeURIComponent(JSON.stringify((0, routing_1.replicaHeaders)(replicas)))}`);
|
|
219
|
+
headers.baggage = baggage.filter(Boolean).join(',');
|
|
220
|
+
return headers;
|
|
187
221
|
}
|
|
188
|
-
/**
|
|
189
|
-
|
|
222
|
+
/**
|
|
223
|
+
* Reconstruct a propagated parent {@link RunTree} from a trace context; never throws. LangSmith's `RunTree.fromHeaders`
|
|
224
|
+
* lets the context's destination outrank `fallback`, so `fallback` applies only when the context names none.
|
|
225
|
+
*/
|
|
226
|
+
function runTreeFromContext(ctx, fallback) {
|
|
190
227
|
if (!ctx) {
|
|
191
228
|
return undefined;
|
|
192
229
|
}
|
|
193
230
|
try {
|
|
194
|
-
|
|
231
|
+
const run = run_trees_1.RunTree.fromHeaders({ ...ctx, baggage: (0, routing_1.normalizeReplicaHeaders)(ctx.baggage ?? '') }, fallback);
|
|
232
|
+
if (!run)
|
|
233
|
+
return undefined;
|
|
234
|
+
run.replicas = (0, routing_1.replicaRouting)(run.replicas);
|
|
235
|
+
return run;
|
|
195
236
|
}
|
|
196
237
|
catch {
|
|
197
238
|
return undefined;
|
|
@@ -205,115 +246,14 @@ function buildRunTree(config, params) {
|
|
|
205
246
|
return new run_trees_1.RunTree({
|
|
206
247
|
name: params.name,
|
|
207
248
|
run_type: params.runType,
|
|
208
|
-
inputs:
|
|
249
|
+
inputs: {},
|
|
209
250
|
parent_run: params.parent,
|
|
210
251
|
client: config.client,
|
|
211
|
-
project_name: config.projectName
|
|
252
|
+
...(0, routing_1.destination)(params.parent, { project_name: config.projectName, address: config.address }),
|
|
253
|
+
replicas: params.parent?.replicas ?? config.replicas,
|
|
212
254
|
tags: config.tags,
|
|
213
|
-
extra: { metadata:
|
|
255
|
+
extra: { metadata: { ...config.metadata, ...params.metadata } },
|
|
214
256
|
tracingEnabled: true,
|
|
215
257
|
});
|
|
216
258
|
}
|
|
217
|
-
/**
|
|
218
|
-
* A {@link RunTree} subclass safe to construct and drive from workflow code.
|
|
219
|
-
*
|
|
220
|
-
* Subclasses rather than wraps because LangSmith's `traceable` resolves its
|
|
221
|
-
* parent with `instanceof RunTree` before calling `parent.createChild(...)`, so
|
|
222
|
-
* a plain wrapper would refuse to nest under it.
|
|
223
|
-
*
|
|
224
|
-
* @internal
|
|
225
|
-
*/
|
|
226
|
-
class ReplaySafeRunTree extends run_trees_1.RunTree {
|
|
227
|
-
// Per-invocation run-id factory. Supplied by read-only handlers (queries, update
|
|
228
|
-
// validators) so their ids don't draw from the Workflow main PRNG; left
|
|
229
|
-
// undefined on recorded paths, where id minting falls back to the isolated
|
|
230
|
-
// LANGSMITH_RUN_TREE_STREAM named stream. Propagated to every child so the whole
|
|
231
|
-
// subtree mints from one factory.
|
|
232
|
-
generateNewUuid4;
|
|
233
|
-
constructor(config, generateNewUuid4) {
|
|
234
|
-
super(ReplaySafeRunTree.fill(config, generateNewUuid4));
|
|
235
|
-
this.generateNewUuid4 = generateNewUuid4;
|
|
236
|
-
}
|
|
237
|
-
static fill(config, generateNewUuid4) {
|
|
238
|
-
const id = config.id ?? (generateNewUuid4 ? generateNewUuid4() : (0, workflow_1.getRandomStream)(LANGSMITH_RUN_TREE_STREAM).uuid4());
|
|
239
|
-
const start_time = config.start_time ?? Date.now();
|
|
240
|
-
const trace_id = config.trace_id ?? config.parent_run?.trace_id ?? id;
|
|
241
|
-
let dotted_order = config.dotted_order;
|
|
242
|
-
if (dotted_order == null) {
|
|
243
|
-
const startMs = typeof start_time === 'number' ? start_time : Date.parse(String(start_time));
|
|
244
|
-
const { dottedOrder } = (0, run_trees_1.convertToDottedOrderFormat)(startMs, id);
|
|
245
|
-
const parentDotted = config.parent_run?.dotted_order;
|
|
246
|
-
dotted_order = parentDotted ? `${parentDotted}.${dottedOrder}` : dottedOrder;
|
|
247
|
-
}
|
|
248
|
-
return {
|
|
249
|
-
...config,
|
|
250
|
-
id,
|
|
251
|
-
start_time,
|
|
252
|
-
trace_id,
|
|
253
|
-
dotted_order,
|
|
254
|
-
parent_run_id: config.parent_run_id ?? config.parent_run?.id,
|
|
255
|
-
client: NOOP_CLIENT,
|
|
256
|
-
tracingEnabled: config.tracingEnabled ?? true,
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
/** Produce a replay-safe child so deeply-nested `traceable` runs stay deterministic. */
|
|
260
|
-
createChild(config) {
|
|
261
|
-
const child = new ReplaySafeRunTree({
|
|
262
|
-
...config,
|
|
263
|
-
run_type: config.run_type ?? exports.RUN_TYPE.CHAIN,
|
|
264
|
-
parent_run: this,
|
|
265
|
-
parent_run_id: this.id,
|
|
266
|
-
trace_id: this.trace_id,
|
|
267
|
-
project_name: config.project_name ?? this.project_name,
|
|
268
|
-
}, this.generateNewUuid4);
|
|
269
|
-
this.child_runs.push(child);
|
|
270
|
-
return child;
|
|
271
|
-
}
|
|
272
|
-
/** Emit a `createRun` via the Sink, unless replaying. */
|
|
273
|
-
async postRun() {
|
|
274
|
-
if (isReplaying()) {
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
sinks()[sinks_1.LANGSMITH_SINK_NAME].createRun(serializeRun(this));
|
|
278
|
-
}
|
|
279
|
-
/** Record outputs/end-time locally then emit an `updateRun` via the Sink, unless replaying. */
|
|
280
|
-
async patchRun() {
|
|
281
|
-
if (isReplaying()) {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
sinks()[sinks_1.LANGSMITH_SINK_NAME].updateRun(serializeRun(this));
|
|
285
|
-
}
|
|
286
|
-
/** Record end-time / outputs / error on the run object (pure, replay-safe). */
|
|
287
|
-
async end(outputs, error, endTime) {
|
|
288
|
-
if (outputs !== undefined) {
|
|
289
|
-
this.outputs = outputs;
|
|
290
|
-
}
|
|
291
|
-
if (error !== undefined) {
|
|
292
|
-
this.error = error;
|
|
293
|
-
}
|
|
294
|
-
this.end_time = endTime ?? Date.now();
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
exports.ReplaySafeRunTree = ReplaySafeRunTree;
|
|
298
|
-
/**
|
|
299
|
-
* A placeholder, never-emitted parent whose {@link createChild} produces
|
|
300
|
-
* independent root children. Installed as the ambient so a workflow-body
|
|
301
|
-
* `traceable` takes LangSmith's `createChild` branch (deterministic id) instead
|
|
302
|
-
* of the no-parent branch that mints a uuid via `crypto`, which the isolate lacks.
|
|
303
|
-
*
|
|
304
|
-
* @internal
|
|
305
|
-
*/
|
|
306
|
-
class _RootReplaySafeRunTreeFactory extends ReplaySafeRunTree {
|
|
307
|
-
/** Produce a replay-safe child with no link back to this factory. */
|
|
308
|
-
createChild(config) {
|
|
309
|
-
return new ReplaySafeRunTree({
|
|
310
|
-
...config,
|
|
311
|
-
run_type: config.run_type ?? exports.RUN_TYPE.CHAIN,
|
|
312
|
-
project_name: config.project_name ?? this.project_name,
|
|
313
|
-
}, this.generateNewUuid4);
|
|
314
|
-
}
|
|
315
|
-
async postRun() { }
|
|
316
|
-
async patchRun() { }
|
|
317
|
-
}
|
|
318
|
-
exports._RootReplaySafeRunTreeFactory = _RootReplaySafeRunTreeFactory;
|
|
319
259
|
//# sourceMappingURL=run-tree.js.map
|
package/lib/run-tree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-tree.js","sourceRoot":"","sources":["../src/run-tree.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AA+
|
|
1
|
+
{"version":3,"file":"run-tree.js","sourceRoot":"","sources":["../src/run-tree.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AA+EH,sDAaC;AAGD,oCAOC;AAGD,oCAqBC;AAUD,sCAQC;AAGD,sCAEC;AAMD,8BA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AI;QACjB,KAAK,EAAE,EAAE,QAAQ,EAAE,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,EAAE;QAC/D,cAAc,EAAE,IAAI;KACrB,CAAC,CAAC;AACL,CAAC"}
|
package/lib/sinks.d.ts
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import type { Client } from 'langsmith';
|
|
7
|
+
import { RunTree, type RunTreeConfig, type WriteReplica } from 'langsmith/run_trees';
|
|
8
|
+
import type { Logger } from '@temporalio/common';
|
|
7
9
|
import type { Sinks } from '@temporalio/workflow';
|
|
8
10
|
import type { InjectedSinks } from '@temporalio/worker';
|
|
11
|
+
import { type ReplicaRouting } from './routing';
|
|
9
12
|
/** Plain-JSON description of a LangSmith run crossing the isolate→worker boundary. */
|
|
10
13
|
export interface SerializedRun {
|
|
11
14
|
id: string;
|
|
@@ -24,6 +27,9 @@ export interface SerializedRun {
|
|
|
24
27
|
extra?: Record<string, unknown>;
|
|
25
28
|
tags?: string[];
|
|
26
29
|
project_name?: string;
|
|
30
|
+
address?: RunTreeConfig['address'];
|
|
31
|
+
replicas?: ReplicaRouting[];
|
|
32
|
+
distributedParentId?: string;
|
|
27
33
|
events?: Record<string, unknown>[];
|
|
28
34
|
}
|
|
29
35
|
/** Runtime configuration shared by the client and activity interceptors. */
|
|
@@ -34,6 +40,9 @@ export interface EmitterConfig {
|
|
|
34
40
|
addTemporalRuns: boolean;
|
|
35
41
|
/** Target LangSmith project. */
|
|
36
42
|
projectName?: string;
|
|
43
|
+
address?: RunTreeConfig['address'];
|
|
44
|
+
/** Full replica configuration is local to the client/worker process. */
|
|
45
|
+
replicas?: WriteReplica[];
|
|
37
46
|
/** Tags attached to every emitted run. */
|
|
38
47
|
tags?: string[];
|
|
39
48
|
/** Metadata merged into every emitted run. */
|
|
@@ -47,8 +56,14 @@ export interface LangSmithSinks extends Sinks {
|
|
|
47
56
|
/** Emit a `createRun` for a newly started run. */
|
|
48
57
|
createRun(run: SerializedRun): void;
|
|
49
58
|
/** Emit an `updateRun` (end / outputs / error / events) for a run. */
|
|
50
|
-
updateRun(run: SerializedRun): void;
|
|
59
|
+
updateRun(run: SerializedRun, options?: Parameters<RunTree['patchRun']>[0]): void;
|
|
51
60
|
};
|
|
52
61
|
}
|
|
53
|
-
/**
|
|
54
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Build the worker-side {@link InjectedSinks} routing serialized runs to a real LangSmith client, and a `drain` that
|
|
64
|
+
* resolves once every queued write has reached the client.
|
|
65
|
+
*/
|
|
66
|
+
export declare function createLangSmithSinks(client: Client, replicas: WriteReplica[] | undefined, logger: Logger): {
|
|
67
|
+
sinks: InjectedSinks<LangSmithSinks>;
|
|
68
|
+
drain: () => Promise<void>;
|
|
69
|
+
};
|
package/lib/sinks.js
CHANGED
|
@@ -7,66 +7,49 @@
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.LANGSMITH_SINK_NAME = void 0;
|
|
9
9
|
exports.createLangSmithSinks = createLangSmithSinks;
|
|
10
|
-
const
|
|
10
|
+
const run_trees_1 = require("langsmith/run_trees");
|
|
11
|
+
const routing_1 = require("./routing");
|
|
11
12
|
/** The injected sink's wire name. Reserved-prefixed; allowlisted in `@temporalio/common`. */
|
|
12
13
|
exports.LANGSMITH_SINK_NAME = '__temporal_langsmith';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
id: run.id,
|
|
17
|
-
trace_id: run.trace_id,
|
|
18
|
-
dotted_order: run.dotted_order,
|
|
19
|
-
parent_run_id: run.parent_run_id,
|
|
20
|
-
name: run.name,
|
|
21
|
-
run_type: run.run_type,
|
|
22
|
-
start_time: run.start_time,
|
|
14
|
+
function emissionRun(run, client, replicas) {
|
|
15
|
+
const tree = new run_trees_1.RunTree({
|
|
16
|
+
...run,
|
|
23
17
|
inputs: run.inputs ?? {},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
18
|
+
client,
|
|
19
|
+
replicas: (0, routing_1.bindReplicaCredentials)(run.replicas, replicas),
|
|
20
|
+
tracingEnabled: true,
|
|
21
|
+
});
|
|
22
|
+
tree.events = run.events;
|
|
23
|
+
return tree;
|
|
28
24
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Build the worker-side {@link InjectedSinks} routing serialized runs to a real LangSmith client, and a `drain` that
|
|
27
|
+
* resolves once every queued write has reached the client.
|
|
28
|
+
*/
|
|
29
|
+
function createLangSmithSinks(client, replicas, logger) {
|
|
30
|
+
// Writes run one at a time in call order, so an update never overtakes its create.
|
|
31
|
+
let writes = Promise.resolve();
|
|
32
|
+
// The Workflow already decided whether to trace each run, so the env isn't checked again here.
|
|
33
|
+
const enqueue = (write) => {
|
|
34
|
+
// Emission must never fail the workflow.
|
|
35
|
+
writes = writes.then(write).catch((err) => {
|
|
36
|
+
logger.error(`LangSmith background I/O error: ${String(err)}`);
|
|
37
|
+
});
|
|
40
38
|
};
|
|
41
|
-
}
|
|
42
|
-
/** Build the worker-side {@link InjectedSinks} routing serialized runs to a real LangSmith client. */
|
|
43
|
-
function createLangSmithSinks(client) {
|
|
44
39
|
return {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
void Promise.resolve(client.createRun(toCreateParams(run))).catch(() => {
|
|
53
|
-
/* swallow: emission must never fail the workflow */
|
|
54
|
-
});
|
|
40
|
+
sinks: {
|
|
41
|
+
[exports.LANGSMITH_SINK_NAME]: {
|
|
42
|
+
createRun: {
|
|
43
|
+
fn: (_info, run) => enqueue(() => emissionRun(run, client, replicas).postRun()),
|
|
44
|
+
callDuringReplay: false,
|
|
55
45
|
},
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
fn: (_info, run) => {
|
|
60
|
-
if (!(0, langsmith_1.isTracingEnabled)()) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
void Promise.resolve(client.updateRun(run.id, toUpdateParams(run))).catch(() => {
|
|
64
|
-
/* swallow: emission must never fail the workflow */
|
|
65
|
-
});
|
|
46
|
+
updateRun: {
|
|
47
|
+
fn: (_info, run, options) => enqueue(() => emissionRun(run, client, replicas).patchRun(options)),
|
|
48
|
+
callDuringReplay: false,
|
|
66
49
|
},
|
|
67
|
-
callDuringReplay: false,
|
|
68
50
|
},
|
|
69
51
|
},
|
|
52
|
+
drain: () => writes,
|
|
70
53
|
};
|
|
71
54
|
}
|
|
72
55
|
//# sourceMappingURL=sinks.js.map
|
package/lib/sinks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sinks.js","sourceRoot":"","sources":["../src/sinks.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;
|
|
1
|
+
{"version":3,"file":"sinks.js","sourceRoot":"","sources":["../src/sinks.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AA+EH,oDA6BC;AAzGD,mDAAqF;AAIrF,uCAAwE;AA2CxE,6FAA6F;AAChF,QAAA,mBAAmB,GAAG,sBAA+B,CAAC;AAYnE,SAAS,WAAW,CAAC,GAAkB,EAAE,MAAc,EAAE,QAAoC;IAC3F,MAAM,IAAI,GAAG,IAAI,mBAAO,CAAC;QACvB,GAAG,GAAG;QACN,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE;QACxB,MAAM;QACN,QAAQ,EAAE,IAAA,gCAAsB,EAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC;QACxD,cAAc,EAAE,IAAI;KACrB,CAAC,CAAC;IACH,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,MAA2B,CAAC;IAC9C,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,SAAgB,oBAAoB,CAClC,MAAc,EACd,QAAoC,EACpC,MAAc;IAEd,mFAAmF;IACnF,IAAI,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAC/B,+FAA+F;IAC/F,MAAM,OAAO,GAAG,CAAC,KAA0B,EAAQ,EAAE;QACnD,yCAAyC;QACzC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;YACjD,MAAM,CAAC,KAAK,CAAC,mCAAmC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IACF,OAAO;QACL,KAAK,EAAE;YACL,CAAC,2BAAmB,CAAC,EAAE;gBACrB,SAAS,EAAE;oBACT,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;oBAC/E,gBAAgB,EAAE,KAAK;iBACxB;gBACD,SAAS,EAAE;oBACT,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;oBAChG,gBAAgB,EAAE,KAAK;iBACxB;aACF;SACF;QACD,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM;KACpB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Scoped LangSmith defaults for worker handlers with no propagated parent. */
|
|
2
|
+
import { type RunTreeOverrides } from './run-tree';
|
|
3
|
+
import type { EmitterConfig } from './sinks';
|
|
4
|
+
export declare const WORKER_RUN_TREE_OVERRIDES: RunTreeOverrides;
|
|
5
|
+
/** Supply native roots with defaults without installing an ambient RunTree. */
|
|
6
|
+
export declare function withRunTreeDefaults<T>(config: EmitterConfig, fn: () => T): T;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Scoped LangSmith defaults for worker handlers with no propagated parent. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.WORKER_RUN_TREE_OVERRIDES = void 0;
|
|
5
|
+
exports.withRunTreeDefaults = withRunTreeDefaults;
|
|
6
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
7
|
+
const traceable_1 = require("langsmith/singletons/traceable");
|
|
8
|
+
const run_tree_1 = require("./run-tree");
|
|
9
|
+
const context = new node_async_hooks_1.AsyncLocalStorage();
|
|
10
|
+
let installed = false;
|
|
11
|
+
exports.WORKER_RUN_TREE_OVERRIDES = {
|
|
12
|
+
statics: {
|
|
13
|
+
getSharedClient: (original) => function (...args) {
|
|
14
|
+
return context.getStore()?.client ?? original.apply(this, args);
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
methods: {
|
|
18
|
+
_resolveAddressing: (original) => function (config, ...args) {
|
|
19
|
+
const defaults = context.getStore();
|
|
20
|
+
if (!defaults)
|
|
21
|
+
return original.call(this, config, ...args);
|
|
22
|
+
this.replicas ??= defaults.replicas;
|
|
23
|
+
// Explicit destinations and native child inheritance outrank the plugin.
|
|
24
|
+
const selected = config.project_name || config.address != null
|
|
25
|
+
? config
|
|
26
|
+
: { ...config, project_name: defaults.projectName, address: defaults.address };
|
|
27
|
+
return original.call(this, selected, ...args);
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
function installDefaults() {
|
|
32
|
+
if (installed)
|
|
33
|
+
return;
|
|
34
|
+
(0, run_tree_1.patchRunTree)(exports.WORKER_RUN_TREE_OVERRIDES);
|
|
35
|
+
installed = true;
|
|
36
|
+
}
|
|
37
|
+
/** Supply native roots with defaults without installing an ambient RunTree. */
|
|
38
|
+
function withRunTreeDefaults(config, fn) {
|
|
39
|
+
installDefaults();
|
|
40
|
+
const storage = traceable_1.AsyncLocalStorageProviderSingleton.getInstance();
|
|
41
|
+
return context.run(config, () => storage.run(undefined, fn));
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=worker-run-tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-run-tree.js","sourceRoot":"","sources":["../src/worker-run-tree.ts"],"names":[],"mappings":";AAAA,+EAA+E;;;AAwC/E,kDAMC;AA5CD,uDAAqD;AAErD,8DAAoF;AACpF,yCAAiE;AAGjE,MAAM,OAAO,GAAG,IAAI,oCAAiB,EAAiB,CAAC;AACvD,IAAI,SAAS,GAAG,KAAK,CAAC;AAET,QAAA,yBAAyB,GAAqB;IACzD,OAAO,EAAE;QACP,eAAe,EAAE,CAAC,QAAQ,EAAE,EAAE,CAC5B,UAAgC,GAAG,IAAe;YAChD,OAAO,OAAO,CAAC,QAAQ,EAAE,EAAE,MAAM,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAClE,CAAC;KACJ;IACD,OAAO,EAAE;QACP,kBAAkB,EAAE,CAAC,QAAQ,EAAE,EAAE,CAC/B,UAAyB,MAAqB,EAAE,GAAG,IAAe;YAChE,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;YACpC,IAAI,CAAC,QAAQ;gBAAE,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;YAC3D,IAAI,CAAC,QAAQ,KAAK,QAAQ,CAAC,QAAQ,CAAC;YACpC,yEAAyE;YACzE,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,OAAO,IAAI,IAAI;gBAC5D,CAAC,CAAC,MAA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