@opencode/ai 0.0.0-dev-1320 → 0.0.0-dev-1322

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.
@@ -108,10 +108,6 @@ const GeminiThinkingConfig = Schema.Struct({
108
108
  includeThoughts: Schema.optional(Schema.Boolean),
109
109
  thinkingLevel: Schema.optional(GeminiThinkingLevel),
110
110
  });
111
- const GeminiSafetySetting = Schema.Struct({
112
- category: knownString(),
113
- threshold: knownString(),
114
- });
115
111
  // =============================================================================
116
112
  // Provider Options
117
113
  // =============================================================================
@@ -124,7 +120,7 @@ const GeminiThinkingConfigInput = Schema.Struct({
124
120
  });
125
121
  const Options = Schema.Struct({
126
122
  cachedContent: lenient(Schema.String),
127
- safetySettings: lenient(Schema.Array(GeminiSafetySetting)),
123
+ safetySettings: lenient(Schema.Array(GeminiGenerateContent.SafetySetting)),
128
124
  serviceTier: lenient(knownString()),
129
125
  thinkingConfig: lenient(GeminiThinkingConfigInput),
130
126
  });
@@ -144,7 +140,7 @@ const GeminiBodyFields = {
144
140
  cachedContent: Schema.optional(Schema.String),
145
141
  contents: Schema.Array(GeminiContent),
146
142
  labels: Schema.optional(Schema.Record(Schema.String, Schema.String)),
147
- safetySettings: optionalArray(GeminiSafetySetting),
143
+ safetySettings: optionalArray(GeminiGenerateContent.SafetySetting),
148
144
  serviceTier: Schema.optional(Schema.String),
149
145
  systemInstruction: Schema.optional(GeminiSystemInstruction),
150
146
  tools: optionalArray(GeminiTool),
@@ -1,6 +1,7 @@
1
1
  import { Effect, Schema } from "effect";
2
2
  import { Route } from "../route/client.js";
3
3
  import { Protocol } from "../route/protocol.js";
4
+ import { HttpTransport, type Transport, type TransportPrepareInput } from "../route/transport/index.js";
4
5
  import { AIError } from "../schema/index.js";
5
6
  import { Media } from "../media.js";
6
7
  import { Lifecycle } from "./utils/lifecycle.js";
@@ -12,9 +13,87 @@ declare const Options: Schema.Struct<{
12
13
  readonly thinkingLevel: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.declare<import("../schema/options.js").OpenString<"high" | "low" | "medium" | "minimal">, import("../schema/options.js").OpenString<"high" | "low" | "medium" | "minimal">>>, never>>;
13
14
  readonly thinkingSummaries: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.declare<import("../schema/options.js").OpenString<"auto" | "none">, import("../schema/options.js").OpenString<"auto" | "none">>>, never>>;
14
15
  readonly serviceTier: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.declare<import("../schema/options.js").OpenString<"deferred" | "flex" | "priority" | "standard">, import("../schema/options.js").OpenString<"deferred" | "flex" | "priority" | "standard">>>, never>>;
16
+ readonly safetySettings: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.$Array<Schema.Struct<{
17
+ readonly category: Schema.declare<import("../schema/options.js").OpenString<"HARM_CATEGORY_CIVIC_INTEGRITY" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_UNSPECIFIED">, import("../schema/options.js").OpenString<"HARM_CATEGORY_CIVIC_INTEGRITY" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_UNSPECIFIED">>;
18
+ readonly threshold: Schema.declare<import("../schema/options.js").OpenString<"BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_NONE" | "BLOCK_ONLY_HIGH" | "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "OFF">, import("../schema/options.js").OpenString<"BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_NONE" | "BLOCK_ONLY_HIGH" | "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "OFF">>;
19
+ }>>>, never>>;
15
20
  }>;
16
21
  export type OptionsInput = typeof Options.Encoded;
17
22
  export type ProviderOptionsInput = OptionsInput;
23
+ declare const Body: Schema.Struct<{
24
+ readonly model: Schema.String;
25
+ readonly input: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
26
+ readonly type: Schema.Literals<readonly ["user_input", "model_output"]>;
27
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
28
+ readonly type: Schema.Literal<"text">;
29
+ readonly text: Schema.String;
30
+ }>, Schema.Struct<{
31
+ readonly type: Schema.Literals<readonly ["image", "audio", "video", "document"]>;
32
+ readonly data: Schema.optional<Schema.String>;
33
+ readonly uri: Schema.optional<Schema.String>;
34
+ readonly mime_type: Schema.String;
35
+ }>]>>;
36
+ }>, Schema.Struct<{
37
+ readonly type: Schema.Literal<"thought">;
38
+ readonly signature: Schema.optional<Schema.String>;
39
+ readonly summary: Schema.optional<Schema.$Array<Schema.Struct<{
40
+ readonly type: Schema.Literal<"text">;
41
+ readonly text: Schema.String;
42
+ }>>>;
43
+ }>, Schema.Struct<{
44
+ readonly type: Schema.Literal<"function_call">;
45
+ readonly id: Schema.String;
46
+ readonly name: Schema.String;
47
+ readonly arguments: Schema.Unknown;
48
+ readonly signature: Schema.optional<Schema.String>;
49
+ }>, Schema.Struct<{
50
+ readonly type: Schema.Literal<"function_result">;
51
+ readonly call_id: Schema.String;
52
+ readonly name: Schema.String;
53
+ readonly result: Schema.Unknown;
54
+ readonly is_error: Schema.optional<Schema.Boolean>;
55
+ }>]>>>;
56
+ readonly stream: Schema.Literal<true>;
57
+ readonly store: Schema.Boolean;
58
+ readonly previous_interaction_id: Schema.optional<Schema.String>;
59
+ readonly continuation_token: Schema.optional<Schema.String>;
60
+ readonly system_instruction: Schema.optional<Schema.String>;
61
+ readonly service_tier: Schema.optional<Schema.String>;
62
+ readonly safety_settings: Schema.optional<Schema.$Array<Schema.Struct<{
63
+ readonly type: Schema.String;
64
+ readonly threshold: Schema.String;
65
+ }>>>;
66
+ readonly tools: Schema.optional<Schema.$Array<Schema.Struct<{
67
+ readonly type: Schema.Literal<"function">;
68
+ readonly name: Schema.String;
69
+ readonly description: Schema.String;
70
+ readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
71
+ }>>>;
72
+ readonly generation_config: Schema.Struct<{
73
+ readonly max_output_tokens: Schema.optional<Schema.Number>;
74
+ readonly temperature: Schema.optional<Schema.Number>;
75
+ readonly top_p: Schema.optional<Schema.Number>;
76
+ readonly seed: Schema.optional<Schema.Number>;
77
+ readonly stop_sequences: Schema.optional<Schema.$Array<Schema.String>>;
78
+ readonly thinking_level: Schema.optional<Schema.declare<import("../schema/options.js").OpenString<"high" | "low" | "medium" | "minimal">, import("../schema/options.js").OpenString<"high" | "low" | "medium" | "minimal">>>;
79
+ readonly thinking_summaries: Schema.optional<Schema.String>;
80
+ readonly tool_choice: Schema.optional<Schema.Union<readonly [Schema.Literals<readonly ["auto", "any", "none"]>, Schema.Struct<{
81
+ readonly allowed_tools: Schema.Struct<{
82
+ readonly mode: Schema.Literal<"any">;
83
+ readonly tools: Schema.$Array<Schema.String>;
84
+ }>;
85
+ }>]>>;
86
+ }>;
87
+ }>;
88
+ declare const RawUsage: Schema.StructWithRest<Schema.Struct<{
89
+ readonly total_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
90
+ readonly total_cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
91
+ readonly total_output_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
92
+ readonly total_thought_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
93
+ readonly total_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
94
+ readonly raw_prompt_token: Schema.optional<Schema.NullOr<Schema.Number>>;
95
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
96
+ type RawUsage = typeof RawUsage.Type;
18
97
  declare const OutputStep: Schema.Struct<{
19
98
  readonly type: Schema.String;
20
99
  readonly id: Schema.optional<Schema.String>;
@@ -31,10 +110,105 @@ declare const OutputStep: Schema.Struct<{
31
110
  }>>>;
32
111
  }>;
33
112
  type OutputStep = typeof OutputStep.Type;
113
+ declare const Event: Schema.Union<readonly [Schema.Struct<{
114
+ readonly event_type: Schema.Literal<"step.start">;
115
+ readonly index: Schema.Number;
116
+ readonly step: Schema.Struct<{
117
+ readonly type: Schema.String;
118
+ readonly id: Schema.optional<Schema.String>;
119
+ readonly name: Schema.optional<Schema.String>;
120
+ readonly arguments: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
121
+ readonly signature: Schema.optional<Schema.String>;
122
+ readonly summary: Schema.optional<Schema.$Array<Schema.Struct<{
123
+ readonly type: Schema.Literal<"text">;
124
+ readonly text: Schema.String;
125
+ }>>>;
126
+ readonly content: Schema.optional<Schema.$Array<Schema.Struct<{
127
+ readonly type: Schema.String;
128
+ readonly text: Schema.optional<Schema.String>;
129
+ }>>>;
130
+ }>;
131
+ }>, Schema.Struct<{
132
+ readonly event_type: Schema.Literal<"step.delta">;
133
+ readonly index: Schema.Number;
134
+ readonly delta: Schema.Union<readonly [Schema.Struct<{
135
+ readonly type: Schema.Literal<"text">;
136
+ readonly text: Schema.String;
137
+ }>, Schema.Struct<{
138
+ readonly type: Schema.Literal<"arguments_delta">;
139
+ readonly arguments: Schema.String;
140
+ }>, Schema.Struct<{
141
+ readonly type: Schema.Literal<"thought_signature">;
142
+ readonly signature: Schema.String;
143
+ }>, Schema.Struct<{
144
+ readonly type: Schema.Literal<"thought_summary">;
145
+ readonly content: Schema.Struct<{
146
+ readonly type: Schema.Literal<"text">;
147
+ readonly text: Schema.String;
148
+ }>;
149
+ }>, Schema.decodeTo<Schema.Struct<{
150
+ readonly type: Schema.Literal<"unknown">;
151
+ readonly rawType: Schema.String;
152
+ }>, Schema.Struct<{
153
+ readonly type: Schema.String;
154
+ }>, never, never>]>;
155
+ }>, Schema.Struct<{
156
+ readonly event_type: Schema.Literal<"step.stop">;
157
+ readonly index: Schema.Number;
158
+ }>, Schema.Struct<{
159
+ readonly event_type: Schema.Literal<"interaction.created">;
160
+ readonly interaction: Schema.Struct<{
161
+ readonly id: Schema.optional<Schema.String>;
162
+ }>;
163
+ }>, Schema.Struct<{
164
+ readonly event_type: Schema.Literal<"interaction.status_update">;
165
+ readonly interaction_id: Schema.optional<Schema.String>;
166
+ readonly status: Schema.String;
167
+ readonly continuation_token: Schema.optional<Schema.NullOr<Schema.String>>;
168
+ readonly usage: Schema.optional<Schema.StructWithRest<Schema.Struct<{
169
+ readonly total_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
170
+ readonly total_cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
171
+ readonly total_output_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
172
+ readonly total_thought_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
173
+ readonly total_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
174
+ readonly raw_prompt_token: Schema.optional<Schema.NullOr<Schema.Number>>;
175
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>;
176
+ }>, Schema.Struct<{
177
+ readonly event_type: Schema.Literal<"interaction.completed">;
178
+ readonly interaction: Schema.StructWithRest<Schema.Struct<{
179
+ readonly id: Schema.optional<Schema.String>;
180
+ readonly status: Schema.String;
181
+ readonly continuation_token: Schema.optional<Schema.NullOr<Schema.String>>;
182
+ readonly usage: Schema.optional<Schema.StructWithRest<Schema.Struct<{
183
+ readonly total_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
184
+ readonly total_cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
185
+ readonly total_output_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
186
+ readonly total_thought_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
187
+ readonly total_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
188
+ readonly raw_prompt_token: Schema.optional<Schema.NullOr<Schema.Number>>;
189
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>;
190
+ readonly errors: Schema.optional<Schema.$Array<Schema.Struct<{
191
+ readonly code: Schema.optional<Schema.String>;
192
+ readonly message: Schema.optional<Schema.String>;
193
+ }>>>;
194
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
195
+ }>, Schema.Struct<{
196
+ readonly event_type: Schema.Literal<"error">;
197
+ readonly error: Schema.optionalKey<Schema.Unknown>;
198
+ }>, Schema.decodeTo<Schema.Struct<{
199
+ readonly event_type: Schema.Literal<"unknown">;
200
+ }>, Schema.Struct<{
201
+ readonly event_type: Schema.String;
202
+ }>, never, never>]>;
203
+ type Event = typeof Event.Type;
34
204
  interface ParserState {
35
205
  readonly route: string;
36
206
  readonly metadataKey: string;
37
207
  readonly lifecycle: Lifecycle.State;
208
+ readonly hop: number;
209
+ readonly hasToolCalls: boolean;
210
+ readonly usage?: RawUsage;
211
+ readonly continuedUsage: ReadonlyArray<RawUsage | undefined>;
38
212
  readonly steps: Partial<Record<number, OutputStep>>;
39
213
  readonly tools: ToolStream.State<number>;
40
214
  }
@@ -49,9 +223,17 @@ export declare const mediaContent: (asset: Media.Asset) => Effect.Effect<{
49
223
  data: string;
50
224
  mime_type: string;
51
225
  }, AIError, never>;
226
+ declare class NextRequest {
227
+ }
228
+ type Body = typeof Body.Type;
229
+ export interface Prepared {
230
+ readonly http: HttpTransport.HttpPrepared<string>;
231
+ readonly input: TransportPrepareInput<Body>;
232
+ }
233
+ export declare const transport: Transport<Body, Prepared, Event | NextRequest>;
52
234
  export declare const protocol: Protocol<{
53
235
  readonly model: string;
54
- readonly input: readonly ({
236
+ readonly input?: readonly ({
55
237
  readonly type: "model_output" | "user_input";
56
238
  readonly content: readonly ({
57
239
  readonly type: "text";
@@ -81,12 +263,17 @@ export declare const protocol: Protocol<{
81
263
  readonly name: string;
82
264
  readonly result: unknown;
83
265
  readonly is_error?: boolean | undefined;
84
- })[];
266
+ })[] | undefined;
85
267
  readonly stream: true;
86
268
  readonly store: boolean;
87
269
  readonly previous_interaction_id?: string | undefined;
270
+ readonly continuation_token?: string | undefined;
88
271
  readonly system_instruction?: string | undefined;
89
272
  readonly service_tier?: string | undefined;
273
+ readonly safety_settings?: readonly {
274
+ readonly type: string;
275
+ readonly threshold: string;
276
+ }[] | undefined;
90
277
  readonly tools?: readonly {
91
278
  readonly type: "function";
92
279
  readonly name: string;
@@ -110,7 +297,97 @@ export declare const protocol: Protocol<{
110
297
  };
111
298
  } | undefined;
112
299
  };
113
- }, string, {
300
+ }, string | NextRequest | {
301
+ readonly event_type: "unknown";
302
+ } | {
303
+ readonly event_type: "step.start";
304
+ readonly index: number;
305
+ readonly step: {
306
+ readonly type: string;
307
+ readonly id?: string | undefined;
308
+ readonly name?: string | undefined;
309
+ readonly arguments?: {
310
+ readonly [x: string]: unknown;
311
+ } | undefined;
312
+ readonly signature?: string | undefined;
313
+ readonly summary?: readonly {
314
+ readonly type: "text";
315
+ readonly text: string;
316
+ }[] | undefined;
317
+ readonly content?: readonly {
318
+ readonly type: string;
319
+ readonly text?: string | undefined;
320
+ }[] | undefined;
321
+ };
322
+ } | {
323
+ readonly event_type: "step.delta";
324
+ readonly index: number;
325
+ readonly delta: {
326
+ readonly type: "unknown";
327
+ readonly rawType: string;
328
+ } | {
329
+ readonly type: "text";
330
+ readonly text: string;
331
+ } | {
332
+ readonly type: "arguments_delta";
333
+ readonly arguments: string;
334
+ } | {
335
+ readonly type: "thought_signature";
336
+ readonly signature: string;
337
+ } | {
338
+ readonly type: "thought_summary";
339
+ readonly content: {
340
+ readonly type: "text";
341
+ readonly text: string;
342
+ };
343
+ };
344
+ } | {
345
+ readonly event_type: "step.stop";
346
+ readonly index: number;
347
+ } | {
348
+ readonly event_type: "interaction.created";
349
+ readonly interaction: {
350
+ readonly id?: string | undefined;
351
+ };
352
+ } | {
353
+ readonly event_type: "interaction.completed";
354
+ readonly interaction: {
355
+ readonly [x: string]: unknown;
356
+ readonly id?: string | undefined;
357
+ readonly status: string;
358
+ readonly continuation_token?: string | null | undefined;
359
+ readonly usage?: {
360
+ readonly [x: string]: unknown;
361
+ readonly total_input_tokens?: number | null | undefined;
362
+ readonly total_cached_tokens?: number | null | undefined;
363
+ readonly total_output_tokens?: number | null | undefined;
364
+ readonly total_thought_tokens?: number | null | undefined;
365
+ readonly total_tokens?: number | null | undefined;
366
+ readonly raw_prompt_token?: number | null | undefined;
367
+ } | undefined;
368
+ readonly errors?: readonly {
369
+ readonly code?: string | undefined;
370
+ readonly message?: string | undefined;
371
+ }[] | undefined;
372
+ };
373
+ } | {
374
+ readonly event_type: "interaction.status_update";
375
+ readonly interaction_id?: string | undefined;
376
+ readonly status: string;
377
+ readonly continuation_token?: string | null | undefined;
378
+ readonly usage?: {
379
+ readonly [x: string]: unknown;
380
+ readonly total_input_tokens?: number | null | undefined;
381
+ readonly total_cached_tokens?: number | null | undefined;
382
+ readonly total_output_tokens?: number | null | undefined;
383
+ readonly total_thought_tokens?: number | null | undefined;
384
+ readonly total_tokens?: number | null | undefined;
385
+ readonly raw_prompt_token?: number | null | undefined;
386
+ } | undefined;
387
+ } | {
388
+ readonly event_type: "error";
389
+ readonly error?: unknown;
390
+ }, NextRequest | {
114
391
  readonly event_type: "unknown";
115
392
  } | {
116
393
  readonly event_type: "step.start";
@@ -168,6 +445,7 @@ export declare const protocol: Protocol<{
168
445
  readonly [x: string]: unknown;
169
446
  readonly id?: string | undefined;
170
447
  readonly status: string;
448
+ readonly continuation_token?: string | null | undefined;
171
449
  readonly usage?: {
172
450
  readonly [x: string]: unknown;
173
451
  readonly total_input_tokens?: number | null | undefined;
@@ -186,13 +464,23 @@ export declare const protocol: Protocol<{
186
464
  readonly event_type: "interaction.status_update";
187
465
  readonly interaction_id?: string | undefined;
188
466
  readonly status: string;
467
+ readonly continuation_token?: string | null | undefined;
468
+ readonly usage?: {
469
+ readonly [x: string]: unknown;
470
+ readonly total_input_tokens?: number | null | undefined;
471
+ readonly total_cached_tokens?: number | null | undefined;
472
+ readonly total_output_tokens?: number | null | undefined;
473
+ readonly total_thought_tokens?: number | null | undefined;
474
+ readonly total_tokens?: number | null | undefined;
475
+ readonly raw_prompt_token?: number | null | undefined;
476
+ } | undefined;
189
477
  } | {
190
478
  readonly event_type: "error";
191
479
  readonly error?: unknown;
192
480
  }, ParserState>;
193
481
  export declare const route: Route<{
194
482
  readonly model: string;
195
- readonly input: readonly ({
483
+ readonly input?: readonly ({
196
484
  readonly type: "model_output" | "user_input";
197
485
  readonly content: readonly ({
198
486
  readonly type: "text";
@@ -222,12 +510,17 @@ export declare const route: Route<{
222
510
  readonly name: string;
223
511
  readonly result: unknown;
224
512
  readonly is_error?: boolean | undefined;
225
- })[];
513
+ })[] | undefined;
226
514
  readonly stream: true;
227
515
  readonly store: boolean;
228
516
  readonly previous_interaction_id?: string | undefined;
517
+ readonly continuation_token?: string | undefined;
229
518
  readonly system_instruction?: string | undefined;
230
519
  readonly service_tier?: string | undefined;
520
+ readonly safety_settings?: readonly {
521
+ readonly type: string;
522
+ readonly threshold: string;
523
+ }[] | undefined;
231
524
  readonly tools?: readonly {
232
525
  readonly type: "function";
233
526
  readonly name: string;
@@ -251,5 +544,5 @@ export declare const route: Route<{
251
544
  };
252
545
  } | undefined;
253
546
  };
254
- }, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>;
547
+ }, Prepared, import("../route/client.js").CompactionOperations | undefined>;
255
548
  export * as GoogleInteractions from "./google-interactions.js";
@@ -1,9 +1,9 @@
1
- import { Effect, Option, Schema, SchemaGetter } from "effect";
1
+ import { Effect, Option, Schema, SchemaGetter, Stream } from "effect";
2
2
  import { Route } from "../route/client.js";
3
3
  import { Auth } from "../route/auth.js";
4
4
  import { Endpoint } from "../route/endpoint.js";
5
- import { Framing } from "../route/framing.js";
6
5
  import { Protocol } from "../route/protocol.js";
6
+ import { HttpTransport, } from "../route/transport/index.js";
7
7
  import { AIError, ContentPolicyError, InvalidProviderOutputError, LLMEvent, ProviderID, Usage, } from "../schema/index.js";
8
8
  import { Media } from "../media.js";
9
9
  import { classifyProviderFailure, providerErrorMessage } from "../provider-error.js";
@@ -14,6 +14,9 @@ import { MediaInput } from "./utils/media-input.js";
14
14
  import { GeminiGenerateContent } from "./utils/gemini-generate-content.js";
15
15
  import { ToolStream } from "./utils/tool-stream.js";
16
16
  const ADAPTER = "google-interactions";
17
+ const CONTINUATION = "requires_continuation";
18
+ // Matches Google's GenAI SDKs (Python, JS, and Go).
19
+ const MAX_STREAM_RECONNECTS_WITHOUT_PROGRESS = 3;
17
20
  const SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
18
21
  export const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
19
22
  // =============================================================================
@@ -26,6 +29,7 @@ const Options = Schema.Struct({
26
29
  thinkingLevel: lenient(ThinkingLevel),
27
30
  thinkingSummaries: lenient(knownString()),
28
31
  serviceTier: lenient(knownString()),
32
+ safetySettings: lenient(Schema.Array(GeminiGenerateContent.SafetySetting)),
29
33
  });
30
34
  const decodeOptions = ProviderShared.validateWith(Schema.decodeUnknownEffect(Options));
31
35
  // =============================================================================
@@ -67,12 +71,14 @@ const ToolChoice = Schema.Union([
67
71
  ]);
68
72
  const Body = Schema.Struct({
69
73
  model: Schema.String,
70
- input: Schema.Array(InputStep),
74
+ input: Schema.optional(Schema.Array(InputStep)),
71
75
  stream: Schema.Literal(true),
72
76
  store: Schema.Boolean,
73
77
  previous_interaction_id: Schema.optional(Schema.String),
78
+ continuation_token: Schema.optional(Schema.String),
74
79
  system_instruction: Schema.optional(Schema.String),
75
80
  service_tier: Schema.optional(Schema.String),
81
+ safety_settings: Schema.optional(Schema.Array(Schema.Struct({ type: Schema.String, threshold: Schema.String }))),
76
82
  tools: Schema.optional(Schema.Array(Schema.Struct({
77
83
  type: Schema.Literal("function"),
78
84
  name: Schema.String,
@@ -128,6 +134,7 @@ const Delta = Schema.Union([
128
134
  const Interaction = Schema.StructWithRest(Schema.Struct({
129
135
  id: Schema.optional(Schema.String),
130
136
  status: Schema.String,
137
+ continuation_token: optionalNull(Schema.String),
131
138
  usage: Schema.optional(RawUsage),
132
139
  errors: Schema.optional(Schema.Array(Schema.Struct({ code: Schema.optional(Schema.String), message: Schema.optional(Schema.String) }))),
133
140
  }), [Schema.Record(Schema.String, Schema.Unknown)]);
@@ -164,6 +171,8 @@ const Event = Schema.Union([
164
171
  event_type: Schema.Literal("interaction.status_update"),
165
172
  interaction_id: Schema.optional(Schema.String),
166
173
  status: Schema.String,
174
+ continuation_token: optionalNull(Schema.String),
175
+ usage: Schema.optional(RawUsage),
167
176
  }),
168
177
  Schema.Struct({ event_type: Schema.Literal("interaction.completed"), interaction: Interaction }),
169
178
  Schema.Struct({ event_type: Schema.Literal("error"), error: Schema.optionalKey(Schema.Unknown) }),
@@ -172,12 +181,26 @@ const Event = Schema.Union([
172
181
  // =============================================================================
173
182
  // Request Body Construction
174
183
  // =============================================================================
184
+ // https://aistudio.google.com/docs/document-processing#office-documents
185
+ const OFFICE_DOCUMENT_MIME_TYPES = new Set([
186
+ "application/msword",
187
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
188
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
189
+ "application/vnd.oasis.opendocument.text",
190
+ "application/vnd.ms-powerpoint",
191
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation",
192
+ "application/vnd.oasis.opendocument.presentation",
193
+ "application/vnd.ms-excel",
194
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
195
+ "application/vnd.oasis.opendocument.spreadsheet",
196
+ ]);
175
197
  export const mediaContent = Effect.fnUntraced(function* (asset) {
176
198
  if (asset.kind !== "image" &&
177
199
  asset.kind !== "audio" &&
178
200
  asset.kind !== "video" &&
179
201
  asset.mediaType !== "application/pdf" &&
180
- asset.mediaType !== "text/csv")
202
+ asset.mediaType !== "text/csv" &&
203
+ !OFFICE_DOCUMENT_MIME_TYPES.has(asset.mediaType))
181
204
  return yield* ProviderShared.invalidRequest(`Google Interactions does not support ${asset.mediaType} document input`);
182
205
  const type = asset.kind === "image" || asset.kind === "audio" || asset.kind === "video" ? asset.kind : "document";
183
206
  const uri = asset.kind === "video" && asset.source.type === "url" && /^https?:\/\//i.test(asset.source.url)
@@ -297,6 +320,10 @@ const fromRequest = Effect.fn("GoogleInteractions.fromRequest")(function* (reque
297
320
  previous_interaction_id: options.previousInteractionId,
298
321
  system_instruction: request.system.length ? ProviderShared.joinText(request.system) : undefined,
299
322
  service_tier: options.serviceTier,
323
+ safety_settings: options.safetySettings?.map((setting) => ({
324
+ type: setting.category.replace(/^HARM_CATEGORY_/, "").toLowerCase(),
325
+ threshold: setting.threshold.toLowerCase(),
326
+ })),
300
327
  tools: flattened.tools.length
301
328
  ? flattened.tools.map((tool) => ({
302
329
  type: "function",
@@ -323,31 +350,52 @@ const fromRequest = Effect.fn("GoogleInteractions.fromRequest")(function* (reque
323
350
  const metadata = (state, step) => ({
324
351
  [state.metadataKey]: { interactionSignature: step.signature },
325
352
  });
326
- const mapUsage = (usage, key) => {
327
- if (!usage)
353
+ const mapUsage = (usage, key, continued) => {
354
+ if (!usage && continued.every((hop) => !hop))
328
355
  return undefined;
329
- const input = usage.total_input_tokens ?? undefined;
330
- const cached = usage.total_cached_tokens ?? undefined;
331
- const reasoning = usage.total_thought_tokens ?? undefined;
332
- const output = usage.total_output_tokens === undefined || usage.total_output_tokens === null
333
- ? undefined
334
- : usage.total_output_tokens + (reasoning ?? 0);
356
+ const first = continued.length ? continued[0] : usage;
357
+ const hops = [...continued, usage];
358
+ const sum = (field) => ProviderShared.sumTokens(...hops.map((hop) => (hop ? (field(hop) ?? undefined) : undefined)));
359
+ const input = first?.total_input_tokens ?? undefined;
360
+ const cached = first?.total_cached_tokens ?? undefined;
361
+ const reasoning = sum((hop) => hop.total_thought_tokens);
362
+ const text = sum((hop) => hop.total_output_tokens);
363
+ const output = continued.length
364
+ ? ProviderShared.sumTokens(text, reasoning)
365
+ : text === undefined
366
+ ? undefined
367
+ : text + (reasoning ?? 0);
335
368
  return new Usage({
336
- contextTokens: usage.raw_prompt_token ?? input,
369
+ contextTokens: first?.raw_prompt_token ?? input,
337
370
  inputTokens: input,
338
371
  outputTokens: output,
339
372
  nonCachedInputTokens: ProviderShared.subtractTokens(input, cached),
340
373
  cacheReadInputTokens: cached,
341
374
  reasoningTokens: reasoning,
342
- totalTokens: usage.total_tokens ?? undefined,
343
- providerMetadata: { [key]: usage },
375
+ totalTokens: continued.length
376
+ ? ProviderShared.totalTokens(input, output, undefined)
377
+ : (usage?.total_tokens ?? undefined),
378
+ // Keep re-billed input in provider metadata, separate from the logical call's input.
379
+ providerMetadata: {
380
+ [key]: continued.length
381
+ ? {
382
+ total_input_tokens: sum((hop) => hop.total_input_tokens),
383
+ total_cached_tokens: sum((hop) => hop.total_cached_tokens),
384
+ total_output_tokens: text,
385
+ total_thought_tokens: reasoning,
386
+ total_tokens: sum((hop) => hop.total_tokens),
387
+ requests: hops.length,
388
+ }
389
+ : (usage ?? {}),
390
+ },
344
391
  });
345
392
  };
393
+ const blockID = (state, index) => (state.hop === 0 ? String(index) : `${state.hop}:${index}`);
346
394
  const onStart = Effect.fnUntraced(function* (state, index, step) {
347
395
  const events = [];
348
396
  let lifecycle = Lifecycle.stepStart(state.lifecycle, events);
349
397
  let tools = state.tools;
350
- const id = String(index);
398
+ const id = blockID(state, index);
351
399
  if (step.type === "thought") {
352
400
  lifecycle = Lifecycle.reasoningStart(lifecycle, events, id, metadata(state, step));
353
401
  for (const part of step.summary ?? [])
@@ -375,7 +423,16 @@ const onStart = Effect.fnUntraced(function* (state, index, step) {
375
423
  }
376
424
  else
377
425
  return yield* ProviderShared.eventError(ADAPTER, `Unsupported Interactions step: ${step.type}`, encodeJson(step));
378
- return [{ ...state, lifecycle, tools, steps: { ...state.steps, [index]: step } }, events];
426
+ return [
427
+ {
428
+ ...state,
429
+ lifecycle,
430
+ tools,
431
+ hasToolCalls: state.hasToolCalls || step.type === "function_call",
432
+ steps: { ...state.steps, [index]: step },
433
+ },
434
+ events,
435
+ ];
379
436
  });
380
437
  const onDelta = Effect.fnUntraced(function* (state, index, delta) {
381
438
  const step = state.steps[index];
@@ -384,12 +441,15 @@ const onDelta = Effect.fnUntraced(function* (state, index, delta) {
384
441
  const events = [];
385
442
  if (delta.type === "text" && step.type === "model_output")
386
443
  return [
387
- { ...state, lifecycle: Lifecycle.textDelta(state.lifecycle, events, String(index), delta.text) },
444
+ { ...state, lifecycle: Lifecycle.textDelta(state.lifecycle, events, blockID(state, index), delta.text) },
388
445
  events,
389
446
  ];
390
447
  if (delta.type === "thought_summary" && step.type === "thought")
391
448
  return [
392
- { ...state, lifecycle: Lifecycle.reasoningDelta(state.lifecycle, events, String(index), delta.content.text) },
449
+ {
450
+ ...state,
451
+ lifecycle: Lifecycle.reasoningDelta(state.lifecycle, events, blockID(state, index), delta.content.text),
452
+ },
393
453
  events,
394
454
  ];
395
455
  if (delta.type === "thought_signature") {
@@ -419,12 +479,15 @@ const onStop = Effect.fnUntraced(function* (state, index) {
419
479
  const events = [];
420
480
  if (step.type === "thought")
421
481
  return [
422
- { ...state, lifecycle: Lifecycle.reasoningEnd(state.lifecycle, events, String(index), metadata(state, step)) },
482
+ {
483
+ ...state,
484
+ lifecycle: Lifecycle.reasoningEnd(state.lifecycle, events, blockID(state, index), metadata(state, step)),
485
+ },
423
486
  events,
424
487
  ];
425
488
  if (step.type === "model_output")
426
489
  return [
427
- { ...state, lifecycle: Lifecycle.textEnd(state.lifecycle, events, String(index)) },
490
+ { ...state, lifecycle: Lifecycle.textEnd(state.lifecycle, events, blockID(state, index)) },
428
491
  events,
429
492
  ];
430
493
  const result = yield* ToolStream.finish(ADAPTER, state.tools, index);
@@ -447,7 +510,34 @@ const failureReason = (route, code, message, data, rawBody) => {
447
510
  return new ContentPolicyError({ message, body: rawBody });
448
511
  return classifyProviderFailure({ message, data, rawBody });
449
512
  };
513
+ // Marks a request boundary without adding another logical LLM step or finish.
514
+ class NextRequest {
515
+ }
450
516
  const step = Effect.fnUntraced(function* (state, event) {
517
+ if (event instanceof NextRequest) {
518
+ const pending = yield* ToolStream.finishAll(ADAPTER, state.tools);
519
+ const events = [...pending.events];
520
+ let lifecycle = state.lifecycle;
521
+ for (const [index, step] of Object.entries(state.steps)) {
522
+ const id = blockID(state, Number(index));
523
+ if (step?.type === "thought")
524
+ lifecycle = Lifecycle.reasoningEnd(lifecycle, events, id, metadata(state, step));
525
+ if (step?.type === "model_output")
526
+ lifecycle = Lifecycle.textEnd(lifecycle, events, id);
527
+ }
528
+ return [
529
+ {
530
+ ...state,
531
+ hop: state.hop + 1,
532
+ lifecycle,
533
+ steps: {},
534
+ tools: ToolStream.empty(),
535
+ usage: undefined,
536
+ continuedUsage: [...state.continuedUsage, state.usage],
537
+ },
538
+ events,
539
+ ];
540
+ }
451
541
  switch (event.event_type) {
452
542
  case "step.start":
453
543
  return yield* onStart(state, event.index, event.step);
@@ -455,8 +545,9 @@ const step = Effect.fnUntraced(function* (state, event) {
455
545
  return yield* onDelta(state, event.index, event.delta);
456
546
  case "step.stop":
457
547
  return yield* onStop(state, event.index);
458
- case "interaction.created":
459
548
  case "interaction.status_update":
549
+ return [{ ...state, usage: event.usage ?? state.usage }, []];
550
+ case "interaction.created":
460
551
  case "unknown":
461
552
  return [state, []];
462
553
  case "error": {
@@ -468,6 +559,8 @@ const step = Effect.fnUntraced(function* (state, event) {
468
559
  }
469
560
  case "interaction.completed": {
470
561
  const interaction = event.interaction;
562
+ if (interaction.status === CONTINUATION)
563
+ return [{ ...state, usage: interaction.usage ?? state.usage }, []];
471
564
  if (interaction.status === "failed" || interaction.status === "cancelled") {
472
565
  const messages = (interaction.errors ?? []).flatMap((error) => (error.message?.trim() ? [error.message] : []));
473
566
  const coded = interaction.errors?.find((error) => error.code);
@@ -481,23 +574,143 @@ const step = Effect.fnUntraced(function* (state, event) {
481
574
  return yield* ProviderShared.eventError(ADAPTER, `Unexpected terminal Interactions status: ${interaction.status}`, encodeJson(event));
482
575
  const pending = yield* ToolStream.finishAll(ADAPTER, state.tools);
483
576
  const events = [...pending.events];
484
- const hasToolCalls = Object.values(state.steps).some((item) => item?.type === "function_call");
485
577
  const lifecycle = Lifecycle.finish(state.lifecycle, events, {
486
578
  reason: {
487
- normalized: interaction.status === "requires_action" || (interaction.status === "completed" && hasToolCalls)
579
+ normalized: interaction.status === "requires_action" || (interaction.status === "completed" && state.hasToolCalls)
488
580
  ? "tool-calls"
489
581
  : interaction.status === "incomplete"
490
582
  ? "length"
491
583
  : "stop",
492
584
  raw: interaction.status,
493
585
  },
494
- usage: mapUsage(interaction.usage, state.metadataKey),
586
+ usage: mapUsage(interaction.usage ?? state.usage, state.metadataKey, state.continuedUsage),
495
587
  providerMetadata: { [state.metadataKey]: { interactionId: interaction.id } },
496
588
  });
497
589
  return [{ ...state, lifecycle, tools: pending.tools }, events];
498
590
  }
499
591
  }
500
592
  });
593
+ const sse = HttpTransport.sseJson.with();
594
+ const WireEvent = Protocol.jsonEvent(Event);
595
+ const decodeEvent = Schema.decodeUnknownEffect(WireEvent);
596
+ export const transport = {
597
+ id: sse.id,
598
+ prepare: (input) => sse.prepare(input).pipe(Effect.map((http) => ({ http, input }))),
599
+ execute: (prepared, request, runtime) => Effect.gen(function* () {
600
+ const label = `${request.model.provider}/${request.model.route.id}`;
601
+ const raw = new WeakMap();
602
+ const respond = (execution, resume) => Stream.suspend(() => {
603
+ let token = resume?.token;
604
+ let owner;
605
+ let status;
606
+ let contentSinceToken = false;
607
+ let terminal = false;
608
+ let dropped;
609
+ const pendingTools = new Set();
610
+ return execution.frames.pipe(Stream.mapEffect((frame) => decodeEvent(frame).pipe(Effect.mapError((cause) => ProviderShared.eventError(ADAPTER, `Invalid ${label} stream event`, frame, cause)), Effect.map((event) => {
611
+ raw.set(event, frame);
612
+ switch (event.event_type) {
613
+ case "interaction.created":
614
+ owner = event.interaction.id;
615
+ break;
616
+ case "interaction.status_update":
617
+ status = event.status;
618
+ owner = event.interaction_id ?? owner;
619
+ if (event.continuation_token && event.continuation_token !== token) {
620
+ token = event.continuation_token;
621
+ contentSinceToken = false;
622
+ }
623
+ break;
624
+ case "interaction.completed":
625
+ terminal = true;
626
+ status = event.interaction.status;
627
+ owner = event.interaction.id ?? owner;
628
+ if (event.interaction.continuation_token) {
629
+ token = event.interaction.continuation_token;
630
+ contentSinceToken = false;
631
+ }
632
+ break;
633
+ case "step.start":
634
+ if (event.step.type === "function_call")
635
+ pendingTools.add(event.index);
636
+ if (pendingTools.has(event.index) ||
637
+ event.step.content?.length ||
638
+ event.step.summary?.length ||
639
+ event.step.signature)
640
+ contentSinceToken = true;
641
+ break;
642
+ case "step.delta":
643
+ contentSinceToken = true;
644
+ break;
645
+ case "step.stop":
646
+ if (pendingTools.delete(event.index))
647
+ contentSinceToken = true;
648
+ break;
649
+ }
650
+ return event;
651
+ }))), Stream.takeUntil((event) => event.event_type === "interaction.completed"), Stream.catchIf((error) => error.reason._tag === "Transport" && error.reason.code !== "Timeout", (error) => {
652
+ dropped = error;
653
+ return Stream.empty;
654
+ }), Stream.concat(Stream.suspend(() => {
655
+ const needsContinuation = status === CONTINUATION;
656
+ const resumable = needsContinuation || (!terminal && (status === undefined || status === "in_progress"));
657
+ const newToken = token !== resume?.token;
658
+ // An interrupted tool call may carry arguments across the checkpoint. Don't finalize it on EOF.
659
+ if (token &&
660
+ resumable &&
661
+ !contentSinceToken &&
662
+ (terminal || pendingTools.size === 0) &&
663
+ (!needsContinuation || newToken)) {
664
+ const reconnectsWithoutProgress = newToken ? 0 : (resume?.reconnectsWithoutProgress ?? 0) + 1;
665
+ const lastError = dropped ?? (newToken ? undefined : resume?.lastError);
666
+ if (reconnectsWithoutProgress > MAX_STREAM_RECONNECTS_WITHOUT_PROGRESS) {
667
+ if (!lastError)
668
+ return Stream.empty;
669
+ return Stream.fail(new AIError({
670
+ reason: new InvalidProviderOutputError({
671
+ route: label,
672
+ message: lastError.reason.message,
673
+ classification: "incomplete-stream",
674
+ cause: lastError,
675
+ http: lastError.reason.http,
676
+ }),
677
+ }));
678
+ }
679
+ return Stream.concat(Stream.succeed(new NextRequest()), next({ token, owner: newToken ? owner : resume?.owner, reconnectsWithoutProgress, lastError }));
680
+ }
681
+ if (dropped)
682
+ return Stream.fail(dropped);
683
+ if (terminal && needsContinuation && !token)
684
+ return Stream.fail(ProviderShared.eventError(label, "Google Interactions continued without a token"));
685
+ // No safe checkpoint. Leave EOF for the route's incomplete-stream check.
686
+ return Stream.empty;
687
+ })));
688
+ });
689
+ const next = (resume) => {
690
+ const body = prepared.input.body;
691
+ return Stream.unwrap(sse
692
+ .prepare({
693
+ ...prepared.input,
694
+ body: {
695
+ ...body,
696
+ continuation_token: resume.token,
697
+ ...(body.store && resume.owner ? { input: undefined, previous_interaction_id: resume.owner } : {}),
698
+ },
699
+ })
700
+ .pipe(Effect.flatMap((continued) => sse.execute(continued, request, runtime)), Effect.map((execution) => respond(execution, resume))));
701
+ };
702
+ const first = yield* sse.execute(prepared.http, request, runtime);
703
+ return {
704
+ frames: respond(first),
705
+ http: first.http,
706
+ body: (frame) => raw.get(frame),
707
+ raw: (frame) => {
708
+ const body = raw.get(frame);
709
+ return body === undefined ? undefined : ProviderShared.decodeJson(body);
710
+ },
711
+ };
712
+ }),
713
+ };
501
714
  // =============================================================================
502
715
  // Protocol And Route
503
716
  // =============================================================================
@@ -506,16 +719,21 @@ export const protocol = Protocol.make({
506
719
  sanitizer: "gemini",
507
720
  body: { schema: Body, from: fromRequest },
508
721
  stream: {
509
- event: Protocol.jsonEvent(Event),
722
+ event: Schema.Union([Schema.instanceOf(NextRequest), Schema.toType(Event), WireEvent]),
510
723
  initial: (request) => ({
511
724
  route: `${request.model.provider}/${request.model.route.id}`,
512
725
  metadataKey: request.model.route.providerMetadataKey ?? request.model.provider,
513
726
  lifecycle: Lifecycle.initial(),
727
+ hop: 0,
728
+ hasToolCalls: false,
729
+ continuedUsage: [],
514
730
  steps: {},
515
731
  tools: ToolStream.empty(),
516
732
  }),
517
733
  step,
518
- terminal: (event) => event.event_type === "interaction.completed",
734
+ terminal: (event) => !(event instanceof NextRequest) &&
735
+ event.event_type === "interaction.completed" &&
736
+ event.interaction.status !== CONTINUATION,
519
737
  },
520
738
  });
521
739
  export const route = Route.make({
@@ -525,6 +743,6 @@ export const route = Route.make({
525
743
  protocol,
526
744
  endpoint: Endpoint.path("/interactions", { baseURL: DEFAULT_BASE_URL }),
527
745
  auth: Auth.none,
528
- framing: Framing.sse,
746
+ transport,
529
747
  });
530
748
  export * as GoogleInteractions from "./google-interactions.js";
@@ -3,6 +3,10 @@ import type { Tool } from "@opencode/schema/tool";
3
3
  import { Media } from "../../media.js";
4
4
  import type { MediaProtocol } from "../../route/media-protocol.js";
5
5
  import { AIError, type MediaUsage, type ProviderMetadata } from "../../schema/index.js";
6
+ export declare const SafetySetting: Schema.Struct<{
7
+ readonly category: Schema.declare<import("../../schema/options.js").OpenString<"HARM_CATEGORY_CIVIC_INTEGRITY" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_UNSPECIFIED">, import("../../schema/options.js").OpenString<"HARM_CATEGORY_CIVIC_INTEGRITY" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_UNSPECIFIED">>;
8
+ readonly threshold: Schema.declare<import("../../schema/options.js").OpenString<"BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_NONE" | "BLOCK_ONLY_HIGH" | "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "OFF">, import("../../schema/options.js").OpenString<"BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_NONE" | "BLOCK_ONLY_HIGH" | "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "OFF">>;
9
+ }>;
6
10
  declare const UsageMetadata: Schema.Struct<{
7
11
  readonly promptTokenCount: Schema.optional<Schema.Number>;
8
12
  readonly candidatesTokenCount: Schema.optional<Schema.Number>;
@@ -2,9 +2,13 @@ import { Effect, Schema } from "effect";
2
2
  import { Media } from "../../media.js";
3
3
  import { Framing } from "../../route/framing.js";
4
4
  import { AIError, ContentPolicyError, ProviderID, tokenUsage, } from "../../schema/index.js";
5
- import { ProviderShared } from "../shared.js";
5
+ import { knownString, ProviderShared } from "../shared.js";
6
6
  import { MediaInput } from "./media-input.js";
7
7
  const PROVIDER = ProviderID.make("google");
8
+ export const SafetySetting = Schema.Struct({
9
+ category: knownString(),
10
+ threshold: knownString(),
11
+ });
8
12
  const UsageMetadata = Schema.Struct({
9
13
  promptTokenCount: Schema.optional(Schema.Number),
10
14
  candidatesTokenCount: Schema.optional(Schema.Number),
@@ -24,7 +24,7 @@ export type Settings = ProviderPackage.Settings & GoogleInteractions.ProviderOpt
24
24
  };
25
25
  export declare const routes: Route<{
26
26
  readonly model: string;
27
- readonly input: readonly ({
27
+ readonly input?: readonly ({
28
28
  readonly type: "model_output" | "user_input";
29
29
  readonly content: readonly ({
30
30
  readonly type: "text";
@@ -54,12 +54,17 @@ export declare const routes: Route<{
54
54
  readonly name: string;
55
55
  readonly result: unknown;
56
56
  readonly is_error?: boolean | undefined;
57
- })[];
57
+ })[] | undefined;
58
58
  readonly stream: true;
59
59
  readonly store: boolean;
60
60
  readonly previous_interaction_id?: string | undefined;
61
+ readonly continuation_token?: string | undefined;
61
62
  readonly system_instruction?: string | undefined;
62
63
  readonly service_tier?: string | undefined;
64
+ readonly safety_settings?: readonly {
65
+ readonly type: string;
66
+ readonly threshold: string;
67
+ }[] | undefined;
63
68
  readonly tools?: readonly {
64
69
  readonly type: "function";
65
70
  readonly name: string;
@@ -83,7 +88,7 @@ export declare const routes: Route<{
83
88
  };
84
89
  } | undefined;
85
90
  };
86
- }, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>[];
91
+ }, GoogleInteractions.Prepared, import("../route/client.js").CompactionOperations | undefined>[];
87
92
  export declare const configure: (input?: Config) => {
88
93
  id: string & import("effect/Brand").Brand<"AI.ProviderID">;
89
94
  model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
@@ -92,6 +97,10 @@ export declare const configure: (input?: Config) => {
92
97
  readonly thinkingLevel?: import("../schema/options.js").OpenString<"high" | "low" | "medium" | "minimal"> | undefined;
93
98
  readonly thinkingSummaries?: import("../schema/options.js").OpenString<"auto" | "none"> | undefined;
94
99
  readonly serviceTier?: import("../schema/options.js").OpenString<"deferred" | "flex" | "priority" | "standard"> | undefined;
100
+ readonly safetySettings?: readonly {
101
+ readonly category: import("../schema/options.js").OpenString<"HARM_CATEGORY_CIVIC_INTEGRITY" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_UNSPECIFIED">;
102
+ readonly threshold: import("../schema/options.js").OpenString<"BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_NONE" | "BLOCK_ONLY_HIGH" | "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "OFF">;
103
+ }[] | undefined;
95
104
  }, import("../route/client.js").CompactionOperations | undefined>;
96
105
  configure: typeof configure;
97
106
  };
@@ -2,7 +2,6 @@ import { GoogleInteractions } from "../protocols/google-interactions.js";
2
2
  import { Auth } from "../route/auth.js";
3
3
  import { Route } from "../route/client.js";
4
4
  import { Endpoint } from "../route/endpoint.js";
5
- import { Framing } from "../route/framing.js";
6
5
  import { ProviderConfigurationError, ProviderID } from "../schema/index.js";
7
6
  import { GoogleVertexShared } from "./google-vertex-shared.js";
8
7
  export const id = ProviderID.make("google-vertex");
@@ -17,7 +16,7 @@ const route = Route.make({
17
16
  const serviceTier = request.providerOptions?.serviceTier;
18
17
  return typeof serviceTier === "string" ? { "x-vertex-ai-llm-shared-request-type": serviceTier } : {};
19
18
  },
20
- framing: Framing.sse,
19
+ transport: GoogleInteractions.transport,
21
20
  });
22
21
  export const routes = [route];
23
22
  const configuredRoute = (input) => {
@@ -102,7 +102,7 @@ export declare const routes: (import("../route.js").Route<{
102
102
  readonly continuationToken?: string | undefined;
103
103
  }, Gemini.Prepared, import("../route.js").CompactionOperations | undefined> | import("../route.js").Route<{
104
104
  readonly model: string;
105
- readonly input: readonly ({
105
+ readonly input?: readonly ({
106
106
  readonly type: "model_output" | "user_input";
107
107
  readonly content: readonly ({
108
108
  readonly type: "text";
@@ -132,12 +132,17 @@ export declare const routes: (import("../route.js").Route<{
132
132
  readonly name: string;
133
133
  readonly result: unknown;
134
134
  readonly is_error?: boolean | undefined;
135
- })[];
135
+ })[] | undefined;
136
136
  readonly stream: true;
137
137
  readonly store: boolean;
138
138
  readonly previous_interaction_id?: string | undefined;
139
+ readonly continuation_token?: string | undefined;
139
140
  readonly system_instruction?: string | undefined;
140
141
  readonly service_tier?: string | undefined;
142
+ readonly safety_settings?: readonly {
143
+ readonly type: string;
144
+ readonly threshold: string;
145
+ }[] | undefined;
141
146
  readonly tools?: readonly {
142
147
  readonly type: "function";
143
148
  readonly name: string;
@@ -161,7 +166,7 @@ export declare const routes: (import("../route.js").Route<{
161
166
  };
162
167
  } | undefined;
163
168
  };
164
- }, import("../route/transport/http.js").HttpPrepared<string>, import("../route.js").CompactionOperations | undefined>)[];
169
+ }, GoogleInteractions.Prepared, import("../route.js").CompactionOperations | undefined>)[];
165
170
  export type Config = RequestOptions & ProviderAuthOption<"optional"> & {
166
171
  readonly baseURL?: string;
167
172
  readonly providerOptions?: Gemini.ProviderOptionsInput & GoogleInteractions.ProviderOptionsInput;
@@ -180,6 +185,10 @@ export declare const configure: (input?: Config) => {
180
185
  readonly thinkingLevel?: import("../schema/options.js").OpenString<"high" | "low" | "medium" | "minimal"> | undefined;
181
186
  readonly thinkingSummaries?: import("../schema/options.js").OpenString<"auto" | "none"> | undefined;
182
187
  readonly serviceTier?: import("../schema/options.js").OpenString<"deferred" | "flex" | "priority" | "standard"> | undefined;
188
+ readonly safetySettings?: readonly {
189
+ readonly category: import("../schema/options.js").OpenString<"HARM_CATEGORY_CIVIC_INTEGRITY" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_UNSPECIFIED">;
190
+ readonly threshold: import("../schema/options.js").OpenString<"BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_NONE" | "BLOCK_ONLY_HIGH" | "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "OFF">;
191
+ }[] | undefined;
183
192
  }, import("../route.js").CompactionOperations | undefined>;
184
193
  image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/google-images.js").GoogleImageOptions>;
185
194
  video: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../video.js").VideoModel<import("../protocols/google-interactions-video.js").GoogleVideoOptions>;
@@ -199,6 +208,10 @@ export declare const provider: {
199
208
  readonly thinkingLevel?: import("../schema/options.js").OpenString<"high" | "low" | "medium" | "minimal"> | undefined;
200
209
  readonly thinkingSummaries?: import("../schema/options.js").OpenString<"auto" | "none"> | undefined;
201
210
  readonly serviceTier?: import("../schema/options.js").OpenString<"deferred" | "flex" | "priority" | "standard"> | undefined;
211
+ readonly safetySettings?: readonly {
212
+ readonly category: import("../schema/options.js").OpenString<"HARM_CATEGORY_CIVIC_INTEGRITY" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_UNSPECIFIED">;
213
+ readonly threshold: import("../schema/options.js").OpenString<"BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_NONE" | "BLOCK_ONLY_HIGH" | "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "OFF">;
214
+ }[] | undefined;
202
215
  }, import("../route.js").CompactionOperations | undefined>;
203
216
  image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/google-images.js").GoogleImageOptions>;
204
217
  video: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../video.js").VideoModel<import("../protocols/google-interactions-video.js").GoogleVideoOptions>;
@@ -223,6 +236,10 @@ export declare const interactions: (modelID: string | ModelID) => import("../sch
223
236
  readonly thinkingLevel?: import("../schema/options.js").OpenString<"high" | "low" | "medium" | "minimal"> | undefined;
224
237
  readonly thinkingSummaries?: import("../schema/options.js").OpenString<"auto" | "none"> | undefined;
225
238
  readonly serviceTier?: import("../schema/options.js").OpenString<"deferred" | "flex" | "priority" | "standard"> | undefined;
239
+ readonly safetySettings?: readonly {
240
+ readonly category: import("../schema/options.js").OpenString<"HARM_CATEGORY_CIVIC_INTEGRITY" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_UNSPECIFIED">;
241
+ readonly threshold: import("../schema/options.js").OpenString<"BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_NONE" | "BLOCK_ONLY_HIGH" | "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "OFF">;
242
+ }[] | undefined;
226
243
  }, import("../route.js").CompactionOperations | undefined>;
227
244
  export declare const speech: (modelID: string | ModelID) => import("../speech.js").SpeechModel<import("../protocols/google-speech.js").GoogleSpeechOptions>;
228
245
  export declare const transcription: (modelID: string | ModelID) => import("../transcription.js").TranscriptionModel<import("../protocols/google-transcription.js").GoogleTranscriptionOptions>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "0.0.0-dev-1320",
3
+ "version": "0.0.0-dev-1322",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -624,7 +624,7 @@
624
624
  "devDependencies": {
625
625
  "@clack/prompts": "1.0.0-alpha.1",
626
626
  "@effect/platform-node": "4.1.0",
627
- "@opencode/http-recorder": "0.0.0-dev-1320",
627
+ "@opencode/http-recorder": "0.0.0-dev-1322",
628
628
  "@tsconfig/bun": "1.0.9",
629
629
  "@types/bun": "1.4.3",
630
630
  "@typescript/native": "npm:typescript@7.1.0-beta",
@@ -634,7 +634,7 @@
634
634
  "@aws-sdk/credential-providers": "3.1057.0",
635
635
  "@smithy/eventstream-codec": "4.2.14",
636
636
  "@smithy/util-utf8": "4.2.2",
637
- "@opencode/schema": "0.0.0-dev-1320",
637
+ "@opencode/schema": "0.0.0-dev-1322",
638
638
  "aws4fetch": "1.0.20",
639
639
  "effect": "4.1.0",
640
640
  "google-auth-library": "10.5.0"