@eddyskywalker/dsh-chatgpt-subscription 0.33.0 → 0.35.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 +96 -110
- package/README.md +51 -110
- package/lib/client.js +5301 -5413
- package/lib/client.js.map +1 -1
- package/lib/index.js +30296 -32529
- package/lib/types/client/CodexSubscriptionSection.d.ts.map +1 -1
- package/lib/types/client/ProviderHubSection.d.ts.map +1 -1
- package/lib/types/client/antigravity/locales.d.ts +2 -5
- package/lib/types/client/antigravity/locales.d.ts.map +1 -1
- package/lib/types/client/claude/locales.d.ts +2 -5
- package/lib/types/client/claude/locales.d.ts.map +1 -1
- package/lib/types/client/claude/styles.d.ts +2 -2
- package/lib/types/client/cline-pass/locales.d.ts +0 -6
- package/lib/types/client/cline-pass/locales.d.ts.map +1 -1
- package/lib/types/client/command-code/locales.d.ts +2 -5
- package/lib/types/client/command-code/locales.d.ts.map +1 -1
- package/lib/types/client/common/AccountPoolSection.d.ts +3 -2
- package/lib/types/client/common/AccountPoolSection.d.ts.map +1 -1
- package/lib/types/client/common/account-pool-labels.d.ts +0 -2
- package/lib/types/client/common/account-pool-labels.d.ts.map +1 -1
- package/lib/types/client/common/format.d.ts +12 -2
- package/lib/types/client/common/format.d.ts.map +1 -1
- package/lib/types/client/common/styles.d.ts.map +1 -1
- package/lib/types/client/glm-coding-plan/GlmCodingPlanSection.d.ts +1 -1
- package/lib/types/client/glm-coding-plan/locales.d.ts +2 -5
- package/lib/types/client/glm-coding-plan/locales.d.ts.map +1 -1
- package/lib/types/client/glm-coding-plan/styles.d.ts +3 -2
- package/lib/types/client/glm-coding-plan/styles.d.ts.map +1 -1
- package/lib/types/client/glm-coding-plan/useGlmCodingPlanSection.d.ts.map +1 -1
- package/lib/types/client/hub/UpdateCheck.d.ts +9 -0
- package/lib/types/client/hub/UpdateCheck.d.ts.map +1 -0
- package/lib/types/client/hub/brand-icons.d.ts +2 -2
- package/lib/types/client/hub/brand-icons.d.ts.map +1 -1
- package/lib/types/client/hub/brand-svg.d.ts +0 -4
- package/lib/types/client/hub/brand-svg.d.ts.map +1 -1
- package/lib/types/client/hub/hub-styles.d.ts.map +1 -1
- package/lib/types/client/hub/providers.d.ts.map +1 -1
- package/lib/types/client/index.d.ts +2 -2
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/kimi-code/locales.d.ts +2 -5
- package/lib/types/client/kimi-code/locales.d.ts.map +1 -1
- package/lib/types/client/locales.d.ts +39 -3
- package/lib/types/client/locales.d.ts.map +1 -1
- package/lib/types/client/minimax-code/locales.d.ts +2 -5
- package/lib/types/client/minimax-code/locales.d.ts.map +1 -1
- package/lib/types/client/minimax-code/useMinimaxCodeSection.d.ts +2 -2
- package/lib/types/client/minimax-code/useMinimaxCodeSection.d.ts.map +1 -1
- package/lib/types/client/ollama/locales.d.ts +0 -6
- package/lib/types/client/ollama/locales.d.ts.map +1 -1
- package/lib/types/client/opendesign/OpenDesignComposerQuota.d.ts +20 -0
- package/lib/types/client/opendesign/OpenDesignComposerQuota.d.ts.map +1 -0
- package/lib/types/client/opendesign/OpenDesignSection.d.ts +18 -0
- package/lib/types/client/opendesign/OpenDesignSection.d.ts.map +1 -0
- package/lib/types/client/opendesign/api.d.ts +45 -0
- package/lib/types/client/opendesign/api.d.ts.map +1 -0
- package/lib/types/client/opendesign/locales.d.ts +683 -0
- package/lib/types/client/{workbuddy → opendesign}/locales.d.ts.map +1 -1
- package/lib/types/client/opendesign/styles.d.ts +11 -0
- package/lib/types/client/opendesign/styles.d.ts.map +1 -0
- package/lib/types/client/qoder/QoderSection.d.ts +13 -3
- package/lib/types/client/qoder/QoderSection.d.ts.map +1 -1
- package/lib/types/client/qoder/locales.d.ts +7 -3
- package/lib/types/client/qoder/locales.d.ts.map +1 -1
- package/lib/types/client/qoder/useQoderSection.d.ts.map +1 -1
- package/lib/types/client/step-code/StepCodeComposerQuota.d.ts +2 -2
- package/lib/types/client/step-code/StepCodeSection.d.ts +1 -1
- package/lib/types/client/step-code/locales.d.ts +2 -5
- package/lib/types/client/step-code/locales.d.ts.map +1 -1
- package/lib/types/client/step-code/styles.d.ts +1 -1
- package/lib/types/client/step-code/useStepCodeSection.d.ts.map +1 -1
- package/lib/types/host/claude/account-pool.d.ts +2 -2
- package/lib/types/host/claude/account-pool.d.ts.map +1 -1
- package/lib/types/host/claude/routes.d.ts +1 -1
- package/lib/types/host/common/capabilities.d.ts.map +1 -1
- package/lib/types/host/common/credential-read-cache.d.ts +2 -3
- package/lib/types/host/common/credential-read-cache.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 +2 -2
- package/lib/types/host/common/request-diagnostics.d.ts.map +1 -1
- package/lib/types/host/glm-coding-plan/mapper-openai.d.ts +1 -1
- package/lib/types/host/glm-coding-plan/model-catalog.d.ts +4 -4
- package/lib/types/host/kimi-code/adapter.d.ts +31 -0
- package/lib/types/host/kimi-code/adapter.d.ts.map +1 -1
- package/lib/types/host/kimi-code/mapper.d.ts +8 -0
- package/lib/types/host/kimi-code/mapper.d.ts.map +1 -1
- package/lib/types/host/kimi-code/types.d.ts +92 -0
- package/lib/types/host/kimi-code/types.d.ts.map +1 -1
- package/lib/types/host/minimax-code/account-pool.d.ts +6 -7
- package/lib/types/host/minimax-code/account-pool.d.ts.map +1 -1
- package/lib/types/host/minimax-code/checkin.d.ts +7 -8
- package/lib/types/host/minimax-code/checkin.d.ts.map +1 -1
- package/lib/types/host/minimax-code/routes.d.ts +1 -1
- package/lib/types/host/opendesign/account-pool.d.ts +54 -0
- package/lib/types/host/opendesign/account-pool.d.ts.map +1 -0
- package/lib/types/host/opendesign/adapter.d.ts +69 -0
- package/lib/types/host/opendesign/adapter.d.ts.map +1 -0
- package/lib/types/host/opendesign/catalog.d.ts +44 -0
- package/lib/types/host/opendesign/catalog.d.ts.map +1 -0
- package/lib/types/host/opendesign/client.d.ts +148 -0
- package/lib/types/host/opendesign/client.d.ts.map +1 -0
- package/lib/types/host/opendesign/line.d.ts +49 -0
- package/lib/types/host/opendesign/line.d.ts.map +1 -0
- package/lib/types/host/opendesign/mapper.d.ts +128 -0
- package/lib/types/host/opendesign/mapper.d.ts.map +1 -0
- package/lib/types/host/opendesign/oauth.d.ts +105 -0
- package/lib/types/host/opendesign/oauth.d.ts.map +1 -0
- package/lib/types/host/opendesign/routes.d.ts +74 -0
- package/lib/types/host/opendesign/routes.d.ts.map +1 -0
- package/lib/types/host/opendesign/token-store.d.ts +154 -0
- package/lib/types/host/opendesign/token-store.d.ts.map +1 -0
- package/lib/types/host/opendesign/types.d.ts +180 -0
- package/lib/types/host/opendesign/types.d.ts.map +1 -0
- package/lib/types/host/qoder/adapter.d.ts +26 -2
- package/lib/types/host/qoder/adapter.d.ts.map +1 -1
- package/lib/types/host/qoder/client.d.ts +112 -0
- package/lib/types/host/qoder/client.d.ts.map +1 -1
- package/lib/types/host/qoder/model-catalog.d.ts +52 -6
- package/lib/types/host/qoder/model-catalog.d.ts.map +1 -1
- package/lib/types/host/qoder/routes.d.ts +23 -0
- package/lib/types/host/qoder/routes.d.ts.map +1 -1
- package/lib/types/host/qoder/token-store.d.ts +56 -7
- package/lib/types/host/qoder/token-store.d.ts.map +1 -1
- package/lib/types/host/step-code/adapter.d.ts +1 -1
- package/lib/types/host/step-code/client.d.ts +1 -1
- package/lib/types/host/step-code/mapper.d.ts +3 -3
- package/lib/types/host/step-code/oauth.d.ts +1 -1
- package/lib/types/host/update-check.d.ts +118 -0
- package/lib/types/host/update-check.d.ts.map +1 -0
- package/lib/types/index.d.ts +11 -7
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/shared/account-pool-contracts.d.ts +0 -24
- package/lib/types/shared/account-pool-contracts.d.ts.map +1 -1
- package/lib/types/shared/hub-contracts.d.ts +1 -1
- package/lib/types/shared/hub-contracts.d.ts.map +1 -1
- package/lib/types/shared/minimax-code-contracts.d.ts +2 -2
- package/lib/types/shared/opendesign-contracts.d.ts +159 -0
- package/lib/types/shared/opendesign-contracts.d.ts.map +1 -0
- package/lib/types/shared/qoder-contracts.d.ts +40 -1
- package/lib/types/shared/qoder-contracts.d.ts.map +1 -1
- package/lib/types/shared/update-contracts.d.ts +124 -0
- package/lib/types/shared/update-contracts.d.ts.map +1 -0
- package/package.json +1 -1
- package/lib/types/client/workbuddy/WorkBuddyComposerQuota.d.ts +0 -22
- package/lib/types/client/workbuddy/WorkBuddyComposerQuota.d.ts.map +0 -1
- package/lib/types/client/workbuddy/WorkBuddySection.d.ts +0 -50
- package/lib/types/client/workbuddy/WorkBuddySection.d.ts.map +0 -1
- package/lib/types/client/workbuddy/locales.d.ts +0 -635
- package/lib/types/client/workbuddy/styles.d.ts +0 -15
- package/lib/types/client/workbuddy/styles.d.ts.map +0 -1
- package/lib/types/client/workbuddy/useWorkBuddySection.d.ts +0 -149
- package/lib/types/client/workbuddy/useWorkBuddySection.d.ts.map +0 -1
- package/lib/types/host/workbuddy/account-pool.d.ts +0 -235
- package/lib/types/host/workbuddy/account-pool.d.ts.map +0 -1
- package/lib/types/host/workbuddy/adapter.d.ts +0 -129
- package/lib/types/host/workbuddy/adapter.d.ts.map +0 -1
- package/lib/types/host/workbuddy/atrest.d.ts +0 -98
- package/lib/types/host/workbuddy/atrest.d.ts.map +0 -1
- package/lib/types/host/workbuddy/checkin.d.ts +0 -150
- package/lib/types/host/workbuddy/checkin.d.ts.map +0 -1
- package/lib/types/host/workbuddy/client.d.ts +0 -169
- package/lib/types/host/workbuddy/client.d.ts.map +0 -1
- package/lib/types/host/workbuddy/dsml.d.ts +0 -55
- package/lib/types/host/workbuddy/dsml.d.ts.map +0 -1
- package/lib/types/host/workbuddy/guardrails.d.ts +0 -111
- package/lib/types/host/workbuddy/guardrails.d.ts.map +0 -1
- package/lib/types/host/workbuddy/identity.d.ts +0 -71
- package/lib/types/host/workbuddy/identity.d.ts.map +0 -1
- package/lib/types/host/workbuddy/mapper.d.ts +0 -131
- package/lib/types/host/workbuddy/mapper.d.ts.map +0 -1
- package/lib/types/host/workbuddy/model-catalog.d.ts +0 -217
- package/lib/types/host/workbuddy/model-catalog.d.ts.map +0 -1
- package/lib/types/host/workbuddy/oauth.d.ts +0 -47
- package/lib/types/host/workbuddy/oauth.d.ts.map +0 -1
- package/lib/types/host/workbuddy/outbound-identity.d.ts +0 -66
- package/lib/types/host/workbuddy/outbound-identity.d.ts.map +0 -1
- package/lib/types/host/workbuddy/routes.d.ts +0 -56
- package/lib/types/host/workbuddy/routes.d.ts.map +0 -1
- package/lib/types/host/workbuddy/token-store.d.ts +0 -360
- package/lib/types/host/workbuddy/token-store.d.ts.map +0 -1
- package/lib/types/host/workbuddy/types.d.ts +0 -161
- package/lib/types/host/workbuddy/types.d.ts.map +0 -1
- package/lib/types/shared/workbuddy-contracts.d.ts +0 -353
- package/lib/types/shared/workbuddy-contracts.d.ts.map +0 -1
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenDesign wire mapping: the harness conversation in, an OpenAI-compatible
|
|
3
|
+
* `chat/completions` body out; decoded SSE frames in, harness stream chunks out.
|
|
4
|
+
*
|
|
5
|
+
* The request order rules matter more than they look: an assistant message
|
|
6
|
+
* carrying `tool_calls` must be followed immediately by one `tool` message per
|
|
7
|
+
* call id, or a validating gateway rejects the whole request with "insufficient
|
|
8
|
+
* tool messages following tool_calls message". Everything that would otherwise
|
|
9
|
+
* land inside that run is held back until the group closes.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-chatgpt-subscription/opendesign-mapper
|
|
12
|
+
*/
|
|
13
|
+
import { type StreamChunk, type TokenUsage } from '@deepseek-ai/dsh-llm';
|
|
14
|
+
import type { GenerateOptions, Message } from '../common/llm-compat.ts';
|
|
15
|
+
import { type ResolvedRequestImages } from '../common/request-images.ts';
|
|
16
|
+
/** The sentence a no-content finish carries, shared with the sibling lines. */
|
|
17
|
+
export declare const NO_ANSWER_PHRASE = "ended the turn without an answer or a tool call";
|
|
18
|
+
/** One OpenAI wire message. */
|
|
19
|
+
export interface OpenDesignWireMessage {
|
|
20
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
21
|
+
content: string | Array<Record<string, unknown>>;
|
|
22
|
+
reasoning_content?: string;
|
|
23
|
+
tool_calls?: Array<{
|
|
24
|
+
id: string;
|
|
25
|
+
type: 'function';
|
|
26
|
+
function: {
|
|
27
|
+
name: string;
|
|
28
|
+
arguments: string;
|
|
29
|
+
};
|
|
30
|
+
}>;
|
|
31
|
+
tool_call_id?: string;
|
|
32
|
+
}
|
|
33
|
+
/** One request body, as sent to the gateway. */
|
|
34
|
+
export interface OpenDesignWireBody {
|
|
35
|
+
model: string;
|
|
36
|
+
messages: OpenDesignWireMessage[];
|
|
37
|
+
stream: true;
|
|
38
|
+
stream_options: {
|
|
39
|
+
include_usage: true;
|
|
40
|
+
};
|
|
41
|
+
tools?: Array<{
|
|
42
|
+
type: 'function';
|
|
43
|
+
function: {
|
|
44
|
+
name: string;
|
|
45
|
+
description: string;
|
|
46
|
+
parameters: Record<string, unknown>;
|
|
47
|
+
};
|
|
48
|
+
}>;
|
|
49
|
+
temperature?: number;
|
|
50
|
+
max_tokens?: number;
|
|
51
|
+
stop?: readonly string[];
|
|
52
|
+
reasoning_effort?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Convert the harness conversation to wire messages.
|
|
56
|
+
*
|
|
57
|
+
* Tool results become standalone `role: 'tool'` messages. A user message
|
|
58
|
+
* carrying an image switches to the OpenAI content-part array; a text-only one
|
|
59
|
+
* keeps the plain-string form. An image nested in a tool result has no OpenAI
|
|
60
|
+
* `tool` wire spelling, so it rides a following user message instead — the same
|
|
61
|
+
* shape the shipped adapters use. Deferring that message until the next non-tool
|
|
62
|
+
* message keeps a parallel group's answers contiguous.
|
|
63
|
+
*
|
|
64
|
+
* `developer` becomes `system`: the newer OpenAI spelling is not accepted by
|
|
65
|
+
* every OpenAI-compatible gateway, while `system` is.
|
|
66
|
+
*/
|
|
67
|
+
export declare function serializeMessages(messages: readonly Message[], images: ResolvedRequestImages): OpenDesignWireMessage[];
|
|
68
|
+
/**
|
|
69
|
+
* Build the wire request for one harness call.
|
|
70
|
+
* @param options - the harness request (model, system, history, tools, sampling).
|
|
71
|
+
* @param connection - resolved connection facts (default output budget).
|
|
72
|
+
* @param images - attachmentId → prepared request version.
|
|
73
|
+
*/
|
|
74
|
+
export declare function buildOpenDesignBody(options: GenerateOptions, connection: {
|
|
75
|
+
maxTokens: number;
|
|
76
|
+
}, images: ResolvedRequestImages): OpenDesignWireBody;
|
|
77
|
+
/** Map an OpenAI `finish_reason` to the harness finish reason. */
|
|
78
|
+
export declare function mapFinishReason(reason: string): StreamChunk & {
|
|
79
|
+
type: 'finish';
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Map OpenAI usage fields to disjoint harness counts.
|
|
83
|
+
*
|
|
84
|
+
* `prompt_tokens` includes cache hits per the OpenAI convention, and the harness
|
|
85
|
+
* counts are disjoint, so cached tokens are subtracted out of `inputTokens`.
|
|
86
|
+
*/
|
|
87
|
+
export declare function mapUsage(usage: Record<string, unknown> | null | undefined): TokenUsage;
|
|
88
|
+
/**
|
|
89
|
+
* Read one delta's reasoning text, tolerating both wire spellings.
|
|
90
|
+
*
|
|
91
|
+
* Prefers the string field, and falls back to joining the `reasoning_details`
|
|
92
|
+
* parts, which is where a gateway that omits the flat field puts the same text.
|
|
93
|
+
*/
|
|
94
|
+
export declare function reasoningOf(delta: Record<string, unknown>): string | undefined;
|
|
95
|
+
/** The gateway's error string, whichever envelope it arrived in. */
|
|
96
|
+
export declare function errorText(error: unknown): string;
|
|
97
|
+
/** Whether the payload is a bare error object rather than a completion chunk. */
|
|
98
|
+
export declare function isErrorPayload(payload: unknown): payload is {
|
|
99
|
+
error: unknown;
|
|
100
|
+
};
|
|
101
|
+
/** Whether one refusal is about the credential at all. */
|
|
102
|
+
export declare function isAuthenticationError(message: string, status?: number): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Map a gateway error payload to a stable harness code.
|
|
105
|
+
*
|
|
106
|
+
* OpenDesign meters in dollar-denominated credits, so the exhausted state reads
|
|
107
|
+
* as an insufficient-balance/credits refusal, not a window name: 402, or the
|
|
108
|
+
* gateway's own wording about credits/balance running out, is QUOTA. Anything
|
|
109
|
+
* merely mentioning a plan or a limit is NOT — a temporary billing-lookup
|
|
110
|
+
* failure must not stand an account down.
|
|
111
|
+
*/
|
|
112
|
+
export declare function streamErrorCode(message: string, status?: number): string;
|
|
113
|
+
/**
|
|
114
|
+
* Parse an SSE body into decoded JSON frames.
|
|
115
|
+
* @param body - a web ReadableStream of UTF-8 bytes.
|
|
116
|
+
* @returns every `data:` payload up to `[DONE]`.
|
|
117
|
+
*/
|
|
118
|
+
export declare function parseServerSentEvents(body: ReadableStream<Uint8Array>): AsyncGenerator<unknown | '[DONE]'>;
|
|
119
|
+
/**
|
|
120
|
+
* Translate decoded SSE payloads into harness stream chunks.
|
|
121
|
+
*
|
|
122
|
+
* Deltas stream through as they arrive; block ends, usage and the finish reason
|
|
123
|
+
* are all deferred to the `[DONE]` sentinel, so no chunk ever follows `finish`.
|
|
124
|
+
* A completion with no content at all becomes an `EMPTY_RESPONSE` error finish
|
|
125
|
+
* rather than a silent empty message.
|
|
126
|
+
*/
|
|
127
|
+
export declare function translate(payloads: AsyncIterable<unknown | '[DONE]'>): AsyncGenerator<StreamChunk>;
|
|
128
|
+
//# sourceMappingURL=mapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapper.d.ts","sourceRoot":"","sources":["../../../../src/host/opendesign/mapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAKL,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAsC,eAAe,EAAE,OAAO,EAAE,MAAM,yBAA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AOG;AACH,wBAAuB,SAAS,CAAC,QAAQ,EAAE,aAAa,CAAC,OAAO,GAAG,QAAQ,CAAC,GAAG,cAAc,CAAC,WAAW,CAAC,CA+FzG"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { OpenDesignOAuthCredentials } from './token-store.ts';
|
|
2
|
+
/** An auth failure with the HTTP facts a caller can judge. */
|
|
3
|
+
export declare class OpenDesignOAuthError extends Error {
|
|
4
|
+
readonly status?: number;
|
|
5
|
+
readonly code?: string;
|
|
6
|
+
constructor(message: string, options?: {
|
|
7
|
+
status?: number;
|
|
8
|
+
code?: string;
|
|
9
|
+
cause?: unknown;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/** One device authorization, as the create call returns it. */
|
|
13
|
+
export interface OpenDesignDeviceAuthorization {
|
|
14
|
+
deviceId: string;
|
|
15
|
+
userCode: string;
|
|
16
|
+
activationUrl: string;
|
|
17
|
+
deviceSecret: string;
|
|
18
|
+
expiresAt: number;
|
|
19
|
+
pollIntervalSeconds: number;
|
|
20
|
+
}
|
|
21
|
+
/** Step 1: create one device authorization. */
|
|
22
|
+
export declare function startOpenDesignDeviceAuth(fetchFn: typeof fetch, { apiBase, host, signal, timeoutMs, }: {
|
|
23
|
+
apiBase?: string;
|
|
24
|
+
host: string;
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
}): Promise<OpenDesignDeviceAuthorization>;
|
|
28
|
+
/** One poll verdict: still waiting, or the issued credential pair. */
|
|
29
|
+
export type OpenDesignDevicePoll = {
|
|
30
|
+
pending: true;
|
|
31
|
+
} | {
|
|
32
|
+
pending: false;
|
|
33
|
+
credentials: OpenDesignOAuthCredentials;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Step 3: one poll of the device grant.
|
|
37
|
+
*
|
|
38
|
+
* Completion is read from the payload's SHAPE: `runtimeKey`/`controlKey`
|
|
39
|
+
* present means approved, whatever `status` says; a non-pending status with no
|
|
40
|
+
* keys is a refusal (denied or expired), reported with the service's own words.
|
|
41
|
+
*/
|
|
42
|
+
export declare function pollOpenDesignDevice(fetchFn: typeof fetch, authorization: Pick<OpenDesignDeviceAuthorization, 'deviceId' | 'deviceSecret'>, { apiBase, signal, timeoutMs, }?: {
|
|
43
|
+
apiBase?: string;
|
|
44
|
+
signal?: AbortSignal;
|
|
45
|
+
timeoutMs?: number;
|
|
46
|
+
}): Promise<OpenDesignDevicePoll>;
|
|
47
|
+
/** One login flow, as the settings card renders it. */
|
|
48
|
+
export type OpenDesignLoginStatus = 'idle' | 'pending' | 'complete' | 'failed' | 'cancelled';
|
|
49
|
+
export interface OpenDesignLoginFlow {
|
|
50
|
+
id: string;
|
|
51
|
+
status: OpenDesignLoginStatus;
|
|
52
|
+
userCode: string;
|
|
53
|
+
verificationUri: string;
|
|
54
|
+
expiresAt: number;
|
|
55
|
+
intervalSeconds: number;
|
|
56
|
+
error: string;
|
|
57
|
+
accountAlias: string;
|
|
58
|
+
}
|
|
59
|
+
export interface OpenDesignLoginOptions {
|
|
60
|
+
fetchFn: typeof fetch;
|
|
61
|
+
/** AMR control-plane base; a test seam and a deployment override. */
|
|
62
|
+
apiBase?: string;
|
|
63
|
+
/** This machine's name, recorded on the authorization the console lists. */
|
|
64
|
+
host(): string;
|
|
65
|
+
/** Persist a newly signed-in account; throws make the flow fail. */
|
|
66
|
+
onLogin(credentials: OpenDesignOAuthCredentials): Promise<void>;
|
|
67
|
+
logger?: {
|
|
68
|
+
warn(message: string, ...args: unknown[]): void;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* One device-authorization sign-in at a time.
|
|
73
|
+
*
|
|
74
|
+
* Polling is driven by the card (`GET /login/status`): each request makes at
|
|
75
|
+
* most one AMR call, and only after the advertised interval has elapsed. A host
|
|
76
|
+
* restart therefore loses the pending flow rather than keeping a poll loop
|
|
77
|
+
* alive with no reader — the same contract the sibling lines use.
|
|
78
|
+
*/
|
|
79
|
+
export declare class OpenDesignLoginManager {
|
|
80
|
+
private readonly options;
|
|
81
|
+
private flow;
|
|
82
|
+
private sequence;
|
|
83
|
+
constructor(options: OpenDesignLoginOptions);
|
|
84
|
+
/** Start a new flow, cancelling any previous one. */
|
|
85
|
+
begin({ signal }?: {
|
|
86
|
+
signal?: AbortSignal;
|
|
87
|
+
}): Promise<OpenDesignLoginFlow>;
|
|
88
|
+
/** The latest flow, or null when this process never started one. */
|
|
89
|
+
current(): OpenDesignLoginFlow | null;
|
|
90
|
+
/**
|
|
91
|
+
* Advance one flow and return its state.
|
|
92
|
+
*
|
|
93
|
+
* A flow the caller does not name is not advanced: two cards (or a stale one)
|
|
94
|
+
* cannot spend each other's polls.
|
|
95
|
+
*/
|
|
96
|
+
status(id: string, { signal, timeoutMs }?: {
|
|
97
|
+
signal?: AbortSignal;
|
|
98
|
+
timeoutMs?: number;
|
|
99
|
+
}): Promise<OpenDesignLoginFlow>;
|
|
100
|
+
/** Abandon one flow; a late browser confirmation is then ignored. */
|
|
101
|
+
cancel(id: string): boolean;
|
|
102
|
+
/** Mark every flow cancelled for teardown. */
|
|
103
|
+
dispose(): void;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=oauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../../src/host/opendesign/oauth.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAA;AAQlE,8DAA8D;AAC9D,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;gBAEV,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,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,EAAE,EAAE,MAAM,GAAG,OAAO;IAQ3B,8CAA8C;IAC9C,OAAO,IAAI,IAAI;CAKhB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OpenDesign settings API.
|
|
3
|
+
*
|
|
4
|
+
* The surface is the one every sibling line exposes — status, accounts, models —
|
|
5
|
+
* plus the controls this line genuinely has: device-authorization sign-in, an
|
|
6
|
+
* explicit catalog sync, and the wallet-balance read an OAuth account's control
|
|
7
|
+
* key can make.
|
|
8
|
+
*
|
|
9
|
+
* Reads never trigger an upstream call; the catalog is synced by its own action
|
|
10
|
+
* and behind a successful sign-in, and quota is refreshed by its own action.
|
|
11
|
+
*
|
|
12
|
+
* @module dsh-chatgpt-subscription/opendesign-routes
|
|
13
|
+
*/
|
|
14
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
15
|
+
import type { OpenDesignAccountPool } from './account-pool.ts';
|
|
16
|
+
import { type OpenDesignModelSettingsStore } from './token-store.ts';
|
|
17
|
+
import type { OpenDesignLoginManager } from './oauth.ts';
|
|
18
|
+
import { openPlatformBrowser } from '../step-code/routes.ts';
|
|
19
|
+
import { type OpenDesignUsageAccountDto, type OpenDesignWebStatus } from '../../shared/opendesign-contracts.ts';
|
|
20
|
+
export interface OpenDesignRouteOptions {
|
|
21
|
+
settings: OpenDesignModelSettingsStore;
|
|
22
|
+
accountPool: OpenDesignAccountPool;
|
|
23
|
+
/** Proxy-aware fetch for account verification, quota reads and catalog syncs. */
|
|
24
|
+
fetchFn: typeof fetch;
|
|
25
|
+
/** Device-authorization sign-in state, when the composition installed one. */
|
|
26
|
+
login?: OpenDesignLoginManager;
|
|
27
|
+
/**
|
|
28
|
+
* Browser opener for `/login/start`; defaults to a no-op because the settings
|
|
29
|
+
* card opens the activation URL itself via `window.open`.
|
|
30
|
+
*/
|
|
31
|
+
openBrowser?: (url: string) => void;
|
|
32
|
+
serving(): boolean;
|
|
33
|
+
conflict(): string | null;
|
|
34
|
+
}
|
|
35
|
+
/** Named browser opener for deployments that want the host to launch the activation URL. */
|
|
36
|
+
export declare const openOpenDesignBrowser: typeof openPlatformBrowser;
|
|
37
|
+
/**
|
|
38
|
+
* Latest wallet readings, in-process only.
|
|
39
|
+
*
|
|
40
|
+
* A reading is a snapshot, not a stream: a restart starts blank rather than
|
|
41
|
+
* serving a stale figure as if fresh, and a failed refresh keeps the previous
|
|
42
|
+
* one with its error attached (the card shows both).
|
|
43
|
+
*/
|
|
44
|
+
interface UsageStore {
|
|
45
|
+
readings: Map<string, OpenDesignUsageAccountDto>;
|
|
46
|
+
fetchedAt: number;
|
|
47
|
+
}
|
|
48
|
+
/** Assemble the whole status payload the OpenDesign tab renders. */
|
|
49
|
+
export declare function getOpenDesignWebStatus(options: OpenDesignRouteOptions, usageStore?: UsageStore): Promise<OpenDesignWebStatus>;
|
|
50
|
+
/** The route table, exported so the client and this file can be checked against each other. */
|
|
51
|
+
export declare const OPENDESIGN_ROUTES: {
|
|
52
|
+
readonly status: "GET";
|
|
53
|
+
readonly settings: "POST";
|
|
54
|
+
readonly accounts: "GET|POST";
|
|
55
|
+
readonly 'login/start': "POST";
|
|
56
|
+
readonly 'login/status': "GET";
|
|
57
|
+
readonly 'login/cancel': "POST";
|
|
58
|
+
readonly models: "GET|POST";
|
|
59
|
+
readonly 'models/visibility': "POST";
|
|
60
|
+
readonly 'models/visibility-all': "POST";
|
|
61
|
+
readonly 'models/context-window': "POST";
|
|
62
|
+
readonly 'catalog/refresh': "POST";
|
|
63
|
+
readonly usage: "GET|POST";
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Register the OpenDesign settings API under `/opendesign/api`.
|
|
67
|
+
*
|
|
68
|
+
* Registered unconditionally: the card is how a user adds their first key, so
|
|
69
|
+
* gating it on winning the route would leave a contested id with no way to
|
|
70
|
+
* configure it at all.
|
|
71
|
+
*/
|
|
72
|
+
export declare function registerOpenDesignRoutes(ctx: Context, options: OpenDesignRouteOptions): () => void;
|
|
73
|
+
export {};
|
|
74
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../../src/host/opendesign/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAKlD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAC9D,OAAO,EAKL,KAAK,4BAA4B,EAClC,MAAM,kBAAkB,CAAA;AAEzB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAOL,KAAK,yBAAyB,EAE9B,KAAK,mBAAmB,EACzB,MAAM,sCAAsC,CAAA;AAsG7C,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,4BAA4B,CAAA;IACtC,WAAW,EAAE,qBAAqB,CAAA;IAClC,iFAAiF;IACjF,OAAO,EAAE,OAAO,KAAK,CAAA;IACrB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,sBAAsB,CAAA;IAC9B;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IACnC,OAAO,IAAI,OAAO,CAAA;IAClB,QAAQ,IAAI,MAAM,GAAG,IAAI,CAAA;CAC1B;AAED,4FAA4F;AAC5F,eAAO,MAAM,qBAAqB,4BAAsB,CAAA;AAExD;;;;;;GAMG;AACH,UAAU,UAAU;IAClB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAA;IAChD,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,oEAAoE;AACpE,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,sBAAsB,EAC/B,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,mBAAmB,CAAC,CAwC9B;AAkBD,+FAA+F;AAC/F,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;CAAS,CAAA;AAEvC;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,sBAAsB,GAAG,MAAM,IAAI,CAwYlG"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { CredentialStore } from '../token-store.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Shared non-secret display facts of one credential.
|
|
4
|
+
*/
|
|
5
|
+
interface OpenDesignCredentialBase {
|
|
6
|
+
/** User-chosen label so several accounts are distinguishable. */
|
|
7
|
+
alias?: string;
|
|
8
|
+
/** Unix milliseconds the credential was added to the pool. */
|
|
9
|
+
addedAt?: number;
|
|
10
|
+
/** Per-account gateway override; empty means the line's own base URL. */
|
|
11
|
+
baseURL?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* One stored OpenDesign API key.
|
|
15
|
+
*
|
|
16
|
+
* The gateway authenticates with a static key, so there is no refresh token and
|
|
17
|
+
* nothing expires. The key is host-only and never crosses to a browser; the
|
|
18
|
+
* settings card renders the alias and the account row, never this value.
|
|
19
|
+
*/
|
|
20
|
+
export interface OpenDesignApiKeyCredentials extends OpenDesignCredentialBase {
|
|
21
|
+
/** Present on every record this line writes; absent records predate the marker. */
|
|
22
|
+
kind?: 'api-key';
|
|
23
|
+
/** Host-only bearer key, created in the OpenDesign Cloud console. */
|
|
24
|
+
apiKey: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* One account signed in through browser device authorization.
|
|
28
|
+
*
|
|
29
|
+
* The approval issues a pair (upstream issue nexu-io/open-design#8870): a
|
|
30
|
+
* `vela_ctrl_…` control key that reads the control plane (wallet balance and
|
|
31
|
+
* friends) and an `sk-amr-…` runtime key that serves the link gateway. Neither
|
|
32
|
+
* carries a published expiry, so there is no refresh lifecycle here — a revoked
|
|
33
|
+
* key is replaced by signing in again, not refreshed.
|
|
34
|
+
*/
|
|
35
|
+
export interface OpenDesignOAuthCredentials extends OpenDesignCredentialBase {
|
|
36
|
+
kind: 'oauth';
|
|
37
|
+
/** Control-plane bearer (`vela_ctrl_…`): wallet reads, never chat. */
|
|
38
|
+
controlKey: string;
|
|
39
|
+
/** Link-gateway bearer (`sk-amr-…`): chat and the live catalog. */
|
|
40
|
+
runtimeKey: string;
|
|
41
|
+
/** The account's identity as the approval returned it. */
|
|
42
|
+
user?: {
|
|
43
|
+
id?: string;
|
|
44
|
+
email?: string;
|
|
45
|
+
name?: string;
|
|
46
|
+
plan?: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export type OpenDesignCredentials = OpenDesignApiKeyCredentials | OpenDesignOAuthCredentials;
|
|
50
|
+
/** Whether one credential is a device-flow session rather than a pasted key. */
|
|
51
|
+
export declare function isOpenDesignOAuthCredentials(credentials: OpenDesignCredentials): credentials is OpenDesignOAuthCredentials;
|
|
52
|
+
/** The chat bearer (`Authorization` value) for one credential. */
|
|
53
|
+
export declare function bearerFor(credentials: OpenDesignCredentials): string;
|
|
54
|
+
/** The control-plane bearer for one credential, when it has one. */
|
|
55
|
+
export declare function controlKeyFor(credentials: OpenDesignCredentials): string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Stable identity of one key.
|
|
58
|
+
*
|
|
59
|
+
* The console hands the user a bare key and the gateway answers no profile for
|
|
60
|
+
* it, so the key's own digest is the only identity available. It is never
|
|
61
|
+
* written anywhere: it exists to tell two pasted keys apart inside the pool
|
|
62
|
+
* document, and it is not a credential and cannot be used as one.
|
|
63
|
+
*/
|
|
64
|
+
export declare function credentialsIdentity(credentials: OpenDesignCredentials): string;
|
|
65
|
+
/** The user-facing label for one credential, when it states one. */
|
|
66
|
+
export declare function credentialsLabel(credentials: OpenDesignCredentials): string | undefined;
|
|
67
|
+
/** One catalog entry, as the last successful gateway listing published it. */
|
|
68
|
+
export interface OpenDesignCatalogModel {
|
|
69
|
+
id: string;
|
|
70
|
+
name?: string;
|
|
71
|
+
contextWindow?: number;
|
|
72
|
+
maxTokens?: number;
|
|
73
|
+
reasoning?: boolean;
|
|
74
|
+
efforts?: string[];
|
|
75
|
+
input?: string[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Everything this line stores besides credentials.
|
|
79
|
+
*
|
|
80
|
+
* `enabledModelIds === null` is "no filter": every known model, including ones
|
|
81
|
+
* a later sync adds. An array is an explicit selection, and an empty one
|
|
82
|
+
* switches every model off. Modelling "all" as null rather than as an explicit
|
|
83
|
+
* all-ids list means a model the service adds later is not silently hidden by a
|
|
84
|
+
* selection made before it existed.
|
|
85
|
+
*
|
|
86
|
+
* The synced catalog lives in this same document (`catalogModels`), so a
|
|
87
|
+
* restart rehydrates it from a local read with no network in the path — the
|
|
88
|
+
* picker never has to wait on the gateway to show what was already discovered.
|
|
89
|
+
*/
|
|
90
|
+
export interface OpenDesignModelSettings {
|
|
91
|
+
enabled: boolean;
|
|
92
|
+
baseURL: string;
|
|
93
|
+
enabledModelIds: string[] | null;
|
|
94
|
+
catalogModels: OpenDesignCatalogModel[];
|
|
95
|
+
/** Models the route must not advertise even though it still knows them. */
|
|
96
|
+
hiddenModels: string[];
|
|
97
|
+
/** Per-model context-window override; absent uses the resolved window. */
|
|
98
|
+
contextWindowOverrides: Record<string, number>;
|
|
99
|
+
defaultContextWindow: number;
|
|
100
|
+
defaultMaxTokens: number;
|
|
101
|
+
maxConcurrentRequests: number;
|
|
102
|
+
streamIdleTimeoutMs: number;
|
|
103
|
+
}
|
|
104
|
+
export interface OpenDesignPreferenceStore {
|
|
105
|
+
status(): OpenDesignModelSettings;
|
|
106
|
+
read(): Promise<OpenDesignModelSettings>;
|
|
107
|
+
update(patch: Partial<OpenDesignModelSettings>): Promise<OpenDesignModelSettings>;
|
|
108
|
+
}
|
|
109
|
+
export declare function credentialPath(): string;
|
|
110
|
+
export declare function modelSettingsPath(): string;
|
|
111
|
+
/** Validate one stored credential: a device-flow session or a static API key. */
|
|
112
|
+
export declare function parseOpenDesignCredentials(value: unknown): OpenDesignCredentials;
|
|
113
|
+
/** Encrypted credential store for the single-key (pre-pool) configuration. */
|
|
114
|
+
export declare class FileCredentialStore {
|
|
115
|
+
private readonly filePath;
|
|
116
|
+
private readonly backend;
|
|
117
|
+
constructor(filePath?: string, backend?: CredentialStore<OpenDesignCredentials>);
|
|
118
|
+
path(): string;
|
|
119
|
+
read(): Promise<OpenDesignCredentials | null>;
|
|
120
|
+
write(credentials: OpenDesignCredentials): Promise<void>;
|
|
121
|
+
clear(): Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
/** Parse one whole settings document. */
|
|
124
|
+
export declare function parseOpenDesignModelSettings(value: unknown): OpenDesignModelSettings;
|
|
125
|
+
/** The document a fresh install starts from. */
|
|
126
|
+
export declare function defaultOpenDesignModelSettings(): OpenDesignModelSettings;
|
|
127
|
+
/**
|
|
128
|
+
* Model and connection settings, bound to a JSON file beside the encrypted
|
|
129
|
+
* credential store.
|
|
130
|
+
*
|
|
131
|
+
* The file is written atomically (temp + rename) so a crash mid-write leaves the
|
|
132
|
+
* previous document intact rather than a truncated one that reads as "reset all
|
|
133
|
+
* settings".
|
|
134
|
+
*/
|
|
135
|
+
export declare class OpenDesignModelSettingsStore implements OpenDesignPreferenceStore {
|
|
136
|
+
private readonly filePath;
|
|
137
|
+
private cached;
|
|
138
|
+
private loadPromise;
|
|
139
|
+
constructor(filePath?: string);
|
|
140
|
+
path(): string;
|
|
141
|
+
status(): OpenDesignModelSettings;
|
|
142
|
+
/** Read the document at activation time, synchronously. */
|
|
143
|
+
readSync(): OpenDesignModelSettings;
|
|
144
|
+
read(): Promise<OpenDesignModelSettings>;
|
|
145
|
+
private load;
|
|
146
|
+
write(settings: OpenDesignModelSettings): Promise<OpenDesignModelSettings>;
|
|
147
|
+
update(patch: Partial<OpenDesignModelSettings>): Promise<OpenDesignModelSettings>;
|
|
148
|
+
/** Record a catalog sync without touching the user's selection. */
|
|
149
|
+
storeCatalog(models: OpenDesignCatalogModel[]): Promise<OpenDesignModelSettings>;
|
|
150
|
+
/** Store or clear (null) one model's context-window override. */
|
|
151
|
+
setContextWindowOverride(model: string, contextWindow: number | null): Promise<OpenDesignModelSettings>;
|
|
152
|
+
}
|
|
153
|
+
export {};
|
|
154
|
+
//# sourceMappingURL=token-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-store.d.ts","sourceRoot":"","sources":["../../../../src/host/opendesign/token-store.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAcxD;;GAEG;AACH,UAAU,wBAAwB;IAChC,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,2BAA4B,SAAQ,wBAAwB;IAC3E,mFAAmF;IACnF,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,0BAA2B,SAAQ,wBAAwB;IAC1E,IAAI,EAAE,OAAO,CAAA;IACb,sEAAsE;IACtE,UAAU,EAAE,MAAM,CAAA;IAClB,mEAAmE;IACnE,UAAU,EAAE,MAAM,CAAA;IAClB,0DAA0D;IAC1D,IAAI,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CACrE;AAED,MAAM,MAAM,qBAAqB,GAAG,2BAA2B,GAAG,0BAA0B,CAAA;AAE5F,gFAAgF;AAChF,wBAAgB,4BAA4B,CAAC,WAAW,EAAE,q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