@vymalo/opencode-oauth2 0.11.0 → 0.14.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.
Files changed (57) hide show
  1. package/dist/cache.d.ts +6 -6
  2. package/dist/cache.js +100 -104
  3. package/dist/cache.js.map +1 -1
  4. package/dist/config.d.ts +107 -107
  5. package/dist/config.js +173 -182
  6. package/dist/config.js.map +1 -1
  7. package/dist/index.js +1 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib.js +1 -0
  10. package/dist/lib.js.map +1 -1
  11. package/dist/logging.d.ts +6 -6
  12. package/dist/logging.js +57 -56
  13. package/dist/logging.js.map +1 -1
  14. package/dist/model-discovery.d.ts +3 -3
  15. package/dist/model-discovery.js +61 -66
  16. package/dist/model-discovery.js.map +1 -1
  17. package/dist/model-normalization.js +84 -73
  18. package/dist/model-normalization.js.map +1 -1
  19. package/dist/oauth/browser.js +29 -25
  20. package/dist/oauth/browser.js.map +1 -1
  21. package/dist/oauth/client.d.ts +46 -46
  22. package/dist/oauth/client.js +411 -430
  23. package/dist/oauth/client.js.map +1 -1
  24. package/dist/oauth/device-code.d.ts +23 -23
  25. package/dist/oauth/device-code.js +225 -235
  26. package/dist/oauth/device-code.js.map +1 -1
  27. package/dist/oauth/discovery.d.ts +5 -5
  28. package/dist/oauth/discovery.js +34 -34
  29. package/dist/oauth/discovery.js.map +1 -1
  30. package/dist/oauth/http-utils.d.ts +27 -27
  31. package/dist/oauth/http-utils.js +96 -107
  32. package/dist/oauth/http-utils.js.map +1 -1
  33. package/dist/oauth/local-callback.d.ts +5 -5
  34. package/dist/oauth/local-callback.js +76 -74
  35. package/dist/oauth/local-callback.js.map +1 -1
  36. package/dist/oauth/pkce.d.ts +2 -2
  37. package/dist/oauth/pkce.js +9 -5
  38. package/dist/oauth/pkce.js.map +1 -1
  39. package/dist/oauth/subject-token.d.ts +15 -15
  40. package/dist/oauth/subject-token.js +68 -73
  41. package/dist/oauth/subject-token.js.map +1 -1
  42. package/dist/opencode.d.ts +15 -15
  43. package/dist/opencode.js +477 -497
  44. package/dist/opencode.js.map +1 -1
  45. package/dist/plugin.d.ts +39 -39
  46. package/dist/plugin.js +270 -277
  47. package/dist/plugin.js.map +1 -1
  48. package/dist/responses-repair.d.ts +12 -35
  49. package/dist/responses-repair.js +119 -125
  50. package/dist/responses-repair.js.map +1 -1
  51. package/dist/scheduler.d.ts +5 -5
  52. package/dist/scheduler.js +43 -45
  53. package/dist/scheduler.js.map +1 -1
  54. package/dist/types.d.ts +25 -25
  55. package/dist/types.js +1 -0
  56. package/dist/types.js.map +1 -1
  57. package/package.json +3 -3
package/dist/cache.d.ts CHANGED
@@ -2,10 +2,10 @@ import type { Logger } from "./logging.js";
2
2
  import type { CachedServerState } from "./types.js";
3
3
  export declare function resolveCacheDir(namespace: string): string;
4
4
  export declare class FileCacheStore {
5
- private readonly baseDir;
6
- private readonly logger?;
7
- constructor(baseDir: string, logger?: Logger | undefined);
8
- ensureReady(): Promise<void>;
9
- loadServerState(serverId: string): Promise<CachedServerState | undefined>;
10
- saveServerState(state: CachedServerState): Promise<void>;
5
+ private readonly baseDir;
6
+ private readonly logger?;
7
+ constructor(baseDir: string, logger?: Logger | undefined);
8
+ ensureReady(): Promise<void>;
9
+ loadServerState(serverId: string): Promise<CachedServerState | undefined>;
10
+ saveServerState(state: CachedServerState): Promise<void>;
11
11
  }
