@stitchmux/client 0.0.0-stage → 0.96.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +45 -2
- package/dist/chunk-szdg2ww3.js +714 -0
- package/dist/index.js +4070 -0
- package/dist/monitoring.js +279 -0
- package/native-stream.json +8 -0
- package/package.json +36 -4
- package/types/src/agent/claude/native/commandSchema.d.ts +14 -0
- package/types/src/agent/custom/config.d.ts +159 -0
- package/types/src/agent/custom/endpoint.d.ts +26 -0
- package/types/src/agent/transcript/messageSchema.d.ts +153 -0
- package/types/src/attachments/reference.d.ts +56 -0
- package/types/src/attachments/schema.d.ts +512 -0
- package/types/src/chat/communicationAuthorizationSchema.d.ts +77 -0
- package/types/src/chat/communicationReceiptSchema.d.ts +82 -0
- package/types/src/chat/feedSchema.d.ts +641 -0
- package/types/src/chat/holdKind.d.ts +26 -0
- package/types/src/chat/identity.d.ts +55 -0
- package/types/src/chat/identitySchema.d.ts +121 -0
- package/types/src/chat/letterRequestSchema.d.ts +35 -0
- package/types/src/chat/messageOperationSchema.d.ts +277 -0
- package/types/src/chat/messageSchema.d.ts +284 -0
- package/types/src/chat/originSchema.d.ts +67 -0
- package/types/src/chat/sentLetterSchema.d.ts +79 -0
- package/types/src/client.d.ts +16 -0
- package/types/src/config/claudeProfileSchema.d.ts +22 -0
- package/types/src/config/launchSchema.d.ts +136 -0
- package/types/src/config/location.d.ts +6 -0
- package/types/src/config/machineSchema.d.ts +320 -0
- package/types/src/config/modelSelectionFlags.d.ts +4 -0
- package/types/src/config/paths.d.ts +87 -0
- package/types/src/config/remoteTransport.d.ts +12 -0
- package/types/src/content/schema.d.ts +312 -0
- package/types/src/content/toolSchema.d.ts +36 -0
- package/types/src/context/corpusSearchSchema.d.ts +578 -0
- package/types/src/context/exactMessageSchema.d.ts +54 -0
- package/types/src/context/messageSenderSchema.d.ts +14 -0
- package/types/src/context/schema.d.ts +176 -0
- package/types/src/context/searchFrames.d.ts +225 -0
- package/types/src/context/searchRequestSchema.d.ts +47 -0
- package/types/src/context/transcriptJsonSchema.d.ts +210 -0
- package/types/src/control/schema/context.d.ts +188 -0
- package/types/src/control/schema/contract.d.ts +7142 -0
- package/types/src/control/schema/core.d.ts +722 -0
- package/types/src/control/schema/directory.d.ts +34 -0
- package/types/src/control/schema/eventsContract.d.ts +1423 -0
- package/types/src/control/schema/externalList.d.ts +96 -0
- package/types/src/control/schema/message.d.ts +280 -0
- package/types/src/control/schema/model.d.ts +128 -0
- package/types/src/control/schema/native.d.ts +664 -0
- package/types/src/control/schema/nativeStreamContract.d.ts +155 -0
- package/types/src/control/schema/performance.d.ts +85 -0
- package/types/src/control/schema/public.d.ts +48 -0
- package/types/src/control/schema/reading.d.ts +24 -0
- package/types/src/control/schema/refusals.d.ts +433 -0
- package/types/src/control/schema/runtimeOps.d.ts +724 -0
- package/types/src/control/schema/searchContract.d.ts +258 -0
- package/types/src/control/schema/selection.d.ts +124 -0
- package/types/src/control/schema/session.d.ts +272 -0
- package/types/src/control/schema/terminalPrompt.d.ts +102 -0
- package/types/src/control/transport/boundary.d.ts +7137 -0
- package/types/src/control/transport/client.d.ts +10838 -0
- package/types/src/control/transport/connection.d.ts +13 -0
- package/types/src/control/transport/socketPath.d.ts +3 -0
- package/types/src/control-client.d.ts +9 -0
- package/types/src/delegation/applicationSchema.d.ts +132 -0
- package/types/src/delegation/schema.d.ts +267 -0
- package/types/src/events/schema.d.ts +155 -0
- package/types/src/external/contentSchema.d.ts +145 -0
- package/types/src/external/messageSchema.d.ts +131 -0
- package/types/src/external/residentFrames.d.ts +130 -0
- package/types/src/external/residentSchema.d.ts +144 -0
- package/types/src/external/sessionSchema.d.ts +427 -0
- package/types/src/external/turnSchema.d.ts +55 -0
- package/types/src/fleet/fleetSchema.d.ts +937 -0
- package/types/src/inventory/listSchema.d.ts +442 -0
- package/types/src/monitoring/nativeFile.d.ts +7 -0
- package/types/src/monitoring/nativeRead.d.ts +14 -0
- package/types/src/monitoring/performanceSchema.d.ts +28 -0
- package/types/src/monitoring/schema.d.ts +410 -0
- package/types/src/monitoring/validate.d.ts +5 -0
- package/types/src/monitoring-reader.d.ts +4 -0
- package/types/src/policy/reference.d.ts +93 -0
- package/types/src/policy/runtimeProfile.d.ts +24 -0
- package/types/src/policy/schema.d.ts +177 -0
- package/types/src/runtime/capabilities.d.ts +124 -0
- package/types/src/runtime/modes.d.ts +47 -0
- package/types/src/runtime/permissionScope.d.ts +22 -0
- package/types/src/runtime/planLimitsSchema.d.ts +55 -0
- package/types/src/runtime/projectionSchema.d.ts +539 -0
- package/types/src/runtime/rewindSchema.d.ts +16 -0
- package/types/src/runtime/selectionSchema.d.ts +158 -0
- package/types/src/runtime/workloadContract.d.ts +55 -0
- package/types/src/session/boundary.d.ts +43 -0
- package/types/src/session/identitySchema.d.ts +353 -0
- package/types/src/session/schema.d.ts +341 -0
- package/types/src/session/sleep/schema.d.ts +283 -0
- package/types/src/steering/schema.d.ts +197 -0
- package/types/src/types.d.ts +48 -0
- package/types/src/usage/schema.d.ts +978 -0
- package/types/src/util/home.d.ts +9 -0
- package/types/src/util/preview.d.ts +13 -0
- package/types/src/util/version.d.ts +3 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
AgentKindSchema,
|
|
4
|
+
monitoringStatusPath,
|
|
5
|
+
machineConfigPath,
|
|
6
|
+
resolveMonitoringLocation,
|
|
7
|
+
VERSION
|
|
8
|
+
} from "./chunk-szdg2ww3.js";
|
|
9
|
+
|
|
10
|
+
// src/monitoring/nativeRead.ts
|
|
11
|
+
import { z as z3 } from "zod";
|
|
12
|
+
|
|
13
|
+
// src/monitoring/nativeFile.ts
|
|
14
|
+
import { constants } from "fs";
|
|
15
|
+
import { open } from "fs/promises";
|
|
16
|
+
|
|
17
|
+
class MonitoringFileError extends Error {
|
|
18
|
+
reason;
|
|
19
|
+
constructor(reason) {
|
|
20
|
+
super(reason);
|
|
21
|
+
this.reason = reason;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function readBoundedFile(path, limit) {
|
|
25
|
+
const file = await open(path, constants.O_RDONLY | constants.O_NONBLOCK | constants.O_NOFOLLOW).catch((error) => {
|
|
26
|
+
throw new MonitoringFileError(error instanceof Error && "code" in error && error.code === "ENOENT" ? "missing" : "read-failed");
|
|
27
|
+
});
|
|
28
|
+
try {
|
|
29
|
+
const stat = await file.stat();
|
|
30
|
+
if (!stat.isFile())
|
|
31
|
+
throw new MonitoringFileError("invalid");
|
|
32
|
+
if (stat.uid !== process.getuid?.() || (stat.mode & 18) !== 0)
|
|
33
|
+
throw new MonitoringFileError("unauthorized");
|
|
34
|
+
if (stat.size > limit)
|
|
35
|
+
throw new MonitoringFileError("oversized");
|
|
36
|
+
const bytes = Buffer.alloc(limit + 1);
|
|
37
|
+
let length = 0;
|
|
38
|
+
while (length < bytes.length) {
|
|
39
|
+
const { bytesRead } = await file.read(bytes, length, bytes.length - length, length);
|
|
40
|
+
if (bytesRead === 0)
|
|
41
|
+
break;
|
|
42
|
+
length += bytesRead;
|
|
43
|
+
}
|
|
44
|
+
if (length > limit)
|
|
45
|
+
throw new MonitoringFileError("oversized");
|
|
46
|
+
return bytes.toString("utf8", 0, length);
|
|
47
|
+
} finally {
|
|
48
|
+
await file.close();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/monitoring/schema.ts
|
|
53
|
+
import { z as z2 } from "zod";
|
|
54
|
+
|
|
55
|
+
// src/session/boundary.ts
|
|
56
|
+
import { observeProcessInstance, ProcessInstanceSchema } from "stitchkit/process";
|
|
57
|
+
import { z } from "zod";
|
|
58
|
+
var SessionBoundarySchema = z.object({
|
|
59
|
+
unit: z.string().min(1).max(256).nullable(),
|
|
60
|
+
roots: z.array(z.object({ pid: z.number().int().positive(), instance: ProcessInstanceSchema.nullable() })).max(4)
|
|
61
|
+
}).strict();
|
|
62
|
+
|
|
63
|
+
// src/monitoring/schema.ts
|
|
64
|
+
var STATUS_MAX_ITEMS = 256;
|
|
65
|
+
var STATUS_MAX_BYTES = 512 * 1024;
|
|
66
|
+
var STATUS_MAX_AGE_MS = 1e4;
|
|
67
|
+
var MonitoringStepSchema = z2.object({
|
|
68
|
+
kind: z2.string().min(1).max(64),
|
|
69
|
+
role: z2.string().min(1).max(64),
|
|
70
|
+
toolName: z2.string().min(1).max(256).nullable(),
|
|
71
|
+
at: z2.string().min(1).max(64).nullable()
|
|
72
|
+
});
|
|
73
|
+
var MonitoringRowSchema = z2.object({
|
|
74
|
+
plane: z2.literal("managed"),
|
|
75
|
+
name: z2.string().min(1).max(256),
|
|
76
|
+
agent: AgentKindSchema,
|
|
77
|
+
uuid: z2.uuid(),
|
|
78
|
+
rc: z2.string().max(512),
|
|
79
|
+
address: z2.string().max(512),
|
|
80
|
+
dir: z2.string().max(8192),
|
|
81
|
+
archived: z2.boolean(),
|
|
82
|
+
running: z2.boolean(),
|
|
83
|
+
state: z2.enum(["working", "idle", "prompt", "stopped", "blocked", "unknown"]),
|
|
84
|
+
model: z2.string().max(512).nullable(),
|
|
85
|
+
contextPercent: z2.number().min(0).max(100).nullable(),
|
|
86
|
+
statusLineRendersPerMinute: z2.number().nonnegative().nullable(),
|
|
87
|
+
uptimeSeconds: z2.number().nonnegative().nullable(),
|
|
88
|
+
startedAt: z2.iso.datetime().nullable(),
|
|
89
|
+
lastActivityAt: z2.iso.datetime().nullable(),
|
|
90
|
+
turnStartedAt: z2.iso.datetime().nullable(),
|
|
91
|
+
step: MonitoringStepSchema.nullable(),
|
|
92
|
+
atPrompt: z2.string().min(1).max(256).nullable(),
|
|
93
|
+
waitingFor: z2.string().min(1).max(256).nullable(),
|
|
94
|
+
sleeping: z2.boolean(),
|
|
95
|
+
pinned: z2.boolean(),
|
|
96
|
+
memoryBytes: z2.number().int().nonnegative().nullable(),
|
|
97
|
+
registrationGeneration: z2.uuid().nullable(),
|
|
98
|
+
boundary: SessionBoundarySchema.nullable(),
|
|
99
|
+
observedAt: z2.iso.datetime()
|
|
100
|
+
});
|
|
101
|
+
var MonitoringRowReadSchema = MonitoringRowSchema.extend({
|
|
102
|
+
agent: z2.union([AgentKindSchema, z2.literal("unknown")]).catch("unknown"),
|
|
103
|
+
state: MonitoringRowSchema.shape.state.catch("unknown"),
|
|
104
|
+
startedAt: MonitoringRowSchema.shape.startedAt.optional(),
|
|
105
|
+
step: MonitoringRowSchema.shape.step.optional(),
|
|
106
|
+
atPrompt: MonitoringRowSchema.shape.atPrompt.optional(),
|
|
107
|
+
waitingFor: MonitoringRowSchema.shape.waitingFor.optional(),
|
|
108
|
+
sleeping: MonitoringRowSchema.shape.sleeping.optional(),
|
|
109
|
+
pinned: MonitoringRowSchema.shape.pinned.optional(),
|
|
110
|
+
memoryBytes: MonitoringRowSchema.shape.memoryBytes.optional(),
|
|
111
|
+
registrationGeneration: MonitoringRowSchema.shape.registrationGeneration.optional(),
|
|
112
|
+
boundary: MonitoringRowSchema.shape.boundary.optional()
|
|
113
|
+
});
|
|
114
|
+
var MonitoringSnapshotSchema = z2.object({
|
|
115
|
+
protocol: z2.literal(1),
|
|
116
|
+
version: z2.string().min(1).max(64),
|
|
117
|
+
generation: z2.uuid(),
|
|
118
|
+
sequence: z2.number().int().positive(),
|
|
119
|
+
pid: z2.number().int().positive(),
|
|
120
|
+
rcPrefix: z2.string().min(1).max(128),
|
|
121
|
+
scope: z2.literal("managed"),
|
|
122
|
+
observedAt: z2.iso.datetime(),
|
|
123
|
+
generatedAt: z2.iso.datetime(),
|
|
124
|
+
refreshDurationMs: z2.number().nonnegative(),
|
|
125
|
+
maxAgeMs: z2.literal(STATUS_MAX_AGE_MS),
|
|
126
|
+
limits: z2.object({ items: z2.literal(STATUS_MAX_ITEMS), bytes: z2.literal(STATUS_MAX_BYTES) }).strict(),
|
|
127
|
+
omitted: z2.number().int().nonnegative(),
|
|
128
|
+
sessions: z2.array(MonitoringRowSchema).max(STATUS_MAX_ITEMS)
|
|
129
|
+
});
|
|
130
|
+
var MonitoringSnapshotReadSchema = MonitoringSnapshotSchema.extend({
|
|
131
|
+
sessions: z2.array(MonitoringRowReadSchema).max(STATUS_MAX_ITEMS)
|
|
132
|
+
});
|
|
133
|
+
var MonitoringReadSchema = z2.object({
|
|
134
|
+
protocol: z2.literal(1),
|
|
135
|
+
status: z2.enum(["live", "stale", "unavailable"]),
|
|
136
|
+
reason: z2.enum([
|
|
137
|
+
"missing",
|
|
138
|
+
"invalid",
|
|
139
|
+
"oversized",
|
|
140
|
+
"producer-stopped",
|
|
141
|
+
"expired",
|
|
142
|
+
"clock-skew",
|
|
143
|
+
"read-failed",
|
|
144
|
+
"unauthorized",
|
|
145
|
+
"config-changed",
|
|
146
|
+
"cancelled",
|
|
147
|
+
"deadline",
|
|
148
|
+
"busy"
|
|
149
|
+
]).nullable(),
|
|
150
|
+
snapshot: MonitoringSnapshotReadSchema.nullable()
|
|
151
|
+
}).strict();
|
|
152
|
+
|
|
153
|
+
// src/monitoring/validate.ts
|
|
154
|
+
function unavailable(reason) {
|
|
155
|
+
return { protocol: 1, status: "unavailable", reason, snapshot: null };
|
|
156
|
+
}
|
|
157
|
+
function validateLiveness(snapshot, now = Date.now()) {
|
|
158
|
+
try {
|
|
159
|
+
process.kill(snapshot.pid, 0);
|
|
160
|
+
} catch {
|
|
161
|
+
return unavailable("producer-stopped");
|
|
162
|
+
}
|
|
163
|
+
const age = now - Date.parse(snapshot.observedAt);
|
|
164
|
+
if (age < 0)
|
|
165
|
+
return { protocol: 1, status: "stale", reason: "clock-skew", snapshot: null };
|
|
166
|
+
if (age > STATUS_MAX_AGE_MS)
|
|
167
|
+
return { protocol: 1, status: "stale", reason: "expired", snapshot: null };
|
|
168
|
+
return { protocol: 1, status: "live", reason: null, snapshot };
|
|
169
|
+
}
|
|
170
|
+
function validateSnapshot(bytes, rcPrefix, now = Date.now()) {
|
|
171
|
+
try {
|
|
172
|
+
const parsed = MonitoringSnapshotReadSchema.safeParse(JSON.parse(bytes));
|
|
173
|
+
if (!parsed.success || parsed.data.rcPrefix !== rcPrefix)
|
|
174
|
+
return unavailable("invalid");
|
|
175
|
+
return validateLiveness(parsed.data, now);
|
|
176
|
+
} catch {
|
|
177
|
+
return unavailable("invalid");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/monitoring/nativeRead.ts
|
|
182
|
+
var MONITORING_CONFIG_MAX_BYTES = 128 * 1024;
|
|
183
|
+
var MONITORING_MAX_READERS = 128;
|
|
184
|
+
var MONITORING_DEFAULT_TIMEOUT_MS = 250;
|
|
185
|
+
var MONITORING_MAX_TIMEOUT_MS = 1000;
|
|
186
|
+
var ReadOptionsSchema = z3.object({
|
|
187
|
+
signal: z3.instanceof(AbortSignal).optional(),
|
|
188
|
+
timeoutMs: z3.number().min(1).max(MONITORING_MAX_TIMEOUT_MS).optional()
|
|
189
|
+
}).strict();
|
|
190
|
+
var active;
|
|
191
|
+
var pending = new Set;
|
|
192
|
+
async function readConfig(path) {
|
|
193
|
+
try {
|
|
194
|
+
return await readBoundedFile(path, MONITORING_CONFIG_MAX_BYTES);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
if (error instanceof MonitoringFileError && error.reason === "missing")
|
|
197
|
+
return "{}";
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async function readOnce() {
|
|
202
|
+
try {
|
|
203
|
+
const configPath = machineConfigPath();
|
|
204
|
+
const config = await readConfig(configPath);
|
|
205
|
+
const location = resolveMonitoringLocation(JSON.parse(config));
|
|
206
|
+
const bytes = await readBoundedFile(monitoringStatusPath(location), STATUS_MAX_BYTES);
|
|
207
|
+
const after = await readConfig(configPath);
|
|
208
|
+
const next = resolveMonitoringLocation(JSON.parse(after));
|
|
209
|
+
if (configPath !== machineConfigPath() || config !== after || next.stateDir !== location.stateDir || next.rcPrefix !== location.rcPrefix) {
|
|
210
|
+
return unavailable("config-changed");
|
|
211
|
+
}
|
|
212
|
+
return validateSnapshot(bytes, location.rcPrefix);
|
|
213
|
+
} catch (error) {
|
|
214
|
+
return unavailable(error instanceof MonitoringFileError ? error.reason : "invalid");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function readMonitoringStatus(options = {}) {
|
|
218
|
+
const parsed = ReadOptionsSchema.safeParse(options);
|
|
219
|
+
if (!parsed.success)
|
|
220
|
+
return Promise.resolve(unavailable("invalid"));
|
|
221
|
+
options = parsed.data;
|
|
222
|
+
const timeoutMs = options.timeoutMs ?? MONITORING_DEFAULT_TIMEOUT_MS;
|
|
223
|
+
if (options.signal?.aborted)
|
|
224
|
+
return Promise.resolve(unavailable("cancelled"));
|
|
225
|
+
if (pending.size >= MONITORING_MAX_READERS)
|
|
226
|
+
return Promise.resolve(unavailable("busy"));
|
|
227
|
+
const deadline = performance.now() + timeoutMs;
|
|
228
|
+
return new Promise((resolve) => {
|
|
229
|
+
let settled = false;
|
|
230
|
+
const finish = (result) => {
|
|
231
|
+
if (settled)
|
|
232
|
+
return;
|
|
233
|
+
settled = true;
|
|
234
|
+
clearTimeout(timer);
|
|
235
|
+
options.signal?.removeEventListener("abort", cancel);
|
|
236
|
+
pending.delete(deliver);
|
|
237
|
+
resolve(result);
|
|
238
|
+
};
|
|
239
|
+
const cancel = () => finish(unavailable("cancelled"));
|
|
240
|
+
const timer = setTimeout(() => finish(unavailable("deadline")), timeoutMs);
|
|
241
|
+
options.signal?.addEventListener("abort", cancel, { once: true });
|
|
242
|
+
const deliver = (result) => {
|
|
243
|
+
if (settled)
|
|
244
|
+
return;
|
|
245
|
+
if (options.signal?.aborted)
|
|
246
|
+
return cancel();
|
|
247
|
+
if (performance.now() >= deadline)
|
|
248
|
+
return finish(unavailable("deadline"));
|
|
249
|
+
const delivered = result.snapshot ? validateLiveness(structuredClone(result.snapshot)) : result;
|
|
250
|
+
finish(performance.now() >= deadline ? unavailable("deadline") : delivered);
|
|
251
|
+
};
|
|
252
|
+
pending.add(deliver);
|
|
253
|
+
if (!active) {
|
|
254
|
+
active = readOnce();
|
|
255
|
+
active.then((result) => {
|
|
256
|
+
active = undefined;
|
|
257
|
+
for (const notify of [...pending])
|
|
258
|
+
notify(result);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
export {
|
|
264
|
+
MONITORING_CONFIG_MAX_BYTES,
|
|
265
|
+
MONITORING_DEFAULT_TIMEOUT_MS,
|
|
266
|
+
MONITORING_MAX_READERS,
|
|
267
|
+
MONITORING_MAX_TIMEOUT_MS,
|
|
268
|
+
VERSION as MONITORING_READER_VERSION,
|
|
269
|
+
MonitoringReadSchema,
|
|
270
|
+
MonitoringRowReadSchema,
|
|
271
|
+
MonitoringRowSchema,
|
|
272
|
+
MonitoringSnapshotReadSchema,
|
|
273
|
+
MonitoringSnapshotSchema,
|
|
274
|
+
MonitoringStepSchema,
|
|
275
|
+
STATUS_MAX_AGE_MS,
|
|
276
|
+
STATUS_MAX_BYTES,
|
|
277
|
+
STATUS_MAX_ITEMS,
|
|
278
|
+
readMonitoringStatus
|
|
279
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stitchmux/client",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.96.0",
|
|
4
|
+
"description": "The Stitchmux client: typed control over the local daemon socket or an injected transport, and monitoring snapshots.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/max-listov/stitchmux.git"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public",
|
|
12
|
+
"registry": "https://registry.npmjs.org"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"types",
|
|
18
|
+
"native-stream.json",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./types/src/client.d.ts",
|
|
25
|
+
"import": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./monitoring": {
|
|
28
|
+
"types": "./types/src/monitoring-reader.d.ts",
|
|
29
|
+
"import": "./dist/monitoring.js"
|
|
30
|
+
},
|
|
31
|
+
"./native-stream.json": "./native-stream.json",
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"stitchkit": ">=0.133.0 <1",
|
|
36
|
+
"zod": "^4.6.7"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* One slash command a runtime offers.
|
|
4
|
+
*
|
|
5
|
+
* Kept apart from the catalog that reads and writes it: a control-plane schema travels into the
|
|
6
|
+
* packed client, and a client has no filesystem — a schema living beside `node:path` drags it there.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ControlCommandSchema: z.ZodObject<{
|
|
9
|
+
name: z.ZodString;
|
|
10
|
+
description: z.ZodString;
|
|
11
|
+
argumentHint: z.ZodString;
|
|
12
|
+
aliases: z.ZodArray<z.ZodString>;
|
|
13
|
+
}, z.core.$strict>;
|
|
14
|
+
export type ControlCommand = z.infer<typeof ControlCommandSchema>;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The names a recipe may declare — and they are the names the composed session actually gets.
|
|
4
|
+
*
|
|
5
|
+
* This list and the harness's own were two authorities on one set, and they disagreed both ways.
|
|
6
|
+
* `apply_patch` could be declared and was never built, so a recipe naming it passed validation,
|
|
7
|
+
* received a digest, reported `configured`, and then killed its session at startup; `edit_file`,
|
|
8
|
+
* `glob` and `list_directory` were built and could not be declared, so a Custom session had no way
|
|
9
|
+
* to edit a file at all — `write_file` rewrites it whole.
|
|
10
|
+
*
|
|
11
|
+
* A literal union is kept rather than derived from the harness, because the names are types
|
|
12
|
+
* everywhere else in this tree. What keeps it honest is `composableToolNames` below and the test
|
|
13
|
+
* that compares the two sets: the next divergence reddens there instead of in a consumer's session.
|
|
14
|
+
*/
|
|
15
|
+
export declare const CustomToolNameSchema: z.ZodEnum<{
|
|
16
|
+
edit_file: "edit_file";
|
|
17
|
+
glob: "glob";
|
|
18
|
+
list_directory: "list_directory";
|
|
19
|
+
read_file: "read_file";
|
|
20
|
+
read_output: "read_output";
|
|
21
|
+
read_resource: "read_resource";
|
|
22
|
+
run_command: "run_command";
|
|
23
|
+
search_files: "search_files";
|
|
24
|
+
write_file: "write_file";
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Which inference provider this host composes, and what each kind needs from the host to work.
|
|
28
|
+
*
|
|
29
|
+
* A discriminated union rather than an endpoint bolted onto one shape, because the kinds do not
|
|
30
|
+
* differ by configuration alone: they differ in provenance. `kind` is what the catalog publishes as
|
|
31
|
+
* the source of an answer and what every model in the registry must declare, so a local endpoint
|
|
32
|
+
* described as `openrouter` would not be a shortcut — it would make the runtime report the wrong
|
|
33
|
+
* origin for the work it did.
|
|
34
|
+
*
|
|
35
|
+
* The credential is required for the aggregator and optional for a local server, which is not a
|
|
36
|
+
* relaxation of the rule but the rule stated accurately: an aggregator without a key cannot answer
|
|
37
|
+
* at all, while the common local servers accept requests without one.
|
|
38
|
+
*/
|
|
39
|
+
export declare const CustomProviderSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
40
|
+
kind: z.ZodLiteral<"openrouter">;
|
|
41
|
+
credentialEnv: z.ZodString;
|
|
42
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
43
|
+
kind: z.ZodLiteral<"local">;
|
|
44
|
+
endpoint: z.ZodString;
|
|
45
|
+
credentialEnv: z.ZodOptional<z.ZodString>;
|
|
46
|
+
label: z.ZodOptional<z.ZodString>;
|
|
47
|
+
}, z.core.$strict>], "kind">;
|
|
48
|
+
/**
|
|
49
|
+
* Every tool name one recipe declares — coding tools and service operations, in one expression.
|
|
50
|
+
*
|
|
51
|
+
* The two lists are configured apart because they are configured by different things, and that is
|
|
52
|
+
* precisely why this exists rather than each reader assembling its own union. Composition admitted
|
|
53
|
+
* both while the applied-profile check knew only `tools`, so a recipe declaring any service was
|
|
54
|
+
* accepted, earned a digest, reported `configured` — and its session died on its first profile
|
|
55
|
+
* event with «Native applied profile differs from its host authority». One set, two copies, and
|
|
56
|
+
* they disagreed; the same shape this file already carries a note about, one field up.
|
|
57
|
+
*/
|
|
58
|
+
export declare function declaredCustomToolNames(config: CustomLaunchConfig): string[];
|
|
59
|
+
/**
|
|
60
|
+
* The most names a valid recipe can declare, for the readers that must bound that set.
|
|
61
|
+
*
|
|
62
|
+
* Derived rather than written down: a literal here would be the third authority on this set, and
|
|
63
|
+
* this file records what happened the last two times one went stale. A downstream bound smaller
|
|
64
|
+
* than this rejects a recipe the schema accepted, which is the same defect one layer along.
|
|
65
|
+
*/
|
|
66
|
+
export declare const MAX_DECLARED_CUSTOM_TOOLS: number;
|
|
67
|
+
/**
|
|
68
|
+
* A contract service whose operations this host mounts as tools of a Custom session.
|
|
69
|
+
*
|
|
70
|
+
* Custom exists to run this system's own loop on a machine that is not the consumer's, and without
|
|
71
|
+
* this a session could read and write files and perform not one operation of the party that started
|
|
72
|
+
* it. The seam was never missing — `mountAgent` takes services — what was missing is where the
|
|
73
|
+
* operation SHAPES come from, because the service runs elsewhere. They arrive by handshake: stitchmux
|
|
74
|
+
* spawns the declared executable and speaks MCP over its stdio, so no schema is written down twice
|
|
75
|
+
* and nothing of the far side's code runs inside the supervisor.
|
|
76
|
+
*/
|
|
77
|
+
declare const CustomServiceSchema: z.ZodObject<{
|
|
78
|
+
id: z.ZodString;
|
|
79
|
+
command: z.ZodString;
|
|
80
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
81
|
+
credentialEnv: z.ZodOptional<z.ZodString>;
|
|
82
|
+
tools: z.ZodArray<z.ZodString>;
|
|
83
|
+
}, z.core.$strict>;
|
|
84
|
+
/** Execution-host definition only. The public API selects the existing immutable launch recipe;
|
|
85
|
+
* it never receives this configuration, source paths, executable aliases or credentials. */
|
|
86
|
+
export declare const CustomLaunchConfigSchema: z.ZodObject<{
|
|
87
|
+
provider: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
88
|
+
kind: z.ZodLiteral<"openrouter">;
|
|
89
|
+
credentialEnv: z.ZodString;
|
|
90
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
91
|
+
kind: z.ZodLiteral<"local">;
|
|
92
|
+
endpoint: z.ZodString;
|
|
93
|
+
credentialEnv: z.ZodOptional<z.ZodString>;
|
|
94
|
+
label: z.ZodOptional<z.ZodString>;
|
|
95
|
+
}, z.core.$strict>], "kind">;
|
|
96
|
+
models: z.ZodArray<z.ZodObject<{
|
|
97
|
+
selection: z.ZodObject<{
|
|
98
|
+
provider: z.ZodString;
|
|
99
|
+
model: z.ZodString;
|
|
100
|
+
}, z.core.$strict>;
|
|
101
|
+
contextWindow: z.ZodNumber;
|
|
102
|
+
capabilities: z.ZodArray<z.ZodEnum<{
|
|
103
|
+
files: "files";
|
|
104
|
+
reasoning: "reasoning";
|
|
105
|
+
tools: "tools";
|
|
106
|
+
vision: "vision";
|
|
107
|
+
}>>;
|
|
108
|
+
}, z.core.$strict>>;
|
|
109
|
+
defaultModel: z.ZodObject<{
|
|
110
|
+
provider: z.ZodString;
|
|
111
|
+
model: z.ZodString;
|
|
112
|
+
}, z.core.$strict>;
|
|
113
|
+
trustedRoots: z.ZodArray<z.ZodString>;
|
|
114
|
+
resources: z.ZodArray<z.ZodObject<{
|
|
115
|
+
id: z.ZodString;
|
|
116
|
+
path: z.ZodString;
|
|
117
|
+
sha256: z.ZodString;
|
|
118
|
+
kind: z.ZodEnum<{
|
|
119
|
+
instruction: "instruction";
|
|
120
|
+
resource: "resource";
|
|
121
|
+
skill: "skill";
|
|
122
|
+
}>;
|
|
123
|
+
}, z.core.$strict>>;
|
|
124
|
+
tools: z.ZodArray<z.ZodEnum<{
|
|
125
|
+
edit_file: "edit_file";
|
|
126
|
+
glob: "glob";
|
|
127
|
+
list_directory: "list_directory";
|
|
128
|
+
read_file: "read_file";
|
|
129
|
+
read_output: "read_output";
|
|
130
|
+
read_resource: "read_resource";
|
|
131
|
+
run_command: "run_command";
|
|
132
|
+
search_files: "search_files";
|
|
133
|
+
write_file: "write_file";
|
|
134
|
+
}>>;
|
|
135
|
+
approvalTools: z.ZodArray<z.ZodEnum<{
|
|
136
|
+
edit_file: "edit_file";
|
|
137
|
+
glob: "glob";
|
|
138
|
+
list_directory: "list_directory";
|
|
139
|
+
read_file: "read_file";
|
|
140
|
+
read_output: "read_output";
|
|
141
|
+
read_resource: "read_resource";
|
|
142
|
+
run_command: "run_command";
|
|
143
|
+
search_files: "search_files";
|
|
144
|
+
write_file: "write_file";
|
|
145
|
+
}>>;
|
|
146
|
+
services: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
147
|
+
id: z.ZodString;
|
|
148
|
+
command: z.ZodString;
|
|
149
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
150
|
+
credentialEnv: z.ZodOptional<z.ZodString>;
|
|
151
|
+
tools: z.ZodArray<z.ZodString>;
|
|
152
|
+
}, z.core.$strict>>>;
|
|
153
|
+
approvalSecretEnv: z.ZodString;
|
|
154
|
+
executables: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
155
|
+
commandEnvironment: z.ZodArray<z.ZodString>;
|
|
156
|
+
}, z.core.$strict>;
|
|
157
|
+
export type CustomLaunchConfig = z.infer<typeof CustomLaunchConfigSchema>;
|
|
158
|
+
export type CustomService = z.infer<typeof CustomServiceSchema>;
|
|
159
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What makes a declared endpoint actually local.
|
|
3
|
+
*
|
|
4
|
+
* The provider kind is called `local`, and the catalog publishes that word to every caller as the
|
|
5
|
+
* provenance of an answer. If the word were only a label a host could attach to any URL, then the
|
|
6
|
+
* one thing this runtime promises about a local model — that the prompt did not leave the host or
|
|
7
|
+
* its network — would be unverifiable at exactly the moment someone needs it to be true. Acceptance
|
|
8
|
+
* asks for no hidden cloud reroute; the honest way to deliver that is to make a cloud endpoint
|
|
9
|
+
* unrepresentable as `local` rather than to promise it never happens.
|
|
10
|
+
*
|
|
11
|
+
* So locality is decided from the address literal, with no name resolution: a schema must not
|
|
12
|
+
* perform I/O, and a DNS answer is not a property of the configuration anyway — it can change after
|
|
13
|
+
* validation. That costs the host the ability to name a machine by an arbitrary hostname, which is
|
|
14
|
+
* a real cost and a deliberate one; `localhost` and address literals cover the endpoints this is
|
|
15
|
+
* for (a model server on the host, or one on the host's own network).
|
|
16
|
+
*/
|
|
17
|
+
/** True when this address literal cannot leave the host or its own network. */
|
|
18
|
+
export declare function isLocalAddress(hostname: string): boolean;
|
|
19
|
+
export type EndpointRefusal = 'not-a-url' | 'protocol' | 'embedded-credentials' | 'query-or-fragment' | 'not-local';
|
|
20
|
+
/** Parse a declared local endpoint, naming the exact reason it is refused. */
|
|
21
|
+
export declare function parseLocalEndpoint(raw: string): {
|
|
22
|
+
url: URL;
|
|
23
|
+
} | {
|
|
24
|
+
refused: EndpointRefusal;
|
|
25
|
+
};
|
|
26
|
+
export declare const ENDPOINT_REFUSAL_TEXT: Readonly<Record<EndpointRefusal, string>>;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const TranscriptRoleSchema: z.ZodEnum<{
|
|
3
|
+
assistant: "assistant";
|
|
4
|
+
system: "system";
|
|
5
|
+
tool: "tool";
|
|
6
|
+
unknown: "unknown";
|
|
7
|
+
user: "user";
|
|
8
|
+
}>;
|
|
9
|
+
export declare const TranscriptKindSchema: z.ZodEnum<{
|
|
10
|
+
event: "event";
|
|
11
|
+
image: "image";
|
|
12
|
+
message: "message";
|
|
13
|
+
thinking: "thinking";
|
|
14
|
+
tool_call: "tool_call";
|
|
15
|
+
tool_result: "tool_result";
|
|
16
|
+
unknown: "unknown";
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* An image in a transcript, addressed rather than inlined.
|
|
20
|
+
*
|
|
21
|
+
* The bytes stay out of the record on purpose: a message list is read constantly (it backs
|
|
22
|
+
* `lastMessage` in `list --json`), and carrying pictures through it would make every listing pay
|
|
23
|
+
* for content almost nobody asked to see. `address` is what a reader hands back to fetch them.
|
|
24
|
+
*/
|
|
25
|
+
export declare const TranscriptImageSchema: z.ZodObject<{
|
|
26
|
+
address: z.ZodString;
|
|
27
|
+
mediaType: z.ZodNullable<z.ZodString>;
|
|
28
|
+
bytes: z.ZodNullable<z.ZodNumber>;
|
|
29
|
+
digest: z.ZodNullable<z.ZodString>;
|
|
30
|
+
unavailable: z.ZodNullable<z.ZodEnum<{
|
|
31
|
+
malformed: "malformed";
|
|
32
|
+
"too-large": "too-large";
|
|
33
|
+
"unsupported-source": "unsupported-source";
|
|
34
|
+
}>>;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
export type TranscriptImage = z.infer<typeof TranscriptImageSchema>;
|
|
37
|
+
/** What a turn spent, exactly as the source reports it. Absent is "unknown", never zero. */
|
|
38
|
+
export declare const TranscriptUsageSchema: z.ZodObject<{
|
|
39
|
+
inputTokens: z.ZodNullable<z.ZodNumber>;
|
|
40
|
+
outputTokens: z.ZodNullable<z.ZodNumber>;
|
|
41
|
+
cacheReadTokens: z.ZodNullable<z.ZodNumber>;
|
|
42
|
+
cacheCreationTokens: z.ZodNullable<z.ZodNumber>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
export type TranscriptUsage = z.infer<typeof TranscriptUsageSchema>;
|
|
45
|
+
/**
|
|
46
|
+
* The agent a Claude `Agent` call spawned, read from the agent's own transcript beside the
|
|
47
|
+
* session file (`<uuid>/subagents/agent-<id>.jsonl`). The call carries this so a consumer can show
|
|
48
|
+
* the agent living — with its tool calls and spend — instead of a call that "finished" the second
|
|
49
|
+
* it was launched. `available` says the file was there to read; the rest is null when it was not.
|
|
50
|
+
*/
|
|
51
|
+
export declare const TranscriptAgentSchema: z.ZodObject<{
|
|
52
|
+
id: z.ZodString;
|
|
53
|
+
type: z.ZodNullable<z.ZodString>;
|
|
54
|
+
description: z.ZodNullable<z.ZodString>;
|
|
55
|
+
model: z.ZodNullable<z.ZodString>;
|
|
56
|
+
state: z.ZodEnum<{
|
|
57
|
+
finished: "finished";
|
|
58
|
+
running: "running";
|
|
59
|
+
}>;
|
|
60
|
+
startedAt: z.ZodNullable<z.ZodString>;
|
|
61
|
+
finishedAt: z.ZodNullable<z.ZodString>;
|
|
62
|
+
toolCalls: z.ZodNullable<z.ZodNumber>;
|
|
63
|
+
usage: z.ZodNullable<z.ZodObject<{
|
|
64
|
+
inputTokens: z.ZodNullable<z.ZodNumber>;
|
|
65
|
+
outputTokens: z.ZodNullable<z.ZodNumber>;
|
|
66
|
+
cacheReadTokens: z.ZodNullable<z.ZodNumber>;
|
|
67
|
+
cacheCreationTokens: z.ZodNullable<z.ZodNumber>;
|
|
68
|
+
}, z.core.$strip>>;
|
|
69
|
+
available: z.ZodBoolean;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
export type TranscriptAgent = z.infer<typeof TranscriptAgentSchema>;
|
|
72
|
+
export declare const TranscriptMessageSchema: z.ZodObject<{
|
|
73
|
+
id: z.ZodString;
|
|
74
|
+
seq: z.ZodNumber;
|
|
75
|
+
createdAt: z.ZodNullable<z.ZodString>;
|
|
76
|
+
role: z.ZodEnum<{
|
|
77
|
+
assistant: "assistant";
|
|
78
|
+
system: "system";
|
|
79
|
+
tool: "tool";
|
|
80
|
+
unknown: "unknown";
|
|
81
|
+
user: "user";
|
|
82
|
+
}>;
|
|
83
|
+
kind: z.ZodEnum<{
|
|
84
|
+
event: "event";
|
|
85
|
+
image: "image";
|
|
86
|
+
message: "message";
|
|
87
|
+
thinking: "thinking";
|
|
88
|
+
tool_call: "tool_call";
|
|
89
|
+
tool_result: "tool_result";
|
|
90
|
+
unknown: "unknown";
|
|
91
|
+
}>;
|
|
92
|
+
text: z.ZodNullable<z.ZodString>;
|
|
93
|
+
title: z.ZodNullable<z.ZodString>;
|
|
94
|
+
toolName: z.ZodNullable<z.ZodString>;
|
|
95
|
+
toolCallId: z.ZodNullable<z.ZodString>;
|
|
96
|
+
status: z.ZodNullable<z.ZodEnum<{
|
|
97
|
+
error: "error";
|
|
98
|
+
}>>;
|
|
99
|
+
rawType: z.ZodNullable<z.ZodString>;
|
|
100
|
+
done: z.ZodBoolean;
|
|
101
|
+
result: z.ZodNullable<z.ZodString>;
|
|
102
|
+
input: z.ZodNullable<z.ZodString>;
|
|
103
|
+
image: z.ZodDefault<z.ZodNullable<z.ZodObject<{
|
|
104
|
+
address: z.ZodString;
|
|
105
|
+
mediaType: z.ZodNullable<z.ZodString>;
|
|
106
|
+
bytes: z.ZodNullable<z.ZodNumber>;
|
|
107
|
+
digest: z.ZodNullable<z.ZodString>;
|
|
108
|
+
unavailable: z.ZodNullable<z.ZodEnum<{
|
|
109
|
+
malformed: "malformed";
|
|
110
|
+
"too-large": "too-large";
|
|
111
|
+
"unsupported-source": "unsupported-source";
|
|
112
|
+
}>>;
|
|
113
|
+
}, z.core.$strip>>>;
|
|
114
|
+
resultImages: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
115
|
+
address: z.ZodString;
|
|
116
|
+
mediaType: z.ZodNullable<z.ZodString>;
|
|
117
|
+
bytes: z.ZodNullable<z.ZodNumber>;
|
|
118
|
+
digest: z.ZodNullable<z.ZodString>;
|
|
119
|
+
unavailable: z.ZodNullable<z.ZodEnum<{
|
|
120
|
+
malformed: "malformed";
|
|
121
|
+
"too-large": "too-large";
|
|
122
|
+
"unsupported-source": "unsupported-source";
|
|
123
|
+
}>>;
|
|
124
|
+
}, z.core.$strip>>>;
|
|
125
|
+
usage: z.ZodDefault<z.ZodNullable<z.ZodObject<{
|
|
126
|
+
inputTokens: z.ZodNullable<z.ZodNumber>;
|
|
127
|
+
outputTokens: z.ZodNullable<z.ZodNumber>;
|
|
128
|
+
cacheReadTokens: z.ZodNullable<z.ZodNumber>;
|
|
129
|
+
cacheCreationTokens: z.ZodNullable<z.ZodNumber>;
|
|
130
|
+
}, z.core.$strip>>>;
|
|
131
|
+
resultText: z.ZodNullable<z.ZodString>;
|
|
132
|
+
doneAt: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
133
|
+
agent: z.ZodDefault<z.ZodNullable<z.ZodObject<{
|
|
134
|
+
id: z.ZodString;
|
|
135
|
+
type: z.ZodNullable<z.ZodString>;
|
|
136
|
+
description: z.ZodNullable<z.ZodString>;
|
|
137
|
+
model: z.ZodNullable<z.ZodString>;
|
|
138
|
+
state: z.ZodEnum<{
|
|
139
|
+
finished: "finished";
|
|
140
|
+
running: "running";
|
|
141
|
+
}>;
|
|
142
|
+
startedAt: z.ZodNullable<z.ZodString>;
|
|
143
|
+
finishedAt: z.ZodNullable<z.ZodString>;
|
|
144
|
+
toolCalls: z.ZodNullable<z.ZodNumber>;
|
|
145
|
+
usage: z.ZodNullable<z.ZodObject<{
|
|
146
|
+
inputTokens: z.ZodNullable<z.ZodNumber>;
|
|
147
|
+
outputTokens: z.ZodNullable<z.ZodNumber>;
|
|
148
|
+
cacheReadTokens: z.ZodNullable<z.ZodNumber>;
|
|
149
|
+
cacheCreationTokens: z.ZodNullable<z.ZodNumber>;
|
|
150
|
+
}, z.core.$strip>>;
|
|
151
|
+
available: z.ZodBoolean;
|
|
152
|
+
}, z.core.$strip>>>;
|
|
153
|
+
}, z.core.$strip>;
|