@khanglvm/relay 0.20.3 → 0.22.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 (73) hide show
  1. package/README.md +1 -1
  2. package/docs/AGENT.md +35 -62
  3. package/docs/SETUP.md +3 -2
  4. package/package.json +17 -5
  5. package/schema/spec.v1.json +55 -3
  6. package/skills/relay/SKILL.md +5 -2
  7. package/src/a2ui/board-catalog.json +1004 -0
  8. package/src/a2ui/board-constants.js +35 -0
  9. package/src/a2ui/board.js +5 -0
  10. package/src/a2ui/from-a2ui.js +71 -0
  11. package/src/a2ui/negotiate.js +38 -0
  12. package/src/a2ui/to-a2ui.js +147 -0
  13. package/src/cli/args.js +1 -1
  14. package/src/cli/help.js +2 -1
  15. package/src/cli/mcp.js +23 -3
  16. package/src/mcp/boards.js +195 -0
  17. package/src/mcp/config.js +20 -0
  18. package/src/mcp/constants.js +33 -0
  19. package/src/mcp/index.js +5 -0
  20. package/src/mcp/page.js +59 -0
  21. package/src/mcp/schemas.js +45 -0
  22. package/src/mcp/serve.js +116 -0
  23. package/src/mcp/server.js +24 -0
  24. package/src/mcp/store.js +35 -0
  25. package/src/mcp/token.js +56 -0
  26. package/src/mcp/tools.js +179 -0
  27. package/src/mcp-ui/board/block-ctx.js +22 -0
  28. package/src/mcp-ui/board/bridge.js +12 -2
  29. package/src/mcp-ui/board/core.js +2 -0
  30. package/src/mcp-ui/board/lifecycle.js +47 -9
  31. package/src/mcp-ui/board/normalize.js +12 -0
  32. package/src/mcp-ui/board/render.js +38 -45
  33. package/src/mcp-ui/board/state.js +3 -0
  34. package/src/mcp-ui/board/vendors.js +56 -11
  35. package/src/server/board.js +12 -9
  36. package/src/server/http.js +19 -0
  37. package/src/server/page.js +4 -0
  38. package/src/spec/constants.js +13 -1
  39. package/src/spec/index.js +1 -0
  40. package/src/spec/lookup.js +1 -0
  41. package/src/spec/normalize.js +3 -0
  42. package/src/spec/pick.js +104 -0
  43. package/src/spec/schema.js +26 -3
  44. package/src/ui/app/drafts.js +3 -0
  45. package/src/ui/app/render.js +1 -0
  46. package/src/ui/app/submit.js +1 -1
  47. package/src/ui/manifest.js +3 -2
  48. package/src/ui/pick.css +32 -0
  49. package/src/ui/pick.js +246 -0
  50. package/types/a2ui/board-constants.d.ts +24 -0
  51. package/types/a2ui/from-a2ui.d.ts +16 -0
  52. package/types/a2ui/negotiate.d.ts +17 -0
  53. package/types/a2ui/to-a2ui.d.ts +12 -0
  54. package/types/cli/agent-topics.d.ts +46 -0
  55. package/types/mcp/boards.d.ts +178 -0
  56. package/types/{mcp.d.ts → mcp/config.d.ts} +1 -8
  57. package/types/mcp/constants.d.ts +21 -0
  58. package/types/mcp/index.d.ts +4 -0
  59. package/types/mcp/page.d.ts +27 -0
  60. package/types/mcp/schemas.d.ts +49 -0
  61. package/types/mcp/serve.d.ts +16 -0
  62. package/types/mcp/server.d.ts +4 -0
  63. package/types/mcp/store.d.ts +52 -0
  64. package/types/mcp/token.d.ts +9 -0
  65. package/types/mcp/tools.d.ts +17 -0
  66. package/types/server/result.d.ts +10 -0
  67. package/types/server/sanitize.d.ts +6 -0
  68. package/types/spec/constants.d.ts +9 -0
  69. package/types/spec/index.d.ts +1 -0
  70. package/types/spec/lookup.d.ts +2 -1
  71. package/types/spec/pick.d.ts +25 -0
  72. package/types/spec/schema.d.ts +48 -0
  73. package/src/mcp.js +0 -483
