@adaptivemcp/spec 0.2.1 → 0.4.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kemal Elmizan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/events.d.ts CHANGED
@@ -6,6 +6,7 @@ export interface ToolEventContext {
6
6
  sessionId?: string;
7
7
  requestId?: string;
8
8
  model?: string;
9
+ metadata?: Record<string, unknown>;
9
10
  }
10
11
  /**
11
12
  * Construct a tool execution event with sensible defaults. Timestamps use the
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEjE,eAAO,MAAM,oBAAoB,EAAG,0CAAmD,CAAC;AAExF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,gBAAgB,EACrB,MAAM,EAAE,UAAU,EAClB,KAAK,GAAE,OAAO,CAAC,kBAAkB,CAAM,GACtC,kBAAkB,CAYpB"}
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEjE,eAAO,MAAM,oBAAoB,EAAG,0CAAmD,CAAC;AAExF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,gBAAgB,EACrB,MAAM,EAAE,UAAU,EAClB,KAAK,GAAE,OAAO,CAAC,kBAAkB,CAAM,GACtC,kBAAkB,CAYpB"}
@@ -1 +1 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,0CAAmD,CAAC;AAUxF;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,GAAqB,EACrB,MAAkB,EAClB,QAAqC,EAAE;IAEvC,OAAO;QACL,EAAE,EAAE,KAAK,CAAC,EAAE,IAAI,MAAM,CAAC,UAAU,EAAE;QACnC,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACtD,MAAM;QACN,GAAG,KAAK;KACT,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,0CAAmD,CAAC;AAWxF;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,GAAqB,EACrB,MAAkB,EAClB,QAAqC,EAAE;IAEvC,OAAO;QACL,EAAE,EAAE,KAAK,CAAC,EAAE,IAAI,MAAM,CAAC,UAAU,EAAE;QACnC,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACtD,MAAM;QACN,GAAG,KAAK;KACT,CAAC;AACJ,CAAC"}
@@ -0,0 +1,63 @@
1
+ import type { ExecutionNode } from "./types.js";
2
+ /**
3
+ * Canonical, JSON-serializable wire format for a session's execution graph —
4
+ * the shape any MCP server can emit (and any client can parse) for
5
+ * cross-server graph correlation. Field names are snake_case, matching the
6
+ * convention already used by every other *Document wire type in this
7
+ * codebase (`WorkflowGraphDocument`, `GraphInsightsDocument`); TS-internal
8
+ * types like `ExecutionNode` stay camelCase.
9
+ *
10
+ * This replaces the old `ExecutionGraph` type (Map-based `nodes`, never
11
+ * built or consumed anywhere in the codebase) — Maps aren't directly
12
+ * JSON-serializable, so they were never a viable wire format to begin with.
13
+ * "Federation" here means a shared, importable schema + builder other MCP
14
+ * servers' code can construct against — not an implemented multi-server
15
+ * aggregation/discovery protocol, which would need infrastructure (server
16
+ * registries, cross-server RPC) that doesn't exist in this codebase.
17
+ */
18
+ export interface ExecutionGraphResource {
19
+ version: string;
20
+ etag: string;
21
+ generated_at: string;
22
+ session_id: string;
23
+ workflow_id?: string;
24
+ nodes: Array<{
25
+ id: string;
26
+ tool: string;
27
+ server?: string;
28
+ parent?: string;
29
+ children: string[];
30
+ timestamp: string;
31
+ duration_ms?: number;
32
+ status: string;
33
+ cost?: number;
34
+ model?: string;
35
+ /** W3C `traceparent` recorded on the node, if graph tracking generated one. */
36
+ trace_parent?: string;
37
+ }>;
38
+ edges: Array<{
39
+ from: string;
40
+ to: string;
41
+ }>;
42
+ /**
43
+ * Opaque pagination cursor (the `id` of the last returned node) — present
44
+ * when more nodes exist beyond this page. Absent on the last page or when
45
+ * the caller didn't request pagination.
46
+ */
47
+ next_cursor?: string;
48
+ }
49
+ export interface BuildExecutionGraphOptions {
50
+ version: string;
51
+ sessionId: string;
52
+ generatedAt?: string;
53
+ workflowId?: string;
54
+ nextCursor?: string;
55
+ }
56
+ /**
57
+ * Pure builder: maps a flat `ExecutionNode[]` (already the desired page) into
58
+ * the canonical wire shape. `etag` is returned empty — it's a hash of this
59
+ * very output, so callers compute it over the returned object and assign it
60
+ * afterward (see `ExtensionController.buildExecutionGraphDocument`).
61
+ */
62
+ export declare function buildExecutionGraph(nodes: ExecutionNode[], opts: BuildExecutionGraphOptions): ExecutionGraphResource;
63
+ //# sourceMappingURL=execution-graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-graph.d.ts","sourceRoot":"","sources":["../src/execution-graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,KAAK,CAAC;QACX,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,+EAA+E;QAC/E,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC,CAAC;IACH,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC3C;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,IAAI,EAAE,0BAA0B,GAAG,sBAAsB,CA0BpH"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Pure builder: maps a flat `ExecutionNode[]` (already the desired page) into
3
+ * the canonical wire shape. `etag` is returned empty — it's a hash of this
4
+ * very output, so callers compute it over the returned object and assign it
5
+ * afterward (see `ExtensionController.buildExecutionGraphDocument`).
6
+ */
7
+ export function buildExecutionGraph(nodes, opts) {
8
+ const renderedNodes = nodes.map((n) => ({
9
+ id: n.id,
10
+ tool: n.toolName,
11
+ server: n.serverName,
12
+ parent: n.parentId,
13
+ children: n.childrenIds,
14
+ timestamp: n.timestamp,
15
+ duration_ms: n.durationMs,
16
+ status: n.status,
17
+ cost: n.cost?.amount,
18
+ model: n.model,
19
+ trace_parent: n.metadata?.traceparent,
20
+ }));
21
+ const edges = nodes.flatMap((n) => n.childrenIds.map((childId) => ({ from: n.id, to: childId })));
22
+ return {
23
+ version: opts.version,
24
+ etag: "",
25
+ generated_at: opts.generatedAt ?? new Date().toISOString(),
26
+ session_id: opts.sessionId,
27
+ workflow_id: opts.workflowId ?? nodes[0]?.workflowId ?? "unknown",
28
+ nodes: renderedNodes,
29
+ edges,
30
+ next_cursor: opts.nextCursor,
31
+ };
32
+ }
33
+ //# sourceMappingURL=execution-graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-graph.js","sourceRoot":"","sources":["../src/execution-graph.ts"],"names":[],"mappings":"AAuDA;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAsB,EAAE,IAAgC;IAC1F,MAAM,aAAa,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACtC,EAAE,EAAE,CAAC,CAAC,EAAE;QACR,IAAI,EAAE,CAAC,CAAC,QAAQ;QAChB,MAAM,EAAE,CAAC,CAAC,UAAU;QACpB,MAAM,EAAE,CAAC,CAAC,QAAQ;QAClB,QAAQ,EAAE,CAAC,CAAC,WAAW;QACvB,SAAS,EAAE,CAAC,CAAC,SAAS;QACtB,WAAW,EAAE,CAAC,CAAC,UAAU;QACzB,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM;QACpB,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,YAAY,EAAE,CAAC,CAAC,QAAQ,EAAE,WAAiC;KAC5D,CAAC,CAAC,CAAC;IACJ,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;IAElG,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,IAAI,EAAE,EAAE;QACR,YAAY,EAAE,IAAI,CAAC,WAAW,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QAC1D,UAAU,EAAE,IAAI,CAAC,SAAS;QAC1B,WAAW,EAAE,IAAI,CAAC,UAAU,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,UAAU,IAAI,SAAS;QACjE,KAAK,EAAE,aAAa;QACpB,KAAK;QACL,WAAW,EAAE,IAAI,CAAC,UAAU;KAC7B,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export * from "./types.js";
2
+ export * from "./result.js";
2
3
  export * from "./extensions.js";
