@jini-ai/integrations 0.7.2 → 0.7.3-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -8
- package/README.md +1 -0
- package/dist/api-connections/access-token.js +4 -4
- package/dist/api-connections/account-actions.d.ts +10 -4
- package/dist/api-connections/account-actions.js +13 -13
- package/dist/api-connections/attempt-state.d.ts +11 -5
- package/dist/api-connections/attempt-state.js +4 -4
- package/dist/api-connections/authorization.d.ts +7 -3
- package/dist/api-connections/authorization.js +18 -18
- package/dist/api-connections/finish-authorization.d.ts +8 -4
- package/dist/api-connections/finish-authorization.js +9 -9
- package/dist/api-connections/host.d.ts +30 -32
- package/dist/api-connections/host.js +232 -205
- package/dist/api-connections/hosted-mcp/contracts.d.ts +1 -1
- package/dist/api-connections/hosted-mcp/oauth-row-writes.d.ts +50 -0
- package/dist/api-connections/hosted-mcp/oauth-row-writes.js +38 -0
- package/dist/api-connections/hosted-mcp/shared-sign-in.d.ts +40 -40
- package/dist/api-connections/hosted-mcp/shared-sign-in.js +98 -22
- package/dist/api-connections/hosted-mcp/sign-in-configuration.d.ts +29 -0
- package/dist/api-connections/hosted-mcp/sign-in-configuration.js +127 -0
- package/dist/api-connections/hosted-mcp/sign-in-discovery.d.ts +72 -0
- package/dist/api-connections/hosted-mcp/sign-in-discovery.js +131 -0
- package/dist/api-connections/hosted-mcp/sign-in-flow.d.ts +42 -0
- package/dist/api-connections/hosted-mcp/sign-in-flow.js +50 -0
- package/dist/api-connections/hosted-mcp/sign-in-provider.d.ts +103 -0
- package/dist/api-connections/hosted-mcp/sign-in-provider.js +142 -0
- package/dist/api-connections/hosted-mcp/sign-in-status.d.ts +19 -0
- package/dist/api-connections/hosted-mcp/sign-in-status.js +143 -0
- package/dist/api-connections/hosted-mcp/sign-in.d.ts +2 -9
- package/dist/api-connections/hosted-mcp/sign-in.js +219 -770
- package/dist/api-connections/index.js +1 -1
- package/dist/api-connections/install-credential.d.ts +4 -2
- package/dist/api-connections/install-credential.js +7 -7
- package/dist/api-connections/records.d.ts +17 -5
- package/dist/api-connections/records.js +5 -5
- package/dist/api-connections/request-checks.d.ts +29 -9
- package/dist/api-connections/request-checks.js +13 -13
- package/dist/api-connections/service.d.ts +1 -1
- package/dist/api-connections/service.js +6 -6
- package/dist/api-connections/status.d.ts +3 -1
- package/dist/api-connections/status.js +3 -3
- package/dist/api-connections/token-store/errors.d.ts +3 -1
- package/dist/api-connections/token-store/errors.js +1 -1
- package/dist/api-connections/token-store/vault-token-store.js +186 -173
- package/dist/args.d.ts +4 -1
- package/dist/args.js +1 -1
- package/dist/credentialed-http/credentialed-request.d.ts +5 -5
- package/dist/credentialed-http/credentialed-request.js +8 -8
- package/dist/credentialed-http/response-redaction.d.ts +18 -4
- package/dist/credentialed-http/response-redaction.js +7 -7
- package/dist/credentialed-http/sets/vault-repo.js +5 -1
- package/dist/credentialed-http/tools/credential-copy-tool.js +20 -15
- package/dist/credentialed-http/tools/tool-registrations.js +272 -249
- package/dist/media-providers/catalog.d.ts +1 -0
- package/dist/media-providers/catalog.js +1 -0
- package/dist/media-providers/dispatch/async-operation-store.d.ts +6 -4
- package/dist/media-providers/dispatch/async-operation-store.js +100 -88
- package/dist/media-providers/dispatch/context.js +1 -1
- package/dist/media-providers/dispatch/engine.d.ts +5 -1
- package/dist/media-providers/dispatch/engine.js +2 -2
- package/dist/media-providers/dispatch/index.d.ts +1 -1
- package/dist/media-providers/dispatch/index.js +1 -1
- package/dist/media-providers/dispatch/node.d.ts +1 -1
- package/dist/media-providers/dispatch/node.js +1 -1
- package/dist/media-providers/dispatch/openai-compatible.d.ts +50 -11
- package/dist/media-providers/dispatch/openai-compatible.js +21 -17
- package/dist/media-providers/dispatch/operation-runtime.js +18 -18
- package/dist/media-providers/dispatch/outbound.d.ts +2 -2
- package/dist/media-providers/dispatch/outbound.js +1 -1
- package/dist/media-providers/dispatch/polling-adapter.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/aihubmix-shared.d.ts +20 -6
- package/dist/media-providers/dispatch/providers/aihubmix-shared.js +8 -8
- package/dist/media-providers/dispatch/providers/aihubmix.js +12 -12
- package/dist/media-providers/dispatch/providers/custom-image.js +4 -4
- package/dist/media-providers/dispatch/providers/fishaudio.js +2 -9
- package/dist/media-providers/dispatch/providers/grok.js +5 -19
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.js +22 -20
- package/dist/media-providers/dispatch/providers/imagerouter.js +7 -21
- package/dist/media-providers/dispatch/providers/minimax.js +2 -9
- package/dist/media-providers/dispatch/providers/nanobanana.js +2 -2
- package/dist/media-providers/dispatch/providers/openai.js +6 -6
- package/dist/media-providers/dispatch/providers/openrouter.js +4 -4
- package/dist/media-providers/dispatch/providers/senseaudio.js +5 -19
- package/dist/media-providers/dispatch/providers/volcengine.js +5 -12
- package/dist/media-providers/dispatch/response-parsers.js +3 -3
- package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts +1 -1
- package/dist/media-providers/dispatch/sqlite-async-operation-store.js +31 -5
- package/dist/media-providers/dispatch/ssrf-guard.js +5 -12
- package/dist/media-providers/dispatch/stub.js +2 -2
- package/dist/media-providers/dispatch/vendor-adapter.js +2 -2
- package/dist/media-providers/image-model-ids.d.ts +36 -0
- package/dist/media-providers/image-model-ids.js +24 -0
- package/dist/media-providers/sqlite-driver.adapter.d.ts +1 -1
- package/dist/media-providers/sqlite-task-store.d.ts +2 -2
- package/dist/media-providers/sqlite-task-store.js +31 -4
- package/dist/media-providers/task-lifecycle.d.ts +17 -4
- package/dist/media-providers/task-lifecycle.js +4 -4
- package/dist/media-providers/task-store.js +28 -24
- package/dist/media-providers/ui-defaults.d.ts +7 -0
- package/dist/media-providers/ui-defaults.js +11 -17
- package/dist/saved-requests/types.d.ts +1 -1
- package/dist/webhooks/delivery.js +31 -27
- package/dist/webhooks/ports.d.ts +4 -1
- package/dist/webhooks/subscriptions.d.ts +7 -2
- package/dist/webhooks/subscriptions.js +30 -37
- package/dist/webhooks/tools/agent-tools.d.ts +82 -0
- package/dist/webhooks/tools/agent-tools.js +120 -0
- package/dist/webhooks/tools/index.d.ts +7 -0
- package/dist/webhooks/tools/index.js +5 -0
- package/dist/webhooks/tools/tool-handlers.d.ts +22 -0
- package/dist/webhooks/tools/tool-handlers.js +154 -0
- package/dist/webhooks/tools/tool-handlers.types.d.ts +64 -0
- package/dist/webhooks/tools/tool-handlers.types.js +2 -0
- package/dist/webhooks/tools/tool-registrations.d.ts +35 -0
- package/dist/webhooks/tools/tool-registrations.js +95 -0
- package/dist/webhooks/tools/tool-views.d.ts +62 -0
- package/dist/webhooks/tools/tool-views.js +50 -0
- package/dist/webhooks/types.d.ts +2 -0
- package/dist/webhooks/worker.d.ts +7 -4
- package/dist/webhooks/worker.js +22 -20
- package/package.json +16 -18
- package/dist/composio/bounded-data.d.ts +0 -36
- package/dist/composio/bounded-data.js +0 -181
- package/dist/composio/catalog.d.ts +0 -147
- package/dist/composio/catalog.js +0 -126
- package/dist/composio/composio-config.d.ts +0 -42
- package/dist/composio/composio-config.js +0 -145
- package/dist/composio/composio-descriptions.d.ts +0 -16
- package/dist/composio/composio-descriptions.js +0 -766
- package/dist/composio/composio.d.ts +0 -364
- package/dist/composio/composio.js +0 -1902
- package/dist/composio/errors.d.ts +0 -15
- package/dist/composio/errors.js +0 -16
- package/dist/composio/file-lock.d.ts +0 -13
- package/dist/composio/file-lock.js +0 -92
- package/dist/composio/index.d.ts +0 -18
- package/dist/composio/index.js +0 -7
- package/dist/composio/json-schema.d.ts +0 -93
- package/dist/composio/json-schema.js +0 -498
- package/dist/composio/output-protection.d.ts +0 -32
- package/dist/composio/output-protection.js +0 -105
- package/dist/composio/service.d.ts +0 -181
- package/dist/composio/service.js +0 -758
|
@@ -19,7 +19,7 @@ function withCardApp({ spec, app }) {
|
|
|
19
19
|
* - `CredentialedRequestValidationError` — a bad `method`/`url`/`headers`/`body` shape, OR a `url`
|
|
20
20
|
* whose origin is not one of the credential's own saved hosts (`resolveAllowedRequestUrl`'s
|
|
21
21
|
* allowlist refusal — the "off-allowlist host" case).
|
|
22
|
-
* - `EgressRefusedError` — the shared `HttpClientPort`
|
|
22
|
+
* - `EgressRefusedError` — the shared `HttpClientPort` refused the target before ever
|
|
23
23
|
* connecting: a non-public resolved address on the first hop or any re-verified redirect hop, a
|
|
24
24
|
* disallowed scheme, or credentials embedded in the URL.
|
|
25
25
|
*
|
|
@@ -450,6 +450,123 @@ async function openCreateCard(required, _optional = {}) {
|
|
|
450
450
|
});
|
|
451
451
|
return card.handler({ surfaceExchanges: surfaces.surfaceExchanges, askThenReport: cards.askThenReport })(ctx, emitSurface ? { emitSurface } : {});
|
|
452
452
|
}
|
|
453
|
+
// An MCP-UI surface for the SECRET itself — see this file's secret-handling header
|
|
454
|
+
// for the full mechanism and why it holds up "a token must never pass through the model's
|
|
455
|
+
// context" rather than merely "an agent must never write one". Shape validation
|
|
456
|
+
// (`rejectUnexpectedSetTokenFields`) and the label->id resolution both run BEFORE any exchange is
|
|
457
|
+
// opened, same ordering `custom_credential_make_request`'s DELETE gate below uses: a malformed or
|
|
458
|
+
// unresolvable call must never raise a dialog for a human to see. WRITE-gated, same permission
|
|
459
|
+
// `custom_credential_set_username`/`custom_credential_make_request` use.
|
|
460
|
+
function rotateCredentialHandler(c) {
|
|
461
|
+
const { routeDeps, surfaces, host, cards, operations, probe } = c;
|
|
462
|
+
return async (ctx, options = {}) => {
|
|
463
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
464
|
+
rejectUnexpectedSetTokenFields({ input, messages: operations.messages });
|
|
465
|
+
const label = requireString({ input, key: "label" });
|
|
466
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: host.vocabulary.permissions.write }, { entityType: host.vocabulary.entityType });
|
|
467
|
+
// Non-decrypting label->id resolution — same lookup `custom_credential_set_username` above uses,
|
|
468
|
+
// and for the identical reason: a bad label should never cost a decrypt. Only `existing.id` is
|
|
469
|
+
// load-bearing past this point: `saveSetToken` deliberately re-reads the username itself,
|
|
470
|
+
// fresh, right before writing — see its own header for why trusting THIS snapshot's username
|
|
471
|
+
// would be wrong once the human's answer can arrive an arbitrarily long time later.
|
|
472
|
+
const existing = await operations.sets.byLabel({ label });
|
|
473
|
+
if (!existing) {
|
|
474
|
+
throw new CustomCredentialNotFoundError(operations.messages.notFoundLabel({ label }));
|
|
475
|
+
}
|
|
476
|
+
// Fail closed rather than degrade — and, unlike every OTHER gated tool in this codebase, there is
|
|
477
|
+
// deliberately no fallback second-call shape for this one even in principle: that shape is a
|
|
478
|
+
// fresh MODEL-ISSUED tool call carrying the human's answer as its own input, which is exactly the
|
|
479
|
+
// path this tool exists to make impossible for a secret. See this file's header.
|
|
480
|
+
// A `ToolInputError` with the wording unchanged: a bare `Error` is redacted to a 500 that
|
|
481
|
+
// no allowlist rule can rescue. No code prefix — the per-tool suites pin this exact string.
|
|
482
|
+
// The run ended during the pre-dialog reads: the engine opens no dialog for an aborted run.
|
|
483
|
+
// `askThenReport`, not `askOnce` — the engine waits for save and replaces the same card URI.
|
|
484
|
+
const locale = await operations.locale.resolve({ principalId: ctx.principal.id });
|
|
485
|
+
const pluginCard = await operations.pluginCards.find({ workspaceId: routeDeps.workspaceId, saveKind: 'api', target: label });
|
|
486
|
+
let errorSummary = "";
|
|
487
|
+
const card = cards.defineSecretCardTool({
|
|
488
|
+
toolId: operations.ids.save,
|
|
489
|
+
prepare: async () => ({ label }),
|
|
490
|
+
form: ({ prep }) => operations.credentialCardForms.applyPlugin({ card: pluginCard, form: withCardApp({ spec: operations.credentialCardForms.rotate(prep), app: host.cardIdentity.appNames.setToken }) }),
|
|
491
|
+
save: ({ values, signal }) => saveSetToken({ token: values.token, signal, routeDeps, operations, probe, existing, pluginCard, principalId: ctx.principal.id }),
|
|
492
|
+
result: ({ run }) => {
|
|
493
|
+
// Token hints belong on the human's card, never in the model-facing result or audit output.
|
|
494
|
+
if (run.status === "saved")
|
|
495
|
+
return { saved: true };
|
|
496
|
+
if (run.status === "blank")
|
|
497
|
+
return { saved: false, reason: "invalid", message: operations.locale.text({ id: "blank", locale }) };
|
|
498
|
+
if (run.status === "failed")
|
|
499
|
+
return { saved: false, reason: "error", message: run.safeMessage };
|
|
500
|
+
return { saved: false, reason: run.status };
|
|
501
|
+
},
|
|
502
|
+
outcome: ({ run }) => {
|
|
503
|
+
if (run.status === "saved") {
|
|
504
|
+
const hint = operations.locale.hint({ hint: run.saved.tokenHint, locale });
|
|
505
|
+
return withCardApp({ spec: operations.credentialCardForms.rotateOutcome({ label, state: "success", message: `${hint ? hint + ". " : ""}${operations.locale.text({ id: "saved", locale })}` }), app: host.cardIdentity.appNames.setTokenOutcome });
|
|
506
|
+
}
|
|
507
|
+
if (run.status === "blank" || run.status === "failed")
|
|
508
|
+
return withCardApp({ spec: operations.credentialCardForms.rotateOutcome({ label, state: "failure",
|
|
509
|
+
message: run.status === "blank" ? operations.locale.text({ id: "blank", locale }) : run.safeMessage }), app: host.cardIdentity.appNames.setTokenOutcome });
|
|
510
|
+
return undefined;
|
|
511
|
+
},
|
|
512
|
+
}, {
|
|
513
|
+
uriHost: host.cardIdentity.uriNamespace,
|
|
514
|
+
text: { noEmitter: operations.messages.noRotateChannel },
|
|
515
|
+
safeError: err => {
|
|
516
|
+
// Never `err.message`: it can quote the token just submitted. See operations.formErrors.
|
|
517
|
+
errorSummary = operations.diagnostics.describeError({ error: err });
|
|
518
|
+
return operations.locale.translate({ message: callerSafeErrorMessage({ err, rules: operations.formErrors, fallback: operations.messages.formSaveFailure }), locale });
|
|
519
|
+
},
|
|
520
|
+
logFailure: ({ toolId, exchangeId }) => operations.diagnostics.rotateFailure({ toolId, exchangeId, credentialId: existing.id, errorSummary }),
|
|
521
|
+
});
|
|
522
|
+
return card.handler({ surfaceExchanges: surfaces.surfaceExchanges, askThenReport: cards.askThenReport })(ctx, options);
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
// Creates a brand-new credential row — see this file's creation-ordering header for the
|
|
526
|
+
// full mechanism and the incident it closes. Unlike every other write handler in this domain, there
|
|
527
|
+
// is no existing row to resolve or fail closed on before opening the form: a CREATE's row does not
|
|
528
|
+
// exist yet, so the only pre-form checks are the permission gate and the `emitSurface` fail-closed
|
|
529
|
+
// guard below. All three prefill fields are optional and non-secret by schema
|
|
530
|
+
// in the host's API creation schema — a call with none of them is a normal, valid call.
|
|
531
|
+
function createCredentialHandler(c) {
|
|
532
|
+
const { routeDeps, surfaces, host, cards, operations, probe } = c;
|
|
533
|
+
return async (ctx, { emitSurface } = {}) => {
|
|
534
|
+
// `requireInputRecord` refuses `undefined` outright, but this tool's schema has no required
|
|
535
|
+
// field at all (same `required: []` shape `custom_credential_list`'s own `NO_INPUT_SCHEMA`
|
|
536
|
+
// documents) — a model-issued call with no arguments at all is a normal, valid call here, not a
|
|
537
|
+
// malformed one, so it is treated the same as an explicit `{}` rather than rejected.
|
|
538
|
+
const input = ctx.input === undefined ? {} : requireInputRecord({ input: ctx.input });
|
|
539
|
+
const prefill = readCreateCredentialPrefill({ input, operations });
|
|
540
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: host.vocabulary.permissions.write }, { entityType: host.vocabulary.entityType });
|
|
541
|
+
const providers = await operations.publish.loadProviders({});
|
|
542
|
+
const locale = await operations.locale.resolve({ principalId: ctx.principal.id });
|
|
543
|
+
return openCreateCard({ ctx, emitSurface, routeDeps, operations, probe, cards, surfaces, locale, initialLabel: prefill.label ?? '', cardIdentity: host.cardIdentity,
|
|
544
|
+
form: () => withCardApp({ spec: operations.credentialCardForms.create({ prefill, providers }), app: host.cardIdentity.appNames.create }),
|
|
545
|
+
submissionOf: values => deriveCreateCredentialSubmission({ raw: readRawCreateCredentialFields(values), operations }) });
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
// A plugin's own key card (credential_save kind plugin-provider): plugin copy, a masked token
|
|
549
|
+
// and declared public fields, with fixed row metadata resolved on the server. Same
|
|
550
|
+
// permission, save port and outcome as the generic create card. The host supplies these through operations.pluginCards.
|
|
551
|
+
function pluginProviderHandler(c) {
|
|
552
|
+
const { routeDeps, surfaces, host, cards, operations, probe } = c;
|
|
553
|
+
return async (ctx, { emitSurface } = {}) => {
|
|
554
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
555
|
+
const providerId = requireString({ input, key: "provider" });
|
|
556
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: host.vocabulary.permissions.write }, { entityType: host.vocabulary.entityType });
|
|
557
|
+
const card = (await operations.pluginCards.load({ workspaceId: routeDeps.workspaceId })).find(entry => entry.providerId === providerId);
|
|
558
|
+
if (!card)
|
|
559
|
+
throw new ToolInputError({ message: operations.messages.missingPluginCard({ providerId }) });
|
|
560
|
+
const locale = await operations.locale.resolve({ principalId: ctx.principal.id });
|
|
561
|
+
return openCreateCard({ ctx, emitSurface, routeDeps, operations, probe, cards, surfaces, locale, initialLabel: card.label, cardIdentity: host.cardIdentity,
|
|
562
|
+
form: () => operations.credentialCardForms.buildPlugin({ card }),
|
|
563
|
+
submissionOf: values => {
|
|
564
|
+
const fields = operations.pluginCards.readValues({ card, values });
|
|
565
|
+
return { ...deriveCreateCredentialSubmission({ raw: readRawCreateCredentialFields({ ...fields, worksFor: [] }), operations }), pluginCard: card,
|
|
566
|
+
...(fields.additionalHosts === undefined ? {} : { additionalHosts: fields.additionalHosts }) };
|
|
567
|
+
} });
|
|
568
|
+
};
|
|
569
|
+
}
|
|
453
570
|
/**
|
|
454
571
|
* API-key cards with every consumed operation supplied by the composing host.
|
|
455
572
|
*
|
|
@@ -458,117 +575,156 @@ async function openCreateCard(required, _optional = {}) {
|
|
|
458
575
|
/** @agent-note create accepts optional label/baseUrl/category/worksFor, rotate requires label and pluginProvider requires provider, while secrets arrive only from human card values. */
|
|
459
576
|
export function createCredentialSaveHandlers({ routeDeps, surfaces, host, ports, cards, operations }, _optional = {}) {
|
|
460
577
|
const probe = (input) => ports.credentialedRequest.probe(input);
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
578
|
+
const context = { routeDeps, surfaces, host, cards, operations, probe };
|
|
579
|
+
const handlers = { rotate: rotateCredentialHandler(context), create: createCredentialHandler(context), pluginProvider: pluginProviderHandler(context) };
|
|
580
|
+
return withModelFacingErrors({ handlers, rules: operations.modelFacingErrors });
|
|
581
|
+
}
|
|
582
|
+
// Non-decrypting read-back through the existing store, scoped by the read permission and
|
|
583
|
+
// empty-input contract. Saved origins and usernames reach the model; token hints remain
|
|
584
|
+
// on human surfaces. One workspace read plus O(n + c) projection for saved rows and active cards.
|
|
585
|
+
async function listCredentials(tc, ctx) {
|
|
586
|
+
const { routeDeps, host, operations } = tc;
|
|
587
|
+
requireNoInput({ input: ctx.input });
|
|
588
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: host.vocabulary.permissions.read }, { entityType: host.vocabulary.entityType });
|
|
589
|
+
const credentials = await operations.sets.list({});
|
|
590
|
+
const cards = await operations.pluginCards.load({ workspaceId: routeDeps.workspaceId });
|
|
591
|
+
const apiCards = new Map(cards.filter(card => card.saveKind === undefined || card.saveKind === 'api').map(card => [card.ownedApiLabel ?? card.label, card]));
|
|
592
|
+
// Exact owned labels attach display copy only; usedFor never participates in key selection.
|
|
593
|
+
return { credentials: credentials.map(({ tokenHint: _humanHint, ...credential }) => {
|
|
594
|
+
const card = apiCards.get(credential.label);
|
|
595
|
+
return card ? { ...credential, pluginId: card.pluginId, usedFor: card.usedFor ?? [] } : credential;
|
|
596
|
+
}) };
|
|
597
|
+
}
|
|
598
|
+
async function verifyCredential(tc, ctx) {
|
|
599
|
+
const { routeDeps, host, operations } = tc;
|
|
600
|
+
const { credentialedRequest } = tc.ports;
|
|
601
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
602
|
+
const label = requireString({ input, key: "label" });
|
|
603
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: host.vocabulary.permissions.read }, { entityType: host.vocabulary.entityType });
|
|
604
|
+
return operations.recovery.withSetup({ label, verification: true, invoke: () => credentialedRequest.verify({ workspaceId: routeDeps.workspaceId, label }) }, {});
|
|
605
|
+
}
|
|
606
|
+
// The self-healing FIX half of the 401/403 diagnostic `custom_credential_verify`/
|
|
607
|
+
// `custom_credential_make_request` now carry (`../credentialed-request.ts`'s `AuthFailureDiagnostic`)
|
|
608
|
+
// — see this file's username-update header for the full incident and design.
|
|
609
|
+
// Shape/security validation (`rejectUnexpectedSetUsernameFields`, `requireUsernameOrClearSentinel`)
|
|
610
|
+
// runs BEFORE the permission check, same ordering `custom_credential_make_request` below uses — a
|
|
611
|
+
// malformed call is refused on its own terms regardless of who is asking. WRITE-gated (this durably
|
|
612
|
+
// changes a host-side column), and — by the owner's own standing "no confirm ceremonies" instruction
|
|
613
|
+
// — deliberately NOT wrapped in the DELETE-style confirmation dialog: this field is not a secret,
|
|
614
|
+
// and there is structurally no way for this call to carry one.
|
|
615
|
+
async function setCredentialUsername(tc, ctx) {
|
|
616
|
+
const { routeDeps, host, operations } = tc;
|
|
617
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
618
|
+
rejectUnexpectedSetUsernameFields({ input, messages: operations.messages });
|
|
619
|
+
const label = requireString({ input, key: "label" });
|
|
620
|
+
const username = requireUsernameOrClearSentinel({ input, messages: operations.messages });
|
|
621
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: host.vocabulary.permissions.write }, { entityType: host.vocabulary.entityType });
|
|
622
|
+
// Non-decrypting label->id resolution — same lookup `resolveRequestTarget` above uses for the
|
|
623
|
+
// identical reason: a bad label should never cost a decrypt, and this update never needs one
|
|
624
|
+
// either (see `CustomCredentialsToolDeps.siteAssistantSecretKeyring`'s own doc).
|
|
625
|
+
const existing = await operations.sets.byLabel({ label });
|
|
626
|
+
if (!existing) {
|
|
627
|
+
throw new CustomCredentialNotFoundError(operations.messages.notFoundLabel({ label }));
|
|
628
|
+
}
|
|
629
|
+
ctx.signal.throwIfAborted();
|
|
630
|
+
return operations.sets.setUsername({ id: existing.id, username });
|
|
631
|
+
}
|
|
632
|
+
// GET/POST/PUT/PATCH run immediately (no ceremony — parity with the site). DELETE opens an
|
|
633
|
+
// in-chat confirmation and parks until answered; see this file's own header for the full
|
|
634
|
+
// mechanism and why. All shape/security-boundary validation (`method`/`url`/`headers`/`body`,
|
|
635
|
+
// label existence, host allowlist) happens inside `resolveRequestTarget`/`makeCredentialedRequest`
|
|
636
|
+
// themselves — this handler's only job is deciding WHETHER to gate, never re-validating.
|
|
637
|
+
async function makeCredentialRequest(tc, ctx, { emitSurface } = {}) {
|
|
638
|
+
const { routeDeps, host, operations } = tc;
|
|
639
|
+
const { credentialedRequest } = tc.ports;
|
|
640
|
+
ctx = { ...ctx, input: structuredClone(ctx.input), principal: { ...ctx.principal }, run: { ...ctx.run } };
|
|
641
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
642
|
+
const label = requireString({ input, key: "label" });
|
|
643
|
+
const method = requireString({ input, key: "method" });
|
|
644
|
+
const url = requireString({ input, key: "url" });
|
|
645
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: host.vocabulary.permissions.write }, { entityType: host.vocabulary.entityType });
|
|
646
|
+
if (method !== "DELETE") {
|
|
647
|
+
return operations.recovery.withSetup({ label, url, invoke: () => makeModelFacingCredentialedRequest({ port: credentialedRequest, input: { workspaceId: routeDeps.workspaceId, label, method, url, headers: input.headers, body: input.body }, catalog: host.vocabulary.catalog, toolId: operations.ids.makeRequest }) }, {});
|
|
648
|
+
}
|
|
649
|
+
// Non-decrypting: a declined/expired/off-allowlist DELETE must never have cost a decrypt.
|
|
650
|
+
// Classify the original preflight rejection once before map-level message publication.
|
|
651
|
+
// Preserve the validation class and existing DELETE text; only caller-safe copy may enter it.
|
|
652
|
+
// Other rejection identities stay unchanged. Schema decoration here would change that text.
|
|
653
|
+
const target = await operations.recovery.withSetup({ label, url, invoke: async () => {
|
|
654
|
+
try {
|
|
655
|
+
return await credentialedRequest.resolveTarget({ workspaceId: routeDeps.workspaceId, label, url });
|
|
482
656
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
return withCardApp({ spec: operations.credentialCardForms.rotateOutcome({ label, state: "success", message: `${hint ? hint + ". " : ""}${operations.locale.text({ id: "saved", locale })}` }), app: host.cardIdentity.appNames.setTokenOutcome });
|
|
513
|
-
}
|
|
514
|
-
if (run.status === "blank" || run.status === "failed")
|
|
515
|
-
return withCardApp({ spec: operations.credentialCardForms.rotateOutcome({ label, state: "failure",
|
|
516
|
-
message: run.status === "blank" ? operations.locale.text({ id: "blank", locale }) : run.safeMessage }), app: host.cardIdentity.appNames.setTokenOutcome });
|
|
517
|
-
return undefined;
|
|
518
|
-
},
|
|
519
|
-
}, {
|
|
520
|
-
uriHost: host.cardIdentity.uriNamespace,
|
|
521
|
-
text: { noEmitter: operations.messages.noRotateChannel },
|
|
522
|
-
safeError: err => {
|
|
523
|
-
// Never `err.message`: it can quote the token just submitted. See operations.formErrors.
|
|
524
|
-
errorSummary = operations.diagnostics.describeError({ error: err });
|
|
525
|
-
return operations.locale.translate({ message: callerSafeErrorMessage({ err, rules: operations.formErrors, fallback: operations.messages.formSaveFailure }), locale });
|
|
526
|
-
},
|
|
527
|
-
logFailure: ({ toolId, exchangeId }) => operations.diagnostics.rotateFailure({ toolId, exchangeId, credentialId: existing.id, errorSummary }),
|
|
528
|
-
});
|
|
529
|
-
return card.handler({ surfaceExchanges: surfaces.surfaceExchanges, askThenReport: cards.askThenReport })(ctx, options);
|
|
530
|
-
},
|
|
531
|
-
// Creates a brand-new credential row — see this file's creation-ordering header for the
|
|
532
|
-
// full mechanism and the incident it closes. Unlike every other write handler in this domain, there
|
|
533
|
-
// is no existing row to resolve or fail closed on before opening the form: a CREATE's row does not
|
|
534
|
-
// exist yet, so the only pre-form checks are the permission gate and the `emitSurface` fail-closed
|
|
535
|
-
// guard below. All three prefill fields are optional and non-secret by schema
|
|
536
|
-
// in the host's API creation schema — a call with none of them is a normal, valid call.
|
|
537
|
-
create: async (ctx, { emitSurface } = {}) => {
|
|
538
|
-
// `requireInputRecord` refuses `undefined` outright, but this tool's schema has no required
|
|
539
|
-
// field at all (same `required: []` shape `custom_credential_list`'s own `NO_INPUT_SCHEMA`
|
|
540
|
-
// documents) — a model-issued call with no arguments at all is a normal, valid call here, not a
|
|
541
|
-
// malformed one, so it is treated the same as an explicit `{}` rather than rejected.
|
|
542
|
-
const input = ctx.input === undefined ? {} : requireInputRecord({ input: ctx.input });
|
|
543
|
-
const prefill = readCreateCredentialPrefill({ input, operations });
|
|
544
|
-
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: host.vocabulary.permissions.write }, { entityType: host.vocabulary.entityType });
|
|
545
|
-
const providers = await operations.publish.loadProviders({});
|
|
546
|
-
const locale = await operations.locale.resolve({ principalId: ctx.principal.id });
|
|
547
|
-
return openCreateCard({ ctx, emitSurface, routeDeps, operations, probe, cards, surfaces, locale, initialLabel: prefill.label ?? '', cardIdentity: host.cardIdentity,
|
|
548
|
-
form: () => withCardApp({ spec: operations.credentialCardForms.create({ prefill, providers }), app: host.cardIdentity.appNames.create }),
|
|
549
|
-
submissionOf: values => deriveCreateCredentialSubmission({ raw: readRawCreateCredentialFields(values), operations }) });
|
|
550
|
-
},
|
|
551
|
-
// A plugin's own key card (credential_save kind plugin-provider): plugin copy, a masked token
|
|
552
|
-
// and declared public fields, with fixed row metadata resolved on the server. Same
|
|
553
|
-
// permission, save port and outcome as the generic create card. The host supplies these through operations.pluginCards.
|
|
554
|
-
pluginProvider: async (ctx, { emitSurface } = {}) => {
|
|
555
|
-
const input = requireInputRecord({ input: ctx.input });
|
|
556
|
-
const providerId = requireString({ input, key: "provider" });
|
|
557
|
-
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: host.vocabulary.permissions.write }, { entityType: host.vocabulary.entityType });
|
|
558
|
-
const card = (await operations.pluginCards.load({ workspaceId: routeDeps.workspaceId })).find(entry => entry.providerId === providerId);
|
|
559
|
-
if (!card)
|
|
560
|
-
throw new ToolInputError({ message: operations.messages.missingPluginCard({ providerId }) });
|
|
561
|
-
const locale = await operations.locale.resolve({ principalId: ctx.principal.id });
|
|
562
|
-
return openCreateCard({ ctx, emitSurface, routeDeps, operations, probe, cards, surfaces, locale, initialLabel: card.label, cardIdentity: host.cardIdentity,
|
|
563
|
-
form: () => operations.credentialCardForms.buildPlugin({ card }),
|
|
564
|
-
submissionOf: values => {
|
|
565
|
-
const fields = operations.pluginCards.readValues({ card, values });
|
|
566
|
-
return { ...deriveCreateCredentialSubmission({ raw: readRawCreateCredentialFields({ ...fields, worksFor: [] }), operations }), pluginCard: card,
|
|
567
|
-
...(fields.additionalHosts === undefined ? {} : { additionalHosts: fields.additionalHosts }) };
|
|
568
|
-
} });
|
|
657
|
+
catch (error) {
|
|
658
|
+
const classified = credentialedRequest.classifyError({ error });
|
|
659
|
+
if (classified.category === "validation")
|
|
660
|
+
throw new CredentialedRequestValidationError({ message: classified.callerSafeMessage });
|
|
661
|
+
throw error;
|
|
662
|
+
}
|
|
663
|
+
} }, {});
|
|
664
|
+
if ("credentialSetup" in target)
|
|
665
|
+
return target;
|
|
666
|
+
// Fail closed rather than degrade — same posture `content_post_delete`'s own handler documents:
|
|
667
|
+
// an execution context that cannot hold this call open cannot run a gated DELETE at all.
|
|
668
|
+
if (!emitSurface) {
|
|
669
|
+
// A `ToolInputError` with the wording unchanged: a bare `Error` is redacted to a 500 that
|
|
670
|
+
// no allowlist rule can rescue. No code prefix — the per-tool suites pin this exact string.
|
|
671
|
+
throw new ToolInputError({ message: operations.messages.noDeleteChannel });
|
|
672
|
+
}
|
|
673
|
+
// A run aborted during reconnaissance must not proceed to the external commit.
|
|
674
|
+
if (ctx.signal.aborted)
|
|
675
|
+
return { executed: false, cancelled: false, reason: "abandoned" };
|
|
676
|
+
return operations.approval.handler({
|
|
677
|
+
prepare: async () => ({ label: target.label, host: target.url.host, path: `${target.url.pathname}${target.url.search}` }),
|
|
678
|
+
describe: ({ prepared }) => ({ ask: true, description: operations.approval.describeDelete(prepared) }),
|
|
679
|
+
askHuman: (required, optional) => operations.approval.askHuman(required, optional),
|
|
680
|
+
run: async ({ ctx: approvedCtx }) => {
|
|
681
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: approvedCtx.principal.id, permission: host.vocabulary.permissions.write }, { entityType: host.vocabulary.entityType });
|
|
682
|
+
if (approvedCtx.signal.aborted)
|
|
683
|
+
return { executed: false, cancelled: false, reason: "abandoned" };
|
|
684
|
+
const frozen = requireInputRecord({ input: approvedCtx.input });
|
|
685
|
+
return operations.recovery.withSetup({ label, url, invoke: () => makeModelFacingCredentialedRequest({ port: credentialedRequest, input: { workspaceId: routeDeps.workspaceId, label, method: "DELETE", url, headers: frozen.headers, body: frozen.body }, catalog: host.vocabulary.catalog, toolId: operations.ids.makeRequest }) }, {});
|
|
569
686
|
},
|
|
570
|
-
|
|
571
|
-
|
|
687
|
+
notConfirmed: ({ reason }) => reason === "declined" ? { executed: false, cancelled: true } : { executed: false, cancelled: false, reason },
|
|
688
|
+
})(ctx, { emitSurface });
|
|
689
|
+
}
|
|
690
|
+
// See this file's header for file-write validation, provider-plan and freshness boundaries.
|
|
691
|
+
async function writeCredentialFiles(tc, ctx) {
|
|
692
|
+
const { routeDeps, host, operations } = tc;
|
|
693
|
+
const { sourceControlWrite } = tc.ports;
|
|
694
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
695
|
+
const label = requireString({ input, key: "label" });
|
|
696
|
+
const shapeRejection = { toolId: operations.ids.writeFiles, catalog: host.vocabulary.catalog, isShapeRejection: ({ error }) => isWriteFilesShapeRejection(error) };
|
|
697
|
+
const request = await withSchemaOnRejection({ ...shapeRejection, fn: async () => operations.policy.validateWriteFiles({ branch: input.branch, commitMessage: input.commitMessage, files: input.files })
|
|
698
|
+
});
|
|
699
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: host.vocabulary.permissions.write }, { entityType: host.vocabulary.entityType });
|
|
700
|
+
// The host first, from the credential's plaintext base URL (no decrypt): its owner/repo rules
|
|
701
|
+
// decide whether this call is well formed at all.
|
|
702
|
+
const summary = await operations.sets.byLabel({ label });
|
|
703
|
+
if (!summary) {
|
|
704
|
+
throw new CustomCredentialNotFoundError(operations.messages.notFoundLabel({ label }));
|
|
705
|
+
}
|
|
706
|
+
const built = await sourceControlWrite.build({ workspaceId: routeDeps.workspaceId, baseUrl: summary.baseUrl });
|
|
707
|
+
if (!built.ok)
|
|
708
|
+
throw new Error(operations.messages.writeFailure({ message: built.message }));
|
|
709
|
+
const provider = built.provider;
|
|
710
|
+
const target = await withSchemaOnRejection({ ...shapeRejection, fn: async () => sourceControlWrite.validateTarget({ provider, target: { owner: input.owner, repo: input.repo } }) });
|
|
711
|
+
const validated = { ...request, ...target };
|
|
712
|
+
// A DECRYPTING resolve: the plan phase's read-only host calls need the token regardless of
|
|
713
|
+
// whether the human goes on to confirm. The row was just seen above; one deleted in between
|
|
714
|
+
// is the same not-found refusal.
|
|
715
|
+
const resolved = await operations.sets.resolve({ label });
|
|
716
|
+
if (!resolved) {
|
|
717
|
+
throw new CustomCredentialNotFoundError(operations.messages.notFoundLabel({ label }));
|
|
718
|
+
}
|
|
719
|
+
const planResult = await sourceControlWrite.planFileWrite({ provider, input: { ...writeTarget(resolved, validated), branch: validated.branch, files: validated.files } });
|
|
720
|
+
if (!planResult.ok) {
|
|
721
|
+
operations.diagnostics.writeFailure({ phase: "plan", failure: planResult });
|
|
722
|
+
throw new Error(operations.messages.writeFailure({ message: planResult.message }));
|
|
723
|
+
}
|
|
724
|
+
// A run aborted during reconnaissance must not proceed to the external commit.
|
|
725
|
+
if (ctx.signal.aborted)
|
|
726
|
+
return { executed: false, cancelled: false, reason: "abandoned" };
|
|
727
|
+
return performRepositoryFilesWrite({ operations, port: sourceControlWrite, provider, resolved, validated, plan: planResult.plan });
|
|
572
728
|
}
|
|
573
729
|
/**
|
|
574
730
|
* Credential tool handlers over required host operations and core-only consumer contracts.
|
|
@@ -577,146 +733,13 @@ export function createCredentialSaveHandlers({ routeDeps, surfaces, host, ports,
|
|
|
577
733
|
*/
|
|
578
734
|
/** @agent-note operations.ids must exactly match catalog, metadata and risk names and the host answer routing. */
|
|
579
735
|
export function createCredentialToolRegistrations({ routeDeps, host, ports, operations }, _optional = {}) {
|
|
580
|
-
const {
|
|
736
|
+
const tc = { routeDeps, host, ports, operations };
|
|
581
737
|
const handlers = {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
[operations.ids.
|
|
586
|
-
|
|
587
|
-
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: host.vocabulary.permissions.read }, { entityType: host.vocabulary.entityType });
|
|
588
|
-
const credentials = await operations.sets.list({});
|
|
589
|
-
const cards = await operations.pluginCards.load({ workspaceId: routeDeps.workspaceId });
|
|
590
|
-
const apiCards = new Map(cards.filter(card => card.saveKind === undefined || card.saveKind === 'api').map(card => [card.ownedApiLabel ?? card.label, card]));
|
|
591
|
-
// Exact owned labels attach display copy only; usedFor never participates in key selection.
|
|
592
|
-
return { credentials: credentials.map(({ tokenHint: _humanHint, ...credential }) => {
|
|
593
|
-
const card = apiCards.get(credential.label);
|
|
594
|
-
return card ? { ...credential, pluginId: card.pluginId, usedFor: card.usedFor ?? [] } : credential;
|
|
595
|
-
}) };
|
|
596
|
-
},
|
|
597
|
-
[operations.ids.verify]: async (ctx) => {
|
|
598
|
-
const input = requireInputRecord({ input: ctx.input });
|
|
599
|
-
const label = requireString({ input, key: "label" });
|
|
600
|
-
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: host.vocabulary.permissions.read }, { entityType: host.vocabulary.entityType });
|
|
601
|
-
return operations.recovery.withSetup({ label, verification: true, invoke: () => credentialedRequest.verify({ workspaceId: routeDeps.workspaceId, label }) }, {});
|
|
602
|
-
},
|
|
603
|
-
// The self-healing FIX half of the 401/403 diagnostic `custom_credential_verify`/
|
|
604
|
-
// `custom_credential_make_request` now carry (`../credentialed-request.ts`'s `AuthFailureDiagnostic`)
|
|
605
|
-
// — see this file's username-update header for the full incident and design.
|
|
606
|
-
// Shape/security validation (`rejectUnexpectedSetUsernameFields`, `requireUsernameOrClearSentinel`)
|
|
607
|
-
// runs BEFORE the permission check, same ordering `custom_credential_make_request` below uses — a
|
|
608
|
-
// malformed call is refused on its own terms regardless of who is asking. WRITE-gated (this durably
|
|
609
|
-
// changes a host-side column), and — by the owner's own standing "no confirm ceremonies" instruction
|
|
610
|
-
// — deliberately NOT wrapped in the DELETE-style confirmation dialog: this field is not a secret,
|
|
611
|
-
// and there is structurally no way for this call to carry one.
|
|
612
|
-
[operations.ids.setUsername]: async (ctx) => {
|
|
613
|
-
const input = requireInputRecord({ input: ctx.input });
|
|
614
|
-
rejectUnexpectedSetUsernameFields({ input, messages: operations.messages });
|
|
615
|
-
const label = requireString({ input, key: "label" });
|
|
616
|
-
const username = requireUsernameOrClearSentinel({ input, messages: operations.messages });
|
|
617
|
-
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: host.vocabulary.permissions.write }, { entityType: host.vocabulary.entityType });
|
|
618
|
-
// Non-decrypting label->id resolution — same lookup `resolveRequestTarget` above uses for the
|
|
619
|
-
// identical reason: a bad label should never cost a decrypt, and this update never needs one
|
|
620
|
-
// either (see `CustomCredentialsToolDeps.siteAssistantSecretKeyring`'s own doc).
|
|
621
|
-
const existing = await operations.sets.byLabel({ label });
|
|
622
|
-
if (!existing) {
|
|
623
|
-
throw new CustomCredentialNotFoundError(operations.messages.notFoundLabel({ label }));
|
|
624
|
-
}
|
|
625
|
-
return operations.sets.setUsername({ id: existing.id, username });
|
|
626
|
-
},
|
|
627
|
-
// GET/POST/PUT/PATCH run immediately (no ceremony — parity with the site). DELETE opens an
|
|
628
|
-
// in-chat confirmation and parks until answered; see this file's own header for the full
|
|
629
|
-
// mechanism and why. All shape/security-boundary validation (`method`/`url`/`headers`/`body`,
|
|
630
|
-
// label existence, host allowlist) happens inside `resolveRequestTarget`/`makeCredentialedRequest`
|
|
631
|
-
// themselves — this handler's only job is deciding WHETHER to gate, never re-validating.
|
|
632
|
-
[operations.ids.makeRequest]: async (ctx, { emitSurface } = {}) => {
|
|
633
|
-
ctx = { ...ctx, input: structuredClone(ctx.input), principal: { ...ctx.principal }, run: { ...ctx.run } };
|
|
634
|
-
const input = requireInputRecord({ input: ctx.input });
|
|
635
|
-
const label = requireString({ input, key: "label" });
|
|
636
|
-
const method = requireString({ input, key: "method" });
|
|
637
|
-
const url = requireString({ input, key: "url" });
|
|
638
|
-
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: host.vocabulary.permissions.write }, { entityType: host.vocabulary.entityType });
|
|
639
|
-
if (method !== "DELETE") {
|
|
640
|
-
return operations.recovery.withSetup({ label, url, invoke: () => makeModelFacingCredentialedRequest({ port: credentialedRequest, input: { workspaceId: routeDeps.workspaceId, label, method, url, headers: input.headers, body: input.body }, catalog: host.vocabulary.catalog, toolId: operations.ids.makeRequest }) }, {});
|
|
641
|
-
}
|
|
642
|
-
// Non-decrypting: a declined/expired/off-allowlist DELETE must never have cost a decrypt.
|
|
643
|
-
// Classify the original preflight rejection once before map-level message publication.
|
|
644
|
-
// Preserve the validation class and existing DELETE text; only caller-safe copy may enter it.
|
|
645
|
-
// Other rejection identities stay unchanged. Schema decoration here would change that text.
|
|
646
|
-
const target = await operations.recovery.withSetup({ label, url, invoke: async () => {
|
|
647
|
-
try {
|
|
648
|
-
return await credentialedRequest.resolveTarget({ workspaceId: routeDeps.workspaceId, label, url });
|
|
649
|
-
}
|
|
650
|
-
catch (error) {
|
|
651
|
-
const classified = credentialedRequest.classifyError({ error });
|
|
652
|
-
if (classified.category === "validation")
|
|
653
|
-
throw new CredentialedRequestValidationError({ message: classified.callerSafeMessage });
|
|
654
|
-
throw error;
|
|
655
|
-
}
|
|
656
|
-
} }, {});
|
|
657
|
-
if ("credentialSetup" in target)
|
|
658
|
-
return target;
|
|
659
|
-
// Fail closed rather than degrade — same posture `content_post_delete`'s own handler documents:
|
|
660
|
-
// an execution context that cannot hold this call open cannot run a gated DELETE at all.
|
|
661
|
-
if (!emitSurface) {
|
|
662
|
-
// A `ToolInputError` with the wording unchanged: a bare `Error` is redacted to a 500 that
|
|
663
|
-
// no allowlist rule can rescue. No code prefix — the per-tool suites pin this exact string.
|
|
664
|
-
throw new ToolInputError({ message: operations.messages.noDeleteChannel });
|
|
665
|
-
}
|
|
666
|
-
// A run aborted during reconnaissance must not proceed to the external commit.
|
|
667
|
-
if (ctx.signal.aborted)
|
|
668
|
-
return { executed: false, cancelled: false, reason: "abandoned" };
|
|
669
|
-
return operations.approval.handler({
|
|
670
|
-
prepare: async () => ({ label: target.label, host: target.url.host, path: `${target.url.pathname}${target.url.search}` }),
|
|
671
|
-
describe: ({ prepared }) => ({ ask: true, description: operations.approval.describeDelete(prepared) }),
|
|
672
|
-
askHuman: (required, optional) => operations.approval.askHuman(required, optional),
|
|
673
|
-
run: async ({ ctx: approvedCtx }) => {
|
|
674
|
-
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: approvedCtx.principal.id, permission: host.vocabulary.permissions.write }, { entityType: host.vocabulary.entityType });
|
|
675
|
-
if (approvedCtx.signal.aborted)
|
|
676
|
-
return { executed: false, cancelled: false, reason: "abandoned" };
|
|
677
|
-
const frozen = requireInputRecord({ input: approvedCtx.input });
|
|
678
|
-
return operations.recovery.withSetup({ label, url, invoke: () => makeModelFacingCredentialedRequest({ port: credentialedRequest, input: { workspaceId: routeDeps.workspaceId, label, method: "DELETE", url, headers: frozen.headers, body: frozen.body }, catalog: host.vocabulary.catalog, toolId: operations.ids.makeRequest }) }, {});
|
|
679
|
-
},
|
|
680
|
-
notConfirmed: ({ reason }) => reason === "declined" ? { executed: false, cancelled: true } : { executed: false, cancelled: false, reason },
|
|
681
|
-
})(ctx, { emitSurface });
|
|
682
|
-
},
|
|
683
|
-
// See this file's header for file-write validation, provider-plan and freshness boundaries.
|
|
684
|
-
[operations.ids.writeFiles]: async (ctx) => {
|
|
685
|
-
const input = requireInputRecord({ input: ctx.input });
|
|
686
|
-
const label = requireString({ input, key: "label" });
|
|
687
|
-
const shapeRejection = { toolId: operations.ids.writeFiles, catalog: host.vocabulary.catalog, isShapeRejection: ({ error }) => isWriteFilesShapeRejection(error) };
|
|
688
|
-
const request = await withSchemaOnRejection({ ...shapeRejection, fn: async () => operations.policy.validateWriteFiles({ branch: input.branch, commitMessage: input.commitMessage, files: input.files })
|
|
689
|
-
});
|
|
690
|
-
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: routeDeps.authorize }), workspaceId: routeDeps.workspaceId, principalId: ctx.principal.id, permission: host.vocabulary.permissions.write }, { entityType: host.vocabulary.entityType });
|
|
691
|
-
// The host first, from the credential's plaintext base URL (no decrypt): its owner/repo rules
|
|
692
|
-
// decide whether this call is well formed at all.
|
|
693
|
-
const summary = await operations.sets.byLabel({ label });
|
|
694
|
-
if (!summary) {
|
|
695
|
-
throw new CustomCredentialNotFoundError(operations.messages.notFoundLabel({ label }));
|
|
696
|
-
}
|
|
697
|
-
const built = await sourceControlWrite.build({ workspaceId: routeDeps.workspaceId, baseUrl: summary.baseUrl });
|
|
698
|
-
if (!built.ok)
|
|
699
|
-
throw new Error(operations.messages.writeFailure({ message: built.message }));
|
|
700
|
-
const provider = built.provider;
|
|
701
|
-
const target = await withSchemaOnRejection({ ...shapeRejection, fn: async () => sourceControlWrite.validateTarget({ provider, target: { owner: input.owner, repo: input.repo } }) });
|
|
702
|
-
const validated = { ...request, ...target };
|
|
703
|
-
// A DECRYPTING resolve: the plan phase's read-only host calls need the token regardless of
|
|
704
|
-
// whether the human goes on to confirm. The row was just seen above; one deleted in between
|
|
705
|
-
// is the same not-found refusal.
|
|
706
|
-
const resolved = await operations.sets.resolve({ label });
|
|
707
|
-
if (!resolved) {
|
|
708
|
-
throw new CustomCredentialNotFoundError(operations.messages.notFoundLabel({ label }));
|
|
709
|
-
}
|
|
710
|
-
const planResult = await sourceControlWrite.planFileWrite({ provider, input: { ...writeTarget(resolved, validated), branch: validated.branch, files: validated.files } });
|
|
711
|
-
if (!planResult.ok) {
|
|
712
|
-
operations.diagnostics.writeFailure({ phase: "plan", failure: planResult });
|
|
713
|
-
throw new Error(operations.messages.writeFailure({ message: planResult.message }));
|
|
714
|
-
}
|
|
715
|
-
// A run aborted during reconnaissance must not proceed to the external commit.
|
|
716
|
-
if (ctx.signal.aborted)
|
|
717
|
-
return { executed: false, cancelled: false, reason: "abandoned" };
|
|
718
|
-
return performRepositoryFilesWrite({ operations, port: sourceControlWrite, provider, resolved, validated, plan: planResult.plan });
|
|
719
|
-
},
|
|
738
|
+
[operations.ids.list]: (ctx) => listCredentials(tc, ctx),
|
|
739
|
+
[operations.ids.verify]: (ctx) => verifyCredential(tc, ctx),
|
|
740
|
+
[operations.ids.setUsername]: (ctx) => setCredentialUsername(tc, ctx),
|
|
741
|
+
[operations.ids.makeRequest]: (ctx, options) => makeCredentialRequest(tc, ctx, options),
|
|
742
|
+
[operations.ids.writeFiles]: (ctx) => writeCredentialFiles(tc, ctx),
|
|
720
743
|
};
|
|
721
744
|
return buildDomainRegistrations({ metadata: host.vocabulary.metadata,
|
|
722
745
|
domain: host.vocabulary.domain,
|
|
@@ -210,7 +210,10 @@ export declare function hydrateAsyncOperationRecord({ raw }: {
|
|
|
210
210
|
raw: Record<string, unknown>;
|
|
211
211
|
}): AsyncOperationRecord;
|
|
212
212
|
/** Exported for the same reason as `TERMINAL_STATUSES` — see its doc. */
|
|
213
|
-
export declare function assertTransition(from
|
|
213
|
+
export declare function assertTransition({ from, to }: {
|
|
214
|
+
from: AsyncOperationStatus;
|
|
215
|
+
to: AsyncOperationStatus;
|
|
216
|
+
}, _optional?: Record<string, never>): void;
|
|
214
217
|
/**
|
|
215
218
|
* Create-time validation shared by every store, in order: `maxAttempts`, `deadlineAt`, then the
|
|
216
219
|
* `state` allowlist. The duplicate-id check stays with each store, which alone knows its storage
|
|
@@ -236,12 +239,11 @@ export declare function isFencedOut({ existing, options }: {
|
|
|
236
239
|
* `TERMINAL_STATUSES`.
|
|
237
240
|
* @throws `Error` for credential material; `RangeError` for an illegal transition.
|
|
238
241
|
*/
|
|
239
|
-
export declare function mergeAsyncOperationPatch({ existing, patch }: {
|
|
242
|
+
export declare function mergeAsyncOperationPatch({ existing, patch, now }: {
|
|
240
243
|
existing: AsyncOperationRecord;
|
|
241
244
|
patch: AsyncOperationPatch;
|
|
242
|
-
}, { now }: {
|
|
243
245
|
now: number;
|
|
244
|
-
}): AsyncOperationRecord;
|
|
246
|
+
}, _optional?: Record<string, never>): AsyncOperationRecord;
|
|
245
247
|
/**
|
|
246
248
|
* Creates the in-memory reference `AsyncOperationStore`. No persistence — a durable adapter
|
|
247
249
|
* implements the same interface; every method here is written so the equivalent SQL is a direct
|