@opencode/ai 2.1.2 → 2.1.4

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.
Files changed (140) hide show
  1. package/dist/cache-policy.js +6 -5
  2. package/dist/experimental/evaluation.d.ts +7 -6
  3. package/dist/experimental/evaluation.js +3 -11
  4. package/dist/experimental/realtime.d.ts +59 -0
  5. package/dist/experimental/realtime.js +21 -13
  6. package/dist/experimental.d.ts +1 -1
  7. package/dist/generation.js +1 -1
  8. package/dist/image-client.d.ts +11 -9
  9. package/dist/image.d.ts +158 -150
  10. package/dist/image.js +2 -2
  11. package/dist/llm.d.ts +2 -4
  12. package/dist/llm.js +2 -2
  13. package/dist/media-model.d.ts +2 -2
  14. package/dist/media-model.js +1 -1
  15. package/dist/promise.d.ts +121 -121
  16. package/dist/promise.js +3 -5
  17. package/dist/protocols/alibaba-chat.d.ts +18 -18
  18. package/dist/protocols/alibaba-chat.js +3 -3
  19. package/dist/protocols/alibaba-messages.d.ts +12 -12
  20. package/dist/protocols/alibaba-messages.js +1 -1
  21. package/dist/protocols/alibaba-responses.d.ts +38 -38
  22. package/dist/protocols/anthropic-messages.d.ts +40 -44
  23. package/dist/protocols/anthropic-messages.js +13 -15
  24. package/dist/protocols/bedrock-converse.d.ts +36 -85
  25. package/dist/protocols/bedrock-converse.js +6 -6
  26. package/dist/protocols/bedrock-event-stream.d.ts +6 -1
  27. package/dist/protocols/bedrock-event-stream.js +9 -8
  28. package/dist/protocols/cartesia-speech.d.ts +32 -32
  29. package/dist/protocols/cohere-chat.d.ts +13 -10
  30. package/dist/protocols/cohere-chat.js +2 -2
  31. package/dist/protocols/deepgram-speech.d.ts +32 -32
  32. package/dist/protocols/elevenlabs-speech.d.ts +32 -32
  33. package/dist/protocols/gemini.d.ts +46 -36
  34. package/dist/protocols/gemini.js +12 -15
  35. package/dist/protocols/google-interactions.d.ts +14 -13
  36. package/dist/protocols/google-interactions.js +16 -11
  37. package/dist/protocols/google-speech.d.ts +32 -32
  38. package/dist/protocols/google-transcription.d.ts +32 -32
  39. package/dist/protocols/meta-messages.d.ts +23 -23
  40. package/dist/protocols/meta-responses.d.ts +84 -84
  41. package/dist/protocols/mistral-chat.d.ts +81 -78
  42. package/dist/protocols/mistral-chat.js +3 -5
  43. package/dist/protocols/open-responses-channel.js +47 -46
  44. package/dist/protocols/open-responses-continuation.d.ts +8 -2
  45. package/dist/protocols/open-responses-continuation.js +3 -1
  46. package/dist/protocols/open-responses.d.ts +419 -419
  47. package/dist/protocols/open-responses.js +11 -10
  48. package/dist/protocols/openai-chat.d.ts +68 -67
  49. package/dist/protocols/openai-chat.js +7 -8
  50. package/dist/protocols/openai-compatible-chat.d.ts +13 -14
  51. package/dist/protocols/openai-compatible-responses.d.ts +39 -40
  52. package/dist/protocols/openai-images.d.ts +32 -32
  53. package/dist/protocols/openai-responses.d.ts +253 -253
  54. package/dist/protocols/openai-responses.js +1 -1
  55. package/dist/protocols/openai-speech.d.ts +32 -32
  56. package/dist/protocols/openai-transcription.d.ts +32 -32
  57. package/dist/protocols/openai-transcription.js +12 -7
  58. package/dist/protocols/utils/open-responses-options.d.ts +8 -8
  59. package/dist/protocols/utils/open-responses-options.js +4 -6
  60. package/dist/protocols/utils/partial-json-options.d.ts +0 -1
  61. package/dist/protocols/utils/partial-json-options.js +0 -1
  62. package/dist/protocols/utils/partial-json.js +5 -4
  63. package/dist/protocols/utils/tool-schema.d.ts +0 -3
  64. package/dist/protocols/utils/tool-schema.js +0 -4
  65. package/dist/protocols/utils/tool-stream.d.ts +1 -1
  66. package/dist/protocols/venice-chat.d.ts +52 -53
  67. package/dist/protocols/venice-chat.js +6 -5
  68. package/dist/protocols/xai-images.js +3 -4
  69. package/dist/protocols/xai-responses.d.ts +81 -81
  70. package/dist/protocols/zai-chat.d.ts +33 -30
  71. package/dist/protocols/zai-chat.js +8 -3
  72. package/dist/protocols/zai-messages.d.ts +21 -19
  73. package/dist/protocols/zai-messages.js +3 -2
  74. package/dist/provider-error.js +8 -7
  75. package/dist/providers/alibaba.d.ts +74 -74
  76. package/dist/providers/amazon-bedrock-mantle.d.ts +202 -202
  77. package/dist/providers/amazon-bedrock.d.ts +16 -13
  78. package/dist/providers/anthropic-compatible.d.ts +13 -13
  79. package/dist/providers/anthropic.d.ts +13 -13
  80. package/dist/providers/azure.d.ts +112 -112
  81. package/dist/providers/baseten.d.ts +24 -24
  82. package/dist/providers/cerebras.d.ts +24 -24
  83. package/dist/providers/cloudflare-ai-gateway.d.ts +237 -234
  84. package/dist/providers/cloudflare-ai-gateway.js +3 -6
  85. package/dist/providers/cloudflare-workers-ai.d.ts +24 -24
  86. package/dist/providers/cohere.d.ts +78 -74
  87. package/dist/providers/deepinfra.d.ts +24 -24
  88. package/dist/providers/deepseek.d.ts +24 -24
  89. package/dist/providers/digitalocean.d.ts +36 -36
  90. package/dist/providers/fireworks.d.ts +24 -24
  91. package/dist/providers/google-vertex-chat.d.ts +12 -12
  92. package/dist/providers/google-vertex-interactions.d.ts +3 -3
  93. package/dist/providers/google-vertex-messages.d.ts +20 -20
  94. package/dist/providers/google-vertex-mistral.d.ts +14 -14
  95. package/dist/providers/google-vertex-responses.d.ts +38 -38
  96. package/dist/providers/google-vertex.d.ts +17 -17
  97. package/dist/providers/google-vertex.js +2 -2
  98. package/dist/providers/google.d.ts +79 -79
  99. package/dist/providers/groq.d.ts +24 -24
  100. package/dist/providers/meta.d.ts +189 -189
  101. package/dist/providers/minimax.d.ts +202 -202
  102. package/dist/providers/mistral.d.ts +28 -28
  103. package/dist/providers/moonshot.d.ts +202 -202
  104. package/dist/providers/open-responses-options.d.ts +0 -1
  105. package/dist/providers/open-responses-options.js +1 -1
  106. package/dist/providers/openai-compatible-responses.d.ts +38 -38
  107. package/dist/providers/openai-compatible.d.ts +12 -12
  108. package/dist/providers/openai-compatible.js +1 -1
  109. package/dist/providers/openai-options.d.ts +3 -4
  110. package/dist/providers/openai-options.js +0 -1
  111. package/dist/providers/openai.d.ts +103 -103
  112. package/dist/providers/openrouter.d.ts +171 -112
  113. package/dist/providers/openrouter.js +40 -33
  114. package/dist/providers/togetherai.d.ts +24 -24
  115. package/dist/providers/venice.d.ts +195 -20
  116. package/dist/providers/xai.d.ts +12 -12
  117. package/dist/providers/zai-coding-plan.d.ts +152 -72
  118. package/dist/providers/zai.d.ts +84 -19
  119. package/dist/route/auth-options.d.ts +0 -3
  120. package/dist/route/auth.d.ts +0 -2
  121. package/dist/route/auth.js +0 -2
  122. package/dist/route/client.d.ts +0 -218
  123. package/dist/route/client.js +3 -7
  124. package/dist/route/executor-service.js +1 -1
  125. package/dist/route/transport/http.js +5 -8
  126. package/dist/schema/errors.d.ts +1 -1
  127. package/dist/schema/errors.js +1 -1
  128. package/dist/schema/messages.js +4 -7
  129. package/dist/speech-client.d.ts +11 -9
  130. package/dist/speech.d.ts +158 -150
  131. package/dist/speech.js +2 -2
  132. package/dist/transcription-client.d.ts +11 -9
  133. package/dist/transcription.d.ts +158 -150
  134. package/dist/transcription.js +2 -2
  135. package/dist/video-client.d.ts +11 -9
  136. package/dist/video.d.ts +124 -116
  137. package/dist/video.js +2 -2
  138. package/package.json +7 -6
  139. package/dist/protocols/utils/openai-options.d.ts +0 -16
  140. package/dist/protocols/utils/openai-options.js +0 -15
