@cydm/pie 2.7.4 → 2.7.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.
@@ -5,18 +5,37 @@ import { createRequire as __createRequire } from "node:module"; const require =
5
5
  import { randomUUID as randomUUID2 } from "node:crypto";
6
6
  import { pathToFileURL } from "node:url";
7
7
 
8
+ // vendor/computer-use-axi/src/test-backend-guard.ts
9
+ function requireFakeBackend(env = process.env) {
10
+ return env.PIE_COMPUTER_USE_REQUIRE_FAKE_BACKEND === "1";
11
+ }
12
+ function resolveTestOnlyBackend(env = process.env) {
13
+ if (requireFakeBackend(env) && (env.PIE_COMPUTER_USE_FAKE_BACKEND !== "1" || env.PIE_COMPUTER_USE_ENABLE_TEST_COMMANDS !== "1")) {
14
+ throw new Error("Required fake backend needs PIE_COMPUTER_USE_FAKE_BACKEND=1 and PIE_COMPUTER_USE_ENABLE_TEST_COMMANDS=1.");
15
+ }
16
+ if (env.PIE_COMPUTER_USE_FAKE_BACKEND !== "1") return { enabled: false };
17
+ if (env.PIE_COMPUTER_USE_ENABLE_TEST_COMMANDS !== "1") {
18
+ return {
19
+ enabled: false,
20
+ warning: "PIE_COMPUTER_USE_FAKE_BACKEND is test-only and was ignored: it requires PIE_COMPUTER_USE_ENABLE_TEST_COMMANDS=1 as well."
21
+ };
22
+ }
23
+ return { enabled: true };
24
+ }
25
+
8
26
  // vendor/computer-use-axi/src/broker-client.ts
9
27
  import { spawn } from "node:child_process";
10
28
  import { closeSync, existsSync as existsSync2, mkdirSync as mkdirSync2, openSync } from "node:fs";
11
29
  import net from "node:net";
12
- import path3 from "node:path";
30
+ import path4 from "node:path";
13
31
  import { fileURLToPath as fileURLToPath2 } from "node:url";
14
32
 
15
33
  // vendor/computer-use-axi/src/broker-protocol.ts
16
34
  import { createHash, randomUUID } from "node:crypto";
17
- import path2 from "node:path";
35
+ import path3 from "node:path";
18
36
 
19
- // vendor/computer-use-axi/src/persist.ts
37
+ // vendor/computer-use-axi/src/config.ts
38
+ import { AsyncLocalStorage } from "node:async_hooks";
20
39
  import path from "node:path";
21
40
 
22
41
  // src/config.ts
@@ -60,11 +79,59 @@ function getConfigDir() {
60
79
  return join(homedir(), CONFIG_DIR_NAME);
61
80
  }
62
81
 
