@eddyskywalker/dsh-chatgpt-subscription 0.2.20 → 0.3.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/CHANGELOG.md +79 -0
- package/README.md +116 -1
- package/lib/client.js +2825 -512
- package/lib/client.js.map +1 -1
- package/lib/index.js +8758 -352
- package/lib/types/client/ProviderHubSection.d.ts +15 -0
- package/lib/types/client/ProviderHubSection.d.ts.map +1 -0
- package/lib/types/client/command-code/CommandCodeComposerQuota.d.ts +24 -0
- package/lib/types/client/command-code/CommandCodeComposerQuota.d.ts.map +1 -0
- package/lib/types/client/command-code/CommandCodeSection.d.ts +11 -0
- package/lib/types/client/command-code/CommandCodeSection.d.ts.map +1 -0
- package/lib/types/client/command-code/locales.d.ts +401 -0
- package/lib/types/client/command-code/locales.d.ts.map +1 -0
- package/lib/types/client/index.d.ts +2 -0
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/kimi-code/KimiCodeComposerQuota.d.ts +25 -0
- package/lib/types/client/kimi-code/KimiCodeComposerQuota.d.ts.map +1 -0
- package/lib/types/client/kimi-code/KimiCodeSection.d.ts +11 -0
- package/lib/types/client/kimi-code/KimiCodeSection.d.ts.map +1 -0
- package/lib/types/client/kimi-code/KimiModelCapabilities.d.ts +16 -0
- package/lib/types/client/kimi-code/KimiModelCapabilities.d.ts.map +1 -0
- package/lib/types/client/kimi-code/locales.d.ts +665 -0
- package/lib/types/client/kimi-code/locales.d.ts.map +1 -0
- package/lib/types/client/kimi-code/styles.d.ts +4 -0
- package/lib/types/client/kimi-code/styles.d.ts.map +1 -0
- package/lib/types/client/locales.d.ts +3 -1
- package/lib/types/client/locales.d.ts.map +1 -1
- package/lib/types/client/styles.d.ts.map +1 -1
- package/lib/types/host/antigravity/adapter.d.ts +2 -0
- package/lib/types/host/antigravity/adapter.d.ts.map +1 -1
- package/lib/types/host/antigravity/mapper.d.ts +51 -2
- package/lib/types/host/antigravity/mapper.d.ts.map +1 -1
- package/lib/types/host/command-code/adapter.d.ts +34 -0
- package/lib/types/host/command-code/adapter.d.ts.map +1 -0
- package/lib/types/host/command-code/client.d.ts +99 -0
- package/lib/types/host/command-code/client.d.ts.map +1 -0
- package/lib/types/host/command-code/mapper.d.ts +102 -0
- package/lib/types/host/command-code/mapper.d.ts.map +1 -0
- package/lib/types/host/command-code/model-catalog.d.ts +31 -0
- package/lib/types/host/command-code/model-catalog.d.ts.map +1 -0
- package/lib/types/host/command-code/oauth.d.ts +89 -0
- package/lib/types/host/command-code/oauth.d.ts.map +1 -0
- package/lib/types/host/command-code/plans.d.ts +40 -0
- package/lib/types/host/command-code/plans.d.ts.map +1 -0
- package/lib/types/host/command-code/routes.d.ts +27 -0
- package/lib/types/host/command-code/routes.d.ts.map +1 -0
- package/lib/types/host/command-code/token-store.d.ts +88 -0
- package/lib/types/host/command-code/token-store.d.ts.map +1 -0
- package/lib/types/host/command-code/types.d.ts +138 -0
- package/lib/types/host/command-code/types.d.ts.map +1 -0
- package/lib/types/host/kimi-code/adapter.d.ts +112 -0
- package/lib/types/host/kimi-code/adapter.d.ts.map +1 -0
- package/lib/types/host/kimi-code/client.d.ts +161 -0
- package/lib/types/host/kimi-code/client.d.ts.map +1 -0
- package/lib/types/host/kimi-code/mapper.d.ts +334 -0
- package/lib/types/host/kimi-code/mapper.d.ts.map +1 -0
- package/lib/types/host/kimi-code/modalities.d.ts +94 -0
- package/lib/types/host/kimi-code/modalities.d.ts.map +1 -0
- package/lib/types/host/kimi-code/model-catalog.d.ts +77 -0
- package/lib/types/host/kimi-code/model-catalog.d.ts.map +1 -0
- package/lib/types/host/kimi-code/oauth.d.ts +133 -0
- package/lib/types/host/kimi-code/oauth.d.ts.map +1 -0
- package/lib/types/host/kimi-code/routes.d.ts +26 -0
- package/lib/types/host/kimi-code/routes.d.ts.map +1 -0
- package/lib/types/host/kimi-code/token-store.d.ts +135 -0
- package/lib/types/host/kimi-code/token-store.d.ts.map +1 -0
- package/lib/types/host/kimi-code/types.d.ts +174 -0
- package/lib/types/host/kimi-code/types.d.ts.map +1 -0
- package/lib/types/host/relay-probe.d.ts +161 -0
- package/lib/types/host/relay-probe.d.ts.map +1 -0
- package/lib/types/host/responses-client.d.ts.map +1 -1
- package/lib/types/index.d.ts +13 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/shared/command-code-contracts.d.ts +119 -0
- package/lib/types/shared/command-code-contracts.d.ts.map +1 -0
- package/lib/types/shared/kimi-code-contracts.d.ts +203 -0
- package/lib/types/shared/kimi-code-contracts.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import { PROVIDER_ID, PROVIDER_NAME } from './types.ts';
|
|
3
|
+
import { FileCredentialStore, FileModelSettingsStore, type CommandCodeCatalogModel, type CommandCodePreferenceStore } from './token-store.ts';
|
|
4
|
+
import { getCachedCatalog } from './client.ts';
|
|
5
|
+
import type { CommandCodeApiEnv, CommandCodeWebStatus } from '../../shared/command-code-contracts.ts';
|
|
6
|
+
/**
|
|
7
|
+
* The selection the card should show.
|
|
8
|
+
*
|
|
9
|
+
* A stored list that still equals the shipped default has never been edited, so
|
|
10
|
+
* it cannot know about models the live catalog has since added; treating it as
|
|
11
|
+
* "everything currently offered" keeps a first run from hiding the whole
|
|
12
|
+
* catalog behind an unedited default. Any explicit edit is honoured exactly.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveEnabledModelIds(stored: readonly string[], catalog: readonly CommandCodeCatalogModel[]): string[];
|
|
15
|
+
export interface CommandCodeStatusOptions {
|
|
16
|
+
fetchFn?: typeof fetch;
|
|
17
|
+
/** Whether this plugin currently owns the provider route; re-read on every status. */
|
|
18
|
+
serving?: boolean | (() => boolean);
|
|
19
|
+
/** Diagnostic when another plugin owns the provider route; re-read on every status. */
|
|
20
|
+
conflict?: string | null | (() => string | null);
|
|
21
|
+
}
|
|
22
|
+
/** Everything the settings card renders: account, quota, and the model catalog. */
|
|
23
|
+
export declare function getCommandCodeWebStatus(store: FileCredentialStore, modelSettings: FileModelSettingsStore, preferences?: CommandCodePreferenceStore, options?: CommandCodeStatusOptions): Promise<CommandCodeWebStatus>;
|
|
24
|
+
/** Register the Command Code settings routes under `/command-code/api`. */
|
|
25
|
+
export declare function registerCommandCodeRoutes(ctx: Context, store: FileCredentialStore, modelSettings: FileModelSettingsStore, preferences?: CommandCodePreferenceStore, options?: CommandCodeStatusOptions): () => void;
|
|
26
|
+
export { PROVIDER_ID, PROVIDER_NAME, type CommandCodeApiEnv, getCachedCatalog };
|
|
27
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../../src/host/command-code/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,EAAmB,WAAW,EAAE,aAAa,EAAqC,MAAM,YAAY,CAAA;AAC3G,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,KAAK,uBAAuB,EAE5B,KAAK,0BAA0B,EAChC,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAKL,gBAAgB,EAMjB,MAAM,aAAa,CAAA;AAGpB,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAA;AAkErG;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,EAAE,SAAS,uBAAuB,EAAE,GAC1C,MAAM,EAAE,CAYV;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,CAAC,EAAE,OAAO,KAAK,CAAA;IACtB,sFAAsF;IACtF,OAAO,CAAC,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,CAAA;IACnC,uFAAuF;IACvF,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC,CAAA;CACjD;AAMD,mFAAmF;AACnF,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,mBAAmB,EAC1B,aAAa,EAAE,sBAAsB,EACrC,WAAW,CAAC,EAAE,0BAA0B,EACxC,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,oBAAoB,CAAC,CAqC/B;AAED,2EAA2E;AAC3E,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,mBAAmB,EAC1B,aAAa,EAAE,sBAAsB,EACrC,WAAW,CAAC,EAAE,0BAA0B,EACxC,OAAO,GAAE,wBAA6B,GACrC,MAAM,IAAI,CAuIZ;AAED,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,gBAAgB,EAAE,CAAA"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { SettingsProvider } from '@deepseek-ai/dsh-settings';
|
|
2
|
+
import type { CommandCodeApiEnv, CommandCodeReasoningEffort } from '../../shared/command-code-contracts.ts';
|
|
3
|
+
import type { CredentialStore } from '../token-store.ts';
|
|
4
|
+
export declare const COMMAND_CODE_PREFERENCES_NAMESPACE = "dsh-command-code";
|
|
5
|
+
export type { CommandCodeReasoningEffort };
|
|
6
|
+
/**
|
|
7
|
+
* One stored Command Code credential.
|
|
8
|
+
*
|
|
9
|
+
* The provider API authenticates with a bearer API key rather than the rotating
|
|
10
|
+
* OAuth pair the other routes in this plugin store, so there is no refresh
|
|
11
|
+
* token and nothing expires. The browser sign-in returns the same key a user
|
|
12
|
+
* can paste by hand, which is why both paths converge on this shape.
|
|
13
|
+
*/
|
|
14
|
+
export interface CommandCodeCredentials {
|
|
15
|
+
/** Bearer key issued by Command Code Studio. Host-only; never sent to a browser. */
|
|
16
|
+
apiKey: string;
|
|
17
|
+
userId?: string;
|
|
18
|
+
userName?: string;
|
|
19
|
+
email?: string;
|
|
20
|
+
keyName?: string;
|
|
21
|
+
organizationName?: string;
|
|
22
|
+
planLabel?: string;
|
|
23
|
+
planId?: string;
|
|
24
|
+
/** Unix milliseconds the key was obtained. */
|
|
25
|
+
authenticatedAt?: number;
|
|
26
|
+
/** Which API deployment the key belongs to. */
|
|
27
|
+
apiEnv?: CommandCodeApiEnv;
|
|
28
|
+
}
|
|
29
|
+
export interface CommandCodeCatalogModel {
|
|
30
|
+
id: string;
|
|
31
|
+
name?: string;
|
|
32
|
+
contextWindow?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface CommandCodeModelSettings {
|
|
35
|
+
enabledModelIds: string[];
|
|
36
|
+
catalogModels: CommandCodeCatalogModel[];
|
|
37
|
+
contextWindowOverrides: Record<string, number>;
|
|
38
|
+
defaultReasoningEffort: CommandCodeReasoningEffort | null;
|
|
39
|
+
}
|
|
40
|
+
export interface CommandCodePreferenceStore {
|
|
41
|
+
status(): CommandCodeModelSettings;
|
|
42
|
+
update(patch: {
|
|
43
|
+
enabledModelIds?: string[];
|
|
44
|
+
contextWindowOverrides?: Record<string, number>;
|
|
45
|
+
defaultReasoningEffort?: CommandCodeReasoningEffort | null;
|
|
46
|
+
}): Promise<CommandCodeModelSettings>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Bind the model selection to the DSH settings document, which is what the
|
|
50
|
+
* settings service can persist durably; the JSON file beside it remains the
|
|
51
|
+
* store used when the plugin runs without a settings provider (headless tests).
|
|
52
|
+
*/
|
|
53
|
+
export declare function registerCommandCodePreferenceStore(settings?: SettingsProvider, fallbackStore?: FileModelSettingsStore): CommandCodePreferenceStore;
|
|
54
|
+
export declare function credentialPath(): string;
|
|
55
|
+
export declare function modelSettingsPath(): string;
|
|
56
|
+
export declare function parseCommandCodeCredentials(value: unknown): CommandCodeCredentials;
|
|
57
|
+
/** Encrypted credential store; the plaintext JSON is only a migration source. */
|
|
58
|
+
export declare class FileCredentialStore {
|
|
59
|
+
private readonly filePath;
|
|
60
|
+
private readonly backend;
|
|
61
|
+
constructor(filePath?: string, backend?: CredentialStore<CommandCodeCredentials>);
|
|
62
|
+
path(): string;
|
|
63
|
+
private serialize;
|
|
64
|
+
private removeLegacy;
|
|
65
|
+
private saveVerified;
|
|
66
|
+
read(): Promise<CommandCodeCredentials | null>;
|
|
67
|
+
write(credentials: CommandCodeCredentials): Promise<void>;
|
|
68
|
+
delete(): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
/** Plain-JSON model settings used when the settings service is unavailable. */
|
|
71
|
+
export declare class FileModelSettingsStore {
|
|
72
|
+
private readonly filePath;
|
|
73
|
+
constructor(filePath?: string);
|
|
74
|
+
path(): string;
|
|
75
|
+
read(): Promise<CommandCodeModelSettings>;
|
|
76
|
+
write(settings: CommandCodeModelSettings): Promise<void>;
|
|
77
|
+
updateSettings(patch: {
|
|
78
|
+
enabledModelIds?: string[];
|
|
79
|
+
contextWindowOverrides?: Record<string, number>;
|
|
80
|
+
defaultReasoningEffort?: CommandCodeReasoningEffort | null;
|
|
81
|
+
}): Promise<CommandCodeModelSettings>;
|
|
82
|
+
setCatalogModels(catalogModels: CommandCodeCatalogModel[], options?: {
|
|
83
|
+
enabledModelIds?: string[];
|
|
84
|
+
}): Promise<CommandCodeModelSettings>;
|
|
85
|
+
}
|
|
86
|
+
/** Environment the credential was last used against; defaults to the current one. */
|
|
87
|
+
export declare function credentialApiEnv(credentials: CommandCodeCredentials | null): CommandCodeApiEnv;
|
|
88
|
+
//# sourceMappingURL=token-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-store.d.ts","sourceRoot":"","sources":["../../../../src/host/command-code/token-store.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,2BAA2B,CAAA;AAGhF,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAA;AAG3G,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAMxD,eAAO,MA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A;KAAE,GACvC,OAAO,CAAC,wBAAwB,CAAC;CAUrC;AAED,qFAAqF;AACrF,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,sBAAsB,GAAG,IAAI,GAAG,iBAAiB,CAE9F"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static facts about the Command Code provider API.
|
|
3
|
+
*
|
|
4
|
+
* Command Code publishes two surfaces this plugin uses:
|
|
5
|
+
*
|
|
6
|
+
* - the **provider API** (`https://api.commandcode.ai/provider/v1`) which is an
|
|
7
|
+
* OpenAI-compatible `/chat/completions` endpoint, an Anthropic-compatible
|
|
8
|
+
* `/messages` endpoint, and a public `/models` catalog; and
|
|
9
|
+
* - the **alpha API** (`https://api.commandcode.ai/alpha/*`) the official CLI
|
|
10
|
+
* uses for account, billing, and usage facts.
|
|
11
|
+
*
|
|
12
|
+
* Model ids are served by exactly one of the two provider endpoints: Anthropic
|
|
13
|
+
* models are rejected on `/chat/completions` and OpenAI-format models are
|
|
14
|
+
* rejected on `/messages`, so the route is decided per model, not per request.
|
|
15
|
+
* See https://commandcode.ai/blog/command-code-provider-api.
|
|
16
|
+
*/
|
|
17
|
+
import type { CommandCodeApiEnv, CommandCodeWire } from '../../shared/command-code-contracts.ts';
|
|
18
|
+
export declare const PROVIDER_ID = "command-code";
|
|
19
|
+
export declare const PROVIDER_NAME = "Command Code";
|
|
20
|
+
/** Browser sign-in page the CLI opens; it redirects back to our loopback server. */
|
|
21
|
+
export declare const STUDIO_PATH = "/studio/auth/cli";
|
|
22
|
+
/** Query parameter that carries the loopback callback URL to the studio page. */
|
|
23
|
+
export declare const STUDIO_CALLBACK_PARAM = "callback";
|
|
24
|
+
/** Studio client marker; mirrors the value the official CLI sends. */
|
|
25
|
+
export declare const STUDIO_CLIENT = "cli";
|
|
26
|
+
export declare const API_ENDPOINTS: Record<CommandCodeApiEnv, string>;
|
|
27
|
+
export declare const STUDIO_ENDPOINTS: Record<CommandCodeApiEnv, string>;
|
|
28
|
+
/** Provider API prefix; add `/chat/completions`, `/messages`, or `/models`. */
|
|
29
|
+
export declare const PROVIDER_API_PREFIX = "/provider/v1";
|
|
30
|
+
/** Account identity the CLI reads before doing anything authenticated. */
|
|
31
|
+
export declare const WHOAMI_PATH = "/alpha/whoami";
|
|
32
|
+
/** Credit balance for the signed-in account. */
|
|
33
|
+
export declare const BILLING_CREDITS_PATH = "/alpha/billing/credits";
|
|
34
|
+
/** Plan / subscription facts for the signed-in account. */
|
|
35
|
+
export declare const BILLING_SUBSCRIPTIONS_PATH = "/alpha/billing/subscriptions";
|
|
36
|
+
/** Rolling usage accounting for the signed-in account. */
|
|
37
|
+
export declare const USAGE_SUMMARY_PATH = "/alpha/usage/summary";
|
|
38
|
+
/** First loopback port tried for the browser callback; matches the official CLI. */
|
|
39
|
+
export declare const DEFAULT_CALLBACK_PORT = 5959;
|
|
40
|
+
/** Consecutive ports probed when the default is taken; matches the official CLI. */
|
|
41
|
+
export declare const CALLBACK_PORT_ATTEMPTS = 10;
|
|
42
|
+
export declare const CALLBACK_PATH = "/callback";
|
|
43
|
+
/** Page the studio's browser tab lands on after a successful POST; CLI-compatible. */
|
|
44
|
+
export declare const CALLBACK_COMPLETE_PATH = "/callback/complete";
|
|
45
|
+
/** How long a landed credential waits for the browser tab before login resolves. */
|
|
46
|
+
export declare const CALLBACK_LANDING_GRACE_MS = 10000;
|
|
47
|
+
/** Body cap the official callback server enforces. */
|
|
48
|
+
export declare const CALLBACK_MAX_BYTES = 10000;
|
|
49
|
+
/** Origins the studio signs in from; echoed back for the browser's CORS check. */
|
|
50
|
+
export declare const CALLBACK_ALLOWED_ORIGINS: readonly ["https://commandcode.ai", "https://staging.commandcode.ai", "http://localhost:3000"];
|
|
51
|
+
export declare const LOGIN_TIMEOUT_MS: number;
|
|
52
|
+
export declare const DISCOVERY_TIMEOUT_MS = 15000;
|
|
53
|
+
export declare const QUOTA_CACHE_TTL_MS: number;
|
|
54
|
+
export declare const CATALOG_CACHE_TTL_MS: number;
|
|
55
|
+
export declare const DEFAULT_MAX_TOKENS = 32768;
|
|
56
|
+
export declare const DEFAULT_CONTEXT_WINDOW = 128000;
|
|
57
|
+
export declare const STREAM_IDLE_TIMEOUT_MS = 300000;
|
|
58
|
+
export declare const STREAM_IDLE_TIMEOUT_CODE = "LLM_STREAM_IDLE_TIMEOUT";
|
|
59
|
+
/**
|
|
60
|
+
* Product identity for the provider API's `User-Agent`.
|
|
61
|
+
*
|
|
62
|
+
* The alpha routes are identified as the CLI (they are the CLI's own API); the
|
|
63
|
+
* provider routes are ordinary model calls, so they carry this plugin's
|
|
64
|
+
* attribution instead of impersonating a client it is not.
|
|
65
|
+
*/
|
|
66
|
+
export declare const PLUGIN_USER_AGENT = "dsh-chatgpt-subscription (+https://github.com/Aa728848/dsh-chatgpt-subscription)";
|
|
67
|
+
/** User-Agent the official CLI sends; the alpha API is friendlier to a known client. */
|
|
68
|
+
export declare const CLI_USER_AGENT = "command-code-cli";
|
|
69
|
+
/** Headers the alpha API accepts, mirroring the official CLI's vocabulary. */
|
|
70
|
+
export declare const HEADER_API_KEY = "authorization";
|
|
71
|
+
export declare const HEADER_CLI_VERSION = "x-command-code-cli-version";
|
|
72
|
+
export declare const HEADER_CLI_ENVIRONMENT = "x-command-code-cli-environment";
|
|
73
|
+
export declare const HEADER_PROJECT_SLUG = "x-command-code-project-slug";
|
|
74
|
+
export declare const HEADER_TASTE_LEARNING = "x-command-code-taste-learning";
|
|
75
|
+
export declare const HEADER_SESSION_ID = "x-command-code-session-id";
|
|
76
|
+
export declare const HEADER_OSS_PRIMARY_PROVIDER = "x-command-code-oss-primary-provider";
|
|
77
|
+
export declare function resolveApiEnv(raw?: string | undefined): CommandCodeApiEnv;
|
|
78
|
+
export declare function apiBaseUrl(env?: CommandCodeApiEnv): string;
|
|
79
|
+
export declare function studioBaseUrl(env?: CommandCodeApiEnv): string;
|
|
80
|
+
export declare function providerUrl(env?: CommandCodeApiEnv): string;
|
|
81
|
+
/**
|
|
82
|
+
* Which provider endpoint serves a model id.
|
|
83
|
+
*
|
|
84
|
+
* The split the API enforces is Anthropic-format vs OpenAI-format, and the
|
|
85
|
+
* Anthropic-served catalog is exactly the `claude-*` family. Everything else —
|
|
86
|
+
* the open-weight models and the GPT models — is OpenAI Chat Completions.
|
|
87
|
+
*
|
|
88
|
+
* @param modelId - exact model id from the live catalog or a caller.
|
|
89
|
+
* @returns the wire dialect to build the request for.
|
|
90
|
+
*/
|
|
91
|
+
export declare function wireForModel(modelId: string): CommandCodeWire;
|
|
92
|
+
/**
|
|
93
|
+
* Reasoning levels one model advertises.
|
|
94
|
+
*
|
|
95
|
+
* The registry is the authority: a model it describes but gives no
|
|
96
|
+
* `reasoningEfforts` is a non-reasoning model, which is why that answers with an
|
|
97
|
+
* empty list rather than a default level. A model the registry does not
|
|
98
|
+
* describe declares nothing either — guessing from the family name is exactly
|
|
99
|
+
* how `deepseek-v4-flash` got treated as a reasoner with image input when it is
|
|
100
|
+
* text-only with a different effort set.
|
|
101
|
+
*/
|
|
102
|
+
export declare function reasoningEffortsFor(modelId: string): string[];
|
|
103
|
+
/**
|
|
104
|
+
* Accepted request modalities for one model.
|
|
105
|
+
*
|
|
106
|
+
* An unknown model falls back to text-only: DSH turns a false "no images" into
|
|
107
|
+
* a visible placeholder the user can correct by switching models, while a false
|
|
108
|
+
* "images accepted" sends bytes to an endpoint that rejects the whole request.
|
|
109
|
+
*/
|
|
110
|
+
export declare function inputModalitiesFor(modelId: string): Array<'text' | 'image'>;
|
|
111
|
+
/**
|
|
112
|
+
* Thinking-token budget one Anthropic-route reasoning level asks for.
|
|
113
|
+
*
|
|
114
|
+
* The registry's two extra levels are covered too: `xhigh` sits between `high`
|
|
115
|
+
* and `max` (it is the level Claude Opus 5 / Fable 5 and Muse Spark 1.3 expose
|
|
116
|
+
* above `high`), and `minimal` is the cheapest supported budget.
|
|
117
|
+
*/
|
|
118
|
+
export declare function anthropicThinkingBudget(effort: string): number | null;
|
|
119
|
+
/**
|
|
120
|
+
* Output cap one request asks for when the caller omits one. A cap the registry
|
|
121
|
+
* declares wins over the observed value, which in turn wins over the default.
|
|
122
|
+
*/
|
|
123
|
+
export declare function maxOutputTokensFor(modelId: string): number;
|
|
124
|
+
/**
|
|
125
|
+
* Context windows used before the live catalog has ever been fetched.
|
|
126
|
+
*
|
|
127
|
+
* The public `/provider/v1/models` endpoint reports `context_length` for every
|
|
128
|
+
* model and is the authority once reachable; these values only keep the model
|
|
129
|
+
* picker usable on a machine that cannot reach the catalog yet. They are drawn
|
|
130
|
+
* from the registry rather than hand-listed, so a model cannot drift between the
|
|
131
|
+
* offline fallback and its real capability entry.
|
|
132
|
+
*/
|
|
133
|
+
export declare const FALLBACK_MODELS: ReadonlyArray<{
|
|
134
|
+
id: string;
|
|
135
|
+
name: string;
|
|
136
|
+
contextWindow: number;
|
|
137
|
+
}>;
|
|
138
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/host/command-code/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AAGhG,eAAO,MAAM,WAAW,iBAAiB,CAAA;AACzC,eAAO,MAAM,aAAa,iBAAiB,CAAA;AAE3C,oFAAoF;AACpF,eAAO,MAAM,WAAW,qBAAqB,CAAA;AAC7C,iFAAiF;AACjF,eAAO,MAAM,qBAAqB,aAAa,CAAA;AAC/C,sEAAsE;AACtE,eAAO,MAAM,aAAa,QAAQ,CAAA;AAElC,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAI3D,CAAA;AAED,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAI9D,CAAA;AAED,+EAA+E;AAC/E,eAAO,MAAM,mBAAmB,iBAAiB,CAAA;AA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CAAA;AACpE,eAAO,MAAM,iBAAiB,8BAA8B,CAAA;AAC5D,eAAO,MAAM,2BAA2B,wCAAwC,CAAA;AAEhF,wBAAgB,aAAa,CAAC,GAAG,qBAAmC,GAAG,iBAAiB,CAGvF;AAED,wBAAgB,UAAU,CAAC,GAAG,GAAE,iBAAmC,GAAG,MAAM,CAE3E;AAED,wBAAgB,aAAa,CAAC,GAAG,GAAE,iBAAmC,GAAG,MAAM,CAE9E;AAED,wBAAgB,WAAW,CAAC,GAAG,GAAE,iBAAmC,GAAG,MAAM,CAE5E;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAE7D;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAE7D;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,CAE3E;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUrE;AA6CD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAI1D;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAGQ,CAAA"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { LlmAdapter, ReasoningEffortId, type GenerateOptions, type LlmModelInfo, type LlmProviderInfo, type LlmResolvedModelInfo, type PreparedAdapterCall, type ResolvedRetryPolicy, type StreamChunk } from '@deepseek-ai/dsh-llm';
|
|
2
|
+
import { PROVIDER_ID, reasoningEffortsFor } from './types.ts';
|
|
3
|
+
import { FileCredentialStore, FileModelSettingsStore, type KimiCodeCatalogModel, type KimiCodePreferenceStore } from './token-store.ts';
|
|
4
|
+
import { buildModelOptions, clearCachedCatalog } from './client.ts';
|
|
5
|
+
import { type AttachmentImageReader, type AttachmentVideoReader } from './mapper.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Transient-failure retry policy for the `kimi-code` route.
|
|
8
|
+
*
|
|
9
|
+
* Kimi Code fronts the model providers, so a call can fail with a 502/503/504
|
|
10
|
+
* while the subscription and the credential stay perfectly usable. The service
|
|
11
|
+
* publishes exactly this case, and the body is usually
|
|
12
|
+
* `{"error":{"message":"Upstream model provider is temporarily unavailable.
|
|
13
|
+
* Please try again in a moment.","type":"server_error"}}` — which is precisely a
|
|
14
|
+
* message telling the client to try again.
|
|
15
|
+
*
|
|
16
|
+
* The retryable set is therefore:
|
|
17
|
+
*
|
|
18
|
+
* - `SERVER` — any 5xx, including that upstream-unavailable 502;
|
|
19
|
+
* - `RATE_LIMIT` — a 429 that is genuine back-pressure ("too many requests",
|
|
20
|
+
* "the engine is currently overloaded"), which the documentation describes as
|
|
21
|
+
* transient;
|
|
22
|
+
* - `TRANSPORT` — a connection that produced no response at all;
|
|
23
|
+
* - `TIMEOUT` — a stalled stream, handled by the idle watchdog.
|
|
24
|
+
*
|
|
25
|
+
* Deliberately outside the set:
|
|
26
|
+
*
|
|
27
|
+
* - `INVALID_CREDENTIAL` — a rejected access token fails identically on every
|
|
28
|
+
* attempt;
|
|
29
|
+
* - `PROVIDER_ERROR` — a 400, a 401 that is really a plan-entitlement refusal,
|
|
30
|
+
* or a 403 quota limit. Retrying a quota that resets in hours only burns
|
|
31
|
+
* requests and delays the message the user needs to see;
|
|
32
|
+
* - `ABORTED` — the caller already cancelled.
|
|
33
|
+
*
|
|
34
|
+
* The DSH normal defaults would apply anyway; stating the values here pins them
|
|
35
|
+
* so this route never retries less than the rest of the plugin.
|
|
36
|
+
*/
|
|
37
|
+
export declare const KIMI_CODE_RETRY_POLICY_CONFIG: {
|
|
38
|
+
mode: 'normal';
|
|
39
|
+
maxRetries: number;
|
|
40
|
+
retryableCodes: string[];
|
|
41
|
+
backoff: {
|
|
42
|
+
initialDelayMs: number;
|
|
43
|
+
maxDelayMs: number;
|
|
44
|
+
jitterRatio: number;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/** Configured effort when the model supports it, else the adapter's preference order. */
|
|
48
|
+
export declare function resolveDefaultReasoningEffort(efforts: readonly string[], configuredEffort?: string | null): ReasoningEffortId | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* What one failed response means for the retry policy.
|
|
51
|
+
*
|
|
52
|
+
* The service overloads a single status for unrelated problems — a 401 covers
|
|
53
|
+
* both "your token is bad" and "your plan does not include k3", and a 429
|
|
54
|
+
* covers both ordinary back-pressure and a spent quota that must not be
|
|
55
|
+
* retried. The body text is what separates them, so the classification reads
|
|
56
|
+
* it rather than trusting the status alone.
|
|
57
|
+
*/
|
|
58
|
+
export interface KimiFailureClassification {
|
|
59
|
+
/** DSH error code; decides whether the route retries. */
|
|
60
|
+
code: string;
|
|
61
|
+
/** Message shown to the user, with the provider's own text appended. */
|
|
62
|
+
message: string;
|
|
63
|
+
/** True only when the failure is worth retrying. */
|
|
64
|
+
retryable: boolean;
|
|
65
|
+
}
|
|
66
|
+
/** Short, single-line excerpt of one error body, safe to show a user. */
|
|
67
|
+
export declare function summarizeFailureBody(raw: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Classify one non-2xx response for the retry policy.
|
|
70
|
+
*
|
|
71
|
+
* @param status - HTTP status the service answered with.
|
|
72
|
+
* @param bodyText - raw response body, used to separate overloaded statuses.
|
|
73
|
+
*/
|
|
74
|
+
export declare function classifyKimiFailure(status: number, bodyText: string): KimiFailureClassification;
|
|
75
|
+
export interface KimiCodeAdapterOptions {
|
|
76
|
+
fetchFn?: typeof fetch;
|
|
77
|
+
attachments?: AttachmentImageReader;
|
|
78
|
+
/**
|
|
79
|
+
* Video reader seam.
|
|
80
|
+
*
|
|
81
|
+
* DSH's attachment service stores images only, so a deployment that produces
|
|
82
|
+
* video references injects the reader here. Absent, video occurrences degrade
|
|
83
|
+
* to an explicit text placeholder rather than silently vanishing.
|
|
84
|
+
*/
|
|
85
|
+
videos?: AttachmentVideoReader;
|
|
86
|
+
/** Live catalog loader seam; defaults to the managed `/models` call. */
|
|
87
|
+
loadCatalog?: () => Promise<KimiCodeCatalogModel[]>;
|
|
88
|
+
}
|
|
89
|
+
export declare class KimiCodeAdapter extends LlmAdapter {
|
|
90
|
+
private readonly store;
|
|
91
|
+
private readonly modelSettings;
|
|
92
|
+
private readonly preferences?;
|
|
93
|
+
private readonly options;
|
|
94
|
+
constructor(store?: FileCredentialStore, modelSettings?: FileModelSettingsStore, preferences?: KimiCodePreferenceStore | undefined, options?: KimiCodeAdapterOptions);
|
|
95
|
+
providerInfo(provider: string): LlmProviderInfo;
|
|
96
|
+
providerRetryPolicy(): ResolvedRetryPolicy;
|
|
97
|
+
imageRequestPricing(): undefined;
|
|
98
|
+
private settings;
|
|
99
|
+
/**
|
|
100
|
+
* Catalog for the picker: the live managed listing when reachable, the
|
|
101
|
+
* shipped fallback otherwise, narrowed by the user's enabled selection.
|
|
102
|
+
*/
|
|
103
|
+
private catalog;
|
|
104
|
+
private contextWindowFor;
|
|
105
|
+
listModels(provider?: string): Promise<readonly LlmModelInfo[]>;
|
|
106
|
+
resolveModel(provider: string, modelId: string, signal?: AbortSignal): Promise<LlmResolvedModelInfo>;
|
|
107
|
+
prepareCall(provider: string, model: string, signal?: AbortSignal): Promise<PreparedAdapterCall>;
|
|
108
|
+
stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
|
|
109
|
+
private requestStream;
|
|
110
|
+
}
|
|
111
|
+
export { clearCachedCatalog, buildModelOptions, reasoningEffortsFor, PROVIDER_ID };
|
|
112
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../../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,CAAC;IAO/F,MAAM,CAAC,OAAO,EAAE,eAAe,GAAG,aAAa,CAAC,WAAW,CAAC;YAgBpD,aAAa;CAgI7B;AAQD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,WAAW,EAAE,CAAA"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { PROVIDER_NAME } from './types.ts';
|
|
2
|
+
import { FileCredentialStore, type KimiCodeCatalogModel, type KimiCodeCredentials } from './token-store.ts';
|
|
3
|
+
import type { KimiCodeAccount, KimiCodeAccountQuota, KimiCodeExtraUsage, KimiCodeModelOption, KimiCodeRegion, KimiCodeUsageWindow, KimiCodeWire } from '../../shared/kimi-code-contracts.ts';
|
|
4
|
+
/** Endpoint suffixes on the coding API base. */
|
|
5
|
+
export declare const MODELS_PATH = "/models";
|
|
6
|
+
export declare const USAGES_PATH = "/usages";
|
|
7
|
+
export declare const ME_PATH = "/me";
|
|
8
|
+
/** Parse an ISO string, Unix seconds, or Unix milliseconds into Unix milliseconds. */
|
|
9
|
+
export declare function parseTimestamp(value: unknown): number | null;
|
|
10
|
+
/**
|
|
11
|
+
* Headers for a managed coding API request.
|
|
12
|
+
*
|
|
13
|
+
* The OpenAI-compatible surface authenticates with a bearer token. On the
|
|
14
|
+
* Anthropic-compatible surface the Anthropic SDK sends the token as
|
|
15
|
+
* `x-api-key` instead and deliberately omits `authorization`, so both are
|
|
16
|
+
* emitted — the service documents each surface and only reads its own field.
|
|
17
|
+
*/
|
|
18
|
+
export declare function kimiCodeHeaders(accessToken: string, wire?: KimiCodeWire, extra?: Record<string, string>): Promise<Record<string, string>>;
|
|
19
|
+
/**
|
|
20
|
+
* Headers for one model call.
|
|
21
|
+
*
|
|
22
|
+
* The managed service attributes usage to the installation, so the same
|
|
23
|
+
* \`X-Msh-*\` device identity the account endpoints require is sent here too.
|
|
24
|
+
* The product token stays this plugin's own: the service documents third-party
|
|
25
|
+
* clients against this endpoint, and claiming to be the official CLI is both
|
|
26
|
+
* dishonest and, per its own terms, grounds for suspending the subscription.
|
|
27
|
+
* The cost of that honesty is that a non-whitelisted user agent can be routed to
|
|
28
|
+
* a deprioritized pool, which answers with a transient 429 — the retry policy in
|
|
29
|
+
* the adapter is what absorbs it.
|
|
30
|
+
*/
|
|
31
|
+
export declare function modelRequestHeaders(accessToken: string, wire: KimiCodeWire): Promise<Record<string, string>>;
|
|
32
|
+
/** Test seam: resolve the URL one request goes to. */
|
|
33
|
+
export declare function requestUrl(wire: KimiCodeWire, region: KimiCodeRegion): string;
|
|
34
|
+
export declare function clearCachedCatalog(): void;
|
|
35
|
+
export declare function getCachedCatalog(): KimiCodeCatalogModel[];
|
|
36
|
+
/**
|
|
37
|
+
* Fetch the models the signed-in subscription can use.
|
|
38
|
+
*
|
|
39
|
+
* The live listing is authoritative — it is what tells the plugin which models
|
|
40
|
+
* the account's tier actually unlocks — so it is cached for half an hour and
|
|
41
|
+
* re-read on demand from the settings card.
|
|
42
|
+
*/
|
|
43
|
+
export declare function loadProviderModels(options?: {
|
|
44
|
+
fetchFn?: typeof fetch;
|
|
45
|
+
store?: FileCredentialStore;
|
|
46
|
+
accessToken?: string;
|
|
47
|
+
region?: KimiCodeRegion;
|
|
48
|
+
signal?: AbortSignal;
|
|
49
|
+
force?: boolean;
|
|
50
|
+
}): Promise<KimiCodeCatalogModel[]>;
|
|
51
|
+
/** Choose the wire dialect for one model, from the live catalog when it says. */
|
|
52
|
+
export declare function wireForCatalogEntry(modelId: string, catalog: readonly KimiCodeCatalogModel[]): KimiCodeWire;
|
|
53
|
+
/** Thinking levels for one model, from the catalog when it declares them. */
|
|
54
|
+
export declare function reasoningEffortsForEntry(modelId: string, catalog: readonly KimiCodeCatalogModel[]): string[];
|
|
55
|
+
/** Input modalities for one model, from the catalog when it declares them. */
|
|
56
|
+
export declare function inputModalitiesForEntry(modelId: string, catalog: readonly KimiCodeCatalogModel[]): Array<'text' | 'image' | 'video'>;
|
|
57
|
+
/** Build the picker entries the settings card renders. */
|
|
58
|
+
export declare function buildModelOptions(catalog: readonly KimiCodeCatalogModel[], enabledModelIds: readonly string[], contextWindowOverrides: Record<string, number>): KimiCodeModelOption[];
|
|
59
|
+
export declare function getCachedQuota(): KimiCodeAccountQuota | null;
|
|
60
|
+
export declare function clearCachedQuota(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Read the windowed quota block.
|
|
63
|
+
*
|
|
64
|
+
* The service's own shape nests one entry per window under `usages`; a
|
|
65
|
+
* community-documented alternative reports a top-level `usage` plus a
|
|
66
|
+
* `limits[]` array. Both are read so a service-side change of shape does not
|
|
67
|
+
* silently blank the card, and an unrecognized payload yields no windows rather
|
|
68
|
+
* than a fabricated 0%.
|
|
69
|
+
*/
|
|
70
|
+
export declare function parseUsageWindows(payload: unknown): KimiCodeUsageWindow[];
|
|
71
|
+
/**
|
|
72
|
+
* Convert the fixed-point money field the service uses into cents.
|
|
73
|
+
*
|
|
74
|
+
* Amounts arrive as 1e-6 cents; a positive amount that would round to zero is
|
|
75
|
+
* reported as one cent, because "you have something left" is closer to the
|
|
76
|
+
* truth than "you have nothing".
|
|
77
|
+
*/
|
|
78
|
+
export declare function fixedPointToCents(value: unknown): number | null;
|
|
79
|
+
/**
|
|
80
|
+
* Read the booster wallet (the pay-as-you-go top-up pool).
|
|
81
|
+
*
|
|
82
|
+
* The wallet only counts when its balance is a real booster balance; anything
|
|
83
|
+
* else is reported as absent so the card does not advertise credit the account
|
|
84
|
+
* cannot spend.
|
|
85
|
+
*/
|
|
86
|
+
export declare function parseExtraUsage(payload: unknown): KimiCodeExtraUsage | null;
|
|
87
|
+
/** Human name for one machine level code, or the code itself when unknown. */
|
|
88
|
+
export declare function membershipLevelName(level: string | null | undefined): string | null;
|
|
89
|
+
/**
|
|
90
|
+
* Subscription tier the payload names, from any documented shape.
|
|
91
|
+
*
|
|
92
|
+
* Prefers the display name when the service still sends one, then the machine
|
|
93
|
+
* level (mapped to its marketing name), so a payload that dropped
|
|
94
|
+
* `user_level_name` still yields a readable tier instead of a raw enum.
|
|
95
|
+
*/
|
|
96
|
+
export declare function parsePlanName(payload: unknown): string | null;
|
|
97
|
+
/** Machine tier level when the service reports one. */
|
|
98
|
+
export declare function parsePlanLevel(payload: unknown): string | null;
|
|
99
|
+
/**
|
|
100
|
+
* Turn a `/me` payload into the public account DTO.
|
|
101
|
+
*
|
|
102
|
+
* The endpoint answers with snake_case fields while the card consumes
|
|
103
|
+
* camelCase, and either profile source may be the one that answered, so both
|
|
104
|
+
* spellings are accepted.
|
|
105
|
+
*/
|
|
106
|
+
export declare function parseUserInfo(payload: unknown, fallback?: Partial<KimiCodeAccount>): KimiCodeAccount;
|
|
107
|
+
export interface QuotaFetchOptions {
|
|
108
|
+
fetchFn?: typeof fetch;
|
|
109
|
+
signal?: AbortSignal;
|
|
110
|
+
/** Bypass the local cache and read the service again. */
|
|
111
|
+
force?: boolean;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Fetch and cache the account's quota snapshot.
|
|
115
|
+
*
|
|
116
|
+
* A 401 is surfaced as a rejection so the caller can invalidate the stored
|
|
117
|
+
* credential; every other failure leaves the previous snapshot in place rather
|
|
118
|
+
* than blanking the card, because a transient outage says nothing about the
|
|
119
|
+
* account's real usage.
|
|
120
|
+
*/
|
|
121
|
+
export declare function fetchAccountQuota(store: FileCredentialStore, options?: QuotaFetchOptions): Promise<KimiCodeAccountQuota | null>;
|
|
122
|
+
/**
|
|
123
|
+
* Build the account view for one credential.
|
|
124
|
+
*
|
|
125
|
+
* There is no account-profile endpoint on the coding API: the signed-in
|
|
126
|
+
* identity lives in the token's own claims, so the account is assembled from
|
|
127
|
+
* the stored credential (which the login and every refresh keep populated) and
|
|
128
|
+
* enriched by whatever the usage payload reports about the tier.
|
|
129
|
+
*/
|
|
130
|
+
export declare function accountFromCredentials(credentials: KimiCodeCredentials, payload?: unknown, profile?: unknown): KimiCodeAccount;
|
|
131
|
+
/**
|
|
132
|
+
* Read the plan profile from `/me`.
|
|
133
|
+
*
|
|
134
|
+
* The endpoint exists and is the only remaining source of the plan's display
|
|
135
|
+
* name: `/usages` used to carry `user_level_name` and stopped. It is called
|
|
136
|
+
* with the OAuth access token only (never a pasted plan key) and is treated as
|
|
137
|
+
* enrichment — a failure returns null so the card still renders the identity it
|
|
138
|
+
* already has from the token.
|
|
139
|
+
*/
|
|
140
|
+
export declare function fetchProfile(store: FileCredentialStore, options?: QuotaFetchOptions): Promise<unknown | null>;
|
|
141
|
+
/**
|
|
142
|
+
* Read the account identity for a stored credential.
|
|
143
|
+
*
|
|
144
|
+
* Combines the token's own claims (the identity) with `/me` (the plan name) and
|
|
145
|
+
* persists what it learns, so a later call needs no network work. It never
|
|
146
|
+
* throws for a missing profile: the identity is derived locally.
|
|
147
|
+
*/
|
|
148
|
+
export declare function fetchUserInfo(store: FileCredentialStore, options?: QuotaFetchOptions): Promise<KimiCodeAccount | null>;
|
|
149
|
+
/**
|
|
150
|
+
* Prove the stored credential still authenticates, and report how long that took.
|
|
151
|
+
*
|
|
152
|
+
* The probe is the real usage call rather than a profile lookup, because there
|
|
153
|
+
* is no profile endpoint: a 200 from `/usages` is what shows the token is
|
|
154
|
+
* accepted, and it doubles as a quota refresh for the card.
|
|
155
|
+
*/
|
|
156
|
+
export declare function testConnection(store: FileCredentialStore, options?: QuotaFetchOptions): Promise<{
|
|
157
|
+
account: KimiCodeAccount | null;
|
|
158
|
+
latencyMs: number;
|
|
159
|
+
}>;
|
|
160
|
+
export { PROVIDER_NAME };
|
|
161
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/host/kimi-code/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,aAAa,EAQd,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,mBAAmB,EAEnB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,KAAK,EAC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