omnicell-router 0.7.0 → 0.8.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 (243) hide show
  1. package/backend/dist/cli/clients/base.d.ts +13 -2
  2. package/backend/dist/cli/clients/claude.d.ts +2 -2
  3. package/backend/dist/cli/clients/codex.d.ts +2 -2
  4. package/backend/dist/cli/clients/core-adapters.d.ts +3 -4
  5. package/backend/dist/cli/clients/core-adapters.js +3 -4
  6. package/backend/dist/cli/clients/cursor-proxy.d.ts +88 -0
  7. package/backend/dist/cli/clients/cursor-proxy.js +421 -0
  8. package/backend/dist/cli/clients/dsh.d.ts +2 -2
  9. package/backend/dist/cli/clients/grok.d.ts +2 -2
  10. package/backend/dist/cli/clients/index.d.ts +8 -1
  11. package/backend/dist/cli/clients/index.js +48 -20
  12. package/backend/dist/cli/clients/kimi.d.ts +2 -2
  13. package/backend/dist/cli/clients/launcher.d.ts +8 -0
  14. package/backend/dist/cli/clients/model-meta.js +1 -1
  15. package/backend/dist/cli/clients/omp.d.ts +2 -2
  16. package/backend/dist/cli/clients/openclaw.d.ts +2 -2
  17. package/backend/dist/cli/clients/opencode-proxy.d.ts +11 -0
  18. package/backend/dist/cli/clients/opencode-proxy.js +351 -0
  19. package/backend/dist/cli/clients/opencode.d.ts +2 -2
  20. package/backend/dist/cli/clients/pi.d.ts +2 -2
  21. package/backend/dist/cli/clients/plugin-adapters.d.ts +3 -1
  22. package/backend/dist/cli/clients/plugin-adapters.js +6 -29
  23. package/backend/dist/cli/clients/qoder-proxy.d.ts +84 -0
  24. package/backend/dist/cli/clients/qoder-proxy.js +497 -0
  25. package/backend/dist/cli/clients/reserved.d.ts +2 -6
  26. package/backend/dist/cli/clients/reserved.js +2 -0
  27. package/backend/dist/cli/clients/workbuddy.d.ts +2 -2
  28. package/backend/dist/cli/index.js +60 -9
  29. package/backend/dist/cli/types.d.ts +20 -8
  30. package/backend/dist/compression/caveman-prompts.d.ts +1 -1
  31. package/backend/dist/config/comments-en.js +6 -12
  32. package/backend/dist/config/comments-zh.js +6 -12
  33. package/backend/dist/config/defaults.d.ts +56 -1
  34. package/backend/dist/config/defaults.js +68 -0
  35. package/backend/dist/config/index.d.ts +9 -2
  36. package/backend/dist/config/index.js +26 -3
  37. package/backend/dist/config/types.d.ts +55 -43
  38. package/backend/dist/forward-proxy/egress.d.ts +10 -2
  39. package/backend/dist/forward-proxy/egress.js +42 -4
  40. package/backend/dist/forward-proxy/ordered-relay.d.ts +29 -0
  41. package/backend/dist/forward-proxy/ordered-relay.js +46 -0
  42. package/backend/dist/forward-proxy/rules.d.ts +66 -19
  43. package/backend/dist/forward-proxy/rules.js +61 -14
  44. package/backend/dist/forward-proxy/server.js +226 -77
  45. package/backend/dist/forward-proxy/system-proxy.d.ts +42 -2
  46. package/backend/dist/forward-proxy/system-proxy.js +199 -22
  47. package/backend/dist/harness/common/market.d.ts +3 -3
  48. package/backend/dist/harness/host/adapters/amp.d.ts +1 -1
  49. package/backend/dist/harness/host/adapters/antigravity.d.ts +1 -1
  50. package/backend/dist/harness/host/adapters/claude.d.ts +1 -1
  51. package/backend/dist/harness/host/adapters/cline.d.ts +1 -1
  52. package/backend/dist/harness/host/adapters/codex.d.ts +1 -1
  53. package/backend/dist/harness/host/adapters/cursor.d.ts +1 -1
  54. package/backend/dist/harness/host/adapters/dsh.d.ts +2 -2
  55. package/backend/dist/harness/host/adapters/factory.d.ts +1 -1
  56. package/backend/dist/harness/host/adapters/gemini-cli.d.ts +1 -1
  57. package/backend/dist/harness/host/adapters/grok.d.ts +1 -1
  58. package/backend/dist/harness/host/adapters/kimi.d.ts +1 -1
  59. package/backend/dist/harness/host/adapters/omp.d.ts +1 -1
  60. package/backend/dist/harness/host/adapters/openclaw.d.ts +1 -1
  61. package/backend/dist/harness/host/adapters/opencode.d.ts +1 -1
  62. package/backend/dist/harness/host/adapters/pi.d.ts +1 -1
  63. package/backend/dist/harness/host/adapters/universal.d.ts +1 -1
  64. package/backend/dist/harness/host/adapters/windsurf.d.ts +1 -1
  65. package/backend/dist/harness/host/adapters/zed.d.ts +1 -1
  66. package/backend/dist/harness/skill/skills-sh.d.ts +1 -1
  67. package/backend/dist/harness/translation.js +64 -21
  68. package/backend/dist/harness/types.d.ts +1 -1
  69. package/backend/dist/harness/types.js +1 -1
  70. package/backend/dist/index.js +31 -18
  71. package/backend/dist/ir/adapters/anthropic-stream.d.ts +18 -0
  72. package/backend/dist/ir/adapters/anthropic-stream.js +247 -0
  73. package/backend/dist/ir/adapters/anthropic.d.ts +29 -0
  74. package/backend/dist/ir/adapters/anthropic.js +788 -0
  75. package/backend/dist/ir/adapters/chat.d.ts +15 -0
  76. package/backend/dist/ir/adapters/chat.js +602 -0
  77. package/backend/dist/ir/adapters/google-stream.d.ts +22 -0
  78. package/backend/dist/ir/adapters/google-stream.js +242 -0
  79. package/backend/dist/ir/adapters/google.d.ts +9 -0
  80. package/backend/dist/ir/adapters/google.js +317 -0
  81. package/backend/dist/ir/adapters/openai-responses-output.js +8 -5
  82. package/backend/dist/ir/adapters/openai-responses.d.ts +15 -0
  83. package/backend/dist/ir/adapters/openai-responses.js +26 -1
  84. package/backend/dist/ir/adapters/responses-output.d.ts +50 -0
  85. package/backend/dist/ir/adapters/responses-output.js +348 -0
  86. package/backend/dist/ir/adapters/responses-stream.d.ts +12 -0
  87. package/backend/dist/ir/adapters/responses-stream.js +178 -0
  88. package/backend/dist/ir/adapters/responses.d.ts +14 -0
  89. package/backend/dist/ir/adapters/responses.js +646 -0
  90. package/backend/dist/ir/errors.d.ts +2 -2
  91. package/backend/dist/ir/types.d.ts +2 -1
  92. package/backend/dist/metrics/request-cost.d.ts +11 -2
  93. package/backend/dist/metrics/request-cost.js +12 -3
  94. package/backend/dist/observability/request-identity.d.ts +1 -1
  95. package/backend/dist/observability/trace-id.d.ts +40 -0
  96. package/backend/dist/observability/trace-id.js +134 -0
  97. package/backend/dist/observability/upstream-events.d.ts +82 -60
  98. package/backend/dist/observability/upstream-events.js +142 -67
  99. package/backend/dist/opencode/catalog/types.d.ts +9 -0
  100. package/backend/dist/opencode/credentials/types.d.ts +2 -2
  101. package/backend/dist/opencode/probe.d.ts +24 -1
  102. package/backend/dist/opencode/probe.js +28 -4
  103. package/backend/dist/opencode/user-config.d.ts +5 -0
  104. package/backend/dist/pipeline/directives.d.ts +6 -2
  105. package/backend/dist/pipeline/directives.js +7 -3
  106. package/backend/dist/pipeline/orchestrator.d.ts +28 -27
  107. package/backend/dist/pipeline/orchestrator.js +220 -194
  108. package/backend/dist/pipeline/unresolved-model.d.ts +33 -0
  109. package/backend/dist/pipeline/unresolved-model.js +43 -0
  110. package/backend/dist/plugins/catalog-def.d.ts +143 -0
  111. package/backend/dist/plugins/catalog-def.js +177 -0
  112. package/backend/dist/plugins/gateways.d.ts +62 -3
  113. package/backend/dist/plugins/gateways.js +139 -2
  114. package/backend/dist/plugins/host.d.ts +42 -5
  115. package/backend/dist/plugins/host.js +454 -38
  116. package/backend/dist/plugins/manifest.d.ts +119 -10
  117. package/backend/dist/plugins/manifest.js +265 -14
  118. package/backend/dist/plugins/pack.js +26 -0
  119. package/backend/dist/plugins/types.d.ts +187 -21
  120. package/backend/dist/protocols/systemone/convert.d.ts +1 -0
  121. package/backend/dist/protocols/systemone/convert.js +6 -1
  122. package/backend/dist/protocols/systemone/decide.js +18 -8
  123. package/backend/dist/providers/anthropic-messages.d.ts +12 -0
  124. package/backend/dist/providers/anthropic-messages.js +53 -0
  125. package/backend/dist/providers/anthropic.d.ts +7 -8
  126. package/backend/dist/providers/anthropic.js +36 -324
  127. package/backend/dist/providers/base.d.ts +14 -2
  128. package/backend/dist/providers/boot-direct.js +68 -38
  129. package/backend/dist/providers/dispatch.d.ts +5 -19
  130. package/backend/dist/providers/dispatch.js +46 -58
  131. package/backend/dist/providers/executors/anthropic-messages.d.ts +1 -0
  132. package/backend/dist/providers/executors/anthropic-messages.js +3 -0
  133. package/backend/dist/providers/executors/dispatch.d.ts +16 -2
  134. package/backend/dist/providers/executors/dispatch.js +39 -9
  135. package/backend/dist/providers/executors/google-gemini.d.ts +1 -0
  136. package/backend/dist/providers/executors/google-gemini.js +3 -0
  137. package/backend/dist/providers/executors/http-stream.js +16 -3
  138. package/backend/dist/providers/executors/openai-chat.d.ts +1 -0
  139. package/backend/dist/providers/executors/openai-chat.js +3 -0
  140. package/backend/dist/providers/executors/openai-responses.d.ts +1 -0
  141. package/backend/dist/providers/executors/openai-responses.js +3 -0
  142. package/backend/dist/providers/executors/plugin-adapter.js +4 -4
  143. package/backend/dist/providers/google-gemini.d.ts +12 -0
  144. package/backend/dist/providers/google-gemini.js +50 -0
  145. package/backend/dist/providers/google.d.ts +7 -8
  146. package/backend/dist/providers/google.js +35 -308
  147. package/backend/dist/providers/http-json.d.ts +19 -0
  148. package/backend/dist/providers/http-json.js +104 -0
  149. package/backend/dist/providers/http-stream.d.ts +52 -0
  150. package/backend/dist/providers/http-stream.js +423 -0
  151. package/backend/dist/providers/member-match.d.ts +4 -5
  152. package/backend/dist/providers/member-match.js +4 -5
  153. package/backend/dist/providers/openai-chat.d.ts +13 -0
  154. package/backend/dist/providers/openai-chat.js +99 -0
  155. package/backend/dist/providers/openai-compatible.d.ts +7 -4
  156. package/backend/dist/providers/openai-compatible.js +71 -368
  157. package/backend/dist/providers/openai-responses.d.ts +12 -0
  158. package/backend/dist/providers/openai-responses.js +68 -0
  159. package/backend/dist/providers/opencode-proxy.d.ts +5 -5
  160. package/backend/dist/providers/opencode-proxy.js +49 -125
  161. package/backend/dist/providers/plugin-adapter.d.ts +9 -0
  162. package/backend/dist/providers/plugin-adapter.js +31 -0
  163. package/backend/dist/providers/registry.d.ts +49 -24
  164. package/backend/dist/providers/registry.js +97 -55
  165. package/backend/dist/providers/responses.d.ts +7 -28
  166. package/backend/dist/providers/responses.js +45 -253
  167. package/backend/dist/providers/tool-markup-leak.d.ts +41 -0
  168. package/backend/dist/providers/tool-markup-leak.js +57 -0
  169. package/backend/dist/providers/tool-markup-recovery.d.ts +27 -0
  170. package/backend/dist/providers/tool-markup-recovery.js +786 -0
  171. package/backend/dist/providers/virtual-meta.d.ts +21 -2
  172. package/backend/dist/providers/virtual-meta.js +49 -9
  173. package/backend/dist/proxy/asset-download.d.ts +54 -0
  174. package/backend/dist/proxy/asset-download.js +420 -0
  175. package/backend/dist/proxy/manual-node-spec.d.ts +16 -16
  176. package/backend/dist/proxy/mihomo-binary.d.ts +17 -2
  177. package/backend/dist/proxy/mihomo-binary.js +62 -51
  178. package/backend/dist/proxy/mihomo-client.js +15 -1
  179. package/backend/dist/proxy/mihomo-config.js +11 -2
  180. package/backend/dist/proxy/mihomo-geo.d.ts +87 -0
  181. package/backend/dist/proxy/mihomo-geo.js +213 -0
  182. package/backend/dist/proxy/mihomo-logs.d.ts +27 -0
  183. package/backend/dist/proxy/mihomo-logs.js +70 -0
  184. package/backend/dist/proxy/mihomo-pac.d.ts +11 -0
  185. package/backend/dist/proxy/mihomo-pac.js +15 -0
  186. package/backend/dist/proxy/mihomo-rules-import.d.ts +1 -1
  187. package/backend/dist/proxy/mihomo-rules-import.js +7 -7
  188. package/backend/dist/proxy/mihomo-sidecar.d.ts +17 -1
  189. package/backend/dist/proxy/mihomo-sidecar.js +148 -26
  190. package/backend/dist/quota/adapters/minimax.js +36 -13
  191. package/backend/dist/quota/cli-login.d.ts +8 -0
  192. package/backend/dist/quota/cli-login.js +18 -0
  193. package/backend/dist/quota/declarations.js +10 -0
  194. package/backend/dist/quota/dsl.js +18 -5
  195. package/backend/dist/quota/engine.d.ts +22 -1
  196. package/backend/dist/quota/engine.js +170 -29
  197. package/backend/dist/quota/prober.d.ts +5 -0
  198. package/backend/dist/quota/prober.js +11 -2
  199. package/backend/dist/quota/types.d.ts +87 -8
  200. package/backend/dist/quota/verdict.d.ts +35 -0
  201. package/backend/dist/quota/verdict.js +135 -0
  202. package/backend/dist/ratelimit/admission.d.ts +131 -0
  203. package/backend/dist/ratelimit/admission.js +233 -0
  204. package/backend/dist/ratelimit/rate-limiter.js +6 -0
  205. package/backend/dist/resilience/types.d.ts +2 -2
  206. package/backend/dist/router/layer2-decision.d.ts +1 -1
  207. package/backend/dist/router/layer2-decision.js +5 -8
  208. package/backend/dist/routes/console.js +242 -51
  209. package/backend/dist/routes/mihomo.d.ts +2 -0
  210. package/backend/dist/routes/mihomo.js +334 -29
  211. package/backend/dist/routes/responses.d.ts +87 -8
  212. package/backend/dist/routes/responses.js +314 -33
  213. package/backend/dist/server.js +26 -6
  214. package/backend/dist/session/session-manager.d.ts +6 -0
  215. package/backend/dist/session/session-manager.js +20 -9
  216. package/backend/dist/surfaces/chat-pipeline.d.ts +2 -2
  217. package/backend/dist/surfaces/chat-pipeline.js +17 -7
  218. package/backend/dist/surfaces/chat.js +15 -0
  219. package/backend/dist/surfaces/decision-pipeline.js +7 -10
  220. package/backend/dist/surfaces/direct-forward.d.ts +3 -0
  221. package/backend/dist/surfaces/direct-forward.js +206 -0
  222. package/backend/dist/surfaces/rate-limit-response.d.ts +17 -0
  223. package/backend/dist/surfaces/rate-limit-response.js +57 -0
  224. package/backend/dist/surfaces/types.d.ts +11 -0
  225. package/backend/dist/trace/tracker.d.ts +32 -1
  226. package/backend/dist/trace/tracker.js +29 -4
  227. package/backend/dist/types/router.d.ts +34 -12
  228. package/backend/dist/types/router.js +35 -6
  229. package/backend/dist/utils/chat-stream.d.ts +21 -8
  230. package/backend/dist/utils/chat-stream.js +46 -9
  231. package/backend/dist/utils/event-ring.d.ts +4 -0
  232. package/backend/dist/utils/event-ring.js +4 -0
  233. package/backend/dist/utils/popularity.js +29 -4
  234. package/backend/dist/utils/proxy.d.ts +7 -0
  235. package/backend/dist/utils/proxy.js +35 -10
  236. package/backend/dist/utils/retry-after.d.ts +21 -0
  237. package/backend/dist/utils/retry-after.js +36 -0
  238. package/bin/ocr.js +2 -2
  239. package/frontend/dist/assets/index-Cn3QMOQx.js +1487 -0
  240. package/frontend/dist/assets/{index-CQSLGFTV.css → index-DxZ9MHKB.css} +1 -1
  241. package/frontend/dist/index.html +2 -2
  242. package/package.json +1 -1
  243. package/frontend/dist/assets/index-CLvxJjp_.js +0 -1476
