@ai-sdk/harness-opencode 1.0.92 → 1.0.94

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.d.ts CHANGED
@@ -1,39 +1,11 @@
1
1
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
2
2
  import * as _ai_sdk_harness from '@ai-sdk/harness';
3
- import { HarnessV1CredentialForwarding, HarnessV1PortEndpoint, HarnessV1, HarnessV1BuiltinTool } from '@ai-sdk/harness';
3
+ import { HarnessV1Authentication, HarnessV1CredentialForwarding, HarnessV1PortEndpoint, HarnessV1, HarnessV1BuiltinTool } from '@ai-sdk/harness';
4
4
 
5
- type OpenCodeResolvedAuthenticationMode = 'anthropic' | 'openai' | 'ai-gateway';
6
- type OpenCodeAuthenticationMode = OpenCodeResolvedAuthenticationMode | 'auto';
7
- /**
8
- * @deprecated Passing an object to auth options is deprecated. Use an `OpenCodeAuthenticationMode` string value ("auto" | "anthropic" | "openai" | "ai-gateway") instead, and pass credentials via environment variables.
9
- */
10
- type LegacyOpenCodeAuthOptions = {
11
- readonly gateway?: {
12
- readonly apiKey?: string;
13
- readonly baseUrl?: string;
14
- };
15
- readonly anthropic?: {
16
- readonly apiKey?: string;
17
- readonly authToken?: string;
18
- readonly baseUrl?: string;
19
- };
20
- readonly openai?: {
21
- readonly apiKey?: string;
22
- readonly baseUrl?: string;
23
- readonly organization?: string;
24
- readonly project?: string;
25
- };
26
- readonly openaiCompatible?: {
27
- readonly apiKey?: string;
28
- readonly baseUrl?: string;
29
- readonly name?: string;
30
- readonly queryParams?: Record<string, string>;
31
- };
32
- };
33
- type OpenCodeAuthOptions = OpenCodeAuthenticationMode | LegacyOpenCodeAuthOptions;
5
+ type OpenCodeAuthenticationMode = HarnessV1Authentication<'anthropic' | 'openai'>;
34
6
 
