@omnicross/contracts 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 +21 -0
- package/README.md +15 -0
- package/dist/account-tokens-types.cjs +18 -0
- package/dist/account-tokens-types.d.cts +142 -0
- package/dist/account-tokens-types.d.ts +142 -0
- package/dist/account-tokens-types.js +0 -0
- package/dist/canonical-models.cjs +262 -0
- package/dist/canonical-models.d.cts +107 -0
- package/dist/canonical-models.d.ts +107 -0
- package/dist/canonical-models.js +232 -0
- package/dist/completion-types.cjs +18 -0
- package/dist/completion-types.d.cts +324 -0
- package/dist/completion-types.d.ts +324 -0
- package/dist/completion-types.js +0 -0
- package/dist/endpoint-resolver.cjs +54 -0
- package/dist/endpoint-resolver.d.cts +43 -0
- package/dist/endpoint-resolver.d.ts +43 -0
- package/dist/endpoint-resolver.js +29 -0
- package/dist/extended-context.cjs +39 -0
- package/dist/extended-context.d.cts +21 -0
- package/dist/extended-context.d.ts +21 -0
- package/dist/extended-context.js +13 -0
- package/dist/index.cjs +2724 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +2656 -0
- package/dist/llm-config-CQjOimv2.d.cts +390 -0
- package/dist/llm-config-D1jKQLVp.d.ts +390 -0
- package/dist/llm-config.cjs +18 -0
- package/dist/llm-config.d.cts +2 -0
- package/dist/llm-config.d.ts +2 -0
- package/dist/llm-config.js +0 -0
- package/dist/mcp-types.cjs +33 -0
- package/dist/mcp-types.d.cts +131 -0
- package/dist/mcp-types.d.ts +131 -0
- package/dist/mcp-types.js +8 -0
- package/dist/message-blocks.cjs +18 -0
- package/dist/message-blocks.d.cts +44 -0
- package/dist/message-blocks.d.ts +44 -0
- package/dist/message-blocks.js +0 -0
- package/dist/provider-presets/index.cjs +2183 -0
- package/dist/provider-presets/index.d.cts +104 -0
- package/dist/provider-presets/index.d.ts +104 -0
- package/dist/provider-presets/index.js +2143 -0
- package/dist/subscription-types.cjs +48 -0
- package/dist/subscription-types.d.cts +149 -0
- package/dist/subscription-types.d.ts +149 -0
- package/dist/subscription-types.js +22 -0
- package/dist/thinking-CBWSLel8.d.cts +33 -0
- package/dist/thinking-CBWSLel8.d.ts +33 -0
- package/dist/thinking-config.cjs +243 -0
- package/dist/thinking-config.d.cts +71 -0
- package/dist/thinking-config.d.ts +71 -0
- package/dist/thinking-config.js +205 -0
- package/dist/usage-types.cjs +18 -0
- package/dist/usage-types.d.cts +41 -0
- package/dist/usage-types.d.ts +41 -0
- package/dist/usage-types.js +0 -0
- package/dist/websearch-types.cjs +37 -0
- package/dist/websearch-types.d.cts +76 -0
- package/dist/websearch-types.d.ts +76 -0
- package/dist/websearch-types.js +11 -0
- package/package.json +116 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/subscription-types.ts
|
|
21
|
+
var subscription_types_exports = {};
|
|
22
|
+
__export(subscription_types_exports, {
|
|
23
|
+
legacyCliBackendToSubscriptionProvider: () => legacyCliBackendToSubscriptionProvider,
|
|
24
|
+
subscriptionTargetForSession: () => subscriptionTargetForSession
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(subscription_types_exports);
|
|
27
|
+
function legacyCliBackendToSubscriptionProvider(cliBackend) {
|
|
28
|
+
switch (cliBackend) {
|
|
29
|
+
case "claude-code":
|
|
30
|
+
return "claude";
|
|
31
|
+
case "codex":
|
|
32
|
+
return "codex";
|
|
33
|
+
case "gemini-cli":
|
|
34
|
+
return "gemini";
|
|
35
|
+
case "opencodego":
|
|
36
|
+
return "opencodego";
|
|
37
|
+
default:
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function subscriptionTargetForSession(session) {
|
|
42
|
+
return session.subscriptionProviderId ?? legacyCliBackendToSubscriptionProvider(session.cliBackend);
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
legacyCliBackendToSubscriptionProvider,
|
|
47
|
+
subscriptionTargetForSession
|
|
48
|
+
});
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-subscription dispatch contracts.
|
|
3
|
+
*
|
|
4
|
+
* Subscription providers are catalog entries that route an agent through a
|
|
5
|
+
* user's third-party subscription (Claude Pro/Max, ChatGPT Plus/Pro via Codex
|
|
6
|
+
* OAuth, Google Gemini OAuth, OpenCodeGo Bearer key). They are distinct from
|
|
7
|
+
* user-configured LLM providers.
|
|
8
|
+
*
|
|
9
|
+
* Holds the provider-id / OpenCodeGo / status / list contracts plus the resolver
|
|
10
|
+
* helpers the `@omnicross/*` packages consume.
|
|
11
|
+
*/
|
|
12
|
+
/** Stable IDs for built-in subscription providers. */
|
|
13
|
+
type SubscriptionProviderId = 'claude' | 'codex' | 'gemini' | 'opencodego';
|
|
14
|
+
/**
|
|
15
|
+
* OpenCodeGo routing scenarios, mirroring `_others/oc-go-cc/internal/router/`
|
|
16
|
+
* (and `_others/oc-go-cc/configs/config.example.json`).
|
|
17
|
+
*
|
|
18
|
+
* `background` is DORMANT in this version: the scenario router never
|
|
19
|
+
* auto-selects it (keyword-driven selection is a downstream change). It is
|
|
20
|
+
* reachable ONLY when a user explicitly keys `background` in
|
|
21
|
+
* `OpenCodeGoTokenConfig.modelMap` / `fallbacks`.
|
|
22
|
+
*/
|
|
23
|
+
type OpenCodeGoScenario = 'default' | 'long_context' | 'think' | 'complex' | 'fast' | 'background';
|
|
24
|
+
/** One entry of the OpenCodeGo model map — selected by the scenario router. */
|
|
25
|
+
interface OpenCodeGoModelEntry {
|
|
26
|
+
/** Provider model id sent upstream (e.g. `kimi-k2.6`, `minimax-m2.5`). */
|
|
27
|
+
modelId: string;
|
|
28
|
+
/**
|
|
29
|
+
* Which opencode provider HALF this model lives on. Mirrors the reference
|
|
30
|
+
* `ModelConfig.Provider` (`_others/oc-go-cc`). When ABSENT it defaults to
|
|
31
|
+
* `'go'` (the reference's `Provider("")` → `opencode-go`), so every existing
|
|
32
|
+
* stored config behaves byte-identically (no zen traffic). The built-in
|
|
33
|
+
* default `modelMap`/`fallbacks` are entirely `'go'`; a `'zen'` model is
|
|
34
|
+
* reachable ONLY via a user-supplied entry that explicitly sets this field
|
|
35
|
+
* (strict user-only parity, mirroring the reference's `model_overrides`).
|
|
36
|
+
*/
|
|
37
|
+
provider?: 'go' | 'zen';
|
|
38
|
+
/** Optional temperature override. */
|
|
39
|
+
temperature?: number;
|
|
40
|
+
/** Optional max_tokens override. */
|
|
41
|
+
maxTokens?: number;
|
|
42
|
+
/** When set, the scenario router only picks this entry when the estimated
|
|
43
|
+
* cl100k_base input-token count meets/exceeds the threshold. */
|
|
44
|
+
contextThreshold?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Persisted OpenCodeGo subscription configuration. Mirrors the
|
|
48
|
+
* Claude/Codex/Gemini siblings in `account-tokens-types.ts` but is
|
|
49
|
+
* static-bearer only (no OAuth, no refresh token).
|
|
50
|
+
*/
|
|
51
|
+
interface OpenCodeGoTokenConfig {
|
|
52
|
+
/** No OAuth — only manual API key entry is supported. */
|
|
53
|
+
authMethod: 'manual';
|
|
54
|
+
status: 'unconfigured' | 'configured' | 'error';
|
|
55
|
+
/** Encrypted on disk; decrypted in memory only via the host's token store. */
|
|
56
|
+
apiKey?: string;
|
|
57
|
+
/** Optional override of the default OpenCodeGo upstream host. Applies to the
|
|
58
|
+
* GO half ONLY (mirrors the reference's `OC_GO_CC_OPENCODE_URL`); the zen
|
|
59
|
+
* half is overridden by `zenBaseUrl`. */
|
|
60
|
+
baseUrl?: string;
|
|
61
|
+
/** Optional override of the default opencode-ZEN upstream host. Applies to the
|
|
62
|
+
* ZEN half ONLY (mirrors the reference's `OC_GO_CC_OPENCODE_ZEN_URL`). When
|
|
63
|
+
* unset, zen models resolve under the built-in zen constants. A go-half
|
|
64
|
+
* override (`baseUrl`) NEVER redirects zen traffic and vice-versa. */
|
|
65
|
+
zenBaseUrl?: string;
|
|
66
|
+
/** Optional override of the built-in model map per scenario. */
|
|
67
|
+
modelMap?: Partial<Record<OpenCodeGoScenario, OpenCodeGoModelEntry>>;
|
|
68
|
+
/** Optional override of the built-in fallback chain per scenario. */
|
|
69
|
+
fallbacks?: Partial<Record<OpenCodeGoScenario, OpenCodeGoModelEntry[]>>;
|
|
70
|
+
lastRefreshedAt?: string;
|
|
71
|
+
errorMessage?: string;
|
|
72
|
+
}
|
|
73
|
+
/** Sanitized view of `OpenCodeGoTokenConfig` for client display. */
|
|
74
|
+
interface OpenCodeGoTokenSanitized {
|
|
75
|
+
authMethod: 'manual';
|
|
76
|
+
status: 'unconfigured' | 'configured' | 'error';
|
|
77
|
+
hasApiKey: boolean;
|
|
78
|
+
baseUrl?: string;
|
|
79
|
+
/** Mirrors `OpenCodeGoTokenConfig.zenBaseUrl` (zen-half host override) for
|
|
80
|
+
* client display parity with `baseUrl`. */
|
|
81
|
+
zenBaseUrl?: string;
|
|
82
|
+
lastRefreshedAt?: string;
|
|
83
|
+
errorMessage?: string;
|
|
84
|
+
}
|
|
85
|
+
/** Status of a single subscription provider, surfaced by `subscription:status`. */
|
|
86
|
+
interface SubscriptionStatusEntry {
|
|
87
|
+
providerId: SubscriptionProviderId;
|
|
88
|
+
ok: boolean;
|
|
89
|
+
/** Machine-readable reason when `ok === false`. */
|
|
90
|
+
reason?: 'missing-credential' | 'expired' | 'reauth-required' | 'refresh-failed' | 'not-refreshable' | 'unknown';
|
|
91
|
+
/** ISO timestamp when the credential expires (OAuth providers only). */
|
|
92
|
+
expiresAt?: string;
|
|
93
|
+
}
|
|
94
|
+
/** Catalog entry returned by `subscription:list`. */
|
|
95
|
+
interface SubscriptionListEntry {
|
|
96
|
+
providerId: SubscriptionProviderId;
|
|
97
|
+
displayName: string;
|
|
98
|
+
/** Auth model — same discriminator as the dispatch `AuthStrategy.kind`. */
|
|
99
|
+
kind: 'pass-through' | 'oauth-bearer' | 'static-bearer';
|
|
100
|
+
credentialStatus: SubscriptionStatusEntry;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Map a legacy `cliBackend` engine-marker token to the subscription-target
|
|
104
|
+
* `SubscriptionProviderId` it used to imply. Pre-D6
|
|
105
|
+
* (`provider-proxy-transformer-matrix`) the subscription target was DERIVED
|
|
106
|
+
* from `cliBackend`; this function preserves that derivation as a backfill /
|
|
107
|
+
* in-flight fallback only. New sessions carry an explicit
|
|
108
|
+
* `subscriptionProviderId` and SHOULD NOT rely on this.
|
|
109
|
+
*
|
|
110
|
+
* `'opencodego'` is intentionally accepted as an input here even though it is
|
|
111
|
+
* no longer a `CodeCliBackend` member — the migration backfill reads raw DB
|
|
112
|
+
* rows that may still hold the legacy token.
|
|
113
|
+
*/
|
|
114
|
+
declare function legacyCliBackendToSubscriptionProvider(cliBackend: string | null | undefined): SubscriptionProviderId | null;
|
|
115
|
+
/**
|
|
116
|
+
* Resolve the subscription-target `SubscriptionProviderId` for a session.
|
|
117
|
+
*
|
|
118
|
+
* Precedence (D6): the EXPLICIT `subscriptionProviderId` field wins. When it
|
|
119
|
+
* is unset (in-flight rows created before the field existed / before backfill),
|
|
120
|
+
* fall back to the legacy `cliBackend`-derived mapping. Returns `null` when
|
|
121
|
+
* neither resolves — the caller treats that as "no subscription target".
|
|
122
|
+
*
|
|
123
|
+
* This is the SINGLE place engine code should consult to find a session's
|
|
124
|
+
* upstream subscription Provider — never the `cliBackend` token directly.
|
|
125
|
+
*/
|
|
126
|
+
declare function subscriptionTargetForSession(session: {
|
|
127
|
+
subscriptionProviderId?: SubscriptionProviderId | null;
|
|
128
|
+
cliBackend?: string | null;
|
|
129
|
+
}): SubscriptionProviderId | null;
|
|
130
|
+
/**
|
|
131
|
+
* Provider-channel axis (Axis 2) — HOW a session's provider credential is
|
|
132
|
+
* sourced / routed, orthogonal to the engine (Axis 1, `EngineType`).
|
|
133
|
+
*
|
|
134
|
+
* - `native` — the provider's own egress (e.g. a CLI binary talking to
|
|
135
|
+
* its own backend, or a direct first-party API). Replaces
|
|
136
|
+
* the old `EngineSource = 'cli'` value.
|
|
137
|
+
* - `subscription` — routed through a user's third-party subscription
|
|
138
|
+
* (Claude Pro/Max, Codex/ChatGPT, Gemini, OpenCodeGo).
|
|
139
|
+
* - `relay` — routed through a relay / proxy endpoint.
|
|
140
|
+
* - `api-key` — routed with a user-supplied BYO API key.
|
|
141
|
+
*
|
|
142
|
+
* Renamed from `EngineSource` and value-space-expanded by the
|
|
143
|
+
* `engine-provider-decouple` change (Phase 0). The engine type is now a pure
|
|
144
|
+
* `f(engine)` lookup and no longer reads this axis; per-channel injection
|
|
145
|
+
* wiring lands in Phase 1b.
|
|
146
|
+
*/
|
|
147
|
+
type ProviderChannel = 'native' | 'subscription' | 'relay' | 'api-key';
|
|
148
|
+
|
|
149
|
+
export { type OpenCodeGoModelEntry, type OpenCodeGoScenario, type OpenCodeGoTokenConfig, type OpenCodeGoTokenSanitized, type ProviderChannel, type SubscriptionListEntry, type SubscriptionProviderId, type SubscriptionStatusEntry, legacyCliBackendToSubscriptionProvider, subscriptionTargetForSession };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-subscription dispatch contracts.
|
|
3
|
+
*
|
|
4
|
+
* Subscription providers are catalog entries that route an agent through a
|
|
5
|
+
* user's third-party subscription (Claude Pro/Max, ChatGPT Plus/Pro via Codex
|
|
6
|
+
* OAuth, Google Gemini OAuth, OpenCodeGo Bearer key). They are distinct from
|
|
7
|
+
* user-configured LLM providers.
|
|
8
|
+
*
|
|
9
|
+
* Holds the provider-id / OpenCodeGo / status / list contracts plus the resolver
|
|
10
|
+
* helpers the `@omnicross/*` packages consume.
|
|
11
|
+
*/
|
|
12
|
+
/** Stable IDs for built-in subscription providers. */
|
|
13
|
+
type SubscriptionProviderId = 'claude' | 'codex' | 'gemini' | 'opencodego';
|
|
14
|
+
/**
|
|
15
|
+
* OpenCodeGo routing scenarios, mirroring `_others/oc-go-cc/internal/router/`
|
|
16
|
+
* (and `_others/oc-go-cc/configs/config.example.json`).
|
|
17
|
+
*
|
|
18
|
+
* `background` is DORMANT in this version: the scenario router never
|
|
19
|
+
* auto-selects it (keyword-driven selection is a downstream change). It is
|
|
20
|
+
* reachable ONLY when a user explicitly keys `background` in
|
|
21
|
+
* `OpenCodeGoTokenConfig.modelMap` / `fallbacks`.
|
|
22
|
+
*/
|
|
23
|
+
type OpenCodeGoScenario = 'default' | 'long_context' | 'think' | 'complex' | 'fast' | 'background';
|
|
24
|
+
/** One entry of the OpenCodeGo model map — selected by the scenario router. */
|
|
25
|
+
interface OpenCodeGoModelEntry {
|
|
26
|
+
/** Provider model id sent upstream (e.g. `kimi-k2.6`, `minimax-m2.5`). */
|
|
27
|
+
modelId: string;
|
|
28
|
+
/**
|
|
29
|
+
* Which opencode provider HALF this model lives on. Mirrors the reference
|
|
30
|
+
* `ModelConfig.Provider` (`_others/oc-go-cc`). When ABSENT it defaults to
|
|
31
|
+
* `'go'` (the reference's `Provider("")` → `opencode-go`), so every existing
|
|
32
|
+
* stored config behaves byte-identically (no zen traffic). The built-in
|
|
33
|
+
* default `modelMap`/`fallbacks` are entirely `'go'`; a `'zen'` model is
|
|
34
|
+
* reachable ONLY via a user-supplied entry that explicitly sets this field
|
|
35
|
+
* (strict user-only parity, mirroring the reference's `model_overrides`).
|
|
36
|
+
*/
|
|
37
|
+
provider?: 'go' | 'zen';
|
|
38
|
+
/** Optional temperature override. */
|
|
39
|
+
temperature?: number;
|
|
40
|
+
/** Optional max_tokens override. */
|
|
41
|
+
maxTokens?: number;
|
|
42
|
+
/** When set, the scenario router only picks this entry when the estimated
|
|
43
|
+
* cl100k_base input-token count meets/exceeds the threshold. */
|
|
44
|
+
contextThreshold?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Persisted OpenCodeGo subscription configuration. Mirrors the
|
|
48
|
+
* Claude/Codex/Gemini siblings in `account-tokens-types.ts` but is
|
|
49
|
+
* static-bearer only (no OAuth, no refresh token).
|
|
50
|
+
*/
|
|
51
|
+
interface OpenCodeGoTokenConfig {
|
|
52
|
+
/** No OAuth — only manual API key entry is supported. */
|
|
53
|
+
authMethod: 'manual';
|
|
54
|
+
status: 'unconfigured' | 'configured' | 'error';
|
|
55
|
+
/** Encrypted on disk; decrypted in memory only via the host's token store. */
|
|
56
|
+
apiKey?: string;
|
|
57
|
+
/** Optional override of the default OpenCodeGo upstream host. Applies to the
|
|
58
|
+
* GO half ONLY (mirrors the reference's `OC_GO_CC_OPENCODE_URL`); the zen
|
|
59
|
+
* half is overridden by `zenBaseUrl`. */
|
|
60
|
+
baseUrl?: string;
|
|
61
|
+
/** Optional override of the default opencode-ZEN upstream host. Applies to the
|
|
62
|
+
* ZEN half ONLY (mirrors the reference's `OC_GO_CC_OPENCODE_ZEN_URL`). When
|
|
63
|
+
* unset, zen models resolve under the built-in zen constants. A go-half
|
|
64
|
+
* override (`baseUrl`) NEVER redirects zen traffic and vice-versa. */
|
|
65
|
+
zenBaseUrl?: string;
|
|
66
|
+
/** Optional override of the built-in model map per scenario. */
|
|
67
|
+
modelMap?: Partial<Record<OpenCodeGoScenario, OpenCodeGoModelEntry>>;
|
|
68
|
+
/** Optional override of the built-in fallback chain per scenario. */
|
|
69
|
+
fallbacks?: Partial<Record<OpenCodeGoScenario, OpenCodeGoModelEntry[]>>;
|
|
70
|
+
lastRefreshedAt?: string;
|
|
71
|
+
errorMessage?: string;
|
|
72
|
+
}
|
|
73
|
+
/** Sanitized view of `OpenCodeGoTokenConfig` for client display. */
|
|
74
|
+
interface OpenCodeGoTokenSanitized {
|
|
75
|
+
authMethod: 'manual';
|
|
76
|
+
status: 'unconfigured' | 'configured' | 'error';
|
|
77
|
+
hasApiKey: boolean;
|
|
78
|
+
baseUrl?: string;
|
|
79
|
+
/** Mirrors `OpenCodeGoTokenConfig.zenBaseUrl` (zen-half host override) for
|
|
80
|
+
* client display parity with `baseUrl`. */
|
|
81
|
+
zenBaseUrl?: string;
|
|
82
|
+
lastRefreshedAt?: string;
|
|
83
|
+
errorMessage?: string;
|
|
84
|
+
}
|
|
85
|
+
/** Status of a single subscription provider, surfaced by `subscription:status`. */
|
|
86
|
+
interface SubscriptionStatusEntry {
|
|
87
|
+
providerId: SubscriptionProviderId;
|
|
88
|
+
ok: boolean;
|
|
89
|
+
/** Machine-readable reason when `ok === false`. */
|
|
90
|
+
reason?: 'missing-credential' | 'expired' | 'reauth-required' | 'refresh-failed' | 'not-refreshable' | 'unknown';
|
|
91
|
+
/** ISO timestamp when the credential expires (OAuth providers only). */
|
|
92
|
+
expiresAt?: string;
|
|
93
|
+
}
|
|
94
|
+
/** Catalog entry returned by `subscription:list`. */
|
|
95
|
+
interface SubscriptionListEntry {
|
|
96
|
+
providerId: SubscriptionProviderId;
|
|
97
|
+
displayName: string;
|
|
98
|
+
/** Auth model — same discriminator as the dispatch `AuthStrategy.kind`. */
|
|
99
|
+
kind: 'pass-through' | 'oauth-bearer' | 'static-bearer';
|
|
100
|
+
credentialStatus: SubscriptionStatusEntry;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Map a legacy `cliBackend` engine-marker token to the subscription-target
|
|
104
|
+
* `SubscriptionProviderId` it used to imply. Pre-D6
|
|
105
|
+
* (`provider-proxy-transformer-matrix`) the subscription target was DERIVED
|
|
106
|
+
* from `cliBackend`; this function preserves that derivation as a backfill /
|
|
107
|
+
* in-flight fallback only. New sessions carry an explicit
|
|
108
|
+
* `subscriptionProviderId` and SHOULD NOT rely on this.
|
|
109
|
+
*
|
|
110
|
+
* `'opencodego'` is intentionally accepted as an input here even though it is
|
|
111
|
+
* no longer a `CodeCliBackend` member — the migration backfill reads raw DB
|
|
112
|
+
* rows that may still hold the legacy token.
|
|
113
|
+
*/
|
|
114
|
+
declare function legacyCliBackendToSubscriptionProvider(cliBackend: string | null | undefined): SubscriptionProviderId | null;
|
|
115
|
+
/**
|
|
116
|
+
* Resolve the subscription-target `SubscriptionProviderId` for a session.
|
|
117
|
+
*
|
|
118
|
+
* Precedence (D6): the EXPLICIT `subscriptionProviderId` field wins. When it
|
|
119
|
+
* is unset (in-flight rows created before the field existed / before backfill),
|
|
120
|
+
* fall back to the legacy `cliBackend`-derived mapping. Returns `null` when
|
|
121
|
+
* neither resolves — the caller treats that as "no subscription target".
|
|
122
|
+
*
|
|
123
|
+
* This is the SINGLE place engine code should consult to find a session's
|
|
124
|
+
* upstream subscription Provider — never the `cliBackend` token directly.
|
|
125
|
+
*/
|
|
126
|
+
declare function subscriptionTargetForSession(session: {
|
|
127
|
+
subscriptionProviderId?: SubscriptionProviderId | null;
|
|
128
|
+
cliBackend?: string | null;
|
|
129
|
+
}): SubscriptionProviderId | null;
|
|
130
|
+
/**
|
|
131
|
+
* Provider-channel axis (Axis 2) — HOW a session's provider credential is
|
|
132
|
+
* sourced / routed, orthogonal to the engine (Axis 1, `EngineType`).
|
|
133
|
+
*
|
|
134
|
+
* - `native` — the provider's own egress (e.g. a CLI binary talking to
|
|
135
|
+
* its own backend, or a direct first-party API). Replaces
|
|
136
|
+
* the old `EngineSource = 'cli'` value.
|
|
137
|
+
* - `subscription` — routed through a user's third-party subscription
|
|
138
|
+
* (Claude Pro/Max, Codex/ChatGPT, Gemini, OpenCodeGo).
|
|
139
|
+
* - `relay` — routed through a relay / proxy endpoint.
|
|
140
|
+
* - `api-key` — routed with a user-supplied BYO API key.
|
|
141
|
+
*
|
|
142
|
+
* Renamed from `EngineSource` and value-space-expanded by the
|
|
143
|
+
* `engine-provider-decouple` change (Phase 0). The engine type is now a pure
|
|
144
|
+
* `f(engine)` lookup and no longer reads this axis; per-channel injection
|
|
145
|
+
* wiring lands in Phase 1b.
|
|
146
|
+
*/
|
|
147
|
+
type ProviderChannel = 'native' | 'subscription' | 'relay' | 'api-key';
|
|
148
|
+
|
|
149
|
+
export { type OpenCodeGoModelEntry, type OpenCodeGoScenario, type OpenCodeGoTokenConfig, type OpenCodeGoTokenSanitized, type ProviderChannel, type SubscriptionListEntry, type SubscriptionProviderId, type SubscriptionStatusEntry, legacyCliBackendToSubscriptionProvider, subscriptionTargetForSession };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/subscription-types.ts
|
|
2
|
+
function legacyCliBackendToSubscriptionProvider(cliBackend) {
|
|
3
|
+
switch (cliBackend) {
|
|
4
|
+
case "claude-code":
|
|
5
|
+
return "claude";
|
|
6
|
+
case "codex":
|
|
7
|
+
return "codex";
|
|
8
|
+
case "gemini-cli":
|
|
9
|
+
return "gemini";
|
|
10
|
+
case "opencodego":
|
|
11
|
+
return "opencodego";
|
|
12
|
+
default:
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function subscriptionTargetForSession(session) {
|
|
17
|
+
return session.subscriptionProviderId ?? legacyCliBackendToSubscriptionProvider(session.cliBackend);
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
legacyCliBackendToSubscriptionProvider,
|
|
21
|
+
subscriptionTargetForSession
|
|
22
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module shared/completion-types/thinking
|
|
3
|
+
*
|
|
4
|
+
* Thinking / reasoning effort level + reasoning-config types. Provider-
|
|
5
|
+
* neutral surface used by both OpenAI- and Anthropic-style requests.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Thinking/reasoning effort levels
|
|
9
|
+
* Used to configure the amount of reasoning in model responses
|
|
10
|
+
*/
|
|
11
|
+
type ThinkLevel = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
12
|
+
/**
|
|
13
|
+
* Thinking content with optional signature for verification
|
|
14
|
+
*/
|
|
15
|
+
interface ThinkingContent {
|
|
16
|
+
/** The thinking/reasoning content */
|
|
17
|
+
content: string;
|
|
18
|
+
/** Optional cryptographic signature for thinking verification */
|
|
19
|
+
signature?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Reasoning configuration for model requests
|
|
23
|
+
*/
|
|
24
|
+
interface ReasoningConfig {
|
|
25
|
+
/** Reasoning effort level */
|
|
26
|
+
effort?: ThinkLevel;
|
|
27
|
+
/** Maximum tokens for reasoning */
|
|
28
|
+
max_tokens?: number;
|
|
29
|
+
/** Whether reasoning is enabled */
|
|
30
|
+
enabled?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type { ReasoningConfig as R, ThinkLevel as T, ThinkingContent as a };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module shared/completion-types/thinking
|
|
3
|
+
*
|
|
4
|
+
* Thinking / reasoning effort level + reasoning-config types. Provider-
|
|
5
|
+
* neutral surface used by both OpenAI- and Anthropic-style requests.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Thinking/reasoning effort levels
|
|
9
|
+
* Used to configure the amount of reasoning in model responses
|
|
10
|
+
*/
|
|
11
|
+
type ThinkLevel = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
12
|
+
/**
|
|
13
|
+
* Thinking content with optional signature for verification
|
|
14
|
+
*/
|
|
15
|
+
interface ThinkingContent {
|
|
16
|
+
/** The thinking/reasoning content */
|
|
17
|
+
content: string;
|
|
18
|
+
/** Optional cryptographic signature for thinking verification */
|
|
19
|
+
signature?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Reasoning configuration for model requests
|
|
23
|
+
*/
|
|
24
|
+
interface ReasoningConfig {
|
|
25
|
+
/** Reasoning effort level */
|
|
26
|
+
effort?: ThinkLevel;
|
|
27
|
+
/** Maximum tokens for reasoning */
|
|
28
|
+
max_tokens?: number;
|
|
29
|
+
/** Whether reasoning is enabled */
|
|
30
|
+
enabled?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type { ReasoningConfig as R, ThinkLevel as T, ThinkingContent as a };
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/thinking-config.ts
|
|
21
|
+
var thinking_config_exports = {};
|
|
22
|
+
__export(thinking_config_exports, {
|
|
23
|
+
CANNOT_DISABLE_THINKING_PATTERNS: () => CANNOT_DISABLE_THINKING_PATTERNS,
|
|
24
|
+
DEFAULT_MAX_TOKENS: () => DEFAULT_MAX_TOKENS,
|
|
25
|
+
EFFORT_RATIO: () => EFFORT_RATIO,
|
|
26
|
+
REASONING_MODEL_PATTERNS: () => REASONING_MODEL_PATTERNS,
|
|
27
|
+
THINKING_TOKEN_MAP: () => THINKING_TOKEN_MAP,
|
|
28
|
+
buildAnthropicThinking: () => buildAnthropicThinking,
|
|
29
|
+
buildGeminiThinkingConfig: () => buildGeminiThinkingConfig,
|
|
30
|
+
buildQwenThinkingConfig: () => buildQwenThinkingConfig,
|
|
31
|
+
calculateThinkingBudget: () => calculateThinkingBudget,
|
|
32
|
+
canDisableThinking: () => canDisableThinking,
|
|
33
|
+
findTokenLimit: () => findTokenLimit,
|
|
34
|
+
getClaudeMaxTokens: () => getClaudeMaxTokens,
|
|
35
|
+
getOpenAIReasoningEffort: () => getOpenAIReasoningEffort,
|
|
36
|
+
isReasoningModel: () => isReasoningModel
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(thinking_config_exports);
|
|
39
|
+
var EFFORT_RATIO = {
|
|
40
|
+
none: 0.01,
|
|
41
|
+
minimal: 0.02,
|
|
42
|
+
low: 0.05,
|
|
43
|
+
medium: 0.5,
|
|
44
|
+
high: 0.8,
|
|
45
|
+
xhigh: 0.92,
|
|
46
|
+
max: 0.95
|
|
47
|
+
};
|
|
48
|
+
var DEFAULT_MAX_TOKENS = 4096;
|
|
49
|
+
var THINKING_TOKEN_MAP = {
|
|
50
|
+
// Gemini
|
|
51
|
+
"gemini-2\\.5-flash-lite": { min: 512, max: 24576 },
|
|
52
|
+
"gemini-.*-flash": { min: 0, max: 24576 },
|
|
53
|
+
"gemini-.*-pro": { min: 128, max: 32768 },
|
|
54
|
+
// Qwen
|
|
55
|
+
"qwen3-235b-a22b-thinking": { min: 0, max: 81920 },
|
|
56
|
+
"qwen3-30b-a3b-thinking": { min: 0, max: 81920 },
|
|
57
|
+
"qwen3-vl-235b-a22b-thinking": { min: 0, max: 81920 },
|
|
58
|
+
"qwen3-vl-30b-a3b-thinking": { min: 0, max: 81920 },
|
|
59
|
+
"qwen-plus-2025": { min: 0, max: 38912 },
|
|
60
|
+
"qwen-plus": { min: 0, max: 81920 },
|
|
61
|
+
"qwen-turbo": { min: 0, max: 38912 },
|
|
62
|
+
"qwen-flash": { min: 0, max: 81920 },
|
|
63
|
+
"qwen3-": { min: 1024, max: 38912 },
|
|
64
|
+
qwq: { min: 1024, max: 38912 },
|
|
65
|
+
// Claude (incl. AWS Bedrock, GCP Vertex AI)
|
|
66
|
+
"claude-opus-4[.-]7": { min: 1024, max: 128e3 },
|
|
67
|
+
"claude-(sonnet|opus)-4[.-]6": { min: 1024, max: 128e3 },
|
|
68
|
+
"claude-3[.-]7.*sonnet": { min: 1024, max: 64e3 },
|
|
69
|
+
"claude-(haiku|sonnet|opus)-4[.-]5": { min: 1024, max: 64e3 },
|
|
70
|
+
"claude-opus-4[.-]1": { min: 1024, max: 32e3 },
|
|
71
|
+
"claude-sonnet-4": { min: 1024, max: 64e3 },
|
|
72
|
+
"claude-opus-4": { min: 1024, max: 32e3 },
|
|
73
|
+
"claude-3[.-]5-sonnet": { min: 1024, max: 64e3 },
|
|
74
|
+
// OpenAI o-series
|
|
75
|
+
"o1-preview": { min: 0, max: 32768 },
|
|
76
|
+
"o1-mini": { min: 0, max: 32768 },
|
|
77
|
+
"o1-pro": { min: 0, max: 32768 },
|
|
78
|
+
"o3-mini": { min: 0, max: 32768 },
|
|
79
|
+
o3: { min: 0, max: 65536 },
|
|
80
|
+
"o4-mini": { min: 0, max: 32768 },
|
|
81
|
+
// GPT-5 series (Response API reasoning models)
|
|
82
|
+
"gpt-5\\.5": { min: 0, max: 128e3 },
|
|
83
|
+
"gpt-5\\.4": { min: 0, max: 128e3 },
|
|
84
|
+
"gpt-5\\.3": { min: 0, max: 128e3 },
|
|
85
|
+
"gpt-5\\.2": { min: 0, max: 65536 },
|
|
86
|
+
"gpt-5\\.1": { min: 0, max: 65536 },
|
|
87
|
+
"gpt-5": { min: 0, max: 65536 },
|
|
88
|
+
// DeepSeek
|
|
89
|
+
"deepseek-v4-pro": { min: 0, max: 32768 },
|
|
90
|
+
"deepseek-v4-flash": { min: 0, max: 32768 },
|
|
91
|
+
"deepseek-r1": { min: 0, max: 32768 },
|
|
92
|
+
"deepseek-reasoner": { min: 0, max: 32768 },
|
|
93
|
+
// Baichuan
|
|
94
|
+
"baichuan-m2": { min: 0, max: 3e4 },
|
|
95
|
+
"baichuan-m3": { min: 0, max: 3e4 },
|
|
96
|
+
// Grok
|
|
97
|
+
"grok-3": { min: 0, max: 32768 },
|
|
98
|
+
// Zhipu GLM
|
|
99
|
+
"glm.*zero": { min: 0, max: 16384 },
|
|
100
|
+
// Hunyuan
|
|
101
|
+
"hunyuan.*t1": { min: 0, max: 16384 },
|
|
102
|
+
// Doubao
|
|
103
|
+
"doubao.*think": { min: 0, max: 16384 }
|
|
104
|
+
};
|
|
105
|
+
var REASONING_MODEL_PATTERNS = [
|
|
106
|
+
/^o[134](-mini|-preview|-pro)?$/i,
|
|
107
|
+
/^gpt-5(\.\d)?(-pro|-codex|-codex-max)?/i,
|
|
108
|
+
/claude.*3[.-]?5.*sonnet|claude.*sonnet.*3[.-]?5|claude-sonnet-4|claude-opus-4|claude-(haiku|sonnet|opus)-4[.-]?5/i,
|
|
109
|
+
/gemini.*(2\.0|2-|2\.5|3).*flash|gemini.*(2\.5|3).*pro|gemini.*think/i,
|
|
110
|
+
/grok-3/i,
|
|
111
|
+
/qwq|qwen.*qwq|qwen.*thinking/i,
|
|
112
|
+
/deepseek-v4|deepseek.*r1|r1.*deepseek|deepseek-reasoner/i,
|
|
113
|
+
/glm.*zero/i,
|
|
114
|
+
/hunyuan.*t1/i,
|
|
115
|
+
/doubao.*think/i,
|
|
116
|
+
/baichuan-m[23]/i
|
|
117
|
+
];
|
|
118
|
+
var CANNOT_DISABLE_THINKING_PATTERNS = [
|
|
119
|
+
/gemini.*3.*pro/i,
|
|
120
|
+
/gemini.*2\.5.*pro/i,
|
|
121
|
+
/^o1-pro$/i
|
|
122
|
+
];
|
|
123
|
+
function isReasoningModel(modelId) {
|
|
124
|
+
if (!modelId) return false;
|
|
125
|
+
return REASONING_MODEL_PATTERNS.some((pattern) => pattern.test(modelId));
|
|
126
|
+
}
|
|
127
|
+
function canDisableThinking(modelId) {
|
|
128
|
+
if (!modelId) return true;
|
|
129
|
+
return !CANNOT_DISABLE_THINKING_PATTERNS.some((pattern) => pattern.test(modelId));
|
|
130
|
+
}
|
|
131
|
+
function findTokenLimit(modelOrId) {
|
|
132
|
+
if (!modelOrId) return null;
|
|
133
|
+
if (typeof modelOrId === "object") {
|
|
134
|
+
if (modelOrId.thinkingTokenLimit) return modelOrId.thinkingTokenLimit;
|
|
135
|
+
return findTokenLimit(modelOrId.id);
|
|
136
|
+
}
|
|
137
|
+
const lowerModelId = modelOrId.toLowerCase();
|
|
138
|
+
for (const [pattern, limit] of Object.entries(THINKING_TOKEN_MAP)) {
|
|
139
|
+
const regex = new RegExp(pattern, "i");
|
|
140
|
+
if (regex.test(lowerModelId)) {
|
|
141
|
+
return limit;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
function calculateThinkingBudget(modelId, level, userMaxTokens) {
|
|
147
|
+
if (level === "none") {
|
|
148
|
+
const tokenLimit2 = findTokenLimit(modelId);
|
|
149
|
+
if (tokenLimit2 && tokenLimit2.min > 0) {
|
|
150
|
+
return tokenLimit2.min;
|
|
151
|
+
}
|
|
152
|
+
return void 0;
|
|
153
|
+
}
|
|
154
|
+
const tokenLimit = findTokenLimit(modelId);
|
|
155
|
+
const ratio = EFFORT_RATIO[level];
|
|
156
|
+
if (!tokenLimit) {
|
|
157
|
+
if (userMaxTokens) {
|
|
158
|
+
const maxBudget = Math.floor(userMaxTokens * 0.75);
|
|
159
|
+
return Math.floor(Math.min(userMaxTokens * ratio, maxBudget));
|
|
160
|
+
}
|
|
161
|
+
return void 0;
|
|
162
|
+
}
|
|
163
|
+
const formulaResult = Math.floor((tokenLimit.max - tokenLimit.min) * ratio + tokenLimit.min);
|
|
164
|
+
if (userMaxTokens !== void 0) {
|
|
165
|
+
const maxBudgetFromUserTokens = Math.floor(userMaxTokens * Math.min(ratio, 0.75));
|
|
166
|
+
return Math.max(tokenLimit.min, Math.min(formulaResult, maxBudgetFromUserTokens));
|
|
167
|
+
}
|
|
168
|
+
return formulaResult;
|
|
169
|
+
}
|
|
170
|
+
function getClaudeMaxTokens(userMaxTokens, thinkingBudget) {
|
|
171
|
+
if (!userMaxTokens) return void 0;
|
|
172
|
+
if (!thinkingBudget) return userMaxTokens;
|
|
173
|
+
const outputTokens = userMaxTokens - thinkingBudget;
|
|
174
|
+
return outputTokens > 0 ? outputTokens : void 0;
|
|
175
|
+
}
|
|
176
|
+
function getOpenAIReasoningEffort(level) {
|
|
177
|
+
switch (level) {
|
|
178
|
+
case "none":
|
|
179
|
+
return "none";
|
|
180
|
+
case "minimal":
|
|
181
|
+
return "minimal";
|
|
182
|
+
case "low":
|
|
183
|
+
return "low";
|
|
184
|
+
case "medium":
|
|
185
|
+
return "medium";
|
|
186
|
+
case "high":
|
|
187
|
+
return "high";
|
|
188
|
+
case "xhigh":
|
|
189
|
+
return "xhigh";
|
|
190
|
+
case "max":
|
|
191
|
+
return "high";
|
|
192
|
+
default:
|
|
193
|
+
return void 0;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function buildGeminiThinkingConfig(modelId, level, userMaxTokens) {
|
|
197
|
+
if (!isReasoningModel(modelId)) {
|
|
198
|
+
return void 0;
|
|
199
|
+
}
|
|
200
|
+
const budget = calculateThinkingBudget(modelId, level, userMaxTokens);
|
|
201
|
+
if (budget === void 0) {
|
|
202
|
+
return void 0;
|
|
203
|
+
}
|
|
204
|
+
return { thinking_budget: budget };
|
|
205
|
+
}
|
|
206
|
+
function buildAnthropicThinking(modelId, level, userMaxTokens) {
|
|
207
|
+
if (level === "none") {
|
|
208
|
+
return void 0;
|
|
209
|
+
}
|
|
210
|
+
const budget = calculateThinkingBudget(modelId, level, userMaxTokens);
|
|
211
|
+
if (!budget || budget < 1024) {
|
|
212
|
+
return { type: "enabled", budget_tokens: 1024 };
|
|
213
|
+
}
|
|
214
|
+
return { type: "enabled", budget_tokens: budget };
|
|
215
|
+
}
|
|
216
|
+
function buildQwenThinkingConfig(level, userMaxTokens) {
|
|
217
|
+
if (level === "none") {
|
|
218
|
+
return { enable_thinking: false };
|
|
219
|
+
}
|
|
220
|
+
const ratio = EFFORT_RATIO[level];
|
|
221
|
+
const budget = userMaxTokens ? Math.floor(userMaxTokens * ratio) : void 0;
|
|
222
|
+
return {
|
|
223
|
+
enable_thinking: true,
|
|
224
|
+
thinking_budget: budget
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
228
|
+
0 && (module.exports = {
|
|
229
|
+
CANNOT_DISABLE_THINKING_PATTERNS,
|
|
230
|
+
DEFAULT_MAX_TOKENS,
|
|
231
|
+
EFFORT_RATIO,
|
|
232
|
+
REASONING_MODEL_PATTERNS,
|
|
233
|
+
THINKING_TOKEN_MAP,
|
|
234
|
+
buildAnthropicThinking,
|
|
235
|
+
buildGeminiThinkingConfig,
|
|
236
|
+
buildQwenThinkingConfig,
|
|
237
|
+
calculateThinkingBudget,
|
|
238
|
+
canDisableThinking,
|
|
239
|
+
findTokenLimit,
|
|
240
|
+
getClaudeMaxTokens,
|
|
241
|
+
getOpenAIReasoningEffort,
|
|
242
|
+
isReasoningModel
|
|
243
|
+
});
|