@standardagents/builder 0.22.1 → 0.24.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 (33) hide show
  1. package/dist/built-in-routes.js +196 -58
  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 +66 -3
  28. package/dist/index.js.map +1 -1
  29. package/dist/runtime.d.ts +29 -0
  30. package/dist/runtime.js +66 -3
  31. package/dist/runtime.js.map +1 -1
  32. package/package.json +5 -5
  33. 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++) {
@@ -9410,7 +9410,7 @@ ${lines.join("\n\n")}`
9410
9410
  const base64Data = match[2];
9411
9411
  const ext = mimeType.split("/")[1] || "png";
9412
9412
  const attachmentId = crypto.randomUUID();
9413
- const path = `/attachments/${Date.now()}-${attachmentId}.${ext}`;
9413
+ const path = `/attachments/${Date.now()}-${attachmentId.slice(0, 8)}.${ext}`;
9414
9414
  try {
9415
9415
  await state.thread.instance.writeFile(path, base64Data, mimeType);
9416
9416
  if (image.id) {
@@ -9480,7 +9480,7 @@ ${lines.join("\n\n")}`
9480
9480
  const base64Data = imageUrl.slice(base64Index + base64Marker.length);
9481
9481
  const ext = mimeType.split("/")[1] || "png";
9482
9482
  const attachmentId = crypto.randomUUID();
9483
- const path = `/attachments/${Date.now()}-${attachmentId}.${ext}`;
9483
+ const path = `/attachments/${Date.now()}-${attachmentId.slice(0, 8)}.${ext}`;
9484
9484
  try {
9485
9485
  await state.thread.instance.writeFile(path, base64Data, mimeType);
9486
9486
  const attachmentRef = {
@@ -18252,6 +18252,38 @@ ${resultContent}${attachmentSummary}`;
18252
18252
  throw error;
18253
18253
  }
18254
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
+ }
18255
18287
  /**
18256
18288
  * Get specific logs, optionally including all descendant logs.
18257
18289
  */
@@ -21644,6 +21676,37 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
21644
21676
  created_at: row.created_at
21645
21677
  };
21646
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
+ }
21647
21710
  /**
21648
21711
  * List threads with optional filtering.
21649
21712
  * Note: tenvs are not decrypted in list operations for performance.