@standardagents/builder 0.40.5-next.3b25e2a → 0.40.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.
@@ -99,12 +99,6 @@ function encodeStreamChunk(bytes) {
99
99
  }
100
100
  return btoa(binary);
101
101
  }
102
- function decodeStreamChunk(data) {
103
- const binary = atob(data);
104
- const bytes = new Uint8Array(binary.length);
105
- for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
106
- return bytes;
107
- }
108
102
  var init_client_forwarding = __esm({
109
103
  "src/agents/client-forwarding.ts"() {
110
104
  }
@@ -5047,9 +5041,7 @@ Message one with subagent_message(referenceId, message).`
5047
5041
  if (resumable) {
5048
5042
  await this.settleResumableChildAfterRun(
5049
5043
  state,
5050
- stub,
5051
- childThreadId,
5052
- childResult
5044
+ childThreadId
5053
5045
  );
5054
5046
  } else if (stub.terminateThread) {
5055
5047
  await stub.terminateThread(childThreadId);
@@ -5061,7 +5053,7 @@ Message one with subagent_message(referenceId, message).`
5061
5053
  attachments: copiedAttachments,
5062
5054
  subagent_id: childThreadId
5063
5055
  };
5064
- return resumable && !this.isTerminalSubagentResult(childResult) ? this.withReferenceInToolResult(toolResult, childThreadId) : toolResult;
5056
+ return resumable ? this.withReferenceInToolResult(toolResult, childThreadId) : toolResult;
5065
5057
  }