3
4
  export * from "./events.js";
5
+ export * from "./execution-graph.js";
4
6
  export { SPEC_VERSION } from "./version.js";
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  export * from "./types.js";
2
+ export * from "./result.js";
2
3
  export * from "./extensions.js";
3
4
  export * from "./events.js";
5
+ export * from "./execution-graph.js";
4
6
  export { SPEC_VERSION } from "./version.js";
5
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Result classification.
3
+ *
4
+ * A client's transport may report a tool call as "ok" while the server has, in
5
+ * fact, signalled a *logical* failure in-band — for example a JSON envelope with
6
+ * `status: "error"` instead of the protocol-level `isError` flag. Left alone,
7
+ * that outcome is recorded as a success, which poisons every derived signal:
8
+ * failure rate, insights, routing, drift.
9
+ *
10
+ * A `ToolResultClassifier` is the seam that corrects this. It runs on each
11
+ * execution *attempt*, before the outcome is recorded (and therefore before the
12
+ * retry decision), so a reclassified failure can also trigger a retry. It is
13
+ * advisory in the same sense as the rest of Adaptive MCP: the host opts in by
14
+ * supplying a classifier; returning `undefined` leaves the outcome untouched.
15
+ */
16
+ /** A raw tool outcome, as produced by the transport before classification. */
17
+ export interface ToolCallOutcome {
18
+ ok: boolean;
19
+ error?: string;
20
+ output?: unknown;
21
+ }
22
+ /** Fields a classifier may override; omitted fields keep their raw value. */
23
+ export interface ToolResultClassification {
24
+ ok?: boolean;
25
+ error?: string;
26
+ }
27
+ /** Context identifying the call an outcome belongs to. */
28
+ export interface ToolResultContext {
29
+ toolName: string;
30
+ serverName?: string;
31
+ }
32
+ /**
33
+ * Inspect a raw outcome and optionally re-classify it. Return `undefined` (or
34
+ * nothing) to leave it unchanged.
35
+ */
36
+ export type ToolResultClassifier = (outcome: ToolCallOutcome, context: ToolResultContext) => ToolResultClassification | void | undefined;
37
+ //# sourceMappingURL=result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,8EAA8E;AAC9E,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,6EAA6E;AAC7E,MAAM,WAAW,wBAAwB;IACvC,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,0DAA0D;AAC1D,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,CACjC,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,iBAAiB,KACvB,wBAAwB,GAAG,IAAI,GAAG,SAAS,CAAC"}
package/dist/result.js ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Result classification.
3
+ *
4
+ * A client's transport may report a tool call as "ok" while the server has, in
5
+ * fact, signalled a *logical* failure in-band — for example a JSON envelope with
6
+ * `status: "error"` instead of the protocol-level `isError` flag. Left alone,
7
+ * that outcome is recorded as a success, which poisons every derived signal:
8
+ * failure rate, insights, routing, drift.
9
+ *
10
+ * A `ToolResultClassifier` is the seam that corrects this. It runs on each
11
+ * execution *attempt*, before the outcome is recorded (and therefore before the
12
+ * retry decision), so a reclassified failure can also trigger a retry. It is
13
+ * advisory in the same sense as the rest of Adaptive MCP: the host opts in by
14
+ * supplying a classifier; returning `undefined` leaves the outcome untouched.
15
+ */
16
+ export {};
17
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
package/dist/types.d.ts CHANGED
@@ -28,13 +28,30 @@ export interface ToolExecutionEvent {
28
28
  requestId?: string;
29
29
  timestamp: string;
30
30
  durationMs?: number;
31
+ /** Total execution attempts (1 = no retry); for retry-rate metrics. */
32
+ attempts?: number;
31
33
  status: ToolStatus;
32
34
  input?: unknown;
33
35
  output?: unknown;
34
36
  error?: ToolError;
35
37
  model?: string;
36
38
  cost?: CostInfo;
39
+ /**
40
+ * The decoding Adaptive MCP actually applied to the completion that produced
41
+ * this call. Recording the *resolved* values + `resolverVersion` keeps past
42
+ * decisions reproducible after the resolver's tables change (ROADMAP 8d).
43
+ */
44
+ decoding?: ToolDecoding;
45
+ /** Token usage for that completion, when the host knows it. */
46
+ usage?: {
47
+ inputTokens?: number;
48
+ outputTokens?: number;
49
+ };
37
50
  metadata?: Record<string, unknown>;
51
+ /** Parent node ID in the execution graph (for DAG construction) */
52
+ parentId?: string;
53
+ /** Human-readable workflow name (e.g., "deploy_release") */
54
+ workflowId?: string;
38
55
  }
