agent-neckbeard 1.1.28 → 1.1.29
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/CHANGELOG.md +5 -0
- package/README.md +3 -3
- package/dist/build.cjs +170 -15
- package/dist/build.d.cts +1 -1
- package/dist/build.d.ts +1 -1
- package/dist/build.js +3 -3
- package/dist/{chunk-JF5YPOBY.js → chunk-BPXEIXPM.js} +25 -1
- package/dist/{chunk-M7XNBKG4.js → chunk-FSBTLBB5.js} +1 -1
- package/dist/{chunk-M3FISP7J.js → chunk-YFG4EKZM.js} +146 -15
- package/dist/cli.cjs +170 -15
- package/dist/cli.js +3 -3
- package/dist/index.cjs +170 -15
- package/dist/index.d.cts +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +2 -2
- package/dist/{serve-Dan1HQKN.d.ts → serve-Du2NCz9_.d.cts} +24 -2
- package/dist/{serve-Dan1HQKN.d.cts → serve-Du2NCz9_.d.ts} +24 -2
- package/dist/serve.cjs +143 -13
- package/dist/serve.d.cts +1 -1
- package/dist/serve.d.ts +1 -1
- package/dist/serve.js +1 -1
- package/docs/AGENT.md +39 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3749,7 +3749,7 @@ var import_node_crypto3 = require("crypto");
|
|
|
3749
3749
|
init_sse_framing();
|
|
3750
3750
|
|
|
3751
3751
|
// src/turn-protocol.ts
|
|
3752
|
-
var TURN_PROTOCOL_VERSION =
|
|
3752
|
+
var TURN_PROTOCOL_VERSION = 3;
|
|
3753
3753
|
var MAX_TURN_REQUEST_BYTES = 4 * 1024 * 1024;
|
|
3754
3754
|
var MAX_TURN_ID_LENGTH = 200;
|
|
3755
3755
|
function isRecord2(value) {
|
|
@@ -3764,12 +3764,13 @@ function parseTurnRecord(record) {
|
|
|
3764
3764
|
if (record.type === "event" && "event" in record) {
|
|
3765
3765
|
return { seq, type: "event", event: record.event };
|
|
3766
3766
|
}
|
|
3767
|
-
if (record.type === "end" && (record.outcome === "completed" || record.outcome === "aborted" || record.outcome === "failed") && (record.error === void 0 || typeof record.error === "string")) {
|
|
3767
|
+
if (record.type === "end" && (record.outcome === "completed" || record.outcome === "aborted" || record.outcome === "failed") && (record.error === void 0 || typeof record.error === "string") && (record.undeliveredSteerIds === void 0 || Array.isArray(record.undeliveredSteerIds) && record.undeliveredSteerIds.every((id) => typeof id === "string"))) {
|
|
3768
3768
|
return {
|
|
3769
3769
|
seq,
|
|
3770
3770
|
type: "end",
|
|
3771
3771
|
outcome: record.outcome,
|
|
3772
|
-
...record.error === void 0 ? {} : { error: record.error }
|
|
3772
|
+
...record.error === void 0 ? {} : { error: record.error },
|
|
3773
|
+
...record.undeliveredSteerIds === void 0 ? {} : { undeliveredSteerIds: record.undeliveredSteerIds }
|
|
3773
3774
|
};
|
|
3774
3775
|
}
|
|
3775
3776
|
throw new Error("Turn record has an unknown shape.");
|
|
@@ -4115,6 +4116,25 @@ var Agent = class {
|
|
|
4115
4116
|
throw new ExecutionError(`Aborting turn ${turnId} failed with ${response.status}.`);
|
|
4116
4117
|
}
|
|
4117
4118
|
}
|
|
4119
|
+
/**
|
|
4120
|
+
* Queues a message for a running turn, which Pi takes after its current tool calls. Resolves to
|
|
4121
|
+
* true once the session has queued it: it is then delivered into the turn, or named in the end
|
|
4122
|
+
* record's `undeliveredSteerIds`. Resolves to false when the turn can no longer take it, or the
|
|
4123
|
+
* runtime no longer has it, so the caller can send the message as a turn of its own. Throws when
|
|
4124
|
+
* queueing failed or the request did; calling again with the same `steerId` never queues it twice.
|
|
4125
|
+
*/
|
|
4126
|
+
async steer(sandboxId, turnId, steer, signal) {
|
|
4127
|
+
const response = await this.request(sandboxId, "POST", `/turns/${encodeURIComponent(turnId)}/steer`, steer, signal);
|
|
4128
|
+
if (response.status === 200 || response.status === 202) {
|
|
4129
|
+
await response.body?.cancel();
|
|
4130
|
+
return true;
|
|
4131
|
+
}
|
|
4132
|
+
if (response.status === 409 || response.status === 404) {
|
|
4133
|
+
await response.body?.cancel();
|
|
4134
|
+
return false;
|
|
4135
|
+
}
|
|
4136
|
+
throw new ExecutionError(`Steering turn ${turnId} failed with ${response.status}: ${await response.text()}`);
|
|
4137
|
+
}
|
|
4118
4138
|
async health(sandboxId, signal) {
|
|
4119
4139
|
const response = await this.request(sandboxId, "GET", "/health", void 0, signal);
|
|
4120
4140
|
if (!response.ok) throw new ExecutionError(`Health check of sandbox ${sandboxId} returned ${response.status}.`);
|
|
@@ -4522,6 +4542,17 @@ function parseStartTurn(body) {
|
|
|
4522
4542
|
}
|
|
4523
4543
|
return { turnId, message, ...env === void 0 ? {} : { env } };
|
|
4524
4544
|
}
|
|
4545
|
+
function parseSteerTurn(body) {
|
|
4546
|
+
if (!body || typeof body !== "object") throw new RequestError(400, "Request body must be an object.");
|
|
4547
|
+
const { steerId, message } = body;
|
|
4548
|
+
if (typeof steerId !== "string" || !steerId || steerId.length > MAX_TURN_ID_LENGTH) {
|
|
4549
|
+
throw new RequestError(400, `steerId must be a non-empty string of at most ${MAX_TURN_ID_LENGTH} characters.`);
|
|
4550
|
+
}
|
|
4551
|
+
if (typeof message !== "string" || !message.trim()) {
|
|
4552
|
+
throw new RequestError(400, "message must be a non-empty string.");
|
|
4553
|
+
}
|
|
4554
|
+
return { steerId, message };
|
|
4555
|
+
}
|
|
4525
4556
|
async function serve(options) {
|
|
4526
4557
|
const toWireEvent = options.toWireEvent ?? toPiJsonEvent;
|
|
4527
4558
|
let sessionPromise;
|
|
@@ -4534,14 +4565,85 @@ async function serve(options) {
|
|
|
4534
4565
|
turn.records.push(json);
|
|
4535
4566
|
for (const wake of turn.waiters) wake();
|
|
4536
4567
|
};
|
|
4568
|
+
const reclaimSteers = (turn) => {
|
|
4569
|
+
let left;
|
|
4570
|
+
try {
|
|
4571
|
+
left = turn.session?.clearQueue?.().steering.length ?? 0;
|
|
4572
|
+
} catch {
|
|
4573
|
+
left = turn.queuedSteers.length;
|
|
4574
|
+
sessionPromise = void 0;
|
|
4575
|
+
}
|
|
4576
|
+
const leftover = left > 0 ? turn.queuedSteers.slice(-left) : [];
|
|
4577
|
+
for (const steer of turn.queuedSteers) steer.state = leftover.includes(steer) ? "undelivered" : "delivered";
|
|
4578
|
+
turn.queuedSteers = [];
|
|
4579
|
+
turn.undeliveredSteers.push(...leftover);
|
|
4580
|
+
};
|
|
4537
4581
|
const end = (turn, outcome, error) => {
|
|
4538
|
-
if (turn.
|
|
4539
|
-
|
|
4540
|
-
turn.
|
|
4582
|
+
if (turn.ending) return turn.ending;
|
|
4583
|
+
turn.closed = true;
|
|
4584
|
+
turn.sessionReady();
|
|
4585
|
+
let written;
|
|
4586
|
+
turn.ending = new Promise((resolve2) => {
|
|
4587
|
+
written = resolve2;
|
|
4588
|
+
});
|
|
4589
|
+
reclaimSteers(turn);
|
|
4590
|
+
void (async () => {
|
|
4591
|
+
let timer;
|
|
4592
|
+
const graceMs = turn.stopBy === void 0 ? options.abortGraceMs ?? DEFAULT_ABORT_GRACE_MS : Math.max(0, turn.stopBy - Date.now());
|
|
4593
|
+
await Promise.race([
|
|
4594
|
+
turn.steering,
|
|
4595
|
+
new Promise((resolve2) => {
|
|
4596
|
+
timer = setTimeout(resolve2, graceMs);
|
|
4597
|
+
})
|
|
4598
|
+
]);
|
|
4599
|
+
clearTimeout(timer);
|
|
4600
|
+
reclaimSteers(turn);
|
|
4601
|
+
const undeliveredSteerIds = turn.undeliveredSteers.filter((steer) => !steer.late).map((steer) => steer.id);
|
|
4602
|
+
append(turn, {
|
|
4603
|
+
type: "end",
|
|
4604
|
+
outcome,
|
|
4605
|
+
...error === void 0 ? {} : { error },
|
|
4606
|
+
...undeliveredSteerIds.length > 0 ? { undeliveredSteerIds } : {}
|
|
4607
|
+
});
|
|
4608
|
+
turn.ended = true;
|
|
4609
|
+
written();
|
|
4610
|
+
})();
|
|
4611
|
+
return turn.ending;
|
|
4612
|
+
};
|
|
4613
|
+
const acceptSteer = (turn, id, message) => {
|
|
4614
|
+
const steer = { id, state: "pending", late: false, settled: Promise.resolve() };
|
|
4615
|
+
steer.settled = turn.steering.then(async () => {
|
|
4616
|
+
const session = turn.session;
|
|
4617
|
+
if (turn.closed || !session?.steer || !session.clearQueue) {
|
|
4618
|
+
steer.state = "undelivered";
|
|
4619
|
+
return;
|
|
4620
|
+
}
|
|
4621
|
+
try {
|
|
4622
|
+
if (await session.steer(message) === "handled") {
|
|
4623
|
+
steer.state = "handled";
|
|
4624
|
+
return;
|
|
4625
|
+
}
|
|
4626
|
+
steer.state = "queued";
|
|
4627
|
+
turn.queuedSteers.push(steer);
|
|
4628
|
+
if (turn.closed) {
|
|
4629
|
+
reclaimSteers(turn);
|
|
4630
|
+
steer.late = turn.undeliveredSteers.includes(steer);
|
|
4631
|
+
}
|
|
4632
|
+
} catch (error) {
|
|
4633
|
+
steer.state = "failed";
|
|
4634
|
+
steer.error = error;
|
|
4635
|
+
turn.steers.delete(id);
|
|
4636
|
+
}
|
|
4637
|
+
});
|
|
4638
|
+
turn.steering = steer.settled;
|
|
4639
|
+
turn.steers.set(id, steer);
|
|
4640
|
+
return steer;
|
|
4541
4641
|
};
|
|
4542
4642
|
const endAfterGrace = (turn, outcome, error) => {
|
|
4543
|
-
if (turn.
|
|
4544
|
-
|
|
4643
|
+
if (turn.ending || turn.finishing || turn.forceEnd) return;
|
|
4644
|
+
const graceMs = options.abortGraceMs ?? DEFAULT_ABORT_GRACE_MS;
|
|
4645
|
+
turn.stopBy = Date.now() + graceMs;
|
|
4646
|
+
turn.forceEnd = setTimeout(() => void end(turn, outcome, error), graceMs);
|
|
4545
4647
|
};
|
|
4546
4648
|
const runTurn = async (turn, request) => {
|
|
4547
4649
|
const previousEnv = /* @__PURE__ */ new Map();
|
|
@@ -4551,18 +4653,21 @@ async function serve(options) {
|
|
|
4551
4653
|
const timeoutMessage = `Turn exceeded ${options.maxTurnDurationMs}ms.`;
|
|
4552
4654
|
const timer = options.maxTurnDurationMs === void 0 ? void 0 : setTimeout(() => {
|
|
4553
4655
|
timedOut = true;
|
|
4656
|
+
turn.closed = true;
|
|
4657
|
+
reclaimSteers(turn);
|
|
4554
4658
|
if (session) void session.abort().catch(() => void 0);
|
|
4555
4659
|
endAfterGrace(turn, "failed", timeoutMessage);
|
|
4556
4660
|
}, options.maxTurnDurationMs);
|
|
4557
4661
|
const finish = async (outcome, error) => {
|
|
4558
4662
|
turn.finishing = true;
|
|
4663
|
+
turn.closed = true;
|
|
4559
4664
|
if (timer) clearTimeout(timer);
|
|
4560
4665
|
clearTimeout(turn.forceEnd);
|
|
4561
4666
|
try {
|
|
4562
4667
|
await session?.afterTurn?.();
|
|
4563
4668
|
} catch {
|
|
4564
4669
|
}
|
|
4565
|
-
end(turn, outcome, error);
|
|
4670
|
+
await end(turn, outcome, error);
|
|
4566
4671
|
};
|
|
4567
4672
|
try {
|
|
4568
4673
|
sessionPromise ??= options.createSession();
|
|
@@ -4573,26 +4678,34 @@ async function serve(options) {
|
|
|
4573
4678
|
throw error;
|
|
4574
4679
|
}
|
|
4575
4680
|
if (timedOut) {
|
|
4576
|
-
end(turn, "failed", timeoutMessage);
|
|
4681
|
+
await end(turn, "failed", timeoutMessage);
|
|
4577
4682
|
return;
|
|
4578
4683
|
}
|
|
4579
4684
|
const started = session;
|
|
4685
|
+
turn.session = session;
|
|
4580
4686
|
for (const [name, value] of Object.entries(request.env ?? {})) {
|
|
4581
4687
|
previousEnv.set(name, process.env[name]);
|
|
4582
4688
|
process.env[name] = value;
|
|
4583
4689
|
}
|
|
4584
4690
|
unsubscribe = session.subscribe((event) => {
|
|
4585
|
-
if (turn.
|
|
4691
|
+
if (turn.ending) return;
|
|
4586
4692
|
try {
|
|
4587
4693
|
append(turn, { type: "event", event: toWireEvent(event) });
|
|
4588
4694
|
} catch (error) {
|
|
4589
|
-
end(turn, "failed", `Could not convert an agent event: ${error instanceof Error ? error.message : String(error)}`);
|
|
4695
|
+
void end(turn, "failed", `Could not convert an agent event: ${error instanceof Error ? error.message : String(error)}`);
|
|
4590
4696
|
void started.abort().catch(() => void 0);
|
|
4591
4697
|
}
|
|
4592
4698
|
});
|
|
4593
4699
|
currentSessionAbort = () => started.abort();
|
|
4700
|
+
turn.sessionReady();
|
|
4701
|
+
if (!turn.closed) await turn.steering;
|
|
4702
|
+
if (turn.ending) return;
|
|
4703
|
+
if (timedOut) {
|
|
4704
|
+
await end(turn, "failed", timeoutMessage);
|
|
4705
|
+
return;
|
|
4706
|
+
}
|
|
4594
4707
|
if (turn.abortRequested) {
|
|
4595
|
-
end(turn, "aborted");
|
|
4708
|
+
await end(turn, "aborted");
|
|
4596
4709
|
return;
|
|
4597
4710
|
}
|
|
4598
4711
|
await started.prompt(request.message);
|
|
@@ -4605,8 +4718,13 @@ async function serve(options) {
|
|
|
4605
4718
|
} finally {
|
|
4606
4719
|
if (timer) clearTimeout(timer);
|
|
4607
4720
|
clearTimeout(turn.forceEnd);
|
|
4721
|
+
turn.closed = true;
|
|
4722
|
+
turn.sessionReady();
|
|
4723
|
+
await turn.ending;
|
|
4608
4724
|
unsubscribe?.();
|
|
4609
4725
|
currentSessionAbort = void 0;
|
|
4726
|
+
await turn.steering;
|
|
4727
|
+
reclaimSteers(turn);
|
|
4610
4728
|
for (const [name, value] of previousEnv) {
|
|
4611
4729
|
if (value === void 0) delete process.env[name];
|
|
4612
4730
|
else process.env[name] = value;
|
|
@@ -4621,12 +4739,21 @@ async function serve(options) {
|
|
|
4621
4739
|
if (current && !current.settled) {
|
|
4622
4740
|
return { status: 409, body: { error: "Another turn is running.", turnId: current.id } };
|
|
4623
4741
|
}
|
|
4742
|
+
let sessionReady;
|
|
4624
4743
|
const turn = {
|
|
4625
4744
|
id: request.turnId,
|
|
4626
4745
|
records: [],
|
|
4627
4746
|
ended: false,
|
|
4628
4747
|
settled: false,
|
|
4629
4748
|
abortRequested: false,
|
|
4749
|
+
steers: /* @__PURE__ */ new Map(),
|
|
4750
|
+
queuedSteers: [],
|
|
4751
|
+
undeliveredSteers: [],
|
|
4752
|
+
steering: new Promise((resolve2) => {
|
|
4753
|
+
sessionReady = resolve2;
|
|
4754
|
+
}),
|
|
4755
|
+
sessionReady: () => sessionReady(),
|
|
4756
|
+
closed: false,
|
|
4630
4757
|
finishing: false,
|
|
4631
4758
|
waiters: /* @__PURE__ */ new Set()
|
|
4632
4759
|
};
|
|
@@ -4691,7 +4818,7 @@ data: ${turn.records[next]}
|
|
|
4691
4818
|
const server = (0, import_node_http.createServer)((request, response) => {
|
|
4692
4819
|
void (async () => {
|
|
4693
4820
|
const url = new URL(request.url ?? "/", "http://localhost");
|
|
4694
|
-
const turnPath = /^\/turns\/([^/]+)\/(events|abort)$/u.exec(url.pathname);
|
|
4821
|
+
const turnPath = /^\/turns\/([^/]+)\/(events|abort|steer)$/u.exec(url.pathname);
|
|
4695
4822
|
if (request.method === "GET" && url.pathname === "/health") {
|
|
4696
4823
|
const health = {
|
|
4697
4824
|
ok: true,
|
|
@@ -4717,13 +4844,36 @@ data: ${turn.records[next]}
|
|
|
4717
4844
|
return streamTurn(turn, after, request, response);
|
|
4718
4845
|
}
|
|
4719
4846
|
if (request.method === "POST" && turnPath[2] === "abort") {
|
|
4720
|
-
if (!turn.
|
|
4847
|
+
if (!turn.ending && !turn.finishing && !turn.abortRequested) {
|
|
4721
4848
|
turn.abortRequested = true;
|
|
4849
|
+
turn.closed = true;
|
|
4850
|
+
reclaimSteers(turn);
|
|
4722
4851
|
if (turn === current) void currentSessionAbort?.().catch(() => void 0);
|
|
4723
4852
|
endAfterGrace(turn, "aborted");
|
|
4724
4853
|
}
|
|
4725
4854
|
return sendJson(response, 202, { turnId: turn.id, ended: turn.ended });
|
|
4726
4855
|
}
|
|
4856
|
+
if (request.method === "POST" && turnPath[2] === "steer") {
|
|
4857
|
+
const { steerId, message } = parseSteerTurn(await readJsonBody(request));
|
|
4858
|
+
const known = turn.steers.get(steerId);
|
|
4859
|
+
if (!known && (turn !== current || turn.closed)) {
|
|
4860
|
+
return sendJson(response, 409, { error: "The turn is no longer running.", turnId: turn.id });
|
|
4861
|
+
}
|
|
4862
|
+
const steer = known ?? acceptSteer(turn, steerId, message);
|
|
4863
|
+
await steer.settled;
|
|
4864
|
+
if (steer.state === "failed") throw steer.error;
|
|
4865
|
+
if (steer.state === "undelivered" && !turn.closed) {
|
|
4866
|
+
return sendJson(response, 501, { error: "The session does not take steering messages." });
|
|
4867
|
+
}
|
|
4868
|
+
if (steer.late || steer.state === "undelivered") {
|
|
4869
|
+
return sendJson(response, 409, { error: "The turn is no longer running.", turnId: turn.id });
|
|
4870
|
+
}
|
|
4871
|
+
return sendJson(response, known ? 200 : 202, {
|
|
4872
|
+
turnId: turn.id,
|
|
4873
|
+
steerId,
|
|
4874
|
+
...steer.state === "handled" ? { handled: true } : {}
|
|
4875
|
+
});
|
|
4876
|
+
}
|
|
4727
4877
|
}
|
|
4728
4878
|
sendJson(response, 404, { error: "Not found." });
|
|
4729
4879
|
})().catch((error) => {
|
|
@@ -4857,6 +5007,9 @@ var DefinedAgent = class {
|
|
|
4857
5007
|
abort(sandboxId, turnId, signal) {
|
|
4858
5008
|
return this.agent.abort(sandboxId, turnId, signal);
|
|
4859
5009
|
}
|
|
5010
|
+
steer(sandboxId, turnId, steer, signal) {
|
|
5011
|
+
return this.agent.steer(sandboxId, turnId, steer, signal);
|
|
5012
|
+
}
|
|
4860
5013
|
health(sandboxId, signal) {
|
|
4861
5014
|
return this.agent.health(sandboxId, signal);
|
|
4862
5015
|
}
|
|
@@ -4949,6 +5102,8 @@ async function createPiSession(config) {
|
|
|
4949
5102
|
subscribe: (listener) => session.subscribe(listener),
|
|
4950
5103
|
prompt: (text) => session.prompt(text),
|
|
4951
5104
|
abort: () => session.abort(),
|
|
5105
|
+
steer: (text) => session.steer(text),
|
|
5106
|
+
clearQueue: () => session.clearQueue(),
|
|
4952
5107
|
afterTurn: () => braintrust.flush()
|
|
4953
5108
|
};
|
|
4954
5109
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { S as SandboxFileContent$1, a as SandboxCommandOptions, b as SandboxCommandResult, c as SandboxDetachedCommandOptions, d as SandboxDetachedCommand } from './sandbox-capabilities-CFjnZ_kB.cjs';
|
|
3
|
-
import { S as StartTurnRequest, T as TurnRecord, a as
|
|
4
|
-
export { P as PiTurnResult,
|
|
3
|
+
import { S as StartTurnRequest, T as TurnRecord, a as SteerTurnRequest, b as TurnHealth, c as ServedSession, d as ServeHandle } from './serve-Du2NCz9_.cjs';
|
|
4
|
+
export { P as PiTurnResult, e as TURN_PROTOCOL_VERSION, f as TurnOutcome, g as getPiTurnResult } from './serve-Du2NCz9_.cjs';
|
|
5
5
|
|
|
6
6
|
/** Sandbox providers supported by the public and in-sandbox runtimes. */
|
|
7
7
|
type SandboxProvider = 'e2b' | 'daytona' | 'modal' | 'docker';
|
|
@@ -223,6 +223,14 @@ declare class Agent<TEvent = unknown> {
|
|
|
223
223
|
events(sandboxId: string, turnId: string, options?: TurnStreamOptions): AsyncGenerator<TurnRecord<TEvent>>;
|
|
224
224
|
/** Asks the runtime to stop the turn; its stream then ends with an `aborted` record. */
|
|
225
225
|
abort(sandboxId: string, turnId: string, signal?: AbortSignal): Promise<void>;
|
|
226
|
+
/**
|
|
227
|
+
* Queues a message for a running turn, which Pi takes after its current tool calls. Resolves to
|
|
228
|
+
* true once the session has queued it: it is then delivered into the turn, or named in the end
|
|
229
|
+
* record's `undeliveredSteerIds`. Resolves to false when the turn can no longer take it, or the
|
|
230
|
+
* runtime no longer has it, so the caller can send the message as a turn of its own. Throws when
|
|
231
|
+
* queueing failed or the request did; calling again with the same `steerId` never queues it twice.
|
|
232
|
+
*/
|
|
233
|
+
steer(sandboxId: string, turnId: string, steer: SteerTurnRequest, signal?: AbortSignal): Promise<boolean>;
|
|
226
234
|
health(sandboxId: string, signal?: AbortSignal): Promise<TurnHealth>;
|
|
227
235
|
/** Waits until no turn runs, for example before reading files a turn writes. */
|
|
228
236
|
waitForIdle(sandboxId: string, options?: {
|
|
@@ -348,6 +356,7 @@ declare class DefinedAgent<TEvent = unknown> {
|
|
|
348
356
|
run(sandboxId: string, turn: StartTurnRequest, options?: RunOptions<TEvent>): Promise<string | null>;
|
|
349
357
|
events(sandboxId: string, turnId: string, options?: TurnStreamOptions): AsyncGenerator<TurnRecord<TEvent>>;
|
|
350
358
|
abort(sandboxId: string, turnId: string, signal?: AbortSignal): Promise<void>;
|
|
359
|
+
steer(sandboxId: string, turnId: string, steer: SteerTurnRequest, signal?: AbortSignal): Promise<boolean>;
|
|
351
360
|
health(sandboxId: string, signal?: AbortSignal): Promise<TurnHealth>;
|
|
352
361
|
waitForIdle(sandboxId: string, options?: {
|
|
353
362
|
timeoutMs?: number;
|
|
@@ -1035,4 +1044,4 @@ declare class LegacyBundledAgent<TInput, TOutput = unknown, TFrame = unknown> {
|
|
|
1035
1044
|
}): AsyncGenerator<TFrame>;
|
|
1036
1045
|
}
|
|
1037
1046
|
|
|
1038
|
-
export { Agent, type AgentConfig, type AgentDefinition, type AgentKind, type AgentMode, type AgentOptions, type AgentRunContext, type AgentRunResult, type AgentSandbox, type AgentSandboxContext, type AgentSessionHandler, type AttachedAgentSession, type BuildOptions, ConfigurationError, type CreateAttachedSessionOptions, DEFAULT_DEPENDENCIES, type DaytonaAgentSandbox, type DaytonaSandboxConfig, DefinedAgent, DeploymentError, type DockerSandboxConfig, type E2BSandboxConfig, type E2bAgentSandbox, ExecutionError, type FileDownload, LegacyBundledAgent, type LocalDirectoryUpload, type ModalAgentSandbox, type ModalSandboxConfig, NeckbeardError, type NeckbeardNextConfigOptions, type OsDependencies, type PiSessionConfig, type ResolveAgentSourceFileOptions, type RunAgentConfig, type RunOptions, RuntimeBusyError, SKILLS_DIR, SandboxClient, type SandboxClientConnectOptions, type SandboxClientCreateOptions, SandboxCommandOptions, SandboxCommandResult, type SandboxConfig, SandboxDetachedCommand, SandboxDetachedCommandOptions, type SandboxFileContent, type SandboxProvider, type SandboxServerEndpoint, type ServerAgentConfig, type SessionAgentConfig, type SessionDurability, type StartOptions, StartTurnRequest, TurnHealth, TurnLostError, TurnRecord, type TurnStreamOptions, ValidationError, defineAgent, isDefinedAgent, resolveAgentSourceFile, resolveImageTag, withNeckbeardNextConfig };
|
|
1047
|
+
export { Agent, type AgentConfig, type AgentDefinition, type AgentKind, type AgentMode, type AgentOptions, type AgentRunContext, type AgentRunResult, type AgentSandbox, type AgentSandboxContext, type AgentSessionHandler, type AttachedAgentSession, type BuildOptions, ConfigurationError, type CreateAttachedSessionOptions, DEFAULT_DEPENDENCIES, type DaytonaAgentSandbox, type DaytonaSandboxConfig, DefinedAgent, DeploymentError, type DockerSandboxConfig, type E2BSandboxConfig, type E2bAgentSandbox, ExecutionError, type FileDownload, LegacyBundledAgent, type LocalDirectoryUpload, type ModalAgentSandbox, type ModalSandboxConfig, NeckbeardError, type NeckbeardNextConfigOptions, type OsDependencies, type PiSessionConfig, type ResolveAgentSourceFileOptions, type RunAgentConfig, type RunOptions, RuntimeBusyError, SKILLS_DIR, SandboxClient, type SandboxClientConnectOptions, type SandboxClientCreateOptions, SandboxCommandOptions, SandboxCommandResult, type SandboxConfig, SandboxDetachedCommand, SandboxDetachedCommandOptions, type SandboxFileContent, type SandboxProvider, type SandboxServerEndpoint, type ServerAgentConfig, type SessionAgentConfig, type SessionDurability, type StartOptions, StartTurnRequest, SteerTurnRequest, TurnHealth, TurnLostError, TurnRecord, type TurnStreamOptions, ValidationError, defineAgent, isDefinedAgent, resolveAgentSourceFile, resolveImageTag, withNeckbeardNextConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { S as SandboxFileContent$1, a as SandboxCommandOptions, b as SandboxCommandResult, c as SandboxDetachedCommandOptions, d as SandboxDetachedCommand } from './sandbox-capabilities-CFjnZ_kB.js';
|
|
3
|
-
import { S as StartTurnRequest, T as TurnRecord, a as
|
|
4
|
-
export { P as PiTurnResult,
|
|
3
|
+
import { S as StartTurnRequest, T as TurnRecord, a as SteerTurnRequest, b as TurnHealth, c as ServedSession, d as ServeHandle } from './serve-Du2NCz9_.js';
|
|
4
|
+
export { P as PiTurnResult, e as TURN_PROTOCOL_VERSION, f as TurnOutcome, g as getPiTurnResult } from './serve-Du2NCz9_.js';
|
|
5
5
|
|
|
6
6
|
/** Sandbox providers supported by the public and in-sandbox runtimes. */
|
|
7
7
|
type SandboxProvider = 'e2b' | 'daytona' | 'modal' | 'docker';
|
|
@@ -223,6 +223,14 @@ declare class Agent<TEvent = unknown> {
|
|
|
223
223
|
events(sandboxId: string, turnId: string, options?: TurnStreamOptions): AsyncGenerator<TurnRecord<TEvent>>;
|
|
224
224
|
/** Asks the runtime to stop the turn; its stream then ends with an `aborted` record. */
|
|
225
225
|
abort(sandboxId: string, turnId: string, signal?: AbortSignal): Promise<void>;
|
|
226
|
+
/**
|
|
227
|
+
* Queues a message for a running turn, which Pi takes after its current tool calls. Resolves to
|
|
228
|
+
* true once the session has queued it: it is then delivered into the turn, or named in the end
|
|
229
|
+
* record's `undeliveredSteerIds`. Resolves to false when the turn can no longer take it, or the
|
|
230
|
+
* runtime no longer has it, so the caller can send the message as a turn of its own. Throws when
|
|
231
|
+
* queueing failed or the request did; calling again with the same `steerId` never queues it twice.
|
|
232
|
+
*/
|
|
233
|
+
steer(sandboxId: string, turnId: string, steer: SteerTurnRequest, signal?: AbortSignal): Promise<boolean>;
|
|
226
234
|
health(sandboxId: string, signal?: AbortSignal): Promise<TurnHealth>;
|
|
227
235
|
/** Waits until no turn runs, for example before reading files a turn writes. */
|
|
228
236
|
waitForIdle(sandboxId: string, options?: {
|
|
@@ -348,6 +356,7 @@ declare class DefinedAgent<TEvent = unknown> {
|
|
|
348
356
|
run(sandboxId: string, turn: StartTurnRequest, options?: RunOptions<TEvent>): Promise<string | null>;
|
|
349
357
|
events(sandboxId: string, turnId: string, options?: TurnStreamOptions): AsyncGenerator<TurnRecord<TEvent>>;
|
|
350
358
|
abort(sandboxId: string, turnId: string, signal?: AbortSignal): Promise<void>;
|
|
359
|
+
steer(sandboxId: string, turnId: string, steer: SteerTurnRequest, signal?: AbortSignal): Promise<boolean>;
|
|
351
360
|
health(sandboxId: string, signal?: AbortSignal): Promise<TurnHealth>;
|
|
352
361
|
waitForIdle(sandboxId: string, options?: {
|
|
353
362
|
timeoutMs?: number;
|
|
@@ -1035,4 +1044,4 @@ declare class LegacyBundledAgent<TInput, TOutput = unknown, TFrame = unknown> {
|
|
|
1035
1044
|
}): AsyncGenerator<TFrame>;
|
|
1036
1045
|
}
|
|
1037
1046
|
|
|
1038
|
-
export { Agent, type AgentConfig, type AgentDefinition, type AgentKind, type AgentMode, type AgentOptions, type AgentRunContext, type AgentRunResult, type AgentSandbox, type AgentSandboxContext, type AgentSessionHandler, type AttachedAgentSession, type BuildOptions, ConfigurationError, type CreateAttachedSessionOptions, DEFAULT_DEPENDENCIES, type DaytonaAgentSandbox, type DaytonaSandboxConfig, DefinedAgent, DeploymentError, type DockerSandboxConfig, type E2BSandboxConfig, type E2bAgentSandbox, ExecutionError, type FileDownload, LegacyBundledAgent, type LocalDirectoryUpload, type ModalAgentSandbox, type ModalSandboxConfig, NeckbeardError, type NeckbeardNextConfigOptions, type OsDependencies, type PiSessionConfig, type ResolveAgentSourceFileOptions, type RunAgentConfig, type RunOptions, RuntimeBusyError, SKILLS_DIR, SandboxClient, type SandboxClientConnectOptions, type SandboxClientCreateOptions, SandboxCommandOptions, SandboxCommandResult, type SandboxConfig, SandboxDetachedCommand, SandboxDetachedCommandOptions, type SandboxFileContent, type SandboxProvider, type SandboxServerEndpoint, type ServerAgentConfig, type SessionAgentConfig, type SessionDurability, type StartOptions, StartTurnRequest, TurnHealth, TurnLostError, TurnRecord, type TurnStreamOptions, ValidationError, defineAgent, isDefinedAgent, resolveAgentSourceFile, resolveImageTag, withNeckbeardNextConfig };
|
|
1047
|
+
export { Agent, type AgentConfig, type AgentDefinition, type AgentKind, type AgentMode, type AgentOptions, type AgentRunContext, type AgentRunResult, type AgentSandbox, type AgentSandboxContext, type AgentSessionHandler, type AttachedAgentSession, type BuildOptions, ConfigurationError, type CreateAttachedSessionOptions, DEFAULT_DEPENDENCIES, type DaytonaAgentSandbox, type DaytonaSandboxConfig, DefinedAgent, DeploymentError, type DockerSandboxConfig, type E2BSandboxConfig, type E2bAgentSandbox, ExecutionError, type FileDownload, LegacyBundledAgent, type LocalDirectoryUpload, type ModalAgentSandbox, type ModalSandboxConfig, NeckbeardError, type NeckbeardNextConfigOptions, type OsDependencies, type PiSessionConfig, type ResolveAgentSourceFileOptions, type RunAgentConfig, type RunOptions, RuntimeBusyError, SKILLS_DIR, SandboxClient, type SandboxClientConnectOptions, type SandboxClientCreateOptions, SandboxCommandOptions, SandboxCommandResult, type SandboxConfig, SandboxDetachedCommand, SandboxDetachedCommandOptions, type SandboxFileContent, type SandboxProvider, type SandboxServerEndpoint, type ServerAgentConfig, type SessionAgentConfig, type SessionDurability, type StartOptions, StartTurnRequest, SteerTurnRequest, TurnHealth, TurnLostError, TurnRecord, type TurnStreamOptions, ValidationError, defineAgent, isDefinedAgent, resolveAgentSourceFile, resolveImageTag, withNeckbeardNextConfig };
|
package/dist/index.js
CHANGED
|
@@ -19,12 +19,12 @@ import {
|
|
|
19
19
|
resolveAgentSourceFile,
|
|
20
20
|
resolveImageTag,
|
|
21
21
|
withNeckbeardNextConfig
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-BPXEIXPM.js";
|
|
23
23
|
import "./chunk-6P5I7ZCH.js";
|
|
24
24
|
import {
|
|
25
25
|
TURN_PROTOCOL_VERSION,
|
|
26
26
|
getPiTurnResult
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-YFG4EKZM.js";
|
|
28
28
|
import "./chunk-KG6SJM74.js";
|
|
29
29
|
import "./chunk-33IXN6MM.js";
|
|
30
30
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Wire contract between `Agent` on the host and `serve()` in the sandbox. See docs/AGENT.md.
|
|
3
3
|
*/
|
|
4
|
-
declare const TURN_PROTOCOL_VERSION =
|
|
4
|
+
declare const TURN_PROTOCOL_VERSION = 3;
|
|
5
5
|
/** One record of a turn's stream. `seq` starts at 0 and increases by one per record. */
|
|
6
6
|
type TurnRecord<TEvent = unknown> = {
|
|
7
7
|
seq: number;
|
|
@@ -12,6 +12,8 @@ type TurnRecord<TEvent = unknown> = {
|
|
|
12
12
|
type: 'end';
|
|
13
13
|
outcome: TurnOutcome;
|
|
14
14
|
error?: string;
|
|
15
|
+
/** Steers the runtime accepted that the turn ended without taking, oldest first. */
|
|
16
|
+
undeliveredSteerIds?: string[];
|
|
15
17
|
};
|
|
16
18
|
type TurnOutcome = 'completed' | 'aborted' | 'failed';
|
|
17
19
|
interface StartTurnRequest {
|
|
@@ -21,6 +23,11 @@ interface StartTurnRequest {
|
|
|
21
23
|
/** Set in the agent's `process.env` for this turn only, then restored. */
|
|
22
24
|
env?: Record<string, string>;
|
|
23
25
|
}
|
|
26
|
+
interface SteerTurnRequest {
|
|
27
|
+
/** Caller-chosen, stable per steer, so a retried steer is never queued twice. */
|
|
28
|
+
steerId: string;
|
|
29
|
+
message: string;
|
|
30
|
+
}
|
|
24
31
|
interface TurnHealth {
|
|
25
32
|
ok: true;
|
|
26
33
|
protocolVersion: number;
|
|
@@ -46,6 +53,21 @@ interface ServedSession {
|
|
|
46
53
|
subscribe(listener: (event: unknown) => void): () => void;
|
|
47
54
|
prompt(text: string): Promise<void>;
|
|
48
55
|
abort(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Queues a message for the running prompt, which Pi delivers after its current tool calls and
|
|
58
|
+
* before its next model call. It may take a while, as Pi runs its input hooks first, and
|
|
59
|
+
* resolves to `"handled"` when a hook took the message instead of queueing it. Without it, the
|
|
60
|
+
* runtime answers a steer with 501.
|
|
61
|
+
*/
|
|
62
|
+
steer?(text: string): Promise<unknown>;
|
|
63
|
+
/**
|
|
64
|
+
* Empties the session's queue, returning the steering messages its prompt never took. A session
|
|
65
|
+
* with `steer()` needs it: without it the runtime can't take back a steer the turn never took,
|
|
66
|
+
* so it answers a steer with 501.
|
|
67
|
+
*/
|
|
68
|
+
clearQueue?(): {
|
|
69
|
+
steering: readonly unknown[];
|
|
70
|
+
};
|
|
49
71
|
/**
|
|
50
72
|
* Runs once each turn's outcome is known: outside its deadline, so it can't fail the turn, and
|
|
51
73
|
* before its end record, so a host that deletes the sandbox at the end loses nothing, as when
|
|
@@ -86,4 +108,4 @@ declare function toPiJsonEvent(event: unknown): unknown;
|
|
|
86
108
|
*/
|
|
87
109
|
declare function serve(options: ServeOptions): Promise<ServeHandle>;
|
|
88
110
|
|
|
89
|
-
export { type PiTurnResult as P, type StartTurnRequest as S, type TurnRecord as T, type
|
|
111
|
+
export { type PiTurnResult as P, type StartTurnRequest as S, type TurnRecord as T, type SteerTurnRequest as a, type TurnHealth as b, type ServedSession as c, type ServeHandle as d, TURN_PROTOCOL_VERSION as e, type TurnOutcome as f, getPiTurnResult as g, type ServeOptions as h, serve as s, toPiJsonEvent as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Wire contract between `Agent` on the host and `serve()` in the sandbox. See docs/AGENT.md.
|
|
3
3
|
*/
|
|
4
|
-
declare const TURN_PROTOCOL_VERSION =
|
|
4
|
+
declare const TURN_PROTOCOL_VERSION = 3;
|
|
5
5
|
/** One record of a turn's stream. `seq` starts at 0 and increases by one per record. */
|
|
6
6
|
type TurnRecord<TEvent = unknown> = {
|
|
7
7
|
seq: number;
|
|
@@ -12,6 +12,8 @@ type TurnRecord<TEvent = unknown> = {
|
|
|
12
12
|
type: 'end';
|
|
13
13
|
outcome: TurnOutcome;
|
|
14
14
|
error?: string;
|
|
15
|
+
/** Steers the runtime accepted that the turn ended without taking, oldest first. */
|
|
16
|
+
undeliveredSteerIds?: string[];
|
|
15
17
|
};
|
|
16
18
|
type TurnOutcome = 'completed' | 'aborted' | 'failed';
|
|
17
19
|
interface StartTurnRequest {
|
|
@@ -21,6 +23,11 @@ interface StartTurnRequest {
|
|
|
21
23
|
/** Set in the agent's `process.env` for this turn only, then restored. */
|
|
22
24
|
env?: Record<string, string>;
|
|
23
25
|
}
|
|
26
|
+
interface SteerTurnRequest {
|
|
27
|
+
/** Caller-chosen, stable per steer, so a retried steer is never queued twice. */
|
|
28
|
+
steerId: string;
|
|
29
|
+
message: string;
|
|
30
|
+
}
|
|
24
31
|
interface TurnHealth {
|
|
25
32
|
ok: true;
|
|
26
33
|
protocolVersion: number;
|
|
@@ -46,6 +53,21 @@ interface ServedSession {
|
|
|
46
53
|
subscribe(listener: (event: unknown) => void): () => void;
|
|
47
54
|
prompt(text: string): Promise<void>;
|
|
48
55
|
abort(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Queues a message for the running prompt, which Pi delivers after its current tool calls and
|
|
58
|
+
* before its next model call. It may take a while, as Pi runs its input hooks first, and
|
|
59
|
+
* resolves to `"handled"` when a hook took the message instead of queueing it. Without it, the
|
|
60
|
+
* runtime answers a steer with 501.
|
|
61
|
+
*/
|
|
62
|
+
steer?(text: string): Promise<unknown>;
|
|
63
|
+
/**
|
|
64
|
+
* Empties the session's queue, returning the steering messages its prompt never took. A session
|
|
65
|
+
* with `steer()` needs it: without it the runtime can't take back a steer the turn never took,
|
|
66
|
+
* so it answers a steer with 501.
|
|
67
|
+
*/
|
|
68
|
+
clearQueue?(): {
|
|
69
|
+
steering: readonly unknown[];
|
|
70
|
+
};
|
|
49
71
|
/**
|
|
50
72
|
* Runs once each turn's outcome is known: outside its deadline, so it can't fail the turn, and
|
|
51
73
|
* before its end record, so a host that deletes the sandbox at the end loses nothing, as when
|
|
@@ -86,4 +108,4 @@ declare function toPiJsonEvent(event: unknown): unknown;
|
|
|
86
108
|
*/
|
|
87
109
|
declare function serve(options: ServeOptions): Promise<ServeHandle>;
|
|
88
110
|
|
|
89
|
-
export { type PiTurnResult as P, type StartTurnRequest as S, type TurnRecord as T, type
|
|
111
|
+
export { type PiTurnResult as P, type StartTurnRequest as S, type TurnRecord as T, type SteerTurnRequest as a, type TurnHealth as b, type ServedSession as c, type ServeHandle as d, TURN_PROTOCOL_VERSION as e, type TurnOutcome as f, getPiTurnResult as g, type ServeOptions as h, serve as s, toPiJsonEvent as t };
|