@standardagents/builder 0.22.0 → 0.23.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 (35) hide show
  1. package/dist/built-in-routes.js +175 -47
  2. package/dist/built-in-routes.js.map +1 -1
  3. package/dist/client/{ApiKeysView-N0JkbRqs.js → ApiKeysView-1m7uIS8S.js} +1 -1
  4. package/dist/client/{CenteredContentView-DTm87Sif.js → CenteredContentView-DJzHRMGj.js} +1 -1
  5. package/dist/client/{CompositionView-DnSaz1Nk.js → CompositionView-nzqzVKAg.js} +1 -1
  6. package/dist/client/{ConfirmDialog.vue_vue_type_script_setup_true_lang-DgfpzkTb.js → ConfirmDialog.vue_vue_type_script_setup_true_lang-YX8WE_iB.js} +1 -1
  7. package/dist/client/{CopyButton.vue_vue_type_script_setup_true_lang-DaO8fv5n.js → CopyButton.vue_vue_type_script_setup_true_lang-BpJt6BT0.js} +1 -1
  8. package/dist/client/{DataTable.vue_vue_type_script_setup_true_lang-CXfKtM8R.js → DataTable.vue_vue_type_script_setup_true_lang-Dg3HMMJ0.js} +1 -1
  9. package/dist/client/{JsonViewer-dnp9s6ji.js → JsonViewer-BdNA5OCG.js} +1 -1
  10. package/dist/client/{LoginView-C4vODzeq.js → LoginView-BlF_2TtB.js} +1 -1
  11. package/dist/client/{MarketplaceView-D4QuJAyk.js → MarketplaceView-DrlOb57k.js} +1 -1
  12. package/dist/client/{Modal.vue_vue_type_script_setup_true_lang-DbzeQ2-L.js → Modal.vue_vue_type_script_setup_true_lang-hkOmEwrb.js} +1 -1
  13. package/dist/client/{ModelModal.vue_vue_type_script_setup_true_lang-CNIgneiU.js → ModelModal.vue_vue_type_script_setup_true_lang-p3esoV-i.js} +1 -1
  14. package/dist/client/{ModelsView-CYQm6yLC.js → ModelsView-CHBanMSH.js} +1 -1
  15. package/dist/client/{PromptEditView-BAJoqY8N.js → PromptEditView-b5B43l4Q.js} +1 -1
  16. package/dist/client/{PromptModal-CFd4gHai.js → PromptModal-BF5bdmNQ.js} +1 -1
  17. package/dist/client/{PromptsView-DDapP7U-.js → PromptsView-6TfMOScI.js} +1 -1
  18. package/dist/client/{ProvidersView-D2g5wSI1.js → ProvidersView-CA5Yx2Fn.js} +1 -1
  19. package/dist/client/{ThreadInspectorPane.vue_vue_type_script_setup_true_lang-Cyvuox_G.js → ThreadInspectorPane.vue_vue_type_script_setup_true_lang-ejyFhmNy.js} +15 -15
  20. package/dist/client/{ThreadsView-Dc3lr6Au.js → ThreadsView-yJpVmf42.js} +1 -1
  21. package/dist/client/{ToolsView-C-marn6m.js → ToolsView-DE1TDnlU.js} +1 -1
  22. package/dist/client/{UsersView-D4j8izbK.js → UsersView-BXDHjJLB.js} +1 -1
  23. package/dist/client/{VariablesView-d3lOE_O2.js → VariablesView-Bz-CbaEv.js} +1 -1
  24. package/dist/client/assets/index-V68N0r_5.css +1 -0
  25. package/dist/client/{index-DR9DbKrm.js → index-TIntu1KJ.js} +2 -2
  26. package/dist/client/index.html +2 -2
  27. package/dist/index.js +106 -6
  28. package/dist/index.js.map +1 -1
  29. package/dist/plugin.js +8 -0
  30. package/dist/plugin.js.map +1 -1
  31. package/dist/runtime.d.ts +29 -0
  32. package/dist/runtime.js +98 -6
  33. package/dist/runtime.js.map +1 -1
  34. package/package.json +5 -5
  35. package/dist/client/assets/index-_JaOWezk.css +0 -1
package/dist/runtime.d.ts CHANGED
@@ -747,6 +747,21 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
747
747
  total: number;
748
748
  hasMore: boolean;
749
749
  }>;
750
+ /**
751
+ * This thread's OWN request-log cost summary (no descendants), aggregated
752
+ * in SQL so subtree cost reporting doesn't page full log rows out of every
753
+ * thread in the tree. Used by GET /api/threads/:id/cost, which merges these
754
+ * across the thread and all of its subagent descendants.
755
+ */
756
+ getCostSummary(): Promise<{
757
+ totalCost: number;
758
+ requestCount: number;
759
+ messageCount: number;
760
+ byModel: Record<string, {
761
+ totalCost: number;
762
+ count: number;
763
+ }>;
764
+ }>;
750
765
  /**
751
766
  * Get specific logs, optionally including all descendant logs.
752
767
  */
@@ -1622,6 +1637,20 @@ declare class DurableAgentBuilder<Env extends AgentBuilderEnv = AgentBuilderEnv>
1622
1637
  * Get a thread by ID.
