stitchkit 0.78.0 → 0.79.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/dist/agent-runtime-browser.js +53 -581
- package/dist/agent-runtime-coding-tools.js +6 -5
- package/dist/agent-runtime-harness.js +21 -94
- package/dist/agent-runtime-openrouter.js +1 -1
- package/dist/agent-runtime.js +68 -64
- package/dist/application/kernel.d.ts.map +1 -1
- package/dist/application/schemas.d.ts +2 -0
- package/dist/application/schemas.d.ts.map +1 -1
- package/dist/application/watch-hub.d.ts.map +1 -1
- package/dist/application-diagnostic-journal.js +14 -96
- package/dist/application-opentelemetry.js +6 -92
- package/dist/application-schemas.js +2 -1
- package/dist/application.js +158 -1802
- package/dist/cli.js +13 -11
- package/dist/contract/index.js +7 -4
- package/dist/index-2qzskm8h.js +63 -0
- package/dist/{index-93xp5tgg.js → index-2rwwmr7v.js} +3 -3
- package/dist/{index-kw12fsbc.js → index-3gye9wzb.js} +7 -3
- package/dist/{index-1ckavx4h.js → index-3z73fh2c.js} +1 -49
- package/dist/index-4fpa9dy2.js +51 -0
- package/dist/{index-cwp38wxn.js → index-5mtc969c.js} +2 -2
- package/dist/index-5s3zajp8.js +192 -0
- package/dist/index-6s7n2v50.js +583 -0
- package/dist/{index-qaajjfp6.js → index-758zx2ha.js} +15 -94
- package/dist/{index-qyrqwr4c.js → index-77fekveh.js} +4 -1
- package/dist/{index-k45qqrdh.js → index-7ag81v2f.js} +13 -166
- package/dist/{index-n1g2xm6a.js → index-7gnkny4z.js} +124 -1
- package/dist/index-7zbps32p.js +89 -0
- package/dist/index-85vfqd7m.js +135 -0
- package/dist/{index-4ntp63ps.js → index-9s6z8vgf.js} +18 -142
- package/dist/index-a916km3r.js +45 -0
- package/dist/index-b9aefrqd.js +20 -0
- package/dist/index-dre2ywck.js +48 -0
- package/dist/{index-s5tn4kdv.js → index-dwf1f2ap.js} +3 -3
- package/dist/{index-wwst0td5.js → index-dx9xehwt.js} +1 -1
- package/dist/{index-5r0ak8fr.js → index-dxesg10d.js} +4 -4
- package/dist/{index-aczggrty.js → index-dxjjv399.js} +2 -2
- package/dist/{index-j6mfaw26.js → index-egaabxkz.js} +3 -3
- package/dist/index-evcnmsc3.js +866 -0
- package/dist/{index-efm026pw.js → index-fxz0v7vg.js} +86 -86
- package/dist/{index-56fm73re.js → index-hb5pf3s4.js} +1 -1
- package/dist/{index-n7apa6sy.js → index-k9ay6v6d.js} +24 -275
- package/dist/index-kzfs85xp.js +9 -0
- package/dist/{index-vbf2p6me.js → index-m9kzax52.js} +91 -89
- package/dist/{index-22by16v6.js → index-mgtxfe6b.js} +1 -1
- package/dist/index-p7hgdyhb.js +22 -0
- package/dist/index-pq95qkbf.js +0 -0
- package/dist/index-t0z5p5w6.js +318 -0
- package/dist/{index-31k1ns1s.js → index-vwp69871.js} +13 -11
- package/dist/index-wc4x00bn.js +103 -0
- package/dist/{index-aewy3x5j.js → index-xcetq6j3.js} +10 -8
- package/dist/{index-7z69kyrh.js → index-y01f4223.js} +24 -40
- package/dist/{index-dmfn9m4x.js → index-ywd0y6m1.js} +20 -341
- package/dist/index.js +46 -407
- package/dist/live.js +6 -3
- package/dist/node.js +17 -14
- package/dist/observability/index.js +8 -7
- package/dist/primitives.js +4 -2
- package/dist/react.js +1 -1
- package/dist/remote.js +7 -3
- package/dist/server/index.js +32 -45
- package/dist/telegram.js +1 -1
- package/dist/testing.js +90 -1576
- package/dist/tool-invoker.js +11 -9
- package/dist/tools/async-operation-contract.d.ts +61 -0
- package/dist/tools/async-operation-contract.d.ts.map +1 -0
- package/dist/tools/async-operation.d.ts +2 -47
- package/dist/tools/async-operation.d.ts.map +1 -1
- package/dist/tools/view-file-contract.d.ts +98 -0
- package/dist/tools/view-file-contract.d.ts.map +1 -0
- package/dist/tools/view-file.d.ts +4 -83
- package/dist/tools/view-file.d.ts.map +1 -1
- package/dist/tools-contract.d.ts +29 -0
- package/dist/tools-contract.d.ts.map +1 -0
- package/dist/tools-contract.js +24 -0
- package/dist/tools.d.ts +3 -3
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +61 -140
- package/llms-full.txt +38 -3
- package/package.json +9 -6
- package/dist/index-anyqnqcv.js +0 -79
- package/dist/index-ksp6e2ye.js +0 -24
- package/dist/index-vj3vvpaa.js +0 -307
- package/dist/index-wfq8zerm.js +0 -92
package/dist/index-vj3vvpaa.js
DELETED
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
// src/contract/define.ts
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
// src/internal/route-pattern.ts
|
|
5
|
-
var PARAM_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
6
|
-
function joinRoutePath(...parts) {
|
|
7
|
-
const joined = parts.filter((part) => Boolean(part)).map((part) => part.replace(/^\/+|\/+$/g, "")).filter(Boolean).join("/");
|
|
8
|
-
return `/${joined}`;
|
|
9
|
-
}
|
|
10
|
-
function parseTrailingWildcard(path) {
|
|
11
|
-
const segments = path.split("/").filter(Boolean);
|
|
12
|
-
const paramNames = new Set;
|
|
13
|
-
let wildcard = null;
|
|
14
|
-
for (const [segmentIndex, segment] of segments.entries()) {
|
|
15
|
-
if (segment.startsWith(":")) {
|
|
16
|
-
const name2 = segment.slice(1);
|
|
17
|
-
if (!PARAM_IDENTIFIER.test(name2)) {
|
|
18
|
-
throw new Error(`Invalid route parameter name "${name2}" in path "${path}"`);
|
|
19
|
-
}
|
|
20
|
-
if (paramNames.has(name2)) {
|
|
21
|
-
throw new Error(`Duplicate route parameter name "${name2}" in path "${path}"`);
|
|
22
|
-
}
|
|
23
|
-
paramNames.add(name2);
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
if (!segment.startsWith("*")) {
|
|
27
|
-
if (segment.includes("*")) {
|
|
28
|
-
throw new Error(`Wildcard must occupy its own segment in path "${path}"`);
|
|
29
|
-
}
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
const name = segment.slice(1);
|
|
33
|
-
if (!PARAM_IDENTIFIER.test(name)) {
|
|
34
|
-
throw new Error(`Trailing wildcard in path "${path}" must be named, for example "/*filePath"`);
|
|
35
|
-
}
|
|
36
|
-
if (segmentIndex !== segments.length - 1) {
|
|
37
|
-
throw new Error(`Wildcard "*${name}" must be the final segment in path "${path}"`);
|
|
38
|
-
}
|
|
39
|
-
if (wildcard) {
|
|
40
|
-
throw new Error(`Path "${path}" contains more than one wildcard`);
|
|
41
|
-
}
|
|
42
|
-
if (paramNames.has(name)) {
|
|
43
|
-
throw new Error(`Duplicate route parameter name "${name}" in path "${path}"`);
|
|
44
|
-
}
|
|
45
|
-
wildcard = { name, segmentIndex };
|
|
46
|
-
}
|
|
47
|
-
return wildcard;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// src/internal/safe-json.ts
|
|
51
|
-
function isUnsafeKey(key) {
|
|
52
|
-
return key === "__proto__";
|
|
53
|
-
}
|
|
54
|
-
function safeJsonParse(text) {
|
|
55
|
-
return JSON.parse(text, (key, value) => isUnsafeKey(key) ? undefined : value);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// src/contract/define.ts
|
|
59
|
-
function defineContract(meta, endpoints) {
|
|
60
|
-
const toolTransports = new Map;
|
|
61
|
-
for (const [key, ep] of Object.entries(endpoints)) {
|
|
62
|
-
const wildcard = parseTrailingWildcard(ep.path);
|
|
63
|
-
if (wildcard) {
|
|
64
|
-
if (!ep.params) {
|
|
65
|
-
throw new Error(`Contract "${meta.prefix}": endpoint "${key}" wildcard "${wildcard.name}" requires a params schema field`);
|
|
66
|
-
}
|
|
67
|
-
const paramsJson = z.toJSONSchema(ep.params, { io: "input" });
|
|
68
|
-
if (!paramsJson.properties || !(wildcard.name in paramsJson.properties)) {
|
|
69
|
-
throw new Error(`Contract "${meta.prefix}": endpoint "${key}" params schema is missing wildcard field "${wildcard.name}"`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (ep.desc.trim() === "") {
|
|
73
|
-
throw new Error(`Contract "${meta.prefix}": endpoint "${key}" has an empty desc`);
|
|
74
|
-
}
|
|
75
|
-
if (ep.maxJsonBodyBytes !== undefined && (!Number.isSafeInteger(ep.maxJsonBodyBytes) || ep.maxJsonBodyBytes <= 0)) {
|
|
76
|
-
throw new Error(`Contract "${meta.prefix}": endpoint "${key}" maxJsonBodyBytes must be a positive safe integer, received ${ep.maxJsonBodyBytes}`);
|
|
77
|
-
}
|
|
78
|
-
if (ep.multipart)
|
|
79
|
-
assertMultipartEndpoint(meta.prefix, key, ep);
|
|
80
|
-
if (ep.rawResponse)
|
|
81
|
-
assertRawEndpoint(meta.prefix, key, ep);
|
|
82
|
-
if ("stream" in ep)
|
|
83
|
-
assertStreamingResponseEndpoint(meta.prefix, key, ep);
|
|
84
|
-
if (ep.method === "HEAD")
|
|
85
|
-
assertHeadEndpoint(meta.prefix, key, ep);
|
|
86
|
-
if (ep.rawBody)
|
|
87
|
-
assertRawBodyEndpoint(meta.prefix, key, ep);
|
|
88
|
-
if ("responseMeta" in ep)
|
|
89
|
-
assertResponseMetaEndpoint(meta.prefix, key, ep);
|
|
90
|
-
if (!("toolName" in ep) || !ep.toolName)
|
|
91
|
-
continue;
|
|
92
|
-
const transports = new Set(ep.expose ? ep.expose.filter((t) => t !== "HTTP") : ["MCP", "AGENT"]);
|
|
93
|
-
if (transports.size === 0) {
|
|
94
|
-
throw new Error(`Contract "${meta.prefix}": endpoint "${key}" sets toolName "${ep.toolName}" but is not exposed on any tool transport (MCP / AGENT)`);
|
|
95
|
-
}
|
|
96
|
-
const existing = toolTransports.get(ep.toolName);
|
|
97
|
-
if (existing) {
|
|
98
|
-
for (const t of transports) {
|
|
99
|
-
if (existing.transports.has(t)) {
|
|
100
|
-
throw new Error(`Contract "${meta.prefix}": duplicate toolName "${ep.toolName}" on transport "${t}" (endpoints: "${existing.key}" and "${key}")`);
|
|
101
|
-
}
|
|
102
|
-
existing.transports.add(t);
|
|
103
|
-
}
|
|
104
|
-
} else {
|
|
105
|
-
toolTransports.set(ep.toolName, { key, transports });
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return { meta, endpoints };
|
|
109
|
-
}
|
|
110
|
-
function assertPositiveLimit(where, name, value) {
|
|
111
|
-
if (value !== undefined && (!Number.isSafeInteger(value) || value <= 0)) {
|
|
112
|
-
throw new Error(`${where} ${name} must be a positive safe integer, received ${value}`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
function assertMultipartEndpoint(prefix, key, ep) {
|
|
116
|
-
const where = `Contract "${prefix}": multipart endpoint "${key}"`;
|
|
117
|
-
if (ep.method !== "POST" && ep.method !== "PUT" && ep.method !== "PATCH") {
|
|
118
|
-
throw new Error(`${where} must use POST, PUT or PATCH`);
|
|
119
|
-
}
|
|
120
|
-
const multipart = ep.multipart;
|
|
121
|
-
if (!multipart || typeof multipart !== "object") {
|
|
122
|
-
throw new Error(`${where} must declare a multipart descriptor`);
|
|
123
|
-
}
|
|
124
|
-
assertPositiveLimit(where, "maxRequestBytes", multipart.maxRequestBytes);
|
|
125
|
-
assertPositiveLimit(where, "maxFieldBytes", multipart.maxFieldBytes);
|
|
126
|
-
const entries = Object.entries(multipart.files);
|
|
127
|
-
if (entries.length === 0)
|
|
128
|
-
throw new Error(`${where} must declare at least one file field`);
|
|
129
|
-
for (const [field, policy] of entries) {
|
|
130
|
-
if (!field || isUnsafeKey(field))
|
|
131
|
-
throw new Error(`${where} has an invalid file field name`);
|
|
132
|
-
assertPositiveLimit(`${where} field "${field}"`, "maxBytes", policy.maxBytes);
|
|
133
|
-
assertPositiveLimit(`${where} field "${field}"`, "maxFiles", policy.maxFiles);
|
|
134
|
-
if (policy.multiple !== true && policy.maxFiles !== undefined) {
|
|
135
|
-
throw new Error(`${where} field "${field}" may set maxFiles only with multiple: true`);
|
|
136
|
-
}
|
|
137
|
-
if (policy.contentTypes) {
|
|
138
|
-
if (policy.contentTypes.length === 0) {
|
|
139
|
-
throw new Error(`${where} field "${field}" contentTypes cannot be empty`);
|
|
140
|
-
}
|
|
141
|
-
for (const contentType of policy.contentTypes) {
|
|
142
|
-
if (!/^[a-z0-9!#$&^_.+-]+\/(?:[a-z0-9!#$&^_.+-]+|\*)$/i.test(contentType)) {
|
|
143
|
-
throw new Error(`${where} field "${field}" has invalid content type policy "${contentType}"`);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
function assertRawEndpoint(prefix, key, ep) {
|
|
150
|
-
const where = `Contract "${prefix}": raw endpoint "${key}"`;
|
|
151
|
-
if (ep.output)
|
|
152
|
-
throw new Error(`${where} cannot declare an output schema`);
|
|
153
|
-
if ("toolName" in ep && ep.toolName)
|
|
154
|
-
throw new Error(`${where} cannot set a toolName`);
|
|
155
|
-
if ("ui" in ep && ep.ui)
|
|
156
|
-
throw new Error(`${where} cannot set MCP ui metadata`);
|
|
157
|
-
if ("annotations" in ep && ep.annotations) {
|
|
158
|
-
throw new Error(`${where} cannot set MCP annotations`);
|
|
159
|
-
}
|
|
160
|
-
const nonHttp = (ep.expose ?? []).filter((t) => t !== "HTTP");
|
|
161
|
-
if (nonHttp.length > 0) {
|
|
162
|
-
throw new Error(`${where} is HTTP-only — remove ${nonHttp.join(", ")} from expose`);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
function assertStreamingResponseEndpoint(prefix, key, ep) {
|
|
166
|
-
const where = `Contract "${prefix}": streaming endpoint "${key}"`;
|
|
167
|
-
if (!("stream" in ep) || !ep.stream || typeof ep.stream !== "object") {
|
|
168
|
-
throw new Error(`${where} must declare a stream descriptor`);
|
|
169
|
-
}
|
|
170
|
-
if (!ep.stream.item || typeof ep.stream.item.parse !== "function") {
|
|
171
|
-
throw new Error(`${where} must declare an item schema`);
|
|
172
|
-
}
|
|
173
|
-
const runtimeFormat = Reflect.get(ep.stream, "format");
|
|
174
|
-
const runtimeFinalLine = Reflect.get(ep.stream, "finalLine");
|
|
175
|
-
if (ep.stream.framing === "item" && runtimeFormat === "sse") {
|
|
176
|
-
throw new Error(`${where} item framing is supported only for ndjson`);
|
|
177
|
-
}
|
|
178
|
-
if (ep.stream.framing === "item" && ep.stream.completion !== "terminal") {
|
|
179
|
-
throw new Error(`${where} item framing requires terminal completion`);
|
|
180
|
-
}
|
|
181
|
-
if (ep.stream.completion === "terminal" && !ep.stream.terminal) {
|
|
182
|
-
throw new Error(`${where} terminal completion requires a terminal schema`);
|
|
183
|
-
}
|
|
184
|
-
if (runtimeFinalLine === "require-newline" && runtimeFormat === "sse") {
|
|
185
|
-
throw new Error(`${where} finalLine applies only to ndjson`);
|
|
186
|
-
}
|
|
187
|
-
assertPositiveLimit(where, "maxFrameBytes", ep.stream.maxFrameBytes);
|
|
188
|
-
assertPositiveLimit(where, "lifetimeMs", ep.stream.lifetimeMs);
|
|
189
|
-
assertPositiveLimit(where, "heartbeatMs", ep.stream.heartbeatMs);
|
|
190
|
-
if (ep.stream.idleTimeoutSeconds !== undefined && (!Number.isSafeInteger(ep.stream.idleTimeoutSeconds) || ep.stream.idleTimeoutSeconds < 0)) {
|
|
191
|
-
throw new Error(`${where} idleTimeoutSeconds must be a non-negative safe integer`);
|
|
192
|
-
}
|
|
193
|
-
if (ep.output)
|
|
194
|
-
throw new Error(`${where} cannot declare an output schema`);
|
|
195
|
-
if (ep.rawResponse)
|
|
196
|
-
throw new Error(`${where} cannot also be rawResponse`);
|
|
197
|
-
if (ep.multipart)
|
|
198
|
-
throw new Error(`${where} cannot be multipart`);
|
|
199
|
-
if ("toolName" in ep && ep.toolName)
|
|
200
|
-
throw new Error(`${where} cannot set a toolName`);
|
|
201
|
-
const nonHttp = (ep.expose ?? []).filter((transport) => transport !== "HTTP");
|
|
202
|
-
if (nonHttp.length > 0) {
|
|
203
|
-
throw new Error(`${where} is HTTP-only — remove ${nonHttp.join(", ")} from expose`);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
function assertHeadEndpoint(prefix, key, ep) {
|
|
207
|
-
const where = `Contract "${prefix}": HEAD endpoint "${key}"`;
|
|
208
|
-
if (!ep.rawResponse)
|
|
209
|
-
throw new Error(`${where} must declare rawResponse: true`);
|
|
210
|
-
if (ep.input)
|
|
211
|
-
throw new Error(`${where} cannot declare an input schema`);
|
|
212
|
-
if (ep.multipart)
|
|
213
|
-
throw new Error(`${where} cannot be multipart`);
|
|
214
|
-
if (ep.rawBody)
|
|
215
|
-
throw new Error(`${where} cannot retain a raw body`);
|
|
216
|
-
}
|
|
217
|
-
function assertRawBodyEndpoint(prefix, key, ep) {
|
|
218
|
-
const where = `Contract "${prefix}": rawBody endpoint "${key}"`;
|
|
219
|
-
if (!ep.input)
|
|
220
|
-
throw new Error(`${where} must declare an input schema`);
|
|
221
|
-
if (ep.multipart)
|
|
222
|
-
throw new Error(`${where} cannot be multipart`);
|
|
223
|
-
if (ep.method !== "POST" && ep.method !== "PUT" && ep.method !== "PATCH") {
|
|
224
|
-
throw new Error(`${where} must use POST, PUT or PATCH`);
|
|
225
|
-
}
|
|
226
|
-
if ("toolName" in ep && ep.toolName)
|
|
227
|
-
throw new Error(`${where} cannot set a toolName`);
|
|
228
|
-
if ("ui" in ep && ep.ui)
|
|
229
|
-
throw new Error(`${where} cannot set MCP ui metadata`);
|
|
230
|
-
if ("annotations" in ep && ep.annotations) {
|
|
231
|
-
throw new Error(`${where} cannot set MCP annotations`);
|
|
232
|
-
}
|
|
233
|
-
const nonHttp = (ep.expose ?? []).filter((transport) => transport !== "HTTP");
|
|
234
|
-
if (nonHttp.length > 0) {
|
|
235
|
-
throw new Error(`${where} is HTTP-only — remove ${nonHttp.join(", ")} from expose`);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
function assertResponseMetaEndpoint(prefix, key, ep) {
|
|
239
|
-
const where = `Contract "${prefix}": responseMeta endpoint "${key}"`;
|
|
240
|
-
if (!ep.responseMeta || typeof ep.responseMeta !== "object") {
|
|
241
|
-
throw new Error(`${where} must declare responseMeta as an object`);
|
|
242
|
-
}
|
|
243
|
-
const status = ep.responseMeta.status;
|
|
244
|
-
if (status !== undefined && (!Number.isSafeInteger(status) || status < 200 || status > 299)) {
|
|
245
|
-
throw new Error(`${where} status must be a successful 2xx integer, received ${status}`);
|
|
246
|
-
}
|
|
247
|
-
if (ep.output && (status === 204 || status === 205)) {
|
|
248
|
-
throw new Error(`${where} cannot combine output with bodyless status ${status}`);
|
|
249
|
-
}
|
|
250
|
-
if (ep.rawResponse)
|
|
251
|
-
throw new Error(`${where} cannot also be a rawResponse endpoint`);
|
|
252
|
-
if ("toolName" in ep && ep.toolName)
|
|
253
|
-
throw new Error(`${where} cannot set a toolName`);
|
|
254
|
-
if ("ui" in ep && ep.ui)
|
|
255
|
-
throw new Error(`${where} cannot set MCP ui metadata`);
|
|
256
|
-
if ("annotations" in ep && ep.annotations) {
|
|
257
|
-
throw new Error(`${where} cannot set MCP annotations`);
|
|
258
|
-
}
|
|
259
|
-
const nonHttp = (ep.expose ?? []).filter((transport) => transport !== "HTTP");
|
|
260
|
-
if (nonHttp.length > 0) {
|
|
261
|
-
throw new Error(`${where} is HTTP-only — remove ${nonHttp.join(", ")} from expose`);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
function mergeMeta(contractMeta, endpointMeta) {
|
|
265
|
-
if (!contractMeta)
|
|
266
|
-
return endpointMeta;
|
|
267
|
-
if (!endpointMeta)
|
|
268
|
-
return { ...contractMeta };
|
|
269
|
-
return { ...contractMeta, ...endpointMeta };
|
|
270
|
-
}
|
|
271
|
-
// src/contract/errors-factory.ts
|
|
272
|
-
import { z as z2 } from "zod";
|
|
273
|
-
// src/contract/pagination.ts
|
|
274
|
-
import { z as z3 } from "zod";
|
|
275
|
-
|
|
276
|
-
// src/internal/base64url.ts
|
|
277
|
-
function bytesToBase64Url(bytes) {
|
|
278
|
-
let binary = "";
|
|
279
|
-
for (const byte of bytes)
|
|
280
|
-
binary += String.fromCharCode(byte);
|
|
281
|
-
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
282
|
-
}
|
|
283
|
-
function base64UrlToBytes(segment) {
|
|
284
|
-
if (!/^[A-Za-z0-9_-]*$/.test(segment) || segment.length % 4 === 1) {
|
|
285
|
-
throw new Error("invalid base64url segment");
|
|
286
|
-
}
|
|
287
|
-
const b64 = segment.replace(/-/g, "+").replace(/_/g, "/");
|
|
288
|
-
const padded = b64.padEnd(Math.ceil(b64.length / 4) * 4, "=");
|
|
289
|
-
return Uint8Array.from(atob(padded), (c) => c.charCodeAt(0));
|
|
290
|
-
}
|
|
291
|
-
// src/contract/stream.ts
|
|
292
|
-
import { z as z4 } from "zod";
|
|
293
|
-
var DEFAULT_CONTRACT_STREAM_FRAME_BYTES = 256 * 1024;
|
|
294
|
-
var ContractStreamFrameSchema = z4.discriminatedUnion("type", [
|
|
295
|
-
z4.object({ type: z4.literal("data"), data: z4.unknown() }).strict(),
|
|
296
|
-
z4.object({
|
|
297
|
-
type: z4.literal("error"),
|
|
298
|
-
error: z4.object({
|
|
299
|
-
code: z4.string(),
|
|
300
|
-
message: z4.string().optional(),
|
|
301
|
-
details: z4.unknown().optional(),
|
|
302
|
-
hint: z4.string().optional()
|
|
303
|
-
}).strict()
|
|
304
|
-
}).strict(),
|
|
305
|
-
z4.object({ type: z4.literal("end") }).strict()
|
|
306
|
-
]);
|
|
307
|
-
export { joinRoutePath, parseTrailingWildcard, isUnsafeKey, safeJsonParse, defineContract, mergeMeta, bytesToBase64Url, base64UrlToBytes, DEFAULT_CONTRACT_STREAM_FRAME_BYTES, ContractStreamFrameSchema };
|
package/dist/index-wfq8zerm.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
LiveStatePhaseSchema,
|
|
3
|
-
LiveStateStopReasonSchema
|
|
4
|
-
} from "./index-dmfn9m4x.js";
|
|
5
|
-
|
|
6
|
-
// src/live/watch-contract.ts
|
|
7
|
-
import { z } from "zod";
|
|
8
|
-
var WatchKeySchema = z.object({
|
|
9
|
-
service: z.string().min(1),
|
|
10
|
-
action: z.string().min(1),
|
|
11
|
-
digest: z.string().min(1)
|
|
12
|
-
}).strict().readonly();
|
|
13
|
-
var WatchOpenSchema = z.object({ key: WatchKeySchema, args: z.unknown() }).readonly();
|
|
14
|
-
var WatchAcceptedSchema = z.object({
|
|
15
|
-
accepted: z.boolean(),
|
|
16
|
-
reason: z.string().optional()
|
|
17
|
-
}).strict().readonly();
|
|
18
|
-
var WatchValueSchema = z.object({
|
|
19
|
-
key: WatchKeySchema,
|
|
20
|
-
revision: z.number().int().nonnegative(),
|
|
21
|
-
value: z.unknown()
|
|
22
|
-
}).readonly();
|
|
23
|
-
var WatchStateSchema = z.object({
|
|
24
|
-
key: WatchKeySchema,
|
|
25
|
-
phase: LiveStatePhaseSchema,
|
|
26
|
-
reason: LiveStateStopReasonSchema.optional(),
|
|
27
|
-
code: z.string().optional(),
|
|
28
|
-
message: z.string().optional()
|
|
29
|
-
}).readonly();
|
|
30
|
-
var WATCH_OPEN = "stitchkit.watch.open";
|
|
31
|
-
var WATCH_CLOSE = "stitchkit.watch.close";
|
|
32
|
-
var WATCH_VALUE = "stitchkit.watch.value";
|
|
33
|
-
var WATCH_STATE = "stitchkit.watch.state";
|
|
34
|
-
var watchContract = {
|
|
35
|
-
serverToClient: {
|
|
36
|
-
[WATCH_VALUE]: { args: z.tuple([WatchValueSchema]) },
|
|
37
|
-
[WATCH_STATE]: { args: z.tuple([WatchStateSchema]) }
|
|
38
|
-
},
|
|
39
|
-
clientToServer: {
|
|
40
|
-
[WATCH_OPEN]: { args: z.tuple([WatchOpenSchema]), ack: WatchAcceptedSchema },
|
|
41
|
-
[WATCH_CLOSE]: { args: z.tuple([z.object({ key: WatchKeySchema }).readonly()]) }
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
function watchKeyString(key) {
|
|
45
|
-
return `${key.service}/${key.action}/${key.digest}`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// src/internal/stable-digest.ts
|
|
49
|
-
function stableValue(value) {
|
|
50
|
-
if (Array.isArray(value))
|
|
51
|
-
return value.map(stableValue);
|
|
52
|
-
if (value === null || typeof value !== "object")
|
|
53
|
-
return value;
|
|
54
|
-
const result = {};
|
|
55
|
-
for (const key of Object.keys(value).sort()) {
|
|
56
|
-
result[key] = stableValue(Reflect.get(value, key));
|
|
57
|
-
}
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
function mix128(input) {
|
|
61
|
-
let a = 2654435769;
|
|
62
|
-
let b = 2246822507;
|
|
63
|
-
let c = 3266489909;
|
|
64
|
-
let d = 668265263;
|
|
65
|
-
for (let index = 0;index < input.length; index += 1) {
|
|
66
|
-
const code = input.charCodeAt(index);
|
|
67
|
-
a = Math.imul(a ^ code, 2246822519);
|
|
68
|
-
b = Math.imul(b ^ code, 3266489917);
|
|
69
|
-
c = Math.imul(c ^ code, 668265263);
|
|
70
|
-
d = Math.imul(d ^ code, 374761393);
|
|
71
|
-
a = a << 13 | a >>> 19;
|
|
72
|
-
b = b << 17 | b >>> 15;
|
|
73
|
-
c = c << 7 | c >>> 25;
|
|
74
|
-
d = d << 11 | d >>> 21;
|
|
75
|
-
}
|
|
76
|
-
a ^= b >>> 15;
|
|
77
|
-
b ^= c >>> 13;
|
|
78
|
-
c ^= d >>> 11;
|
|
79
|
-
d ^= a >>> 9;
|
|
80
|
-
return [
|
|
81
|
-
Math.imul(a ^ a >>> 16, 575075507) >>> 0,
|
|
82
|
-
Math.imul(b ^ b >>> 13, 2654435761) >>> 0,
|
|
83
|
-
Math.imul(c ^ c >>> 16, 2246822507) >>> 0,
|
|
84
|
-
Math.imul(d ^ d >>> 15, 3266489909) >>> 0
|
|
85
|
-
];
|
|
86
|
-
}
|
|
87
|
-
function argumentsDigest(args) {
|
|
88
|
-
const lanes = mix128(JSON.stringify(stableValue(args)) ?? "undefined");
|
|
89
|
-
return lanes.map((lane) => lane.toString(16).padStart(8, "0")).join("");
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export { stableValue, argumentsDigest, WatchKeySchema, WatchValueSchema, WatchStateSchema, WATCH_OPEN, WATCH_CLOSE, WATCH_VALUE, WATCH_STATE, watchContract, watchKeyString };
|