@@ -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,49 @@
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
+ /** A widget button click (`blockId`, `name`, `context`), or a renderer event (`action`, plus the surface's `dataModel`). */
27
+ export declare const actionInput: z.ZodObject<{
28
+ boardId: z.ZodString;
29
+ token: z.ZodString;
30
+ blockId: z.ZodOptional<z.ZodString>;
31
+ name: z.ZodOptional<z.ZodString>;
32
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
33
+ action: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
34
+ dataModel: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
35
+ }, z.core.$strip>;
36
+ export declare const assetInput: z.ZodObject<{
37
+ name: z.ZodString;
38
+ index: z.ZodDefault<z.ZodNumber>;
39
+ }, z.core.$strip>;
40
+ export declare const helpInput: z.ZodObject<{
41
+ topic: z.ZodOptional<z.ZodEnum<{
42
+ [x: string]: string;
43
+ }>>;
44
+ schema: z.ZodOptional<z.ZodString>;
45
+ }, z.core.$strip>;
46
+ export declare const resultInput: z.ZodObject<{
47
+ boardId: z.ZodString;
48
+ wait_seconds: z.ZodOptional<z.ZodNumber>;
49
+ }, 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,9 @@
1
+ /**
2
+ * The server's HMAC key: a random value kept in the relay home, created on first use.
3
+ * Two servers starting together both try to create it; the exclusive create lets one
4
+ * win and the other read what the winner wrote, so they never hold different keys.
5
+ */
6
+ export declare function loadServerKey(file?: string): string;
7
+ export declare const boardToken: (key: any, boardId: any) => string;
8
+ /** Constant-time comparison, so a wrong token leaks nothing about the right one. */
9
+ 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;
@@ -28,6 +28,9 @@ export declare const ALIASES: {
28
28
  budget: string;
29
29
  distribute: string;
30
30
  points: string;
31
+ tiles: string;
32
+ gallery: string;
33
+ shortlist: string;
31
34
  };
32
35
  export declare const BLOCK_ALIASES: {
33
36
  md: string;
@@ -79,3 +82,9 @@ export declare const IMAGE_MIMES: {
79
82
  bmp: string;
80
83
  };
81
84
  export declare const IMAGE_MAX_BYTES: number;
85
+ export declare const PICK: {
86
+ maxItems: number;
87
+ maxImageBytes: number;
88
+ maxNoteChars: number;
89
+ maxOverallChars: number;
90
+ };
@@ -3,3 +3,4 @@ export { assertSpecReady } from './ready.js';
3
3
  export { normalizeSpec, questionFromInline } from './normalize.js';
4
4
  export { SPEC_SCHEMA } from './schema.js';
5
5
  export { lookupSchema } from './lookup.js';
6
+ export { cleanAnswers, cleanPick } from './pick.js';
@@ -29,6 +29,7 @@ export declare const QUESTION_FIELDS: {
29
29
  rank: string[];
30
30
  checklist: string[];
31
31
  allocate: string[];
32
+ pick: string[];
32
33
  };
33
34
  /** The property names the schema defines for blocks and for questions. */
34
35
  export declare function schemaFieldNames(): {
@@ -41,12 +42,12 @@ export declare function schemaFieldNames(): {
41
42
  * collides today; a block wins if one ever does.
42
43
  */
43
44
  export declare function lookupSchema(name: any): {
45
+ required?: undefined;
44
46
  kind: string;
45
47
  type: string;
46
48
  fields: {
47
49
  [k: string]: any;
48
50
  };
49
- required?: undefined;
50
51
  } | {
51
52
  kind: string;
52
53
  type: string;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Adds the pick fields to a normalized question: `items`, `min`, `max`, `itemNote`, `overall`.
3
+ * The generic per-question note stays off: a pick carries its own notes.
4
+ * @param {Record<string, any>} q the question being built
5
+ * @param {Record<string, any>} rq what the agent wrote
6
+ */
7
+ export declare function normalizePick(q: Record<string, any>, rq: Record<string, any>, where: any, cwd: any): void;
8
+ /**
9
+ * The answer to a pick question, cut down to what the question allows: known ids
10
+ * once each, at most `max` of them in the order picked, notes only when the tiles
11
+ * take them. Returns undefined when nothing is left, which reads as skipped.
12
+ * @returns {{ picks: Array<{ id: string, note?: string }>, overall?: string } | undefined}
13
+ */
14
+ export declare function cleanPick(q: any, value: any): {
15
+ picks: Array<{
16
+ id: string;
17
+ note?: string;
18
+ }>;
19
+ overall?: string;
20
+ } | undefined;
21
+ /**
22
+ * A copy of a board's answers in which every pick answer is cleaned. Other
23
+ * answers pass through as sent, which is how every board already treats them.
24
+ */
25
+ export declare function cleanAnswers(spec: any, answers: any): any;
@@ -747,6 +747,54 @@ export declare const SPEC_SCHEMA: {
747
747
  })[];
748
748
  };
749
749
  };
750
+ items: {
751
+ type: string;
752
+ description: string;
753
+ items: {
754
+ anyOf: ({
755
+ properties?: undefined;
756
+ type: string;
757
+ required?: undefined;
758
+ } | {
759
+ type: string;
760
+ required: string[];
761
+ properties: {
762
+ id: {
763
+ type: string;
764
+ description: string;
765
+ };
766
+ title: {
767
+ type: string;
768
+ };
769
+ caption: {
770
+ type: string;
771
+ };
772
+ image: {
773
+ type: string;
774
+ description: string;
775
+ };
776
+ video: {
777
+ type: string;
778
+ description: string;
779
+ };
780
+ url: {
781
+ type: string;
782
+ description: string;
783
+ };
784
+ };
785
+ })[];
786
+ };
787
+ };
788
+ itemNote: {
789
+ type: string;
790
+ default: boolean;
791
+ description: string;
792
+ };
793
+ overall: {
794
+ type: string;
795
+ default: boolean;
796
+ description: string;
797
+ };
750
798
  other: {
751
799
  type: string;
752
800
  description: string;