@@ -0,0 +1,646 @@
1
+ import { IrUnsupportedError } from '../errors.js';
2
+ import { assertCanonicalRequestSupported } from '../validate.js';
3
+ const PROTOCOL = 'openai-responses';
4
+ function record(value) {
5
+ return value && typeof value === 'object' ? value : {};
6
+ }
7
+ function dataUrl(mediaType, data) {
8
+ return `data:${mediaType};base64,${data}`;
9
+ }
10
+ function annotationFromWire(raw) {
11
+ const a = record(raw);
12
+ if (a.type === 'url_citation' && typeof a.url === 'string') {
13
+ return {
14
+ type: 'url_citation', url: a.url,
15
+ ...(typeof a.title === 'string' ? { title: a.title } : {}),
16
+ ...(typeof a.start_index === 'number' ? { startIndex: a.start_index } : {}),
17
+ ...(typeof a.end_index === 'number' ? { endIndex: a.end_index } : {}),
18
+ };
19
+ }
20
+ if (a.type === 'file_citation' && typeof a.file_id === 'string') {
21
+ return {
22
+ type: 'file_citation', fileId: a.file_id,
23
+ ...(typeof a.filename === 'string' ? { filename: a.filename } : {}),
24
+ ...(typeof a.index === 'number' ? { index: a.index } : {}),
25
+ };
26
+ }
27
+ if (a.type === 'file_path' && typeof a.file_id === 'string') {
28
+ return { type: 'file_path', fileId: a.file_id, ...(typeof a.index === 'number' ? { index: a.index } : {}) };
29
+ }
30
+ return { type: 'extension', protocol: PROTOCOL, payload: raw };
31
+ }
32
+ function annotationToWire(annotation) {
33
+ switch (annotation.type) {
34
+ case 'url_citation':
35
+ return {
36
+ type: 'url_citation', url: annotation.url,
37
+ ...(annotation.title !== undefined ? { title: annotation.title } : {}),
38
+ ...(annotation.startIndex !== undefined ? { start_index: annotation.startIndex } : {}),
39
+ ...(annotation.endIndex !== undefined ? { end_index: annotation.endIndex } : {}),
40
+ };
41
+ case 'file_citation':
42
+ return {
43
+ type: 'file_citation', file_id: annotation.fileId,
44
+ ...(annotation.filename !== undefined ? { filename: annotation.filename } : {}),
45
+ ...(annotation.index !== undefined ? { index: annotation.index } : {}),
46
+ };
47
+ case 'file_path':
48
+ return { type: 'file_path', file_id: annotation.fileId, ...(annotation.index !== undefined ? { index: annotation.index } : {}) };
49
+ case 'extension':
50
+ if (annotation.protocol !== PROTOCOL) {
51
+ throw new IrUnsupportedError('annotation', `Cannot convert ${annotation.protocol} annotation.`, PROTOCOL);
52
+ }
53
+ return record(annotation.payload);
54
+ }
55
+ }
56
+ function partFromWire(raw) {
57
+ const p = record(raw);
58
+ if ((p.type === 'input_text' || p.type === 'output_text') && typeof p.text === 'string') {
59
+ return {
60
+ type: 'text', text: p.text,
61
+ ...(Array.isArray(p.annotations) ? { annotations: p.annotations.map(annotationFromWire) } : {}),
62
+ ...(Array.isArray(p.logprobs) ? { logprobs: p.logprobs } : {}),
63
+ ...(p.prompt_cache_breakpoint ? { cache: { raw: p.prompt_cache_breakpoint } } : {}),
64
+ };
65
+ }
66
+ if (p.type === 'refusal' && typeof p.refusal === 'string')
67
+ return { type: 'refusal', text: p.refusal };
68
+ if (p.type === 'input_image') {
69
+ if (typeof p.file_id === 'string' && p.file_id) {
70
+ return {
71
+ type: 'image', source: { kind: 'file', fileId: p.file_id },
72
+ ...(p.detail && p.detail !== 'original' ? { detail: p.detail } : {}),
73
+ };
74
+ }
75
+ if (typeof p.image_url === 'string' && p.image_url) {
76
+ const match = /^data:([^;]+);base64,(.*)$/.exec(p.image_url);
77
+ return {
78
+ type: 'image',
79
+ source: match ? { kind: 'base64', mediaType: match[1], data: match[2] } : { kind: 'url', url: p.image_url },
80
+ ...(p.detail && p.detail !== 'original' ? { detail: p.detail } : {}),
81
+ };
82
+ }
83
+ }
84
+ if (p.type === 'input_file') {
85
+ const common = { ...(typeof p.filename === 'string' ? { filename: p.filename } : {}) };
86
+ if (typeof p.file_id === 'string' && p.file_id) {
87
+ return { type: 'file', source: { kind: 'file', fileId: p.file_id }, ...common };
88
+ }
89
+ if (typeof p.file_url === 'string' && p.file_url) {
90
+ return { type: 'file', source: { kind: 'url', url: p.file_url }, ...common };
91
+ }
92
+ if (typeof p.file_data === 'string' && p.file_data) {
93
+ const match = /^data:([^;]+);base64,(.*)$/.exec(p.file_data);
94
+ if (match) {
95
+ return {
96
+ type: 'file', source: { kind: 'base64', mediaType: match[1], data: match[2] },
97
+ ...common,
98
+ };
99
+ }
100
+ }
101
+ }
102
+ if (p.type === 'input_image' || p.type === 'input_file') {
103
+ fail('content_part', `Invalid ${p.type}: no supported source was provided.`);
104
+ }
105
+ return { type: 'extension', protocol: PROTOCOL, payload: raw };
106
+ }
107
+ export function responsesPartToWire(part, role) {
108
+ if (part.type === 'extension') {
109
+ if (part.protocol !== PROTOCOL)
110
+ throw new IrUnsupportedError('content_part', `Cannot convert ${part.protocol} content.`, PROTOCOL);
111
+ return record(part.payload);
112
+ }
113
+ if (part.type === 'text') {
114
+ return {
115
+ type: role === 'assistant' ? 'output_text' : 'input_text', text: part.text,
116
+ ...(part.annotations ? { annotations: part.annotations.map(annotationToWire) } : {}),
117
+ ...(part.logprobs ? { logprobs: part.logprobs } : {}),
118
+ ...(part.cache?.raw ? { prompt_cache_breakpoint: part.cache.raw } : {}),
119
+ };
120
+ }
121
+ if (part.type === 'refusal')
122
+ return { type: 'refusal', refusal: part.text };
123
+ if (part.type === 'image') {
124
+ return {
125
+ type: 'input_image',
126
+ ...(part.source.kind === 'url' ? { image_url: part.source.url } : {}),
127
+ ...(part.source.kind === 'base64' ? { image_url: dataUrl(part.source.mediaType, part.source.data) } : {}),
128
+ ...(part.source.kind === 'file' ? { file_id: part.source.fileId } : {}),
129
+ ...(part.detail ? { detail: part.detail } : {}),
130
+ };
131
+ }
132
+ if (part.type === 'file') {
133
+ return {
134
+ type: 'input_file',
135
+ ...(part.source.kind === 'url' ? { file_url: part.source.url } : {}),
136
+ ...(part.source.kind === 'base64' ? { file_data: dataUrl(part.source.mediaType, part.source.data) } : {}),
137
+ ...(part.source.kind === 'file' ? { file_id: part.source.fileId } : {}),
138
+ ...(part.filename ? { filename: part.filename } : {}),
139
+ };
140
+ }
141
+ throw new IrUnsupportedError('audio_part', 'Responses adapter cannot carry input audio.', PROTOCOL);
142
+ }
143
+ export function responsesToolToWire(tool) {
144
+ if (tool.type === 'extension') {
145
+ if (tool.protocol !== PROTOCOL)
146
+ throw new IrUnsupportedError('tool_type', `Cannot convert ${tool.protocol} tool.`, PROTOCOL);
147
+ return record(tool.payload);
148
+ }
149
+ if (tool.type === 'function') {
150
+ return {
151
+ type: 'function', name: tool.function.name,
152
+ ...(tool.function.description !== undefined ? { description: tool.function.description } : {}),
153
+ ...(tool.function.parameters !== undefined ? { parameters: tool.function.parameters } : {}),
154
+ ...(tool.function.strict !== undefined ? { strict: tool.function.strict } : {}),
155
+ };
156
+ }
157
+ if (tool.type === 'custom') {
158
+ return {
159
+ type: 'custom', name: tool.name,
160
+ ...(tool.description !== undefined ? { description: tool.description } : {}),
161
+ ...(tool.format !== undefined ? { format: tool.format } : {}),
162
+ };
163
+ }
164
+ return { type: tool.kind, ...record(tool.config) };
165
+ }
166
+ function itemToWire(item) {
167
+ if (item.type === 'extension') {
168
+ if (item.protocol !== PROTOCOL)
169
+ throw new IrUnsupportedError('input_item', `Cannot convert ${item.protocol} item.`, PROTOCOL);
170
+ return record(item.payload);
171
+ }
172
+ if (item.type === 'item_reference')
173
+ return { type: 'item_reference', id: item.id };
174
+ if (item.type === 'reasoning') {
175
+ if (item.signature)
176
+ throw new IrUnsupportedError('reasoning_signature', 'Responses cannot replay a foreign reasoning signature.', PROTOCOL);
177
+ return {
178
+ type: 'reasoning',
179
+ ...(item.id ? { id: item.id } : {}),
180
+ ...(item.status ? { status: item.status } : {}),
181
+ summary: item.summary?.map((text) => ({ type: 'summary_text', text })) ?? [],
182
+ ...(item.text ? { content: [{ type: 'reasoning_text', text: item.text }] } : {}),
183
+ ...(item.encrypted ? { encrypted_content: item.encrypted } : {}),
184
+ };
185
+ }
186
+ if (item.type === 'tool_call') {
187
+ if (item.signature)
188
+ throw new IrUnsupportedError('tool_call_signature', 'Responses cannot replay a foreign tool-call signature.', PROTOCOL);
189
+ const custom = item.vendor?.[PROTOCOL]?.itemType === 'custom_tool_call';
190
+ return {
191
+ type: custom ? 'custom_tool_call' : 'function_call', id: item.id, call_id: item.callId ?? item.id,
192
+ name: item.name,
193
+ ...(custom ? { input: item.arguments } : { arguments: item.arguments }),
194
+ ...(item.status ? { status: item.status } : {}),
195
+ };
196
+ }
197
+ if (item.type === 'tool_result') {
198
+ if (item.isError)
199
+ throw new IrUnsupportedError('tool_result_error', 'Responses has no lossless is_error field for tool output.', PROTOCOL);
200
+ const parts = item.content.map((p) => responsesPartToWire(p, 'user'));
201
+ const textOnly = parts.every((p) => p.type === 'input_text');
202
+ return {
203
+ type: item.vendor?.[PROTOCOL]?.itemType === 'custom_tool_call_output' ? 'custom_tool_call_output' : 'function_call_output',
204
+ call_id: item.callId,
205
+ output: textOnly ? parts.map((p) => String(p.text ?? '')).join('\n') : parts,
206
+ };
207
+ }
208
+ if (item.role === 'system' || item.role === 'developer')
209
+ return null;
210
+ const role = item.role === 'assistant' ? 'assistant' : 'user';
211
+ return {
212
+ type: 'message', role,
213
+ ...(item.id ? { id: item.id } : {}),
214
+ ...(item.status ? { status: item.status } : {}),
215
+ content: item.content.map((p) => responsesPartToWire(p, role)),
216
+ };
217
+ }
218
+ /** Canonical IR → OpenAI Responses request. No request-object spreading. */
219
+ export function canonicalToResponsesPayload(ir, model, stream = false) {
220
+ assertCanonicalRequestSupported(ir, PROTOCOL);
221
+ const instructions = [
222
+ ...(ir.instructions ? [ir.instructions] : []),
223
+ ...ir.input.flatMap((item) => item.type === 'message' && (item.role === 'system' || item.role === 'developer')
224
+ ? item.content.map((p) => p.type === 'text'
225
+ ? p.text
226
+ : fail('system_part', 'Responses system/developer instructions carry text only.'))
227
+ : []),
228
+ ].filter(Boolean).join('\n\n');
229
+ const input = ir.input.flatMap((item) => {
230
+ const converted = itemToWire(item);
231
+ if (!converted)
232
+ return [];
233
+ return Array.isArray(converted) ? converted : [converted];
234
+ });
235
+ const include = [...(ir.include ?? [])];
236
+ if (ir.reasoning?.include && !include.includes('reasoning.encrypted_content'))
237
+ include.push('reasoning.encrypted_content');
238
+ if ((ir.logprobs === true || ir.topLogprobs !== undefined) && !include.includes('message.output_text.logprobs')) {
239
+ include.push('message.output_text.logprobs');
240
+ }
241
+ return {
242
+ model: model.upstreamModel,
243
+ input,
244
+ stream,
245
+ ...(ir.logprobs === true || ir.topLogprobs !== undefined ? { top_logprobs: ir.topLogprobs ?? 0 } : {}),
246
+ ...(instructions ? { instructions } : {}),
247
+ ...(ir.generation?.maxOutputTokens !== undefined ? { max_output_tokens: ir.generation.maxOutputTokens } : {}),
248
+ ...(ir.generation?.temperature !== undefined && model.temperature !== false
249
+ ? { temperature: ir.generation.temperature }
250
+ : {}),
251
+ ...(ir.generation?.topP !== undefined ? { top_p: ir.generation.topP } : {}),
252
+ ...(ir.tools?.length ? { tools: ir.tools.map(responsesToolToWire) } : {}),
253
+ ...(ir.toolChoice
254
+ ? {
255
+ tool_choice: ir.toolChoice.type === 'function' || ir.toolChoice.type === 'custom'
256
+ ? { type: ir.toolChoice.type, name: ir.toolChoice.name }
257
+ : ir.toolChoice.type === 'allowed'
258
+ ? { type: 'allowed_tools', mode: ir.toolChoice.mode, tools: ir.toolChoice.tools }
259
+ : ir.toolChoice.type,
260
+ }
261
+ : {}),
262
+ ...(ir.parallelToolCalls !== undefined ? { parallel_tool_calls: ir.parallelToolCalls } : {}),
263
+ ...(ir.text
264
+ ? {
265
+ text: {
266
+ ...(ir.text.format
267
+ ? {
268
+ format: ir.text.format.type === 'json_schema'
269
+ ? {
270
+ type: 'json_schema', name: ir.text.format.name ?? 'output', schema: ir.text.format.schema,
271
+ ...(ir.text.format.description !== undefined ? { description: ir.text.format.description } : {}),
272
+ ...(ir.text.format.strict !== undefined ? { strict: ir.text.format.strict } : {}),
273
+ }
274
+ : ir.text.format,
275
+ }
276
+ : {}),
277
+ ...(ir.text.verbosity ? { verbosity: ir.text.verbosity } : {}),
278
+ },
279
+ }
280
+ : {}),
281
+ ...(ir.reasoning
282
+ ? {
283
+ reasoning: {
284
+ ...(ir.reasoning.effort ? { effort: ir.reasoning.effort } : {}),
285
+ ...(ir.reasoning.budgetTokens !== undefined ? { max_tokens: ir.reasoning.budgetTokens } : {}),
286
+ ...(ir.reasoning.summary ? { summary: ir.reasoning.summary } : {}),
287
+ },
288
+ }
289
+ : {}),
290
+ ...(ir.cache?.key ? { prompt_cache_key: ir.cache.key } : {}),
291
+ ...(ir.cache?.retention ? { prompt_cache_retention: ir.cache.retention } : {}),
292
+ ...(ir.cache?.options ? { prompt_cache_options: ir.cache.options } : {}),
293
+ ...(ir.store !== undefined ? { store: ir.store } : {}),
294
+ ...(ir.previousResponseId ? { previous_response_id: ir.previousResponseId } : {}),
295
+ ...(ir.conversation !== undefined ? { conversation: ir.conversation } : {}),
296
+ ...(ir.prompt ? { prompt: ir.prompt } : {}),
297
+ ...(ir.background !== undefined ? { background: ir.background } : {}),
298
+ ...(include.length ? { include } : {}),
299
+ ...(ir.truncation ? { truncation: ir.truncation } : {}),
300
+ ...(ir.serviceTier ? { service_tier: ir.serviceTier } : {}),
301
+ ...(ir.safetyIdentifier ? { safety_identifier: ir.safetyIdentifier } : {}),
302
+ ...(ir.user ? { user: ir.user } : {}),
303
+ ...(ir.metadata ? { metadata: ir.metadata } : {}),
304
+ };
305
+ }
306
+ function fail(code, message) {
307
+ throw new IrUnsupportedError(code, message, PROTOCOL);
308
+ }
309
+ function responsesPartText(content) {
310
+ if (typeof content === 'string')
311
+ return content;
312
+ if (!Array.isArray(content))
313
+ fail('instructions', 'Responses instructions content must be text.');
314
+ return content.map((raw) => {
315
+ const part = record(raw);
316
+ if ((part.type === 'input_text' || part.type === 'output_text') && typeof part.text === 'string')
317
+ return part.text;
318
+ return fail('instructions', 'Responses instructions arrays accept text content only.');
319
+ }).join('');
320
+ }
321
+ function instructionsFromWire(raw) {
322
+ if (raw === undefined || raw === null)
323
+ return undefined;
324
+ if (typeof raw === 'string')
325
+ return raw || undefined;
326
+ if (!Array.isArray(raw))
327
+ fail('instructions', 'Responses instructions must be a string or message array.');
328
+ const text = raw.map((item) => {
329
+ if (typeof item === 'string')
330
+ return item;
331
+ const message = record(item);
332
+ if (message.type !== undefined && message.type !== 'message') {
333
+ return fail('instructions', 'Responses instructions arrays accept message items only.');
334
+ }
335
+ return responsesPartText(message.content);
336
+ }).filter(Boolean).join('\n\n');
337
+ return text || undefined;
338
+ }
339
+ function toolsFromWire(raw) {
340
+ if (raw === undefined)
341
+ return undefined;
342
+ if (!Array.isArray(raw))
343
+ fail('tools', 'Responses tools must be an array.');
344
+ return raw.map((entry) => {
345
+ const tool = record(entry);
346
+ if (tool.type === 'function') {
347
+ if (typeof tool.name !== 'string')
348
+ fail('tool', 'Responses function tools require a name.');
349
+ return {
350
+ type: 'function',
351
+ function: {
352
+ name: tool.name,
353
+ ...(typeof tool.description === 'string' ? { description: tool.description } : {}),
354
+ ...(tool.parameters !== undefined ? { parameters: record(tool.parameters) } : {}),
355
+ ...(typeof tool.strict === 'boolean' ? { strict: tool.strict } : {}),
356
+ },
357
+ };
358
+ }
359
+ if (tool.type === 'custom') {
360
+ if (typeof tool.name !== 'string')
361
+ fail('tool', 'Responses custom tools require a name.');
362
+ const format = record(tool.format);
363
+ return {
364
+ type: 'custom', name: tool.name,
365
+ ...(typeof tool.description === 'string' ? { description: tool.description } : {}),
366
+ ...(tool.format !== undefined ? {
367
+ format: format.type === 'grammar'
368
+ ? {
369
+ type: 'grammar',
370
+ definition: String(format.definition ?? ''),
371
+ syntax: format.syntax === 'regex' ? 'regex' : 'lark',
372
+ }
373
+ : { type: 'text' },
374
+ } : {}),
375
+ };
376
+ }
377
+ if (typeof tool.type !== 'string' || !tool.type)
378
+ fail('tool_type', 'Responses tools require a type.');
379
+ const { type, ...config } = tool;
380
+ return { type: 'builtin', kind: type, config };
381
+ });
382
+ }
383
+ function toolChoiceFromWire(raw) {
384
+ if (raw === undefined || raw === null)
385
+ return undefined;
386
+ if (raw === 'auto' || raw === 'none' || raw === 'required')
387
+ return { type: raw };
388
+ const choice = record(raw);
389
+ if ((choice.type === 'function' || choice.type === 'custom') && typeof choice.name === 'string') {
390
+ return { type: choice.type, name: choice.name };
391
+ }
392
+ if (choice.type === 'allowed_tools' && (choice.mode === 'auto' || choice.mode === 'required') && Array.isArray(choice.tools)) {
393
+ const tools = choice.tools.map((rawTool) => {
394
+ const tool = record(rawTool);
395
+ if ((tool.type !== 'function' && tool.type !== 'custom') || typeof tool.name !== 'string') {
396
+ return fail('allowed_tools', 'Responses allowed_tools entries require a function/custom type and name.');
397
+ }
398
+ return { type: tool.type, name: tool.name };
399
+ });
400
+ return { type: 'allowed', mode: choice.mode, tools };
401
+ }
402
+ return fail('tool_choice', 'Unsupported Responses tool_choice.');
403
+ }
404
+ export function responsesInputToIR(raw) {
405
+ if (typeof raw === 'string') {
406
+ return raw ? [{ type: 'message', role: 'user', content: [{ type: 'text', text: raw }] }] : [];
407
+ }
408
+ if (!Array.isArray(raw))
409
+ fail('input', 'Responses input must be a string or item array.');
410
+ return raw.flatMap((entry) => {
411
+ const item = record(entry);
412
+ const type = item.type ?? 'message';
413
+ if (type === 'message') {
414
+ const role = item.role ?? 'user';
415
+ if (role !== 'system' && role !== 'developer' && role !== 'user' && role !== 'assistant') {
416
+ fail('role', `Unsupported Responses message role: ${String(role)}.`);
417
+ }
418
+ const content = typeof item.content === 'string'
419
+ ? [{ type: 'text', text: item.content }]
420
+ : Array.isArray(item.content)
421
+ ? item.content.map(partFromWire)
422
+ : fail('content', 'Responses message content must be a string or part array.');
423
+ return [{
424
+ type: 'message', role,
425
+ ...(typeof item.id === 'string' ? { id: item.id } : {}),
426
+ ...(typeof item.status === 'string' ? { status: item.status } : {}),
427
+ content,
428
+ }];
429
+ }
430
+ if (type === 'item_reference' && typeof item.id === 'string')
431
+ return [{ type: 'item_reference', id: item.id }];
432
+ if (type === 'reasoning') {
433
+ const summary = Array.isArray(item.summary)
434
+ ? item.summary.flatMap((part) => typeof record(part).text === 'string' ? [record(part).text] : [])
435
+ : undefined;
436
+ const content = Array.isArray(item.content)
437
+ ? item.content.flatMap((part) => typeof record(part).text === 'string' ? [record(part).text] : [])
438
+ : [];
439
+ return [{
440
+ type: 'reasoning',
441
+ ...(typeof item.id === 'string' ? { id: item.id } : {}),
442
+ ...(typeof item.status === 'string' ? { status: item.status } : {}),
443
+ ...(content.length ? { text: content.join('\n') } : {}),
444
+ ...(summary ? { summary } : {}),
445
+ ...(typeof item.signature === 'string' ? { signature: item.signature } : {}),
446
+ ...(typeof item.encrypted_content === 'string' ? { encrypted: item.encrypted_content } : {}),
447
+ }];
448
+ }
449
+ if (type === 'function_call' || type === 'custom_tool_call') {
450
+ const id = typeof item.id === 'string' ? item.id : String(item.call_id ?? '');
451
+ const callId = typeof item.call_id === 'string' ? item.call_id : id;
452
+ const args = type === 'custom_tool_call' ? item.input : item.arguments;
453
+ return [{
454
+ type: 'tool_call', id, callId,
455
+ name: String(item.name ?? ''),
456
+ arguments: typeof args === 'string' ? args : JSON.stringify(args ?? {}),
457
+ ...(typeof item.status === 'string' ? { status: item.status } : {}),
458
+ ...(type === 'custom_tool_call' ? { vendor: { [PROTOCOL]: { itemType: type } } } : {}),
459
+ }];
460
+ }
461
+ if (type === 'function_call_output' || type === 'custom_tool_call_output') {
462
+ if (typeof item.call_id !== 'string')
463
+ fail('tool_result', 'Responses tool outputs require call_id.');
464
+ const content = typeof item.output === 'string'
465
+ ? [{ type: 'text', text: item.output }]
466
+ : Array.isArray(item.output)
467
+ ? item.output.map(partFromWire)
468
+ : fail('tool_result', 'Responses tool output must be a string or content-part array.');
469
+ return [{
470
+ type: 'tool_result', callId: item.call_id, content,
471
+ ...(type === 'custom_tool_call_output' ? { vendor: { [PROTOCOL]: { itemType: type } } } : {}),
472
+ }];
473
+ }
474
+ return [{ type: 'extension', protocol: PROTOCOL, payload: entry }];
475
+ });
476
+ }
477
+ /** OpenAI Responses request → Canonical IR. No Chat-shaped intermediate. */
478
+ export function responsesRequestToIR(body) {
479
+ const req = record(body);
480
+ if (req.input === undefined || req.input === null)
481
+ fail('input', 'Invalid request: "input" is required.');
482
+ const input = responsesInputToIR(req.input);
483
+ if (input.length === 0)
484
+ fail('input', 'Invalid request: "input" resolved to an empty item list.');
485
+ const format = record(record(req.text).format);
486
+ let text;
487
+ if (format.type !== undefined || record(req.text).verbosity !== undefined) {
488
+ let parsedFormat;
489
+ if (format.type === undefined || format.type === 'text')
490
+ parsedFormat = { type: 'text' };
491
+ else if (format.type === 'json_object')
492
+ parsedFormat = { type: 'json_object' };
493
+ else if (format.type === 'json_schema') {
494
+ if (typeof format.name !== 'string' || !format.schema || typeof format.schema !== 'object') {
495
+ fail('response_format', 'Responses json_schema text.format requires name and schema.');
496
+ }
497
+ parsedFormat = {
498
+ type: 'json_schema', name: format.name, schema: record(format.schema),
499
+ ...(typeof format.description === 'string' ? { description: format.description } : {}),
500
+ ...(typeof format.strict === 'boolean' ? { strict: format.strict } : {}),
501
+ };
502
+ }
503
+ else
504
+ fail('response_format', `Unsupported Responses text.format: ${String(format.type)}.`);
505
+ const verbosity = record(req.text).verbosity;
506
+ if (verbosity !== undefined && verbosity !== 'low' && verbosity !== 'medium' && verbosity !== 'high') {
507
+ fail('text_verbosity', `Unsupported Responses text.verbosity: ${String(verbosity)}.`);
508
+ }
509
+ text = { format: parsedFormat, ...(verbosity ? { verbosity } : {}) };
510
+ }
511
+ const reasoningWire = record(req.reasoning);
512
+ const effort = reasoningWire.effort;
513
+ if (effort !== undefined && !['none', 'minimal', 'low', 'medium', 'high', 'xhigh'].includes(String(effort))) {
514
+ fail('reasoning_effort', `Unsupported Responses reasoning effort: ${String(effort)}.`);
515
+ }
516
+ const generation = {
517
+ ...(typeof req.temperature === 'number' ? { temperature: req.temperature } : {}),
518
+ ...(typeof req.top_p === 'number' ? { topP: req.top_p } : {}),
519
+ ...(typeof req.max_output_tokens === 'number' ? { maxOutputTokens: req.max_output_tokens } : {}),
520
+ };
521
+ const instructions = instructionsFromWire(req.instructions);
522
+ const tools = toolsFromWire(req.tools);
523
+ const toolChoice = toolChoiceFromWire(req.tool_choice);
524
+ return {
525
+ model: typeof req.model === 'string' && req.model.trim() ? req.model.trim() : 'auto',
526
+ stream: req.stream === true,
527
+ input,
528
+ ...(instructions ? { instructions } : {}),
529
+ ...(tools?.length ? { tools } : {}),
530
+ ...(toolChoice ? { toolChoice } : {}),
531
+ ...(typeof req.parallel_tool_calls === 'boolean' ? { parallelToolCalls: req.parallel_tool_calls } : {}),
532
+ ...(Object.keys(generation).length ? { generation } : {}),
533
+ ...(text ? { text } : {}),
534
+ ...(req.reasoning !== undefined ? {
535
+ reasoning: {
536
+ ...(effort ? { effort: effort } : {}),
537
+ ...(typeof reasoningWire.max_tokens === 'number' ? { budgetTokens: reasoningWire.max_tokens } : {}),
538
+ ...(typeof reasoningWire.summary === 'string' ? { summary: reasoningWire.summary } : {}),
539
+ },
540
+ } : {}),
541
+ ...(req.prompt_cache_key || req.prompt_cache_retention || req.prompt_cache_options ? {
542
+ cache: {
543
+ ...(typeof req.prompt_cache_key === 'string' ? { key: req.prompt_cache_key } : {}),
544
+ ...(typeof req.prompt_cache_retention === 'string' ? { retention: req.prompt_cache_retention } : {}),
545
+ ...(req.prompt_cache_options && typeof req.prompt_cache_options === 'object' ? { options: record(req.prompt_cache_options) } : {}),
546
+ },
547
+ } : {}),
548
+ ...(typeof req.store === 'boolean' ? { store: req.store } : {}),
549
+ ...(typeof req.previous_response_id === 'string' ? { previousResponseId: req.previous_response_id } : {}),
550
+ ...(req.conversation !== undefined ? { conversation: req.conversation } : {}),
551
+ ...(req.prompt !== undefined ? { prompt: req.prompt } : {}),
552
+ ...(typeof req.background === 'boolean' ? { background: req.background } : {}),
553
+ ...(Array.isArray(req.include) ? { include: req.include } : {}),
554
+ ...(req.truncation !== undefined ? { truncation: req.truncation } : {}),
555
+ ...(typeof req.service_tier === 'string' ? { serviceTier: req.service_tier } : {}),
556
+ ...(typeof req.safety_identifier === 'string' ? { safetyIdentifier: req.safety_identifier } : {}),
557
+ ...(typeof req.user === 'string' ? { user: req.user } : {}),
558
+ ...(req.metadata && typeof req.metadata === 'object' ? { metadata: record(req.metadata) } : {}),
559
+ };
560
+ }
561
+ function usageFromWire(raw) {
562
+ const u = record(raw);
563
+ return {
564
+ inputTokens: u.input_tokens ?? 0,
565
+ outputTokens: u.output_tokens ?? 0,
566
+ ...(u.total_tokens !== undefined ? { totalTokens: u.total_tokens } : {}),
567
+ ...(u.input_tokens_details?.cached_tokens !== undefined
568
+ ? { cachedInputTokens: u.input_tokens_details.cached_tokens }
569
+ : {}),
570
+ ...(u.input_tokens_details?.audio_tokens !== undefined ? { audioInputTokens: u.input_tokens_details.audio_tokens } : {}),
571
+ ...(u.output_tokens_details?.reasoning_tokens !== undefined
572
+ ? { reasoningTokens: u.output_tokens_details.reasoning_tokens }
573
+ : {}),
574
+ ...(u.output_tokens_details?.audio_tokens !== undefined
575
+ ? { audioOutputTokens: u.output_tokens_details.audio_tokens }
576
+ : {}),
577
+ ...(u.output_tokens_details?.accepted_prediction_tokens !== undefined
578
+ ? { acceptedPredictionTokens: u.output_tokens_details.accepted_prediction_tokens }
579
+ : {}),
580
+ ...(u.output_tokens_details?.rejected_prediction_tokens !== undefined
581
+ ? { rejectedPredictionTokens: u.output_tokens_details.rejected_prediction_tokens }
582
+ : {}),
583
+ };
584
+ }
585
+ export function responsesResponseToIR(data) {
586
+ const body = record(data);
587
+ const output = [];
588
+ for (const raw of Array.isArray(body.output) ? body.output : []) {
589
+ const item = record(raw);
590
+ if (item.type === 'reasoning') {
591
+ const text = (Array.isArray(item.content) ? item.content : [])
592
+ .flatMap((part) => typeof record(part).text === 'string' ? [record(part).text] : [])
593
+ .join('\n');
594
+ output.push({
595
+ type: 'reasoning',
596
+ ...(item.id ? { id: item.id } : {}),
597
+ ...(item.status ? { status: item.status } : {}),
598
+ ...(text ? { text } : {}),
599
+ ...(Array.isArray(item.summary)
600
+ ? { summary: item.summary.flatMap((part) => typeof record(part).text === 'string' ? [record(part).text] : []) }
601
+ : {}),
602
+ ...(typeof item.encrypted_content === 'string' ? { encrypted: item.encrypted_content } : {}),
603
+ });
604
+ }
605
+ else if (item.type === 'function_call' || item.type === 'custom_tool_call') {
606
+ const callId = typeof item.call_id === 'string' ? item.call_id : String(item.id ?? '');
607
+ const args = item.type === 'custom_tool_call' ? item.input : item.arguments;
608
+ output.push({
609
+ type: 'tool_call', id: String(item.id ?? callId), callId,
610
+ name: String(item.name ?? ''),
611
+ arguments: typeof args === 'string' ? args : JSON.stringify(args ?? {}),
612
+ ...(item.status ? { status: item.status } : {}),
613
+ ...(item.type === 'custom_tool_call' ? { vendor: { [PROTOCOL]: { itemType: item.type } } } : {}),
614
+ });
615
+ }
616
+ else if (item.type === 'message') {
617
+ output.push({
618
+ type: 'message', role: 'assistant',
619
+ ...(item.id ? { id: item.id } : {}),
620
+ ...(item.status ? { status: item.status } : {}),
621
+ content: (Array.isArray(item.content) ? item.content : []).map(partFromWire),
622
+ });
623
+ }
624
+ else {
625
+ output.push({ type: 'extension', protocol: PROTOCOL, payload: raw });
626
+ }
627
+ }
628
+ const incomplete = body.status === 'incomplete';
629
+ const failed = body.status === 'failed';
630
+ const reason = failed ? 'error' : incomplete
631
+ ? body.incomplete_details?.reason === 'content_filter' ? 'content_filter' : 'length'
632
+ : output.some((item) => item.type === 'tool_call') ? 'tool_calls' : 'stop';
633
+ return {
634
+ ...(body.id ? { id: body.id } : {}),
635
+ ...(body.model ? { model: body.model } : {}),
636
+ ...(typeof body.created_at === 'number' ? { createdAt: body.created_at } : {}),
637
+ status: failed ? 'failed' : incomplete ? 'incomplete' : 'completed',
638
+ reason,
639
+ output,
640
+ usage: usageFromWire(body.usage),
641
+ ...(body.service_tier ? { serviceTier: body.service_tier } : {}),
642
+ ...(body.previous_response_id ? { previousResponseId: body.previous_response_id } : {}),
643
+ ...(body.error ? { error: { code: body.error.code, message: body.error.message ?? 'Responses turn failed.' } } : {}),
644
+ };
645
+ }
646
+ export { annotationFromWire as responsesAnnotationFromWire, partFromWire as responsesPartFromWire, usageFromWire as responsesUsageFromWire, };
@@ -18,6 +18,6 @@ export declare class IrUnsupportedError extends Error {
18
18
  /** A southbound wire returned an error body; adapters use this for 502s. */
19
19
  export declare class IrUpstreamError extends Error {
20
20
  readonly status?: number | undefined;
21
- readonly body?: unknown;
22
- constructor(message: string, status?: number | undefined, body?: unknown);
21
+ readonly body?: unknown | undefined;
22
+ constructor(message: string, status?: number | undefined, body?: unknown | undefined);
23
23
  }
@@ -192,7 +192,8 @@ export interface MessageItem {
192
192
  }
193
193
  export interface ToolCallItem {
194
194
  type: 'tool_call';
195
- /** Item id (Responses `id`); carriers without item ids reuse `callId`. */
195
+ /** Item id (Responses `id`); carriers without item ids reuse `callId`, and a
196
+ * Responses encoder then derives the prefixed item id (`fc_`/`ctc_`). */
196
197
  id: string;
197
198
  /** Correlation id the tool result must reference (Responses `call_id`). */
198
199
  callId?: string;