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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.29 - 2026-11-19
|
|
4
|
+
|
|
5
|
+
- Add `Agent.steer(sandboxId, turnId, { steerId, message })` and the runtime's `POST /turns/:turnId/steer`, which queue a message for a running turn with the session's `steer()`; Pi delivers it after its current tool calls. Each steer gets exactly one outcome: it is delivered into its turn, or the turn's end record names it in `undeliveredSteerIds`, and it never reaches a later turn. `steer()` returns `false` for a turn that can no longer take it, a repeated `steerId` shares the first request's outcome, and an abort takes back the steers still queued before stopping the session. See `docs/AGENT.md#steering`.
|
|
6
|
+
- **Breaking:** the turn protocol is version 3. A host on this release refuses to start a sandbox whose image serves version 2, so build the agent's image with this release before deploying the host, as a host that runs its own commit's image does.
|
|
7
|
+
|
|
3
8
|
## 1.1.28 - 2026-11-13
|
|
4
9
|
|
|
5
10
|
- Add `Agent`, which runs a Pi agent from a prebuilt container image, and `serve()` from the new `agent-neckbeard/serve` entry point, which the image runs as its main process around its Pi session, calling the session's optional `afterTurn()` before each turn's end record and outside its deadline. Starting a sandbox installs and uploads nothing, and `kill()` throws when a provider fails to delete a sandbox that still exists, so cleanup can be retried. Turns carry a caller-chosen `turnId` and per-turn `env`, stream numbered records of Pi's JSON events, keep running when the host disconnects, and resume from any record; retrying a start never runs a turn twice. Modal pulls the image directly; `prepare()` turns it into a Daytona snapshot or E2B template, and `gc()` deletes older ones. See `docs/AGENT.md`.
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Neckbeard runs a [Pi](https://github.com/earendil-works/pi) agent in a Daytona,
|
|
|
8
8
|
|
|
9
9
|
```
|
|
10
10
|
my-agent/
|
|
11
|
-
|
|
11
|
+
agent.ts # defineAgent(): the image, the sandbox, and the Pi session, used by both your process and the image
|
|
12
12
|
skills/ # skills you wrote, committed
|
|
13
13
|
skills-lock.json # third-party skills, pinned to commits (npx skills@1.8.1 add <repo>#<sha> --skill <name> --copy)
|
|
14
14
|
sandbox/Dockerfile # OS and Python packages; copies in what neckbeard build writes
|
|
@@ -20,7 +20,7 @@ my-agent/
|
|
|
20
20
|
npm install agent-neckbeard @earendil-works/pi-coding-agent
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
`
|
|
23
|
+
`agent.ts` defines the agent once. In the image it serves its Pi session, which lives as long as the sandbox, so each turn remembers the earlier ones; in your process it starts sandboxes and runs turns.
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
26
|
import { defineAgent } from "agent-neckbeard";
|
|
@@ -38,7 +38,7 @@ export const myAgent = defineAgent<JsonAgentSessionEvent>({
|
|
|
38
38
|
`neckbeard push`, run from CI, bundles it with Pi's `package.json` and installs `skills/` and the locked skills into the image's build context, builds the image with `sandbox/Dockerfile` ([example](docs/AGENT.md#building-and-pushing-the-image)), pushes it tagged with the commit, and creates its Daytona snapshot:
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
npx neckbeard push
|
|
41
|
+
npx neckbeard push agent.ts --tag $GITHUB_SHA
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
Then run a turn from your process. A host deployed from the same commit runs that commit's image: it finds the commit in `GITHUB_SHA`, `RENDER_GIT_COMMIT`, `VERCEL_GIT_COMMIT_SHA` and the like, or `NECKBEARD_IMAGE_TAG` ([image names](docs/AGENT.md#image-names)).
|
package/dist/build.cjs
CHANGED
|
@@ -3428,7 +3428,7 @@ var ModalSandboxHandle = class _ModalSandboxHandle {
|
|
|
3428
3428
|
};
|
|
3429
3429
|
|
|
3430
3430
|
// src/turn-protocol.ts
|
|
3431
|
-
var TURN_PROTOCOL_VERSION =
|
|
3431
|
+
var TURN_PROTOCOL_VERSION = 3;
|
|
3432
3432
|
var MAX_TURN_REQUEST_BYTES = 4 * 1024 * 1024;
|
|
3433
3433
|
var MAX_TURN_ID_LENGTH = 200;
|
|
3434
3434
|
function isRecord2(value) {
|
|
@@ -3443,12 +3443,13 @@ function parseTurnRecord(record) {
|
|
|
3443
3443
|
if (record.type === "event" && "event" in record) {
|
|
3444
3444
|
return { seq, type: "event", event: record.event };
|
|
3445
3445
|
}
|
|
3446
|
-
if (record.type === "end" && (record.outcome === "completed" || record.outcome === "aborted" || record.outcome === "failed") && (record.error === void 0 || typeof record.error === "string")) {
|
|
3446
|
+
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"))) {
|
|
3447
3447
|
return {
|
|
3448
3448
|
seq,
|
|
3449
3449
|
type: "end",
|
|
3450
3450
|
outcome: record.outcome,
|
|
3451
|
-
...record.error === void 0 ? {} : { error: record.error }
|
|
3451
|
+
...record.error === void 0 ? {} : { error: record.error },
|
|
3452
|
+
...record.undeliveredSteerIds === void 0 ? {} : { undeliveredSteerIds: record.undeliveredSteerIds }
|
|
3452
3453
|
};
|
|
3453
3454
|
}
|
|
3454
3455
|
throw new Error("Turn record has an unknown shape.");
|
|
@@ -4448,6 +4449,25 @@ var Agent = class {
|
|
|
4448
4449
|
throw new ExecutionError(`Aborting turn ${turnId} failed with ${response.status}.`);
|
|
4449
4450
|
}
|
|
4450
4451
|
}
|
|
4452
|
+
/**
|
|
4453
|
+
* Queues a message for a running turn, which Pi takes after its current tool calls. Resolves to
|
|
4454
|
+
* true once the session has queued it: it is then delivered into the turn, or named in the end
|
|
4455
|
+
* record's `undeliveredSteerIds`. Resolves to false when the turn can no longer take it, or the
|
|
4456
|
+
* runtime no longer has it, so the caller can send the message as a turn of its own. Throws when
|
|
4457
|
+
* queueing failed or the request did; calling again with the same `steerId` never queues it twice.
|
|
4458
|
+
*/
|
|
4459
|
+
async steer(sandboxId, turnId, steer, signal) {
|
|
4460
|
+
const response = await this.request(sandboxId, "POST", `/turns/${encodeURIComponent(turnId)}/steer`, steer, signal);
|
|
4461
|
+
if (response.status === 200 || response.status === 202) {
|
|
4462
|
+
await response.body?.cancel();
|
|
4463
|
+
return true;
|
|
4464
|
+
}
|
|
4465
|
+
if (response.status === 409 || response.status === 404) {
|
|
4466
|
+
await response.body?.cancel();
|
|
4467
|
+
return false;
|
|
4468
|
+
}
|
|
4469
|
+
throw new ExecutionError(`Steering turn ${turnId} failed with ${response.status}: ${await response.text()}`);
|
|
4470
|
+
}
|
|
4451
4471
|
async health(sandboxId, signal) {
|
|
4452
4472
|
const response = await this.request(sandboxId, "GET", "/health", void 0, signal);
|
|
4453
4473
|
if (!response.ok) throw new ExecutionError(`Health check of sandbox ${sandboxId} returned ${response.status}.`);
|
|
@@ -4802,6 +4822,17 @@ function parseStartTurn(body) {
|
|
|
4802
4822
|
}
|
|
4803
4823
|
return { turnId, message, ...env === void 0 ? {} : { env } };
|
|
4804
4824
|
}
|
|
4825
|
+
function parseSteerTurn(body) {
|
|
4826
|
+
if (!body || typeof body !== "object") throw new RequestError(400, "Request body must be an object.");
|
|
4827
|
+
const { steerId, message } = body;
|
|
4828
|
+
if (typeof steerId !== "string" || !steerId || steerId.length > MAX_TURN_ID_LENGTH) {
|
|
4829
|
+
throw new RequestError(400, `steerId must be a non-empty string of at most ${MAX_TURN_ID_LENGTH} characters.`);
|
|
4830
|
+
}
|
|
4831
|
+
if (typeof message !== "string" || !message.trim()) {
|
|
4832
|
+
throw new RequestError(400, "message must be a non-empty string.");
|
|
4833
|
+
}
|
|
4834
|
+
return { steerId, message };
|
|
4835
|
+
}
|
|
4805
4836
|
async function serve(options) {
|
|
4806
4837
|
const toWireEvent = options.toWireEvent ?? toPiJsonEvent;
|
|
4807
4838
|
let sessionPromise;
|
|
@@ -4814,14 +4845,85 @@ async function serve(options) {
|
|
|
4814
4845
|
turn.records.push(json);
|
|
4815
4846
|
for (const wake of turn.waiters) wake();
|
|
4816
4847
|
};
|
|
4848
|
+
const reclaimSteers = (turn) => {
|
|
4849
|
+
let left;
|
|
4850
|
+
try {
|
|
4851
|
+
left = turn.session?.clearQueue?.().steering.length ?? 0;
|
|
4852
|
+
} catch {
|
|
4853
|
+
left = turn.queuedSteers.length;
|
|
4854
|
+
sessionPromise = void 0;
|
|
4855
|
+
}
|
|
4856
|
+
const leftover = left > 0 ? turn.queuedSteers.slice(-left) : [];
|
|
4857
|
+
for (const steer of turn.queuedSteers) steer.state = leftover.includes(steer) ? "undelivered" : "delivered";
|
|
4858
|
+
turn.queuedSteers = [];
|
|
4859
|
+
turn.undeliveredSteers.push(...leftover);
|
|
4860
|
+
};
|
|
4817
4861
|
const end = (turn, outcome, error) => {
|
|
4818
|
-
if (turn.
|
|
4819
|
-
|
|
4820
|
-
turn.
|
|
4862
|
+
if (turn.ending) return turn.ending;
|
|
4863
|
+
turn.closed = true;
|
|
4864
|
+
turn.sessionReady();
|
|
4865
|
+
let written;
|
|
4866
|
+
turn.ending = new Promise((resolve2) => {
|
|
4867
|
+
written = resolve2;
|
|
4868
|
+
});
|
|
4869
|
+
reclaimSteers(turn);
|
|
4870
|
+
void (async () => {
|
|
4871
|
+
let timer;
|
|
4872
|
+
const graceMs = turn.stopBy === void 0 ? options.abortGraceMs ?? DEFAULT_ABORT_GRACE_MS : Math.max(0, turn.stopBy - Date.now());
|
|
4873
|
+
await Promise.race([
|
|
4874
|
+
turn.steering,
|
|
4875
|
+
new Promise((resolve2) => {
|
|
4876
|
+
timer = setTimeout(resolve2, graceMs);
|
|
4877
|
+
})
|
|
4878
|
+
]);
|
|
4879
|
+
clearTimeout(timer);
|
|
4880
|
+
reclaimSteers(turn);
|
|
4881
|
+
const undeliveredSteerIds = turn.undeliveredSteers.filter((steer) => !steer.late).map((steer) => steer.id);
|
|
4882
|
+
append(turn, {
|
|
4883
|
+
type: "end",
|
|
4884
|
+
outcome,
|
|
4885
|
+
...error === void 0 ? {} : { error },
|
|
4886
|
+
...undeliveredSteerIds.length > 0 ? { undeliveredSteerIds } : {}
|
|
4887
|
+
});
|
|
4888
|
+
turn.ended = true;
|
|
4889
|
+
written();
|
|
4890
|
+
})();
|
|
4891
|
+
return turn.ending;
|
|
4892
|
+
};
|
|
4893
|
+
const acceptSteer = (turn, id, message) => {
|
|
4894
|
+
const steer = { id, state: "pending", late: false, settled: Promise.resolve() };
|
|
4895
|
+
steer.settled = turn.steering.then(async () => {
|
|
4896
|
+
const session = turn.session;
|
|
4897
|
+
if (turn.closed || !session?.steer || !session.clearQueue) {
|
|
4898
|
+
steer.state = "undelivered";
|
|
4899
|
+
return;
|
|
4900
|
+
}
|
|
4901
|
+
try {
|
|
4902
|
+
if (await session.steer(message) === "handled") {
|
|
4903
|
+
steer.state = "handled";
|
|
4904
|
+
return;
|
|
4905
|
+
}
|
|
4906
|
+
steer.state = "queued";
|
|
4907
|
+
turn.queuedSteers.push(steer);
|
|
4908
|
+
if (turn.closed) {
|
|
4909
|
+
reclaimSteers(turn);
|
|
4910
|
+
steer.late = turn.undeliveredSteers.includes(steer);
|
|
4911
|
+
}
|
|
4912
|
+
} catch (error) {
|
|
4913
|
+
steer.state = "failed";
|
|
4914
|
+
steer.error = error;
|
|
4915
|
+
turn.steers.delete(id);
|
|
4916
|
+
}
|
|
4917
|
+
});
|
|
4918
|
+
turn.steering = steer.settled;
|
|
4919
|
+
turn.steers.set(id, steer);
|
|
4920
|
+
return steer;
|
|
4821
4921
|
};
|
|
4822
4922
|
const endAfterGrace = (turn, outcome, error) => {
|
|
4823
|
-
if (turn.
|
|
4824
|
-
|
|
4923
|
+
if (turn.ending || turn.finishing || turn.forceEnd) return;
|
|
4924
|
+
const graceMs = options.abortGraceMs ?? DEFAULT_ABORT_GRACE_MS;
|
|
4925
|
+
turn.stopBy = Date.now() + graceMs;
|
|
4926
|
+
turn.forceEnd = setTimeout(() => void end(turn, outcome, error), graceMs);
|
|
4825
4927
|
};
|
|
4826
4928
|
const runTurn = async (turn, request) => {
|
|
4827
4929
|
const previousEnv = /* @__PURE__ */ new Map();
|
|
@@ -4831,18 +4933,21 @@ async function serve(options) {
|
|
|
4831
4933
|
const timeoutMessage = `Turn exceeded ${options.maxTurnDurationMs}ms.`;
|
|
4832
4934
|
const timer = options.maxTurnDurationMs === void 0 ? void 0 : setTimeout(() => {
|
|
4833
4935
|
timedOut = true;
|
|
4936
|
+
turn.closed = true;
|
|
4937
|
+
reclaimSteers(turn);
|
|
4834
4938
|
if (session) void session.abort().catch(() => void 0);
|
|
4835
4939
|
endAfterGrace(turn, "failed", timeoutMessage);
|
|
4836
4940
|
}, options.maxTurnDurationMs);
|
|
4837
4941
|
const finish = async (outcome, error) => {
|
|
4838
4942
|
turn.finishing = true;
|
|
4943
|
+
turn.closed = true;
|
|
4839
4944
|
if (timer) clearTimeout(timer);
|
|
4840
4945
|
clearTimeout(turn.forceEnd);
|
|
4841
4946
|
try {
|
|
4842
4947
|
await session?.afterTurn?.();
|
|
4843
4948
|
} catch {
|
|
4844
4949
|
}
|
|
4845
|
-
end(turn, outcome, error);
|
|
4950
|
+
await end(turn, outcome, error);
|
|
4846
4951
|
};
|
|
4847
4952
|
try {
|
|
4848
4953
|
sessionPromise ??= options.createSession();
|
|
@@ -4853,26 +4958,34 @@ async function serve(options) {
|
|
|
4853
4958
|
throw error;
|
|
4854
4959
|
}
|
|
4855
4960
|
if (timedOut) {
|
|
4856
|
-
end(turn, "failed", timeoutMessage);
|
|
4961
|
+
await end(turn, "failed", timeoutMessage);
|
|
4857
4962
|
return;
|
|
4858
4963
|
}
|
|
4859
4964
|
const started = session;
|
|
4965
|
+
turn.session = session;
|
|
4860
4966
|
for (const [name, value] of Object.entries(request.env ?? {})) {
|
|
4861
4967
|
previousEnv.set(name, process.env[name]);
|
|
4862
4968
|
process.env[name] = value;
|
|
4863
4969
|
}
|
|
4864
4970
|
unsubscribe = session.subscribe((event) => {
|
|
4865
|
-
if (turn.
|
|
4971
|
+
if (turn.ending) return;
|
|
4866
4972
|
try {
|
|
4867
4973
|
append(turn, { type: "event", event: toWireEvent(event) });
|
|
4868
4974
|
} catch (error) {
|
|
4869
|
-
end(turn, "failed", `Could not convert an agent event: ${error instanceof Error ? error.message : String(error)}`);
|
|
4975
|
+
void end(turn, "failed", `Could not convert an agent event: ${error instanceof Error ? error.message : String(error)}`);
|
|
4870
4976
|
void started.abort().catch(() => void 0);
|
|
4871
4977
|
}
|
|
4872
4978
|
});
|
|
4873
4979
|
currentSessionAbort = () => started.abort();
|
|
4980
|
+
turn.sessionReady();
|
|
4981
|
+
if (!turn.closed) await turn.steering;
|
|
4982
|
+
if (turn.ending) return;
|
|
4983
|
+
if (timedOut) {
|
|
4984
|
+
await end(turn, "failed", timeoutMessage);
|
|
4985
|
+
return;
|
|
4986
|
+
}
|
|
4874
4987
|
if (turn.abortRequested) {
|
|
4875
|
-
end(turn, "aborted");
|
|
4988
|
+
await end(turn, "aborted");
|
|
4876
4989
|
return;
|
|
4877
4990
|
}
|
|
4878
4991
|
await started.prompt(request.message);
|
|
@@ -4885,8 +4998,13 @@ async function serve(options) {
|
|
|
4885
4998
|
} finally {
|
|
4886
4999
|
if (timer) clearTimeout(timer);
|
|
4887
5000
|
clearTimeout(turn.forceEnd);
|
|
5001
|
+
turn.closed = true;
|
|
5002
|
+
turn.sessionReady();
|
|
5003
|
+
await turn.ending;
|
|
4888
5004
|
unsubscribe?.();
|
|
4889
5005
|
currentSessionAbort = void 0;
|
|
5006
|
+
await turn.steering;
|
|
5007
|
+
reclaimSteers(turn);
|
|
4890
5008
|
for (const [name, value] of previousEnv) {
|
|
4891
5009
|
if (value === void 0) delete process.env[name];
|
|
4892
5010
|
else process.env[name] = value;
|
|
@@ -4901,12 +5019,21 @@ async function serve(options) {
|
|
|
4901
5019
|
if (current && !current.settled) {
|
|
4902
5020
|
return { status: 409, body: { error: "Another turn is running.", turnId: current.id } };
|
|
4903
5021
|
}
|
|
5022
|
+
let sessionReady;
|
|
4904
5023
|
const turn = {
|
|
4905
5024
|
id: request.turnId,
|
|
4906
5025
|
records: [],
|
|
4907
5026
|
ended: false,
|
|
4908
5027
|
settled: false,
|
|
4909
5028
|
abortRequested: false,
|
|
5029
|
+
steers: /* @__PURE__ */ new Map(),
|
|
5030
|
+
queuedSteers: [],
|
|
5031
|
+
undeliveredSteers: [],
|
|
5032
|
+
steering: new Promise((resolve2) => {
|
|
5033
|
+
sessionReady = resolve2;
|
|
5034
|
+
}),
|
|
5035
|
+
sessionReady: () => sessionReady(),
|
|
5036
|
+
closed: false,
|
|
4910
5037
|
finishing: false,
|
|
4911
5038
|
waiters: /* @__PURE__ */ new Set()
|
|
4912
5039
|
};
|
|
@@ -4971,7 +5098,7 @@ data: ${turn.records[next]}
|
|
|
4971
5098
|
const server = (0, import_node_http.createServer)((request, response) => {
|
|
4972
5099
|
void (async () => {
|
|
4973
5100
|
const url = new URL(request.url ?? "/", "http://localhost");
|
|
4974
|
-
const turnPath = /^\/turns\/([^/]+)\/(events|abort)$/u.exec(url.pathname);
|
|
5101
|
+
const turnPath = /^\/turns\/([^/]+)\/(events|abort|steer)$/u.exec(url.pathname);
|
|
4975
5102
|
if (request.method === "GET" && url.pathname === "/health") {
|
|
4976
5103
|
const health = {
|
|
4977
5104
|
ok: true,
|
|
@@ -4997,13 +5124,36 @@ data: ${turn.records[next]}
|
|
|
4997
5124
|
return streamTurn(turn, after, request, response);
|
|
4998
5125
|
}
|
|
4999
5126
|
if (request.method === "POST" && turnPath[2] === "abort") {
|
|
5000
|
-
if (!turn.
|
|
5127
|
+
if (!turn.ending && !turn.finishing && !turn.abortRequested) {
|
|
5001
5128
|
turn.abortRequested = true;
|
|
5129
|
+
turn.closed = true;
|
|
5130
|
+
reclaimSteers(turn);
|
|
5002
5131
|
if (turn === current) void currentSessionAbort?.().catch(() => void 0);
|
|
5003
5132
|
endAfterGrace(turn, "aborted");
|
|
5004
5133
|
}
|
|
5005
5134
|
return sendJson(response, 202, { turnId: turn.id, ended: turn.ended });
|
|
5006
5135
|
}
|
|
5136
|
+
if (request.method === "POST" && turnPath[2] === "steer") {
|
|
5137
|
+
const { steerId, message } = parseSteerTurn(await readJsonBody(request));
|
|
5138
|
+
const known = turn.steers.get(steerId);
|
|
5139
|
+
if (!known && (turn !== current || turn.closed)) {
|
|
5140
|
+
return sendJson(response, 409, { error: "The turn is no longer running.", turnId: turn.id });
|
|
5141
|
+
}
|
|
5142
|
+
const steer = known ?? acceptSteer(turn, steerId, message);
|
|
5143
|
+
await steer.settled;
|
|
5144
|
+
if (steer.state === "failed") throw steer.error;
|
|
5145
|
+
if (steer.state === "undelivered" && !turn.closed) {
|
|
5146
|
+
return sendJson(response, 501, { error: "The session does not take steering messages." });
|
|
5147
|
+
}
|
|
5148
|
+
if (steer.late || steer.state === "undelivered") {
|
|
5149
|
+
return sendJson(response, 409, { error: "The turn is no longer running.", turnId: turn.id });
|
|
5150
|
+
}
|
|
5151
|
+
return sendJson(response, known ? 200 : 202, {
|
|
5152
|
+
turnId: turn.id,
|
|
5153
|
+
steerId,
|
|
5154
|
+
...steer.state === "handled" ? { handled: true } : {}
|
|
5155
|
+
});
|
|
5156
|
+
}
|
|
5007
5157
|
}
|
|
5008
5158
|
sendJson(response, 404, { error: "Not found." });
|
|
5009
5159
|
})().catch((error) => {
|
|
@@ -5137,6 +5287,9 @@ var DefinedAgent = class {
|
|
|
5137
5287
|
abort(sandboxId, turnId, signal) {
|
|
5138
5288
|
return this.agent.abort(sandboxId, turnId, signal);
|
|
5139
5289
|
}
|
|
5290
|
+
steer(sandboxId, turnId, steer, signal) {
|
|
5291
|
+
return this.agent.steer(sandboxId, turnId, steer, signal);
|
|
5292
|
+
}
|
|
5140
5293
|
health(sandboxId, signal) {
|
|
5141
5294
|
return this.agent.health(sandboxId, signal);
|
|
5142
5295
|
}
|
|
@@ -5226,6 +5379,8 @@ async function createPiSession(config) {
|
|
|
5226
5379
|
subscribe: (listener) => session.subscribe(listener),
|
|
5227
5380
|
prompt: (text) => session.prompt(text),
|
|
5228
5381
|
abort: () => session.abort(),
|
|
5382
|
+
steer: (text) => session.steer(text),
|
|
5383
|
+
clearQueue: () => session.clearQueue(),
|
|
5229
5384
|
afterTurn: () => braintrust.flush()
|
|
5230
5385
|
};
|
|
5231
5386
|
}
|
package/dist/build.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DefinedAgent } from './index.cjs';
|
|
2
2
|
import 'node:buffer';
|
|
3
3
|
import './sandbox-capabilities-CFjnZ_kB.cjs';
|
|
4
|
-
import './serve-
|
|
4
|
+
import './serve-Du2NCz9_.cjs';
|
|
5
5
|
|
|
6
6
|
interface PushAgentOptions {
|
|
7
7
|
/** The module that defines the agent with `defineAgent()`, relative to `cwd`. */
|
package/dist/build.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DefinedAgent } from './index.js';
|
|
2
2
|
import 'node:buffer';
|
|
3
3
|
import './sandbox-capabilities-CFjnZ_kB.js';
|
|
4
|
-
import './serve-
|
|
4
|
+
import './serve-Du2NCz9_.js';
|
|
5
5
|
|
|
6
6
|
interface PushAgentOptions {
|
|
7
7
|
/** The module that defines the agent with `defineAgent()`, relative to `cwd`. */
|
package/dist/build.js
CHANGED
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
buildAgent,
|
|
4
4
|
loadAgent,
|
|
5
5
|
pushAgent
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-FSBTLBB5.js";
|
|
7
|
+
import "./chunk-BPXEIXPM.js";
|
|
8
8
|
import "./chunk-6P5I7ZCH.js";
|
|
9
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-YFG4EKZM.js";
|
|
10
10
|
import "./chunk-KG6SJM74.js";
|
|
11
11
|
import "./chunk-33IXN6MM.js";
|
|
12
12
|
export {
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
parseTurnHealth,
|
|
23
23
|
parseTurnRecord,
|
|
24
24
|
serve
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-YFG4EKZM.js";
|
|
26
26
|
import {
|
|
27
27
|
IncompleteSseFrameError,
|
|
28
28
|
RUNTIME_ABORT_GRACE_MS,
|
|
@@ -1313,6 +1313,25 @@ var Agent = class {
|
|
|
1313
1313
|
throw new ExecutionError(`Aborting turn ${turnId} failed with ${response.status}.`);
|
|
1314
1314
|
}
|
|
1315
1315
|
}
|
|
1316
|
+
/**
|
|
1317
|
+
* Queues a message for a running turn, which Pi takes after its current tool calls. Resolves to
|
|
1318
|
+
* true once the session has queued it: it is then delivered into the turn, or named in the end
|
|
1319
|
+
* record's `undeliveredSteerIds`. Resolves to false when the turn can no longer take it, or the
|
|
1320
|
+
* runtime no longer has it, so the caller can send the message as a turn of its own. Throws when
|
|
1321
|
+
* queueing failed or the request did; calling again with the same `steerId` never queues it twice.
|
|
1322
|
+
*/
|
|
1323
|
+
async steer(sandboxId, turnId, steer, signal) {
|
|
1324
|
+
const response = await this.request(sandboxId, "POST", `/turns/${encodeURIComponent(turnId)}/steer`, steer, signal);
|
|
1325
|
+
if (response.status === 200 || response.status === 202) {
|
|
1326
|
+
await response.body?.cancel();
|
|
1327
|
+
return true;
|
|
1328
|
+
}
|
|
1329
|
+
if (response.status === 409 || response.status === 404) {
|
|
1330
|
+
await response.body?.cancel();
|
|
1331
|
+
return false;
|
|
1332
|
+
}
|
|
1333
|
+
throw new ExecutionError(`Steering turn ${turnId} failed with ${response.status}: ${await response.text()}`);
|
|
1334
|
+
}
|
|
1316
1335
|
async health(sandboxId, signal) {
|
|
1317
1336
|
const response = await this.request(sandboxId, "GET", "/health", void 0, signal);
|
|
1318
1337
|
if (!response.ok) throw new ExecutionError(`Health check of sandbox ${sandboxId} returned ${response.status}.`);
|
|
@@ -1761,6 +1780,9 @@ var DefinedAgent = class {
|
|
|
1761
1780
|
abort(sandboxId, turnId, signal) {
|
|
1762
1781
|
return this.agent.abort(sandboxId, turnId, signal);
|
|
1763
1782
|
}
|
|
1783
|
+
steer(sandboxId, turnId, steer, signal) {
|
|
1784
|
+
return this.agent.steer(sandboxId, turnId, steer, signal);
|
|
1785
|
+
}
|
|
1764
1786
|
health(sandboxId, signal) {
|
|
1765
1787
|
return this.agent.health(sandboxId, signal);
|
|
1766
1788
|
}
|
|
@@ -1853,6 +1875,8 @@ async function createPiSession(config) {
|
|
|
1853
1875
|
subscribe: (listener) => session.subscribe(listener),
|
|
1854
1876
|
prompt: (text) => session.prompt(text),
|
|
1855
1877
|
abort: () => session.abort(),
|
|
1878
|
+
steer: (text) => session.steer(text),
|
|
1879
|
+
clearQueue: () => session.clearQueue(),
|
|
1856
1880
|
afterTurn: () => braintrust.flush()
|
|
1857
1881
|
};
|
|
1858
1882
|
}
|