@standardagents/builder 0.37.4 → 0.37.6

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 (53) hide show
  1. package/dist/built-in-routes.js +184 -83
  2. package/dist/built-in-routes.js.map +1 -1
  3. package/dist/client/{ApiKeysView-BhuT3pIF.js → ApiKeysView-Pk5oljVU.js} +1 -1
  4. package/dist/client/CenteredContentView-HGpMGAQj.js +1 -0
  5. package/dist/client/CompositionView-DN8dTOCO.js +32 -0
  6. package/dist/client/{ConfirmDialog.vue_vue_type_script_setup_true_lang-BqwwsXWJ.js → ConfirmDialog.vue_vue_type_script_setup_true_lang--j_hnMZ0.js} +1 -1
  7. package/dist/client/{CopyButton.vue_vue_type_script_setup_true_lang-Cqm3Vt3E.js → CopyButton.vue_vue_type_script_setup_true_lang-CpJDcbZx.js} +1 -1
  8. package/dist/client/{DataTable.vue_vue_type_script_setup_true_lang-CA5qgsty.js → DataTable.vue_vue_type_script_setup_true_lang-unLrY-PY.js} +1 -1
  9. package/dist/client/{JsonViewer-ByQKCShF.js → JsonViewer-BYj_yrGB.js} +1 -1
  10. package/dist/client/{LoginView-J4qtHbQK.js → LoginView-CfVqItZV.js} +1 -1
  11. package/dist/client/{MarketplaceView-CshdWDqp.js → MarketplaceView-Cidt0nLf.js} +1 -1
  12. package/dist/client/{Modal.vue_vue_type_script_setup_true_lang-DKdB9A8Z.js → Modal.vue_vue_type_script_setup_true_lang-C1dmm1HX.js} +1 -1
  13. package/dist/client/ModelModal.vue_vue_type_script_setup_true_lang-DIKLuPXT.js +1 -0
  14. package/dist/client/{ModelsView-B_n306yk.js → ModelsView-DH6wNe38.js} +1 -1
  15. package/dist/client/{PromptEditView-C85qRgsE.js → PromptEditView-D_VjoAa-.js} +1 -1
  16. package/dist/client/{PromptModal-PNpoJfqD.js → PromptModal-a9LTOWNt.js} +1 -1
  17. package/dist/client/{PromptsView-BKnfThIF.js → PromptsView-BCCCryKR.js} +1 -1
  18. package/dist/client/{ProvidersView-Df41VhHD.js → ProvidersView-CF4x5F6G.js} +2 -2
  19. package/dist/client/ThreadInspectorPane.vue_vue_type_script_setup_true_lang-D5VDoQiK.js +22 -0
  20. package/dist/client/ThreadsView-BzscU1l2.js +1 -0
  21. package/dist/client/{ToolsView-C0MH9x3N.js → ToolsView-CeEtxDZV.js} +1 -1
  22. package/dist/client/{UiCodeBlock.vue_vue_type_script_setup_true_lang-DjDQOYjB.js → UiCodeBlock.vue_vue_type_script_setup_true_lang-BdyzSxZZ.js} +1 -1
  23. package/dist/client/{UsersView--TQiJYP7.js → UsersView-Di5cmUYL.js} +1 -1
  24. package/dist/client/{VariablesView-BO3UljZu.js → VariablesView-CXUr05jD.js} +1 -1
  25. package/dist/client/assets/{CompositionView-nJBKoNx4.css → CompositionView-0qQUWuc1.css} +1 -1
  26. package/dist/client/{check-DeHZQcv4.js → check-YKi1o6p6.js} +1 -1
  27. package/dist/client/{chevron-right-C8Mb0B59.js → chevron-right-T0zzq_GX.js} +1 -1
  28. package/dist/client/{copy-BxJsl-KZ.js → copy-C_gUGAj1.js} +1 -1
  29. package/dist/client/{formkit-0eyyCEP_.js → formkit-CE26dtFp.js} +1 -1
  30. package/dist/client/index-BMqXblce.js +6 -0
  31. package/dist/client/index.html +3 -3
  32. package/dist/client/{package-B9czwyIu.js → package-B70IFSDB.js} +1 -1
  33. package/dist/client/{plus-DqtuqJFm.js → plus-BN9IHYdt.js} +1 -1
  34. package/dist/client/{timeAgo-CDt-vAhI.js → timeAgo-G1ovbWPH.js} +1 -1
  35. package/dist/client/{useActionFeedback-B6UfBJ7l.js → useActionFeedback-7pfPjKMi.js} +1 -1
  36. package/dist/client/{vue-Dw7WLX4c.js → vue-CZ-ORfS3.js} +1 -1
  37. package/dist/{index-DceFbLG9.d.ts → index-Lfan8QMN.d.ts} +46 -0
  38. package/dist/index.d.ts +1 -1
  39. package/dist/index.js +303 -27
  40. package/dist/index.js.map +1 -1
  41. package/dist/plugin.js +6 -0
  42. package/dist/plugin.js.map +1 -1
  43. package/dist/runtime.d.ts +45 -5
  44. package/dist/runtime.js +297 -27
  45. package/dist/runtime.js.map +1 -1
  46. package/dist/test.d.ts +1 -1
  47. package/package.json +5 -5
  48. package/dist/client/CenteredContentView-CfgX3Ao3.js +0 -1
  49. package/dist/client/CompositionView-B9FfWMHd.js +0 -32
  50. package/dist/client/ModelModal.vue_vue_type_script_setup_true_lang-BAxaBZsx.js +0 -1
  51. package/dist/client/ThreadInspectorPane.vue_vue_type_script_setup_true_lang-CtIBWHUR.js +0 -22
  52. package/dist/client/ThreadsView-sjo5Rrcm.js +0 -1
  53. package/dist/client/index-BgZnQr8X.js +0 -6
