stitchkit 0.77.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 +20 -93
- package/dist/agent-runtime-openrouter.js +1 -1
- package/dist/agent-runtime.js +65 -61
- package/dist/application/decisions.d.ts +28 -25
- package/dist/application/decisions.d.ts.map +1 -1
- package/dist/application/kernel.d.ts +2 -0
- package/dist/application/kernel.d.ts.map +1 -1
- package/dist/application/keyspace.d.ts +11 -1
- package/dist/application/keyspace.d.ts.map +1 -1
- package/dist/application/schedule.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/server-resource.d.ts.map +1 -1
- package/dist/application/watch-hub.d.ts.map +1 -1
- package/dist/application-diagnostic-journal.d.ts +21 -0
- package/dist/application-diagnostic-journal.d.ts.map +1 -0
- package/dist/application-diagnostic-journal.js +632 -0
- package/dist/application-opentelemetry.js +3 -2
- package/dist/application-schemas.js +14 -98
- package/dist/application.d.ts +1 -2
- package/dist/application.d.ts.map +1 -1
- package/dist/application.js +155 -882
- package/dist/cli.js +13 -11
- package/dist/contract/index.js +15 -10
- package/dist/files/boundary.d.ts.map +1 -1
- package/dist/files.js +1 -1
- package/dist/{index-7b188kmz.js → index-2qzskm8h.js} +15 -1
- package/dist/{index-k2zczx1g.js → index-2rwwmr7v.js} +3 -3
- package/dist/{index-8eywc9zv.js → index-3gye9wzb.js} +6 -3
- package/dist/index-4fpa9dy2.js +51 -0
- package/dist/{index-7qy2ex0m.js → index-5mtc969c.js} +2 -2
- package/dist/index-5s3zajp8.js +192 -0
- package/dist/{index-3cwck0rm.js → index-6s7n2v50.js} +60 -374
- package/dist/{index-s4c8wy8m.js → index-758zx2ha.js} +11 -90
- package/dist/{index-qyrqwr4c.js → index-77fekveh.js} +4 -1
- package/dist/{index-58jzmnn4.js → index-7ag81v2f.js} +355 -34
- package/dist/index-7gnkny4z.js +326 -0
- package/dist/index-7zbps32p.js +89 -0
- package/dist/index-85vfqd7m.js +135 -0
- package/dist/{index-m668wzyc.js → index-9s6z8vgf.js} +17 -141
- package/dist/{index-bfcpjw20.js → index-actkayzn.js} +7 -3
- package/dist/index-b9aefrqd.js +20 -0
- package/dist/index-dre2ywck.js +48 -0
- package/dist/{index-nemjkxjp.js → index-dwf1f2ap.js} +16 -12
- package/dist/{index-wwst0td5.js → index-dx9xehwt.js} +1 -1
- package/dist/{index-ezmn6ac6.js → index-dxesg10d.js} +4 -4
- package/dist/{index-aczggrty.js → index-dxjjv399.js} +2 -2
- package/dist/{index-jqtsc9mj.js → index-egaabxkz.js} +3 -3
- package/dist/{index-vc1b0b1b.js → index-evcnmsc3.js} +49 -8
- package/dist/{index-nt1mp8km.js → index-fxz0v7vg.js} +84 -84
- package/dist/index-h4pj6fta.js +87 -0
- package/dist/{index-1rxswfbv.js → index-hb5pf3s4.js} +1 -1
- package/dist/{index-t8qyvrvg.js → index-k9ay6v6d.js} +21 -272
- 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-s2rchahr.js → index-vwp69871.js} +13 -11
- package/dist/index-wc4x00bn.js +103 -0
- package/dist/{index-da1aqnhb.js → index-xcetq6j3.js} +8 -6
- package/dist/{index-f6n5n7nz.js → index-y01f4223.js} +33 -126
- package/dist/{index-35z5h2ty.js → index-ywd0y6m1.js} +18 -218
- package/dist/index.js +65 -1588
- package/dist/internal/deadline.d.ts +17 -0
- package/dist/internal/deadline.d.ts.map +1 -0
- package/dist/live.js +15 -89
- package/dist/node.js +17 -15
- package/dist/observability/context.d.ts.map +1 -1
- package/dist/observability/index.js +7 -6
- package/dist/primitives.js +5 -2
- package/dist/react.js +1 -1
- package/dist/remote.js +7 -6
- package/dist/server/event-bus.d.ts.map +1 -1
- package/dist/server/index.js +26 -38
- package/dist/telegram.js +1 -1
- package/dist/testing.js +86 -97
- 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 +59 -95
- package/llms-full.txt +146 -14
- package/package.json +14 -7
- package/dist/index-ksp6e2ye.js +0 -24
- package/dist/index-vj3vvpaa.js +0 -307
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isRecord
|
|
3
|
+
} from "./index-77fekveh.js";
|
|
4
|
+
|
|
5
|
+
// src/application/diagnostic-journal-contract.ts
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
var PositiveSafeIntegerSchema = z.number().int().positive().safe();
|
|
8
|
+
var FileModeSchema = z.number().int().min(0).max(511);
|
|
9
|
+
var DiagnosticJournalLimitsSchema = z.object({
|
|
10
|
+
maxEventBytes: PositiveSafeIntegerSchema,
|
|
11
|
+
maxPendingItems: PositiveSafeIntegerSchema,
|
|
12
|
+
maxPendingBytes: PositiveSafeIntegerSchema,
|
|
13
|
+
maxFileBytes: PositiveSafeIntegerSchema,
|
|
14
|
+
maxFiles: PositiveSafeIntegerSchema
|
|
15
|
+
}).strict().readonly();
|
|
16
|
+
var DiagnosticJournalLockPolicySchema = z.enum(["refuse", "reclaim-stale"]);
|
|
17
|
+
var DiagnosticJournalStateSchema = z.enum(["open", "draining", "closed", "failed"]);
|
|
18
|
+
var DiagnosticJournalRefusalReasonSchema = z.enum([
|
|
19
|
+
"closed",
|
|
20
|
+
"failed",
|
|
21
|
+
"invalid",
|
|
22
|
+
"oversized",
|
|
23
|
+
"item-capacity",
|
|
24
|
+
"byte-capacity"
|
|
25
|
+
]);
|
|
26
|
+
var DiagnosticJournalRefusalCountersSchema = z.object({
|
|
27
|
+
closed: z.number().int().nonnegative(),
|
|
28
|
+
failed: z.number().int().nonnegative(),
|
|
29
|
+
invalid: z.number().int().nonnegative(),
|
|
30
|
+
oversized: z.number().int().nonnegative(),
|
|
31
|
+
"item-capacity": z.number().int().nonnegative(),
|
|
32
|
+
"byte-capacity": z.number().int().nonnegative()
|
|
33
|
+
}).strict().readonly();
|
|
34
|
+
var DiagnosticJournalFailurePhaseSchema = z.enum(["write", "rotation", "close"]);
|
|
35
|
+
var DiagnosticJournalStatusSchema = z.object({
|
|
36
|
+
state: DiagnosticJournalStateSchema,
|
|
37
|
+
epoch: z.uuid(),
|
|
38
|
+
limits: DiagnosticJournalLimitsSchema,
|
|
39
|
+
lock: z.object({
|
|
40
|
+
policy: DiagnosticJournalLockPolicySchema,
|
|
41
|
+
reclaimedStale: z.boolean()
|
|
42
|
+
}).strict().readonly(),
|
|
43
|
+
received: z.number().int().nonnegative(),
|
|
44
|
+
accepted: z.number().int().nonnegative(),
|
|
45
|
+
refused: z.number().int().nonnegative(),
|
|
46
|
+
refusals: DiagnosticJournalRefusalCountersSchema,
|
|
47
|
+
written: z.number().int().nonnegative(),
|
|
48
|
+
failedRecords: z.number().int().nonnegative(),
|
|
49
|
+
pendingItems: z.number().int().nonnegative(),
|
|
50
|
+
pendingBytes: z.number().int().nonnegative(),
|
|
51
|
+
inFlight: z.boolean(),
|
|
52
|
+
rotations: z.number().int().nonnegative(),
|
|
53
|
+
rotationFailures: z.number().int().nonnegative(),
|
|
54
|
+
partialTails: z.number().int().nonnegative(),
|
|
55
|
+
currentFileBytes: z.number().int().nonnegative(),
|
|
56
|
+
retainedFiles: z.number().int().nonnegative(),
|
|
57
|
+
lastAcceptedSequence: z.number().int().positive().optional(),
|
|
58
|
+
lastWrittenSequence: z.number().int().positive().optional(),
|
|
59
|
+
lastSettledSequence: z.number().int().positive().optional(),
|
|
60
|
+
lastFailure: z.object({
|
|
61
|
+
phase: DiagnosticJournalFailurePhaseSchema,
|
|
62
|
+
sequence: z.number().int().positive().optional()
|
|
63
|
+
}).strict().readonly().optional()
|
|
64
|
+
}).strict().readonly();
|
|
65
|
+
var DiagnosticJournalSubmitResultSchema = z.discriminatedUnion("outcome", [
|
|
66
|
+
z.object({
|
|
67
|
+
outcome: z.literal("accepted"),
|
|
68
|
+
epoch: z.uuid(),
|
|
69
|
+
sequence: z.number().int().positive()
|
|
70
|
+
}).strict().readonly(),
|
|
71
|
+
z.object({
|
|
72
|
+
outcome: z.literal("refused"),
|
|
73
|
+
reason: DiagnosticJournalRefusalReasonSchema
|
|
74
|
+
}).strict().readonly()
|
|
75
|
+
]);
|
|
76
|
+
var DiagnosticJournalWaitResultSchema = z.object({
|
|
77
|
+
outcome: z.enum(["settled", "timed-out", "cancelled"]),
|
|
78
|
+
state: DiagnosticJournalStateSchema,
|
|
79
|
+
throughSequence: z.number().int().nonnegative(),
|
|
80
|
+
settledSequence: z.number().int().nonnegative()
|
|
81
|
+
}).strict().readonly();
|
|
82
|
+
var DiagnosticJournalCloseResultSchema = z.object({
|
|
83
|
+
outcome: z.enum(["closed", "timed-out", "cancelled"]),
|
|
84
|
+
state: DiagnosticJournalStateSchema,
|
|
85
|
+
pendingItems: z.number().int().nonnegative()
|
|
86
|
+
}).strict().readonly();
|
|
87
|
+
var DiagnosticJournalFrameSchema = z.object({
|
|
88
|
+
schemaVersion: z.literal(1),
|
|
89
|
+
epoch: z.uuid(),
|
|
90
|
+
sequence: z.number().int().positive(),
|
|
91
|
+
event: z.json()
|
|
92
|
+
}).strict().readonly();
|
|
93
|
+
function parseDiagnosticJournalMode(mode) {
|
|
94
|
+
return FileModeSchema.parse(mode ?? 384);
|
|
95
|
+
}
|
|
96
|
+
function readDiagnosticJournalLockDiagnosis(error) {
|
|
97
|
+
if (!isRecord(error))
|
|
98
|
+
return;
|
|
99
|
+
const diagnosis = error.journalLock;
|
|
100
|
+
return isRecord(diagnosis) ? diagnosis : undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { DiagnosticJournalLimitsSchema, DiagnosticJournalLockPolicySchema, DiagnosticJournalStateSchema, DiagnosticJournalRefusalReasonSchema, DiagnosticJournalFailurePhaseSchema, DiagnosticJournalStatusSchema, DiagnosticJournalSubmitResultSchema, DiagnosticJournalWaitResultSchema, DiagnosticJournalCloseResultSchema, DiagnosticJournalFrameSchema, parseDiagnosticJournalMode, readDiagnosticJournalLockDiagnosis };
|
|
@@ -2,20 +2,22 @@ import {
|
|
|
2
2
|
contextContributionDelta,
|
|
3
3
|
mergeContextContribution,
|
|
4
4
|
prepareContextContribution
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-m9kzax52.js";
|
|
6
6
|
import {
|
|
7
7
|
base64UrlToBytes,
|
|
8
|
-
bytesToBase64Url
|
|
9
|
-
|
|
10
|
-
safeJsonParse
|
|
11
|
-
} from "./index-vj3vvpaa.js";
|
|
8
|
+
bytesToBase64Url
|
|
9
|
+
} from "./index-y01f4223.js";
|
|
12
10
|
import {
|
|
13
11
|
forbidden,
|
|
14
12
|
unauthorized
|
|
15
13
|
} from "./index-0w9abg87.js";
|
|
14
|
+
import {
|
|
15
|
+
isUnsafeKey,
|
|
16
|
+
safeJsonParse
|
|
17
|
+
} from "./index-kzfs85xp.js";
|
|
16
18
|
import {
|
|
17
19
|
isRecord
|
|
18
|
-
} from "./index-
|
|
20
|
+
} from "./index-77fekveh.js";
|
|
19
21
|
|
|
20
22
|
// src/server/middleware/cookies.ts
|
|
21
23
|
function parseCookies(header) {
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppError
|
|
3
|
+
} from "./index-0w9abg87.js";
|
|
4
|
+
import {
|
|
5
|
+
isUnsafeKey
|
|
6
|
+
} from "./index-kzfs85xp.js";
|
|
1
7
|
import {
|
|
2
8
|
mapObjectTypeBoundary
|
|
3
|
-
} from "./index-
|
|
9
|
+
} from "./index-77fekveh.js";
|
|
4
10
|
|
|
5
11
|
// src/contract/define.ts
|
|
6
12
|
import { z } from "zod";
|
|
7
13
|
|
|
8
14
|
// src/internal/route-pattern.ts
|
|
9
15
|
var PARAM_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
16
|
+
function joinRoutePath(...parts) {
|
|
17
|
+
const joined = parts.filter((part) => Boolean(part)).map((part) => part.replace(/^\/+|\/+$/g, "")).filter(Boolean).join("/");
|
|
18
|
+
return `/${joined}`;
|
|
19
|
+
}
|
|
10
20
|
function parseTrailingWildcard(path) {
|
|
11
21
|
const segments = path.split("/").filter(Boolean);
|
|
12
22
|
const paramNames = new Set;
|
|
@@ -47,11 +57,6 @@ function parseTrailingWildcard(path) {
|
|
|
47
57
|
return wildcard;
|
|
48
58
|
}
|
|
49
59
|
|
|
50
|
-
// src/internal/safe-json.ts
|
|
51
|
-
function isUnsafeKey(key) {
|
|
52
|
-
return key === "__proto__";
|
|
53
|
-
}
|
|
54
|
-
|
|
55
60
|
// src/contract/define.ts
|
|
56
61
|
var ALL_TRANSPORTS = ["HTTP", "MCP", "AGENT", "CLI"];
|
|
57
62
|
function defineContract(meta, endpoints) {
|
|
@@ -259,92 +264,12 @@ function assertResponseMetaEndpoint(prefix, key, ep) {
|
|
|
259
264
|
throw new Error(`${where} is HTTP-only — remove ${nonHttp.join(", ")} from expose`);
|
|
260
265
|
}
|
|
261
266
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
details;
|
|
269
|
-
hint;
|
|
270
|
-
traceId;
|
|
271
|
-
constructor(code, message, status = 500, details, hint, traceId) {
|
|
272
|
-
super(message ?? code);
|
|
273
|
-
this.code = code;
|
|
274
|
-
this.status = status;
|
|
275
|
-
this.details = details;
|
|
276
|
-
this.hint = hint;
|
|
277
|
-
this.traceId = traceId;
|
|
278
|
-
this.name = "AppError";
|
|
279
|
-
Object.defineProperty(this, APP_ERROR_BRAND, { value: true });
|
|
280
|
-
}
|
|
281
|
-
static is(err) {
|
|
282
|
-
return typeof err === "object" && err !== null && APP_ERROR_BRAND in err;
|
|
283
|
-
}
|
|
284
|
-
toJSON() {
|
|
285
|
-
return {
|
|
286
|
-
error: {
|
|
287
|
-
code: this.code,
|
|
288
|
-
message: this.message,
|
|
289
|
-
...this.details && { details: this.details },
|
|
290
|
-
...this.hint && { hint: this.hint }
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
function notFound(message = "Not found") {
|
|
296
|
-
throw new AppError("NOT_FOUND", message, 404);
|
|
297
|
-
}
|
|
298
|
-
function badRequest(message, details) {
|
|
299
|
-
throw new AppError("BAD_REQUEST", message, 400, details);
|
|
300
|
-
}
|
|
301
|
-
function unauthorized(message = "Unauthorized") {
|
|
302
|
-
throw new AppError("UNAUTHORIZED", message, 401);
|
|
303
|
-
}
|
|
304
|
-
function forbidden(message = "Forbidden") {
|
|
305
|
-
throw new AppError("FORBIDDEN", message, 403);
|
|
306
|
-
}
|
|
307
|
-
function conflict(message = "Conflict", details) {
|
|
308
|
-
throw new AppError("CONFLICT", message, 409, details);
|
|
309
|
-
}
|
|
310
|
-
function rateLimited(message = "Too many requests") {
|
|
311
|
-
throw new AppError("RATE_LIMITED", message, 429);
|
|
312
|
-
}
|
|
313
|
-
var STITCH_ERROR_STATUS = {
|
|
314
|
-
BAD_REQUEST: 400,
|
|
315
|
-
UNAUTHORIZED: 401,
|
|
316
|
-
FORBIDDEN: 403,
|
|
317
|
-
NOT_FOUND: 404,
|
|
318
|
-
METHOD_NOT_ALLOWED: 405,
|
|
319
|
-
CONFLICT: 409,
|
|
320
|
-
RATE_LIMITED: 429,
|
|
321
|
-
VALIDATION_ERROR: 400,
|
|
322
|
-
FILE_INVALID_PATH: 400,
|
|
323
|
-
FILE_OUTSIDE_ROOT: 400,
|
|
324
|
-
FILE_NOT_FOUND: 404,
|
|
325
|
-
FILE_NOT_REGULAR: 422,
|
|
326
|
-
FILE_INSPECTION_REJECTED: 422,
|
|
327
|
-
FILE_TOO_LARGE: 413,
|
|
328
|
-
FILE_EXISTS: 409,
|
|
329
|
-
REALTIME_CONTRACT_VIOLATION: 500,
|
|
330
|
-
APPLICATION_NOT_ACCEPTING: 503,
|
|
331
|
-
GRAMMY_WEBHOOK_NOT_ACCEPTING: 503,
|
|
332
|
-
WAIT_TIMEOUT: 408,
|
|
333
|
-
WAIT_FAILED: 409,
|
|
334
|
-
DOWNLOAD_NOT_FOUND: 404,
|
|
335
|
-
VIEW_HTTP_ERROR: 502,
|
|
336
|
-
OPERATION_NOT_SUCCEEDED: 409,
|
|
337
|
-
STREAM_ITEM_INVALID: 500,
|
|
338
|
-
STREAM_FRAME_TOO_LARGE: 500,
|
|
339
|
-
STREAM_TERMINAL_MISSING: 500,
|
|
340
|
-
STREAM_LIFETIME_EXCEEDED: 408,
|
|
341
|
-
INTERNAL_SERVER_ERROR: 500
|
|
342
|
-
};
|
|
343
|
-
function isStitchErrorCode(code) {
|
|
344
|
-
return Object.hasOwn(STITCH_ERROR_STATUS, code);
|
|
345
|
-
}
|
|
346
|
-
function appError(code, message, details) {
|
|
347
|
-
throw new AppError(code, message, isStitchErrorCode(code) ? STITCH_ERROR_STATUS[code] : 500, details);
|
|
267
|
+
function mergeMeta(contractMeta, endpointMeta) {
|
|
268
|
+
if (!contractMeta)
|
|
269
|
+
return endpointMeta;
|
|
270
|
+
if (!endpointMeta)
|
|
271
|
+
return { ...contractMeta };
|
|
272
|
+
return { ...contractMeta, ...endpointMeta };
|
|
348
273
|
}
|
|
349
274
|
// src/contract/errors-factory.ts
|
|
350
275
|
import { z as z2 } from "zod";
|
|
@@ -411,26 +336,8 @@ function createContractFactory(config) {
|
|
|
411
336
|
};
|
|
412
337
|
return { defineContract: explicit };
|
|
413
338
|
}
|
|
414
|
-
// src/contract/file-ref.ts
|
|
415
|
-
import { z as z3 } from "zod";
|
|
416
|
-
function isManagedFilePath(value) {
|
|
417
|
-
if (value.length === 0 || value.includes("\x00") || value.includes("\\"))
|
|
418
|
-
return false;
|
|
419
|
-
if (value.startsWith("/") || value.startsWith("//") || /^[A-Za-z]:/.test(value)) {
|
|
420
|
-
return false;
|
|
421
|
-
}
|
|
422
|
-
const parts = value.split("/");
|
|
423
|
-
return parts.every((part) => part.length > 0 && part !== "." && part !== "..");
|
|
424
|
-
}
|
|
425
|
-
var ManagedFilePathSchema = z3.string().refine(isManagedFilePath, "expected a canonical relative managed-file path");
|
|
426
|
-
var ManagedFileRefSchema = z3.object({
|
|
427
|
-
path: ManagedFilePathSchema,
|
|
428
|
-
size: z3.number().int().nonnegative(),
|
|
429
|
-
mediaType: z3.string().min(1).optional(),
|
|
430
|
-
name: z3.string().min(1).optional()
|
|
431
|
-
});
|
|
432
339
|
// src/contract/pagination.ts
|
|
433
|
-
import { z as
|
|
340
|
+
import { z as z3 } from "zod";
|
|
434
341
|
|
|
435
342
|
// src/internal/base64url.ts
|
|
436
343
|
function bytesToBase64Url(bytes) {
|
|
@@ -450,9 +357,9 @@ function base64UrlToBytes(segment) {
|
|
|
450
357
|
|
|
451
358
|
// src/contract/pagination.ts
|
|
452
359
|
function paginatedSchema(itemSchema) {
|
|
453
|
-
return
|
|
454
|
-
items:
|
|
455
|
-
nextCursor:
|
|
360
|
+
return z3.object({
|
|
361
|
+
items: z3.array(itemSchema),
|
|
362
|
+
nextCursor: z3.string().nullable()
|
|
456
363
|
});
|
|
457
364
|
}
|
|
458
365
|
function toBase64Url(str) {
|
|
@@ -475,19 +382,19 @@ function decodeCursor(cursor, schema) {
|
|
|
475
382
|
}
|
|
476
383
|
}
|
|
477
384
|
// src/contract/stream.ts
|
|
478
|
-
import { z as
|
|
385
|
+
import { z as z4 } from "zod";
|
|
479
386
|
var DEFAULT_CONTRACT_STREAM_FRAME_BYTES = 256 * 1024;
|
|
480
|
-
var ContractStreamFrameSchema =
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
type:
|
|
484
|
-
error:
|
|
485
|
-
code:
|
|
486
|
-
message:
|
|
487
|
-
details:
|
|
488
|
-
hint:
|
|
387
|
+
var ContractStreamFrameSchema = z4.discriminatedUnion("type", [
|
|
388
|
+
z4.object({ type: z4.literal("data"), data: z4.unknown() }).strict(),
|
|
389
|
+
z4.object({
|
|
390
|
+
type: z4.literal("error"),
|
|
391
|
+
error: z4.object({
|
|
392
|
+
code: z4.string(),
|
|
393
|
+
message: z4.string().optional(),
|
|
394
|
+
details: z4.unknown().optional(),
|
|
395
|
+
hint: z4.string().optional()
|
|
489
396
|
}).strict()
|
|
490
397
|
}).strict(),
|
|
491
|
-
|
|
398
|
+
z4.object({ type: z4.literal("end") }).strict()
|
|
492
399
|
]);
|
|
493
|
-
export { parseTrailingWildcard, ALL_TRANSPORTS, defineContract,
|
|
400
|
+
export { joinRoutePath, parseTrailingWildcard, ALL_TRANSPORTS, defineContract, mergeMeta, defineErrors, createContractFactory, bytesToBase64Url, base64UrlToBytes, paginatedSchema, encodeCursor, decodeCursor, DEFAULT_CONTRACT_STREAM_FRAME_BYTES, ContractStreamFrameSchema };
|
|
@@ -1,211 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
createBoundedChannel
|
|
3
|
+
} from "./index-7gnkny4z.js";
|
|
3
4
|
|
|
4
|
-
// src/
|
|
5
|
+
// src/browser/live-state.ts
|
|
5
6
|
import { z } from "zod";
|
|
6
7
|
var PositiveSafeIntegerSchema = z.number().int().positive().safe();
|
|
7
|
-
var
|
|
8
|
-
var BoundedChannelStateSchema = z.enum(["open", "draining", "closed", "failed"]);
|
|
9
|
-
var BoundedChannelSnapshotSchema = z.object({
|
|
10
|
-
state: BoundedChannelStateSchema,
|
|
11
|
-
policy: BoundedChannelPolicySchema,
|
|
12
|
-
queuedItems: z.number().int().nonnegative(),
|
|
13
|
-
queuedBytes: z.number().int().nonnegative(),
|
|
14
|
-
waitingReader: z.boolean(),
|
|
15
|
-
offered: z.number().int().nonnegative(),
|
|
16
|
-
delivered: z.number().int().nonnegative(),
|
|
17
|
-
queued: z.number().int().nonnegative(),
|
|
18
|
-
coalesced: z.number().int().nonnegative(),
|
|
19
|
-
refused: z.number().int().nonnegative(),
|
|
20
|
-
discarded: z.number().int().nonnegative()
|
|
21
|
-
}).strict().readonly();
|
|
22
|
-
|
|
23
|
-
class BoundedChannelReaderError extends Error {
|
|
24
|
-
constructor() {
|
|
25
|
-
super("A bounded channel permits only one pending next() call");
|
|
26
|
-
this.name = "BoundedChannelReaderError";
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function createBoundedChannel(config) {
|
|
30
|
-
const policy = BoundedChannelPolicySchema.parse(config.policy);
|
|
31
|
-
const maxItems = PositiveSafeIntegerSchema.parse(config.maxItems);
|
|
32
|
-
const maxBytes = PositiveSafeIntegerSchema.parse(config.maxBytes);
|
|
33
|
-
const queue = [];
|
|
34
|
-
let state = "open";
|
|
35
|
-
let queuedBytes = 0;
|
|
36
|
-
let waiting;
|
|
37
|
-
let failure;
|
|
38
|
-
let hasFailure = false;
|
|
39
|
-
let offered = 0;
|
|
40
|
-
let delivered = 0;
|
|
41
|
-
let queued = 0;
|
|
42
|
-
let coalesced = 0;
|
|
43
|
-
let refused = 0;
|
|
44
|
-
let discarded = 0;
|
|
45
|
-
const removeAbortListener = () => {
|
|
46
|
-
config.signal?.removeEventListener("abort", abortChannel);
|
|
47
|
-
};
|
|
48
|
-
const snapshot = () => BoundedChannelSnapshotSchema.parse({
|
|
49
|
-
state,
|
|
50
|
-
policy,
|
|
51
|
-
queuedItems: queue.length,
|
|
52
|
-
queuedBytes,
|
|
53
|
-
waitingReader: waiting !== undefined,
|
|
54
|
-
offered,
|
|
55
|
-
delivered,
|
|
56
|
-
queued,
|
|
57
|
-
coalesced,
|
|
58
|
-
refused,
|
|
59
|
-
discarded
|
|
60
|
-
});
|
|
61
|
-
const clearQueue = () => {
|
|
62
|
-
discarded += queue.length;
|
|
63
|
-
queue.length = 0;
|
|
64
|
-
queuedBytes = 0;
|
|
65
|
-
};
|
|
66
|
-
const settleClosed = () => {
|
|
67
|
-
if (state !== "draining" || queue.length > 0)
|
|
68
|
-
return;
|
|
69
|
-
state = "closed";
|
|
70
|
-
removeAbortListener();
|
|
71
|
-
const reader = waiting;
|
|
72
|
-
waiting = undefined;
|
|
73
|
-
reader?.resolve({ done: true, value: undefined });
|
|
74
|
-
};
|
|
75
|
-
const close = (options = {}) => {
|
|
76
|
-
if (state === "closed" || state === "failed")
|
|
77
|
-
return snapshot();
|
|
78
|
-
const mode = options.mode ?? "drain";
|
|
79
|
-
if (mode !== "drain" && mode !== "discard") {
|
|
80
|
-
throw new TypeError("Bounded channel close mode must be drain or discard");
|
|
81
|
-
}
|
|
82
|
-
if (mode === "discard") {
|
|
83
|
-
clearQueue();
|
|
84
|
-
state = "closed";
|
|
85
|
-
removeAbortListener();
|
|
86
|
-
const reader = waiting;
|
|
87
|
-
waiting = undefined;
|
|
88
|
-
reader?.resolve({ done: true, value: undefined });
|
|
89
|
-
return snapshot();
|
|
90
|
-
}
|
|
91
|
-
state = "draining";
|
|
92
|
-
settleClosed();
|
|
93
|
-
return snapshot();
|
|
94
|
-
};
|
|
95
|
-
function abortChannel() {
|
|
96
|
-
close({ mode: "discard" });
|
|
97
|
-
}
|
|
98
|
-
const channel = {
|
|
99
|
-
[Symbol.asyncIterator]() {
|
|
100
|
-
return channel;
|
|
101
|
-
},
|
|
102
|
-
offer(value) {
|
|
103
|
-
offered += 1;
|
|
104
|
-
if (state !== "open") {
|
|
105
|
-
refused += 1;
|
|
106
|
-
return { outcome: "refused", reason: "not-open" };
|
|
107
|
-
}
|
|
108
|
-
const bytes = config.sizeOf(value);
|
|
109
|
-
if (!Number.isSafeInteger(bytes) || bytes < 0) {
|
|
110
|
-
throw new TypeError("Bounded channel sizeOf() must return a non-negative safe integer");
|
|
111
|
-
}
|
|
112
|
-
if (bytes > maxBytes) {
|
|
113
|
-
refused += 1;
|
|
114
|
-
return { outcome: "refused", reason: "item-too-large" };
|
|
115
|
-
}
|
|
116
|
-
const reader = waiting;
|
|
117
|
-
if (reader) {
|
|
118
|
-
waiting = undefined;
|
|
119
|
-
delivered += 1;
|
|
120
|
-
reader.resolve({ done: false, value });
|
|
121
|
-
return { outcome: "delivered" };
|
|
122
|
-
}
|
|
123
|
-
if (policy === "latest" && queue.length > 0) {
|
|
124
|
-
const previous = queue[0];
|
|
125
|
-
if (!previous)
|
|
126
|
-
throw new Error("Bounded latest channel lost its pending value");
|
|
127
|
-
queue[0] = { value, bytes };
|
|
128
|
-
queuedBytes += bytes - previous.bytes;
|
|
129
|
-
coalesced += 1;
|
|
130
|
-
return { outcome: "coalesced", replaced: 1 };
|
|
131
|
-
}
|
|
132
|
-
if (queue.length >= maxItems) {
|
|
133
|
-
refused += 1;
|
|
134
|
-
return { outcome: "refused", reason: "item-capacity" };
|
|
135
|
-
}
|
|
136
|
-
if (queuedBytes + bytes > maxBytes) {
|
|
137
|
-
refused += 1;
|
|
138
|
-
return { outcome: "refused", reason: "byte-capacity" };
|
|
139
|
-
}
|
|
140
|
-
queue.push({ value, bytes });
|
|
141
|
-
queuedBytes += bytes;
|
|
142
|
-
queued += 1;
|
|
143
|
-
return { outcome: "queued" };
|
|
144
|
-
},
|
|
145
|
-
next() {
|
|
146
|
-
if (hasFailure)
|
|
147
|
-
return Promise.reject(failure);
|
|
148
|
-
const next = queue.shift();
|
|
149
|
-
if (next) {
|
|
150
|
-
queuedBytes -= next.bytes;
|
|
151
|
-
delivered += 1;
|
|
152
|
-
settleClosed();
|
|
153
|
-
return Promise.resolve({ done: false, value: next.value });
|
|
154
|
-
}
|
|
155
|
-
if (state === "closed" || state === "draining") {
|
|
156
|
-
settleClosed();
|
|
157
|
-
return Promise.resolve({ done: true, value: undefined });
|
|
158
|
-
}
|
|
159
|
-
if (waiting)
|
|
160
|
-
return Promise.reject(new BoundedChannelReaderError);
|
|
161
|
-
return new Promise((resolve, reject) => {
|
|
162
|
-
waiting = { resolve, reject };
|
|
163
|
-
});
|
|
164
|
-
},
|
|
165
|
-
return() {
|
|
166
|
-
close({ mode: "discard" });
|
|
167
|
-
return Promise.resolve({ done: true, value: undefined });
|
|
168
|
-
},
|
|
169
|
-
throw(error) {
|
|
170
|
-
channel.fail(error);
|
|
171
|
-
return Promise.reject(error);
|
|
172
|
-
},
|
|
173
|
-
close,
|
|
174
|
-
fail(error) {
|
|
175
|
-
if (state === "closed" || state === "failed")
|
|
176
|
-
return snapshot();
|
|
177
|
-
failure = error;
|
|
178
|
-
hasFailure = true;
|
|
179
|
-
state = "failed";
|
|
180
|
-
clearQueue();
|
|
181
|
-
removeAbortListener();
|
|
182
|
-
const reader = waiting;
|
|
183
|
-
waiting = undefined;
|
|
184
|
-
reader?.reject(error);
|
|
185
|
-
return snapshot();
|
|
186
|
-
},
|
|
187
|
-
getSnapshot: snapshot
|
|
188
|
-
};
|
|
189
|
-
if (config.signal?.aborted)
|
|
190
|
-
abortChannel();
|
|
191
|
-
else
|
|
192
|
-
config.signal?.addEventListener("abort", abortChannel, { once: true });
|
|
193
|
-
return channel;
|
|
194
|
-
}
|
|
195
|
-
var CreditWindowSnapshotSchema = z.object({
|
|
196
|
-
state: z.enum(["open", "closed"]),
|
|
197
|
-
capacityBytes: PositiveSafeIntegerSchema,
|
|
198
|
-
availableBytes: z.number().int().nonnegative(),
|
|
199
|
-
leasedBytes: z.number().int().nonnegative(),
|
|
200
|
-
acquired: z.number().int().nonnegative(),
|
|
201
|
-
refused: z.number().int().nonnegative(),
|
|
202
|
-
replenishedBytes: z.number().int().nonnegative(),
|
|
203
|
-
waiting: z.number().int().nonnegative()
|
|
204
|
-
}).strict().readonly();
|
|
205
|
-
|
|
206
|
-
// src/browser/live-state.ts
|
|
207
|
-
var PositiveSafeIntegerSchema2 = z2.number().int().positive().safe();
|
|
208
|
-
var LiveStatePhaseSchema = z2.enum([
|
|
8
|
+
var LiveStatePhaseSchema = z.enum([
|
|
209
9
|
"idle",
|
|
210
10
|
"opening",
|
|
211
11
|
"live",
|
|
@@ -213,7 +13,7 @@ var LiveStatePhaseSchema = z2.enum([
|
|
|
213
13
|
"unavailable",
|
|
214
14
|
"closed"
|
|
215
15
|
]);
|
|
216
|
-
var LiveStateStopReasonSchema =
|
|
16
|
+
var LiveStateStopReasonSchema = z.enum([
|
|
217
17
|
"gap",
|
|
218
18
|
"buffer-overflow",
|
|
219
19
|
"source-unavailable",
|
|
@@ -221,22 +21,22 @@ var LiveStateStopReasonSchema = z2.enum([
|
|
|
221
21
|
"controller-error",
|
|
222
22
|
"controller-capacity"
|
|
223
23
|
]);
|
|
224
|
-
var LiveStateControllerStatusSchema =
|
|
24
|
+
var LiveStateControllerStatusSchema = z.object({
|
|
225
25
|
phase: LiveStatePhaseSchema,
|
|
226
|
-
generation:
|
|
227
|
-
hasValue:
|
|
228
|
-
bufferedEvents:
|
|
229
|
-
bufferedBytes:
|
|
230
|
-
receivedEvents:
|
|
231
|
-
appliedEvents:
|
|
232
|
-
duplicateEvents:
|
|
233
|
-
gapEvents:
|
|
234
|
-
refusedEvents:
|
|
26
|
+
generation: z.number().int().nonnegative(),
|
|
27
|
+
hasValue: z.boolean(),
|
|
28
|
+
bufferedEvents: z.number().int().nonnegative(),
|
|
29
|
+
bufferedBytes: z.number().int().nonnegative(),
|
|
30
|
+
receivedEvents: z.number().int().nonnegative(),
|
|
31
|
+
appliedEvents: z.number().int().nonnegative(),
|
|
32
|
+
duplicateEvents: z.number().int().nonnegative(),
|
|
33
|
+
gapEvents: z.number().int().nonnegative(),
|
|
34
|
+
refusedEvents: z.number().int().nonnegative(),
|
|
235
35
|
reason: LiveStateStopReasonSchema.optional()
|
|
236
36
|
}).strict().readonly();
|
|
237
37
|
function createLiveStateController(config) {
|
|
238
|
-
const maxBufferedEvents =
|
|
239
|
-
const maxBufferedBytes =
|
|
38
|
+
const maxBufferedEvents = PositiveSafeIntegerSchema.parse(config.maxBufferedEvents);
|
|
39
|
+
const maxBufferedBytes = PositiveSafeIntegerSchema.parse(config.maxBufferedBytes);
|
|
240
40
|
const subscribers = new Set;
|
|
241
41
|
let phase = "idle";
|
|
242
42
|
let reason;
|