@axlsdk/studio 0.19.0 → 0.20.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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createServer,
3
3
  handleWsMessage
4
- } from "./chunk-S6HQOGOQ.js";
4
+ } from "./chunk-KQ3HBRTC.js";
5
5
 
6
6
  // src/middleware.ts
7
7
  import { resolve as resolve2, dirname } from "path";
@@ -51,8 +51,7 @@ var SAFE_ERROR_NAMES = /* @__PURE__ */ new Set([
51
51
  "NoConsensus",
52
52
  "TimeoutError",
53
53
  "MaxTurnsError",
54
- "BudgetExceededError",
55
- "ToolDenied"
54
+ "BudgetExceededError"
56
55
  ]);
57
56
  function redactErrorMessage(err, redact) {
58
57
  const raw = err instanceof Error ? err.message : String(err);
@@ -120,7 +119,7 @@ function redactSessionHistory(history, redact) {
120
119
  }
121
120
  function redactStreamEvent(event, redact) {
122
121
  if (!redact) return event;
123
- return (0, import_axl.redactEvent)(event);
122
+ return (0, import_axl.redactHistoricalEvent)(event);
124
123
  }
125
124
  function redactEvalItem(item) {
126
125
  const scrubbed = {
@@ -183,31 +182,29 @@ function redactPendingDecisionList(decisions, redact) {
183
182
  }
184
183
 
185
184
  // src/server/middleware/error-handler.ts
186
- async function errorHandler(c, next) {
187
- try {
188
- await next();
189
- } catch (err) {
190
- const rawMessage = err instanceof Error ? err.message : String(err);
191
- const code = err.code ?? "INTERNAL_ERROR";
192
- let status = 500;
193
- if ("status" in err) {
194
- const errStatus = err.status;
195
- if (typeof errStatus === "number" && errStatus >= 400 && errStatus < 600) {
196
- status = errStatus;
197
- }
198
- } else if (code === "NOT_FOUND" || rawMessage.includes("not found") || rawMessage.includes("not registered")) {
199
- status = 404;
200
- } else if (code === "VALIDATION_ERROR" || rawMessage.includes("Expected") || rawMessage.includes("invalid")) {
201
- status = 400;
202
- }
203
- const runtime = c.get("runtime");
204
- const redactOn = runtime?.isRedactEnabled?.() ?? false;
205
- const body = {
206
- ok: false,
207
- error: { code, message: redactErrorMessage(err, redactOn) }
208
- };
209
- return c.json(body, status);
185
+ function errorHandler(err, c) {
186
+ const rawMessage = err.message;
187
+ const code = err.code ?? "INTERNAL_ERROR";
188
+ let status = 500;
189
+ if ("status" in err) {
190
+ const errStatus = err.status;
191
+ if (typeof errStatus === "number" && errStatus >= 400 && errStatus < 600) {
192
+ status = errStatus;
193
+ }
194
+ } else if (code === "CROSS_PROCESS_RESUME_UNSUPPORTED") {
195
+ status = 409;
196
+ } else if (code === "NOT_FOUND" || code === "PENDING_DECISION_NOT_FOUND" || rawMessage.includes("not found") || rawMessage.includes("not registered")) {
197
+ status = 404;
198
+ } else if (code === "VALIDATION_ERROR" || code === "INVALID_HUMAN_DECISION" || rawMessage.includes("Expected") || rawMessage.includes("invalid")) {
199
+ status = 400;
210
200
  }
201
+ const runtime = c.get("runtime");
202
+ const redactOn = runtime?.isRedactEnabled?.() ?? false;
203
+ const body = {
204
+ ok: false,
205
+ error: { code, message: redactErrorMessage(err, redactOn) }
206
+ };
207
+ return c.json(body, status);
211
208
  }
212
209
 
213
210
  // src/server/ws/connection-manager.ts
@@ -1123,19 +1120,58 @@ function reduceTraceStats(acc, event) {
1123
1120
  const eventTypeCounts = { ...acc.eventTypeCounts };
1124
1121
  eventTypeCounts[event.type] = (eventTypeCounts[event.type] ?? 0) + 1;
1125
1122
  const byTool = { ...acc.byTool };
1126
- if (event.type === "tool_call_end" || event.type === "tool_denied" || event.type === "tool_approval") {
1123
+ if (event.type === "tool_call_start" || event.type === "tool_call_end" || event.type === "tool_call_rejected" || event.type === "tool_denied" || event.type === "tool_approval") {
1127
1124
  const toolName = event.tool;
1128
- const prev = byTool[toolName] ?? { calls: 0, denied: 0, approved: 0 };
1129
- const isDeniedEvent = event.type === "tool_denied";
1130
- const isApprovalEvent = event.type === "tool_approval";
1131
- const eventData = isDeniedEvent || isApprovalEvent ? event.data : void 0;
1132
- const isApproved = isDeniedEvent && eventData?.approved === true || isApprovalEvent && eventData?.approved === true;
1133
- const isDenied = isDeniedEvent && !eventData?.approved || isApprovalEvent && eventData?.approved === false;
1134
- byTool[toolName] = {
1135
- calls: prev.calls + (event.type === "tool_call_end" ? 1 : 0),
1136
- denied: prev.denied + (isDenied ? 1 : 0),
1137
- approved: prev.approved + (isApproved ? 1 : 0)
1125
+ const prev = byTool[toolName] ?? {
1126
+ accepted: 0,
1127
+ succeeded: 0,
1128
+ failed: 0,
1129
+ failedByPhase: {},
1130
+ denied: 0,
1131
+ cancelled: 0,
1132
+ rejected: 0,
1133
+ approved: 0,
1134
+ legacy: { calls: 0, denied: 0, approved: 0 }
1135
+ };
1136
+ const next = {
1137
+ ...prev,
1138
+ failedByPhase: { ...prev.failedByPhase },
1139
+ legacy: { ...prev.legacy }
1138
1140
  };
1141
+ if (event.schemaVersion === 2) {
1142
+ if (event.type === "tool_call_start") next.accepted++;
1143
+ if (event.type === "tool_call_rejected") next.rejected++;
1144
+ if (event.type === "tool_approval" && event.data?.approved) next.approved++;
1145
+ if (event.type === "tool_call_end") {
1146
+ switch (event.data.outcome.status) {
1147
+ case "succeeded":
1148
+ next.succeeded++;
1149
+ break;
1150
+ case "failed": {
1151
+ next.failed++;
1152
+ const phase = event.data.outcome.failure.phase;
1153
+ next.failedByPhase[phase] = (next.failedByPhase[phase] ?? 0) + 1;
1154
+ break;
1155
+ }
1156
+ case "denied":
1157
+ next.denied++;
1158
+ break;
1159
+ case "cancelled":
1160
+ next.cancelled++;
1161
+ break;
1162
+ }
1163
+ }
1164
+ } else if (event.type === "tool_call_end") {
1165
+ next.legacy.calls++;
1166
+ } else if (event.type === "tool_denied") {
1167
+ const approved = event.data?.approved === true;
1168
+ if (approved) next.legacy.approved++;
1169
+ else next.legacy.denied++;
1170
+ } else if (event.type === "tool_approval") {
1171
+ if (event.data?.approved === true) next.legacy.approved++;
1172
+ else if (event.data?.approved === false) next.legacy.denied++;
1173
+ }
1174
+ byTool[toolName] = next;
1139
1175
  }
1140
1176
  const retryByAgent = { ...acc.retryByAgent };
1141
1177
  if (event.agent && event.type === "agent_call_end") {
@@ -1615,7 +1651,14 @@ app4.get("/decisions", async (c) => {
1615
1651
  app4.post("/decisions/:executionId/resolve", async (c) => {
1616
1652
  const runtime = c.get("runtime");
1617
1653
  const executionId = c.req.param("executionId");
1618
- const body = await c.req.json();
1654
+ let body;
1655
+ try {
1656
+ body = await c.req.json();
1657
+ } catch {
1658
+ const error48 = new Error("Invalid JSON request body");
1659
+ Object.assign(error48, { code: "INVALID_HUMAN_DECISION", status: 400 });
1660
+ throw error48;
1661
+ }
1619
1662
  await runtime.resolveDecision(executionId, body);
1620
1663
  return c.json({ ok: true, data: { resolved: true } });
1621
1664
  });
@@ -15955,6 +15998,7 @@ function createPlaygroundRoutes(connMgr) {
15955
15998
  (async () => {
15956
15999
  let stepCounter = Number.MAX_SAFE_INTEGER - 1;
15957
16000
  const terminalFields = () => ({
16001
+ schemaVersion: 2,
15958
16002
  executionId,
15959
16003
  step: stepCounter++,
15960
16004
  timestamp: Date.now()
@@ -16071,7 +16115,7 @@ function createServer(options) {
16071
16115
  if (options.cors !== false) {
16072
16116
  app5.use("*", (0, import_cors.cors)());
16073
16117
  }
16074
- app5.use("*", errorHandler);
16118
+ app5.onError(errorHandler);
16075
16119
  app5.use("*", async (c, next) => {
16076
16120
  c.set("runtime", runtime);
16077
16121
  await next();