ruicode 0.75.0 → 0.82.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.
@@ -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; // The single default choice above supplies every omitted/null directory.
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")
@@ -1,26 +1,18 @@
1
- /** The wire version openapi.json describes. A test keeps the two equal. */
2
- export declare const WIRE_VERSION = "18";
1
+ export declare const WIRE_VERSION = "20";
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
- /** The wire version openapi.json describes. A test keeps the two equal. */
7
- export const WIRE_VERSION = "18";
8
- /** The largest reply body read. The Host's own replies stay far below it. */
3
+ export const WIRE_VERSION = "20";
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
  }