@nhtio/adk 0.1.0-master-f0aa531d

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 (297) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +3 -0
  3. package/batteries/index.d.ts +28 -0
  4. package/batteries/llm/index.d.ts +11 -0
  5. package/batteries/llm/openai_chat_completions/adapter.cjs +916 -0
  6. package/batteries/llm/openai_chat_completions/adapter.cjs.map +1 -0
  7. package/batteries/llm/openai_chat_completions/adapter.d.ts +101 -0
  8. package/batteries/llm/openai_chat_completions/adapter.mjs +914 -0
  9. package/batteries/llm/openai_chat_completions/adapter.mjs.map +1 -0
  10. package/batteries/llm/openai_chat_completions/exceptions.cjs +89 -0
  11. package/batteries/llm/openai_chat_completions/exceptions.cjs.map +1 -0
  12. package/batteries/llm/openai_chat_completions/exceptions.d.ts +97 -0
  13. package/batteries/llm/openai_chat_completions/exceptions.mjs +81 -0
  14. package/batteries/llm/openai_chat_completions/exceptions.mjs.map +1 -0
  15. package/batteries/llm/openai_chat_completions/helpers.cjs +819 -0
  16. package/batteries/llm/openai_chat_completions/helpers.cjs.map +1 -0
  17. package/batteries/llm/openai_chat_completions/helpers.d.ts +233 -0
  18. package/batteries/llm/openai_chat_completions/helpers.mjs +783 -0
  19. package/batteries/llm/openai_chat_completions/helpers.mjs.map +1 -0
  20. package/batteries/llm/openai_chat_completions/index.d.ts +27 -0
  21. package/batteries/llm/openai_chat_completions/types.cjs +1 -0
  22. package/batteries/llm/openai_chat_completions/types.d.ts +524 -0
  23. package/batteries/llm/openai_chat_completions/types.mjs +0 -0
  24. package/batteries/llm/openai_chat_completions/validation.cjs +190 -0
  25. package/batteries/llm/openai_chat_completions/validation.cjs.map +1 -0
  26. package/batteries/llm/openai_chat_completions/validation.d.ts +31 -0
  27. package/batteries/llm/openai_chat_completions/validation.mjs +187 -0
  28. package/batteries/llm/openai_chat_completions/validation.mjs.map +1 -0
  29. package/batteries/llm/openai_chat_completions.cjs +51 -0
  30. package/batteries/llm/openai_chat_completions.mjs +5 -0
  31. package/batteries/llm/webllm_chat_completions/adapter.cjs +658 -0
  32. package/batteries/llm/webllm_chat_completions/adapter.cjs.map +1 -0
  33. package/batteries/llm/webllm_chat_completions/adapter.d.ts +103 -0
  34. package/batteries/llm/webllm_chat_completions/adapter.mjs +656 -0
  35. package/batteries/llm/webllm_chat_completions/adapter.mjs.map +1 -0
  36. package/batteries/llm/webllm_chat_completions/exceptions.cjs +70 -0
  37. package/batteries/llm/webllm_chat_completions/exceptions.cjs.map +1 -0
  38. package/batteries/llm/webllm_chat_completions/exceptions.d.ts +74 -0
  39. package/batteries/llm/webllm_chat_completions/exceptions.mjs +65 -0
  40. package/batteries/llm/webllm_chat_completions/exceptions.mjs.map +1 -0
  41. package/batteries/llm/webllm_chat_completions/helpers.cjs +38 -0
  42. package/batteries/llm/webllm_chat_completions/helpers.d.ts +6 -0
  43. package/batteries/llm/webllm_chat_completions/helpers.mjs +2 -0
  44. package/batteries/llm/webllm_chat_completions/index.d.ts +25 -0
  45. package/batteries/llm/webllm_chat_completions/types.d.ts +31 -0
  46. package/batteries/llm/webllm_chat_completions/validation.cjs +115 -0
  47. package/batteries/llm/webllm_chat_completions/validation.cjs.map +1 -0
  48. package/batteries/llm/webllm_chat_completions/validation.d.ts +8 -0
  49. package/batteries/llm/webllm_chat_completions/validation.mjs +112 -0
  50. package/batteries/llm/webllm_chat_completions/validation.mjs.map +1 -0
  51. package/batteries/llm/webllm_chat_completions.cjs +50 -0
  52. package/batteries/llm/webllm_chat_completions.mjs +6 -0
  53. package/batteries/llm.cjs +63 -0
  54. package/batteries/llm.mjs +10 -0
  55. package/batteries/storage/flydrive/index.d.ts +167 -0
  56. package/batteries/storage/flydrive.cjs +249 -0
  57. package/batteries/storage/flydrive.cjs.map +1 -0
  58. package/batteries/storage/flydrive.mjs +249 -0
  59. package/batteries/storage/flydrive.mjs.map +1 -0
  60. package/batteries/storage/in_memory/index.d.ts +106 -0
  61. package/batteries/storage/in_memory.cjs +121 -0
  62. package/batteries/storage/in_memory.cjs.map +1 -0
  63. package/batteries/storage/in_memory.mjs +119 -0
  64. package/batteries/storage/in_memory.mjs.map +1 -0
  65. package/batteries/storage/index.d.ts +18 -0
  66. package/batteries/storage/opfs/index.d.ts +299 -0
  67. package/batteries/storage/opfs.cjs +368 -0
  68. package/batteries/storage/opfs.cjs.map +1 -0
  69. package/batteries/storage/opfs.mjs +366 -0
  70. package/batteries/storage/opfs.mjs.map +1 -0
  71. package/batteries/storage.cjs +4 -0
  72. package/batteries/storage.mjs +2 -0
  73. package/batteries/tools/color/index.d.ts +37 -0
  74. package/batteries/tools/color.cjs +659 -0
  75. package/batteries/tools/color.cjs.map +1 -0
  76. package/batteries/tools/color.mjs +655 -0
  77. package/batteries/tools/color.mjs.map +1 -0
  78. package/batteries/tools/comparison/index.d.ts +29 -0
  79. package/batteries/tools/comparison.cjs +171 -0
  80. package/batteries/tools/comparison.cjs.map +1 -0
  81. package/batteries/tools/comparison.mjs +168 -0
  82. package/batteries/tools/comparison.mjs.map +1 -0
  83. package/batteries/tools/data_structure/index.d.ts +30 -0
  84. package/batteries/tools/data_structure.cjs +270 -0
  85. package/batteries/tools/data_structure.cjs.map +1 -0
  86. package/batteries/tools/data_structure.mjs +267 -0
  87. package/batteries/tools/data_structure.mjs.map +1 -0
  88. package/batteries/tools/datetime_extended/index.d.ts +51 -0
  89. package/batteries/tools/datetime_extended.cjs +309 -0
  90. package/batteries/tools/datetime_extended.cjs.map +1 -0
  91. package/batteries/tools/datetime_extended.mjs +302 -0
  92. package/batteries/tools/datetime_extended.mjs.map +1 -0
  93. package/batteries/tools/datetime_math/index.d.ts +36 -0
  94. package/batteries/tools/datetime_math.cjs +175 -0
  95. package/batteries/tools/datetime_math.cjs.map +1 -0
  96. package/batteries/tools/datetime_math.mjs +171 -0
  97. package/batteries/tools/datetime_math.mjs.map +1 -0
  98. package/batteries/tools/encoding/index.d.ts +36 -0
  99. package/batteries/tools/encoding.cjs +156 -0
  100. package/batteries/tools/encoding.cjs.map +1 -0
  101. package/batteries/tools/encoding.mjs +152 -0
  102. package/batteries/tools/encoding.mjs.map +1 -0
  103. package/batteries/tools/formatting/index.d.ts +28 -0
  104. package/batteries/tools/formatting.cjs +120 -0
  105. package/batteries/tools/formatting.cjs.map +1 -0
  106. package/batteries/tools/formatting.mjs +117 -0
  107. package/batteries/tools/formatting.mjs.map +1 -0
  108. package/batteries/tools/geo_basics/index.d.ts +33 -0
  109. package/batteries/tools/geo_basics.cjs +136 -0
  110. package/batteries/tools/geo_basics.cjs.map +1 -0
  111. package/batteries/tools/geo_basics.mjs +132 -0
  112. package/batteries/tools/geo_basics.mjs.map +1 -0
  113. package/batteries/tools/index.d.ts +32 -0
  114. package/batteries/tools/math/index.d.ts +37 -0
  115. package/batteries/tools/math.cjs +136 -0
  116. package/batteries/tools/math.cjs.map +1 -0
  117. package/batteries/tools/math.mjs +133 -0
  118. package/batteries/tools/math.mjs.map +1 -0
  119. package/batteries/tools/memory/index.d.ts +73 -0
  120. package/batteries/tools/memory.cjs +193 -0
  121. package/batteries/tools/memory.cjs.map +1 -0
  122. package/batteries/tools/memory.mjs +187 -0
  123. package/batteries/tools/memory.mjs.map +1 -0
  124. package/batteries/tools/parsing/index.d.ts +47 -0
  125. package/batteries/tools/parsing.cjs +191 -0
  126. package/batteries/tools/parsing.cjs.map +1 -0
  127. package/batteries/tools/parsing.mjs +185 -0
  128. package/batteries/tools/parsing.mjs.map +1 -0
  129. package/batteries/tools/retrievables/index.d.ts +81 -0
  130. package/batteries/tools/retrievables.cjs +215 -0
  131. package/batteries/tools/retrievables.cjs.map +1 -0
  132. package/batteries/tools/retrievables.mjs +209 -0
  133. package/batteries/tools/retrievables.mjs.map +1 -0
  134. package/batteries/tools/standing_instructions/index.d.ts +64 -0
  135. package/batteries/tools/standing_instructions.cjs +126 -0
  136. package/batteries/tools/standing_instructions.cjs.map +1 -0
  137. package/batteries/tools/standing_instructions.mjs +121 -0
  138. package/batteries/tools/standing_instructions.mjs.map +1 -0
  139. package/batteries/tools/statistics/index.d.ts +46 -0
  140. package/batteries/tools/statistics.cjs +253 -0
  141. package/batteries/tools/statistics.cjs.map +1 -0
  142. package/batteries/tools/statistics.mjs +248 -0
  143. package/batteries/tools/statistics.mjs.map +1 -0
  144. package/batteries/tools/string_processing/index.d.ts +29 -0
  145. package/batteries/tools/string_processing.cjs +154 -0
  146. package/batteries/tools/string_processing.cjs.map +1 -0
  147. package/batteries/tools/string_processing.mjs +151 -0
  148. package/batteries/tools/string_processing.mjs.map +1 -0
  149. package/batteries/tools/structured_data/index.d.ts +34 -0
  150. package/batteries/tools/structured_data.cjs +189 -0
  151. package/batteries/tools/structured_data.cjs.map +1 -0
  152. package/batteries/tools/structured_data.mjs +185 -0
  153. package/batteries/tools/structured_data.mjs.map +1 -0
  154. package/batteries/tools/text_analysis/index.d.ts +31 -0
  155. package/batteries/tools/text_analysis.cjs +120 -0
  156. package/batteries/tools/text_analysis.cjs.map +1 -0
  157. package/batteries/tools/text_analysis.mjs +117 -0
  158. package/batteries/tools/text_analysis.mjs.map +1 -0
  159. package/batteries/tools/text_comparison/index.d.ts +28 -0
  160. package/batteries/tools/text_comparison.cjs +96 -0
  161. package/batteries/tools/text_comparison.cjs.map +1 -0
  162. package/batteries/tools/text_comparison.mjs +93 -0
  163. package/batteries/tools/text_comparison.mjs.map +1 -0
  164. package/batteries/tools/time/index.d.ts +27 -0
  165. package/batteries/tools/time.cjs +63 -0
  166. package/batteries/tools/time.cjs.map +1 -0
  167. package/batteries/tools/time.mjs +60 -0
  168. package/batteries/tools/time.mjs.map +1 -0
  169. package/batteries/tools/unit_conversion/index.d.ts +19 -0
  170. package/batteries/tools/unit_conversion.cjs +452 -0
  171. package/batteries/tools/unit_conversion.cjs.map +1 -0
  172. package/batteries/tools/unit_conversion.mjs +450 -0
  173. package/batteries/tools/unit_conversion.mjs.map +1 -0
  174. package/batteries/tools.cjs +80 -0
  175. package/batteries/tools.mjs +21 -0
  176. package/batteries.cjs +142 -0
  177. package/batteries.mjs +30 -0
  178. package/chunk-KmRHZBOW.js +35 -0
  179. package/common-DeZaonK1.mjs +208 -0
  180. package/common-DeZaonK1.mjs.map +1 -0
  181. package/common-Od8edUXU.js +232 -0
  182. package/common-Od8edUXU.js.map +1 -0
  183. package/common.cjs +31 -0
  184. package/common.d.ts +108 -0
  185. package/common.mjs +8 -0
  186. package/dispatch_runner-9j6bXHL3.mjs +1609 -0
  187. package/dispatch_runner-9j6bXHL3.mjs.map +1 -0
  188. package/dispatch_runner-CsoH0nld.js +1627 -0
  189. package/dispatch_runner-CsoH0nld.js.map +1 -0
  190. package/dispatch_runner.cjs +3 -0
  191. package/dispatch_runner.d.ts +17 -0
  192. package/dispatch_runner.mjs +2 -0
  193. package/exceptions-D5YrO9Vm.js +280 -0
  194. package/exceptions-D5YrO9Vm.js.map +1 -0
  195. package/exceptions-NrzIHw_R.mjs +244 -0
  196. package/exceptions-NrzIHw_R.mjs.map +1 -0
  197. package/exceptions.cjs +33 -0
  198. package/exceptions.d.ts +52 -0
  199. package/exceptions.mjs +3 -0
  200. package/factories.cjs +4 -0
  201. package/factories.d.ts +39 -0
  202. package/factories.mjs +2 -0
  203. package/forge.cjs +9 -0
  204. package/forge.d.ts +49 -0
  205. package/forge.mjs +5 -0
  206. package/guards.cjs +96 -0
  207. package/guards.cjs.map +1 -0
  208. package/guards.d.ts +83 -0
  209. package/guards.mjs +72 -0
  210. package/guards.mjs.map +1 -0
  211. package/index.cjs +107 -0
  212. package/index.cjs.map +1 -0
  213. package/index.d.ts +18 -0
  214. package/index.mjs +31 -0
  215. package/index.mjs.map +1 -0
  216. package/lib/classes/artifact_tool.d.ts +129 -0
  217. package/lib/classes/base_exception.d.ts +83 -0
  218. package/lib/classes/identity.d.ts +71 -0
  219. package/lib/classes/media.d.ts +326 -0
  220. package/lib/classes/memory.d.ts +72 -0
  221. package/lib/classes/message.d.ts +137 -0
  222. package/lib/classes/registry.d.ts +79 -0
  223. package/lib/classes/retrievable.d.ts +100 -0
  224. package/lib/classes/spooled_artifact.d.ts +296 -0
  225. package/lib/classes/spooled_json_artifact.d.ts +158 -0
  226. package/lib/classes/spooled_markdown_artifact.d.ts +202 -0
  227. package/lib/classes/thought.d.ts +142 -0
  228. package/lib/classes/tokenizable.d.ts +124 -0
  229. package/lib/classes/tool.d.ts +228 -0
  230. package/lib/classes/tool_call.d.ts +190 -0
  231. package/lib/classes/tool_registry.d.ts +159 -0
  232. package/lib/classes/turn_gate.d.ts +109 -0
  233. package/lib/contracts/dispatch_context.d.ts +345 -0
  234. package/lib/contracts/media_reader.d.ts +60 -0
  235. package/lib/contracts/spool_reader.d.ts +80 -0
  236. package/lib/contracts/spooled_artifact_constructor.d.ts +38 -0
  237. package/lib/contracts/turn_runner_config.d.ts +101 -0
  238. package/lib/contracts/turn_runner_context.d.ts +267 -0
  239. package/lib/dispatch_runner.d.ts +98 -0
  240. package/lib/exceptions/runtime.d.ts +370 -0
  241. package/lib/helpers/media_readers.d.ts +39 -0
  242. package/lib/turn_runner.d.ts +144 -0
  243. package/lib/types/dispatch_context.d.ts +233 -0
  244. package/lib/types/dispatch_runner.d.ts +387 -0
  245. package/lib/types/turn_runner.d.ts +322 -0
  246. package/lib/utils/canonical_json.d.ts +18 -0
  247. package/lib/utils/exceptions.d.ts +78 -0
  248. package/lib/utils/guards.d.ts +32 -0
  249. package/lib/utils/validation.d.ts +77 -0
  250. package/package.json +334 -0
  251. package/runtime-BJVkrGQe.js +519 -0
  252. package/runtime-BJVkrGQe.js.map +1 -0
  253. package/runtime-CrEPIFgr.mjs +346 -0
  254. package/runtime-CrEPIFgr.mjs.map +1 -0
  255. package/skills/adk-assembly/SKILL.md +109 -0
  256. package/skills/adk-assembly/references/assembly-contract.md +66 -0
  257. package/skills/adk-assembly/references/executors-tools-pipelines-events.md +113 -0
  258. package/skills/adk-assembly/references/first-integration.md +93 -0
  259. package/skills/adk-assembly/references/storage-and-context.md +102 -0
  260. package/spooled_artifact-C5ZtGxuJ.mjs +544 -0
  261. package/spooled_artifact-C5ZtGxuJ.mjs.map +1 -0
  262. package/spooled_artifact-Cm9Te22K.js +568 -0
  263. package/spooled_artifact-Cm9Te22K.js.map +1 -0
  264. package/spooled_artifact.cjs +7 -0
  265. package/spooled_artifact.d.ts +40 -0
  266. package/spooled_artifact.mjs +3 -0
  267. package/spooled_markdown_artifact-BpUJol0W.mjs +771 -0
  268. package/spooled_markdown_artifact-BpUJol0W.mjs.map +1 -0
  269. package/spooled_markdown_artifact-RRB113sy.js +786 -0
  270. package/spooled_markdown_artifact-RRB113sy.js.map +1 -0
  271. package/thought-CDb457b4.mjs +470 -0
  272. package/thought-CDb457b4.mjs.map +1 -0
  273. package/thought-DuN2PgdO.js +494 -0
  274. package/thought-DuN2PgdO.js.map +1 -0
  275. package/tool-COSeH8I6.js +302 -0
  276. package/tool-COSeH8I6.js.map +1 -0
  277. package/tool-D2WB1EA1.mjs +296 -0
  278. package/tool-D2WB1EA1.mjs.map +1 -0
  279. package/tool_call-BKyyxGaZ.mjs +578 -0
  280. package/tool_call-BKyyxGaZ.mjs.map +1 -0
  281. package/tool_call-DFgzcVcU.js +608 -0
  282. package/tool_call-DFgzcVcU.js.map +1 -0
  283. package/tool_registry-Dkfprsck.js +641 -0
  284. package/tool_registry-Dkfprsck.js.map +1 -0
  285. package/tool_registry-DqLOyGyG.mjs +592 -0
  286. package/tool_registry-DqLOyGyG.mjs.map +1 -0
  287. package/turn_runner-CMm2BHdX.js +615 -0
  288. package/turn_runner-CMm2BHdX.js.map +1 -0
  289. package/turn_runner-y7eyEcJH.mjs +603 -0
  290. package/turn_runner-y7eyEcJH.mjs.map +1 -0
  291. package/turn_runner.cjs +3 -0
  292. package/turn_runner.d.ts +21 -0
  293. package/turn_runner.mjs +2 -0
  294. package/types.cjs +1 -0
  295. package/types.d.ts +56 -0
  296. package/types.mjs +0 -0
  297. package/vite-env.d.ts +23 -0
