@effect-uai/responses 0.11.0 → 0.12.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 (49) hide show
  1. package/dist/OpenAIDeepResearch.d.mts +6 -5
  2. package/dist/OpenAIDeepResearch.d.mts.map +1 -1
  3. package/dist/OpenAIDeepResearch.mjs +8 -4
  4. package/dist/OpenAIDeepResearch.mjs.map +1 -1
  5. package/dist/OpenAIEmbedding.d.mts +2 -3
  6. package/dist/OpenAIEmbedding.d.mts.map +1 -1
  7. package/dist/OpenAIEmbedding.mjs +1 -1
  8. package/dist/OpenAIEmbedding.mjs.map +1 -1
  9. package/dist/Responses.d.mts +20 -2
  10. package/dist/Responses.d.mts.map +1 -1
  11. package/dist/Responses.mjs +9 -6
  12. package/dist/Responses.mjs.map +1 -1
  13. package/dist/ResponsesTools.d.mts +0 -2
  14. package/dist/ResponsesTools.d.mts.map +1 -1
  15. package/dist/ResponsesTools.mjs +1 -1
  16. package/dist/ResponsesTools.mjs.map +1 -1
  17. package/dist/codec.d.mts +0 -2
  18. package/dist/codec.d.mts.map +1 -1
  19. package/dist/codec.mjs +31 -9
  20. package/dist/codec.mjs.map +1 -1
  21. package/dist/codec.test.d.mts +1 -0
  22. package/dist/codec.test.mjs +94 -0
  23. package/dist/codec.test.mjs.map +1 -0
  24. package/dist/{magic-string.es-CaWgF-3p.mjs → magic-string.es-CUAnjKYC.mjs} +14 -13
  25. package/dist/{magic-string.es-CaWgF-3p.mjs.map → magic-string.es-CUAnjKYC.mjs.map} +1 -1
  26. package/dist/models.d.mts.map +1 -1
  27. package/dist/region.d.mts.map +1 -1
  28. package/dist/region.mjs.map +1 -1
  29. package/dist/region.test.d.mts +1 -1
  30. package/dist/region.test.mjs +1 -1
  31. package/dist/region.test.mjs.map +1 -1
  32. package/dist/responsesTools.test.d.mts +1 -1
  33. package/dist/responsesTools.test.mjs +7 -5
  34. package/dist/responsesTools.test.mjs.map +1 -1
  35. package/dist/streamEvents.d.mts +0 -2
  36. package/dist/streamEvents.d.mts.map +1 -1
  37. package/dist/streamEvents.mjs +1 -1
  38. package/dist/streamEvents.mjs.map +1 -1
  39. package/dist/{test.DNmyFkvJ-CPKukVWS.mjs → test.DNmyFkvJ-N3QqMRwZ.mjs} +247 -222
  40. package/dist/test.DNmyFkvJ-N3QqMRwZ.mjs.map +1 -0
  41. package/package.json +9 -5
  42. package/src/OpenAIDeepResearch.ts +9 -14
  43. package/src/OpenAIEmbedding.ts +24 -29
  44. package/src/Responses.ts +28 -8
  45. package/src/ResponsesTools.ts +4 -6
  46. package/src/codec.test.ts +87 -0
  47. package/src/codec.ts +33 -13
  48. package/dist/test.DNmyFkvJ-CPKukVWS.mjs.map +0 -1
  49. /package/dist/{chunk-CfYAbeIz.mjs → rolldown-runtime-D7D4PA-g.mjs} +0 -0
package/dist/codec.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
2
- import { Encoding, Match, Option, Schema } from "effect";
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { Encoding, Match, Option, Result, Schema, pipe } from "effect";
3
3
  //#region src/codec.ts
