stitchkit 0.77.0 → 0.78.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-coding-tools.js +1 -1
- package/dist/agent-runtime-harness.js +6 -6
- package/dist/agent-runtime.js +11 -11
- 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/server-resource.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 +714 -0
- package/dist/application-opentelemetry.js +92 -5
- package/dist/application-schemas.js +13 -98
- package/dist/application.d.ts +1 -2
- package/dist/application.d.ts.map +1 -1
- package/dist/application.js +1775 -858
- package/dist/cli.js +7 -7
- package/dist/contract/index.js +9 -7
- package/dist/files/boundary.d.ts.map +1 -1
- package/dist/files.js +1 -1
- package/dist/{index-3z73fh2c.js → index-1ckavx4h.js} +49 -1
- package/dist/{index-s2rchahr.js → index-31k1ns1s.js} +4 -4
- package/dist/{index-m668wzyc.js → index-4ntp63ps.js} +4 -4
- package/dist/{index-1rxswfbv.js → index-56fm73re.js} +1 -1
- package/dist/{index-ezmn6ac6.js → index-5r0ak8fr.js} +3 -3
- package/dist/{index-f6n5n7nz.js → index-7z69kyrh.js} +10 -87
- package/dist/{index-k2zczx1g.js → index-93xp5tgg.js} +1 -1
- package/dist/{index-bfcpjw20.js → index-actkayzn.js} +7 -3
- package/dist/index-anyqnqcv.js +79 -0
- package/dist/{index-7qy2ex0m.js → index-cwp38wxn.js} +1 -1
- package/dist/{index-35z5h2ty.js → index-dmfn9m4x.js} +125 -4
- package/dist/index-h4pj6fta.js +87 -0
- package/dist/{index-jqtsc9mj.js → index-j6mfaw26.js} +2 -2
- package/dist/{index-58jzmnn4.js → index-k45qqrdh.js} +513 -39
- package/dist/{index-8eywc9zv.js → index-kw12fsbc.js} +0 -1
- package/dist/index-n1g2xm6a.js +203 -0
- package/dist/{index-t8qyvrvg.js → index-n7apa6sy.js} +12 -12
- package/dist/{index-s4c8wy8m.js → index-qaajjfp6.js} +8 -8
- package/dist/{index-nemjkxjp.js → index-s5tn4kdv.js} +14 -10
- package/dist/index-wfq8zerm.js +92 -0
- package/dist/index.js +53 -1215
- package/dist/internal/deadline.d.ts +17 -0
- package/dist/internal/deadline.d.ts.map +1 -0
- package/dist/live.js +12 -89
- package/dist/node.js +5 -6
- package/dist/observability/context.d.ts.map +1 -1
- package/dist/observability/index.js +3 -3
- package/dist/primitives.js +2 -1
- package/dist/remote.js +3 -6
- package/dist/server/event-bus.d.ts.map +1 -1
- package/dist/server/index.js +31 -30
- package/dist/testing.js +1562 -87
- package/dist/tool-invoker.js +6 -6
- package/dist/tools.js +66 -23
- package/llms-full.txt +110 -13
- package/package.json +8 -4
- package/dist/index-3cwck0rm.js +0 -897
- package/dist/index-7b188kmz.js +0 -49
- package/dist/index-a916km3r.js +0 -45
- package/dist/index-vc1b0b1b.js +0 -825
- package/dist/{index-da1aqnhb.js → index-aewy3x5j.js} +3 -3
- package/dist/{index-nt1mp8km.js → index-efm026pw.js} +3 -3
package/dist/cli.js
CHANGED
|
@@ -5,19 +5,19 @@ import {
|
|
|
5
5
|
emitResult,
|
|
6
6
|
parseCliArgs,
|
|
7
7
|
pollUntilDone
|
|
8
|
-
} from "./index-
|
|
9
|
-
import"./index-
|
|
8
|
+
} from "./index-31k1ns1s.js";
|
|
9
|
+
import"./index-93xp5tgg.js";
|
|
10
10
|
import"./index-wwst0td5.js";
|
|
11
|
-
import"./index-
|
|
12
|
-
import"./index-
|
|
13
|
-
import"./index-nemjkxjp.js";
|
|
11
|
+
import"./index-cwp38wxn.js";
|
|
12
|
+
import"./index-qaajjfp6.js";
|
|
14
13
|
import"./index-sbdmyz75.js";
|
|
15
14
|
import"./index-22by16v6.js";
|
|
16
15
|
import"./index-cby4ar3v.js";
|
|
17
|
-
import"./index-
|
|
16
|
+
import"./index-s5tn4kdv.js";
|
|
17
|
+
import"./index-efm026pw.js";
|
|
18
18
|
import"./index-vj3vvpaa.js";
|
|
19
|
-
import"./index-0w9abg87.js";
|
|
20
19
|
import"./index-qyrqwr4c.js";
|
|
20
|
+
import"./index-0w9abg87.js";
|
|
21
21
|
import"./index-6k1937bx.js";
|
|
22
22
|
export {
|
|
23
23
|
pollUntilDone,
|
package/dist/contract/index.js
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ALL_TRANSPORTS,
|
|
3
|
-
AppError,
|
|
4
3
|
ContractStreamFrameSchema,
|
|
5
4
|
DEFAULT_CONTRACT_STREAM_FRAME_BYTES,
|
|
6
5
|
ManagedFilePathSchema,
|
|
7
6
|
ManagedFileRefSchema,
|
|
8
|
-
STITCH_ERROR_STATUS,
|
|
9
|
-
appError,
|
|
10
|
-
badRequest,
|
|
11
|
-
conflict,
|
|
12
7
|
createContractFactory,
|
|
13
8
|
decodeCursor,
|
|
14
9
|
defineContract,
|
|
15
10
|
defineErrors,
|
|
16
11
|
encodeCursor,
|
|
12
|
+
paginatedSchema
|
|
13
|
+
} from "../index-7z69kyrh.js";
|
|
14
|
+
import {
|
|
15
|
+
AppError,
|
|
16
|
+
STITCH_ERROR_STATUS,
|
|
17
|
+
appError,
|
|
18
|
+
badRequest,
|
|
19
|
+
conflict,
|
|
17
20
|
forbidden,
|
|
18
21
|
isStitchErrorCode,
|
|
19
22
|
notFound,
|
|
20
|
-
paginatedSchema,
|
|
21
23
|
rateLimited,
|
|
22
24
|
unauthorized
|
|
23
|
-
} from "../index-
|
|
25
|
+
} from "../index-0w9abg87.js";
|
|
24
26
|
import"../index-ksp6e2ye.js";
|
|
25
27
|
export {
|
|
26
28
|
unauthorized,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../../src/files/boundary.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,cAAc,EAEpB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../../src/files/boundary.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,cAAc,EAEpB,MAAM,sBAAsB,CAAC;AAqB9B,MAAM,MAAM,oBAAoB,GAC5B,mBAAmB,GACnB,gBAAgB,GAChB,kBAAkB,GAClB,mBAAmB,GACnB,gBAAgB,GAChB,aAAa,GACb,0BAA0B,GAC1B,eAAe,CAAC;AAEpB,qBAAa,gBAAiB,SAAQ,KAAK;aAEvB,IAAI,EAAE,oBAAoB;IAD5C,YACkB,IAAI,EAAE,oBAAoB,EAC1C,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,YAAY,EAIvB;CACF;AAED,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,UAAU,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,oEAAoE;IACpE,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,cAAc,EAAE,WAAW,GAAG,MAAM,CAAC,CAAC;AAE/E,MAAM,MAAM,oBAAoB,GAAG,CACjC,KAAK,EAAE,0BAA0B,KAC9B,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAE5D,MAAM,WAAW,yBAAyB;IACxC,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAC;IACb,uFAAuF;IACvF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,wEAAwE;IACxE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAC3C;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,cAAc,CAAC;IACpB,KAAK,EAAE,UAAU,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACjF,KAAK,CACH,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC,EAC/C,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,cAAc,CAAC,CAAC;CAC5B;AAmRD;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,mBAAmB,CAAC,CAyJ9B"}
|
package/dist/files.js
CHANGED
|
@@ -329,4 +329,52 @@ function createServerLifecycle(getAdapter) {
|
|
|
329
329
|
};
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
|
|
332
|
+
// src/realtime/request.ts
|
|
333
|
+
import { z as z2 } from "zod";
|
|
334
|
+
var RealtimeRequestPhaseSchema = z2.enum([
|
|
335
|
+
"engine-handoff",
|
|
336
|
+
"engine-ack-received",
|
|
337
|
+
"settled",
|
|
338
|
+
"timeout",
|
|
339
|
+
"disconnected"
|
|
340
|
+
]);
|
|
341
|
+
var RealtimeRequestPhaseEventSchema = z2.object({
|
|
342
|
+
requestId: z2.string().min(1),
|
|
343
|
+
event: z2.string().min(1),
|
|
344
|
+
phase: RealtimeRequestPhaseSchema,
|
|
345
|
+
elapsedMs: z2.number().finite().nonnegative()
|
|
346
|
+
}).strict();
|
|
347
|
+
|
|
348
|
+
class RealtimeRequestTimeoutError extends Error {
|
|
349
|
+
code = "REALTIME_REQUEST_TIMEOUT";
|
|
350
|
+
event;
|
|
351
|
+
timeoutMs;
|
|
352
|
+
constructor(event, timeoutMs) {
|
|
353
|
+
super(`Realtime request "${event}" timed out after ${timeoutMs}ms`);
|
|
354
|
+
this.name = "RealtimeRequestTimeoutError";
|
|
355
|
+
this.event = event;
|
|
356
|
+
this.timeoutMs = timeoutMs;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
class RealtimeRequestDisconnectedError extends Error {
|
|
361
|
+
code = "REALTIME_REQUEST_DISCONNECTED";
|
|
362
|
+
event;
|
|
363
|
+
constructor(event) {
|
|
364
|
+
super(`Realtime request "${event}" was interrupted by disconnect`);
|
|
365
|
+
this.name = "RealtimeRequestDisconnectedError";
|
|
366
|
+
this.event = event;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
class RealtimeRequestInvalidAcknowledgementError extends Error {
|
|
371
|
+
code = "REALTIME_REQUEST_INVALID_ACKNOWLEDGEMENT";
|
|
372
|
+
event;
|
|
373
|
+
constructor(event, cause) {
|
|
374
|
+
super(`Realtime request "${event}" received an invalid acknowledgement`, { cause });
|
|
375
|
+
this.name = "RealtimeRequestInvalidAcknowledgementError";
|
|
376
|
+
this.event = event;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export { isStreamCancellation, ownHttpStream, settleStreamCleanup, ShutdownStateSchema, ShutdownOptionsSchema, ShutdownStatusSchema, ShutdownResultSchema, createServerLifecycle, RealtimeRequestTimeoutError, RealtimeRequestDisconnectedError, RealtimeRequestInvalidAcknowledgementError };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
collectToolSurface
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-93xp5tgg.js";
|
|
4
4
|
import {
|
|
5
5
|
createToolRunner,
|
|
6
6
|
formatToolError
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-cwp38wxn.js";
|
|
8
8
|
import {
|
|
9
9
|
coerceJsonArgs,
|
|
10
10
|
toolResultFromError
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-qaajjfp6.js";
|
|
12
12
|
import {
|
|
13
13
|
isWithinDir
|
|
14
14
|
} from "./index-sbdmyz75.js";
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import {
|
|
24
24
|
formatZodError,
|
|
25
25
|
validateDeclaredOutput
|
|
26
|
-
} from "./index-
|
|
26
|
+
} from "./index-efm026pw.js";
|
|
27
27
|
import {
|
|
28
28
|
isUnsafeKey,
|
|
29
29
|
safeJsonParse
|
|
@@ -6,16 +6,13 @@ import {
|
|
|
6
6
|
isAssistantHistoryEvidence,
|
|
7
7
|
isCompleteAgentHistoryTurn
|
|
8
8
|
} from "./index-y2s6h5bf.js";
|
|
9
|
-
import {
|
|
10
|
-
createBoundedSinkManager
|
|
11
|
-
} from "./index-a59da114.js";
|
|
12
9
|
import {
|
|
13
10
|
isAgentToolError
|
|
14
11
|
} from "./index-3xnq72rz.js";
|
|
15
12
|
import {
|
|
16
13
|
ToolExecutionControlError,
|
|
17
14
|
isToolExecutionControlError
|
|
18
|
-
} from "./index-
|
|
15
|
+
} from "./index-qaajjfp6.js";
|
|
19
16
|
import {
|
|
20
17
|
AgentAssistantPlaceholderSchema,
|
|
21
18
|
AgentJsonObjectSchema,
|
|
@@ -33,6 +30,9 @@ import {
|
|
|
33
30
|
AgentTimestampSchema,
|
|
34
31
|
runStateForTerminalReason
|
|
35
32
|
} from "./index-x1th9s8c.js";
|
|
33
|
+
import {
|
|
34
|
+
createBoundedSinkManager
|
|
35
|
+
} from "./index-a59da114.js";
|
|
36
36
|
import {
|
|
37
37
|
isRecord,
|
|
38
38
|
transportResult
|
|
@@ -3,15 +3,15 @@ import {
|
|
|
3
3
|
} from "./index-3xnq72rz.js";
|
|
4
4
|
import {
|
|
5
5
|
collectToolSurface
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-93xp5tgg.js";
|
|
7
7
|
import {
|
|
8
8
|
createToolRunner,
|
|
9
9
|
formatToolError
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-cwp38wxn.js";
|
|
11
11
|
import {
|
|
12
12
|
isToolExecutionControlError,
|
|
13
13
|
toolResultFromError
|
|
14
|
-
} from "./index-
|
|
14
|
+
} from "./index-qaajjfp6.js";
|
|
15
15
|
import {
|
|
16
16
|
isRecord
|
|
17
17
|
} from "./index-qyrqwr4c.js";
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppError
|
|
3
|
+
} from "./index-0w9abg87.js";
|
|
1
4
|
import {
|
|
2
5
|
mapObjectTypeBoundary
|
|
3
6
|
} from "./index-ksp6e2ye.js";
|
|
@@ -259,92 +262,12 @@ function assertResponseMetaEndpoint(prefix, key, ep) {
|
|
|
259
262
|
throw new Error(`${where} is HTTP-only — remove ${nonHttp.join(", ")} from expose`);
|
|
260
263
|
}
|
|
261
264
|
}
|
|
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);
|
|
265
|
+
function mergeMeta(contractMeta, endpointMeta) {
|
|
266
|
+
if (!contractMeta)
|
|
267
|
+
return endpointMeta;
|
|
268
|
+
if (!endpointMeta)
|
|
269
|
+
return { ...contractMeta };
|
|
270
|
+
return { ...contractMeta, ...endpointMeta };
|
|
348
271
|
}
|
|
349
272
|
// src/contract/errors-factory.ts
|
|
350
273
|
import { z as z2 } from "zod";
|
|
@@ -490,4 +413,4 @@ var ContractStreamFrameSchema = z5.discriminatedUnion("type", [
|
|
|
490
413
|
}).strict(),
|
|
491
414
|
z5.object({ type: z5.literal("end") }).strict()
|
|
492
415
|
]);
|
|
493
|
-
export { parseTrailingWildcard, ALL_TRANSPORTS, defineContract,
|
|
416
|
+
export { parseTrailingWildcard, ALL_TRANSPORTS, defineContract, mergeMeta, defineErrors, createContractFactory, ManagedFilePathSchema, ManagedFileRefSchema, paginatedSchema, encodeCursor, decodeCursor, DEFAULT_CONTRACT_STREAM_FRAME_BYTES, ContractStreamFrameSchema };
|
|
@@ -14,7 +14,11 @@ import { basename, dirname, resolve } from "node:path";
|
|
|
14
14
|
var DEFAULT_MAX_BYTES = 100 * 1024 * 1024;
|
|
15
15
|
var DEFAULT_INSPECTION_BYTES = 64 * 1024;
|
|
16
16
|
var DEFAULT_INSPECTION_TIMEOUT_MS = 15000;
|
|
17
|
-
var
|
|
17
|
+
var nofollowFlag;
|
|
18
|
+
var noFollow = () => {
|
|
19
|
+
nofollowFlag ??= constants.O_NOFOLLOW ?? 0;
|
|
20
|
+
return nofollowFlag;
|
|
21
|
+
};
|
|
18
22
|
var ManagedFileInspectionSchema = ManagedFileRefSchema.pick({
|
|
19
23
|
mediaType: true,
|
|
20
24
|
name: true
|
|
@@ -273,7 +277,7 @@ async function createManagedFileBoundary(config) {
|
|
|
273
277
|
const maxBytes = positiveLimit(options.maxBytes, maxReadBytes, "maxBytes");
|
|
274
278
|
let handle;
|
|
275
279
|
try {
|
|
276
|
-
handle = await open(realTarget, constants.O_RDONLY |
|
|
280
|
+
handle = await open(realTarget, constants.O_RDONLY | noFollow());
|
|
277
281
|
const info = await handle.stat();
|
|
278
282
|
if (!info.isFile()) {
|
|
279
283
|
throw new ManagedFileError("FILE_NOT_REGULAR", "managed path is not a regular file");
|
|
@@ -310,7 +314,7 @@ async function createManagedFileBoundary(config) {
|
|
|
310
314
|
let committed = false;
|
|
311
315
|
let size = 0;
|
|
312
316
|
try {
|
|
313
|
-
handle = await open(temporary, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY |
|
|
317
|
+
handle = await open(temporary, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | noFollow(), 384);
|
|
314
318
|
const written = await writeSource(handle, source, maxBytes, inspectionBytes, options.signal);
|
|
315
319
|
size = written.size;
|
|
316
320
|
if (options.durable)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// src/application/schemas.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var ApplicationIdSchema = z.string().min(1).max(128).regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]*$/);
|
|
4
|
+
var ApplicationLifecycleSchema = z.enum([
|
|
5
|
+
"created",
|
|
6
|
+
"starting",
|
|
7
|
+
"ready",
|
|
8
|
+
"draining",
|
|
9
|
+
"stopping",
|
|
10
|
+
"stopped",
|
|
11
|
+
"failed"
|
|
12
|
+
]);
|
|
13
|
+
var ApplicationHealthSchema = z.enum(["unknown", "healthy", "degraded", "unhealthy"]);
|
|
14
|
+
var ManagedResourceStateSchema = z.enum([
|
|
15
|
+
"registered",
|
|
16
|
+
"starting",
|
|
17
|
+
"ready",
|
|
18
|
+
"failed",
|
|
19
|
+
"stopping",
|
|
20
|
+
"stopped"
|
|
21
|
+
]);
|
|
22
|
+
var NonNegativeIntegerSchema = z.number().int().nonnegative();
|
|
23
|
+
var ApplicationAdmissionSnapshotSchema = z.object({
|
|
24
|
+
accepting: z.boolean(),
|
|
25
|
+
accepted: NonNegativeIntegerSchema,
|
|
26
|
+
completed: NonNegativeIntegerSchema,
|
|
27
|
+
pending: NonNegativeIntegerSchema
|
|
28
|
+
}).readonly();
|
|
29
|
+
var ManagedResourceSnapshotSchema = z.object({
|
|
30
|
+
id: ApplicationIdSchema,
|
|
31
|
+
required: z.boolean(),
|
|
32
|
+
dependsOn: z.array(ApplicationIdSchema).readonly(),
|
|
33
|
+
state: ManagedResourceStateSchema,
|
|
34
|
+
health: ApplicationHealthSchema,
|
|
35
|
+
ready: z.boolean()
|
|
36
|
+
}).readonly();
|
|
37
|
+
var ApplicationSnapshotSchema = z.object({
|
|
38
|
+
id: ApplicationIdSchema,
|
|
39
|
+
epoch: z.string().uuid(),
|
|
40
|
+
revision: NonNegativeIntegerSchema,
|
|
41
|
+
lifecycle: ApplicationLifecycleSchema,
|
|
42
|
+
health: ApplicationHealthSchema,
|
|
43
|
+
ready: z.boolean(),
|
|
44
|
+
capturedAt: z.string().datetime({ offset: true }),
|
|
45
|
+
changedAt: z.string().datetime({ offset: true }),
|
|
46
|
+
admission: ApplicationAdmissionSnapshotSchema,
|
|
47
|
+
resources: z.array(ManagedResourceSnapshotSchema).readonly()
|
|
48
|
+
}).readonly();
|
|
49
|
+
var ApplicationStatusProjectionSchema = z.object({
|
|
50
|
+
id: ApplicationIdSchema,
|
|
51
|
+
lifecycle: ApplicationLifecycleSchema,
|
|
52
|
+
health: ApplicationHealthSchema,
|
|
53
|
+
ready: z.boolean(),
|
|
54
|
+
capturedAt: z.string().datetime({ offset: true }),
|
|
55
|
+
resources: z.object({
|
|
56
|
+
total: NonNegativeIntegerSchema,
|
|
57
|
+
ready: NonNegativeIntegerSchema,
|
|
58
|
+
degraded: NonNegativeIntegerSchema,
|
|
59
|
+
failed: NonNegativeIntegerSchema
|
|
60
|
+
}).readonly()
|
|
61
|
+
}).readonly();
|
|
62
|
+
var ApplicationResourceShutdownSchema = z.object({
|
|
63
|
+
id: ApplicationIdSchema,
|
|
64
|
+
state: z.enum(["not-started", "closed", "force-failed"]),
|
|
65
|
+
failures: z.array(z.enum(["start", "ready", "completion", "admission", "drain", "close", "force"])).readonly()
|
|
66
|
+
}).readonly();
|
|
67
|
+
var ApplicationShutdownResultSchema = z.object({
|
|
68
|
+
outcome: z.enum(["clean", "forced"]),
|
|
69
|
+
reason: z.enum(["deadline", "signal"]).optional(),
|
|
70
|
+
cleanupComplete: z.boolean(),
|
|
71
|
+
acceptedOperations: NonNegativeIntegerSchema,
|
|
72
|
+
completedOperations: NonNegativeIntegerSchema,
|
|
73
|
+
pendingOperations: NonNegativeIntegerSchema,
|
|
74
|
+
pendingOperationsAtForce: NonNegativeIntegerSchema,
|
|
75
|
+
resources: z.array(ApplicationResourceShutdownSchema).readonly(),
|
|
76
|
+
durationMs: z.number().nonnegative()
|
|
77
|
+
}).readonly();
|
|
78
|
+
|
|
79
|
+
export { ApplicationIdSchema, ApplicationSnapshotSchema, ApplicationShutdownResultSchema };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// src/browser/live-state.ts
|
|
2
|
-
import { z as z2 } from "zod";
|
|
3
|
-
|
|
4
1
|
// src/application/channel.ts
|
|
5
2
|
import { z } from "zod";
|
|
6
3
|
var PositiveSafeIntegerSchema = z.number().int().positive().safe();
|
|
@@ -202,8 +199,132 @@ var CreditWindowSnapshotSchema = z.object({
|
|
|
202
199
|
replenishedBytes: z.number().int().nonnegative(),
|
|
203
200
|
waiting: z.number().int().nonnegative()
|
|
204
201
|
}).strict().readonly();
|
|
202
|
+
function createCreditWindow(config) {
|
|
203
|
+
const capacityBytes = PositiveSafeIntegerSchema.parse(config.capacityBytes);
|
|
204
|
+
let availableBytes = capacityBytes;
|
|
205
|
+
let state = "open";
|
|
206
|
+
let acquired = 0;
|
|
207
|
+
let refused = 0;
|
|
208
|
+
let replenishedBytes = 0;
|
|
209
|
+
const waiters = new Set;
|
|
210
|
+
const snapshot = () => CreditWindowSnapshotSchema.parse({
|
|
211
|
+
state,
|
|
212
|
+
capacityBytes,
|
|
213
|
+
availableBytes,
|
|
214
|
+
leasedBytes: capacityBytes - availableBytes,
|
|
215
|
+
acquired,
|
|
216
|
+
refused,
|
|
217
|
+
replenishedBytes,
|
|
218
|
+
waiting: waiters.size
|
|
219
|
+
});
|
|
220
|
+
const serveWaiters = () => {
|
|
221
|
+
for (const waiter of waiters) {
|
|
222
|
+
if (waiter.bytes > availableBytes)
|
|
223
|
+
return;
|
|
224
|
+
waiter.settle({ outcome: "leased", lease: lease(waiter.bytes) });
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
const lease = (requested) => {
|
|
228
|
+
availableBytes -= requested;
|
|
229
|
+
acquired += 1;
|
|
230
|
+
let leaseReleased = false;
|
|
231
|
+
return {
|
|
232
|
+
bytes: requested,
|
|
233
|
+
get released() {
|
|
234
|
+
return leaseReleased;
|
|
235
|
+
},
|
|
236
|
+
release() {
|
|
237
|
+
if (leaseReleased)
|
|
238
|
+
return;
|
|
239
|
+
leaseReleased = true;
|
|
240
|
+
availableBytes += requested;
|
|
241
|
+
replenishedBytes += requested;
|
|
242
|
+
if (availableBytes > capacityBytes) {
|
|
243
|
+
throw new Error("Credit window accounting exceeded its capacity");
|
|
244
|
+
}
|
|
245
|
+
serveWaiters();
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
const tryLease = (requested) => {
|
|
250
|
+
if (state === "closed")
|
|
251
|
+
return { outcome: "refused", reason: "closed" };
|
|
252
|
+
if (requested > capacityBytes) {
|
|
253
|
+
return { outcome: "refused", reason: "larger-than-window" };
|
|
254
|
+
}
|
|
255
|
+
if (requested > availableBytes) {
|
|
256
|
+
return { outcome: "refused", reason: "insufficient-credit" };
|
|
257
|
+
}
|
|
258
|
+
return { outcome: "leased", lease: lease(requested) };
|
|
259
|
+
};
|
|
260
|
+
const acquireNow = (requested) => {
|
|
261
|
+
const result = tryLease(requested);
|
|
262
|
+
if (result.outcome === "refused")
|
|
263
|
+
refused += 1;
|
|
264
|
+
return result;
|
|
265
|
+
};
|
|
266
|
+
const acquireWaiting = (requested, options) => {
|
|
267
|
+
const timeoutMs = options.timeoutMs === undefined ? undefined : PositiveSafeIntegerSchema.parse(options.timeoutMs);
|
|
268
|
+
const immediate = tryLease(requested);
|
|
269
|
+
if (immediate.outcome === "leased")
|
|
270
|
+
return Promise.resolve(immediate);
|
|
271
|
+
if (immediate.reason !== "insufficient-credit") {
|
|
272
|
+
refused += 1;
|
|
273
|
+
return Promise.resolve({ outcome: "refused", reason: immediate.reason });
|
|
274
|
+
}
|
|
275
|
+
if (options.signal?.aborted) {
|
|
276
|
+
refused += 1;
|
|
277
|
+
return Promise.resolve({ outcome: "refused", reason: "aborted" });
|
|
278
|
+
}
|
|
279
|
+
return new Promise((resolve) => {
|
|
280
|
+
let settled = false;
|
|
281
|
+
let timer;
|
|
282
|
+
const waiter = {
|
|
283
|
+
bytes: requested,
|
|
284
|
+
settle(result) {
|
|
285
|
+
if (settled)
|
|
286
|
+
return;
|
|
287
|
+
settled = true;
|
|
288
|
+
if (timer !== undefined)
|
|
289
|
+
clearTimeout(timer);
|
|
290
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
291
|
+
waiters.delete(waiter);
|
|
292
|
+
if (result.outcome === "refused")
|
|
293
|
+
refused += 1;
|
|
294
|
+
resolve(result);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
function onAbort() {
|
|
298
|
+
waiter.settle({ outcome: "refused", reason: "aborted" });
|
|
299
|
+
}
|
|
300
|
+
waiters.add(waiter);
|
|
301
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
302
|
+
if (timeoutMs !== undefined) {
|
|
303
|
+
timer = setTimeout(() => {
|
|
304
|
+
waiter.settle({ outcome: "refused", reason: "timed-out" });
|
|
305
|
+
}, timeoutMs);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
};
|
|
309
|
+
function acquire(bytes, options) {
|
|
310
|
+
const requested = PositiveSafeIntegerSchema.parse(bytes);
|
|
311
|
+
return options === undefined ? acquireNow(requested) : acquireWaiting(requested, options);
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
acquire,
|
|
315
|
+
close() {
|
|
316
|
+
state = "closed";
|
|
317
|
+
for (const waiter of [...waiters]) {
|
|
318
|
+
waiter.settle({ outcome: "refused", reason: "closed" });
|
|
319
|
+
}
|
|
320
|
+
return snapshot();
|
|
321
|
+
},
|
|
322
|
+
getSnapshot: snapshot
|
|
323
|
+
};
|
|
324
|
+
}
|
|
205
325
|
|
|
206
326
|
// src/browser/live-state.ts
|
|
327
|
+
import { z as z2 } from "zod";
|
|
207
328
|
var PositiveSafeIntegerSchema2 = z2.number().int().positive().safe();
|
|
208
329
|
var LiveStatePhaseSchema = z2.enum([
|
|
209
330
|
"idle",
|
|
@@ -591,4 +712,4 @@ function createLiveStateController(config) {
|
|
|
591
712
|
};
|
|
592
713
|
}
|
|
593
714
|
|
|
594
|
-
export { LiveStatePhaseSchema, LiveStateStopReasonSchema, LiveStateControllerStatusSchema, createLiveStateController };
|
|
715
|
+
export { BoundedChannelPolicySchema, BoundedChannelStateSchema, BoundedChannelSnapshotSchema, BoundedChannelReaderError, createBoundedChannel, CreditWindowSnapshotSchema, createCreditWindow, LiveStatePhaseSchema, LiveStateStopReasonSchema, LiveStateControllerStatusSchema, createLiveStateController };
|