@@ -0,0 +1,524 @@
1
+ /**
2
+ * TypeScript wire shapes, helper contracts, and option types for the Chat Completions battery.
3
+ *
4
+ * @module @nhtio/adk/batteries/llm/openai_chat_completions/types
5
+ *
6
+ * @remarks
7
+ * Shared TypeScript type aliases for the OpenAI Chat Completions adapter — wire shapes,
8
+ * helper input/output shapes, and the adapter's options shape. These are documentation-level
9
+ * types only; runtime validation lives in `validation.ts` (`openAIChatCompletionsOptionsSchema`).
10
+ */
11
+ import type { TokenEncoding } from "../../../common";
12
+ import type { SpooledArtifact, Media } from "../../../common";
13
+ import type { Tokenizable, Memory, Message, Thought, ToolCall, Retrievable, Tool, ArtifactTool, ToolRegistry } from "../../../common";
14
+ export interface DescriptionLike {
15
+ type?: string;
16
+ description?: string;
17
+ presence?: string;
18
+ default?: unknown;
19
+ enum?: unknown[];
20
+ valids?: unknown[];
21
+ examples?: unknown[];
22
+ properties?: Record<string, DescriptionLike>;
23
+ items?: DescriptionLike | DescriptionLike[];
24
+ required?: string[];
25
+ flags?: {
26
+ presence?: string;
27
+ description?: string;
28
+ default?: unknown;
29
+ };
30
+ [key: string]: unknown;
31
+ }
32
+ export interface JsonSchema {
33
+ type?: 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
34
+ description?: string;
35
+ enum?: unknown[];
36
+ default?: unknown;
37
+ examples?: unknown[];
38
+ properties?: Record<string, JsonSchema>;
39
+ required?: string[];
40
+ items?: JsonSchema | JsonSchema[];
41
+ additionalProperties?: boolean | JsonSchema;
42
+ [key: string]: unknown;
43
+ }
44
+ export interface UntrustedContentAttrs {
45
+ nonce: string;
46
+ kind: string;
47
+ tool?: string;
48
+ /**
49
+ * When wrapping a {@link @nhtio/adk!Media}-derived text marker, the modality hazard axis derived from
50
+ * `media.modalityHazard`: `'inert'`, `'extractable'` (from `'extractable-instructions'`), or
51
+ * `'opaque'` (from `'opaque-perceptual'`). Omitted for non-media envelopes.
52
+ */
53
+ modality?: 'inert' | 'extractable' | 'opaque';
54
+ }
55
+ export interface TrustedContentAttrs {
56
+ nonce: string;
57
+ kind: string;
58
+ tool?: string;
59
+ /**
60
+ * Same semantics as {@link UntrustedContentAttrs.modality}.
61
+ */
62
+ modality?: 'inert' | 'extractable' | 'opaque';
63
+ }
64
+ export interface StandingInstructionAttrs {
65
+ version?: string;
66
+ }
67
+ export interface MemoryAttrs {
68
+ nonce: string;
69
+ source?: string;
70
+ createdAt?: string;
71
+ kind?: string;
72
+ score?: number;
73
+ }
74
+ export interface RetrievableAttrs {
75
+ nonce: string;
76
+ source?: string;
77
+ createdAt?: string;
78
+ kind?: string;
79
+ score?: number;
80
+ }
81
+ export interface ThoughtAttrs {
82
+ nonce: string;
83
+ kind: 'self-reasoning' | 'peer-reasoning' | 'opaque-reasoning';
84
+ from: string;
85
+ createdAt?: string;
86
+ replayCompatibility?: string;
87
+ }
88
+ export type ChatCompletionsBucketLabel = 'standingInstructions' | 'memories' | 'retrievables' | 'timeline';
89
+ export type ChatCompletionsBucketOrder = ReadonlyArray<ChatCompletionsBucketLabel>;
90
+ export interface ChatCompletionsToolCallWire {
91
+ id: string;
92
+ type?: 'function';
93
+ function?: {
94
+ name?: string;
95
+ arguments?: string;
96
+ };
97
+ }
98
+ /**
99
+ * Discriminated union of content block shapes accepted by the OpenAI Chat Completions wire
100
+ * format for a content-array message body.
101
+ *
102
+ * @remarks
103
+ * `text` is the trust-envelope-wrapped string body. `image_url` carries either an inline
104
+ * `data:` URI or a remote URL. `input_audio` carries base64-encoded audio plus a format hint.
105
+ * `file` carries either a previously-uploaded `file_id` or an inline `file_data` blob with
106
+ * a `filename`.
107
+ */
108
+ export type ChatCompletionsContentBlock = {
109
+ type: 'text';
110
+ text: string;
111
+ } | {
112
+ type: 'image_url';
113
+ image_url: {
114
+ url: string;
115
+ detail?: 'auto' | 'low' | 'high';
116
+ };
117
+ } | {
118
+ type: 'input_audio';
119
+ input_audio: {
120
+ data: string;
121
+ format: 'wav' | 'mp3';
122
+ };
123
+ } | {
124
+ type: 'file';
125
+ file: {
126
+ file_id?: string;
127
+ filename?: string;
128
+ file_data?: string;
129
+ };
130
+ };
131
+ export interface ChatCompletionsMessage {
132
+ role: 'system' | 'user' | 'assistant' | 'tool' | 'developer';
133
+ content: string | ChatCompletionsContentBlock[] | null;
134
+ name?: string;
135
+ tool_call_id?: string;
136
+ tool_calls?: ChatCompletionsToolCallWire[];
137
+ }
138
+ export interface ChatCompletionsTool {
139
+ type: 'function';
140
+ function: {
141
+ name: string;
142
+ description?: string;
143
+ parameters?: JsonSchema;
144
+ };
145
+ }
146
+ export interface ChatCompletionsToolCallDelta {
147
+ index: number;
148
+ id?: string;
149
+ type?: 'function';
150
+ function?: {
151
+ name?: string;
152
+ arguments?: string;
153
+ };
154
+ }
155
+ export interface AssembledToolCall {
156
+ id: string;
157
+ type: 'function';
158
+ name: string;
159
+ args: string;
160
+ }
161
+ export interface ChatCompletionsToolCallDeltaAccumulator {
162
+ feed(delta: ChatCompletionsToolCallDelta): void;
163
+ drain(): AssembledToolCall[];
164
+ }
165
+ export interface ChatCompletionsChunkDelta {
166
+ role?: 'assistant';
167
+ content?: string | null;
168
+ reasoning_content?: string | null;
169
+ tool_calls?: ChatCompletionsToolCallDelta[];
170
+ }
171
+ export interface ChatCompletionsChunkChoice {
172
+ index?: number;
173
+ delta?: ChatCompletionsChunkDelta;
174
+ finish_reason?: string | null;
175
+ }
176
+ export interface ChatCompletionsChunk {
177
+ id?: string;
178
+ object?: string;
179
+ created?: number;
180
+ model?: string;
181
+ choices?: ChatCompletionsChunkChoice[];
182
+ usage?: Record<string, unknown>;
183
+ }
184
+ export interface ChatCompletionsResponseMessage {
185
+ role?: 'assistant';
186
+ content?: string | null;
187
+ reasoning_content?: string | null;
188
+ tool_calls?: ChatCompletionsToolCallWire[];
189
+ }
190
+ export interface ChatCompletionsResponseChoice {
191
+ index?: number;
192
+ message?: ChatCompletionsResponseMessage;
193
+ finish_reason?: string | null;
194
+ }
195
+ export interface ChatCompletionsResponse {
196
+ id?: string;
197
+ object?: string;
198
+ created?: number;
199
+ model?: string;
200
+ choices?: ChatCompletionsResponseChoice[];
201
+ usage?: Record<string, unknown>;
202
+ }
203
+ /**
204
+ * Policy for how the OpenAI Chat Completions battery handles a {@link @nhtio/adk!Media} instance whose
205
+ * modality the wire protocol cannot natively represent (today: video).
206
+ *
207
+ * @remarks
208
+ * Three modes:
209
+ *
210
+ * - `'throw'` — raise `E_UNSUPPORTED_MEDIA_MODALITY` and fail the dispatch. Loud failure;
211
+ * the default, so a misconfigured pipeline surfaces immediately.
212
+ * - `'fallback-stash'` — look for a model-readable text entry in `media.stash`. If
213
+ * present, render that text inside the appropriate trust envelope in lieu of a media block.
214
+ * If no entry is found, fall through to `'synthetic-description'` behaviour. The shorthand
215
+ * string form uses the battery's default key list (`['text:transcript', 'text:caption',
216
+ * 'text:description']`, walked in order). The object form `{ mode: 'fallback-stash';
217
+ * stashKeys }` overrides the key list.
218
+ * - `'synthetic-description'` — always render a synthetic text description constructed from
219
+ * `filename`, `byteLength`, and `mimeType` (e.g. `[media: report.mp4, video/mp4, 38.4 MB]`)
220
+ * regardless of `stash` presence.
221
+ */
222
+ export type UnsupportedMediaPolicy = 'throw' | 'fallback-stash' | 'synthetic-description' | {
223
+ mode: 'fallback-stash';
224
+ stashKeys: ReadonlyArray<string>;
225
+ };
226
+ export interface ChatCompletionsRetryConfig {
227
+ maxAttempts?: number;
228
+ baseDelayMs?: number;
229
+ maxDelayMs?: number;
230
+ retriableStatuses?: number[];
231
+ honorRetryAfter?: boolean;
232
+ }
233
+ export interface ChatCompletionsHelpers {
234
+ descriptionToChatCompletionsJsonSchema: (d: DescriptionLike) => JsonSchema;
235
+ renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string;
236
+ renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string;
237
+ renderStandingInstructions: (items: Iterable<Tokenizable>, attrs?: StandingInstructionAttrs) => string;
238
+ renderMemories: (items: Iterable<{
239
+ memory: Memory;
240
+ attrs: MemoryAttrs;
241
+ }>) => string;
242
+ renderRetrievableSafetyDirective: () => string;
243
+ renderFirstPartyRetrievables: (items: Iterable<{
244
+ retrievable: Retrievable;
245
+ attrs: RetrievableAttrs;
246
+ }>) => string;
247
+ renderThirdPartyPublicRetrievables: (items: Iterable<{
248
+ retrievable: Retrievable;
249
+ attrs: RetrievableAttrs;
250
+ }>, deps: {
251
+ renderUntrustedContent: ChatCompletionsHelpers['renderUntrustedContent'];
252
+ }) => string;
253
+ renderThirdPartyPrivateRetrievables: (items: Iterable<{
254
+ retrievable: Retrievable;
255
+ attrs: RetrievableAttrs;
256
+ }>, deps: {
257
+ renderUntrustedContent: ChatCompletionsHelpers['renderUntrustedContent'];
258
+ }) => string;
259
+ renderRetrievables: (items: Iterable<{
260
+ retrievable: Retrievable;
261
+ attrs: RetrievableAttrs;
262
+ }>, deps: {
263
+ renderRetrievableSafetyDirective: ChatCompletionsHelpers['renderRetrievableSafetyDirective'];
264
+ renderFirstPartyRetrievables: ChatCompletionsHelpers['renderFirstPartyRetrievables'];
265
+ renderThirdPartyPublicRetrievables: ChatCompletionsHelpers['renderThirdPartyPublicRetrievables'];
266
+ renderThirdPartyPrivateRetrievables: ChatCompletionsHelpers['renderThirdPartyPrivateRetrievables'];
267
+ renderUntrustedContent: ChatCompletionsHelpers['renderUntrustedContent'];
268
+ }) => string;
269
+ renderTimelineMessage: (input: {
270
+ message: Message;
271
+ selfIdentity: string;
272
+ unsupportedMediaPolicy: UnsupportedMediaPolicy;
273
+ warn?: (msg: string) => void;
274
+ }) => Promise<ChatCompletionsMessage>;
275
+ renderThought: (content: string, attrs: ThoughtAttrs, payload?: unknown) => string;
276
+ filterThoughts: (thoughts: Iterable<Thought>, mode: 'all-self' | 'latest-self' | 'all', selfIdentity: string, replayCompatibility: ReadonlyArray<string>) => Thought[];
277
+ toolsToChatCompletionsTools: (tools: ReadonlyArray<Tool | ArtifactTool>, deps: {
278
+ descriptionToChatCompletionsJsonSchema: (d: DescriptionLike) => JsonSchema;
279
+ }) => ChatCompletionsTool[];
280
+ renderChatCompletionsSystemPrompt: (input: {
281
+ systemPrompt: Tokenizable;
282
+ standingInstructions: Iterable<Tokenizable>;
283
+ memories: Iterable<Memory>;
284
+ retrievables: Iterable<Retrievable>;
285
+ bucketOrder: ChatCompletionsBucketOrder;
286
+ renderStandingInstructions: ChatCompletionsHelpers['renderStandingInstructions'];
287
+ renderMemories: ChatCompletionsHelpers['renderMemories'];
288
+ renderRetrievables: ChatCompletionsHelpers['renderRetrievables'];
289
+ renderRetrievableSafetyDirective: ChatCompletionsHelpers['renderRetrievableSafetyDirective'];
290
+ renderFirstPartyRetrievables: ChatCompletionsHelpers['renderFirstPartyRetrievables'];
291
+ renderThirdPartyPublicRetrievables: ChatCompletionsHelpers['renderThirdPartyPublicRetrievables'];
292
+ renderThirdPartyPrivateRetrievables: ChatCompletionsHelpers['renderThirdPartyPrivateRetrievables'];
293
+ renderUntrustedContent: ChatCompletionsHelpers['renderUntrustedContent'];
294
+ }) => string;
295
+ renderChatCompletionsToolCallResult: (input: {
296
+ toolCall: ToolCall;
297
+ results: Tokenizable | SpooledArtifact | SpooledArtifact[] | Media | Media[];
298
+ tool: Tool | ArtifactTool | undefined;
299
+ renderUntrustedContent: ChatCompletionsHelpers['renderUntrustedContent'];
300
+ renderTrustedContent: ChatCompletionsHelpers['renderTrustedContent'];
301
+ unsupportedMediaPolicy: UnsupportedMediaPolicy;
302
+ warn?: (msg: string) => void;
303
+ }) => Promise<string | ChatCompletionsContentBlock[]>;
304
+ buildChatCompletionsHistory: (input: {
305
+ systemPrompt: Tokenizable;
306
+ standingInstructions: Iterable<Tokenizable>;
307
+ memories: Iterable<Memory>;
308
+ retrievables: Iterable<Retrievable>;
309
+ messages: Iterable<Message>;
310
+ thoughts: Iterable<Thought>;
311
+ toolCalls: Iterable<ToolCall>;
312
+ tools: ToolRegistry;
313
+ renderedToolCallResults: Map<string, string | ChatCompletionsContentBlock[]>;
314
+ bucketOrder: ChatCompletionsBucketOrder;
315
+ selfIdentity: string;
316
+ thoughtSurfacing: 'all-self' | 'latest-self' | 'all';
317
+ replayCompatibility: ReadonlyArray<string>;
318
+ unsupportedMediaPolicy: UnsupportedMediaPolicy;
319
+ renderChatCompletionsToolCallResult: ChatCompletionsHelpers['renderChatCompletionsToolCallResult'];
320
+ renderChatCompletionsSystemPrompt: ChatCompletionsHelpers['renderChatCompletionsSystemPrompt'];
321
+ renderStandingInstructions: ChatCompletionsHelpers['renderStandingInstructions'];
322
+ renderMemories: ChatCompletionsHelpers['renderMemories'];
323
+ renderRetrievables: ChatCompletionsHelpers['renderRetrievables'];
324
+ renderRetrievableSafetyDirective: ChatCompletionsHelpers['renderRetrievableSafetyDirective'];
325
+ renderFirstPartyRetrievables: ChatCompletionsHelpers['renderFirstPartyRetrievables'];
326
+ renderThirdPartyPublicRetrievables: ChatCompletionsHelpers['renderThirdPartyPublicRetrievables'];
327
+ renderThirdPartyPrivateRetrievables: ChatCompletionsHelpers['renderThirdPartyPrivateRetrievables'];
328
+ renderTimelineMessage: ChatCompletionsHelpers['renderTimelineMessage'];
329
+ renderThought: ChatCompletionsHelpers['renderThought'];
330
+ filterThoughts: ChatCompletionsHelpers['filterThoughts'];
331
+ renderUntrustedContent: ChatCompletionsHelpers['renderUntrustedContent'];
332
+ renderTrustedContent: ChatCompletionsHelpers['renderTrustedContent'];
333
+ warn?: (msg: string) => void;
334
+ }) => Promise<{
335
+ messages: ChatCompletionsMessage[];
336
+ reasoningPayloads: Array<{
337
+ id: string;
338
+ replayCompatibility: string;
339
+ payload: unknown;
340
+ }>;
341
+ }>;
342
+ createChatCompletionsToolCallDeltaAccumulator: () => ChatCompletionsToolCallDeltaAccumulator;
343
+ }
344
+ export interface OpenAIChatCompletionsRequestBody {
345
+ model: string;
346
+ messages: ChatCompletionsMessage[];
347
+ stream: boolean;
348
+ tools?: ChatCompletionsTool[];
349
+ /**
350
+ * Side-channel for opaque vendor reasoning payloads. Forwarded to gateways that understand
351
+ * them; stripped by gateways that don't.
352
+ */
353
+ _adk_reasoning_payloads?: Array<{
354
+ id: string;
355
+ replayCompatibility: string;
356
+ payload: unknown;
357
+ }>;
358
+ [key: string]: unknown;
359
+ }
360
+ export interface OpenAIChatCompletionsAdapterOptions {
361
+ apiKey?: string;
362
+ baseURL?: string;
363
+ headers?: Record<string, string>;
364
+ stream?: boolean;
365
+ streamIdleTimeoutMs?: number;
366
+ requestTimeoutMs?: number;
367
+ retry?: ChatCompletionsRetryConfig;
368
+ fetch?: typeof globalThis.fetch;
369
+ bucketOrder?: ChatCompletionsBucketOrder;
370
+ contextWindow?: number;
371
+ selfIdentity?: string;
372
+ thoughtSurfacing?: 'all-self' | 'latest-self' | 'all';
373
+ tokenEncoding?: TokenEncoding | null;
374
+ replayCompatibility?: ReadonlyArray<string>;
375
+ helpers?: Partial<ChatCompletionsHelpers>;
376
+ /**
377
+ * When `tool_choice` (or the `allowed_tools` variant) forces the model onto a specific tool
378
+ * name, and that name resolves to an ephemeral, forged artifact-query tool (one produced by
379
+ * `<Subclass>.forgeTools(ctx)` — i.e. `tool.ephemeral === true`), this flag controls how the
380
+ * adapter reacts:
381
+ *
382
+ * - `false` (default): emit a single `helpers.log.warn({ kind: 'tool-choice-forged-artifact', ... })`
383
+ * record and continue. Forging an artifact-query tool by name is almost always a
384
+ * misconfiguration — the tool may not exist in the next iteration once the artifact ages
385
+ * out — but the call still goes through.
386
+ * - `true`: hard-fail with `E_INVALID_OPENAI_CHAT_COMPLETIONS_OPTIONS`. Use this in
387
+ * production deployments where forcing a forged tool indicates a real bug.
388
+ *
389
+ * @defaultValue `false`
390
+ */
391
+ strictToolChoice?: boolean;
392
+ /**
393
+ * Policy for how the adapter handles a {@link @nhtio/adk!Media} instance whose modality the OpenAI Chat
394
+ * Completions wire format does not natively support (today: video). See
395
+ * {@link UnsupportedMediaPolicy}.
396
+ *
397
+ * @defaultValue `'throw'`
398
+ */
399
+ unsupportedMediaPolicy?: UnsupportedMediaPolicy;
400
+ /**
401
+ * Whether the executor should call {@link @nhtio/adk!DispatchContext.ack | ctx.ack()} itself when a
402
+ * generation completes with no tool calls (a terminal text answer).
403
+ *
404
+ * @remarks
405
+ * `ack()` is terminal and one-shot: once called, the dispatch loop exits after the current
406
+ * iteration. When the executor acks automatically, it seizes turn-completion control from the
407
+ * implementor — a `dispatchOutputPipeline` quality gate can never run, because the signal is
408
+ * already set before the output pipeline executes.
409
+ *
410
+ * This option therefore defaults to **`false`** (opt-in). With `autoAck: false`, a tool-call-free
411
+ * response leaves the context unsignalled and the executor returns; the implementor's output
412
+ * pipeline (or a later iteration) is responsible for calling `ctx.ack()` / `ctx.nack()`. This is
413
+ * the seam that makes output-side quality gates (citation enforcement, schema validation,
414
+ * regenerate-on-reject) possible.
415
+ *
416
+ * Set `autoAck: true` to restore single-shot behavior: the executor acks the moment a
417
+ * tool-call-free answer finishes, terminating the turn without giving the output pipeline a vote.
418
+ * The tool-call path is unaffected by this flag — it always withholds ack so the runner can
419
+ * iterate and execute the calls. Error paths always {@link @nhtio/adk!DispatchContext.nack | nack}
420
+ * regardless of this flag.
421
+ *
422
+ * @defaultValue `false`
423
+ */
424
+ autoAck?: boolean;
425
+ model: string;
426
+ audio?: {
427
+ voice: string;
428
+ format: 'wav' | 'mp3' | 'flac' | 'opus' | 'pcm16';
429
+ };
430
+ frequency_penalty?: number;
431
+ function_call?: 'none' | 'auto' | {
432
+ name: string;
433
+ };
434
+ functions?: Array<{
435
+ name: string;
436
+ description?: string;
437
+ parameters?: JsonSchema;
438
+ }>;
439
+ logit_bias?: Record<string, number>;
440
+ logprobs?: boolean;
441
+ max_completion_tokens?: number;
442
+ max_tokens?: number;
443
+ metadata?: Record<string, string>;
444
+ modalities?: Array<'text' | 'audio'>;
445
+ n?: number;
446
+ parallel_tool_calls?: boolean;
447
+ prediction?: {
448
+ type: 'content';
449
+ content: string | Array<{
450
+ type: 'text';
451
+ text: string;
452
+ }>;
453
+ };
454
+ presence_penalty?: number;
455
+ prompt_cache_key?: string;
456
+ prompt_cache_retention?: 'in_memory' | '24h';
457
+ reasoning_effort?: 'minimal' | 'low' | 'medium' | 'high';
458
+ response_format?: {
459
+ type: 'text';
460
+ } | {
461
+ type: 'json_object';
462
+ } | {
463
+ type: 'json_schema';
464
+ json_schema: {
465
+ name: string;
466
+ schema: JsonSchema;
467
+ strict?: boolean;
468
+ description?: string;
469
+ };
470
+ };
471
+ safety_identifier?: string;
472
+ seed?: number;
473
+ service_tier?: 'auto' | 'default' | 'flex' | 'priority' | 'scale';
474
+ stop?: string | string[];
475
+ store?: boolean;
476
+ stream_options?: {
477
+ include_usage?: boolean;
478
+ include_obfuscation?: boolean;
479
+ };
480
+ temperature?: number;
481
+ tool_choice?: 'none' | 'auto' | 'required' | {
482
+ type: 'function';
483
+ function: {
484
+ name: string;
485
+ };
486
+ } | {
487
+ type: 'custom';
488
+ custom: {
489
+ name: string;
490
+ };
491
+ } | {
492
+ type: 'allowed_tools';
493
+ allowed_tools: {
494
+ mode: 'auto' | 'required';
495
+ tools: Array<{
496
+ type: 'function';
497
+ function: {
498
+ name: string;
499
+ };
500
+ } | {
501
+ type: 'custom';
502
+ custom: {
503
+ name: string;
504
+ };
505
+ }>;
506
+ };
507
+ };
508
+ top_logprobs?: number;
509
+ top_p?: number;
510
+ user?: string;
511
+ verbosity?: 'low' | 'medium' | 'high';
512
+ web_search_options?: {
513
+ search_context_size?: 'low' | 'medium' | 'high';
514
+ user_location?: {
515
+ type: 'approximate';
516
+ approximate: {
517
+ city?: string;
518
+ country?: string;
519
+ region?: string;
520
+ timezone?: string;
521
+ };
522
+ };
523
+ };
524
+ }