4
4
  var codec_exports = /* @__PURE__ */ __exportAll({
5
5
  WireAnnotation: () => WireAnnotation,
@@ -114,11 +114,33 @@ const WireResponseCompleted = Schema.Struct({
114
114
  error: Schema.optional(Schema.NullOr(WireResponseError))
115
115
  });
116
116
  /**
117
- * If an item carries `providerData` from a prior OpenAI turn, re-emit it
118
- * verbatim - preserves `encrypted_content`, item ids, and any field this
119
- * codec doesn't model.
117
+ * The item shapes we stash for round-tripping. Narrower than
118
+ * `WireOutputItem`: the provider-hosted call variants are dropped from the
119
+ * turn, so they are never stored. Composed from the internal `Wire*` structs,
120
+ * which keeps the wire model out of the package's public surface.
120
121
  */
121
- const passthrough = (item) => item.providerData !== void 0 && typeof item.providerData === "object" && item.providerData !== null ? item.providerData : void 0;
122
+ const StoredItem = Schema.Union([
123
+ WireMessage,
124
+ WireFunctionCall,
125
+ WireReasoning
126
+ ]);
127
+ const ProviderDataResponses = Schema.Struct({ responses: StoredItem });
128
+ const decodeResponsesData = Schema.decodeUnknownResult(ProviderDataResponses);
129
+ /**
130
+ * If an item carries `providerData.responses` from a prior turn on this API,
131
+ * re-emit it verbatim - preserves `encrypted_content` and item ids, which a
132
+ * fresh encode from our `HistoryItem` shape cannot reconstruct.
133
+ *
134
+ * Namespaced because `providerData` is a shared slot: an item routed through
135
+ * another provider first (dynamic fallback) carries that provider's key, and
136
+ * re-emitting the whole object would send that provider's data as the wire
137
+ * item and drop the real content. Anything that fails to decode is not ours,
138
+ * so we fall back to encoding the item normally.
139
+ */
140
+ const passthrough = (item) => pipe(decodeResponsesData(item.providerData), Result.match({
141
+ onSuccess: (data) => data.responses,
142
+ onFailure: () => void 0
143
+ }));
122
144
  /**
123
145
  * OpenAI's `input_image` content block carries a single `image_url` field;
124
146
  * inline bytes get encoded as a `data:` URI. Either form (URL or data URI)
@@ -188,21 +210,21 @@ const wireItemToItem = (wire) => Match.value(wire).pipe(Match.discriminatorsExha
188
210
  type: "message",
189
211
  role: m.role,
190
212
  content: m.content.map(wireMessageContentToBlock),
191
- providerData: m
213
+ providerData: { responses: m }
192
214
  }],
193
215
  function_call: (f) => [{
194
216
  type: "function_call",
195
217
  call_id: f.call_id,
196
218
  name: f.name,
197
219
  arguments: f.arguments,
198
- providerData: f
220
+ providerData: { responses: f }
199
221
  }],
200
222
  reasoning: (r) => [{
201
223
  type: "reasoning",
202
224
  ...r.id !== void 0 && { id: r.id },
203
225
  ...r.summary !== void 0 && { summary: r.summary.map((s) => s.text).join("\n") },
204
226
  ...r.encrypted_content !== void 0 && { signature: r.encrypted_content },
205
- providerData: r
227
+ providerData: { responses: r }
206
228
  }],
207
229
  web_search_call: () => [],
208
230
  code_interpreter_call: () => [],
@@ -1 +1 @@
1
- {"version":3,"file":"codec.mjs","names":[],"sources":["../src/codec.ts"],"sourcesContent":["import { Encoding, Match, Option, Schema } from \"effect\"\nimport type { ContentBlock, InputImage, HistoryItem } from \"@effect-uai/core/Items\"\nimport type { Turn } from \"@effect-uai/core/Turn\"\n\n// ---------------------------------------------------------------------------\n// Wire schemas - minimal subset of the Responses API output we consume.\n// Reference: https://www.openresponses.org/specification\n// ---------------------------------------------------------------------------\n\nconst WireUrlCitation = Schema.Struct({\n type: Schema.Literal(\"url_citation\"),\n url: Schema.String,\n start_index: Schema.Number,\n end_index: Schema.Number,\n title: Schema.String,\n})\n\nconst WireFileCitation = Schema.Struct({\n type: Schema.Literal(\"file_citation\"),\n file_id: Schema.String,\n index: Schema.Number,\n})\n\nconst WireContainerFileCitation = Schema.Struct({\n type: Schema.Literal(\"container_file_citation\"),\n container_id: Schema.String,\n file_id: Schema.String,\n start_index: Schema.Number,\n end_index: Schema.Number,\n})\n\nconst WireFilePath = Schema.Struct({\n type: Schema.Literal(\"file_path\"),\n file_id: Schema.String,\n index: Schema.Number,\n})\n\nexport const WireAnnotation = Schema.Union([\n WireUrlCitation,\n WireFileCitation,\n WireContainerFileCitation,\n WireFilePath,\n])\n\nconst WireOutputTextContent = Schema.Struct({\n type: Schema.Literal(\"output_text\"),\n text: Schema.String,\n annotations: Schema.optional(Schema.NullOr(Schema.Array(WireAnnotation))),\n})\n\nconst WireRefusalContent = Schema.Struct({\n type: Schema.Literal(\"refusal\"),\n refusal: Schema.String,\n})\n\nconst WireMessageContent = Schema.Union([WireOutputTextContent, WireRefusalContent])\n\nconst WireSummaryText = Schema.Struct({\n type: Schema.Literal(\"summary_text\"),\n text: Schema.String,\n})\n\nconst WireMessage = Schema.Struct({\n type: Schema.Literal(\"message\"),\n id: Schema.optional(Schema.String),\n role: Schema.Literal(\"assistant\"),\n content: Schema.Array(WireMessageContent),\n})\n\nconst WireFunctionCall = Schema.Struct({\n type: Schema.Literal(\"function_call\"),\n id: Schema.optional(Schema.String),\n call_id: Schema.String,\n name: Schema.String,\n arguments: Schema.String,\n})\n\nconst WireReasoning = Schema.Struct({\n type: Schema.Literal(\"reasoning\"),\n id: Schema.optional(Schema.String),\n summary: Schema.optional(Schema.Array(WireSummaryText)),\n encrypted_content: Schema.optional(Schema.String),\n})\n\n// Provider-hosted tool call items (web search, code interpreter, file search).\n// The provider executes them, not us — we model them only so a grounded\n// `response.completed` still decodes and assembles a Turn; they are dropped\n// from the turn's items in Phase 1. Surfacing them is a follow-up.\nconst WireWebSearchCall = Schema.Struct({\n type: Schema.Literal(\"web_search_call\"),\n id: Schema.optional(Schema.String),\n})\n\nconst WireCodeInterpreterCall = Schema.Struct({\n type: Schema.Literal(\"code_interpreter_call\"),\n id: Schema.optional(Schema.String),\n})\n\nconst WireFileSearchCall = Schema.Struct({\n type: Schema.Literal(\"file_search_call\"),\n id: Schema.optional(Schema.String),\n})\n\nexport const WireOutputItem = Schema.Union([\n WireMessage,\n WireFunctionCall,\n WireReasoning,\n WireWebSearchCall,\n WireCodeInterpreterCall,\n WireFileSearchCall,\n])\nexport type WireOutputItem = typeof WireOutputItem.Type\n\nconst WireInputTokensDetails = Schema.Struct({\n cached_tokens: Schema.optional(Schema.NullOr(Schema.Number)),\n})\n\nconst WireOutputTokensDetails = Schema.Struct({\n reasoning_tokens: Schema.optional(Schema.NullOr(Schema.Number)),\n})\n\nconst WireUsage = Schema.Struct({\n input_tokens: Schema.optional(Schema.Number),\n output_tokens: Schema.optional(Schema.Number),\n total_tokens: Schema.optional(Schema.Number),\n input_tokens_details: Schema.optional(Schema.NullOr(WireInputTokensDetails)),\n output_tokens_details: Schema.optional(Schema.NullOr(WireOutputTokensDetails)),\n})\n\nconst WireResponseError = Schema.Struct({\n code: Schema.optional(Schema.NullOr(Schema.String)),\n message: Schema.optional(Schema.NullOr(Schema.String)),\n})\n\n// Many Responses-API fields are emitted as explicit `null` rather than\n// missing - `Schema.optional` alone (T | undefined) doesn't cover that, so\n// we lift each through `NullOr` first. Used by `response.completed`,\n// `response.incomplete`, and `response.failed` events; not every field is\n// populated on every event (e.g. `error` only on failed, `incomplete_details`\n// only on incomplete).\nexport const WireResponseCompleted = Schema.Struct({\n id: Schema.optional(Schema.NullOr(Schema.String)),\n status: Schema.optional(Schema.NullOr(Schema.String)),\n output: Schema.optional(Schema.NullOr(Schema.Array(WireOutputItem))),\n usage: Schema.optional(Schema.NullOr(WireUsage)),\n incomplete_details: Schema.optional(\n Schema.NullOr(\n Schema.Struct({\n reason: Schema.optional(Schema.NullOr(Schema.String)),\n }),\n ),\n ),\n error: Schema.optional(Schema.NullOr(WireResponseError)),\n})\nexport type WireResponseCompleted = typeof WireResponseCompleted.Type\n\n// ---------------------------------------------------------------------------\n// History → request body input\n// ---------------------------------------------------------------------------\n\n/**\n * If an item carries `providerData` from a prior OpenAI turn, re-emit it\n * verbatim - preserves `encrypted_content`, item ids, and any field this\n * codec doesn't model.\n */\nconst passthrough = (item: HistoryItem): Record<string, unknown> | undefined =>\n item.providerData !== undefined &&\n typeof item.providerData === \"object\" &&\n item.providerData !== null\n ? (item.providerData as Record<string, unknown>)\n : undefined\n\n/**\n * OpenAI's `input_image` content block carries a single `image_url` field;\n * inline bytes get encoded as a `data:` URI. Either form (URL or data URI)\n * is fine - the model just dereferences `image_url`.\n */\nconst imageSourceToUrl = Match.type<InputImage[\"source\"]>().pipe(\n Match.tag(\"url\", (s) => s.url),\n Match.tag(\"base64\", (s) => `data:${s.mimeType};base64,${s.base64}`),\n Match.tag(\"bytes\", (s) => `data:${s.mimeType};base64,${Encoding.encodeBase64(s.bytes)}`),\n Match.exhaustive,\n)\n\nconst contentBlockToInput = Match.type<ContentBlock>().pipe(\n Match.discriminatorsExhaustive(\"type\")({\n input_text: (b) => ({ type: \"input_text\", text: b.text }),\n input_image: (b) => ({\n type: \"input_image\",\n image_url: imageSourceToUrl(b.source),\n }),\n output_text: (b) => ({ type: \"output_text\", text: b.text }),\n refusal: (b) => ({ type: \"refusal\", refusal: b.text }),\n }),\n)\n\nconst itemToInput = (item: HistoryItem): Record<string, unknown> =>\n passthrough(item) ??\n Match.value(item).pipe(\n Match.discriminatorsExhaustive(\"type\")({\n message: (m) => ({\n type: \"message\",\n role: m.role,\n content: m.content.map(contentBlockToInput),\n }),\n function_call: (f) => ({\n type: \"function_call\",\n call_id: f.call_id,\n name: f.name,\n arguments: f.arguments,\n }),\n function_call_output: (o) => ({\n type: \"function_call_output\",\n call_id: o.call_id,\n output: o.output,\n }),\n reasoning: (r) => ({\n type: \"reasoning\",\n ...(r.id !== undefined && { id: r.id }),\n ...(r.summary !== undefined && {\n summary: [{ type: \"summary_text\", text: r.summary }],\n }),\n ...(r.signature !== undefined && { encrypted_content: r.signature }),\n }),\n }),\n )\n\n/** Convert our `HistoryItem[]` history into the Responses API `input` array. */\nexport const itemsToInput = (\n items: ReadonlyArray<HistoryItem>,\n): ReadonlyArray<Record<string, unknown>> => items.map(itemToInput)\n\n// ---------------------------------------------------------------------------\n// Wire output items → our Items\n// ---------------------------------------------------------------------------\n\nconst wireMessageContentToBlock = Match.type<typeof WireMessageContent.Type>().pipe(\n Match.discriminatorsExhaustive(\"type\")({\n output_text: (c): ContentBlock => ({\n type: \"output_text\",\n text: c.text,\n ...(c.annotations !== undefined && c.annotations !== null && { annotations: c.annotations }),\n }),\n refusal: (c): ContentBlock => ({ type: \"refusal\", text: c.refusal }),\n }),\n)\n\nexport const wireItemToItem = (wire: WireOutputItem): ReadonlyArray<HistoryItem> =>\n Match.value(wire).pipe(\n Match.discriminatorsExhaustive(\"type\")({\n message: (m): ReadonlyArray<HistoryItem> => [\n {\n type: \"message\" as const,\n role: m.role,\n content: m.content.map(wireMessageContentToBlock),\n providerData: m,\n },\n ],\n function_call: (f): ReadonlyArray<HistoryItem> => [\n {\n type: \"function_call\" as const,\n call_id: f.call_id,\n name: f.name,\n arguments: f.arguments,\n providerData: f,\n },\n ],\n reasoning: (r): ReadonlyArray<HistoryItem> => [\n {\n type: \"reasoning\" as const,\n ...(r.id !== undefined && { id: r.id }),\n ...(r.summary !== undefined && {\n summary: r.summary.map((s) => s.text).join(\"\\n\"),\n }),\n ...(r.encrypted_content !== undefined && { signature: r.encrypted_content }),\n providerData: r,\n },\n ],\n // Hosted-tool calls are provider-executed; drop from the turn (Phase 1).\n web_search_call: (): ReadonlyArray<HistoryItem> => [],\n code_interpreter_call: (): ReadonlyArray<HistoryItem> => [],\n file_search_call: (): ReadonlyArray<HistoryItem> => [],\n }),\n )\n\n// ---------------------------------------------------------------------------\n// response.completed → Turn\n// ---------------------------------------------------------------------------\n\nconst reasonToStop = Match.type<string>().pipe(\n Match.when(\"max_output_tokens\", () => \"max_tokens\" as const),\n Match.when(\"refusal\", () => \"refusal\" as const),\n Match.when(\"content_filter\", () => \"content_filter\" as const),\n Match.when(\"max_tool_calls\", () => \"max_tool_calls\" as const),\n Match.option,\n)\n\nconst hasRefusalContent = (payload: WireResponseCompleted): boolean =>\n (payload.output ?? []).some(\n (i) => i.type === \"message\" && i.content.some((c) => c.type === \"refusal\"),\n )\n\nconst stopReasonFromCompleted = (payload: WireResponseCompleted): Turn[\"stop_reason\"] =>\n Option.match(reasonToStop(payload.incomplete_details?.reason ?? \"\"), {\n onSome: (s) => s,\n onNone: () =>\n hasRefusalContent(payload)\n ? (\"refusal\" as const)\n : (payload.output ?? []).some((i) => i.type === \"function_call\")\n ? (\"tool_calls\" as const)\n : (\"stop\" as const),\n })\n\nconst cachedTokens = (payload: WireResponseCompleted): number | undefined =>\n payload.usage?.input_tokens_details?.cached_tokens ?? undefined\n\nconst reasoningTokens = (payload: WireResponseCompleted): number | undefined =>\n payload.usage?.output_tokens_details?.reasoning_tokens ?? undefined\n\nexport const turnFromCompleted = (payload: WireResponseCompleted): Turn => {\n const cached = cachedTokens(payload)\n const reasoning = reasoningTokens(payload)\n return {\n items: (payload.output ?? []).flatMap(wireItemToItem),\n usage: {\n ...(payload.usage?.input_tokens !== undefined && {\n input_tokens: payload.usage.input_tokens,\n }),\n ...(payload.usage?.output_tokens !== undefined && {\n output_tokens: payload.usage.output_tokens,\n }),\n ...(payload.usage?.total_tokens !== undefined && {\n total_tokens: payload.usage.total_tokens,\n }),\n ...(cached !== undefined && {\n input_tokens_details: { cached_tokens: cached },\n }),\n ...(reasoning !== undefined && {\n output_tokens_details: { reasoning_tokens: reasoning },\n }),\n },\n stop_reason: stopReasonFromCompleted(payload),\n }\n}\n"],"mappings":";;;;;;;;;;;AASA,MAAM,kBAAkB,OAAO,OAAO;CACpC,MAAM,OAAO,QAAQ,eAAe;CACpC,KAAK,OAAO;CACZ,aAAa,OAAO;CACpB,WAAW,OAAO;CAClB,OAAO,OAAO;CACf,CAAC;AAEF,MAAM,mBAAmB,OAAO,OAAO;CACrC,MAAM,OAAO,QAAQ,gBAAgB;CACrC,SAAS,OAAO;CAChB,OAAO,OAAO;CACf,CAAC;AAEF,MAAM,4BAA4B,OAAO,OAAO;CAC9C,MAAM,OAAO,QAAQ,0BAA0B;CAC/C,cAAc,OAAO;CACrB,SAAS,OAAO;CAChB,aAAa,OAAO;CACpB,WAAW,OAAO;CACnB,CAAC;AAEF,MAAM,eAAe,OAAO,OAAO;CACjC,MAAM,OAAO,QAAQ,YAAY;CACjC,SAAS,OAAO;CAChB,OAAO,OAAO;CACf,CAAC;AAEF,MAAa,iBAAiB,OAAO,MAAM;CACzC;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,wBAAwB,OAAO,OAAO;CAC1C,MAAM,OAAO,QAAQ,cAAc;CACnC,MAAM,OAAO;CACb,aAAa,OAAO,SAAS,OAAO,OAAO,OAAO,MAAM,eAAe,CAAC,CAAC;CAC1E,CAAC;AAEF,MAAM,qBAAqB,OAAO,OAAO;CACvC,MAAM,OAAO,QAAQ,UAAU;CAC/B,SAAS,OAAO;CACjB,CAAC;AAEF,MAAM,qBAAqB,OAAO,MAAM,CAAC,uBAAuB,mBAAmB,CAAC;AAEpF,MAAM,kBAAkB,OAAO,OAAO;CACpC,MAAM,OAAO,QAAQ,eAAe;CACpC,MAAM,OAAO;CACd,CAAC;AAEF,MAAM,cAAc,OAAO,O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AAA;AAExD,MAAM,mBAAmB,YACvB,QAAQ,OAAO,uBAAuB,oBAAoB,KAAA;AAE5D,MAAa,qBAAqB,YAAyC;CACzE,MAAM,SAAS,aAAa,QAAQ;CACpC,MAAM,YAAY,gBAAgB,QAAQ;AAC1C,QAAO;EACL,QAAQ,QAAQ,UAAU,EAAE,EAAE,QAAQ,eAAe;EACrD,OAAO;GACL,GAAI,QAAQ,OAAO,iBAAiB,KAAA,KAAa,EAC/C,cAAc,QAAQ,MAAM,cAC7B;GACD,GAAI,QAAQ,OAAO,kBAAkB,KAAA,KAAa,EAChD,eAAe,QAAQ,MAAM,eAC9B;GACD,GAAI,QAAQ,OAAO,iBAAiB,KAAA,KAAa,EAC/C,cAAc,QAAQ,MAAM,cAC7B;GACD,GAAI,WAAW,KAAA,KAAa,EAC1B,sBAAsB,EAAE,eAAe,QAAQ,EAChD;GACD,GAAI,cAAc,KAAA,KAAa,EAC7B,uBAAuB,EAAE,kBAAkB,WAAW,EACvD;GACF;EACD,aAAa,wBAAwB,QAAQ;EAC9C"}
1
+ {"version":3,"file":"codec.mjs","names":[],"sources":["../src/codec.ts"],"sourcesContent":["import { Encoding, Match, Option, Result, Schema, pipe } from \"effect\"\nimport type { ContentBlock, InputImage, HistoryItem } from \"@effect-uai/core/Items\"\nimport type { Turn } from \"@effect-uai/core/Turn\"\n\n// ---------------------------------------------------------------------------\n// Wire schemas - minimal subset of the Responses API output we consume.\n// Reference: https://www.openresponses.org/specification\n// ---------------------------------------------------------------------------\n\nconst WireUrlCitation = Schema.Struct({\n type: Schema.Literal(\"url_citation\"),\n url: Schema.String,\n start_index: Schema.Number,\n end_index: Schema.Number,\n title: Schema.String,\n})\n\nconst WireFileCitation = Schema.Struct({\n type: Schema.Literal(\"file_citation\"),\n file_id: Schema.String,\n index: Schema.Number,\n})\n\nconst WireContainerFileCitation = Schema.Struct({\n type: Schema.Literal(\"container_file_citation\"),\n container_id: Schema.String,\n file_id: Schema.String,\n start_index: Schema.Number,\n end_index: Schema.Number,\n})\n\nconst WireFilePath = Schema.Struct({\n type: Schema.Literal(\"file_path\"),\n file_id: Schema.String,\n index: Schema.Number,\n})\n\nexport const WireAnnotation = Schema.Union([\n WireUrlCitation,\n WireFileCitation,\n WireContainerFileCitation,\n WireFilePath,\n])\n\nconst WireOutputTextContent = Schema.Struct({\n type: Schema.Literal(\"output_text\"),\n text: Schema.String,\n annotations: Schema.optional(Schema.NullOr(Schema.Array(WireAnnotation))),\n})\n\nconst WireRefusalContent = Schema.Struct({\n type: Schema.Literal(\"refusal\"),\n refusal: Schema.String,\n})\n\nconst WireMessageContent = Schema.Union([WireOutputTextContent, WireRefusalContent])\n\nconst WireSummaryText = Schema.Struct({\n type: Schema.Literal(\"summary_text\"),\n text: Schema.String,\n})\n\nconst WireMessage = Schema.Struct({\n type: Schema.Literal(\"message\"),\n id: Schema.optional(Schema.String),\n role: Schema.Literal(\"assistant\"),\n content: Schema.Array(WireMessageContent),\n})\n\nconst WireFunctionCall = Schema.Struct({\n type: Schema.Literal(\"function_call\"),\n id: Schema.optional(Schema.String),\n call_id: Schema.String,\n name: Schema.String,\n arguments: Schema.String,\n})\n\nconst WireReasoning = Schema.Struct({\n type: Schema.Literal(\"reasoning\"),\n id: Schema.optional(Schema.String),\n summary: Schema.optional(Schema.Array(WireSummaryText)),\n encrypted_content: Schema.optional(Schema.String),\n})\n\n// Provider-hosted tool call items (web search, code interpreter, file search).\n// The provider executes them, not us — we model them only so a grounded\n// `response.completed` still decodes and assembles a Turn; they are dropped\n// from the turn's items in Phase 1. Surfacing them is a follow-up.\nconst WireWebSearchCall = Schema.Struct({\n type: Schema.Literal(\"web_search_call\"),\n id: Schema.optional(Schema.String),\n})\n\nconst WireCodeInterpreterCall = Schema.Struct({\n type: Schema.Literal(\"code_interpreter_call\"),\n id: Schema.optional(Schema.String),\n})\n\nconst WireFileSearchCall = Schema.Struct({\n type: Schema.Literal(\"file_search_call\"),\n id: Schema.optional(Schema.String),\n})\n\nexport const WireOutputItem = Schema.Union([\n WireMessage,\n WireFunctionCall,\n WireReasoning,\n WireWebSearchCall,\n WireCodeInterpreterCall,\n WireFileSearchCall,\n])\nexport type WireOutputItem = typeof WireOutputItem.Type\n\nconst WireInputTokensDetails = Schema.Struct({\n cached_tokens: Schema.optional(Schema.NullOr(Schema.Number)),\n})\n\nconst WireOutputTokensDetails = Schema.Struct({\n reasoning_tokens: Schema.optional(Schema.NullOr(Schema.Number)),\n})\n\nconst WireUsage = Schema.Struct({\n input_tokens: Schema.optional(Schema.Number),\n output_tokens: Schema.optional(Schema.Number),\n total_tokens: Schema.optional(Schema.Number),\n input_tokens_details: Schema.optional(Schema.NullOr(WireInputTokensDetails)),\n output_tokens_details: Schema.optional(Schema.NullOr(WireOutputTokensDetails)),\n})\n\nconst WireResponseError = Schema.Struct({\n code: Schema.optional(Schema.NullOr(Schema.String)),\n message: Schema.optional(Schema.NullOr(Schema.String)),\n})\n\n// Many Responses-API fields are emitted as explicit `null` rather than\n// missing - `Schema.optional` alone (T | undefined) doesn't cover that, so\n// we lift each through `NullOr` first. Used by `response.completed`,\n// `response.incomplete`, and `response.failed` events; not every field is\n// populated on every event (e.g. `error` only on failed, `incomplete_details`\n// only on incomplete).\nexport const WireResponseCompleted = Schema.Struct({\n id: Schema.optional(Schema.NullOr(Schema.String)),\n status: Schema.optional(Schema.NullOr(Schema.String)),\n output: Schema.optional(Schema.NullOr(Schema.Array(WireOutputItem))),\n usage: Schema.optional(Schema.NullOr(WireUsage)),\n incomplete_details: Schema.optional(\n Schema.NullOr(\n Schema.Struct({\n reason: Schema.optional(Schema.NullOr(Schema.String)),\n }),\n ),\n ),\n error: Schema.optional(Schema.NullOr(WireResponseError)),\n})\nexport type WireResponseCompleted = typeof WireResponseCompleted.Type\n\n// ---------------------------------------------------------------------------\n// History → request body input\n// ---------------------------------------------------------------------------\n\n/**\n * The item shapes we stash for round-tripping. Narrower than\n * `WireOutputItem`: the provider-hosted call variants are dropped from the\n * turn, so they are never stored. Composed from the internal `Wire*` structs,\n * which keeps the wire model out of the package's public surface.\n */\nconst StoredItem = Schema.Union([WireMessage, WireFunctionCall, WireReasoning])\ntype StoredItem = typeof StoredItem.Type\n\nconst ProviderDataResponses = Schema.Struct({ responses: StoredItem })\nconst decodeResponsesData = Schema.decodeUnknownResult(ProviderDataResponses)\n\n/**\n * If an item carries `providerData.responses` from a prior turn on this API,\n * re-emit it verbatim - preserves `encrypted_content` and item ids, which a\n * fresh encode from our `HistoryItem` shape cannot reconstruct.\n *\n * Namespaced because `providerData` is a shared slot: an item routed through\n * another provider first (dynamic fallback) carries that provider's key, and\n * re-emitting the whole object would send that provider's data as the wire\n * item and drop the real content. Anything that fails to decode is not ours,\n * so we fall back to encoding the item normally.\n */\nconst passthrough = (item: HistoryItem): StoredItem | undefined =>\n pipe(\n decodeResponsesData(item.providerData),\n Result.match({\n onSuccess: (data) => data.responses,\n onFailure: (): StoredItem | undefined => undefined,\n }),\n )\n\n/**\n * OpenAI's `input_image` content block carries a single `image_url` field;\n * inline bytes get encoded as a `data:` URI. Either form (URL or data URI)\n * is fine - the model just dereferences `image_url`.\n */\nconst imageSourceToUrl = Match.type<InputImage[\"source\"]>().pipe(\n Match.tag(\"url\", (s) => s.url),\n Match.tag(\"base64\", (s) => `data:${s.mimeType};base64,${s.base64}`),\n Match.tag(\"bytes\", (s) => `data:${s.mimeType};base64,${Encoding.encodeBase64(s.bytes)}`),\n Match.exhaustive,\n)\n\nconst contentBlockToInput = Match.type<ContentBlock>().pipe(\n Match.discriminatorsExhaustive(\"type\")({\n input_text: (b) => ({ type: \"input_text\", text: b.text }),\n input_image: (b) => ({\n type: \"input_image\",\n image_url: imageSourceToUrl(b.source),\n }),\n output_text: (b) => ({ type: \"output_text\", text: b.text }),\n refusal: (b) => ({ type: \"refusal\", refusal: b.text }),\n }),\n)\n\nconst itemToInput = (item: HistoryItem): Record<string, unknown> =>\n passthrough(item) ??\n Match.value(item).pipe(\n Match.discriminatorsExhaustive(\"type\")({\n message: (m) => ({\n type: \"message\",\n role: m.role,\n content: m.content.map(contentBlockToInput),\n }),\n function_call: (f) => ({\n type: \"function_call\",\n call_id: f.call_id,\n name: f.name,\n arguments: f.arguments,\n }),\n function_call_output: (o) => ({\n type: \"function_call_output\",\n call_id: o.call_id,\n output: o.output,\n }),\n reasoning: (r) => ({\n type: \"reasoning\",\n ...(r.id !== undefined && { id: r.id }),\n ...(r.summary !== undefined && {\n summary: [{ type: \"summary_text\", text: r.summary }],\n }),\n ...(r.signature !== undefined && { encrypted_content: r.signature }),\n }),\n }),\n )\n\n/** Convert our `HistoryItem[]` history into the Responses API `input` array. */\nexport const itemsToInput = (\n items: ReadonlyArray<HistoryItem>,\n): ReadonlyArray<Record<string, unknown>> => items.map(itemToInput)\n\n// ---------------------------------------------------------------------------\n// Wire output items → our Items\n// ---------------------------------------------------------------------------\n\nconst wireMessageContentToBlock = Match.type<typeof WireMessageContent.Type>().pipe(\n Match.discriminatorsExhaustive(\"type\")({\n output_text: (c): ContentBlock => ({\n type: \"output_text\",\n text: c.text,\n ...(c.annotations !== undefined && c.annotations !== null && { annotations: c.annotations }),\n }),\n refusal: (c): ContentBlock => ({ type: \"refusal\", text: c.refusal }),\n }),\n)\n\nexport const wireItemToItem = (wire: WireOutputItem): ReadonlyArray<HistoryItem> =>\n Match.value(wire).pipe(\n Match.discriminatorsExhaustive(\"type\")({\n message: (m): ReadonlyArray<HistoryItem> => [\n {\n type: \"message\" as const,\n role: m.role,\n content: m.content.map(wireMessageContentToBlock),\n providerData: { responses: m },\n },\n ],\n function_call: (f): ReadonlyArray<HistoryItem> => [\n {\n type: \"function_call\" as const,\n call_id: f.call_id,\n name: f.name,\n arguments: f.arguments,\n providerData: { responses: f },\n },\n ],\n reasoning: (r): ReadonlyArray<HistoryItem> => [\n {\n type: \"reasoning\" as const,\n ...(r.id !== undefined && { id: r.id }),\n ...(r.summary !== undefined && {\n summary: r.summary.map((s) => s.text).join(\"\\n\"),\n }),\n ...(r.encrypted_content !== undefined && { signature: r.encrypted_content }),\n providerData: { responses: r },\n },\n ],\n // Hosted-tool calls are provider-executed; drop from the turn (Phase 1).\n web_search_call: (): ReadonlyArray<HistoryItem> => [],\n code_interpreter_call: (): ReadonlyArray<HistoryItem> => [],\n file_search_call: (): ReadonlyArray<HistoryItem> => [],\n }),\n )\n\n// ---------------------------------------------------------------------------\n// response.completed → Turn\n// ---------------------------------------------------------------------------\n\nconst reasonToStop = Match.type<string>().pipe(\n Match.when(\"max_output_tokens\", () => \"max_tokens\" as const),\n Match.when(\"refusal\", () => \"refusal\" as const),\n Match.when(\"content_filter\", () => \"content_filter\" as const),\n Match.when(\"max_tool_calls\", () => \"max_tool_calls\" as const),\n Match.option,\n)\n\nconst hasRefusalContent = (payload: WireResponseCompleted): boolean =>\n (payload.output ?? []).some(\n (i) => i.type === \"message\" && i.content.some((c) => c.type === \"refusal\"),\n )\n\nconst stopReasonFromCompleted = (payload: WireResponseCompleted): Turn[\"stop_reason\"] =>\n Option.match(reasonToStop(payload.incomplete_details?.reason ?? \"\"), {\n onSome: (s) => s,\n onNone: () =>\n hasRefusalContent(payload)\n ? (\"refusal\" as const)\n : (payload.output ?? []).some((i) => i.type === \"function_call\")\n ? (\"tool_calls\" as const)\n : (\"stop\" as const),\n })\n\nconst cachedTokens = (payload: WireResponseCompleted): number | undefined =>\n payload.usage?.input_tokens_details?.cached_tokens ?? undefined\n\nconst reasoningTokens = (payload: WireResponseCompleted): number | undefined =>\n payload.usage?.output_tokens_details?.reasoning_tokens ?? undefined\n\nexport const turnFromCompleted = (payload: WireResponseCompleted): Turn => {\n const cached = cachedTokens(payload)\n const reasoning = reasoningTokens(payload)\n return {\n items: (payload.output ?? []).flatMap(wireItemToItem),\n usage: {\n ...(payload.usage?.input_tokens !== undefined && {\n input_tokens: payload.usage.input_tokens,\n }),\n ...(payload.usage?.output_tokens !== undefined && {\n output_tokens: payload.usage.output_tokens,\n }),\n ...(payload.usage?.total_tokens !== undefined && {\n total_tokens: payload.usage.total_tokens,\n }),\n ...(cached !== undefined && {\n input_tokens_details: { cached_tokens: cached },\n }),\n ...(reasoning !== undefined && {\n output_tokens_details: { reasoning_tokens: reasoning },\n }),\n },\n stop_reason: stopReasonFromCompleted(payload),\n }\n}\n"],"mappings":";;;;;;;;;;;AASA,MAAM,kBAAkB,OAAO,OAAO;CACpC,MAAM,OAAO,QAAQ,cAAc;CACnC,KAAK,OAAO;CACZ,aAAa,OAAO;CACpB,WAAW,OAAO;CAClB,OAAO,OAAO;AAChB,CAAC;AAED,MAAM,mBAAmB,OAAO,OAAO;CACrC,MAAM,OAAO,QAAQ,eAAe;CACpC,SAAS,OAAO;CAChB,OAAO,OAAO;AAChB,CAAC;AAED,MAAM,4BAA4B,OAAO,OAAO;CAC9C,MAAM,OAAO,QAAQ,yBAAyB;CAC9C,cAAc,OAAO;CACrB,SAAS,OAAO;CAChB,aAAa,OAAO;CACpB,WAAW,OAAO;AACpB,CAAC;AAED,MAAM,eAAe,OAAO,OAAO;CACjC,MAAM,OAAO,QAAQ,WAAW;CAChC,SAAS,OAAO;CAChB,OAAO,OAAO;AAChB,CAAC;AAED,MAAa,iBAAiB,OAAO,MAAM;CACzC;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,wBAAwB,OAAO,OAAO;CAC1C,MAAM,OAAO,QAAQ,aAAa;CAClC,MAAM,OAAO;CACb,aAAa,OAAO,SAAS,OAAO,OAAO,OAAO,MAAM,cAAc,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,qBAAqB,OAAO,OAAO;CACvC,MAAM,OAAO,QAAQ,SAAS;CAC9B,SAAS,OAAO;AAClB,CAAC;AAED,MAAM,qBAAqB,OAAO,MAAM,CAAC,uBAAuB,kBAAkB,CAAC;AAEnF,MAAM,kBAAkB,OAAO,OAAO;CACpC,MAAM,OAAO,QAAQ,cAAc;CACnC,MAAM,OAAO;AACf,CAAC;AAED,MAAM,cAAc,OAAO,OAAO;CAChC,MAAM,OAAO,QAAQ,SAAS;CAC9B,IAAI,OA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AEF,MAAM,2BAA2B,YAC/B,OAAO,MAAM,aAAa,QAAQ,oBAAoB,UAAU,EAAE,GAAG;CACnE,SAAS,MAAM;CACf,cACE,kBAAkB,OAAO,IACpB,aACA,QAAQ,UAAU,CAAC,EAAA,CAAG,MAAM,MAAM,EAAE,SAAS,eAAe,IAC1D,eACA;AACX,CAAC;AAEH,MAAM,gBAAgB,YACpB,QAAQ,OAAO,sBAAsB,iBAAiB,KAAA;AAExD,MAAM,mBAAmB,YACvB,QAAQ,OAAO,uBAAuB,oBAAoB,KAAA;AAE5D,MAAa,qBAAqB,YAAyC;CACzE,MAAM,SAAS,aAAa,OAAO;CACnC,MAAM,YAAY,gBAAgB,OAAO;CACzC,OAAO;EACL,QAAQ,QAAQ,UAAU,CAAC,EAAA,CAAG,QAAQ,cAAc;EACpD,OAAO;GACL,GAAI,QAAQ,OAAO,iBAAiB,KAAA,KAAa,EAC/C,cAAc,QAAQ,MAAM,aAC9B;GACA,GAAI,QAAQ,OAAO,kBAAkB,KAAA,KAAa,EAChD,eAAe,QAAQ,MAAM,cAC/B;GACA,GAAI,QAAQ,OAAO,iBAAiB,KAAA,KAAa,EAC/C,cAAc,QAAQ,MAAM,aAC9B;GACA,GAAI,WAAW,KAAA,KAAa,EAC1B,sBAAsB,EAAE,eAAe,OAAO,EAChD;GACA,GAAI,cAAc,KAAA,KAAa,EAC7B,uBAAuB,EAAE,kBAAkB,UAAU,EACvD;EACF;EACA,aAAa,wBAAwB,OAAO;CAC9C;AACF"}
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,94 @@
1
+ import { itemsToInput, wireItemToItem } from "./codec.mjs";
2
+ import { n as describe, r as it, t as globalExpect } from "./test.DNmyFkvJ-N3QqMRwZ.mjs";
3
+ //#region src/codec.test.ts
4
+ describe("providerData round-trip", () => {
5
+ it("re-emits a stashed item verbatim, preserving fields our shape drops", () => {
6
+ const items = wireItemToItem({
7
+ type: "reasoning",
8
+ id: "rs_1",
9
+ encrypted_content: "opaque-state"
10
+ });
11
+ globalExpect(itemsToInput(items)).toEqual([{
12
+ type: "reasoning",
13
+ id: "rs_1",
14
+ encrypted_content: "opaque-state"
15
+ }]);
16
+ });
17
+ });
18
+ describe("providerData is a shared slot", () => {
19
+ it("ignores another provider's data and encodes the item normally", () => {
20
+ globalExpect(itemsToInput([{
21
+ type: "message",
22
+ role: "user",
23
+ content: [{
24
+ type: "input_text",
25
+ text: "hello world"
26
+ }],
27
+ providerData: { gemini: { thoughtSignature: "sig-abc" } }
28
+ }])).toEqual([{
29
+ type: "message",
30
+ role: "user",
31
+ content: [{
32
+ type: "input_text",
33
+ text: "hello world"
34
+ }]
35
+ }]);
36
+ });
37
+ it("does not send a foreign function_call as junk", () => {
38
+ globalExpect(itemsToInput([{
39
+ type: "function_call",
40
+ call_id: "c1",
41
+ name: "get_weather",
42
+ arguments: "{\"city\":\"Lisbon\"}",
43
+ providerData: { gemini: {
44
+ id: "g1",
45
+ thoughtSignature: "sig-abc"
46
+ } }
47
+ }])).toEqual([{
48
+ type: "function_call",
49
+ call_id: "c1",
50
+ name: "get_weather",
51
+ arguments: "{\"city\":\"Lisbon\"}"
52
+ }]);
53
+ });
54
+ it("re-emits only our key when an item carries several providers' data", () => {
55
+ globalExpect(itemsToInput([{
56
+ type: "reasoning",
57
+ signature: "opaque-state",
58
+ providerData: {
59
+ responses: {
60
+ type: "reasoning",
61
+ id: "rs_1",
62
+ encrypted_content: "opaque-state"
63
+ },
64
+ gemini: { thoughtSignature: "sig-abc" }
65
+ }
66
+ }])).toEqual([{
67
+ type: "reasoning",
68
+ id: "rs_1",
69
+ encrypted_content: "opaque-state"
70
+ }]);
71
+ });
72
+ it("falls back to a normal encode when the stashed value is not one of ours", () => {
73
+ globalExpect(itemsToInput([{
74
+ type: "message",
75
+ role: "user",
76
+ content: [{
77
+ type: "input_text",
78
+ text: "hi"
79
+ }],
80
+ providerData: { responses: { type: "not_an_item_we_model" } }
81
+ }])).toEqual([{
82
+ type: "message",
83
+ role: "user",
84
+ content: [{
85
+ type: "input_text",
86
+ text: "hi"
87
+ }]
88
+ }]);
89
+ });
90
+ });
91
+ //#endregion
92
+ export {};
93
+
94
+ //# sourceMappingURL=codec.test.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.test.mjs","names":[],"sources":["../src/codec.test.ts"],"sourcesContent":["import type { HistoryItem } from \"@effect-uai/core/Items\"\nimport { describe, expect, it } from \"vitest\"\nimport { itemsToInput, wireItemToItem } from \"./codec.js\"\n\ndescribe(\"providerData round-trip\", () => {\n it(\"re-emits a stashed item verbatim, preserving fields our shape drops\", () => {\n // `id` and `encrypted_content` cannot be reconstructed from a Reasoning\n // item, so the round-trip has to go through the stash.\n const items = wireItemToItem({\n type: \"reasoning\",\n id: \"rs_1\",\n encrypted_content: \"opaque-state\",\n })\n expect(itemsToInput(items)).toEqual([\n { type: \"reasoning\", id: \"rs_1\", encrypted_content: \"opaque-state\" },\n ])\n })\n})\n\ndescribe(\"providerData is a shared slot\", () => {\n // Regression: the passthrough used to re-emit the whole `providerData`\n // object as the wire item. An item that had been through another provider\n // first was sent as that provider's data, losing the real content.\n it(\"ignores another provider's data and encodes the item normally\", () => {\n const history: ReadonlyArray<HistoryItem> = [\n {\n type: \"message\",\n role: \"user\",\n content: [{ type: \"input_text\", text: \"hello world\" }],\n providerData: { gemini: { thoughtSignature: \"sig-abc\" } },\n },\n ]\n expect(itemsToInput(history)).toEqual([\n { type: \"message\", role: \"user\", content: [{ type: \"input_text\", text: \"hello world\" }] },\n ])\n })\n\n it(\"does not send a foreign function_call as junk\", () => {\n const history: ReadonlyArray<HistoryItem> = [\n {\n type: \"function_call\",\n call_id: \"c1\",\n name: \"get_weather\",\n arguments: '{\"city\":\"Lisbon\"}',\n providerData: { gemini: { id: \"g1\", thoughtSignature: \"sig-abc\" } },\n },\n ]\n expect(itemsToInput(history)).toEqual([\n {\n type: \"function_call\",\n call_id: \"c1\",\n name: \"get_weather\",\n arguments: '{\"city\":\"Lisbon\"}',\n },\n ])\n })\n\n it(\"re-emits only our key when an item carries several providers' data\", () => {\n const history: ReadonlyArray<HistoryItem> = [\n {\n type: \"reasoning\",\n signature: \"opaque-state\",\n providerData: {\n responses: { type: \"reasoning\", id: \"rs_1\", encrypted_content: \"opaque-state\" },\n gemini: { thoughtSignature: \"sig-abc\" },\n },\n },\n ]\n expect(itemsToInput(history)).toEqual([\n { type: \"reasoning\", id: \"rs_1\", encrypted_content: \"opaque-state\" },\n ])\n })\n\n it(\"falls back to a normal encode when the stashed value is not one of ours\", () => {\n const history: ReadonlyArray<HistoryItem> = [\n {\n type: \"message\",\n role: \"user\",\n content: [{ type: \"input_text\", text: \"hi\" }],\n providerData: { responses: { type: \"not_an_item_we_model\" } },\n },\n ]\n expect(itemsToInput(history)).toEqual([\n { type: \"message\", role: \"user\", content: [{ type: \"input_text\", text: \"hi\" }] },\n ])\n })\n})\n"],"mappings":";;;AAIA,SAAS,iCAAiC;CACxC,GAAG,6EAA6E;EAG9E,MAAM,QAAQ,eAAe;GAC3B,MAAM;GACN,IAAI;GACJ,mBAAmB;EACrB,CAAC;EACD,aAAO,aAAa,KAAK,CAAC,CAAC,CAAC,QAAQ,CAClC;GAAE,MAAM;GAAa,IAAI;GAAQ,mBAAmB;EAAe,CACrE,CAAC;CACH,CAAC;AACH,CAAC;AAED,SAAS,uCAAuC;CAI9C,GAAG,uEAAuE;EASxE,aAAO,aAAa,CAPlB;GACE,MAAM;GACN,MAAM;GACN,SAAS,CAAC;IAAE,MAAM;IAAc,MAAM;GAAc,CAAC;GACrD,cAAc,EAAE,QAAQ,EAAE,kBAAkB,UAAU,EAAE;EAC1D,CAEwB,CAAC,CAAC,CAAC,CAAC,QAAQ,CACpC;GAAE,MAAM;GAAW,MAAM;GAAQ,SAAS,CAAC;IAAE,MAAM;IAAc,MAAM;GAAc,CAAC;EAAE,CAC1F,CAAC;CACH,CAAC;CAED,GAAG,uDAAuD;EAUxD,aAAO,aAAa,CARlB;GACE,MAAM;GACN,SAAS;GACT,MAAM;GACN,WAAW;GACX,cAAc,EAAE,QAAQ;IAAE,IAAI;IAAM,kBAAkB;GAAU,EAAE;EACpE,CAEwB,CAAC,CAAC,CAAC,CAAC,QAAQ,CACpC;GACE,MAAM;GACN,SAAS;GACT,MAAM;GACN,WAAW;EACb,CACF,CAAC;CACH,CAAC;CAED,GAAG,4EAA4E;EAW7E,aAAO,aAAa,CATlB;GACE,MAAM;GACN,WAAW;GACX,cAAc;IACZ,WAAW;KAAE,MAAM;KAAa,IAAI;KAAQ,mBAAmB;IAAe;IAC9E,QAAQ,EAAE,kBAAkB,UAAU;GACxC;EACF,CAEwB,CAAC,CAAC,CAAC,CAAC,QAAQ,CACpC;GAAE,MAAM;GAAa,IAAI;GAAQ,mBAAmB;EAAe,CACrE,CAAC;CACH,CAAC;CAED,GAAG,iFAAiF;EASlF,aAAO,aAAa,CAPlB;GACE,MAAM;GACN,MAAM;GACN,SAAS,CAAC;IAAE,MAAM;IAAc,MAAM;GAAK,CAAC;GAC5C,cAAc,EAAE,WAAW,EAAE,MAAM,uBAAuB,EAAE;EAC9D,CAEwB,CAAC,CAAC,CAAC,CAAC,QAAQ,CACpC;GAAE,MAAM;GAAW,MAAM;GAAQ,SAAS,CAAC;IAAE,MAAM;IAAc,MAAM;GAAK,CAAC;EAAE,CACjF,CAAC;CACH,CAAC;AACH,CAAC"}
@@ -2,8 +2,8 @@
2
2
  var comma = ",".charCodeAt(0);
