@opencode/ai 2.2.2 → 2.2.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 (52) hide show
  1. package/README.md +159 -144
  2. package/dist/decision.d.ts +0 -1
  3. package/dist/effect.d.ts +47 -17
  4. package/dist/effect.js +25 -13
  5. package/dist/experimental/testing.d.ts +3 -0
  6. package/dist/experimental/testing.js +3 -0
  7. package/dist/experimental.d.ts +12 -0
  8. package/dist/experimental.js +9 -0
  9. package/dist/index.d.ts +637 -1323
  10. package/dist/index.js +60 -56
  11. package/dist/llm.d.ts +4 -3
  12. package/dist/llm.js +21 -29
  13. package/dist/protocols/alibaba-responses.d.ts +2 -2
  14. package/dist/protocols/assemblyai-transcription.js +3 -3
  15. package/dist/protocols/meta-responses.d.ts +4 -4
  16. package/dist/protocols/open-responses.d.ts +18 -18
  17. package/dist/protocols/open-responses.js +4 -2
  18. package/dist/protocols/openai-compatible-responses.d.ts +2 -2
  19. package/dist/protocols/openai-responses.d.ts +12 -12
  20. package/dist/protocols/runway-video.js +2 -2
  21. package/dist/protocols/xai-responses.d.ts +2 -2
  22. package/dist/protocols/xai-responses.js +1 -1
  23. package/dist/protocols/xai-video.js +2 -2
  24. package/dist/providers/alibaba.d.ts +2 -2
  25. package/dist/providers/amazon-bedrock-mantle.d.ts +2 -2
  26. package/dist/providers/azure.d.ts +4 -4
  27. package/dist/providers/cloudflare-ai-gateway.d.ts +4 -4
  28. package/dist/providers/digitalocean.d.ts +2 -2
  29. package/dist/providers/google-vertex-responses.d.ts +2 -2
  30. package/dist/providers/meta.d.ts +2 -2
  31. package/dist/providers/minimax.d.ts +2 -2
  32. package/dist/providers/moonshot.d.ts +2 -2
  33. package/dist/providers/openai-compatible-responses.d.ts +2 -2
  34. package/dist/providers/openai.d.ts +2 -2
  35. package/dist/providers/openrouter/responses.d.ts +1 -2
  36. package/dist/providers/openrouter.d.ts +36 -23
  37. package/dist/providers/openrouter.js +29 -10
  38. package/dist/providers/venice.d.ts +2 -2
  39. package/dist/providers/zai-coding-plan.d.ts +2 -2
  40. package/dist/route/client.d.ts +3 -2
  41. package/dist/route/client.js +6 -9
  42. package/dist/route/media-protocol.d.ts +2 -3
  43. package/dist/route/media-protocol.js +2 -6
  44. package/dist/schema/errors.d.ts +6 -0
  45. package/dist/schema/errors.js +8 -0
  46. package/dist/schema/events.d.ts +2 -0
  47. package/dist/schema/events.js +4 -0
  48. package/dist/testing.d.ts +1 -4
  49. package/dist/testing.js +4 -12
  50. package/dist/tool.d.ts +40 -73
  51. package/dist/tool.js +27 -18
  52. package/package.json +7 -3
package/dist/index.js CHANGED
@@ -2,14 +2,14 @@ import { Effect, Layer, ManagedRuntime, Schema, Stream } from "effect";
2
2
  import { AIClient } from "./ai-client.js";
3
3
  import { Decision } from "./decision.js";
4
4
  import { Image } from "./image.js";
5
- import { LLM } from "./effect.js";
5
+ import { LLM } from "./llm.js";
6
6
  import { Media } from "./media.js";
7
- import { LLMClient, } from "./route/client.js";
7
+ import {} from "./route/client.js";
8
8
  import { RequestExecutor } from "./route/executor.js";
9
9
  import { AIError, InvalidRequestError, LanguageModel, } from "./schema/index.js";
10
10
  import { Speech } from "./speech.js";
11
11
  import { Transcription, } from "./transcription.js";
12
- import { Tool, ToolFailure } from "./tool.js";
12
+ import { ToolFailure, build } from "./tool.js";
13
13
  import { fileMediaType } from "./utils/media-type.js";
14
14
  import { Video } from "./video.js";
15
15
  // Fails with `signal.reason` so aborted calls reject and aborted streams throw like `fetch`: an `AbortError` by default.
