@ai-sdk/harness-opencode 1.0.64 → 1.0.66

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.
@@ -67,6 +67,11 @@ const OPENCODE_CLIENT_APP = `ai-sdk/harness-opencode/${VERSION}`;
67
67
 
68
68
  export type OpenCodeHarnessSettings = {
69
69
  readonly auth?: OpenCodeAuthOptions;
70
+ /**
71
+ * MCP server definitions keyed by server name. Each definition uses the
72
+ * underlying runtime's native MCP server configuration format.
73
+ */
74
+ readonly mcpServers?: Record<string, unknown>;
70
75
  readonly model?: string;
71
76
  readonly provider?: string;
72
77
  /**
@@ -77,6 +82,11 @@ export type OpenCodeHarnessSettings = {
77
82
  readonly reasoningVariant?: string;
78
83
  readonly port?: number;
79
84
  readonly startupTimeoutMs?: number;
85
+ /**
86
+ * Creates the authentication token used by the sandbox bridge. Defaults to
87
+ * a random 32-byte hexadecimal token.
88
+ */
89
+ readonly mintBridgeToken?: (sandboxId: string) => string;
80
90
  };
81
91
 
82
92
  const optionalStringRecord = z.record(z.string(), z.unknown()).optional();
@@ -201,6 +211,14 @@ type OpenCodeBridgeCoords = z.infer<typeof openCodeBridgeCoordsSchema>;
201
211
  export function createOpenCode(
202
212
  settings: OpenCodeHarnessSettings = {},
203
213
  ): HarnessV1<typeof OPENCODE_BUILTIN_TOOLS> {
214
+ if (
215
+ settings.mcpServers != null &&
216
+ Object.prototype.hasOwnProperty.call(settings.mcpServers, 'harness-tools')
217
+ ) {
218
+ throw new Error(
219
+ 'OpenCode MCP server name "harness-tools" is reserved for HarnessAgent tools.',
220
+ );
221
+ }
204
222
  let cachedBootstrap: HarnessV1Bootstrap | undefined;
205
223
 
206
224
  return {
@@ -309,6 +327,7 @@ export function createOpenCode(
309
327
  model,
310
328
  provider: settings.provider,
311
329
  reasoningVariant: settings.reasoningVariant,
330
+ mcpServers: settings.mcpServers,
312
331
  openCodeSessionId: resumeSessionId,
313
332
  isResume: true,
314
333
  seedResumeSessionOnFirstPrompt: false,
@@ -339,7 +358,10 @@ export function createOpenCode(
339
358
  }
340
359
 
341
360
  const port = resolveBridgePort(sandboxSession, settings.port);
342
- const token = randomBytes(32).toString('hex');
361
+ const token =
362
+ settings.mintBridgeToken == null
363
+ ? randomBytes(32).toString('hex')
364
+ : settings.mintBridgeToken(sandboxId);
343
365
  const sandboxHomeDir = await resolveSandboxHomeDir({
344
366
  sandbox: session,
345
367
  abortSignal: startOpts.abortSignal,
@@ -456,6 +478,7 @@ export function createOpenCode(
456
478
  model,
457
479
  provider: settings.provider,
458
480
  reasoningVariant: settings.reasoningVariant,
481
+ mcpServers: settings.mcpServers,
459
482
  openCodeSessionId: resumeSessionId,
460
483
  isResume: respawnStrategy !== undefined,
461
484
  seedResumeSessionOnFirstPrompt: respawnStrategy !== undefined,
@@ -552,6 +575,7 @@ function createSession({
552
575
  model,
553
576
  provider,
554
577
  reasoningVariant,
578
+ mcpServers,
555
579
  openCodeSessionId,
556
580
  isResume,
557
581
  seedResumeSessionOnFirstPrompt,
@@ -569,6 +593,7 @@ function createSession({
569
593
  model: string | undefined;
570
594
  provider: string | undefined;
571
595
  reasoningVariant: string | undefined;
596
+ mcpServers: Record<string, unknown> | undefined;
572
597
  openCodeSessionId: string | undefined;
573
598
  isResume: boolean;
574
599
  seedResumeSessionOnFirstPrompt: boolean;
@@ -729,6 +754,7 @@ function createSession({
729
754
  model,
730
755
  provider,
731
756
  ...(reasoningVariant ? { variant: reasoningVariant } : {}),
757
+ ...(mcpServers == null ? {} : { mcpServers }),
732
758
  ...(permissionMode ? { permissionMode } : {}),
733
759
  ...(builtinToolFiltering ? { builtinToolFiltering } : {}),
734
760
  ...(pendingResumeSessionId
@@ -808,6 +834,7 @@ function createSession({
808
834
  provider,
809
835
  permissionMode,
810
836
  debug,
837
+ mcpServers,
811
838
  resumeSessionId: latestOpenCodeSessionId,
812
839
  onCompaction: part => pendingCompactionParts.push(part),
813
840
  });
@@ -964,6 +991,7 @@ async function runCompactOperation({
964
991
  provider,
965
992
  permissionMode,
966
993
  debug,
994
+ mcpServers,
967
995
  resumeSessionId,
968
996
  onCompaction,
969
997
  }: {
@@ -972,6 +1000,7 @@ async function runCompactOperation({
972
1000
  provider: string | undefined;
973
1001
  permissionMode: HarnessV1PermissionMode | undefined;
974
1002
  debug: HarnessV1DebugConfig | undefined;
1003
+ mcpServers: Record<string, unknown> | undefined;
975
1004
  resumeSessionId: string | undefined;
976
1005
  onCompaction: (part: HarnessV1StreamPart) => void;
977
1006
  }): Promise<void> {
@@ -999,6 +1028,7 @@ async function runCompactOperation({
999
1028
  tools: [],
1000
1029
  model,
1001
1030
  provider,
1031
+ ...(mcpServers == null ? {} : { mcpServers }),
1002
1032
  ...(permissionMode ? { permissionMode } : {}),
1003
1033
  ...(resumeSessionId ? { resumeSessionId } : {}),
1004
1034
  ...(debug ? { debug } : {}),