ruicode 0.94.3 → 0.96.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/dist/feed.d.ts +8 -4
- package/dist/feed.js +15 -15
- package/dist/rejections.js +0 -1
- package/dist/sessions.d.ts +3 -5
- package/dist/sessions.js +4 -6
- package/dist/transport.d.ts +1 -1
- package/dist/transport.js +1 -1
- package/dist/turn-endings.d.ts +11 -0
- package/dist/turn-endings.js +12 -0
- package/dist/wire.d.ts +168 -205
- package/package.json +4 -4
package/dist/feed.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import type { InterruptTarget, Link, ServedWork } from "./sessions.ts";
|
|
|
2
2
|
import { type Part } from "./parts.ts";
|
|
3
3
|
import type { components } from "./wire.ts";
|
|
4
4
|
type Schemas = components["schemas"];
|
|
5
|
-
export declare function servedWork(work: Pick<Schemas["SessionWork"], "
|
|
5
|
+
export declare function servedWork(work: Pick<Schemas["SessionWork"], "actions">): ServedWork;
|
|
6
6
|
type Row = Schemas["ActivityItem"];
|
|
7
7
|
/** Every kind the Host's feed has, in its own order. */
|
|
8
|
-
export declare const FEED_KINDS: readonly ["admission", "user", "assistant", "call", "tool_result", "hosted_call", "turn_ended", "stop", "
|
|
8
|
+
export declare const FEED_KINDS: readonly ["admission", "user", "assistant", "call", "tool_result", "hosted_call", "turn_ended", "stop", "received", "approval_requested", "session_changed", "compacted", "model_call", "instruction", "skill"];
|
|
9
9
|
export type FeedKind = (typeof FEED_KINDS)[number];
|
|
10
10
|
/** Entry text is inline up to this many bytes (D168). */
|
|
11
11
|
export declare const INLINE_TEXT_BYTES: number;
|
|
@@ -53,15 +53,19 @@ export declare function decodeCursor(cursor: string): {
|
|
|
53
53
|
position: string;
|
|
54
54
|
ordinal: string;
|
|
55
55
|
};
|
|
56
|
+
/** Which exact text of a row to open. A hosted call holds several: its targets in order, then its pattern. Every other row has one, field 0. */
|
|
57
|
+
export interface ContentOptions {
|
|
58
|
+
field?: number;
|
|
59
|
+
}
|
|
56
60
|
/** The Host owns the rule: its text route refuses a parts value as `ContentIsParts`. */
|
|
57
61
|
export declare function readContentBytes(link: Link, session: string, entry: {
|
|
58
62
|
position: string;
|
|
59
63
|
ordinal: string;
|
|
60
|
-
}): Promise<Buffer>;
|
|
64
|
+
}, options?: ContentOptions): Promise<Buffer>;
|
|
61
65
|
export declare function readContent(link: Link, session: string, entry: {
|
|
62
66
|
position: string;
|
|
63
67
|
ordinal: string;
|
|
64
|
-
}): Promise<string>;
|
|
68
|
+
}, options?: ContentOptions): Promise<string>;
|
|
65
69
|
/** A page request: the next row's cursor, the `since` token of the last full reply, and the kinds. `end` pins a bounded traversal. */
|
|
66
70
|
export interface PageRequest {
|
|
67
71
|
end: string | null;
|
package/dist/feed.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import { ContentIsPartsError, RuiRequestError, RuiUnavailableError } from "./errors.js";
|
|
2
2
|
import { listParts, readPartBytes } from "./parts.js";
|
|
3
3
|
import { WIRE_VERSION } from "./transport.js";
|
|
4
|
+
import { ENDING_SIGN } from "./turn-endings.js";
|
|
4
5
|
export function servedWork(work) {
|
|
5
|
-
if (!work || !
|
|
6
|
+
if (!work || !work.actions ||
|
|
6
7
|
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
8
|
(work.actions.decide !== null && typeof work.actions.decide !== "string") ||
|
|
12
9
|
(work.actions.interrupt !== null && (typeof work.actions.interrupt !== "object" ||
|
|
13
10
|
typeof work.actions.interrupt.turn !== "string" || typeof work.actions.interrupt.operation !== "string"))) {
|
|
14
11
|
throw new Error("Invalid work reply: missing served facts");
|
|
15
12
|
}
|
|
16
|
-
return {
|
|
13
|
+
return { canStop: work.actions.stop,
|
|
17
14
|
decide: work.actions.decide, interruptTarget: work.actions.interrupt };
|
|
18
15
|
}
|
|
19
16
|
/** Every kind the Host's feed has, in its own order. */
|
|
@@ -26,20 +23,21 @@ export const FEED_KINDS = [
|
|
|
26
23
|
"hosted_call",
|
|
27
24
|
"turn_ended",
|
|
28
25
|
"stop",
|
|
29
|
-
"sent",
|
|
30
|
-
"send_failed",
|
|
31
26
|
"received",
|
|
32
27
|
"approval_requested",
|
|
33
28
|
"session_changed",
|
|
34
29
|
"compacted",
|
|
35
30
|
"model_call",
|
|
31
|
+
"instruction",
|
|
32
|
+
"skill",
|
|
36
33
|
];
|
|
37
34
|
const complete = true;
|
|
38
35
|
void complete;
|
|
36
|
+
const endingsSigned = true;
|
|
37
|
+
void endingsSigned;
|
|
39
38
|
/** Entry text is inline up to this many bytes (D168). */
|
|
40
39
|
export const INLINE_TEXT_BYTES = 16 * 1024;
|
|
41
40
|
const PAGE_ROWS = 16;
|
|
42
|
-
const ENDINGS_WITH_TEXT = new Set(["provider_refused", "out_of_quota", "failed"]);
|
|
43
41
|
export function encodeCursor(position, ordinal) {
|
|
44
42
|
return Buffer.from(`1:${position}:${ordinal}`).toString("base64url");
|
|
45
43
|
}
|
|
@@ -66,7 +64,8 @@ function contentOf(payload) {
|
|
|
66
64
|
function entryOf(row) {
|
|
67
65
|
const [kind, payload] = Object.entries(row.value)[0];
|
|
68
66
|
const reference = contentOf(payload);
|
|
69
|
-
|
|
67
|
+
// A failed Turn's report is the entry's text; a finished Turn's answer is its assistant entry and a stopped one has none.
|
|
68
|
+
const wanted = kind !== "turn_ended" || ENDING_SIGN[payload.ending] === "failed";
|
|
70
69
|
const entry = {
|
|
71
70
|
kind,
|
|
72
71
|
cursor: encodeCursor(row.position, row.ordinal),
|
|
@@ -93,7 +92,7 @@ function activityBody(store, session, request) {
|
|
|
93
92
|
...(request.since === null ? {} : { since: request.since }),
|
|
94
93
|
});
|
|
95
94
|
}
|
|
96
|
-
function contentBody(store, session, entry) {
|
|
95
|
+
function contentBody(store, session, entry, options = {}) {
|
|
97
96
|
return JSON.stringify({
|
|
98
97
|
version: WIRE_VERSION,
|
|
99
98
|
kind: "activity_content",
|
|
@@ -101,13 +100,14 @@ function contentBody(store, session, entry) {
|
|
|
101
100
|
session,
|
|
102
101
|
position: entry.position,
|
|
103
102
|
ordinal: entry.ordinal,
|
|
103
|
+
...(options.field === undefined ? {} : { field: String(options.field) }),
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
const MAX_CONTENT_BYTES = 1024 * 1024 * 1024;
|
|
107
107
|
/** The Host owns the rule: its text route refuses a parts value as `ContentIsParts`. */
|
|
108
|
-
export async function readContentBytes(link, session, entry) {
|
|
108
|
+
export async function readContentBytes(link, session, entry, options = {}) {
|
|
109
109
|
try {
|
|
110
|
-
return await link.exchange("/v1/activity-content", (store) => contentBody(store, session, entry), undefined, { max: MAX_CONTENT_BYTES });
|
|
110
|
+
return await link.exchange("/v1/activity-content", (store) => contentBody(store, session, entry, options), undefined, { max: MAX_CONTENT_BYTES });
|
|
111
111
|
}
|
|
112
112
|
catch (error) {
|
|
113
113
|
if (error instanceof RuiRequestError && error.code === "ContentIsParts")
|
|
@@ -115,8 +115,8 @@ export async function readContentBytes(link, session, entry) {
|
|
|
115
115
|
throw error;
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
export async function readContent(link, session, entry) {
|
|
119
|
-
return (await readContentBytes(link, session, entry)).toString("utf8");
|
|
118
|
+
export async function readContent(link, session, entry, options = {}) {
|
|
119
|
+
return (await readContentBytes(link, session, entry, options)).toString("utf8");
|
|
120
120
|
}
|
|
121
121
|
export async function readPage(link, session, request) {
|
|
122
122
|
const reply = await link.exchange("/v1/activity-page", (store) => activityBody(store, session, request));
|
package/dist/rejections.js
CHANGED
|
@@ -21,7 +21,6 @@ export const REJECTION_SENTENCES = {
|
|
|
21
21
|
"invalid_model": "The model ID is empty.",
|
|
22
22
|
"invalid_output_reservation": "The output reservation is not a nonnegative token count.",
|
|
23
23
|
"invalid_output_schema": "The output schema is not valid JSON.",
|
|
24
|
-
"invalid_sender_handle": "The peer sender handle is invalid or no longer live.",
|
|
25
24
|
"invalid_session_reference": "That Session reference is malformed.",
|
|
26
25
|
"invalid_target": "A target ID is invalid.",
|
|
27
26
|
"invalid_workspace": "The workspace is not a usable absolute directory.",
|
package/dist/sessions.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Follows } from "./follow.ts";
|
|
2
|
-
import { type ActivitySearchEntry, type SearchActivityOptions, type FeedEntry, type ListActivityOptions, type WatchOptions } from "./feed.ts";
|
|
2
|
+
import { type ActivitySearchEntry, type SearchActivityOptions, type ContentOptions, type FeedEntry, type ListActivityOptions, type WatchOptions } from "./feed.ts";
|
|
3
3
|
import { type ContentValue } from "./parts.ts";
|
|
4
4
|
import { type ReplyLimits } from "./transport.ts";
|
|
5
5
|
import type { components } from "./wire.ts";
|
|
@@ -107,8 +107,6 @@ export type SessionPinResult = Pick<Extract<Schemas["SessionPinReply"]["answer"]
|
|
|
107
107
|
status: "accepted";
|
|
108
108
|
}>, "pinned">;
|
|
109
109
|
export interface ServedWork {
|
|
110
|
-
attention: Schemas["SessionWork"]["attention"];
|
|
111
|
-
group: Schemas["SessionWork"]["group"];
|
|
112
110
|
canStop: boolean;
|
|
113
111
|
decide: string | null;
|
|
114
112
|
interruptTarget: InterruptTarget | null;
|
|
@@ -186,9 +184,9 @@ export declare class Session {
|
|
|
186
184
|
/** Search public feed text newest first, with bounded snippets. */
|
|
187
185
|
searchActivity(query: string, options?: SearchActivityOptions): AsyncGenerator<ActivitySearchEntry, void, undefined>;
|
|
188
186
|
/** The whole text of an entry (D134). Past about 512 MiB a string cannot hold it and this throws: use `readContentBytes`. */
|
|
189
|
-
readContent(entry: Pick<FeedEntry, "position" | "ordinal"
|
|
187
|
+
readContent(entry: Pick<FeedEntry, "position" | "ordinal">, options?: ContentOptions): Promise<string>;
|
|
190
188
|
/** The whole text of an entry as UTF-8 bytes, up to the Host's limit of about 1 GiB. */
|
|
191
|
-
readContentBytes(entry: Pick<FeedEntry, "position" | "ordinal"
|
|
189
|
+
readContentBytes(entry: Pick<FeedEntry, "position" | "ordinal">, options?: ContentOptions): Promise<Buffer>;
|
|
192
190
|
/** The exact bytes of one part of a parts entry; rejects with `TypeError` for an entry whose content is not parts. */
|
|
193
191
|
readPart(entry: {
|
|
194
192
|
content: ContentValue | null;
|
package/dist/sessions.js
CHANGED
|
@@ -88,12 +88,12 @@ export class Session {
|
|
|
88
88
|
return searchActivity(this.#link, this.id, query, options);
|
|
89
89
|
}
|
|
90
90
|
/** The whole text of an entry (D134). Past about 512 MiB a string cannot hold it and this throws: use `readContentBytes`. */
|
|
91
|
-
readContent(entry) {
|
|
92
|
-
return readContent(this.#link, this.id, entry);
|
|
91
|
+
readContent(entry, options) {
|
|
92
|
+
return readContent(this.#link, this.id, entry, options);
|
|
93
93
|
}
|
|
94
94
|
/** The whole text of an entry as UTF-8 bytes, up to the Host's limit of about 1 GiB. */
|
|
95
|
-
readContentBytes(entry) {
|
|
96
|
-
return readContentBytes(this.#link, this.id, entry);
|
|
95
|
+
readContentBytes(entry, options) {
|
|
96
|
+
return readContentBytes(this.#link, this.id, entry, options);
|
|
97
97
|
}
|
|
98
98
|
/** The exact bytes of one part of a parts entry; rejects with `TypeError` for an entry whose content is not parts. */
|
|
99
99
|
async readPart(entry, ordinal) {
|
|
@@ -140,8 +140,6 @@ export class Session {
|
|
|
140
140
|
store,
|
|
141
141
|
key: options.idempotencyKey,
|
|
142
142
|
session: this.id,
|
|
143
|
-
sender: null,
|
|
144
|
-
sender_handle: null,
|
|
145
143
|
text: { state: "value", value: text },
|
|
146
144
|
});
|
|
147
145
|
const reply = parse(await this.#link.exchange("/v1/message", body, environmentBytes(options.env)));
|
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 = "29";
|
|
4
4
|
const MAX_REPLY_BYTES = 64 * 1024 * 1024;
|
|
5
5
|
const TRANSFER_IDLE_MS = 60_000;
|
|
6
6
|
export class ConnectionError extends Error {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** What each Turn ending means to a person: it finished, it was stopped, or it failed. */
|
|
2
|
+
export declare const ENDING_SIGN: {
|
|
3
|
+
readonly done: "finished";
|
|
4
|
+
readonly context_full: "failed";
|
|
5
|
+
readonly provider_refused: "failed";
|
|
6
|
+
readonly out_of_quota: "failed";
|
|
7
|
+
readonly provider_unavailable: "failed";
|
|
8
|
+
readonly stopped: "stopped";
|
|
9
|
+
readonly interrupted: "stopped";
|
|
10
|
+
readonly failed: "failed";
|
|
11
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Generated from src/turn_ending.zig by `zig build openapi`. Do not edit.
|
|
2
|
+
/** What each Turn ending means to a person: it finished, it was stopped, or it failed. */
|
|
3
|
+
export const ENDING_SIGN = {
|
|
4
|
+
"done": "finished",
|
|
5
|
+
"context_full": "failed",
|
|
6
|
+
"provider_refused": "failed",
|
|
7
|
+
"out_of_quota": "failed",
|
|
8
|
+
"provider_unavailable": "failed",
|
|
9
|
+
"stopped": "stopped",
|
|
10
|
+
"interrupted": "stopped",
|
|
11
|
+
"failed": "failed",
|
|
12
|
+
};
|