coding-tool-x 3.8.7 → 3.8.9
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/README.md +2 -2
- package/dist/web/assets/{AgentsDrawer-C7ePByZx.js → AgentsDrawer-Cj5CJ4d9.js} +1 -1
- package/dist/web/assets/Analytics-1doS-8uC.js +1 -0
- package/dist/web/assets/AssetPathField-C9TOPl7o.js +1 -0
- package/dist/web/assets/{ChatHistoryDrawer-Ccl4rhdz.js → ChatHistoryDrawer-BTmQ1aQr.js} +1 -1
- package/dist/web/assets/{CollapseItem-MxG_UD4o.js → CollapseItem-CwqJk3bE.js} +1 -1
- package/dist/web/assets/{CommandsDrawer-DWbaxHRZ.js → CommandsDrawer-CaZWDI_G.js} +1 -1
- package/dist/web/assets/ConfigExportDrawer-C3vSZEsS.js +1 -0
- package/dist/web/assets/{ConfigTemplates-AiRPv2cd.js → ConfigTemplates-gyERg9iC.js} +1 -1
- package/dist/web/assets/{ConfigTemplatesDrawer-CKMFsfEF.js → ConfigTemplatesDrawer-B17RqFi4.js} +1 -1
- package/dist/web/assets/{ConfigTemplatesPanel-Cvbnkvpt.js → ConfigTemplatesPanel-DKIC_FqG.js} +1 -1
- package/dist/web/assets/{Divider-D28g1gwj.js → Divider-DsdbkHrG.js} +1 -1
- package/dist/web/assets/{FavoritesDrawer-DA-dR_vP.js → FavoritesDrawer-DaziQmBp.js} +1 -1
- package/dist/web/assets/Forward-DLCL7aMY.js +1 -0
- package/dist/web/assets/{GatewayConvertDrawer-402_raGb.js → GatewayConvertDrawer-OMgWUUSc.js} +1 -1
- package/dist/web/assets/Home-DOSUTfrE.js +1 -0
- package/dist/web/assets/{MarkdownEditor-BvkDECwH.js → MarkdownEditor-9TTwTS-U.js} +1 -1
- package/dist/web/assets/McpDrawer-I8rl8lGH.js +1 -0
- package/dist/web/assets/{McpFormDrawer-DPMnyt5L.js → McpFormDrawer-DEP3C7ut.js} +1 -1
- package/dist/web/assets/{PluginManager-FKVeugr4.js → PluginManager-BuRcWuBj.js} +1 -1
- package/dist/web/assets/{PluginsDrawer-MvM1R55d.js → PluginsDrawer-_zZENaQn.js} +1 -1
- package/dist/web/assets/PluginsPanel-Bs5qZ-TK.js +1 -0
- package/dist/web/assets/PluginsPanel-CzGMK-Ap.css +1 -0
- package/dist/web/assets/ProjectList-BSxuL2td.js +1 -0
- package/dist/web/assets/{ProjectList-677RLZ8O.css → ProjectList-VbIYSHbH.css} +1 -1
- package/dist/web/assets/PromptsDrawer-CoZ-ZtsY.js +1 -0
- package/dist/web/assets/RecentSessionsDrawer-B_17aJBG.js +1 -0
- package/dist/web/assets/RecentSessionsDrawer-yrAD4p1A.css +1 -0
- package/dist/web/assets/SessionCard-BL_x0d3t.js +1 -0
- package/dist/web/assets/SessionList-DhRYZ6vl.js +1 -0
- package/dist/web/assets/SessionList-qG_XpPBJ.css +1 -0
- package/dist/web/assets/{SettingsDrawer-lMjttbkD.js → SettingsDrawer-fYb0DU7X.js} +1 -1
- package/dist/web/assets/SkillManager-S698Hns8.js +1 -0
- package/dist/web/assets/{SkillsDrawer-DF6JsSyj.js → SkillsDrawer-Ms4lPCow.js} +1 -1
- package/dist/web/assets/{SkillsPanel-B3Nm5j32.css → SkillsPanel-C4ke56nF.css} +1 -1
- package/dist/web/assets/SkillsPanel-rqnqAOGL.js +1 -0
- package/dist/web/assets/{SpeedTestDrawer-BaZkZqPP.js → SpeedTestDrawer-Bbn38SfV.js} +1 -1
- package/dist/web/assets/Upload-CdyVHxCI.js +1 -0
- package/dist/web/assets/{WorkspaceDrawer-BFSwZ5yU.js → WorkspaceDrawer-L7HJRc6u.js} +1 -1
- package/dist/web/assets/{WorkspaceManager-BHL1uYct.js → WorkspaceManager-DsoNg2z8.js} +1 -1
- package/dist/web/assets/{WorkspacePanel-B5PooBtg.js → WorkspacePanel-Be8PVZah.js} +1 -1
- package/dist/web/assets/{headers-cf-QapUq.js → headers-B5JWGn3v.js} +1 -1
- package/dist/web/assets/{icons-B2Vg-IOC.js → icons-DmFe4b5j.js} +1 -1
- package/dist/web/assets/{index-BohDDAy_.css → index-3Lp6z8TQ.css} +1 -1
- package/dist/web/assets/index-BKlAWTH-.js +2 -0
- package/dist/web/assets/{light-Cp0t7v32.js → light-0eavxNvt.js} +1 -1
- package/dist/web/assets/platforms-BmzzwnSw.js +1 -0
- package/dist/web/assets/platforms-DWXgmy2w.js +1 -0
- package/dist/web/assets/session-visibility-BAmxh3cK.js +1 -0
- package/dist/web/assets/sessions-CC0j-KH_.js +1 -0
- package/dist/web/assets/sessions-D4yQtfKb.js +1 -0
- package/dist/web/assets/use-message-DqCwefG6.js +1 -0
- package/dist/web/assets/{useResponsiveDrawer-D-DDpbnI.js → useResponsiveDrawer-V_onl9NV.js} +1 -1
- package/dist/web/index.html +7 -7
- package/package.json +1 -1
- package/src/commands/daemon.js +27 -4
- package/src/commands/search.js +17 -2
- package/src/config/paths.js +2 -0
- package/src/platforms/channel-auth-registry.js +36 -6
- package/src/platforms/channel-auth-service.js +12 -2
- package/src/platforms/driver-registry.js +9 -1
- package/src/platforms/drivers/claude/session-history-adapter.js +72 -1
- package/src/platforms/drivers/claude/sessions-implementation.js +49 -7
- package/src/platforms/drivers/claude/sessions.js +30 -6
- package/src/platforms/drivers/codex/parser.js +57 -1
- package/src/platforms/drivers/codex/session-history-adapter.js +8 -2
- package/src/platforms/drivers/codex/sessions-implementation.js +25 -3
- package/src/platforms/drivers/codex/sessions.js +18 -1
- package/src/platforms/drivers/dsh/api-operations.js +396 -0
- package/src/platforms/drivers/dsh/channels-implementation.js +458 -0
- package/src/platforms/drivers/dsh/channels.js +191 -0
- package/src/platforms/drivers/dsh/common.js +571 -0
- package/src/platforms/drivers/dsh/native-config.js +93 -0
- package/src/platforms/drivers/dsh/native-logs.js +116 -0
- package/src/platforms/drivers/dsh/plugin-manager.js +117 -0
- package/src/platforms/drivers/dsh/projects.js +23 -0
- package/src/platforms/drivers/dsh/proxy-implementation.js +260 -0
- package/src/platforms/drivers/dsh/proxy.js +23 -0
- package/src/platforms/drivers/dsh/resources.js +346 -0
- package/src/platforms/drivers/dsh/sessions.js +587 -0
- package/src/platforms/drivers/dsh/statistics-implementation.js +238 -0
- package/src/platforms/drivers/dsh/statistics.js +24 -0
- package/src/platforms/drivers/gemini/session-history-adapter.js +49 -1
- package/src/platforms/drivers/gemini/sessions-implementation.js +46 -1
- package/src/platforms/drivers/gemini/sessions.js +2 -1
- package/src/platforms/drivers/omp/prompts.js +58 -2
- package/src/platforms/drivers/omp/proxy-implementation.js +25 -1
- package/src/platforms/drivers/omp/session-history-adapter.js +42 -1
- package/src/platforms/drivers/omp/sessions-implementation.js +51 -3
- package/src/platforms/drivers/omp/sessions.js +33 -2
- package/src/platforms/drivers/opencode/channels-implementation.js +25 -22
- package/src/platforms/drivers/opencode/channels.js +6 -1
- package/src/platforms/drivers/opencode/sessions-implementation.js +89 -9
- package/src/platforms/drivers/opencode/sessions.js +37 -1
- package/src/platforms/manifest-schema.js +43 -3
- package/src/platforms/manifests/dsh.json +542 -0
- package/src/platforms/manifests/omp.json +2 -1
- package/src/platforms/manifests/opencode.json +28 -0
- package/src/platforms/native-oauth-adapters.js +318 -18
- package/src/platforms/oauth-credentials-service.js +344 -13
- package/src/platforms/path-resolver.js +2 -0
- package/src/platforms/platform-path-context.js +12 -2
- package/src/platforms/registry.js +16 -1
- package/src/platforms/runtime.js +5 -0
- package/src/platforms/session-history-adapters.js +1 -0
- package/src/server/api/platform-api-config.js +23 -2
- package/src/server/api/platform-route-factory.js +9 -2
- package/src/server/api/platforms.js +19 -1
- package/src/server/api/plugins.js +108 -13
- package/src/server/index.js +35 -1
- package/src/server/services/config-registry-service.js +10 -1
- package/src/server/services/config-templates-service.js +1 -0
- package/src/server/services/plugins-service.js +474 -103
- package/src/server/services/session-history-index.js +900 -140
- package/src/server/services/session-history-worker.js +3 -1
- package/src/server/services/skill-service.js +214 -7
- package/src/server/services/usage-log-utils.js +1 -0
- package/src/server/services/workspace-service.js +39 -10
- package/src/shared/driver-factories/api.js +22 -6
- package/src/shared/driver-factories/projects.js +8 -0
- package/dist/web/assets/Analytics-BVG6ehFv.js +0 -1
- package/dist/web/assets/AssetPathField-BZI9NvEr.js +0 -1
- package/dist/web/assets/ConfigExportDrawer-DrawKwxE.js +0 -1
- package/dist/web/assets/Home-CTF8ZWKW.js +0 -1
- package/dist/web/assets/McpDrawer-DZGHkuDm.js +0 -1
- package/dist/web/assets/PluginsPanel-CKuBs38B.js +0 -1
- package/dist/web/assets/PluginsPanel-D6ZqITcR.css +0 -1
- package/dist/web/assets/ProjectList-tsjwjXV1.js +0 -1
- package/dist/web/assets/PromptsDrawer-B-X9ci8n.js +0 -1
- package/dist/web/assets/RecentSessionsDrawer-CKFsOYDM.css +0 -1
- package/dist/web/assets/RecentSessionsDrawer-wLktMF_c.js +0 -1
- package/dist/web/assets/SessionCard-DkJPy0TY.js +0 -1
- package/dist/web/assets/SessionList-BpYRz1cX.css +0 -1
- package/dist/web/assets/SessionList-Gzhh4FOZ.js +0 -1
- package/dist/web/assets/SkillManager-CzFxWxx-.js +0 -1
- package/dist/web/assets/SkillsPanel--lLEts9y.js +0 -1
- package/dist/web/assets/Upload-BEQ-3Kqq.js +0 -1
- package/dist/web/assets/index-BFInlZGI.js +0 -2
- package/dist/web/assets/platforms-CBkB45JP.js +0 -1
- package/dist/web/assets/platforms-FTpjxAT6.js +0 -1
- package/dist/web/assets/sessions-Cmy31slD.js +0 -1
- package/dist/web/assets/sessions-yC_oVVh8.js +0 -1
- package/dist/web/assets/use-message-DoLM8C1C.js +0 -1
|
@@ -6,7 +6,9 @@ const {
|
|
|
6
6
|
inspectTool,
|
|
7
7
|
SUPPORTED_TOOLS,
|
|
8
8
|
fingerprintFor,
|
|
9
|
-
readAllNativeOAuth
|
|
9
|
+
readAllNativeOAuth,
|
|
10
|
+
updateCodexOAuthTokens,
|
|
11
|
+
applyOAuthCredential
|
|
10
12
|
} = require('./native-oauth-adapters');
|
|
11
13
|
const { maskToken } = require('../server/services/oauth-utils');
|
|
12
14
|
|
|
@@ -110,6 +112,7 @@ function sanitizeCredential(entry, defaultCredentialId) {
|
|
|
110
112
|
providerId: entry.providerId || '',
|
|
111
113
|
accountId: entry.accountId || '',
|
|
112
114
|
accountEmail: entry.accountEmail || '',
|
|
115
|
+
identityKey: entry.identityKey || '',
|
|
113
116
|
expiresAt: entry.expiresAt || null,
|
|
114
117
|
lastRefresh: entry.lastRefresh || null,
|
|
115
118
|
lastUsedAt: entry.lastUsedAt || null,
|
|
@@ -209,12 +212,34 @@ function extractSecrets(tool, metadata) {
|
|
|
209
212
|
importPayload: metadata.importPayload || null,
|
|
210
213
|
primaryToken: metadata.primaryToken || metadata.accessToken || ''
|
|
211
214
|
};
|
|
215
|
+
case 'opencode':
|
|
216
|
+
return {
|
|
217
|
+
providerId: metadata.providerId || '',
|
|
218
|
+
accessToken: metadata.accessToken || '',
|
|
219
|
+
idToken: metadata.idToken || '',
|
|
220
|
+
refreshToken: metadata.refreshToken || '',
|
|
221
|
+
expiresAt: metadata.expiresAt || null,
|
|
222
|
+
accountId: metadata.accountId || '',
|
|
223
|
+
accountEmail: metadata.accountEmail || '',
|
|
224
|
+
identityKey: metadata.identityKey || '',
|
|
225
|
+
primaryToken: metadata.primaryToken || metadata.accessToken || ''
|
|
226
|
+
};
|
|
212
227
|
default:
|
|
213
228
|
return { primaryToken: metadata.primaryToken || metadata.accessToken || '' };
|
|
214
229
|
}
|
|
215
230
|
}
|
|
216
231
|
|
|
217
232
|
function stableFingerprintValue(tool, metadata) {
|
|
233
|
+
// Codex account IDs remain stable while access tokens rotate.
|
|
234
|
+
if (tool === 'codex') {
|
|
235
|
+
return metadata.accountId
|
|
236
|
+
|| metadata.accountEmail
|
|
237
|
+
|| metadata.refreshToken
|
|
238
|
+
|| metadata.primaryToken
|
|
239
|
+
|| metadata.accessToken
|
|
240
|
+
|| '';
|
|
241
|
+
}
|
|
242
|
+
|
|
218
243
|
// 优先使用稳定标识符,避免 access token 轮换导致重复记录
|
|
219
244
|
const stableId = metadata.accountEmail
|
|
220
245
|
|| metadata.accountId
|
|
@@ -227,6 +252,9 @@ function stableFingerprintValue(tool, metadata) {
|
|
|
227
252
|
}
|
|
228
253
|
|
|
229
254
|
function resolveFingerprintValue(tool, metadata, options = {}) {
|
|
255
|
+
if (tool === 'codex') {
|
|
256
|
+
return stableFingerprintValue(tool, metadata);
|
|
257
|
+
}
|
|
230
258
|
if (options.fingerprintMode === 'primary-token') {
|
|
231
259
|
return metadata.primaryToken
|
|
232
260
|
|| metadata.accessToken
|
|
@@ -235,13 +263,28 @@ function resolveFingerprintValue(tool, metadata, options = {}) {
|
|
|
235
263
|
return stableFingerprintValue(tool, metadata);
|
|
236
264
|
}
|
|
237
265
|
|
|
266
|
+
function matchesCodexIdentity(entry = {}, metadata = {}) {
|
|
267
|
+
const entryAccountId = safeString(entry.accountId || entry.secrets?.accountId);
|
|
268
|
+
const metadataAccountId = safeString(metadata.accountId);
|
|
269
|
+
if (entryAccountId && metadataAccountId) {
|
|
270
|
+
return entryAccountId === metadataAccountId;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const entryEmail = safeString(entry.accountEmail);
|
|
274
|
+
const metadataEmail = safeString(metadata.accountEmail);
|
|
275
|
+
return Boolean(entryEmail && metadataEmail && entryEmail === metadataEmail);
|
|
276
|
+
}
|
|
277
|
+
|
|
238
278
|
function upsertCredential(tool, metadata, options = {}) {
|
|
239
279
|
const store = readStore();
|
|
240
280
|
const toolStore = getToolStore(store, tool);
|
|
241
281
|
const now = Date.now();
|
|
242
282
|
const primaryToken = metadata.primaryToken || metadata.accessToken || '';
|
|
243
283
|
const fingerprint = fingerprintFor(tool, resolveFingerprintValue(tool, metadata, options));
|
|
244
|
-
|
|
284
|
+
let existingIndex = toolStore.credentials.findIndex((item) => item.fingerprint === fingerprint);
|
|
285
|
+
if (existingIndex < 0 && tool === 'codex') {
|
|
286
|
+
existingIndex = toolStore.credentials.findIndex((item) => matchesCodexIdentity(item, metadata));
|
|
287
|
+
}
|
|
245
288
|
const existing = existingIndex >= 0 ? toolStore.credentials[existingIndex] : null;
|
|
246
289
|
|
|
247
290
|
const entry = {
|
|
@@ -267,7 +310,21 @@ function upsertCredential(tool, metadata, options = {}) {
|
|
|
267
310
|
toolStore.credentials.unshift(entry);
|
|
268
311
|
}
|
|
269
312
|
|
|
270
|
-
if (
|
|
313
|
+
if (tool === 'codex') {
|
|
314
|
+
const duplicateIds = new Set();
|
|
315
|
+
for (let index = toolStore.credentials.length - 1; index >= 0; index -= 1) {
|
|
316
|
+
const candidate = toolStore.credentials[index];
|
|
317
|
+
if (candidate.id === entry.id || !matchesCodexIdentity(candidate, metadata)) continue;
|
|
318
|
+
duplicateIds.add(candidate.id);
|
|
319
|
+
toolStore.credentials.splice(index, 1);
|
|
320
|
+
}
|
|
321
|
+
if (duplicateIds.has(toolStore.defaultCredentialId)) {
|
|
322
|
+
toolStore.defaultCredentialId = entry.id;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (!toolStore.defaultCredentialId
|
|
327
|
+
|| !toolStore.credentials.some((item) => item.id === toolStore.defaultCredentialId)) {
|
|
271
328
|
toolStore.defaultCredentialId = entry.id;
|
|
272
329
|
}
|
|
273
330
|
|
|
@@ -290,10 +347,13 @@ function syncLocalCredential(tool) {
|
|
|
290
347
|
throw new Error('当前本地未检测到可同步的 OAuth 凭证。');
|
|
291
348
|
}
|
|
292
349
|
|
|
293
|
-
const credentials = nativeCredentials.map((metadata) =>
|
|
294
|
-
source: 'synced-local'
|
|
295
|
-
|
|
296
|
-
|
|
350
|
+
const credentials = nativeCredentials.map((metadata) => {
|
|
351
|
+
const options = { source: 'synced-local' };
|
|
352
|
+
if (tool !== 'codex') {
|
|
353
|
+
options.fingerprintMode = 'primary-token';
|
|
354
|
+
}
|
|
355
|
+
return upsertCredential(tool, metadata, options);
|
|
356
|
+
});
|
|
297
357
|
|
|
298
358
|
return {
|
|
299
359
|
credential: credentials[0] || null,
|
|
@@ -302,6 +362,70 @@ function syncLocalCredential(tool) {
|
|
|
302
362
|
};
|
|
303
363
|
}
|
|
304
364
|
|
|
365
|
+
function restoreStoredOmpOAuthCredentials(channels = []) {
|
|
366
|
+
const oauthChannels = (Array.isArray(channels) ? channels : [])
|
|
367
|
+
.filter(channel => channel?.enabled !== false && channel?.authMode === 'oauth');
|
|
368
|
+
if (oauthChannels.length === 0) return { restored: [], warnings: [] };
|
|
369
|
+
|
|
370
|
+
const store = readStore();
|
|
371
|
+
const toolStore = getToolStore(store, 'omp');
|
|
372
|
+
const nativeCredentials = readAllNativeOAuth('omp');
|
|
373
|
+
const restored = [];
|
|
374
|
+
const warnings = [];
|
|
375
|
+
const seenCredentialIds = new Set();
|
|
376
|
+
|
|
377
|
+
for (const channel of oauthChannels) {
|
|
378
|
+
const ref = channel.authRef || {};
|
|
379
|
+
const stored = toolStore.credentials.find((entry) => {
|
|
380
|
+
if (ref.credentialId && entry.id === ref.credentialId) return true;
|
|
381
|
+
if (ref.providerId && entry.providerId !== ref.providerId) return false;
|
|
382
|
+
if (ref.accountId && entry.accountId === ref.accountId) return true;
|
|
383
|
+
if (ref.accountEmail && entry.accountEmail === ref.accountEmail) return true;
|
|
384
|
+
return !ref.credentialId && !ref.accountId && !ref.accountEmail && !ref.providerId;
|
|
385
|
+
});
|
|
386
|
+
if (!stored || seenCredentialIds.has(stored.id)) continue;
|
|
387
|
+
seenCredentialIds.add(stored.id);
|
|
388
|
+
|
|
389
|
+
const accessToken = stored.secrets?.accessToken || stored.secrets?.primaryToken || '';
|
|
390
|
+
if (!accessToken) {
|
|
391
|
+
warnings.push(`OMP OAuth credential ${stored.id} has no access token.`);
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
const expiresAt = Number(stored.expiresAt || stored.secrets?.expiresAt || 0);
|
|
395
|
+
if (expiresAt > 0 && expiresAt <= Date.now()) {
|
|
396
|
+
warnings.push(`OMP OAuth credential ${stored.id} is expired and was not restored.`);
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const alreadyNative = nativeCredentials.some((native) => (
|
|
401
|
+
native.providerId === stored.providerId
|
|
402
|
+
&& ((!stored.accountId && !stored.accountEmail)
|
|
403
|
+
|| (stored.accountId && native.accountId === stored.accountId)
|
|
404
|
+
|| (stored.accountEmail && native.accountEmail === stored.accountEmail))
|
|
405
|
+
));
|
|
406
|
+
if (alreadyNative) continue;
|
|
407
|
+
|
|
408
|
+
try {
|
|
409
|
+
applyOAuthCredential('omp', {
|
|
410
|
+
providerId: stored.providerId || stored.secrets?.providerId,
|
|
411
|
+
credentialType: stored.secrets?.credentialType || 'oauth',
|
|
412
|
+
accessToken,
|
|
413
|
+
refreshToken: stored.secrets?.refreshToken || '',
|
|
414
|
+
expiresAt: expiresAt || null,
|
|
415
|
+
accountId: stored.accountId || stored.secrets?.accountId || '',
|
|
416
|
+
accountEmail: stored.accountEmail || stored.secrets?.accountEmail || '',
|
|
417
|
+
identityKey: stored.identityKey || stored.secrets?.identityKey || stored.accountId || '',
|
|
418
|
+
primaryToken: accessToken
|
|
419
|
+
});
|
|
420
|
+
restored.push(stored.id);
|
|
421
|
+
} catch (error) {
|
|
422
|
+
warnings.push(`OMP OAuth credential ${stored.id} restore failed: ${error.message}`);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return { restored, warnings };
|
|
427
|
+
}
|
|
428
|
+
|
|
305
429
|
|
|
306
430
|
function findStoredCredential(tool, credentialId) {
|
|
307
431
|
const store = readStore();
|
|
@@ -359,6 +483,11 @@ function httpPost(url, body, headers = {}) {
|
|
|
359
483
|
});
|
|
360
484
|
}
|
|
361
485
|
|
|
486
|
+
const CODEX_OAUTH_CLIENT_ID = 'app_EMoamEEZ73f0CkXaXp7hrann';
|
|
487
|
+
const CODEX_OAUTH_TOKEN_URL = 'https://auth.openai.com/oauth/token';
|
|
488
|
+
const CODEX_REFRESH_SKEW_MS = 60 * 1000;
|
|
489
|
+
const codexRefreshPromises = new Map();
|
|
490
|
+
|
|
362
491
|
function parseJsonBody(body) {
|
|
363
492
|
try {
|
|
364
493
|
return JSON.parse(body);
|
|
@@ -400,11 +529,21 @@ function extractCodexAccountId(...tokens) {
|
|
|
400
529
|
return '';
|
|
401
530
|
}
|
|
402
531
|
|
|
532
|
+
function isCodexOAuthProvider(providerId = '') {
|
|
533
|
+
const value = String(providerId || '').trim().toLowerCase();
|
|
534
|
+
return value === 'codex'
|
|
535
|
+
|| value === 'openai'
|
|
536
|
+
|| value.includes('openai-codex')
|
|
537
|
+
|| value.includes('codex');
|
|
538
|
+
}
|
|
539
|
+
|
|
403
540
|
async function fetchCodexUsage(accessToken, accountId = '') {
|
|
404
541
|
try {
|
|
405
542
|
const headers = {
|
|
406
543
|
'Authorization': `Bearer ${accessToken}`,
|
|
407
|
-
'User-Agent': 'codex-cli/0.1'
|
|
544
|
+
'User-Agent': 'codex-cli/0.1',
|
|
545
|
+
'Accept': 'application/json',
|
|
546
|
+
'originator': 'codex_cli_rs'
|
|
408
547
|
};
|
|
409
548
|
if (accountId) headers['ChatGPT-Account-Id'] = accountId;
|
|
410
549
|
const result = await httpGet('https://chatgpt.com/backend-api/wham/usage', headers);
|
|
@@ -415,6 +554,166 @@ async function fetchCodexUsage(accessToken, accountId = '') {
|
|
|
415
554
|
}
|
|
416
555
|
}
|
|
417
556
|
|
|
557
|
+
function isCodexCredential(tool, entry = {}) {
|
|
558
|
+
if (tool === 'codex') return true;
|
|
559
|
+
if (tool !== 'omp' && tool !== 'opencode') return false;
|
|
560
|
+
return isCodexOAuthProvider(entry.providerId || entry.secrets?.providerId);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function credentialExpiresAt(entry = {}) {
|
|
564
|
+
const explicit = Number(entry.expiresAt || entry.secrets?.expiresAt || 0);
|
|
565
|
+
if (Number.isFinite(explicit) && explicit > 0) return explicit;
|
|
566
|
+
const { decodeJwtPayload } = require('../server/services/oauth-utils');
|
|
567
|
+
for (const token of [entry.secrets?.accessToken, entry.secrets?.idToken]) {
|
|
568
|
+
const exp = Number(decodeJwtPayload(token)?.exp || 0);
|
|
569
|
+
if (Number.isFinite(exp) && exp > 0) return exp * 1000;
|
|
570
|
+
}
|
|
571
|
+
return null;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
async function refreshCodexCredential(entry) {
|
|
575
|
+
const refreshToken = String(entry?.secrets?.refreshToken || '').trim();
|
|
576
|
+
if (!refreshToken) return { entry, refreshed: false, attempted: false };
|
|
577
|
+
const existing = codexRefreshPromises.get(entry.id);
|
|
578
|
+
if (existing) return existing;
|
|
579
|
+
|
|
580
|
+
const promise = (async () => {
|
|
581
|
+
const form = new URLSearchParams({
|
|
582
|
+
grant_type: 'refresh_token',
|
|
583
|
+
refresh_token: refreshToken,
|
|
584
|
+
client_id: CODEX_OAUTH_CLIENT_ID
|
|
585
|
+
}).toString();
|
|
586
|
+
const result = await httpPost(CODEX_OAUTH_TOKEN_URL, form, {
|
|
587
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
588
|
+
'Accept': 'application/json'
|
|
589
|
+
});
|
|
590
|
+
const payload = parseJsonBody(result.body) || {};
|
|
591
|
+
if (result.statusCode < 200 || result.statusCode >= 300 || !payload.access_token) {
|
|
592
|
+
return { entry, refreshed: false, attempted: true };
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
const accessToken = String(payload.access_token).trim();
|
|
596
|
+
const nextRefreshToken = String(payload.refresh_token || refreshToken).trim();
|
|
597
|
+
const idToken = String(payload.id_token || entry.secrets.idToken || '').trim();
|
|
598
|
+
const accountId = extractCodexAccountId(idToken, accessToken)
|
|
599
|
+
|| entry.accountId
|
|
600
|
+
|| entry.secrets.accountId
|
|
601
|
+
|| '';
|
|
602
|
+
const expiresIn = Number(payload.expires_in || 0);
|
|
603
|
+
const expiresAt = expiresIn > 0
|
|
604
|
+
? Date.now() + expiresIn * 1000
|
|
605
|
+
: credentialExpiresAt({ secrets: { accessToken, idToken } });
|
|
606
|
+
const lastRefresh = new Date().toISOString();
|
|
607
|
+
|
|
608
|
+
const store = readStore();
|
|
609
|
+
const toolStore = getToolStore(store, entry.tool);
|
|
610
|
+
const stored = toolStore.credentials.find(item => item.id === entry.id);
|
|
611
|
+
if (!stored) return { entry, refreshed: false, attempted: true };
|
|
612
|
+
stored.accountId = accountId || stored.accountId || '';
|
|
613
|
+
stored.expiresAt = expiresAt || stored.expiresAt || null;
|
|
614
|
+
stored.updatedAt = Date.now();
|
|
615
|
+
stored.secrets = {
|
|
616
|
+
...stored.secrets,
|
|
617
|
+
accessToken,
|
|
618
|
+
refreshToken: nextRefreshToken,
|
|
619
|
+
idToken,
|
|
620
|
+
accountId: accountId || stored.secrets.accountId || '',
|
|
621
|
+
expiresAt: expiresAt || stored.secrets.expiresAt || null,
|
|
622
|
+
lastRefresh,
|
|
623
|
+
primaryToken: accessToken
|
|
624
|
+
};
|
|
625
|
+
writeStore(store);
|
|
626
|
+
|
|
627
|
+
if (entry.tool === 'codex' && typeof updateCodexOAuthTokens === 'function') {
|
|
628
|
+
try {
|
|
629
|
+
updateCodexOAuthTokens({
|
|
630
|
+
authMode: stored.secrets.authMode,
|
|
631
|
+
accessToken,
|
|
632
|
+
refreshToken: nextRefreshToken,
|
|
633
|
+
idToken,
|
|
634
|
+
accountId,
|
|
635
|
+
lastRefresh
|
|
636
|
+
});
|
|
637
|
+
} catch {
|
|
638
|
+
// The credential store is sufficient for quota lookup; native sync is best-effort.
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
if (entry.tool === 'omp' && typeof applyOAuthCredential === 'function') {
|
|
643
|
+
try {
|
|
644
|
+
applyOAuthCredential('omp', {
|
|
645
|
+
providerId: stored.providerId || stored.secrets.providerId,
|
|
646
|
+
credentialType: stored.secrets.credentialType || 'oauth',
|
|
647
|
+
accessToken,
|
|
648
|
+
refreshToken: nextRefreshToken,
|
|
649
|
+
expiresAt,
|
|
650
|
+
accountId,
|
|
651
|
+
accountEmail: stored.accountEmail || stored.secrets.accountEmail || '',
|
|
652
|
+
identityKey: stored.identityKey || stored.secrets.identityKey || accountId,
|
|
653
|
+
primaryToken: accessToken
|
|
654
|
+
});
|
|
655
|
+
} catch {
|
|
656
|
+
// Quota lookup can still use the refreshed app credential if native sync is unavailable.
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
return { entry: stored, refreshed: true, attempted: true };
|
|
661
|
+
})().catch(() => ({ entry, refreshed: false, attempted: true }));
|
|
662
|
+
codexRefreshPromises.set(entry.id, promise);
|
|
663
|
+
try {
|
|
664
|
+
return await promise;
|
|
665
|
+
} finally {
|
|
666
|
+
codexRefreshPromises.delete(entry.id);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
async function ensureFreshCodexCredential(entry) {
|
|
671
|
+
const expiresAt = credentialExpiresAt(entry);
|
|
672
|
+
if (expiresAt && expiresAt - Date.now() > CODEX_REFRESH_SKEW_MS) {
|
|
673
|
+
return { entry, refreshed: false, attempted: false };
|
|
674
|
+
}
|
|
675
|
+
return refreshCodexCredential(entry);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
async function refreshNativeCodexOAuth() {
|
|
679
|
+
const native = readAllNativeOAuth('codex')[0];
|
|
680
|
+
if (!native) {
|
|
681
|
+
return { available: false, refreshed: false, synchronized: false };
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
const synced = syncLocalCredential('codex');
|
|
685
|
+
const credentialId = synced.credential?.id;
|
|
686
|
+
if (!credentialId) {
|
|
687
|
+
return { available: true, refreshed: false, synchronized: false };
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
let entry = findStoredCredential('codex', credentialId);
|
|
691
|
+
const result = await ensureFreshCodexCredential(entry);
|
|
692
|
+
entry = result.entry || entry;
|
|
693
|
+
|
|
694
|
+
let synchronized = Boolean(result.refreshed);
|
|
695
|
+
if (!result.refreshed && !result.attempted && entry.secrets?.refreshToken) {
|
|
696
|
+
updateCodexOAuthTokens({
|
|
697
|
+
authMode: native.authMode,
|
|
698
|
+
accessToken: native.accessToken,
|
|
699
|
+
refreshToken: native.refreshToken,
|
|
700
|
+
idToken: native.idToken,
|
|
701
|
+
accountId: native.accountId,
|
|
702
|
+
lastRefresh: native.lastRefresh
|
|
703
|
+
});
|
|
704
|
+
synchronized = true;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
return {
|
|
708
|
+
available: true,
|
|
709
|
+
refreshed: Boolean(result.refreshed),
|
|
710
|
+
refreshAttempted: Boolean(result.attempted),
|
|
711
|
+
refreshFailed: Boolean(result.attempted && !result.refreshed),
|
|
712
|
+
synchronized,
|
|
713
|
+
credentialId: entry.id
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
|
|
418
717
|
async function fetchGeminiUsage(accessToken) {
|
|
419
718
|
try {
|
|
420
719
|
const body = JSON.stringify({
|
|
@@ -586,9 +885,16 @@ function normalizeOAuthQuota(tool, raw) {
|
|
|
586
885
|
}
|
|
587
886
|
|
|
588
887
|
async function fetchCredentialUsage(tool, credentialId) {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
888
|
+
let entry = findStoredCredential(tool, credentialId);
|
|
889
|
+
let secrets = entry.secrets || {};
|
|
890
|
+
let codexRefreshed = false;
|
|
891
|
+
if (isCodexCredential(tool, entry)) {
|
|
892
|
+
const refreshed = await ensureFreshCodexCredential(entry);
|
|
893
|
+
entry = refreshed.entry;
|
|
894
|
+
secrets = entry.secrets || {};
|
|
895
|
+
codexRefreshed = refreshed.refreshed;
|
|
896
|
+
}
|
|
897
|
+
let accessToken = secrets.accessToken || secrets.primaryToken || '';
|
|
592
898
|
if (!accessToken) return { error: '无有效 token' };
|
|
593
899
|
|
|
594
900
|
let response;
|
|
@@ -606,7 +912,7 @@ async function fetchCredentialUsage(tool, credentialId) {
|
|
|
606
912
|
response = await fetchGeminiUsage(accessToken);
|
|
607
913
|
break;
|
|
608
914
|
case 'omp': {
|
|
609
|
-
const providerId = entry.providerId || secrets.providerId || '';
|
|
915
|
+
const providerId = String(entry.providerId || secrets.providerId || '').toLowerCase();
|
|
610
916
|
response = providerId.includes('claude') || providerId.includes('anthropic')
|
|
611
917
|
? await fetchClaudeUsage(accessToken)
|
|
612
918
|
: providerId.includes('gemini') || providerId.includes('google')
|
|
@@ -614,11 +920,34 @@ async function fetchCredentialUsage(tool, credentialId) {
|
|
|
614
920
|
: await fetchCodexUsage(accessToken, extractCodexAccountId(accessToken) || entry.accountId || secrets.accountId);
|
|
615
921
|
break;
|
|
616
922
|
}
|
|
923
|
+
case 'opencode': {
|
|
924
|
+
const providerId = entry.providerId || secrets.providerId || '';
|
|
925
|
+
response = isCodexOAuthProvider(providerId)
|
|
926
|
+
? await fetchCodexUsage(accessToken, extractCodexAccountId(secrets.idToken, accessToken) || entry.accountId || secrets.accountId)
|
|
927
|
+
: { raw: null, provider: 'opencode', statusCode: 200 };
|
|
928
|
+
break;
|
|
929
|
+
}
|
|
617
930
|
default:
|
|
618
931
|
return { quota: null, status: 'unsupported', error: `不支持的工具: ${tool}` };
|
|
619
932
|
}
|
|
620
933
|
if (response?.error) return { quota: null, status: 'unavailable', error: response.error };
|
|
621
934
|
if (response?.statusCode === 401 || response?.statusCode === 403) {
|
|
935
|
+
if (isCodexCredential(tool, entry) && !codexRefreshed) {
|
|
936
|
+
const refreshed = await refreshCodexCredential(entry);
|
|
937
|
+
if (refreshed.refreshed) {
|
|
938
|
+
entry = refreshed.entry;
|
|
939
|
+
secrets = entry.secrets || {};
|
|
940
|
+
accessToken = secrets.accessToken || secrets.primaryToken || '';
|
|
941
|
+
response = await fetchCodexUsage(
|
|
942
|
+
accessToken,
|
|
943
|
+
extractCodexAccountId(secrets.idToken, accessToken) || entry.accountId || secrets.accountId
|
|
944
|
+
);
|
|
945
|
+
if (response?.error) return { quota: null, status: 'unavailable', error: response.error };
|
|
946
|
+
if (response?.statusCode !== 401 && response?.statusCode !== 403) {
|
|
947
|
+
return normalizeOAuthQuota(tool, response?.raw);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}
|
|
622
951
|
return { quota: null, status: 'unauthorized', error: '上游 OAuth 授权已失效' };
|
|
623
952
|
}
|
|
624
953
|
return normalizeOAuthQuota(tool, response?.raw);
|
|
@@ -627,9 +956,11 @@ async function fetchCredentialUsage(tool, credentialId) {
|
|
|
627
956
|
module.exports = {
|
|
628
957
|
SUPPORTED_TOOLS,
|
|
629
958
|
syncLocalCredential,
|
|
959
|
+
restoreStoredOmpOAuthCredentials,
|
|
630
960
|
normalizeOAuthQuota,
|
|
631
961
|
fetchCredentialUsage,
|
|
632
962
|
extractCodexAccountId,
|
|
633
963
|
normalizeResetAt,
|
|
634
|
-
normalizeWindow
|
|
964
|
+
normalizeWindow,
|
|
965
|
+
refreshNativeCodexOAuth
|
|
635
966
|
};
|
|
@@ -92,6 +92,7 @@ function resolveNativeHome(pathResolverId, env, commandRunner, homeDir, hasInjec
|
|
|
92
92
|
case 'codex': return env.CODEX_HOME || path.join(homeDir, '.codex');
|
|
93
93
|
case 'gemini': return path.join(homeDir, '.gemini');
|
|
94
94
|
case 'opencode': return path.join(homeDir, '.config', 'opencode');
|
|
95
|
+
case 'dsh': return env.DSH_HOME || path.join(homeDir, '.dsh');
|
|
95
96
|
default: return undefined;
|
|
96
97
|
}
|
|
97
98
|
}
|
|
@@ -127,6 +128,7 @@ function resolveNativeHome(pathResolverId, env, commandRunner, homeDir, hasInjec
|
|
|
127
128
|
case 'gemini': return getGeminiDir();
|
|
128
129
|
case 'opencode': return getOpenCodeConfigDir() || getOpenCodeDataDir();
|
|
129
130
|
case 'omp': return getOmpAgentDir(env, { commandRunner });
|
|
131
|
+
case 'dsh': return env.DSH_HOME || path.join(homeDir, '.dsh');
|
|
130
132
|
default: return undefined;
|
|
131
133
|
}
|
|
132
134
|
}
|
|
@@ -147,7 +147,8 @@ function getDefaultNativePaths(platform, homeDir, env, rootOverride) {
|
|
|
147
147
|
codex: rootOverride || path.join(homeDir, '.codex'),
|
|
148
148
|
gemini: rootOverride || path.join(homeDir, '.gemini'),
|
|
149
149
|
opencode: rootOverride || getOpenCodeConfigDir(homeDir, env),
|
|
150
|
-
omp: rootOverride || getOmpFallbackDir(homeDir, env)
|
|
150
|
+
omp: rootOverride || getOmpFallbackDir(homeDir, env),
|
|
151
|
+
dsh: rootOverride || env.DSH_HOME || path.join(homeDir, '.dsh')
|
|
151
152
|
};
|
|
152
153
|
const root = roots[platform] || homeDir;
|
|
153
154
|
|
|
@@ -219,6 +220,15 @@ function getDefaultNativePaths(platform, homeDir, env, rootOverride) {
|
|
|
219
220
|
themes: path.join(root, 'themes'),
|
|
220
221
|
packages: path.join(root, 'packages')
|
|
221
222
|
};
|
|
223
|
+
case 'dsh':
|
|
224
|
+
return {
|
|
225
|
+
dir: root,
|
|
226
|
+
settings: path.join(root, 'settings.yaml'),
|
|
227
|
+
credentials: path.join(root, '.credentials.yaml'),
|
|
228
|
+
sessions: path.join(root, 'sessions'),
|
|
229
|
+
profiles: path.join(root, 'profiles'),
|
|
230
|
+
patch: path.join(root, 'cordis.patch.yml')
|
|
231
|
+
};
|
|
222
232
|
default:
|
|
223
233
|
return { dir: homeDir };
|
|
224
234
|
}
|
|
@@ -239,7 +249,7 @@ function createPlatformPathContext({ key, platform, manifest, resolvedPaths = {}
|
|
|
239
249
|
const homeDir = pathOptions.homeDir || resolveDefaultHomeDir();
|
|
240
250
|
const env = { ...process.env, ...(pathOptions.env || {}) };
|
|
241
251
|
const resolverId = manifest && manifest.pathResolverId;
|
|
242
|
-
const nativeKey = ['claude', 'codex', 'gemini', 'opencode', 'omp'].includes(resolverId)
|
|
252
|
+
const nativeKey = ['claude', 'codex', 'gemini', 'opencode', 'omp', 'dsh'].includes(resolverId)
|
|
243
253
|
? resolverId
|
|
244
254
|
: platformKey;
|
|
245
255
|
const resolvedHome = resolvedPaths.home || homeDir;
|
|
@@ -18,7 +18,8 @@ const BUILT_IN_MANIFESTS = [
|
|
|
18
18
|
require('./manifests/codex.json'),
|
|
19
19
|
require('./manifests/gemini.json'),
|
|
20
20
|
require('./manifests/opencode.json'),
|
|
21
|
-
require('./manifests/omp.json')
|
|
21
|
+
require('./manifests/omp.json'),
|
|
22
|
+
require('./manifests/dsh.json')
|
|
22
23
|
];
|
|
23
24
|
|
|
24
25
|
function getDefaultPlatformsFile(env = process.env, homeDir = os.homedir()) {
|
|
@@ -49,6 +50,18 @@ function publicResourceTypes(resourceTypes) {
|
|
|
49
50
|
);
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
function publicResourceActions(resourceActions) {
|
|
54
|
+
if (!resourceActions || typeof resourceActions !== 'object' || Array.isArray(resourceActions)) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return Object.fromEntries(Object.entries(resourceActions).map(([resourceType, actions]) => [
|
|
58
|
+
resourceType,
|
|
59
|
+
actions && typeof actions === 'object' && !Array.isArray(actions)
|
|
60
|
+
? Object.fromEntries(Object.entries(actions).filter(([, value]) => typeof value === 'boolean'))
|
|
61
|
+
: {}
|
|
62
|
+
]));
|
|
63
|
+
}
|
|
64
|
+
|
|
52
65
|
function hasCustomPathResolution(pathOptions = {}, overlay = {}, platformKey = '') {
|
|
53
66
|
if (pathOptions.homeDir || pathOptions.env || pathOptions.commandRunner) return true;
|
|
54
67
|
const entry = overlay?.platforms?.[String(platformKey || '').trim().toLowerCase()];
|
|
@@ -179,6 +192,8 @@ function createPlatformRegistry({
|
|
|
179
192
|
};
|
|
180
193
|
const resourceTypes = publicResourceTypes(platform.resourceTypes);
|
|
181
194
|
if (resourceTypes) result.resourceTypes = resourceTypes;
|
|
195
|
+
const resourceActions = publicResourceActions(platform.resourceActions);
|
|
196
|
+
if (resourceActions) result.resourceActions = resourceActions;
|
|
182
197
|
if (typeof platform.promptLabel === 'string' && platform.promptLabel.trim()) {
|
|
183
198
|
result.promptLabel = platform.promptLabel;
|
|
184
199
|
}
|
package/src/platforms/runtime.js
CHANGED
|
@@ -14,6 +14,11 @@ const PATH_CONTEXT_ENV_KEYS = [
|
|
|
14
14
|
'XDG_CONFIG_HOME',
|
|
15
15
|
'XDG_DATA_HOME',
|
|
16
16
|
'XDG_STATE_HOME',
|
|
17
|
+
'DSH_HOME',
|
|
18
|
+
'DSH_INSTALL_ANCHOR',
|
|
19
|
+
'DSH_INSTALL_ROOT',
|
|
20
|
+
'DSH_AGENTS_HOME',
|
|
21
|
+
'DSH_BUNDLED_SKILL_DIR',
|
|
17
22
|
'PATH',
|
|
18
23
|
'OMP_COMMAND',
|
|
19
24
|
'OMP_CONFIG_DIR',
|
|
@@ -33,20 +33,41 @@ function requestContext(request, manifest, route, config) {
|
|
|
33
33
|
|
|
34
34
|
function projectPayload(data, context) {
|
|
35
35
|
if (Array.isArray(data)) {
|
|
36
|
-
return {
|
|
36
|
+
return {
|
|
37
|
+
projects: data,
|
|
38
|
+
currentProject: null,
|
|
39
|
+
pagination: { page: 1, limit: data.length || 20, total: data.length, hasMore: false },
|
|
40
|
+
meta: {}
|
|
41
|
+
};
|
|
37
42
|
}
|
|
38
43
|
const payload = cloneObject(data);
|
|
39
44
|
if (!Array.isArray(payload.projects)) payload.projects = [];
|
|
40
45
|
if (!Object.prototype.hasOwnProperty.call(payload, 'currentProject')) payload.currentProject = null;
|
|
41
46
|
if (!payload.meta || typeof payload.meta !== 'object' || Array.isArray(payload.meta)) payload.meta = {};
|
|
47
|
+
if (!payload.pagination || typeof payload.pagination !== 'object') {
|
|
48
|
+
payload.pagination = { page: 1, limit: payload.projects.length || 20, total: payload.projects.length, hasMore: false };
|
|
49
|
+
}
|
|
42
50
|
return payload;
|
|
43
51
|
}
|
|
44
52
|
|
|
45
53
|
function sessionPayload(data) {
|
|
46
|
-
if (Array.isArray(data))
|
|
54
|
+
if (Array.isArray(data)) {
|
|
55
|
+
return {
|
|
56
|
+
sessions: data,
|
|
57
|
+
totalSize: data.reduce((sum, session) => sum + (Number(session?.size) || 0), 0),
|
|
58
|
+
pagination: { page: 1, limit: data.length || 20, total: data.length, hasMore: false },
|
|
59
|
+
meta: {}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
47
62
|
const payload = cloneObject(data);
|
|
48
63
|
if (!Array.isArray(payload.sessions)) payload.sessions = [];
|
|
49
64
|
if (!payload.meta || typeof payload.meta !== 'object' || Array.isArray(payload.meta)) payload.meta = {};
|
|
65
|
+
if (!payload.pagination || typeof payload.pagination !== 'object') {
|
|
66
|
+
payload.pagination = { page: 1, limit: payload.sessions.length || 20, total: payload.sessions.length, hasMore: false };
|
|
67
|
+
}
|
|
68
|
+
if (!Object.prototype.hasOwnProperty.call(payload, 'totalSize')) {
|
|
69
|
+
payload.totalSize = payload.sessions.reduce((sum, session) => sum + (Number(session?.size) || 0), 0);
|
|
70
|
+
}
|
|
50
71
|
return payload;
|
|
51
72
|
}
|
|
52
73
|
|
|
@@ -63,9 +63,16 @@ function makeUnsupported(context) {
|
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
function legacyArguments(route, request) {
|
|
66
|
-
|
|
66
|
+
const listOptions = () => {
|
|
67
|
+
const options = { force: request.query?.fresh === '1' };
|
|
68
|
+
if (request.query?.page != null) options.page = request.query.page;
|
|
69
|
+
if (request.query?.limit != null) options.limit = request.query.limit;
|
|
70
|
+
if (request.query?.q || request.query?.search) options.q = request.query.q || request.query.search;
|
|
71
|
+
return options;
|
|
72
|
+
};
|
|
73
|
+
if (route.capability === 'projects' && route.operation === 'listProjects') return [listOptions()];
|
|
67
74
|
if (route.capability === 'sessions' && route.operation === 'listSessions') {
|
|
68
|
-
return [request.params.projectName,
|
|
75
|
+
return [request.params.projectName, listOptions()];
|
|
69
76
|
}
|
|
70
77
|
if (route.capability === 'channels') {
|
|
71
78
|
if (route.method === 'POST') return [request.body || {}];
|