@agentshouse/kit-wire 0.0.0-stage → 0.1.0-ce39c80194ad4

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anton (trof3039)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,28 @@
1
- # Temporary Holding Version
1
+ # `@agentshouse/kit-wire`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Kit wire: every shape agents.house and the Kit exchange, declared once with
4
+ [zod](https://zod.dev), and the wire computed from them.
5
+
6
+ - The Kit connection at `KIT_CONNECTION_PATH`: each Kit call House sends (`KIT_CALLS`, one per
7
+ Kit method), the Result the Kit returns (`KIT_CALL_RESULT`), and the One-way calls each side
8
+ sends (`HOUSE_ONE_WAY_CALLS`, `KIT_ONE_WAY_CALLS`).
9
+ - Every `/kit/<act>` request and answer (`KIT_ACTS`), the names of the door acts the Kit calls
10
+ at `/kit/door/<act>` (`KIT_DOOR_ACTS`), and the sign-in at `/kit` and `/kit/token`
11
+ (`KIT_LOGIN_START`, `KIT_LOGIN_POLL` and their answers).
12
+ - `KIT_WIRE` is computed from those shapes, so a change to any of them is a new wire. A Kit
13
+ names it in the `x-house-kit-wire` header (`KIT_WIRE_HEADER`) of every request and in its
14
+ connection's subprotocol, `KIT_CONNECTION_PROTOCOL_PREFIX` followed by the wire. House serves
15
+ its own wire alone and answers any other with `kit_update_required`, whose `release` and
16
+ `commands` (`BUILDING_KIT`) name the Kit release its Building serves.
17
+
18
+ ```ts
19
+ import { KIT_WIRE, KIT_WIRE_HEADER, KIT_CALL, type KitActRequest } from '@agentshouse/kit-wire';
20
+
21
+ const call = KIT_CALL.parse(JSON.parse(frame));
22
+ const ended: KitActRequest<'turns/end'> = { conversation, turn, content, failed };
23
+ await fetch(new URL('/kit/turns/end', house), {
24
+ method: 'POST',
25
+ headers: { 'content-type': 'application/json', [KIT_WIRE_HEADER]: KIT_WIRE },
26
+ body: JSON.stringify(ended),
27
+ });
28
+ ```
package/dist/acts.d.ts ADDED
@@ -0,0 +1,339 @@
1
+ import { z } from 'zod';
2
+ export declare const SHA256: z.ZodString;
3
+ export declare const MEDIA_TYPE: z.ZodString;
4
+ export declare const FILE_BYTES: z.ZodInt;
5
+ export declare const FILE_NAME_MAX = 255;
6
+ export declare const FILE_NAME: z.ZodString;
7
+ export declare const PART_SHA256: z.ZodArray<z.ZodString>;
8
+ export declare const SECRET_CEREMONY_STEPS_MAX = 8;
9
+ declare const CEREMONY_STEP: z.ZodDiscriminatedUnion<[z.ZodObject<{
10
+ kind: z.ZodLiteral<"visit">;
11
+ label: z.ZodString;
12
+ url: z.ZodString;
13
+ }, z.core.$strict>, z.ZodObject<{
14
+ kind: z.ZodLiteral<"show">;
15
+ label: z.ZodString;
16
+ text: z.ZodString;
17
+ }, z.core.$strict>, z.ZodObject<{
18
+ kind: z.ZodLiteral<"collect">;
19
+ label: z.ZodString;
20
+ name: z.ZodString;
21
+ description: z.ZodOptional<z.ZodString>;
22
+ }, z.core.$strict>], "kind">;
23
+ export type SecretCeremonyStep = z.infer<typeof CEREMONY_STEP>;
24
+ export declare const DECLARED_SECRET_CEREMONY: z.ZodObject<{
25
+ steps: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
26
+ kind: z.ZodLiteral<"visit">;
27
+ label: z.ZodString;
28
+ url: z.ZodString;
29
+ }, z.core.$strict>, z.ZodObject<{
30
+ kind: z.ZodLiteral<"show">;
31
+ label: z.ZodString;
32
+ text: z.ZodString;
33
+ }, z.core.$strict>, z.ZodObject<{
34
+ kind: z.ZodLiteral<"collect">;
35
+ label: z.ZodString;
36
+ name: z.ZodString;
37
+ description: z.ZodOptional<z.ZodString>;
38
+ }, z.core.$strict>], "kind">>;
39
+ }, z.core.$strict>;
40
+ export type DeclaredSecretCeremony = z.infer<typeof DECLARED_SECRET_CEREMONY>;
41
+ export declare const SECRET_RELAY_RELEASES: readonly ['held', 'superseded', 'withdrawn'];
42
+ export declare const SECRET_RELAY_OUTCOME: z.ZodDiscriminatedUnion<[z.ZodObject<{
43
+ outcome: z.ZodLiteral<"collected">;
44
+ content: z.ZodRecord<z.ZodString, z.ZodString>;
45
+ }, z.core.$strict>, z.ZodObject<{
46
+ outcome: z.ZodLiteral<"released">;
47
+ release: z.ZodEnum<{
48
+ held: "held";
49
+ superseded: "superseded";
50
+ withdrawn: "withdrawn";
51
+ }>;
52
+ }, z.core.$strict>], "outcome">;
53
+ export type SecretRelayOutcome = z.infer<typeof SECRET_RELAY_OUTCOME>;
54
+ export declare const REPORTED_AGENT_KIND: z.ZodObject<{
55
+ kind: z.ZodString;
56
+ release: z.ZodNullable<z.ZodString>;
57
+ minimum: z.ZodOptional<z.ZodString>;
58
+ update: z.ZodOptional<z.ZodString>;
59
+ failure: z.ZodNullable<z.ZodString>;
60
+ installing: z.ZodOptional<z.ZodLiteral<true>>;
61
+ signed_in: z.ZodBoolean;
62
+ models: z.ZodArray<z.ZodObject<{
63
+ model: z.ZodString;
64
+ name: z.ZodString;
65
+ efforts: z.ZodArray<z.ZodString>;
66
+ }, z.core.$strict>>;
67
+ default_model: z.ZodOptional<z.ZodString>;
68
+ default_effort: z.ZodOptional<z.ZodString>;
69
+ modes: z.ZodArray<z.ZodObject<{
70
+ mode: z.ZodString;
71
+ name: z.ZodString;
72
+ }, z.core.$strict>>;
73
+ full_access: z.ZodNullable<z.ZodString>;
74
+ }, z.core.$strict>;
75
+ export type ReportedAgentKind = z.infer<typeof REPORTED_AGENT_KIND>;
76
+ export declare const ENVIRONMENT_FORMS: readonly ['laptop', 'desktop', 'server'];
77
+ declare const TRANSCRIPTION_REPORT: z.ZodObject<{
78
+ installed: z.ZodBoolean;
79
+ failure: z.ZodNullable<z.ZodString>;
80
+ no_engine: z.ZodOptional<z.ZodLiteral<true>>;
81
+ }, z.core.$strict>;
82
+ export type TranscriptionReport = z.infer<typeof TRANSCRIPTION_REPORT>;
83
+ export declare const AGENT_CAPABILITY_DECLARATION: z.ZodObject<{
84
+ os: z.ZodString;
85
+ kit_release: z.ZodString;
86
+ wire: z.ZodString;
87
+ form: z.ZodOptional<z.ZodEnum<{
88
+ desktop: "desktop";
89
+ laptop: "laptop";
90
+ server: "server";
91
+ }>>;
92
+ ssh_host_key: z.ZodOptional<z.ZodString>;
93
+ agent_base: z.ZodOptional<z.ZodString>;
94
+ agents: z.ZodArray<z.ZodObject<{
95
+ kind: z.ZodString;
96
+ release: z.ZodNullable<z.ZodString>;
97
+ minimum: z.ZodOptional<z.ZodString>;
98
+ update: z.ZodOptional<z.ZodString>;
99
+ failure: z.ZodNullable<z.ZodString>;
100
+ installing: z.ZodOptional<z.ZodLiteral<true>>;
101
+ signed_in: z.ZodBoolean;
102
+ models: z.ZodArray<z.ZodObject<{
103
+ model: z.ZodString;
104
+ name: z.ZodString;
105
+ efforts: z.ZodArray<z.ZodString>;
106
+ }, z.core.$strict>>;
107
+ default_model: z.ZodOptional<z.ZodString>;
108
+ default_effort: z.ZodOptional<z.ZodString>;
109
+ modes: z.ZodArray<z.ZodObject<{
110
+ mode: z.ZodString;
111
+ name: z.ZodString;
112
+ }, z.core.$strict>>;
113
+ full_access: z.ZodNullable<z.ZodString>;
114
+ }, z.core.$strict>>;
115
+ transcription: z.ZodOptional<z.ZodObject<{
116
+ installed: z.ZodBoolean;
117
+ failure: z.ZodNullable<z.ZodString>;
118
+ no_engine: z.ZodOptional<z.ZodLiteral<true>>;
119
+ }, z.core.$strict>>;
120
+ }, z.core.$strict>;
121
+ export type AgentCapabilityDeclaration = z.infer<typeof AGENT_CAPABILITY_DECLARATION>;
122
+ export declare const DESIRED_AGENT_ROUTE: z.ZodObject<{
123
+ agent_id: z.ZodUUID;
124
+ kind: z.ZodString;
125
+ base_instructions: z.ZodString;
126
+ working_directory: z.ZodString;
127
+ model: z.ZodNullable<z.ZodString>;
128
+ effort: z.ZodNullable<z.ZodString>;
129
+ mode: z.ZodNullable<z.ZodString>;
130
+ }, z.core.$strict>;
131
+ export type DesiredAgentRoute = z.infer<typeof DESIRED_AGENT_ROUTE>;
132
+ export declare const DESIRED_AGENTS: z.ZodObject<{
133
+ agents: z.ZodArray<z.ZodString>;
134
+ routes: z.ZodArray<z.ZodObject<{
135
+ agent_id: z.ZodUUID;
136
+ kind: z.ZodString;
137
+ base_instructions: z.ZodString;
138
+ working_directory: z.ZodString;
139
+ model: z.ZodNullable<z.ZodString>;
140
+ effort: z.ZodNullable<z.ZodString>;
141
+ mode: z.ZodNullable<z.ZodString>;
142
+ }, z.core.$strict>>;
143
+ transcribe: z.ZodBoolean;
144
+ }, z.core.$strict>;
145
+ export declare const KIT_TURN_END: z.ZodObject<{
146
+ content: z.ZodUnknown;
147
+ failed: z.ZodOptional<z.ZodString>;
148
+ }, z.core.$strict>;
149
+ export type KitTurnEnd = z.infer<typeof KIT_TURN_END>;
150
+ export declare const KIT_TURN_IMAGE: z.ZodObject<{
151
+ bytes: z.ZodInt;
152
+ sha256: z.ZodString;
153
+ name: z.ZodString;
154
+ media_type: z.ZodString;
155
+ }, z.core.$strict>;
156
+ export type KitTurnImage = z.infer<typeof KIT_TURN_IMAGE>;
157
+ export declare const KIT_UPLOAD_FINISH: z.ZodObject<{
158
+ upload: z.ZodUUID;
159
+ part_sha256: z.ZodArray<z.ZodString>;
160
+ }, z.core.$strict>;
161
+ export declare const TRANSCRIPT: z.ZodObject<{
162
+ path: z.ZodString;
163
+ text: z.ZodString;
164
+ }, z.core.$strict>;
165
+ export type Transcript = z.infer<typeof TRANSCRIPT>;
166
+ export declare const KIT_QUESTION: z.ZodObject<{
167
+ interaction_id: z.ZodUUID;
168
+ request: z.ZodJSONSchema;
169
+ secret: z.ZodBoolean;
170
+ }, z.core.$strict>;
171
+ export type KitQuestion = z.infer<typeof KIT_QUESTION>;
172
+ export declare const LOCAL_COPY_ROOM: z.ZodObject<{
173
+ room_ref: z.ZodString;
174
+ room_handle: z.ZodString;
175
+ }, z.core.$strict>;
176
+ export type LocalCopyRoom = z.infer<typeof LOCAL_COPY_ROOM>;
177
+ export interface KitActDeclaration<Id extends string, Body extends z.ZodType, Answer extends z.ZodType | KitDoorAnswer> {
178
+ readonly ids: readonly Id[];
179
+ readonly body: Body;
180
+ readonly answer: Answer;
181
+ }
182
+ export interface KitDoorAnswer {
183
+ readonly door: string;
184
+ }
185
+ export declare const KIT_ACTS: {
186
+ 'secret-inputs/await': KitActDeclaration<"subject", z.ZodObject<{
187
+ steps: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
188
+ kind: z.ZodLiteral<"visit">;
189
+ label: z.ZodString;
190
+ url: z.ZodString;
191
+ }, z.core.$strict>, z.ZodObject<{
192
+ kind: z.ZodLiteral<"show">;
193
+ label: z.ZodString;
194
+ text: z.ZodString;
195
+ }, z.core.$strict>, z.ZodObject<{
196
+ kind: z.ZodLiteral<"collect">;
197
+ label: z.ZodString;
198
+ name: z.ZodString;
199
+ description: z.ZodOptional<z.ZodString>;
200
+ }, z.core.$strict>], "kind">>;
201
+ }, z.core.$strict>, z.ZodDiscriminatedUnion<[z.ZodObject<{
202
+ outcome: z.ZodLiteral<"collected">;
203
+ content: z.ZodRecord<z.ZodString, z.ZodString>;
204
+ }, z.core.$strict>, z.ZodObject<{
205
+ outcome: z.ZodLiteral<"released">;
206
+ release: z.ZodEnum<{
207
+ held: "held";
208
+ superseded: "superseded";
209
+ withdrawn: "withdrawn";
210
+ }>;
211
+ }, z.core.$strict>], "outcome">>;
212
+ 'agents/report': KitActDeclaration<never, z.ZodObject<{
213
+ os: z.ZodString;
214
+ kit_release: z.ZodString;
215
+ wire: z.ZodString;
216
+ form: z.ZodOptional<z.ZodEnum<{
217
+ desktop: "desktop";
218
+ laptop: "laptop";
219
+ server: "server";
220
+ }>>;
221
+ ssh_host_key: z.ZodOptional<z.ZodString>;
222
+ agent_base: z.ZodOptional<z.ZodString>;
223
+ agents: z.ZodArray<z.ZodObject<{
224
+ kind: z.ZodString;
225
+ release: z.ZodNullable<z.ZodString>;
226
+ minimum: z.ZodOptional<z.ZodString>;
227
+ update: z.ZodOptional<z.ZodString>;
228
+ failure: z.ZodNullable<z.ZodString>;
229
+ installing: z.ZodOptional<z.ZodLiteral<true>>;
230
+ signed_in: z.ZodBoolean;
231
+ models: z.ZodArray<z.ZodObject<{
232
+ model: z.ZodString;
233
+ name: z.ZodString;
234
+ efforts: z.ZodArray<z.ZodString>;
235
+ }, z.core.$strict>>;
236
+ default_model: z.ZodOptional<z.ZodString>;
237
+ default_effort: z.ZodOptional<z.ZodString>;
238
+ modes: z.ZodArray<z.ZodObject<{
239
+ mode: z.ZodString;
240
+ name: z.ZodString;
241
+ }, z.core.$strict>>;
242
+ full_access: z.ZodNullable<z.ZodString>;
243
+ }, z.core.$strict>>;
244
+ transcription: z.ZodOptional<z.ZodObject<{
245
+ installed: z.ZodBoolean;
246
+ failure: z.ZodNullable<z.ZodString>;
247
+ no_engine: z.ZodOptional<z.ZodLiteral<true>>;
248
+ }, z.core.$strict>>;
249
+ }, z.core.$strict>, z.ZodObject<{}, z.core.$strict>>;
250
+ 'agents/desired/list': KitActDeclaration<never, z.ZodObject<{}, z.core.$strict>, z.ZodObject<{
251
+ agents: z.ZodArray<z.ZodString>;
252
+ routes: z.ZodArray<z.ZodObject<{
253
+ agent_id: z.ZodUUID;
254
+ kind: z.ZodString;
255
+ base_instructions: z.ZodString;
256
+ working_directory: z.ZodString;
257
+ model: z.ZodNullable<z.ZodString>;
258
+ effort: z.ZodNullable<z.ZodString>;
259
+ mode: z.ZodNullable<z.ZodString>;
260
+ }, z.core.$strict>>;
261
+ transcribe: z.ZodBoolean;
262
+ }, z.core.$strict>>;
263
+ 'kit-calls/results/return': KitActDeclaration<"call", z.ZodUnion<readonly [z.ZodObject<{
264
+ provider_session_id: z.ZodString;
265
+ }, z.core.$strict>, z.ZodObject<{
266
+ refused: z.ZodString;
267
+ resume_refused: z.ZodOptional<z.ZodLiteral<true>>;
268
+ }, z.core.$strict>, z.ZodObject<{
269
+ exit_code: z.ZodInt;
270
+ }, z.core.$strict>, z.ZodObject<{
271
+ output: z.ZodString;
272
+ cut: z.ZodBoolean;
273
+ exit_code: z.ZodInt;
274
+ }, z.core.$strict>, z.ZodObject<{
275
+ output: z.ZodString;
276
+ cut: z.ZodBoolean;
277
+ timed_out: z.ZodLiteral<true>;
278
+ }, z.core.$strict>, z.ZodObject<{
279
+ started: z.ZodLiteral<true>;
280
+ }, z.core.$strict>, z.ZodObject<{}, z.core.$strict>]>, z.ZodObject<{}, z.core.$strict>>;
281
+ 'turns/start': KitActDeclaration<"conversation" | "turn", z.ZodObject<{}, z.core.$strict>, z.ZodObject<{
282
+ run: z.ZodOptional<z.ZodLiteral<true>>;
283
+ }, z.core.$strict>>;
284
+ 'turns/activity/report': KitActDeclaration<"conversation" | "turn", z.ZodObject<{}, z.core.$strict>, z.ZodObject<{}, z.core.$strict>>;
285
+ 'turns/end': KitActDeclaration<"conversation" | "turn", z.ZodObject<{
286
+ content: z.ZodUnknown;
287
+ failed: z.ZodOptional<z.ZodString>;
288
+ }, z.core.$strict>, z.ZodObject<{}, z.core.$strict>>;
289
+ 'turns/images/declare': KitActDeclaration<"conversation" | "turn", z.ZodObject<{
290
+ bytes: z.ZodInt;
291
+ sha256: z.ZodString;
292
+ name: z.ZodString;
293
+ media_type: z.ZodString;
294
+ }, z.core.$strict>, {
295
+ door: string;
296
+ }>;
297
+ 'transcripts/keep': KitActDeclaration<"conversation" | "message", z.ZodObject<{
298
+ path: z.ZodString;
299
+ text: z.ZodString;
300
+ }, z.core.$strict>, z.ZodObject<{}, z.core.$strict>>;
301
+ 'uploads/finish': KitActDeclaration<never, z.ZodObject<{
302
+ upload: z.ZodUUID;
303
+ part_sha256: z.ZodArray<z.ZodString>;
304
+ }, z.core.$strict>, {
305
+ door: string;
306
+ }>;
307
+ 'conversations/interaction/ask': KitActDeclaration<"conversation" | "turn", z.ZodObject<{
308
+ interaction_id: z.ZodUUID;
309
+ request: z.ZodJSONSchema;
310
+ secret: z.ZodBoolean;
311
+ }, z.core.$strict>, z.ZodObject<{}, z.core.$strict>>;
312
+ 'kits/report-idle': KitActDeclaration<never, z.ZodObject<{}, z.core.$strict>, z.ZodObject<{}, z.core.$strict>>;
313
+ 'kits/report-restart': KitActDeclaration<never, z.ZodObject<{}, z.core.$strict>, z.ZodObject<{}, z.core.$strict>>;
314
+ 'conversations/credentials/issue': KitActDeclaration<"conversation", z.ZodObject<{}, z.core.$strict>, z.ZodObject<{
315
+ credential: z.ZodString;
316
+ }, z.core.$strict>>;
317
+ 'kits/log-out': KitActDeclaration<never, z.ZodObject<{}, z.core.$strict>, z.ZodObject<{
318
+ environment: z.ZodUUID;
319
+ revoked: z.ZodLiteral<true>;
320
+ }, z.core.$strict>>;
321
+ 'local-copies/selection/read': KitActDeclaration<never, z.ZodObject<{}, z.core.$strict>, z.ZodObject<{
322
+ local_copy: z.ZodObject<{
323
+ rooms: z.ZodArray<z.ZodObject<{
324
+ room_ref: z.ZodString;
325
+ room_handle: z.ZodString;
326
+ }, z.core.$strict>>;
327
+ }, z.core.$strict>;
328
+ }, z.core.$strict>>;
329
+ };
330
+ export type KitActName = keyof typeof KIT_ACTS;
331
+ type Declared<Name extends KitActName> = (typeof KIT_ACTS)[Name];
332
+ type Fields<Body> = Body extends unknown ? (string extends keyof Body ? {} : Body) : never;
333
+ export type KitActRequest<Name extends KitActName> = {
334
+ readonly [Id in Declared<Name>['ids'][number]]: string;
335
+ } & Fields<z.input<Declared<Name>['body']>>;
336
+ export type KitActAnswer<Name extends KitActName> = Declared<Name>['answer'] extends z.ZodType ? z.output<Declared<Name>['answer']> : unknown;
337
+ export declare const KIT_DOOR_ACTS: readonly ['rooms/discover', 'room-chunks/list', 'changes/enumerate', 'files/revisions/list', 'files/batch'];
338
+ export type KitDoorAct = (typeof KIT_DOOR_ACTS)[number];
339
+ export {};
package/dist/acts.js ADDED
@@ -0,0 +1,185 @@
1
+ import { z } from 'zod';
2
+ import { KIT_CALL_RESULT, KIT_CAUSE } from './connection.js';
3
+ export const SHA256 = z
4
+ .string()
5
+ .regex(/^[0-9a-f]{64}$/u, "must be the file's SHA-256 as 64 lowercase hex digits");
6
+ export const MEDIA_TYPE = z.string().min(1).max(255);
7
+ export const FILE_BYTES = z.int().min(0);
8
+ export const FILE_NAME_MAX = 255;
9
+ export const FILE_NAME = z.string().min(1).max(FILE_NAME_MAX);
10
+ const STORE_PARTS_MAX = 10_000;
11
+ export const PART_SHA256 = z.array(SHA256).min(1).max(STORE_PARTS_MAX);
12
+ export const SECRET_CEREMONY_STEPS_MAX = 8;
13
+ const SECRET_STEP_LABEL_MAX = 200;
14
+ const SECRET_STEP_TEXT_MAX = 4096;
15
+ const SECRET_STEP_NAME_MAX = 64;
16
+ const SECRET_STEP_URL_MAX = 2048;
17
+ const LABEL = z.string().min(1).max(SECRET_STEP_LABEL_MAX);
18
+ const NAME = z
19
+ .string()
20
+ .regex(/^[A-Za-z_][A-Za-z0-9_.-]*$/)
21
+ .refine((name) => name !== '__proto__');
22
+ const CEREMONY_STEP = z.discriminatedUnion('kind', [
23
+ z.strictObject({
24
+ kind: z.literal('visit'),
25
+ label: LABEL,
26
+ url: z
27
+ .string()
28
+ .max(SECRET_STEP_URL_MAX)
29
+ .refine((url) => URL.canParse(url) && new URL(url).protocol === 'https:'),
30
+ }),
31
+ z.strictObject({
32
+ kind: z.literal('show'),
33
+ label: LABEL,
34
+ text: z.string().min(1).max(SECRET_STEP_TEXT_MAX),
35
+ }),
36
+ z.strictObject({
37
+ kind: z.literal('collect'),
38
+ label: LABEL,
39
+ name: NAME.max(SECRET_STEP_NAME_MAX),
40
+ description: z.string().max(SECRET_STEP_TEXT_MAX).optional(),
41
+ }),
42
+ ]);
43
+ export const DECLARED_SECRET_CEREMONY = z
44
+ .strictObject({
45
+ steps: z.array(CEREMONY_STEP).min(1).max(SECRET_CEREMONY_STEPS_MAX),
46
+ })
47
+ .refine((ceremony) => {
48
+ const collected = ceremony.steps.filter((step) => step.kind === 'collect');
49
+ return new Set(collected.map((step) => step.name)).size === collected.length;
50
+ });
51
+ export const SECRET_RELAY_RELEASES = ['held', 'superseded', 'withdrawn'];
52
+ export const SECRET_RELAY_OUTCOME = z.discriminatedUnion('outcome', [
53
+ z.strictObject({ outcome: z.literal('collected'), content: z.record(z.string(), z.string()) }),
54
+ z.strictObject({ outcome: z.literal('released'), release: z.enum(SECRET_RELAY_RELEASES) }),
55
+ ]);
56
+ const AGENT_KIND_MAX = 64;
57
+ const AGENT_RELEASE_MAX = 64;
58
+ const UPDATE_COMMAND_MAX = 256;
59
+ const OPERATING_SYSTEM_MAX = 256;
60
+ const KIT_RELEASE_MAX = 64;
61
+ const OFFERED_MODELS_MAX = 256;
62
+ const MODEL_EFFORTS_MAX = 32;
63
+ const OFFERED_MODES_MAX = 32;
64
+ const MODE_NAME_MAX = 128;
65
+ const CHOICE = z.string().min(1);
66
+ const OFFERED_MODELS = z
67
+ .array(z.strictObject({
68
+ model: CHOICE,
69
+ name: z.string().min(1),
70
+ efforts: z.array(CHOICE).max(MODEL_EFFORTS_MAX),
71
+ }))
72
+ .max(OFFERED_MODELS_MAX);
73
+ const OFFERED_MODES = z
74
+ .array(z.strictObject({ mode: CHOICE, name: z.string().min(1).max(MODE_NAME_MAX) }))
75
+ .max(OFFERED_MODES_MAX);
76
+ const AGENT_RELEASE = z.string().min(1).max(AGENT_RELEASE_MAX);
77
+ export const REPORTED_AGENT_KIND = z.strictObject({
78
+ kind: z.string().min(1).max(AGENT_KIND_MAX),
79
+ release: AGENT_RELEASE.nullable(),
80
+ minimum: AGENT_RELEASE.optional().meta({
81
+ description: "Present only for a CLI below its adapter's minimum release: that minimum.",
82
+ }),
83
+ update: z.string().min(1).max(UPDATE_COMMAND_MAX).optional().meta({
84
+ description: "Present only for a CLI below its adapter's minimum release: its own update command.",
85
+ }),
86
+ failure: KIT_CAUSE.nullable(),
87
+ installing: z.literal(true).optional().meta({
88
+ description: 'Present only while the Kit installs the CLI, whose release and failure are then null.',
89
+ }),
90
+ signed_in: z.boolean(),
91
+ models: OFFERED_MODELS,
92
+ default_model: CHOICE.optional().meta({
93
+ description: 'Present only where the Kit can name the model a fresh session of the CLI starts with: that model, as models lists it.',
94
+ }),
95
+ default_effort: CHOICE.optional().meta({
96
+ description: 'Present only where the Kit can name the effort a fresh session of the CLI starts with: that effort.',
97
+ }),
98
+ modes: OFFERED_MODES,
99
+ full_access: CHOICE.nullable(),
100
+ });
101
+ export const ENVIRONMENT_FORMS = ['laptop', 'desktop', 'server'];
102
+ const TRANSCRIPTION_REPORT = z.strictObject({
103
+ installed: z.boolean(),
104
+ failure: KIT_CAUSE.nullable(),
105
+ no_engine: z.literal(true).optional().meta({
106
+ description: 'Present only where the Kit release pins no transcription engine for the computer.',
107
+ }),
108
+ });
109
+ export const AGENT_CAPABILITY_DECLARATION = z.strictObject({
110
+ os: z.string().min(1).max(OPERATING_SYSTEM_MAX),
111
+ kit_release: z.string().min(1).max(KIT_RELEASE_MAX),
112
+ wire: z.string().min(1),
113
+ form: z.enum(ENVIRONMENT_FORMS).optional(),
114
+ ssh_host_key: z
115
+ .string()
116
+ .regex(/^SHA256:[A-Za-z0-9+/]{43}$/)
117
+ .optional(),
118
+ agent_base: z.string().startsWith('/').optional(),
119
+ agents: z
120
+ .array(REPORTED_AGENT_KIND)
121
+ .refine((agents) => new Set(agents.map((agent) => agent.kind)).size === agents.length),
122
+ transcription: TRANSCRIPTION_REPORT.optional(),
123
+ });
124
+ export const DESIRED_AGENT_ROUTE = z.strictObject({
125
+ agent_id: z.uuid(),
126
+ kind: z.string(),
127
+ base_instructions: z.string(),
128
+ working_directory: z.string(),
129
+ model: z.string().nullable(),
130
+ effort: z.string().nullable(),
131
+ mode: z.string().nullable(),
132
+ });
133
+ export const DESIRED_AGENTS = z.strictObject({
134
+ agents: z.array(z.string()),
135
+ routes: z.array(DESIRED_AGENT_ROUTE),
136
+ transcribe: z.boolean(),
137
+ });
138
+ export const KIT_TURN_END = z.strictObject({ content: z.unknown(), failed: KIT_CAUSE.optional() });
139
+ export const KIT_TURN_IMAGE = z.strictObject({
140
+ bytes: FILE_BYTES,
141
+ sha256: SHA256,
142
+ name: FILE_NAME,
143
+ media_type: MEDIA_TYPE,
144
+ });
145
+ export const KIT_UPLOAD_FINISH = z.strictObject({ upload: z.uuid(), part_sha256: PART_SHA256 });
146
+ export const TRANSCRIPT = z.strictObject({
147
+ path: z.string().regex(/^\/rooms\/[^/)\s]+\/[^)\s]+$/u),
148
+ text: z.string().min(1),
149
+ });
150
+ export const KIT_QUESTION = z.strictObject({
151
+ interaction_id: z.uuid(),
152
+ request: z.json(),
153
+ secret: z.boolean(),
154
+ });
155
+ export const LOCAL_COPY_ROOM = z.strictObject({ room_ref: z.string(), room_handle: z.string() });
156
+ const NOTHING = z.strictObject({});
157
+ function act(ids, body, answer) {
158
+ return { ids, body, answer };
159
+ }
160
+ const CONVERSATION_TURN = ['conversation', 'turn'];
161
+ export const KIT_ACTS = {
162
+ 'secret-inputs/await': act(['subject'], DECLARED_SECRET_CEREMONY, SECRET_RELAY_OUTCOME),
163
+ 'agents/report': act([], AGENT_CAPABILITY_DECLARATION, NOTHING),
164
+ 'agents/desired/list': act([], NOTHING, DESIRED_AGENTS),
165
+ 'kit-calls/results/return': act(['call'], KIT_CALL_RESULT, NOTHING),
166
+ 'turns/start': act(CONVERSATION_TURN, NOTHING, z.strictObject({ run: z.literal(true).optional() })),
167
+ 'turns/activity/report': act(CONVERSATION_TURN, NOTHING, NOTHING),
168
+ 'turns/end': act(CONVERSATION_TURN, KIT_TURN_END, NOTHING),
169
+ 'turns/images/declare': act(CONVERSATION_TURN, KIT_TURN_IMAGE, { door: 'files/attach' }),
170
+ 'transcripts/keep': act(['conversation', 'message'], TRANSCRIPT, NOTHING),
171
+ 'uploads/finish': act([], KIT_UPLOAD_FINISH, { door: 'files/finish' }),
172
+ 'conversations/interaction/ask': act(CONVERSATION_TURN, KIT_QUESTION, NOTHING),
173
+ 'kits/report-idle': act([], NOTHING, NOTHING),
174
+ 'kits/report-restart': act([], NOTHING, NOTHING),
175
+ 'conversations/credentials/issue': act(['conversation'], NOTHING, z.strictObject({ credential: z.string().min(1) })),
176
+ 'kits/log-out': act([], NOTHING, z.strictObject({ environment: z.uuid(), revoked: z.literal(true) })),
177
+ 'local-copies/selection/read': act([], NOTHING, z.strictObject({ local_copy: z.strictObject({ rooms: z.array(LOCAL_COPY_ROOM) }) })),
178
+ };
179
+ export const KIT_DOOR_ACTS = [
180
+ 'rooms/discover',
181
+ 'room-chunks/list',
182
+ 'changes/enumerate',
183
+ 'files/revisions/list',
184
+ 'files/batch',
185
+ ];