ruicode 0.75.1 → 0.83.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -1
- package/dist/binary.d.ts +0 -3
- package/dist/binary.js +0 -4
- package/dist/client.d.ts +0 -16
- package/dist/client.js +0 -39
- package/dist/errors.d.ts +5 -1
- package/dist/errors.js +5 -3
- package/dist/feed.d.ts +8 -8
- package/dist/feed.js +56 -30
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -2
- package/dist/notifications.d.ts +0 -1
- package/dist/notifications.js +0 -2
- package/dist/parts.d.ts +27 -0
- package/dist/parts.js +19 -0
- package/dist/sessions.d.ts +44 -16
- package/dist/sessions.js +48 -38
- package/dist/settings.d.ts +0 -3
- package/dist/settings.js +1 -12
- package/dist/transport.d.ts +1 -9
- package/dist/transport.js +1 -12
- package/dist/wire.d.ts +1131 -760
- package/package.json +4 -4
package/dist/parts.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { WIRE_VERSION } from "./transport.js";
|
|
2
|
+
export async function listParts(link, session, owner) {
|
|
3
|
+
const reply = JSON.parse((await link.exchange("/v1/public-parts", (store) => JSON.stringify({
|
|
4
|
+
version: WIRE_VERSION, kind: "public_parts", store, session, owner,
|
|
5
|
+
}))).toString("utf8"));
|
|
6
|
+
return reply.parts.map((part) => {
|
|
7
|
+
const ordinal = Number(part.ordinal);
|
|
8
|
+
if (part.type === "text")
|
|
9
|
+
return { ordinal, type: "text", bytes: part.bytes, sha256: part.sha256 };
|
|
10
|
+
return { ordinal, type: "image", mime: part.mime, width: Number(part.width), height: Number(part.height), name: part.name, bytes: part.bytes, sha256: part.sha256 };
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export async function readPartBytes(link, session, owner, ordinal, options) {
|
|
14
|
+
if (!Number.isSafeInteger(ordinal) || ordinal < 0)
|
|
15
|
+
throw new RangeError("part ordinal must be a non-negative safe integer");
|
|
16
|
+
return link.exchange("/v1/public-part-content", (store) => JSON.stringify({
|
|
17
|
+
version: WIRE_VERSION, kind: "public_part_content", store, session, owner, part: String(ordinal), start: "0", stream: true,
|
|
18
|
+
}), undefined, options?.prefix === undefined ? { max: 1024 * 1024 * 1024 } : { prefix: options.prefix });
|
|
19
|
+
}
|
package/dist/sessions.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import type { SessionNotifications } from "./notifications.ts";
|
|
2
2
|
import { type ActivitySearchEntry, type SearchActivityOptions, type FeedEntry, type ListActivityOptions } from "./feed.ts";
|
|
3
|
+
import { type ContentValue } from "./parts.ts";
|
|
3
4
|
import { type ReplyLimits } from "./transport.ts";
|
|
4
5
|
import type { components } from "./wire.ts";
|
|
5
|
-
/** What a Session handle needs from the client. */
|
|
6
6
|
export interface Link {
|
|
7
7
|
readonly activity?: SessionNotifications;
|
|
8
8
|
exchange(path: string, build: (store: string) => string, environment?: Buffer, limits?: ReplyLimits): Promise<Buffer>;
|
|
9
9
|
}
|
|
10
10
|
type Schemas = components["schemas"];
|
|
11
11
|
export type ActionStatus = Schemas["ReadActionReply"];
|
|
12
|
+
export type ActionSelection = Extract<Schemas["ActionBackgroundReply"]["answer"], {
|
|
13
|
+
status: "accepted";
|
|
14
|
+
}>["action_selection"];
|
|
12
15
|
/** The Session settings the Host takes today. */
|
|
13
16
|
export interface AgentSpec {
|
|
14
17
|
/** The working directory for Bash. Required with `bash`, fixed for the Session's life. */
|
|
@@ -20,9 +23,9 @@ export interface AgentSpec {
|
|
|
20
23
|
instructions?: string;
|
|
21
24
|
/** JSON output schema object; `null` clears it. */
|
|
22
25
|
outputSchema?: Record<string, unknown> | null;
|
|
23
|
-
/**
|
|
26
|
+
/** Configured allowed tool names, such as `bash` and `web_search`. */
|
|
24
27
|
tools: readonly string[];
|
|
25
|
-
/**
|
|
28
|
+
/** Loaded tool intent within `tools`; each Operation freezes its effective model offer. */
|
|
26
29
|
loadedTools?: readonly string[];
|
|
27
30
|
/** Tokens reserved for model output; null clears the override. */
|
|
28
31
|
outputReservation?: number | null;
|
|
@@ -48,6 +51,8 @@ export type SessionCreate = ((AgentSpec & {
|
|
|
48
51
|
/** The settings `update` may change: everything but the ones fixed at creation. */
|
|
49
52
|
export type SessionUpdate = Partial<Pick<SessionSpec, "model" | "instructions" | "outputSchema" | "tools" | "permissionMode" | "effort" | "compactAt" | "label" | "loadedTools" | "outputReservation">>;
|
|
50
53
|
export interface WriteOptions {
|
|
54
|
+
/** Optional caller-supplied key for replay. Takes precedence over `idempotencyKey`. */
|
|
55
|
+
key?: string;
|
|
51
56
|
/** Required on `create` and `send`, built as `kind:driftId`. Other writes get a fresh UUIDv4 when it is left out (D123). */
|
|
52
57
|
idempotencyKey?: string;
|
|
53
58
|
}
|
|
@@ -69,32 +74,51 @@ export interface SessionArchiveResult {
|
|
|
69
74
|
export type SessionPinResult = Pick<Extract<Schemas["SessionPinReply"]["answer"], {
|
|
70
75
|
status: "accepted";
|
|
71
76
|
}>, "pinned">;
|
|
72
|
-
export interface
|
|
77
|
+
export interface ServedWork {
|
|
78
|
+
attention: Schemas["SessionWork"]["attention"];
|
|
79
|
+
group: Schemas["SessionWork"]["group"];
|
|
80
|
+
canStop: boolean;
|
|
81
|
+
decide: string | null;
|
|
82
|
+
interruptTarget: InterruptTarget | null;
|
|
83
|
+
}
|
|
84
|
+
export interface SessionSummary extends ServedWork {
|
|
73
85
|
id: string;
|
|
74
86
|
label: string | null;
|
|
75
87
|
/** The Session's work state, such as `idle`, `working` or `approval`. */
|
|
76
88
|
state: string;
|
|
77
89
|
archiveState: SessionArchiveState;
|
|
78
90
|
parent: string | null;
|
|
91
|
+
/** Session that started this Session, including a detached agent. */
|
|
92
|
+
creator: Schemas["SessionRow"]["creator"];
|
|
79
93
|
}
|
|
80
94
|
type CurrentReport = Extract<Schemas["InspectSessionReply"], {
|
|
81
95
|
profile: "current";
|
|
82
96
|
work: unknown;
|
|
83
97
|
}>;
|
|
98
|
+
/** The observed Turn and Operation IDs as decimal strings. */
|
|
99
|
+
export interface InterruptTarget {
|
|
100
|
+
turn: string;
|
|
101
|
+
operation: string;
|
|
102
|
+
}
|
|
84
103
|
/** Current Host facts. Decimal counts, times and IDs remain lossless strings. */
|
|
85
|
-
export interface SessionStatus {
|
|
104
|
+
export interface SessionStatus extends ServedWork {
|
|
86
105
|
archiveState: SessionArchiveState;
|
|
87
106
|
/** `working` includes owed attached-tree work, including unpublished child endings. */
|
|
88
107
|
state: CurrentReport["work"]["state"]["kind"];
|
|
89
108
|
since: CurrentReport["work"]["state"]["since"];
|
|
90
109
|
turn: CurrentReport["work"]["turn"];
|
|
91
110
|
operation: CurrentReport["work"]["operation"];
|
|
111
|
+
/** The Host-served target for interrupting the observed model call. */
|
|
112
|
+
interruptTarget: InterruptTarget | null;
|
|
92
113
|
pendingMessages: CurrentReport["pending_messages"];
|
|
93
114
|
parent: CurrentReport["session"]["parent"];
|
|
94
115
|
label: CurrentReport["session"]["label"];
|
|
95
116
|
model: CurrentReport["session"]["model"];
|
|
96
117
|
effort: CurrentReport["session"]["reasoning_effort"];
|
|
118
|
+
/** Configured allowed tool names. */
|
|
97
119
|
tools: CurrentReport["session"]["tools"];
|
|
120
|
+
/** Loaded tool intent; an active Operation keeps its frozen model offer. */
|
|
121
|
+
loadedTools: CurrentReport["session"]["loaded_tools"];
|
|
98
122
|
permissionMode: CurrentReport["session"]["permission_mode"];
|
|
99
123
|
latestOutcome: CurrentReport["work"]["latest_outcome"];
|
|
100
124
|
}
|
|
@@ -103,9 +127,7 @@ export interface ModelSummary {
|
|
|
103
127
|
id: string;
|
|
104
128
|
known: boolean;
|
|
105
129
|
}
|
|
106
|
-
/** One plain wire spec for configure and connect-time presets. */
|
|
107
130
|
export declare function agentSpec(spec: Partial<SessionSpec>): Schemas["Configuration"];
|
|
108
|
-
/** `NAME=VALUE\0` for each entry the Host would keep (D121): a name that is not empty, holds no `=` or NUL and does not start with `RUI_`, and a value without NUL. The rest are left out, because after encoding the Host could not tell where an entry ended. */
|
|
109
131
|
export declare function environmentBytes(env: Record<string, string> | undefined): Buffer;
|
|
110
132
|
export declare class Session {
|
|
111
133
|
#private;
|
|
@@ -124,6 +146,10 @@ export declare class Session {
|
|
|
124
146
|
readContent(entry: Pick<FeedEntry, "position" | "ordinal">): Promise<string>;
|
|
125
147
|
/** The whole text of an entry as UTF-8 bytes, up to the Host's limit of about 1 GiB. */
|
|
126
148
|
readContentBytes(entry: Pick<FeedEntry, "position" | "ordinal">): Promise<Buffer>;
|
|
149
|
+
/** The exact bytes of one part of a parts entry; rejects with `TypeError` for an entry whose content is not parts. */
|
|
150
|
+
readPart(entry: {
|
|
151
|
+
content: ContentValue | null;
|
|
152
|
+
}, ordinal: number): Promise<Buffer>;
|
|
127
153
|
/** A Current report's summary (D12). A separate ending is not reported. */
|
|
128
154
|
status(): Promise<SessionStatus>;
|
|
129
155
|
/** Sends a Message. The receipt is its admission number; the answer arrives in the feed (D8). */
|
|
@@ -142,15 +168,19 @@ export declare class Session {
|
|
|
142
168
|
pin(options?: WriteOptions): Promise<SessionPinResult>;
|
|
143
169
|
/** Removes this Session's pin without changing its work. */
|
|
144
170
|
unpin(options?: WriteOptions): Promise<SessionPinResult>;
|
|
171
|
+
/** Releases the original call with an immutable receipt. Poll `readAction` for the sole final result. */
|
|
172
|
+
backgroundAction(action: string, options?: WriteOptions): Promise<ActionSelection>;
|
|
173
|
+
/** Selects an owned Action for stop. Reuse the key to recover a lost reply. */
|
|
174
|
+
stopAction(action: string, options?: WriteOptions): Promise<string | null>;
|
|
145
175
|
/** Reads an owned Action. Acceptance and attempted state do not assert a running process. */
|
|
146
|
-
readAction(action: string, offset?: string): Promise<ActionStatus>;
|
|
147
|
-
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* call is current, or when the call ended before the cut arrived (D167, D171).
|
|
176
|
+
readAction(action: string, offset?: string, after?: string): Promise<ActionStatus>;
|
|
177
|
+
/** Interrupt an observed target with one keyed request. Reuse the key to replay its answer.
|
|
178
|
+
* `operation_resolved` and `target_mismatch` resolve without effect. With no target, use this handle's
|
|
179
|
+
* last status or feed observation; send nothing when it had no interrupt target.
|
|
180
|
+
* Neither form reads first.
|
|
152
181
|
*/
|
|
153
|
-
interrupt(): Promise<void>;
|
|
182
|
+
interrupt(target: InterruptTarget, options?: WriteOptions): Promise<void>;
|
|
183
|
+
interrupt(options?: WriteOptions): Promise<void>;
|
|
154
184
|
/** Answers an approval. `requestId` is the Action id of the `approval_requested` entry (D15). */
|
|
155
185
|
decide(requestId: string, decision: "allow" | "deny", options?: WriteOptions): Promise<void>;
|
|
156
186
|
}
|
|
@@ -164,8 +194,6 @@ export declare class Sessions {
|
|
|
164
194
|
/** Configured Sessions, newest first; archived Sessions are hidden by default. */
|
|
165
195
|
list(options?: ListSessionsOptions): Promise<SessionSummary[]>;
|
|
166
196
|
}
|
|
167
|
-
/** The models each provider offers (D128). */
|
|
168
197
|
export declare function models(link: Link): Promise<ModelSummary[]>;
|
|
169
|
-
/** Holds every new Turn while paused; running work continues (D199). */
|
|
170
198
|
export declare function setPaused(link: Link, paused: boolean): Promise<void>;
|
|
171
199
|
export {};
|
package/dist/sessions.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
// Sessions: create, list, status, send, update, stop, interrupt and decide, plus the
|
|
2
|
-
// model list and Host pause (D7, D8, D14 to D17, D121, D123, D128, D167,
|
|
3
|
-
// D171). Every call is one request to a Host route that exists today.
|
|
4
1
|
import { randomUUID } from "node:crypto";
|
|
5
2
|
import { RuiRequestError } from "./errors.js";
|
|
6
|
-
import { listActivity, searchActivity, readContent, readContentBytes } from "./feed.js";
|
|
3
|
+
import { servedWork, listActivity, searchActivity, readContent, readContentBytes } from "./feed.js";
|
|
4
|
+
import { readPartBytes } from "./parts.js";
|
|
7
5
|
import { WIRE_VERSION } from "./transport.js";
|
|
8
|
-
/** One plain wire spec for configure and connect-time presets. */
|
|
9
6
|
export function agentSpec(spec) {
|
|
10
7
|
return {
|
|
11
8
|
...(spec.workspace === undefined ? {} : { workspace: spec.workspace }),
|
|
@@ -34,24 +31,23 @@ function configureBody(store, key, session, spec) {
|
|
|
34
31
|
});
|
|
35
32
|
}
|
|
36
33
|
function key(options) {
|
|
37
|
-
return options?.idempotencyKey ?? randomUUID();
|
|
34
|
+
return options?.key ?? options?.idempotencyKey ?? randomUUID();
|
|
38
35
|
}
|
|
39
36
|
function parse(reply) {
|
|
40
37
|
return JSON.parse(reply.toString("utf8"));
|
|
41
38
|
}
|
|
42
|
-
/** Throws the Host's rejection or conflict; returns the accepted answer. */
|
|
43
39
|
function accepted(answer) {
|
|
44
40
|
if (answer.status !== "accepted")
|
|
45
41
|
throw new RuiRequestError(answer.status, answer.code, "message" in answer ? answer.message : undefined);
|
|
46
42
|
return answer;
|
|
47
43
|
}
|
|
48
|
-
/** `NAME=VALUE\0` for each entry the Host would keep (D121): a name that is not empty, holds no `=` or NUL and does not start with `RUI_`, and a value without NUL. The rest are left out, because after encoding the Host could not tell where an entry ended. */
|
|
49
44
|
export function environmentBytes(env) {
|
|
50
45
|
const forwarded = Object.entries(env ?? {}).filter(([name, entry]) => name !== "" && !name.startsWith("RUI_") && !/[=\0]/.test(name) && !entry.includes("\0"));
|
|
51
46
|
return Buffer.from(forwarded.map(([name, entry]) => `${name}=${entry}\0`).join(""), "utf8");
|
|
52
47
|
}
|
|
53
48
|
export class Session {
|
|
54
49
|
#link;
|
|
50
|
+
#interruptTarget = null;
|
|
55
51
|
id;
|
|
56
52
|
constructor(link, id) {
|
|
57
53
|
this.#link = link;
|
|
@@ -64,7 +60,7 @@ export class Session {
|
|
|
64
60
|
* See `ListActivityOptions.follow`; `signal` abort also ends an idle wait.
|
|
65
61
|
*/
|
|
66
62
|
listActivity(options) {
|
|
67
|
-
return listActivity(this.#link, this.id, options);
|
|
63
|
+
return listActivity(this.#link, this.id, options, (target) => { this.#interruptTarget = target; });
|
|
68
64
|
}
|
|
69
65
|
/** Search public feed text newest first, with bounded snippets. */
|
|
70
66
|
searchActivity(query, options) {
|
|
@@ -78,6 +74,12 @@ export class Session {
|
|
|
78
74
|
readContentBytes(entry) {
|
|
79
75
|
return readContentBytes(this.#link, this.id, entry);
|
|
80
76
|
}
|
|
77
|
+
/** The exact bytes of one part of a parts entry; rejects with `TypeError` for an entry whose content is not parts. */
|
|
78
|
+
async readPart(entry, ordinal) {
|
|
79
|
+
if (entry.content?.type !== "parts")
|
|
80
|
+
throw new TypeError("entry content is not parts");
|
|
81
|
+
return readPartBytes(this.#link, this.id, entry.content.owner, ordinal);
|
|
82
|
+
}
|
|
81
83
|
/** A Current report's summary (D12). A separate ending is not reported. */
|
|
82
84
|
async status() {
|
|
83
85
|
const reply = parse(await this.#link.exchange("/v1/inspect-session", (store) => JSON.stringify({
|
|
@@ -88,18 +90,22 @@ export class Session {
|
|
|
88
90
|
})));
|
|
89
91
|
if (reply.session === null)
|
|
90
92
|
throw new RuiRequestError("invocation_error", "session_not_found");
|
|
93
|
+
const served = servedWork(reply.work);
|
|
94
|
+
this.#interruptTarget = served.interruptTarget === null ? null : { ...served.interruptTarget };
|
|
91
95
|
return {
|
|
92
96
|
archiveState: reply.archive_state,
|
|
93
97
|
state: reply.work.state.kind,
|
|
94
98
|
since: reply.work.state.since,
|
|
95
99
|
turn: reply.work.turn,
|
|
96
100
|
operation: reply.work.operation,
|
|
101
|
+
...served,
|
|
97
102
|
pendingMessages: reply.pending_messages,
|
|
98
103
|
parent: reply.session.parent,
|
|
99
104
|
label: reply.session.label,
|
|
100
105
|
model: reply.session.model,
|
|
101
106
|
effort: reply.session.reasoning_effort,
|
|
102
107
|
tools: reply.session.tools,
|
|
108
|
+
loadedTools: reply.session.loaded_tools,
|
|
103
109
|
permissionMode: reply.session.permission_mode,
|
|
104
110
|
latestOutcome: reply.work.latest_outcome,
|
|
105
111
|
};
|
|
@@ -188,38 +194,49 @@ export class Session {
|
|
|
188
194
|
this.#link.activity?.notify(this.id);
|
|
189
195
|
return { pinned: answer.pinned };
|
|
190
196
|
}
|
|
197
|
+
/** Releases the original call with an immutable receipt. Poll `readAction` for the sole final result. */
|
|
198
|
+
async backgroundAction(action, options) {
|
|
199
|
+
const idempotencyKey = key(options);
|
|
200
|
+
const reply = parse(await this.#link.exchange("/v1/control/action-background", (store) => JSON.stringify({
|
|
201
|
+
version: WIRE_VERSION, kind: "action_background", store,
|
|
202
|
+
key: idempotencyKey, session: this.id, action,
|
|
203
|
+
})));
|
|
204
|
+
const answer = accepted(reply.answer);
|
|
205
|
+
this.#link.activity?.notify(this.id);
|
|
206
|
+
return answer.action_selection;
|
|
207
|
+
}
|
|
208
|
+
/** Selects an owned Action for stop. Reuse the key to recover a lost reply. */
|
|
209
|
+
async stopAction(action, options) {
|
|
210
|
+
const idempotencyKey = key(options);
|
|
211
|
+
const reply = parse(await this.#link.exchange("/v1/control/action-stop", (store) => JSON.stringify({
|
|
212
|
+
version: WIRE_VERSION, kind: "action_stop", store,
|
|
213
|
+
key: idempotencyKey, session: this.id, action,
|
|
214
|
+
})));
|
|
215
|
+
const answer = accepted(reply.answer);
|
|
216
|
+
this.#link.activity?.notify(this.id);
|
|
217
|
+
return answer.resolution_position;
|
|
218
|
+
}
|
|
191
219
|
/** Reads an owned Action. Acceptance and attempted state do not assert a running process. */
|
|
192
|
-
async readAction(action, offset = "0") {
|
|
220
|
+
async readAction(action, offset = "0", after = "0") {
|
|
193
221
|
return parse(await this.#link.exchange("/v1/read-action", (store) => JSON.stringify({
|
|
194
|
-
version: WIRE_VERSION, kind: "read_action", store, session: this.id, action, offset,
|
|
222
|
+
version: WIRE_VERSION, kind: "read_action", store, session: this.id, action, offset, after,
|
|
195
223
|
})));
|
|
196
224
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
* call is current, or when the call ended before the cut arrived (D167, D171).
|
|
202
|
-
*/
|
|
203
|
-
async interrupt() {
|
|
204
|
-
const status = await this.status();
|
|
205
|
-
const { turn, operation } = status;
|
|
206
|
-
if (turn === null || operation === null || !modelCallCurrent(status.state)) {
|
|
207
|
-
this.#link.activity?.notify(this.id);
|
|
225
|
+
async interrupt(targetOrOptions, options) {
|
|
226
|
+
const explicit = targetOrOptions !== undefined && "turn" in targetOrOptions;
|
|
227
|
+
const target = explicit ? targetOrOptions : this.#interruptTarget;
|
|
228
|
+
if (target === null)
|
|
208
229
|
return;
|
|
209
|
-
}
|
|
210
|
-
const idempotencyKey =
|
|
230
|
+
const { turn, operation } = target;
|
|
231
|
+
const idempotencyKey = key(explicit ? options : targetOrOptions);
|
|
211
232
|
const body = (store) => JSON.stringify({
|
|
212
|
-
version: WIRE_VERSION,
|
|
213
|
-
|
|
214
|
-
store,
|
|
215
|
-
key: idempotencyKey,
|
|
216
|
-
target: { session: this.id, turn, operation },
|
|
233
|
+
version: WIRE_VERSION, kind: "model_interruption", store,
|
|
234
|
+
key: idempotencyKey, target: { session: this.id, turn, operation },
|
|
217
235
|
});
|
|
218
236
|
try {
|
|
219
237
|
accepted(parse(await this.#link.exchange("/v1/control/model-interruption", body)).answer);
|
|
220
238
|
}
|
|
221
239
|
catch (error) {
|
|
222
|
-
// The call ended before the cut reached it: nothing is left to cut.
|
|
223
240
|
const gone = error instanceof RuiRequestError && (error.code === "operation_resolved" || error.code === "target_mismatch");
|
|
224
241
|
if (!gone)
|
|
225
242
|
throw error;
|
|
@@ -243,10 +260,6 @@ export class Session {
|
|
|
243
260
|
this.#link.activity?.notify(this.id);
|
|
244
261
|
}
|
|
245
262
|
}
|
|
246
|
-
/** Work states in which a model call is the current thing. */
|
|
247
|
-
function modelCallCurrent(kind) {
|
|
248
|
-
return kind === "working" || kind === "retrying" || kind === "pending";
|
|
249
|
-
}
|
|
250
263
|
export class Sessions {
|
|
251
264
|
#link;
|
|
252
265
|
constructor(link) {
|
|
@@ -275,7 +288,7 @@ export class Sessions {
|
|
|
275
288
|
ceiling: wireCeiling,
|
|
276
289
|
})));
|
|
277
290
|
for (const row of page.sessions) {
|
|
278
|
-
summaries.push({ id: row.reference, label: row.label, state: row.work.state.kind, archiveState: row.archive_state, parent: row.parent });
|
|
291
|
+
summaries.push({ id: row.reference, label: row.label, state: row.work.state.kind, ...servedWork(row.work), archiveState: row.archive_state, parent: row.parent, creator: row.creator });
|
|
279
292
|
}
|
|
280
293
|
if (page.next === null || !("after" in page.next))
|
|
281
294
|
return summaries.reverse();
|
|
@@ -284,19 +297,16 @@ export class Sessions {
|
|
|
284
297
|
}
|
|
285
298
|
}
|
|
286
299
|
}
|
|
287
|
-
/** The models each provider offers (D128). */
|
|
288
300
|
export async function models(link) {
|
|
289
301
|
const reply = parse(await link.exchange("/v1/model-list", (store) => JSON.stringify({
|
|
290
302
|
version: WIRE_VERSION,
|
|
291
303
|
kind: "model_list",
|
|
292
304
|
store,
|
|
293
305
|
}), undefined, {
|
|
294
|
-
// A live provider list can take longer than the default response wait.
|
|
295
306
|
responseMs: 30_000,
|
|
296
307
|
}));
|
|
297
308
|
return reply.providers.flatMap((entry) => entry.models.map((model) => ({ provider: entry.provider, id: model.id, known: model.known })));
|
|
298
309
|
}
|
|
299
|
-
/** Holds every new Turn while paused; running work continues (D199). */
|
|
300
310
|
export async function setPaused(link, paused) {
|
|
301
311
|
await link.exchange("/v1/control/host-pause", (store) => JSON.stringify({
|
|
302
312
|
version: WIRE_VERSION,
|
package/dist/settings.d.ts
CHANGED
|
@@ -12,14 +12,11 @@ export type HostSettings = Omit<Input<components["schemas"]["HostSettings"]>, "p
|
|
|
12
12
|
/** Uses the same friendly Session spec and writer as sessions.create. */
|
|
13
13
|
presets?: Record<string, AgentSpec>;
|
|
14
14
|
};
|
|
15
|
-
/** Normalize only generated schema leaves. Arbitrary preset JSON is not interpreted. */
|
|
16
15
|
export declare function pipeSettings(value: HostSettings, environmentSource?: (name: unknown, path: string) => void): components["schemas"]["HostSettings"];
|
|
17
|
-
/** Launch projection is owned alongside the document, not by child supervision. */
|
|
18
16
|
export interface PreparedSettings {
|
|
19
17
|
document: components["schemas"]["HostSettings"];
|
|
20
18
|
interfaceDir: NonNullable<NonNullable<components["schemas"]["HostSettings"]["interface"]>["dir"]>;
|
|
21
19
|
detached: boolean;
|
|
22
20
|
}
|
|
23
|
-
/** Preserve client defaults and friendly preset encoding after canonical normalization. */
|
|
24
21
|
export declare function prepareSettings(settings: HostSettings, runtimeDir: string, env: NodeJS.ProcessEnv): PreparedSettings;
|
|
25
22
|
export {};
|
package/dist/settings.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
// Friendly inputs are mechanically derived from the generated document type.
|
|
2
|
-
// Runtime codecs come from annotations on that same schema, never a field list.
|
|
3
1
|
import { SETTINGS_KINDS } from "./settings-kinds.js";
|
|
4
2
|
import { agentSpec } from "./sessions.js";
|
|
5
3
|
import { RuiStartError } from "./errors.js";
|
|
6
|
-
/** Normalize only generated schema leaves. Arbitrary preset JSON is not interpreted. */
|
|
7
4
|
export function pipeSettings(value, environmentSource) {
|
|
8
5
|
function visit(value, codec, path) {
|
|
9
6
|
if (codec?.kind === "secret" && typeof value === "string")
|
|
@@ -12,7 +9,6 @@ export function pipeSettings(value, environmentSource) {
|
|
|
12
9
|
if (value instanceof Uint8Array)
|
|
13
10
|
return { hex: Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString("hex") };
|
|
14
11
|
if (value !== null && typeof value === "object") {
|
|
15
|
-
// Project only this byte leaf once, preserving toJSON(key) and omitted-field semantics.
|
|
16
12
|
const key = path.slice(path.lastIndexOf(".") + 1);
|
|
17
13
|
const projected = JSON.parse(JSON.stringify({ [key]: value }));
|
|
18
14
|
return Object.hasOwn(projected, key) ? projected[key] : undefined;
|
|
@@ -22,7 +18,6 @@ export function pipeSettings(value, environmentSource) {
|
|
|
22
18
|
if (!codec?.fields || value === null || typeof value !== "object")
|
|
23
19
|
return value;
|
|
24
20
|
if (Array.isArray(value)) {
|
|
25
|
-
// Invalid record arrays retain their shape, without species, iterators or serializers.
|
|
26
21
|
const elements = new Array(value.length);
|
|
27
22
|
Object.setPrototypeOf(elements, null);
|
|
28
23
|
for (let index = 0; index < value.length; index++) {
|
|
@@ -31,7 +26,6 @@ export function pipeSettings(value, environmentSource) {
|
|
|
31
26
|
}
|
|
32
27
|
return elements;
|
|
33
28
|
}
|
|
34
|
-
// Metadata-owned records are own data; callable fields cannot rewrite later decisions.
|
|
35
29
|
const normalized = Object.fromEntries(Object.entries(value).filter(([, field]) => typeof field !== "function").map(([name, field]) => [name, visit(field, codec.fields && Object.hasOwn(codec.fields, name) ? codec.fields[name] : codec.fields?.["*"], path ? `${path}.${name}` : name)]));
|
|
36
30
|
if (codec.kind === "secret" && Object.hasOwn(normalized, "env"))
|
|
37
31
|
environmentSource?.(normalized.env, `${path}.env`);
|
|
@@ -39,7 +33,6 @@ export function pipeSettings(value, environmentSource) {
|
|
|
39
33
|
}
|
|
40
34
|
return visit(value, SETTINGS_KINDS, "");
|
|
41
35
|
}
|
|
42
|
-
/** Preserve client defaults and friendly preset encoding after canonical normalization. */
|
|
43
36
|
export function prepareSettings(settings, runtimeDir, env) {
|
|
44
37
|
let document = pipeSettings(settings, (source, path) => {
|
|
45
38
|
const name = environmentName(source, path);
|
|
@@ -53,27 +46,23 @@ export function prepareSettings(settings, runtimeDir, env) {
|
|
|
53
46
|
let detached = false;
|
|
54
47
|
if (document !== null && typeof document === "object" && !Array.isArray(document)) {
|
|
55
48
|
if (Object.hasOwn(document, "presets") && document.presets !== undefined) {
|
|
56
|
-
// Presets retain their existing friendly spec writer after settings normalization.
|
|
57
49
|
const presets = document.presets;
|
|
58
50
|
document = { ...document, presets: Object.fromEntries(Object.entries(presets).map(([name, spec]) => [name, agentSpec(spec)])) };
|
|
59
51
|
}
|
|
60
52
|
const supplied = Object.hasOwn(document, "interface") && document.interface !== undefined ? document.interface : {};
|
|
61
53
|
if (supplied !== null && typeof supplied === "object" && !Array.isArray(supplied)) {
|
|
62
|
-
// Choose client defaults once, from canonical own data; invalid groups reach the Host unchanged.
|
|
63
54
|
const selected = {
|
|
64
55
|
...supplied,
|
|
65
56
|
...(!Object.hasOwn(supplied, "dir") || supplied.dir == null ? { dir: runtimeDir } : {}),
|
|
66
57
|
...(!Object.hasOwn(supplied, "lifetime") || supplied.lifetime === undefined ? { lifetime: "stdin" } : {}),
|
|
67
58
|
};
|
|
68
59
|
document = { ...document, interface: selected };
|
|
69
|
-
interfaceDir = selected.dir;
|
|
60
|
+
interfaceDir = selected.dir;
|
|
70
61
|
detached = selected.lifetime !== "stdin";
|
|
71
62
|
}
|
|
72
63
|
}
|
|
73
64
|
return { document, interfaceDir, detached };
|
|
74
65
|
}
|
|
75
|
-
/** Consume the byte codec's canonical JSON value before allowing any Node environment lookup.
|
|
76
|
-
* Malformed values stay in the document for Host refusal; Host bounds remain its own. */
|
|
77
66
|
function environmentName(source, path) {
|
|
78
67
|
let name;
|
|
79
68
|
if (typeof source === "string")
|
package/dist/transport.d.ts
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const WIRE_VERSION = "19";
|
|
1
|
+
export declare const WIRE_VERSION = "21";
|
|
3
2
|
export interface Post {
|
|
4
3
|
socketPath: string;
|
|
5
4
|
path: string;
|
|
6
|
-
/** The serialized request JSON. */
|
|
7
5
|
body: string;
|
|
8
|
-
/** The Host instance from host-info; a different instance refuses the call. */
|
|
9
6
|
instance?: string;
|
|
10
|
-
/** Client environment bytes sent ahead of the JSON (`/v1/message`). */
|
|
11
7
|
environment?: Buffer;
|
|
12
|
-
/** `prefix`: resolve with the first this-many bytes of a successful reply and drop the rest. `max`: the most a reply may hold; the default fits the Host's control replies. */
|
|
13
8
|
limits?: ReplyLimits;
|
|
14
9
|
}
|
|
15
10
|
export interface ReplyLimits {
|
|
16
11
|
prefix?: number;
|
|
17
12
|
max?: number;
|
|
18
|
-
/** The longest silence before the first reply byte, once the request is sent. Default 5 s. */
|
|
19
13
|
responseMs?: number;
|
|
20
|
-
/** The longest a transfer may make no byte of progress. Default 60 s. */
|
|
21
14
|
idleMs?: number;
|
|
22
15
|
}
|
|
23
|
-
/** A failure to reach the Host at all, as opposed to a refusal from it. */
|
|
24
16
|
export declare class ConnectionError extends Error {
|
|
25
17
|
readonly name = "ConnectionError";
|
|
26
18
|
}
|
package/dist/transport.js
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
// One POST over the Host's Unix socket. The Host speaks HTTP/1.1, answers
|
|
2
|
-
// once and closes the connection. Nothing here is exported from the package
|
|
3
|
-
// (D19).
|
|
4
1
|
import { request } from "node:http";
|
|
5
2
|
import { RuiRequestError } from "./errors.js";
|
|
6
|
-
|
|
7
|
-
export const WIRE_VERSION = "19";
|
|
8
|
-
/** The largest reply body read. The Host's own replies stay far below it. */
|
|
3
|
+
export const WIRE_VERSION = "21";
|
|
9
4
|
const MAX_REPLY_BYTES = 64 * 1024 * 1024;
|
|
10
|
-
/** After the request is sent, the longest the Host may stay silent before its first reply byte. */
|
|
11
5
|
const RESPONSE_WAIT_MS = 5_000;
|
|
12
|
-
/** The longest a transfer, in either direction, may make no byte of progress. */
|
|
13
6
|
const TRANSFER_IDLE_MS = 60_000;
|
|
14
|
-
/** A failure to reach the Host at all, as opposed to a refusal from it. */
|
|
15
7
|
export class ConnectionError extends Error {
|
|
16
8
|
name = "ConnectionError";
|
|
17
9
|
}
|
|
@@ -32,7 +24,6 @@ export function post(call) {
|
|
|
32
24
|
const idle = call.limits?.idleMs ?? TRANSFER_IDLE_MS;
|
|
33
25
|
outgoing.setTimeout(idle);
|
|
34
26
|
outgoing.on("timeout", () => outgoing.destroy(new Error("the Host made no progress in time")));
|
|
35
|
-
// Silence after the whole request went out gets the short budget; any byte of progress renews the long one.
|
|
36
27
|
outgoing.on("finish", () => outgoing.setTimeout(call.limits?.responseMs ?? RESPONSE_WAIT_MS));
|
|
37
28
|
outgoing.on("error", (error) => reject(new ConnectionError(error.message, { cause: error })));
|
|
38
29
|
outgoing.on("response", (incoming) => {
|
|
@@ -74,12 +65,10 @@ function refusal(status, reply) {
|
|
|
74
65
|
parsed = JSON.parse(reply.toString("utf8"));
|
|
75
66
|
}
|
|
76
67
|
catch {
|
|
77
|
-
// Fall through: a reply that is not an ErrorReply is reported by status.
|
|
78
68
|
}
|
|
79
69
|
if (parsed && typeof parsed.code === "string" && typeof parsed.type === "string") {
|
|
80
70
|
return new RuiRequestError(parsed.type, parsed.code);
|
|
81
71
|
}
|
|
82
|
-
// A reused key with different input answers 409 with the command's own envelope.
|
|
83
72
|
if (parsed?.answer && typeof parsed.answer.code === "string" && typeof parsed.answer.status === "string") {
|
|
84
73
|
return new RuiRequestError(parsed.answer.status, parsed.answer.code);
|
|
85
74
|
}
|