@elicitkit/server 0.1.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,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 the Elicitkit authors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/dist/bin.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
package/dist/bin.js ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { createElicitServer } from "./server.js";
4
+ /**
5
+ * stdio entrypoint — the universal MCP transport (Claude Code, Codex CLI,
6
+ * Cursor, …). HTTP/SDK and CLI surfaces land in Task #6.
7
+ */
8
+ async function main() {
9
+ const server = createElicitServer();
10
+ const transport = new StdioServerTransport();
11
+ await server.connect(transport);
12
+ // stderr only: stdout is the MCP wire.
13
+ process.stderr.write("elicitkit MCP server ready (stdio)\n");
14
+ }
15
+ main().catch((err) => {
16
+ process.stderr.write(`elicitkit fatal: ${String(err)}\n`);
17
+ process.exit(1);
18
+ });
19
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD;;;GAGG;AACH,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,kBAAkB,EAAE,CAAC;IACpC,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,uCAAuC;IACvC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;AAC/D,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC1D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { createElicitServer } from "./server.js";
2
+ export type { ElicitServerOptions } from "./server.js";
3
+ export { negotiateTier, setFloor, TIER_ORDER } from "./tiers.js";
4
+ export type { TierChoice } from "./tiers.js";
5
+ export { renderPanel } from "./render.js";
6
+ export { openRound, peekRound, closeRound } from "./submit.js";
7
+ export type { SubmitResult } from "./submit.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACjE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC/D,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { createElicitServer } from "./server.js";
2
+ export { negotiateTier, setFloor, TIER_ORDER } from "./tiers.js";
3
+ export { renderPanel } from "./render.js";
4
+ export { openRound, peekRound, closeRound } from "./submit.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { AskSet, Tier } from "@elicitkit/core";
2
+ import { type RenderedPanel } from "@elicitkit/renderers";
3
+ /**
4
+ * Dispatch the panel tiers (`apps` / `url` / `tui`). The `elicitation` tier is
5
+ * NOT here: it resolves inline against the host's native elicitation primitive
6
+ * and is driven directly by the server (see server.ts), with no panel or
7
+ * `elicit_submit` round-trip.
8
+ */
9
+ export declare function renderPanel(set: AskSet, tier: Tier, token: string): Promise<RenderedPanel>;
10
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,sBAAsB,CAAC;AAE9B;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,aAAa,CAAC,CAKxB"}
package/dist/render.js ADDED
@@ -0,0 +1,16 @@
1
+ import { renderApps, renderUrl, renderTui, } from "@elicitkit/renderers";
2
+ /**
3
+ * Dispatch the panel tiers (`apps` / `url` / `tui`). The `elicitation` tier is
4
+ * NOT here: it resolves inline against the host's native elicitation primitive
5
+ * and is driven directly by the server (see server.ts), with no panel or
6
+ * `elicit_submit` round-trip.
7
+ */
8
+ export async function renderPanel(set, tier, token) {
9
+ if (tier === "apps")
10
+ return renderApps(set, token);
11
+ if (tier === "url")
12
+ return renderUrl(set, token);
13
+ // "tui" — and the safe sink for anything unexpected.
14
+ return renderTui(set, token);
15
+ }
16
+ //# sourceMappingURL=render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,SAAS,EACT,SAAS,GAEV,MAAM,sBAAsB,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,GAAW,EACX,IAAU,EACV,KAAa;IAEb,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACnD,IAAI,IAAI,KAAK,KAAK;QAAE,OAAO,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACjD,qDAAqD;IACrD,OAAO,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { type Tier } from "@elicitkit/core";
3
+ export interface ElicitServerOptions {
4
+ name?: string;
5
+ version?: string;
6
+ /**
7
+ * Hosts known to render the `apps`/`url` UI panels. No standard MCP
8
+ * capability advertises HTML rendering, so the server will NOT serve a
9
+ * UI tier to a plain terminal client just because the agent asked for it
10
+ * (that produces a dead "fill out the panel" message with no panel).
11
+ * Opt in here, or via ELICITKIT_UI_TIERS=apps,url, for a host you know
12
+ * supports mcp-ui / MCP Apps.
13
+ */
14
+ uiTiers?: Tier[];
15
+ }
16
+ /**
17
+ * Build the Elicitkit MCP reference server.
18
+ *
19
+ * - `elicit` — the agent submits an AskSet; the server validates it
20
+ * against the v0.1 schema and negotiates the render tier
21
+ * against the host's capabilities. EVERY tier returns
22
+ * fast: panel tiers (apps / url / tui) return a
23
+ * rendering plus a round token; the elicitation tier
24
+ * issues the FIRST native elicitInput inline, awaits
25
+ * ONE user answer, and returns `pending: true` so the
26
+ * per-call MCP timeout is never the gating factor.
27
+ * - `elicit_next` — NEW. Drives the next elicitInput for an open
28
+ * elicitation-tier round. Returns `pending:true`
29
+ * until the last ask is answered, then `pending:false`
30
+ * with the validated answers.
31
+ * - `elicit_submit` — the panel (or the agent, in `tui`/`url`) returns the
32
+ * user's answers; validated per-type, handed back clean.
33
+ *
34
+ * The spec is the product; this server is its reference implementation.
35
+ */
36
+ export declare function createElicitServer(opts?: ElicitServerOptions): McpServer;
37
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGpE,OAAO,EAA+B,KAAK,IAAI,EAAyB,MAAM,iBAAiB,CAAC;AAqBhG,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,GAAE,mBAAwB,GAAG,SAAS,CAmV5E"}
package/dist/server.js ADDED
@@ -0,0 +1,442 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { z } from "zod";
3
+ import { validateAskSet } from "@elicitkit/core";
4
+ import { buildPanelHtml, compileAskToInputs, decodeAskAnswer, } from "@elicitkit/renderers";
5
+ import { negotiateTier, slowAskRoute, TIER_ORDER } from "./tiers.js";
6
+ import { renderPanel } from "./render.js";
7
+ import { appendCollected, closeCollected, closeRound, openRound, peekRoundState, } from "./submit.js";
8
+ const TIER_VALUES = TIER_ORDER;
9
+ /**
10
+ * Build the Elicitkit MCP reference server.
11
+ *
12
+ * - `elicit` — the agent submits an AskSet; the server validates it
13
+ * against the v0.1 schema and negotiates the render tier
14
+ * against the host's capabilities. EVERY tier returns
15
+ * fast: panel tiers (apps / url / tui) return a
16
+ * rendering plus a round token; the elicitation tier
17
+ * issues the FIRST native elicitInput inline, awaits
18
+ * ONE user answer, and returns `pending: true` so the
19
+ * per-call MCP timeout is never the gating factor.
20
+ * - `elicit_next` — NEW. Drives the next elicitInput for an open
21
+ * elicitation-tier round. Returns `pending:true`
22
+ * until the last ask is answered, then `pending:false`
23
+ * with the validated answers.
24
+ * - `elicit_submit` — the panel (or the agent, in `tui`/`url`) returns the
25
+ * user's answers; validated per-type, handed back clean.
26
+ *
27
+ * The spec is the product; this server is its reference implementation.
28
+ */
29
+ export function createElicitServer(opts = {}) {
30
+ const server = new McpServer({
31
+ name: opts.name ?? "elicitkit",
32
+ version: opts.version ?? "0.1.0",
33
+ });
34
+ // Bridge the renderers' narrow ElicitFn to the SDK's elicitation primitive.
35
+ const elicit = (params) => server.server.elicitInput({
36
+ mode: "form",
37
+ message: params.message,
38
+ requestedSchema: params.requestedSchema,
39
+ });
40
+ server.registerTool("elicit", {
41
+ title: "Elicit structured input",
42
+ description: "Render an Elicitkit AskSet to the user and obtain typed answers. " +
43
+ "Returns FAST: panel tiers return a token + rendering; the " +
44
+ "elicitation tier issues ONE native prompt inline and returns " +
45
+ "`pending:true` so the per-call MCP timeout is never blown by " +
46
+ "human-think time. If `pending:true` and tier === 'elicitation', " +
47
+ "call `elicit_next(token)` until `pending:false`; otherwise " +
48
+ "collect answers per the rendering and call " +
49
+ "`elicit_submit(token, answers)`. Never fabricate answers.",
50
+ inputSchema: {
51
+ askSet: z
52
+ .unknown()
53
+ .describe("A v0.1 Elicitkit AskSet: { specVersion, asks: [...] }"),
54
+ supportedTiers: z
55
+ .array(z.enum(TIER_VALUES))
56
+ .optional()
57
+ .describe("Render tiers this host supports, richest first. Omit if unknown " +
58
+ "(the server then uses the universal 'tui' text tier)."),
59
+ },
60
+ }, async ({ askSet, supportedTiers }) => {
61
+ // Some MCP clients serialize complex object args as a JSON string.
62
+ // Coerce back to an object before schema validation.
63
+ if (typeof askSet === "string") {
64
+ try {
65
+ askSet = JSON.parse(askSet);
66
+ }
67
+ catch {
68
+ /* leave as-is; validateAskSet will reject it */
69
+ }
70
+ }
71
+ const v = validateAskSet(askSet);
72
+ if (!v.ok) {
73
+ return {
74
+ isError: true,
75
+ content: [
76
+ {
77
+ type: "text",
78
+ text: "AskSet failed v0.1 schema validation:\n- " +
79
+ v.errors.join("\n- "),
80
+ },
81
+ ],
82
+ };
83
+ }
84
+ const set = askSet;
85
+ // The connected MCP CLIENT is the authority on what can render — NOT
86
+ // the agent (an LLM guessing "apps" in a terminal is how you get a
87
+ // dead panel). Derive what the host can actually do:
88
+ const caps = server.server.getClientCapabilities();
89
+ const clientElicitation = !!caps?.elicitation;
90
+ const exp = (caps?.experimental ?? {});
91
+ const uiOptIn = opts.uiTiers ??
92
+ process.env.ELICITKIT_UI_TIERS?.split(",").map((s) => s.trim()).filter(Boolean);
93
+ // Positive evidence only: an operator opt-in, or the client itself
94
+ // advertising a UI extension. Never the agent's say-so.
95
+ const uiOk = (uiOptIn && uiOptIn.length > 0) ||
96
+ !!(exp["mcp-ui"] || exp["apps"] || exp["ui"] || exp["io.modelcontextprotocol/apps"]);
97
+ const hostTiers = new Set(["tui"]);
98
+ if (clientElicitation)
99
+ hostTiers.add("elicitation");
100
+ if (uiOk) {
101
+ hostTiers.add("apps");
102
+ hostTiers.add("url");
103
+ }
104
+ // Slow-ask auto-router: if any ask in the set is likely-slow on the
105
+ // per-prompt elicitation primitive (long text, big code diff, large
106
+ // rank), drop `elicitation` from the candidates so we degrade to a
107
+ // panel tier (apps/url) where the user can take as long as they
108
+ // want, or to tui where the agent collects the answers in chat.
109
+ const slow = slowAskRoute(set);
110
+ const candidates = new Set(hostTiers);
111
+ if (slow.routed)
112
+ candidates.delete("elicitation");
113
+ // The agent's supportedTiers may only NARROW within the host's real
114
+ // set — it can't grant a tier the host can't do. If its narrowing
115
+ // leaves nothing, ignore it and trust the host.
116
+ let effective = [...candidates];
117
+ const requested = supportedTiers;
118
+ if (requested && requested.length > 0) {
119
+ const r = new Set(requested);
120
+ const narrowed = effective.filter((t) => r.has(t));
121
+ if (narrowed.length > 0)
122
+ effective = narrowed;
123
+ }
124
+ // If filtering / routing emptied the set, fall back to the universal
125
+ // sink so we never hard-fail at negotiation.
126
+ if (effective.length === 0)
127
+ effective = ["tui"];
128
+ const { tier, negotiated } = negotiateTier(set, effective);
129
+ const baseMeta = {
130
+ renderedTier: tier,
131
+ tierNegotiated: negotiated,
132
+ hostTiers: [...hostTiers],
133
+ ...(slow.routed
134
+ ? { routedAwayFromElicitation: true, routeReason: slow.reason }
135
+ : {}),
136
+ };
137
+ // ── elicitation tier: open round, issue FIRST elicitInput inline,
138
+ // await ONE answer, return pending:true. The rest of the round is
139
+ // driven by elicit_next so each tool call is bounded by one user
140
+ // answer (a Codex-realistic 14-question set never trips a per-call
141
+ // MCP timeout).
142
+ if (tier === "elicitation") {
143
+ const token = openRound(set, { tier: "elicitation" });
144
+ const out = await driveOneStep(token, elicit);
145
+ if (!out.ok) {
146
+ return {
147
+ isError: true,
148
+ content: [{ type: "text", text: out.error }],
149
+ };
150
+ }
151
+ return out.result(token, baseMeta);
152
+ }
153
+ // ── panel tiers (tui/url/apps): return panel ref + token IMMEDIATELY,
154
+ // no await. The user fills the panel; the agent calls elicit_submit.
155
+ const token = openRound(set, {
156
+ tier,
157
+ ...(slow.routed ? { routedAwayFromElicitation: { reason: slow.reason ?? "" } } : {}),
158
+ });
159
+ const out = await renderPanel(set, tier, token);
160
+ const content = [
161
+ { type: "text", text: out.text },
162
+ ];
163
+ if (out.ui) {
164
+ content.push(out.ui);
165
+ }
166
+ return {
167
+ content,
168
+ structuredContent: {
169
+ pending: true,
170
+ token,
171
+ tier,
172
+ ...(tier === "url" || tier === "apps"
173
+ ? { panelUri: out.ui?.resource.uri }
174
+ : {}),
175
+ },
176
+ _meta: {
177
+ elicitkit: {
178
+ token,
179
+ pending: true,
180
+ ...baseMeta,
181
+ renderedTier: out.tier,
182
+ requestedTier: tier,
183
+ ...(out.ui ? {} : {}),
184
+ },
185
+ ...(out.ui ? { ui: { resourceUri: out.ui.resource.uri } } : {}),
186
+ },
187
+ };
188
+ });
189
+ server.registerTool("elicit_next", {
190
+ title: "Advance an open elicitation-tier round",
191
+ description: "Drive the next native elicitInput for an open elicitation-tier " +
192
+ "round. Returns `pending:true` (more asks to come) or " +
193
+ "`pending:false` with the validated `answers`. Only valid for the " +
194
+ "elicitation tier — panel tiers (tui/url/apps) complete via " +
195
+ "elicit_submit instead.",
196
+ inputSchema: {
197
+ token: z
198
+ .string()
199
+ .describe("The round token from a prior elicit / elicit_next result."),
200
+ },
201
+ }, async ({ token }) => {
202
+ const st = peekRoundState(token);
203
+ if (!st) {
204
+ return {
205
+ isError: true,
206
+ content: [{ type: "text", text: "unknown or expired token" }],
207
+ };
208
+ }
209
+ if (st.tier !== "elicitation") {
210
+ return {
211
+ isError: true,
212
+ content: [
213
+ {
214
+ type: "text",
215
+ text: `round token is for tier ${st.tier}; use elicit_submit instead`,
216
+ },
217
+ ],
218
+ };
219
+ }
220
+ if (st.index >= st.set.asks.length) {
221
+ return {
222
+ isError: true,
223
+ content: [
224
+ { type: "text", text: "round already complete; no more asks" },
225
+ ],
226
+ };
227
+ }
228
+ const out = await driveOneStep(token, elicit);
229
+ if (!out.ok) {
230
+ return { isError: true, content: [{ type: "text", text: out.error }] };
231
+ }
232
+ return out.result(token, {
233
+ renderedTier: "elicitation",
234
+ hostTiers: [],
235
+ });
236
+ });
237
+ server.registerTool("elicit_submit", {
238
+ title: "Submit elicited answers",
239
+ description: "Return the user's answers for an open elicitation round. Called by " +
240
+ "the interactive panel; in the tui/url tiers the agent calls it with " +
241
+ "answers the user provided (e.g. a payload pasted back from the url " +
242
+ "panel — forward it verbatim).",
243
+ inputSchema: {
244
+ token: z.string().describe("The round token from the elicit result _meta."),
245
+ answers: z
246
+ .array(z.unknown())
247
+ .describe("One Answer per ask: " +
248
+ '{ id, type, status: "answered"|"declined"|"deferred", value? }'),
249
+ },
250
+ }, async ({ token, answers }) => {
251
+ const r = closeRound(token, answers);
252
+ if (!r.ok) {
253
+ return {
254
+ isError: true,
255
+ content: [
256
+ {
257
+ type: "text",
258
+ text: "Answers rejected — re-ask (SPEC.md §5):\n- " +
259
+ r.errors.join("\n- "),
260
+ },
261
+ ],
262
+ };
263
+ }
264
+ return {
265
+ content: [{ type: "text", text: JSON.stringify(r.answers, null, 2) }],
266
+ structuredContent: { answers: r.answers, pending: false },
267
+ _meta: { elicitkit: { token, ok: true, pending: false } },
268
+ };
269
+ });
270
+ server.registerTool("elicit_render", {
271
+ title: "Render an AskSet to a standalone HTML panel",
272
+ description: "Return a self-contained HTML panel for an AskSet as a one-shot " +
273
+ "deliverable. Use when the user wants HTML / a file / a " +
274
+ "questionnaire / a shareable panel. This is NOT an interactive " +
275
+ "round: save the returned HTML to a .html file, give the user the " +
276
+ "path, and STOP — do not also call `elicit`, do not wait for or " +
277
+ "prompt for answers, do not treat a round as pending. The panel can " +
278
+ "still produce a copy-paste payload, but feeding it to " +
279
+ "elicit_submit is OPTIONAL and only if the user later chooses to " +
280
+ "return one. `elicit` is the interactive ask; this is just the file.",
281
+ inputSchema: {
282
+ askSet: z
283
+ .unknown()
284
+ .describe("A v0.1 Elicitkit AskSet: { specVersion, asks: [...] }"),
285
+ },
286
+ }, async ({ askSet }) => {
287
+ if (typeof askSet === "string") {
288
+ try {
289
+ askSet = JSON.parse(askSet);
290
+ }
291
+ catch {
292
+ /* leave as-is; validateAskSet will reject it */
293
+ }
294
+ }
295
+ const v = validateAskSet(askSet);
296
+ if (!v.ok) {
297
+ return {
298
+ isError: true,
299
+ content: [
300
+ { type: "text", text: "AskSet failed v0.1 schema validation:\n- " + v.errors.join("\n- ") },
301
+ ],
302
+ };
303
+ }
304
+ const set = askSet;
305
+ // A real round token so the panel's copy-paste payload validates
306
+ // through elicit_submit just like any other round.
307
+ const token = openRound(set, { tier: "url" });
308
+ const html = buildPanelHtml(set, token, "url");
309
+ return {
310
+ content: [
311
+ {
312
+ type: "text",
313
+ text: `Deliverable: save the following to a .html file, give the ` +
314
+ `user the path, and stop — this is not an interactive round, ` +
315
+ `do not wait for answers. (If the user later returns the ` +
316
+ `panel's copy-paste JSON, it may optionally be forwarded to ` +
317
+ `elicit_submit; the round token is embedded.)\n\n` +
318
+ html,
319
+ },
320
+ ],
321
+ _meta: { elicitkit: { token, rendered: "url", bytes: html.length } },
322
+ };
323
+ });
324
+ return server;
325
+ }
326
+ async function driveOneStep(token, elicit) {
327
+ const st = peekRoundState(token);
328
+ if (!st)
329
+ return { ok: false, error: "unknown or expired token" };
330
+ const stateAny = st;
331
+ if (!stateAny.subResponses)
332
+ stateAny.subResponses = [];
333
+ const askIdx = stateAny.index;
334
+ const ask = stateAny.set.asks[askIdx];
335
+ if (!ask) {
336
+ return { ok: false, error: "round already complete; no more asks" };
337
+ }
338
+ const inputs = compileAskToInputs(ask);
339
+ const subStep = stateAny.subResponses.length;
340
+ const params = inputs[subStep];
341
+ if (!params) {
342
+ return { ok: false, error: "no elicitInput compiled for ask" };
343
+ }
344
+ const r = await elicit(params);
345
+ stateAny.subResponses.push(r);
346
+ // For ask_code_diff, a non-accept on any hunk ends the ask. For other
347
+ // asks there's only one input anyway.
348
+ const moreSubSteps = inputs.length > stateAny.subResponses.length;
349
+ const continueAsk = moreSubSteps && (ask.type !== "ask_code_diff" || r.action === "accept");
350
+ if (continueAsk) {
351
+ // Still inside the current ask. Return pending:true with progress.
352
+ return {
353
+ ok: true,
354
+ result: (tok, extra) => ({
355
+ content: [
356
+ {
357
+ type: "text",
358
+ text: JSON.stringify({ pending: true, token: tok, completed: stateAny.index, total: stateAny.set.asks.length }, null, 2),
359
+ },
360
+ ],
361
+ structuredContent: {
362
+ pending: true,
363
+ token: tok,
364
+ tier: "elicitation",
365
+ completed: stateAny.index,
366
+ total: stateAny.set.asks.length,
367
+ },
368
+ _meta: {
369
+ elicitkit: {
370
+ token: tok,
371
+ pending: true,
372
+ completed: stateAny.index,
373
+ total: stateAny.set.asks.length,
374
+ ...extra,
375
+ },
376
+ },
377
+ }),
378
+ };
379
+ }
380
+ // The ask is done — decode its accumulated responses into an Answer.
381
+ const answer = decodeAskAnswer(ask, stateAny.subResponses);
382
+ const counters = appendCollected(token, answer);
383
+ stateAny.subResponses = [];
384
+ if (counters.completed < counters.total) {
385
+ return {
386
+ ok: true,
387
+ result: (tok, extra) => ({
388
+ content: [
389
+ {
390
+ type: "text",
391
+ text: JSON.stringify({ pending: true, token: tok, completed: counters.completed, total: counters.total }, null, 2),
392
+ },
393
+ ],
394
+ structuredContent: {
395
+ pending: true,
396
+ token: tok,
397
+ tier: "elicitation",
398
+ completed: counters.completed,
399
+ total: counters.total,
400
+ },
401
+ _meta: {
402
+ elicitkit: {
403
+ token: tok,
404
+ pending: true,
405
+ completed: counters.completed,
406
+ total: counters.total,
407
+ ...extra,
408
+ },
409
+ },
410
+ }),
411
+ };
412
+ }
413
+ // Last ask — finalise the round.
414
+ const final = closeCollected(token);
415
+ if (!final.ok) {
416
+ return {
417
+ ok: false,
418
+ error: "Answers rejected — re-ask (SPEC.md §5):\n- " + final.errors.join("\n- "),
419
+ };
420
+ }
421
+ return {
422
+ ok: true,
423
+ result: (tok, extra) => ({
424
+ content: [{ type: "text", text: JSON.stringify(final.answers, null, 2) }],
425
+ structuredContent: {
426
+ pending: false,
427
+ token: tok,
428
+ tier: "elicitation",
429
+ answers: final.answers,
430
+ },
431
+ _meta: {
432
+ elicitkit: {
433
+ token: tok,
434
+ pending: false,
435
+ inline: true,
436
+ ...extra,
437
+ },
438
+ },
439
+ }),
440
+ };
441
+ }
442
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../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C,IAAI,CAAC,MAAM,CAAC;SACjF,CAAC;IACJ,CAAC;IACD,OAAO;QACL,EAAE,EAAE,IAAI;QACR,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CACrB,CAAC;YACC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;YACzE,iBAAiB,EAAE;gBACjB,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,GAAG;gBACV,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,KAAK,CAAC,OAAO;aACvB;YACD,KAAK,EAAE;gBACL,SAAS,EAAE;oBACT,KAAK,EAAE,GAAG;oBACV,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,IAAI;oBACZ,GAAG,KAAK;iBACT;aACF;SACF,CAA0B;KAC9B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { type Answer, type AskSet, type Tier } from "@elicitkit/core";
2
+ /**
3
+ * In-memory store of pending AskSets, keyed by an opaque token handed to the
4
+ * UI. The token scopes a submission to exactly one elicitation round. A real
5
+ * deployment would back this with the security envelope (Task #7); for the
6
+ * v0.1 reference impl an in-process map is sufficient and honest. Answer
7
+ * validation itself lives in @elicitkit/core (shared with the HTTP surface).
8
+ *
9
+ * Rounds carry tier metadata + (for the elicitation tier) the per-ask
10
+ * progress so a `elicit` → `elicit_next` … sequence resolves one ask per
11
+ * tool call. Panel tiers (tui/url/apps) still complete in a single
12
+ * `elicit_submit` call; the multi-step state is only consulted by the
13
+ * elicitation path.
14
+ */
15
+ export interface RoundState {
16
+ set: AskSet;
17
+ tier: Tier;
18
+ /** Index of the NEXT ask to issue an elicitInput for. */
19
+ index: number;
20
+ /** Answers collected so far (elicitation-tier multi-step path). */
21
+ collected: Answer[];
22
+ /** When set, the round was routed away from elicitation; reason is
23
+ * exposed in `_meta.elicitkit.routedAwayFromElicitation` so the
24
+ * decision is debuggable + testable. */
25
+ routedAwayFromElicitation?: {
26
+ reason: string;
27
+ };
28
+ }
29
+ export interface OpenRoundOpts {
30
+ tier?: Tier;
31
+ routedAwayFromElicitation?: {
32
+ reason: string;
33
+ };
34
+ }
35
+ export declare function openRound(set: AskSet, opts?: OpenRoundOpts): string;
36
+ export declare function peekRound(token: string): AskSet | undefined;
37
+ export declare function peekRoundState(token: string): RoundState | undefined;
38
+ /** Append one answer to the elicitation-tier round and advance the cursor.
39
+ * Returns the updated counters so the server can decide whether to
40
+ * return `pending:true` (more asks) or the final `pending:false`. */
41
+ export declare function appendCollected(token: string, answer: Answer): {
42
+ completed: number;
43
+ total: number;
44
+ } | undefined;
45
+ /** Validate the collected answers as a batch (same path as elicit_submit)
46
+ * and discard the round. Used at the end of the elicitation-tier
47
+ * multi-step loop. */
48
+ export declare function closeCollected(token: string): SubmitResult;
49
+ export interface SubmitResult {
50
+ ok: boolean;
51
+ answers: Answer[];
52
+ errors: string[];
53
+ }
54
+ /** Validate raw answers against the pending AskSet for `token`. The
55
+ * panel-tier submission path (tui/url/apps). */
56
+ export declare function closeRound(token: string, raw: unknown): SubmitResult;
57
+ //# sourceMappingURL=submit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submit.d.ts","sourceRoot":"","sources":["../src/submit.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,KAAK,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvF;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,IAAI,CAAC;IACX,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB;;6CAEyC;IACzC,yBAAyB,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAChD;AAID,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,yBAAyB,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAChD;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,aAAkB,GAAG,MAAM,CAYvE;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE3D;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAEpE;AAED;;sEAEsE;AACtE,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAM/G;AAED;;uBAEuB;AACvB,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAQ1D;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;iDACiD;AACjD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,YAAY,CAQpE"}
package/dist/submit.js ADDED
@@ -0,0 +1,59 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { validateAnswers } from "@elicitkit/core";
3
+ const pending = new Map();
4
+ export function openRound(set, opts = {}) {
5
+ const token = randomUUID();
6
+ pending.set(token, {
7
+ set,
8
+ tier: opts.tier ?? "tui",
9
+ index: 0,
10
+ collected: [],
11
+ ...(opts.routedAwayFromElicitation
12
+ ? { routedAwayFromElicitation: opts.routedAwayFromElicitation }
13
+ : {}),
14
+ });
15
+ return token;
16
+ }
17
+ export function peekRound(token) {
18
+ return pending.get(token)?.set;
19
+ }
20
+ export function peekRoundState(token) {
21
+ return pending.get(token);
22
+ }
23
+ /** Append one answer to the elicitation-tier round and advance the cursor.
24
+ * Returns the updated counters so the server can decide whether to
25
+ * return `pending:true` (more asks) or the final `pending:false`. */
26
+ export function appendCollected(token, answer) {
27
+ const st = pending.get(token);
28
+ if (!st)
29
+ return undefined;
30
+ st.collected.push(answer);
31
+ st.index += 1;
32
+ return { completed: st.collected.length, total: st.set.asks.length };
33
+ }
34
+ /** Validate the collected answers as a batch (same path as elicit_submit)
35
+ * and discard the round. Used at the end of the elicitation-tier
36
+ * multi-step loop. */
37
+ export function closeCollected(token) {
38
+ const st = pending.get(token);
39
+ if (!st) {
40
+ return { ok: false, answers: [], errors: ["unknown or expired token"] };
41
+ }
42
+ const r = validateAnswers(st.set, st.collected);
43
+ if (r.ok)
44
+ pending.delete(token);
45
+ return r;
46
+ }
47
+ /** Validate raw answers against the pending AskSet for `token`. The
48
+ * panel-tier submission path (tui/url/apps). */
49
+ export function closeRound(token, raw) {
50
+ const st = pending.get(token);
51
+ if (!st) {
52
+ return { ok: false, answers: [], errors: ["unknown or expired token"] };
53
+ }
54
+ const r = validateAnswers(st.set, raw);
55
+ if (r.ok)
56
+ pending.delete(token);
57
+ return r;
58
+ }
59
+ //# sourceMappingURL=submit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submit.js","sourceRoot":"","sources":["../src/submit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAuC,MAAM,iBAAiB,CAAC;AA4BvF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAsB,CAAC;AAO9C,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,OAAsB,EAAE;IAC7D,MAAM,KAAK,GAAG,UAAU,EAAE,CAAC;IAC3B,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE;QACjB,GAAG;QACH,IAAI,EAAE,IAAI,CAAC,IAAI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AAC,SAAS,CAAC,CAAC;IAChD,IAAI,CAAC,CAAC,EAAE;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAChC,OAAO,CAAC,CAAC;AACX,CAAC;AAQD;iDACiD;AACjD,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,GAAY;IACpD,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,0BAA0B,CAAC,EAAE,CAAC;IAC1E,CAAC;IACD,MAAM,CAAC,GAAG,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACvC,IAAI,CAAC,CAAC,EAAE;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAChC,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { AskSet, Tier } from "@elicitkit/core";
2
+ /** Richest → poorest. The spec's normative ordering (SPEC.md §4). */
3
+ export declare const TIER_ORDER: readonly Tier[];
4
+ /**
5
+ * The poorest `minTier` across all asks in the set bounds how rich a tier the
6
+ * whole panel may use — every ask must still be faithful at the chosen tier.
7
+ * An ask with `minTier: "url"` cannot degrade below `url`; the set inherits
8
+ * that floor. Default floor is `tui` (the universal sink — never hard-fails).
9
+ */
10
+ export declare function setFloor(set: AskSet): Tier;
11
+ export interface TierChoice {
12
+ tier: Tier;
13
+ /** True when the host advertised tiers and the floor still fit. */
14
+ negotiated: boolean;
15
+ }
16
+ /**
17
+ * Pick the richest tier the host supports that is still ≥ the set's floor
18
+ * (SPEC.md §4). If the host advertises nothing, assume `tui` — the one tier
19
+ * every client can render and the spec guarantees never hard-fails.
20
+ */
21
+ export declare function negotiateTier(set: AskSet, hostSupported: readonly Tier[] | undefined): TierChoice;
22
+ /**
23
+ * Slow-ask auto-router. The elicitation tier is one-question-at-a-time
24
+ * over a per-tool-call MCP timeout — fine for quick asks (ask_confirm, a
25
+ * short ask_select, a number) but cliff-edge for any ask that needs
26
+ * actual thought time (a multiline essay, a many-hunk code diff, a long
27
+ * ranking). For those, a panel tier (apps/url) — or, failing those, tui
28
+ * with a single round-trip — keeps the call bounded while letting the
29
+ * user take as long as they want.
30
+ *
31
+ * The router is conservative: a single slow-likely ask in the set is
32
+ * enough to drop elicitation from the candidate tier list. The host's
33
+ * other tiers (apps/url/tui) still negotiate normally. If elicitation
34
+ * was the only tier the host offered, the safe sink ("tui") still wins
35
+ * because the spec guarantees every type renders there.
36
+ */
37
+ export interface SlowAskDecision {
38
+ routed: boolean;
39
+ reason?: string;
40
+ }
41
+ export declare function slowAskRoute(set: AskSet): SlowAskDecision;
42
+ //# sourceMappingURL=tiers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiers.d.ts","sourceRoot":"","sources":["../src/tiers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAO,MAAM,EAAE,IAAI,EAAiC,MAAM,iBAAiB,CAAC;AAExF,qEAAqE;AACrE,eAAO,MAAM,UAAU,EAAE,SAAS,IAAI,EAA0C,CAAC;AASjF;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAO1C;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,IAAI,CAAC;IACX,mEAAmE;IACnE,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,SAAS,IAAI,EAAE,GAAG,SAAS,GACzC,UAAU,CAmBZ;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAMzD"}
package/dist/tiers.js ADDED
@@ -0,0 +1,91 @@
1
+ /** Richest → poorest. The spec's normative ordering (SPEC.md §4). */
2
+ export const TIER_ORDER = ["apps", "url", "elicitation", "tui"];
3
+ const RANK = { apps: 0, url: 1, elicitation: 2, tui: 3 };
4
+ /** A higher rank number = poorer tier. `a` is at least as rich as `b`. */
5
+ function atLeastAsRich(a, b) {
6
+ return RANK[a] <= RANK[b];
7
+ }
8
+ /**
9
+ * The poorest `minTier` across all asks in the set bounds how rich a tier the
10
+ * whole panel may use — every ask must still be faithful at the chosen tier.
11
+ * An ask with `minTier: "url"` cannot degrade below `url`; the set inherits
12
+ * that floor. Default floor is `tui` (the universal sink — never hard-fails).
13
+ */
14
+ export function setFloor(set) {
15
+ let floor = "tui";
16
+ for (const ask of set.asks) {
17
+ const m = ask.meta?.minTier;
18
+ if (m && atLeastAsRich(m, floor) === false)
19
+ floor = m;
20
+ }
21
+ return floor;
22
+ }
23
+ /**
24
+ * Pick the richest tier the host supports that is still ≥ the set's floor
25
+ * (SPEC.md §4). If the host advertises nothing, assume `tui` — the one tier
26
+ * every client can render and the spec guarantees never hard-fails.
27
+ */
28
+ export function negotiateTier(set, hostSupported) {
29
+ const floor = setFloor(set);
30
+ if (!hostSupported || hostSupported.length === 0) {
31
+ // No capabilities advertised: the safe universal sink.
32
+ return { tier: "tui", negotiated: false };
33
+ }
34
+ const supported = new Set(hostSupported);
35
+ for (const tier of TIER_ORDER) {
36
+ // richest → poorest: first supported tier that is still ≥ the floor
37
+ if (supported.has(tier) && atLeastAsRich(tier, floor)) {
38
+ return { tier, negotiated: true };
39
+ }
40
+ }
41
+ // Host supports nothing at or above the floor — fall back to tui, which
42
+ // the spec defines for every type so the panel still renders.
43
+ return { tier: "tui", negotiated: false };
44
+ }
45
+ export function slowAskRoute(set) {
46
+ for (const ask of set.asks) {
47
+ const r = isSlowAsk(ask);
48
+ if (r)
49
+ return { routed: true, reason: r };
50
+ }
51
+ return { routed: false };
52
+ }
53
+ function isSlowAsk(ask) {
54
+ switch (ask.type) {
55
+ case "ask_text": {
56
+ const s = ask.spec ?? {};
57
+ if (s.multiline === true)
58
+ return "ask_text.multiline";
59
+ // No bound = free-form; we treat unset as "could be long". 200 chars
60
+ // is roughly the limit at which typing time exceeds typical per-call
61
+ // MCP timeouts on a slow human.
62
+ if (typeof s.maxLen === "number") {
63
+ if (s.maxLen >= 200)
64
+ return "ask_text.maxLen>=200";
65
+ }
66
+ else {
67
+ return "ask_text.maxLen-unset";
68
+ }
69
+ return null;
70
+ }
71
+ case "ask_code_diff": {
72
+ const files = ask.spec.files ?? [];
73
+ const hunks = files.reduce((n, f) => n + (f.hunks?.length ?? 0), 0);
74
+ if (hunks > 2)
75
+ return "ask_code_diff.hunks>2";
76
+ return null;
77
+ }
78
+ case "ask_rank": {
79
+ const items = ask.spec.items ?? [];
80
+ if (items.length > 4)
81
+ return "ask_rank.items>4";
82
+ return null;
83
+ }
84
+ // Reserved hooks for v0.1 (ask_form / ask_table land later):
85
+ // the names are listed in the SPEC additive so a forward-compatible
86
+ // implementation could plug them in here without a major bump.
87
+ default:
88
+ return null;
89
+ }
90
+ }
91
+ //# sourceMappingURL=tiers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiers.js","sourceRoot":"","sources":["../src/tiers.ts"],"names":[],"mappings":"AAEA,qEAAqE;AACrE,MAAM,CAAC,MAAM,UAAU,GAAoB,CAAC,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;AAEjF,MAAM,IAAI,GAAyB,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;AAE/E,0EAA0E;AAC1E,SAAS,aAAa,CAAC,CAAO,EAAE,CAAO;IACrC,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;AAC5B,CAA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YAChD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,6DAA6D;QAC7D,oEAAoE;QACpE,+DAA+D;QAC/D;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@elicitkit/server",
3
+ "version": "0.1.0",
4
+ "description": "Elicitkit MCP reference implementation — serves the question catalog over MCP with progressive 4-tier rendering on @mcp-ui/server.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "bin": {
16
+ "elicitkit-server": "dist/bin.js"
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc -p tsconfig.json",
23
+ "test": "tsc -p tsconfig.json && node test/smoke.mjs"
24
+ },
25
+ "dependencies": {
26
+ "@elicitkit/core": "workspace:*",
27
+ "@elicitkit/renderers": "workspace:*",
28
+ "@modelcontextprotocol/sdk": "^1.29.0",
29
+ "zod": "^3.25.1"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ }
34
+ }