opencode-top 3.1.2 → 3.2.1
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/bin/octop.js +2 -9
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +22432 -0
- package/dist/cli.js.map +1 -0
- package/dist/cli.mjs +22572 -0
- package/dist/core/agents.d.ts +11 -0
- package/dist/core/agents.d.ts.map +1 -0
- package/dist/core/agents.js +58 -0
- package/dist/core/agents.js.map +1 -0
- package/dist/core/session.d.ts +19 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/session.js +261 -0
- package/dist/core/session.js.map +1 -0
- package/dist/core/types.d.ts +140 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +29 -0
- package/dist/core/types.js.map +1 -0
- package/dist/data/pricing.d.ts +4 -0
- package/dist/data/pricing.d.ts.map +1 -0
- package/dist/data/pricing.js +76 -0
- package/dist/data/pricing.js.map +1 -0
- package/dist/data/sqlite.d.ts +5 -0
- package/dist/data/sqlite.d.ts.map +1 -0
- package/dist/data/sqlite.js +222 -0
- package/dist/data/sqlite.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/{src/index.ts → dist/index.js} +1 -0
- package/dist/index.js.map +1 -0
- package/dist/ui/App.d.ts +6 -0
- package/dist/ui/App.d.ts.map +1 -0
- package/dist/ui/App.js +101 -0
- package/dist/ui/App.js.map +1 -0
- package/dist/ui/components/AgentChainGraph.d.ts +9 -0
- package/dist/ui/components/AgentChainGraph.d.ts.map +1 -0
- package/dist/ui/components/AgentChainGraph.js +41 -0
- package/dist/ui/components/AgentChainGraph.js.map +1 -0
- package/dist/ui/components/AgentTree.d.ts +13 -0
- package/dist/ui/components/AgentTree.d.ts.map +1 -0
- package/dist/ui/components/AgentTree.js +50 -0
- package/dist/ui/components/AgentTree.js.map +1 -0
- package/dist/ui/components/DetailsPanel.d.ts +9 -0
- package/dist/ui/components/DetailsPanel.d.ts.map +1 -0
- package/dist/ui/components/DetailsPanel.js +82 -0
- package/dist/ui/components/DetailsPanel.js.map +1 -0
- package/dist/ui/components/MessagesPanel.d.ts +12 -0
- package/dist/ui/components/MessagesPanel.d.ts.map +1 -0
- package/dist/ui/components/MessagesPanel.js +107 -0
- package/dist/ui/components/MessagesPanel.js.map +1 -0
- package/dist/ui/components/SparkLine.d.ts +10 -0
- package/dist/ui/components/SparkLine.d.ts.map +1 -0
- package/dist/ui/components/SparkLine.js +12 -0
- package/dist/ui/components/SparkLine.js.map +1 -0
- package/dist/ui/components/StatusBar.d.ts +9 -0
- package/dist/ui/components/StatusBar.d.ts.map +1 -0
- package/dist/ui/components/StatusBar.js +9 -0
- package/dist/ui/components/StatusBar.js.map +1 -0
- package/dist/ui/components/TabBar.d.ts +10 -0
- package/dist/ui/components/TabBar.d.ts.map +1 -0
- package/dist/ui/components/TabBar.js +17 -0
- package/dist/ui/components/TabBar.js.map +1 -0
- package/dist/ui/screens/OverviewScreen.d.ts +12 -0
- package/dist/ui/screens/OverviewScreen.d.ts.map +1 -0
- package/dist/ui/screens/OverviewScreen.js +94 -0
- package/dist/ui/screens/OverviewScreen.js.map +1 -0
- package/dist/ui/screens/SessionsScreen.d.ts +12 -0
- package/dist/ui/screens/SessionsScreen.d.ts.map +1 -0
- package/dist/ui/screens/SessionsScreen.js +98 -0
- package/dist/ui/screens/SessionsScreen.js.map +1 -0
- package/dist/ui/screens/TimelineScreen.d.ts +11 -0
- package/dist/ui/screens/TimelineScreen.d.ts.map +1 -0
- package/dist/ui/screens/TimelineScreen.js +128 -0
- package/dist/ui/screens/TimelineScreen.js.map +1 -0
- package/dist/ui/screens/ToolsScreen.d.ts +12 -0
- package/dist/ui/screens/ToolsScreen.d.ts.map +1 -0
- package/dist/ui/screens/ToolsScreen.js +113 -0
- package/dist/ui/screens/ToolsScreen.js.map +1 -0
- package/dist/ui/theme.d.ts +21 -0
- package/dist/ui/theme.d.ts.map +1 -0
- package/dist/ui/theme.js +21 -0
- package/dist/ui/theme.js.map +1 -0
- package/package.json +3 -1
- package/patches/ink+5.2.1.patch +13 -0
- package/bin/octop.mjs +0 -13
- package/src/cli.ts +0 -60
- package/src/core/agents.ts +0 -78
- package/src/core/session.ts +0 -315
- package/src/core/types.ts +0 -156
- package/src/data/pricing.ts +0 -82
- package/src/data/sqlite.ts +0 -347
- package/src/ui/App.tsx +0 -154
- package/src/ui/components/AgentChainGraph.tsx +0 -95
- package/src/ui/components/AgentTree.tsx +0 -101
- package/src/ui/components/DetailsPanel.tsx +0 -211
- package/src/ui/components/MessagesPanel.tsx +0 -323
- package/src/ui/components/SparkLine.tsx +0 -18
- package/src/ui/components/StatusBar.tsx +0 -24
- package/src/ui/components/TabBar.tsx +0 -42
- package/src/ui/screens/OverviewScreen.tsx +0 -327
- package/src/ui/screens/SessionsScreen.tsx +0 -168
- package/src/ui/screens/TimelineScreen.tsx +0 -222
- package/src/ui/screens/ToolsScreen.tsx +0 -260
- package/src/ui/theme.ts +0 -21
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Session, Workflow } from "./types";
|
|
2
|
+
export declare class AgentRegistry {
|
|
3
|
+
private mainAgents;
|
|
4
|
+
private subAgents;
|
|
5
|
+
isMainAgent(agent: string | null): boolean;
|
|
6
|
+
isSubAgent(agent: string | null): boolean;
|
|
7
|
+
addMainAgent(agent: string): void;
|
|
8
|
+
addSubAgent(agent: string): void;
|
|
9
|
+
}
|
|
10
|
+
export declare function groupSessionsToWorkflows(sessions: Session[], _registry?: AgentRegistry): Workflow[];
|
|
11
|
+
//# sourceMappingURL=agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/core/agents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAa,MAAM,SAAS,CAAC;AAE5D,qBAAa,aAAa;IACxB,OAAO,CAAC,UAAU,CAA8B;IAChD,OAAO,CAAC,SAAS,CAAwB;IAEzC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAK1C,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAKzC,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIjC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAGjC;AA8BD,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,OAAO,EAAE,EACnB,SAAS,CAAC,EAAE,aAAa,GACxB,QAAQ,EAAE,CAqBZ"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export class AgentRegistry {
|
|
2
|
+
mainAgents = new Set(["plan", "build"]);
|
|
3
|
+
subAgents = new Set(["explore"]);
|
|
4
|
+
isMainAgent(agent) {
|
|
5
|
+
if (!agent)
|
|
6
|
+
return true;
|
|
7
|
+
return this.mainAgents.has(agent);
|
|
8
|
+
}
|
|
9
|
+
isSubAgent(agent) {
|
|
10
|
+
if (!agent)
|
|
11
|
+
return false;
|
|
12
|
+
return this.subAgents.has(agent);
|
|
13
|
+
}
|
|
14
|
+
addMainAgent(agent) {
|
|
15
|
+
this.mainAgents.add(agent);
|
|
16
|
+
}
|
|
17
|
+
addSubAgent(agent) {
|
|
18
|
+
this.subAgents.add(agent);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function buildAgentNode(session, sessionMap, depth) {
|
|
22
|
+
// Find all direct children of this session
|
|
23
|
+
const children = [];
|
|
24
|
+
for (const [, s] of sessionMap) {
|
|
25
|
+
if (s.parentId === session.id) {
|
|
26
|
+
children.push(buildAgentNode(s, sessionMap, depth + 1));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// Sort children by timeCreated
|
|
30
|
+
children.sort((a, b) => (a.session.timeCreated ?? 0) - (b.session.timeCreated ?? 0));
|
|
31
|
+
return { session, children, depth };
|
|
32
|
+
}
|
|
33
|
+
function collectAllDescendants(node) {
|
|
34
|
+
const result = [];
|
|
35
|
+
for (const child of node.children) {
|
|
36
|
+
result.push(child.session);
|
|
37
|
+
result.push(...collectAllDescendants(child));
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
export function groupSessionsToWorkflows(sessions, _registry) {
|
|
42
|
+
const sessionMap = new Map(sessions.map((s) => [s.id, s]));
|
|
43
|
+
// Find root sessions (no parentId)
|
|
44
|
+
const roots = sessions.filter((s) => s.parentId === null);
|
|
45
|
+
const workflows = [];
|
|
46
|
+
for (const root of roots) {
|
|
47
|
+
const agentTree = buildAgentNode(root, sessionMap, 0);
|
|
48
|
+
const subAgentSessions = collectAllDescendants(agentTree);
|
|
49
|
+
workflows.push({
|
|
50
|
+
id: root.id,
|
|
51
|
+
mainSession: root,
|
|
52
|
+
subAgentSessions,
|
|
53
|
+
agentTree,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return workflows;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=agents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../../src/core/agents.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,aAAa;IAChB,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACxC,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAEzC,WAAW,CAAC,KAAoB;QAC9B,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QACxB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,UAAU,CAAC,KAAoB;QAC7B,IAAI,CAAC,KAAK;YAAE,OAAO,KAAK,CAAC;QACzB,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,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AAU,GAAG,IAAI,GAAG,CAAkB,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAE5E,mCAAmC;IACnC,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC;IAE1D,MAAM,SAAS,GAAe,EAAE,CAAC;IAEjC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,SAAS,GAAG,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;QACtD,MAAM,gBAAgB,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;QAE1D,SAAS,CAAC,IAAI,CAAC;YACb,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,WAAW,EAAE,IAAI;YACjB,gBAAgB;YAChB,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TokenUsage } from "./types";
|
|
2
|
+
import type { Session, Workflow, ToolUsage, ModelPricing, OverviewStats } from "./types";
|
|
3
|
+
import type { MessagePart } from "./types";
|
|
4
|
+
export declare function getSessionTokens(session: Session): TokenUsage;
|
|
5
|
+
export declare function getSessionCost(session: Session, pricing: Map<string, ModelPricing>): Decimal;
|
|
6
|
+
export declare function getSessionCostSingle(session: Session, pricing: ModelPricing): Decimal;
|
|
7
|
+
export declare function getSessionDuration(session: Session): number;
|
|
8
|
+
export declare function getWorkflowTokens(workflow: Workflow): TokenUsage;
|
|
9
|
+
export declare function getWorkflowCost(workflow: Workflow, pricing: Map<string, ModelPricing>): Decimal;
|
|
10
|
+
export declare function getWorkflowCostSingle(workflow: Workflow, pricing: ModelPricing): Decimal;
|
|
11
|
+
export declare function getToolUsage(session: Session): ToolUsage[];
|
|
12
|
+
export declare function getWorkflowToolUsage(workflow: Workflow): ToolUsage[];
|
|
13
|
+
export declare function getOutputRate(session: Session): number;
|
|
14
|
+
export declare function computeOverviewStats(workflows: Workflow[], pricing: Map<string, ModelPricing>): OverviewStats;
|
|
15
|
+
/** Build spark series (8 levels) from numeric array */
|
|
16
|
+
export declare function buildSparkSeries(values: number[]): string;
|
|
17
|
+
/** All parts across all interactions in a session */
|
|
18
|
+
export declare function getAllParts(session: Session): MessagePart[];
|
|
19
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/core/session.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAE7D;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,OAAO,CAM5F;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAIrF;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAa3D;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,UAAU,CAOhE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,OAAO,CAO/F;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAOxF;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,EAAE,CA6C1D;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAAE,CAqCpE;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAUtD;AAED,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,QAAQ,EAAE,EACrB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,GACjC,aAAa,CAiIf;AAED,uDAAuD;AACvD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAWzD;AAED,qDAAqD;AACrD,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,EAAE,CAE3D"}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
2
|
+
import { TokenUsage } from "./types";
|
|
3
|
+
export function getSessionTokens(session) {
|
|
4
|
+
return session.interactions.reduce((acc, i) => acc.add(i.tokens), new TokenUsage());
|
|
5
|
+
}
|
|
6
|
+
export function getSessionCost(session, pricing) {
|
|
7
|
+
return session.interactions.reduce((acc, i) => {
|
|
8
|
+
const p = pricing.get(i.modelId);
|
|
9
|
+
if (!p)
|
|
10
|
+
return acc;
|
|
11
|
+
return acc.plus(i.tokens.calculateCost(p));
|
|
12
|
+
}, new Decimal(0));
|
|
13
|
+
}
|
|
14
|
+
export function getSessionCostSingle(session, pricing) {
|
|
15
|
+
return session.interactions.reduce((acc, i) => {
|
|
16
|
+
return acc.plus(i.tokens.calculateCost(pricing));
|
|
17
|
+
}, new Decimal(0));
|
|
18
|
+
}
|
|
19
|
+
export function getSessionDuration(session) {
|
|
20
|
+
const interactions = session.interactions;
|
|
21
|
+
if (interactions.length === 0)
|
|
22
|
+
return 0;
|
|
23
|
+
// Use real time.completed when available
|
|
24
|
+
const times = [];
|
|
25
|
+
for (const i of interactions) {
|
|
26
|
+
if (i.time.created !== null)
|
|
27
|
+
times.push(i.time.created);
|
|
28
|
+
if (i.time.completed !== null)
|
|
29
|
+
times.push(i.time.completed);
|
|
30
|
+
}
|
|
31
|
+
if (times.length === 0)
|
|
32
|
+
return 0;
|
|
33
|
+
return Math.max(...times) - Math.min(...times);
|
|
34
|
+
}
|
|
35
|
+
export function getWorkflowTokens(workflow) {
|
|
36
|
+
const main = getSessionTokens(workflow.mainSession);
|
|
37
|
+
const subs = workflow.subAgentSessions.reduce((acc, s) => acc.add(getSessionTokens(s)), new TokenUsage());
|
|
38
|
+
return main.add(subs);
|
|
39
|
+
}
|
|
40
|
+
export function getWorkflowCost(workflow, pricing) {
|
|
41
|
+
const main = getSessionCost(workflow.mainSession, pricing);
|
|
42
|
+
const subs = workflow.subAgentSessions.reduce((acc, s) => acc.plus(getSessionCost(s, pricing)), new Decimal(0));
|
|
43
|
+
return main.plus(subs);
|
|
44
|
+
}
|
|
45
|
+
export function getWorkflowCostSingle(workflow, pricing) {
|
|
46
|
+
const main = getSessionCostSingle(workflow.mainSession, pricing);
|
|
47
|
+
const subs = workflow.subAgentSessions.reduce((acc, s) => acc.plus(getSessionCostSingle(s, pricing)), new Decimal(0));
|
|
48
|
+
return main.plus(subs);
|
|
49
|
+
}
|
|
50
|
+
export function getToolUsage(session) {
|
|
51
|
+
const tools = new Map();
|
|
52
|
+
for (const interaction of session.interactions) {
|
|
53
|
+
for (const part of interaction.parts) {
|
|
54
|
+
if (part.type !== "tool")
|
|
55
|
+
continue;
|
|
56
|
+
const existing = tools.get(part.toolName) ?? {
|
|
57
|
+
calls: 0,
|
|
58
|
+
successes: 0,
|
|
59
|
+
failures: 0,
|
|
60
|
+
totalDurationMs: 0,
|
|
61
|
+
recentErrors: [],
|
|
62
|
+
};
|
|
63
|
+
existing.calls++;
|
|
64
|
+
if (part.status === "completed") {
|
|
65
|
+
existing.successes++;
|
|
66
|
+
}
|
|
67
|
+
else if (part.status === "error") {
|
|
68
|
+
existing.failures++;
|
|
69
|
+
// Keep last 3 errors
|
|
70
|
+
if (existing.recentErrors.length < 3) {
|
|
71
|
+
existing.recentErrors.push(part.output?.slice(0, 200) ?? "unknown error");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const durationMs = part.timeEnd > 0 && part.timeStart > 0 ? part.timeEnd - part.timeStart : 0;
|
|
75
|
+
existing.totalDurationMs += durationMs;
|
|
76
|
+
tools.set(part.toolName, existing);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return Array.from(tools.entries()).map(([name, stats]) => ({
|
|
80
|
+
name,
|
|
81
|
+
calls: stats.calls,
|
|
82
|
+
successes: stats.successes,
|
|
83
|
+
failures: stats.failures,
|
|
84
|
+
totalDurationMs: stats.totalDurationMs,
|
|
85
|
+
avgDurationMs: stats.calls > 0 ? stats.totalDurationMs / stats.calls : 0,
|
|
86
|
+
recentErrors: stats.recentErrors,
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
export function getWorkflowToolUsage(workflow) {
|
|
90
|
+
const allSessions = [workflow.mainSession, ...workflow.subAgentSessions];
|
|
91
|
+
const merged = new Map();
|
|
92
|
+
for (const session of allSessions) {
|
|
93
|
+
const usage = getToolUsage(session);
|
|
94
|
+
for (const tool of usage) {
|
|
95
|
+
const existing = merged.get(tool.name) ?? {
|
|
96
|
+
calls: 0,
|
|
97
|
+
successes: 0,
|
|
98
|
+
failures: 0,
|
|
99
|
+
totalDurationMs: 0,
|
|
100
|
+
recentErrors: [],
|
|
101
|
+
};
|
|
102
|
+
existing.calls += tool.calls;
|
|
103
|
+
existing.successes += tool.successes;
|
|
104
|
+
existing.failures += tool.failures;
|
|
105
|
+
existing.totalDurationMs += tool.totalDurationMs;
|
|
106
|
+
for (const err of tool.recentErrors) {
|
|
107
|
+
if (existing.recentErrors.length < 3)
|
|
108
|
+
existing.recentErrors.push(err);
|
|
109
|
+
}
|
|
110
|
+
merged.set(tool.name, existing);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return Array.from(merged.entries()).map(([name, stats]) => ({
|
|
114
|
+
name,
|
|
115
|
+
calls: stats.calls,
|
|
116
|
+
successes: stats.successes,
|
|
117
|
+
failures: stats.failures,
|
|
118
|
+
totalDurationMs: stats.totalDurationMs,
|
|
119
|
+
avgDurationMs: stats.calls > 0 ? stats.totalDurationMs / stats.calls : 0,
|
|
120
|
+
recentErrors: stats.recentErrors,
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
export function getOutputRate(session) {
|
|
124
|
+
const rates = session.interactions
|
|
125
|
+
.map((i) => i.outputRate)
|
|
126
|
+
.filter((r) => r > 0)
|
|
127
|
+
.sort((a, b) => a - b);
|
|
128
|
+
if (rates.length === 0)
|
|
129
|
+
return 0;
|
|
130
|
+
const mid = Math.floor(rates.length / 2);
|
|
131
|
+
return rates.length % 2 !== 0 ? rates[mid] : (rates[mid - 1] + rates[mid]) / 2;
|
|
132
|
+
}
|
|
133
|
+
export function computeOverviewStats(workflows, pricing) {
|
|
134
|
+
const totalTokens = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reasoning: 0 };
|
|
135
|
+
let totalCost = new Decimal(0);
|
|
136
|
+
const modelBreakdown = new Map();
|
|
137
|
+
const projectBreakdown = new Map();
|
|
138
|
+
const agentBreakdown = new Map();
|
|
139
|
+
const agentToolErrors = new Map();
|
|
140
|
+
const toolCallCounts = new Map();
|
|
141
|
+
const weeklyTokenMap = new Map();
|
|
142
|
+
const weeklySessionMap = new Map();
|
|
143
|
+
const hourlyActivity = new Array(24).fill(0);
|
|
144
|
+
const now = Date.now();
|
|
145
|
+
const sevenDaysAgo = now - 7 * 86_400_000;
|
|
146
|
+
for (const workflow of workflows) {
|
|
147
|
+
const allSessions = [workflow.mainSession, ...workflow.subAgentSessions];
|
|
148
|
+
for (const session of allSessions) {
|
|
149
|
+
const projName = session.projectName ?? "Unknown";
|
|
150
|
+
const projEntry = projectBreakdown.get(projName) ?? { cost: new Decimal(0), sessions: 0 };
|
|
151
|
+
projEntry.sessions++;
|
|
152
|
+
// Weekly session count
|
|
153
|
+
const sessionTs = session.timeCreated;
|
|
154
|
+
if (sessionTs && sessionTs >= sevenDaysAgo) {
|
|
155
|
+
const day = new Date(sessionTs).toISOString().slice(5, 10); // MM-DD
|
|
156
|
+
weeklySessionMap.set(day, (weeklySessionMap.get(day) ?? 0) + 1);
|
|
157
|
+
}
|
|
158
|
+
for (const interaction of session.interactions) {
|
|
159
|
+
const p = pricing.get(interaction.modelId);
|
|
160
|
+
const cost = p ? interaction.tokens.calculateCost(p) : new Decimal(0);
|
|
161
|
+
totalCost = totalCost.plus(cost);
|
|
162
|
+
projEntry.cost = projEntry.cost.plus(cost);
|
|
163
|
+
totalTokens.input += interaction.tokens.input;
|
|
164
|
+
totalTokens.output += interaction.tokens.output;
|
|
165
|
+
totalTokens.cacheRead += interaction.tokens.cacheRead;
|
|
166
|
+
totalTokens.cacheWrite += interaction.tokens.cacheWrite;
|
|
167
|
+
totalTokens.reasoning += interaction.tokens.reasoning;
|
|
168
|
+
// Model breakdown
|
|
169
|
+
const modelEntry = modelBreakdown.get(interaction.modelId) ?? {
|
|
170
|
+
cost: new Decimal(0),
|
|
171
|
+
tokens: 0,
|
|
172
|
+
calls: 0,
|
|
173
|
+
};
|
|
174
|
+
modelEntry.cost = modelEntry.cost.plus(cost);
|
|
175
|
+
modelEntry.tokens += interaction.tokens.total;
|
|
176
|
+
modelEntry.calls++;
|
|
177
|
+
modelBreakdown.set(interaction.modelId, modelEntry);
|
|
178
|
+
// Agent breakdown
|
|
179
|
+
const agentKey = interaction.agent ?? "main";
|
|
180
|
+
const agentEntry = agentBreakdown.get(agentKey) ?? { cost: new Decimal(0), calls: 0 };
|
|
181
|
+
agentEntry.cost = agentEntry.cost.plus(cost);
|
|
182
|
+
agentEntry.calls++;
|
|
183
|
+
agentBreakdown.set(agentKey, agentEntry);
|
|
184
|
+
// Hourly activity
|
|
185
|
+
const ts = interaction.time.created;
|
|
186
|
+
if (ts) {
|
|
187
|
+
hourlyActivity[new Date(ts).getHours()]++;
|
|
188
|
+
// Weekly token trend
|
|
189
|
+
if (ts >= sevenDaysAgo) {
|
|
190
|
+
const day = new Date(ts).toISOString().slice(5, 10);
|
|
191
|
+
weeklyTokenMap.set(day, (weeklyTokenMap.get(day) ?? 0) + interaction.tokens.total);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Tool stats: per-tool call counts and agent tool errors
|
|
195
|
+
for (const part of interaction.parts) {
|
|
196
|
+
if (part.type !== "tool")
|
|
197
|
+
continue;
|
|
198
|
+
const isError = part.status === "error";
|
|
199
|
+
const dur = part.timeEnd > 0 && part.timeStart > 0 ? part.timeEnd - part.timeStart : 0;
|
|
200
|
+
// Tool call counts
|
|
201
|
+
const toolEntry = toolCallCounts.get(part.toolName) ?? { calls: 0, errors: 0, totalDurationMs: 0 };
|
|
202
|
+
toolEntry.calls++;
|
|
203
|
+
if (isError)
|
|
204
|
+
toolEntry.errors++;
|
|
205
|
+
toolEntry.totalDurationMs += dur;
|
|
206
|
+
toolCallCounts.set(part.toolName, toolEntry);
|
|
207
|
+
// Agent tool errors
|
|
208
|
+
const agentToolEntry = agentToolErrors.get(agentKey) ?? { calls: 0, errors: 0 };
|
|
209
|
+
agentToolEntry.calls++;
|
|
210
|
+
if (isError)
|
|
211
|
+
agentToolEntry.errors++;
|
|
212
|
+
agentToolErrors.set(agentKey, agentToolEntry);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
projectBreakdown.set(projName, projEntry);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// Build 7-day arrays (last 7 days, MM-DD labels)
|
|
219
|
+
const today = new Date();
|
|
220
|
+
const weeklyTokens = [];
|
|
221
|
+
const weeklySessions = [];
|
|
222
|
+
for (let i = 6; i >= 0; i--) {
|
|
223
|
+
const d = new Date(today);
|
|
224
|
+
d.setDate(d.getDate() - i);
|
|
225
|
+
const day = d.toISOString().slice(5, 10);
|
|
226
|
+
weeklyTokens.push({ date: day, tokens: weeklyTokenMap.get(day) ?? 0 });
|
|
227
|
+
weeklySessions.push({ date: day, sessions: weeklySessionMap.get(day) ?? 0 });
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
totalCost,
|
|
231
|
+
totalTokens: new TokenUsage(totalTokens.input, totalTokens.output, totalTokens.cacheRead, totalTokens.cacheWrite, totalTokens.reasoning),
|
|
232
|
+
modelBreakdown,
|
|
233
|
+
projectBreakdown,
|
|
234
|
+
agentBreakdown,
|
|
235
|
+
agentToolErrors,
|
|
236
|
+
toolCallCounts,
|
|
237
|
+
weeklyTokens,
|
|
238
|
+
weeklySessions,
|
|
239
|
+
hourlyActivity,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/** Build spark series (8 levels) from numeric array */
|
|
243
|
+
export function buildSparkSeries(values) {
|
|
244
|
+
if (values.length === 0)
|
|
245
|
+
return "";
|
|
246
|
+
const max = Math.max(...values);
|
|
247
|
+
if (max === 0)
|
|
248
|
+
return "▁".repeat(values.length);
|
|
249
|
+
const chars = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"];
|
|
250
|
+
return values
|
|
251
|
+
.map((v) => {
|
|
252
|
+
const idx = Math.min(7, Math.floor((v / max) * 8));
|
|
253
|
+
return chars[idx];
|
|
254
|
+
})
|
|
255
|
+
.join("");
|
|
256
|
+
}
|
|
257
|
+
/** All parts across all interactions in a session */
|
|
258
|
+
export function getAllParts(session) {
|
|
259
|
+
return session.interactions.flatMap((i) => i.parts);
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/core/session.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAIrC,MAAM,UAAU,gB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,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACnD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC,CAAC;SACD,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,OAAO,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
2
|
+
export declare class TokenUsage {
|
|
3
|
+
readonly input: number;
|
|
4
|
+
readonly output: number;
|
|
5
|
+
readonly cacheRead: number;
|
|
6
|
+
readonly cacheWrite: number;
|
|
7
|
+
readonly reasoning: number;
|
|
8
|
+
constructor(input?: number, output?: number, cacheRead?: number, cacheWrite?: number, reasoning?: number);
|
|
9
|
+
get total(): number;
|
|
10
|
+
add(other: TokenUsage): TokenUsage;
|
|
11
|
+
calculateCost(pricing: ModelPricing): Decimal;
|
|
12
|
+
}
|
|
13
|
+
export interface TimeData {
|
|
14
|
+
created: number | null;
|
|
15
|
+
completed: number | null;
|
|
16
|
+
}
|
|
17
|
+
export type MessagePart = {
|
|
18
|
+
type: "text";
|
|
19
|
+
text: string;
|
|
20
|
+
timeStart: number;
|
|
21
|
+
timeEnd: number;
|
|
22
|
+
} | {
|
|
23
|
+
type: "tool";
|
|
24
|
+
callId: string;
|
|
25
|
+
toolName: string;
|
|
26
|
+
status: "completed" | "pending" | "error";
|
|
27
|
+
input: Record<string, unknown>;
|
|
28
|
+
output: string;
|
|
29
|
+
title: string | null;
|
|
30
|
+
exitCode: number | null;
|
|
31
|
+
truncated: boolean;
|
|
32
|
+
timeStart: number;
|
|
33
|
+
timeEnd: number;
|
|
34
|
+
} | {
|
|
35
|
+
type: "reasoning";
|
|
36
|
+
text: string;
|
|
37
|
+
timeStart: number;
|
|
38
|
+
timeEnd: number;
|
|
39
|
+
} | {
|
|
40
|
+
type: "patch";
|
|
41
|
+
hash: string;
|
|
42
|
+
files: string[];
|
|
43
|
+
};
|
|
44
|
+
export interface Interaction {
|
|
45
|
+
id: string;
|
|
46
|
+
sessionId: string;
|
|
47
|
+
modelId: string;
|
|
48
|
+
providerId: string | null;
|
|
49
|
+
role: "assistant" | "user";
|
|
50
|
+
tokens: TokenUsage;
|
|
51
|
+
time: TimeData;
|
|
52
|
+
agent: string | null;
|
|
53
|
+
finishReason: string | null;
|
|
54
|
+
outputRate: number;
|
|
55
|
+
parts: MessagePart[];
|
|
56
|
+
}
|
|
57
|
+
export interface Session {
|
|
58
|
+
id: string;
|
|
59
|
+
parentId: string | null;
|
|
60
|
+
projectId: string | null;
|
|
61
|
+
projectName: string | null;
|
|
62
|
+
title: string | null;
|
|
63
|
+
timeCreated: number | null;
|
|
64
|
+
timeArchived: number | null;
|
|
65
|
+
interactions: Interaction[];
|
|
66
|
+
source: "sqlite" | "files";
|
|
67
|
+
}
|
|
68
|
+
export interface AgentNode {
|
|
69
|
+
session: Session;
|
|
70
|
+
children: AgentNode[];
|
|
71
|
+
depth: number;
|
|
72
|
+
}
|
|
73
|
+
export interface FlatNode {
|
|
74
|
+
id: string;
|
|
75
|
+
session: Session;
|
|
76
|
+
workflowIndex: number;
|
|
77
|
+
depth: number;
|
|
78
|
+
hasChildren: boolean;
|
|
79
|
+
agentNode: AgentNode;
|
|
80
|
+
}
|
|
81
|
+
export interface Workflow {
|
|
82
|
+
id: string;
|
|
83
|
+
mainSession: Session;
|
|
84
|
+
subAgentSessions: Session[];
|
|
85
|
+
agentTree: AgentNode;
|
|
86
|
+
}
|
|
87
|
+
export interface ModelPricing {
|
|
88
|
+
input: Decimal;
|
|
89
|
+
output: Decimal;
|
|
90
|
+
cacheRead: Decimal;
|
|
91
|
+
cacheWrite: Decimal;
|
|
92
|
+
contextWindow: number;
|
|
93
|
+
}
|
|
94
|
+
export interface ToolUsage {
|
|
95
|
+
name: string;
|
|
96
|
+
calls: number;
|
|
97
|
+
successes: number;
|
|
98
|
+
failures: number;
|
|
99
|
+
totalDurationMs: number;
|
|
100
|
+
avgDurationMs: number;
|
|
101
|
+
recentErrors: string[];
|
|
102
|
+
}
|
|
103
|
+
export interface OverviewStats {
|
|
104
|
+
totalCost: Decimal;
|
|
105
|
+
totalTokens: TokenUsage;
|
|
106
|
+
modelBreakdown: Map<string, {
|
|
107
|
+
cost: Decimal;
|
|
108
|
+
tokens: number;
|
|
109
|
+
calls: number;
|
|
110
|
+
}>;
|
|
111
|
+
projectBreakdown: Map<string, {
|
|
112
|
+
cost: Decimal;
|
|
113
|
+
sessions: number;
|
|
114
|
+
}>;
|
|
115
|
+
agentBreakdown: Map<string, {
|
|
116
|
+
cost: Decimal;
|
|
117
|
+
calls: number;
|
|
118
|
+
}>;
|
|
119
|
+
agentToolErrors: Map<string, {
|
|
120
|
+
calls: number;
|
|
121
|
+
errors: number;
|
|
122
|
+
}>;
|
|
123
|
+
toolCallCounts: Map<string, {
|
|
124
|
+
calls: number;
|
|
125
|
+
errors: number;
|
|
126
|
+
totalDurationMs: number;
|
|
127
|
+
}>;
|
|
128
|
+
weeklyTokens: {
|
|
129
|
+
date: string;
|
|
130
|
+
tokens: number;
|
|
131
|
+
}[];
|
|
132
|
+
weeklySessions: {
|
|
133
|
+
date: string;
|
|
134
|
+
sessions: number;
|
|
135
|
+
}[];
|
|
136
|
+
hourlyActivity: number[];
|
|
137
|
+
}
|
|
138
|
+
export type ScreenId = "sessions" | "tools" | "overview";
|
|
139
|
+
export type { Decimal };
|
|
140
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,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;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChE,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAExF,YAAY,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACjD,cAAc,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAErD,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC;AAEzD,YAAY,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
2
|
+
export class TokenUsage {
|
|
3
|
+
input;
|
|
4
|
+
output;
|
|
5
|
+
cacheRead;
|
|
6
|
+
cacheWrite;
|
|
7
|
+
reasoning;
|
|
8
|
+
constructor(input = 0, output = 0, cacheRead = 0, cacheWrite = 0, reasoning = 0) {
|
|
9
|
+
this.input = input;
|
|
10
|
+
this.output = output;
|
|
11
|
+
this.cacheRead = cacheRead;
|
|
12
|
+
this.cacheWrite = cacheWrite;
|
|
13
|
+
this.reasoning = reasoning;
|
|
14
|
+
}
|
|
15
|
+
get total() {
|
|
16
|
+
return this.input + this.output + this.cacheRead + this.cacheWrite;
|
|
17
|
+
}
|
|
18
|
+
add(other) {
|
|
19
|
+
return new TokenUsage(this.input + other.input, this.output + other.output, this.cacheRead + other.cacheRead, this.cacheWrite + other.cacheWrite, this.reasoning + other.reasoning);
|
|
20
|
+
}
|
|
21
|
+
calculateCost(pricing) {
|
|
22
|
+
const inputCost = new Decimal(this.input).mul(pricing.input).div(1_000_000);
|
|
23
|
+
const outputCost = new Decimal(this.output).mul(pricing.output).div(1_000_000);
|
|
24
|
+
const cacheReadCost = new Decimal(this.cacheRead).mul(pricing.cacheRead).div(1_000_000);
|
|
25
|
+
const cacheWriteCost = new Decimal(this.cacheWrite).mul(pricing.cacheWrite).div(1_000_000);
|
|
26
|
+
return inputCost.plus(outputCost).plus(cacheReadCost).plus(cacheWriteCost);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,MAAM,OAAO,UAAU;IAEV;IACA;IACA;IACA;IACA;IALX,YACW,QAAgB,CAAC,EACjB,SAAiB,CAAC,EAClB,YAAoB,CAAC,EACrB,aAAqB,CAAC,EACtB,YAAoB,CAAC;QAJrB,UAAK,GAAL,KAAK,CAAY;QACjB,WAAM,GAAN,MAAM,CAAY;QAClB,cAAS,GAAT,SAAS,CAAY;QACrB,eAAU,GAAV,UAAU,CAAY;QACtB,cAAS,GAAT,SAAS,CAAY;IAC7B,CAAC;IAEJ,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC;IACrE,CAAC;IAED,GAAG,CAAC,KAAiB;QACnB,OAAO,IAAI,UAAU,CACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,EACxB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,EAC1B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,EAChC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,EAClC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CACjC,CAAC;IACJ,CAAC;IAED,aAAa,CAAC,OAAqB;QACjC,MAAM,SAAS,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC5E,MAAM,UAAU,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC/E,MAAM,aAAa,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACxF,MAAM,cAAc,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC3F,OAAO,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC7E,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../../src/data/pricing.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AA8DlD,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAUxD;AAED,wBAAgB,aAAa,IAAI,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAMzD"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
2
|
+
const DEFAULT_PRICING = {
|
|
3
|
+
input: new Decimal(0),
|
|
4
|
+
output: new Decimal(0),
|
|
5
|
+
cacheRead: new Decimal(0),
|
|
6
|
+
cacheWrite: new Decimal(0),
|
|
7
|
+
contextWindow: 128000,
|
|
8
|
+
};
|
|
9
|
+
const KNOWN_PRICING = {
|
|
10
|
+
"claude-sonnet-4-20250514": {
|
|
11
|
+
input: new Decimal(3),
|
|
12
|
+
output: new Decimal(15),
|
|
13
|
+
cacheRead: new Decimal(0.3),
|
|
14
|
+
cacheWrite: new Decimal(3.75),
|
|
15
|
+
contextWindow: 200000,
|
|
16
|
+
},
|
|
17
|
+
"claude-3-5-sonnet-20241022": {
|
|
18
|
+
input: new Decimal(3),
|
|
19
|
+
output: new Decimal(15),
|
|
20
|
+
cacheRead: new Decimal(0.3),
|
|
21
|
+
cacheWrite: new Decimal(3.75),
|
|
22
|
+
contextWindow: 200000,
|
|
23
|
+
},
|
|
24
|
+
"claude-3-5-sonnet-20240620": {
|
|
25
|
+
input: new Decimal(3),
|
|
26
|
+
output: new Decimal(15),
|
|
27
|
+
cacheRead: new Decimal(0.3),
|
|
28
|
+
cacheWrite: new Decimal(3.75),
|
|
29
|
+
contextWindow: 200000,
|
|
30
|
+
},
|
|
31
|
+
"claude-3-5-haiku-20241022": {
|
|
32
|
+
input: new Decimal(1),
|
|
33
|
+
output: new Decimal(5),
|
|
34
|
+
cacheRead: new Decimal(0.1),
|
|
35
|
+
cacheWrite: new Decimal(1.25),
|
|
36
|
+
contextWindow: 200000,
|
|
37
|
+
},
|
|
38
|
+
"claude-3-haiku-20240307": {
|
|
39
|
+
input: new Decimal(0.25),
|
|
40
|
+
output: new Decimal(1.25),
|
|
41
|
+
cacheRead: new Decimal(0.03),
|
|
42
|
+
cacheWrite: new Decimal(0.3),
|
|
43
|
+
contextWindow: 200000,
|
|
44
|
+
},
|
|
45
|
+
"claude-3-opus-20240229": {
|
|
46
|
+
input: new Decimal(15),
|
|
47
|
+
output: new Decimal(75),
|
|
48
|
+
cacheRead: new Decimal(1.5),
|
|
49
|
+
cacheWrite: new Decimal(18.75),
|
|
50
|
+
contextWindow: 200000,
|
|
51
|
+
},
|
|
52
|
+
"claude-opus-4-20250514": {
|
|
53
|
+
input: new Decimal(15),
|
|
54
|
+
output: new Decimal(75),
|
|
55
|
+
cacheRead: new Decimal(1.5),
|
|
56
|
+
cacheWrite: new Decimal(18.75),
|
|
57
|
+
contextWindow: 200000,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
export function getPricing(modelId) {
|
|
61
|
+
const normalized = modelId.toLowerCase();
|
|
62
|
+
for (const [key, pricing] of Object.entries(KNOWN_PRICING)) {
|
|
63
|
+
if (normalized.includes(key.toLowerCase()) || key.toLowerCase().includes(normalized)) {
|
|
64
|
+
return { ...DEFAULT_PRICING, ...pricing };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return DEFAULT_PRICING;
|
|
68
|
+
}
|
|
69
|
+
export function getAllPricing() {
|
|
70
|
+
const result = new Map();
|
|
71
|
+
for (const [key, pricing] of Object.entries(KNOWN_PRICING)) {
|
|
72
|
+
result.set(key.toLowerCase(), { ...DEFAULT_PRICING, ...pricing });
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=pricing.js.map
|