langsmith 0.5.25 → 0.6.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/dist/client.cjs +50 -20
- package/dist/client.d.ts +40 -3
- package/dist/client.js +50 -20
- package/dist/experimental/anthropic/context.cjs +419 -49
- package/dist/experimental/anthropic/context.js +420 -50
- package/dist/experimental/anthropic/index.cjs +78 -10
- package/dist/experimental/anthropic/index.js +80 -12
- package/dist/experimental/anthropic/messages.cjs +53 -0
- package/dist/experimental/anthropic/messages.d.ts +6 -0
- package/dist/experimental/anthropic/messages.js +52 -0
- package/dist/experimental/anthropic/transcripts.cjs +144 -0
- package/dist/experimental/anthropic/transcripts.d.ts +22 -0
- package/dist/experimental/anthropic/transcripts.js +141 -0
- package/dist/experimental/anthropic/types.d.ts +1 -0
- package/dist/experimental/anthropic/usage.cjs +19 -20
- package/dist/experimental/anthropic/usage.d.ts +2 -1
- package/dist/experimental/anthropic/usage.js +18 -20
- package/dist/experimental/opencode/index.cjs +36 -0
- package/dist/experimental/opencode/index.d.ts +3 -0
- package/dist/experimental/opencode/index.js +32 -0
- package/dist/experimental/opencode/tracer.cjs +389 -0
- package/dist/experimental/opencode/tracer.d.ts +30 -0
- package/dist/experimental/opencode/tracer.js +385 -0
- package/dist/experimental/otel/setup.cjs +1 -1
- package/dist/experimental/otel/setup.js +1 -1
- package/dist/experimental/sandbox/sandbox.cjs +6 -2
- package/dist/experimental/sandbox/sandbox.d.ts +5 -1
- package/dist/experimental/sandbox/sandbox.js +6 -2
- package/dist/experimental/sandbox/types.d.ts +3 -1
- package/dist/experimental/vercel/index.cjs +1 -1
- package/dist/experimental/vercel/index.js +1 -1
- package/dist/experimental/vercel/middleware.cjs +2 -1
- package/dist/experimental/vercel/middleware.js +2 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/singletons/traceable.cjs +1 -3
- package/dist/singletons/traceable.js +1 -3
- package/dist/traceable.cjs +1 -3
- package/dist/traceable.js +1 -3
- package/dist/utils/_git.cjs +2 -2
- package/dist/utils/_git.js +2 -2
- package/dist/utils/env.cjs +2 -2
- package/dist/utils/env.js +2 -2
- package/dist/utils/error.cjs +2 -2
- package/dist/utils/error.js +2 -2
- package/dist/utils/jestlike/reporter.cjs +1 -1
- package/dist/utils/jestlike/reporter.js +1 -1
- package/dist/utils/jestlike/vendor/chain.cjs +2 -3
- package/dist/utils/jestlike/vendor/chain.js +2 -3
- package/dist/utils/serialize_worker.cjs +1 -2
- package/dist/utils/serialize_worker.d.ts +1 -2
- package/dist/utils/serialize_worker.js +1 -2
- package/dist/vitest/utils/esm.mjs +4 -4
- package/dist/wrappers/gemini.cjs +1 -1
- package/dist/wrappers/gemini.js +1 -1
- package/dist/wrappers/openai.cjs +2 -6
- package/dist/wrappers/openai.js +2 -6
- package/experimental/opencode.cjs +1 -0
- package/experimental/opencode.d.cts +1 -0
- package/experimental/opencode.d.ts +1 -0
- package/experimental/opencode.js +1 -0
- package/package.json +24 -18
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
// import type { Event, FilePart, Message, Model, Part } from "@opencode-ai/sdk";
|
|
2
|
+
import { RunTree } from "../../run_trees.js";
|
|
3
|
+
import { Client } from "../../index.js";
|
|
4
|
+
const dedupeParts = (parts) => {
|
|
5
|
+
const partById = {};
|
|
6
|
+
for (const part of parts) {
|
|
7
|
+
partById[part.id] = { ...partById[part.id], ...part };
|
|
8
|
+
}
|
|
9
|
+
return Object.values(partById);
|
|
10
|
+
};
|
|
11
|
+
const convertToStandardContentBlock = (part) => {
|
|
12
|
+
// Ignore AI SDK specific parts
|
|
13
|
+
if (part.type === "step-start" || part.type === "step-finish") {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
if (part.type === "text") {
|
|
17
|
+
return {
|
|
18
|
+
type: "text",
|
|
19
|
+
text: part.text,
|
|
20
|
+
extras: part.metadata,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (part.type === "reasoning") {
|
|
24
|
+
return {
|
|
25
|
+
type: "thinking",
|
|
26
|
+
thinking: part.text,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (part.type === "file") {
|
|
30
|
+
return {
|
|
31
|
+
type: "file",
|
|
32
|
+
id: part.filename ?? part.id,
|
|
33
|
+
url: part.url,
|
|
34
|
+
mime_type: part.mime,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (part.type === "tool") {
|
|
38
|
+
return {
|
|
39
|
+
type: "tool_use",
|
|
40
|
+
name: part.tool,
|
|
41
|
+
input: part.state.input,
|
|
42
|
+
id: part.callID,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (part.type === "compaction") {
|
|
46
|
+
return {
|
|
47
|
+
type: "compaction",
|
|
48
|
+
data: { auto: part.auto },
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
type: "non_standard",
|
|
53
|
+
value: part,
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
const convertToStandardMessages = (messages) => {
|
|
57
|
+
return messages.flatMap((message) => {
|
|
58
|
+
const parts = dedupeParts(message.parts);
|
|
59
|
+
if (message.info?.role === "assistant") {
|
|
60
|
+
// split out into "model message"
|
|
61
|
+
return [
|
|
62
|
+
{
|
|
63
|
+
role: "assistant",
|
|
64
|
+
content: parts.flatMap(convertToStandardContentBlock),
|
|
65
|
+
},
|
|
66
|
+
...parts.flatMap((part) => {
|
|
67
|
+
if (part.type !== "tool")
|
|
68
|
+
return [];
|
|
69
|
+
if (part.state.status === "completed") {
|
|
70
|
+
return {
|
|
71
|
+
role: "tool",
|
|
72
|
+
content: part.state.output,
|
|
73
|
+
name: part.tool,
|
|
74
|
+
id: part.id,
|
|
75
|
+
tool_call_id: part.callID,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (part.state.status === "error") {
|
|
79
|
+
return {
|
|
80
|
+
role: "tool",
|
|
81
|
+
content: part.state.error,
|
|
82
|
+
name: part.tool,
|
|
83
|
+
id: part.id,
|
|
84
|
+
tool_call_id: part.callID,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return [];
|
|
88
|
+
}),
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
if (message.info?.role === "user") {
|
|
92
|
+
return {
|
|
93
|
+
role: "user",
|
|
94
|
+
content: parts.flatMap(convertToStandardContentBlock),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return [];
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
export class OpenCodeSessionTracer {
|
|
101
|
+
constructor(inputConfig) {
|
|
102
|
+
Object.defineProperty(this, "sessions", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
configurable: true,
|
|
105
|
+
writable: true,
|
|
106
|
+
value: {}
|
|
107
|
+
});
|
|
108
|
+
Object.defineProperty(this, "client", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
configurable: true,
|
|
111
|
+
writable: true,
|
|
112
|
+
value: void 0
|
|
113
|
+
});
|
|
114
|
+
Object.defineProperty(this, "inputConfig", {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
configurable: true,
|
|
117
|
+
writable: true,
|
|
118
|
+
value: void 0
|
|
119
|
+
});
|
|
120
|
+
this.inputConfig = inputConfig ?? {};
|
|
121
|
+
this.client = inputConfig?.client ?? new Client();
|
|
122
|
+
}
|
|
123
|
+
getSession(sessionID) {
|
|
124
|
+
this.sessions[sessionID] ??= {
|
|
125
|
+
messages: {},
|
|
126
|
+
traces: {},
|
|
127
|
+
history: undefined,
|
|
128
|
+
pendingSystem: undefined,
|
|
129
|
+
postRunQueue: [],
|
|
130
|
+
parentID: undefined,
|
|
131
|
+
};
|
|
132
|
+
return this.sessions[sessionID];
|
|
133
|
+
}
|
|
134
|
+
getMessage(sessionID, messageID) {
|
|
135
|
+
const session = this.getSession(sessionID);
|
|
136
|
+
session.messages[messageID] ??= {
|
|
137
|
+
info: undefined,
|
|
138
|
+
parts: [],
|
|
139
|
+
complete: false,
|
|
140
|
+
system: undefined,
|
|
141
|
+
};
|
|
142
|
+
// Attach pending system to assistant messages
|
|
143
|
+
if (session.pendingSystem != null &&
|
|
144
|
+
session.messages[messageID]?.info?.role === "assistant") {
|
|
145
|
+
session.messages[messageID].system = session.pendingSystem;
|
|
146
|
+
session.pendingSystem = undefined;
|
|
147
|
+
}
|
|
148
|
+
return session.messages[messageID];
|
|
149
|
+
}
|
|
150
|
+
getProviderMetadata(run) {
|
|
151
|
+
const info = run.info;
|
|
152
|
+
if (!info || info.role !== "assistant")
|
|
153
|
+
return {};
|
|
154
|
+
const model = run.system?.model;
|
|
155
|
+
const modelId = model?.id ?? info.modelID;
|
|
156
|
+
const providerId = model?.providerID ?? info.providerID;
|
|
157
|
+
const ls_invocation_params = {
|
|
158
|
+
model: modelId,
|
|
159
|
+
providerID: providerId,
|
|
160
|
+
};
|
|
161
|
+
if (model?.name)
|
|
162
|
+
ls_invocation_params.model_display_name = model.name;
|
|
163
|
+
if (model?.api?.id)
|
|
164
|
+
ls_invocation_params.api_model_id = model.api.id;
|
|
165
|
+
if (model?.api?.url)
|
|
166
|
+
ls_invocation_params.api_url = model.api.url;
|
|
167
|
+
if (model?.api?.npm)
|
|
168
|
+
ls_invocation_params.api_npm_package = model.api.npm;
|
|
169
|
+
const stepFinish = run.parts.find((part) => part.type === "step-finish");
|
|
170
|
+
return {
|
|
171
|
+
ls_model_name: modelId,
|
|
172
|
+
ls_provider: providerId,
|
|
173
|
+
ls_model_type: "chat",
|
|
174
|
+
ls_invocation_params,
|
|
175
|
+
usage_metadata: stepFinish
|
|
176
|
+
? {
|
|
177
|
+
input_tokens: stepFinish.tokens.input,
|
|
178
|
+
output_tokens: stepFinish.tokens.output + stepFinish.tokens.reasoning,
|
|
179
|
+
total_tokens: stepFinish.tokens.input +
|
|
180
|
+
stepFinish.tokens.output +
|
|
181
|
+
stepFinish.tokens.reasoning,
|
|
182
|
+
input_token_details: {
|
|
183
|
+
cache_read: stepFinish.tokens.cache.read,
|
|
184
|
+
cache_creation: stepFinish.tokens.cache.write,
|
|
185
|
+
},
|
|
186
|
+
}
|
|
187
|
+
: undefined,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
async sendTrace(sessionID, runs, options) {
|
|
191
|
+
const session = this.getSession(sessionID);
|
|
192
|
+
const userRunIdx = runs.findIndex(({ info }) => info?.role === "user");
|
|
193
|
+
const userRun = runs.at(userRunIdx);
|
|
194
|
+
const agentRuns = runs.slice(userRunIdx + 1);
|
|
195
|
+
if (userRunIdx === -1 || userRun == null)
|
|
196
|
+
return;
|
|
197
|
+
const parentStartTime = userRun?.info?.time?.created ?? Date.now();
|
|
198
|
+
const parentEndTime = agentRuns
|
|
199
|
+
.flatMap((run) => run.parts)
|
|
200
|
+
.reduce((acc, part) => {
|
|
201
|
+
if (!("time" in part) || part.time == null)
|
|
202
|
+
return acc;
|
|
203
|
+
if (!("end" in part.time) || typeof part.time.end !== "number")
|
|
204
|
+
return acc;
|
|
205
|
+
return Math.max(acc, part.time.end);
|
|
206
|
+
}, parentStartTime);
|
|
207
|
+
if (userRun?.info) {
|
|
208
|
+
session.history ??= [];
|
|
209
|
+
session.history.push({ info: userRun.info, parts: userRun.parts });
|
|
210
|
+
}
|
|
211
|
+
const parentConfig = {
|
|
212
|
+
name: "opencode.session",
|
|
213
|
+
run_type: "chain",
|
|
214
|
+
start_time: parentStartTime,
|
|
215
|
+
end_time: parentEndTime,
|
|
216
|
+
extra: {
|
|
217
|
+
metadata: {
|
|
218
|
+
ls_integration: "opencode-js",
|
|
219
|
+
ls_agent_type: "root",
|
|
220
|
+
thread_id: sessionID,
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
inputs: { messages: convertToStandardMessages([userRun]) },
|
|
224
|
+
outputs: { messages: convertToStandardMessages(agentRuns) },
|
|
225
|
+
...this.inputConfig,
|
|
226
|
+
client: this.client,
|
|
227
|
+
};
|
|
228
|
+
const parent = options?.parentRunTree?.createChild(parentConfig) ??
|
|
229
|
+
new RunTree(parentConfig);
|
|
230
|
+
session.postRunQueue.push(parent.postRun());
|
|
231
|
+
for (const run of agentRuns) {
|
|
232
|
+
const startTime = run.info?.time?.created ?? Date.now();
|
|
233
|
+
const endTime = run.parts.reduce((acc, part) => {
|
|
234
|
+
if (!("time" in part) || part.time == null)
|
|
235
|
+
return acc;
|
|
236
|
+
if (!("end" in part.time) || typeof part.time.end !== "number")
|
|
237
|
+
return acc;
|
|
238
|
+
return Math.max(acc, part.time.end);
|
|
239
|
+
}, startTime);
|
|
240
|
+
const parts = dedupeParts(run.parts);
|
|
241
|
+
// Create child runs for tool parts
|
|
242
|
+
const child = parent.createChild({
|
|
243
|
+
name: "opencode.assistant.turn",
|
|
244
|
+
run_type: "llm",
|
|
245
|
+
start_time: startTime,
|
|
246
|
+
end_time: endTime,
|
|
247
|
+
inputs: {
|
|
248
|
+
messages: [
|
|
249
|
+
...(run.system?.system
|
|
250
|
+
? [{ role: "system", content: run.system.system.join("\n") }]
|
|
251
|
+
: []),
|
|
252
|
+
...convertToStandardMessages(session.history ?? []),
|
|
253
|
+
],
|
|
254
|
+
},
|
|
255
|
+
outputs: { messages: convertToStandardMessages([run]) },
|
|
256
|
+
extra: { metadata: this.getProviderMetadata(run) },
|
|
257
|
+
});
|
|
258
|
+
session.postRunQueue.push(child.postRun());
|
|
259
|
+
for (const toolPart of parts) {
|
|
260
|
+
if (toolPart.type !== "tool")
|
|
261
|
+
continue;
|
|
262
|
+
const state = toolPart.state;
|
|
263
|
+
// Try looking for subgraph
|
|
264
|
+
let toolHandled = false;
|
|
265
|
+
if (state.metadata?.sessionId) {
|
|
266
|
+
const session = this.getSession(state.metadata.sessionId);
|
|
267
|
+
for (const trace of Object.values(session.traces)) {
|
|
268
|
+
if (trace.state !== "subgraph")
|
|
269
|
+
continue;
|
|
270
|
+
await this.sendTrace(state.metadata.sessionId, trace.runs, {
|
|
271
|
+
parentRunTree: child,
|
|
272
|
+
});
|
|
273
|
+
toolHandled = true;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (toolHandled)
|
|
277
|
+
continue;
|
|
278
|
+
const tool = child.createChild({
|
|
279
|
+
name: toolPart.tool,
|
|
280
|
+
run_type: "tool",
|
|
281
|
+
inputs: state.input ?? {},
|
|
282
|
+
outputs: {
|
|
283
|
+
output: state.output,
|
|
284
|
+
attachments: state.attachments?.map(convertToStandardContentBlock) ??
|
|
285
|
+
undefined,
|
|
286
|
+
},
|
|
287
|
+
start_time: state.time?.start ?? startTime,
|
|
288
|
+
end_time: state.time?.end ?? endTime,
|
|
289
|
+
error: state.error,
|
|
290
|
+
extra: { metadata: state.metadata },
|
|
291
|
+
});
|
|
292
|
+
session.postRunQueue.push(tool.postRun());
|
|
293
|
+
}
|
|
294
|
+
if (run.info) {
|
|
295
|
+
session.history ??= [];
|
|
296
|
+
session.history.push({ info: run.info, parts });
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
async flush() {
|
|
301
|
+
await Promise.all(Object.values(this.sessions).flatMap((session) => session.postRunQueue));
|
|
302
|
+
await this.client.flush();
|
|
303
|
+
await this.client.awaitPendingTraceBatches();
|
|
304
|
+
}
|
|
305
|
+
async handleSystem(input, output) {
|
|
306
|
+
if (!input.sessionID)
|
|
307
|
+
return;
|
|
308
|
+
const session = this.getSession(input.sessionID);
|
|
309
|
+
session.pendingSystem = { model: input.model, system: output.system };
|
|
310
|
+
}
|
|
311
|
+
async handleSessionLoad(sessionID, history) {
|
|
312
|
+
const session = this.getSession(sessionID);
|
|
313
|
+
if (session.history)
|
|
314
|
+
return;
|
|
315
|
+
session.history = await history(sessionID);
|
|
316
|
+
}
|
|
317
|
+
async handleEvent({ event: { properties, type } }) {
|
|
318
|
+
if (type === "server.instance.disposed") {
|
|
319
|
+
await this.flush();
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const sessionID = "sessionID" in properties && typeof properties.sessionID === "string"
|
|
323
|
+
? properties.sessionID
|
|
324
|
+
: undefined;
|
|
325
|
+
if (!sessionID)
|
|
326
|
+
return;
|
|
327
|
+
const session = this.getSession(sessionID);
|
|
328
|
+
let updatedID;
|
|
329
|
+
if (type === "session.created" || type === "session.updated") {
|
|
330
|
+
session.parentID = properties.info.parentID;
|
|
331
|
+
}
|
|
332
|
+
if (type === "message.updated") {
|
|
333
|
+
const message = this.getMessage(sessionID, properties.info.id);
|
|
334
|
+
message.info = properties.info;
|
|
335
|
+
updatedID = properties.info.id;
|
|
336
|
+
}
|
|
337
|
+
if (type === "message.part.updated") {
|
|
338
|
+
const message = this.getMessage(sessionID, properties.part.messageID);
|
|
339
|
+
message.parts.push(properties.part);
|
|
340
|
+
updatedID = properties.part.messageID;
|
|
341
|
+
}
|
|
342
|
+
if (type === "message.part.removed") {
|
|
343
|
+
const message = this.getMessage(sessionID, properties.messageID);
|
|
344
|
+
message.parts = message.parts.filter((part) => part.id !== properties.partID);
|
|
345
|
+
updatedID = properties.messageID;
|
|
346
|
+
}
|
|
347
|
+
if (type === "message.removed") {
|
|
348
|
+
const session = this.getSession(sessionID);
|
|
349
|
+
delete session.messages[properties.messageID];
|
|
350
|
+
}
|
|
351
|
+
// Message consolidation logic
|
|
352
|
+
const message = updatedID ? session.messages[updatedID] : undefined;
|
|
353
|
+
if (message?.info?.role == null)
|
|
354
|
+
return;
|
|
355
|
+
// Skip if message is already marked as complete
|
|
356
|
+
if (message.complete)
|
|
357
|
+
return;
|
|
358
|
+
message.complete =
|
|
359
|
+
(message.info?.role === "user" && message.parts.length > 0) ||
|
|
360
|
+
(message.info?.role === "assistant" &&
|
|
361
|
+
message.parts.some((part) => part.type === "step-finish"));
|
|
362
|
+
// Now we're complete, add to a trace
|
|
363
|
+
if (message.complete) {
|
|
364
|
+
const traceId = message.info.role === "user" ? message.info.id : message.info.parentID;
|
|
365
|
+
session.traces[traceId] ??= { runs: [], state: false };
|
|
366
|
+
const trace = session.traces[traceId];
|
|
367
|
+
trace.runs.push(message);
|
|
368
|
+
// Skip if trace is already marked as complete
|
|
369
|
+
if (trace.state !== false)
|
|
370
|
+
return;
|
|
371
|
+
trace.state = trace.runs.some((run) => run.parts.some(
|
|
372
|
+
// trace is marked complete when there's a step-finish part with reason "stop"
|
|
373
|
+
(part) => part.type === "step-finish" && part.reason === "stop"));
|
|
374
|
+
if (trace.state) {
|
|
375
|
+
// If trace is part of a subagent call, mark it as a subgraph and submit
|
|
376
|
+
// when parent is being submitted (to preserve correct dotted order)
|
|
377
|
+
if (session.parentID) {
|
|
378
|
+
trace.state = "subgraph";
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
await this.sendTrace(sessionID, trace.runs);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
@@ -56,7 +56,7 @@ const initializeOTEL = (config = {}) => {
|
|
|
56
56
|
contextManager.enable();
|
|
57
57
|
api_1.context.setGlobalContextManager(contextManager);
|
|
58
58
|
}
|
|
59
|
-
catch (
|
|
59
|
+
catch (_e) {
|
|
60
60
|
console.log([
|
|
61
61
|
`Could not automatically set up an OTEL context manager.`,
|
|
62
62
|
`This may be expected if you have (or another imported library has) already set a global context manager.`,
|
|
@@ -53,7 +53,7 @@ export const initializeOTEL = (config = {}) => {
|
|
|
53
53
|
contextManager.enable();
|
|
54
54
|
otel_context.setGlobalContextManager(contextManager);
|
|
55
55
|
}
|
|
56
|
-
catch (
|
|
56
|
+
catch (_e) {
|
|
57
57
|
console.log([
|
|
58
58
|
`Could not automatically set up an OTEL context manager.`,
|
|
59
59
|
`This may be expected if you have (or another imported library has) already set a global context manager.`,
|
|
@@ -87,7 +87,11 @@ class Sandbox {
|
|
|
87
87
|
writable: true,
|
|
88
88
|
value: void 0
|
|
89
89
|
});
|
|
90
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* Idle timeout TTL in seconds (`0` means disabled).
|
|
92
|
+
* New sandboxes receive a server-side default of `600` seconds (10 minutes)
|
|
93
|
+
* when the caller did not set `idleTtlSeconds` explicitly.
|
|
94
|
+
*/
|
|
91
95
|
Object.defineProperty(this, "idle_ttl_seconds", {
|
|
92
96
|
enumerable: true,
|
|
93
97
|
configurable: true,
|
|
@@ -201,7 +205,7 @@ class Sandbox {
|
|
|
201
205
|
catch (e) {
|
|
202
206
|
// Fall back to HTTP on connection errors or missing ws package
|
|
203
207
|
const name = e != null && typeof e === "object" ? e.name : "";
|
|
204
|
-
const message = e != null && typeof e === "object" ? e.message ?? "" : "";
|
|
208
|
+
const message = e != null && typeof e === "object" ? (e.message ?? "") : "";
|
|
205
209
|
if (name === "LangSmithSandboxConnectionError" ||
|
|
206
210
|
name === "LangSmithSandboxServerReloadError" ||
|
|
207
211
|
message.includes("'ws' package")) {
|
|
@@ -40,7 +40,11 @@ export declare class Sandbox {
|
|
|
40
40
|
readonly updated_at?: string;
|
|
41
41
|
/** Maximum lifetime TTL in seconds (`0` means disabled). */
|
|
42
42
|
readonly ttl_seconds?: number;
|
|
43
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Idle timeout TTL in seconds (`0` means disabled).
|
|
45
|
+
* New sandboxes receive a server-side default of `600` seconds (10 minutes)
|
|
46
|
+
* when the caller did not set `idleTtlSeconds` explicitly.
|
|
47
|
+
*/
|
|
44
48
|
readonly idle_ttl_seconds?: number;
|
|
45
49
|
/** Computed expiration timestamp when a TTL is active. */
|
|
46
50
|
readonly expires_at?: string;
|
|
@@ -84,7 +84,11 @@ export class Sandbox {
|
|
|
84
84
|
writable: true,
|
|
85
85
|
value: void 0
|
|
86
86
|
});
|
|
87
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Idle timeout TTL in seconds (`0` means disabled).
|
|
89
|
+
* New sandboxes receive a server-side default of `600` seconds (10 minutes)
|
|
90
|
+
* when the caller did not set `idleTtlSeconds` explicitly.
|
|
91
|
+
*/
|
|
88
92
|
Object.defineProperty(this, "idle_ttl_seconds", {
|
|
89
93
|
enumerable: true,
|
|
90
94
|
configurable: true,
|
|
@@ -198,7 +202,7 @@ export class Sandbox {
|
|
|
198
202
|
catch (e) {
|
|
199
203
|
// Fall back to HTTP on connection errors or missing ws package
|
|
200
204
|
const name = e != null && typeof e === "object" ? e.name : "";
|
|
201
|
-
const message = e != null && typeof e === "object" ? e.message ?? "" : "";
|
|
205
|
+
const message = e != null && typeof e === "object" ? (e.message ?? "") : "";
|
|
202
206
|
if (name === "LangSmithSandboxConnectionError" ||
|
|
203
207
|
name === "LangSmithSandboxServerReloadError" ||
|
|
204
208
|
message.includes("'ws' package")) {
|
|
@@ -270,7 +270,8 @@ export interface CreateSandboxOptions {
|
|
|
270
270
|
ttlSeconds?: number;
|
|
271
271
|
/**
|
|
272
272
|
* Idle timeout in seconds. The sandbox is deleted after this much inactivity.
|
|
273
|
-
* Must be a multiple of 60
|
|
273
|
+
* Must be a multiple of 60. Pass `0` to explicitly disable the idle timeout.
|
|
274
|
+
* When omitted, the server applies a default of `600` seconds (10 minutes).
|
|
274
275
|
*/
|
|
275
276
|
idleTtlSeconds?: number;
|
|
276
277
|
/** Number of vCPUs. */
|
|
@@ -374,6 +375,7 @@ export interface UpdateSandboxOptions {
|
|
|
374
375
|
ttlSeconds?: number;
|
|
375
376
|
/**
|
|
376
377
|
* Idle timeout in seconds. Must be a multiple of 60. Pass `0` to disable.
|
|
378
|
+
* Omit (or pass `undefined`) to leave the existing value unchanged.
|
|
377
379
|
*/
|
|
378
380
|
idleTtlSeconds?: number;
|
|
379
381
|
}
|
|
@@ -191,7 +191,7 @@ const _getGenerateTextWrapperConfig = ({ model, runName, aiSdkMethodName, resolv
|
|
|
191
191
|
return (0, utils_js_1.convertMessageToTracedFormat)({
|
|
192
192
|
content: content ?? outputs.outputs.text,
|
|
193
193
|
role: "assistant",
|
|
194
|
-
}, resolvedLsConfig?.traceResponseMetadata ?? traceResponseMetadata
|
|
194
|
+
}, (resolvedLsConfig?.traceResponseMetadata ?? traceResponseMetadata)
|
|
195
195
|
? { steps }
|
|
196
196
|
: undefined);
|
|
197
197
|
}
|
|
@@ -187,7 +187,7 @@ const _getGenerateTextWrapperConfig = ({ model, runName, aiSdkMethodName, resolv
|
|
|
187
187
|
return convertMessageToTracedFormat({
|
|
188
188
|
content: content ?? outputs.outputs.text,
|
|
189
189
|
role: "assistant",
|
|
190
|
-
}, resolvedLsConfig?.traceResponseMetadata ?? traceResponseMetadata
|
|
190
|
+
}, (resolvedLsConfig?.traceResponseMetadata ?? traceResponseMetadata)
|
|
191
191
|
? { steps }
|
|
192
192
|
: undefined);
|
|
193
193
|
}
|
|
@@ -280,7 +280,8 @@ function LangSmithMiddleware(config) {
|
|
|
280
280
|
}
|
|
281
281
|
let formattedOutputs;
|
|
282
282
|
if (lsConfig?.processOutputs) {
|
|
283
|
-
formattedOutputs =
|
|
283
|
+
formattedOutputs =
|
|
284
|
+
await lsConfig.processOutputs(outputForTracing);
|
|
284
285
|
}
|
|
285
286
|
else {
|
|
286
287
|
formattedOutputs = _formatTracedOutputs(outputForTracing, lsConfig?.traceRawHttp);
|
|
@@ -277,7 +277,8 @@ export function LangSmithMiddleware(config) {
|
|
|
277
277
|
}
|
|
278
278
|
let formattedOutputs;
|
|
279
279
|
if (lsConfig?.processOutputs) {
|
|
280
|
-
formattedOutputs =
|
|
280
|
+
formattedOutputs =
|
|
281
|
+
await lsConfig.processOutputs(outputForTracing);
|
|
281
282
|
}
|
|
282
283
|
else {
|
|
283
284
|
formattedOutputs = _formatTracedOutputs(outputForTracing, lsConfig?.traceRawHttp);
|
package/dist/index.cjs
CHANGED
|
@@ -18,4 +18,4 @@ Object.defineProperty(exports, "PromptCache", { enumerable: true, get: function
|
|
|
18
18
|
Object.defineProperty(exports, "configureGlobalPromptCache", { enumerable: true, get: function () { return index_js_1.configureGlobalPromptCache; } });
|
|
19
19
|
Object.defineProperty(exports, "promptCacheSingleton", { enumerable: true, get: function () { return index_js_1.promptCacheSingleton; } });
|
|
20
20
|
// Update using pnpm bump-version
|
|
21
|
-
exports.__version__ = "0.
|
|
21
|
+
exports.__version__ = "0.6.0";
|
package/dist/index.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
|
5
5
|
export { getDefaultProjectName } from "./utils/project.js";
|
|
6
6
|
export { uuid7, uuid7FromTime } from "./uuid.js";
|
|
7
7
|
export { Cache, PromptCache, type CacheConfig, type CacheMetrics, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
|
|
8
|
-
export declare const __version__ = "0.
|
|
8
|
+
export declare const __version__ = "0.6.0";
|
package/dist/index.js
CHANGED
|
@@ -5,4 +5,4 @@ export { getDefaultProjectName } from "./utils/project.js";
|
|
|
5
5
|
export { uuid7, uuid7FromTime } from "./uuid.js";
|
|
6
6
|
export { Cache, PromptCache, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
|
|
7
7
|
// Update using pnpm bump-version
|
|
8
|
-
export const __version__ = "0.
|
|
8
|
+
export const __version__ = "0.6.0";
|
|
@@ -43,8 +43,6 @@ function withRunTree(runTree, fn) {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
exports.ROOT = Symbol.for("langsmith:traceable:root");
|
|
46
|
-
function isTraceableFunction(x
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
-
) {
|
|
46
|
+
function isTraceableFunction(x) {
|
|
49
47
|
return typeof x === "function" && "langsmith:traceable" in x;
|
|
50
48
|
}
|
|
@@ -37,8 +37,6 @@ export function withRunTree(runTree, fn) {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
export const ROOT = Symbol.for("langsmith:traceable:root");
|
|
40
|
-
export function isTraceableFunction(x
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
-
) {
|
|
40
|
+
export function isTraceableFunction(x) {
|
|
43
41
|
return typeof x === "function" && "langsmith:traceable" in x;
|
|
44
42
|
}
|
package/dist/traceable.cjs
CHANGED
|
@@ -16,9 +16,7 @@ traceable_js_1.AsyncLocalStorageProviderSingleton.initializeGlobalInstance(new n
|
|
|
16
16
|
/**
|
|
17
17
|
* Create OpenTelemetry context manager from RunTree if OTEL is enabled.
|
|
18
18
|
*/
|
|
19
|
-
function maybeCreateOtelContext(runTree, projectName, tracer
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
-
) {
|
|
19
|
+
function maybeCreateOtelContext(runTree, projectName, tracer) {
|
|
22
20
|
if (!runTree || runTree.client.tracingMode !== "otel") {
|
|
23
21
|
return;
|
|
24
22
|
}
|
package/dist/traceable.js
CHANGED
|
@@ -12,9 +12,7 @@ AsyncLocalStorageProviderSingleton.initializeGlobalInstance(new AsyncLocalStorag
|
|
|
12
12
|
/**
|
|
13
13
|
* Create OpenTelemetry context manager from RunTree if OTEL is enabled.
|
|
14
14
|
*/
|
|
15
|
-
function maybeCreateOtelContext(runTree, projectName, tracer
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
-
) {
|
|
15
|
+
function maybeCreateOtelContext(runTree, projectName, tracer) {
|
|
18
16
|
if (!runTree || runTree.client.tracingMode !== "otel") {
|
|
19
17
|
return;
|
|
20
18
|
}
|
package/dist/utils/_git.cjs
CHANGED
|
@@ -23,7 +23,7 @@ const getGitInfo = async (remote = "origin") => {
|
|
|
23
23
|
const execImport = await importChildProcess();
|
|
24
24
|
exec = execImport.exec;
|
|
25
25
|
}
|
|
26
|
-
catch (
|
|
26
|
+
catch (_e) {
|
|
27
27
|
// no-op
|
|
28
28
|
return null;
|
|
29
29
|
}
|
|
@@ -59,7 +59,7 @@ const getDefaultRevisionId = async () => {
|
|
|
59
59
|
const execImport = await importChildProcess();
|
|
60
60
|
exec = execImport.exec;
|
|
61
61
|
}
|
|
62
|
-
catch (
|
|
62
|
+
catch (_e) {
|
|
63
63
|
// no-op
|
|
64
64
|
return null;
|
|
65
65
|
}
|
package/dist/utils/_git.js
CHANGED
|
@@ -20,7 +20,7 @@ export const getGitInfo = async (remote = "origin") => {
|
|
|
20
20
|
const execImport = await importChildProcess();
|
|
21
21
|
exec = execImport.exec;
|
|
22
22
|
}
|
|
23
|
-
catch (
|
|
23
|
+
catch (_e) {
|
|
24
24
|
// no-op
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
@@ -55,7 +55,7 @@ export const getDefaultRevisionId = async () => {
|
|
|
55
55
|
const execImport = await importChildProcess();
|
|
56
56
|
exec = execImport.exec;
|
|
57
57
|
}
|
|
58
|
-
catch (
|
|
58
|
+
catch (_e) {
|
|
59
59
|
// no-op
|
|
60
60
|
return null;
|
|
61
61
|
}
|
package/dist/utils/env.cjs
CHANGED
|
@@ -146,7 +146,7 @@ function getLangSmithEnvironmentVariables() {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
catch (
|
|
149
|
+
catch (_e) {
|
|
150
150
|
// Catch any errors that might occur while trying to access environment variables
|
|
151
151
|
}
|
|
152
152
|
return envVars;
|
|
@@ -160,7 +160,7 @@ function getEnvironmentVariable(name) {
|
|
|
160
160
|
process.env?.[name]
|
|
161
161
|
: undefined;
|
|
162
162
|
}
|
|
163
|
-
catch (
|
|
163
|
+
catch (_e) {
|
|
164
164
|
return undefined;
|
|
165
165
|
}
|
|
166
166
|
}
|
package/dist/utils/env.js
CHANGED
|
@@ -128,7 +128,7 @@ export function getLangSmithEnvironmentVariables() {
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
catch (
|
|
131
|
+
catch (_e) {
|
|
132
132
|
// Catch any errors that might occur while trying to access environment variables
|
|
133
133
|
}
|
|
134
134
|
return envVars;
|
|
@@ -142,7 +142,7 @@ export function getEnvironmentVariable(name) {
|
|
|
142
142
|
process.env?.[name]
|
|
143
143
|
: undefined;
|
|
144
144
|
}
|
|
145
|
-
catch (
|
|
145
|
+
catch (_e) {
|
|
146
146
|
return undefined;
|
|
147
147
|
}
|
|
148
148
|
}
|