@eddyskywalker/dsh-chatgpt-subscription 0.46.1 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/README.md +22 -1
- package/lib/client.js +2639 -571
- package/lib/client.js.map +1 -1
- package/lib/index.js +12000 -3591
- package/lib/plan-mode-pipeline.js +419 -0
- package/lib/types/client/hub/brand-icons.d.ts +1 -1
- package/lib/types/client/hub/brand-icons.d.ts.map +1 -1
- package/lib/types/client/hub/brand-svg.d.ts +4 -0
- package/lib/types/client/hub/brand-svg.d.ts.map +1 -1
- package/lib/types/client/hub/providers.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/locales-ru/index.d.ts.map +1 -1
- package/lib/types/client/locales-ru/progress-updates.d.ts.map +1 -1
- package/lib/types/client/locales-ru/workbuddy.d.ts +10 -0
- package/lib/types/client/locales-ru/workbuddy.d.ts.map +1 -0
- package/lib/types/client/progress-updates/locales.d.ts +23 -5
- package/lib/types/client/progress-updates/locales.d.ts.map +1 -1
- package/lib/types/client/progress-updates/settings-binding.d.ts +13 -1
- package/lib/types/client/progress-updates/settings-binding.d.ts.map +1 -1
- package/lib/types/client/progress-updates/settings-section.d.ts +1 -1
- package/lib/types/client/progress-updates/settings-section.d.ts.map +1 -1
- package/lib/types/client/workbuddy/WorkBuddyComposerQuota.d.ts +34 -0
- package/lib/types/client/workbuddy/WorkBuddyComposerQuota.d.ts.map +1 -0
- package/lib/types/client/workbuddy/WorkBuddySection.d.ts +91 -0
- package/lib/types/client/workbuddy/WorkBuddySection.d.ts.map +1 -0
- package/lib/types/client/workbuddy/locales.d.ts +768 -0
- package/lib/types/client/workbuddy/locales.d.ts.map +1 -0
- package/lib/types/client/workbuddy/styles.d.ts +21 -0
- package/lib/types/client/workbuddy/styles.d.ts.map +1 -0
- package/lib/types/client/workbuddy/useWorkBuddySection.d.ts +149 -0
- package/lib/types/client/workbuddy/useWorkBuddySection.d.ts.map +1 -0
- package/lib/types/compat.d.ts +1 -1
- package/lib/types/entry-plan-mode-pipeline.d.ts +191 -0
- package/lib/types/entry-plan-mode-pipeline.d.ts.map +1 -0
- package/lib/types/host/agent-preset.d.ts.map +1 -1
- package/lib/types/host/cache-warmup/contracts.d.ts +5 -1
- package/lib/types/host/cache-warmup/contracts.d.ts.map +1 -1
- package/lib/types/host/cache-warmup/install.d.ts.map +1 -1
- package/lib/types/host/cache-warmup/projection.d.ts.map +1 -1
- package/lib/types/host/cache-warmup/retrieval-intent.d.ts +18 -0
- package/lib/types/host/cache-warmup/retrieval-intent.d.ts.map +1 -0
- package/lib/types/host/cache-warmup/settings.d.ts +9 -2
- package/lib/types/host/cache-warmup/settings.d.ts.map +1 -1
- package/lib/types/host/common/capabilities.d.ts.map +1 -1
- package/lib/types/host/common/model-request-control.d.ts +1 -1
- package/lib/types/host/common/model-request-control.d.ts.map +1 -1
- package/lib/types/host/common/request-diagnostics.d.ts +1 -1
- package/lib/types/host/common/request-diagnostics.d.ts.map +1 -1
- package/lib/types/host/compaction-prompt.d.ts +129 -0
- package/lib/types/host/compaction-prompt.d.ts.map +1 -0
- package/lib/types/host/preset-sync.d.ts.map +1 -1
- package/lib/types/host/workbuddy/account-pool.d.ts +389 -0
- package/lib/types/host/workbuddy/account-pool.d.ts.map +1 -0
- package/lib/types/host/workbuddy/adapter.d.ts +249 -0
- package/lib/types/host/workbuddy/adapter.d.ts.map +1 -0
- package/lib/types/host/workbuddy/atrest.d.ts +98 -0
- package/lib/types/host/workbuddy/atrest.d.ts.map +1 -0
- package/lib/types/host/workbuddy/checkin.d.ts +150 -0
- package/lib/types/host/workbuddy/checkin.d.ts.map +1 -0
- package/lib/types/host/workbuddy/client.d.ts +214 -0
- package/lib/types/host/workbuddy/client.d.ts.map +1 -0
- package/lib/types/host/workbuddy/dsml.d.ts +55 -0
- package/lib/types/host/workbuddy/dsml.d.ts.map +1 -0
- package/lib/types/host/workbuddy/guardrails.d.ts +111 -0
- package/lib/types/host/workbuddy/guardrails.d.ts.map +1 -0
- package/lib/types/host/workbuddy/identity.d.ts +71 -0
- package/lib/types/host/workbuddy/identity.d.ts.map +1 -0
- package/lib/types/host/workbuddy/mapper.d.ts +238 -0
- package/lib/types/host/workbuddy/mapper.d.ts.map +1 -0
- package/lib/types/host/workbuddy/model-catalog.d.ts +217 -0
- package/lib/types/host/workbuddy/model-catalog.d.ts.map +1 -0
- package/lib/types/host/workbuddy/oauth.d.ts +47 -0
- package/lib/types/host/workbuddy/oauth.d.ts.map +1 -0
- package/lib/types/host/workbuddy/outbound-identity.d.ts +139 -0
- package/lib/types/host/workbuddy/outbound-identity.d.ts.map +1 -0
- package/lib/types/host/workbuddy/routes.d.ts +56 -0
- package/lib/types/host/workbuddy/routes.d.ts.map +1 -0
- package/lib/types/host/workbuddy/token-store.d.ts +370 -0
- package/lib/types/host/workbuddy/token-store.d.ts.map +1 -0
- package/lib/types/host/workbuddy/types.d.ts +179 -0
- package/lib/types/host/workbuddy/types.d.ts.map +1 -0
- package/lib/types/index.d.ts +35 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/shared/workbuddy-contracts.d.ts +531 -0
- package/lib/types/shared/workbuddy-contracts.d.ts.map +1 -0
- package/package.json +6 -2
- package/presets/dispatch/README.md +57 -3
- package/presets/dispatch/agent.cordis.yml +42 -13
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire mapping for the WorkBuddy / CodeBuddy subscription chat endpoint.
|
|
3
|
+
*
|
|
4
|
+
* The endpoint is OpenAI Chat Completions shaped, but with three measured
|
|
5
|
+
* deviations from the OpenAI default that this module exists to absorb:
|
|
6
|
+
*
|
|
7
|
+
* 1. **Stream only.** `stream: false` answers 400 `code 11101`. The request
|
|
8
|
+
* builder therefore always sends `stream: true`, and there is no
|
|
9
|
+
* non-streaming code path to keep in sync.
|
|
10
|
+
* 2. **A leading system message is mandatory on the international backend.**
|
|
11
|
+
* A request whose first message is a user turn answers 400 `code 11128`
|
|
12
|
+
* ("first message is not system prompt"). {@link buildChatRequest} injects
|
|
13
|
+
* one when the caller supplied none, so a hand-built one-shot request cannot
|
|
14
|
+
* trip this. Note that the same code is also the gateway's channel-verification
|
|
15
|
+
* refusal (`msg: "conversation id missing"`), which the conversation header
|
|
16
|
+
* group this route sends is what satisfies — see `conversationHeaders` in
|
|
17
|
+
* `client.ts`. A history that is already correct can still answer 11128 for
|
|
18
|
+
* that second reason, so the code alone does not implicate the messages.
|
|
19
|
+
* 3. **Reasoning rides `delta.reasoning_content`,** not OpenAI's
|
|
20
|
+
* `reasoning_summary`, and is emitted as its own DSH reasoning block.
|
|
21
|
+
*/
|
|
22
|
+
import { type OutboundContentBlock, type GenerateOptions, type StreamChunk } from '../common/llm-compat.ts';
|
|
23
|
+
import { MAX_REQUEST_IMAGE_BYTES, NO_RESOLVED_IMAGES, SUPPORTED_IMAGE_MEDIA_TYPES, attachmentLabel, imageBlockToInline, offloadOldestRequestImages, requestImageTargetOrOriginal, resolveRequestImages, unavailableImageText, type AttachmentImageReader, type ResolvedRequestImage, type ResolvedRequestImages } from '../common/request-images.ts';
|
|
24
|
+
import { stripMetaSchema } from '../common/tool-schema.ts';
|
|
25
|
+
export declare function sanitizeText(text: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* The system prompt every request must open with.
|
|
28
|
+
*
|
|
29
|
+
* The international backend rejects a request whose first message is not a
|
|
30
|
+
* system turn, so this stands in when the caller supplies no prompt at all. It
|
|
31
|
+
* is deliberately neutral: it must not change model behaviour beyond satisfying
|
|
32
|
+
* the shape check.
|
|
33
|
+
*/
|
|
34
|
+
declare const IMPLICIT_SYSTEM_PROMPT = "You are a helpful assistant.";
|
|
35
|
+
/**
|
|
36
|
+
* The image seam is the SHARED kernel's, not this route's own.
|
|
37
|
+
*
|
|
38
|
+
* The old copy here carried a private 12 MB budget while the shared kernel
|
|
39
|
+
* bounds a request at {@link MAX_REQUEST_IMAGE_BYTES} (1.5 MB), and the adapter
|
|
40
|
+
* answered no `imageRequestTarget` at all — so the harness downscaled for a
|
|
41
|
+
* ceiling this mapper never applied, and the body could still exceed the one
|
|
42
|
+
* the kernel had already paid for. Re-exporting the kernel here keeps the
|
|
43
|
+
* projection, the budget and the target a single number.
|
|
44
|
+
*
|
|
45
|
+
* What stays route-specific is only what the WIRE shape needs ({@link
|
|
46
|
+
* MAX_REQUEST_IMAGE_BYTES} is imported for the doc link and the tests that pin
|
|
47
|
+
* it): the chat and Messages builders both consume the same resolution.
|
|
48
|
+
*/
|
|
49
|
+
export { MAX_REQUEST_IMAGE_BYTES, NO_RESOLVED_IMAGES, SUPPORTED_IMAGE_MEDIA_TYPES, attachmentLabel, imageBlockToInline, offloadOldestRequestImages, requestImageTargetOrOriginal, resolveRequestImages, unavailableImageText, stripMetaSchema, };
|
|
50
|
+
export type { AttachmentImageReader, ResolvedRequestImage, ResolvedRequestImages };
|
|
51
|
+
/**
|
|
52
|
+
* Build one `/v2/chat/completions` body.
|
|
53
|
+
*
|
|
54
|
+
* Always `stream: true`: the endpoint rejects a non-streaming request outright
|
|
55
|
+
* (400 `code 11101`), so there is no second shape to produce.
|
|
56
|
+
*/
|
|
57
|
+
export declare function buildChatRequest(options: GenerateOptions, images?: ResolvedRequestImages): Record<string, unknown>;
|
|
58
|
+
interface PendingToolCall {
|
|
59
|
+
blockIndex: number;
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
arguments: string;
|
|
63
|
+
started: boolean;
|
|
64
|
+
}
|
|
65
|
+
export interface WorkBuddyStreamState {
|
|
66
|
+
blocks: OutboundContentBlock[];
|
|
67
|
+
current: {
|
|
68
|
+
index: number;
|
|
69
|
+
type: 'text' | 'reasoning';
|
|
70
|
+
text: string;
|
|
71
|
+
} | null;
|
|
72
|
+
/** wire tool index -> accumulating call. */
|
|
73
|
+
toolCalls: Map<number, PendingToolCall>;
|
|
74
|
+
hasContent: boolean;
|
|
75
|
+
hasToolCall: boolean;
|
|
76
|
+
finishReason: string | null;
|
|
77
|
+
/** The `[DONE]` sentinel arrived. */
|
|
78
|
+
done: boolean;
|
|
79
|
+
/** Terminal chunks were already emitted. */
|
|
80
|
+
finished: boolean;
|
|
81
|
+
inputTokens: number;
|
|
82
|
+
outputTokens: number;
|
|
83
|
+
cacheReadTokens: number;
|
|
84
|
+
cacheWriteTokens: number;
|
|
85
|
+
reasoningTokens: number;
|
|
86
|
+
sawUsage: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Text held back while it may still turn into a printed tool call.
|
|
89
|
+
*
|
|
90
|
+
* `holding` is set once a `<` that could open a call region was seen; the
|
|
91
|
+
* buffer then grows until the region closes (or the cap is hit), and is
|
|
92
|
+
* resolved into prose or calls exactly once.
|
|
93
|
+
*/
|
|
94
|
+
printed: {
|
|
95
|
+
pending: string;
|
|
96
|
+
holding: boolean;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export declare function createStreamState(): WorkBuddyStreamState;
|
|
100
|
+
/** Feed one SSE line from `/v2/chat/completions`. */
|
|
101
|
+
export declare function processStreamLine(line: string, state: WorkBuddyStreamState): StreamChunk[];
|
|
102
|
+
/** Flush every open block, then emit usage and the terminal finish. */
|
|
103
|
+
export declare function closeStream(state: WorkBuddyStreamState): StreamChunk[];
|
|
104
|
+
/**
|
|
105
|
+
* A stream that ends without a terminal event is truncated, not complete.
|
|
106
|
+
*
|
|
107
|
+
* The endpoint always terminates with either `finish_reason` or `[DONE]`, so
|
|
108
|
+
* their absence means the connection dropped mid-answer and the partial text
|
|
109
|
+
* must not be presented as a finished reply.
|
|
110
|
+
*/
|
|
111
|
+
export declare function assertStreamComplete(state: WorkBuddyStreamState): void;
|
|
112
|
+
/** Whether one 11128 body is the channel refusal a system move can repair. */
|
|
113
|
+
export declare function isChannelRefusal11128(detail: string): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* What a chat's system prompt is known by.
|
|
116
|
+
*
|
|
117
|
+
* The key is the system TEXT, not the conversation: one agent refused once must
|
|
118
|
+
* not pay the refusal again on its next conversation, which is a different
|
|
119
|
+
* message list with the same opening. A body whose system text is already the
|
|
120
|
+
* neutral default has nothing to move, so it keys as the empty string.
|
|
121
|
+
*/
|
|
122
|
+
export declare function chatSystemKey(body: unknown): string;
|
|
123
|
+
/**
|
|
124
|
+
* Move a chat's system prompt into the first user turn, in INSTRUCTIONS tags,
|
|
125
|
+
* and leave the neutral default in the leading system position.
|
|
126
|
+
*
|
|
127
|
+
* A system message LATER in the history becomes a user message where it stands:
|
|
128
|
+
* the gateway refuses those too, and the position is meaningful to the model, so
|
|
129
|
+
* it is rewritten rather than lifted out and merged. String content is prefixed
|
|
130
|
+
* with the tagged text and a blank line; block content gets one extra leading
|
|
131
|
+
* text part, which is what keeps images and tool parts exactly where they were.
|
|
132
|
+
*
|
|
133
|
+
* Returns the new body as JSON, or NULL when there is nothing to move — a caller
|
|
134
|
+
* that gets null must not retry, because the second request would be the first
|
|
135
|
+
* one again.
|
|
136
|
+
*/
|
|
137
|
+
export declare function relocateSystemToInstructions(body: unknown): string | null;
|
|
138
|
+
/**
|
|
139
|
+
* The id one USER SEND is known by, for the request-id header family.
|
|
140
|
+
*
|
|
141
|
+
* Derived from the harness history rather than from a clock or a counter: every
|
|
142
|
+
* tool step of one send appends to the history AFTER the user's own last
|
|
143
|
+
* message, so the same key is computed for all of them, and the user's next
|
|
144
|
+
* message is what changes it. Tool-result turns are skipped because they are the
|
|
145
|
+
* harness answering the model, not the user speaking — including them would give
|
|
146
|
+
* each tool step its own id, which is the behaviour this exists to prevent.
|
|
147
|
+
*
|
|
148
|
+
* Empty when there is no user turn to name, which the caller reads as "make a
|
|
149
|
+
* fresh id for this request" (config probes, compactions, and one-shot calls).
|
|
150
|
+
*/
|
|
151
|
+
export declare function userTurnKey(options: GenerateOptions): string;
|
|
152
|
+
/**
|
|
153
|
+
* `anthropic-version` the Messages surface requires.
|
|
154
|
+
*
|
|
155
|
+
* Sent for every Messages request: without it the endpoint answers 400 rather
|
|
156
|
+
* than falling back to a default, so it is a protocol requirement and not a
|
|
157
|
+
* feature negotiation.
|
|
158
|
+
*/
|
|
159
|
+
export declare const ANTHROPIC_VERSION = "2023-06-01";
|
|
160
|
+
/**
|
|
161
|
+
* Thinking control the Messages surface takes.
|
|
162
|
+
*
|
|
163
|
+
* Not the chat endpoint's `reasoning_effort`: Messages asks for thinking
|
|
164
|
+
* (`thinking.type: 'adaptive'`) and expresses the LEVEL in
|
|
165
|
+
* `output_config.effort`. Sending the chat spelling here is what made an
|
|
166
|
+
* effort pick do nothing, and 'max' is a legal level of this ladder, so it is
|
|
167
|
+
* carried verbatim rather than filtered through the chat ladder.
|
|
168
|
+
*/
|
|
169
|
+
export declare const MESSAGES_THINKING_FIELD = "thinking";
|
|
170
|
+
export declare const MESSAGES_EFFORT_FIELD = "output_config";
|
|
171
|
+
export interface MessagesRequestOptions {
|
|
172
|
+
/** Durable user images resolved for this request. */
|
|
173
|
+
images?: ResolvedRequestImages;
|
|
174
|
+
/** Effort ladder the gateway catalog declares for this model; empty = no thinking. */
|
|
175
|
+
efforts?: readonly string[];
|
|
176
|
+
/** Effort the caller picked, carried verbatim (no chat-ladder filtering). */
|
|
177
|
+
effort?: string;
|
|
178
|
+
/** Output cap to use when the caller names none. */
|
|
179
|
+
defaultMaxTokens?: number;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Build one `/v1/messages` body.
|
|
183
|
+
*
|
|
184
|
+
* `stream: true` is mandatory: the adapter reads every response as SSE, and a
|
|
185
|
+
* non-streaming answer is one JSON document with no `data:` lines, no
|
|
186
|
+
* `message_stop` and no `stop_reason`.
|
|
187
|
+
*
|
|
188
|
+
* The system prompt travels as the top-level `system` string — the surface has
|
|
189
|
+
* a field for it, so the chat endpoint's "the first message must be a system
|
|
190
|
+
* turn" requirement does not exist here and no relocation is ever needed.
|
|
191
|
+
*/
|
|
192
|
+
export declare function buildMessagesRequest(options: GenerateOptions, request?: MessagesRequestOptions): Record<string, unknown>;
|
|
193
|
+
interface MessagesTextBlock {
|
|
194
|
+
index: number;
|
|
195
|
+
kind: 'text' | 'reasoning';
|
|
196
|
+
text: string;
|
|
197
|
+
}
|
|
198
|
+
interface MessagesToolCall {
|
|
199
|
+
index: number;
|
|
200
|
+
id: string;
|
|
201
|
+
name: string;
|
|
202
|
+
arguments: string;
|
|
203
|
+
}
|
|
204
|
+
export interface MessagesStreamState {
|
|
205
|
+
blocks: OutboundContentBlock[];
|
|
206
|
+
/** wire content index -> open text or reasoning block. */
|
|
207
|
+
open: Map<number, MessagesTextBlock>;
|
|
208
|
+
/** wire content index -> accumulating tool call. */
|
|
209
|
+
toolCalls: Map<number, MessagesToolCall>;
|
|
210
|
+
hasContent: boolean;
|
|
211
|
+
hasToolCall: boolean;
|
|
212
|
+
finishReason: string | null;
|
|
213
|
+
sawMessageStart: boolean;
|
|
214
|
+
sawMessageStop: boolean;
|
|
215
|
+
sawUsage: boolean;
|
|
216
|
+
inputTokens: number;
|
|
217
|
+
outputTokens: number;
|
|
218
|
+
cacheReadTokens: number;
|
|
219
|
+
cacheWriteTokens: number;
|
|
220
|
+
reasoningTokens: number;
|
|
221
|
+
finished: boolean;
|
|
222
|
+
}
|
|
223
|
+
export declare function createMessagesStreamState(): MessagesStreamState;
|
|
224
|
+
/** Flush every open block, then emit usage and the terminal finish. */
|
|
225
|
+
export declare function closeMessagesStream(state: MessagesStreamState): StreamChunk[];
|
|
226
|
+
/** A stream that ends without `message_stop` is truncated, not complete. */
|
|
227
|
+
export declare function assertMessagesStreamComplete(state: MessagesStreamState): void;
|
|
228
|
+
/**
|
|
229
|
+
* Feed one SSE line from `/v1/messages`.
|
|
230
|
+
*
|
|
231
|
+
* Both fragments of one event arrive as two lines (`event:` then `data:`), so
|
|
232
|
+
* the parser keys on `data:` alone and ignores the event name: the JSON payload
|
|
233
|
+
* carries its own `type`, which is the same discriminator and cannot disagree
|
|
234
|
+
* with the label above it.
|
|
235
|
+
*/
|
|
236
|
+
export declare function processMessagesStreamLine(line: string, state: MessagesStreamState): StreamChunk[];
|
|
237
|
+
export { IMPLICIT_SYSTEM_PROMPT };
|
|
238
|
+
//# sourceMappingURL=mapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapper.d.ts","sourceRoot":"","sources":["../../../../src/host/workbuddy/mapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAGL,KAAK,oBAAoB,EAEzB,KAAK,eAAe,EAEpB,KAAK,WAAW,EAEjB,MAAM,yBAAyB,CAAA;AAEhC,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,2BAA2B,EAC3B,eAAe,EACf,kBAAkB,EAClB,0BAA0B,EAC1B,4BAA4B,EAC5B,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC3B,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AA+D1D,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAiBjD;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,sBAAsB,iCAAiC,CAAA;AAM7D;;;;;;;;;;;;;GAaG;AACH,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,2BAA2B,EAC3B,eAAe,EACf,kBAAkB,EAClB,0BAA0B,EAC1B,4BAA4B,EAC5B,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,GAChB,CAAA;AACD,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,CAAA;AAoRlF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,eAAe,EACxB,MAAM,GAAE,qBAA0C,GACjD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA0EzB;AAMD,UAAU,eAAe;IACvB,UAAU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IAClC,MAAM,EAAE,oBAAoB,EAAE,CAAA;IAC9B,0DAA0D;IAC1D,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAA;IACpC,oDAAoD;IACpD,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;IACxC,UAAU,EAAE,OAAO,CAAA;IACnB,WAAW,EAAE,OAAO,CAAA;IACpB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,eAAe,EAAE,OAAO,CAAA;IACxB,cAAc,EAAE,OAAO,CAAA;IACvB,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,eAAe,EAAE,MAAM,CAAA;IACvB,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,yBAAyB,IAAI,mBAAmB,CAkB/D;AA2FD,uEAAuE;AACvE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,mBAAmB,GAAG,WAAW,EAAE,CAO7E;AAED,4EAA4E;AAC5E,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI,CAI7E;AAkBD;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,GAAG,WAAW,EAAE,CAiHjG;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAA"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model catalog for the WorkBuddy / CodeBuddy subscription.
|
|
3
|
+
*
|
|
4
|
+
* The subscription exposes no `/v1/models`-style listing on the chat host
|
|
5
|
+
* (that path answers 404), but the gateway does publish an **authoritative
|
|
6
|
+
* catalog** at `GET /v3/config`, which the official CLI reads at startup. That
|
|
7
|
+
* payload carries each model's real context window, output cap, image support,
|
|
8
|
+
* and the exact reasoning ladder it accepts — so this route prefers the live
|
|
9
|
+
* catalog and keeps the table below only as an offline fallback.
|
|
10
|
+
*
|
|
11
|
+
* The fallback is a verbatim transcription of a live `/v3/config` read, not
|
|
12
|
+
* hand-written guesses: an earlier revision of this file guessed context
|
|
13
|
+
* windows from vendor marketing and was wrong in both directions (`glm-5.3`
|
|
14
|
+
* and `kimi-k3` are 1M, not 200K/256K).
|
|
15
|
+
*
|
|
16
|
+
* One entry serves both regions, so a model the regions disagree about needs a
|
|
17
|
+
* merged figure. The rule is asymmetric on purpose: the **larger maximum** is
|
|
18
|
+
* kept, while the **served default** and the **output cap** take the **smaller**
|
|
19
|
+
* of the two. Over-declaring either one is a hard failure — DSH would send a
|
|
20
|
+
* request the gateway rejects — whereas under-declaring only compresses a
|
|
21
|
+
* conversation earlier than needed, and both remain overridable per model from
|
|
22
|
+
* the settings card. Measured disagreements (`glm-5.3-flash`, `glm-5.3`,
|
|
23
|
+
* `glm-5.2`, `kimi-k2.8-preview` served 300000/48000/48000/32000 by intl
|
|
24
|
+
* against 1000000/64000/64000/64000 by cn) are reconciled that way.
|
|
25
|
+
*
|
|
26
|
+
* The regions also do not serve the same ids. intl added `glm-5.3-flash` and
|
|
27
|
+
* keeps `gemini-3.5-flash`, `kimi-k3` and the `*-model` aliases to itself; cn
|
|
28
|
+
* keeps `glm-5.3-flash`, `kimi-k3-1` and its own `-x` variants.
|
|
29
|
+
*
|
|
30
|
+
* `regions` is a routing fact, not a preference: asking a region for a model it
|
|
31
|
+
* does not serve answers 400 `code 11102`.
|
|
32
|
+
*
|
|
33
|
+
* A second `code 11102` source was measured and is deliberately NOT filtered
|
|
34
|
+
* out here: the gateway lists models the *current account* is not entitled to
|
|
35
|
+
* call (on a free plan, `glm-5.0`, `glm-4.7`, `glm-4.6`, `glm-4.6v`,
|
|
36
|
+
* `kimi-k2-thinking`, `hy4-preview-x` and `minimax-m2.5` all advertise a context
|
|
37
|
+
* window and then answer 11102). Those entries are kept because the gating is
|
|
38
|
+
* per-account, not per-model — a paid plan may serve them — and because the
|
|
39
|
+
* shipped default selection excludes them anyway. The adapter's failure message
|
|
40
|
+
* names this case so a user knows to pick another model rather than to retry.
|
|
41
|
+
*
|
|
42
|
+
* `credits` is the consumption multiplier the same payload publishes as a
|
|
43
|
+
* string (`x0.79 credits` on cn, `x6.67` on intl), stored here in the bare
|
|
44
|
+
* numeric form the settings card renders. It is kept per region because the two
|
|
45
|
+
* backends do not always agree — measured 2026-10-09, `deepseek-v4.1-flash`
|
|
46
|
+
* is `0.11` on cn against `0.00` on intl — and a key is written only for a
|
|
47
|
+
* region that actually published one (every `gpt-5.x` and `gpt-6-astra` is
|
|
48
|
+
* intl-only, the `minimax` and `glm-5.0`/`glm-4.x` rows carry no intl key).
|
|
49
|
+
* An empty string (`default-model`) means no rate was declared at all, so that
|
|
50
|
+
* row has no `credits` field rather than a zeroed one: a guessed rate on a
|
|
51
|
+
* spend figure is worse than a missing one.
|
|
52
|
+
*
|
|
53
|
+
* `reasoningEfforts` carries the ladder a model accepts, transcribed from the
|
|
54
|
+
* gateway's own declaration. `/v3/config` uses two shapes and they were once
|
|
55
|
+
* conflated, in opposite directions: a lone `{ effort: 'high' }` (no
|
|
56
|
+
* `supportedEfforts`) first became a one-entry ladder, which rejected a
|
|
57
|
+
* caller's explicit `low`; widening it to every level this route can name then
|
|
58
|
+
* advertised `minimal`/`xhigh` on a model that has three. Such a model accepts
|
|
59
|
+
* exactly `low`/`high`/`max` (measured on `deepseek-v4.1-flash`), the same
|
|
60
|
+
* three the gateway declares explicitly for `glm-5.3-flash` and
|
|
61
|
+
* `kimi-k2.8-preview`, and routes any other value into the nearest of them.
|
|
62
|
+
*/
|
|
63
|
+
import type { WorkBuddyModelCredits, WorkBuddyRegion } from '../../shared/workbuddy-contracts.ts';
|
|
64
|
+
export interface WorkBuddyModelEntry {
|
|
65
|
+
id: string;
|
|
66
|
+
name: string;
|
|
67
|
+
/**
|
|
68
|
+
* Context length the gateway serves **by default** for this model.
|
|
69
|
+
*
|
|
70
|
+
* This route sends no explicit context-length parameter, so this is the
|
|
71
|
+
* figure DSH's compaction and overflow decisions must use. It is not always
|
|
72
|
+
* the model's maximum: the gateway reports both (for example
|
|
73
|
+
* `deepseek-v4.1-flash` serves 300000 by default and allows 1000000).
|
|
74
|
+
*/
|
|
75
|
+
contextWindow: number;
|
|
76
|
+
/** Largest context length the model accepts when one is requested. */
|
|
77
|
+
maxContextWindow: number;
|
|
78
|
+
/** Output cap requested when the caller omits one. */
|
|
79
|
+
maxTokens: number;
|
|
80
|
+
/** Regions whose backend serves this id. */
|
|
81
|
+
regions: readonly WorkBuddyRegion[];
|
|
82
|
+
/**
|
|
83
|
+
* Consumption multiplier per region, as `/v3/config` publishes it.
|
|
84
|
+
*
|
|
85
|
+
* Optional on purpose: the multiplier is the one field the gateway may omit
|
|
86
|
+
* for a model it otherwise describes (`default-model` ships an empty string),
|
|
87
|
+
* so every catalog literal in this repo — test fixtures and the live parser
|
|
88
|
+
* alike — must stay valid without it. Absent therefore means "nothing usable
|
|
89
|
+
* was published", never "zero": `x0.00` is a real declaration and is kept.
|
|
90
|
+
*/
|
|
91
|
+
credits?: WorkBuddyModelCredits;
|
|
92
|
+
/** Whether the model accepts image input. */
|
|
93
|
+
supportsImage: boolean;
|
|
94
|
+
/** Reasoning ladder the model accepts; empty for a non-reasoning model. */
|
|
95
|
+
reasoningEfforts: readonly string[];
|
|
96
|
+
/** Level this route selects when the caller names none. */
|
|
97
|
+
defaultReasoningEffort: string | null;
|
|
98
|
+
/** Whether the model can be asked to skip thinking entirely. */
|
|
99
|
+
canDisableThinking: boolean;
|
|
100
|
+
/** One-line note shown beside the model in the settings card. */
|
|
101
|
+
description: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Models the gateway serves but does not publish in `/v3/config`.
|
|
105
|
+
*
|
|
106
|
+
* The catalog is a published list, not the served one: measured on the
|
|
107
|
+
* international backend, `gpt-6-sol`, `gpt-6-luna` and `gemini-3.8-flash` all
|
|
108
|
+
* answer a normal streaming completion with 200 while being absent from
|
|
109
|
+
* `/v3/config` entirely, and a reachable gateway *replaces* the shipped table
|
|
110
|
+
* with that list. Without these rows the picker would simply never show them, so
|
|
111
|
+
* they are declared here and merged into a live catalog too
|
|
112
|
+
* ({@link withUnpublishedModels}) rather than living in the fallback alone.
|
|
113
|
+
*
|
|
114
|
+
* What each row records, and how it was established, differs by field:
|
|
115
|
+
*
|
|
116
|
+
* - **Existence, the reasoning ladder, image support** were measured against the
|
|
117
|
+
* live endpoint, not inferred from the name. A rejected level answers 400
|
|
118
|
+
* `code 11133` with `extError` `400002`; `gpt-6-sol` takes exactly the ladder
|
|
119
|
+
* `gpt-6-astra` publishes (`minimal` refused, `low`/`medium`/`high`/`xhigh`/
|
|
120
|
+
* `max` accepted) and both accept a 1x1 PNG.
|
|
121
|
+
* - **Context window, output cap and `canDisableThinking` are inherited from the
|
|
122
|
+
* published sibling in the same family** — `gpt-6-astra` for `gpt-6-sol` and
|
|
123
|
+
* `gpt-6-luna`, `gemini-3.5-flash` for `gemini-3.8-flash`. They are marked
|
|
124
|
+
* here rather than measured because the gateway publishes nothing for these
|
|
125
|
+
* ids and offers no cheap way to read the real figure: it accepts a
|
|
126
|
+
* `max_tokens` larger than any published window (even for `gpt-6-astra`, whose
|
|
127
|
+
* own catalog caps at 128000), so the number is neither enforced nor
|
|
128
|
+
* discoverable from the request side.
|
|
129
|
+
*
|
|
130
|
+
* Every field stays overridable per model from the settings card, and an
|
|
131
|
+
* inherited window errs low rather than high: over-declaring overflows the
|
|
132
|
+
* gateway mid-session, while under-declaring only compresses earlier.
|
|
133
|
+
*/
|
|
134
|
+
export declare const UNPUBLISHED_MODELS: readonly WorkBuddyModelEntry[];
|
|
135
|
+
/**
|
|
136
|
+
* Offline fallback catalog, transcribed from a live `/v3/config` read.
|
|
137
|
+
*
|
|
138
|
+
* Used when the gateway cannot be reached (first run before sign-in, or a
|
|
139
|
+
* network failure); a reachable gateway always wins.
|
|
140
|
+
*/
|
|
141
|
+
export declare const FALLBACK_MODELS: readonly WorkBuddyModelEntry[];
|
|
142
|
+
/**
|
|
143
|
+
* Models the picker offers on a fresh install.
|
|
144
|
+
*
|
|
145
|
+
* Deliberately short: the catalog holds every id the subscription serves, and
|
|
146
|
+
* the picker is far more usable with the handful of general-purpose models. The
|
|
147
|
+
* card lets a user add the rest, and a first-run default expands to everything
|
|
148
|
+
* the account's region can actually call.
|
|
149
|
+
*/
|
|
150
|
+
export declare const DEFAULT_VISIBLE_MODEL_IDS: readonly string[];
|
|
151
|
+
/** Every id the fallback knows, in declaration order. */
|
|
152
|
+
export declare const WORKBUDDY_MODEL_IDS: readonly string[];
|
|
153
|
+
/**
|
|
154
|
+
* Add the served-but-unpublished models to a live `/v3/config` catalog.
|
|
155
|
+
*
|
|
156
|
+
* A reachable gateway replaces the shipped table with the list it publishes, so
|
|
157
|
+
* a model it serves without listing ({@link UNPUBLISHED_MODELS}) would drop out
|
|
158
|
+
* of the picker the moment the catalog loads. Merging here keeps it offered.
|
|
159
|
+
*
|
|
160
|
+
* A published entry always wins: the gateway is the authority on anything it
|
|
161
|
+
* does describe, so these rows only fill ids the payload is silent about.
|
|
162
|
+
*/
|
|
163
|
+
export declare function withUnpublishedModels(catalog: readonly WorkBuddyModelEntry[], region: WorkBuddyRegion): WorkBuddyModelEntry[];
|
|
164
|
+
/**
|
|
165
|
+
* Resolve one entry from a catalog.
|
|
166
|
+
*
|
|
167
|
+
* An unknown id resolves to a synthetic text-only entry rather than the first
|
|
168
|
+
* catalog row: reporting a real model's capabilities for an id it does not
|
|
169
|
+
* describe would mis-declare image support and route a request to a 400.
|
|
170
|
+
*/
|
|
171
|
+
export declare function resolveWorkBuddyModel(id: string, catalog?: readonly WorkBuddyModelEntry[]): WorkBuddyModelEntry;
|
|
172
|
+
/** Whether one catalog knows this exact id. */
|
|
173
|
+
export declare function isWorkBuddyModelId(id: unknown, catalog?: readonly WorkBuddyModelEntry[]): id is string;
|
|
174
|
+
/** The vendor family one model belongs to. */
|
|
175
|
+
export declare function workBuddyModelVendor(id: string): string;
|
|
176
|
+
/**
|
|
177
|
+
* Group a list so every vendor's models sit together.
|
|
178
|
+
*
|
|
179
|
+
* Families appear in the order their first model does — the catalog decides
|
|
180
|
+
* which vendor leads, not this function — and each family is ordered newest
|
|
181
|
+
* generation first.
|
|
182
|
+
*/
|
|
183
|
+
export declare function groupWorkBuddyModelsByVendor<T extends {
|
|
184
|
+
id: string;
|
|
185
|
+
}>(models: readonly T[]): T[];
|
|
186
|
+
/**
|
|
187
|
+
* Models an account in `region` can actually call, grouped by vendor.
|
|
188
|
+
*
|
|
189
|
+
* Grouped here rather than in the settings card because this is also what the
|
|
190
|
+
* request path resolves against: one ordering rule, so the picker and the
|
|
191
|
+
* adapter can never disagree about which models a region offers.
|
|
192
|
+
*/
|
|
193
|
+
export declare function modelsForRegion(region: WorkBuddyRegion, catalog?: readonly WorkBuddyModelEntry[]): WorkBuddyModelEntry[];
|
|
194
|
+
/** Whether one model accepts image input. */
|
|
195
|
+
export declare function workBuddyModelSupportsImage(id: string, catalog?: readonly WorkBuddyModelEntry[]): boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Reasoning ladder one model accepts, plus `none` when its trace can be turned off.
|
|
198
|
+
*
|
|
199
|
+
* The ladder in the catalog is what the model ACCEPTS, so `none` never appears
|
|
200
|
+
* in it; `canDisableThinking` is the separate statement that switching thinking
|
|
201
|
+
* off is allowed, and this is the single place that turns it into the one level
|
|
202
|
+
* the picker can offer. Callers that need the ladder alone read the entry.
|
|
203
|
+
*/
|
|
204
|
+
export declare function workBuddyReasoningEfforts(id: string, catalog?: readonly WorkBuddyModelEntry[]): readonly string[];
|
|
205
|
+
/**
|
|
206
|
+
* Consumption multiplier per region one model publishes.
|
|
207
|
+
*
|
|
208
|
+
* Read through {@link resolveWorkBuddyModel} like the other accessors, so an id
|
|
209
|
+
* no catalog describes reports `{}` — "no rate published" rather than a rate
|
|
210
|
+
* of zero.
|
|
211
|
+
*/
|
|
212
|
+
export declare function workBuddyModelCredits(id: string, catalog?: readonly WorkBuddyModelEntry[]): WorkBuddyModelCredits;
|
|
213
|
+
/** Output cap requested when the caller omits one. */
|
|
214
|
+
export declare function maxOutputTokensFor(id: string, catalog?: readonly WorkBuddyModelEntry[]): number;
|
|
215
|
+
/** Context window assumed when no override is saved. */
|
|
216
|
+
export declare function defaultContextWindowFor(id: string, catalog?: readonly WorkBuddyModelEntry[]): number;
|
|
217
|
+
//# sourceMappingURL=model-catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-catalog.d.ts","sourceRoot":"","sources":["../../../../src/host/workbuddy/model-catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAA;AAIjG,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ;;;;;;;OAOG;IACH,aAAa,EAAE,MAAM,CAAA;IACrB,sEAAsE;IACtE,gBAAgB,EAAE,MAAM,CAAA;IACxB,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAA;IACjB,4CAA4C;IAC5C,OAAO,EAAE,SAAS,eAAe,EAAE,CAAA;IACnC;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,qBAAqB,CAAA;IAC/B,6CAA6C;IAC7C,aAAa,EAAE,OAAO,CAAA;IACtB,2EAA2E;IAC3E,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAA;IACnC,2DAA2D;IAC3D,sBAAsB,EAAE,MAAM,GAAG,IAAI,CAAA;IACrC,gEAAgE;IAChE,kBAAkB,EAAE,OAAO,CAAA;IAC3B,iEAAiE;IACjE,WAAW,EAAE,MAAM,CAAA;CACpB;AA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AyB,CACvC,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,SAAS,mBAAmB,EAAoB,GACxD,SAAS,MAAM,EAAE,CAInB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,SAAS,mBAAmB,EAAoB,GACxD,qBAAqB,CAEvB;AAED,sDAAsD;AACtD,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,SAAS,mBAAmB,EAAoB,GACxD,MAAM,CAER;AAED,wDAAwD;AACxD,wBAAgB,uBAAuB,CACrC,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,SAAS,mBAAmB,EAAoB,GACxD,MAAM,CAER"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { FileCredentialStore, type WorkBuddyCredentials } from './token-store.ts';
|
|
2
|
+
import { type WorkBuddyTokenIdentity } from './identity.ts';
|
|
3
|
+
import type { WorkBuddyRegion } from '../../shared/workbuddy-contracts.ts';
|
|
4
|
+
export type WorkBuddyLoginStatus = 'idle' | 'pending' | 'complete' | 'error';
|
|
5
|
+
export interface WorkBuddyLoginFlowState {
|
|
6
|
+
status: WorkBuddyLoginStatus;
|
|
7
|
+
region?: WorkBuddyRegion;
|
|
8
|
+
authUrl?: string;
|
|
9
|
+
progress?: string;
|
|
10
|
+
accountId?: string;
|
|
11
|
+
startedAt?: number;
|
|
12
|
+
completedAt?: number;
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function getWebLoginStatus(): WorkBuddyLoginFlowState;
|
|
16
|
+
export declare function resetWebLogin(): void;
|
|
17
|
+
export interface WorkBuddyLoginAttempt {
|
|
18
|
+
state: string;
|
|
19
|
+
authUrl: string;
|
|
20
|
+
region: WorkBuddyRegion;
|
|
21
|
+
domain: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function requestLoginState(region: WorkBuddyRegion, fetchFn?: typeof fetch, signal?: AbortSignal): Promise<WorkBuddyLoginAttempt>;
|
|
24
|
+
/** Parse the successful token-poll shape while accepting the two observed wrappers. */
|
|
25
|
+
export declare function parseLoginCredential(payload: unknown, attempt: WorkBuddyLoginAttempt): WorkBuddyCredentials | null;
|
|
26
|
+
export declare function pollLogin(attempt: WorkBuddyLoginAttempt, fetchFn?: typeof fetch, signal?: AbortSignal): Promise<WorkBuddyCredentials | null>;
|
|
27
|
+
/** Where a completed sign-in is written; the default is this line's own store. */
|
|
28
|
+
export interface WorkBuddyLoginOptions {
|
|
29
|
+
/**
|
|
30
|
+
* Persist the completed credential.
|
|
31
|
+
*
|
|
32
|
+
* The account pool owns routing, so it is what a completed sign-in must reach;
|
|
33
|
+
* the default writes to the credential store alone, which is what a caller
|
|
34
|
+
* running without a pool needs.
|
|
35
|
+
*/
|
|
36
|
+
onSave?: (credentials: WorkBuddyCredentials) => Promise<unknown>;
|
|
37
|
+
/**
|
|
38
|
+
* Resolve the signed-in account's identity before it is saved.
|
|
39
|
+
*
|
|
40
|
+
* The token response does not say which account it belongs to, so the default
|
|
41
|
+
* reads it from the account endpoint; a test can replace this, and a caller
|
|
42
|
+
* that already knows the identity can skip the extra request.
|
|
43
|
+
*/
|
|
44
|
+
resolveIdentity?: (credentials: WorkBuddyCredentials) => Promise<WorkBuddyTokenIdentity | null>;
|
|
45
|
+
}
|
|
46
|
+
export declare function beginWebLogin(store: FileCredentialStore, region: WorkBuddyRegion, fetchFn?: typeof fetch, options?: WorkBuddyLoginOptions): Promise<WorkBuddyLoginFlowState>;
|
|
47
|
+
//# sourceMappingURL=oauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../../src/host/workbuddy/oauth.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,mBAAmB,EAAsB,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACrG,OAAO,EAAwB,KAAK,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAEjF,O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AAC,OAAO,CAAC,CAAA;IAChE;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,CAAC,WAAW,EAAE,oBAAoB,KAAK,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAA;CAChG;AA8BD,wBAAsB,aAAa,CACjC,KAAK,EAAE,mBAAmB,EAC1B,MAAM,EAAE,eAAe,EACvB,OAAO,GAAE,OAAO,KAAa,EAC7B,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,uBAAuB,CAAC,CAuClC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outbound client identities this route can present.
|
|
3
|
+
*
|
|
4
|
+
* The subscription gateway gates on client identity, and it gates DIFFERENTLY
|
|
5
|
+
* per surface: measured on this route, `CodeBuddyIDE` is rejected by
|
|
6
|
+
* `/v3/config` with 400 `code 12403` ("check ua") and 401'd outright by the
|
|
7
|
+
* international chat endpoint, which is why the CLI identity is what the line
|
|
8
|
+
* ships and has always used.
|
|
9
|
+
*
|
|
10
|
+
* Two more identities exist on the same backend. Both were captured by sibling
|
|
11
|
+
* gateways that reverse-engineered the real clients' requests; this file's
|
|
12
|
+
* version block below names the exact source of every string it sends.
|
|
13
|
+
*
|
|
14
|
+
* desktop `WorkBuddy/<app> <appName>/<app> CLI/<cli>`, where `<app>` is
|
|
15
|
+
* the desktop build, `<appName>` is `WorkBuddy` (domestic) or
|
|
16
|
+
* `workbuddy-ai` (international) and `<cli>` is the CLI bundled
|
|
17
|
+
* inside that build
|
|
18
|
+
* + `X-IDE-Type/Name: WorkBuddy`, `X-IDE-Version`, `X-Agent-Intent: craft`
|
|
19
|
+
* + `X-Agent-Purpose: conversation`, `X-Agent-Type: main`,
|
|
20
|
+
* + `X-Agent-Runtime: local-agent` (the 5.9 client names where the
|
|
21
|
+
* agent runs; the header is absent in 5.8), trace headers
|
|
22
|
+
* vscode `VSCode/<ide> WorkBuddy/<product>`
|
|
23
|
+
* + `X-IDE-Type/Name: VSCode`, `X-IDE-Version`, `X-Product-Version`, `X-Env-ID`
|
|
24
|
+
* cli `CLI/2.63.2 CodeBuddy/2.63.2` + no overrides
|
|
25
|
+
*
|
|
26
|
+
* The `cli` literal is kept byte-identical to what this line has always sent,
|
|
27
|
+
* but it is NO LONGER the default: upstream now refuses any agent that is not a
|
|
28
|
+
* `WorkBuddy/<version>` one with error 10085, which is exactly what a bare
|
|
29
|
+
* `CLI/...` agent is. `DEFAULT_OUTBOUND_SETTING` therefore names `workbuddy`,
|
|
30
|
+
* and {@link migrateOutboundSettingDocument} moves a stored pre-marker document
|
|
31
|
+
* across without overriding a choice the user has since made.
|
|
32
|
+
*
|
|
33
|
+
* Quota is NOT per identity: the subscription meters an account × model over a
|
|
34
|
+
* 24h window (429 `code 6004`), so switching identity cannot create allowance.
|
|
35
|
+
* What it can do is give each account a stable, plausible client — the same
|
|
36
|
+
* reason the gateway projects one device per account.
|
|
37
|
+
*/
|
|
38
|
+
import type { WorkBuddyOutboundProduct, WorkBuddyOutboundSetting } from '../../shared/workbuddy-contracts.ts';
|
|
39
|
+
export type { WorkBuddyOutboundProduct, WorkBuddyOutboundSetting };
|
|
40
|
+
/** Everything the settings card may offer, in display order. */
|
|
41
|
+
export declare const OUTBOUND_PRODUCTS: readonly WorkBuddyOutboundProduct[];
|
|
42
|
+
/**
|
|
43
|
+
* Shipped default: the desktop identity.
|
|
44
|
+
*
|
|
45
|
+
* It used to be `cli`, because that literal is what this line measured working
|
|
46
|
+
* first. That is no longer true — upstream refuses any agent that is not a
|
|
47
|
+
* `WorkBuddy/<version>` one with error 10085, and a bare `CLI/...` agent is
|
|
48
|
+
* exactly such a request (see the version block below, which cites the source
|
|
49
|
+
* of both facts). The desktop identity is the shipped one because it is the
|
|
50
|
+
* identity that presents a `WorkBuddy/<version>` agent.
|
|
51
|
+
*
|
|
52
|
+
* A document written while `cli` was the default is moved across ONCE by
|
|
53
|
+
* {@link migrateOutboundSettingDocument}; a choice made after that is never
|
|
54
|
+
* revisited.
|
|
55
|
+
*/
|
|
56
|
+
export declare const DEFAULT_OUTBOUND_SETTING: WorkBuddyOutboundProduct;
|
|
57
|
+
/** Narrow a stored or patched value into a supported preference. */
|
|
58
|
+
export declare function normalizeOutboundSetting(value: unknown): WorkBuddyOutboundSetting;
|
|
59
|
+
/**
|
|
60
|
+
* Which identity one account uses.
|
|
61
|
+
*
|
|
62
|
+
* `auto` assigns by hashing the account key, so an account keeps the same
|
|
63
|
+
* client for its whole life — the one property that matters for a device
|
|
64
|
+
* fingerprint — while a pool as a whole spreads over the available clients.
|
|
65
|
+
*/
|
|
66
|
+
export declare function resolveOutboundProduct(setting: WorkBuddyOutboundSetting, accountKey: string): WorkBuddyOutboundProduct;
|
|
67
|
+
/**
|
|
68
|
+
* A stable pseudo-device id for one account.
|
|
69
|
+
*
|
|
70
|
+
* Same derivation as the measured clients (`derive_id`: md5 of `salt:uid`
|
|
71
|
+
* reshaped into a UUID), so the value is a well-formed v4-shaped machine id
|
|
72
|
+
* that never changes for an account and never collides between accounts. A
|
|
73
|
+
* per-PROCESS id would be worse than none here: it would present every account
|
|
74
|
+
* in the pool as the same machine.
|
|
75
|
+
*/
|
|
76
|
+
export declare function deriveMachineId(uid: string): string;
|
|
77
|
+
/** Identity-specific headers and user agent for one request. */
|
|
78
|
+
export interface OutboundIdentity {
|
|
79
|
+
product: WorkBuddyOutboundProduct;
|
|
80
|
+
userAgent: string;
|
|
81
|
+
/** Extra or overriding headers; `conversation` supplies the ids already minted. */
|
|
82
|
+
headers(conversation: Readonly<Record<string, string>>): Record<string, string>;
|
|
83
|
+
}
|
|
84
|
+
/** Resolve the identity block for one product on one region. */
|
|
85
|
+
export declare function outboundIdentity(product: WorkBuddyOutboundProduct, region: 'cn' | 'intl', uid: string): OutboundIdentity;
|
|
86
|
+
/**
|
|
87
|
+
* Version of the outbound-identity semantics one settings document carries.
|
|
88
|
+
*
|
|
89
|
+
* 1 (never written as a number) = the era whose shipped default was `cli`. That
|
|
90
|
+
* era wrote `cli` into a document as soon as it normalised an unset
|
|
91
|
+
* preference, so a stored `cli` from it cannot be told apart from "untouched".
|
|
92
|
+
* 2 = the desktop default.
|
|
93
|
+
*
|
|
94
|
+
* A document with no marker is version 1 — that direction is load-bearing. A
|
|
95
|
+
* register-backed scope whose schema defaulted the marker to the CURRENT version
|
|
96
|
+
* would declare every stale document already migrated, which is the same
|
|
97
|
+
* upgrade-breaks-everyone bug reached through the other storage path.
|
|
98
|
+
*/
|
|
99
|
+
export declare const OUTBOUND_IDENTITY_VERSION = 2;
|
|
100
|
+
/** What an absent marker means. Deliberately not the current version. */
|
|
101
|
+
export declare const LEGACY_OUTBOUND_IDENTITY_VERSION = 1;
|
|
102
|
+
/** One stored preference, as {@link migrateOutboundSettingDocument} reads it. */
|
|
103
|
+
export interface OutboundSettingDocument {
|
|
104
|
+
/** The stored preference, in whatever shape the document holds it. */
|
|
105
|
+
outboundIdentity?: unknown;
|
|
106
|
+
/** The marker; absent on a pre-marker document. */
|
|
107
|
+
outboundIdentityVersion?: unknown;
|
|
108
|
+
}
|
|
109
|
+
/** What a caller must use, and whether it must write the document back. */
|
|
110
|
+
export interface MigratedOutboundSetting {
|
|
111
|
+
/** The identity this host is to present. */
|
|
112
|
+
outboundIdentity: WorkBuddyOutboundSetting;
|
|
113
|
+
/** Marker the document carries after this read. */
|
|
114
|
+
outboundIdentityVersion: number;
|
|
115
|
+
/** Whether the caller must persist the document (marker and/or new value). */
|
|
116
|
+
migrated: boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Read one stored outbound preference, migrating the pre-marker default once.
|
|
120
|
+
*
|
|
121
|
+
* The rule, and the reason for each half:
|
|
122
|
+
*
|
|
123
|
+
* - `marker >= 2`: this document has been through the migration. Whatever it
|
|
124
|
+
* holds is a choice now — `cli` included, which a deployment may pin on
|
|
125
|
+
* purpose — so the value is returned untouched and nothing is written.
|
|
126
|
+
* - no marker and a stored `cli`: the era's default, indistinguishable from a
|
|
127
|
+
* deliberate one, and a value upstream now refuses (10085). It becomes
|
|
128
|
+
* {@link DEFAULT_OUTBOUND_SETTING} and the marker is stamped. The stamp is
|
|
129
|
+
* what makes this idempotent AND what stops a genuine `cli` pinned AFTER the
|
|
130
|
+
* migration from being flipped on the next read.
|
|
131
|
+
* - no marker and any other value (`auto`/`workbuddy`/`vscode`): a real user
|
|
132
|
+
* setting, kept as-is; only the marker is stamped, so a later upgrade never
|
|
133
|
+
* re-decides it.
|
|
134
|
+
*
|
|
135
|
+
* An unparseable stored value normalises to the shipped default, exactly as an
|
|
136
|
+
* absent one does, and is stamped: garbage is not a preference.
|
|
137
|
+
*/
|
|
138
|
+
export declare function migrateOutboundSettingDocument(document: OutboundSettingDocument): MigratedOutboundSetting;
|
|
139
|
+
//# sourceMappingURL=outbound-identity.d.ts.map
|