@@ -28,23 +28,25 @@ export const make = (options = {}) => {
28
28
  const runtime = ManagedRuntime.make(Layer.merge(AIClient.layerWith(options.layer ?? RequestExecutor.fetchLayer),
29
29
  // `R` is only inferred from `clients`, so it is `never` whenever `clients` is omitted.
30
30
  (options.clients ?? Layer.empty)));
31
- /** Run any package Effect (for example `LLMClient.compact(...)`) inside this runtime. */
31
+ /** Run any package Effect (for example `ai.compact(...)` from `@opencode/ai/effect`) inside this runtime. */
32
32
  const run = (effect, options) => runtime.runPromise(Effect.raceFirst(effect, abortEffect(options?.signal)));
33
33
  const iterate = (stream, options) => Stream.toAsyncIterable(Stream.unwrap(runtime.contextEffect.pipe(Effect.map((context) => stream.pipe(Stream.interruptWhen(abortEffect(options?.signal)), Stream.provideContext(context))))));
34
34
  function generateObject(input, options) {
35
35
  return run("schema" in input ? LLM.generateObject(input) : LLM.generateObject(input), options);
36
36
  }
37
- // The overloads pair each request type with its mechanism; `LLMClient.compact` checks the route's capability at runtime.
37
+ // The overloads pair each request type with its mechanism; `LLM.compact` checks the route's capability at runtime.
38
38
  function compact(request, options) {
39
39
  return options?.mechanism === "trigger"
40
- ? run(LLMClient.compact(request, options), options)
41
- : run(LLMClient.compact(request, options), options);
40
+ ? run(LLM.compact(request, options), options)
41
+ : run(LLM.compact(request, options), options);
42
42
  }
43
43
  const handle = (generation) => ({
44
44
  ...generation.snapshot,
45
+ snapshot: generation.snapshot,
46
+ terminal: generation.terminal,
45
47
  token: generation.token,
46
- await: (options) => run(generation.await({ poll: options?.poll }), options),
47
- events: (options) => iterate(generation.events({ poll: options?.poll }), options),
48
+ await: (options) => run(generation.await(options), options),
49
+ events: (options) => iterate(generation.events(options), options),
48
50
  result: (options) => run(generation.result(), options),
49
51
  refresh: (options) => run(generation.refresh(), options).then(handle),
50
52
  cancel: (options) => run(generation.cancel(), options),
@@ -75,65 +77,67 @@ export const make = (options = {}) => {
75
77
  catch: (cause) => fileError(`Failed to write media file ${path}`, cause),
76
78
  }))), options);
77
79
  },
78
- llm: {
79
- request: LLM.request,
80
- generate: (input, options) => run(LLM.generate(input), options),
81
- stream: (input, options) => iterate(LLM.stream(input), options),
82
- /** Stream model calls, running their tool calls, until the model stops calling tools or `until` is true. */
83
- loop: (input, options) => iterate(LLM.loop(input), options),
84
- /** Decode the model's output against `schema` (or `jsonSchema`, unvalidated) like `LLM.generateObject`. */
85
- generateObject,
86
- /** Compact a Responses request like `LLMClient.compact`: a replacement window, or a checkpoint with `mechanism: "trigger"`. */
87
- compact,
88
- },
80
+ request: LLM.request,
81
+ generate: (input, options) => run(LLM.generate(input, options), options),
82
+ stream: (input, options) => iterate(LLM.stream(input, options), options),
83
+ /** Stream model calls, running their tool calls, until the model stops calling tools or `until` is true. */
84
+ loop: (input, options) => iterate(LLM.loop(input, options), options),
85
+ /** Decode the model's output against `schema` (or `jsonSchema`, unvalidated). */
86
+ generateObject,
87
+ /** Compact a Responses request: a replacement window, or a checkpoint with `mechanism: "trigger"`. */
88
+ compact,
89
+ canCompact: LLM.canCompact,
89
90
  image: {
90
91
  request: Image.request,
91
- generate: (input, options) => run(Image.generate(input, { poll: options?.poll }), options),
92
- stream: (input, options) => iterate(Image.stream(input, { poll: options?.poll }), options),
92
+ generate: (input, options) => run(Image.generate(input, options), options),
93
+ stream: (input, options) => iterate(Image.stream(input, options), options),
93
94
  start: (input, options) => run(Image.start(input), options).then(handle),
94
95
  resume: (model, token, options) => run(Image.resume(model, token), options).then(handle),
95
96
  },