@@ -13320,8 +13320,25 @@ var init_ThreadStateImpl = __esm({
13320
13320
  const mustParkForApproval = await this.forwardedCallNeedsApproval(request);
13321
13321
  if (mustParkForApproval && canPark && toolCallId && typeof instance.hasBridge === "function" && await instance.hasBridge()) {
13322
13322
  await instance.dispatchClientTool(request, toolCallId, side);
13323
- const getDelivered = instance.getDeliveredClientToolResult;
13324
- if (typeof getDelivered === "function") {
13323
+ const withDelivery = instance;
13324
+ if (typeof withDelivery.awaitDeliveredClientToolResult === "function") {
13325
+ try {
13326
+ const delivered = await withDelivery.awaitDeliveredClientToolResult.call(
13327
+ instance,
13328
+ toolCallId,
13329
+ 4e3
13330
+ );
13331
+ if (delivered) {
13332
+ return {
13333
+ ok: delivered.toolStatus !== "error",
13334
+ result: delivered.content,
13335
+ data: { toolCallId }
13336
+ };
13337
+ }
13338
+ } catch {
13339
+ }
13340
+ } else if (typeof withDelivery.getDeliveredClientToolResult === "function") {
13341
+ const getDelivered = withDelivery.getDeliveredClientToolResult;
13325
13342
  const graceDeadline = Date.now() + 4e3;
13326
13343
  while (Date.now() < graceDeadline) {
13327
13344
  await new Promise((r) => setTimeout(r, 150));
@@ -13411,7 +13428,14 @@ var init_ThreadStateImpl = __esm({
13411
13428
  if (typeof stub.proxyStreamOpen === "function") {
13412
13429
  const opened = await stub.proxyStreamOpen(withWake(parentId));
13413
13430
  if (opened.ok && opened.id) {
13414
- return { ok: true, duplex: this.buildProxyDuplex(stub, opened.id) };
13431
+ return {
13432
+ ok: true,
13433
+ duplex: this.buildProxyDuplex(
13434
+ stub,
13435
+ opened.id,
13436
+ opened.parkedPull === true
13437
+ )
13438
+ };
13415
13439
  }
13416
13440
  if (opened.error && !opened.noClient) {
13417
13441
  return {
@@ -13429,11 +13453,15 @@ var init_ThreadStateImpl = __esm({
13429
13453
  }
13430
13454
  /**
13431
13455
  * Build a client duplex that bridges to a stream opened on an ancestor DO
13432
- * (the bridge holder) via chunk-pull RPCs. `readable` polls `proxyStreamPull`;
13433
- * `writable` forwards each chunk with `proxyStreamWrite`; teardown calls
13456
+ * (the bridge holder) via chunk-pull RPCs. `readable` issues PARKED pulls —
13457
+ * a current ancestor holds one `proxyStreamPull` until bytes, completion,
13458
+ * error, or abort, so an idle open stream performs zero repeated pulls.
13459
+ * Older ancestors use the bounded long-pull compatibility path. `writable`
13460
+ * forwards each chunk with `proxyStreamWrite`; teardown calls
13434
13461
  * `proxyStreamAbort`.
13435
13462
  */
13436
- buildProxyDuplex(stub, id) {
13463
+ static PROXY_PULL_MAX_WAIT_MS = 2e4;
13464
+ buildProxyDuplex(stub, id, supportsParkedPull = false) {
13437
13465
  let settleDone;
13438
13466
  const done = new Promise((r) => settleDone = r);
13439
13467
  let closed = false;
@@ -13446,9 +13474,13 @@ var init_ThreadStateImpl = __esm({
13446
13474
  const readable = new ReadableStream({
13447
13475
  async pull(controller) {
13448
13476
  while (!closed) {
13477
+ const pullStartedAt = Date.now();
13449
13478
  let res;
13450
13479
  try {
13451
- res = await stub.proxyStreamPull(id);
13480
+ res = await stub.proxyStreamPull(
13481
+ id,
13482
+ supportsParkedPull ? void 0 : _ThreadStateImpl.PROXY_PULL_MAX_WAIT_MS
13483
+ );
13452
13484
  } catch (error) {
13453
13485
  controller.error(error instanceof Error ? error : new Error(String(error)));
13454
13486
  settle({ ok: false, error: "proxy stream pull failed" });
@@ -13463,7 +13495,14 @@ var init_ThreadStateImpl = __esm({
13463
13495
  return;
13464
13496
  }
13465
13497
  if (res.chunks.length > 0) return;
13466
- await new Promise((r) => setTimeout(r, 25));
13498
+ if (supportsParkedPull) {
13499
+ controller.error(new Error("parked proxy pull returned without data"));
13500
+ settle({ ok: false, error: "parked proxy pull returned without data" });
13501
+ return;
13502
+ }
13503
+ if (Date.now() - pullStartedAt < 250) {
13504
+ await new Promise((r) => setTimeout(r, 250));
13505
+ }
13467
13506
  }
13468
13507
  },
13469
13508
  cancel() {
@@ -13638,7 +13677,7 @@ var init_ThreadStateImpl = __esm({
13638
13677
  return bytes.buffer;
13639
13678
  }
13640
13679
  async readFileStream(path10, options) {
13641
- const fileInfo = await this._threadInstance.statFile(path10);
13680
+ const fileInfo = this._unwrapStatRecord(await this._threadInstance.statFile(path10));
13642
13681
  if (!fileInfo) {
13643
13682
  return null;
13644
13683
  }
@@ -13693,12 +13732,32 @@ var init_ThreadStateImpl = __esm({
13693
13732
  }
13694
13733
  };
13695
13734
  }
13735
+ /**
13736
+ * Unwrap the thread DO's `{ success, file }` stat envelope (older shapes
13737
+ * returned the record directly). A failed or absent lookup is NULL — the
13738
+ * old code mapped the envelope itself, producing a truthy record with
13739
+ * every field defaulted (size 0, application/octet-stream) even for
13740
+ * NONEXISTENT paths, which let a phantom asset pass an existence check and
13741
+ * a real 1.2MB image read as "0 bytes" (2026-08-11).
13742
+ */
13743
+ _unwrapStatRecord(result) {
13744
+ const record24 = result?.file ?? result;
13745
+ if (!record24 || typeof record24 !== "object") return null;
13746
+ if (!("path" in record24) && !("name" in record24)) return null;
13747
+ return record24;
13748
+ }
13696
13749
  async statFile(path10) {
13697
- const result = await this._threadInstance.statFile(path10);
13698
- return result ? this._mapFileRecord(result) : null;
13750
+ const record24 = this._unwrapStatRecord(await this._threadInstance.statFile(path10));
13751
+ return record24 ? this._mapFileRecord(record24) : null;
13699
13752
  }
13700
13753
  async readdirFile(path10) {
13701
- const entries = await this._threadInstance.readdirFile(path10);
13754
+ const result = await this._threadInstance.readdirFile(path10);
13755
+ const entries = Array.isArray(result) ? result : result?.files;
13756
+ if (!Array.isArray(entries)) {
13757
+ throw new Error(
13758
+ result?.error || `Could not list directory: ${path10}`
13759
+ );
13760
+ }
13702
13761
  return {
13703
13762
  entries: entries.map((e) => this._mapFileRecord(e))
13704
13763
  };
@@ -67928,7 +67987,7 @@ var config_get_default = defineController2(async ({ config, env: env2, req }) =>
67928
67987
  });
67929
67988
 
67930
67989
  // src/version.ts
67931
- var BUILDER_VERSION = "0.37.4".length > 0 ? "0.37.4" : "dev";
67990
+ var BUILDER_VERSION = "0.37.6".length > 0 ? "0.37.6" : "dev";
67932
67991
 
67933
67992
  // src/api/diagnostics.get.ts
67934
67993
  init_LLMRequest();
@@ -70318,6 +70377,33 @@ var id_patch_default = defineController2(async ({ req, env: env2, params }) => {
70318
70377
  }
70319
70378
  });
70320
70379
 
70380
+ // src/middleware/request-auth.ts
70381
+ async function resolveRequestAuth(context) {
70382
+ if (context.auth) return context.auth;
70383
+ return requireAuth(context.req, context.env);
70384
+ }
70385
+ async function resolveOptionalRequestAuth(context) {
70386
+ if (context.auth) return context.auth;
70387
+ return authenticate(context.req, context.env);
70388
+ }
70389
+ async function resolveRequestPermission(context, permission) {
70390
+ if (context.auth) {
70391
+ if (!hasPermission(context.auth.user, permission)) {
70392
+ return Response.json(
70393
+ { error: `Forbidden: '${permission}' access required` },
70394
+ { status: 403 }
70395
+ );
70396
+ }
70397
+ return context.auth;
70398
+ }
70399
+ return requirePermission(context.req, context.env, permission);
70400
+ }
70401
+ function routerAuthorizedThread(context, threadId) {
70402
+ const access = context.threadAccess;
70403
+ if (!access || !threadId) return null;
70404
+ return access.threadId === threadId ? access.thread : null;
70405
+ }
70406
+
70321
70407
  // src/api/threads/[id].ts
70322
70408
  function resolveIconUrl2(icon, origin) {
70323
70409
  if (!icon) return void 0;
@@ -70329,8 +70415,9 @@ function resolveIconUrl2(icon, origin) {
70329
70415
  }
70330
70416
  return icon;
70331
70417
  }
70332
- var id_default = defineController2(async ({ req, params, env: env2 }) => {
70333
- const authResult = await requireAuth(req, env2);
70418
+ var id_default = defineController2(async (context) => {
70419
+ const { req, params, env: env2 } = context;
70420
+ const authResult = await resolveRequestAuth(context);
70334
70421
  if (authResult instanceof Response) {
70335
70422
  return authResult;
70336
70423
  }
@@ -70340,20 +70427,22 @@ var id_default = defineController2(async ({ req, params, env: env2 }) => {
70340
70427
  return Response.json({ error: "Thread ID required" }, { status: 400 });
70341
70428
  }
70342
70429
  try {
70343
- const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
70344
- const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
70345
- const thread = await agentBuilder.getThread(threadId);
70346
- if (!thread) {
70347
- return Response.json(
70348
- { error: `Thread not found: ${threadId}` },
70349
- { status: 404 }
70350
- );
70351
- }
70352
- if (!canAccessThread(auth, thread)) {
70353
- return Response.json(
70354
- { error: "Forbidden: You don't have access to this thread" },
70355
- { status: 403 }
70356
- );
70430
+ if (!routerAuthorizedThread(context, threadId)) {
70431
+ const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
70432
+ const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
70433
+ const thread = await agentBuilder.getThread(threadId);
70434
+ if (!thread) {
70435
+ return Response.json(
70436
+ { error: `Thread not found: ${threadId}` },
70437
+ { status: 404 }
70438
+ );
70439
+ }
70440
+ if (!canAccessThread(auth, thread)) {
70441
+ return Response.json(
70442
+ { error: "Forbidden: You don't have access to this thread" },
70443
+ { status: 403 }
70444
+ );
70445
+ }
70357
70446
  }
70358
70447
  const durableId = env2.AGENT_BUILDER_THREAD.idFromName(threadId);
70359
70448
  const stub = env2.AGENT_BUILDER_THREAD.get(durableId);
@@ -73459,31 +73548,34 @@ var diagnostics_get_default2 = defineController2(async ({ req, params, env: env2
73459
73548
  });
73460
73549
 
73461
73550
  // src/api/threads/[id]/effects.get.ts
73462
- async function getAuthorizedThreadStub(req, env2, threadId) {
73463
- const authResult = await requireAuth(req, env2);
73551
+ async function getAuthorizedThreadStub(context, threadId) {
73552
+ const { env: env2 } = context;
73553
+ const authResult = await resolveRequestAuth(context);
73464
73554
  if (authResult instanceof Response) {
73465
73555
  return authResult;
73466
73556
  }
73467
- const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
73468
- const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
73469
- if (typeof agentBuilder.getThread !== "function") {
73470
- return Response.json(
73471
- { error: "Thread lookup is not supported by this runtime" },
73472
- { status: 500 }
73473
- );
73474
- }
73475
- const thread = await agentBuilder.getThread(threadId);
73476
- if (!thread) {
73477
- return Response.json(
73478
- { error: `Thread not found: ${threadId}` },
73479
- { status: 404 }
73480
- );
73481
- }
73482
- if (!canAccessThread(authResult, thread)) {
73483
- return Response.json(
73484
- { error: "Forbidden: You don't have access to this thread" },
73485
- { status: 403 }
73486
- );
73557
+ if (!routerAuthorizedThread(context, threadId)) {
73558
+ const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
73559
+ const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
73560
+ if (typeof agentBuilder.getThread !== "function") {
73561
+ return Response.json(
73562
+ { error: "Thread lookup is not supported by this runtime" },
73563
+ { status: 500 }
73564
+ );
73565
+ }
73566
+ const thread = await agentBuilder.getThread(threadId);
73567
+ if (!thread) {
73568
+ return Response.json(
73569
+ { error: `Thread not found: ${threadId}` },
73570
+ { status: 404 }
73571
+ );
73572
+ }
73573
+ if (!canAccessThread(authResult, thread)) {
73574
+ return Response.json(
73575
+ { error: "Forbidden: You don't have access to this thread" },
73576
+ { status: 403 }
73577
+ );
73578
+ }
73487
73579
  }
73488
73580
  const durableId = env2.AGENT_BUILDER_THREAD.idFromName(threadId);
73489
73581
  return env2.AGENT_BUILDER_THREAD.get(durableId);
@@ -73492,13 +73584,14 @@ function parseInteger(value, fallback) {
73492
73584
  const parsed = value ? Number.parseInt(value, 10) : Number.NaN;
73493
73585
  return Number.isFinite(parsed) ? parsed : fallback;
73494
73586
  }
73495
- var effects_get_default = defineController2(async ({ req, params, env: env2, url }) => {
73587
+ var effects_get_default = defineController2(async (context) => {
73588
+ const { params, url } = context;
73496
73589
  const threadId = params.id;
73497
73590
  if (!threadId) {
73498
73591
  return Response.json({ error: "Thread ID required" }, { status: 400 });
73499
73592
  }
73500
73593
  try {
73501
- const stub = await getAuthorizedThreadStub(req, env2, threadId);
73594
+ const stub = await getAuthorizedThreadStub(context, threadId);
73502
73595
  if (stub instanceof Response) return stub;
73503
73596
  if (typeof stub.listEffectRuns !== "function") {
73504
73597
  return Response.json(
@@ -73582,31 +73675,34 @@ var fs_default = defineController2(async ({ req, params, env: env2 }) => {
73582
73675
  });
73583
73676
 
73584
73677
  // src/api/threads/[id]/kv/index.ts
73585
- async function getAuthorizedThreadStub2(req, env2, threadId) {
73586
- const authResult = await requireAuth(req, env2);
73678
+ async function getAuthorizedThreadStub2(context, threadId) {
73679
+ const { env: env2 } = context;
73680
+ const authResult = await resolveRequestAuth(context);
73587
73681
  if (authResult instanceof Response) {
73588
73682
  return authResult;
73589
73683
  }
73590
- const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
73591
- const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
73592
- if (typeof agentBuilder.getThread !== "function") {
73593
- return Response.json(
73594
- { error: "Thread lookup is not supported by this runtime" },
73595
- { status: 500 }
73596
- );
73597
- }
73598
- const thread = await agentBuilder.getThread(threadId);
73599
- if (!thread) {
73600
- return Response.json(
73601
- { error: `Thread not found: ${threadId}` },
73602
- { status: 404 }
73603
- );
73604
- }
73605
- if (!canAccessThread(authResult, thread)) {
73606
- return Response.json(
73607
- { error: "Forbidden: You don't have access to this thread" },
73608
- { status: 403 }
73609
- );
73684
+ if (!routerAuthorizedThread(context, threadId)) {
73685
+ const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
73686
+ const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
73687
+ if (typeof agentBuilder.getThread !== "function") {
73688
+ return Response.json(
73689
+ { error: "Thread lookup is not supported by this runtime" },
73690
+ { status: 500 }
73691
+ );
73692
+ }
73693
+ const thread = await agentBuilder.getThread(threadId);
73694
+ if (!thread) {
73695
+ return Response.json(
73696
+ { error: `Thread not found: ${threadId}` },
73697
+ { status: 404 }
73698
+ );
73699
+ }
73700
+ if (!canAccessThread(authResult, thread)) {
73701
+ return Response.json(
73702
+ { error: "Forbidden: You don't have access to this thread" },
73703
+ { status: 403 }
73704
+ );
73705
+ }
73610
73706
  }
73611
73707
  const durableId = env2.AGENT_BUILDER_THREAD.idFromName(threadId);
73612
73708
  return env2.AGENT_BUILDER_THREAD.get(durableId);
@@ -73704,13 +73800,14 @@ async function handleDelete(stub, req, url) {
73704
73800
  await stub.setValue(key, null);
73705
73801
  return new Response(null, { status: 204 });
73706
73802
  }
73707
- var kv_default = defineController2(async ({ req, params, env: env2, url }) => {
73803
+ var kv_default = defineController2(async (context) => {
73804
+ const { req, params, url } = context;
73708
73805
  const threadId = params.id;
73709
73806
  if (!threadId) {
73710
73807
  return Response.json({ error: "Thread ID required" }, { status: 400 });
73711
73808
  }
73712
73809
  try {
73713
- const stub = await getAuthorizedThreadStub2(req, env2, threadId);
73810
+ const stub = await getAuthorizedThreadStub2(context, threadId);
73714
73811
  if (stub instanceof Response) return stub;
73715
73812
  switch (req.method) {
73716
73813
  case "GET":
@@ -73735,14 +73832,15 @@ var kv_default = defineController2(async ({ req, params, env: env2, url }) => {
73735
73832
  });
73736
73833
 
73737
73834
  // src/api/threads/[id]/logs.get.ts
73738
- var logs_get_default = defineController2(async ({ req, params, env: env2 }) => {
73835
+ var logs_get_default = defineController2(async (context) => {
73836
+ const { req, params, env: env2 } = context;
73739
73837
  if (isPlatformHosted(env2)) {
73740
- const authResult = await requirePermission(req, env2, "logs");
73838
+ const authResult = await resolveRequestPermission(context, "logs");
73741
73839
  if (authResult instanceof Response) {
73742
73840
  return authResult;
73743
73841
  }
73744
73842
  } else {
73745
- const authContext = await authenticate(req, env2);
73843
+ const authContext = await resolveOptionalRequestAuth(context);
73746
73844
  if (authContext && !hasPermission(authContext.user, "logs")) {
73747
73845
  return Response.json(
73748
73846
  { error: "Forbidden: 'logs' access required" },
@@ -73756,9 +73854,12 @@ var logs_get_default = defineController2(async ({ req, params, env: env2 }) => {
73756
73854
  return Response.json({ error: "Thread ID required" }, { status: 400 });
73757
73855
  }
73758
73856
  try {
73759
- const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
73760
- const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
73761
- const thread = await agentBuilder.getThread(threadId);
73857
+ let thread = routerAuthorizedThread(context, threadId);
73858
+ if (!thread) {
73859
+ const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
73860
+ const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
73861
+ thread = await agentBuilder.getThread(threadId);
73862
+ }
73762
73863
  if (!thread) {
73763
73864
  return Response.json(
73764
73865
  { error: `Thread not found: ${threadId}` },