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.
Files changed (99) hide show
  1. package/dist/agent-runtime-browser.js +53 -581
  2. package/dist/agent-runtime-coding-tools.js +6 -5
  3. package/dist/agent-runtime-harness.js +20 -93
  4. package/dist/agent-runtime-openrouter.js +1 -1
  5. package/dist/agent-runtime.js +65 -61
  6. package/dist/application/decisions.d.ts +28 -25
  7. package/dist/application/decisions.d.ts.map +1 -1
  8. package/dist/application/kernel.d.ts +2 -0
  9. package/dist/application/kernel.d.ts.map +1 -1
  10. package/dist/application/keyspace.d.ts +11 -1
  11. package/dist/application/keyspace.d.ts.map +1 -1
  12. package/dist/application/schedule.d.ts.map +1 -1
  13. package/dist/application/schemas.d.ts +2 -0
  14. package/dist/application/schemas.d.ts.map +1 -1
  15. package/dist/application/server-resource.d.ts.map +1 -1
  16. package/dist/application/watch-hub.d.ts.map +1 -1
  17. package/dist/application-diagnostic-journal.d.ts +21 -0
  18. package/dist/application-diagnostic-journal.d.ts.map +1 -0
  19. package/dist/application-diagnostic-journal.js +632 -0
  20. package/dist/application-opentelemetry.js +3 -2
  21. package/dist/application-schemas.js +14 -98
  22. package/dist/application.d.ts +1 -2
  23. package/dist/application.d.ts.map +1 -1
  24. package/dist/application.js +155 -882
  25. package/dist/cli.js +13 -11
  26. package/dist/contract/index.js +15 -10
  27. package/dist/files/boundary.d.ts.map +1 -1
  28. package/dist/files.js +1 -1
  29. package/dist/{index-7b188kmz.js → index-2qzskm8h.js} +15 -1
  30. package/dist/{index-k2zczx1g.js → index-2rwwmr7v.js} +3 -3
  31. package/dist/{index-8eywc9zv.js → index-3gye9wzb.js} +6 -3
  32. package/dist/index-4fpa9dy2.js +51 -0
  33. package/dist/{index-7qy2ex0m.js → index-5mtc969c.js} +2 -2
  34. package/dist/index-5s3zajp8.js +192 -0
  35. package/dist/{index-3cwck0rm.js → index-6s7n2v50.js} +60 -374
  36. package/dist/{index-s4c8wy8m.js → index-758zx2ha.js} +11 -90
  37. package/dist/{index-qyrqwr4c.js → index-77fekveh.js} +4 -1
  38. package/dist/{index-58jzmnn4.js → index-7ag81v2f.js} +355 -34
  39. package/dist/index-7gnkny4z.js +326 -0
  40. package/dist/index-7zbps32p.js +89 -0
  41. package/dist/index-85vfqd7m.js +135 -0
  42. package/dist/{index-m668wzyc.js → index-9s6z8vgf.js} +17 -141
  43. package/dist/{index-bfcpjw20.js → index-actkayzn.js} +7 -3
  44. package/dist/index-b9aefrqd.js +20 -0
  45. package/dist/index-dre2ywck.js +48 -0
  46. package/dist/{index-nemjkxjp.js → index-dwf1f2ap.js} +16 -12
  47. package/dist/{index-wwst0td5.js → index-dx9xehwt.js} +1 -1
  48. package/dist/{index-ezmn6ac6.js → index-dxesg10d.js} +4 -4
  49. package/dist/{index-aczggrty.js → index-dxjjv399.js} +2 -2
  50. package/dist/{index-jqtsc9mj.js → index-egaabxkz.js} +3 -3
  51. package/dist/{index-vc1b0b1b.js → index-evcnmsc3.js} +49 -8
  52. package/dist/{index-nt1mp8km.js → index-fxz0v7vg.js} +84 -84
  53. package/dist/index-h4pj6fta.js +87 -0
  54. package/dist/{index-1rxswfbv.js → index-hb5pf3s4.js} +1 -1
  55. package/dist/{index-t8qyvrvg.js → index-k9ay6v6d.js} +21 -272
  56. package/dist/index-kzfs85xp.js +9 -0
  57. package/dist/{index-vbf2p6me.js → index-m9kzax52.js} +91 -89
  58. package/dist/{index-22by16v6.js → index-mgtxfe6b.js} +1 -1
  59. package/dist/index-p7hgdyhb.js +22 -0
  60. package/dist/index-pq95qkbf.js +0 -0
  61. package/dist/index-t0z5p5w6.js +318 -0
  62. package/dist/{index-s2rchahr.js → index-vwp69871.js} +13 -11
  63. package/dist/index-wc4x00bn.js +103 -0
  64. package/dist/{index-da1aqnhb.js → index-xcetq6j3.js} +8 -6
  65. package/dist/{index-f6n5n7nz.js → index-y01f4223.js} +33 -126
  66. package/dist/{index-35z5h2ty.js → index-ywd0y6m1.js} +18 -218
  67. package/dist/index.js +65 -1588
  68. package/dist/internal/deadline.d.ts +17 -0
  69. package/dist/internal/deadline.d.ts.map +1 -0
  70. package/dist/live.js +15 -89
  71. package/dist/node.js +17 -15
  72. package/dist/observability/context.d.ts.map +1 -1
  73. package/dist/observability/index.js +7 -6
  74. package/dist/primitives.js +5 -2
  75. package/dist/react.js +1 -1
  76. package/dist/remote.js +7 -6
  77. package/dist/server/event-bus.d.ts.map +1 -1
  78. package/dist/server/index.js +26 -38
  79. package/dist/telegram.js +1 -1
  80. package/dist/testing.js +86 -97
  81. package/dist/tool-invoker.js +11 -9
  82. package/dist/tools/async-operation-contract.d.ts +61 -0
  83. package/dist/tools/async-operation-contract.d.ts.map +1 -0
  84. package/dist/tools/async-operation.d.ts +2 -47
  85. package/dist/tools/async-operation.d.ts.map +1 -1
  86. package/dist/tools/view-file-contract.d.ts +98 -0
  87. package/dist/tools/view-file-contract.d.ts.map +1 -0
  88. package/dist/tools/view-file.d.ts +4 -83
  89. package/dist/tools/view-file.d.ts.map +1 -1
  90. package/dist/tools-contract.d.ts +29 -0
  91. package/dist/tools-contract.d.ts.map +1 -0
  92. package/dist/tools-contract.js +24 -0
  93. package/dist/tools.d.ts +3 -3
  94. package/dist/tools.d.ts.map +1 -1
  95. package/dist/tools.js +59 -95
  96. package/llms-full.txt +146 -14
  97. package/package.json +14 -7
  98. package/dist/index-ksp6e2ye.js +0 -24
  99. package/dist/index-vj3vvpaa.js +0 -307
