@denizokcu/haze 0.3.0 → 0.4.0
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/CHANGELOG.md +34 -0
- package/README.md +31 -19
- package/dist/cli/commands/chat.d.ts +1 -1
- package/dist/cli/commands/chat.js +144 -52
- package/dist/cli/commands/commands.js +105 -114
- package/dist/cli/commands/streaming.d.ts +33 -5
- package/dist/cli/commands/streaming.js +235 -103
- package/dist/cli/contextReport.d.ts +1 -0
- package/dist/cli/contextReport.js +47 -0
- package/dist/config/contextFiles.d.ts +25 -0
- package/dist/config/contextFiles.js +53 -0
- package/dist/core/agent/compaction.d.ts +3 -0
- package/dist/core/agent/compaction.js +23 -3
- package/dist/core/agent/contextBudget.d.ts +33 -0
- package/dist/core/agent/contextBudget.js +88 -0
- package/dist/core/agent/requestAssembly.d.ts +22 -0
- package/dist/core/agent/requestAssembly.js +146 -0
- package/dist/core/agent/toolOutputStore.d.ts +11 -0
- package/dist/core/agent/toolOutputStore.js +33 -0
- package/dist/core/agent/workState.d.ts +38 -0
- package/dist/core/agent/workState.js +89 -0
- package/dist/core/goal/completionPolicy.js +1 -1
- package/dist/core/goal/sessionGoal.d.ts +2 -0
- package/dist/core/goal/sessionGoal.js +8 -1
- package/dist/core/log/llmLog.d.ts +68 -0
- package/dist/core/log/llmLog.js +55 -0
- package/dist/core/session/sessionStore.d.ts +6 -0
- package/dist/core/session/sessionStore.js +5 -0
- package/dist/core/subagent/subagentRunner.d.ts +4 -1
- package/dist/core/subagent/subagentRunner.js +5 -15
- package/dist/core/validation/outputParser.js +15 -2
- package/dist/llm/client.d.ts +39 -0
- package/dist/llm/client.js +46 -2
- package/dist/llm/hazeTools.d.ts +37 -12
- package/dist/llm/hazeTools.js +133 -55
- package/dist/llm/systemPrompt.d.ts +6 -1
- package/dist/llm/systemPrompt.js +42 -81
- package/dist/skills/builder/SkillBuilder.d.ts +16 -2
- package/dist/skills/builder/SkillBuilder.js +68 -65
- package/dist/skills/skillTools.d.ts +2 -19
- package/dist/skills/skillTools.js +28 -19
- package/package.json +2 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { classifyRequestIntent } from './requestClassifier.js';
|
|
2
|
+
import { createWorkState, observeWorkToolEvent } from '../agent/workState.js';
|
|
2
3
|
function shortRequest(value) {
|
|
3
4
|
return value.replace(/\s+/g, ' ').trim().slice(0, 160) || 'current request';
|
|
4
5
|
}
|
|
@@ -27,26 +28,30 @@ export function createSessionGoal(request, now = Date.now()) {
|
|
|
27
28
|
: intent === 'answer'
|
|
28
29
|
? ['Answer the user using current project context when needed']
|
|
29
30
|
: ['Inspect the relevant files', 'Make the requested change when needed', 'Validate the change when practical', 'Summarize only current-task changes and validation'];
|
|
31
|
+
const successCriteria = criteria;
|
|
30
32
|
return {
|
|
31
33
|
id: `goal-${now}-${Math.random().toString(36).slice(2)}`,
|
|
32
34
|
originalUserRequest: request,
|
|
33
35
|
normalizedIntent: intent,
|
|
34
|
-
successCriteria
|
|
36
|
+
successCriteria,
|
|
35
37
|
constraints: [],
|
|
36
38
|
touchedFiles: [],
|
|
37
39
|
validationCommands: [],
|
|
38
40
|
status: 'active',
|
|
39
41
|
phase: 'starting',
|
|
40
42
|
lastProgressAt: now,
|
|
43
|
+
workState: createWorkState(request, intent, successCriteria),
|
|
41
44
|
};
|
|
42
45
|
}
|
|
43
46
|
export function observeGoalToolEvent(goal, event, now = Date.now()) {
|
|
44
47
|
if (event.duplicateSkipped)
|
|
45
48
|
return goal;
|
|
49
|
+
observeWorkToolEvent(goal.workState, event);
|
|
46
50
|
if (event.success && ['listFiles', 'readFile'].includes(event.toolName)) {
|
|
47
51
|
goal.phase = goal.phase === 'editing' || goal.phase === 'validating' ? goal.phase : 'inspecting';
|
|
48
52
|
goal.lastProgressAt = now;
|
|
49
53
|
}
|
|
54
|
+
goal.workState.phase = goal.phase;
|
|
50
55
|
if (['editFile', 'replaceLines', 'writeFile'].includes(event.toolName)) {
|
|
51
56
|
const path = inputPath(event.input);
|
|
52
57
|
if (path)
|
|
@@ -59,6 +64,7 @@ export function observeGoalToolEvent(goal, event, now = Date.now()) {
|
|
|
59
64
|
goal.blocker = `File edit failed${path ? ` for ${path}` : ''}; recovery read is required before retry.`;
|
|
60
65
|
}
|
|
61
66
|
}
|
|
67
|
+
goal.workState.phase = goal.phase;
|
|
62
68
|
if (event.toolName === 'bash') {
|
|
63
69
|
const command = bashCommand(event.input);
|
|
64
70
|
if (command) {
|
|
@@ -75,6 +81,7 @@ export function observeGoalToolEvent(goal, event, now = Date.now()) {
|
|
|
75
81
|
goal.blocker = `Validation command failed: ${command}`;
|
|
76
82
|
}
|
|
77
83
|
}
|
|
84
|
+
goal.workState.phase = goal.phase;
|
|
78
85
|
return goal;
|
|
79
86
|
}
|
|
80
87
|
export function formatGoalStatus(goal) {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ModelMessage } from 'ai';
|
|
2
|
+
import type { ContextBreakdown } from '../agent/contextBudget.js';
|
|
3
|
+
export interface LlmLogEntry {
|
|
4
|
+
/** ISO timestamp. */
|
|
5
|
+
at: string;
|
|
6
|
+
/** Entry type. */
|
|
7
|
+
type: 'request' | 'response' | 'step' | 'tool_call' | 'tool_result' | 'error' | 'warning';
|
|
8
|
+
/** Which stream this belongs to: 'main' or 'continuation'. */
|
|
9
|
+
stream: string;
|
|
10
|
+
/** Step number within the stream. */
|
|
11
|
+
step?: number;
|
|
12
|
+
/** System prompt sent to the model (request entries only). */
|
|
13
|
+
system?: string;
|
|
14
|
+
/** Messages sent to the model (request entries only). */
|
|
15
|
+
messages?: ModelMessage[];
|
|
16
|
+
/** Tool names available (request entries only). */
|
|
17
|
+
tools?: string[];
|
|
18
|
+
/** Size-only request composition metrics. */
|
|
19
|
+
context?: ContextBreakdown;
|
|
20
|
+
/** Model response text. */
|
|
21
|
+
text?: string;
|
|
22
|
+
/** Finish reason from the model. */
|
|
23
|
+
finishReason?: string;
|
|
24
|
+
/** Token usage from the provider. */
|
|
25
|
+
usage?: {
|
|
26
|
+
inputTokens?: number;
|
|
27
|
+
outputTokens?: number;
|
|
28
|
+
cacheReadTokens?: number;
|
|
29
|
+
cacheWriteTokens?: number;
|
|
30
|
+
noCacheTokens?: number;
|
|
31
|
+
reasoningTokens?: number;
|
|
32
|
+
logicalInputEstimate?: number;
|
|
33
|
+
effectiveNonCachedInput?: number;
|
|
34
|
+
/** cacheReadTokens / inputTokens. Undefined when either is missing or input is 0. */
|
|
35
|
+
cacheHitRatio?: number;
|
|
36
|
+
};
|
|
37
|
+
/** Tool call details. */
|
|
38
|
+
toolCall?: {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
input: unknown;
|
|
42
|
+
};
|
|
43
|
+
/** Tool result details. */
|
|
44
|
+
toolResult?: {
|
|
45
|
+
id: string;
|
|
46
|
+
name: string;
|
|
47
|
+
success: boolean;
|
|
48
|
+
output?: unknown;
|
|
49
|
+
error?: unknown;
|
|
50
|
+
durationMs?: number;
|
|
51
|
+
};
|
|
52
|
+
/** Error message. */
|
|
53
|
+
error?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface LlmLog {
|
|
56
|
+
id: string;
|
|
57
|
+
file: string;
|
|
58
|
+
}
|
|
59
|
+
export declare function createLog(): Promise<LlmLog>;
|
|
60
|
+
export declare function appendLogEntry(log: LlmLog, entry: LlmLogEntry): Promise<void>;
|
|
61
|
+
export declare function endLog(log: LlmLog): Promise<void>;
|
|
62
|
+
export declare function listLogs(): Promise<Array<{
|
|
63
|
+
id: string;
|
|
64
|
+
file: string;
|
|
65
|
+
size: number;
|
|
66
|
+
modified: string;
|
|
67
|
+
}>>;
|
|
68
|
+
export declare function readLogEntries(id: string): Promise<LlmLogEntry[]>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { HAZE_DIR } from '../../config/paths.js';
|
|
4
|
+
const LOGS_DIR = path.join(HAZE_DIR, 'logs');
|
|
5
|
+
function logFileId(now = new Date()) {
|
|
6
|
+
return now.toISOString().replace(/[:.]/g, '-');
|
|
7
|
+
}
|
|
8
|
+
function logFilePath(id) {
|
|
9
|
+
return path.join(LOGS_DIR, `${id}.jsonl`);
|
|
10
|
+
}
|
|
11
|
+
export async function createLog() {
|
|
12
|
+
await fs.ensureDir(LOGS_DIR);
|
|
13
|
+
const id = logFileId();
|
|
14
|
+
const file = logFilePath(id);
|
|
15
|
+
await fs.writeFile(file, '');
|
|
16
|
+
return { id, file };
|
|
17
|
+
}
|
|
18
|
+
export async function appendLogEntry(log, entry) {
|
|
19
|
+
const line = JSON.stringify(entry) + '\n';
|
|
20
|
+
await fs.appendFile(log.file, line);
|
|
21
|
+
}
|
|
22
|
+
export async function endLog(log) {
|
|
23
|
+
const entry = {
|
|
24
|
+
at: new Date().toISOString(),
|
|
25
|
+
type: 'response',
|
|
26
|
+
stream: 'main',
|
|
27
|
+
finishReason: 'log-ended',
|
|
28
|
+
};
|
|
29
|
+
await appendLogEntry(log, entry);
|
|
30
|
+
}
|
|
31
|
+
export async function listLogs() {
|
|
32
|
+
await fs.ensureDir(LOGS_DIR);
|
|
33
|
+
const files = await fs.readdir(LOGS_DIR);
|
|
34
|
+
const logs = [];
|
|
35
|
+
for (const name of files) {
|
|
36
|
+
if (!name.endsWith('.jsonl'))
|
|
37
|
+
continue;
|
|
38
|
+
const file = path.join(LOGS_DIR, name);
|
|
39
|
+
const stat = await fs.stat(file);
|
|
40
|
+
logs.push({ id: name.replace(/\.jsonl$/, ''), file, size: stat.size, modified: stat.mtime.toISOString() });
|
|
41
|
+
}
|
|
42
|
+
return logs.sort((a, b) => b.modified.localeCompare(a.modified));
|
|
43
|
+
}
|
|
44
|
+
export async function readLogEntries(id) {
|
|
45
|
+
const file = logFilePath(id);
|
|
46
|
+
const raw = await fs.readFile(file, 'utf8').catch(() => '');
|
|
47
|
+
return raw.split('\n').filter(Boolean).flatMap(line => {
|
|
48
|
+
try {
|
|
49
|
+
return [JSON.parse(line)];
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ModelMessage } from 'ai';
|
|
2
|
+
import type { WorkState } from '../agent/workState.js';
|
|
2
3
|
export type SessionEntry = {
|
|
3
4
|
type: 'header';
|
|
4
5
|
id: string;
|
|
@@ -14,6 +15,10 @@ export type SessionEntry = {
|
|
|
14
15
|
type: 'conversation_snapshot';
|
|
15
16
|
at: string;
|
|
16
17
|
messages: ModelMessage[];
|
|
18
|
+
} | {
|
|
19
|
+
type: 'work_state_snapshot';
|
|
20
|
+
at: string;
|
|
21
|
+
state: WorkState;
|
|
17
22
|
} | {
|
|
18
23
|
type: 'event';
|
|
19
24
|
at: string;
|
|
@@ -34,4 +39,5 @@ export declare function latestSession(cwd?: string, sessionsDir?: string): Promi
|
|
|
34
39
|
export declare function appendSessionEntry(session: HazeSession, entry: SessionEntry): Promise<void>;
|
|
35
40
|
export declare function readSessionEntries(session: HazeSession): Promise<SessionEntry[]>;
|
|
36
41
|
export declare function restoreConversation(session: HazeSession): Promise<ModelMessage[]>;
|
|
42
|
+
export declare function restoreWorkState(session: HazeSession): Promise<WorkState | undefined>;
|
|
37
43
|
export declare function formatSession(session: HazeSession): string;
|
|
@@ -54,6 +54,11 @@ export async function restoreConversation(session) {
|
|
|
54
54
|
const snapshots = entries.filter((entry) => entry.type === 'conversation_snapshot');
|
|
55
55
|
return snapshots.at(-1)?.messages ?? [];
|
|
56
56
|
}
|
|
57
|
+
export async function restoreWorkState(session) {
|
|
58
|
+
const entries = await readSessionEntries(session);
|
|
59
|
+
const snapshots = entries.filter((entry) => entry.type === 'work_state_snapshot');
|
|
60
|
+
return snapshots.at(-1)?.state;
|
|
61
|
+
}
|
|
57
62
|
export function formatSession(session) {
|
|
58
63
|
return `${session.id} · ${session.file}`;
|
|
59
64
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { streamText } from 'ai';
|
|
2
|
+
import { type PromptSession } from '../../llm/systemPrompt.js';
|
|
2
3
|
import type { ContextFile } from '../../config/contextFiles.js';
|
|
3
4
|
export interface SubagentResult {
|
|
4
5
|
status: 'ok' | 'error' | 'timeout' | 'cancelled';
|
|
@@ -22,12 +23,14 @@ export declare function runSubagent(task: string, options: {
|
|
|
22
23
|
allowedTools?: readonly string[];
|
|
23
24
|
maxSteps?: number;
|
|
24
25
|
abortSignal?: AbortSignal;
|
|
26
|
+
session?: PromptSession;
|
|
25
27
|
}): Promise<SubagentResult>;
|
|
26
28
|
export declare function createSubagentTool(options: {
|
|
27
29
|
model: Parameters<typeof streamText>[0]['model'];
|
|
28
30
|
contextFiles: ContextFile[];
|
|
31
|
+
session?: PromptSession;
|
|
29
32
|
}): import("ai").Tool<{
|
|
30
33
|
task: string;
|
|
31
|
-
tools?: ("listFiles" | "editFile" | "replaceLines" | "writeFile" | "readFile" | "grep" | "bash")[] | undefined;
|
|
34
|
+
tools?: ("listFiles" | "editFile" | "replaceLines" | "writeFile" | "readFile" | "grep" | "bash" | "readToolOutput")[] | undefined;
|
|
32
35
|
maxSteps?: number | undefined;
|
|
33
36
|
}, SubagentResult>;
|
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
import { streamText, stepCountIs, tool } from 'ai';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
3
|
+
import { buildSubagentPrompt } from '../../llm/systemPrompt.js';
|
|
4
4
|
import { hazeTools } from '../../llm/hazeTools.js';
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
Rules:
|
|
8
|
-
- Use whatever tools you need within the assigned scope. You have full access to file tools and bash.
|
|
9
|
-
- If the task requires creating or modifying files, do it directly with file tools or an efficient non-destructive shell command; do not ask for permission for ordinary edits.
|
|
10
|
-
- Assume expert users understand what they asked for. Do not ask for command confirmations; run relevant commands directly.
|
|
11
|
-
- Destructive and ordinary professional workflows should proceed without extra ceremony when they are relevant to the assigned task.
|
|
12
|
-
- If a file edit tool fails, read the exact file again and retry once with current content or line numbers.
|
|
13
|
-
- After completing the task, summarize what you did, what files you created or changed, validation run, and important findings.
|
|
14
|
-
- If you cannot complete the task, explain exactly what blocked you and what you tried.
|
|
15
|
-
- Your summary is all the parent agent will see. Be specific: include file paths, function names, command results, and concrete next steps.`;
|
|
16
|
-
const ALL_TOOLS = ['listFiles', 'readFile', 'grep', 'bash', 'editFile', 'replaceLines', 'writeFile'];
|
|
5
|
+
const ALL_TOOLS = ['listFiles', 'readFile', 'grep', 'bash', 'readToolOutput', 'editFile', 'replaceLines', 'writeFile'];
|
|
17
6
|
const STEP_LIMIT = 25;
|
|
18
7
|
const MAX_SUMMARY = 4000;
|
|
19
8
|
const TOOL_ONLY_LIMIT = 12;
|
|
@@ -59,7 +48,7 @@ export async function runSubagent(task, options) {
|
|
|
59
48
|
const result = streamText({
|
|
60
49
|
model: options.model,
|
|
61
50
|
maxOutputTokens: 4096,
|
|
62
|
-
system:
|
|
51
|
+
system: buildSubagentPrompt(options.contextFiles, options.session),
|
|
63
52
|
messages: [{ role: 'user', content: task }],
|
|
64
53
|
tools: scopedTools,
|
|
65
54
|
stopWhen: stepCountIs(maxSteps),
|
|
@@ -127,7 +116,7 @@ export function createSubagentTool(options) {
|
|
|
127
116
|
description: 'Spawn subagents to run independent tasks in parallel. ONLY use when a request clearly decomposes into 2+ independent subtasks that can run concurrently — spawn all of them in one step. Do NOT use for single tasks, sequential work, or anything that benefits from conversation context; do those directly instead. Subagents have no conversation history and return a summary.',
|
|
128
117
|
inputSchema: z.object({
|
|
129
118
|
task: z.string().min(1).describe('Clear, specific task for the subagent to complete.'),
|
|
130
|
-
tools: z.array(z.enum(['listFiles', 'readFile', 'grep', 'bash', 'editFile', 'replaceLines', 'writeFile'])).optional().describe('Tools the subagent can use. Defaults to all tools.
|
|
119
|
+
tools: z.array(z.enum(['listFiles', 'readFile', 'grep', 'bash', 'readToolOutput', 'editFile', 'replaceLines', 'writeFile'])).optional().describe('Tools the subagent can use. Defaults to all tools.'),
|
|
131
120
|
maxSteps: z.number().int().positive().max(50).optional().describe('Maximum tool-call rounds. Default 25.'),
|
|
132
121
|
}),
|
|
133
122
|
execute: async ({ task, tools, maxSteps }, context) => runSubagent(task, {
|
|
@@ -136,6 +125,7 @@ export function createSubagentTool(options) {
|
|
|
136
125
|
allowedTools: tools,
|
|
137
126
|
maxSteps,
|
|
138
127
|
abortSignal: context.abortSignal,
|
|
128
|
+
session: options.session,
|
|
139
129
|
}),
|
|
140
130
|
});
|
|
141
131
|
}
|
|
@@ -20,7 +20,6 @@ export function parseValidationOutput(input) {
|
|
|
20
20
|
const failedTests = [];
|
|
21
21
|
const failedFiles = [];
|
|
22
22
|
const kind = inferKind(input.command, input.classification);
|
|
23
|
-
const status = input.timedOut ? 'timed_out' : input.code === 0 ? 'passed' : input.code == null ? 'unknown' : 'failed';
|
|
24
23
|
for (const line of lines) {
|
|
25
24
|
const ts = line.match(/^(.+?\.(?:ts|tsx|js|jsx|mts|cts))\((\d+),(\d+)\):\s+(error|warning)\s+TS\d+:\s+(.+)$/);
|
|
26
25
|
if (ts) {
|
|
@@ -45,7 +44,7 @@ export function parseValidationOutput(input) {
|
|
|
45
44
|
const vitestFile = line.match(/^\s*(?:FAIL|FAILED|✓|✗|❯)?\s*([^\s]+\.(?:test|spec)\.(?:ts|tsx|js|jsx))/i);
|
|
46
45
|
if (vitestFile)
|
|
47
46
|
failedFiles.push(vitestFile[1] ?? '');
|
|
48
|
-
const testName = line.match(/^\s*(?:FAIL
|
|
47
|
+
const testName = line.match(/^\s*(?:FAIL|✗|×|●)\s+(.+)$/);
|
|
49
48
|
if (testName && !/^(FAIL|FAILED)\s+\S+\.(?:test|spec)\./i.test(line.trim()))
|
|
50
49
|
failedTests.push((testName[1] ?? '').trim());
|
|
51
50
|
const genericFile = line.match(/([^\s()]+\.(?:ts|tsx|js|jsx|mts|cts)):(\d+):(\d+)/);
|
|
@@ -59,6 +58,20 @@ export function parseValidationOutput(input) {
|
|
|
59
58
|
const uniqueTests = uniq(failedTests).slice(0, 10);
|
|
60
59
|
const diagCount = diagnostics.length;
|
|
61
60
|
const rawOutputTruncated = Boolean(input.stdoutTruncated || input.stderrTruncated);
|
|
61
|
+
// Pipes (e.g. `npm test | tail`) and process substitutions can mask a
|
|
62
|
+
// non-zero exit code behind the final command in the pipeline. Treat
|
|
63
|
+
// parsed failure evidence as authoritative over `code` so a green exit
|
|
64
|
+
// status does not override real failures the parser already found.
|
|
65
|
+
const hasFailureEvidence = uniqueTests.length > 0 || diagCount > 0;
|
|
66
|
+
const status = input.timedOut
|
|
67
|
+
? 'timed_out'
|
|
68
|
+
: hasFailureEvidence
|
|
69
|
+
? 'failed'
|
|
70
|
+
: input.code === 0
|
|
71
|
+
? 'passed'
|
|
72
|
+
: input.code == null
|
|
73
|
+
? 'unknown'
|
|
74
|
+
: 'failed';
|
|
62
75
|
let summaryText;
|
|
63
76
|
if (status === 'passed')
|
|
64
77
|
summaryText = `${kind} passed`;
|
package/dist/llm/client.d.ts
CHANGED
|
@@ -1 +1,40 @@
|
|
|
1
|
+
export interface ProviderCapabilities {
|
|
2
|
+
reportsCacheUsage: boolean;
|
|
3
|
+
supportsPromptCacheKey: boolean;
|
|
4
|
+
supportsExtendedCacheRetention: boolean;
|
|
5
|
+
supportsStickySessionId: boolean;
|
|
6
|
+
supportsServerCompaction: boolean;
|
|
7
|
+
supportsTextVerbosity: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ModelRuntimeConfig {
|
|
10
|
+
providerName: string;
|
|
11
|
+
baseURL: string;
|
|
12
|
+
modelName: string;
|
|
13
|
+
cacheKey: string;
|
|
14
|
+
capabilities: ProviderCapabilities;
|
|
15
|
+
}
|
|
16
|
+
export declare function modelWithConfig(session?: {
|
|
17
|
+
cwd?: string;
|
|
18
|
+
}): Promise<{
|
|
19
|
+
model: import("@ai-sdk/provider").LanguageModelV3;
|
|
20
|
+
config: {
|
|
21
|
+
providerName: string;
|
|
22
|
+
baseURL: string;
|
|
23
|
+
modelName: string;
|
|
24
|
+
cacheKey: string;
|
|
25
|
+
capabilities: ProviderCapabilities;
|
|
26
|
+
};
|
|
27
|
+
}>;
|
|
1
28
|
export declare function model(): Promise<import("@ai-sdk/provider").LanguageModelV3>;
|
|
29
|
+
export declare function cacheKeyFor(name: string, cwd?: string): string;
|
|
30
|
+
export declare function providerRequestSettings(config: ModelRuntimeConfig): {
|
|
31
|
+
headers?: {
|
|
32
|
+
'x-session-id': string;
|
|
33
|
+
} | undefined;
|
|
34
|
+
providerOptions?: {
|
|
35
|
+
openai: {
|
|
36
|
+
textVerbosity?: "low" | undefined;
|
|
37
|
+
promptCacheKey?: string | undefined;
|
|
38
|
+
};
|
|
39
|
+
} | undefined;
|
|
40
|
+
};
|
package/dist/llm/client.js
CHANGED
|
@@ -1,11 +1,55 @@
|
|
|
1
1
|
import { createOpenAI } from '@ai-sdk/openai';
|
|
2
|
+
import crypto from 'node:crypto';
|
|
2
3
|
import { readSettings } from '../config/settings.js';
|
|
3
4
|
import { activeModel } from '../config/providers.js';
|
|
4
|
-
|
|
5
|
+
function capabilities(providerName, baseURL) {
|
|
6
|
+
const directOpenAI = providerName === 'openai' || /api\.openai\.com/i.test(baseURL);
|
|
7
|
+
const openRouter = providerName === 'openrouter' || /openrouter\.ai/i.test(baseURL);
|
|
8
|
+
return {
|
|
9
|
+
reportsCacheUsage: directOpenAI || openRouter,
|
|
10
|
+
supportsPromptCacheKey: directOpenAI,
|
|
11
|
+
supportsExtendedCacheRetention: false,
|
|
12
|
+
supportsStickySessionId: openRouter,
|
|
13
|
+
supportsServerCompaction: false,
|
|
14
|
+
supportsTextVerbosity: directOpenAI,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export async function modelWithConfig(session) {
|
|
5
18
|
const settings = await readSettings();
|
|
6
19
|
const selection = activeModel(settings);
|
|
7
20
|
const baseURL = process.env.OPENAI_BASE_URL ?? selection.provider.url;
|
|
8
21
|
const apiKey = process.env.OPENAI_API_KEY ?? selection.provider.key ?? settings.apiKey ?? 'not-needed';
|
|
9
22
|
const name = process.env.HAZE_MODEL ?? selection.model;
|
|
10
|
-
|
|
23
|
+
const cacheSeed = session?.cwd ?? process.cwd();
|
|
24
|
+
const cacheKey = crypto.createHash('sha256').update(`${cacheSeed}\0${name}`).digest('hex').slice(0, 32);
|
|
25
|
+
return {
|
|
26
|
+
model: createOpenAI({ apiKey, baseURL }).chat(name),
|
|
27
|
+
config: {
|
|
28
|
+
providerName: selection.provider.name,
|
|
29
|
+
baseURL,
|
|
30
|
+
modelName: name,
|
|
31
|
+
cacheKey,
|
|
32
|
+
capabilities: capabilities(selection.provider.name, baseURL),
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export async function model() {
|
|
37
|
+
return (await modelWithConfig()).model;
|
|
38
|
+
}
|
|
39
|
+
export function cacheKeyFor(name, cwd) {
|
|
40
|
+
const seed = cwd ?? process.cwd();
|
|
41
|
+
return crypto.createHash('sha256').update(`${seed}\0${name}`).digest('hex').slice(0, 32);
|
|
42
|
+
}
|
|
43
|
+
export function providerRequestSettings(config) {
|
|
44
|
+
return {
|
|
45
|
+
...(config.capabilities.supportsPromptCacheKey || config.capabilities.supportsTextVerbosity ? {
|
|
46
|
+
providerOptions: {
|
|
47
|
+
openai: {
|
|
48
|
+
...(config.capabilities.supportsPromptCacheKey ? { promptCacheKey: config.cacheKey } : {}),
|
|
49
|
+
...(config.capabilities.supportsTextVerbosity ? { textVerbosity: 'low' } : {}),
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
} : {}),
|
|
53
|
+
...(config.capabilities.supportsStickySessionId ? { headers: { 'x-session-id': config.cacheKey } } : {}),
|
|
54
|
+
};
|
|
11
55
|
}
|
package/dist/llm/hazeTools.d.ts
CHANGED
|
@@ -56,23 +56,14 @@ export declare const hazeTools: {
|
|
|
56
56
|
toolName: string;
|
|
57
57
|
reason: string;
|
|
58
58
|
} | {
|
|
59
|
-
text: string;
|
|
60
|
-
truncated: boolean;
|
|
61
|
-
omittedChars?: undefined;
|
|
62
59
|
path: string;
|
|
63
60
|
startLine: number;
|
|
64
61
|
endLine: number;
|
|
65
62
|
totalLines: number;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
text: string;
|
|
63
|
+
content: string;
|
|
64
|
+
nextOffset: number | undefined;
|
|
69
65
|
truncated: boolean;
|
|
70
|
-
|
|
71
|
-
path: string;
|
|
72
|
-
startLine: number;
|
|
73
|
-
endLine: number;
|
|
74
|
-
totalLines: number;
|
|
75
|
-
lineNumberedText: string;
|
|
66
|
+
lineTruncated: boolean;
|
|
76
67
|
}>;
|
|
77
68
|
grep: import("ai").Tool<{
|
|
78
69
|
pattern: string;
|
|
@@ -96,6 +87,17 @@ export declare const hazeTools: {
|
|
|
96
87
|
duplicateSkipped: true;
|
|
97
88
|
toolName: string;
|
|
98
89
|
reason: string;
|
|
90
|
+
} | {
|
|
91
|
+
pattern: string;
|
|
92
|
+
path: string;
|
|
93
|
+
glob: string | null;
|
|
94
|
+
caseInsensitive: boolean;
|
|
95
|
+
matches: never[];
|
|
96
|
+
totalMatches: number;
|
|
97
|
+
truncated: boolean;
|
|
98
|
+
returnedMatches?: undefined;
|
|
99
|
+
omittedMatches?: undefined;
|
|
100
|
+
suggestion?: undefined;
|
|
99
101
|
} | {
|
|
100
102
|
pattern: string;
|
|
101
103
|
path: string;
|
|
@@ -108,7 +110,10 @@ export declare const hazeTools: {
|
|
|
108
110
|
isContext: boolean;
|
|
109
111
|
}[];
|
|
110
112
|
totalMatches: number;
|
|
113
|
+
returnedMatches: number;
|
|
114
|
+
omittedMatches: number;
|
|
111
115
|
truncated: boolean;
|
|
116
|
+
suggestion: string | undefined;
|
|
112
117
|
}>;
|
|
113
118
|
replaceLines: import("ai").Tool<{
|
|
114
119
|
path: string;
|
|
@@ -213,11 +218,31 @@ export declare const hazeTools: {
|
|
|
213
218
|
error: string;
|
|
214
219
|
taskCount?: undefined;
|
|
215
220
|
summary?: undefined;
|
|
221
|
+
counts?: undefined;
|
|
216
222
|
} | {
|
|
217
223
|
ok: boolean;
|
|
218
224
|
taskCount: number;
|
|
219
225
|
summary: string;
|
|
220
226
|
error?: undefined;
|
|
227
|
+
counts?: undefined;
|
|
228
|
+
} | {
|
|
229
|
+
ok: boolean;
|
|
230
|
+
taskCount: number;
|
|
231
|
+
counts: {
|
|
232
|
+
pending: number;
|
|
233
|
+
in_progress: number;
|
|
234
|
+
completed: number;
|
|
235
|
+
};
|
|
236
|
+
summary: string;
|
|
237
|
+
error?: undefined;
|
|
238
|
+
}>;
|
|
239
|
+
readToolOutput: import("ai").Tool<{
|
|
240
|
+
handle: string;
|
|
241
|
+
offset: number;
|
|
242
|
+
limit: number;
|
|
243
|
+
}, import("../core/agent/toolOutputStore.js").StoredToolOutputPage | {
|
|
244
|
+
ok: boolean;
|
|
245
|
+
error: string;
|
|
221
246
|
}>;
|
|
222
247
|
bash: import("ai").Tool<{
|
|
223
248
|
command: string;
|