@ai-sdk/harness-opencode 1.0.177 → 1.0.178
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 +11 -0
- package/dist/bridge/host-tool-mcp.mjs.map +1 -1
- package/dist/bridge/index.mjs +24 -2
- package/dist/bridge/index.mjs.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -15
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/bridge/index.ts +13 -0
- package/src/opencode-harness.ts +7 -1
- package/src/opencode-subscription.ts +26 -14
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.178",
|
|
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.175",
|
|
30
30
|
"@ai-sdk/provider": "4.0.36",
|
|
31
31
|
"@ai-sdk/provider-utils": "5.0.75",
|
|
32
32
|
"ws": "8.21.0"
|
package/src/bridge/index.ts
CHANGED
|
@@ -196,6 +196,9 @@ procEnv.OPENCODE_DISABLE_PROJECT_CONFIG = '1';
|
|
|
196
196
|
await runBridge<StartMessage>({
|
|
197
197
|
bridgeType: 'opencode',
|
|
198
198
|
bridgeStateDir,
|
|
199
|
+
...(args.hostDisconnectTimeoutMs !== undefined
|
|
200
|
+
? { hostDisconnectTimeoutMs: args.hostDisconnectTimeoutMs }
|
|
201
|
+
: {}),
|
|
199
202
|
onStart: runTurn,
|
|
200
203
|
onStop: () =>
|
|
201
204
|
runtime.sessionId ? { openCodeSessionId: runtime.sessionId } : {},
|
|
@@ -474,6 +477,9 @@ function buildProviderConfig(
|
|
|
474
477
|
if (procEnv.AI_GATEWAY_API_KEY && procEnv.AI_GATEWAY_BASE_URL) {
|
|
475
478
|
return {
|
|
476
479
|
[providerID]: {
|
|
480
|
+
...(providerID === 'google' || providerID === 'mistral'
|
|
481
|
+
? { npm: '@ai-sdk/openai-compatible' }
|
|
482
|
+
: {}),
|
|
477
483
|
options: {
|
|
478
484
|
apiKey: procEnv.AI_GATEWAY_API_KEY,
|
|
479
485
|
baseURL: toOpenCodeGatewayBaseUrl(procEnv.AI_GATEWAY_BASE_URL),
|
|
@@ -2221,18 +2227,25 @@ function parseArgs(args: string[]): {
|
|
|
2221
2227
|
bridgeStateDir?: string;
|
|
2222
2228
|
bootstrapDir?: string;
|
|
2223
2229
|
skillsDir?: string;
|
|
2230
|
+
hostDisconnectTimeoutMs?: number;
|
|
2224
2231
|
} {
|
|
2225
2232
|
const out: {
|
|
2226
2233
|
workdir?: string;
|
|
2227
2234
|
bridgeStateDir?: string;
|
|
2228
2235
|
bootstrapDir?: string;
|
|
2229
2236
|
skillsDir?: string;
|
|
2237
|
+
hostDisconnectTimeoutMs?: number;
|
|
2230
2238
|
} = {};
|
|
2231
2239
|
for (let i = 0; i < args.length; i++) {
|
|
2232
2240
|
if (args[i] === '--workdir' && i + 1 < args.length) {
|
|
2233
2241
|
out.workdir = args[++i];
|
|
2234
2242
|
} else if (args[i] === '--bridge-state-dir' && i + 1 < args.length) {
|
|
2235
2243
|
out.bridgeStateDir = args[++i];
|
|
2244
|
+
} else if (
|
|
2245
|
+
args[i] === '--host-disconnect-timeout-ms' &&
|
|
2246
|
+
i + 1 < args.length
|
|
2247
|
+
) {
|
|
2248
|
+
out.hostDisconnectTimeoutMs = Number(args[++i]);
|
|
2236
2249
|
} else if (args[i] === '--bootstrap-dir' && i + 1 < args.length) {
|
|
2237
2250
|
out.bootstrapDir = args[++i];
|
|
2238
2251
|
} else if (args[i] === '--skills-dir' && i + 1 < args.length) {
|
package/src/opencode-harness.ts
CHANGED
|
@@ -125,6 +125,12 @@ export type OpenCodeHarnessSettings = {
|
|
|
125
125
|
*/
|
|
126
126
|
readonly portEndpoint?: HarnessV1PortEndpoint;
|
|
127
127
|
readonly startupTimeoutMs?: number;
|
|
128
|
+
/**
|
|
129
|
+
* Abort a running turn when its host disconnects and does not reconnect
|
|
130
|
+
* within this many milliseconds, so the turn stops spending. A suspended
|
|
131
|
+
* turn is exempt. Unset keeps the turn running until it finishes.
|
|
132
|
+
*/
|
|
133
|
+
readonly hostDisconnectTimeoutMs?: number;
|
|
128
134
|
/**
|
|
129
135
|
* Configures reconnection attempts after an established bridge connection
|
|
130
136
|
* drops. The reconnect window includes connection establishment and
|
|
@@ -579,7 +585,7 @@ export function createOpenCode(
|
|
|
579
585
|
});
|
|
580
586
|
|
|
581
587
|
const proc = await toolSafeSandboxSession.spawn({
|
|
582
|
-
command: `node ${shellQuote(`${bootstrapDir}/bridge.mjs`)} --workdir ${shellQuote(workDir)} --bridge-state-dir ${shellQuote(bridgeStateDir)} --bootstrap-dir ${shellQuote(bootstrapDir)} --skills-dir ${shellQuote(skillsDir)}`,
|
|
588
|
+
command: `node ${shellQuote(`${bootstrapDir}/bridge.mjs`)} --workdir ${shellQuote(workDir)} --bridge-state-dir ${shellQuote(bridgeStateDir)} --bootstrap-dir ${shellQuote(bootstrapDir)} --skills-dir ${shellQuote(skillsDir)}${settings.hostDisconnectTimeoutMs !== undefined ? ` --host-disconnect-timeout-ms ${shellQuote(String(settings.hostDisconnectTimeoutMs))}` : ''}`,
|
|
583
589
|
env,
|
|
584
590
|
abortSignal: startOpts.abortSignal,
|
|
585
591
|
});
|
|
@@ -255,7 +255,7 @@ export async function readOpenCodeSubscription({
|
|
|
255
255
|
fetch?: typeof globalThis.fetch;
|
|
256
256
|
}): Promise<OpenCodeSubscription | undefined> {
|
|
257
257
|
if (!isSubscriptionProvider(providerId)) return undefined;
|
|
258
|
-
const stored = await readStore({ env, homeDirectory, platform });
|
|
258
|
+
const stored = await readStore({ providerId, env, homeDirectory, platform });
|
|
259
259
|
if (stored == null) return undefined;
|
|
260
260
|
const candidate = stored.value[providerId];
|
|
261
261
|
if (!isRecord(candidate)) return undefined;
|
|
@@ -661,10 +661,12 @@ async function extractOpenAIAccountId(
|
|
|
661
661
|
}
|
|
662
662
|
|
|
663
663
|
async function readStore({
|
|
664
|
+
providerId,
|
|
664
665
|
env,
|
|
665
666
|
homeDirectory,
|
|
666
667
|
platform,
|
|
667
668
|
}: {
|
|
669
|
+
providerId: string;
|
|
668
670
|
env: Readonly<Record<string, string | undefined>>;
|
|
669
671
|
homeDirectory: string;
|
|
670
672
|
platform: NodeJS.Platform;
|
|
@@ -681,20 +683,30 @@ async function readStore({
|
|
|
681
683
|
? { value: parsed.value }
|
|
682
684
|
: undefined;
|
|
683
685
|
}
|
|
684
|
-
|
|
686
|
+
// OpenCode keeps auth.json in its XDG data directory on every platform,
|
|
687
|
+
// including Windows. The GitLab auth plugin (before v3) writes to
|
|
688
|
+
// `~/.opencode` on Windows instead, so that store is checked as a fallback.
|
|
689
|
+
const authPaths =
|
|
685
690
|
env.XDG_DATA_HOME != null
|
|
686
|
-
? join(env.XDG_DATA_HOME, 'opencode', 'auth.json')
|
|
687
|
-
:
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
691
|
+
? [join(env.XDG_DATA_HOME, 'opencode', 'auth.json')]
|
|
692
|
+
: [
|
|
693
|
+
join(homeDirectory, '.local', 'share', 'opencode', 'auth.json'),
|
|
694
|
+
...(isWindows(platform)
|
|
695
|
+
? [join(homeDirectory, '.opencode', 'auth.json')]
|
|
696
|
+
: []),
|
|
697
|
+
];
|
|
698
|
+
for (const authPath of authPaths) {
|
|
699
|
+
const text = await readFile(authPath, 'utf8').catch(() => undefined);
|
|
700
|
+
if (text == null) continue;
|
|
701
|
+
const parsed = await safeParseJSON({ text });
|
|
702
|
+
if (!parsed.success || !isRecord(parsed.value)) continue;
|
|
703
|
+
if (!isRecord(parsed.value[providerId])) continue;
|
|
704
|
+
return {
|
|
705
|
+
value: parsed.value,
|
|
706
|
+
write: value => writeStore({ authPath, value }),
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
return undefined;
|
|
698
710
|
}
|
|
699
711
|
|
|
700
712
|
async function writeStore({
|