1623
1638
  */
1624
1639
  getThread(id: string): Promise<ThreadRegistryEntry | null>;
1640
+ /**
1641
+ * All descendant threads of a root thread (children, grandchildren, …),
1642
+ * excluding the root itself. Used for subtree cost reporting: a thread's
1643
+ * displayed cost is its own plus every subagent thread it spawned,
1644
+ * recursively. Ordered parents-before-children (breadth by creation time).
1645
+ */
1646
+ getDescendantThreads(rootId: string): Promise<Array<{
1647
+ id: string;
1648
+ agent_name: string;
1649
+ parent: string | null;
1650
+ tags: string[] | null;
1651
+ terminated: number | null;
1652
+ created_at: number;
1653
+ }>>;
1625
1654
  /**
1626
1655
  * List threads with optional filtering.
1627
1656
  * Note: tenvs are not decrypted in list operations for performance.
package/dist/runtime.js CHANGED
@@ -5730,7 +5730,7 @@ ${attachmentPaths}`;
5730
5730
  const attachmentId = crypto.randomUUID();
5731
5731
  const timestamp = Date.now();
5732
5732
  const ext = attachment.mimeType === "image/png" ? "png" : attachment.mimeType === "image/jpeg" ? "jpg" : attachment.mimeType === "image/gif" ? "gif" : attachment.mimeType === "image/webp" ? "webp" : attachment.name.split(".").pop() || "bin";
5733
- const path = `/attachments/${timestamp}-${attachmentId}.${ext}`;
5733
+ const path = `/attachments/${timestamp}-${attachmentId.slice(0, 8)}.${ext}`;
5734
5734
  const binaryString = atob(attachment.data);
5735
5735
  const dataBuffer = new Uint8Array(binaryString.length);
5736
5736
  for (let i = 0; i < binaryString.length; i++) {
@@ -6057,9 +6057,10 @@ var init_context = __esm({
6057
6057
  // src/agents/FlowEngine.ts
6058
6058
  var FlowEngine_exports = {};
6059
6059
  __export(FlowEngine_exports, {
6060
- FlowEngine: () => FlowEngine
6060
+ FlowEngine: () => FlowEngine,
6061
+ HookBlockedExecutionError: () => HookBlockedExecutionError
6061
6062
  });
6062
- var IMMEDIATE_BOOTSTRAP_TOOL_NAME, FlowEngine;
6063
+ var IMMEDIATE_BOOTSTRAP_TOOL_NAME, HookBlockedExecutionError, FlowEngine;
6063
6064
  var init_FlowEngine = __esm({
6064
6065
  "src/agents/FlowEngine.ts"() {
6065
6066
  init_types();
@@ -6070,6 +6071,12 @@ var init_FlowEngine = __esm({
6070
6071
  init_sessionTools();
6071
6072
  init_ThreadStateImpl();
6072
6073
  IMMEDIATE_BOOTSTRAP_TOOL_NAME = "bootstrap_immediate_subagent";
6074
+ HookBlockedExecutionError = class extends Error {
6075
+ constructor(message) {
6076
+ super(message);
6077
+ this.name = "HookBlockedExecutionError";
6078
+ }
6079
+ };
6073
6080
  FlowEngine = class _FlowEngine {
6074
6081
  static IMMEDIATE_SCOPED_ENV_CONTEXT_KEY = "__immediate_scoped_env_by_call_id";
6075
6082
  /**
@@ -6617,7 +6624,26 @@ This usually points to something I can't fix from here \u2014 for example the wo
6617
6624
  state.messageHistory = await this.loadMessageHistory(state);
6618
6625
  const context = await this.assembleContext(state);
6619
6626
  state.allowedTools = context.tools;
6620
- context.messages = await this.runPrefilterLLMHistoryHook(state, context.messages);
6627
+ try {
6628
+ context.messages = await this.runPrefilterLLMHistoryHook(state, context.messages);
6629
+ } catch (error) {
6630
+ if (error instanceof HookBlockedExecutionError) {
6631
+ const threadState = ThreadStateImpl.fromFlowState(state);
6632
+ await threadState.injectMessage({ role: "assistant", content: error.message });
6633
+ state.stopped = true;
6634
+ state.stoppedBy = state.currentSide;
6635
+ state.stopReason = error.message;
6636
+ state.stopReasonCode = "hook_blocked";
6637
+ state.emitTelemetry?.({
6638
+ type: "stopped",
6639
+ reason: state.stopReason,
6640
+ side: state.currentSide,
6641
+ timestamp: Date.now()
6642
+ });
6643
+ return;
6644
+ }
6645
+ throw error;
6646
+ }
6621
6647
  const pendingMessageId = await this.createPendingMessage(state);
6622
6648
  state.pendingMessageId = pendingMessageId;
6623
6649
  let responseStatus = "completed";
@@ -8773,6 +8799,9 @@ ${lines.join("\n\n")}`
8773
8799
  try {
8774
8800
  result = await executor(threadState, result);
8775
8801
  } catch (error) {
8802
+ if (error && typeof error === "object" && error.block === true) {
8803
+ throw new HookBlockedExecutionError(error instanceof Error ? error.message : String(error));
8804
+ }
8776
8805
  console.error("[Hooks] \u2717 Error running prefilter_llm_history hook:", error);
8777
8806
  }
8778
8807
  }
@@ -9381,7 +9410,7 @@ ${lines.join("\n\n")}`
9381
9410
  const base64Data = match[2];
9382
9411
  const ext = mimeType.split("/")[1] || "png";
9383
9412
  const attachmentId = crypto.randomUUID();
9384
- const path = `/attachments/${Date.now()}-${attachmentId}.${ext}`;
9413
+ const path = `/attachments/${Date.now()}-${attachmentId.slice(0, 8)}.${ext}`;
9385
9414
  try {
9386
9415
  await state.thread.instance.writeFile(path, base64Data, mimeType);
9387
9416
  if (image.id) {
@@ -9451,7 +9480,7 @@ ${lines.join("\n\n")}`
9451
9480
  const base64Data = imageUrl.slice(base64Index + base64Marker.length);
9452
9481
  const ext = mimeType.split("/")[1] || "png";
9453
9482
  const attachmentId = crypto.randomUUID();
9454
- const path = `/attachments/${Date.now()}-${attachmentId}.${ext}`;
9483
+ const path = `/attachments/${Date.now()}-${attachmentId.slice(0, 8)}.${ext}`;
9455
9484
  try {
9456
9485
  await state.thread.instance.writeFile(path, base64Data, mimeType);
9457
9486
  const attachmentRef = {
@@ -18223,6 +18252,38 @@ ${resultContent}${attachmentSummary}`;
18223
18252
  throw error;
18224
18253
  }
18225
18254
  }
18255
+ /**
18256
+ * This thread's OWN request-log cost summary (no descendants), aggregated
18257
+ * in SQL so subtree cost reporting doesn't page full log rows out of every
18258
+ * thread in the tree. Used by GET /api/threads/:id/cost, which merges these
18259
+ * across the thread and all of its subagent descendants.
18260
+ */
18261
+ async getCostSummary() {
18262
+ await this.ensureMigrated();
18263
+ const byModel = {};
18264
+ let totalCost = 0;
18265
+ let requestCount = 0;
18266
+ const modelRows = await this.ctx.storage.sql.exec(
18267
+ `
18268
+ SELECT COALESCE(model_name, model, 'unknown') AS model_key,
18269
+ SUM(cost_total) AS total_cost,
18270
+ COUNT(*) AS request_count
18271
+ FROM logs
18272
+ WHERE cost_total IS NOT NULL
18273
+ GROUP BY model_key
18274
+ `
18275
+ );
18276
+ for (const row of modelRows.toArray()) {
18277
+ byModel[row.model_key] = { totalCost: row.total_cost, count: row.request_count };
18278
+ totalCost += row.total_cost;
18279
+ requestCount += row.request_count;
18280
+ }
18281
+ const messageRow = await this.ctx.storage.sql.exec(
18282
+ `SELECT COUNT(DISTINCT message_id) AS message_count FROM logs WHERE cost_total IS NOT NULL`
18283
+ );
18284
+ const messageCount = messageRow.one().message_count || 0;
18285
+ return { totalCost, requestCount, messageCount, byModel };
18286
+ }
18226
18287
  /**
18227
18288
  * Get specific logs, optionally including all descendant logs.
18228
18289
  */
