@fungi.computer/knapsack 0.1.0 → 0.2.1
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 +42 -5
- package/dist/files-patch.d.ts +16 -2
- package/dist/files-patch.js +8 -1
- package/dist/files-read.d.ts +108 -3
- package/dist/files-read.js +77 -7
- package/dist/files-search.d.ts +14 -0
- package/dist/files-search.js +52 -0
- package/dist/files.d.ts +40 -46
- package/dist/files.js +171 -85
- package/dist/index.d.ts +8 -1
- package/dist/index.js +5 -1
- package/dist/mcp.d.ts +1 -2
- package/dist/ui/browser.d.ts +44 -0
- package/dist/ui/browser.js +171 -0
- package/dist/ui/effect.d.ts +106 -0
- package/dist/ui/effect.js +208 -0
- package/dist/ui/host.d.ts +9 -0
- package/dist/ui/host.js +158 -0
- package/dist/ui/sessions.d.ts +32 -0
- package/dist/ui/sessions.js +172 -0
- package/dist/ui/wire.d.ts +290 -0
- package/dist/ui/wire.js +136 -0
- package/dist/ui-browser.d.ts +6 -0
- package/dist/ui-browser.js +6 -0
- package/dist/ui.d.ts +29 -0
- package/dist/ui.js +35 -0
- package/docs/api/README.md +1 -0
- package/docs/api/files-patch.md +39 -43
- package/docs/api/files-read.md +263 -27
- package/docs/api/index.md +209 -108
- package/docs/api/ui-browser.md +94 -0
- package/package.json +16 -5
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
export declare const uiWireIds: Readonly<{
|
|
3
|
+
readonly request: import("@fungi.computer/cairn").IdCodec<"knapsack-ui", "request", 1>;
|
|
4
|
+
readonly connection: import("@fungi.computer/cairn").IdCodec<"knapsack-ui", "connection", 1>;
|
|
5
|
+
readonly claim: import("@fungi.computer/cairn").IdCodec<"knapsack-ui", "claim", 1>;
|
|
6
|
+
readonly attempt: import("@fungi.computer/cairn").IdCodec<"knapsack-ui", "attempt", 1>;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const BrowserWireObjectSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
9
|
+
export type BrowserWireObject = z.output<typeof BrowserWireObjectSchema>;
|
|
10
|
+
export declare const BrowserCommandRowSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
11
|
+
action: z.ZodUnion<readonly [z.ZodObject<{
|
|
12
|
+
inputSchema: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
13
|
+
outputSchema: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
14
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
15
|
+
inputSchema: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
16
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
17
|
+
outputSchema: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
18
|
+
}, z.core.$strict>]>;
|
|
19
|
+
commandId: z.ZodString;
|
|
20
|
+
sourceId: z.ZodString;
|
|
21
|
+
title: z.ZodString;
|
|
22
|
+
category: z.ZodString;
|
|
23
|
+
description: z.ZodNullable<z.ZodString>;
|
|
24
|
+
order: z.ZodNumber;
|
|
25
|
+
keybind: z.ZodNullable<z.ZodString>;
|
|
26
|
+
availability: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
27
|
+
status: z.ZodLiteral<"available">;
|
|
28
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
29
|
+
status: z.ZodLiteral<"unavailable">;
|
|
30
|
+
reason: z.ZodString;
|
|
31
|
+
}, z.core.$strip>], "status">;
|
|
32
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
33
|
+
commandId: z.ZodString;
|
|
34
|
+
sourceId: z.ZodString;
|
|
35
|
+
title: z.ZodString;
|
|
36
|
+
category: z.ZodString;
|
|
37
|
+
description: z.ZodNullable<z.ZodString>;
|
|
38
|
+
order: z.ZodNumber;
|
|
39
|
+
keybind: z.ZodNullable<z.ZodString>;
|
|
40
|
+
availability: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
41
|
+
status: z.ZodLiteral<"available">;
|
|
42
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
43
|
+
status: z.ZodLiteral<"unavailable">;
|
|
44
|
+
reason: z.ZodString;
|
|
45
|
+
}, z.core.$strip>], "status">;
|
|
46
|
+
}, z.core.$strict>]>;
|
|
47
|
+
export declare const BrowserExecuteInputSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
48
|
+
commandId: z.ZodString;
|
|
49
|
+
arguments: z.ZodJSONSchema;
|
|
50
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
51
|
+
commandId: z.ZodString;
|
|
52
|
+
}, z.core.$strict>]>;
|
|
53
|
+
declare const BrowserRequestSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
54
|
+
type: z.ZodLiteral<"discover">;
|
|
55
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
56
|
+
commandId: z.ZodString;
|
|
57
|
+
arguments: z.ZodJSONSchema;
|
|
58
|
+
type: z.ZodLiteral<"execute">;
|
|
59
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
60
|
+
commandId: z.ZodString;
|
|
61
|
+
type: z.ZodLiteral<"execute">;
|
|
62
|
+
}, z.core.$strict>]>;
|
|
63
|
+
declare const BrowserRequestEnvelopeSchema: z.ZodObject<{
|
|
64
|
+
requestId: z.ZodString;
|
|
65
|
+
request: z.ZodUnion<readonly [z.ZodObject<{
|
|
66
|
+
type: z.ZodLiteral<"discover">;
|
|
67
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
68
|
+
commandId: z.ZodString;
|
|
69
|
+
arguments: z.ZodJSONSchema;
|
|
70
|
+
type: z.ZodLiteral<"execute">;
|
|
71
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
72
|
+
commandId: z.ZodString;
|
|
73
|
+
type: z.ZodLiteral<"execute">;
|
|
74
|
+
}, z.core.$strict>]>;
|
|
75
|
+
}, z.core.$strip>;
|
|
76
|
+
export declare const BrowserRequestDeliverySchema: z.ZodObject<{
|
|
77
|
+
requestId: z.ZodString;
|
|
78
|
+
request: z.ZodUnion<readonly [z.ZodObject<{
|
|
79
|
+
type: z.ZodLiteral<"discover">;
|
|
80
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
81
|
+
commandId: z.ZodString;
|
|
82
|
+
arguments: z.ZodJSONSchema;
|
|
83
|
+
type: z.ZodLiteral<"execute">;
|
|
84
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
85
|
+
commandId: z.ZodString;
|
|
86
|
+
type: z.ZodLiteral<"execute">;
|
|
87
|
+
}, z.core.$strict>]>;
|
|
88
|
+
connectionId: z.ZodString;
|
|
89
|
+
}, z.core.$strip>;
|
|
90
|
+
export declare const BrowserClaimSchema: z.ZodObject<{
|
|
91
|
+
requestId: z.ZodString;
|
|
92
|
+
connectionId: z.ZodString;
|
|
93
|
+
attemptId: z.ZodString;
|
|
94
|
+
}, z.core.$strip>;
|
|
95
|
+
export declare const BrowserClaimResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
96
|
+
status: z.ZodLiteral<"claimed">;
|
|
97
|
+
claimId: z.ZodString;
|
|
98
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
99
|
+
status: z.ZodLiteral<"waiting">;
|
|
100
|
+
retryAfterMs: z.ZodNumber;
|
|
101
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
102
|
+
status: z.ZodLiteral<"skipped">;
|
|
103
|
+
}, z.core.$strip>], "status">;
|
|
104
|
+
export declare const BrowserExecutionOutcomeSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
105
|
+
status: z.ZodLiteral<"handled">;
|
|
106
|
+
result: z.ZodJSONSchema;
|
|
107
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
108
|
+
status: z.ZodLiteral<"handled">;
|
|
109
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
110
|
+
status: z.ZodLiteral<"closed">;
|
|
111
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
112
|
+
status: z.ZodLiteral<"missing">;
|
|
113
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
114
|
+
status: z.ZodLiteral<"invalid">;
|
|
115
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
116
|
+
status: z.ZodLiteral<"unavailable">;
|
|
117
|
+
reason: z.ZodString;
|
|
118
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
119
|
+
status: z.ZodLiteral<"failed">;
|
|
120
|
+
error: z.ZodObject<{
|
|
121
|
+
code: z.ZodString;
|
|
122
|
+
message: z.ZodString;
|
|
123
|
+
details: z.ZodJSONSchema;
|
|
124
|
+
}, z.core.$strip>;
|
|
125
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
126
|
+
status: z.ZodLiteral<"failed">;
|
|
127
|
+
error: z.ZodObject<{
|
|
128
|
+
code: z.ZodString;
|
|
129
|
+
message: z.ZodString;
|
|
130
|
+
}, z.core.$strict>;
|
|
131
|
+
}, z.core.$strict>]>;
|
|
132
|
+
declare const BrowserWireResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
133
|
+
type: z.ZodLiteral<"discover">;
|
|
134
|
+
commands: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
135
|
+
action: z.ZodUnion<readonly [z.ZodObject<{
|
|
136
|
+
inputSchema: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
137
|
+
outputSchema: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
138
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
139
|
+
inputSchema: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
140
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
141
|
+
outputSchema: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
142
|
+
}, z.core.$strict>]>;
|
|
143
|
+
commandId: z.ZodString;
|
|
144
|
+
sourceId: z.ZodString;
|
|
145
|
+
title: z.ZodString;
|
|
146
|
+
category: z.ZodString;
|
|
147
|
+
description: z.ZodNullable<z.ZodString>;
|
|
148
|
+
order: z.ZodNumber;
|
|
149
|
+
keybind: z.ZodNullable<z.ZodString>;
|
|
150
|
+
availability: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
151
|
+
status: z.ZodLiteral<"available">;
|
|
152
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
153
|
+
status: z.ZodLiteral<"unavailable">;
|
|
154
|
+
reason: z.ZodString;
|
|
155
|
+
}, z.core.$strip>], "status">;
|
|
156
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
157
|
+
commandId: z.ZodString;
|
|
158
|
+
sourceId: z.ZodString;
|
|
159
|
+
title: z.ZodString;
|
|
160
|
+
category: z.ZodString;
|
|
161
|
+
description: z.ZodNullable<z.ZodString>;
|
|
162
|
+
order: z.ZodNumber;
|
|
163
|
+
keybind: z.ZodNullable<z.ZodString>;
|
|
164
|
+
availability: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
165
|
+
status: z.ZodLiteral<"available">;
|
|
166
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
167
|
+
status: z.ZodLiteral<"unavailable">;
|
|
168
|
+
reason: z.ZodString;
|
|
169
|
+
}, z.core.$strip>], "status">;
|
|
170
|
+
}, z.core.$strict>]>>;
|
|
171
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
172
|
+
type: z.ZodLiteral<"execute">;
|
|
173
|
+
outcome: z.ZodUnion<readonly [z.ZodObject<{
|
|
174
|
+
status: z.ZodLiteral<"handled">;
|
|
175
|
+
result: z.ZodJSONSchema;
|
|
176
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
177
|
+
status: z.ZodLiteral<"handled">;
|
|
178
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
179
|
+
status: z.ZodLiteral<"closed">;
|
|
180
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
181
|
+
status: z.ZodLiteral<"missing">;
|
|
182
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
183
|
+
status: z.ZodLiteral<"invalid">;
|
|
184
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
185
|
+
status: z.ZodLiteral<"unavailable">;
|
|
186
|
+
reason: z.ZodString;
|
|
187
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
188
|
+
status: z.ZodLiteral<"failed">;
|
|
189
|
+
error: z.ZodObject<{
|
|
190
|
+
code: z.ZodString;
|
|
191
|
+
message: z.ZodString;
|
|
192
|
+
details: z.ZodJSONSchema;
|
|
193
|
+
}, z.core.$strip>;
|
|
194
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
195
|
+
status: z.ZodLiteral<"failed">;
|
|
196
|
+
error: z.ZodObject<{
|
|
197
|
+
code: z.ZodString;
|
|
198
|
+
message: z.ZodString;
|
|
199
|
+
}, z.core.$strict>;
|
|
200
|
+
}, z.core.$strict>]>;
|
|
201
|
+
}, z.core.$strip>], "type">;
|
|
202
|
+
export declare const BrowserResultEnvelopeSchema: z.ZodObject<{
|
|
203
|
+
requestId: z.ZodString;
|
|
204
|
+
claimId: z.ZodString;
|
|
205
|
+
result: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
206
|
+
type: z.ZodLiteral<"discover">;
|
|
207
|
+
commands: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
208
|
+
action: z.ZodUnion<readonly [z.ZodObject<{
|
|
209
|
+
inputSchema: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
210
|
+
outputSchema: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
211
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
212
|
+
inputSchema: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
213
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
214
|
+
outputSchema: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
215
|
+
}, z.core.$strict>]>;
|
|
216
|
+
commandId: z.ZodString;
|
|
217
|
+
sourceId: z.ZodString;
|
|
218
|
+
title: z.ZodString;
|
|
219
|
+
category: z.ZodString;
|
|
220
|
+
description: z.ZodNullable<z.ZodString>;
|
|
221
|
+
order: z.ZodNumber;
|
|
222
|
+
keybind: z.ZodNullable<z.ZodString>;
|
|
223
|
+
availability: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
224
|
+
status: z.ZodLiteral<"available">;
|
|
225
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
226
|
+
status: z.ZodLiteral<"unavailable">;
|
|
227
|
+
reason: z.ZodString;
|
|
228
|
+
}, z.core.$strip>], "status">;
|
|
229
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
230
|
+
commandId: z.ZodString;
|
|
231
|
+
sourceId: z.ZodString;
|
|
232
|
+
title: z.ZodString;
|
|
233
|
+
category: z.ZodString;
|
|
234
|
+
description: z.ZodNullable<z.ZodString>;
|
|
235
|
+
order: z.ZodNumber;
|
|
236
|
+
keybind: z.ZodNullable<z.ZodString>;
|
|
237
|
+
availability: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
238
|
+
status: z.ZodLiteral<"available">;
|
|
239
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
240
|
+
status: z.ZodLiteral<"unavailable">;
|
|
241
|
+
reason: z.ZodString;
|
|
242
|
+
}, z.core.$strip>], "status">;
|
|
243
|
+
}, z.core.$strict>]>>;
|
|
244
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
245
|
+
type: z.ZodLiteral<"execute">;
|
|
246
|
+
outcome: z.ZodUnion<readonly [z.ZodObject<{
|
|
247
|
+
status: z.ZodLiteral<"handled">;
|
|
248
|
+
result: z.ZodJSONSchema;
|
|
249
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
250
|
+
status: z.ZodLiteral<"handled">;
|
|
251
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
252
|
+
status: z.ZodLiteral<"closed">;
|
|
253
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
254
|
+
status: z.ZodLiteral<"missing">;
|
|
255
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
256
|
+
status: z.ZodLiteral<"invalid">;
|
|
257
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
258
|
+
status: z.ZodLiteral<"unavailable">;
|
|
259
|
+
reason: z.ZodString;
|
|
260
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
261
|
+
status: z.ZodLiteral<"failed">;
|
|
262
|
+
error: z.ZodObject<{
|
|
263
|
+
code: z.ZodString;
|
|
264
|
+
message: z.ZodString;
|
|
265
|
+
details: z.ZodJSONSchema;
|
|
266
|
+
}, z.core.$strip>;
|
|
267
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
268
|
+
status: z.ZodLiteral<"failed">;
|
|
269
|
+
error: z.ZodObject<{
|
|
270
|
+
code: z.ZodString;
|
|
271
|
+
message: z.ZodString;
|
|
272
|
+
}, z.core.$strict>;
|
|
273
|
+
}, z.core.$strict>]>;
|
|
274
|
+
}, z.core.$strip>], "type">;
|
|
275
|
+
}, z.core.$strip>;
|
|
276
|
+
export declare const BrowserSettlementResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
277
|
+
status: z.ZodLiteral<"accepted">;
|
|
278
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
279
|
+
status: z.ZodLiteral<"ignored">;
|
|
280
|
+
}, z.core.$strip>], "status">;
|
|
281
|
+
export type BrowserCommandRow = z.output<typeof BrowserCommandRowSchema>;
|
|
282
|
+
export type BrowserRequest = z.output<typeof BrowserRequestSchema>;
|
|
283
|
+
export type BrowserRequestEnvelope = z.output<typeof BrowserRequestEnvelopeSchema>;
|
|
284
|
+
export type BrowserRequestDelivery = z.output<typeof BrowserRequestDeliverySchema>;
|
|
285
|
+
export type BrowserClaim = z.output<typeof BrowserClaimSchema>;
|
|
286
|
+
export type BrowserClaimResult = z.output<typeof BrowserClaimResultSchema>;
|
|
287
|
+
export type BrowserWireResult = z.output<typeof BrowserWireResultSchema>;
|
|
288
|
+
export type BrowserResultEnvelope = z.output<typeof BrowserResultEnvelopeSchema>;
|
|
289
|
+
export type BrowserSettlementResult = z.output<typeof BrowserSettlementResultSchema>;
|
|
290
|
+
export {};
|
package/dist/ui/wire.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { defineIdFamily } from "@fungi.computer/cairn";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
export const uiWireIds = defineIdFamily({
|
|
4
|
+
family: "knapsack-ui",
|
|
5
|
+
version: 1,
|
|
6
|
+
kinds: {
|
|
7
|
+
request: { prefix: "ui_request" },
|
|
8
|
+
connection: { prefix: "ui_connection" },
|
|
9
|
+
claim: { prefix: "ui_claim" },
|
|
10
|
+
attempt: { prefix: "ui_attempt" },
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
const identifier = z.string().min(1).max(256);
|
|
14
|
+
const requestId = z
|
|
15
|
+
.string()
|
|
16
|
+
.refine((value) => uiWireIds.request.parse(value).ok);
|
|
17
|
+
const json = z.json();
|
|
18
|
+
const schemaDocument = z.record(z.string(), json);
|
|
19
|
+
export const BrowserWireObjectSchema = z.record(z.string(), z.unknown());
|
|
20
|
+
const WhistleAvailabilitySchema = z.discriminatedUnion("status", [
|
|
21
|
+
z.object({ status: z.literal("available") }),
|
|
22
|
+
z.object({ status: z.literal("unavailable"), reason: z.string() }),
|
|
23
|
+
]);
|
|
24
|
+
/** The same descriptor is decoded at browser ingress and in model tool results. */
|
|
25
|
+
const browserCommandRowFields = {
|
|
26
|
+
commandId: identifier,
|
|
27
|
+
sourceId: identifier,
|
|
28
|
+
title: z.string(),
|
|
29
|
+
category: z.string(),
|
|
30
|
+
description: z.string().nullable(),
|
|
31
|
+
order: z.number(),
|
|
32
|
+
keybind: z.string().nullable(),
|
|
33
|
+
availability: WhistleAvailabilitySchema,
|
|
34
|
+
};
|
|
35
|
+
const browserActionSchema = z.union([
|
|
36
|
+
z
|
|
37
|
+
.object({ inputSchema: schemaDocument, outputSchema: schemaDocument })
|
|
38
|
+
.strict(),
|
|
39
|
+
z.object({ inputSchema: schemaDocument }).strict(),
|
|
40
|
+
z.object({ outputSchema: schemaDocument }).strict(),
|
|
41
|
+
]);
|
|
42
|
+
const browserCommandRowWithActionSchema = z
|
|
43
|
+
.object({ ...browserCommandRowFields, action: browserActionSchema })
|
|
44
|
+
.strict();
|
|
45
|
+
const browserCommandRowWithoutActionSchema = z
|
|
46
|
+
.object(browserCommandRowFields)
|
|
47
|
+
.strict();
|
|
48
|
+
export const BrowserCommandRowSchema = z.union([
|
|
49
|
+
browserCommandRowWithActionSchema,
|
|
50
|
+
browserCommandRowWithoutActionSchema,
|
|
51
|
+
]);
|
|
52
|
+
const browserExecuteCommandSchema = z.object({
|
|
53
|
+
commandId: z.string().max(256),
|
|
54
|
+
});
|
|
55
|
+
const browserExecuteInputWireSchema = browserExecuteCommandSchema
|
|
56
|
+
.extend({ arguments: json })
|
|
57
|
+
.strict();
|
|
58
|
+
const browserExecuteInputWithoutArgumentsSchema = browserExecuteCommandSchema.strict();
|
|
59
|
+
export const BrowserExecuteInputSchema = z.union([
|
|
60
|
+
browserExecuteInputWireSchema,
|
|
61
|
+
browserExecuteInputWithoutArgumentsSchema,
|
|
62
|
+
]);
|
|
63
|
+
const BrowserRequestSchema = z.union([
|
|
64
|
+
z.object({ type: z.literal("discover") }).strict(),
|
|
65
|
+
browserExecuteInputWireSchema.extend({ type: z.literal("execute") }),
|
|
66
|
+
browserExecuteInputWithoutArgumentsSchema.extend({
|
|
67
|
+
type: z.literal("execute"),
|
|
68
|
+
}),
|
|
69
|
+
]);
|
|
70
|
+
const BrowserRequestEnvelopeSchema = z.object({
|
|
71
|
+
requestId,
|
|
72
|
+
request: BrowserRequestSchema,
|
|
73
|
+
});
|
|
74
|
+
export const BrowserRequestDeliverySchema = BrowserRequestEnvelopeSchema.extend({
|
|
75
|
+
connectionId: z
|
|
76
|
+
.string()
|
|
77
|
+
.refine((value) => uiWireIds.connection.parse(value).ok),
|
|
78
|
+
});
|
|
79
|
+
export const BrowserClaimSchema = z.object({
|
|
80
|
+
requestId,
|
|
81
|
+
connectionId: z
|
|
82
|
+
.string()
|
|
83
|
+
.refine((value) => uiWireIds.connection.parse(value).ok),
|
|
84
|
+
attemptId: z.string().refine((value) => uiWireIds.attempt.parse(value).ok),
|
|
85
|
+
});
|
|
86
|
+
export const BrowserClaimResultSchema = z.discriminatedUnion("status", [
|
|
87
|
+
z.object({ status: z.literal("claimed"), claimId: z.string() }),
|
|
88
|
+
z.object({
|
|
89
|
+
status: z.literal("waiting"),
|
|
90
|
+
retryAfterMs: z.number().int().min(10).max(1_000),
|
|
91
|
+
}),
|
|
92
|
+
z.object({ status: z.literal("skipped") }),
|
|
93
|
+
]);
|
|
94
|
+
export const BrowserExecutionOutcomeSchema = z.union([
|
|
95
|
+
z.object({ status: z.literal("handled"), result: json }).strict(),
|
|
96
|
+
z.object({ status: z.literal("handled") }).strict(),
|
|
97
|
+
z.object({ status: z.literal("closed") }).strict(),
|
|
98
|
+
z.object({ status: z.literal("missing") }).strict(),
|
|
99
|
+
z.object({ status: z.literal("invalid") }).strict(),
|
|
100
|
+
z.object({ status: z.literal("unavailable"), reason: z.string() }).strict(),
|
|
101
|
+
z
|
|
102
|
+
.object({
|
|
103
|
+
status: z.literal("failed"),
|
|
104
|
+
error: z.object({
|
|
105
|
+
code: z.string(),
|
|
106
|
+
message: z.string(),
|
|
107
|
+
details: json,
|
|
108
|
+
}),
|
|
109
|
+
})
|
|
110
|
+
.strict(),
|
|
111
|
+
z
|
|
112
|
+
.object({
|
|
113
|
+
status: z.literal("failed"),
|
|
114
|
+
error: z.object({ code: z.string(), message: z.string() }).strict(),
|
|
115
|
+
})
|
|
116
|
+
.strict(),
|
|
117
|
+
]);
|
|
118
|
+
const BrowserWireResultSchema = z.discriminatedUnion("type", [
|
|
119
|
+
z.object({
|
|
120
|
+
type: z.literal("discover"),
|
|
121
|
+
commands: z.array(BrowserCommandRowSchema),
|
|
122
|
+
}),
|
|
123
|
+
z.object({
|
|
124
|
+
type: z.literal("execute"),
|
|
125
|
+
outcome: BrowserExecutionOutcomeSchema,
|
|
126
|
+
}),
|
|
127
|
+
]);
|
|
128
|
+
export const BrowserResultEnvelopeSchema = z.object({
|
|
129
|
+
requestId,
|
|
130
|
+
claimId: z.string().refine((value) => uiWireIds.claim.parse(value).ok),
|
|
131
|
+
result: BrowserWireResultSchema,
|
|
132
|
+
});
|
|
133
|
+
export const BrowserSettlementResultSchema = z.discriminatedUnion("status", [
|
|
134
|
+
z.object({ status: z.literal("accepted") }),
|
|
135
|
+
z.object({ status: z.literal("ignored") }),
|
|
136
|
+
]);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser side of Knapsack.ui: connect the App's Whistle runtime to one Agent
|
|
3
|
+
* Session's `/browser/*` transport so the Agent can discover and run its
|
|
4
|
+
* live commands.
|
|
5
|
+
*/
|
|
6
|
+
export { connectBrowser, UiBrowserError, type BrowserConnection, type BrowserConnectionOptions, } from "./ui/browser.js";
|
package/dist/ui.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CapabilitySource } from "@fungi.computer/mycelium";
|
|
2
|
+
/** How one Agent host connects its Sessions' open Apps to Knapsack.ui. */
|
|
3
|
+
export type UiConnectionOptions = Readonly<{
|
|
4
|
+
/** Stable, secret-free capability source id, such as `"hub-ui"`. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** Whether the Session is stored; only a stored Session's browser may connect. */
|
|
7
|
+
hasSession: (sessionId: string) => Promise<boolean>;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* Live commands of the App open in each Agent Session's browser. The Agent
|
|
11
|
+
* reaches them through the `ui` module (`ui.discover`, `ui.execute`); the
|
|
12
|
+
* browser runs them through Whistle over the transport this connection serves.
|
|
13
|
+
*/
|
|
14
|
+
export type UiConnection = Readonly<{
|
|
15
|
+
/**
|
|
16
|
+
* Each Session run borrows its Session's `ui` module and releases it when
|
|
17
|
+
* the run ends. A Session-free acquisition contributes no module.
|
|
18
|
+
*/
|
|
19
|
+
source: CapabilitySource;
|
|
20
|
+
/**
|
|
21
|
+
* Serve `/browser/sessions/<sessionId>/browser/{events,claims,results}`.
|
|
22
|
+
* It authenticates nobody: mount it behind the host's own authorization.
|
|
23
|
+
*/
|
|
24
|
+
fetch: (request: Request) => Promise<Response>;
|
|
25
|
+
/** End every browser stream; later requests answer 410 and later borrows fail. */
|
|
26
|
+
close: () => Promise<void>;
|
|
27
|
+
}>;
|
|
28
|
+
/** Connect the open App's live Whistle commands to each Agent Session. */
|
|
29
|
+
export declare function ui(options: UiConnectionOptions): UiConnection;
|
package/dist/ui.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createUiHost } from "./ui/host.js";
|
|
2
|
+
import { BrowserSessions } from "./ui/sessions.js";
|
|
3
|
+
/** Borrow one Session's `ui` module for the acquiring run. */
|
|
4
|
+
function borrow(sessions, context) {
|
|
5
|
+
context.signal.throwIfAborted();
|
|
6
|
+
if (context.session === undefined)
|
|
7
|
+
return {
|
|
8
|
+
snapshot: { version: "no-session", modules: [] },
|
|
9
|
+
release: () => Promise.resolve(),
|
|
10
|
+
};
|
|
11
|
+
const sessionId = context.session.sessionId;
|
|
12
|
+
const lease = sessions.acquire(sessionId);
|
|
13
|
+
return {
|
|
14
|
+
snapshot: { version: `session:${sessionId}`, modules: lease.modules },
|
|
15
|
+
release: () => {
|
|
16
|
+
lease.release();
|
|
17
|
+
return Promise.resolve();
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Connect the open App's live Whistle commands to each Agent Session. */
|
|
22
|
+
export function ui(options) {
|
|
23
|
+
const sessions = new BrowserSessions(() => createUiHost(), options.hasSession);
|
|
24
|
+
return Object.freeze({
|
|
25
|
+
source: {
|
|
26
|
+
id: options.id,
|
|
27
|
+
// The executor turns a refused borrow (aborted, or closed) into a rejection.
|
|
28
|
+
acquire: (context) => new Promise((resolve) => {
|
|
29
|
+
resolve(borrow(sessions, context));
|
|
30
|
+
}),
|
|
31
|
+
},
|
|
32
|
+
fetch: (request) => sessions.fetch(request),
|
|
33
|
+
close: () => sessions.close(),
|
|
34
|
+
});
|
|
35
|
+
}
|
package/docs/api/README.md
CHANGED
package/docs/api/files-patch.md
CHANGED
|
@@ -13,11 +13,13 @@
|
|
|
13
13
|
### patchInputSchema
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
-
const patchInputSchema:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const patchInputSchema: ZodLazy<
|
|
17
|
+
ZodObject<
|
|
18
|
+
{
|
|
19
|
+
patch: ZodString;
|
|
20
|
+
},
|
|
21
|
+
$strict
|
|
22
|
+
>
|
|
21
23
|
>;
|
|
22
24
|
```
|
|
23
25
|
|
|
@@ -28,44 +30,38 @@ Browser-safe patch contracts shared by native Files tools and Computer HTTP.
|
|
|
28
30
|
### patchOutputSchema
|
|
29
31
|
|
|
30
32
|
```ts
|
|
31
|
-
const patchOutputSchema: ZodUnion<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
>;
|
|
64
|
-
},
|
|
65
|
-
$strict
|
|
66
|
-
>,
|
|
67
|
-
]
|
|
68
|
-
>;
|
|
33
|
+
const patchOutputSchema: ZodLazy<ZodUnion<readonly [ZodObject<{
|
|
34
|
+
status: ZodEnum<{
|
|
35
|
+
completed: "completed";
|
|
36
|
+
failed: "failed";
|
|
37
|
+
cancelled: "cancelled";
|
|
38
|
+
}>;
|
|
39
|
+
exitCode: ZodNumber;
|
|
40
|
+
stdout: ZodString;
|
|
41
|
+
stderr: ZodString;
|
|
42
|
+
truncated: ZodUnion<readonly [ZodLiteral<false>, ZodArray<ZodObject<{
|
|
43
|
+
stream: ZodEnum<...>;
|
|
44
|
+
keptBytes: ZodNumber;
|
|
45
|
+
totalBytes: ZodNumber;
|
|
46
|
+
}, $strict>>]>;
|
|
47
|
+
}, $strict>, ZodObject<{
|
|
48
|
+
status: ZodEnum<{
|
|
49
|
+
completed: "completed";
|
|
50
|
+
failed: "failed";
|
|
51
|
+
cancelled: "cancelled";
|
|
52
|
+
}>;
|
|
53
|
+
exitCode: ZodNumber;
|
|
54
|
+
stdout: ZodString;
|
|
55
|
+
stderr: ZodString;
|
|
56
|
+
truncated: ZodUnion<readonly [ZodLiteral<false>, ZodArray<ZodObject<{
|
|
57
|
+
stream: ZodEnum<...>;
|
|
58
|
+
keptBytes: ZodNumber;
|
|
59
|
+
totalBytes: ZodNumber;
|
|
60
|
+
}, $strict>>]>;
|
|
61
|
+
error: ZodObject<{
|
|
62
|
+
kind: ZodLiteral<"mismatch">;
|
|
63
|
+
}, $strict>;
|
|
64
|
+
}, $strict>]>>;
|
|
69
65
|
```
|
|
70
66
|
|
|
71
67
|
Native patch completion, cancellation or failure, including an optional
|