@enlitt/sdk 0.1.0 → 0.1.1

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 (72) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +3 -1
  3. package/dist/{chunk-C76K6HLL.cjs → chunk-2BGWYTJM.cjs} +240 -49
  4. package/dist/chunk-2BGWYTJM.cjs.map +1 -0
  5. package/dist/{chunk-VNVMEU34.js → chunk-NI6WH5FI.js} +3 -3
  6. package/dist/{chunk-VNVMEU34.js.map → chunk-NI6WH5FI.js.map} +1 -1
  7. package/dist/{chunk-6DPBYLA5.js → chunk-O6ASIA3X.js} +19 -8
  8. package/dist/chunk-O6ASIA3X.js.map +1 -0
  9. package/dist/{chunk-26SW63P5.cjs → chunk-PPOUNWNA.cjs} +19 -7
  10. package/dist/chunk-PPOUNWNA.cjs.map +1 -0
  11. package/dist/{chunk-SFI4RLNN.js → chunk-UVZMKGIL.js} +198 -7
  12. package/dist/chunk-UVZMKGIL.js.map +1 -0
  13. package/dist/{chunk-G4DTTV5E.cjs → chunk-YPA4R65T.cjs} +7 -7
  14. package/dist/{chunk-G4DTTV5E.cjs.map → chunk-YPA4R65T.cjs.map} +1 -1
  15. package/dist/core/errors.d.cts +13 -5
  16. package/dist/core/errors.d.ts +13 -5
  17. package/dist/core/errors.d.ts.map +1 -1
  18. package/dist/core/index.d.cts +1 -1
  19. package/dist/core/index.d.ts +1 -1
  20. package/dist/core/index.d.ts.map +1 -1
  21. package/dist/core/session.d.cts +15 -0
  22. package/dist/core/session.d.ts +15 -0
  23. package/dist/core/session.d.ts.map +1 -1
  24. package/dist/core/transport.d.cts +1 -1
  25. package/dist/core/transport.d.ts +1 -1
  26. package/dist/core.cjs +22 -18
  27. package/dist/core.js +2 -2
  28. package/dist/openai/client.d.cts +25 -1
  29. package/dist/openai/client.d.ts +25 -1
  30. package/dist/openai/client.d.ts.map +1 -1
  31. package/dist/openai/index.d.cts +1 -0
  32. package/dist/openai/index.d.ts +1 -0
  33. package/dist/openai/index.d.ts.map +1 -1
  34. package/dist/openai/media.d.cts +108 -0
  35. package/dist/openai/media.d.ts +109 -0
  36. package/dist/openai/media.d.ts.map +1 -0
  37. package/dist/openai.cjs +191 -47
  38. package/dist/openai.cjs.map +1 -1
  39. package/dist/openai.js +145 -1
  40. package/dist/openai.js.map +1 -1
  41. package/dist/server/callback.d.cts +2 -1
  42. package/dist/server/callback.d.ts +2 -1
  43. package/dist/server/callback.d.ts.map +1 -1
  44. package/dist/server/client-sign-in.d.cts +77 -0
  45. package/dist/server/client-sign-in.d.ts +78 -0
  46. package/dist/server/client-sign-in.d.ts.map +1 -0
  47. package/dist/server/index.d.cts +2 -1
  48. package/dist/server/index.d.ts +2 -1
  49. package/dist/server/index.d.ts.map +1 -1
  50. package/dist/server.cjs +555 -29
  51. package/dist/server.cjs.map +1 -1
  52. package/dist/server.js +529 -9
  53. package/dist/server.js.map +1 -1
  54. package/dist/vercel/index.d.cts +4 -2
  55. package/dist/vercel/index.d.ts +4 -2
  56. package/dist/vercel/index.d.ts.map +1 -1
  57. package/dist/vercel/language-model.d.cts +17 -2
  58. package/dist/vercel/language-model.d.ts +17 -2
  59. package/dist/vercel/language-model.d.ts.map +1 -1
  60. package/dist/vercel/premium-language-model.d.cts +30 -1
  61. package/dist/vercel/premium-language-model.d.ts +30 -1
  62. package/dist/vercel/premium-language-model.d.ts.map +1 -1
  63. package/dist/vercel/premium-media-model.d.cts +101 -0
  64. package/dist/vercel/premium-media-model.d.ts +102 -0
  65. package/dist/vercel/premium-media-model.d.ts.map +1 -0
  66. package/dist/vercel.cjs +5 -5
  67. package/dist/vercel.js +2 -2
  68. package/package.json +12 -2
  69. package/dist/chunk-26SW63P5.cjs.map +0 -1
  70. package/dist/chunk-6DPBYLA5.js.map +0 -1
  71. package/dist/chunk-C76K6HLL.cjs.map +0 -1
  72. package/dist/chunk-SFI4RLNN.js.map +0 -1
