@jini-ai/integrations 0.3.6 → 0.4.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 +90 -0
- package/README.md +72 -24
- package/dist/args.d.ts +8 -0
- package/dist/args.js +10 -0
- package/dist/argument-error.d.ts +9 -0
- package/dist/argument-error.js +7 -0
- package/dist/credentialed-http/auth-schemes.d.ts +29 -0
- package/dist/credentialed-http/auth-schemes.js +60 -0
- package/dist/credentialed-http/credentialed-request.d.ts +132 -0
- package/dist/credentialed-http/credentialed-request.js +365 -0
- package/dist/credentialed-http/index.d.ts +4 -0
- package/dist/credentialed-http/index.js +4 -0
- package/dist/credentialed-http/ports.d.ts +42 -0
- package/dist/credentialed-http/ports.js +2 -0
- package/dist/media-providers/capability-registry.d.ts +13 -7
- package/dist/media-providers/capability-registry.js +6 -6
- package/dist/media-providers/dispatch/async-operation-store.d.ts +25 -8
- package/dist/media-providers/dispatch/async-operation-store.js +12 -32
- package/dist/media-providers/dispatch/builtin-vendors.d.ts +6 -0
- package/dist/media-providers/dispatch/builtin-vendors.js +30 -0
- package/dist/media-providers/dispatch/context.d.ts +7 -2
- package/dist/media-providers/dispatch/context.js +1 -1
- package/dist/media-providers/dispatch/credentials.d.ts +4 -1
- package/dist/media-providers/dispatch/credentials.js +1 -1
- package/dist/media-providers/dispatch/engine.d.ts +5 -13
- package/dist/media-providers/dispatch/engine.js +25 -26
- package/dist/media-providers/dispatch/index.d.ts +4 -1
- package/dist/media-providers/dispatch/index.js +4 -2
- package/dist/media-providers/dispatch/openai-compatible.d.ts +12 -2
- package/dist/media-providers/dispatch/openai-compatible.js +9 -5
- package/dist/media-providers/dispatch/operation-runtime.d.ts +16 -8
- package/dist/media-providers/dispatch/operation-runtime.js +93 -76
- package/dist/media-providers/dispatch/outbound.d.ts +31 -0
- package/dist/media-providers/dispatch/outbound.js +54 -0
- package/dist/media-providers/dispatch/polling-adapter.d.ts +26 -8
- package/dist/media-providers/dispatch/polling-adapter.js +2 -2
- package/dist/media-providers/dispatch/providers/aihubmix-shared.d.ts +2 -2
- package/dist/media-providers/dispatch/providers/aihubmix-shared.js +2 -2
- package/dist/media-providers/dispatch/providers/aihubmix.d.ts +13 -2
- package/dist/media-providers/dispatch/providers/aihubmix.js +18 -16
- package/dist/media-providers/dispatch/providers/custom-image.d.ts +16 -2
- package/dist/media-providers/dispatch/providers/custom-image.js +12 -9
- package/dist/media-providers/dispatch/providers/elevenlabs.d.ts +13 -2
- package/dist/media-providers/dispatch/providers/elevenlabs.js +16 -14
- package/dist/media-providers/dispatch/providers/fishaudio.d.ts +9 -1
- package/dist/media-providers/dispatch/providers/fishaudio.js +10 -8
- package/dist/media-providers/dispatch/providers/grok.d.ts +16 -3
- package/dist/media-providers/dispatch/providers/grok.js +19 -17
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.js +23 -22
- package/dist/media-providers/dispatch/providers/imagerouter.d.ts +17 -3
- package/dist/media-providers/dispatch/providers/imagerouter.js +21 -19
- package/dist/media-providers/dispatch/providers/minimax.d.ts +9 -1
- package/dist/media-providers/dispatch/providers/minimax.js +9 -7
- package/dist/media-providers/dispatch/providers/nanobanana.d.ts +9 -1
- package/dist/media-providers/dispatch/providers/nanobanana.js +10 -8
- package/dist/media-providers/dispatch/providers/openai.d.ts +13 -2
- package/dist/media-providers/dispatch/providers/openai.js +23 -28
- package/dist/media-providers/dispatch/providers/openrouter.d.ts +12 -2
- package/dist/media-providers/dispatch/providers/openrouter.js +14 -12
- package/dist/media-providers/dispatch/providers/senseaudio.d.ts +13 -2
- package/dist/media-providers/dispatch/providers/senseaudio.js +16 -14
- package/dist/media-providers/dispatch/providers/volcengine.d.ts +9 -1
- package/dist/media-providers/dispatch/providers/volcengine.js +11 -9
- package/dist/media-providers/dispatch/response-parsers.d.ts +21 -7
- package/dist/media-providers/dispatch/response-parsers.js +15 -11
- package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts +3 -1
- package/dist/media-providers/dispatch/sqlite-async-operation-store.js +30 -28
- package/dist/media-providers/dispatch/ssrf-guard.d.ts +27 -14
- package/dist/media-providers/dispatch/ssrf-guard.js +46 -105
- package/dist/media-providers/dispatch/stub.d.ts +7 -2
- package/dist/media-providers/dispatch/stub.js +4 -3
- package/dist/media-providers/dispatch/types.d.ts +17 -13
- package/dist/media-providers/dispatch/vendor-adapter.d.ts +22 -5
- package/dist/media-providers/dispatch/vendor-adapter.js +13 -10
- package/dist/media-providers/dispatch/vendor-registry.d.ts +14 -11
- package/dist/media-providers/dispatch/vendor-registry.js +33 -4
- package/dist/media-providers/index.d.ts +1 -1
- package/dist/media-providers/index.js +1 -1
- package/dist/media-providers/policy.d.ts +3 -2
- package/dist/media-providers/policy.js +4 -2
- package/dist/media-providers/providers.d.ts +12 -4
- package/dist/media-providers/providers.js +3 -3
- package/dist/media-providers/staging.d.ts +8 -2
- package/dist/media-providers/staging.js +13 -4
- package/dist/media-providers/task-store.d.ts +2 -2
- package/dist/media-providers/task-store.js +2 -2
- package/dist/media-providers/tokens.js +3 -3
- package/dist/media-providers/types.d.ts +4 -4
- package/dist/media-providers/types.js +1 -1
- package/dist/media-providers/video-request.d.ts +35 -15
- package/dist/media-providers/video-request.js +15 -15
- package/dist/webhooks/delivery.d.ts +76 -0
- package/dist/webhooks/delivery.js +222 -0
- package/dist/webhooks/index.d.ts +7 -0
- package/dist/webhooks/index.js +7 -0
- package/dist/webhooks/ports.d.ts +113 -0
- package/dist/webhooks/ports.js +2 -0
- package/dist/webhooks/signing.d.ts +38 -0
- package/dist/webhooks/signing.js +83 -0
- package/dist/webhooks/signing.keyring.d.ts +8 -0
- package/dist/webhooks/signing.keyring.js +18 -0
- package/dist/webhooks/subscriptions.d.ts +78 -0
- package/dist/webhooks/subscriptions.js +139 -0
- package/dist/webhooks/types.d.ts +103 -0
- package/dist/webhooks/types.js +2 -0
- package/package.json +36 -22
- package/dist/composio/bounded-data.d.ts.map +0 -1
- package/dist/composio/bounded-data.js.map +0 -1
- package/dist/composio/catalog.d.ts.map +0 -1
- package/dist/composio/catalog.js.map +0 -1
- package/dist/composio/composio-config.d.ts.map +0 -1
- package/dist/composio/composio-config.js.map +0 -1
- package/dist/composio/composio-descriptions.d.ts.map +0 -1
- package/dist/composio/composio-descriptions.js.map +0 -1
- package/dist/composio/composio.d.ts.map +0 -1
- package/dist/composio/composio.js.map +0 -1
- package/dist/composio/errors.d.ts.map +0 -1
- package/dist/composio/errors.js.map +0 -1
- package/dist/composio/file-lock.d.ts.map +0 -1
- package/dist/composio/file-lock.js.map +0 -1
- package/dist/composio/index.d.ts.map +0 -1
- package/dist/composio/index.js.map +0 -1
- package/dist/composio/json-schema.d.ts.map +0 -1
- package/dist/composio/json-schema.js.map +0 -1
- package/dist/composio/output-protection.d.ts.map +0 -1
- package/dist/composio/output-protection.js.map +0 -1
- package/dist/composio/service.d.ts.map +0 -1
- package/dist/composio/service.js.map +0 -1
- package/dist/media-providers/capability-registry.d.ts.map +0 -1
- package/dist/media-providers/capability-registry.js.map +0 -1
- package/dist/media-providers/catalog.d.ts.map +0 -1
- package/dist/media-providers/catalog.js.map +0 -1
- package/dist/media-providers/dispatch/async-operation-store.d.ts.map +0 -1
- package/dist/media-providers/dispatch/async-operation-store.js.map +0 -1
- package/dist/media-providers/dispatch/context.d.ts.map +0 -1
- package/dist/media-providers/dispatch/context.js.map +0 -1
- package/dist/media-providers/dispatch/credentials.d.ts.map +0 -1
- package/dist/media-providers/dispatch/credentials.js.map +0 -1
- package/dist/media-providers/dispatch/engine.d.ts.map +0 -1
- package/dist/media-providers/dispatch/engine.js.map +0 -1
- package/dist/media-providers/dispatch/index.d.ts.map +0 -1
- package/dist/media-providers/dispatch/index.js.map +0 -1
- package/dist/media-providers/dispatch/openai-compatible.d.ts.map +0 -1
- package/dist/media-providers/dispatch/openai-compatible.js.map +0 -1
- package/dist/media-providers/dispatch/operation-runtime.d.ts.map +0 -1
- package/dist/media-providers/dispatch/operation-runtime.js.map +0 -1
- package/dist/media-providers/dispatch/polling-adapter.d.ts.map +0 -1
- package/dist/media-providers/dispatch/polling-adapter.js.map +0 -1
- package/dist/media-providers/dispatch/providers/aihubmix-shared.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/aihubmix-shared.js.map +0 -1
- package/dist/media-providers/dispatch/providers/aihubmix.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/aihubmix.js.map +0 -1
- package/dist/media-providers/dispatch/providers/custom-image.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/custom-image.js.map +0 -1
- package/dist/media-providers/dispatch/providers/elevenlabs.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/elevenlabs.js.map +0 -1
- package/dist/media-providers/dispatch/providers/fishaudio.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/fishaudio.js.map +0 -1
- package/dist/media-providers/dispatch/providers/grok.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/grok.js.map +0 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.js.map +0 -1
- package/dist/media-providers/dispatch/providers/imagerouter.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/imagerouter.js.map +0 -1
- package/dist/media-providers/dispatch/providers/minimax.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/minimax.js.map +0 -1
- package/dist/media-providers/dispatch/providers/nanobanana.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/nanobanana.js.map +0 -1
- package/dist/media-providers/dispatch/providers/openai.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/openai.js.map +0 -1
- package/dist/media-providers/dispatch/providers/openrouter.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/openrouter.js.map +0 -1
- package/dist/media-providers/dispatch/providers/senseaudio.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/senseaudio.js.map +0 -1
- package/dist/media-providers/dispatch/providers/volcengine.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/volcengine.js.map +0 -1
- package/dist/media-providers/dispatch/response-parsers.d.ts.map +0 -1
- package/dist/media-providers/dispatch/response-parsers.js.map +0 -1
- package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts.map +0 -1
- package/dist/media-providers/dispatch/sqlite-async-operation-store.js.map +0 -1
- package/dist/media-providers/dispatch/ssrf-guard.d.ts.map +0 -1
- package/dist/media-providers/dispatch/ssrf-guard.js.map +0 -1
- package/dist/media-providers/dispatch/stub.d.ts.map +0 -1
- package/dist/media-providers/dispatch/stub.js.map +0 -1
- package/dist/media-providers/dispatch/types.d.ts.map +0 -1
- package/dist/media-providers/dispatch/types.js.map +0 -1
- package/dist/media-providers/dispatch/vendor-adapter.d.ts.map +0 -1
- package/dist/media-providers/dispatch/vendor-adapter.js.map +0 -1
- package/dist/media-providers/dispatch/vendor-registry.d.ts.map +0 -1
- package/dist/media-providers/dispatch/vendor-registry.js.map +0 -1
- package/dist/media-providers/index.d.ts.map +0 -1
- package/dist/media-providers/index.js.map +0 -1
- package/dist/media-providers/policy.d.ts.map +0 -1
- package/dist/media-providers/policy.js.map +0 -1
- package/dist/media-providers/providers.d.ts.map +0 -1
- package/dist/media-providers/providers.js.map +0 -1
- package/dist/media-providers/seed.d.ts.map +0 -1
- package/dist/media-providers/seed.js.map +0 -1
- package/dist/media-providers/sqlite-task-store.d.ts.map +0 -1
- package/dist/media-providers/sqlite-task-store.js.map +0 -1
- package/dist/media-providers/staging.d.ts.map +0 -1
- package/dist/media-providers/staging.js.map +0 -1
- package/dist/media-providers/task-store.d.ts.map +0 -1
- package/dist/media-providers/task-store.js.map +0 -1
- package/dist/media-providers/tokens.d.ts.map +0 -1
- package/dist/media-providers/tokens.js.map +0 -1
- package/dist/media-providers/types.d.ts.map +0 -1
- package/dist/media-providers/types.js.map +0 -1
- package/dist/media-providers/video-request.d.ts.map +0 -1
- package/dist/media-providers/video-request.js.map +0 -1
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arbitrary operator-saved provider URLs require an injected guarded HTTP port, rather than raw
|
|
3
|
+
* fetch against an assumed-safe provider catalog. Composition owns DNS/address checks, connection
|
|
4
|
+
* pinning, per-hop redirect checks, response bounds, and cross-origin authorization stripping.
|
|
5
|
+
* This layer adds the credential's persisted origin binding; request input cannot widen it.
|
|
6
|
+
* Confirmation belongs to the calling host: this service executes an allowed verb uniformly and
|
|
7
|
+
* does not introduce a second approval ceremony or expose decrypted credentials to the caller.
|
|
8
|
+
*/
|
|
9
|
+
import { IntegrationError } from "../argument-error.js";
|
|
10
|
+
import { nowIso } from "@jini-ai/core/primitives";
|
|
11
|
+
import { detectSelfDescribingAuthScheme } from "./auth-schemes.js";
|
|
12
|
+
export class CredentialNotFoundError extends IntegrationError {
|
|
13
|
+
}
|
|
14
|
+
// Multiple saved origins support providers with separate API hosts. A single absolute URL keeps
|
|
15
|
+
// host/path fields from drifting; compare parsed origins exactly, never prefixes or substrings.
|
|
16
|
+
function allowedOriginsFor(record) {
|
|
17
|
+
return [...new Set([new URL(record.baseUrl).origin, ...record.additionalHosts])];
|
|
18
|
+
}
|
|
19
|
+
// Request validation is distinct from validation of stored credentials, which belongs to the resolver.
|
|
20
|
+
export class CredentialedRequestValidationError extends IntegrationError {
|
|
21
|
+
}
|
|
22
|
+
// An answered HTTP error is still a normal response. A host-recognized egress refusal retains its
|
|
23
|
+
// identity, so callers can distinguish a fixable target rejection from a DNS/timeout failure.
|
|
24
|
+
export class CredentialedRequestTransportError extends IntegrationError {
|
|
25
|
+
}
|
|
26
|
+
// Bound a synchronous agent-facing probe; the guarded client's policy timeout may lower this ceiling.
|
|
27
|
+
const CREDENTIALED_REQUEST_TIMEOUT_MS = 10_000;
|
|
28
|
+
// Response bounds do not bound what a caller can ask the server to SEND. Cap that direction too.
|
|
29
|
+
const MAX_REQUEST_BODY_BYTES = 1_000_000;
|
|
30
|
+
// Caller headers cannot replace credentials or override the bound host. User-Agent is allowed:
|
|
31
|
+
// it carries no secret and does not widen origin binding; the transport's default need not override it.
|
|
32
|
+
const FORBIDDEN_REQUEST_HEADER_NAMES = new Set(["authorization", "cookie", "host", "proxy-authorization"]);
|
|
33
|
+
// Echo endpoints and provider cookies must not return credential-bearing headers to the model,
|
|
34
|
+
// even when a value is too short to identify safely by substring matching.
|
|
35
|
+
const FORBIDDEN_RESPONSE_HEADER_NAMES = new Set(["authorization", "proxy-authorization", "set-cookie", "cookie"]);
|
|
36
|
+
// A visible marker explains removal; silently splicing bytes out could alter the response's meaning.
|
|
37
|
+
const REDACTED_MARKER = "[REDACTED]";
|
|
38
|
+
// Very short tokens can match ordinary words ("ab" inside "abacus"); scrubbing would silently
|
|
39
|
+
// mangle unrelated content. The eight-character floor retains normal long API-token responses
|
|
40
|
+
// while withholding pathological ones. Dropping a whole response header needs no such floor.
|
|
41
|
+
const MIN_SAFE_BODY_REDACTION_TOKEN_LENGTH = 8;
|
|
42
|
+
// Withhold the body rather than leak the secret or make unrelated content look like provider output;
|
|
43
|
+
// the request still ran, and the marker lets a caller distinguish display limits from auth failure.
|
|
44
|
+
const BODY_WITHHELD_SHORT_TOKEN_MARKER = "[body withheld: credential too short to redact safely]";
|
|
45
|
+
// Match secrets embedded in diagnostic header values too, not just values equal to a full secret.
|
|
46
|
+
// Whole-header removal has no partial-mangling failure mode and therefore applies at any length.
|
|
47
|
+
function redactResponseHeaders(headers, secrets) {
|
|
48
|
+
const result = {};
|
|
49
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
50
|
+
if (FORBIDDEN_RESPONSE_HEADER_NAMES.has(key.trim().toLowerCase()))
|
|
51
|
+
continue;
|
|
52
|
+
if (secrets.some((secret) => secret !== "" && value.includes(secret)))
|
|
53
|
+
continue;
|
|
54
|
+
result[key] = value;
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
// Reflecting responses must not send injected credentials back through the model; retain all other
|
|
59
|
+
// provider text instead of replacing the provider's answer with an authentication diagnosis.
|
|
60
|
+
function redactSecretSubstrings(text, secrets) {
|
|
61
|
+
return secrets.reduce((acc, secret) => (secret === "" ? acc : acc.split(secret).join(REDACTED_MARKER)), text);
|
|
62
|
+
}
|
|
63
|
+
// One-to-three-character suffix matches are too ambiguous to identify a cut-off secret. This
|
|
64
|
+
// four-character partial-tail floor gates a different risk from the full-token length floor above.
|
|
65
|
+
const MIN_SAFE_TRUNCATED_TAIL_PREFIX_LENGTH = 4;
|
|
66
|
+
// A size cap can cut a reflected secret mid-token, so whole-secret replacement alone leaks its
|
|
67
|
+
// prefix. Use the longest matching suffix across all secrets to remove the whole fragment; only
|
|
68
|
+
// truncated bodies qualify, since matching complete bodies could remove innocent trailing text.
|
|
69
|
+
function redactTruncatedTail(body, secrets) {
|
|
70
|
+
let longestMatch = 0;
|
|
71
|
+
for (const secret of secrets) {
|
|
72
|
+
for (let len = Math.min(secret.length, body.length); len >= MIN_SAFE_TRUNCATED_TAIL_PREFIX_LENGTH; len--) {
|
|
73
|
+
if (body.endsWith(secret.slice(0, len))) {
|
|
74
|
+
longestMatch = Math.max(longestMatch, len);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return longestMatch === 0 ? body : body.slice(0, body.length - longestMatch) + REDACTED_MARKER;
|
|
80
|
+
}
|
|
81
|
+
// Gate on the raw token: a scheme-prefixed header is longer and cannot make a short token safe.
|
|
82
|
+
// The second pass is conditional because a complete response has no cap-cut fragment to repair.
|
|
83
|
+
function resolveRedactedResponseBody(bodyText, token, secrets, bodyTruncated) {
|
|
84
|
+
if (token.length < MIN_SAFE_BODY_REDACTION_TOKEN_LENGTH)
|
|
85
|
+
return BODY_WITHHELD_SHORT_TOKEN_MARKER;
|
|
86
|
+
const redacted = redactSecretSubstrings(bodyText, secrets);
|
|
87
|
+
return bodyTruncated ? redactTruncatedTail(redacted, secrets) : redacted;
|
|
88
|
+
}
|
|
89
|
+
// Match the HTTP port's verb vocabulary so every validated method is one the transport can send.
|
|
90
|
+
const SUPPORTED_METHODS = new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]);
|
|
91
|
+
function requireLabel(raw) {
|
|
92
|
+
if (typeof raw !== "string" || raw.trim() === "") {
|
|
93
|
+
throw new CredentialedRequestValidationError({ message: "label must be a non-empty string" });
|
|
94
|
+
}
|
|
95
|
+
return raw;
|
|
96
|
+
}
|
|
97
|
+
function validateMethod(raw) {
|
|
98
|
+
if (typeof raw !== "string" || !SUPPORTED_METHODS.has(raw)) {
|
|
99
|
+
throw new CredentialedRequestValidationError({ message: "method must be one of GET, POST, PUT, PATCH, DELETE" });
|
|
100
|
+
}
|
|
101
|
+
return raw;
|
|
102
|
+
}
|
|
103
|
+
// This binds the original caller URL only. Any redirect comes from the already-approved host;
|
|
104
|
+
// the injected transport must recheck its address and strip credentials on cross-origin hops,
|
|
105
|
+
// rather than widening its global egress allowlist to make the redirected host reachable.
|
|
106
|
+
function resolveAllowedRequestUrl(candidate, allowedOrigins) {
|
|
107
|
+
if (typeof candidate !== "string" || candidate.trim() === "") {
|
|
108
|
+
throw new CredentialedRequestValidationError({ message: "url must be a non-empty string" });
|
|
109
|
+
}
|
|
110
|
+
let parsed;
|
|
111
|
+
try {
|
|
112
|
+
parsed = new URL(candidate);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
throw new CredentialedRequestValidationError({ message: "url must be a valid absolute URL" });
|
|
116
|
+
}
|
|
117
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
118
|
+
throw new CredentialedRequestValidationError({ message: "url must use http or https" });
|
|
119
|
+
}
|
|
120
|
+
if (parsed.username || parsed.password) {
|
|
121
|
+
throw new CredentialedRequestValidationError({ message: "url must not embed credentials (user:pass@) — the server injects the real Authorization header itself" });
|
|
122
|
+
}
|
|
123
|
+
if (!allowedOrigins.includes(parsed.origin)) {
|
|
124
|
+
throw new CredentialedRequestValidationError({ message: `url '${candidate}' resolves to origin '${parsed.origin}', which is not one of this credential's saved hosts (${allowedOrigins.join(", ")})` });
|
|
125
|
+
}
|
|
126
|
+
return parsed;
|
|
127
|
+
}
|
|
128
|
+
function isPlainRecord(value) {
|
|
129
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
130
|
+
}
|
|
131
|
+
// Keep one entry's rejection logic separate so the collection validator has a single per-entry call.
|
|
132
|
+
function validateHeaderEntry(key, value) {
|
|
133
|
+
if (typeof value !== "string") {
|
|
134
|
+
throw new CredentialedRequestValidationError({ message: `header '${key}' must be a string value` });
|
|
135
|
+
}
|
|
136
|
+
if (FORBIDDEN_REQUEST_HEADER_NAMES.has(key.trim().toLowerCase())) {
|
|
137
|
+
throw new CredentialedRequestValidationError({ message: `header '${key}' may not be set by the caller — the server injects the real credential's own Authorization header itself` });
|
|
138
|
+
}
|
|
139
|
+
return value;
|
|
140
|
+
}
|
|
141
|
+
function validateExtraHeaders(raw) {
|
|
142
|
+
if (raw === undefined)
|
|
143
|
+
return {};
|
|
144
|
+
if (!isPlainRecord(raw)) {
|
|
145
|
+
throw new CredentialedRequestValidationError({ message: "headers must be an object of string values" });
|
|
146
|
+
}
|
|
147
|
+
const result = {};
|
|
148
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
149
|
+
result[key] = validateHeaderEntry(key, value);
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
// Some real APIs accept DELETE bodies; do not invent a verb-specific restriction here.
|
|
154
|
+
function validateOptionalBody(raw) {
|
|
155
|
+
if (raw === undefined)
|
|
156
|
+
return undefined;
|
|
157
|
+
if (typeof raw !== "string") {
|
|
158
|
+
throw new CredentialedRequestValidationError({ message: "body must be a string when provided" });
|
|
159
|
+
}
|
|
160
|
+
const byteLength = Buffer.byteLength(raw, "utf8");
|
|
161
|
+
if (byteLength > MAX_REQUEST_BODY_BYTES) {
|
|
162
|
+
throw new CredentialedRequestValidationError({ message: `body is ${byteLength} bytes, which exceeds the ${MAX_REQUEST_BODY_BYTES}-byte limit for this tool` });
|
|
163
|
+
}
|
|
164
|
+
return raw;
|
|
165
|
+
}
|
|
166
|
+
// A self-describing token dictates its transport even if an old saved username remains. Both header
|
|
167
|
+
// building and diagnostics call this resolver so reported auth can never drift from what was sent.
|
|
168
|
+
function resolveAuthorizationScheme(connection, schemes) {
|
|
169
|
+
const selfDescribing = detectSelfDescribingAuthScheme({ token: connection.token, rules: schemes });
|
|
170
|
+
if (selfDescribing) {
|
|
171
|
+
return { kind: "self-describing", scheme: selfDescribing.scheme, value: selfDescribing.value };
|
|
172
|
+
}
|
|
173
|
+
if (connection.username) {
|
|
174
|
+
return { kind: "basic", username: connection.username, token: connection.token };
|
|
175
|
+
}
|
|
176
|
+
return { kind: "bearer", token: connection.token };
|
|
177
|
+
}
|
|
178
|
+
/** Resolve self-describing, Basic, then Bearer precedence for trusted outbound-request executors.
|
|
179
|
+
* Returns a secret-bearing header to those executors only; never expose it in tool/model results,
|
|
180
|
+
* previews or logs. Callers needing only the target must use `resolveRequestTarget` instead. */
|
|
181
|
+
// Public so other credential-using operations share precedence; returned secrets belong only in
|
|
182
|
+
// outbound headers, never logs or model-facing results. Pass an empty rule set for Basic/Bearer only.
|
|
183
|
+
export function buildAuthorizationHeader(required) {
|
|
184
|
+
const { connection, schemes } = required;
|
|
185
|
+
const resolved = resolveAuthorizationScheme(connection, schemes);
|
|
186
|
+
if (resolved.kind === "self-describing")
|
|
187
|
+
return `${resolved.scheme} ${resolved.value}`;
|
|
188
|
+
if (resolved.kind === "basic")
|
|
189
|
+
return `Basic ${buildBasicAuthPayload(resolved.username, resolved.token)}`;
|
|
190
|
+
return `Bearer ${resolved.token}`;
|
|
191
|
+
}
|
|
192
|
+
// Share the exact encoding with response redaction. An echo of the bare base64 username:token
|
|
193
|
+
// payload contains neither the full prefixed header nor the raw token, and must be listed separately.
|
|
194
|
+
function buildBasicAuthPayload(username, token) {
|
|
195
|
+
return Buffer.from(`${username}:${token}`, "utf8").toString("base64");
|
|
196
|
+
}
|
|
197
|
+
function buildAuthFailureDiagnostic(connection, status, schemes) {
|
|
198
|
+
const usernameStored = connection.username !== undefined;
|
|
199
|
+
const resolved = resolveAuthorizationScheme(connection, schemes);
|
|
200
|
+
const schemeSent = resolved.kind === "self-describing" ? resolved.scheme : resolved.kind === "basic" ? "Basic" : "Bearer";
|
|
201
|
+
// A provider once returned 403 for a missing User-Agent, and suggesting Basic auth led to an
|
|
202
|
+
// ineffective username repair. Scope/policy/header refusals explain 403 too; retain facts without
|
|
203
|
+
// guessing. Gate on the scheme actually sent, not username presence alone.
|
|
204
|
+
if (resolved.kind !== "bearer" || status !== 401) {
|
|
205
|
+
return { schemeSent, usernameStored };
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
schemeSent,
|
|
209
|
+
usernameStored,
|
|
210
|
+
hint: "This request was sent with a Bearer token and no saved username. Some providers (e.g. ones that " +
|
|
211
|
+
"authenticate a token against an account username via HTTP Basic) may reject a Bearer-only request " +
|
|
212
|
+
"for that reason — this credential has no username saved. If that's the cause, saving one may fix it.",
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
// A structured line gives deployments an inspectable trail without requiring a database audit sink.
|
|
216
|
+
export class ConsoleCredentialedRequestAuditLog {
|
|
217
|
+
required;
|
|
218
|
+
constructor(required) {
|
|
219
|
+
this.required = required;
|
|
220
|
+
}
|
|
221
|
+
record({ entry }) {
|
|
222
|
+
const refusal = entry.egressRefusal !== undefined ? ` egressRefusal=${JSON.stringify(entry.egressRefusal)}` : "";
|
|
223
|
+
this.required.log({
|
|
224
|
+
line: `${this.required.prefix} request label=${entry.label} host=${entry.host} method=${entry.method} status=${entry.status} bodyBytes=${entry.bodyBytes} at=${entry.at}${refusal}`,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
// Capture ordered metadata for direct audit assertions without parsing formatted log lines.
|
|
229
|
+
export class InMemoryCredentialedRequestAuditLog {
|
|
230
|
+
entries = [];
|
|
231
|
+
record({ entry }) {
|
|
232
|
+
this.entries.push(entry);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/** Resolve an approved request target without decrypting credentials. */
|
|
236
|
+
// Confirmation dialogs need only plaintext label/origins. A declined call should never cost a
|
|
237
|
+
// decrypt; the full resolver is reserved for callers that will actually send an authenticated request.
|
|
238
|
+
export async function resolveRequestTarget(required) {
|
|
239
|
+
const { resolver, input } = required;
|
|
240
|
+
const label = requireLabel(input.label);
|
|
241
|
+
const summary = await resolver.describe({ workspaceId: input.workspaceId, label });
|
|
242
|
+
if (!summary)
|
|
243
|
+
throw new CredentialNotFoundError({ message: `no custom credential labeled '${label}' in this workspace` });
|
|
244
|
+
return { label, url: resolveAllowedRequestUrl(input.url, allowedOriginsFor(summary)) };
|
|
245
|
+
}
|
|
246
|
+
// Decrypting path: callers needing only origins must use describe/resolveRequestTarget instead.
|
|
247
|
+
// Missing rows fail loudly and resolver decryption failures propagate rather than appearing absent.
|
|
248
|
+
async function resolveCredentialOrThrow(deps, input) {
|
|
249
|
+
const resolved = await deps.resolver.resolve(input);
|
|
250
|
+
if (!resolved)
|
|
251
|
+
throw new CredentialNotFoundError({ message: `no custom credential labeled '${input.label}' in this workspace` });
|
|
252
|
+
return resolved;
|
|
253
|
+
}
|
|
254
|
+
// Only 401/403 affirmatively reject it; redirects and other statuses reaching this classifier say
|
|
255
|
+
// nothing about validity. Keep this local rather than coupling independent provider features.
|
|
256
|
+
function classifyCustomCredentialStatus(status) {
|
|
257
|
+
if (status >= 200 && status < 300)
|
|
258
|
+
return "valid";
|
|
259
|
+
if (status === 401 || status === 403)
|
|
260
|
+
return "invalid";
|
|
261
|
+
return "unreachable";
|
|
262
|
+
}
|
|
263
|
+
// Wording may change without changing the three-way classification contract.
|
|
264
|
+
function buildVerificationMessage(label, status, outcome) {
|
|
265
|
+
if (outcome === "valid")
|
|
266
|
+
return `'${label}' accepted this credential.`;
|
|
267
|
+
if (outcome === "invalid") {
|
|
268
|
+
return `'${label}' rejected this credential (HTTP ${status}) — it is invalid, expired, or missing required permissions.`;
|
|
269
|
+
}
|
|
270
|
+
return `Could not get a clear accept or reject from '${label}' (HTTP ${status}) — this does not necessarily mean the credential is bad.`;
|
|
271
|
+
}
|
|
272
|
+
/** Probe the saved origin root and classify 2xx/401/403/other outcomes; audit without returning response bodies. */
|
|
273
|
+
// Probe the primary saved origin to answer whether the credential works at all, rather than trying
|
|
274
|
+
// every additional API host. Provider bodies never belong in verification results; transport failure
|
|
275
|
+
// remains "unreachable", and only an affirmative auth rejection has a diagnostic worth attaching.
|
|
276
|
+
export async function verifyCustomCredential(required, optional = {}) {
|
|
277
|
+
const { deps, input } = required;
|
|
278
|
+
const label = requireLabel(input.label);
|
|
279
|
+
const checkedAt = nowIso({ clock: deps.clock });
|
|
280
|
+
const { baseUrl, connection } = await resolveCredentialOrThrow(deps, { workspaceId: input.workspaceId, label });
|
|
281
|
+
const url = new URL(`${new URL(baseUrl).origin}/`);
|
|
282
|
+
const audit = deps.audit;
|
|
283
|
+
const schemes = await deps.schemeRegistry.load({ workspaceId: input.workspaceId });
|
|
284
|
+
let status;
|
|
285
|
+
try {
|
|
286
|
+
const response = await deps.httpClient.send({ request: {
|
|
287
|
+
method: "GET",
|
|
288
|
+
url: url.toString(),
|
|
289
|
+
headers: { Authorization: buildAuthorizationHeader({ connection, schemes }) },
|
|
290
|
+
timeoutMs: CREDENTIALED_REQUEST_TIMEOUT_MS,
|
|
291
|
+
} });
|
|
292
|
+
status = response.status;
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
audit.record({ entry: { label, host: url.hostname, method: "GET", status: 0, bodyBytes: 0, at: checkedAt } });
|
|
296
|
+
return { status: "unreachable", message: `Could not reach '${label}' to verify this credential — this does not necessarily mean the credential is bad.`, checkedAt };
|
|
297
|
+
}
|
|
298
|
+
audit.record({ entry: { label, host: url.hostname, method: "GET", status, bodyBytes: 0, at: checkedAt } });
|
|
299
|
+
const outcome = classifyCustomCredentialStatus(status);
|
|
300
|
+
const authDiagnostic = outcome === "invalid" ? mapAuthDiagnostic(connection, status, schemes, optional) : undefined;
|
|
301
|
+
return { status: outcome, message: buildVerificationMessage(label, status, outcome), checkedAt, ...(authDiagnostic ? { authDiagnostic } : {}) };
|
|
302
|
+
}
|
|
303
|
+
// Echo endpoints may return bare Basic payloads or bare self-describing values without their scheme
|
|
304
|
+
// words. Listing just the raw token and full header missed those leaks. Derive forms from the same
|
|
305
|
+
// resolved scheme as header building: a leftover username must not invent a Basic payload never sent.
|
|
306
|
+
// Keep an explicit three-way match: grouping self-describing with "not Basic" once silently used
|
|
307
|
+
// Bearer's incomplete two-secret list and leaked a reflected bare value.
|
|
308
|
+
function buildResponseSecrets(connection, authorizationHeader, schemes) {
|
|
309
|
+
const resolvedScheme = resolveAuthorizationScheme(connection, schemes);
|
|
310
|
+
if (resolvedScheme.kind === "self-describing")
|
|
311
|
+
return [authorizationHeader, connection.token, resolvedScheme.value];
|
|
312
|
+
if (resolvedScheme.kind === "basic")
|
|
313
|
+
return [authorizationHeader, connection.token, buildBasicAuthPayload(resolvedScheme.username, resolvedScheme.token)];
|
|
314
|
+
return [authorizationHeader, connection.token];
|
|
315
|
+
}
|
|
316
|
+
function mapAuthDiagnostic(connection, status, schemes, optional) {
|
|
317
|
+
const diagnostic = buildAuthFailureDiagnostic(connection, status, schemes);
|
|
318
|
+
return optional.diagnosticMapper ? optional.diagnosticMapper({ diagnostic, status }) : diagnostic;
|
|
319
|
+
}
|
|
320
|
+
/** Validate caller shape and credential origins, send through the guarded HTTP port, then redact response secrets. Transport failures are audited; egress refusal identity is host-defined. */
|
|
321
|
+
// Malformed/off-origin requests must fail before any network call. Actual HTTP error responses
|
|
322
|
+
// resolve normally so the provider's reason survives; transport failures are distinct throws.
|
|
323
|
+
export async function makeCredentialedRequest(required, optional = {}) {
|
|
324
|
+
const { deps, input } = required;
|
|
325
|
+
const label = requireLabel(input.label);
|
|
326
|
+
const method = validateMethod(input.method);
|
|
327
|
+
const extraHeaders = validateExtraHeaders(optional.headers);
|
|
328
|
+
const body = validateOptionalBody(optional.body);
|
|
329
|
+
const at = nowIso({ clock: deps.clock });
|
|
330
|
+
const { additionalHosts, baseUrl, connection } = await resolveCredentialOrThrow(deps, { workspaceId: input.workspaceId, label });
|
|
331
|
+
const url = resolveAllowedRequestUrl(input.url, allowedOriginsFor({ baseUrl, additionalHosts }));
|
|
332
|
+
const audit = deps.audit;
|
|
333
|
+
const bodyBytes = body !== undefined ? Buffer.byteLength(body, "utf8") : 0;
|
|
334
|
+
const schemes = await deps.schemeRegistry.load({ workspaceId: input.workspaceId });
|
|
335
|
+
const authorizationHeader = buildAuthorizationHeader({ connection, schemes });
|
|
336
|
+
const responseSecrets = buildResponseSecrets(connection, authorizationHeader, schemes);
|
|
337
|
+
let response;
|
|
338
|
+
try {
|
|
339
|
+
response = await deps.httpClient.send({ request: {
|
|
340
|
+
method,
|
|
341
|
+
url: url.toString(),
|
|
342
|
+
headers: { ...extraHeaders, Authorization: authorizationHeader },
|
|
343
|
+
timeoutMs: CREDENTIALED_REQUEST_TIMEOUT_MS,
|
|
344
|
+
...(body !== undefined ? { body } : {}),
|
|
345
|
+
} });
|
|
346
|
+
}
|
|
347
|
+
catch (err) {
|
|
348
|
+
audit.record({ entry: { label, host: url.hostname, method, status: 0, bodyBytes, at, ...(optional.errorPolicy?.isEgressRefusal({ error: err }) ? { egressRefusal: optional.errorPolicy.describeEgressRefusal({ error: err }) } : {}) } });
|
|
349
|
+
// Preserve the host refusal class: wrapping it would make a recoverable target-policy problem
|
|
350
|
+
// indistinguishable from a redacted internal failure at the tool boundary. Audit status stays zero.
|
|
351
|
+
if (optional.errorPolicy?.isEgressRefusal({ error: err }))
|
|
352
|
+
throw err;
|
|
353
|
+
throw new CredentialedRequestTransportError({ message: `request to '${label}' failed: ${resolveRedactedResponseBody(err instanceof Error ? err.message : String(err), connection.token, responseSecrets, false)}` });
|
|
354
|
+
}
|
|
355
|
+
audit.record({ entry: { label, host: url.hostname, method, status: response.status, bodyBytes, at } });
|
|
356
|
+
const authDiagnostic = response.status === 401 || response.status === 403 ? mapAuthDiagnostic(connection, response.status, schemes, optional) : undefined;
|
|
357
|
+
return {
|
|
358
|
+
executed: true,
|
|
359
|
+
status: response.status,
|
|
360
|
+
headers: redactResponseHeaders(response.headers, responseSecrets),
|
|
361
|
+
bodyText: resolveRedactedResponseBody(response.bodyText, connection.token, responseSecrets, response.bodyTruncated === true),
|
|
362
|
+
...(authDiagnostic ? { authDiagnostic } : {}),
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
//# sourceMappingURL=credentialed-request.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Plaintext credentials are resolved in-process for trusted authenticated-request executors.
|
|
2
|
+
* Request/verification results and target previews never return them to tool/model callers;
|
|
3
|
+
* callers needing only origins use `describe`, which does not decrypt. */
|
|
4
|
+
export interface CredentialConnection {
|
|
5
|
+
readonly token: string;
|
|
6
|
+
readonly username?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface CredentialTarget {
|
|
9
|
+
readonly baseUrl: string;
|
|
10
|
+
readonly additionalHosts: readonly string[];
|
|
11
|
+
}
|
|
12
|
+
export interface ResolvedCredential extends CredentialTarget {
|
|
13
|
+
readonly connection: CredentialConnection;
|
|
14
|
+
}
|
|
15
|
+
/** describe must not decrypt; the host owns sealed storage, AAD and workspace authorization. */
|
|
16
|
+
export interface CredentialResolverPort {
|
|
17
|
+
describe(required: {
|
|
18
|
+
workspaceId: string;
|
|
19
|
+
label: string;
|
|
20
|
+
}): Promise<CredentialTarget | null>;
|
|
21
|
+
resolve(required: {
|
|
22
|
+
workspaceId: string;
|
|
23
|
+
label: string;
|
|
24
|
+
}): Promise<ResolvedCredential | null>;
|
|
25
|
+
}
|
|
26
|
+
/** Registry loading/trust policy is host-owned. There is no default plugin loader. */
|
|
27
|
+
export interface CredentialSchemeRegistryPort {
|
|
28
|
+
load(required: {
|
|
29
|
+
workspaceId: string;
|
|
30
|
+
}): Promise<readonly import("./auth-schemes.js").CredentialSchemeRule[]>;
|
|
31
|
+
}
|
|
32
|
+
/** Recognize host egress-refusal identities without coupling to a transport implementation.
|
|
33
|
+
* Descriptions must contain only safe network diagnostics; refusal errors are rethrown unchanged. */
|
|
34
|
+
export interface CredentialedRequestErrorPolicyPort {
|
|
35
|
+
isEgressRefusal(required: {
|
|
36
|
+
error: unknown;
|
|
37
|
+
}): boolean;
|
|
38
|
+
describeEgressRefusal(required: {
|
|
39
|
+
error: unknown;
|
|
40
|
+
}): string;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Injection-style capability registry.
|
|
3
|
-
* from OD's `apps/daemon/src/media-adapters/capabilities.ts` — the
|
|
4
|
-
* task brief's own research flagged this as "a clean, already-generic port."
|
|
2
|
+
* Injection-style capability registry.
|
|
5
3
|
* The registry holds NO data of its own: callers seed it, and every consumer
|
|
6
4
|
* depends only on `get()`/`register()`/`all()`, never on the raw seed, so
|
|
7
5
|
* swapping the data source (a hardcoded const today, a live vendor-API fetch
|
|
@@ -10,9 +8,13 @@
|
|
|
10
8
|
import type { ModelCapability } from './types.js';
|
|
11
9
|
export interface CapabilityRegistry {
|
|
12
10
|
/** Looks up a model by catalogue id (an aggregator prefix, if any, is stripped first — see `normalizeModelId`). */
|
|
13
|
-
get(
|
|
11
|
+
get(required: {
|
|
12
|
+
id: string;
|
|
13
|
+
}): ModelCapability | undefined;
|
|
14
14
|
/** Adds/overrides capabilities (later calls win on a duplicate id). */
|
|
15
|
-
register(
|
|
15
|
+
register(required: {
|
|
16
|
+
caps: readonly ModelCapability[];
|
|
17
|
+
}): void;
|
|
16
18
|
/** All registered capabilities. */
|
|
17
19
|
all(): ModelCapability[];
|
|
18
20
|
}
|
|
@@ -22,7 +24,11 @@ export interface CapabilityRegistry {
|
|
|
22
24
|
* package's one ported reference seed (`seed.ts`) — a different aggregator's
|
|
23
25
|
* prefix is the caller's own normalization to apply before `register`/`get`.
|
|
24
26
|
*/
|
|
25
|
-
export declare function normalizeModelId(id
|
|
27
|
+
export declare function normalizeModelId({ id }: {
|
|
28
|
+
id: string;
|
|
29
|
+
}): string;
|
|
26
30
|
/** Creates a `CapabilityRegistry`, optionally pre-seeded with `seed`. */
|
|
27
|
-
export declare function createCapabilityRegistry(seed?:
|
|
31
|
+
export declare function createCapabilityRegistry({}: Record<string, never>, { seed }?: {
|
|
32
|
+
seed?: readonly ModelCapability[] | undefined;
|
|
33
|
+
}): CapabilityRegistry;
|
|
28
34
|
//# sourceMappingURL=capability-registry.d.ts.map
|
|
@@ -4,22 +4,22 @@
|
|
|
4
4
|
* package's one ported reference seed (`seed.ts`) — a different aggregator's
|
|
5
5
|
* prefix is the caller's own normalization to apply before `register`/`get`.
|
|
6
6
|
*/
|
|
7
|
-
export function normalizeModelId(id) {
|
|
7
|
+
export function normalizeModelId({ id }) {
|
|
8
8
|
return (id || '').trim().replace(/^aihubmix-/, '');
|
|
9
9
|
}
|
|
10
10
|
/** Creates a `CapabilityRegistry`, optionally pre-seeded with `seed`. */
|
|
11
|
-
export function createCapabilityRegistry(seed = []) {
|
|
11
|
+
export function createCapabilityRegistry({}, { seed = [] } = {}) {
|
|
12
12
|
const map = new Map();
|
|
13
|
-
const register = (caps) => {
|
|
13
|
+
const register = ({ caps }) => {
|
|
14
14
|
for (const cap of caps) {
|
|
15
15
|
if (cap && typeof cap.id === 'string' && cap.id) {
|
|
16
|
-
map.set(normalizeModelId(cap.id), cap);
|
|
16
|
+
map.set(normalizeModelId({ id: cap.id }), cap);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
-
register(seed);
|
|
20
|
+
register({ caps: seed });
|
|
21
21
|
return {
|
|
22
|
-
get: (id) => map.get(normalizeModelId(id)),
|
|
22
|
+
get: ({ id }) => map.get(normalizeModelId({ id })),
|
|
23
23
|
register,
|
|
24
24
|
all: () => [...map.values()],
|
|
25
25
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RequiredArgs, OptionalArgs } from '../../args.js';
|
|
1
2
|
/**
|
|
2
3
|
* `AsyncOperationStore` — the durable operation row behind submit-then-poll media generation.
|
|
3
4
|
*
|
|
@@ -137,17 +138,26 @@ export interface AsyncOperationReconcileResult {
|
|
|
137
138
|
readonly deadlineExpired: number;
|
|
138
139
|
}
|
|
139
140
|
export interface AsyncOperationStore {
|
|
140
|
-
create(
|
|
141
|
-
get(
|
|
141
|
+
create(required: RequiredArgs<AsyncOperationCreateInput>, optional?: OptionalArgs<AsyncOperationCreateInput>): Promise<AsyncOperationRecord>;
|
|
142
|
+
get(required: {
|
|
143
|
+
id: string;
|
|
144
|
+
}): Promise<AsyncOperationRecord | null>;
|
|
142
145
|
/**
|
|
143
146
|
* Applies `patch`. Pass `options.leaseOwner` to fence the write to a lease the caller believes it
|
|
144
147
|
* holds — see `AsyncOperationUpdateOptions`. Omitted, the write applies unconditionally (the
|
|
145
148
|
* pre-lease case, e.g. `startOperation`'s initial persistence).
|
|
146
149
|
*/
|
|
147
|
-
update(
|
|
148
|
-
|
|
150
|
+
update(required: {
|
|
151
|
+
id: string;
|
|
152
|
+
patch: AsyncOperationPatch;
|
|
153
|
+
}, optional?: {
|
|
154
|
+
options?: AsyncOperationUpdateOptions | undefined;
|
|
155
|
+
}): Promise<AsyncOperationRecord | null>;
|
|
156
|
+
listByOwner(required: {
|
|
157
|
+
ownerRef: string;
|
|
158
|
+
}): Promise<AsyncOperationRecord[]>;
|
|
149
159
|
/** Atomically leases every due, unleased, non-terminal operation and returns the leased rows. */
|
|
150
|
-
claimDue(
|
|
160
|
+
claimDue(required: RequiredArgs<AsyncOperationClaimOptions>, optional?: OptionalArgs<AsyncOperationClaimOptions>): Promise<AsyncOperationRecord[]>;
|
|
151
161
|
/**
|
|
152
162
|
* Releases a lease this caller believes it holds. Fenced on `leaseOwner`: a release only takes
|
|
153
163
|
* effect while the row's current `leaseOwner` still equals the one passed here (the equivalent
|
|
@@ -158,7 +168,10 @@ export interface AsyncOperationStore {
|
|
|
158
168
|
* never claimed it, or another worker has since reclaimed it — is a no-op, not an error: the
|
|
159
169
|
* caller's intent ("I'm done, let someone else have it") is already satisfied either way.
|
|
160
170
|
*/
|
|
161
|
-
releaseLease(
|
|
171
|
+
releaseLease(required: {
|
|
172
|
+
id: string;
|
|
173
|
+
leaseOwner: string;
|
|
174
|
+
}): Promise<void>;
|
|
162
175
|
/**
|
|
163
176
|
* Boot-time recovery. Unlike `MediaTaskStore.reconcileOnBoot`, this does NOT terminate in-flight
|
|
164
177
|
* work: a vendor-side job outlives our process, so the row stays pollable and only its dead
|
|
@@ -179,7 +192,9 @@ export interface AsyncOperationStore {
|
|
|
179
192
|
* @complexity O(n) in the total number of keys, bounded by `MAX_STATE_DEPTH` against a cyclic or
|
|
180
193
|
* pathologically nested object.
|
|
181
194
|
*/
|
|
182
|
-
export declare function assertNoCredentialMaterial(state
|
|
195
|
+
export declare function assertNoCredentialMaterial({ state }: {
|
|
196
|
+
state: Readonly<Record<string, unknown>> | null | undefined;
|
|
197
|
+
}): void;
|
|
183
198
|
/**
|
|
184
199
|
* The branching read path for a persisted operation row.
|
|
185
200
|
*
|
|
@@ -191,7 +206,9 @@ export declare function assertNoCredentialMaterial(state: Readonly<Record<string
|
|
|
191
206
|
* @throws When `schemaVersion` is newer than this build understands.
|
|
192
207
|
* @complexity O(1).
|
|
193
208
|
*/
|
|
194
|
-
export declare function hydrateAsyncOperationRecord(raw
|
|
209
|
+
export declare function hydrateAsyncOperationRecord({ raw }: {
|
|
210
|
+
raw: Record<string, unknown>;
|
|
211
|
+
}): AsyncOperationRecord;
|
|
195
212
|
/** Exported for the same reason as `TERMINAL_STATUSES` — see its doc. */
|
|
196
213
|
export declare function assertTransition(from: AsyncOperationStatus, to: AsyncOperationStatus): void;
|
|
197
214
|
/**
|