82
+ // vendor/computer-use-axi/src/config.ts
83
+ var DEFAULT_CONFIG = {
84
+ browser_use: true,
85
+ headless: false,
86
+ cursor_overlay: true,
87
+ managed_browser: "chrome"
88
+ };
89
+ var REQUEST_ENV_KEYS = ["PIE_COMPUTER_USE_BROWSER_USE", "PIE_COMPUTER_USE_HEADLESS", "PIE_COMPUTER_USE_CURSOR_OVERLAY", "PIE_COMPUTER_USE_MANAGED_BROWSER", "PIE_COMPUTER_USE_HELIUM_EXECUTABLE", "PIE_COMPUTER_USE_CHROME_EXECUTABLE", "PIE_COMPUTER_USE_CDP_PORT", "PIE_COMPUTER_USE_DELIVERY_POLICY", "PIE_COMPUTER_USE_EVENT_DELIVERY"];
90
+ function captureComputerUseEnvironment(env = process.env) {
91
+ const out = {};
92
+ for (const key of REQUEST_ENV_KEYS) {
93
+ const value = env[key]?.trim();
94
+ if (!value) continue;
95
+ if (Buffer.byteLength(value) > 4096 || value.includes("\0")) throw new Error(`Invalid ${key}`);
96
+ if (["PIE_COMPUTER_USE_BROWSER_USE", "PIE_COMPUTER_USE_HEADLESS", "PIE_COMPUTER_USE_CURSOR_OVERLAY"].includes(key)) {
97
+ const parsed = parseBoolean(value);
98
+ if (parsed === void 0) throw new Error(`Invalid ${key}`);
99
+ out[key] = String(parsed);
100
+ } else if (key === "PIE_COMPUTER_USE_MANAGED_BROWSER") {
101
+ if (value !== "helium" && value !== "chrome") throw new Error(`Invalid ${key}`);
102
+ out[key] = value;
103
+ } else if (key === "PIE_COMPUTER_USE_DELIVERY_POLICY" || key === "PIE_COMPUTER_USE_EVENT_DELIVERY") {
104
+ const policy = value.toLowerCase();
105
+ if (!["default", "background", "pid", "foreground", "hid", "ax_only", "ax-only"].includes(policy)) throw new Error(`Invalid ${key}`);
106
+ out[key] = policy;
107
+ } else if (key === "PIE_COMPUTER_USE_CDP_PORT") {
108
+ if (!/^\d+$/.test(value) || Number(value) < 1 || Number(value) > 65535) throw new Error(`Invalid ${key}`);
109
+ out[key] = String(Number(value));
110
+ } else {
111
+ if (!path.isAbsolute(value)) throw new Error(`Invalid ${key}: expected absolute path`);
112
+ out[key] = value;
113
+ }
114
+ }
115
+ return Object.freeze(out);
116
+ }
117
+ var operationConfig = new AsyncLocalStorage();
118
+ var defaultLoaded = Object.freeze({ config: Object.freeze({ ...DEFAULT_CONFIG }), sources: [], env: {}, environment: {} });
119
+ function parseBoolean(value) {
120
+ if (typeof value === "boolean") return value;
121
+ if (typeof value === "number") return value === 1 ? true : value === 0 ? false : void 0;
122
+ if (typeof value !== "string") return void 0;
123
+ const normalized = value.trim().toLowerCase();
124
+ if (["1", "true", "yes", "on", "enabled"].includes(normalized)) return true;
125
+ if (["0", "false", "no", "off", "disabled"].includes(normalized)) return false;
126
+ return void 0;
127
+ }
128
+
63
129
  // vendor/computer-use-axi/src/persist.ts
130
+ import path2 from "node:path";
64
131
  function stateRootDir(env = process.env) {
65
132
  const override = env.PIE_COMPUTER_USE_STATE_DIR?.trim();
66
133
  if (override) return override;
67
- return path.join(getConfigDir(), "computer-use");
134
+ return path2.join(getConfigDir(), "computer-use");
68
135
  }
69
136
 
70
137
  // src/runtime/computer-use-owner.ts
@@ -83,8 +150,8 @@ function computerUseOwnerFromEnv(env = process.env) {
83
150
  }
84
151
 
85
152
  // vendor/computer-use-axi/src/broker-protocol.ts
86
- var BROKER_PROTOCOL_VERSION = 1;
87
- var BROKER_ENGINE_VERSION = 2;
153
+ var BROKER_PROTOCOL_VERSION = 3;
154
+ var BROKER_ENGINE_VERSION = 4;
88
155
  var BROKER_PACKAGE_VERSION = "0.5.1-pie.1";
89
156
  var BROKER_MAX_FRAME_BYTES = 4 * 1024 * 1024;
90
157
  var BROKER_MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