package/dist/openai.cjs CHANGED
@@ -1,9 +1,151 @@
1
1
  'use strict';
2
2
 
3
3
  var chunk6OWXYBBT_cjs = require('./chunk-6OWXYBBT.cjs');
4
- var chunk26SW63P5_cjs = require('./chunk-26SW63P5.cjs');
4
+ var chunkPPOUNWNA_cjs = require('./chunk-PPOUNWNA.cjs');
5
5
  var protocol = require('@enlitt/protocol');
6
6
 
7
+ function createMediaMethods(client, provider) {
8
+ return {
9
+ images: {
10
+ generate: async (body, options) => {
11
+ validateRequestOptions(options);
12
+ assertPremiumModel(body, provider);
13
+ if (typeof body.model !== "string" || body.model.length === 0) {
14
+ throw new chunkPPOUNWNA_cjs.EnlittConfigurationError(
15
+ "images.generate() through Enlitt requires a model name, so the operation names the model it paid for."
16
+ );
17
+ }
18
+ if (body.stream === true) {
19
+ throw new chunkPPOUNWNA_cjs.EnlittConfigurationError("Streaming image generation is not supported through Enlitt.");
20
+ }
21
+ const method = requireMethod(provider?.images?.generate, "images.generate");
22
+ const { enlitt: _removed, ...request } = body;
23
+ return runMediaCall(client, body, options, {
24
+ kind: "image",
25
+ request,
26
+ invoke: () => method.call(provider.images, request, options),
27
+ facts: imageUsageFacts
28
+ });
29
+ }
30
+ },
31
+ audio: {
32
+ speech: {
33
+ create: async (body, options) => {
34
+ validateRequestOptions(options);
35
+ assertPremiumModel(body, provider);
36
+ const method = requireMethod(provider?.audio?.speech?.create, "audio.speech.create");
37
+ const { enlitt: _removed, ...request } = body;
38
+ return runMediaCall(client, body, options, {
39
+ kind: "speech",
40
+ request,
41
+ characters: [...request.input].length,
42
+ // The `Response` body is the caller's; the adapter never reads it.
43
+ invoke: () => method.call(provider.audio.speech, request, options),
44
+ facts: () => ({})
45
+ });
46
+ }
47
+ },
48
+ transcriptions: {
49
+ create: async (body, options) => {
50
+ validateRequestOptions(options);
51
+ assertPremiumModel(body, provider);
52
+ if (body.stream === true) {
53
+ throw new chunkPPOUNWNA_cjs.EnlittConfigurationError("Streaming transcription is not supported through Enlitt.");
54
+ }
55
+ const method = requireMethod(provider?.audio?.transcriptions?.create, "audio.transcriptions.create");
56
+ const { enlitt: _removed, ...request } = body;
57
+ return runMediaCall(client, body, options, {
58
+ kind: "transcription",
59
+ request,
60
+ invoke: () => method.call(provider.audio.transcriptions, request, options),
61
+ facts: () => ({})
62
+ });
63
+ }
64
+ }
65
+ }
66
+ };
67
+ }
68
+ function assertPremiumModel(body, provider) {
69
+ if (body.model === protocol.ENLITT_STANDARD_MODEL) {
70
+ throw new chunkPPOUNWNA_cjs.EnlittConfigurationError(
71
+ `Enlitt has no standard image or audio model; "${protocol.ENLITT_STANDARD_MODEL}" is a language model only.`
72
+ );
73
+ }
74
+ if (provider === void 0) {
75
+ throw new chunkPPOUNWNA_cjs.EnlittConfigurationError("A premium OpenAI model requires an OpenAI client passed to enlitt().");
76
+ }
77
+ }
78
+ function requireMethod(method, name) {
79
+ if (typeof method !== "function") {
80
+ throw new chunkPPOUNWNA_cjs.EnlittConfigurationError(`The OpenAI client passed to enlitt() does not expose ${name}().`);
81
+ }
82
+ return method;
83
+ }
84
+ async function runMediaCall(client, body, options, spec) {
85
+ const call = readCallOptions(body, "premium");
86
+ const price = call.price;
87
+ const signal = options?.signal;
88
+ const request = {
89
+ maxCharge: call.maxCharge,
90
+ provider: { id: "openai", model: String(body.model) },
91
+ callId: call.idempotencyKey,
92
+ ...call.reportingDeadlineMs !== void 0 ? { reportingDeadlineMs: call.reportingDeadlineMs } : {},
93
+ ...call.metadata !== void 0 ? { metadata: call.metadata } : {},
94
+ ...signal !== void 0 ? { signal } : {}
95
+ };
96
+ return chunkPPOUNWNA_cjs.runPremiumCharge(client, request, async (charge, operation) => {
97
+ const startedAt = /* @__PURE__ */ new Date();
98
+ let result;
99
+ try {
100
+ result = await spec.invoke();
101
+ } catch (thrown) {
102
+ const endedAt2 = /* @__PURE__ */ new Date();
103
+ const canceled = chunkPPOUNWNA_cjs.isCancellation(thrown, signal);
104
+ if (canceled) {
105
+ charge(await evaluatePrice(client, price, buildContext(spec, "canceled", void 0, startedAt, endedAt2, operation)));
106
+ }
107
+ operation.describe({
108
+ timing: { startedAt: startedAt.toISOString(), endedAt: endedAt2.toISOString() },
109
+ delivery: { outputStarted: false, outputCompleted: false },
110
+ errorCategory: canceled ? "canceled" : "provider"
111
+ });
112
+ throw thrown;
113
+ }
114
+ const endedAt = /* @__PURE__ */ new Date();
115
+ charge(await evaluatePrice(client, price, buildContext(spec, "completed", result, startedAt, endedAt, operation)));
116
+ operation.describe({
117
+ timing: { startedAt: startedAt.toISOString(), endedAt: endedAt.toISOString() },
118
+ delivery: { outputStarted: true, outputCompleted: true },
119
+ ...spec.facts(result)
120
+ });
121
+ return result;
122
+ });
123
+ }
124
+ function buildContext(spec, status, result, startedAt, endedAt, operation) {
125
+ const base = {
126
+ status,
127
+ startedAt,
128
+ endedAt,
129
+ durationMs: endedAt.getTime() - startedAt.getTime(),
130
+ effectiveMaxChargeNanoUsd: operation.effectiveMaxChargeNanoUsd
131
+ };
132
+ if (spec.kind === "speech") {
133
+ return { ...base, kind: "speech", request: spec.request, characters: spec.characters };
134
+ }
135
+ return {
136
+ ...base,
137
+ kind: spec.kind,
138
+ request: spec.request,
139
+ ...result !== void 0 ? { response: result } : {}
140
+ };
141
+ }
142
+ function imageUsageFacts(result) {
143
+ const usage = result?.usage;
144
+ if (usage === void 0) return {};
145
+ return { usage: { inputTokens: usage.input_tokens, outputTokens: usage.output_tokens } };
146
+ }
147
+
148
+ // src/openai/client.ts
7
149
  var RESPONSES_PATH = "/v1/responses";
