@joe-broadhead/opencode-mem 0.6.1 → 0.7.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.
@@ -13,6 +13,24 @@
13
13
  * `globalThis[Symbol.for("jelly.plugin-secrets")].get(PACKAGE_NAME, "token")`:
14
14
  * the key a person pasted into the plugin's settings.
15
15
  *
16
+ * **When Jelly refuses the token.** `token("memory")` rejects with one of four
17
+ * codes (Jelly's host maps Jelly ID's 400 to `invalid_target`, 401 to
18
+ * `not_enrolled`, 403 to `access_denied`, and anything else, a 503 included,
19
+ * to `unavailable`, and holds each answer for 30 s):
20
+ *
21
+ * - `invalid_target`, `not_enrolled`, `unavailable`: the request uses the
22
+ * pasted key instead, when one is saved. The refusal is held here for
23
+ * `REFUSAL_HOLD_MS` (the host's own hold), so Jelly is not asked on every
24
+ * request; after it, Jelly is asked again. With no key saved, the request
25
+ * fails with one sentence saying the agent's Jelly sign-in cannot be used for
26
+ * memory and no memory key is saved.
27
+ * - `access_denied`: no fallback. Jelly says the account behind this agent is
28
+ * disabled or marked for deletion; writing on with a pasted key would get
29
+ * round the switch that stops that account, so the request fails instead.
30
+ *
31
+ * Accepted risk: a person whose Jelly sign-in and pasted key belong to two
32
+ * different memory users writes as the key's user while a fallback lasts.
33
+ *
16
34
  * The gateway origin is the `controlURL` option, else the identity accessor's
17
35
  * `memory` resource `url` (see `followOrigin`).
18
36
  *
@@ -31,6 +49,12 @@ export const MEMORY_RESOURCE = "memory"
31
49
  export const SECRET_KEY = "token"
32
50
  /** A Jelly token is replaced this long before it expires. */
33
51
  export const REFRESH_MARGIN_MS = 60_000
52
+ /**
53
+ * How long a refusal from `token("memory")` is believed before Jelly is asked
54
+ * again: the host holds each refusal this long too (`REFUSAL_HOLD_MS` in
55
+ * Jelly's `backend/host/src/auth/resource-tokens.ts`).
56
+ */
57
+ export const REFUSAL_HOLD_MS = 30_000
34
58
  /** The longest value Jelly lets a setting carry (`PLUGIN_SETTING_MAX_LENGTH`). */
35
59
  const MAX_TOKEN_CHARS = 8192
36
60
  /** Visible ASCII only: a bearer goes into an HTTP header. */
@@ -44,9 +68,15 @@ const TOKEN_ERRORS = Object.freeze({
44
68
  unavailable: "Jelly could not issue a memory token just now",
45
69
  not_enrolled: "this Jelly host is not enrolled at a Jelly account",
46
70
  access_denied: "the Jelly account is disabled or marked for deletion",
47
- invalid_target: "the Jelly account does not offer memory",
71
+ invalid_target: "the Jelly account does not offer memory to this agent",
48
72
  })
49
73
 
74
+ /**
75
+ * The refusals after which a request uses the pasted key instead. Not
76
+ * `access_denied`: see the module comment.
77
+ */
78
+ export const FALLBACK_CODES = Object.freeze(["invalid_target", "not_enrolled", "unavailable"])
79
+
50
80
  /**
51
81
  * A memory token could not be had. `status` lets the spool and the bootstrap
52
82
  * classify it: 503 when Jelly cannot answer now, 401 otherwise.
@@ -114,16 +144,20 @@ export function originOf(value) {
114
144
  * token?: string,
115
145
  * holder?: Record<symbol, unknown>,
116
146
  * now?: () => number,
147
+ * log?: { info?: Function, warn?: Function },
117
148
  * }} [input]
118
149
  */
119
150
  export function createCredentials(input = {}) {
120
151
  const optionToken = typeof input.token === "string" ? input.token : ""
121
152
  const holder = input.holder ?? globalThis
122
153
  const now = typeof input.now === "function" ? input.now : Date.now
154
+ const log = input.log ?? null
123
155
  /** The last Jelly token: `{ accessToken, expiresAt }`. Memory only. */
124
156
  let cached = null
125
157
  /** One `token("memory")` call at a time. */
126
158
  let minting = null
159
+ /** The last refusal from `token("memory")`: `{ code, until }`, believed until `until`. */
160
+ let refusal = null
127
161
 
128
162
  function identity() {
129
163
  const accessor = readGlobal(holder, IDENTITY_SYMBOL)
@@ -168,14 +202,42 @@ export function createCredentials(input = {}) {
168
202
  }
169
203
  }
170
204
 
171
- /** Which source supplies the bearer now, or "" when none does. */
205
+ /** The refusal Jelly gave within the hold, or null. */
206
+ function held() {
207
+ if (refusal && refusal.until > now()) return refusal
208
+ refusal = null
209
+ return null
210
+ }
211
+
212
+ /**
213
+ * Which source supplies the bearer now, or "" when none does.
214
+ *
215
+ * During a hold after a refusal that falls back, that is the pasted key when
216
+ * one is saved. With no key, or after `access_denied`, it stays the Jelly
217
+ * sign-in: the only candidate, whose requests fail with the reason, so a
218
+ * finished turn is spooled for later rather than dropped as unavailable.
219
+ */
172
220
  function source() {
173
221
  if (optionToken) return SOURCES.option
174
- if (memoryResource()) return SOURCES.identity
222
+ if (memoryResource()) {
223
+ const refused = held()
224
+ if (refused && FALLBACK_CODES.includes(refused.code) && secretToken()) return SOURCES.secret
225
+ return SOURCES.identity
226
+ }
175
227
  if (secretToken()) return SOURCES.secret
176
228
  return ""
177
229
  }
178
230
 
231
+ /**
232
+ * The source in use and, during a hold, the code Jelly refused with ("" when
233
+ * none), for `mem_status`.
234
+ */
235
+ function describe() {
236
+ const current = source()
237
+ const refused = current === SOURCES.option ? null : memoryResource() ? held() : null
238
+ return { source: current, refused: refused?.code ?? "" }
239
+ }
240
+
179
241
  /** Jelly's core plugin has published at least one accessor in this engine. */
180
242
  function inJelly() {
181
243
  return Boolean(identity() || secrets())
@@ -190,6 +252,30 @@ export function createCredentials(input = {}) {
190
252
  return Boolean(entry && entry.expiresAt - REFRESH_MARGIN_MS > now())
191
253
  }
192
254
 
255
+ /**
256
+ * Hold a refusal for `REFUSAL_HOLD_MS` and log it: the code only, never a
257
+ * token or the accessor's words. Returns the error for this request.
258
+ *
259
+ * @param {string} code
260
+ * @param {string} [reason] why, in the plugin's words; the code's own by default
261
+ */
262
+ function hold(code, reason = TOKEN_ERRORS[code]) {
263
+ refusal = { code, reason, until: now() + REFUSAL_HOLD_MS }
264
+ const message = FALLBACK_CODES.includes(code)
265
+ ? "Jelly refused a memory token; the saved memory key, if any, is used until Jelly is asked again"
266
+ : "Jelly refused a memory token; the saved memory key is not used in its place"
267
+ log?.warn?.(message, { code, holdMs: REFUSAL_HOLD_MS, keySaved: Boolean(secretToken()) })
268
+ return refusalError(refusal)
269
+ }
270
+
271
+ /** The error for a refusal: the contract's code and the plugin's words, never the accessor's own. */
272
+ function refusalError({ code, reason }) {
273
+ if (code === "access_denied") {
274
+ return new CredentialError(`${reason} (${code}); a saved memory key is not used in its place`, code)
275
+ }
276
+ return new CredentialError(`${reason} (${code})`, code)
277
+ }
278
+
193
279
  async function mint() {
194
280
  if (minting) return minting
195
281
  minting = (async () => {
@@ -200,15 +286,15 @@ export function createCredentials(input = {}) {
200
286
  answer = await accessor.token(MEMORY_RESOURCE)
201
287
  } catch (error) {
202
288
  const code = typeof member(error, "code") === "string" && TOKEN_ERRORS[error.code] ? error.code : "unavailable"
203
- // The accessor's own words are not repeated: only the contract's codes are.
204
- throw new CredentialError(`${TOKEN_ERRORS[code]} (${code})`, code)
289
+ throw hold(code)
205
290
  }
206
291
  const accessToken = usableToken(member(answer, "accessToken"))
207
292
  const expiresAt = Number(member(answer, "expiresAt"))
208
293
  if (!accessToken || !Number.isFinite(expiresAt)) {
209
- throw new CredentialError("Jelly returned a malformed memory token", "unavailable")
294
+ throw hold("unavailable", "Jelly returned a malformed memory token")
210
295
  }
211
296
  const entry = { accessToken, expiresAt }
297
+ refusal = null
212
298
  // A token already inside the refresh margin is used for this request
213
299
  // but not kept: the next request asks again.
214
300
  cached = fresh(entry) ? entry : null
@@ -221,38 +307,88 @@ export function createCredentials(input = {}) {
221
307
  }
222
308
  }
223
309
 
310
+ /**
311
+ * The pasted key for a request Jelly refused with a code that falls back, or
312
+ * a CredentialError saying what is missing. `status` follows the code (503
313
+ * for `unavailable`, else 401), so the spool and the bootstrap classify it as
314
+ * before.
315
+ */
316
+ function fallback(refused) {
317
+ if (!FALLBACK_CODES.includes(refused.code)) throw refusalError(refused)
318
+ const key = secretToken()
319
+ if (key) return key
320
+ throw new CredentialError(
321
+ `this agent's Jelly sign-in can't be used for memory: ${refused.reason} (${refused.code}), and no memory key is saved in the plugin's settings`,
322
+ refused.code,
323
+ )
324
+ }
325
+
224
326
  /**
225
327
  * The bearer for one request, or "" when no source has one. A Jelly token
226
- * that is failing to mint rejects with a CredentialError.
328
+ * that cannot be had falls back to the pasted key (see the module comment),
329
+ * or rejects with a CredentialError.
227
330
  *
228
331
  * @returns {Promise<string>}
229
332
  */
230
333
  async function bearer() {
231
334
  if (optionToken) return optionToken
232
- if (memoryResource()) {
335
+ if (!memoryResource()) return secretToken()
336
+ let refused = held()
337
+ if (!refused) {
233
338
  if (fresh(cached)) return cached.accessToken
234
- return (await mint()).accessToken
339
+ try {
340
+ return (await mint()).accessToken
341
+ } catch (error) {
342
+ refused = held()
343
+ // Only a refusal is held; an accessor gone since `memoryResource()` read it is not.
344
+ if (!refused) throw error
345
+ }
235
346
  }
236
- return secretToken()
347
+ return fallback(refused)
237
348
  }
238
349
 
239
350
  /**
240
351
  * After a 401: drop the refused Jelly token and ask for another. Returns the
241
- * new bearer, or "" when there is nothing different to try (a key from the
242
- * option or the settings, or a host that hands back the same token).
352
+ * new bearer, or "" when there is nothing different to try: a key from the
353
+ * option or the settings, a host that hands back the same token, or Jelly
354
+ * refusing within its hold. A 401 never switches sources, so a request is
355
+ * never passed back and forth between a Jelly token and the pasted key; a
356
+ * refusal here is held, and the next request falls back.
243
357
  *
244
358
  * @param {string} rejected the bearer the gateway refused
245
359
  * @returns {Promise<string>}
246
360
  */
247
361
  async function refresh(rejected) {
248
362
  if (optionToken || !memoryResource()) return ""
363
+ if (!rejected || rejected === secretToken()) return ""
364
+ if (held()) return ""
249
365
  if (cached?.accessToken === rejected) cached = null
250
366
  if (fresh(cached)) return cached.accessToken
251
- const next = (await mint()).accessToken
367
+ let next
368
+ try {
369
+ next = (await mint()).accessToken
370
+ } catch {
371
+ return ""
372
+ }
252
373
  return next === rejected ? "" : next
253
374
  }
254
375
 
255
- return { source, inJelly, origin, bearer, refresh, memoryResource }
376
+ return { source, describe, inJelly, origin, bearer, refresh, memoryResource }
377
+ }
378
+
379
+ /**
380
+ * The `credential` line of `mem_status` and `/mem-status`, from `describe()`:
381
+ * the source in use, and during a hold the code Jelly refused with.
382
+ *
383
+ * @param {{ source: string, refused: string }} state
384
+ */
385
+ export function credentialLine({ source, refused }) {
386
+ const name = source || "none"
387
+ if (!refused) return name
388
+ if (source === SOURCES.secret) {
389
+ return `${name} (Jelly refused a memory token: ${refused}; Jelly is asked again within ${REFUSAL_HOLD_MS / 1000} s)`
390
+ }
391
+ return `${name} (Jelly refused a memory token: ${refused})`
256
392
  }
257
393
 
258
394
  /**
@@ -265,7 +401,7 @@ export function createCredentials(input = {}) {
265
401
  export function unavailableReason({ source, controlURL, inJelly }) {
266
402
  if (!source) {
267
403
  return inJelly
268
- ? "Memory is unavailable: this Jelly is not signed in to a Jelly account that offers memory, and no memory key is saved in the plugin's settings."
404
+ ? "Memory is unavailable: this agent's Jelly sign-in can't be used for memory, and no memory key is saved in the plugin's settings."
269
405
  : "Memory is unavailable: no memory key is set; set the token option or MEMORY_TOKEN to the key from the memory site's /account page."
270
406
  }
271
407
  if (!controlURL) {
package/src/index.js CHANGED
@@ -8,6 +8,7 @@ import { syncSkills, registerBuiltinSkill } from "./skills.js"
8
8
  import { registerCommands } from "./commands.js"
9
9
  import { attachMemoryHooks } from "./hooks.js"
10
10
  import { attachCapture } from "./events.js"
11
+ import { registerViewRpc } from "./views/rpc.js"
11
12
  import { errorMessage, versionAtLeast } from "./util.js"
12
13
 
13
14
  /**
@@ -57,7 +58,7 @@ export default {
57
58
 
58
59
  // Credentials and, inside Jelly, the gateway origin are read on use: the
59
60
  // accessors Jelly's core plugin publishes may appear after this setup.
60
- const credentials = createCredentials({ token: config.token })
61
+ const credentials = createCredentials({ token: config.token, log })
61
62
  const jelly = !config.controlURL && credentials.inJelly()
62
63
  if (jelly) followOrigin(config, () => credentials.origin())
63
64
  const gateway = Boolean(config.controlURL) || jelly
@@ -129,6 +130,15 @@ export default {
129
130
  log.error("tool registration failed", error)
130
131
  }
131
132
 
133
+ // Memory's views in Jelly call this RPC. It registers even while memory is
134
+ // unavailable, so the views can say why and what to do.
135
+ try {
136
+ const views = await registerViewRpc(ctx, runtime)
137
+ if (views) disposers.push(() => views.dispose())
138
+ } catch (error) {
139
+ log.error("view RPC registration failed", error)
140
+ }
141
+
132
142
  try {
133
143
  await runtime.refreshSkills()
134
144
  } catch (error) {
package/src/runtime.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { contextScopeLabel, placementSignature, resolveScope, scopeLabel, taskKey } from "./scope.js"
2
2
  import { buildBootstrap } from "./bootstrap.js"
3
3
  import { buildCheckpoint, checkpointFingerprint } from "./compaction.js"
4
- import { unavailableReason } from "./credentials.js"
4
+ import { credentialLine, unavailableReason } from "./credentials.js"
5
5
  import { createControlClient } from "./spaces.js"
6
6
  import { createSkillContexts } from "./skill-contexts.js"
7
7
  import { createSpool } from "./spool.js"
@@ -793,6 +793,8 @@ export function createRuntime(input) {
793
793
  ])
794
794
  return {
795
795
  health: health.ok ? "ok" : `unavailable (${health.error})`,
796
+ // Read after the requests above, so a refusal they met is reported.
797
+ credential: credentials ? credentialLine(credentials.describe()) : config.token ? "option" : "none",
796
798
  scope: context ? contextScopeLabel(context, scoped) : scopeLabel(scoped),
797
799
  space: context?.space_id ?? null,
798
800
  spaceName: context?.space_name ?? null,
@@ -35,6 +35,7 @@ export function registerStatus(editor, toolkit) {
35
35
  `backend: ${status.health}`,
36
36
  `scope: ${status.scope}`,
37
37
  `capture: ${status.capture}`,
38
+ `credential: ${status.credential}`,
38
39
  ]
39
40
  if (status.space) {
40
41
  const kind = status.spaceKind && status.spaceKind !== "unknown" ? ` [${status.spaceKind}]` : ""
@@ -0,0 +1,239 @@
1
+ /**
2
+ * The read-only RPC methods Memory's views call in Jelly, and their schemas.
3
+ *
4
+ * This module is the one source of the method list: `package.json`'s
5
+ * `jelly.rpc` must equal `declaredMethods()` (test/views-contract.test.js), and
6
+ * `src/views/rpc.js` registers exactly these, under the package name, with the
7
+ * engine's RPC (`ctx.rpc.register`).
8
+ *
9
+ * Jelly holds each call to the agent's rules for the method's `permission`
10
+ * before the plugin sees it, so every method reads under the permission of the
11
+ * tool that makes the same read: the overview under `mem_status`, the space
12
+ * list under `mem_spaces`, recent memories under `mem_recall`, the wiki under
13
+ * `mem_wiki`. None of them writes: a write starts as a message the person sends
14
+ * (`open-agent`), and the agent's tool runs under the person's rules.
15
+ *
16
+ * The schemas are JSON Schema documents Jelly reads as data, checked on every
17
+ * call both ways (input and answer), each at most 16 KB. They use no
18
+ * `pattern`: the pinned engine's RPC (OpenCode 2.2.5, through Effect's
19
+ * `fromJsonSchemaDocument`) refuses to register a schema that has one ("Patterns
20
+ * may block validation and are disabled"). The handlers check ids themselves
21
+ * (`ID_PATTERN`) and refuse a bad one in words.
22
+ */
23
+
24
+ /** A memory, space, wiki or page id as the views pass it back: visible ASCII, bounded. */
25
+ export const ID_PATTERN = "^[A-Za-z0-9][A-Za-z0-9._:/-]{0,199}$"
26
+ /**
27
+ * Recent memories per page, and the most the page may skip: two pages, the
28
+ * newest 100, as deep as one upstream query reads (`src/views/rpc.js`).
29
+ */
30
+ export const RECENT_PAGE = 50
31
+ export const RECENT_MAX_OFFSET = 50
32
+ /** Characters of one memory a view is given; the tool reads the rest. */
33
+ export const MEMORY_TEXT_CHARS = 600
34
+ /** Characters of one wiki page a view is given. */
35
+ export const PAGE_TEXT_CHARS = 48_000
36
+ /** The most wikis, pages and spaces one answer lists. */
37
+ export const LIST_MAX = 100
38
+
39
+ const empty = { type: "object", additionalProperties: false, properties: {} }
40
+ const id = { type: "string", maxLength: 200 }
41
+ const line = (max) => ({ type: "string", maxLength: max })
42
+ const space = {
43
+ type: "object",
44
+ additionalProperties: false,
45
+ required: ["id", "name", "kind"],
46
+ properties: {
47
+ id,
48
+ name: line(200),
49
+ kind: { type: "string", enum: ["personal", "shared", "unknown"] },
50
+ },
51
+ }
52
+
53
+ const overviewOutput = {
54
+ type: "object",
55
+ additionalProperties: false,
56
+ required: ["connected", "credential", "capture", "health"],
57
+ properties: {
58
+ /** Whether memory can be used at all; `reason` says why not. */
59
+ connected: { type: "boolean" },
60
+ reason: line(400),
61
+ /** Where the bearer comes from: Jelly, a pasted key, the token option, or nothing. */
62
+ credential: { type: "string", enum: ["jelly", "key", "option", "none"] },
63
+ /** Jelly's refusal code while the plugin falls back to a pasted key. */
64
+ refused: line(40),
65
+ /** The memory service's origin. */
66
+ address: line(300),
67
+ /** Capture as this engine runs it now: the declared setting, read at start. */
68
+ capture: { type: "boolean" },
69
+ health: { type: "string", enum: ["ok", "unreachable", "unknown"] },
70
+ space,
71
+ counts: {
72
+ type: "object",
73
+ additionalProperties: false,
74
+ required: ["memories", "conversations", "summaries", "profile"],
75
+ properties: {
76
+ memories: { type: "integer", minimum: 0 },
77
+ conversations: { type: "integer", minimum: 0 },
78
+ summaries: { type: "integer", minimum: 0 },
79
+ profile: { type: "boolean" },
80
+ },
81
+ },
82
+ },
83
+ }
84
+
85
+ const spacesOutput = {
86
+ type: "object",
87
+ additionalProperties: false,
88
+ required: ["spaces"],
89
+ properties: {
90
+ spaces: {
91
+ type: "array",
92
+ maxItems: LIST_MAX,
93
+ items: {
94
+ type: "object",
95
+ additionalProperties: false,
96
+ required: ["id", "name", "kind", "role"],
97
+ properties: { ...space.properties, role: line(40) },
98
+ },
99
+ },
100
+ },
101
+ }
102
+
103
+ const recentInput = {
104
+ type: "object",
105
+ additionalProperties: false,
106
+ properties: { offset: { type: "integer", minimum: 0, maximum: RECENT_MAX_OFFSET, multipleOf: RECENT_PAGE } },
107
+ }
108
+
109
+ const recentOutput = {
110
+ type: "object",
111
+ additionalProperties: false,
112
+ required: ["space", "items", "more"],
113
+ properties: {
114
+ space,
115
+ items: {
116
+ type: "array",
117
+ maxItems: RECENT_PAGE,
118
+ items: {
119
+ type: "object",
120
+ additionalProperties: false,
121
+ required: ["id", "text", "type", "at"],
122
+ properties: {
123
+ id,
124
+ text: line(MEMORY_TEXT_CHARS),
125
+ type: line(40),
126
+ /** ISO time it was written or last changed; "" when the store gave none. */
127
+ at: line(40),
128
+ },
129
+ },
130
+ },
131
+ /** Whether a later page has more. */
132
+ more: { type: "boolean" },
133
+ },
134
+ }
135
+
136
+ const wikiListOutput = {
137
+ type: "object",
138
+ additionalProperties: false,
139
+ required: ["wikis"],
140
+ properties: {
141
+ wikis: {
142
+ type: "array",
143
+ maxItems: LIST_MAX,
144
+ items: {
145
+ type: "object",
146
+ additionalProperties: false,
147
+ required: ["id", "name", "pages"],
148
+ properties: { id, name: line(200), pages: { type: "integer", minimum: 0 } },
149
+ },
150
+ },
151
+ },
152
+ }
153
+
154
+ const wikiPagesOutput = {
155
+ type: "object",
156
+ additionalProperties: false,
157
+ required: ["pages"],
158
+ properties: {
159
+ pages: {
160
+ type: "array",
161
+ maxItems: LIST_MAX,
162
+ items: {
163
+ type: "object",
164
+ additionalProperties: false,
165
+ required: ["ref", "title"],
166
+ properties: { ref: id, title: line(200) },
167
+ },
168
+ },
169
+ },
170
+ }
171
+
172
+ const wikiReadOutput = {
173
+ type: "object",
174
+ additionalProperties: false,
175
+ required: ["ref", "content", "clipped"],
176
+ properties: { ref: id, content: line(PAGE_TEXT_CHARS), clipped: { type: "boolean" } },
177
+ }
178
+
179
+ /**
180
+ * The methods, in the order `package.json` declares them.
181
+ * @type {ReadonlyArray<{ name: string, label: string, permission: string, input: object, output: object }>}
182
+ */
183
+ export const VIEW_METHODS = Object.freeze([
184
+ {
185
+ name: "memory.overview",
186
+ label: "say whether memory is connected and how much it holds",
187
+ permission: "mem_status",
188
+ input: empty,
189
+ output: overviewOutput,
190
+ },
191
+ { name: "spaces.list", label: "list your memory spaces", permission: "mem_spaces", input: empty, output: spacesOutput },
192
+ {
193
+ name: "memories.recent",
194
+ label: "list your newest memories",
195
+ permission: "mem_recall",
196
+ input: recentInput,
197
+ output: recentOutput,
198
+ },
199
+ { name: "wiki.list", label: "list your wikis", permission: "mem_wiki", input: empty, output: wikiListOutput },
200
+ {
201
+ name: "wiki.pages",
202
+ label: "list a wiki's pages",
203
+ permission: "mem_wiki",
204
+ input: {
205
+ type: "object",
206
+ additionalProperties: false,
207
+ required: ["wiki"],
208
+ properties: { wiki: id },
209
+ },
210
+ output: wikiPagesOutput,
211
+ },
212
+ {
213
+ name: "wiki.read",
214
+ label: "read a wiki page",
215
+ permission: "mem_wiki",
216
+ input: {
217
+ type: "object",
218
+ additionalProperties: false,
219
+ required: ["wiki", "ref"],
220
+ properties: { wiki: id, ref: id },
221
+ },
222
+ output: wikiReadOutput,
223
+ },
224
+ ])
225
+
226
+ /** The refusal a page can show in the plugin's own words (`call.error`). */
227
+ export const VIEW_ERROR = "memory.refused"
228
+
229
+ /** `jelly.rpc` as package.json declares it. */
230
+ export function declaredMethods() {
231
+ return VIEW_METHODS.map(({ name, label, permission, input, output }) => ({
232
+ name,
233
+ label,
234
+ permission,
235
+ readOnly: true,
236
+ input,
237
+ output,
238
+ }))
239
+ }