@khanglvm/relay 0.20.2 → 0.21.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.
Files changed (54) hide show
  1. package/README.md +2 -2
  2. package/docs/AGENT.md +56 -83
  3. package/docs/SETUP.md +3 -2
  4. package/package.json +12 -5
  5. package/skills/relay/SKILL.md +45 -145
  6. package/src/cli/agent-topics.js +84 -0
  7. package/src/cli/config.js +26 -2
  8. package/src/cli/index.js +3 -5
  9. package/src/cli/mcp.js +4 -2
  10. package/src/cli/skill.js +21 -22
  11. package/src/mcp/boards.js +173 -0
  12. package/src/mcp/config.js +20 -0
  13. package/src/mcp/constants.js +31 -0
  14. package/src/mcp/index.js +5 -0
  15. package/src/mcp/page.js +59 -0
  16. package/src/mcp/schemas.js +42 -0
  17. package/src/mcp/serve.js +116 -0
  18. package/src/mcp/server.js +23 -0
  19. package/src/mcp/store.js +35 -0
  20. package/src/mcp/token.js +31 -0
  21. package/src/mcp/tools.js +171 -0
  22. package/src/mcp-ui/board/block-ctx.js +22 -0
  23. package/src/mcp-ui/board/bridge.js +12 -2
  24. package/src/mcp-ui/board/core.js +2 -0
  25. package/src/mcp-ui/board/lifecycle.js +47 -9
  26. package/src/mcp-ui/board/render.js +36 -44
  27. package/src/mcp-ui/board/vendors.js +56 -11
  28. package/src/spec/blocks/chart.js +8 -4
  29. package/src/spec/constants.js +19 -0
  30. package/src/spec/index.js +1 -0
  31. package/src/spec/lookup.js +78 -0
  32. package/src/spec/normalize.js +9 -4
  33. package/src/spec/ready.js +15 -1
  34. package/src/ui/manifest.js +1 -1
  35. package/types/cli/agent-topics.d.ts +46 -0
  36. package/types/mcp/boards.d.ts +168 -0
  37. package/types/{mcp.d.ts → mcp/config.d.ts} +1 -8
  38. package/types/mcp/constants.d.ts +21 -0
  39. package/types/mcp/index.d.ts +4 -0
  40. package/types/mcp/page.d.ts +27 -0
  41. package/types/mcp/schemas.d.ts +46 -0
  42. package/types/mcp/serve.d.ts +16 -0
  43. package/types/mcp/server.d.ts +4 -0
  44. package/types/mcp/store.d.ts +52 -0
  45. package/types/mcp/token.d.ts +5 -0
  46. package/types/mcp/tools.d.ts +17 -0
  47. package/types/server/result.d.ts +10 -0
  48. package/types/server/sanitize.d.ts +6 -0
  49. package/types/spec/blocks/chart.d.ts +1 -1
  50. package/types/spec/constants.d.ts +14 -0
  51. package/types/spec/index.d.ts +1 -0
  52. package/types/spec/lookup.d.ts +57 -0
  53. package/types/spec/ready.d.ts +2 -0
  54. package/src/mcp.js +0 -483
