@eddyskywalker/dsh-chatgpt-subscription 0.9.9 → 0.10.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/README.md +80 -2
  3. package/lib/client.js +1596 -207
  4. package/lib/client.js.map +1 -1
  5. package/lib/index.js +4834 -1019
  6. package/lib/types/client/ProviderHubSection.d.ts.map +1 -1
  7. package/lib/types/client/claude/locales.d.ts +2 -2
  8. package/lib/types/client/command-code/locales.d.ts +2 -2
  9. package/lib/types/client/index.d.ts +2 -0
  10. package/lib/types/client/index.d.ts.map +1 -1
  11. package/lib/types/client/kimi-code/locales.d.ts +2 -2
  12. package/lib/types/client/minimax-code/MinimaxCodeComposerQuota.d.ts +27 -0
  13. package/lib/types/client/minimax-code/MinimaxCodeComposerQuota.d.ts.map +1 -0
  14. package/lib/types/client/minimax-code/MinimaxCodeSection.d.ts +49 -0
  15. package/lib/types/client/minimax-code/MinimaxCodeSection.d.ts.map +1 -0
  16. package/lib/types/client/minimax-code/api.d.ts +5 -0
  17. package/lib/types/client/minimax-code/api.d.ts.map +1 -0
  18. package/lib/types/client/minimax-code/locales.d.ts +341 -0
  19. package/lib/types/client/minimax-code/locales.d.ts.map +1 -0
  20. package/lib/types/client/minimax-code/styles.d.ts +12 -0
  21. package/lib/types/client/minimax-code/styles.d.ts.map +1 -0
  22. package/lib/types/client/styles.d.ts +19 -0
  23. package/lib/types/client/styles.d.ts.map +1 -1
  24. package/lib/types/compat.d.ts +1 -0
  25. package/lib/types/compat.d.ts.map +1 -1
  26. package/lib/types/host/agent-preset.d.ts.map +1 -1
  27. package/lib/types/host/claude/mapper.d.ts +11 -2
  28. package/lib/types/host/claude/mapper.d.ts.map +1 -1
  29. package/lib/types/host/minimax-code/account-pool.d.ts +219 -0
  30. package/lib/types/host/minimax-code/account-pool.d.ts.map +1 -0
  31. package/lib/types/host/minimax-code/adapter.d.ts +168 -0
  32. package/lib/types/host/minimax-code/adapter.d.ts.map +1 -0
  33. package/lib/types/host/minimax-code/client.d.ts +184 -0
  34. package/lib/types/host/minimax-code/client.d.ts.map +1 -0
  35. package/lib/types/host/minimax-code/mapper.d.ts +143 -0
  36. package/lib/types/host/minimax-code/mapper.d.ts.map +1 -0
  37. package/lib/types/host/minimax-code/model-catalog.d.ts +146 -0
  38. package/lib/types/host/minimax-code/model-catalog.d.ts.map +1 -0
  39. package/lib/types/host/minimax-code/oauth.d.ts +204 -0
  40. package/lib/types/host/minimax-code/oauth.d.ts.map +1 -0
  41. package/lib/types/host/minimax-code/routes.d.ts +79 -0
  42. package/lib/types/host/minimax-code/routes.d.ts.map +1 -0
  43. package/lib/types/host/minimax-code/token-store.d.ts +238 -0
  44. package/lib/types/host/minimax-code/token-store.d.ts.map +1 -0
  45. package/lib/types/host/minimax-code/types.d.ts +206 -0
  46. package/lib/types/host/minimax-code/types.d.ts.map +1 -0
  47. package/lib/types/host/subagent-model-authorization.d.ts +7 -0
  48. package/lib/types/host/subagent-model-authorization.d.ts.map +1 -1
  49. package/lib/types/index.d.ts +10 -0
  50. package/lib/types/index.d.ts.map +1 -1
  51. package/lib/types/shared/minimax-code-contracts.d.ts +166 -0
  52. package/lib/types/shared/minimax-code-contracts.d.ts.map +1 -0
  53. package/package.json +1 -1
  54. package/presets/dispatch/agent.cordis.yml +13 -1
