@dirgha/code 1.2.0

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 (360) hide show
  1. package/LICENSE +101 -0
  2. package/README.md +674 -0
  3. package/dist/dirgha.mjs +2185 -0
  4. package/dist_v2/acp/index.d.ts +1 -0
  5. package/dist_v2/acp/index.js +2 -0
  6. package/dist_v2/acp/server.d.ts +31 -0
  7. package/dist_v2/acp/server.js +137 -0
  8. package/dist_v2/cli/auth-cmd.d.ts +10 -0
  9. package/dist_v2/cli/auth-cmd.js +69 -0
  10. package/dist_v2/cli/config.d.ts +46 -0
  11. package/dist_v2/cli/config.js +70 -0
  12. package/dist_v2/cli/flags.d.ts +10 -0
  13. package/dist_v2/cli/flags.js +49 -0
  14. package/dist_v2/cli/flows/full-cycle.d.ts +30 -0
  15. package/dist_v2/cli/flows/full-cycle.js +39 -0
  16. package/dist_v2/cli/flows/index.d.ts +2 -0
  17. package/dist_v2/cli/flows/index.js +3 -0
  18. package/dist_v2/cli/flows/tarball.d.ts +10 -0
  19. package/dist_v2/cli/flows/tarball.js +47 -0
  20. package/dist_v2/cli/index.d.ts +4 -0
  21. package/dist_v2/cli/index.js +5 -0
  22. package/dist_v2/cli/interactive.d.ts +21 -0
  23. package/dist_v2/cli/interactive.js +207 -0
  24. package/dist_v2/cli/main.d.ts +10 -0
  25. package/dist_v2/cli/main.js +173 -0
  26. package/dist_v2/cli/models-cmd.d.ts +6 -0
  27. package/dist_v2/cli/models-cmd.js +50 -0
  28. package/dist_v2/cli/setup.d.ts +13 -0
  29. package/dist_v2/cli/setup.js +128 -0
  30. package/dist_v2/cli/slash/account.d.ts +10 -0
  31. package/dist_v2/cli/slash/account.js +59 -0
  32. package/dist_v2/cli/slash/clear.d.ts +8 -0
  33. package/dist_v2/cli/slash/clear.js +15 -0
  34. package/dist_v2/cli/slash/compact.d.ts +7 -0
  35. package/dist_v2/cli/slash/compact.js +13 -0
  36. package/dist_v2/cli/slash/config.d.ts +8 -0
  37. package/dist_v2/cli/slash/config.js +49 -0
  38. package/dist_v2/cli/slash/exit.d.ts +7 -0
  39. package/dist_v2/cli/slash/exit.js +16 -0
  40. package/dist_v2/cli/slash/fleet.d.ts +7 -0
  41. package/dist_v2/cli/slash/fleet.js +22 -0
  42. package/dist_v2/cli/slash/help.d.ts +9 -0
  43. package/dist_v2/cli/slash/help.js +31 -0
  44. package/dist_v2/cli/slash/history.d.ts +7 -0
  45. package/dist_v2/cli/slash/history.js +42 -0
  46. package/dist_v2/cli/slash/index.d.ts +30 -0
  47. package/dist_v2/cli/slash/index.js +52 -0
  48. package/dist_v2/cli/slash/init.d.ts +8 -0
  49. package/dist_v2/cli/slash/init.js +57 -0
  50. package/dist_v2/cli/slash/keys.d.ts +8 -0
  51. package/dist_v2/cli/slash/keys.js +101 -0
  52. package/dist_v2/cli/slash/login.d.ts +10 -0
  53. package/dist_v2/cli/slash/login.js +47 -0
  54. package/dist_v2/cli/slash/memory.d.ts +8 -0
  55. package/dist_v2/cli/slash/memory.js +101 -0
  56. package/dist_v2/cli/slash/mode.d.ts +8 -0
  57. package/dist_v2/cli/slash/mode.js +30 -0
  58. package/dist_v2/cli/slash/models.d.ts +8 -0
  59. package/dist_v2/cli/slash/models.js +73 -0
  60. package/dist_v2/cli/slash/resume.d.ts +8 -0
  61. package/dist_v2/cli/slash/resume.js +24 -0
  62. package/dist_v2/cli/slash/session.d.ts +8 -0
  63. package/dist_v2/cli/slash/session.js +74 -0
  64. package/dist_v2/cli/slash/setup.d.ts +8 -0
  65. package/dist_v2/cli/slash/setup.js +50 -0
  66. package/dist_v2/cli/slash/status.d.ts +7 -0
  67. package/dist_v2/cli/slash/status.js +37 -0
  68. package/dist_v2/cli/slash/theme.d.ts +9 -0
  69. package/dist_v2/cli/slash/theme.js +53 -0
  70. package/dist_v2/cli/slash/types.d.ts +14 -0
  71. package/dist_v2/cli/slash/types.js +9 -0
  72. package/dist_v2/cli/slash/upgrade.d.ts +9 -0
  73. package/dist_v2/cli/slash/upgrade.js +66 -0
  74. package/dist_v2/cli/slash.d.ts +72 -0
  75. package/dist_v2/cli/slash.js +77 -0
  76. package/dist_v2/cli/subcommands/ask.d.ts +17 -0
  77. package/dist_v2/cli/subcommands/ask.js +76 -0
  78. package/dist_v2/cli/subcommands/audit.d.ts +15 -0
  79. package/dist_v2/cli/subcommands/audit.js +128 -0
  80. package/dist_v2/cli/subcommands/chat.d.ts +13 -0
  81. package/dist_v2/cli/subcommands/chat.js +72 -0
  82. package/dist_v2/cli/subcommands/compact.d.ts +14 -0
  83. package/dist_v2/cli/subcommands/compact.js +114 -0
  84. package/dist_v2/cli/subcommands/doctor.d.ts +11 -0
  85. package/dist_v2/cli/subcommands/doctor.js +103 -0
  86. package/dist_v2/cli/subcommands/export-session.d.ts +10 -0
  87. package/dist_v2/cli/subcommands/export-session.js +60 -0
  88. package/dist_v2/cli/subcommands/import-session.d.ts +11 -0
  89. package/dist_v2/cli/subcommands/import-session.js +77 -0
  90. package/dist_v2/cli/subcommands/index.d.ts +40 -0
  91. package/dist_v2/cli/subcommands/index.js +38 -0
  92. package/dist_v2/cli/subcommands/init.d.ts +10 -0
  93. package/dist_v2/cli/subcommands/init.js +74 -0
  94. package/dist_v2/cli/subcommands/keys.d.ts +12 -0
  95. package/dist_v2/cli/subcommands/keys.js +136 -0
  96. package/dist_v2/cli/subcommands/login.d.ts +10 -0
  97. package/dist_v2/cli/subcommands/login.js +60 -0
  98. package/dist_v2/cli/subcommands/logout.d.ts +10 -0
  99. package/dist_v2/cli/subcommands/logout.js +21 -0
  100. package/dist_v2/cli/subcommands/models.d.ts +14 -0
  101. package/dist_v2/cli/subcommands/models.js +144 -0
  102. package/dist_v2/cli/subcommands/setup.d.ts +11 -0
  103. package/dist_v2/cli/subcommands/setup.js +107 -0
  104. package/dist_v2/cli/subcommands/stats.d.ts +13 -0
  105. package/dist_v2/cli/subcommands/stats.js +148 -0
  106. package/dist_v2/cli/subcommands/status.d.ts +14 -0
  107. package/dist_v2/cli/subcommands/status.js +91 -0
  108. package/dist_v2/cli/submit-paper.d.ts +15 -0
  109. package/dist_v2/cli/submit-paper.js +68 -0
  110. package/dist_v2/context/_fts.d.ts +62 -0
  111. package/dist_v2/context/_fts.js +195 -0
  112. package/dist_v2/context/branch.d.ts +18 -0
  113. package/dist_v2/context/branch.js +66 -0
  114. package/dist_v2/context/compaction.d.ts +26 -0
  115. package/dist_v2/context/compaction.js +120 -0
  116. package/dist_v2/context/index.d.ts +5 -0
  117. package/dist_v2/context/index.js +6 -0
  118. package/dist_v2/context/knowledge.d.ts +38 -0
  119. package/dist_v2/context/knowledge.js +146 -0
  120. package/dist_v2/context/memory.d.ts +80 -0
  121. package/dist_v2/context/memory.js +276 -0
  122. package/dist_v2/context/mode.d.ts +25 -0
  123. package/dist_v2/context/mode.js +81 -0
  124. package/dist_v2/context/session.d.ts +56 -0
  125. package/dist_v2/context/session.js +108 -0
  126. package/dist_v2/daemon/index.d.ts +2 -0
  127. package/dist_v2/daemon/index.js +3 -0
  128. package/dist_v2/daemon/protocol.d.ts +73 -0
  129. package/dist_v2/daemon/protocol.js +6 -0
  130. package/dist_v2/daemon/server.d.ts +35 -0
  131. package/dist_v2/daemon/server.js +191 -0
  132. package/dist_v2/eval/index.d.ts +5 -0
  133. package/dist_v2/eval/index.js +6 -0
  134. package/dist_v2/eval/regression.d.ts +14 -0
  135. package/dist_v2/eval/regression.js +106 -0
  136. package/dist_v2/eval/reporter.d.ts +7 -0
  137. package/dist_v2/eval/reporter.js +34 -0
  138. package/dist_v2/eval/swe-bench.d.ts +18 -0
  139. package/dist_v2/eval/swe-bench.js +23 -0
  140. package/dist_v2/eval/terminal-bench.d.ts +13 -0
  141. package/dist_v2/eval/terminal-bench.js +19 -0
  142. package/dist_v2/eval/types.d.ts +36 -0
  143. package/dist_v2/eval/types.js +5 -0
  144. package/dist_v2/fleet/apply-back.d.ts +27 -0
  145. package/dist_v2/fleet/apply-back.js +191 -0
  146. package/dist_v2/fleet/cli-command.d.ts +61 -0
  147. package/dist_v2/fleet/cli-command.js +329 -0
  148. package/dist_v2/fleet/index.d.ts +21 -0
  149. package/dist_v2/fleet/index.js +21 -0
  150. package/dist_v2/fleet/runner.d.ts +28 -0
  151. package/dist_v2/fleet/runner.js +347 -0
  152. package/dist_v2/fleet/tripleshot.d.ts +21 -0
  153. package/dist_v2/fleet/tripleshot.js +222 -0
  154. package/dist_v2/fleet/types.d.ts +193 -0
  155. package/dist_v2/fleet/types.js +24 -0
  156. package/dist_v2/fleet/worktree.d.ts +51 -0
  157. package/dist_v2/fleet/worktree.js +176 -0
  158. package/dist_v2/hooks/index.d.ts +1 -0
  159. package/dist_v2/hooks/index.js +2 -0
  160. package/dist_v2/hooks/registry.d.ts +21 -0
  161. package/dist_v2/hooks/registry.js +40 -0
  162. package/dist_v2/index.d.ts +12 -0
  163. package/dist_v2/index.js +11 -0
  164. package/dist_v2/integrations/arniko-client.d.ts +42 -0
  165. package/dist_v2/integrations/arniko-client.js +86 -0
  166. package/dist_v2/integrations/auth.d.ts +45 -0
  167. package/dist_v2/integrations/auth.js +54 -0
  168. package/dist_v2/integrations/billing.d.ts +71 -0
  169. package/dist_v2/integrations/billing.js +107 -0
  170. package/dist_v2/integrations/bucky-client.d.ts +105 -0
  171. package/dist_v2/integrations/bucky-client.js +76 -0
  172. package/dist_v2/integrations/deploy-client.d.ts +60 -0
  173. package/dist_v2/integrations/deploy-client.js +87 -0
  174. package/dist_v2/integrations/device-auth.d.ts +48 -0
  175. package/dist_v2/integrations/device-auth.js +192 -0
  176. package/dist_v2/integrations/entitlements.d.ts +34 -0
  177. package/dist_v2/integrations/entitlements.js +43 -0
  178. package/dist_v2/integrations/http.d.ts +22 -0
  179. package/dist_v2/integrations/http.js +114 -0
  180. package/dist_v2/integrations/index.d.ts +8 -0
  181. package/dist_v2/integrations/index.js +15 -0
  182. package/dist_v2/intelligence/cost.d.ts +28 -0
  183. package/dist_v2/intelligence/cost.js +58 -0
  184. package/dist_v2/intelligence/error-classifier.d.ts +8 -0
  185. package/dist_v2/intelligence/error-classifier.js +71 -0
  186. package/dist_v2/intelligence/index.d.ts +5 -0
  187. package/dist_v2/intelligence/index.js +6 -0
  188. package/dist_v2/intelligence/prices.d.ts +13 -0
  189. package/dist_v2/intelligence/prices.js +26 -0
  190. package/dist_v2/intelligence/smart-router.d.ts +21 -0
  191. package/dist_v2/intelligence/smart-router.js +59 -0
  192. package/dist_v2/intelligence/telemetry.d.ts +22 -0
  193. package/dist_v2/intelligence/telemetry.js +31 -0
  194. package/dist_v2/kernel/agent-loop.d.ts +32 -0
  195. package/dist_v2/kernel/agent-loop.js +151 -0
  196. package/dist_v2/kernel/event-stream.d.ts +18 -0
  197. package/dist_v2/kernel/event-stream.js +102 -0
  198. package/dist_v2/kernel/index.d.ts +4 -0
  199. package/dist_v2/kernel/index.js +5 -0
  200. package/dist_v2/kernel/message.d.ts +29 -0
  201. package/dist_v2/kernel/message.js +118 -0
  202. package/dist_v2/kernel/types.d.ts +206 -0
  203. package/dist_v2/kernel/types.js +9 -0
  204. package/dist_v2/mcp/client.d.ts +44 -0
  205. package/dist_v2/mcp/client.js +63 -0
  206. package/dist_v2/mcp/index.d.ts +3 -0
  207. package/dist_v2/mcp/index.js +4 -0
  208. package/dist_v2/mcp/tool-bridge.d.ts +11 -0
  209. package/dist_v2/mcp/tool-bridge.js +33 -0
  210. package/dist_v2/mcp/transport.d.ts +29 -0
  211. package/dist_v2/mcp/transport.js +73 -0
  212. package/dist_v2/parity/index.d.ts +3 -0
  213. package/dist_v2/parity/index.js +4 -0
  214. package/dist_v2/parity/mock-openai-compat.d.ts +15 -0
  215. package/dist_v2/parity/mock-openai-compat.js +35 -0
  216. package/dist_v2/parity/runner.d.ts +21 -0
  217. package/dist_v2/parity/runner.js +76 -0
  218. package/dist_v2/parity/scenarios.d.ts +20 -0
  219. package/dist_v2/parity/scenarios.js +70 -0
  220. package/dist_v2/providers/anthropic.d.ts +21 -0
  221. package/dist_v2/providers/anthropic.js +191 -0
  222. package/dist_v2/providers/dispatch.d.ts +11 -0
  223. package/dist_v2/providers/dispatch.js +45 -0
  224. package/dist_v2/providers/fireworks.d.ts +18 -0
  225. package/dist_v2/providers/fireworks.js +44 -0
  226. package/dist_v2/providers/gemini.d.ts +19 -0
  227. package/dist_v2/providers/gemini.js +188 -0
  228. package/dist_v2/providers/http.d.ts +41 -0
  229. package/dist_v2/providers/http.js +188 -0
  230. package/dist_v2/providers/iface.d.ts +18 -0
  231. package/dist_v2/providers/iface.js +18 -0
  232. package/dist_v2/providers/index.d.ts +39 -0
  233. package/dist_v2/providers/index.js +51 -0
  234. package/dist_v2/providers/nvidia.d.ts +27 -0
  235. package/dist_v2/providers/nvidia.js +142 -0
  236. package/dist_v2/providers/ollama.d.ts +15 -0
  237. package/dist_v2/providers/ollama.js +37 -0
  238. package/dist_v2/providers/openai-compat.d.ts +29 -0
  239. package/dist_v2/providers/openai-compat.js +239 -0
  240. package/dist_v2/providers/openai.d.ts +20 -0
  241. package/dist_v2/providers/openai.js +107 -0
  242. package/dist_v2/providers/openrouter.d.ts +24 -0
  243. package/dist_v2/providers/openrouter.js +69 -0
  244. package/dist_v2/safety/approval-bus.d.ts +26 -0
  245. package/dist_v2/safety/approval-bus.js +48 -0
  246. package/dist_v2/safety/audit-log.d.ts +27 -0
  247. package/dist_v2/safety/audit-log.js +71 -0
  248. package/dist_v2/safety/index.d.ts +4 -0
  249. package/dist_v2/safety/index.js +5 -0
  250. package/dist_v2/safety/policy.d.ts +32 -0
  251. package/dist_v2/safety/policy.js +131 -0
  252. package/dist_v2/safety/sandbox/bwrap.d.ts +11 -0
  253. package/dist_v2/safety/sandbox/bwrap.js +52 -0
  254. package/dist_v2/safety/sandbox/iface.d.ts +29 -0
  255. package/dist_v2/safety/sandbox/iface.js +8 -0
  256. package/dist_v2/safety/sandbox/index.d.ts +7 -0
  257. package/dist_v2/safety/sandbox/index.js +8 -0
  258. package/dist_v2/safety/sandbox/landlock.d.ts +17 -0
  259. package/dist_v2/safety/sandbox/landlock.js +26 -0
  260. package/dist_v2/safety/sandbox/noop.d.ts +12 -0
  261. package/dist_v2/safety/sandbox/noop.js +52 -0
  262. package/dist_v2/safety/sandbox/seatbelt.d.ts +11 -0
  263. package/dist_v2/safety/sandbox/seatbelt.js +49 -0
  264. package/dist_v2/safety/sandbox/select.d.ts +6 -0
  265. package/dist_v2/safety/sandbox/select.js +42 -0
  266. package/dist_v2/safety/sandbox/windows.d.ts +13 -0
  267. package/dist_v2/safety/sandbox/windows.js +22 -0
  268. package/dist_v2/skills/index.d.ts +3 -0
  269. package/dist_v2/skills/index.js +4 -0
  270. package/dist_v2/skills/loader.d.ts +38 -0
  271. package/dist_v2/skills/loader.js +102 -0
  272. package/dist_v2/skills/matcher.d.ts +14 -0
  273. package/dist_v2/skills/matcher.js +72 -0
  274. package/dist_v2/skills/runtime.d.ts +13 -0
  275. package/dist_v2/skills/runtime.js +40 -0
  276. package/dist_v2/subagents/delegator.d.ts +36 -0
  277. package/dist_v2/subagents/delegator.js +82 -0
  278. package/dist_v2/subagents/index.d.ts +2 -0
  279. package/dist_v2/subagents/index.js +3 -0
  280. package/dist_v2/subagents/pool.d.ts +18 -0
  281. package/dist_v2/subagents/pool.js +31 -0
  282. package/dist_v2/tools/browser.d.ts +27 -0
  283. package/dist_v2/tools/browser.js +179 -0
  284. package/dist_v2/tools/checkpoint.d.ts +25 -0
  285. package/dist_v2/tools/checkpoint.js +222 -0
  286. package/dist_v2/tools/cron.d.ts +32 -0
  287. package/dist_v2/tools/cron.js +160 -0
  288. package/dist_v2/tools/diff.d.ts +18 -0
  289. package/dist_v2/tools/diff.js +117 -0
  290. package/dist_v2/tools/exec.d.ts +19 -0
  291. package/dist_v2/tools/exec.js +49 -0
  292. package/dist_v2/tools/fs-edit.d.ts +11 -0
  293. package/dist_v2/tools/fs-edit.js +81 -0
  294. package/dist_v2/tools/fs-ls.d.ts +7 -0
  295. package/dist_v2/tools/fs-ls.js +57 -0
  296. package/dist_v2/tools/fs-read.d.ts +7 -0
  297. package/dist_v2/tools/fs-read.js +60 -0
  298. package/dist_v2/tools/fs-write.d.ts +8 -0
  299. package/dist_v2/tools/fs-write.js +46 -0
  300. package/dist_v2/tools/git.d.ts +8 -0
  301. package/dist_v2/tools/git.js +57 -0
  302. package/dist_v2/tools/index.d.ts +25 -0
  303. package/dist_v2/tools/index.js +39 -0
  304. package/dist_v2/tools/multimodal.d.ts +41 -0
  305. package/dist_v2/tools/multimodal.js +381 -0
  306. package/dist_v2/tools/permission.d.ts +27 -0
  307. package/dist_v2/tools/permission.js +43 -0
  308. package/dist_v2/tools/registry.d.ts +44 -0
  309. package/dist_v2/tools/registry.js +62 -0
  310. package/dist_v2/tools/search-glob.d.ts +7 -0
  311. package/dist_v2/tools/search-glob.js +98 -0
  312. package/dist_v2/tools/search-grep.d.ts +7 -0
  313. package/dist_v2/tools/search-grep.js +109 -0
  314. package/dist_v2/tools/shell.d.ts +10 -0
  315. package/dist_v2/tools/shell.js +76 -0
  316. package/dist_v2/tools/task.d.ts +8 -0
  317. package/dist_v2/tools/task.js +37 -0
  318. package/dist_v2/tui/approval.d.ts +7 -0
  319. package/dist_v2/tui/approval.js +55 -0
  320. package/dist_v2/tui/index.d.ts +4 -0
  321. package/dist_v2/tui/index.js +5 -0
  322. package/dist_v2/tui/ink/App.d.ts +39 -0
  323. package/dist_v2/tui/ink/App.js +206 -0
  324. package/dist_v2/tui/ink/components/AtFileComplete.d.ts +25 -0
  325. package/dist_v2/tui/ink/components/AtFileComplete.js +158 -0
  326. package/dist_v2/tui/ink/components/HelpOverlay.d.ts +24 -0
  327. package/dist_v2/tui/ink/components/HelpOverlay.js +130 -0
  328. package/dist_v2/tui/ink/components/InputBox.d.ts +35 -0
  329. package/dist_v2/tui/ink/components/InputBox.js +153 -0
  330. package/dist_v2/tui/ink/components/Logo.d.ts +12 -0
  331. package/dist_v2/tui/ink/components/Logo.js +27 -0
  332. package/dist_v2/tui/ink/components/ModelPicker.d.ts +26 -0
  333. package/dist_v2/tui/ink/components/ModelPicker.js +80 -0
  334. package/dist_v2/tui/ink/components/PasteCollapse.d.ts +36 -0
  335. package/dist_v2/tui/ink/components/PasteCollapse.js +59 -0
  336. package/dist_v2/tui/ink/components/StatusBar.d.ts +18 -0
  337. package/dist_v2/tui/ink/components/StatusBar.js +41 -0
  338. package/dist_v2/tui/ink/components/StreamingText.d.ts +14 -0
  339. package/dist_v2/tui/ink/components/StreamingText.js +11 -0
  340. package/dist_v2/tui/ink/components/ThinkingBlock.d.ts +13 -0
  341. package/dist_v2/tui/ink/components/ThinkingBlock.js +13 -0
  342. package/dist_v2/tui/ink/components/ToolBox.d.ts +20 -0
  343. package/dist_v2/tui/ink/components/ToolBox.js +63 -0
  344. package/dist_v2/tui/ink/components/vim-bindings.d.ts +43 -0
  345. package/dist_v2/tui/ink/components/vim-bindings.js +135 -0
  346. package/dist_v2/tui/ink/index.d.ts +39 -0
  347. package/dist_v2/tui/ink/index.js +47 -0
  348. package/dist_v2/tui/ink/use-event-projection.d.ts +51 -0
  349. package/dist_v2/tui/ink/use-event-projection.js +126 -0
  350. package/dist_v2/tui/ink/use-overlays.d.ts +24 -0
  351. package/dist_v2/tui/ink/use-overlays.js +50 -0
  352. package/dist_v2/tui/renderer.d.ts +19 -0
  353. package/dist_v2/tui/renderer.js +64 -0
  354. package/dist_v2/tui/status-bar.d.ts +12 -0
  355. package/dist_v2/tui/status-bar.js +16 -0
  356. package/dist_v2/tui/theme.d.ts +27 -0
  357. package/dist_v2/tui/theme.js +56 -0
  358. package/dist_v2/utils/json-repair.d.ts +7 -0
  359. package/dist_v2/utils/json-repair.js +45 -0
  360. package/package.json +113 -0
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Scripted parity scenarios. Each scenario describes a sequence of
3
+ * inputs (messages, tool stubs) and the expected event sequence from
4
+ * the provider adapter under test. Scenarios are format-agnostic; the
5
+ * runner maps them onto mock HTTP servers per provider.
6
+ */
7
+ export const DEFAULT_SCENARIOS = [
8
+ {
9
+ name: 'streaming_text_basic',
10
+ provider: 'nvidia',
11
+ model: 'moonshotai/kimi-k2-instruct',
12
+ request: {
13
+ messages: [{ role: 'user', content: 'Say PONG' }],
14
+ },
15
+ mockChunks: [
16
+ JSON.stringify({ choices: [{ delta: { content: 'PO' } }] }),
17
+ JSON.stringify({ choices: [{ delta: { content: 'NG' } }] }),
18
+ JSON.stringify({ choices: [{ delta: {}, finish_reason: 'stop' }], usage: { prompt_tokens: 5, completion_tokens: 2 } }),
19
+ '[DONE]',
20
+ ],
21
+ expectedEventTypes: ['text_start', 'text_delta', 'text_delta', 'text_end', 'usage'],
22
+ },
23
+ {
24
+ name: 'tool_call_roundtrip',
25
+ provider: 'nvidia',
26
+ model: 'moonshotai/kimi-k2-instruct',
27
+ request: {
28
+ messages: [{ role: 'user', content: 'list files' }],
29
+ tools: [{
30
+ name: 'fs_ls',
31
+ description: 'List files',
32
+ inputSchema: { type: 'object', properties: { path: { type: 'string' } } },
33
+ }],
34
+ },
35
+ mockChunks: [
36
+ JSON.stringify({
37
+ choices: [{
38
+ delta: {
39
+ tool_calls: [{ index: 0, id: 'call-1', function: { name: 'fs_ls', arguments: '{"path":' } }],
40
+ },
41
+ }],
42
+ }),
43
+ JSON.stringify({
44
+ choices: [{
45
+ delta: { tool_calls: [{ index: 0, function: { arguments: '"."}' } }] },
46
+ finish_reason: 'tool_calls',
47
+ }],
48
+ usage: { prompt_tokens: 8, completion_tokens: 4 },
49
+ }),
50
+ '[DONE]',
51
+ ],
52
+ expectedEventTypes: ['toolcall_start', 'toolcall_delta', 'toolcall_delta', 'toolcall_end', 'usage'],
53
+ },
54
+ {
55
+ name: 'unicode_text',
56
+ provider: 'openrouter',
57
+ model: 'inclusionai/ling-2.6-1t:free',
58
+ request: {
59
+ messages: [{ role: 'user', content: 'echo emoji' }],
60
+ },
61
+ mockChunks: [
62
+ JSON.stringify({ choices: [{ delta: { content: '✨' } }] }),
63
+ JSON.stringify({ choices: [{ delta: { content: ' done' } }] }),
64
+ JSON.stringify({ choices: [{ delta: {}, finish_reason: 'stop' }], usage: { prompt_tokens: 3, completion_tokens: 2 } }),
65
+ '[DONE]',
66
+ ],
67
+ expectedEventTypes: ['text_start', 'text_delta', 'text_delta', 'text_end', 'usage'],
68
+ },
69
+ ];
70
+ //# sourceMappingURL=scenarios.js.map
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Anthropic provider. Uses the Messages API (/v1/messages) with its own
3
+ * SSE event shape (content_block_start, content_block_delta,
4
+ * content_block_stop, message_delta, message_stop). Event-to-kernel
5
+ * mapping is bespoke; it does not share the openai-compat adapter.
6
+ */
7
+ import type { AgentEvent } from '../kernel/types.js';
8
+ import type { Provider, StreamRequest, ProviderConfig } from './iface.js';
9
+ export declare class AnthropicProvider implements Provider {
10
+ readonly id = "anthropic";
11
+ private readonly apiKey;
12
+ private readonly baseUrl;
13
+ private readonly version;
14
+ private readonly timeoutMs;
15
+ constructor(config: ProviderConfig & {
16
+ version?: string;
17
+ });
18
+ supportsTools(_modelId: string): boolean;
19
+ supportsThinking(modelId: string): boolean;
20
+ stream(req: StreamRequest): AsyncIterable<AgentEvent>;
21
+ }
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Anthropic provider. Uses the Messages API (/v1/messages) with its own
3
+ * SSE event shape (content_block_start, content_block_delta,
4
+ * content_block_stop, message_delta, message_stop). Event-to-kernel
5
+ * mapping is bespoke; it does not share the openai-compat adapter.
6
+ */
7
+ import { ProviderError } from './iface.js';
8
+ import { streamSSE } from './http.js';
9
+ const DEFAULT_BASE = 'https://api.anthropic.com/v1';
10
+ const DEFAULT_VERSION = '2023-06-01';
11
+ export class AnthropicProvider {
12
+ id = 'anthropic';
13
+ apiKey;
14
+ baseUrl;
15
+ version;
16
+ timeoutMs;
17
+ constructor(config) {
18
+ this.apiKey = config.apiKey ?? process.env.ANTHROPIC_API_KEY ?? '';
19
+ if (!this.apiKey)
20
+ throw new ProviderError('ANTHROPIC_API_KEY is required', this.id);
21
+ this.baseUrl = (config.baseUrl ?? DEFAULT_BASE).replace(/\/+$/, '');
22
+ this.version = config.version ?? DEFAULT_VERSION;
23
+ this.timeoutMs = config.timeoutMs ?? 60_000;
24
+ }
25
+ supportsTools(_modelId) {
26
+ return true;
27
+ }
28
+ supportsThinking(modelId) {
29
+ return /claude-(opus|sonnet|haiku)-[0-9]/.test(modelId);
30
+ }
31
+ async *stream(req) {
32
+ const model = req.model.replace(/^anthropic\//, '');
33
+ const { system, messages } = splitSystem(req.messages);
34
+ const body = {
35
+ model,
36
+ messages: messages.map(toAnthropicMessage),
37
+ max_tokens: req.maxTokens ?? 4096,
38
+ stream: true,
39
+ };
40
+ if (system)
41
+ body.system = system;
42
+ if (req.temperature !== undefined)
43
+ body.temperature = req.temperature;
44
+ if (req.tools && req.tools.length > 0) {
45
+ body.tools = req.tools.map(t => ({
46
+ name: t.name,
47
+ description: t.description,
48
+ input_schema: t.inputSchema ?? { type: 'object', properties: {} },
49
+ }));
50
+ }
51
+ if (req.thinking && req.thinking !== 'off' && this.supportsThinking(req.model)) {
52
+ const budget = req.thinking === 'low' ? 1024 : req.thinking === 'medium' ? 4096 : 16384;
53
+ body.thinking = { type: 'enabled', budget_tokens: budget };
54
+ }
55
+ const state = new AnthropicState();
56
+ for await (const payload of streamSSE({
57
+ providerName: this.id,
58
+ url: `${this.baseUrl}/messages`,
59
+ apiKey: this.apiKey,
60
+ body,
61
+ signal: req.signal,
62
+ timeoutMs: this.timeoutMs,
63
+ extraHeaders: {
64
+ 'x-api-key': this.apiKey,
65
+ 'anthropic-version': this.version,
66
+ },
67
+ })) {
68
+ let event;
69
+ try {
70
+ event = JSON.parse(payload);
71
+ }
72
+ catch {
73
+ continue;
74
+ }
75
+ yield* state.ingest(event);
76
+ }
77
+ }
78
+ }
79
+ function splitSystem(messages) {
80
+ const systemTexts = [];
81
+ const rest = [];
82
+ for (const m of messages) {
83
+ if (m.role === 'system') {
84
+ const t = typeof m.content === 'string'
85
+ ? m.content
86
+ : m.content.filter((p) => p.type === 'text').map(p => p.text).join('');
87
+ systemTexts.push(t);
88
+ }
89
+ else {
90
+ rest.push(m);
91
+ }
92
+ }
93
+ return { system: systemTexts.length > 0 ? systemTexts.join('\n\n') : undefined, messages: rest };
94
+ }
95
+ function toAnthropicMessage(msg) {
96
+ if (typeof msg.content === 'string') {
97
+ return { role: msg.role === 'assistant' ? 'assistant' : 'user', content: [{ type: 'text', text: msg.content }] };
98
+ }
99
+ const blocks = [];
100
+ for (const p of msg.content) {
101
+ if (p.type === 'text')
102
+ blocks.push({ type: 'text', text: p.text });
103
+ else if (p.type === 'thinking')
104
+ blocks.push({ type: 'thinking', thinking: p.text });
105
+ else if (p.type === 'tool_use')
106
+ blocks.push({ type: 'tool_use', id: p.id, name: p.name, input: p.input ?? {} });
107
+ else if (p.type === 'tool_result')
108
+ blocks.push({ type: 'tool_result', tool_use_id: p.toolUseId, content: p.content });
109
+ }
110
+ return { role: msg.role === 'assistant' ? 'assistant' : 'user', content: blocks };
111
+ }
112
+ class AnthropicState {
113
+ blocks = new Map();
114
+ *ingest(ev) {
115
+ switch (ev.type) {
116
+ case 'content_block_start': {
117
+ const index = ev.index ?? 0;
118
+ const block = ev.content_block;
119
+ if (!block)
120
+ return;
121
+ if (block.type === 'text') {
122
+ this.blocks.set(index, { kind: 'text', buffer: '' });
123
+ yield { type: 'text_start' };
124
+ }
125
+ else if (block.type === 'thinking') {
126
+ this.blocks.set(index, { kind: 'thinking', buffer: '' });
127
+ yield { type: 'thinking_start' };
128
+ }
129
+ else if (block.type === 'tool_use') {
130
+ const id = block.id ?? `tu-${index}`;
131
+ this.blocks.set(index, { kind: 'tool', id, name: block.name ?? '', buffer: '' });
132
+ yield { type: 'toolcall_start', id, name: block.name ?? '' };
133
+ }
134
+ break;
135
+ }
136
+ case 'content_block_delta': {
137
+ const index = ev.index ?? 0;
138
+ const entry = this.blocks.get(index);
139
+ if (!entry)
140
+ return;
141
+ if (entry.kind === 'text' && ev.delta?.text) {
142
+ entry.buffer += ev.delta.text;
143
+ yield { type: 'text_delta', delta: ev.delta.text };
144
+ }
145
+ else if (entry.kind === 'thinking' && ev.delta?.thinking) {
146
+ entry.buffer += ev.delta.thinking;
147
+ yield { type: 'thinking_delta', delta: ev.delta.thinking };
148
+ }
149
+ else if (entry.kind === 'tool' && ev.delta?.partial_json) {
150
+ entry.buffer += ev.delta.partial_json;
151
+ yield { type: 'toolcall_delta', id: entry.id, deltaJson: ev.delta.partial_json };
152
+ }
153
+ break;
154
+ }
155
+ case 'content_block_stop': {
156
+ const index = ev.index ?? 0;
157
+ const entry = this.blocks.get(index);
158
+ if (!entry)
159
+ return;
160
+ if (entry.kind === 'text')
161
+ yield { type: 'text_end' };
162
+ else if (entry.kind === 'thinking')
163
+ yield { type: 'thinking_end' };
164
+ else if (entry.kind === 'tool') {
165
+ let input = {};
166
+ try {
167
+ input = entry.buffer ? JSON.parse(entry.buffer) : {};
168
+ }
169
+ catch {
170
+ input = {};
171
+ }
172
+ yield { type: 'toolcall_end', id: entry.id, input };
173
+ }
174
+ this.blocks.delete(index);
175
+ break;
176
+ }
177
+ case 'message_delta': {
178
+ if (ev.usage) {
179
+ yield {
180
+ type: 'usage',
181
+ inputTokens: ev.usage.input_tokens ?? 0,
182
+ outputTokens: ev.usage.output_tokens ?? 0,
183
+ cachedTokens: ev.usage.cache_read_input_tokens ?? 0,
184
+ };
185
+ }
186
+ break;
187
+ }
188
+ }
189
+ }
190
+ }
191
+ //# sourceMappingURL=anthropic.js.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Model identifier → provider id routing.
3
+ *
4
+ * Pure function. Adding a new provider here is a one-line change.
5
+ * Model ids use provider-scoped prefixes (e.g., "anthropic/...",
6
+ * "nvidia/..."); bare ids fall through to the catch-all rules at the
7
+ * end.
8
+ */
9
+ export type ProviderId = 'anthropic' | 'openai' | 'gemini' | 'openrouter' | 'nvidia' | 'ollama' | 'fireworks';
10
+ export declare function routeModel(modelId: string): ProviderId;
11
+ export declare function isKnownProvider(id: string): id is ProviderId;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Model identifier → provider id routing.
3
+ *
4
+ * Pure function. Adding a new provider here is a one-line change.
5
+ * Model ids use provider-scoped prefixes (e.g., "anthropic/...",
6
+ * "nvidia/..."); bare ids fall through to the catch-all rules at the
7
+ * end.
8
+ */
9
+ const RULES = [
10
+ { match: id => id.startsWith('anthropic/') || id.startsWith('claude-'), provider: 'anthropic' },
11
+ { match: id => id.startsWith('openai/') || id.startsWith('gpt-') || /^o[1-9](?:-.+)?$/i.test(id), provider: 'openai' },
12
+ { match: id => id.startsWith('google/') || id.startsWith('gemini-'), provider: 'gemini' },
13
+ { match: id => id.startsWith('ollama/'), provider: 'ollama' },
14
+ { match: id => id.startsWith('fireworks/'), provider: 'fireworks' },
15
+ {
16
+ match: id => id.startsWith('openrouter/')
17
+ || id.startsWith('inclusionai/')
18
+ || id.includes(':free'),
19
+ provider: 'openrouter',
20
+ },
21
+ {
22
+ match: id => id.startsWith('minimaxai/')
23
+ || id.startsWith('moonshotai/')
24
+ || id.startsWith('mistralai/')
25
+ || id.startsWith('z-ai/')
26
+ || id.startsWith('meta/')
27
+ || id.startsWith('nvidia/')
28
+ || id.startsWith('qwen/')
29
+ || id.startsWith('deepseek-ai/'),
30
+ provider: 'nvidia',
31
+ },
32
+ ];
33
+ export function routeModel(modelId) {
34
+ for (const rule of RULES) {
35
+ if (rule.match(modelId))
36
+ return rule.provider;
37
+ }
38
+ throw new Error(`No provider configured for model "${modelId}". Add a routing rule in providers/dispatch.ts.`);
39
+ }
40
+ export function isKnownProvider(id) {
41
+ return (id === 'anthropic' || id === 'openai' || id === 'gemini'
42
+ || id === 'openrouter' || id === 'nvidia' || id === 'ollama'
43
+ || id === 'fireworks');
44
+ }
45
+ //# sourceMappingURL=dispatch.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Fireworks provider. Kept for back-compat routing only — the upstream
3
+ * plan that fronted this provider is wound down and the default router
4
+ * no longer uses it. The adapter still exists so existing session
5
+ * transcripts that reference fireworks/* model ids remain decodable.
6
+ */
7
+ import type { AgentEvent } from '../kernel/types.js';
8
+ import type { Provider, StreamRequest, ProviderConfig } from './iface.js';
9
+ export declare class FireworksProvider implements Provider {
10
+ readonly id = "fireworks";
11
+ private readonly apiKey;
12
+ private readonly baseUrl;
13
+ private readonly timeoutMs;
14
+ constructor(config: ProviderConfig);
15
+ supportsTools(_modelId: string): boolean;
16
+ supportsThinking(_modelId: string): boolean;
17
+ stream(req: StreamRequest): AsyncIterable<AgentEvent>;
18
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Fireworks provider. Kept for back-compat routing only — the upstream
3
+ * plan that fronted this provider is wound down and the default router
4
+ * no longer uses it. The adapter still exists so existing session
5
+ * transcripts that reference fireworks/* model ids remain decodable.
6
+ */
7
+ import { ProviderError } from './iface.js';
8
+ import { streamChatCompletions } from './openai-compat.js';
9
+ const DEFAULT_BASE = 'https://api.fireworks.ai/inference/v1';
10
+ export class FireworksProvider {
11
+ id = 'fireworks';
12
+ apiKey;
13
+ baseUrl;
14
+ timeoutMs;
15
+ constructor(config) {
16
+ this.apiKey = config.apiKey ?? process.env.FIREWORKS_API_KEY ?? '';
17
+ if (!this.apiKey)
18
+ throw new ProviderError('FIREWORKS_API_KEY is required', this.id);
19
+ this.baseUrl = (config.baseUrl ?? DEFAULT_BASE).replace(/\/+$/, '');
20
+ this.timeoutMs = config.timeoutMs ?? 60_000;
21
+ }
22
+ supportsTools(_modelId) {
23
+ return true;
24
+ }
25
+ supportsThinking(_modelId) {
26
+ return false;
27
+ }
28
+ stream(req) {
29
+ const model = req.model.replace(/^fireworks\//, '');
30
+ return streamChatCompletions({
31
+ providerName: this.id,
32
+ endpoint: `${this.baseUrl}/chat/completions`,
33
+ apiKey: this.apiKey,
34
+ model,
35
+ messages: req.messages,
36
+ tools: req.tools,
37
+ temperature: req.temperature,
38
+ maxTokens: req.maxTokens,
39
+ signal: req.signal,
40
+ timeoutMs: this.timeoutMs,
41
+ });
42
+ }
43
+ }
44
+ //# sourceMappingURL=fireworks.js.map
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Google Gemini provider.
3
+ *
4
+ * Uses generativelanguage.googleapis.com v1beta with streamGenerateContent.
5
+ * Gemini's wire format is JSON-array-over-SSE rather than delta
6
+ * envelopes, so this adapter has its own ingest loop.
7
+ */
8
+ import type { AgentEvent } from '../kernel/types.js';
9
+ import type { Provider, StreamRequest, ProviderConfig } from './iface.js';
10
+ export declare class GeminiProvider implements Provider {
11
+ readonly id = "gemini";
12
+ private readonly apiKey;
13
+ private readonly baseUrl;
14
+ private readonly timeoutMs;
15
+ constructor(config: ProviderConfig);
16
+ supportsTools(_modelId: string): boolean;
17
+ supportsThinking(modelId: string): boolean;
18
+ stream(req: StreamRequest): AsyncIterable<AgentEvent>;
19
+ }
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Google Gemini provider.
3
+ *
4
+ * Uses generativelanguage.googleapis.com v1beta with streamGenerateContent.
5
+ * Gemini's wire format is JSON-array-over-SSE rather than delta
6
+ * envelopes, so this adapter has its own ingest loop.
7
+ */
8
+ import { ProviderError } from './iface.js';
9
+ const DEFAULT_BASE = 'https://generativelanguage.googleapis.com/v1beta';
10
+ export class GeminiProvider {
11
+ id = 'gemini';
12
+ apiKey;
13
+ baseUrl;
14
+ timeoutMs;
15
+ constructor(config) {
16
+ this.apiKey = config.apiKey ?? process.env.GEMINI_API_KEY ?? process.env.GOOGLE_API_KEY ?? '';
17
+ if (!this.apiKey)
18
+ throw new ProviderError('GEMINI_API_KEY or GOOGLE_API_KEY is required', this.id);
19
+ this.baseUrl = (config.baseUrl ?? DEFAULT_BASE).replace(/\/+$/, '');
20
+ this.timeoutMs = config.timeoutMs ?? 60_000;
21
+ }
22
+ supportsTools(_modelId) {
23
+ return true;
24
+ }
25
+ supportsThinking(modelId) {
26
+ return modelId.includes('thinking') || modelId.includes('2.5');
27
+ }
28
+ async *stream(req) {
29
+ const model = req.model.replace(/^(google|gemini)\//, '').replace(/^gemini-/, '');
30
+ const url = `${this.baseUrl}/models/gemini-${model}:streamGenerateContent?alt=sse&key=${encodeURIComponent(this.apiKey)}`;
31
+ const body = buildGeminiBody(req);
32
+ const { signal, cancel } = makeTimeoutSignal(this.timeoutMs, req.signal);
33
+ let response;
34
+ try {
35
+ response = await fetch(url, {
36
+ method: 'POST',
37
+ headers: { 'Content-Type': 'application/json', Accept: 'text/event-stream' },
38
+ body: JSON.stringify(body),
39
+ signal,
40
+ });
41
+ }
42
+ catch (err) {
43
+ cancel();
44
+ throw new ProviderError(`Network error: ${String(err?.message ?? err)}`, this.id, undefined, true);
45
+ }
46
+ if (!response.ok) {
47
+ const text = await response.text().catch(() => '');
48
+ cancel();
49
+ throw new ProviderError(`HTTP ${response.status}: ${text}`, this.id, response.status, response.status >= 500 || response.status === 429);
50
+ }
51
+ if (!response.body) {
52
+ cancel();
53
+ throw new ProviderError('Empty response body', this.id);
54
+ }
55
+ const reader = response.body.getReader();
56
+ const decoder = new TextDecoder('utf-8');
57
+ let buffer = '';
58
+ let textOpen = false;
59
+ let toolIndex = 0;
60
+ try {
61
+ for (;;) {
62
+ const { value, done } = await reader.read();
63
+ if (done)
64
+ break;
65
+ buffer += decoder.decode(value, { stream: true });
66
+ let nl;
67
+ while ((nl = buffer.indexOf('\n')) >= 0) {
68
+ const raw = buffer.slice(0, nl);
69
+ buffer = buffer.slice(nl + 1);
70
+ const line = raw.endsWith('\r') ? raw.slice(0, -1) : raw;
71
+ if (!line.startsWith('data:'))
72
+ continue;
73
+ const payload = line.slice(5).trim();
74
+ if (!payload)
75
+ continue;
76
+ let chunk;
77
+ try {
78
+ chunk = JSON.parse(payload);
79
+ }
80
+ catch {
81
+ continue;
82
+ }
83
+ const candidate = chunk.candidates?.[0];
84
+ if (!candidate)
85
+ continue;
86
+ for (const part of candidate.content?.parts ?? []) {
87
+ if (part.text) {
88
+ if (!textOpen) {
89
+ yield { type: 'text_start' };
90
+ textOpen = true;
91
+ }
92
+ yield { type: 'text_delta', delta: part.text };
93
+ }
94
+ else if (part.functionCall) {
95
+ if (textOpen) {
96
+ yield { type: 'text_end' };
97
+ textOpen = false;
98
+ }
99
+ const id = `fc-${toolIndex++}`;
100
+ const name = part.functionCall.name;
101
+ yield { type: 'toolcall_start', id, name };
102
+ yield { type: 'toolcall_end', id, input: part.functionCall.args ?? {} };
103
+ }
104
+ }
105
+ if (chunk.usageMetadata) {
106
+ yield {
107
+ type: 'usage',
108
+ inputTokens: chunk.usageMetadata.promptTokenCount ?? 0,
109
+ outputTokens: chunk.usageMetadata.candidatesTokenCount ?? 0,
110
+ cachedTokens: chunk.usageMetadata.cachedContentTokenCount ?? 0,
111
+ };
112
+ }
113
+ }
114
+ }
115
+ if (textOpen)
116
+ yield { type: 'text_end' };
117
+ }
118
+ finally {
119
+ cancel();
120
+ try {
121
+ reader.releaseLock();
122
+ }
123
+ catch { /* noop */ }
124
+ }
125
+ }
126
+ }
127
+ function makeTimeoutSignal(timeoutMs, external) {
128
+ const controller = new AbortController();
129
+ const timer = setTimeout(() => controller.abort(new Error(`Request timed out after ${timeoutMs}ms`)), timeoutMs);
130
+ const onExternal = () => controller.abort(external.reason);
131
+ if (external) {
132
+ if (external.aborted)
133
+ controller.abort(external.reason);
134
+ else
135
+ external.addEventListener('abort', onExternal, { once: true });
136
+ }
137
+ return {
138
+ signal: controller.signal,
139
+ cancel: () => {
140
+ clearTimeout(timer);
141
+ if (external)
142
+ external.removeEventListener('abort', onExternal);
143
+ },
144
+ };
145
+ }
146
+ function buildGeminiBody(req) {
147
+ const contents = [];
148
+ let systemInstruction;
149
+ for (const msg of req.messages) {
150
+ if (msg.role === 'system') {
151
+ const text = typeof msg.content === 'string'
152
+ ? msg.content
153
+ : msg.content.filter((p) => p.type === 'text').map(p => p.text).join('');
154
+ systemInstruction = { parts: [{ text }] };
155
+ continue;
156
+ }
157
+ const parts = [];
158
+ const raw = typeof msg.content === 'string' ? [{ type: 'text', text: msg.content }] : msg.content;
159
+ for (const p of raw) {
160
+ if (p.type === 'text')
161
+ parts.push({ text: p.text });
162
+ else if (p.type === 'tool_result')
163
+ parts.push({ text: p.content });
164
+ }
165
+ contents.push({ role: msg.role === 'assistant' ? 'model' : 'user', parts });
166
+ }
167
+ const body = { contents };
168
+ if (systemInstruction)
169
+ body.systemInstruction = systemInstruction;
170
+ if (req.tools && req.tools.length > 0) {
171
+ body.tools = [{
172
+ functionDeclarations: req.tools.map((t) => ({
173
+ name: t.name,
174
+ description: t.description,
175
+ parameters: t.inputSchema ?? { type: 'object', properties: {} },
176
+ })),
177
+ }];
178
+ }
179
+ const generationConfig = {};
180
+ if (req.temperature !== undefined)
181
+ generationConfig.temperature = req.temperature;
182
+ if (req.maxTokens !== undefined)
183
+ generationConfig.maxOutputTokens = req.maxTokens;
184
+ if (Object.keys(generationConfig).length > 0)
185
+ body.generationConfig = generationConfig;
186
+ return body;
187
+ }
188
+ //# sourceMappingURL=gemini.js.map
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Canonical HTTP helpers for provider adapters.
3
+ *
4
+ * The NVIDIA streaming stutter root cause was header duplication: the
5
+ * previous implementation added Content-Type: application/json alongside
6
+ * Accept: application/json, which breaks NIM's SSE response negotiation.
7
+ * Two invariants enforced here eliminate that class of bug:
8
+ *
9
+ * (i) Accept declares what the SERVER returns. For SSE streams we
10
+ * request text/event-stream; for JSON RPC we request application/
11
+ * json. Never both.
12
+ * (ii) Content-Type declares what the CLIENT is sending. It is only
13
+ * attached when there is a body, and only as application/json.
14
+ *
15
+ * All provider adapters route through streamSSE or postJSON. No adapter
16
+ * sets Accept or Content-Type directly; extraHeaders is for custom
17
+ * provider-specific keys (e.g., organisation id) only.
18
+ */
19
+ export interface SseRequest {
20
+ url: string;
21
+ apiKey: string;
22
+ body: unknown;
23
+ extraHeaders?: Record<string, string>;
24
+ timeoutMs?: number;
25
+ signal?: AbortSignal;
26
+ providerName: string;
27
+ }
28
+ export interface JsonRequest extends SseRequest {
29
+ }
30
+ /**
31
+ * POST a body and yield `data: ...` payload strings from a Server-Sent
32
+ * Events response body. Does not attempt JSON parsing; the caller owns
33
+ * per-provider payload semantics.
34
+ */
35
+ export declare function streamSSE(req: SseRequest): AsyncIterable<string>;
36
+ /**
37
+ * One-shot JSON POST. Returns the parsed body. Use only for non-streaming
38
+ * endpoints; streaming completions must go through streamSSE to preserve
39
+ * token-level event fidelity.
40
+ */
41
+ export declare function postJSON<T>(req: JsonRequest): Promise<T>;