@@ -0,0 +1,78 @@
1
+ // `rly schema <name>`: the exact fields of one block or question type, cut out of SPEC_SCHEMA.
2
+ import { BLOCK_TYPES, TYPES } from './constants.js';
3
+ import { SPEC_SCHEMA } from './schema.js';
4
+
5
+ const BLOCK_PROPS = SPEC_SCHEMA.properties.blocks.items.properties;
6
+ const QUESTION_PROPS = SPEC_SCHEMA.properties.questions.items.properties;
7
+
8
+ // Fields every block carries on top of its own.
9
+ const COMMON_BLOCK_FIELDS = ['type', 'ref', 'height'];
10
+
11
+ // Which BLOCK_PROPS entries each block type reads. A test checks that every
12
+ // property of the block schema belongs to at least one type, so a new field
13
+ // cannot be added to the schema without being listed here.
14
+ export const BLOCK_FIELDS = {
15
+ markdown: ['md', 'mdFile'],
16
+ mermaid: ['code', 'editable'],
17
+ graphviz: ['dot'],
18
+ plantuml: ['code', 'server'],
19
+ chart: ['kind', 'labels', 'series', 'config', 'title'],
20
+ table: ['columns', 'rows', 'rowsFile', 'sortable', 'filterable', 'exportable'],
21
+ code: ['code', 'codeFile', 'lang', 'filename'],
22
+ diff: ['diff', 'diffFile', 'view', 'review', 'reviewKind', 'commit', 'lang', 'filename'],
23
+ 'git-conflict': ['content', 'text', 'file', 'path', 'lang', 'filename'],
24
+ video: ['src', 'alt', 'title'],
25
+ pdf: ['src', 'alt', 'title'],
26
+ html: ['html', 'htmlFile'],
27
+ image: ['src', 'alt', 'pins'],
28
+ palette: ['palettes', 'colors', 'name'],
29
+ kpi: ['items'],
30
+ typography: ['specimens'],
31
+ compare: ['before', 'after', 'beforeLabel', 'afterLabel'],
32
+ a2ui: ['express', 'components', 'dataModel', 'title'],
33
+ };
34
+
35
+ // Fields every question carries on top of its own.
36
+ const COMMON_QUESTION_FIELDS = ['id', 'type', 'label', 'description', 'required', 'note', 'blocks'];
37
+
38
+ export const QUESTION_FIELDS = {
39
+ single: ['options', 'other', 'default'],
40
+ multi: ['options', 'other', 'default'],
41
+ yesno: ['default'],
42
+ text: ['placeholder', 'default'],
43
+ textarea: ['placeholder', 'default'],
44
+ scale: ['min', 'max', 'minLabel', 'maxLabel', 'default'],
45
+ color: ['presets', 'palette', 'default'],
46
+ rank: ['options', 'default'],
47
+ checklist: ['options', 'statuses', 'default'],
48
+ allocate: ['options', 'total', 'unit', 'default'],
49
+ };
50
+
51
+ function pick(props, names) {
52
+ return Object.fromEntries(names.filter((n) => props[n]).map((n) => [n, props[n]]));
53
+ }
54
+
55
+ /** The property names the schema defines for blocks and for questions. */
56
+ export function schemaFieldNames() {
57
+ return { block: Object.keys(BLOCK_PROPS), question: Object.keys(QUESTION_PROPS) };
58
+ }
59
+
60
+ /**
61
+ * The fields of one block or question type, or null when the name is neither.
62
+ * A name that is both (`code` is only a block; `color` only a question) never
63
+ * collides today; a block wins if one ever does.
64
+ */
65
+ export function lookupSchema(name) {
66
+ const key = String(name).trim().toLowerCase();
67
+ if (BLOCK_TYPES.includes(key)) {
68
+ const fields = pick(BLOCK_PROPS, [...COMMON_BLOCK_FIELDS, ...(BLOCK_FIELDS[key] ?? [])]);
69
+ fields.type = { const: key };
70
+ return { kind: 'block', type: key, fields };
71
+ }
72
+ if (TYPES.includes(key)) {
73
+ const fields = pick(QUESTION_PROPS, [...COMMON_QUESTION_FIELDS, ...(QUESTION_FIELDS[key] ?? [])]);
74
+ fields.type = { const: key };
75
+ return { kind: 'question', type: key, required: ['label'], fields };
76
+ }
77
+ return null;
78
+ }
@@ -2,7 +2,7 @@
2
2
  // the server and the MCP App read.
3
3
  import { CliError } from '../util.js';
4
4
  import { asStr, clampInt, readBlockHtml, readHtml } from './sources.js';
5
- import { ALIASES, BLOCK_HEIGHT, BLOCK_TYPES, HTML_HEIGHT, TYPES } from './constants.js';
5
+ import { ALIASES, BLOCK_ALIASES, BLOCK_HEIGHT, BLOCK_TYPES, CHART_KINDS, HTML_HEIGHT, TYPES } from './constants.js';
6
6
  import { BLOCK_NORMALIZERS } from './blocks/index.js';
7
7
 
8
8
  // Normalizes one block object. `id` is the already-assigned block id.
@@ -13,8 +13,13 @@ function normalizeBlock(rawBlock, id, cwd, where) {
13
13
  }