@@ -1,345 +1,23 @@
1
1
  import {
2
2
  ApplicationIdSchema
3
- } from "./index-8eywc9zv.js";
3
+ } from "./index-3gye9wzb.js";
4
+ import {
5
+ createBoundedChannel
6
+ } from "./index-7gnkny4z.js";
4
7
 
5
- // src/application/channel.ts
8
+ // src/application/latest-sink.ts
6
9
  import { z } from "zod";
7
- var PositiveSafeIntegerSchema = z.number().int().positive().safe();
8
- var BoundedChannelPolicySchema = z.enum(["ordered", "latest"]);
9
- var BoundedChannelStateSchema = z.enum(["open", "draining", "closed", "failed"]);
10
- var BoundedChannelSnapshotSchema = z.object({
11
- state: BoundedChannelStateSchema,
12
- policy: BoundedChannelPolicySchema,
13
- queuedItems: z.number().int().nonnegative(),
14
- queuedBytes: z.number().int().nonnegative(),
15
- waitingReader: z.boolean(),
16
- offered: z.number().int().nonnegative(),
10
+ var SnapshotRevisionSchema = z.number().int().nonnegative();
11
+ var ApplicationSnapshotSinkStatusSchema = z.object({
12
+ accepting: z.boolean(),
13
+ received: z.number().int().nonnegative(),
14
+ accepted: z.number().int().nonnegative(),
15
+ rejected: z.number().int().nonnegative(),
17
16
  delivered: z.number().int().nonnegative(),
18
- queued: z.number().int().nonnegative(),
19
17
  coalesced: z.number().int().nonnegative(),
20
- refused: z.number().int().nonnegative(),
21
- discarded: z.number().int().nonnegative()
22
- }).strict().readonly();
23
-
24
- class BoundedChannelReaderError extends Error {
25
- constructor() {
26
- super("A bounded channel permits only one pending next() call");
27
- this.name = "BoundedChannelReaderError";
28
- }
29
- }
30
- function createBoundedChannel(config) {
31
- const policy = BoundedChannelPolicySchema.parse(config.policy);
32
- const maxItems = PositiveSafeIntegerSchema.parse(config.maxItems);
33
- const maxBytes = PositiveSafeIntegerSchema.parse(config.maxBytes);
34
- const queue = [];
35
- let state = "open";
36
- let queuedBytes = 0;
37
- let waiting;
38
- let failure;
39
- let hasFailure = false;
40
- let offered = 0;
41
- let delivered = 0;
42
- let queued = 0;
43
- let coalesced = 0;
44
- let refused = 0;
45
- let discarded = 0;
46
- const removeAbortListener = () => {
47
- config.signal?.removeEventListener("abort", abortChannel);
48
- };
49
- const snapshot = () => BoundedChannelSnapshotSchema.parse({
50
- state,
51
- policy,
52
- queuedItems: queue.length,
53
- queuedBytes,
54
- waitingReader: waiting !== undefined,
55
- offered,
56
- delivered,
57
- queued,
58
- coalesced,
59
- refused,
60
- discarded
61
- });
62
- const clearQueue = () => {
63
- discarded += queue.length;
64
- queue.length = 0;
65
- queuedBytes = 0;
66
- };
67
- const settleClosed = () => {
68
- if (state !== "draining" || queue.length > 0)
69
- return;
70
- state = "closed";
71
- removeAbortListener();
72
- const reader = waiting;
73
- waiting = undefined;
74
- reader?.resolve({ done: true, value: undefined });
75
- };
76
- const close = (options = {}) => {
77
- if (state === "closed" || state === "failed")
78
- return snapshot();
79
- const mode = options.mode ?? "drain";
80
- if (mode !== "drain" && mode !== "discard") {
81
- throw new TypeError("Bounded channel close mode must be drain or discard");
82
- }
83
- if (mode === "discard") {
84
- clearQueue();
85
- state = "closed";
86
- removeAbortListener();
87
- const reader = waiting;
88
- waiting = undefined;
89
- reader?.resolve({ done: true, value: undefined });
90
- return snapshot();
91
- }
92
- state = "draining";
93
- settleClosed();
94
- return snapshot();
95
- };
96
- function abortChannel() {
97
- close({ mode: "discard" });
98
- }
99
- const channel = {
100
- [Symbol.asyncIterator]() {
101
- return channel;
102
- },
103
- offer(value) {
104
- offered += 1;
105
- if (state !== "open") {
106
- refused += 1;
107
- return { outcome: "refused", reason: "not-open" };
108
- }
109
- const bytes = config.sizeOf(value);
110
- if (!Number.isSafeInteger(bytes) || bytes < 0) {
111
- throw new TypeError("Bounded channel sizeOf() must return a non-negative safe integer");
112
- }
113
- if (bytes > maxBytes) {
114
- refused += 1;
115
- return { outcome: "refused", reason: "item-too-large" };
116
- }
117
- const reader = waiting;
118
- if (reader) {
119
- waiting = undefined;
120
- delivered += 1;
121
- reader.resolve({ done: false, value });
122
- return { outcome: "delivered" };
123
- }
124
- if (policy === "latest" && queue.length > 0) {
125
- const previous = queue[0];
126
- if (!previous)
127
- throw new Error("Bounded latest channel lost its pending value");
128
- queue[0] = { value, bytes };
129
- queuedBytes += bytes - previous.bytes;
130
- coalesced += 1;
131
- return { outcome: "coalesced", replaced: 1 };
132
- }
133
- if (queue.length >= maxItems) {
134
- refused += 1;
135
- return { outcome: "refused", reason: "item-capacity" };
136
- }
137
- if (queuedBytes + bytes > maxBytes) {
138
- refused += 1;
139
- return { outcome: "refused", reason: "byte-capacity" };
140
- }
141
- queue.push({ value, bytes });
142
- queuedBytes += bytes;
143
- queued += 1;
144
- return { outcome: "queued" };
145
- },
146
- next() {
147
- if (hasFailure)
148
- return Promise.reject(failure);
149
- const next = queue.shift();
150
- if (next) {
151
- queuedBytes -= next.bytes;
152
- delivered += 1;
153
- settleClosed();
154
- return Promise.resolve({ done: false, value: next.value });
155
- }
156
- if (state === "closed" || state === "draining") {
157
- settleClosed();
158
- return Promise.resolve({ done: true, value: undefined });
159
- }
160
- if (waiting)
161
- return Promise.reject(new BoundedChannelReaderError);
162
- return new Promise((resolve, reject) => {
163
- waiting = { resolve, reject };
164
- });
165
- },
166
- return() {
167
- close({ mode: "discard" });
168
- return Promise.resolve({ done: true, value: undefined });
169
- },
170
- throw(error) {
171
- channel.fail(error);
172
- return Promise.reject(error);
173
- },
174
- close,
175
- fail(error) {
176
- if (state === "closed" || state === "failed")
177
- return snapshot();
178
- failure = error;
179
- hasFailure = true;
180
- state = "failed";
181
- clearQueue();
182
- removeAbortListener();
183
- const reader = waiting;
184
- waiting = undefined;
185
- reader?.reject(error);
186
- return snapshot();
187
- },
188
- getSnapshot: snapshot
189
- };
190
- if (config.signal?.aborted)
191
- abortChannel();
192
- else
193
- config.signal?.addEventListener("abort", abortChannel, { once: true });
194
- return channel;
195
- }
196
- var CreditWindowSnapshotSchema = z.object({
197
- state: z.enum(["open", "closed"]),
198
- capacityBytes: PositiveSafeIntegerSchema,
199
- availableBytes: z.number().int().nonnegative(),
200
- leasedBytes: z.number().int().nonnegative(),
201
- acquired: z.number().int().nonnegative(),
202
- refused: z.number().int().nonnegative(),
203
- replenishedBytes: z.number().int().nonnegative(),
204
- waiting: z.number().int().nonnegative()
205
- }).strict().readonly();
206
- function createCreditWindow(config) {
207
- const capacityBytes = PositiveSafeIntegerSchema.parse(config.capacityBytes);
208
- let availableBytes = capacityBytes;
209
- let state = "open";
210
- let acquired = 0;
211
- let refused = 0;
212
- let replenishedBytes = 0;
213
- const waiters = new Set;
214
- const snapshot = () => CreditWindowSnapshotSchema.parse({
215
- state,
216
- capacityBytes,
217
- availableBytes,
218
- leasedBytes: capacityBytes - availableBytes,
219
- acquired,
220
- refused,
221
- replenishedBytes,
222
- waiting: waiters.size
223
- });
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();
250
- }
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 = {
287
- bytes: requested,
288
- settle(result) {
289
- if (settled)
290
- return;
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);
299
- }
300
- };
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,
319
- close() {
320
- state = "closed";
321
- for (const waiter of [...waiters]) {
322
- waiter.settle({ outcome: "refused", reason: "closed" });
323
- }
324
- return snapshot();
325
- },
326
- getSnapshot: snapshot
327
- };
328
- }
329
-
330
- // src/application/latest-sink.ts
331
- import { z as z2 } from "zod";
332
- var SnapshotRevisionSchema = z2.number().int().nonnegative();
333
- var ApplicationSnapshotSinkStatusSchema = z2.object({
334
- accepting: z2.boolean(),
335
- received: z2.number().int().nonnegative(),
336
- accepted: z2.number().int().nonnegative(),
337
- rejected: z2.number().int().nonnegative(),
338
- delivered: z2.number().int().nonnegative(),
339
- coalesced: z2.number().int().nonnegative(),
340
- failed: z2.number().int().nonnegative(),
341
- inFlight: z2.boolean(),
342
- pending: z2.boolean(),
18
+ failed: z.number().int().nonnegative(),
19
+ inFlight: z.boolean(),
20
+ pending: z.boolean(),
343
21
  lastAcceptedRevision: SnapshotRevisionSchema.optional(),
344
22
  lastDeliveredRevision: SnapshotRevisionSchema.optional()
345
23
  }).strict().readonly();
