@capybara-hq/kernel 0.1.0-rc.57 → 0.1.0-rc.58
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/dist/admin/extensions.controller.d.ts +2 -10
- package/dist/admin/extensions.controller.js +2 -24
- package/dist/admin/extensions.schemas.d.ts +21 -0
- package/dist/admin/extensions.schemas.js +37 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-extension-switch.d.ts +3 -1
- package/dist/catalog/org-extension-switch.js +12 -5
- package/dist/catalog/org-extension.controller.d.ts +2 -21
- package/dist/catalog/org-extension.controller.js +1 -38
- package/dist/catalog/org-extension.schemas.d.ts +31 -0
- package/dist/catalog/org-extension.schemas.js +65 -0
- package/dist/channels/actions.js +2 -0
- package/dist/channels/cards.d.ts +8 -0
- package/dist/channels/cards.js +18 -0
- package/dist/channels/outbound.js +8 -1
- package/dist/channels/phrases.d.ts +10 -0
- package/dist/channels/phrases.js +10 -0
- package/dist/conversations/conversations.module.js +4 -0
- package/dist/conversations/events.d.ts +1 -0
- package/dist/conversations/events.js +5 -0
- package/dist/conversations/leak-check.d.ts +26 -0
- package/dist/conversations/leak-check.js +69 -0
- package/dist/ctx/secrets.d.ts +5 -0
- package/dist/ctx/secrets.js +5 -0
- package/dist/db/kernel-schema.d.ts +15 -0
- package/dist/errors.d.ts +9 -0
- package/dist/errors.js +9 -0
- package/dist/extensions/deployment-config.d.ts +6 -2
- package/dist/extensions/deployment-config.js +35 -23
- package/dist/extensions/org-config.d.ts +2 -0
- package/dist/extensions/org-config.js +1 -0
- package/dist/extensions/org-overrides.d.ts +2 -0
- package/dist/extensions/org-overrides.js +3 -2
- package/dist/identity/initial-passwords.job.d.ts +3 -2
- package/dist/identity/initial-passwords.job.js +9 -5
- package/dist/platform/exclusions.js +1 -41
- package/dist/platform/method.js +1 -0
- package/dist/platform/operation.d.ts +30 -2
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/extensions-admin.ops.d.ts +15 -2
- package/dist/platform/ops/extensions-admin.ops.js +153 -5
- package/dist/platform/ops/extensions.ops.d.ts +19 -5
- package/dist/platform/ops/extensions.ops.js +285 -10
- package/dist/platform/ops/person-inputs.d.ts +35 -0
- package/dist/platform/ops/person-inputs.js +79 -0
- package/dist/platform/ops/plugins.ops.d.ts +2 -0
- package/dist/platform/ops/plugins.ops.js +30 -17
- package/dist/platform/parity.d.ts +6 -2
- package/dist/platform/parity.js +38 -1
- package/dist/platform/person-fields.d.ts +103 -0
- package/dist/platform/person-fields.js +381 -0
- package/dist/platform/platform.module.d.ts +3 -3
- package/dist/platform/platform.module.js +6 -5
- package/dist/platform/sealed-inputs.d.ts +44 -0
- package/dist/platform/sealed-inputs.js +116 -0
- package/dist/runtime/waits.js +8 -2
- package/dist/tools/approvals.controller.d.ts +1 -0
- package/dist/tools/approvals.controller.js +19 -0
- package/dist/tools/approvals.service.d.ts +50 -1
- package/dist/tools/approvals.service.js +118 -10
- package/dist/tools/builtins/builtin-tools.d.ts +3 -0
- package/dist/tools/builtins/builtin-tools.js +31 -9
- package/dist/tools/builtins/platform.d.ts +20 -0
- package/dist/tools/builtins/platform.js +174 -15
- package/dist/tools/pipeline.d.ts +24 -2
- package/dist/tools/pipeline.js +80 -17
- package/dist/tools/policy.d.ts +3 -0
- package/dist/tools/policy.js +6 -0
- package/dist/tools/registry.d.ts +22 -0
- package/dist/tools/tools.module.js +3 -0
- package/package.json +4 -4
- package/src/migrations/0169_platform_sealed_inputs.sql +23 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { OperationContext } from "../operation.js";
|
|
2
|
+
/**
|
|
3
|
+
* Runs a write that may carry the person's card values (platform web parity spec §4.3): inside
|
|
4
|
+
* `ctx.personInputs.apply` when the approved call asked for person fields, so the sealed values
|
|
5
|
+
* are consumed in the write's own transaction, else directly with none. `write` gets the values
|
|
6
|
+
* by dot path and the audit detail: `viaAgent(operation)` plus `inputsProvided` (the entered
|
|
7
|
+
* paths, never the values) when the person entered any (spec §10).
|
|
8
|
+
*/
|
|
9
|
+
export declare function withPersonInputs<T>(operation: string, ctx: OperationContext, write: (entered: Readonly<Record<string, string>>, auditDetail: Record<string, unknown>) => Promise<T>): Promise<T>;
|
|
10
|
+
/**
|
|
11
|
+
* The `values` of a config route keyed by field dot path (deployment config, the org's copy): the
|
|
12
|
+
* model's non-secret values, the person's entered secrets, and `null` (clear) for each path in
|
|
13
|
+
* `clear`. A secret left out keeps its stored value, as on the web form.
|
|
14
|
+
*/
|
|
15
|
+
export declare function flatValues(values: Readonly<Record<string, unknown>>, entered: Readonly<Record<string, string>>, clear: readonly string[]): Record<string, unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* The whole org config (`config` of `PUT /orgs/:orgId/extensions/:extension`, a nested object): the
|
|
18
|
+
* model's non-secret config with the person's entered secrets set at their dot paths and `null`
|
|
19
|
+
* (clear) at each path in `clear`. A secret left out keeps its stored value.
|
|
20
|
+
*/
|
|
21
|
+
export declare function nestedConfig(values: Readonly<Record<string, unknown>>, entered: Readonly<Record<string, string>>, clear: readonly string[]): Record<string, unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* The card text of a config write: the non-secret values it sets, the secrets the person enters
|
|
24
|
+
* and the secrets it clears (paths only), e.g. `baseUrl="https://…"; the person enters apiKey`.
|
|
25
|
+
* The entered secrets are the plan's (`ctx.personAsk`: required secrets the call did not name
|
|
26
|
+
* included), else the call's `askPerson`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function configChanges(i: {
|
|
29
|
+
values: Readonly<Record<string, unknown>>;
|
|
30
|
+
askPerson: readonly string[];
|
|
31
|
+
clearSecrets: readonly string[];
|
|
32
|
+
}, ctx: Pick<OperationContext, "personAsk">): {
|
|
33
|
+
zh: string;
|
|
34
|
+
en: string;
|
|
35
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { setDeep } from "../../extensions/deployment-config-store.js";
|
|
2
|
+
import { viaAgent } from "./errors.js";
|
|
3
|
+
import { named } from "./summary.js";
|
|
4
|
+
/**
|
|
5
|
+
* Runs a write that may carry the person's card values (platform web parity spec §4.3): inside
|
|
6
|
+
* `ctx.personInputs.apply` when the approved call asked for person fields, so the sealed values
|
|
7
|
+
* are consumed in the write's own transaction, else directly with none. `write` gets the values
|
|
8
|
+
* by dot path and the audit detail: `viaAgent(operation)` plus `inputsProvided` (the entered
|
|
9
|
+
* paths, never the values) when the person entered any (spec §10).
|
|
10
|
+
*/
|
|
11
|
+
export function withPersonInputs(operation, ctx, write) {
|
|
12
|
+
const base = viaAgent(operation, ctx);
|
|
13
|
+
if (ctx.personInputs === undefined)
|
|
14
|
+
return write({}, base);
|
|
15
|
+
return ctx.personInputs.apply((values) => write(values, { ...base, inputsProvided: Object.keys(values).sort() }));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The `values` of a config route keyed by field dot path (deployment config, the org's copy): the
|
|
19
|
+
* model's non-secret values, the person's entered secrets, and `null` (clear) for each path in
|
|
20
|
+
* `clear`. A secret left out keeps its stored value, as on the web form.
|
|
21
|
+
*/
|
|
22
|
+
export function flatValues(values, entered, clear) {
|
|
23
|
+
return {
|
|
24
|
+
...values,
|
|
25
|
+
...entered,
|
|
26
|
+
...Object.fromEntries(clear.map((p) => [p, null])),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The whole org config (`config` of `PUT /orgs/:orgId/extensions/:extension`, a nested object): the
|
|
31
|
+
* model's non-secret config with the person's entered secrets set at their dot paths and `null`
|
|
32
|
+
* (clear) at each path in `clear`. A secret left out keeps its stored value.
|
|
33
|
+
*/
|
|
34
|
+
export function nestedConfig(values, entered, clear) {
|
|
35
|
+
const config = structuredClone(values);
|
|
36
|
+
for (const [path, v] of Object.entries(entered))
|
|
37
|
+
setDeep(config, path, v);
|
|
38
|
+
for (const path of clear)
|
|
39
|
+
setDeep(config, path, null);
|
|
40
|
+
return config;
|
|
41
|
+
}
|
|
42
|
+
/** Leaf `path=value` pairs of a values object (dot paths), each clipped for a card. */
|
|
43
|
+
function pairsOf(values, prefix = "") {
|
|
44
|
+
return Object.entries(values).flatMap(([k, v]) => {
|
|
45
|
+
const path = prefix === "" ? k : `${prefix}.${k}`;
|
|
46
|
+
if (typeof v === "object" && v !== null && !Array.isArray(v)) {
|
|
47
|
+
return pairsOf(v, path);
|
|
48
|
+
}
|
|
49
|
+
return [named(`${path}=${JSON.stringify(v)}`)];
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The card text of a config write: the non-secret values it sets, the secrets the person enters
|
|
54
|
+
* and the secrets it clears (paths only), e.g. `baseUrl="https://…"; the person enters apiKey`.
|
|
55
|
+
* The entered secrets are the plan's (`ctx.personAsk`: required secrets the call did not name
|
|
56
|
+
* included), else the call's `askPerson`.
|
|
57
|
+
*/
|
|
58
|
+
export function configChanges(i, ctx) {
|
|
59
|
+
const { values, clearSecrets: clear } = i;
|
|
60
|
+
const ask = ctx.personAsk ?? i.askPerson;
|
|
61
|
+
const set = pairsOf(values);
|
|
62
|
+
const zh = [];
|
|
63
|
+
const en = [];
|
|
64
|
+
if (set.length > 0) {
|
|
65
|
+
zh.push(`设置 ${set.join(",")}`);
|
|
66
|
+
en.push(`sets ${set.join(", ")}`);
|
|
67
|
+
}
|
|
68
|
+
if (ask.length > 0) {
|
|
69
|
+
zh.push(`由本人填写 ${ask.map(named).join("、")}`);
|
|
70
|
+
en.push(`the person enters ${ask.map(named).join(", ")}`);
|
|
71
|
+
}
|
|
72
|
+
if (clear.length > 0) {
|
|
73
|
+
zh.push(`清除 ${clear.map(named).join("、")}`);
|
|
74
|
+
en.push(`clears ${clear.map(named).join(", ")}`);
|
|
75
|
+
}
|
|
76
|
+
if (zh.length === 0)
|
|
77
|
+
return { zh: "不改动任何字段", en: "changes no field" };
|
|
78
|
+
return { zh: zh.join(";"), en: en.join("; ") };
|
|
79
|
+
}
|
|
@@ -9,6 +9,8 @@ import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
|
9
9
|
import { PlatformOperations } from "../registry.js";
|
|
10
10
|
export { OTHER_ORG } from "./other-orgs.js";
|
|
11
11
|
export declare const NEEDS_INPUT = "This plugin needs configuration a person must enter; ask them to enable it on the Plugins page.";
|
|
12
|
+
/** `plugin.needs_input` when what is missing is its extension's org config (an agent can set it). */
|
|
13
|
+
export declare const needsOrgConfig: (extension: string) => string;
|
|
12
14
|
/**
|
|
13
15
|
* Plugin operations of the `Platform` tool (spec §7): the org's view (list, get, switch on or off)
|
|
14
16
|
* and the super admin's platform view (list, get, update with its preview). Every platform result
|
|
@@ -41,6 +41,8 @@ const LOCKED = "This plugin is on for every org (or shipped with the platform) a
|
|
|
41
41
|
/** The confirm value of switching off a plugin with nothing installed in the org. */
|
|
42
42
|
const NOTHING_INSTALLED = "nothing-installed";
|
|
43
43
|
export const NEEDS_INPUT = "This plugin needs configuration a person must enter; ask them to enable it on the Plugins page.";
|
|
44
|
+
/** `plugin.needs_input` when what is missing is its extension's org config (an agent can set it). */
|
|
45
|
+
export const needsOrgConfig = (extension) => `This plugin's extension ${extension} needs its org config first: read what is missing with extensions.org-config, fill it in with extensions.set-org-config (the person enters secrets on the confirmation card; the org's own copy of overridable platform fields is extensions.save-org-config), then call plugins.set-enabled again.`;
|
|
44
46
|
/** The English name of a plugin as next steps and messages name it. */
|
|
45
47
|
const enName = (i) => localized(i.displayName, i.name).en;
|
|
46
48
|
/** The item with the reason its extension stopped loading (state unchanged), when it has one. */
|
|
@@ -84,21 +86,30 @@ const hasConfigFields = (schema) => {
|
|
|
84
86
|
return typeof props === "object" && props !== null && Object.keys(props).length > 0;
|
|
85
87
|
};
|
|
86
88
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* org
|
|
89
|
+
* Why switching the plugin on needs input first, as the `plugin.needs_input` message, or null: its
|
|
90
|
+
* extension's org config misses required values (an agent fills it in with
|
|
91
|
+
* `extensions.set-org-config`), or connector templates without their connector, or anything else
|
|
92
|
+
* the item's `needs_config` stands for (a person enters it on the Plugins page). Unlike the web's
|
|
93
|
+
* install wizard, an org config form whose required values are all stored does not stop the switch.
|
|
90
94
|
*/
|
|
91
95
|
function needsInput(item, extensions) {
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
const own = extensions.find((e) => e.catalogItem?.itemId === item.id);
|
|
97
|
+
// `needs_config` also means connector templates without their connector (the Plugins page)
|
|
98
|
+
if (item.state === "needs_config") {
|
|
99
|
+
return own?.needsConfig === true ? needsOrgConfig(own.plugin) : NEEDS_INPUT;
|
|
100
|
+
}
|
|
94
101
|
if (item.installed !== null)
|
|
95
|
-
return
|
|
102
|
+
return null;
|
|
96
103
|
if (item.componentCounts.connectorTemplates > 0)
|
|
97
|
-
return
|
|
104
|
+
return NEEDS_INPUT;
|
|
98
105
|
if (item.componentCounts.extension === 0)
|
|
99
|
-
return
|
|
100
|
-
|
|
101
|
-
|
|
106
|
+
return null;
|
|
107
|
+
return own !== undefined &&
|
|
108
|
+
!own.enabled &&
|
|
109
|
+
hasConfigFields(own.orgConfigSchema) &&
|
|
110
|
+
own.needsConfig
|
|
111
|
+
? needsOrgConfig(own.plugin)
|
|
112
|
+
: null;
|
|
102
113
|
}
|
|
103
114
|
/**
|
|
104
115
|
* Plugin operations of the `Platform` tool (spec §7): the org's view (list, get, switch on or off)
|
|
@@ -251,7 +262,7 @@ let PluginsOperations = class PluginsOperations {
|
|
|
251
262
|
},
|
|
252
263
|
{
|
|
253
264
|
code: "plugin.needs_input",
|
|
254
|
-
next: "
|
|
265
|
+
next: "When its extension's org config is missing, fill it in with extensions.set-org-config (secrets in askPerson), then call again; connector inputs are entered by the person on the Plugins page.",
|
|
255
266
|
},
|
|
256
267
|
{
|
|
257
268
|
code: "catalog.approval_required",
|
|
@@ -292,9 +303,11 @@ let PluginsOperations = class PluginsOperations {
|
|
|
292
303
|
next: unavailableNext(item.reason, name),
|
|
293
304
|
};
|
|
294
305
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
306
|
+
const missing = i.enabled
|
|
307
|
+
? needsInput(item, await this.extensions.list(ctx.orgId))
|
|
308
|
+
: null;
|
|
309
|
+
if (missing !== null)
|
|
310
|
+
return { ok: false, code: "plugin.needs_input", message: missing };
|
|
298
311
|
return { ok: true };
|
|
299
312
|
},
|
|
300
313
|
summary: async (i, ctx) => {
|
|
@@ -322,9 +335,9 @@ let PluginsOperations = class PluginsOperations {
|
|
|
322
335
|
run: async (input, ctx) => {
|
|
323
336
|
if (input.enabled) {
|
|
324
337
|
const [item] = await this.orgCatalog.list(ctx.orgId, ctx.actorAccountId, input.itemId);
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
338
|
+
const missing = item ? needsInput(item, await this.extensions.list(ctx.orgId)) : null;
|
|
339
|
+
if (missing !== null)
|
|
340
|
+
throw new ToolError(missing);
|
|
328
341
|
}
|
|
329
342
|
const r = await this.orgCatalog.setSwitch(ctx.orgId, ctx.actorAccountId, input.itemId, input.enabled ? { enabled: true } : { enabled: false, confirm: input.confirm }, undefined, viaAgent("plugins.set-enabled", ctx));
|
|
330
343
|
if (r.kind === "done") {
|
|
@@ -6,10 +6,12 @@ export interface ParityFinding {
|
|
|
6
6
|
route: string;
|
|
7
7
|
/** The operation field (or declaration entry) it is about; absent when about the whole route. */
|
|
8
8
|
field?: string;
|
|
9
|
+
/** The named rule of a finding that has one (`platform-op-secret-param`). */
|
|
10
|
+
rule?: "platform-op-secret-param";
|
|
9
11
|
message: string;
|
|
10
12
|
}
|
|
11
13
|
/** What {@link inputParity} reads of an operation. */
|
|
12
|
-
export type ParityOperation = Pick<PlatformOperation, "id" | "input" | "mirrors"> & Partial<Pick<PlatformOperation, "omits" | "extras" | "renames" | "loosens">>;
|
|
14
|
+
export type ParityOperation = Pick<PlatformOperation, "id" | "input" | "mirrors"> & Partial<Pick<PlatformOperation, "omits" | "extras" | "renames" | "loosens" | "personFields">>;
|
|
13
15
|
/**
|
|
14
16
|
* Compares an operation's input with one mirrored route's body + query + path params (spec
|
|
15
17
|
* §14.5 item 3), on their input JSON Schemas:
|
|
@@ -23,7 +25,9 @@ export type ParityOperation = Pick<PlatformOperation, "id" | "input" | "mirrors"
|
|
|
23
25
|
* - a `loosens` entry names an input field allowed to accept more than the route (with the
|
|
24
26
|
* reason); it is still compared by type, and an entry that loosens nothing is stale;
|
|
25
27
|
* - a top-level route field the input neither has nor renames into is listed in `omits`, an input
|
|
26
|
-
* field with no route counterpart in `extras`; stale entries of either are findings
|
|
28
|
+
* field with no route counterpart in `extras`; stale entries of either are findings;
|
|
29
|
+
* - rule `platform-op-secret-param`: a route field holding the SDK's `secret()` meta anywhere is
|
|
30
|
+
* never an input field (it is in `omits`), and the operation defines `personFields`.
|
|
27
31
|
*/
|
|
28
32
|
export declare function inputParity(op: ParityOperation, route: RouteSchemas): ParityFinding[];
|
|
29
33
|
/**
|
package/dist/platform/parity.js
CHANGED
|
@@ -5,6 +5,22 @@ const IMPLICIT = new Set(["orgId"]);
|
|
|
5
5
|
const UPPER = ["maxLength", "maximum", "exclusiveMaximum", "maxItems", "maxProperties"];
|
|
6
6
|
const LOWER = ["minLength", "minimum", "exclusiveMinimum", "minItems", "minProperties"];
|
|
7
7
|
const toJson = (s) => z.toJSONSchema(s, { io: "input", unrepresentable: "any" });
|
|
8
|
+
/** Keywords whose value is data, never a schema: a `secret` key inside them is no marker. */
|
|
9
|
+
const DATA_KEYWORDS = new Set(["const", "enum", "default", "examples"]);
|
|
10
|
+
/**
|
|
11
|
+
* Whether a JSON Schema holds the SDK's `secret()` meta anywhere (`z.toJSONSchema` copies the meta
|
|
12
|
+
* `{ secret: true }` onto the node), nested objects, items, unions and `$defs` included.
|
|
13
|
+
*/
|
|
14
|
+
function holdsSecret(node) {
|
|
15
|
+
if (Array.isArray(node))
|
|
16
|
+
return node.some(holdsSecret);
|
|
17
|
+
if (typeof node !== "object" || node === null)
|
|
18
|
+
return false;
|
|
19
|
+
const o = node;
|
|
20
|
+
if (o.secret === true)
|
|
21
|
+
return true;
|
|
22
|
+
return Object.entries(o).some(([k, v]) => !DATA_KEYWORDS.has(k) && holdsSecret(v));
|
|
23
|
+
}
|
|
8
24
|
/** A schema's alternatives: the branches of `anyOf` / `oneOf` (flattened), else itself. */
|
|
9
25
|
function alternatives(s) {
|
|
10
26
|
const branches = (s.anyOf ?? s.oneOf);
|
|
@@ -169,7 +185,9 @@ function fieldMismatch(op, route, path, top) {
|
|
|
169
185
|
* - a `loosens` entry names an input field allowed to accept more than the route (with the
|
|
170
186
|
* reason); it is still compared by type, and an entry that loosens nothing is stale;
|
|
171
187
|
* - a top-level route field the input neither has nor renames into is listed in `omits`, an input
|
|
172
|
-
* field with no route counterpart in `extras`; stale entries of either are findings
|
|
188
|
+
* field with no route counterpart in `extras`; stale entries of either are findings;
|
|
189
|
+
* - rule `platform-op-secret-param`: a route field holding the SDK's `secret()` meta anywhere is
|
|
190
|
+
* never an input field (it is in `omits`), and the operation defines `personFields`.
|
|
173
191
|
*/
|
|
174
192
|
export function inputParity(op, route) {
|
|
175
193
|
const out = [];
|
|
@@ -226,6 +244,25 @@ export function inputParity(op, route) {
|
|
|
226
244
|
if (why !== null)
|
|
227
245
|
add(k, `${name}: ${why} (${r})`);
|
|
228
246
|
}
|
|
247
|
+
// rule `platform-op-secret-param` (platform web parity spec §9): a route field carrying a
|
|
248
|
+
// `secret()` value is entered by the person on the card, never passed by the model
|
|
249
|
+
for (const [k, f] of routeFields) {
|
|
250
|
+
if (!holdsSecret(f.schema))
|
|
251
|
+
continue;
|
|
252
|
+
const secretRule = (message) => out.push({
|
|
253
|
+
op: op.id,
|
|
254
|
+
route: route.route,
|
|
255
|
+
field: k,
|
|
256
|
+
rule: "platform-op-secret-param",
|
|
257
|
+
message: `${op.id}: platform-op-secret-param: ${message}`,
|
|
258
|
+
});
|
|
259
|
+
if (covered.has(k)) {
|
|
260
|
+
secretRule(`\`${k}\` of ${r} carries a secret (\`secret()\` meta): leave it out of the input, list it in \`omits\`, and have the person enter it on the card (\`personFields\`)`);
|
|
261
|
+
}
|
|
262
|
+
else if (op.personFields === undefined) {
|
|
263
|
+
secretRule(`\`${k}\` of ${r} carries a secret (\`secret()\` meta): the operation must define \`personFields\`, so the person enters secrets on the card`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
229
266
|
for (const k of routeFields.keys()) {
|
|
230
267
|
if (!covered.has(k) && !omits.has(k)) {
|
|
231
268
|
add(k, `\`${k}\` of ${r} is missing from the input and not in \`omits\``);
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Person fields (platform web parity spec §4.1, §4.2): the secret fields of a write's target config
|
|
4
|
+
* schema that the person types on the approval card instead of the model passing them in params.
|
|
5
|
+
* Pure rules shared by the Platform operations: find the secret fields of a JSON Schema produced by
|
|
6
|
+
* the SDK's `configJsonSchema` (`"x-secret": true`), plan which ones one call asks for, and check
|
|
7
|
+
* one typed value. Paths are the dot paths the config routes use in `values` (ruling R1); secret
|
|
8
|
+
* records (`x-ui.secrets`, `secret(z.record(...))`) and secrets inside array items cannot be
|
|
9
|
+
* addressed that way and are reported as `recordOnly` (entered on the web page).
|
|
10
|
+
*/
|
|
11
|
+
/** UTF-8 bytes of one value the person types. */
|
|
12
|
+
export declare const PERSON_FIELD_MAX_BYTES: number;
|
|
13
|
+
/** Person fields one call may ask for (one approval card). */
|
|
14
|
+
export declare const PERSON_FIELDS_MAX = 32;
|
|
15
|
+
/** One secret field the person may enter on the approval card. */
|
|
16
|
+
export interface PersonFieldSpec {
|
|
17
|
+
/** Dot path from the schema root (R1). */
|
|
18
|
+
path: string;
|
|
19
|
+
/** From the node's `title` / `x-ui.label`, else the path. */
|
|
20
|
+
label: string;
|
|
21
|
+
/** From the node's `description` / `x-ui.help`. */
|
|
22
|
+
description?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The node's `x-ui` widget is a textarea (or JSON) editor. `checkConfigUi` forbids widgets on
|
|
25
|
+
* secret nodes of extension schemas, so their rows are single-line (JSON pastes fine into a
|
|
26
|
+
* masked single-line input).
|
|
27
|
+
*/
|
|
28
|
+
multiline: boolean;
|
|
29
|
+
/** Listed in its parent's `required` along the whole path. */
|
|
30
|
+
required: boolean;
|
|
31
|
+
/** A stored value exists. */
|
|
32
|
+
isSet: boolean;
|
|
33
|
+
/** The JSON Schema node, scrubbed of value keywords (default / examples / const / enum). */
|
|
34
|
+
schema: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
/** What one operation writes: its name for the card and the person fields of its schema. */
|
|
37
|
+
export interface PersonFieldTarget {
|
|
38
|
+
target: {
|
|
39
|
+
zh: string;
|
|
40
|
+
en: string;
|
|
41
|
+
};
|
|
42
|
+
fields: PersonFieldSpec[];
|
|
43
|
+
/** Secret paths the card cannot ask for (records, array items): entered on the web page. */
|
|
44
|
+
recordOnly?: string[];
|
|
45
|
+
}
|
|
46
|
+
/** The params every operation with person fields adds to its input schema. */
|
|
47
|
+
export declare const personFieldParams: {
|
|
48
|
+
askPerson: z.ZodType<string[]>;
|
|
49
|
+
clearSecrets: z.ZodType<string[]>;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The secret fields of a config JSON Schema (`configJsonSchema` output): every string node marked
|
|
53
|
+
* `"x-secret": true` (or under a secret object) reachable through `properties`, by dot path, in
|
|
54
|
+
* declaration order. `required` holds when every object along the path lists the next name in
|
|
55
|
+
* its `required`; `isSet` when `stored` holds the path. Secrets the card cannot address go to
|
|
56
|
+
* `recordOnly`: the paths `x-ui.secrets` names, secret nodes that are not strings (records), and
|
|
57
|
+
* secrets inside array items (as `list[].key`), and a secret object that takes undeclared keys
|
|
58
|
+
* (`additionalProperties`, `patternProperties`) for those keys. It fails closed on shapes it cannot see through:
|
|
59
|
+
* a `$ref`, an `allOf` or a union of two or more non-null branches whose subtree holds a secret
|
|
60
|
+
* puts the node's own path into `recordOnly`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function secretFieldsOf(jsonSchema: unknown, stored: ReadonlySet<string>): {
|
|
63
|
+
fields: PersonFieldSpec[];
|
|
64
|
+
recordOnly: string[];
|
|
65
|
+
};
|
|
66
|
+
/** The plan of one call: the fields the card asks for and the secrets to clear, or a refusal. */
|
|
67
|
+
export type PersonFieldPlan = {
|
|
68
|
+
ok: true;
|
|
69
|
+
ask: PersonFieldSpec[];
|
|
70
|
+
clear: string[];
|
|
71
|
+
} | {
|
|
72
|
+
ok: false;
|
|
73
|
+
message: string;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* The paths of `paths` that `values` touches (a pair at, below or above one, null included),
|
|
77
|
+
* flattened like the plan's check: e.g. the read-only fields a call tries to write.
|
|
78
|
+
*/
|
|
79
|
+
export declare function pathsTouched(values: Readonly<Record<string, unknown>> | undefined, paths: readonly string[]): string[];
|
|
80
|
+
/**
|
|
81
|
+
* Plans the person fields of one call (spec §4.1). Refusals are English for the model:
|
|
82
|
+
* - a non-null value in `values` at, below or above a secret field or a recordOnly path (an
|
|
83
|
+
* array-item secret: its array root) -> the leaked-secret copy, naming only the path, never the
|
|
84
|
+
* value; `values` is flattened once, so flat, nested and prefix keys all count; a null at a
|
|
85
|
+
* secret field -> pointed to clearSecrets;
|
|
86
|
+
* - an `askPerson` / `clearSecrets` path that is not a secret field of the target;
|
|
87
|
+
* - a path both asked and cleared;
|
|
88
|
+
* - more than {@link PERSON_FIELDS_MAX} fields to ask.
|
|
89
|
+
* A required secret without a stored value joins `ask` even when not named (unless it is cleared).
|
|
90
|
+
*/
|
|
91
|
+
export declare function planPersonFields(t: PersonFieldTarget, p: {
|
|
92
|
+
values?: Record<string, unknown>;
|
|
93
|
+
askPerson: string[];
|
|
94
|
+
clearSecrets: string[];
|
|
95
|
+
}): PersonFieldPlan;
|
|
96
|
+
/**
|
|
97
|
+
* Checks one value the person typed against its field: at most {@link PERSON_FIELD_MAX_BYTES}
|
|
98
|
+
* UTF-8 bytes, not empty, and valid for the field's JSON Schema node (ajv, JSON Schema 2020-12,
|
|
99
|
+
* as the tool pipeline validates inputs). Returns null when valid, else an English problem that
|
|
100
|
+
* names the field and never echoes the value. A node ajv cannot compile accepts the value: the
|
|
101
|
+
* write validates the whole config again.
|
|
102
|
+
*/
|
|
103
|
+
export declare function checkPersonValue(spec: PersonFieldSpec, value: string): string | null;
|