@opencode/ai 0.0.0-dev-70 → 0.0.0-dev-80

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 (57) hide show
  1. package/README.md +14 -10
  2. package/dist/decision.d.ts +22 -6
  3. package/dist/decision.js +15 -4
  4. package/dist/effect.d.ts +1 -1
  5. package/dist/effect.js +1 -1
  6. package/dist/image-client.d.ts +0 -9
  7. package/dist/image-client.js +0 -1
  8. package/dist/image.d.ts +0 -135
  9. package/dist/image.js +0 -3
  10. package/dist/index.d.ts +0 -72
  11. package/dist/media.d.ts +0 -7
  12. package/dist/media.js +0 -6
  13. package/dist/protocols/cartesia-speech.d.ts +0 -18
  14. package/dist/protocols/deepgram-speech.d.ts +0 -18
  15. package/dist/protocols/elevenlabs-speech.d.ts +0 -18
  16. package/dist/protocols/fal-images.js +1 -9
  17. package/dist/protocols/google-images.js +6 -33
  18. package/dist/protocols/google-speech.d.ts +0 -18
  19. package/dist/protocols/google-speech.js +0 -1
  20. package/dist/protocols/google-transcription.d.ts +0 -18
  21. package/dist/protocols/google-transcription.js +0 -1
  22. package/dist/protocols/google-video.js +1 -6
  23. package/dist/protocols/meta-images.d.ts +1 -1
  24. package/dist/protocols/meta-images.js +3 -12
  25. package/dist/protocols/openai-decisions.js +25 -5
  26. package/dist/protocols/openai-images.d.ts +0 -18
  27. package/dist/protocols/openai-images.js +3 -7
  28. package/dist/protocols/openai-speech.d.ts +0 -18
  29. package/dist/protocols/openai-speech.js +3 -4
  30. package/dist/protocols/openai-transcription.d.ts +0 -18
  31. package/dist/protocols/openai-transcription.js +3 -4
  32. package/dist/protocols/stability-images.js +0 -3
  33. package/dist/protocols/system-one.d.ts +2 -0
  34. package/dist/protocols/system-one.js +6 -4
  35. package/dist/protocols/utils/gemini-generate-content.d.ts +0 -2
  36. package/dist/protocols/utils/gemini-generate-content.js +3 -14
  37. package/dist/protocols/utils/image-sizing.d.ts +1 -4
  38. package/dist/protocols/utils/image-sizing.js +2 -8
  39. package/dist/protocols/utils/speech-stream.d.ts +0 -1
  40. package/dist/protocols/utils/speech-stream.js +0 -1
  41. package/dist/protocols/xai-images.js +1 -6
  42. package/dist/protocols/xai-video.js +10 -7
  43. package/dist/protocols/zai-images.js +0 -9
  44. package/dist/schema/events.d.ts +7 -0
  45. package/dist/schema/events.js +4 -0
  46. package/dist/speech-client.d.ts +0 -9
  47. package/dist/speech-client.js +0 -1
  48. package/dist/speech.d.ts +0 -135
  49. package/dist/speech.js +0 -3
  50. package/dist/transcription-client.d.ts +0 -9
  51. package/dist/transcription.d.ts +0 -135
  52. package/dist/transcription.js +0 -1
  53. package/dist/video-client.d.ts +0 -9
  54. package/dist/video-client.js +0 -1
  55. package/dist/video.d.ts +0 -135
  56. package/dist/video.js +0 -3
  57. package/package.json +3 -3
package/dist/media.js CHANGED
@@ -63,12 +63,6 @@ export const Info = Schema.Struct({
63
63
  encoding: Schema.optional(Schema.String),
64
64
  format: Schema.optional(Schema.String),
65
65
  }).annotate({ identifier: "Media.Info" });
66
- /** A provider-side partial result such as stripped audio or a moderated sample; never a silent drop. */
67
- export const Notice = Schema.Struct({
68
- type: Schema.Literals(["moderated", "filtered", "other"]),
69
- message: Schema.String,
70
- providerMetadata: Schema.optional(ProviderMetadata),
71
- }).annotate({ identifier: "Media.Notice" });
72
66
  // ---------------------------------------------------------------------------
