stitchkit 0.70.6 → 0.72.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/README.md +1 -1
- package/dist/agent-runtime/coding-tool-contract.d.ts +11 -1
- package/dist/agent-runtime/coding-tool-contract.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tool-files.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tool-listing.d.ts +15 -0
- package/dist/agent-runtime/coding-tool-listing.d.ts.map +1 -0
- package/dist/agent-runtime/coding-tool-paths.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tool-refusals.d.ts +59 -0
- package/dist/agent-runtime/coding-tool-refusals.d.ts.map +1 -0
- package/dist/agent-runtime/coding-tool-search-patch.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tools.d.ts +3 -1
- package/dist/agent-runtime/coding-tools.d.ts.map +1 -1
- package/dist/agent-runtime/compaction.d.ts +35 -0
- package/dist/agent-runtime/compaction.d.ts.map +1 -1
- package/dist/agent-runtime/contained-files.d.ts +21 -2
- package/dist/agent-runtime/contained-files.d.ts.map +1 -1
- package/dist/agent-runtime/provider-failure.d.ts +66 -0
- package/dist/agent-runtime/provider-failure.d.ts.map +1 -0
- package/dist/agent-runtime/run-execution.d.ts.map +1 -1
- package/dist/agent-runtime/runtime.d.ts +31 -1
- package/dist/agent-runtime/runtime.d.ts.map +1 -1
- package/dist/agent-runtime/schemas.d.ts +1 -0
- package/dist/agent-runtime/schemas.d.ts.map +1 -1
- package/dist/agent-runtime-coding-tools.js +438 -124
- package/dist/agent-runtime-harness.js +4 -4
- package/dist/agent-runtime-openrouter.d.ts +19 -0
- package/dist/agent-runtime-openrouter.d.ts.map +1 -1
- package/dist/agent-runtime-openrouter.js +2 -1
- package/dist/agent-runtime.d.ts +3 -2
- package/dist/agent-runtime.d.ts.map +1 -1
- package/dist/agent-runtime.js +118 -14
- package/dist/application/admission.d.ts +22 -2
- package/dist/application/admission.d.ts.map +1 -1
- package/dist/application/channel.d.ts +28 -0
- package/dist/application/channel.d.ts.map +1 -1
- package/dist/application/diagnostic-journal-contract.d.ts +20 -0
- package/dist/application/diagnostic-journal-contract.d.ts.map +1 -1
- package/dist/application/diagnostic-journal-lock.d.ts +17 -0
- package/dist/application/diagnostic-journal-lock.d.ts.map +1 -0
- package/dist/application/diagnostic-journal-manager.d.ts +2 -1
- package/dist/application/diagnostic-journal-manager.d.ts.map +1 -1
- package/dist/application/diagnostic-journal-storage.d.ts +4 -1
- package/dist/application/diagnostic-journal-storage.d.ts.map +1 -1
- package/dist/application/diagnostic-journal.d.ts +4 -2
- package/dist/application/diagnostic-journal.d.ts.map +1 -1
- package/dist/application-opentelemetry.js +1 -1
- package/dist/application.d.ts +3 -3
- package/dist/application.d.ts.map +1 -1
- package/dist/application.js +134 -21
- package/dist/browser/resumable.d.ts +56 -0
- package/dist/browser/resumable.d.ts.map +1 -0
- package/dist/cli.js +5 -5
- package/dist/{index-cx84zg25.js → index-118v0z41.js} +1 -1
- package/dist/{index-zpyj7hsv.js → index-3cwck0rm.js} +98 -33
- package/dist/{index-ejv31h14.js → index-7qy2ex0m.js} +1 -1
- package/dist/{index-trrf7nch.js → index-ezmn6ac6.js} +3 -3
- package/dist/{index-ekkt4gy9.js → index-jqtsc9mj.js} +2 -2
- package/dist/{index-hxtm2xr2.js → index-k2zczx1g.js} +1 -1
- package/dist/{index-by57nwhc.js → index-m668wzyc.js} +10 -2
- package/dist/{index-w9m1wznn.js → index-nemjkxjp.js} +118 -1
- package/dist/{index-tnazr5tc.js → index-pz7ytdga.js} +3 -3
- package/dist/{index-1z5xxfst.js → index-rqpdar1e.js} +102 -5
- package/dist/{index-qm87g51s.js → index-s4c8wy8m.js} +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +103 -14
- package/dist/node.js +2 -2
- package/dist/observability/index.js +1 -1
- package/dist/primitives/audit.d.ts +52 -0
- package/dist/primitives/audit.d.ts.map +1 -0
- package/dist/primitives/deadline.d.ts +39 -0
- package/dist/primitives/deadline.d.ts.map +1 -0
- package/dist/primitives/decimal.d.ts +10 -0
- package/dist/primitives/decimal.d.ts.map +1 -0
- package/dist/primitives/delivery.d.ts +96 -0
- package/dist/primitives/delivery.d.ts.map +1 -0
- package/dist/primitives/event.d.ts +42 -0
- package/dist/primitives/event.d.ts.map +1 -0
- package/dist/primitives/export-operation.d.ts +89 -0
- package/dist/primitives/export-operation.d.ts.map +1 -0
- package/dist/primitives/index.d.ts +12 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/lifecycle.d.ts +90 -0
- package/dist/primitives/lifecycle.d.ts.map +1 -0
- package/dist/primitives/migration-checks.d.ts +15 -0
- package/dist/primitives/migration-checks.d.ts.map +1 -0
- package/dist/primitives/money.d.ts +43 -0
- package/dist/primitives/money.d.ts.map +1 -0
- package/dist/primitives/owner-scope.d.ts +30 -0
- package/dist/primitives/owner-scope.d.ts.map +1 -0
- package/dist/primitives/permission.d.ts +28 -0
- package/dist/primitives/permission.d.ts.map +1 -0
- package/dist/primitives/quantity.d.ts +57 -0
- package/dist/primitives/quantity.d.ts.map +1 -0
- package/dist/primitives.d.ts +3 -0
- package/dist/primitives.d.ts.map +1 -0
- package/dist/primitives.js +750 -0
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +4 -2
- package/dist/server/request.d.ts +19 -0
- package/dist/server/request.d.ts.map +1 -1
- package/dist/telegram/init-data.d.ts +134 -0
- package/dist/telegram/init-data.d.ts.map +1 -0
- package/dist/telegram/send-failure.d.ts +73 -0
- package/dist/telegram/send-failure.d.ts.map +1 -0
- package/dist/telegram.d.ts +3 -0
- package/dist/telegram.d.ts.map +1 -0
- package/dist/telegram.js +224 -0
- package/dist/tool-invoker.js +4 -4
- package/dist/tools.js +7 -7
- package/llms-full.txt +510 -10
- package/llms.txt +1 -0
- package/native/darwin-arm64.node +0 -0
- package/native/darwin-x64.node +0 -0
- package/package.json +11 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,gBAAgB,EAChB,KAAK,iBAAiB,EACtB,uBAAuB,EACvB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,iCAAiC,EACtC,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,KAAK,eAAe,EACpB,qBAAqB,EACrB,KAAK,qBAAqB,EAC1B,2BAA2B,EAC3B,KAAK,aAAa,EAClB,kBAAkB,EAClB,KAAK,kBAAkB,EACvB,wBAAwB,GACzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EACjC,KAAK,2BAA2B,EAChC,KAAK,2BAA2B,EAChC,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,EAC3B,4BAA4B,EAC5B,4BAA4B,EAC5B,KAAK,6BAA6B,EAClC,mCAAmC,EACnC,KAAK,6BAA6B,EAClC,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,8BAA8B,EAC9B,KAAK,qBAAqB,EAC1B,2BAA2B,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,0BAA0B,EAC/B,yBAAyB,EACzB,KAAK,iBAAiB,EACtB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,0BAA0B,EAC/B,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EACzB,0BAA0B,EAC1B,yBAAyB,EACzB,KAAK,sBAAsB,EAC3B,4BAA4B,EAC5B,KAAK,mBAAmB,EACxB,yBAAyB,EACzB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,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,4BAA4B,EACjC,KAAK,6BAA6B,EAClC,mCAAmC,EACnC,6BAA6B,EAC7B,KAAK,6BAA6B,GACnC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,+BAA+B,EACpC,KAAK,0BAA0B,EAC/B,2BAA2B,GAC5B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,+BAA+B,EAC/B,KAAK,0BAA0B,EAC/B,gCAAgC,EAChC,KAAK,sBAAsB,EAC3B,4BAA4B,EAC5B,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,EAC1B,2BAA2B,EAC3B,KAAK,oBAAoB,GAC1B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,KAAK,4BAA4B,EACjC,kCAAkC,EAClC,KAAK,iBAAiB,EACtB,uBAAuB,EACvB,KAAK,aAAa,EAClB,mBAAmB,EACnB,KAAK,oBAAoB,EACzB,0BAA0B,EAC1B,KAAK,2BAA2B,EAChC,iCAAiC,EACjC,KAAK,yBAAyB,EAC9B,+BAA+B,EAC/B,KAAK,mBAAmB,EACxB,yBAAyB,EACzB,KAAK,2BAA2B,EAChC,iCAAiC,EACjC,KAAK,uBAAuB,EAC5B,6BAA6B,EAC7B,KAAK,oBAAoB,EACzB,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,qBAAqB,GACtB,MAAM,+BAA+B,CAAC"}
|
package/dist/application.js
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
createBoundedChannel,
|
|
21
21
|
createCreditWindow,
|
|
22
22
|
createManagedSchedule
|
|
23
|
-
} from "./index-
|
|
23
|
+
} from "./index-3cwck0rm.js";
|
|
24
24
|
import {
|
|
25
25
|
createBoundedSinkManager
|
|
26
26
|
} from "./index-a59da114.js";
|
|
@@ -59,16 +59,27 @@ var BoundedRateBudgetSchema = z.object({
|
|
|
59
59
|
limit: PositiveSafeIntegerSchema,
|
|
60
60
|
intervalMs: PositiveSafeIntegerSchema
|
|
61
61
|
}).strict().readonly();
|
|
62
|
+
var BoundedAdmissionPerKeyLimitsSchema = z.object({
|
|
63
|
+
maxConcurrent: PositiveSafeIntegerSchema,
|
|
64
|
+
rate: BoundedRateBudgetSchema.optional()
|
|
65
|
+
}).strict().readonly();
|
|
66
|
+
var PerKeyLimitResolverSchema = z.custom((value) => typeof value === "function", { message: "perKey.limits must be a function of the key" });
|
|
62
67
|
var BoundedAdmissionPolicySchema = z.object({
|
|
63
68
|
global: z.object({
|
|
64
69
|
maxConcurrent: PositiveSafeIntegerSchema,
|
|
65
70
|
rate: BoundedRateBudgetSchema.optional()
|
|
66
71
|
}).strict(),
|
|
67
|
-
perKey: z.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
perKey: z.union([
|
|
73
|
+
z.object({
|
|
74
|
+
maxConcurrent: PositiveSafeIntegerSchema,
|
|
75
|
+
maxKeys: PositiveSafeIntegerSchema,
|
|
76
|
+
rate: BoundedRateBudgetSchema.optional()
|
|
77
|
+
}).strict(),
|
|
78
|
+
z.object({
|
|
79
|
+
maxKeys: PositiveSafeIntegerSchema,
|
|
80
|
+
limits: PerKeyLimitResolverSchema
|
|
81
|
+
}).strict()
|
|
82
|
+
]).optional()
|
|
72
83
|
}).strict().readonly();
|
|
73
84
|
var BoundedAdmissionStateSchema = z.enum(["accepting", "draining", "closed"]);
|
|
74
85
|
var BoundedAdmissionRefusalReasonSchema = z.enum([
|
|
@@ -153,6 +164,18 @@ function createBoundedAdmission(config) {
|
|
|
153
164
|
lastNow = value;
|
|
154
165
|
return value;
|
|
155
166
|
};
|
|
167
|
+
const resolveKeyLimits = (key) => {
|
|
168
|
+
const perKey = policy.perKey;
|
|
169
|
+
if (!perKey)
|
|
170
|
+
return;
|
|
171
|
+
if ("limits" in perKey) {
|
|
172
|
+
return BoundedAdmissionPerKeyLimitsSchema.parse(perKey.limits(key));
|
|
173
|
+
}
|
|
174
|
+
return BoundedAdmissionPerKeyLimitsSchema.parse({
|
|
175
|
+
maxConcurrent: perKey.maxConcurrent,
|
|
176
|
+
...perKey.rate && { rate: perKey.rate }
|
|
177
|
+
});
|
|
178
|
+
};
|
|
156
179
|
const pruneRate = (samples, intervalMs, at) => {
|
|
157
180
|
let expired = 0;
|
|
158
181
|
while (expired < samples.length && at - (samples[expired]?.at ?? at) >= intervalMs) {
|
|
@@ -165,8 +188,8 @@ function createBoundedAdmission(config) {
|
|
|
165
188
|
if (policy.global.rate)
|
|
166
189
|
pruneRate(globalRate, policy.global.rate.intervalMs, at);
|
|
167
190
|
for (const [key, record] of keys) {
|
|
168
|
-
if (
|
|
169
|
-
pruneRate(record.rate,
|
|
191
|
+
if (record.limits?.rate) {
|
|
192
|
+
pruneRate(record.rate, record.limits.rate.intervalMs, at);
|
|
170
193
|
}
|
|
171
194
|
if (record.active === 0 && record.rate.length === 0)
|
|
172
195
|
keys.delete(key);
|
|
@@ -221,22 +244,23 @@ function createBoundedAdmission(config) {
|
|
|
221
244
|
if (policy.perKey && key !== undefined) {
|
|
222
245
|
if (!keyRecord && keys.size >= policy.perKey.maxKeys)
|
|
223
246
|
return refuse("key-capacity");
|
|
224
|
-
if (keyRecord && keyRecord.active >=
|
|
247
|
+
if (keyRecord?.limits && keyRecord.active >= keyRecord.limits.maxConcurrent) {
|
|
225
248
|
return refuse("key-concurrency");
|
|
226
249
|
}
|
|
227
250
|
}
|
|
228
251
|
if (policy.global.rate && globalRate.length >= policy.global.rate.limit) {
|
|
229
252
|
return refuse("global-rate", retryAfter(globalRate, policy.global.rate, at));
|
|
230
253
|
}
|
|
231
|
-
|
|
232
|
-
|
|
254
|
+
const keyRate = keyRecord?.limits?.rate;
|
|
255
|
+
if (keyRate && keyRecord && keyRecord.rate.length >= keyRate.limit) {
|
|
256
|
+
return refuse("key-rate", retryAfter(keyRecord.rate, keyRate, at));
|
|
233
257
|
}
|
|
234
258
|
if (key !== undefined && !keyRecord) {
|
|
235
|
-
keyRecord = { active: 0, rate: [] };
|
|
259
|
+
keyRecord = { active: 0, rate: [], limits: resolveKeyLimits(key) };
|
|
236
260
|
keys.set(key, keyRecord);
|
|
237
261
|
}
|
|
238
262
|
const globalSample = policy.global.rate ? { at } : undefined;
|
|
239
|
-
const keySample =
|
|
263
|
+
const keySample = keyRecord?.limits?.rate ? { at } : undefined;
|
|
240
264
|
active += 1;
|
|
241
265
|
if (keyRecord)
|
|
242
266
|
keyRecord.active += 1;
|
|
@@ -413,6 +437,7 @@ var DiagnosticJournalLimitsSchema = z2.object({
|
|
|
413
437
|
maxFileBytes: PositiveSafeIntegerSchema2,
|
|
414
438
|
maxFiles: PositiveSafeIntegerSchema2
|
|
415
439
|
}).strict().readonly();
|
|
440
|
+
var DiagnosticJournalLockPolicySchema = z2.enum(["refuse", "reclaim-stale"]);
|
|
416
441
|
var DiagnosticJournalStateSchema = z2.enum(["open", "draining", "closed", "failed"]);
|
|
417
442
|
var DiagnosticJournalRefusalReasonSchema = z2.enum([
|
|
418
443
|
"closed",
|
|
@@ -435,6 +460,10 @@ var DiagnosticJournalStatusSchema = z2.object({
|
|
|
435
460
|
state: DiagnosticJournalStateSchema,
|
|
436
461
|
epoch: z2.uuid(),
|
|
437
462
|
limits: DiagnosticJournalLimitsSchema,
|
|
463
|
+
lock: z2.object({
|
|
464
|
+
policy: DiagnosticJournalLockPolicySchema,
|
|
465
|
+
reclaimedStale: z2.boolean()
|
|
466
|
+
}).strict().readonly(),
|
|
438
467
|
received: z2.number().int().nonnegative(),
|
|
439
468
|
accepted: z2.number().int().nonnegative(),
|
|
440
469
|
refused: z2.number().int().nonnegative(),
|
|
@@ -493,9 +522,86 @@ function parseDiagnosticJournalMode(mode) {
|
|
|
493
522
|
import { z as z3 } from "zod";
|
|
494
523
|
|
|
495
524
|
// src/application/diagnostic-journal-storage.ts
|
|
496
|
-
import { constants } from "node:fs";
|
|
497
|
-
import { lstat, open, readdir, realpath, rename, unlink } from "node:fs/promises";
|
|
525
|
+
import { constants as constants2 } from "node:fs";
|
|
526
|
+
import { lstat, open as open2, readdir, realpath, rename, unlink as unlink2 } from "node:fs/promises";
|
|
498
527
|
import { basename, dirname, isAbsolute, resolve } from "node:path";
|
|
528
|
+
|
|
529
|
+
// src/application/diagnostic-journal-lock.ts
|
|
530
|
+
import { constants } from "node:fs";
|
|
531
|
+
import { open, unlink } from "node:fs/promises";
|
|
532
|
+
import { hostname } from "node:os";
|
|
533
|
+
function isExisting(error) {
|
|
534
|
+
return isRecord(error) && error.code === "EEXIST";
|
|
535
|
+
}
|
|
536
|
+
function readOwner(text) {
|
|
537
|
+
let parsed;
|
|
538
|
+
try {
|
|
539
|
+
parsed = JSON.parse(text);
|
|
540
|
+
} catch {
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
if (!isRecord(parsed))
|
|
544
|
+
return;
|
|
545
|
+
const { pid, host, acquiredAt } = parsed;
|
|
546
|
+
if (typeof pid !== "number" || !Number.isSafeInteger(pid) || pid <= 0)
|
|
547
|
+
return;
|
|
548
|
+
if (typeof host !== "string" || host.length === 0)
|
|
549
|
+
return;
|
|
550
|
+
if (typeof acquiredAt !== "string")
|
|
551
|
+
return;
|
|
552
|
+
return { pid, host, acquiredAt };
|
|
553
|
+
}
|
|
554
|
+
function isGone(owner) {
|
|
555
|
+
if (owner.host !== hostname())
|
|
556
|
+
return false;
|
|
557
|
+
try {
|
|
558
|
+
process.kill(owner.pid, 0);
|
|
559
|
+
return false;
|
|
560
|
+
} catch (error) {
|
|
561
|
+
return isRecord(error) && error.code === "ESRCH";
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
async function readLockOwner(lockPath) {
|
|
565
|
+
let handle;
|
|
566
|
+
try {
|
|
567
|
+
handle = await open(lockPath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
568
|
+
return readOwner(await handle.readFile("utf8"));
|
|
569
|
+
} catch {
|
|
570
|
+
return;
|
|
571
|
+
} finally {
|
|
572
|
+
await handle?.close().catch(() => {
|
|
573
|
+
return;
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
async function createExclusive(lockPath, mode) {
|
|
578
|
+
const handle = await open(lockPath, "wx", mode);
|
|
579
|
+
const owner = {
|
|
580
|
+
pid: process.pid,
|
|
581
|
+
host: hostname(),
|
|
582
|
+
acquiredAt: new Date().toISOString()
|
|
583
|
+
};
|
|
584
|
+
await handle.writeFile(`${JSON.stringify(owner)}
|
|
585
|
+
`, "utf8");
|
|
586
|
+
return handle;
|
|
587
|
+
}
|
|
588
|
+
async function acquireDiagnosticJournalLock(lockPath, mode, policy) {
|
|
589
|
+
try {
|
|
590
|
+
return { handle: await createExclusive(lockPath, mode), reclaimedStale: false };
|
|
591
|
+
} catch (error) {
|
|
592
|
+
if (policy !== "reclaim-stale" || !isExisting(error))
|
|
593
|
+
throw error;
|
|
594
|
+
const owner = await readLockOwner(lockPath);
|
|
595
|
+
if (!owner || !isGone(owner))
|
|
596
|
+
throw error;
|
|
597
|
+
await unlink(lockPath).catch(() => {
|
|
598
|
+
return;
|
|
599
|
+
});
|
|
600
|
+
return { handle: await createExclusive(lockPath, mode), reclaimedStale: true };
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// src/application/diagnostic-journal-storage.ts
|
|
499
605
|
class DiagnosticJournalStorageError extends Error {
|
|
500
606
|
phase;
|
|
501
607
|
constructor(phase, message, options) {
|
|
@@ -513,7 +619,7 @@ async function removeIfPresent(path) {
|
|
|
513
619
|
if (info.isSymbolicLink() || !info.isFile()) {
|
|
514
620
|
throw new Error("Diagnostic journal generations must be regular files");
|
|
515
621
|
}
|
|
516
|
-
await
|
|
622
|
+
await unlink2(path);
|
|
517
623
|
} catch (error) {
|
|
518
624
|
if (!isMissing(error))
|
|
519
625
|
throw error;
|
|
@@ -552,7 +658,7 @@ async function createRotatingDiagnosticJournalStorage(config) {
|
|
|
552
658
|
const parent = await realpath(dirname(config.path));
|
|
553
659
|
const journalPath = resolve(parent, basename(config.path));
|
|
554
660
|
const lockPath = `${journalPath}.lock`;
|
|
555
|
-
const lock = await
|
|
661
|
+
const { handle: lock, reclaimedStale } = await acquireDiagnosticJournalLock(lockPath, config.mode, config.lock);
|
|
556
662
|
let handle;
|
|
557
663
|
let currentFileBytes = 0;
|
|
558
664
|
let retainedFiles = 1;
|
|
@@ -560,7 +666,7 @@ async function createRotatingDiagnosticJournalStorage(config) {
|
|
|
560
666
|
let partialTails = 0;
|
|
561
667
|
let closed = false;
|
|
562
668
|
const openCurrent = async () => {
|
|
563
|
-
handle = await
|
|
669
|
+
handle = await open2(journalPath, constants2.O_APPEND | constants2.O_CREAT | constants2.O_RDWR | constants2.O_NOFOLLOW, config.mode);
|
|
564
670
|
const info = await handle.stat();
|
|
565
671
|
if (!info.isFile()) {
|
|
566
672
|
await handle.close();
|
|
@@ -624,7 +730,7 @@ async function createRotatingDiagnosticJournalStorage(config) {
|
|
|
624
730
|
await lock.close().catch(() => {
|
|
625
731
|
return;
|
|
626
732
|
});
|
|
627
|
-
await
|
|
733
|
+
await unlink2(lockPath).catch(() => {
|
|
628
734
|
return;
|
|
629
735
|
});
|
|
630
736
|
throw error;
|
|
@@ -636,6 +742,7 @@ async function createRotatingDiagnosticJournalStorage(config) {
|
|
|
636
742
|
partialTails
|
|
637
743
|
});
|
|
638
744
|
return {
|
|
745
|
+
reclaimedStale,
|
|
639
746
|
async append(bytes) {
|
|
640
747
|
if (closed || !handle) {
|
|
641
748
|
throw new DiagnosticJournalStorageError("write", "Diagnostic journal storage is closed");
|
|
@@ -668,7 +775,7 @@ async function createRotatingDiagnosticJournalStorage(config) {
|
|
|
668
775
|
}
|
|
669
776
|
try {
|
|
670
777
|
await lock.close();
|
|
671
|
-
await
|
|
778
|
+
await unlink2(lockPath);
|
|
672
779
|
} catch (error) {
|
|
673
780
|
failure ??= error;
|
|
674
781
|
}
|
|
@@ -822,6 +929,7 @@ function createDiagnosticJournalManager(config, storage) {
|
|
|
822
929
|
state,
|
|
823
930
|
epoch: config.epoch,
|
|
824
931
|
limits,
|
|
932
|
+
lock: config.lock,
|
|
825
933
|
received,
|
|
826
934
|
accepted,
|
|
827
935
|
refused,
|
|
@@ -917,16 +1025,19 @@ function createDiagnosticJournalManager(config, storage) {
|
|
|
917
1025
|
// src/application/diagnostic-journal.ts
|
|
918
1026
|
async function createDiagnosticJournal(config) {
|
|
919
1027
|
const limits = DiagnosticJournalLimitsSchema.parse(config.limits);
|
|
1028
|
+
const lock = DiagnosticJournalLockPolicySchema.parse(config.lock ?? "refuse");
|
|
920
1029
|
const storage = await createRotatingDiagnosticJournalStorage({
|
|
921
1030
|
path: config.path,
|
|
922
1031
|
maxFileBytes: limits.maxFileBytes,
|
|
923
1032
|
maxFiles: limits.maxFiles,
|
|
924
|
-
mode: parseDiagnosticJournalMode(config.mode)
|
|
1033
|
+
mode: parseDiagnosticJournalMode(config.mode),
|
|
1034
|
+
lock
|
|
925
1035
|
});
|
|
926
1036
|
return createDiagnosticJournalManager({
|
|
927
1037
|
eventSchema: config.eventSchema,
|
|
928
1038
|
epoch: randomUUID(),
|
|
929
1039
|
limits,
|
|
1040
|
+
lock: { policy: lock, reclaimedStale: storage.reclaimedStale },
|
|
930
1041
|
...config.onFailure && { onFailure: config.onFailure }
|
|
931
1042
|
}, storage);
|
|
932
1043
|
}
|
|
@@ -1092,6 +1203,7 @@ export {
|
|
|
1092
1203
|
DiagnosticJournalStatusSchema,
|
|
1093
1204
|
DiagnosticJournalStateSchema,
|
|
1094
1205
|
DiagnosticJournalRefusalReasonSchema,
|
|
1206
|
+
DiagnosticJournalLockPolicySchema,
|
|
1095
1207
|
DiagnosticJournalLimitsSchema,
|
|
1096
1208
|
DiagnosticJournalFrameSchema,
|
|
1097
1209
|
DiagnosticJournalFailurePhaseSchema,
|
|
@@ -1108,6 +1220,7 @@ export {
|
|
|
1108
1220
|
BoundedAdmissionRefusalReasonSchema,
|
|
1109
1221
|
BoundedAdmissionRefusalError,
|
|
1110
1222
|
BoundedAdmissionPolicySchema,
|
|
1223
|
+
BoundedAdmissionPerKeyLimitsSchema,
|
|
1111
1224
|
ApplicationStatusProjectionSchema,
|
|
1112
1225
|
ApplicationSnapshotSinkStatusSchema,
|
|
1113
1226
|
ApplicationSnapshotSchema,
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const BackoffPolicySchema: z.ZodReadonly<z.ZodObject<{
|
|
3
|
+
minDelayMs: z.ZodNumber;
|
|
4
|
+
maxDelayMs: z.ZodNumber;
|
|
5
|
+
jitter: z.ZodNumber;
|
|
6
|
+
}, z.core.$strict>>;
|
|
7
|
+
export type BackoffPolicy = z.infer<typeof BackoffPolicySchema>;
|
|
8
|
+
export interface Backoff {
|
|
9
|
+
/** The next delay in milliseconds, doubling from `minDelayMs` and jittered. */
|
|
10
|
+
next(): number;
|
|
11
|
+
reset(): void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Exponential backoff with jitter, as a value.
|
|
15
|
+
*
|
|
16
|
+
* Jitter is the part that is easy to leave out and expensive to leave out: without it every
|
|
17
|
+
* consumer that lost the same server retries at the same instant, and the recovering server is
|
|
18
|
+
* hit by the whole fleet at once instead of a spread. The randomisation is subtractive — a delay
|
|
19
|
+
* is never longer than the ceiling the caller declared, only shorter — so `maxDelayMs` remains a
|
|
20
|
+
* real bound rather than an average.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createBackoff(policy: BackoffPolicy, random?: () => number): Backoff;
|
|
23
|
+
export interface ResumableAttempt {
|
|
24
|
+
/** 1 for the first re-open after a failure, growing until a delivery resets it. */
|
|
25
|
+
readonly number: number;
|
|
26
|
+
readonly delayMs: number;
|
|
27
|
+
readonly error: unknown;
|
|
28
|
+
}
|
|
29
|
+
export interface ResumableIteratorConfig<T, CURSOR> {
|
|
30
|
+
/** Open the stream, from the last cursor a delivered item advanced to. */
|
|
31
|
+
open(cursor: CURSOR | undefined): AsyncIterable<T> | Promise<AsyncIterable<T>>;
|
|
32
|
+
/** The cursor that would resume after this item. The framework never reads inside it. */
|
|
33
|
+
advance(item: T, cursor: CURSOR | undefined): CURSOR;
|
|
34
|
+
/** An item that ends the stream for good instead of triggering a re-open. */
|
|
35
|
+
isTerminal?(item: T): boolean;
|
|
36
|
+
retry?: BackoffPolicy;
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
/** Called before each wait. A reconnect loop nobody can see is the shape of this defect. */
|
|
39
|
+
onAttempt?(attempt: ResumableAttempt): void;
|
|
40
|
+
/** Deterministic jitter for tests; defaults to `Math.random`. */
|
|
41
|
+
random?(): number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Re-open a long-lived stream from the last delivered position.
|
|
45
|
+
*
|
|
46
|
+
* The caller owns every domain decision: `open` knows the transport, `advance` knows what a
|
|
47
|
+
* cursor means and `isTerminal` knows which item ends the stream. What this owns is the part
|
|
48
|
+
* that is the same everywhere and wrong in most hand-written copies — retrying with a bounded,
|
|
49
|
+
* jittered delay, resuming rather than restarting, resetting the backoff once the stream
|
|
50
|
+
* delivers again, and stopping promptly when the caller aborts.
|
|
51
|
+
*
|
|
52
|
+
* A failure while opening and a failure mid-stream are one case: both re-open from the cursor
|
|
53
|
+
* the last delivered item produced.
|
|
54
|
+
*/
|
|
55
|
+
export declare function resumableIterator<T, CURSOR>(config: ResumableIteratorConfig<T, CURSOR>): AsyncGenerator<T, void, undefined>;
|
|
56
|
+
//# sourceMappingURL=resumable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resumable.d.ts","sourceRoot":"","sources":["../../src/browser/resumable.ts"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AE,MAAM,EAChD,MAAM,EAAE,uBAAuB,CAAC,CAAC,EAAE,MAAM,CAAC,GACzC,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,CAiCpC"}
|
package/dist/cli.js
CHANGED
|
@@ -5,12 +5,12 @@ import {
|
|
|
5
5
|
emitResult,
|
|
6
6
|
parseCliArgs,
|
|
7
7
|
pollUntilDone
|
|
8
|
-
} from "./index-
|
|
9
|
-
import"./index-
|
|
8
|
+
} from "./index-pz7ytdga.js";
|
|
9
|
+
import"./index-k2zczx1g.js";
|
|
10
10
|
import"./index-wwst0td5.js";
|
|
11
|
-
import"./index-
|
|
12
|
-
import"./index-
|
|
13
|
-
import"./index-
|
|
11
|
+
import"./index-7qy2ex0m.js";
|
|
12
|
+
import"./index-s4c8wy8m.js";
|
|
13
|
+
import"./index-nemjkxjp.js";
|
|
14
14
|
import"./index-sbdmyz75.js";
|
|
15
15
|
import"./index-22by16v6.js";
|
|
16
16
|
import"./index-cby4ar3v.js";
|
|
@@ -200,7 +200,8 @@ var CreditWindowSnapshotSchema = z.object({
|
|
|
200
200
|
leasedBytes: z.number().int().nonnegative(),
|
|
201
201
|
acquired: z.number().int().nonnegative(),
|
|
202
202
|
refused: z.number().int().nonnegative(),
|
|
203
|
-
replenishedBytes: z.number().int().nonnegative()
|
|
203
|
+
replenishedBytes: z.number().int().nonnegative(),
|
|
204
|
+
waiting: z.number().int().nonnegative()
|
|
204
205
|
}).strict().readonly();
|
|
205
206
|
function createCreditWindow(config) {
|
|
206
207
|
const capacityBytes = PositiveSafeIntegerSchema.parse(config.capacityBytes);
|
|
@@ -209,6 +210,7 @@ function createCreditWindow(config) {
|
|
|
209
210
|
let acquired = 0;
|
|
210
211
|
let refused = 0;
|
|
211
212
|
let replenishedBytes = 0;
|
|
213
|
+
const waiters = new Set;
|
|
212
214
|
const snapshot = () => CreditWindowSnapshotSchema.parse({
|
|
213
215
|
state,
|
|
214
216
|
capacityBytes,
|
|
@@ -216,46 +218,109 @@ function createCreditWindow(config) {
|
|
|
216
218
|
leasedBytes: capacityBytes - availableBytes,
|
|
217
219
|
acquired,
|
|
218
220
|
refused,
|
|
219
|
-
replenishedBytes
|
|
221
|
+
replenishedBytes,
|
|
222
|
+
waiting: waiters.size
|
|
220
223
|
});
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
224
|
+
const serveWaiters = () => {
|
|
225
|
+
for (const waiter of waiters) {
|
|
226
|
+
if (waiter.bytes > availableBytes)
|
|
227
|
+
return;
|
|
228
|
+
waiter.settle({ outcome: "leased", lease: lease(waiter.bytes) });
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const lease = (requested) => {
|
|
232
|
+
availableBytes -= requested;
|
|
233
|
+
acquired += 1;
|
|
234
|
+
let leaseReleased = false;
|
|
235
|
+
return {
|
|
236
|
+
bytes: requested,
|
|
237
|
+
get released() {
|
|
238
|
+
return leaseReleased;
|
|
239
|
+
},
|
|
240
|
+
release() {
|
|
241
|
+
if (leaseReleased)
|
|
242
|
+
return;
|
|
243
|
+
leaseReleased = true;
|
|
244
|
+
availableBytes += requested;
|
|
245
|
+
replenishedBytes += requested;
|
|
246
|
+
if (availableBytes > capacityBytes) {
|
|
247
|
+
throw new Error("Credit window accounting exceeded its capacity");
|
|
248
|
+
}
|
|
249
|
+
serveWaiters();
|
|
235
250
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
const tryLease = (requested) => {
|
|
254
|
+
if (state === "closed")
|
|
255
|
+
return { outcome: "refused", reason: "closed" };
|
|
256
|
+
if (requested > capacityBytes) {
|
|
257
|
+
return { outcome: "refused", reason: "larger-than-window" };
|
|
258
|
+
}
|
|
259
|
+
if (requested > availableBytes) {
|
|
260
|
+
return { outcome: "refused", reason: "insufficient-credit" };
|
|
261
|
+
}
|
|
262
|
+
return { outcome: "leased", lease: lease(requested) };
|
|
263
|
+
};
|
|
264
|
+
const acquireNow = (requested) => {
|
|
265
|
+
const result = tryLease(requested);
|
|
266
|
+
if (result.outcome === "refused")
|
|
267
|
+
refused += 1;
|
|
268
|
+
return result;
|
|
269
|
+
};
|
|
270
|
+
const acquireWaiting = (requested, options) => {
|
|
271
|
+
const timeoutMs = options.timeoutMs === undefined ? undefined : PositiveSafeIntegerSchema.parse(options.timeoutMs);
|
|
272
|
+
const immediate = tryLease(requested);
|
|
273
|
+
if (immediate.outcome === "leased")
|
|
274
|
+
return Promise.resolve(immediate);
|
|
275
|
+
if (immediate.reason !== "insufficient-credit") {
|
|
276
|
+
refused += 1;
|
|
277
|
+
return Promise.resolve({ outcome: "refused", reason: immediate.reason });
|
|
278
|
+
}
|
|
279
|
+
if (options.signal?.aborted) {
|
|
280
|
+
refused += 1;
|
|
281
|
+
return Promise.resolve({ outcome: "refused", reason: "aborted" });
|
|
282
|
+
}
|
|
283
|
+
return new Promise((resolve) => {
|
|
284
|
+
let settled = false;
|
|
285
|
+
let timer;
|
|
286
|
+
const waiter = {
|
|
240
287
|
bytes: requested,
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
},
|
|
244
|
-
release() {
|
|
245
|
-
if (leaseReleased)
|
|
288
|
+
settle(result) {
|
|
289
|
+
if (settled)
|
|
246
290
|
return;
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
291
|
+
settled = true;
|
|
292
|
+
if (timer !== undefined)
|
|
293
|
+
clearTimeout(timer);
|
|
294
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
295
|
+
waiters.delete(waiter);
|
|
296
|
+
if (result.outcome === "refused")
|
|
297
|
+
refused += 1;
|
|
298
|
+
resolve(result);
|
|
253
299
|
}
|
|
254
300
|
};
|
|
255
|
-
|
|
256
|
-
|
|
301
|
+
function onAbort() {
|
|
302
|
+
waiter.settle({ outcome: "refused", reason: "aborted" });
|
|
303
|
+
}
|
|
304
|
+
waiters.add(waiter);
|
|
305
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
306
|
+
if (timeoutMs !== undefined) {
|
|
307
|
+
timer = setTimeout(() => {
|
|
308
|
+
waiter.settle({ outcome: "refused", reason: "timed-out" });
|
|
309
|
+
}, timeoutMs);
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
function acquire(bytes, options) {
|
|
314
|
+
const requested = PositiveSafeIntegerSchema.parse(bytes);
|
|
315
|
+
return options === undefined ? acquireNow(requested) : acquireWaiting(requested, options);
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
acquire,
|
|
257
319
|
close() {
|
|
258
320
|
state = "closed";
|
|
321
|
+
for (const waiter of [...waiters]) {
|
|
322
|
+
waiter.settle({ outcome: "refused", reason: "closed" });
|
|
323
|
+
}
|
|
259
324
|
return snapshot();
|
|
260
325
|
},
|
|
261
326
|
getSnapshot: snapshot
|
|
@@ -3,15 +3,15 @@ import {
|
|
|
3
3
|
} from "./index-3xnq72rz.js";
|
|
4
4
|
import {
|
|
5
5
|
collectToolSurface
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-k2zczx1g.js";
|
|
7
7
|
import {
|
|
8
8
|
createToolRunner,
|
|
9
9
|
formatToolError
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-7qy2ex0m.js";
|
|
11
11
|
import {
|
|
12
12
|
isToolExecutionControlError,
|
|
13
13
|
toolResultFromError
|
|
14
|
-
} from "./index-
|
|
14
|
+
} from "./index-s4c8wy8m.js";
|
|
15
15
|
import {
|
|
16
16
|
isRecord
|
|
17
17
|
} from "./index-qyrqwr4c.js";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
collectTools,
|
|
3
3
|
createToolRunner
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-7qy2ex0m.js";
|
|
5
5
|
import {
|
|
6
6
|
toolErrorFromResult
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-s4c8wy8m.js";
|
|
8
8
|
import {
|
|
9
9
|
assertUniqueToolName
|
|
10
10
|
} from "./index-22by16v6.js";
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import {
|
|
16
16
|
ToolExecutionControlError,
|
|
17
17
|
isToolExecutionControlError
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-s4c8wy8m.js";
|
|
19
19
|
import {
|
|
20
20
|
AgentAssistantPlaceholderSchema,
|
|
21
21
|
AgentJsonObjectSchema,
|
|
@@ -1418,11 +1418,18 @@ function createRunExecutor(dependencies) {
|
|
|
1418
1418
|
...run.fencingToken !== undefined && { fencingToken: run.fencingToken }
|
|
1419
1419
|
})
|
|
1420
1420
|
});
|
|
1421
|
+
let lastPromptTokens = { provenance: "unavailable" };
|
|
1421
1422
|
const runtimeContext = {
|
|
1422
1423
|
context: input.context,
|
|
1423
1424
|
run,
|
|
1424
1425
|
signal: executionSignal,
|
|
1425
|
-
toolFenceLifecycle
|
|
1426
|
+
toolFenceLifecycle,
|
|
1427
|
+
get contextUsage() {
|
|
1428
|
+
const descriptor = selectedModel?.descriptor;
|
|
1429
|
+
if (!descriptor)
|
|
1430
|
+
return;
|
|
1431
|
+
return { usedTokens: lastPromptTokens, contextWindow: descriptor.contextWindow };
|
|
1432
|
+
}
|
|
1426
1433
|
};
|
|
1427
1434
|
selectedModel = await config.models.resolve({
|
|
1428
1435
|
context: input.context,
|
|
@@ -1783,6 +1790,7 @@ function createRunExecutor(dependencies) {
|
|
|
1783
1790
|
usage: part.usage,
|
|
1784
1791
|
providerMetadata: part.providerMetadata
|
|
1785
1792
|
}) ?? normalizeSdkUsage(part.usage);
|
|
1793
|
+
lastPromptTokens = stepUsage.inputTokens;
|
|
1786
1794
|
modelUsage = addUsage(modelUsage, stepUsage);
|
|
1787
1795
|
usage = nonModelUsage ? addUsage(nonModelUsage, modelUsage) : modelUsage;
|
|
1788
1796
|
config.observe?.emit({
|