@joe-broadhead/opencode-mem 0.9.14 → 0.11.3
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 +1856 -0
- package/README.md +15 -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 +8921 -1070
- 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 +88 -7
- 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 +74 -23
- package/src/tools/held-write.js +46 -19
- package/src/tools/index.js +28 -0
- package/src/tools/ingest.js +38 -2
- package/src/tools/memory.js +56 -25
- package/src/tools/page.js +212 -95
- package/src/tools/recall.js +218 -4
- package/src/tools/share.js +42 -3
- package/src/tools/shared.js +84 -6
- package/src/tools/space-lifecycle.js +278 -0
- package/src/tools/spaces.js +381 -30
- package/src/tools/status.js +9 -2
- package/src/tools/wiki.js +231 -116
- 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 +1082 -23
- package/src/views/inbox-bytes.js +103 -0
- package/src/views/profile.js +31 -0
- package/src/views/receipt.js +26 -1
- package/src/views/records-reads.js +520 -41
- package/src/views/rpc.js +153 -25
- package/src/views/shape.js +8 -5
- package/src/views/write-state.js +89 -0
- package/src/wiki-ingest.js +215 -0
- package/src/wiki-state.js +228 -0
- package/views/pages.html +2 -2
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// @we-the-rebel-alliance/source-contract 0.1.0. Built by scripts/build.mjs; do not edit.
|
|
2
|
+
import {
|
|
3
|
+
SOURCES_SCHEMA
|
|
4
|
+
} from "./chunk-RRUAIQ4I.js";
|
|
5
|
+
import {
|
|
6
|
+
SUPPORTED_CONTRACT_VERSIONS
|
|
7
|
+
} from "./chunk-ELPJD3ND.js";
|
|
8
|
+
import {
|
|
9
|
+
EVENT_KINDS,
|
|
10
|
+
MAX_BYTES,
|
|
11
|
+
isEventKind
|
|
12
|
+
} from "./chunk-ZUKF7P6U.js";
|
|
13
|
+
import {
|
|
14
|
+
OUTPUT_NAMES,
|
|
15
|
+
isExtensionOutput,
|
|
16
|
+
isOutputName
|
|
17
|
+
} from "./chunk-6HDIB2SA.js";
|
|
18
|
+
import {
|
|
19
|
+
_enum,
|
|
20
|
+
array,
|
|
21
|
+
boolean,
|
|
22
|
+
looseObject,
|
|
23
|
+
number,
|
|
24
|
+
object,
|
|
25
|
+
problemsOf,
|
|
26
|
+
record,
|
|
27
|
+
string,
|
|
28
|
+
unknown
|
|
29
|
+
} from "./chunk-W5SHR7DQ.js";
|
|
30
|
+
|
|
31
|
+
// src/descriptor.ts
|
|
32
|
+
import { createHash } from "node:crypto";
|
|
33
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
34
|
+
import { dirname, join } from "node:path";
|
|
35
|
+
var MAX_BYTES_LIMIT = MAX_BYTES.max;
|
|
36
|
+
var DEFAULT_MAX_BYTES = MAX_BYTES.default;
|
|
37
|
+
var SOURCE_ID = /^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+$/;
|
|
38
|
+
var METHOD = /^[A-Za-z0-9_.-]{1,100}$/;
|
|
39
|
+
var ACTION = /^[A-Za-z0-9_.-]{1,200}$/;
|
|
40
|
+
var OPERATION = /^[A-Za-z0-9_.-]{1,200}$/;
|
|
41
|
+
var DETAIL_FIELDS = ["external_id", "kind", "occurred_at", "url", "thread", "actors", "labels", "hash"];
|
|
42
|
+
var action = string().regex(ACTION, "must be a permission action, such as gws.events_list");
|
|
43
|
+
var operation = string().regex(OPERATION, "must be an operation name of letters, digits, dots, underscores or hyphens");
|
|
44
|
+
var price = object({ per: string().min(1).max(40), usd: number().nonnegative().finite() });
|
|
45
|
+
var item = looseObject({
|
|
46
|
+
id: string().regex(SOURCE_ID, "must be the plugin's name and the source's, dotted and lowercase, such as gws.gmail"),
|
|
47
|
+
kind: _enum(["events", "snapshot"]),
|
|
48
|
+
tool: string().regex(METHOD, "must be a tools-RPC method name"),
|
|
49
|
+
input: record(string(), unknown()).optional(),
|
|
50
|
+
// PROVISIONAL (app#2346 decisions D13 and D15, PR #7): one event kind, core or x-<plugin>/<kind>. Whether `reads`
|
|
51
|
+
// takes a list, and whether an extension's <plugin> must match the descriptor's, are not agreed yet.
|
|
52
|
+
reads: string().refine(isEventKind, `must be an event kind: ${EVENT_KINDS.join(", ")}, or x-<plugin>/<kind>`).optional(),
|
|
53
|
+
output: string().optional(),
|
|
54
|
+
params: record(string(), looseObject({ relative: boolean().optional(), me: boolean().optional() })).optional(),
|
|
55
|
+
accounts: looseObject({ named: boolean().optional() }).optional(),
|
|
56
|
+
scope: looseObject({ keys: array(string().regex(/^[a-z][a-zA-Z0-9_-]{0,39}$/)).min(1), describe: string().max(200).optional() }).optional(),
|
|
57
|
+
details: array(
|
|
58
|
+
looseObject({
|
|
59
|
+
id: string().regex(SOURCE_ID),
|
|
60
|
+
tool: string().regex(METHOD),
|
|
61
|
+
from: array(_enum(DETAIL_FIELDS)).min(1)
|
|
62
|
+
})
|
|
63
|
+
).optional(),
|
|
64
|
+
permission: looseObject({
|
|
65
|
+
events: action.optional(),
|
|
66
|
+
tool: action.optional(),
|
|
67
|
+
operations: array(operation).min(1, "must name at least one operation: grants and off switches key on them").optional(),
|
|
68
|
+
// A provider whose resources are method-and-path (GitHub's `github_api` on `GET /user`) states its grants
|
|
69
|
+
// verbatim; `operationRule` derives from `operations` for every other provider (#4, from the github plugin).
|
|
70
|
+
rules: array(object({ action, resource: string().min(1).max(200) })).min(1).optional()
|
|
71
|
+
}),
|
|
72
|
+
private: boolean().optional(),
|
|
73
|
+
cost: looseObject({ class: _enum(["free", "metered", "billed"]), units: array(price).optional(), probe: price.optional() }),
|
|
74
|
+
cadence: looseObject({ providerMinMinutes: number().int().positive().optional() }).optional(),
|
|
75
|
+
maxBytes: number().int().positive().max(MAX_BYTES_LIMIT, `must be at most ${MAX_BYTES_LIMIT} (1 MB)`).optional(),
|
|
76
|
+
maxAgeSec: number().int().positive().optional(),
|
|
77
|
+
retentionDays: number().int().positive().optional(),
|
|
78
|
+
urlHosts: array(string().min(1).max(253)).optional()
|
|
79
|
+
}).superRefine((source, context) => {
|
|
80
|
+
const problem = (path, message) => context.addIssue({ code: "custom", path, message });
|
|
81
|
+
if (source.kind === "events") {
|
|
82
|
+
if (source.reads === void 0) problem(["reads"], "an events source must say which event kind it reads");
|
|
83
|
+
if (source.permission.events === void 0) problem(["permission", "events"], "an events source must name its method's action");
|
|
84
|
+
if (source.output !== void 0) problem(["output"], "only a snapshot source has an output");
|
|
85
|
+
} else {
|
|
86
|
+
if (source.output === void 0) problem(["output"], `a snapshot source must name its output (${OUTPUT_NAMES.join(", ")})`);
|
|
87
|
+
else if (!isOutputName(source.output) && !isExtensionOutput(source.output)) {
|
|
88
|
+
problem(["output"], `"${source.output}" is not a registered output (${OUTPUT_NAMES.join(", ")}) and not an x-<namespace>/<name>`);
|
|
89
|
+
}
|
|
90
|
+
if (source.permission.tool === void 0) problem(["permission", "tool"], "a snapshot source must name its method's action");
|
|
91
|
+
if (source.details !== void 0) problem(["details"], "only an events source has detail reads");
|
|
92
|
+
}
|
|
93
|
+
if (source.permission.events !== void 0 && source.permission.tool !== void 0) problem(["permission"], "name one method action: events or tool, not both");
|
|
94
|
+
if (source.cost?.class === "billed" && (source.cost.units === void 0 || source.cost.units.length === 0)) {
|
|
95
|
+
problem(["cost", "units"], "a billed source must state its price units");
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
var TOOLS_RPC_ID = /^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)*\.tools$/;
|
|
99
|
+
var sources = looseObject({
|
|
100
|
+
rpc: string().regex(TOOLS_RPC_ID, "must be a tools-RPC id: the plugin id and .tools, such as google-workspace.gws.tools").optional(),
|
|
101
|
+
probe: looseObject({ action }).optional(),
|
|
102
|
+
contractVersion: number().int().refine((version) => SUPPORTED_CONTRACT_VERSIONS.includes(version), {
|
|
103
|
+
message: `must be a contract version this package reads (${SUPPORTED_CONTRACT_VERSIONS.join(", ")})`
|
|
104
|
+
}),
|
|
105
|
+
items: array(item).min(1, "must declare at least one source")
|
|
106
|
+
}).superRefine((value, context) => {
|
|
107
|
+
const seen = /* @__PURE__ */ new Set();
|
|
108
|
+
for (const [index, source] of value.items.entries()) {
|
|
109
|
+
for (const id of [source.id, ...(source.details ?? []).map((detail) => detail.id)]) {
|
|
110
|
+
if (seen.has(id)) context.addIssue({ code: "custom", path: ["items", index, "id"], message: `"${id}" is declared twice` });
|
|
111
|
+
seen.add(id);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
function checkSources(value) {
|
|
116
|
+
const schema = SOURCES_SCHEMA.check(value);
|
|
117
|
+
if (!schema.ok) return { ok: false, problems: schema.problems.map((problem) => `sources.${problem}`.replace("sources.the value", "sources")) };
|
|
118
|
+
const result = sources.safeParse(value);
|
|
119
|
+
if (result.success) return { ok: true, value };
|
|
120
|
+
return { ok: false, problems: problemsOf(result.error).map((problem) => `sources.${problem}`.replace("sources.the value", "sources")) };
|
|
121
|
+
}
|
|
122
|
+
function canonicalJson(value) {
|
|
123
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
124
|
+
if (typeof value === "object" && value !== null) {
|
|
125
|
+
const entries = Object.keys(value).sort().filter((key) => value[key] !== void 0).map((key) => `${JSON.stringify(key)}:${canonicalJson(value[key])}`);
|
|
126
|
+
return `{${entries.join(",")}}`;
|
|
127
|
+
}
|
|
128
|
+
return JSON.stringify(value) ?? "null";
|
|
129
|
+
}
|
|
130
|
+
function descriptorHash(value) {
|
|
131
|
+
return `sha256:${createHash("sha256").update(canonicalJson(value)).digest("hex")}`;
|
|
132
|
+
}
|
|
133
|
+
function readInstalledDescriptor(directory, options = {}) {
|
|
134
|
+
const file = join(directory, "package.json");
|
|
135
|
+
let pkg;
|
|
136
|
+
try {
|
|
137
|
+
pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
138
|
+
} catch (error) {
|
|
139
|
+
const reason = error.code === "ENOENT" ? "there is no package.json there" : "its package.json is not JSON";
|
|
140
|
+
return { ok: false, problems: [`no descriptor at ${directory}: ${reason}`] };
|
|
141
|
+
}
|
|
142
|
+
if (typeof pkg !== "object" || pkg === null || Array.isArray(pkg)) return { ok: false, problems: [`no descriptor at ${directory}: its package.json is not an object`] };
|
|
143
|
+
const { name, version, sources: declared } = pkg;
|
|
144
|
+
if (typeof name !== "string" || typeof version !== "string") return { ok: false, problems: [`no descriptor at ${directory}: its package.json has no name and version`] };
|
|
145
|
+
if (options.version !== void 0 && options.version !== version) {
|
|
146
|
+
return { ok: false, problems: [`${name} at ${directory} is version ${version}, not the ${options.version} the install names`] };
|
|
147
|
+
}
|
|
148
|
+
if (declared === void 0) return { ok: false, problems: [`${name} ${version} declares no sources (no top-level "sources" key)`] };
|
|
149
|
+
const checked = checkSources(declared);
|
|
150
|
+
if (!checked.ok) return { ok: false, problems: checked.problems.map((problem) => `${name} ${version}: ${problem}`) };
|
|
151
|
+
return { ok: true, value: { package: name, version, directory, sources: checked.value, hash: descriptorHash(declared) } };
|
|
152
|
+
}
|
|
153
|
+
function findInstalledPackage(name, from) {
|
|
154
|
+
if (!/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/.test(name)) return void 0;
|
|
155
|
+
let directory = from;
|
|
156
|
+
for (; ; ) {
|
|
157
|
+
const candidate = join(directory, "node_modules", ...name.split("/"));
|
|
158
|
+
if (existsSync(join(candidate, "package.json"))) return candidate;
|
|
159
|
+
const parent = dirname(directory);
|
|
160
|
+
if (parent === directory) return void 0;
|
|
161
|
+
directory = parent;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function findSource(descriptor, id) {
|
|
165
|
+
return descriptor.items.find((source) => source.id === id);
|
|
166
|
+
}
|
|
167
|
+
function maxBytesOf(source) {
|
|
168
|
+
return source.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export {
|
|
172
|
+
MAX_BYTES_LIMIT,
|
|
173
|
+
DEFAULT_MAX_BYTES,
|
|
174
|
+
DETAIL_FIELDS,
|
|
175
|
+
checkSources,
|
|
176
|
+
canonicalJson,
|
|
177
|
+
descriptorHash,
|
|
178
|
+
readInstalledDescriptor,
|
|
179
|
+
findInstalledPackage,
|
|
180
|
+
findSource,
|
|
181
|
+
maxBytesOf
|
|
182
|
+
};
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
// @we-the-rebel-alliance/source-contract 0.1.0. Built by scripts/build.mjs; do not edit.
|
|
2
|
+
import {
|
|
3
|
+
findSource,
|
|
4
|
+
maxBytesOf
|
|
5
|
+
} from "./chunk-KYWBTAF4.js";
|
|
6
|
+
import {
|
|
7
|
+
ERROR_CODES,
|
|
8
|
+
PAGE,
|
|
9
|
+
canonicalCode,
|
|
10
|
+
probeResultProblems,
|
|
11
|
+
resultProblems
|
|
12
|
+
} from "./chunk-ZUKF7P6U.js";
|
|
13
|
+
import {
|
|
14
|
+
canonicalScope
|
|
15
|
+
} from "./chunk-I2RXJJJM.js";
|
|
16
|
+
import {
|
|
17
|
+
resolveParams,
|
|
18
|
+
resolveSince
|
|
19
|
+
} from "./chunk-RYNKNCPP.js";
|
|
20
|
+
import {
|
|
21
|
+
detailRules,
|
|
22
|
+
grantCovers,
|
|
23
|
+
probeRules,
|
|
24
|
+
sessionRules
|
|
25
|
+
} from "./chunk-3M5PAKSS.js";
|
|
26
|
+
import {
|
|
27
|
+
pick,
|
|
28
|
+
pickProblemsForOutput
|
|
29
|
+
} from "./chunk-4ERCA4TK.js";
|
|
30
|
+
import {
|
|
31
|
+
checkOutput
|
|
32
|
+
} from "./chunk-6HDIB2SA.js";
|
|
33
|
+
|
|
34
|
+
// src/internal/failure.ts
|
|
35
|
+
var FAILURE_CODES = ERROR_CODES;
|
|
36
|
+
function failure(code, what, next, retryAfterSec) {
|
|
37
|
+
return {
|
|
38
|
+
code,
|
|
39
|
+
message: `${code}: ${what.replace(/[.\s]+$/, "")}. Next step: ${next}`,
|
|
40
|
+
next,
|
|
41
|
+
...retryAfterSec === void 0 ? {} : { retryAfterSec }
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function failureFromError(error) {
|
|
45
|
+
const record = typeof error === "object" && error !== null ? error : {};
|
|
46
|
+
const data = typeof record["data"] === "object" && record["data"] !== null ? record["data"] : {};
|
|
47
|
+
const message = typeof record["message"] === "string" ? record["message"] : String(error);
|
|
48
|
+
const raw = [record["code"], data["code"], /^([A-Z][A-Z_]+):/.exec(message)?.[1]].find((code2) => typeof code2 === "string");
|
|
49
|
+
const canonical = raw === void 0 ? void 0 : canonicalCode(raw);
|
|
50
|
+
const refusedInput = canonical === "INPUT_INVALID" || canonical === "SOURCE_UNKNOWN";
|
|
51
|
+
const code = canonical !== void 0 && FAILURE_CODES.includes(canonical) ? canonical : void 0;
|
|
52
|
+
const first = message.split(/\r?\n/, 1)[0].slice(0, 300);
|
|
53
|
+
const fallback = refusedInput ? "Check the source's descriptor against the installed plugin's version; if they match, report it to the plugin's maintainers." : "Try again later; if it keeps failing, check the plugin's status.";
|
|
54
|
+
const next = typeof data["next"] === "string" ? data["next"] : /Next step: (.*)$/.exec(first)?.[1] ?? fallback;
|
|
55
|
+
const what = first.replace(/^[A-Z][A-Z_]+:\s*/, "").replace(/\s*Next step:.*$/, "");
|
|
56
|
+
const retry = typeof record["retryAfterSec"] === "number" ? record["retryAfterSec"] : typeof data["retryAfterSec"] === "number" ? data["retryAfterSec"] : void 0;
|
|
57
|
+
return failure(code ?? "UNAVAILABLE", what || "the read failed", next, retry);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/read.ts
|
|
61
|
+
var rpcOf = (installed) => installed.sources.rpc === void 0 ? {} : { rpc: installed.sources.rpc };
|
|
62
|
+
var plain = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
63
|
+
var refused = (code, what, next) => ({ ok: false, failure: failure(code, what, next) });
|
|
64
|
+
var bytes = (value) => new TextEncoder().encode(JSON.stringify(value)).length;
|
|
65
|
+
function checkReadRequest(request) {
|
|
66
|
+
const { installed, grant } = request;
|
|
67
|
+
const source = findSource(installed.sources, request.source);
|
|
68
|
+
if (!source) return refused("UNAVAILABLE", `${installed.package} ${installed.version} declares no source ${request.source}`, "Check the source id against the installed plugin's sources.");
|
|
69
|
+
if (grant.disabled) return refused("SOURCE_DISABLED", `${source.id} is turned off for ${grant.consumer}`, "Turn the source on again to read it.");
|
|
70
|
+
if (grant.consumer !== request.consumer) return refused("PERMISSION_DENIED", `the grant is ${grant.consumer}'s, not ${request.consumer}'s`, "Ask the person to grant this consumer the source.");
|
|
71
|
+
if (grant.descriptorHash !== installed.hash) {
|
|
72
|
+
return refused("PERMISSION_DENIED", `${source.id}'s declaration changed since the person consented`, "Ask the person to review the source and consent again.");
|
|
73
|
+
}
|
|
74
|
+
const asked = request.scope ?? grant.scope;
|
|
75
|
+
if (!grantCovers(grant, { source: source.id, account: grant.account, ...asked === void 0 ? {} : { scope: asked } })) {
|
|
76
|
+
return refused("PERMISSION_DENIED", `the read asks for more of ${source.id} than the person granted`, "Read within the granted scope, or ask the person to widen it.");
|
|
77
|
+
}
|
|
78
|
+
const scope = asked === void 0 ? void 0 : canonicalScope(asked);
|
|
79
|
+
if (source.kind === "events") {
|
|
80
|
+
if (request.params !== void 0 || request.pick !== void 0) return refused("SCHEMA_VIOLATION", "params and pick are for a snapshot source", "Pass cursor, since and limit to an events source.");
|
|
81
|
+
} else {
|
|
82
|
+
if (request.cursor !== void 0 || request.since !== void 0 || request.limit !== void 0) {
|
|
83
|
+
return refused("SCHEMA_VIOLATION", "cursor, since and limit are for an events source", "Pass params and pick to a snapshot source.");
|
|
84
|
+
}
|
|
85
|
+
if (request.pick !== void 0) {
|
|
86
|
+
const problems = pickProblemsForOutput(source.output ?? "", request.pick, source.outputSchema);
|
|
87
|
+
if (problems.length > 0) return refused("SCHEMA_VIOLATION", problems.join("; "), "Pick only paths of the source's output schema.");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return { source, ...scope === void 0 ? {} : { scope } };
|
|
91
|
+
}
|
|
92
|
+
function prepare(request) {
|
|
93
|
+
const checked = checkReadRequest(request);
|
|
94
|
+
if ("ok" in checked) return checked;
|
|
95
|
+
const { source, scope } = checked;
|
|
96
|
+
const input = { ...source.input ?? {}, account: request.grant.account };
|
|
97
|
+
if (scope !== void 0) input["scope"] = scope;
|
|
98
|
+
if (source.kind === "events") {
|
|
99
|
+
if (request.since !== void 0) {
|
|
100
|
+
const since = resolveSince(request.since, request.context);
|
|
101
|
+
if (!since.ok) return refused("SCHEMA_VIOLATION", since.problems.join("; "), "Pass since as a relative time such as -7d, or an ISO date-time.");
|
|
102
|
+
input["since"] = since.value;
|
|
103
|
+
}
|
|
104
|
+
if (request.cursor !== void 0) input["cursor"] = request.cursor;
|
|
105
|
+
if (request.limit !== void 0) input["limit"] = request.limit;
|
|
106
|
+
return { source, input };
|
|
107
|
+
}
|
|
108
|
+
const params = resolveParams(source.params, request.params, request.context);
|
|
109
|
+
if (!params.ok) return refused("SCHEMA_VIOLATION", params.problems.join("; "), "Pass only the params the source declares, as its descriptor describes them.");
|
|
110
|
+
return { source, input: { ...input, ...params.value } };
|
|
111
|
+
}
|
|
112
|
+
function checkAnswer(source, account, answer) {
|
|
113
|
+
const size = bytes(answer);
|
|
114
|
+
if (size > maxBytesOf(source)) return failure("TOO_LARGE", `${source.id} answered ${size} bytes, over its ${maxBytesOf(source)}`, "Read a smaller window or fewer items.");
|
|
115
|
+
if (!plain(answer)) return failure("SCHEMA_VIOLATION", `${source.id} answered something that is not an object`, "Report it to the plugin's maintainers.");
|
|
116
|
+
if (answer["trust"] !== "untrusted") return failure("SCHEMA_VIOLATION", `${source.id}'s answer is not marked trust: "untrusted"`, "Report it to the plugin's maintainers.");
|
|
117
|
+
if (answer["account"] !== void 0 && answer["account"] !== account) {
|
|
118
|
+
return failure("ACCOUNT_MISMATCH", `${source.id} answered for another account than the one granted`, "Sign the plugin in to the granted account, or ask the person to grant this one.");
|
|
119
|
+
}
|
|
120
|
+
return void 0;
|
|
121
|
+
}
|
|
122
|
+
async function fencedCall(host, rules, call, title) {
|
|
123
|
+
if (!rules.ok) return { ok: false, failure: failure("PERMISSION_DENIED", rules.problems.join("; "), "Fix the source's declaration or the grant.") };
|
|
124
|
+
let session;
|
|
125
|
+
try {
|
|
126
|
+
session = await host.openSession({ rules: rules.value, title });
|
|
127
|
+
return { ok: true, answer: await host.call({ ...call, sessionID: session.sessionID }) };
|
|
128
|
+
} catch (error) {
|
|
129
|
+
return { ok: false, failure: failureFromError(error) };
|
|
130
|
+
} finally {
|
|
131
|
+
await session?.close().catch(() => void 0);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async function read(host, request) {
|
|
135
|
+
const prepared = prepare(request);
|
|
136
|
+
if ("ok" in prepared) return prepared;
|
|
137
|
+
const { source, input } = prepared;
|
|
138
|
+
const called = await fencedCall(
|
|
139
|
+
host,
|
|
140
|
+
sessionRules(source, request.grant),
|
|
141
|
+
{ package: request.installed.package, ...rpcOf(request.installed), method: source.tool, input, ...request.signal ? { signal: request.signal } : {} },
|
|
142
|
+
`${request.consumer} reads ${source.id}`
|
|
143
|
+
);
|
|
144
|
+
if (!called.ok) return { ok: false, failure: called.failure };
|
|
145
|
+
return acceptAnswer(source, request.grant.account, called.answer, {
|
|
146
|
+
...request.limit === void 0 ? {} : { limit: request.limit },
|
|
147
|
+
...request.pick === void 0 ? {} : { pick: request.pick }
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function acceptAnswer(source, account, answer, options = {}) {
|
|
151
|
+
const problem = checkAnswer(source, account, answer);
|
|
152
|
+
if (problem) return { ok: false, failure: problem };
|
|
153
|
+
const value = answer;
|
|
154
|
+
if (source.kind === "events") {
|
|
155
|
+
const problems = resultProblems(value, options.limit ?? PAGE.max, maxBytesOf(source));
|
|
156
|
+
if (problems.length > 0) {
|
|
157
|
+
return { ok: false, failure: failure("SCHEMA_VIOLATION", `${source.id}'s page breaks the events contract: ${problems.slice(0, 3).join("; ")}`, "Report it to the plugin's maintainers.") };
|
|
158
|
+
}
|
|
159
|
+
return { ok: true, kind: "events", page: value };
|
|
160
|
+
}
|
|
161
|
+
const checked = checkOutput(source.output ?? "", value["data"], source.outputSchema);
|
|
162
|
+
if (!checked.ok) return { ok: false, failure: failure("SCHEMA_VIOLATION", `${source.id}'s data breaks the ${source.output} schema: ${checked.problems.slice(0, 3).join("; ")}`, "Report it to the plugin's maintainers.") };
|
|
163
|
+
if (typeof value["asOf"] !== "string" || !Number.isFinite(Date.parse(value["asOf"]))) {
|
|
164
|
+
return { ok: false, failure: failure("SCHEMA_VIOLATION", `${source.id}'s snapshot has no asOf time`, "Report it to the plugin's maintainers.") };
|
|
165
|
+
}
|
|
166
|
+
let picked = value["data"];
|
|
167
|
+
if (options.pick !== void 0) {
|
|
168
|
+
const kept = pick(picked, options.pick);
|
|
169
|
+
picked = kept.ok ? kept.data : {};
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
ok: true,
|
|
173
|
+
kind: "snapshot",
|
|
174
|
+
snapshot: { data: picked, asOf: value["asOf"], ...value["cost"] === void 0 ? {} : { cost: value["cost"] }, trust: "untrusted" }
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function detailFields(source, detailId, event) {
|
|
178
|
+
const detail = source.details?.find((entry) => entry.id === detailId);
|
|
179
|
+
if (!detail) return { ok: false, problems: [`${source.id} declares no detail read ${detailId}`] };
|
|
180
|
+
const fields = {};
|
|
181
|
+
const problems = [];
|
|
182
|
+
for (const field of detail.from) {
|
|
183
|
+
if (event[field] === void 0 || event[field] === null) problems.push(`the event has no ${field} for ${detailId}`);
|
|
184
|
+
else fields[field] = event[field];
|
|
185
|
+
}
|
|
186
|
+
return problems.length === 0 ? { ok: true, value: fields } : { ok: false, problems };
|
|
187
|
+
}
|
|
188
|
+
async function readDetail(host, request) {
|
|
189
|
+
const { installed, grant } = request;
|
|
190
|
+
const source = findSource(installed.sources, request.source);
|
|
191
|
+
if (!source) return { ok: false, failure: failure("UNAVAILABLE", `${installed.package} declares no source ${request.source}`, "Check the source id.") };
|
|
192
|
+
if (grant.disabled) return { ok: false, failure: failure("SOURCE_DISABLED", `${source.id} is turned off for ${grant.consumer}`, "Turn the source on again to read it.") };
|
|
193
|
+
if (grant.consumer !== request.consumer || grant.descriptorHash !== installed.hash) {
|
|
194
|
+
return { ok: false, failure: failure("PERMISSION_DENIED", `the grant does not cover ${request.consumer}'s read of ${source.id} as installed`, "Ask the person to consent again.") };
|
|
195
|
+
}
|
|
196
|
+
if (request.event["account"] !== void 0 && request.event["account"] !== grant.account) {
|
|
197
|
+
return { ok: false, failure: failure("ACCOUNT_MISMATCH", "the event is another account's", "Read details only for events of the granted account.") };
|
|
198
|
+
}
|
|
199
|
+
const fields = detailFields(source, request.detail, request.event);
|
|
200
|
+
if (!fields.ok) return { ok: false, failure: failure("SCHEMA_VIOLATION", fields.problems.join("; "), "Read details only for events the source listed.") };
|
|
201
|
+
const detail = source.details.find((entry) => entry.id === request.detail);
|
|
202
|
+
const scope = grant.scope === void 0 ? {} : canonicalScope(grant.scope);
|
|
203
|
+
const called = await fencedCall(
|
|
204
|
+
host,
|
|
205
|
+
detailRules(source, request.detail, grant),
|
|
206
|
+
{ package: installed.package, ...rpcOf(installed), method: detail.tool, input: { account: grant.account, scope, fields: fields.value }, ...request.signal ? { signal: request.signal } : {} },
|
|
207
|
+
`${request.consumer} reads ${request.detail}`
|
|
208
|
+
);
|
|
209
|
+
if (!called.ok) return called;
|
|
210
|
+
const problem = checkAnswer(source, grant.account, called.answer);
|
|
211
|
+
return problem ? { ok: false, failure: problem } : { ok: true, answer: called.answer };
|
|
212
|
+
}
|
|
213
|
+
async function probe(host, request) {
|
|
214
|
+
const source = findSource(request.installed.sources, request.source);
|
|
215
|
+
if (!source) return { ok: false, failure: failure("UNAVAILABLE", `${request.installed.package} declares no source ${request.source}`, "Check the source id.") };
|
|
216
|
+
const declared = source.permission.identity;
|
|
217
|
+
const identity = declared ?? request.identityOperations;
|
|
218
|
+
if (identity === void 0) {
|
|
219
|
+
return { ok: false, failure: failure("PERMISSION_DENIED", `${source.id} declares no identity operations, and none were given`, "Declare permission.identity in the source, or pass the identity operations.") };
|
|
220
|
+
}
|
|
221
|
+
const name = typeof source.input?.["source"] === "string" ? { source: source.input["source"] } : {};
|
|
222
|
+
const called = await fencedCall(
|
|
223
|
+
host,
|
|
224
|
+
probeRules(source, request.account, identity, request.installed.sources.probe?.action),
|
|
225
|
+
{ package: request.installed.package, ...rpcOf(request.installed), method: "probe", input: { ...name, account: request.account }, ...request.signal ? { signal: request.signal } : {} },
|
|
226
|
+
`probe ${source.id}`
|
|
227
|
+
);
|
|
228
|
+
if (!called.ok) return called;
|
|
229
|
+
const answer = called.answer;
|
|
230
|
+
if (plain(answer) && answer["owner"] === null) {
|
|
231
|
+
return { ok: false, failure: failure("NEEDS_SIGN_IN", `${source.id} is not signed in`, "Sign the plugin in to the account you mean. A probe refuses with NEEDS_SIGN_IN; it never answers owner: null.") };
|
|
232
|
+
}
|
|
233
|
+
if (plain(answer) && typeof answer["account"] === "string" && answer["account"] !== request.account) return { ok: false, failure: failure("ACCOUNT_MISMATCH", `${source.id} is signed in to another account`, "Sign the plugin in to the account you mean.") };
|
|
234
|
+
const problems = probeResultProblems(answer, { ...typeof source.input?.["source"] === "string" ? { source: source.input["source"] } : {}, account: request.account });
|
|
235
|
+
if (problems.length > 0) {
|
|
236
|
+
return { ok: false, failure: failure("SCHEMA_VIOLATION", `${source.id}'s probe answer is not the contract's: ${problems[0]}`, "Report it to the plugin's maintainers.") };
|
|
237
|
+
}
|
|
238
|
+
return { ok: true, answer };
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export {
|
|
242
|
+
failureFromError,
|
|
243
|
+
checkReadRequest,
|
|
244
|
+
read,
|
|
245
|
+
acceptAnswer,
|
|
246
|
+
detailFields,
|
|
247
|
+
readDetail,
|
|
248
|
+
probe
|
|
249
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// @we-the-rebel-alliance/source-contract 0.1.0. Built by scripts/build.mjs; do not edit.
|
|
2
|
+
import {
|
|
3
|
+
isToolsRpcId
|
|
4
|
+
} from "./chunk-KWEWSZ4V.js";
|
|
5
|
+
import {
|
|
6
|
+
isEventKind
|
|
7
|
+
} from "./chunk-ZUKF7P6U.js";
|
|
8
|
+
import {
|
|
9
|
+
_enum,
|
|
10
|
+
array,
|
|
11
|
+
boolean,
|
|
12
|
+
discriminatedUnion,
|
|
13
|
+
int,
|
|
14
|
+
literal,
|
|
15
|
+
looseObject,
|
|
16
|
+
never,
|
|
17
|
+
number,
|
|
18
|
+
object,
|
|
19
|
+
string,
|
|
20
|
+
union,
|
|
21
|
+
validator
|
|
22
|
+
} from "./chunk-W5SHR7DQ.js";
|
|
23
|
+
|
|
24
|
+
// src/internal/schema/types.ts
|
|
25
|
+
var MAX_BYTES_DEFAULT = 65536;
|
|
26
|
+
var MAX_BYTES_LIMIT = 1048576;
|
|
27
|
+
|
|
28
|
+
// src/internal/schema/sources.ts
|
|
29
|
+
var SOURCE_ID = /^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/;
|
|
30
|
+
var TOOL_NAME = /^[a-z][a-z0-9_]{0,63}$/;
|
|
31
|
+
var ACTION = /^(?:[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*|[a-z][a-z0-9]*_[a-z][a-z0-9_]*)$/;
|
|
32
|
+
var OPERATION = /^[A-Za-z][A-Za-z0-9._-]{0,199}$/;
|
|
33
|
+
var SCOPE_KEY = /^[a-z][a-z0-9_]{0,31}$/;
|
|
34
|
+
var REGISTRY_NAME = /^[a-z][a-z0-9-]{0,31}$/;
|
|
35
|
+
var isOutputName = (name) => REGISTRY_NAME.test(name) || isEventKind(name);
|
|
36
|
+
var PRICE_PER = /^[a-z][a-z0-9-]{0,31}$/;
|
|
37
|
+
var HOST = /^(?:\*\.)?[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/;
|
|
38
|
+
var price = object({
|
|
39
|
+
per: string().max(32).regex(PRICE_PER, { error: "must be a lowercase word such as post, author or call" }),
|
|
40
|
+
usd: number().min(0)
|
|
41
|
+
}).strict().describe("One price unit, in US dollars, from the plugin's own price table.");
|
|
42
|
+
var units = array(price).min(1);
|
|
43
|
+
var freeCost = object({
|
|
44
|
+
class: literal("free"),
|
|
45
|
+
units: never({ error: "a free source states no price units" }).optional(),
|
|
46
|
+
probe: never({ error: "a free source states no probe cost" }).optional()
|
|
47
|
+
}).strict();
|
|
48
|
+
var meteredCost = object({ class: literal("metered"), units, probe: price.optional() }).strict();
|
|
49
|
+
var billedCost = object({ class: literal("billed"), units, probe: price }).strict();
|
|
50
|
+
var cost = discriminatedUnion("class", [freeCost, meteredCost, billedCost], { error: "must be free, metered or billed" }).describe("What one read costs, including a probe call, which reads no content.");
|
|
51
|
+
var accounts = object({ named: boolean().describe("True when the source reads more than one account, so a read names one.") }).strict().describe("Which signed-in accounts a source reads.");
|
|
52
|
+
var scope = object({
|
|
53
|
+
keys: array(string().max(32).regex(SCOPE_KEY, { error: "must be a lowercase scope key such as channels" })).describe("The scope keys a person confirms: labels, channels, repositories. Empty when there is nothing to choose."),
|
|
54
|
+
describe: string().max(200).describe("The sentence shown at consent, such as Which labels."),
|
|
55
|
+
suggest: object({
|
|
56
|
+
tool: string().max(64).regex(TOOL_NAME, { error: "must be a tool name" }),
|
|
57
|
+
operations: array(string().max(200).regex(OPERATION, { error: "must be a provider operation or an MCP tool name" })).min(1)
|
|
58
|
+
}).strict().optional().describe(
|
|
59
|
+
"The read-only tool that lists the values a person may pick, and the operations it asserts. It runs only at bind, in the probe session; its results are shown and never stored, so its operations never enter a running grant."
|
|
60
|
+
)
|
|
61
|
+
}).strict().describe("What a person confirms at consent, and the sentence that asks them.");
|
|
62
|
+
var detail = object({
|
|
63
|
+
id: string().max(64).regex(SOURCE_ID, { error: "must be a dotted id such as gws.gmail.message" }),
|
|
64
|
+
tool: string().max(64).regex(TOOL_NAME, { error: "must be a tool name" }),
|
|
65
|
+
from: array(_enum(["external_id", "kind", "occurred_at", "url", "thread", "actors", "labels", "hash"])).min(1).describe("The event fields the detail's input comes from. Identifiers only: an event's title and text are never an input.")
|
|
66
|
+
}).strict().describe("One read of an event's detail: the tool, and the event fields its input comes from.");
|
|
67
|
+
var permissionBase = {
|
|
68
|
+
identity: array(string().max(200).regex(OPERATION, { error: "must be a provider operation or an MCP tool name" })).min(1).optional().describe("The identity operations probe asserts for this source (#4, #8); each is among permission.operations, and no content read asserts it."),
|
|
69
|
+
operations: array(string().max(200).regex(OPERATION, { error: "must be a provider operation or an MCP tool name" })).min(1).optional().describe("Every operation the source's reads assert, and nothing else. Absent when `rules` states them."),
|
|
70
|
+
rules: array(
|
|
71
|
+
object({
|
|
72
|
+
action: string().max(80).regex(ACTION, { error: "must be a permission action such as github_api" }),
|
|
73
|
+
resource: string().max(200).describe("The resource the action is asserted on, such as GET /user.")
|
|
74
|
+
}).strict()
|
|
75
|
+
).min(1).optional().describe("The grants verbatim, for a provider whose resources are not <account>:<operation> (GitHub's github_api on GET /user).")
|
|
76
|
+
};
|
|
77
|
+
var permissionEither = (value, ctx) => {
|
|
78
|
+
if (value.operations === void 0 && value.rules === void 0) {
|
|
79
|
+
ctx.addIssue({ code: "custom", message: "a permission states its operations, or its rules verbatim" });
|
|
80
|
+
}
|
|
81
|
+
if (value.operations !== void 0 && value.rules !== void 0) {
|
|
82
|
+
ctx.addIssue({ code: "custom", message: "a permission states operations or rules, not both" });
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var permissionEvents = object({
|
|
86
|
+
events: string().max(80).regex(ACTION, { error: "must be a dotted action such as gws.events_list, or a namespaced tool action such as slack_events_list" }),
|
|
87
|
+
tool: never({ error: "an events source has events, not tool" }).optional(),
|
|
88
|
+
...permissionBase
|
|
89
|
+
}).strict().superRefine(permissionEither).describe("The events_list action, and the provider operations the source asserts.");
|
|
90
|
+
var permissionTool = object({
|
|
91
|
+
tool: string().max(80).regex(ACTION, { error: "must be a dotted action such as gws.calendar_today, or a namespaced tool action" }),
|
|
92
|
+
events: never({ error: "a snapshot has tool, not events" }).optional(),
|
|
93
|
+
...permissionBase
|
|
94
|
+
}).strict().superRefine(permissionEither).describe("The read tool's action, and the provider operations the source asserts.");
|
|
95
|
+
var cadence = object({ providerMinMinutes: int().min(1).max(10080).optional() }).strict().describe("A provider's own floor between reads. Only where the provider imposes one.");
|
|
96
|
+
var urlHosts = array(
|
|
97
|
+
string().max(253).regex(HOST, { error: "must be a host such as slack.com, or *.slack.com" })
|
|
98
|
+
).describe("The hosts an event's url may point at, for display. A consumer renders a url only when its host matches.");
|
|
99
|
+
var common = {
|
|
100
|
+
id: string().max(64).regex(SOURCE_ID, { error: "must be a dotted source id such as gws.gmail" }),
|
|
101
|
+
tool: string().max(64).regex(TOOL_NAME, { error: "must be a tool name" }),
|
|
102
|
+
input: looseObject({}).optional().describe("The input the tool needs to reach this source. It carries no account and no secret."),
|
|
103
|
+
accounts: accounts.optional(),
|
|
104
|
+
scope: scope.optional(),
|
|
105
|
+
private: boolean().optional().describe("True when everything this source reads is personal: shown at consent."),
|
|
106
|
+
cost,
|
|
107
|
+
cadence: cadence.optional(),
|
|
108
|
+
maxBytes: int().min(1).max(MAX_BYTES_LIMIT).optional().meta({ default: MAX_BYTES_DEFAULT }).describe("The most bytes one result may take: default 65536 (64 KB), at most 1048576 (1 MB)."),
|
|
109
|
+
retentionDays: int().min(1).optional().describe("How many days an events consumer keeps what it read."),
|
|
110
|
+
urlHosts: urlHosts.optional()
|
|
111
|
+
};
|
|
112
|
+
var events = object({
|
|
113
|
+
...common,
|
|
114
|
+
kind: literal("events"),
|
|
115
|
+
reads: string().max(64).refine(isEventKind, { error: "must be a core kind such as message, or x-<namespace>/<name>" }).describe("The thing it reads: a core kind, or x-<namespace>/<name>, whose namespace is the source's."),
|
|
116
|
+
details: array(detail).optional(),
|
|
117
|
+
permission: permissionEvents,
|
|
118
|
+
output: never({ error: "an events source has no output: output belongs to a snapshot" }).optional(),
|
|
119
|
+
maxAgeSec: never({ error: "an events source has no maxAgeSec: a snapshot may be reused, an events page is read once" }).optional(),
|
|
120
|
+
params: never({ error: "an events source has no params: events_list takes since, cursor and limit" }).optional()
|
|
121
|
+
}).strict().describe("An events source: append-only, ordered, read with a cursor.");
|
|
122
|
+
var snapshot = object({
|
|
123
|
+
...common,
|
|
124
|
+
kind: literal("snapshot"),
|
|
125
|
+
output: string().max(64).refine(isOutputName, { error: "must be a registry name such as agenda, or x-<namespace>/<name>" }).describe("A registry name, or x-<namespace>/<name>; an x- output carries its schema inline."),
|
|
126
|
+
outputSchema: union([boolean(), looseObject({})]).optional().describe("An x- output's schema, inline: JSON Schema draft 2020-12. Required for x-, absent for a registry name."),
|
|
127
|
+
params: looseObject({}).optional().describe("The parameters a consumer may pass, resolved by the library at read time."),
|
|
128
|
+
permission: permissionTool,
|
|
129
|
+
maxAgeSec: int().min(1).optional().describe("How long a result may be reused before it is read again."),
|
|
130
|
+
reads: never({ error: "a snapshot has no reads: it is state, not a feed" }).optional(),
|
|
131
|
+
details: never({ error: "a snapshot has no details: it has no events to read one of" }).optional()
|
|
132
|
+
}).strict().describe("A snapshot source: the latest state, read on demand.").superRefine((value, ctx) => {
|
|
133
|
+
const extension = value.output.startsWith("x-");
|
|
134
|
+
if (extension && value.outputSchema === void 0) {
|
|
135
|
+
ctx.addIssue({ code: "custom", path: ["outputSchema"], message: "an x- output has no registry schema, so the item carries its outputSchema inline" });
|
|
136
|
+
}
|
|
137
|
+
if (!extension && value.outputSchema !== void 0) {
|
|
138
|
+
ctx.addIssue({ code: "custom", path: ["outputSchema"], message: "a registry output names its schema, so outputSchema belongs only to an x- output" });
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
var source = discriminatedUnion("kind", [events, snapshot]);
|
|
142
|
+
var sourcesSchema = object({
|
|
143
|
+
contractVersion: literal(1),
|
|
144
|
+
rpc: string().max(200).refine(isToolsRpcId, { error: "must be a tools-RPC id: the plugin id and .tools, such as google-workspace.gws.tools" }).optional().describe("The plugin's tools-RPC id (#4, #8), which a consumer calls instead of mapping the package."),
|
|
145
|
+
probe: object({ action: string().max(80).regex(ACTION, { error: "must be a dotted action such as gws.probe" }) }).strict().optional().describe("The plugin's one probe tool, and the permission action it asserts (#4, #8)."),
|
|
146
|
+
items: array(source).min(1).describe("The plugin's sources. A source id is unique across the declaration.")
|
|
147
|
+
}).strict();
|
|
148
|
+
|
|
149
|
+
// src/schema.ts
|
|
150
|
+
var SOURCES_SCHEMA = validator("sources", sourcesSchema);
|
|
151
|
+
|
|
152
|
+
export {
|
|
153
|
+
MAX_BYTES_DEFAULT,
|
|
154
|
+
MAX_BYTES_LIMIT,
|
|
155
|
+
SOURCES_SCHEMA
|
|
156
|
+
};
|