3
3
  var semicolon = ";".charCodeAt(0);
4
4
  var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
5
- var intToChar = new Uint8Array(64);
6
- var charToInt = new Uint8Array(128);
5
+ var intToChar = /* @__PURE__ */ new Uint8Array(64);
6
+ var charToInt = /* @__PURE__ */ new Uint8Array(128);
7
7
  for (let i = 0; i < chars.length; i++) {
8
8
  const c = chars.charCodeAt(i);
9
9
  intToChar[i] = c;
@@ -20,7 +20,7 @@ function encodeInteger(builder, num, relative) {
20
20
  } while (delta > 0);
21
21
  return num;
22
22
  }
23
- var bufLength = 1024 * 16;
23
+ var bufLength = 16384;
24
24
  var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? { decode(buf) {
25
25
  return Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength).toString();
26
26
  } } : { decode(buf) {
@@ -218,7 +218,7 @@ function getBtoa() {
218
218
  throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
219
219
  };
220
220
  }
221
- const btoa = /* @__PURE__ */ getBtoa();
221
+ const btoa = /*#__PURE__*/ getBtoa();
222
222
  var SourceMap = class {
223
223
  constructor(properties) {
224
224
  this.version = 3;
@@ -355,16 +355,17 @@ var Mappings = class {
355
355
  loc.line,
356
356
  loc.column
357
357
  ];
358
- if (this.hires === "boundary") if (wordRegex.test(original[originalCharIndex])) {
359
- if (!charInHiresBoundary) {
358
+ if (this.hires === "boundary") {
359
+ if (wordRegex.test(original[originalCharIndex])) {
360
+ if (!charInHiresBoundary) {
361
+ this.rawSegments.push(segment);
362
+ charInHiresBoundary = true;
363
+ }
364
+ } else {
360
365
  this.rawSegments.push(segment);
361
- charInHiresBoundary = true;
366
+ charInHiresBoundary = false;
362
367
  }
363
- } else {
364
- this.rawSegments.push(segment);
365
- charInHiresBoundary = false;
366
- }
367
- else this.rawSegments.push(segment);
368
+ } else this.rawSegments.push(segment);
368
369
  }
369
370
  loc.column += 1;
370
371
  this.generatedCodeColumn += 1;
@@ -1010,4 +1011,4 @@ var MagicString = class MagicString {
1010
1011
  //#endregion
1011
1012
  export { MagicString as default };
1012
1013
 
1013
- //# sourceMappingURL=magic-string.es-CaWgF-3p.mjs.map
1014
+ //# sourceMappingURL=magic-string.es-CUAnjKYC.mjs.map