@code-yeongyu/senpi-ai 2026.9.3 → 2026.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/context-room.d.ts +20 -0
- package/dist/api/context-room.d.ts.map +1 -0
- package/dist/api/context-room.js +40 -0
- package/dist/api/context-room.js.map +1 -0
- package/dist/api/simple-options.d.ts +1 -3
- package/dist/api/simple-options.d.ts.map +1 -1
- package/dist/api/simple-options.js +2 -16
- package/dist/api/simple-options.js.map +1 -1
- package/dist/auth/pool/slots.d.ts +16 -3
- package/dist/auth/pool/slots.d.ts.map +1 -1
- package/dist/auth/pool/slots.js +40 -6
- package/dist/auth/pool/slots.js.map +1 -1
- package/dist/compat/extension-oauth-types.d.ts +8 -0
- package/dist/compat/extension-oauth-types.d.ts.map +1 -1
- package/dist/compat/extension-oauth-types.js.map +1 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +3 -2
- package/dist/models.js.map +1 -1
- package/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/azure-openai-responses.json +1 -1
- package/dist/providers/data/huggingface.json +1 -1
- package/dist/providers/data/nvidia.json +1 -1
- package/dist/providers/data/openai-codex.json +1 -1
- package/dist/providers/data/openai.json +1 -1
- package/dist/providers/data/openrouter.json +1 -1
- package/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/utils/overflow.d.ts.map +1 -1
- package/dist/utils/overflow.js +2 -0
- package/dist/utils/overflow.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Api, Context, Model } from "../types.ts";
|
|
2
|
+
export declare const CONTEXT_SAFETY_TOKENS = 4096;
|
|
3
|
+
/** Tokens always left for the answer when a thinking budget shares the response ceiling. */
|
|
4
|
+
export declare const MIN_ANSWER_TOKENS = 1024;
|
|
5
|
+
/** Windows too small to hold the safety margin plus one answer keep the legacy one-token floor. */
|
|
6
|
+
export declare const CONTEXT_GUARD_MIN_WINDOW: number;
|
|
7
|
+
export declare class ContextWindowExhaustedError extends Error {
|
|
8
|
+
readonly estimatedTokens: number;
|
|
9
|
+
readonly contextWindow: number;
|
|
10
|
+
constructor(estimatedTokens: number, contextWindow: number);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Fit the requested output budget into the room the context leaves in the model window.
|
|
14
|
+
* For windows of at least {@link CONTEXT_GUARD_MIN_WINDOW} tokens this throws
|
|
15
|
+
* {@link ContextWindowExhaustedError} instead of shrinking the budget below
|
|
16
|
+
* {@link MIN_ANSWER_TOKENS}: such a request can only return a truncated tool call or an
|
|
17
|
+
* empty "length" stop while still billing the whole prompt.
|
|
18
|
+
*/
|
|
19
|
+
export declare function clampMaxTokensToContext(model: Model<Api>, context: Context, maxTokens: number): number;
|
|
20
|
+
//# sourceMappingURL=context-room.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-room.d.ts","sourceRoot":"","sources":["../../src/api/context-room.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGvD,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,4FAA4F;AAC5F,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC,mGAAmG;AACnG,eAAO,MAAM,wBAAwB,QAA4C,CAAC;AAElF,qBAAa,2BAA4B,SAAQ,KAAK;IACrD,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;gBAEnB,eAAe,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM;CAU1D;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CActG"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { estimateContextTokens } from "../utils/estimate.js";
|
|
2
|
+
export const CONTEXT_SAFETY_TOKENS = 4096;
|
|
3
|
+
/** Tokens always left for the answer when a thinking budget shares the response ceiling. */
|
|
4
|
+
export const MIN_ANSWER_TOKENS = 1024;
|
|
5
|
+
const MIN_MAX_TOKENS = 1;
|
|
6
|
+
/** Windows too small to hold the safety margin plus one answer keep the legacy one-token floor. */
|
|
7
|
+
export const CONTEXT_GUARD_MIN_WINDOW = CONTEXT_SAFETY_TOKENS + MIN_ANSWER_TOKENS;
|
|
8
|
+
export class ContextWindowExhaustedError extends Error {
|
|
9
|
+
constructor(estimatedTokens, contextWindow) {
|
|
10
|
+
super(`Context window exhausted: the conversation is estimated at ${estimatedTokens} of ${contextWindow} tokens, ` +
|
|
11
|
+
`leaving fewer than ${MIN_ANSWER_TOKENS} tokens for a response. ` +
|
|
12
|
+
"Compact the conversation, enable auto-compaction, or start a new session before retrying.");
|
|
13
|
+
this.name = "ContextWindowExhaustedError";
|
|
14
|
+
this.estimatedTokens = estimatedTokens;
|
|
15
|
+
this.contextWindow = contextWindow;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Fit the requested output budget into the room the context leaves in the model window.
|
|
20
|
+
* For windows of at least {@link CONTEXT_GUARD_MIN_WINDOW} tokens this throws
|
|
21
|
+
* {@link ContextWindowExhaustedError} instead of shrinking the budget below
|
|
22
|
+
* {@link MIN_ANSWER_TOKENS}: such a request can only return a truncated tool call or an
|
|
23
|
+
* empty "length" stop while still billing the whole prompt.
|
|
24
|
+
*/
|
|
25
|
+
export function clampMaxTokensToContext(model, context, maxTokens) {
|
|
26
|
+
if (model.contextWindow <= 0) {
|
|
27
|
+
return Number.isFinite(maxTokens) && maxTokens > 0
|
|
28
|
+
? Math.max(MIN_MAX_TOKENS, Math.floor(maxTokens))
|
|
29
|
+
: MIN_MAX_TOKENS;
|
|
30
|
+
}
|
|
31
|
+
const estimatedTokens = estimateContextTokens(context).tokens;
|
|
32
|
+
const available = model.contextWindow - estimatedTokens - CONTEXT_SAFETY_TOKENS;
|
|
33
|
+
if (model.contextWindow >= CONTEXT_GUARD_MIN_WINDOW && available < MIN_ANSWER_TOKENS) {
|
|
34
|
+
throw new ContextWindowExhaustedError(estimatedTokens, model.contextWindow);
|
|
35
|
+
}
|
|
36
|
+
const safeAvailable = Math.max(MIN_MAX_TOKENS, available);
|
|
37
|
+
const requested = Number.isFinite(maxTokens) && maxTokens > 0 ? Math.floor(maxTokens) : safeAvailable;
|
|
38
|
+
return Math.min(requested, safeAvailable);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=context-room.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-room.js","sourceRoot":"","sources":["../../src/api/context-room.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAC1C,4FAA4F;AAC5F,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AACtC,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,mGAAmG;AACnG,MAAM,CAAC,MAAM,wBAAwB,GAAG,qBAAqB,GAAG,iBAAiB,CAAC;AAElF,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAIrD,YAAY,eAAuB,EAAE,aAAqB;QACzD,KAAK,CACJ,8DAA8D,eAAe,OAAO,aAAa,WAAW;YAC3G,sBAAsB,iBAAiB,0BAA0B;YACjE,2FAA2F,CAC5F,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACpC,CAAC;CACD;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAiB,EAAE,OAAgB,EAAE,SAAiB;IAC7F,IAAI,KAAK,CAAC,aAAa,IAAI,CAAC,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,GAAG,CAAC;YACjD,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;YACjD,CAAC,CAAC,cAAc,CAAC;IACnB,CAAC;IACD,MAAM,eAAe,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAC9D,MAAM,SAAS,GAAG,KAAK,CAAC,aAAa,GAAG,eAAe,GAAG,qBAAqB,CAAC;IAChF,IAAI,KAAK,CAAC,aAAa,IAAI,wBAAwB,IAAI,SAAS,GAAG,iBAAiB,EAAE,CAAC;QACtF,MAAM,IAAI,2BAA2B,CAAC,eAAe,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;IAC7E,CAAC;IACD,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IAC1D,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;IACtG,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import type { Api, Context, Model } from \"../types.ts\";\nimport { estimateContextTokens } from \"../utils/estimate.ts\";\n\nexport const CONTEXT_SAFETY_TOKENS = 4096;\n/** Tokens always left for the answer when a thinking budget shares the response ceiling. */\nexport const MIN_ANSWER_TOKENS = 1024;\nconst MIN_MAX_TOKENS = 1;\n/** Windows too small to hold the safety margin plus one answer keep the legacy one-token floor. */\nexport const CONTEXT_GUARD_MIN_WINDOW = CONTEXT_SAFETY_TOKENS + MIN_ANSWER_TOKENS;\n\nexport class ContextWindowExhaustedError extends Error {\n\treadonly estimatedTokens: number;\n\treadonly contextWindow: number;\n\n\tconstructor(estimatedTokens: number, contextWindow: number) {\n\t\tsuper(\n\t\t\t`Context window exhausted: the conversation is estimated at ${estimatedTokens} of ${contextWindow} tokens, ` +\n\t\t\t\t`leaving fewer than ${MIN_ANSWER_TOKENS} tokens for a response. ` +\n\t\t\t\t\"Compact the conversation, enable auto-compaction, or start a new session before retrying.\",\n\t\t);\n\t\tthis.name = \"ContextWindowExhaustedError\";\n\t\tthis.estimatedTokens = estimatedTokens;\n\t\tthis.contextWindow = contextWindow;\n\t}\n}\n\n/**\n * Fit the requested output budget into the room the context leaves in the model window.\n * For windows of at least {@link CONTEXT_GUARD_MIN_WINDOW} tokens this throws\n * {@link ContextWindowExhaustedError} instead of shrinking the budget below\n * {@link MIN_ANSWER_TOKENS}: such a request can only return a truncated tool call or an\n * empty \"length\" stop while still billing the whole prompt.\n */\nexport function clampMaxTokensToContext(model: Model<Api>, context: Context, maxTokens: number): number {\n\tif (model.contextWindow <= 0) {\n\t\treturn Number.isFinite(maxTokens) && maxTokens > 0\n\t\t\t? Math.max(MIN_MAX_TOKENS, Math.floor(maxTokens))\n\t\t\t: MIN_MAX_TOKENS;\n\t}\n\tconst estimatedTokens = estimateContextTokens(context).tokens;\n\tconst available = model.contextWindow - estimatedTokens - CONTEXT_SAFETY_TOKENS;\n\tif (model.contextWindow >= CONTEXT_GUARD_MIN_WINDOW && available < MIN_ANSWER_TOKENS) {\n\t\tthrow new ContextWindowExhaustedError(estimatedTokens, model.contextWindow);\n\t}\n\tconst safeAvailable = Math.max(MIN_MAX_TOKENS, available);\n\tconst requested = Number.isFinite(maxTokens) && maxTokens > 0 ? Math.floor(maxTokens) : safeAvailable;\n\treturn Math.min(requested, safeAvailable);\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Api, Context, Model, SimpleStreamOptions, StreamOptions, ThinkingBudgets, ThinkingLevel } from "../types.ts";
|
|
2
|
+
export { CONTEXT_GUARD_MIN_WINDOW, CONTEXT_SAFETY_TOKENS, ContextWindowExhaustedError, clampMaxTokensToContext, MIN_ANSWER_TOKENS, } from "./context-room.ts";
|
|
2
3
|
/**
|
|
3
4
|
* Merge user-supplied extraBody fields into a provider request payload, skipping
|
|
4
5
|
* any key the provider manages itself (model id, messages, stream flag, etc.).
|
|
@@ -16,10 +17,7 @@ export declare const GOOGLE_RESERVED_BODY_KEYS: ReadonlySet<string>;
|
|
|
16
17
|
export declare const ANTHROPIC_RESERVED_BODY_KEYS: ReadonlySet<string>;
|
|
17
18
|
export declare const MISTRAL_RESERVED_BODY_KEYS: ReadonlySet<string>;
|
|
18
19
|
export declare const BEDROCK_RESERVED_BODY_KEYS: ReadonlySet<string>;
|
|
19
|
-
export declare function clampMaxTokensToContext(model: Model<Api>, context: Context, maxTokens: number): number;
|
|
20
20
|
export declare function buildBaseOptions(model: Model<Api>, context: Context, options?: SimpleStreamOptions, apiKey?: string): StreamOptions;
|
|
21
|
-
/** Tokens always left for the answer when a thinking budget shares the response ceiling. */
|
|
22
|
-
export declare const MIN_ANSWER_TOKENS = 1024;
|
|
23
21
|
export declare const DEFAULT_THINKING_BUDGETS: ThinkingBudgets;
|
|
24
22
|
export declare function clampReasoning(effort: ThinkingLevel | undefined): Exclude<ThinkingLevel, "xhigh" | "max"> | undefined;
|
|
25
23
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-options.d.ts","sourceRoot":"","sources":["../../src/api/simple-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,GAAG,EACH,OAAO,EACP,KAAK,EACL,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,aAAa,EACb,MAAM,aAAa,CAAC;AAGrB;;;;GAIG;AACH,wBAAgB,cAAc,CAC7B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC9C,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,GAC/B,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AM,CASzD,CAAC;AAEH,eAAO,MAAM,0BAA0B,EAAE,WAAW,CAAC,MAAM,CAQzD,CAAC;AAEH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,mBAAmB,EAC7B,MAAM,CAAC,EAAE,MAAM,GACb,aAAa,CA4Bf;AAED,eAAO,MAAM,wBAAwB,EAAE,eAKtC,CAAC;AAEF,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,SAAS,GAAG,OAAO,CAAC,aAAa,EAAE,OAAO,GAAG,KAAK,CAAC,GAAG,SAAS,CAGrH;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,aAAa,GAAG,SAAS,EACjC,cAAc,EAAE,OAAO,GACrB,OAAO,CAAC,aAAa,EAAE,KAAK,CAAC,GAAG,SAAS,CAG3C;AAED,wBAAgB,sBAAsB,CAAC,cAAc,EAAE,aAAa,EAAE,aAAa,CAAC,EAAE,eAAe,GAAG,MAAM,CAI7G;AAED,kGAAkG;AAClG,wBAAgB,+BAA+B,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAE/F;AAED,wBAAgB,0BAA0B,CAEzC,aAAa,EAAE,MAAM,GAAG,SAAS,EACjC,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,aAAa,EAC7B,aAAa,CAAC,EAAE,eAAe,GAC7B;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,CAe/C"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { clampMaxTokensToContext, MIN_ANSWER_TOKENS } from "./context-room.js";
|
|
2
|
+
export { CONTEXT_GUARD_MIN_WINDOW, CONTEXT_SAFETY_TOKENS, ContextWindowExhaustedError, clampMaxTokensToContext, MIN_ANSWER_TOKENS, } from "./context-room.js";
|
|
2
3
|
/**
|
|
3
4
|
* Merge user-supplied extraBody fields into a provider request payload, skipping
|
|
4
5
|
* any key the provider manages itself (model id, messages, stream flag, etc.).
|
|
@@ -101,19 +102,6 @@ export const BEDROCK_RESERVED_BODY_KEYS = new Set([
|
|
|
101
102
|
"inferenceConfig",
|
|
102
103
|
"requestMetadata",
|
|
103
104
|
]);
|
|
104
|
-
const CONTEXT_SAFETY_TOKENS = 4096;
|
|
105
|
-
const MIN_MAX_TOKENS = 1;
|
|
106
|
-
export function clampMaxTokensToContext(model, context, maxTokens) {
|
|
107
|
-
if (model.contextWindow <= 0) {
|
|
108
|
-
return Number.isFinite(maxTokens) && maxTokens > 0
|
|
109
|
-
? Math.max(MIN_MAX_TOKENS, Math.floor(maxTokens))
|
|
110
|
-
: MIN_MAX_TOKENS;
|
|
111
|
-
}
|
|
112
|
-
const available = model.contextWindow - estimateContextTokens(context).tokens - CONTEXT_SAFETY_TOKENS;
|
|
113
|
-
const safeAvailable = Math.max(MIN_MAX_TOKENS, available);
|
|
114
|
-
const requested = Number.isFinite(maxTokens) && maxTokens > 0 ? Math.floor(maxTokens) : safeAvailable;
|
|
115
|
-
return Math.min(requested, safeAvailable);
|
|
116
|
-
}
|
|
117
105
|
export function buildBaseOptions(model, context, options, apiKey) {
|
|
118
106
|
const samplingParams = model.samplingParams || options?.samplingParams
|
|
119
107
|
? { ...model.samplingParams, ...options?.samplingParams }
|
|
@@ -142,8 +130,6 @@ export function buildBaseOptions(model, context, options, apiKey) {
|
|
|
142
130
|
env: options?.env,
|
|
143
131
|
};
|
|
144
132
|
}
|
|
145
|
-
/** Tokens always left for the answer when a thinking budget shares the response ceiling. */
|
|
146
|
-
export const MIN_ANSWER_TOKENS = 1024;
|
|
147
133
|
export const DEFAULT_THINKING_BUDGETS = {
|
|
148
134
|
minimal: 1024,
|
|
149
135
|
low: 2048,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-options.js","sourceRoot":"","sources":["../../src/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C,cAAc,CAAC,CAAC;IAC7C,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,EAAE,SAAS,EAAE,aAAa,IAAI,cAAc,EAAE,cAAc,EAAE,CAAC,EAAE,CAAC;IAC1E,CAAC;IACD,IAAI,cAAc,GAAG,sBAAsB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAClE,MAAM,SAAS,GACd,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,GAAG,cAAc,EAAE,cAAc,CAAC,CAAC;IAEzG,IAAI,SAAS,IAAI,cAAc,EAAE,CAAC;QACjC,cAAc,GAAG,+BAA+B,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IAC7E,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;AACtC,CAAC","sourcesContent":["import type {\n\tApi,\n\tContext,\n\tModel,\n\tSimpleStreamOptions,\n\tStreamOptions,\n\tThinkingBudgets,\n\tThinkingLevel,\n} from \"../types.ts\";\nimport { estimateContextTokens } from \"../utils/estimate.ts\";\n\n/**\n * Merge user-supplied extraBody fields into a provider request payload, skipping\n * any key the provider manages itself (model id, messages, stream flag, etc.).\n * Mutates `target` in place for zero-copy integration into per-provider builders.\n */\nexport function applyExtraBody(\n\ttarget: object,\n\textraBody: Record<string, unknown> | undefined,\n\treservedKeys: ReadonlySet<string>,\n): void {\n\tif (!extraBody) return;\n\tfor (const [key, value] of Object.entries(extraBody)) {\n\t\tif (reservedKeys.has(key)) continue;\n\t\tReflect.set(target, key, value);\n\t}\n}\n\nexport const OPENAI_COMPLETIONS_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"model\",\n\t\"messages\",\n\t\"stream\",\n\t\"stream_options\",\n\t\"tools\",\n\t\"tool_choice\",\n\t\"store\",\n\t\"temperature\",\n\t\"max_tokens\",\n\t\"max_completion_tokens\",\n\t\"reasoning_effort\",\n\t\"reasoning\",\n\t\"thinking\",\n\t\"enable_thinking\",\n\t\"chat_template_kwargs\",\n\t\"tool_stream\",\n\t\"provider\",\n\t\"providerOptions\",\n]);\n\nexport const OPENAI_RESPONSES_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"model\",\n\t\"input\",\n\t\"instructions\",\n\t\"stream\",\n\t\"tools\",\n\t\"tool_choice\",\n\t\"parallel_tool_calls\",\n\t\"reasoning\",\n\t\"max_output_tokens\",\n\t\"temperature\",\n\t\"text\",\n\t\"store\",\n\t\"include\",\n\t\"prompt_cache_key\",\n\t\"prompt_cache_retention\",\n\t\"service_tier\",\n]);\n\n/**\n * Reserved keys for the inner Google `config` object (which is serialized as the\n * request body's generationConfig/tools/systemInstruction by the @google/genai SDK).\n * extraBody is merged into `config`, not the top-level GenerateContentParameters.\n */\nexport const GOOGLE_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"systemInstruction\",\n\t\"tools\",\n\t\"toolConfig\",\n\t\"temperature\",\n\t\"maxOutputTokens\",\n\t\"thinkingConfig\",\n\t\"responseMimeType\",\n\t\"responseSchema\",\n\t\"cachedContent\",\n\t\"abortSignal\",\n\t\"httpOptions\",\n]);\n\nexport const ANTHROPIC_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"model\",\n\t\"messages\",\n\t\"system\",\n\t\"stream\",\n\t\"tools\",\n\t\"tool_choice\",\n\t\"temperature\",\n\t\"max_tokens\",\n\t\"thinking\",\n\t\"output_config\",\n\t\"metadata\",\n]);\n\nexport const MISTRAL_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"model\",\n\t\"messages\",\n\t\"stream\",\n\t\"tools\",\n\t\"toolChoice\",\n\t\"temperature\",\n\t\"maxTokens\",\n\t\"promptMode\",\n]);\n\nexport const BEDROCK_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"modelId\",\n\t\"messages\",\n\t\"system\",\n\t\"toolConfig\",\n\t\"additionalModelRequestFields\",\n\t\"inferenceConfig\",\n\t\"requestMetadata\",\n]);\n\nconst CONTEXT_SAFETY_TOKENS = 4096;\nconst MIN_MAX_TOKENS = 1;\n\nexport function clampMaxTokensToContext(model: Model<Api>, context: Context, maxTokens: number): number {\n\tif (model.contextWindow <= 0) {\n\t\treturn Number.isFinite(maxTokens) && maxTokens > 0\n\t\t\t? Math.max(MIN_MAX_TOKENS, Math.floor(maxTokens))\n\t\t\t: MIN_MAX_TOKENS;\n\t}\n\tconst available = model.contextWindow - estimateContextTokens(context).tokens - CONTEXT_SAFETY_TOKENS;\n\tconst safeAvailable = Math.max(MIN_MAX_TOKENS, available);\n\tconst requested = Number.isFinite(maxTokens) && maxTokens > 0 ? Math.floor(maxTokens) : safeAvailable;\n\treturn Math.min(requested, safeAvailable);\n}\n\nexport function buildBaseOptions(\n\tmodel: Model<Api>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n\tapiKey?: string,\n): StreamOptions {\n\tconst samplingParams =\n\t\tmodel.samplingParams || options?.samplingParams\n\t\t\t? { ...model.samplingParams, ...options?.samplingParams }\n\t\t\t: undefined;\n\treturn {\n\t\ttemperature: options?.temperature,\n\t\tsamplingParams,\n\t\tmaxTokens: clampMaxTokensToContext(model, context, options?.maxTokens ?? model.maxTokens),\n\t\tsignal: options?.signal,\n\t\tabortServerSideFallback: options?.abortServerSideFallback,\n\t\ttelemetryContext: options?.telemetryContext,\n\t\tapiKey: apiKey || options?.apiKey,\n\t\tfetch: options?.fetch,\n\t\ttransport: options?.transport,\n\t\tcacheRetention: options?.cacheRetention ?? model.cacheRetention,\n\t\tsessionId: options?.sessionId,\n\t\theaders: options?.headers,\n\t\textraBody: options?.extraBody,\n\t\tonPayload: options?.onPayload,\n\t\tonResponse: options?.onResponse,\n\t\ttimeoutMs: options?.timeoutMs,\n\t\twebsocketConnectTimeoutMs: options?.websocketConnectTimeoutMs,\n\t\tmaxRetries: options?.maxRetries,\n\t\tmaxRetryDelayMs: options?.maxRetryDelayMs,\n\t\tmetadata: options?.metadata,\n\t\tenv: options?.env,\n\t};\n}\n\n/** Tokens always left for the answer when a thinking budget shares the response ceiling. */\nexport const MIN_ANSWER_TOKENS = 1024;\n\nexport const DEFAULT_THINKING_BUDGETS: ThinkingBudgets = {\n\tminimal: 1024,\n\tlow: 2048,\n\tmedium: 8192,\n\thigh: 16384,\n};\n\nexport function clampReasoning(effort: ThinkingLevel | undefined): Exclude<ThinkingLevel, \"xhigh\" | \"max\"> | undefined {\n\tif (effort === \"xhigh\" || effort === \"max\") return \"high\";\n\treturn effort;\n}\n\n/**\n * Clamp \"max\" to an OpenAI-compatible effort. OpenAI-style reasoning APIs accept\n * low|medium|high|xhigh but not \"max\". Callers that know the model supports xhigh\n * should pass through xhigh; \"max\" downgrades to \"xhigh\" on xhigh-capable models\n * and to \"high\" otherwise.\n */\nexport function clampMaxForOpenAI(\n\teffort: ThinkingLevel | undefined,\n\txhighSupported: boolean,\n): Exclude<ThinkingLevel, \"max\"> | undefined {\n\tif (effort === \"max\") return xhighSupported ? \"xhigh\" : \"high\";\n\treturn effort;\n}\n\nexport function thinkingBudgetForLevel(reasoningLevel: ThinkingLevel, customBudgets?: ThinkingBudgets): number {\n\tconst budgets = { ...DEFAULT_THINKING_BUDGETS, ...customBudgets };\n\tconst level = clampReasoning(reasoningLevel)!;\n\treturn budgets[level]!;\n}\n\n/** Cap a thinking budget so at least MIN_ANSWER_TOKENS remain under a shared response ceiling. */\nexport function clampThinkingBudgetToAnswerRoom(thinkingBudget: number, ceiling: number): number {\n\treturn Math.min(thinkingBudget, Math.max(0, ceiling - MIN_ANSWER_TOKENS));\n}\n\nexport function adjustMaxTokensForThinking(\n\t// Undefined means no explicit caller cap. Use the model cap and fit thinking inside it.\n\tbaseMaxTokens: number | undefined,\n\tmodelMaxTokens: number,\n\treasoningLevel: ThinkingLevel,\n\tcustomBudgets?: ThinkingBudgets,\n): { maxTokens: number; thinkingBudget: number } {\n\t// Fork: an absent/unresolvable level means \"no thinking\", not a NaN budget.\n\tconst level = clampReasoning(reasoningLevel);\n\tif (!level) {\n\t\treturn { maxTokens: baseMaxTokens ?? modelMaxTokens, thinkingBudget: 0 };\n\t}\n\tlet thinkingBudget = thinkingBudgetForLevel(level, customBudgets);\n\tconst maxTokens =\n\t\tbaseMaxTokens === undefined ? modelMaxTokens : Math.min(baseMaxTokens + thinkingBudget, modelMaxTokens);\n\n\tif (maxTokens <= thinkingBudget) {\n\t\tthinkingBudget = clampThinkingBudgetToAnswerRoom(thinkingBudget, maxTokens);\n\t}\n\n\treturn { maxTokens, thinkingBudget };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"simple-options.js","sourceRoot":"","sources":["../../src/api/simple-options.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE/E,OAAO,EACN,wBAAwB,EACxB,qBAAqB,EACrB,2BAA2B,EAC3B,uBAAuB,EACvB,iBAAiB,GACjB,MAAM,mBAAmB,CAAC;AAE3B;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC7B,MAAc,EACd,SAA8C,EAC9C,YAAiC;IAEjC,IAAI,CAAC,SAAS;QAAE,OAAO;IACvB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACtD,IAAI,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAS;QACpC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC;AACF,CAAC;AAED,MAAM,CAAC,MAAM,qCAAqC,GAAwB,IAAI,GAAG,CAAC;IACjF,OAAO;IACP,UAAU;IACV,QAAQ;IACR,gBAAgB;IAChB,OAAO;IACP,aAAa;IACb,OAAO;IACP,aAAa;IACb,YAAY;IACZ,uBAAuB;IACvB,kBAAkB;IAClB,WAAW;IACX,UAAU;IACV,iBAAiB;IACjB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AAC,CAAC;IAEzG,IAAI,SAAS,IAAI,cAAc,EAAE,CAAC;QACjC,cAAc,GAAG,+BAA+B,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IAC7E,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;AACtC,CAAC","sourcesContent":["import type {\n\tApi,\n\tContext,\n\tModel,\n\tSimpleStreamOptions,\n\tStreamOptions,\n\tThinkingBudgets,\n\tThinkingLevel,\n} from \"../types.ts\";\nimport { clampMaxTokensToContext, MIN_ANSWER_TOKENS } from \"./context-room.ts\";\n\nexport {\n\tCONTEXT_GUARD_MIN_WINDOW,\n\tCONTEXT_SAFETY_TOKENS,\n\tContextWindowExhaustedError,\n\tclampMaxTokensToContext,\n\tMIN_ANSWER_TOKENS,\n} from \"./context-room.ts\";\n\n/**\n * Merge user-supplied extraBody fields into a provider request payload, skipping\n * any key the provider manages itself (model id, messages, stream flag, etc.).\n * Mutates `target` in place for zero-copy integration into per-provider builders.\n */\nexport function applyExtraBody(\n\ttarget: object,\n\textraBody: Record<string, unknown> | undefined,\n\treservedKeys: ReadonlySet<string>,\n): void {\n\tif (!extraBody) return;\n\tfor (const [key, value] of Object.entries(extraBody)) {\n\t\tif (reservedKeys.has(key)) continue;\n\t\tReflect.set(target, key, value);\n\t}\n}\n\nexport const OPENAI_COMPLETIONS_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"model\",\n\t\"messages\",\n\t\"stream\",\n\t\"stream_options\",\n\t\"tools\",\n\t\"tool_choice\",\n\t\"store\",\n\t\"temperature\",\n\t\"max_tokens\",\n\t\"max_completion_tokens\",\n\t\"reasoning_effort\",\n\t\"reasoning\",\n\t\"thinking\",\n\t\"enable_thinking\",\n\t\"chat_template_kwargs\",\n\t\"tool_stream\",\n\t\"provider\",\n\t\"providerOptions\",\n]);\n\nexport const OPENAI_RESPONSES_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"model\",\n\t\"input\",\n\t\"instructions\",\n\t\"stream\",\n\t\"tools\",\n\t\"tool_choice\",\n\t\"parallel_tool_calls\",\n\t\"reasoning\",\n\t\"max_output_tokens\",\n\t\"temperature\",\n\t\"text\",\n\t\"store\",\n\t\"include\",\n\t\"prompt_cache_key\",\n\t\"prompt_cache_retention\",\n\t\"service_tier\",\n]);\n\n/**\n * Reserved keys for the inner Google `config` object (which is serialized as the\n * request body's generationConfig/tools/systemInstruction by the @google/genai SDK).\n * extraBody is merged into `config`, not the top-level GenerateContentParameters.\n */\nexport const GOOGLE_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"systemInstruction\",\n\t\"tools\",\n\t\"toolConfig\",\n\t\"temperature\",\n\t\"maxOutputTokens\",\n\t\"thinkingConfig\",\n\t\"responseMimeType\",\n\t\"responseSchema\",\n\t\"cachedContent\",\n\t\"abortSignal\",\n\t\"httpOptions\",\n]);\n\nexport const ANTHROPIC_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"model\",\n\t\"messages\",\n\t\"system\",\n\t\"stream\",\n\t\"tools\",\n\t\"tool_choice\",\n\t\"temperature\",\n\t\"max_tokens\",\n\t\"thinking\",\n\t\"output_config\",\n\t\"metadata\",\n]);\n\nexport const MISTRAL_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"model\",\n\t\"messages\",\n\t\"stream\",\n\t\"tools\",\n\t\"toolChoice\",\n\t\"temperature\",\n\t\"maxTokens\",\n\t\"promptMode\",\n]);\n\nexport const BEDROCK_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"modelId\",\n\t\"messages\",\n\t\"system\",\n\t\"toolConfig\",\n\t\"additionalModelRequestFields\",\n\t\"inferenceConfig\",\n\t\"requestMetadata\",\n]);\n\nexport function buildBaseOptions(\n\tmodel: Model<Api>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n\tapiKey?: string,\n): StreamOptions {\n\tconst samplingParams =\n\t\tmodel.samplingParams || options?.samplingParams\n\t\t\t? { ...model.samplingParams, ...options?.samplingParams }\n\t\t\t: undefined;\n\treturn {\n\t\ttemperature: options?.temperature,\n\t\tsamplingParams,\n\t\tmaxTokens: clampMaxTokensToContext(model, context, options?.maxTokens ?? model.maxTokens),\n\t\tsignal: options?.signal,\n\t\tabortServerSideFallback: options?.abortServerSideFallback,\n\t\ttelemetryContext: options?.telemetryContext,\n\t\tapiKey: apiKey || options?.apiKey,\n\t\tfetch: options?.fetch,\n\t\ttransport: options?.transport,\n\t\tcacheRetention: options?.cacheRetention ?? model.cacheRetention,\n\t\tsessionId: options?.sessionId,\n\t\theaders: options?.headers,\n\t\textraBody: options?.extraBody,\n\t\tonPayload: options?.onPayload,\n\t\tonResponse: options?.onResponse,\n\t\ttimeoutMs: options?.timeoutMs,\n\t\twebsocketConnectTimeoutMs: options?.websocketConnectTimeoutMs,\n\t\tmaxRetries: options?.maxRetries,\n\t\tmaxRetryDelayMs: options?.maxRetryDelayMs,\n\t\tmetadata: options?.metadata,\n\t\tenv: options?.env,\n\t};\n}\n\nexport const DEFAULT_THINKING_BUDGETS: ThinkingBudgets = {\n\tminimal: 1024,\n\tlow: 2048,\n\tmedium: 8192,\n\thigh: 16384,\n};\n\nexport function clampReasoning(effort: ThinkingLevel | undefined): Exclude<ThinkingLevel, \"xhigh\" | \"max\"> | undefined {\n\tif (effort === \"xhigh\" || effort === \"max\") return \"high\";\n\treturn effort;\n}\n\n/**\n * Clamp \"max\" to an OpenAI-compatible effort. OpenAI-style reasoning APIs accept\n * low|medium|high|xhigh but not \"max\". Callers that know the model supports xhigh\n * should pass through xhigh; \"max\" downgrades to \"xhigh\" on xhigh-capable models\n * and to \"high\" otherwise.\n */\nexport function clampMaxForOpenAI(\n\teffort: ThinkingLevel | undefined,\n\txhighSupported: boolean,\n): Exclude<ThinkingLevel, \"max\"> | undefined {\n\tif (effort === \"max\") return xhighSupported ? \"xhigh\" : \"high\";\n\treturn effort;\n}\n\nexport function thinkingBudgetForLevel(reasoningLevel: ThinkingLevel, customBudgets?: ThinkingBudgets): number {\n\tconst budgets = { ...DEFAULT_THINKING_BUDGETS, ...customBudgets };\n\tconst level = clampReasoning(reasoningLevel)!;\n\treturn budgets[level]!;\n}\n\n/** Cap a thinking budget so at least MIN_ANSWER_TOKENS remain under a shared response ceiling. */\nexport function clampThinkingBudgetToAnswerRoom(thinkingBudget: number, ceiling: number): number {\n\treturn Math.min(thinkingBudget, Math.max(0, ceiling - MIN_ANSWER_TOKENS));\n}\n\nexport function adjustMaxTokensForThinking(\n\t// Undefined means no explicit caller cap. Use the model cap and fit thinking inside it.\n\tbaseMaxTokens: number | undefined,\n\tmodelMaxTokens: number,\n\treasoningLevel: ThinkingLevel,\n\tcustomBudgets?: ThinkingBudgets,\n): { maxTokens: number; thinkingBudget: number } {\n\t// Fork: an absent/unresolvable level means \"no thinking\", not a NaN budget.\n\tconst level = clampReasoning(reasoningLevel);\n\tif (!level) {\n\t\treturn { maxTokens: baseMaxTokens ?? modelMaxTokens, thinkingBudget: 0 };\n\t}\n\tlet thinkingBudget = thinkingBudgetForLevel(level, customBudgets);\n\tconst maxTokens =\n\t\tbaseMaxTokens === undefined ? modelMaxTokens : Math.min(baseMaxTokens + thinkingBudget, modelMaxTokens);\n\n\tif (maxTokens <= thinkingBudget) {\n\t\tthinkingBudget = clampThinkingBudgetToAnswerRoom(thinkingBudget, maxTokens);\n\t}\n\n\treturn { maxTokens, thinkingBudget };\n}\n"]}
|
|
@@ -31,6 +31,13 @@ export declare function upsertSlot(credential: PooledCredential | undefined, slo
|
|
|
31
31
|
* Removes one slot. The credential is dropped entirely once its last slot is gone,
|
|
32
32
|
* and a pin naming the removed slot is cleared so selection never points at a slot
|
|
33
33
|
* that no longer exists.
|
|
34
|
+
*
|
|
35
|
+
* When the removed slot was the one the flat top-level fields projected, those
|
|
36
|
+
* fields are re-projected from the first survivor. Without that the pool keeps
|
|
37
|
+
* authenticating with the deleted account's material: a credential with a single
|
|
38
|
+
* remaining slot does not enter the rotation path, so ordinary requests resolve
|
|
39
|
+
* the flat projection and would keep using exactly the account the user removed.
|
|
40
|
+
* `accounts` is preserved either way, so the entry stays a pool.
|
|
34
41
|
*/
|
|
35
42
|
export declare function removeSlot(credential: PooledCredential | undefined, name: string): PooledCredential | undefined;
|
|
36
43
|
export declare function pinSlot(credential: PooledCredential, name: string): PooledCredential;
|
|
@@ -41,9 +48,15 @@ export declare function pinSlot(credential: PooledCredential, name: string): Poo
|
|
|
41
48
|
*/
|
|
42
49
|
export declare function projectSlot(credential: PooledCredential | undefined, name: string): Credential | undefined;
|
|
43
50
|
/**
|
|
44
|
-
* Appends an unnamed flat credential to a pool as a generated `login-N` slot.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
51
|
+
* Appends an unnamed flat credential to a pool as a generated `login-N` slot.
|
|
52
|
+
* An absent current entry keeps today's whole-write shape; a flat current entry
|
|
53
|
+
* is promoted to a pool so the legacy credential stays reachable as `default`
|
|
54
|
+
* instead of being overwritten by the second login.
|
|
55
|
+
*
|
|
56
|
+
* A login result that already carries its own populated `accounts` array is a
|
|
57
|
+
* provider-owned pool: it IS the complete post-login credential, so it is
|
|
58
|
+
* written through untouched. Reading its top-level fields as a flat credential
|
|
59
|
+
* would append the provider's placeholder material as a second slot.
|
|
47
60
|
*/
|
|
48
61
|
export declare function appendLoginSlot(current: PooledCredential | undefined, flat: Credential): Credential;
|
|
49
62
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slots.d.ts","sourceRoot":"","sources":["../../../src/auth/pool/slots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,YAAY,EAAE,UAAU,EAAE,CAAC;AAE3B,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;AAE9D,MAAM,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;I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AAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,UAAU,GAAG,UAAU,CAe3F"}
|
package/dist/auth/pool/slots.js
CHANGED
|
@@ -51,18 +51,43 @@ export function upsertSlot(credential, slot) {
|
|
|
51
51
|
: [...existing, slot];
|
|
52
52
|
return { ...base, accounts };
|
|
53
53
|
}
|
|
54
|
+
/** Whether the flat top-level fields are this slot's material rather than a sibling's. */
|
|
55
|
+
function slotMirrorsFlat(credential, slot) {
|
|
56
|
+
if (credential.type === "oauth")
|
|
57
|
+
return slot.access === credential.access || slot.refresh === credential.refresh;
|
|
58
|
+
return slot.key === credential.key;
|
|
59
|
+
}
|
|
60
|
+
/** Rewrites the flat top-level projection to carry the given slot's material. */
|
|
61
|
+
function projectFlatFields(credential, slot) {
|
|
62
|
+
if (credential.type === "oauth") {
|
|
63
|
+
if (slot.access === undefined || slot.refresh === undefined || slot.expires === undefined)
|
|
64
|
+
return credential;
|
|
65
|
+
return { ...credential, access: slot.access, refresh: slot.refresh, expires: slot.expires };
|
|
66
|
+
}
|
|
67
|
+
return { ...credential, key: slot.key };
|
|
68
|
+
}
|
|
54
69
|
/**
|
|
55
70
|
* Removes one slot. The credential is dropped entirely once its last slot is gone,
|
|
56
71
|
* and a pin naming the removed slot is cleared so selection never points at a slot
|
|
57
72
|
* that no longer exists.
|
|
73
|
+
*
|
|
74
|
+
* When the removed slot was the one the flat top-level fields projected, those
|
|
75
|
+
* fields are re-projected from the first survivor. Without that the pool keeps
|
|
76
|
+
* authenticating with the deleted account's material: a credential with a single
|
|
77
|
+
* remaining slot does not enter the rotation path, so ordinary requests resolve
|
|
78
|
+
* the flat projection and would keep using exactly the account the user removed.
|
|
79
|
+
* `accounts` is preserved either way, so the entry stays a pool.
|
|
58
80
|
*/
|
|
59
81
|
export function removeSlot(credential, name) {
|
|
60
82
|
if (!credential)
|
|
61
83
|
return undefined;
|
|
62
|
-
const
|
|
84
|
+
const existing = listSlots(credential);
|
|
85
|
+
const removed = existing.find((slot) => slot.name === name);
|
|
86
|
+
const accounts = existing.filter((slot) => slot.name !== name);
|
|
63
87
|
if (accounts.length === 0)
|
|
64
88
|
return undefined;
|
|
65
|
-
const
|
|
89
|
+
const reprojected = removed && slotMirrorsFlat(credential, removed) ? projectFlatFields(credential, accounts[0]) : credential;
|
|
90
|
+
const next = { ...reprojected, accounts };
|
|
66
91
|
if (next.pinned === name)
|
|
67
92
|
delete next.pinned;
|
|
68
93
|
return next;
|
|
@@ -112,12 +137,21 @@ function nextLoginSlotName(credential) {
|
|
|
112
137
|
throw new Error("Credential pool is full");
|
|
113
138
|
}
|
|
114
139
|
/**
|
|
115
|
-
* Appends an unnamed flat credential to a pool as a generated `login-N` slot.
|
|
116
|
-
*
|
|
117
|
-
*
|
|
140
|
+
* Appends an unnamed flat credential to a pool as a generated `login-N` slot.
|
|
141
|
+
* An absent current entry keeps today's whole-write shape; a flat current entry
|
|
142
|
+
* is promoted to a pool so the legacy credential stays reachable as `default`
|
|
143
|
+
* instead of being overwritten by the second login.
|
|
144
|
+
*
|
|
145
|
+
* A login result that already carries its own populated `accounts` array is a
|
|
146
|
+
* provider-owned pool: it IS the complete post-login credential, so it is
|
|
147
|
+
* written through untouched. Reading its top-level fields as a flat credential
|
|
148
|
+
* would append the provider's placeholder material as a second slot.
|
|
118
149
|
*/
|
|
119
150
|
export function appendLoginSlot(current, flat) {
|
|
120
|
-
if (
|
|
151
|
+
if ("accounts" in flat && Array.isArray(flat.accounts) && flat.accounts.length > 0) {
|
|
152
|
+
return flat;
|
|
153
|
+
}
|
|
154
|
+
if (!current) {
|
|
121
155
|
return flat;
|
|
122
156
|
}
|
|
123
157
|
return upsertSlot(current, slotFromFlatCredentialNamed(flat, nextLoginSlotName(current)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slots.js","sourceRoot":"","sources":["../../../src/auth/pool/slots.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAkB3C,MAAM,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AAG,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,CAAC;AACtF,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAyB,EAAE,SAAqB;IAC9E,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvE,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,IAAI,SAAS,CAAC,IAAI,KAAK,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,SAAS,CAAC;IAC7E,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACnH,MAAM,OAAO,GAAG;QACf,MAAM,EAAE,SAAS,CAAC,MAAM;QACxB,OAAO,EAAE,SAAS,CAAC,OAAO;QAC1B,OAAO,EAAE,SAAS,CAAC,OAAO;KAC1B,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM;QACtB,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACpF,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IACpB,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["import type { Credential } from \"../types.ts\";\n\nexport type { Credential };\n\nexport const DEFAULT_SLOT_NAME = \"default\";\n\nexport type CredentialSlotSource = \"login\" | \"import\" | \"env\";\n\nexport type CredentialSlot = {\n\tname: string;\n\tsource?: CredentialSlotSource;\n\tkey?: string;\n\taccess?: string;\n\trefresh?: string;\n\texpires?: number;\n};\n\nexport type PooledCredential = Credential & {\n\taccounts?: CredentialSlot[];\n\tpinned?: string;\n};\n\nconst SLOT_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/;\n\nexport function assertValidSlotName(name: string): void {\n\tif (!SLOT_NAME_PATTERN.test(name)) {\n\t\tthrow new Error(\n\t\t\t`Invalid account name '${name}': use letters, digits, '-' or '_', starting with a letter or digit`,\n\t\t);\n\t}\n}\n\nfunction storedSlots(credential: PooledCredential): CredentialSlot[] {\n\treturn Array.isArray(credential.accounts) ? credential.accounts : [];\n}\n\nfunction slotFromFlatCredential(credential: PooledCredential): CredentialSlot {\n\tif (credential.type === \"oauth\") {\n\t\treturn {\n\t\t\tname: DEFAULT_SLOT_NAME,\n\t\t\tsource: \"login\",\n\t\t\taccess: credential.access,\n\t\t\trefresh: credential.refresh,\n\t\t\texpires: credential.expires,\n\t\t};\n\t}\n\treturn { name: DEFAULT_SLOT_NAME, source: \"login\", key: credential.key };\n}\n\n/**\n * A flat credential written by a build predating pools is read as a one-slot pool\n * without writing anything back; the caller decides whether a write ever happens.\n */\nexport function listSlots(credential: PooledCredential | undefined): CredentialSlot[] {\n\tif (!credential) return [];\n\tconst slots = storedSlots(credential);\n\treturn slots.length > 0 ? [...slots] : [slotFromFlatCredential(credential)];\n}\n\nexport function findSlot(credential: PooledCredential | undefined, name: string): CredentialSlot | undefined {\n\treturn listSlots(credential).find((slot) => slot.name === name);\n}\n\n/**\n * Replaces or appends one slot while every sibling, the pin, and the flat\n * top-level credential survive untouched. The flat fields stay as written so a\n * build that ignores `accounts` still authenticates from them.\n */\nexport function upsertSlot(credential: PooledCredential | undefined, slot: CredentialSlot): PooledCredential {\n\tassertValidSlotName(slot.name);\n\tconst base: PooledCredential =\n\t\tcredential ??\n\t\t(slot.access !== undefined || slot.refresh !== undefined\n\t\t\t? { type: \"oauth\", access: slot.access ?? \"\", refresh: slot.refresh ?? \"\", expires: slot.expires ?? 0 }\n\t\t\t: { type: \"api_key\", key: slot.key });\n\tconst existing = listSlots(base);\n\tconst index = existing.findIndex((candidate) => candidate.name === slot.name);\n\tconst accounts =\n\t\tindex >= 0\n\t\t\t? existing.map((candidate) => (candidate.name === slot.name ? { ...candidate, ...slot } : candidate))\n\t\t\t: [...existing, slot];\n\treturn { ...base, accounts };\n}\n\n/**\n * Removes one slot. The credential is dropped entirely once its last slot is gone,\n * and a pin naming the removed slot is cleared so selection never points at a slot\n * that no longer exists.\n */\nexport function removeSlot(credential: PooledCredential | undefined, name: string): PooledCredential | undefined {\n\tif (!credential) return undefined;\n\tconst accounts = listSlots(credential).filter((slot) => slot.name !== name);\n\tif (accounts.length === 0) return undefined;\n\tconst next: PooledCredential = { ...credential, accounts };\n\tif (next.pinned === name) delete next.pinned;\n\treturn next;\n}\n\nexport function pinSlot(credential: PooledCredential, name: string): PooledCredential {\n\tassertValidSlotName(name);\n\treturn { ...credential, pinned: name };\n}\n\n/**\n * Projects one named slot onto the flat credential shape for request-scoped\n * resolution; pool bookkeeping fields are stripped so provider handlers see a\n * plain credential and never write pool state back through the projection.\n */\nexport function projectSlot(credential: PooledCredential | undefined, name: string): Credential | undefined {\n\tif (!credential) return undefined;\n\tconst slot = findSlot(credential, name);\n\tif (!slot) return undefined;\n\tconst { accounts: _accounts, pinned: _pinned, ...flat } = credential;\n\tif (flat.type === \"oauth\") {\n\t\tif (slot.access === undefined || slot.refresh === undefined || slot.expires === undefined) return undefined;\n\t\treturn { ...flat, access: slot.access, refresh: slot.refresh, expires: slot.expires };\n\t}\n\treturn { ...flat, key: slot.key };\n}\n\nfunction slotFromFlatCredentialNamed(credential: Credential, name: string): CredentialSlot {\n\tif (credential.type === \"oauth\") {\n\t\treturn {\n\t\t\tname,\n\t\t\tsource: \"login\",\n\t\t\taccess: credential.access,\n\t\t\trefresh: credential.refresh,\n\t\t\texpires: credential.expires,\n\t\t};\n\t}\n\treturn { name, source: \"login\", key: credential.key };\n}\n\nfunction nextLoginSlotName(credential: PooledCredential): string {\n\tconst taken = new Set(listSlots(credential).map((slot) => slot.name));\n\tfor (let index = 2; index < 1000; index++) {\n\t\tconst candidate = `login-${index}`;\n\t\tif (!taken.has(candidate)) return candidate;\n\t}\n\tthrow new Error(\"Credential pool is full\");\n}\n\n/**\n * Appends an unnamed flat credential to a pool as a generated `login-N` slot. A\n * flat or absent current entry keeps today's whole-write shape so no existing\n * user's stored bytes change until a second credential actually exists.\n */\nexport function appendLoginSlot(current: PooledCredential | undefined, flat: Credential): Credential {\n\tif (!current || !Array.isArray(current.accounts) || current.accounts.length === 0) {\n\t\treturn flat;\n\t}\n\treturn upsertSlot(current, slotFromFlatCredentialNamed(flat, nextLoginSlotName(current)));\n}\n\n/**\n * Merges a rotated OAuth credential back into the pool: the slot whose material\n * matches the pre-refresh flat fields is updated in place together with those\n * flat fields, while every sibling and the pin survive byte-identical. A flat\n * current entry keeps today's whole-write shape.\n */\n/**\n * Merges a rotated OAuth credential into the NAMED slot. The flat top-level\n * projection rotates only when it mirrored that slot's previous material, so\n * refreshing a secondary slot never disturbs what an older binary reads.\n */\nexport function mergeRefreshedSlot(current: PooledCredential, name: string, refreshed: Credential): Credential {\n\tif (refreshed.type !== \"oauth\" || current.type !== \"oauth\") return current;\n\tif (!Array.isArray(current.accounts) || current.accounts.length === 0) return mergeRefreshed(current, refreshed);\n\tconst target = current.accounts.find((slot) => slot.name === name);\n\tif (!target) return current;\n\tconst rotated = { access: refreshed.access, refresh: refreshed.refresh, expires: refreshed.expires };\n\tconst accounts = current.accounts.map((slot) => (slot === target ? { ...slot, ...rotated } : slot));\n\tconst mirrorsFlat = target.access === current.access || target.refresh === current.refresh;\n\treturn mirrorsFlat ? { ...current, ...rotated, accounts } : { ...current, accounts };\n}\n\nexport function mergeRefreshed(current: PooledCredential, refreshed: Credential): Credential {\n\tif (!Array.isArray(current.accounts) || current.accounts.length === 0) {\n\t\treturn refreshed;\n\t}\n\tif (refreshed.type !== \"oauth\" || current.type !== \"oauth\") return refreshed;\n\tconst target = current.accounts.find((slot) => slot.access === current.access || slot.refresh === current.refresh);\n\tconst rotated = {\n\t\taccess: refreshed.access,\n\t\trefresh: refreshed.refresh,\n\t\texpires: refreshed.expires,\n\t};\n\tconst accounts = target\n\t\t? current.accounts.map((slot) => (slot === target ? { ...slot, ...rotated } : slot))\n\t\t: current.accounts;\n\treturn { ...current, ...rotated, accounts };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"slots.js","sourceRoot":"","sources":["../../../src/auth/pool/slots.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAkB3C,MAAM,iBAAiB,GAAG,kCAAkC,CAAC;AAE7D,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC/C,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACd,yBAAyB,IAAI,qEAAqE,CAClG,CAAC;IACH,CAAC;AACF,CAAC;AAED,SAAS,WAAW,CAAC,UAA4B;IAChD,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;AACtE,CAAC;AAED,SAAS,sBAAsB,CAAC,UAA4B;IAC3D,IAAI,UAAU,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QACjC,OAAO;YACN,IAAI,EAAE,iBAAiB;YACvB,MAAM,EAAE,OAAO;YACf,MAAM,EAAE,UAAU,CAAC,MAAM;YACzB,OAAO,EAAE,UAAU,CAAC,OAAO;YAC3B,OAAO,EAAE,UAAU,CAAC,OAAO;SAC3B,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,OAA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B,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM;QACtB,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACpF,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IACpB,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["import type { Credential } from \"../types.ts\";\n\nexport type { Credential };\n\nexport const DEFAULT_SLOT_NAME = \"default\";\n\nexport type CredentialSlotSource = \"login\" | \"import\" | \"env\";\n\nexport type CredentialSlot = {\n\tname: string;\n\tsource?: CredentialSlotSource;\n\tkey?: string;\n\taccess?: string;\n\trefresh?: string;\n\texpires?: number;\n};\n\nexport type PooledCredential = Credential & {\n\taccounts?: CredentialSlot[];\n\tpinned?: string;\n};\n\nconst SLOT_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/;\n\nexport function assertValidSlotName(name: string): void {\n\tif (!SLOT_NAME_PATTERN.test(name)) {\n\t\tthrow new Error(\n\t\t\t`Invalid account name '${name}': use letters, digits, '-' or '_', starting with a letter or digit`,\n\t\t);\n\t}\n}\n\nfunction storedSlots(credential: PooledCredential): CredentialSlot[] {\n\treturn Array.isArray(credential.accounts) ? credential.accounts : [];\n}\n\nfunction slotFromFlatCredential(credential: PooledCredential): CredentialSlot {\n\tif (credential.type === \"oauth\") {\n\t\treturn {\n\t\t\tname: DEFAULT_SLOT_NAME,\n\t\t\tsource: \"login\",\n\t\t\taccess: credential.access,\n\t\t\trefresh: credential.refresh,\n\t\t\texpires: credential.expires,\n\t\t};\n\t}\n\treturn { name: DEFAULT_SLOT_NAME, source: \"login\", key: credential.key };\n}\n\n/**\n * A flat credential written by a build predating pools is read as a one-slot pool\n * without writing anything back; the caller decides whether a write ever happens.\n */\nexport function listSlots(credential: PooledCredential | undefined): CredentialSlot[] {\n\tif (!credential) return [];\n\tconst slots = storedSlots(credential);\n\treturn slots.length > 0 ? [...slots] : [slotFromFlatCredential(credential)];\n}\n\nexport function findSlot(credential: PooledCredential | undefined, name: string): CredentialSlot | undefined {\n\treturn listSlots(credential).find((slot) => slot.name === name);\n}\n\n/**\n * Replaces or appends one slot while every sibling, the pin, and the flat\n * top-level credential survive untouched. The flat fields stay as written so a\n * build that ignores `accounts` still authenticates from them.\n */\nexport function upsertSlot(credential: PooledCredential | undefined, slot: CredentialSlot): PooledCredential {\n\tassertValidSlotName(slot.name);\n\tconst base: PooledCredential =\n\t\tcredential ??\n\t\t(slot.access !== undefined || slot.refresh !== undefined\n\t\t\t? { type: \"oauth\", access: slot.access ?? \"\", refresh: slot.refresh ?? \"\", expires: slot.expires ?? 0 }\n\t\t\t: { type: \"api_key\", key: slot.key });\n\tconst existing = listSlots(base);\n\tconst index = existing.findIndex((candidate) => candidate.name === slot.name);\n\tconst accounts =\n\t\tindex >= 0\n\t\t\t? existing.map((candidate) => (candidate.name === slot.name ? { ...candidate, ...slot } : candidate))\n\t\t\t: [...existing, slot];\n\treturn { ...base, accounts };\n}\n\n/** Whether the flat top-level fields are this slot's material rather than a sibling's. */\nfunction slotMirrorsFlat(credential: PooledCredential, slot: CredentialSlot): boolean {\n\tif (credential.type === \"oauth\") return slot.access === credential.access || slot.refresh === credential.refresh;\n\treturn slot.key === credential.key;\n}\n\n/** Rewrites the flat top-level projection to carry the given slot's material. */\nfunction projectFlatFields(credential: PooledCredential, slot: CredentialSlot): PooledCredential {\n\tif (credential.type === \"oauth\") {\n\t\tif (slot.access === undefined || slot.refresh === undefined || slot.expires === undefined) return credential;\n\t\treturn { ...credential, access: slot.access, refresh: slot.refresh, expires: slot.expires };\n\t}\n\treturn { ...credential, key: slot.key };\n}\n\n/**\n * Removes one slot. The credential is dropped entirely once its last slot is gone,\n * and a pin naming the removed slot is cleared so selection never points at a slot\n * that no longer exists.\n *\n * When the removed slot was the one the flat top-level fields projected, those\n * fields are re-projected from the first survivor. Without that the pool keeps\n * authenticating with the deleted account's material: a credential with a single\n * remaining slot does not enter the rotation path, so ordinary requests resolve\n * the flat projection and would keep using exactly the account the user removed.\n * `accounts` is preserved either way, so the entry stays a pool.\n */\nexport function removeSlot(credential: PooledCredential | undefined, name: string): PooledCredential | undefined {\n\tif (!credential) return undefined;\n\tconst existing = listSlots(credential);\n\tconst removed = existing.find((slot) => slot.name === name);\n\tconst accounts = existing.filter((slot) => slot.name !== name);\n\tif (accounts.length === 0) return undefined;\n\tconst reprojected =\n\t\tremoved && slotMirrorsFlat(credential, removed) ? projectFlatFields(credential, accounts[0]) : credential;\n\tconst next: PooledCredential = { ...reprojected, accounts };\n\tif (next.pinned === name) delete next.pinned;\n\treturn next;\n}\n\nexport function pinSlot(credential: PooledCredential, name: string): PooledCredential {\n\tassertValidSlotName(name);\n\treturn { ...credential, pinned: name };\n}\n\n/**\n * Projects one named slot onto the flat credential shape for request-scoped\n * resolution; pool bookkeeping fields are stripped so provider handlers see a\n * plain credential and never write pool state back through the projection.\n */\nexport function projectSlot(credential: PooledCredential | undefined, name: string): Credential | undefined {\n\tif (!credential) return undefined;\n\tconst slot = findSlot(credential, name);\n\tif (!slot) return undefined;\n\tconst { accounts: _accounts, pinned: _pinned, ...flat } = credential;\n\tif (flat.type === \"oauth\") {\n\t\tif (slot.access === undefined || slot.refresh === undefined || slot.expires === undefined) return undefined;\n\t\treturn { ...flat, access: slot.access, refresh: slot.refresh, expires: slot.expires };\n\t}\n\treturn { ...flat, key: slot.key };\n}\n\nfunction slotFromFlatCredentialNamed(credential: Credential, name: string): CredentialSlot {\n\tif (credential.type === \"oauth\") {\n\t\treturn {\n\t\t\tname,\n\t\t\tsource: \"login\",\n\t\t\taccess: credential.access,\n\t\t\trefresh: credential.refresh,\n\t\t\texpires: credential.expires,\n\t\t};\n\t}\n\treturn { name, source: \"login\", key: credential.key };\n}\n\nfunction nextLoginSlotName(credential: PooledCredential): string {\n\tconst taken = new Set(listSlots(credential).map((slot) => slot.name));\n\tfor (let index = 2; index < 1000; index++) {\n\t\tconst candidate = `login-${index}`;\n\t\tif (!taken.has(candidate)) return candidate;\n\t}\n\tthrow new Error(\"Credential pool is full\");\n}\n\n/**\n * Appends an unnamed flat credential to a pool as a generated `login-N` slot.\n * An absent current entry keeps today's whole-write shape; a flat current entry\n * is promoted to a pool so the legacy credential stays reachable as `default`\n * instead of being overwritten by the second login.\n *\n * A login result that already carries its own populated `accounts` array is a\n * provider-owned pool: it IS the complete post-login credential, so it is\n * written through untouched. Reading its top-level fields as a flat credential\n * would append the provider's placeholder material as a second slot.\n */\nexport function appendLoginSlot(current: PooledCredential | undefined, flat: Credential): Credential {\n\tif (\"accounts\" in flat && Array.isArray(flat.accounts) && flat.accounts.length > 0) {\n\t\treturn flat;\n\t}\n\tif (!current) {\n\t\treturn flat;\n\t}\n\treturn upsertSlot(current, slotFromFlatCredentialNamed(flat, nextLoginSlotName(current)));\n}\n\n/**\n * Merges a rotated OAuth credential back into the pool: the slot whose material\n * matches the pre-refresh flat fields is updated in place together with those\n * flat fields, while every sibling and the pin survive byte-identical. A flat\n * current entry keeps today's whole-write shape.\n */\n/**\n * Merges a rotated OAuth credential into the NAMED slot. The flat top-level\n * projection rotates only when it mirrored that slot's previous material, so\n * refreshing a secondary slot never disturbs what an older binary reads.\n */\nexport function mergeRefreshedSlot(current: PooledCredential, name: string, refreshed: Credential): Credential {\n\tif (refreshed.type !== \"oauth\" || current.type !== \"oauth\") return current;\n\tif (!Array.isArray(current.accounts) || current.accounts.length === 0) return mergeRefreshed(current, refreshed);\n\tconst target = current.accounts.find((slot) => slot.name === name);\n\tif (!target) return current;\n\tconst rotated = { access: refreshed.access, refresh: refreshed.refresh, expires: refreshed.expires };\n\tconst accounts = current.accounts.map((slot) => (slot === target ? { ...slot, ...rotated } : slot));\n\tconst mirrorsFlat = target.access === current.access || target.refresh === current.refresh;\n\treturn mirrorsFlat ? { ...current, ...rotated, accounts } : { ...current, accounts };\n}\n\nexport function mergeRefreshed(current: PooledCredential, refreshed: Credential): Credential {\n\tif (!Array.isArray(current.accounts) || current.accounts.length === 0) {\n\t\treturn refreshed;\n\t}\n\tif (refreshed.type !== \"oauth\" || current.type !== \"oauth\") return refreshed;\n\tconst target = current.accounts.find((slot) => slot.access === current.access || slot.refresh === current.refresh);\n\tconst rotated = {\n\t\taccess: refreshed.access,\n\t\trefresh: refreshed.refresh,\n\t\texpires: refreshed.expires,\n\t};\n\tconst accounts = target\n\t\t? current.accounts.map((slot) => (slot === target ? { ...slot, ...rotated } : slot))\n\t\t: current.accounts;\n\treturn { ...current, ...rotated, accounts };\n}\n"]}
|
|
@@ -6,6 +6,12 @@ export interface OAuthPrompt {
|
|
|
6
6
|
message: string;
|
|
7
7
|
placeholder?: string;
|
|
8
8
|
allowEmpty?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Per-prompt cancellation, forwarded from `AuthPrompt.signal`: a provider
|
|
11
|
+
* aborts it when an out-of-band step resolves the flow, e.g. a manual-code
|
|
12
|
+
* prompt raced against a local callback server.
|
|
13
|
+
*/
|
|
14
|
+
signal?: AbortSignal;
|
|
9
15
|
}
|
|
10
16
|
/** Legacy extension OAuth authorization link. */
|
|
11
17
|
export interface OAuthAuthInfo {
|
|
@@ -27,6 +33,8 @@ export interface OAuthSelectOption {
|
|
|
27
33
|
export interface OAuthSelectPrompt {
|
|
28
34
|
message: string;
|
|
29
35
|
options: readonly OAuthSelectOption[];
|
|
36
|
+
/** Per-prompt cancellation, forwarded from `AuthPrompt.signal`. */
|
|
37
|
+
signal?: AbortSignal;
|
|
30
38
|
}
|
|
31
39
|
/** Callback surface retained only for coding-agent extension compatibility. */
|
|
32
40
|
export interface OAuthLoginCallbacks {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension-oauth-types.d.ts","sourceRoot":"","sources":["../../src/compat/extension-oauth-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,mEAAmE;AACnE,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC,qCAAqC;AACrC,MAAM,WAAW,WAAW;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,iDAAiD;AACjD,MAAM,WAAW,aAAa;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,uDAAuD;AACvD,MAAM,WAAW,mBAAmB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,SAAS,iBAAiB,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"extension-oauth-types.d.ts","sourceRoot":"","sources":["../../src/compat/extension-oauth-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,mEAAmE;AACnE,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC,qCAAqC;AACrC,MAAM,WAAW,WAAW;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;OAIG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB;AAED,iDAAiD;AACjD,MAAM,WAAW,aAAa;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,uDAAuD;AACvD,MAAM,WAAW,mBAAmB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACtC,mEAAmE;IACnE,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB;AAED,+EAA+E;AAC/E,MAAM,WAAW,mBAAmB;IACnC,MAAM,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;IAClC,YAAY,CAAC,IAAI,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAC9C,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/C,UAAU,CAAC,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,iBAAiB,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACjE,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB;AAED,YAAY,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension-oauth-types.js","sourceRoot":"","sources":["../../src/compat/extension-oauth-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { OAuthCredentials } from \"../auth/types.ts\";\n\n/** Legacy provider identifier accepted by extension OAuth APIs. */\nexport type OAuthProviderId = string;\n\n/** Legacy extension OAuth prompt. */\nexport interface OAuthPrompt {\n\tmessage: string;\n\tplaceholder?: string;\n\tallowEmpty?: boolean;\n}\n\n/** Legacy extension OAuth authorization link. */\nexport interface OAuthAuthInfo {\n\turl: string;\n\tinstructions?: string;\n}\n\n/** Legacy extension OAuth device-code notification. */\nexport interface OAuthDeviceCodeInfo {\n\tuserCode: string;\n\tverificationUri: string;\n\tintervalSeconds?: number;\n\texpiresInSeconds?: number;\n}\n\nexport interface OAuthSelectOption {\n\tid: string;\n\tlabel: string;\n\tdescription?: string;\n}\n\nexport interface OAuthSelectPrompt {\n\tmessage: string;\n\toptions: readonly OAuthSelectOption[];\n}\n\n/** Callback surface retained only for coding-agent extension compatibility. */\nexport interface OAuthLoginCallbacks {\n\tonAuth(info: OAuthAuthInfo): void;\n\tonDeviceCode(info: OAuthDeviceCodeInfo): void;\n\tonPrompt(prompt: OAuthPrompt): Promise<string>;\n\tonProgress?(message: string): void;\n\tonManualCodeInput?(): Promise<string>;\n\tonSelect(prompt: OAuthSelectPrompt): Promise<string | undefined>;\n\tsignal?: AbortSignal;\n}\n\nexport type { OAuthCredentials };\n"]}
|
|
1
|
+
{"version":3,"file":"extension-oauth-types.js","sourceRoot":"","sources":["../../src/compat/extension-oauth-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { OAuthCredentials } from \"../auth/types.ts\";\n\n/** Legacy provider identifier accepted by extension OAuth APIs. */\nexport type OAuthProviderId = string;\n\n/** Legacy extension OAuth prompt. */\nexport interface OAuthPrompt {\n\tmessage: string;\n\tplaceholder?: string;\n\tallowEmpty?: boolean;\n\t/**\n\t * Per-prompt cancellation, forwarded from `AuthPrompt.signal`: a provider\n\t * aborts it when an out-of-band step resolves the flow, e.g. a manual-code\n\t * prompt raced against a local callback server.\n\t */\n\tsignal?: AbortSignal;\n}\n\n/** Legacy extension OAuth authorization link. */\nexport interface OAuthAuthInfo {\n\turl: string;\n\tinstructions?: string;\n}\n\n/** Legacy extension OAuth device-code notification. */\nexport interface OAuthDeviceCodeInfo {\n\tuserCode: string;\n\tverificationUri: string;\n\tintervalSeconds?: number;\n\texpiresInSeconds?: number;\n}\n\nexport interface OAuthSelectOption {\n\tid: string;\n\tlabel: string;\n\tdescription?: string;\n}\n\nexport interface OAuthSelectPrompt {\n\tmessage: string;\n\toptions: readonly OAuthSelectOption[];\n\t/** Per-prompt cancellation, forwarded from `AuthPrompt.signal`. */\n\tsignal?: AbortSignal;\n}\n\n/** Callback surface retained only for coding-agent extension compatibility. */\nexport interface OAuthLoginCallbacks {\n\tonAuth(info: OAuthAuthInfo): void;\n\tonDeviceCode(info: OAuthDeviceCodeInfo): void;\n\tonPrompt(prompt: OAuthPrompt): Promise<string>;\n\tonProgress?(message: string): void;\n\tonManualCodeInput?(): Promise<string>;\n\tonSelect(prompt: OAuthSelectPrompt): Promise<string | undefined>;\n\tsignal?: AbortSignal;\n}\n\nexport type { OAuthCredentials };\n"]}
|
package/dist/models.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,uBAAuB,EAAoC,MAAM,mBAAmB,CAAC;AACnG,OAAO,KAAK,EACX,SAAS,EACT,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,UAAU,EACV,QAAQ,EACR,UAAU,EACV,eAAe,EACf,YAAY,EACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAuB,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACjG,OAAO,KAAK,EACX,GAAG,EACH,gBAAgB,EAChB,gBAAgB,EAChB,2BAA2B,EAC3B,OAAO,EACP,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,KAAK,EAEL,kBAAkB,EAClB,eAAe,EAEf,eAAe,EACf,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,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAoB/F;AAID,wBAAgB,0BAA0B,CAAC,IAAI,SAAS,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,kBAAkB,EAAE,CAUrG;AAED,wBAAgB,kBAAkB,CAAC,IAAI,SAAS,GAAG,EAClD,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,KAAK,EAAE,kBAAkB,GACvB,kBAAkB,CAgBpB;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,SAAS,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,OAAO,CAM3E;AAyCD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,SAAS,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,OAAO,CAMzE;AAgCD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,SAAS,GAAG,EAC9C,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,EACjC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,GAC/B,OAAO,CAGT"}
|
package/dist/models.js
CHANGED
|
@@ -644,6 +644,7 @@ const XHIGH_MODEL_IDS = [
|
|
|
644
644
|
"gpt-5.6-luna",
|
|
645
645
|
"gpt-5.6-sol",
|
|
646
646
|
"gpt-5.6-terra",
|
|
647
|
+
"gpt-6-astra",
|
|
647
648
|
"deepseek-v4-pro",
|
|
648
649
|
"deepseek-v4-flash",
|
|
649
650
|
"opus-4-6",
|
|
@@ -694,7 +695,7 @@ const OPENAI_MAX_APIS = [
|
|
|
694
695
|
"openai-completions",
|
|
695
696
|
];
|
|
696
697
|
/** Model family that accepts native `max` effort on OpenAI-compatible APIs. */
|
|
697
|
-
const
|
|
698
|
+
const OPENAI_MAX_MODEL_IDS = ["gpt-5.6-sol", "gpt-6-astra"];
|
|
698
699
|
const MAX_MODEL_IDS = [
|
|
699
700
|
"opus-4-6",
|
|
700
701
|
"opus-4.6",
|
|
@@ -709,7 +710,7 @@ const MAX_MODEL_IDS = [
|
|
|
709
710
|
function supportsMaxModel(model) {
|
|
710
711
|
if (!model.reasoning)
|
|
711
712
|
return false;
|
|
712
|
-
if (OPENAI_MAX_APIS.includes(model.api) && matchesModelFamily(model.id,
|
|
713
|
+
if (OPENAI_MAX_APIS.includes(model.api) && OPENAI_MAX_MODEL_IDS.some((id) => matchesModelFamily(model.id, id)))
|
|
713
714
|
return true;
|
|
714
715
|
return MAX_MODEL_IDS.some((id) => matchesModelFamily(model.id, id));
|
|
715
716
|
}
|