selftune 0.1.0 → 0.1.4

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.
@@ -2,15 +2,15 @@
2
2
  * Shared LLM call utility.
3
3
  *
4
4
  * Provides a unified interface for calling LLMs via agent subprocess
5
- * (claude/codex/opencode) or via the direct Anthropic API. Extracted from
6
- * grade-session.ts so other modules can reuse the same calling logic.
5
+ * (claude/codex/opencode). Extracted from grade-session.ts so other
6
+ * modules can reuse the same calling logic.
7
7
  */
8
8
 
9
9
  import { readFileSync, writeFileSync } from "node:fs";
10
10
  import { tmpdir } from "node:os";
11
11
  import { join } from "node:path";
12
12
 
13
- import { AGENT_CANDIDATES, API_URL, MODEL } from "../constants.js";
13
+ import { AGENT_CANDIDATES } from "../constants.js";
14
14
 
15
15
  // ---------------------------------------------------------------------------
16
16
  // Agent detection
@@ -126,67 +126,18 @@ export async function callViaAgent(
126
126
  }
127
127
  }
128
128
 
129
- // ---------------------------------------------------------------------------
130
- // Call LLM via direct Anthropic API
131
- // ---------------------------------------------------------------------------
132
-
133
- /** Call LLM via direct Anthropic API. Returns raw text. */
134
- export async function callViaApi(systemPrompt: string, userPrompt: string): Promise<string> {
135
- const apiKey = process.env.ANTHROPIC_API_KEY ?? "";
136
- if (!apiKey) {
137
- throw new Error(
138
- "ANTHROPIC_API_KEY not set. Use --use-agent to grade via your " +
139
- "installed Claude Code / Codex / OpenCode subscription instead.",
140
- );
141
- }
142
-
143
- const payload = {
144
- model: MODEL,
145
- max_tokens: 2000,
146
- system: systemPrompt,
147
- messages: [{ role: "user", content: userPrompt }],
148
- };
149
-
150
- const resp = await fetch(API_URL, {
151
- method: "POST",
152
- headers: {
153
- "Content-Type": "application/json",
154
- "x-api-key": apiKey,
155
- "anthropic-version": "2023-06-01",
156
- },
157
- body: JSON.stringify(payload),
158
- });
159
-
160
- if (!resp.ok) {
161
- const body = await resp.text();
162
- throw new Error(`API error ${resp.status}: ${body}`);
163
- }
164
-
165
- const data = await resp.json();
166
- let raw = "";
167
- for (const block of data.content ?? []) {
168
- if (block.type === "text") raw += block.text ?? "";
169
- }
170
-
171
- return raw;
172
- }
173
-
174
129
  // ---------------------------------------------------------------------------
175
130
  // Unified dispatcher
176
131
  // ---------------------------------------------------------------------------
177
132
 
178
- /** Dispatch to callViaAgent or callViaApi. Returns raw text. */
133
+ /** Call LLM via agent subprocess. Returns raw text. */
179
134
  export async function callLlm(
180
135
  systemPrompt: string,
181
136
  userPrompt: string,
182
- mode: "agent" | "api",
183
- agent?: string,
137
+ agent: string,
184
138
  ): Promise<string> {
185
- if (mode === "agent") {
186
- if (!agent) {
187
- throw new Error("Agent must be specified when mode is 'agent'");
188
- }
189
- return callViaAgent(systemPrompt, userPrompt, agent);
139
+ if (!agent) {
140
+ throw new Error("Agent must be specified for callLlm");
190
141
  }
191
- return callViaApi(systemPrompt, userPrompt);
142
+ return callViaAgent(systemPrompt, userPrompt, agent);
192
143
  }