@capybara-hq/kernel 0.1.0-rc.3 → 0.1.0-rc.4
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/admin.controller.d.ts +9 -4
- package/dist/admin/admin.controller.js +13 -4
- package/dist/admin/extensions.controller.d.ts +8 -1
- package/dist/admin/extensions.controller.js +22 -2
- package/dist/agents/agent-lookup.d.ts +3 -0
- package/dist/agents/agent-lookup.js +10 -0
- package/dist/agents/agent-profile.service.d.ts +29 -0
- package/dist/agents/agent-profile.service.js +117 -0
- package/dist/agents/agents.controller.d.ts +93 -3
- package/dist/agents/agents.controller.js +114 -4
- package/dist/agents/agents.module.js +6 -2
- package/dist/agents/agents.service.d.ts +13 -5
- package/dist/agents/agents.service.js +30 -7
- package/dist/agents/definition.d.ts +4 -0
- package/dist/agents/definition.js +10 -0
- package/dist/agents/instruction-files.d.ts +60 -0
- package/dist/agents/instruction-files.js +111 -0
- package/dist/agents/models.controller.d.ts +9 -3
- package/dist/agents/models.controller.js +19 -4
- package/dist/agents/profile.d.ts +96 -0
- package/dist/agents/profile.js +51 -0
- package/dist/agents/readiness.controller.d.ts +26 -0
- package/dist/agents/readiness.controller.js +56 -0
- package/dist/agents/templates.js +1 -1
- package/dist/background/background.controller.d.ts +38 -0
- package/dist/background/background.controller.js +87 -0
- package/dist/background/background.module.d.ts +10 -0
- package/dist/background/background.module.js +32 -0
- package/dist/background/finish.d.ts +43 -0
- package/dist/background/finish.js +94 -0
- package/dist/background/launch-lock.d.ts +14 -0
- package/dist/background/launch-lock.js +39 -0
- package/dist/background/launch.d.ts +36 -0
- package/dist/background/launch.js +70 -0
- package/dist/background/poll.job.d.ts +53 -0
- package/dist/background/poll.job.js +182 -0
- package/dist/background/render.d.ts +23 -0
- package/dist/background/render.js +48 -0
- package/dist/background/session.d.ts +37 -0
- package/dist/background/session.js +66 -0
- package/dist/background/status.d.ts +35 -0
- package/dist/background/status.js +57 -0
- package/dist/background/stop.d.ts +62 -0
- package/dist/background/stop.js +225 -0
- package/dist/background/store.d.ts +150 -0
- package/dist/background/store.js +351 -0
- package/dist/background/store.module.d.ts +6 -0
- package/dist/background/store.module.js +22 -0
- package/dist/background/tasks.service.d.ts +67 -0
- package/dist/background/tasks.service.js +186 -0
- package/dist/background/wake-rules.d.ts +57 -0
- package/dist/background/wake-rules.js +83 -0
- package/dist/background/wake.d.ts +28 -0
- package/dist/background/wake.js +57 -0
- package/dist/catalog/claude/agents.js +2 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/plugin-import.js +1 -1
- package/dist/catalog/plugin-upgrade.js +1 -1
- package/dist/channels/cards.js +1 -1
- package/dist/channels/connections.service.d.ts +16 -1
- package/dist/channels/connections.service.js +38 -4
- package/dist/channels/threads.d.ts +5 -0
- package/dist/channels/threads.js +8 -0
- package/dist/config/schema.d.ts +18 -0
- package/dist/config/schema.js +102 -0
- package/dist/conversations/access.js +2 -0
- package/dist/conversations/attachments.service.d.ts +30 -0
- package/dist/conversations/attachments.service.js +130 -5
- package/dist/conversations/conversations.controller.d.ts +36 -5
- package/dist/conversations/conversations.controller.js +62 -12
- package/dist/conversations/conversations.module.js +3 -0
- package/dist/conversations/conversations.service.d.ts +44 -2
- package/dist/conversations/conversations.service.js +140 -12
- package/dist/conversations/event-log.d.ts +1 -1
- package/dist/conversations/event-log.js +10 -1
- package/dist/conversations/events.d.ts +58 -0
- package/dist/conversations/events.js +57 -2
- package/dist/conversations/queue.d.ts +3 -1
- package/dist/conversations/queue.js +13 -2
- package/dist/conversations/queue.service.js +3 -1
- package/dist/conversations/titles.d.ts +7 -0
- package/dist/conversations/titles.js +15 -0
- package/dist/db/kernel-schema.d.ts +58 -2
- package/dist/db/pool.d.ts +5 -0
- package/dist/db/pool.js +3 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +8 -0
- package/dist/evals/run-replay.d.ts +5 -2
- package/dist/evals/run-replay.js +30 -7
- package/dist/evals/step-replay.js +12 -6
- package/dist/evals/trajectory.js +1 -1
- package/dist/extensions/admin-ops.js +2 -0
- package/dist/extensions/admin-view.d.ts +3 -1
- package/dist/extensions/admin-view.js +10 -2
- package/dist/extensions/blobs.js +1 -0
- package/dist/extensions/config-issues.d.ts +13 -1
- package/dist/extensions/config-issues.js +22 -5
- package/dist/extensions/config-json-schema.d.ts +43 -7
- package/dist/extensions/config-json-schema.js +124 -58
- package/dist/extensions/deployment-config-store.d.ts +6 -0
- package/dist/extensions/deployment-config.d.ts +50 -3
- package/dist/extensions/deployment-config.js +125 -28
- package/dist/extensions/display-name.d.ts +22 -0
- package/dist/extensions/display-name.js +77 -0
- package/dist/extensions/extensions.module.js +6 -0
- package/dist/extensions/host.d.ts +26 -1
- package/dist/extensions/host.js +82 -9
- package/dist/extensions/org-config.controller.d.ts +11 -3
- package/dist/extensions/org-config.controller.js +14 -6
- package/dist/extensions/org-config.d.ts +6 -0
- package/dist/extensions/org-config.js +12 -13
- package/dist/extensions/package.d.ts +14 -1
- package/dist/extensions/package.js +51 -2
- package/dist/extensions/permission-view.d.ts +3 -0
- package/dist/extensions/point-defaults.controller.d.ts +34 -0
- package/dist/extensions/point-defaults.controller.js +71 -0
- package/dist/extensions/point-defaults.d.ts +64 -0
- package/dist/extensions/point-defaults.js +206 -0
- package/dist/extensions/registry.d.ts +1 -1
- package/dist/extensions/registry.js +2 -0
- package/dist/http/api.module.js +8 -0
- package/dist/http/nest-logger.d.ts +6 -5
- package/dist/http/nest-logger.js +24 -10
- package/dist/identity/auth.controller.js +9 -5
- package/dist/identity/cookies.d.ts +20 -5
- package/dist/identity/cookies.js +44 -6
- package/dist/identity/me.controller.d.ts +5 -1
- package/dist/identity/me.controller.js +12 -3
- package/dist/identity/sessions.d.ts +12 -0
- package/dist/identity/sessions.js +45 -0
- package/dist/index.d.ts +1 -1
- package/dist/infra/config/kernel-config.service.js +6 -0
- package/dist/infra/database/database.module.js +1 -0
- package/dist/infra/events/kernel-events.d.ts +8 -0
- package/dist/infra/lifecycle/process-guards.js +4 -0
- package/dist/infra/logging/logging.module.d.ts +4 -2
- package/dist/infra/logging/logging.module.js +24 -6
- package/dist/infra/queue/redis-connection.d.ts +6 -0
- package/dist/infra/queue/redis-connection.js +7 -0
- package/dist/infra/redis/redis.module.js +6 -2
- package/dist/infra/tokens.d.ts +6 -1
- package/dist/infra/tokens.js +6 -1
- package/dist/log.d.ts +13 -1
- package/dist/log.js +93 -17
- package/dist/models/purposes.d.ts +23 -0
- package/dist/models/purposes.js +31 -10
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +26 -16
- package/dist/orgs/settings.service.d.ts +5 -0
- package/dist/orgs/settings.service.js +13 -2
- package/dist/roles/worker.module.js +6 -0
- package/dist/runtime/context/build.d.ts +9 -7
- package/dist/runtime/context/build.js +27 -19
- package/dist/runtime/context/claude-tools.d.ts +2 -1
- package/dist/runtime/context/claude-tools.js +5 -4
- package/dist/runtime/context/compaction.js +4 -0
- package/dist/runtime/langgraph-loop.js +3 -2
- package/dist/runtime/loop.d.ts +4 -3
- package/dist/runtime/maintenance.d.ts +4 -2
- package/dist/runtime/maintenance.js +17 -5
- package/dist/runtime/model-call.d.ts +17 -1
- package/dist/runtime/model-call.js +3 -2
- package/dist/runtime/providers.d.ts +6 -0
- package/dist/runtime/providers.js +8 -0
- package/dist/runtime/run-queue.d.ts +25 -2
- package/dist/runtime/run-queue.js +129 -33
- package/dist/runtime/run-worker.js +16 -3
- package/dist/runtime/runtime.module.js +8 -3
- package/dist/runtime/step-log.d.ts +6 -0
- package/dist/runtime/step-log.js +16 -2
- package/dist/runtime/subagents/definition.js +3 -1
- package/dist/runtime/usage-report.d.ts +2 -1
- package/dist/runtime/usage-report.js +2 -1
- package/dist/runtime/waits.d.ts +8 -2
- package/dist/runtime/waits.js +37 -11
- package/dist/sandbox/sandbox.module.js +6 -1
- package/dist/sandbox/sandbox.service.d.ts +61 -3
- package/dist/sandbox/sandbox.service.js +141 -7
- package/dist/tools/approvals.service.js +2 -0
- package/dist/tools/builtin-names.d.ts +20 -2
- package/dist/tools/builtin-names.js +29 -2
- package/dist/tools/builtins/builtin-tools.d.ts +15 -1
- package/dist/tools/builtins/builtin-tools.js +34 -2
- package/dist/tools/builtins/sandbox/bash.d.ts +1 -1
- package/dist/tools/builtins/sandbox/bash.js +230 -3
- package/dist/tools/builtins/sandbox/common.d.ts +27 -4
- package/dist/tools/builtins/sandbox/common.js +7 -3
- package/dist/tools/builtins/sandbox/deliver.js +1 -1
- package/dist/tools/builtins/sandbox/index.d.ts +2 -0
- package/dist/tools/builtins/sandbox/index.js +6 -0
- package/dist/tools/builtins/sandbox/task-output.d.ts +63 -0
- package/dist/tools/builtins/sandbox/task-output.js +304 -0
- package/dist/tools/builtins/sandbox/task-stop.d.ts +10 -0
- package/dist/tools/builtins/sandbox/task-stop.js +112 -0
- package/dist/tools/builtins/web/errors.d.ts +8 -0
- package/dist/tools/builtins/web/errors.js +53 -0
- package/dist/tools/builtins/web/extract.d.ts +62 -0
- package/dist/tools/builtins/web/extract.js +267 -0
- package/dist/tools/builtins/web/fetch.d.ts +55 -0
- package/dist/tools/builtins/web/fetch.js +174 -0
- package/dist/tools/builtins/web/index.d.ts +13 -0
- package/dist/tools/builtins/web/index.js +12 -0
- package/dist/tools/builtins/web/page-cache.d.ts +25 -0
- package/dist/tools/builtins/web/page-cache.js +77 -0
- package/dist/tools/builtins/web/search.d.ts +25 -0
- package/dist/tools/builtins/web/search.js +209 -0
- package/dist/tools/builtins/web/url.d.ts +17 -0
- package/dist/tools/builtins/web/url.js +43 -0
- package/dist/tools/oauth/flow-paths.d.ts +1 -1
- package/dist/tools/oauth/flow-paths.js +1 -1
- package/dist/tools/pipeline.js +15 -0
- package/dist/tools/registry.d.ts +22 -3
- package/dist/tools/registry.js +26 -11
- package/dist/tools/tools.module.js +12 -0
- package/dist/tools/validate.js +1 -1
- package/package.json +3 -3
- package/src/migrations/0064_account_last_org.sql +7 -0
- package/src/migrations/0065_conversation_archive.sql +8 -0
- package/src/migrations/0066_extension_display_name.sql +4 -0
- package/src/migrations/0067_agent_profiles.sql +20 -0
- package/src/migrations/0068_agent_avatar_uploads.sql +7 -0
- package/src/migrations/0069_attachments_agent_idx.sql +3 -0
- package/src/migrations/0070_background_tasks.sql +37 -0
- package/src/migrations/0071_background_tasks_reserve.sql +6 -0
- package/src/migrations/0072_background_tasks_stopping.sql +5 -0
- package/src/migrations/0073_org_extension_point_defaults.sql +11 -0
|
@@ -1,73 +1,139 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
/** JSON Schema 无法表达的 zod 类型:降级为 `{}` 并标注 `x-unsupported`。 */
|
|
3
|
-
const UNSUPPORTED = new Set([
|
|
4
|
-
"bigint",
|
|
5
|
-
"date",
|
|
6
|
-
"symbol",
|
|
7
|
-
"undefined",
|
|
8
|
-
"void",
|
|
9
|
-
"nan",
|
|
10
|
-
"map",
|
|
11
|
-
"set",
|
|
12
|
-
"function",
|
|
13
|
-
"promise",
|
|
14
|
-
"custom",
|
|
15
|
-
"file",
|
|
16
|
-
]);
|
|
17
1
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* - 以输入侧形态输出(含 default),不带 `$schema`。
|
|
2
|
+
* Config schema → JSON Schema for forms. The conversion (and the secret scrub) lives in the SDK
|
|
3
|
+
* (`configJsonSchema`, extension config forms spec §4.1) so the packer, the checks and the kernel
|
|
4
|
+
* share one implementation; the kernel keeps no copy.
|
|
22
5
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
override: (ctx) => {
|
|
28
|
-
const js = ctx.jsonSchema;
|
|
29
|
-
const def = ctx.zodSchema._zod.def;
|
|
30
|
-
if (js.secret === true) {
|
|
31
|
-
delete js.secret;
|
|
32
|
-
js["x-secret"] = true;
|
|
33
|
-
}
|
|
34
|
-
if (UNSUPPORTED.has(def.type))
|
|
35
|
-
js["x-unsupported"] = true;
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
delete out.$schema;
|
|
39
|
-
scrubSecrets(out);
|
|
40
|
-
return out;
|
|
41
|
-
}
|
|
42
|
-
/** 会泄露取值的关键字:密钥字段一律不输出。 */
|
|
43
|
-
const VALUE_KEYWORDS = ["default", "examples", "const", "enum"];
|
|
44
|
-
/** 值为「名字 -> 子 schema」映射的关键字:其键是用户字段名,不是关键字。 */
|
|
6
|
+
import { configJsonSchema, validateConfigUi, } from "@capybara-hq/plugin-sdk";
|
|
7
|
+
export { configJsonSchema as configToJsonSchema } from "@capybara-hq/plugin-sdk";
|
|
8
|
+
const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
9
|
+
/** Keywords whose value maps names to sub-schemas: their keys are field names, not keywords. */
|
|
45
10
|
const SCHEMA_MAPS = new Set(["properties", "patternProperties", "$defs", "definitions"]);
|
|
11
|
+
/** Keywords whose value is data, not a schema: never recursed into. */
|
|
12
|
+
const VALUE_KEYWORDS = new Set(["default", "const", "enum", "examples"]);
|
|
46
13
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* `properties` 等映射里的键是字段名,名为 default / enum 的字段照常遍历。
|
|
14
|
+
* Removes every `x-ui` from a JSON Schema in place (a property named `x-ui` is kept, and so are
|
|
15
|
+
* values: `default`, `const`, `enum` and `examples` are left as they are).
|
|
50
16
|
*/
|
|
51
|
-
function
|
|
17
|
+
export function stripConfigUi(node) {
|
|
52
18
|
if (Array.isArray(node)) {
|
|
53
19
|
for (const n of node)
|
|
54
|
-
|
|
20
|
+
stripConfigUi(n);
|
|
55
21
|
return;
|
|
56
22
|
}
|
|
57
|
-
if (
|
|
23
|
+
if (!isObj(node))
|
|
58
24
|
return;
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
for (const [k, v] of Object.entries(o)) {
|
|
65
|
-
if (SCHEMA_MAPS.has(k) && typeof v === "object" && v !== null) {
|
|
25
|
+
delete node["x-ui"];
|
|
26
|
+
for (const [k, v] of Object.entries(node)) {
|
|
27
|
+
if (VALUE_KEYWORDS.has(k))
|
|
28
|
+
continue;
|
|
29
|
+
if (SCHEMA_MAPS.has(k) && isObj(v))
|
|
66
30
|
for (const child of Object.values(v))
|
|
67
|
-
|
|
31
|
+
stripConfigUi(child);
|
|
32
|
+
else
|
|
33
|
+
stripConfigUi(v);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Validates the hints of a JSON Schema at a level and strips every `x-ui` when there is any
|
|
38
|
+
* problem (in place): invalid hints never reach a form, and never fail a load (spec §4.1).
|
|
39
|
+
*/
|
|
40
|
+
export function checkConfigUi(schema, level) {
|
|
41
|
+
const problems = validateConfigUi(schema, level);
|
|
42
|
+
if (problems.length > 0)
|
|
43
|
+
stripConfigUi(schema);
|
|
44
|
+
return problems;
|
|
45
|
+
}
|
|
46
|
+
/** Manifests are immutable: one conversion per zod schema object and level (read-only, per replica). */
|
|
47
|
+
const caches = {
|
|
48
|
+
deployment: new WeakMap(),
|
|
49
|
+
org: new WeakMap(),
|
|
50
|
+
connection: new WeakMap(),
|
|
51
|
+
};
|
|
52
|
+
/** A config schema's form JSON Schema ({@link checkConfigUi} applied), cached per schema object. */
|
|
53
|
+
export function configFormSchema(schema, level) {
|
|
54
|
+
const cache = caches[level];
|
|
55
|
+
let r = cache.get(schema);
|
|
56
|
+
if (!r) {
|
|
57
|
+
const js = configJsonSchema(schema);
|
|
58
|
+
r = { schema: js, problems: checkConfigUi(js, level) };
|
|
59
|
+
cache.set(schema, r);
|
|
60
|
+
}
|
|
61
|
+
return r;
|
|
62
|
+
}
|
|
63
|
+
/** The schemas whose hinted conversion threw: their fallback (plain schema, or null). */
|
|
64
|
+
const fallbacks = {
|
|
65
|
+
deployment: new WeakMap(),
|
|
66
|
+
org: new WeakMap(),
|
|
67
|
+
connection: new WeakMap(),
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* {@link configFormSchema} that never throws, for every caller that serves a form schema or reads
|
|
71
|
+
* its messages (deployment, org, connection, issues). A hint conversion that throws (a hand-made
|
|
72
|
+
* package, e.g. hints that won't serialize as JSON) drops the hints: the plain schema with every
|
|
73
|
+
* `x-ui` stripped, else `null` when even the plain conversion fails. `onFallback` runs once per
|
|
74
|
+
* schema object and level on this replica (the caller's one warning); later calls reuse the result.
|
|
75
|
+
*/
|
|
76
|
+
export function safeConfigFormSchema(schema, level, onFallback) {
|
|
77
|
+
const failed = fallbacks[level].get(schema);
|
|
78
|
+
if (failed !== undefined)
|
|
79
|
+
return failed;
|
|
80
|
+
try {
|
|
81
|
+
return configFormSchema(schema, level);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
let r = null;
|
|
85
|
+
try {
|
|
86
|
+
const plain = configJsonSchema(schema);
|
|
87
|
+
stripConfigUi(plain);
|
|
88
|
+
r = { schema: plain, problems: [] };
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
r = null;
|
|
68
92
|
}
|
|
69
|
-
|
|
70
|
-
|
|
93
|
+
fallbacks[level].set(schema, r);
|
|
94
|
+
onFallback(err, r ? "plain" : "none");
|
|
95
|
+
return r;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The secret record paths some `x-ui.secrets[].path` of a form schema names (spec §4.3), anywhere in
|
|
100
|
+
* the schema. Read from a checked schema: one whose hints were invalid was stripped and names none.
|
|
101
|
+
*/
|
|
102
|
+
export function hintedSecretPaths(node, out = new Set()) {
|
|
103
|
+
if (Array.isArray(node)) {
|
|
104
|
+
for (const n of node)
|
|
105
|
+
hintedSecretPaths(n, out);
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
if (!isObj(node))
|
|
109
|
+
return out;
|
|
110
|
+
const hints = node["x-ui"];
|
|
111
|
+
if (isObj(hints) && Array.isArray(hints.secrets)) {
|
|
112
|
+
for (const s of hints.secrets) {
|
|
113
|
+
if (isObj(s) && typeof s.path === "string")
|
|
114
|
+
out.add(s.path);
|
|
71
115
|
}
|
|
72
116
|
}
|
|
117
|
+
for (const [k, v] of Object.entries(node)) {
|
|
118
|
+
if (k === "x-ui" || VALUE_KEYWORDS.has(k))
|
|
119
|
+
continue;
|
|
120
|
+
if (SCHEMA_MAPS.has(k) && isObj(v)) {
|
|
121
|
+
for (const child of Object.values(v))
|
|
122
|
+
hintedSecretPaths(child, out);
|
|
123
|
+
}
|
|
124
|
+
else
|
|
125
|
+
hintedSecretPaths(v, out);
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
/** The root `x-ui.messages` of a form schema (the localized texts of custom issues), if any. */
|
|
130
|
+
export function configMessages(schema) {
|
|
131
|
+
const hints = schema?.["x-ui"];
|
|
132
|
+
return isObj(hints) && isObj(hints.messages) ? hints.messages : undefined;
|
|
133
|
+
}
|
|
134
|
+
/** A short text of hint problems for a status detail or a log (the first few). */
|
|
135
|
+
export function describeConfigUiProblems(level, problems) {
|
|
136
|
+
const shown = problems.slice(0, 5).map((p) => `${p.path || "<root>"}: ${p.message}`);
|
|
137
|
+
const more = problems.length > shown.length ? `; and ${problems.length - shown.length} more` : "";
|
|
138
|
+
return `${level} config UI hints ignored (${shown.join("; ")}${more})`;
|
|
73
139
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { core } from "zod";
|
|
2
2
|
import { type Keyring } from "../ctx/secrets.js";
|
|
3
3
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
4
|
+
import type { JsonSchema } from "./config-json-schema.js";
|
|
4
5
|
type Obj = Record<string, unknown>;
|
|
5
6
|
/**
|
|
6
7
|
* The stored half of the deployment-level extension config (C10): where PG keeps it, how it is read
|
|
@@ -16,6 +17,11 @@ export declare const secretKey: (plugin: string, path: string) => string;
|
|
|
16
17
|
export interface DeploymentSchemaInfo {
|
|
17
18
|
version: string;
|
|
18
19
|
schema?: core.$ZodType | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Without `schema` (no module on this replica): the package's static form schema
|
|
22
|
+
* (`extension.configSchemas.deployment`), shown but never used to validate.
|
|
23
|
+
*/
|
|
24
|
+
jsonSchema?: JsonSchema | undefined;
|
|
19
25
|
fields: {
|
|
20
26
|
path: string;
|
|
21
27
|
secret: boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LocalizedName } from "@capybara-hq/plugin-sdk";
|
|
1
2
|
import type { core } from "zod";
|
|
2
3
|
import type { KernelAppOptions } from "../app.js";
|
|
3
4
|
import { type ConfigSourceKind } from "../config/sources.js";
|
|
@@ -12,6 +13,7 @@ import type { PublishBus } from "./admin-view.js";
|
|
|
12
13
|
import { type ConfigIssue } from "./config-issues.js";
|
|
13
14
|
import { type JsonSchema } from "./config-json-schema.js";
|
|
14
15
|
import { DEPLOYMENT_SECRETS_ORG, type DeploymentSchemaInfo, mergeDeploymentConfig, readStoredDeploymentConfig, schemaFields, secretPathsOf } from "./deployment-config-store.js";
|
|
16
|
+
import { ExtensionDisplayNames } from "./display-name.js";
|
|
15
17
|
import { ExtensionHost } from "./host.js";
|
|
16
18
|
import { ExtensionInstalls } from "./installs.js";
|
|
17
19
|
import { ExtensionLifecycle } from "./lifecycle.js";
|
|
@@ -34,15 +36,36 @@ export interface DeploymentConfigField {
|
|
|
34
36
|
value?: unknown;
|
|
35
37
|
/** 密钥字段是否已设置(任何来源);值永不回显。 */
|
|
36
38
|
set?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Only on a secret record some `x-ui.secrets[].path` names: the record's keys that are set, sorted
|
|
41
|
+
* (item names, not secret values; spec §4.3). Other secret fields report only `set`.
|
|
42
|
+
*/
|
|
43
|
+
keys?: string[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* One operation on a secret record drawn per item (spec §4.3), only for a path some
|
|
47
|
+
* `x-ui.secrets[].path` names: `renameFrom` moves an existing value to `key` (nothing when it has
|
|
48
|
+
* none, replacing a value already at `key`), then `value` sets it (a string) or removes it (`null`).
|
|
49
|
+
*/
|
|
50
|
+
export interface SecretEntry {
|
|
51
|
+
path: string;
|
|
52
|
+
key: string;
|
|
53
|
+
value?: string | null | undefined;
|
|
54
|
+
renameFrom?: string | undefined;
|
|
37
55
|
}
|
|
38
56
|
/** The response of `GET / PUT /api/v1/admin/extensions/:name/config`. */
|
|
39
57
|
export interface DeploymentConfigView {
|
|
40
58
|
plugin: string;
|
|
59
|
+
/** The plugin's display name (`ExtensionDisplayNames`); null when it has none. */
|
|
60
|
+
displayName: LocalizedName | null;
|
|
41
61
|
version: string;
|
|
42
62
|
/** 插件声明了部署级配置。 */
|
|
43
63
|
configurable: boolean;
|
|
44
64
|
fields: DeploymentConfigField[];
|
|
45
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* 部署级 schema 的 JSON Schema(密钥字段带 `x-secret`,提示 `x-ui` / `x-hot`)。本副本拿不到模块(未加载的
|
|
67
|
+
* 安装记录)时取包内的 `extension.configSchemas.deployment`(`validated` 为 false);旧包没有它时为 null。
|
|
68
|
+
*/
|
|
46
69
|
schema: JsonSchema | null;
|
|
47
70
|
/** 生效配置按 schema 校验通过(`validated` 为 false 时没有校验,恒为 true,界面不要据此显示「合法」)。 */
|
|
48
71
|
valid: boolean;
|
|
@@ -79,6 +102,7 @@ export declare class ExtensionDeploymentConfigService {
|
|
|
79
102
|
/** Publishes {@link PLUGIN_DEPLOYMENT_CONFIG_TOPIC} after a save (a failure only warns). */
|
|
80
103
|
private readonly bus;
|
|
81
104
|
private readonly log;
|
|
105
|
+
private readonly displayNames;
|
|
82
106
|
/** Where each startup-config field comes from (see `extensionConfigSources`); those fields are read-only. */
|
|
83
107
|
private readonly sources;
|
|
84
108
|
constructor(kdb: KernelDb, txHost: TransactionHost,
|
|
@@ -91,7 +115,7 @@ export declare class ExtensionDeploymentConfigService {
|
|
|
91
115
|
/** Applies a saved config on this replica at once (other replicas through the bus). */
|
|
92
116
|
lifecycle: ExtensionLifecycle,
|
|
93
117
|
/** Publishes {@link PLUGIN_DEPLOYMENT_CONFIG_TOPIC} after a save (a failure only warns). */
|
|
94
|
-
bus: PublishBus, log: KernelLogger, options: Pick<KernelAppOptions, "env" | "extensionConfigSources"
|
|
118
|
+
bus: PublishBus, log: KernelLogger, options: Pick<KernelAppOptions, "env" | "extensionConfigSources">, displayNames: ExtensionDisplayNames);
|
|
95
119
|
private get db();
|
|
96
120
|
/** The startup config's `extensionConfig` (file / Nacos merged with env). */
|
|
97
121
|
private fileConfig;
|
|
@@ -113,17 +137,40 @@ export declare class ExtensionDeploymentConfigService {
|
|
|
113
137
|
* invalid after merging (except a problem in a read-only startup-config field itself) ->
|
|
114
138
|
* `extension.config_invalid` (details carry only paths and messages);
|
|
115
139
|
* - a field present in the startup config (file / Nacos / env) -> 409 `extension.config_readonly`.
|
|
140
|
+
* `secretEntries` change single keys of secret records some `x-ui.secrets[].path` names
|
|
141
|
+
* ({@link SecretEntry}; spec §4.3): applied under the same locks to the decrypted record, which
|
|
142
|
+
* is re-encrypted whole, then validated with `values`; the audit lists the record's path, no keys.
|
|
143
|
+
* A path no hint names -> 400 `validation_failed`; one in the startup config -> 409
|
|
144
|
+
* `extension.config_readonly`.
|
|
116
145
|
* In a transaction, first `lockEnterpriseAdminsAndAuthorize` (re-checks the enterprise admin under
|
|
117
146
|
* the lock), then an advisory lock per extension; audit `extension.deployment_config_updated`
|
|
118
147
|
* (detail only `changedPaths`). After the commit publishes {@link PLUGIN_DEPLOYMENT_CONFIG_TOPIC} and
|
|
119
148
|
* applies it on this replica right away.
|
|
120
149
|
*/
|
|
121
|
-
put(plugin: string, values: Record<string, unknown>, actor: string, actorTokenId?: string): Promise<DeploymentConfigView>;
|
|
150
|
+
put(plugin: string, values: Record<string, unknown>, actor: string, actorTokenId?: string, secretEntries?: readonly SecretEntry[]): Promise<DeploymentConfigView>;
|
|
151
|
+
/**
|
|
152
|
+
* Secret entries name a secret record field some hint names (else 400 `validation_failed`, also
|
|
153
|
+
* for a path given in `values` too, an entry with neither `value` nor `renameFrom`, or a key
|
|
154
|
+
* `__proto__`). Messages carry paths and keys only, never values.
|
|
155
|
+
*/
|
|
156
|
+
private checkSecretEntries;
|
|
122
157
|
private write;
|
|
123
158
|
private info;
|
|
124
159
|
private render;
|
|
160
|
+
/**
|
|
161
|
+
* The form JSON Schema of the description: the zod schema's, else the package's static one. A
|
|
162
|
+
* hint conversion that throws (a hand-made package) drops the hints: the plain schema, or none
|
|
163
|
+
* when even the conversion fails; one warning per schema. Never throws.
|
|
164
|
+
*/
|
|
165
|
+
private formSchemaOf;
|
|
166
|
+
private messagesOf;
|
|
167
|
+
/** The secret record paths some hint of the form schema names. */
|
|
168
|
+
private hintedPaths;
|
|
125
169
|
}
|
|
126
170
|
/**
|
|
127
171
|
* 本副本拿不到模块时(未加载的安装记录)按包内审阅过的静态清单给出字段(没有 zod schema:不校验,加载时再校验)。
|
|
172
|
+
* The package's `extension.configSchemas.deployment` (written by the packer) is the form schema;
|
|
173
|
+
* its hints are checked like a loaded schema's (stripped when invalid, silently: a hand-made
|
|
174
|
+
* package). It is not compared with the module (not part of `manifest_mismatch`, spec §4.5).
|
|
128
175
|
*/
|
|
129
176
|
export declare function staticDeploymentSchema(db: KernelSchemaDb, plugin: string): Promise<DeploymentSchemaInfo | undefined>;
|
|
@@ -22,8 +22,9 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
|
22
22
|
import { KERNEL_BUS, KERNEL_LOGGER, KEYRING } from "../infra/tokens.js";
|
|
23
23
|
import { KERNEL_APP_OPTIONS } from "../lifecycle/tokens.js";
|
|
24
24
|
import { toIssues } from "./config-issues.js";
|
|
25
|
-
import {
|
|
26
|
-
import { DEPLOYMENT_SECRETS_ORG, deleteDeep, mergeDeploymentConfig, readStoredDeploymentConfig, SECRETS_NAMESPACE, schemaFields, secretKey, secretPathsOf, setDeep, } from "./deployment-config-store.js";
|
|
25
|
+
import { checkConfigUi, configMessages, hintedSecretPaths, safeConfigFormSchema, } from "./config-json-schema.js";
|
|
26
|
+
import { DEPLOYMENT_SECRETS_ORG, deleteDeep, isObj, mergeDeploymentConfig, readStoredDeploymentConfig, SECRETS_NAMESPACE, schemaFields, secretKey, secretPathsOf, setDeep, } from "./deployment-config-store.js";
|
|
27
|
+
import { ExtensionDisplayNames } from "./display-name.js";
|
|
27
28
|
import { ExtensionHost } from "./host.js";
|
|
28
29
|
import { ExtensionInstalls } from "./installs.js";
|
|
29
30
|
import { ExtensionLifecycle } from "./lifecycle.js";
|
|
@@ -31,16 +32,6 @@ import { PLUGIN_DEPLOYMENT_CONFIG_TOPIC } from "./lifecycle-topics.js";
|
|
|
31
32
|
import { PluginDeploymentConfigLock } from "./locks.js";
|
|
32
33
|
export { DEPLOYMENT_SECRETS_ORG, mergeDeploymentConfig, readStoredDeploymentConfig, schemaFields, secretPathsOf, };
|
|
33
34
|
export { PLUGIN_DEPLOYMENT_CONFIG_TOPIC };
|
|
34
|
-
/** JSON Schema 转换按 schema 对象缓存(清单不可变)。 */
|
|
35
|
-
const jsonSchemaCache = new WeakMap();
|
|
36
|
-
function jsonSchemaOf(schema) {
|
|
37
|
-
let js = jsonSchemaCache.get(schema);
|
|
38
|
-
if (!js) {
|
|
39
|
-
js = configToJsonSchema(schema);
|
|
40
|
-
jsonSchemaCache.set(schema, js);
|
|
41
|
-
}
|
|
42
|
-
return structuredClone(js);
|
|
43
|
-
}
|
|
44
35
|
/** 某字段 zod 叶子上的默认值(整份配置不合法、校验没能补上默认值时,视图仍按它显示)。 */
|
|
45
36
|
function defaultOf(schema, path) {
|
|
46
37
|
const f = configFields(schema).find((x) => x.path === path);
|
|
@@ -69,6 +60,7 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
|
|
|
69
60
|
lifecycle;
|
|
70
61
|
bus;
|
|
71
62
|
log;
|
|
63
|
+
displayNames;
|
|
72
64
|
/** Where each startup-config field comes from (see `extensionConfigSources`); those fields are read-only. */
|
|
73
65
|
sources;
|
|
74
66
|
constructor(kdb, txHost,
|
|
@@ -81,7 +73,7 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
|
|
|
81
73
|
/** Applies a saved config on this replica at once (other replicas through the bus). */
|
|
82
74
|
lifecycle,
|
|
83
75
|
/** Publishes {@link PLUGIN_DEPLOYMENT_CONFIG_TOPIC} after a save (a failure only warns). */
|
|
84
|
-
bus, log, options) {
|
|
76
|
+
bus, log, options, displayNames) {
|
|
85
77
|
this.kdb = kdb;
|
|
86
78
|
this.txHost = txHost;
|
|
87
79
|
this.adminLock = adminLock;
|
|
@@ -93,6 +85,7 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
|
|
|
93
85
|
this.lifecycle = lifecycle;
|
|
94
86
|
this.bus = bus;
|
|
95
87
|
this.log = log;
|
|
88
|
+
this.displayNames = displayNames;
|
|
96
89
|
const env = options.env ?? process.env;
|
|
97
90
|
this.sources =
|
|
98
91
|
options.extensionConfigSources ??
|
|
@@ -125,8 +118,11 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
|
|
|
125
118
|
/** Admin view; an extension unknown to the deployment -> `extension.not_found`. */
|
|
126
119
|
async view(plugin) {
|
|
127
120
|
const info = await this.info(plugin);
|
|
128
|
-
const stored = await
|
|
129
|
-
|
|
121
|
+
const [stored, displayName] = await Promise.all([
|
|
122
|
+
this.readStored(plugin, info),
|
|
123
|
+
this.displayNames.get(plugin),
|
|
124
|
+
]);
|
|
125
|
+
return this.render(plugin, info, stored, displayName);
|
|
130
126
|
}
|
|
131
127
|
/** `REPEATABLE READ` read-only: every stored field from one snapshot. */
|
|
132
128
|
readStored(plugin, info) {
|
|
@@ -141,12 +137,17 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
|
|
|
141
137
|
* invalid after merging (except a problem in a read-only startup-config field itself) ->
|
|
142
138
|
* `extension.config_invalid` (details carry only paths and messages);
|
|
143
139
|
* - a field present in the startup config (file / Nacos / env) -> 409 `extension.config_readonly`.
|
|
140
|
+
* `secretEntries` change single keys of secret records some `x-ui.secrets[].path` names
|
|
141
|
+
* ({@link SecretEntry}; spec §4.3): applied under the same locks to the decrypted record, which
|
|
142
|
+
* is re-encrypted whole, then validated with `values`; the audit lists the record's path, no keys.
|
|
143
|
+
* A path no hint names -> 400 `validation_failed`; one in the startup config -> 409
|
|
144
|
+
* `extension.config_readonly`.
|
|
144
145
|
* In a transaction, first `lockEnterpriseAdminsAndAuthorize` (re-checks the enterprise admin under
|
|
145
146
|
* the lock), then an advisory lock per extension; audit `extension.deployment_config_updated`
|
|
146
147
|
* (detail only `changedPaths`). After the commit publishes {@link PLUGIN_DEPLOYMENT_CONFIG_TOPIC} and
|
|
147
148
|
* applies it on this replica right away.
|
|
148
149
|
*/
|
|
149
|
-
async put(plugin, values, actor, actorTokenId) {
|
|
150
|
+
async put(plugin, values, actor, actorTokenId, secretEntries = []) {
|
|
150
151
|
const info = await this.info(plugin);
|
|
151
152
|
if (info.fields.length === 0) {
|
|
152
153
|
throw new ApiError("extension.config_invalid", `Extension ${plugin} has no deployment config`);
|
|
@@ -156,14 +157,16 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
|
|
|
156
157
|
if (unknown.length > 0) {
|
|
157
158
|
throw new ApiError("extension.config_invalid", `Unknown deployment config fields for extension ${plugin}`, unknown.map((path) => ({ path, message: "unknown field" })));
|
|
158
159
|
}
|
|
160
|
+
this.checkSecretEntries(plugin, info, values, secretEntries);
|
|
159
161
|
const sources = this.sources[plugin];
|
|
160
|
-
const
|
|
162
|
+
const entryPaths = [...new Set(secretEntries.map((e) => e.path))];
|
|
163
|
+
const readonly = [...Object.keys(values), ...entryPaths].filter((p) => fieldSource(sources, p) !== undefined);
|
|
161
164
|
if (readonly.length > 0) {
|
|
162
165
|
throw new ApiError("extension.config_readonly", `These deployment config fields of extension ${plugin} are set in the startup config (file, Nacos or environment) and are read-only here: ${readonly.join(", ")}`, readonly.map((path) => ({ path, source: fieldSource(sources, path) })));
|
|
163
166
|
}
|
|
164
167
|
const fileValue = this.fileConfig()[plugin];
|
|
165
168
|
const fieldPaths = info.fields.map((f) => f.path);
|
|
166
|
-
const { saved, changed } = await this.write(plugin, values, actor, actorTokenId, info, sources, fileValue);
|
|
169
|
+
const { saved, changed } = await this.write(plugin, values, secretEntries, actor, actorTokenId, info, sources, fileValue);
|
|
167
170
|
const stored = saved ?? {};
|
|
168
171
|
if (info.schema) {
|
|
169
172
|
const secrets = secretValues(info.schema, mergeDeploymentConfig(stored, fileValue, fieldPaths));
|
|
@@ -187,9 +190,38 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
|
|
|
187
190
|
});
|
|
188
191
|
}
|
|
189
192
|
}
|
|
190
|
-
return this.render(plugin, info, stored);
|
|
193
|
+
return this.render(plugin, info, stored, await this.displayNames.get(plugin));
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Secret entries name a secret record field some hint names (else 400 `validation_failed`, also
|
|
197
|
+
* for a path given in `values` too, an entry with neither `value` nor `renameFrom`, or a key
|
|
198
|
+
* `__proto__`). Messages carry paths and keys only, never values.
|
|
199
|
+
*/
|
|
200
|
+
checkSecretEntries(plugin, info, values, entries) {
|
|
201
|
+
if (entries.length === 0)
|
|
202
|
+
return;
|
|
203
|
+
const hinted = this.hintedPaths(plugin, info);
|
|
204
|
+
const secret = new Set(secretPathsOf(info.fields));
|
|
205
|
+
const problems = [];
|
|
206
|
+
for (const e of entries) {
|
|
207
|
+
if (!hinted.has(e.path) || !secret.has(e.path)) {
|
|
208
|
+
problems.push({ path: e.path, message: "no config UI hint draws this secret per item" });
|
|
209
|
+
}
|
|
210
|
+
else if (Object.hasOwn(values, e.path)) {
|
|
211
|
+
problems.push({ path: e.path, message: "given both in values and in secretEntries" });
|
|
212
|
+
}
|
|
213
|
+
else if (e.value === undefined && e.renameFrom === undefined) {
|
|
214
|
+
problems.push({ path: e.path, message: `entry ${e.key} has neither value nor renameFrom` });
|
|
215
|
+
}
|
|
216
|
+
else if (e.key === "__proto__" || e.renameFrom === "__proto__") {
|
|
217
|
+
problems.push({ path: e.path, message: "__proto__ is not a valid key" });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (problems.length > 0) {
|
|
221
|
+
throw new ApiError("validation_failed", `Invalid secret entries for the deployment config of extension ${plugin}`, problems);
|
|
222
|
+
}
|
|
191
223
|
}
|
|
192
|
-
async write(plugin, values, actor, actorTokenId, info, sources, fileValue) {
|
|
224
|
+
async write(plugin, values, secretEntries, actor, actorTokenId, info, sources, fileValue) {
|
|
193
225
|
const fieldPaths = info.fields.map((f) => f.path);
|
|
194
226
|
let changed = [];
|
|
195
227
|
const t = this.db;
|
|
@@ -206,17 +238,19 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
|
|
|
206
238
|
else
|
|
207
239
|
setDeep(next, path, structuredClone(v));
|
|
208
240
|
}
|
|
241
|
+
applySecretEntries(next, secretEntries);
|
|
242
|
+
const touched = new Set([...Object.keys(values), ...secretEntries.map((e) => e.path)]);
|
|
209
243
|
if (info.schema) {
|
|
210
244
|
const r = info.schema.safeParse(mergeDeploymentConfig(next, fileValue, fieldPaths));
|
|
211
245
|
if (!r.success) {
|
|
212
246
|
// 启动配置里只读字段自己的问题这里改不了(照样保存,插件保持待配置),其余拒绝
|
|
213
|
-
const issues = toIssues(r.error).filter((i) => i.path === "" || fieldSource(sources, i.path) === undefined);
|
|
247
|
+
const issues = toIssues(r.error, this.messagesOf(plugin, info)).filter((i) => i.path === "" || fieldSource(sources, i.path) === undefined);
|
|
214
248
|
if (issues.length > 0) {
|
|
215
249
|
throw new ApiError("extension.config_invalid", `Invalid deployment config for extension ${plugin}`, issues);
|
|
216
250
|
}
|
|
217
251
|
}
|
|
218
252
|
}
|
|
219
|
-
changed =
|
|
253
|
+
changed = [...touched]
|
|
220
254
|
.filter((p) => !isDeepStrictEqual(getPath(before, p), getPath(next, p)))
|
|
221
255
|
.sort();
|
|
222
256
|
const saved = next;
|
|
@@ -228,7 +262,7 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
|
|
|
228
262
|
if (!f.secret)
|
|
229
263
|
continue;
|
|
230
264
|
deleteDeep(plain, f.path);
|
|
231
|
-
if (!(f.path
|
|
265
|
+
if (!touched.has(f.path))
|
|
232
266
|
continue;
|
|
233
267
|
const v = getPath(next, f.path);
|
|
234
268
|
if (v === undefined)
|
|
@@ -261,7 +295,7 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
|
|
|
261
295
|
}
|
|
262
296
|
return info;
|
|
263
297
|
}
|
|
264
|
-
render(plugin, info, stored) {
|
|
298
|
+
render(plugin, info, stored, displayName) {
|
|
265
299
|
const fileValue = this.fileConfig()[plugin];
|
|
266
300
|
const sources = this.sources[plugin];
|
|
267
301
|
const raw = mergeDeploymentConfig(stored, fileValue, info.fields.map((f) => f.path));
|
|
@@ -274,9 +308,11 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
|
|
|
274
308
|
effective = r.data;
|
|
275
309
|
else {
|
|
276
310
|
valid = false;
|
|
277
|
-
issues = toIssues(r.error);
|
|
311
|
+
issues = toIssues(r.error, this.messagesOf(plugin, info));
|
|
278
312
|
}
|
|
279
313
|
}
|
|
314
|
+
const formSchema = this.formSchemaOf(plugin, info);
|
|
315
|
+
const hinted = formSchema ? hintedSecretPaths(formSchema) : new Set();
|
|
280
316
|
const fields = info.fields.map((f) => {
|
|
281
317
|
const from = fieldSource(sources, f.path);
|
|
282
318
|
let value = getPath(effective, f.path);
|
|
@@ -298,21 +334,48 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
|
|
|
298
334
|
source,
|
|
299
335
|
readonly: from !== undefined,
|
|
300
336
|
};
|
|
337
|
+
// a schema default (e.g. `secret(record).default({})`) is no secret anybody set
|
|
338
|
+
const set = value !== undefined && source !== "default";
|
|
339
|
+
if (f.secret && hinted.has(f.path)) {
|
|
340
|
+
// record keys are item names, never values
|
|
341
|
+
return { ...base, set, keys: set && isObj(value) ? Object.keys(value).sort() : [] };
|
|
342
|
+
}
|
|
301
343
|
if (f.secret)
|
|
302
|
-
return { ...base, set
|
|
344
|
+
return { ...base, set };
|
|
303
345
|
return value === undefined ? base : { ...base, value: structuredClone(value) };
|
|
304
346
|
});
|
|
305
347
|
return {
|
|
306
348
|
plugin,
|
|
349
|
+
displayName,
|
|
307
350
|
version: info.version,
|
|
308
351
|
configurable: info.fields.length > 0,
|
|
309
352
|
fields,
|
|
310
|
-
schema:
|
|
353
|
+
schema: structuredClone(formSchema ?? null),
|
|
311
354
|
valid,
|
|
312
355
|
validated: info.schema !== undefined,
|
|
313
356
|
issues,
|
|
314
357
|
};
|
|
315
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* The form JSON Schema of the description: the zod schema's, else the package's static one. A
|
|
361
|
+
* hint conversion that throws (a hand-made package) drops the hints: the plain schema, or none
|
|
362
|
+
* when even the conversion fails; one warning per schema. Never throws.
|
|
363
|
+
*/
|
|
364
|
+
formSchemaOf(plugin, info) {
|
|
365
|
+
if (!info.schema)
|
|
366
|
+
return info.jsonSchema;
|
|
367
|
+
const r = safeConfigFormSchema(info.schema, "deployment", (err, schema) => this.log.warn("the deployment config form schema could not be built with its UI hints; hints dropped", { plugin, version: info.version, schema, err }));
|
|
368
|
+
return r?.schema;
|
|
369
|
+
}
|
|
370
|
+
messagesOf(plugin, info) {
|
|
371
|
+
const js = this.formSchemaOf(plugin, info);
|
|
372
|
+
return js && configMessages(js);
|
|
373
|
+
}
|
|
374
|
+
/** The secret record paths some hint of the form schema names. */
|
|
375
|
+
hintedPaths(plugin, info) {
|
|
376
|
+
const js = this.formSchemaOf(plugin, info);
|
|
377
|
+
return js ? hintedSecretPaths(js) : new Set();
|
|
378
|
+
}
|
|
316
379
|
};
|
|
317
380
|
__decorate([
|
|
318
381
|
Transactional({
|
|
@@ -337,11 +400,38 @@ ExtensionDeploymentConfigService = __decorate([
|
|
|
337
400
|
__param(8, Inject(ExtensionLifecycle)),
|
|
338
401
|
__param(9, Inject(KERNEL_BUS)),
|
|
339
402
|
__param(10, Inject(KERNEL_LOGGER)),
|
|
340
|
-
__param(11, Inject(KERNEL_APP_OPTIONS))
|
|
403
|
+
__param(11, Inject(KERNEL_APP_OPTIONS)),
|
|
404
|
+
__param(12, Inject(ExtensionDisplayNames))
|
|
341
405
|
], ExtensionDeploymentConfigService);
|
|
342
406
|
export { ExtensionDeploymentConfigService };
|
|
407
|
+
/**
|
|
408
|
+
* Applies secret entries in order to the decrypted config `next` (in place): each record is read
|
|
409
|
+
* from `next` at its path, renamed, set or removed, and put back; an empty record is removed (the
|
|
410
|
+
* field falls back to its default).
|
|
411
|
+
*/
|
|
412
|
+
function applySecretEntries(next, entries) {
|
|
413
|
+
for (const e of entries) {
|
|
414
|
+
const cur = getPath(next, e.path);
|
|
415
|
+
const rec = isObj(cur) ? { ...cur } : {};
|
|
416
|
+
if (e.renameFrom !== undefined && e.renameFrom !== e.key && Object.hasOwn(rec, e.renameFrom)) {
|
|
417
|
+
rec[e.key] = rec[e.renameFrom];
|
|
418
|
+
delete rec[e.renameFrom];
|
|
419
|
+
}
|
|
420
|
+
if (e.value === null)
|
|
421
|
+
delete rec[e.key];
|
|
422
|
+
else if (e.value !== undefined)
|
|
423
|
+
rec[e.key] = e.value;
|
|
424
|
+
if (Object.keys(rec).length === 0)
|
|
425
|
+
deleteDeep(next, e.path);
|
|
426
|
+
else
|
|
427
|
+
setDeep(next, e.path, rec);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
343
430
|
/**
|
|
344
431
|
* 本副本拿不到模块时(未加载的安装记录)按包内审阅过的静态清单给出字段(没有 zod schema:不校验,加载时再校验)。
|
|
432
|
+
* The package's `extension.configSchemas.deployment` (written by the packer) is the form schema;
|
|
433
|
+
* its hints are checked like a loaded schema's (stripped when invalid, silently: a hand-made
|
|
434
|
+
* package). It is not compared with the module (not part of `manifest_mismatch`, spec §4.5).
|
|
345
435
|
*/
|
|
346
436
|
export async function staticDeploymentSchema(db, plugin) {
|
|
347
437
|
const row = await db
|
|
@@ -355,8 +445,15 @@ export async function staticDeploymentSchema(db, plugin) {
|
|
|
355
445
|
// new rows hold the plugin's extension section, pre-0.1.0 rows the old capybara section; both
|
|
356
446
|
// carry the static manifest
|
|
357
447
|
const section = row.section;
|
|
448
|
+
const stored = section.configSchemas?.deployment;
|
|
449
|
+
let jsonSchema;
|
|
450
|
+
if (typeof stored === "object" && stored !== null && !Array.isArray(stored)) {
|
|
451
|
+
jsonSchema = structuredClone(stored);
|
|
452
|
+
checkConfigUi(jsonSchema, "deployment");
|
|
453
|
+
}
|
|
358
454
|
return {
|
|
359
455
|
version: row.version,
|
|
456
|
+
...(jsonSchema !== undefined && { jsonSchema }),
|
|
360
457
|
fields: (section.manifest.config?.deployment ?? []).map((f) => ({
|
|
361
458
|
path: f.path,
|
|
362
459
|
secret: f.secret,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { LocalizedName } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
3
|
+
import { ExtensionHost } from "./host.js";
|
|
4
|
+
/**
|
|
5
|
+
* Extension display names (extension config forms spec §2.2), the one resolver every extension and
|
|
6
|
+
* model API uses: a config-declared extension's plugin.json (read by this replica's host at load,
|
|
7
|
+
* the same on every replica), else the installed package's `display_name`, else the live catalog
|
|
8
|
+
* item of the same name, else null. No backfill: a package stored before 0066 gets a name with its
|
|
9
|
+
* next version. Stateless; one query per call.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ExtensionDisplayNames {
|
|
12
|
+
private readonly db;
|
|
13
|
+
/** The config-declared extensions (they win over an install record of the same name, C15). */
|
|
14
|
+
private readonly host;
|
|
15
|
+
constructor(db: KernelDb,
|
|
16
|
+
/** The config-declared extensions (they win over an install record of the same name, C15). */
|
|
17
|
+
host: ExtensionHost);
|
|
18
|
+
/** One extension's display name. */
|
|
19
|
+
get(name: string): Promise<LocalizedName | null>;
|
|
20
|
+
/** The display names of `names` (each one a key, null when it has none), in one query. */
|
|
21
|
+
many(names: string[]): Promise<Map<string, LocalizedName | null>>;
|
|
22
|
+
}
|