@ai-sdk/harness-opencode 1.0.152 → 1.0.154
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 +21 -0
- package/dist/bridge/host-tool-mcp.mjs +87 -5
- package/dist/bridge/host-tool-mcp.mjs.map +1 -1
- package/dist/bridge/index.mjs +262 -72
- package/dist/bridge/index.mjs.map +1 -1
- package/dist/bridge/package.json +1 -0
- package/dist/bridge/pnpm-lock.yaml +117 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +53 -8
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/bridge/create-emit-stream-event.ts +37 -0
- package/src/bridge/host-tool-mcp.ts +29 -1
- package/src/bridge/index.ts +247 -108
- package/src/bridge/opencode-host-input-tracker.ts +106 -0
- package/src/bridge/opencode-path.ts +3 -1
- package/src/bridge/package.json +1 -0
- package/src/bridge/pnpm-lock.yaml +117 -0
- package/src/bridge/tool-relay.ts +15 -5
- package/src/opencode-bridge-protocol.ts +33 -11
- package/src/opencode-harness.ts +49 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/harness-opencode",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.154",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@ai-sdk/harness": "1.0.
|
|
29
|
+
"@ai-sdk/harness": "1.0.152",
|
|
30
30
|
"@ai-sdk/provider": "4.0.27",
|
|
31
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
31
|
+
"@ai-sdk/provider-utils": "5.0.60",
|
|
32
32
|
"ws": "8.21.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"@types/node": "22.19.19",
|
|
41
41
|
"@types/ws": "^8.5.13",
|
|
42
42
|
"@vercel/ai-tsconfig": "0.0.0",
|
|
43
|
+
"@vscode/ripgrep": "1.18.0",
|
|
43
44
|
"tsdown": "^0.23.0",
|
|
44
45
|
"typescript": "6.0.3",
|
|
45
46
|
"zod": "3.25.76"
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
mapOpenCodeFinishReason,
|
|
12
12
|
translateLegacyStepFinishPart,
|
|
13
13
|
} from './opencode-finish-step';
|
|
14
|
+
import type { OpenCodeHostInputGroup } from './opencode-host-input-tracker';
|
|
14
15
|
import { mapUsage } from './opencode-usage';
|
|
15
16
|
import {
|
|
16
17
|
asOpenCodeObject,
|
|
@@ -35,6 +36,7 @@ export function createEmitStreamEvent({
|
|
|
35
36
|
getHostToolName,
|
|
36
37
|
authorizeHostToolCall,
|
|
37
38
|
onSubagentSession,
|
|
39
|
+
onToolCallStatus,
|
|
38
40
|
isMcpToolName,
|
|
39
41
|
stripWorkDir,
|
|
40
42
|
formatError,
|
|
@@ -57,6 +59,7 @@ export function createEmitStreamEvent({
|
|
|
57
59
|
input: unknown;
|
|
58
60
|
}) => void;
|
|
59
61
|
onSubagentSession?: (session: SubagentSession) => void;
|
|
62
|
+
onToolCallStatus?: OnToolCallStatus;
|
|
60
63
|
isMcpToolName: (toolName: string) => boolean;
|
|
61
64
|
stripWorkDir: (file: string) => string;
|
|
62
65
|
formatError: (error: unknown) => string;
|
|
@@ -171,6 +174,7 @@ export function createEmitStreamEvent({
|
|
|
171
174
|
getHostToolName,
|
|
172
175
|
authorizeHostToolCall,
|
|
173
176
|
onSubagentSession,
|
|
177
|
+
onToolCallStatus,
|
|
174
178
|
isMcpToolName,
|
|
175
179
|
});
|
|
176
180
|
return;
|
|
@@ -241,6 +245,7 @@ export function createEmitStreamEvent({
|
|
|
241
245
|
const callID = String(props.callID ?? event.id);
|
|
242
246
|
const command = String(props.command ?? '');
|
|
243
247
|
state.shellCommands.set(callID, command);
|
|
248
|
+
onToolCallStatus?.({ callID, status: 'started', group: undefined });
|
|
244
249
|
emit({
|
|
245
250
|
type: 'tool-call',
|
|
246
251
|
toolCallId: callID,
|
|
@@ -253,6 +258,7 @@ export function createEmitStreamEvent({
|
|
|
253
258
|
}
|
|
254
259
|
if (type === 'session.next.shell.ended') {
|
|
255
260
|
const callID = String(props.callID ?? event.id);
|
|
261
|
+
onToolCallStatus?.({ callID, status: 'settled', group: undefined });
|
|
256
262
|
emit({
|
|
257
263
|
type: 'tool-result',
|
|
258
264
|
toolCallId: callID,
|
|
@@ -288,6 +294,11 @@ export function createEmitStreamEvent({
|
|
|
288
294
|
const toolName = toWireToolName(rawToolName);
|
|
289
295
|
state.toolNames.set(callID, { rawToolName, toolName });
|
|
290
296
|
const hostToolName = getHostToolName(toolName, props.tool);
|
|
297
|
+
onToolCallStatus?.({
|
|
298
|
+
callID,
|
|
299
|
+
status: 'started',
|
|
300
|
+
group: toolCallGroup({ hostToolName, toolName }),
|
|
301
|
+
});
|
|
291
302
|
if (hostToolName) {
|
|
292
303
|
authorizeHostToolCall({
|
|
293
304
|
callID,
|
|
@@ -325,6 +336,7 @@ export function createEmitStreamEvent({
|
|
|
325
336
|
}
|
|
326
337
|
const toolName =
|
|
327
338
|
cachedTool?.toolName ?? toWireToolName(rawToolName || 'unknown');
|
|
339
|
+
onToolCallStatus?.({ callID, status: 'settled', group: undefined });
|
|
328
340
|
if (getHostToolName(toolName, rawToolName)) return;
|
|
329
341
|
emit({
|
|
330
342
|
type: 'tool-result',
|
|
@@ -403,6 +415,24 @@ export function createEmitStreamEvent({
|
|
|
403
415
|
};
|
|
404
416
|
}
|
|
405
417
|
|
|
418
|
+
type OnToolCallStatus = (input: {
|
|
419
|
+
callID: string;
|
|
420
|
+
status: 'started' | 'settled';
|
|
421
|
+
group: OpenCodeHostInputGroup | undefined;
|
|
422
|
+
}) => void;
|
|
423
|
+
|
|
424
|
+
function toolCallGroup({
|
|
425
|
+
hostToolName,
|
|
426
|
+
toolName,
|
|
427
|
+
}: {
|
|
428
|
+
hostToolName: string | undefined;
|
|
429
|
+
toolName: string;
|
|
430
|
+
}): OpenCodeHostInputGroup | undefined {
|
|
431
|
+
if (hostToolName) return 'host-tool';
|
|
432
|
+
if (toolName === 'agent') return 'subagent';
|
|
433
|
+
return undefined;
|
|
434
|
+
}
|
|
435
|
+
|
|
406
436
|
function closeLegacyOpenParts({
|
|
407
437
|
state,
|
|
408
438
|
emit,
|
|
@@ -453,6 +483,7 @@ function emitLegacyToolPart({
|
|
|
453
483
|
getHostToolName,
|
|
454
484
|
authorizeHostToolCall,
|
|
455
485
|
onSubagentSession,
|
|
486
|
+
onToolCallStatus,
|
|
456
487
|
isMcpToolName,
|
|
457
488
|
}: {
|
|
458
489
|
part: unknown;
|
|
@@ -472,6 +503,7 @@ function emitLegacyToolPart({
|
|
|
472
503
|
input: unknown;
|
|
473
504
|
}) => void;
|
|
474
505
|
onSubagentSession?: (session: SubagentSession) => void;
|
|
506
|
+
onToolCallStatus?: OnToolCallStatus;
|
|
475
507
|
isMcpToolName: (toolName: string) => boolean;
|
|
476
508
|
}): void {
|
|
477
509
|
const toolPart = legacyToolPartFromValue(part);
|
|
@@ -497,6 +529,11 @@ function emitLegacyToolPart({
|
|
|
497
529
|
}
|
|
498
530
|
state.toolNames.set(callID, { rawToolName, toolName });
|
|
499
531
|
const hostToolName = getHostToolName(toolName, rawToolName);
|
|
532
|
+
onToolCallStatus?.({
|
|
533
|
+
callID,
|
|
534
|
+
status: status === 'running' ? 'started' : 'settled',
|
|
535
|
+
group: toolCallGroup({ hostToolName, toolName }),
|
|
536
|
+
});
|
|
500
537
|
if (hostToolName) {
|
|
501
538
|
if (status === 'running') {
|
|
502
539
|
authorizeHostToolCall({
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
8
8
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
9
|
+
import {
|
|
10
|
+
convertHarnessToolModelOutput,
|
|
11
|
+
type BridgeTurn,
|
|
12
|
+
} from '@ai-sdk/harness/bridge';
|
|
9
13
|
import { readHostToolSchemasFromEnvironment } from './host-tool-schemas';
|
|
10
14
|
import { jsonSchemaToZodShape } from './json-schema-to-zod';
|
|
11
15
|
|
|
@@ -43,7 +47,30 @@ for (const schema of schemas) {
|
|
|
43
47
|
`Tool relay ${schema.name} failed with ${res.status}: ${body.slice(0, 500)}`,
|
|
44
48
|
);
|
|
45
49
|
}
|
|
46
|
-
const data = (await res.json()) as {
|
|
50
|
+
const data = (await res.json()) as {
|
|
51
|
+
result?: unknown;
|
|
52
|
+
isError?: boolean;
|
|
53
|
+
toolResult?: Awaited<
|
|
54
|
+
ReturnType<BridgeTurn['requestToolResult']>
|
|
55
|
+
>['toolResult'];
|
|
56
|
+
};
|
|
57
|
+
if (data.toolResult != null) {
|
|
58
|
+
const converted = convertHarnessToolModelOutput({
|
|
59
|
+
output: data.toolResult.output,
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
content: converted.content.map(part =>
|
|
63
|
+
part.type === 'text'
|
|
64
|
+
? part
|
|
65
|
+
: {
|
|
66
|
+
type: 'image' as const,
|
|
67
|
+
data: part.data,
|
|
68
|
+
mimeType: part.mediaType,
|
|
69
|
+
},
|
|
70
|
+
),
|
|
71
|
+
isError: data.isError === true || converted.isError,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
47
74
|
return {
|
|
48
75
|
content: [
|
|
49
76
|
{
|
|
@@ -51,6 +78,7 @@ for (const schema of schemas) {
|
|
|
51
78
|
text: JSON.stringify(data.result ?? null),
|
|
52
79
|
},
|
|
53
80
|
],
|
|
81
|
+
...(data.isError === true ? { isError: true } : {}),
|
|
54
82
|
};
|
|
55
83
|
} catch (err) {
|
|
56
84
|
return {
|