dsh-cost-meter 1.8.19 → 1.8.20
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 +6 -6
- package/README.zh-CN.md +6 -6
- package/docs/call-detail-preview.png +0 -0
- package/docs/context-costs-design.md +17 -3
- package/docs/step-billing-preview.png +0 -0
- package/lib/backfill.js +1 -1
- package/lib/call-inspection.js +112 -0
- package/lib/client.js +2 -2
- package/lib/client.statistics.js +18 -7
- package/lib/index.js +4 -0
- package/lib/trajectory.js +99 -0
- package/lib/turn-cost.js +2 -1
- package/lib/typert.host.js +14 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
Per-conversation cost · daily totals · OpenCode Go subscription quota display · budget with usage percentage · official account balance · custom provider balance · balance progress bar · history · peak/off-peak pricing hours display (peak hours UTC 01:00–04:00, 06:00–10:00; weekends and Chinese public holidays are off-peak all day, with separate labels) · pre-switch popup & system-notification alerts for peak/off-peak changes (position / lead time / alert type configurable) · one-click price sync from the official docs · Codex-style token usage heat grid · multi-vendor model pricing (built-in 170+ model-ID catalog with auto-matching) · mainstream Coding Plan quota queries & display (Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet / Volcano Ark / Qwen / Xiaomi MiMo) plan/API dual-track billing (subscription quota vs pay-as-you-go money separated, per-1% & full-window token/equivalent-cost estimates with daily/weekly/monthly curves) · · quota strip above the input box (budget / Go / coding-plan usage in one row, toggleable)
|
|
10
10
|
|
|
11
|
-
[](https://github.com/Han-1413141/dsh-cost-meter)
|
|
12
12
|
|
|
13
|
-
**v1.8.
|
|
13
|
+
**v1.8.20** opens Cost details with one aggregate donut showing each trajectory step’s share of session costs. Individual step charts and rate tables start collapsed. Overview keeps a compact billing trajectory with input, output, cache costs and total share per step. Existing billing composition remains available, while individual calls can show saved inputs, responses and tool records on demand. The main page requires fewer view changes. Gateway quota cards now expose their refresh interval. See the [guide and preview](docs/context-costs-design.md#english).
|
|
14
14
|
|
|
15
15
|
Desktop users: follow the [Desktop installation instructions](docs/install-troubleshooting.md#desktop-安装与更新) for the application's own CLI and `desktop` Profile.
|
|
16
16
|
|
|
@@ -323,22 +323,22 @@ On Node.js 20, use `npm install -g pnpm@10` instead. See [pnpm installation and
|
|
|
323
323
|
dsh plugin --profile web add dsh-cost-meter
|
|
324
324
|
```
|
|
325
325
|
|
|
326
|
-
**PowerShell one-click script** (copy the whole line, paste, press Enter; pnpm is provisioned automatically, git is auto-detected — no clone needed; the install chain is **pinned to the release tag `v1.8.
|
|
326
|
+
**PowerShell one-click script** (copy the whole line, paste, press Enter; pnpm is provisioned automatically, git is auto-detected — no clone needed; the install chain is **pinned to the release tag `v1.8.20`** — review the script before running):
|
|
327
327
|
|
|
328
328
|
```powershell
|
|
329
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.
|
|
329
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.20/install.ps1 | iex
|
|
330
330
|
```
|
|
331
331
|
|
|
332
332
|
**Or a plain command line** (the machine must already have pnpm and git; also pinned to the tag):
|
|
333
333
|
|
|
334
334
|
```sh
|
|
335
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.
|
|
335
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.20
|
|
336
336
|
```
|
|
337
337
|
|
|
338
338
|
Without git, use the GitHub tag archive:
|
|
339
339
|
|
|
340
340
|
```sh
|
|
341
|
-
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.
|
|
341
|
+
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.20.tar.gz
|
|
342
342
|
```
|
|
343
343
|
|
|
344
344
|
After installing, **restart** `dsh web` (plugin rows, the Typert manifest and the client bundle are all scanned at startup):
|
package/README.zh-CN.md
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
本会话费用 · 当日费用 · OpenCode Go 订阅额度显示 · 预算与已用百分比 · 官方账户余额 · 自定义 Provider 余额查询(可配任意 HTTP 端点) · 余额三段进度条 · 历史记录 · 峰谷计价时段显示(UTC 01:00–04:00、06:00–10:00 为峰时段;周末与中国法定假日全天按谷价,分别标注) · 峰/谷切换前弹窗与系统通知提醒(位置/提前量/提醒类型可配) · 官方价格一键同步 · 类 Codex Token 用量热图 · 多厂商多模型价格计费(内置 170+ 模型 ID 价格目录与自动匹配) · 主流 Coding Plan 额度查询与显示(Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet / 火山方舟 / 千问 / 小米 MiMo 十一家,含 Volcano Ark AK/SK 签名与 MiMo 控制台 Cookie 查询) · Plan/API 双轨计费(订阅额度与按量金额分离统计,每 1% 额度与满窗的 token/等值金额估算及日/周/月曲线) · 输入框上方额度横条(预算/Go/Coding Plan 用量一条横排显示,可开关)
|
|
10
10
|
|
|
11
|
-
[](https://github.com/Han-1413141/dsh-cost-meter)
|
|
12
12
|
|
|
13
|
-
**v1.8.
|
|
13
|
+
**v1.8.20** 的“费用明细”默认用一张圆环图汇总全部轨迹步骤的费用占比,逐步图表与单价明细收起。概览中的计费轨迹直接列出每步输入、输出、缓存金额及占比。原有费用构成保留,单次调用还可按需查看输入、回复和工具内容;主页面布局更紧凑,减少页面切换。另补齐网关额度刷新间隔设置。详见[使用说明与界面预览](docs/context-costs-design.md)。
|
|
14
14
|
|
|
15
15
|
桌面端用户请按 [Desktop 安装说明](docs/install-troubleshooting.md#desktop-安装与更新),使用应用自带的 CLI 和 `desktop` Profile。
|
|
16
16
|
|
|
@@ -323,22 +323,22 @@ Node.js 20 请改用 `npm install -g pnpm@10`。版本要求见 [pnpm 官方安
|
|
|
323
323
|
dsh plugin --profile web add dsh-cost-meter
|
|
324
324
|
```
|
|
325
325
|
|
|
326
|
-
**PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.8.
|
|
326
|
+
**PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.8.20`**,建议先下载审阅再运行):
|
|
327
327
|
|
|
328
328
|
```powershell
|
|
329
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.
|
|
329
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.20/install.ps1 | iex
|
|
330
330
|
```
|
|
331
331
|
|
|
332
332
|
**或直接命令行**(机器上需已有 pnpm 与 git;同样固定到 tag):
|
|
333
333
|
|
|
334
334
|
```sh
|
|
335
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.
|
|
335
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.20
|
|
336
336
|
```
|
|
337
337
|
|
|
338
338
|
没有 git 时可用 GitHub tag 打包直链:
|
|
339
339
|
|
|
340
340
|
```sh
|
|
341
|
-
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.
|
|
341
|
+
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.20.tar.gz
|
|
342
342
|
```
|
|
343
343
|
|
|
344
344
|
安装后**重启** `dsh web`(插件行、Typert 清单与客户端 bundle 均在启动时扫描):
|
|
Binary file
|
|
@@ -2,9 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
## 使用方式
|
|
4
4
|
|
|
5
|
-
点击对话输入区的费用明细,只查看当前对话。费用概览集中显示总费用、调用次数、Token
|
|
5
|
+
点击对话输入区的费用明细,只查看当前对话。费用概览集中显示总费用、调用次数、Token、缓存命中率和费用构成;计费轨迹直接显示在概览,逐次调用明细原位展开;“费用明细”默认用一张圆环图汇总全部轨迹步骤费用,每块代表一步。逐步独立圆环和上下文参考默认折叠。设置中的计费统计保留跨对话查询入口。
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
“步骤费用构成”按已有轨迹步骤汇总费用,显示每步金额与全会话占比。超过 20 步时,费用最高的 20 步单列,其余合并为一块,所有步骤均计入分母。“计费轨迹”逐步列出输入、输出、缓存金额及占比,点击步骤可展开 Token、单价和金额。多个工具属于同一步时,整步模型费用只计一次;工具名称用于识别步骤,不把整笔费用重复分摊给各工具。缺少步骤编号的调用单列。
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
步骤统计只提取日志中的轮次、步骤、工具名称和用量,不读取文本做内容分类。默认连续显示 100 步,更多步骤在原位置展开;统计分母始终覆盖完整会话。已完成日志的工具名称索引缓存按文件大小和修改时间失效,实时会话按事件变化刷新。
|
|
12
|
+
|
|
13
|
+
逐次调用图按整个查询范围计算占比,显示费用最高的 7 次和其余合计。点击单次调用可跨页定位;展开后左侧为费用圆环与计费明细,右侧切换“输入记录、模型回复、工具调用”。各计费项目显示 Token、每百万 Token 单价、金额与占比;点击圆环项目可切换到相关内容。缓存对比展示缓存读取占输入 Token 和输入费用的比例,多模型或多环节时显示相应费用分布。
|
|
14
|
+
|
|
15
|
+
输入记录区分本轮用户输入、技能、注入内容与上一步工具返回;回复区展示正文及已记录的思考;工具区显示参数、返回结果、状态与耗时。读取内容时核对会话、计费事件序号与时间。输入记录不是完整 HTTP 请求体,不含请求头;提供商没有逐段缓存归属数据,费用不按这些文本片段硬分摊。工具的输出文本也不作为独立模型调用重复计费。
|
|
16
|
+
|
|
17
|
+
原始内容只在展开单次调用时读取。每段文本上限 16,000 字符,超出标记截取;工具每页 20 项。附件仅显示类型;未保存的内容显示缺失状态。所有内容使用纯文本显示。
|
|
18
|
+
|
|
19
|
+

|
|
8
20
|
|
|
9
21
|
圆环图显示整体构成,右侧图例列出各部分百分比。悬停或用键盘聚焦圆环/图例,即可看到该部分的 Token、金额与占比。鼠标移走或焦点移出后恢复整体视图,不留下选中状态。很小的部分也可通过图例查看。完整明细默认折叠。关闭按钮固定在弹窗顶部,滚动到底部仍然可用,也可按 Esc 关闭。
|
|
10
22
|
|
|
@@ -79,9 +91,11 @@ dsh-context 主要展示上下文占用、组成、变化和注入事件。0.66.
|
|
|
79
91
|
|
|
80
92
|
## English
|
|
81
93
|
|
|
94
|
+
Each expanded call pairs a cost donut and a token/rate/cost/share table with Inputs, Response and Tools views. Inputs separate user text, skills, injected context and preceding tool results. Response includes recorded reasoning; tools show arguments, results, status and duration. Content is fetched only when expanded and matched by session, billed event sequence and timestamp. Excerpts are bounded to 16,000 characters per text field, tools are paged by 20, and attachments are represented by type. Missing content remains explicit. Input excerpts are not a complete HTTP request; per-message cache attribution is unavailable, so costs are not apportioned by text length.
|
|
95
|
+
|
|
82
96
|
Open **Cost details** beside the conversation input to see only that conversation: call-log totals, context composition, latest-call charges and turn/call details. Cross-conversation statistics remain available in Settings.
|
|
83
97
|
|
|
84
|
-
Overview
|
|
98
|
+
Overview and Cost details are the two main views. Overview keeps the input/output/cache composition beside step cost composition and a compact billing trajectory. Cost details opens one aggregate donut: each slice represents a trajectory step’s share of the full session cost. The top 20 steps are separate slices; any remaining steps are combined without dropping their costs. Individual step donuts and token/rate/cost tables are in a collapsed section; context references are also collapsed. Individual call records expand within Overview. Overview includes per-call shares across the full selection, cache token/cost comparisons and conditional model/activity charts. The seven highest-cost calls are individual slices; the rest are combined. Select a call to open its details, even on another page. Donut charts use a brighter palette with compact percentage legends. Hover or focus a slice or legend item to inspect its amount and tokens, including tiny categories. Leaving the chart or moving keyboard focus away clears the highlight. Expanding the individual-step section reveals its billing tables, which can also be collapsed. The close button stays visible while scrolling; Escape also closes the dialog. Dialogs follow DSH popup background tokens, including dsh-dream-skin opacity.
|
|
85
99
|
|
|
86
100
|
Expand **Display and integration settings → dsh-context integration** to enable or disable the optional integration or reopen its before/after preview. Supported versions are 0.62.0 and 0.66.0. Integration starts off; dismissing the initial prompt prevents repeated automatic prompts. When enabled, costs appear inside the peer's current-context card in the conversation tab, right sidebar and `/context` overlay.
|
|
87
101
|
|
|
Binary file
|
package/lib/backfill.js
CHANGED
|
@@ -511,7 +511,7 @@ export function replaySessionRecords(records, config, wantDates = null, collectS
|
|
|
511
511
|
const sample = { key, date, providerKey, buckets, cost, apiCost, seed: isSeed }
|
|
512
512
|
if (samples) {
|
|
513
513
|
if (prev) samples.delete(prev)
|
|
514
|
-
samples.set(sample, { ...sample, atMs, provider: effectiveProvider, model: sampleModel, resolved, peak, plan, kind: isCompaction ? 'compaction' : isNativeSearch ? 'search' : 'model',
|
|
514
|
+
samples.set(sample, { ...sample, atMs, logSeq: !isNativeSearch && Number.isSafeInteger(event.seq) && event.seq >= 0 ? event.seq : null, provider: effectiveProvider, model: sampleModel, resolved, peak, plan, kind: isCompaction ? 'compaction' : isNativeSearch ? 'search' : 'model',
|
|
515
515
|
turn: Number.isSafeInteger(event.data?.turn) && event.data.turn >= 0 ? event.data.turn : null,
|
|
516
516
|
step: Number.isSafeInteger(event.data?.step) && event.data.step >= 0 ? event.data.step : null })
|
|
517
517
|
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/** On-demand, bounded excerpts for one billed log event. Never replay a model request. */
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { resolveDshHome } from '@deepseek-ai/dsh-home-paths'
|
|
4
|
+
import { listSessionLogs, iterateSessionRecords } from './backfill.js'
|
|
5
|
+
|
|
6
|
+
const LIMIT = 16000
|
|
7
|
+
const validSeq = n => Number.isSafeInteger(n) && n >= 0
|
|
8
|
+
const clip = value => { const text = typeof value === 'string' ? value : JSON.stringify(value ?? '', null, 2); return { text: text.slice(0, LIMIT), truncated: text.length > LIMIT } }
|
|
9
|
+
const blocks = (content, reasoning = false) => {
|
|
10
|
+
if (typeof content === 'string') return reasoning ? '' : content
|
|
11
|
+
return (Array.isArray(content) ? content : []).map(block => {
|
|
12
|
+
if (block?.type === (reasoning ? 'reasoning' : 'text')) return String(block.text ?? '')
|
|
13
|
+
return !reasoning && !['reasoning', 'tool-call'].includes(block?.type) ? `[${String(block?.type ?? 'attachment')}]` : ''
|
|
14
|
+
}).filter(Boolean).join('\n')
|
|
15
|
+
}
|
|
16
|
+
const empty = offset => ({ found: false, kind: 'model', input: '', injected: '', skills: '', precedingTools: '', output: '', reasoning: '', truncated: false, tools: [], totalTools: 0, offset })
|
|
17
|
+
|
|
18
|
+
export async function inspectCall(records, seq, offset = 0, atMs) {
|
|
19
|
+
let result = empty(offset), activeTurn = null, activeStep = null, scanned = 0, results = '', resultsTruncated = false
|
|
20
|
+
let selected = new Map(), seenTools = new Set(), inputIds = new Set()
|
|
21
|
+
const append = (key, value) => { const next = clip(result[key] + value); result[key] = next.text; result.truncated ||= next.truncated }
|
|
22
|
+
const resetStep = () => {
|
|
23
|
+
result.precedingTools = results; result.truncated ||= resultsTruncated; results = ''; resultsTruncated = false
|
|
24
|
+
result.output = ''; result.reasoning = ''; result.tools = []; result.totalTools = 0
|
|
25
|
+
selected = new Map(); seenTools = new Set()
|
|
26
|
+
}
|
|
27
|
+
const addTool = (data, event) => {
|
|
28
|
+
const id = String(data.callId ?? data.id ?? '')
|
|
29
|
+
if (!id) return
|
|
30
|
+
if (seenTools.has(id)) {
|
|
31
|
+
if (event.type === 'tool/call' && selected.has(id)) selected.get(id).atMs = Number.isFinite(event.time) ? event.time : 0
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
seenTools.add(id)
|
|
35
|
+
const index = result.totalTools++
|
|
36
|
+
if (index < offset || index >= offset + 20) return
|
|
37
|
+
const args = clip(data.arguments)
|
|
38
|
+
const row = { seq: validSeq(event.seq) ? event.seq : index, step: activeStep, name: String(data.name ?? ''), callId: id,
|
|
39
|
+
atMs: Number.isFinite(event.time) ? event.time : 0, durationMs: null, arguments: args.text, result: '', truncated: args.truncated, status: 'pending' }
|
|
40
|
+
result.tools.push(row); selected.set(id, row)
|
|
41
|
+
}
|
|
42
|
+
for await (const event of records) {
|
|
43
|
+
if (++scanned > 500000) throw new Error('Session exceeds the call inspection limit')
|
|
44
|
+
const data = event.data ?? {}
|
|
45
|
+
if (event.seq === seq && atMs !== undefined && event.time !== atMs) return empty(offset)
|
|
46
|
+
if (['tool/call', 'tool/result'].includes(event.type) && ((validSeq(data.turn) && data.turn !== activeTurn) || (validSeq(data.step) && data.step !== activeStep))) continue
|
|
47
|
+
if (event.type === 'turn/start') {
|
|
48
|
+
if (result.found) break
|
|
49
|
+
result = empty(offset); activeTurn = data.turn; activeStep = null; results = ''; resultsTruncated = false; inputIds = new Set(); resetStep()
|
|
50
|
+
}
|
|
51
|
+
const isAssistant = ['assistant/message', 'assistant/attempt', 'assistant/chunk'].includes(event.type)
|
|
52
|
+
if (event.type === 'step/start' || isAssistant) {
|
|
53
|
+
const turn = validSeq(data.turn) ? data.turn : activeTurn, step = validSeq(data.step) ? data.step : activeStep
|
|
54
|
+
if (turn !== activeTurn || step !== activeStep) {
|
|
55
|
+
if (result.found) break
|
|
56
|
+
if (turn !== activeTurn) { result = empty(offset); results = ''; resultsTruncated = false; inputIds = new Set() }
|
|
57
|
+
resetStep(); activeTurn = turn; activeStep = step
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (event.type === 'user/message' && !result.found && (!event.surfaceOp || event.surfaceOp === 'append')) {
|
|
61
|
+
const id = data.id ?? event.seq
|
|
62
|
+
if (!inputIds.has(id)) {
|
|
63
|
+
inputIds.add(id)
|
|
64
|
+
const source = data.source ?? data.message?.source
|
|
65
|
+
const kind = typeof source === 'string' ? source : source?.type ?? source?.kind ?? ''
|
|
66
|
+
const key = !kind || ['user', 'human', 'input'].includes(kind) ? 'input' : kind.includes('skill') ? 'skills' : 'injected'
|
|
67
|
+
append(key, (result[key] ? '\n\n' : '') + blocks(data.content ?? data.message?.content))
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (event.type === 'compaction/summary' && event.seq === seq && data.usage != null) {
|
|
71
|
+
result = empty(offset); result.found = true; result.kind = 'compaction'
|
|
72
|
+
append('output', blocks(data.rawOutput ?? data.summary ?? data.message?.content))
|
|
73
|
+
append('reasoning', blocks(data.rawOutput ?? data.message?.content, true)); break
|
|
74
|
+
}
|
|
75
|
+
if (isAssistant) {
|
|
76
|
+
if (event.type === 'assistant/chunk') {
|
|
77
|
+
const chunk = data.chunk ?? {}
|
|
78
|
+
if (chunk.type === 'text-delta') append('output', String(chunk.text ?? chunk.delta ?? ''))
|
|
79
|
+
if (chunk.type === 'reasoning-delta') append('reasoning', String(chunk.text ?? chunk.delta ?? ''))
|
|
80
|
+
} else if (data.message?.content != null) {
|
|
81
|
+
result.output = ''; result.reasoning = ''
|
|
82
|
+
append('output', blocks(data.message.content)); append('reasoning', blocks(data.message.content, true))
|
|
83
|
+
for (const block of Array.isArray(data.message.content) ? data.message.content : []) if (block.type === 'tool-call') addTool(block, event)
|
|
84
|
+
}
|
|
85
|
+
if (event.seq === seq && (data.usage != null || data.chunk?.type === 'usage')) result.found = true
|
|
86
|
+
}
|
|
87
|
+
if (event.type === 'tool/call') addTool(data, event)
|
|
88
|
+
if (event.type === 'tool/result') {
|
|
89
|
+
const message = data.message ?? {}, id = message.source?.callId ?? message.toolCallId ?? data.callId
|
|
90
|
+
if (seenTools.has(id)) {
|
|
91
|
+
const value = clip(blocks(message.content)), row = selected.get(id)
|
|
92
|
+
const combined = clip(results + (results ? '\n\n' : '') + String(id) + '\n' + value.text)
|
|
93
|
+
results = combined.text; resultsTruncated ||= value.truncated || combined.truncated
|
|
94
|
+
if (row) {
|
|
95
|
+
row.result = value.text; row.truncated ||= value.truncated; row.status = message.isError ? 'error' : 'complete'
|
|
96
|
+
if (row.atMs > 0 && Number.isFinite(event.time) && event.time >= row.atMs) row.durationMs = event.time - row.atMs
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (result.found && (event.type === 'step/end' || event.type === 'turn/end')) break
|
|
101
|
+
}
|
|
102
|
+
return result.found ? result : empty(offset)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export async function getCallInspection(ctx, query) {
|
|
106
|
+
if (!query || typeof query.sessionId !== 'string' || !query.sessionId || query.sessionId.length > 512 || !validSeq(query.seq) || !Number.isFinite(query.atMs) || query.atMs <= 0
|
|
107
|
+
|| !validSeq(query.offset ?? 0) || (query.offset ?? 0) > 1e7) throw new Error('invalid call inspection query')
|
|
108
|
+
const live = ctx?.get?.('sessions')?.get?.(query.sessionId)?.snapshotEvents?.()
|
|
109
|
+
if (Array.isArray(live)) return inspectCall(live, query.seq, query.offset ?? 0, query.atMs)
|
|
110
|
+
const paths = listSessionLogs(join(resolveDshHome(), 'sessions'), new Set([query.sessionId]))
|
|
111
|
+
return inspectCall(paths.length ? iterateSessionRecords(paths[0]) : [], query.seq, query.offset ?? 0, query.atMs)
|
|
112
|
+
}
|