5066
5058
  const backgroundRun = (async () => {
5067
5059
  try {
@@ -5096,9 +5088,7 @@ Message one with subagent_message(referenceId, message).`
5096
5088
  if (resumable) {
5097
5089
  await this.settleResumableChildAfterRun(
5098
5090
  state,
5099
- stub,
5100
- childThreadId,
5101
- childResult
5091
+ childThreadId
5102
5092
  );
5103
5093
  } else if (stub.terminateThread) {
5104
5094
  await stub.terminateThread(childThreadId);
@@ -5493,18 +5483,8 @@ Message one with subagent_message(referenceId, message).`
5493
5483
  JSON.stringify(next)
5494
5484
  );
5495
5485
  }
5496
- static isTerminalSubagentResult(result) {
5497
- return result.terminal === true;
5498
- }
5499
- static async settleResumableChildAfterRun(state, childThread, reference, result) {
5500
- if (!this.isTerminalSubagentResult(result)) {
5501
- await this.updateChildStatus(state, reference, "idle");
5502
- return;
5503
- }
5504
- await this.updateChildStatus(state, reference, "terminated");
5505
- if (typeof childThread.terminateThread === "function") {
5506
- await childThread.terminateThread(reference);
5507
- }
5486
+ static async settleResumableChildAfterRun(state, reference) {
5487
+ await this.updateChildStatus(state, reference, "idle");
5508
5488
  }
5509
5489
  static async buildChildInvocationMessages(state, childThread, content, receivesMessages, parentAttachments, initialArguments) {
5510
5490
  const copiedAttachments = await this.copyAttachmentsBetweenThreads(
@@ -13992,27 +13972,51 @@ var init_ThreadStateImpl = __esm({
13992
13972
  const withWake = (threadId) => wakeUserId ? { ...request, wake: { threadId, userId: wakeUserId } } : request;
13993
13973
  const local = await instance.openClientStream(withWake(this._metadata.id));
13994
13974
  if (local.ok || !this.isNoClient(local)) return local;
13995
- const env2 = this._threadInstance.env;
13996
- if (!env2?.AGENT_BUILDER_THREAD) return local;
13975
+ if (typeof instance.createProxyStreamReceiver !== "function" || typeof instance.proxyStreamReceive !== "function") {
13976
+ return local;
13977
+ }
13978
+ let abortRemote = null;
13979
+ const receiver = instance.createProxyStreamReceiver((error) => abortRemote?.(error));
13980
+ const discardReceiver = async (error) => {
13981
+ await instance.proxyStreamReceive(receiver.id, { type: "abort", error });
13982
+ };
13983
+ const namespace = instance.env.AGENT_BUILDER_THREAD;
13997
13984
  const seen = /* @__PURE__ */ new Set([this._metadata.id]);
13998
13985
  let parentId = await this.resolveParentThreadId(this._metadata.id);
13999
13986
  while (parentId && !seen.has(parentId)) {
14000
13987
  seen.add(parentId);
14001
13988
  try {
14002
- const stub = env2.AGENT_BUILDER_THREAD.get(env2.AGENT_BUILDER_THREAD.idFromName(parentId));
13989
+ const stub = namespace.get(namespace.idFromName(parentId));
14003
13990
  if (typeof stub.proxyStreamOpen === "function") {
14004
- const opened = await stub.proxyStreamOpen(withWake(parentId));
13991
+ const opened = await stub.proxyStreamOpen(withWake(parentId), {
13992
+ threadId: this._metadata.id,
13993
+ receiverId: receiver.id
13994
+ });
14005
13995
  if (opened.ok && opened.id) {
13996
+ if (opened.eventDriven !== true) {
13997
+ await stub.proxyStreamAbort(opened.id).catch(() => {
13998
+ });
13999
+ await discardReceiver("The ancestor runtime does not support event-driven streams.");
14000
+ return {
14001
+ ok: false,
14002
+ error: "The ancestor runtime does not support event-driven streams.",
14003
+ data: { code: "unsupported" }
14004
+ };
14005
+ }
14006
+ abortRemote = (error) => {
14007
+ void stub.proxyStreamAbort(opened.id).catch(() => {
14008
+ });
14009
+ if (error) {
14010
+ void instance.proxyStreamReceive(receiver.id, { type: "abort", error });
14011
+ }
14012
+ };
14006
14013
  return {
14007
14014
  ok: true,
14008
- duplex: this.buildProxyDuplex(
14009
- stub,
14010
- opened.id,
14011
- opened.parkedPull === true
14012
- )
14015
+ duplex: this.buildEventProxyDuplex(stub, opened.id, receiver, instance)
14013
14016
  };
14014
14017
  }
14015
14018
  if (opened.error && !opened.noClient) {
14019
+ await discardReceiver(opened.error);
14016
14020
  return {
14017
14021
  ok: false,
14018
14022
  error: opened.error,
@@ -14024,69 +14028,21 @@ var init_ThreadStateImpl = __esm({
14024
14028
  }
14025
14029
  parentId = await this.resolveParentThreadId(parentId);
14026
14030
  }
14031
+ await discardReceiver(local.error ?? "No execution-owner bridge is available.");
14027
14032
  return local;
14028
14033
  }
14029
14034
  /**
14030
14035
  * Build a client duplex that bridges to a stream opened on an ancestor DO
14031
- * (the bridge holder) via chunk-pull RPCs. `readable` issues PARKED pulls —
14032
- * a current ancestor holds one `proxyStreamPull` until bytes, completion,
14033
- * error, or abort, so an idle open stream performs zero repeated pulls.
14034
- * Older ancestors use the bounded long-pull compatibility path. `writable`
14035
- * forwards each chunk with `proxyStreamWrite`; teardown calls
14036
- * `proxyStreamAbort`.
14036
+ * (the bridge holder). The readable is the receiver registered on this DO;
14037
+ * writes and terminal actions are the only child-to-ancestor RPCs.
14037
14038
  */
14038
- static PROXY_PULL_MAX_WAIT_MS = 2e4;
14039
- buildProxyDuplex(stub, id, supportsParkedPull = false) {
14040
- let settleDone;
14041
- const done = new Promise((r) => settleDone = r);
14039
+ buildEventProxyDuplex(stub, id, receiver, instance) {
14042
14040
  let closed = false;
14043
- let settled = false;
14044
- const settle = (result) => {
14045
- if (settled) return;
14046
- settled = true;
14047
- settleDone(result);
14041
+ const settleLocal = (error) => {
14042
+ if (typeof instance.proxyStreamReceive !== "function") return;
14043
+ const frame = error ? { type: "abort", error } : { type: "end" };
14044
+ void instance.proxyStreamReceive(receiver.id, frame);
14048
14045
  };
14049
- const readable = new ReadableStream({
14050
- async pull(controller) {
14051
- while (!closed) {
14052
- const pullStartedAt = Date.now();
14053
- let res;
14054
- try {
14055
- res = await stub.proxyStreamPull(
14056
- id,
14057
- supportsParkedPull ? void 0 : _ThreadStateImpl.PROXY_PULL_MAX_WAIT_MS
14058
- );
14059
- } catch (error) {
14060
- controller.error(error instanceof Error ? error : new Error(String(error)));
14061
- settle({ ok: false, error: "proxy stream pull failed" });
14062
- return;
14063
- }
14064
- for (const chunk of res.chunks) {
14065
- controller.enqueue(decodeStreamChunk(chunk));
14066
- }
14067
- if (res.done) {
14068
- controller.close();
14069
- settle(res.error ? { ok: false, error: res.error } : { ok: true });
14070
- return;
14071
- }
14072
- if (res.chunks.length > 0) return;
14073
- if (supportsParkedPull) {
14074
- controller.error(new Error("parked proxy pull returned without data"));
14075
- settle({ ok: false, error: "parked proxy pull returned without data" });
14076
- return;
14077
- }
14078
- if (Date.now() - pullStartedAt < 250) {
14079
- await new Promise((r) => setTimeout(r, 250));
14080
- }
14081
- }
14082
- },
14083
- cancel() {
14084
- closed = true;
14085
- void stub.proxyStreamAbort(id).catch(() => {
14086
- });
14087
- settle({ ok: false, error: "proxy stream reader canceled" });
14088
- }
14089
- });
14090
14046
  const writable = new WritableStream({
14091
14047
  async write(chunk) {
14092
14048
  await stub.proxyStreamWrite(id, encodeStreamChunk(chunk));
@@ -14099,20 +14055,20 @@ var init_ThreadStateImpl = __esm({
14099
14055
  closed = true;
14100
14056
  void stub.proxyStreamAbort(id).catch(() => {
14101
14057
  });
14102
- settle({ ok: false, error: "proxy stream writer aborted" });
14058
+ settleLocal("The proxy stream writer was aborted.");
14103
14059
  }
14104
14060
  });
14105
14061
  return {
14106
- readable,
14062
+ readable: receiver.readable,
14107
14063
  writable,
14108
14064
  close: (error) => {
14109
14065
  if (closed) return;
14110
14066
  closed = true;
14111
14067
  void stub.proxyStreamAbort(id).catch(() => {
14112
14068
  });
14113
- settle(error ? { ok: false, error } : { ok: true });
14069
+ settleLocal(error);
14114
14070
  },
14115
- done
14071
+ done: receiver.done
14116
14072
  };
14117
14073
  }
14118
14074
  isNoClient(res) {
@@ -68027,7 +67983,14 @@ function isHostedInstance(env2) {
68027
67983
  }
68028
67984
  return Boolean(value);
68029
67985
  }
68030
- function isTrustedLocalDevelopmentRequest(request, env2) {
67986
+ function compiledTrustedDevHosts() {
67987
+ try {
67988
+ return typeof __STANDARD_AGENTS_TRUSTED_DEV_HOSTS__ !== "undefined" && Array.isArray(__STANDARD_AGENTS_TRUSTED_DEV_HOSTS__) ? __STANDARD_AGENTS_TRUSTED_DEV_HOSTS__ : [];
67989
+ } catch {
67990
+ return [];
67991
+ }
67992
+ }
67993
+ function isTrustedLocalDevelopmentRequest(request, env2, trustedDevHosts = compiledTrustedDevHosts()) {
68031
67994
  if (isHostedInstance(env2)) return false;
68032
67995
  let hostname;
68033
67996
  try {
@@ -68035,7 +67998,7 @@ function isTrustedLocalDevelopmentRequest(request, env2) {
68035
67998
  } catch {
68036
67999
  return false;
68037
68000
  }
68038
- return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1" || hostname.endsWith(".localhost") || hostname.endsWith(".orb.local");
68001
+ return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1" || hostname.endsWith(".localhost") || hostname.endsWith(".orb.local") || trustedDevHosts.some((trusted) => trusted.trim().toLowerCase() === hostname);
68039
68002
  }
68040
68003
  function requestObservedOrigins(request) {
68041
68004
  const origins = /* @__PURE__ */ new Set();
@@ -68899,7 +68862,7 @@ var config_get_default = defineController2(async ({ config, env: env2, req }) =>
68899
68862
  });
68900
68863
 
68901
68864
  // src/version.ts
68902
- var BUILDER_VERSION = "0.40.5-next.3b25e2a".length > 0 ? "0.40.5-next.3b25e2a" : "dev";
68865
+ var BUILDER_VERSION = "0.40.6".length > 0 ? "0.40.6" : "dev";
68903
68866
 
68904
68867
  // src/api/diagnostics.get.ts
68905
68868
  init_LLMRequest();
@@ -75494,11 +75457,8 @@ var tool_result_post_default = defineController2(async ({ req, params, env: env2
75494
75457
  if (!delivered) {
75495
75458
  return Response.json({ status: "ignored" }, { status: 200 });
75496
75459
  }
75497
- if (delivered.resume) {
75498
- await stub.continueExecution(threadId, delivered.side);
75499
- return Response.json({ status: "resumed", side: delivered.side }, { status: 200 });
75500
- }
75501
- return Response.json({ status: "delivered", side: delivered.side }, { status: 200 });
75460
+ await stub.continueExecution(threadId, delivered.side);
75461
+ return Response.json({ status: "resumed", side: delivered.side }, { status: 200 });
75502
75462
  } catch (error) {
75503
75463
  console.error(`Error delivering tool result for thread ${threadId}:`, error);
75504
75464
  return Response.json(