@langspan/client 0.0.0-stage → 0.17.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/LICENSE +202 -0
- package/NOTICE +25 -0
- package/README.md +39 -2
- package/dist/commands/admission.d.ts +124 -0
- package/dist/commands/admission.js +4 -0
- package/dist/commands/checks.d.ts +115 -0
- package/dist/commands/checks.js +3 -0
- package/dist/commands/graph.d.ts +119 -0
- package/dist/commands/graph.js +4 -0
- package/dist/commands/index.d.ts +25 -0
- package/dist/commands/index.js +125 -0
- package/dist/commands/notes.d.ts +103 -0
- package/dist/commands/notes.js +3 -0
- package/dist/commands/policy.d.ts +49 -0
- package/dist/commands/policy.js +3 -0
- package/dist/commands/reads.d.ts +105 -0
- package/dist/commands/reads.js +4 -0
- package/dist/commands/remote.d.ts +52 -0
- package/dist/commands/remote.js +3 -0
- package/dist/commands/scans.d.ts +39 -0
- package/dist/commands/scans.js +4 -0
- package/dist/commands/sessions.d.ts +63 -0
- package/dist/commands/sessions.js +3 -0
- package/dist/commands/turns.d.ts +67 -0
- package/dist/commands/turns.js +3 -0
- package/dist/errors.d.ts +35 -0
- package/dist/errors.js +195 -0
- package/dist/node.d.ts +16 -0
- package/dist/node.js +78 -0
- package/dist/outcomes/admission.d.ts +79 -0
- package/dist/outcomes/admission.js +4 -0
- package/dist/outcomes/checks.d.ts +123 -0
- package/dist/outcomes/checks.js +4 -0
- package/dist/outcomes/graph.d.ts +181 -0
- package/dist/outcomes/graph.js +5 -0
- package/dist/outcomes/index.d.ts +21 -0
- package/dist/outcomes/index.js +126 -0
- package/dist/outcomes/log.d.ts +87 -0
- package/dist/outcomes/log.js +4 -0
- package/dist/outcomes/notes.d.ts +140 -0
- package/dist/outcomes/notes.js +4 -0
- package/dist/outcomes/sessions.d.ts +120 -0
- package/dist/outcomes/sessions.js +3 -0
- package/dist/protocol.d.ts +100 -0
- package/dist/protocol.js +166 -0
- package/dist/records.d.ts +250 -0
- package/dist/records.js +6 -0
- package/dist/values.d.ts +330 -0
- package/dist/values.js +7 -0
- package/package.json +43 -4
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { Adoption, ContextUse, PresenceSetting, Session, SessionLiveness, Workspace, WorkspaceEnding, WorkspaceKept, WorkspaceSummary } from "../records.ts";
|
|
2
|
+
export interface WorkspaceOutcome {
|
|
3
|
+
type: "workspace";
|
|
4
|
+
workspace: Workspace;
|
|
5
|
+
}
|
|
6
|
+
export interface WorkspacesOutcome {
|
|
7
|
+
type: "workspaces";
|
|
8
|
+
workspaces: WorkspaceSummary[];
|
|
9
|
+
next?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface WorkspaceMovedOutcome {
|
|
12
|
+
type: "workspace_moved";
|
|
13
|
+
workspace: Workspace;
|
|
14
|
+
from_root: string;
|
|
15
|
+
kept: WorkspaceKept;
|
|
16
|
+
}
|
|
17
|
+
/** `applied` is false for a dry run: nothing ended. */
|
|
18
|
+
export interface WorkspaceRemovalOutcome {
|
|
19
|
+
type: "workspace_removal";
|
|
20
|
+
workspace_id: string;
|
|
21
|
+
applied: boolean;
|
|
22
|
+
ending: WorkspaceEnding;
|
|
23
|
+
}
|
|
24
|
+
export interface SessionOutcome {
|
|
25
|
+
type: "session";
|
|
26
|
+
session: Session;
|
|
27
|
+
}
|
|
28
|
+
export interface SessionLivenessOutcome {
|
|
29
|
+
type: "session_liveness";
|
|
30
|
+
liveness: SessionLiveness;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The session's last recorded hook run, this one or one less than
|
|
34
|
+
* `SESSION_SEEN_INTERVAL_MS` earlier.
|
|
35
|
+
*/
|
|
36
|
+
export interface SessionSeenOutcome {
|
|
37
|
+
type: "session_seen";
|
|
38
|
+
session_id: string;
|
|
39
|
+
last_hook_ms: number;
|
|
40
|
+
}
|
|
41
|
+
/** What the session's hooks have added to its context so far. */
|
|
42
|
+
export interface ContextRecordedOutcome {
|
|
43
|
+
type: "context_recorded";
|
|
44
|
+
session_id: string;
|
|
45
|
+
context: ContextUse;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* How many of the named items the session had been told and now has not;
|
|
49
|
+
* zero when none was, and nothing is recorded.
|
|
50
|
+
*/
|
|
51
|
+
export interface ToldForgottenOutcome {
|
|
52
|
+
type: "told_forgotten";
|
|
53
|
+
session_id: string;
|
|
54
|
+
forgotten: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* How many of the named items the hook placed are told now; zero when all
|
|
58
|
+
* were already, and nothing is recorded (issue #531).
|
|
59
|
+
*/
|
|
60
|
+
export interface ToldConfirmedOutcome {
|
|
61
|
+
type: "told_confirmed";
|
|
62
|
+
session_id: string;
|
|
63
|
+
confirmed: number;
|
|
64
|
+
}
|
|
65
|
+
export interface SessionPromptedOutcome {
|
|
66
|
+
type: "session_prompted";
|
|
67
|
+
session_id: string;
|
|
68
|
+
shared_lines?: number;
|
|
69
|
+
}
|
|
70
|
+
export interface PromptTargetsOutcome {
|
|
71
|
+
type: "prompt_targets";
|
|
72
|
+
session_id: string;
|
|
73
|
+
paths: string[];
|
|
74
|
+
}
|
|
75
|
+
export interface PresenceObservedOutcome {
|
|
76
|
+
type: "presence_observed";
|
|
77
|
+
session_id: string;
|
|
78
|
+
paths: number;
|
|
79
|
+
}
|
|
80
|
+
export interface PresenceOutcome {
|
|
81
|
+
type: "presence";
|
|
82
|
+
session_id: string;
|
|
83
|
+
setting: PresenceSetting;
|
|
84
|
+
}
|
|
85
|
+
export interface SessionEndedOutcome {
|
|
86
|
+
type: "session_ended";
|
|
87
|
+
session_id: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* `recorded` is false when this session had already adopted `from`: nothing
|
|
91
|
+
* new was recorded, and the adapter may finish crediting the lines. `root`
|
|
92
|
+
* is the workspace's, whose line journal holds them. `live` names `from`'s
|
|
93
|
+
* subagents that have not ended: their lines (and their own subagents') stay
|
|
94
|
+
* theirs. `earlier` names the sessions whose adoptions lead to `from`: an
|
|
95
|
+
* adopter that ended before its lines were credited left them there, and
|
|
96
|
+
* they are credited too. `kept` names subagents of `from` (or of an
|
|
97
|
+
* `earlier` session) that another session adopted: their lines (and their
|
|
98
|
+
* own subagents') are that session's to credit, so they stay where they are.
|
|
99
|
+
*/
|
|
100
|
+
export interface AdoptedOutcome {
|
|
101
|
+
type: "adopted";
|
|
102
|
+
adoption: Adoption;
|
|
103
|
+
root: string;
|
|
104
|
+
recorded: boolean;
|
|
105
|
+
live?: string[];
|
|
106
|
+
earlier?: string[];
|
|
107
|
+
kept?: string[];
|
|
108
|
+
}
|
|
109
|
+
export interface SessionStoppedOutcome {
|
|
110
|
+
type: "session_stopped";
|
|
111
|
+
session_id: string;
|
|
112
|
+
released: string[];
|
|
113
|
+
wrote?: boolean;
|
|
114
|
+
}
|
|
115
|
+
export interface ToolBatchObservedOutcome {
|
|
116
|
+
type: "tool_batch_observed";
|
|
117
|
+
session_id: string;
|
|
118
|
+
calls: number;
|
|
119
|
+
wrote?: boolean;
|
|
120
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { Command } from "./commands/index.ts";
|
|
2
|
+
import type { ErrorOutcome, Outcome } from "./outcomes/index.ts";
|
|
3
|
+
export * from "./commands/index.ts";
|
|
4
|
+
export * from "./errors.ts";
|
|
5
|
+
export * from "./outcomes/index.ts";
|
|
6
|
+
export type * from "./records.ts";
|
|
7
|
+
export type * from "./values.ts";
|
|
8
|
+
/** The wire version this client speaks (ADR 0037). */
|
|
9
|
+
export declare const PROTOCOL_VERSION = 10;
|
|
10
|
+
/** The largest frame, newline included, either side sends or reads. */
|
|
11
|
+
export declare const MAX_FRAME_BYTES = 65536;
|
|
12
|
+
/**
|
|
13
|
+
* The capabilities this client names, so the coordinator grants each one it
|
|
14
|
+
* knows. Pinned to `src/protocol.rs` and `fixtures/capabilities/answer.json`
|
|
15
|
+
* by the tests.
|
|
16
|
+
*/
|
|
17
|
+
export declare const CAPABILITIES: readonly ["anchored_notes", "briefing_memory", "briefing_outcomes", "build_errors", "collisions", "composition_table", "confirmed_briefings", "git_trouble", "inflight_partial", "intent_contracts", "intent_frames", "intent_overlaps", "interface_notices", "landing_held", "landing_rewrites", "message_paths", "notice_recipients", "opaque_events", "outline_reads", "place_told", "push_messages", "recap_since", "refusal_outcomes", "refused_roots", "remote_messages", "rename_holds", "renames", "reservations", "same_task", "sender_source", "session_limits", "standing_decisions", "subscriptions", "symbol_findings", "tolerant_responses", "trails", "usage", "versioned_keys", "withheld_events", "worked_examples"];
|
|
18
|
+
/**
|
|
19
|
+
* What the coordinator serves and this client does not speak yet (ADR 0043,
|
|
20
|
+
* "Transport"). The client names the `subscriptions` capability, which
|
|
21
|
+
* changes no answer to a request, and has no call or type for its frames.
|
|
22
|
+
*/
|
|
23
|
+
export declare const NOT_YET_AVAILABLE: {
|
|
24
|
+
readonly subscribe: "#628: a held connection, `subscribe` and its `subscribed`, `event` and `resync` frames";
|
|
25
|
+
readonly loopback_websocket: "#653: a `Transport` over the coordinator's opt-in loopback WebSocket";
|
|
26
|
+
};
|
|
27
|
+
export interface Request {
|
|
28
|
+
version: number;
|
|
29
|
+
request_id: string;
|
|
30
|
+
command: Command;
|
|
31
|
+
capabilities?: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
export interface Response {
|
|
34
|
+
version: number;
|
|
35
|
+
request_id: string;
|
|
36
|
+
replayed: boolean;
|
|
37
|
+
generation: number;
|
|
38
|
+
lease_valid: boolean | null;
|
|
39
|
+
/**
|
|
40
|
+
* Typed by `type`. A newer coordinator can send a `type` this client
|
|
41
|
+
* doesn't know; `isKnownOutcome` checks before you rely on its fields.
|
|
42
|
+
*/
|
|
43
|
+
outcome: Outcome;
|
|
44
|
+
/** Present when the request named a capability the coordinator lacks. */
|
|
45
|
+
capabilities?: string[];
|
|
46
|
+
/** Events of a page left out because this client can't read their type. */
|
|
47
|
+
withheld?: number;
|
|
48
|
+
}
|
|
49
|
+
/** A response whose outcome is not an error: the client throws those. */
|
|
50
|
+
export type Answer = Response & {
|
|
51
|
+
outcome: Exclude<Outcome, ErrorOutcome>;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Carries one request frame and returns its one answer frame, both as text
|
|
55
|
+
* without the trailing newline. The Node adapter speaks the Unix socket; a
|
|
56
|
+
* browser embedder supplies one that forwards frames to a local host.
|
|
57
|
+
*
|
|
58
|
+
* Not yet available here (`NOT_YET_AVAILABLE`): subscriptions (#628) and the
|
|
59
|
+
* loopback WebSocket (#653), which the coordinator serves. A subscription
|
|
60
|
+
* keeps its connection open after the answer, so it will be a second,
|
|
61
|
+
* streaming method beside `exchange`; the WebSocket will be another
|
|
62
|
+
* `Transport` carrying the same frames. docs/protocol/README.md,
|
|
63
|
+
* "Subscriptions", specifies the frames.
|
|
64
|
+
*/
|
|
65
|
+
export interface Transport {
|
|
66
|
+
exchange(frame: string, signal?: AbortSignal): Promise<string>;
|
|
67
|
+
}
|
|
68
|
+
/** The request as one frame, or a TransportError when it exceeds the limit. */
|
|
69
|
+
export declare function encodeRequest(request: Request): string;
|
|
70
|
+
/**
|
|
71
|
+
* Parses an answer frame and checks it answers `request`. An integer above
|
|
72
|
+
* `Number.MAX_SAFE_INTEGER`, such as a briefing item's 64-bit key, is read
|
|
73
|
+
* as a `bigint` with every digit; every other number stays a `number`.
|
|
74
|
+
*/
|
|
75
|
+
export declare function decodeResponse(frame: string, request: Request): Response;
|
|
76
|
+
export interface ClientOptions {
|
|
77
|
+
/** Capabilities to name; every one this client knows by default. */
|
|
78
|
+
capabilities?: readonly string[];
|
|
79
|
+
/** Makes request IDs; random UUIDs by default. */
|
|
80
|
+
requestId?: () => string;
|
|
81
|
+
}
|
|
82
|
+
export interface SendOptions {
|
|
83
|
+
/** The ID of an earlier request to retry: the coordinator replays its outcome. */
|
|
84
|
+
requestId?: string;
|
|
85
|
+
signal?: AbortSignal;
|
|
86
|
+
}
|
|
87
|
+
/** Sends typed commands over a transport and returns their outcomes. */
|
|
88
|
+
export declare class Client {
|
|
89
|
+
#private;
|
|
90
|
+
constructor(transport: Transport, options?: ClientOptions);
|
|
91
|
+
/**
|
|
92
|
+
* Sends `command` and returns the whole response. Throws CoordinatorError
|
|
93
|
+
* when the coordinator answers with an error, and TransportError when it
|
|
94
|
+
* cannot be reached or answers out of protocol. Either error's `requestId`
|
|
95
|
+
* is the ID to retry with, generated or given.
|
|
96
|
+
*/
|
|
97
|
+
send(command: Command, options?: SendOptions): Promise<Answer>;
|
|
98
|
+
/** Sends `command` and returns its outcome alone. */
|
|
99
|
+
request(command: Command, options?: SendOptions): Promise<Answer["outcome"]>;
|
|
100
|
+
}
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// The transport-agnostic part of the client: frames, requests, answers and
|
|
2
|
+
// errors. It imports nothing from Node, so a browser build can use it behind
|
|
3
|
+
// an embedder's bridge (ADR 0043, "Clients").
|
|
4
|
+
import { CoordinatorError, TransportError } from "./errors.js";
|
|
5
|
+
export * from "./commands/index.js";
|
|
6
|
+
export * from "./errors.js";
|
|
7
|
+
export * from "./outcomes/index.js";
|
|
8
|
+
/** The wire version this client speaks (ADR 0037). */
|
|
9
|
+
export const PROTOCOL_VERSION = 10;
|
|
10
|
+
/** The largest frame, newline included, either side sends or reads. */
|
|
11
|
+
export const MAX_FRAME_BYTES = 65_536;
|
|
12
|
+
/**
|
|
13
|
+
* The capabilities this client names, so the coordinator grants each one it
|
|
14
|
+
* knows. Pinned to `src/protocol.rs` and `fixtures/capabilities/answer.json`
|
|
15
|
+
* by the tests.
|
|
16
|
+
*/
|
|
17
|
+
export const CAPABILITIES = [
|
|
18
|
+
"anchored_notes",
|
|
19
|
+
"briefing_memory",
|
|
20
|
+
"briefing_outcomes",
|
|
21
|
+
"build_errors",
|
|
22
|
+
"collisions",
|
|
23
|
+
"composition_table",
|
|
24
|
+
"confirmed_briefings",
|
|
25
|
+
"git_trouble",
|
|
26
|
+
"inflight_partial",
|
|
27
|
+
"intent_contracts",
|
|
28
|
+
"intent_frames",
|
|
29
|
+
"intent_overlaps",
|
|
30
|
+
"interface_notices",
|
|
31
|
+
"landing_held",
|
|
32
|
+
"landing_rewrites",
|
|
33
|
+
"message_paths",
|
|
34
|
+
"notice_recipients",
|
|
35
|
+
"opaque_events",
|
|
36
|
+
"outline_reads",
|
|
37
|
+
"place_told",
|
|
38
|
+
"push_messages",
|
|
39
|
+
"recap_since",
|
|
40
|
+
"refusal_outcomes",
|
|
41
|
+
"refused_roots",
|
|
42
|
+
"remote_messages",
|
|
43
|
+
"rename_holds",
|
|
44
|
+
"renames",
|
|
45
|
+
"reservations",
|
|
46
|
+
"same_task",
|
|
47
|
+
"sender_source",
|
|
48
|
+
"session_limits",
|
|
49
|
+
"standing_decisions",
|
|
50
|
+
"subscriptions",
|
|
51
|
+
"symbol_findings",
|
|
52
|
+
"tolerant_responses",
|
|
53
|
+
"trails",
|
|
54
|
+
"usage",
|
|
55
|
+
"versioned_keys",
|
|
56
|
+
"withheld_events",
|
|
57
|
+
"worked_examples",
|
|
58
|
+
];
|
|
59
|
+
/**
|
|
60
|
+
* What the coordinator serves and this client does not speak yet (ADR 0043,
|
|
61
|
+
* "Transport"). The client names the `subscriptions` capability, which
|
|
62
|
+
* changes no answer to a request, and has no call or type for its frames.
|
|
63
|
+
*/
|
|
64
|
+
export const NOT_YET_AVAILABLE = {
|
|
65
|
+
subscribe: "#628: a held connection, `subscribe` and its `subscribed`, `event` and `resync` frames",
|
|
66
|
+
loopback_websocket: "#653: a `Transport` over the coordinator's opt-in loopback WebSocket",
|
|
67
|
+
};
|
|
68
|
+
const encoder = new TextEncoder();
|
|
69
|
+
// JSON's source-text access (ES2026; Node 21 and later), which the es2023
|
|
70
|
+
// lib this package checks against doesn't declare.
|
|
71
|
+
const lossless = JSON;
|
|
72
|
+
/** The request as one frame, or a TransportError when it exceeds the limit. */
|
|
73
|
+
export function encodeRequest(request) {
|
|
74
|
+
// A `bigint` (a `U64` above 2^53) is written as its exact digits.
|
|
75
|
+
const frame = JSON.stringify(request, (_, value) => typeof value === "bigint" ? lossless.rawJSON(value.toString()) : value);
|
|
76
|
+
if (encoder.encode(frame).length + 1 > MAX_FRAME_BYTES) {
|
|
77
|
+
throw new TransportError(`request ${request.request_id} exceeds the 64 KiB frame limit; send fewer paths or shorter text`, { requestId: request.request_id });
|
|
78
|
+
}
|
|
79
|
+
return frame;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Parses an answer frame and checks it answers `request`. An integer above
|
|
83
|
+
* `Number.MAX_SAFE_INTEGER`, such as a briefing item's 64-bit key, is read
|
|
84
|
+
* as a `bigint` with every digit; every other number stays a `number`.
|
|
85
|
+
*/
|
|
86
|
+
export function decodeResponse(frame, request) {
|
|
87
|
+
const requestId = request.request_id;
|
|
88
|
+
let value;
|
|
89
|
+
try {
|
|
90
|
+
value = lossless.parse(frame, (_, parsed, { source }) => typeof parsed === "number" && !Number.isSafeInteger(parsed) && source && /^-?\d+$/.test(source)
|
|
91
|
+
? BigInt(source)
|
|
92
|
+
: parsed);
|
|
93
|
+
}
|
|
94
|
+
catch (cause) {
|
|
95
|
+
throw new TransportError("the coordinator's answer is not JSON; check that the socket belongs to a LangSpan coordinator", { cause, requestId });
|
|
96
|
+
}
|
|
97
|
+
if (!isResponse(value)) {
|
|
98
|
+
throw new TransportError("the coordinator's answer is not a protocol response; check that the coordinator speaks wire version 10", { requestId });
|
|
99
|
+
}
|
|
100
|
+
// A coordinator answers a frame it could not read without the request ID,
|
|
101
|
+
// as an error: nothing took effect, and the error is the answer.
|
|
102
|
+
const unread = value.request_id === "" && value.outcome.type === "error";
|
|
103
|
+
if (value.request_id !== request.request_id && !unread) {
|
|
104
|
+
throw new TransportError(`the answer is for request ${JSON.stringify(value.request_id)}, not ${requestId}; retry with the same request ID`, { requestId });
|
|
105
|
+
}
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
function isResponse(value) {
|
|
109
|
+
if (typeof value !== "object" || value === null)
|
|
110
|
+
return false;
|
|
111
|
+
const v = value;
|
|
112
|
+
const outcome = v.outcome;
|
|
113
|
+
return (typeof v.version === "number" &&
|
|
114
|
+
typeof v.request_id === "string" &&
|
|
115
|
+
typeof v.replayed === "boolean" &&
|
|
116
|
+
typeof v.generation === "number" &&
|
|
117
|
+
typeof outcome === "object" &&
|
|
118
|
+
outcome !== null &&
|
|
119
|
+
typeof outcome.type === "string" &&
|
|
120
|
+
(outcome.type !== "error" || (typeof outcome.code === "string" && typeof outcome.message === "string")));
|
|
121
|
+
}
|
|
122
|
+
/** Sends typed commands over a transport and returns their outcomes. */
|
|
123
|
+
export class Client {
|
|
124
|
+
#transport;
|
|
125
|
+
#capabilities;
|
|
126
|
+
#requestId;
|
|
127
|
+
constructor(transport, options = {}) {
|
|
128
|
+
this.#transport = transport;
|
|
129
|
+
this.#capabilities = options.capabilities ?? CAPABILITIES;
|
|
130
|
+
this.#requestId = options.requestId ?? (() => globalThis.crypto.randomUUID());
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Sends `command` and returns the whole response. Throws CoordinatorError
|
|
134
|
+
* when the coordinator answers with an error, and TransportError when it
|
|
135
|
+
* cannot be reached or answers out of protocol. Either error's `requestId`
|
|
136
|
+
* is the ID to retry with, generated or given.
|
|
137
|
+
*/
|
|
138
|
+
async send(command, options = {}) {
|
|
139
|
+
const request = {
|
|
140
|
+
version: PROTOCOL_VERSION,
|
|
141
|
+
request_id: options.requestId ?? this.#requestId(),
|
|
142
|
+
command,
|
|
143
|
+
capabilities: this.#capabilities,
|
|
144
|
+
};
|
|
145
|
+
const encoded = encodeRequest(request);
|
|
146
|
+
let frame;
|
|
147
|
+
try {
|
|
148
|
+
frame = await this.#transport.exchange(encoded, options.signal);
|
|
149
|
+
}
|
|
150
|
+
catch (cause) {
|
|
151
|
+
// The coordinator may have recorded the request: say which ID it had.
|
|
152
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
153
|
+
throw new TransportError(message, { cause, requestId: request.request_id });
|
|
154
|
+
}
|
|
155
|
+
const response = decodeResponse(frame, request);
|
|
156
|
+
const { outcome } = response;
|
|
157
|
+
if (outcome.type === "error") {
|
|
158
|
+
throw new CoordinatorError(outcome.code, outcome.message, request.request_id);
|
|
159
|
+
}
|
|
160
|
+
return response;
|
|
161
|
+
}
|
|
162
|
+
/** Sends `command` and returns its outcome alone. */
|
|
163
|
+
async request(command, options = {}) {
|
|
164
|
+
return (await this.send(command, options)).outcome;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import type { FileState, PathRegions, Rebased, ToolIdentity, UnitKey } from "./values.ts";
|
|
2
|
+
/**
|
|
3
|
+
* A structure this client passes through without typing its fields yet.
|
|
4
|
+
* Its Rust type of the same name in `crates/langspan-core/src` defines it.
|
|
5
|
+
* The coordinator may add fields (`tolerant_responses`, ADR 0015).
|
|
6
|
+
*/
|
|
7
|
+
export type Fields = {
|
|
8
|
+
readonly [field: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
export interface Workspace {
|
|
11
|
+
workspace_id: string;
|
|
12
|
+
root: string;
|
|
13
|
+
verified_overlaps?: string[];
|
|
14
|
+
}
|
|
15
|
+
export interface Session {
|
|
16
|
+
session_id: string;
|
|
17
|
+
workspace_id: string;
|
|
18
|
+
generation: number;
|
|
19
|
+
parent?: string;
|
|
20
|
+
headless?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface Intent {
|
|
23
|
+
session_id: string;
|
|
24
|
+
workspace_id: string;
|
|
25
|
+
paths: string[];
|
|
26
|
+
summary: string;
|
|
27
|
+
generation: number;
|
|
28
|
+
/** Contracts the work changes and reads; capability `intent_contracts`. */
|
|
29
|
+
changes?: string[];
|
|
30
|
+
reads?: string[];
|
|
31
|
+
/** Typed parts of the work (issue #33); capability `intent_contracts`. */
|
|
32
|
+
parts?: IntentPart[];
|
|
33
|
+
}
|
|
34
|
+
/** A rename, signature change, removal or move of `symbol`; `to` names a rename's new name. */
|
|
35
|
+
export type PartKind = "rename" | "change_signature" | "remove" | "move";
|
|
36
|
+
export interface IntentPart {
|
|
37
|
+
kind: PartKind;
|
|
38
|
+
symbol: string;
|
|
39
|
+
to?: string;
|
|
40
|
+
}
|
|
41
|
+
export type LeaseStatus = "active" | "completed" | "expired" | "invalidated";
|
|
42
|
+
export interface Lease {
|
|
43
|
+
lease_id: string;
|
|
44
|
+
session_id: string;
|
|
45
|
+
workspace_id: string;
|
|
46
|
+
paths: string[];
|
|
47
|
+
generation: number;
|
|
48
|
+
expires_at_ms: number;
|
|
49
|
+
status: LeaseStatus;
|
|
50
|
+
operation?: ToolIdentity;
|
|
51
|
+
/** Admitted paths the coordinator had no version of (ADR 0005). */
|
|
52
|
+
base_unknown?: string[];
|
|
53
|
+
regions?: PathRegions[];
|
|
54
|
+
/** A rename's new names, held beside the old one; capability `versioned_keys`. */
|
|
55
|
+
renamed_to?: UnitKey[];
|
|
56
|
+
rebased_over?: Rebased[];
|
|
57
|
+
}
|
|
58
|
+
/** A current holder an admission met. */
|
|
59
|
+
export interface Conflict {
|
|
60
|
+
lease_id: string;
|
|
61
|
+
session_id: string;
|
|
62
|
+
paths: string[];
|
|
63
|
+
regions?: PathRegions[];
|
|
64
|
+
}
|
|
65
|
+
/** A file whose version differs from the one the session last read or wrote. */
|
|
66
|
+
export interface StaleFile {
|
|
67
|
+
path: string;
|
|
68
|
+
read: FileState;
|
|
69
|
+
current: FileState;
|
|
70
|
+
changed_by: string | null;
|
|
71
|
+
}
|
|
72
|
+
/** What kind of live work shares a path with a new intent. */
|
|
73
|
+
export type OverlapKind = "intent" | "admission" | "prompt_target" | "contract";
|
|
74
|
+
/** Other running sessions' work that shares a path with a new intent; capability `intent_overlaps`. */
|
|
75
|
+
export interface IntentOverlap {
|
|
76
|
+
session_id: string;
|
|
77
|
+
kind: OverlapKind;
|
|
78
|
+
paths: string[];
|
|
79
|
+
/** For kind `contract`: contracts the other session changes that this intent changes or reads. */
|
|
80
|
+
changes?: string[];
|
|
81
|
+
/** For kind `contract`: contracts the other session only reads that this intent changes. */
|
|
82
|
+
reads?: string[];
|
|
83
|
+
/** The other session's checkout root, when it is not the caller's. */
|
|
84
|
+
worktree?: string;
|
|
85
|
+
}
|
|
86
|
+
export interface IntentOverlaps {
|
|
87
|
+
/** Newest first, at most 8. */
|
|
88
|
+
entries: IntentOverlap[];
|
|
89
|
+
/** Entries past the limit. */
|
|
90
|
+
omitted?: number;
|
|
91
|
+
/** True when the caller's checkout is not scanned yet: only its own is listed. */
|
|
92
|
+
worktrees_unavailable?: boolean;
|
|
93
|
+
}
|
|
94
|
+
export interface Reservation {
|
|
95
|
+
scope: string;
|
|
96
|
+
key: string;
|
|
97
|
+
number: number;
|
|
98
|
+
session_id: string;
|
|
99
|
+
workspace_id: string;
|
|
100
|
+
at_ms: number;
|
|
101
|
+
}
|
|
102
|
+
/** One event of the log. `Event` in `event.rs` has one shape per `type`. */
|
|
103
|
+
export type Event = {
|
|
104
|
+
readonly type: string;
|
|
105
|
+
readonly [field: string]: unknown;
|
|
106
|
+
};
|
|
107
|
+
export interface RecordedEvent {
|
|
108
|
+
seq: number;
|
|
109
|
+
event: Event;
|
|
110
|
+
}
|
|
111
|
+
export type Adoption = Fields;
|
|
112
|
+
export type AutoCheck = Fields;
|
|
113
|
+
export type BlindSpots = Fields;
|
|
114
|
+
export type BranchObservation = Fields;
|
|
115
|
+
export type Briefing = Fields;
|
|
116
|
+
export type CallBreak = Fields;
|
|
117
|
+
export type CheckRecord = Fields;
|
|
118
|
+
export type CheckView = Fields;
|
|
119
|
+
export type CheckoutChange = Fields;
|
|
120
|
+
export type CheckoutRun = Fields;
|
|
121
|
+
export type CompactionReport = Fields;
|
|
122
|
+
export type ContextUse = Fields;
|
|
123
|
+
export type Dashboard = Fields;
|
|
124
|
+
export type DiskObservation = Fields;
|
|
125
|
+
export type FlakyTest = Fields;
|
|
126
|
+
export type GraphCoverage = Fields;
|
|
127
|
+
export type History = Fields;
|
|
128
|
+
export type ImpactLevel = Fields;
|
|
129
|
+
export type InflightNotice = Fields;
|
|
130
|
+
export type InterfaceImpact = Fields;
|
|
131
|
+
export type InterfaceNotice = Fields;
|
|
132
|
+
export type Landing = Fields;
|
|
133
|
+
export type MapArea = Fields;
|
|
134
|
+
export type MapEdge = Fields;
|
|
135
|
+
export type Message = Fields;
|
|
136
|
+
export type MessageStatus = Fields;
|
|
137
|
+
export type NameContext = Fields;
|
|
138
|
+
export type NameRef = Fields;
|
|
139
|
+
export type Note = Fields;
|
|
140
|
+
export type RecordedDecision = Fields;
|
|
141
|
+
export type Observation = Fields;
|
|
142
|
+
export type OutlineEntry = Fields;
|
|
143
|
+
export type PeerCallers = Fields;
|
|
144
|
+
export type PlanEdge = Fields;
|
|
145
|
+
export type PlanLive = Fields;
|
|
146
|
+
export type PolicyRow = Fields;
|
|
147
|
+
export type PresenceSetting = Fields;
|
|
148
|
+
export type QueuedLanding = Fields;
|
|
149
|
+
export type Recall = Fields;
|
|
150
|
+
export type Recap = Fields;
|
|
151
|
+
export type RefusalCount = Fields;
|
|
152
|
+
export type RemoteLink = Fields;
|
|
153
|
+
export type Rename = Fields;
|
|
154
|
+
export type Report = Fields;
|
|
155
|
+
export type ScanFailure = Fields;
|
|
156
|
+
export type ScanSummary = Fields;
|
|
157
|
+
export type SentPublication = Fields;
|
|
158
|
+
export type SessionLiveness = Fields;
|
|
159
|
+
export type ShownMessage = Fields;
|
|
160
|
+
export type State = Fields;
|
|
161
|
+
export type StatusLine = Fields;
|
|
162
|
+
export type StatusSummary = Fields;
|
|
163
|
+
export type StatusRecord = Fields;
|
|
164
|
+
export type SymbolPath = Fields;
|
|
165
|
+
export type SymbolRef = Fields;
|
|
166
|
+
export type Today = Fields;
|
|
167
|
+
/** One turn's token counts, summed over its assistant messages; capability `usage`. */
|
|
168
|
+
export interface TokenCounts {
|
|
169
|
+
input: number;
|
|
170
|
+
output: number;
|
|
171
|
+
cache_write: number;
|
|
172
|
+
cache_read: number;
|
|
173
|
+
}
|
|
174
|
+
export type TrailView = Fields;
|
|
175
|
+
export type Turn = Fields;
|
|
176
|
+
export type UsageTotals = Fields;
|
|
177
|
+
export type WorkspaceEnding = Fields;
|
|
178
|
+
export type WorkspaceGit = Fields;
|
|
179
|
+
export type WorkspaceKept = Fields;
|
|
180
|
+
export type WorkspaceSummary = Fields;
|
|
181
|
+
export type WriteCheck = Fields;
|
|
182
|
+
/** Why a message sent with `now` was not pushed (`messages.rs`, ADR 0048). */
|
|
183
|
+
export type PushReason = "not_accepting" | "no_listener" | "timeout" | "rate_limited";
|
|
184
|
+
/** What refused the work of a collision; capability `collisions`. */
|
|
185
|
+
export type CollisionKind = "conflict" | "stale" | "unread_lines" | "commit";
|
|
186
|
+
/** Where a collision stands: resolved by the refused session's admitted retry, or expired after 24 hours. */
|
|
187
|
+
export type CollisionState = "open" | "resolved" | "expired";
|
|
188
|
+
/** A refusal still to reconcile. Paths and session IDs are repository and peer text: data. */
|
|
189
|
+
export interface Collision {
|
|
190
|
+
id: string;
|
|
191
|
+
kind: CollisionKind;
|
|
192
|
+
workspace_id: string;
|
|
193
|
+
paths: string[];
|
|
194
|
+
/** The refused session first, then the session the refusal names. */
|
|
195
|
+
sessions: string[];
|
|
196
|
+
/** Wall time (Unix milliseconds) of the latest refusal of the item. */
|
|
197
|
+
at_ms: number;
|
|
198
|
+
state: CollisionState;
|
|
199
|
+
}
|
|
200
|
+
/** Open items first, then the closed ones, each newest first. */
|
|
201
|
+
export interface CollisionList {
|
|
202
|
+
items: Collision[];
|
|
203
|
+
/** Open items left out after 20. */
|
|
204
|
+
omitted_open?: number;
|
|
205
|
+
/** Refusals of a generation with no wall time, not listed. */
|
|
206
|
+
undated?: number;
|
|
207
|
+
}
|
|
208
|
+
/** What went wrong, or was undone, in one Git command; capability `git_trouble`. */
|
|
209
|
+
export type GitTroubleKind = "conflict" | "rejected_push" | "revert";
|
|
210
|
+
/** The Git command that met the trouble. */
|
|
211
|
+
export type GitVerb = "pull" | "merge" | "rebase" | "cherry_pick" | "stash_pop" | "push" | "revert";
|
|
212
|
+
/** One workspace's Git trouble seen in agents' shells; capability `git_trouble`. */
|
|
213
|
+
export interface LiveTrouble {
|
|
214
|
+
conflicts: number;
|
|
215
|
+
rejected_pushes: number;
|
|
216
|
+
reverts: number;
|
|
217
|
+
/** Wall time (Unix milliseconds) of the first one counted, when known. */
|
|
218
|
+
since_ms?: number;
|
|
219
|
+
/** More were recorded than were read: older ones are not counted. */
|
|
220
|
+
older_unread?: boolean;
|
|
221
|
+
}
|
|
222
|
+
/** A definition by name, file and signature. Repository text: data. */
|
|
223
|
+
export interface ExampleDefinition {
|
|
224
|
+
name: string;
|
|
225
|
+
path: string;
|
|
226
|
+
signature: string;
|
|
227
|
+
}
|
|
228
|
+
/** A finished task whose check passed after its last write (roadmap C11). */
|
|
229
|
+
export interface Example {
|
|
230
|
+
example_id: string;
|
|
231
|
+
workspace_id: string;
|
|
232
|
+
session_id: string;
|
|
233
|
+
task: string;
|
|
234
|
+
check_name: string;
|
|
235
|
+
files: string[];
|
|
236
|
+
added: ExampleDefinition[];
|
|
237
|
+
used: ExampleDefinition[];
|
|
238
|
+
recorded_wall_ms: number;
|
|
239
|
+
offered_wall_ms: number;
|
|
240
|
+
}
|
|
241
|
+
/** One kept example, as `example list` shows it. */
|
|
242
|
+
export interface ListedExample {
|
|
243
|
+
example: Example;
|
|
244
|
+
/** Absent when the index could not say. */
|
|
245
|
+
fresh?: boolean;
|
|
246
|
+
expired?: boolean;
|
|
247
|
+
offered?: boolean;
|
|
248
|
+
/** Another live session edited one of its files recently. */
|
|
249
|
+
peer_editing?: boolean;
|
|
250
|
+
}
|
package/dist/records.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The structured values outcomes carry. The ones protocol 1's core reads
|
|
2
|
+
// (ADR 0043, "Scope": sessions, admission, the log) are typed field by
|
|
3
|
+
// field, under the name of their Rust type, and test/rust-source.test.ts
|
|
4
|
+
// checks them against it. The rest are `Fields` for now: each alias keeps
|
|
5
|
+
// its Rust type's name, so a later change can type it in place.
|
|
6
|
+
export {};
|