@eddyskywalker/dsh-chatgpt-subscription 0.2.21 → 0.3.1
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 +100 -0
- package/README.md +115 -1
- package/lib/client.js +2831 -512
- package/lib/client.js.map +1 -1
- package/lib/index.js +9092 -389
- 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 +671 -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/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 +173 -0
- package/lib/types/host/kimi-code/client.d.ts.map +1 -0
- package/lib/types/host/kimi-code/mapper.d.ts +370 -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/kimi-code/video-store.d.ts +99 -0
- package/lib/types/host/kimi-code/video-store.d.ts.map +1 -0
- package/lib/types/host/kimi-code/video-tool.d.ts +25 -0
- package/lib/types/host/kimi-code/video-tool.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,133 @@
|
|
|
1
|
+
import { FileCredentialStore, type KimiCodeCredentials } from './token-store.ts';
|
|
2
|
+
import type { KimiCodeLoginFlowStatus, KimiCodeRegion } from '../../shared/kimi-code-contracts.ts';
|
|
3
|
+
/** Raised when the stored refresh token was rejected and a new login is required. */
|
|
4
|
+
export declare class KimiCodeUnauthorizedError extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
/** Raised when a transient failure outlived its retry budget. */
|
|
8
|
+
export declare class KimiCodeRetryableError extends Error {
|
|
9
|
+
readonly cause?: unknown | undefined;
|
|
10
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
11
|
+
}
|
|
12
|
+
/** Raised when the user denied the device authorization request. */
|
|
13
|
+
export declare class KimiCodeAccessDeniedError extends Error {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
/** Test seam: forget every remembered rejection. */
|
|
17
|
+
export declare function resetRefreshRejections(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Whether the given refresh token was recently rejected by the service.
|
|
20
|
+
*
|
|
21
|
+
* The settings card uses this to say "sign in again" instead of showing an
|
|
22
|
+
* account that merely looks signed in while every call is failing.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isRefreshTokenRejected(refreshToken: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Read the stable device id, creating it exactly once.
|
|
27
|
+
*
|
|
28
|
+
* The managed service treats this as the installation's identity. It is not a
|
|
29
|
+
* secret; it only has to stay stable, so a failed write degrades to a
|
|
30
|
+
* per-process value instead of failing the login.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getDeviceId(): Promise<string>;
|
|
33
|
+
/** Identity headers every Kimi Code OAuth and account request carries. */
|
|
34
|
+
export declare function kimiIdentityHeaders(extra?: Record<string, string>): Promise<Record<string, string>>;
|
|
35
|
+
/** Parsed device authorization response. */
|
|
36
|
+
export interface DeviceAuthorization {
|
|
37
|
+
userCode: string;
|
|
38
|
+
deviceCode: string;
|
|
39
|
+
verificationUri: string;
|
|
40
|
+
verificationUriComplete: string;
|
|
41
|
+
expiresIn: number;
|
|
42
|
+
interval: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Start a device authorization (RFC 8628 section 3.1).
|
|
46
|
+
*
|
|
47
|
+
* A public client sends only its `client_id`; no scope, no PKCE.
|
|
48
|
+
*/
|
|
49
|
+
export declare function requestDeviceAuthorization(options?: {
|
|
50
|
+
fetchFn?: typeof fetch;
|
|
51
|
+
signal?: AbortSignal;
|
|
52
|
+
region?: KimiCodeRegion;
|
|
53
|
+
}): Promise<{
|
|
54
|
+
authorization: DeviceAuthorization;
|
|
55
|
+
host: string;
|
|
56
|
+
}>;
|
|
57
|
+
/** Identity claims a Kimi token carries about the signed-in account. */
|
|
58
|
+
export interface KimiTokenIdentity {
|
|
59
|
+
userId?: string;
|
|
60
|
+
email?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Decode one JWT payload without verifying it.
|
|
64
|
+
*
|
|
65
|
+
* Kimi's access and refresh tokens are JWTs whose payload names the account,
|
|
66
|
+
* and there is NO account-profile endpoint on the coding API — the identity
|
|
67
|
+
* exists only inside the token. The claims are read for display only and the
|
|
68
|
+
* token itself is what authenticates, so no signature check applies here.
|
|
69
|
+
*/
|
|
70
|
+
export declare function decodeJwtPayload(token: string): Record<string, unknown> | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Account identity carried by a token pair.
|
|
73
|
+
*
|
|
74
|
+
* `user_id` is preferred across BOTH tokens before `sub` is considered: the two
|
|
75
|
+
* claims share an issuer namespace but `sub` is the weaker one, so a refresh
|
|
76
|
+
* token's `user_id` must beat an access token's `sub`.
|
|
77
|
+
*/
|
|
78
|
+
export declare function identityFromTokens(accessToken: string, refreshToken?: string): KimiTokenIdentity;
|
|
79
|
+
/** OAuth token response, in the shape the rest of the plugin stores. */
|
|
80
|
+
export interface OAuthToken {
|
|
81
|
+
accessToken: string;
|
|
82
|
+
refreshToken: string;
|
|
83
|
+
expiresAt: number;
|
|
84
|
+
expiresIn: number;
|
|
85
|
+
scope: string;
|
|
86
|
+
tokenType: string;
|
|
87
|
+
}
|
|
88
|
+
/** How long before expiry a token must be replaced, from its own lifetime. */
|
|
89
|
+
export declare function refreshThresholdMs(expiresIn: number): number;
|
|
90
|
+
/**
|
|
91
|
+
* Refresh an access token, with the official client's bounded retry.
|
|
92
|
+
*
|
|
93
|
+
* Only a transient status or a transport failure is retried; a 401/403 (or an
|
|
94
|
+
* `invalid_grant` body) is a verdict that the refresh token is dead and stops
|
|
95
|
+
* immediately, because retrying it can never succeed.
|
|
96
|
+
*/
|
|
97
|
+
export declare function refreshAccessToken(refreshToken: string, options?: {
|
|
98
|
+
fetchFn?: typeof fetch;
|
|
99
|
+
signal?: AbortSignal;
|
|
100
|
+
host?: string;
|
|
101
|
+
region?: KimiCodeRegion;
|
|
102
|
+
}): Promise<OAuthToken>;
|
|
103
|
+
export interface EnsureTokenOptions {
|
|
104
|
+
fetchFn?: typeof fetch;
|
|
105
|
+
signal?: AbortSignal;
|
|
106
|
+
/** Refresh even when the current token is not near expiry. */
|
|
107
|
+
force?: boolean;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Return a usable access token, refreshing and persisting when needed.
|
|
111
|
+
*
|
|
112
|
+
* Concurrent callers share one refresh request: a subscription is rate limited,
|
|
113
|
+
* and a burst of tool calls at token expiry would otherwise each try to rotate
|
|
114
|
+
* the same refresh token.
|
|
115
|
+
*/
|
|
116
|
+
export declare function ensureAccessToken(store: FileCredentialStore, options?: EnsureTokenOptions): Promise<KimiCodeCredentials>;
|
|
117
|
+
export declare function getWebLoginStatus(): KimiCodeLoginFlowStatus;
|
|
118
|
+
/** Reset the flow so a cancelled attempt cannot keep a later one from starting. */
|
|
119
|
+
export declare function resetWebLogin(): void;
|
|
120
|
+
export declare function openBrowser(url: string): void;
|
|
121
|
+
/**
|
|
122
|
+
* Start the browser sign-in.
|
|
123
|
+
*
|
|
124
|
+
* Resolves immediately with the flow state the settings card polls; the device
|
|
125
|
+
* code is fetched, opened, and polled in the background so the HTTP request
|
|
126
|
+
* behind the button never has to stay open for the whole authorization.
|
|
127
|
+
*/
|
|
128
|
+
export declare function beginWebLogin(store: FileCredentialStore, options?: {
|
|
129
|
+
fetchFn?: typeof fetch;
|
|
130
|
+
openBrowser?: (url: string) => void;
|
|
131
|
+
region?: KimiCodeRegion;
|
|
132
|
+
}): Promise<KimiCodeLoginFlowStatus>;
|
|
133
|
+
//# sourceMappingURL=oauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../../src/host/kimi-code/oauth.ts"],"names":[],"mappings":"AA+BA,OAAO,EACL,mBAAmB,EAInB,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAA;AACzB,OAAO,KAAK,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AAclG,qFAAqF;AACrF,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,OAAO,EAAE,MAAM;CAI5B;AAED,iEAAiE;AACjE,qBAAa,sBAAuB,SAAQ,KAAK;IAClB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;gBAAzC,OAAO,EAAE,MAAM,EAAW,KAAK,CAAC,EAAE,OAAO,YAAA;C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,CAAC,EAAE,OAAO,KAAK,CAAC;IAAC,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,cAAc,CAAA;CAAO,GACrG,OAAO,CAAC,uBAAuB,CAAC,CAiClC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import { PROVIDER_ID, PROVIDER_NAME } from './types.ts';
|
|
3
|
+
import { FileCredentialStore, FileModelSettingsStore, type KimiCodeCatalogModel, type KimiCodePreferenceStore } from './token-store.ts';
|
|
4
|
+
import { type KimiCodeWebStatus } from '../../shared/kimi-code-contracts.ts';
|
|
5
|
+
/**
|
|
6
|
+
* The selection the card should show.
|
|
7
|
+
*
|
|
8
|
+
* A stored list that still equals the shipped default has never been edited, so
|
|
9
|
+
* it cannot know about models the live catalog has since added; treating it as
|
|
10
|
+
* "everything currently offered" keeps a first run from hiding the whole
|
|
11
|
+
* catalog behind an unedited default. Any explicit edit is honoured exactly.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveEnabledModelIds(stored: readonly string[], catalog: readonly KimiCodeCatalogModel[]): string[];
|
|
14
|
+
export interface KimiCodeStatusOptions {
|
|
15
|
+
fetchFn?: typeof fetch;
|
|
16
|
+
/** Whether this plugin currently owns the provider route; re-read on every status. */
|
|
17
|
+
serving?: boolean | (() => boolean);
|
|
18
|
+
/** Diagnostic when another plugin owns the provider route; re-read on every status. */
|
|
19
|
+
conflict?: string | null | (() => string | null);
|
|
20
|
+
}
|
|
21
|
+
/** Everything the settings card renders: account, quota, and the model catalog. */
|
|
22
|
+
export declare function getKimiCodeWebStatus(store: FileCredentialStore, modelSettings: FileModelSettingsStore, preferences?: KimiCodePreferenceStore, options?: KimiCodeStatusOptions): Promise<KimiCodeWebStatus>;
|
|
23
|
+
/** Register the Kimi Code settings routes under `/kimi-code/api`. */
|
|
24
|
+
export declare function registerKimiCodeRoutes(ctx: Context, store: FileCredentialStore, modelSettings: FileModelSettingsStore, preferences?: KimiCodePreferenceStore, options?: KimiCodeStatusOptions): () => void;
|
|
25
|
+
export { PROVIDER_ID, PROVIDER_NAME };
|
|
26
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../../src/host/kimi-code/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,EAEL,WAAW,EACX,aAAa,EAId,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EAEtB,KAAK,oBAAoB,EAEzB,KAAK,uBAAuB,EAC7B,MAAM,kBAAkB,CAAA;AAazB,OAAO,EAML,KAAK,iBAAiB,EACvB,MAAM,qCAAqC,CAAA;AAqE5C;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,EAAE,SAAS,oBAAoB,EAAE,GACvC,MAAM,EAAE,CAYV;AAED,MAAM,WAAW,qBAAqB;IACpC,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,oBAAoB,CACxC,KAAK,EAAE,mBAAmB,EAC1B,aAAa,EAAE,sBAAsB,EACrC,WAAW,CAAC,EAAE,uBAAuB,EACrC,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,iBAAiB,CAAC,CA0C5B;AAQD,qEAAqE;AACrE,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,mBAAmB,EAC1B,aAAa,EAAE,sBAAsB,EACrC,WAAW,CAAC,EAAE,uBAAuB,EACrC,OAAO,GAAE,qBAA0B,GAClC,MAAM,IAAI,CA+JZ;AAED,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,CAAA"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { SettingsProvider } from '@deepseek-ai/dsh-settings';
|
|
2
|
+
import type { KimiCodeReasoningEffort, KimiCodeRegion } from '../../shared/kimi-code-contracts.ts';
|
|
3
|
+
import type { CredentialStore } from '../token-store.ts';
|
|
4
|
+
import { DEFAULT_OAUTH_HOST } from './types.ts';
|
|
5
|
+
export declare const KIMI_CODE_PREFERENCES_NAMESPACE = "dsh-kimi-code";
|
|
6
|
+
export type { KimiCodeReasoningEffort };
|
|
7
|
+
/**
|
|
8
|
+
* One stored Kimi Code credential.
|
|
9
|
+
*
|
|
10
|
+
* Kimi Code is an OAuth subscription: the bearer pair rotates, so both tokens
|
|
11
|
+
* are kept and the access token is refreshed shortly before it expires. The
|
|
12
|
+
* remaining fields are non-secret account facts the settings card renders
|
|
13
|
+
* without another round trip.
|
|
14
|
+
*/
|
|
15
|
+
export interface KimiCodeCredentials {
|
|
16
|
+
/** Bearer access token for the coding API. Host-only; never sent to a browser. */
|
|
17
|
+
accessToken: string;
|
|
18
|
+
/** Rotating refresh token. Host-only. */
|
|
19
|
+
refreshToken: string;
|
|
20
|
+
/** Unix milliseconds the access token stops being valid. */
|
|
21
|
+
expiresAt: number;
|
|
22
|
+
/** Lifetime the token endpoint reported, in seconds. */
|
|
23
|
+
expiresIn: number;
|
|
24
|
+
scope?: string;
|
|
25
|
+
tokenType?: string;
|
|
26
|
+
/** Region the credential was issued in; decides which hosts are used. */
|
|
27
|
+
region: KimiCodeRegion;
|
|
28
|
+
/** OAuth host the credential came from, so a refresh targets the same one. */
|
|
29
|
+
oauthHost: string;
|
|
30
|
+
/** Coding API base URL the credential was issued for, without /v1. */
|
|
31
|
+
baseUrl: string;
|
|
32
|
+
userId?: string;
|
|
33
|
+
nickname?: string;
|
|
34
|
+
email?: string;
|
|
35
|
+
planName?: string;
|
|
36
|
+
/** Unix milliseconds the credential was obtained. */
|
|
37
|
+
authenticatedAt?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface KimiCodeCatalogModel {
|
|
40
|
+
id: string;
|
|
41
|
+
name?: string;
|
|
42
|
+
contextWindow?: number;
|
|
43
|
+
reasoningEfforts?: string[];
|
|
44
|
+
defaultReasoningEffort?: string;
|
|
45
|
+
inputModalities?: Array<'text' | 'image' | 'video'>;
|
|
46
|
+
protocol?: 'openai' | 'anthropic';
|
|
47
|
+
/** Whether the model also accepts video input (reported; DSH cannot send it). */
|
|
48
|
+
supportsVideo?: boolean;
|
|
49
|
+
/** One-line description from the official model table. */
|
|
50
|
+
description?: string;
|
|
51
|
+
/** Subscription tier the model needs, when not every member has it. */
|
|
52
|
+
minimumPlan?: string | null;
|
|
53
|
+
/**
|
|
54
|
+
* Whether the model supports dynamically loaded tools.
|
|
55
|
+
*
|
|
56
|
+
* K3 advertises this: extra tool definitions can be injected mid-conversation
|
|
57
|
+
* as a system message carrying a `tools` array, keeping the top-level list
|
|
58
|
+
* small and stable. DSH has no equivalent concept, so this is reported for
|
|
59
|
+
* information rather than acted on.
|
|
60
|
+
*/
|
|
61
|
+
supportsDynamicTools?: boolean;
|
|
62
|
+
}
|
|
63
|
+
export interface KimiCodeModelSettings {
|
|
64
|
+
enabledModelIds: string[];
|
|
65
|
+
catalogModels: KimiCodeCatalogModel[];
|
|
66
|
+
contextWindowOverrides: Record<string, number>;
|
|
67
|
+
defaultReasoningEffort: KimiCodeReasoningEffort | null;
|
|
68
|
+
}
|
|
69
|
+
export interface KimiCodePreferenceStore {
|
|
70
|
+
status(): KimiCodeModelSettings;
|
|
71
|
+
update(patch: {
|
|
72
|
+
enabledModelIds?: string[];
|
|
73
|
+
contextWindowOverrides?: Record<string, number>;
|
|
74
|
+
defaultReasoningEffort?: KimiCodeReasoningEffort | null;
|
|
75
|
+
}): Promise<KimiCodeModelSettings>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Bind the model selection to the DSH settings document, which is what the
|
|
79
|
+
* settings service can persist durably; the JSON file beside it remains the
|
|
80
|
+
* store used when the plugin runs without a settings provider (headless tests).
|
|
81
|
+
*/
|
|
82
|
+
export declare function registerKimiCodePreferenceStore(settings?: SettingsProvider, fallbackStore?: FileModelSettingsStore): KimiCodePreferenceStore;
|
|
83
|
+
export declare function credentialPath(): string;
|
|
84
|
+
export declare function modelSettingsPath(): string;
|
|
85
|
+
/** File the install channel uses to pin a region before the first login. */
|
|
86
|
+
export declare function regionMarkerPath(): string;
|
|
87
|
+
/**
|
|
88
|
+
* Stable per-installation device id the managed service expects.
|
|
89
|
+
*
|
|
90
|
+
* The official client writes this once and reuses it; it is not a secret, only
|
|
91
|
+
* an identity marker, so it lives beside the other plugin state.
|
|
92
|
+
*/
|
|
93
|
+
export declare function deviceIdPath(): string;
|
|
94
|
+
export declare function parseKimiCodeCredentials(value: unknown): KimiCodeCredentials;
|
|
95
|
+
/** Encrypted credential store; the plaintext JSON is only a migration source. */
|
|
96
|
+
export declare class FileCredentialStore {
|
|
97
|
+
private readonly filePath;
|
|
98
|
+
private readonly backend;
|
|
99
|
+
constructor(filePath?: string, backend?: CredentialStore<KimiCodeCredentials>);
|
|
100
|
+
path(): string;
|
|
101
|
+
private serialize;
|
|
102
|
+
private removeLegacy;
|
|
103
|
+
private saveVerified;
|
|
104
|
+
read(): Promise<KimiCodeCredentials | null>;
|
|
105
|
+
write(credentials: KimiCodeCredentials): Promise<void>;
|
|
106
|
+
delete(): Promise<void>;
|
|
107
|
+
}
|
|
108
|
+
/** Plain-JSON model settings used when the settings service is unavailable. */
|
|
109
|
+
export declare class FileModelSettingsStore {
|
|
110
|
+
private readonly filePath;
|
|
111
|
+
constructor(filePath?: string);
|
|
112
|
+
path(): string;
|
|
113
|
+
read(): Promise<KimiCodeModelSettings>;
|
|
114
|
+
write(settings: KimiCodeModelSettings): Promise<void>;
|
|
115
|
+
updateSettings(patch: {
|
|
116
|
+
enabledModelIds?: string[];
|
|
117
|
+
contextWindowOverrides?: Record<string, number>;
|
|
118
|
+
defaultReasoningEffort?: KimiCodeReasoningEffort | null;
|
|
119
|
+
}): Promise<KimiCodeModelSettings>;
|
|
120
|
+
setCatalogModels(catalogModels: KimiCodeCatalogModel[], options?: {
|
|
121
|
+
enabledModelIds?: string[];
|
|
122
|
+
}): Promise<KimiCodeModelSettings>;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Resolve the region this installation belongs to.
|
|
126
|
+
*
|
|
127
|
+
* Read locally, never probed: an environment pin wins, then the marker file the
|
|
128
|
+
* install channel may have written, then the default. A region only selects
|
|
129
|
+
* hosts, so an unknown marker is ignored rather than fatal.
|
|
130
|
+
*/
|
|
131
|
+
export declare function resolveRegion(env?: NodeJS.ProcessEnv): Promise<KimiCodeRegion>;
|
|
132
|
+
/** Remember a region choice so a later status call reports the same one. */
|
|
133
|
+
export declare function persistRegion(region: KimiCodeRegion): Promise<void>;
|
|
134
|
+
export { DEFAULT_OAUTH_HOST };
|
|
135
|
+
//# sourceMappingURL=token-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-store.d.ts","sourceRoot":"","sources":["../../../../src/host/kimi-code/token-store.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,2BAA2B,CAAA;AAGhF,OAAO,KAAK,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AAElG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAKxD,OAAO,EAAE,kBAAkB,EAAwE,MAAM,YAAY,CAAA;AAErH,eAAO,MAAM,+BAA+B,kBAAkB,CAAA;AAE9D,YAAY,EAAE,uBAAuB,EAAE,CAAA;AAOvC;;;;;;;GAOG;AACH,MAAM,WAAW,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AAO,CAAC,IAAI,CAAC;CAOxB;AAED,+EAA+E;AAC/E,qBAAa,sBAAsB;IACrB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,SAAsB;IAE3D,IAAI,IAAI,MAAM;IAIR,IAAI,IAAI,OAAO,CAAC,qBAAqB,CAAC;IAgCtC,KAAK,CAAC,QAAQ,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOrD,cAAc,CAAC,KAAK,EAAE;QAC1B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;QAC1B,sBAAsB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAC/C,sBAAsB,CAAC,EAAE,uBAAuB,GAAG,IAAI,CAAA;KACxD,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAgB5B,gBAAgB,CACpB,aAAa,EAAE,oBAAoB,EAAE,EACrC,OAAO,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GACvC,OAAO,CAAC,qBAAqB,CAAC;CAUlC;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,OAAO,CAAC,cAAc,CAAC,CAiBjG;AAED,4EAA4E;AAC5E,wBAAsB,aAAa,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAQzE;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAA"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static facts about the Kimi Code provider API.
|
|
3
|
+
*
|
|
4
|
+
* Kimi Code is the subscription product (https://www.kimi.com/code); it is a
|
|
5
|
+
* different system from the pay-as-you-go Moonshot Open Platform, and its keys
|
|
6
|
+
* and base URLs are not interchangeable. The facts below are transcribed from
|
|
7
|
+
* the official CLI sources and documentation:
|
|
8
|
+
*
|
|
9
|
+
* - the OAuth device flow lives on auth.kimi.com and is implemented by
|
|
10
|
+
* MoonshotAI/kimi-cli in src/kimi_cli/auth/oauth.py;
|
|
11
|
+
* - the managed provider is configured as type "kimi", an OpenAI-compatible
|
|
12
|
+
* client, against https://api.kimi.com/coding/v1;
|
|
13
|
+
* - the same service documents https://api.kimi.com/coding/ as an Anthropic
|
|
14
|
+
* Messages base URL for third-party tools;
|
|
15
|
+
* - account quota comes from GET /coding/v1/usages.
|
|
16
|
+
*
|
|
17
|
+
* See https://www.kimi.com/code/docs/en/kimi-code/models.html and
|
|
18
|
+
* https://www.kimi.com/code/docs/en/kimi-code/error-reference.html
|
|
19
|
+
*/
|
|
20
|
+
import type { KimiCodeReasoningEffort, KimiCodeRegion, KimiCodeWire } from '../../shared/kimi-code-contracts.ts';
|
|
21
|
+
export declare const PROVIDER_ID = "kimi-code";
|
|
22
|
+
export declare const PROVIDER_NAME = "Kimi Code";
|
|
23
|
+
/**
|
|
24
|
+
* OAuth client id the official Kimi CLI registers.
|
|
25
|
+
*
|
|
26
|
+
* The device flow has no client secret: the client id alone identifies the
|
|
27
|
+
* public client, exactly as RFC 8628 intends for a device that cannot keep one.
|
|
28
|
+
*/
|
|
29
|
+
export declare const KIMI_CODE_CLIENT_ID = "17e5f671-d194-4dfb-9706-5516cb48c098";
|
|
30
|
+
/** OAuth host serving /api/oauth/device_authorization and /api/oauth/token. */
|
|
31
|
+
export declare const DEFAULT_OAUTH_HOST = "https://auth.kimi.com";
|
|
32
|
+
/** Device authorization endpoint (RFC 8628 section 3.1). */
|
|
33
|
+
export declare const DEVICE_AUTHORIZATION_PATH = "/api/oauth/device_authorization";
|
|
34
|
+
/** Token endpoint for both the device-code grant and refresh (RFC 8628 section 3.4). */
|
|
35
|
+
export declare const OAUTH_TOKEN_PATH = "/api/oauth/token";
|
|
36
|
+
/** Grant type the device-code polling request declares. */
|
|
37
|
+
export declare const DEVICE_CODE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
38
|
+
/** Host set per region; a global account is served by the .ai properties. */
|
|
39
|
+
export declare const REGION_HOSTS: Record<KimiCodeRegion, {
|
|
40
|
+
oauth: string;
|
|
41
|
+
coding: string;
|
|
42
|
+
}>;
|
|
43
|
+
/** OpenAI-compatible prefix; append /chat/completions or /models. */
|
|
44
|
+
export declare const OPENAI_API_PREFIX = "/v1";
|
|
45
|
+
export declare const USER_AGENT = "dsh-chatgpt-subscription (+https://github.com/Aa728848/dsh-chatgpt-subscription)";
|
|
46
|
+
/**
|
|
47
|
+
* Product markers the managed service recognizes.
|
|
48
|
+
*
|
|
49
|
+
* The official client identifies itself as kimi_cli and reports a stable
|
|
50
|
+
* per-installation device id; sending the same vocabulary keeps the subscription
|
|
51
|
+
* endpoints answering the way they do for the official CLI.
|
|
52
|
+
*/
|
|
53
|
+
export declare const MSH_PLATFORM = "kimi_code_cli";
|
|
54
|
+
export declare const HEADER_MSH_PLATFORM = "x-msh-platform";
|
|
55
|
+
export declare const HEADER_MSH_VERSION = "x-msh-version";
|
|
56
|
+
export declare const HEADER_MSH_DEVICE_NAME = "x-msh-device-name";
|
|
57
|
+
export declare const HEADER_MSH_DEVICE_MODEL = "x-msh-device-model";
|
|
58
|
+
export declare const HEADER_MSH_OS_VERSION = "x-msh-os-version";
|
|
59
|
+
export declare const HEADER_MSH_DEVICE_ID = "x-msh-device-id";
|
|
60
|
+
/** Version the plugin reports to the managed service's telemetry headers. */
|
|
61
|
+
export declare const MSH_VERSION = "1.0.0";
|
|
62
|
+
/**
|
|
63
|
+
* Refresh timing, copied from the official client.
|
|
64
|
+
*
|
|
65
|
+
* A token is refreshed once it is within max(300s, expires_in * 0.5) of expiry,
|
|
66
|
+
* so a short-lived token is replaced early enough to never be used while stale.
|
|
67
|
+
*/
|
|
68
|
+
export declare const MIN_REFRESH_THRESHOLD_SECONDS = 300;
|
|
69
|
+
export declare const REFRESH_THRESHOLD_RATIO = 0.5;
|
|
70
|
+
/** How long a rejected refresh token is remembered before a new attempt. */
|
|
71
|
+
export declare const UNAUTHORIZED_REFRESH_RETRY_COOLDOWN_MS = 300000;
|
|
72
|
+
/** Attempts one refresh gets before the stored credential is declared dead. */
|
|
73
|
+
export declare const REFRESH_MAX_RETRIES = 3;
|
|
74
|
+
/** Exponential backoff base for a retryable refresh failure. */
|
|
75
|
+
export declare const REFRESH_BACKOFF_BASE_MS = 1000;
|
|
76
|
+
/** Device-flow polling defaults when the service omits them. */
|
|
77
|
+
export declare const DEFAULT_DEVICE_INTERVAL_SECONDS = 5;
|
|
78
|
+
export declare const DEFAULT_DEVICE_EXPIRES_SECONDS = 600;
|
|
79
|
+
/** Local timeouts and cache lifetimes. */
|
|
80
|
+
export declare const DISCOVERY_TIMEOUT_MS = 15000;
|
|
81
|
+
export declare const LOGIN_TIMEOUT_MS: number;
|
|
82
|
+
export declare const QUOTA_CACHE_TTL_MS: number;
|
|
83
|
+
export declare const CATALOG_CACHE_TTL_MS: number;
|
|
84
|
+
/** Output cap used when neither the registry nor the live catalog states one. */
|
|
85
|
+
export declare const DEFAULT_MAX_TOKENS = 32768;
|
|
86
|
+
export declare const DEFAULT_CONTEXT_WINDOW = 262144;
|
|
87
|
+
export declare const STREAM_IDLE_TIMEOUT_MS = 300000;
|
|
88
|
+
export declare const STREAM_IDLE_TIMEOUT_CODE = "LLM_STREAM_IDLE_TIMEOUT";
|
|
89
|
+
/**
|
|
90
|
+
* Resolve the managed OAuth host.
|
|
91
|
+
*
|
|
92
|
+
* The official client lets an environment variable pin the host for testing or
|
|
93
|
+
* for a private deployment; the region then supplies the default.
|
|
94
|
+
*/
|
|
95
|
+
export declare function oauthHost(region?: KimiCodeRegion): string;
|
|
96
|
+
/**
|
|
97
|
+
* Resolve the coding API base URL without a trailing slash or version.
|
|
98
|
+
*
|
|
99
|
+
* The official client reads KIMI_CODE_BASE_URL, which already includes /v1;
|
|
100
|
+
* this plugin keeps the prefix separate so both dialects can be built from one
|
|
101
|
+
* value. An override that carries /v1 has it stripped exactly once.
|
|
102
|
+
*/
|
|
103
|
+
export declare function codingBaseUrl(region?: KimiCodeRegion): string;
|
|
104
|
+
/** OpenAI-compatible request URL for one endpoint suffix. */
|
|
105
|
+
export declare function openAIUrl(suffix: string, region?: KimiCodeRegion): string;
|
|
106
|
+
/** Anthropic-compatible request URL for one endpoint suffix, such as /v1/messages. */
|
|
107
|
+
export declare function anthropicUrl(suffix: string, region?: KimiCodeRegion): string;
|
|
108
|
+
/**
|
|
109
|
+
* Path the Anthropic-compatible Messages endpoint is posted to.
|
|
110
|
+
*
|
|
111
|
+
* The managed service exposes its Anthropic surface behind the beta gateway,
|
|
112
|
+
* exactly as the official client's `client.beta.messages.create` call does.
|
|
113
|
+
*/
|
|
114
|
+
export declare const ANTHROPIC_MESSAGES_PATH = "/v1/messages?beta=true";
|
|
115
|
+
/** Anthropic protocol revision the managed service documents. */
|
|
116
|
+
export declare const ANTHROPIC_VERSION = "2023-06-01";
|
|
117
|
+
/**
|
|
118
|
+
* Which wire dialect a model id is served over.
|
|
119
|
+
*
|
|
120
|
+
* The managed service speaks both protocols for every model, so the choice is a
|
|
121
|
+
* client preference rather than a per-model constraint. The OpenAI dialect is
|
|
122
|
+
* the default because that is what the official CLI configures for the managed
|
|
123
|
+
* provider.
|
|
124
|
+
*/
|
|
125
|
+
export declare function wireForModel(_modelId: string): KimiCodeWire;
|
|
126
|
+
/** Thinking levels one model advertises, from the static registry. */
|
|
127
|
+
export declare function reasoningEffortsFor(modelId: string): string[];
|
|
128
|
+
/**
|
|
129
|
+
* Accepted request modalities for one model.
|
|
130
|
+
*
|
|
131
|
+
* An unknown model falls back to text-only, matching the sibling routes: DSH
|
|
132
|
+
* turns a false "no images" into a visible placeholder the user can correct,
|
|
133
|
+
* while a false "images accepted" sends bytes to an endpoint that rejects the
|
|
134
|
+
* whole request.
|
|
135
|
+
*/
|
|
136
|
+
export declare function inputModalitiesFor(modelId: string): Array<'text' | 'image' | 'video'>;
|
|
137
|
+
/**
|
|
138
|
+
* Room a request must leave below its context window.
|
|
139
|
+
*
|
|
140
|
+
* The service rejects a request whose prompt plus requested output exceeds the
|
|
141
|
+
* model's window ("Your request exceeded model token limit: 262144"), so the
|
|
142
|
+
* output cap is derived from the window rather than fixed. 4,096 tokens is the
|
|
143
|
+
* headroom reserved for the prompt on a request that declares no size — the same
|
|
144
|
+
* shape the official client's completion budgeting uses.
|
|
145
|
+
*/
|
|
146
|
+
export declare const CONTEXT_HEADROOM_TOKENS = 4096;
|
|
147
|
+
/**
|
|
148
|
+
* Output cap one request asks for when the caller omits one.
|
|
149
|
+
*
|
|
150
|
+
* The K3 family reasons by default and `reasoning_content` is billed as output,
|
|
151
|
+
* so a fixed 32K cap silently truncates a long `max`-effort turn mid-thought and
|
|
152
|
+
* returns a `length` finish — the official client instead caps output at the
|
|
153
|
+
* model's context window (clamped to window − prompt). The declared floor is
|
|
154
|
+
* kept as a minimum so a small window cannot starve the answer.
|
|
155
|
+
*/
|
|
156
|
+
export declare function maxOutputTokensFor(modelId: string, contextWindow?: number): number;
|
|
157
|
+
/**
|
|
158
|
+
* Reduce the requested output cap so prompt + output fit the window.
|
|
159
|
+
*
|
|
160
|
+
* `estimatedInputTokens` is the caller's own size estimate; when it is absent
|
|
161
|
+
* the cap is left alone rather than guessed at, because under-asking truncates
|
|
162
|
+
* reasoning while over-asking is rejected outright — the service is the final
|
|
163
|
+
* authority and only it knows the real prompt size.
|
|
164
|
+
*/
|
|
165
|
+
export declare function clampOutputToContext(requested: number, contextWindow: number, estimatedInputTokens?: number): number;
|
|
166
|
+
/** Reasoning levels the whole route understands, for route-level validation. */
|
|
167
|
+
export declare function isKimiCodeReasoningEffort(value: unknown): value is KimiCodeReasoningEffort;
|
|
168
|
+
/** Context window used before the live catalog has answered. */
|
|
169
|
+
export declare const FALLBACK_MODELS: ReadonlyArray<{
|
|
170
|
+
id: string;
|
|
171
|
+
name: string;
|
|
172
|
+
contextWindow: number;
|
|
173
|
+
}>;
|
|
174
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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M,GAAG,MAAM,EAAE,CAE7D;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,CAKrF;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,OAAQ,CAAA;AAE5C;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAKlF;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,oBAAoB,CAAC,EAAE,MAAM,GAC5B,MAAM,CAKR;AAED,gFAAgF;AAChF,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,uBAAuB,CAE1F;AAED,gEAAgE;AAChE,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CACY,CAAA"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local store for videos this plugin attaches to a Kimi Code request.
|
|
3
|
+
*
|
|
4
|
+
* DSH's attachment service normalizes and stores images only, and no DSH
|
|
5
|
+
* surface can produce a video block, so the route owns its own store rather
|
|
6
|
+
* than pretending DSH issued these references. The store is deliberately
|
|
7
|
+
* narrow: a tool ingests bytes, a reader hands them back for one request.
|
|
8
|
+
*
|
|
9
|
+
* The identifier is the sha256 of the stored bytes, so re-ingesting the same
|
|
10
|
+
* file is idempotent and a reference cannot silently point at different bytes.
|
|
11
|
+
*/
|
|
12
|
+
import { type VideoAttachmentRef } from './modalities.ts';
|
|
13
|
+
/**
|
|
14
|
+
* Largest single video this route will carry.
|
|
15
|
+
*
|
|
16
|
+
* Two independent published limits bound this, and the smaller wins:
|
|
17
|
+
*
|
|
18
|
+
* - the official Kimi video integration encodes a local file as
|
|
19
|
+
* `data:video/...;base64,...` and caps that payload at about 50 MB;
|
|
20
|
+
* - the VS Code client caps a picked video file at 20 MB.
|
|
21
|
+
*
|
|
22
|
+
* The integration figure is the one that describes what the MODEL accepts
|
|
23
|
+
* over this exact wire, so the cap is set just under it rather than at the
|
|
24
|
+
* editor's more conservative picker limit. Note this is an encoded payload
|
|
25
|
+
* limit: base64 grows bytes by 4/3, so the raw file must stay under 3/4 of it.
|
|
26
|
+
*/
|
|
27
|
+
export declare const MAX_VIDEO_FILE_BYTES: number;
|
|
28
|
+
/** Maximum base64 payload derived from {@link MAX_VIDEO_FILE_BYTES}. */
|
|
29
|
+
export declare const MAX_VIDEO_BASE64_BYTES: number;
|
|
30
|
+
/** Directory the ingested videos live in. */
|
|
31
|
+
export declare function videoStoreDir(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Media type for one path, from its extension.
|
|
34
|
+
*
|
|
35
|
+
* A local file rarely carries a usable declared type, so the extension is the
|
|
36
|
+
* signal; an unknown one yields undefined rather than a guess, so the caller
|
|
37
|
+
* can refuse instead of sending a type the service will reject.
|
|
38
|
+
*/
|
|
39
|
+
export declare function mediaTypeForPath(filePath: string): string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Whether this route will actually send this container.
|
|
42
|
+
*
|
|
43
|
+
* The ingress accepts exactly what the mapper can put on the wire, so a file
|
|
44
|
+
* is either accepted and sent or refused with a reason. An earlier revision
|
|
45
|
+
* also stored Matroska (.mkv), which some third-party integrations accept but
|
|
46
|
+
* the vision guide does not list; that produced a video reported as "attached"
|
|
47
|
+
* which the mapper then silently downgraded to a placeholder. Accepting only
|
|
48
|
+
* {@link KIMI_VIDEO_MEDIA_TYPES} keeps the tool's promise and the wire's
|
|
49
|
+
* behaviour the same thing.
|
|
50
|
+
*/
|
|
51
|
+
export declare function isStorableVideoType(mediaType: string): boolean;
|
|
52
|
+
/** Raised when an ingest cannot produce a usable reference. */
|
|
53
|
+
export declare class VideoIngestError extends Error {
|
|
54
|
+
readonly code: string;
|
|
55
|
+
constructor(message: string, code: string);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Commit one video's bytes and return the reference a request can cite.
|
|
59
|
+
*
|
|
60
|
+
* @param data - complete encoded file bytes.
|
|
61
|
+
* @param declaredType - media type from the source (extension or Content-Type).
|
|
62
|
+
* @param name - display name; never interpreted as a path.
|
|
63
|
+
* @param declaredBytes - total the source advertised, when it did, so an
|
|
64
|
+
* oversized file is refused before its bytes are buffered.
|
|
65
|
+
*/
|
|
66
|
+
export declare function saveVideo(input: {
|
|
67
|
+
data: Uint8Array;
|
|
68
|
+
declaredType: string | undefined;
|
|
69
|
+
name: string;
|
|
70
|
+
declaredBytes?: number;
|
|
71
|
+
}): Promise<VideoAttachmentRef>;
|
|
72
|
+
/**
|
|
73
|
+
* Total bytes the store may occupy before it prunes itself.
|
|
74
|
+
*
|
|
75
|
+
* Videos are content-addressed and re-attaching an identical file costs nothing,
|
|
76
|
+
* but nothing ever removed an old clip, so the directory only grew. The budget
|
|
77
|
+
* is deliberately generous (a few large clips) and enforced only on write, so a
|
|
78
|
+
* prune never runs during a read of the clip about to be sent.
|
|
79
|
+
*/
|
|
80
|
+
export declare const VIDEO_STORE_BUDGET_BYTES: number;
|
|
81
|
+
/**
|
|
82
|
+
* Drop the least recently used objects until the store fits its budget.
|
|
83
|
+
*
|
|
84
|
+
* Recency is the object's mtime, which writing refreshes, so a clip that was
|
|
85
|
+
* just re-attached is not the one evicted. Failure is swallowed: a store that
|
|
86
|
+
* cannot be pruned must not fail the attachment the caller asked for.
|
|
87
|
+
*/
|
|
88
|
+
export declare function pruneVideoStore(budgetBytes?: number): Promise<number>;
|
|
89
|
+
/** Path of the stored object for a reference, or undefined when it is gone. */
|
|
90
|
+
export declare function storedPathFor(ref: VideoAttachmentRef): string | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Read the bytes one reference points at.
|
|
93
|
+
*
|
|
94
|
+
* The reference is re-verified against the stored bytes: a file whose digest
|
|
95
|
+
* no longer matches its name is refused rather than sent, so a tampered or
|
|
96
|
+
* truncated object cannot reach the model as if it were the original.
|
|
97
|
+
*/
|
|
98
|
+
export declare function readVideoBytes(ref: VideoAttachmentRef): Promise<Uint8Array>;
|
|
99
|
+
//# sourceMappingURL=video-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video-store.d.ts","sourceRoot":"","sources":["../../../../src/host/kimi-code/video-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,EAA0B,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEjF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,QAAmB,CAAA;AAEpD,wEAAwE;AACxE,eAAO,MAAM,sBAAsB,QAA0C,CAAA;AAE7E,6CAA6C;AAC7C,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AA+BD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAErE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE9D;AAED,+DAA+D;AAC/D,qBAAa,gBAAiB,SAAQ,KAAK;IACZ,QAAQ,CAAC,IAAI,EAAE,MAAM;gBAAtC,OAAO,EAAE,MAAM,EAAW,IAAI,EAAE,MAAM;CAInD;AAED;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE;IACrC,IAAI,EAAE,UAAU,CAAA;IAChB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA8C9B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,QAAoB,CAAA;AAEzD;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,WAAW,SAA2B,GAAG,OAAO,CAAC,MAAM,CAAC,CA8B7F;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,GAAG,EAAE,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAIzE;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC,CAgBjF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool that attaches a video for the next Kimi Code request.
|
|
3
|
+
*
|
|
4
|
+
* DSH's attachment service stores images only and no DSH surface can produce a
|
|
5
|
+
* video block, so this route supplies its own ingress. The bytes are committed
|
|
6
|
+
* to the plugin's video store and then injected into the conversation as a
|
|
7
|
+
* plugin-sourced user message, which is the same mechanism this plugin already
|
|
8
|
+
* uses to return a generated image to the model.
|
|
9
|
+
*
|
|
10
|
+
* Two sources are accepted:
|
|
11
|
+
*
|
|
12
|
+
* - an absolute local path, read straight from disk;
|
|
13
|
+
* - an http(s) URL, fetched through the deployment's proxy-aware fetch and
|
|
14
|
+
* checked against the same public-address policy the search/fetch provider
|
|
15
|
+
* uses, so this cannot become an SSRF primitive against the local network.
|
|
16
|
+
*/
|
|
17
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
18
|
+
export declare const KIMI_VIDEO_TOOL_NAME = "kimi_attach_video";
|
|
19
|
+
type FetchLike = typeof fetch;
|
|
20
|
+
export interface KimiVideoToolOptions {
|
|
21
|
+
fetchFn?: FetchLike;
|
|
22
|
+
}
|
|
23
|
+
export declare function createKimiVideoTool(ctx: Context, options?: KimiVideoToolOptions): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=video-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video-tool.d.ts","sourceRoot":"","sources":["../../../../src/host/kimi-code/video-tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAOlD,eAAO,MAAM,oBAAoB,sBAAsB,CAAA;AAEvD,KAAK,SAAS,GAAG,OAAO,KAAK,CAAA;AAE7B,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,SAAS,CAAA;CACpB;AAwID,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,oBAAyB,mDAwGnF"}
|