@ramme-io/devkit 0.3.2 → 0.4.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/README.md CHANGED
@@ -23,8 +23,9 @@ That gives you the `ramme` command. Or run it without installing, as
23
23
  ## Get a token
24
24
 
25
25
  On ramme.io, open **Settings → Access tokens** and make one. Tick **See my
26
- boards** and **Send apps to my boards**, choose how long it lasts, and copy it
27
- — it is shown once. Then either save it:
26
+ boards** and **Send apps to my boards** (and **See my saved apps** and **Save
27
+ apps to my account** for an agent that should keep what it writes), choose how
28
+ long it lasts, and copy it — it is shown once. Then either save it:
28
29
 
29
30
  ```bash
30
31
  ramme login --token rmk_…
@@ -80,7 +81,14 @@ validate before sending:
80
81
  - `ramme_board_parts`: what one board has plugged in, whether each part works,
81
82
  and each sensor's latest reading as a Signal (a temperature probe's
82
83
  `temperature` in °C, say), plus its settings and the apps it holds.
83
- - `ramme_send_app`: sends a validated app to a board, by id or name.
84
+ - `ramme_send_app`: sends a validated app to a board, by id or name: a
85
+ document written out, or one saved to your account.
86
+ - `ramme_save_app`: saves a validated app to your account, under its id, so
87
+ it outlives the board it went to and can go to any of yours. Saving an app
88
+ with the same id again replaces it. It needs a token that can save apps.
89
+ - `ramme_list_apps`, `ramme_get_app`: what is saved, and one app's document
90
+ to edit. They need a token that can see saved apps.
91
+ - `ramme_delete_app`: removes one saved app. Boards keep their copy.
84
92
  - `ramme_configure_board`: changes a board's settings: its name, whether its
85
93
  screen's light and dark are swapped, which of its apps is on show, and how
86
94
  often they take turns. It needs a token that can change settings.
@@ -42,6 +42,7 @@ var RammeApiError = class extends Error {
42
42
  this.code = code;
43
43
  }
44
44
  };
45
+ var NO_LIBRARY = "This server keeps no saved apps \u2014 ramme.io does. Send the app to a board instead.";
45
46
  var HINTS = {
46
47
  NOT_SIGNED_IN: "No working token. Make one on ramme.io under Settings \u2192 Access tokens (or use the one your own server printed), then run `ramme login` or set RAMME_TOKEN.",
47
48
  TOKEN_SCOPE: "",
@@ -86,9 +87,32 @@ var createClient = (options) => {
86
87
  },
87
88
  send: async (deviceId, document) => await call("POST", "/api/device/send", { deviceId, document }),
88
89
  rename: async (deviceId, label) => await call("PATCH", "/api/device/claim", { deviceId, label }),
89
- change: async (deviceId, change) => await call("POST", "/api/device/shelf", { deviceId, ...change })
90
+ change: async (deviceId, change) => await call("POST", "/api/device/shelf", { deviceId, ...change }),
91
+ savedApps: async () => (await library(() => call("GET", "/api/account/apps"))).apps,
92
+ savedApp: async (id) => (await library(() => call("GET", `/api/account/apps?id=${encodeURIComponent(id)}`))).app,
93
+ saveApp: async (document) => await library(() => call("PUT", "/api/account/apps", { document })),
94
+ deleteApp: async (id) => {
95
+ await library(() => call("DELETE", `/api/account/apps?id=${encodeURIComponent(id)}`));
96
+ }
90
97
  };
91
98
  };
99
+ var library = async (run) => {
100
+ try {
101
+ return await run();
102
+ } catch (e) {
103
+ if (e instanceof RammeApiError && (e.code === "HTTP_404" || e.code === "NOT_FOUND")) throw new RammeApiError(404, "NO_LIBRARY", NO_LIBRARY);
104
+ throw e;
105
+ }
106
+ };
107
+ var resolveSavedApp = (apps, said) => {
108
+ const want = said.trim().toLowerCase();
109
+ const byId = apps.find((a) => a.id === want);
110
+ if (byId) return byId;
111
+ const named = apps.filter((a) => a.name.trim().toLowerCase() === want);
112
+ if (named.length === 1) return named[0];
113
+ if (named.length > 1) throw new RammeApiError(400, "AMBIGUOUS", `More than one saved app is called \u201C${said}\u201D: ${named.map((a) => a.id).join(", ")}. Use its id.`);
114
+ throw new RammeApiError(404, "NO_SUCH_APP", `No saved app is called that. Saved: ${apps.map((a) => `\u201C${a.name}\u201D (${a.id})`).join("; ") || "none"}.`);
115
+ };
92
116
  var resolveBoard = (boards, said) => {
93
117
  const want = said.trim();
94
118
  const byId = boards.find((b) => b.deviceId === want.toUpperCase());
@@ -143,7 +167,9 @@ var INSTRUCTIONS = [
143
167
  "Call ramme_app_guide first: it is the format, with its limits.",
144
168
  "Check every app with ramme_validate_app before sending it, and fix what it reports.",
145
169
  "ramme_list_boards shows the boards this token can reach; ramme_board_parts shows what one has plugged in and what its sensors last read;",
146
- "ramme_send_app sends an app to one, by id or by name; ramme_configure_board renames one, swaps its light and dark, puts one of its apps on show or sets how often they rotate.",
170
+ "ramme_send_app sends an app to one, by id or by name, written out or saved; ramme_configure_board renames one, swaps its light and dark, puts one of its apps on show or sets how often they rotate.",
171
+ "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
+ "Save an app the owner will want again: one only sent lives on that board alone.",
147
173
  "Installing firmware and claiming or releasing a board are the owner\u2019s, on the board\u2019s page \u2014 no tool does them.",
148
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."
149
175
  ].join(" ");
@@ -176,11 +202,45 @@ var TOOLS = [
176
202
  },
177
203
  {
178
204
  name: "ramme_send_app",
179
- description: "Send a validated app to one of the owner\u2019s boards, by its id (8 characters) or its name. Needs a token that can send apps.",
205
+ description: "Send an app to one of the owner\u2019s boards, by its id (8 characters) or its name: a document written out, or an app saved to the account by its id or name. Needs a token that can send apps, and to send a saved one, see saved apps.",
180
206
  inputSchema: {
181
207
  type: "object",
182
- properties: { board: { type: "string", description: "The board\u2019s id or its name." }, document: DOCUMENT },
183
- required: ["board", "document"],
208
+ properties: {
209
+ board: { type: "string", description: "The board\u2019s id or its name." },
210
+ document: DOCUMENT,
211
+ app: { type: "string", description: "Instead of document: a saved app\u2019s id or name (ramme_list_apps)." }
212
+ },
213
+ required: ["board"],
214
+ additionalProperties: false
215
+ }
216
+ },
217
+ {
218
+ name: "ramme_save_app",
219
+ 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.",
220
+ inputSchema: { type: "object", properties: { document: DOCUMENT }, required: ["document"], additionalProperties: false }
221
+ },
222
+ {
223
+ name: "ramme_list_apps",
224
+ description: "List the apps saved to the owner\u2019s account: name, id, and when each was last saved. Needs a token that can see saved apps.",
225
+ inputSchema: { type: "object", properties: {}, additionalProperties: false }
226
+ },
227
+ {
228
+ name: "ramme_get_app",
229
+ description: "One saved app\u2019s document, by its id or name, to read or edit and save again. Needs a token that can see saved apps.",
230
+ inputSchema: {
231
+ type: "object",
232
+ properties: { app: { type: "string", description: "The saved app\u2019s id or its name." } },
233
+ required: ["app"],
234
+ additionalProperties: false
235
+ }
236
+ },
237
+ {
238
+ name: "ramme_delete_app",
239
+ description: "Delete one saved app from the owner\u2019s account, by its id or name. Boards it was sent to keep their copy. Needs a token that can save apps.",
240
+ inputSchema: {
241
+ type: "object",
242
+ properties: { app: { type: "string", description: "The saved app\u2019s id or its name." } },
243
+ required: ["app"],
184
244
  additionalProperties: false
185
245
  }
186
246
  },
@@ -269,7 +329,14 @@ var callTool = async (client, name, args = {}) => {
269
329
  return text(describeParts(`${board.label ?? "(unnamed)"} \u2014 ${board.deviceId}`, await client.parts(board.deviceId)));
270
330
  }
271
331
  case "ramme_send_app": {
272
- const v = validateApp(args.document);
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);
273
340
  if (!v.ok) return text(`Not sent. ${describeValidation(v)}`, true);
274
341
  const board = resolveBoard(await client.boards(), String(args.board ?? ""));
275
342
  const sent = await client.send(board.deviceId, v.document);
@@ -277,6 +344,26 @@ var callTool = async (client, name, args = {}) => {
277
344
  [`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(" ")