39
56
  export type InsightSource = "telemetry" | "evaluation" | "human" | "memory";
40
57
  /**
@@ -43,6 +60,7 @@ export type InsightSource = "telemetry" | "evaluation" | "human" | "memory";
43
60
  */
44
61
  export interface Insight {
45
62
  toolName: string;
63
+ serverName?: string;
46
64
  key: string;
47
65
  value: unknown;
48
66
  confidence: number;
@@ -51,29 +69,154 @@ export interface Insight {
51
69
  sampleSize?: number;
52
70
  }
53
71
  export type RiskLevel = "low" | "medium" | "high";
72
+ /**
73
+ * Core MCP `ToolAnnotations` (the `annotations` object on a tool in
74
+ * `tools/list`). Adaptive MCP maps its *static* risk onto these native hints so
75
+ * hosts don't have to learn a parallel taxonomy. See `riskToToolAnnotations`.
76
+ */
77
+ export interface ToolAnnotationsLike {
78
+ title?: string;
79
+ readOnlyHint?: boolean;
80
+ destructiveHint?: boolean;
81
+ idempotentHint?: boolean;
82
+ openWorldHint?: boolean;
83
+ }
84
+ /**
85
+ * Map an Adaptive MCP static `risk` level onto core MCP `ToolAnnotations`.
86
+ *
87
+ * The MCP spec says clients MUST treat `ToolAnnotations` as untrusted unless
88
+ * from a trusted server, so this is advisory — but it rides the host's native,
89
+ * already-parsed risk signal (higher uptake than a custom `risk` field). The
90
+ * server-published tools-metadata resource keeps `risk` for the *learned/
91
+ * observed* dimension only (e.g. "observed flaky / costly in practice"), which
92
+ * core hints cannot express. See doubts.md §10/§11 (Strategy 2 of the hybrid).
93
+ */
94
+ export declare function riskToToolAnnotations(risk?: RiskLevel): ToolAnnotationsLike;
54
95
  /**
55
96
  * Written metadata attached to a tool by a human or operator.
97
+ *
98
+ * `risk` here is the *static* operator-assigned risk. Per the governance hybrid
99
+ * (doubts.md §11), static risk SHOULD be projected onto core `Tool.annotations`
100
+ * via `riskToToolAnnotations` rather than emitted in the resource; the resource's
101
+ * `annotation.risk` is reserved for learned/observed risk. `owner`/`tags`/
102
+ * `description` are non-governance metadata with no core-MCP equivalent.
56
103
  */
57
104
  export interface Annotation {
58
105
  toolName: string;
106
+ serverName?: string;
59
107
  risk?: RiskLevel;
60
108
  owner?: string;
61
109
  tags?: string[];
62
110
  description?: string;
63
111
  metadata?: Record<string, unknown>;
64
112
  }
65
- export type RecommendationType = "model" | "approval" | "workflow" | "routing";
113
+ export type RecommendationType = "model" | "approval" | "workflow" | "routing" | "sampling" | "decoding";
66
114
  /**
67
115
  * A suggested adaptation derived from accumulated knowledge.
68
116
  */
69
117
  export interface Recommendation {
70
118
  toolName: string;
119
+ serverName?: string;
71
120
  type: RecommendationType;
72
121
  payload: unknown;
73
122
  rationale: string;
74
123
  confidence: number;
75
124
  generatedAt: string;
76
125
  }
126
+ /**
127
+ * Payload shape for `Recommendation.type === "sampling"`: suggested LLM
128
+ * sampling parameters for the *next* generation turn involving this tool.
129
+ * All fields optional — an advisor only emits the parameters it has an
130
+ * opinion about; a host applying this should treat an absent field as "no
131
+ * change from your own default," never as "set to undefined/null."
132
+ *
133
+ * Advisory only: nothing in this repo makes an LLM completion call, so this
134
+ * payload has no effect unless a host reads it and applies it to its own
135
+ * request.
136
+ *
137
+ * @deprecated Superseded by `DecodingProfile` + `DecodingResolver` (Phase 8,
138
+ * see docs/ROADMAP.md and docs/doubts.md §13 D5). Kept exported and working —
139
+ * a shipped public shape shouldn't break existing consumers for a rename —
140
+ * but new code should produce/consume `DecodingRecommendation` instead. Will
141
+ * be removed at the next `SPEC_VERSION` major bump.
142
+ */
143
+ export interface SamplingRecommendationPayload {
144
+ temperature?: number;
145
+ topP?: number;
146
+ topK?: number;
147
+ presencePenalty?: number;
148
+ repetitionPenalty?: number;
149
+ }
150
+ /**
151
+ * A symbolic, backend-agnostic decoding intent. `DecodingAdvisor` emits this
152
+ * instead of raw sampling numbers — nothing backend-specific belongs here.
153
+ * `DecodingResolver` is the only thing that translates it into concrete
154
+ * knobs for a specific backend. See docs/doubts.md §13 D1.
155
+ */
156
+ export interface DecodingProfile {
157
+ id: "deterministic" | "balanced" | "creative";
158
+ }
159
+ /**
160
+ * Which decoding knobs a specific model/inference backend actually exposes.
161
+ * `DecodingResolver` uses this to translate a `DecodingProfile` into
162
+ * `ResolvedDecodingSettings`, dropping (never approximating) knobs a backend
163
+ * doesn't support — e.g. `minP` and `topP` aren't equivalent, so one is never
164
+ * substituted for the other.
165
+ */
166
+ export interface ModelCapabilities {
167
+ supports: {
168
+ temperature?: boolean;
169
+ topP?: boolean;
170
+ topK?: boolean;
171
+ minP?: boolean;
172
+ presencePenalty?: boolean;
173
+ repetitionPenalty?: boolean;
174
+ frequencyPenalty?: boolean;
175
+ };
176
+ }
177
+ /**
178
+ * Concrete, backend-specific decoding parameters produced by a
179
+ * `DecodingResolver`. Superset of the deprecated `SamplingRecommendationPayload`
180
+ * (adds `minP`/`frequencyPenalty`) — all fields optional, absent means "no
181
+ * opinion," never "set to null."
182
+ */
183
+ export interface ResolvedDecodingSettings {
184
+ temperature?: number;
185
+ topP?: number;
186
+ topK?: number;
187
+ minP?: number;
188
+ presencePenalty?: number;
189
+ repetitionPenalty?: number;
190
+ frequencyPenalty?: number;
191
+ }
192
+ /**
193
+ * What `DecodingAdvisor` + `DecodingResolver` jointly produce: a suggested
194
+ * decoding profile, its concrete resolved settings for a specific backend,
195
+ * the resolver version that produced them (so past decisions stay
196
+ * reproducible after the resolver's tables change), and enough evidence
197
+ * (`confidence`/`reasons`) for a host to decide whether to trust it.
198
+ *
199
+ * Advisory only, same as `SamplingRecommendationPayload` — nothing here is
200
+ * auto-applied; a host reads this and chooses whether to act on it.
201
+ */
202
+ export interface DecodingRecommendation {
203
+ profile: DecodingProfile;
204
+ resolved: ResolvedDecodingSettings;
205
+ resolverVersion: string;
206
+ confidence: number;
207
+ reasons: string[];
208
+ }
209
+ /**
210
+ * The decoding actually applied to a completion, as stored on a
211
+ * `ToolExecutionEvent` (ROADMAP 8d). A flattened `DecodingRecommendation`:
212
+ * the profile id, the concrete knobs, and the resolver version that produced
213
+ * them.
214
+ */
215
+ export interface ToolDecoding {
216
+ profile: DecodingProfile["id"];
217
+ resolverVersion: string;
218
+ resolved: ResolvedDecodingSettings;
219
+ }
77
220
  /**
78
221
  * The store record for a tool, persisted in SQLite.
79
222
  * The YAML tools-metadata view is derived from this record.
@@ -94,6 +237,160 @@ export interface ToolStats {
94
237
  avgDurationMs: number | null;
95
238
  totalCost: number;
96
239
  lastObservedAt: string | null;
240
+ /** Average output tokens per invocation (for context cost tracking) */
241
+ avgOutputTokens?: number;
242
+ }
243
+ /**
244
+ * A bounded dimension tuple for a metric cell. Keys with undefined values are
245
+ * omitted. Kept open-ended (`[key]`) so new dimensions don't need a migration;
246
+ * cardinality is bounded by the host (models from its catalog, 3 decoding
247
+ * profiles, few resolver versions).
248
+ */
249
+ export interface MetricDimensions {
250
+ model?: string;
251
+ decodingProfile?: string;
252
+ resolverVersion?: string;
253
+ [key: string]: string | undefined;
254
+ }
255
+ /**
256
+ * A pre-aggregated metric cell: events folded into a bounded dimension tuple and
257
+ * window. This is how Adaptive MCP keeps *rich, queryable* metadata without a
258
+ * raw events table — counters, sums, a fixed-bucket duration histogram, EWMA
259
+ * recency, and a bounded exemplar ring, instead of every event.
260
+ */
261
+ export interface MetricCell {
262
+ toolName: string;
263
+ serverName?: string;
264
+ /** Retention window key; `"all"` is the lifetime aggregate. */
265
+ window: string;
266
+ dimensions: MetricDimensions;
267
+ invocations: number;
268
+ failures: number;
269
+ /** Sum of execution attempts (> invocations when retries happened). */
270
+ attempts: number;
271
+ /** Error-code → count. */
272
+ errorCodes: Record<string, number>;
273
+ durationSum: number;
274
+ durationCount: number;
275
+ /** Counts per fixed duration bucket (ms); see the store's bucket bounds. */
276
+ durationHistogram: number[];
277
+ tokenInSum: number;
278
+ tokenOutSum: number;
279
+ tokenCount: number;
280
+ costSum: number;
281
+ /** Exponentially-weighted failure rate / duration, for recency-aware drift. */
282
+ ewmaFailureRate?: number;
283
+ ewmaDurationMs?: number;
284
+ firstSeen: string;
285
+ lastSeen: string;
286
+ /** Bounded ids of the most recent contributing events (drill-down). */
287
+ exemplars: string[];
288
+ }
289
+ /**
290
+ * A single node in the execution graph (DAG).
291
+ * Each tool invocation becomes a node with parent/children relationships.
292
+ */
293
+ export interface ExecutionNode {
294
+ id: string;
295
+ toolName: string;
296
+ serverName?: string;
297
+ sessionId: string;
298
+ workflowId?: string;
299
+ parentId?: string;
300
+ childrenIds: string[];
301
+ timestamp: string;
302
+ durationMs?: number;
303
+ status: ToolStatus;
304
+ input?: unknown;
305
+ output?: unknown;
306
+ error?: ToolError;
307
+ model?: string;
308
+ cost?: CostInfo;
309
+ metadata?: Record<string, unknown>;
310
+ }
311
+ /**
312
+ * Graph analysis results.
313
+ */
314
+ export interface CriticalPathResult {
315
+ path: ExecutionNode[];
316
+ totalDurationMs: number;
317
+ }
318
+ export interface Bottleneck {
319
+ node: ExecutionNode;
320
+ impactScore: number;
321
+ reason: "duration" | "fan_out" | "failure_rate" | "cost";
322
+ }
323
+ export interface FanOutReport {
324
+ maxFanOut: number;
325
+ avgFanOut: number;
326
+ parallelizableNodes: ExecutionNode[];
327
+ sequentialChains: ExecutionNode[][];
328
+ }
329
+ /**
330
+ * A recurring structural anti-pattern detected in a session's graph.
331
+ * Deliberately limited to two named shapes rather than general subgraph
332
+ * isomorphism (NP-hard, unnecessary for small execution DAGs).
333
+ */
334
+ export interface AntiPattern {
335
+ type: "sequential_bottleneck" | "diamond_dependency";
336
+ nodes: ExecutionNode[];
337
+ severity: number;
338
+ }
339
+ export interface FailureCascade {
340
+ rootCause: ExecutionNode;
341
+ affectedNodes: ExecutionNode[];
342
+ blastRadius: number;
343
+ }
344
+ /**
345
+ * Ancestor-based causal ordering among the failed nodes of a session: a
346
+ * failed node with no failed ancestor is a root cause; a failed node
347
+ * downstream of a failed ancestor is a symptom of the nearest one. This is
348
+ * NOT counterfactual causal inference (which would require replaying
349
+ * execution without the trigger) — it's graph-ancestry ordering over the
350
+ * failures actually recorded.
351
+ */
352
+ export interface CausalCascade {
353
+ rootCauses: ExecutionNode[];
354
+ symptoms: Array<{
355
+ node: ExecutionNode;
356
+ causedBy: ExecutionNode;
357
+ }>;
358
+ blastRadius: number;
359
+ }
360
+ export interface CostBreakdown {
361
+ totalCost: number;
362
+ byTool: Record<string, number>;
363
+ byNode: Record<string, number>;
364
+ criticalPathCost: number;
365
+ }
366
+ export interface WorkflowStats {
367
+ workflowId: string;
368
+ totalExecutions: number;
369
+ successRate: number;
370
+ avgDurationMs: number;
371
+ avgCost: number;
372
+ commonPatterns: WorkflowPattern[];
373
+ }
374
+ export interface WorkflowPattern {
375
+ pattern: string;
376
+ frequency: number;
377
+ avgDurationMs: number;
378
+ successRate: number;
379
+ }
380
+ /**
381
+ * A heuristic forecast for an in-progress workflow session, extrapolated
382
+ * from historical runs of the same workflow. NOT a trained/statistical
383
+ * model — a ratio-vs-baseline projection, in the same spirit as
384
+ * `detectAnomalies`'s duration/cost ratio checks.
385
+ */
386
+ export interface WorkflowForecast {
387
+ workflowId: string;
388
+ /** Nodes seen so far / historical avg node count for this workflow, capped at 1. */
389
+ progressRatio: number;
390
+ projectedDurationMs: number;
391
+ projectedCost: number;
392
+ /** Blend of historical failure rate and this session's own failures observed so far. */
393
+ failureProbability: number;
97
394
  }