@@ -21615,6 +21676,37 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
21615
21676
  created_at: row.created_at
21616
21677
  };
21617
21678
  }
21679
+ /**
21680
+ * All descendant threads of a root thread (children, grandchildren, …),
21681
+ * excluding the root itself. Used for subtree cost reporting: a thread's
21682
+ * displayed cost is its own plus every subagent thread it spawned,
21683
+ * recursively. Ordered parents-before-children (breadth by creation time).
21684
+ */
21685
+ async getDescendantThreads(rootId) {
21686
+ await this.ensureMigrated();
21687
+ const cursor = await this.ctx.storage.sql.exec(
21688
+ `
21689
+ WITH RECURSIVE descendants(id) AS (
21690
+ SELECT id FROM threads WHERE parent = ?
21691
+ UNION ALL
21692
+ SELECT t.id FROM threads t JOIN descendants d ON t.parent = d.id
21693
+ )
21694
+ SELECT id, agent_name, parent, tags, terminated, created_at
21695
+ FROM threads
21696
+ WHERE id IN (SELECT id FROM descendants)
21697
+ ORDER BY created_at ASC
21698
+ `,
21699
+ rootId
21700
+ );
21701
+ return cursor.toArray().map((row) => ({
21702
+ id: row.id,
21703
+ agent_name: row.agent_name,
21704
+ parent: row.parent,
21705
+ tags: row.tags ? JSON.parse(row.tags) : null,
21706
+ terminated: row.terminated,
21707
+ created_at: row.created_at
21708
+ }));
21709
+ }
21618
21710
  /**
21619
21711
  * List threads with optional filtering.
21620
21712
  * Note: tenvs are not decrypted in list operations for performance.