@joe-broadhead/opencode-mem 0.9.14 → 0.11.2
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/CHANGELOG.md +1805 -0
- package/README.md +14 -7
- package/SECURITY.md +3 -1
- package/docs/agent-instructions.md +1 -1
- package/docs/agent-protocol.md +7 -7
- package/docs/permissions.md +16 -0
- package/package.json +7688 -339
- package/shared/page-paths.js +44 -0
- package/skills/mem.pages/SKILL.md +3 -1
- package/skills/mem.usage/SKILL.md +15 -15
- package/src/action-grant-keys.js +159 -0
- package/src/action-grant.js +439 -0
- package/src/actions.js +1690 -0
- package/src/backend/records.js +25 -2
- package/src/backend/v3.js +76 -22
- package/src/call-shapes.js +17 -16
- package/src/collector-lock.js +533 -62
- package/src/collector-service.js +153 -26
- package/src/collector.js +623 -30
- package/src/config.js +79 -6
- package/src/connect.js +106 -8
- package/src/credentials.js +123 -25
- package/src/events.js +174 -3
- package/src/forget-turn.js +141 -0
- package/src/host-refusal.js +78 -0
- package/src/index.js +209 -22
- package/src/jobs/host.js +557 -0
- package/src/ops/codes.js +110 -0
- package/src/ops/copy-lineage.js +42 -0
- package/src/ops/index.js +28 -0
- package/src/ops/space-ops.js +1936 -0
- package/src/outlinks.js +103 -0
- package/src/p2-reservation.js +151 -0
- package/src/permissions.js +30 -0
- package/src/plugins/descriptor.js +62 -0
- package/src/plugins/discovery.js +318 -0
- package/src/plugins/grants.js +178 -0
- package/src/plugins/locate.js +319 -0
- package/src/plugins/manifest.js +1162 -0
- package/src/plugins/source-contract/index.js +34 -0
- package/src/plugins/source-contract/policy.js +102 -0
- package/src/plugins/source-contract/vendor/PROVENANCE.json +17 -0
- package/src/plugins/source-contract/vendor/RELEASE-SHA256SUMS +3 -0
- package/src/plugins/source-contract/vendor/RELEASE.json +17 -0
- package/src/plugins/source-contract/vendor/SHA256SUMS +41 -0
- package/src/plugins/source-contract/vendor/THIRD-PARTY-NOTICES.md +35 -0
- package/src/plugins/source-contract/vendor/broker-client.js +93 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-3M5PAKSS.js +84 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-4ERCA4TK.js +185 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-6HDIB2SA.js +183 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-ELPJD3ND.js +10 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-HLVAKAYG.js +10 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-I2RXJJJM.js +81 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-KWEWSZ4V.js +505 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-KYWBTAF4.js +182 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-Q3RQA5J2.js +249 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-RRUAIQ4I.js +156 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-RYNKNCPP.js +165 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-W5SHR7DQ.js +9477 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-ZUKF7P6U.js +653 -0
- package/src/plugins/source-contract/vendor/cursor.js +26 -0
- package/src/plugins/source-contract/vendor/descriptor.js +34 -0
- package/src/plugins/source-contract/vendor/events.js +257 -0
- package/src/plugins/source-contract/vendor/index.js +10 -0
- package/src/plugins/source-contract/vendor/params.js +22 -0
- package/src/plugins/source-contract/vendor/permission.js +28 -0
- package/src/plugins/source-contract/vendor/pick.js +22 -0
- package/src/plugins/source-contract/vendor/read.js +29 -0
- package/src/plugins/source-contract/vendor/registry.js +23 -0
- package/src/plugins/source-contract/vendor/schema.js +17 -0
- package/src/plugins/source-contract/vendor/schemas/output.agenda.json +96 -0
- package/src/plugins/source-contract/vendor/schemas/output.countdown.json +28 -0
- package/src/plugins/source-contract/vendor/schemas/output.image.json +28 -0
- package/src/plugins/source-contract/vendor/schemas/output.inbox.json +84 -0
- package/src/plugins/source-contract/vendor/schemas/output.links.json +46 -0
- package/src/plugins/source-contract/vendor/schemas/output.list.json +57 -0
- package/src/plugins/source-contract/vendor/schemas/output.metric.json +61 -0
- package/src/plugins/source-contract/vendor/schemas/output.note.json +14 -0
- package/src/plugins/source-contract/vendor/schemas/output.progress.json +50 -0
- package/src/plugins/source-contract/vendor/schemas/output.record.json +38 -0
- package/src/plugins/source-contract/vendor/schemas/output.table.json +61 -0
- package/src/plugins/source-contract/vendor/schemas/output.thread.json +62 -0
- package/src/plugins/source-contract/vendor/schemas/sources.json +819 -0
- package/src/plugins/source-contract/vendor/schemas.js +19 -0
- package/src/plugins/source-contract/vendor/tools-rpc.js +42 -0
- package/src/plugins/verify.js +56 -0
- package/src/protocol.js +11 -6
- package/src/recall.js +92 -5
- package/src/records.js +61 -2
- package/src/requests.js +216 -0
- package/src/runtime.js +89 -7
- package/src/setup-time.js +68 -0
- package/src/skills.js +230 -8
- package/src/source-ids.js +25 -0
- package/src/sources/declaration.js +365 -0
- package/src/sources/reads.js +772 -0
- package/src/sources/rpc.js +151 -0
- package/src/sources.js +389 -92
- package/src/spaces.js +283 -11
- package/src/spool.js +61 -4
- package/src/stated.js +10 -5
- package/src/storable.js +139 -0
- package/src/tools/commitments.js +37 -4
- package/src/tools/held-write.js +31 -12
- package/src/tools/index.js +27 -0
- package/src/tools/ingest.js +27 -2
- package/src/tools/memory.js +30 -7
- package/src/tools/page.js +95 -9
- package/src/tools/recall.js +208 -4
- package/src/tools/share.js +42 -3
- package/src/tools/shared.js +44 -4
- package/src/tools/space-lifecycle.js +278 -0
- package/src/tools/spaces.js +373 -29
- package/src/tools/status.js +9 -2
- package/src/tools/wiki.js +34 -4
- package/src/util.js +110 -6
- package/src/vendor/source-contract/README.md +24 -0
- package/src/vendor/source-contract/THIRD-PARTY-NOTICES.md +35 -0
- package/src/vendor/source-contract/VENDOR.json +81 -0
- package/src/vendor/source-contract/chunks/chunk-3M5PAKSS.js +84 -0
- package/src/vendor/source-contract/chunks/chunk-6HDIB2SA.js +183 -0
- package/src/vendor/source-contract/chunks/chunk-HLVAKAYG.js +10 -0
- package/src/vendor/source-contract/chunks/chunk-I2RXJJJM.js +81 -0
- package/src/vendor/source-contract/chunks/chunk-KWEWSZ4V.js +505 -0
- package/src/vendor/source-contract/chunks/chunk-W5SHR7DQ.js +9477 -0
- package/src/vendor/source-contract/chunks/chunk-ZUKF7P6U.js +653 -0
- package/src/vendor/source-contract/cursor.js +26 -0
- package/src/vendor/source-contract/events.js +257 -0
- package/src/vendor/source-contract/registry.js +23 -0
- package/src/vendor/source-contract/tools-rpc.js +42 -0
- package/src/views/access-reads.js +256 -0
- package/src/views/communities.js +77 -0
- package/src/views/contracts.js +930 -21
- package/src/views/inbox-bytes.js +103 -0
- package/src/views/profile.js +31 -0
- package/src/views/records-reads.js +355 -38
- package/src/views/rpc.js +118 -8
- package/src/views/shape.js +8 -5
- package/views/pages.html +2 -2
package/src/tools/wiki.js
CHANGED
|
@@ -8,6 +8,9 @@ const MAX_FILE_BYTES = 512 * 1024
|
|
|
8
8
|
const DEFAULT_FILE = "README.md"
|
|
9
9
|
/** The wiki actions that change knowledge; every other action only reads. */
|
|
10
10
|
export const WIKI_WRITE_ACTIONS = Object.freeze(["create", "write", "append", "delete"])
|
|
11
|
+
|
|
12
|
+
/** The reads of mem_wiki, and all of `mem.wikis` (jelly #74). */
|
|
13
|
+
export const WIKI_READ_ACTIONS = Object.freeze(["list", "search", "read", "status"])
|
|
11
14
|
/** The actions that write a source file (delete has its own path). */
|
|
12
15
|
const FILE_WRITE_ACTIONS = Object.freeze(["create", "write", "append"])
|
|
13
16
|
/** The hub's structural pages, which page/rm refuses (PAGE_FORBIDDEN_REFS). */
|
|
@@ -518,7 +521,7 @@ export function registerWiki(editor, toolkit) {
|
|
|
518
521
|
|
|
519
522
|
if (input?.confirm !== true) {
|
|
520
523
|
return text(
|
|
521
|
-
`${note}Preview only: nothing was deleted and nothing was asked. In ${where}, mem_wiki delete with confirm: true would delete ${subject}. That call asks the person first, then reads the deletion back.`,
|
|
524
|
+
`${note}Preview only: nothing was deleted and nothing was asked. In ${where}, mem_wiki delete with confirm: true would delete ${subject}. That call asks the person first, then reads the deletion back. Only delete it if the person asked: a wiki or file you created by mistake is reported, and removed only if the person asks.`,
|
|
522
525
|
)
|
|
523
526
|
}
|
|
524
527
|
|
|
@@ -553,7 +556,7 @@ export function registerWiki(editor, toolkit) {
|
|
|
553
556
|
}
|
|
554
557
|
const deleted = (data?.deleted_ids ?? []).map(String).includes(wikiID)
|
|
555
558
|
const missing = (data?.failed ?? []).some((entry) => String(entry?.id) === wikiID && /not\s*found/i.test(String(entry?.reason ?? "")))
|
|
556
|
-
if (!deleted && !missing) return fail(`wiki ${oneLine(wikiID, 80)} was not deleted: ${oneLine((data?.failed ?? [])[0]?.reason ?? "the wiki did not confirm it", 200)}.`)
|
|
559
|
+
if (!deleted && !missing) return fail(`wiki ${oneLine(wikiID, 80)} was not deleted: ${oneLine(errorMessage((data?.failed ?? [])[0]?.reason ?? "the wiki did not confirm it"), 200)}.`)
|
|
557
560
|
}
|
|
558
561
|
const back = await wikiGone(scoped, wikiID)
|
|
559
562
|
log.info("wiki deleted", { wikiID, catalog: Boolean(resourceID), verified: back.gone })
|
|
@@ -590,7 +593,7 @@ export function registerWiki(editor, toolkit) {
|
|
|
590
593
|
}
|
|
591
594
|
}
|
|
592
595
|
|
|
593
|
-
|
|
596
|
+
const wiki = {
|
|
594
597
|
name: "wiki",
|
|
595
598
|
description:
|
|
596
599
|
"When asked to read a named document or wiki file, use mem_wiki read (or search to find it), even if mem_recall might answer. Call list, search and read for documentation, architecture, ownership and call-graph questions about what was uploaded or indexed. Write only documents the person gave you, as flat source files (\"notes.md\"; a name with a folder is refused). A space has a knowledge wiki only once action create makes one (name it \"My knowledge\" in the personal space); list shows which wikis exist. A write starts an ingest that locks the wiki for a few minutes: to write several files, pass ingest: false on each and ingest: true on the last. Like mem_recall it uses the session's space by default: your personal space, or a shared space bound to the session. A write to a shared space asks the person and shows the file and an excerpt; a write to your personal space does not. delete removes one source file (filename), one generated page (ref), or a whole wiki (wiki_id alone): without confirm it only previews; with confirm: true it always asks the person, then deletes and reads it back. Never put things to do (mem_commitments), where a project stands, or person and project pages (mem_page) here.",
|
|
@@ -636,7 +639,7 @@ export function registerWiki(editor, toolkit) {
|
|
|
636
639
|
confirm: {
|
|
637
640
|
type: "boolean",
|
|
638
641
|
description:
|
|
639
|
-
"delete only: omitted or false previews what would go and changes nothing; true asks the person, deletes, and reads the deletion back.
|
|
642
|
+
"delete only: omitted or false previews what would go and changes nothing; true asks the person, deletes, and reads the deletion back. Pass true only when the person asked; one you propose is offered, never deleted",
|
|
640
643
|
},
|
|
641
644
|
path: { type: "string", description: "Same as ref: the page path a search hit shows" },
|
|
642
645
|
visibility: {
|
|
@@ -942,5 +945,32 @@ export function registerWiki(editor, toolkit) {
|
|
|
942
945
|
return fail(errorMessage(error))
|
|
943
946
|
}
|
|
944
947
|
},
|
|
948
|
+
}
|
|
949
|
+
editor.add(wiki)
|
|
950
|
+
// The read-only twin (jelly #74), for the reason `mem.pages` gives: a host
|
|
951
|
+
// that offers the `memory` resource and keeps the declaration's `readOnly: true`.
|
|
952
|
+
if (toolkit.readOnlyTwins === true) editor.add({
|
|
953
|
+
name: "wikis",
|
|
954
|
+
description:
|
|
955
|
+
"Read a document: list, search, read and status, and never a write (mem_wiki writes and deletes).",
|
|
956
|
+
input: {
|
|
957
|
+
type: "object",
|
|
958
|
+
properties: {
|
|
959
|
+
action: { type: "string", enum: [...WIKI_READ_ACTIONS], description: "Required. list, search, read, status." },
|
|
960
|
+
query: { type: "string", description: "search: the query" },
|
|
961
|
+
knowledge_id: { type: "string", description: "search: one id from list" },
|
|
962
|
+
wiki_id: { type: "string", description: "read, status: the wiki id" },
|
|
963
|
+
ref: { type: "string", description: "read: a hit's `path` or a page id" },
|
|
964
|
+
type: { type: "string", description: "list, search: wiki, code-graph, all" },
|
|
965
|
+
space: { type: "string", description: "A space id; the session's by default" },
|
|
966
|
+
},
|
|
967
|
+
required: ["action"],
|
|
968
|
+
additionalProperties: false,
|
|
969
|
+
},
|
|
970
|
+
options: { namespace: "mem" },
|
|
971
|
+
execute: async (input, context) =>
|
|
972
|
+
WIKI_READ_ACTIONS.includes(String(input?.action ?? ""))
|
|
973
|
+
? wiki.execute(input, context)
|
|
974
|
+
: text(`not read: mem_wikis reads only (${WIKI_READ_ACTIONS.join(", ")}). To change a document, use mem_wiki with action "${oneLine(input?.action, 40)}", which asks where it must.`),
|
|
945
975
|
})
|
|
946
976
|
}
|
package/src/util.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto"
|
|
2
|
+
import { ERROR_WITHHELD, redactErrorText, redactSecrets, secretKinds } from "./storable.js"
|
|
2
3
|
|
|
3
4
|
/** @param {Date} [d] */
|
|
4
5
|
export function nowIso(d = new Date()) {
|
|
@@ -11,6 +12,11 @@ export function shortHash(value, length = 12) {
|
|
|
11
12
|
|
|
12
13
|
export function oneLine(value, max = 400) {
|
|
13
14
|
const text = String(value ?? "")
|
|
15
|
+
// Bidi controls and other format characters are never part of a name a
|
|
16
|
+
// person reads: they can reorder the words around them (jelly #75, N3).
|
|
17
|
+
// Only the bidi controls: U+200C (ZWNJ) and U+200D (ZWJ) are part of
|
|
18
|
+
// Persian, Indic and emoji text and stay (review round 2).
|
|
19
|
+
.replace(/[\u200E\u200F\u202A-\u202E\u2066-\u2069]/g, "")
|
|
14
20
|
.replace(/\s+/g, " ")
|
|
15
21
|
.trim()
|
|
16
22
|
return text.length > max ? `${text.slice(0, max - 1)}…` : text
|
|
@@ -81,7 +87,7 @@ export function rememberBounded(store, key, value, max = 500) {
|
|
|
81
87
|
// The redaction rules live in storable.js, with the decision of what may be
|
|
82
88
|
// stored (owner decision D3); the logger, ask excerpts and the redaction
|
|
83
89
|
// vectors use them from here.
|
|
84
|
-
export { redactLocalPaths, redactSecrets } from "./storable.js"
|
|
90
|
+
export { ERROR_TEXT_MAX, ERROR_WITHHELD, redactErrorText, redactLocalPaths, redactSecrets } from "./storable.js"
|
|
85
91
|
|
|
86
92
|
/**
|
|
87
93
|
* One line describing the capture spool: pending depth, quarantined entries,
|
|
@@ -145,22 +151,120 @@ export function sleep(ms) {
|
|
|
145
151
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
146
152
|
}
|
|
147
153
|
|
|
154
|
+
/** What no message is called: never `[object Object]`, and never a guess at an object's contents. */
|
|
155
|
+
export const NO_ERROR_MESSAGE = "an error with no message"
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The message of a failure, for every answer and report that shows one
|
|
159
|
+
* (0.10.3 gate, A15; review F2). A records or RPC failure arrives as a plain
|
|
160
|
+
* object, so `String(error)` wrote "[object Object]" and hid the real reason.
|
|
161
|
+
* Only these fields are read — `message`, `error` (a string, or an object's
|
|
162
|
+
* `message`), `cause.message` and `code` — never the object's other contents,
|
|
163
|
+
* which can carry headers and tokens. The text is sanitised by
|
|
164
|
+
* `redactErrorText`; if Memory's own detector still finds a secret, the
|
|
165
|
+
* message is withheld and only the code is kept.
|
|
166
|
+
*/
|
|
148
167
|
export function errorMessage(error) {
|
|
168
|
+
const raw = messageOf(error)
|
|
169
|
+
const code = codeOf(error)
|
|
170
|
+
const clean = redactErrorText(raw)
|
|
171
|
+
if (clean.trim() && secretKinds(clean).length > 0) return withheld(code)
|
|
172
|
+
if (clean.trim()) return clean
|
|
173
|
+
if (code && secretKinds(redactErrorText(code)).length === 0) return redactErrorText(code)
|
|
174
|
+
return NO_ERROR_MESSAGE
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The withheld phrase, naming the code so a failure is still diagnosable. */
|
|
178
|
+
function withheld(code) {
|
|
179
|
+
return code ? `${ERROR_WITHHELD} (code ${oneLine(code, 60)})` : ERROR_WITHHELD
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** `errorMessage`'s body: the message fields only, never a dump of the object. */
|
|
183
|
+
function messageOf(error) {
|
|
149
184
|
if (error instanceof Error) return error.message
|
|
150
|
-
|
|
185
|
+
if (typeof error === "string") return error
|
|
186
|
+
if (typeof error === "number" || typeof error === "boolean" || typeof error === "bigint") return String(error)
|
|
187
|
+
if (!error || typeof error !== "object") return NO_ERROR_MESSAGE
|
|
188
|
+
const shown = (value) => (typeof value === "string" && value.trim() ? value : "")
|
|
189
|
+
const own = shown(error.message)
|
|
190
|
+
if (own) return own
|
|
191
|
+
const coded = shown(error.error)
|
|
192
|
+
if (coded) return coded
|
|
193
|
+
const nested = error.error && typeof error.error === "object" ? shown(error.error.message) : ""
|
|
194
|
+
if (nested) return nested
|
|
195
|
+
if (error.cause instanceof Error && shown(error.cause.message)) return error.cause.message
|
|
196
|
+
const caused = error.cause && typeof error.cause === "object" ? shown(error.cause.message) : ""
|
|
197
|
+
if (caused) return caused
|
|
198
|
+
const code = shown(error.code)
|
|
199
|
+
if (code) return code
|
|
200
|
+
return NO_ERROR_MESSAGE
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** A failure's `code`, where it names one: kept even when the message is withheld. */
|
|
204
|
+
function codeOf(error) {
|
|
205
|
+
if (!error || typeof error !== "object") return ""
|
|
206
|
+
const code = error.code ?? (error.error && typeof error.error === "object" ? error.error.code : undefined)
|
|
207
|
+
return typeof code === "string" && code.trim() ? code.trim() : ""
|
|
151
208
|
}
|
|
152
209
|
|
|
153
210
|
/**
|
|
154
|
-
*
|
|
155
|
-
*
|
|
211
|
+
* The numeric parts of a host version, or `null` when it cannot be read. A
|
|
212
|
+
* leading `v` (what `opencode --version` prints) and surrounding spaces are not
|
|
213
|
+
* part of the version, so `v2.3.0` is 2.3.0 and not an unreadable string.
|
|
156
214
|
*/
|
|
157
|
-
export function
|
|
215
|
+
export function versionParts(version) {
|
|
158
216
|
const parts = String(version ?? "")
|
|
217
|
+
.trim()
|
|
218
|
+
.replace(/^v/i, "")
|
|
159
219
|
.split(".")
|
|
160
220
|
.map((part) => Number.parseInt(part, 10))
|
|
161
|
-
if (parts.length < 2 || parts.some((part) => !Number.isFinite(part))) return
|
|
221
|
+
if (parts.length < 2 || parts.some((part) => !Number.isFinite(part))) return null
|
|
222
|
+
return parts
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** Compare a dotted version against a minimum, the floor of the supported range. */
|
|
226
|
+
export function versionAtLeast(version, major, minor, patch = 0) {
|
|
227
|
+
const parts = versionParts(version)
|
|
228
|
+
if (!parts) return false
|
|
162
229
|
const [a = 0, b = 0, c = 0] = parts
|
|
163
230
|
if (a !== major) return a > major
|
|
164
231
|
if (b !== minor) return b > minor
|
|
165
232
|
return c >= patch
|
|
166
233
|
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Whether a host version is below `major.minor.patch`, the ceiling half of the
|
|
237
|
+
* range Memory supports. A different major is above it, so 3.0.0 is not below
|
|
238
|
+
* 2.4.0; an unparseable or absent version is not below it either, which leaves
|
|
239
|
+
* the refusal to `versionAtLeast`'s floor below.
|
|
240
|
+
*/
|
|
241
|
+
export function versionBelow(version, major, minor, patch = 0) {
|
|
242
|
+
const parts = versionParts(version)
|
|
243
|
+
if (!parts) return false
|
|
244
|
+
const [a = 0, b = 0, c = 0] = parts
|
|
245
|
+
if (a !== major) return a < major
|
|
246
|
+
if (b !== minor) return b < minor
|
|
247
|
+
return c < patch
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Plugin text at a display edge: a source's `scope.describe`, the label its
|
|
252
|
+
* probe reports, a note it wrote. The text is the plugin's own and is shown
|
|
253
|
+
* verbatim only where nothing interprets it; anywhere a surface renders it as
|
|
254
|
+
* markup, it is escaped first, because a declaration can say anything
|
|
255
|
+
* (DESIGN §15.5, B5). Control characters are dropped and the answer is bounded.
|
|
256
|
+
*
|
|
257
|
+
* @param {unknown} value
|
|
258
|
+
* @param {number} [max]
|
|
259
|
+
* @returns {string}
|
|
260
|
+
*/
|
|
261
|
+
export function escapeForDisplay(value, max = 500) {
|
|
262
|
+
return String(value ?? "")
|
|
263
|
+
.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, "")
|
|
264
|
+
.replaceAll("&", "&")
|
|
265
|
+
.replaceAll("<", "<")
|
|
266
|
+
.replaceAll(">", ">")
|
|
267
|
+
.replaceAll('"', """)
|
|
268
|
+
.replaceAll("'", "'")
|
|
269
|
+
.slice(0, Math.max(0, Number(max) || 500))
|
|
270
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Vendored `@we-the-rebel-alliance/source-contract`
|
|
2
|
+
|
|
3
|
+
**The locked v0.1.0 release.** This is the package's `dist/` at
|
|
4
|
+
`381e6c91` — `main` after PR #21, #24 and #25 merged (schema: rpc, probe and identity, one
|
|
5
|
+
kind rule, the events page, and verbatim grants), `package.json` version
|
|
6
|
+
`0.1.0`. The `v0.1.0` tag is not created yet; whichever commit it names must be
|
|
7
|
+
this one, and `VENDOR.json` names the commit and the SHA-256 of every file here.
|
|
8
|
+
|
|
9
|
+
- **Runtime:** `tools-rpc.js`, `events.js`, `cursor.js` and `registry.js` are what
|
|
10
|
+
Memory's sources carry the protocol with, so the copy ships inside the plugin (the
|
|
11
|
+
plugin may not import npm packages).
|
|
12
|
+
- **Tests:** `conformance.js` and `schemas/` are the conformance kit and the
|
|
13
|
+
declaration schema. `test/sources-conformance.test.js` runs the kit over every
|
|
14
|
+
source Memory declares, and holds each `x-` output's `data` to its inline schema.
|
|
15
|
+
- **Replaced by the tag.** When the package publishes `vX.Y.Z`, delete this
|
|
16
|
+
directory, pin `github:we-the-rebel-alliance/source-contract#vX.Y.Z`, and bundle
|
|
17
|
+
what is imported.
|
|
18
|
+
|
|
19
|
+
Why here and not `scripts/vendor/`: the plugin's shipped tree is `src/` (and not
|
|
20
|
+
`scripts/`, which `test/package-contents.test.js` refuses), and these modules are
|
|
21
|
+
imported at runtime.
|
|
22
|
+
|
|
23
|
+
Do not edit a file in this directory: a change belongs upstream, or in Memory's own
|
|
24
|
+
code beside it.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Bundled packages
|
|
2
|
+
|
|
3
|
+
dist/ bundles these packages and this data, so an install needs none of them.
|
|
4
|
+
|
|
5
|
+
## zod 4.6.7 (MIT)
|
|
6
|
+
|
|
7
|
+
MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2025 Colin McDonnell
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
## Public Suffix List (MPL-2.0)
|
|
30
|
+
|
|
31
|
+
The conformance kit bundles the Public Suffix List, ICANN and PRIVATE sections, from
|
|
32
|
+
https://publicsuffix.org/list/public_suffix_list.dat.
|
|
33
|
+
|
|
34
|
+
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
|
|
35
|
+
distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"commit": "8ace21db949557740c6dd8fd837c6efc50c367b7",
|
|
3
|
+
"files": {
|
|
4
|
+
"THIRD-PARTY-NOTICES.md": "1a00d3f937d6c65cd6987bbd0f0da1591d6f423bd7751aedfdc8cdd152bfa04e",
|
|
5
|
+
"broker-client.d.ts": "cf65170b6e960ae4b3501f91913fb4ddbf95d600239ef6bdeac12f872c8b9801",
|
|
6
|
+
"broker-client.js": "0b79307d2d1f33db24d3dd53184a3166627b51dffbdbb81f7cb4cf7a5ecafadd",
|
|
7
|
+
"chunks/chunk-3M5PAKSS.js": "d5a610aab777cff819b2d4fb4ebc9b4903f14345a1ebe5f52842f41119290f13",
|
|
8
|
+
"chunks/chunk-4ERCA4TK.js": "b91fefade14e3988d5817431a0a72476f5f03c8ce40e5c0448034e0572f8975b",
|
|
9
|
+
"chunks/chunk-6HDIB2SA.js": "a4f9d76b5e98c2994cdd9e2dc9d6ad4f796977fa7a7720519f498cb8996ed047",
|
|
10
|
+
"chunks/chunk-ELPJD3ND.js": "d8e1a5c27078e5ce1cfe2ef7e3f6381fffe242e625fa6370251b6fbfc03105ff",
|
|
11
|
+
"chunks/chunk-HLVAKAYG.js": "d0c7a4785744974cc4cf01af0f21495fc13b5ecea729aa8d162f800f16a56d6f",
|
|
12
|
+
"chunks/chunk-I2RXJJJM.js": "6f9f2b56ea30e3aa7629f823cc19b9438b5178f7448e2c292d2b07d28b0bc8e8",
|
|
13
|
+
"chunks/chunk-KWEWSZ4V.js": "9789db2ecce07e4ef24e46afe7f0b6669b45e7fe544c9aa302048dcfb20f6c34",
|
|
14
|
+
"chunks/chunk-KYWBTAF4.js": "b2efb36e7e70f930f23d2375f79a825a14ba682b86986ad038588747797743c7",
|
|
15
|
+
"chunks/chunk-Q3RQA5J2.js": "a4887f98e83f3ecea7ddfd1da9a5518f4c44ac0032f91aa1bdaf057a5bdfa630",
|
|
16
|
+
"chunks/chunk-RRUAIQ4I.js": "1e431825a38c3b8ec14d94b312f9b255b019c151277fc5ae304deafbf43a0729",
|
|
17
|
+
"chunks/chunk-RYNKNCPP.js": "c384c7af7ae1fc1d58999221adc1a4830001fb467b86cdb7678016eea174daaa",
|
|
18
|
+
"chunks/chunk-W5SHR7DQ.js": "2b17357118874b1052601e8062dc2aa24c182d5a55c2642400cba7572577d151",
|
|
19
|
+
"chunks/chunk-ZUKF7P6U.js": "6971bb13eb9a9ea9a3708d7e99b76292d4f82170c58cdafbd2443e1d47a34153",
|
|
20
|
+
"conformance.d.ts": "e7bff576b2085cde07b9fc82244b1b41475175f28c6fd5d26eac383306ecb01e",
|
|
21
|
+
"conformance.js": "d939fa44dbe5536e0e6bfaf1560b9b1abd2380cb0849fa9361a1b224da986ca3",
|
|
22
|
+
"cursor.d.ts": "b6bd52b4f5267fba84fc6ac4c46f06aeddc8f77d216980929aaed8577f8caa32",
|
|
23
|
+
"cursor.js": "28482ff668ec5680fe7c3e38ae7ee87c36da99ee447dbb851d055cdc49b0bea1",
|
|
24
|
+
"descriptor.d.ts": "3ff8eec5623bf716fb290e7c3ab1f5e77b6026706126fa58e7ac775e1c946c01",
|
|
25
|
+
"descriptor.js": "684cf95c0ddfb7d1b4e13c10fe5307a96971771e8e2ca71ab9a992d5deb6ebd2",
|
|
26
|
+
"events.d.ts": "cee2042a1a8216ceabd1ea22a997f6fb1754516ce4d3fa241ab135904e5d33db",
|
|
27
|
+
"events.js": "ce67038a5d442dd57d554a59eda98adcf726e3d7f5210c544c4e4f78200dd852",
|
|
28
|
+
"index.d.ts": "04416e21fe8ff873f320ddc2e55b4c061760fc5c3a908d9636119135dc4272d2",
|
|
29
|
+
"index.js": "52208818a550d9317dc263906f9a001bf0b4b56fb3d19319c43fe8fe68a7cc28",
|
|
30
|
+
"internal/checked.d.ts": "b139039477b76f14aa42683729f059607218a059180e638620c98c70ac4a8d09",
|
|
31
|
+
"internal/conformance/details.d.ts": "abc4d34f01b11ac668510030a10646d306919f176de72d245454a8fbe1c8061c",
|
|
32
|
+
"internal/conformance/kit.d.ts": "bc18e66225a3a9ec3ac3cc86e109bc82047434898c16e13a78e0db0c99e0fd8d",
|
|
33
|
+
"internal/conformance/page.d.ts": "839e4b9768d60d5d0b89da9f40a1b33a91c5497059a3167f1123493962604773",
|
|
34
|
+
"internal/conformance/permission.d.ts": "4056582ed572e8d6e34902244a90fd9c5596c3b9c0dd519f7e8f215f6a58fe2f",
|
|
35
|
+
"internal/conformance/probe.d.ts": "76fca0d07bb8de25931c0520a4a928b0957e852679d410f044a1fe1e8e305c6a",
|
|
36
|
+
"internal/conformance/rules.d.ts": "b5566a7b8c68d67ad017114bb49b18d77b1720f6352aa2f5d2517e55a95802ca",
|
|
37
|
+
"internal/conformance/suggest.d.ts": "fc75a1f0a495afe4d2289aa597fcb3d862b9d9326060f897b085a4772744674a",
|
|
38
|
+
"internal/events-conformance.d.ts": "4ba72ddf14447b064f5e9e775b57bf182c8d504fd9076a1b8cd55a0a1d329c95",
|
|
39
|
+
"internal/events.d.ts": "cdc142750d5a355794f7f2b33cff2a94a104c5d7546333c7d065639e9305a410",
|
|
40
|
+
"internal/failure.d.ts": "8a97c06868c3004afce0c17ad3f34a456be7e263e4f6437c2ec5f463f988275b",
|
|
41
|
+
"internal/schema/types.d.ts": "75bf6d6ff5d708e386ebb9e505fdc6cd834f68f54353fc077e7685ea5a2bc8e3",
|
|
42
|
+
"internal/secrets.d.ts": "8e294e3b5c0c84eedd90bc60af8476e2bbcfc5f9f775963f07a9ec180a5e3b13",
|
|
43
|
+
"params.d.ts": "454d5aa201c4f80be08502de442e835fa2619a923440f7b25969def6436676d3",
|
|
44
|
+
"params.js": "e5168b149699c793eccf1ad4c0f8a07df777aec675f093754ec3194d62c44ca7",
|
|
45
|
+
"permission.d.ts": "6c14da085dff17b9a4448eb298919578e2bd3c67169fbfbcbb17b941da9db73d",
|
|
46
|
+
"permission.js": "2ca7ea60b48cab16d5e14fc3f447469ad736f506a9c9a29f22ccef83e292da12",
|
|
47
|
+
"pick.d.ts": "e41f48be4cbde48049ad1a34dbd844b532a0b0d37f6490b4de60e24252591d8a",
|
|
48
|
+
"pick.js": "572ab1bd6534215d59f99b774ff1d2dfff399dc94439e45b7ed048ab9ea6bdf1",
|
|
49
|
+
"read.d.ts": "5ec18bf920b1b18897232e728a89f0e5a2ea2b130d24ac16475f046a6161d15c",
|
|
50
|
+
"read.js": "5890bea19273e20a2c4726f855c66c2470e68c0deb732309b7122b81f02d6081",
|
|
51
|
+
"registry.d.ts": "d28922618fa5e6b6601ff5c1cf250545a86fe9cc342712115bd57716d0637760",
|
|
52
|
+
"registry.js": "52ac92e7c0bb4c651e42d9a7ae6e7ae029a2c8677dfa240426271bbe4721164f",
|
|
53
|
+
"schema.d.ts": "e7322f2604e2dac1cca02fc8d2201de5e369cecf817accea3b28c2760a7a44e3",
|
|
54
|
+
"schema.js": "826b66a5c8e44c029795b2db9aaf8bc63092be99b75a6a866705312ed238b11b",
|
|
55
|
+
"schemas.d.ts": "5893b16f86f605ac68d37496e0a79c825fa412acb804977e28c3e44f2c90ede9",
|
|
56
|
+
"schemas.js": "98fb19d5d3974668d31e949bdbb238b682326b22b8bca6a2b4c5c1105ca3c53f",
|
|
57
|
+
"schemas/output.agenda.json": "afdcaa972b3294394883025d8c531ff51d4117cb8f5d2240b5f55319cf646b10",
|
|
58
|
+
"schemas/output.countdown.json": "2bb069201056c91056b3590417918970e3b79950df39f45f1537cc59eb3b9933",
|
|
59
|
+
"schemas/output.image.json": "b162cf16515ffb3eb324c4cc62d9898e6c894ba882d91af60025b60cf33129f9",
|
|
60
|
+
"schemas/output.inbox.json": "035a570bbccb36950d0e1af40bed15d48fe76a7f77a219f78b7c3498a5db7438",
|
|
61
|
+
"schemas/output.links.json": "37e583b99519ee9f96aa1f96fc2c1585f67afd4b797da5efce534e6761d94f75",
|
|
62
|
+
"schemas/output.list.json": "07b63a0a2eec2aa4282d10cb5bba50b4790fa7e75ecdb64465610320af78a487",
|
|
63
|
+
"schemas/output.metric.json": "76c03b348ee77415032d709e065ecae4b5316dcbe860bc4cb28624251552f6d4",
|
|
64
|
+
"schemas/output.note.json": "aa806aeb1f800c179648c7d3ad2d2ee67fa3c39977087d6f03c733ad28d14dcd",
|
|
65
|
+
"schemas/output.progress.json": "3d9be5dbf10713ef516bc08154bf92380c1cddd4450b2061601195a108d958e8",
|
|
66
|
+
"schemas/output.record.json": "30fbb81a6f8df5d0601e428f2503eb726eca603cc350805852dc7c909a9b59a1",
|
|
67
|
+
"schemas/output.table.json": "3d9695004dbf803576efcca0ff5bcef94af2d9475131db2fc694f974bc217dae",
|
|
68
|
+
"schemas/output.thread.json": "ffaaaa5107a2a6b7b36230e2e458383591b687af77c1be2e1876194bdeb40f90",
|
|
69
|
+
"schemas/sources.json": "160d6c9fff25809ae4eaa4d3d2275b7048b57e5606bf277e6924d6064dd1ca95",
|
|
70
|
+
"tools-rpc.d.ts": "bd050c3ba4deadf286dc54206ee228af3e32dd6b7463dbd08f3f211653bed772",
|
|
71
|
+
"tools-rpc.js": "bdac6baf1f7fa35fa800aa59269aaee22e770a76247b81f324b2d263a75447a1"
|
|
72
|
+
},
|
|
73
|
+
"package": "@we-the-rebel-alliance/source-contract",
|
|
74
|
+
"repository": "https://github.com/we-the-rebel-alliance/source-contract",
|
|
75
|
+
"tag": "v0.1.0",
|
|
76
|
+
"tagObject": "1bf9466b3d3745900bad4abb1c83f922956887de",
|
|
77
|
+
"release": "https://github.com/we-the-rebel-alliance/source-contract/releases/tag/v0.1.0",
|
|
78
|
+
"vendoredAt": "2026-11-14",
|
|
79
|
+
"version": "0.1.0",
|
|
80
|
+
"why": "v0.1.0's tagged release (tag v0.1.0 on 8ace21db), copied from the release tarball's dist/ after verifying it against the release's SHA256SUMS. tools-rpc, events, cursor and registry are what the sources' protocol uses at runtime; the kit and the schema are read by Memory's tests."
|
|
81
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// @we-the-rebel-alliance/source-contract 0.1.0. Built by scripts/build.mjs; do not edit.
|
|
2
|
+
|
|
3
|
+
// src/permission.ts
|
|
4
|
+
var DENY_ALL = { action: "*", resource: "*", effect: "deny" };
|
|
5
|
+
var ACCOUNT_PATTERN = /^[^\s*?:\u0000-\u001f\u007f]{1,320}$/;
|
|
6
|
+
var WILDCARD = /[*?]/;
|
|
7
|
+
function accountProblem(account) {
|
|
8
|
+
if (typeof account !== "string" || !ACCOUNT_PATTERN.test(account)) {
|
|
9
|
+
return "the account must be 1 to 320 characters with no wildcard (* or ?), no colon and no whitespace";
|
|
10
|
+
}
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
var allow = (action, resource) => ({ action, resource, effect: "allow" });
|
|
14
|
+
function namespaceOf(source) {
|
|
15
|
+
return source.id.split(".")[0] ?? source.id;
|
|
16
|
+
}
|
|
17
|
+
function operationRule(source, operation, account) {
|
|
18
|
+
const namespace = namespaceOf(source);
|
|
19
|
+
return operation.includes(".") ? allow(`${namespace}.read`, `${account}:${operation}`) : allow(`${namespace}_${operation}`, "*");
|
|
20
|
+
}
|
|
21
|
+
function fenced(rules) {
|
|
22
|
+
const loose = rules.find((rule) => WILDCARD.test(rule.action) || rule.resource !== "*" && WILDCARD.test(rule.resource));
|
|
23
|
+
if (loose) return { ok: false, problems: [`the rule for ${loose.action} on ${loose.resource} has a wildcard, which would widen the grant`] };
|
|
24
|
+
const seen = /* @__PURE__ */ new Set();
|
|
25
|
+
const unique = rules.filter((rule) => {
|
|
26
|
+
const key = `${rule.action}\0${rule.resource}`;
|
|
27
|
+
if (seen.has(key)) return false;
|
|
28
|
+
seen.add(key);
|
|
29
|
+
return true;
|
|
30
|
+
});
|
|
31
|
+
return { ok: true, value: [DENY_ALL, ...unique] };
|
|
32
|
+
}
|
|
33
|
+
function methodAction(source) {
|
|
34
|
+
return source.kind === "events" ? source.permission.events : source.permission.tool;
|
|
35
|
+
}
|
|
36
|
+
function sessionRules(source, grant) {
|
|
37
|
+
if (grant.source !== source.id) return { ok: false, problems: [`the grant is for ${grant.source}, not ${source.id}`] };
|
|
38
|
+
const problem = accountProblem(grant.account);
|
|
39
|
+
if (problem) return { ok: false, problems: [problem] };
|
|
40
|
+
const method = methodAction(source);
|
|
41
|
+
if (method === void 0) return { ok: false, problems: [`${source.id} names no action for its method`] };
|
|
42
|
+
const declared = source.permission.rules;
|
|
43
|
+
if (declared !== void 0) return fenced([allow(method, "*"), ...declared.map((rule) => allow(rule.action, rule.resource))]);
|
|
44
|
+
const operations = source.permission.operations ?? [];
|
|
45
|
+
if (operations.length === 0) return { ok: false, problems: [`${source.id} declares neither operations nor rules`] };
|
|
46
|
+
return fenced([allow(method, "*"), ...operations.map((operation) => operationRule(source, operation, grant.account))]);
|
|
47
|
+
}
|
|
48
|
+
function detailRules(source, detailId, grant) {
|
|
49
|
+
if (!source.details?.some((entry) => entry.id === detailId)) return { ok: false, problems: [`${source.id} declares no detail read ${detailId}`] };
|
|
50
|
+
return sessionRules(source, grant);
|
|
51
|
+
}
|
|
52
|
+
function probeRules(source, account, identityOperations, probeAction) {
|
|
53
|
+
const problem = accountProblem(account);
|
|
54
|
+
if (problem) return { ok: false, problems: [problem] };
|
|
55
|
+
const method = probeAction ?? methodAction(source);
|
|
56
|
+
if (method === void 0) return { ok: false, problems: [`${source.id} names no action for its method`] };
|
|
57
|
+
return fenced([allow(method, "*"), ...identityOperations.map((operation) => operationRule(source, operation, account))]);
|
|
58
|
+
}
|
|
59
|
+
function evaluate(rules, action, resource = "*") {
|
|
60
|
+
return rules.findLast((rule) => wildcard(rule.action, action) && wildcard(rule.resource, resource))?.effect ?? "ask";
|
|
61
|
+
}
|
|
62
|
+
var wildcard = (pattern, value) => new RegExp(`^${pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".")}$`).test(value);
|
|
63
|
+
function grantCovers(grant, request) {
|
|
64
|
+
if (grant.source !== request.source || grant.account !== request.account) return false;
|
|
65
|
+
for (const [key, values] of Object.entries(request.scope ?? {})) {
|
|
66
|
+
const granted = grant.scope?.[key];
|
|
67
|
+
if (!granted || values.some((value) => !granted.includes(value))) return false;
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export {
|
|
73
|
+
DENY_ALL,
|
|
74
|
+
ACCOUNT_PATTERN,
|
|
75
|
+
accountProblem,
|
|
76
|
+
namespaceOf,
|
|
77
|
+
operationRule,
|
|
78
|
+
methodAction,
|
|
79
|
+
sessionRules,
|
|
80
|
+
detailRules,
|
|
81
|
+
probeRules,
|
|
82
|
+
evaluate,
|
|
83
|
+
grantCovers
|
|
84
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// @we-the-rebel-alliance/source-contract 0.1.0. Built by scripts/build.mjs; do not edit.
|
|
2
|
+
import {
|
|
3
|
+
_enum,
|
|
4
|
+
_null,
|
|
5
|
+
array,
|
|
6
|
+
boolean,
|
|
7
|
+
fromJSONSchema,
|
|
8
|
+
iso_exports,
|
|
9
|
+
number,
|
|
10
|
+
object,
|
|
11
|
+
problemsOf,
|
|
12
|
+
record,
|
|
13
|
+
string,
|
|
14
|
+
union,
|
|
15
|
+
validator
|
|
16
|
+
} from "./chunk-W5SHR7DQ.js";
|
|
17
|
+
|
|
18
|
+
// src/registry.ts
|
|
19
|
+
var text = (max) => string().max(max);
|
|
20
|
+
var httpsUrl = string().max(2048).refine((value) => {
|
|
21
|
+
try {
|
|
22
|
+
return new URL(value).protocol === "https:";
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}, "must be an https URL");
|
|
27
|
+
var timestamp = iso_exports.datetime({ offset: true });
|
|
28
|
+
var date = union([timestamp, string().regex(/^\d{4}-\d{2}-\d{2}$/, "must be an ISO date-time with an offset, or a date")]);
|
|
29
|
+
var item = {
|
|
30
|
+
id: string().min(1).max(128),
|
|
31
|
+
url: httpsUrl.optional(),
|
|
32
|
+
ask: text(200).optional()
|
|
33
|
+
};
|
|
34
|
+
var IMAGE_DATA_URI_MAX = 1024 * 1024 - 4 * 1024;
|
|
35
|
+
var agenda = object({
|
|
36
|
+
items: array(
|
|
37
|
+
object({
|
|
38
|
+
...item,
|
|
39
|
+
title: text(120),
|
|
40
|
+
start: date,
|
|
41
|
+
end: date.optional(),
|
|
42
|
+
allDay: boolean().optional(),
|
|
43
|
+
location: text(120).optional(),
|
|
44
|
+
calendar: text(60).optional(),
|
|
45
|
+
joinUrl: httpsUrl.optional()
|
|
46
|
+
}).strict()
|
|
47
|
+
).max(50),
|
|
48
|
+
rangeEnd: date.optional()
|
|
49
|
+
}).strict();
|
|
50
|
+
var inbox = object({
|
|
51
|
+
unread: number().int().nonnegative().nullable(),
|
|
52
|
+
unit: text(20).optional(),
|
|
53
|
+
label: text(60).optional(),
|
|
54
|
+
items: array(
|
|
55
|
+
object({
|
|
56
|
+
...item,
|
|
57
|
+
title: text(120),
|
|
58
|
+
from: text(60).optional(),
|
|
59
|
+
preview: text(200).optional(),
|
|
60
|
+
at: timestamp,
|
|
61
|
+
count: number().int().nonnegative().optional(),
|
|
62
|
+
important: boolean().optional()
|
|
63
|
+
}).strict()
|
|
64
|
+
).max(30)
|
|
65
|
+
}).strict();
|
|
66
|
+
var metric = object({
|
|
67
|
+
label: text(40),
|
|
68
|
+
value: union([number().finite(), text(20)]),
|
|
69
|
+
unit: text(10).optional(),
|
|
70
|
+
delta: object({
|
|
71
|
+
value: number().finite(),
|
|
72
|
+
direction: _enum(["up", "down", "flat"]),
|
|
73
|
+
good: boolean().optional()
|
|
74
|
+
}).strict().optional(),
|
|
75
|
+
spark: array(number().finite()).max(48).optional()
|
|
76
|
+
}).strict();
|
|
77
|
+
var list = object({
|
|
78
|
+
items: array(
|
|
79
|
+
object({
|
|
80
|
+
id: item.id,
|
|
81
|
+
text: text(200),
|
|
82
|
+
done: boolean().optional(),
|
|
83
|
+
note: text(200).optional(),
|
|
84
|
+
due: date.optional()
|
|
85
|
+
}).strict()
|
|
86
|
+
).max(50),
|
|
87
|
+
editable: boolean()
|
|
88
|
+
}).strict();
|
|
89
|
+
var progress = object({
|
|
90
|
+
label: text(60),
|
|
91
|
+
value: number().nonnegative(),
|
|
92
|
+
max: number().positive(),
|
|
93
|
+
steps: array(object({ label: text(40), done: boolean() }).strict()).max(12).optional(),
|
|
94
|
+
eta: timestamp.optional()
|
|
95
|
+
}).strict().refine((value) => value.value <= value.max, { message: "value must not exceed max", path: ["value"] });
|
|
96
|
+
var note = object({ markdown: text(16 * 1024) }).strict();
|
|
97
|
+
var links = object({
|
|
98
|
+
items: array(
|
|
99
|
+
object({
|
|
100
|
+
...item,
|
|
101
|
+
title: text(60),
|
|
102
|
+
url: httpsUrl,
|
|
103
|
+
hint: text(60).optional()
|
|
104
|
+
}).strict()
|
|
105
|
+
).max(12)
|
|
106
|
+
}).strict();
|
|
107
|
+
var countdown = object({
|
|
108
|
+
label: text(60),
|
|
109
|
+
target: timestamp,
|
|
110
|
+
style: _enum(["relative", "timer"])
|
|
111
|
+
}).strict();
|
|
112
|
+
var image = object({
|
|
113
|
+
url: httpsUrl.optional(),
|
|
114
|
+
dataUri: string().max(IMAGE_DATA_URI_MAX).regex(/^data:image\/(png|jpeg|webp);base64,[A-Za-z0-9+/]+={0,2}$/, "must be a base64 data URI of a png, jpeg or webp image").optional(),
|
|
115
|
+
alt: string().min(1).max(200),
|
|
116
|
+
caption: text(120).optional()
|
|
117
|
+
}).strict().refine((value) => value.url === void 0 !== (value.dataUri === void 0), { message: "give exactly one of url and dataUri" });
|
|
118
|
+
var thread = object({
|
|
119
|
+
subject: text(200),
|
|
120
|
+
messages: array(
|
|
121
|
+
object({
|
|
122
|
+
...item,
|
|
123
|
+
from: text(120),
|
|
124
|
+
at: timestamp,
|
|
125
|
+
body: text(4e3),
|
|
126
|
+
quoted: text(4e3).optional()
|
|
127
|
+
}).strict()
|
|
128
|
+
).min(1).max(50)
|
|
129
|
+
}).strict();
|
|
130
|
+
var table = object({
|
|
131
|
+
columns: array(object({ key: string().regex(/^[A-Za-z0-9_-]{1,40}$/), label: text(40) }).strict()).min(1).max(8),
|
|
132
|
+
rows: array(record(string(), union([text(200), number().finite(), boolean(), _null()]))).max(100)
|
|
133
|
+
}).strict();
|
|
134
|
+
var record2 = object({
|
|
135
|
+
title: text(120),
|
|
136
|
+
fields: array(object({ label: text(60), value: text(400) }).strict()).min(1).max(24)
|
|
137
|
+
}).strict();
|
|
138
|
+
var OUTPUTS = {
|
|
139
|
+
agenda: validator("output.agenda", agenda),
|
|
140
|
+
inbox: validator("output.inbox", inbox),
|
|
141
|
+
metric: validator("output.metric", metric),
|
|
142
|
+
list: validator("output.list", list),
|
|
143
|
+
progress: validator("output.progress", progress),
|
|
144
|
+
note: validator("output.note", note),
|
|
145
|
+
links: validator("output.links", links),
|
|
146
|
+
countdown: validator("output.countdown", countdown),
|
|
147
|
+
image: validator("output.image", image),
|
|
148
|
+
thread: validator("output.thread", thread),
|
|
149
|
+
table: validator("output.table", table),
|
|
150
|
+
record: validator("output.record", record2)
|
|
151
|
+
};
|
|
152
|
+
var OUTPUT_NAMES = Object.keys(OUTPUTS);
|
|
153
|
+
function isOutputName(name) {
|
|
154
|
+
return typeof name === "string" && Object.hasOwn(OUTPUTS, name);
|
|
155
|
+
}
|
|
156
|
+
function outputValidator(name) {
|
|
157
|
+
return isOutputName(name) ? OUTPUTS[name] : void 0;
|
|
158
|
+
}
|
|
159
|
+
var EXTENSION_OUTPUT = /^x-[a-z][a-z0-9-]{0,31}\/[a-z][a-z0-9-]{0,31}$/;
|
|
160
|
+
function isExtensionOutput(name) {
|
|
161
|
+
return typeof name === "string" && EXTENSION_OUTPUT.test(name);
|
|
162
|
+
}
|
|
163
|
+
function checkOutput(name, data, schema) {
|
|
164
|
+
const found = outputValidator(name);
|
|
165
|
+
if (found) return found.check(data);
|
|
166
|
+
if (isExtensionOutput(name)) {
|
|
167
|
+
if (schema === void 0) return { ok: false, problems: [`"${name}" is an extension output and its source states no outputSchema`] };
|
|
168
|
+
const checked = fromJSONSchema(schema).safeParse(data);
|
|
169
|
+
return checked.success ? { ok: true, value: checked.data } : { ok: false, problems: problemsOf(checked.error) };
|
|
170
|
+
}
|
|
171
|
+
return { ok: false, problems: [`"${name}" is not a registered output (${OUTPUT_NAMES.join(", ")})`] };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export {
|
|
175
|
+
IMAGE_DATA_URI_MAX,
|
|
176
|
+
OUTPUTS,
|
|
177
|
+
OUTPUT_NAMES,
|
|
178
|
+
isOutputName,
|
|
179
|
+
outputValidator,
|
|
180
|
+
EXTENSION_OUTPUT,
|
|
181
|
+
isExtensionOutput,
|
|
182
|
+
checkOutput
|
|
183
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @we-the-rebel-alliance/source-contract 0.1.0. Built by scripts/build.mjs; do not edit.
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
__export
|
|
10
|
+
};
|