langwatch 1.11.0 → 1.12.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.
Files changed (34) hide show
  1. package/dist/agent/index.d.mts +7 -1
  2. package/dist/agent/index.d.ts +7 -1
  3. package/dist/agent/index.js +26 -1
  4. package/dist/agent/index.js.map +1 -1
  5. package/dist/agent/index.mjs +26 -1
  6. package/dist/agent/index.mjs.map +1 -1
  7. package/dist/{chunk-2PD3YA5H.js → chunk-3WIN2UXZ.js} +2 -2
  8. package/dist/{chunk-2PD3YA5H.js.map → chunk-3WIN2UXZ.js.map} +1 -1
  9. package/dist/{chunk-VMNKKJVI.mjs → chunk-BAE4KYKJ.mjs} +2 -2
  10. package/dist/{chunk-BS5CNZ5S.mjs → chunk-F5UYCQT3.mjs} +2 -2
  11. package/dist/{chunk-BS5CNZ5S.mjs.map → chunk-F5UYCQT3.mjs.map} +1 -1
  12. package/dist/{chunk-AJDFFRSW.js → chunk-QLYKPPAW.js} +12 -12
  13. package/dist/{chunk-AJDFFRSW.js.map → chunk-QLYKPPAW.js.map} +1 -1
  14. package/dist/cli/bundle.js +295 -217
  15. package/dist/{implementation-aczLxVpV.d.mts → implementation-BA3xa5UR.d.mts} +1 -1
  16. package/dist/{implementation-D58yPTJW.d.ts → implementation-rpImK8WS.d.ts} +1 -1
  17. package/dist/index.d.mts +55 -2
  18. package/dist/index.d.ts +55 -2
  19. package/dist/index.js +89 -33
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +58 -2
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/observability-sdk/index.d.mts +3 -3
  24. package/dist/observability-sdk/index.d.ts +3 -3
  25. package/dist/observability-sdk/index.js +2 -2
  26. package/dist/observability-sdk/index.mjs +1 -1
  27. package/dist/observability-sdk/instrumentation/langchain/index.d.mts +1 -1
  28. package/dist/observability-sdk/instrumentation/langchain/index.d.ts +1 -1
  29. package/dist/observability-sdk/setup/node/index.js +3 -3
  30. package/dist/observability-sdk/setup/node/index.mjs +2 -2
  31. package/dist/{types-D_YNU-VL.d.ts → types-Cr25FO-i.d.ts} +395 -293
  32. package/dist/{types-BmMuUDrO.d.mts → types-DJyJypkv.d.mts} +395 -293
  33. package/package.json +1 -1
  34. /package/dist/{chunk-VMNKKJVI.mjs.map → chunk-BAE4KYKJ.mjs.map} +0 -0
@@ -44,7 +44,7 @@ import * as os from "os";
44
44
  import { randomUUID } from "crypto";
45
45
 
46
46
  // package.json
47
- var version = "1.11.0";
47
+ var version = "1.12.0";
48
48
 
49
49
  // src/internal/constants.ts
50
50
  var LANGWATCH_SDK_VERSION = version;
@@ -1169,6 +1169,8 @@ var AgentClient = class {
1169
1169
  try {
1170
1170
  const result = await context.with(parent, () => runtime.run(call));
1171
1171
  if (entry.cancelled) return;
1172
+ this.releaseCall({ callId: frame.callId, entry });
1173
+ await this.flushSpans();
1172
1174
  this.send({
1173
1175
  type: "result",
1174
1176
  protocol: PROTOCOL_VERSION,
@@ -1181,11 +1183,34 @@ var AgentClient = class {
1181
1183
  const code = error instanceof AgentParameterError ? error.code : "agent_call_failed";
1182
1184
  const message = describeError(error);
1183
1185
  this.logger.warn(`agent "${runtime.name}" call ${frame.callId} failed: ${message}`);
1186
+ this.releaseCall({ callId: frame.callId, entry });
1187
+ await this.flushSpans();
1184
1188
  this.sendError({ callId: frame.callId, code, message });
1185
1189
  } finally {
1186
1190
  this.releaseCall({ callId: frame.callId, entry });
1187
1191
  }
1188
1192
  }
1193
+ /**
1194
+ * Exports the spans of the call now instead of at the exporter's next
1195
+ * schedule. The judge reads the agent's spans right after the last turn,
1196
+ * and a batch exporter would otherwise hold them for seconds, which is what
1197
+ * made the judge report the spans missing.
1198
+ *
1199
+ * The call awaits this before it sends its result or its error: the frame is
1200
+ * what tells the platform the turn is over, so a frame that goes out first
1201
+ * lets the judge read the call while its spans are still in the exporter.
1202
+ */
1203
+ async flushSpans() {
1204
+ const provider = trace.getTracerProvider();
1205
+ const delegate = typeof provider.getDelegate === "function" ? provider.getDelegate() : provider;
1206
+ const flush = delegate?.forceFlush;
1207
+ if (typeof flush !== "function") return;
1208
+ try {
1209
+ await flush.call(delegate);
1210
+ } catch (error) {
1211
+ this.logger.debug(`span flush after a call failed: ${describeError(error)}`);
1212
+ }
1213
+ }
1189
1214
  /** Frees the slot the call holds and drops its deadline timer. */
1190
1215
  releaseCall({ callId, entry }) {
1191
1216
  if (entry.timer) {