ruicode 0.82.0 → 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 +24 -2
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +5 -0
- package/dist/feed.d.ts +8 -3
- package/dist/feed.js +55 -7
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/parts.d.ts +27 -0
- package/dist/parts.js +19 -0
- package/dist/sessions.d.ts +30 -9
- package/dist/sessions.js +25 -27
- package/dist/transport.d.ts +1 -1
- package/dist/transport.js +1 -1
- package/dist/wire.d.ts +688 -757
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -155,6 +155,21 @@ Only top-level field names become camelCase (for example `callOrdinal`); nested
|
|
|
155
155
|
Text-bearing kinds add `text`, or `truncated: true` when the text exceeds 16 KiB; `contentBytes` gives its byte length.
|
|
156
156
|
Use `session.readContent(entry)` or `readContentBytes(entry)` for the whole text.
|
|
157
157
|
|
|
158
|
+
A parts value has `entry.parts`, the certified ordered list, and no `entry.text`. Any entry that carries content can carry parts. Text parts have `text` inline, in order, while the entry's inline total stays within 16 KiB; a part past that has `truncated: true`. Image parts include their MIME type as the Host reports it, dimensions and optional name. `contentBytes` is the manifest length, not the sum of the parts. Read any part's exact bytes with `session.readPart(entry, part.ordinal)`. `readContent` and `readContentBytes` reject with `ContentIsPartsError` for a parts value, as the Host refuses it on its text route.
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
for await (const entry of session.listActivity()) {
|
|
162
|
+
if ("parts" in entry && entry.parts) {
|
|
163
|
+
for (const part of entry.parts) {
|
|
164
|
+
if (part.type === "text") console.log(part.text ?? `(use readPart for ${part.bytes} bytes)`);
|
|
165
|
+
else await writeFile(`image-${part.ordinal}.${part.mime === "image/png" ? "png" : "jpg"}`, await session.readPart(entry, part.ordinal));
|
|
166
|
+
}
|
|
167
|
+
} else if ("text" in entry) console.log(entry.text);
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
The example uses `writeFile` from `node:fs/promises`.
|
|
172
|
+
|
|
158
173
|
Following polls with backoff from 250 ms to 2 s only while the Session is busy.
|
|
159
174
|
An empty page in `idle`, `finished`, `failed`, or `stopped` state with nothing queued puts the iterator to sleep **without a timer**.
|
|
160
175
|
It wakes after a successful `send`, `update`, `decide`, `interrupt`, `stop`, `archive`, or `unarchive` through any handle for that Session ID on the same Rui instance, then starts polling again at 250 ms.
|
|
@@ -203,7 +218,14 @@ await session.update({ model: "gpt-5.5" });
|
|
|
203
218
|
`await session.status()` reads the Current report: work `state` and `since`, `turn`, `operation`, `pendingMessages`, `parent`, `label`, `model`, `effort`, `tools`, `permissionMode`, `latestOutcome` and `archiveState`.
|
|
204
219
|
Counts, times and Turn/Operation IDs stay decimal strings; absent targets, parents and outcomes are `null`.
|
|
205
220
|
A separate ending is not in the report, so status does not invent one.
|
|
206
|
-
`
|
|
221
|
+
`interruptTarget` is the Host-served target from that snapshot. Pass it explicitly with a key to interrupt that observed call in one request, and reuse the same key to recover its answer:
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
const { interruptTarget } = await session.status();
|
|
225
|
+
if (interruptTarget) await session.interrupt(interruptTarget, { key: "interrupt:1" });
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
`key` is also accepted by other writes using `WriteOptions`; it takes precedence if `idempotencyKey` is also supplied. `operation_resolved` and `target_mismatch` resolve without effect; other rejections throw. The convenience `interrupt({ key: "interrupt:1" })` uses the last target observed by this handle through `status()` or a feed page. It sends nothing if the handle has observed no target, or its last observation had a null target. Neither form reads first.
|
|
207
229
|
|
|
208
230
|
Presets are complete agent specs passed at connect and kept only in Host memory.
|
|
209
231
|
Creation copies the preset, with every supplied field (including `null`) overriding it.
|
|
@@ -246,7 +268,7 @@ Both methods notify local activity followers without submitting a Message or sta
|
|
|
246
268
|
|
|
247
269
|
`session.stopAction(action, { idempotencyKey })` selects one Action in that Session for stop.
|
|
248
270
|
It returns the existing Resolution position when the Action has already ended, or `null` when stop selection precedes completion.
|
|
249
|
-
Use `session.readAction(action)` to read completion and
|
|
271
|
+
Use `session.readAction(action)` to read completion, saved output, and published values. To continue a value page, pass its `values.next` as the third argument: `session.readAction(action, "0", values.next)`. The second argument is the independent final-output byte offset.
|
|
250
272
|
Retain the key and exact inputs before sending. Retry them unchanged to recover a lost reply.
|
|
251
273
|
A stop selection suppresses that Action's final Session input and preserves its sole Resolution.
|
|
252
274
|
Other Actions continue.
|
package/dist/errors.d.ts
CHANGED
|
@@ -38,4 +38,9 @@ export declare class RuiUnavailableError extends Error {
|
|
|
38
38
|
cause?: unknown;
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
|
+
/** The entry contains parts; read an individual part instead. */
|
|
42
|
+
export declare class ContentIsPartsError extends Error {
|
|
43
|
+
readonly name = "ContentIsPartsError";
|
|
44
|
+
constructor();
|
|
45
|
+
}
|
|
41
46
|
export {};
|
package/dist/errors.js
CHANGED
|
@@ -26,3 +26,8 @@ export class RuiUnavailableError extends Error {
|
|
|
26
26
|
super(message, options);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
/** The entry contains parts; read an individual part instead. */
|
|
30
|
+
export class ContentIsPartsError extends Error {
|
|
31
|
+
name = "ContentIsPartsError";
|
|
32
|
+
constructor() { super("Content contains parts; use session.readPart(entry, ordinal)"); }
|
|
33
|
+
}
|
package/dist/feed.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { Link } from "./sessions.ts";
|
|
1
|
+
import type { InterruptTarget, Link, ServedWork } from "./sessions.ts";
|
|
2
|
+
import { type Part } from "./parts.ts";
|
|
2
3
|
import type { components } from "./wire.ts";
|
|
3
4
|
type Schemas = components["schemas"];
|
|
5
|
+
export declare function servedWork(work: Pick<Schemas["SessionWork"], "attention" | "group" | "actions">): ServedWork;
|
|
4
6
|
type Row = Schemas["ActivityItem"];
|
|
5
7
|
/** Every kind the Host's feed has, in its own order. */
|
|
6
8
|
export declare const FEED_KINDS: readonly ["admission", "user", "assistant", "call", "tool_result", "hosted_call", "turn_ended", "stop", "sent", "send_failed", "received", "approval_requested", "session_changed", "compacted", "model_call"];
|
|
@@ -32,8 +34,10 @@ type EntryText = {
|
|
|
32
34
|
text?: string;
|
|
33
35
|
/** Text exceeds 16 KiB: use `session.readContent(entry)`. */
|
|
34
36
|
truncated?: boolean;
|
|
35
|
-
/** The
|
|
37
|
+
/** The value's length in bytes when this kind carries one: the text's length, or the manifest's for a parts value. */
|
|
36
38
|
contentBytes?: string;
|
|
39
|
+
/** Certified parts, in order, when the content is a parts value. */
|
|
40
|
+
parts?: Part[];
|
|
37
41
|
};
|
|
38
42
|
type EntryFromRow<R extends Row> = R extends Row ? {
|
|
39
43
|
[Kind in keyof R["value"]]: Omit<R, "value"> & {
|
|
@@ -52,6 +56,7 @@ export declare function decodeCursor(cursor: string): {
|
|
|
52
56
|
position: string;
|
|
53
57
|
ordinal: string;
|
|
54
58
|
};
|
|
59
|
+
/** The Host owns the rule: its text route refuses a parts value as `ContentIsParts`. */
|
|
55
60
|
export declare function readContentBytes(link: Link, session: string, entry: {
|
|
56
61
|
position: string;
|
|
57
62
|
ordinal: string;
|
|
@@ -60,7 +65,7 @@ export declare function readContent(link: Link, session: string, entry: {
|
|
|
60
65
|
position: string;
|
|
61
66
|
ordinal: string;
|
|
62
67
|
}): Promise<string>;
|
|
63
|
-
export declare function listActivity(link: Link, session: string, options?: ListActivityOptions): AsyncGenerator<FeedEntry, void, undefined>;
|
|
68
|
+
export declare function listActivity(link: Link, session: string, options?: ListActivityOptions, observe?: (target: InterruptTarget | null) => void): AsyncGenerator<FeedEntry, void, undefined>;
|
|
64
69
|
export interface SearchActivityOptions {
|
|
65
70
|
/** Resume before this search entry's cursor. */
|
|
66
71
|
before?: string;
|
package/dist/feed.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
+
import { ContentIsPartsError, RuiRequestError } from "./errors.js";
|
|
2
|
+
import { listParts, readPartBytes } from "./parts.js";
|
|
1
3
|
import { WIRE_VERSION } from "./transport.js";
|
|
4
|
+
export function servedWork(work) {
|
|
5
|
+
if (!work || !("attention" in work) || !("group" in work) || !work.actions ||
|
|
6
|
+
typeof work.actions.stop !== "boolean" || !("interrupt" in work.actions) || !("decide" in work.actions) ||
|
|
7
|
+
!["needs_you", "working", "queued", "done"].includes(work.group) ||
|
|
8
|
+
(work.attention !== null && (typeof work.attention !== "object" ||
|
|
9
|
+
!["approval", "failed", "finished"].includes(work.attention.kind) ||
|
|
10
|
+
typeof work.attention.turn !== "string" || typeof work.attention.step !== "string")) ||
|
|
11
|
+
(work.actions.decide !== null && typeof work.actions.decide !== "string") ||
|
|
12
|
+
(work.actions.interrupt !== null && (typeof work.actions.interrupt !== "object" ||
|
|
13
|
+
typeof work.actions.interrupt.turn !== "string" || typeof work.actions.interrupt.operation !== "string"))) {
|
|
14
|
+
throw new Error("Invalid work reply: missing served facts");
|
|
15
|
+
}
|
|
16
|
+
return { attention: work.attention, group: work.group, canStop: work.actions.stop,
|
|
17
|
+
decide: work.actions.decide, interruptTarget: work.actions.interrupt };
|
|
18
|
+
}
|
|
2
19
|
/** Every kind the Host's feed has, in its own order. */
|
|
3
20
|
export const FEED_KINDS = [
|
|
4
21
|
"admission",
|
|
@@ -42,12 +59,15 @@ function camel(name) {
|
|
|
42
59
|
function camelCase(row) {
|
|
43
60
|
return Object.fromEntries(Object.entries(row).map(([name, value]) => [camel(name), value]));
|
|
44
61
|
}
|
|
45
|
-
function
|
|
46
|
-
|
|
62
|
+
function contentOf(payload) {
|
|
63
|
+
const value = payload.content;
|
|
64
|
+
if (typeof value !== "object" || value === null || !("type" in value))
|
|
65
|
+
return undefined;
|
|
66
|
+
return value.type === "text" || value.type === "parts" ? value : undefined;
|
|
47
67
|
}
|
|
48
68
|
function entryOf(row) {
|
|
49
69
|
const [kind, payload] = Object.entries(row.value)[0];
|
|
50
|
-
const reference =
|
|
70
|
+
const reference = contentOf(payload);
|
|
51
71
|
const wanted = kind !== "turn_ended" || ENDINGS_WITH_TEXT.has(String(payload.ending));
|
|
52
72
|
const entry = {
|
|
53
73
|
kind,
|
|
@@ -86,8 +106,16 @@ function contentBody(store, session, entry) {
|
|
|
86
106
|
});
|
|
87
107
|
}
|
|
88
108
|
const MAX_CONTENT_BYTES = 1024 * 1024 * 1024;
|
|
89
|
-
|
|
90
|
-
|
|
109
|
+
/** The Host owns the rule: its text route refuses a parts value as `ContentIsParts`. */
|
|
110
|
+
export async function readContentBytes(link, session, entry) {
|
|
111
|
+
try {
|
|
112
|
+
return await link.exchange("/v1/activity-content", (store) => contentBody(store, session, entry), undefined, { max: MAX_CONTENT_BYTES });
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (error instanceof RuiRequestError && error.code === "ContentIsParts")
|
|
116
|
+
throw new ContentIsPartsError();
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
91
119
|
}
|
|
92
120
|
export async function readContent(link, session, entry) {
|
|
93
121
|
return (await readContentBytes(link, session, entry)).toString("utf8");
|
|
@@ -105,7 +133,7 @@ function pause(ms, signal) {
|
|
|
105
133
|
signal?.addEventListener("abort", done, { once: true });
|
|
106
134
|
});
|
|
107
135
|
}
|
|
108
|
-
export async function* listActivity(link, session, options = {}) {
|
|
136
|
+
export async function* listActivity(link, session, options = {}, observe) {
|
|
109
137
|
const kinds = options.kinds === undefined ? FEED_KINDS : FEED_KINDS.filter((kind) => options.kinds?.includes(kind));
|
|
110
138
|
let position = "0";
|
|
111
139
|
let ordinal = null;
|
|
@@ -129,12 +157,32 @@ export async function* listActivity(link, session, options = {}) {
|
|
|
129
157
|
since = page.since;
|
|
130
158
|
}
|
|
131
159
|
else {
|
|
160
|
+
const served = servedWork(page.work);
|
|
161
|
+
observe?.(served.interruptTarget);
|
|
132
162
|
for (const row of page.items) {
|
|
133
163
|
if (signal?.aborted)
|
|
134
164
|
return;
|
|
135
165
|
const { entry, reference } = entryOf(row);
|
|
136
166
|
if (reference && "content" in entry) {
|
|
137
|
-
if (
|
|
167
|
+
if (reference.type === "parts") {
|
|
168
|
+
entry.parts = await listParts(link, session, reference.owner);
|
|
169
|
+
// One entry inlines at most INLINE_TEXT_BYTES across its Text parts, as a text entry does.
|
|
170
|
+
let inline = INLINE_TEXT_BYTES;
|
|
171
|
+
for (const part of entry.parts) {
|
|
172
|
+
if (part.type !== "text")
|
|
173
|
+
continue;
|
|
174
|
+
if (signal?.aborted)
|
|
175
|
+
return;
|
|
176
|
+
const bytes = Number(part.bytes);
|
|
177
|
+
if (bytes > inline) {
|
|
178
|
+
part.truncated = true;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
inline -= bytes;
|
|
182
|
+
part.text = (await readPartBytes(link, session, reference.owner, part.ordinal, { prefix: INLINE_TEXT_BYTES })).toString("utf8");
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else if (Number(reference.bytes) > INLINE_TEXT_BYTES) {
|
|
138
186
|
entry.truncated = true;
|
|
139
187
|
}
|
|
140
188
|
else {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { Rui, type HostSettings, type ClientOptions, type ExitEvent } from "./client.ts";
|
|
2
|
-
export { RuiRequestError, RuiStartError, RuiUnavailableError } from "./errors.ts";
|
|
3
|
-
export { Session, Sessions, type AgentSpec, type ActionStatus, type ActionSelection, type ListSessionsOptions, type SessionArchiveState, type SessionArchiveResult, type SessionPinResult, type SessionCreate, type ModelSummary, type SendOptions, type SessionSpec, type SessionSummary, type SessionStatus, type SessionUpdate, type WriteOptions, } from "./sessions.ts";
|
|
2
|
+
export { ContentIsPartsError, RuiRequestError, RuiStartError, RuiUnavailableError } from "./errors.ts";
|
|
3
|
+
export { Session, Sessions, type AgentSpec, type ActionStatus, type ActionSelection, type ListSessionsOptions, type SessionArchiveState, type SessionArchiveResult, type SessionPinResult, type SessionCreate, type ModelSummary, type SendOptions, type SessionSpec, type SessionSummary, type SessionStatus, type InterruptTarget, type SessionUpdate, type WriteOptions, } from "./sessions.ts";
|
|
4
4
|
export { FEED_KINDS, INLINE_TEXT_BYTES, type FeedEntry, type FeedKind, type ListActivityOptions, type SearchActivityOptions, type ActivitySearchEntry } from "./feed.ts";
|
|
5
|
+
export type { ContentValue, PartOwner, Part } from "./parts.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Rui } from "./client.js";
|
|
2
|
-
export { RuiRequestError, RuiStartError, RuiUnavailableError } from "./errors.js";
|
|
2
|
+
export { ContentIsPartsError, RuiRequestError, RuiStartError, RuiUnavailableError } from "./errors.js";
|
|
3
3
|
export { Session, Sessions, } from "./sessions.js";
|
|
4
4
|
export { FEED_KINDS, INLINE_TEXT_BYTES } from "./feed.js";
|
package/dist/parts.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Link } from "./sessions.ts";
|
|
2
|
+
import type { components } from "./wire.ts";
|
|
3
|
+
type Schemas = components["schemas"];
|
|
4
|
+
export type ContentValue = Schemas["ContentValue"];
|
|
5
|
+
export type PartOwner = Schemas["PartOwner"];
|
|
6
|
+
export type Part = {
|
|
7
|
+
ordinal: number;
|
|
8
|
+
type: "text";
|
|
9
|
+
bytes: string;
|
|
10
|
+
sha256: string;
|
|
11
|
+
text?: string;
|
|
12
|
+
truncated?: boolean;
|
|
13
|
+
} | {
|
|
14
|
+
ordinal: number;
|
|
15
|
+
type: "image";
|
|
16
|
+
mime: string;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
name: string | null;
|
|
20
|
+
bytes: string;
|
|
21
|
+
sha256: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function listParts(link: Link, session: string, owner: PartOwner): Promise<Part[]>;
|
|
24
|
+
export declare function readPartBytes(link: Link, session: string, owner: PartOwner, ordinal: number, options?: {
|
|
25
|
+
prefix?: number;
|
|
26
|
+
}): Promise<Buffer>;
|
|
27
|
+
export {};
|
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,5 +1,6 @@
|
|
|
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
6
|
export interface Link {
|
|
@@ -50,6 +51,8 @@ export type SessionCreate = ((AgentSpec & {
|
|
|
50
51
|
/** The settings `update` may change: everything but the ones fixed at creation. */
|
|
51
52
|
export type SessionUpdate = Partial<Pick<SessionSpec, "model" | "instructions" | "outputSchema" | "tools" | "permissionMode" | "effort" | "compactAt" | "label" | "loadedTools" | "outputReservation">>;
|
|
52
53
|
export interface WriteOptions {
|
|
54
|
+
/** Optional caller-supplied key for replay. Takes precedence over `idempotencyKey`. */
|
|
55
|
+
key?: string;
|
|
53
56
|
/** Required on `create` and `send`, built as `kind:driftId`. Other writes get a fresh UUIDv4 when it is left out (D123). */
|
|
54
57
|
idempotencyKey?: string;
|
|
55
58
|
}
|
|
@@ -71,7 +74,14 @@ export interface SessionArchiveResult {
|
|
|
71
74
|
export type SessionPinResult = Pick<Extract<Schemas["SessionPinReply"]["answer"], {
|
|
72
75
|
status: "accepted";
|
|
73
76
|
}>, "pinned">;
|
|
74
|
-
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 {
|
|
75
85
|
id: string;
|
|
76
86
|
label: string | null;
|
|
77
87
|
/** The Session's work state, such as `idle`, `working` or `approval`. */
|
|
@@ -85,14 +95,21 @@ type CurrentReport = Extract<Schemas["InspectSessionReply"], {
|
|
|
85
95
|
profile: "current";
|
|
86
96
|
work: unknown;
|
|
87
97
|
}>;
|
|
98
|
+
/** The observed Turn and Operation IDs as decimal strings. */
|
|
99
|
+
export interface InterruptTarget {
|
|
100
|
+
turn: string;
|
|
101
|
+
operation: string;
|
|
102
|
+
}
|
|
88
103
|
/** Current Host facts. Decimal counts, times and IDs remain lossless strings. */
|
|
89
|
-
export interface SessionStatus {
|
|
104
|
+
export interface SessionStatus extends ServedWork {
|
|
90
105
|
archiveState: SessionArchiveState;
|
|
91
106
|
/** `working` includes owed attached-tree work, including unpublished child endings. */
|
|
92
107
|
state: CurrentReport["work"]["state"]["kind"];
|
|
93
108
|
since: CurrentReport["work"]["state"]["since"];
|
|
94
109
|
turn: CurrentReport["work"]["turn"];
|
|
95
110
|
operation: CurrentReport["work"]["operation"];
|
|
111
|
+
/** The Host-served target for interrupting the observed model call. */
|
|
112
|
+
interruptTarget: InterruptTarget | null;
|
|
96
113
|
pendingMessages: CurrentReport["pending_messages"];
|
|
97
114
|
parent: CurrentReport["session"]["parent"];
|
|
98
115
|
label: CurrentReport["session"]["label"];
|
|
@@ -129,6 +146,10 @@ export declare class Session {
|
|
|
129
146
|
readContent(entry: Pick<FeedEntry, "position" | "ordinal">): Promise<string>;
|
|
130
147
|
/** The whole text of an entry as UTF-8 bytes, up to the Host's limit of about 1 GiB. */
|
|
131
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>;
|
|
132
153
|
/** A Current report's summary (D12). A separate ending is not reported. */
|
|
133
154
|
status(): Promise<SessionStatus>;
|
|
134
155
|
/** Sends a Message. The receipt is its admission number; the answer arrives in the feed (D8). */
|
|
@@ -152,14 +173,14 @@ export declare class Session {
|
|
|
152
173
|
/** Selects an owned Action for stop. Reuse the key to recover a lost reply. */
|
|
153
174
|
stopAction(action: string, options?: WriteOptions): Promise<string | null>;
|
|
154
175
|
/** Reads an owned Action. Acceptance and attempted state do not assert a running process. */
|
|
155
|
-
readAction(action: string, offset?: string): Promise<ActionStatus>;
|
|
156
|
-
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* 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.
|
|
161
181
|
*/
|
|
162
|
-
interrupt(): Promise<void>;
|
|
182
|
+
interrupt(target: InterruptTarget, options?: WriteOptions): Promise<void>;
|
|
183
|
+
interrupt(options?: WriteOptions): Promise<void>;
|
|
163
184
|
/** Answers an approval. `requestId` is the Action id of the `approval_requested` entry (D15). */
|
|
164
185
|
decide(requestId: string, decision: "allow" | "deny", options?: WriteOptions): Promise<void>;
|
|
165
186
|
}
|
package/dist/sessions.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { RuiRequestError } from "./errors.js";
|
|
3
|
-
import { listActivity, searchActivity, readContent, readContentBytes } from "./feed.js";
|
|
3
|
+
import { servedWork, listActivity, searchActivity, readContent, readContentBytes } from "./feed.js";
|
|
4
|
+
import { readPartBytes } from "./parts.js";
|
|
4
5
|
import { WIRE_VERSION } from "./transport.js";
|
|
5
6
|
export function agentSpec(spec) {
|
|
6
7
|
return {
|
|
@@ -30,7 +31,7 @@ function configureBody(store, key, session, spec) {
|
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
33
|
function key(options) {
|
|
33
|
-
return options?.idempotencyKey ?? randomUUID();
|
|
34
|
+
return options?.key ?? options?.idempotencyKey ?? randomUUID();
|
|
34
35
|
}
|
|
35
36
|
function parse(reply) {
|
|
36
37
|
return JSON.parse(reply.toString("utf8"));
|
|
@@ -46,6 +47,7 @@ export function environmentBytes(env) {
|
|
|
46
47
|
}
|
|
47
48
|
export class Session {
|
|
48
49
|
#link;
|
|
50
|
+
#interruptTarget = null;
|
|
49
51
|
id;
|
|
50
52
|
constructor(link, id) {
|
|
51
53
|
this.#link = link;
|
|
@@ -58,7 +60,7 @@ export class Session {
|
|
|
58
60
|
* See `ListActivityOptions.follow`; `signal` abort also ends an idle wait.
|
|
59
61
|
*/
|
|
60
62
|
listActivity(options) {
|
|
61
|
-
return listActivity(this.#link, this.id, options);
|
|
63
|
+
return listActivity(this.#link, this.id, options, (target) => { this.#interruptTarget = target; });
|
|
62
64
|
}
|
|
63
65
|
/** Search public feed text newest first, with bounded snippets. */
|
|
64
66
|
searchActivity(query, options) {
|
|
@@ -72,6 +74,12 @@ export class Session {
|
|
|
72
74
|
readContentBytes(entry) {
|
|
73
75
|
return readContentBytes(this.#link, this.id, entry);
|
|
74
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
|
+
}
|
|
75
83
|
/** A Current report's summary (D12). A separate ending is not reported. */
|
|
76
84
|
async status() {
|
|
77
85
|
const reply = parse(await this.#link.exchange("/v1/inspect-session", (store) => JSON.stringify({
|
|
@@ -82,12 +90,15 @@ export class Session {
|
|
|
82
90
|
})));
|
|
83
91
|
if (reply.session === null)
|
|
84
92
|
throw new RuiRequestError("invocation_error", "session_not_found");
|
|
93
|
+
const served = servedWork(reply.work);
|
|
94
|
+
this.#interruptTarget = served.interruptTarget === null ? null : { ...served.interruptTarget };
|
|
85
95
|
return {
|
|
86
96
|
archiveState: reply.archive_state,
|
|
87
97
|
state: reply.work.state.kind,
|
|
88
98
|
since: reply.work.state.since,
|
|
89
99
|
turn: reply.work.turn,
|
|
90
100
|
operation: reply.work.operation,
|
|
101
|
+
...served,
|
|
91
102
|
pendingMessages: reply.pending_messages,
|
|
92
103
|
parent: reply.session.parent,
|
|
93
104
|
label: reply.session.label,
|
|
@@ -206,31 +217,21 @@ export class Session {
|
|
|
206
217
|
return answer.resolution_position;
|
|
207
218
|
}
|
|
208
219
|
/** Reads an owned Action. Acceptance and attempted state do not assert a running process. */
|
|
209
|
-
async readAction(action, offset = "0") {
|
|
220
|
+
async readAction(action, offset = "0", after = "0") {
|
|
210
221
|
return parse(await this.#link.exchange("/v1/read-action", (store) => JSON.stringify({
|
|
211
|
-
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,
|
|
212
223
|
})));
|
|
213
224
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
* call is current, or when the call ended before the cut arrived (D167, D171).
|
|
219
|
-
*/
|
|
220
|
-
async interrupt() {
|
|
221
|
-
const status = await this.status();
|
|
222
|
-
const { turn, operation } = status;
|
|
223
|
-
if (turn === null || operation === null || !modelCallCurrent(status.state)) {
|
|
224
|
-
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)
|
|
225
229
|
return;
|
|
226
|
-
}
|
|
227
|
-
const idempotencyKey =
|
|
230
|
+
const { turn, operation } = target;
|
|
231
|
+
const idempotencyKey = key(explicit ? options : targetOrOptions);
|
|
228
232
|
const body = (store) => JSON.stringify({
|
|
229
|
-
version: WIRE_VERSION,
|
|
230
|
-
|
|
231
|
-
store,
|
|
232
|
-
key: idempotencyKey,
|
|
233
|
-
target: { session: this.id, turn, operation },
|
|
233
|
+
version: WIRE_VERSION, kind: "model_interruption", store,
|
|
234
|
+
key: idempotencyKey, target: { session: this.id, turn, operation },
|
|
234
235
|
});
|
|
235
236
|
try {
|
|
236
237
|
accepted(parse(await this.#link.exchange("/v1/control/model-interruption", body)).answer);
|
|
@@ -259,9 +260,6 @@ export class Session {
|
|
|
259
260
|
this.#link.activity?.notify(this.id);
|
|
260
261
|
}
|
|
261
262
|
}
|
|
262
|
-
function modelCallCurrent(kind) {
|
|
263
|
-
return kind === "working" || kind === "retrying" || kind === "pending";
|
|
264
|
-
}
|
|
265
263
|
export class Sessions {
|
|
266
264
|
#link;
|
|
267
265
|
constructor(link) {
|
|
@@ -290,7 +288,7 @@ export class Sessions {
|
|
|
290
288
|
ceiling: wireCeiling,
|
|
291
289
|
})));
|
|
292
290
|
for (const row of page.sessions) {
|
|
293
|
-
summaries.push({ id: row.reference, label: row.label, state: row.work.state.kind, archiveState: row.archive_state, parent: row.parent, creator: row.creator });
|
|
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 });
|
|
294
292
|
}
|
|
295
293
|
if (page.next === null || !("after" in page.next))
|
|
296
294
|
return summaries.reverse();
|
package/dist/transport.d.ts
CHANGED
package/dist/transport.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { request } from "node:http";
|
|
2
2
|
import { RuiRequestError } from "./errors.js";
|
|
3
|
-
export const WIRE_VERSION = "
|
|
3
|
+
export const WIRE_VERSION = "21";
|
|
4
4
|
const MAX_REPLY_BYTES = 64 * 1024 * 1024;
|
|
5
5
|
const RESPONSE_WAIT_MS = 5_000;
|
|
6
6
|
const TRANSFER_IDLE_MS = 60_000;
|