@getpaseo/server 0.7.0-beta.3 → 0.7.0

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.
@@ -1412,6 +1412,7 @@ export class AgentManager {
1412
1412
  }
1413
1413
  agent.pendingReplacement = false;
1414
1414
  const errorMsg = error instanceof Error ? error.message : "Failed to start turn";
1415
+ pendingRun.start = { status: "failed", error: errorMsg };
1415
1416
  await this.handleStreamEvent(agent, {
1416
1417
  type: "turn_failed",
1417
1418
  provider: agent.provider,
@@ -1464,8 +1465,7 @@ export class AgentManager {
1464
1465
  agent.pendingReplacement = false;
1465
1466
  }
1466
1467
  const turnStartedAt = new Date();
1467
- pendingRun.started = true;
1468
- pendingRun.turnId = turnId;
1468
+ pendingRun.start = { status: "started", turnId };
1469
1469
  agent.activeForegroundTurnId = turnId;
1470
1470
  this.openActiveTurn(agent, turnId, turnStartedAt);
1471
1471
  agent.lifecycle = "running";
@@ -1739,7 +1739,8 @@ export class AgentManager {
1739
1739
  throw new Error(`Agent ${agentId} not found`);
1740
1740
  }
1741
1741
  const pendingRun = this.runs.getPendingRun(agentId);
1742
- if ((snapshot.lifecycle === "running" || pendingRun?.started) && !snapshot.pendingReplacement) {
1742
+ if ((snapshot.lifecycle === "running" || pendingRun?.start.status === "started") &&
1743
+ !snapshot.pendingReplacement) {
1743
1744
  return;
1744
1745
  }
1745
1746
  if (!snapshot.activeForegroundTurnId && !pendingRun && !snapshot.pendingReplacement) {
@@ -1794,12 +1795,16 @@ export class AgentManager {
1794
1795
  return true;
1795
1796
  }
1796
1797
  const currentPendingRun = this.runs.getPendingRun(agentId);
1797
- if ((current.lifecycle === "running" || currentPendingRun?.started) &&
1798
+ if ((current.lifecycle === "running" || currentPendingRun?.start.status === "started") &&
1798
1799
  !current.pendingReplacement) {
1799
1800
  finishOk();
1800
1801
  return true;
1801
1802
  }
1802
- if (current.lifecycle === "error" && !currentPendingRun?.started) {
1803
+ if (currentPendingRun?.start.status === "failed") {
1804
+ finishErr(new Error(currentPendingRun.start.error));
1805
+ return true;
1806
+ }
1807
+ if (current.lifecycle === "error" && !currentPendingRun) {
1803
1808
  finishErr(new Error(current.lastError ?? `Agent ${agentId} failed to start`));
1804
1809
  return true;
1805
1810
  }
@@ -1865,13 +1870,14 @@ export class AgentManager {
1865
1870
  if (!interruptAcknowledged) {
1866
1871
  return { status: settlement === "completed" ? "settled" : "refused" };
1867
1872
  }
1868
- if (settlement === "timed_out" && run.turnId) {
1869
- this.logger.warn({ agentId, turnId: run.turnId, kind: run.kind }, "cancelAgentRun: acknowledged turn still active after timeout, force-canceling");
1873
+ const runTurnId = this.runs.getTurnId(agentId);
1874
+ if (settlement === "timed_out" && runTurnId) {
1875
+ this.logger.warn({ agentId, turnId: runTurnId, kind: run.kind }, "cancelAgentRun: acknowledged turn still active after timeout, force-canceling");
1870
1876
  await this.dispatchSessionEvent(agent, {
1871
1877
  type: "turn_canceled",
1872
1878
  provider: agent.provider,
1873
1879
  reason: "interrupted",
1874
- turnId: run.turnId,
1880
+ turnId: runTurnId,
1875
1881
  });
1876
1882
  await run.settledPromise;
1877
1883
  }
@@ -2090,7 +2096,7 @@ export class AgentManager {
2090
2096
  let currentStatus = initialStatus;
2091
2097
  let hasStarted = isAgentBusy(initialStatus) ||
2092
2098
  Boolean(snapshot.activeForegroundTurnId) ||
2093
- Boolean(pendingForegroundRun?.started);
2099
+ pendingForegroundRun?.start.status === "started";
2094
2100
  let terminalStatusOverride = null;
2095
2101
  let finished = false;
2096
2102
  // Bug #3 Fix: Declare unsubscribe and abortHandler upfront so cleanup can reference them
@@ -2395,7 +2401,7 @@ export class AgentManager {
2395
2401
  return;
2396
2402
  }
2397
2403
  const pendingRun = this.runs.getPendingRun(agentId);
2398
- if (pendingRun && !pendingRun.started) {
2404
+ if (pendingRun?.start.status === "pending") {
2399
2405
  pendingRun.stagedEvents.push(event);
2400
2406
  return;
2401
2407
  }
@@ -10,8 +10,15 @@ export interface PendingForegroundRun {
10
10
  token: string;
11
11
  kind: "foreground";
12
12
  stagedEvents: AgentStreamEvent[];
13
- turnId: string | null;
14
- started: boolean;
13
+ start: {
14
+ status: "pending";
15
+ } | {
16
+ status: "started";
17
+ turnId: string;
18
+ } | {
19
+ status: "failed";
20
+ error: string;
21
+ };
15
22
  settled: boolean;
16
23
  settledPromise: Promise<void>;
17
24
  resolveSettled: () => void;
@@ -37,6 +44,7 @@ export declare class AgentRunState {
37
44
  hasPendingRun(agentId: string): boolean;
38
45
  getRun(agentId: string): TrackedAgentRun | null;
39
46
  hasRun(agentId: string): boolean;
47
+ getTurnId(agentId: string): string | null;
40
48
  trackAutonomousRun(agentId: string, turnId: string | null): TrackedAgentRun;
41
49
  settleTerminalRun(agentId: string, turnId: string | undefined): void;
42
50
  settleForegroundRun(agentId: string, token: string): void;
@@ -22,6 +22,14 @@ export class AgentRunState {
22
22
  hasRun(agentId) {
23
23
  return this.runs.has(agentId);
24
24
  }
25
+ getTurnId(agentId) {
26
+ const run = this.runs.get(agentId);
27
+ if (!run)
28
+ return null;
29
+ if (run.kind === "autonomous")
30
+ return run.turnId;
31
+ return run.start.status === "started" ? run.start.turnId : null;
32
+ }
25
33
  trackAutonomousRun(agentId, turnId) {
26
34
  const current = this.runs.get(agentId);
27
35
  if (current) {
@@ -41,7 +49,8 @@ export class AgentRunState {
41
49
  if (!run) {
42
50
  return;
43
51
  }
44
- if (run.kind === "foreground" && (run.turnId === null || run.turnId !== turnId)) {
52
+ if (run.kind === "foreground" &&
53
+ (run.start.status !== "started" || run.start.turnId !== turnId)) {
45
54
  return;
46
55
  }
47
56
  if (run.kind === "autonomous" &&
@@ -177,8 +186,7 @@ function createPendingForegroundRun() {
177
186
  return {
178
187
  ...createTrackedRunState(),
179
188
  kind: "foreground",
180
- turnId: null,
181
- started: false,
189
+ start: { status: "pending" },
182
190
  stagedEvents: [],
183
191
  };
184
192
  }
@@ -57,6 +57,7 @@ export declare class JsonlRpcProcess {
57
57
  /** Route a complete logical frame to its consumer (response or subscriber). */
58
58
  private dispatchFrame;
59
59
  private handleResponse;
60
+ private handleStdinError;
60
61
  private failAll;
61
62
  }
62
63
  //# sourceMappingURL=jsonl-rpc-process.d.ts.map
@@ -52,6 +52,9 @@ export class JsonlRpcProcess {
52
52
  this.stderrBuffer = this.stderrBuffer.slice(-STDERR_BUFFER_LIMIT);
53
53
  }
54
54
  });
55
+ this.child.stdin.on("error", (error) => {
56
+ this.handleStdinError(error);
57
+ });
55
58
  this.child.on("error", (error) => {
56
59
  this.failAll(error instanceof Error ? error : new Error(String(error)));
57
60
  });
@@ -103,10 +106,19 @@ export class JsonlRpcProcess {
103
106
  return this.startRequest(command, timeoutMs).promise;
104
107
  }
105
108
  send(message) {
106
- if (this.disposed || this.child.stdin.destroyed || !this.child.stdin.writable) {
109
+ if (this.disposed) {
110
+ return;
111
+ }
112
+ if (this.child.stdin.destroyed || !this.child.stdin.writable) {
113
+ this.handleStdinError(new Error(`${this.diagnosticName} stdin is not writable`));
107
114
  return;
108
115
  }
109
- this.child.stdin.write(`${JSON.stringify(message)}\n`);
116
+ try {
117
+ this.child.stdin.write(`${JSON.stringify(message)}\n`);
118
+ }
119
+ catch (error) {
120
+ this.handleStdinError(error);
121
+ }
110
122
  }
111
123
  async close(error = new Error(`${this.diagnosticName} process is closed`)) {
112
124
  if (this.disposed)
@@ -160,6 +172,14 @@ export class JsonlRpcProcess {
160
172
  }
161
173
  pending.resolve(response.data);
162
174
  }
175
+ handleStdinError(error) {
176
+ if (this.disposed) {
177
+ return;
178
+ }
179
+ const err = error instanceof Error ? error : new Error(String(error));
180
+ this.options.logger.warn({ err }, `${this.diagnosticName} stdin write failed`);
181
+ void this.close(err);
182
+ }
163
183
  failAll(error) {
164
184
  if (this.disposed) {
165
185
  return;
@@ -252,8 +252,8 @@ export declare const OmpSubagentStatusSchema: z.ZodEnum<{
252
252
  running: "running";
253
253
  completed: "completed";
254
254
  failed: "failed";
255
- aborted: "aborted";
256
255
  pending: "pending";
256
+ aborted: "aborted";
257
257
  }>;
258
258
  export declare const OmpSubagentLifecyclePayloadSchema: z.ZodObject<{
259
259
  id: z.ZodString;
@@ -277,8 +277,8 @@ export declare const OmpSubagentProgressSchema: z.ZodObject<{
277
277
  running: "running";
278
278
  completed: "completed";
279
279
  failed: "failed";
280
- aborted: "aborted";
281
280
  pending: "pending";
281
+ aborted: "aborted";
282
282
  }>;
283
283
  description: z.ZodOptional<z.ZodString>;
284
284
  currentTool: z.ZodOptional<z.ZodUnknown>;
@@ -299,8 +299,8 @@ export declare const OmpSubagentProgressPayloadSchema: z.ZodObject<{
299
299
  running: "running";
300
300
  completed: "completed";
301
301
  failed: "failed";
302
- aborted: "aborted";
303
302
  pending: "pending";
303
+ aborted: "aborted";
304
304
  }>;
305
305
  description: z.ZodOptional<z.ZodString>;
306
306
  currentTool: z.ZodOptional<z.ZodUnknown>;
@@ -1372,8 +1372,8 @@ export declare const OmpRuntimeEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject
1372
1372
  running: "running";
1373
1373
  completed: "completed";
1374
1374
  failed: "failed";
1375
- aborted: "aborted";
1376
1375
  pending: "pending";
1376
+ aborted: "aborted";
1377
1377
  }>;
1378
1378
  description: z.ZodOptional<z.ZodString>;
1379
1379
  currentTool: z.ZodOptional<z.ZodUnknown>;
@@ -1978,7 +1978,7 @@ function shouldSuppressOpenCodeAssistantPart(part, messageRole, state) {
1978
1978
  }
1979
1979
  function appendOpenCodeTextPart(part, messageRole, state, events) {
1980
1980
  if (messageRole === "user") {
1981
- if (!part.time?.end || !part.text || state.emittedUserMessageIds?.has(part.messageID)) {
1981
+ if (!part.text || state.emittedUserMessageIds?.has(part.messageID)) {
1982
1982
  return;
1983
1983
  }
1984
1984
  state.emittedUserMessageIds?.add(part.messageID);