@ai-sdk/harness-opencode 1.0.159 → 1.0.160
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 +7 -0
- package/dist/bridge/index.mjs +20 -6
- package/dist/bridge/index.mjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -17
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/bridge/index.ts +5 -3
- package/src/bridge/opencode-prompt.ts +17 -0
- package/src/opencode-bridge-protocol.ts +2 -0
- package/src/opencode-harness.ts +2 -19
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.160",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@ai-sdk/harness": "1.0.
|
|
29
|
+
"@ai-sdk/harness": "1.0.158",
|
|
30
30
|
"@ai-sdk/provider": "4.0.31",
|
|
31
31
|
"@ai-sdk/provider-utils": "5.0.64",
|
|
32
32
|
"ws": "8.21.0"
|
package/src/bridge/index.ts
CHANGED
|
@@ -59,6 +59,7 @@ import {
|
|
|
59
59
|
toOpenCodeQuestionResponse,
|
|
60
60
|
type OpenCodeQuestionRequest,
|
|
61
61
|
} from './question-tool';
|
|
62
|
+
import { toOpenCodePromptParts } from './opencode-prompt';
|
|
62
63
|
|
|
63
64
|
type Emit = (msg: Record<string, unknown>) => void;
|
|
64
65
|
|
|
@@ -551,12 +552,12 @@ async function legacySessionPrompt({
|
|
|
551
552
|
client,
|
|
552
553
|
sessionId,
|
|
553
554
|
start,
|
|
554
|
-
prompt
|
|
555
|
+
prompt,
|
|
555
556
|
}: {
|
|
556
557
|
client: OpenCodeClient;
|
|
557
558
|
sessionId: string;
|
|
558
559
|
start: StartMessage;
|
|
559
|
-
prompt
|
|
560
|
+
prompt: StartMessage['prompt'];
|
|
560
561
|
}): Promise<{ error?: unknown; data?: unknown }> {
|
|
561
562
|
const session = (client as any).session;
|
|
562
563
|
const submitPrompt = session.promptAsync ?? session.prompt;
|
|
@@ -573,7 +574,7 @@ async function legacySessionPrompt({
|
|
|
573
574
|
},
|
|
574
575
|
}
|
|
575
576
|
: {}),
|
|
576
|
-
parts:
|
|
577
|
+
parts: toOpenCodePromptParts(prompt),
|
|
577
578
|
});
|
|
578
579
|
}
|
|
579
580
|
|
|
@@ -885,6 +886,7 @@ async function runPrompt({
|
|
|
885
886
|
client,
|
|
886
887
|
sessionId,
|
|
887
888
|
start,
|
|
889
|
+
prompt: start.prompt,
|
|
888
890
|
});
|
|
889
891
|
} catch (error) {
|
|
890
892
|
promptRequestSettled.resolve(undefined);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { StartMessage } from '../opencode-bridge-protocol';
|
|
2
|
+
|
|
3
|
+
export function toOpenCodePromptParts(prompt: StartMessage['prompt']) {
|
|
4
|
+
if (typeof prompt === 'string') {
|
|
5
|
+
return [{ type: 'text' as const, text: prompt }];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return prompt.map(part =>
|
|
9
|
+
part.type === 'text'
|
|
10
|
+
? { type: 'text' as const, text: part.text }
|
|
11
|
+
: {
|
|
12
|
+
type: 'file' as const,
|
|
13
|
+
mime: part.mediaType,
|
|
14
|
+
url: `data:${part.mediaType};base64,${part.data}`,
|
|
15
|
+
},
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
harnessV1BridgeReadySchema,
|
|
5
5
|
harnessV1BridgeStartBaseSchema,
|
|
6
6
|
} from '@ai-sdk/harness';
|
|
7
|
+
import { harnessPromptContentSchema } from '@ai-sdk/harness/utils';
|
|
7
8
|
import { z } from 'zod/v4';
|
|
8
9
|
|
|
9
10
|
export const outboundMessageSchema = harnessV1BridgeOutboundMessageSchema;
|
|
@@ -31,6 +32,7 @@ export type OpenCodeBuiltinToolName = z.infer<
|
|
|
31
32
|
export const startMessageSchema = harnessV1BridgeStartBaseSchema
|
|
32
33
|
.omit({ builtinToolFiltering: true })
|
|
33
34
|
.extend({
|
|
35
|
+
prompt: harnessPromptContentSchema,
|
|
34
36
|
operation: z.enum(['prompt', 'compact']).optional(),
|
|
35
37
|
provider: z.string().optional(),
|
|
36
38
|
variant: z.string().optional(),
|
package/src/opencode-harness.ts
CHANGED
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
type HarnessV1MintBridgeTokenCallback,
|
|
15
15
|
type HarnessV1NetworkSandboxSession,
|
|
16
16
|
type HarnessV1PermissionMode,
|
|
17
|
-
type HarnessV1Prompt,
|
|
18
17
|
type HarnessV1PromptControl,
|
|
19
18
|
type HarnessV1ResponseFormat,
|
|
20
19
|
type HarnessV1PortEndpoint,
|
|
@@ -37,6 +36,7 @@ import {
|
|
|
37
36
|
drainBridgeProcessStream,
|
|
38
37
|
forwardBridgeProcessStream,
|
|
39
38
|
getRestrictedSandboxSession,
|
|
39
|
+
extractHarnessPromptContent,
|
|
40
40
|
markBridgeStarting,
|
|
41
41
|
resolveSandboxHomeDir,
|
|
42
42
|
SandboxChannel,
|
|
@@ -1218,7 +1218,7 @@ function createSession({
|
|
|
1218
1218
|
channel.send({
|
|
1219
1219
|
type: 'start',
|
|
1220
1220
|
operation: 'prompt',
|
|
1221
|
-
prompt:
|
|
1221
|
+
prompt: extractHarnessPromptContent({ prompt: promptOpts.prompt }),
|
|
1222
1222
|
tools: (promptOpts.tools ?? []).map(t => ({
|
|
1223
1223
|
name: t.name,
|
|
1224
1224
|
description: t.description,
|
|
@@ -1518,20 +1518,3 @@ async function runCompactOperation({
|
|
|
1518
1518
|
});
|
|
1519
1519
|
await done;
|
|
1520
1520
|
}
|
|
1521
|
-
|
|
1522
|
-
function extractUserText(prompt: HarnessV1Prompt): string {
|
|
1523
|
-
if (typeof prompt === 'string') return prompt;
|
|
1524
|
-
const { content } = prompt;
|
|
1525
|
-
if (typeof content === 'string') return content;
|
|
1526
|
-
const parts: string[] = [];
|
|
1527
|
-
for (const part of content) {
|
|
1528
|
-
if (part.type !== 'text') {
|
|
1529
|
-
throw new HarnessCapabilityUnsupportedError({
|
|
1530
|
-
harnessId: 'opencode',
|
|
1531
|
-
message: `The OpenCode harness does not yet support user message parts of type '${part.type}'. Pass a string or a user message whose content contains only text parts.`,
|
|
1532
|
-
});
|
|
1533
|
-
}
|
|
1534
|
-
parts.push(part.text);
|
|
1535
|
-
}
|
|
1536
|
-
return parts.join('\n\n');
|
|
1537
|
-
}
|