codexmate 0.0.19 → 0.0.21
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.en.md +349 -255
- package/README.md +284 -248
- package/cli/agents-files.js +162 -0
- package/cli/archive-helpers.js +446 -0
- package/cli/auth-profiles.js +359 -0
- package/cli/builtin-proxy.js +580 -0
- package/cli/claude-proxy.js +998 -0
- package/cli/config-bootstrap.js +384 -0
- package/cli/config-health.js +338 -0
- package/cli/openclaw-config.js +629 -0
- package/cli/skills.js +1141 -0
- package/cli/zip-commands.js +510 -0
- package/cli.js +13129 -12973
- package/lib/cli-file-utils.js +151 -151
- package/lib/cli-models-utils.js +419 -152
- package/lib/cli-network-utils.js +164 -148
- package/lib/cli-path-utils.js +69 -0
- package/lib/cli-session-utils.js +121 -121
- package/lib/cli-sessions.js +386 -0
- package/lib/cli-utils.js +155 -155
- package/lib/download-artifacts.js +77 -0
- package/lib/mcp-stdio.js +440 -440
- package/lib/task-orchestrator.js +869 -0
- package/lib/text-diff.js +303 -303
- package/lib/workflow-engine.js +340 -340
- package/package.json +74 -63
- package/res/json5.min.js +1 -1
- package/res/vue.global.prod.js +13 -0
- package/web-ui/app.js +530 -5548
- package/web-ui/index.html +33 -2246
- package/web-ui/logic.agents-diff.mjs +386 -0
- package/web-ui/logic.claude.mjs +168 -0
- package/web-ui/logic.mjs +5 -793
- package/web-ui/logic.runtime.mjs +124 -0
- package/web-ui/logic.sessions.mjs +581 -0
- package/web-ui/modules/api.mjs +90 -0
- package/web-ui/modules/app.computed.dashboard.mjs +113 -0
- package/web-ui/modules/app.computed.index.mjs +15 -0
- package/web-ui/modules/app.computed.main-tabs.mjs +195 -0
- package/web-ui/modules/app.computed.session.mjs +507 -0
- package/web-ui/modules/app.constants.mjs +15 -0
- package/web-ui/modules/app.methods.agents.mjs +493 -0
- package/web-ui/modules/app.methods.claude-config.mjs +174 -0
- package/web-ui/modules/app.methods.codex-config.mjs +640 -0
- package/web-ui/modules/app.methods.index.mjs +88 -0
- package/web-ui/modules/app.methods.install.mjs +149 -0
- package/web-ui/modules/app.methods.navigation.mjs +619 -0
- package/web-ui/modules/app.methods.openclaw-core.mjs +814 -0
- package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -0
- package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -0
- package/web-ui/modules/app.methods.providers.mjs +363 -0
- package/web-ui/modules/app.methods.runtime.mjs +323 -0
- package/web-ui/modules/app.methods.session-actions.mjs +520 -0
- package/web-ui/modules/app.methods.session-browser.mjs +626 -0
- package/web-ui/modules/app.methods.session-timeline.mjs +448 -0
- package/web-ui/modules/app.methods.session-trash.mjs +422 -0
- package/web-ui/modules/app.methods.startup-claude.mjs +412 -0
- package/web-ui/modules/app.methods.task-orchestration.mjs +471 -0
- package/web-ui/modules/config-mode.computed.mjs +126 -124
- package/web-ui/modules/skills.computed.mjs +107 -107
- package/web-ui/modules/skills.methods.mjs +481 -481
- package/web-ui/partials/index/layout-footer.html +13 -0
- package/web-ui/partials/index/layout-header.html +402 -0
- package/web-ui/partials/index/modal-config-template-agents.html +125 -0
- package/web-ui/partials/index/modal-confirm-toast.html +32 -0
- package/web-ui/partials/index/modal-health-check.html +72 -0
- package/web-ui/partials/index/modal-openclaw-config.html +280 -0
- package/web-ui/partials/index/modal-skills.html +184 -0
- package/web-ui/partials/index/modals-basic.html +156 -0
- package/web-ui/partials/index/panel-config-claude.html +126 -0
- package/web-ui/partials/index/panel-config-codex.html +237 -0
- package/web-ui/partials/index/panel-config-openclaw.html +78 -0
- package/web-ui/partials/index/panel-docs.html +130 -0
- package/web-ui/partials/index/panel-market.html +174 -0
- package/web-ui/partials/index/panel-orchestration.html +397 -0
- package/web-ui/partials/index/panel-sessions.html +292 -0
- package/web-ui/partials/index/panel-settings.html +190 -0
- package/web-ui/partials/index/panel-usage.html +213 -0
- package/web-ui/session-helpers.mjs +559 -362
- package/web-ui/source-bundle.cjs +233 -0
- package/web-ui/styles/base-theme.css +271 -0
- package/web-ui/styles/controls-forms.css +360 -0
- package/web-ui/styles/docs-panel.css +182 -0
- package/web-ui/styles/feedback.css +108 -0
- package/web-ui/styles/health-check-dialog.css +144 -0
- package/web-ui/styles/layout-shell.css +376 -0
- package/web-ui/styles/modals-core.css +464 -0
- package/web-ui/styles/navigation-panels.css +348 -0
- package/web-ui/styles/openclaw-structured.css +266 -0
- package/web-ui/styles/responsive.css +450 -0
- package/web-ui/styles/sessions-list.css +400 -0
- package/web-ui/styles/sessions-preview.css +411 -0
- package/web-ui/styles/sessions-toolbar-trash.css +243 -0
- package/web-ui/styles/sessions-usage.css +628 -0
- package/web-ui/styles/skills-list.css +296 -0
- package/web-ui/styles/skills-market.css +335 -0
- package/web-ui/styles/task-orchestration.css +776 -0
- package/web-ui/styles/titles-cards.css +408 -0
- package/web-ui/styles.css +18 -4668
- package/web-ui.html +17 -17
- package/res/screenshot.png +0 -0
- package/res/vue.global.js +0 -18552
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildSessionTimelineNodes,
|
|
3
|
+
buildUsageChartGroups,
|
|
4
|
+
isSessionQueryEnabled
|
|
5
|
+
} from '../logic.mjs';
|
|
6
|
+
import { SESSION_TRASH_PAGE_SIZE } from './app.constants.mjs';
|
|
7
|
+
|
|
8
|
+
function formatUsageSummaryNumber(value) {
|
|
9
|
+
const numeric = Number(value);
|
|
10
|
+
if (!Number.isFinite(numeric) || numeric < 0) {
|
|
11
|
+
return '0';
|
|
12
|
+
}
|
|
13
|
+
return Math.floor(numeric).toLocaleString('en-US');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function formatCompactUsageSummaryNumber(value) {
|
|
17
|
+
const numeric = Number(value);
|
|
18
|
+
if (!Number.isFinite(numeric) || numeric < 0) {
|
|
19
|
+
return '0';
|
|
20
|
+
}
|
|
21
|
+
return new Intl.NumberFormat('en-US', {
|
|
22
|
+
notation: 'compact',
|
|
23
|
+
compactDisplay: 'short',
|
|
24
|
+
maximumFractionDigits: 1
|
|
25
|
+
}).format(Math.floor(numeric));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function readUsageCostNumber(value) {
|
|
29
|
+
const numeric = Number(value);
|
|
30
|
+
if (!Number.isFinite(numeric) || numeric < 0) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return numeric;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function formatUsageEstimatedCost(value, options = {}) {
|
|
37
|
+
const numeric = Number(value);
|
|
38
|
+
if (!Number.isFinite(numeric) || numeric <= 0) {
|
|
39
|
+
return '$0.00';
|
|
40
|
+
}
|
|
41
|
+
const precise = options && options.precise === true;
|
|
42
|
+
if (numeric < 0.0001) {
|
|
43
|
+
return '<$0.0001';
|
|
44
|
+
}
|
|
45
|
+
let fractionDigits = 2;
|
|
46
|
+
if (numeric < 1) {
|
|
47
|
+
fractionDigits = precise ? 6 : 4;
|
|
48
|
+
} else if (numeric >= 100) {
|
|
49
|
+
fractionDigits = 0;
|
|
50
|
+
}
|
|
51
|
+
return new Intl.NumberFormat('en-US', {
|
|
52
|
+
style: 'currency',
|
|
53
|
+
currency: 'USD',
|
|
54
|
+
minimumFractionDigits: fractionDigits,
|
|
55
|
+
maximumFractionDigits: fractionDigits
|
|
56
|
+
}).format(numeric);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function formatUsageRangeLabel(range) {
|
|
60
|
+
const normalized = typeof range === 'string' ? range.trim().toLowerCase() : '7d';
|
|
61
|
+
if (normalized === '30d') return '近 30 天';
|
|
62
|
+
if (normalized === 'all') return '全部';
|
|
63
|
+
return '近 7 天';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function formatUsageDuration(value, options = {}) {
|
|
67
|
+
const numeric = Number(value);
|
|
68
|
+
if (!Number.isFinite(numeric) || numeric <= 0) {
|
|
69
|
+
return '0分';
|
|
70
|
+
}
|
|
71
|
+
const totalMinutes = Math.floor(numeric / 60000);
|
|
72
|
+
if (totalMinutes <= 0) {
|
|
73
|
+
return '<1分';
|
|
74
|
+
}
|
|
75
|
+
const maxParts = Number.isFinite(Number(options.maxParts))
|
|
76
|
+
? Math.max(1, Math.floor(Number(options.maxParts)))
|
|
77
|
+
: 2;
|
|
78
|
+
const compact = options.compact !== false;
|
|
79
|
+
const units = compact
|
|
80
|
+
? [
|
|
81
|
+
{ label: '天', value: 24 * 60 },
|
|
82
|
+
{ label: '时', value: 60 },
|
|
83
|
+
{ label: '分', value: 1 }
|
|
84
|
+
]
|
|
85
|
+
: [
|
|
86
|
+
{ label: '天', value: 24 * 60 },
|
|
87
|
+
{ label: '小时', value: 60 },
|
|
88
|
+
{ label: '分', value: 1 }
|
|
89
|
+
];
|
|
90
|
+
let remainingMinutes = totalMinutes;
|
|
91
|
+
const parts = [];
|
|
92
|
+
for (const unit of units) {
|
|
93
|
+
if (remainingMinutes < unit.value && unit.value !== 1) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const count = unit.value === 1 ? remainingMinutes : Math.floor(remainingMinutes / unit.value);
|
|
97
|
+
if (count <= 0) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
parts.push(`${count}${unit.label}`);
|
|
101
|
+
remainingMinutes -= count * unit.value;
|
|
102
|
+
if (parts.length >= maxParts) {
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return parts.length ? parts.join(compact ? '' : ' ') : '0分';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const KNOWN_USAGE_MODEL_PRICING = Object.freeze({
|
|
110
|
+
'gpt-5.4': Object.freeze({ input: 2.5, output: 15, cacheRead: 0.25, cacheWrite: 0 }),
|
|
111
|
+
'gpt-5.4-mini': Object.freeze({ input: 0.75, output: 4.5, cacheRead: 0.075, cacheWrite: 0 }),
|
|
112
|
+
'gpt-5.3-codex': Object.freeze({ input: 1.75, output: 14, cacheRead: 0.175, cacheWrite: 0 }),
|
|
113
|
+
'gpt-5.2-codex': Object.freeze({ input: 1.75, output: 14, cacheRead: 0.175, cacheWrite: 0 })
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
function createUsagePricingEntry(pricing, source) {
|
|
117
|
+
const resolvedSource = typeof source === 'string' && source.trim() ? source.trim() : 'provider-config';
|
|
118
|
+
return {
|
|
119
|
+
input: readUsageCostNumber(pricing && pricing.input),
|
|
120
|
+
output: readUsageCostNumber(pricing && pricing.output),
|
|
121
|
+
reasoningOutput: readUsageCostNumber(pricing && (pricing.reasoningOutput ?? pricing.reasoning)),
|
|
122
|
+
cacheRead: readUsageCostNumber(pricing && pricing.cacheRead),
|
|
123
|
+
cacheWrite: readUsageCostNumber(pricing && pricing.cacheWrite),
|
|
124
|
+
source: resolvedSource
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function buildUsagePricingIndex(providersList = []) {
|
|
129
|
+
const byProvider = new Map();
|
|
130
|
+
const byModel = new Map();
|
|
131
|
+
const knownByModel = new Map();
|
|
132
|
+
const list = Array.isArray(providersList) ? providersList : [];
|
|
133
|
+
for (const provider of list) {
|
|
134
|
+
if (!provider || typeof provider !== 'object') continue;
|
|
135
|
+
const providerName = typeof provider.name === 'string' ? provider.name.trim() : '';
|
|
136
|
+
const models = Array.isArray(provider.models) ? provider.models : [];
|
|
137
|
+
const providerMap = new Map();
|
|
138
|
+
for (const model of models) {
|
|
139
|
+
if (!model || typeof model !== 'object') continue;
|
|
140
|
+
const modelId = typeof model.id === 'string' ? model.id.trim() : '';
|
|
141
|
+
if (!modelId) continue;
|
|
142
|
+
const pricing = createUsagePricingEntry(
|
|
143
|
+
model.cost && typeof model.cost === 'object' && !Array.isArray(model.cost)
|
|
144
|
+
? model.cost
|
|
145
|
+
: null,
|
|
146
|
+
'provider-config'
|
|
147
|
+
);
|
|
148
|
+
const hasKnownRate = [pricing.input, pricing.output, pricing.reasoningOutput, pricing.cacheRead, pricing.cacheWrite]
|
|
149
|
+
.some((value) => value !== null);
|
|
150
|
+
if (!hasKnownRate) continue;
|
|
151
|
+
providerMap.set(modelId, pricing);
|
|
152
|
+
const modelMatches = byModel.get(modelId) || [];
|
|
153
|
+
modelMatches.push({ provider: providerName, pricing });
|
|
154
|
+
byModel.set(modelId, modelMatches);
|
|
155
|
+
}
|
|
156
|
+
if (providerName && providerMap.size) {
|
|
157
|
+
byProvider.set(providerName, providerMap);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
for (const [modelId, pricing] of Object.entries(KNOWN_USAGE_MODEL_PRICING)) {
|
|
161
|
+
const normalizedModelId = typeof modelId === 'string' ? modelId.trim() : '';
|
|
162
|
+
if (!normalizedModelId || byModel.has(normalizedModelId)) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
knownByModel.set(normalizedModelId, createUsagePricingEntry(pricing, 'public-catalog'));
|
|
166
|
+
}
|
|
167
|
+
return { byProvider, byModel, knownByModel };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function resolveUsagePricingForSession(session, pricingIndex, fallbackProvider = '') {
|
|
171
|
+
if (!session || typeof session !== 'object' || !pricingIndex || typeof pricingIndex !== 'object') {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
const model = typeof session.model === 'string' ? session.model.trim() : '';
|
|
175
|
+
if (!model) return null;
|
|
176
|
+
const provider = typeof session.provider === 'string' ? session.provider.trim() : '';
|
|
177
|
+
const effectiveProvider = provider || fallbackProvider;
|
|
178
|
+
if (effectiveProvider) {
|
|
179
|
+
const providerMap = pricingIndex.byProvider instanceof Map ? pricingIndex.byProvider.get(effectiveProvider) : null;
|
|
180
|
+
if (providerMap instanceof Map && providerMap.has(model)) {
|
|
181
|
+
return providerMap.get(model);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const modelMatches = pricingIndex.byModel instanceof Map ? pricingIndex.byModel.get(model) : null;
|
|
185
|
+
if (Array.isArray(modelMatches) && modelMatches.length === 1) {
|
|
186
|
+
return modelMatches[0].pricing;
|
|
187
|
+
}
|
|
188
|
+
const knownPricing = pricingIndex.knownByModel instanceof Map ? pricingIndex.knownByModel.get(model) : null;
|
|
189
|
+
if (knownPricing) {
|
|
190
|
+
return knownPricing;
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function shouldEstimateUsageCostForSession(session) {
|
|
196
|
+
if (!session || typeof session !== 'object') {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
const source = typeof session.source === 'string' ? session.source.trim().toLowerCase() : '';
|
|
200
|
+
const provider = typeof session.provider === 'string' ? session.provider.trim().toLowerCase() : '';
|
|
201
|
+
const model = typeof session.model === 'string' ? session.model.trim().toLowerCase() : '';
|
|
202
|
+
if (source === 'claude' || provider === 'claude') {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
if (/^claude(?:[-_]|$)/.test(model)) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function estimateUsageCostSummary(sessions, providersList, currentProvider) {
|
|
212
|
+
const list = Array.isArray(sessions) ? sessions : [];
|
|
213
|
+
const pricingIndex = buildUsagePricingIndex(providersList);
|
|
214
|
+
let totalCostUsd = 0;
|
|
215
|
+
let estimatedSessions = 0;
|
|
216
|
+
let totalTokens = 0;
|
|
217
|
+
let estimatedTokens = 0;
|
|
218
|
+
let configuredSessions = 0;
|
|
219
|
+
let catalogSessions = 0;
|
|
220
|
+
let missingPricingSessions = 0;
|
|
221
|
+
let missingTokenSessions = 0;
|
|
222
|
+
let supportedSessions = 0;
|
|
223
|
+
let skippedUnsupportedSessions = 0;
|
|
224
|
+
|
|
225
|
+
for (const session of list) {
|
|
226
|
+
if (!session || typeof session !== 'object') continue;
|
|
227
|
+
if (!shouldEstimateUsageCostForSession(session)) {
|
|
228
|
+
skippedUnsupportedSessions += 1;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
supportedSessions += 1;
|
|
232
|
+
const inputTokens = Number.isFinite(Number(session.inputTokens)) ? Math.max(0, Math.floor(Number(session.inputTokens))) : null;
|
|
233
|
+
const cachedInputTokens = Number.isFinite(Number(session.cachedInputTokens)) ? Math.max(0, Math.floor(Number(session.cachedInputTokens))) : 0;
|
|
234
|
+
const outputTokens = Number.isFinite(Number(session.outputTokens)) ? Math.max(0, Math.floor(Number(session.outputTokens))) : null;
|
|
235
|
+
const reasoningOutputTokens = Number.isFinite(Number(session.reasoningOutputTokens)) ? Math.max(0, Math.floor(Number(session.reasoningOutputTokens))) : 0;
|
|
236
|
+
const billableInputTokens = Math.max(0, (inputTokens || 0) - cachedInputTokens);
|
|
237
|
+
const fallbackSessionTokens = billableInputTokens + cachedInputTokens + (outputTokens || 0) + reasoningOutputTokens;
|
|
238
|
+
const totalSessionTokens = Number.isFinite(Number(session.totalTokens))
|
|
239
|
+
? Math.max(0, Math.floor(Number(session.totalTokens)))
|
|
240
|
+
: fallbackSessionTokens;
|
|
241
|
+
totalTokens += totalSessionTokens;
|
|
242
|
+
const pricing = resolveUsagePricingForSession(session, pricingIndex, currentProvider);
|
|
243
|
+
if (!pricing) {
|
|
244
|
+
missingPricingSessions += 1;
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (inputTokens === null && outputTokens === null && reasoningOutputTokens === 0) {
|
|
248
|
+
missingTokenSessions += 1;
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
const estimatedUsd = (
|
|
252
|
+
((pricing.input || 0) * billableInputTokens)
|
|
253
|
+
+ ((pricing.cacheRead || 0) * cachedInputTokens)
|
|
254
|
+
+ (((pricing.reasoningOutput ?? pricing.output) || 0) * reasoningOutputTokens)
|
|
255
|
+
+ ((pricing.output || 0) * (outputTokens || 0))
|
|
256
|
+
) / 1000000;
|
|
257
|
+
totalCostUsd += estimatedUsd;
|
|
258
|
+
estimatedSessions += 1;
|
|
259
|
+
estimatedTokens += totalSessionTokens;
|
|
260
|
+
if (pricing.source === 'public-catalog') {
|
|
261
|
+
catalogSessions += 1;
|
|
262
|
+
} else {
|
|
263
|
+
configuredSessions += 1;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const coveragePercent = totalTokens > 0
|
|
268
|
+
? Math.round((estimatedTokens / totalTokens) * 100)
|
|
269
|
+
: (estimatedSessions > 0 ? 100 : 0);
|
|
270
|
+
return {
|
|
271
|
+
totalCostUsd,
|
|
272
|
+
estimatedSessions,
|
|
273
|
+
totalSessions: supportedSessions,
|
|
274
|
+
estimatedTokens,
|
|
275
|
+
totalTokens,
|
|
276
|
+
coveragePercent,
|
|
277
|
+
hasEstimate: estimatedSessions > 0,
|
|
278
|
+
configuredSessions,
|
|
279
|
+
catalogSessions,
|
|
280
|
+
missingPricingSessions,
|
|
281
|
+
missingTokenSessions,
|
|
282
|
+
skippedUnsupportedSessions
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function createSessionComputed() {
|
|
287
|
+
return {
|
|
288
|
+
isSessionQueryEnabled() {
|
|
289
|
+
return isSessionQueryEnabled(this.sessionFilterSource);
|
|
290
|
+
},
|
|
291
|
+
activeSessionExportKey() {
|
|
292
|
+
return this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
|
|
293
|
+
},
|
|
294
|
+
sortedSessionsList() {
|
|
295
|
+
const list = Array.isArray(this.sessionsList) ? this.sessionsList : [];
|
|
296
|
+
if (list.length === 0) return [];
|
|
297
|
+
const pinnedMap = (this.sessionPinnedMap && typeof this.sessionPinnedMap === 'object')
|
|
298
|
+
? this.sessionPinnedMap
|
|
299
|
+
: {};
|
|
300
|
+
if (Object.keys(pinnedMap).length === 0) {
|
|
301
|
+
return list;
|
|
302
|
+
}
|
|
303
|
+
let hasPinned = false;
|
|
304
|
+
const decorated = list.map((session, index) => {
|
|
305
|
+
const key = session ? this.getSessionExportKey(session) : '';
|
|
306
|
+
const rawPinnedAt = key ? pinnedMap[key] : 0;
|
|
307
|
+
const pinnedAt = Number.isFinite(Number(rawPinnedAt))
|
|
308
|
+
? Math.floor(Number(rawPinnedAt))
|
|
309
|
+
: 0;
|
|
310
|
+
const isPinned = pinnedAt > 0;
|
|
311
|
+
if (isPinned) {
|
|
312
|
+
hasPinned = true;
|
|
313
|
+
}
|
|
314
|
+
return { session, index, pinnedAt, isPinned };
|
|
315
|
+
});
|
|
316
|
+
if (!hasPinned) return list;
|
|
317
|
+
decorated.sort((a, b) => {
|
|
318
|
+
if (a.isPinned !== b.isPinned) return a.isPinned ? -1 : 1;
|
|
319
|
+
if (a.isPinned && a.pinnedAt !== b.pinnedAt) return b.pinnedAt - a.pinnedAt;
|
|
320
|
+
return a.index - b.index;
|
|
321
|
+
});
|
|
322
|
+
return decorated.map(item => item.session);
|
|
323
|
+
},
|
|
324
|
+
visibleSessionsList() {
|
|
325
|
+
if (!this.sessionListRenderEnabled) {
|
|
326
|
+
return [];
|
|
327
|
+
}
|
|
328
|
+
const list = Array.isArray(this.sortedSessionsList) ? this.sortedSessionsList : [];
|
|
329
|
+
if (list.length === 0) {
|
|
330
|
+
return [];
|
|
331
|
+
}
|
|
332
|
+
const rawVisibleCount = Number(this.sessionListVisibleCount);
|
|
333
|
+
const visibleCount = Number.isFinite(rawVisibleCount)
|
|
334
|
+
? Math.max(0, Math.floor(rawVisibleCount))
|
|
335
|
+
: 0;
|
|
336
|
+
let targetCount = visibleCount > 0 ? Math.min(visibleCount, list.length) : Math.min(list.length, 1);
|
|
337
|
+
const activeKey = this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
|
|
338
|
+
if (activeKey) {
|
|
339
|
+
const activeIndex = list.findIndex((session) => this.getSessionExportKey(session) === activeKey);
|
|
340
|
+
if (activeIndex >= 0) {
|
|
341
|
+
targetCount = Math.max(targetCount, activeIndex + 1);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (targetCount >= list.length) {
|
|
345
|
+
return list;
|
|
346
|
+
}
|
|
347
|
+
return list.slice(0, targetCount);
|
|
348
|
+
},
|
|
349
|
+
activeSessionVisibleMessages() {
|
|
350
|
+
if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
|
|
351
|
+
return [];
|
|
352
|
+
}
|
|
353
|
+
const list = Array.isArray(this.activeSessionMessages) ? this.activeSessionMessages : [];
|
|
354
|
+
const rawCount = Number(this.sessionPreviewVisibleCount);
|
|
355
|
+
const visibleCount = Number.isFinite(rawCount)
|
|
356
|
+
? Math.max(0, Math.floor(rawCount))
|
|
357
|
+
: 0;
|
|
358
|
+
if (visibleCount <= 0) {
|
|
359
|
+
const initialBatchSize = Number.isFinite(this.sessionPreviewInitialBatchSize)
|
|
360
|
+
? Math.max(1, Math.floor(this.sessionPreviewInitialBatchSize))
|
|
361
|
+
: 12;
|
|
362
|
+
return list.slice(0, Math.min(initialBatchSize, list.length));
|
|
363
|
+
}
|
|
364
|
+
if (visibleCount >= list.length) return list;
|
|
365
|
+
return list.slice(0, visibleCount);
|
|
366
|
+
},
|
|
367
|
+
canLoadMoreSessionMessages() {
|
|
368
|
+
if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
const total = Array.isArray(this.activeSessionMessages) ? this.activeSessionMessages.length : 0;
|
|
372
|
+
const visible = Array.isArray(this.activeSessionVisibleMessages) ? this.activeSessionVisibleMessages.length : 0;
|
|
373
|
+
return total > visible;
|
|
374
|
+
},
|
|
375
|
+
sessionPreviewRemainingCount() {
|
|
376
|
+
const total = Array.isArray(this.activeSessionMessages) ? this.activeSessionMessages.length : 0;
|
|
377
|
+
const visible = Array.isArray(this.activeSessionVisibleMessages) ? this.activeSessionVisibleMessages.length : 0;
|
|
378
|
+
return Math.max(0, total - visible);
|
|
379
|
+
},
|
|
380
|
+
sessionTimelineNodes() {
|
|
381
|
+
if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
|
|
382
|
+
return [];
|
|
383
|
+
}
|
|
384
|
+
return buildSessionTimelineNodes(this.activeSessionVisibleMessages, {
|
|
385
|
+
getKey: (message, index) => this.getRecordRenderKey(message, index)
|
|
386
|
+
});
|
|
387
|
+
},
|
|
388
|
+
sessionTimelineNodeKeyMap() {
|
|
389
|
+
const nodes = Array.isArray(this.sessionTimelineNodes) ? this.sessionTimelineNodes : [];
|
|
390
|
+
if (!nodes.length) {
|
|
391
|
+
return Object.create(null);
|
|
392
|
+
}
|
|
393
|
+
const map = Object.create(null);
|
|
394
|
+
for (const node of nodes) {
|
|
395
|
+
if (!node || !node.key) continue;
|
|
396
|
+
map[node.key] = true;
|
|
397
|
+
}
|
|
398
|
+
return map;
|
|
399
|
+
},
|
|
400
|
+
sessionTimelineActiveTitle() {
|
|
401
|
+
if (!this.sessionTimelineActiveKey) return '';
|
|
402
|
+
const nodes = Array.isArray(this.sessionTimelineNodes) ? this.sessionTimelineNodes : [];
|
|
403
|
+
const matched = nodes.find(node => node.key === this.sessionTimelineActiveKey);
|
|
404
|
+
return matched ? matched.title : '';
|
|
405
|
+
},
|
|
406
|
+
sessionQueryPlaceholder() {
|
|
407
|
+
if (this.isSessionQueryEnabled) {
|
|
408
|
+
return '关键词检索(支持 Codex/Claude,例:claude code)';
|
|
409
|
+
}
|
|
410
|
+
return '当前来源暂不支持关键词检索';
|
|
411
|
+
},
|
|
412
|
+
sessionUsageCharts() {
|
|
413
|
+
return buildUsageChartGroups(this.sessionsUsageList, {
|
|
414
|
+
range: this.sessionsUsageTimeRange
|
|
415
|
+
});
|
|
416
|
+
},
|
|
417
|
+
sessionUsageSummaryCards() {
|
|
418
|
+
const summary = this.sessionUsageCharts && this.sessionUsageCharts.summary
|
|
419
|
+
? this.sessionUsageCharts.summary
|
|
420
|
+
: { totalSessions: 0, totalMessages: 0, totalTokens: 0, totalContextWindow: 0, activeDurationMs: 0, totalDurationMs: 0, activeDays: 0, avgMessagesPerSession: 0, busiestDay: null, busiestHour: null };
|
|
421
|
+
const filteredUsageSessions = this.sessionUsageCharts && Array.isArray(this.sessionUsageCharts.filteredSessions)
|
|
422
|
+
? this.sessionUsageCharts.filteredSessions
|
|
423
|
+
: this.sessionsUsageList;
|
|
424
|
+
const usageRangeLabel = formatUsageRangeLabel(this.sessionsUsageTimeRange);
|
|
425
|
+
const estimatedCost = estimateUsageCostSummary(
|
|
426
|
+
filteredUsageSessions,
|
|
427
|
+
this.providersList,
|
|
428
|
+
this.currentProvider
|
|
429
|
+
);
|
|
430
|
+
return [
|
|
431
|
+
{ key: 'sessions', label: '总会话数', value: formatUsageSummaryNumber(summary.totalSessions || 0) },
|
|
432
|
+
{ key: 'messages', label: '总消息数', value: formatUsageSummaryNumber(summary.totalMessages || 0) },
|
|
433
|
+
{
|
|
434
|
+
key: 'tokens',
|
|
435
|
+
label: '总 token 数',
|
|
436
|
+
value: formatCompactUsageSummaryNumber(summary.totalTokens || 0),
|
|
437
|
+
title: formatUsageSummaryNumber(summary.totalTokens || 0)
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
key: 'context-window',
|
|
441
|
+
label: '总上下文数',
|
|
442
|
+
value: formatCompactUsageSummaryNumber(summary.totalContextWindow || 0),
|
|
443
|
+
title: formatUsageSummaryNumber(summary.totalContextWindow || 0)
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
key: 'estimated-cost',
|
|
447
|
+
label: `预估费用 · ${usageRangeLabel}`,
|
|
448
|
+
value: estimatedCost.hasEstimate ? formatUsageEstimatedCost(estimatedCost.totalCostUsd) : '暂无',
|
|
449
|
+
title: estimatedCost.hasEstimate
|
|
450
|
+
? `${estimatedCost.skippedUnsupportedSessions > 0 ? '暂不含 Claude,' : ''}${estimatedCost.catalogSessions > 0
|
|
451
|
+
? (estimatedCost.configuredSessions > 0 ? '按已配置单价 + 公开模型目录估算' : '按公开模型目录估算')
|
|
452
|
+
: '按已配置单价估算'},估算 ${formatUsageEstimatedCost(estimatedCost.totalCostUsd, { precise: true })},覆盖 ${estimatedCost.estimatedSessions}/${estimatedCost.totalSessions} 个会话,约 ${estimatedCost.coveragePercent}% token`
|
|
453
|
+
: `${estimatedCost.skippedUnsupportedSessions > 0 ? '暂不统计 Claude 费用。' : ''}缺少可匹配的模型单价或 token 拆分。请先补 models.cost,或确认会话已记录 input/output token。`
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
key: 'active-duration',
|
|
457
|
+
label: '活跃时长',
|
|
458
|
+
value: formatUsageDuration(summary.activeDurationMs || 0, { compact: true }),
|
|
459
|
+
title: `累计会话跨度 ${formatUsageDuration(summary.activeDurationMs || 0, { maxParts: 3, compact: false })}`
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
key: 'total-duration',
|
|
463
|
+
label: '总时长',
|
|
464
|
+
value: formatUsageDuration(summary.totalDurationMs || 0, { compact: true }),
|
|
465
|
+
title: `整体时间跨度 ${formatUsageDuration(summary.totalDurationMs || 0, { maxParts: 3, compact: false })}`
|
|
466
|
+
},
|
|
467
|
+
{ key: 'days', label: '活跃天数', value: formatUsageSummaryNumber(summary.activeDays || 0) },
|
|
468
|
+
{ key: 'avg-messages', label: '平均每会话消息', value: summary.avgMessagesPerSession || 0 },
|
|
469
|
+
{
|
|
470
|
+
key: 'busiest-day',
|
|
471
|
+
label: '最忙日',
|
|
472
|
+
value: summary.busiestDay && summary.busiestDay.totalSessions > 0
|
|
473
|
+
? `${summary.busiestDay.label} · ${summary.busiestDay.totalSessions}`
|
|
474
|
+
: '暂无'
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
key: 'busiest-hour',
|
|
478
|
+
label: '高峰时段',
|
|
479
|
+
value: summary.busiestHour && summary.busiestHour.count > 0
|
|
480
|
+
? `${summary.busiestHour.label} · ${summary.busiestHour.count}`
|
|
481
|
+
: '暂无'
|
|
482
|
+
}
|
|
483
|
+
];
|
|
484
|
+
},
|
|
485
|
+
visibleSessionTrashItems() {
|
|
486
|
+
const items = Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems : [];
|
|
487
|
+
const visibleCount = Number(this.sessionTrashVisibleCount);
|
|
488
|
+
const safeVisibleCount = Number.isFinite(visibleCount) && visibleCount > 0
|
|
489
|
+
? Math.floor(visibleCount)
|
|
490
|
+
: SESSION_TRASH_PAGE_SIZE;
|
|
491
|
+
return items.slice(0, safeVisibleCount);
|
|
492
|
+
},
|
|
493
|
+
sessionTrashHasMoreItems() {
|
|
494
|
+
return this.visibleSessionTrashItems.length < this.sessionTrashCount;
|
|
495
|
+
},
|
|
496
|
+
sessionTrashHiddenCount() {
|
|
497
|
+
return Math.max(0, this.sessionTrashCount - this.visibleSessionTrashItems.length);
|
|
498
|
+
},
|
|
499
|
+
sessionTrashCount() {
|
|
500
|
+
const totalCount = Number(this.sessionTrashTotalCount);
|
|
501
|
+
if (Number.isFinite(totalCount) && totalCount >= 0) {
|
|
502
|
+
return Math.max(0, Math.floor(totalCount));
|
|
503
|
+
}
|
|
504
|
+
return Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems.length : 0;
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const SESSION_TRASH_LIST_LIMIT = 500;
|
|
2
|
+
export const SESSION_TRASH_PAGE_SIZE = 200;
|
|
3
|
+
export const DEFAULT_MODEL_CONTEXT_WINDOW = 190000;
|
|
4
|
+
export const DEFAULT_MODEL_AUTO_COMPACT_TOKEN_LIMIT = 185000;
|
|
5
|
+
export const DEFAULT_OPENCLAW_TEMPLATE = `{
|
|
6
|
+
// OpenClaw config (JSON5)
|
|
7
|
+
agent: {
|
|
8
|
+
model: "gpt-4.1"
|
|
9
|
+
},
|
|
10
|
+
agents: {
|
|
11
|
+
defaults: {
|
|
12
|
+
workspace: "~/.openclaw/workspace"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}`;
|