96
- video: {
97
- request: Video.request,
98
- start: (input, options) => run(Video.start(input), options).then(handle),
99
- generate: (input, options) => run(Video.generate(input, { poll: options?.poll }), options),
100
- resume: (model, token, options) => run(Video.resume(model, token), options).then(handle),
101
- stream: (input, options) => iterate(Video.stream(input, { poll: options?.poll }), options),
102
- },
103
- speech: {
104
- request: Speech.request,
105
- generate: (input, options) => run(Speech.generate(input), options),
106
- stream: (input, options) => iterate(Speech.stream(input), options),
107
- },
108
- transcription: {
109
- request: Transcription.request,
110
- generate: (input, options) => run(Transcription.generate(input, { poll: options?.poll }), options),
111
- stream: (input, options) => iterate(Transcription.stream(input, { poll: options?.poll }), options),
112
- start: (input, options) => run(Transcription.start(input), options).then(handle),
113
- resume: (model, token, options) => run(Transcription.resume(model, token), options).then(handle),
114
- },
115
97
  decision: {
116
98
  request: Decision.request,
117
99
  generate: (input, options) => run(Decision.generate(input), options),
118
100
  },
101
+ /** Experimental: may change without compatibility guarantees. */
102
+ experimental: {
103
+ speech: {
104
+ request: Speech.request,
105
+ generate: (input, options) => run(Speech.generate(input), options),
106
+ stream: (input, options) => iterate(Speech.stream(input), options),
107
+ },
108
+ transcription: {
109
+ request: Transcription.request,
110
+ generate: (input, options) => run(Transcription.generate(input, { poll: options?.poll }), options),
111
+ stream: (input, options) => iterate(Transcription.stream(input, { poll: options?.poll }), options),
112
+ start: (input, options) => run(Transcription.start(input), options).then(handle),
113
+ resume: (model, token, options) => run(Transcription.resume(model, token), options).then(handle),
114
+ },
115
+ video: {
116
+ request: Video.request,
117
+ start: (input, options) => run(Video.start(input), options).then(handle),
118
+ generate: (input, options) => run(Video.generate(input, { poll: options?.poll }), options),
119
+ resume: (model, token, options) => run(Video.resume(model, token), options).then(handle),
120
+ stream: (input, options) => iterate(Video.stream(input, { poll: options?.poll }), options),
121
+ },
122
+ },
119
123
  dispose: () => runtime.dispose(),
120
124
  };
121
125
  };
122
126
  const fileError = (message, cause) => new AIError({ reason: new InvalidRequestError({ message, cause }) });
123
- /**
124
- * Promise counterpart of `Tool.make` for `ai.llm.loop`. A throw or rejection becomes the error result the model sees, the
125
- * returned value is sent unvalidated (`undefined` as `null`), and `signal` aborts when the loop is interrupted.
126
- */
127
- export const tool = (config) => Tool.make({
128
- description: config.description,
129
- parameters: config.parameters,
130
- success: Schema.Unknown,
131
- freeform: config.freeform,
132
- execute: (params, context) => Effect.tryPromise({
133
- try: async (signal) => (await config.execute(params, { ...context, signal })) ?? null,
134
- catch: (error) => new ToolFailure({ message: error instanceof Error ? error.message : String(error), error }),
135
- }),
136
- });
137
- /** Default client over `RequestExecutor.fetchLayer` for scripts; the runtime builds its layer on first use. */
127
+ /** `tool` from `@opencode/ai/effect`, with an `execute` that returns a value or a Promise and throws to fail. */
128
+ export const tool = (config) => {
129
+ const execute = config.execute;
130
+ return build(config, execute &&
131
+ ((params, context) => Effect.tryPromise({
132
+ try: async (signal) => execute(params, { ...context, signal }),
133
+ catch: (error) => new ToolFailure({ message: error instanceof Error ? error.message : String(error), error }),
134
+ })));
135
+ };
136
+ /** Default client over `RequestExecutor.fetchLayer`; the runtime builds its layer on first use and holds nothing to dispose. */
138
137
  export const ai = make();
139
138
  export * as AI from "./index.js";
139
+ export { isContextOverflow, isContextOverflowFailure, isRetryable } from "./provider-error.js";
140
+ export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding, HttpOptions, GenerationOptions, LanguageModelDefaults, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, Message, Freeform, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, LLMRequest, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, ToolError, FinishReasonDetails, StepFinish, Finish, MediaEvent, ProviderErrorEvent, LLMEvent, LLMResponse, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, NoRouteError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
141
+ export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageRequest, ImageResponse } from "./image.js";
142
+ export { ChoiceAnswer, ChoiceQuestion, ChoiceValue, DecisionAnswer, DecisionJsonPart, DecisionMediaPart, DecisionModel, DecisionModelCompatibility, DecisionModelSchema, DecisionPart, DecisionQuestion, DecisionRequest, DecisionResponse, DecisionTextPart, DecisionUsage, ErrorAnswer, ErrorReason, PredicateAnswer, PredicateQuestion, ScoreAnswer, ScoreQuestion, } from "./decision.js";
143
+ export { Media } from "./media.js";
package/dist/llm.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Effect, JsonSchema, Schema, Stream } from "effect";
2
2
  import { Service, type StreamOptions } from "./route/client.js";
