@agentex/agent 0.0.17 → 0.0.19
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.
- package/README.md +112 -17
- package/dist/derived.d.ts +69 -0
- package/dist/derived.d.ts.map +1 -0
- package/dist/derived.js +218 -0
- package/dist/derived.js.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/providers/_shared/http-agent.d.ts +39 -0
- package/dist/providers/_shared/http-agent.d.ts.map +1 -0
- package/dist/providers/_shared/http-agent.js +265 -0
- package/dist/providers/_shared/http-agent.js.map +1 -0
- package/dist/providers/acp/index.d.ts +29 -0
- package/dist/providers/acp/index.d.ts.map +1 -0
- package/dist/providers/acp/index.js +153 -0
- package/dist/providers/acp/index.js.map +1 -0
- package/dist/providers/acp/parse.d.ts +22 -0
- package/dist/providers/acp/parse.d.ts.map +1 -0
- package/dist/providers/acp/parse.js +122 -0
- package/dist/providers/acp/parse.js.map +1 -0
- package/dist/providers/acp/session.d.ts +36 -0
- package/dist/providers/acp/session.d.ts.map +1 -0
- package/dist/providers/acp/session.js +487 -0
- package/dist/providers/acp/session.js.map +1 -0
- package/dist/providers/claude/execute.d.ts.map +1 -1
- package/dist/providers/claude/execute.js +6 -2
- package/dist/providers/claude/execute.js.map +1 -1
- package/dist/providers/claude/index.d.ts.map +1 -1
- package/dist/providers/claude/index.js +1 -0
- package/dist/providers/claude/index.js.map +1 -1
- package/dist/providers/claude/parse.d.ts.map +1 -1
- package/dist/providers/claude/parse.js +8 -0
- package/dist/providers/claude/parse.js.map +1 -1
- package/dist/providers/claude/session.d.ts +25 -2
- package/dist/providers/claude/session.d.ts.map +1 -1
- package/dist/providers/claude/session.js +120 -7
- package/dist/providers/claude/session.js.map +1 -1
- package/dist/providers/codex/execute.d.ts.map +1 -1
- package/dist/providers/codex/execute.js +5 -1
- package/dist/providers/codex/execute.js.map +1 -1
- package/dist/providers/codex/index.d.ts.map +1 -1
- package/dist/providers/codex/index.js +3 -0
- package/dist/providers/codex/index.js.map +1 -1
- package/dist/providers/codex/modes.d.ts +35 -0
- package/dist/providers/codex/modes.d.ts.map +1 -0
- package/dist/providers/codex/modes.js +148 -0
- package/dist/providers/codex/modes.js.map +1 -0
- package/dist/providers/codex/parse.d.ts.map +1 -1
- package/dist/providers/codex/parse.js +4 -0
- package/dist/providers/codex/parse.js.map +1 -1
- package/dist/providers/codex/session.d.ts +41 -2
- package/dist/providers/codex/session.d.ts.map +1 -1
- package/dist/providers/codex/session.js +319 -16
- package/dist/providers/codex/session.js.map +1 -1
- package/dist/providers/copilot/index.d.ts +15 -0
- package/dist/providers/copilot/index.d.ts.map +1 -0
- package/dist/providers/copilot/index.js +19 -0
- package/dist/providers/copilot/index.js.map +1 -0
- package/dist/providers/cursor/index.d.ts.map +1 -1
- package/dist/providers/cursor/index.js +1 -0
- package/dist/providers/cursor/index.js.map +1 -1
- package/dist/providers/cursor/parse.d.ts.map +1 -1
- package/dist/providers/cursor/parse.js +1 -0
- package/dist/providers/cursor/parse.js.map +1 -1
- package/dist/providers/gemini/index.d.ts.map +1 -1
- package/dist/providers/gemini/index.js +16 -20
- package/dist/providers/gemini/index.js.map +1 -1
- package/dist/providers/openclaw/execute.d.ts +5 -0
- package/dist/providers/openclaw/execute.d.ts.map +1 -1
- package/dist/providers/openclaw/execute.js +13 -173
- package/dist/providers/openclaw/execute.js.map +1 -1
- package/dist/providers/openclaw/index.d.ts.map +1 -1
- package/dist/providers/openclaw/index.js +1 -0
- package/dist/providers/openclaw/index.js.map +1 -1
- package/dist/providers/opencode/event-parse.d.ts +23 -0
- package/dist/providers/opencode/event-parse.d.ts.map +1 -0
- package/dist/providers/opencode/event-parse.js +128 -0
- package/dist/providers/opencode/event-parse.js.map +1 -0
- package/dist/providers/opencode/http-session.d.ts +4 -0
- package/dist/providers/opencode/http-session.d.ts.map +1 -0
- package/dist/providers/opencode/http-session.js +376 -0
- package/dist/providers/opencode/http-session.js.map +1 -0
- package/dist/providers/opencode/index.d.ts.map +1 -1
- package/dist/providers/opencode/index.js +6 -1
- package/dist/providers/opencode/index.js.map +1 -1
- package/dist/providers/opencode/parse.d.ts.map +1 -1
- package/dist/providers/opencode/parse.js +1 -0
- package/dist/providers/opencode/parse.js.map +1 -1
- package/dist/providers/opencode/server.d.ts +8 -0
- package/dist/providers/opencode/server.d.ts.map +1 -0
- package/dist/providers/opencode/server.js +0 -0
- package/dist/providers/opencode/server.js.map +1 -0
- package/dist/providers/pi/index.d.ts.map +1 -1
- package/dist/providers/pi/index.js +6 -1
- package/dist/providers/pi/index.js.map +1 -1
- package/dist/providers/pi/parse.d.ts.map +1 -1
- package/dist/providers/pi/parse.js +1 -0
- package/dist/providers/pi/parse.js.map +1 -1
- package/dist/providers/pi/session.d.ts +40 -0
- package/dist/providers/pi/session.d.ts.map +1 -0
- package/dist/providers/pi/session.js +328 -0
- package/dist/providers/pi/session.js.map +1 -0
- package/dist/providers/process/index.d.ts.map +1 -1
- package/dist/providers/process/index.js +1 -0
- package/dist/providers/process/index.js.map +1 -1
- package/dist/registry.d.ts +1 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +6 -0
- package/dist/registry.js.map +1 -1
- package/dist/types.d.ts +113 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/tool-names.d.ts +24 -0
- package/dist/utils/tool-names.d.ts.map +1 -0
- package/dist/utils/tool-names.js +50 -0
- package/dist/utils/tool-names.js.map +1 -0
- package/package.json +22 -13
- package/dist/providers/claude/test.d.ts +0 -3
- package/dist/providers/claude/test.d.ts.map +0 -1
- package/dist/providers/claude/test.js +0 -167
- package/dist/providers/claude/test.js.map +0 -1
- package/dist/providers/codex/test.d.ts +0 -3
- package/dist/providers/codex/test.d.ts.map +0 -1
- package/dist/providers/codex/test.js +0 -74
- package/dist/providers/codex/test.js.map +0 -1
- package/dist/providers/cursor/test.d.ts +0 -3
- package/dist/providers/cursor/test.d.ts.map +0 -1
- package/dist/providers/cursor/test.js +0 -58
- package/dist/providers/cursor/test.js.map +0 -1
- package/dist/providers/gemini/codec.d.ts +0 -3
- package/dist/providers/gemini/codec.d.ts.map +0 -1
- package/dist/providers/gemini/codec.js +0 -47
- package/dist/providers/gemini/codec.js.map +0 -1
- package/dist/providers/gemini/execute.d.ts +0 -3
- package/dist/providers/gemini/execute.d.ts.map +0 -1
- package/dist/providers/gemini/execute.js +0 -256
- package/dist/providers/gemini/execute.js.map +0 -1
- package/dist/providers/gemini/parse.d.ts +0 -20
- package/dist/providers/gemini/parse.d.ts.map +0 -1
- package/dist/providers/gemini/parse.js +0 -235
- package/dist/providers/gemini/parse.js.map +0 -1
- package/dist/providers/gemini/test.d.ts +0 -3
- package/dist/providers/gemini/test.d.ts.map +0 -1
- package/dist/providers/gemini/test.js +0 -67
- package/dist/providers/gemini/test.js.map +0 -1
- package/dist/providers/openclaw/test.d.ts +0 -3
- package/dist/providers/openclaw/test.d.ts.map +0 -1
- package/dist/providers/openclaw/test.js +0 -54
- package/dist/providers/openclaw/test.js.map +0 -1
- package/dist/providers/opencode/test.d.ts +0 -3
- package/dist/providers/opencode/test.d.ts.map +0 -1
- package/dist/providers/opencode/test.js +0 -60
- package/dist/providers/opencode/test.js.map +0 -1
- package/dist/providers/pi/test.d.ts +0 -3
- package/dist/providers/pi/test.d.ts.map +0 -1
- package/dist/providers/pi/test.js +0 -60
- package/dist/providers/pi/test.js.map +0 -1
- package/dist/utils/model-cache.d.ts +0 -11
- package/dist/utils/model-cache.d.ts.map +0 -1
- package/dist/utils/model-cache.js +0 -17
- package/dist/utils/model-cache.js.map +0 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AgentSession, CancelResult, SendHandle, SendOptions, SessionContext, SessionState } from "../../types.js";
|
|
2
|
+
/** Create + connect a persistent `pi --mode rpc` session. */
|
|
3
|
+
export declare function createPiSession(ctx: SessionContext): Promise<AgentSession>;
|
|
4
|
+
/** @internal Exported for unit testing — not part of the public API. */
|
|
5
|
+
export declare class PiSession implements AgentSession {
|
|
6
|
+
private readonly ctx;
|
|
7
|
+
private _state;
|
|
8
|
+
private proc;
|
|
9
|
+
private _sessionPath;
|
|
10
|
+
private _lineBuffer;
|
|
11
|
+
private _turnActive;
|
|
12
|
+
private _turnText;
|
|
13
|
+
private _pending;
|
|
14
|
+
private _inFlight;
|
|
15
|
+
private _draining;
|
|
16
|
+
/** Serial dispatch so onEvent fires in order and a turn resolves after them. */
|
|
17
|
+
private _eventChain;
|
|
18
|
+
/** Decided outcome of an interrupted turn, applied when its `agent_end` acks. */
|
|
19
|
+
private _pendingStatus;
|
|
20
|
+
private _pendingMessage;
|
|
21
|
+
/** Force-resolve timer if pi never acks an abort with `agent_end`. */
|
|
22
|
+
private _graceTimer;
|
|
23
|
+
/** Count of `agent_end`s to swallow (from turns force-resolved before their ack). */
|
|
24
|
+
private _staleEnds;
|
|
25
|
+
constructor(ctx: SessionContext);
|
|
26
|
+
get sessionId(): string | null;
|
|
27
|
+
get state(): SessionState;
|
|
28
|
+
connect(): Promise<void>;
|
|
29
|
+
private onStdout;
|
|
30
|
+
private handleLine;
|
|
31
|
+
private resolveTurn;
|
|
32
|
+
private failPending;
|
|
33
|
+
send(message: string, options?: SendOptions): Promise<SendHandle>;
|
|
34
|
+
private onTurnInterrupt;
|
|
35
|
+
cancel(_uuid: string): Promise<CancelResult>;
|
|
36
|
+
interrupt(): Promise<void>;
|
|
37
|
+
drain(): Promise<void>;
|
|
38
|
+
close(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/providers/pi/session.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,WAAW,EACX,cAAc,EACd,YAAY,EAEb,MAAM,gBA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IAYtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAY7B"}
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import * as os from "node:os";
|
|
5
|
+
import { findBinary } from "../../utils/binary.js";
|
|
6
|
+
import { buildEnv, ensurePathInEnv } from "../../utils/env.js";
|
|
7
|
+
import { uuidv7 } from "../../utils/uuid.js";
|
|
8
|
+
import { resolveInstructions } from "../../utils/instructions.js";
|
|
9
|
+
import { injectHomeSkills } from "../../utils/skills.js";
|
|
10
|
+
import { parsePiStreamLine } from "./parse.js";
|
|
11
|
+
import { piSessionCodec } from "./codec.js";
|
|
12
|
+
const PI_SESSIONS_DIR = path.join(os.homedir(), ".pi", "sessions");
|
|
13
|
+
function parseProviderModel(model) {
|
|
14
|
+
const m = (model ?? "").trim();
|
|
15
|
+
if (!m)
|
|
16
|
+
return { provider: null, modelId: null };
|
|
17
|
+
const idx = m.indexOf("/");
|
|
18
|
+
if (idx < 0)
|
|
19
|
+
return { provider: null, modelId: m };
|
|
20
|
+
return { provider: m.slice(0, idx).trim() || null, modelId: m.slice(idx + 1).trim() || null };
|
|
21
|
+
}
|
|
22
|
+
function buildSessionPath() {
|
|
23
|
+
const ts = new Date().toISOString().replace(/[:.]/g, "-");
|
|
24
|
+
return path.join(PI_SESSIONS_DIR, `${ts}-${uuidv7()}.jsonl`);
|
|
25
|
+
}
|
|
26
|
+
/** Create + connect a persistent `pi --mode rpc` session. */
|
|
27
|
+
export async function createPiSession(ctx) {
|
|
28
|
+
const session = new PiSession(ctx);
|
|
29
|
+
await session.connect();
|
|
30
|
+
return session;
|
|
31
|
+
}
|
|
32
|
+
/** @internal Exported for unit testing — not part of the public API. */
|
|
33
|
+
export class PiSession {
|
|
34
|
+
ctx;
|
|
35
|
+
_state = "idle";
|
|
36
|
+
proc = null;
|
|
37
|
+
_sessionPath = "";
|
|
38
|
+
_lineBuffer = "";
|
|
39
|
+
_turnActive = false;
|
|
40
|
+
_turnText = "";
|
|
41
|
+
_pending = null;
|
|
42
|
+
_inFlight = null;
|
|
43
|
+
_draining = false;
|
|
44
|
+
/** Serial dispatch so onEvent fires in order and a turn resolves after them. */
|
|
45
|
+
_eventChain = Promise.resolve();
|
|
46
|
+
/** Decided outcome of an interrupted turn, applied when its `agent_end` acks. */
|
|
47
|
+
_pendingStatus = null;
|
|
48
|
+
_pendingMessage = null;
|
|
49
|
+
/** Force-resolve timer if pi never acks an abort with `agent_end`. */
|
|
50
|
+
_graceTimer = null;
|
|
51
|
+
/** Count of `agent_end`s to swallow (from turns force-resolved before their ack). */
|
|
52
|
+
_staleEnds = 0;
|
|
53
|
+
constructor(ctx) {
|
|
54
|
+
this.ctx = ctx;
|
|
55
|
+
}
|
|
56
|
+
get sessionId() {
|
|
57
|
+
return this._sessionPath || null;
|
|
58
|
+
}
|
|
59
|
+
get state() {
|
|
60
|
+
return this._state;
|
|
61
|
+
}
|
|
62
|
+
async connect() {
|
|
63
|
+
const config = this.ctx.config ?? {};
|
|
64
|
+
const resolved = await findBinary("pi", config.command);
|
|
65
|
+
const env = buildEnv(this.ctx.env);
|
|
66
|
+
ensurePathInEnv(env);
|
|
67
|
+
const cwd = this.ctx.cwd ?? process.cwd();
|
|
68
|
+
if (config.instructionsFile)
|
|
69
|
+
await resolveInstructions(config.instructionsFile);
|
|
70
|
+
let skillsDir = null;
|
|
71
|
+
if (config.skillDirs && config.skillDirs.length > 0) {
|
|
72
|
+
try {
|
|
73
|
+
skillsDir = await injectHomeSkills(config.skillDirs, "pi");
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
/* non-fatal */
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
await fs.mkdir(PI_SESSIONS_DIR, { recursive: true });
|
|
80
|
+
// Resume an existing session file, or start a new one. Pi keys sessions by
|
|
81
|
+
// file path; `--session <file>` resumes when the file exists, creates otherwise.
|
|
82
|
+
const decoded = piSessionCodec.deserialize(this.ctx.sessionParams ?? null);
|
|
83
|
+
const resumeId = typeof decoded?.["sessionId"] === "string" ? decoded["sessionId"] : null;
|
|
84
|
+
this._sessionPath = resumeId || buildSessionPath();
|
|
85
|
+
const { provider, modelId } = parseProviderModel(this.ctx.config?.model);
|
|
86
|
+
const args = [...resolved.prefixArgs, "--mode", "rpc"];
|
|
87
|
+
if (provider)
|
|
88
|
+
args.push("--provider", provider);
|
|
89
|
+
if (modelId)
|
|
90
|
+
args.push("--model", modelId);
|
|
91
|
+
if (config.thinking)
|
|
92
|
+
args.push("--thinking", config.thinking);
|
|
93
|
+
args.push("--tools", "read,bash,edit,write,grep,find,ls");
|
|
94
|
+
args.push("--session", this._sessionPath);
|
|
95
|
+
if (skillsDir)
|
|
96
|
+
args.push("--skill", skillsDir);
|
|
97
|
+
if (config.instructionsFile)
|
|
98
|
+
args.push("--append-system-prompt", config.instructionsFile);
|
|
99
|
+
if (config.extraArgs)
|
|
100
|
+
args.push(...config.extraArgs);
|
|
101
|
+
const proc = spawn(resolved.bin, args, { cwd, env, stdio: ["pipe", "pipe", "pipe"] });
|
|
102
|
+
this.proc = proc;
|
|
103
|
+
proc.stdout.setEncoding("utf-8");
|
|
104
|
+
proc.stdout.on("data", (chunk) => this.onStdout(chunk));
|
|
105
|
+
proc.stderr.setEncoding("utf-8");
|
|
106
|
+
proc.stderr.on("data", (chunk) => {
|
|
107
|
+
if (this.ctx.onOutput) {
|
|
108
|
+
try {
|
|
109
|
+
void this.ctx.onOutput("stderr", chunk);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
/* swallow */
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
proc.on("exit", (code, signal) => {
|
|
117
|
+
if (this._state !== "closed") {
|
|
118
|
+
this._state = "closed";
|
|
119
|
+
this.failPending(`pi process exited (code=${code}, signal=${signal})`);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
proc.on("error", (err) => {
|
|
123
|
+
if (this._state !== "closed") {
|
|
124
|
+
this._state = "closed";
|
|
125
|
+
this.failPending(err instanceof Error ? err.message : String(err));
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
if (this.ctx.signal) {
|
|
129
|
+
if (this.ctx.signal.aborted)
|
|
130
|
+
void this.close();
|
|
131
|
+
else
|
|
132
|
+
this.ctx.signal.addEventListener("abort", () => void this.close(), { once: true });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// -------------------------------------------------------------------------
|
|
136
|
+
// stdout → events (strict \n framing per pi's RPC contract)
|
|
137
|
+
// -------------------------------------------------------------------------
|
|
138
|
+
onStdout(chunk) {
|
|
139
|
+
if (this.ctx.onOutput) {
|
|
140
|
+
try {
|
|
141
|
+
void this.ctx.onOutput("stdout", chunk);
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
/* swallow */
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
this._lineBuffer += chunk;
|
|
148
|
+
const lines = this._lineBuffer.split("\n");
|
|
149
|
+
this._lineBuffer = lines.pop() ?? "";
|
|
150
|
+
for (const line of lines) {
|
|
151
|
+
const trimmed = line.replace(/\r$/, "").trim();
|
|
152
|
+
if (trimmed)
|
|
153
|
+
this.handleLine(trimmed);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
handleLine(line) {
|
|
157
|
+
// Command acks (`{"type":"response",...}`) aren't agent events — skip.
|
|
158
|
+
let obj;
|
|
159
|
+
try {
|
|
160
|
+
obj = JSON.parse(line);
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (obj && typeof obj === "object" && obj["type"] === "response")
|
|
166
|
+
return;
|
|
167
|
+
const ev = parsePiStreamLine(line);
|
|
168
|
+
if (!ev)
|
|
169
|
+
return;
|
|
170
|
+
// `agent_end` (mapped to "result") is a turn terminal. Swallow a stale end
|
|
171
|
+
// from a turn that was already force-resolved (timed out and pi never acked
|
|
172
|
+
// before the grace deadline) so it can't resolve the NEXT turn.
|
|
173
|
+
if (ev.type === "result" && this._staleEnds > 0) {
|
|
174
|
+
this._staleEnds--;
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
// Only accumulate/emit while a turn is active so stragglers from a finished
|
|
178
|
+
// turn don't contaminate the next one's summary or event stream.
|
|
179
|
+
if (!this._turnActive)
|
|
180
|
+
return;
|
|
181
|
+
if (ev.type === "assistant")
|
|
182
|
+
this._turnText += ev.text;
|
|
183
|
+
// Emit through the serial chain so handlers run in order.
|
|
184
|
+
if (this.ctx.onEvent) {
|
|
185
|
+
const handler = this.ctx.onEvent;
|
|
186
|
+
this._eventChain = this._eventChain.then(() => handler(ev)).catch(() => { });
|
|
187
|
+
}
|
|
188
|
+
// agent_end → the turn is complete. If the turn was interrupted, apply the
|
|
189
|
+
// decided status (timeout/aborted); otherwise it completed.
|
|
190
|
+
if (ev.type === "result") {
|
|
191
|
+
const status = this._pendingStatus ?? "completed";
|
|
192
|
+
const message = this._pendingMessage ?? undefined;
|
|
193
|
+
void this._eventChain.then(() => this.resolveTurn(status, message));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
resolveTurn(status, errorMessage) {
|
|
197
|
+
const pending = this._pending;
|
|
198
|
+
if (!pending || pending.settled)
|
|
199
|
+
return;
|
|
200
|
+
pending.settled = true;
|
|
201
|
+
pending.cleanup();
|
|
202
|
+
if (this._graceTimer) {
|
|
203
|
+
clearTimeout(this._graceTimer);
|
|
204
|
+
this._graceTimer = null;
|
|
205
|
+
}
|
|
206
|
+
const summary = this._turnText || null;
|
|
207
|
+
// Reset per-turn accumulators here (not only in send()) so anything that
|
|
208
|
+
// arrives between turns can't leak into the next turn's summary.
|
|
209
|
+
this._turnText = "";
|
|
210
|
+
this._turnActive = false;
|
|
211
|
+
this._inFlight = null;
|
|
212
|
+
this._pending = null;
|
|
213
|
+
this._pendingStatus = null;
|
|
214
|
+
this._pendingMessage = null;
|
|
215
|
+
if (this._state !== "closed")
|
|
216
|
+
this._state = "idle";
|
|
217
|
+
pending.resolve({
|
|
218
|
+
summary,
|
|
219
|
+
costUsd: null,
|
|
220
|
+
status,
|
|
221
|
+
errorCode: status === "completed" ? null : status === "failed" ? "error" : status,
|
|
222
|
+
errorMessage: errorMessage ?? null,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
failPending(message) {
|
|
226
|
+
if (this._pending && !this._pending.settled)
|
|
227
|
+
this.resolveTurn("failed", message);
|
|
228
|
+
}
|
|
229
|
+
// -------------------------------------------------------------------------
|
|
230
|
+
// Public API
|
|
231
|
+
// -------------------------------------------------------------------------
|
|
232
|
+
async send(message, options) {
|
|
233
|
+
if (this._state === "closed")
|
|
234
|
+
throw new Error("Session is closed");
|
|
235
|
+
if (this._draining)
|
|
236
|
+
throw new Error("Session is draining — no new sends accepted");
|
|
237
|
+
if (this._turnActive) {
|
|
238
|
+
throw new Error("Pi session is busy — a turn is already in progress (concurrentSend not supported)");
|
|
239
|
+
}
|
|
240
|
+
if (!this.proc?.stdin)
|
|
241
|
+
throw new Error("Pi session is not connected");
|
|
242
|
+
const uuid = uuidv7();
|
|
243
|
+
this._turnActive = true;
|
|
244
|
+
this._turnText = "";
|
|
245
|
+
this._state = "thinking";
|
|
246
|
+
const timeoutSec = options?.timeoutSec ?? this.ctx.config?.timeoutSec;
|
|
247
|
+
const result = new Promise((resolve) => {
|
|
248
|
+
let timer = null;
|
|
249
|
+
const onAbort = () => this.onTurnInterrupt("aborted");
|
|
250
|
+
const cleanup = () => {
|
|
251
|
+
if (timer)
|
|
252
|
+
clearTimeout(timer);
|
|
253
|
+
options?.signal?.removeEventListener("abort", onAbort);
|
|
254
|
+
};
|
|
255
|
+
this._pending = { resolve, settled: false, cleanup };
|
|
256
|
+
if (timeoutSec && timeoutSec > 0) {
|
|
257
|
+
timer = setTimeout(() => this.onTurnInterrupt("timeout"), timeoutSec * 1000);
|
|
258
|
+
}
|
|
259
|
+
if (options?.signal) {
|
|
260
|
+
if (options.signal.aborted)
|
|
261
|
+
this.onTurnInterrupt("aborted");
|
|
262
|
+
else
|
|
263
|
+
options.signal.addEventListener("abort", onAbort, { once: true });
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
this._inFlight = result;
|
|
267
|
+
this.proc.stdin.write(JSON.stringify({ id: uuid, type: "prompt", message }) + "\n");
|
|
268
|
+
return { uuid, result };
|
|
269
|
+
}
|
|
270
|
+
onTurnInterrupt(status) {
|
|
271
|
+
if (!this._pending || this._pending.settled)
|
|
272
|
+
return;
|
|
273
|
+
// Decide the outcome, send `abort`, but keep the turn open until pi acks with
|
|
274
|
+
// `agent_end` so the aborted turn's stragglers stay inside this turn (and
|
|
275
|
+
// don't bleed into the next). Force-resolve after a grace deadline if pi
|
|
276
|
+
// never acks — and then swallow the eventual stale `agent_end`.
|
|
277
|
+
this._pendingStatus = status;
|
|
278
|
+
this._pendingMessage = status === "timeout" ? "Turn exceeded its timeout" : "Turn aborted";
|
|
279
|
+
void this.interrupt();
|
|
280
|
+
if (this._graceTimer)
|
|
281
|
+
clearTimeout(this._graceTimer);
|
|
282
|
+
const graceMs = (this.ctx.config?.graceSec ?? 5) * 1000;
|
|
283
|
+
this._graceTimer = setTimeout(() => {
|
|
284
|
+
this._graceTimer = null;
|
|
285
|
+
this._staleEnds++;
|
|
286
|
+
this.resolveTurn(status, status === "timeout" ? "Turn exceeded its timeout" : "Turn aborted");
|
|
287
|
+
}, graceMs);
|
|
288
|
+
}
|
|
289
|
+
async cancel(_uuid) {
|
|
290
|
+
return { cancelled: false };
|
|
291
|
+
}
|
|
292
|
+
async interrupt() {
|
|
293
|
+
if (this.proc?.stdin && !this.proc.stdin.destroyed) {
|
|
294
|
+
try {
|
|
295
|
+
this.proc.stdin.write(JSON.stringify({ type: "abort" }) + "\n");
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
/* best effort */
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
async drain() {
|
|
303
|
+
this._draining = true;
|
|
304
|
+
if (this._inFlight) {
|
|
305
|
+
try {
|
|
306
|
+
await this._inFlight;
|
|
307
|
+
}
|
|
308
|
+
catch {
|
|
309
|
+
/* ignore */
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
await this.close();
|
|
313
|
+
}
|
|
314
|
+
async close() {
|
|
315
|
+
this._state = "closed";
|
|
316
|
+
const proc = this.proc;
|
|
317
|
+
this.proc = null;
|
|
318
|
+
if (proc && !proc.killed) {
|
|
319
|
+
try {
|
|
320
|
+
proc.kill();
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
/* ignore */
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/providers/pi/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAU9B,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,eAAe,GAAG,IAAI,CAAC,I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AAE,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;YAClE,CAAC;YAAC,MAAM,CAAC;gBACP,iBAAiB;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,SAAS,CAAC;YACvB,CAAC;YAAC,MAAM,CAAC;gBACP,YAAY;YACd,CAAC;QACH,CAAC;QACD,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;QACvB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACzB,IAAI,CAAC;gBACH,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,CAAC;YAAC,MAAM,CAAC;gBACP,YAAY;YACd,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/process/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkC,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAiCrF,eAAO,MAAM,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/process/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkC,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAiCrF,eAAO,MAAM,eAAe,EAAE,cAiB7B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/process/index.ts"],"names":[],"mappings":"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,QAAQ,EAAE,KAAK;QACf,cAAc,EAAE,KAAK;QACrB,YAAY,EAAE,KAAK;QACnB,GAAG,EAAE,KAAK;QACV,MAAM,EAAE,KAAK;QACb,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,KAAK;QACf,cAAc,EAAE,KAAK;QACrB,mBAAmB,EAAE,KAAK;QAC1B,KAAK,EAAE,KAAK;KACb;IACD,OAAO,EAAE,sBAAsB;IAC/B,WAAW,EAAE,kBAAkB;CAChC,CAAC"}
|
package/dist/registry.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ProviderModule } from "./types.js";
|
|
2
|
+
import "./providers/acp/index.js";
|
|
2
3
|
export declare function getProvider(type: string): ProviderModule;
|
|
3
4
|
export declare function listProviders(): string[];
|
|
4
5
|
export declare function registerProvider(provider: ProviderModule): void;
|
package/dist/registry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAajD,OAAO,0BAA0B,CAAC;AAelC,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAOxD;AAED,wBAAgB,aAAa,IAAI,MAAM,EAAE,CAExC;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAE/D"}
|
package/dist/registry.js
CHANGED
|
@@ -6,6 +6,11 @@ import { geminiProvider } from "./providers/gemini/index.js";
|
|
|
6
6
|
import { cursorProvider } from "./providers/cursor/index.js";
|
|
7
7
|
import { opencodeProvider } from "./providers/opencode/index.js";
|
|
8
8
|
import { piProvider } from "./providers/pi/index.js";
|
|
9
|
+
import { copilotProvider } from "./providers/copilot/index.js";
|
|
10
|
+
// Side-effect import: registers the ACP factory so `loadProvidersFromConfig`
|
|
11
|
+
// can build `extends: "acp"` providers. Cheap — the ACP SDK is only loaded when
|
|
12
|
+
// an ACP session actually runs.
|
|
13
|
+
import "./providers/acp/index.js";
|
|
9
14
|
const providers = new Map();
|
|
10
15
|
// Pre-register built-in providers
|
|
11
16
|
providers.set("claude", claudeProvider);
|
|
@@ -16,6 +21,7 @@ providers.set("gemini", geminiProvider);
|
|
|
16
21
|
providers.set("cursor", cursorProvider);
|
|
17
22
|
providers.set("opencode", opencodeProvider);
|
|
18
23
|
providers.set("pi", piProvider);
|
|
24
|
+
providers.set("copilot", copilotProvider);
|
|
19
25
|
export function getProvider(type) {
|
|
20
26
|
const provider = providers.get(type);
|
|
21
27
|
if (!provider) {
|
package/dist/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAA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AG,CAAC,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnD,MAAM,IAAI,KAAK,CAAC,0BAA0B,IAAI,iBAAiB,SAAS,EAAE,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,CAAC,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAAwB;IACvD,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACzC,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -52,6 +52,42 @@ export interface ProviderCapabilities {
|
|
|
52
52
|
* cancel returns `{cancelled: false}`.
|
|
53
53
|
*/
|
|
54
54
|
cancelQueuedMessage: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Provider exposes selectable operating modes via `listModes()` — e.g. Codex
|
|
57
|
+
* collaboration modes, Copilot's allow-all/agent/plan. When `false`,
|
|
58
|
+
* `config.modeId` is ignored and `listModes` is absent.
|
|
59
|
+
*/
|
|
60
|
+
modes: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Capabilities are negotiated at runtime rather than statically known.
|
|
63
|
+
* `true` for ACP providers, whose real capability set comes from the agent's
|
|
64
|
+
* `initialize` handshake — the static flags here are a best-effort default
|
|
65
|
+
* until a session is created. Consumers needing exact capabilities for a
|
|
66
|
+
* dynamic provider should create a session and read its reported state.
|
|
67
|
+
*/
|
|
68
|
+
dynamicCapabilities?: boolean;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A selectable operating mode a provider/session exposes. Discovered at
|
|
72
|
+
* runtime for dynamic providers (ACP), queried from the agent for codex.
|
|
73
|
+
*/
|
|
74
|
+
export interface AgentMode {
|
|
75
|
+
/**
|
|
76
|
+
* Stable mode identifier. May be a full URI for ACP providers (e.g.
|
|
77
|
+
* "https://agentclientprotocol.com/protocol/session-modes#agent") — never
|
|
78
|
+
* assume it's a simple slug.
|
|
79
|
+
*/
|
|
80
|
+
id: string;
|
|
81
|
+
/** Human-readable label for display. */
|
|
82
|
+
name: string;
|
|
83
|
+
/** Optional longer description of what the mode does. */
|
|
84
|
+
description?: string;
|
|
85
|
+
}
|
|
86
|
+
/** Options for `ProviderModule.listModes()`. */
|
|
87
|
+
export interface ListModesOptions {
|
|
88
|
+
cwd?: string;
|
|
89
|
+
env?: Record<string, string>;
|
|
90
|
+
config?: ProviderConfig;
|
|
55
91
|
}
|
|
56
92
|
export interface ProviderModule {
|
|
57
93
|
type: string;
|
|
@@ -76,6 +112,12 @@ export interface ProviderModule {
|
|
|
76
112
|
listModels?(options?: {
|
|
77
113
|
cacheTtlMs?: number;
|
|
78
114
|
}): Promise<ProviderModel[]>;
|
|
115
|
+
/**
|
|
116
|
+
* List the operating modes this provider exposes (see `AgentMode`). Present
|
|
117
|
+
* only on providers with `capabilities.modes === true`. May spawn the agent
|
|
118
|
+
* to query it (ACP, codex), so it's async and accepts cwd/env/config.
|
|
119
|
+
*/
|
|
120
|
+
listModes?(options?: ListModesOptions): Promise<AgentMode[]>;
|
|
79
121
|
/** Check current quota/rate limit status. Not all providers support this. */
|
|
80
122
|
checkQuota?(ctx: QuotaContext): Promise<QuotaStatus>;
|
|
81
123
|
/**
|
|
@@ -179,7 +221,22 @@ export interface ProviderConfig {
|
|
|
179
221
|
model?: string;
|
|
180
222
|
effort?: string;
|
|
181
223
|
maxTurns?: number;
|
|
224
|
+
/**
|
|
225
|
+
* Hard runtime cap, in seconds.
|
|
226
|
+
* - `exec()`: kills the child process (SIGTERM → grace → SIGKILL) and reports
|
|
227
|
+
* `status: "timeout"`.
|
|
228
|
+
* - Sessions (`createSession`): acts as the per-session default timeout for
|
|
229
|
+
* `send()`. A per-call `SendOptions.timeoutSec` overrides it. On fire, the
|
|
230
|
+
* active turn is `interrupt()`ed and that send's `TurnResult` resolves with
|
|
231
|
+
* `status: "timeout"`. Unset means no timeout.
|
|
232
|
+
*/
|
|
182
233
|
timeoutSec?: number;
|
|
234
|
+
/**
|
|
235
|
+
* Grace period, in seconds, between SIGTERM and SIGKILL when terminating the
|
|
236
|
+
* underlying process. Applies to both `exec()` and session `close()`/`drain()`.
|
|
237
|
+
* Defaults to 5. Bump it for workloads that legitimately need longer to clean
|
|
238
|
+
* up (long Bash, test suites) so they aren't hard-killed mid-flight.
|
|
239
|
+
*/
|
|
183
240
|
graceSec?: number;
|
|
184
241
|
skipPermissions?: boolean;
|
|
185
242
|
skillDirs?: string[];
|
|
@@ -195,6 +252,14 @@ export interface ProviderConfig {
|
|
|
195
252
|
* instead, which is the cross-provider abstraction.
|
|
196
253
|
*/
|
|
197
254
|
mode?: string;
|
|
255
|
+
/**
|
|
256
|
+
* Select a provider operating mode by id (one of `listModes()`). Honored by
|
|
257
|
+
* providers with `capabilities.modes === true` (codex collaboration modes,
|
|
258
|
+
* ACP session modes, copilot allow-all/agent/plan). Ignored otherwise.
|
|
259
|
+
* Distinct from `mode` (cursor's raw `--mode` passthrough) and `planMode`
|
|
260
|
+
* (the cross-provider read-only abstraction).
|
|
261
|
+
*/
|
|
262
|
+
modeId?: string;
|
|
198
263
|
/**
|
|
199
264
|
* Run the agent in read-only "plan" mode: it can read, search, and reason,
|
|
200
265
|
* but cannot edit files or run mutating commands. Honored by providers
|
|
@@ -431,6 +496,15 @@ export type StreamEvent = ({
|
|
|
431
496
|
type: "tool_result";
|
|
432
497
|
/** FK back to the tool_call.toolCallId this responds to. */
|
|
433
498
|
toolCallId: string | null;
|
|
499
|
+
/**
|
|
500
|
+
* Name of the tool whose result this is — mirrors the matching
|
|
501
|
+
* `tool_call.name`. Saves consumers from maintaining their own
|
|
502
|
+
* `toolCallId → name` cache to attribute a result to a named action.
|
|
503
|
+
* Null when the name couldn't be correlated (no preceding `tool_call`
|
|
504
|
+
* was observed on this stream — e.g. onEvent attached mid-turn, or a
|
|
505
|
+
* provider that emits a result with no paired call).
|
|
506
|
+
*/
|
|
507
|
+
toolName: string | null;
|
|
434
508
|
content: string;
|
|
435
509
|
isError: boolean;
|
|
436
510
|
/** Exit code for command-execution tools (Codex); null otherwise. */
|
|
@@ -739,6 +813,26 @@ export interface CancelResult {
|
|
|
739
813
|
*/
|
|
740
814
|
cancelled: boolean;
|
|
741
815
|
}
|
|
816
|
+
/** Per-call options for `AgentSession.send()`. */
|
|
817
|
+
export interface SendOptions {
|
|
818
|
+
/**
|
|
819
|
+
* Hard cap on this turn's runtime, in seconds. On fire, the SDK
|
|
820
|
+
* `interrupt()`s the active turn and resolves this send's `result` with
|
|
821
|
+
* `status: "timeout"`. Overrides `ProviderConfig.timeoutSec` for this call.
|
|
822
|
+
*
|
|
823
|
+
* Note: a session runs a single underlying agent, so interrupting one
|
|
824
|
+
* timed-out send also ends any other sends coalesced into the same turn —
|
|
825
|
+
* the natural shape for the one-send-per-turn (scheduled-run) use case.
|
|
826
|
+
*/
|
|
827
|
+
timeoutSec?: number;
|
|
828
|
+
/**
|
|
829
|
+
* Abort just this turn (not the whole session). On abort, the active turn is
|
|
830
|
+
* `interrupt()`ed and this send's `result` resolves with `status: "aborted"`.
|
|
831
|
+
* Distinct from `SessionContext.signal`, which closes the entire session.
|
|
832
|
+
* Stacks with `timeoutSec`; whichever fires first wins.
|
|
833
|
+
*/
|
|
834
|
+
signal?: AbortSignal;
|
|
835
|
+
}
|
|
742
836
|
/** A persistent session handle for multi-turn conversations. */
|
|
743
837
|
export interface AgentSession {
|
|
744
838
|
readonly sessionId: string | null;
|
|
@@ -763,8 +857,11 @@ export interface AgentSession {
|
|
|
763
857
|
*
|
|
764
858
|
* Multiple concurrent sends may resolve with the same shared `TurnResult`
|
|
765
859
|
* if the CLI coalesces them. See `SendHandle` JSDoc.
|
|
860
|
+
*
|
|
861
|
+
* Pass `SendOptions` to bound this turn with a timeout and/or abort signal.
|
|
862
|
+
* Throws if the session is closed or `drain()`ing.
|
|
766
863
|
*/
|
|
767
|
-
send(message: string): Promise<SendHandle>;
|
|
864
|
+
send(message: string, options?: SendOptions): Promise<SendHandle>;
|
|
768
865
|
/**
|
|
769
866
|
* Cancel a previously-sent message that is still queued in the CLI.
|
|
770
867
|
*
|
|
@@ -775,6 +872,14 @@ export interface AgentSession {
|
|
|
775
872
|
cancel(uuid: string): Promise<CancelResult>;
|
|
776
873
|
/** Gracefully interrupt the current turn. */
|
|
777
874
|
interrupt(): Promise<void>;
|
|
875
|
+
/**
|
|
876
|
+
* Graceful stop: refuse new `send()` calls (they throw), await any in-flight
|
|
877
|
+
* turn's `result` to settle, then `close()`. Use this — not `interrupt()`
|
|
878
|
+
* (loses in-flight work) or `close()` (kills mid-tool) — when you want a
|
|
879
|
+
* running turn to finish before shutting down (budget gate, SIGTERM, schedule
|
|
880
|
+
* pause). Resolves once fully closed. Idempotent.
|
|
881
|
+
*/
|
|
882
|
+
drain(): Promise<void>;
|
|
778
883
|
/** Terminate the session and kill the underlying process. */
|
|
779
884
|
close(): Promise<void>;
|
|
780
885
|
}
|
|
@@ -783,7 +888,13 @@ export interface TurnResult {
|
|
|
783
888
|
summary: string | null;
|
|
784
889
|
usage?: Record<string, TokenUsage>;
|
|
785
890
|
costUsd: number | null;
|
|
786
|
-
|
|
891
|
+
/**
|
|
892
|
+
* `timeout` — the per-send timeout (`SendOptions.timeoutSec` or the session
|
|
893
|
+
* default `ProviderConfig.timeoutSec`) fired and the turn was interrupted.
|
|
894
|
+
* `aborted` — a `SendOptions.signal` aborted the turn (or the turn was
|
|
895
|
+
* otherwise interrupted).
|
|
896
|
+
*/
|
|
897
|
+
status: "completed" | "failed" | "max_turns" | "max_budget" | "aborted" | "timeout";
|
|
787
898
|
errorCode: string | null;
|
|
788
899
|
errorMessage: string | null;
|
|
789
900
|
}
|