package/dist/cache.js CHANGED
@@ -4,117 +4,113 @@ import { randomUUID } from "node:crypto";
4
4
  import { dirname, join } from "node:path";
5
5
  import { homedir } from "node:os";
6
6
  function resolveDefaultCacheRoot() {
7
- if (process.platform === "win32") {
8
- return process.env.LOCALAPPDATA ?? join(homedir(), "AppData", "Local");
9
- }
10
- if (process.platform === "darwin") {
11
- return join(homedir(), "Library", "Caches");
12
- }
13
- return process.env.XDG_CACHE_HOME ?? join(homedir(), ".cache");
7
+ if (process.platform === "win32") {
8
+ return process.env.LOCALAPPDATA ?? join(homedir(), "AppData", "Local");
9
+ }
10
+ if (process.platform === "darwin") {
11
+ return join(homedir(), "Library", "Caches");
12
+ }
13
+ return process.env.XDG_CACHE_HOME ?? join(homedir(), ".cache");
14
14
  }
15
15
  export function resolveCacheDir(namespace) {
16
- return join(resolveDefaultCacheRoot(), "opencode-oauth2", namespace);
16
+ return join(resolveDefaultCacheRoot(), "opencode-oauth2", namespace);
17
17
  }
18
18
  function statePath(baseDir, serverId) {
19
- return join(baseDir, `${serverId}.json`);
19
+ return join(baseDir, `${serverId}.json`);
20
20
  }
21
21
  function hasValidTokenShape(token) {
22
- if (!token || typeof token !== "object" || Array.isArray(token)) {
23
- return false;
24
- }
25
- const candidate = token;
26
- if (typeof candidate.accessToken !== "string" ||
27
- candidate.accessToken.length === 0 ||
28
- typeof candidate.tokenType !== "string" ||
29
- candidate.tokenType.length === 0) {
30
- return false;
31
- }
32
- // refreshToken is optional: client_credentials grant never returns one.
33
- // When present, it must be a non-empty string.
34
- if (candidate.refreshToken !== undefined) {
35
- return typeof candidate.refreshToken === "string" && candidate.refreshToken.length > 0;
36
- }
37
- return true;
22
+ if (!token || typeof token !== "object" || Array.isArray(token)) {
23
+ return false;
24
+ }
25
+ const candidate = token;
26
+ if (typeof candidate.accessToken !== "string" || candidate.accessToken.length === 0 || typeof candidate.tokenType !== "string" || candidate.tokenType.length === 0) {
27
+ return false;
28
+ }
29
+ // refreshToken is optional: client_credentials grant never returns one.
30
+ // When present, it must be a non-empty string.
31
+ if (candidate.refreshToken !== undefined) {
32
+ return typeof candidate.refreshToken === "string" && candidate.refreshToken.length > 0;
33
+ }
34
+ return true;
38
35
  }
