@open-everywhere/adapters 0.1.0
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/LICENSE +201 -0
- package/NOTICE +21 -0
- package/README.md +43 -0
- package/agent/aws/cli.ts +121 -0
- package/agent/aws/config.ts +71 -0
- package/agent/aws/register.ts +65 -0
- package/agent/aws/sso.ts +567 -0
- package/agent/aws/sts.ts +191 -0
- package/agent/blob/hosting.ts +24 -0
- package/agent/browser/config.ts +62 -0
- package/agent/browser/register.ts +66 -0
- package/agent/browser/sandbox.ts +39 -0
- package/agent/contributions.ts +12 -0
- package/agent/directory/config.ts +138 -0
- package/agent/directory/okta.ts +226 -0
- package/agent/directory/register.ts +16 -0
- package/agent/instrumentation.ts +42 -0
- package/agent/model/approval-judge.ts +57 -0
- package/agent/model/dream-judge.ts +105 -0
- package/agent/model/gateway-vision.ts +162 -0
- package/agent/model/gateway.ts +85 -0
- package/agent/oe-oauth/config.ts +246 -0
- package/agent/oe-oauth/errors.ts +77 -0
- package/agent/oe-oauth/oauth-client.ts +376 -0
- package/agent/oe-oauth/pkce.ts +21 -0
- package/agent/oe-oauth/register.ts +32 -0
- package/agent/oe-oauth/token-vault.ts +652 -0
- package/agent/oe-oauth/user-auth-flow.ts +76 -0
- package/agent/postgres/neon.ts +108 -0
- package/agent/sandbox/backend-stop.ts +259 -0
- package/agent/sandbox/created-sandbox-registry.ts +27 -0
- package/agent/sandbox/extend-workspace-time.ts +77 -0
- package/agent/sandbox/vercel-lifecycle.ts +252 -0
- package/dist/agent/aws/cli.d.ts +24 -0
- package/dist/agent/aws/cli.d.ts.map +1 -0
- package/dist/agent/aws/cli.js +89 -0
- package/dist/agent/aws/cli.js.map +1 -0
- package/dist/agent/aws/config.d.ts +27 -0
- package/dist/agent/aws/config.d.ts.map +1 -0
- package/dist/agent/aws/config.js +46 -0
- package/dist/agent/aws/config.js.map +1 -0
- package/dist/agent/aws/register.d.ts +23 -0
- package/dist/agent/aws/register.d.ts.map +1 -0
- package/dist/agent/aws/register.js +39 -0
- package/dist/agent/aws/register.js.map +1 -0
- package/dist/agent/aws/sso.d.ts +109 -0
- package/dist/agent/aws/sso.d.ts.map +1 -0
- package/dist/agent/aws/sso.js +421 -0
- package/dist/agent/aws/sso.js.map +1 -0
- package/dist/agent/aws/sts.d.ts +27 -0
- package/dist/agent/aws/sts.d.ts.map +1 -0
- package/dist/agent/aws/sts.js +135 -0
- package/dist/agent/aws/sts.js.map +1 -0
- package/dist/agent/blob/hosting.d.ts +4 -0
- package/dist/agent/blob/hosting.d.ts.map +1 -0
- package/dist/agent/blob/hosting.js +20 -0
- package/dist/agent/blob/hosting.js.map +1 -0
- package/dist/agent/browser/config.d.ts +24 -0
- package/dist/agent/browser/config.d.ts.map +1 -0
- package/dist/agent/browser/config.js +50 -0
- package/dist/agent/browser/config.js.map +1 -0
- package/dist/agent/browser/register.d.ts +7 -0
- package/dist/agent/browser/register.d.ts.map +1 -0
- package/dist/agent/browser/register.js +47 -0
- package/dist/agent/browser/register.js.map +1 -0
- package/dist/agent/browser/sandbox.d.ts +23 -0
- package/dist/agent/browser/sandbox.d.ts.map +1 -0
- package/dist/agent/browser/sandbox.js +27 -0
- package/dist/agent/browser/sandbox.js.map +1 -0
- package/dist/agent/contributions.d.ts +16 -0
- package/dist/agent/contributions.d.ts.map +1 -0
- package/dist/agent/contributions.js +11 -0
- package/dist/agent/contributions.js.map +1 -0
- package/dist/agent/directory/config.d.ts +39 -0
- package/dist/agent/directory/config.d.ts.map +1 -0
- package/dist/agent/directory/config.js +101 -0
- package/dist/agent/directory/config.js.map +1 -0
- package/dist/agent/directory/okta.d.ts +19 -0
- package/dist/agent/directory/okta.d.ts.map +1 -0
- package/dist/agent/directory/okta.js +178 -0
- package/dist/agent/directory/okta.js.map +1 -0
- package/dist/agent/directory/register.d.ts +6 -0
- package/dist/agent/directory/register.d.ts.map +1 -0
- package/dist/agent/directory/register.js +16 -0
- package/dist/agent/directory/register.js.map +1 -0
- package/dist/agent/instrumentation.d.ts +5 -0
- package/dist/agent/instrumentation.d.ts.map +1 -0
- package/dist/agent/instrumentation.js +39 -0
- package/dist/agent/instrumentation.js.map +1 -0
- package/dist/agent/model/approval-judge.d.ts +15 -0
- package/dist/agent/model/approval-judge.d.ts.map +1 -0
- package/dist/agent/model/approval-judge.js +46 -0
- package/dist/agent/model/approval-judge.js.map +1 -0
- package/dist/agent/model/dream-judge.d.ts +40 -0
- package/dist/agent/model/dream-judge.d.ts.map +1 -0
- package/dist/agent/model/dream-judge.js +80 -0
- package/dist/agent/model/dream-judge.js.map +1 -0
- package/dist/agent/model/gateway-vision.d.ts +53 -0
- package/dist/agent/model/gateway-vision.d.ts.map +1 -0
- package/dist/agent/model/gateway-vision.js +129 -0
- package/dist/agent/model/gateway-vision.js.map +1 -0
- package/dist/agent/model/gateway.d.ts +30 -0
- package/dist/agent/model/gateway.d.ts.map +1 -0
- package/dist/agent/model/gateway.js +55 -0
- package/dist/agent/model/gateway.js.map +1 -0
- package/dist/agent/oe-oauth/config.d.ts +69 -0
- package/dist/agent/oe-oauth/config.d.ts.map +1 -0
- package/dist/agent/oe-oauth/config.js +182 -0
- package/dist/agent/oe-oauth/config.js.map +1 -0
- package/dist/agent/oe-oauth/errors.d.ts +63 -0
- package/dist/agent/oe-oauth/errors.d.ts.map +1 -0
- package/dist/agent/oe-oauth/errors.js +73 -0
- package/dist/agent/oe-oauth/errors.js.map +1 -0
- package/dist/agent/oe-oauth/oauth-client.d.ts +124 -0
- package/dist/agent/oe-oauth/oauth-client.d.ts.map +1 -0
- package/dist/agent/oe-oauth/oauth-client.js +262 -0
- package/dist/agent/oe-oauth/oauth-client.js.map +1 -0
- package/dist/agent/oe-oauth/pkce.d.ts +8 -0
- package/dist/agent/oe-oauth/pkce.d.ts.map +1 -0
- package/dist/agent/oe-oauth/pkce.js +18 -0
- package/dist/agent/oe-oauth/pkce.js.map +1 -0
- package/dist/agent/oe-oauth/register.d.ts +17 -0
- package/dist/agent/oe-oauth/register.d.ts.map +1 -0
- package/dist/agent/oe-oauth/register.js +24 -0
- package/dist/agent/oe-oauth/register.js.map +1 -0
- package/dist/agent/oe-oauth/token-vault.d.ts +107 -0
- package/dist/agent/oe-oauth/token-vault.d.ts.map +1 -0
- package/dist/agent/oe-oauth/token-vault.js +498 -0
- package/dist/agent/oe-oauth/token-vault.js.map +1 -0
- package/dist/agent/oe-oauth/user-auth-flow.d.ts +10 -0
- package/dist/agent/oe-oauth/user-auth-flow.d.ts.map +1 -0
- package/dist/agent/oe-oauth/user-auth-flow.js +66 -0
- package/dist/agent/oe-oauth/user-auth-flow.js.map +1 -0
- package/dist/agent/postgres/neon.d.ts +29 -0
- package/dist/agent/postgres/neon.d.ts.map +1 -0
- package/dist/agent/postgres/neon.js +76 -0
- package/dist/agent/postgres/neon.js.map +1 -0
- package/dist/agent/sandbox/backend-stop.d.ts +98 -0
- package/dist/agent/sandbox/backend-stop.d.ts.map +1 -0
- package/dist/agent/sandbox/backend-stop.js +188 -0
- package/dist/agent/sandbox/backend-stop.js.map +1 -0
- package/dist/agent/sandbox/created-sandbox-registry.d.ts +15 -0
- package/dist/agent/sandbox/created-sandbox-registry.d.ts.map +1 -0
- package/dist/agent/sandbox/created-sandbox-registry.js +26 -0
- package/dist/agent/sandbox/created-sandbox-registry.js.map +1 -0
- package/dist/agent/sandbox/extend-workspace-time.d.ts +31 -0
- package/dist/agent/sandbox/extend-workspace-time.d.ts.map +1 -0
- package/dist/agent/sandbox/extend-workspace-time.js +63 -0
- package/dist/agent/sandbox/extend-workspace-time.js.map +1 -0
- package/dist/agent/sandbox/vercel-lifecycle.d.ts +38 -0
- package/dist/agent/sandbox/vercel-lifecycle.d.ts.map +1 -0
- package/dist/agent/sandbox/vercel-lifecycle.js +244 -0
- package/dist/agent/sandbox/vercel-lifecycle.js.map +1 -0
- package/package.json +204 -0
- package/tsconfig.build.json +22 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Gateway transport for the image describer — core owns the seam. Zero-data-retention is enforced AT THE
|
|
2
|
+
// GATEWAY by org policy; the call is fail-closed, reports its own spend, and must NOT stamp the model.
|
|
3
|
+
import { gateway, generateText } from "ai";
|
|
4
|
+
import { registerImageDescriber, } from "@open-everywhere/core/agent/adapter-api.js";
|
|
5
|
+
// The instruction: describe, transcribe on-image text, reply STRICT JSON. Kept here rather than in core
|
|
6
|
+
// because it is paired with THIS transport's message shape.
|
|
7
|
+
const VISION_PROMPT = "You are a vision assistant reducing an image to text for a text-only agent. Look at the " +
|
|
8
|
+
"image and reply with STRICT JSON only, no prose outside it: " +
|
|
9
|
+
'{"description": "<a plain, factual description of what the image shows>", ' +
|
|
10
|
+
'"ocr_text": "<ALL text visible in the image, transcribed verbatim; empty string if none>"}. ' +
|
|
11
|
+
"Describe only what is actually visible — never invent detail you cannot see.";
|
|
12
|
+
/**
|
|
13
|
+
* Tolerantly parse a vision completion into `{description, ocrText}`: the strict-JSON shape, else the whole
|
|
14
|
+
* completion as the description. Pure — exported for tests.
|
|
15
|
+
*/
|
|
16
|
+
export function parseVisionResult(text) {
|
|
17
|
+
const start = text.indexOf("{");
|
|
18
|
+
const end = text.lastIndexOf("}");
|
|
19
|
+
if (start !== -1 && end > start) {
|
|
20
|
+
try {
|
|
21
|
+
const o = JSON.parse(text.slice(start, end + 1));
|
|
22
|
+
const description = typeof o["description"] === "string" ? o["description"].trim() : "";
|
|
23
|
+
const ocrRaw = typeof o["ocr_text"] === "string" ? o["ocr_text"].trim() : "";
|
|
24
|
+
if (description.length > 0 || ocrRaw.length > 0) {
|
|
25
|
+
return { description: description.length > 0 ? description : "(no description returned)", ...(ocrRaw.length > 0 ? { ocrText: ocrRaw } : {}) };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
/* fall through to the raw-text fallback */
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const raw = text.trim();
|
|
33
|
+
return { description: raw.length > 0 ? raw : "(no description returned)" };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Wrap a failed vision call so the error NAMES THE MODEL ID this role asked for: a gateway refusal names only
|
|
37
|
+
* the provider, and the id lives in app config that neither the tool nor its audit row can see.
|
|
38
|
+
*/
|
|
39
|
+
export function visionCallError(id, err) {
|
|
40
|
+
return new Error(`vision model "${id}": ${err instanceof Error ? err.message : String(err)}`);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* What this call cost, reduced to the seam's usage shape. 🔴 The extraction rules are EVE'S, copied
|
|
44
|
+
* field-for-field: these rows sit in the same two tables as turn steps and are summed by the same caps.
|
|
45
|
+
*/
|
|
46
|
+
export function visionCallUsage(id, res) {
|
|
47
|
+
const u = res.usage;
|
|
48
|
+
const gw = (() => {
|
|
49
|
+
const raw = res.providerMetadata?.["gateway"];
|
|
50
|
+
return raw !== null && typeof raw === "object" && !Array.isArray(raw) ? raw : undefined;
|
|
51
|
+
})();
|
|
52
|
+
const costUsd = (() => {
|
|
53
|
+
const raw = gw?.["cost"];
|
|
54
|
+
if (typeof raw === "number" && Number.isFinite(raw))
|
|
55
|
+
return raw;
|
|
56
|
+
if (typeof raw === "string") {
|
|
57
|
+
const n = Number(raw);
|
|
58
|
+
if (Number.isFinite(n))
|
|
59
|
+
return n;
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
})();
|
|
63
|
+
const generationId = typeof gw?.["generationId"] === "string" && gw["generationId"].length > 0 ? gw["generationId"] : undefined;
|
|
64
|
+
// Finiteness-guarded, not merely typeof-guarded: `NaN` is a number, and every one of these
|
|
65
|
+
// lands in a column a cap sums. An unreadable count is dropped (the row then simply under-reports
|
|
66
|
+
// that dimension) rather than propagated as a value arithmetic cannot use.
|
|
67
|
+
const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : undefined);
|
|
68
|
+
const tok = {
|
|
69
|
+
inputTokens: num(u?.inputTokens),
|
|
70
|
+
outputTokens: num(u?.outputTokens),
|
|
71
|
+
cacheReadTokens: num(u?.inputTokenDetails?.cacheReadTokens),
|
|
72
|
+
cacheWriteTokens: num(u?.inputTokenDetails?.cacheWriteTokens),
|
|
73
|
+
// The REASONING dimension, and this is the one place OE can read it — eve's `extractStepUsage` never copies
|
|
74
|
+
// `outputTokenDetails.reasoningTokens`. Absent means unreported rather than zero, and it is NEVER priced.
|
|
75
|
+
reasoningTokens: num(u?.outputTokenDetails?.reasoningTokens),
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
model: id,
|
|
79
|
+
...(tok.inputTokens !== undefined ? { inputTokens: tok.inputTokens } : {}),
|
|
80
|
+
...(tok.outputTokens !== undefined ? { outputTokens: tok.outputTokens } : {}),
|
|
81
|
+
...(tok.cacheReadTokens !== undefined ? { cacheReadTokens: tok.cacheReadTokens } : {}),
|
|
82
|
+
...(tok.cacheWriteTokens !== undefined ? { cacheWriteTokens: tok.cacheWriteTokens } : {}),
|
|
83
|
+
...(tok.reasoningTokens !== undefined ? { reasoningTokens: tok.reasoningTokens } : {}),
|
|
84
|
+
...(costUsd !== undefined ? { costUsd } : {}),
|
|
85
|
+
...(generationId !== undefined ? { generationId } : {}),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** Build the gateway-backed ImageDescriber. A gateway/model error — including the gateway
|
|
89
|
+
* refusing to route the vision model under a ZDR-only org policy — propagates as a throw, and
|
|
90
|
+
* the tool's fail-closed contract turns it into "couldn't describe". */
|
|
91
|
+
export function gatewayImageDescriber(defaults) {
|
|
92
|
+
return {
|
|
93
|
+
async describe(req) {
|
|
94
|
+
let res;
|
|
95
|
+
try {
|
|
96
|
+
res = await generateText({
|
|
97
|
+
model: gateway(defaults.id),
|
|
98
|
+
messages: [
|
|
99
|
+
{
|
|
100
|
+
role: "user",
|
|
101
|
+
content: [
|
|
102
|
+
{ type: "text", text: req.hint ? `${VISION_PROMPT}\nContext hint: ${req.hint}` : VISION_PROMPT },
|
|
103
|
+
{ type: "image", image: req.bytes, mediaType: req.mimeType },
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
...(defaults.gateway !== undefined
|
|
108
|
+
? { providerOptions: { gateway: defaults.gateway } }
|
|
109
|
+
: {}),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
// Re-thrown with the model id prefixed (visionCallError) and nothing else changed: the
|
|
114
|
+
// tool's fail-closed contract is unaffected, the failure just becomes attributable.
|
|
115
|
+
throw visionCallError(defaults.id, err);
|
|
116
|
+
}
|
|
117
|
+
// The call's own accounting rides back with the result (OPE-403) — describe_image writes the
|
|
118
|
+
// attributed ledger + usage rows from it, because nothing else in the tree can see this call.
|
|
119
|
+
return { ...parseVisionResult(res.text), usage: visionCallUsage(defaults.id, res) };
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** Convenience for agent.ts: build + register the gateway image describer at boot. Without this
|
|
124
|
+
* call the `describe_image` tool has no backend and fails closed on every call (the agent says
|
|
125
|
+
* it can't see the image) — registration IS the "agent can see images" opt-in. */
|
|
126
|
+
export function registerGatewayImageDescriber(defaults) {
|
|
127
|
+
registerImageDescriber(gatewayImageDescriber(defaults));
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=gateway-vision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-vision.js","sourceRoot":"","sources":["../../../agent/model/gateway-vision.ts"],"names":[],"mappings":"AAAA,yGAAyG;AACzG,uGAAuG;AAEvG,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC3C,OAAO,EAKL,sBAAsB,GACvB,MAAM,4CAA4C,CAAC;AAapD,wGAAwG;AACxG,4DAA4D;AAC5D,MAAM,aAAa,GACjB,0FAA0F;IAC1F,8DAA8D;IAC9D,4EAA4E;IAC5E,8FAA8F;IAC9F,8EAA8E,CAAC;AAEjF;;;GAGG;AACH,MAAM,UAAU,iBA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BAC7G,CAAC,CAAC,EAAE,CAAC;iBACR,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,uFAAuF;gBACvF,oFAAoF;gBACpF,MAAM,eAAe,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;YAC1C,CAAC;YACD,6FAA6F;YAC7F,8FAA8F;YAC9F,OAAO,EAAE,GAAG,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC;QACtF,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;mFAEmF;AACnF,MAAM,UAAU,6BAA6B,CAAC,QAA+B;IAC3E,sBAAsB,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { gateway } from "ai";
|
|
2
|
+
import { type ModelRoute, type ModelBackend, type RoutedCallOptions } from "@open-everywhere/core/agent/adapter-api.js";
|
|
3
|
+
type GatewayModel = ReturnType<typeof gateway>;
|
|
4
|
+
/** Static defaults for one routed slot — mirrors what a plain string config said. */
|
|
5
|
+
export interface GatewayRoutedDefaults {
|
|
6
|
+
/** Default gateway model id (what unrouted channels use), e.g. "zai/glm-5.2". */
|
|
7
|
+
readonly id: string;
|
|
8
|
+
/**
|
|
9
|
+
* Gateway providerOptions applied when the CALL carries none — a floor, since turn calls carry their own.
|
|
10
|
+
* Any gateway option is forwarded verbatim; this mapping has no allow-list of keys.
|
|
11
|
+
*/
|
|
12
|
+
readonly gateway?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Map a route's provider hints onto one call's gateway options. Pure. A MODEL CHANGE strips the pin keys — a
|
|
16
|
+
* pin set for one model is broken for another — and a route's `providers` becomes `order`, never `only`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function applyGatewayOptions(route: ModelRoute, options: RoutedCallOptions, ids: {
|
|
19
|
+
readonly id: string;
|
|
20
|
+
readonly defaultId: string;
|
|
21
|
+
}, defaults?: Record<string, unknown>): RoutedCallOptions;
|
|
22
|
+
/** The gateway ModelBackend (see core ModelBackend). */
|
|
23
|
+
export declare function gatewayModelBackend(defaults?: Record<string, unknown>): ModelBackend<GatewayModel>;
|
|
24
|
+
/**
|
|
25
|
+
* A `step.started` dynamic-model resolver. It MUST be `step.started`: eve discards a model INSTANCE at turn
|
|
26
|
+
* scope. It ALWAYS returns a model, never null, and `event` carries the turn id this ctx does not.
|
|
27
|
+
*/
|
|
28
|
+
export declare function gatewayModelResolver(primary: GatewayRoutedDefaults): (event: unknown, ctx: unknown) => Promise<GatewayModel>;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=gateway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../../../agent/model/gateway.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAiB,MAAM,IAAI,CAAC;AAC5C,OAAO,EACL,KAAK,UAAU,EAEf,KAAK,YAAY,EACjB,KAAK,iBAAiB,EAGvB,MAAM,4CAA4C,CAAC;AAEpD,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC;AAY/C,qFAAqF;AACrF,MAAM,WAAW,qBAAqB;IACpC,iFAAiF;IACjF,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC5C;AAKD;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,iBAAiB,EAC1B,GAAG,EAAE;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,EACxD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,iBAAiB,CAanB;AAED,wDAAwD;AACxD,wBAAgB,mBAAmB,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,CAKlG;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,YAAY,CAAC,CAG5H"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// The Vercel AI Gateway model backend — the reference `ModelBackend`. Provider SELECTION is not pinned here:
|
|
2
|
+
// that is a gateway-operator concern, and `ModelRoute.providers` is only an optional per-route preference.
|
|
3
|
+
import { gateway, createGateway } from "ai";
|
|
4
|
+
import { liveIdentity, resolvePrimaryModel, } from "@open-everywhere/core/agent/adapter-api.js";
|
|
5
|
+
/**
|
|
6
|
+
* THE GATEWAY TARGET — `OE_AI_GATEWAY_URL`, read once at module load: a target that changed mid-process would
|
|
7
|
+
* send two calls in one turn to two providers. Unset ⇒ the plain `gateway` export, byte-identical.
|
|
8
|
+
*/
|
|
9
|
+
const GATEWAY_BASE_URL = process.env.OE_AI_GATEWAY_URL?.trim();
|
|
10
|
+
/** The gateway provider this backend resolves model ids through — retargeted only when
|
|
11
|
+
* {@link GATEWAY_BASE_URL} names a different host. */
|
|
12
|
+
const provider = GATEWAY_BASE_URL ? createGateway({ baseURL: GATEWAY_BASE_URL }) : gateway;
|
|
13
|
+
/** Gateway pin keys a route replaces — a pin belongs to the id it was set with. */
|
|
14
|
+
const PIN_KEYS = ["only", "order"];
|
|
15
|
+
/**
|
|
16
|
+
* Map a route's provider hints onto one call's gateway options. Pure. A MODEL CHANGE strips the pin keys — a
|
|
17
|
+
* pin set for one model is broken for another — and a route's `providers` becomes `order`, never `only`.
|
|
18
|
+
*/
|
|
19
|
+
export function applyGatewayOptions(route, options, ids, defaults) {
|
|
20
|
+
const base = (options.providerOptions?.gateway ?? defaults);
|
|
21
|
+
let gatewayOpts = base;
|
|
22
|
+
if (ids.id !== ids.defaultId && base !== undefined) {
|
|
23
|
+
gatewayOpts = { ...base };
|
|
24
|
+
for (const k of PIN_KEYS)
|
|
25
|
+
delete gatewayOpts[k];
|
|
26
|
+
}
|
|
27
|
+
if (route.providers !== undefined) {
|
|
28
|
+
gatewayOpts = { ...(gatewayOpts ?? {}), order: [...route.providers] };
|
|
29
|
+
delete gatewayOpts["only"];
|
|
30
|
+
}
|
|
31
|
+
if (gatewayOpts === undefined)
|
|
32
|
+
return options;
|
|
33
|
+
return { ...options, providerOptions: { ...options.providerOptions, gateway: gatewayOpts } };
|
|
34
|
+
}
|
|
35
|
+
/** The gateway ModelBackend (see core ModelBackend). */
|
|
36
|
+
export function gatewayModelBackend(defaults) {
|
|
37
|
+
return {
|
|
38
|
+
model: (id) => provider(id),
|
|
39
|
+
applyOptions: (route, options, ids) => applyGatewayOptions(route, options, ids, defaults),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A `step.started` dynamic-model resolver. It MUST be `step.started`: eve discards a model INSTANCE at turn
|
|
44
|
+
* scope. It ALWAYS returns a model, never null, and `event` carries the turn id this ctx does not.
|
|
45
|
+
*/
|
|
46
|
+
export function gatewayModelResolver(primary) {
|
|
47
|
+
const deps = { ...liveIdentity, backend: gatewayModelBackend(primary.gateway) };
|
|
48
|
+
return (event, ctx) => resolvePrimaryModel(ctx, { primary: { id: primary.id } }, deps, event);
|
|
49
|
+
}
|
|
50
|
+
// There is deliberately NO exported compaction model here. eve 0.38.3 cannot run an authored
|
|
51
|
+
// `compaction.model` under a dynamic agent model — it resolves the slot's reference through the
|
|
52
|
+
// AGENT-LEVEL `model` field and throws (OPE-670; the full chain is on `agent/agent.ts`'s
|
|
53
|
+
// `compaction` block). Compaction runs on the live turn model instead, which this file already
|
|
54
|
+
// serves through `gatewayModelResolver`.
|
|
55
|
+
//# sourceMappingURL=gateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../../../agent/model/gateway.ts"],"names":[],"mappings":"AAAA,6GAA6G;AAC7G,2GAA2G;AAE3G,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAC5C,OAAO,EAKL,YAAY,EACZ,mBAAmB,GACpB,MAAM,4CAA4C,CAAC;AAIpD;;;GAGG;AACH,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC;AAE/D;uDACuD;AACvD,MAAM,QAAQ,GAAG,gBAAgB,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AAa3F,mFAAmF;AACnF,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,OAAO,CAAU,CAAC;AAE5C;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAiB,EACjB,OAA0B,EAC1B,GAAwD,EACxD,QAAkC;IAElC,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,OAAO,IAAI,QAAQ,CAAwC,CAAC;IACnG,IAAI,WAAW,GAAG,IAAI,CAAC;IACvB,IAAI,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,SAAS,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACnD,WAAW,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC;QAC1B,KAAK,MAAM,CAAC,IAAI,QAAQ;YAAE,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC;IACD,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QAClC,WAAW,GAAG,EAAE,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;QACtE,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;IACD,IAAI,WAAW,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC;IAC9C,OAAO,EAAE,GAAG,OAAO,EAAE,eAAe,EAAE,EAAE,GAAG,OAAO,CAAC,eAAe,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,CAAC;AAC/F,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,mBAAmB,CAAC,QAAkC;IACpE,OAAO;QACL,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3B,YAAY,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC;KAC1F,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAA8B;IACjE,MAAM,IAAI,GAAG,EAAE,GAAG,YAAY,EAAE,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;IAChF,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,mBAAmB,CAAC,GAAsB,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AACnH,CAAC;AAED,6FAA6F;AAC7F,gGAAgG;AAChG,yFAAyF;AACzF,+FAA+F;AAC/F,yCAAyC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** The JSON provider-config block env var. */
|
|
2
|
+
export declare const OE_OAUTH_CONFIG_ENV = "OE_OAUTH_CONFIG";
|
|
3
|
+
/** The discovery + DCR + PKCE public-client dialect — the original and default mode. */
|
|
4
|
+
export declare const OE_OAUTH_MODE_DISCOVERY = "discovery-dcr-pkce";
|
|
5
|
+
/** The static confidential-client dialect (OPE-1086) — no discovery, no registration, HTTP Basic. */
|
|
6
|
+
export declare const OE_OAUTH_MODE_STATIC = "static-confidential";
|
|
7
|
+
/** How a static provider encodes its token-request body. Declared, never inferred: Notion's REST
|
|
8
|
+
* token endpoint takes JSON, the RFC 6749 default is form-encoded, and sending the wrong one reads
|
|
9
|
+
* as an authentication failure rather than as a shape error. */
|
|
10
|
+
export type OeOauthBodyEncoding = "json" | "form";
|
|
11
|
+
/** Fields every provider entry carries, whatever its mode. */
|
|
12
|
+
interface OeOauthProviderConfigBase {
|
|
13
|
+
/** The opaque connector id (the connection's providerRef, and this map's key). */
|
|
14
|
+
readonly ref: string;
|
|
15
|
+
/** Requested scopes (space-joined onto the authorization + token requests when present). */
|
|
16
|
+
readonly scopes?: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
/** A provider whose authorization server publishes RFC 8414 metadata and an RFC 7591 registration
|
|
19
|
+
* endpoint — the hosted-MCP shape the adapter was built for. */
|
|
20
|
+
export interface OeOauthDiscoveryProviderConfig extends OeOauthProviderConfigBase {
|
|
21
|
+
readonly mode: typeof OE_OAUTH_MODE_DISCOVERY;
|
|
22
|
+
/** The hosted-MCP server URL — discovery base + RFC 8707 resource indicator. */
|
|
23
|
+
readonly resource: string;
|
|
24
|
+
/** The `client_name` sent at Dynamic Client Registration (default "Open Everywhere"). */
|
|
25
|
+
readonly clientName?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A provider whose client is created BY A HUMAN in the vendor's developer portal, and authenticated
|
|
29
|
+
* as a CONFIDENTIAL client with a secret (OPE-1086). Nothing here is discovered at runtime.
|
|
30
|
+
*/
|
|
31
|
+
export interface OeOauthStaticProviderConfig extends OeOauthProviderConfigBase {
|
|
32
|
+
readonly mode: typeof OE_OAUTH_MODE_STATIC;
|
|
33
|
+
/** Where the human is sent to consent. HTTPS only. */
|
|
34
|
+
readonly authorizationEndpoint: string;
|
|
35
|
+
/** Where the code is exchanged and the refresh happens. HTTPS only. */
|
|
36
|
+
readonly tokenEndpoint: string;
|
|
37
|
+
/** RFC 7009 revocation, when the vendor offers one. ABSENT ⇒ a purge is local-only, exactly as it
|
|
38
|
+
* is for a discovered server that publishes no `revocation_endpoint`. Notion documents none. */
|
|
39
|
+
readonly revocationEndpoint?: string;
|
|
40
|
+
/** The client id from the vendor's developer portal. Not a secret — it rides the authorize URL. */
|
|
41
|
+
readonly clientId: string;
|
|
42
|
+
/** The credential-store REF of the client secret. NEVER the value. */
|
|
43
|
+
readonly clientSecretRef: string;
|
|
44
|
+
/** The broker the ref resolves through. Default "db" — the encrypted credential store. */
|
|
45
|
+
readonly clientSecretBroker: string;
|
|
46
|
+
/** Extra authorize-URL query parameters the vendor requires (Notion needs `owner=user`). The
|
|
47
|
+
* parameters this adapter sets itself are RESERVED and cannot be overridden here. */
|
|
48
|
+
readonly authorizeParams?: Readonly<Record<string, string>>;
|
|
49
|
+
/** Extra token-request headers the vendor requires (Notion needs `Notion-Version`). `authorization`
|
|
50
|
+
* is RESERVED — config may not replace the Basic credential. */
|
|
51
|
+
readonly tokenHeaders?: Readonly<Record<string, string>>;
|
|
52
|
+
/** How the token-request body is encoded. */
|
|
53
|
+
readonly bodyEncoding: OeOauthBodyEncoding;
|
|
54
|
+
}
|
|
55
|
+
/** One provider's OAuth target, in one of the two declared modes. */
|
|
56
|
+
export type OeOauthProviderConfig = OeOauthDiscoveryProviderConfig | OeOauthStaticProviderConfig;
|
|
57
|
+
/** Narrow a provider config to the static confidential-client mode. Reads the DECLARED `mode` and
|
|
58
|
+
* nothing else — never the presence of a field. */
|
|
59
|
+
export declare function isStaticConfidential(cfg: OeOauthProviderConfig): cfg is OeOauthStaticProviderConfig;
|
|
60
|
+
/** Truthiness for the master flag — same off-spellings as the connector flags (default OFF). */
|
|
61
|
+
export declare function oeOauthEnabled(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Load the provider config map from env, or `undefined` when no provider is configured (the
|
|
64
|
+
* "config-absent" path — combined with {@link oeOauthEnabled}, both must be truthy for the own-rolled
|
|
65
|
+
* OAuth layer to register). Explicit OE_OAUTH_CONFIG entries win over the notion shortcut.
|
|
66
|
+
*/
|
|
67
|
+
export declare function loadOeOauthConfig(): Map<string, OeOauthProviderConfig> | undefined;
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../agent/oe-oauth/config.ts"],"names":[],"mappings":"AAKA,8CAA8C;AAC9C,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAIrD,wFAAwF;AACxF,eAAO,MAAM,uBAAuB,uBAAuB,CAAC;AAC5D,qGAAqG;AACrG,eAAO,MAAM,oBAAoB,wBAAwB,CAAC;AAE1D;;iEAEiE;AACjE,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,MAAM,CAAC;AAElD,8DAA8D;AAC9D,UAAU,yBAAyB;IACjC,kFAAkF;IAClF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,4FAA4F;IAC5F,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAED;iEACiE;AACjE,MAAM,WAAW,8BAA+B,SAAQ,yBAAyB;IAC/E,QAAQ,CAAC,IAAI,EAAE,OAAO,uBAAuB,CAAC;IAC9C,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,yFAAyF;IACzF,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,2BAA4B,SAAQ,yBAAyB;IAC5E,QAAQ,CAAC,IAAI,EAAE,OAAO,oBAAoB,CAAC;IAC3C,sDAAsD;IACtD,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,uEAAuE;IACvE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B;qGACiG;IACjG,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,mGAAmG;IACnG,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,sEAAsE;IACtE,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,0FAA0F;IAC1F,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC;0FACsF;IACtF,QAAQ,CAAC,eAAe,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5D;qEACiE;IACjE,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACzD,6CAA6C;IAC7C,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAC;CAC5C;AAED,qEAAqE;AACrE,MAAM,MAAM,qBAAqB,GAAG,8BAA8B,GAAG,2BAA2B,CAAC;AAEjG;oDACoD;AACpD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,qBAAqB,GAAG,GAAG,IAAI,2BAA2B,CAEnG;AAED,gGAAgG;AAChG,wBAAgB,cAAc,IAAI,OAAO,CAKxC;AAoJD;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,GAAG,SAAS,CAUlF"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// The `oe-oauth` master flag and provider config, env-sourced. 🔴 The client SECRET is a REF — a literal in
|
|
2
|
+
// the JSON is REFUSED. ⚠️ A map key must equal the credential home's ref, or the click dies late, at DCR.
|
|
3
|
+
/** The master arming flag env var — one string this module's readers share. */
|
|
4
|
+
const OE_OAUTH_ENABLED_ENV = "OE_OAUTH_ENABLED";
|
|
5
|
+
/** The JSON provider-config block env var. */
|
|
6
|
+
export const OE_OAUTH_CONFIG_ENV = "OE_OAUTH_CONFIG";
|
|
7
|
+
/** Convenience: a `notion` provider's resource (mcp.notion.com), without hand-writing the JSON. */
|
|
8
|
+
const OE_OAUTH_NOTION_RESOURCE_ENV = "OE_OAUTH_NOTION_RESOURCE";
|
|
9
|
+
/** The discovery + DCR + PKCE public-client dialect — the original and default mode. */
|
|
10
|
+
export const OE_OAUTH_MODE_DISCOVERY = "discovery-dcr-pkce";
|
|
11
|
+
/** The static confidential-client dialect (OPE-1086) — no discovery, no registration, HTTP Basic. */
|
|
12
|
+
export const OE_OAUTH_MODE_STATIC = "static-confidential";
|
|
13
|
+
/** Narrow a provider config to the static confidential-client mode. Reads the DECLARED `mode` and
|
|
14
|
+
* nothing else — never the presence of a field. */
|
|
15
|
+
export function isStaticConfidential(cfg) {
|
|
16
|
+
return cfg.mode === OE_OAUTH_MODE_STATIC;
|
|
17
|
+
}
|
|
18
|
+
/** Truthiness for the master flag — same off-spellings as the connector flags (default OFF). */
|
|
19
|
+
export function oeOauthEnabled() {
|
|
20
|
+
const raw = process.env[OE_OAUTH_ENABLED_ENV];
|
|
21
|
+
if (raw === undefined)
|
|
22
|
+
return false;
|
|
23
|
+
const v = raw.trim().toLowerCase();
|
|
24
|
+
return v !== "" && v !== "0" && v !== "false" && v !== "off" && v !== "no";
|
|
25
|
+
}
|
|
26
|
+
/** Authorize-URL parameters this adapter composes itself. A config entry that named one of these
|
|
27
|
+
* could point the consent at another client id or another redirect target, so the parser refuses
|
|
28
|
+
* them instead of letting the last writer win. */
|
|
29
|
+
const RESERVED_AUTHORIZE_PARAMS = new Set(["response_type", "client_id", "redirect_uri", "state", "scope", "code_challenge", "code_challenge_method"]);
|
|
30
|
+
function requireString(v, where) {
|
|
31
|
+
if (typeof v !== "string" || v.trim() === "")
|
|
32
|
+
throw new Error(`${where} must be a non-empty string.`);
|
|
33
|
+
return v.trim();
|
|
34
|
+
}
|
|
35
|
+
/** An endpoint must be an absolute HTTPS URL. A client secret rides these requests in an
|
|
36
|
+
* `Authorization` header, so `http:` would put it on the wire in the clear, and a relative value
|
|
37
|
+
* would resolve against whatever base the runtime happened to have. */
|
|
38
|
+
function requireHttpsUrl(v, where) {
|
|
39
|
+
const raw = requireString(v, where);
|
|
40
|
+
let parsed;
|
|
41
|
+
try {
|
|
42
|
+
parsed = new URL(raw);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
throw new Error(`${where} must be an absolute URL (got ${JSON.stringify(raw)}).`);
|
|
46
|
+
}
|
|
47
|
+
if (parsed.protocol !== "https:") {
|
|
48
|
+
throw new Error(`${where} must use https — a confidential client presents its secret on this request, so ${JSON.stringify(parsed.protocol)} is refused.`);
|
|
49
|
+
}
|
|
50
|
+
return raw;
|
|
51
|
+
}
|
|
52
|
+
function optionalStringMap(v, where) {
|
|
53
|
+
if (v === undefined)
|
|
54
|
+
return undefined;
|
|
55
|
+
if (typeof v !== "object" || v === null || Array.isArray(v))
|
|
56
|
+
throw new Error(`${where} must be a JSON object of string values.`);
|
|
57
|
+
const out = {};
|
|
58
|
+
for (const [k, raw] of Object.entries(v)) {
|
|
59
|
+
if (typeof raw !== "string")
|
|
60
|
+
throw new Error(`${where}["${k}"] must be a string.`);
|
|
61
|
+
out[k] = raw;
|
|
62
|
+
}
|
|
63
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
64
|
+
}
|
|
65
|
+
function parseScopes(v) {
|
|
66
|
+
const scopes = Array.isArray(v) ? v.filter((s) => typeof s === "string") : undefined;
|
|
67
|
+
return scopes && scopes.length ? scopes : undefined;
|
|
68
|
+
}
|
|
69
|
+
/** Parse ONE `static-confidential` entry, with every refusal stated. */
|
|
70
|
+
function parseStaticProvider(ref, rec) {
|
|
71
|
+
const where = `${OE_OAUTH_CONFIG_ENV}["${ref}"]`;
|
|
72
|
+
// 🔴 A LITERAL SECRET IS REFUSED, NOT ACCEPTED. See the module header: this block is an env var.
|
|
73
|
+
if ("clientSecret" in rec) {
|
|
74
|
+
throw new Error(`${where} carries a literal "clientSecret". The client secret must NEVER live in this config block — ` +
|
|
75
|
+
`store it in the credential store and name it with "clientSecretRef" (for example "db:notion:rest-client-secret").`);
|
|
76
|
+
}
|
|
77
|
+
const authorizeParams = optionalStringMap(rec.authorizeParams, `${where}.authorizeParams`);
|
|
78
|
+
for (const name of Object.keys(authorizeParams ?? {})) {
|
|
79
|
+
if (RESERVED_AUTHORIZE_PARAMS.has(name.toLowerCase())) {
|
|
80
|
+
throw new Error(`${where}.authorizeParams may not set "${name}" — the adapter composes that parameter itself.`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const tokenHeaders = optionalStringMap(rec.tokenHeaders, `${where}.tokenHeaders`);
|
|
84
|
+
for (const name of Object.keys(tokenHeaders ?? {})) {
|
|
85
|
+
if (name.toLowerCase() === "authorization") {
|
|
86
|
+
throw new Error(`${where}.tokenHeaders may not set "${name}" — that header carries the confidential client's Basic credential.`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const bodyEncoding = requireString(rec.bodyEncoding, `${where}.bodyEncoding`);
|
|
90
|
+
if (bodyEncoding !== "json" && bodyEncoding !== "form") {
|
|
91
|
+
throw new Error(`${where}.bodyEncoding must be "json" or "form" — the dialect is declared, not guessed.`);
|
|
92
|
+
}
|
|
93
|
+
const revocationEndpoint = rec.revocationEndpoint === undefined ? undefined : requireHttpsUrl(rec.revocationEndpoint, `${where}.revocationEndpoint`);
|
|
94
|
+
const scopes = parseScopes(rec.scopes);
|
|
95
|
+
return {
|
|
96
|
+
mode: OE_OAUTH_MODE_STATIC,
|
|
97
|
+
ref,
|
|
98
|
+
authorizationEndpoint: requireHttpsUrl(rec.authorizationEndpoint, `${where}.authorizationEndpoint`),
|
|
99
|
+
tokenEndpoint: requireHttpsUrl(rec.tokenEndpoint, `${where}.tokenEndpoint`),
|
|
100
|
+
...(revocationEndpoint ? { revocationEndpoint } : {}),
|
|
101
|
+
clientId: requireString(rec.clientId, `${where}.clientId`),
|
|
102
|
+
clientSecretRef: requireString(rec.clientSecretRef, `${where}.clientSecretRef`),
|
|
103
|
+
clientSecretBroker: rec.clientSecretBroker === undefined ? "db" : requireString(rec.clientSecretBroker, `${where}.clientSecretBroker`),
|
|
104
|
+
...(authorizeParams ? { authorizeParams } : {}),
|
|
105
|
+
...(tokenHeaders ? { tokenHeaders } : {}),
|
|
106
|
+
bodyEncoding,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/** Parse ONE `discovery-dcr-pkce` entry. */
|
|
110
|
+
function parseDiscoveryProvider(ref, rec) {
|
|
111
|
+
const where = `${OE_OAUTH_CONFIG_ENV}["${ref}"]`;
|
|
112
|
+
const resource = typeof rec.resource === "string" ? rec.resource.trim() : "";
|
|
113
|
+
if (!resource)
|
|
114
|
+
throw new Error(`${where} is missing a string "resource".`);
|
|
115
|
+
const scopes = parseScopes(rec.scopes);
|
|
116
|
+
return {
|
|
117
|
+
mode: OE_OAUTH_MODE_DISCOVERY,
|
|
118
|
+
ref,
|
|
119
|
+
resource,
|
|
120
|
+
...(scopes ? { scopes } : {}),
|
|
121
|
+
...(typeof rec.clientName === "string" && rec.clientName.trim() ? { clientName: rec.clientName.trim() } : {}),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function parseJsonConfig(raw) {
|
|
125
|
+
const out = new Map();
|
|
126
|
+
let obj;
|
|
127
|
+
try {
|
|
128
|
+
obj = JSON.parse(raw);
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
throw new Error(`${OE_OAUTH_CONFIG_ENV} is not valid JSON — expected {"<ref>":{"resource":"..."}}.`);
|
|
132
|
+
}
|
|
133
|
+
if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
|
|
134
|
+
throw new Error(`${OE_OAUTH_CONFIG_ENV} must be a JSON object mapping provider ref → one provider entry.`);
|
|
135
|
+
}
|
|
136
|
+
for (const [ref, v] of Object.entries(obj)) {
|
|
137
|
+
if (typeof v !== "object" || v === null)
|
|
138
|
+
continue;
|
|
139
|
+
const rec = v;
|
|
140
|
+
// The MODE decides how the rest is read. An absent `mode` is the discovery dialect, which is
|
|
141
|
+
// what every entry authored before OPE-1086 means. An unknown one is refused rather than
|
|
142
|
+
// defaulted: silently reading a mistyped mode as the public-client flow would drop the client
|
|
143
|
+
// secret and the Basic authentication without saying so.
|
|
144
|
+
const mode = rec.mode === undefined ? OE_OAUTH_MODE_DISCOVERY : rec.mode;
|
|
145
|
+
if (mode === OE_OAUTH_MODE_STATIC) {
|
|
146
|
+
out.set(ref, parseStaticProvider(ref, rec));
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (mode !== OE_OAUTH_MODE_DISCOVERY) {
|
|
150
|
+
throw new Error(`${OE_OAUTH_CONFIG_ENV}["${ref}"].mode ${JSON.stringify(mode)} is not a known oe-oauth mode — use "${OE_OAUTH_MODE_DISCOVERY}" or "${OE_OAUTH_MODE_STATIC}".`);
|
|
151
|
+
}
|
|
152
|
+
const parsed = parseDiscoveryProvider(ref, rec);
|
|
153
|
+
// A discovery entry that also carries confidential-client fields is a MIS-DECLARED entry, not a
|
|
154
|
+
// static one. Refusing it here is the whole "declared, not sniffed" rule in one place: the
|
|
155
|
+
// adapter will not promote an entry to the confidential mode because it looks like one.
|
|
156
|
+
for (const field of ["clientId", "clientSecretRef", "clientSecret", "tokenEndpoint", "authorizationEndpoint"]) {
|
|
157
|
+
if (field in rec) {
|
|
158
|
+
throw new Error(`${OE_OAUTH_CONFIG_ENV}["${ref}"] carries "${field}" but declares no mode, so it reads as "${OE_OAUTH_MODE_DISCOVERY}" ` +
|
|
159
|
+
`(discovery + dynamic registration + PKCE), which ignores that field. Add "mode": "${OE_OAUTH_MODE_STATIC}" if that is what you meant.`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
out.set(ref, parsed);
|
|
163
|
+
}
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Load the provider config map from env, or `undefined` when no provider is configured (the
|
|
168
|
+
* "config-absent" path — combined with {@link oeOauthEnabled}, both must be truthy for the own-rolled
|
|
169
|
+
* OAuth layer to register). Explicit OE_OAUTH_CONFIG entries win over the notion shortcut.
|
|
170
|
+
*/
|
|
171
|
+
export function loadOeOauthConfig() {
|
|
172
|
+
const providers = new Map();
|
|
173
|
+
const notionResource = process.env[OE_OAUTH_NOTION_RESOURCE_ENV]?.trim();
|
|
174
|
+
if (notionResource)
|
|
175
|
+
providers.set("notion", { mode: OE_OAUTH_MODE_DISCOVERY, ref: "notion", resource: notionResource });
|
|
176
|
+
const rawJson = process.env[OE_OAUTH_CONFIG_ENV]?.trim();
|
|
177
|
+
if (rawJson)
|
|
178
|
+
for (const [ref, cfg] of parseJsonConfig(rawJson))
|
|
179
|
+
providers.set(ref, cfg);
|
|
180
|
+
return providers.size > 0 ? providers : undefined;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../agent/oe-oauth/config.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,0GAA0G;AAE1G,+EAA+E;AAC/E,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AAChD,8CAA8C;AAC9C,MAAM,CAAC,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AACrD,mGAAmG;AACnG,MAAM,4BAA4B,GAAG,0BAA0B,CAAC;AAEhE,wFAAwF;AACxF,MAAM,CAAC,MAAM,uBAAuB,GAAG,oBAAoB,CAAC;AAC5D,qGAAqG;AACrG,MAAM,CAAC,MAAM,oBAAoB,GAAG,qBAAqB,CAAC;AAyD1D;oDACoD;AACpD,MAAM,UAAU,oBAAoB,CAAC,GAA0B;IAC7D,OAAO,GAAG,CAAC,IAAI,KAAK,oBAAoB,CAAC;AAC3C,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,cAAc;IAC5B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IAC9C,IAAI,GAAG,KA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C,QAAQ,EAAE,EAAE,IAAI,EAAE,uBAAuB,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC,CAAC;IAExH,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAE,IAAI,EAAE,CAAC;IACzD,IAAI,OAAO;QAAE,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,eAAe,CAAC,OAAO,CAAC;YAAE,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAExF,OAAO,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** The subject an error is about, as a log-safe label (never an opaque token). */
|
|
2
|
+
export declare function subjectLabel(subject: {
|
|
3
|
+
readonly type: "user";
|
|
4
|
+
readonly id: string;
|
|
5
|
+
} | {
|
|
6
|
+
readonly type: "app";
|
|
7
|
+
}): string;
|
|
8
|
+
/** The human has NEVER authorized this (provider, subject) — no token is stored. The connector plane
|
|
9
|
+
* turns this into a fresh consent link. */
|
|
10
|
+
export declare class OeOauthNeedsConsentError extends Error {
|
|
11
|
+
readonly code = "oe_oauth_needs_consent";
|
|
12
|
+
constructor(providerRef: string, subject: {
|
|
13
|
+
readonly type: "user";
|
|
14
|
+
readonly id: string;
|
|
15
|
+
} | {
|
|
16
|
+
readonly type: "app";
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/** A previously-working authorization is dead (refresh token rejected / rotated away) — the human
|
|
20
|
+
* must RE-authorize. Distinct from needs-consent so the audit trail can tell a first connect from a
|
|
21
|
+
* lapsed one, but both classify as "user authorization required". */
|
|
22
|
+
export declare class OeOauthNeedsReconsentError extends Error {
|
|
23
|
+
readonly code = "oe_oauth_needs_reconsent";
|
|
24
|
+
constructor(providerRef: string, subject: {
|
|
25
|
+
readonly type: "user";
|
|
26
|
+
readonly id: string;
|
|
27
|
+
} | {
|
|
28
|
+
readonly type: "app";
|
|
29
|
+
}, why: string);
|
|
30
|
+
}
|
|
31
|
+
/** The cross-process single-flight LOSER timed out (OPE-91): another instance holds the refresh claim
|
|
32
|
+
* and did not release a rotated token within this caller's wait budget. TRANSIENT and RETRYABLE — a
|
|
33
|
+
* fresh request may win the claim or find the rotated token — so it is DELIBERATELY not classified as
|
|
34
|
+
* user-auth-required (the human need do nothing; nothing is re-consented). Carries no secret material,
|
|
35
|
+
* only the provider ref + subject label. */
|
|
36
|
+
export declare class OeOauthRefreshContendedError extends Error {
|
|
37
|
+
readonly code = "oe_oauth_refresh_contended";
|
|
38
|
+
constructor(providerRef: string, subject: {
|
|
39
|
+
readonly type: "user";
|
|
40
|
+
readonly id: string;
|
|
41
|
+
} | {
|
|
42
|
+
readonly type: "app";
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** A generic upstream OAuth failure (token endpoint / discovery / DCR returned an error). `oauthError`
|
|
46
|
+
* is the RFC 6749 `error` code when the body carried one (e.g. "invalid_grant", "invalid_client") —
|
|
47
|
+
* a fixed-vocabulary string, never a secret. */
|
|
48
|
+
export declare class OeOauthError extends Error {
|
|
49
|
+
readonly code = "oe_oauth_error";
|
|
50
|
+
readonly oauthError?: string;
|
|
51
|
+
readonly httpStatus?: number;
|
|
52
|
+
constructor(message: string, opts?: {
|
|
53
|
+
readonly oauthError?: string;
|
|
54
|
+
readonly httpStatus?: number;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** True iff `e` is an upstream OAuth failure whose `error` code is `invalid_grant` (the refresh token
|
|
58
|
+
* was rejected — consumed by a rotation, revoked, or expired). Duck-typed for cross-process safety. */
|
|
59
|
+
export declare function isInvalidGrant(e: unknown): boolean;
|
|
60
|
+
/** The connector-plane classifier (used by UserAuthFlowProvider.isUserAuthRequired). Duck-typed on
|
|
61
|
+
* the stable `code` strings so a cross-process instance still matches. */
|
|
62
|
+
export declare function isUserAuthRequiredError(e: unknown): boolean;
|
|
63
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../agent/oe-oauth/errors.ts"],"names":[],"mappings":"AAGA,kFAAkF;AAClF,wBAAgB,YAAY,CAAC,OAAO,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;CAAE,GAAG,MAAM,CAEvH;AAED;4CAC4C;AAC5C,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,QAAQ,CAAC,IAAI,4BAA4B;IACzC,YAAY,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;KAAE,EAGlH;CACF;AAED;;sEAEsE;AACtE,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,QAAQ,CAAC,IAAI,8BAA8B;IAC3C,YAAY,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;KAAE,EAAE,GAAG,EAAE,MAAM,EAG/H;CACF;AAED;;;;6CAI6C;AAC7C,qBAAa,4BAA6B,SAAQ,KAAK;IACrD,QAAQ,CAAC,IAAI,gCAAgC;IAC7C,YAAY,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,EAAE,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