8
150
  var STANDARD_FIELDS = /* @__PURE__ */ new Set(["model", "input", "instructions", "max_output_tokens", "tools", "tool_choice", "stream", "metadata", "enlitt"]);
9
151
  function enlitt(first = {}, second = {}) {
@@ -12,15 +154,17 @@ function enlitt(first = {}, second = {}) {
12
154
  let options;
13
155
  if (looksLikeClient) {
14
156
  if (!isOpenAIClient(first)) {
15
- throw new chunk26SW63P5_cjs.EnlittConfigurationError("The OpenAI client must expose responses.create().");
157
+ throw new chunkPPOUNWNA_cjs.EnlittConfigurationError("The OpenAI client must expose responses.create().");
16
158
  }
17
159
  provider = first;
18
160
  options = second;
19
161
  } else {
20
162
  options = first;
21
163
  }
22
- const client = chunk26SW63P5_cjs.createInternalClient(options);
164
+ const client = chunkPPOUNWNA_cjs.createInternalClient(options);
23
165
  return {
166
+ // Premium-only image and audio methods (owner decision 2026-11-15).
167
+ ...createMediaMethods(client, provider),
24
168
  responses: {
25
169
  create: (body, requestOptions) => {
26
170
  validateRequestOptions(requestOptions);
@@ -41,38 +185,38 @@ function validateRequestOptions(options) {
41
185
  if (options === void 0) return;
42
186
  for (const key of Object.keys(options)) {
43
187
  if (key !== "signal" && key !== "timeout") {
44
- throw new chunk26SW63P5_cjs.EnlittConfigurationError(`OpenAI request option "${key}" is not supported by the Enlitt adapter.`);
188
+ throw new chunkPPOUNWNA_cjs.EnlittConfigurationError(`OpenAI request option "${key}" is not supported by the Enlitt adapter.`);
45
189
  }
46
190
  }
47
191
  if (options.timeout !== void 0 && (!Number.isSafeInteger(options.timeout) || options.timeout <= 0)) {
48
- throw new chunk26SW63P5_cjs.EnlittConfigurationError("OpenAI request option timeout must be a positive safe integer.");
192
+ throw new chunkPPOUNWNA_cjs.EnlittConfigurationError("OpenAI request option timeout must be a positive safe integer.");
49
193
  }
50
194
  }
51
195
  function readCallOptions(body, mode) {
52
196
  const input = body.enlitt ?? {};
53
197
  const known = /* @__PURE__ */ new Set(["idempotencyKey", "maxCharge", "price", "reportingDeadlineMs", "metadata"]);
54
198
  for (const key of Object.keys(input)) {
55
- if (!known.has(key)) throw new chunk26SW63P5_cjs.EnlittConfigurationError(`enlitt.${key} is not a recognized Enlitt option.`);
199
+ if (!known.has(key)) throw new chunkPPOUNWNA_cjs.EnlittConfigurationError(`enlitt.${key} is not a recognized Enlitt option.`);
56
200
  }
57
201
  if (mode === "standard" && (input.maxCharge !== void 0 || input.price !== void 0 || input.reportingDeadlineMs !== void 0)) {
58
- throw new chunk26SW63P5_cjs.EnlittConfigurationError("maxCharge, price, and reportingDeadlineMs are premium-only options.");
202
+ throw new chunkPPOUNWNA_cjs.EnlittConfigurationError("maxCharge, price, and reportingDeadlineMs are premium-only options.");
59
203
  }
60
- const idempotencyKey = input.idempotencyKey === void 0 ? chunk26SW63P5_cjs.generateRandomCallId() : chunk26SW63P5_cjs.assertCallId(input.idempotencyKey);
61
- const metadata = input.metadata === void 0 ? void 0 : chunk26SW63P5_cjs.assertCallerMetadata(input.metadata, "enlitt.metadata");
204
+ const idempotencyKey = input.idempotencyKey === void 0 ? chunkPPOUNWNA_cjs.generateRandomCallId() : chunkPPOUNWNA_cjs.assertCallId(input.idempotencyKey);
205
+ const metadata = input.metadata === void 0 ? void 0 : chunkPPOUNWNA_cjs.assertCallerMetadata(input.metadata, "enlitt.metadata");
62
206
  if (mode === "standard") return { idempotencyKey, metadata };
63
207
  const price = input.price;
64
208
  if (price !== void 0 && typeof price !== "string" && typeof price !== "function") {
65
- throw new chunk26SW63P5_cjs.EnlittConfigurationError("enlitt.price must be a canonical NANOUSD string or a function.");
209
+ throw new chunkPPOUNWNA_cjs.EnlittConfigurationError("enlitt.price must be a canonical NANOUSD string or a function.");
66
210
  }
67
- const constantPrice = typeof price === "string" ? chunk26SW63P5_cjs.assertNanoUsd(price, "enlitt.price") : price;
68
- const maxCharge = input.maxCharge === void 0 ? typeof constantPrice === "string" ? constantPrice : void 0 : chunk26SW63P5_cjs.assertNanoUsd(input.maxCharge, "enlitt.maxCharge");
211
+ const constantPrice = typeof price === "string" ? chunkPPOUNWNA_cjs.assertNanoUsd(price, "enlitt.price") : price;
212
+ const maxCharge = input.maxCharge === void 0 ? typeof constantPrice === "string" ? constantPrice : void 0 : chunkPPOUNWNA_cjs.assertNanoUsd(input.maxCharge, "enlitt.maxCharge");
69
213
  if (maxCharge === void 0) {
70
- throw new chunk26SW63P5_cjs.EnlittConfigurationError("A premium call requires enlitt.maxCharge, or a constant enlitt.price.");
214
+ throw new chunkPPOUNWNA_cjs.EnlittConfigurationError("A premium call requires enlitt.maxCharge, or a constant enlitt.price.");
71
215
  }
72
216
  if (typeof constantPrice === "string" && BigInt(constantPrice) > BigInt(maxCharge)) {
73
- throw new chunk26SW63P5_cjs.EnlittConfigurationError("enlitt.price cannot exceed enlitt.maxCharge.");
217
+ throw new chunkPPOUNWNA_cjs.EnlittConfigurationError("enlitt.price cannot exceed enlitt.maxCharge.");
74
218
  }
75
- const reportingDeadlineMs = input.reportingDeadlineMs === void 0 ? void 0 : chunk26SW63P5_cjs.assertReportingDeadlineMs(input.reportingDeadlineMs, "enlitt.reportingDeadlineMs");
219
+ const reportingDeadlineMs = input.reportingDeadlineMs === void 0 ? void 0 : chunkPPOUNWNA_cjs.assertReportingDeadlineMs(input.reportingDeadlineMs, "enlitt.reportingDeadlineMs");
76
220
  return { idempotencyKey, metadata, maxCharge, price: constantPrice, reportingDeadlineMs };
77
221
  }
78
222
  function timedSignal(options) {
@@ -94,7 +238,7 @@ async function createStandardResponse(client, body, options) {
94
238
  const request = buildStandardRequest(body, call.metadata);
95
239
  const timed = timedSignal(options);
96
240
  try {
97
- const response = await chunk26SW63P5_cjs.requestEnlitt(client, {
241
+ const response = await chunkPPOUNWNA_cjs.requestEnlitt(client, {
98
242
  path: RESPONSES_PATH,
99
243
  body: request,
100
244
  callId: call.idempotencyKey,
@@ -102,10 +246,10 @@ async function createStandardResponse(client, body, options) {
102
246
  ...timed.signal !== void 0 ? { signal: timed.signal } : {}
103
247
  });
104
248
  if (body.stream === true) {
105
- if (response.body === null) throw new chunk26SW63P5_cjs.EnlittError("malformed_response", "Enlitt's streaming response carried no body.");
249
+ if (response.body === null) throw new chunkPPOUNWNA_cjs.EnlittError("malformed_response", "Enlitt's streaming response carried no body.");
106
250
  return mapStandardStream(response.body, () => timed.cleanup());
107
251
  }
108
- const parsed = protocol.validateOpenAIResponse(await chunk26SW63P5_cjs.readEnlittJson(response), { mode: "tolerant" });
252
+ const parsed = protocol.validateOpenAIResponse(await chunkPPOUNWNA_cjs.readEnlittJson(response), { mode: "tolerant" });
109
253
  if (!parsed.ok) throw malformed(parsed.error.message, parsed.error.param);
110
254
  return mapStandardResponse(parsed.value);
111
255
  } finally {
@@ -114,11 +258,11 @@ async function createStandardResponse(client, body, options) {
114
258
  }
115
259
  function buildStandardRequest(body, metadata) {
116
260
  for (const key of Object.keys(body)) {
117
- if (!STANDARD_FIELDS.has(key)) throw new chunk26SW63P5_cjs.EnlittConfigurationError(`OpenAI field "${key}" is not supported by Enlitt's standard route.`);
261
+ if (!STANDARD_FIELDS.has(key)) throw new chunkPPOUNWNA_cjs.EnlittConfigurationError(`OpenAI field "${key}" is not supported by Enlitt's standard route.`);
118
262
  }
119
263
  const messages = [];
120
264
  if (body.instructions !== void 0 && body.instructions !== null) {
121
- if (typeof body.instructions !== "string") throw new chunk26SW63P5_cjs.EnlittConfigurationError("Standard instructions must be a string.");
265
+ if (typeof body.instructions !== "string") throw new chunkPPOUNWNA_cjs.EnlittConfigurationError("Standard instructions must be a string.");
122
266
  messages.push({ role: "system", content: body.instructions });
123
267
  }
124
268
  messages.push(...mapInput(body.input));
@@ -127,52 +271,52 @@ function buildStandardRequest(body, metadata) {
127
271
  if (body.stream === true) draft.stream = true;
128
272
  if (metadata !== void 0) draft.metadata = metadata;
129
273
  if (body.metadata !== void 0 && body.metadata !== null) {
130
- if (metadata !== void 0) throw new chunk26SW63P5_cjs.EnlittConfigurationError("Supply metadata under enlitt.metadata, not both metadata locations.");
131
- draft.metadata = chunk26SW63P5_cjs.assertCallerMetadata(body.metadata, "metadata");
274
+ if (metadata !== void 0) throw new chunkPPOUNWNA_cjs.EnlittConfigurationError("Supply metadata under enlitt.metadata, not both metadata locations.");
275
+ draft.metadata = chunkPPOUNWNA_cjs.assertCallerMetadata(body.metadata, "metadata");
132
276
  }
133
277
  if (body.tool_choice !== void 0 && body.tool_choice !== "auto" && body.tool_choice !== "none") {
134
- throw new chunk26SW63P5_cjs.EnlittConfigurationError("Standard tool_choice supports only auto or none.");
278
+ throw new chunkPPOUNWNA_cjs.EnlittConfigurationError("Standard tool_choice supports only auto or none.");
135
279
  }
136
280
  if (body.tools !== void 0 && body.tool_choice !== "none") {
137
281
  draft.tools = body.tools.map((tool, index) => {
138
282
  const value = tool;
139
- if (value.type !== "function") throw new chunk26SW63P5_cjs.EnlittConfigurationError(`tools[${index}] must be a function tool.`);
140
- if (value.strict !== void 0) throw new chunk26SW63P5_cjs.EnlittConfigurationError(`tools[${index}].strict is not supported.`);
283
+ if (value.type !== "function") throw new chunkPPOUNWNA_cjs.EnlittConfigurationError(`tools[${index}] must be a function tool.`);
284
+ if (value.strict !== void 0) throw new chunkPPOUNWNA_cjs.EnlittConfigurationError(`tools[${index}].strict is not supported.`);
141
285
  return { name: value.name, ...value.description !== void 0 ? { description: value.description } : {}, input_schema: value.parameters };
142
286
  });
143
287
  }
144
288
  const validated = protocol.validateEnlittStandardRequest(draft);
145
- if (!validated.ok) throw new chunk26SW63P5_cjs.EnlittConfigurationError(`${validated.error.message} (${validated.error.param})`);
289
+ if (!validated.ok) throw new chunkPPOUNWNA_cjs.EnlittConfigurationError(`${validated.error.message} (${validated.error.param})`);
146
290
  return validated.value;
147
291
  }
148
292
  function mapInput(input) {
149
293
  if (typeof input === "string") return [{ role: "user", content: [{ type: "text", text: input }] }];
150
- if (!Array.isArray(input)) throw new chunk26SW63P5_cjs.EnlittConfigurationError("Standard input must be a string or an array of supported input items.");
294
+ if (!Array.isArray(input)) throw new chunkPPOUNWNA_cjs.EnlittConfigurationError("Standard input must be a string or an array of supported input items.");
151
295
  return input.map((item, index) => {
152
- if (typeof item !== "object" || item === null) throw new chunk26SW63P5_cjs.EnlittConfigurationError(`input[${index}] is not supported.`);
296
+ if (typeof item !== "object" || item === null) throw new chunkPPOUNWNA_cjs.EnlittConfigurationError(`input[${index}] is not supported.`);
153
297
  const value = item;
154
298
  if (value.type === "function_call") {
155
299
  return { role: "assistant", tool_calls: [{ id: String(value.call_id), name: String(value.name), arguments: String(value.arguments) }] };
156
300
  }
157
301
  if (value.type === "function_call_output") {
158
- if (typeof value.output !== "string") throw new chunk26SW63P5_cjs.EnlittConfigurationError(`input[${index}].output must be a string.`);
302
+ if (typeof value.output !== "string") throw new chunkPPOUNWNA_cjs.EnlittConfigurationError(`input[${index}].output must be a string.`);
159
303
  return { role: "tool", tool_call_id: String(value.call_id), content: value.output };
160
304
  }
161
305
  const role = value.role;
162
306
  if (role !== "user" && role !== "system" && role !== "developer" && role !== "assistant") {
163
- throw new chunk26SW63P5_cjs.EnlittConfigurationError(`input[${index}].role is not supported.`);
307
+ throw new chunkPPOUNWNA_cjs.EnlittConfigurationError(`input[${index}].role is not supported.`);
164
308
  }
165
309
  const content = value.content;
166
310
  if (role === "system" || role === "developer") {
167
- if (typeof content !== "string") throw new chunk26SW63P5_cjs.EnlittConfigurationError(`input[${index}].content must be a string.`);
311
+ if (typeof content !== "string") throw new chunkPPOUNWNA_cjs.EnlittConfigurationError(`input[${index}].content must be a string.`);
168
312
  return { role: "system", content };
169
313
  }
170
314
  if (role === "assistant") {
171
- if (typeof content !== "string") throw new chunk26SW63P5_cjs.EnlittConfigurationError(`input[${index}].content must be a string.`);
315
+ if (typeof content !== "string") throw new chunkPPOUNWNA_cjs.EnlittConfigurationError(`input[${index}].content must be a string.`);
172
316
  return { role: "assistant", content };
173
317
  }
174
318
  const parts = typeof content === "string" ? [{ type: "input_text", text: content }] : content;
175
- if (!Array.isArray(parts)) throw new chunk26SW63P5_cjs.EnlittConfigurationError(`input[${index}].content is not supported.`);
319
+ if (!Array.isArray(parts)) throw new chunkPPOUNWNA_cjs.EnlittConfigurationError(`input[${index}].content is not supported.`);
176
320
  return {
177
321
  role: "user",
178
322
  content: parts.map((part, partIndex) => {
@@ -182,7 +326,7 @@ function mapInput(input) {
182
326
  const match = /^data:(image\/(?:png|jpeg));base64,(.+)$/.exec(p.image_url);
183
327
  return match ? { type: "image", source: { type: "base64", media_type: match[1], data: match[2] } } : { type: "image", source: { type: "url", url: p.image_url } };
184
328
  }
185
- throw new chunk26SW63P5_cjs.EnlittConfigurationError(`input[${index}].content[${partIndex}] is not supported.`);
329
+ throw new chunkPPOUNWNA_cjs.EnlittConfigurationError(`input[${index}].content[${partIndex}] is not supported.`);
186
330
  })
187
331
  };
188
332
  });
@@ -265,12 +409,12 @@ function mapStandardEvent(event) {
265
409
  return event;
266
410
  }
267
411
  function malformed(message, param) {
268
- return new chunk26SW63P5_cjs.EnlittError("malformed_response", `Enlitt's response could not be validated: ${message} (${param}).`);
412
+ return new chunkPPOUNWNA_cjs.EnlittError("malformed_response", `Enlitt's response could not be validated: ${message} (${param}).`);
269
413
  }
270
414
  async function createPremiumResponse(client, provider, body, options) {
271
- if (provider === void 0) throw new chunk26SW63P5_cjs.EnlittConfigurationError("A premium OpenAI model requires an OpenAI client passed to enlitt().");
272
- if (typeof body.model !== "string" || body.model.length === 0) throw new chunk26SW63P5_cjs.EnlittConfigurationError("A premium OpenAI call requires a model name.");
273
- if (body.background === true) throw new chunk26SW63P5_cjs.EnlittConfigurationError("Background OpenAI responses are not supported.");
415
+ if (provider === void 0) throw new chunkPPOUNWNA_cjs.EnlittConfigurationError("A premium OpenAI model requires an OpenAI client passed to enlitt().");
416
+ if (typeof body.model !== "string" || body.model.length === 0) throw new chunkPPOUNWNA_cjs.EnlittConfigurationError("A premium OpenAI call requires a model name.");
417
+ if (body.background === true) throw new chunkPPOUNWNA_cjs.EnlittConfigurationError("Background OpenAI responses are not supported.");
274
418
  const call = readCallOptions(body, "premium");
275
419
  const { enlitt: _removed, ...providerBody } = body;
276
420
  const request = {
@@ -293,13 +437,13 @@ var TerminalResponse = class extends Error {
293
437
  };
294
438
  async function wrapPremiumResponse(client, provider, request, price, body, options) {
295
439
  try {
296
- return await chunk26SW63P5_cjs.runPremiumCharge(client, request, async (charge, operation) => {
440
+ return await chunkPPOUNWNA_cjs.runPremiumCharge(client, request, async (charge, operation) => {
297
441
  const startedAt = /* @__PURE__ */ new Date();
298
442
  let response;
299
443
  try {
300
444
  response = await provider.responses.create(body, options);
301
445
  } catch (error) {
302
- if (chunk26SW63P5_cjs.isCancellation(error, request.signal)) {
446
+ if (chunkPPOUNWNA_cjs.isCancellation(error, request.signal)) {
303
447
  const endedAt2 = /* @__PURE__ */ new Date();
304
448
  charge(await evaluatePrice(
305
449
  client,
@@ -338,13 +482,13 @@ async function wrapPremiumStream(client, provider, request, price, body, options
338
482
  rejectExpose = reject;
339
483
  });
340
484
  let wasExposed = false;
341
- void chunk26SW63P5_cjs.runPremiumCharge(client, request, async (charge, operation) => {
485
+ void chunkPPOUNWNA_cjs.runPremiumCharge(client, request, async (charge, operation) => {
342
486
  const startedAt = /* @__PURE__ */ new Date();
343
487
  let source;
344
488
  try {
345
489
  source = await provider.responses.create(body, options);
346
490
  } catch (error) {
347
- if (chunk26SW63P5_cjs.isCancellation(error, request.signal)) {
491
+ if (chunkPPOUNWNA_cjs.isCancellation(error, request.signal)) {
348
492
  const endedAt = /* @__PURE__ */ new Date();
349
493
  charge(await evaluatePrice(
350
494
  client,
@@ -408,7 +552,7 @@ async function* streamWithSettlement(source, price, client, charge, operation, s
408
552
  if (!terminal) {
409
553
  terminal = true;
410
554
  const endedAt = /* @__PURE__ */ new Date();
411
- if (chunk26SW63P5_cjs.isCancellation(error, signal)) {
555
+ if (chunkPPOUNWNA_cjs.isCancellation(error, signal)) {
412
556
  charge(await evaluatePrice(
413
557
  client,
414
558
  price,
@@ -440,9 +584,9 @@ async function evaluatePrice(client, price, context) {
440
584
  if (price === void 0) return "0";
441
585
  if (typeof price === "string") return price;
442
586
  try {
443
- return chunk26SW63P5_cjs.assertNanoUsd(await price(context), "price() result");
587
+ return chunkPPOUNWNA_cjs.assertNanoUsd(await price(context), "price() result");
444
588
  } catch (error) {
445
- client.onTerminalReportError?.(error instanceof chunk26SW63P5_cjs.EnlittError ? error : new chunk26SW63P5_cjs.EnlittConfigurationError(`The price function failed, so the call was charged "0": ${error instanceof Error ? error.message : String(error)}`));
589
+ client.onTerminalReportError?.(error instanceof chunkPPOUNWNA_cjs.EnlittError ? error : new chunkPPOUNWNA_cjs.EnlittConfigurationError(`The price function failed, so the call was charged "0": ${error instanceof Error ? error.message : String(error)}`));
446
590
  return "0";
447
591
  }
448
592
  }
@@ -464,8 +608,8 @@ function describe(operation, startedAt, endedAt, response, errorCategory) {
464
608
  });
465
609
  }
466
610
  function perToken(rates) {
467
- const input = BigInt(chunk26SW63P5_cjs.assertNanoUsd(rates.input, "perToken input rate"));
468
- const output = BigInt(chunk26SW63P5_cjs.assertNanoUsd(rates.output, "perToken output rate"));
611
+ const input = BigInt(chunkPPOUNWNA_cjs.assertNanoUsd(rates.input, "perToken input rate"));
612
+ const output = BigInt(chunkPPOUNWNA_cjs.assertNanoUsd(rates.output, "perToken output rate"));
469
613
  return (context) => (input * BigInt(context.usage?.input_tokens ?? 0) + output * BigInt(context.usage?.output_tokens ?? 0)).toString();
470
614
  }
471
615