@eddyskywalker/dsh-chatgpt-subscription 0.10.0 → 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.
- package/CHANGELOG.md +45 -0
- package/README.md +39 -1
- package/lib/client.js +1569 -205
- package/lib/client.js.map +1 -1
- package/lib/index.js +4775 -1030
- package/lib/types/client/ProviderHubSection.d.ts.map +1 -1
- package/lib/types/client/index.d.ts +2 -0
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/minimax-code/MinimaxCodeComposerQuota.d.ts +27 -0
- package/lib/types/client/minimax-code/MinimaxCodeComposerQuota.d.ts.map +1 -0
- package/lib/types/client/minimax-code/MinimaxCodeSection.d.ts +49 -0
- package/lib/types/client/minimax-code/MinimaxCodeSection.d.ts.map +1 -0
- package/lib/types/client/minimax-code/api.d.ts +5 -0
- package/lib/types/client/minimax-code/api.d.ts.map +1 -0
- package/lib/types/client/minimax-code/locales.d.ts +341 -0
- package/lib/types/client/minimax-code/locales.d.ts.map +1 -0
- package/lib/types/client/minimax-code/styles.d.ts +12 -0
- package/lib/types/client/minimax-code/styles.d.ts.map +1 -0
- package/lib/types/client/styles.d.ts.map +1 -1
- package/lib/types/compat.d.ts +1 -0
- package/lib/types/compat.d.ts.map +1 -1
- package/lib/types/host/minimax-code/account-pool.d.ts +219 -0
- package/lib/types/host/minimax-code/account-pool.d.ts.map +1 -0
- package/lib/types/host/minimax-code/adapter.d.ts +168 -0
- package/lib/types/host/minimax-code/adapter.d.ts.map +1 -0
- package/lib/types/host/minimax-code/client.d.ts +184 -0
- package/lib/types/host/minimax-code/client.d.ts.map +1 -0
- package/lib/types/host/minimax-code/mapper.d.ts +143 -0
- package/lib/types/host/minimax-code/mapper.d.ts.map +1 -0
- package/lib/types/host/minimax-code/model-catalog.d.ts +146 -0
- package/lib/types/host/minimax-code/model-catalog.d.ts.map +1 -0
- package/lib/types/host/minimax-code/oauth.d.ts +204 -0
- package/lib/types/host/minimax-code/oauth.d.ts.map +1 -0
- package/lib/types/host/minimax-code/routes.d.ts +79 -0
- package/lib/types/host/minimax-code/routes.d.ts.map +1 -0
- package/lib/types/host/minimax-code/token-store.d.ts +238 -0
- package/lib/types/host/minimax-code/token-store.d.ts.map +1 -0
- package/lib/types/host/minimax-code/types.d.ts +206 -0
- package/lib/types/host/minimax-code/types.d.ts.map +1 -0
- package/lib/types/index.d.ts +10 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/shared/minimax-code-contracts.d.ts +166 -0
- package/lib/types/shared/minimax-code-contracts.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -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,oBAAoB,EAEpB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC3B,MAAM,wBAAwB,CAAA;AAO/B,OAAO,EACL,iBAAiB,EAKlB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,CAAA;AACzG,YAAY,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,CAAA;AA6Q5D;;;;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AAA;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/host/minimax-code/model-catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,sBAAsB,EACtB,0BAA0B,EAE3B,MAAM,wCAAwC,CAAA;AAI/C;;;;;;GAMG;AACH,MAAM,MAAM,uBAAuB,GAAG,WAAW,GAAG,QAAQ,GAAG,eAAe,CAAA;AAE9E,sDAAsD;AACtD,MAAM,WAAW,uBAAuB;IACtC,yCAAyC;IACzC,EAAE,EAAE,MAAM,CAAA;IACV,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAA;IACZ,4DAA4D;IAC5D,aAAa,EAAE,MAAM,CAAA;IACrB,2EAA2E;IAC3E,qBAA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eAAO,MAAM,kBAAkB,OAAQ,CAAA;AAEvC;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GACzD,MAAM,CAOR;AAED;;;;;;;;;GASG;AACH,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,UAAO,GACb,MAAM,EAAE,CAOV;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,qBAAqB,EAAE,SAAS,MAAM,EAAE,EACxC,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9C,OAAO,UAAO,GACb,sBAAsB,EAAE,CAoB1B"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth for the MiniMax Code subscription.
|
|
3
|
+
*
|
|
4
|
+
* The flow is RFC 8628 device authorization with PKCE(S256) against a public
|
|
5
|
+
* client (`mcode-public`, no secret) — the shape the desktop app uses, and the
|
|
6
|
+
* only one that fits a plugin with no browser callback to receive.
|
|
7
|
+
*
|
|
8
|
+
* Measured facts that shape this file (brief section 2.5):
|
|
9
|
+
*
|
|
10
|
+
* - device authorization: POST `account.minimax.cn/oauth2/device/code`
|
|
11
|
+
* - token (device grant AND refresh): POST `account.minimax.cn/oauth2/token`
|
|
12
|
+
* - revocation: POST `account.minimax.cn/oauth2/revoke`
|
|
13
|
+
* - every call is `application/x-www-form-urlencoded` with `Accept: application/json`
|
|
14
|
+
* - the device grant carries `code_challenge`/`code_challenge_method=S256` and the
|
|
15
|
+
* poll carries the matching `code_verifier`
|
|
16
|
+
* - the refresh carries `grant_type=refresh_token`, `refresh_token`, `client_id`,
|
|
17
|
+
* `scope` and `audience`
|
|
18
|
+
*
|
|
19
|
+
* The refresh policy is the one the brief fixes at section 2.6: read the stored
|
|
20
|
+
* credential first and use it while it is valid, refresh only when it is not (or
|
|
21
|
+
* when the service has just rejected it), write the rotation back atomically, and
|
|
22
|
+
* never let a failed refresh damage the file MiniMax Code itself depends on.
|
|
23
|
+
*/
|
|
24
|
+
import type { MinimaxCodeAccount, MinimaxCodeRegion, MinimaxCodeWebLogin } from '../../shared/minimax-code-contracts.ts';
|
|
25
|
+
import { accountHost } from './types.ts';
|
|
26
|
+
import { type MinimaxCodeCredentialStore, type MinimaxCodeCredentials } from './token-store.ts';
|
|
27
|
+
/** Raised when the stored credential was rejected and a new sign-in is required. */
|
|
28
|
+
export declare class MinimaxCodeUnauthorizedError extends Error {
|
|
29
|
+
constructor(message: string);
|
|
30
|
+
}
|
|
31
|
+
/** Raised when a transient failure outlived its retry budget. */
|
|
32
|
+
export declare class MinimaxCodeRetryableError extends Error {
|
|
33
|
+
constructor(message: string, cause?: unknown);
|
|
34
|
+
}
|
|
35
|
+
/** Raised when the user denied the device authorization request. */
|
|
36
|
+
export declare class MinimaxCodeAccessDeniedError extends Error {
|
|
37
|
+
constructor(message: string);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* One PKCE pair (RFC 7636).
|
|
41
|
+
*
|
|
42
|
+
* The verifier is a fresh random string per authorization; the challenge is its
|
|
43
|
+
* SHA-256 digest, both base64url encoded with no padding, which is what S256
|
|
44
|
+
* means on the wire.
|
|
45
|
+
*/
|
|
46
|
+
export declare function createPkcePair(): {
|
|
47
|
+
verifier: string;
|
|
48
|
+
challenge: string;
|
|
49
|
+
};
|
|
50
|
+
/** Parsed device authorization response. */
|
|
51
|
+
export interface DeviceAuthorization {
|
|
52
|
+
userCode: string;
|
|
53
|
+
deviceCode: string;
|
|
54
|
+
verificationUri: string;
|
|
55
|
+
verificationUriComplete: string;
|
|
56
|
+
expiresIn: number;
|
|
57
|
+
interval: number;
|
|
58
|
+
/** PKCE verifier the matching poll must present. */
|
|
59
|
+
codeVerifier: string;
|
|
60
|
+
/** Region the authorization was requested in; decides every later host. */
|
|
61
|
+
region: MinimaxCodeRegion;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Start a device authorization (RFC 8628 section 3.1).
|
|
65
|
+
*
|
|
66
|
+
* A public client sends its `client_id`, the scope and audience it wants, and the
|
|
67
|
+
* PKCE challenge — no secret, which is the whole point of the device profile.
|
|
68
|
+
*/
|
|
69
|
+
export declare function requestDeviceAuthorization(options?: {
|
|
70
|
+
fetchFn?: typeof fetch;
|
|
71
|
+
signal?: AbortSignal;
|
|
72
|
+
region?: MinimaxCodeRegion;
|
|
73
|
+
}): Promise<DeviceAuthorization>;
|
|
74
|
+
/** One token response, in the shape the store persists. */
|
|
75
|
+
export interface MinimaxToken {
|
|
76
|
+
accessToken: string;
|
|
77
|
+
refreshToken: string;
|
|
78
|
+
tokenType: string;
|
|
79
|
+
expiresInSec: number;
|
|
80
|
+
expiresAtMs: number;
|
|
81
|
+
scope: string;
|
|
82
|
+
}
|
|
83
|
+
/** Outcome of one device-token poll. */
|
|
84
|
+
export type DevicePollOutcome = {
|
|
85
|
+
kind: 'success';
|
|
86
|
+
token: MinimaxToken;
|
|
87
|
+
} | {
|
|
88
|
+
kind: 'pending';
|
|
89
|
+
slowDown: boolean;
|
|
90
|
+
} | {
|
|
91
|
+
kind: 'expired';
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Poll the token endpoint once for one device code (RFC 8628 section 3.4).
|
|
95
|
+
*
|
|
96
|
+
* A 5xx is a transport-class failure rather than a verdict on the device code, so
|
|
97
|
+
* it is raised for the caller's retry loop instead of being read as "still
|
|
98
|
+
* pending" — treating it as pending would spin against a broken endpoint until the
|
|
99
|
+
* device code expired.
|
|
100
|
+
*/
|
|
101
|
+
export declare function pollDeviceToken(authorization: Pick<DeviceAuthorization, 'deviceCode' | 'codeVerifier' | 'region'>, options?: {
|
|
102
|
+
fetchFn?: typeof fetch;
|
|
103
|
+
signal?: AbortSignal;
|
|
104
|
+
}): Promise<DevicePollOutcome>;
|
|
105
|
+
/**
|
|
106
|
+
* Refresh an access token, with a bounded retry.
|
|
107
|
+
*
|
|
108
|
+
* Only a transient status or a transport failure is retried. A 400/401/403, or an
|
|
109
|
+
* `invalid_grant` body, is a verdict that the refresh token is dead and stops
|
|
110
|
+
* immediately: retrying it can never succeed, and every attempt is a request the
|
|
111
|
+
* subscription pays for.
|
|
112
|
+
*/
|
|
113
|
+
export declare function refreshAccessToken(refreshToken: string, options: {
|
|
114
|
+
fetchFn?: typeof fetch;
|
|
115
|
+
signal?: AbortSignal;
|
|
116
|
+
region: MinimaxCodeRegion;
|
|
117
|
+
}): Promise<MinimaxToken>;
|
|
118
|
+
/**
|
|
119
|
+
* Revoke one token at the service.
|
|
120
|
+
*
|
|
121
|
+
* Best effort by design: a revocation that cannot reach the service must not stop
|
|
122
|
+
* a local sign-out, because the credential is already gone from this machine.
|
|
123
|
+
*/
|
|
124
|
+
export declare function revokeToken(token: string, options: {
|
|
125
|
+
fetchFn?: typeof fetch;
|
|
126
|
+
signal?: AbortSignal;
|
|
127
|
+
region: MinimaxCodeRegion;
|
|
128
|
+
}): Promise<boolean>;
|
|
129
|
+
/** Start a device-code sign-in and hand the card what it must display. */
|
|
130
|
+
export declare function beginWebLogin(options?: {
|
|
131
|
+
fetchFn?: typeof fetch;
|
|
132
|
+
region?: MinimaxCodeRegion;
|
|
133
|
+
signal?: AbortSignal;
|
|
134
|
+
}): Promise<MinimaxCodeWebLogin>;
|
|
135
|
+
/** The public projection of one live sign-in, for the status route. */
|
|
136
|
+
export declare function getWebLogin(loginId: string): MinimaxCodeWebLogin | null;
|
|
137
|
+
/** Cancel one sign-in, dropping the session so a later poll cannot resume it. */
|
|
138
|
+
export declare function cancelWebLogin(loginId: string): boolean;
|
|
139
|
+
/** Forget every session; used by the test seam and by a full sign-out. */
|
|
140
|
+
export declare function resetWebLogins(): void;
|
|
141
|
+
/** Build the account projection one credential yields. */
|
|
142
|
+
export declare function accountFromCredentials(credentials: {
|
|
143
|
+
loginEpoch: string;
|
|
144
|
+
generation: number;
|
|
145
|
+
expiresAtMs: number;
|
|
146
|
+
region: MinimaxCodeRegion;
|
|
147
|
+
}): MinimaxCodeAccount;
|
|
148
|
+
export { accountHost };
|
|
149
|
+
/** Whether the given refresh token was rejected recently. */
|
|
150
|
+
export declare function isRefreshTokenRejected(refreshToken: string): boolean;
|
|
151
|
+
/** Test seam: forget every remembered rejection. */
|
|
152
|
+
export declare function resetRefreshRejections(): void;
|
|
153
|
+
export interface EnsureTokenOptions {
|
|
154
|
+
fetchFn?: typeof fetch;
|
|
155
|
+
signal?: AbortSignal;
|
|
156
|
+
/** Refresh even when the stored token is not near expiry (used after a 401). */
|
|
157
|
+
force?: boolean;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Return a usable access token, refreshing and writing back only when needed.
|
|
161
|
+
*
|
|
162
|
+
* This is the whole of the contention discipline in one function:
|
|
163
|
+
*
|
|
164
|
+
* 1. read the stored credential and use it as-is while it is valid — the
|
|
165
|
+
* common case, and the one that never touches the file or the network;
|
|
166
|
+
* 2. refresh only when it is not (or when `force` reports a 401 the service has
|
|
167
|
+
* already issued);
|
|
168
|
+
* 3. share one rotation between concurrent callers, so a burst of tool calls at
|
|
169
|
+
* expiry cannot each try to rotate the same refresh token;
|
|
170
|
+
* 4. write the result back through the store's atomic replacement, and remember a
|
|
171
|
+
* rejected token so the next caller is told to sign in instead of retrying.
|
|
172
|
+
*/
|
|
173
|
+
export declare function ensureAccessToken(store: MinimaxCodeCredentialStore, options?: EnsureTokenOptions): Promise<MinimaxCodeCredentials>;
|
|
174
|
+
/**
|
|
175
|
+
* Poll one live sign-in once and, on success, persist what it produced.
|
|
176
|
+
*
|
|
177
|
+
* The persisted credential is plugin-owned: a device-code sign-in started here
|
|
178
|
+
* has no record in the desktop app's `auth.json` (its record key embeds a hash
|
|
179
|
+
* this plugin cannot reproduce), so writing a fabricated entry there would leave
|
|
180
|
+
* the app with an entry it never reads.
|
|
181
|
+
*/
|
|
182
|
+
export declare function pollWebLogin(store: MinimaxCodeCredentialStore, loginId: string, options?: {
|
|
183
|
+
fetchFn?: typeof fetch;
|
|
184
|
+
signal?: AbortSignal;
|
|
185
|
+
/**
|
|
186
|
+
* Called with the credential a completed sign-in produced, after it has been
|
|
187
|
+
* persisted.
|
|
188
|
+
*
|
|
189
|
+
* The single-credential store cannot express a second account, so without this
|
|
190
|
+
* a sign-in started from the card would never join the pool: the pool would
|
|
191
|
+
* keep serving its existing accounts, and the user's new sign-in would exist
|
|
192
|
+
* only as the mirror file. The pool installs this hook and adds the credential
|
|
193
|
+
* as its own account.
|
|
194
|
+
*
|
|
195
|
+
* A failure here must not fail the sign-in: the credential is already durable,
|
|
196
|
+
* and the pool is a routing convenience on top of it. The caller receives the
|
|
197
|
+
* authenticated verdict either way.
|
|
198
|
+
*/
|
|
199
|
+
onSave?: (credentials: MinimaxCodeCredentials) => Promise<void>;
|
|
200
|
+
}): Promise<{
|
|
201
|
+
status: 'pending' | 'authenticated' | 'expired' | 'denied';
|
|
202
|
+
account?: MinimaxCodeAccount;
|
|
203
|
+
}>;
|
|
204
|
+
//# sourceMappingURL=oauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../../src/host/minimax-code/oauth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AACxH,OAAO,EAgBL,WAAW,EAIZ,MAAM,YAAY,CAAA;AACnB,OAAO,EAEL,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,EAC5B,MAAM,kBAAkB,CAAA;AAEzB,oFAAoF;AACpF,qBAAa,4BAA6B,SAAQ,KAAK;gBACzC,OAAO,EAAE,MAAM;CAI5B;AAED,iEAAiE;AACjE,qBAAa,yBAA0B,SAAQ,KAAK;gBAGtC,OAAO,EAAE,MAAM,EAAE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WAAW,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,iBAAiB,CAAA;CAAE,GACtG,kBAAkB,CAQpB;AAGD,OAAO,EAAE,WAAW,EAAE,CAAA;AAsBtB,6DAA6D;AAC7D,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAQpE;AAED,oDAAoD;AACpD,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C;AAKD,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,OAAO,KAAK,CAAA;IACtB,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,gFAAgF;IAChF,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAOD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,0BAA0B,EACjC,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,sBAAsB,CAAC,CAkDjC;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,KAAK,EAAE,0BAA0B,EACjC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,OAAO,KAAK,CAAA;IACtB,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,sBAAsB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3D,GACL,OAAO,CAAC;IAAE,MAAM,EAAE,SAAS,GAAG,eAAe,GAAG,SAAS,GAAG,QAAQ,CAAC;IAAC,OAAO,CAAC,EAAE,kBAAkB,CAAA;CAAE,CAAC,CA6DvG"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web routes for the MiniMax Code line.
|
|
3
|
+
*
|
|
4
|
+
* The six routes below are the frozen contract the client half consumes (brief
|
|
5
|
+
* section 3). Their paths, request bodies and verdicts are therefore not free:
|
|
6
|
+
* this file implements them as specified rather than as this line might prefer.
|
|
7
|
+
*
|
|
8
|
+
* Response envelope: every route answers \`{ ok: true, value: <payload> }\`, which is
|
|
9
|
+
* what the sibling lines in this package use. The three routes whose contract names
|
|
10
|
+
* a top-level key as well (\`/login/start\` -> \`login\`, \`/login/poll\` -> \`status\` and
|
|
11
|
+
* \`account\`, \`/test\` -> \`ok\`/\`model\`/\`error\`) carry that key at the top level too,
|
|
12
|
+
* so a client written against either reading resolves. \`/test\` is the one route
|
|
13
|
+
* where the envelope's \`ok\` cannot double as the payload's: its contract defines
|
|
14
|
+
* \`ok\` as the probe verdict, so the envelope there is the verdict itself and the
|
|
15
|
+
* duplicate lives under \`value\`.
|
|
16
|
+
*
|
|
17
|
+
* Mounting: the routes are registered under BOTH the contract prefix and the
|
|
18
|
+
* sibling-line convention, because the two disagree in this repository and the
|
|
19
|
+
* client half must not be able to miss them for that reason alone.
|
|
20
|
+
*
|
|
21
|
+
* \`/models\` and \`/settings\` are the model-settings half every sibling line has and
|
|
22
|
+
* this one shipped without. They are two names for one route because the sibling
|
|
23
|
+
* cards disagree about which to call: kimi-code and claude call it \`/models\`,
|
|
24
|
+
* workbuddy and command-code call it \`/settings\`. Serving both costs one string
|
|
25
|
+
* comparison and removes a client-side special case.
|
|
26
|
+
*/
|
|
27
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
28
|
+
import { MINIMAX_CODE_PROVIDER_ID, type MinimaxCodeWebStatus } from '../../shared/minimax-code-contracts.ts';
|
|
29
|
+
import { type MinimaxCodeAccountPool } from './account-pool.ts';
|
|
30
|
+
import { MinimaxCodeCredentialStore, MinimaxCodeModelSettingsStore, type MinimaxCodeModelSettings, type MinimaxCodePreferenceStore, type MinimaxCodeSettingsPatch } from './token-store.ts';
|
|
31
|
+
import { ensureAccessToken, getWebLogin } from './oauth.ts';
|
|
32
|
+
/** The sub-path one request addresses, whichever prefix it arrived under. */
|
|
33
|
+
export declare function subPathOf(requestUrl: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* The stored selection, however this deployment persists it.
|
|
36
|
+
*
|
|
37
|
+
* The routes accept either shape so a composition that still has the register
|
|
38
|
+
* settings seam and one that only has the file both work: the caller passes
|
|
39
|
+
* whichever it wired, and nothing in this file needs to know which it got. The
|
|
40
|
+
* patch type is the store's own, deliberately, so a field added to the settings
|
|
41
|
+
* document cannot become one this route accepts but the stores silently drop.
|
|
42
|
+
*/
|
|
43
|
+
export interface MinimaxCodeSettingsSource {
|
|
44
|
+
/** Current selection: a value on the register seam, a read on the file store. */
|
|
45
|
+
status(): Promise<MinimaxCodeModelSettings> | MinimaxCodeModelSettings;
|
|
46
|
+
update(patch: MinimaxCodeSettingsPatch): Promise<MinimaxCodeModelSettings>;
|
|
47
|
+
}
|
|
48
|
+
export interface MinimaxCodeStatusOptions {
|
|
49
|
+
fetchFn?: typeof fetch;
|
|
50
|
+
/** Whether this plugin currently owns the provider route; re-read on every status. */
|
|
51
|
+
serving?: boolean | (() => boolean);
|
|
52
|
+
/** Diagnostic when another plugin owns the provider route; re-read on every status. */
|
|
53
|
+
conflict?: string | null | (() => string | null);
|
|
54
|
+
/**
|
|
55
|
+
* Where the model selection lives.
|
|
56
|
+
*
|
|
57
|
+
* Omitted, the routes read the default settings file, which is what a caller
|
|
58
|
+
* that only wants the connection half of the card gets. The plugin entry
|
|
59
|
+
* supplies the same store the adapter was built with, so the card and the
|
|
60
|
+
* request path can never read two different selections.
|
|
61
|
+
*/
|
|
62
|
+
settings?: MinimaxCodeSettingsSource;
|
|
63
|
+
/**
|
|
64
|
+
* The account pool, when this process installed one.
|
|
65
|
+
*
|
|
66
|
+
* Omitting it is a supported posture: the line then behaves as the
|
|
67
|
+
* single-credential route it was before the pool existed, and the status
|
|
68
|
+
* reports `poolInstalled: false` so the card can say so rather than render an
|
|
69
|
+
* empty account list that looks like a bug.
|
|
70
|
+
*/
|
|
71
|
+
accountPool?: MinimaxCodeAccountPool;
|
|
72
|
+
}
|
|
73
|
+
/** Everything the settings card renders. */
|
|
74
|
+
export declare function getMinimaxCodeWebStatus(store: MinimaxCodeCredentialStore, options?: MinimaxCodeStatusOptions, settingsSource?: MinimaxCodeSettingsSource): Promise<MinimaxCodeWebStatus>;
|
|
75
|
+
export declare function registerMinimaxCodeRoutes(ctx: Context, store?: MinimaxCodeCredentialStore, options?: MinimaxCodeStatusOptions, modelSettings?: MinimaxCodeModelSettingsStore, preferences?: MinimaxCodePreferenceStore): () => void;
|
|
76
|
+
/** Test seam: forget which sign-in the status route reports. */
|
|
77
|
+
export declare function resetLatestLogin(): void;
|
|
78
|
+
export { MINIMAX_CODE_PROVIDER_ID, getWebLogin, ensureAccessToken };
|
|
79
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../../src/host/minimax-code/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAGlD,OAAO,EACL,wBAAwB,EAMxB,KAAK,oBAAoB,EAC1B,MAAM,wCAAwC,CAAA;AAG/C,OAAO,EAGL,KAAK,sBAAsB,EAC5B,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAE7B,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC9B,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAIL,iBAAiB,EACjB,WAAW,EAKZ,MAAM,YAAY,CAAA;AAqDnB,6EAA6E;AAC7E,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAMpD;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,yBAAyB;IACxC,iFAAiF;IACjF,MAAM,IAAI,OAAO,CAAC,wBAAwB,CAAC,GAAG,wBAAwB,C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