@knpkv/relay 0.1.0 → 0.2.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 +23 -3
- package/dist/harness.d.ts +8 -4
- package/dist/harness.d.ts.map +1 -1
- package/dist/index.js +128 -17
- package/dist/index.js.map +4 -4
- package/dist/messages.d.ts +44 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/model.d.ts +19 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/wire.d.ts +214 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +145 -0
- package/dist/wire.js.map +7 -0
- package/package.json +6 -2
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type MessageEvent = {
|
|
2
|
+
readonly _tag: "MessageQueued";
|
|
3
|
+
readonly requestId: string;
|
|
4
|
+
} | {
|
|
5
|
+
readonly _tag: "MessagePlaced";
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly requestId: string;
|
|
8
|
+
readonly text: string;
|
|
9
|
+
} | {
|
|
10
|
+
readonly _tag: "MessageWithdrawn";
|
|
11
|
+
readonly requestId: string;
|
|
12
|
+
};
|
|
13
|
+
/** What the tracker reads of a stored message; Pi's messages fit it, and no Pi type leaves the bundle. */
|
|
14
|
+
export interface StoredMessage {
|
|
15
|
+
readonly role: string;
|
|
16
|
+
readonly content: string | ReadonlyArray<{
|
|
17
|
+
readonly type: string;
|
|
18
|
+
readonly text?: string;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
/** What the tracker reads of a committed entry. */
|
|
22
|
+
export interface CommittedEntry {
|
|
23
|
+
readonly id: number;
|
|
24
|
+
readonly kind: string;
|
|
25
|
+
readonly model?: ReadonlyArray<StoredMessage>;
|
|
26
|
+
}
|
|
27
|
+
/** What the tracker reads of a submission record. */
|
|
28
|
+
export interface SubmissionState {
|
|
29
|
+
readonly id: number;
|
|
30
|
+
readonly type: "input" | "write";
|
|
31
|
+
readonly status: "queued" | "placed" | "done" | "unanswered";
|
|
32
|
+
readonly requestId?: string;
|
|
33
|
+
readonly entry?: number;
|
|
34
|
+
}
|
|
35
|
+
/** The visible text of a stored user or assistant entry. */
|
|
36
|
+
export declare const entryText: (messages: ReadonlyArray<StoredMessage> | undefined) => string;
|
|
37
|
+
/** One subscription's tracker: feed it each committed entry and submission record, in stream order. */
|
|
38
|
+
export declare const makeMessageTracker: () => {
|
|
39
|
+
/** A committed entry; only a person's message can place one. */
|
|
40
|
+
entry: (entry: CommittedEntry) => ReadonlyArray<MessageEvent>;
|
|
41
|
+
/** A submission record; Relay submits every input with the dock's requestId, its id is the fallback. */
|
|
42
|
+
record: (record: SubmissionState) => ReadonlyArray<MessageEvent>;
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAkBA,MAAM,MAAM,YAAY,GACpB;IAAE,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAC9D;IAAE,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC1G;IAAE,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAA;AAErE,0GAA0G;AAC1G,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CAAC;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC5F;AAED,mDAAmD;AACnD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAA;CAC9C;AAED,qDAAqD;AACrD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAA;IAChC,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,YAAY,CAAA;IAC5D,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,4DAA4D;AAC5D,eAAO,MAAM,SAAS,aAAc,aAAa,CAAC,aAAa,CAAC,GAAG,SAAS,KAAG,MAShE,CAAA;AAEf,uGAAuG;AACvG,eAAO,MAAM,kBAAkB;IAc3B,gEAAgE;IAChE,KAAK,UAAU,cAAc,KAAG,aAAa,CAAC,YAAY,CAAC;IAK3D,wGAAwG;IACxG,MAAM,WAAW,eAAe,KAAG,aAAa,CAAC,YAAY,CAAC;CAYjE,CAAA"}
|
package/dist/model.d.ts
CHANGED
|
@@ -125,6 +125,23 @@ export declare const RelayEvent: Schema.TaggedUnion<{
|
|
|
125
125
|
readonly call: Schema.String;
|
|
126
126
|
readonly decision: Schema.Literals<readonly ["confirmed", "declined", "expired"]>;
|
|
127
127
|
}>;
|
|
128
|
+
readonly MessagePlaced: Schema.TaggedStruct<"MessagePlaced", {
|
|
129
|
+
readonly session: Schema.String;
|
|
130
|
+
readonly seq: Schema.Int;
|
|
131
|
+
readonly id: Schema.String;
|
|
132
|
+
readonly requestId: Schema.String;
|
|
133
|
+
readonly text: Schema.String;
|
|
134
|
+
}>;
|
|
135
|
+
readonly MessageQueued: Schema.TaggedStruct<"MessageQueued", {
|
|
136
|
+
readonly session: Schema.String;
|
|
137
|
+
readonly seq: Schema.Int;
|
|
138
|
+
readonly requestId: Schema.String;
|
|
139
|
+
}>;
|
|
140
|
+
readonly MessageWithdrawn: Schema.TaggedStruct<"MessageWithdrawn", {
|
|
141
|
+
readonly session: Schema.String;
|
|
142
|
+
readonly seq: Schema.Int;
|
|
143
|
+
readonly requestId: Schema.String;
|
|
144
|
+
}>;
|
|
128
145
|
readonly RunFailed: Schema.TaggedStruct<"RunFailed", {
|
|
129
146
|
readonly session: Schema.String;
|
|
130
147
|
readonly seq: Schema.Int;
|
|
@@ -152,6 +169,8 @@ export declare const RelayEvent: Schema.TaggedUnion<{
|
|
|
152
169
|
}>>;
|
|
153
170
|
/** The run in flight, empty when idle. */
|
|
154
171
|
readonly runIds: Schema.$Array<Schema.String>;
|
|
172
|
+
/** Messages accepted but not yet in the transcript, oldest first: they wait for the run in flight. */
|
|
173
|
+
readonly queued: Schema.$Array<Schema.String>;
|
|
155
174
|
}>;
|
|
156
175
|
readonly TextDelta: Schema.TaggedStruct<"TextDelta", {
|
|
157
176
|
readonly session: Schema.String;
|
package/dist/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAI/B,uCAAuC;AACvC,eAAO,MAAM,YAAY,2FAAmF,CAAA;AAC5G,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAA;AAEnD,sGAAsG;AACtG,eAAO,MAAM,SAAS;;;;EAIpB,CAAA;AACF,MAAM,WAAW,SAAU,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,SAAS,CAAC;CAAG;AAE1E,+HAA+H;AAC/H,eAAO,MAAM,YAAY,QAAS,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CAAC;CAAG;AAE9E;;;GAGG;AACH,eAAO,MAAM,YAAY;;;;EAIvB,CAAA;AACF,MAAM,WAAW,YAAa,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,YAAY,CAAC;CAAG;AAShF,kHAAkH;AAClH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAMnB,0CAA0C;;QAE1C,sGAAsG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoCxG,CAAA;AACF,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,IAAI,CAAA"}
|
package/dist/wire.d.ts
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Relay's wire contract: what a product's `/…/relay` routes accept and send, and what the browser decodes.
|
|
3
|
+
* Browser-safe: it imports only `effect` and `@knpkv/capability`, never the harness, Pi or SQLite, so a page
|
|
4
|
+
* can import `@knpkv/relay/wire` without pulling the server in.
|
|
5
|
+
*
|
|
6
|
+
* **Mental model**
|
|
7
|
+
*
|
|
8
|
+
* - **One stream per conversation.** `GET events?product&kind&id` sends `data: <RelayStreamFrame JSON>`
|
|
9
|
+
* frames: a `Snapshot` first, then live {@link RelayEvent}s. `Unauthorized` (the browser's session ended)
|
|
10
|
+
* and `StreamFailed` (the server could not read the session's events) end the stream.
|
|
11
|
+
* - **Writes answer with what happened.** `messages` is 202 {@link RelayMessageAccepted}; `cancel` and
|
|
12
|
+
* `decisions` are 204, or 409 {@link RelayConflictError} with the state they found. Every route can be 503
|
|
13
|
+
* {@link RelayUnavailableError} with the fix when Relay could not start in that process.
|
|
14
|
+
*
|
|
15
|
+
* A product narrows `ref` to its own objects and may add a typed `context` to a message; both are its own
|
|
16
|
+
* schema built on these.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
import { Schema } from "effect";
|
|
21
|
+
export { BackendStatus, BackendUnavailableCause, CapabilityAccess, DecisionState, ObjectRef, objectRefKey, RelayBackendId, RelayEvent, RelayProduct, SessionInfo, SessionTool, WriteReceipt } from "./model.js";
|
|
22
|
+
/** One `data:` frame of the events stream: an event, or why the stream ended. */
|
|
23
|
+
export declare const RelayStreamFrame: Schema.Union<readonly [Schema.TaggedUnion<{
|
|
24
|
+
readonly ApprovalPending: Schema.TaggedStruct<"ApprovalPending", {
|
|
25
|
+
readonly session: Schema.String;
|
|
26
|
+
readonly seq: Schema.Int;
|
|
27
|
+
readonly call: Schema.String;
|
|
28
|
+
readonly approvalId: Schema.String;
|
|
29
|
+
}>;
|
|
30
|
+
readonly Cancelled: Schema.TaggedStruct<"Cancelled", {
|
|
31
|
+
readonly session: Schema.String;
|
|
32
|
+
readonly seq: Schema.Int;
|
|
33
|
+
readonly runIds: Schema.$Array<Schema.String>;
|
|
34
|
+
}>;
|
|
35
|
+
readonly ConfirmationRequired: Schema.TaggedStruct<"ConfirmationRequired", {
|
|
36
|
+
readonly session: Schema.String;
|
|
37
|
+
readonly seq: Schema.Int;
|
|
38
|
+
readonly call: Schema.String;
|
|
39
|
+
readonly action: Schema.Struct<{
|
|
40
|
+
readonly verb: Schema.String;
|
|
41
|
+
readonly target: Schema.Struct<{
|
|
42
|
+
readonly product: Schema.String;
|
|
43
|
+
readonly kind: Schema.String;
|
|
44
|
+
readonly id: Schema.String;
|
|
45
|
+
}>;
|
|
46
|
+
readonly args: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
47
|
+
}>;
|
|
48
|
+
readonly reversible: Schema.Boolean;
|
|
49
|
+
}>;
|
|
50
|
+
readonly ConfirmationResolved: Schema.TaggedStruct<"ConfirmationResolved", {
|
|
51
|
+
readonly session: Schema.String;
|
|
52
|
+
readonly seq: Schema.Int;
|
|
53
|
+
readonly call: Schema.String;
|
|
54
|
+
readonly decision: Schema.Literals<readonly ["confirmed", "declined", "expired"]>;
|
|
55
|
+
}>;
|
|
56
|
+
readonly MessagePlaced: Schema.TaggedStruct<"MessagePlaced", {
|
|
57
|
+
readonly session: Schema.String;
|
|
58
|
+
readonly seq: Schema.Int;
|
|
59
|
+
readonly id: Schema.String;
|
|
60
|
+
readonly requestId: Schema.String;
|
|
61
|
+
readonly text: Schema.String;
|
|
62
|
+
}>;
|
|
63
|
+
readonly MessageQueued: Schema.TaggedStruct<"MessageQueued", {
|
|
64
|
+
readonly session: Schema.String;
|
|
65
|
+
readonly seq: Schema.Int;
|
|
66
|
+
readonly requestId: Schema.String;
|
|
67
|
+
}>;
|
|
68
|
+
readonly MessageWithdrawn: Schema.TaggedStruct<"MessageWithdrawn", {
|
|
69
|
+
readonly session: Schema.String;
|
|
70
|
+
readonly seq: Schema.Int;
|
|
71
|
+
readonly requestId: Schema.String;
|
|
72
|
+
}>;
|
|
73
|
+
readonly RunFailed: Schema.TaggedStruct<"RunFailed", {
|
|
74
|
+
readonly session: Schema.String;
|
|
75
|
+
readonly seq: Schema.Int;
|
|
76
|
+
readonly runIds: Schema.$Array<Schema.String>;
|
|
77
|
+
readonly cause: Schema.String;
|
|
78
|
+
readonly fix: Schema.String;
|
|
79
|
+
}>;
|
|
80
|
+
readonly RunFinished: Schema.TaggedStruct<"RunFinished", {
|
|
81
|
+
readonly session: Schema.String;
|
|
82
|
+
readonly seq: Schema.Int;
|
|
83
|
+
readonly runIds: Schema.$Array<Schema.String>;
|
|
84
|
+
}>;
|
|
85
|
+
readonly RunStarted: Schema.TaggedStruct<"RunStarted", {
|
|
86
|
+
readonly session: Schema.String;
|
|
87
|
+
readonly seq: Schema.Int;
|
|
88
|
+
readonly runIds: Schema.$Array<Schema.String>;
|
|
89
|
+
}>;
|
|
90
|
+
readonly Snapshot: Schema.TaggedStruct<"Snapshot", {
|
|
91
|
+
readonly session: Schema.String;
|
|
92
|
+
readonly seq: Schema.Int;
|
|
93
|
+
readonly messages: Schema.$Array<Schema.Struct<{
|
|
94
|
+
readonly id: Schema.String;
|
|
95
|
+
readonly role: Schema.Literals<readonly ["user", "relay"]>;
|
|
96
|
+
readonly text: Schema.String;
|
|
97
|
+
}>>;
|
|
98
|
+
readonly runIds: Schema.$Array<Schema.String>;
|
|
99
|
+
readonly queued: Schema.$Array<Schema.String>;
|
|
100
|
+
}>;
|
|
101
|
+
readonly TextDelta: Schema.TaggedStruct<"TextDelta", {
|
|
102
|
+
readonly session: Schema.String;
|
|
103
|
+
readonly seq: Schema.Int;
|
|
104
|
+
readonly text: Schema.String;
|
|
105
|
+
}>;
|
|
106
|
+
readonly ToolFinished: Schema.TaggedStruct<"ToolFinished", {
|
|
107
|
+
readonly session: Schema.String;
|
|
108
|
+
readonly seq: Schema.Int;
|
|
109
|
+
readonly call: Schema.String;
|
|
110
|
+
readonly ok: Schema.Boolean;
|
|
111
|
+
readonly summary: Schema.String;
|
|
112
|
+
readonly cites: Schema.$Array<Schema.Struct<{
|
|
113
|
+
readonly product: Schema.String;
|
|
114
|
+
readonly kind: Schema.String;
|
|
115
|
+
readonly id: Schema.String;
|
|
116
|
+
}>>;
|
|
117
|
+
readonly receipt: Schema.optionalKey<Schema.Struct<{
|
|
118
|
+
readonly summary: Schema.String;
|
|
119
|
+
readonly providerId: Schema.String;
|
|
120
|
+
readonly link: Schema.optionalKey<Schema.String>;
|
|
121
|
+
}>>;
|
|
122
|
+
}>;
|
|
123
|
+
readonly ToolStarted: Schema.TaggedStruct<"ToolStarted", {
|
|
124
|
+
readonly session: Schema.String;
|
|
125
|
+
readonly seq: Schema.Int;
|
|
126
|
+
readonly call: Schema.String;
|
|
127
|
+
readonly capability: Schema.String;
|
|
128
|
+
readonly summary: Schema.String;
|
|
129
|
+
readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
130
|
+
}>;
|
|
131
|
+
}>, Schema.TaggedStruct<"Unauthorized", {}>, Schema.TaggedStruct<"StreamFailed", {}>]>;
|
|
132
|
+
export type RelayStreamFrame = typeof RelayStreamFrame.Type;
|
|
133
|
+
/** The text a message may carry. */
|
|
134
|
+
export declare const RelayMessageText: Schema.String;
|
|
135
|
+
/**
|
|
136
|
+
* `POST messages`. `requestId` is the client's: a retry with the same one lands once, and the run that
|
|
137
|
+
* answers carries it in `runIds`. `backend` switches the session from its next turn on.
|
|
138
|
+
*/
|
|
139
|
+
export declare const RelayMessageRequest: Schema.Struct<{
|
|
140
|
+
readonly ref: Schema.Struct<{
|
|
141
|
+
readonly product: Schema.Literals<readonly ["codecommit", "jcf", "agent-usage", "control-center", "herdr"]>;
|
|
142
|
+
readonly kind: Schema.String;
|
|
143
|
+
readonly id: Schema.String;
|
|
144
|
+
}>;
|
|
145
|
+
readonly text: Schema.String;
|
|
146
|
+
readonly requestId: Schema.String;
|
|
147
|
+
readonly backend: Schema.optionalKey<Schema.Literals<readonly ["claude-code", "codex-cli"]>>;
|
|
148
|
+
}>;
|
|
149
|
+
export interface RelayMessageRequest extends Schema.Schema.Type<typeof RelayMessageRequest> {
|
|
150
|
+
}
|
|
151
|
+
/** `messages` answers 202 with the run id, which is the request id. */
|
|
152
|
+
export declare const RelayMessageAccepted: Schema.Struct<{
|
|
153
|
+
readonly runId: Schema.String;
|
|
154
|
+
}>;
|
|
155
|
+
export interface RelayMessageAccepted extends Schema.Schema.Type<typeof RelayMessageAccepted> {
|
|
156
|
+
}
|
|
157
|
+
/** `POST cancel`: withdraws a queued message, or stops the run in flight. */
|
|
158
|
+
export declare const RelayCancelRequest: Schema.Struct<{
|
|
159
|
+
readonly ref: Schema.Struct<{
|
|
160
|
+
readonly product: Schema.Literals<readonly ["codecommit", "jcf", "agent-usage", "control-center", "herdr"]>;
|
|
161
|
+
readonly kind: Schema.String;
|
|
162
|
+
readonly id: Schema.String;
|
|
163
|
+
}>;
|
|
164
|
+
readonly runId: Schema.String;
|
|
165
|
+
}>;
|
|
166
|
+
export interface RelayCancelRequest extends Schema.Schema.Type<typeof RelayCancelRequest> {
|
|
167
|
+
}
|
|
168
|
+
/** `POST decisions`: the person's answer to one confirmation card. */
|
|
169
|
+
export declare const RelayDecisionRequest: Schema.Struct<{
|
|
170
|
+
readonly ref: Schema.Struct<{
|
|
171
|
+
readonly product: Schema.Literals<readonly ["codecommit", "jcf", "agent-usage", "control-center", "herdr"]>;
|
|
172
|
+
readonly kind: Schema.String;
|
|
173
|
+
readonly id: Schema.String;
|
|
174
|
+
}>;
|
|
175
|
+
readonly callId: Schema.String;
|
|
176
|
+
readonly allow: Schema.Boolean;
|
|
177
|
+
}>;
|
|
178
|
+
export interface RelayDecisionRequest extends Schema.Schema.Type<typeof RelayDecisionRequest> {
|
|
179
|
+
}
|
|
180
|
+
/** What a 409 found instead: the run already over, or the confirmation decided, expired or never asked. */
|
|
181
|
+
export declare const RelayConflictState: Schema.Union<readonly [Schema.TaggedUnion<{
|
|
182
|
+
readonly Decided: Schema.TaggedStruct<"Decided", {
|
|
183
|
+
readonly allow: Schema.Boolean;
|
|
184
|
+
}>;
|
|
185
|
+
readonly Expired: Schema.TaggedStruct<"Expired", {}>;
|
|
186
|
+
readonly Unknown: Schema.TaggedStruct<"Unknown", {}>;
|
|
187
|
+
}>, Schema.TaggedStruct<"NotRunning", {}>]>;
|
|
188
|
+
export type RelayConflictState = typeof RelayConflictState.Type;
|
|
189
|
+
declare const RelayUnavailableError_base: Schema.Class<RelayUnavailableError, Schema.TaggedStruct<"RelayUnavailableError", {
|
|
190
|
+
readonly message: Schema.String;
|
|
191
|
+
readonly fix: Schema.String;
|
|
192
|
+
}>, import("effect/Cause").YieldableError>;
|
|
193
|
+
/** Relay could not start in this process: another one owns its store, or the store is unreadable. */
|
|
194
|
+
export declare class RelayUnavailableError extends RelayUnavailableError_base {
|
|
195
|
+
}
|
|
196
|
+
declare const RelayConflictError_base: Schema.Class<RelayConflictError, Schema.TaggedStruct<"RelayConflictError", {
|
|
197
|
+
readonly state: Schema.Union<readonly [Schema.TaggedUnion<{
|
|
198
|
+
readonly Decided: Schema.TaggedStruct<"Decided", {
|
|
199
|
+
readonly allow: Schema.Boolean;
|
|
200
|
+
}>;
|
|
201
|
+
readonly Expired: Schema.TaggedStruct<"Expired", {}>;
|
|
202
|
+
readonly Unknown: Schema.TaggedStruct<"Unknown", {}>;
|
|
203
|
+
}>, Schema.TaggedStruct<"NotRunning", {}>]>;
|
|
204
|
+
}>, import("effect/Cause").YieldableError>;
|
|
205
|
+
/** A run or confirmation is no longer in the state the request assumed; `state` says which it is in. */
|
|
206
|
+
export declare class RelayConflictError extends RelayConflictError_base {
|
|
207
|
+
}
|
|
208
|
+
declare const RelayBadRequestError_base: Schema.Class<RelayBadRequestError, Schema.TaggedStruct<"RelayBadRequestError", {
|
|
209
|
+
readonly message: Schema.String;
|
|
210
|
+
}>, import("effect/Cause").YieldableError>;
|
|
211
|
+
/** The request named a backend this server does not offer, or was otherwise malformed. */
|
|
212
|
+
export declare class RelayBadRequestError extends RelayBadRequestError_base {
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=wire.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAG/B,OAAO,EACL,aAAa,EACb,uBAAuB,EACvB,gBAAgB,EAChB,aAAa,EACb,SAAS,EACT,YAAY,EACZ,cAAc,EACd,UAAU,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,YAAY,EACb,MAAM,YAAY,CAAA;AAInB,iFAAiF;AACjF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sFAI3B,CAAA;AACF,MAAM,MAAM,gBAAgB,GAAG,OAAO,gBAAgB,CAAC,IAAI,CAAA;AAE3D,oCAAoC;AACpC,eAAO,MAAM,gBAAgB,eAAuE,CAAA;AAEpG;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;EAK9B,CAAA;AACF,MAAM,WAAW,mBAAoB,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,mBAAmB,CAAC;CAAG;AAE9F,uEAAuE;AACvE,eAAO,MAAM,oBAAoB;;EAA0C,CAAA;AAC3E,MAAM,WAAW,oBAAqB,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,oBAAoB,CAAC;CAAG;AAEhG,6EAA6E;AAC7E,eAAO,MAAM,kBAAkB;;;;;;;EAAiD,CAAA;AAChF,MAAM,WAAW,kBAAmB,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,kBAAkB,CAAC;CAAG;AAE5F,sEAAsE;AACtE,eAAO,MAAM,oBAAoB;;;;;;;;EAAyE,CAAA;AAC1G,MAAM,WAAW,oBAAqB,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,oBAAoB,CAAC;CAAG;AAEhG,2GAA2G;AAC3G,eAAO,MAAM,kBAAkB;;;;;;2CAAuE,CAAA;AACtG,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAC,IAAI,CAAA;;;;;AAE/D,qGAAqG;AACrG,qBAAa,qBAAsB,SAAQ,0BAI1C;CAAG;;;;;;;;;;AAEJ,wGAAwG;AACxG,qBAAa,kBAAmB,SAAQ,uBAIvC;CAAG;;;;AAEJ,0FAA0F;AAC1F,qBAAa,oBAAqB,SAAQ,yBAIzC;CAAG"}
|
package/dist/wire.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// dist/wire.js
|
|
2
|
+
import { Schema as Schema2 } from "effect";
|
|
3
|
+
|
|
4
|
+
// dist/model.js
|
|
5
|
+
import * as Capability from "@knpkv/capability";
|
|
6
|
+
import { Schema } from "effect";
|
|
7
|
+
var Name = Schema.String.check(Schema.isTrimmed(), Schema.isNonEmpty(), Schema.isMaxLength(200));
|
|
8
|
+
var RelayProduct = Schema.Literals(["codecommit", "jcf", "agent-usage", "control-center", "herdr"]);
|
|
9
|
+
var ObjectRef2 = Schema.Struct({
|
|
10
|
+
product: RelayProduct,
|
|
11
|
+
kind: Name,
|
|
12
|
+
id: Name
|
|
13
|
+
});
|
|
14
|
+
var objectRefKey = (ref) => JSON.stringify([ref.product, ref.kind, ref.id]);
|
|
15
|
+
var CapabilityAccess = Schema.Literals(["read", "write", "host"]);
|
|
16
|
+
var BackendUnavailableCause = Schema.Literals(["NotInstalled", "SignedOut", "Misconfigured", "NoCapability"]);
|
|
17
|
+
var RelayBackendId = Schema.Literals(["claude-code", "codex-cli"]);
|
|
18
|
+
var backendFields = { backend: RelayBackendId, label: Schema.String };
|
|
19
|
+
var BackendStatus = Schema.TaggedUnion({
|
|
20
|
+
Unverified: { ...backendFields, version: Schema.String },
|
|
21
|
+
Ready: { ...backendFields, version: Schema.String },
|
|
22
|
+
Unavailable: {
|
|
23
|
+
...backendFields,
|
|
24
|
+
version: Schema.optionalKey(Schema.String),
|
|
25
|
+
cause: BackendUnavailableCause,
|
|
26
|
+
fix: Schema.String
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
var DecisionState = Schema.TaggedUnion({
|
|
30
|
+
Decided: { allow: Schema.Boolean },
|
|
31
|
+
Expired: {},
|
|
32
|
+
Unknown: {}
|
|
33
|
+
});
|
|
34
|
+
var SessionTool = Schema.Struct({
|
|
35
|
+
name: Name,
|
|
36
|
+
access: CapabilityAccess,
|
|
37
|
+
available: Schema.Boolean,
|
|
38
|
+
unavailableReason: Schema.optional(Schema.String)
|
|
39
|
+
});
|
|
40
|
+
var SessionInfo = Schema.Struct({
|
|
41
|
+
tools: Schema.Array(SessionTool),
|
|
42
|
+
backend: RelayBackendId,
|
|
43
|
+
cancel: Schema.Boolean
|
|
44
|
+
});
|
|
45
|
+
var WriteReceipt = Schema.Struct({
|
|
46
|
+
summary: Schema.String,
|
|
47
|
+
providerId: Schema.String,
|
|
48
|
+
link: Schema.optionalKey(Schema.String)
|
|
49
|
+
});
|
|
50
|
+
var Seq = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
|
|
51
|
+
var eventFields = { session: Name, seq: Seq };
|
|
52
|
+
var RunIds = Schema.Array(Name);
|
|
53
|
+
var RelayEvent = Schema.TaggedUnion({
|
|
54
|
+
Snapshot: {
|
|
55
|
+
...eventFields,
|
|
56
|
+
messages: Schema.Array(Schema.Struct({ id: Name, role: Schema.Literals(["user", "relay"]), text: Schema.String })),
|
|
57
|
+
/** The run in flight, empty when idle. */
|
|
58
|
+
runIds: RunIds,
|
|
59
|
+
/** Messages accepted but not yet in the transcript, oldest first: they wait for the run in flight. */
|
|
60
|
+
queued: RunIds
|
|
61
|
+
},
|
|
62
|
+
/**
|
|
63
|
+
* A message the server accepted that waits for the run in flight. It joins the transcript with its own
|
|
64
|
+
* `MessagePlaced`, or leaves with `MessageWithdrawn`.
|
|
65
|
+
*/
|
|
66
|
+
MessageQueued: { ...eventFields, requestId: Name },
|
|
67
|
+
/** A message the server placed in the transcript; `id` is its transcript id, as a later Snapshot names it. */
|
|
68
|
+
MessagePlaced: { ...eventFields, id: Name, requestId: Name, text: Schema.String },
|
|
69
|
+
/** A queued message the person withdrew before any run took it. */
|
|
70
|
+
MessageWithdrawn: { ...eventFields, requestId: Name },
|
|
71
|
+
RunStarted: { ...eventFields, runIds: RunIds },
|
|
72
|
+
TextDelta: { ...eventFields, text: Schema.String },
|
|
73
|
+
/** `summary` is a server-built, display-safe line; `input` is the call's typed arguments. */
|
|
74
|
+
ToolStarted: { ...eventFields, call: Name, capability: Name, summary: Schema.String, input: Schema.Json },
|
|
75
|
+
/** `receipt` is set when a write completed and its capability projects one. */
|
|
76
|
+
ToolFinished: {
|
|
77
|
+
...eventFields,
|
|
78
|
+
call: Name,
|
|
79
|
+
ok: Schema.Boolean,
|
|
80
|
+
summary: Schema.String,
|
|
81
|
+
cites: Schema.Array(Capability.ObjectRef),
|
|
82
|
+
receipt: Schema.optionalKey(WriteReceipt)
|
|
83
|
+
},
|
|
84
|
+
ConfirmationRequired: { ...eventFields, call: Name, action: Capability.PendingAction, reversible: Schema.Boolean },
|
|
85
|
+
/** The server's outcome for a confirmation: the card turns to past tense only on this. */
|
|
86
|
+
ConfirmationResolved: {
|
|
87
|
+
...eventFields,
|
|
88
|
+
call: Name,
|
|
89
|
+
decision: Schema.Literals(["confirmed", "declined", "expired"])
|
|
90
|
+
},
|
|
91
|
+
ApprovalPending: { ...eventFields, call: Name, approvalId: Name },
|
|
92
|
+
Cancelled: { ...eventFields, runIds: RunIds },
|
|
93
|
+
RunFinished: { ...eventFields, runIds: RunIds },
|
|
94
|
+
RunFailed: { ...eventFields, runIds: RunIds, cause: Schema.String, fix: Schema.String }
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// dist/wire.js
|
|
98
|
+
var Name2 = Schema2.String.check(Schema2.isTrimmed(), Schema2.isNonEmpty(), Schema2.isMaxLength(200));
|
|
99
|
+
var RelayStreamFrame = Schema2.Union([
|
|
100
|
+
RelayEvent,
|
|
101
|
+
Schema2.TaggedStruct("Unauthorized", {}),
|
|
102
|
+
Schema2.TaggedStruct("StreamFailed", {})
|
|
103
|
+
]);
|
|
104
|
+
var RelayMessageText = Schema2.String.check(Schema2.isNonEmpty(), Schema2.isMaxLength(2e4));
|
|
105
|
+
var RelayMessageRequest = Schema2.Struct({
|
|
106
|
+
ref: ObjectRef2,
|
|
107
|
+
text: RelayMessageText,
|
|
108
|
+
requestId: Name2,
|
|
109
|
+
backend: Schema2.optionalKey(RelayBackendId)
|
|
110
|
+
});
|
|
111
|
+
var RelayMessageAccepted = Schema2.Struct({ runId: Schema2.String });
|
|
112
|
+
var RelayCancelRequest = Schema2.Struct({ ref: ObjectRef2, runId: Name2 });
|
|
113
|
+
var RelayDecisionRequest = Schema2.Struct({ ref: ObjectRef2, callId: Name2, allow: Schema2.Boolean });
|
|
114
|
+
var RelayConflictState = Schema2.Union([DecisionState, Schema2.TaggedStruct("NotRunning", {})]);
|
|
115
|
+
var RelayUnavailableError = class extends Schema2.TaggedError()("RelayUnavailableError", { message: Schema2.String, fix: Schema2.String }, { httpApiStatus: 503 }) {
|
|
116
|
+
};
|
|
117
|
+
var RelayConflictError = class extends Schema2.TaggedError()("RelayConflictError", { state: RelayConflictState }, { httpApiStatus: 409 }) {
|
|
118
|
+
};
|
|
119
|
+
var RelayBadRequestError = class extends Schema2.TaggedError()("RelayBadRequestError", { message: Schema2.String }, { httpApiStatus: 400 }) {
|
|
120
|
+
};
|
|
121
|
+
export {
|
|
122
|
+
BackendStatus,
|
|
123
|
+
BackendUnavailableCause,
|
|
124
|
+
CapabilityAccess,
|
|
125
|
+
DecisionState,
|
|
126
|
+
ObjectRef2 as ObjectRef,
|
|
127
|
+
RelayBackendId,
|
|
128
|
+
RelayBadRequestError,
|
|
129
|
+
RelayCancelRequest,
|
|
130
|
+
RelayConflictError,
|
|
131
|
+
RelayConflictState,
|
|
132
|
+
RelayDecisionRequest,
|
|
133
|
+
RelayEvent,
|
|
134
|
+
RelayMessageAccepted,
|
|
135
|
+
RelayMessageRequest,
|
|
136
|
+
RelayMessageText,
|
|
137
|
+
RelayProduct,
|
|
138
|
+
RelayStreamFrame,
|
|
139
|
+
RelayUnavailableError,
|
|
140
|
+
SessionInfo,
|
|
141
|
+
SessionTool,
|
|
142
|
+
WriteReceipt,
|
|
143
|
+
objectRefKey
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=wire.js.map
|
package/dist/wire.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/wire.ts", "../src/model.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Relay's wire contract: what a product's `/\u2026/relay` routes accept and send, and what the browser decodes.\n * Browser-safe: it imports only `effect` and `@knpkv/capability`, never the harness, Pi or SQLite, so a page\n * can import `@knpkv/relay/wire` without pulling the server in.\n *\n * **Mental model**\n *\n * - **One stream per conversation.** `GET events?product&kind&id` sends `data: <RelayStreamFrame JSON>`\n * frames: a `Snapshot` first, then live {@link RelayEvent}s. `Unauthorized` (the browser's session ended)\n * and `StreamFailed` (the server could not read the session's events) end the stream.\n * - **Writes answer with what happened.** `messages` is 202 {@link RelayMessageAccepted}; `cancel` and\n * `decisions` are 204, or 409 {@link RelayConflictError} with the state they found. Every route can be 503\n * {@link RelayUnavailableError} with the fix when Relay could not start in that process.\n *\n * A product narrows `ref` to its own objects and may add a typed `context` to a message; both are its own\n * schema built on these.\n *\n * @module\n */\nimport { Schema } from \"effect\"\nimport { DecisionState, ObjectRef, RelayBackendId, RelayEvent } from \"./model.js\"\n\nexport {\n BackendStatus,\n BackendUnavailableCause,\n CapabilityAccess,\n DecisionState,\n ObjectRef,\n objectRefKey,\n RelayBackendId,\n RelayEvent,\n RelayProduct,\n SessionInfo,\n SessionTool,\n WriteReceipt\n} from \"./model.js\"\n\nconst Name = Schema.String.check(Schema.isTrimmed(), Schema.isNonEmpty(), Schema.isMaxLength(200))\n\n/** One `data:` frame of the events stream: an event, or why the stream ended. */\nexport const RelayStreamFrame = Schema.Union([\n RelayEvent,\n Schema.TaggedStruct(\"Unauthorized\", {}),\n Schema.TaggedStruct(\"StreamFailed\", {})\n])\nexport type RelayStreamFrame = typeof RelayStreamFrame.Type\n\n/** The text a message may carry. */\nexport const RelayMessageText = Schema.String.check(Schema.isNonEmpty(), Schema.isMaxLength(20_000))\n\n/**\n * `POST messages`. `requestId` is the client's: a retry with the same one lands once, and the run that\n * answers carries it in `runIds`. `backend` switches the session from its next turn on.\n */\nexport const RelayMessageRequest = Schema.Struct({\n ref: ObjectRef,\n text: RelayMessageText,\n requestId: Name,\n backend: Schema.optionalKey(RelayBackendId)\n})\nexport interface RelayMessageRequest extends Schema.Schema.Type<typeof RelayMessageRequest> {}\n\n/** `messages` answers 202 with the run id, which is the request id. */\nexport const RelayMessageAccepted = Schema.Struct({ runId: Schema.String })\nexport interface RelayMessageAccepted extends Schema.Schema.Type<typeof RelayMessageAccepted> {}\n\n/** `POST cancel`: withdraws a queued message, or stops the run in flight. */\nexport const RelayCancelRequest = Schema.Struct({ ref: ObjectRef, runId: Name })\nexport interface RelayCancelRequest extends Schema.Schema.Type<typeof RelayCancelRequest> {}\n\n/** `POST decisions`: the person's answer to one confirmation card. */\nexport const RelayDecisionRequest = Schema.Struct({ ref: ObjectRef, callId: Name, allow: Schema.Boolean })\nexport interface RelayDecisionRequest extends Schema.Schema.Type<typeof RelayDecisionRequest> {}\n\n/** What a 409 found instead: the run already over, or the confirmation decided, expired or never asked. */\nexport const RelayConflictState = Schema.Union([DecisionState, Schema.TaggedStruct(\"NotRunning\", {})])\nexport type RelayConflictState = typeof RelayConflictState.Type\n\n/** Relay could not start in this process: another one owns its store, or the store is unreadable. */\nexport class RelayUnavailableError extends Schema.TaggedError<RelayUnavailableError>()(\n \"RelayUnavailableError\",\n { message: Schema.String, fix: Schema.String },\n { httpApiStatus: 503 }\n) {}\n\n/** A run or confirmation is no longer in the state the request assumed; `state` says which it is in. */\nexport class RelayConflictError extends Schema.TaggedError<RelayConflictError>()(\n \"RelayConflictError\",\n { state: RelayConflictState },\n { httpApiStatus: 409 }\n) {}\n\n/** The request named a backend this server does not offer, or was otherwise malformed. */\nexport class RelayBadRequestError extends Schema.TaggedError<RelayBadRequestError>()(\n \"RelayBadRequestError\",\n { message: Schema.String },\n { httpApiStatus: 400 }\n) {}\n", "/**\n * The Relay contracts every product and the dock share.\n *\n * **Mental model**\n *\n * - **An {@link ObjectRef} is what a conversation is about.** A pull request, a jcf week, a herdr\n * goal. Relay keeps one durable session per ref, so the same question about the same object finds\n * its history again.\n * - **A capability (`@knpkv/capability`) is the only way Relay touches a product.** Its contract declares\n * input, output and failure as Schema, and its access: `read` runs, `write` waits for the person to\n * confirm the exact action in the dock, `host` waits for a herdr Approval. The harness enforces it; the\n * product never sees an unconfirmed write.\n * - **A {@link RelayEvent} is the only thing the dock renders.** Every event carries the session and a\n * `seq` that counts up within one subscription. A dock that reconnects starts a new subscription: a\n * `Snapshot` first (with any run in flight and any pending confirmation), then live events. `seq` is not\n * comparable across subscriptions; render the Snapshot rather than deduplicating by `seq`.\n *\n * @module\n */\nimport * as Capability from \"@knpkv/capability\"\nimport { Schema } from \"effect\"\n\nconst Name = Schema.String.check(Schema.isTrimmed(), Schema.isNonEmpty(), Schema.isMaxLength(200))\n\n/** The products Relay can be about. */\nexport const RelayProduct = Schema.Literals([\"codecommit\", \"jcf\", \"agent-usage\", \"control-center\", \"herdr\"])\nexport type RelayProduct = typeof RelayProduct.Type\n\n/** A product object a Relay session is about. Relay keeps sessions only for the products it knows. */\nexport const ObjectRef = Schema.Struct({\n product: RelayProduct,\n kind: Name,\n id: Name\n})\nexport interface ObjectRef extends Schema.Schema.Type<typeof ObjectRef> {}\n\n/** The key a session is stored under. Unique per product, kind and id: JSON-encoded, so no field can contain the separator. */\nexport const objectRefKey = (ref: ObjectRef): string => JSON.stringify([ref.product, ref.kind, ref.id])\n\n/** Who must agree before a capability runs, as the dock lists it. */\nexport const CapabilityAccess = Schema.Literals([\"read\", \"write\", \"host\"])\nexport type CapabilityAccess = typeof CapabilityAccess.Type\n\n/** Why a backend can't answer yet, and the one action that fixes it. */\nexport const BackendUnavailableCause = Schema.Literals([\"NotInstalled\", \"SignedOut\", \"Misconfigured\", \"NoCapability\"])\nexport type BackendUnavailableCause = typeof BackendUnavailableCause.Type\n\n/** The backends Relay supports: each runs on the user's own CLI login, never on a token Relay holds. */\nexport const RelayBackendId = Schema.Literals([\"claude-code\", \"codex-cli\"])\nexport type RelayBackendId = typeof RelayBackendId.Type\n\nconst backendFields = { backend: RelayBackendId, label: Schema.String }\n\n/**\n * What setup shows for one backend. `Unverified` (installed, version known, never answered yet) until a turn\n * answers (`Ready`) or is refused for sign-in (`Unavailable` with `SignedOut`). Not persisted: every start is\n * `Unverified` or `Unavailable` again. `fix` is one line the person can act on.\n */\nexport const BackendStatus = Schema.TaggedUnion({\n Unverified: { ...backendFields, version: Schema.String },\n Ready: { ...backendFields, version: Schema.String },\n Unavailable: {\n ...backendFields,\n version: Schema.optionalKey(Schema.String),\n cause: BackendUnavailableCause,\n fix: Schema.String\n }\n})\nexport type BackendStatus = typeof BackendStatus.Type\n\n/** Why a confirmation can't be answered: answered already, withdrawn with its run, or never asked. */\nexport const DecisionState = Schema.TaggedUnion({\n Decided: { allow: Schema.Boolean },\n Expired: {},\n Unknown: {}\n})\nexport type DecisionState = typeof DecisionState.Type\n\n/** One tool as the dock lists it for a session. */\nexport const SessionTool = Schema.Struct({\n name: Name,\n access: CapabilityAccess,\n available: Schema.Boolean,\n unavailableReason: Schema.optional(Schema.String)\n})\nexport interface SessionTool extends Schema.Schema.Type<typeof SessionTool> {}\n\n/**\n * What the dock shows for a session: its tools, the backend its next turn runs on, and whether a run can\n * be stopped (the dock offers Stop only when `cancel` is true).\n */\nexport const SessionInfo = Schema.Struct({\n tools: Schema.Array(SessionTool),\n backend: RelayBackendId,\n cancel: Schema.Boolean\n})\nexport interface SessionInfo extends Schema.Schema.Type<typeof SessionInfo> {}\n\n/**\n * What a confirmed write did, as the product projects it: a display-safe line, the provider's id for what\n * was made, and where to see it.\n */\nexport const WriteReceipt = Schema.Struct({\n summary: Schema.String,\n providerId: Schema.String,\n link: Schema.optionalKey(Schema.String)\n})\nexport interface WriteReceipt extends Schema.Schema.Type<typeof WriteReceipt> {}\n\nconst Seq = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))\n\nconst eventFields = { session: Name, seq: Seq }\n\n/** The `requestId`s of the messages a run answers: one run can take several queued messages. */\nconst RunIds = Schema.Array(Name)\n\n/** Everything the dock renders. `seq` counts up within one subscription; a reconnect starts from a `Snapshot`. */\nexport const RelayEvent = Schema.TaggedUnion({\n Snapshot: {\n ...eventFields,\n messages: Schema.Array(\n Schema.Struct({ id: Name, role: Schema.Literals([\"user\", \"relay\"]), text: Schema.String })\n ),\n /** The run in flight, empty when idle. */\n runIds: RunIds,\n /** Messages accepted but not yet in the transcript, oldest first: they wait for the run in flight. */\n queued: RunIds\n },\n /**\n * A message the server accepted that waits for the run in flight. It joins the transcript with its own\n * `MessagePlaced`, or leaves with `MessageWithdrawn`.\n */\n MessageQueued: { ...eventFields, requestId: Name },\n /** A message the server placed in the transcript; `id` is its transcript id, as a later Snapshot names it. */\n MessagePlaced: { ...eventFields, id: Name, requestId: Name, text: Schema.String },\n /** A queued message the person withdrew before any run took it. */\n MessageWithdrawn: { ...eventFields, requestId: Name },\n RunStarted: { ...eventFields, runIds: RunIds },\n TextDelta: { ...eventFields, text: Schema.String },\n /** `summary` is a server-built, display-safe line; `input` is the call's typed arguments. */\n ToolStarted: { ...eventFields, call: Name, capability: Name, summary: Schema.String, input: Schema.Json },\n /** `receipt` is set when a write completed and its capability projects one. */\n ToolFinished: {\n ...eventFields,\n call: Name,\n ok: Schema.Boolean,\n summary: Schema.String,\n cites: Schema.Array(Capability.ObjectRef),\n receipt: Schema.optionalKey(WriteReceipt)\n },\n ConfirmationRequired: { ...eventFields, call: Name, action: Capability.PendingAction, reversible: Schema.Boolean },\n /** The server's outcome for a confirmation: the card turns to past tense only on this. */\n ConfirmationResolved: {\n ...eventFields,\n call: Name,\n decision: Schema.Literals([\"confirmed\", \"declined\", \"expired\"])\n },\n ApprovalPending: { ...eventFields, call: Name, approvalId: Name },\n Cancelled: { ...eventFields, runIds: RunIds },\n RunFinished: { ...eventFields, runIds: RunIds },\n RunFailed: { ...eventFields, runIds: RunIds, cause: Schema.String, fix: Schema.String }\n})\nexport type RelayEvent = typeof RelayEvent.Type\n"],
|
|
5
|
+
"mappings": ";AAmBA,SAAS,UAAAA,eAAc;;;ACAvB,YAAY,gBAAgB;AAC5B,SAAS,cAAc;AAEvB,IAAM,OAAO,OAAO,OAAO,MAAM,OAAO,UAAS,GAAI,OAAO,WAAU,GAAI,OAAO,YAAY,GAAG,CAAC;AAG1F,IAAM,eAAe,OAAO,SAAS,CAAC,cAAc,OAAO,eAAe,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;AAG1F,IAAM,mBAAmBA,QAAO,MAAM;EAC3C;EACAA,QAAO,aAAa,gBAAgB,CAAA,CAAE;EACtCA,QAAO,aAAa,gBAAgB,CAAA,CAAE;CACvC;AAIM,IAAM,mBAAmBA,QAAO,OAAO,MAAMA,QAAO,WAAU,GAAIA,QAAO,YAAY,GAAM,CAAC;AAM5F,IAAM,sBAAsBA,QAAO,OAAO;EAC/C,KAAKC;EACL,MAAM;EACN,WAAWF;EACX,SAASC,QAAO,YAAY,cAAc;CAC3C;AAIM,IAAM,uBAAuBA,QAAO,OAAO,EAAE,OAAOA,QAAO,OAAM,CAAE;AAInE,IAAM,qBAAqBA,QAAO,OAAO,EAAE,KAAKC,YAAW,OAAOF,MAAI,CAAE;AAIxE,IAAM,uBAAuBC,QAAO,OAAO,EAAE,KAAKC,YAAW,QAAQF,OAAM,OAAOC,QAAO,QAAO,CAAE;AAIlG,IAAM,qBAAqBA,QAAO,MAAM,CAAC,eAAeA,QAAO,aAAa,cAAc,CAAA,CAAE,CAAC,CAAC;AAI/F,IAAO,wBAAP,cAAqCA,QAAO,YAAW,EAC3D,yBACA,EAAE,SAASA,QAAO,QAAQ,KAAKA,QAAO,OAAM,GAC5C,EAAE,eAAe,IAAG,CAAE,EACvB;;AAGK,IAAO,qBAAP,cAAkCA,QAAO,YAAW,EACxD,sBACA,EAAE,OAAO,mBAAkB,GAC3B,EAAE,eAAe,IAAG,CAAE,EACvB;;AAGK,IAAO,uBAAP,cAAoCA,QAAO,YAAW,EAC1D,wBACA,EAAE,SAASA,QAAO,OAAM,GACxB,EAAE,eAAe,IAAG,CAAE,EACvB;;",
|
|
6
|
+
"names": ["Schema", "ObjectRef", "Name", "Schema", "ObjectRef"]
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knpkv/relay",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Relay agent harness: durable sessions per product object, typed capabilities, a central permission gate, and model turns through the user's own Claude Code or Codex CLI login",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "knpkv",
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
".": {
|
|
18
18
|
"types": "./dist/index.d.ts",
|
|
19
19
|
"import": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./wire": {
|
|
22
|
+
"types": "./dist/wire.d.ts",
|
|
23
|
+
"import": "./dist/wire.js"
|
|
20
24
|
}
|
|
21
25
|
},
|
|
22
26
|
"files": [
|
|
@@ -37,8 +41,8 @@
|
|
|
37
41
|
"@libsql/client": "^0.18.0",
|
|
38
42
|
"typebox": "1.3.27",
|
|
39
43
|
"@knpkv/ai-claude": "^0.4.3",
|
|
40
|
-
"@knpkv/ai-codex": "^0.5.3",
|
|
41
44
|
"@knpkv/ai-runtime": "^0.5.2",
|
|
45
|
+
"@knpkv/ai-codex": "^0.5.3",
|
|
42
46
|
"@knpkv/capability": "^0.1.0"
|
|
43
47
|
},
|
|
44
48
|
"devDependencies": {
|