35
7
  type OpenCodeHarnessSettings = {
36
- readonly auth?: OpenCodeAuthOptions;
8
+ readonly auth?: OpenCodeAuthenticationMode;
37
9
  /**
38
10
  * Customizes each credential value before it is forwarded into a sandbox
39
11
  * process. This does not restrict which credentials the harness adapter can
@@ -201,4 +173,4 @@ declare const openCode: _ai_sdk_harness.HarnessV1<{
201
173
  }, any, any>;
202
174
  }>;
203
175
 
204
- export { type OpenCodeAuthOptions, type OpenCodeAuthenticationMode, type OpenCodeHarnessSettings, VERSION, createOpenCode, openCode };
176
+ export { type OpenCodeAuthenticationMode, type OpenCodeHarnessSettings, VERSION, createOpenCode, openCode };
package/dist/index.js CHANGED
@@ -94,7 +94,8 @@ async function readBridgeAsset(name) {
94
94
  // src/opencode-auth.ts
95
95
  import {
96
96
  createCredentialRequestTransformation,
97
- getAiGatewayAuthFromEnv
97
+ getAiGatewayAuthFromEnv,
98
+ isHarnessAuthenticationEnvironment
98
99
  } from "@ai-sdk/harness/utils";
99
100
  var OPENCODE_CREDENTIAL_ENVIRONMENT_VARIABLES = [
100
101
  "AI_GATEWAY_API_KEY",
@@ -211,29 +212,22 @@ function resolveOpenCodeEnv({
211
212
  provider,
212
213
  processEnv = process.env
213
214
  }) {
214
- const normalizedAuth = normalizeOpenCodeAuthToLegacyAuth(auth);
215
+ const suppliedEnvironment = isHarnessAuthenticationEnvironment(auth);
216
+ const authenticationEnvironment = suppliedEnvironment ? auth : processEnv;
215
217
  const selectedProvider = resolveOpenCodeProvider({ model, provider });
216
- if (normalizedAuth?.openaiCompatible) {
217
- return pickOpenAICompatible(normalizedAuth.openaiCompatible, processEnv);
218
+ if (selectedProvider === "openai" && auth === "openai") {
219
+ return pickOpenAI({ processEnv: authenticationEnvironment });
218
220
  }
219
- if (selectedProvider === "openai") {
220
- if (normalizedAuth?.openai) {
221
- return pickOpenAI({ explicit: normalizedAuth.openai, processEnv });
222
- }
223
- } else if (normalizedAuth?.anthropic) {
224
- return pickAnthropic({ explicit: normalizedAuth.anthropic, processEnv });
225
- }
226
- const gatewayAuthFromEnv = getAiGatewayAuthFromEnv({ env: processEnv });
227
- if (normalizedAuth?.gateway) {
228
- return pickGateway({
229
- explicit: normalizedAuth.gateway,
230
- gatewayAuthFromEnv
231
- });
221
+ if (selectedProvider === "anthropic" && auth === "anthropic") {
222
+ return pickAnthropic({ processEnv: authenticationEnvironment });
232
223
  }
233
- if (gatewayAuthFromEnv.apiKey) {
234
- return pickGateway({ explicit: {}, gatewayAuthFromEnv });
224
+ const gatewayAuthFromEnv = getAiGatewayAuthFromEnv({
225
+ env: authenticationEnvironment
226
+ });
227
+ if (auth === "ai-gateway" || gatewayAuthFromEnv.apiKey) {
228
+ return pickGateway({ gatewayAuthFromEnv });
235
229
  }
236
- return selectedProvider === "openai" ? pickOpenAI({ processEnv }) : pickAnthropic({ processEnv });
230
+ return selectedProvider === "openai" ? pickOpenAI({ processEnv: authenticationEnvironment }) : pickAnthropic({ processEnv: authenticationEnvironment });
237
231
  }
238
232
  function resolveOpenCodeAuthenticationMode({
239
233
  auth,
@@ -241,17 +235,17 @@ function resolveOpenCodeAuthenticationMode({
241
235
  provider,
242
236
  processEnv = process.env
243
237
  }) {
244
- if (typeof auth !== "string" && auth?.openaiCompatible) {
245
- return "openai";
238
+ if (isHarnessAuthenticationEnvironment(auth)) {
239
+ return getAiGatewayAuthFromEnv({ env: auth }).apiKey ? "ai-gateway" : resolveOpenCodeProvider({ model, provider });
246
240
  }
247
241
  const selectedProvider = resolveOpenCodeProvider({ model, provider });
248
- if (selectedProvider === "openai" && (auth === "openai" || typeof auth !== "string" && auth?.openai)) {
242
+ if (selectedProvider === "openai" && auth === "openai") {
249
243
  return "openai";
250
244
  }
251
- if (selectedProvider === "anthropic" && (auth === "anthropic" || typeof auth !== "string" && auth?.anthropic)) {
245
+ if (selectedProvider === "anthropic" && auth === "anthropic") {
252
246
  return "anthropic";
253
247
  }
254
- if (auth === "ai-gateway" || typeof auth !== "string" && auth?.gateway) {
248
+ if (auth === "ai-gateway") {
255
249
  return "ai-gateway";
256
250
  }
257
251
  if (getAiGatewayAuthFromEnv({ env: processEnv }).apiKey) {
@@ -259,80 +253,39 @@ function resolveOpenCodeAuthenticationMode({
259
253
  }
260
254
  return selectedProvider;
261
255
  }
262
- function normalizeOpenCodeAuthToLegacyAuth(auth) {
263
- if (auth == null || auth === "auto") {
264
- return void 0;
265
- }
266
- if (typeof auth === "string") {
267
- switch (auth) {
268
- case "anthropic":
269
- return { anthropic: {} };
270
- case "openai":
271
- return { openai: {} };
272
- case "ai-gateway":
273
- return { gateway: {} };
274
- default:
275
- return void 0;
276
- }
277
- }
278
- console.warn(
279
- '[opencode] Passing an object to auth options is deprecated. Use a string mode ("auto" | "anthropic" | "openai" | "ai-gateway") instead, and pass credentials via environment variables.'
280
- );
281
- return auth;
282
- }
283
- function pickOpenAICompatible(explicit, processEnv) {
284
- const env = {};
285
- const apiKey = explicit.apiKey ?? processEnv.OPENAI_API_KEY;
286
- if (apiKey) env.OPENAI_API_KEY = apiKey;
287
- const baseUrl = explicit.baseUrl ?? processEnv.OPENAI_BASE_URL;
288
- if (baseUrl) env.OPENAI_BASE_URL = baseUrl;
289
- const name = explicit.name ?? processEnv.OPENAI_NAME;
290
- if (name) env.OPENAI_NAME = name;
291
- if (explicit.queryParams && Object.keys(explicit.queryParams).length > 0) {
292
- env.OPENAI_QUERY_PARAMS_JSON = JSON.stringify(explicit.queryParams);
293
- } else if (processEnv.OPENAI_QUERY_PARAMS_JSON) {
294
- env.OPENAI_QUERY_PARAMS_JSON = processEnv.OPENAI_QUERY_PARAMS_JSON;
295
- }
296
- return env;
297
- }
298
256
  function pickOpenAI({
299
- explicit,
300
257
  processEnv
301
258
  }) {
302
259
  const env = {};
303
- const apiKey = explicit?.apiKey ?? processEnv.OPENAI_API_KEY;
260
+ const apiKey = processEnv.OPENAI_API_KEY;
304
261
  if (apiKey) env.OPENAI_API_KEY = apiKey;
305
- const baseUrl = explicit?.baseUrl ?? processEnv.OPENAI_BASE_URL;
262
+ const baseUrl = processEnv.OPENAI_BASE_URL;
306
263
  if (baseUrl) env.OPENAI_BASE_URL = baseUrl;
307
- const organization = explicit?.organization ?? processEnv.OPENAI_ORGANIZATION;
264
+ const organization = processEnv.OPENAI_ORGANIZATION;
308
265
  if (organization) env.OPENAI_ORGANIZATION = organization;
309
- const project = explicit?.project ?? processEnv.OPENAI_PROJECT;
266
+ const project = processEnv.OPENAI_PROJECT;
310
267
  if (project) env.OPENAI_PROJECT = project;
311
268
  return env;
312
269
  }
313
270
  function pickAnthropic({
314
- explicit,
315
271
  processEnv
316
272
  }) {
317
273
  const env = {};
318
- const apiKey = explicit?.apiKey ?? processEnv.ANTHROPIC_API_KEY;
274
+ const apiKey = processEnv.ANTHROPIC_API_KEY;
319
275
  if (apiKey) env.ANTHROPIC_API_KEY = apiKey;
320
- const authToken = explicit?.authToken ?? processEnv.ANTHROPIC_AUTH_TOKEN;
276
+ const authToken = processEnv.ANTHROPIC_AUTH_TOKEN;
321
277
  if (authToken) env.ANTHROPIC_AUTH_TOKEN = authToken;
322
- const baseUrl = explicit?.baseUrl ?? processEnv.ANTHROPIC_BASE_URL;
278
+ const baseUrl = processEnv.ANTHROPIC_BASE_URL;
323
279
  if (baseUrl) env.ANTHROPIC_BASE_URL = baseUrl;
324
280
  return env;
325
281
  }
326
282
  function pickGateway({
327
- explicit,
328
283
  gatewayAuthFromEnv
329
284
  }) {
330
285
  const env = {};
331
- const apiKey = explicit.apiKey ?? gatewayAuthFromEnv.apiKey;
286
+ const apiKey = gatewayAuthFromEnv.apiKey;
332
287
  if (apiKey) env.AI_GATEWAY_API_KEY = apiKey;
333
- const baseUrl = toOpenCodeGatewayBaseUrl(
334
- explicit.baseUrl ?? gatewayAuthFromEnv.baseUrl
335
- );
288
+ const baseUrl = toOpenCodeGatewayBaseUrl(gatewayAuthFromEnv.baseUrl);
336
289
  env.AI_GATEWAY_BASE_URL = baseUrl;
337
290
  return env;
338
291
  }
@@ -364,7 +317,7 @@ var inboundMessageSchema = z.discriminatedUnion("type", [
364
317
  ]);
365
318
 
366
319
  // src/version.ts
367
- var VERSION = true ? "1.0.92" : "0.0.0-test";
320
+ var VERSION = true ? "1.0.94" : "0.0.0-test";
368
321
 
369
322
  // src/opencode-harness.ts
370
323
  var OPENCODE_CLIENT_APP = `ai-sdk/harness-opencode/${VERSION}`;