@phren/agent 0.1.8 → 0.1.10
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/dist/commands/info.js +1 -0
- package/dist/commands/model.js +5 -4
- package/dist/commands/session.js +24 -2
- package/dist/commands.js +36 -1
- package/dist/config.js +27 -11
- package/dist/cost.js +11 -74
- package/dist/index.js +92 -35
- package/dist/mcp-client.js +4 -2
- package/dist/memory/context.js +56 -24
- package/dist/memory/session.js +21 -88
- package/dist/models.js +390 -0
- package/dist/multi/agent-types.js +170 -0
- package/dist/multi/child-entry.js +248 -78
- package/dist/multi/coordinator.js +69 -1
- package/dist/multi/diff-renderer.js +193 -17
- package/dist/multi/markdown.js +49 -23
- package/dist/multi/model-picker.js +12 -21
- package/dist/multi/multi-events.js +17 -0
- package/dist/multi/multi-render.js +1 -0
- package/dist/multi/provider-manager.js +23 -13
- package/dist/multi/spawner.js +84 -7
- package/dist/multi/syntax-highlight.js +64 -48
- package/dist/multi/worktree.js +43 -0
- package/dist/package-metadata.js +11 -0
- package/dist/permissions/checker.js +21 -1
- package/dist/providers/codex-auth.js +48 -34
- package/dist/providers/codex.js +110 -40
- package/dist/providers/ollama.js +5 -4
- package/dist/providers/openrouter.js +12 -5
- package/dist/providers/resolve.js +50 -32
- package/dist/providers/types.js +0 -1
- package/dist/repl.js +19 -34
- package/dist/tools/grep.js +111 -23
- package/dist/tools/mcp-resources.js +32 -0
- package/dist/tools/registry.js +13 -2
- package/dist/tools/shell.js +101 -3
- package/dist/tools/skill.js +44 -0
- package/dist/tools/spawn-agent.js +158 -0
- package/dist/tui/ansi.js +15 -11
- package/dist/tui/components/App.js +180 -20
- package/dist/tui/components/Banner.js +7 -4
- package/dist/tui/components/InputArea.js +54 -12
- package/dist/tui/components/PhrenInput.js +329 -0
- package/dist/tui/components/StatusBar.js +3 -1
- package/dist/tui/components/SteerQueue.js +4 -2
- package/dist/tui/components/ThinkingIndicator.js +12 -11
- package/dist/tui/components/ToolCall.js +17 -11
- package/dist/tui/components/ToolSpinner.js +13 -0
- package/dist/tui/hooks/useKeyboardShortcuts.js +65 -24
- package/dist/tui/hooks/useSearch.js +47 -0
- package/dist/tui/hooks/useSlashCommands.js +16 -19
- package/dist/tui/ink-entry.js +317 -18
- package/dist/tui/mouse.js +71 -0
- package/dist/tui/terminal-control.js +62 -0
- package/dist/tui/themes.js +398 -0
- package/dist/tui/tool-render.js +12 -1
- package/dist/tui.js +2 -1
- package/package.json +1 -3
package/dist/memory/context.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
|
+
import * as os from "os";
|
|
2
3
|
import * as path from "path";
|
|
3
4
|
import { findPhrenPath, getProjectDirs } from "@phren/cli/paths";
|
|
4
5
|
import { resolveRuntimeProfile } from "@phren/cli/runtime-profile";
|
|
@@ -66,21 +67,52 @@ function readTruths(phrenPath, project) {
|
|
|
66
67
|
return [];
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
70
|
+
const CLAUDE_MD_MAX_CHARS = 4000;
|
|
71
|
+
/**
|
|
72
|
+
* Collect CLAUDE.md files by walking up from cwd to the filesystem root,
|
|
73
|
+
* then checking the user-level ~/.claude/CLAUDE.md.
|
|
74
|
+
* Returns entries most-specific first (cwd → parent → ... → user-level).
|
|
75
|
+
*/
|
|
76
|
+
function collectClaudeMdFiles() {
|
|
77
|
+
const seen = new Set();
|
|
78
|
+
const results = [];
|
|
79
|
+
// Walk from cwd up to root
|
|
80
|
+
let dir = process.cwd();
|
|
81
|
+
while (true) {
|
|
82
|
+
const candidate = path.join(dir, "CLAUDE.md");
|
|
83
|
+
const resolved = path.resolve(candidate);
|
|
84
|
+
if (!seen.has(resolved)) {
|
|
85
|
+
seen.add(resolved);
|
|
86
|
+
try {
|
|
87
|
+
if (fs.existsSync(resolved)) {
|
|
88
|
+
const content = fs.readFileSync(resolved, "utf-8").trim();
|
|
89
|
+
if (content) {
|
|
90
|
+
results.push({ filePath: resolved, content });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch { /* skip unreadable */ }
|
|
95
|
+
}
|
|
96
|
+
const parent = path.dirname(dir);
|
|
97
|
+
if (parent === dir)
|
|
98
|
+
break; // reached root
|
|
99
|
+
dir = parent;
|
|
80
100
|
}
|
|
81
|
-
|
|
82
|
-
|
|
101
|
+
// Check user-level ~/.claude/CLAUDE.md
|
|
102
|
+
const userLevel = path.resolve(os.homedir(), ".claude", "CLAUDE.md");
|
|
103
|
+
if (!seen.has(userLevel)) {
|
|
104
|
+
seen.add(userLevel);
|
|
105
|
+
try {
|
|
106
|
+
if (fs.existsSync(userLevel)) {
|
|
107
|
+
const content = fs.readFileSync(userLevel, "utf-8").trim();
|
|
108
|
+
if (content) {
|
|
109
|
+
results.push({ filePath: userLevel, content });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch { /* skip */ }
|
|
83
114
|
}
|
|
115
|
+
return results;
|
|
84
116
|
}
|
|
85
117
|
/** Build a context string from phren knowledge to inject into the system prompt. */
|
|
86
118
|
export async function buildContextSnippet(ctx, taskKeywords) {
|
|
@@ -132,20 +164,20 @@ export async function buildContextSnippet(ctx, taskKeywords) {
|
|
|
132
164
|
}
|
|
133
165
|
catch { /* silent */ }
|
|
134
166
|
}
|
|
135
|
-
// Section 4:
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
167
|
+
// Section 4: CLAUDE.md hierarchy (cwd → parent dirs → ~/.claude/CLAUDE.md)
|
|
168
|
+
try {
|
|
169
|
+
const claudeFiles = collectClaudeMdFiles();
|
|
170
|
+
if (claudeFiles.length > 0) {
|
|
171
|
+
let combined = claudeFiles
|
|
172
|
+
.map((f) => `<!-- ${f.filePath} -->\n${f.content}`)
|
|
173
|
+
.join("\n\n---\n\n");
|
|
174
|
+
if (combined.length > CLAUDE_MD_MAX_CHARS) {
|
|
175
|
+
combined = combined.slice(0, CLAUDE_MD_MAX_CHARS) + "\n\n<!-- truncated -->";
|
|
145
176
|
}
|
|
177
|
+
sections.push(`## CLAUDE.md\n\n${combined}`);
|
|
146
178
|
}
|
|
147
|
-
catch { /* silent */ }
|
|
148
179
|
}
|
|
180
|
+
catch { /* silent */ }
|
|
149
181
|
// Section 5: FTS5 search
|
|
150
182
|
try {
|
|
151
183
|
const db = await buildIndex(ctx.phrenPath, ctx.profile || undefined);
|
package/dist/memory/session.js
CHANGED
|
@@ -1,100 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as fs from "fs";
|
|
3
|
-
import * as path from "path";
|
|
4
|
-
function sessionsDir(phrenPath) {
|
|
5
|
-
const dir = path.join(phrenPath, ".runtime", "sessions");
|
|
6
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
7
|
-
return dir;
|
|
8
|
-
}
|
|
9
|
-
function sessionFile(phrenPath, sessionId) {
|
|
10
|
-
return path.join(sessionsDir(phrenPath), `session-${sessionId}.json`);
|
|
11
|
-
}
|
|
1
|
+
import { endSessionRecord, findMostRecentSummaryWithProject, incrementSessionStateCounter, loadLastSessionMessages as loadSharedLastSessionMessages, loadLastSessionSnapshot as loadSharedLastSessionSnapshot, saveSessionMessages as saveSharedSessionMessages, startSessionRecord, } from "@phren/cli/session/artifacts";
|
|
12
2
|
export function startSession(ctx) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
sessionId,
|
|
16
|
-
project: ctx.project || undefined,
|
|
17
|
-
startedAt: new Date().toISOString(),
|
|
18
|
-
findingsAdded: 0,
|
|
19
|
-
tasksCompleted: 0,
|
|
3
|
+
return startSessionRecord(ctx.phrenPath, {
|
|
4
|
+
project: ctx.project ?? undefined,
|
|
20
5
|
agentCreated: true,
|
|
21
|
-
};
|
|
22
|
-
const file = sessionFile(ctx.phrenPath, sessionId);
|
|
23
|
-
fs.writeFileSync(file, JSON.stringify(state, null, 2) + "\n");
|
|
24
|
-
return sessionId;
|
|
6
|
+
});
|
|
25
7
|
}
|
|
26
8
|
export function endSession(ctx, sessionId, summary) {
|
|
27
|
-
|
|
28
|
-
if (!fs.existsSync(file))
|
|
29
|
-
return;
|
|
30
|
-
try {
|
|
31
|
-
const state = JSON.parse(fs.readFileSync(file, "utf-8"));
|
|
32
|
-
state.endedAt = new Date().toISOString();
|
|
33
|
-
if (summary) {
|
|
34
|
-
// Also write to last-summary.json for fast pickup by next session_start
|
|
35
|
-
const summaryFile = path.join(sessionsDir(ctx.phrenPath), "last-summary.json");
|
|
36
|
-
fs.writeFileSync(summaryFile, JSON.stringify({
|
|
37
|
-
summary,
|
|
38
|
-
sessionId,
|
|
39
|
-
project: state.project,
|
|
40
|
-
endedAt: state.endedAt,
|
|
41
|
-
}, null, 2) + "\n");
|
|
42
|
-
}
|
|
43
|
-
fs.writeFileSync(file, JSON.stringify(state, null, 2) + "\n");
|
|
44
|
-
}
|
|
45
|
-
catch { /* best effort */ }
|
|
9
|
+
endSessionRecord(ctx.phrenPath, sessionId, summary);
|
|
46
10
|
}
|
|
47
11
|
export function incrementSessionCounter(phrenPath, sessionId, counter) {
|
|
48
|
-
|
|
49
|
-
if (!fs.existsSync(file))
|
|
50
|
-
return;
|
|
51
|
-
try {
|
|
52
|
-
const state = JSON.parse(fs.readFileSync(file, "utf-8"));
|
|
53
|
-
state[counter] = (state[counter] ?? 0) + 1;
|
|
54
|
-
fs.writeFileSync(file, JSON.stringify(state, null, 2) + "\n");
|
|
55
|
-
}
|
|
56
|
-
catch { /* best effort */ }
|
|
12
|
+
incrementSessionStateCounter(phrenPath, sessionId, counter);
|
|
57
13
|
}
|
|
58
|
-
/** Read the most recent session summary for prior context. */
|
|
59
14
|
export function getPriorSummary(ctx) {
|
|
60
|
-
|
|
61
|
-
const summaryFile = path.join(sessionsDir(ctx.phrenPath), "last-summary.json");
|
|
62
|
-
if (!fs.existsSync(summaryFile))
|
|
63
|
-
return null;
|
|
64
|
-
const data = JSON.parse(fs.readFileSync(summaryFile, "utf-8"));
|
|
65
|
-
return data.summary || null;
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
15
|
+
return findMostRecentSummaryWithProject(ctx.phrenPath, ctx.project ?? undefined).summary;
|
|
70
16
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
74
|
-
return dir;
|
|
17
|
+
export function saveSessionMessages(phrenPath, sessionId, messages, project) {
|
|
18
|
+
saveSharedSessionMessages(phrenPath, sessionId, messages, project);
|
|
75
19
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
fs.writeFileSync(file, JSON.stringify(messages, null, 2) + "\n");
|
|
80
|
-
}
|
|
81
|
-
/** Load the last session's messages for resume. Returns null if none found. */
|
|
82
|
-
export function loadLastSessionMessages(phrenPath) {
|
|
83
|
-
try {
|
|
84
|
-
const dir = messagesDir(phrenPath);
|
|
85
|
-
const files = fs.readdirSync(dir)
|
|
86
|
-
.filter(f => f.endsWith("-messages.json"))
|
|
87
|
-
.map(f => ({
|
|
88
|
-
name: f,
|
|
89
|
-
mtime: fs.statSync(path.join(dir, f)).mtimeMs,
|
|
90
|
-
}))
|
|
91
|
-
.sort((a, b) => b.mtime - a.mtime);
|
|
92
|
-
if (files.length === 0)
|
|
93
|
-
return null;
|
|
94
|
-
const data = fs.readFileSync(path.join(dir, files[0].name), "utf-8");
|
|
95
|
-
return JSON.parse(data);
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
20
|
+
export function loadLastSessionSnapshot(phrenPath, project) {
|
|
21
|
+
const snapshot = loadSharedLastSessionSnapshot(phrenPath, project);
|
|
22
|
+
if (!snapshot)
|
|
98
23
|
return null;
|
|
99
|
-
|
|
24
|
+
return {
|
|
25
|
+
sessionId: snapshot.sessionId,
|
|
26
|
+
project: snapshot.project,
|
|
27
|
+
savedAt: snapshot.savedAt,
|
|
28
|
+
messages: snapshot.messages,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function loadLastSessionMessages(phrenPath, project) {
|
|
32
|
+
return loadSharedLastSessionMessages(phrenPath, project);
|
|
100
33
|
}
|
package/dist/models.js
ADDED
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
export const REASONING_LEVELS = ["low", "medium", "high", "xhigh"];
|
|
2
|
+
const BUILTIN_MODELS = {
|
|
3
|
+
anthropic: [
|
|
4
|
+
{
|
|
5
|
+
id: "claude-sonnet-4-20250514",
|
|
6
|
+
provider: "anthropic",
|
|
7
|
+
label: "Sonnet 4",
|
|
8
|
+
contextWindow: 200_000,
|
|
9
|
+
maxOutputTokens: 16_384,
|
|
10
|
+
reasoningDefault: "medium",
|
|
11
|
+
reasoningRange: ["low", "medium", "high"],
|
|
12
|
+
pricing: { inputPer1M: 3, outputPer1M: 15 },
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: "claude-opus-4-20250514",
|
|
16
|
+
provider: "anthropic",
|
|
17
|
+
label: "Opus 4",
|
|
18
|
+
contextWindow: 200_000,
|
|
19
|
+
maxOutputTokens: 32_768,
|
|
20
|
+
reasoningDefault: "high",
|
|
21
|
+
reasoningRange: ["low", "medium", "high", "xhigh"],
|
|
22
|
+
pricing: { inputPer1M: 15, outputPer1M: 75 },
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "claude-haiku-4-5-20251001",
|
|
26
|
+
provider: "anthropic",
|
|
27
|
+
label: "Haiku 4.5",
|
|
28
|
+
contextWindow: 200_000,
|
|
29
|
+
maxOutputTokens: 8_192,
|
|
30
|
+
reasoningDefault: null,
|
|
31
|
+
reasoningRange: [],
|
|
32
|
+
pricing: { inputPer1M: 0.8, outputPer1M: 4 },
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
openrouter: [
|
|
36
|
+
{
|
|
37
|
+
id: "anthropic/claude-sonnet-4-20250514",
|
|
38
|
+
provider: "openrouter",
|
|
39
|
+
label: "Sonnet 4",
|
|
40
|
+
contextWindow: 200_000,
|
|
41
|
+
maxOutputTokens: 16_384,
|
|
42
|
+
reasoningDefault: "medium",
|
|
43
|
+
reasoningRange: ["low", "medium", "high"],
|
|
44
|
+
pricing: { inputPer1M: 3, outputPer1M: 15 },
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: "anthropic/claude-opus-4-20250514",
|
|
48
|
+
provider: "openrouter",
|
|
49
|
+
label: "Opus 4",
|
|
50
|
+
contextWindow: 200_000,
|
|
51
|
+
maxOutputTokens: 32_768,
|
|
52
|
+
reasoningDefault: "high",
|
|
53
|
+
reasoningRange: ["low", "medium", "high", "xhigh"],
|
|
54
|
+
pricing: { inputPer1M: 15, outputPer1M: 75 },
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: "openai/gpt-4o",
|
|
58
|
+
provider: "openrouter",
|
|
59
|
+
label: "GPT-4o",
|
|
60
|
+
contextWindow: 128_000,
|
|
61
|
+
maxOutputTokens: 16_384,
|
|
62
|
+
reasoningDefault: null,
|
|
63
|
+
reasoningRange: [],
|
|
64
|
+
pricing: { inputPer1M: 2.5, outputPer1M: 10 },
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: "openai/o4-mini",
|
|
68
|
+
provider: "openrouter",
|
|
69
|
+
label: "o4-mini",
|
|
70
|
+
contextWindow: 128_000,
|
|
71
|
+
maxOutputTokens: 100_000,
|
|
72
|
+
reasoningDefault: "medium",
|
|
73
|
+
reasoningRange: ["low", "medium", "high"],
|
|
74
|
+
pricing: { inputPer1M: 1.1, outputPer1M: 4.4 },
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: "google/gemini-2.5-pro",
|
|
78
|
+
provider: "openrouter",
|
|
79
|
+
label: "Gemini 2.5 Pro",
|
|
80
|
+
contextWindow: 1_000_000,
|
|
81
|
+
maxOutputTokens: 8_192,
|
|
82
|
+
reasoningDefault: "medium",
|
|
83
|
+
reasoningRange: ["low", "medium", "high"],
|
|
84
|
+
pricing: { inputPer1M: 1.25, outputPer1M: 10 },
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: "google/gemini-2.5-flash",
|
|
88
|
+
provider: "openrouter",
|
|
89
|
+
label: "Gemini 2.5 Flash",
|
|
90
|
+
contextWindow: 1_000_000,
|
|
91
|
+
maxOutputTokens: 8_192,
|
|
92
|
+
reasoningDefault: "medium",
|
|
93
|
+
reasoningRange: ["low", "medium", "high"],
|
|
94
|
+
pricing: { inputPer1M: 0.15, outputPer1M: 0.6 },
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: "deepseek/deepseek-r1",
|
|
98
|
+
provider: "openrouter",
|
|
99
|
+
label: "DeepSeek R1",
|
|
100
|
+
contextWindow: 128_000,
|
|
101
|
+
maxOutputTokens: 8_192,
|
|
102
|
+
reasoningDefault: "high",
|
|
103
|
+
reasoningRange: ["medium", "high"],
|
|
104
|
+
pricing: { inputPer1M: 0.55, outputPer1M: 2.19 },
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: "deepseek/deepseek-v3",
|
|
108
|
+
provider: "openrouter",
|
|
109
|
+
label: "DeepSeek V3",
|
|
110
|
+
contextWindow: 128_000,
|
|
111
|
+
maxOutputTokens: 8_192,
|
|
112
|
+
reasoningDefault: null,
|
|
113
|
+
reasoningRange: [],
|
|
114
|
+
pricing: { inputPer1M: 0.27, outputPer1M: 1.1 },
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: "meta-llama/llama-4-maverick",
|
|
118
|
+
provider: "openrouter",
|
|
119
|
+
label: "Llama 4 Maverick",
|
|
120
|
+
contextWindow: 128_000,
|
|
121
|
+
maxOutputTokens: 8_192,
|
|
122
|
+
reasoningDefault: null,
|
|
123
|
+
reasoningRange: [],
|
|
124
|
+
pricing: { inputPer1M: 0.5, outputPer1M: 0.7 },
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: "qwen/qwen3-235b",
|
|
128
|
+
provider: "openrouter",
|
|
129
|
+
label: "Qwen 3 235B",
|
|
130
|
+
contextWindow: 128_000,
|
|
131
|
+
maxOutputTokens: 8_192,
|
|
132
|
+
reasoningDefault: "medium",
|
|
133
|
+
reasoningRange: ["low", "medium", "high"],
|
|
134
|
+
pricing: { inputPer1M: 0.8, outputPer1M: 2.4 },
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
openai: [
|
|
138
|
+
{
|
|
139
|
+
id: "gpt-5.4",
|
|
140
|
+
provider: "openai",
|
|
141
|
+
label: "GPT-5.4",
|
|
142
|
+
contextWindow: 1_050_000,
|
|
143
|
+
maxOutputTokens: 128_000,
|
|
144
|
+
reasoningDefault: "medium",
|
|
145
|
+
reasoningRange: ["low", "medium", "high", "xhigh"],
|
|
146
|
+
pricing: { inputPer1M: 2.5, outputPer1M: 15 },
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
id: "gpt-4o",
|
|
150
|
+
provider: "openai",
|
|
151
|
+
label: "GPT-4o",
|
|
152
|
+
contextWindow: 128_000,
|
|
153
|
+
maxOutputTokens: 16_384,
|
|
154
|
+
reasoningDefault: null,
|
|
155
|
+
reasoningRange: [],
|
|
156
|
+
pricing: { inputPer1M: 2.5, outputPer1M: 10 },
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
id: "o4-mini",
|
|
160
|
+
provider: "openai",
|
|
161
|
+
label: "o4-mini",
|
|
162
|
+
contextWindow: 200_000,
|
|
163
|
+
maxOutputTokens: 100_000,
|
|
164
|
+
reasoningDefault: "medium",
|
|
165
|
+
reasoningRange: ["low", "medium", "high"],
|
|
166
|
+
pricing: { inputPer1M: 1.1, outputPer1M: 4.4 },
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
id: "o3",
|
|
170
|
+
provider: "openai",
|
|
171
|
+
label: "o3",
|
|
172
|
+
contextWindow: 200_000,
|
|
173
|
+
maxOutputTokens: 100_000,
|
|
174
|
+
reasoningDefault: "high",
|
|
175
|
+
reasoningRange: ["low", "medium", "high", "xhigh"],
|
|
176
|
+
pricing: { inputPer1M: 2, outputPer1M: 8 },
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
"openai-codex": [
|
|
180
|
+
{
|
|
181
|
+
id: "gpt-5.4",
|
|
182
|
+
provider: "openai-codex",
|
|
183
|
+
label: "GPT-5.4",
|
|
184
|
+
contextWindow: 1_050_000,
|
|
185
|
+
maxOutputTokens: 128_000,
|
|
186
|
+
reasoningDefault: "medium",
|
|
187
|
+
reasoningRange: ["low", "medium", "high", "xhigh"],
|
|
188
|
+
metered: false,
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
id: "gpt-4o",
|
|
192
|
+
provider: "openai-codex",
|
|
193
|
+
label: "GPT-4o",
|
|
194
|
+
contextWindow: 128_000,
|
|
195
|
+
maxOutputTokens: 16_384,
|
|
196
|
+
reasoningDefault: null,
|
|
197
|
+
reasoningRange: [],
|
|
198
|
+
metered: false,
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
id: "o4-mini",
|
|
202
|
+
provider: "openai-codex",
|
|
203
|
+
label: "o4-mini",
|
|
204
|
+
contextWindow: 200_000,
|
|
205
|
+
maxOutputTokens: 100_000,
|
|
206
|
+
reasoningDefault: "medium",
|
|
207
|
+
reasoningRange: ["low", "medium", "high"],
|
|
208
|
+
metered: false,
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
id: "o3",
|
|
212
|
+
provider: "openai-codex",
|
|
213
|
+
label: "o3",
|
|
214
|
+
contextWindow: 200_000,
|
|
215
|
+
maxOutputTokens: 100_000,
|
|
216
|
+
reasoningDefault: "high",
|
|
217
|
+
reasoningRange: ["low", "medium", "high", "xhigh"],
|
|
218
|
+
metered: false,
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
ollama: [
|
|
222
|
+
{
|
|
223
|
+
id: "qwen2.5-coder:14b",
|
|
224
|
+
provider: "ollama",
|
|
225
|
+
label: "Qwen 2.5 Coder 14B",
|
|
226
|
+
contextWindow: 32_000,
|
|
227
|
+
maxOutputTokens: 8_192,
|
|
228
|
+
reasoningDefault: null,
|
|
229
|
+
reasoningRange: [],
|
|
230
|
+
pricing: { inputPer1M: 0, outputPer1M: 0 },
|
|
231
|
+
metered: false,
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
id: "llama3.2",
|
|
235
|
+
provider: "ollama",
|
|
236
|
+
label: "Llama 3.2",
|
|
237
|
+
contextWindow: 128_000,
|
|
238
|
+
maxOutputTokens: 8_192,
|
|
239
|
+
reasoningDefault: null,
|
|
240
|
+
reasoningRange: [],
|
|
241
|
+
pricing: { inputPer1M: 0, outputPer1M: 0 },
|
|
242
|
+
metered: false,
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
id: "deepseek-r1:14b",
|
|
246
|
+
provider: "ollama",
|
|
247
|
+
label: "DeepSeek R1 14B",
|
|
248
|
+
contextWindow: 128_000,
|
|
249
|
+
maxOutputTokens: 8_192,
|
|
250
|
+
reasoningDefault: "medium",
|
|
251
|
+
reasoningRange: ["medium", "high"],
|
|
252
|
+
pricing: { inputPer1M: 0, outputPer1M: 0 },
|
|
253
|
+
metered: false,
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
};
|
|
257
|
+
const LEGACY_OUTPUT_LIMITS = [
|
|
258
|
+
["claude-opus-4", 32_768],
|
|
259
|
+
["claude-sonnet-4", 16_384],
|
|
260
|
+
["claude-haiku-4", 8_192],
|
|
261
|
+
["claude-3-5-sonnet", 8_192],
|
|
262
|
+
["claude-3-5-haiku", 8_192],
|
|
263
|
+
["claude-3-opus", 4_096],
|
|
264
|
+
["gpt-4.1", 32_768],
|
|
265
|
+
["gpt-4o", 16_384],
|
|
266
|
+
["gpt-4-turbo", 4_096],
|
|
267
|
+
["gpt-5", 128_000],
|
|
268
|
+
["o3", 100_000],
|
|
269
|
+
["o4-mini", 100_000],
|
|
270
|
+
["gemini-2.5", 8_192],
|
|
271
|
+
["deepseek", 8_192],
|
|
272
|
+
["llama-4", 8_192],
|
|
273
|
+
["qwen", 8_192],
|
|
274
|
+
];
|
|
275
|
+
const LEGACY_PRICING = [
|
|
276
|
+
["claude-opus-4", { inputPer1M: 15, outputPer1M: 75 }],
|
|
277
|
+
["claude-sonnet-4", { inputPer1M: 3, outputPer1M: 15 }],
|
|
278
|
+
["claude-haiku-4", { inputPer1M: 0.8, outputPer1M: 4 }],
|
|
279
|
+
["claude-3-5-sonnet", { inputPer1M: 3, outputPer1M: 15 }],
|
|
280
|
+
["claude-3-5-haiku", { inputPer1M: 0.8, outputPer1M: 4 }],
|
|
281
|
+
["claude-3-opus", { inputPer1M: 15, outputPer1M: 75 }],
|
|
282
|
+
["gpt-5", { inputPer1M: 2.5, outputPer1M: 10 }],
|
|
283
|
+
["gpt-4.1", { inputPer1M: 2, outputPer1M: 8 }],
|
|
284
|
+
["gpt-4o", { inputPer1M: 2.5, outputPer1M: 10 }],
|
|
285
|
+
["gpt-4-turbo", { inputPer1M: 10, outputPer1M: 30 }],
|
|
286
|
+
["gpt-4", { inputPer1M: 30, outputPer1M: 60 }],
|
|
287
|
+
["o3", { inputPer1M: 2, outputPer1M: 8 }],
|
|
288
|
+
["o4-mini", { inputPer1M: 1.1, outputPer1M: 4.4 }],
|
|
289
|
+
["anthropic/claude-opus-4", { inputPer1M: 15, outputPer1M: 75 }],
|
|
290
|
+
["anthropic/claude-sonnet-4", { inputPer1M: 3, outputPer1M: 15 }],
|
|
291
|
+
["anthropic/claude-haiku-4", { inputPer1M: 0.8, outputPer1M: 4 }],
|
|
292
|
+
["openai/gpt-4o", { inputPer1M: 2.5, outputPer1M: 10 }],
|
|
293
|
+
["google/gemini-2.5-pro", { inputPer1M: 1.25, outputPer1M: 10 }],
|
|
294
|
+
["google/gemini-2.5-flash", { inputPer1M: 0.15, outputPer1M: 0.6 }],
|
|
295
|
+
["deepseek/deepseek-r1", { inputPer1M: 0.55, outputPer1M: 2.19 }],
|
|
296
|
+
["deepseek/deepseek-v3", { inputPer1M: 0.27, outputPer1M: 1.1 }],
|
|
297
|
+
["deepseek-r1", { inputPer1M: 0.55, outputPer1M: 2.19 }],
|
|
298
|
+
["deepseek-v3", { inputPer1M: 0.27, outputPer1M: 1.1 }],
|
|
299
|
+
["meta-llama/llama-4-maverick", { inputPer1M: 0.5, outputPer1M: 0.7 }],
|
|
300
|
+
["qwen/qwen3-235b", { inputPer1M: 0.8, outputPer1M: 2.4 }],
|
|
301
|
+
["gemini-2.5-pro", { inputPer1M: 1.25, outputPer1M: 10 }],
|
|
302
|
+
["gemini-2.5-flash", { inputPer1M: 0.15, outputPer1M: 0.6 }],
|
|
303
|
+
["ollama", { inputPer1M: 0, outputPer1M: 0 }],
|
|
304
|
+
];
|
|
305
|
+
LEGACY_OUTPUT_LIMITS.sort((a, b) => b[0].length - a[0].length);
|
|
306
|
+
LEGACY_PRICING.sort((a, b) => b[0].length - a[0].length);
|
|
307
|
+
export function normalizeProviderId(provider) {
|
|
308
|
+
if (!provider)
|
|
309
|
+
return undefined;
|
|
310
|
+
if (provider === "codex")
|
|
311
|
+
return "openai-codex";
|
|
312
|
+
if (provider === "openrouter" ||
|
|
313
|
+
provider === "anthropic" ||
|
|
314
|
+
provider === "openai" ||
|
|
315
|
+
provider === "openai-codex" ||
|
|
316
|
+
provider === "ollama") {
|
|
317
|
+
return provider;
|
|
318
|
+
}
|
|
319
|
+
return undefined;
|
|
320
|
+
}
|
|
321
|
+
export function normalizeReasoningEffort(raw) {
|
|
322
|
+
if (!raw)
|
|
323
|
+
return undefined;
|
|
324
|
+
const value = raw.toLowerCase();
|
|
325
|
+
if (value === "max")
|
|
326
|
+
return "xhigh";
|
|
327
|
+
if (value === "low" || value === "medium" || value === "high" || value === "xhigh")
|
|
328
|
+
return value;
|
|
329
|
+
return undefined;
|
|
330
|
+
}
|
|
331
|
+
export function getDefaultModel(provider) {
|
|
332
|
+
return BUILTIN_MODELS[provider][0].id;
|
|
333
|
+
}
|
|
334
|
+
export function getBuiltinModels(provider) {
|
|
335
|
+
return BUILTIN_MODELS[provider].map((entry) => ({
|
|
336
|
+
...entry,
|
|
337
|
+
reasoningRange: [...entry.reasoningRange],
|
|
338
|
+
pricing: entry.pricing ? { ...entry.pricing } : undefined,
|
|
339
|
+
}));
|
|
340
|
+
}
|
|
341
|
+
export function getModelMetadata(provider, model) {
|
|
342
|
+
const normalizedProvider = normalizeProviderId(provider);
|
|
343
|
+
if (normalizedProvider) {
|
|
344
|
+
const direct = BUILTIN_MODELS[normalizedProvider].find((entry) => entry.id === model);
|
|
345
|
+
if (direct)
|
|
346
|
+
return direct;
|
|
347
|
+
}
|
|
348
|
+
for (const entries of Object.values(BUILTIN_MODELS)) {
|
|
349
|
+
const direct = entries.find((entry) => entry.id === model);
|
|
350
|
+
if (direct)
|
|
351
|
+
return direct;
|
|
352
|
+
}
|
|
353
|
+
return undefined;
|
|
354
|
+
}
|
|
355
|
+
export function getDefaultReasoningEffort(provider, model) {
|
|
356
|
+
return getModelMetadata(provider, model)?.reasoningDefault ?? undefined;
|
|
357
|
+
}
|
|
358
|
+
export function getReasoningRange(provider, model) {
|
|
359
|
+
return [...(getModelMetadata(provider, model)?.reasoningRange ?? [])];
|
|
360
|
+
}
|
|
361
|
+
export function lookupMaxOutputTokens(model, provider) {
|
|
362
|
+
const metadata = getModelMetadata(provider, model);
|
|
363
|
+
if (metadata)
|
|
364
|
+
return metadata.maxOutputTokens;
|
|
365
|
+
const lower = model.toLowerCase();
|
|
366
|
+
for (const [prefix, limit] of LEGACY_OUTPUT_LIMITS) {
|
|
367
|
+
if (lower.startsWith(prefix))
|
|
368
|
+
return limit;
|
|
369
|
+
}
|
|
370
|
+
return 8_192;
|
|
371
|
+
}
|
|
372
|
+
export function lookupPricing(model, provider) {
|
|
373
|
+
const normalizedProvider = normalizeProviderId(provider);
|
|
374
|
+
if (normalizedProvider === "openai-codex") {
|
|
375
|
+
return { pricing: { inputPer1M: 0, outputPer1M: 0 }, metered: false };
|
|
376
|
+
}
|
|
377
|
+
const metadata = getModelMetadata(provider, model);
|
|
378
|
+
if (metadata?.pricing) {
|
|
379
|
+
return { pricing: metadata.pricing, metered: metadata.metered ?? true };
|
|
380
|
+
}
|
|
381
|
+
if (metadata?.metered === false) {
|
|
382
|
+
return { pricing: { inputPer1M: 0, outputPer1M: 0 }, metered: false };
|
|
383
|
+
}
|
|
384
|
+
const lower = model.toLowerCase();
|
|
385
|
+
for (const [prefix, pricing] of LEGACY_PRICING) {
|
|
386
|
+
if (lower.startsWith(prefix))
|
|
387
|
+
return { pricing, metered: true };
|
|
388
|
+
}
|
|
389
|
+
return { pricing: { inputPer1M: 3, outputPer1M: 15 }, metered: true };
|
|
390
|
+
}
|