stitchkit 0.67.0 → 0.68.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.js +5 -6
- package/dist/application/admission.d.ts +131 -0
- package/dist/application/admission.d.ts.map +1 -0
- package/dist/application/channel.d.ts +106 -0
- package/dist/application/channel.d.ts.map +1 -0
- package/dist/application/latest-sink.d.ts.map +1 -1
- package/dist/application-grammy.js +1 -1
- package/dist/application-opentelemetry.js +1 -1
- package/dist/application.d.ts +2 -0
- package/dist/application.d.ts.map +1 -1
- package/dist/application.js +386 -17
- package/dist/browser/client.d.ts +2 -3
- package/dist/browser/client.d.ts.map +1 -1
- package/dist/browser/contract-stream.d.ts +5 -0
- package/dist/browser/contract-stream.d.ts.map +1 -0
- package/dist/browser/http.d.ts +3 -0
- package/dist/browser/http.d.ts.map +1 -1
- package/dist/browser/stream.d.ts +4 -1
- package/dist/browser/stream.d.ts.map +1 -1
- package/dist/browser/transport.d.ts +3 -0
- package/dist/browser/transport.d.ts.map +1 -0
- package/dist/cli.js +6 -7
- package/dist/contract/define.d.ts +34 -2
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/contract/errors.d.ts +4 -0
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/index.d.ts +2 -1
- package/dist/contract/index.d.ts.map +1 -1
- package/dist/contract/index.js +5 -1
- package/dist/contract/stream.d.ts +19 -0
- package/dist/contract/stream.d.ts.map +1 -0
- package/dist/{index-xxye8j3k.js → index-0w9abg87.js} +4 -0
- package/dist/index-69m2278y.js +115 -0
- package/dist/{index-physbf4z.js → index-6wzr93cg.js} +1 -1
- package/dist/{index-1pgeyyee.js → index-7pn02bgv.js} +4 -6
- package/dist/index-9ky9hhg3.js +484 -0
- package/dist/{index-wrhf06ak.js → index-avjd67h6.js} +8 -8
- package/dist/{index-413xk7ga.js → index-cq9q73nf.js} +50 -1
- package/dist/{index-6taryy00.js → index-dafax5md.js} +1 -1
- package/dist/{index-8mxadm34.js → index-nymn7wbg.js} +1092 -19
- package/dist/{index-y91zd0ch.js → index-pr0qsmjy.js} +3 -2
- package/dist/index-v5bayx1z.js +138 -0
- package/dist/{index-mfw1pec7.js → index-wqyrvhzz.js} +3 -3
- package/dist/{index-svqhcrrj.js → index-zd4v31v2.js} +156 -10
- package/dist/{index-x8v8b7rc.js → index-zpyj7hsv.js} +330 -58
- package/dist/index.js +270 -105
- package/dist/internal/bounded-lines.d.ts +4 -0
- package/dist/internal/bounded-lines.d.ts.map +1 -0
- package/dist/node.d.ts +1 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +11 -8
- package/dist/observability/index.js +6 -7
- package/dist/remote.js +5 -6
- package/dist/server/contract-stream.d.ts +5 -0
- package/dist/server/contract-stream.d.ts.map +1 -0
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/implement.d.ts.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +41 -283
- package/dist/server/openapi.d.ts.map +1 -1
- package/dist/server/stream.d.ts +3 -1
- package/dist/server/stream.d.ts.map +1 -1
- package/dist/server/streaming-route.d.ts +2 -0
- package/dist/server/streaming-route.d.ts.map +1 -1
- package/dist/server/types.d.ts +13 -3
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/unix-client-body.d.ts +4 -0
- package/dist/server/unix-client-body.d.ts.map +1 -0
- package/dist/server/unix-client-bun.d.ts +13 -0
- package/dist/server/unix-client-bun.d.ts.map +1 -0
- package/dist/server/unix-client-error.d.ts +9 -0
- package/dist/server/unix-client-error.d.ts.map +1 -0
- package/dist/server/unix-client.d.ts +25 -0
- package/dist/server/unix-client.d.ts.map +1 -0
- package/dist/testing.js +6 -5
- package/dist/tools.js +14 -16
- package/llms-full.txt +337 -17
- package/package.json +1 -1
- package/dist/index-48ffdxgk.js +0 -6
- package/dist/index-pzyt11ch.js +0 -127
- package/dist/index-tvwcrx2d.js +0 -224
- package/dist/index-wd8g8z6e.js +0 -206
package/dist/application.js
CHANGED
|
@@ -6,20 +6,27 @@ import {
|
|
|
6
6
|
ActivityStageSnapshotSchema,
|
|
7
7
|
ActivityTokenBrand,
|
|
8
8
|
ApplicationSnapshotSinkStatusSchema,
|
|
9
|
+
BoundedChannelPolicySchema,
|
|
10
|
+
BoundedChannelReaderError,
|
|
11
|
+
BoundedChannelSnapshotSchema,
|
|
12
|
+
BoundedChannelStateSchema,
|
|
13
|
+
CreditWindowSnapshotSchema,
|
|
9
14
|
ManagedScheduleDescriptorSchema,
|
|
10
15
|
ManagedScheduleErrorPolicySchema,
|
|
11
16
|
ManagedScheduleOverlapSchema,
|
|
12
17
|
ManagedScheduleStatusSchema,
|
|
13
18
|
createActivityProjection,
|
|
14
19
|
createApplicationSnapshotSink,
|
|
20
|
+
createBoundedChannel,
|
|
21
|
+
createCreditWindow,
|
|
15
22
|
createManagedSchedule
|
|
16
|
-
} from "./index-
|
|
23
|
+
} from "./index-zpyj7hsv.js";
|
|
17
24
|
import {
|
|
18
25
|
ApplicationAdmissionError,
|
|
19
26
|
ApplicationShutdownBudgetSchema,
|
|
20
27
|
ApplicationShutdownOptionsSchema,
|
|
21
28
|
createApplication
|
|
22
|
-
} from "./index-
|
|
29
|
+
} from "./index-6wzr93cg.js";
|
|
23
30
|
import {
|
|
24
31
|
defineManagedResource,
|
|
25
32
|
managedResourceDependencyId
|
|
@@ -41,19 +48,366 @@ import"./index-dk6e56g0.js";
|
|
|
41
48
|
import {
|
|
42
49
|
createBoundedSinkManager
|
|
43
50
|
} from "./index-a59da114.js";
|
|
44
|
-
import"./index-
|
|
45
|
-
// src/application/
|
|
51
|
+
import"./index-0w9abg87.js";
|
|
52
|
+
// src/application/admission.ts
|
|
46
53
|
import { z } from "zod";
|
|
47
|
-
var
|
|
48
|
-
|
|
54
|
+
var PositiveSafeIntegerSchema = z.number().int().positive().safe();
|
|
55
|
+
var BoundedRateBudgetSchema = z.object({
|
|
56
|
+
limit: PositiveSafeIntegerSchema,
|
|
57
|
+
intervalMs: PositiveSafeIntegerSchema
|
|
58
|
+
}).strict().readonly();
|
|
59
|
+
var BoundedAdmissionPolicySchema = z.object({
|
|
60
|
+
global: z.object({
|
|
61
|
+
maxConcurrent: PositiveSafeIntegerSchema,
|
|
62
|
+
rate: BoundedRateBudgetSchema.optional()
|
|
63
|
+
}).strict(),
|
|
64
|
+
perKey: z.object({
|
|
65
|
+
maxConcurrent: PositiveSafeIntegerSchema,
|
|
66
|
+
maxKeys: PositiveSafeIntegerSchema,
|
|
67
|
+
rate: BoundedRateBudgetSchema.optional()
|
|
68
|
+
}).strict().optional()
|
|
69
|
+
}).strict().readonly();
|
|
70
|
+
var BoundedAdmissionStateSchema = z.enum(["accepting", "draining", "closed"]);
|
|
71
|
+
var BoundedAdmissionRefusalReasonSchema = z.enum([
|
|
72
|
+
"not-accepting",
|
|
73
|
+
"global-concurrency",
|
|
74
|
+
"key-required",
|
|
75
|
+
"key-capacity",
|
|
76
|
+
"key-concurrency",
|
|
77
|
+
"global-rate",
|
|
78
|
+
"key-rate",
|
|
79
|
+
"upstream"
|
|
80
|
+
]);
|
|
81
|
+
var RefusalCountersSchema = z.object({
|
|
82
|
+
"not-accepting": z.number().int().nonnegative(),
|
|
83
|
+
"global-concurrency": z.number().int().nonnegative(),
|
|
84
|
+
"key-required": z.number().int().nonnegative(),
|
|
85
|
+
"key-capacity": z.number().int().nonnegative(),
|
|
86
|
+
"key-concurrency": z.number().int().nonnegative(),
|
|
87
|
+
"global-rate": z.number().int().nonnegative(),
|
|
88
|
+
"key-rate": z.number().int().nonnegative(),
|
|
89
|
+
upstream: z.number().int().nonnegative()
|
|
90
|
+
}).strict().readonly();
|
|
91
|
+
var BoundedAdmissionSnapshotSchema = z.object({
|
|
92
|
+
state: BoundedAdmissionStateSchema,
|
|
93
|
+
active: z.number().int().nonnegative(),
|
|
94
|
+
accepted: z.number().int().nonnegative(),
|
|
95
|
+
released: z.number().int().nonnegative(),
|
|
96
|
+
refused: z.number().int().nonnegative(),
|
|
97
|
+
keys: z.number().int().nonnegative(),
|
|
98
|
+
globalRateSamples: z.number().int().nonnegative(),
|
|
99
|
+
keyRateSamples: z.number().int().nonnegative(),
|
|
100
|
+
refusals: RefusalCountersSchema
|
|
101
|
+
}).strict().readonly();
|
|
102
|
+
|
|
103
|
+
class BoundedAdmissionRefusalError extends Error {
|
|
104
|
+
reason;
|
|
105
|
+
retryAfterMs;
|
|
106
|
+
constructor(reason, retryAfterMs) {
|
|
107
|
+
super(`Bounded admission refused: ${reason}`);
|
|
108
|
+
this.reason = reason;
|
|
109
|
+
this.retryAfterMs = retryAfterMs;
|
|
110
|
+
this.name = "BoundedAdmissionRefusalError";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
class BoundedOperationWaitError extends Error {
|
|
115
|
+
reason;
|
|
116
|
+
constructor(reason) {
|
|
117
|
+
super(reason === "cancelled" ? "Operation wait was cancelled" : "Operation wait timed out");
|
|
118
|
+
this.reason = reason;
|
|
119
|
+
this.name = "BoundedOperationWaitError";
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function createBoundedAdmission(config) {
|
|
123
|
+
const policy = BoundedAdmissionPolicySchema.parse(config.policy);
|
|
124
|
+
const clock = config.clock ?? { now: () => performance.now() };
|
|
125
|
+
const keys = new Map;
|
|
126
|
+
const globalRate = [];
|
|
127
|
+
const drainWaiters = new Set;
|
|
128
|
+
const refusals = {
|
|
129
|
+
"not-accepting": 0,
|
|
130
|
+
"global-concurrency": 0,
|
|
131
|
+
"key-required": 0,
|
|
132
|
+
"key-capacity": 0,
|
|
133
|
+
"key-concurrency": 0,
|
|
134
|
+
"global-rate": 0,
|
|
135
|
+
"key-rate": 0,
|
|
136
|
+
upstream: 0
|
|
137
|
+
};
|
|
138
|
+
let state = "accepting";
|
|
139
|
+
let active = 0;
|
|
140
|
+
let accepted = 0;
|
|
141
|
+
let released = 0;
|
|
142
|
+
let refused = 0;
|
|
143
|
+
let lastNow = Number.NEGATIVE_INFINITY;
|
|
144
|
+
const now = () => {
|
|
145
|
+
const value = clock.now();
|
|
146
|
+
if (!Number.isFinite(value))
|
|
147
|
+
throw new TypeError("Bounded admission clock must be finite");
|
|
148
|
+
if (value < lastNow)
|
|
149
|
+
throw new Error("Bounded admission clock moved backwards");
|
|
150
|
+
lastNow = value;
|
|
151
|
+
return value;
|
|
152
|
+
};
|
|
153
|
+
const pruneRate = (samples, intervalMs, at) => {
|
|
154
|
+
let expired = 0;
|
|
155
|
+
while (expired < samples.length && at - (samples[expired]?.at ?? at) >= intervalMs) {
|
|
156
|
+
expired += 1;
|
|
157
|
+
}
|
|
158
|
+
if (expired > 0)
|
|
159
|
+
samples.splice(0, expired);
|
|
160
|
+
};
|
|
161
|
+
const prune = (at) => {
|
|
162
|
+
if (policy.global.rate)
|
|
163
|
+
pruneRate(globalRate, policy.global.rate.intervalMs, at);
|
|
164
|
+
for (const [key, record] of keys) {
|
|
165
|
+
if (policy.perKey?.rate) {
|
|
166
|
+
pruneRate(record.rate, policy.perKey.rate.intervalMs, at);
|
|
167
|
+
}
|
|
168
|
+
if (record.active === 0 && record.rate.length === 0)
|
|
169
|
+
keys.delete(key);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const retryAfter = (samples, budget, at) => Math.max(1, Math.ceil(budget.intervalMs - (at - (samples[0]?.at ?? at))));
|
|
173
|
+
const refuse = (reason, retryAfterMs) => {
|
|
174
|
+
refused += 1;
|
|
175
|
+
refusals[reason] += 1;
|
|
176
|
+
return {
|
|
177
|
+
outcome: "refused",
|
|
178
|
+
reason,
|
|
179
|
+
...retryAfterMs !== undefined && { retryAfterMs }
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
const closeIfDrained = () => {
|
|
183
|
+
if (state !== "draining" || active !== 0)
|
|
184
|
+
return;
|
|
185
|
+
state = "closed";
|
|
186
|
+
for (const resolve of drainWaiters)
|
|
187
|
+
resolve();
|
|
188
|
+
drainWaiters.clear();
|
|
189
|
+
};
|
|
190
|
+
const rollbackReservation = (key, keyRecord, globalSample, keySample) => {
|
|
191
|
+
active -= 1;
|
|
192
|
+
if (keyRecord)
|
|
193
|
+
keyRecord.active -= 1;
|
|
194
|
+
if (globalSample) {
|
|
195
|
+
const index = globalRate.indexOf(globalSample);
|
|
196
|
+
if (index >= 0)
|
|
197
|
+
globalRate.splice(index, 1);
|
|
198
|
+
}
|
|
199
|
+
if (keySample && keyRecord) {
|
|
200
|
+
const index = keyRecord.rate.indexOf(keySample);
|
|
201
|
+
if (index >= 0)
|
|
202
|
+
keyRecord.rate.splice(index, 1);
|
|
203
|
+
}
|
|
204
|
+
if (key !== undefined && keyRecord?.active === 0 && keyRecord.rate.length === 0) {
|
|
205
|
+
keys.delete(key);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
const acquire = (key) => {
|
|
209
|
+
const at = now();
|
|
210
|
+
prune(at);
|
|
211
|
+
if (state !== "accepting")
|
|
212
|
+
return refuse("not-accepting");
|
|
213
|
+
if (active >= policy.global.maxConcurrent)
|
|
214
|
+
return refuse("global-concurrency");
|
|
215
|
+
if (policy.perKey && key === undefined)
|
|
216
|
+
return refuse("key-required");
|
|
217
|
+
let keyRecord = key === undefined ? undefined : keys.get(key);
|
|
218
|
+
if (policy.perKey && key !== undefined) {
|
|
219
|
+
if (!keyRecord && keys.size >= policy.perKey.maxKeys)
|
|
220
|
+
return refuse("key-capacity");
|
|
221
|
+
if (keyRecord && keyRecord.active >= policy.perKey.maxConcurrent) {
|
|
222
|
+
return refuse("key-concurrency");
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (policy.global.rate && globalRate.length >= policy.global.rate.limit) {
|
|
226
|
+
return refuse("global-rate", retryAfter(globalRate, policy.global.rate, at));
|
|
227
|
+
}
|
|
228
|
+
if (policy.perKey?.rate && keyRecord && keyRecord.rate.length >= policy.perKey.rate.limit) {
|
|
229
|
+
return refuse("key-rate", retryAfter(keyRecord.rate, policy.perKey.rate, at));
|
|
230
|
+
}
|
|
231
|
+
if (key !== undefined && !keyRecord) {
|
|
232
|
+
keyRecord = { active: 0, rate: [] };
|
|
233
|
+
keys.set(key, keyRecord);
|
|
234
|
+
}
|
|
235
|
+
const globalSample = policy.global.rate ? { at } : undefined;
|
|
236
|
+
const keySample = policy.perKey?.rate && keyRecord ? { at } : undefined;
|
|
237
|
+
active += 1;
|
|
238
|
+
if (keyRecord)
|
|
239
|
+
keyRecord.active += 1;
|
|
240
|
+
if (globalSample)
|
|
241
|
+
globalRate.push(globalSample);
|
|
242
|
+
if (keySample && keyRecord)
|
|
243
|
+
keyRecord.rate.push(keySample);
|
|
244
|
+
const upstreamLease = config.upstream?.acquire();
|
|
245
|
+
if (config.upstream && !upstreamLease) {
|
|
246
|
+
rollbackReservation(key, keyRecord, globalSample, keySample);
|
|
247
|
+
return refuse("upstream");
|
|
248
|
+
}
|
|
249
|
+
accepted += 1;
|
|
250
|
+
let leaseReleased = false;
|
|
251
|
+
const lease = {
|
|
252
|
+
...key !== undefined && { key },
|
|
253
|
+
get released() {
|
|
254
|
+
return leaseReleased;
|
|
255
|
+
},
|
|
256
|
+
release() {
|
|
257
|
+
if (leaseReleased)
|
|
258
|
+
return;
|
|
259
|
+
leaseReleased = true;
|
|
260
|
+
active -= 1;
|
|
261
|
+
if (keyRecord)
|
|
262
|
+
keyRecord.active -= 1;
|
|
263
|
+
released += 1;
|
|
264
|
+
if (key !== undefined && keyRecord?.active === 0 && keyRecord.rate.length === 0) {
|
|
265
|
+
keys.delete(key);
|
|
266
|
+
}
|
|
267
|
+
upstreamLease?.release();
|
|
268
|
+
closeIfDrained();
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
return { outcome: "leased", lease };
|
|
272
|
+
};
|
|
273
|
+
const getSnapshot = () => {
|
|
274
|
+
const at = now();
|
|
275
|
+
prune(at);
|
|
276
|
+
let keyRateSamples = 0;
|
|
277
|
+
for (const record of keys.values())
|
|
278
|
+
keyRateSamples += record.rate.length;
|
|
279
|
+
return BoundedAdmissionSnapshotSchema.parse({
|
|
280
|
+
state,
|
|
281
|
+
active,
|
|
282
|
+
accepted,
|
|
283
|
+
released,
|
|
284
|
+
refused,
|
|
285
|
+
keys: keys.size,
|
|
286
|
+
globalRateSamples: globalRate.length,
|
|
287
|
+
keyRateSamples,
|
|
288
|
+
refusals
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
const stopAdmission = () => {
|
|
292
|
+
if (state === "accepting")
|
|
293
|
+
state = "draining";
|
|
294
|
+
closeIfDrained();
|
|
295
|
+
return getSnapshot();
|
|
296
|
+
};
|
|
297
|
+
const drain = async (options = {}) => {
|
|
298
|
+
stopAdmission();
|
|
299
|
+
if (active === 0)
|
|
300
|
+
return { drained: true, remaining: 0 };
|
|
301
|
+
const controller = new AbortController;
|
|
302
|
+
let timer;
|
|
303
|
+
const abort = () => controller.abort();
|
|
304
|
+
if (options.signal?.aborted)
|
|
305
|
+
abort();
|
|
306
|
+
else
|
|
307
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
308
|
+
if (options.timeoutMs !== undefined) {
|
|
309
|
+
if (!Number.isSafeInteger(options.timeoutMs) || options.timeoutMs < 0) {
|
|
310
|
+
throw new TypeError("drain timeoutMs must be a non-negative safe integer");
|
|
311
|
+
}
|
|
312
|
+
timer = setTimeout(abort, options.timeoutMs);
|
|
313
|
+
}
|
|
314
|
+
let resolveDrained;
|
|
315
|
+
try {
|
|
316
|
+
await Promise.race([
|
|
317
|
+
new Promise((resolve) => {
|
|
318
|
+
resolveDrained = resolve;
|
|
319
|
+
drainWaiters.add(resolve);
|
|
320
|
+
}),
|
|
321
|
+
new Promise((resolve) => {
|
|
322
|
+
if (controller.signal.aborted)
|
|
323
|
+
resolve();
|
|
324
|
+
else
|
|
325
|
+
controller.signal.addEventListener("abort", () => resolve(), { once: true });
|
|
326
|
+
})
|
|
327
|
+
]);
|
|
328
|
+
} finally {
|
|
329
|
+
if (timer !== undefined)
|
|
330
|
+
clearTimeout(timer);
|
|
331
|
+
options.signal?.removeEventListener("abort", abort);
|
|
332
|
+
if (resolveDrained)
|
|
333
|
+
drainWaiters.delete(resolveDrained);
|
|
334
|
+
}
|
|
335
|
+
return { drained: active === 0, remaining: active };
|
|
336
|
+
};
|
|
337
|
+
const run = async (key, work, options = {}) => {
|
|
338
|
+
if (options.timeoutMs !== undefined) {
|
|
339
|
+
if (!Number.isSafeInteger(options.timeoutMs) || options.timeoutMs < 0) {
|
|
340
|
+
throw new TypeError("run timeoutMs must be a non-negative safe integer");
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (options.signal?.aborted)
|
|
344
|
+
throw new BoundedOperationWaitError("cancelled");
|
|
345
|
+
const admission = acquire(key);
|
|
346
|
+
if (admission.outcome === "refused") {
|
|
347
|
+
throw new BoundedAdmissionRefusalError(admission.reason, admission.retryAfterMs);
|
|
348
|
+
}
|
|
349
|
+
const workAbort = new AbortController;
|
|
350
|
+
const abortWork = () => workAbort.abort(options.signal?.reason);
|
|
351
|
+
options.signal?.addEventListener("abort", abortWork, { once: true });
|
|
352
|
+
let timer;
|
|
353
|
+
let timedOut = false;
|
|
354
|
+
if (options.timeoutMs !== undefined) {
|
|
355
|
+
timer = setTimeout(() => {
|
|
356
|
+
timedOut = true;
|
|
357
|
+
workAbort.abort(new DOMException("Operation wait timed out", "TimeoutError"));
|
|
358
|
+
}, options.timeoutMs);
|
|
359
|
+
}
|
|
360
|
+
const outcome = Promise.resolve().then(() => work({ signal: workAbort.signal })).then((value) => ({ kind: "value", value }), (error) => ({ kind: "error", error })).finally(() => admission.lease.release());
|
|
361
|
+
const callerDone = new Promise((resolve) => {
|
|
362
|
+
const settle = () => resolve({ kind: "caller" });
|
|
363
|
+
if (workAbort.signal.aborted)
|
|
364
|
+
settle();
|
|
365
|
+
else
|
|
366
|
+
workAbort.signal.addEventListener("abort", settle, { once: true });
|
|
367
|
+
});
|
|
368
|
+
try {
|
|
369
|
+
const settled = await Promise.race([outcome, callerDone]);
|
|
370
|
+
if (settled.kind === "caller") {
|
|
371
|
+
throw new BoundedOperationWaitError(timedOut ? "timed-out" : "cancelled");
|
|
372
|
+
}
|
|
373
|
+
if (settled.kind === "error")
|
|
374
|
+
throw settled.error;
|
|
375
|
+
return settled.value;
|
|
376
|
+
} finally {
|
|
377
|
+
if (timer !== undefined)
|
|
378
|
+
clearTimeout(timer);
|
|
379
|
+
options.signal?.removeEventListener("abort", abortWork);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
return {
|
|
383
|
+
acquire,
|
|
384
|
+
run,
|
|
385
|
+
stopAdmission,
|
|
386
|
+
drain,
|
|
387
|
+
force() {
|
|
388
|
+
if (state === "accepting")
|
|
389
|
+
state = "draining";
|
|
390
|
+
state = "closed";
|
|
391
|
+
for (const resolve of drainWaiters)
|
|
392
|
+
resolve();
|
|
393
|
+
drainWaiters.clear();
|
|
394
|
+
return { remaining: active };
|
|
395
|
+
},
|
|
396
|
+
getSnapshot
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
// src/application/events.ts
|
|
400
|
+
import { z as z2 } from "zod";
|
|
401
|
+
var ApplicationLifecycleEventSchema = z2.object({
|
|
402
|
+
type: z2.literal("application-state"),
|
|
49
403
|
applicationId: ApplicationIdSchema,
|
|
50
|
-
epoch:
|
|
51
|
-
revision:
|
|
404
|
+
epoch: z2.string().uuid(),
|
|
405
|
+
revision: z2.number().int().nonnegative(),
|
|
52
406
|
lifecycle: ApplicationLifecycleSchema,
|
|
53
407
|
health: ApplicationHealthSchema,
|
|
54
|
-
ready:
|
|
55
|
-
capturedAt:
|
|
56
|
-
resources:
|
|
408
|
+
ready: z2.boolean(),
|
|
409
|
+
capturedAt: z2.string().datetime({ offset: true }),
|
|
410
|
+
resources: z2.array(ManagedResourceSnapshotSchema).readonly()
|
|
57
411
|
}).strict().readonly();
|
|
58
412
|
function applicationLifecycleEvent(snapshot) {
|
|
59
413
|
return ApplicationLifecycleEventSchema.parse({
|
|
@@ -84,13 +438,13 @@ function createApplicationEventSink(config) {
|
|
|
84
438
|
};
|
|
85
439
|
}
|
|
86
440
|
// src/application/health.ts
|
|
87
|
-
import { z as
|
|
88
|
-
var ApplicationHealthHandlerOptionsSchema =
|
|
89
|
-
kind:
|
|
90
|
-
retryAfterSeconds:
|
|
441
|
+
import { z as z3 } from "zod";
|
|
442
|
+
var ApplicationHealthHandlerOptionsSchema = z3.object({
|
|
443
|
+
kind: z3.enum(["liveness", "readiness"]),
|
|
444
|
+
retryAfterSeconds: z3.number().int().nonnegative().default(5)
|
|
91
445
|
});
|
|
92
|
-
var ApplicationOperationalHandlersOptionsSchema =
|
|
93
|
-
retryAfterSeconds:
|
|
446
|
+
var ApplicationOperationalHandlersOptionsSchema = z3.object({
|
|
447
|
+
retryAfterSeconds: z3.number().int().nonnegative().default(5)
|
|
94
448
|
});
|
|
95
449
|
function createApplicationHealthHandler(application, options) {
|
|
96
450
|
const parsed = ApplicationHealthHandlerOptionsSchema.parse(options);
|
|
@@ -195,6 +549,18 @@ export {
|
|
|
195
549
|
ApplicationSnapshotSchema,
|
|
196
550
|
ApplicationSnapshotSinkStatusSchema,
|
|
197
551
|
ApplicationStatusProjectionSchema,
|
|
552
|
+
BoundedAdmissionPolicySchema,
|
|
553
|
+
BoundedAdmissionRefusalError,
|
|
554
|
+
BoundedAdmissionRefusalReasonSchema,
|
|
555
|
+
BoundedAdmissionSnapshotSchema,
|
|
556
|
+
BoundedAdmissionStateSchema,
|
|
557
|
+
BoundedChannelPolicySchema,
|
|
558
|
+
BoundedChannelReaderError,
|
|
559
|
+
BoundedChannelSnapshotSchema,
|
|
560
|
+
BoundedChannelStateSchema,
|
|
561
|
+
BoundedOperationWaitError,
|
|
562
|
+
BoundedRateBudgetSchema,
|
|
563
|
+
CreditWindowSnapshotSchema,
|
|
198
564
|
ManagedResourceSnapshotSchema,
|
|
199
565
|
ManagedResourceStateSchema,
|
|
200
566
|
ManagedScheduleDescriptorSchema,
|
|
@@ -208,6 +574,9 @@ export {
|
|
|
208
574
|
createApplicationHealthHandler,
|
|
209
575
|
createApplicationOperationalHandlers,
|
|
210
576
|
createApplicationSnapshotSink,
|
|
577
|
+
createBoundedAdmission,
|
|
578
|
+
createBoundedChannel,
|
|
579
|
+
createCreditWindow,
|
|
211
580
|
createManagedSchedule,
|
|
212
581
|
defineManagedResource,
|
|
213
582
|
managedResourceDependencyId,
|
package/dist/browser/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ContractDef, EndpointDef, ScopedHttpClient, ScopedUrlBuilder } from '../contract';
|
|
2
2
|
import { type HttpClient as HttpAdapter, type UnauthorizedMatcher } from './http';
|
|
3
|
-
|
|
4
|
-
export type ClientFetch
|
|
3
|
+
import type { ClientFetch } from './transport';
|
|
4
|
+
export type { ClientFetch } from './transport';
|
|
5
5
|
export interface ClientConfig {
|
|
6
6
|
baseUrl: string;
|
|
7
7
|
/** Override Web Fetch delivery while preserving the complete client pipeline. */
|
|
@@ -85,5 +85,4 @@ export declare function createUrlBuilders<T extends Record<string, ContractDef<R
|
|
|
85
85
|
};
|
|
86
86
|
/** Build one URL registry routed by contract scope; arrays compose a namespace. */
|
|
87
87
|
export declare function createScopedUrlBuilders<const T extends Record<string, ClientRegistryValue>, const Configs extends ScopeClientConfigs<RegistryScope<T[keyof T]>>>(contracts: T, source: UrlBuilderConfig, scopeConfigs: Configs): ScopedUrlBuilderRegistry<T, Configs>;
|
|
88
|
-
export {};
|
|
89
88
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/browser/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAGjB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/browser/client.ts"],"names":[],"mappings":"AAAA,OAA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ndpointStreamDescriptor } from '../contract';
|
|
3
|
+
/** Convert protocol frames into an immediately-owned schema-derived iterator. */
|
|
4
|
+
export declare function parseContractStream<T>(response: Response, descriptor: EndpointStreamDescriptor<ZodType<T>>, abort: () => void): AsyncIterableIterator<T>;
|
|
5
|
+
//# sourceMappingURL=contract-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-stream.d.ts","sourceRoot":"","sources":["../../src/browser/contract-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,aAAa,CAAC;AAkHrB,iFAAiF;AACjF,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,wBAAwB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAChD,KAAK,EAAE,MAAM,IAAI,GAChB,qBAAqB,CAAC,CAAC,CAAC,CAE1B"}
|
package/dist/browser/http.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ErrorEnvelope } from '../contract';
|
|
2
|
+
import type { ClientFetch } from './transport';
|
|
2
3
|
export type ApiEvent = {
|
|
3
4
|
type: 'unauthorized';
|
|
4
5
|
} | {
|
|
@@ -61,6 +62,8 @@ export interface HttpClientConfig {
|
|
|
61
62
|
* Default `false`.
|
|
62
63
|
*/
|
|
63
64
|
trace?: boolean;
|
|
65
|
+
/** Explicit Fetch-compatible transport, for example `createUnixClientTransport().fetch`. */
|
|
66
|
+
fetch?: ClientFetch;
|
|
64
67
|
/**
|
|
65
68
|
* Dial a unix domain socket instead of TCP (Bun runtime only — other
|
|
66
69
|
* runtimes ignore the option and dial `baseUrl` over TCP). `baseUrl` stays
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/browser/http.ts"],"names":[],"mappings":"AAOA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CAwN/E"}
|
package/dist/browser/stream.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export { type ParseSSEOptions, parseSSE } from '../server/stream';
|
|
2
|
+
export { DEFAULT_STREAM_LINE_BYTES } from '../internal/bounded-lines';
|
|
2
3
|
/** Options for `parseNDJSON`. */
|
|
3
4
|
export interface ParseNDJSONOptions {
|
|
4
|
-
/**
|
|
5
|
+
/** Maximum bytes retained for one line. Default 1 MiB. */
|
|
6
|
+
maxLineBytes?: number;
|
|
7
|
+
/** Called for invalid UTF-8/JSON; without it parsing fails closed. */
|
|
5
8
|
onParseError?: (raw: string, error: Error) => void;
|
|
6
9
|
}
|
|
7
10
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/browser/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/browser/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAIlE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAEtE,iCAAiC;AACjC,MAAM,WAAW,kBAAkB;IACjC,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACpD;AAYD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAuB,WAAW,CAAC,CAAC,EAClC,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,cAAc,CAAC,CAAC,CAAC,CAiBnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/browser/transport.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -5,18 +5,17 @@ import {
|
|
|
5
5
|
emitResult,
|
|
6
6
|
parseCliArgs,
|
|
7
7
|
pollUntilDone
|
|
8
|
-
} from "./index-
|
|
9
|
-
import"./index-
|
|
8
|
+
} from "./index-7pn02bgv.js";
|
|
9
|
+
import"./index-avjd67h6.js";
|
|
10
10
|
import"./index-sbdmyz75.js";
|
|
11
11
|
import"./index-vkk06pv1.js";
|
|
12
12
|
import"./index-6djpbnda.js";
|
|
13
13
|
import"./index-cby4ar3v.js";
|
|
14
|
-
import"./index-
|
|
15
|
-
import"./index-
|
|
16
|
-
import"./index-6k1937bx.js";
|
|
17
|
-
import"./index-pzyt11ch.js";
|
|
14
|
+
import"./index-69m2278y.js";
|
|
15
|
+
import"./index-9ky9hhg3.js";
|
|
18
16
|
import"./index-smpbdg6k.js";
|
|
19
|
-
import"./index-
|
|
17
|
+
import"./index-0w9abg87.js";
|
|
18
|
+
import"./index-6k1937bx.js";
|
|
20
19
|
export {
|
|
21
20
|
DEFAULT_EXIT_CODES,
|
|
22
21
|
createCli,
|
|
@@ -14,6 +14,22 @@ export interface EndpointResponseMeta {
|
|
|
14
14
|
export interface ResponseMetadata {
|
|
15
15
|
headers: Headers;
|
|
16
16
|
}
|
|
17
|
+
/** Wire framing and bounds for one contract-first streaming response. */
|
|
18
|
+
export interface EndpointStreamDescriptor<TItem extends ZodType = ZodType> {
|
|
19
|
+
item: TItem;
|
|
20
|
+
/** Default `ndjson`. */
|
|
21
|
+
format?: 'ndjson' | 'sse';
|
|
22
|
+
/** Maximum encoded data-frame size. Default 256 KiB. */
|
|
23
|
+
maxFrameBytes?: number;
|
|
24
|
+
/** Optional total operation lifetime after response open. */
|
|
25
|
+
lifetimeMs?: number;
|
|
26
|
+
/** Default 5 seconds; keeps a healthy quiet feed observable to intermediaries. */
|
|
27
|
+
heartbeatMs?: number;
|
|
28
|
+
/** Default 0 (disabled). */
|
|
29
|
+
idleTimeoutSeconds?: number;
|
|
30
|
+
/** When present, normal completion requires at least one matching item. */
|
|
31
|
+
terminal?: ZodType<unknown>;
|
|
32
|
+
}
|
|
17
33
|
/**
|
|
18
34
|
* The transport tag on `ctx.source`. The four built-ins keep autocomplete, but
|
|
19
35
|
* the union is **open** (`string & {}`) so a bring-your-own transport — e.g. a
|
|
@@ -245,6 +261,20 @@ interface RawResponseEndpointDef extends EndpointDefBase {
|
|
|
245
261
|
expose?: readonly ['HTTP'];
|
|
246
262
|
responseMeta?: never;
|
|
247
263
|
}
|
|
264
|
+
/** A validated HTTP-only stream whose client yields schema-derived items. */
|
|
265
|
+
interface StreamingResponseEndpointDef extends EndpointDefBase {
|
|
266
|
+
stream: EndpointStreamDescriptor;
|
|
267
|
+
output?: never;
|
|
268
|
+
rawResponse?: never;
|
|
269
|
+
rawBody?: never;
|
|
270
|
+
responseMeta?: never;
|
|
271
|
+
multipart?: never;
|
|
272
|
+
toolName?: never;
|
|
273
|
+
ui?: never;
|
|
274
|
+
annotations?: never;
|
|
275
|
+
mcp?: never;
|
|
276
|
+
expose?: readonly ['HTTP'];
|
|
277
|
+
}
|
|
248
278
|
/** An explicit HTTP HEAD operation. Headers/status are handler-owned; the body is always stripped. */
|
|
249
279
|
export interface HeadEndpointDef {
|
|
250
280
|
method: 'HEAD';
|
|
@@ -268,7 +298,7 @@ export interface HeadEndpointDef {
|
|
|
268
298
|
responseMeta?: never;
|
|
269
299
|
contentType?: string;
|
|
270
300
|
}
|
|
271
|
-
export type EndpointDef = HttpOnlyEndpointDef | ToolEndpointDef | RawBodyEndpointDef | ResponseMetaDataEndpointDef | ResponseMetaEmptyEndpointDef | ResponseMetaRawBodyDataEndpointDef | ResponseMetaRawBodyEmptyEndpointDef | RawResponseEndpointDef | HeadEndpointDef;
|
|
301
|
+
export type EndpointDef = HttpOnlyEndpointDef | ToolEndpointDef | RawBodyEndpointDef | ResponseMetaDataEndpointDef | ResponseMetaEmptyEndpointDef | ResponseMetaRawBodyDataEndpointDef | ResponseMetaRawBodyEmptyEndpointDef | RawResponseEndpointDef | StreamingResponseEndpointDef | HeadEndpointDef;
|
|
272
302
|
export interface ContractMeta<TScope extends string = string> {
|
|
273
303
|
prefix: string;
|
|
274
304
|
scope?: TScope;
|
|
@@ -479,7 +509,9 @@ type EndpointArgs<E> = InferInput<Prop<E, 'params'>> & InferInput<Prop<E, 'input
|
|
|
479
509
|
*/
|
|
480
510
|
type EndpointOutput<E> = E extends {
|
|
481
511
|
rawResponse: true;
|
|
482
|
-
} ? Response : Prop<E, '
|
|
512
|
+
} ? Response : Prop<E, 'stream'> extends {
|
|
513
|
+
item: ZodType<infer O>;
|
|
514
|
+
} ? AsyncIterableIterator<O> : Prop<E, 'output'> extends ZodType<infer O> ? O : undefined;
|
|
483
515
|
export type EndpointFn<E> = [keyof EndpointArgs<E>] extends [never] ? ClientEndpointWithoutArgs<EndpointOutput<E>> : ClientEndpointWithArgs<EndpointArgs<E>, EndpointOutput<E>>;
|
|
484
516
|
export type TypedClient<C extends Record<string, EndpointDef>> = {
|
|
485
517
|
[K in keyof C]: EndpointFn<C[K]>;
|