@standardagents/builder 0.40.5 → 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
  }
@@ -13978,27 +13972,51 @@ var init_ThreadStateImpl = __esm({
13978
13972
  const withWake = (threadId) => wakeUserId ? { ...request, wake: { threadId, userId: wakeUserId } } : request;
13979
13973
  const local = await instance.openClientStream(withWake(this._metadata.id));
13980
13974
  if (local.ok || !this.isNoClient(local)) return local;
13981
- const env2 = this._threadInstance.env;
13982
- 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;
13983
13984
  const seen = /* @__PURE__ */ new Set([this._metadata.id]);
13984
13985
  let parentId = await this.resolveParentThreadId(this._metadata.id);
13985
13986
  while (parentId && !seen.has(parentId)) {
13986
13987
  seen.add(parentId);
13987
13988
  try {
13988
- const stub = env2.AGENT_BUILDER_THREAD.get(env2.AGENT_BUILDER_THREAD.idFromName(parentId));
13989
+ const stub = namespace.get(namespace.idFromName(parentId));
13989
13990
  if (typeof stub.proxyStreamOpen === "function") {
13990
- 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
+ });
13991
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
+ };
13992
14013
  return {
13993
14014
  ok: true,
13994
- duplex: this.buildProxyDuplex(
13995
- stub,
13996
- opened.id,
13997
- opened.parkedPull === true
13998
- )
14015
+ duplex: this.buildEventProxyDuplex(stub, opened.id, receiver, instance)
13999
14016
  };
14000
14017
  }
14001
14018
  if (opened.error && !opened.noClient) {
14019
+ await discardReceiver(opened.error);
14002
14020
  return {
14003
14021
  ok: false,
14004
14022
  error: opened.error,
@@ -14010,69 +14028,21 @@ var init_ThreadStateImpl = __esm({
14010
14028
  }
14011
14029
  parentId = await this.resolveParentThreadId(parentId);
14012
14030
  }
14031
+ await discardReceiver(local.error ?? "No execution-owner bridge is available.");
14013
14032
  return local;
14014
14033
  }
14015
14034
  /**
14016
14035
  * Build a client duplex that bridges to a stream opened on an ancestor DO
14017
- * (the bridge holder) via chunk-pull RPCs. `readable` issues PARKED pulls —
14018
- * a current ancestor holds one `proxyStreamPull` until bytes, completion,
14019
- * error, or abort, so an idle open stream performs zero repeated pulls.
14020
- * Older ancestors use the bounded long-pull compatibility path. `writable`
14021
- * forwards each chunk with `proxyStreamWrite`; teardown calls
14022
- * `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.
14023
14038
  */
14024
- static PROXY_PULL_MAX_WAIT_MS = 2e4;
14025
- buildProxyDuplex(stub, id, supportsParkedPull = false) {
14026
- let settleDone;
14027
- const done = new Promise((r) => settleDone = r);
14039
+ buildEventProxyDuplex(stub, id, receiver, instance) {
14028
14040
  let closed = false;
14029
- let settled = false;
14030
- const settle = (result) => {
14031
- if (settled) return;
14032
- settled = true;
14033
- 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);
14034
14045
  };
14035
- const readable = new ReadableStream({
14036
- async pull(controller) {
14037
- while (!closed) {
14038
- const pullStartedAt = Date.now();
14039
- let res;
14040
- try {
14041
- res = await stub.proxyStreamPull(
14042
- id,
14043
- supportsParkedPull ? void 0 : _ThreadStateImpl.PROXY_PULL_MAX_WAIT_MS
14044
- );
14045
- } catch (error) {
14046
- controller.error(error instanceof Error ? error : new Error(String(error)));
14047
- settle({ ok: false, error: "proxy stream pull failed" });
14048
- return;
14049
- }
14050
- for (const chunk of res.chunks) {
14051
- controller.enqueue(decodeStreamChunk(chunk));
14052
- }
14053
- if (res.done) {
14054
- controller.close();
14055
- settle(res.error ? { ok: false, error: res.error } : { ok: true });
14056
- return;
14057
- }
14058
- if (res.chunks.length > 0) return;
14059
- if (supportsParkedPull) {
14060
- controller.error(new Error("parked proxy pull returned without data"));
14061
- settle({ ok: false, error: "parked proxy pull returned without data" });
14062
- return;
14063
- }
14064
- if (Date.now() - pullStartedAt < 250) {
14065
- await new Promise((r) => setTimeout(r, 250));
14066
- }
14067
- }
14068
- },
14069
- cancel() {
14070
- closed = true;
14071
- void stub.proxyStreamAbort(id).catch(() => {
14072
- });
14073
- settle({ ok: false, error: "proxy stream reader canceled" });
14074
- }
14075
- });
14076
14046
  const writable = new WritableStream({
14077
14047
  async write(chunk) {
14078
14048
  await stub.proxyStreamWrite(id, encodeStreamChunk(chunk));
@@ -14085,20 +14055,20 @@ var init_ThreadStateImpl = __esm({
14085
14055
  closed = true;
14086
14056
  void stub.proxyStreamAbort(id).catch(() => {
14087
14057
  });
14088
- settle({ ok: false, error: "proxy stream writer aborted" });
14058
+ settleLocal("The proxy stream writer was aborted.");
14089
14059
  }
14090
14060
  });
14091
14061
  return {
14092
- readable,
14062
+ readable: receiver.readable,
14093
14063
  writable,
14094
14064
  close: (error) => {
14095
14065
  if (closed) return;
14096
14066
  closed = true;
14097
14067
  void stub.proxyStreamAbort(id).catch(() => {
14098
14068
  });
14099
- settle(error ? { ok: false, error } : { ok: true });
14069
+ settleLocal(error);
14100
14070
  },
14101
- done
14071
+ done: receiver.done
14102
14072
  };
14103
14073
  }
14104
14074
  isNoClient(res) {
@@ -68892,7 +68862,7 @@ var config_get_default = defineController2(async ({ config, env: env2, req }) =>
68892
68862
  });
68893
68863
 
68894
68864
  // src/version.ts
68895
- var BUILDER_VERSION = "0.40.5".length > 0 ? "0.40.5" : "dev";
68865
+ var BUILDER_VERSION = "0.40.6".length > 0 ? "0.40.6" : "dev";
68896
68866
 
68897
68867
  // src/api/diagnostics.get.ts
68898
68868
  init_LLMRequest();