14
14
  let type = asStr(rawBlock.type).trim().toLowerCase();
15
15
  if (!type) throw new CliError(`${where}: missing "type". Valid: ${BLOCK_TYPES.join(', ')}.`);
16
+ if (CHART_KINDS.includes(type)) {
17
+ rawBlock = { ...rawBlock, kind: rawBlock.kind ?? type };
18
+ type = 'chart';
19
+ }
20
+ type = BLOCK_ALIASES[type] || type;
16
21
  if (!BLOCK_TYPES.includes(type)) {
17
- throw new CliError(`${where}: unknown block type "${rawBlock.type}". Valid: ${BLOCK_TYPES.join(', ')}.`);
22
+ throw new CliError(`${where}: unknown block type "${rawBlock.type}". Use one of: ${BLOCK_TYPES.join(', ')}. \`rly schema <type>\` shows its fields.`);
18
23
  }
19
24
 
20
25
  const hasHeight = rawBlock.height !== undefined && rawBlock.height !== null && rawBlock.height !== '';
@@ -159,7 +164,7 @@ export function normalizeSpec(raw, { cwd = process.cwd() } = {}) {
159
164
  };
160
165
 
161
166
  if (type === 'single' || type === 'multi' || type === 'rank' || type === 'checklist' || type === 'allocate') {
162
- const opts = Array.isArray(rq.options) ? rq.options : [];
167
+ const opts = Array.isArray(rq.options) ? rq.options : Array.isArray(rq.choices) ? rq.choices : [];
163
168
  q.options = opts.map((o, j) => {
164
169
  if (typeof o === 'string' || typeof o === 'number') {
165
170
  return { value: String(o), label: String(o) };
@@ -261,7 +266,7 @@ export function normalizeSpec(raw, { cwd = process.cwd() } = {}) {
261
266
  throw new CliError('Spec needs "questions" and/or "blocks"/"html" — nothing to show.');
262
267
  }
263
268
  if (!spec.responseRequired && spec.questions.length) {
264
- throw new CliError('responseRequired:false is display-only and cannot contain questions. Use responseRequired:true when answers are needed.');
269
+ throw new CliError('responseRequired:false makes a display-only board, which cannot hold questions. Remove "responseRequired" to collect answers, or remove "questions" to keep the board display-only.');
265
270
  }
266
271
  spec.submitLabel = asStr(raw.submitLabel).trim() || (spec.questions.length ? 'Submit' : 'Acknowledge');
267
272
  return spec;
package/src/spec/ready.js CHANGED
@@ -81,13 +81,27 @@ async function mermaidValidator() {
81
81
  return mermaidValidatorPromise;
82
82
  }
83
83
 
84
+ // Names of the errors JavaScript itself throws. The parser throws these when
85
+ // its sandbox lacks something (`X is not defined`, `Y is not a function`); a
86
+ // diagram with bad syntax makes it throw a plain Error carrying a parse message.
87
+ // The sandbox is another realm, so `instanceof` cannot tell them apart.
88
+ const ENVIRONMENT_ERROR_NAMES = new Set(['TypeError', 'ReferenceError', 'RangeError', 'EvalError']);
89
+
90
+ /** True when the error comes from the checker's own environment and says nothing about the diagram. */
91
+ export function isCheckerFailure(err) {
92
+ return Boolean(err) && ENVIRONMENT_ERROR_NAMES.has(err.name);
93
+ }
94
+
84
95
  async function assertMermaidSyntax(code, where) {
85
96
  const mermaid = await mermaidValidator();
86
97
  try {
87
98
  const parsed = mermaid.parse(code);
88
99
  if (parsed && typeof parsed.then === 'function') await parsed;
89
100
  } catch (err) {
90
- throw new CliError(`${where}: invalid mermaid syntax — ${compactError(err)}`);
101
+ if (isCheckerFailure(err)) {
102
+ throw new CliError(`${where}: internal error, the mermaid checker failed and did not check this diagram (${compactError(err)}). The diagram may be fine. Report this to the relay maintainers, or show the diagram as an image or a markdown code block meanwhile.`, 1);
103
+ }
104
+ throw new CliError(`${where}: invalid mermaid syntax. Fix the diagram source: ${compactError(err)}`);
91
105
  }
92
106
  }
93
107
 
@@ -1,5 +1,5 @@
1
1
  // The browser files of each page, in the order they run. The web board
2
- // (src/server/page.js) and the MCP App page (src/mcp.js) both assemble their
2
+ // (src/server/page.js) and the MCP App page (src/mcp/page.js) both assemble their
3
3
  // scripts and styles from this list, so a file added here reaches both pages.
4
4
  //
5
5
  // Browser scripts share one scope per page. A bundle part holds files that read
@@ -0,0 +1,46 @@
1
+ export declare const AGENT_TOPICS: {
2
+ questions: {
3
+ summary: string;
4
+ headings: string[];
5
+ };
6
+ blocks: {
7
+ summary: string;
8
+ headings: string[];
9
+ };
10
+ annotate: {
11
+ summary: string;
12
+ headings: string[];
13
+ };
14
+ lifecycle: {
15
+ summary: string;
16
+ headings: string[];
17
+ preamble: boolean;
18
+ };
19
+ sharing: {
20
+ summary: string;
21
+ headings: string[];
22
+ };
23
+ mcp: {
24
+ summary: string;
25
+ headings: string[];
26
+ };
27
+ a2ui: {
28
+ summary: string;
29
+ file: string;
30
+ };
31
+ };
32
+ /** Splits a markdown guide into its text before the first H2 and its H2 sections. Headings inside code fences are text. */
33
+ export declare function splitSections(md: any): {
34
+ preamble: string;
35
+ sections: {
36
+ title: any;
37
+ text: any;
38
+ }[];
39
+ };
40
+ /** The topic list `rly agent` prints for an unknown topic. */
41
+ export declare function topicIndex(): string;
42
+ /**
43
+ * The text of one topic. `readDoc(file)` returns a docs/ file as text; the
44
+ * caller owns the filesystem so this stays testable.
45
+ */
46
+ export declare function renderAgentTopic(topic: any, readDoc: any): any;
@@ -0,0 +1,168 @@
1
+ /** One board call's mode: a board that wants a reply is `ask`, anything else `show`. Questions always want a reply. */
2
+ export declare const modeOf: (spec: any) => "ask" | "show";
3
+ /**
4
+ * Normalizes the tool arguments into a stored board. Spec errors come back as
5
+ * CliError so the tool can answer with an isError result the model can fix.
6
+ * @param {import('./store.js').RelayStore} store
7
+ * @param {Record<string, any>} args
8
+ * @param {{ displayOnly?: boolean }} [options]
9
+ */
10
+ export declare function createMcpBoard(store: import('./store.js').RelayStore, args: Record<string, any>, options?: {
11
+ displayOnly?: boolean;
12
+ }): Promise<{
13
+ record: import("./store.js").BoardRecord;
14
+ spec: {
15
+ title: string;
16
+ intro: string;
17
+ blocks: any[];
18
+ allowPartial: boolean;
19
+ note: boolean;
20
+ autoClose: boolean;
21
+ responseRequired: boolean;
22
+ questions: any[];
23
+ submitLabel: string;
24
+ };
25
+ mode: string;
26
+ }>;
27
+ /** The compact list of questions a model sees in the relay_board result: id, type, label. */
28
+ export declare function questionList(spec: any, labelMax?: number): any;
29
+ /**
30
+ * The relay_board result: a summary and structuredContent, never the spec.
31
+ * The question list shrinks until the whole result fits RESULT_BUDGET_BYTES.
32
+ * @returns {ToolResult}
33
+ */
34
+ export declare function boardResult(record: any, spec: any, mode: any): ToolResult;
35
+ export type ToolResult = import('@modelcontextprotocol/server').CallToolResult;
36
+ /** @typedef {import('@modelcontextprotocol/server').CallToolResult} ToolResult */
37
+ /** @returns {ToolResult} */
38
+ export declare const errorResult: (message: any) => ToolResult;
39
+ /** An invalid spec as a tool error; anything else is a server bug and rethrows. */
40
+ export declare function specError(err: any): {
41
+ [x: string]: unknown;
42
+ _meta?: {
43
+ [x: string]: unknown;
44
+ "io.modelcontextprotocol/serverInfo"?: {
45
+ version: string;
46
+ websiteUrl?: string;
47
+ description?: string;
48
+ icons?: {
49
+ src: string;
50
+ mimeType?: string;
51
+ sizes?: string[];
52
+ theme?: "dark" | "light";
53
+ }[];
54
+ name: string;
55
+ title?: string;
56
+ };
57
+ };
58
+ content: ({
59
+ type: "text";
60
+ text: string;
61
+ annotations?: {
62
+ audience?: ("assistant" | "user")[];
63
+ priority?: number;
64
+ lastModified?: string;
65
+ };
66
+ _meta?: {
67
+ [x: string]: unknown;
68
+ };
69
+ } | {
70
+ type: "image";
71
+ data: string;
72
+ mimeType: string;
73
+ annotations?: {
74
+ audience?: ("assistant" | "user")[];
75
+ priority?: number;
76
+ lastModified?: string;
77
+ };
78
+ _meta?: {
79
+ [x: string]: unknown;
80
+ };
81
+ } | {
82
+ type: "audio";
83
+ data: string;
84
+ mimeType: string;
85
+ annotations?: {
86
+ audience?: ("assistant" | "user")[];
87
+ priority?: number;
88
+ lastModified?: string;
89
+ };
90
+ _meta?: {
91
+ [x: string]: unknown;
92
+ };
93
+ } | {
94
+ uri: string;
95
+ description?: string;
96
+ mimeType?: string;
97
+ size?: number;
98
+ annotations?: {
99
+ audience?: ("assistant" | "user")[];
100
+ priority?: number;
101
+ lastModified?: string;
102
+ };
103
+ _meta?: {
104
+ [x: string]: unknown;
105
+ };
106
+ icons?: {
107
+ src: string;
108
+ mimeType?: string;
109
+ sizes?: string[];
110
+ theme?: "dark" | "light";
111
+ }[];
112
+ name: string;
113
+ title?: string;
114
+ type: "resource_link";
115
+ } | {
116
+ type: "resource";
117
+ resource?: {
118
+ uri: string;
119
+ mimeType?: string;
120
+ _meta?: {
121
+ [x: string]: unknown;
122
+ };
123
+ text: string;
124
+ } | {
125
+ uri: string;
126
+ mimeType?: string;
127
+ _meta?: {
128
+ [x: string]: unknown;
129
+ };
130
+ blob: string;
131
+ };
132
+ annotations?: {
133
+ audience?: ("assistant" | "user")[];
134
+ priority?: number;
135
+ lastModified?: string;
136
+ };
137
+ _meta?: {
138
+ [x: string]: unknown;
139
+ };
140
+ })[];
141
+ structuredContent?: unknown;
142
+ isError?: boolean;
143
+ };
144
+ /** Saves the person's answers so far, so relay_result can show them before the final submit. */
145
+ export declare function saveDraft(store: any, id: any, draft: any): Promise<any>;
146
+ /**
147
+ * Stores the final answers. A second submit is refused so a stray click cannot
148
+ * overwrite what the agent may already have read.
149
+ * @returns {Promise<{ ok: boolean, status?: string, error?: string }>}
150
+ */
151
+ export declare function submitBoard(store: any, record: any, body: any): Promise<{
152
+ ok: boolean;
153
+ status?: string;
154
+ error?: string;
155
+ }>;
156
+ /**
157
+ * Appends one a2ui button click for relay_result to report. The click must name
158
+ * an a2ui block on this board and pass the checks the browser board applies to a2ui state.
159
+ * @returns {Promise<{ ok: boolean, entry?: object, error?: string }>}
160
+ */
161
+ export declare function recordEvent(store: any, record: any, event: any): Promise<{
162
+ ok: boolean;
163
+ entry?: object;
164
+ error?: string;
165
+ }>;
166
+ /** What relay_result reports for a board right now. */
167
+ export declare function resultOf(record: any): any;
168
+ export declare const isFinal: (record: any) => boolean;
@@ -1,10 +1,4 @@
1
- export declare function runMcp(): Promise<any>;
2
- export declare function runMcpHttp({ port, host, token, allowOrigin }?: {
3
- allowOrigin?: string;
4
- host?: string;
5
- port?: number;
6
- token?: string;
7
- }): Promise<any>;
1
+ /** Setup for each host: a JSON entry, a Codex TOML block, and how to run the HTTP transport. */
8
2
  export declare function mcpConfig({ command, httpPort }?: {
9
3
  command?: string;
10
4
  httpPort?: number;
@@ -25,7 +19,6 @@ export declare function mcpConfig({ command, httpPort }?: {
25
19
  http: {
26
20
  run: string;
27
21
  url: string;
28
- deploy: string;
29
22
  note: string;
30
23
  };
31
24
  };
@@ -0,0 +1,21 @@
1
+ export declare const UI_EXT = "io.modelcontextprotocol/ui";
2
+ export declare const UI_MIME = "text/html;profile=mcp-app";
3
+ export declare const BOARD_URI = "ui://relay/board";
4
+ export declare const VENDOR_URI_PREFIX = "ui://relay/vendor/";
5
+ export declare const HTTP_PATH = "/mcp";
6
+ export declare const DEFAULT_HTTP_PORT = 4319;
7
+ export declare const VENDOR_CHUNK_BYTES: number;
8
+ export declare const MAX_WAIT_SECONDS = 600;
9
+ export declare const RESULT_BUDGET_BYTES = 2048;
10
+ export declare const TOOL: {
11
+ board: string;
12
+ help: string;
13
+ result: string;
14
+ view: string;
15
+ draft: string;
16
+ submit: string;
17
+ asset: string;
18
+ a2uiAction: string;
19
+ ask: string;
20
+ show: string;
21
+ };
@@ -0,0 +1,4 @@
1
+ export { mcpConfig } from './config.js';
2
+ export { runMcp, runMcpHttp } from './serve.js';
3
+ export { fileStore } from './store.js';
4
+ export { registerRelay } from './tools.js';
@@ -0,0 +1,27 @@
1
+ /** The vendored libraries a board may load, by file name. Nothing else under vendor/ is served. */
2
+ export declare const VENDOR_FILES: string[];
3
+ export declare const PKG: any;
4
+ export declare const DOCS_DIR: string;
5
+ /** The single self-contained page: styles, block renderer and the MCP client, inlined. Built once per process. */
6
+ export declare function boardPage(): any;
7
+ /** The text of one vendor file, or null when the name is not on the allowlist. */
8
+ export declare function vendorText(name: any): string;
9
+ /**
10
+ * One base64 chunk of a vendor file, for hosts that refuse resources/read.
11
+ * @returns {{ name: string, index: number, count: number, data: string } | null}
12
+ */
13
+ export declare function vendorChunk(name: any, index: any): {
14
+ name: string;
15
+ index: number;
16
+ count: number;
17
+ data: string;
18
+ } | null;
19
+ /** The resource metadata hosts read to build the iframe's CSP. */
20
+ export declare const BOARD_RESOURCE_META: {
21
+ prefersBorder: boolean;
22
+ csp: {
23
+ connectDomains: undefined[];
24
+ resourceDomains: string[];
25
+ frameDomains: string[];
26
+ };
27
+ };
@@ -0,0 +1,46 @@
1
+ import * as z from 'zod';
2
+ /** The relay_board input: the spec's top-level fields, with blocks and questions left open. */
3
+ export declare const boardInput: z.ZodObject<{
4
+ title: z.ZodOptional<z.ZodString>;
5
+ intro: z.ZodOptional<z.ZodString>;
6
+ blocks: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
7
+ questions: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
8
+ responseRequired: z.ZodOptional<z.ZodBoolean>;
9
+ }, z.core.$loose>;
10
+ /** The deprecated relay_ask and relay_show take the same fields, but their schema stays empty so the tool list stays small. */
11
+ export declare const aliasInput: z.ZodObject<{}, z.core.$loose>;
12
+ export declare const viewInput: z.ZodObject<{
13
+ boardId: z.ZodString;
14
+ token: z.ZodString;
15
+ }, z.core.$strip>;
16
+ export declare const draftInput: z.ZodObject<{
17
+ boardId: z.ZodString;
18
+ token: z.ZodString;
19
+ draft: z.ZodRecord<z.ZodString, z.ZodUnknown>;
20
+ }, z.core.$strip>;
21
+ export declare const submitInput: z.ZodObject<{
22
+ boardId: z.ZodString;
23
+ token: z.ZodString;
24
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
25
+ }, z.core.$strip>;
26
+ export declare const actionInput: z.ZodObject<{
27
+ boardId: z.ZodString;
28
+ token: z.ZodString;
29
+ blockId: z.ZodString;
30
+ name: z.ZodString;
31
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
32
+ }, z.core.$strip>;
33
+ export declare const assetInput: z.ZodObject<{
34
+ name: z.ZodString;
35
+ index: z.ZodDefault<z.ZodNumber>;
36
+ }, z.core.$strip>;
37
+ export declare const helpInput: z.ZodObject<{
38
+ topic: z.ZodOptional<z.ZodEnum<{
39
+ [x: string]: string;
40
+ }>>;
41
+ schema: z.ZodOptional<z.ZodString>;
42
+ }, z.core.$strip>;
43
+ export declare const resultInput: z.ZodObject<{
44
+ boardId: z.ZodString;
45
+ wait_seconds: z.ZodOptional<z.ZodNumber>;
46
+ }, z.core.$strip>;
@@ -0,0 +1,16 @@
1
+ /** Serves MCP over this process's stdin and stdout until the host closes stdin. */
2
+ export declare function runMcp(): Promise<any>;
3
+ /** A browser Origin is trusted when it is local or the one the operator allowed. A client with no Origin is not a browser. */
4
+ export declare function originAllowed(origin: any, allowOrigin: any): boolean;
5
+ /** Constant-time string comparison for the bearer token. */
6
+ export declare function safeEqual(a: any, b: any): boolean;
7
+ /**
8
+ * Serves MCP over Streamable HTTP. Localhost by default; a bearer token and an
9
+ * allowed Origin are the controls for anything wider.
10
+ */
11
+ export declare function runMcpHttp({ port, host, token, allowOrigin }?: {
12
+ allowOrigin?: string;
13
+ host?: string;
14
+ port?: number;
15
+ token?: string;
16
+ }): Promise<any>;
@@ -0,0 +1,4 @@
1
+ import { McpServer } from '@modelcontextprotocol/server';
2
+ import { registerRelay } from './tools.js';
3
+ /** @param {Parameters<typeof registerRelay>[1]} [options] */
4
+ export declare function createRelayServer(options?: Parameters<typeof registerRelay>[1]): McpServer;
@@ -0,0 +1,52 @@
1
+ export type BoardRecord = {
2
+ id: string;
3
+ /**
4
+ * the normalized board spec
5
+ */
6
+ spec: any;
7
+ /**
8
+ * the person's answers so far
9
+ */
10
+ draft?: any;
11
+ /**
12
+ * set once the person submits
13
+ */
14
+ result?: any;
15
+ /**
16
+ * a2ui button clicks, newest last
17
+ */
18
+ events?: any[];
19
+ };
20
+ export type RelayStore = {
21
+ create: (spec: any) => BoardRecord | Promise<BoardRecord>;
22
+ get: (id: string) => BoardRecord | null | Promise<BoardRecord | null>;
23
+ update: (id: string, patch: Partial<BoardRecord>) => BoardRecord | null | Promise<BoardRecord | null>;
24
+ };
25
+ /**
26
+ * @typedef {object} BoardRecord
27
+ * @property {string} id
28
+ * @property {any} spec the normalized board spec
29
+ * @property {any} [draft] the person's answers so far
30
+ * @property {any} [result] set once the person submits
31
+ * @property {any[]} [events] a2ui button clicks, newest last
32
+ */
33
+ /**
34
+ * @typedef {object} RelayStore
35
+ * @property {(spec: any) => BoardRecord | Promise<BoardRecord>} create
36
+ * @property {(id: string) => BoardRecord | null | Promise<BoardRecord | null>} get
37
+ * @property {(id: string, patch: Partial<BoardRecord>) => BoardRecord | null | Promise<BoardRecord | null>} update
38
+ */
39
+ /** The default store: one JSON file per board under the relay home, shared with the CLI. */
40
+ export declare function fileStore(): {
41
+ create: (spec: any) => {
42
+ id: string;
43
+ createdAt: string;
44
+ title: any;
45
+ cwd: string;
46
+ spec: any;
47
+ draft: any;
48
+ result: any;
49
+ };
50
+ get: (id: any) => any;
51
+ update(id: any, patch: any): any;
52
+ };
@@ -0,0 +1,5 @@
1
+ /** The server's HMAC key: a random value kept in the relay home, created on first use. */
2
+ export declare function loadServerKey(file?: string): string;
3
+ export declare const boardToken: (key: any, boardId: any) => string;
4
+ /** Constant-time comparison, so a wrong token leaks nothing about the right one. */
5
+ export declare function tokenValid(key: any, boardId: any, token: any): boolean;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Adds the relay tools and the board resource to `server`.
3
+ *
4
+ * @param {any} server an McpServer
5
+ * @param {object} [options]
6
+ * @param {import('./store.js').RelayStore} [options.store] where boards live; defaults to the relay home on disk
7
+ * @param {string | Buffer} [options.tokenKey] the secret behind board tokens; defaults to a key file in the relay home
8
+ * @param {(name: string) => string} [options.assetUrl] URL of a vendor file, for hosts that can fetch it
9
+ * @param {(boardId: string) => string} [options.linkUrl] a URL where a person can open the board outside the host
10
+ * @returns the app-only tools, so a server can hide them from a client that cannot render the board
11
+ */
12
+ export declare function registerRelay(server: any, options?: {
13
+ store?: import('./store.js').RelayStore;
14
+ tokenKey?: string | Buffer;
15
+ assetUrl?: (name: string) => string;
16
+ linkUrl?: (boardId: string) => string;
17
+ }): any[];
@@ -0,0 +1,10 @@
1
+ export declare const ARTIFACT_MAX_BYTES: number;
2
+ export declare const ARTIFACT_MIMES: {
3
+ 'image/png': string;
4
+ 'image/jpeg': string;
5
+ 'image/webp': string;
6
+ };
7
+ export declare function artifactBytesMatch(mime: any, bytes: any): boolean;
8
+ export declare function runOnResult(cmd: any, result: any, { quiet }?: {
9
+ quiet?: boolean;
10
+ }): void;
@@ -0,0 +1,6 @@
1
+ export declare function sanitizeAnnotations(value: any, boardId: any): any[];
2
+ export declare function sanitizeBlockEdits(value: any): {};
3
+ export declare function findBlock(spec: any, blockId: any, type: any): any;
4
+ export declare function findHtmlBlock(spec: any, blockId: any): any;
5
+ export declare function firstBoardHtml(spec: any): any;
6
+ export declare function firstQuestionHtml(q: any): any;
@@ -1,4 +1,4 @@
1
- export declare function normalizeChartBlock(rawBlock: any, id: any, cwd: any, where: any, hasHeight: any): {
1
+ export declare function normalizeChartBlock(raw: any, id: any, cwd: any, where: any, hasHeight: any): {
2
2
  id: any;
3
3
  type: string;
4
4
  };
@@ -29,6 +29,20 @@ export declare const ALIASES: {
29
29
  distribute: string;
30
30
  points: string;
31
31
  };
32
+ export declare const BLOCK_ALIASES: {
33
+ md: string;
34
+ img: string;
35
+ picture: string;
36
+ flowchart: string;
37
+ diagram: string;
38
+ stats: string;
39
+ metrics: string;
40
+ widget: string;
41
+ patch: string;
42
+ swatches: string;
43
+ };
44
+ export declare const CHART_KIND_FIELDS: string[];
45
+ export declare const CHART_SERIES_FIELDS: string[];
32
46
  export declare const HTML_HEIGHT: {
33
47
  min: number;
34
48
  max: number;
@@ -2,3 +2,4 @@ export { TYPES, BLOCK_TYPES } from './constants.js';
2
2
  export { assertSpecReady } from './ready.js';
3
3
  export { normalizeSpec, questionFromInline } from './normalize.js';
4
4
  export { SPEC_SCHEMA } from './schema.js';
5
+ export { lookupSchema } from './lookup.js';