@denizokcu/haze 1.7.10 → 1.7.12
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 +25 -0
- package/README.md +125 -99
- package/assets/graph-grammars/NOTICE.md +21 -0
- package/assets/graph-grammars/tree-sitter-javascript.wasm +0 -0
- package/assets/graph-grammars/tree-sitter-tsx.wasm +0 -0
- package/assets/graph-grammars/tree-sitter-typescript.wasm +0 -0
- package/assets/graph-grammars/web-tree-sitter.cjs +4116 -0
- package/assets/graph-grammars/web-tree-sitter.cjs.map +7 -0
- package/assets/graph-grammars/web-tree-sitter.js +4056 -0
- package/assets/graph-grammars/web-tree-sitter.js.map +7 -0
- package/assets/graph-grammars/web-tree-sitter.wasm +0 -0
- package/assets/graph-grammars/web-tree-sitter.wasm.map +55 -0
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/BusyBar.d.ts +2 -1
- package/dist/cli/chat/BusyBar.js +2 -2
- package/dist/cli/chat/chatMetrics.d.ts +25 -0
- package/dist/cli/chat/chatMetrics.js +36 -0
- package/dist/cli/chat/inputSuggestions.js +1 -0
- package/dist/cli/chat/sessionLifecycle.d.ts +2 -0
- package/dist/cli/chat/sessionLifecycle.js +29 -19
- package/dist/cli/chat/sessionRecorder.d.ts +2 -1
- package/dist/cli/chat/sessionRecorder.js +29 -9
- package/dist/cli/chat/startupSequence.d.ts +2 -0
- package/dist/cli/chat/startupSequence.js +6 -0
- package/dist/cli/chat/transcriptPartition.js +10 -4
- package/dist/cli/chat/wizard/providerHandlers.js +57 -9
- package/dist/cli/chat/wizard/sessionThemeHandlers.js +5 -1
- package/dist/cli/commands/chat.js +44 -9
- package/dist/cli/commands/commandHelp.js +6 -3
- package/dist/cli/commands/commands.js +2 -0
- package/dist/cli/commands/formatters.js +28 -0
- package/dist/cli/commands/graphCommand.d.ts +2 -0
- package/dist/cli/commands/graphCommand.js +60 -0
- package/dist/cli/commands/initCommand.js +14 -0
- package/dist/cli/commands/providerWizard.js +9 -17
- package/dist/cli/commands/reasoningCommand.d.ts +1 -0
- package/dist/cli/commands/reasoningCommand.js +32 -4
- package/dist/cli/commands/runCommand.js +7 -1
- package/dist/cli/commands/streaming/agentAttempt.js +11 -1
- package/dist/cli/commands/streaming/attemptLifecycle.js +1 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +6 -2
- package/dist/cli/commands/streaming/attemptSetup.d.ts +3 -0
- package/dist/cli/commands/streaming/attemptSetup.js +13 -6
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +1 -1
- package/dist/cli/commands/streaming/goalSupervisor.js +22 -1
- package/dist/cli/commands/streaming/prepareStep.js +1 -0
- package/dist/cli/commands/streaming/streamLoop.d.ts +2 -0
- package/dist/cli/commands/streaming/streamLoop.js +14 -10
- package/dist/cli/commands/streaming/toolPartHandlers.js +7 -1
- package/dist/cli/commands/streaming.d.ts +2 -0
- package/dist/cli/commands/streaming.js +5 -0
- package/dist/cli/commands/wizardFlow.d.ts +1 -0
- package/dist/cli/commands/wizardFlow.js +10 -4
- package/dist/cli/index.js +5 -3
- package/dist/config/hazeBuild.d.ts +2 -2
- package/dist/config/hazeBuild.js +2 -2
- package/dist/config/modelDiscovery.d.ts +1 -1
- package/dist/config/modelDiscovery.js +8 -8
- package/dist/config/{modelCatalog.d.ts → providerModelFacts.d.ts} +13 -2
- package/dist/config/{modelCatalog.js → providerModelFacts.js} +145 -21
- package/dist/config/providerPresets.d.ts +8 -19
- package/dist/config/providerPresets.js +86 -555
- package/dist/config/providerReasoning.d.ts +16 -0
- package/dist/config/providerReasoning.js +56 -0
- package/dist/config/providers.d.ts +4 -0
- package/dist/config/providers.js +19 -2
- package/dist/config/settings.d.ts +14 -0
- package/dist/config/settings.js +5 -0
- package/dist/core/agent/compaction.d.ts +1 -0
- package/dist/core/agent/compaction.js +3 -0
- package/dist/core/agent/events.d.ts +1 -1
- package/dist/core/agent/providerTransition.d.ts +8 -0
- package/dist/core/agent/providerTransition.js +47 -0
- package/dist/core/agent/reasoningPolicy.d.ts +1 -1
- package/dist/core/agent/reasoningPolicy.js +4 -2
- package/dist/core/graph/analyze.d.ts +61 -0
- package/dist/core/graph/analyze.js +274 -0
- package/dist/core/graph/buildGraph.d.ts +44 -0
- package/dist/core/graph/buildGraph.js +290 -0
- package/dist/core/graph/digest.d.ts +2 -0
- package/dist/core/graph/digest.js +40 -0
- package/dist/core/graph/extract.d.ts +58 -0
- package/dist/core/graph/extract.js +394 -0
- package/dist/core/graph/model.d.ts +63 -0
- package/dist/core/graph/model.js +96 -0
- package/dist/core/graph/query.d.ts +69 -0
- package/dist/core/graph/query.js +391 -0
- package/dist/core/graph/store.d.ts +64 -0
- package/dist/core/graph/store.js +171 -0
- package/dist/core/limits.d.ts +0 -2
- package/dist/core/limits.js +0 -2
- package/dist/core/process/runBoundedProcess.js +12 -6
- package/dist/core/providerContracts.d.ts +9 -8
- package/dist/core/providerContracts.js +21 -1
- package/dist/core/safety/redaction.js +12 -2
- package/dist/core/safety/untrustedEnvelopes.d.ts +6 -0
- package/dist/core/safety/untrustedEnvelopes.js +17 -2
- package/dist/core/session/sessionSlimming.js +5 -59
- package/dist/core/session/sessionStore.d.ts +4 -0
- package/dist/core/session/sessionStore.js +149 -9
- package/dist/core/session/snapshotCodec.d.ts +5 -0
- package/dist/core/session/snapshotCodec.js +47 -0
- package/dist/core/shellOutput/registry.js +2 -46
- package/dist/core/subagent/executionProfiles.js +8 -5
- package/dist/core/tasks/taskStorage.js +11 -1
- package/dist/core/toolOutput/reduction.d.ts +55 -2
- package/dist/core/toolOutput/reduction.js +77 -2
- package/dist/core/validation/outputParser.js +16 -8
- package/dist/llm/client.d.ts +4 -2
- package/dist/llm/client.js +104 -55
- package/dist/llm/hazeTools.d.ts +2 -12426
- package/dist/llm/hazeTools.js +2 -0
- package/dist/llm/lspTools.d.ts +3 -12622
- package/dist/llm/mistralReasoning.d.ts +2 -0
- package/dist/llm/mistralReasoning.js +17 -0
- package/dist/llm/mistralVibeAuth.d.ts +5 -0
- package/dist/llm/mistralVibeAuth.js +63 -0
- package/dist/llm/requestContext.d.ts +3 -0
- package/dist/llm/requestContext.js +21 -11
- package/dist/llm/subagentRunner.d.ts +2 -308
- package/dist/llm/subagentRunner.js +15 -7
- package/dist/llm/systemPrompt.js +7 -4
- package/dist/llm/toolResultTypes.d.ts +1 -1
- package/dist/llm/toolResultTypes.js +7 -1
- package/dist/llm/tools/fetchTool.d.ts +2 -1221
- package/dist/llm/tools/fileTools.d.ts +2 -7768
- package/dist/llm/tools/graphAdvisory.d.ts +22 -0
- package/dist/llm/tools/graphAdvisory.js +68 -0
- package/dist/llm/tools/graphTools.d.ts +13 -0
- package/dist/llm/tools/graphTools.js +195 -0
- package/dist/llm/tools/outputCap.d.ts +2 -7
- package/dist/llm/tools/outputCap.js +3 -11
- package/dist/llm/tools/processTool.d.ts +2 -1081
- package/dist/llm/tools/replaceInFiles.js +5 -0
- package/dist/llm/tools/shellTool.d.ts +2 -1513
- package/dist/llm/tools/storedOutputTool.d.ts +2 -355
- package/dist/llm/tools/taskTool.d.ts +2 -489
- package/dist/llm/tools/toolContext.js +24 -9
- package/dist/llm/tools/toolContextState.d.ts +3 -0
- package/dist/llm/tools/toolContextState.js +2 -1
- package/dist/skills/skillTools.js +4 -1
- package/package.json +24 -15
|
@@ -9,7 +9,60 @@ export interface ReductionMetrics {
|
|
|
9
9
|
estimatedSavedTokens: number;
|
|
10
10
|
savingsPct: number;
|
|
11
11
|
}
|
|
12
|
+
export interface StreamReduction {
|
|
13
|
+
text: string;
|
|
14
|
+
truncated: boolean;
|
|
15
|
+
filtered: boolean;
|
|
16
|
+
reducerName?: string;
|
|
17
|
+
filterName?: string;
|
|
18
|
+
contentKind: ReductionContentKind;
|
|
19
|
+
lossy: boolean;
|
|
20
|
+
parseTier: ReductionParseTier;
|
|
21
|
+
warning?: string;
|
|
22
|
+
handle?: string;
|
|
23
|
+
rawHandle?: string;
|
|
24
|
+
omittedChars: number;
|
|
25
|
+
rawChars: number;
|
|
26
|
+
returnedChars: number;
|
|
27
|
+
rawTokensEstimate: number;
|
|
28
|
+
returnedTokensEstimate: number;
|
|
29
|
+
estimatedSavedTokens: number;
|
|
30
|
+
savingsPct: number;
|
|
31
|
+
}
|
|
12
32
|
export declare function capOutputForProcessing(text: string, maxChars?: number): string;
|
|
13
33
|
export declare function reductionMetrics(raw: string, returned: string): ReductionMetrics;
|
|
14
|
-
|
|
15
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Compact output for storage, keeping head + tail and storing the full text behind a handle.
|
|
36
|
+
*/
|
|
37
|
+
export declare function compactOutput(text: string, maxChars: number, storeRawOutput?: (text: string) => string): {
|
|
38
|
+
text: string;
|
|
39
|
+
truncated: boolean;
|
|
40
|
+
handle?: string;
|
|
41
|
+
omittedChars?: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Create a stream reduction result for shell output.
|
|
45
|
+
*/
|
|
46
|
+
export declare function makeStreamReduction(raw: string, text: string, filtered: boolean, reducerName: string | undefined, input: {
|
|
47
|
+
storeRawOutput?: (text: string) => string;
|
|
48
|
+
compactMaxChars: number;
|
|
49
|
+
fallbackCompact?: (text: string, maxChars: number) => {
|
|
50
|
+
text: string;
|
|
51
|
+
truncated: boolean;
|
|
52
|
+
handle?: string;
|
|
53
|
+
omittedChars?: number;
|
|
54
|
+
};
|
|
55
|
+
}, warning?: string, contentKind?: ReductionContentKind): StreamReduction;
|
|
56
|
+
/**
|
|
57
|
+
* Fallback reduction for passthrough output.
|
|
58
|
+
*/
|
|
59
|
+
export declare function passthroughReduction(raw: string, input: {
|
|
60
|
+
storeRawOutput?: (text: string) => string;
|
|
61
|
+
compactMaxChars: number;
|
|
62
|
+
fallbackCompact?: (text: string, maxChars: number) => {
|
|
63
|
+
text: string;
|
|
64
|
+
truncated: boolean;
|
|
65
|
+
handle?: string;
|
|
66
|
+
omittedChars?: number;
|
|
67
|
+
};
|
|
68
|
+
}): StreamReduction;
|
|
@@ -27,9 +27,84 @@ export function reductionMetrics(raw, returned) {
|
|
|
27
27
|
savingsPct,
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
function retrievalHint(handle) {
|
|
31
31
|
return `Use readToolOutput with handle ${handle} for the original output.`;
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
function isInflating(raw, returned) {
|
|
34
34
|
return raw.trim().length > 0 && returned.length > raw.length;
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Compact output for storage, keeping head + tail and storing the full text behind a handle.
|
|
38
|
+
*/
|
|
39
|
+
export function compactOutput(text, maxChars, storeRawOutput) {
|
|
40
|
+
if (text.length <= maxChars)
|
|
41
|
+
return { text, truncated: false };
|
|
42
|
+
const handle = storeRawOutput?.(text);
|
|
43
|
+
const headChars = Math.floor(maxChars * 0.4);
|
|
44
|
+
const tailChars = maxChars - headChars;
|
|
45
|
+
const omitted = text.length - maxChars;
|
|
46
|
+
return {
|
|
47
|
+
text: `${text.slice(0, headChars)}\n\n[... ${omitted} characters omitted${handle ? `; use readToolOutput with handle ${handle}` : ''} ...]\n\n${text.slice(-tailChars)}`,
|
|
48
|
+
truncated: true,
|
|
49
|
+
omittedChars: omitted,
|
|
50
|
+
handle,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create a stream reduction result for shell output.
|
|
55
|
+
*/
|
|
56
|
+
export function makeStreamReduction(raw, text, filtered, reducerName, input, warning, contentKind = 'generic') {
|
|
57
|
+
let finalText = text;
|
|
58
|
+
let handle;
|
|
59
|
+
let truncated = false;
|
|
60
|
+
const compactFn = input.fallbackCompact ?? ((value, max) => compactOutput(value, max, input.storeRawOutput));
|
|
61
|
+
if (finalText.length > input.compactMaxChars) {
|
|
62
|
+
const compacted = compactFn(finalText, input.compactMaxChars);
|
|
63
|
+
finalText = compacted.text;
|
|
64
|
+
handle = compacted.handle;
|
|
65
|
+
truncated = compacted.truncated;
|
|
66
|
+
}
|
|
67
|
+
const lossy = filtered && finalText !== raw;
|
|
68
|
+
const rawHandle = lossy && input.storeRawOutput ? input.storeRawOutput(raw) : handle;
|
|
69
|
+
if (filtered && contentKind !== 'validation' && raw.length > 2000 && isInflating(raw, finalText)) {
|
|
70
|
+
return passthroughReduction(raw, input);
|
|
71
|
+
}
|
|
72
|
+
if (lossy && rawHandle && !finalText.includes(rawHandle)) {
|
|
73
|
+
finalText = `${finalText}\n\n[${retrievalHint(rawHandle)}]`;
|
|
74
|
+
}
|
|
75
|
+
const metrics = reductionMetrics(raw, finalText);
|
|
76
|
+
return {
|
|
77
|
+
text: finalText,
|
|
78
|
+
truncated,
|
|
79
|
+
filtered,
|
|
80
|
+
...(reducerName ? { reducerName, filterName: reducerName } : {}),
|
|
81
|
+
contentKind,
|
|
82
|
+
lossy,
|
|
83
|
+
parseTier: warning ? 'degraded' : filtered ? 'full' : 'passthrough',
|
|
84
|
+
...(warning ? { warning } : {}),
|
|
85
|
+
...(handle ?? rawHandle ? { handle: handle ?? rawHandle } : {}),
|
|
86
|
+
...(rawHandle ? { rawHandle } : {}),
|
|
87
|
+
omittedChars: Math.max(0, raw.length - finalText.length),
|
|
88
|
+
...metrics,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Fallback reduction for passthrough output.
|
|
93
|
+
*/
|
|
94
|
+
export function passthroughReduction(raw, input) {
|
|
95
|
+
const compactFn = input.fallbackCompact ?? ((value, max) => compactOutput(value, max, input.storeRawOutput));
|
|
96
|
+
const compacted = compactFn(raw, input.compactMaxChars);
|
|
97
|
+
const metrics = reductionMetrics(raw, compacted.text);
|
|
98
|
+
return {
|
|
99
|
+
text: compacted.text,
|
|
100
|
+
truncated: compacted.truncated,
|
|
101
|
+
filtered: false,
|
|
102
|
+
reducerName: 'generic-cap',
|
|
103
|
+
contentKind: 'generic',
|
|
104
|
+
lossy: compacted.truncated,
|
|
105
|
+
parseTier: 'passthrough',
|
|
106
|
+
...(compacted.handle ? { handle: compacted.handle, rawHandle: compacted.handle } : {}),
|
|
107
|
+
omittedChars: compacted.omittedChars ?? Math.max(0, raw.length - compacted.text.length),
|
|
108
|
+
...metrics,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -36,14 +36,17 @@ export function parseValidationOutput(input) {
|
|
|
36
36
|
if (ts) {
|
|
37
37
|
const [, file, lineNo, column, severity, message] = ts;
|
|
38
38
|
diagnostics.push({ file, line: Number(lineNo), column: Number(column), severity: severity === 'warning' ? 'warning' : 'error', message: message ?? '' });
|
|
39
|
-
|
|
39
|
+
if (severity !== 'warning')
|
|
40
|
+
failedFiles.push(file ?? '');
|
|
40
41
|
continue;
|
|
41
42
|
}
|
|
42
43
|
const eslint = line.match(/^(.+?\.(?:ts|tsx|js|jsx|mts|cts))\s*$/);
|
|
43
44
|
if (eslint) {
|
|
44
45
|
const currentFile = eslint[1] ?? '';
|
|
45
46
|
const next = lines[index + 1];
|
|
46
|
-
|
|
47
|
+
// Only error-severity follow-up lines make this a failed file; a
|
|
48
|
+
// warnings-only run must not populate `failedFiles`.
|
|
49
|
+
if (next && /^\s*\d+:\d+\s+error\s/.test(next))
|
|
47
50
|
failedFiles.push(currentFile);
|
|
48
51
|
}
|
|
49
52
|
const eslintDiag = line.match(/^\s*(\d+):(\d+)\s+(error|warning)\s+(.+?)(?:\s{2,}\S+)?$/);
|
|
@@ -52,7 +55,7 @@ export function parseValidationOutput(input) {
|
|
|
52
55
|
diagnostics.push({ line: Number(lineNo), column: Number(column), severity: severity === 'warning' ? 'warning' : 'error', message: message ?? '' });
|
|
53
56
|
continue;
|
|
54
57
|
}
|
|
55
|
-
const vitestFile = line.match(/^\s*(?:FAIL|FAILED
|
|
58
|
+
const vitestFile = line.match(/^\s*(?:FAIL|FAILED|✗|❯)?\s*([^\s]+\.(?:test|spec)\.(?:ts|tsx|js|jsx))/i);
|
|
56
59
|
if (vitestFile)
|
|
57
60
|
failedFiles.push(vitestFile[1] ?? '');
|
|
58
61
|
const testName = line.match(/^\s*(?:FAIL|✗|×|●)\s+(.+)$/);
|
|
@@ -61,19 +64,24 @@ export function parseValidationOutput(input) {
|
|
|
61
64
|
const genericFile = line.match(/([^\s()]+\.(?:ts|tsx|js|jsx|mts|cts)):(\d+):(\d+)/);
|
|
62
65
|
if (genericFile) {
|
|
63
66
|
const [, file, lineNo, column] = genericFile;
|
|
64
|
-
|
|
65
|
-
diagnostics.push({ file, line: Number(lineNo), column: Number(column), severity
|
|
67
|
+
const severity = /warn/i.test(line) ? 'warning' : 'error';
|
|
68
|
+
diagnostics.push({ file, line: Number(lineNo), column: Number(column), severity, message: line.trim() });
|
|
69
|
+
if (severity === 'error')
|
|
70
|
+
failedFiles.push(file ?? '');
|
|
66
71
|
}
|
|
67
72
|
}
|
|
68
73
|
const uniqueFiles = uniq(failedFiles).slice(0, 10);
|
|
69
74
|
const uniqueTests = uniq(failedTests).slice(0, 10);
|
|
70
75
|
const diagCount = diagnostics.length;
|
|
76
|
+
const errorDiagCount = diagnostics.filter(diagnostic => diagnostic.severity === 'error').length;
|
|
71
77
|
const rawOutputTruncated = Boolean(input.stdoutTruncated || input.stderrTruncated);
|
|
72
78
|
// Pipes (e.g. `npm test | tail`) and process substitutions can mask a
|
|
73
79
|
// non-zero exit code behind the final command in the pipeline. Treat
|
|
74
|
-
// parsed failure evidence as authoritative over `code` so a green exit
|
|
75
|
-
// status does not override real failures the parser already found.
|
|
76
|
-
|
|
80
|
+
// parsed *failure* evidence as authoritative over `code` so a green exit
|
|
81
|
+
// status does not override real failures the parser already found. Only
|
|
82
|
+
// error-severity diagnostics and failed tests count: warning diagnostics
|
|
83
|
+
// never fail an otherwise-green run (ESLint exits 0 on warnings only).
|
|
84
|
+
const hasFailureEvidence = uniqueTests.length > 0 || errorDiagCount > 0;
|
|
77
85
|
const status = input.timedOut
|
|
78
86
|
? 'timed_out'
|
|
79
87
|
: hasFailureEvidence
|
package/dist/llm/client.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface ModelRuntimeConfig {
|
|
|
13
13
|
providerName: string;
|
|
14
14
|
providerKind?: HazeProviderSettings['kind'];
|
|
15
15
|
baseURL: string;
|
|
16
|
+
isLocal?: boolean;
|
|
16
17
|
modelName: string;
|
|
17
18
|
cacheKey: string;
|
|
18
19
|
capabilities: ProviderCapabilities;
|
|
@@ -24,8 +25,8 @@ export interface ModelRuntimeConfig {
|
|
|
24
25
|
* (128K hosted / 32K local) so `contextWindowSource` can flag the guess.
|
|
25
26
|
*/
|
|
26
27
|
contextWindowTokens: number;
|
|
27
|
-
/** Where
|
|
28
|
-
contextWindowSource: 'settings' | 'catalog' | 'user-fallback' | 'default-fallback' | 'deployment';
|
|
28
|
+
/** Where the context window came from. */
|
|
29
|
+
contextWindowSource: 'settings' | 'discovery' | 'preset' | 'catalog' | 'user-fallback' | 'default-fallback' | 'deployment';
|
|
29
30
|
deployment?: HazeBuildManifest;
|
|
30
31
|
warnings?: string[];
|
|
31
32
|
/** Optional output-token limit metadata for request budgeting (RH-005). */
|
|
@@ -33,6 +34,7 @@ export interface ModelRuntimeConfig {
|
|
|
33
34
|
}
|
|
34
35
|
/** True for loopback/local inference servers, whose effective window is server-configured (often far below the model's). */
|
|
35
36
|
export declare function isLocalProviderUrl(url: string): boolean;
|
|
37
|
+
export declare function isLocalProvider(provider: Pick<HazeProviderSettings, 'url' | 'location'>): boolean;
|
|
36
38
|
export declare function modelWithConfig(session?: {
|
|
37
39
|
cwd?: string;
|
|
38
40
|
modelSelector?: string;
|
package/dist/llm/client.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { createOpenAI } from '@ai-sdk/openai';
|
|
2
2
|
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
|
3
|
+
import { createOpenRouter } from '@openrouter/ai-sdk-provider';
|
|
3
4
|
import { discoverHazeBuildManifest } from '../config/hazeBuild.js';
|
|
4
5
|
import { createHazeBuildModel } from './hazeBuild.js';
|
|
6
|
+
import { isMistralApi, reasoningLevelsForProvider, resolveProviderReasoning } from '../config/providerReasoning.js';
|
|
7
|
+
import { mistralRequestBody } from './mistralReasoning.js';
|
|
5
8
|
import crypto from 'node:crypto';
|
|
9
|
+
import { isIP } from 'node:net';
|
|
6
10
|
import { readSettings } from '../config/settings.js';
|
|
7
|
-
import { catalogLimitsFor } from '../config/
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
+
import { catalogLimitsFor } from '../config/providerModelFacts.js';
|
|
12
|
+
import { ollamaModelLimits } from '../config/modelDiscovery.js';
|
|
13
|
+
import { presetModelLimitsForModels } from '../config/providerPresets.js';
|
|
14
|
+
import { activeModel, modelSelector, providerApiKey, resolveModelSelector } from '../config/providers.js';
|
|
15
|
+
import { assertCredentialedEndpointSecure, isLoopbackHostname } from '../config/endpointSecurity.js';
|
|
16
|
+
import { effectiveRequestedReasoning, isStoredReasoning, reasoningCallSetting, resolveAttemptReasoning, REASONING_LEVELS } from '../core/agent/reasoningPolicy.js';
|
|
11
17
|
import { FALLBACK_CONTEXT_WINDOW_TOKENS, FALLBACK_LOCAL_CONTEXT_TOKENS } from '../core/agent/contextBudget.js';
|
|
12
18
|
import { createChatGptCodexFetch } from './openaiCodex.js';
|
|
13
19
|
const HAZE_SITE_URL = 'https://github.com/DenizOkcu/haze';
|
|
@@ -16,8 +22,24 @@ const HAZE_TITLE = 'Haze';
|
|
|
16
22
|
// replaces authentication. Generate a non-credential sentinel at runtime so
|
|
17
23
|
// static scanners cannot mistake a fixed placeholder for a shipped secret.
|
|
18
24
|
const OAUTH_SDK_SENTINEL = `oauth-sentinel-${crypto.randomUUID()}`;
|
|
19
|
-
function isOpenRouter(
|
|
20
|
-
|
|
25
|
+
function isOpenRouter(_providerName, baseURL) {
|
|
26
|
+
try {
|
|
27
|
+
return new URL(baseURL).hostname.toLowerCase() === 'openrouter.ai';
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** Groq Qwen requires parsed reasoning when tools are present. */
|
|
34
|
+
function groqRequestTransform(baseURL, model) {
|
|
35
|
+
try {
|
|
36
|
+
if (new URL(baseURL).hostname.toLowerCase() !== 'api.groq.com' || model.toLowerCase() !== 'qwen/qwen3.8-27b')
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
return body => Array.isArray(body.tools) && body.tools.length ? { ...body, reasoning_format: 'parsed' } : body;
|
|
21
43
|
}
|
|
22
44
|
function openRouterHeaders(providerName, baseURL) {
|
|
23
45
|
if (!isOpenRouter(providerName, baseURL))
|
|
@@ -28,19 +50,21 @@ function openRouterHeaders(providerName, baseURL) {
|
|
|
28
50
|
};
|
|
29
51
|
}
|
|
30
52
|
/** True when the endpoint is OpenAI's own API, not a gateway/local server speaking the compatible subset. */
|
|
31
|
-
function isDirectOpenAi(
|
|
32
|
-
|
|
53
|
+
function isDirectOpenAi(_providerName, baseURL, providerKind) {
|
|
54
|
+
try {
|
|
55
|
+
return providerKind !== 'chatgpt-codex' && new URL(baseURL).hostname.toLowerCase() === 'api.openai.com';
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
33
60
|
}
|
|
34
|
-
function capabilities(
|
|
61
|
+
function capabilities(provider, modelName) {
|
|
62
|
+
const { name: providerName, url: baseURL, kind: providerKind } = provider;
|
|
35
63
|
const directOpenAI = isDirectOpenAi(providerName, baseURL, providerKind);
|
|
36
64
|
const openRouter = isOpenRouter(providerName, baseURL);
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// unsupported levels — even `none` — to `on` (LM Studio), inverting the
|
|
41
|
-
// request, and subagent workers rely on `none` meaning off. Hosted
|
|
42
|
-
// OpenAI-compatible endpoints keep the SDK pass-through (`true`).
|
|
43
|
-
const supportsReasoningEffort = explicit?.reasoningEffort ?? (providerKind === 'haze-build' || !isLocalProviderUrl(baseURL));
|
|
65
|
+
// The same profile drives UI choices, main requests, and worker defaults.
|
|
66
|
+
const levels = reasoningLevelsForProvider(provider, modelName);
|
|
67
|
+
const supportsReasoningEffort = levels.length > 0;
|
|
44
68
|
return {
|
|
45
69
|
reportsCacheUsage: providerKind === 'haze-build' || directOpenAI || openRouter,
|
|
46
70
|
supportsPromptCacheKey: directOpenAI,
|
|
@@ -49,45 +73,40 @@ function capabilities(providerName, baseURL, providerKind, explicit) {
|
|
|
49
73
|
supportsServerCompaction: false,
|
|
50
74
|
supportsTextVerbosity: directOpenAI,
|
|
51
75
|
supportsReasoningEffort,
|
|
76
|
+
...(openRouter ? { reasoningTransport: 'openrouter' } : {}),
|
|
77
|
+
...(supportsReasoningEffort && (!openRouter || provider.reasoningLevels || provider.modelReasoningLevels?.[modelName]) ? { workerReasoningEffort: REASONING_LEVELS.find(level => levels.includes(level)) } : {}),
|
|
52
78
|
...(providerKind === 'haze-build' ? { supportsBinaryThinking: true } : {}),
|
|
53
79
|
};
|
|
54
80
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Match the pinned OpenAI SDK's GPT-6+ effort restrictions before transport.
|
|
57
|
-
* Unsupported choices are omitted, not promoted to a different effort; the
|
|
58
|
-
* policy retains the request and explains why the provider default will apply.
|
|
59
|
-
*/
|
|
60
|
-
function reasoningPolicyForModel(modelName, requested, caps) {
|
|
61
|
-
const policy = resolveReasoningPolicy({ requested, capabilities: caps });
|
|
62
|
-
if (policy.effective === 'disabled')
|
|
63
|
-
return policy;
|
|
64
|
-
const version = /^gpt-(\d+)(?:\.\d+)?(?:-.+)?$/.exec(modelName);
|
|
65
|
-
const supportsNone = modelName === 'gpt-6-sol' || modelName === 'gpt-6-luna';
|
|
66
|
-
if (version && Number(version[1]) >= 6 && (requested === 'minimal' || (requested === 'none' && !supportsNone))) {
|
|
67
|
-
return { requested, effective: 'disabled', reason: `${modelName} does not support reasoning effort ${requested}; parameter omitted (provider default). Choose low, medium, high, xhigh, or unset.` };
|
|
68
|
-
}
|
|
69
|
-
return policy;
|
|
70
|
-
}
|
|
71
81
|
/** True for loopback/local inference servers, whose effective window is server-configured (often far below the model's). */
|
|
72
82
|
export function isLocalProviderUrl(url) {
|
|
73
83
|
try {
|
|
74
84
|
const hostname = new URL(url).hostname.toLowerCase().replace(/^\[|\]$/g, '');
|
|
75
|
-
|
|
85
|
+
if (isLoopbackHostname(hostname) || hostname === '0.0.0.0' || hostname.endsWith('.local'))
|
|
86
|
+
return true;
|
|
87
|
+
if (isIP(hostname) === 4) {
|
|
88
|
+
const [a, b] = hostname.split('.').map(Number);
|
|
89
|
+
return a === 10 || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168) || (a === 169 && b === 254);
|
|
90
|
+
}
|
|
91
|
+
return isIP(hostname) === 6 && /^(?:f[cd]|fe[89ab])/i.test(hostname);
|
|
76
92
|
}
|
|
77
93
|
catch {
|
|
78
94
|
return false;
|
|
79
95
|
}
|
|
80
96
|
}
|
|
81
|
-
function
|
|
97
|
+
export function isLocalProvider(provider) {
|
|
98
|
+
return provider.location ? provider.location === 'local' : isLocalProviderUrl(provider.url);
|
|
99
|
+
}
|
|
100
|
+
function runtimeForSelection(settings, selection, cwd, reasoningOverride, sessionReasoningByModel, deployment, freshLocalLimits) {
|
|
82
101
|
const baseURL = selection.provider.url;
|
|
83
102
|
const providerKind = selection.provider.kind;
|
|
84
|
-
const configuredKey = providerKind === 'chatgpt-codex' ? undefined : selection.provider
|
|
103
|
+
const configuredKey = providerKind === 'chatgpt-codex' ? undefined : providerApiKey(settings, selection.provider);
|
|
85
104
|
assertCredentialedEndpointSecure(baseURL, configuredKey);
|
|
86
105
|
const apiKey = configuredKey ?? 'not-needed';
|
|
87
106
|
const name = selection.model;
|
|
88
107
|
const cacheSeed = cwd ?? process.cwd();
|
|
89
108
|
const cacheKey = crypto.createHash('sha256').update(`${cacheSeed}\0${name}`).digest('hex').slice(0, 32);
|
|
90
|
-
const caps = capabilities(selection.provider
|
|
109
|
+
const caps = capabilities(selection.provider, name);
|
|
91
110
|
const selector = modelSelector(selection.provider, name);
|
|
92
111
|
// The full precedence chain lives in one pure resolver
|
|
93
112
|
// (`resolveAttemptReasoning`): run-scoped override → session per-model map →
|
|
@@ -102,25 +121,30 @@ function runtimeForSelection(settings, selection, cwd, reasoningOverride, sessio
|
|
|
102
121
|
globalSetting: isStoredReasoning(settings.reasoning) ? settings.reasoning : undefined,
|
|
103
122
|
});
|
|
104
123
|
const requestedReasoning = effectiveRequestedReasoning(storedReasoning);
|
|
105
|
-
const resolvedPolicy =
|
|
124
|
+
const resolvedPolicy = resolveProviderReasoning(selection.provider, name, requestedReasoning);
|
|
106
125
|
const reasoningPolicy = deployment && resolvedPolicy.effective !== 'disabled'
|
|
107
126
|
? { ...resolvedPolicy, reason: `haze.build binary thinking ${requestedReasoning === 'none' ? 'off' : 'on'}; effort levels do not imply different compute budgets` }
|
|
108
127
|
: resolvedPolicy;
|
|
109
|
-
//
|
|
110
|
-
// codex OAuth kind ride @ai-sdk/openai (Responses access, `prompt_cache_key`,
|
|
111
|
-
// catalog effort remapping); every other endpoint — gateways, local servers,
|
|
112
|
-
// custom proxies — speaks the compatible subset and rides
|
|
113
|
-
// @ai-sdk/openai-compatible. `includeUsage` is mandatory there: the openai
|
|
114
|
-
// package always streams `include_usage` and context estimation depends on
|
|
115
|
-
// provider usage. Reasoning levels pass through verbatim (no catalog remap).
|
|
128
|
+
// Preserve native reasoning continuation on Responses and OpenRouter.
|
|
116
129
|
const headers = openRouterHeaders(selection.provider.name, baseURL);
|
|
130
|
+
const customFormat = selection.provider.reasoningFormat;
|
|
131
|
+
const transformRequestBody = customFormat === 'thinking' || customFormat === 'enable-thinking'
|
|
132
|
+
? (body) => {
|
|
133
|
+
if (typeof body.reasoning_effort !== 'string')
|
|
134
|
+
return body;
|
|
135
|
+
const { reasoning_effort: effort, ...rest } = body;
|
|
136
|
+
return customFormat === 'thinking' ? { ...rest, thinking: { type: effort === 'none' ? 'disabled' : 'enabled' } } : { ...rest, enable_thinking: effort !== 'none' };
|
|
137
|
+
}
|
|
138
|
+
: isMistralApi(baseURL) ? mistralRequestBody : groqRequestTransform(baseURL, name);
|
|
117
139
|
const model = deployment
|
|
118
140
|
? createHazeBuildModel({ baseURL, apiKey, manifest: deployment })
|
|
119
141
|
: providerKind === 'chatgpt-codex'
|
|
120
142
|
? createOpenAI({ apiKey: OAUTH_SDK_SENTINEL, baseURL, fetch: createChatGptCodexFetch(selection.provider.name) }).responses(name)
|
|
121
143
|
: isDirectOpenAi(selection.provider.name, baseURL, providerKind)
|
|
122
|
-
? createOpenAI({ apiKey, baseURL, headers }).chat(name)
|
|
123
|
-
:
|
|
144
|
+
? /^gpt-6(?:\.|-)/i.test(name) ? createOpenAI({ apiKey, baseURL, headers }).responses(name) : createOpenAI({ apiKey, baseURL, headers }).chat(name)
|
|
145
|
+
: isOpenRouter(selection.provider.name, baseURL)
|
|
146
|
+
? createOpenRouter({ apiKey, baseURL, headers, compatibility: 'strict' }).chat(name)
|
|
147
|
+
: createOpenAICompatible({ name: selection.provider.name, baseURL, apiKey, headers, includeUsage: true, ...(transformRequestBody ? { transformRequestBody } : {}) }).chatModel(name);
|
|
124
148
|
const limits = modelLimitsFor(selection.provider, name);
|
|
125
149
|
// Class-aware fallback so unknown local models (server-configured window,
|
|
126
150
|
// silent truncation) stay conservative while unknown hosted models get the
|
|
@@ -130,16 +154,22 @@ function runtimeForSelection(settings, selection, cwd, reasoningOverride, sessio
|
|
|
130
154
|
// overrides the built-in default; the source tag distinguishes an
|
|
131
155
|
// intentional guess (no warning) from the default guess (warned once per
|
|
132
156
|
// session) (RH-005).
|
|
133
|
-
const isLocal =
|
|
157
|
+
const isLocal = isLocalProvider(selection.provider);
|
|
158
|
+
// Local loaded context can change on restart; a persisted discovery is only a
|
|
159
|
+
// hint to re-probe, never a safe runtime budget on its own.
|
|
160
|
+
const discovered = isLocal ? freshLocalLimits?.[name] : selection.provider.discoveredModelLimits?.[name];
|
|
161
|
+
const preset = isLocal ? undefined : presetModelLimitsForModels(selection.provider, [name])[name];
|
|
134
162
|
const catalog = isLocal ? undefined : catalogLimitsFor(name);
|
|
135
163
|
const userFallback = isLocal ? settings.localContextWindowFallbackTokens : settings.contextWindowFallbackTokens;
|
|
136
164
|
const fallbackTokens = userFallback ?? (isLocal ? FALLBACK_LOCAL_CONTEXT_TOKENS : FALLBACK_CONTEXT_WINDOW_TOKENS);
|
|
137
165
|
const contextWindowSource = limits.contextWindowTokens !== undefined
|
|
138
166
|
? 'settings'
|
|
139
|
-
:
|
|
140
|
-
? '
|
|
141
|
-
|
|
142
|
-
|
|
167
|
+
: discovered?.contextWindowTokens !== undefined ? 'discovery'
|
|
168
|
+
: preset?.contextWindowTokens !== undefined ? 'preset'
|
|
169
|
+
: catalog
|
|
170
|
+
? 'catalog'
|
|
171
|
+
: userFallback !== undefined ? 'user-fallback' : 'default-fallback';
|
|
172
|
+
const maxOutputTokens = limits.maxOutputTokens ?? discovered?.maxOutputTokens ?? preset?.maxOutputTokens ?? catalog?.maxOutputTokens;
|
|
143
173
|
return {
|
|
144
174
|
model,
|
|
145
175
|
selector,
|
|
@@ -147,11 +177,12 @@ function runtimeForSelection(settings, selection, cwd, reasoningOverride, sessio
|
|
|
147
177
|
providerName: selection.provider.name,
|
|
148
178
|
providerKind,
|
|
149
179
|
baseURL,
|
|
180
|
+
isLocal,
|
|
150
181
|
modelName: name,
|
|
151
182
|
cacheKey,
|
|
152
183
|
capabilities: caps,
|
|
153
184
|
reasoningPolicy,
|
|
154
|
-
contextWindowTokens: deployment ? Math.min(limits.contextWindowTokens ?? deployment.contextWindowTokens, deployment.contextWindowTokens) : limits.contextWindowTokens ?? catalog?.contextWindowTokens ?? fallbackTokens,
|
|
185
|
+
contextWindowTokens: deployment ? Math.min(limits.contextWindowTokens ?? deployment.contextWindowTokens, deployment.contextWindowTokens) : limits.contextWindowTokens ?? discovered?.contextWindowTokens ?? preset?.contextWindowTokens ?? catalog?.contextWindowTokens ?? fallbackTokens,
|
|
155
186
|
contextWindowSource: deployment ? 'deployment' : contextWindowSource,
|
|
156
187
|
...(deployment ? { deployment, maxOutputTokens: Math.min(limits.maxOutputTokens ?? deployment.maxOutputTokens, deployment.maxOutputTokens),
|
|
157
188
|
warnings: [
|
|
@@ -189,10 +220,17 @@ export async function modelWithConfig(session, settings) {
|
|
|
189
220
|
selection = activeModel(resolvedSettings);
|
|
190
221
|
if (!selection)
|
|
191
222
|
return undefined;
|
|
223
|
+
assertCredentialedEndpointSecure(selection.provider.url, selection.provider.kind === 'chatgpt-codex' ? undefined : providerApiKey(resolvedSettings, selection.provider));
|
|
192
224
|
const deployment = selection.provider.kind === 'haze-build' ? await discoverHazeBuildManifest(selection.provider) : undefined;
|
|
193
225
|
if (deployment && selection.model !== deployment.model)
|
|
194
226
|
throw new Error(`haze.build currently serves ${deployment.model}; choose it explicitly via /model.`);
|
|
195
|
-
|
|
227
|
+
const freshLocalLimits = await refreshLocalLimits(selection, resolvedSettings);
|
|
228
|
+
return runtimeForSelection(resolvedSettings, selection, session?.cwd, session?.reasoningOverride, session?.reasoningByModel, deployment, freshLocalLimits);
|
|
229
|
+
}
|
|
230
|
+
async function refreshLocalLimits(selection, settings) {
|
|
231
|
+
if (!isLocalProvider(selection.provider) || selection.provider.kind === 'haze-build' || selection.provider.modelLimits?.[selection.model]?.contextWindowTokens !== undefined || !selection.provider.discoveredModelLimits?.[selection.model])
|
|
232
|
+
return undefined;
|
|
233
|
+
return ollamaModelLimits({ baseUrl: selection.provider.url, models: [selection.model], conservativeCap: settings.localContextWindowFallbackTokens ?? FALLBACK_LOCAL_CONTEXT_TOKENS, timeoutMs: 1000 }).catch(() => undefined);
|
|
196
234
|
}
|
|
197
235
|
export async function resolveWorkerRuntime(input) {
|
|
198
236
|
const requested = input.selector?.trim();
|
|
@@ -201,6 +239,7 @@ export async function resolveWorkerRuntime(input) {
|
|
|
201
239
|
const resolved = resolveModelSelector(input.settings, requested);
|
|
202
240
|
if (resolved.status !== 'found')
|
|
203
241
|
return { status: resolved.status, message: resolved.status === 'ambiguous' ? `Worker model ${requested} is ambiguous; use provider:model.` : `Worker model ${requested} is not configured. Configure it via /provider or remove subagents.workerModel.` };
|
|
242
|
+
assertCredentialedEndpointSecure(resolved.provider.url, resolved.provider.kind === 'chatgpt-codex' ? undefined : providerApiKey(input.settings, resolved.provider));
|
|
204
243
|
// The active deployment was fetched and validated for this attempt. An
|
|
205
244
|
// explicit worker selecting that same provider/model can reuse it rather
|
|
206
245
|
// than making a second network round trip; different endpoints still refresh.
|
|
@@ -214,9 +253,10 @@ export async function resolveWorkerRuntime(input) {
|
|
|
214
253
|
: undefined;
|
|
215
254
|
if (deployment && resolved.model !== deployment.model)
|
|
216
255
|
return { status: 'missing', message: `haze.build currently serves ${deployment.model}.` };
|
|
217
|
-
|
|
256
|
+
const selection = { provider: resolved.provider, model: resolved.model };
|
|
257
|
+
selected = runtimeForSelection(input.settings, selection, input.cwd, undefined, undefined, deployment, await refreshLocalLimits(selection, input.settings));
|
|
218
258
|
}
|
|
219
|
-
return { status: 'found', runtime: { model: selected.model, selector: selected.selector, providerName: selected.config.providerName, capabilities: selected.config.capabilities, requestOptions: providerRequestSettings(selected.config), contextWindowTokens: selected.config.contextWindowTokens, maxOutputTokens: selected.config.maxOutputTokens, ...(selected.config.deployment ? { nativeMaxConcurrency:
|
|
259
|
+
return { status: 'found', runtime: { model: selected.model, selector: selected.selector, providerName: selected.config.providerName, capabilities: selected.config.capabilities, requestOptions: providerRequestSettings(selected.config), contextWindowTokens: selected.config.contextWindowTokens, maxOutputTokens: selected.config.maxOutputTokens, ...(selected.config.deployment ? { nativeMaxConcurrency: selected.config.deployment.activeSequences } : {}) } };
|
|
220
260
|
}
|
|
221
261
|
export function providerRequestSettings(config) {
|
|
222
262
|
// Top-level AI SDK `reasoning` setting; the key is omitted entirely when the
|
|
@@ -232,12 +272,21 @@ export function providerRequestSettings(config) {
|
|
|
232
272
|
...(reasoning ? { reasoning } : {}),
|
|
233
273
|
};
|
|
234
274
|
}
|
|
275
|
+
if (isOpenRouter(config.providerName, config.baseURL))
|
|
276
|
+
return {
|
|
277
|
+
headers: { 'x-session-id': config.cacheKey },
|
|
278
|
+
...(reasoning ? { providerOptions: { openrouter: { reasoning: { effort: reasoning } } } } : {}),
|
|
279
|
+
};
|
|
235
280
|
const caps = config.capabilities;
|
|
236
281
|
const openaiOptions = {};
|
|
237
282
|
if (caps.supportsPromptCacheKey)
|
|
238
283
|
openaiOptions.promptCacheKey = config.cacheKey;
|
|
239
284
|
if (caps.supportsTextVerbosity)
|
|
240
285
|
openaiOptions.textVerbosity = 'low';
|
|
286
|
+
if (caps.supportsPromptCacheKey && /^gpt-6(?:\.|-)/i.test(config.modelName)) {
|
|
287
|
+
openaiOptions.store = false;
|
|
288
|
+
openaiOptions.include = ['reasoning.encrypted_content'];
|
|
289
|
+
}
|
|
241
290
|
const providerOptions = Object.keys(openaiOptions).length > 0 ? { openai: openaiOptions } : undefined;
|
|
242
291
|
return {
|
|
243
292
|
...(providerOptions ? { providerOptions } : {}),
|