@codespar/types 0.10.5 → 0.10.9

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/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./types.js";
2
2
  export * from "./guards.js";
3
+ export * from "./meta-tool-contract.js";
3
4
  //# 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,aAAa,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,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./types.js";
2
2
  export * from "./guards.js";
3
+ export * from "./meta-tool-contract.js";
3
4
  //# 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,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,162 @@
1
+ /**
2
+ * A field's required wire shape, expressed as a JSON-value kind. The kit
3
+ * uses these to assert wire-shape validity without importing a schema
4
+ * library: each kind maps to a `typeof`/`Array.isArray` check.
5
+ *
6
+ * `string-enum` additionally constrains the value to a closed set (see
7
+ * {@link FieldRule.values}).
8
+ */
9
+ export type FieldKind = "string" | "string-enum" | "number" | "boolean" | "object" | "array";
10
+ /** One field's contract within a wire shape. */
11
+ export interface FieldRule {
12
+ /** The field name on the wire object. */
13
+ name: string;
14
+ /** The required JSON-value kind. */
15
+ kind: FieldKind;
16
+ /** Whether the field must be present (and non-null). Defaults to true. */
17
+ required?: boolean;
18
+ /** Closed value set — required when `kind` is "string-enum". */
19
+ values?: readonly string[];
20
+ }
21
+ /**
22
+ * A named wire shape: the set of field rules an instance of the shape must
23
+ * satisfy. A conforming implementation MAY carry optional fields beyond
24
+ * these (subset-shape), but MUST carry every `required` field with the
25
+ * stated kind.
26
+ */
27
+ export interface WireShape {
28
+ /** The interface name in `types.ts`, e.g. "ShopSearchResult". */
29
+ name: string;
30
+ /** Field-level rules the result object must satisfy. */
31
+ fields: readonly FieldRule[];
32
+ }
33
+ /**
34
+ * One action a meta-tool exposes, with the input it is driven by and the
35
+ * result wire shape it returns. `terminal` marks an action whose result
36
+ * carries a terminal status (the state machine cannot advance past it).
37
+ */
38
+ export interface ActionRule {
39
+ /** The `action` discriminator value, e.g. "search". */
40
+ action: string;
41
+ /** A minimal valid input the kit can post to drive this action. The
42
+ * `action` field is added by the kit, so omit it here. */
43
+ sampleInput: Record<string, unknown>;
44
+ /** The result wire shape this action returns. */
45
+ result: WireShape;
46
+ /** The `status` field on the result that the state machine reads, when
47
+ * this action's result participates in the state machine. */
48
+ statusField?: string;
49
+ }
50
+ /**
51
+ * The action state machine for a meta-tool. `actions` is keyed by the
52
+ * `action` discriminator; `terminalStatuses` is the closed set of status
53
+ * values that end a flow (no further action advances past them); `start`
54
+ * names the action a flow begins at.
55
+ *
56
+ * Example (shop): start `search`, advance through `checkout` to
57
+ * `checkout_status`, whose `ready_for_payment` / `canceled` are terminal.
58
+ */
59
+ export interface ActionStateMachine {
60
+ /** The action a flow begins at. */
61
+ start: string;
62
+ /** Every action the tool exposes, keyed by the discriminator value. */
63
+ actions: readonly ActionRule[];
64
+ /** Status values that terminate a flow. */
65
+ terminalStatuses: readonly string[];
66
+ }
67
+ /**
68
+ * The error rules a meta-tool must honor. These are the two
69
+ * implementation-agnostic guarantees every contract'd meta-tool makes,
70
+ * regardless of which runtime serves it.
71
+ */
72
+ export interface ErrorRules {
73
+ /**
74
+ * The error a runtime returns when the tool has no registered
75
+ * implementation. The runtime returns a `ToolResult` with
76
+ * `success: false` and an `error` that starts with this string —
77
+ * never an HTTP error. The literal is "Tool not registered".
78
+ */
79
+ unregisteredErrorPrefix: string;
80
+ /**
81
+ * A malformed input the kit posts to assert the runtime returns a typed
82
+ * error envelope (`success: false`, non-empty `error`) rather than
83
+ * throwing across the wire or returning a success result. The `action`
84
+ * field is added by the kit when `malformedAction` is set.
85
+ */
86
+ malformedInput: Record<string, unknown>;
87
+ /** The action to drive the malformed input against, when the tool is
88
+ * action-based. Omit for tools with no action discriminator. */
89
+ malformedAction?: string;
90
+ }
91
+ /**
92
+ * The happy-path contract for a single-shot tool — one with no action
93
+ * discriminator (e.g. `codespar_discover`). Names a minimal valid input to
94
+ * drive the tool with and the result wire shape the response must satisfy,
95
+ * so the kit asserts the result shape rather than only that it succeeded.
96
+ */
97
+ export interface SingleShotRule {
98
+ /** A minimal valid input the kit posts to drive the happy path. */
99
+ sampleInput: Record<string, unknown>;
100
+ /** The result wire shape the successful response must satisfy. */
101
+ result: WireShape;
102
+ }
103
+ /**
104
+ * The full contract descriptor for one meta-tool — the machine-readable
105
+ * contract the conformance kit consumes. Names the tool, its wire types,
106
+ * its action state machine (or single-shot rule), and its error rules.
107
+ *
108
+ * Exactly one of `stateMachine` (action-discriminated tools) or
109
+ * `singleShot` (tools with no action) describes the happy path.
110
+ */
111
+ export interface MetaToolContractDescriptor {
112
+ /** The wire tool name, e.g. "codespar_shop". */
113
+ toolName: string;
114
+ /** The Args interface name in `types.ts`, e.g. "ShopArgs". */
115
+ argsType: string;
116
+ /** The Result interface (or union) name in `types.ts`, e.g.
117
+ * "ShopResult". */
118
+ resultType: string;
119
+ /** The action state machine. Present for action-discriminated tools. */
120
+ stateMachine?: ActionStateMachine;
121
+ /** The single-shot happy-path rule. Present for tools with no action
122
+ * discriminator (mutually exclusive with `stateMachine`). */
123
+ singleShot?: SingleShotRule;
124
+ /** The error rules every runtime serving this tool must honor. */
125
+ errors: ErrorRules;
126
+ }
127
+ /** The literal a runtime returns for a tool with no registered impl. */
128
+ export declare const TOOL_NOT_REGISTERED_PREFIX: "Tool not registered";
129
+ /**
130
+ * `codespar_discover` is a single-shot search (no action discriminator):
131
+ * it takes a `use_case` and returns a `DiscoverResult`. The contract is the
132
+ * result wire shape (DiscoverResult's real fields) plus the two error
133
+ * rules. `recommended` is intentionally not required: it is nullable by
134
+ * contract (`DiscoverToolMatch | null`), so a conforming result MAY return
135
+ * `recommended: null` — when present it must be an object.
136
+ */
137
+ export declare const DISCOVER_CONTRACT: MetaToolContractDescriptor;
138
+ /**
139
+ * `codespar_manage_connections` is action-discriminated over
140
+ * `list | status | initiate`, but the actions do not form a sequential
141
+ * flow — each is an independent read/initiate against a server's
142
+ * connection state, so there is no terminal-status state machine. The
143
+ * contract names the per-action result shape and the error rules.
144
+ */
145
+ export declare const MANAGE_CONNECTIONS_CONTRACT: MetaToolContractDescriptor;
146
+ /**
147
+ * `codespar_shop` is the canonical action state machine: `search` finds
148
+ * offers, `checkout` starts an async session, and `checkout_status` polls
149
+ * to a terminal `ready_for_payment` (carries a payable Pix) or `canceled`
150
+ * (carries an error). The `in_progress` status is non-terminal — the flow
151
+ * advances by re-polling `checkout_status`.
152
+ */
153
+ export declare const SHOP_CONTRACT: MetaToolContractDescriptor;
154
+ /** Every in-scope contract descriptor, keyed by wire tool name. */
155
+ export declare const META_TOOL_CONTRACTS: {
156
+ readonly codespar_discover: MetaToolContractDescriptor;
157
+ readonly codespar_manage_connections: MetaToolContractDescriptor;
158
+ readonly codespar_shop: MetaToolContractDescriptor;
159
+ };
160
+ /** The wire tool names that have a published contract descriptor. */
161
+ export type ContractedToolName = keyof typeof META_TOOL_CONTRACTS;
162
+ //# sourceMappingURL=meta-tool-contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta-tool-contract.d.ts","sourceRoot":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C;CAC1B;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,mEAAmE;IACnE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,kEAAkE;IAClE,MAAM,EAAE,SAAS,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,0BAA0B;IACzC,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,8DAA8D;IAC9D,QAAQ,EAAE,MAAM,CAAC;IACjB;wBACoB;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,wEAAwE;IACxE,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC;kEAC8D;IAC9D,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,kEAAkE;IAClE,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,wEAAwE;AACxE,eAAO,MAAM,0BAA0B,EAAG,qBAA8B,CAAC;AAIzE;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,EAAE,0BA2B/B,CAAC;AAIF;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,EAAE,0BA2DzC,CAAC;AAIF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,EAAE,0BA2D3B,CAAC;AAEF,mEAAmE;AACnE,eAAO,MAAM,mBAAmB;;;;CAItB,CAAC;AAEX,qEAAqE;AACrE,MAAM,MAAM,kBAAkB,GAAG,MAAM,OAAO,mBAAmB,CAAC"}
@@ -0,0 +1,196 @@
1
+ /* ── Meta-tool contract descriptor ───────────────────────────────
2
+ *
3
+ * A machine-readable description of a single meta-tool's contract: the
4
+ * names of its wire types, its action state machine, and its error rules.
5
+ * The conformance kit (`@codespar/types/testing`) consumes a descriptor and
6
+ * asserts that whatever implementation is registered at a live backend
7
+ * honors it — so the descriptor is the single source of truth for "what it
8
+ * means to conform", and both the OSS runtime and a managed backend prove
9
+ * parity by passing the same descriptor-driven suite.
10
+ *
11
+ * Descriptors are data, not code paths: they reference wire shapes by name
12
+ * (the interfaces authored in `types.ts`) rather than carrying validators,
13
+ * so they stay portable across language ports and serialize cleanly.
14
+ * ─────────────────────────────────────────────────────────────── */
15
+ /** The literal a runtime returns for a tool with no registered impl. */
16
+ export const TOOL_NOT_REGISTERED_PREFIX = "Tool not registered";
17
+ /* ── codespar_discover ───────────────────────────────────────── */
18
+ /**
19
+ * `codespar_discover` is a single-shot search (no action discriminator):
20
+ * it takes a `use_case` and returns a `DiscoverResult`. The contract is the
21
+ * result wire shape (DiscoverResult's real fields) plus the two error
22
+ * rules. `recommended` is intentionally not required: it is nullable by
23
+ * contract (`DiscoverToolMatch | null`), so a conforming result MAY return
24
+ * `recommended: null` — when present it must be an object.
25
+ */
26
+ export const DISCOVER_CONTRACT = {
27
+ toolName: "codespar_discover",
28
+ argsType: "DiscoverOptions",
29
+ resultType: "DiscoverResult",
30
+ singleShot: {
31
+ sampleInput: { use_case: "test conformance probe" },
32
+ result: {
33
+ name: "DiscoverResult",
34
+ fields: [
35
+ { name: "use_case", kind: "string" },
36
+ {
37
+ name: "search_strategy",
38
+ kind: "string-enum",
39
+ values: ["embedding", "trigram", "empty"],
40
+ },
41
+ { name: "recommended", kind: "object", required: false },
42
+ { name: "related", kind: "array" },
43
+ { name: "next_steps", kind: "array" },
44
+ ],
45
+ },
46
+ },
47
+ errors: {
48
+ unregisteredErrorPrefix: TOOL_NOT_REGISTERED_PREFIX,
49
+ // A discover call with no use_case is malformed — the tool cannot
50
+ // search for nothing.
51
+ malformedInput: {},
52
+ },
53
+ };
54
+ /* ── codespar_manage_connections ─────────────────────────────── */
55
+ /**
56
+ * `codespar_manage_connections` is action-discriminated over
57
+ * `list | status | initiate`, but the actions do not form a sequential
58
+ * flow — each is an independent read/initiate against a server's
59
+ * connection state, so there is no terminal-status state machine. The
60
+ * contract names the per-action result shape and the error rules.
61
+ */
62
+ export const MANAGE_CONNECTIONS_CONTRACT = {
63
+ toolName: "codespar_manage_connections",
64
+ argsType: "ConnectionWizardOptions",
65
+ resultType: "ConnectionWizardResult",
66
+ stateMachine: {
67
+ start: "list",
68
+ actions: [
69
+ {
70
+ action: "list",
71
+ sampleInput: {},
72
+ result: {
73
+ name: "ConnectionWizardResult",
74
+ fields: [
75
+ { name: "action", kind: "string-enum", values: ["list"] },
76
+ { name: "connections", kind: "array" },
77
+ ],
78
+ },
79
+ },
80
+ {
81
+ action: "status",
82
+ sampleInput: { server_id: "asaas" },
83
+ result: {
84
+ name: "ConnectionWizardResult",
85
+ fields: [
86
+ { name: "action", kind: "string-enum", values: ["status"] },
87
+ { name: "connections", kind: "array" },
88
+ // `status` is `ConnectionStatusRow | null` — an object when a
89
+ // row is found, null when the server is unknown. Validated
90
+ // only when present.
91
+ { name: "status", kind: "object", required: false },
92
+ ],
93
+ },
94
+ },
95
+ {
96
+ action: "initiate",
97
+ sampleInput: { server_id: "asaas" },
98
+ result: {
99
+ name: "ConnectionWizardResult",
100
+ fields: [
101
+ { name: "action", kind: "string-enum", values: ["initiate"] },
102
+ { name: "connections", kind: "array" },
103
+ // `initiate` is `ConnectionWizardInstructions | null` — an
104
+ // object when the wizard is issued, null otherwise. Validated
105
+ // only when present.
106
+ { name: "initiate", kind: "object", required: false },
107
+ ],
108
+ },
109
+ },
110
+ ],
111
+ // No flow terminus — each action is independent.
112
+ terminalStatuses: [],
113
+ },
114
+ errors: {
115
+ unregisteredErrorPrefix: TOOL_NOT_REGISTERED_PREFIX,
116
+ // An unknown action is malformed — the closed set is
117
+ // list | status | initiate.
118
+ malformedInput: { action: "not_a_real_action" },
119
+ malformedAction: "not_a_real_action",
120
+ },
121
+ };
122
+ /* ── codespar_shop ───────────────────────────────────────────── */
123
+ /**
124
+ * `codespar_shop` is the canonical action state machine: `search` finds
125
+ * offers, `checkout` starts an async session, and `checkout_status` polls
126
+ * to a terminal `ready_for_payment` (carries a payable Pix) or `canceled`
127
+ * (carries an error). The `in_progress` status is non-terminal — the flow
128
+ * advances by re-polling `checkout_status`.
129
+ */
130
+ export const SHOP_CONTRACT = {
131
+ toolName: "codespar_shop",
132
+ argsType: "ShopArgs",
133
+ resultType: "ShopResult",
134
+ stateMachine: {
135
+ start: "search",
136
+ actions: [
137
+ {
138
+ action: "search",
139
+ sampleInput: { query: "cat food" },
140
+ result: {
141
+ name: "ShopSearchResult",
142
+ fields: [
143
+ { name: "rail", kind: "string" },
144
+ { name: "products", kind: "array" },
145
+ ],
146
+ },
147
+ },
148
+ {
149
+ action: "checkout",
150
+ sampleInput: { url: "https://example.test/p/sku_1" },
151
+ result: {
152
+ name: "ShopCheckoutResult",
153
+ fields: [
154
+ { name: "checkout_session_id", kind: "string" },
155
+ {
156
+ name: "status",
157
+ kind: "string-enum",
158
+ values: ["in_progress"],
159
+ },
160
+ ],
161
+ },
162
+ statusField: "status",
163
+ },
164
+ {
165
+ action: "checkout_status",
166
+ sampleInput: { checkout_session_id: "cks_sample" },
167
+ result: {
168
+ name: "ShopStatusResult",
169
+ fields: [
170
+ { name: "checkout_session_id", kind: "string" },
171
+ {
172
+ name: "status",
173
+ kind: "string-enum",
174
+ values: ["in_progress", "ready_for_payment", "canceled"],
175
+ },
176
+ ],
177
+ },
178
+ statusField: "status",
179
+ },
180
+ ],
181
+ terminalStatuses: ["ready_for_payment", "canceled"],
182
+ },
183
+ errors: {
184
+ unregisteredErrorPrefix: TOOL_NOT_REGISTERED_PREFIX,
185
+ // A search with no query is malformed — there is nothing to search for.
186
+ malformedInput: {},
187
+ malformedAction: "search",
188
+ },
189
+ };
190
+ /** Every in-scope contract descriptor, keyed by wire tool name. */
191
+ export const META_TOOL_CONTRACTS = {
192
+ codespar_discover: DISCOVER_CONTRACT,
193
+ codespar_manage_connections: MANAGE_CONNECTIONS_CONTRACT,
194
+ codespar_shop: SHOP_CONTRACT,
195
+ };
196
+ //# sourceMappingURL=meta-tool-contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta-tool-contract.js","sourceRoot":"","sources":["../src/meta-tool-contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;q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AAE,mBAAmB,EAAE,UAAU,CAAC;yBACzD;qBACF;iBACF;gBACD,WAAW,EAAE,QAAQ;aACtB;SACF;QACD,gBAAgB,EAAE,CAAC,mBAAmB,EAAE,UAAU,CAAC;KACpD;IACD,MAAM,EAAE;QACN,uBAAuB,EAAE,0BAA0B;QACnD,wEAAwE;QACxE,cAAc,EAAE,EAAE;QAClB,eAAe,EAAE,QAAQ;KAC1B;CACF,CAAC;AAEF,mEAAmE;AACnE,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,iBAAiB,EAAE,iBAAiB;IACpC,2BAA2B,EAAE,2BAA2B;IACxD,aAAa,EAAE,aAAa;CACpB,CAAC"}
@@ -0,0 +1,101 @@
1
+ import type { ToolResult } from "../index.js";
2
+ import { type ContractedToolName, type FieldRule, type MetaToolContractDescriptor, type WireShape } from "../meta-tool-contract.js";
3
+ /** Options for {@link runMetaToolConformanceSuite}. */
4
+ export interface ConformanceSuiteOptions {
5
+ /** Which contract'd meta-tool to assert conformance for. */
6
+ tool: ContractedToolName;
7
+ /**
8
+ * Server ids to post when opening the session. Defaults to `[]`, matching
9
+ * a self-hosted OSS runtime that accepts an empty server list. A managed
10
+ * backend requires at least one server, so a managed-side consumer MUST
11
+ * pass `[<seeded-server-id>]` here — see {@link runMetaToolConformanceSuite}.
12
+ */
13
+ servers?: string[];
14
+ }
15
+ /** A single conformance violation: which check failed and why. */
16
+ export interface Violation {
17
+ /** A stable code for the kind of violation. */
18
+ code: "wire-shape" | "action-state" | "error-unregistered" | "error-malformed";
19
+ /** Human-readable detail naming the specific field/rule that failed. */
20
+ detail: string;
21
+ }
22
+ /** True when `value` matches the JSON-value kind `rule.kind` demands. */
23
+ export declare function fieldMatches(rule: FieldRule, value: unknown): boolean;
24
+ /**
25
+ * Check a wire object against a {@link WireShape}. Returns the violations
26
+ * found (empty array = conforms). A field is checked when it is `required`
27
+ * (the default) or present; absent optional fields are skipped.
28
+ */
29
+ export declare function checkWireShape(shape: WireShape, obj: unknown): Violation[];
30
+ /**
31
+ * Verify a successful action result: the `ToolResult` reports success and
32
+ * its `data` conforms to the action's result wire shape. Also enforces that
33
+ * a `statusField`, when declared, holds a value the state machine knows —
34
+ * a terminal status or `in_progress`/non-terminal status drawn from the
35
+ * declared enum (the enum check is part of the wire shape).
36
+ */
37
+ export declare function checkActionResult(descriptor: MetaToolContractDescriptor, action: string, result: ToolResult): Violation[];
38
+ /**
39
+ * Verify a single-shot tool's happy-path result: the `ToolResult` reports
40
+ * success and its `data` conforms to the descriptor's `singleShot` result
41
+ * wire shape. This gives a no-state-machine tool (e.g. `codespar_discover`)
42
+ * the same wire-shape teeth the action path has — a wrong-shaped result
43
+ * fails with a precise `[wire-shape]` violation rather than passing on
44
+ * `success: true` alone.
45
+ */
46
+ export declare function checkSingleShotResult(descriptor: MetaToolContractDescriptor, result: ToolResult): Violation[];
47
+ /**
48
+ * Verify the unregistered-tool error rule: a runtime with no registered
49
+ * implementation returns `success: false` with an `error` that starts with
50
+ * the descriptor's `unregisteredErrorPrefix` (never an HTTP-level error and
51
+ * never a success result).
52
+ */
53
+ export declare function checkUnregisteredError(descriptor: MetaToolContractDescriptor, result: ToolResult): Violation[];
54
+ /**
55
+ * Verify the malformed-input error rule: a malformed input yields a typed
56
+ * error envelope (`success: false` with a non-empty `error`) rather than a
57
+ * success result. The error message itself is implementation-defined; only
58
+ * the shape of the failure is contracted.
59
+ */
60
+ export declare function checkMalformedError(descriptor: MetaToolContractDescriptor, result: ToolResult): Violation[];
61
+ /**
62
+ * Register the meta-tool conformance test suite against a live backend.
63
+ *
64
+ * Given a base URL and an `apiKey` for a backend that has an implementation
65
+ * of `opts.tool` registered, drives `execute(toolName, ...)` and asserts the
66
+ * tool's contract descriptor: every action's result wire shape, the action
67
+ * state machine (the declared status enum, terminal vs non-terminal), and
68
+ * the two error rules (unregistered → "Tool not registered"; malformed
69
+ * input → typed error envelope).
70
+ *
71
+ * The suite is implementation-agnostic — it tests whatever is registered at
72
+ * `baseUrl`. It validates the baseUrl before issuing any request: only
73
+ * https:// URLs and localhost are accepted, so a misconfigured CI
74
+ * environment fails early rather than leaking the apiKey to an arbitrary
75
+ * host.
76
+ *
77
+ * The unregistered-error leg uses a deliberately unregistered tool name
78
+ * (the contract'd tool name with a `__unregistered_probe` suffix) so it
79
+ * asserts the runtime's fall-through behavior without depending on any
80
+ * tool being absent.
81
+ *
82
+ * Backend prerequisites:
83
+ * - **Route prefix.** The kit drives `POST /v1/sessions`,
84
+ * `POST /v1/sessions/:id/execute`, and `DELETE /v1/sessions/:id` — the
85
+ * backend (or test harness) must mount the session routes under the `/v1`
86
+ * prefix.
87
+ * - **`servers` option.** `opts.servers` defaults to `[]`. A self-hosted
88
+ * OSS runtime accepts an empty server list on session create, but a
89
+ * managed backend requires at least one server — so a managed-side
90
+ * consumer MUST pass `opts.servers: [<seeded-server-id>]` (a server whose
91
+ * meta-tool implementation is registered), or session create will be
92
+ * rejected before any conformance case runs.
93
+ *
94
+ * @param baseUrl - API base URL (e.g. "https://your-runtime.example" or "http://localhost:3000")
95
+ * @param apiKey - Bearer token for session creation
96
+ * @param opts - The tool to assert and optional servers list (see {@link ConformanceSuiteOptions})
97
+ */
98
+ export declare function runMetaToolConformanceSuite(baseUrl: string, apiKey: string, opts: ConformanceSuiteOptions): void;
99
+ /** Join violations into a single message for an assertion failure. */
100
+ export declare function formatViolations(violations: Violation[]): string;
101
+ //# sourceMappingURL=conformance-kit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conformance-kit.d.ts","sourceRoot":"","sources":["../../src/testing/conformance-kit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACd,KAAK,0BAA0B,EAC/B,KAAK,SAAS,EACf,MAAM,0BAA0B,CAAC;AAElC,uDAAuD;AACvD,MAAM,WAAW,uBAAuB;IACtC,4DAA4D;IAC5D,IAAI,EA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