@mcpmesh/sdk 2.8.1 → 3.0.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/__tests__/agent-add-tool.spec.js +106 -0
- package/dist/__tests__/agent-add-tool.spec.js.map +1 -1
- package/dist/__tests__/claim-dispatcher-resume-cursor.test.d.ts +2 -0
- package/dist/__tests__/claim-dispatcher-resume-cursor.test.d.ts.map +1 -0
- package/dist/__tests__/claim-dispatcher-resume-cursor.test.js +145 -0
- package/dist/__tests__/claim-dispatcher-resume-cursor.test.js.map +1 -0
- package/dist/__tests__/direct-invoke-required.spec.d.ts +2 -0
- package/dist/__tests__/direct-invoke-required.spec.d.ts.map +1 -0
- package/dist/__tests__/direct-invoke-required.spec.js +209 -0
- package/dist/__tests__/direct-invoke-required.spec.js.map +1 -0
- package/dist/__tests__/service-view-types.spec.d.ts +2 -0
- package/dist/__tests__/service-view-types.spec.d.ts.map +1 -0
- package/dist/__tests__/service-view-types.spec.js +66 -0
- package/dist/__tests__/service-view-types.spec.js.map +1 -0
- package/dist/__tests__/service-view.spec.d.ts +2 -0
- package/dist/__tests__/service-view.spec.d.ts.map +1 -0
- package/dist/__tests__/service-view.spec.js +902 -0
- package/dist/__tests__/service-view.spec.js.map +1 -0
- package/dist/__tests__/superseded-signal.spec.d.ts +19 -0
- package/dist/__tests__/superseded-signal.spec.d.ts.map +1 -0
- package/dist/__tests__/superseded-signal.spec.js +222 -0
- package/dist/__tests__/superseded-signal.spec.js.map +1 -0
- package/dist/__tests__/worker-error-serde.spec.d.ts +2 -0
- package/dist/__tests__/worker-error-serde.spec.d.ts.map +1 -0
- package/dist/__tests__/worker-error-serde.spec.js +122 -0
- package/dist/__tests__/worker-error-serde.spec.js.map +1 -0
- package/dist/a2a/producer/mount.d.ts.map +1 -1
- package/dist/a2a/producer/mount.js +4 -0
- package/dist/a2a/producer/mount.js.map +1 -1
- package/dist/agent.d.ts +51 -3
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +435 -33
- package/dist/agent.js.map +1 -1
- package/dist/claim-dispatcher.d.ts +25 -1
- package/dist/claim-dispatcher.d.ts.map +1 -1
- package/dist/claim-dispatcher.js +51 -2
- package/dist/claim-dispatcher.js.map +1 -1
- package/dist/inbound-job-dispatch.d.ts +1 -1
- package/dist/inbound-job-dispatch.d.ts.map +1 -1
- package/dist/inbound-job-dispatch.js +8 -2
- package/dist/inbound-job-dispatch.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/llm-provider.d.ts +14 -16
- package/dist/llm-provider.d.ts.map +1 -1
- package/dist/llm-provider.js +2 -4
- package/dist/llm-provider.js.map +1 -1
- package/dist/llm.d.ts +1 -2
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +1 -2
- package/dist/llm.js.map +1 -1
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +37 -0
- package/dist/proxy.js.map +1 -1
- package/dist/route.d.ts.map +1 -1
- package/dist/route.js +5 -0
- package/dist/route.js.map +1 -1
- package/dist/service-view.d.ts +245 -0
- package/dist/service-view.d.ts.map +1 -0
- package/dist/service-view.js +210 -0
- package/dist/service-view.js.map +1 -0
- package/dist/settle.d.ts +22 -0
- package/dist/settle.d.ts.map +1 -1
- package/dist/settle.js +51 -22
- package/dist/settle.js.map +1 -1
- package/dist/superseded.d.ts +70 -0
- package/dist/superseded.d.ts.map +1 -0
- package/dist/superseded.js +99 -0
- package/dist/superseded.js.map +1 -0
- package/dist/tool-worker-entry.js +1 -12
- package/dist/tool-worker-entry.js.map +1 -1
- package/dist/tool-worker-pool.d.ts.map +1 -1
- package/dist/tool-worker-pool.js +1 -12
- package/dist/tool-worker-pool.js.map +1 -1
- package/dist/types.d.ts +31 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/worker-error-serde.d.ts +40 -0
- package/dist/worker-error-serde.d.ts.map +1 -0
- package/dist/worker-error-serde.js +86 -0
- package/dist/worker-error-serde.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service views (RFC #1280) for the TypeScript SDK.
|
|
3
|
+
*
|
|
4
|
+
* Two related roles, mirroring the Java runtime (`@McpMeshService`) so the
|
|
5
|
+
* cross-runtime contract (integration suite uc37) holds identically:
|
|
6
|
+
*
|
|
7
|
+
* 1. CONSUMER VIEW — `mesh.serviceView({ methods, minAvailable? })` produces a
|
|
8
|
+
* branded object that occupies ONE positional dependency slot in a tool's
|
|
9
|
+
* `dependencies` array but expands into N ordinary dependency edges (one per
|
|
10
|
+
* method, SORTED BY NAME for deterministic registration). At call time the
|
|
11
|
+
* framework injects a facade whose methods delegate to each edge's own
|
|
12
|
+
* resolved proxy — so different methods may bind different provider agents
|
|
13
|
+
* and rebind independently as topology changes. There are NO wire or
|
|
14
|
+
* registry changes: every method is an ordinary dependency edge.
|
|
15
|
+
*
|
|
16
|
+
* 2. PRODUCER SUGAR — `agent.addService("prefix", { ... })` publishes each
|
|
17
|
+
* entry (name-sorted) as an ordinary mesh tool with capability
|
|
18
|
+
* `prefix.<method>` through the existing `addTool` machinery.
|
|
19
|
+
*
|
|
20
|
+
* A service view is purely consumer-local: there is no group versioning and no
|
|
21
|
+
* interface-level availability summary. The optional `minAvailable` floor is a
|
|
22
|
+
* consumer-local circuit breaker with no wire effect.
|
|
23
|
+
*/
|
|
24
|
+
import { z } from "zod";
|
|
25
|
+
import { normalizeDependency } from "./proxy.js";
|
|
26
|
+
/**
|
|
27
|
+
* Reject any {@link ServiceView} in a dependency list for a surface that does
|
|
28
|
+
* NOT support the tool-parameter facade form (mesh.route, mesh.a2a.mount). A
|
|
29
|
+
* view there would normalize to a `capability: undefined` edge — a settle key
|
|
30
|
+
* that never resolves plus a nameless dependency shipped to the registry.
|
|
31
|
+
* Shared by every such call site so the error message + policy stay identical.
|
|
32
|
+
*/
|
|
33
|
+
export function assertNoServiceViewDeps(deps, surface) {
|
|
34
|
+
for (const dep of deps) {
|
|
35
|
+
if (isServiceView(dep)) {
|
|
36
|
+
throw new Error(`${surface} does not support mesh.serviceView(...) dependencies ` +
|
|
37
|
+
`(RFC #1280 service views are a tool-parameter surface). Declare the ` +
|
|
38
|
+
`individual capability deps directly, or use a service view inside ` +
|
|
39
|
+
`agent.addTool(...).`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Segment-wise dotted capability-name grammar. Kept in lockstep with the Go
|
|
45
|
+
* registry validator's `capabilityNamePattern`
|
|
46
|
+
* (src/core/registry/validation.go: `^[a-zA-Z][a-zA-Z0-9_-]*(\.[a-zA-Z][a-zA-Z0-9_-]*)*$`)
|
|
47
|
+
* and the Python/Java runtimes. Applied to the PRODUCED capability names of
|
|
48
|
+
* `agent.addService` (the derived `prefix.method`) and `agent.addTool`
|
|
49
|
+
* (`capability ?? name`, #1293 item 6) — both validate before the name reaches
|
|
50
|
+
* the registry. Dependency capability names are deliberately left unvalidated
|
|
51
|
+
* (the registry remains their single authority).
|
|
52
|
+
*/
|
|
53
|
+
export const CAPABILITY_NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9_-]*(\.[a-zA-Z][a-zA-Z0-9_-]*)*$/;
|
|
54
|
+
/**
|
|
55
|
+
* Brand symbol marking a `mesh.serviceView(...)` result so the dependency
|
|
56
|
+
* expander can detect a view slot structurally (config-over-reflection, the
|
|
57
|
+
* same precedent as `meshJobDepIndex`). `Symbol.for` keeps the brand stable
|
|
58
|
+
* across duplicate module instances.
|
|
59
|
+
*/
|
|
60
|
+
export const SERVICE_VIEW_BRAND = Symbol.for("@mcpmesh/sdk/service-view");
|
|
61
|
+
/** Structural brand check — true for a `mesh.serviceView(...)` result. */
|
|
62
|
+
export function isServiceView(value) {
|
|
63
|
+
return (typeof value === "object" &&
|
|
64
|
+
value !== null &&
|
|
65
|
+
value[SERVICE_VIEW_BRAND] === true);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Thrown by every facade call when a view is below its declared
|
|
69
|
+
* {@link ServiceViewSpec.minAvailable} floor. Carries the view label plus the
|
|
70
|
+
* current/total/floor counts so the failure is actionable. Mirrors Java's
|
|
71
|
+
* `MeshServiceUnavailableException`.
|
|
72
|
+
*/
|
|
73
|
+
export class MeshServiceUnavailableError extends Error {
|
|
74
|
+
service;
|
|
75
|
+
available;
|
|
76
|
+
total;
|
|
77
|
+
floor;
|
|
78
|
+
name = "MeshServiceUnavailableError";
|
|
79
|
+
constructor(
|
|
80
|
+
/** View label (spec.name or a derived owner:slot label). */
|
|
81
|
+
service,
|
|
82
|
+
/** View methods currently resolving to a provider. */
|
|
83
|
+
available,
|
|
84
|
+
/** Total dependency-bound view methods. */
|
|
85
|
+
total,
|
|
86
|
+
/** The declared availability floor. */
|
|
87
|
+
floor) {
|
|
88
|
+
super(`Mesh service view unavailable (${service}): ${available}/${total} ` +
|
|
89
|
+
`method(s) resolved, below the declared minAvailable=${floor} floor`);
|
|
90
|
+
this.service = service;
|
|
91
|
+
this.available = available;
|
|
92
|
+
this.total = total;
|
|
93
|
+
this.floor = floor;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Construct a consumer service view. Validates the spec at construction time
|
|
98
|
+
* (empty methods map; blank capability; out-of-range `minAvailable`) so misuse
|
|
99
|
+
* fails loud before the agent talks to the registry.
|
|
100
|
+
*/
|
|
101
|
+
export function serviceView(spec) {
|
|
102
|
+
if (spec == null ||
|
|
103
|
+
typeof spec !== "object" ||
|
|
104
|
+
typeof spec.methods !== "object" ||
|
|
105
|
+
spec.methods === null ||
|
|
106
|
+
Array.isArray(spec.methods)) {
|
|
107
|
+
throw new Error("mesh.serviceView: `methods` must be an object mapping method names to " +
|
|
108
|
+
"capabilities.");
|
|
109
|
+
}
|
|
110
|
+
const keys = Object.keys(spec.methods);
|
|
111
|
+
if (keys.length === 0) {
|
|
112
|
+
throw new Error("mesh.serviceView: `methods` must declare at least one method (got an " +
|
|
113
|
+
"empty methods map).");
|
|
114
|
+
}
|
|
115
|
+
for (const key of keys) {
|
|
116
|
+
const m = spec.methods[key];
|
|
117
|
+
const capability = typeof m === "string" ? m : m?.capability;
|
|
118
|
+
if (typeof capability !== "string" || capability.trim() === "") {
|
|
119
|
+
throw new Error(`mesh.serviceView: method '${key}' has a blank capability.`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const min = spec.minAvailable;
|
|
123
|
+
if (min !== undefined) {
|
|
124
|
+
if (!Number.isInteger(min) || min < 0) {
|
|
125
|
+
throw new Error(`mesh.serviceView: minAvailable must be an integer >= 0 (got ${min}).`);
|
|
126
|
+
}
|
|
127
|
+
if (min > keys.length) {
|
|
128
|
+
throw new Error(`mesh.serviceView: minAvailable=${min} exceeds the number of methods ` +
|
|
129
|
+
`(${keys.length}) — the floor can never be satisfied.`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
[SERVICE_VIEW_BRAND]: true,
|
|
134
|
+
spec,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function normalizeViewMethod(m) {
|
|
138
|
+
if (typeof m === "string") {
|
|
139
|
+
return normalizeDependency(m);
|
|
140
|
+
}
|
|
141
|
+
return normalizeDependency({
|
|
142
|
+
capability: m.capability,
|
|
143
|
+
tags: m.tags,
|
|
144
|
+
version: m.version,
|
|
145
|
+
required: m.required,
|
|
146
|
+
expectedSchema: m.expectedSchema,
|
|
147
|
+
matchMode: m.matchMode,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Expand a tool's authored dependency list (a mix of {@link DependencySpec} and
|
|
152
|
+
* {@link ServiceView}) into the flat edge array + the positional slot layout.
|
|
153
|
+
*
|
|
154
|
+
* Layout contract (identical to the Java runtime — see uc37):
|
|
155
|
+
* - non-view entries keep their exact slot↔edge pairing;
|
|
156
|
+
* - a view entry contributes ONE slot at its array position but N edges,
|
|
157
|
+
* expanded IN-PLACE (name-sorted) so the flat edge indices stay contiguous
|
|
158
|
+
* and every downstream index consumer (settle keys, wire payload,
|
|
159
|
+
* resolution events, required guard) sees ordinary edges.
|
|
160
|
+
*
|
|
161
|
+
* For a view-free list this returns `edges` byte-identical to
|
|
162
|
+
* `deps.map(normalizeDependency)` and `slots[i] = { kind: "dep", edgeIndex: i }`
|
|
163
|
+
* — zero behavior change.
|
|
164
|
+
*/
|
|
165
|
+
export function expandDependencies(deps, ownerLabel) {
|
|
166
|
+
const edges = [];
|
|
167
|
+
const slots = [];
|
|
168
|
+
deps.forEach((entry, slotIndex) => {
|
|
169
|
+
if (isServiceView(entry)) {
|
|
170
|
+
const spec = entry.spec;
|
|
171
|
+
// Object key order is insertion-based; MUST sort by name for a
|
|
172
|
+
// deterministic edge layout across runtimes.
|
|
173
|
+
const methodNames = Object.keys(spec.methods).sort();
|
|
174
|
+
const methods = [];
|
|
175
|
+
for (const method of methodNames) {
|
|
176
|
+
const edgeIndex = edges.length;
|
|
177
|
+
edges.push(normalizeViewMethod(spec.methods[method]));
|
|
178
|
+
methods.push({ method, edgeIndex });
|
|
179
|
+
}
|
|
180
|
+
slots.push({
|
|
181
|
+
kind: "view",
|
|
182
|
+
name: spec.name ?? `${ownerLabel}:view${slotIndex}`,
|
|
183
|
+
minAvailable: spec.minAvailable ?? 0,
|
|
184
|
+
methods,
|
|
185
|
+
});
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
// Guard: an object without a `capability` in a dependencies array is almost
|
|
189
|
+
// certainly a producer-method object placed where a view/dep was expected
|
|
190
|
+
// (or a malformed spec). Fail loud rather than shipping a `capability:
|
|
191
|
+
// undefined` edge.
|
|
192
|
+
if (typeof entry === "object" &&
|
|
193
|
+
entry !== null &&
|
|
194
|
+
typeof entry.capability !== "string") {
|
|
195
|
+
throw new Error(`${ownerLabel}: dependency #${slotIndex} is an object without a ` +
|
|
196
|
+
`'capability' — expected a DependencySpec (string or { capability }) ` +
|
|
197
|
+
`or a mesh.serviceView(...). If this is a producer method, register ` +
|
|
198
|
+
`it with agent.addService(...).`);
|
|
199
|
+
}
|
|
200
|
+
const edgeIndex = edges.length;
|
|
201
|
+
edges.push(normalizeDependency(entry));
|
|
202
|
+
slots.push({ kind: "dep", edgeIndex });
|
|
203
|
+
});
|
|
204
|
+
return { edges, slots };
|
|
205
|
+
}
|
|
206
|
+
/** Permissive default schema for producer methods that declare no `parameters`. */
|
|
207
|
+
export function defaultProducerParams() {
|
|
208
|
+
return z.object({}).passthrough();
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=service-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-view.js","sourceRoot":"","sources":["../src/service-view.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,IAA4B,EAC5B,OAAe;IAEf,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CACb,GAAG,OAAO,uDAAuD;gBAC/D,sEAAsE;gBACtE,oEAAoE;gBACpE,qBAAqB,CACxB,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAClC,qDAAqD,CAAC;AAExD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAkB,MAAM,CAAC,GAAG,CACzD,2BAA2B,CAC5B,CAAC;AAmGF,0EAA0E;AAC1E,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,CACL,OAAO,KAAK,K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AC/D,sEAAsE;gBACtE,qEAAqE;gBACrE,gCAAgC,CACnC,CAAC;QACJ,CAAC;QAED,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,KAAuB,CAAC,CAAC,CAAC;QACzD,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC1B,CAAC;AAuBD,mFAAmF;AACnF,MAAM,UAAU,qBAAqB;IACnC,OAAO,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;AACpC,CAAC"}
|
package/dist/settle.d.ts
CHANGED
|
@@ -109,6 +109,19 @@ export declare class SettleState {
|
|
|
109
109
|
remainingMs(): number;
|
|
110
110
|
isResolved(depKey: string): boolean;
|
|
111
111
|
private waiterFor;
|
|
112
|
+
/**
|
|
113
|
+
* Shared wait plumbing for {@link waitFor} / {@link waitForAny}: log the
|
|
114
|
+
* settle cadence for each capability (INFO first time, DEBUG after), bump the
|
|
115
|
+
* diagnostic `waitCount`, and race every `depKeys` resolution waiter against
|
|
116
|
+
* ONE budget timer bounded by `remaining` — never a fixed sleep. Callers apply
|
|
117
|
+
* their own resolved-state filtering + early-return BEFORE calling this, so
|
|
118
|
+
* `depKeys` are the genuinely-still-pending keys and `remaining > 0`.
|
|
119
|
+
*
|
|
120
|
+
* On timeout the caller simply proceeds — the unresolved dep injects null
|
|
121
|
+
* exactly as today; the existing unresolved-dep handling covers the
|
|
122
|
+
* diagnostic (no double-logging here).
|
|
123
|
+
*/
|
|
124
|
+
private raceWaiters;
|
|
112
125
|
/**
|
|
113
126
|
* Wait until `depKey` resolves or the remaining settle budget elapses.
|
|
114
127
|
* Event-driven: the dependency's resolution promise is raced against a
|
|
@@ -121,6 +134,15 @@ export declare class SettleState {
|
|
|
121
134
|
* regardless of how many deps are pending.
|
|
122
135
|
*/
|
|
123
136
|
awaitPending(pending: PendingSettleDep[]): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Wait until ANY of `pending` resolves or the remaining settle budget
|
|
139
|
+
* elapses. Unlike {@link awaitPending} (which blocks on each key in turn),
|
|
140
|
+
* this races every pending key's resolution promise against ONE budget timer,
|
|
141
|
+
* so a caller gated on a floor wakes the moment ANY qualifying dependency
|
|
142
|
+
* lands — never sleeping on an already-satisfied floor because it happened to
|
|
143
|
+
* be awaiting a still-pending sibling key (RFC #1280 minAvailable).
|
|
144
|
+
*/
|
|
145
|
+
waitForAny(pending: PendingSettleDep[]): Promise<void>;
|
|
124
146
|
}
|
|
125
147
|
/** Get the process-wide settle state. */
|
|
126
148
|
export declare function getSettleState(): SettleState;
|
package/dist/settle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settle.d.ts","sourceRoot":"","sources":["../src/settle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAIH,eAAO,MAAM,8BAA8B,KAAK,CAAC;AAQjD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAmBhD;AAOD,6EAA6E;AAC7E,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,qBAAa,WAAW;IACtB;;;;;OAKG;IACH,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgC;IACxD,oEAAoE;IACpE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;IACjD,OAAO,CAAC,OAAO,CAAS;IACxB;;;;OAIG;IACH,SA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,GAAG,IAAI;IAOtC;;;;;;OAMG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAqBlC;;;;;;;;;OASG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IA0BpD,kEAAkE;IAClE,SAAS,IAAI,OAAO;IAsBpB,sDAAsD;IACtD,WAAW,IAAI,MAAM;IAUrB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAInC,OAAO,CAAC,SAAS;IAajB;;;;;;;;;;;OAWG;YACW,WAAW;IAmCzB;;;;OAIG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQhE;;;;OAIG;IACG,YAAY,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAM9D;;;;;;;OAOG;IACG,UAAU,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAY7D;AAID,yCAAyC;AACzC,wBAAgB,cAAc,IAAI,WAAW,CAE5C;AAED,2EAA2E;AAC3E,wBAAgB,wBAAwB,IAAI,IAAI,CAG/C"}
|
package/dist/settle.js
CHANGED
|
@@ -218,32 +218,36 @@ export class SettleState {
|
|
|
218
218
|
return waiter;
|
|
219
219
|
}
|
|
220
220
|
/**
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
221
|
+
* Shared wait plumbing for {@link waitFor} / {@link waitForAny}: log the
|
|
222
|
+
* settle cadence for each capability (INFO first time, DEBUG after), bump the
|
|
223
|
+
* diagnostic `waitCount`, and race every `depKeys` resolution waiter against
|
|
224
|
+
* ONE budget timer bounded by `remaining` — never a fixed sleep. Callers apply
|
|
225
|
+
* their own resolved-state filtering + early-return BEFORE calling this, so
|
|
226
|
+
* `depKeys` are the genuinely-still-pending keys and `remaining > 0`.
|
|
227
|
+
*
|
|
228
|
+
* On timeout the caller simply proceeds — the unresolved dep injects null
|
|
229
|
+
* exactly as today; the existing unresolved-dep handling covers the
|
|
230
|
+
* diagnostic (no double-logging here).
|
|
224
231
|
*/
|
|
225
|
-
async
|
|
226
|
-
const remaining = this.remainingMs();
|
|
227
|
-
if (remaining <= 0 || this.resolved.has(depKey)) {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
const waiter = this.waiterFor(depKey);
|
|
232
|
+
async raceWaiters(depKeys, capabilities, remaining) {
|
|
231
233
|
const remainingSecs = (remaining / 1000).toFixed(1);
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
234
|
+
for (const capability of capabilities) {
|
|
235
|
+
const message = `waiting up to ${remainingSecs}s for dependency '${capability}' to settle`;
|
|
236
|
+
if (!this.loggedWaits.has(capability)) {
|
|
237
|
+
// One INFO line per capability per process; later waits at DEBUG
|
|
238
|
+
// (matches the Python/Java log cadence).
|
|
239
|
+
this.loggedWaits.add(capability);
|
|
240
|
+
console.log(message);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
console.debug(message);
|
|
244
|
+
}
|
|
241
245
|
}
|
|
242
246
|
this.waitCount++;
|
|
243
247
|
let timer;
|
|
244
248
|
try {
|
|
245
249
|
await Promise.race([
|
|
246
|
-
|
|
250
|
+
...depKeys.map((k) => this.waiterFor(k).promise),
|
|
247
251
|
new Promise((resolve) => {
|
|
248
252
|
timer = setTimeout(resolve, remaining);
|
|
249
253
|
// Never keep the process alive just for a settle timer.
|
|
@@ -256,9 +260,18 @@ export class SettleState {
|
|
|
256
260
|
clearTimeout(timer);
|
|
257
261
|
}
|
|
258
262
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Wait until `depKey` resolves or the remaining settle budget elapses.
|
|
266
|
+
* Event-driven: the dependency's resolution promise is raced against a
|
|
267
|
+
* timer bounded by the remaining window — never a fixed sleep.
|
|
268
|
+
*/
|
|
269
|
+
async waitFor(depKey, capability) {
|
|
270
|
+
const remaining = this.remainingMs();
|
|
271
|
+
if (remaining <= 0 || this.resolved.has(depKey)) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
await this.raceWaiters([depKey], [capability], remaining);
|
|
262
275
|
}
|
|
263
276
|
/**
|
|
264
277
|
* Await every pending dependency in turn. The per-wait budget is the
|
|
@@ -270,6 +283,22 @@ export class SettleState {
|
|
|
270
283
|
await this.waitFor(depKey, capability);
|
|
271
284
|
}
|
|
272
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Wait until ANY of `pending` resolves or the remaining settle budget
|
|
288
|
+
* elapses. Unlike {@link awaitPending} (which blocks on each key in turn),
|
|
289
|
+
* this races every pending key's resolution promise against ONE budget timer,
|
|
290
|
+
* so a caller gated on a floor wakes the moment ANY qualifying dependency
|
|
291
|
+
* lands — never sleeping on an already-satisfied floor because it happened to
|
|
292
|
+
* be awaiting a still-pending sibling key (RFC #1280 minAvailable).
|
|
293
|
+
*/
|
|
294
|
+
async waitForAny(pending) {
|
|
295
|
+
const remaining = this.remainingMs();
|
|
296
|
+
const unresolved = pending.filter((p) => !this.resolved.has(p.depKey));
|
|
297
|
+
if (remaining <= 0 || unresolved.length === 0) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
await this.raceWaiters(unresolved.map((p) => p.depKey), unresolved.map((p) => p.capability), remaining);
|
|
301
|
+
}
|
|
273
302
|
}
|
|
274
303
|
let settleState = new SettleState();
|
|
275
304
|
/** Get the process-wide settle state. */
|
package/dist/settle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settle.js","sourceRoot":"","sources":["../src/settle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,WAAW,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UPERSEDED executor —
|
|
5
|
+
* the app compares the calling job's epoch via {@link callingJob} (issue
|
|
6
|
+
* #1263) against its own live epoch — rejects the call by throwing
|
|
7
|
+
* {@link MeshSupersededError}. That crosses the wire as the reserved app
|
|
8
|
+
* envelope `{"error":"claim_superseded"}` (plus an optional `"detail"`
|
|
9
|
+
* string), and the CALLING side's injected proxy recognizes the envelope and
|
|
10
|
+
* re-throws {@link MeshSupersededError}. A superseded caller then unwinds with
|
|
11
|
+
* one `catch (e) { if (e instanceof MeshSupersededError) ... }` instead of
|
|
12
|
+
* string-matching `claim_superseded` after every mutating call.
|
|
13
|
+
*
|
|
14
|
+
* The framework does NOT auto-detect supersession — the app decides (full
|
|
15
|
+
* control); the framework provides the typed class plus the emit/recognize
|
|
16
|
+
* plumbing. This is the structural parallel of the `dependency_unavailable`
|
|
17
|
+
* refusal (issue #1273): both throw a `UserError` whose message is a reserved
|
|
18
|
+
* JSON envelope, so the contract (not the carrier) drives classification.
|
|
19
|
+
*/
|
|
20
|
+
import { UserError } from "fastmcp";
|
|
21
|
+
/**
|
|
22
|
+
* Reserved marker string for the supersession envelope. This is the SAME
|
|
23
|
+
* canonical marker the job path already uses on the wire (Rust
|
|
24
|
+
* `task_backend.rs` `CLAIM_SUPERSEDED_REASON` / Go `ent_service_jobs.go`),
|
|
25
|
+
* reused verbatim so a superseded signal is one string end-to-end.
|
|
26
|
+
*/
|
|
27
|
+
export declare const CLAIM_SUPERSEDED_MARKER = "claim_superseded";
|
|
28
|
+
/**
|
|
29
|
+
* Thrown by a provider tool to reject a call from a superseded executor.
|
|
30
|
+
*
|
|
31
|
+
* Extends fastmcp's {@link UserError} — the same error primitive the
|
|
32
|
+
* `dependency_unavailable` refusal uses (agent.ts) — so throwing it from a
|
|
33
|
+
* `@mesh.tool` handler auto-emits an `isError` tool result whose text is the
|
|
34
|
+
* reserved envelope, through the EXISTING fastmcp UserError path (fastmcp maps
|
|
35
|
+
* a thrown `UserError` to `{content:[{text: error.message}], isError:true}`,
|
|
36
|
+
* so no provider wrapper change is needed).
|
|
37
|
+
*
|
|
38
|
+
* The serialized message (`err.message`) is
|
|
39
|
+
* `{"error":"claim_superseded","detail":<detail>}` — the `detail` key is
|
|
40
|
+
* omitted entirely when no detail is supplied.
|
|
41
|
+
*
|
|
42
|
+
* Provider usage:
|
|
43
|
+
* ```ts
|
|
44
|
+
* const cj = callingJob();
|
|
45
|
+
* if (cj && cj.claimEpoch != null && cj.claimEpoch < myLiveEpoch) {
|
|
46
|
+
* throw new MeshSupersededError(`stale epoch ${cj.claimEpoch}`);
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* `if (e instanceof MeshSupersededError)` is the specific catch this enables;
|
|
51
|
+
* because it IS a `UserError`, `if (e instanceof UserError)` still catches it
|
|
52
|
+
* too.
|
|
53
|
+
*/
|
|
54
|
+
export declare class MeshSupersededError extends UserError {
|
|
55
|
+
readonly detail?: string;
|
|
56
|
+
constructor(detail?: string);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Return a {@link MeshSupersededError} if `text` is the reserved supersession
|
|
60
|
+
* envelope, else `null`.
|
|
61
|
+
*
|
|
62
|
+
* Defensive parse for the consumer recognize path: a non-JSON body, a JSON
|
|
63
|
+
* body that is not a plain object, or one whose `error` field is not exactly
|
|
64
|
+
* the reserved marker all return `null` so the caller falls through to its
|
|
65
|
+
* existing generic error handling. Only the exact reserved marker is
|
|
66
|
+
* classified — a `dependency_unavailable` (or any other) envelope is left
|
|
67
|
+
* alone.
|
|
68
|
+
*/
|
|
69
|
+
export declare function parseSupersededEnvelope(text: string): MeshSupersededError | null;
|
|
70
|
+
//# sourceMappingURL=superseded.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"superseded.d.ts","sourceRoot":"","sources":["../src/superseded.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBAEb,MAAM,CAAC,EAAE,MAAM;CAW5B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,GACX,mBAAmB,GAAG,IAAI,CAsB5B"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed supersession signal (issue #1278).
|
|
3
|
+
*
|
|
4
|
+
* A provider tool that detects it is being called by a SUPERSEDED executor —
|
|
5
|
+
* the app compares the calling job's epoch via {@link callingJob} (issue
|
|
6
|
+
* #1263) against its own live epoch — rejects the call by throwing
|
|
7
|
+
* {@link MeshSupersededError}. That crosses the wire as the reserved app
|
|
8
|
+
* envelope `{"error":"claim_superseded"}` (plus an optional `"detail"`
|
|
9
|
+
* string), and the CALLING side's injected proxy recognizes the envelope and
|
|
10
|
+
* re-throws {@link MeshSupersededError}. A superseded caller then unwinds with
|
|
11
|
+
* one `catch (e) { if (e instanceof MeshSupersededError) ... }` instead of
|
|
12
|
+
* string-matching `claim_superseded` after every mutating call.
|
|
13
|
+
*
|
|
14
|
+
* The framework does NOT auto-detect supersession — the app decides (full
|
|
15
|
+
* control); the framework provides the typed class plus the emit/recognize
|
|
16
|
+
* plumbing. This is the structural parallel of the `dependency_unavailable`
|
|
17
|
+
* refusal (issue #1273): both throw a `UserError` whose message is a reserved
|
|
18
|
+
* JSON envelope, so the contract (not the carrier) drives classification.
|
|
19
|
+
*/
|
|
20
|
+
import { UserError } from "fastmcp";
|
|
21
|
+
/**
|
|
22
|
+
* Reserved marker string for the supersession envelope. This is the SAME
|
|
23
|
+
* canonical marker the job path already uses on the wire (Rust
|
|
24
|
+
* `task_backend.rs` `CLAIM_SUPERSEDED_REASON` / Go `ent_service_jobs.go`),
|
|
25
|
+
* reused verbatim so a superseded signal is one string end-to-end.
|
|
26
|
+
*/
|
|
27
|
+
export const CLAIM_SUPERSEDED_MARKER = "claim_superseded";
|
|
28
|
+
/**
|
|
29
|
+
* Thrown by a provider tool to reject a call from a superseded executor.
|
|
30
|
+
*
|
|
31
|
+
* Extends fastmcp's {@link UserError} — the same error primitive the
|
|
32
|
+
* `dependency_unavailable` refusal uses (agent.ts) — so throwing it from a
|
|
33
|
+
* `@mesh.tool` handler auto-emits an `isError` tool result whose text is the
|
|
34
|
+
* reserved envelope, through the EXISTING fastmcp UserError path (fastmcp maps
|
|
35
|
+
* a thrown `UserError` to `{content:[{text: error.message}], isError:true}`,
|
|
36
|
+
* so no provider wrapper change is needed).
|
|
37
|
+
*
|
|
38
|
+
* The serialized message (`err.message`) is
|
|
39
|
+
* `{"error":"claim_superseded","detail":<detail>}` — the `detail` key is
|
|
40
|
+
* omitted entirely when no detail is supplied.
|
|
41
|
+
*
|
|
42
|
+
* Provider usage:
|
|
43
|
+
* ```ts
|
|
44
|
+
* const cj = callingJob();
|
|
45
|
+
* if (cj && cj.claimEpoch != null && cj.claimEpoch < myLiveEpoch) {
|
|
46
|
+
* throw new MeshSupersededError(`stale epoch ${cj.claimEpoch}`);
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* `if (e instanceof MeshSupersededError)` is the specific catch this enables;
|
|
51
|
+
* because it IS a `UserError`, `if (e instanceof UserError)` still catches it
|
|
52
|
+
* too.
|
|
53
|
+
*/
|
|
54
|
+
export class MeshSupersededError extends UserError {
|
|
55
|
+
detail;
|
|
56
|
+
constructor(detail) {
|
|
57
|
+
const envelope = {
|
|
58
|
+
error: CLAIM_SUPERSEDED_MARKER,
|
|
59
|
+
};
|
|
60
|
+
if (detail !== undefined) {
|
|
61
|
+
envelope.detail = detail;
|
|
62
|
+
}
|
|
63
|
+
super(JSON.stringify(envelope));
|
|
64
|
+
this.name = "MeshSupersededError";
|
|
65
|
+
this.detail = detail;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Return a {@link MeshSupersededError} if `text` is the reserved supersession
|
|
70
|
+
* envelope, else `null`.
|
|
71
|
+
*
|
|
72
|
+
* Defensive parse for the consumer recognize path: a non-JSON body, a JSON
|
|
73
|
+
* body that is not a plain object, or one whose `error` field is not exactly
|
|
74
|
+
* the reserved marker all return `null` so the caller falls through to its
|
|
75
|
+
* existing generic error handling. Only the exact reserved marker is
|
|
76
|
+
* classified — a `dependency_unavailable` (or any other) envelope is left
|
|
77
|
+
* alone.
|
|
78
|
+
*/
|
|
79
|
+
export function parseSupersededEnvelope(text) {
|
|
80
|
+
let payload;
|
|
81
|
+
try {
|
|
82
|
+
payload = JSON.parse(text);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
if (payload === null ||
|
|
88
|
+
typeof payload !== "object" ||
|
|
89
|
+
Array.isArray(payload)) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const obj = payload;
|
|
93
|
+
if (obj.error !== CLAIM_SUPERSEDED_MARKER) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const detail = obj.detail;
|
|
97
|
+
return new MeshSupersededError(typeof detail === "string" ? detail : undefined);
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=superseded.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"superseded.js","sourceRoot":"","sources":["../src/superseded.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,mBAAoB,SAAQ,SAAS;IACvC,MAAM,CAAU;IAEzB,YAAY,MAAe;QACzB,MAAM,QAAQ,GAAuC;YACnD,KAAK,EAAE,uBAAuB;SAC/B,CAAC;QACF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;QAC3B,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,uBAAuB,CACrC,IAAY;IAEZ,IAAI,OAAgB,CAAC;IACrB,IAAI,CAAC;QACH,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IACE,OAAO,KAAK,IAAI;QAChB,OAAO,OAAO,KAAK,QAAQ;QAC3B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EACtB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,GAAG,GAAG,OAAkC,CAAC;IAC/C,IAAI,GAAG,CAAC,KAAK,KAAK,uBAAuB,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC1B,OAAO,IAAI,mBAAmB,CAC5B,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAChD,CAAC;AACJ,CAAC"}
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
import { parentPort, workerData, isMainThread } from "node:worker_threads";
|
|
21
21
|
import { createRequire } from "node:module";
|
|
22
22
|
import { pathToFileURL } from "node:url";
|
|
23
|
+
import { serializeError } from "./worker-error-serde.js";
|
|
23
24
|
if (isMainThread) {
|
|
24
25
|
throw new Error("tool-worker-entry.js must be loaded inside a worker thread");
|
|
25
26
|
}
|
|
@@ -89,18 +90,6 @@ async function bootstrap() {
|
|
|
89
90
|
});
|
|
90
91
|
parentPort.postMessage({ kind: "ready" });
|
|
91
92
|
}
|
|
92
|
-
function serializeError(err) {
|
|
93
|
-
if (!(err instanceof Error)) {
|
|
94
|
-
return { name: "Error", message: String(err) };
|
|
95
|
-
}
|
|
96
|
-
const out = { name: err.name, message: err.message, stack: err.stack };
|
|
97
|
-
const errAny = err;
|
|
98
|
-
if (errAny.code !== undefined)
|
|
99
|
-
out.code = errAny.code;
|
|
100
|
-
if (errAny.cause !== undefined)
|
|
101
|
-
out.cause = serializeError(errAny.cause);
|
|
102
|
-
return out;
|
|
103
|
-
}
|
|
104
93
|
function handleMessage(msg, tools, createProxy, runWithTraceContext, runWithPropagatedHeaders) {
|
|
105
94
|
if (!msg || typeof msg !== "object")
|
|
106
95
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-worker-entry.js","sourceRoot":"","sources":["../src/tool-worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-worker-entry.js","sourceRoot":"","sources":["../src/tool-worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC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-pool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;
|
|
1
|
+
{"version":3,"file":"tool-worker-pool.d.ts","sourceRoot":"","sources":["../src/tool-worker-pool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AASH,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,CAAC,SAAS,GAAG,IAAI,CAAC,EAAE,CAAC;IACjC,YAAY,EAAE,OAAO,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AAwLD;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAiCzE;AAED;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAAC,UAAU,SAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BhE"}
|