278
345
  );
279
346
  }
347
+ case "ramme_save_app": {
348
+ const v = validateApp(args.document);
349
+ if (!v.ok) return text(`Not saved. ${describeValidation(v)}`, true);
350
+ const saved = await client.saveApp(v.document);
351
+ return text(`${saved.replaced ? "Saved over" : "Saved"} \u201C${saved.app.name}\u201D (${saved.app.id}) on the account. Send it with ramme_send_app and app: "${saved.app.id}".`);
352
+ }
353
+ case "ramme_list_apps": {
354
+ const apps = await client.savedApps();
355
+ if (!apps.length) return text("No saved apps yet. Save one with ramme_save_app.");
356
+ return text(apps.map((a) => `${a.name} \u2014 ${a.id} \u2014 saved ${ago(a.updatedAt)}`).join("\n"));
357
+ }
358
+ case "ramme_get_app": {
359
+ const saved = resolveSavedApp(await client.savedApps(), String(args.app ?? ""));
360
+ return text(JSON.stringify((await client.savedApp(saved.id)).document, null, 2));
361
+ }
362
+ case "ramme_delete_app": {
363
+ const saved = resolveSavedApp(await client.savedApps(), String(args.app ?? ""));
364
+ await client.deleteApp(saved.id);
365
+ return text(`Deleted the saved app \u201C${saved.name}\u201D (${saved.id}). Boards it was sent to keep their copy.`);
366
+ }
280
367
  case "ramme_configure_board": {
281
368
  const board = resolveBoard(await client.boards(), String(args.board ?? ""));
282
369
  const plan = plannedChanges(args, await client.parts(board.deviceId));
@@ -360,6 +447,7 @@ export {
360
447
  forgetToken,
361
448
  RammeApiError,
362
449
  createClient,
450
+ resolveSavedApp,
363
451
  resolveBoard,
364
452
  ago,
365
453
  validateApp,
package/dist/cli.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  serveMcp,
15
15
  serverLabel,
16
16
  validateAppText
17
- } from "./chunk-IEPOKHAT.js";
17
+ } from "./chunk-Y7Q727ZC.js";
18
18
 