39
36
  export class FileCacheStore {
40
- baseDir;
41
- logger;
42
- constructor(baseDir, logger) {
43
- this.baseDir = baseDir;
44
- this.logger = logger;
45
- }
46
- async ensureReady() {
47
- await mkdir(this.baseDir, { recursive: true, mode: 0o700 });
48
- }
49
- async loadServerState(serverId) {
50
- const filePath = statePath(this.baseDir, serverId);
51
- try {
52
- const content = await readFile(filePath, "utf8");
53
- const parsed = JSON.parse(content);
54
- if (!parsed || parsed.serverId !== serverId) {
55
- return undefined;
56
- }
57
- if (!Array.isArray(parsed.models) || !Array.isArray(parsed.rawModels)) {
58
- return undefined;
59
- }
60
- if (parsed.token && !hasValidTokenShape(parsed.token)) {
61
- this.logger?.trace("oauth2_cache_token_dropped_invalid_shape", { serverId });
62
- parsed.token = undefined;
63
- }
64
- this.logger?.trace("oauth2_cache_file_read", {
65
- serverId,
66
- modelCount: Array.isArray(parsed.models) ? parsed.models.length : 0,
67
- hasToken: Boolean(parsed.token)
68
- });
69
- return parsed;
70
- }
71
- catch (error) {
72
- if (typeof error === "object" &&
73
- error &&
74
- "code" in error &&
75
- error.code === "ENOENT") {
76
- this.logger?.trace("oauth2_cache_file_missing", { serverId });
77
- return undefined;
78
- }
79
- throw error;
80
- }
81
- }
82
- async saveServerState(state) {
83
- const filePath = statePath(this.baseDir, state.serverId);
84
- // Unique per-write temp name. A shared `${filePath}.tmp` collides when
85
- // several opencode instances boot at once (the desktop app restores every
86
- // project window in parallel) and all sync the same provider: one process'
87
- // rename consumes the temp file the other is about to rename, surfacing as
88
- // `sync_failed ENOENT rename '<serverId>.json.tmp' -> '<serverId>.json'`.
89
- // pid + uuid makes each writer's temp file private; rename stays atomic so
90
- // last-writer-wins on the final path. See docs/troubleshooting.md.
91
- const tempPath = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
92
- await mkdir(dirname(filePath), { recursive: true, mode: 0o700 });
93
- const serialized = JSON.stringify(state, null, 2);
94
- try {
95
- await writeFile(tempPath, serialized, {
96
- encoding: "utf8",
97
- mode: 0o600,
98
- flag: fsConstants.O_CREAT | fsConstants.O_TRUNC | fsConstants.O_WRONLY
99
- });
100
- await rename(tempPath, filePath);
101
- this.logger?.trace("oauth2_cache_file_written", {
102
- serverId: state.serverId,
103
- modelCount: Array.isArray(state.models) ? state.models.length : 0,
104
- hasToken: Boolean(state.token)
105
- });
106
- }
107
- catch (error) {
108
- // Best-effort cleanup so a failed write never strands an orphan temp file.
109
- await unlink(tempPath).catch(() => { });
110
- throw error;
111
- }
112
- try {
113
- await chmod(filePath, 0o600);
114
- }
115
- catch {
116
- // Some filesystems may ignore chmod semantics; keep operation non-fatal.
117
- }
118
- }
37
+ baseDir;
38
+ logger;
39
+ constructor(baseDir, logger) {
40
+ this.baseDir = baseDir;
41
+ this.logger = logger;
42
+ }
43
+ async ensureReady() {
44
+ await mkdir(this.baseDir, {
45
+ recursive: true,
46
+ mode: 448
47
+ });
48
+ }
49
+ async loadServerState(serverId) {
50
+ const filePath = statePath(this.baseDir, serverId);
51
+ try {
52
+ const content = await readFile(filePath, "utf8");
53
+ const parsed = JSON.parse(content);
54
+ if (!parsed || parsed.serverId !== serverId) {
55
+ return undefined;
56
+ }
57
+ if (!Array.isArray(parsed.models) || !Array.isArray(parsed.rawModels)) {
58
+ return undefined;
59
+ }
60
+ if (parsed.token && !hasValidTokenShape(parsed.token)) {
61
+ this.logger?.trace("oauth2_cache_token_dropped_invalid_shape", { serverId });
62
+ parsed.token = undefined;
63
+ }
64
+ this.logger?.trace("oauth2_cache_file_read", {
65
+ serverId,
66
+ modelCount: Array.isArray(parsed.models) ? parsed.models.length : 0,
67
+ hasToken: Boolean(parsed.token)
68
+ });
69
+ return parsed;
70
+ } catch (error) {
71
+ if (typeof error === "object" && error && "code" in error && error.code === "ENOENT") {
72
+ this.logger?.trace("oauth2_cache_file_missing", { serverId });
73
+ return undefined;
74
+ }
75
+ throw error;
76
+ }
77
+ }
78
+ async saveServerState(state) {
79
+ const filePath = statePath(this.baseDir, state.serverId);
80
+ // Unique per-write temp name. A shared `${filePath}.tmp` collides when
81
+ // several opencode instances boot at once (the desktop app restores every
82
+ // project window in parallel) and all sync the same provider: one process'
83
+ // rename consumes the temp file the other is about to rename, surfacing as
84
+ // `sync_failed ENOENT rename '<serverId>.json.tmp' -> '<serverId>.json'`.
85
+ // pid + uuid makes each writer's temp file private; rename stays atomic so
86
+ // last-writer-wins on the final path. See docs/troubleshooting.md.
87
+ const tempPath = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
88
+ await mkdir(dirname(filePath), {
89
+ recursive: true,
90
+ mode: 448
91
+ });
92
+ const serialized = JSON.stringify(state, null, 2);
93
+ try {
94
+ await writeFile(tempPath, serialized, {
95
+ encoding: "utf8",
96
+ mode: 384,
97
+ flag: fsConstants.O_CREAT | fsConstants.O_TRUNC | fsConstants.O_WRONLY
98
+ });
99
+ await rename(tempPath, filePath);
100
+ this.logger?.trace("oauth2_cache_file_written", {
101
+ serverId: state.serverId,
102
+ modelCount: Array.isArray(state.models) ? state.models.length : 0,
103
+ hasToken: Boolean(state.token)
104
+ });
105
+ } catch (error) {
106
+ // Best-effort cleanup so a failed write never strands an orphan temp file.
107
+ await unlink(tempPath).catch(() => {});
108
+ throw error;
109
+ }
110
+ try {
111
+ await chmod(filePath, 384);
112
+ } catch {}
113
+ }
119
114
  }
