@standardagents/builder 0.37.3 → 0.37.5

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 +178 -81
  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 +297 -25
  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 +291 -25
  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
@@ -9983,10 +9983,18 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
9983
9983
  const mimeType = match2[1];
9984
9984
  const base64Data = match2[2];
9985
9985
  const ext = mimeType.split("/")[1] || "png";
9986
+ if (base64Data.length < 64) {
9987
+ console.error("[FlowEngine] Generated image payload is empty/truncated, skipping");
9988
+ continue;
9989
+ }
9986
9990
  const attachmentId = crypto.randomUUID();
9987
9991
  const path10 = `/attachments/${Date.now()}-${attachmentId.slice(0, 8)}.${ext}`;
9988
9992
  try {
9989
- await state.thread.instance.writeFile(path10, base64Data, mimeType);
9993
+ const written = await state.thread.instance.writeFile(path10, base64Data, mimeType);
9994
+ if (written && written.success === false) {
9995
+ console.error("[FlowEngine] Generated image write failed:", written.error);
9996
+ continue;
9997
+ }
9990
9998
  if (image.id) {
9991
9999
  imagePathMap.set(image.id, path10);
9992
10000
  }
@@ -10053,10 +10061,18 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
10053
10061
  const mimeType = imageUrl.slice(dataPrefix.length, base64Index);
10054
10062
  const base64Data = imageUrl.slice(base64Index + base64Marker.length);
10055
10063
  const ext = mimeType.split("/")[1] || "png";
10064
+ if (base64Data.length < 64) {
10065
+ console.error(`[FlowEngine] ${toolName} image payload is empty/truncated, skipping`);
10066
+ continue;
10067
+ }
10056
10068
  const attachmentId = crypto.randomUUID();
10057
10069
  const path10 = `/attachments/${Date.now()}-${attachmentId.slice(0, 8)}.${ext}`;
10058
10070
  try {
10059
- await state.thread.instance.writeFile(path10, base64Data, mimeType);
10071
+ const written = await state.thread.instance.writeFile(path10, base64Data, mimeType);
10072
+ if (written && written.success === false) {
10073
+ console.error(`[FlowEngine] ${toolName} image write failed:`, written.error);
10074
+ continue;
10075
+ }
10060
10076
  const attachmentRef = {
10061
10077
  id: attachmentId,
10062
10078
  type: "file",
@@ -13304,8 +13320,25 @@ var init_ThreadStateImpl = __esm({
13304
13320
  const mustParkForApproval = await this.forwardedCallNeedsApproval(request);
13305
13321
  if (mustParkForApproval && canPark && toolCallId && typeof instance.hasBridge === "function" && await instance.hasBridge()) {
13306
13322
  await instance.dispatchClientTool(request, toolCallId, side);
13307
- const getDelivered = instance.getDeliveredClientToolResult;
13308
- 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;
13309
13342
  const graceDeadline = Date.now() + 4e3;
13310
13343
  while (Date.now() < graceDeadline) {
13311
13344
  await new Promise((r) => setTimeout(r, 150));
@@ -13395,7 +13428,14 @@ var init_ThreadStateImpl = __esm({
13395
13428
  if (typeof stub.proxyStreamOpen === "function") {
13396
13429
  const opened = await stub.proxyStreamOpen(withWake(parentId));
13397
13430
  if (opened.ok && opened.id) {
13398
- 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
+ };
13399
13439
  }
13400
13440
  if (opened.error && !opened.noClient) {
13401
13441
  return {
@@ -13413,11 +13453,15 @@ var init_ThreadStateImpl = __esm({
13413
13453
  }
13414
13454
  /**
13415
13455
  * Build a client duplex that bridges to a stream opened on an ancestor DO
13416
- * (the bridge holder) via chunk-pull RPCs. `readable` polls `proxyStreamPull`;
13417
- * `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
13418
13461
  * `proxyStreamAbort`.
13419
13462
  */
13420
- buildProxyDuplex(stub, id) {
13463
+ static PROXY_PULL_MAX_WAIT_MS = 2e4;
13464
+ buildProxyDuplex(stub, id, supportsParkedPull = false) {
13421
13465
  let settleDone;
13422
13466
  const done = new Promise((r) => settleDone = r);
13423
13467
  let closed = false;
@@ -13430,9 +13474,13 @@ var init_ThreadStateImpl = __esm({
13430
13474
  const readable = new ReadableStream({
13431
13475
  async pull(controller) {
13432
13476
  while (!closed) {
13477
+ const pullStartedAt = Date.now();
13433
13478
  let res;
13434
13479
  try {
13435
- res = await stub.proxyStreamPull(id);
13480
+ res = await stub.proxyStreamPull(
13481
+ id,
13482
+ supportsParkedPull ? void 0 : _ThreadStateImpl.PROXY_PULL_MAX_WAIT_MS
13483
+ );
13436
13484
  } catch (error) {
13437
13485
  controller.error(error instanceof Error ? error : new Error(String(error)));
13438
13486
  settle({ ok: false, error: "proxy stream pull failed" });
@@ -13447,7 +13495,14 @@ var init_ThreadStateImpl = __esm({
13447
13495
  return;
13448
13496
  }
13449
13497
  if (res.chunks.length > 0) return;
13450
- 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
+ }
13451
13506
  }
13452
13507
  },
13453
13508
  cancel() {
@@ -67912,7 +67967,7 @@ var config_get_default = defineController2(async ({ config, env: env2, req }) =>
67912
67967
  });
67913
67968
 
67914
67969
  // src/version.ts
67915
- var BUILDER_VERSION = "0.37.3".length > 0 ? "0.37.3" : "dev";
67970
+ var BUILDER_VERSION = "0.37.5".length > 0 ? "0.37.5" : "dev";
67916
67971
 
67917
67972
  // src/api/diagnostics.get.ts
67918
67973
  init_LLMRequest();
@@ -70302,6 +70357,33 @@ var id_patch_default = defineController2(async ({ req, env: env2, params }) => {
70302
70357
  }
70303
70358
  });
70304
70359
 
70360
+ // src/middleware/request-auth.ts
70361
+ async function resolveRequestAuth(context) {
70362
+ if (context.auth) return context.auth;
70363
+ return requireAuth(context.req, context.env);
70364
+ }
70365
+ async function resolveOptionalRequestAuth(context) {
70366
+ if (context.auth) return context.auth;
70367
+ return authenticate(context.req, context.env);
70368
+ }
70369
+ async function resolveRequestPermission(context, permission) {
70370
+ if (context.auth) {
70371
+ if (!hasPermission(context.auth.user, permission)) {
70372
+ return Response.json(
70373
+ { error: `Forbidden: '${permission}' access required` },
70374
+ { status: 403 }
70375
+ );
70376
+ }
70377
+ return context.auth;
70378
+ }
70379
+ return requirePermission(context.req, context.env, permission);
70380
+ }
70381
+ function routerAuthorizedThread(context, threadId) {
70382
+ const access = context.threadAccess;
70383
+ if (!access || !threadId) return null;
70384
+ return access.threadId === threadId ? access.thread : null;
70385
+ }
70386
+
70305
70387
  // src/api/threads/[id].ts
70306
70388
  function resolveIconUrl2(icon, origin) {
70307
70389
  if (!icon) return void 0;
@@ -70313,8 +70395,9 @@ function resolveIconUrl2(icon, origin) {
70313
70395
  }
70314
70396
  return icon;
70315
70397
  }
70316
- var id_default = defineController2(async ({ req, params, env: env2 }) => {
70317
- const authResult = await requireAuth(req, env2);
70398
+ var id_default = defineController2(async (context) => {
70399
+ const { req, params, env: env2 } = context;
70400
+ const authResult = await resolveRequestAuth(context);
70318
70401
  if (authResult instanceof Response) {
70319
70402
  return authResult;
70320
70403
  }
@@ -70324,20 +70407,22 @@ var id_default = defineController2(async ({ req, params, env: env2 }) => {
70324
70407
  return Response.json({ error: "Thread ID required" }, { status: 400 });
70325
70408
  }
70326
70409
  try {
70327
- const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
70328
- const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
70329
- const thread = await agentBuilder.getThread(threadId);
70330
- if (!thread) {
70331
- return Response.json(
70332
- { error: `Thread not found: ${threadId}` },
70333
- { status: 404 }
70334
- );
70335
- }
70336
- if (!canAccessThread(auth, thread)) {
70337
- return Response.json(
70338
- { error: "Forbidden: You don't have access to this thread" },
70339
- { status: 403 }
70340
- );
70410
+ if (!routerAuthorizedThread(context, threadId)) {
70411
+ const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
70412
+ const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
70413
+ const thread = await agentBuilder.getThread(threadId);
70414
+ if (!thread) {
70415
+ return Response.json(
70416
+ { error: `Thread not found: ${threadId}` },
70417
+ { status: 404 }
70418
+ );
70419
+ }
70420
+ if (!canAccessThread(auth, thread)) {
70421
+ return Response.json(
70422
+ { error: "Forbidden: You don't have access to this thread" },
70423
+ { status: 403 }
70424
+ );
70425
+ }
70341
70426
  }
70342
70427
  const durableId = env2.AGENT_BUILDER_THREAD.idFromName(threadId);
70343
70428
  const stub = env2.AGENT_BUILDER_THREAD.get(durableId);
@@ -73443,31 +73528,34 @@ var diagnostics_get_default2 = defineController2(async ({ req, params, env: env2
73443
73528
  });
73444
73529
 
73445
73530
  // src/api/threads/[id]/effects.get.ts
73446
- async function getAuthorizedThreadStub(req, env2, threadId) {
73447
- const authResult = await requireAuth(req, env2);
73531
+ async function getAuthorizedThreadStub(context, threadId) {
73532
+ const { env: env2 } = context;
73533
+ const authResult = await resolveRequestAuth(context);
73448
73534
  if (authResult instanceof Response) {
73449
73535
  return authResult;
73450
73536
  }
73451
- const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
73452
- const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
73453
- if (typeof agentBuilder.getThread !== "function") {
73454
- return Response.json(
73455
- { error: "Thread lookup is not supported by this runtime" },
73456
- { status: 500 }
73457
- );
73458
- }
73459
- const thread = await agentBuilder.getThread(threadId);
73460
- if (!thread) {
73461
- return Response.json(
73462
- { error: `Thread not found: ${threadId}` },
73463
- { status: 404 }
73464
- );
73465
- }
73466
- if (!canAccessThread(authResult, thread)) {
73467
- return Response.json(
73468
- { error: "Forbidden: You don't have access to this thread" },
73469
- { status: 403 }
73470
- );
73537
+ if (!routerAuthorizedThread(context, threadId)) {
73538
+ const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
73539
+ const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
73540
+ if (typeof agentBuilder.getThread !== "function") {
73541
+ return Response.json(
73542
+ { error: "Thread lookup is not supported by this runtime" },
73543
+ { status: 500 }
73544
+ );
73545
+ }
73546
+ const thread = await agentBuilder.getThread(threadId);
73547
+ if (!thread) {
73548
+ return Response.json(
73549
+ { error: `Thread not found: ${threadId}` },
73550
+ { status: 404 }
73551
+ );
73552
+ }
73553
+ if (!canAccessThread(authResult, thread)) {
73554
+ return Response.json(
73555
+ { error: "Forbidden: You don't have access to this thread" },
73556
+ { status: 403 }
73557
+ );
73558
+ }
73471
73559
  }
73472
73560
  const durableId = env2.AGENT_BUILDER_THREAD.idFromName(threadId);
73473
73561
  return env2.AGENT_BUILDER_THREAD.get(durableId);
@@ -73476,13 +73564,14 @@ function parseInteger(value, fallback) {
73476
73564
  const parsed = value ? Number.parseInt(value, 10) : Number.NaN;
73477
73565
  return Number.isFinite(parsed) ? parsed : fallback;
73478
73566
  }
73479
- var effects_get_default = defineController2(async ({ req, params, env: env2, url }) => {
73567
+ var effects_get_default = defineController2(async (context) => {
73568
+ const { params, url } = context;
73480
73569
  const threadId = params.id;
73481
73570
  if (!threadId) {
73482
73571
  return Response.json({ error: "Thread ID required" }, { status: 400 });
73483
73572
  }
73484
73573
  try {
73485
- const stub = await getAuthorizedThreadStub(req, env2, threadId);
73574
+ const stub = await getAuthorizedThreadStub(context, threadId);
73486
73575
  if (stub instanceof Response) return stub;
73487
73576
  if (typeof stub.listEffectRuns !== "function") {
73488
73577
  return Response.json(
@@ -73566,31 +73655,34 @@ var fs_default = defineController2(async ({ req, params, env: env2 }) => {
73566
73655
  });
73567
73656
 
73568
73657
  // src/api/threads/[id]/kv/index.ts
73569
- async function getAuthorizedThreadStub2(req, env2, threadId) {
73570
- const authResult = await requireAuth(req, env2);
73658
+ async function getAuthorizedThreadStub2(context, threadId) {
73659
+ const { env: env2 } = context;
73660
+ const authResult = await resolveRequestAuth(context);
73571
73661
  if (authResult instanceof Response) {
73572
73662
  return authResult;
73573
73663
  }
73574
- const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
73575
- const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
73576
- if (typeof agentBuilder.getThread !== "function") {
73577
- return Response.json(
73578
- { error: "Thread lookup is not supported by this runtime" },
73579
- { status: 500 }
73580
- );
73581
- }
73582
- const thread = await agentBuilder.getThread(threadId);
73583
- if (!thread) {
73584
- return Response.json(
73585
- { error: `Thread not found: ${threadId}` },
73586
- { status: 404 }
73587
- );
73588
- }
73589
- if (!canAccessThread(authResult, thread)) {
73590
- return Response.json(
73591
- { error: "Forbidden: You don't have access to this thread" },
73592
- { status: 403 }
73593
- );
73664
+ if (!routerAuthorizedThread(context, threadId)) {
73665
+ const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
73666
+ const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
73667
+ if (typeof agentBuilder.getThread !== "function") {
73668
+ return Response.json(
73669
+ { error: "Thread lookup is not supported by this runtime" },
73670
+ { status: 500 }
73671
+ );
73672
+ }
73673
+ const thread = await agentBuilder.getThread(threadId);
73674
+ if (!thread) {
73675
+ return Response.json(
73676
+ { error: `Thread not found: ${threadId}` },
73677
+ { status: 404 }
73678
+ );
73679
+ }
73680
+ if (!canAccessThread(authResult, thread)) {
73681
+ return Response.json(
73682
+ { error: "Forbidden: You don't have access to this thread" },
73683
+ { status: 403 }
73684
+ );
73685
+ }
73594
73686
  }
73595
73687
  const durableId = env2.AGENT_BUILDER_THREAD.idFromName(threadId);
73596
73688
  return env2.AGENT_BUILDER_THREAD.get(durableId);
@@ -73688,13 +73780,14 @@ async function handleDelete(stub, req, url) {
73688
73780
  await stub.setValue(key, null);
73689
73781
  return new Response(null, { status: 204 });
73690
73782
  }
73691
- var kv_default = defineController2(async ({ req, params, env: env2, url }) => {
73783
+ var kv_default = defineController2(async (context) => {
73784
+ const { req, params, url } = context;
73692
73785
  const threadId = params.id;
73693
73786
  if (!threadId) {
73694
73787
  return Response.json({ error: "Thread ID required" }, { status: 400 });
73695
73788
  }
73696
73789
  try {
73697
- const stub = await getAuthorizedThreadStub2(req, env2, threadId);
73790
+ const stub = await getAuthorizedThreadStub2(context, threadId);
73698
73791
  if (stub instanceof Response) return stub;
73699
73792
  switch (req.method) {
73700
73793
  case "GET":
@@ -73719,14 +73812,15 @@ var kv_default = defineController2(async ({ req, params, env: env2, url }) => {
73719
73812
  });
73720
73813
 
73721
73814
  // src/api/threads/[id]/logs.get.ts
73722
- var logs_get_default = defineController2(async ({ req, params, env: env2 }) => {
73815
+ var logs_get_default = defineController2(async (context) => {
73816
+ const { req, params, env: env2 } = context;
73723
73817
  if (isPlatformHosted(env2)) {
73724
- const authResult = await requirePermission(req, env2, "logs");
73818
+ const authResult = await resolveRequestPermission(context, "logs");
73725
73819
  if (authResult instanceof Response) {
73726
73820
  return authResult;
73727
73821
  }
73728
73822
  } else {
73729
- const authContext = await authenticate(req, env2);
73823
+ const authContext = await resolveOptionalRequestAuth(context);
73730
73824
  if (authContext && !hasPermission(authContext.user, "logs")) {
73731
73825
  return Response.json(
73732
73826
  { error: "Forbidden: 'logs' access required" },
@@ -73740,9 +73834,12 @@ var logs_get_default = defineController2(async ({ req, params, env: env2 }) => {
73740
73834
  return Response.json({ error: "Thread ID required" }, { status: 400 });
73741
73835
  }
73742
73836
  try {
73743
- const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
73744
- const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
73745
- const thread = await agentBuilder.getThread(threadId);
73837
+ let thread = routerAuthorizedThread(context, threadId);
73838
+ if (!thread) {
73839
+ const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
73840
+ const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
73841
+ thread = await agentBuilder.getThread(threadId);
73842
+ }
73746
73843
  if (!thread) {
73747
73844
  return Response.json(
73748
73845
  { error: `Thread not found: ${threadId}` },