@ai-sdk/harness-grok-build 0.0.0 → 1.0.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 +17 -0
- package/LICENSE +13 -0
- package/README.md +41 -3
- package/dist/bridge/package.json +13 -0
- package/dist/bridge/pnpm-lock.yaml +890 -0
- package/dist/index.d.ts +4540 -0
- package/dist/index.js +288 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -10
- package/src/bridge/package.json +13 -0
- package/src/bridge/pnpm-lock.yaml +890 -0
- package/src/grok-build-harness.ts +314 -0
- package/src/index.ts +10 -0
- package/src/version.ts +5 -0
- package/index.js +0 -1
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import {
|
|
3
|
+
commonTool,
|
|
4
|
+
type HarnessV1,
|
|
5
|
+
type HarnessV1BuiltinTool,
|
|
6
|
+
} from '@ai-sdk/harness';
|
|
7
|
+
import {
|
|
8
|
+
createACP,
|
|
9
|
+
type ACPProviderAuthenticationMode,
|
|
10
|
+
} from '@ai-sdk/harness-acp';
|
|
11
|
+
import { tool } from '@ai-sdk/provider-utils';
|
|
12
|
+
import { z } from 'zod/v4';
|
|
13
|
+
import { VERSION } from './version';
|
|
14
|
+
|
|
15
|
+
const GROK_BUILD_CLIENT_APP = `ai-sdk/harness-grok-build/${VERSION}`;
|
|
16
|
+
const GROK_BUILD_IMPLEMENTATION_PACKAGE_JSON = readFileSync(
|
|
17
|
+
new URL('./bridge/package.json', import.meta.url),
|
|
18
|
+
'utf8',
|
|
19
|
+
);
|
|
20
|
+
const GROK_BUILD_IMPLEMENTATION_PNPM_LOCK = readFileSync(
|
|
21
|
+
new URL('./bridge/pnpm-lock.yaml', import.meta.url),
|
|
22
|
+
'utf8',
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export type GrokBuildHarnessSettings = {
|
|
26
|
+
/**
|
|
27
|
+
* Selects direct xAI or AI Gateway authentication. Defaults to automatic
|
|
28
|
+
* environment-based selection.
|
|
29
|
+
*/
|
|
30
|
+
readonly auth?: ACPProviderAuthenticationMode;
|
|
31
|
+
/**
|
|
32
|
+
* Grok model id selected through ACP. Unset preserves Grok Build's default.
|
|
33
|
+
*/
|
|
34
|
+
readonly model?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Overrides the sandbox port used by the ACP bridge.
|
|
37
|
+
*/
|
|
38
|
+
readonly port?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Maximum milliseconds to wait for the ACP bridge to start.
|
|
41
|
+
*/
|
|
42
|
+
readonly startupTimeoutMs?: number;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
* Tool names and inputs were captured from the model request produced by
|
|
47
|
+
* @xai-official/grok 0.2.111, the version used by the pinned Grok Build ACP
|
|
48
|
+
* implementation.
|
|
49
|
+
*/
|
|
50
|
+
const GROK_BUILD_BUILTIN_TOOLS = {
|
|
51
|
+
bash: commonTool('bash', {
|
|
52
|
+
nativeName: 'run_terminal_command',
|
|
53
|
+
toolUseKind: 'bash',
|
|
54
|
+
inputSchema: z.looseObject({
|
|
55
|
+
command: z.string(),
|
|
56
|
+
timeout: z.number().int().min(0).max(36_000_000).nullable().optional(),
|
|
57
|
+
description: z.string().optional(),
|
|
58
|
+
background: z.boolean().optional(),
|
|
59
|
+
}),
|
|
60
|
+
}),
|
|
61
|
+
edit: commonTool('edit', {
|
|
62
|
+
nativeName: 'search_replace',
|
|
63
|
+
toolUseKind: 'edit',
|
|
64
|
+
inputSchema: z.looseObject({
|
|
65
|
+
file_path: z.string(),
|
|
66
|
+
old_string: z.string(),
|
|
67
|
+
new_string: z.string(),
|
|
68
|
+
replace_all: z.boolean().optional(),
|
|
69
|
+
}),
|
|
70
|
+
}),
|
|
71
|
+
grep: commonTool('grep', {
|
|
72
|
+
nativeName: 'grep',
|
|
73
|
+
toolUseKind: 'readonly',
|
|
74
|
+
inputSchema: z.looseObject({
|
|
75
|
+
pattern: z.string(),
|
|
76
|
+
path: z.string().nullable().optional(),
|
|
77
|
+
glob: z.string().nullable().optional(),
|
|
78
|
+
'-B': z.number().int().optional(),
|
|
79
|
+
'-A': z.number().int().optional(),
|
|
80
|
+
'-C': z.number().int().optional(),
|
|
81
|
+
'-i': z.boolean().optional(),
|
|
82
|
+
type: z.string().nullable().optional(),
|
|
83
|
+
head_limit: z.number().int().optional(),
|
|
84
|
+
multiline: z.boolean().optional(),
|
|
85
|
+
}),
|
|
86
|
+
}),
|
|
87
|
+
webSearch: commonTool('webSearch', {
|
|
88
|
+
nativeName: 'web_search',
|
|
89
|
+
toolUseKind: 'readonly',
|
|
90
|
+
inputSchema: z.looseObject({
|
|
91
|
+
query: z.string(),
|
|
92
|
+
allowed_domains: z.array(z.string()).nullable().optional(),
|
|
93
|
+
}),
|
|
94
|
+
}),
|
|
95
|
+
write: commonTool('write', {
|
|
96
|
+
nativeName: 'write',
|
|
97
|
+
toolUseKind: 'edit',
|
|
98
|
+
inputSchema: z.looseObject({
|
|
99
|
+
file_path: z.string(),
|
|
100
|
+
content: z.string(),
|
|
101
|
+
}),
|
|
102
|
+
}),
|
|
103
|
+
read_file: {
|
|
104
|
+
...tool({
|
|
105
|
+
inputSchema: z.looseObject({
|
|
106
|
+
target_file: z.string(),
|
|
107
|
+
offset: z.number().int().optional(),
|
|
108
|
+
limit: z.number().int().optional(),
|
|
109
|
+
pages: z.string().nullable().optional(),
|
|
110
|
+
format: z.string().nullable().optional(),
|
|
111
|
+
}),
|
|
112
|
+
}),
|
|
113
|
+
toolUseKind: 'readonly',
|
|
114
|
+
},
|
|
115
|
+
list_dir: {
|
|
116
|
+
...tool({
|
|
117
|
+
inputSchema: z.looseObject({
|
|
118
|
+
target_directory: z.string(),
|
|
119
|
+
}),
|
|
120
|
+
}),
|
|
121
|
+
toolUseKind: 'readonly',
|
|
122
|
+
},
|
|
123
|
+
kill_command_or_subagent: tool({
|
|
124
|
+
inputSchema: z.looseObject({
|
|
125
|
+
task_id: z.string(),
|
|
126
|
+
}),
|
|
127
|
+
}),
|
|
128
|
+
todo_write: tool({
|
|
129
|
+
inputSchema: z.looseObject({
|
|
130
|
+
merge: z.boolean().optional(),
|
|
131
|
+
todos: z.array(
|
|
132
|
+
z.looseObject({
|
|
133
|
+
id: z.string(),
|
|
134
|
+
content: z.string().nullable().optional(),
|
|
135
|
+
status: z
|
|
136
|
+
.enum(['pending', 'in_progress', 'completed', 'cancelled'])
|
|
137
|
+
.nullable()
|
|
138
|
+
.optional(),
|
|
139
|
+
}),
|
|
140
|
+
),
|
|
141
|
+
}),
|
|
142
|
+
}),
|
|
143
|
+
get_command_or_subagent_output: {
|
|
144
|
+
...tool({
|
|
145
|
+
inputSchema: z.looseObject({
|
|
146
|
+
task_ids: z.array(z.string()).optional(),
|
|
147
|
+
timeout_ms: z.number().int().nonnegative().nullable().optional(),
|
|
148
|
+
}),
|
|
149
|
+
}),
|
|
150
|
+
toolUseKind: 'readonly',
|
|
151
|
+
},
|
|
152
|
+
spawn_subagent: tool({
|
|
153
|
+
inputSchema: z.looseObject({
|
|
154
|
+
prompt: z.string(),
|
|
155
|
+
description: z.string(),
|
|
156
|
+
subagent_type: z.string().optional(),
|
|
157
|
+
background: z.boolean().optional(),
|
|
158
|
+
capability_mode: z
|
|
159
|
+
.enum(['read-only', 'read-write', 'execute', 'all'])
|
|
160
|
+
.nullable()
|
|
161
|
+
.optional(),
|
|
162
|
+
isolation: z.enum(['none', 'worktree']).nullable().optional(),
|
|
163
|
+
resume_from: z.string().nullable().optional(),
|
|
164
|
+
cwd: z.string().nullable().optional(),
|
|
165
|
+
model: z.string().nullable().optional(),
|
|
166
|
+
}),
|
|
167
|
+
}),
|
|
168
|
+
scheduler_create: tool({
|
|
169
|
+
inputSchema: z.looseObject({
|
|
170
|
+
task_id: z.string().nullable().optional(),
|
|
171
|
+
interval: z.string().nullable().optional(),
|
|
172
|
+
prompt: z.string().nullable().optional(),
|
|
173
|
+
durable: z.boolean().nullable().optional(),
|
|
174
|
+
foreground: z.boolean().nullable().optional(),
|
|
175
|
+
fire_immediately: z.boolean().optional(),
|
|
176
|
+
}),
|
|
177
|
+
}),
|
|
178
|
+
scheduler_delete: tool({
|
|
179
|
+
inputSchema: z.looseObject({ id: z.string() }),
|
|
180
|
+
}),
|
|
181
|
+
scheduler_list: {
|
|
182
|
+
...tool({ inputSchema: z.looseObject({}) }),
|
|
183
|
+
toolUseKind: 'readonly',
|
|
184
|
+
},
|
|
185
|
+
monitor: tool({
|
|
186
|
+
inputSchema: z.looseObject({
|
|
187
|
+
command: z.string(),
|
|
188
|
+
description: z.string(),
|
|
189
|
+
timeout_ms: z.number().int().nonnegative().nullable().optional(),
|
|
190
|
+
persistent: z.boolean().optional(),
|
|
191
|
+
}),
|
|
192
|
+
}),
|
|
193
|
+
search_tool: {
|
|
194
|
+
...tool({
|
|
195
|
+
inputSchema: z.looseObject({
|
|
196
|
+
query: z.string(),
|
|
197
|
+
limit: z.number().int().min(0).max(255).nullable().optional(),
|
|
198
|
+
}),
|
|
199
|
+
}),
|
|
200
|
+
toolUseKind: 'readonly',
|
|
201
|
+
},
|
|
202
|
+
use_tool: tool({
|
|
203
|
+
inputSchema: z.looseObject({
|
|
204
|
+
tool_name: z.string(),
|
|
205
|
+
tool_input: z.looseObject({}),
|
|
206
|
+
}),
|
|
207
|
+
}),
|
|
208
|
+
workflow: tool({
|
|
209
|
+
inputSchema: z.looseObject({
|
|
210
|
+
agent_budget: z.number().int().min(1).max(1024).nullable().optional(),
|
|
211
|
+
name: z.string().nullable().optional(),
|
|
212
|
+
script: z.string().nullable().optional(),
|
|
213
|
+
script_path: z.string().nullable().optional(),
|
|
214
|
+
args: z.unknown().optional(),
|
|
215
|
+
resume_from_run_id: z.string().nullable().optional(),
|
|
216
|
+
validate_only: z.boolean().optional(),
|
|
217
|
+
}),
|
|
218
|
+
}),
|
|
219
|
+
enter_plan_mode: tool({ inputSchema: z.looseObject({}) }),
|
|
220
|
+
exit_plan_mode: tool({ inputSchema: z.looseObject({}) }),
|
|
221
|
+
ask_user_question: tool({
|
|
222
|
+
inputSchema: z.looseObject({
|
|
223
|
+
questions: z.array(
|
|
224
|
+
z.looseObject({
|
|
225
|
+
question: z.string(),
|
|
226
|
+
options: z.array(
|
|
227
|
+
z.looseObject({
|
|
228
|
+
label: z.string(),
|
|
229
|
+
description: z.string(),
|
|
230
|
+
preview: z.string().nullable().optional(),
|
|
231
|
+
}),
|
|
232
|
+
),
|
|
233
|
+
multi_select: z.boolean().nullable().optional(),
|
|
234
|
+
}),
|
|
235
|
+
),
|
|
236
|
+
}),
|
|
237
|
+
}),
|
|
238
|
+
image_gen: tool({
|
|
239
|
+
inputSchema: z.looseObject({
|
|
240
|
+
prompt: z.string(),
|
|
241
|
+
aspect_ratio: z.string().optional(),
|
|
242
|
+
}),
|
|
243
|
+
}),
|
|
244
|
+
image_edit: tool({
|
|
245
|
+
inputSchema: z.looseObject({
|
|
246
|
+
prompt: z.string(),
|
|
247
|
+
image: z.array(z.string()),
|
|
248
|
+
aspect_ratio: z.string().optional(),
|
|
249
|
+
}),
|
|
250
|
+
}),
|
|
251
|
+
image_to_video: tool({
|
|
252
|
+
inputSchema: z.looseObject({
|
|
253
|
+
prompt: z.string().nullable().optional(),
|
|
254
|
+
image: z.string(),
|
|
255
|
+
duration: z.number().int().nonnegative().nullable().optional(),
|
|
256
|
+
resolution_name: z.string().optional(),
|
|
257
|
+
}),
|
|
258
|
+
}),
|
|
259
|
+
reference_to_video: tool({
|
|
260
|
+
inputSchema: z.looseObject({
|
|
261
|
+
prompt: z.string(),
|
|
262
|
+
images: z.array(z.string()),
|
|
263
|
+
aspect_ratio: z.string(),
|
|
264
|
+
duration: z.number().int().nonnegative().nullable().optional(),
|
|
265
|
+
resolution_name: z.string().optional(),
|
|
266
|
+
}),
|
|
267
|
+
}),
|
|
268
|
+
} as const satisfies Record<string, HarnessV1BuiltinTool<any, any>>;
|
|
269
|
+
|
|
270
|
+
export function createGrokBuild(
|
|
271
|
+
settings: GrokBuildHarnessSettings = {},
|
|
272
|
+
): HarnessV1<typeof GROK_BUILD_BUILTIN_TOOLS> {
|
|
273
|
+
const clientAppSegments = GROK_BUILD_CLIENT_APP.split('/');
|
|
274
|
+
const clientAppVersion = clientAppSegments.pop()!;
|
|
275
|
+
|
|
276
|
+
return createACP({
|
|
277
|
+
auth: settings.auth,
|
|
278
|
+
modelId: settings.model,
|
|
279
|
+
port: settings.port,
|
|
280
|
+
startupTimeoutMs: settings.startupTimeoutMs,
|
|
281
|
+
version: 'v1',
|
|
282
|
+
harnessId: 'grok-build',
|
|
283
|
+
builtinTools: GROK_BUILD_BUILTIN_TOOLS,
|
|
284
|
+
clientApp: {
|
|
285
|
+
name: clientAppSegments.join('/'),
|
|
286
|
+
version: clientAppVersion,
|
|
287
|
+
},
|
|
288
|
+
source: {
|
|
289
|
+
type: 'npm-locked',
|
|
290
|
+
packageJson: GROK_BUILD_IMPLEMENTATION_PACKAGE_JSON,
|
|
291
|
+
pnpmLockYaml: GROK_BUILD_IMPLEMENTATION_PNPM_LOCK,
|
|
292
|
+
},
|
|
293
|
+
executable: 'grok',
|
|
294
|
+
args: ['agent', 'stdio'],
|
|
295
|
+
forwardEnv: ['XAI_API_KEY'],
|
|
296
|
+
providerAuthentication: {
|
|
297
|
+
gateway: {
|
|
298
|
+
env: {
|
|
299
|
+
GROK_CLIENT_NAME: { $source: 'client-app-name' },
|
|
300
|
+
GROK_CLIENT_VERSION: { $source: 'client-app-version' },
|
|
301
|
+
XAI_API_KEY: { $source: 'gateway-api-key' },
|
|
302
|
+
GROK_XAI_API_BASE_URL: {
|
|
303
|
+
$source: 'gateway-base-url',
|
|
304
|
+
ensureSuffix: '/v1',
|
|
305
|
+
},
|
|
306
|
+
GROK_MODELS_BASE_URL: {
|
|
307
|
+
$source: 'gateway-base-url',
|
|
308
|
+
ensureSuffix: '/v1',
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createGrokBuild } from './grok-build-harness';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Default Grok Build harness instance. Equivalent to `createGrokBuild()`.
|
|
5
|
+
*/
|
|
6
|
+
export const grokBuild = createGrokBuild();
|
|
7
|
+
|
|
8
|
+
export { createGrokBuild } from './grok-build-harness';
|
|
9
|
+
export type { GrokBuildHarnessSettings } from './grok-build-harness';
|
|
10
|
+
export { VERSION } from './version';
|
package/src/version.ts
ADDED
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|