115
+
120
116
  //# sourceMappingURL=cache.js.map
package/dist/cache.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrF,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAKlC,SAAS,uBAAuB;IAC9B,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,OAAO,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACzE,CAAC;IAED,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d,IACE,OAAO,UAAU,YACjB,SACA,UAAU,SACT,MAA2B,SAAS,UACrC;IACA,KAAK,QAAQ,MAAM,6BAA6B,EAAE,SAAS,CAAC;IAC5D,OAAO;GACT;GACA,MAAM;EACR;CACF;CAEA,MAAM,gBAAgB,OAAyC;EAC7D,MAAM,WAAW,UAAU,KAAK,SAAS,MAAM,QAAQ;;;;;;;;EAQvD,MAAM,WAAW,GAAG,SAAS,GAAG,QAAQ,IAAI,GAAG,WAAW,EAAE;EAE5D,MAAM,MAAM,QAAQ,QAAQ,GAAG;GAAE,WAAW;GAAM,MAAM;EAAM,CAAC;EAE/D,MAAM,aAAa,KAAK,UAAU,OAAO,MAAM,CAAC;EAChD,IAAI;GACF,MAAM,UAAU,UAAU,YAAY;IACpC,UAAU;IACV,MAAM;IACN,MAAM,YAAY,UAAU,YAAY,UAAU,YAAY;GAChE,CAAC;GACD,MAAM,OAAO,UAAU,QAAQ;GAC/B,KAAK,QAAQ,MAAM,6BAA6B;IAC9C,UAAU,MAAM;IAChB,YAAY,MAAM,QAAQ,MAAM,MAAM,IAAI,MAAM,OAAO,SAAS;IAChE,UAAU,QAAQ,MAAM,KAAK;GAC/B,CAAC;EACH,SAAS,OAAO;;GAEd,MAAM,OAAO,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC;GACrC,MAAM;EACR;EAEA,IAAI;GACF,MAAM,MAAM,UAAU,GAAK;EAC7B,QAAQ,CAER;CACF;AACF","names":[],"sources":["../src/cache.ts"],"version":3,"file":"cache.js","sourceRoot":""}
package/dist/config.d.ts CHANGED
@@ -1,128 +1,128 @@
1
1
  import type { LogLevel } from "./logging.js";