98
395
  /**
99
396
  * The persistence boundary for Adaptive MCP.
@@ -102,15 +399,27 @@ export interface ToolStats {
102
399
  * backend (SQLite, Postgres, in-memory, remote) can be swapped without touching
103
400
  * the middleware. `MemoryStore` in `@adaptivemcp/memory` is the reference
104
401
  * implementation.
402
+ *
403
+ * Records are identified by the `(toolName, serverName)` pair, not `toolName`
404
+ * alone: two different MCP servers may expose a tool with the same name, and
405
+ * without the server in the key their records would collide. `serverName` is
406
+ * optional on read/write because not every call site knows which server it's
407
+ * dealing with; when omitted, lookups fall back to the most recently updated
408
+ * record with that `toolName` (ambiguous only if the same tool name is in use
409
+ * across multiple servers).
105
410
  */
106
411
  export interface Store {
107
412
  /** Close the underlying backend and release resources. */
108
413
  close(): void;
109
414
  /** Ensure a tool record exists, seeding it with an empty annotation. */
110
415
  ensureTool(toolName: string, serverName?: string): ToolRecord;
111
- /** Read a single tool record, or `undefined` if it has never been observed. */
112
- getTool(toolName: string): ToolRecord | undefined;
113
- /** Read every tool record, ordered by tool name. */
416
+ /**
417
+ * Read a single tool record, or `undefined` if it has never been observed.
418
+ * Pass `serverName` to disambiguate when the same tool name may exist on
419
+ * multiple servers; otherwise the most recently updated match is returned.
420
+ */
421
+ getTool(toolName: string, serverName?: string): ToolRecord | undefined;
422
+ /** Read every tool record, ordered by tool name then server name. */
114
423
  allTools(): ToolRecord[];
115
424
  /** Persist a human-written annotation (the static metadata layer). */
116
425
  setAnnotation(annotation: Annotation): ToolRecord;
@@ -123,8 +432,39 @@ export interface Store {
123
432
  * orchestration, and approval packages so each adaptation pass recomputes its
124
433
  * own recommendations instead of appending duplicates on every observation.
125
434
  */
126
- clearRecommendations(toolName: string, type: RecommendationType): ToolRecord;
435
+ clearRecommendations(toolName: string, type: RecommendationType, serverName?: string): ToolRecord;
127
436
  /** Fold a tool execution event into the persisted stats. */
128
437
  recordExecution(event: ToolExecutionEvent): ToolRecord;
438
+ /**
439
+ * Read pre-aggregated metric cells (bounded dimensional rollups folded from
440
+ * events). Optional: a backend without the rollup may omit it, in which case
441
+ * callers should fall back to sample-level data.
442
+ */
443
+ metricCells?(options?: {
444
+ toolName?: string;
445
+ serverName?: string;
446
+ }): MetricCell[];
447
+ /** Record an execution node in the graph. */
448
+ recordExecutionNode?(node: ExecutionNode): ExecutionNode;
449
+ /** Get an execution node by ID. */
450
+ getExecutionNode?(id: string): ExecutionNode | undefined;
451
+ /** Get all nodes for a session. */
452
+ getNodesBySession?(sessionId: string): ExecutionNode[];
453
+ /** Get all nodes for a workflow (across sessions). */
454
+ getNodesByWorkflow?(workflowId: string): ExecutionNode[];
455
+ /** Get every distinct workflow ID that has at least one recorded execution node. */
456
+ getWorkflowIds?(): string[];
457
+ /** Get every distinct session ID that has at least one recorded execution node. */
458
+ getSessionIds?(): string[];
459
+ /** Get children of a node. */
460
+ getChildren?(parentId: string): ExecutionNode[];
461
+ /** Get parent of a node. */
462
+ getParent?(childId: string): ExecutionNode | undefined;
463
+ /** Get root nodes (no parent) for a session. */
464
+ getRootNodes?(sessionId: string): ExecutionNode[];
465
+ /** Get leaf nodes (no children) for a session. */
466
+ getLeafNodes?(sessionId: string): ExecutionNode[];
467
+ /** Update children IDs of a parent node. */
468
+ updateChildrenIds?(parentId: string, childrenIds: string[]): void;
129
469
  }
130
470
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;AAE1E,MAAM,WAAW,QAAQ;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,YAAY,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE5E;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,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AC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,UAAU,EAAE,CAAC;IAGjF,6CAA6C;IAC7C,mBAAmB,CAAC,CAAC,IAAI,EAAE,aAAa,GAAG,aAAa,CAAC;IACzD,mCAAmC;IACnC,gBAAgB,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;IACzD,mCAAmC;IACnC,iBAAiB,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,EAAE,CAAC;IACvD,sDAAsD;IACtD,kBAAkB,CAAC,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa,EAAE,CAAC;IACzD,oFAAoF;IACpF,cAAc,CAAC,IAAI,MAAM,EAAE,CAAC;IAC5B,mFAAmF;IACnF,aAAa,CAAC,IAAI,MAAM,EAAE,CAAC;IAC3B,8BAA8B;IAC9B,WAAW,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,EAAE,CAAC;IAChD,4BAA4B;IAC5B,SAAS,CAAC,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;IACvD,gDAAgD;IAChD,YAAY,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,EAAE,CAAC;IAClD,kDAAkD;IAClD,YAAY,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,EAAE,CAAC;IAClD,4CAA4C;IAC5C,iBAAiB,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CACnE"}
package/dist/types.js CHANGED
@@ -5,5 +5,26 @@
5
5
  * They intentionally avoid coupling to shell commands, filesystems, processes,
6
6
  * sockets, or HTTP requests — those remain implementation details of MCP servers.
7
7
  */
8
- export {};
8
+ /**
9
+ * Map an Adaptive MCP static `risk` level onto core MCP `ToolAnnotations`.
10
+ *
11
+ * The MCP spec says clients MUST treat `ToolAnnotations` as untrusted unless
12
+ * from a trusted server, so this is advisory — but it rides the host's native,
13
+ * already-parsed risk signal (higher uptake than a custom `risk` field). The
14
+ * server-published tools-metadata resource keeps `risk` for the *learned/
15
+ * observed* dimension only (e.g. "observed flaky / costly in practice"), which
16
+ * core hints cannot express. See doubts.md §10/§11 (Strategy 2 of the hybrid).
17
+ */
18
+ export function riskToToolAnnotations(risk) {
19
+ switch (risk) {
20
+ case "high":
21
+ return { destructiveHint: true, openWorldHint: true };
22
+ case "medium":
23
+ return { idempotentHint: false, openWorldHint: true };
24
+ case "low":
25
+ return { readOnlyHint: true };
26
+ default:
27
+ return {};
28
+ }
29
+ }
9
30
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAmFH;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAgB;IACpD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,MAAM;YACT,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;QACxD,KAAK,QAAQ;YACX,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;QACxD,KAAK,KAAK;YACR,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;QAChC;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptivemcp/spec",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "Extension identifiers, event schemas, and shared types for Adaptive MCP.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,12 +17,12 @@
17
17
  "dist",
18
18
  "README.md"
19
19
  ],
20
- "scripts": {
21
- "build": "tsc -p tsconfig.json",
22
- "test": "vitest run --config ../../vitest.config.ts"
23
- },
24
20
  "devDependencies": {
25
21
  "typescript": "^5.6.0",
26
22
  "vitest": "^2.1.0"
23
+ },
24
+ "scripts": {
25
+ "build": "tsc -p tsconfig.json",
26
+ "test": "vitest run --config ../../vitest.config.ts"
27
27
  }
28
- }
28
+ }