dsh-subscription-qoder 0.0.0-stage → 0.6.6
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/LICENSE +21 -0
- package/README.en.md +40 -0
- package/README.md +43 -2
- package/UPSTREAM.md +11 -0
- package/assets/icon.png +0 -0
- package/cordis.patch.yml +6 -0
- package/docs/wiki/configuration.md +61 -0
- package/docs/wiki/configuration_CN.md +63 -0
- package/lib/client.js +3984 -0
- package/lib/index.d.ts +291 -0
- package/lib/index.js +8463 -0
- package/lib/invariant.d.ts +15 -0
- package/lib/invariant.js +15 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +136 -4
- package/src/client/assets/qoder.svg +19 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,3984 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "dsh-subscription-qoder",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
let react = require("react");
|
|
8
|
+
let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
9
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
+
//#region node_modules/.pnpm/@deepseek-ai+dsh-brand@0.2.0-rc.2_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-brand/lib/index.js
|
|
11
|
+
/**
|
|
12
|
+
* Duplicate-install-safe nominal primitive helpers.
|
|
13
|
+
*
|
|
14
|
+
* A brand makes structurally identical strings or numbers non-interchangeable
|
|
15
|
+
* at the type level: a `SessionId` cannot be passed where a `ToolCallId` is
|
|
16
|
+
* expected, and an event sequence cannot be passed as a log offset. Comparison,
|
|
17
|
+
* logging, and serialization retain the underlying primitive behavior.
|
|
18
|
+
*
|
|
19
|
+
* This package owns no concrete domain value and keeps no runtime identity or mutable
|
|
20
|
+
* state, so independently installed copies produce interchangeable values.
|
|
21
|
+
*
|
|
22
|
+
* @module @deepseek-ai/dsh-brand
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Apply a compile-time string brand without changing the value.
|
|
26
|
+
* @param value - string admitted by the domain that owns the target brand.
|
|
27
|
+
* @returns the same string with the requested compile-time brand.
|
|
28
|
+
*/
|
|
29
|
+
function brandString(value) {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region node_modules/.pnpm/@deepseek-ai+dsh-session@0.2.0-rc.2_@deepseek-ai+cordis@4.0.4_@deepseek-ai+dsh-scope@0._c9dee8deba3bd498ce58eb9c566c157f/node_modules/@deepseek-ai/dsh-session/lib/types/types.js
|
|
34
|
+
/**
|
|
35
|
+
* Brand a string as a {@link SessionId}.
|
|
36
|
+
* @param id - the raw session id string.
|
|
37
|
+
* @returns the same string with the session-id brand.
|
|
38
|
+
*/
|
|
39
|
+
function SessionId(id) {
|
|
40
|
+
return brandString(id);
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/dsh/credential-contract.ts
|
|
44
|
+
/** Shared DSH host/browser contract for the one managed Qoder credential. */
|
|
45
|
+
const qoderCredentialRef = "QODER_MANAGED_CREDENTIAL";
|
|
46
|
+
/** DSH's local provider uses `env` and `*-env` for ambient credential layers. */
|
|
47
|
+
function isEnvironmentCredentialSource(source) {
|
|
48
|
+
return source === "env" || source?.endsWith("-env") === true;
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/qoder/catalog.ts
|
|
52
|
+
/** Apply the final choices for a model. Undefined means the change is no longer valid. */
|
|
53
|
+
function applyQoderCatalogChange(model, change) {
|
|
54
|
+
const enabled = change.enabled ?? model.enabled !== false;
|
|
55
|
+
if (change.remove) return model.missingFromCatalog && !enabled ? null : void 0;
|
|
56
|
+
let updated = enabled === (model.enabled !== false) ? model : {
|
|
57
|
+
...model,
|
|
58
|
+
enabled
|
|
59
|
+
};
|
|
60
|
+
if (change.tierKey !== void 0) {
|
|
61
|
+
const tokenCount = model.contextOptions?.[change.tierKey]?.tokenCount;
|
|
62
|
+
if (typeof tokenCount !== "number" || !Number.isFinite(tokenCount) || tokenCount <= 0) return void 0;
|
|
63
|
+
updated = {
|
|
64
|
+
...updated,
|
|
65
|
+
contextTier: change.tierKey,
|
|
66
|
+
contextWindow: tokenCount
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return updated;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Provider-advertised context tiers of one model, smallest first. A tier without
|
|
73
|
+
* a usable capacity cannot be selected and is dropped.
|
|
74
|
+
*/
|
|
75
|
+
function contextTiersOf(model) {
|
|
76
|
+
const options = model.contextOptions;
|
|
77
|
+
if (options === void 0) return [];
|
|
78
|
+
return Object.entries(options).flatMap(([key, value]) => {
|
|
79
|
+
const tokenCount = value.tokenCount;
|
|
80
|
+
return typeof tokenCount === "number" && Number.isFinite(tokenCount) && tokenCount > 0 ? [{
|
|
81
|
+
key,
|
|
82
|
+
tokenCount,
|
|
83
|
+
isDefault: value.isDefault === true
|
|
84
|
+
}] : [];
|
|
85
|
+
}).sort((left, right) => left.tokenCount - right.tokenCount);
|
|
86
|
+
}
|
|
87
|
+
/** Resolve a usable selection consistently for the composer and adapter. */
|
|
88
|
+
function resolveContextTier(model, manualTier, historicalWindow) {
|
|
89
|
+
const tiers = contextTiersOf(model);
|
|
90
|
+
return tiers.find((tier) => tier.key === manualTier) ?? tiers.find((tier) => tier.tokenCount === historicalWindow) ?? tiers.find((tier) => tier.key === model.contextTier) ?? tiers.find((tier) => tier.tokenCount === model.contextWindow) ?? (model.contextWindow === void 0 ? tiers.find((tier) => tier.isDefault) : void 0);
|
|
91
|
+
}
|
|
92
|
+
/** Compact capacity label, e.g. `200K` or `1M`. */
|
|
93
|
+
function formatContextTokens(tokenCount) {
|
|
94
|
+
if (tokenCount >= 1e6) {
|
|
95
|
+
const millions = tokenCount / 1e6;
|
|
96
|
+
return `${Number.isInteger(millions) ? millions : millions.toFixed(1)}M`;
|
|
97
|
+
}
|
|
98
|
+
if (tokenCount >= 1e3) {
|
|
99
|
+
const thousands = tokenCount / 1e3;
|
|
100
|
+
return `${Number.isInteger(thousands) ? thousands : thousands.toFixed(1)}K`;
|
|
101
|
+
}
|
|
102
|
+
return String(tokenCount);
|
|
103
|
+
}
|
|
104
|
+
/** Format a price factor number to string (e.g. 1 -> '1', 1.6 -> '1.6', 0.5 -> '0.5', 1.25 -> '1.25'). */
|
|
105
|
+
function formatRateFactor(value) {
|
|
106
|
+
const rounded = Number(value.toFixed(2));
|
|
107
|
+
return String(rounded);
|
|
108
|
+
}
|
|
109
|
+
/** Clone a model catalog entry, detaching any contextOptions object. */
|
|
110
|
+
function cloneCatalogModel(model) {
|
|
111
|
+
return {
|
|
112
|
+
...model,
|
|
113
|
+
...model.contextOptions !== void 0 ? { contextOptions: { ...model.contextOptions } } : {}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const defaultMaxTokens = 32768;
|
|
117
|
+
const defaultModels = [
|
|
118
|
+
{
|
|
119
|
+
id: "cmodel",
|
|
120
|
+
name: "Cantus (Qoder)",
|
|
121
|
+
description: "Default Global Qoder subscription model for quick validation",
|
|
122
|
+
contextWindow: 1e6,
|
|
123
|
+
maxTokens: defaultMaxTokens,
|
|
124
|
+
supportsImages: true
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: "auto",
|
|
128
|
+
name: "Qoder Auto",
|
|
129
|
+
description: "Server-routed Global Qoder model pool",
|
|
130
|
+
contextWindow: 18e4,
|
|
131
|
+
maxTokens: defaultMaxTokens,
|
|
132
|
+
supportsImages: true
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
id: "ultimate",
|
|
136
|
+
name: "Qoder Ultimate",
|
|
137
|
+
description: "Highest-capability Global Qoder model pool",
|
|
138
|
+
contextWindow: 1e6,
|
|
139
|
+
maxTokens: defaultMaxTokens,
|
|
140
|
+
supportsImages: true
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
id: "performance",
|
|
144
|
+
name: "Qoder Performance",
|
|
145
|
+
description: "Performance-oriented Global Qoder model pool",
|
|
146
|
+
contextWindow: 1e6,
|
|
147
|
+
maxTokens: defaultMaxTokens,
|
|
148
|
+
supportsImages: true
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
id: "efficient",
|
|
152
|
+
name: "Qoder Efficient",
|
|
153
|
+
description: "Efficiency-oriented Global Qoder model pool",
|
|
154
|
+
contextWindow: 18e4,
|
|
155
|
+
maxTokens: defaultMaxTokens,
|
|
156
|
+
supportsImages: true
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
id: "lite",
|
|
160
|
+
name: "Qoder Lite",
|
|
161
|
+
description: "Basic Global Qoder model pool",
|
|
162
|
+
contextWindow: 18e4,
|
|
163
|
+
maxTokens: defaultMaxTokens
|
|
164
|
+
}
|
|
165
|
+
];
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/client/credential-operations.ts
|
|
168
|
+
function regionOf(value) {
|
|
169
|
+
if (typeof value !== "object" || value === null) return "global";
|
|
170
|
+
return value.region === "china" ? "china" : "global";
|
|
171
|
+
}
|
|
172
|
+
function modelsOf(section, region) {
|
|
173
|
+
const scoped = section?.modelsByRegion?.[region];
|
|
174
|
+
return Array.isArray(scoped) ? scoped : defaultModels.map((model) => ({ ...model }));
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Absolute Fetch-route prefix. Connection mounts its shared, authenticated API
|
|
178
|
+
* channel at `/api`, and every exact Fetch route lives directly below it.
|
|
179
|
+
*/
|
|
180
|
+
const qoderRpcApiPath = `/api/qoder-subscription`;
|
|
181
|
+
/** Absolute Fetch-route path of one endpoint. */
|
|
182
|
+
function qoderRpcPath(endpoint) {
|
|
183
|
+
return `${qoderRpcApiPath}/${endpoint}`;
|
|
184
|
+
}
|
|
185
|
+
/** Standard diagnostic codes carried in a settings RPC failure envelope. */
|
|
186
|
+
const qoderRpcErrorCodes = [
|
|
187
|
+
"NO_CREDENTIALS",
|
|
188
|
+
"UNAUTHENTICATED",
|
|
189
|
+
"UPSTREAM_ERROR",
|
|
190
|
+
"CATALOG_REFRESHING",
|
|
191
|
+
"CATALOG_EDITING",
|
|
192
|
+
"CATALOG_TIER_UNAVAILABLE",
|
|
193
|
+
"CATALOG_SAVE_FAILED",
|
|
194
|
+
"TIMEOUT",
|
|
195
|
+
"ABORTED",
|
|
196
|
+
"UNKNOWN_ENDPOINT",
|
|
197
|
+
"INTERNAL",
|
|
198
|
+
"INVALID_REQUEST"
|
|
199
|
+
];
|
|
200
|
+
/** Type guard for an untrusted error code. */
|
|
201
|
+
function isQoderRpcErrorCode(value) {
|
|
202
|
+
return typeof value === "string" && qoderRpcErrorCodes.includes(value);
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/client/operation-result.ts
|
|
206
|
+
const success = (value) => ({
|
|
207
|
+
ok: true,
|
|
208
|
+
value
|
|
209
|
+
});
|
|
210
|
+
const record = (value) => typeof value === "object" && value !== null ? value : {};
|
|
211
|
+
/** Classify only explicit protocol fields and standard exception names, never error prose. */
|
|
212
|
+
function operationCause(error) {
|
|
213
|
+
const value = record(error);
|
|
214
|
+
const code = value.code;
|
|
215
|
+
const status = value.status ?? record(value.details).status;
|
|
216
|
+
if (code === "PERMISSION_DENIED" || code === "FORBIDDEN" || code === "EACCES" || code === "EPERM" || value.name === "NotAllowedError" || value.name === "SecurityError") return "permission-denied";
|
|
217
|
+
if (code === "UNAUTHENTICATED" || code === "NO_CREDENTIALS") return "unauthenticated";
|
|
218
|
+
if (code === "TIMEOUT" || code === "ETIMEDOUT" || value.name === "TimeoutError") return "timeout";
|
|
219
|
+
if (code === "ABORTED" || code === "ABORT_ERR" || value.name === "AbortError") return "cancelled";
|
|
220
|
+
if (code === "PERSISTENCE_FAILED" || code === "STORAGE_ERROR") return "persistence";
|
|
221
|
+
if ([
|
|
222
|
+
"ECONNRESET",
|
|
223
|
+
"ECONNREFUSED",
|
|
224
|
+
"ENETUNREACH",
|
|
225
|
+
"NETWORK_ERROR"
|
|
226
|
+
].includes(String(code)) || value.name === "NetworkError" || record(value.details).cause === "connection") return "connection";
|
|
227
|
+
if (status === 403) return "permission-denied";
|
|
228
|
+
if (status === 401) return "unauthenticated";
|
|
229
|
+
return "unknown";
|
|
230
|
+
}
|
|
231
|
+
/** A whitelist deliberately excludes exception messages, details, values and credentials. */
|
|
232
|
+
function diagnoseOperation(error) {
|
|
233
|
+
console.error("[Qoder settings operation]", error.diagnostic);
|
|
234
|
+
}
|
|
235
|
+
function failure(operation, stage, error, options = {}) {
|
|
236
|
+
const cause = operationCause(error);
|
|
237
|
+
const completedStages = options.completedStages ?? [];
|
|
238
|
+
const raw = record(error);
|
|
239
|
+
const rpcCode = isQoderRpcErrorCode(raw.code) ? raw.code : void 0;
|
|
240
|
+
const outcome = options.mutation ? options.outcome ?? (completedStages.length ? "partial" : "unknown") : void 0;
|
|
241
|
+
const code = [
|
|
242
|
+
"PERMISSION_DENIED",
|
|
243
|
+
"FORBIDDEN",
|
|
244
|
+
"EACCES",
|
|
245
|
+
"EPERM",
|
|
246
|
+
"PERSISTENCE_FAILED",
|
|
247
|
+
"STORAGE_ERROR",
|
|
248
|
+
"ECONNRESET",
|
|
249
|
+
"ECONNREFUSED",
|
|
250
|
+
"ENETUNREACH",
|
|
251
|
+
"ETIMEDOUT",
|
|
252
|
+
"NETWORK_ERROR",
|
|
253
|
+
"ABORT_ERR"
|
|
254
|
+
].includes(String(raw.code)) ? String(raw.code) : void 0;
|
|
255
|
+
const rawStatus = raw.status ?? record(raw.details).status;
|
|
256
|
+
const status = typeof rawStatus === "number" && Number.isInteger(rawStatus) && rawStatus >= 100 && rawStatus <= 599 ? rawStatus : void 0;
|
|
257
|
+
const context = options.context === void 0 ? void 0 : {
|
|
258
|
+
...options.context.region === "global" || options.context.region === "china" ? { region: options.context.region } : {},
|
|
259
|
+
...typeof options.context.sessionId === "string" ? { sessionId: options.context.sessionId } : {},
|
|
260
|
+
...typeof options.context.modelId === "string" ? { modelId: options.context.modelId } : {},
|
|
261
|
+
...typeof options.context.tierKey === "string" ? { tierKey: options.context.tierKey } : {}
|
|
262
|
+
};
|
|
263
|
+
const result = {
|
|
264
|
+
cause,
|
|
265
|
+
stage,
|
|
266
|
+
completedStages,
|
|
267
|
+
...outcome ? { outcome } : {},
|
|
268
|
+
diagnostic: {
|
|
269
|
+
operation,
|
|
270
|
+
stage,
|
|
271
|
+
cause,
|
|
272
|
+
...outcome ? { outcome } : {},
|
|
273
|
+
...rpcCode ? { rpcCode } : {},
|
|
274
|
+
...code ? { code } : {},
|
|
275
|
+
...status ? { status } : {},
|
|
276
|
+
completedStages,
|
|
277
|
+
...context ? { context } : {}
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
diagnoseOperation(result);
|
|
281
|
+
return {
|
|
282
|
+
ok: false,
|
|
283
|
+
error: result
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
/** Concise presentation uses completion evidence; diagnostic text never reaches the UI. */
|
|
287
|
+
function operationNotice(error, fallback) {
|
|
288
|
+
if (error.outcome === "partial") return "patSavedSelectionFailed";
|
|
289
|
+
if (error.outcome === "unknown") return "operationOutcomeUnknown";
|
|
290
|
+
return fallback;
|
|
291
|
+
}
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region src/client/settings-operations.ts
|
|
294
|
+
/** Client storage adapters; host/Qoder protocol access remains in the existing RPC. */
|
|
295
|
+
function createSettingsOperations(credentials, form, authorization, rpc) {
|
|
296
|
+
const rejectedOutcome = (error) => {
|
|
297
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "INVALID_REQUEST" || [
|
|
298
|
+
"permission-denied",
|
|
299
|
+
"unauthenticated",
|
|
300
|
+
"persistence"
|
|
301
|
+
].includes(operationCause(error)) ? "not-completed" : "unknown";
|
|
302
|
+
};
|
|
303
|
+
const describePat = async () => {
|
|
304
|
+
try {
|
|
305
|
+
const response = await credentials.describe([qoderCredentialRef]);
|
|
306
|
+
if (!response.ok) return failure("describePat", "read-pat", response.error);
|
|
307
|
+
const value = response.value[qoderCredentialRef];
|
|
308
|
+
return success(value ?? {
|
|
309
|
+
configured: false,
|
|
310
|
+
writable: false
|
|
311
|
+
});
|
|
312
|
+
} catch (error) {
|
|
313
|
+
return failure("describePat", "read-pat", error);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
const setting = async (operation, write) => {
|
|
317
|
+
try {
|
|
318
|
+
if (await write() !== false) return success(void 0);
|
|
319
|
+
return failure(operation, "persist-settings", void 0, { mutation: true });
|
|
320
|
+
} catch (error) {
|
|
321
|
+
return failure(operation, "persist-settings", error, { mutation: true });
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
const readTier = (scope) => rpc.call("readSessionTier", scope);
|
|
325
|
+
return {
|
|
326
|
+
describePat,
|
|
327
|
+
describe: async () => {
|
|
328
|
+
try {
|
|
329
|
+
const result = await authorization.read(regionOf(form.getSnapshot().value));
|
|
330
|
+
if (!result.ok) return failure("describe", "read-authorization", result.error);
|
|
331
|
+
const authorizationView = result.value;
|
|
332
|
+
const authorizationConfigured = authorizationView.configured && !authorizationView.expired;
|
|
333
|
+
if (authorizationView.method !== "pat") {
|
|
334
|
+
const browserSubscriberId = authorizationView.method === "browser" ? authorizationView.profile?.id : void 0;
|
|
335
|
+
return success({
|
|
336
|
+
configured: authorizationConfigured,
|
|
337
|
+
writable: authorizationView.writable,
|
|
338
|
+
...browserSubscriberId ? { browserSubscriberId } : {}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
const pat = await describePat();
|
|
342
|
+
if (!pat.ok) return pat;
|
|
343
|
+
return success({
|
|
344
|
+
configured: authorizationConfigured && pat.value.configured && !isEnvironmentCredentialSource(pat.value.source),
|
|
345
|
+
...pat.value.source === void 0 ? {} : { source: pat.value.source },
|
|
346
|
+
writable: pat.value.writable
|
|
347
|
+
});
|
|
348
|
+
} catch (error) {
|
|
349
|
+
return failure("describe", "read-authorization", error);
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
store: async (value) => {
|
|
353
|
+
let region;
|
|
354
|
+
let saved = false;
|
|
355
|
+
let stage = "read-settings";
|
|
356
|
+
try {
|
|
357
|
+
region = regionOf(form.getSnapshot().value);
|
|
358
|
+
stage = "persist-pat";
|
|
359
|
+
const response = await credentials.set(qoderCredentialRef, value.trim());
|
|
360
|
+
if (!response.ok) return failure("storePat", stage, response.error, {
|
|
361
|
+
mutation: true,
|
|
362
|
+
outcome: rejectedOutcome(response.error),
|
|
363
|
+
context: { region }
|
|
364
|
+
});
|
|
365
|
+
saved = true;
|
|
366
|
+
stage = "read-authorization";
|
|
367
|
+
const current = await authorization.read(region);
|
|
368
|
+
if (!current.ok) return failure("storePat", stage, current.error, {
|
|
369
|
+
mutation: true,
|
|
370
|
+
completedStages: ["persist-pat"]
|
|
371
|
+
});
|
|
372
|
+
if (current.value.method === "pat") return success(void 0);
|
|
373
|
+
stage = "select-authorization";
|
|
374
|
+
let selectionError;
|
|
375
|
+
try {
|
|
376
|
+
const selected = await authorization.select(region, "pat");
|
|
377
|
+
if (selected.ok) return success(void 0);
|
|
378
|
+
selectionError = selected.error;
|
|
379
|
+
} catch (error) {
|
|
380
|
+
selectionError = error;
|
|
381
|
+
}
|
|
382
|
+
const reconciled = await authorization.read(region).catch(() => void 0);
|
|
383
|
+
if (reconciled?.ok && reconciled.value.method === "pat") return success(void 0);
|
|
384
|
+
return failure("storePat", stage, selectionError, {
|
|
385
|
+
mutation: true,
|
|
386
|
+
completedStages: ["persist-pat"],
|
|
387
|
+
context: { region }
|
|
388
|
+
});
|
|
389
|
+
} catch (error) {
|
|
390
|
+
return failure("storePat", stage, error, {
|
|
391
|
+
mutation: true,
|
|
392
|
+
completedStages: saved ? ["persist-pat"] : [],
|
|
393
|
+
...stage === "read-settings" ? { outcome: "not-completed" } : {},
|
|
394
|
+
context: { region }
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
remove: async () => {
|
|
399
|
+
let error;
|
|
400
|
+
try {
|
|
401
|
+
const response = await credentials.unset(qoderCredentialRef);
|
|
402
|
+
if (response.ok) return success(void 0);
|
|
403
|
+
error = response.error;
|
|
404
|
+
if (rejectedOutcome(error) === "not-completed") return failure("removePat", "remove-pat", error, {
|
|
405
|
+
mutation: true,
|
|
406
|
+
outcome: "not-completed"
|
|
407
|
+
});
|
|
408
|
+
} catch (caught) {
|
|
409
|
+
error = caught;
|
|
410
|
+
}
|
|
411
|
+
try {
|
|
412
|
+
const response = await credentials.describe([qoderCredentialRef]);
|
|
413
|
+
if (response.ok && response.value["QODER_MANAGED_CREDENTIAL"]?.configured === false) return success(void 0);
|
|
414
|
+
} catch {}
|
|
415
|
+
return failure("removePat", "remove-pat", error, { mutation: true });
|
|
416
|
+
},
|
|
417
|
+
storeModels: (region, models) => setting("storeModels", () => form.mutate([{
|
|
418
|
+
op: "set",
|
|
419
|
+
path: ["modelsByRegion", region],
|
|
420
|
+
value: JSON.parse(JSON.stringify(models))
|
|
421
|
+
}])),
|
|
422
|
+
storeRegion: (region) => setting("storeRegion", () => form.set("region", region)),
|
|
423
|
+
storeWebSearchMode: (mode) => setting("storeWebSearchMode", () => form.set("webSearchMode", mode)),
|
|
424
|
+
storeImageSearchEnabled: (enabled) => setting("storeImageSearchEnabled", () => form.set("imageSearchEnabled", enabled)),
|
|
425
|
+
storeImageGenEnabled: (enabled) => setting("storeImageGenEnabled", () => form.set("imageGenEnabled", enabled)),
|
|
426
|
+
readSessionTier: async (scope) => {
|
|
427
|
+
try {
|
|
428
|
+
const result = await readTier(scope);
|
|
429
|
+
return result.ok ? result : failure("readSessionTier", "read-context-tier", result.error, { context: scope });
|
|
430
|
+
} catch (error) {
|
|
431
|
+
return failure("readSessionTier", "read-context-tier", error, { context: scope });
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
setSessionTier: async (sessionId, modelId, tierKey, region) => {
|
|
435
|
+
const scope = {
|
|
436
|
+
sessionId,
|
|
437
|
+
modelId,
|
|
438
|
+
region
|
|
439
|
+
};
|
|
440
|
+
let error;
|
|
441
|
+
try {
|
|
442
|
+
const result = await rpc.call("sessionTier", {
|
|
443
|
+
...scope,
|
|
444
|
+
tierKey
|
|
445
|
+
});
|
|
446
|
+
if (result.ok) return result;
|
|
447
|
+
error = result.error;
|
|
448
|
+
if (rejectedOutcome(error) === "not-completed") return failure("setSessionTier", "persist-context-tier", error, {
|
|
449
|
+
mutation: true,
|
|
450
|
+
outcome: "not-completed",
|
|
451
|
+
context: {
|
|
452
|
+
...scope,
|
|
453
|
+
tierKey
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
} catch (caught) {
|
|
457
|
+
error = caught;
|
|
458
|
+
}
|
|
459
|
+
try {
|
|
460
|
+
const current = await readTier(scope);
|
|
461
|
+
if (current.ok && current.value.tierKey === tierKey && current.value.sessionId === sessionId && current.value.modelId === modelId && current.value.region === region) return current;
|
|
462
|
+
} catch {}
|
|
463
|
+
return failure("setSessionTier", "persist-context-tier", error, {
|
|
464
|
+
mutation: true,
|
|
465
|
+
context: {
|
|
466
|
+
...scope,
|
|
467
|
+
tierKey
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
//#endregion
|
|
474
|
+
//#region src/client/queue-status.ts
|
|
475
|
+
/** Match DSH's running status clock: whole hours, minutes and seconds. */
|
|
476
|
+
function formatQueueDuration(ms, t) {
|
|
477
|
+
const total = Math.max(0, Math.floor(ms / 1e3));
|
|
478
|
+
const hours = Math.floor(total / 3600);
|
|
479
|
+
const minutes = Math.floor(total / 60) % 60;
|
|
480
|
+
const seconds = total % 60;
|
|
481
|
+
return (hours > 0 ? `${hours}${t("queueHourUnit")}` : "") + (total >= 60 ? `${minutes}${t("queueMinuteUnit")}` : "") + `${seconds}${t("queueSecondUnit")}`;
|
|
482
|
+
}
|
|
483
|
+
function parseQueueSnapshots(value, sessionId) {
|
|
484
|
+
if (!Array.isArray(value) || value.length > 256) throw new Error("Invalid queue snapshots");
|
|
485
|
+
return value.map((item) => {
|
|
486
|
+
if (!item || typeof item !== "object" || item.sessionId !== sessionId || typeof item.callId !== "string" || !item.callId || typeof item.model !== "string" || item.modelName !== void 0 && (typeof item.modelName !== "string" || !item.modelName.trim()) || ![
|
|
487
|
+
"waitElapsedMs",
|
|
488
|
+
"maxWaitMs",
|
|
489
|
+
"updatedAt"
|
|
490
|
+
].every((key) => typeof item[key] === "number" && Number.isFinite(item[key]) && item[key] >= 0) || !["queueCount", "waitTimeMs"].every((key) => item[key] === void 0 || typeof item[key] === "number" && Number.isFinite(item[key]) && item[key] >= 0)) throw new Error("Invalid queue snapshot");
|
|
491
|
+
return item;
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
function watchQueueStatus(rpc, sessionId, visibility, changed, readDismissedRefusalId) {
|
|
495
|
+
let disposed = false;
|
|
496
|
+
let generation = 0;
|
|
497
|
+
let timer;
|
|
498
|
+
let active;
|
|
499
|
+
let items = [];
|
|
500
|
+
const poll = async () => {
|
|
501
|
+
if (disposed || visibility.hidden || active) return;
|
|
502
|
+
const revision = generation;
|
|
503
|
+
const controller = new AbortController();
|
|
504
|
+
active = controller;
|
|
505
|
+
const timeout = setTimeout(() => controller.abort(), 5e3);
|
|
506
|
+
try {
|
|
507
|
+
const dismissedRefusalId = readDismissedRefusalId?.();
|
|
508
|
+
const result = await rpc.call("conversationStatus", {
|
|
509
|
+
sessionId,
|
|
510
|
+
...dismissedRefusalId === void 0 ? {} : { dismissedRefusalId }
|
|
511
|
+
}, controller.signal);
|
|
512
|
+
if (disposed || revision !== generation) return;
|
|
513
|
+
if (!result.ok) throw new Error("Queue status unavailable");
|
|
514
|
+
items = parseQueueSnapshots(result.value.queue, sessionId);
|
|
515
|
+
const { refusalId } = result.value;
|
|
516
|
+
const refused = result.value.refused === true && (refusalId === void 0 || refusalId !== readDismissedRefusalId?.());
|
|
517
|
+
changed({
|
|
518
|
+
items,
|
|
519
|
+
unavailable: false,
|
|
520
|
+
refused,
|
|
521
|
+
...refused && typeof refusalId === "string" ? { refusalId } : {}
|
|
522
|
+
});
|
|
523
|
+
} catch {
|
|
524
|
+
if (!disposed && revision === generation) changed({
|
|
525
|
+
items,
|
|
526
|
+
unavailable: true,
|
|
527
|
+
refused: false
|
|
528
|
+
});
|
|
529
|
+
} finally {
|
|
530
|
+
clearTimeout(timeout);
|
|
531
|
+
if (active === controller) active = void 0;
|
|
532
|
+
if (!disposed && revision === generation && !visibility.hidden) timer = setTimeout(() => {
|
|
533
|
+
poll();
|
|
534
|
+
}, 1e3);
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
const stop = () => {
|
|
538
|
+
generation++;
|
|
539
|
+
clearTimeout(timer);
|
|
540
|
+
active?.abort();
|
|
541
|
+
active = void 0;
|
|
542
|
+
};
|
|
543
|
+
const onVisibility = () => {
|
|
544
|
+
stop();
|
|
545
|
+
if (!visibility.hidden) poll();
|
|
546
|
+
};
|
|
547
|
+
visibility.addEventListener("visibilitychange", onVisibility);
|
|
548
|
+
poll();
|
|
549
|
+
return () => {
|
|
550
|
+
disposed = true;
|
|
551
|
+
stop();
|
|
552
|
+
visibility.removeEventListener("visibilitychange", onVisibility);
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
//#endregion
|
|
556
|
+
//#region \0dsh-css:src/client/QoderQueueStatus.module.css.mjs
|
|
557
|
+
const css$3 = ".kGpW6a_queues{box-sizing:border-box;width:calc(100% - 2 * var(--dsh-composer-side-clearance,16px) - 2 * var(--dsh-composer-dock-inset,8px));max-width:calc(var(--dsh-composer-card-max-width,952px) - 2 * var(--dsh-composer-dock-inset,8px));padding:0 var(--dsh-composer-dock-inset,8px);--dsw-alias-label-shimmer:var(--dsw-alias-label-deep-diving-shimmer);color:var(--dsw-alias-label-deep-diving,#4d6bfe);font-size:var(--dsh-content-font-size-secondary,13px);line-height:calc(22px + var(--dsh-content-font-delta,0px));flex:none;margin:0 auto}.kGpW6a_panel{isolation:isolate;border-radius:var(--dsw-radius-lg,16px);width:100%;padding:2px 0;position:relative;overflow:hidden}.kGpW6a_panel:before{z-index:-1;border-radius:inherit;background:var(--dsw-specific-menu,var(--dsw-alias-bg-layer-1,#242629));backdrop-filter:var(--dsw-menu-backdrop-filter,none);content:\"\";pointer-events:none;position:absolute;inset:0}.kGpW6a_panel:after{border:.5px solid var(--dsw-alias-border-l1,#42454a);border-radius:inherit;content:\"\";pointer-events:none;position:absolute;inset:0}.kGpW6a_row{min-width:0}.kGpW6a_row+.kGpW6a_row{box-shadow:inset 0 1px 0 var(--dsw-alias-border-l1,#42454a)}.kGpW6a_row[data-unavailable]{color:var(--dsw-alias-label-secondary)}.kGpW6a_summary{box-sizing:border-box;cursor:pointer;align-items:center;gap:10px;width:100%;min-width:0;min-height:36px;padding:7px 12px;list-style:none;display:flex}.kGpW6a_summary::-webkit-details-marker{display:none}.kGpW6a_summary:focus-visible{outline-offset:-2px;border-radius:var(--dsw-radius-md,8px);outline:2px solid}.kGpW6a_icon{flex:none;width:14px;height:14px}.kGpW6a_text{font-variant-numeric:tabular-nums;overflow-wrap:anywhere;flex:1;min-width:0}.kGpW6a_chevron{width:6px;height:6px;color:var(--dsw-alias-label-tertiary);border-bottom:1.5px solid;border-right:1.5px solid;flex:none;margin:0 3px 3px;transform:rotate(45deg)}.kGpW6a_row>details[open] .kGpW6a_chevron{margin-bottom:-3px;transform:rotate(225deg)}.kGpW6a_details{color:var(--dsw-alias-label-secondary);flex-wrap:wrap;gap:2px 16px;padding:0 12px 10px 36px;display:flex}.kGpW6a_visuallyHidden{clip-path:inset(50%);white-space:nowrap;width:1px;height:1px;padding:0;position:absolute;overflow:hidden}";
|
|
558
|
+
const tagId$3 = "dsh-subscription-qoder/QoderQueueStatus.module.css";
|
|
559
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$3) + "]") === null) {
|
|
560
|
+
const tag = document.createElement("style");
|
|
561
|
+
tag.dataset.plugin = "dsh-subscription-qoder";
|
|
562
|
+
tag.dataset.pluginCss = tagId$3;
|
|
563
|
+
tag.textContent = css$3;
|
|
564
|
+
document.head.appendChild(tag);
|
|
565
|
+
}
|
|
566
|
+
var QoderQueueStatus_module_css_default = {
|
|
567
|
+
"chevron": "kGpW6a_chevron",
|
|
568
|
+
"details": "kGpW6a_details",
|
|
569
|
+
"icon": "kGpW6a_icon",
|
|
570
|
+
"panel": "kGpW6a_panel",
|
|
571
|
+
"queues": "kGpW6a_queues",
|
|
572
|
+
"row": "kGpW6a_row",
|
|
573
|
+
"summary": "kGpW6a_summary",
|
|
574
|
+
"text": "kGpW6a_text",
|
|
575
|
+
"visuallyHidden": "kGpW6a_visuallyHidden"
|
|
576
|
+
};
|
|
577
|
+
//#endregion
|
|
578
|
+
//#region src/client/QoderQueueStatus.tsx
|
|
579
|
+
function QueueRow({ item, unavailable, t }) {
|
|
580
|
+
const elapsed = Math.min(item.maxWaitMs, item.waitElapsedMs + Math.max(0, Date.now() - item.updatedAt));
|
|
581
|
+
const name = item.modelName ?? item.model;
|
|
582
|
+
const status = unavailable ? t("queueUnavailable") : t("queueWaiting", { model: name });
|
|
583
|
+
const label = unavailable ? status : t("queueRunningFor", {
|
|
584
|
+
model: name,
|
|
585
|
+
duration: formatQueueDuration(elapsed, t)
|
|
586
|
+
});
|
|
587
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
588
|
+
className: QoderQueueStatus_module_css_default.row,
|
|
589
|
+
"data-unavailable": unavailable || void 0,
|
|
590
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
591
|
+
className: QoderQueueStatus_module_css_default.visuallyHidden,
|
|
592
|
+
role: "status",
|
|
593
|
+
"aria-live": "polite",
|
|
594
|
+
"aria-atomic": "true",
|
|
595
|
+
children: status
|
|
596
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("summary", {
|
|
597
|
+
className: QoderQueueStatus_module_css_default.summary,
|
|
598
|
+
"aria-label": status,
|
|
599
|
+
children: [
|
|
600
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconQueueOutlineRegular, {
|
|
601
|
+
className: QoderQueueStatus_module_css_default.icon,
|
|
602
|
+
"aria-hidden": "true"
|
|
603
|
+
}),
|
|
604
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.TextShimmer, {
|
|
605
|
+
active: !unavailable,
|
|
606
|
+
className: QoderQueueStatus_module_css_default.text,
|
|
607
|
+
"aria-hidden": "true",
|
|
608
|
+
children: label
|
|
609
|
+
}),
|
|
610
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
611
|
+
className: QoderQueueStatus_module_css_default.chevron,
|
|
612
|
+
"aria-hidden": "true"
|
|
613
|
+
})
|
|
614
|
+
]
|
|
615
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
616
|
+
className: QoderQueueStatus_module_css_default.details,
|
|
617
|
+
children: [
|
|
618
|
+
item.queueCount !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("queueCount", { count: item.queueCount }) }),
|
|
619
|
+
item.waitTimeMs !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("queueEstimate", { seconds: Math.ceil(item.waitTimeMs / 1e3) }) }),
|
|
620
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("queueBudget", { seconds: Math.ceil(item.maxWaitMs / 1e3) }) }),
|
|
621
|
+
item.serviceAvailable === false && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("queueServiceUnavailable") })
|
|
622
|
+
]
|
|
623
|
+
})] })]
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
/** A provider contribution in DSH's input dock, using its shared process-row primitives. */
|
|
627
|
+
function QoderQueueStatus({ sessionId, rpc, t }) {
|
|
628
|
+
const [view, setView] = (0, react.useState)();
|
|
629
|
+
const dismissed = (0, react.useRef)(void 0);
|
|
630
|
+
const [visible, setVisible] = (0, react.useState)(false);
|
|
631
|
+
(0, react.useEffect)(() => watchQueueStatus(rpc, sessionId, document, (state) => setView({
|
|
632
|
+
sessionId,
|
|
633
|
+
state
|
|
634
|
+
}), () => dismissed.current?.sessionId === sessionId ? dismissed.current.id : void 0), [rpc, sessionId]);
|
|
635
|
+
(0, react.useEffect)(() => {
|
|
636
|
+
const updateVisibility = () => setVisible(!document.hidden);
|
|
637
|
+
updateVisibility();
|
|
638
|
+
document.addEventListener("visibilitychange", updateVisibility);
|
|
639
|
+
return () => document.removeEventListener("visibilitychange", updateVisibility);
|
|
640
|
+
}, []);
|
|
641
|
+
const state = view?.sessionId === sessionId ? view.state : void 0;
|
|
642
|
+
const refusalId = visible ? state?.refusalId : void 0;
|
|
643
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [refusalId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Toast, {
|
|
644
|
+
text: t("modelRefusal"),
|
|
645
|
+
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconWarningOutlineRegular, {}),
|
|
646
|
+
onDone: () => {
|
|
647
|
+
if (document.hidden) return;
|
|
648
|
+
dismissed.current = {
|
|
649
|
+
sessionId,
|
|
650
|
+
id: refusalId
|
|
651
|
+
};
|
|
652
|
+
setView((current) => current?.sessionId === sessionId && current.state.refusalId === refusalId ? {
|
|
653
|
+
sessionId,
|
|
654
|
+
state: {
|
|
655
|
+
...current.state,
|
|
656
|
+
refused: false,
|
|
657
|
+
refusalId: void 0
|
|
658
|
+
}
|
|
659
|
+
} : current);
|
|
660
|
+
}
|
|
661
|
+
}, refusalId), state && state.items.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
662
|
+
className: QoderQueueStatus_module_css_default.queues,
|
|
663
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
664
|
+
className: QoderQueueStatus_module_css_default.panel,
|
|
665
|
+
"aria-label": t("queueTitle"),
|
|
666
|
+
children: state.items.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(QueueRow, {
|
|
667
|
+
item,
|
|
668
|
+
unavailable: state.unavailable,
|
|
669
|
+
t
|
|
670
|
+
}, item.callId))
|
|
671
|
+
})
|
|
672
|
+
})] });
|
|
673
|
+
}
|
|
674
|
+
//#endregion
|
|
675
|
+
//#region src/client/locales.ts
|
|
676
|
+
const zh = {
|
|
677
|
+
patSavedSelectionFailed: "PAT 已保存,但无法确认授权选择。可选择使用已保存的 PAT 重试。",
|
|
678
|
+
operationOutcomeUnknown: "无法确认更改结果,请先核对当前状态再重试。",
|
|
679
|
+
accountConnectionTitle: "Qoder 账号",
|
|
680
|
+
signInDescription: "登录 Qoder,使用当前区域的订阅和模型。",
|
|
681
|
+
manageAccount: "管理账号",
|
|
682
|
+
manageCredential: "管理凭据",
|
|
683
|
+
changeAccount: "更换账号",
|
|
684
|
+
editPat: "编辑 PAT",
|
|
685
|
+
patActive: "正在使用 PAT",
|
|
686
|
+
saveAndUsePat: "保存并使用 PAT",
|
|
687
|
+
useSavedPat: "使用已保存的 PAT",
|
|
688
|
+
signInAgain: "重新登录",
|
|
689
|
+
reopenLogin: "重新打开官网",
|
|
690
|
+
loginLinkCopied: "链接已复制",
|
|
691
|
+
loginTimeRemaining: "链接剩余有效时间:{seconds} 秒",
|
|
692
|
+
regionChanged: "已切换服务区域;原区域如有未完成的登录,已取消。",
|
|
693
|
+
regionChangeFailed: "服务区域切换失败,请重试。",
|
|
694
|
+
browserRejected: "Qoder 未完成授权,请重新登录。",
|
|
695
|
+
browserStorageFailed: "官网授权已完成,但凭据保存失败。请检查存储后重新登录。",
|
|
696
|
+
authorizationConnectionFailed: "暂时无法连接或读取登录状态,请稍后重试。",
|
|
697
|
+
patSaveFailed: "PAT 保存或启用失败,请重试。",
|
|
698
|
+
browserRemoveFailed: "浏览器授权移除失败,请检查凭据存储是否可写后重试。",
|
|
699
|
+
browserLoginTitle: "Qoder 官网登录",
|
|
700
|
+
browserMethod: "浏览器授权",
|
|
701
|
+
savedBrowserAccount: "已保存的浏览器账号",
|
|
702
|
+
patMethod: "PAT 鉴权",
|
|
703
|
+
signedOut: "未连接",
|
|
704
|
+
sharedAuthorization: "当前区域的账号由所有连接此 DSH 实例的客户端共享。",
|
|
705
|
+
signInQoder: "通过 Qoder 登录",
|
|
706
|
+
signOutQoder: "移除浏览器授权",
|
|
707
|
+
usePat: "使用 PAT",
|
|
708
|
+
useBrowser: "使用已保存的浏览器授权",
|
|
709
|
+
cancelLogin: "取消登录",
|
|
710
|
+
openLogin: "打开登录页面",
|
|
711
|
+
copyLogin: "复制登录链接",
|
|
712
|
+
copyLoginFailed: "无法复制,请使用“打开登录页面”。",
|
|
713
|
+
browserWaiting: "等待在 Qoder 官网完成验证与授权…",
|
|
714
|
+
browserSaving: "正在保存授权…",
|
|
715
|
+
browserComplete: "已登录。",
|
|
716
|
+
browserCancelled: "登录已取消。",
|
|
717
|
+
browserTimeout: "登录链接已过期,请重新发起登录。",
|
|
718
|
+
browserFailed: "登录未完成,或授权保存失败。请检查账号状态后重试。",
|
|
719
|
+
browserExpired: "浏览器授权已失效,请重新登录。",
|
|
720
|
+
browserUnsaved: "续期凭据尚未保存,重启后可能需要重新登录;下次使用时将重试保存。",
|
|
721
|
+
browserOperationFailed: "无法更新登录状态,请重试。",
|
|
722
|
+
queueTitle: "Qoder 模型排队",
|
|
723
|
+
modelRefusal: "Qoder 拒绝生成此内容。",
|
|
724
|
+
queueWaiting: "{model} 正在排队",
|
|
725
|
+
queueRunningFor: "{model} 正在排队,用时 {duration} ···",
|
|
726
|
+
queueHourUnit: "小时",
|
|
727
|
+
queueMinuteUnit: "分",
|
|
728
|
+
queueSecondUnit: "秒",
|
|
729
|
+
queueCount: "排队数量:{count}",
|
|
730
|
+
queueEstimate: "预计等待 {seconds} 秒",
|
|
731
|
+
queueElapsed: "已等待 {seconds} 秒",
|
|
732
|
+
queueUnavailable: "Qoder 排队状态暂不可用",
|
|
733
|
+
queueServiceUnavailable: "服务暂不可用,继续等待",
|
|
734
|
+
queueBudget: "等待上限 {seconds} 秒",
|
|
735
|
+
nav: "Qoder",
|
|
736
|
+
title: "Qoder 凭据",
|
|
737
|
+
configured: "已配置",
|
|
738
|
+
missing: "未配置",
|
|
739
|
+
loading: "正在读取凭据状态…",
|
|
740
|
+
loadFailed: "无法读取凭据状态。",
|
|
741
|
+
retry: "重试",
|
|
742
|
+
edit: "编辑",
|
|
743
|
+
cancel: "取消",
|
|
744
|
+
regionLabel: "服务区域",
|
|
745
|
+
regionGlobal: "国际版 (Global)",
|
|
746
|
+
regionChina: "中国区 (CN)",
|
|
747
|
+
regionHint: "请确保 PAT 与所选服务区域匹配。",
|
|
748
|
+
tokenLabel: "Personal Access Token (PAT)",
|
|
749
|
+
tokenPlaceholder: "输入新的 Personal Access Token",
|
|
750
|
+
configuredHint: "已配置——输入新值可替换",
|
|
751
|
+
readOnly: "当前凭据存储不可写。",
|
|
752
|
+
save: "保存",
|
|
753
|
+
saving: "正在保存…",
|
|
754
|
+
saved: "Qoder 设置已保存。",
|
|
755
|
+
saveFailed: "Qoder 设置保存失败,请重试。",
|
|
756
|
+
remove: "删除",
|
|
757
|
+
removing: "正在删除…",
|
|
758
|
+
removeFailed: "凭据删除失败,请重试。",
|
|
759
|
+
confirmRemove: "删除已保存的 Qoder 凭据?删除后,新的模型请求将无法运行。",
|
|
760
|
+
customized: "自定义设置",
|
|
761
|
+
modelsTitle: "模型目录",
|
|
762
|
+
modelsLoading: "正在读取模型设置…",
|
|
763
|
+
modelsUnavailable: "当前无法读取或保存模型设置。",
|
|
764
|
+
modelsEnabled: "已启用 {count} 个模型",
|
|
765
|
+
modelsFetch: "获取可用模型",
|
|
766
|
+
modelsUpdating: "正在更新模型目录…",
|
|
767
|
+
modelWaitingForCatalog: "等待目录更新",
|
|
768
|
+
modelsFetchFailed: "无法获取可用模型。",
|
|
769
|
+
modelsUpdateNotSaved: "模型目录更新未保存。",
|
|
770
|
+
catalogTierNotSaved: "所选上下文档位已不可用,未保存该档位。",
|
|
771
|
+
modelMissingFromCatalog: "未列入目录",
|
|
772
|
+
modelDelete: "删除",
|
|
773
|
+
modelRateFree: "免费",
|
|
774
|
+
modelRatePromotionLabel: ",原倍率 {original},当前倍率 {current}",
|
|
775
|
+
contextTierLabel: "上下文",
|
|
776
|
+
contextTierDefaultSuffix: "(默认)",
|
|
777
|
+
contextSelectFailed: "上下文切换失败,请重试。",
|
|
778
|
+
contextSelectTitle: "选择上下文大小",
|
|
779
|
+
contextSelectMenuHeader: "上下文容量",
|
|
780
|
+
accountTitle: "Qoder",
|
|
781
|
+
accountLoading: "正在读取账号与额度…",
|
|
782
|
+
accountFailed: "无法读取账号信息与额度。",
|
|
783
|
+
accountCredentialHint: "请先在“模型”设置中登录 Qoder 或选择已配置的 PAT。",
|
|
784
|
+
refresh: "刷新",
|
|
785
|
+
refreshing: "正在刷新…",
|
|
786
|
+
userQuotaTitle: "订阅额度",
|
|
787
|
+
orgResourceTitle: "组织资源包",
|
|
788
|
+
addOnQuotaTitle: "增值额度",
|
|
789
|
+
dedicatedResourceTitle: "专属资源包",
|
|
790
|
+
dedicatedResourceExpiresAt: "有效期至:{value}",
|
|
791
|
+
quotaRemaining: "剩余 {value} {unit}",
|
|
792
|
+
quotaUsed: "已用 {used} / {total} {unit}",
|
|
793
|
+
quotaUsedOnly: "已用 {used} {unit}",
|
|
794
|
+
quotaTotal: "总额 {total} {unit}",
|
|
795
|
+
quotaStatusExhausted: "已用尽",
|
|
796
|
+
quotaStatusExpired: "已过期",
|
|
797
|
+
quotaStatusSuspended: "已暂停",
|
|
798
|
+
quotaStatusAvailable: "可用",
|
|
799
|
+
quotaStatusUnavailable: "不可用",
|
|
800
|
+
quotaModelScope: "适用于指定模型",
|
|
801
|
+
quotaModelFamilies: "模型系列:{value}",
|
|
802
|
+
quotaModelKeys: "模型标识:{value}",
|
|
803
|
+
accountRefreshFailed: "额度刷新失败。",
|
|
804
|
+
accountLastUpdated: "上次更新:{value}",
|
|
805
|
+
noQuota: "暂无额度信息",
|
|
806
|
+
quotaExceeded: "Qoder 额度已达上限。",
|
|
807
|
+
plan: "套餐计划",
|
|
808
|
+
planExpiresAt: "有效期至:{value}",
|
|
809
|
+
organization: "组织:{name}",
|
|
810
|
+
accountSuspended: "当前账号或组织已被暂停/冻结。",
|
|
811
|
+
featuresTitle: "功能设置",
|
|
812
|
+
imageSearchLabel: "图片搜索",
|
|
813
|
+
imageSearchHint: "允许通过 Qoder 搜索图片。",
|
|
814
|
+
imageGenLabel: "图片生成",
|
|
815
|
+
imageGenHint: "允许通过 Qoder 生成图片。",
|
|
816
|
+
featureSaveFailed: "功能设置保存失败,请重试。",
|
|
817
|
+
searchModeLabel: "联网搜索模式",
|
|
818
|
+
searchModeAuto: "自动",
|
|
819
|
+
searchModeAlways: "始终使用 Qoder",
|
|
820
|
+
searchModeDisabled: "关闭",
|
|
821
|
+
searchModeHint: "自动模式下,使用 Qoder 模型时通过 Qoder 联网搜索,使用其他模型时交由当前搜索提供方处理。关闭后不提供 Qoder 联网搜索。"
|
|
822
|
+
};
|
|
823
|
+
const en = {
|
|
824
|
+
patSavedSelectionFailed: "PAT saved. Authorization selection could not be confirmed. Use the saved PAT to retry.",
|
|
825
|
+
operationOutcomeUnknown: "Could not confirm the change. Check the current state before retrying.",
|
|
826
|
+
accountConnectionTitle: "Qoder account",
|
|
827
|
+
signInDescription: "Sign in to use your subscription and models for this region.",
|
|
828
|
+
manageAccount: "Manage account",
|
|
829
|
+
manageCredential: "Manage credentials",
|
|
830
|
+
changeAccount: "Change account",
|
|
831
|
+
editPat: "Edit PAT",
|
|
832
|
+
patActive: "Using PAT",
|
|
833
|
+
saveAndUsePat: "Save and use PAT",
|
|
834
|
+
useSavedPat: "Use saved PAT",
|
|
835
|
+
signInAgain: "Sign in again",
|
|
836
|
+
reopenLogin: "Reopen Qoder website",
|
|
837
|
+
loginLinkCopied: "Link copied",
|
|
838
|
+
loginTimeRemaining: "Link expires in {seconds} seconds",
|
|
839
|
+
regionChanged: "Region changed; any unfinished sign-in for the previous region was cancelled.",
|
|
840
|
+
regionChangeFailed: "Could not change region. Please retry.",
|
|
841
|
+
browserRejected: "Qoder authorization was not completed. Sign in again.",
|
|
842
|
+
browserStorageFailed: "Website authorization completed, but credentials could not be saved. Check storage and sign in again.",
|
|
843
|
+
authorizationConnectionFailed: "Could not connect or read sign-in status. Please retry shortly.",
|
|
844
|
+
patSaveFailed: "Could not save or activate the PAT. Please retry.",
|
|
845
|
+
browserRemoveFailed: "Could not remove browser authorization. Check that credential storage is writable and retry.",
|
|
846
|
+
browserLoginTitle: "Qoder website sign-in",
|
|
847
|
+
browserMethod: "Browser authorization",
|
|
848
|
+
savedBrowserAccount: "Saved browser account",
|
|
849
|
+
patMethod: "PAT authentication",
|
|
850
|
+
signedOut: "Disconnected",
|
|
851
|
+
sharedAuthorization: "The account for this region is shared by all clients connected to this DSH instance.",
|
|
852
|
+
signInQoder: "Sign in with Qoder",
|
|
853
|
+
signOutQoder: "Remove browser authorization",
|
|
854
|
+
usePat: "Use PAT",
|
|
855
|
+
useBrowser: "Use saved browser authorization",
|
|
856
|
+
cancelLogin: "Cancel sign-in",
|
|
857
|
+
openLogin: "Open sign-in page",
|
|
858
|
+
copyLogin: "Copy sign-in link",
|
|
859
|
+
copyLoginFailed: "Could not copy. Use Open sign-in page.",
|
|
860
|
+
browserWaiting: "Complete verification and authorization on the Qoder website…",
|
|
861
|
+
browserSaving: "Saving authorization…",
|
|
862
|
+
browserComplete: "Signed in.",
|
|
863
|
+
browserCancelled: "Sign-in cancelled.",
|
|
864
|
+
browserTimeout: "Sign-in link expired. Start a new sign-in.",
|
|
865
|
+
browserFailed: "Sign-in or saving authorization failed. Check account status and retry.",
|
|
866
|
+
browserExpired: "Browser authorization expired. Sign in again.",
|
|
867
|
+
browserUnsaved: "Renewed credentials have not been saved. Restarting may require sign-in; saving will be retried on next use.",
|
|
868
|
+
browserOperationFailed: "Could not update sign-in status. Please retry.",
|
|
869
|
+
queueTitle: "Qoder model queue",
|
|
870
|
+
modelRefusal: "Qoder refused to generate this content.",
|
|
871
|
+
queueWaiting: "{model} is queued",
|
|
872
|
+
queueRunningFor: "{model} queued for {duration} ···",
|
|
873
|
+
queueHourUnit: "h",
|
|
874
|
+
queueMinuteUnit: "m",
|
|
875
|
+
queueSecondUnit: "s",
|
|
876
|
+
queueCount: "Queue count: {count}",
|
|
877
|
+
queueEstimate: "Estimated wait: {seconds}s",
|
|
878
|
+
queueElapsed: "Waited {seconds}s",
|
|
879
|
+
queueUnavailable: "Qoder queue status is temporarily unavailable",
|
|
880
|
+
queueServiceUnavailable: "Service unavailable; waiting",
|
|
881
|
+
queueBudget: "Wait limit: {seconds}s",
|
|
882
|
+
nav: "Qoder",
|
|
883
|
+
title: "Qoder credential",
|
|
884
|
+
configured: "Configured",
|
|
885
|
+
missing: "Not configured",
|
|
886
|
+
loading: "Reading credential status…",
|
|
887
|
+
loadFailed: "Could not read credential status.",
|
|
888
|
+
retry: "Retry",
|
|
889
|
+
edit: "Edit",
|
|
890
|
+
cancel: "Cancel",
|
|
891
|
+
regionLabel: "Service Region",
|
|
892
|
+
regionGlobal: "Global",
|
|
893
|
+
regionChina: "China (CN)",
|
|
894
|
+
regionHint: "Ensure your PAT matches the selected service region.",
|
|
895
|
+
tokenLabel: "Personal Access Token (PAT)",
|
|
896
|
+
tokenPlaceholder: "Enter a new Personal Access Token",
|
|
897
|
+
configuredHint: "Configured — enter a new value to replace",
|
|
898
|
+
readOnly: "The current credential store is read-only.",
|
|
899
|
+
save: "Save",
|
|
900
|
+
saving: "Saving…",
|
|
901
|
+
saved: "Qoder settings saved.",
|
|
902
|
+
saveFailed: "Could not save the Qoder settings. Try again.",
|
|
903
|
+
remove: "Remove",
|
|
904
|
+
removing: "Removing…",
|
|
905
|
+
removeFailed: "Could not remove the credential. Try again.",
|
|
906
|
+
confirmRemove: "Remove the stored Qoder credential? New model requests will stop working.",
|
|
907
|
+
customized: "Custom settings",
|
|
908
|
+
modelsTitle: "Model catalog",
|
|
909
|
+
modelsLoading: "Reading model settings…",
|
|
910
|
+
modelsUnavailable: "Model settings cannot currently be read or saved.",
|
|
911
|
+
modelsEnabled: "{count} models enabled",
|
|
912
|
+
modelsFetch: "Fetch available models",
|
|
913
|
+
modelsUpdating: "Updating model catalog…",
|
|
914
|
+
modelWaitingForCatalog: "Waiting for catalog refresh",
|
|
915
|
+
modelsFetchFailed: "Could not fetch available models.",
|
|
916
|
+
modelsUpdateNotSaved: "The model catalog update was not saved.",
|
|
917
|
+
catalogTierNotSaved: "The selected context tier is unavailable and was not saved.",
|
|
918
|
+
modelMissingFromCatalog: "Not listed in the catalog",
|
|
919
|
+
modelDelete: "Delete",
|
|
920
|
+
modelRateFree: "Free",
|
|
921
|
+
modelRatePromotionLabel: ", original rate {original}, current rate {current}",
|
|
922
|
+
contextTierLabel: "Context",
|
|
923
|
+
contextTierDefaultSuffix: " (default)",
|
|
924
|
+
contextSelectFailed: "Could not change the context window. Please retry.",
|
|
925
|
+
contextSelectTitle: "Select context window size",
|
|
926
|
+
contextSelectMenuHeader: "Context Capacity",
|
|
927
|
+
accountTitle: "Qoder",
|
|
928
|
+
accountLoading: "Reading account and quota…",
|
|
929
|
+
accountFailed: "Could not read account details or quota.",
|
|
930
|
+
accountCredentialHint: "Sign in to Qoder or select a configured PAT in Models settings first.",
|
|
931
|
+
refresh: "Refresh",
|
|
932
|
+
refreshing: "Refreshing…",
|
|
933
|
+
userQuotaTitle: "Subscription Credits",
|
|
934
|
+
orgResourceTitle: "Org Resource Package",
|
|
935
|
+
addOnQuotaTitle: "Add-on Credits",
|
|
936
|
+
dedicatedResourceTitle: "Dedicated Resource Package",
|
|
937
|
+
dedicatedResourceExpiresAt: "Expires at: {value}",
|
|
938
|
+
quotaRemaining: "{value} {unit} remaining",
|
|
939
|
+
quotaUsed: "Used {used} / {total} {unit}",
|
|
940
|
+
quotaUsedOnly: "Used {used} {unit}",
|
|
941
|
+
quotaTotal: "Total {total} {unit}",
|
|
942
|
+
quotaStatusExhausted: "Exhausted",
|
|
943
|
+
quotaStatusExpired: "Expired",
|
|
944
|
+
quotaStatusSuspended: "Suspended",
|
|
945
|
+
quotaStatusAvailable: "Available",
|
|
946
|
+
quotaStatusUnavailable: "Unavailable",
|
|
947
|
+
quotaModelScope: "Applies to specific models",
|
|
948
|
+
quotaModelFamilies: "Model families: {value}",
|
|
949
|
+
quotaModelKeys: "Model keys: {value}",
|
|
950
|
+
accountRefreshFailed: "Could not refresh quota.",
|
|
951
|
+
accountLastUpdated: "Last updated: {value}",
|
|
952
|
+
noQuota: "No quota metrics available",
|
|
953
|
+
quotaExceeded: "Qoder reports that the quota limit has been reached.",
|
|
954
|
+
plan: "Plan",
|
|
955
|
+
planExpiresAt: "Expires at: {value}",
|
|
956
|
+
organization: "Org: {name}",
|
|
957
|
+
accountSuspended: "Account or organization is currently suspended.",
|
|
958
|
+
featuresTitle: "Features",
|
|
959
|
+
imageSearchLabel: "Image search",
|
|
960
|
+
imageSearchHint: "Allow image searches through Qoder.",
|
|
961
|
+
imageGenLabel: "Image generation",
|
|
962
|
+
imageGenHint: "Allow image generation through Qoder.",
|
|
963
|
+
featureSaveFailed: "Failed to save the feature setting. Please try again.",
|
|
964
|
+
searchModeLabel: "Web Search Mode",
|
|
965
|
+
searchModeAuto: "Auto",
|
|
966
|
+
searchModeAlways: "Always use Qoder",
|
|
967
|
+
searchModeDisabled: "Disabled",
|
|
968
|
+
searchModeHint: "In auto mode, searches route to Qoder when using Qoder models, and fall back to ambient providers otherwise."
|
|
969
|
+
};
|
|
970
|
+
/**
|
|
971
|
+
* Compare one provider language tag against the requested locale.
|
|
972
|
+
*
|
|
973
|
+
* `prefix` additionally accepts a shared primary subtag, which is what lets the
|
|
974
|
+
* built-in `zh`/`en` ids reach the provider's `zh-CN`/`en-US` keys.
|
|
975
|
+
*/
|
|
976
|
+
function localeMatches(tag, requested, prefix) {
|
|
977
|
+
const normalized = tag.trim().toLowerCase();
|
|
978
|
+
if (normalized === requested) return true;
|
|
979
|
+
if (!prefix) return false;
|
|
980
|
+
const primary = requested.slice(0, requested.indexOf("-") < 0 ? requested.length : requested.indexOf("-"));
|
|
981
|
+
return primary.length > 0 && normalized.split("-")[0] === primary;
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* Return the first provider translation whose language tag matches the request.
|
|
985
|
+
*
|
|
986
|
+
* `prefix` decides whether a shared primary subtag counts as a match; blank
|
|
987
|
+
* translations are skipped so they cannot shadow a later usable one.
|
|
988
|
+
*/
|
|
989
|
+
function pickLocalizedValue(values, requested, prefix) {
|
|
990
|
+
for (const [tag, value] of Object.entries(values)) {
|
|
991
|
+
if (!localeMatches(tag, requested, prefix)) continue;
|
|
992
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
993
|
+
if (text.length > 0) return text;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* Resolve provider copy for the active UI locale.
|
|
998
|
+
*
|
|
999
|
+
* Order: exact language tag, then a shared primary subtag, then the provider's
|
|
1000
|
+
* language-neutral fallback, then any translation at all. The client owns this
|
|
1001
|
+
* choice because only it knows the locale the user is reading.
|
|
1002
|
+
*/
|
|
1003
|
+
function resolveLocalizedText(text, locale) {
|
|
1004
|
+
if (!text) return void 0;
|
|
1005
|
+
const values = text.values ?? {};
|
|
1006
|
+
const requested = typeof locale === "string" ? locale.trim().toLowerCase() : "";
|
|
1007
|
+
if (requested.length > 0) {
|
|
1008
|
+
const exact = pickLocalizedValue(values, requested, false);
|
|
1009
|
+
if (exact !== void 0) return exact;
|
|
1010
|
+
const related = pickLocalizedValue(values, requested, true);
|
|
1011
|
+
if (related !== void 0) return related;
|
|
1012
|
+
}
|
|
1013
|
+
const fallback = typeof text.fallback === "string" ? text.fallback.trim() : "";
|
|
1014
|
+
if (fallback.length > 0) return fallback;
|
|
1015
|
+
for (const value of Object.values(values)) {
|
|
1016
|
+
const candidate = typeof value === "string" ? value.trim() : "";
|
|
1017
|
+
if (candidate.length > 0) return candidate;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
//#endregion
|
|
1021
|
+
//#region src/dsh/provider.ts
|
|
1022
|
+
/** DSH model provider route, matching the plugin package name. */
|
|
1023
|
+
const QODER_PROVIDER_ID = "dsh-provider-qoder";
|
|
1024
|
+
//#endregion
|
|
1025
|
+
//#region \0dsh-css:src/client/QoderModelLabel.module.css.mjs
|
|
1026
|
+
const css$2 = ".xM38QW_label{vertical-align:baseline;white-space:nowrap;align-items:center;gap:4px;max-width:100%;display:inline-flex}.xM38QW_name{text-overflow:ellipsis;min-width:0;overflow:hidden}.xM38QW_badge{flex:none}.xM38QW_visuallyHidden{clip-path:inset(50%);white-space:nowrap;width:1px;height:1px;padding:0;position:absolute;overflow:hidden}";
|
|
1027
|
+
const tagId$2 = "dsh-subscription-qoder/QoderModelLabel.module.css";
|
|
1028
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$2) + "]") === null) {
|
|
1029
|
+
const tag = document.createElement("style");
|
|
1030
|
+
tag.dataset.plugin = "dsh-subscription-qoder";
|
|
1031
|
+
tag.dataset.pluginCss = tagId$2;
|
|
1032
|
+
tag.textContent = css$2;
|
|
1033
|
+
document.head.appendChild(tag);
|
|
1034
|
+
}
|
|
1035
|
+
var QoderModelLabel_module_css_default = {
|
|
1036
|
+
"badge": "xM38QW_badge",
|
|
1037
|
+
"label": "xM38QW_label",
|
|
1038
|
+
"name": "xM38QW_name",
|
|
1039
|
+
"visuallyHidden": "xM38QW_visuallyHidden"
|
|
1040
|
+
};
|
|
1041
|
+
//#endregion
|
|
1042
|
+
//#region src/client/QoderModelLabel.tsx
|
|
1043
|
+
function QoderModelLabel({ provider, model, placement, rates, t, resolveBadgeText }) {
|
|
1044
|
+
if (provider.id === "dsh-provider-qoder") return placement === "option" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(QoderModelOption, {
|
|
1045
|
+
model,
|
|
1046
|
+
rates,
|
|
1047
|
+
t
|
|
1048
|
+
}) : model.name;
|
|
1049
|
+
if (!model.badge) return model.name;
|
|
1050
|
+
const badge = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
|
|
1051
|
+
className: QoderModelLabel_module_css_default.badge,
|
|
1052
|
+
tone: model.badge.tone,
|
|
1053
|
+
children: resolveBadgeText(model.badge.text)
|
|
1054
|
+
});
|
|
1055
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1056
|
+
className: QoderModelLabel_module_css_default.label,
|
|
1057
|
+
children: [
|
|
1058
|
+
placement === "trigger" ? badge : null,
|
|
1059
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1060
|
+
className: QoderModelLabel_module_css_default.name,
|
|
1061
|
+
children: model.name
|
|
1062
|
+
}),
|
|
1063
|
+
placement === "trigger" ? null : badge
|
|
1064
|
+
]
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
function QoderModelOption({ model, rates, t }) {
|
|
1068
|
+
return renderQoderModelRate((0, react.useSyncExternalStore)(rates.subscribe, rates.getSnapshot).get(model.id), t, model.name);
|
|
1069
|
+
}
|
|
1070
|
+
function renderQoderModelRate(rate, t, name) {
|
|
1071
|
+
const price = rate?.priceFactor ?? (rate?.isFree ? 0 : void 0);
|
|
1072
|
+
if (price === void 0) return name ?? null;
|
|
1073
|
+
if (price === 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1074
|
+
name,
|
|
1075
|
+
" · ",
|
|
1076
|
+
t("modelRateFree")
|
|
1077
|
+
] });
|
|
1078
|
+
const current = `${formatRateFactor(price)}×`;
|
|
1079
|
+
const original = rate?.originalPriceFactor;
|
|
1080
|
+
if (original === void 0 || original <= price) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1081
|
+
name,
|
|
1082
|
+
" · ",
|
|
1083
|
+
current
|
|
1084
|
+
] });
|
|
1085
|
+
const originalRate = `${formatRateFactor(original)}×`;
|
|
1086
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1087
|
+
className: QoderModelLabel_module_css_default.label,
|
|
1088
|
+
children: [
|
|
1089
|
+
name === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1090
|
+
className: QoderModelLabel_module_css_default.name,
|
|
1091
|
+
children: name
|
|
1092
|
+
}),
|
|
1093
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1094
|
+
"aria-hidden": "true",
|
|
1095
|
+
className: QoderModelLabel_module_css_default.label,
|
|
1096
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: ["· ", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("del", { children: originalRate })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
|
|
1097
|
+
className: QoderModelLabel_module_css_default.badge,
|
|
1098
|
+
tone: "success",
|
|
1099
|
+
children: current
|
|
1100
|
+
})]
|
|
1101
|
+
}),
|
|
1102
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1103
|
+
className: QoderModelLabel_module_css_default.visuallyHidden,
|
|
1104
|
+
children: t("modelRatePromotionLabel", {
|
|
1105
|
+
original: originalRate,
|
|
1106
|
+
current
|
|
1107
|
+
})
|
|
1108
|
+
})
|
|
1109
|
+
]
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
//#endregion
|
|
1113
|
+
//#region src/client/model-catalog-editor.ts
|
|
1114
|
+
const editDebounceMs = 2e3;
|
|
1115
|
+
const maxEditDelayMs = 5e3;
|
|
1116
|
+
const editRetryDelays = [
|
|
1117
|
+
150,
|
|
1118
|
+
300,
|
|
1119
|
+
600,
|
|
1120
|
+
1200,
|
|
1121
|
+
2400
|
|
1122
|
+
];
|
|
1123
|
+
function hasChanges(change) {
|
|
1124
|
+
return change.enabled !== void 0 || change.tierKey !== void 0 || change.remove === true;
|
|
1125
|
+
}
|
|
1126
|
+
function previewCatalogChange(model, change) {
|
|
1127
|
+
if (!change) return model;
|
|
1128
|
+
const updated = applyQoderCatalogChange(model, change);
|
|
1129
|
+
if (updated !== void 0) return updated;
|
|
1130
|
+
if (change.tierKey !== void 0 && change.enabled !== void 0) return {
|
|
1131
|
+
...model,
|
|
1132
|
+
enabled: change.enabled
|
|
1133
|
+
};
|
|
1134
|
+
return model;
|
|
1135
|
+
}
|
|
1136
|
+
function unavailableTierIds(error) {
|
|
1137
|
+
if (error?.code !== "CATALOG_TIER_UNAVAILABLE" || !error.details || !("modelIds" in error.details)) return /* @__PURE__ */ new Set();
|
|
1138
|
+
const ids = error.details.modelIds;
|
|
1139
|
+
return new Set(Array.isArray(ids) ? ids.filter((id) => typeof id === "string") : []);
|
|
1140
|
+
}
|
|
1141
|
+
var QoderModelCatalogEditor = class {
|
|
1142
|
+
region;
|
|
1143
|
+
operations;
|
|
1144
|
+
queued = /* @__PURE__ */ new Map();
|
|
1145
|
+
listeners = /* @__PURE__ */ new Set();
|
|
1146
|
+
active = true;
|
|
1147
|
+
mounts = 0;
|
|
1148
|
+
unsubscribeStatus;
|
|
1149
|
+
inFlight;
|
|
1150
|
+
debounceTimer;
|
|
1151
|
+
deadlineTimer;
|
|
1152
|
+
batchReady = false;
|
|
1153
|
+
draining = false;
|
|
1154
|
+
retry;
|
|
1155
|
+
editRetries = 0;
|
|
1156
|
+
snapshot;
|
|
1157
|
+
constructor(region, models, operations) {
|
|
1158
|
+
this.region = region;
|
|
1159
|
+
this.operations = operations;
|
|
1160
|
+
const saved = models.map(cloneCatalogModel);
|
|
1161
|
+
this.snapshot = {
|
|
1162
|
+
models: saved,
|
|
1163
|
+
viewModels: saved,
|
|
1164
|
+
savingChanges: false,
|
|
1165
|
+
hasPendingChanges: false,
|
|
1166
|
+
refreshRequested: false
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
getSnapshot = () => this.snapshot;
|
|
1170
|
+
subscribe = (listener) => {
|
|
1171
|
+
this.listeners.add(listener);
|
|
1172
|
+
return () => {
|
|
1173
|
+
this.listeners.delete(listener);
|
|
1174
|
+
};
|
|
1175
|
+
};
|
|
1176
|
+
replaceModels(models) {
|
|
1177
|
+
if (this.active) this.publish({ models: models.map(cloneCatalogModel) });
|
|
1178
|
+
}
|
|
1179
|
+
activate() {
|
|
1180
|
+
this.mounts++;
|
|
1181
|
+
this.active = true;
|
|
1182
|
+
this.unsubscribeStatus ??= this.operations.subscribeCatalog?.(this.region, (status) => {
|
|
1183
|
+
this.publish({ status });
|
|
1184
|
+
this.drain();
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
dispose() {
|
|
1188
|
+
if (this.mounts > 0 && --this.mounts > 0) return;
|
|
1189
|
+
this.active = false;
|
|
1190
|
+
this.flush();
|
|
1191
|
+
this.releaseSubscription();
|
|
1192
|
+
}
|
|
1193
|
+
releaseSubscription() {
|
|
1194
|
+
if (this.active || this.draining || this.queued.size || this.snapshot.pending || this.snapshot.refreshRequested) return;
|
|
1195
|
+
this.unsubscribeStatus?.();
|
|
1196
|
+
this.unsubscribeStatus = void 0;
|
|
1197
|
+
}
|
|
1198
|
+
publish(patch) {
|
|
1199
|
+
const models = patch.models ?? this.snapshot.models;
|
|
1200
|
+
const hasPendingChanges = !!this.inFlight || this.queued.size > 0;
|
|
1201
|
+
const viewModels = hasPendingChanges ? models.flatMap((model) => {
|
|
1202
|
+
const baseline = previewCatalogChange(model, this.inFlight?.get(model.id));
|
|
1203
|
+
if (baseline === null) return [];
|
|
1204
|
+
const updated = previewCatalogChange(baseline, this.queued.get(model.id));
|
|
1205
|
+
return updated === null ? [] : [updated];
|
|
1206
|
+
}) : models;
|
|
1207
|
+
this.snapshot = {
|
|
1208
|
+
...this.snapshot,
|
|
1209
|
+
...patch,
|
|
1210
|
+
viewModels,
|
|
1211
|
+
hasPendingChanges,
|
|
1212
|
+
savingChanges: !!this.inFlight
|
|
1213
|
+
};
|
|
1214
|
+
if (this.active) for (const listener of this.listeners) listener();
|
|
1215
|
+
}
|
|
1216
|
+
hostLocked() {
|
|
1217
|
+
return this.snapshot.status?.refreshing === true || !!this.operations.subscribeCatalog && !this.snapshot.status;
|
|
1218
|
+
}
|
|
1219
|
+
discover() {
|
|
1220
|
+
if (!this.active || !this.operations.refreshCatalog || this.hostLocked() || this.snapshot.pending || this.snapshot.refreshRequested) return;
|
|
1221
|
+
this.publish({
|
|
1222
|
+
refreshRequested: true,
|
|
1223
|
+
failure: void 0
|
|
1224
|
+
});
|
|
1225
|
+
return this.flush();
|
|
1226
|
+
}
|
|
1227
|
+
edit(edit) {
|
|
1228
|
+
if (!this.active || !this.operations.editCatalog || this.hostLocked() || this.snapshot.pending || this.snapshot.refreshRequested) return;
|
|
1229
|
+
const model = this.snapshot.models.find((candidate) => candidate.id === edit.id);
|
|
1230
|
+
const current = this.snapshot.viewModels.find((candidate) => candidate.id === edit.id);
|
|
1231
|
+
if (!model || !current) return;
|
|
1232
|
+
const sent = this.inFlight?.get(edit.id);
|
|
1233
|
+
const baseline = sent ? applyQoderCatalogChange(model, sent) ?? model : model;
|
|
1234
|
+
const change = {
|
|
1235
|
+
id: edit.id,
|
|
1236
|
+
...this.queued.get(edit.id)
|
|
1237
|
+
};
|
|
1238
|
+
if (edit.action === "toggle") if (sent?.enabled === void 0 && edit.enabled === (baseline.enabled !== false)) delete change.enabled;
|
|
1239
|
+
else change.enabled = edit.enabled;
|
|
1240
|
+
else if (edit.action === "selectTier") {
|
|
1241
|
+
if (current.enabled === false || !applyQoderCatalogChange(current, {
|
|
1242
|
+
id: edit.id,
|
|
1243
|
+
tierKey: edit.tierKey
|
|
1244
|
+
})) return;
|
|
1245
|
+
if (sent?.tierKey === void 0 && edit.tierKey === resolveContextTier(baseline)?.key) delete change.tierKey;
|
|
1246
|
+
else change.tierKey = edit.tierKey;
|
|
1247
|
+
} else {
|
|
1248
|
+
if (!current.missingFromCatalog || current.enabled !== false) return;
|
|
1249
|
+
change.remove = true;
|
|
1250
|
+
if (model.enabled !== false) change.enabled = false;
|
|
1251
|
+
delete change.tierKey;
|
|
1252
|
+
}
|
|
1253
|
+
if (!hasChanges(change)) this.queued.delete(edit.id);
|
|
1254
|
+
else this.queued.set(edit.id, change);
|
|
1255
|
+
this.publish({ failure: void 0 });
|
|
1256
|
+
if (!this.queued.size || this.batchReady) return this.flush();
|
|
1257
|
+
clearTimeout(this.debounceTimer);
|
|
1258
|
+
this.debounceTimer = setTimeout(() => {
|
|
1259
|
+
this.flush();
|
|
1260
|
+
}, editDebounceMs);
|
|
1261
|
+
this.deadlineTimer ??= setTimeout(() => {
|
|
1262
|
+
this.flush();
|
|
1263
|
+
}, maxEditDelayMs);
|
|
1264
|
+
}
|
|
1265
|
+
flush() {
|
|
1266
|
+
clearTimeout(this.debounceTimer);
|
|
1267
|
+
clearTimeout(this.deadlineTimer);
|
|
1268
|
+
this.debounceTimer = void 0;
|
|
1269
|
+
this.deadlineTimer = void 0;
|
|
1270
|
+
this.batchReady = this.queued.size > 0;
|
|
1271
|
+
return this.drain();
|
|
1272
|
+
}
|
|
1273
|
+
async drain() {
|
|
1274
|
+
if (this.draining || this.retry !== void 0 || this.hostLocked()) return;
|
|
1275
|
+
this.draining = true;
|
|
1276
|
+
try {
|
|
1277
|
+
const apply = this.operations.editCatalog;
|
|
1278
|
+
while (apply && !this.hostLocked() && this.batchReady) {
|
|
1279
|
+
const modelsAtStart = this.snapshot.models;
|
|
1280
|
+
const { batch, failure } = this.prepareBatch(modelsAtStart);
|
|
1281
|
+
this.queued.clear();
|
|
1282
|
+
this.batchReady = false;
|
|
1283
|
+
const notice = failure ? {
|
|
1284
|
+
refreshRequested: false,
|
|
1285
|
+
failure
|
|
1286
|
+
} : {};
|
|
1287
|
+
if (!batch.size) {
|
|
1288
|
+
this.publish(notice);
|
|
1289
|
+
continue;
|
|
1290
|
+
}
|
|
1291
|
+
this.inFlight = batch;
|
|
1292
|
+
this.publish(notice);
|
|
1293
|
+
const result = await apply(this.region, {
|
|
1294
|
+
action: "editBatch",
|
|
1295
|
+
changes: [...batch.values()]
|
|
1296
|
+
}).catch(() => void 0);
|
|
1297
|
+
this.inFlight = void 0;
|
|
1298
|
+
if (result?.ok) {
|
|
1299
|
+
this.editRetries = 0;
|
|
1300
|
+
this.confirm(result.value, modelsAtStart);
|
|
1301
|
+
continue;
|
|
1302
|
+
}
|
|
1303
|
+
const code = result?.error.code;
|
|
1304
|
+
if (this.retryWhenAvailable(code)) {
|
|
1305
|
+
this.restoreBatch(batch);
|
|
1306
|
+
this.publish({});
|
|
1307
|
+
this.flush();
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
const staleTiers = unavailableTierIds(result?.error);
|
|
1311
|
+
if ([...batch.values()].some((change) => change.tierKey !== void 0 && staleTiers.has(change.id))) {
|
|
1312
|
+
this.restoreBatch(batch, staleTiers);
|
|
1313
|
+
this.publish({
|
|
1314
|
+
refreshRequested: false,
|
|
1315
|
+
failure: "catalogTierNotSaved"
|
|
1316
|
+
});
|
|
1317
|
+
this.flush();
|
|
1318
|
+
continue;
|
|
1319
|
+
}
|
|
1320
|
+
this.publish({
|
|
1321
|
+
refreshRequested: false,
|
|
1322
|
+
failure: "saveFailed"
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
const refresh = this.operations.refreshCatalog;
|
|
1326
|
+
if (refresh && this.snapshot.refreshRequested && !this.queued.size && !this.hostLocked()) {
|
|
1327
|
+
const modelsAtStart = this.snapshot.models;
|
|
1328
|
+
this.publish({
|
|
1329
|
+
pending: "discovering",
|
|
1330
|
+
refreshRequested: false
|
|
1331
|
+
});
|
|
1332
|
+
const result = await refresh(this.region).catch(() => void 0);
|
|
1333
|
+
if (result?.ok) {
|
|
1334
|
+
this.editRetries = 0;
|
|
1335
|
+
this.confirm(result.value, modelsAtStart, { pending: void 0 });
|
|
1336
|
+
} else if (this.retryWhenAvailable(result?.error.code)) this.publish({
|
|
1337
|
+
pending: void 0,
|
|
1338
|
+
refreshRequested: true
|
|
1339
|
+
});
|
|
1340
|
+
else {
|
|
1341
|
+
const failure = result?.error.code === "CATALOG_SAVE_FAILED" ? "modelsUpdateNotSaved" : "modelsFetchFailed";
|
|
1342
|
+
this.publish({
|
|
1343
|
+
pending: void 0,
|
|
1344
|
+
failure
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
} finally {
|
|
1349
|
+
this.draining = false;
|
|
1350
|
+
this.releaseSubscription();
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
prepareBatch(models) {
|
|
1354
|
+
const saved = new Map(models.map((model) => [model.id, model]));
|
|
1355
|
+
const batch = /* @__PURE__ */ new Map();
|
|
1356
|
+
let invalid = false;
|
|
1357
|
+
let staleTier = false;
|
|
1358
|
+
for (const [id, change] of this.queued) {
|
|
1359
|
+
const model = saved.get(id);
|
|
1360
|
+
if (!model) {
|
|
1361
|
+
invalid = true;
|
|
1362
|
+
continue;
|
|
1363
|
+
}
|
|
1364
|
+
const next = { ...change };
|
|
1365
|
+
if (next.enabled === (model.enabled !== false)) delete next.enabled;
|
|
1366
|
+
if (next.tierKey !== void 0) {
|
|
1367
|
+
if (!applyQoderCatalogChange(model, {
|
|
1368
|
+
id,
|
|
1369
|
+
tierKey: next.tierKey
|
|
1370
|
+
})) {
|
|
1371
|
+
delete next.tierKey;
|
|
1372
|
+
staleTier = true;
|
|
1373
|
+
} else if (next.tierKey === resolveContextTier(model)?.key) delete next.tierKey;
|
|
1374
|
+
}
|
|
1375
|
+
if (!hasChanges(next)) continue;
|
|
1376
|
+
if (applyQoderCatalogChange(model, next) === void 0) invalid = true;
|
|
1377
|
+
else batch.set(id, next);
|
|
1378
|
+
}
|
|
1379
|
+
return {
|
|
1380
|
+
batch,
|
|
1381
|
+
failure: invalid ? "saveFailed" : staleTier ? "catalogTierNotSaved" : void 0
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1384
|
+
restoreBatch(batch, staleTiers) {
|
|
1385
|
+
for (const [id, change] of batch) {
|
|
1386
|
+
const sent = { ...change };
|
|
1387
|
+
if (staleTiers?.has(id)) delete sent.tierKey;
|
|
1388
|
+
const combined = {
|
|
1389
|
+
...sent,
|
|
1390
|
+
...this.queued.get(id)
|
|
1391
|
+
};
|
|
1392
|
+
if (combined.remove) delete combined.tierKey;
|
|
1393
|
+
if (hasChanges(combined)) this.queued.set(id, combined);
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
retryWhenAvailable(code) {
|
|
1397
|
+
if (code !== "CATALOG_EDITING") this.editRetries = 0;
|
|
1398
|
+
if (code !== "CATALOG_EDITING" && code !== "CATALOG_REFRESHING") return false;
|
|
1399
|
+
if (this.hostLocked()) return true;
|
|
1400
|
+
const delay = code === "CATALOG_EDITING" ? editRetryDelays[this.editRetries++] : 150;
|
|
1401
|
+
if (delay === void 0) {
|
|
1402
|
+
this.editRetries = 0;
|
|
1403
|
+
return false;
|
|
1404
|
+
}
|
|
1405
|
+
this.retry = setTimeout(() => {
|
|
1406
|
+
this.retry = void 0;
|
|
1407
|
+
this.drain();
|
|
1408
|
+
}, delay);
|
|
1409
|
+
return true;
|
|
1410
|
+
}
|
|
1411
|
+
confirm(saved, modelsAtStart, patch = {}) {
|
|
1412
|
+
const models = this.snapshot.models === modelsAtStart ? saved.map(cloneCatalogModel) : this.snapshot.models;
|
|
1413
|
+
this.publish({
|
|
1414
|
+
...patch,
|
|
1415
|
+
models
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
};
|
|
1419
|
+
//#endregion
|
|
1420
|
+
//#region \0dsh-css:src/client/QoderCredentialCard.module.css.mjs
|
|
1421
|
+
const css$1 = "._1cFIwW_credential{color:var(--dsw-alias-label-primary);border-radius:10px;margin-top:12px}._1cFIwW_connectionBody{flex-direction:column;gap:10px;display:flex}._1cFIwW_connectionHead,._1cFIwW_subscriberRow{justify-content:space-between;align-items:center;gap:16px;display:flex}._1cFIwW_connectionHead{flex-wrap:wrap}._1cFIwW_subscriberRow{gap:10px;padding:4px 0}._1cFIwW_subscriberIdentity{overflow-wrap:anywhere;flex-direction:column;flex:1;gap:2px;min-width:0;display:flex}._1cFIwW_subscriberIdentity>span{color:var(--dsw-alias-label-tertiary);font-size:11px}._1cFIwW_connectionActions{flex-wrap:wrap;align-items:center;gap:10px;margin-top:12px;display:flex}._1cFIwW_loginProgress{background:var(--dsw-alias-interactive-bg-hover);border-radius:10px;flex-direction:column;gap:8px;padding:14px;display:flex}._1cFIwW_managementPanel{flex-wrap:wrap;align-items:center;gap:8px;display:flex}._1cFIwW_credential ._1cFIwW_managementPanel ._1cFIwW_textButton{border-radius:var(--dsw-radius-md,8px);height:32px;color:var(--dsw-alias-label-primary);font:inherit;font-size:12px;padding:0 10px!important}._1cFIwW_credential ._1cFIwW_managementPanel ._1cFIwW_textButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}._1cFIwW_credential ._1cFIwW_managementPanel ._1cFIwW_dangerText{color:var(--dsw-alias-state-error-primary);margin-left:8px}._1cFIwW_credential ._1cFIwW_managementPanel ._1cFIwW_dangerText:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover-danger)}._1cFIwW_credential ._1cFIwW_textButton{color:var(--dsw-alias-brand-primary);background:0 0;border:0!important;padding:4px 2px!important}._1cFIwW_primaryLink{background:var(--dsw-alias-button-primary-fill);color:var(--dsw-alias-label-primary-foreground);border-radius:18px;padding:8px 14px;font-size:12px;text-decoration:none;display:inline-flex}._1cFIwW_credential p._1cFIwW_sharedNote{color:var(--dsw-alias-label-tertiary);margin:0;padding-top:4px;font-size:12px;line-height:18px}@media (width<=480px){._1cFIwW_subscriberRow{flex-wrap:wrap}._1cFIwW_subscriberIdentity{flex-basis:calc(100% - 60px)}}._1cFIwW_credential p{margin:8px 0 0}._1cFIwW_credentialEditor{box-sizing:border-box;border:.5px solid var(--dsw-alias-settings-card-stroke,var(--dsw-alias-border-l2));background:var(--dsw-alias-settings-card-fill,var(--dsw-alias-bg-layer-1));border-radius:var(--dsw-radius-xl,12px);flex-direction:column;gap:10px;padding:12px 14px;display:flex}._1cFIwW_credentialRowHead{align-items:center;gap:10px;display:flex}._1cFIwW_credentialIdentity{align-items:center;gap:6px;min-width:0;display:inline-flex}._1cFIwW_credentialName{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:500;line-height:22px}._1cFIwW_credentialDot{box-sizing:border-box;border-radius:50%;flex:none;width:8px;height:8px;display:inline-block}._1cFIwW_credentialDotConfigured{background:var(--dsw-alias-state-success-primary)}._1cFIwW_credentialDotMissing{background:var(--dsw-alias-state-error-primary)}._1cFIwW_regionBadge{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-secondary);border-radius:4px;align-items:center;padding:1px 6px;font-size:11px;font-weight:500;line-height:16px;display:inline-flex}._1cFIwW_regionSelector{flex-direction:column;gap:8px;margin-bottom:14px;display:flex}._1cFIwW_regionGroup{border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-module-platform);flex-wrap:wrap;gap:4px;padding:3px;display:flex}._1cFIwW_credential button._1cFIwW_regionOption{box-sizing:border-box;border-radius:var(--dsw-radius-sm,6px);cursor:pointer;height:28px;color:var(--dsw-alias-label-secondary);user-select:none;background:0 0;border:.5px solid #0000;align-items:center;gap:6px;padding:0 10px;font-size:12px;line-height:18px;transition:all .12s;display:inline-flex}._1cFIwW_credential button._1cFIwW_regionOption:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}._1cFIwW_credential button._1cFIwW_regionOptionActive{border-color:var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font-weight:500}._1cFIwW_regionOptionDisabled{cursor:not-allowed;opacity:.5}._1cFIwW_editButton{box-sizing:border-box;font:inherit;background:0 0;margin-left:auto;font-size:12px;line-height:18px;border:1px solid var(--dsw-alias-border-l2)!important;border-radius:14px!important;height:28px!important;padding:0 10px!important}._1cFIwW_editButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover-solid)}._1cFIwW_editor{background:var(--dsw-alias-bg-module-platform);border-radius:12px;padding:14px 16px}._1cFIwW_customized{border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-xl,12px);background:var(--dsw-alias-bg-module-platform);margin-top:12px;transition:all .12s;position:relative;overflow:hidden}._1cFIwW_customizedSummary{box-sizing:border-box;border-radius:var(--dsw-radius-xl,12px);cursor:pointer;width:100%;min-height:52px;color:var(--dsw-alias-label-primary);user-select:none;flex-wrap:wrap;align-items:center;gap:8px;margin:0;padding:12px 150px 12px 14px;font-size:13px;font-weight:600;line-height:18px;list-style:none;transition:background .12s;display:flex}._1cFIwW_customizedSummary:hover{background:var(--dsw-alias-interactive-bg-hover)}._1cFIwW_modelSummaryBadge{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-tertiary);border-radius:4px;align-items:center;padding:1px 6px;font-size:11px;font-weight:400;line-height:16px;display:inline-flex}._1cFIwW_customizedSummary::-webkit-details-marker{display:none}._1cFIwW_customizedSummary:before{content:\"\";border-bottom:1.5px solid;border-right:1.5px solid;width:5px;height:5px;transition:transform .12s;transform:rotate(-45deg)translate(-1px,-1px)}._1cFIwW_customized[open]>._1cFIwW_customizedSummary:before{transform:rotate(45deg)translate(-1px,-1px)}._1cFIwW_customized[open]>._1cFIwW_customizedSummary{border-bottom:.5px solid var(--dsw-alias-border-l2);border-bottom-right-radius:0;border-bottom-left-radius:0}._1cFIwW_customizedBody{padding:12px 14px 14px}._1cFIwW_modelCatalog{flex-direction:column;gap:12px;display:flex}._1cFIwW_modelList{box-sizing:border-box;flex-direction:column;gap:6px;padding:8px;display:flex}._1cFIwW_modelCatalogHead{justify-content:space-between;align-items:flex-start;gap:12px;display:flex}._1cFIwW_modelCatalogHeadCompact{justify-content:flex-end;align-items:center;gap:12px;display:flex;position:absolute;top:12px;right:14px}._1cFIwW_modelCatalogTitle{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:500;line-height:18px}._1cFIwW_modelCatalogMeta{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px;margin:2px 0 0!important}._1cFIwW_linkButton{box-sizing:border-box;font:inherit;background:0 0;font-size:12px;line-height:18px;border:none!important;border-radius:14px!important;height:28px!important;padding:0 10px!important}._1cFIwW_linkButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}._1cFIwW_modelChoice{border-radius:6px;flex-direction:column;gap:4px;padding:6px 8px;font-size:13px;display:flex}._1cFIwW_modelChoice:hover{background:var(--dsw-alias-interactive-bg-hover)}._1cFIwW_modelChoiceHead{grid-template-columns:minmax(0,1fr) auto;align-items:center;gap:8px;min-height:28px;display:grid}._1cFIwW_modelChoiceLabel{cursor:pointer;grid-template-columns:16px minmax(0,1fr);align-items:center;gap:8px;display:grid}._1cFIwW_modelChoiceLabel input[type=checkbox]{width:16px;height:16px;margin:0}._1cFIwW_modelChoiceLabel:has(input:disabled){cursor:default}._1cFIwW_modelActions{align-items:center;gap:8px;display:flex}._1cFIwW_modelName,._1cFIwW_modelDetails,._1cFIwW_modelMetadata{flex-wrap:wrap;align-items:center;min-width:0;display:flex}._1cFIwW_modelName{gap:2px 6px}._1cFIwW_modelDetails{justify-content:space-between;gap:4px 12px;padding-inline-start:24px}._1cFIwW_modelMetadata{color:var(--dsw-alias-label-tertiary);gap:2px 8px;font-size:11px;line-height:18px}._1cFIwW_modelMetadata code{overflow-wrap:anywhere;min-width:0}._1cFIwW_modelTier{flex-wrap:wrap;align-items:center;gap:4px 8px;display:flex}._1cFIwW_credential button._1cFIwW_modelTierSelect{box-sizing:border-box;border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-layer-1);height:28px;color:inherit;font:inherit;cursor:pointer;border:0;align-items:center;gap:12px;padding:0 10px;font-size:12px;display:inline-flex}._1cFIwW_credential button._1cFIwW_modelTierSelect:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}._1cFIwW_credential button._1cFIwW_modelTierSelect:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}._1cFIwW_modelChoiceName{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}._1cFIwW_modelRate,._1cFIwW_modelMissing{color:var(--dsw-alias-label-tertiary);white-space:nowrap;font-size:11px;line-height:18px}._1cFIwW_modelRate{font-variant-numeric:tabular-nums}._1cFIwW_credential button._1cFIwW_modelDelete{border-radius:var(--dsw-radius-sm,6px);height:28px;color:var(--dsw-alias-state-error-primary);font:inherit;white-space:nowrap;cursor:pointer;background:0 0;border:0;padding:0 10px;font-size:12px;line-height:18px}._1cFIwW_credential button._1cFIwW_modelDelete:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover-danger)}._1cFIwW_credential button._1cFIwW_modelDelete:disabled{opacity:.4;cursor:default}._1cFIwW_credential button._1cFIwW_modelDelete:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}@media (prefers-reduced-motion:reduce){._1cFIwW_customizedSummary:before{transition:none}}._1cFIwW_head{justify-content:space-between;align-items:center;gap:12px;margin-bottom:20px;display:flex}._1cFIwW_heading{margin:0;font-size:16px;font-weight:500;line-height:24px}._1cFIwW_status{color:var(--dsw-alias-label-secondary);font-size:12px}._1cFIwW_configured,._1cFIwW_success{color:var(--dsw-alias-state-success-primary)}._1cFIwW_label{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:500;line-height:18px;display:block}._1cFIwW_input{box-sizing:border-box;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);width:100%;height:32px;color:var(--dsw-alias-label-primary);border-radius:8px;outline:none;margin-top:6px;padding:0 10px}._1cFIwW_input:focus{border-color:var(--dsw-alias-brand-primary)}._1cFIwW_input::placeholder{color:var(--dsw-alias-label-dimmed)}._1cFIwW_input:disabled{cursor:not-allowed;opacity:.4}._1cFIwW_hint{color:var(--dsw-alias-label-secondary);font-size:12px}._1cFIwW_actions{justify-content:flex-end;gap:8px;margin-top:14px;display:flex}._1cFIwW_credential button:not(:where([data-qoder-features] button)){box-sizing:border-box;cursor:pointer;height:32px;color:var(--dsw-alias-label-primary);border:1px solid #0000;border-radius:16px;justify-content:center;align-items:center;padding:0 12px;line-height:20px;display:inline-flex}._1cFIwW_credential button:not(:where([data-qoder-features] button)):disabled{cursor:not-allowed;opacity:.4}._1cFIwW_primary{background:var(--dsw-alias-button-primary-fill);color:var(--dsw-alias-label-primary-foreground)!important}._1cFIwW_primary:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover)}._1cFIwW_secondary{background:0 0;border-color:var(--dsw-alias-border-l2)!important}._1cFIwW_secondary:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}._1cFIwW_danger{background:0 0;border-color:var(--dsw-alias-state-error-primary)!important;color:var(--dsw-alias-state-error-primary)!important}._1cFIwW_danger:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover-danger)}._1cFIwW_error{color:var(--dsw-alias-state-error-primary);font-size:12px}._1cFIwW_success{font-size:12px}._1cFIwW_featureSection{flex-direction:column;margin-top:24px;display:flex}._1cFIwW_featureSectionTitle{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:600;line-height:22px}._1cFIwW_featureTitle{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}._1cFIwW_featureHint{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}._1cFIwW_featureSetting{border-bottom:.5px solid var(--dsw-alias-border-l2);flex-direction:column;gap:8px;padding:16px 0;display:flex}._1cFIwW_featureSetting:last-of-type{border-bottom:none}._1cFIwW_featureToggleRow{flex-direction:row;justify-content:space-between;align-items:center;gap:16px}._1cFIwW_featureDescription{overflow-wrap:anywhere;flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}._1cFIwW_featureControl{flex:none;max-width:45%}._1cFIwW_searchModeSwitcher{box-sizing:border-box;border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-module-platform);max-width:100%;height:36px;color:var(--dsw-alias-label-primary);font:inherit;white-space:nowrap;cursor:pointer;border:none;align-items:center;gap:12px;padding:0 14px;font-size:14px;line-height:22px;display:inline-flex}._1cFIwW_searchModeSwitcher:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}._1cFIwW_searchModeSwitcher:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}._1cFIwW_searchModeSwitcher:disabled{cursor:not-allowed;opacity:.4}._1cFIwW_searchModeSwitcherLabel{text-overflow:ellipsis;max-width:240px;overflow:hidden}._1cFIwW_searchModeChevron{flex:none}._1cFIwW_accountSection{border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-xl,12px);background:var(--dsw-alias-bg-module-platform);flex-direction:column;gap:10px;margin-top:12px;padding:12px 14px;display:flex}._1cFIwW_accountHead{justify-content:space-between;align-items:center;gap:8px;display:flex}._1cFIwW_userInfo{align-items:center;gap:10px;min-width:0;display:flex}._1cFIwW_avatar{background:var(--dsw-alias-brand-primary);width:32px;height:32px;color:var(--dsw-alias-label-primary-foreground);text-transform:uppercase;border-radius:50%;flex-shrink:0;justify-content:center;align-items:center;font-size:14px;font-weight:600;display:flex}._1cFIwW_userDetails{flex-direction:column;gap:2px;min-width:0;display:flex}._1cFIwW_userName{color:var(--dsw-alias-label-primary);text-overflow:ellipsis;white-space:nowrap;font-size:13px;font-weight:600;overflow:hidden}._1cFIwW_userEmail{color:var(--dsw-alias-label-tertiary);text-overflow:ellipsis;white-space:nowrap;font-size:11px;overflow:hidden}._1cFIwW_refreshBtn{border:1px solid var(--dsw-alias-border-l2)!important;height:26px!important;color:var(--dsw-alias-label-secondary)!important;background:0 0!important;border-radius:13px!important;padding:0 8px!important;font-size:12px!important}._1cFIwW_refreshBtn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)!important}._1cFIwW_quotaBlock{border-top:1px solid var(--dsw-alias-border-l2);flex-direction:column;gap:6px;padding-top:8px;display:flex}._1cFIwW_quotaHeader{flex-wrap:wrap;align-items:center;gap:8px;display:flex}._1cFIwW_quotaLabel{color:var(--dsw-alias-label-secondary);margin-inline-end:auto;font-size:12px;font-weight:600}._1cFIwW_quotaTop{justify-content:space-between;align-items:baseline;gap:8px;font-size:12px;display:flex}._1cFIwW_quotaStatus{color:var(--dsw-alias-state-error-primary);font-size:12px}._1cFIwW_quotaModelScope{color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere;font-size:12px}._1cFIwW_quotaModelScope summary{cursor:pointer}._1cFIwW_accountRefreshStatus{flex-wrap:wrap;gap:4px 8px;display:flex}._1cFIwW_quotaDescription{color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:16px;margin:0!important}._1cFIwW_quotaProgress{background:var(--dsw-alias-border-l3);width:100%;height:6px;accent-color:var(--dsw-alias-brand-primary);-webkit-appearance:none;appearance:none;border:0;border-radius:999px;overflow:hidden}._1cFIwW_quotaProgress::-webkit-progress-bar{background:var(--dsw-alias-border-l3);border-radius:999px}._1cFIwW_quotaProgress::-webkit-progress-value{background:var(--dsw-alias-brand-primary);border-radius:999px}._1cFIwW_quotaProgress::-moz-progress-bar{background:var(--dsw-alias-brand-primary);border-radius:999px}._1cFIwW_quotaMeta{color:var(--dsw-alias-label-tertiary);justify-content:space-between;align-items:center;gap:8px;font-size:11px;display:flex}._1cFIwW_accountLoadingText,._1cFIwW_accountEmptyText{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px}._1cFIwW_userNameRow{align-items:center;gap:8px;display:flex}._1cFIwW_planBadge{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-brand-primary);border-radius:4px;align-items:center;padding:1px 6px;font-size:11px;font-weight:600;line-height:16px;display:inline-flex}._1cFIwW_orgTag{color:var(--dsw-alias-label-tertiary);font-size:11px}._1cFIwW_suspendedBanner{background:var(--dsw-alias-state-error-subtle,#ff4d4f1a);color:var(--dsw-alias-state-error-primary);border-radius:6px;align-items:center;gap:6px;margin-bottom:8px;padding:6px 10px;font-size:12px;display:flex}";
|
|
1422
|
+
const tagId$1 = "dsh-subscription-qoder/QoderCredentialCard.module.css";
|
|
1423
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) {
|
|
1424
|
+
const tag = document.createElement("style");
|
|
1425
|
+
tag.dataset.plugin = "dsh-subscription-qoder";
|
|
1426
|
+
tag.dataset.pluginCss = tagId$1;
|
|
1427
|
+
tag.textContent = css$1;
|
|
1428
|
+
document.head.appendChild(tag);
|
|
1429
|
+
}
|
|
1430
|
+
var QoderCredentialCard_module_css_default = {
|
|
1431
|
+
"accountEmptyText": "_1cFIwW_accountEmptyText",
|
|
1432
|
+
"accountHead": "_1cFIwW_accountHead",
|
|
1433
|
+
"accountLoadingText": "_1cFIwW_accountLoadingText",
|
|
1434
|
+
"accountRefreshStatus": "_1cFIwW_accountRefreshStatus",
|
|
1435
|
+
"accountSection": "_1cFIwW_accountSection",
|
|
1436
|
+
"actions": "_1cFIwW_actions",
|
|
1437
|
+
"avatar": "_1cFIwW_avatar",
|
|
1438
|
+
"configured": "_1cFIwW_configured",
|
|
1439
|
+
"connectionActions": "_1cFIwW_connectionActions",
|
|
1440
|
+
"connectionBody": "_1cFIwW_connectionBody",
|
|
1441
|
+
"connectionHead": "_1cFIwW_connectionHead",
|
|
1442
|
+
"credential": "_1cFIwW_credential",
|
|
1443
|
+
"credentialDot": "_1cFIwW_credentialDot",
|
|
1444
|
+
"credentialDotConfigured": "_1cFIwW_credentialDotConfigured",
|
|
1445
|
+
"credentialDotMissing": "_1cFIwW_credentialDotMissing",
|
|
1446
|
+
"credentialEditor": "_1cFIwW_credentialEditor",
|
|
1447
|
+
"credentialIdentity": "_1cFIwW_credentialIdentity",
|
|
1448
|
+
"credentialName": "_1cFIwW_credentialName",
|
|
1449
|
+
"credentialRowHead": "_1cFIwW_credentialRowHead",
|
|
1450
|
+
"customized": "_1cFIwW_customized",
|
|
1451
|
+
"customizedBody": "_1cFIwW_customizedBody",
|
|
1452
|
+
"customizedSummary": "_1cFIwW_customizedSummary",
|
|
1453
|
+
"danger": "_1cFIwW_danger",
|
|
1454
|
+
"dangerText": "_1cFIwW_dangerText",
|
|
1455
|
+
"editButton": "_1cFIwW_editButton",
|
|
1456
|
+
"editor": "_1cFIwW_editor",
|
|
1457
|
+
"error": "_1cFIwW_error",
|
|
1458
|
+
"featureControl": "_1cFIwW_featureControl",
|
|
1459
|
+
"featureDescription": "_1cFIwW_featureDescription",
|
|
1460
|
+
"featureHint": "_1cFIwW_featureHint",
|
|
1461
|
+
"featureSection": "_1cFIwW_featureSection",
|
|
1462
|
+
"featureSectionTitle": "_1cFIwW_featureSectionTitle",
|
|
1463
|
+
"featureSetting": "_1cFIwW_featureSetting",
|
|
1464
|
+
"featureTitle": "_1cFIwW_featureTitle",
|
|
1465
|
+
"featureToggleRow": "_1cFIwW_featureToggleRow",
|
|
1466
|
+
"head": "_1cFIwW_head",
|
|
1467
|
+
"heading": "_1cFIwW_heading",
|
|
1468
|
+
"hint": "_1cFIwW_hint",
|
|
1469
|
+
"input": "_1cFIwW_input",
|
|
1470
|
+
"label": "_1cFIwW_label",
|
|
1471
|
+
"linkButton": "_1cFIwW_linkButton",
|
|
1472
|
+
"loginProgress": "_1cFIwW_loginProgress",
|
|
1473
|
+
"managementPanel": "_1cFIwW_managementPanel",
|
|
1474
|
+
"modelActions": "_1cFIwW_modelActions",
|
|
1475
|
+
"modelCatalog": "_1cFIwW_modelCatalog",
|
|
1476
|
+
"modelCatalogHead": "_1cFIwW_modelCatalogHead",
|
|
1477
|
+
"modelCatalogHeadCompact": "_1cFIwW_modelCatalogHeadCompact",
|
|
1478
|
+
"modelCatalogMeta": "_1cFIwW_modelCatalogMeta",
|
|
1479
|
+
"modelCatalogTitle": "_1cFIwW_modelCatalogTitle",
|
|
1480
|
+
"modelChoice": "_1cFIwW_modelChoice",
|
|
1481
|
+
"modelChoiceHead": "_1cFIwW_modelChoiceHead",
|
|
1482
|
+
"modelChoiceLabel": "_1cFIwW_modelChoiceLabel",
|
|
1483
|
+
"modelChoiceName": "_1cFIwW_modelChoiceName",
|
|
1484
|
+
"modelDelete": "_1cFIwW_modelDelete",
|
|
1485
|
+
"modelDetails": "_1cFIwW_modelDetails",
|
|
1486
|
+
"modelList": "_1cFIwW_modelList",
|
|
1487
|
+
"modelMetadata": "_1cFIwW_modelMetadata",
|
|
1488
|
+
"modelMissing": "_1cFIwW_modelMissing",
|
|
1489
|
+
"modelName": "_1cFIwW_modelName",
|
|
1490
|
+
"modelRate": "_1cFIwW_modelRate",
|
|
1491
|
+
"modelSummaryBadge": "_1cFIwW_modelSummaryBadge",
|
|
1492
|
+
"modelTier": "_1cFIwW_modelTier",
|
|
1493
|
+
"modelTierSelect": "_1cFIwW_modelTierSelect",
|
|
1494
|
+
"orgTag": "_1cFIwW_orgTag",
|
|
1495
|
+
"planBadge": "_1cFIwW_planBadge",
|
|
1496
|
+
"primary": "_1cFIwW_primary",
|
|
1497
|
+
"primaryLink": "_1cFIwW_primaryLink",
|
|
1498
|
+
"quotaBlock": "_1cFIwW_quotaBlock",
|
|
1499
|
+
"quotaDescription": "_1cFIwW_quotaDescription",
|
|
1500
|
+
"quotaHeader": "_1cFIwW_quotaHeader",
|
|
1501
|
+
"quotaLabel": "_1cFIwW_quotaLabel",
|
|
1502
|
+
"quotaMeta": "_1cFIwW_quotaMeta",
|
|
1503
|
+
"quotaModelScope": "_1cFIwW_quotaModelScope",
|
|
1504
|
+
"quotaProgress": "_1cFIwW_quotaProgress",
|
|
1505
|
+
"quotaStatus": "_1cFIwW_quotaStatus",
|
|
1506
|
+
"quotaTop": "_1cFIwW_quotaTop",
|
|
1507
|
+
"refreshBtn": "_1cFIwW_refreshBtn",
|
|
1508
|
+
"regionBadge": "_1cFIwW_regionBadge",
|
|
1509
|
+
"regionGroup": "_1cFIwW_regionGroup",
|
|
1510
|
+
"regionOption": "_1cFIwW_regionOption",
|
|
1511
|
+
"regionOptionActive": "_1cFIwW_regionOptionActive",
|
|
1512
|
+
"regionOptionDisabled": "_1cFIwW_regionOptionDisabled",
|
|
1513
|
+
"regionSelector": "_1cFIwW_regionSelector",
|
|
1514
|
+
"searchModeChevron": "_1cFIwW_searchModeChevron",
|
|
1515
|
+
"searchModeSwitcher": "_1cFIwW_searchModeSwitcher",
|
|
1516
|
+
"searchModeSwitcherLabel": "_1cFIwW_searchModeSwitcherLabel",
|
|
1517
|
+
"secondary": "_1cFIwW_secondary",
|
|
1518
|
+
"sharedNote": "_1cFIwW_sharedNote",
|
|
1519
|
+
"status": "_1cFIwW_status",
|
|
1520
|
+
"subscriberIdentity": "_1cFIwW_subscriberIdentity",
|
|
1521
|
+
"subscriberRow": "_1cFIwW_subscriberRow",
|
|
1522
|
+
"success": "_1cFIwW_success",
|
|
1523
|
+
"suspendedBanner": "_1cFIwW_suspendedBanner",
|
|
1524
|
+
"textButton": "_1cFIwW_textButton",
|
|
1525
|
+
"userDetails": "_1cFIwW_userDetails",
|
|
1526
|
+
"userEmail": "_1cFIwW_userEmail",
|
|
1527
|
+
"userInfo": "_1cFIwW_userInfo",
|
|
1528
|
+
"userName": "_1cFIwW_userName",
|
|
1529
|
+
"userNameRow": "_1cFIwW_userNameRow"
|
|
1530
|
+
};
|
|
1531
|
+
//#endregion
|
|
1532
|
+
//#region src/client/QoderModelCatalog.tsx
|
|
1533
|
+
/** The key resets directory state whenever the active Qoder service region changes. */
|
|
1534
|
+
function QoderModelCatalog(props) {
|
|
1535
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RegionModelCatalog, { ...props }, props.region);
|
|
1536
|
+
}
|
|
1537
|
+
function RegionModelCatalog({ operations, models, region, disabled, fetchDisabled, hideTitle, t }) {
|
|
1538
|
+
const [editor] = (0, react.useState)(() => operations.getCatalogEditor?.(region, models) ?? new QoderModelCatalogEditor(region, models, operations));
|
|
1539
|
+
const [openTierModelId, setOpenTierModelId] = (0, react.useState)();
|
|
1540
|
+
const snapshot = (0, react.useSyncExternalStore)(editor.subscribe, editor.getSnapshot, editor.getSnapshot);
|
|
1541
|
+
(0, react.useLayoutEffect)(() => {
|
|
1542
|
+
editor.activate();
|
|
1543
|
+
return () => editor.dispose();
|
|
1544
|
+
}, [editor]);
|
|
1545
|
+
(0, react.useLayoutEffect)(() => {
|
|
1546
|
+
editor.replaceModels(models);
|
|
1547
|
+
}, [editor, models]);
|
|
1548
|
+
const fetching = snapshot.pending === "discovering" || snapshot.status?.refreshing === true;
|
|
1549
|
+
const locked = fetching || snapshot.refreshRequested || !snapshot.status;
|
|
1550
|
+
const failure = snapshot.failure ?? (snapshot.status?.failure === "save" ? "modelsUpdateNotSaved" : snapshot.status?.failure === "fetch" ? "modelsFetchFailed" : void 0);
|
|
1551
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
1552
|
+
className: QoderCredentialCard_module_css_default.modelCatalog,
|
|
1553
|
+
"aria-label": t("modelsTitle"),
|
|
1554
|
+
"aria-busy": fetching,
|
|
1555
|
+
children: [
|
|
1556
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1557
|
+
className: hideTitle ? QoderCredentialCard_module_css_default.modelCatalogHeadCompact : QoderCredentialCard_module_css_default.modelCatalogHead,
|
|
1558
|
+
children: [!hideTitle ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", {
|
|
1559
|
+
className: QoderCredentialCard_module_css_default.modelCatalogTitle,
|
|
1560
|
+
children: t("modelsTitle")
|
|
1561
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1562
|
+
className: QoderCredentialCard_module_css_default.modelCatalogMeta,
|
|
1563
|
+
children: t("modelsEnabled", { count: snapshot.viewModels.filter((model) => model.enabled !== false).length })
|
|
1564
|
+
})] }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1565
|
+
type: "button",
|
|
1566
|
+
className: QoderCredentialCard_module_css_default.linkButton,
|
|
1567
|
+
disabled: disabled || locked || Boolean(fetchDisabled),
|
|
1568
|
+
onClick: () => {
|
|
1569
|
+
if (!disabled && !fetchDisabled) editor.discover();
|
|
1570
|
+
},
|
|
1571
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1572
|
+
"aria-live": "polite",
|
|
1573
|
+
children: fetching ? t("modelsUpdating") : t(snapshot.status ? "modelsFetch" : "modelsLoading")
|
|
1574
|
+
})
|
|
1575
|
+
})]
|
|
1576
|
+
}),
|
|
1577
|
+
snapshot.savingChanges ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModelSaveStatus, { t }) : snapshot.hasPendingChanges && snapshot.status?.refreshing ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1578
|
+
className: QoderCredentialCard_module_css_default.modelCatalogMeta,
|
|
1579
|
+
role: "status",
|
|
1580
|
+
children: t("modelWaitingForCatalog")
|
|
1581
|
+
}) : null,
|
|
1582
|
+
failure && !fetching ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1583
|
+
className: QoderCredentialCard_module_css_default.error,
|
|
1584
|
+
role: "alert",
|
|
1585
|
+
children: t(failure)
|
|
1586
|
+
}) : null,
|
|
1587
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1588
|
+
className: QoderCredentialCard_module_css_default.modelList,
|
|
1589
|
+
children: snapshot.viewModels.map((model) => {
|
|
1590
|
+
const missing = model.missingFromCatalog === true;
|
|
1591
|
+
const rate = renderQoderModelRate(model, t);
|
|
1592
|
+
const enabled = model.enabled !== false;
|
|
1593
|
+
const tiers = contextTiersOf(model);
|
|
1594
|
+
const fallbackTier = tiers.find((tier) => tier.isDefault) ?? tiers[tiers.length - 1];
|
|
1595
|
+
const selectedTier = resolveContextTier(model)?.key ?? fallbackTier?.key;
|
|
1596
|
+
const selectedTierOption = tiers.find((tier) => tier.key === selectedTier);
|
|
1597
|
+
const tierDisabled = disabled || locked || !enabled;
|
|
1598
|
+
const tierLabel = (tier) => tier.isDefault ? `${formatContextTokens(tier.tokenCount)}${t("contextTierDefaultSuffix")}` : formatContextTokens(tier.tokenCount);
|
|
1599
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1600
|
+
className: QoderCredentialCard_module_css_default.modelChoice,
|
|
1601
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1602
|
+
className: QoderCredentialCard_module_css_default.modelChoiceHead,
|
|
1603
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
1604
|
+
className: QoderCredentialCard_module_css_default.modelChoiceLabel,
|
|
1605
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
1606
|
+
type: "checkbox",
|
|
1607
|
+
checked: enabled,
|
|
1608
|
+
disabled: disabled || locked,
|
|
1609
|
+
onChange: (event) => {
|
|
1610
|
+
if (!disabled && !locked) editor.edit({
|
|
1611
|
+
action: "toggle",
|
|
1612
|
+
id: model.id,
|
|
1613
|
+
enabled: event.currentTarget.checked
|
|
1614
|
+
});
|
|
1615
|
+
}
|
|
1616
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1617
|
+
className: QoderCredentialCard_module_css_default.modelName,
|
|
1618
|
+
children: [
|
|
1619
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1620
|
+
className: QoderCredentialCard_module_css_default.modelChoiceName,
|
|
1621
|
+
children: model.name
|
|
1622
|
+
}),
|
|
1623
|
+
rate === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1624
|
+
className: QoderCredentialCard_module_css_default.modelRate,
|
|
1625
|
+
children: rate
|
|
1626
|
+
}),
|
|
1627
|
+
missing ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1628
|
+
className: QoderCredentialCard_module_css_default.modelMissing,
|
|
1629
|
+
children: t("modelMissingFromCatalog")
|
|
1630
|
+
}) : null
|
|
1631
|
+
]
|
|
1632
|
+
})]
|
|
1633
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1634
|
+
className: QoderCredentialCard_module_css_default.modelActions,
|
|
1635
|
+
children: missing && !enabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1636
|
+
type: "button",
|
|
1637
|
+
className: QoderCredentialCard_module_css_default.modelDelete,
|
|
1638
|
+
disabled: disabled || locked,
|
|
1639
|
+
onClick: () => {
|
|
1640
|
+
editor.edit({
|
|
1641
|
+
action: "delete",
|
|
1642
|
+
id: model.id
|
|
1643
|
+
});
|
|
1644
|
+
},
|
|
1645
|
+
children: t("modelDelete")
|
|
1646
|
+
}) : null
|
|
1647
|
+
})]
|
|
1648
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1649
|
+
className: QoderCredentialCard_module_css_default.modelDetails,
|
|
1650
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1651
|
+
className: QoderCredentialCard_module_css_default.modelMetadata,
|
|
1652
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: model.id })
|
|
1653
|
+
}), tiers.length > 1 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1654
|
+
className: QoderCredentialCard_module_css_default.modelTier,
|
|
1655
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
|
|
1656
|
+
open: openTierModelId === model.id && !tierDisabled,
|
|
1657
|
+
onClose: () => {
|
|
1658
|
+
setOpenTierModelId(void 0);
|
|
1659
|
+
},
|
|
1660
|
+
items: tiers.map((tier) => ({
|
|
1661
|
+
id: tier.key,
|
|
1662
|
+
label: tierLabel(tier)
|
|
1663
|
+
})),
|
|
1664
|
+
selectedId: selectedTier,
|
|
1665
|
+
onSelect: (key) => {
|
|
1666
|
+
setOpenTierModelId(void 0);
|
|
1667
|
+
if (!tierDisabled && key !== selectedTier && tiers.some((tier) => tier.key === key)) editor.edit({
|
|
1668
|
+
action: "selectTier",
|
|
1669
|
+
id: model.id,
|
|
1670
|
+
tierKey: key
|
|
1671
|
+
});
|
|
1672
|
+
},
|
|
1673
|
+
align: "start",
|
|
1674
|
+
portal: true,
|
|
1675
|
+
anchor: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
1676
|
+
type: "button",
|
|
1677
|
+
className: QoderCredentialCard_module_css_default.modelTierSelect,
|
|
1678
|
+
"aria-label": `${model.name} ${t("contextTierLabel")}`,
|
|
1679
|
+
"aria-haspopup": "menu",
|
|
1680
|
+
"aria-expanded": openTierModelId === model.id && !tierDisabled,
|
|
1681
|
+
disabled: tierDisabled,
|
|
1682
|
+
onClick: () => {
|
|
1683
|
+
if (!tierDisabled) setOpenTierModelId(openTierModelId === model.id ? void 0 : model.id);
|
|
1684
|
+
},
|
|
1685
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: selectedTierOption ? tierLabel(selectedTierOption) : "" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineRegular, {
|
|
1686
|
+
size: 14,
|
|
1687
|
+
"aria-hidden": "true"
|
|
1688
|
+
})]
|
|
1689
|
+
})
|
|
1690
|
+
})
|
|
1691
|
+
}) : null]
|
|
1692
|
+
})]
|
|
1693
|
+
}, model.id);
|
|
1694
|
+
})
|
|
1695
|
+
})
|
|
1696
|
+
]
|
|
1697
|
+
});
|
|
1698
|
+
}
|
|
1699
|
+
function ModelSaveStatus({ t }) {
|
|
1700
|
+
const [showSaving, setShowSaving] = (0, react.useState)(false);
|
|
1701
|
+
(0, react.useEffect)(() => {
|
|
1702
|
+
const timer = setTimeout(() => setShowSaving(true), 500);
|
|
1703
|
+
return () => clearTimeout(timer);
|
|
1704
|
+
}, []);
|
|
1705
|
+
return showSaving ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1706
|
+
className: QoderCredentialCard_module_css_default.modelCatalogMeta,
|
|
1707
|
+
role: "status",
|
|
1708
|
+
children: t("saving")
|
|
1709
|
+
}) : null;
|
|
1710
|
+
}
|
|
1711
|
+
//#endregion
|
|
1712
|
+
//#region src/client/QoderFeatureSettings.tsx
|
|
1713
|
+
function QoderFeatureSettings({ operations, snapshot, t }) {
|
|
1714
|
+
const [saving, setSaving] = (0, react.useState)(false);
|
|
1715
|
+
const [searchMenuOpen, setSearchMenuOpen] = (0, react.useState)(false);
|
|
1716
|
+
const [failed, setFailed] = (0, react.useState)();
|
|
1717
|
+
const pending = (0, react.useRef)(false);
|
|
1718
|
+
const mounted = (0, react.useRef)(true);
|
|
1719
|
+
(0, react.useLayoutEffect)(() => {
|
|
1720
|
+
mounted.current = true;
|
|
1721
|
+
return () => {
|
|
1722
|
+
mounted.current = false;
|
|
1723
|
+
};
|
|
1724
|
+
}, []);
|
|
1725
|
+
const writable = snapshot.status === "ready" && snapshot.writable && !saving;
|
|
1726
|
+
const mode = snapshot.value?.webSearchMode ?? "auto";
|
|
1727
|
+
const save = async (write) => {
|
|
1728
|
+
if (!writable || pending.current) return;
|
|
1729
|
+
pending.current = true;
|
|
1730
|
+
setSaving(true);
|
|
1731
|
+
setFailed(void 0);
|
|
1732
|
+
try {
|
|
1733
|
+
const accepted = await write();
|
|
1734
|
+
if (mounted.current) setFailed(accepted.ok ? void 0 : operationNotice(accepted.error, "featureSaveFailed"));
|
|
1735
|
+
} catch {
|
|
1736
|
+
if (mounted.current) setFailed("featureSaveFailed");
|
|
1737
|
+
} finally {
|
|
1738
|
+
pending.current = false;
|
|
1739
|
+
if (mounted.current) setSaving(false);
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
const searchModes = [
|
|
1743
|
+
["auto", "searchModeAuto"],
|
|
1744
|
+
["always", "searchModeAlways"],
|
|
1745
|
+
["disabled", "searchModeDisabled"]
|
|
1746
|
+
];
|
|
1747
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
1748
|
+
className: QoderCredentialCard_module_css_default.featureSection,
|
|
1749
|
+
"data-qoder-features": true,
|
|
1750
|
+
"aria-label": t("featuresTitle"),
|
|
1751
|
+
"aria-busy": saving,
|
|
1752
|
+
children: [
|
|
1753
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", {
|
|
1754
|
+
className: QoderCredentialCard_module_css_default.featureSectionTitle,
|
|
1755
|
+
children: t("featuresTitle")
|
|
1756
|
+
}),
|
|
1757
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1758
|
+
className: `${QoderCredentialCard_module_css_default.featureSetting} ${QoderCredentialCard_module_css_default.featureToggleRow}`,
|
|
1759
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1760
|
+
className: QoderCredentialCard_module_css_default.featureDescription,
|
|
1761
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1762
|
+
className: QoderCredentialCard_module_css_default.featureTitle,
|
|
1763
|
+
children: t("searchModeLabel")
|
|
1764
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1765
|
+
className: QoderCredentialCard_module_css_default.featureHint,
|
|
1766
|
+
children: t("searchModeHint")
|
|
1767
|
+
})]
|
|
1768
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1769
|
+
className: QoderCredentialCard_module_css_default.featureControl,
|
|
1770
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
|
|
1771
|
+
open: searchMenuOpen && writable,
|
|
1772
|
+
onClose: () => {
|
|
1773
|
+
setSearchMenuOpen(false);
|
|
1774
|
+
},
|
|
1775
|
+
items: searchModes.map(([id, label]) => ({
|
|
1776
|
+
id,
|
|
1777
|
+
label: t(label)
|
|
1778
|
+
})),
|
|
1779
|
+
selectedId: mode,
|
|
1780
|
+
onSelect: (id) => {
|
|
1781
|
+
setSearchMenuOpen(false);
|
|
1782
|
+
const selected = searchModes.find(([value]) => value === id)?.[0];
|
|
1783
|
+
if (selected !== void 0 && mode !== selected) save(() => operations.storeWebSearchMode(selected));
|
|
1784
|
+
},
|
|
1785
|
+
align: "end",
|
|
1786
|
+
portal: true,
|
|
1787
|
+
anchor: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
1788
|
+
type: "button",
|
|
1789
|
+
className: QoderCredentialCard_module_css_default.searchModeSwitcher,
|
|
1790
|
+
"aria-haspopup": "menu",
|
|
1791
|
+
"aria-expanded": searchMenuOpen && writable,
|
|
1792
|
+
"aria-label": t("searchModeLabel"),
|
|
1793
|
+
disabled: !writable,
|
|
1794
|
+
onClick: () => {
|
|
1795
|
+
if (writable) setSearchMenuOpen(!searchMenuOpen);
|
|
1796
|
+
},
|
|
1797
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1798
|
+
className: QoderCredentialCard_module_css_default.searchModeSwitcherLabel,
|
|
1799
|
+
children: t(searchModes.find(([value]) => value === mode)[1])
|
|
1800
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineRegular, {
|
|
1801
|
+
className: QoderCredentialCard_module_css_default.searchModeChevron,
|
|
1802
|
+
size: 14,
|
|
1803
|
+
"aria-hidden": "true"
|
|
1804
|
+
})]
|
|
1805
|
+
})
|
|
1806
|
+
})
|
|
1807
|
+
})]
|
|
1808
|
+
}),
|
|
1809
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1810
|
+
className: `${QoderCredentialCard_module_css_default.featureSetting} ${QoderCredentialCard_module_css_default.featureToggleRow}`,
|
|
1811
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1812
|
+
className: QoderCredentialCard_module_css_default.featureDescription,
|
|
1813
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1814
|
+
className: QoderCredentialCard_module_css_default.featureTitle,
|
|
1815
|
+
children: t("imageSearchLabel")
|
|
1816
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1817
|
+
className: QoderCredentialCard_module_css_default.featureHint,
|
|
1818
|
+
children: t("imageSearchHint")
|
|
1819
|
+
})]
|
|
1820
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, {
|
|
1821
|
+
label: t("imageSearchLabel"),
|
|
1822
|
+
title: t("imageSearchHint"),
|
|
1823
|
+
checked: snapshot.value?.imageSearchEnabled ?? true,
|
|
1824
|
+
disabled: !writable,
|
|
1825
|
+
onChange: (enabled) => {
|
|
1826
|
+
save(() => operations.storeImageSearchEnabled(enabled));
|
|
1827
|
+
}
|
|
1828
|
+
})]
|
|
1829
|
+
}),
|
|
1830
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1831
|
+
className: `${QoderCredentialCard_module_css_default.featureSetting} ${QoderCredentialCard_module_css_default.featureToggleRow}`,
|
|
1832
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1833
|
+
className: QoderCredentialCard_module_css_default.featureDescription,
|
|
1834
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1835
|
+
className: QoderCredentialCard_module_css_default.featureTitle,
|
|
1836
|
+
children: t("imageGenLabel")
|
|
1837
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1838
|
+
className: QoderCredentialCard_module_css_default.featureHint,
|
|
1839
|
+
children: t("imageGenHint")
|
|
1840
|
+
})]
|
|
1841
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, {
|
|
1842
|
+
label: t("imageGenLabel"),
|
|
1843
|
+
title: t("imageGenHint"),
|
|
1844
|
+
checked: snapshot.value?.imageGenEnabled ?? true,
|
|
1845
|
+
disabled: !writable,
|
|
1846
|
+
onChange: (enabled) => {
|
|
1847
|
+
save(() => operations.storeImageGenEnabled(enabled));
|
|
1848
|
+
}
|
|
1849
|
+
})]
|
|
1850
|
+
}),
|
|
1851
|
+
failed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1852
|
+
className: QoderCredentialCard_module_css_default.error,
|
|
1853
|
+
role: "alert",
|
|
1854
|
+
children: t(failed)
|
|
1855
|
+
}) : null
|
|
1856
|
+
]
|
|
1857
|
+
});
|
|
1858
|
+
}
|
|
1859
|
+
//#endregion
|
|
1860
|
+
//#region src/client/QoderAccountCard.tsx
|
|
1861
|
+
function formatAccountDate(locale, dateStr) {
|
|
1862
|
+
if (!dateStr) return void 0;
|
|
1863
|
+
const date = new Date(dateStr);
|
|
1864
|
+
if (Number.isNaN(date.getTime())) return void 0;
|
|
1865
|
+
return date.toLocaleString(locale, {
|
|
1866
|
+
dateStyle: "medium",
|
|
1867
|
+
timeStyle: "short"
|
|
1868
|
+
});
|
|
1869
|
+
}
|
|
1870
|
+
/**
|
|
1871
|
+
* Settings card for the Qoder subscription: credential state, subscriber
|
|
1872
|
+
* profile, and every quota block the provider reports. Region changes remount
|
|
1873
|
+
* the account state before any old profile can be displayed.
|
|
1874
|
+
*/
|
|
1875
|
+
function QoderAccountCard(props) {
|
|
1876
|
+
const modelSnapshot = (0, react.useSyncExternalStore)(props.operations.subscribeModels, props.operations.getModelSnapshot, props.operations.getModelSnapshot);
|
|
1877
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RegionAccountCard, {
|
|
1878
|
+
...props,
|
|
1879
|
+
modelSnapshot
|
|
1880
|
+
}, regionOf(modelSnapshot.value));
|
|
1881
|
+
}
|
|
1882
|
+
function RegionAccountCard({ operations, t, activeLocale, modelSnapshot }) {
|
|
1883
|
+
const [credentialState, setCredentialState] = (0, react.useState)({ status: "loading" });
|
|
1884
|
+
const [accountState, setAccountState] = (0, react.useState)({ status: "idle" });
|
|
1885
|
+
const [refreshing, setRefreshing] = (0, react.useState)(false);
|
|
1886
|
+
const latestAccountRequest = (0, react.useRef)(0);
|
|
1887
|
+
const latestCredentialRequest = (0, react.useRef)(0);
|
|
1888
|
+
const browserSubscriber = (0, react.useRef)(void 0);
|
|
1889
|
+
(0, react.useLayoutEffect)(() => () => {
|
|
1890
|
+
latestAccountRequest.current++;
|
|
1891
|
+
latestCredentialRequest.current++;
|
|
1892
|
+
}, []);
|
|
1893
|
+
const loadAccount = (0, react.useCallback)(async (force = false) => {
|
|
1894
|
+
const requestId = ++latestAccountRequest.current;
|
|
1895
|
+
if (force) {
|
|
1896
|
+
setRefreshing(true);
|
|
1897
|
+
setAccountState((current) => current.status === "ready" ? {
|
|
1898
|
+
...current,
|
|
1899
|
+
refreshFailed: false
|
|
1900
|
+
} : current);
|
|
1901
|
+
} else setAccountState({ status: "loading" });
|
|
1902
|
+
try {
|
|
1903
|
+
const result = await operations.getAccount(force);
|
|
1904
|
+
if (requestId !== latestAccountRequest.current) return;
|
|
1905
|
+
if (result?.ok) {
|
|
1906
|
+
setAccountState({
|
|
1907
|
+
status: "ready",
|
|
1908
|
+
account: result.value
|
|
1909
|
+
});
|
|
1910
|
+
return;
|
|
1911
|
+
}
|
|
1912
|
+
} catch {} finally {
|
|
1913
|
+
if (requestId === latestAccountRequest.current) setRefreshing(false);
|
|
1914
|
+
}
|
|
1915
|
+
if (requestId !== latestAccountRequest.current) return;
|
|
1916
|
+
setAccountState((current) => current.status === "ready" && force ? {
|
|
1917
|
+
...current,
|
|
1918
|
+
refreshFailed: true
|
|
1919
|
+
} : { status: "failed" });
|
|
1920
|
+
}, [operations]);
|
|
1921
|
+
const loadCredential = (0, react.useCallback)(async () => {
|
|
1922
|
+
const requestId = ++latestCredentialRequest.current;
|
|
1923
|
+
setCredentialState({ status: "loading" });
|
|
1924
|
+
const result = await operations.describe();
|
|
1925
|
+
if (requestId !== latestCredentialRequest.current) return;
|
|
1926
|
+
const info = result.ok ? result.value : void 0;
|
|
1927
|
+
const configured = info?.configured === true && !isEnvironmentCredentialSource(info.source);
|
|
1928
|
+
const subscriber = configured ? info.browserSubscriberId : void 0;
|
|
1929
|
+
const sameSubscriber = subscriber !== void 0 && subscriber === browserSubscriber.current;
|
|
1930
|
+
browserSubscriber.current = subscriber;
|
|
1931
|
+
if (!sameSubscriber) {
|
|
1932
|
+
latestAccountRequest.current++;
|
|
1933
|
+
setRefreshing(false);
|
|
1934
|
+
if (configured) loadAccount();
|
|
1935
|
+
else setAccountState({ status: "idle" });
|
|
1936
|
+
}
|
|
1937
|
+
setCredentialState(info ? {
|
|
1938
|
+
status: "ready",
|
|
1939
|
+
info
|
|
1940
|
+
} : { status: "failed" });
|
|
1941
|
+
}, [loadAccount, operations]);
|
|
1942
|
+
(0, react.useEffect)(() => {
|
|
1943
|
+
loadCredential();
|
|
1944
|
+
return operations.subscribe(() => {
|
|
1945
|
+
loadCredential();
|
|
1946
|
+
});
|
|
1947
|
+
}, [loadCredential, operations]);
|
|
1948
|
+
const configured = credentialState.status === "ready" && credentialState.info.configured && !isEnvironmentCredentialSource(credentialState.info.source);
|
|
1949
|
+
if (credentialState.status === "loading") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
|
|
1950
|
+
className: QoderCredentialCard_module_css_default.credential,
|
|
1951
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("loading") })
|
|
1952
|
+
});
|
|
1953
|
+
if (credentialState.status === "failed") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
1954
|
+
className: QoderCredentialCard_module_css_default.credential,
|
|
1955
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1956
|
+
className: QoderCredentialCard_module_css_default.error,
|
|
1957
|
+
role: "alert",
|
|
1958
|
+
children: t("loadFailed")
|
|
1959
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1960
|
+
type: "button",
|
|
1961
|
+
className: QoderCredentialCard_module_css_default.secondary,
|
|
1962
|
+
onClick: () => {
|
|
1963
|
+
loadCredential();
|
|
1964
|
+
},
|
|
1965
|
+
children: t("retry")
|
|
1966
|
+
})]
|
|
1967
|
+
});
|
|
1968
|
+
const locale = activeLocale();
|
|
1969
|
+
const formatCredits = new Intl.NumberFormat(locale, { maximumFractionDigits: 2 }).format;
|
|
1970
|
+
const renderQuota = (key, fallbackLabel, quota) => {
|
|
1971
|
+
if (!quota) return null;
|
|
1972
|
+
const { total, used, remaining, unit, modelFamilies, modelKeys } = quota;
|
|
1973
|
+
const title = resolveLocalizedText(quota.title, locale);
|
|
1974
|
+
const description = resolveLocalizedText(quota.description, locale);
|
|
1975
|
+
const expiresAt = formatAccountDate(locale, quota.expiresAt);
|
|
1976
|
+
const hasModelScope = Boolean(modelFamilies?.length || modelKeys?.length);
|
|
1977
|
+
const hasBalance = total !== void 0 || used !== void 0 || remaining !== void 0;
|
|
1978
|
+
const showAvailable = quota.available === true && !hasBalance;
|
|
1979
|
+
const label = title ?? fallbackLabel;
|
|
1980
|
+
let status;
|
|
1981
|
+
switch (quota.status) {
|
|
1982
|
+
case "QUOTA_DETAIL_STATUS_EXHAUSTED":
|
|
1983
|
+
status = t("quotaStatusExhausted");
|
|
1984
|
+
break;
|
|
1985
|
+
case "QUOTA_DETAIL_STATUS_EXPIRED":
|
|
1986
|
+
status = t("quotaStatusExpired");
|
|
1987
|
+
break;
|
|
1988
|
+
case "QUOTA_DETAIL_STATUS_SUSPENDED":
|
|
1989
|
+
status = t("quotaStatusSuspended");
|
|
1990
|
+
break;
|
|
1991
|
+
default: if (quota.available === false) status = t("quotaStatusUnavailable");
|
|
1992
|
+
}
|
|
1993
|
+
if (!hasBalance && !status && !showAvailable && !title && !description && !expiresAt && !hasModelScope) return null;
|
|
1994
|
+
const displayUnit = unit.toLowerCase() === "credits" ? "Credits" : unit;
|
|
1995
|
+
const balance = remaining === void 0 ? void 0 : t("quotaRemaining", {
|
|
1996
|
+
value: formatCredits(remaining),
|
|
1997
|
+
unit: displayUnit
|
|
1998
|
+
});
|
|
1999
|
+
const usage = used === void 0 ? total === void 0 ? void 0 : t("quotaTotal", {
|
|
2000
|
+
total: formatCredits(total),
|
|
2001
|
+
unit: displayUnit
|
|
2002
|
+
}) : total === void 0 ? t("quotaUsedOnly", {
|
|
2003
|
+
used: formatCredits(used),
|
|
2004
|
+
unit: displayUnit
|
|
2005
|
+
}) : t("quotaUsed", {
|
|
2006
|
+
used: formatCredits(used),
|
|
2007
|
+
total: formatCredits(total),
|
|
2008
|
+
unit: displayUnit
|
|
2009
|
+
});
|
|
2010
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2011
|
+
className: QoderCredentialCard_module_css_default.quotaBlock,
|
|
2012
|
+
children: [
|
|
2013
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2014
|
+
className: QoderCredentialCard_module_css_default.quotaHeader,
|
|
2015
|
+
children: [
|
|
2016
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2017
|
+
className: QoderCredentialCard_module_css_default.quotaLabel,
|
|
2018
|
+
children: label
|
|
2019
|
+
}),
|
|
2020
|
+
status ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", {
|
|
2021
|
+
className: QoderCredentialCard_module_css_default.quotaStatus,
|
|
2022
|
+
children: status
|
|
2023
|
+
}) : null,
|
|
2024
|
+
!status && showAvailable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2025
|
+
className: QoderCredentialCard_module_css_default.quotaMeta,
|
|
2026
|
+
children: t("quotaStatusAvailable")
|
|
2027
|
+
}) : null,
|
|
2028
|
+
balance ? status ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2029
|
+
className: QoderCredentialCard_module_css_default.quotaMeta,
|
|
2030
|
+
children: balance
|
|
2031
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: balance }) : null
|
|
2032
|
+
]
|
|
2033
|
+
}),
|
|
2034
|
+
usage ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2035
|
+
className: QoderCredentialCard_module_css_default.quotaTop,
|
|
2036
|
+
children: usage
|
|
2037
|
+
}) : null,
|
|
2038
|
+
total !== void 0 && total > 0 && used !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("progress", {
|
|
2039
|
+
className: QoderCredentialCard_module_css_default.quotaProgress,
|
|
2040
|
+
max: total,
|
|
2041
|
+
value: Math.max(0, Math.min(total, used)),
|
|
2042
|
+
"aria-label": `${label} ${usage}`
|
|
2043
|
+
}) : null,
|
|
2044
|
+
description ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2045
|
+
className: QoderCredentialCard_module_css_default.quotaDescription,
|
|
2046
|
+
children: description
|
|
2047
|
+
}) : null,
|
|
2048
|
+
expiresAt ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2049
|
+
className: QoderCredentialCard_module_css_default.quotaMeta,
|
|
2050
|
+
children: t("dedicatedResourceExpiresAt", { value: expiresAt })
|
|
2051
|
+
}) : null,
|
|
2052
|
+
hasModelScope ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
|
|
2053
|
+
className: QoderCredentialCard_module_css_default.quotaModelScope,
|
|
2054
|
+
children: [
|
|
2055
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("summary", { children: t("quotaModelScope") }),
|
|
2056
|
+
modelFamilies?.length ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: t("quotaModelFamilies", { value: modelFamilies.join(", ") }) }) : null,
|
|
2057
|
+
modelKeys?.length ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: t("quotaModelKeys", { value: modelKeys.join(", ") }) }) : null
|
|
2058
|
+
]
|
|
2059
|
+
}) : null
|
|
2060
|
+
]
|
|
2061
|
+
}, key);
|
|
2062
|
+
};
|
|
2063
|
+
const renderAccount = () => {
|
|
2064
|
+
if (!configured) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2065
|
+
className: QoderCredentialCard_module_css_default.accountSection,
|
|
2066
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2067
|
+
className: QoderCredentialCard_module_css_default.accountEmptyText,
|
|
2068
|
+
children: t("accountCredentialHint")
|
|
2069
|
+
})
|
|
2070
|
+
});
|
|
2071
|
+
if (accountState.status === "loading") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2072
|
+
className: QoderCredentialCard_module_css_default.accountSection,
|
|
2073
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2074
|
+
className: QoderCredentialCard_module_css_default.accountLoadingText,
|
|
2075
|
+
children: t("accountLoading")
|
|
2076
|
+
})
|
|
2077
|
+
});
|
|
2078
|
+
if (accountState.status === "failed") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2079
|
+
className: QoderCredentialCard_module_css_default.accountSection,
|
|
2080
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2081
|
+
className: QoderCredentialCard_module_css_default.accountHead,
|
|
2082
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2083
|
+
className: QoderCredentialCard_module_css_default.error,
|
|
2084
|
+
children: t("accountFailed")
|
|
2085
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2086
|
+
type: "button",
|
|
2087
|
+
className: QoderCredentialCard_module_css_default.refreshBtn,
|
|
2088
|
+
onClick: () => {
|
|
2089
|
+
loadAccount(true);
|
|
2090
|
+
},
|
|
2091
|
+
children: t("retry")
|
|
2092
|
+
})]
|
|
2093
|
+
})
|
|
2094
|
+
});
|
|
2095
|
+
if (accountState.status !== "ready") return null;
|
|
2096
|
+
const { profile, usage, plan, updatedAt } = accountState.account;
|
|
2097
|
+
const avatarInitial = (profile.name || profile.email || "Q").charAt(0).toUpperCase();
|
|
2098
|
+
const planExpiry = formatAccountDate(locale, plan?.endDate);
|
|
2099
|
+
const lastUpdated = formatAccountDate(locale, updatedAt);
|
|
2100
|
+
const isSuspended = plan?.organization?.isSuspended === true;
|
|
2101
|
+
const quotaBlocks = [
|
|
2102
|
+
renderQuota("userQuota", t("userQuotaTitle"), usage?.userQuota),
|
|
2103
|
+
renderQuota("addOnQuota", t("addOnQuotaTitle"), usage?.addOnQuota),
|
|
2104
|
+
renderQuota("orgResource", t("orgResourceTitle"), usage?.orgResourcePackage),
|
|
2105
|
+
...(usage?.dedicatedResourcePackages ?? []).map((pkg, index) => renderQuota(`dedicatedResource-${pkg.id ?? index}`, t("dedicatedResourceTitle"), pkg))
|
|
2106
|
+
].filter(Boolean);
|
|
2107
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2108
|
+
className: QoderCredentialCard_module_css_default.accountSection,
|
|
2109
|
+
children: [
|
|
2110
|
+
isSuspended ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2111
|
+
className: QoderCredentialCard_module_css_default.suspendedBanner,
|
|
2112
|
+
role: "alert",
|
|
2113
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("accountSuspended") })
|
|
2114
|
+
}) : null,
|
|
2115
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2116
|
+
className: QoderCredentialCard_module_css_default.accountHead,
|
|
2117
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2118
|
+
className: QoderCredentialCard_module_css_default.userInfo,
|
|
2119
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2120
|
+
className: QoderCredentialCard_module_css_default.avatar,
|
|
2121
|
+
"aria-hidden": "true",
|
|
2122
|
+
children: avatarInitial
|
|
2123
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2124
|
+
className: QoderCredentialCard_module_css_default.userDetails,
|
|
2125
|
+
children: [
|
|
2126
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2127
|
+
className: QoderCredentialCard_module_css_default.userNameRow,
|
|
2128
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2129
|
+
className: QoderCredentialCard_module_css_default.userName,
|
|
2130
|
+
children: profile.name || "Qoder Subscriber"
|
|
2131
|
+
}), plan?.planTierName ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2132
|
+
className: QoderCredentialCard_module_css_default.planBadge,
|
|
2133
|
+
children: plan.planTierName
|
|
2134
|
+
}) : null]
|
|
2135
|
+
}),
|
|
2136
|
+
profile.email ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2137
|
+
className: QoderCredentialCard_module_css_default.userEmail,
|
|
2138
|
+
children: profile.email
|
|
2139
|
+
}) : null,
|
|
2140
|
+
planExpiry ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2141
|
+
className: QoderCredentialCard_module_css_default.quotaMeta,
|
|
2142
|
+
children: t("planExpiresAt", { value: planExpiry })
|
|
2143
|
+
}) : null,
|
|
2144
|
+
plan?.organization?.orgName ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2145
|
+
className: QoderCredentialCard_module_css_default.orgTag,
|
|
2146
|
+
children: t("organization", { name: plan.organization.orgName })
|
|
2147
|
+
}) : null
|
|
2148
|
+
]
|
|
2149
|
+
})]
|
|
2150
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2151
|
+
type: "button",
|
|
2152
|
+
className: QoderCredentialCard_module_css_default.refreshBtn,
|
|
2153
|
+
disabled: refreshing,
|
|
2154
|
+
onClick: () => {
|
|
2155
|
+
loadAccount(true);
|
|
2156
|
+
},
|
|
2157
|
+
children: refreshing ? t("refreshing") : accountState.refreshFailed ? t("retry") : t("refresh")
|
|
2158
|
+
})]
|
|
2159
|
+
}),
|
|
2160
|
+
accountState.refreshFailed ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2161
|
+
className: QoderCredentialCard_module_css_default.accountRefreshStatus,
|
|
2162
|
+
role: "status",
|
|
2163
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2164
|
+
className: QoderCredentialCard_module_css_default.error,
|
|
2165
|
+
children: t("accountRefreshFailed")
|
|
2166
|
+
}), lastUpdated ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("time", {
|
|
2167
|
+
className: QoderCredentialCard_module_css_default.quotaMeta,
|
|
2168
|
+
dateTime: updatedAt,
|
|
2169
|
+
children: t("accountLastUpdated", { value: lastUpdated })
|
|
2170
|
+
}) : null]
|
|
2171
|
+
}) : null,
|
|
2172
|
+
usage?.isQuotaExceeded ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2173
|
+
className: QoderCredentialCard_module_css_default.error,
|
|
2174
|
+
role: "status",
|
|
2175
|
+
children: t("quotaExceeded")
|
|
2176
|
+
}) : null,
|
|
2177
|
+
quotaBlocks.length ? quotaBlocks : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2178
|
+
className: QoderCredentialCard_module_css_default.accountEmptyText,
|
|
2179
|
+
children: t("noQuota")
|
|
2180
|
+
})
|
|
2181
|
+
]
|
|
2182
|
+
});
|
|
2183
|
+
};
|
|
2184
|
+
const currentRegion = regionOf(modelSnapshot.value);
|
|
2185
|
+
const currentModels = modelsOf(modelSnapshot.value, currentRegion);
|
|
2186
|
+
const canModifyModels = modelSnapshot.status === "ready" && modelSnapshot.writable;
|
|
2187
|
+
const renderModelCatalogSection = () => {
|
|
2188
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
|
|
2189
|
+
className: QoderCredentialCard_module_css_default.customized,
|
|
2190
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("summary", {
|
|
2191
|
+
className: QoderCredentialCard_module_css_default.customizedSummary,
|
|
2192
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("modelsTitle") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2193
|
+
className: QoderCredentialCard_module_css_default.modelSummaryBadge,
|
|
2194
|
+
children: t("modelsEnabled", { count: currentModels.filter((model) => model.enabled !== false).length })
|
|
2195
|
+
})]
|
|
2196
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2197
|
+
className: QoderCredentialCard_module_css_default.customizedBody,
|
|
2198
|
+
children: modelSnapshot.status === "loading" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2199
|
+
className: QoderCredentialCard_module_css_default.hint,
|
|
2200
|
+
children: t("modelsLoading")
|
|
2201
|
+
}) : modelSnapshot.status === "unavailable" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2202
|
+
className: QoderCredentialCard_module_css_default.error,
|
|
2203
|
+
children: t("modelsUnavailable")
|
|
2204
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(QoderModelCatalog, {
|
|
2205
|
+
region: currentRegion,
|
|
2206
|
+
operations,
|
|
2207
|
+
models: currentModels,
|
|
2208
|
+
disabled: !canModifyModels,
|
|
2209
|
+
fetchDisabled: !configured,
|
|
2210
|
+
hideTitle: true,
|
|
2211
|
+
t
|
|
2212
|
+
})
|
|
2213
|
+
})]
|
|
2214
|
+
});
|
|
2215
|
+
};
|
|
2216
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
2217
|
+
className: QoderCredentialCard_module_css_default.credential,
|
|
2218
|
+
"aria-label": t("accountTitle"),
|
|
2219
|
+
children: [
|
|
2220
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2221
|
+
className: QoderCredentialCard_module_css_default.head,
|
|
2222
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
|
|
2223
|
+
className: QoderCredentialCard_module_css_default.heading,
|
|
2224
|
+
children: t("accountTitle")
|
|
2225
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2226
|
+
className: configured ? `${QoderCredentialCard_module_css_default.status} ${QoderCredentialCard_module_css_default.configured}` : QoderCredentialCard_module_css_default.status,
|
|
2227
|
+
children: configured ? t("configured") : t("missing")
|
|
2228
|
+
})]
|
|
2229
|
+
}),
|
|
2230
|
+
renderAccount(),
|
|
2231
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(QoderFeatureSettings, {
|
|
2232
|
+
operations,
|
|
2233
|
+
snapshot: modelSnapshot,
|
|
2234
|
+
t
|
|
2235
|
+
}),
|
|
2236
|
+
renderModelCatalogSection()
|
|
2237
|
+
]
|
|
2238
|
+
});
|
|
2239
|
+
}
|
|
2240
|
+
//#endregion
|
|
2241
|
+
//#region src/client/QoderBrowserLogin.tsx
|
|
2242
|
+
/** A single current identity, with browser and PAT management revealed only when needed. */
|
|
2243
|
+
function QoderBrowserLogin({ region, operations, credentials, onBusyChange, t }) {
|
|
2244
|
+
const [view, setView] = (0, react.useState)();
|
|
2245
|
+
const [pat, setPat] = (0, react.useState)();
|
|
2246
|
+
const [profile, setProfile] = (0, react.useState)();
|
|
2247
|
+
const [busy, setBusy] = (0, react.useState)(false);
|
|
2248
|
+
const [error, setError] = (0, react.useState)();
|
|
2249
|
+
const [readFailed, setReadFailed] = (0, react.useState)(false);
|
|
2250
|
+
const [editing, setEditing] = (0, react.useState)(false);
|
|
2251
|
+
const [menu, setMenu] = (0, react.useState)(false);
|
|
2252
|
+
const [draft, setDraft] = (0, react.useState)("");
|
|
2253
|
+
const [copyFailed, setCopyFailed] = (0, react.useState)(false);
|
|
2254
|
+
const [copied, setCopied] = (0, react.useState)(false);
|
|
2255
|
+
const [now, setNow] = (0, react.useState)(Date.now());
|
|
2256
|
+
const [accountRevision, setAccountRevision] = (0, react.useState)(0);
|
|
2257
|
+
const mounted = (0, react.useRef)(false);
|
|
2258
|
+
const revision = (0, react.useRef)(0);
|
|
2259
|
+
const mutating = (0, react.useRef)(false);
|
|
2260
|
+
const waitingRef = (0, react.useRef)(false);
|
|
2261
|
+
const wakeRef = (0, react.useRef)(void 0);
|
|
2262
|
+
const attempt = view?.attempt;
|
|
2263
|
+
const pending = attempt !== void 0 && [
|
|
2264
|
+
"waiting",
|
|
2265
|
+
"verifying",
|
|
2266
|
+
"saving"
|
|
2267
|
+
].includes(attempt.phase);
|
|
2268
|
+
const connected = view?.configured === true && !view.expired;
|
|
2269
|
+
const identity = view?.method === "browser" ? view.profile : profile;
|
|
2270
|
+
const patConfigured = pat?.configured === true && !isEnvironmentCredentialSource(pat.source);
|
|
2271
|
+
const remaining = Math.max(0, Math.ceil(((attempt?.expiresAt ?? now) - now) / 1e3));
|
|
2272
|
+
const read = async () => {
|
|
2273
|
+
const described = await (credentials.describePat ?? credentials.describe)();
|
|
2274
|
+
const info = described.ok ? described.value : void 0;
|
|
2275
|
+
const result = operations ? await operations.read(region) : void 0;
|
|
2276
|
+
if (result && !result.ok) throw new Error("Authorization status unavailable");
|
|
2277
|
+
if (!result && !info) throw new Error("Credential status unavailable");
|
|
2278
|
+
return {
|
|
2279
|
+
info,
|
|
2280
|
+
value: result?.value ?? {
|
|
2281
|
+
region,
|
|
2282
|
+
method: "pat",
|
|
2283
|
+
configured: info?.configured === true && !isEnvironmentCredentialSource(info.source),
|
|
2284
|
+
writable: false
|
|
2285
|
+
}
|
|
2286
|
+
};
|
|
2287
|
+
};
|
|
2288
|
+
(0, react.useEffect)(() => {
|
|
2289
|
+
mounted.current = true;
|
|
2290
|
+
let active = true;
|
|
2291
|
+
let timer;
|
|
2292
|
+
const poll = async (identityChanged = false) => {
|
|
2293
|
+
const version = revision.current;
|
|
2294
|
+
try {
|
|
2295
|
+
const result = await read();
|
|
2296
|
+
if (active && mounted.current && version === revision.current && !mutating.current) {
|
|
2297
|
+
waitingRef.current = result.value.attempt !== void 0 && [
|
|
2298
|
+
"waiting",
|
|
2299
|
+
"verifying",
|
|
2300
|
+
"saving"
|
|
2301
|
+
].includes(result.value.attempt.phase);
|
|
2302
|
+
setView(result.value);
|
|
2303
|
+
setPat(result.info);
|
|
2304
|
+
setReadFailed(false);
|
|
2305
|
+
setNow(Date.now());
|
|
2306
|
+
if (identityChanged) setAccountRevision((value) => value + 1);
|
|
2307
|
+
}
|
|
2308
|
+
} catch {
|
|
2309
|
+
if (mounted.current && version === revision.current) setReadFailed(true);
|
|
2310
|
+
}
|
|
2311
|
+
if (active && mounted.current) {
|
|
2312
|
+
clearTimeout(timer);
|
|
2313
|
+
timer = setTimeout(() => {
|
|
2314
|
+
poll();
|
|
2315
|
+
}, waitingRef.current ? 1e3 : 1e4);
|
|
2316
|
+
}
|
|
2317
|
+
};
|
|
2318
|
+
poll();
|
|
2319
|
+
wakeRef.current = () => {
|
|
2320
|
+
clearTimeout(timer);
|
|
2321
|
+
timer = setTimeout(() => {
|
|
2322
|
+
poll();
|
|
2323
|
+
}, 1e3);
|
|
2324
|
+
};
|
|
2325
|
+
const unsubscribe = credentials.subscribe?.(() => {
|
|
2326
|
+
if (mutating.current || !active) return;
|
|
2327
|
+
revision.current++;
|
|
2328
|
+
setProfile(void 0);
|
|
2329
|
+
poll(true);
|
|
2330
|
+
});
|
|
2331
|
+
return () => {
|
|
2332
|
+
active = false;
|
|
2333
|
+
mounted.current = false;
|
|
2334
|
+
wakeRef.current = void 0;
|
|
2335
|
+
clearTimeout(timer);
|
|
2336
|
+
unsubscribe?.();
|
|
2337
|
+
revision.current++;
|
|
2338
|
+
};
|
|
2339
|
+
}, [
|
|
2340
|
+
operations,
|
|
2341
|
+
credentials,
|
|
2342
|
+
region
|
|
2343
|
+
]);
|
|
2344
|
+
(0, react.useEffect)(() => {
|
|
2345
|
+
let active = true;
|
|
2346
|
+
setProfile(void 0);
|
|
2347
|
+
if (view?.method === "pat" && view.configured) {
|
|
2348
|
+
const version = revision.current;
|
|
2349
|
+
credentials.getAccount().then((result) => {
|
|
2350
|
+
if (active && version === revision.current && result?.ok) setProfile(result.value.profile);
|
|
2351
|
+
}).catch(() => {});
|
|
2352
|
+
}
|
|
2353
|
+
return () => {
|
|
2354
|
+
active = false;
|
|
2355
|
+
};
|
|
2356
|
+
}, [
|
|
2357
|
+
credentials,
|
|
2358
|
+
view?.method,
|
|
2359
|
+
view?.configured,
|
|
2360
|
+
accountRevision
|
|
2361
|
+
]);
|
|
2362
|
+
const mutate = async (action) => {
|
|
2363
|
+
if (mutating.current) return;
|
|
2364
|
+
const popup = action === "begin" ? window.open("about:blank", "_blank") : null;
|
|
2365
|
+
if (popup) popup.opener = null;
|
|
2366
|
+
const version = ++revision.current;
|
|
2367
|
+
mutating.current = true;
|
|
2368
|
+
onBusyChange?.(true);
|
|
2369
|
+
setBusy(true);
|
|
2370
|
+
setError(void 0);
|
|
2371
|
+
setMenu(false);
|
|
2372
|
+
try {
|
|
2373
|
+
let result;
|
|
2374
|
+
if (action === "savePat") if (draft.trim()) {
|
|
2375
|
+
const saved = await credentials.store(draft.trim());
|
|
2376
|
+
if (!saved.ok) {
|
|
2377
|
+
if (mounted.current && version === revision.current) {
|
|
2378
|
+
setError(operationNotice(saved.error, "patSaveFailed"));
|
|
2379
|
+
if (saved.error.completedStages.includes("persist-pat")) {
|
|
2380
|
+
setDraft("");
|
|
2381
|
+
const refreshed = await read().catch(() => void 0);
|
|
2382
|
+
if (refreshed && mounted.current && version === revision.current) {
|
|
2383
|
+
setView(refreshed.value);
|
|
2384
|
+
setPat(refreshed.info);
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
return;
|
|
2389
|
+
}
|
|
2390
|
+
} else if (patConfigured) {
|
|
2391
|
+
if (operations) {
|
|
2392
|
+
const current = await operations.read(region);
|
|
2393
|
+
if (!current.ok) {
|
|
2394
|
+
if (mounted.current && version === revision.current) setError("operationOutcomeUnknown");
|
|
2395
|
+
return;
|
|
2396
|
+
}
|
|
2397
|
+
result = current.value.method === "pat" ? current : await operations.select(region, "pat");
|
|
2398
|
+
}
|
|
2399
|
+
} else throw new Error("A PAT is required");
|
|
2400
|
+
else if (action === "removePat") {
|
|
2401
|
+
const removed = await credentials.remove();
|
|
2402
|
+
if (!removed.ok) {
|
|
2403
|
+
if (mounted.current && version === revision.current) setError(operationNotice(removed.error, "removeFailed"));
|
|
2404
|
+
return;
|
|
2405
|
+
}
|
|
2406
|
+
} else if (operations) result = action === "begin" ? await operations.begin(region) : action === "cancel" ? await operations.cancel(region) : await operations.select(region, action);
|
|
2407
|
+
if (result && !result.ok) {
|
|
2408
|
+
if (mounted.current && version === revision.current) {
|
|
2409
|
+
const code = result.error.code;
|
|
2410
|
+
setError(action === "none" ? "browserRemoveFailed" : code === "TIMEOUT" ? "browserTimeout" : code === "UNAUTHENTICATED" ? "browserRejected" : "authorizationConnectionFailed");
|
|
2411
|
+
}
|
|
2412
|
+
popup?.close();
|
|
2413
|
+
return;
|
|
2414
|
+
}
|
|
2415
|
+
const current = result?.value;
|
|
2416
|
+
if (!mounted.current || version !== revision.current) {
|
|
2417
|
+
popup?.close();
|
|
2418
|
+
return;
|
|
2419
|
+
}
|
|
2420
|
+
if (popup && current?.attempt?.url) popup.location.replace(current.attempt.url);
|
|
2421
|
+
else popup?.close();
|
|
2422
|
+
const refreshed = current ? {
|
|
2423
|
+
value: current,
|
|
2424
|
+
info: pat
|
|
2425
|
+
} : await read();
|
|
2426
|
+
if (!mounted.current || version !== revision.current) {
|
|
2427
|
+
popup?.close();
|
|
2428
|
+
return;
|
|
2429
|
+
}
|
|
2430
|
+
setView(refreshed.value);
|
|
2431
|
+
setPat(refreshed.info);
|
|
2432
|
+
setReadFailed(false);
|
|
2433
|
+
setNow(Date.now());
|
|
2434
|
+
waitingRef.current = refreshed.value.attempt !== void 0 && [
|
|
2435
|
+
"waiting",
|
|
2436
|
+
"verifying",
|
|
2437
|
+
"saving"
|
|
2438
|
+
].includes(refreshed.value.attempt.phase);
|
|
2439
|
+
if (action === "savePat" || action === "removePat") {
|
|
2440
|
+
setDraft("");
|
|
2441
|
+
setEditing(false);
|
|
2442
|
+
setProfile(void 0);
|
|
2443
|
+
setAccountRevision((value) => value + 1);
|
|
2444
|
+
}
|
|
2445
|
+
} catch {
|
|
2446
|
+
popup?.close();
|
|
2447
|
+
if (mounted.current && version === revision.current) setError(action === "savePat" ? "patSaveFailed" : action === "removePat" ? "removeFailed" : action === "none" ? "browserRemoveFailed" : "authorizationConnectionFailed");
|
|
2448
|
+
} finally {
|
|
2449
|
+
mutating.current = false;
|
|
2450
|
+
onBusyChange?.(false);
|
|
2451
|
+
if (mounted.current && version === revision.current) {
|
|
2452
|
+
revision.current++;
|
|
2453
|
+
setBusy(false);
|
|
2454
|
+
}
|
|
2455
|
+
if (mounted.current) wakeRef.current?.();
|
|
2456
|
+
}
|
|
2457
|
+
};
|
|
2458
|
+
const openPat = () => {
|
|
2459
|
+
setMenu(false);
|
|
2460
|
+
setDraft("");
|
|
2461
|
+
setError(void 0);
|
|
2462
|
+
setEditing(true);
|
|
2463
|
+
};
|
|
2464
|
+
const initial = (identity?.name || identity?.email || "Q").slice(0, 1).toUpperCase();
|
|
2465
|
+
const failure = attempt?.phase === "failed" ? attempt.failure === "storage" ? "browserStorageFailed" : attempt.failure === "connection" ? "authorizationConnectionFailed" : "browserRejected" : void 0;
|
|
2466
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2467
|
+
className: QoderCredentialCard_module_css_default.connectionBody,
|
|
2468
|
+
"aria-label": t("accountConnectionTitle"),
|
|
2469
|
+
children: [
|
|
2470
|
+
!view ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2471
|
+
role: "status",
|
|
2472
|
+
children: t(readFailed ? "authorizationConnectionFailed" : "loading")
|
|
2473
|
+
}) : null,
|
|
2474
|
+
readFailed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2475
|
+
type: "button",
|
|
2476
|
+
className: QoderCredentialCard_module_css_default.secondary,
|
|
2477
|
+
onClick: () => wakeRef.current?.(),
|
|
2478
|
+
children: t("retry")
|
|
2479
|
+
}) : null,
|
|
2480
|
+
view ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
2481
|
+
connected || view.expired ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2482
|
+
className: QoderCredentialCard_module_css_default.subscriberRow,
|
|
2483
|
+
children: [
|
|
2484
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2485
|
+
className: QoderCredentialCard_module_css_default.avatar,
|
|
2486
|
+
"aria-hidden": "true",
|
|
2487
|
+
children: initial
|
|
2488
|
+
}),
|
|
2489
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2490
|
+
className: QoderCredentialCard_module_css_default.subscriberIdentity,
|
|
2491
|
+
children: [
|
|
2492
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", {
|
|
2493
|
+
className: QoderCredentialCard_module_css_default.userName,
|
|
2494
|
+
children: identity?.name || t(view.method === "pat" ? "patActive" : "browserMethod")
|
|
2495
|
+
}),
|
|
2496
|
+
identity?.email ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: identity.email }) : null,
|
|
2497
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2498
|
+
className: QoderCredentialCard_module_css_default.label,
|
|
2499
|
+
children: t(view.method === "browser" ? "browserMethod" : "patMethod")
|
|
2500
|
+
})
|
|
2501
|
+
]
|
|
2502
|
+
}),
|
|
2503
|
+
!pending && !editing ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2504
|
+
type: "button",
|
|
2505
|
+
className: QoderCredentialCard_module_css_default.secondary,
|
|
2506
|
+
"aria-expanded": menu,
|
|
2507
|
+
"aria-controls": "qoder-account-management",
|
|
2508
|
+
disabled: busy,
|
|
2509
|
+
onClick: () => setMenu(!menu),
|
|
2510
|
+
children: t(view.method === "pat" ? "manageCredential" : "manageAccount")
|
|
2511
|
+
}) : null
|
|
2512
|
+
]
|
|
2513
|
+
}) : !pending && !editing ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2514
|
+
className: QoderCredentialCard_module_css_default.label,
|
|
2515
|
+
children: t("signInDescription")
|
|
2516
|
+
}) : null,
|
|
2517
|
+
pending ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2518
|
+
className: QoderCredentialCard_module_css_default.loginProgress,
|
|
2519
|
+
children: [
|
|
2520
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", {
|
|
2521
|
+
role: "status",
|
|
2522
|
+
"aria-live": "polite",
|
|
2523
|
+
children: t(attempt.phase === "saving" ? "browserSaving" : "browserWaiting")
|
|
2524
|
+
}),
|
|
2525
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2526
|
+
className: QoderCredentialCard_module_css_default.label,
|
|
2527
|
+
role: "timer",
|
|
2528
|
+
"aria-live": "off",
|
|
2529
|
+
children: t("loginTimeRemaining", { seconds: remaining })
|
|
2530
|
+
}),
|
|
2531
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2532
|
+
className: QoderCredentialCard_module_css_default.connectionActions,
|
|
2533
|
+
children: [
|
|
2534
|
+
attempt.url ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
2535
|
+
className: QoderCredentialCard_module_css_default.primaryLink,
|
|
2536
|
+
href: attempt.url,
|
|
2537
|
+
target: "_blank",
|
|
2538
|
+
rel: "noopener noreferrer",
|
|
2539
|
+
referrerPolicy: "no-referrer",
|
|
2540
|
+
children: t("reopenLogin")
|
|
2541
|
+
}) : null,
|
|
2542
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2543
|
+
type: "button",
|
|
2544
|
+
className: QoderCredentialCard_module_css_default.secondary,
|
|
2545
|
+
disabled: busy || !view.writable,
|
|
2546
|
+
onClick: () => {
|
|
2547
|
+
mutate("cancel");
|
|
2548
|
+
},
|
|
2549
|
+
children: t("cancelLogin")
|
|
2550
|
+
}),
|
|
2551
|
+
attempt.url ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2552
|
+
type: "button",
|
|
2553
|
+
className: QoderCredentialCard_module_css_default.textButton,
|
|
2554
|
+
onClick: () => {
|
|
2555
|
+
if (!navigator.clipboard) {
|
|
2556
|
+
setCopyFailed(true);
|
|
2557
|
+
return;
|
|
2558
|
+
}
|
|
2559
|
+
navigator.clipboard.writeText(attempt.url).then(() => {
|
|
2560
|
+
if (mounted.current) {
|
|
2561
|
+
setCopied(true);
|
|
2562
|
+
setCopyFailed(false);
|
|
2563
|
+
}
|
|
2564
|
+
}, () => {
|
|
2565
|
+
if (mounted.current) setCopyFailed(true);
|
|
2566
|
+
});
|
|
2567
|
+
},
|
|
2568
|
+
children: t(copied ? "loginLinkCopied" : "copyLogin")
|
|
2569
|
+
}) : null
|
|
2570
|
+
]
|
|
2571
|
+
})
|
|
2572
|
+
]
|
|
2573
|
+
}) : null,
|
|
2574
|
+
view.expired ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2575
|
+
role: "status",
|
|
2576
|
+
className: QoderCredentialCard_module_css_default.error,
|
|
2577
|
+
children: t("browserExpired")
|
|
2578
|
+
}) : null,
|
|
2579
|
+
view.unsaved ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2580
|
+
role: "alert",
|
|
2581
|
+
className: QoderCredentialCard_module_css_default.error,
|
|
2582
|
+
children: t("browserUnsaved")
|
|
2583
|
+
}) : null,
|
|
2584
|
+
!pending && attempt?.phase === "timeout" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2585
|
+
role: "status",
|
|
2586
|
+
className: QoderCredentialCard_module_css_default.error,
|
|
2587
|
+
children: t("browserTimeout")
|
|
2588
|
+
}) : null,
|
|
2589
|
+
!pending && failure ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2590
|
+
role: "alert",
|
|
2591
|
+
className: QoderCredentialCard_module_css_default.error,
|
|
2592
|
+
children: t(failure)
|
|
2593
|
+
}) : null,
|
|
2594
|
+
menu && !pending && !editing ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2595
|
+
id: "qoder-account-management",
|
|
2596
|
+
className: QoderCredentialCard_module_css_default.managementPanel,
|
|
2597
|
+
children: [
|
|
2598
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2599
|
+
type: "button",
|
|
2600
|
+
className: QoderCredentialCard_module_css_default.secondary,
|
|
2601
|
+
disabled: busy || !view.writable,
|
|
2602
|
+
onClick: () => {
|
|
2603
|
+
mutate("begin");
|
|
2604
|
+
},
|
|
2605
|
+
children: t("changeAccount")
|
|
2606
|
+
}),
|
|
2607
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2608
|
+
type: "button",
|
|
2609
|
+
className: QoderCredentialCard_module_css_default.secondary,
|
|
2610
|
+
disabled: busy || !pat?.writable,
|
|
2611
|
+
onClick: openPat,
|
|
2612
|
+
children: t(view.method === "pat" ? "editPat" : "usePat")
|
|
2613
|
+
}),
|
|
2614
|
+
view.method !== "browser" && view.profile ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2615
|
+
type: "button",
|
|
2616
|
+
className: QoderCredentialCard_module_css_default.secondary,
|
|
2617
|
+
disabled: busy || !view.writable,
|
|
2618
|
+
onClick: () => {
|
|
2619
|
+
mutate("browser");
|
|
2620
|
+
},
|
|
2621
|
+
children: t("useBrowser")
|
|
2622
|
+
}) : null,
|
|
2623
|
+
view.profile ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2624
|
+
type: "button",
|
|
2625
|
+
className: `${QoderCredentialCard_module_css_default.textButton} ${QoderCredentialCard_module_css_default.dangerText}`,
|
|
2626
|
+
disabled: busy || !view.writable,
|
|
2627
|
+
onClick: () => {
|
|
2628
|
+
mutate("none");
|
|
2629
|
+
},
|
|
2630
|
+
children: t("signOutQoder")
|
|
2631
|
+
}) : null
|
|
2632
|
+
]
|
|
2633
|
+
}) : null,
|
|
2634
|
+
!pending && !editing && (!connected || view.expired) ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2635
|
+
className: QoderCredentialCard_module_css_default.connectionActions,
|
|
2636
|
+
children: [
|
|
2637
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2638
|
+
type: "button",
|
|
2639
|
+
className: QoderCredentialCard_module_css_default.primary,
|
|
2640
|
+
disabled: busy || !view.writable,
|
|
2641
|
+
onClick: () => {
|
|
2642
|
+
mutate("begin");
|
|
2643
|
+
},
|
|
2644
|
+
children: t(view.expired ? "signInAgain" : "signInQoder")
|
|
2645
|
+
}),
|
|
2646
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2647
|
+
type: "button",
|
|
2648
|
+
className: QoderCredentialCard_module_css_default.textButton,
|
|
2649
|
+
disabled: busy || !pat?.writable,
|
|
2650
|
+
onClick: openPat,
|
|
2651
|
+
children: t("usePat")
|
|
2652
|
+
}),
|
|
2653
|
+
view.profile && view.method !== "browser" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2654
|
+
type: "button",
|
|
2655
|
+
className: QoderCredentialCard_module_css_default.textButton,
|
|
2656
|
+
disabled: busy || !view.writable,
|
|
2657
|
+
onClick: () => {
|
|
2658
|
+
mutate("browser");
|
|
2659
|
+
},
|
|
2660
|
+
children: t("useBrowser")
|
|
2661
|
+
}) : null
|
|
2662
|
+
]
|
|
2663
|
+
}) : null,
|
|
2664
|
+
editing ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2665
|
+
className: QoderCredentialCard_module_css_default.editor,
|
|
2666
|
+
children: [
|
|
2667
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
2668
|
+
className: QoderCredentialCard_module_css_default.label,
|
|
2669
|
+
htmlFor: "qoder-managed-credential",
|
|
2670
|
+
children: t("tokenLabel")
|
|
2671
|
+
}),
|
|
2672
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
2673
|
+
id: "qoder-managed-credential",
|
|
2674
|
+
className: QoderCredentialCard_module_css_default.input,
|
|
2675
|
+
type: "password",
|
|
2676
|
+
autoComplete: "new-password",
|
|
2677
|
+
value: draft,
|
|
2678
|
+
disabled: busy || !pat?.writable,
|
|
2679
|
+
placeholder: patConfigured ? t("configuredHint") : t("tokenPlaceholder"),
|
|
2680
|
+
onChange: (event) => setDraft(event.currentTarget.value)
|
|
2681
|
+
}),
|
|
2682
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2683
|
+
className: QoderCredentialCard_module_css_default.connectionActions,
|
|
2684
|
+
children: [
|
|
2685
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2686
|
+
type: "button",
|
|
2687
|
+
className: QoderCredentialCard_module_css_default.primary,
|
|
2688
|
+
disabled: busy || !pat?.writable || !draft.trim() && !patConfigured,
|
|
2689
|
+
onClick: () => {
|
|
2690
|
+
mutate("savePat");
|
|
2691
|
+
},
|
|
2692
|
+
children: t(busy ? "saving" : draft.trim() || !patConfigured ? "saveAndUsePat" : "useSavedPat")
|
|
2693
|
+
}),
|
|
2694
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2695
|
+
type: "button",
|
|
2696
|
+
className: QoderCredentialCard_module_css_default.secondary,
|
|
2697
|
+
disabled: busy,
|
|
2698
|
+
onClick: () => {
|
|
2699
|
+
setDraft("");
|
|
2700
|
+
setEditing(false);
|
|
2701
|
+
setError(void 0);
|
|
2702
|
+
},
|
|
2703
|
+
children: t("cancel")
|
|
2704
|
+
}),
|
|
2705
|
+
patConfigured ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2706
|
+
type: "button",
|
|
2707
|
+
className: QoderCredentialCard_module_css_default.danger,
|
|
2708
|
+
disabled: busy || !pat?.writable,
|
|
2709
|
+
onClick: () => {
|
|
2710
|
+
if (window.confirm(t("confirmRemove"))) mutate("removePat");
|
|
2711
|
+
},
|
|
2712
|
+
children: t("remove")
|
|
2713
|
+
}) : null
|
|
2714
|
+
]
|
|
2715
|
+
})
|
|
2716
|
+
]
|
|
2717
|
+
}) : null
|
|
2718
|
+
] }) : null,
|
|
2719
|
+
view && !view.writable && !pat?.writable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2720
|
+
className: QoderCredentialCard_module_css_default.label,
|
|
2721
|
+
children: t("readOnly")
|
|
2722
|
+
}) : null,
|
|
2723
|
+
copyFailed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2724
|
+
role: "alert",
|
|
2725
|
+
className: QoderCredentialCard_module_css_default.error,
|
|
2726
|
+
children: t("copyLoginFailed")
|
|
2727
|
+
}) : null,
|
|
2728
|
+
error ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2729
|
+
role: "alert",
|
|
2730
|
+
className: QoderCredentialCard_module_css_default.error,
|
|
2731
|
+
children: t(error)
|
|
2732
|
+
}) : null,
|
|
2733
|
+
readFailed && view ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2734
|
+
role: "alert",
|
|
2735
|
+
className: QoderCredentialCard_module_css_default.error,
|
|
2736
|
+
children: t("authorizationConnectionFailed")
|
|
2737
|
+
}) : null
|
|
2738
|
+
]
|
|
2739
|
+
});
|
|
2740
|
+
}
|
|
2741
|
+
//#endregion
|
|
2742
|
+
//#region src/client/QoderCredentialCard.tsx
|
|
2743
|
+
/** Region selection stays outside the keyed account state, so old identities never flash. */
|
|
2744
|
+
function QoderCredentialCard({ operations, t }) {
|
|
2745
|
+
const snapshot = (0, react.useSyncExternalStore)(operations.subscribeModels, operations.getModelSnapshot, operations.getModelSnapshot);
|
|
2746
|
+
const region = regionOf(snapshot.value);
|
|
2747
|
+
const [changing, setChanging] = (0, react.useState)(false);
|
|
2748
|
+
const [accountBusy, setAccountBusy] = (0, react.useState)(false);
|
|
2749
|
+
const [notice, setNotice] = (0, react.useState)();
|
|
2750
|
+
const mutating = (0, react.useRef)(false);
|
|
2751
|
+
const canChange = snapshot.status === "ready" && snapshot.writable && !changing && !accountBusy;
|
|
2752
|
+
const changeRegion = async (next) => {
|
|
2753
|
+
if (!canChange || next === region || mutating.current) return;
|
|
2754
|
+
mutating.current = true;
|
|
2755
|
+
setChanging(true);
|
|
2756
|
+
setNotice(void 0);
|
|
2757
|
+
try {
|
|
2758
|
+
const result = await operations.storeRegion(next);
|
|
2759
|
+
setNotice(result.ok ? "regionChanged" : operationNotice(result.error, "regionChangeFailed"));
|
|
2760
|
+
} catch {
|
|
2761
|
+
setNotice("regionChangeFailed");
|
|
2762
|
+
} finally {
|
|
2763
|
+
mutating.current = false;
|
|
2764
|
+
setChanging(false);
|
|
2765
|
+
}
|
|
2766
|
+
};
|
|
2767
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
2768
|
+
className: `${QoderCredentialCard_module_css_default.credential} ${QoderCredentialCard_module_css_default.credentialEditor}`,
|
|
2769
|
+
"aria-label": t("accountConnectionTitle"),
|
|
2770
|
+
children: [
|
|
2771
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2772
|
+
className: QoderCredentialCard_module_css_default.connectionHead,
|
|
2773
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", {
|
|
2774
|
+
className: QoderCredentialCard_module_css_default.credentialName,
|
|
2775
|
+
children: t("accountConnectionTitle")
|
|
2776
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2777
|
+
className: QoderCredentialCard_module_css_default.regionGroup,
|
|
2778
|
+
role: "radiogroup",
|
|
2779
|
+
"aria-label": t("regionLabel"),
|
|
2780
|
+
children: ["global", "china"].map((value) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2781
|
+
type: "button",
|
|
2782
|
+
role: "radio",
|
|
2783
|
+
"aria-checked": region === value,
|
|
2784
|
+
disabled: !canChange,
|
|
2785
|
+
className: `${QoderCredentialCard_module_css_default.regionOption} ${region === value ? QoderCredentialCard_module_css_default.regionOptionActive : ""}`,
|
|
2786
|
+
onClick: () => {
|
|
2787
|
+
changeRegion(value);
|
|
2788
|
+
},
|
|
2789
|
+
children: t(value === "china" ? "regionChina" : "regionGlobal")
|
|
2790
|
+
}, value))
|
|
2791
|
+
})]
|
|
2792
|
+
}),
|
|
2793
|
+
notice ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2794
|
+
role: "status",
|
|
2795
|
+
className: notice !== "regionChanged" ? QoderCredentialCard_module_css_default.error : QoderCredentialCard_module_css_default.label,
|
|
2796
|
+
children: t(notice)
|
|
2797
|
+
}) : null,
|
|
2798
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(QoderBrowserLogin, {
|
|
2799
|
+
region,
|
|
2800
|
+
operations: operations.authorization,
|
|
2801
|
+
credentials: operations,
|
|
2802
|
+
onBusyChange: setAccountBusy,
|
|
2803
|
+
t
|
|
2804
|
+
}, region),
|
|
2805
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2806
|
+
className: QoderCredentialCard_module_css_default.sharedNote,
|
|
2807
|
+
children: t("sharedAuthorization")
|
|
2808
|
+
})
|
|
2809
|
+
]
|
|
2810
|
+
});
|
|
2811
|
+
}
|
|
2812
|
+
//#endregion
|
|
2813
|
+
//#region src/client/context-selection.ts
|
|
2814
|
+
function isQoderProvider(provider) {
|
|
2815
|
+
return [
|
|
2816
|
+
QODER_PROVIDER_ID,
|
|
2817
|
+
"qoder-official",
|
|
2818
|
+
"qoder",
|
|
2819
|
+
"qoder-subscription"
|
|
2820
|
+
].includes(provider ?? "");
|
|
2821
|
+
}
|
|
2822
|
+
//#endregion
|
|
2823
|
+
//#region src/client/session-tier-state.ts
|
|
2824
|
+
/** A mounted view of the host's accepted selection; it owns no manual tier map. */
|
|
2825
|
+
var SessionTierState = class {
|
|
2826
|
+
snapshot = {
|
|
2827
|
+
loading: true,
|
|
2828
|
+
saving: false,
|
|
2829
|
+
error: false
|
|
2830
|
+
};
|
|
2831
|
+
listeners = /* @__PURE__ */ new Set();
|
|
2832
|
+
generation = 0;
|
|
2833
|
+
readGeneration = 0;
|
|
2834
|
+
active = false;
|
|
2835
|
+
lifetime = 0;
|
|
2836
|
+
revalidateRequested = false;
|
|
2837
|
+
preserveQueuedReadError = false;
|
|
2838
|
+
inFlightRead;
|
|
2839
|
+
unsubscribe;
|
|
2840
|
+
scope;
|
|
2841
|
+
operations;
|
|
2842
|
+
constructor(scope, operations) {
|
|
2843
|
+
this.scope = scope;
|
|
2844
|
+
this.operations = operations;
|
|
2845
|
+
}
|
|
2846
|
+
getSnapshot = () => this.snapshot;
|
|
2847
|
+
subscribe = (listener) => {
|
|
2848
|
+
this.listeners.add(listener);
|
|
2849
|
+
return () => {
|
|
2850
|
+
this.listeners.delete(listener);
|
|
2851
|
+
};
|
|
2852
|
+
};
|
|
2853
|
+
publish(value) {
|
|
2854
|
+
this.snapshot = {
|
|
2855
|
+
...this.snapshot,
|
|
2856
|
+
...value
|
|
2857
|
+
};
|
|
2858
|
+
for (const listener of this.listeners) listener();
|
|
2859
|
+
}
|
|
2860
|
+
activate() {
|
|
2861
|
+
this.active = true;
|
|
2862
|
+
this.lifetime++;
|
|
2863
|
+
this.publish({ saving: false });
|
|
2864
|
+
this.unsubscribe = this.operations.subscribeSessionTiers?.(this.scope, () => {
|
|
2865
|
+
this.revalidate();
|
|
2866
|
+
});
|
|
2867
|
+
this.refresh();
|
|
2868
|
+
}
|
|
2869
|
+
dispose() {
|
|
2870
|
+
this.active = false;
|
|
2871
|
+
this.generation++;
|
|
2872
|
+
this.readGeneration++;
|
|
2873
|
+
this.revalidateRequested = false;
|
|
2874
|
+
this.preserveQueuedReadError = false;
|
|
2875
|
+
this.inFlightRead = void 0;
|
|
2876
|
+
this.unsubscribe?.();
|
|
2877
|
+
this.unsubscribe = void 0;
|
|
2878
|
+
}
|
|
2879
|
+
matches(value) {
|
|
2880
|
+
return !!value && value.region === this.scope.region && value.sessionId === this.scope.sessionId && value.modelId === this.scope.modelId;
|
|
2881
|
+
}
|
|
2882
|
+
async read(loading, preserveError = false) {
|
|
2883
|
+
if (!this.active) return;
|
|
2884
|
+
const generation = this.generation;
|
|
2885
|
+
const readGeneration = ++this.readGeneration;
|
|
2886
|
+
const inFlightRead = { loading };
|
|
2887
|
+
this.inFlightRead = inFlightRead;
|
|
2888
|
+
if (loading) this.publish({
|
|
2889
|
+
loading: true,
|
|
2890
|
+
operationError: void 0
|
|
2891
|
+
});
|
|
2892
|
+
try {
|
|
2893
|
+
const result = await this.operations.readSessionTier?.(this.scope);
|
|
2894
|
+
const selection = result?.ok ? result.value : void 0;
|
|
2895
|
+
if (this.active && generation === this.generation && readGeneration === this.readGeneration && !this.snapshot.saving) {
|
|
2896
|
+
this.publish(this.matches(selection) ? {
|
|
2897
|
+
selection,
|
|
2898
|
+
loading: false,
|
|
2899
|
+
...preserveError ? {} : {
|
|
2900
|
+
error: false,
|
|
2901
|
+
operationError: void 0
|
|
2902
|
+
}
|
|
2903
|
+
} : {
|
|
2904
|
+
loading: false,
|
|
2905
|
+
error: true,
|
|
2906
|
+
...preserveError ? {} : { operationError: result && !result.ok ? result.error : void 0 }
|
|
2907
|
+
});
|
|
2908
|
+
this.startQueuedRevalidation();
|
|
2909
|
+
}
|
|
2910
|
+
} catch {
|
|
2911
|
+
if (this.active && generation === this.generation && readGeneration === this.readGeneration && !this.snapshot.saving) {
|
|
2912
|
+
this.publish({
|
|
2913
|
+
loading: false,
|
|
2914
|
+
error: true
|
|
2915
|
+
});
|
|
2916
|
+
this.startQueuedRevalidation();
|
|
2917
|
+
}
|
|
2918
|
+
} finally {
|
|
2919
|
+
if (this.inFlightRead === inFlightRead) this.inFlightRead = void 0;
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2922
|
+
startQueuedRevalidation() {
|
|
2923
|
+
if (!this.revalidateRequested || !this.active || this.snapshot.saving) return;
|
|
2924
|
+
const preserveError = this.preserveQueuedReadError;
|
|
2925
|
+
this.revalidateRequested = false;
|
|
2926
|
+
this.preserveQueuedReadError = false;
|
|
2927
|
+
this.read(false, preserveError);
|
|
2928
|
+
}
|
|
2929
|
+
async refresh() {
|
|
2930
|
+
if (!this.active) return;
|
|
2931
|
+
if (this.snapshot.saving) {
|
|
2932
|
+
this.revalidateRequested = true;
|
|
2933
|
+
return;
|
|
2934
|
+
}
|
|
2935
|
+
this.generation++;
|
|
2936
|
+
await this.read(true);
|
|
2937
|
+
}
|
|
2938
|
+
/** Refresh host state after an external change without disabling a usable control. */
|
|
2939
|
+
async revalidate() {
|
|
2940
|
+
if (!this.active) return;
|
|
2941
|
+
if (this.snapshot.saving) {
|
|
2942
|
+
this.revalidateRequested = true;
|
|
2943
|
+
return;
|
|
2944
|
+
}
|
|
2945
|
+
await this.read(false);
|
|
2946
|
+
}
|
|
2947
|
+
async select(tierKey) {
|
|
2948
|
+
if (!this.active || this.snapshot.loading || this.snapshot.saving || !this.snapshot.selection) return;
|
|
2949
|
+
if (tierKey === this.snapshot.selection.tierKey && !this.snapshot.error) return;
|
|
2950
|
+
if (this.inFlightRead?.loading === false) this.revalidateRequested = true;
|
|
2951
|
+
const generation = ++this.generation;
|
|
2952
|
+
this.readGeneration++;
|
|
2953
|
+
const lifetime = this.lifetime;
|
|
2954
|
+
let writeFailed = false;
|
|
2955
|
+
this.preserveQueuedReadError = false;
|
|
2956
|
+
this.publish({
|
|
2957
|
+
saving: true,
|
|
2958
|
+
error: false,
|
|
2959
|
+
operationError: void 0
|
|
2960
|
+
});
|
|
2961
|
+
try {
|
|
2962
|
+
const { sessionId, modelId, region } = this.scope;
|
|
2963
|
+
const result = await this.operations.setSessionTier?.(sessionId, modelId, tierKey, region);
|
|
2964
|
+
const selection = result?.ok ? result.value : void 0;
|
|
2965
|
+
if (this.active && generation === this.generation) if (this.matches(selection)) this.publish({
|
|
2966
|
+
selection,
|
|
2967
|
+
error: false,
|
|
2968
|
+
operationError: void 0
|
|
2969
|
+
});
|
|
2970
|
+
else {
|
|
2971
|
+
writeFailed = true;
|
|
2972
|
+
this.publish({
|
|
2973
|
+
error: true,
|
|
2974
|
+
operationError: result && !result.ok ? result.error : void 0
|
|
2975
|
+
});
|
|
2976
|
+
}
|
|
2977
|
+
} catch {
|
|
2978
|
+
writeFailed = true;
|
|
2979
|
+
if (this.active && generation === this.generation) this.publish({ error: true });
|
|
2980
|
+
} finally {
|
|
2981
|
+
if (this.active && lifetime === this.lifetime) {
|
|
2982
|
+
if (writeFailed && this.revalidateRequested) this.preserveQueuedReadError = true;
|
|
2983
|
+
this.publish({ saving: false });
|
|
2984
|
+
this.startQueuedRevalidation();
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
}
|
|
2988
|
+
};
|
|
2989
|
+
//#endregion
|
|
2990
|
+
//#region \0dsh-css:src/client/QoderContextSelect.module.css.mjs
|
|
2991
|
+
const css = ".C6TPYW_root{align-items:center;display:inline-flex;position:relative}.C6TPYW_trigger{height:28px;color:var(--dsw-alias-label-secondary);cursor:pointer;user-select:none;background:0 0;border:none;border-radius:24px;outline:none;align-items:center;gap:4px;padding:0 8px;font-size:13px;font-weight:500;line-height:20px;transition:background .12s,color .12s;display:flex}.C6TPYW_trigger:hover,.C6TPYW_triggerActive{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.C6TPYW_trigger:focus-visible{box-shadow:0 0 0 2px var(--dsw-alias-border-l3)}.C6TPYW_icon{color:var(--dsw-alias-label-caption);justify-content:center;align-items:center;display:inline-flex}.C6TPYW_label{white-space:nowrap}.C6TPYW_chevron{color:var(--dsw-alias-label-caption);align-items:center;transition:transform .12s;display:inline-flex}.C6TPYW_chevronOpen{transform:rotate(180deg)}.C6TPYW_menu{z-index:1100;background:var(--dsw-menu-surface-fill);min-width:180px;backdrop-filter:var(--dsw-menu-backdrop-filter);border:1px solid var(--dsw-alias-border-l1);box-shadow:var(--dsw-elevation-prominent);color:var(--dsw-alias-label-primary);border-radius:14px;flex-direction:column;padding:4px;animation:.12s C6TPYW_fadeIn;display:flex;position:absolute;bottom:calc(100% + 8px);right:0}@keyframes C6TPYW_fadeIn{0%{opacity:0;transform:translateY(4px)}to{opacity:1;transform:translateY(0)}}.C6TPYW_menuHeader{text-transform:uppercase;letter-spacing:.5px;color:var(--dsw-alias-label-tertiary);border-bottom:1px solid var(--dsw-alias-border-l1);margin-bottom:4px;padding:6px 10px 4px;font-size:11px;font-weight:600}.C6TPYW_option{box-sizing:border-box;width:100%;color:inherit;cursor:pointer;text-align:left;background:0 0;border:none;border-radius:8px;justify-content:space-between;align-items:center;gap:8px;padding:6px 10px;font-size:13px;line-height:20px;transition:background .1s;display:flex}.C6TPYW_option:hover{background:var(--dsw-alias-interactive-bg-hover)}.C6TPYW_optionSelected{color:var(--dsw-alias-state-brand);font-weight:600}.C6TPYW_optionInfo{align-items:center;gap:6px;display:flex}.C6TPYW_tag{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-caption);border-radius:4px;padding:1px 5px;font-size:11px;font-weight:500}.C6TPYW_check{color:var(--dsw-alias-state-brand);align-items:center;font-size:12px;display:inline-flex}.C6TPYW_error{color:var(--dsw-alias-label-primary);max-width:240px;font-size:12px}";
|
|
2992
|
+
const tagId = "dsh-subscription-qoder/QoderContextSelect.module.css";
|
|
2993
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
|
2994
|
+
const tag = document.createElement("style");
|
|
2995
|
+
tag.dataset.plugin = "dsh-subscription-qoder";
|
|
2996
|
+
tag.dataset.pluginCss = tagId;
|
|
2997
|
+
tag.textContent = css;
|
|
2998
|
+
document.head.appendChild(tag);
|
|
2999
|
+
}
|
|
3000
|
+
var QoderContextSelect_module_css_default = {
|
|
3001
|
+
"check": "C6TPYW_check",
|
|
3002
|
+
"chevron": "C6TPYW_chevron",
|
|
3003
|
+
"chevronOpen": "C6TPYW_chevronOpen",
|
|
3004
|
+
"error": "C6TPYW_error",
|
|
3005
|
+
"fadeIn": "C6TPYW_fadeIn",
|
|
3006
|
+
"icon": "C6TPYW_icon",
|
|
3007
|
+
"label": "C6TPYW_label",
|
|
3008
|
+
"menu": "C6TPYW_menu",
|
|
3009
|
+
"menuHeader": "C6TPYW_menuHeader",
|
|
3010
|
+
"option": "C6TPYW_option",
|
|
3011
|
+
"optionInfo": "C6TPYW_optionInfo",
|
|
3012
|
+
"optionSelected": "C6TPYW_optionSelected",
|
|
3013
|
+
"root": "C6TPYW_root",
|
|
3014
|
+
"tag": "C6TPYW_tag",
|
|
3015
|
+
"trigger": "C6TPYW_trigger",
|
|
3016
|
+
"triggerActive": "C6TPYW_triggerActive"
|
|
3017
|
+
};
|
|
3018
|
+
//#endregion
|
|
3019
|
+
//#region src/client/QoderContextSelect.tsx
|
|
3020
|
+
function QoderContextSelect(props) {
|
|
3021
|
+
const { directory, operations, sessionId, useProjection } = props;
|
|
3022
|
+
const directoryState = (0, react.useSyncExternalStore)((fn) => directory ? directory.subscribe(fn) : () => () => {}, () => directory ? directory.getSnapshot() : null);
|
|
3023
|
+
const modelSnapshot = (0, react.useSyncExternalStore)((fn) => operations ? operations.subscribeModels(fn) : () => () => {}, () => operations ? operations.getModelSnapshot() : null);
|
|
3024
|
+
const modelProj = useProjection ? useProjection("modelSelection") : void 0;
|
|
3025
|
+
const pressure = useProjection ? useProjection("contextPressure") : void 0;
|
|
3026
|
+
if (!operations || !directoryState) return null;
|
|
3027
|
+
const projectedCurrent = modelProj?.next ?? modelProj?.lastUsed;
|
|
3028
|
+
const current = directoryState?.current ?? (projectedCurrent?.model ? {
|
|
3029
|
+
provider: projectedCurrent.provider ?? "dsh-provider-qoder",
|
|
3030
|
+
model: projectedCurrent.model
|
|
3031
|
+
} : null);
|
|
3032
|
+
if (!current) return null;
|
|
3033
|
+
const region = regionOf(modelSnapshot?.value);
|
|
3034
|
+
const models = modelsOf(modelSnapshot?.value, region);
|
|
3035
|
+
const currentModelId = current.model.includes("/") ? current.model.split("/")[1] : current.model;
|
|
3036
|
+
const currentProviderId = current.provider ?? (current.model.includes("/") ? current.model.split("/")[0] : void 0);
|
|
3037
|
+
const activeModel = models.find((m) => m.id === currentModelId || m.id === current.model);
|
|
3038
|
+
if (!isQoderProvider(currentProviderId) || !activeModel) return null;
|
|
3039
|
+
if (contextTiersOf(activeModel).length <= 1) return null;
|
|
3040
|
+
if (!sessionId) return null;
|
|
3041
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SessionContextSelect, {
|
|
3042
|
+
...props,
|
|
3043
|
+
sessionId,
|
|
3044
|
+
operations,
|
|
3045
|
+
region,
|
|
3046
|
+
activeModel,
|
|
3047
|
+
historicalWindow: pressure?.contextWindow,
|
|
3048
|
+
lastUsed: modelProj?.lastUsed
|
|
3049
|
+
}, JSON.stringify([
|
|
3050
|
+
region,
|
|
3051
|
+
sessionId,
|
|
3052
|
+
activeModel.id
|
|
3053
|
+
]));
|
|
3054
|
+
}
|
|
3055
|
+
function SessionContextSelect({ operations, sessionId, region, activeModel, t, historicalWindow, lastUsed }) {
|
|
3056
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
3057
|
+
const [focusedIndex, setFocusedIndex] = (0, react.useState)(0);
|
|
3058
|
+
const rootRef = (0, react.useRef)(null);
|
|
3059
|
+
const triggerRef = (0, react.useRef)(null);
|
|
3060
|
+
const itemRefs = (0, react.useRef)([]);
|
|
3061
|
+
const focusedIndexRef = (0, react.useRef)(0);
|
|
3062
|
+
const state = (0, react.useMemo)(() => new SessionTierState({
|
|
3063
|
+
region,
|
|
3064
|
+
sessionId,
|
|
3065
|
+
modelId: activeModel.id
|
|
3066
|
+
}, operations), [
|
|
3067
|
+
region,
|
|
3068
|
+
sessionId,
|
|
3069
|
+
activeModel.id,
|
|
3070
|
+
operations
|
|
3071
|
+
]);
|
|
3072
|
+
const snapshot = (0, react.useSyncExternalStore)(state.subscribe, state.getSnapshot);
|
|
3073
|
+
(0, react.useLayoutEffect)(() => {
|
|
3074
|
+
state.activate();
|
|
3075
|
+
return () => state.dispose();
|
|
3076
|
+
}, [state]);
|
|
3077
|
+
(0, react.useEffect)(() => {
|
|
3078
|
+
state.revalidate();
|
|
3079
|
+
}, [
|
|
3080
|
+
state,
|
|
3081
|
+
JSON.stringify(activeModel),
|
|
3082
|
+
historicalWindow,
|
|
3083
|
+
lastUsed?.provider,
|
|
3084
|
+
lastUsed?.model
|
|
3085
|
+
]);
|
|
3086
|
+
(0, react.useEffect)(() => {
|
|
3087
|
+
if (!open) return;
|
|
3088
|
+
const handleClickOutside = (e) => {
|
|
3089
|
+
if (rootRef.current && !rootRef.current.contains(e.target)) setOpen(false);
|
|
3090
|
+
};
|
|
3091
|
+
const handleKeyDown = (e) => {
|
|
3092
|
+
if (e.key === "Escape") {
|
|
3093
|
+
setOpen(false);
|
|
3094
|
+
triggerRef.current?.focus();
|
|
3095
|
+
}
|
|
3096
|
+
};
|
|
3097
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
3098
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
3099
|
+
return () => {
|
|
3100
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
3101
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
3102
|
+
};
|
|
3103
|
+
}, [open]);
|
|
3104
|
+
const tiers = contextTiersOf(activeModel);
|
|
3105
|
+
const currentTier = snapshot.selection;
|
|
3106
|
+
const selectedTierKey = currentTier?.tierKey;
|
|
3107
|
+
const pending = snapshot.loading || snapshot.saving;
|
|
3108
|
+
const focusMenuItem = (index) => {
|
|
3109
|
+
if (!tiers.length) return;
|
|
3110
|
+
const next = (index + tiers.length) % tiers.length;
|
|
3111
|
+
focusedIndexRef.current = next;
|
|
3112
|
+
setFocusedIndex(next);
|
|
3113
|
+
itemRefs.current[next]?.focus();
|
|
3114
|
+
};
|
|
3115
|
+
(0, react.useLayoutEffect)(() => {
|
|
3116
|
+
if (!open || pending) return;
|
|
3117
|
+
const selectedIndex = tiers.findIndex((tier) => tier.key === selectedTierKey);
|
|
3118
|
+
focusMenuItem(selectedIndex >= 0 ? selectedIndex : 0);
|
|
3119
|
+
}, [open]);
|
|
3120
|
+
const closeMenu = (restoreTrigger) => {
|
|
3121
|
+
setOpen(false);
|
|
3122
|
+
if (restoreTrigger) triggerRef.current?.focus();
|
|
3123
|
+
};
|
|
3124
|
+
const selectTier = (tierKey) => {
|
|
3125
|
+
if (pending) return;
|
|
3126
|
+
setOpen(false);
|
|
3127
|
+
triggerRef.current?.focus();
|
|
3128
|
+
if (tierKey !== selectedTierKey || snapshot.error) state.select(tierKey);
|
|
3129
|
+
};
|
|
3130
|
+
const handleMenuKeyDown = (e) => {
|
|
3131
|
+
if (!tiers.length || pending) return;
|
|
3132
|
+
if (e.key === "Tab") return;
|
|
3133
|
+
if (e.key === "Escape") {
|
|
3134
|
+
e.preventDefault();
|
|
3135
|
+
closeMenu(true);
|
|
3136
|
+
return;
|
|
3137
|
+
}
|
|
3138
|
+
if (e.key === "ArrowDown") {
|
|
3139
|
+
e.preventDefault();
|
|
3140
|
+
focusMenuItem(focusedIndexRef.current + 1);
|
|
3141
|
+
} else if (e.key === "ArrowUp") {
|
|
3142
|
+
e.preventDefault();
|
|
3143
|
+
focusMenuItem(focusedIndexRef.current - 1);
|
|
3144
|
+
} else if (e.key === "Home") {
|
|
3145
|
+
e.preventDefault();
|
|
3146
|
+
focusMenuItem(0);
|
|
3147
|
+
} else if (e.key === "End") {
|
|
3148
|
+
e.preventDefault();
|
|
3149
|
+
focusMenuItem(tiers.length - 1);
|
|
3150
|
+
}
|
|
3151
|
+
};
|
|
3152
|
+
const handleRootBlur = (e) => {
|
|
3153
|
+
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
3154
|
+
if (open) setOpen(false);
|
|
3155
|
+
}
|
|
3156
|
+
};
|
|
3157
|
+
const defaultSuffix = t ? t("contextTierDefaultSuffix").replace(/[()()]/g, "") : "默认";
|
|
3158
|
+
const selectTitle = t ? t("contextSelectTitle") : "选择上下文大小";
|
|
3159
|
+
const menuHeader = t ? t("contextSelectMenuHeader") : "上下文容量";
|
|
3160
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3161
|
+
className: QoderContextSelect_module_css_default.root,
|
|
3162
|
+
ref: rootRef,
|
|
3163
|
+
onBlurCapture: handleRootBlur,
|
|
3164
|
+
children: [
|
|
3165
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
3166
|
+
type: "button",
|
|
3167
|
+
className: `${QoderContextSelect_module_css_default.trigger} ${open ? QoderContextSelect_module_css_default.triggerActive : ""}`,
|
|
3168
|
+
ref: (element) => {
|
|
3169
|
+
triggerRef.current = element;
|
|
3170
|
+
},
|
|
3171
|
+
disabled: !currentTier,
|
|
3172
|
+
"aria-disabled": pending || !currentTier,
|
|
3173
|
+
"aria-haspopup": "menu",
|
|
3174
|
+
"aria-expanded": open,
|
|
3175
|
+
"aria-label": selectTitle,
|
|
3176
|
+
title: `${selectTitle}: ${currentTier ? formatContextTokens(currentTier.tokenCount) : "…"}`,
|
|
3177
|
+
onClick: () => {
|
|
3178
|
+
if (!pending && currentTier) setOpen((prev) => !prev);
|
|
3179
|
+
},
|
|
3180
|
+
children: [
|
|
3181
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3182
|
+
className: QoderContextSelect_module_css_default.icon,
|
|
3183
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
3184
|
+
width: "14",
|
|
3185
|
+
height: "14",
|
|
3186
|
+
viewBox: "0 0 16 16",
|
|
3187
|
+
fill: "currentColor",
|
|
3188
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M2 4.5A2.5 2.5 0 0 1 4.5 2h7A2.5 2.5 0 0 1 14 4.5v7a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 2 11.5v-7zm2.5-1A1.5 1.5 0 0 0 3 4.5v7A1.5 1.5 0 0 0 4.5 13h7a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 11.5 3.5h-7zM5 6h6v1H5V6zm0 3h4v1H5V9z" })
|
|
3189
|
+
})
|
|
3190
|
+
}),
|
|
3191
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3192
|
+
className: QoderContextSelect_module_css_default.label,
|
|
3193
|
+
children: currentTier ? formatContextTokens(currentTier.tokenCount) : "…"
|
|
3194
|
+
}),
|
|
3195
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3196
|
+
className: `${QoderContextSelect_module_css_default.chevron} ${open ? QoderContextSelect_module_css_default.chevronOpen : ""}`,
|
|
3197
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
3198
|
+
width: "10",
|
|
3199
|
+
height: "10",
|
|
3200
|
+
viewBox: "0 0 12 12",
|
|
3201
|
+
fill: "none",
|
|
3202
|
+
stroke: "currentColor",
|
|
3203
|
+
strokeWidth: "1.5",
|
|
3204
|
+
strokeLinecap: "round",
|
|
3205
|
+
strokeLinejoin: "round",
|
|
3206
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M3 4.5L6 7.5L9 4.5" })
|
|
3207
|
+
})
|
|
3208
|
+
})
|
|
3209
|
+
]
|
|
3210
|
+
}),
|
|
3211
|
+
snapshot.error && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3212
|
+
className: QoderContextSelect_module_css_default.error,
|
|
3213
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3214
|
+
role: "alert",
|
|
3215
|
+
children: t ? t(snapshot.operationError?.outcome === "unknown" ? "operationOutcomeUnknown" : "contextSelectFailed") : "contextSelectFailed"
|
|
3216
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
3217
|
+
type: "button",
|
|
3218
|
+
disabled: pending,
|
|
3219
|
+
onClick: () => {
|
|
3220
|
+
state.refresh();
|
|
3221
|
+
},
|
|
3222
|
+
children: t ? t("refresh") : "refresh"
|
|
3223
|
+
})]
|
|
3224
|
+
}),
|
|
3225
|
+
open && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3226
|
+
className: QoderContextSelect_module_css_default.menu,
|
|
3227
|
+
role: "menu",
|
|
3228
|
+
"aria-label": selectTitle,
|
|
3229
|
+
onKeyDown: handleMenuKeyDown,
|
|
3230
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3231
|
+
className: QoderContextSelect_module_css_default.menuHeader,
|
|
3232
|
+
children: menuHeader
|
|
3233
|
+
}), tiers.map((tier, index) => {
|
|
3234
|
+
const isSelected = tier.key === selectedTierKey;
|
|
3235
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
3236
|
+
type: "button",
|
|
3237
|
+
role: "menuitemradio",
|
|
3238
|
+
ref: (element) => {
|
|
3239
|
+
itemRefs.current[index] = element;
|
|
3240
|
+
},
|
|
3241
|
+
disabled: pending,
|
|
3242
|
+
"aria-checked": isSelected,
|
|
3243
|
+
tabIndex: index === focusedIndex ? 0 : -1,
|
|
3244
|
+
className: `${QoderContextSelect_module_css_default.option} ${isSelected ? QoderContextSelect_module_css_default.optionSelected : ""}`,
|
|
3245
|
+
onFocus: () => {
|
|
3246
|
+
focusedIndexRef.current = index;
|
|
3247
|
+
setFocusedIndex(index);
|
|
3248
|
+
},
|
|
3249
|
+
onClick: () => {
|
|
3250
|
+
selectTier(tier.key);
|
|
3251
|
+
},
|
|
3252
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3253
|
+
className: QoderContextSelect_module_css_default.optionInfo,
|
|
3254
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: formatContextTokens(tier.tokenCount) }), tier.isDefault && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3255
|
+
className: QoderContextSelect_module_css_default.tag,
|
|
3256
|
+
children: defaultSuffix
|
|
3257
|
+
})]
|
|
3258
|
+
}), isSelected && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3259
|
+
className: QoderContextSelect_module_css_default.check,
|
|
3260
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
3261
|
+
width: "14",
|
|
3262
|
+
height: "14",
|
|
3263
|
+
viewBox: "0 0 16 16",
|
|
3264
|
+
fill: "none",
|
|
3265
|
+
stroke: "currentColor",
|
|
3266
|
+
strokeWidth: "2",
|
|
3267
|
+
strokeLinecap: "round",
|
|
3268
|
+
strokeLinejoin: "round",
|
|
3269
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M3.5 8.5L6.5 11.5L12.5 4.5" })
|
|
3270
|
+
})
|
|
3271
|
+
})]
|
|
3272
|
+
}, tier.key);
|
|
3273
|
+
})]
|
|
3274
|
+
})
|
|
3275
|
+
]
|
|
3276
|
+
});
|
|
3277
|
+
}
|
|
3278
|
+
//#endregion
|
|
3279
|
+
//#region src/client/session-tier-events.ts
|
|
3280
|
+
const maxEventLineBytes = 64 * 1024;
|
|
3281
|
+
/** One authenticated host change stream shared by the mounted composer controls. */
|
|
3282
|
+
function createSessionTierEvents(send) {
|
|
3283
|
+
const events = createQoderChangeEvents("sessionTierEvents", (value) => {
|
|
3284
|
+
if ((value.region === "global" || value.region === "china") && typeof value.sessionId === "string" && typeof value.modelId === "string") return {
|
|
3285
|
+
region: value.region,
|
|
3286
|
+
sessionId: value.sessionId,
|
|
3287
|
+
modelId: value.modelId
|
|
3288
|
+
};
|
|
3289
|
+
}, send);
|
|
3290
|
+
return {
|
|
3291
|
+
subscribe(scope, listener) {
|
|
3292
|
+
return events.subscribe((item) => {
|
|
3293
|
+
if (!item || item.region === scope.region && item.sessionId === scope.sessionId && item.modelId === scope.modelId) listener();
|
|
3294
|
+
});
|
|
3295
|
+
},
|
|
3296
|
+
dispose: events.dispose
|
|
3297
|
+
};
|
|
3298
|
+
}
|
|
3299
|
+
function createQoderChangeEvents(endpoint, decode, send = (...args) => globalThis.fetch(...args)) {
|
|
3300
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
3301
|
+
let active;
|
|
3302
|
+
let disposed = false;
|
|
3303
|
+
const notify = (item) => {
|
|
3304
|
+
for (const listener of listeners) try {
|
|
3305
|
+
listener(item);
|
|
3306
|
+
} catch {}
|
|
3307
|
+
};
|
|
3308
|
+
const start = () => {
|
|
3309
|
+
if (active || disposed || !listeners.size) return;
|
|
3310
|
+
const controller = new AbortController();
|
|
3311
|
+
active = controller;
|
|
3312
|
+
follow(controller).finally(() => {
|
|
3313
|
+
if (active === controller) active = void 0;
|
|
3314
|
+
});
|
|
3315
|
+
};
|
|
3316
|
+
async function follow(controller) {
|
|
3317
|
+
let delay = 1e3;
|
|
3318
|
+
while (!controller.signal.aborted) {
|
|
3319
|
+
try {
|
|
3320
|
+
const response = await send(qoderRpcPath(endpoint), {
|
|
3321
|
+
method: "POST",
|
|
3322
|
+
credentials: "include",
|
|
3323
|
+
signal: controller.signal,
|
|
3324
|
+
headers: { "content-type": "application/json" },
|
|
3325
|
+
body: "{}"
|
|
3326
|
+
});
|
|
3327
|
+
if (!response.ok || !response.body) throw new Error("Qoder settings event stream unavailable");
|
|
3328
|
+
const reader = response.body.getReader();
|
|
3329
|
+
const decoder = new TextDecoder();
|
|
3330
|
+
const encoder = new TextEncoder();
|
|
3331
|
+
let line = "";
|
|
3332
|
+
let lineBytes = 0;
|
|
3333
|
+
let droppingOversizedLine = false;
|
|
3334
|
+
const resetLine = () => {
|
|
3335
|
+
line = "";
|
|
3336
|
+
lineBytes = 0;
|
|
3337
|
+
droppingOversizedLine = false;
|
|
3338
|
+
};
|
|
3339
|
+
const consume = (text) => {
|
|
3340
|
+
let offset = 0;
|
|
3341
|
+
while (offset < text.length && !controller.signal.aborted) {
|
|
3342
|
+
const newline = text.indexOf("\n", offset);
|
|
3343
|
+
const end = newline < 0 ? text.length : newline;
|
|
3344
|
+
const segment = text.slice(offset, end);
|
|
3345
|
+
if (!droppingOversizedLine) {
|
|
3346
|
+
const segmentBytes = encoder.encode(segment).byteLength;
|
|
3347
|
+
if (lineBytes + segmentBytes > maxEventLineBytes) {
|
|
3348
|
+
delay = 1e3;
|
|
3349
|
+
notify();
|
|
3350
|
+
line = "";
|
|
3351
|
+
lineBytes = 0;
|
|
3352
|
+
droppingOversizedLine = true;
|
|
3353
|
+
} else {
|
|
3354
|
+
line += segment;
|
|
3355
|
+
lineBytes += segmentBytes;
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3358
|
+
if (newline < 0) return;
|
|
3359
|
+
if (!droppingOversizedLine && line.length > 0) try {
|
|
3360
|
+
const item = JSON.parse(line);
|
|
3361
|
+
if (item !== null && typeof item === "object" && !Array.isArray(item)) {
|
|
3362
|
+
const value = item;
|
|
3363
|
+
delay = 1e3;
|
|
3364
|
+
if (value.ready === true && endpoint === "sessionTierEvents") notify();
|
|
3365
|
+
const decoded = decode(value);
|
|
3366
|
+
if (decoded !== void 0) notify(decoded);
|
|
3367
|
+
}
|
|
3368
|
+
} catch {}
|
|
3369
|
+
resetLine();
|
|
3370
|
+
offset = newline + 1;
|
|
3371
|
+
}
|
|
3372
|
+
};
|
|
3373
|
+
try {
|
|
3374
|
+
while (!controller.signal.aborted) {
|
|
3375
|
+
const { value, done } = await reader.read();
|
|
3376
|
+
if (done || controller.signal.aborted) break;
|
|
3377
|
+
consume(decoder.decode(value, { stream: true }));
|
|
3378
|
+
}
|
|
3379
|
+
if (!controller.signal.aborted) consume(decoder.decode());
|
|
3380
|
+
} finally {
|
|
3381
|
+
await reader.cancel().catch(() => {});
|
|
3382
|
+
reader.releaseLock();
|
|
3383
|
+
}
|
|
3384
|
+
} catch {}
|
|
3385
|
+
if (controller.signal.aborted) break;
|
|
3386
|
+
if (endpoint === "catalogEvents") notify();
|
|
3387
|
+
if (controller.signal.aborted) break;
|
|
3388
|
+
await new Promise((resolve) => {
|
|
3389
|
+
const finish = () => {
|
|
3390
|
+
clearTimeout(timer);
|
|
3391
|
+
controller.signal.removeEventListener("abort", finish);
|
|
3392
|
+
resolve();
|
|
3393
|
+
};
|
|
3394
|
+
const timer = setTimeout(finish, delay);
|
|
3395
|
+
controller.signal.addEventListener("abort", finish, { once: true });
|
|
3396
|
+
});
|
|
3397
|
+
delay = Math.min(delay * 2, 3e4);
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
return {
|
|
3401
|
+
subscribe(listener) {
|
|
3402
|
+
listeners.add(listener);
|
|
3403
|
+
start();
|
|
3404
|
+
return () => {
|
|
3405
|
+
listeners.delete(listener);
|
|
3406
|
+
if (!listeners.size) {
|
|
3407
|
+
active?.abort();
|
|
3408
|
+
active = void 0;
|
|
3409
|
+
}
|
|
3410
|
+
};
|
|
3411
|
+
},
|
|
3412
|
+
dispose() {
|
|
3413
|
+
disposed = true;
|
|
3414
|
+
listeners.clear();
|
|
3415
|
+
active?.abort();
|
|
3416
|
+
active = void 0;
|
|
3417
|
+
}
|
|
3418
|
+
};
|
|
3419
|
+
}
|
|
3420
|
+
//#endregion
|
|
3421
|
+
//#region src/client/catalog-events.ts
|
|
3422
|
+
function decodeStatus(item) {
|
|
3423
|
+
const { region, refreshing, failure } = item;
|
|
3424
|
+
if ((region === "global" || region === "china") && typeof refreshing === "boolean") return {
|
|
3425
|
+
region,
|
|
3426
|
+
refreshing,
|
|
3427
|
+
failure: failure === "fetch" || failure === "save" ? failure : void 0
|
|
3428
|
+
};
|
|
3429
|
+
}
|
|
3430
|
+
function createCatalogEvents(rpc, send) {
|
|
3431
|
+
const events = createQoderChangeEvents("catalogEvents", decodeStatus, send);
|
|
3432
|
+
const subscriptions = /* @__PURE__ */ new Map();
|
|
3433
|
+
const streamed = /* @__PURE__ */ new Map();
|
|
3434
|
+
let unsubscribeStream;
|
|
3435
|
+
function publish(subscription, status) {
|
|
3436
|
+
if (subscription.status?.refreshing === status?.refreshing && subscription.status?.failure === status?.failure) return;
|
|
3437
|
+
subscription.status = status;
|
|
3438
|
+
for (const listener of subscription.listeners) try {
|
|
3439
|
+
listener(status);
|
|
3440
|
+
} catch {}
|
|
3441
|
+
}
|
|
3442
|
+
function stopPolling(subscription) {
|
|
3443
|
+
subscription.poll?.abort();
|
|
3444
|
+
subscription.poll = void 0;
|
|
3445
|
+
clearTimeout(subscription.retry);
|
|
3446
|
+
subscription.retry = void 0;
|
|
3447
|
+
}
|
|
3448
|
+
async function poll(region, subscription) {
|
|
3449
|
+
if (subscriptions.get(region) !== subscription || subscription.streaming || subscription.poll || subscription.retry !== void 0) return;
|
|
3450
|
+
const controller = new AbortController();
|
|
3451
|
+
subscription.poll = controller;
|
|
3452
|
+
const timeout = setTimeout(() => controller.abort(), 3e3);
|
|
3453
|
+
try {
|
|
3454
|
+
const result = await rpc.call("catalogStatus", { region }, controller.signal);
|
|
3455
|
+
if (!controller.signal.aborted && result.ok && result.value?.region === region && typeof result.value.refreshing === "boolean") publish(subscription, result.value);
|
|
3456
|
+
} catch {} finally {
|
|
3457
|
+
clearTimeout(timeout);
|
|
3458
|
+
if (subscription.poll === controller) {
|
|
3459
|
+
subscription.poll = void 0;
|
|
3460
|
+
subscription.retry = setTimeout(() => {
|
|
3461
|
+
subscription.retry = void 0;
|
|
3462
|
+
poll(region, subscription);
|
|
3463
|
+
}, 1e3);
|
|
3464
|
+
}
|
|
3465
|
+
}
|
|
3466
|
+
}
|
|
3467
|
+
function onEvent(status) {
|
|
3468
|
+
if (status) {
|
|
3469
|
+
streamed.set(status.region, status);
|
|
3470
|
+
const subscription = subscriptions.get(status.region);
|
|
3471
|
+
if (!subscription) return;
|
|
3472
|
+
subscription.streaming = true;
|
|
3473
|
+
stopPolling(subscription);
|
|
3474
|
+
publish(subscription, status);
|
|
3475
|
+
return;
|
|
3476
|
+
}
|
|
3477
|
+
streamed.clear();
|
|
3478
|
+
for (const [region, subscription] of subscriptions) {
|
|
3479
|
+
if (subscription.streaming) publish(subscription, void 0);
|
|
3480
|
+
subscription.streaming = false;
|
|
3481
|
+
poll(region, subscription);
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
return {
|
|
3485
|
+
subscribe(region, listener) {
|
|
3486
|
+
let subscription = subscriptions.get(region);
|
|
3487
|
+
if (!subscription) {
|
|
3488
|
+
const status = streamed.get(region);
|
|
3489
|
+
subscription = {
|
|
3490
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
3491
|
+
status,
|
|
3492
|
+
streaming: status !== void 0
|
|
3493
|
+
};
|
|
3494
|
+
subscriptions.set(region, subscription);
|
|
3495
|
+
}
|
|
3496
|
+
subscription.listeners.add(listener);
|
|
3497
|
+
listener(subscription.status);
|
|
3498
|
+
unsubscribeStream ??= events.subscribe(onEvent);
|
|
3499
|
+
poll(region, subscription);
|
|
3500
|
+
return () => {
|
|
3501
|
+
if (!subscription.listeners.delete(listener) || subscription.listeners.size) return;
|
|
3502
|
+
stopPolling(subscription);
|
|
3503
|
+
subscriptions.delete(region);
|
|
3504
|
+
if (!subscriptions.size) {
|
|
3505
|
+
unsubscribeStream?.();
|
|
3506
|
+
unsubscribeStream = void 0;
|
|
3507
|
+
streamed.clear();
|
|
3508
|
+
}
|
|
3509
|
+
};
|
|
3510
|
+
},
|
|
3511
|
+
dispose() {
|
|
3512
|
+
events.dispose();
|
|
3513
|
+
unsubscribeStream = void 0;
|
|
3514
|
+
for (const subscription of subscriptions.values()) stopPolling(subscription);
|
|
3515
|
+
subscriptions.clear();
|
|
3516
|
+
streamed.clear();
|
|
3517
|
+
}
|
|
3518
|
+
};
|
|
3519
|
+
}
|
|
3520
|
+
//#endregion
|
|
3521
|
+
//#region src/client/rpc-client.ts
|
|
3522
|
+
/**
|
|
3523
|
+
* Browser caller for the Qoder settings RPC.
|
|
3524
|
+
*
|
|
3525
|
+
* Requests go to Connection's shared `/api` channel, which the connection
|
|
3526
|
+
* plugin mounts itself and guards with its Host/Origin fence and browser
|
|
3527
|
+
* authentication; the caller only has to carry the session cookie.
|
|
3528
|
+
*/
|
|
3529
|
+
/**
|
|
3530
|
+
* Create the caller used by the account card and the model catalog.
|
|
3531
|
+
*
|
|
3532
|
+
* Failures are returned rather than thrown so the cards keep their existing
|
|
3533
|
+
* "result or undefined" handling: a transport status becomes a transport
|
|
3534
|
+
* failure message, and an endpoint failure keeps the provider's own message.
|
|
3535
|
+
*/
|
|
3536
|
+
function createQoderRpcCaller(transport = {}) {
|
|
3537
|
+
const send = transport.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
3538
|
+
return { async call(endpoint, payload, signal) {
|
|
3539
|
+
const path = qoderRpcPath(endpoint);
|
|
3540
|
+
let phase = "serialize";
|
|
3541
|
+
try {
|
|
3542
|
+
const body = JSON.stringify(payload ?? {});
|
|
3543
|
+
phase = "send";
|
|
3544
|
+
const response = await send(path, {
|
|
3545
|
+
method: "POST",
|
|
3546
|
+
headers: { "content-type": "application/json" },
|
|
3547
|
+
credentials: "include",
|
|
3548
|
+
body,
|
|
3549
|
+
...signal === void 0 ? {} : { signal }
|
|
3550
|
+
});
|
|
3551
|
+
phase = "decode";
|
|
3552
|
+
if (!response.ok) return {
|
|
3553
|
+
ok: false,
|
|
3554
|
+
error: {
|
|
3555
|
+
code: signal?.aborted ? "ABORTED" : "UPSTREAM_ERROR",
|
|
3556
|
+
message: `transport failure for ${path}: HTTP ${response.status}`,
|
|
3557
|
+
details: { status: response.status }
|
|
3558
|
+
}
|
|
3559
|
+
};
|
|
3560
|
+
const envelope = await response.json();
|
|
3561
|
+
if (envelope?.ok === true) return {
|
|
3562
|
+
ok: true,
|
|
3563
|
+
value: envelope.value
|
|
3564
|
+
};
|
|
3565
|
+
const rawError = envelope?.error;
|
|
3566
|
+
let code = "INTERNAL";
|
|
3567
|
+
let message = "RPC returned error";
|
|
3568
|
+
let details;
|
|
3569
|
+
if (typeof rawError === "string") message = rawError;
|
|
3570
|
+
else if (typeof rawError === "object" && rawError !== null) {
|
|
3571
|
+
const errObj = rawError;
|
|
3572
|
+
if (isQoderRpcErrorCode(errObj.code)) code = errObj.code;
|
|
3573
|
+
if (typeof errObj.message === "string") message = errObj.message;
|
|
3574
|
+
if (typeof errObj.details === "object" && errObj.details !== null) details = errObj.details;
|
|
3575
|
+
}
|
|
3576
|
+
if (code === "INTERNAL" && signal?.aborted) code = "ABORTED";
|
|
3577
|
+
return {
|
|
3578
|
+
ok: false,
|
|
3579
|
+
error: {
|
|
3580
|
+
code,
|
|
3581
|
+
message,
|
|
3582
|
+
...details === void 0 ? {} : { details }
|
|
3583
|
+
}
|
|
3584
|
+
};
|
|
3585
|
+
} catch (error) {
|
|
3586
|
+
const name = typeof error === "object" && error !== null && "name" in error ? error.name : void 0;
|
|
3587
|
+
return {
|
|
3588
|
+
ok: false,
|
|
3589
|
+
error: {
|
|
3590
|
+
code: signal?.aborted || name === "AbortError" ? "ABORTED" : name === "TimeoutError" ? "TIMEOUT" : "INTERNAL",
|
|
3591
|
+
...phase === "send" && (name === "TypeError" || name === "NetworkError") ? { details: { cause: "connection" } } : {},
|
|
3592
|
+
message: error instanceof Error ? error.message : String(error)
|
|
3593
|
+
}
|
|
3594
|
+
};
|
|
3595
|
+
}
|
|
3596
|
+
} };
|
|
3597
|
+
}
|
|
3598
|
+
//#endregion
|
|
3599
|
+
//#region src/client/QoderSettingsNavIcon.tsx
|
|
3600
|
+
const mask = `url("data:image/svg+xml,${encodeURIComponent("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg width=\"304pt\" height=\"304pt\" viewBox=\"0 0 304 304\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n<defs>\n <!-- Reduce each edge by 0.13px at the navigation's 16px display size. -->\n <filter id=\"qoder-nav-weight\" x=\"0\" y=\"0\" width=\"304\" height=\"304\" filterUnits=\"userSpaceOnUse\">\n <feMorphology in=\"SourceGraphic\" operator=\"erode\" radius=\"2.5\" />\n </filter>\n</defs>\n<g filter=\"url(#qoder-nav-weight)\">\n<path fill=\"#0f0d0c\" opacity=\"1.00\" d=\" M 191.00 129.00 L 190.22 128.71 L 190.00 101.00 C 190.00 99.14 189.06 93.72 191.00 93.00 C 198.51 89.58 206.37 86.77 214.61 85.73 C 227.25 83.09 240.44 86.25 250.42 94.49 C 260.39 102.74 266.18 115.04 265.97 128.01 L 266.00 179.00 L 266.78 179.29 L 266.78 260.71 L 266.00 261.00 C 265.84 265.35 261.11 267.15 257.41 265.77 L 233.62 255.16 L 228.13 254.92 L 202.82 266.71 L 186.09 270.92 C 172.95 273.84 159.24 270.32 149.04 261.58 C 138.84 252.84 133.44 239.79 134.31 226.41 L 148.01 215.98 L 158.59 205.60 L 168.83 192.82 L 177.90 177.92 L 185.11 160.95 L 189.04 145.90 L 191.00 129.00 Z M 164.00 111.00 C 165.57 111.58 165.57 126.42 164.00 127.00 C 162.89 151.76 152.07 175.06 134.00 192.00 C 132.43 191.42 132.43 175.58 134.00 175.00 C 135.72 150.69 146.34 127.83 164.00 111.00 Z M 34.00 171.00 L 33.22 170.71 L 33.00 134.00 C 33.00 132.02 32.31 124.63 34.00 124.00 C 34.18 113.18 36.33 102.46 40.61 92.50 L 46.84 79.83 L 54.47 68.50 L 63.46 58.46 L 73.08 50.05 L 84.00 43.00 L 95.84 37.76 C 109.61 31.29 125.26 31.06 139.57 35.62 L 192.90 63.26 L 178.56 68.44 L 164.95 75.88 L 153.81 83.81 L 139.92 96.96 L 129.29 110.40 L 120.97 124.15 L 115.53 135.73 L 111.11 148.28 L 107.94 163.12 C 106.82 176.38 106.26 189.70 107.00 203.00 C 105.87 215.92 106.91 228.88 108.95 241.64 L 53.16 211.86 C 40.47 202.23 33.10 187.01 34.00 171.00 Z M 175.00 298.00 L 180.00 298.00 C 197.66 296.83 215.08 292.43 230.65 283.82 C 233.63 283.12 248.26 291.38 252.73 292.52 C 261.63 294.51 270.94 292.74 278.51 287.65 C 286.07 282.56 291.19 274.58 292.69 265.60 L 293.00 139.00 L 292.33 122.84 L 289.71 109.35 L 284.66 96.34 L 277.79 85.22 L 269.74 76.26 L 260.10 68.84 L 150.72 11.21 C 137.22 5.68 122.39 4.08 108.03 6.84 L 90.38 11.26 L 76.68 16.64 L 66.41 22.31 L 54.62 30.57 L 44.50 39.50 C 23.50 60.02 10.56 87.29 7.28 116.39 L 7.41 179.45 C 8.85 202.65 21.53 223.63 41.24 235.88 L 148.01 292.19 C 156.42 296.30 165.71 298.01 175.00 298.00 Z\" />\n<path fill=\"#100e0d\" opacity=\"1.00\" d=\" M 266.00 261.00 L 266.78 260.71 L 266.78 179.29 L 266.00 179.00 L 266.00 261.00 Z\" />\n<path fill=\"#100d0c\" opacity=\"1.00\" d=\" M 34.00 171.00 L 34.00 124.00 C 32.31 124.63 33.00 132.02 33.00 134.00 L 33.22 170.71 L 34.00 171.00 Z\" />\n<path fill=\"#0f0d0d\" opacity=\"1.00\" d=\" M 191.00 129.00 L 191.00 93.00 C 189.06 93.72 190.00 99.14 190.00 101.00 L 190.22 128.71 L 191.00 129.00 Z\" />\n<path fill=\"#100d0c\" opacity=\"1.00\" d=\" M 134.00 192.00 L 134.00 175.00 C 132.43 175.58 132.43 191.42 134.00 192.00 Z\" />\n<path fill=\"#100e0d\" opacity=\"1.00\" d=\" M 164.00 127.00 C 165.57 126.42 165.57 111.58 164.00 111.00 L 164.00 127.00 Z\" />\n<path fill=\"#100e0c\" opacity=\"1.00\" d=\" M 180.00 298.00 L 175.00 298.00 C 176.14 298.89 178.86 298.89 180.00 298.00 Z\" />\n</g>\n</svg>\n")}") center / contain no-repeat`;
|
|
3601
|
+
function QoderSettingsNavIcon({ size }) {
|
|
3602
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3603
|
+
"aria-hidden": "true",
|
|
3604
|
+
style: {
|
|
3605
|
+
display: "inline-block",
|
|
3606
|
+
width: size,
|
|
3607
|
+
height: size,
|
|
3608
|
+
backgroundColor: "currentColor",
|
|
3609
|
+
WebkitMask: mask,
|
|
3610
|
+
mask
|
|
3611
|
+
}
|
|
3612
|
+
});
|
|
3613
|
+
}
|
|
3614
|
+
//#endregion
|
|
3615
|
+
//#region src/client/settings-bootstrap.ts
|
|
3616
|
+
const bootstrapAttempts = 3;
|
|
3617
|
+
const bootstrapRequestTimeout = 5e3;
|
|
3618
|
+
const bootstrapRetryDelays = [250, 500];
|
|
3619
|
+
function transientBootstrapFailure(result) {
|
|
3620
|
+
if (result.ok) return false;
|
|
3621
|
+
if (result.error.code === "TIMEOUT") return true;
|
|
3622
|
+
const details = result.error.details;
|
|
3623
|
+
const status = details?.status;
|
|
3624
|
+
if (typeof status === "number" && (status === 429 || status >= 500 && status <= 599)) return true;
|
|
3625
|
+
return details?.cause === "connection";
|
|
3626
|
+
}
|
|
3627
|
+
function bootstrapFailure(result, attempts) {
|
|
3628
|
+
if (result.ok) return /* @__PURE__ */ new Error("Qoder settings namespace bootstrap returned no failure.");
|
|
3629
|
+
return /* @__PURE__ */ new Error(`Qoder settings namespace bootstrap failed after ${attempts} attempt${attempts === 1 ? "" : "s"} (${result.error.code}): ${result.error.message}`);
|
|
3630
|
+
}
|
|
3631
|
+
function waitForBootstrapRetry(signal, delay) {
|
|
3632
|
+
if (signal.aborted) return Promise.resolve(false);
|
|
3633
|
+
return new Promise((resolve) => {
|
|
3634
|
+
let settled = false;
|
|
3635
|
+
let timer;
|
|
3636
|
+
const finish = (value) => {
|
|
3637
|
+
if (settled) return;
|
|
3638
|
+
settled = true;
|
|
3639
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
3640
|
+
signal.removeEventListener("abort", onAbort);
|
|
3641
|
+
resolve(value);
|
|
3642
|
+
};
|
|
3643
|
+
const onAbort = () => finish(false);
|
|
3644
|
+
timer = setTimeout(() => finish(true), delay);
|
|
3645
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
3646
|
+
if (signal.aborted) finish(false);
|
|
3647
|
+
});
|
|
3648
|
+
}
|
|
3649
|
+
async function runBootstrapAttempt(rpc, signal) {
|
|
3650
|
+
if (signal.aborted) return { kind: "aborted" };
|
|
3651
|
+
const attempt = new AbortController();
|
|
3652
|
+
const forwardAbort = () => attempt.abort();
|
|
3653
|
+
signal.addEventListener("abort", forwardAbort, { once: true });
|
|
3654
|
+
let timeout;
|
|
3655
|
+
let timedOut = false;
|
|
3656
|
+
const request = rpc.call("bootstrap", {}, attempt.signal).then((result) => timedOut ? { kind: "timeout" } : {
|
|
3657
|
+
kind: "result",
|
|
3658
|
+
result
|
|
3659
|
+
}, (error) => timedOut ? { kind: "timeout" } : signal.aborted || error instanceof Error && error.name === "AbortError" ? { kind: "aborted" } : {
|
|
3660
|
+
kind: "result",
|
|
3661
|
+
result: {
|
|
3662
|
+
ok: false,
|
|
3663
|
+
error: {
|
|
3664
|
+
code: "INTERNAL",
|
|
3665
|
+
message: error instanceof Error ? error.message : String(error),
|
|
3666
|
+
details: { cause: "connection" }
|
|
3667
|
+
}
|
|
3668
|
+
}
|
|
3669
|
+
});
|
|
3670
|
+
const timeoutResult = new Promise((resolve) => {
|
|
3671
|
+
timeout = setTimeout(() => {
|
|
3672
|
+
timedOut = true;
|
|
3673
|
+
attempt.abort();
|
|
3674
|
+
resolve({ kind: "timeout" });
|
|
3675
|
+
}, bootstrapRequestTimeout);
|
|
3676
|
+
});
|
|
3677
|
+
let onAbort;
|
|
3678
|
+
const abortResult = new Promise((resolve) => {
|
|
3679
|
+
if (signal.aborted) {
|
|
3680
|
+
attempt.abort();
|
|
3681
|
+
resolve({ kind: "aborted" });
|
|
3682
|
+
return;
|
|
3683
|
+
}
|
|
3684
|
+
onAbort = () => {
|
|
3685
|
+
attempt.abort();
|
|
3686
|
+
resolve({ kind: "aborted" });
|
|
3687
|
+
};
|
|
3688
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
3689
|
+
});
|
|
3690
|
+
try {
|
|
3691
|
+
const outcome = await Promise.race([
|
|
3692
|
+
request,
|
|
3693
|
+
timeoutResult,
|
|
3694
|
+
abortResult
|
|
3695
|
+
]);
|
|
3696
|
+
if (signal.aborted) return { kind: "aborted" };
|
|
3697
|
+
if (timedOut) return { kind: "timeout" };
|
|
3698
|
+
return outcome;
|
|
3699
|
+
} finally {
|
|
3700
|
+
attempt.abort();
|
|
3701
|
+
if (timeout !== void 0) clearTimeout(timeout);
|
|
3702
|
+
signal.removeEventListener("abort", forwardAbort);
|
|
3703
|
+
if (onAbort !== void 0) signal.removeEventListener("abort", onAbort);
|
|
3704
|
+
request.catch(() => {});
|
|
3705
|
+
}
|
|
3706
|
+
}
|
|
3707
|
+
/** Read the host-owned settings namespace with bounded transient recovery. */
|
|
3708
|
+
async function readQoderSettingsNamespace(rpc, signal) {
|
|
3709
|
+
for (let attempt = 1; attempt <= bootstrapAttempts; attempt++) {
|
|
3710
|
+
const outcome = await runBootstrapAttempt(rpc, signal);
|
|
3711
|
+
if (outcome.kind === "aborted") return void 0;
|
|
3712
|
+
if (outcome.kind === "timeout") {
|
|
3713
|
+
if (attempt === bootstrapAttempts) throw new Error(`Qoder settings namespace bootstrap timed out after ${bootstrapAttempts} attempts.`);
|
|
3714
|
+
} else if (outcome.result.ok) {
|
|
3715
|
+
const namespace = outcome.result.value?.settingsNamespace;
|
|
3716
|
+
if (typeof namespace !== "string" || !namespace.trim()) throw new Error("Qoder settings namespace bootstrap returned no namespace.");
|
|
3717
|
+
return namespace;
|
|
3718
|
+
} else if (!transientBootstrapFailure(outcome.result) || attempt === bootstrapAttempts) throw bootstrapFailure(outcome.result, attempt);
|
|
3719
|
+
if (!await waitForBootstrapRetry(signal, bootstrapRetryDelays[attempt - 1] ?? bootstrapRetryDelays.at(-1))) return void 0;
|
|
3720
|
+
}
|
|
3721
|
+
}
|
|
3722
|
+
//#endregion
|
|
3723
|
+
//#region src/client/model-rates.ts
|
|
3724
|
+
/** Share one catalog read across the visible Qoder model options. */
|
|
3725
|
+
function createModelRates(rpc, settings) {
|
|
3726
|
+
const empty = /* @__PURE__ */ new Map();
|
|
3727
|
+
let rates = empty;
|
|
3728
|
+
let region;
|
|
3729
|
+
let request;
|
|
3730
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
3731
|
+
const publish = (next) => {
|
|
3732
|
+
if (rates === next) return;
|
|
3733
|
+
rates = next;
|
|
3734
|
+
for (const listener of listeners) listener();
|
|
3735
|
+
};
|
|
3736
|
+
const enabledRegion = () => {
|
|
3737
|
+
const { value } = settings.getSnapshot();
|
|
3738
|
+
if (value !== void 0 && value.showModelRates !== false) return regionOf(value);
|
|
3739
|
+
};
|
|
3740
|
+
const refresh = (nextRegion) => {
|
|
3741
|
+
if (listeners.size === 0) return;
|
|
3742
|
+
request?.abort();
|
|
3743
|
+
request = void 0;
|
|
3744
|
+
if (region !== nextRegion) {
|
|
3745
|
+
region = nextRegion;
|
|
3746
|
+
publish(empty);
|
|
3747
|
+
}
|
|
3748
|
+
if (nextRegion === void 0) return;
|
|
3749
|
+
const pending = new AbortController();
|
|
3750
|
+
request = pending;
|
|
3751
|
+
rpc.call("modelRates", {}, pending.signal).then((result) => {
|
|
3752
|
+
if (request !== pending) return;
|
|
3753
|
+
request = void 0;
|
|
3754
|
+
if (!result.ok) return;
|
|
3755
|
+
publish(result.value.region === nextRegion ? new Map(result.value.rates.map((rate) => [rate.id, rate])) : empty);
|
|
3756
|
+
});
|
|
3757
|
+
};
|
|
3758
|
+
const unsubscribeSettings = settings.subscribe(() => {
|
|
3759
|
+
const nextRegion = enabledRegion();
|
|
3760
|
+
if (nextRegion !== region) refresh(nextRegion);
|
|
3761
|
+
});
|
|
3762
|
+
return {
|
|
3763
|
+
refresh: () => refresh(enabledRegion()),
|
|
3764
|
+
dispose() {
|
|
3765
|
+
unsubscribeSettings();
|
|
3766
|
+
request?.abort();
|
|
3767
|
+
request = void 0;
|
|
3768
|
+
rates = empty;
|
|
3769
|
+
listeners.clear();
|
|
3770
|
+
},
|
|
3771
|
+
getSnapshot: () => rates,
|
|
3772
|
+
subscribe(listener) {
|
|
3773
|
+
listeners.add(listener);
|
|
3774
|
+
if (listeners.size === 1) refresh(enabledRegion());
|
|
3775
|
+
return () => {
|
|
3776
|
+
listeners.delete(listener);
|
|
3777
|
+
if (listeners.size !== 0) return;
|
|
3778
|
+
request?.abort();
|
|
3779
|
+
request = void 0;
|
|
3780
|
+
rates = empty;
|
|
3781
|
+
};
|
|
3782
|
+
}
|
|
3783
|
+
};
|
|
3784
|
+
}
|
|
3785
|
+
//#endregion
|
|
3786
|
+
//#region src/client/index.ts
|
|
3787
|
+
const localeNamespace = "settings.qoderCredential";
|
|
3788
|
+
const settingsSectionId = "dsh-provider-qoder";
|
|
3789
|
+
const inject = [
|
|
3790
|
+
"slots",
|
|
3791
|
+
"locale",
|
|
3792
|
+
"remote",
|
|
3793
|
+
"remote.credentials",
|
|
3794
|
+
"configForms"
|
|
3795
|
+
];
|
|
3796
|
+
const fill = (text, values) => {
|
|
3797
|
+
if (!values) return text;
|
|
3798
|
+
return Object.entries(values).reduce((next, [key, value]) => next.replace(new RegExp(`\\{${key}\\}`, "g"), String(value)), text);
|
|
3799
|
+
};
|
|
3800
|
+
function apply(ctx) {
|
|
3801
|
+
ctx.configForms;
|
|
3802
|
+
assertCredentials(ctx);
|
|
3803
|
+
const controller = new AbortController();
|
|
3804
|
+
let disposed = false;
|
|
3805
|
+
ctx.effect(() => () => {
|
|
3806
|
+
disposed = true;
|
|
3807
|
+
controller.abort();
|
|
3808
|
+
}, "provider-qoder: settings namespace bootstrap");
|
|
3809
|
+
const rpc = createQoderRpcCaller();
|
|
3810
|
+
return readQoderSettingsNamespace(rpc, controller.signal).then((settingsNamespace) => {
|
|
3811
|
+
if (disposed || controller.signal.aborted) return;
|
|
3812
|
+
if (settingsNamespace === void 0) return;
|
|
3813
|
+
mount(ctx, ctx.configForms.get(settingsNamespace), rpc);
|
|
3814
|
+
});
|
|
3815
|
+
}
|
|
3816
|
+
function assertCredentials(ctx) {
|
|
3817
|
+
const credentials = ctx.remote.credentials;
|
|
3818
|
+
if (!credentials || typeof credentials.describe !== "function" || typeof credentials.set !== "function" || typeof credentials.unset !== "function") throw new Error("Qoder settings require the DSH credentials Remote API.");
|
|
3819
|
+
}
|
|
3820
|
+
function mount(ctx, modelScope, rpc) {
|
|
3821
|
+
ctx.effect(() => ctx.locale.register(localeNamespace, {
|
|
3822
|
+
zh,
|
|
3823
|
+
en
|
|
3824
|
+
}), "provider-qoder: credential copy");
|
|
3825
|
+
const credentials = ctx.remote.credentials;
|
|
3826
|
+
assertCredentials(ctx);
|
|
3827
|
+
const tierEvents = createSessionTierEvents();
|
|
3828
|
+
const catalogEvents = createCatalogEvents(rpc);
|
|
3829
|
+
const catalogEditors = /* @__PURE__ */ new Map();
|
|
3830
|
+
ctx.effect(() => () => catalogEvents.dispose(), "provider-qoder: model catalog events");
|
|
3831
|
+
ctx.effect(() => () => tierEvents.dispose(), "provider-qoder: session context tier events");
|
|
3832
|
+
const readModelSnapshot = () => modelScope.getSnapshot();
|
|
3833
|
+
const authorizationOperations = {
|
|
3834
|
+
read: (region) => rpc.call("authorization", { region }),
|
|
3835
|
+
begin: (region) => rpc.call("beginLogin", { region }),
|
|
3836
|
+
cancel: (region) => rpc.call("cancelLogin", { region }),
|
|
3837
|
+
select: (region, method) => rpc.call("selectAuthorization", {
|
|
3838
|
+
region,
|
|
3839
|
+
method
|
|
3840
|
+
})
|
|
3841
|
+
};
|
|
3842
|
+
const operations = {
|
|
3843
|
+
authorization: authorizationOperations,
|
|
3844
|
+
...createSettingsOperations(credentials, modelScope, authorizationOperations, rpc),
|
|
3845
|
+
getAccount: async (force) => await rpc.call("account", { force }),
|
|
3846
|
+
getModelSnapshot: readModelSnapshot,
|
|
3847
|
+
subscribeModels: (listener) => modelScope.subscribe(listener),
|
|
3848
|
+
getCatalogEditor: (region, models) => {
|
|
3849
|
+
let editor = catalogEditors.get(region);
|
|
3850
|
+
if (!editor) {
|
|
3851
|
+
editor = new QoderModelCatalogEditor(region, models, operations);
|
|
3852
|
+
catalogEditors.set(region, editor);
|
|
3853
|
+
}
|
|
3854
|
+
return editor;
|
|
3855
|
+
},
|
|
3856
|
+
refreshCatalog: (region) => rpc.call("refreshCatalog", { region }),
|
|
3857
|
+
editCatalog: (region, edit) => rpc.call("editCatalog", {
|
|
3858
|
+
region,
|
|
3859
|
+
edit
|
|
3860
|
+
}),
|
|
3861
|
+
subscribeCatalog: (region, listener) => catalogEvents.subscribe(region, listener),
|
|
3862
|
+
subscribeSessionTiers: (scope, listener) => tierEvents.subscribe(scope, listener),
|
|
3863
|
+
subscribe: (listener) => {
|
|
3864
|
+
const reference = ctx.remote.$on("credentials/reference-updated", (ref) => {
|
|
3865
|
+
if (ref === "QODER_MANAGED_CREDENTIAL") listener();
|
|
3866
|
+
});
|
|
3867
|
+
const record = ctx.remote.$on("credentials/record-updated", (key) => {
|
|
3868
|
+
if (key === `provider-qoder/${regionOf(readModelSnapshot().value)}`) listener();
|
|
3869
|
+
});
|
|
3870
|
+
return () => {
|
|
3871
|
+
reference();
|
|
3872
|
+
record();
|
|
3873
|
+
};
|
|
3874
|
+
}
|
|
3875
|
+
};
|
|
3876
|
+
const rawT = ctx.locale.bind(localeNamespace);
|
|
3877
|
+
const t = (key, values) => {
|
|
3878
|
+
const raw = rawT(key);
|
|
3879
|
+
return fill(raw, values);
|
|
3880
|
+
};
|
|
3881
|
+
/**
|
|
3882
|
+
* Read the live UI locale. Cards call this during render, so a language
|
|
3883
|
+
* switch re-resolves provider copy instead of reusing a setup-time snapshot.
|
|
3884
|
+
*/
|
|
3885
|
+
const activeLocale = () => ctx.locale.getLocale().active;
|
|
3886
|
+
ctx.slots.inject("settings.section", () => ctx.slots.register({
|
|
3887
|
+
name: "settings.section",
|
|
3888
|
+
id: settingsSectionId,
|
|
3889
|
+
order: 15,
|
|
3890
|
+
label: () => t("nav"),
|
|
3891
|
+
locale: localeNamespace,
|
|
3892
|
+
inject: () => ({
|
|
3893
|
+
operations,
|
|
3894
|
+
t,
|
|
3895
|
+
activeLocale
|
|
3896
|
+
})
|
|
3897
|
+
}, QoderAccountCard));
|
|
3898
|
+
ctx.slots.inject("settings.section.icon", () => ctx.slots.register({
|
|
3899
|
+
name: "settings.section.icon",
|
|
3900
|
+
id: settingsSectionId
|
|
3901
|
+
}, QoderSettingsNavIcon));
|
|
3902
|
+
ctx.slots.inject("settings.models.footer", () => ctx.slots.register({
|
|
3903
|
+
name: "settings.models.footer",
|
|
3904
|
+
id: "qoder-credential",
|
|
3905
|
+
order: 15,
|
|
3906
|
+
inject: () => ({
|
|
3907
|
+
operations,
|
|
3908
|
+
t,
|
|
3909
|
+
activeLocale
|
|
3910
|
+
})
|
|
3911
|
+
}, QoderCredentialCard));
|
|
3912
|
+
const modelLabelSlot = "conversation.input.model.label";
|
|
3913
|
+
ctx.slots.inject(modelLabelSlot, function* () {
|
|
3914
|
+
const occupied = new Set(ctx.slots.entries?.(modelLabelSlot).map((entry) => entry.options?.priority ?? 0));
|
|
3915
|
+
const rates = createModelRates(rpc, modelScope);
|
|
3916
|
+
let priority = 100;
|
|
3917
|
+
for (let attempt = 0; attempt < 3; attempt++, priority++) {
|
|
3918
|
+
while (occupied.has(priority)) priority++;
|
|
3919
|
+
let unregister;
|
|
3920
|
+
try {
|
|
3921
|
+
unregister = ctx.slots.register({
|
|
3922
|
+
name: modelLabelSlot,
|
|
3923
|
+
priority,
|
|
3924
|
+
locale: localeNamespace,
|
|
3925
|
+
inject: () => ({
|
|
3926
|
+
rates,
|
|
3927
|
+
t,
|
|
3928
|
+
resolveBadgeText: ctx.locale.resolveText.bind(ctx.locale)
|
|
3929
|
+
})
|
|
3930
|
+
}, QoderModelLabel);
|
|
3931
|
+
} catch (error) {
|
|
3932
|
+
if (String(error).includes(`single slot "${modelLabelSlot}" already has a registration at priority `)) continue;
|
|
3933
|
+
break;
|
|
3934
|
+
}
|
|
3935
|
+
yield () => rates.dispose();
|
|
3936
|
+
yield ctx.remote.$on("llm/adapters-updated", rates.refresh);
|
|
3937
|
+
yield unregister;
|
|
3938
|
+
return;
|
|
3939
|
+
}
|
|
3940
|
+
rates.dispose();
|
|
3941
|
+
});
|
|
3942
|
+
ctx.slots.inject("conversation.input.dock", () => ctx.slots.register({
|
|
3943
|
+
name: "conversation.input.dock",
|
|
3944
|
+
id: "qoder-model-queue",
|
|
3945
|
+
order: 30,
|
|
3946
|
+
locale: localeNamespace,
|
|
3947
|
+
inject: (sessionId) => ({
|
|
3948
|
+
sessionId,
|
|
3949
|
+
rpc,
|
|
3950
|
+
t
|
|
3951
|
+
})
|
|
3952
|
+
}, QoderQueueStatus));
|
|
3953
|
+
ctx.inject([
|
|
3954
|
+
"modelDirectories",
|
|
3955
|
+
"sessions",
|
|
3956
|
+
"remote.session"
|
|
3957
|
+
], (scope) => {
|
|
3958
|
+
scope.slots.inject("conversation.input.right", () => scope.slots.register({
|
|
3959
|
+
name: "conversation.input.right",
|
|
3960
|
+
id: "qoder-context-select",
|
|
3961
|
+
order: 10,
|
|
3962
|
+
inject: (sessionId) => {
|
|
3963
|
+
let directory;
|
|
3964
|
+
try {
|
|
3965
|
+
const modelDirectories = scope.get("modelDirectories");
|
|
3966
|
+
directory = sessionId && modelDirectories ? modelDirectories.directoryFor(SessionId(sessionId)).store : void 0;
|
|
3967
|
+
} catch {}
|
|
3968
|
+
return {
|
|
3969
|
+
sessionId,
|
|
3970
|
+
directory,
|
|
3971
|
+
operations,
|
|
3972
|
+
t,
|
|
3973
|
+
activeLocale
|
|
3974
|
+
};
|
|
3975
|
+
}
|
|
3976
|
+
}, QoderContextSelect));
|
|
3977
|
+
});
|
|
3978
|
+
}
|
|
3979
|
+
//#endregion
|
|
3980
|
+
exports.apply = apply;
|
|
3981
|
+
exports.inject = inject;
|
|
3982
|
+
return module.exports;
|
|
3983
|
+
}
|
|
3984
|
+
});
|