2
2
  export declare const DEFAULT_SYNC_INTERVAL_MINUTES = 60;
3
- export declare const DEFAULT_HTTP_TIMEOUT_MS = 15000;
4
- export declare const DEFAULT_TOKEN_EXPIRY_SKEW_MS = 30000;
3
+ export declare const DEFAULT_HTTP_TIMEOUT_MS = 15e3;
4
+ export declare const DEFAULT_TOKEN_EXPIRY_SKEW_MS = 3e4;
5
5
  export declare const DEFAULT_LOG_LEVEL: LogLevel;
6
6
  export type OAuthAuthFlow = "authorization_code" | "device_code" | "client_credentials" | "jwt_bearer" | "token_exchange";
7
7
  export declare const DEFAULT_AUTH_FLOW: OAuthAuthFlow;
8
8
  /**
9
- * Where to read the platform-supplied JWT that the plugin presents as the
10
- * subject token / assertion for the `jwt_bearer` and `token_exchange` flows.
11
- *
12
- * - `github_actions` — fetches the OIDC token from the GitHub Actions runtime
13
- * via `ACTIONS_ID_TOKEN_REQUEST_URL` + `ACTIONS_ID_TOKEN_REQUEST_TOKEN`,
14
- * with the workflow-declared `audience`. The `id-token: write` permission
15
- * is required on the job.
16
- * - `kubernetes_sa` — reads a projected service-account token from the pod
17
- * filesystem. Default path `/var/run/secrets/tokens/oauth2/token`; mount a
18
- * `projected.sources.serviceAccountToken` volume with the OIDC issuer as
19
- * the audience.
20
- * - `file` — reads any JWT from disk. Useful when an external sidecar
21
- * refreshes the token to a fixed path.
22
- * - `env` — reads the JWT from a named environment variable. Mostly useful
23
- * for tests and ad-hoc shells.
24
- */
9
+ * Where to read the platform-supplied JWT that the plugin presents as the
10
+ * subject token / assertion for the `jwt_bearer` and `token_exchange` flows.
11
+ *
12
+ * - `github_actions` — fetches the OIDC token from the GitHub Actions runtime
13
+ * via `ACTIONS_ID_TOKEN_REQUEST_URL` + `ACTIONS_ID_TOKEN_REQUEST_TOKEN`,
14
+ * with the workflow-declared `audience`. The `id-token: write` permission
15
+ * is required on the job.
16
+ * - `kubernetes_sa` — reads a projected service-account token from the pod
17
+ * filesystem. Default path `/var/run/secrets/tokens/oauth2/token`; mount a
18
+ * `projected.sources.serviceAccountToken` volume with the OIDC issuer as
19
+ * the audience.
20
+ * - `file` — reads any JWT from disk. Useful when an external sidecar
21
+ * refreshes the token to a fixed path.
22
+ * - `env` — reads the JWT from a named environment variable. Mostly useful
23
+ * for tests and ad-hoc shells.
24
+ */
25
25
  export type SubjectTokenSource = {
26
- type: "github_actions";
27
- audience: string;
26
+ type: "github_actions";
27
+ audience: string;
28
28
  } | {
29
- type: "kubernetes_sa";
30
- tokenPath?: string;
29
+ type: "kubernetes_sa";
30
+ tokenPath?: string;
31
31
  } | {
32
- type: "file";
33
- path: string;
32
+ type: "file";
33
+ path: string;
34
34
  } | {
35
- type: "env";
36
- var: string;
35
+ type: "env";
36
+ var: string;
37
37
  };
38
38
  export declare const DEFAULT_K8S_SA_TOKEN_PATH = "/var/run/secrets/tokens/oauth2/token";
