@ai-sdk/harness-opencode 1.0.150 → 1.0.152

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/dist/index.js CHANGED
@@ -713,7 +713,7 @@ const startMessageSchema = harnessV1BridgeStartBaseSchema.extend({
713
713
  z.discriminatedUnion("type", [startMessageSchema, ...harnessV1BridgeInboundCommandSchemas]);
714
714
  //#endregion
715
715
  //#region src/version.ts
716
- const VERSION = "1.0.150";
716
+ const VERSION = "1.0.152";
717
717
  //#endregion
718
718
  //#region src/opencode-harness.ts
719
719
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/harness-opencode",
3
- "version": "1.0.150",
3
+ "version": "1.0.152",
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.148",
30
- "@ai-sdk/provider": "4.0.26",
31
- "@ai-sdk/provider-utils": "5.0.58",
29
+ "@ai-sdk/harness": "1.0.150",
30
+ "@ai-sdk/provider": "4.0.27",
31
+ "@ai-sdk/provider-utils": "5.0.59",
32
32
  "ws": "8.21.0"
33
33
  },
34
34
  "peerDependencies": {
@@ -541,8 +541,6 @@ function emitLegacyToolPart({
541
541
 
542
542
  function legacyToolPartInput(part: LegacyToolPart): Record<string, unknown> {
543
543
  return {
544
- ...part.metadata,
545
- ...part.state?.metadata,
546
544
  ...part.state?.input,
547
545
  };
548
546
  }
@@ -6,20 +6,15 @@
6
6
  */
7
7
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
8
8
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
9
+ import { readHostToolSchemasFromEnvironment } from './host-tool-schemas';
9
10
  import { jsonSchemaToZodShape } from './json-schema-to-zod';
10
11
 
11
- type ToolSchema = {
12
- name: string;
13
- description?: string;
14
- inputSchema?: unknown;
15
- };
16
-
17
- const schemas: ToolSchema[] = JSON.parse(process.env.TOOL_SCHEMAS || '[]');
12
+ const schemas = readHostToolSchemasFromEnvironment(process.env);
18
13
  const relayUrl = process.env.TOOL_RELAY_URL || '';
19
14
 
20
15
  if (!schemas.length || !relayUrl) {
21
16
  process.stderr.write(
22
- '[host-tool-mcp] Missing TOOL_SCHEMAS or TOOL_RELAY_URL; exiting\n',
17
+ '[host-tool-mcp] Missing TOOL_SCHEMAS_PATH/TOOL_SCHEMAS or TOOL_RELAY_URL; exiting\n',
23
18
  );
24
19
  process.exit(0);
25
20
  }
@@ -0,0 +1,17 @@
1
+ import { readFileSync } from 'node:fs';
2
+
3
+ export type HostToolSchema = {
4
+ name: string;
5
+ description?: string;
6
+ inputSchema?: unknown;
7
+ };
8
+
9
+ export function readHostToolSchemasFromEnvironment(
10
+ environment: NodeJS.ProcessEnv,
11
+ ): HostToolSchema[] {
12
+ const serializedSchemas = environment.TOOL_SCHEMAS_PATH
13
+ ? readFileSync(environment.TOOL_SCHEMAS_PATH, 'utf8')
14
+ : (environment.TOOL_SCHEMAS ?? '[]');
15
+
16
+ return JSON.parse(serializedSchemas) as HostToolSchema[];
17
+ }
@@ -4,7 +4,7 @@ import {
4
4
  type BridgeTurn,
5
5
  } from '@ai-sdk/harness/bridge';
6
6
  import { randomUUID } from 'node:crypto';
7
- import { realpathSync } from 'node:fs';
7
+ import { mkdirSync, realpathSync, writeFileSync } from 'node:fs';
8
8
  import path from 'node:path';
9
9
  import { argv, env as procEnv } from 'node:process';
10
10
  import { isDeepStrictEqual } from 'node:util';
@@ -224,6 +224,10 @@ async function ensureRuntime({
224
224
  requestToolResult: turn.requestToolResult,
225
225
  });
226
226
  }
227
+ const toolSchemasPath =
228
+ runtime.relay && start.tools
229
+ ? writeHostToolSchemas(start.tools)
230
+ : undefined;
227
231
 
228
232
  const serverAuthHeaders = configureOpenCodeServerAuth({ env: procEnv });
229
233
  const server = await createOpencodeServer({
@@ -233,6 +237,7 @@ async function ensureRuntime({
233
237
  config: buildOpenCodeConfig({
234
238
  start,
235
239
  relayPort: runtime.relay?.port,
240
+ toolSchemasPath,
236
241
  }) as never,
237
242
  });
238
243
  runtime.server = server;
@@ -273,9 +278,11 @@ function closeRuntime(): void {
273
278
  function buildOpenCodeConfig({
274
279
  start,
275
280
  relayPort,
281
+ toolSchemasPath,
276
282
  }: {
277
283
  start: StartMessage;
278
284
  relayPort: number | undefined;
285
+ toolSchemasPath: string | undefined;
279
286
  }): Record<string, unknown> {
280
287
  const config: Record<string, unknown> = {
281
288
  ...withoutAgentPolicyOverrides(start.openCodeConfig),
@@ -312,19 +319,13 @@ function buildOpenCodeConfig({
312
319
  const provider = buildProviderConfig(start);
313
320
  if (provider) config.provider = provider;
314
321
  const mcp = { ...start.mcpServers };
315
- if (relayPort && start.tools && start.tools.length > 0) {
322
+ if (relayPort && toolSchemasPath) {
316
323
  mcp['harness-tools'] = {
317
324
  type: 'local',
318
325
  enabled: true,
319
326
  command: ['node', `${bootstrapDir}/host-tool-mcp.mjs`],
320
327
  environment: {
321
- TOOL_SCHEMAS: JSON.stringify(
322
- start.tools.map(t => ({
323
- name: t.name,
324
- description: t.description,
325
- inputSchema: t.inputSchema,
326
- })),
327
- ),
328
+ TOOL_SCHEMAS_PATH: toolSchemasPath,
328
329
  TOOL_RELAY_URL: `http://127.0.0.1:${relayPort}`,
329
330
  },
330
331
  };
@@ -333,6 +334,27 @@ function buildOpenCodeConfig({
333
334
  return config;
334
335
  }
335
336
 
337
+ function writeHostToolSchemas(
338
+ tools: NonNullable<StartMessage['tools']>,
339
+ ): string {
340
+ mkdirSync(bridgeStateDir, { recursive: true });
341
+ const toolSchemasPath = path.resolve(
342
+ bridgeStateDir,
343
+ 'host-tool-schemas.json',
344
+ );
345
+ writeFileSync(
346
+ toolSchemasPath,
347
+ JSON.stringify(
348
+ tools.map(tool => ({
349
+ name: tool.name,
350
+ description: tool.description,
351
+ inputSchema: tool.inputSchema,
352
+ })),
353
+ ),
354
+ );
355
+ return toolSchemasPath;
356
+ }
357
+
336
358
  function withoutAgentPolicyOverrides(
337
359
  input: Record<string, unknown> | undefined,
338
360
  ): Record<string, unknown> {