19
19
  // src/cli.ts
20
20
  import { readFileSync, realpathSync } from "fs";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AppDocument, DeviceFeatureState, Signal } from '@ramme-io/shared';
1
+ import { AppDocument, DeviceFeatureState, Signal, SavedAppSummary, SavedApp } from '@ramme-io/shared';
2
2
  import { Readable, Writable } from 'node:stream';
3
3
 
4
4
  /**
@@ -26,7 +26,8 @@ declare const describeValidation: (v: Validation) => string;
26
26
  /**
27
27
  * The few ramme.io routes a personal access token can reach: list your
28
28
  * boards and read one's parts and readings (`boards:read`), send one an
29
- * app (`boards:send`), and change its settings (`boards:configure`). Everything is
29
+ * app (`boards:send`), change its settings (`boards:configure`), and keep
30
+ * apps on your account (`apps:read`, `apps:write`). Everything is
30
31
  * authorised by the token; nothing here calls a model, so an agent's own keys
31
32
  * do all the generating.
32
33
  */
@@ -95,12 +96,26 @@ interface Client {
95
96
  change(deviceId: string, change: ShelfChange): Promise<{
96
97
  revision?: number;
97
98
  }>;
99
+ /** The apps saved to the account, newest change first. */
100
+ savedApps(): Promise<SavedAppSummary[]>;
101
+ savedApp(id: string): Promise<SavedApp>;
102
+ /** Saved under document.id: an app already there by that id is replaced. */
103
+ saveApp(document: AppDocument): Promise<{
104
+ app: SavedAppSummary;
105
+ replaced: boolean;
106
+ }>;
107
+ deleteApp(id: string): Promise<void>;
98
108
  }
99
109
  declare const createClient: (options: {
100
110
  base: string;
101
111
  token: string | null;
102
112
  fetch?: typeof fetch;
103
113
  }) => Client;
