@standardagents/builder 0.37.7 → 0.38.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.
@@ -9431,7 +9431,12 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
9431
9431
  const threadState = ThreadStateImpl.fromFlowState(state);
9432
9432
  for (const executor of executors) {
9433
9433
  try {
9434
- result = await executor(threadState, result);
9434
+ const hooked = await executor(threadState, _FlowEngine.rowToHookMessage(result));
9435
+ result = {
9436
+ ...result,
9437
+ ...hooked,
9438
+ attachments: hooked.attachments === void 0 ? result.attachments : hooked.attachments === null ? null : typeof hooked.attachments === "string" ? hooked.attachments : JSON.stringify(hooked.attachments)
9439
+ };
9435
9440
  } catch (error) {
9436
9441
  console.error("[Hooks] \u2717 Error running before_create_message hook:", error);
9437
9442
  }
@@ -9451,12 +9456,31 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
9451
9456
  const threadState = ThreadStateImpl.fromFlowState(state);
9452
9457
  for (const executor of executors) {
9453
9458
  try {
9454
- await executor(threadState, message);
9459
+ await executor(threadState, _FlowEngine.rowToHookMessage(message));
9455
9460
  } catch (error) {
9456
9461
  console.error("[Hooks] \u2717 Error running after_create_message hook:", error);
9457
9462
  }
9458
9463
  }
9459
9464
  }
9465
+ /**
9466
+ * Builder rows store `attachments` as a JSON string; the spec hook surface
9467
+ * carries parsed AttachmentRef[]. Convert at every hook boundary so hooks
9468
+ * see the spec shape and cannot corrupt the stored row shape.
9469
+ */
9470
+ static rowToHookMessage(row) {
9471
+ const { attachments, ...rest } = row;
9472
+ let parsed = void 0;
9473
+ if (attachments === null) parsed = null;
9474
+ else if (typeof attachments === "string" && attachments) {
9475
+ try {
9476
+ const p = JSON.parse(attachments);
9477
+ parsed = Array.isArray(p) ? p : void 0;
9478
+ } catch {
9479
+ parsed = void 0;
9480
+ }
9481
+ }
9482
+ return { ...rest, attachments: parsed };
9483
+ }
9460
9484
  /**
9461
9485
  * Run the before_update_message hook if it exists
9462
9486
  * This hook allows developers to modify a message before it's updated
@@ -9495,7 +9519,7 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
9495
9519
  const threadState = ThreadStateImpl.fromFlowState(state);
9496
9520
  for (const executor of executors) {
9497
9521
  try {
9498
- await executor(threadState, message);
9522
+ await executor(threadState, _FlowEngine.rowToHookMessage(message));
9499
9523
  } catch (error) {
9500
9524
  console.error("[Hooks] \u2717 Error running after_update_message hook:", error);
9501
9525
  }
@@ -10584,7 +10608,11 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
10584
10608
  const threadState = ThreadStateImpl.fromFlowState(state);
10585
10609
  for (const executor of executors) {
10586
10610
  try {
10587
- result = await executor(threadState, result);
10611
+ const byId = /* @__PURE__ */ new Map();
10612
+ for (const row of result) if (row.id) byId.set(row.id, row);
10613
+ const hookView = result.map((row) => _FlowEngine.rowToHookMessage(row));
10614
+ const kept = await executor(threadState, hookView);
10615
+ result = kept.map((m) => m.id && byId.get(m.id) || null).filter((row) => row !== null);
10588
10616
  } catch (error) {
10589
10617
  console.error("[Hooks] \u2717 Error running filter_messages hook:", error);
10590
10618
  }
@@ -13882,9 +13910,25 @@ var init_ThreadStateImpl = __esm({
13882
13910
  parent_id: msg.parent_id,
13883
13911
  depth: msg.depth,
13884
13912
  silent: msg.silent,
13885
- metadata: msg.metadata
13913
+ metadata: msg.metadata,
13914
+ status: msg.status,
13915
+ tool_status: msg.tool_status,
13916
+ attachments: this._parseAttachmentRefs(msg.attachments)
13886
13917
  };
13887
13918
  };