39
39
  export interface OAuthServerConfigInput {
40
- id: string;
41
- name?: string;
42
- issuer: string;
43
- baseURL: string;
44
- clientId: string;
45
- clientSecret?: string;
46
- scopes: string[];
47
- syncIntervalMinutes?: number;
48
- nameOverrides?: Record<string, string>;
49
- authorizationEndpoint?: string;
50
- tokenEndpoint?: string;
51
- deviceAuthorizationEndpoint?: string;
52
- jwksUri?: string;
53
- redirectPort?: number;
54
- authFlow?: OAuthAuthFlow;
55
- /**
56
- * Send PKCE (RFC 7636) on the interactive `authorization_code` and
57
- * `device_code` flows: `code_challenge` + `code_challenge_method=S256` on the
58
- * authorization/device request, and the matching `code_verifier` on the token
59
- * exchange. Defaults to `true` — PKCE is recommended for public clients and
60
- * is silently ignored by servers that don't require it, so leave it on unless
61
- * a non-compliant IdP rejects the extra parameters. Has no effect on the
62
- * machine flows (`client_credentials`, `jwt_bearer`, `token_exchange`).
63
- */
64
- pkce?: boolean;
65
- /**
66
- * Required for `jwt_bearer` and `token_exchange`. Tells the plugin where to
67
- * read the platform JWT it should present as the subject token.
68
- */
69
- subjectTokenSource?: SubjectTokenSource;
70
- /**
71
- * Optional `audience` parameter for the `token_exchange` grant — the
72
- * intended recipient of the resulting access token. Set this when the
73
- * OAuth server expects an explicit audience claim distinct from the
74
- * issuer.
75
- */
76
- tokenExchangeAudience?: string;
77
- /**
78
- * Route inference through the OpenAI **Responses API** (`/v1/responses`)
79
- * instead of Chat Completions (`/v1/chat/completions`). When `true` the
80
- * managed provider is registered with `npm: "@ai-sdk/openai"` (whose default
81
- * `languageModel()` targets Responses since AI SDK v5) rather than
82
- * `@ai-sdk/openai-compatible`. Only enable it when the gateway implements the
83
- * OpenAI Responses contract. Defaults to `false`. This flag affects provider
84
- * registration only — it never touches the token lifecycle, so it is read at
85
- * the config-synthesis layer and not part of the validated runtime config.
86
- */
87
- responseApi?: boolean;
40
+ id: string;
41
+ name?: string;
42
+ issuer: string;
43
+ baseURL: string;
44
+ clientId: string;
45
+ clientSecret?: string;
46
+ scopes: string[];
47
+ syncIntervalMinutes?: number;
48
+ nameOverrides?: Record<string, string>;
49
+ authorizationEndpoint?: string;
50
+ tokenEndpoint?: string;
51
+ deviceAuthorizationEndpoint?: string;
52
+ jwksUri?: string;
53
+ redirectPort?: number;
54
+ authFlow?: OAuthAuthFlow;
55
+ /**
56
+ * Send PKCE (RFC 7636) on the interactive `authorization_code` and
57
+ * `device_code` flows: `code_challenge` + `code_challenge_method=S256` on the
58
+ * authorization/device request, and the matching `code_verifier` on the token
59
+ * exchange. Defaults to `true` — PKCE is recommended for public clients and
60
+ * is silently ignored by servers that don't require it, so leave it on unless
61
+ * a non-compliant IdP rejects the extra parameters. Has no effect on the
62
+ * machine flows (`client_credentials`, `jwt_bearer`, `token_exchange`).
63
+ */
64
+ pkce?: boolean;
65
+ /**
66
+ * Required for `jwt_bearer` and `token_exchange`. Tells the plugin where to
67
+ * read the platform JWT it should present as the subject token.
68
+ */
69
+ subjectTokenSource?: SubjectTokenSource;
70
+ /**
71
+ * Optional `audience` parameter for the `token_exchange` grant — the
72
+ * intended recipient of the resulting access token. Set this when the
73
+ * OAuth server expects an explicit audience claim distinct from the
74
+ * issuer.
75
+ */
76
+ tokenExchangeAudience?: string;
77
+ /**
78
+ * Route inference through the OpenAI **Responses API** (`/v1/responses`)
79
+ * instead of Chat Completions (`/v1/chat/completions`). When `true` the
80
+ * managed provider is registered with `npm: "@ai-sdk/openai"` (whose default
81
+ * `languageModel()` targets Responses since AI SDK v5) rather than
82
+ * `@ai-sdk/openai-compatible`. Only enable it when the gateway implements the
83
+ * OpenAI Responses contract. Defaults to `false`. This flag affects provider
84
+ * registration only — it never touches the token lifecycle, so it is read at
85
+ * the config-synthesis layer and not part of the validated runtime config.
86
+ */
87
+ responseApi?: boolean;
88
88
  }