@@ -448,34 +126,34 @@ function createApplicationSnapshotSink(config) {
448
126
  }
449
127
 
450
128
  // src/application/activity.ts
451
- import { z as z3 } from "zod";
452
- var BoundedOperationalIdSchema = z3.string().min(1).max(64).regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]*$/);
453
- var NonNegativeIntegerSchema = z3.number().int().nonnegative();
129
+ import { z as z2 } from "zod";
130
+ var BoundedOperationalIdSchema = z2.string().min(1).max(64).regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]*$/);
131
+ var NonNegativeIntegerSchema = z2.number().int().nonnegative();
454
132
  var ActivityIdSchema = BoundedOperationalIdSchema;
455
133
  var ActivityStageIdSchema = BoundedOperationalIdSchema;
456
- var ActivityStageSnapshotSchema = z3.object({
134
+ var ActivityStageSnapshotSchema = z2.object({
457
135
  id: ActivityStageIdSchema,
458
136
  active: NonNegativeIntegerSchema,
459
137
  queued: NonNegativeIntegerSchema,
460
138
  completed: NonNegativeIntegerSchema,
461
139
  failed: NonNegativeIntegerSchema
462
140
  }).strict().readonly();
463
- var ActivityTotalsSchema = z3.object({
141
+ var ActivityTotalsSchema = z2.object({
464
142
  active: NonNegativeIntegerSchema,
465
143
  queued: NonNegativeIntegerSchema,
466
144
  completed: NonNegativeIntegerSchema,
467
145
  failed: NonNegativeIntegerSchema
468
146
  }).strict().readonly();
469
- var ActivitySnapshotSchema = z3.object({
147
+ var ActivitySnapshotSchema = z2.object({
470
148
  id: ActivityIdSchema,
471
- epoch: z3.string().uuid(),
149
+ epoch: z2.string().uuid(),
472
150
  revision: NonNegativeIntegerSchema,
473
- capturedAt: z3.string().datetime({ offset: true }),
474
- changedAt: z3.string().datetime({ offset: true }),
475
- stages: z3.array(ActivityStageSnapshotSchema).min(1).max(64).readonly(),
151
+ capturedAt: z2.string().datetime({ offset: true }),
152
+ changedAt: z2.string().datetime({ offset: true }),
153
+ stages: z2.array(ActivityStageSnapshotSchema).min(1).max(64).readonly(),
476
154
  totals: ActivityTotalsSchema
477
155
  }).strict().readonly();
478
- var ActivityLiveStateSchema = z3.enum(["active", "queued"]);
156
+ var ActivityLiveStateSchema = z2.enum(["active", "queued"]);
479
157
  var ActivityTokenBrand = Symbol("stitchkit.application.activity");
480
158
  function emptyCounters() {
481
159
  return { active: 0, queued: 0, completed: 0, failed: 0 };
@@ -490,12 +168,12 @@ function totalsOf(stages) {
490
168
  }
491
169
  function createActivityProjection(config) {
492
170
  const id = ActivityIdSchema.parse(config.id);
493
- const declaredStages = z3.array(ActivityStageIdSchema).min(1).max(64).parse(config.stages);
171
+ const declaredStages = z2.array(ActivityStageIdSchema).min(1).max(64).parse(config.stages);
494
172
  const uniqueStages = new Set(declaredStages);
495
173
  if (uniqueStages.size !== declaredStages.length) {
496
174
  throw new Error("[stitchkit] createActivityProjection: stage ids must be unique");
497
175
  }
498
- const epoch = z3.string().uuid().parse(config.epoch ?? crypto.randomUUID());
176
+ const epoch = z2.string().uuid().parse(config.epoch ?? crypto.randomUUID());
499
177
  const now = config.now ?? (() => new Date);
500
178
  const counters = new Map(declaredStages.map((stage) => [stage, emptyCounters()]));
501
179
  const activities = new WeakMap;
@@ -600,42 +278,42 @@ function createActivityProjection(config) {
600
278
  }
601
279
 
602
280
  // src/application/schedule.ts
603
- import { z as z4 } from "zod";
604
- var NonNegativeSafeIntegerSchema = z4.number().int().nonnegative().refine(Number.isSafeInteger, "Expected a safe integer");
605
- var PositiveSafeIntegerSchema2 = NonNegativeSafeIntegerSchema.refine((value) => value > 0, "Expected a positive integer");
606
- var ManagedScheduleOverlapSchema = z4.discriminatedUnion("mode", [
607
- z4.object({ mode: z4.literal("skip") }).readonly(),
608
- z4.object({ mode: z4.literal("queue-one") }).readonly(),
609
- z4.object({
610
- mode: z4.literal("parallel"),
611
- maxConcurrent: PositiveSafeIntegerSchema2
281
+ import { z as z3 } from "zod";
282
+ var NonNegativeSafeIntegerSchema = z3.number().int().nonnegative().refine(Number.isSafeInteger, "Expected a safe integer");
283
+ var PositiveSafeIntegerSchema = NonNegativeSafeIntegerSchema.refine((value) => value > 0, "Expected a positive integer");
284
+ var ManagedScheduleOverlapSchema = z3.discriminatedUnion("mode", [
285
+ z3.object({ mode: z3.literal("skip") }).readonly(),
286
+ z3.object({ mode: z3.literal("queue-one") }).readonly(),
287
+ z3.object({
288
+ mode: z3.literal("parallel"),
289
+ maxConcurrent: PositiveSafeIntegerSchema
612
290
  }).readonly()
613
291
  ]);
614
- var ManagedScheduleErrorPolicySchema = z4.enum(["continue", "stop-schedule"]);
615
- var ManagedScheduleDescriptorSchema = z4.object({
292
+ var ManagedScheduleErrorPolicySchema = z3.enum(["continue", "stop-schedule"]);
293
+ var ManagedScheduleDescriptorSchema = z3.object({
616
294
  id: ApplicationIdSchema,
617
- everyMs: PositiveSafeIntegerSchema2,
295
+ everyMs: PositiveSafeIntegerSchema,
618
296
  startAfterMs: NonNegativeSafeIntegerSchema,
619
297
  overlap: ManagedScheduleOverlapSchema,
620
298
  errorPolicy: ManagedScheduleErrorPolicySchema
621
299
  }).readonly();
622
- var ManagedScheduleStatusSchema = z4.object({
300
+ var ManagedScheduleStatusSchema = z3.object({
623
301
  descriptor: ManagedScheduleDescriptorSchema,
624
- state: z4.enum(["inactive", "scheduled", "running", "draining", "stopped"]),
302
+ state: z3.enum(["inactive", "scheduled", "running", "draining", "stopped"]),
625
303
  revision: NonNegativeSafeIntegerSchema,
626
- capturedAt: z4.string().datetime({ offset: true }),
627
- changedAt: z4.string().datetime({ offset: true }),
628
- accepting: z4.boolean(),
304
+ capturedAt: z3.string().datetime({ offset: true }),
305
+ changedAt: z3.string().datetime({ offset: true }),
306
+ accepting: z3.boolean(),
629
307
  active: NonNegativeSafeIntegerSchema,
630
- queued: z4.boolean(),
308
+ queued: z3.boolean(),
631
309
  runsStarted: NonNegativeSafeIntegerSchema,
632
310
  runsCompleted: NonNegativeSafeIntegerSchema,
633
311
  runsFailed: NonNegativeSafeIntegerSchema,
634
312
  ticksSkipped: NonNegativeSafeIntegerSchema,
635
- nextRunAt: z4.string().datetime({ offset: true }).nullable(),
636
- lastScheduledAt: z4.string().datetime({ offset: true }).nullable(),
637
- lastStartedAt: z4.string().datetime({ offset: true }).nullable(),
638
- lastFinishedAt: z4.string().datetime({ offset: true }).nullable()
313
+ nextRunAt: z3.string().datetime({ offset: true }).nullable(),
314
+ lastScheduledAt: z3.string().datetime({ offset: true }).nullable(),
315
+ lastStartedAt: z3.string().datetime({ offset: true }).nullable(),
316
+ lastFinishedAt: z3.string().datetime({ offset: true }).nullable()
639
317
  }).readonly();
640
318
  var systemClock = {
641
319
  now: () => performance.now(),
@@ -863,8 +541,16 @@ function createManagedSchedule(config) {
863
541
  return status();
864
542
  },
865
543
  start() {
866
- if (stopped)
867
- throw new Error(`[stitchkit] schedule "${descriptor.id}" is stopped`);
544
+ if (active.size > 0) {
545
+ throw new Error(`[stitchkit] schedule "${descriptor.id}" still has executions from its previous generation`);
546
+ }
547
+ cancelFuture();
548
+ stopped = false;
549
+ accepting = false;
550
+ activated = false;
551
+ activationContext = null;
552
+ queuedAt = null;
553
+ changed();
868
554
  },
869
555
  activate(context) {
870
556
  if (activated || stopped)
@@ -894,4 +580,4 @@ function createManagedSchedule(config) {
894
580
  };
895
581
  }
896
582
 
897
- export { BoundedChannelPolicySchema, BoundedChannelStateSchema, BoundedChannelSnapshotSchema, BoundedChannelReaderError, createBoundedChannel, CreditWindowSnapshotSchema, createCreditWindow, ApplicationSnapshotSinkStatusSchema, createApplicationSnapshotSink, ActivityIdSchema, ActivityStageIdSchema, ActivityStageSnapshotSchema, ActivitySnapshotSchema, ActivityLiveStateSchema, ActivityTokenBrand, createActivityProjection, ManagedScheduleOverlapSchema, ManagedScheduleErrorPolicySchema, ManagedScheduleDescriptorSchema, ManagedScheduleStatusSchema, createManagedSchedule };
583
+ export { ApplicationSnapshotSinkStatusSchema, createApplicationSnapshotSink, ActivityIdSchema, ActivityStageIdSchema, ActivityStageSnapshotSchema, ActivitySnapshotSchema, ActivityLiveStateSchema, ActivityTokenBrand, createActivityProjection, ManagedScheduleOverlapSchema, ManagedScheduleErrorPolicySchema, ManagedScheduleDescriptorSchema, ManagedScheduleStatusSchema, createManagedSchedule };
@@ -1,108 +1,29 @@
1
1
  import {
2
2
  getRequestContext,
3
3
  runWithRequestContext
4
- } from "./index-nemjkxjp.js";
4
+ } from "./index-dwf1f2ap.js";
5
5
  import {
6
6
  objectShapeKeys
7
- } from "./index-22by16v6.js";
7
+ } from "./index-mgtxfe6b.js";
8
+ import {
9
+ coerceJsonArgs
10
+ } from "./index-7zbps32p.js";
8
11
  import {
9
12
  formatZodError,
10
13
  normalizeError,
11
14
  validateDeclaredOutput
12
- } from "./index-nt1mp8km.js";
13
- import {
14
- isUnsafeKey,
15
- safeJsonParse
16
- } from "./index-vj3vvpaa.js";
15
+ } from "./index-fxz0v7vg.js";
17
16
  import {
18
17
  AppError,
19
18
  STITCH_ERROR_STATUS,
20
19
  isStitchErrorCode
21
20
  } from "./index-0w9abg87.js";
21
+ import {
22
+ isUnsafeKey
23
+ } from "./index-kzfs85xp.js";
22
24
  import {
23
25
  isRecord
24
- } from "./index-qyrqwr4c.js";
25
-
26
- // src/tools/coerce.ts
27
- import { z } from "zod";
28
- function needsJsonCoercion(schema) {
29
- if (schema instanceof z.ZodArray || schema instanceof z.ZodObject || schema instanceof z.ZodRecord || schema instanceof z.ZodTuple || schema instanceof z.ZodUnion) {
30
- return true;
31
- }
32
- if (schema instanceof z.ZodOptional || schema instanceof z.ZodNullable || schema instanceof z.ZodDefault) {
33
- return needsJsonCoercion(schema.unwrap());
34
- }
35
- return false;
36
- }
37
- function acceptsRawString(schema) {
38
- const type = schema._zod.def.type;
39
- if (type === "string" || type === "template_literal")
40
- return true;
41
- if (schema instanceof z.ZodLiteral) {
42
- return schema.def.values.some((value) => typeof value === "string");
43
- }
44
- if (schema instanceof z.ZodEnum) {
45
- return schema.options.some((value) => typeof value === "string");
46
- }
47
- if (schema instanceof z.ZodOptional || schema instanceof z.ZodNullable || schema instanceof z.ZodDefault) {
48
- return acceptsRawString(schema.unwrap());
49
- }
50
- if (schema instanceof z.ZodUnion) {
51
- return schema.def.options.some((option) => acceptsRawString(option));
52
- }
53
- return false;
54
- }
55
- function matchingVariant(union, value) {
56
- const disc = union.def.discriminator;
57
- const tag = value[disc];
58
- for (const option of union.def.options) {
59
- if (!(option instanceof z.ZodObject))
60
- continue;
61
- const field = option.shape[disc];
62
- if (field instanceof z.ZodLiteral && field.def.values.some((v) => v === tag))
63
- return option;
64
- if (field instanceof z.ZodEnum && field.options.some((v) => v === tag))
65
- return option;
66
- }
67
- return;
68
- }
69
- function coerceValue(value, schema) {
70
- if (!schema)
71
- return value;
72
- if (schema instanceof z.ZodOptional || schema instanceof z.ZodNullable || schema instanceof z.ZodDefault) {
73
- return coerceValue(value, schema.unwrap());
74
- }
75
- let current = value;
76
- if (typeof current === "string" && needsJsonCoercion(schema)) {
77
- if (acceptsRawString(schema))
78
- return current;
79
- try {
80
- current = safeJsonParse(current);
81
- } catch {
82
- return value;
83
- }
84
- }
85
- if (schema instanceof z.ZodObject && isRecord(current)) {
86
- const shape = schema.shape;
87
- const out = {};
88
- for (const [key, item] of Object.entries(current)) {
89
- out[key] = coerceValue(item, shape[key]);
90
- }
91
- return out;
92
- }
93
- if (schema instanceof z.ZodArray && Array.isArray(current)) {
94
- return current.map((item) => coerceValue(item, schema.element));
95
- }
96
- if (schema instanceof z.ZodDiscriminatedUnion && isRecord(current)) {
97
- const variant = matchingVariant(schema, current);
98
- return variant ? coerceValue(current, variant) : current;
99
- }
100
- return current;
101
- }
102
- function coerceJsonArgs(args, schema) {
103
- const coerced = coerceValue(args, schema);
104
- return isRecord(coerced) ? coerced : args;
105
- }
26
+ } from "./index-77fekveh.js";
106
27
 
107
28
  // src/tools/execute.ts
108
29
  class ToolExecutionControlError extends Error {
@@ -337,4 +258,4 @@ async function runToolMethod(method, toolName, rawArgs, context, hooks, lifecycl
337
258
  }
338
259
  }
339
260
 
340
- export { coerceJsonArgs, ToolExecutionControlError, isToolExecutionControlError, toolResultFromError, toolErrorFromResult, executeToolMethod };
261
+ export { ToolExecutionControlError, isToolExecutionControlError, toolResultFromError, toolErrorFromResult, executeToolMethod };
@@ -37,5 +37,8 @@ function mapObject(source, mapper) {
37
37
  }
38
38
  return result;
39
39
  }
40
+ function mapObjectTypeBoundary(source, mapper) {
41
+ return mapObject(source, (key, value) => mapper(key, value));
42
+ }
40
43
 
41
- export { typedEntries, isRecord, callRuntimeHandler, executableAgentRuntimeTools, transportResult, mapObject };
44
+ export { typedEntries, isRecord, callRuntimeHandler, executableAgentRuntimeTools, transportResult, mapObject, mapObjectTypeBoundary };