114
+ /**
115
+ * A saved app by its id or its name, as resolveBoard finds a board. Refuses
116
+ * an ambiguous name rather than guessing.
117
+ */
118
+ declare const resolveSavedApp: (apps: SavedAppSummary[], said: string) => SavedAppSummary;
104
119
  /**
105
120
  * A board by its id or its name, as a person or an agent would say it:
106
121
  * "A7K2M9QP", or "Kitchen shelf" in any case. Refuses an ambiguous name
@@ -171,7 +186,7 @@ declare const TOOLS: readonly [{
171
186
  };
172
187
  }, {
173
188
  readonly name: "ramme_send_app";
174
- readonly description: "Send a validated app to one of the owner’s boards, by its id (8 characters) or its name. Needs a token that can send apps.";
189
+ readonly description: "Send an app to one of the owner’s boards, by its id (8 characters) or its name: a document written out, or an app saved to the account by its id or name. Needs a token that can send apps, and to send a saved one, see saved apps.";
175
190
  readonly inputSchema: {
176
191
  readonly type: "object";
177
192
  readonly properties: {
@@ -183,8 +198,62 @@ declare const TOOLS: readonly [{
183
198
  type: string;
184
199
  description: string;
185
200
  };
201
+ readonly app: {
202
+ readonly type: "string";
203
+ readonly description: "Instead of document: a saved app’s id or name (ramme_list_apps).";
204
+ };
205
+ };
206
+ readonly required: readonly ["board"];
207
+ readonly additionalProperties: false;
208
+ };
209
+ }, {
210
+ readonly name: "ramme_save_app";
211
+ 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.";
212
+ readonly inputSchema: {
213
+ readonly type: "object";
214
+ readonly properties: {
215
+ readonly document: {
216
+ type: string;
217
+ description: string;
218
+ };
219
+ };
220
+ readonly required: readonly ["document"];
221
+ readonly additionalProperties: false;
222
+ };
223
+ }, {
224
+ readonly name: "ramme_list_apps";
225
+ readonly description: "List the apps saved to the owner’s account: name, id, and when each was last saved. Needs a token that can see saved apps.";
226
+ readonly inputSchema: {
227
+ readonly type: "object";
228
+ readonly properties: {};
229
+ readonly additionalProperties: false;
230
+ };
231
+ }, {
232
+ readonly name: "ramme_get_app";
233
+ readonly description: "One saved app’s document, by its id or name, to read or edit and save again. Needs a token that can see saved apps.";
234
+ readonly inputSchema: {
235
+ readonly type: "object";
236
+ readonly properties: {
237
+ readonly app: {
238
+ readonly type: "string";
239
+ readonly description: "The saved app’s id or its name.";
240
+ };
241
+ };
242
+ readonly required: readonly ["app"];
243
+ readonly additionalProperties: false;
244
+ };
245
+ }, {
246
+ readonly name: "ramme_delete_app";
247
+ readonly description: "Delete one saved app from the owner’s account, by its id or name. Boards it was sent to keep their copy. Needs a token that can save apps.";
248
+ readonly inputSchema: {
249
+ readonly type: "object";
250
+ readonly properties: {
251
+ readonly app: {
252
+ readonly type: "string";
253
+ readonly description: "The saved app’s id or its name.";
254
+ };
186
255
  };
187
- readonly required: readonly ["board", "document"];
256
+ readonly required: readonly ["app"];
188
257
  readonly additionalProperties: false;
189
258
  };
190
259
  }, {
@@ -227,4 +296,4 @@ declare const handleMessage: (client: Client, message: Json) => Promise<Json | n
227
296
  /** Serve until stdin closes. */
228
297
  declare const serveMcp: (client: Client, input?: Readable, output?: Writable) => Promise<void>;
229
298
 
230
- export { type Board, type BoardShelf, type Client, DEFAULT_API, RammeApiError, SERVER_INFO, type SendResult, type ShelfChange, TOOLS, type Validation, apiBase, callTool, createClient, credentialsPath, describeValidation, findToken, forgetToken, handleMessage, resolveBoard, saveToken, serveMcp, validateApp, validateAppText };
299
+ export { type Board, type BoardShelf, type Client, DEFAULT_API, RammeApiError, SERVER_INFO, type SendResult, type ShelfChange, TOOLS, type Validation, apiBase, callTool, createClient, credentialsPath, describeValidation, findToken, forgetToken, handleMessage, resolveBoard, resolveSavedApp, saveToken, serveMcp, validateApp, validateAppText };
package/dist/index.js CHANGED
@@ -12,11 +12,12 @@ import {
12
12
  forgetToken,
13
13
  handleMessage,
14
14
  resolveBoard,
15
+ resolveSavedApp,
15
16
  saveToken,
16
17
  serveMcp,
17
18
  validateApp,
18
19
  validateAppText
19
- } from "./chunk-IEPOKHAT.js";
20
+ } from "./chunk-Y7Q727ZC.js";
20
21
  export {
21
22
  DEFAULT_API,
22
23
  RammeApiError,
@@ -31,6 +32,7 @@ export {
31
32
  forgetToken,
32
33
  handleMessage,
33
34
  resolveBoard,
35
+ resolveSavedApp,
34
36
  saveToken,
35
37
  serveMcp,
36
38
  validateApp,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramme-io/devkit",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
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,7 +31,7 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "@ramme-io/shared": "4.4.0"
34
+ "@ramme-io/shared": "4.5.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "^20.14.10",