@@ -132,6 +199,7 @@ var FrameDecoder = class {
132
199
  for (; ; ) {
133
200
  const newline = this.buffer.indexOf(10);
134
201
  if (newline < 0) break;
202
+ if (newline > this.maxBytes) throw new BrokerProtocolError("frame_too_large", `Frame exceeds the ${this.maxBytes}-byte limit.`);
135
203
  const line = this.buffer.subarray(0, newline).toString("utf8").trim();
136
204
  this.buffer = this.buffer.subarray(newline + 1);
137
205
  if (!line) continue;
@@ -156,11 +224,11 @@ function resolveBrokerEndpoint(env = process.env) {
156
224
  const key = createHash("sha256").update(seed).digest("hex").slice(0, 16);
157
225
  return { kind: "named-pipe", path: `\\\\.\\pipe\\pie-computer-use-axi-${key}` };
158
226
  }
159
- const socketPath = socketOverride || path2.join(stateRootDir(env), "run", "broker.sock");
227
+ const socketPath = socketOverride || path3.join(stateRootDir(env), "run", "broker.sock");
160
228
  if (Buffer.byteLength(socketPath, "utf8") > 100) {
161
229
  throw new BrokerProtocolError("endpoint_too_long", `Unix socket path is ${Buffer.byteLength(socketPath)} bytes (limit ~104): ${socketPath}. Set PIE_COMPUTER_USE_BROKER_SOCKET to a shorter path.`);
162
230
  }
163
- return { kind: "unix-socket", path: socketPath, directory: path2.dirname(socketPath) };
231
+ return { kind: "unix-socket", path: socketPath, directory: path3.dirname(socketPath) };
164
232
  }
165
233
 
166
234
  // vendor/computer-use-axi/src/broker-client.ts
@@ -192,7 +260,7 @@ var SocketFrames = class {
192
260
  socket.on("close", () => this.close());
193
261
  }
194
262
  socket;
195
- decoder = new FrameDecoder();
263
+ decoder = new FrameDecoder(BROKER_MAX_RESPONSE_BYTES);
196
264
  queue = [];
197
265
  waiters = [];
198
266
  closed = false;
@@ -240,12 +308,12 @@ function sleep(ms) {
240
308
  return new Promise((resolve2) => setTimeout(resolve2, ms));
241
309
  }
242
310
  function resolveBrokerSpawn() {
243
- const here = path3.dirname(fileURLToPath2(import.meta.url));
311
+ const here = path4.dirname(fileURLToPath2(import.meta.url));
244
312
  const override = process.env.PIE_COMPUTER_USE_BROKER_ENTRY?.trim();
245
313
  const candidates = [
246
314
  override,
247
- path3.join(here, "computer-use-axi-broker.js"),
248
- path3.join(here, "broker-main.ts")
315
+ path4.join(here, "computer-use-axi-broker.js"),
316
+ path4.join(here, "broker-main.ts")
249
317
  ].filter((candidate) => Boolean(candidate));
250
318
  for (const candidate of candidates) {
251
319
  if (!existsSync2(candidate)) continue;
@@ -259,9 +327,9 @@ function spawnBroker() {
259
327
  let stdio = "ignore";
260
328
  let logFd;
261
329
  try {
262
- const logDir = path3.join(stateRootDir(), "broker");
330
+ const logDir = path4.join(stateRootDir(), "broker");
263
331
  mkdirSync2(logDir, { recursive: true, mode: 448 });
264
- logFd = openSync(path3.join(logDir, "broker.log"), "a", 384);
332
+ logFd = openSync(path4.join(logDir, "broker.log"), "a", 384);
265
333
  stdio = ["ignore", logFd, logFd];
266
334
  } catch {
267
335
  stdio = "ignore";
@@ -309,6 +377,8 @@ function isBrokerResponse(value) {
309
377
  return Boolean(value) && typeof value === "object" && value.type === "response";
310
378
  }
311
379
  async function callBroker(options) {
380
+ if (options.command !== "stop") resolveTestOnlyBackend();
381
+ const environment = captureComputerUseEnvironment();
312
382
  const endpoint = resolveBrokerEndpoint();
313
383
  const budgetMs = Math.min(Math.max(options.budgetMs ?? BROKER_DEFAULT_REQUEST_BUDGET_MS, 100), 15 * 6e4);
314
384
  const spawnState = { spawned: false };
@@ -318,7 +388,7 @@ async function callBroker(options) {
318
388
  const socket = await connectOrSpawn(endpoint, options.spawnIfMissing !== false, spawnState);
319
389
  const frames = new SocketFrames(socket);
320
390
  try {
321
- socket.write(encodeFrame({ type: "hello", protocolVersion: BROKER_PROTOCOL_VERSION, clientVersion: "cli" }));
391
+ socket.write(encodeFrame({ type: "hello", protocolVersion: BROKER_PROTOCOL_VERSION, clientVersion: "cli", buildIdentity: BROKER_BUILD.identity }));
322
392
  const helloFrame = await frames.next(BROKER_HANDSHAKE_TIMEOUT_MS);
323
393
  if (!helloFrame || typeof helloFrame !== "object" || helloFrame.type !== "hello") {
324
394
  throw new BrokerCallError("broker_no_handshake", "The computer-use broker did not answer the protocol handshake.", { exitCode: 1 });
@@ -347,6 +417,12 @@ async function callBroker(options) {
347
417
  );
348
418
  }
349
419
  }
420
+ if (options.command !== "stop" && (hello.protocolVersion !== BROKER_PROTOCOL_VERSION || hello.build?.identity !== BROKER_BUILD.identity)) {
421
+ throw new BrokerCallError("broker_incompatible", "The running broker protocol or engine build differs. Run 'computer-use-axi stop' before retrying; no request was sent.", { exitCode: 3, incompatible: true, brokerPid: hello.pid });
422
+ }
423
+ if (options.command !== "stop" && requireFakeBackend() && (!hello.ok || hello.backend?.fakeInstalled !== true || hello.backend.requireFake !== true)) {
424
+ throw new BrokerCallError("broker_incompatible", "Required fake backend: running broker does not attest installed fake and enforced requirement; no request was sent.", { exitCode: 3, incompatible: true, brokerPid: hello.pid });
425
+ }
350
426
  const brokerProtocol = hello.protocolVersion ?? BROKER_PROTOCOL_VERSION;
351
427
  const request = {
352
428
  type: "request",
@@ -358,6 +434,7 @@ async function callBroker(options) {
358
434
  command: options.command,
359
435
  params: options.params,
360
436
  cwd: options.cwd,
437
+ environment,
361
438
  budgetMs
362
439
  };
363
440
  socket.write(encodeFrame(request));
@@ -4,7 +4,7 @@ import {
4
4
  disposeModelTransports,
5
5
  streamSimple,
6
6
  validateToolArguments
7
- } from "./chunk-Z4EIBY2E.js";
7
+ } from "./chunk-ZF5FHTES.js";
8
8
 
9
9
  // ../../packages/agent-core/src/agent-loop.ts
10
10
  function createLoopErrorMessage(error, config, signal) {
@@ -290,6 +290,7 @@ async function executeToolCalls(tools, assistantMessage, signal, stream, getStee
290
290
  } catch (e) {
291
291
  console.warn(`[AgentLoop] beforeToolCall hook failed for ${toolCall.name}:`, e);
292
292
  }
293
+ if (signal?.aborted) break;
293
294
  let result;
294
295
  let isError = false;
295
296
  let executionArgs = toolCall.arguments;
@@ -637,6 +638,8 @@ var Agent = class {
637
638
  return this.runningPrompt ?? Promise.resolve();
638
639
  }
639
640
  reset() {
641
+ this.abortController?.abort();
642
+ this.abortController = void 0;
640
643
  this.releaseTransport();
641
644
  this._state.messages = [];
642
645
  this._state.isStreaming = false;
@@ -660,6 +663,7 @@ var Agent = class {
660
663
  * Useful when resuming a session that was saved mid-processing.
661
664
  */
662
665
  resetProcessingState() {
666
+ this.abortController?.abort();
663
667
  this._state.isStreaming = false;
664
668
  this._state.streamMessage = null;
665
669
  this._state.pendingToolCalls = /* @__PURE__ */ new Set();
@@ -766,8 +770,10 @@ var Agent = class {
766
770
  async _runLoop(messages, options) {
767
771
  const model = this._state.model;
768
772
  if (!model) throw new Error("No model configured");
769
- this.abortController = new AbortController();
770
- bindToolCallerIdentity(this.abortController.signal, this.toolCallerIdentity);
773
+ const runController = new AbortController();
774
+ this.abortController = runController;
775
+ const ownsRun = () => this.abortController === runController;
776
+ bindToolCallerIdentity(runController.signal, this.toolCallerIdentity);
771
777
  this._state.isStreaming = true;
772
778
  this._state.streamMessage = null;
773
779
  this._state.error = void 0;
@@ -791,7 +797,7 @@ var Agent = class {
791
797
  getApiKey: this.getApiKey,
792
798
  hooks: this.hooks,
793
799
  getSteeringMessages: async () => {
794
- if (options?.suppressSteeringPolls) {
800
+ if (!ownsRun() || options?.suppressSteeringPolls) {
795
801
  return [];
796
802
  }
797
803
  if (skipInitialSteeringPoll) {
@@ -801,7 +807,7 @@ var Agent = class {
801
807
  return this.dequeueSteeringMessages();
802
808
  },
803
809
  getFollowUpMessages: async () => {
804
- if (options?.suppressFollowUpPolls) {
810
+ if (!ownsRun() || options?.suppressFollowUpPolls) {
805
811
  return [];
806
812
  }
807
813
  return this.dequeueFollowUpMessages();
@@ -809,8 +815,9 @@ var Agent = class {
809
815
  };
810
816
  let partial = null;
811
817
  try {
812
- const stream = messages ? agentLoop(messages, context, config, this.abortController.signal, this.streamFn) : agentLoopContinue(context, config, this.abortController.signal, this.streamFn);
818
+ const stream = messages ? agentLoop(messages, context, config, runController.signal, this.streamFn) : agentLoopContinue(context, config, runController.signal, this.streamFn);
813
819
  for await (const event of stream) {
820
+ if (!ownsRun()) return;
814
821
  switch (event.type) {
815
822
  case "message_start":
816
823
  partial = event.message;
@@ -847,9 +854,9 @@ var Agent = class {
847
854
  this._state.streamMessage = null;
848
855
  break;
849
856
  }
850
- this.emit(event);
857
+ this.emit(event, ownsRun);
851
858
  }
852
- if (partial && partial.role === "assistant" && partial.content?.length > 0) {
859
+ if (ownsRun() && partial && partial.role === "assistant" && partial.content?.length > 0) {
853
860
  const onlyEmpty = !partial.content.some(
854
861
  (c) => c.type === "thinking" && c.thinking?.trim().length > 0 || c.type === "text" && c.text?.trim().length > 0 || c.type === "toolCall" && c.name?.trim().length > 0
855
862
  );
@@ -859,6 +866,7 @@ var Agent = class {
859
866
  }
860
867
  }
861
868
  } catch (err) {
869
+ if (!ownsRun()) return;
862
870
  const errorMsg = {
863
871
  role: "assistant",
864
872
  content: [{ type: "text", text: "" }],
@@ -879,19 +887,22 @@ var Agent = class {
879
887
  };
880
888
  this.appendMessage(errorMsg);
881
889
  this._state.error = err?.message || String(err);
882
- this.emit({ type: "agent_end", messages: [errorMsg] });
890
+ this.emit({ type: "agent_end", messages: [errorMsg] }, ownsRun);
883
891
  } finally {
884
- this._state.isStreaming = false;
885
- this._state.streamMessage = null;
886
- this._state.pendingToolCalls = /* @__PURE__ */ new Set();
887
- this.abortController = void 0;
892
+ if (ownsRun()) {
893
+ this._state.isStreaming = false;
894
+ this._state.streamMessage = null;
895
+ this._state.pendingToolCalls = /* @__PURE__ */ new Set();
896
+ this.abortController = void 0;
897
+ }
888
898
  }
889
899
  }
890
900
  reportObserverError(kind, eventType, error) {
891
901
  console.warn(`[Agent] ${kind} failed while handling ${eventType}:`, error);
892
902
  }
893
- emit(e) {
903
+ emit(e, ownsRun = () => true) {
894
904
  for (const listener of this.listeners) {
905
+ if (!ownsRun()) return;
895
906
  try {
896
907
  listener(e);
897
908
  } catch (error) {
@@ -899,13 +910,14 @@ var Agent = class {
899
910
  }
900
911
  }
901
912
  try {
902
- this.emitDerivedSemanticEvents(e);
913
+ if (ownsRun()) this.emitDerivedSemanticEvents(e, ownsRun);
903
914
  } catch (error) {
904
915
  this.reportObserverError("derived semantic event", e.type, error);
905
916
  }
906
917
  }
907
- emitSemantic(e) {
918
+ emitSemantic(e, ownsRun = () => true) {
908
919
  for (const listener of this.semanticListeners) {
920
+ if (!ownsRun()) return;
909
921
  try {
910
922
  listener(e);
911
923
  } catch (error) {
@@ -913,7 +925,8 @@ var Agent = class {
913
925
  }
914
926
  }
915
927
  }
916
- updateStatusSnapshot(next) {
928
+ updateStatusSnapshot(next, ownsRun = () => true) {
929
+ if (!ownsRun()) return;
917
930
  const snapshot = {
918
931
  ...this.statusSnapshot,
919
932
  ...next
@@ -922,26 +935,32 @@ var Agent = class {
922
935
  return;
923
936
  }
924
937
  this.statusSnapshot = snapshot;
925
- this.emitSemantic({ type: "status_snapshot_changed", snapshot: { ...snapshot } });
938
+ this.emitSemantic({ type: "status_snapshot_changed", snapshot: { ...snapshot } }, ownsRun);
926
939
  }
927
- emitDerivedSemanticEvents(event) {
940
+ emitDerivedSemanticEvents(event, ownsRun) {
941
+ const publish = {
942
+ updateStatusSnapshot: (next) => this.updateStatusSnapshot(next, ownsRun),
943
+ emitSemantic: (event2) => {
944
+ if (ownsRun()) this.emitSemantic(event2, ownsRun);
945
+ }
946
+ };
928
947
  switch (event.type) {
929
948
  case "message_start":
930
949
  if (event.message.role === "assistant") {
931
- this.updateStatusSnapshot({
950
+ publish.updateStatusSnapshot({
932
951
  phase: "responding",
933
952
  turnState: "continuing",
934
953
  activeToolName: void 0,
935
954
  lastStopReason: void 0,
936
955
  hasPendingToolContinuation: false
937
956
  });
938
- this.emitSemantic({ type: "assistant_response_started", message: event.message });
957
+ publish.emitSemantic({ type: "assistant_response_started", message: event.message });
939
958
  }
940
959
  break;
941
960
  case "message_update":
942
961
  if (event.message.role === "assistant" && event.assistantMessageEvent.type === "text_delta") {
943
- this.updateStatusSnapshot({ phase: "responding" });
944
- this.emitSemantic({
962
+ publish.updateStatusSnapshot({ phase: "responding" });
963
+ publish.emitSemantic({
945
964
  type: "assistant_response_delta",
946
965
  message: event.message,
947
966
  delta: event.assistantMessageEvent.delta
@@ -950,18 +969,18 @@ var Agent = class {
950
969
  break;
951
970
  case "message_end":
952
971
  if (event.message.role === "assistant") {
953
- this.emitSemantic({ type: "assistant_response_finished", message: event.message });
972
+ publish.emitSemantic({ type: "assistant_response_finished", message: event.message });
954
973
  }
955
974
  break;
956
975
  case "tool_execution_start":
957
- this.updateStatusSnapshot({
976
+ publish.updateStatusSnapshot({
958
977
  phase: "running_tool",
959
978
  turnState: "continuing",
960
979
  activeToolName: event.toolName,
961
980
  lastStopReason: void 0,
962
981
  hasPendingToolContinuation: false
963
982
  });
964
- this.emitSemantic({
983
+ publish.emitSemantic({
965
984
  type: "tool_started",
966
985
  toolCallId: event.toolCallId,
967
986
  toolName: event.toolName,
@@ -969,7 +988,7 @@ var Agent = class {
969
988
  });
970
989
  break;
971
990
  case "tool_execution_update":
972
- this.emitSemantic({
991
+ publish.emitSemantic({
973
992
  type: "tool_progressed",
974
993
  toolCallId: event.toolCallId,
975
994
  toolName: event.toolName,
@@ -978,11 +997,11 @@ var Agent = class {
978
997
  });
979
998
  break;
980
999
  case "tool_execution_end":
981
- this.updateStatusSnapshot({
1000
+ publish.updateStatusSnapshot({
982
1001
  phase: this._state.isStreaming ? "responding" : "completed",
983
1002
  activeToolName: void 0
984
1003
  });
985
- this.emitSemantic({
1004
+ publish.emitSemantic({
986
1005
  type: "tool_finished",
987
1006
  toolCallId: event.toolCallId,
988
1007
  toolName: event.toolName,
@@ -996,40 +1015,40 @@ var Agent = class {
996
1015
  const hasToolCalls = event.message.role === "assistant" && Array.isArray(event.message.content) && event.message.content.some((block) => block.type === "toolCall");
997
1016
  if (stopReason === "error" || stopReason === "aborted") {
998
1017
  this.reportedFailureMessage = event.message;
999
- this.updateStatusSnapshot({
1018
+ publish.updateStatusSnapshot({
1000
1019
  phase: "failed",
1001
1020
  turnState: "failed",
1002
1021
  lastStopReason: stopReason,
1003
1022
  hasPendingToolContinuation: false,
1004
1023
  activeToolName: void 0
1005
1024
  });
1006
- this.emitSemantic({
1025
+ publish.emitSemantic({
1007
1026
  type: "turn_failed",
1008
1027
  message: event.message,
1009
1028
  toolResults: event.toolResults
1010
1029
  });
1011
1030
  } else if (hasToolCalls) {
1012
- this.updateStatusSnapshot({
1031
+ publish.updateStatusSnapshot({
1013
1032
  phase: "responding",
1014
1033
  turnState: "continuing",
1015
1034
  lastStopReason: stopReason,
1016
1035
  hasPendingToolContinuation: true,
1017
1036
  activeToolName: void 0
1018
1037
  });
1019
- this.emitSemantic({
1038
+ publish.emitSemantic({
1020
1039
  type: "turn_continues",
1021
1040
  message: event.message,
1022
1041
  toolResults: event.toolResults
1023
1042
  });
1024
1043
  } else {
1025
- this.updateStatusSnapshot({
1044
+ publish.updateStatusSnapshot({
1026
1045
  phase: "completed",
1027
1046
  turnState: "completed",
1028
1047
  lastStopReason: stopReason,
1029
1048
  hasPendingToolContinuation: false,
1030
1049
  activeToolName: void 0
1031
1050
  });
1032
- this.emitSemantic({
1051
+ publish.emitSemantic({
1033
1052
  type: "turn_completed",
1034
1053
  message: event.message,
1035
1054
  toolResults: event.toolResults
@@ -1042,20 +1061,20 @@ var Agent = class {
1042
1061
  const alreadyReported = lastMessage !== void 0 && lastMessage === this.reportedFailureMessage;
1043
1062
  this.reportedFailureMessage = void 0;
1044
1063
  if (!alreadyReported && lastMessage?.role === "assistant" && (lastMessage.stopReason === "error" || lastMessage.stopReason === "aborted")) {
1045
- this.updateStatusSnapshot({
1064
+ publish.updateStatusSnapshot({
1046
1065
  phase: "failed",
1047
1066
  turnState: "failed",
1048
1067
  lastStopReason: lastMessage.stopReason,
1049
1068
  hasPendingToolContinuation: false,
1050
1069
  activeToolName: void 0
1051
1070
  });
1052
- this.emitSemantic({
1071
+ publish.emitSemantic({
1053
1072
  type: "turn_failed",
1054
1073
  message: lastMessage,
1055
1074
  toolResults: []
1056
1075
  });
1057
1076
  }
1058
- this.updateStatusSnapshot({
1077
+ publish.updateStatusSnapshot({
1059
1078
  phase: "idle",
1060
1079
  activeToolName: void 0,
1061
1080
  hasPendingToolContinuation: false
@@ -6,10 +6,10 @@ import {
6
6
  createSharedWebSearchTool,
7
7
  interpretShellExit,
8
8
  requestInteraction
9
- } from "./chunk-FIE3SSLW.js";
9
+ } from "./chunk-YWWLRZSG.js";
10
10
  import {
11
11
  getLogger
12
- } from "./chunk-Z4EIBY2E.js";
12
+ } from "./chunk-ZF5FHTES.js";
13
13
  import {
14
14
  Type
15
15
  } from "./chunk-XXGYUYXI.js";