@denizokcu/haze 0.7.0 → 0.8.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 +24 -8
- package/README.md +31 -31
- package/dist/cli/chat/inputSuggestions.js +2 -2
- package/dist/cli/commands/chat.js +46 -20
- package/dist/cli/commands/chatModes.js +1 -1
- package/dist/cli/commands/commandHelp.js +2 -2
- package/dist/cli/commands/formatters.d.ts +6 -0
- package/dist/cli/commands/formatters.js +38 -0
- package/dist/cli/commands/streaming.js +34 -23
- package/dist/cli/commands/wizardSuggestions.js +1 -1
- package/dist/config/providers.js +5 -9
- package/dist/config/settings.d.ts +1 -0
- package/dist/config/settings.js +54 -2
- package/dist/core/agent/compaction.js +2 -2
- package/dist/core/agent/errors.js +1 -1
- package/dist/core/agent/requestAssembly.d.ts +1 -0
- package/dist/core/agent/requestAssembly.js +13 -0
- package/dist/core/bashOutput/registry.js +11 -9
- package/dist/core/goal/completionPolicy.js +1 -1
- package/dist/core/subagent/subagentRunner.d.ts +252 -9
- package/dist/core/subagent/subagentRunner.js +13 -18
- package/dist/core/toolOutput/reduction.d.ts +2 -0
- package/dist/core/toolOutput/reduction.js +12 -0
- package/dist/core/validation/outputParser.js +5 -3
- package/dist/llm/client.d.ts +2 -2
- package/dist/llm/client.js +15 -2
- package/dist/llm/hazeTools.d.ts +7709 -364
- package/dist/llm/hazeTools.js +7 -1
- package/dist/llm/initPrompt.js +1 -1
- package/dist/llm/lsp.js +10 -1
- package/dist/llm/lspTools.d.ts +2310 -101
- package/dist/llm/systemPrompt.js +2 -2
- package/dist/llm/tools/bashTool.d.ts +251 -5
- package/dist/llm/tools/bashTool.js +4 -3
- package/dist/llm/tools/fetchTool.d.ts +1201 -65
- package/dist/llm/tools/fetchTool.js +2 -1
- package/dist/llm/tools/storedOutputTool.d.ts +351 -10
- package/dist/llm/tools/taskTool.d.ts +629 -28
- package/dist/llm/tools/toolContext.d.ts +7 -2
- package/dist/llm/tools/toolContext.js +11 -2
- package/dist/llm/webFetch.js +31 -21
- package/dist/skills/builder/SkillBuilder.js +7 -7
- package/dist/ui/components/TextInput.d.ts +7 -0
- package/dist/ui/components/TextInput.js +10 -0
- package/dist/utils/modelName.d.ts +2 -0
- package/dist/utils/modelName.js +15 -0
- package/examples/skills/files/SKILL.md +1 -1
- package/package.json +14 -14
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { streamText } from 'ai';
|
|
2
2
|
import { type PromptSession } from '../../llm/systemPrompt.js';
|
|
3
|
+
import { toolOnlyStepCount } from '../agent/turnPolicy.js';
|
|
3
4
|
import type { ContextFile } from '../../config/contextFiles.js';
|
|
4
5
|
export interface SubagentResult {
|
|
5
6
|
status: 'ok' | 'error' | 'timeout' | 'cancelled';
|
|
@@ -18,10 +19,6 @@ export interface SubagentResult {
|
|
|
18
19
|
error?: string;
|
|
19
20
|
}
|
|
20
21
|
declare function toolSummary(output: unknown): string;
|
|
21
|
-
declare function toolOnlyStepCount(steps: Array<{
|
|
22
|
-
toolCalls: unknown[];
|
|
23
|
-
text: string;
|
|
24
|
-
}>): number;
|
|
25
22
|
export declare const internals: {
|
|
26
23
|
toolSummary: typeof toolSummary;
|
|
27
24
|
toolOnlyStepCount: typeof toolOnlyStepCount;
|
|
@@ -38,9 +35,255 @@ export declare function createSubagentTool(options: {
|
|
|
38
35
|
model: Parameters<typeof streamText>[0]['model'];
|
|
39
36
|
contextFiles: ContextFile[];
|
|
40
37
|
session?: PromptSession;
|
|
41
|
-
}):
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
}): ({
|
|
39
|
+
title?: string;
|
|
40
|
+
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
41
|
+
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
42
|
+
inputSchema: import("ai").FlexibleSchema<{
|
|
43
|
+
task: string;
|
|
44
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
45
|
+
maxSteps?: number | undefined;
|
|
46
|
+
}>;
|
|
47
|
+
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
|
|
48
|
+
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
49
|
+
task: string;
|
|
50
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
51
|
+
maxSteps?: number | undefined;
|
|
52
|
+
}, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
|
|
53
|
+
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
54
|
+
onInputDelta?: ((options: {
|
|
55
|
+
inputTextDelta: string;
|
|
56
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
57
|
+
onInputAvailable?: ((options: {
|
|
58
|
+
input: {
|
|
59
|
+
task: string;
|
|
60
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
61
|
+
maxSteps?: number | undefined;
|
|
62
|
+
};
|
|
63
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
64
|
+
toModelOutput?: ((options: {
|
|
65
|
+
toolCallId: string;
|
|
66
|
+
input: {
|
|
67
|
+
task: string;
|
|
68
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
69
|
+
maxSteps?: number | undefined;
|
|
70
|
+
};
|
|
71
|
+
output: NoInfer<SubagentResult>;
|
|
72
|
+
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
73
|
+
} & {
|
|
74
|
+
outputSchema?: import("ai").FlexibleSchema<SubagentResult> | undefined;
|
|
75
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
76
|
+
task: string;
|
|
77
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
78
|
+
maxSteps?: number | undefined;
|
|
79
|
+
}, SubagentResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
80
|
+
} & {
|
|
81
|
+
description?: string | ((options: {
|
|
82
|
+
context: NoInfer<import("@ai-sdk/provider-utils").Context>;
|
|
83
|
+
experimental_sandbox?: import("ai").Experimental_SandboxSession;
|
|
84
|
+
}) => string) | undefined;
|
|
85
|
+
strict?: boolean;
|
|
86
|
+
inputExamples?: {
|
|
87
|
+
input: NoInfer<{
|
|
88
|
+
task: string;
|
|
89
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
90
|
+
maxSteps?: number | undefined;
|
|
91
|
+
}>;
|
|
92
|
+
}[] | undefined;
|
|
93
|
+
id?: never;
|
|
94
|
+
isProviderExecuted?: never;
|
|
95
|
+
args?: never;
|
|
96
|
+
supportsDeferredResults?: never;
|
|
97
|
+
} & {
|
|
98
|
+
type?: undefined | "function";
|
|
99
|
+
} & {
|
|
100
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
101
|
+
task: string;
|
|
102
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
103
|
+
maxSteps?: number | undefined;
|
|
104
|
+
}, SubagentResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
105
|
+
}) | ({
|
|
106
|
+
title?: string;
|
|
107
|
+
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
108
|
+
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
109
|
+
inputSchema: import("ai").FlexibleSchema<{
|
|
110
|
+
task: string;
|
|
111
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
112
|
+
maxSteps?: number | undefined;
|
|
113
|
+
}>;
|
|
114
|
+
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
|
|
115
|
+
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
116
|
+
task: string;
|
|
117
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
118
|
+
maxSteps?: number | undefined;
|
|
119
|
+
}, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
|
|
120
|
+
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
121
|
+
onInputDelta?: ((options: {
|
|
122
|
+
inputTextDelta: string;
|
|
123
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
124
|
+
onInputAvailable?: ((options: {
|
|
125
|
+
input: {
|
|
126
|
+
task: string;
|
|
127
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
128
|
+
maxSteps?: number | undefined;
|
|
129
|
+
};
|
|
130
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
131
|
+
toModelOutput?: ((options: {
|
|
132
|
+
toolCallId: string;
|
|
133
|
+
input: {
|
|
134
|
+
task: string;
|
|
135
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
136
|
+
maxSteps?: number | undefined;
|
|
137
|
+
};
|
|
138
|
+
output: NoInfer<SubagentResult>;
|
|
139
|
+
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
140
|
+
} & {
|
|
141
|
+
outputSchema?: import("ai").FlexibleSchema<SubagentResult> | undefined;
|
|
142
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
143
|
+
task: string;
|
|
144
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
145
|
+
maxSteps?: number | undefined;
|
|
146
|
+
}, SubagentResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
147
|
+
} & {
|
|
148
|
+
description?: string | ((options: {
|
|
149
|
+
context: NoInfer<import("@ai-sdk/provider-utils").Context>;
|
|
150
|
+
experimental_sandbox?: import("ai").Experimental_SandboxSession;
|
|
151
|
+
}) => string) | undefined;
|
|
152
|
+
strict?: boolean;
|
|
153
|
+
inputExamples?: {
|
|
154
|
+
input: NoInfer<{
|
|
155
|
+
task: string;
|
|
156
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
157
|
+
maxSteps?: number | undefined;
|
|
158
|
+
}>;
|
|
159
|
+
}[] | undefined;
|
|
160
|
+
id?: never;
|
|
161
|
+
isProviderExecuted?: never;
|
|
162
|
+
args?: never;
|
|
163
|
+
supportsDeferredResults?: never;
|
|
164
|
+
} & {
|
|
165
|
+
type: "dynamic";
|
|
166
|
+
} & {
|
|
167
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
168
|
+
task: string;
|
|
169
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
170
|
+
maxSteps?: number | undefined;
|
|
171
|
+
}, SubagentResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
172
|
+
}) | ({
|
|
173
|
+
title?: string;
|
|
174
|
+
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
175
|
+
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
176
|
+
inputSchema: import("ai").FlexibleSchema<{
|
|
177
|
+
task: string;
|
|
178
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
179
|
+
maxSteps?: number | undefined;
|
|
180
|
+
}>;
|
|
181
|
+
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
|
|
182
|
+
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
183
|
+
task: string;
|
|
184
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
185
|
+
maxSteps?: number | undefined;
|
|
186
|
+
}, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
|
|
187
|
+
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
188
|
+
onInputDelta?: ((options: {
|
|
189
|
+
inputTextDelta: string;
|
|
190
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
191
|
+
onInputAvailable?: ((options: {
|
|
192
|
+
input: {
|
|
193
|
+
task: string;
|
|
194
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
195
|
+
maxSteps?: number | undefined;
|
|
196
|
+
};
|
|
197
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
198
|
+
toModelOutput?: ((options: {
|
|
199
|
+
toolCallId: string;
|
|
200
|
+
input: {
|
|
201
|
+
task: string;
|
|
202
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
203
|
+
maxSteps?: number | undefined;
|
|
204
|
+
};
|
|
205
|
+
output: NoInfer<SubagentResult>;
|
|
206
|
+
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
207
|
+
} & {
|
|
208
|
+
outputSchema?: import("ai").FlexibleSchema<SubagentResult> | undefined;
|
|
209
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
210
|
+
task: string;
|
|
211
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
212
|
+
maxSteps?: number | undefined;
|
|
213
|
+
}, SubagentResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
214
|
+
} & {
|
|
215
|
+
type: "provider";
|
|
216
|
+
id: `${string}.${string}`;
|
|
217
|
+
args: Record<string, unknown>;
|
|
218
|
+
description?: never;
|
|
219
|
+
strict?: never;
|
|
220
|
+
inputExamples?: never;
|
|
221
|
+
} & {
|
|
222
|
+
isProviderExecuted: false;
|
|
223
|
+
supportsDeferredResults?: never;
|
|
224
|
+
} & {
|
|
225
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
226
|
+
task: string;
|
|
227
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
228
|
+
maxSteps?: number | undefined;
|
|
229
|
+
}, SubagentResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
230
|
+
}) | ({
|
|
231
|
+
title?: string;
|
|
232
|
+
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
233
|
+
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
234
|
+
inputSchema: import("ai").FlexibleSchema<{
|
|
235
|
+
task: string;
|
|
236
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
237
|
+
maxSteps?: number | undefined;
|
|
238
|
+
}>;
|
|
239
|
+
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
|
|
240
|
+
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
241
|
+
task: string;
|
|
242
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
243
|
+
maxSteps?: number | undefined;
|
|
244
|
+
}, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
|
|
245
|
+
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
246
|
+
onInputDelta?: ((options: {
|
|
247
|
+
inputTextDelta: string;
|
|
248
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
249
|
+
onInputAvailable?: ((options: {
|
|
250
|
+
input: {
|
|
251
|
+
task: string;
|
|
252
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
253
|
+
maxSteps?: number | undefined;
|
|
254
|
+
};
|
|
255
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
256
|
+
toModelOutput?: ((options: {
|
|
257
|
+
toolCallId: string;
|
|
258
|
+
input: {
|
|
259
|
+
task: string;
|
|
260
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
261
|
+
maxSteps?: number | undefined;
|
|
262
|
+
};
|
|
263
|
+
output: NoInfer<SubagentResult>;
|
|
264
|
+
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
265
|
+
} & {
|
|
266
|
+
outputSchema?: import("ai").FlexibleSchema<SubagentResult> | undefined;
|
|
267
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
268
|
+
task: string;
|
|
269
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
270
|
+
maxSteps?: number | undefined;
|
|
271
|
+
}, SubagentResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
272
|
+
} & {
|
|
273
|
+
type: "provider";
|
|
274
|
+
id: `${string}.${string}`;
|
|
275
|
+
args: Record<string, unknown>;
|
|
276
|
+
description?: never;
|
|
277
|
+
strict?: never;
|
|
278
|
+
inputExamples?: never;
|
|
279
|
+
} & {
|
|
280
|
+
isProviderExecuted: true;
|
|
281
|
+
supportsDeferredResults?: boolean;
|
|
282
|
+
} & {
|
|
283
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
284
|
+
task: string;
|
|
285
|
+
tools?: ("listFiles" | "readFile" | "grep" | "replaceLines" | "writeFile" | "editFile" | "bash" | "fetch" | "readToolOutput")[] | undefined;
|
|
286
|
+
maxSteps?: number | undefined;
|
|
287
|
+
}, SubagentResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
288
|
+
});
|
|
46
289
|
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { streamText,
|
|
1
|
+
import { streamText, isStepCount, tool } from 'ai';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { buildSubagentPrompt } from '../../llm/systemPrompt.js';
|
|
4
4
|
import { hazeTools } from '../../llm/hazeTools.js';
|
|
5
|
+
import { toolsContextFor } from '../../llm/tools/toolContext.js';
|
|
6
|
+
import { toolOnlyStepCount } from '../agent/turnPolicy.js';
|
|
5
7
|
const ALL_TOOLS = ['listFiles', 'readFile', 'grep', 'bash', 'readToolOutput', 'editFile', 'replaceLines', 'writeFile', 'fetch'];
|
|
6
8
|
const STEP_LIMIT = 25;
|
|
7
9
|
const MAX_SUMMARY = 4000;
|
|
@@ -20,15 +22,6 @@ function toolSummary(output) {
|
|
|
20
22
|
return `failed: ${o.error.slice(0, 120)}`;
|
|
21
23
|
return 'completed';
|
|
22
24
|
}
|
|
23
|
-
function toolOnlyStepCount(steps) {
|
|
24
|
-
let count = 0;
|
|
25
|
-
for (const step of [...steps].reverse()) {
|
|
26
|
-
if (step.toolCalls.length === 0 || step.text.trim().length > 0)
|
|
27
|
-
break;
|
|
28
|
-
count += 1;
|
|
29
|
-
}
|
|
30
|
-
return count;
|
|
31
|
-
}
|
|
32
25
|
export const internals = { toolSummary, toolOnlyStepCount };
|
|
33
26
|
export async function runSubagent(task, options) {
|
|
34
27
|
const start = performance.now();
|
|
@@ -41,6 +34,7 @@ export async function runSubagent(task, options) {
|
|
|
41
34
|
scopedTools[name] = hazeTools[key];
|
|
42
35
|
}
|
|
43
36
|
const toolCallLog = [];
|
|
37
|
+
const toolExecutionContext = { inFlightToolCalls: new Map() };
|
|
44
38
|
let tokensIn = 0;
|
|
45
39
|
let tokensOut = 0;
|
|
46
40
|
let lastStep = 0;
|
|
@@ -49,12 +43,13 @@ export async function runSubagent(task, options) {
|
|
|
49
43
|
const result = streamText({
|
|
50
44
|
model: options.model,
|
|
51
45
|
maxOutputTokens: 4096,
|
|
52
|
-
|
|
46
|
+
instructions: buildSubagentPrompt(options.contextFiles, options.session),
|
|
53
47
|
messages: [{ role: 'user', content: task }],
|
|
54
48
|
tools: scopedTools,
|
|
55
|
-
stopWhen:
|
|
49
|
+
stopWhen: isStepCount(maxSteps),
|
|
56
50
|
abortSignal: options.abortSignal,
|
|
57
|
-
|
|
51
|
+
runtimeContext: toolExecutionContext,
|
|
52
|
+
toolsContext: toolsContextFor(scopedTools, toolExecutionContext),
|
|
58
53
|
prepareStep({ steps }) {
|
|
59
54
|
const calls = steps.flatMap(step => step.toolCalls);
|
|
60
55
|
const consecutiveToolOnly = toolOnlyStepCount(steps);
|
|
@@ -68,23 +63,23 @@ export async function runSubagent(task, options) {
|
|
|
68
63
|
}
|
|
69
64
|
return undefined;
|
|
70
65
|
},
|
|
71
|
-
|
|
66
|
+
onStepEnd({ stepNumber }) {
|
|
72
67
|
lastStep = stepNumber;
|
|
73
68
|
},
|
|
74
|
-
|
|
69
|
+
onEnd(event) {
|
|
75
70
|
if (event.usage) {
|
|
76
71
|
tokensIn = event.usage.inputTokens ?? 0;
|
|
77
72
|
tokensOut = event.usage.outputTokens ?? 0;
|
|
78
73
|
}
|
|
79
74
|
},
|
|
80
|
-
|
|
75
|
+
onToolExecutionEnd(event) {
|
|
81
76
|
if (!event.toolCall)
|
|
82
77
|
return;
|
|
83
78
|
totalToolCalls += 1;
|
|
84
79
|
toolCallLog.push({
|
|
85
80
|
name: event.toolCall.toolName,
|
|
86
|
-
summary: toolSummary(event.output),
|
|
87
|
-
durationMs: event.
|
|
81
|
+
summary: event.toolOutput.type === 'tool-result' ? toolSummary(event.toolOutput.output) : `failed: ${String(event.toolOutput.error).slice(0, 120)}`,
|
|
82
|
+
durationMs: event.toolExecutionMs,
|
|
88
83
|
});
|
|
89
84
|
},
|
|
90
85
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type ReductionPressure = 'conservative' | 'normal' | 'aggressive';
|
|
2
|
+
export declare const PROCESSING_OUTPUT_CHAR_LIMIT = 200000;
|
|
2
3
|
export type ReductionContentKind = 'validation' | 'log' | 'search' | 'diff' | 'json' | 'table' | 'web' | 'source-outline' | 'generic';
|
|
3
4
|
export type ReductionParseTier = 'full' | 'degraded' | 'passthrough';
|
|
4
5
|
export interface ReductionMetrics {
|
|
@@ -20,6 +21,7 @@ export interface ToolOutputReductionMetadata extends ReductionMetrics {
|
|
|
20
21
|
warning?: string;
|
|
21
22
|
}
|
|
22
23
|
export declare function estimateReductionTokens(text: string): number;
|
|
24
|
+
export declare function capOutputForProcessing(text: string, maxChars?: number): string;
|
|
23
25
|
export declare function reductionMetrics(raw: string, returned: string): ReductionMetrics;
|
|
24
26
|
export declare function retrievalHint(handle: string): string;
|
|
25
27
|
export declare function isInflating(raw: string, returned: string): boolean;
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
export const PROCESSING_OUTPUT_CHAR_LIMIT = 200_000;
|
|
2
|
+
const PROCESSING_TRUNCATION_MARKER = '\n[... output truncated for processing ...]\n';
|
|
1
3
|
export function estimateReductionTokens(text) {
|
|
2
4
|
return Math.ceil(text.length / 4);
|
|
3
5
|
}
|
|
6
|
+
export function capOutputForProcessing(text, maxChars = PROCESSING_OUTPUT_CHAR_LIMIT) {
|
|
7
|
+
if (text.length <= maxChars)
|
|
8
|
+
return text;
|
|
9
|
+
if (maxChars <= PROCESSING_TRUNCATION_MARKER.length)
|
|
10
|
+
return text.slice(0, maxChars);
|
|
11
|
+
const keepChars = maxChars - PROCESSING_TRUNCATION_MARKER.length;
|
|
12
|
+
const headChars = Math.floor(keepChars / 2);
|
|
13
|
+
const tailChars = keepChars - headChars;
|
|
14
|
+
return `${text.slice(0, headChars)}${PROCESSING_TRUNCATION_MARKER}${text.slice(-tailChars)}`;
|
|
15
|
+
}
|
|
4
16
|
export function reductionMetrics(raw, returned) {
|
|
5
17
|
const rawTokensEstimate = estimateReductionTokens(raw);
|
|
6
18
|
const returnedTokensEstimate = estimateReductionTokens(returned);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { capOutputForProcessing } from '../toolOutput/reduction.js';
|
|
1
2
|
function uniq(values) {
|
|
2
3
|
return [...new Set(values.filter(Boolean))];
|
|
3
4
|
}
|
|
@@ -14,13 +15,14 @@ function inferKind(command, classification) {
|
|
|
14
15
|
return 'generic';
|
|
15
16
|
}
|
|
16
17
|
export function parseValidationOutput(input) {
|
|
17
|
-
const text = `${input.stdout}\n${input.stderr}`;
|
|
18
|
+
const text = `${capOutputForProcessing(input.stdout)}\n${capOutputForProcessing(input.stderr)}`;
|
|
18
19
|
const lines = text.split(/\r?\n/);
|
|
19
20
|
const diagnostics = [];
|
|
20
21
|
const failedTests = [];
|
|
21
22
|
const failedFiles = [];
|
|
22
23
|
const kind = inferKind(input.command, input.classification);
|
|
23
|
-
for (
|
|
24
|
+
for (let index = 0; index < lines.length; index++) {
|
|
25
|
+
const line = lines[index];
|
|
24
26
|
const ts = line.match(/^(.+?\.(?:ts|tsx|js|jsx|mts|cts))\((\d+),(\d+)\):\s+(error|warning)\s+TS\d+:\s+(.+)$/);
|
|
25
27
|
if (ts) {
|
|
26
28
|
const [, file, lineNo, column, severity, message] = ts;
|
|
@@ -31,7 +33,7 @@ export function parseValidationOutput(input) {
|
|
|
31
33
|
const eslint = line.match(/^(.+?\.(?:ts|tsx|js|jsx|mts|cts))\s*$/);
|
|
32
34
|
if (eslint) {
|
|
33
35
|
const currentFile = eslint[1] ?? '';
|
|
34
|
-
const next = lines[
|
|
36
|
+
const next = lines[index + 1];
|
|
35
37
|
if (next && /^\s*\d+:\d+\s+/.test(next))
|
|
36
38
|
failedFiles.push(currentFile);
|
|
37
39
|
}
|
package/dist/llm/client.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare function modelWithConfig(session?: {
|
|
|
17
17
|
cwd?: string;
|
|
18
18
|
modelSelector?: string;
|
|
19
19
|
}): Promise<{
|
|
20
|
-
model: import("@ai-sdk/provider").
|
|
20
|
+
model: import("@ai-sdk/provider").LanguageModelV4;
|
|
21
21
|
config: {
|
|
22
22
|
providerName: string;
|
|
23
23
|
baseURL: string;
|
|
@@ -26,7 +26,7 @@ export declare function modelWithConfig(session?: {
|
|
|
26
26
|
capabilities: ProviderCapabilities;
|
|
27
27
|
};
|
|
28
28
|
} | undefined>;
|
|
29
|
-
export declare function model(): Promise<import("@ai-sdk/provider").
|
|
29
|
+
export declare function model(): Promise<import("@ai-sdk/provider").LanguageModelV4 | undefined>;
|
|
30
30
|
export declare function cacheKeyFor(name: string, cwd?: string): string;
|
|
31
31
|
export declare function providerRequestSettings(config: ModelRuntimeConfig): {
|
|
32
32
|
headers?: {
|
package/dist/llm/client.js
CHANGED
|
@@ -2,9 +2,22 @@ import { createOpenAI } from '@ai-sdk/openai';
|
|
|
2
2
|
import crypto from 'node:crypto';
|
|
3
3
|
import { readSettings } from '../config/settings.js';
|
|
4
4
|
import { activeModel, resolveModelSelector } from '../config/providers.js';
|
|
5
|
+
const HAZE_SITE_URL = 'https://denizokcu.github.io/haze/';
|
|
6
|
+
const HAZE_TITLE = 'Haze';
|
|
7
|
+
function isOpenRouter(providerName, baseURL) {
|
|
8
|
+
return providerName === 'openrouter' || /openrouter\.ai/i.test(baseURL);
|
|
9
|
+
}
|
|
10
|
+
function openRouterHeaders(providerName, baseURL) {
|
|
11
|
+
if (!isOpenRouter(providerName, baseURL))
|
|
12
|
+
return undefined;
|
|
13
|
+
return {
|
|
14
|
+
'HTTP-Referer': HAZE_SITE_URL,
|
|
15
|
+
'X-Title': HAZE_TITLE,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
5
18
|
function capabilities(providerName, baseURL) {
|
|
6
19
|
const directOpenAI = providerName === 'openai' || /api\.openai\.com/i.test(baseURL);
|
|
7
|
-
const openRouter = providerName
|
|
20
|
+
const openRouter = isOpenRouter(providerName, baseURL);
|
|
8
21
|
return {
|
|
9
22
|
reportsCacheUsage: directOpenAI || openRouter,
|
|
10
23
|
supportsPromptCacheKey: directOpenAI,
|
|
@@ -34,7 +47,7 @@ export async function modelWithConfig(session) {
|
|
|
34
47
|
const cacheSeed = session?.cwd ?? process.cwd();
|
|
35
48
|
const cacheKey = crypto.createHash('sha256').update(`${cacheSeed}\0${name}`).digest('hex').slice(0, 32);
|
|
36
49
|
return {
|
|
37
|
-
model: createOpenAI({ apiKey, baseURL }).chat(name),
|
|
50
|
+
model: createOpenAI({ apiKey, baseURL, headers: openRouterHeaders(selection.provider.name, baseURL) }).chat(name),
|
|
38
51
|
config: {
|
|
39
52
|
providerName: selection.provider.name,
|
|
40
53
|
baseURL,
|