13919
+ /** Builder rows store attachments as a JSON string of AttachmentRef[];
13920
+ * spec messages carry the parsed refs. Dropping them here is what made
13921
+ * generated assets invisible to every session_state consumer. */
13922
+ _parseAttachmentRefs = (raw) => {
13923
+ if (!raw) return void 0;
13924
+ if (Array.isArray(raw)) return raw;
13925
+ try {
13926
+ const parsed = JSON.parse(raw);
13927
+ return Array.isArray(parsed) ? parsed : void 0;
13928
+ } catch {
13929
+ return void 0;
13930
+ }
13931
+ };
13888
13932
  _mapFileRecord = (record24) => {
13889
13933
  return {
13890
13934
  path: record24.path,
@@ -67006,111 +67050,6 @@ function getParamRegexp(segment) {
67006
67050
 
67007
67051
  // src/router/index.ts
67008
67052
  init_ThreadStateImpl();
67009
- function defineController2(controller) {
67010
- return controller;
67011
- }
67012
-
67013
- // src/api/index.post.ts
67014
- var index_post_default = defineController2(() => {
67015
- const stream = new ReadableStream({
67016
- start(controller) {
67017
- const text2 = "hello world";
67018
- let index = 0;
67019
- const next = () => {
67020
- if (index < text2.length) {
67021
- controller.enqueue(new TextEncoder().encode(text2[index]));
67022
- index++;
67023
- setTimeout(next, 100);
67024
- } else {
67025
- controller.close();
67026
- }
67027
- };
67028
- next();
67029
- }
67030
- });
67031
- return new Response(stream);
67032
- });
67033
-
67034
- // src/api/agents.get.ts
67035
- var agents_get_default = defineController2(async ({ agents, agentNames, registry, auth }) => {
67036
- const includeAuthoringDetails = auth?.user.role === "admin";
67037
- const agentList = [];
67038
- console.log("[agents.get] Registry packages:", registry?.packages ? Object.keys(registry.packages) : "undefined");
67039
- if (agents && agentNames) {
67040
- const globalAgents = await Promise.all(
67041
- agentNames.map(async (name15) => {
67042
- try {
67043
- const loader = agents[name15];
67044
- if (!loader) {
67045
- return null;
67046
- }
67047
- const definition = await loader();
67048
- return {
67049
- id: definition.name,
67050
- name: definition.name,
67051
- title: definition.title || definition.name,
67052
- type: definition.type || "ai_human",
67053
- description: definition.description || null,
67054
- icon: definition.icon || null,
67055
- primary: definition.primary !== false,
67056
- ...includeAuthoringDetails ? {
67057
- default_prompt: definition.sideA?.prompt || "",
67058
- default_model: "",
67059
- tools: [],
67060
- side_a_label: definition.sideA?.label || null,
67061
- side_a_agent_prompt: definition.sideA?.prompt || null,
67062
- side_b_label: definition.sideB?.label || null,
67063
- side_b_agent_prompt: definition.sideB?.prompt || null,
67064
- env: definition.env || null
67065
- } : {},
67066
- created_at: Math.floor(Date.now() / 1e3),
67067
- packed: false
67068
- };
67069
- } catch (error) {
67070
- console.error(`Error loading agent ${name15}:`, error);
67071
- return null;
67072
- }
67073
- })
67074
- );
67075
- agentList.push(...globalAgents);
67076
- }
67077
- if (registry?.packages) {
67078
- for (const [packageId, pkg] of Object.entries(registry.packages)) {
67079
- const packageData = pkg;
67080
- for (const agentName of packageData.entryAgents) {
67081
- try {
67082
- const loader = packageData.agents[agentName];
67083
- if (!loader) continue;
67084
- const definition = await loader();
67085
- agentList.push({
67086
- id: `${packageId}/${definition.name}`,
67087
- name: definition.name,
67088
- title: definition.title || definition.name,
67089
- type: definition.type || "ai_human",
67090
- description: definition.description || null,
67091
- icon: definition.icon || null,
67092
- primary: definition.primary !== false,
67093
- ...includeAuthoringDetails ? {
67094
- default_prompt: definition.sideA?.prompt || "",
67095
- default_model: "",
67096
- tools: [],
67097
- side_a_agent_prompt: definition.sideA?.prompt ? definition.sideA.prompt.includes("/") ? definition.sideA.prompt : `${packageId}/${definition.sideA.prompt}` : null,
67098
- side_b_agent_prompt: definition.sideB?.prompt ? definition.sideB.prompt.includes("/") ? definition.sideB.prompt : `${packageId}/${definition.sideB.prompt}` : null
67099
- } : {},
67100
- created_at: Math.floor(Date.now() / 1e3),
67101
- packed: true,
67102
- packageId,
67103
- source: packageData.signature.source
67104
- });
67105
- } catch (error) {
67106
- console.error(`Error loading packed agent ${agentName} from ${packageId}:`, error);
67107
- }
67108
- }
67109
- }
67110
- }
67111
- const validAgents = agentList.filter(Boolean);
67112
- return Response.json({ agents: validAgents });
67113
- });
67114
67053
 
67115
67054
  // src/utils/auth.ts
67116
67055
  function generateSecureToken(length = 32) {
@@ -67481,6 +67420,111 @@ async function requireAdmin(request, env2) {
67481
67420
  }
67482
67421
  return result;
67483
67422
  }
67423
+ function defineController2(controller) {
67424
+ return controller;
67425
+ }
67426
+
67427
+ // src/api/index.post.ts
67428
+ var index_post_default = defineController2(() => {
67429
+ const stream = new ReadableStream({
67430
+ start(controller) {
67431
+ const text2 = "hello world";
67432
+ let index = 0;
67433
+ const next = () => {
67434
+ if (index < text2.length) {
67435
+ controller.enqueue(new TextEncoder().encode(text2[index]));
67436
+ index++;
67437
+ setTimeout(next, 100);
67438
+ } else {
67439
+ controller.close();
67440
+ }
67441
+ };
67442
+ next();
67443
+ }
67444
+ });
67445
+ return new Response(stream);
67446
+ });
67447
+
67448
+ // src/api/agents.get.ts
67449
+ var agents_get_default = defineController2(async ({ agents, agentNames, registry, auth }) => {
67450
+ const includeAuthoringDetails = auth?.user.role === "admin";
67451
+ const agentList = [];
67452
+ console.log("[agents.get] Registry packages:", registry?.packages ? Object.keys(registry.packages) : "undefined");
67453
+ if (agents && agentNames) {
67454
+ const globalAgents = await Promise.all(
67455
+ agentNames.map(async (name15) => {
67456
+ try {
67457
+ const loader = agents[name15];
67458
+ if (!loader) {
67459
+ return null;
67460
+ }
67461
+ const definition = await loader();
67462
+ return {
67463
+ id: definition.name,
67464
+ name: definition.name,
67465
+ title: definition.title || definition.name,
67466
+ type: definition.type || "ai_human",
67467
+ description: definition.description || null,
67468
+ icon: definition.icon || null,
67469
+ primary: definition.primary !== false,
67470
+ ...includeAuthoringDetails ? {
67471
+ default_prompt: definition.sideA?.prompt || "",
67472
+ default_model: "",
67473
+ tools: [],
67474
+ side_a_label: definition.sideA?.label || null,
67475
+ side_a_agent_prompt: definition.sideA?.prompt || null,
67476
+ side_b_label: definition.sideB?.label || null,
67477
+ side_b_agent_prompt: definition.sideB?.prompt || null,
67478
+ env: definition.env || null
67479
+ } : {},
67480
+ created_at: Math.floor(Date.now() / 1e3),
67481
+ packed: false
67482
+ };
67483
+ } catch (error) {
67484
+ console.error(`Error loading agent ${name15}:`, error);
67485
+ return null;
67486
+ }
67487
+ })
67488
+ );
67489
+ agentList.push(...globalAgents);
67490
+ }
67491
+ if (registry?.packages) {
67492
+ for (const [packageId, pkg] of Object.entries(registry.packages)) {
67493
+ const packageData = pkg;
67494
+ for (const agentName of packageData.entryAgents) {
67495
+ try {
67496
+ const loader = packageData.agents[agentName];
67497
+ if (!loader) continue;
67498
+ const definition = await loader();
67499
+ agentList.push({
67500
+ id: `${packageId}/${definition.name}`,
67501
+ name: definition.name,
67502
+ title: definition.title || definition.name,
67503
+ type: definition.type || "ai_human",
67504
+ description: definition.description || null,
67505
+ icon: definition.icon || null,
67506
+ primary: definition.primary !== false,
67507
+ ...includeAuthoringDetails ? {
67508
+ default_prompt: definition.sideA?.prompt || "",
67509
+ default_model: "",
67510
+ tools: [],
67511
+ side_a_agent_prompt: definition.sideA?.prompt ? definition.sideA.prompt.includes("/") ? definition.sideA.prompt : `${packageId}/${definition.sideA.prompt}` : null,
67512
+ side_b_agent_prompt: definition.sideB?.prompt ? definition.sideB.prompt.includes("/") ? definition.sideB.prompt : `${packageId}/${definition.sideB.prompt}` : null
67513
+ } : {},
67514
+ created_at: Math.floor(Date.now() / 1e3),
67515
+ packed: true,
67516
+ packageId,
67517
+ source: packageData.signature.source
67518
+ });
67519
+ } catch (error) {
67520
+ console.error(`Error loading packed agent ${agentName} from ${packageId}:`, error);
67521
+ }
67522
+ }
67523
+ }
67524
+ }
67525
+ const validAgents = agentList.filter(Boolean);
67526
+ return Response.json({ agents: validAgents });
67527
+ });
67484
67528
 
67485
67529
  // src/routing/access-policy.ts
67486
67530
  function isHostedInstance(env2) {
@@ -67987,7 +68031,7 @@ var config_get_default = defineController2(async ({ config, env: env2, req }) =>
67987
68031
  });
67988
68032
 
67989
68033
  // src/version.ts
67990
- var BUILDER_VERSION = "0.37.7".length > 0 ? "0.37.7" : "dev";
68034
+ var BUILDER_VERSION = "0.38.0".length > 0 ? "0.38.0" : "dev";
67991
68035
 
67992
68036
  // src/api/diagnostics.get.ts
67993
68037
  init_LLMRequest();
@@ -75605,76 +75649,6 @@ var messageId_patch_default = defineController2(async ({ req, params, env: env2
75605
75649
  }
75606
75650
  });
75607
75651
 
75608
- // src/api/threads/[id]/public/[...path].ts
75609
- var path_default4 = defineController2(async ({ req, params, env: env2 }) => {
75610
- if (req.method !== "GET" && req.method !== "HEAD") {
75611
- return Response.json({ error: "Method not allowed" }, { status: 405 });
75612
- }
75613
- const threadId = params.id;
75614
- if (!threadId) {
75615
- return Response.json({ error: "Thread ID required" }, { status: 400 });
75616
- }
75617
- const rawPathParam = params._ || params.path || params["*"] || "";
75618
- const relative4 = rawPathParam === "public" ? "" : rawPathParam.replace(/^\/?public\//, "");
75619
- const segments = [];
75620
- for (const part of relative4.replace(/\\/g, "/").split("/")) {
75621
- if (!part || part === ".") continue;
75622
- if (part === "..") return notFound();
75623
- segments.push(part);
75624
- }
75625
- if (segments.length === 0) return notFound();
75626
- const path10 = `/public/${segments.join("/")}`;
75627
- try {
75628
- const durableId = env2.AGENT_BUILDER_THREAD.idFromName(threadId);
75629
- const stub = env2.AGENT_BUILDER_THREAD.get(durableId);
75630
- const statResult = await stub.statFile(path10);
75631
- if (!statResult?.success) return notFound();
75632
- const file = statResult.file;
75633
- if (!file || file.isDirectory || file.storage !== "local") return notFound();
75634
- const headers = {
75635
- "Content-Type": file.mimeType || "application/octet-stream",
75636
- "Content-Length": String(file.size),
75637
- "Content-Disposition": `inline; filename="${file.name}"`,
75638
- // Public files are mutable (unlike content-addressed assets): cache
75639
- // briefly so shares are fast without pinning stale content for a year.
75640
- "Cache-Control": "public, max-age=300"
75641
- };
75642
- if (req.method === "HEAD") return new Response(null, { headers });
75643
- if (file.isChunked && file.chunkCount) {
75644
- const { readable, writable } = new TransformStream();
75645
- const writer = writable.getWriter();
75646
- (async () => {
75647
- try {
75648
- for (let i = 0; i < file.chunkCount; i++) {
75649
- const chunk = await stub.readFileChunk(path10, i);
75650
- if (!chunk?.success) break;
75651
- const binary2 = atob(chunk.data);
75652
- const bytes2 = new Uint8Array(binary2.length);
75653
- for (let j = 0; j < binary2.length; j++) bytes2[j] = binary2.charCodeAt(j);
75654
- await writer.write(bytes2);
75655
- }
75656
- } finally {
75657
- await writer.close().catch(() => {
75658
- });
75659
- }
75660
- })();
75661
- return new Response(readable, { headers });
75662
- }
75663
- const result = await stub.readFile(path10);
75664
- if (!result?.success) return notFound();
75665
- const binary = atob(result.data);
75666
- const bytes = new Uint8Array(binary.length);
75667
- for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
75668
- return new Response(bytes, { headers });
75669
- } catch (error) {
75670
- console.error(`Error serving public file for thread ${threadId}:`, error);
75671
- return notFound();
75672
- }
75673
- });
75674
- function notFound() {
75675
- return Response.json({ error: "Not found" }, { status: 404 });
75676
- }
75677
-
75678
75652
  // src/api/threads/[id]/variables/[requestId].get.ts
75679
75653
  var requestId_get_default = defineController2(async ({ req, params, env: env2 }) => {
75680
75654
  const authResult = await requireAuth(req, env2);
@@ -76319,7 +76293,6 @@ var routeHandlers = {
76319
76293
  "GET:/threads/:id/logs/:logId": logId_get_default,
76320
76294
  "DELETE:/threads/:id/messages/:messageId": messageId_delete_default,
76321
76295
  "PATCH:/threads/:id/messages/:messageId": messageId_patch_default,
76322
- "GET:/threads/:id/public/**": path_default4,
76323
76296
  "GET:/threads/:id/variables/:requestId": requestId_get_default,
76324
76297
  "POST:/threads/:id/variables/:requestId": requestId_post_default,
76325
76298
  "POST:/threads/:id/effects/:effectId/cancel": cancel_post_default,