89
89
  export interface OAuth2ModelSyncConfigInput {
90
- servers: OAuthServerConfigInput[];
91
- cacheNamespace?: string;
92
- httpTimeoutMs?: number;
93
- tokenExpirySkewMs?: number;
94
- /**
95
- * Minimum log level the plugin emits. Lower-priority records are dropped.
96
- * One of `"trace" | "debug" | "info" | "warn" | "error"`. Defaults to
97
- * `"info"`. `"trace"` is the most-verbose tier (host `--log-level DEBUG`).
98
- */
99
- logLevel?: LogLevel;
90
+ servers: OAuthServerConfigInput[];
91
+ cacheNamespace?: string;
92
+ httpTimeoutMs?: number;
93
+ tokenExpirySkewMs?: number;
94
+ /**
95
+ * Minimum log level the plugin emits. Lower-priority records are dropped.
96
+ * One of `"trace" | "debug" | "info" | "warn" | "error"`. Defaults to
97
+ * `"info"`. `"trace"` is the most-verbose tier (host `--log-level DEBUG`).
98
+ */
99
+ logLevel?: LogLevel;
100
100
  }
101
101
  export interface OAuthServerConfig {
102
- id: string;
103
- name: string;
104
- issuer: string;
105
- baseURL: string;
106
- clientId: string;
107
- clientSecret?: string;
108
- scopes: string[];
109
- syncIntervalMinutes: number;
110
- nameOverrides: Record<string, string>;
111
- authorizationEndpoint?: string;
112
- tokenEndpoint?: string;
113
- deviceAuthorizationEndpoint?: string;
114
- jwksUri?: string;
115
- redirectPort?: number;
116
- authFlow: OAuthAuthFlow;
117
- pkce: boolean;
118
- subjectTokenSource?: SubjectTokenSource;
119
- tokenExchangeAudience?: string;
102
+ id: string;
103
+ name: string;
104
+ issuer: string;
105
+ baseURL: string;
106
+ clientId: string;
107
+ clientSecret?: string;
108
+ scopes: string[];
109
+ syncIntervalMinutes: number;
110
+ nameOverrides: Record<string, string>;
111
+ authorizationEndpoint?: string;
112
+ tokenEndpoint?: string;
113
+ deviceAuthorizationEndpoint?: string;
114
+ jwksUri?: string;
115
+ redirectPort?: number;
116
+ authFlow: OAuthAuthFlow;
117
+ pkce: boolean;
118
+ subjectTokenSource?: SubjectTokenSource;
119
+ tokenExchangeAudience?: string;
120
120
  }
121
121
  export interface OAuth2ModelSyncConfig {
122
- servers: OAuthServerConfig[];
123
- cacheNamespace: string;
124
- httpTimeoutMs: number;
125
- tokenExpirySkewMs: number;
126
- logLevel: LogLevel;
122
+ servers: OAuthServerConfig[];
123
+ cacheNamespace: string;
124
+ httpTimeoutMs: number;
125
+ tokenExpirySkewMs: number;
126
+ logLevel: LogLevel;
127
127
  }
128
128
  export declare function validateConfig(input: OAuth2ModelSyncConfigInput): OAuth2ModelSyncConfig;