3
3
  import { GenerationOptions, HttpOptions, AIError, LLMEvent, LLMRequest, LLMResponse, Message, LanguageModel, SystemPart, ToolChoice, type ContentPart, type LanguageModelProviderOptions, type ToolEntryInput } from "./schema/index.js";
4
- import { type ExecutableTools, type ToolSchema } from "./tool.js";
4
+ import { type ExecutableTool, type ToolSchema } from "./tool.js";
5
5
  /** Input accepted by `LLM.request`, normalized into the canonical `LLMRequest` class. */
6
6
  export type RequestInput<SelectedLanguageModel extends LanguageModel = LanguageModel> = Omit<ConstructorParameters<typeof LLMRequest>[0], "model" | "system" | "messages" | "tools" | "toolChoice" | "generation" | "http" | "providerOptions"> & {
7
7
  readonly model: SelectedLanguageModel;
@@ -17,7 +17,7 @@ export type RequestInput<SelectedLanguageModel extends LanguageModel = LanguageM
17
17
  export declare function generate<const Model extends LanguageModel>(input: RequestInput<Model> | LLMRequest, options?: StreamOptions): Effect.Effect<LLMResponse, AIError, Service>;
18
18
  export declare function stream<const Model extends LanguageModel>(input: RequestInput<Model> | LLMRequest, options?: StreamOptions): Stream.Stream<LLMEvent, AIError, Service>;
19
19
  export type LoopInput<SelectedLanguageModel extends LanguageModel = LanguageModel> = Omit<RequestInput<SelectedLanguageModel>, "tools"> & {
20
- readonly tools: ExecutableTools;
20
+ readonly tools: Record<string, ExecutableTool>;
21
21
  /** Called after each step that has tool calls; returning `true` ends the loop without running them. */
22
22
  readonly until?: (state: {
23
23
  readonly steps: ReadonlyArray<LLMResponse>;
@@ -276,4 +276,5 @@ export interface GenerateObjectDynamicOptions<SelectedLanguageModel extends Lang
276
276
  */
277
277
  export declare function generateObject<const SelectedLanguageModel extends LanguageModel, S extends ToolSchema<any>>(options: GenerateObjectOptions<S, SelectedLanguageModel>): Effect.Effect<GenerateObjectResponse<Schema.Schema.Type<S>>, AIError, Service>;
278
278
  export declare function generateObject<const SelectedLanguageModel extends LanguageModel>(options: GenerateObjectDynamicOptions<SelectedLanguageModel>): Effect.Effect<GenerateObjectResponse<unknown>, AIError, Service>;
279
- export {};
279
+ export { canCompact, compact } from "./route/client.js";
280
+ export * as LLM from "./llm.js";
package/dist/llm.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Effect, JsonSchema, Schema, Stream } from "effect";
2
2
  import { tryRequest } from "./media-model.js";
3
3
  import { LLMClient, Service } from "./route/client.js";
4
- import { GenerationOptions, HttpOptions, InvalidProviderOutputError, AIError, LLMEvent, LLMRequest, LLMResponse, Message, LanguageModel, SystemPart, ToolChoice, ToolEntry, } from "./schema/index.js";
5
- import { make as makeTool, toDefinitions } from "./tool.js";
4
+ import { GenerationOptions, HttpOptions, InvalidProviderOutputError, AIError, LLMEvent, LLMRequest, LLMResponse, Message, LanguageModel, SystemPart, ToolChoice, ToolEntry, withPartial, } from "./schema/index.js";
5
+ import { tool, toDefinitions } from "./tool.js";
6
6
  import { ToolRuntime } from "./tool-runtime.js";
7
7
  export function generate(input, options) {
8
8
  return requestEffect(input).pipe(Effect.flatMap((request) => LLMClient.generate(request, options)));
@@ -13,11 +13,11 @@ export function stream(input, options) {
13
13
  export function loop(input, options) {
14
14
  const { tools, until, ...rest } = input;
15
15
  const step = (request, steps) => Stream.suspend(() => {
16
- const events = [];
17
- return LLMClient.stream(request, options).pipe(Stream.map((event) => event.type === "step-start" || event.type === "step-finish" ? { ...event, index: steps.length } : event), Stream.tap((event) => Effect.sync(() => events.push(event))), Stream.concat(Stream.unwrap(Effect.gen(function* () {
18
- const response = LLMResponse.fromEvents(events);
16
+ let state = LLMResponse.empty();
17
+ return LLMClient.stream(request, options).pipe(Stream.map((event) => event.type === "step-start" || event.type === "step-finish" ? { ...event, index: steps.length } : event), Stream.tap((event) => Effect.sync(() => (state = LLMResponse.reduce(state, event)))), Stream.mapError((error) => withPartial(error, LLMResponse.partial(state))), Stream.concat(Stream.unwrap(Effect.gen(function* () {
18
+ const response = LLMResponse.complete(state);
19
19
  const calls = response?.toolCalls.filter((call) => call.providerExecuted !== true) ?? [];
20
- if (!response || calls.length === 0 || events.some(LLMEvent.is.providerError))
20
+ if (!response || calls.length === 0 || state.events.some(LLMEvent.is.providerError))
21
21
  return Stream.empty;
22
22
  const done = [...steps, response];
23
23
  if (until?.({ steps: done }))
@@ -81,34 +81,26 @@ const runGenerateObject = Effect.fn("LLM.generateObject")(function* (options, to
81
81
  });
82
82
  const response = yield* LLMClient.generate(generateRequest);
83
83
  const call = response.toolCalls.find((event) => event.name === GENERATE_OBJECT_TOOL_NAME);
84
- if (!call)
85
- return yield* new AIError({
86
- reason: new InvalidProviderOutputError({
87
- message: `generateObject: model did not call the forced \`${GENERATE_OBJECT_TOOL_NAME}\` tool`,
88
- }),
89
- });
90
- const object = yield* tool._decode(call.input).pipe(Effect.mapError((error) => new AIError({
91
- reason: new InvalidProviderOutputError({
92
- message: `generateObject: tool input failed schema decode: ${error.message}`,
93
- cause: error,
94
- }),
95
- })));
84
+ const invalidOutput = (reason) => new AIError({ reason, partial: response });
85
+ if (!call) {
86
+ const message = response.finishReason.normalized === "length"
87
+ ? "generateObject: output hit the token limit before the forced tool call completed"
88
+ : `generateObject: model did not call the forced \`${GENERATE_OBJECT_TOOL_NAME}\` tool`;
89
+ return yield* invalidOutput(new InvalidProviderOutputError({ message }));
90
+ }
91
+ const object = yield* tool._decode(call.input).pipe(Effect.mapError((error) => invalidOutput(new InvalidProviderOutputError({
92
+ message: `generateObject: tool input failed schema decode: ${error.message}`,
93
+ cause: error,
94
+ }))));
96
95
  return new GenerateObjectResponse(object, response);
97
96
  });
98
97
  export function generateObject(options) {
99
98
  if ("schema" in options) {
100
99
  const { schema, ...rest } = options;
101
- return runGenerateObject(rest, makeTool({
102
- description: GENERATE_OBJECT_TOOL_DESCRIPTION,
103
- parameters: schema,
104
- success: Schema.Unknown,
105
- execute: () => Effect.void,
106
- }));
100
+ return runGenerateObject(rest, tool({ description: GENERATE_OBJECT_TOOL_DESCRIPTION, parameters: schema }));
107
101
  }
108
102
  const { jsonSchema, ...rest } = options;
109
- return runGenerateObject(rest, makeTool({
110
- description: GENERATE_OBJECT_TOOL_DESCRIPTION,
111
- jsonSchema,
112
- execute: () => Effect.void,
113
- }));
103
+ return runGenerateObject(rest, tool({ description: GENERATE_OBJECT_TOOL_DESCRIPTION, jsonSchema }));
114
104
  }
105
+ export { canCompact, compact } from "./route/client.js";
106
+ export * as LLM from "./llm.js";
@@ -40,7 +40,7 @@ export declare const protocol: Protocol<{
40
40
  readonly detail?: string | undefined;
41
41
  } | {
42
42
  readonly type: "input_file";
43
- readonly filename: string;
43
+ readonly filename?: string | undefined;
44
44
  readonly detail?: string | undefined;
45
45
  readonly file_data?: string | undefined;
46
46
  readonly file_url?: string | undefined;
@@ -72,7 +72,7 @@ export declare const protocol: Protocol<{
72
72
  readonly detail?: string | undefined;
73
73
  } | {
74
74
  readonly type: "input_file";
75
- readonly filename: string;
75
+ readonly filename?: string | undefined;
76
76
  readonly detail?: string | undefined;
77
77
  readonly file_data?: string | undefined;
78
78
  readonly file_url?: string | undefined;
@@ -77,19 +77,19 @@ const fromRequest = Effect.fn("AssemblyAITranscription.fromRequest")(function* (
77
77
  const decodeTranscript = route.decodeJson(Transcript);
78
78
  const decodeStart = Effect.fn("AssemblyAITranscription.decodeStart")(function* (response) {
79
79
  const output = yield* decodeTranscript(response);
80
- const status = yield* MediaProtocol.status(STATUS, output.value.status, output);
80
+ const status = MediaProtocol.status(STATUS, output.value.status);
81
81
  return { token: { transcriptID: output.value.id }, snapshot: { id: output.value.id, status } };
82
82
  });
83
83
  const decodeStatus = Effect.fn("AssemblyAITranscription.decodeStatus")(function* (response, context) {
84
84
  const output = yield* decodeTranscript(response);
85
- const status = yield* MediaProtocol.status(STATUS, output.value.status, output);
85
+ const status = MediaProtocol.status(STATUS, output.value.status);
86
86
  return { id: context.token.transcriptID, status };
87
87
  });
88
88
  const seconds = (milliseconds) => milliseconds / 1000;
89
89
  const decodeResult = Effect.fn("AssemblyAITranscription.decodeResult")(function* (response, context) {
90
90
  const output = yield* decodeTranscript(response);
91
91
  const transcript = output.value;
92
- const status = yield* MediaProtocol.status(STATUS, transcript.status, output);
92
+ const status = MediaProtocol.status(STATUS, transcript.status);
93
93
  const error = transcript.error ?? undefined;
94
94
  if (status === "failed")
95
95
  return yield* output.ended("failed", `${route.name} transcription failed${error === undefined ? "" : `: ${error}`}`);
@@ -54,7 +54,7 @@ export declare const protocol: Protocol<{
54
54
  readonly detail?: string | undefined;
55
55
  } | {
56
56
  readonly type: "input_file";
57
- readonly filename: string;
57
+ readonly filename?: string | undefined;
58
58
  readonly detail?: string | undefined;
59
59
  readonly file_data?: string | undefined;
60
60
  readonly file_url?: string | undefined;
@@ -86,7 +86,7 @@ export declare const protocol: Protocol<{
86
86
  readonly detail?: string | undefined;
87
87
  } | {
88
88
  readonly type: "input_file";
89
- readonly filename: string;
89
+ readonly filename?: string | undefined;
90
90
  readonly detail?: string | undefined;
91
91
  readonly file_data?: string | undefined;
92
92
  readonly file_url?: string | undefined;
@@ -310,7 +310,7 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
310
310
  readonly detail?: string | undefined;
311
311
  } | {
312
312
  readonly type: "input_file";
313
- readonly filename: string;
313
+ readonly filename?: string | undefined;
314
314
  readonly detail?: string | undefined;
315
315
  readonly file_data?: string | undefined;
316
316
  readonly file_url?: string | undefined;
@@ -342,7 +342,7 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
342
342
  readonly detail?: string | undefined;
343
343
  } | {
344
344
  readonly type: "input_file";
345
- readonly filename: string;
345
+ readonly filename?: string | undefined;
346
346
  readonly detail?: string | undefined;
347
347
  readonly file_data?: string | undefined;
348
348
  readonly file_url?: string | undefined;
@@ -19,7 +19,7 @@ export declare const OpenResponsesInputImage: Schema.Struct<{
19
19
  }>;
20
20
  export declare const OpenResponsesInputFile: Schema.Struct<{
21
21
  readonly type: Schema.tag<"input_file">;
22
- readonly filename: Schema.String;
22
+ readonly filename: Schema.optional<Schema.String>;
23
23
  readonly detail: Schema.optional<Schema.String>;
24
24
  readonly file_data: Schema.optional<Schema.String>;
25
25
  readonly file_url: Schema.optional<Schema.String>;
@@ -30,7 +30,7 @@ declare const MediaInput: Schema.Union<readonly [Schema.Struct<{
30
30
  readonly detail: Schema.optional<Schema.String>;
31
31
  }>, Schema.Struct<{
32
32
  readonly type: Schema.tag<"input_file">;
33
- readonly filename: Schema.String;
33
+ readonly filename: Schema.optional<Schema.String>;
34
34
  readonly detail: Schema.optional<Schema.String>;
35
35
  readonly file_data: Schema.optional<Schema.String>;
36
36
  readonly file_url: Schema.optional<Schema.String>;
@@ -134,7 +134,7 @@ export declare const InputItem: Schema.Union<readonly [Schema.Struct<{
134
134
  readonly detail: Schema.optional<Schema.String>;
135
135
  }>, Schema.Struct<{
136
136
  readonly type: Schema.tag<"input_file">;
137
- readonly filename: Schema.String;
137
+ readonly filename: Schema.optional<Schema.String>;
138
138
  readonly detail: Schema.optional<Schema.String>;
139
139
  readonly file_data: Schema.optional<Schema.String>;
140
140
  readonly file_url: Schema.optional<Schema.String>;
@@ -181,7 +181,7 @@ export declare const InputItem: Schema.Union<readonly [Schema.Struct<{
181
181
  readonly detail: Schema.optional<Schema.String>;
182
182
  }>, Schema.Struct<{
183
183
  readonly type: Schema.tag<"input_file">;
184
- readonly filename: Schema.String;
184
+ readonly filename: Schema.optional<Schema.String>;
185
185
  readonly detail: Schema.optional<Schema.String>;
186
186
  readonly file_data: Schema.optional<Schema.String>;
187
187
  readonly file_url: Schema.optional<Schema.String>;
@@ -291,7 +291,7 @@ export declare const coreFields: {
291
291
  readonly detail: Schema.optional<Schema.String>;
292
292
  }>, Schema.Struct<{
293
293
  readonly type: Schema.tag<"input_file">;
294
- readonly filename: Schema.String;
294
+ readonly filename: Schema.optional<Schema.String>;
295
295
  readonly detail: Schema.optional<Schema.String>;
296
296
  readonly file_data: Schema.optional<Schema.String>;
297
297
  readonly file_url: Schema.optional<Schema.String>;
@@ -338,7 +338,7 @@ export declare const coreFields: {
338
338
  readonly detail: Schema.optional<Schema.String>;
339
339
  }>, Schema.Struct<{
340
340
  readonly type: Schema.tag<"input_file">;
341
- readonly filename: Schema.String;
341
+ readonly filename: Schema.optional<Schema.String>;
342
342
  readonly detail: Schema.optional<Schema.String>;
343
343
  readonly file_data: Schema.optional<Schema.String>;
344
344
  readonly file_url: Schema.optional<Schema.String>;
@@ -472,7 +472,7 @@ export declare const OpenResponsesBody: Schema.Struct<{
472
472
  readonly detail: Schema.optional<Schema.String>;
473
473
  }>, Schema.Struct<{
474
474
  readonly type: Schema.tag<"input_file">;
475
- readonly filename: Schema.String;
475
+ readonly filename: Schema.optional<Schema.String>;
476
476
  readonly detail: Schema.optional<Schema.String>;
477
477
  readonly file_data: Schema.optional<Schema.String>;
478
478
  readonly file_url: Schema.optional<Schema.String>;
@@ -519,7 +519,7 @@ export declare const OpenResponsesBody: Schema.Struct<{
519
519
  readonly detail: Schema.optional<Schema.String>;
520
520
  }>, Schema.Struct<{
521
521
  readonly type: Schema.tag<"input_file">;
522
- readonly filename: Schema.String;
522
+ readonly filename: Schema.optional<Schema.String>;
523
523
  readonly detail: Schema.optional<Schema.String>;
524
524
  readonly file_data: Schema.optional<Schema.String>;
525
525
  readonly file_url: Schema.optional<Schema.String>;
@@ -1023,7 +1023,7 @@ export declare const lowerConversation: (request: LLMRequest<import("../schema/o
1023
1023
  readonly detail?: string | undefined;
1024
1024
  } | {
1025
1025
  readonly type: "input_file";
1026
- readonly filename: string;
1026
+ readonly filename?: string | undefined;
1027
1027
  readonly detail?: string | undefined;
1028
1028
  readonly file_data?: string | undefined;
1029
1029
  readonly file_url?: string | undefined;
@@ -1055,7 +1055,7 @@ export declare const lowerConversation: (request: LLMRequest<import("../schema/o
1055
1055
  readonly detail?: string | undefined;
1056
1056
  } | {
1057
1057
  readonly type: "input_file";
1058
- readonly filename: string;
1058
+ readonly filename?: string | undefined;
1059
1059
  readonly detail?: string | undefined;
1060
1060
  readonly file_data?: string | undefined;
1061
1061
  readonly file_url?: string | undefined;
@@ -1200,7 +1200,7 @@ export declare const fromRequestWithAdapter: (request: LLMRequest<import("../sch
1200
1200
  readonly detail?: string | undefined;
1201
1201
  } | {
1202
1202
  readonly type: "input_file";
1203
- readonly filename: string;
1203
+ readonly filename?: string | undefined;
1204
1204
  readonly detail?: string | undefined;
1205
1205
  readonly file_data?: string | undefined;
1206
1206
  readonly file_url?: string | undefined;
@@ -1232,7 +1232,7 @@ export declare const fromRequestWithAdapter: (request: LLMRequest<import("../sch
1232
1232
  readonly detail?: string | undefined;
1233
1233
  } | {
1234
1234
  readonly type: "input_file";
1235
- readonly filename: string;
1235
+ readonly filename?: string | undefined;
1236
1236
  readonly detail?: string | undefined;
1237
1237
  readonly file_data?: string | undefined;
1238
1238
  readonly file_url?: string | undefined;
@@ -1398,7 +1398,7 @@ export declare const fromRequest: (request: LLMRequest) => Effect.Effect<{
1398
1398
  readonly detail?: string | undefined;
1399
1399
  } | {
1400
1400
  readonly type: "input_file";
1401
- readonly filename: string;
1401
+ readonly filename?: string | undefined;
1402
1402
  readonly detail?: string | undefined;
1403
1403
  readonly file_data?: string | undefined;
1404
1404
  readonly file_url?: string | undefined;
@@ -1430,7 +1430,7 @@ export declare const fromRequest: (request: LLMRequest) => Effect.Effect<{
1430
1430
  readonly detail?: string | undefined;
1431
1431
  } | {
1432
1432
  readonly type: "input_file";
1433
- readonly filename: string;
1433
+ readonly filename?: string | undefined;
1434
1434
  readonly detail?: string | undefined;
1435
1435
  readonly file_data?: string | undefined;
1436
1436
  readonly file_url?: string | undefined;
@@ -1834,7 +1834,7 @@ export declare const protocol: Protocol<{
1834
1834
  readonly detail?: string | undefined;
1835
1835
  } | {
1836
1836
  readonly type: "input_file";
1837
- readonly filename: string;
1837
+ readonly filename?: string | undefined;
1838
1838
  readonly detail?: string | undefined;
1839
1839
  readonly file_data?: string | undefined;
1840
1840
  readonly file_url?: string | undefined;
@@ -1866,7 +1866,7 @@ export declare const protocol: Protocol<{
1866
1866
  readonly detail?: string | undefined;
1867
1867
  } | {
1868
1868
  readonly type: "input_file";
1869
- readonly filename: string;
1869
+ readonly filename?: string | undefined;
1870
1870
  readonly detail?: string | undefined;
1871
1871
  readonly file_data?: string | undefined;
1872
1872
  readonly file_url?: string | undefined;
@@ -2090,7 +2090,7 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
2090
2090
  readonly detail?: string | undefined;
2091
2091
  } | {
2092
2092
  readonly type: "input_file";
2093
- readonly filename: string;
2093
+ readonly filename?: string | undefined;
2094
2094
  readonly detail?: string | undefined;
2095
2095
  readonly file_data?: string | undefined;
2096
2096
  readonly file_url?: string | undefined;
@@ -2122,7 +2122,7 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
2122
2122
  readonly detail?: string | undefined;
2123
2123
  } | {
2124
2124
  readonly type: "input_file";
2125
- readonly filename: string;
2125
+ readonly filename?: string | undefined;
2126
2126
  readonly detail?: string | undefined;
2127
2127
  readonly file_data?: string | undefined;
2128
2128
  readonly file_url?: string | undefined;
@@ -26,7 +26,7 @@ export const OpenResponsesInputImage = Schema.Struct({
26
26
  });
27
27
  export const OpenResponsesInputFile = Schema.Struct({
28
28
  type: Schema.tag("input_file"),
29
- filename: Schema.String,
29
+ filename: Schema.optional(Schema.String),
30
30
  detail: Schema.optional(Schema.String),
31
31
  file_data: Schema.optional(Schema.String),
32
32
  file_url: Schema.optional(Schema.String),
@@ -405,11 +405,13 @@ const lowerMedia = Effect.fnUntraced(function* (part, request, adapter) {
405
405
  if (part.media.kind !== "image") {
406
406
  if (part.media.kind === "video")
407
407
  return { type: "input_video", video_url: location };
408
+ if (url)
409
+ return { type: "input_file", file_url: url, detail };
408
410
  return {
409
411
  type: "input_file",
410
412
  filename: part.filename ?? (mime === "application/pdf" ? "document.pdf" : "file"),
411
413
  detail,
412
- ...(url ? { file_url: url } : { file_data: location }),
414
+ file_data: location,
413
415
  };
414
416
  }
415
417
  return {
@@ -34,7 +34,7 @@ export declare const route: Route<{
34
34
  readonly detail?: string | undefined;
35
35
  } | {
36
36
  readonly type: "input_file";
37
- readonly filename: string;
37
+ readonly filename?: string | undefined;
38
38
  readonly detail?: string | undefined;
39
39
  readonly file_data?: string | undefined;
40
40
  readonly file_url?: string | undefined;
@@ -66,7 +66,7 @@ export declare const route: Route<{
66
66
  readonly detail?: string | undefined;
67
67
  } | {
68
68
  readonly type: "input_file";
69
- readonly filename: string;
69
+ readonly filename?: string | undefined;
70
70
  readonly detail?: string | undefined;
71
71
  readonly file_data?: string | undefined;
72
72
  readonly file_url?: string | undefined;