@@ -0,0 +1,184 @@
1
+ /**
2
+ * HTTP surface of the MiniMax Code subscription.
3
+ *
4
+ * ONE header rule governs this whole file, and it is the one the brief calls out as
5
+ * a hard constraint: credentials are sent as `authorization: Bearer <accessToken>`.
6
+ * The endpoint also speaks the Anthropic wire format, whose client normally
7
+ * authenticates with `x-api-key`, and that difference was measured directly — an
8
+ * `x-api-key` request answers 401 `{"code":401,"message":"token is required"}`
9
+ * while the bearer form answers 200. There is deliberately no fallback that tries
10
+ * `x-api-key` after a 401: the measured verdict is that it cannot succeed, and a
11
+ * retry would only add a request to the subscription's bill.
12
+ *
13
+ * The second rule is an absence: this file has no `/v1/models` call and must never
14
+ * grow one. That route is not configured for subscription traffic and answers 503
15
+ * `{"errorCode":50115,"errorReason":"direct_route_not_configured"}`; the model
16
+ * directory is hardcoded in ./model-catalog.ts instead.
17
+ */
18
+ import { DEFAULT_DEVICE_INTERVAL_SECONDS, MESSAGES_PATH, agentBaseUrl, MINIMAX_CODE_BUILD_ENV, redactToken } from './types.ts';
19
+ import { MinimaxCodeCredentialStore, type MinimaxCodeCredentials } from './token-store.ts';
20
+ import { MinimaxCodeUnauthorizedError } from './oauth.ts';
21
+ import type { MinimaxCodeAccount, MinimaxCodeQuota, MinimaxCodeRegion } from '../../shared/minimax-code-contracts.ts';
22
+ /**
23
+ * Headers for one Messages request.
24
+ *
25
+ * `authorization: Bearer` is REQUIRED and is the only credential field sent —
26
+ * see this file's header comment for the measured reason an `x-api-key` variant
27
+ * must not exist.
28
+ *
29
+ * The token itself never appears in a log line or an error: callers that need to
30
+ * name a credential do so through `redactToken`.
31
+ */
32
+ export declare function modelRequestHeaders(accessToken: string): Record<string, string>;
33
+ /** Headers for a non-streaming call (the probe). */
34
+ export declare function probeRequestHeaders(accessToken: string): Record<string, string>;
35
+ /** One parsed Anthropic `usage` object. */
36
+ export interface MinimaxUsage {
37
+ inputTokens: number;
38
+ outputTokens: number;
39
+ cacheReadTokens: number;
40
+ cacheWriteTokens: number;
41
+ }
42
+ /** Read the four token counters the Messages response reports. */
43
+ export declare function parseAnthropicUsage(payload: unknown): MinimaxUsage | null;
44
+ /** Short, single-line excerpt of one error body, safe to show a user. */
45
+ export declare function summarizeFailureBody(raw: string): string;
46
+ export interface MinimaxProbeResult {
47
+ ok: boolean;
48
+ /** Model the probe used, when it reached the service. */
49
+ model?: string;
50
+ /** Failure sentence, already safe to render. */
51
+ error?: string;
52
+ latencyMs: number;
53
+ account?: MinimaxCodeAccount | null;
54
+ usage?: MinimaxUsage;
55
+ }
56
+ /**
57
+ * Model the connection probe uses.
58
+ *
59
+ * M3 is the model the measured request used, so a probe against it exercises the
60
+ * exact shape the reconnaissance attested rather than a preview id that may not be
61
+ * entitled on every account.
62
+ */
63
+ export declare const PROBE_MODEL = "MiniMax-M3";
64
+ /**
65
+ * Prove the stored credential still authenticates.
66
+ *
67
+ * The probe is the real Messages endpoint, because that is the only surface the
68
+ * subscription exposes to a third-party client: there is no account-profile route
69
+ * and `/v1/models` is unavailable, so a 200 from `/messages` is what "signed in"
70
+ * means here. The request is deliberately tiny — one word, 16 output tokens — so a
71
+ * probe the user triggered by pressing a button costs almost nothing.
72
+ */
73
+ export declare function testConnection(store: MinimaxCodeCredentialStore, options?: {
74
+ fetchFn?: typeof fetch;
75
+ signal?: AbortSignal;
76
+ }): Promise<MinimaxProbeResult>;
77
+ /**
78
+ * Non-streaming Messages call, used by callers that want the body rather than a stream.
79
+ *
80
+ * It exists so the streaming path is not the only implementation of the request
81
+ * shape: the probe and any future test use the same headers and URL builder, which
82
+ * is what keeps the Bearer rule from drifting in a second place.
83
+ */
84
+ export declare function createMessage(store: MinimaxCodeCredentialStore, request: {
85
+ model: string;
86
+ maxTokens: number;
87
+ prompt: string;
88
+ }, options?: {
89
+ fetchFn?: typeof fetch;
90
+ signal?: AbortSignal;
91
+ }): Promise<{
92
+ ok: boolean;
93
+ status: number;
94
+ payload?: unknown;
95
+ error?: string;
96
+ latencyMs: number;
97
+ }>;
98
+ /**
99
+ * Headers for the Token Plan usage read.
100
+ *
101
+ * NOT {@link modelRequestHeaders}: that set asks for `text/event-stream` because
102
+ * the Messages route streams, and this route answers one JSON document. The
103
+ * credential is still the same bearer token.
104
+ */
105
+ export declare function quotaRequestHeaders(accessToken: string, pathWithSearch: string, requestTime?: number): Record<string, string>;
106
+ /**
107
+ * The host that last answered.
108
+ *
109
+ * Only a live call can settle which candidate serves this subscription, so the
110
+ * winner is remembered and probed first from then on.
111
+ */
112
+ /**
113
+ * Why a usage snapshot is absent, when the reason is worth stating on the card.
114
+ *
115
+ * - `credential-not-accepted` — the endpoint answered, and refused THIS line's
116
+ * credential because it needs a platform API key. Measured: every candidate
117
+ * host answers HTTP 200 with `base_resp.status_code: 1004` for an
118
+ * `mcode-public` (MiniMax Code) token, under every auth shape tried.
119
+ * - `unreachable` — no candidate host produced a usable answer at all.
120
+ */
121
+ export type MinimaxCodeQuotaUnavailable = 'credential-not-accepted' | 'unreachable';
122
+ /** Forget the cached usage snapshot (a sign-out, a sign-in, a test). */
123
+ export declare function clearCachedQuota(): void;
124
+ /** The last usage snapshot without touching the network. */
125
+ export declare function getCachedQuota(): MinimaxCodeQuota | null;
126
+ /** Why the last read produced no snapshot, or null when it produced one. */
127
+ export declare function getQuotaUnavailable(): MinimaxCodeQuotaUnavailable | null;
128
+ /**
129
+ * Resolve the ambiguous `*_usage_count` fields.
130
+ *
131
+ * TRANSCRIBED from the official CLI (`src/utils/quota.ts`), because the ambiguity
132
+ * is real and reading the field naively inverts the bar: older responses report
133
+ * it as a REMAINING count while newer ones report it as a CONSUMED count. When the
134
+ * server also returns an explicit remaining percentage, that percentage selects
135
+ * whichever reading agrees with it; when the counts agree with neither, this
136
+ * returns undefined and the window falls back to the percentage alone rather than
137
+ * inventing a number.
138
+ */
139
+ export declare function resolveQuotaCounts(reportedCount: number, total: number, remainingPercent: number | undefined): {
140
+ used: number;
141
+ remaining: number;
142
+ total: number;
143
+ } | undefined;
144
+ /**
145
+ * Map one `/v1/token_plan/remains` document onto the card's quota shape.
146
+ *
147
+ * Returns null when nothing usable is present, which the contract defines as the
148
+ * card's graceful degradation.
149
+ */
150
+ export declare function parseTokenPlanQuota(payload: unknown, now?: number): MinimaxCodeQuota | null;
151
+ /**
152
+ * Read the Token Plan usage snapshot.
153
+ *
154
+ * The endpoint is undocumented (it was found in the official CLI, not in MiniMax's
155
+ * API docs), and which host serves THIS subscription has never been measured, so
156
+ * the candidates are tried in order and the winner is remembered. Any failure
157
+ * yields null: the contract makes `quota` optional precisely so a usage read can
158
+ * never break the connection half of the card.
159
+ */
160
+ export declare function fetchTokenPlanQuota(credentials: MinimaxCodeCredentials, options?: {
161
+ fetchFn?: typeof fetch;
162
+ signal?: AbortSignal;
163
+ force?: boolean;
164
+ }): Promise<MinimaxCodeQuota | null>;
165
+ /**
166
+ * Every model id the hardcoded directory offers.
167
+ *
168
+ * Exposed as a function rather than re-exported directly so the status route
169
+ * cannot accidentally treat the catalog as live data: it is shipped, not fetched.
170
+ */
171
+ export declare function listModelIds(): string[];
172
+ /** The catalog entry count, for a status line that reports what is shipped. */
173
+ export declare function catalogSize(): number;
174
+ /**
175
+ * Whether a credential is worth reporting as signed in.
176
+ *
177
+ * A stored-but-expired credential still counts: the card's job is to show who is
178
+ * signed in and let the refresh path repair the token, not to hide an account whose
179
+ * access token happens to have aged out between two calls.
180
+ */
181
+ export declare function describeCredentials(credentials: MinimaxCodeCredentials | null): MinimaxCodeAccount | null;
182
+ export { MinimaxCodeUnauthorizedError, agentBaseUrl, MESSAGES_PATH, DEFAULT_DEVICE_INTERVAL_SECONDS, MINIMAX_CODE_BUILD_ENV, redactToken };
183
+ export type { MinimaxCodeRegion };
184
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/host/minimax-code/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAEL,+BAA+B,EAC/B,aAAa,EACb,YAAY,EAMZ,sBAAsB,EAEtB,WAAW,EACZ,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,0BAA0B,EAC1B,KAAK,sBAAsB,EAC5B,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAA6C,4BAA4B,EAAE,MAAM,YAAY,CAAA;AAEpG,OAAO,KAAK,EACV,kBAAkB,EAClB,gBAAgB,EAEhB,iBAAiB,EAClB,MAAM,wCAAwC,CAAA;AAU/C;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE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C,EAAE,WAAW,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GAC9E,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAmDlC;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,MAAM,EAAE,CAEvC;AAED,+EAA+E;AAC/E,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,sBAAsB,GAAG,IAAI,GAAG,kBAAkB,GAAG,IAAI,CAEzG;AAED,OAAO,EAAE,4BAA4B,EAAE,YAAY,EAAE,aAAa,EAAE,+BAA+B,EAAE,sBAAsB,EAAE,WAAW,EAAE,CAAA;AAC1I,YAAY,EAAE,iBAAiB,EAAE,CAAA"}
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Provider-wire mapping for the MiniMax Code subscription.
3
+ *
4
+ * The subscription speaks Anthropic Messages, so this file builds a
5
+ * \`/messages\` body and normalizes the SSE stream back into DSH's block/delta
6
+ * vocabulary.
7
+ *
8
+ * WHAT IS REUSED, AND WHAT IS NOT
9
+ *
10
+ * The generic halves of this problem already exist beside it in
11
+ * \`../kimi-code/mapper.ts\` and are imported rather than reimplemented: durable
12
+ * image resolution, the image budget that drops the oldest attachments first,
13
+ * JSON-Schema cleanup for tool parameters, and the serialized-body guard. None of
14
+ * those is provider-specific, and having one implementation is what keeps the two
15
+ * lines from drifting.
16
+ *
17
+ * The provider-specific halves are written here:
18
+ *
19
+ * - the thinking control. The subscription's own model table names its thinking
20
+ * vocabulary (M2.7 always on with no level, M3 a two-state switch, M3.1 forced
21
+ * on with a level), which is not Kimi's low/high/max ladder; and
22
+ * - every diagnostic string, because an error a user reads must name the service
23
+ * they are actually talking to.
24
+ *
25
+ * WHAT IS MEASURED AND WHAT IS INFERRED
26
+ *
27
+ * Measured (brief sections 2.1 and 2.3): the endpoint, the URL shape
28
+ * \`<base>/mavis/api/v1/llm/v1/messages\`, the bearer header, the Anthropic
29
+ * protocol revision, the request body \`{model, max_tokens, messages}\` answering
30
+ * 200, and the four usage counters in the response.
31
+ *
32
+ * Inferred, and isolated in \`thinkingFieldFor\` so it is the only thing to change if
33
+ * it is ever contradicted: the \`thinking\` object's exact shape. The model table
34
+ * describes thinking as a state ("none-thinking / thinking") and, for M3.1, as an
35
+ * \`effort\` level, so the field is emitted in that vocabulary and nowhere else. No
36
+ * other undocumented field is ever sent.
37
+ *
38
+ * UNRESOLVED, AND DELIBERATELY NOT ACTED ON: prompt caching.
39
+ *
40
+ * No `cache_control` marker is ever sent, yet this file reads the two cache
41
+ * counters out of `usage` (see the message_start branch) - so the route is
42
+ * prepared to report cache hits it never asks for. MiniMax documents two
43
+ * different mechanisms, and they are not interchangeable:
44
+ *
45
+ * - an AUTOMATIC cache on its native API, which needs no marker at all; and
46
+ * - an EXPLICIT cache on its Anthropic-compatible API, where the
47
+ * `cache_control` breakpoints are what create the cache at all
48
+ * (`tools` -> `system` -> `messages`, per the "Explicit Prompt Caching
49
+ * (Anthropic API)" page of the MiniMax docs).
50
+ *
51
+ * This line speaks the Anthropic dialect, so the explicit mechanism may well be
52
+ * the one that applies - but the subscription endpoint is NOT the public API
53
+ * (`<base>/mavis/api/v1/llm/v1/messages` vs `api.minimax.io/anthropic`), and its
54
+ * caching behaviour has never been measured here. Adding a marker is not free
55
+ * either: `system` is a plain string on this line, so a system-level breakpoint
56
+ * means changing that field into an array of blocks, and a marker on a block the
57
+ * wire does not accept can fail the whole request - the same class of total
58
+ * failure the missing `stream: true` caused.
59
+ *
60
+ * So the marker stays out until one live request settles it: send a body with
61
+ * and without a breakpoint and compare `cache_read_input_tokens`. The shape to
62
+ * copy once that is measured is the Claude line's, which marks only a block the
63
+ * wire accepts and states the intent at the call site because caching there is
64
+ * request-driven (`claude/mapper.ts`, `claude/adapter.ts`).
65
+ */
66
+ import { type ContentBlock, type OutboundContentBlock, type GenerateOptions, type StreamChunk } from '../common/llm-compat.ts';
67
+ import { MAX_MESSAGE_BODY_BYTES, estimatedInputTokens, offloadOldestRequestImages, resolveRequestImages, type AttachmentImageReader, type ResolvedRequestImages } from '../kimi-code/mapper.ts';
68
+ import { ANTHROPIC_VERSION } from './types.ts';
69
+ export { MAX_MESSAGE_BODY_BYTES, estimatedInputTokens, offloadOldestRequestImages, resolveRequestImages };
70
+ export type { AttachmentImageReader, ResolvedRequestImages };
71
+ /**
72
+ * The thinking control for one request.
73
+ *
74
+ * This is the single inferred field in the builder, and it is kept to the
75
+ * vocabulary the subscription's own model table uses:
76
+ *
77
+ * - \`always-on\` (M2.7, M2.7-highspeed): nothing is sent. The model always thinks
78
+ * and has no level, so any field would be decoration at best and a rejected one
79
+ * at worst;
80
+ * - \`toggle\` (M3): the table names the two states "none-thinking / thinking", so
81
+ * the off state is the explicit disable and the on state is what a request that
82
+ * says nothing already gets;
83
+ * - \`forced-effort\` (M3.1-Flash-Preview): thinking is forced on and the table
84
+ * gives the level in an \`effort\` field, so the level travels there.
85
+ *
86
+ * A caller asking for a level the model does not list is mapped to the model's
87
+ * documented default by \`effortForModel\` before it reaches here.
88
+ */
89
+ export declare function thinkingFieldFor(modelId: string, requestedEffort: string | undefined | null): Record<string, unknown> | undefined;
90
+ /** Output cap one request asks for, tracked against the model's declared ceiling. */
91
+ export declare function maxOutputTokensFor(modelId: string, contextWindow?: number): number;
92
+ /** Reduce a requested cap so prompt plus output still fit the window. */
93
+ export declare function clampOutputToContext(requested: number, contextWindow: number, estimatedInputTokens?: number): number;
94
+ /** Build one Anthropic Messages body for this subscription. */
95
+ export declare function buildMinimaxRequest(options: GenerateOptions, images?: ResolvedRequestImages): Record<string, unknown>;
96
+ /**
97
+ * Reject a request the service would refuse, before sending it.
98
+ *
99
+ * @returns the serialized body, so the caller about to send it does not serialize
100
+ * a multi-megabyte string a second time.
101
+ */
102
+ export declare function assertRequestBodyFits(body: Record<string, unknown>): string;
103
+ /** One tool call accumulating across content-block deltas. */
104
+ interface PendingToolCall {
105
+ blockIndex: number;
106
+ id: string;
107
+ name: string;
108
+ arguments: string;
109
+ }
110
+ /** Stream accumulator for one Messages response. */
111
+ export interface MinimaxStreamState {
112
+ blocks: OutboundContentBlock[];
113
+ current: {
114
+ index: number;
115
+ type: 'text' | 'reasoning';
116
+ text: string;
117
+ } | null;
118
+ /** wire content-block index -> accumulating call. */
119
+ toolCalls: Map<number, PendingToolCall>;
120
+ /** wire content-block index -> our block index. */
121
+ contentIndexes: Map<number, number>;
122
+ hasContent: boolean;
123
+ hasToolCall: boolean;
124
+ finishReason: string | null;
125
+ done: boolean;
126
+ finished: boolean;
127
+ inputTokens: number;
128
+ outputTokens: number;
129
+ cacheReadTokens: number;
130
+ cacheWriteTokens: number;
131
+ sawUsage: boolean;
132
+ }
133
+ export declare function createStreamState(): MinimaxStreamState;
134
+ /** Flush every open block, then emit usage and the terminal finish. */
135
+ export declare function closeMinimaxStream(state: MinimaxStreamState): StreamChunk[];
136
+ /** Raise when a stream ended without the terminal event the protocol promises. */
137
+ export declare function assertStreamComplete(state: MinimaxStreamState): void;
138
+ /** Feed one SSE line from the Messages endpoint. */
139
+ export declare function processMinimaxStreamLine(line: string, state: MinimaxStreamState): StreamChunk[];
140
+ /** Whether one chunk stream carried any assistant content at all. */
141
+ export declare function streamHasContent(state: MinimaxStreamState): boolean;
142
+ export { ANTHROPIC_VERSION, type ContentBlock };
143
+ //# sourceMappingURL=mapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapper.d.ts","sourceRoot":"","sources":["../../../../src/host/minimax-code/mapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AAEH,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAEzB,KAAK,eAAe,EAEpB,KAAK,WAAW,EAEjB,MAAM,yBAAyB,CAAA;AAEhC,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,0BAA0B,EAC1B,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M,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;IAC3E,qDAAqD;IACrD,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IACvC,mDAAmD;IACnD,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACnC,UAAU,EAAE,OAAO,CAAA;IACnB,WAAW,EAAE,OAAO,CAAA;IACpB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,IAAI,EAAE,OAAO,CAAA;IACb,QAAQ,EAAE,OAAO,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,MAAM,CAAA;IACxB,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,iBAAiB,IAAI,kBAAkB,CAiBtD;AAoDD,uEAAuE;AACvE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,GAAG,WAAW,EAAE,CAO3E;AAED,kFAAkF;AAClF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAIpE;AAED,oDAAoD;AACpD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,GAAG,WAAW,EAAE,CA8I/F;AAED,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAEnE;AAED,OAAO,EAAE,iBAAiB,EAAE,KAAK,YAAY,EAAE,CAAA"}
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Hardcoded catalog of the models the MiniMax Code subscription serves.
3
+ *
4
+ * This catalog is hardcoded on purpose. The endpoint documents a
5
+ * `GET /v1/models` route, but it is not configured for subscription traffic and
6
+ * answers 503 `{"errorCode":50115,"errorReason":"direct_route_not_configured"}`
7
+ * (and 401 when queried with `x-api-key`). Nothing in this package may probe it,
8
+ * at startup or otherwise.
9
+ *
10
+ * The four entries and every number in them are transcribed verbatim from the
11
+ * model table in `~/.minimax/config.yaml` (brief section 2.3). No value here is
12
+ * inferred from another provider's catalog.
13
+ */
14
+ import type { MinimaxCodeModelOption, MinimaxCodeReasoningEffort } from '../../shared/minimax-code-contracts.ts';
15
+ /**
16
+ * How one model's thinking behaves.
17
+ *
18
+ * - `always-on` — thinking cannot be turned off and has no selectable level;
19
+ * - `toggle` — thinking is on by default and can be disabled;
20
+ * - `forced-effort` — thinking is forced on and a level can be selected.
21
+ */
22
+ export type MinimaxCodeThinkingMode = 'always-on' | 'toggle' | 'forced-effort';
23
+ /** One model the MiniMax Code subscription serves. */
24
+ export interface MinimaxCodeCatalogModel {
25
+ /** Exact model id to put on the wire. */
26
+ id: string;
27
+ /** Display name shown in the picker. */
28
+ name: string;
29
+ /** Context window the account is entitled to by default. */
30
+ contextWindow: number;
31
+ /** Larger window the model can reach, when one is offered as an option. */
32
+ optionalContextWindow: number | null;
33
+ /** Output cap the model accepts. */
34
+ maxTokens: number;
35
+ /**
36
+ * Input the model accepts.
37
+ *
38
+ * Declared as the wire accepts it. Note that a capability listed here is a claim
39
+ * DSH's capability pipeline acts on (prompt admission, the model picker, subagent
40
+ * delegation), so this line lists only what its mapper can actually put on the
41
+ * wire. Video is deliberately NOT listed even though the model table documents it
42
+ * on M3 and M3.1: DSH's attachment service is image-only and this line installs no
43
+ * video byte reader, so a clip that reached the mapper would be replaced by a
44
+ * placeholder — advertising it would promise an upload the route cannot perform.
45
+ * Add 'video' here only together with a real reader (see the Kimi Code line, which
46
+ * implements one in `video-store.ts` and widens the modality vocabulary for it).
47
+ */
48
+ inputModalities: readonly ('text' | 'image')[];
49
+ /** How thinking behaves on this model. */
50
+ thinking: MinimaxCodeThinkingMode;
51
+ /**
52
+ * Levels the model accepts, in escalating order.
53
+ *
54
+ * A single `default` entry means the model has no selectable level: the picker
55
+ * shows one always-on option rather than inventing a gradient the model does
56
+ * not document.
57
+ */
58
+ reasoningEfforts: readonly MinimaxCodeReasoningEffort[];
59
+ /** Level used when the conversation does not pick one. */
60
+ defaultReasoningEffort: MinimaxCodeReasoningEffort;
61
+ /** Attachments one request may carry, when the model states a bound. */
62
+ maxAttachments: number | null;
63
+ /** Largest single image the model accepts, in bytes. */
64
+ maxImageBytes: number | null;
65
+ /** Largest single video the model accepts, in bytes. */
66
+ maxVideoBytes: number | null;
67
+ /** Whether the model is served through the subscription's files API. */
68
+ supportsFilesApi: boolean;
69
+ /** One-line description, from the model table. */
70
+ description: string;
71
+ }
72
+ /**
73
+ * The four ids the subscription serves today.
74
+ *
75
+ * `MiniMax-M3` is the durable default: it is the flagship the measured request
76
+ * used, and it is the one model whose wire behaviour is directly attested.
77
+ */
78
+ export declare const MINIMAX_CODE_MODELS: readonly MinimaxCodeCatalogModel[];
79
+ /** Registry entry for one model id, or undefined when the id is unknown. */
80
+ export declare function minimaxCodeModelDef(modelId: string): MinimaxCodeCatalogModel | undefined;
81
+ /** Membership test for one known model id. */
82
+ export declare function isMinimaxCodeModelId(value: unknown): boolean;
83
+ /** Display name for one model id, falling back to the raw id so nothing is hidden. */
84
+ export declare function minimaxCodeModelName(modelId: string): string;
85
+ /** Every model id the picker offers, in catalog order. */
86
+ export declare function minimaxCodeModelIds(): string[];
87
+ /**
88
+ * Whether one effort id means "thinking off".
89
+ *
90
+ * The subscription table spells the disabled state "none-thinking" while the
91
+ * shared contract's effort vocabulary has no such member, so a caller that
92
+ * nevertheless asks for an off state (an older preference file, a hand-built
93
+ * request) is recognized here rather than silently treated as "on".
94
+ */
95
+ export declare function isThinkingDisabledEffort(value: unknown): boolean;
96
+ /**
97
+ * The effort level to put on the wire for one model.
98
+ *
99
+ * An unknown or off value falls back to the model's documented default, so a
100
+ * caller cannot talk this route into a level the model does not list.
101
+ */
102
+ export declare function effortForModel(modelId: string, requested: string | undefined | null): MinimaxCodeReasoningEffort;
103
+ /**
104
+ * Smallest context window an override may name.
105
+ *
106
+ * Exported because the settings route validates POSTed overrides against the
107
+ * same number this reader uses: if they drifted, the route would accept a value
108
+ * the reader then treats as absent, and the card would show a saved override
109
+ * that silently does nothing.
110
+ */
111
+ export declare const MIN_CONTEXT_WINDOW = 1000;
112
+ /**
113
+ * The effective context window for one model.
114
+ *
115
+ * One reader for both the status card and the request path, because the two
116
+ * disagreeing is the exact failure this override can cause: the card would show
117
+ * a window the request builder then ignored, and the user would see a request
118
+ * clamped to the catalog's number with nothing on screen explaining why.
119
+ *
120
+ * A non-positive or sub-minimum override is treated as absent rather than
121
+ * clamped: the route never stores one (it validates them), so seeing one means
122
+ * the document was hand-edited, and inventing a window from it would size every
123
+ * request on that model against a number the user never chose.
124
+ */
125
+ export declare function contextWindowForModel(modelId: string, contextWindowOverrides: Record<string, number> | undefined): number;
126
+ /**
127
+ * The catalog ids the user's stored selection actually resolves to.
128
+ *
129
+ * A stored list that still equals the shipped default has never been edited, so
130
+ * it cannot know about models a later release added; treating it as "everything
131
+ * the catalog currently offers" is what keeps a first run from hiding a new
132
+ * model behind an unedited default. Any explicit edit is honoured exactly, and
133
+ * an id the catalog no longer serves is dropped so the picker cannot offer a
134
+ * model this build has no entry for.
135
+ */
136
+ export declare function resolveMinimaxCodeEnabledModelIds(stored: readonly string[], enabled?: boolean): string[];
137
+ /**
138
+ * The settings-card rows for the whole shipped catalog.
139
+ *
140
+ * Every model is present, enabled or not: the card toggles rows, so a disabled
141
+ * model has to be rendered to be re-enabled. `contextWindow` is the effective
142
+ * window and `defaultContextWindow` the catalog's own number, which is what lets
143
+ * the card show a modified row as modified.
144
+ */
145
+ export declare function buildMinimaxCodeModelOptions(storedEnabledModelIds: readonly string[], contextWindowOverrides: Record<string, number>, enabled?: boolean): MinimaxCodeModelOption[];
146
+ //# sourceMappingURL=model-catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-catalog.d.ts","sourceRoot":"","sources":["../../../../src/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