@@ -46,7 +46,6 @@ export interface Route<Body, Prepared = unknown, Compact extends CompactionOpera
46
46
  readonly streamPrepared: (prepared: Prepared, request: LLMRequest, runtime: TransportRuntime, options?: StreamOptions) => Stream.Stream<LLMEvent, AIError>;
47
47
  }
48
48
  export type AnyRoute<Compact extends CompactionOperations | undefined = CompactionOperations | undefined> = Route<any, any, Compact>;
49
- export type HttpOptionsInput = HttpOptions.Input;
50
49
  export type RouteLanguageModelInput = Omit<LanguageModel.Input, "provider" | "route">;
51
50
  export type RouteRoutedLanguageModelInput = Omit<LanguageModel.Input, "route">;
52
51
  export interface RouteDefaults {
@@ -71,7 +70,6 @@ export interface RoutePatch<Body, Prepared> extends RouteDefaultsInput {
71
70
  readonly endpoint?: EndpointPatch<Body>;
72
71
  }
73
72
  type RouteMappedLanguageModelInput = RouteLanguageModelInput | RouteRoutedLanguageModelInput;
74
- export declare const generationOptions: (input: GenerationOptions.Input | undefined) => GenerationOptions | undefined;
75
73
  export interface Interface {
76
74
  readonly compact: CompactMethod;
77
75
  readonly stream: StreamMethod;
@@ -214,222 +212,6 @@ export declare function stream(request: LLMRequest, options?: StreamOptions): St
214
212
  export declare function generate(request: LLMRequest, options?: StreamOptions): Effect.Effect<LLMResponse, AIError, Service>;
215
213
  export declare function compact(request: CheckpointRequest, options: TriggerCompactOptions): Effect.Effect<CompactionCheckpointResponse, AIError, Service>;
216
214
  export declare function compact(request: CompactionRequest, options?: EndpointCompactOptions): Effect.Effect<CompactionResponse, AIError, Service>;
217
- export declare const streamRequest: (request: LLMRequest, options?: StreamOptions) => Stream.Stream<{
218
- readonly type: "step-start";
219
- readonly index: number;
220
- } | {
221
- readonly type: "text-start";
222
- readonly id: string;
223
- readonly providerMetadata?: {
224
- readonly [x: string]: {
225
- readonly [x: string]: unknown;
226
- };
227
- } | undefined;
228
- } | {
229
- readonly type: "text-delta";
230
- readonly id: string;
231
- readonly text: string;
232
- readonly providerMetadata?: {
233
- readonly [x: string]: {
234
- readonly [x: string]: unknown;
235
- };
236
- } | undefined;
237
- } | {
238
- readonly type: "text-end";
239
- readonly id: string;
240
- readonly text?: string | undefined;
241
- readonly providerMetadata?: {
242
- readonly [x: string]: {
243
- readonly [x: string]: unknown;
244
- };
245
- } | undefined;
246
- } | {
247
- readonly type: "reasoning-start";
248
- readonly id: string;
249
- readonly providerMetadata?: {
250
- readonly [x: string]: {
251
- readonly [x: string]: unknown;
252
- };
253
- } | undefined;
254
- } | {
255
- readonly type: "reasoning-delta";
256
- readonly id: string;
257
- readonly text: string;
258
- readonly providerMetadata?: {
259
- readonly [x: string]: {
260
- readonly [x: string]: unknown;
261
- };
262
- } | undefined;
263
- } | {
264
- readonly type: "reasoning-end";
265
- readonly id: string;
266
- readonly text?: string | undefined;
267
- readonly providerMetadata?: {
268
- readonly [x: string]: {
269
- readonly [x: string]: unknown;
270
- };
271
- } | undefined;
272
- } | {
273
- readonly type: "tool-input-start";
274
- readonly id: string;
275
- readonly name: string;
276
- readonly namespace?: string | undefined;
277
- readonly providerExecuted?: boolean | undefined;
278
- readonly providerMetadata?: {
279
- readonly [x: string]: {
280
- readonly [x: string]: unknown;
281
- };
282
- } | undefined;
283
- } | {
284
- readonly type: "tool-input-delta";
285
- readonly id: string;
286
- readonly name: string;
287
- readonly namespace?: string | undefined;
288
- readonly text: string;
289
- readonly input?: unknown;
290
- } | {
291
- readonly type: "tool-input-end";
292
- readonly id: string;
293
- readonly name: string;
294
- readonly namespace?: string | undefined;
295
- readonly providerMetadata?: {
296
- readonly [x: string]: {
297
- readonly [x: string]: unknown;
298
- };
299
- } | undefined;
300
- } | {
301
- readonly type: "tool-input-error";
302
- readonly id: string;
303
- readonly name: string;
304
- readonly namespace?: string | undefined;
305
- readonly raw: string;
306
- } | {
307
- readonly type: "tool-call";
308
- readonly id: string;
309
- readonly name: string;
310
- readonly namespace?: string | undefined;
311
- readonly input: unknown;
312
- readonly providerExecuted?: boolean | undefined;
313
- readonly providerMetadata?: {
314
- readonly [x: string]: {
315
- readonly [x: string]: unknown;
316
- };
317
- } | undefined;
318
- } | {
319
- readonly type: "tool-result";
320
- readonly id: string;
321
- readonly name: string;
322
- readonly namespace?: string | undefined;
323
- readonly result: {
324
- readonly type: "json";
325
- readonly value: unknown;
326
- } | {
327
- readonly type: "text";
328
- readonly value: unknown;
329
- } | {
330
- readonly type: "error";
331
- readonly value: unknown;
332
- } | {
333
- readonly type: "content";
334
- readonly value: readonly ({
335
- readonly type: "text";
336
- readonly text: string;
337
- } | {
338
- readonly type: "file";
339
- readonly uri: string;
340
- readonly mime: string;
341
- readonly name?: string | undefined;
342
- })[];
343
- };
344
- readonly output?: {
345
- readonly structured: unknown;
346
- readonly content: readonly ({
347
- readonly type: "text";
348
- readonly text: string;
349
- } | {
350
- readonly type: "file";
351
- readonly uri: string;
352
- readonly mime: string;
353
- readonly name?: string | undefined;
354
- })[];
355
- } | undefined;
356
- readonly providerExecuted?: boolean | undefined;
357
- readonly providerMetadata?: {
358
- readonly [x: string]: {
359
- readonly [x: string]: unknown;
360
- };
361
- } | undefined;
362
- } | {
363
- readonly type: "tool-error";
364
- readonly id: string;
365
- readonly name: string;
366
- readonly namespace?: string | undefined;
367
- readonly message: string;
368
- readonly error?: unknown;
369
- readonly providerMetadata?: {
370
- readonly [x: string]: {
371
- readonly [x: string]: unknown;
372
- };
373
- } | undefined;
374
- } | {
375
- readonly type: "step-finish";
376
- readonly index: number;
377
- readonly reason: {
378
- readonly normalized: "content-filter" | "error" | "length" | "stop" | "tool-calls" | "unknown";
379
- readonly raw?: string | undefined;
380
- readonly category?: string | undefined;
381
- readonly explanation?: string | undefined;
382
- };
383
- readonly usage?: import("../schema/events.js").Usage | undefined;
384
- readonly providerMetadata?: {
385
- readonly [x: string]: {
386
- readonly [x: string]: unknown;
387
- };
388
- } | undefined;
389
- } | {
390
- readonly type: "finish";
391
- readonly reason: {
392
- readonly normalized: "content-filter" | "error" | "length" | "stop" | "tool-calls" | "unknown";
393
- readonly raw?: string | undefined;
394
- readonly category?: string | undefined;
395
- readonly explanation?: string | undefined;
396
- };
397
- readonly usage?: import("../schema/events.js").Usage | undefined;
398
- readonly providerMetadata?: {
399
- readonly [x: string]: {
400
- readonly [x: string]: unknown;
401
- };
402
- } | undefined;
403
- } | {
404
- readonly type: "media";
405
- readonly media: import("../media.js").Asset;
406
- readonly providerMetadata?: {
407
- readonly [x: string]: {
408
- readonly [x: string]: unknown;
409
- };
410
- } | undefined;
411
- } | {
412
- readonly type: "provider-error";
413
- readonly message: string;
414
- readonly classification?: "context-overflow" | "payload-too-large" | undefined;
415
- readonly providerMetadata?: {
416
- readonly [x: string]: {
417
- readonly [x: string]: unknown;
418
- };
419
- } | undefined;
420
- } | ({
421
- readonly type: "compaction";
422
- readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
423
- readonly id?: string | undefined;
424
- readonly encrypted?: string | undefined;
425
- readonly text?: string | null | undefined;
426
- } & ({
427
- readonly encrypted: string;
428
- readonly text?: never;
429
- } | {
430
- readonly text: string | null;
431
- readonly encrypted?: never;
432
- })), AIError, LLMClientService>;
433
215
  export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
434
216
  export declare const Route: {
435
217
  readonly make: typeof make;
@@ -32,7 +32,7 @@ const mergeRouteDefaults = (base, patch) => {
32
32
  ...base,
33
33
  ...patch,
34
34
  headers,
35
- generation: mergeGenerationOptions(generationOptions(base?.generation), generationOptions(patch.generation)),
35
+ generation: mergeGenerationOptions(base?.generation, patch.generation),
36
36
  providerOptions: mergeProviderOptions(base?.providerOptions, patch.providerOptions),
37
37
  http: mergeHttpOptions(base?.http, HttpOptions.make(patch.http), headers === undefined ? undefined : new HttpOptions({ headers })),
38
38
  };
@@ -43,7 +43,6 @@ const mergeHeaders = (...items) => {
43
43
  return undefined;
44
44
  return Object.fromEntries(entries);
45
45
  };
46
- export const generationOptions = (input) => input === undefined ? undefined : GenerationOptions.make(input);
47
46
  export function canCompact(request, options) {
48
47
  if (options?.mechanism === "trigger")
49
48
  return request.model.route.compact?.trigger !== undefined;
@@ -126,8 +125,8 @@ function makeFromTransport(input) {
126
125
  id: id ?? routeInput.id,
127
126
  provider: provider ?? routeInput.provider,
128
127
  providerMetadataKey: providerMetadataKey ??
129
- (provider !== undefined && String(provider) !== String(routeInput.provider)
130
- ? String(provider)
128
+ (provider !== undefined && provider !== routeInput.provider
129
+ ? provider
131
130
  : routeInput.providerMetadataKey),
132
131
  auth: auth ?? routeInput.auth,
133
132
  endpoint: endpoint ? Endpoint.merge(routeInput.endpoint, endpoint) : routeInput.endpoint,
@@ -271,9 +270,6 @@ export function compact(request, options) {
271
270
  return yield* unsupportedCompaction(request, options?.mechanism);
272
271
  });
273
272
  }
274
- export const streamRequest = (request, options) => Stream.unwrap(Effect.gen(function* () {
275
- return (yield* Service).stream(request, options);
276
- }));
277
273
  export const layer = Layer.effect(Service, Effect.gen(function* () {
278
274
  const executor = yield* RequestExecutor.Service;
279
275
  const stream = streamRequestWith({ http: executor });
@@ -3,7 +3,7 @@ import { HttpContext } from "../schema/errors.js";
3
3
  export class RequestExecutorService extends Context.Service()("@opencode/AI/RequestExecutor") {
4
4
  }
5
5
  export const Service = RequestExecutorService;
6
- export const headerDetails = (headers) => Object.fromEntries(Object.entries(headers).map(([name, value]) => [name, String(value)]));
6
+ export const headerDetails = (headers) => Object.fromEntries(Object.entries(headers).map(([name, value]) => [name, value]));
7
7
  export const responseHttp = (response) => new HttpContext({
8
8
  url: response.request.url,
9
9
  status: response.status,
@@ -6,13 +6,6 @@ import { Framing } from "../framing.js";
6
6
  import * as ProviderShared from "../../protocols/shared.js";
7
7
  import { AIError, DEFAULT_CHUNK_TIMEOUT_MS, DEFAULT_HTTP_TIMEOUT_MS, mergeJsonRecords, TransportError, } from "../../schema/index.js";
8
8
  import { RequestExecutor } from "../executor.js";
9
- const applyQuery = (url, query) => {
10
- if (!query)
11
- return url;
12
- const next = new URL(url);
13
- Object.entries(query).forEach(([key, value]) => next.searchParams.set(key, value));
14
- return next.toString();
15
- };
16
9
  const bodyWithOverlay = (body, request, encodeBody) => Effect.gen(function* () {
17
10
  if (request.http?.body === undefined)
18
11
  return { jsonBody: body, bodyText: encodeBody(body) };
@@ -23,7 +16,11 @@ const bodyWithOverlay = (body, request, encodeBody) => Effect.gen(function* () {
23
16
  return yield* ProviderShared.invalidRequest("http.body can only overlay JSON object request bodies");
24
17
  });
25
18
  export const jsonRequestParts = (input) => Effect.gen(function* () {
26
- const url = applyQuery(renderEndpoint(input.endpoint, { request: input.request, body: input.body }).toString(), input.request.http?.query);
19
+ const endpoint = renderEndpoint(input.endpoint, { request: input.request, body: input.body });
20
+ if (input.request.http?.query) {
21
+ Object.entries(input.request.http.query).forEach(([key, value]) => endpoint.searchParams.set(key, value));
22
+ }
23
+ const url = endpoint.toString();
27
24
  const body = yield* bodyWithOverlay(input.body, input.request, input.encodeBody);
28
25
  const headers = yield* Auth.toEffect(input.auth)({
29
26
  request: input.request,
@@ -153,7 +153,7 @@ declare const TimeoutError_base: Schema.Class<TimeoutError, Schema.TaggedStruct<
153
153
  readonly body: Schema.optional<Schema.String>;
154
154
  readonly http: Schema.optional<typeof HttpContext>;
155
155
  readonly cause: Schema.optional<Schema.Defect>;
156
- readonly timeoutMs: Schema.optional<Schema.Number>;
156
+ readonly timeoutMs: Schema.optional<Schema.Int>;
157
157
  }>, import("effect/Cause").YieldableError>;
158
158
  /** A caller-supplied deadline elapsed, such as `Generation.await` polling past its `Poll.timeout`. */
159
159
  export declare class TimeoutError extends TimeoutError_base {
@@ -104,7 +104,7 @@ export class UnknownProviderError extends Schema.TaggedError("AI.Error.UnknownPr
104
104
  /** A caller-supplied deadline elapsed, such as `Generation.await` polling past its `Poll.timeout`. */
105
105
  export class TimeoutError extends Schema.TaggedError("AI.Error.Timeout")("Timeout", {
106
106
  ...ReasonFields,
107
- timeoutMs: Schema.optional(Schema.Number),
107
+ timeoutMs: Schema.optional(NonNegativeInt),
108
108
  }) {
109
109
  }
110
110
  export const AIErrorReason = Schema.Union([
@@ -1,9 +1,10 @@
1
- import { Schema } from "effect";
1
+ import { Option, Schema } from "effect";
2
2
  import { withStatics } from "@opencode/schema/schema";
3
3
  import { Tool } from "@opencode/schema/tool";
4
4
  import { CacheHint, CachePolicy, GenerationOptions, HttpOptions, JsonSchema, LanguageModelSchema, ProviderMetadata, ProviderOptions, ReasoningEffort, } from "./options.js";
5
5
  import { ProviderID } from "./ids.js";
6
6
  import { Media } from "../media.js";
7
+ import { Json } from "../utils/json.js";
7
8
  export const MessageRole = Schema.Literals(["system", "user", "assistant", "tool"]);
8
9
  const systemPartSchema = Schema.Struct({
9
10
  type: Schema.Literal("text"),
@@ -89,15 +90,11 @@ export const ToolOutput = withStatics(Schema.Struct({
89
90
  return { type: "content", value: output.content };
90
91
  },
91
92
  });
93
+ const encodeJsonOption = Schema.encodeUnknownOption(Json);
92
94
  const toolResultText = (value) => {
93
95
  if (typeof value === "string")
94
96
  return value;
95
- try {
96
- return JSON.stringify(value) ?? String(value);
97
- }
98
- catch {
99
- return String(value);
100
- }
97
+ return Option.getOrElse(encodeJsonOption(value), () => String(value));
101
98
  };
102
99
  export const ToolCallPart = withStatics(Schema.Struct({
103
100
  type: Schema.Literal("tool-call"),
@@ -24,14 +24,6 @@ export declare const SpeechClient: {
24
24
  readonly type: "finish";
25
25
  readonly audio: import("./media.js").Asset;
26
26
  readonly usage?: {
27
- readonly type: "tokens";
28
- readonly input?: number | undefined;
29
- readonly output?: number | undefined;
30
- readonly total?: number | undefined;
31
- readonly details?: {
32
- readonly [x: string]: unknown;
33
- } | undefined;
34
- } | {
35
27
  readonly type: "seconds";
36
28
  readonly seconds: number;
37
29
  } | {
@@ -43,6 +35,14 @@ export declare const SpeechClient: {
43
35
  } | {
44
36
  readonly type: "compute";
45
37
  readonly seconds: number;
38
+ } | {
39
+ readonly type: "tokens";
40
+ readonly input?: number | undefined;
41
+ readonly output?: number | undefined;
42
+ readonly total?: number | undefined;
43
+ readonly details?: {
44
+ readonly [x: string]: unknown;
45
+ } | undefined;
46
46
  } | undefined;
47
47
  readonly notices?: readonly {
48
48
  readonly type: "filtered" | "moderated" | "other";
@@ -60,7 +60,9 @@ export declare const SpeechClient: {
60
60
  } | undefined;
61
61
  } | import("./generation.js").Observation, import("./index.js").AIError, SpeechClientService>;
62
62
  readonly start: (request: SpeechRequestFor) => import("effect/Effect").Effect<import("./generation.js").Generation<SpeechResponse>, import("./index.js").AIError, SpeechClientService>;
63
- readonly resume: (model: import("./speech.js").SpeechModel<import("./media-model.js").MediaModel.Options>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<SpeechResponse>, import("./index.js").AIError, SpeechClientService>;
63
+ readonly resume: (model: import("./speech.js").SpeechModel<{
64
+ readonly [x: string]: unknown;
65
+ }>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<SpeechResponse>, import("./index.js").AIError, SpeechClientService>;
64
66
  readonly Service: typeof SpeechClientService;
65
67
  };
66
68
  export {};