@capybara-hq/kernel 0.1.0-rc.57 → 0.1.0-rc.59
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-catalog.controller.d.ts +0 -5
- package/dist/catalog/org-catalog.controller.js +3 -17
- package/dist/catalog/org-catalog.schemas.d.ts +43 -0
- package/dist/catalog/org-catalog.schemas.js +43 -2
- 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/catalog/plugin-install.d.ts +2 -0
- package/dist/catalog/plugin-install.js +3 -3
- 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/channels.schemas.d.ts +3 -0
- package/dist/channels/channels.schemas.js +8 -0
- package/dist/channels/connections.service.d.ts +17 -2
- package/dist/channels/connections.service.js +30 -5
- package/dist/channels/outbound.js +25 -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 +35 -0
- package/dist/conversations/events.js +29 -0
- package/dist/conversations/leak-check.d.ts +26 -0
- package/dist/conversations/leak-check.js +69 -0
- package/dist/ctx/secrets.d.ts +13 -1
- package/dist/ctx/secrets.js +19 -1
- package/dist/db/kernel-schema.d.ts +34 -0
- package/dist/devices/working-root.d.ts +2 -3
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +19 -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/http/api.module.js +6 -0
- package/dist/identity/initial-passwords.job.d.ts +3 -2
- package/dist/identity/initial-passwords.job.js +11 -5
- package/dist/orgs/invitations.controller.d.ts +3 -11
- package/dist/orgs/invitations.controller.js +9 -10
- package/dist/orgs/invitations.service.d.ts +12 -2
- package/dist/orgs/invitations.service.js +14 -7
- package/dist/orgs/members.service.d.ts +12 -2
- package/dist/orgs/members.service.js +10 -8
- package/dist/orgs/orgs.controller.d.ts +4 -12
- package/dist/orgs/orgs.controller.js +10 -10
- package/dist/orgs/orgs.schemas.d.ts +26 -0
- package/dist/orgs/orgs.schemas.js +22 -0
- package/dist/platform/connector-person-fields.d.ts +67 -0
- package/dist/platform/connector-person-fields.js +129 -0
- package/dist/platform/exclusions.js +6 -141
- package/dist/platform/method.js +1 -0
- package/dist/platform/operation.d.ts +61 -2
- package/dist/platform/operation.js +4 -4
- package/dist/platform/ops/accounts.ops.js +1 -0
- package/dist/platform/ops/channels.ops.d.ts +10 -3
- package/dist/platform/ops/channels.ops.js +223 -5
- package/dist/platform/ops/connectors.ops.d.ts +22 -4
- package/dist/platform/ops/connectors.ops.js +664 -13
- 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/org-plugins.ops.d.ts +15 -2
- package/dist/platform/ops/org-plugins.ops.js +323 -4
- package/dist/platform/ops/orgs.ops.d.ts +40 -3
- package/dist/platform/ops/orgs.ops.js +293 -12
- package/dist/platform/ops/person-inputs.d.ts +65 -0
- package/dist/platform/ops/person-inputs.js +129 -0
- package/dist/platform/ops/plugins.ops.d.ts +3 -1
- package/dist/platform/ops/plugins.ops.js +33 -20
- package/dist/platform/parity.d.ts +7 -2
- package/dist/platform/parity.js +75 -13
- package/dist/platform/person-fields.d.ts +119 -0
- package/dist/platform/person-fields.js +403 -0
- package/dist/platform/platform.module.d.ts +4 -3
- package/dist/platform/platform.module.js +8 -5
- package/dist/platform/route-schemas.js +2 -0
- package/dist/platform/sealed-inputs.d.ts +44 -0
- package/dist/platform/sealed-inputs.js +116 -0
- package/dist/platform/sealed-reveals.controller.d.ts +20 -0
- package/dist/platform/sealed-reveals.controller.js +48 -0
- package/dist/platform/sealed-reveals.d.ts +52 -0
- package/dist/platform/sealed-reveals.js +153 -0
- package/dist/runtime/project/knowledge.js +24 -19
- package/dist/runtime/waits.js +8 -2
- package/dist/sandbox/permission-facts.d.ts +5 -1
- package/dist/sandbox/permission-facts.js +8 -2
- package/dist/setup/setup-guides.service.d.ts +5 -0
- package/dist/setup/setup-guides.service.js +2 -1
- 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 +214 -15
- package/dist/tools/connectors.controller.d.ts +6 -7
- package/dist/tools/connectors.controller.js +4 -44
- package/dist/tools/connectors.schemas.d.ts +170 -1
- package/dist/tools/connectors.schemas.js +82 -3
- package/dist/tools/connectors.service.d.ts +16 -6
- package/dist/tools/connectors.service.js +39 -24
- package/dist/tools/oauth/oauth.controller.d.ts +3 -6
- package/dist/tools/oauth/oauth.controller.js +3 -12
- package/dist/tools/oauth/oauth.schemas.d.ts +14 -0
- package/dist/tools/oauth/oauth.schemas.js +27 -0
- package/dist/tools/pipeline.d.ts +31 -2
- package/dist/tools/pipeline.js +89 -17
- package/dist/tools/policy.d.ts +4 -0
- package/dist/tools/policy.js +8 -0
- package/dist/tools/registry.d.ts +29 -0
- package/dist/tools/tools.module.js +3 -0
- package/package.json +3 -3
- package/src/migrations/0169_platform_sealed_inputs.sql +23 -0
- package/src/migrations/0170_platform_sealed_reveals.sql +27 -0
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { ToolError } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { ToolViewSchema } from "../../conversations/events.js";
|
|
3
4
|
import { availability, PLATFORM_UNAVAILABLE_OFF, } from "../../platform/availability.js";
|
|
4
5
|
import { errorRoleOf, errorsFor, nextStepFor, OPERATION_ERROR_NEXT, resolveNext, sentence, toToolError, } from "../../platform/errors.js";
|
|
5
6
|
import { PLATFORM_METHOD } from "../../platform/method.js";
|
|
6
7
|
import { OPERATION_ID, operationDomain, PRECHECK_TIMEOUT_MS, } from "../../platform/operation.js";
|
|
8
|
+
import { PersonFieldsRefused, planPersonFields, } from "../../platform/person-fields.js";
|
|
9
|
+
import { SealedInputsExpiredError } from "../../platform/sealed-inputs.js";
|
|
7
10
|
import { BUILTIN } from "../builtin-names.js";
|
|
8
11
|
/**
|
|
9
12
|
* The `Platform` builtin (Platform tool spec §3–§6): one tool through which an agent discovers and
|
|
@@ -18,6 +21,11 @@ import { BUILTIN } from "../builtin-names.js";
|
|
|
18
21
|
* waited).
|
|
19
22
|
* - An `ApiError` gets the next step the operation declares for its code and the actor's role.
|
|
20
23
|
* - The actor, the agent and the conversation come from the runtime context, never from input.
|
|
24
|
+
* - A write with person fields (platform web parity spec §4: `op.personFields`) is planned at the
|
|
25
|
+
* policy step: a secret in `values` is denied before the card, and the asked fields go to the
|
|
26
|
+
* card through {@link CallPolicy.personFields} (never remembered). The approved call reads the
|
|
27
|
+
* person's sealed values through `personInputs` and its result names each entered path, never a
|
|
28
|
+
* value.
|
|
21
29
|
* - Results are JSON text; a list an operation returns is capped at {@link LIST_MAX} entries.
|
|
22
30
|
*/
|
|
23
31
|
/** The most entries of a list in one result (operations that page return `next`). */
|
|
@@ -137,6 +145,45 @@ const capped = (items) => ({
|
|
|
137
145
|
hint: "Narrow the query or pass params.cursor where the operation pages.",
|
|
138
146
|
}),
|
|
139
147
|
});
|
|
148
|
+
/**
|
|
149
|
+
* The operation's link card for this result (platform web parity spec §6), or null. A throw or an
|
|
150
|
+
* invalid card leaves it out with a warning: the result stands either way.
|
|
151
|
+
*/
|
|
152
|
+
function handoffOf(op, params, result, ctx, log) {
|
|
153
|
+
if (op.handoff === undefined)
|
|
154
|
+
return null;
|
|
155
|
+
try {
|
|
156
|
+
const view = op.handoff(params, result, ctx);
|
|
157
|
+
if (view === null)
|
|
158
|
+
return null;
|
|
159
|
+
const parsed = ToolViewSchema.safeParse(view);
|
|
160
|
+
if (parsed.success && parsed.data.kind === "handoff")
|
|
161
|
+
return parsed.data;
|
|
162
|
+
log?.warn("platform operation returned an invalid handoff card; left out", {
|
|
163
|
+
operation: op.id,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
catch (e) {
|
|
167
|
+
log?.warn("platform operation handoff failed; card left out", {
|
|
168
|
+
operation: op.id,
|
|
169
|
+
error: e instanceof Error ? e.message : String(e),
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* A link card's path is in the result text for the model too (`reviewUrl`, spec §6), unless the
|
|
176
|
+
* operation already returned one.
|
|
177
|
+
*/
|
|
178
|
+
function withReviewUrl(out, view) {
|
|
179
|
+
if (view === null || view.target.type !== "link")
|
|
180
|
+
return out;
|
|
181
|
+
if (typeof out !== "object" || out === null || Array.isArray(out))
|
|
182
|
+
return out;
|
|
183
|
+
if ("reviewUrl" in out)
|
|
184
|
+
return out;
|
|
185
|
+
return { ...out, reviewUrl: view.target.url };
|
|
186
|
+
}
|
|
140
187
|
/** An operation's result as a JSON object: a bare list is capped, nothing becomes `{ ok: true }`. */
|
|
141
188
|
function asResult(value) {
|
|
142
189
|
if (Array.isArray(value))
|
|
@@ -152,6 +199,25 @@ const missingText = (action, field, what) => `Action ${action} needs "${field}":
|
|
|
152
199
|
const invalidParamsText = (id, problems) => `Invalid params for ${id}: ${problems}. Call describe with operation "${id}" for its input schema and an example, then call again.`;
|
|
153
200
|
const unavailableOpText = (id, reason) => `Operation ${id} is unavailable, so do not call it again as is: ${reason}`;
|
|
154
201
|
const precheckText = (id, code, message, next) => `Operation ${id} cannot run now: ${code}: ${sentence(message)} ${next ?? OPERATION_ERROR_NEXT}`;
|
|
202
|
+
const secretRecordText = (id, path, target) => `Operation ${id} cannot run now: platform.secret_record_web_only: \`${path}\` is a secret record, which the confirmation card cannot ask for. Tell the person to enter it on the web page of ${target}.`;
|
|
203
|
+
/** Model-visible: the person's values expired before the approved call ran (spec §4.3). */
|
|
204
|
+
export const PERSON_INPUTS_EXPIRED_TEXT = "The values the person entered expired before they were applied; call the operation again.";
|
|
205
|
+
/** Model-visible: an approved call with person fields that has no approval to read them by. */
|
|
206
|
+
const personInputsMissingText = (id) => `Operation ${id} needs values the person enters on the confirmation card, and this call ran without one; call the operation again.`;
|
|
207
|
+
/**
|
|
208
|
+
* Model-visible: the person-field plan refused an approved call when it resumed (the target's
|
|
209
|
+
* secret fields changed while the card waited); `message` is the plan's English refusal.
|
|
210
|
+
*/
|
|
211
|
+
const personRefusedText = (id, message) => `Operation ${id} cannot run as approved: ${message} Correct the params, then call the operation again.`;
|
|
212
|
+
/**
|
|
213
|
+
* Model-visible: the fields to enter differ between the card the person confirmed, the values they
|
|
214
|
+
* sealed and the call as it runs now.
|
|
215
|
+
*/
|
|
216
|
+
const PERSON_FIELDS_CHANGED_TEXT = "The target changed after the person confirmed (the fields to enter differ); call the operation again.";
|
|
217
|
+
/** Model-visible result line: the approved call's operation never applied the person's values. */
|
|
218
|
+
const unusedValuesText = (id) => `The values the person entered were not used by ${id}.`;
|
|
219
|
+
/** The result line of one field the person entered (never its value). */
|
|
220
|
+
const enteredLine = (path) => `\`${path}\`: entered by the person`;
|
|
155
221
|
const outputRefText = (id) => `Operation ${id} writes, and its params hold a {"$output": ...} reference, which the person confirming would see instead of the content. Pass the content inline in params and call again.`;
|
|
156
222
|
/** Whether a value holds a `{"$output": …}` reference anywhere (the pipeline's form). */
|
|
157
223
|
function hasOutputRef(v) {
|
|
@@ -200,6 +266,7 @@ const confirmCtx = (ctx, errorRole) => ({
|
|
|
200
266
|
agentId: ctx.agentId,
|
|
201
267
|
conversationId: ctx.conversationId,
|
|
202
268
|
runId: ctx.runId,
|
|
269
|
+
...(ctx.callId !== undefined && { callId: ctx.callId }),
|
|
203
270
|
signal: new AbortController().signal,
|
|
204
271
|
errorRole,
|
|
205
272
|
});
|
|
@@ -247,22 +314,38 @@ export function platformTool(deps) {
|
|
|
247
314
|
return deny(outputRefText(op.id));
|
|
248
315
|
}
|
|
249
316
|
const role = errorRoleOf(f);
|
|
317
|
+
const octx = confirmCtx(ctx, role);
|
|
318
|
+
let personFields;
|
|
319
|
+
try {
|
|
320
|
+
personFields = await personFieldsOf(op, params, octx);
|
|
321
|
+
}
|
|
322
|
+
catch (e) {
|
|
323
|
+
if (e instanceof PersonFieldsRefused)
|
|
324
|
+
return deny(e.message);
|
|
325
|
+
// a target that cannot be read (gone, not allowed) is the write's own error
|
|
326
|
+
return deny(toToolError(e, (code) => nextStepFor(op.errors, code, role)).message);
|
|
327
|
+
}
|
|
250
328
|
const failed = await precheckOf(op, params, ctx, role, deps.precheckTimeoutMs ?? PRECHECK_TIMEOUT_MS, deps.log);
|
|
251
329
|
if (failed !== null) {
|
|
252
330
|
const next = resolveNext(failed.next, role) ?? nextStepFor(op.errors, failed.code, role);
|
|
253
331
|
return deny(precheckText(op.id, failed.code, failed.message, next));
|
|
254
332
|
}
|
|
255
|
-
const octx = confirmCtx(ctx, role);
|
|
256
333
|
const [cls, summary] = await Promise.all([
|
|
257
334
|
classOf(op, params, octx),
|
|
258
|
-
summaryOf(op, params,
|
|
335
|
+
summaryOf(op, params, op.personFields === undefined
|
|
336
|
+
? octx
|
|
337
|
+
: { ...octx, personAsk: personFields?.fields.map((f) => f.path) ?? [] }),
|
|
259
338
|
]);
|
|
260
339
|
return {
|
|
261
340
|
key,
|
|
262
341
|
policy: "ask",
|
|
263
|
-
// org / platform writes are confirmed every time (spec §6.2)
|
|
264
|
-
|
|
342
|
+
// org / platform writes are confirmed every time (spec §6.2); so is a write with person
|
|
343
|
+
// fields, whatever its class (spec §4.2, R6)
|
|
344
|
+
remember: personFields === null && cls === "personal" && op.rememberable !== false,
|
|
265
345
|
summary,
|
|
346
|
+
...(personFields !== null && { personFields }),
|
|
347
|
+
// its result is shown once to the approver: only the person may confirm it
|
|
348
|
+
...(op.revealsToApprover === true && { personOnly: true }),
|
|
266
349
|
};
|
|
267
350
|
}
|
|
268
351
|
async function run(raw, ctx) {
|
|
@@ -343,25 +426,98 @@ export function platformTool(deps) {
|
|
|
343
426
|
if (!verdict.ok)
|
|
344
427
|
throw new ToolError(unavailableOpText(op.id, verdict.reason));
|
|
345
428
|
const role = errorRoleOf(f);
|
|
429
|
+
const octx = {
|
|
430
|
+
orgId: ctx.orgId,
|
|
431
|
+
actorAccountId: ctx.accountId,
|
|
432
|
+
agentId: ctx.agentId,
|
|
433
|
+
conversationId: ctx.conversationId,
|
|
434
|
+
runId: ctx.runId ?? null,
|
|
435
|
+
callId: ctx.callId,
|
|
436
|
+
signal: ctx.signal,
|
|
437
|
+
errorRole: role,
|
|
438
|
+
};
|
|
439
|
+
/** The paths whose values the handler applied (the result's lines). */
|
|
440
|
+
let entered = [];
|
|
441
|
+
/** Whether the handler called `personInputs.apply` (once at most). */
|
|
442
|
+
let applied = false;
|
|
346
443
|
let result;
|
|
347
444
|
try {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
445
|
+
const person = await personFieldsOf(op, params, octx);
|
|
446
|
+
// what the card showed (the approval's stored specs) binds what runs: the run-time plan
|
|
447
|
+
// must ask exactly those fields, and the sealed values must carry exactly them
|
|
448
|
+
const approvalId = ctx.approvalId;
|
|
449
|
+
const shown = approvalId === undefined ||
|
|
450
|
+
deps.approvalPersonPaths === undefined ||
|
|
451
|
+
ctx.runId === undefined
|
|
452
|
+
? null
|
|
453
|
+
: await deps.approvalPersonPaths(approvalId, {
|
|
454
|
+
orgId: ctx.orgId,
|
|
455
|
+
runId: ctx.runId,
|
|
456
|
+
callId: ctx.callId,
|
|
457
|
+
});
|
|
458
|
+
if (person === null && shown !== null)
|
|
459
|
+
throw new PersonFieldsChanged();
|
|
460
|
+
if (person !== null) {
|
|
461
|
+
const sealed = deps.sealed;
|
|
462
|
+
if (approvalId === undefined || sealed === undefined) {
|
|
463
|
+
throw new ToolError(personInputsMissingText(op.id));
|
|
464
|
+
}
|
|
465
|
+
// an approval made before the call had person fields (the target changed since)
|
|
466
|
+
if (shown === null)
|
|
467
|
+
throw new PersonFieldsChanged();
|
|
468
|
+
const asked = person.fields.map((p) => p.path);
|
|
469
|
+
if (!sameSet(asked, shown))
|
|
470
|
+
throw new PersonFieldsChanged();
|
|
471
|
+
octx.personInputs = {
|
|
472
|
+
paths: shown,
|
|
473
|
+
apply: (fn) => {
|
|
474
|
+
if (applied)
|
|
475
|
+
throw new Error("personInputs.apply called twice");
|
|
476
|
+
applied = true;
|
|
477
|
+
// the person who typed the values is the run's trigger account, the approval's
|
|
478
|
+
// `requested_for` (a role escalation is refused before the card, R5)
|
|
479
|
+
return sealed.consume(approvalId, ctx.accountId, async (values) => {
|
|
480
|
+
// a throw here rolls the row's delete back: nothing is applied
|
|
481
|
+
if (!sameSet(Object.keys(values), shown) || !sameSet(asked, shown)) {
|
|
482
|
+
throw new PersonFieldsChanged();
|
|
483
|
+
}
|
|
484
|
+
const out = await fn(values);
|
|
485
|
+
entered = Object.keys(values).sort();
|
|
486
|
+
return out;
|
|
487
|
+
});
|
|
488
|
+
},
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
result = await op.run(params, octx);
|
|
358
492
|
}
|
|
359
493
|
catch (e) {
|
|
494
|
+
if (e instanceof SealedInputsExpiredError)
|
|
495
|
+
throw new ToolError(PERSON_INPUTS_EXPIRED_TEXT);
|
|
496
|
+
if (e instanceof PersonFieldsChanged)
|
|
497
|
+
throw new ToolError(PERSON_FIELDS_CHANGED_TEXT);
|
|
498
|
+
if (e instanceof PersonFieldsRefused)
|
|
499
|
+
throw new ToolError(personRefusedText(op.id, e.message));
|
|
360
500
|
// a service refusal after the approval (a race the precheck could not see) still names the
|
|
361
501
|
// next step for this actor (Review Focus 2)
|
|
362
502
|
throw toToolError(e, (code) => nextStepFor(op.errors, code, role));
|
|
363
503
|
}
|
|
364
|
-
|
|
504
|
+
const summary = { zh: `调用平台操作 ${op.id}`, en: `Called ${op.id}` };
|
|
505
|
+
const lines = entered.map(enteredLine);
|
|
506
|
+
if (octx.personInputs !== undefined && !applied) {
|
|
507
|
+
// an operation bug: the person typed values the write never used (they expire unread)
|
|
508
|
+
deps.log?.warn("platform operation did not use the person's values", { operation: op.id });
|
|
509
|
+
lines.push(unusedValuesText(op.id));
|
|
510
|
+
}
|
|
511
|
+
const view = handoffOf(op, params, result, octx, deps.log);
|
|
512
|
+
const out = withReviewUrl(asResult(result), view);
|
|
513
|
+
return {
|
|
514
|
+
content: [
|
|
515
|
+
{ type: "text", text: JSON.stringify(out) },
|
|
516
|
+
...(lines.length === 0 ? [] : [{ type: "text", text: lines.join("\n") }]),
|
|
517
|
+
],
|
|
518
|
+
display: { summary },
|
|
519
|
+
...(view !== null && { view }),
|
|
520
|
+
};
|
|
365
521
|
}
|
|
366
522
|
function read(topic) {
|
|
367
523
|
if (topic === undefined || topic === "") {
|
|
@@ -386,6 +542,49 @@ export function platformTool(deps) {
|
|
|
386
542
|
},
|
|
387
543
|
};
|
|
388
544
|
}
|
|
545
|
+
/** The fields to enter differ from what the person confirmed ({@link PERSON_FIELDS_CHANGED_TEXT}). */
|
|
546
|
+
class PersonFieldsChanged extends Error {
|
|
547
|
+
}
|
|
548
|
+
const sameSet = (a, b) => {
|
|
549
|
+
const sa = new Set(a);
|
|
550
|
+
const sb = new Set(b);
|
|
551
|
+
return sa.size === sb.size && [...sa].every((x) => sb.has(x));
|
|
552
|
+
};
|
|
553
|
+
/** The `askPerson` / `clearSecrets` of a validated input (both default to [] in the schema). */
|
|
554
|
+
const pathsOf = (params, key) => {
|
|
555
|
+
const v = params?.[key];
|
|
556
|
+
return Array.isArray(v) ? v.filter((x) => typeof x === "string") : [];
|
|
557
|
+
};
|
|
558
|
+
/**
|
|
559
|
+
* The person fields one call asks for (spec §4.1): `op.personFields` planned against the input's
|
|
560
|
+
* `values`, `askPerson` and `clearSecrets`. Null when the operation has none or the plan asks for
|
|
561
|
+
* nothing. Throws {@link PersonFieldsRefused} with the plan's refusal, or with
|
|
562
|
+
* `platform.secret_record_web_only` when `askPerson` / `clearSecrets` names a secret record the card
|
|
563
|
+
* cannot ask for (ruling R1); an error reading the target propagates.
|
|
564
|
+
*/
|
|
565
|
+
async function personFieldsOf(op, params, ctx) {
|
|
566
|
+
if (op.personFields === undefined)
|
|
567
|
+
return null;
|
|
568
|
+
const target = await op.personFields(params, ctx);
|
|
569
|
+
const askPerson = pathsOf(params, "askPerson");
|
|
570
|
+
const clearSecrets = pathsOf(params, "clearSecrets");
|
|
571
|
+
const records = new Set(target.recordOnly ?? []);
|
|
572
|
+
const record = [...askPerson, ...clearSecrets].find((p) => records.has(p));
|
|
573
|
+
if (record !== undefined) {
|
|
574
|
+
throw new PersonFieldsRefused(secretRecordText(op.id, record, target.target.en));
|
|
575
|
+
}
|
|
576
|
+
const values = params?.values;
|
|
577
|
+
const plan = planPersonFields(target, {
|
|
578
|
+
...(typeof values === "object" &&
|
|
579
|
+
values !== null &&
|
|
580
|
+
!Array.isArray(values) && { values: values }),
|
|
581
|
+
askPerson,
|
|
582
|
+
clearSecrets,
|
|
583
|
+
});
|
|
584
|
+
if (!plan.ok)
|
|
585
|
+
throw new PersonFieldsRefused(plan.message);
|
|
586
|
+
return plan.ask.length === 0 ? null : { target: target.target, fields: plan.ask };
|
|
587
|
+
}
|
|
389
588
|
/**
|
|
390
589
|
* The class of one write: `confirmFor` when the operation has one (the target decides), else
|
|
391
590
|
* `confirm`. A `confirmFor` that throws counts as `org`: never remembered.
|
|
@@ -77,7 +77,6 @@ declare const CreateBody: z.ZodObject<{
|
|
|
77
77
|
credential: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
78
78
|
git: z.ZodOptional<z.ZodType<import("@capybara-hq/plugin-sdk").GitSource, unknown, z.core.$ZodTypeInternals<import("@capybara-hq/plugin-sdk").GitSource, unknown>>>;
|
|
79
79
|
}, z.core.$strict>;
|
|
80
|
-
/** 预览(Ruling A20):与创建相同的连接器 / 端点 / 认证 / 凭据,认证可缺省(只读端点描述,不列工具)。 */
|
|
81
80
|
declare const PreviewBody: z.ZodObject<{
|
|
82
81
|
name: z.ZodOptional<z.ZodString>;
|
|
83
82
|
slug: z.ZodOptional<z.ZodString>;
|
|
@@ -147,12 +146,6 @@ declare const PreviewBody: z.ZodObject<{
|
|
|
147
146
|
}, z.core.$strict>], "type">>;
|
|
148
147
|
credential: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
149
148
|
}, z.core.$strict>;
|
|
150
|
-
declare const ReviewBody: z.ZodObject<{
|
|
151
|
-
action: z.ZodEnum<{
|
|
152
|
-
approve: "approve";
|
|
153
|
-
reject: "reject";
|
|
154
|
-
}>;
|
|
155
|
-
}, z.core.$strict>;
|
|
156
149
|
declare const UpdateBody: z.ZodObject<{
|
|
157
150
|
name: z.ZodOptional<z.ZodString>;
|
|
158
151
|
status: z.ZodOptional<z.ZodEnum<{
|
|
@@ -173,6 +166,12 @@ declare const UpdateBody: z.ZodObject<{
|
|
|
173
166
|
allowUnannotated: z.ZodOptional<z.ZodBoolean>;
|
|
174
167
|
useForGit: z.ZodOptional<z.ZodBoolean>;
|
|
175
168
|
}, z.core.$strict>;
|
|
169
|
+
declare const ReviewBody: z.ZodObject<{
|
|
170
|
+
action: z.ZodEnum<{
|
|
171
|
+
approve: "approve";
|
|
172
|
+
reject: "reject";
|
|
173
|
+
}>;
|
|
174
|
+
}, z.core.$strict>;
|
|
176
175
|
/** The member's Permissions sheet: their tool policies and the git push part (null without git). */
|
|
177
176
|
interface MemberPolicySheet {
|
|
178
177
|
tools: MemberToolPolicyView[];
|
|
@@ -7,7 +7,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
|
-
import { ConnectorAuthSchema, GitSourceSchema } from "@capybara-hq/plugin-sdk";
|
|
11
10
|
import { Controller, Delete, Get, HttpCode, Inject, Param, Patch, Post, Put } from "@nestjs/common";
|
|
12
11
|
import { z } from "zod";
|
|
13
12
|
import { orgIconScope, PluginIcons } from "../extensions/plugin-icons.js";
|
|
@@ -18,7 +17,7 @@ import { ZBody } from "../infra/validation/zod-params.js";
|
|
|
18
17
|
import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
|
|
19
18
|
import { can } from "../orgs/roles.js";
|
|
20
19
|
import { ConnectorAccountPolicies, } from "./connector-account-policies.js";
|
|
21
|
-
import { ConnectorGuideAckSchema, CredentialValue, GitPushPolicyBody, MemberToolPoliciesBody, } from "./connectors.schemas.js";
|
|
20
|
+
import { ConnectorCreateSchema, ConnectorGuideAckSchema, ConnectorPreviewSchema, ConnectorUpdateSchema, CredentialValue, GitPushPolicyBody, MemberToolPoliciesBody, } from "./connectors.schemas.js";
|
|
22
21
|
import { ConnectorsService, } from "./connectors.service.js";
|
|
23
22
|
import { publicEndpoint } from "./endpoint.js";
|
|
24
23
|
import { callbackUrl } from "./oauth/flow-paths.js";
|
|
@@ -39,49 +38,10 @@ function forViewer(org, c) {
|
|
|
39
38
|
}
|
|
40
39
|
return view;
|
|
41
40
|
}
|
|
42
|
-
const CreateBody =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
slug: z.string().max(24).optional(),
|
|
46
|
-
connector: z.string().min(1).max(100),
|
|
47
|
-
endpoint: z.record(z.string(), z.unknown()),
|
|
48
|
-
auth: ConnectorAuthSchema,
|
|
49
|
-
credential: CredentialValue.optional(),
|
|
50
|
-
/** The git hosts the credential serves in sandboxes (sandbox git credentials spec §6.1). */
|
|
51
|
-
git: GitSourceSchema.optional(),
|
|
52
|
-
})
|
|
53
|
-
.strict();
|
|
54
|
-
/** 预览(Ruling A20):与创建相同的连接器 / 端点 / 认证 / 凭据,认证可缺省(只读端点描述,不列工具)。 */
|
|
55
|
-
const PreviewBody = z
|
|
56
|
-
.object({
|
|
57
|
-
name: z.string().trim().min(1).max(80).optional(),
|
|
58
|
-
slug: z.string().max(24).optional(),
|
|
59
|
-
connector: z.string().min(1).max(100),
|
|
60
|
-
endpoint: z.record(z.string(), z.unknown()),
|
|
61
|
-
auth: ConnectorAuthSchema.optional(),
|
|
62
|
-
credential: CredentialValue.optional(),
|
|
63
|
-
})
|
|
64
|
-
.strict();
|
|
65
|
-
const ToolPatch = z
|
|
66
|
-
.object({
|
|
67
|
-
status: z.enum(["enabled", "disabled"]).optional(),
|
|
68
|
-
defaultPolicy: z.enum(["allow", "ask", "deny"]).optional(),
|
|
69
|
-
})
|
|
70
|
-
.strict();
|
|
41
|
+
const CreateBody = ConnectorCreateSchema;
|
|
42
|
+
const PreviewBody = ConnectorPreviewSchema;
|
|
43
|
+
const UpdateBody = ConnectorUpdateSchema;
|
|
71
44
|
const ReviewBody = z.object({ action: z.enum(["approve", "reject"]) }).strict();
|
|
72
|
-
const UpdateBody = z
|
|
73
|
-
.object({
|
|
74
|
-
name: z.string().trim().min(1).max(80).optional(),
|
|
75
|
-
status: z.enum(["active", "disabled"]).optional(),
|
|
76
|
-
tools: z
|
|
77
|
-
.record(z.string().max(200), ToolPatch)
|
|
78
|
-
.refine((v) => Object.keys(v).length <= 1000, { message: "Too many tools" })
|
|
79
|
-
.optional(),
|
|
80
|
-
allowUnannotated: z.boolean().optional(),
|
|
81
|
-
/** Use an org-credential connector for git in sandboxes (spec 2026-11-12 §6.2). */
|
|
82
|
-
useForGit: z.boolean().optional(),
|
|
83
|
-
})
|
|
84
|
-
.strict();
|
|
85
45
|
class ConnectorCreateBody extends createZodDto(CreateBody, "ConnectorCreateBody") {
|
|
86
46
|
}
|
|
87
47
|
class ConnectorPreviewBody extends createZodDto(PreviewBody, "ConnectorPreviewBody") {
|
|
@@ -2,7 +2,8 @@ import { z } from "zod";
|
|
|
2
2
|
import type { RouteSchemas } from "../platform/route-schemas.js";
|
|
3
3
|
/**
|
|
4
4
|
* A credential value: `Credentials.validate` checks its shape by auth method (values are never
|
|
5
|
-
* echoed); this only bounds its size.
|
|
5
|
+
* echoed); this only bounds its size. A secret (`secret()` meta, ruling R2): a Platform operation
|
|
6
|
+
* never takes it as a param; the person enters it on the confirmation card.
|
|
6
7
|
*/
|
|
7
8
|
export declare const CredentialValue: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
8
9
|
/** 「我已更新应用」: the admin drift hash of the connector template guide the person was shown. */
|
|
@@ -25,6 +26,174 @@ export declare const GitPushPolicyBody: z.ZodObject<{
|
|
|
25
26
|
deny: "deny";
|
|
26
27
|
}>;
|
|
27
28
|
}, z.core.$strict>;
|
|
29
|
+
/** `POST …/connectors`: a custom connector with its endpoint, auth method and credential. */
|
|
30
|
+
export declare const ConnectorCreateSchema: z.ZodObject<{
|
|
31
|
+
name: z.ZodString;
|
|
32
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
33
|
+
connector: z.ZodString;
|
|
34
|
+
endpoint: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
35
|
+
auth: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
36
|
+
type: z.ZodLiteral<"none">;
|
|
37
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
38
|
+
type: z.ZodLiteral<"bearer">;
|
|
39
|
+
ownership: z.ZodEnum<{
|
|
40
|
+
org: "org";
|
|
41
|
+
personal: "personal";
|
|
42
|
+
}>;
|
|
43
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
44
|
+
type: z.ZodLiteral<"api_key">;
|
|
45
|
+
ownership: z.ZodEnum<{
|
|
46
|
+
org: "org";
|
|
47
|
+
personal: "personal";
|
|
48
|
+
}>;
|
|
49
|
+
in: z.ZodEnum<{
|
|
50
|
+
header: "header";
|
|
51
|
+
query: "query";
|
|
52
|
+
}>;
|
|
53
|
+
name: z.ZodString;
|
|
54
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
55
|
+
type: z.ZodLiteral<"basic">;
|
|
56
|
+
ownership: z.ZodEnum<{
|
|
57
|
+
org: "org";
|
|
58
|
+
personal: "personal";
|
|
59
|
+
}>;
|
|
60
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
61
|
+
type: z.ZodLiteral<"headers">;
|
|
62
|
+
ownership: z.ZodEnum<{
|
|
63
|
+
org: "org";
|
|
64
|
+
personal: "personal";
|
|
65
|
+
}>;
|
|
66
|
+
names: z.ZodArray<z.ZodString>;
|
|
67
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
68
|
+
type: z.ZodLiteral<"oauth_code">;
|
|
69
|
+
ownership: z.ZodLiteral<"personal">;
|
|
70
|
+
discovery: z.ZodEnum<{
|
|
71
|
+
manual: "manual";
|
|
72
|
+
mcp: "mcp";
|
|
73
|
+
}>;
|
|
74
|
+
authorizationUrl: z.ZodOptional<z.ZodURL>;
|
|
75
|
+
tokenUrl: z.ZodOptional<z.ZodURL>;
|
|
76
|
+
scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
77
|
+
client: z.ZodEnum<{
|
|
78
|
+
dcr: "dcr";
|
|
79
|
+
manual: "manual";
|
|
80
|
+
}>;
|
|
81
|
+
tokenAuthMethod: z.ZodOptional<z.ZodEnum<{
|
|
82
|
+
client_secret_basic: "client_secret_basic";
|
|
83
|
+
client_secret_post: "client_secret_post";
|
|
84
|
+
}>>;
|
|
85
|
+
tokenTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
86
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
87
|
+
type: z.ZodLiteral<"oauth_client">;
|
|
88
|
+
ownership: z.ZodLiteral<"org">;
|
|
89
|
+
tokenUrl: z.ZodURL;
|
|
90
|
+
scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
91
|
+
tokenAuthMethod: z.ZodOptional<z.ZodEnum<{
|
|
92
|
+
client_secret_basic: "client_secret_basic";
|
|
93
|
+
client_secret_post: "client_secret_post";
|
|
94
|
+
}>>;
|
|
95
|
+
tokenTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
96
|
+
}, z.core.$strict>], "type">;
|
|
97
|
+
credential: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
98
|
+
git: z.ZodOptional<z.ZodType<import("@capybara-hq/plugin-sdk").GitSource, unknown, z.core.$ZodTypeInternals<import("@capybara-hq/plugin-sdk").GitSource, unknown>>>;
|
|
99
|
+
}, z.core.$strict>;
|
|
100
|
+
/**
|
|
101
|
+
* `POST …/connectors/preview` (ruling A20): the create's connector, endpoint, auth and credential;
|
|
102
|
+
* the auth may be left out (reads the endpoint description only, lists no tools).
|
|
103
|
+
*/
|
|
104
|
+
export declare const ConnectorPreviewSchema: z.ZodObject<{
|
|
105
|
+
name: z.ZodOptional<z.ZodString>;
|
|
106
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
107
|
+
connector: z.ZodString;
|
|
108
|
+
endpoint: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
109
|
+
auth: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
110
|
+
type: z.ZodLiteral<"none">;
|
|
111
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
112
|
+
type: z.ZodLiteral<"bearer">;
|
|
113
|
+
ownership: z.ZodEnum<{
|
|
114
|
+
org: "org";
|
|
115
|
+
personal: "personal";
|
|
116
|
+
}>;
|
|
117
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
118
|
+
type: z.ZodLiteral<"api_key">;
|
|
119
|
+
ownership: z.ZodEnum<{
|
|
120
|
+
org: "org";
|
|
121
|
+
personal: "personal";
|
|
122
|
+
}>;
|
|
123
|
+
in: z.ZodEnum<{
|
|
124
|
+
header: "header";
|
|
125
|
+
query: "query";
|
|
126
|
+
}>;
|
|
127
|
+
name: z.ZodString;
|
|
128
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
129
|
+
type: z.ZodLiteral<"basic">;
|
|
130
|
+
ownership: z.ZodEnum<{
|
|
131
|
+
org: "org";
|
|
132
|
+
personal: "personal";
|
|
133
|
+
}>;
|
|
134
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
135
|
+
type: z.ZodLiteral<"headers">;
|
|
136
|
+
ownership: z.ZodEnum<{
|
|
137
|
+
org: "org";
|
|
138
|
+
personal: "personal";
|
|
139
|
+
}>;
|
|
140
|
+
names: z.ZodArray<z.ZodString>;
|
|
141
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
142
|
+
type: z.ZodLiteral<"oauth_code">;
|
|
143
|
+
ownership: z.ZodLiteral<"personal">;
|
|
144
|
+
discovery: z.ZodEnum<{
|
|
145
|
+
manual: "manual";
|
|
146
|
+
mcp: "mcp";
|
|
147
|
+
}>;
|
|
148
|
+
authorizationUrl: z.ZodOptional<z.ZodURL>;
|
|
149
|
+
tokenUrl: z.ZodOptional<z.ZodURL>;
|
|
150
|
+
scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
151
|
+
client: z.ZodEnum<{
|
|
152
|
+
dcr: "dcr";
|
|
153
|
+
manual: "manual";
|
|
154
|
+
}>;
|
|
155
|
+
tokenAuthMethod: z.ZodOptional<z.ZodEnum<{
|
|
156
|
+
client_secret_basic: "client_secret_basic";
|
|
157
|
+
client_secret_post: "client_secret_post";
|
|
158
|
+
}>>;
|
|
159
|
+
tokenTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
160
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
161
|
+
type: z.ZodLiteral<"oauth_client">;
|
|
162
|
+
ownership: z.ZodLiteral<"org">;
|
|
163
|
+
tokenUrl: z.ZodURL;
|
|
164
|
+
scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
165
|
+
tokenAuthMethod: z.ZodOptional<z.ZodEnum<{
|
|
166
|
+
client_secret_basic: "client_secret_basic";
|
|
167
|
+
client_secret_post: "client_secret_post";
|
|
168
|
+
}>>;
|
|
169
|
+
tokenTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
170
|
+
}, z.core.$strict>], "type">>;
|
|
171
|
+
credential: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
172
|
+
}, z.core.$strict>;
|
|
173
|
+
/**
|
|
174
|
+
* `PATCH …/connectors/:connectorId`: rename, switch on or off, per-tool state and default policy,
|
|
175
|
+
* every unannotated tool to allow, and git use. No endpoint and no credential.
|
|
176
|
+
*/
|
|
177
|
+
export declare const ConnectorUpdateSchema: z.ZodObject<{
|
|
178
|
+
name: z.ZodOptional<z.ZodString>;
|
|
179
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
180
|
+
active: "active";
|
|
181
|
+
disabled: "disabled";
|
|
182
|
+
}>>;
|
|
183
|
+
tools: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
184
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
185
|
+
disabled: "disabled";
|
|
186
|
+
enabled: "enabled";
|
|
187
|
+
}>>;
|
|
188
|
+
defaultPolicy: z.ZodOptional<z.ZodEnum<{
|
|
189
|
+
allow: "allow";
|
|
190
|
+
ask: "ask";
|
|
191
|
+
deny: "deny";
|
|
192
|
+
}>>;
|
|
193
|
+
}, z.core.$strict>>>;
|
|
194
|
+
allowUnannotated: z.ZodOptional<z.ZodBoolean>;
|
|
195
|
+
useForGit: z.ZodOptional<z.ZodBoolean>;
|
|
196
|
+
}, z.core.$strict>;
|
|
28
197
|
export declare const CONNECTOR_ROUTES: readonly RouteSchemas[];
|
|
29
198
|
/**
|
|
30
199
|
* `PUT …/connectors/:connectorId/tool-policies/me`: the caller's own policy per tool name (null
|