73
67
  // Asset
74
68
  // ---------------------------------------------------------------------------
@@ -64,15 +64,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
64
64
  readonly [x: string]: unknown;
65
65
  } | undefined;
66
66
  } | undefined;
67
- readonly notices?: readonly {
68
- readonly type: "filtered" | "moderated" | "other";
69
- readonly message: string;
70
- readonly providerMetadata?: {
71
- readonly [x: string]: {
72
- readonly [x: string]: unknown;
73
- };
74
- } | undefined;
75
- }[] | undefined;
76
67
  readonly providerMetadata?: {
77
68
  readonly [x: string]: {
78
69
  readonly [x: string]: unknown;
@@ -123,15 +114,6 @@ export declare const CartesiaSpeech: {
123
114
  readonly [x: string]: unknown;
124
115
  } | undefined;
125
116
  } | undefined;
126
- readonly notices?: readonly {
127
- readonly type: "filtered" | "moderated" | "other";
128
- readonly message: string;
129
- readonly providerMetadata?: {
130
- readonly [x: string]: {
131
- readonly [x: string]: unknown;
132
- };
133
- } | undefined;
134
- }[] | undefined;
135
117
  readonly providerMetadata?: {
136
118
  readonly [x: string]: {
137
119
  readonly [x: string]: unknown;
@@ -57,15 +57,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
57
57
  readonly [x: string]: unknown;
58
58
  } | undefined;
59
59
  } | undefined;
60
- readonly notices?: readonly {
61
- readonly type: "filtered" | "moderated" | "other";
62
- readonly message: string;
63
- readonly providerMetadata?: {
64
- readonly [x: string]: {
65
- readonly [x: string]: unknown;
66
- };
67
- } | undefined;
68
- }[] | undefined;
69
60
  readonly providerMetadata?: {
70
61
  readonly [x: string]: {
71
62
  readonly [x: string]: unknown;
@@ -116,15 +107,6 @@ export declare const DeepgramSpeech: {
116
107
  readonly [x: string]: unknown;
117
108
  } | undefined;
118
109
  } | undefined;
119
- readonly notices?: readonly {
120
- readonly type: "filtered" | "moderated" | "other";
121
- readonly message: string;
122
- readonly providerMetadata?: {
123
- readonly [x: string]: {
124
- readonly [x: string]: unknown;
125
- };
126
- } | undefined;
127
- }[] | undefined;
128
110
  readonly providerMetadata?: {
129
111
  readonly [x: string]: {
130
112
  readonly [x: string]: unknown;
@@ -60,15 +60,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
60
60
  readonly [x: string]: unknown;
61
61
  } | undefined;
62
62
  } | undefined;
63
- readonly notices?: readonly {
64
- readonly type: "filtered" | "moderated" | "other";
65
- readonly message: string;
66
- readonly providerMetadata?: {
67
- readonly [x: string]: {
68
- readonly [x: string]: unknown;
69
- };
70
- } | undefined;
71
- }[] | undefined;
72
63
  readonly providerMetadata?: {
73
64
  readonly [x: string]: {
74
65
  readonly [x: string]: unknown;
@@ -119,15 +110,6 @@ export declare const ElevenLabsSpeech: {
119
110
  readonly [x: string]: unknown;
120
111
  } | undefined;
121
112
  } | undefined;
122
- readonly notices?: readonly {
123
- readonly type: "filtered" | "moderated" | "other";
124
- readonly message: string;
125
- readonly providerMetadata?: {
126
- readonly [x: string]: {
127
- readonly [x: string]: unknown;
128
- };
129
- } | undefined;
130
- }[] | undefined;
131
113
  readonly providerMetadata?: {
132
114
  readonly [x: string]: {
133
115
  readonly [x: string]: unknown;
@@ -68,11 +68,9 @@ const fromRequest = Effect.fn("FalImages.fromRequest")(function* (request) {
68
68
  const decodeQueueResult = route.decodeJson(QueueResult);
69
69
  const decodeResult = Effect.fn("FalImages.decodeResult")(function* (response, context) {
70
70
  const output = yield* decodeQueueResult(response);
71
- const { images, seed, has_nsfw_concepts, ...rest } = output.value;
71
+ const { images, seed, ...rest } = output.value;
72
72
  if (images.length === 0)
73
73
  return yield* output.invalid(`${route.name} returned no images`);
74
- // With the safety checker on, flagged images come back blacked out rather than omitted.
75
- const flagged = (has_nsfw_concepts ?? []).flatMap((value, index) => (value ? [index] : []));
76
74
  return new ImageResponse({
77
75
  images: images.map((image) => {
78
76
  const info = { width: image.width ?? undefined, height: image.height ?? undefined };
@@ -80,12 +78,6 @@ const decodeResult = Effect.fn("FalImages.decodeResult")(function* (response, co
80
78
  return (Media.parseDataUrl(image.url, { info }) ??
81
79
  Media.url(image.url, { mediaType: image.content_type ?? undefined, info }));
82
80
  }),
83
- notices: flagged.length === 0
84
- ? undefined
85
- : flagged.map((index) => ({
86
- type: "moderated",
87
- message: `${route.name} flagged image ${index} as NSFW`,
88
- })),
89
81
  providerMetadata: { fal: { requestId: context.token.requestID, seed: seed ?? undefined, ...rest } },
90
82
  });
91
83
  });
@@ -2,7 +2,7 @@ import { Effect, Schema } from "effect";
2
2
  import { ImageModel, ImageResponse } from "../image.js";
3
3
  import { MediaProtocol } from "../route/media-protocol.js";
4
4
  import { MediaRoute } from "../route/media.js";
5
- import { mergeJsonRecords } from "../schema/index.js";
5
+ import { mergeJsonRecords, tokenUsage } from "../schema/index.js";
6
6
  import { ProviderShared } from "./shared.js";
7
7
  import { GeminiGenerateContent } from "./utils/gemini-generate-content.js";
8
8
  import { MediaInput } from "./utils/media-input.js";
@@ -118,45 +118,18 @@ const decodeResponse = Effect.fn("GoogleImages.decodeResponse")(function* (respo
118
118
  }));
119
119
  if (images.length === 0) {
120
120
  const finishReasons = candidates.flatMap((candidate) => candidate.finishReason === undefined ? [] : [candidate.finishReason]);
121
+ // Safety and recitation stops are Google refusing the prompt, not a malformed response.
122
+ if (finishReasons.some(GeminiGenerateContent.contentFiltered))
123
+ return yield* output.contentPolicy(`${route.name} withheld its images (finish reasons: ${finishReasons.join(", ")})`);
121
124
  return yield* output.invalid(`${route.name} returned no final images${finishReasons.length === 0 ? "" : ` (finish reasons: ${finishReasons.join(", ")})`}; inspect body for prompt feedback and candidate details`);
122
125
  }
123
- // Candidates that stopped for a safety or policy reason are partial results, not a silent drop.
124
- const notices = [
125
- ...(decoded.promptFeedback === undefined
126
- ? []
127
- : [
128
- {
129
- type: "filtered",
130
- message: `${route.name} reported prompt feedback`,
131
- providerMetadata: { google: { promptFeedback: decoded.promptFeedback } },
132
- },
133
- ]),
134
- ...candidates.flatMap((candidate, index) => candidate.finishReason === undefined || candidate.finishReason === "STOP"
135
- ? []
136
- : [
137
- {
138
- type: "filtered",
139
- message: `${route.name} candidate ${candidate.index ?? index} finished with ${candidate.finishReason}${candidate.finishMessage === undefined ? "" : `: ${candidate.finishMessage}`}`,
140
- providerMetadata: {
141
- google: {
142
- candidateIndex: candidate.index ?? index,
143
- finishReason: candidate.finishReason,
144
- finishMessage: candidate.finishMessage,
145
- safetyRatings: candidate.safetyRatings,
146
- },
147
- },
148
- },
149
- ]),
150
- ];
151
126
  const usage = decoded.usageMetadata;
152
127
  const outputTokens = usage?.candidatesTokenCount === undefined ? undefined : usage.candidatesTokenCount + (usage.thoughtsTokenCount ?? 0);
153
128
  return new ImageResponse({
154
129
  images,
155
- notices: notices.length === 0 ? undefined : notices,
156
130
  usage: usage === undefined
157
131
  ? undefined
158
- : {
159
- type: "tokens",
132
+ : tokenUsage({
160
133
  input: usage.promptTokenCount,
161
134
  output: outputTokens,
162
135
  total: ProviderShared.totalTokens(usage.promptTokenCount, outputTokens, usage.totalTokenCount),
@@ -165,7 +138,7 @@ const decodeResponse = Effect.fn("GoogleImages.decodeResponse")(function* (respo
165
138
  cacheReadInputTokens: usage.cachedContentTokenCount,
166
139
  google: usage,
167
140
  },
168
- },
141
+ }),
169
142
  providerMetadata: {
170
143
  google: {
171
144
  modelVersion: decoded.modelVersion,
@@ -67,15 +67,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
67
67
  readonly [x: string]: unknown;
68
68
  } | undefined;
69
69
  } | undefined;
70
- readonly notices?: readonly {
71
- readonly type: "filtered" | "moderated" | "other";
72
- readonly message: string;
73
- readonly providerMetadata?: {
74
- readonly [x: string]: {
75
- readonly [x: string]: unknown;
76
- };
77
- } | undefined;
78
- }[] | undefined;
79
70
  readonly providerMetadata?: {
80
71
  readonly [x: string]: {
81
72
  readonly [x: string]: unknown;
@@ -126,15 +117,6 @@ export declare const GoogleSpeech: {
126
117
  readonly [x: string]: unknown;
127
118
  } | undefined;
128
119
  } | undefined;
129
- readonly notices?: readonly {
130
- readonly type: "filtered" | "moderated" | "other";
131
- readonly message: string;
132
- readonly providerMetadata?: {
133
- readonly [x: string]: {
134
- readonly [x: string]: unknown;
135
- };
136
- } | undefined;
137
- }[] | undefined;
138
120
  readonly providerMetadata?: {
139
121
  readonly [x: string]: {
140
122
  readonly [x: string]: unknown;
@@ -67,7 +67,6 @@ const finish = (state, context) => {
67
67
  return SpeechStream.finish(route, state, {
68
68
  ...output,
69
69
  usage: GeminiGenerateContent.usage(state.usage),
70
- notices: GeminiGenerateContent.notices(route.name, state),
71
70
  providerMetadata: GeminiGenerateContent.providerMetadata(state),
72
71
  detail: `finish reason: ${state.finishReason}`,
73
72
  });
@@ -78,15 +78,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
78
78
  readonly [x: string]: unknown;
79
79
  } | undefined;
80
80
  } | undefined;
81
- readonly notices?: readonly {
82
- readonly type: "filtered" | "moderated" | "other";
83
- readonly message: string;
84
- readonly providerMetadata?: {
85
- readonly [x: string]: {
86
- readonly [x: string]: unknown;
87
- };
88
- } | undefined;
89
- }[] | undefined;
90
81
  readonly providerMetadata?: {
91
82
  readonly [x: string]: {
92
83
  readonly [x: string]: unknown;
@@ -153,15 +144,6 @@ export declare const GoogleTranscription: {
153
144
  readonly [x: string]: unknown;
154
145
  } | undefined;
155
146
  } | undefined;
156
- readonly notices?: readonly {
157
- readonly type: "filtered" | "moderated" | "other";
158
- readonly message: string;
159
- readonly providerMetadata?: {
160
- readonly [x: string]: {
161
- readonly [x: string]: unknown;
162
- };
163
- } | undefined;
164
- }[] | undefined;
165
147
  readonly providerMetadata?: {
166
148
  readonly [x: string]: {
167
149
  readonly [x: string]: unknown;
@@ -103,7 +103,6 @@ const finish = (state) => {
103
103
  segments: state.segments.length === 0 ? undefined : state.segments,
104
104
  words: state.words.length === 0 ? undefined : state.words,
105
105
  usage: GeminiGenerateContent.usage(state.usage),
106
- notices: GeminiGenerateContent.notices(route.name, state),
107
106
  providerMetadata: GeminiGenerateContent.providerMetadata(state),
108
107
  }),
109
108
  ]);
@@ -109,22 +109,17 @@ const decodeResult = Effect.fn("GoogleVideo.decodeResult")(function* (response,
109
109
  headers: context.auth,
110
110
  }));
111
111
  const reasons = generated?.raiMediaFilteredReasons ?? [];
112
- const notices = reasons.map((reason) => ({
113
- type: "filtered",
114
- message: `${route.name} filtered media: ${reason}`,
115
- providerMetadata: { google: { raiMediaFilteredReason: reason } },
116
- }));
117
112
  if (videos.length === 0 && (reasons.length > 0 || (generated?.raiMediaFilteredCount ?? 0) > 0))
118
113
  return yield* output.contentPolicy(`${route.name} filtered every video${reasons.length === 0 ? "" : `: ${reasons.join("; ")}`}`);
119
114
  if (videos.length === 0)
120
115
  return yield* output.invalid(`${route.name} operation completed without any video`);
121
116
  return new VideoResponse({
122
117
  videos,
123
- notices: notices.length === 0 ? undefined : notices,
124
118
  providerMetadata: {
125
119
  google: {
126
120
  operation: context.token.operation,
127
121
  raiMediaFilteredCount: generated?.raiMediaFilteredCount,
122
+ raiMediaFilteredReasons: generated?.raiMediaFilteredReasons,
128
123
  metadata: operation.metadata,
129
124
  },
130
125
  },
@@ -5,7 +5,7 @@ import { type OpenString } from "../schema/index.js";
5
5
  export declare const DEFAULT_BASE_URL = "https://api.meta.ai/v1";
6
6
  /**
7
7
  * Provider-native options. Common fields (`n`, `aspect`, `images`) live on the request; Meta picks its own output
8
- * resolution (about 2.5 megapixels), so `resolution` is ignored with a notice.
8
+ * resolution (about 2.5 megapixels), so `resolution` is ignored.
9
9
  */
10
10
  export type ImageOptions = {
11
11
  /** `WIDTHxHEIGHT` aspect ratio hint; it replaces `aspect`, so setting both fails. */
@@ -3,7 +3,7 @@ import { ImageModel, ImageResponse } from "../image.js";
3
3
  import { Media } from "../media.js";
4
4
  import { MediaProtocol } from "../route/media-protocol.js";
5
5
  import { MediaRoute } from "../route/media.js";
6
- import { mergeJsonRecords } from "../schema/index.js";
6
+ import { mergeJsonRecords, tokenUsage } from "../schema/index.js";
7
7
  import { JsonObject, ProviderShared, optionalNull } from "./shared.js";
8
8
  import { ImageSizing } from "./utils/image-sizing.js";
9
9
  import { MediaInput } from "./utils/media-input.js";
@@ -75,23 +75,14 @@ const decodeResponse = Effect.fn("MetaImages.decodeResponse")(function* (respons
75
75
  return yield* output.invalid(`${route.name} returned no images`);
76
76
  return new ImageResponse({
77
77
  images,
78
- notices: context.request.resolution === undefined
79
- ? undefined
80
- : [
81
- {
82
- type: "other",
83
- message: `${route.name} picks its own output resolution; ignored ${context.request.resolution}`,
84
- },
85
- ],
86
78
  usage: decoded.usage === undefined
87
79
  ? undefined
88
- : {
89
- type: "tokens",
80
+ : tokenUsage({
90
81
  input: decoded.usage.input_tokens,
91
82
  output: decoded.usage.output_tokens,
92
83
  total: decoded.usage.total_tokens,
93
84
  details: { meta: decoded.usage },
94
- },
85
+ }),
95
86
  providerMetadata: { meta: { outputFormat: format } },
96
87
  });
97
88
  });
@@ -1,5 +1,5 @@
1
1
  import { Effect, Schema } from "effect";
2
- import { DecisionResponse } from "../decision.js";
2
+ import { DecisionResponse, DecisionUsage } from "../decision.js";
3
3
  import { DecisionRoute } from "../route/decision.js";
4
4
  import { Endpoint } from "../route/endpoint.js";
5
5
  import { MediaProtocol } from "../route/media-protocol.js";
@@ -34,7 +34,7 @@ const Answer = Schema.Union([
34
34
  probabilities: Schema.Array(Schema.Struct({ value: Schema.Int, label: Schema.String, probability: Probability })),
35
35
  confidence: Probability,
36
36
  }),
37
- Schema.Struct({ type: Schema.Literal("refusal"), name: Schema.String }),
37
+ Schema.Struct({ type: Schema.Literal("refusal"), name: Schema.String, message: Schema.optional(Schema.String) }),
38
38
  ]);
39
39
  const Response = Schema.Struct({
40
40
  model: Schema.String,
@@ -85,13 +85,33 @@ export const protocol = DecisionRoute.protocol({
85
85
  response: {
86
86
  decode: Effect.fn("OpenAIDecisions.decodeResponse")(function* (response, context) {
87
87
  const output = yield* decodeDocument(response);
88
- const answers = output.value.answers.map((answer) => answer.type === "refusal" ? { name: answer.name, type: "error", reason: "refusal" } : answer);
88
+ const answers = output.value.answers.map((answer) => answer.type === "refusal"
89
+ ? {
90
+ name: answer.name,
91
+ type: "error",
92
+ reason: "refusal",
93
+ ...(answer.message === undefined ? {} : { message: answer.message }),
94
+ }
95
+ : answer);
89
96
  const byName = new Map(answers.map((answer) => [answer.name, answer]));
90
97
  const ordered = context.request.questions.flatMap((question) => byName.get(question.name) ?? []);
98
+ const usage = OpenResponses.mapUsage(output.value.usage, context.providerMetadataKey);
91
99
  return new DecisionResponse({
92
100
  answers: ordered.length === answers.length ? ordered : answers,
93
- usage: OpenResponses.mapUsage(output.value.usage, context.providerMetadataKey),
94
- providerMetadata: { [context.providerMetadataKey]: { model: output.value.model } },
101
+ usage: usage === undefined
102
+ ? undefined
103
+ : new DecisionUsage({
104
+ inputTokens: usage.inputTokens,
105
+ outputTokens: usage.outputTokens,
106
+ totalTokens: usage.totalTokens,
107
+ cost: usage.cost,
108
+ }),
109
+ providerMetadata: {
110
+ [context.providerMetadataKey]: {
111
+ model: output.value.model,
112
+ ...(output.value.usage === undefined ? {} : { usage: output.value.usage }),
113
+ },
114
+ },
95
115
  });
96
116
  }),
97
117
  },
@@ -80,15 +80,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
80
80
  readonly [x: string]: unknown;
81
81
  } | undefined;
82
82
  } | undefined;
83
- readonly notices?: readonly {
84
- readonly type: "filtered" | "moderated" | "other";
85
- readonly message: string;
86
- readonly providerMetadata?: {
87
- readonly [x: string]: {
88
- readonly [x: string]: unknown;
89
- };
90
- } | undefined;
91
- }[] | undefined;
92
83
  readonly providerMetadata?: {
93
84
  readonly [x: string]: {
94
85
  readonly [x: string]: unknown;
@@ -139,15 +130,6 @@ export declare const OpenAIImages: {
139
130
  readonly [x: string]: unknown;
140
131
  } | undefined;
141
132
  } | undefined;
142
- readonly notices?: readonly {
143
- readonly type: "filtered" | "moderated" | "other";
144
- readonly message: string;
145
- readonly providerMetadata?: {
146
- readonly [x: string]: {
147
- readonly [x: string]: unknown;
148
- };
149
- } | undefined;
150
- }[] | undefined;
151
133
  readonly providerMetadata?: {
152
134
  readonly [x: string]: {
153
135
  readonly [x: string]: unknown;
@@ -5,7 +5,7 @@ import { classifyProviderFailure } from "../provider-error.js";
5
5
  import { Framing } from "../route/framing.js";
6
6
  import { MediaProtocol } from "../route/media-protocol.js";
7
7
  import { MediaRoute } from "../route/media.js";
8
- import { AIError, mergeJsonRecords, ProviderID } from "../schema/index.js";
8
+ import { AIError, mergeJsonRecords, ProviderID, tokenUsage } from "../schema/index.js";
9
9
  import { optionalNull, ProviderShared } from "./shared.js";
10
10
  import { ImageSizing } from "./utils/image-sizing.js";
11
11
  import { MediaInput } from "./utils/media-input.js";
@@ -164,13 +164,12 @@ const fromRequest = Effect.fn("OpenAIImages.fromRequest")(function* (request) {
164
164
  // ---------------------------------------------------------------------------
165
165
  const usage = (value, provider) => value === undefined
166
166
  ? undefined
167
- : {
168
- type: "tokens",
167
+ : tokenUsage({
169
168
  input: value.input_tokens,
170
169
  output: value.output_tokens,
171
170
  total: value.total_tokens,
172
171
  details: { [provider]: value },
173
- };
172
+ });
174
173
  /** `size` echoes the rendered `WIDTHxHEIGHT`; `auto` or any other value leaves the dimensions unknown. */
175
174
  const info = (format, size) => {
176
175
  const match = size?.match(/^(\d+)x(\d+)$/);
@@ -234,12 +233,9 @@ const finish = (state, context) => {
234
233
  if (state.completed === 0)
235
234
  return Effect.fail(route.incomplete());
236
235
  const provider = context.request.model.provider;
237
- const chosen = size(context.request);
238
- const notice = chosen === undefined ? undefined : ImageSizing.notice(route.name, context.request, chosen);
239
236
  return Effect.succeed([
240
237
  ImageFinishEvent.make({
241
238
  usage: usage(state.usage, provider),
242
- notices: notice === undefined ? undefined : [notice],
243
239
  providerMetadata: {
244
240
  [provider]: {
245
241
  outputFormat: state.format,
@@ -57,15 +57,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
57
57
  readonly [x: string]: unknown;
58
58
  } | undefined;
59
59
  } | undefined;
60
- readonly notices?: readonly {
61
- readonly type: "filtered" | "moderated" | "other";
62
- readonly message: string;
63
- readonly providerMetadata?: {
64
- readonly [x: string]: {
65
- readonly [x: string]: unknown;
66
- };
67
- } | undefined;
68
- }[] | undefined;
69
60
  readonly providerMetadata?: {
70
61
  readonly [x: string]: {
71
62
  readonly [x: string]: unknown;
@@ -116,15 +107,6 @@ export declare const OpenAISpeech: {
116
107
  readonly [x: string]: unknown;
117
108
  } | undefined;
118
109
  } | undefined;
119
- readonly notices?: readonly {
120
- readonly type: "filtered" | "moderated" | "other";
121
- readonly message: string;
122
- readonly providerMetadata?: {
123
- readonly [x: string]: {
124
- readonly [x: string]: unknown;
125
- };
126
- } | undefined;
127
- }[] | undefined;
128
110
  readonly providerMetadata?: {
129
111
  readonly [x: string]: {
130
112
  readonly [x: string]: unknown;
@@ -2,7 +2,7 @@ import { Effect, Schema, SchemaGetter } from "effect";
2
2
  import { Framing } from "../route/framing.js";
3
3
  import { MediaProtocol } from "../route/media-protocol.js";
4
4
  import { MediaRoute } from "../route/media.js";
5
- import { mergeJsonRecords } from "../schema/index.js";
5
+ import { mergeJsonRecords, tokenUsage } from "../schema/index.js";
6
6
  import { SpeechModel } from "../speech.js";
7
7
  import { SpeechStream } from "./utils/speech-stream.js";
8
8
  const route = MediaProtocol.identity({ id: "openai-speech", name: "OpenAI Speech", provider: "openai" });
@@ -73,13 +73,12 @@ const onEvent = Effect.fnUntraced(function* (state, frame) {
73
73
  done: true,
74
74
  usage: usage === undefined
75
75
  ? undefined
76
- : {
77
- type: "tokens",
76
+ : tokenUsage({
78
77
  input: usage.input_tokens,
79
78
  output: usage.output_tokens,
80
79
  total: usage.total_tokens,
81
80
  details: { openai: usage },
82
- },
81
+ }),
83
82
  },
84
83
  [],
85
84
  ];
@@ -115,15 +115,6 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
115
115
  readonly [x: string]: unknown;
116
116
  } | undefined;
117
117
  } | undefined;
118
- readonly notices?: readonly {
119
- readonly type: "filtered" | "moderated" | "other";
120
- readonly message: string;
121
- readonly providerMetadata?: {
122
- readonly [x: string]: {
123
- readonly [x: string]: unknown;
124
- };
125
- } | undefined;
126
- }[] | undefined;
127
118
  readonly providerMetadata?: {
128
119
  readonly [x: string]: {
129
120
  readonly [x: string]: unknown;
@@ -190,15 +181,6 @@ export declare const OpenAITranscription: {
190
181
  readonly [x: string]: unknown;
191
182
  } | undefined;
192
183
  } | undefined;
193
- readonly notices?: readonly {
194
- readonly type: "filtered" | "moderated" | "other";
195
- readonly message: string;
196
- readonly providerMetadata?: {
197
- readonly [x: string]: {
198
- readonly [x: string]: unknown;
199
- };
200
- } | undefined;
201
- }[] | undefined;
202
184
  readonly providerMetadata?: {
203
185
  readonly [x: string]: {
204
186
  readonly [x: string]: unknown;
@@ -3,7 +3,7 @@ import { classifyProviderFailure } from "../provider-error.js";
3
3
  import { Framing } from "../route/framing.js";
4
4
  import { MediaProtocol } from "../route/media-protocol.js";
5
5
  import { MediaRoute } from "../route/media.js";
6
- import { AIError, mergeJsonRecords } from "../schema/index.js";
6
+ import { AIError, mergeJsonRecords, tokenUsage } from "../schema/index.js";
7
7
  import { TranscriptionFinishEvent, TranscriptionModel, TranscriptionSegmentEvent, TranscriptionTextDeltaEvent, } from "../transcription.js";
8
8
  import { mediaTypeExtension } from "../utils/media-type.js";
9
9
  import { ProviderShared } from "./shared.js";
@@ -163,13 +163,12 @@ const usage = (value) => {
163
163
  return undefined;
164
164
  if (value.type === "duration")
165
165
  return { type: "seconds", seconds: value.seconds };
166
- return {
167
- type: "tokens",
166
+ return tokenUsage({
168
167
  input: value.input_tokens,
169
168
  output: value.output_tokens,
170
169
  total: value.total_tokens,
171
170
  details: { openai: value },
172
- };
171
+ });
173
172
  };
174
173
  const finish = (state) => {
175
174
  const transcript = state.transcript;
@@ -73,9 +73,6 @@ const decodeImageDocument = (identity) => {
73
73
  const image = yield* MediaInput.decodedAsset(output.invalid, `${identity.name} result`, data, undefined);
74
74
  return new ImageResponse({
75
75
  images: [image],
76
- notices: document.finish_reason === "CONTENT_FILTERED"
77
- ? [{ type: "moderated", message: `${identity.name} blurred the image for violating its content policy` }]
78
- : undefined,
79
76
  providerMetadata: { stability: { seed: document.seed, finishReason: document.finish_reason } },
80
77
  });
81
78
  });
@@ -25,6 +25,7 @@ export declare const Response: Schema.Struct<{
25
25
  readonly usage: Schema.optional<Schema.StructWithRest<Schema.Struct<{
26
26
  readonly input_tokens: Schema.optional<Schema.Number>;
27
27
  readonly output_tokens: Schema.optional<Schema.Number>;
28
+ readonly cost: Schema.optional<Schema.Number>;
28
29
  }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>;
29
30
  readonly id: Schema.optional<Schema.String>;
30
31
  readonly provider: Schema.optional<Schema.String>;
@@ -72,6 +73,7 @@ export declare const SystemOne: {
72
73
  readonly usage: Schema.optional<Schema.StructWithRest<Schema.Struct<{
73
74
  readonly input_tokens: Schema.optional<Schema.Number>;
74
75
  readonly output_tokens: Schema.optional<Schema.Number>;
76
+ readonly cost: Schema.optional<Schema.Number>;
75
77
  }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>;
76
78
  readonly id: Schema.optional<Schema.String>;
77
79
  readonly provider: Schema.optional<Schema.String>;