@ramme-io/devkit 0.4.0 → 0.5.1

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.
@@ -159,6 +159,88 @@ ${v.issues.map((i) => ` - ${i}`).join("\n")}`;
159
159
  import { createRequire } from "module";
160
160
  import { createInterface } from "readline";
161
161
  import { APP_DOCUMENT_SYSTEM_PROMPT } from "@ramme-io/shared";
162
+
163
+ // src/approve.ts
164
+ import { randomUUID } from "crypto";
165
+ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
166
+
167
+ // src/approveProtocol.ts
168
+ var APPROVE = {
169
+ resourceUri: "ui://ramme/approve",
170
+ mimeType: "text/html;profile=mcp-app",
171
+ catalogId: "https://ramme.io/a2ui/catalog/v1",
172
+ surfaceId: "ramme-approve",
173
+ proposeTool: "ramme_propose_app",
174
+ approveTool: "ramme_approve_send",
175
+ /** The surface's Send button raises this action; the view answers it with approveTool. */
176
+ approveAction: "approve"
177
+ };
178
+
179
+ // src/approve.ts
180
+ var PROPOSAL_TTL_MS = 10 * 6e4;
181
+ var pending = /* @__PURE__ */ new Map();
182
+ var boardName = (b) => b.label ? `${b.label} (${b.deviceId})` : b.deviceId;
183
+ var propose = (board, document, now = Date.now()) => {
184
+ for (const [id2, p] of pending) if (p.expiresAt <= now) pending.delete(id2);
185
+ const id = randomUUID();
186
+ pending.set(id, { deviceId: board.deviceId, boardName: boardName(board), document, expiresAt: now + PROPOSAL_TTL_MS });
187
+ return id;
188
+ };
189
+ var take = (id, now = Date.now()) => {
190
+ const p = pending.get(id);
191
+ pending.delete(id);
192
+ return p && p.expiresAt > now ? p : null;
193
+ };
194
+ var proposalSurface = (proposalId, p) => [
195
+ { version: "1.0", createSurface: { surfaceId: APPROVE.surfaceId, catalogId: APPROVE.catalogId } },
196
+ {
197
+ version: "1.0",
198
+ updateComponents: {
199
+ surfaceId: APPROVE.surfaceId,
200
+ components: [
201
+ { id: "root", component: "Column", children: ["title", "preview", "target", "buttons", "status"] },
202
+ { id: "title", component: "Text", text: { "@path": "/document/name" } },
203
+ { id: "preview", component: "BoardPreview", document: { "@path": "/document" } },
204
+ { id: "target", component: "Text", text: { "@path": "/target" } },
205
+ { id: "buttons", component: "Row", children: ["send"] },
206
+ {
207
+ id: "send",
208
+ component: "Button",
209
+ variant: "primary",
210
+ child: "send_label",
211
+ action: { event: { name: APPROVE.approveAction, context: { proposalId: { "@path": "/proposalId" } } } }
212
+ },
213
+ { id: "send_label", component: "Text", text: "Send to board" },
214
+ { id: "status", component: "Text", variant: "caption", text: { "@path": "/statusText" } }
215
+ ]
216
+ }
217
+ },
218
+ dataModel(proposalId, p, "waiting")
219
+ ];
220
+ var STATUS_TEXT = {
221
+ waiting: "Nothing is sent until you tap Send.",
222
+ sending: "Sending\u2026",
223
+ sent: "Sent. It shows at the board\u2019s next check-in.",
224
+ failed: "Not sent."
225
+ };
226
+ var dataModel = (proposalId, p, status) => ({
227
+ version: "1.0",
228
+ updateDataModel: {
229
+ surfaceId: APPROVE.surfaceId,
230
+ path: "/",
231
+ value: { proposalId, document: p.document, target: `To: ${p.boardName}`, status, statusText: STATUS_TEXT[status] }
232
+ }
233
+ });
234
+ var statusUpdate = (status, detail) => ({
235
+ version: "1.0",
236
+ updateDataModel: { surfaceId: APPROVE.surfaceId, path: "/statusText", value: detail ? `${STATUS_TEXT[status]} ${detail}` : STATUS_TEXT[status] }
237
+ });
238
+ var approveHtml = () => {
239
+ const url = new URL("../dist/app/approve.html", import.meta.url);
240
+ return existsSync2(url) ? readFileSync2(url, "utf8") : null;
241
+ };
242
+
243
+ // src/mcp.ts
162
244
  var { version } = createRequire(import.meta.url)("../package.json");
163
245
  var SERVER_INFO = { name: "ramme", version };
164
246
  var PROTOCOL_VERSION = "2025-06-18";
@@ -171,7 +253,8 @@ var INSTRUCTIONS = [
171
253
  "ramme_save_app keeps an app on the owner\u2019s account, under its id, so saving an edited app again replaces it; ramme_list_apps and ramme_get_app read what is saved, and ramme_delete_app removes one.",
172
254
  "Save an app the owner will want again: one only sent lives on that board alone.",
173
255
  "Installing firmware and claiming or releasing a board are the owner\u2019s, on the board\u2019s page \u2014 no tool does them.",
174
- "A board picks up a new app at its next check-in: within about 30 seconds if someone is using it, 5 minutes if idle."
256
+ "A board picks up a new app at its next check-in: within about 30 seconds if someone is using it, 5 minutes if idle.",
257
+ "Where the host shows interactive cards (Claude Desktop does), prefer ramme_propose_app to ramme_send_app: it shows the owner the app as the board will draw it, and sends only when they tap Send."
175
258
  ].join(" ");
176
259
  var DOCUMENT = { type: "object", description: "The app document, as JSON \u2014 see ramme_app_guide." };
177
260
  var TOOLS = [
@@ -214,6 +297,32 @@ var TOOLS = [
214
297
  additionalProperties: false
215
298
  }
216
299
  },
300
+ {
301
+ name: APPROVE.proposeTool,
302
+ description: "Propose an app for one of the owner\u2019s boards, by its id or name: a document written out, or a saved app by its id or name. The owner sees a card with the app drawn as the board will draw it and sends it with one tap. Nothing is sent by this tool; it only checks the app and shows the card. Needs a token that can see and send to boards.",
303
+ inputSchema: {
304
+ type: "object",
305
+ properties: {
306
+ board: { type: "string", description: "The board\u2019s id or its name." },
307
+ document: DOCUMENT,
308
+ app: { type: "string", description: "Instead of document: a saved app\u2019s id or name (ramme_list_apps)." }
309
+ },
310
+ required: ["board"],
311
+ additionalProperties: false
312
+ },
313
+ _meta: { ui: { resourceUri: APPROVE.resourceUri, visibility: ["model", "app"] } }
314
+ },
315
+ {
316
+ name: APPROVE.approveTool,
317
+ description: "Send a proposed app, from the card the owner tapped. Only the card calls this.",
318
+ inputSchema: {
319
+ type: "object",
320
+ properties: { proposalId: { type: "string", description: "The id the proposal card carries." } },
321
+ required: ["proposalId"],
322
+ additionalProperties: false
323
+ },
324
+ _meta: { ui: { resourceUri: APPROVE.resourceUri, visibility: ["app"] } }
325
+ },
217
326
  {
218
327
  name: "ramme_save_app",
219
328
  description: "Save a validated app to the owner\u2019s account, under its id. An app already saved with that id is replaced, so save an edited app again rather than giving it a new id. Needs a token that can save apps.",
@@ -310,6 +419,17 @@ var describeParts = (name, parts, now = Date.now()) => {
310
419
  return lines.join("\n");
311
420
  };
312
421
  var text = (t, isError = false) => ({ content: [{ type: "text", text: t }], ...isError ? { isError: true } : {} });
422
+ var documentFrom = async (client, args, refused) => {
423
+ if (args.document !== void 0 && args.app !== void 0) return { ok: false, message: `${refused} Give a document or a saved app, not both.` };
424
+ let document = args.document;
425
+ if (args.app !== void 0) {
426
+ const saved = resolveSavedApp(await client.savedApps(), String(args.app));
427
+ document = (await client.savedApp(saved.id)).document;
428
+ }
429
+ if (document === void 0) return { ok: false, message: `${refused} Give a document, or a saved app by its id or name.` };
430
+ const v = validateApp(document);
431
+ return v.ok ? { ok: true, document: v.document } : { ok: false, message: `${refused} ${describeValidation(v)}` };
432
+ };
313
433
  var callTool = async (client, name, args = {}) => {
314
434
  try {
315
435
  switch (name) {
@@ -329,21 +449,47 @@ var callTool = async (client, name, args = {}) => {
329
449
  return text(describeParts(`${board.label ?? "(unnamed)"} \u2014 ${board.deviceId}`, await client.parts(board.deviceId)));
330
450
  }
331
451
  case "ramme_send_app": {
332
- if (args.document !== void 0 && args.app !== void 0) return text("Not sent. Give a document or a saved app, not both.", true);
333
- let document = args.document;
334
- if (args.app !== void 0) {
335
- const saved = resolveSavedApp(await client.savedApps(), String(args.app));
336
- document = (await client.savedApp(saved.id)).document;
337
- }
338
- if (document === void 0) return text("Not sent. Give a document, or a saved app by its id or name.", true);
339
- const v = validateApp(document);
340
- if (!v.ok) return text(`Not sent. ${describeValidation(v)}`, true);
452
+ const v = await documentFrom(client, args, "Not sent.");
453
+ if (!v.ok) return text(v.message, true);
341
454
  const board = resolveBoard(await client.boards(), String(args.board ?? ""));
342
455
  const sent = await client.send(board.deviceId, v.document);
343
456
  return text(
344
457
  [`Sent \u201C${v.document.name}\u201D to ${board.label ?? board.deviceId} (${board.deviceId}), revision ${sent.revision ?? "?"}. It shows at the board\u2019s next check-in.`, sent.message].filter(Boolean).join(" ")
345
458
  );
346
459
  }
460
+ case APPROVE.proposeTool: {
461
+ const v = await documentFrom(client, args, "Nothing proposed.");
462
+ if (!v.ok) return text(v.message, true);
463
+ const board = resolveBoard(await client.boards(), String(args.board ?? ""));
464
+ const proposal = { boardName: boardName(board), document: v.document };
465
+ const id = propose(board, v.document);
466
+ return {
467
+ content: [
468
+ {
469
+ type: "text",
470
+ text: `Proposed \u201C${v.document.name}\u201D for ${proposal.boardName}. The owner sees it on a card and sends it with a tap; nothing is sent until they do. Where no card shows, send it with ramme_send_app once they say so.`
471
+ }
472
+ ],
473
+ structuredContent: { a2ui: proposalSurface(id, proposal) }
474
+ };
475
+ }
476
+ case APPROVE.approveTool: {
477
+ if (!cardHosts.has(client)) return text(`No tool called ${name}.`, true);
478
+ const proposal = take(String(args.proposalId ?? ""));
479
+ if (!proposal) {
480
+ return { ...text("Not sent. That card has expired or was already used; ask for the app again.", true), structuredContent: { a2ui: [statusUpdate("failed", "This card has expired or was already used.")] } };
481
+ }
482
+ try {
483
+ const sent = await client.send(proposal.deviceId, proposal.document);
484
+ return {
485
+ ...text(`Sent \u201C${proposal.document.name}\u201D to ${proposal.boardName}, revision ${sent.revision ?? "?"}. It shows at the board\u2019s next check-in.`),
486
+ structuredContent: { a2ui: [statusUpdate("sent")] }
487
+ };
488
+ } catch (e) {
489
+ const why = e instanceof RammeApiError ? `${e.message} (${e.code})` : e.message;
490
+ return { ...text(`Not sent. ${why}`, true), structuredContent: { a2ui: [statusUpdate("failed", why)] } };
491
+ }
492
+ }
347
493
  case "ramme_save_app": {
348
494
  const v = validateApp(args.document);
349
495
  if (!v.ok) return text(`Not saved. ${describeValidation(v)}`, true);
@@ -396,6 +542,11 @@ var callTool = async (client, name, args = {}) => {
396
542
  return text(message, true);
397
543
  }
398
544
  };
545
+ var cardHosts = /* @__PURE__ */ new WeakSet();
546
+ var showsCards = (params) => {
547
+ const ui = params.capabilities?.extensions?.["io.modelcontextprotocol/ui"];
548
+ return Array.isArray(ui?.mimeTypes) && ui.mimeTypes.includes(APPROVE.mimeType);
549
+ };
399
550
  var handleMessage = async (client, message) => {
400
551
  const id = message.id;
401
552
  const method = String(message.method ?? "");
@@ -404,18 +555,27 @@ var handleMessage = async (client, message) => {
404
555
  if (id === void 0 || id === null) return null;
405
556
  switch (method) {
406
557
  case "initialize":
558
+ if (showsCards(params)) cardHosts.add(client);
559
+ else cardHosts.delete(client);
407
560
  return reply({
408
561
  protocolVersion: typeof params.protocolVersion === "string" ? params.protocolVersion : PROTOCOL_VERSION,
409
- capabilities: { tools: {} },
562
+ capabilities: { tools: {}, resources: {} },
410
563
  serverInfo: SERVER_INFO,
411
564
  instructions: INSTRUCTIONS
412
565
  });
413
566
  case "ping":
414
567
  return reply({});
415
568
  case "tools/list":
416
- return reply({ tools: TOOLS });
569
+ return reply({ tools: cardHosts.has(client) ? TOOLS : TOOLS.filter((t) => t.name !== APPROVE.approveTool) });
417
570
  case "tools/call":
418
571
  return reply(await callTool(client, String(params.name ?? ""), params.arguments ?? {}));
572
+ case "resources/list":
573
+ return reply({ resources: [{ uri: APPROVE.resourceUri, name: "Approve an app for a board", mimeType: APPROVE.mimeType }] });
574
+ case "resources/read": {
575
+ const html = params.uri === APPROVE.resourceUri ? approveHtml() : null;
576
+ if (html === null) return { jsonrpc: "2.0", id, error: { code: -32002, message: `Resource not found: ${String(params.uri)}` } };
577
+ return reply({ contents: [{ uri: APPROVE.resourceUri, mimeType: APPROVE.mimeType, text: html, _meta: { ui: { prefersBorder: true } } }] });
578
+ }
419
579
  default:
420
580
  return { jsonrpc: "2.0", id, error: { code: -32601, message: `Method not found: ${method}` } };
421
581
  }
package/dist/cli.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  serveMcp,
15
15
  serverLabel,
16
16
  validateAppText
17
- } from "./chunk-Y7Q727ZC.js";
17
+ } from "./chunk-NQ2K2FVH.js";
18
18
 
19
19
  // src/cli.ts
20
20
  import { readFileSync, realpathSync } from "fs";
package/dist/index.d.ts CHANGED
@@ -206,6 +206,54 @@ declare const TOOLS: readonly [{
206
206
  readonly required: readonly ["board"];
207
207
  readonly additionalProperties: false;
208
208
  };
209
+ }, {
210
+ readonly name: "ramme_propose_app";
211
+ readonly description: "Propose an app for one of the owner’s boards, by its id or name: a document written out, or a saved app by its id or name. The owner sees a card with the app drawn as the board will draw it and sends it with one tap. Nothing is sent by this tool; it only checks the app and shows the card. Needs a token that can see and send to boards.";
212
+ readonly inputSchema: {
213
+ readonly type: "object";
214
+ readonly properties: {
215
+ readonly board: {
216
+ readonly type: "string";
217
+ readonly description: "The board’s id or its name.";
218
+ };
219
+ readonly document: {
220
+ type: string;
221
+ description: string;
222
+ };
223
+ readonly app: {
224
+ readonly type: "string";
225
+ readonly description: "Instead of document: a saved app’s id or name (ramme_list_apps).";
226
+ };
227
+ };
228
+ readonly required: readonly ["board"];
229
+ readonly additionalProperties: false;
230
+ };
231
+ readonly _meta: {
232
+ readonly ui: {
233
+ readonly resourceUri: "ui://ramme/approve";
234
+ readonly visibility: readonly ["model", "app"];
235
+ };
236
+ };
237
+ }, {
238
+ readonly name: "ramme_approve_send";
239
+ readonly description: "Send a proposed app, from the card the owner tapped. Only the card calls this.";
240
+ readonly inputSchema: {
241
+ readonly type: "object";
242
+ readonly properties: {
243
+ readonly proposalId: {
244
+ readonly type: "string";
245
+ readonly description: "The id the proposal card carries.";
246
+ };
247
+ };
248
+ readonly required: readonly ["proposalId"];
249
+ readonly additionalProperties: false;
250
+ };
251
+ readonly _meta: {
252
+ readonly ui: {
253
+ readonly resourceUri: "ui://ramme/approve";
254
+ readonly visibility: readonly ["app"];
255
+ };
256
+ };
209
257
  }, {
210
258
  readonly name: "ramme_save_app";
211
259
  readonly description: "Save a validated app to the owner’s account, under its id. An app already saved with that id is replaced, so save an edited app again rather than giving it a new id. Needs a token that can save apps.";
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  serveMcp,
18
18
  validateApp,
19
19
  validateAppText
20
- } from "./chunk-Y7Q727ZC.js";
20
+ } from "./chunk-NQ2K2FVH.js";
21
21
  export {
22
22
  DEFAULT_API,
23
23
  RammeApiError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramme-io/devkit",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Make Ramme apps on your own machine with your own coding agent: validate an app, list your boards, send it to one — as a CLI or a local MCP server.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://www.ramme.io",
@@ -31,19 +31,32 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "@ramme-io/shared": "4.5.0"
34
+ "@ramme-io/shared": "4.7.0"
35
35
  },
36
36
  "devDependencies": {
37
+ "@a2ui/markdown-it": "0.2.2",
38
+ "@a2ui/react": "0.15.0",
39
+ "@a2ui/web_core": "0.15.0",
37
40
  "@types/node": "^20.14.10",
41
+ "@types/react": "^18",
42
+ "@types/react-dom": "^18",
43
+ "@vitejs/plugin-react": "^4.3.1",
44
+ "react": "^18.2.0",
45
+ "react-dom": "^18.2.0",
38
46
  "tsup": "^8.5.1",
39
47
  "tsx": "4.21.0",
40
48
  "typescript": "^5.4.5",
41
- "vitest": "^2.1.9"
49
+ "vite": "^5.4.21",
50
+ "vite-plugin-singlefile": "2.3.4",
51
+ "vitest": "^2.1.9",
52
+ "zod": "^3.25.76",
53
+ "@ramme-io/kernel": "^8.1.7",
54
+ "@ramme-io/ui": "^5.5.1"
42
55
  },
43
56
  "scripts": {
44
- "build": "tsup src/cli.ts src/index.ts --format esm --dts --clean --target node20",
57
+ "build": "vite build -c vite.app.config.ts && tsup src/cli.ts src/index.ts --format esm --dts --target node20",
45
58
  "ramme": "tsx src/cli.ts",
46
59
  "test": "vitest run",
47
- "typecheck": "tsc --noEmit -p tsconfig.json"
60
+ "typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p app/tsconfig.json"
48
61
  }
49
62
  }