zerg-ztc 0.1.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 (411) hide show
  1. package/README.md +361 -0
  2. package/dist/App.d.ts +4 -0
  3. package/dist/App.d.ts.map +1 -0
  4. package/dist/App.js +499 -0
  5. package/dist/App.js.map +1 -0
  6. package/dist/agent/agent.d.ts +54 -0
  7. package/dist/agent/agent.d.ts.map +1 -0
  8. package/dist/agent/agent.js +347 -0
  9. package/dist/agent/agent.js.map +1 -0
  10. package/dist/agent/backends/anthropic.d.ts +13 -0
  11. package/dist/agent/backends/anthropic.d.ts.map +1 -0
  12. package/dist/agent/backends/anthropic.js +54 -0
  13. package/dist/agent/backends/anthropic.js.map +1 -0
  14. package/dist/agent/backends/gemini.d.ts +13 -0
  15. package/dist/agent/backends/gemini.d.ts.map +1 -0
  16. package/dist/agent/backends/gemini.js +71 -0
  17. package/dist/agent/backends/gemini.js.map +1 -0
  18. package/dist/agent/backends/inception.d.ts +12 -0
  19. package/dist/agent/backends/inception.d.ts.map +1 -0
  20. package/dist/agent/backends/inception.js +15 -0
  21. package/dist/agent/backends/inception.js.map +1 -0
  22. package/dist/agent/backends/index.d.ts +7 -0
  23. package/dist/agent/backends/index.d.ts.map +1 -0
  24. package/dist/agent/backends/index.js +6 -0
  25. package/dist/agent/backends/index.js.map +1 -0
  26. package/dist/agent/backends/openai.d.ts +12 -0
  27. package/dist/agent/backends/openai.d.ts.map +1 -0
  28. package/dist/agent/backends/openai.js +15 -0
  29. package/dist/agent/backends/openai.js.map +1 -0
  30. package/dist/agent/backends/openai_compatible.d.ts +17 -0
  31. package/dist/agent/backends/openai_compatible.d.ts.map +1 -0
  32. package/dist/agent/backends/openai_compatible.js +95 -0
  33. package/dist/agent/backends/openai_compatible.js.map +1 -0
  34. package/dist/agent/backends/types.d.ts +49 -0
  35. package/dist/agent/backends/types.d.ts.map +1 -0
  36. package/dist/agent/backends/types.js +2 -0
  37. package/dist/agent/backends/types.js.map +1 -0
  38. package/dist/agent/commands/clipboard.d.ts +3 -0
  39. package/dist/agent/commands/clipboard.d.ts.map +1 -0
  40. package/dist/agent/commands/clipboard.js +72 -0
  41. package/dist/agent/commands/clipboard.js.map +1 -0
  42. package/dist/agent/commands/config.d.ts +3 -0
  43. package/dist/agent/commands/config.d.ts.map +1 -0
  44. package/dist/agent/commands/config.js +120 -0
  45. package/dist/agent/commands/config.js.map +1 -0
  46. package/dist/agent/commands/debug.d.ts +3 -0
  47. package/dist/agent/commands/debug.d.ts.map +1 -0
  48. package/dist/agent/commands/debug.js +23 -0
  49. package/dist/agent/commands/debug.js.map +1 -0
  50. package/dist/agent/commands/emulation.d.ts +3 -0
  51. package/dist/agent/commands/emulation.d.ts.map +1 -0
  52. package/dist/agent/commands/emulation.js +78 -0
  53. package/dist/agent/commands/emulation.js.map +1 -0
  54. package/dist/agent/commands/execution.d.ts +3 -0
  55. package/dist/agent/commands/execution.d.ts.map +1 -0
  56. package/dist/agent/commands/execution.js +8 -0
  57. package/dist/agent/commands/execution.js.map +1 -0
  58. package/dist/agent/commands/help.d.ts +3 -0
  59. package/dist/agent/commands/help.d.ts.map +1 -0
  60. package/dist/agent/commands/help.js +19 -0
  61. package/dist/agent/commands/help.js.map +1 -0
  62. package/dist/agent/commands/history.d.ts +3 -0
  63. package/dist/agent/commands/history.d.ts.map +1 -0
  64. package/dist/agent/commands/history.js +12 -0
  65. package/dist/agent/commands/history.js.map +1 -0
  66. package/dist/agent/commands/index.d.ts +4 -0
  67. package/dist/agent/commands/index.d.ts.map +1 -0
  68. package/dist/agent/commands/index.js +19 -0
  69. package/dist/agent/commands/index.js.map +1 -0
  70. package/dist/agent/commands/model.d.ts +3 -0
  71. package/dist/agent/commands/model.d.ts.map +1 -0
  72. package/dist/agent/commands/model.js +10 -0
  73. package/dist/agent/commands/model.js.map +1 -0
  74. package/dist/agent/commands/models.d.ts +3 -0
  75. package/dist/agent/commands/models.d.ts.map +1 -0
  76. package/dist/agent/commands/models.js +110 -0
  77. package/dist/agent/commands/models.js.map +1 -0
  78. package/dist/agent/commands/permissions.d.ts +3 -0
  79. package/dist/agent/commands/permissions.d.ts.map +1 -0
  80. package/dist/agent/commands/permissions.js +58 -0
  81. package/dist/agent/commands/permissions.js.map +1 -0
  82. package/dist/agent/commands/retry.d.ts +3 -0
  83. package/dist/agent/commands/retry.d.ts.map +1 -0
  84. package/dist/agent/commands/retry.js +8 -0
  85. package/dist/agent/commands/retry.js.map +1 -0
  86. package/dist/agent/commands/shell.d.ts +4 -0
  87. package/dist/agent/commands/shell.d.ts.map +1 -0
  88. package/dist/agent/commands/shell.js +66 -0
  89. package/dist/agent/commands/shell.js.map +1 -0
  90. package/dist/agent/commands/skills.d.ts +3 -0
  91. package/dist/agent/commands/skills.d.ts.map +1 -0
  92. package/dist/agent/commands/skills.js +50 -0
  93. package/dist/agent/commands/skills.js.map +1 -0
  94. package/dist/agent/commands/status.d.ts +3 -0
  95. package/dist/agent/commands/status.d.ts.map +1 -0
  96. package/dist/agent/commands/status.js +18 -0
  97. package/dist/agent/commands/status.js.map +1 -0
  98. package/dist/agent/commands/types.d.ts +70 -0
  99. package/dist/agent/commands/types.d.ts.map +1 -0
  100. package/dist/agent/commands/types.js +2 -0
  101. package/dist/agent/commands/types.js.map +1 -0
  102. package/dist/agent/factory.d.ts +13 -0
  103. package/dist/agent/factory.d.ts.map +1 -0
  104. package/dist/agent/factory.js +46 -0
  105. package/dist/agent/factory.js.map +1 -0
  106. package/dist/agent/index.d.ts +14 -0
  107. package/dist/agent/index.d.ts.map +1 -0
  108. package/dist/agent/index.js +10 -0
  109. package/dist/agent/index.js.map +1 -0
  110. package/dist/agent/runtime/capabilities.d.ts +7 -0
  111. package/dist/agent/runtime/capabilities.d.ts.map +1 -0
  112. package/dist/agent/runtime/capabilities.js +8 -0
  113. package/dist/agent/runtime/capabilities.js.map +1 -0
  114. package/dist/agent/runtime/memory.d.ts +13 -0
  115. package/dist/agent/runtime/memory.d.ts.map +1 -0
  116. package/dist/agent/runtime/memory.js +13 -0
  117. package/dist/agent/runtime/memory.js.map +1 -0
  118. package/dist/agent/runtime/policy.d.ts +22 -0
  119. package/dist/agent/runtime/policy.d.ts.map +1 -0
  120. package/dist/agent/runtime/policy.js +29 -0
  121. package/dist/agent/runtime/policy.js.map +1 -0
  122. package/dist/agent/runtime/session.d.ts +11 -0
  123. package/dist/agent/runtime/session.d.ts.map +1 -0
  124. package/dist/agent/runtime/session.js +10 -0
  125. package/dist/agent/runtime/session.js.map +1 -0
  126. package/dist/agent/runtime/tracing.d.ts +13 -0
  127. package/dist/agent/runtime/tracing.d.ts.map +1 -0
  128. package/dist/agent/runtime/tracing.js +6 -0
  129. package/dist/agent/runtime/tracing.js.map +1 -0
  130. package/dist/agent/tools/file.d.ts +5 -0
  131. package/dist/agent/tools/file.d.ts.map +1 -0
  132. package/dist/agent/tools/file.js +162 -0
  133. package/dist/agent/tools/file.js.map +1 -0
  134. package/dist/agent/tools/index.d.ts +13 -0
  135. package/dist/agent/tools/index.d.ts.map +1 -0
  136. package/dist/agent/tools/index.js +34 -0
  137. package/dist/agent/tools/index.js.map +1 -0
  138. package/dist/agent/tools/search.d.ts +3 -0
  139. package/dist/agent/tools/search.d.ts.map +1 -0
  140. package/dist/agent/tools/search.js +124 -0
  141. package/dist/agent/tools/search.js.map +1 -0
  142. package/dist/agent/tools/shell.d.ts +3 -0
  143. package/dist/agent/tools/shell.d.ts.map +1 -0
  144. package/dist/agent/tools/shell.js +60 -0
  145. package/dist/agent/tools/shell.js.map +1 -0
  146. package/dist/agent/tools/skills.d.ts +3 -0
  147. package/dist/agent/tools/skills.d.ts.map +1 -0
  148. package/dist/agent/tools/skills.js +27 -0
  149. package/dist/agent/tools/skills.js.map +1 -0
  150. package/dist/agent/tools/types.d.ts +8 -0
  151. package/dist/agent/tools/types.d.ts.map +1 -0
  152. package/dist/agent/tools/types.js +2 -0
  153. package/dist/agent/tools/types.js.map +1 -0
  154. package/dist/agent/tools/zerg.d.ts +3 -0
  155. package/dist/agent/tools/zerg.d.ts.map +1 -0
  156. package/dist/agent/tools/zerg.js +47 -0
  157. package/dist/agent/tools/zerg.js.map +1 -0
  158. package/dist/cli.d.ts +3 -0
  159. package/dist/cli.d.ts.map +1 -0
  160. package/dist/cli.js +75 -0
  161. package/dist/cli.js.map +1 -0
  162. package/dist/components/FullScreen.d.ts +28 -0
  163. package/dist/components/FullScreen.d.ts.map +1 -0
  164. package/dist/components/FullScreen.js +40 -0
  165. package/dist/components/FullScreen.js.map +1 -0
  166. package/dist/components/Header.d.ts +10 -0
  167. package/dist/components/Header.d.ts.map +1 -0
  168. package/dist/components/Header.js +14 -0
  169. package/dist/components/Header.js.map +1 -0
  170. package/dist/components/InputArea.d.ts +24 -0
  171. package/dist/components/InputArea.d.ts.map +1 -0
  172. package/dist/components/InputArea.js +476 -0
  173. package/dist/components/InputArea.js.map +1 -0
  174. package/dist/components/MessageList.d.ts +12 -0
  175. package/dist/components/MessageList.d.ts.map +1 -0
  176. package/dist/components/MessageList.js +9 -0
  177. package/dist/components/MessageList.js.map +1 -0
  178. package/dist/components/StatusBar.d.ts +18 -0
  179. package/dist/components/StatusBar.d.ts.map +1 -0
  180. package/dist/components/StatusBar.js +21 -0
  181. package/dist/components/StatusBar.js.map +1 -0
  182. package/dist/components/index.d.ts +6 -0
  183. package/dist/components/index.d.ts.map +1 -0
  184. package/dist/components/index.js +7 -0
  185. package/dist/components/index.js.map +1 -0
  186. package/dist/config/types.d.ts +12 -0
  187. package/dist/config/types.d.ts.map +1 -0
  188. package/dist/config/types.js +2 -0
  189. package/dist/config/types.js.map +1 -0
  190. package/dist/config.d.ts +28 -0
  191. package/dist/config.d.ts.map +1 -0
  192. package/dist/config.js +155 -0
  193. package/dist/config.js.map +1 -0
  194. package/dist/debug/logger.d.ts +2 -0
  195. package/dist/debug/logger.d.ts.map +1 -0
  196. package/dist/debug/logger.js +15 -0
  197. package/dist/debug/logger.js.map +1 -0
  198. package/dist/emulation/catalog.d.ts +4 -0
  199. package/dist/emulation/catalog.d.ts.map +1 -0
  200. package/dist/emulation/catalog.js +68 -0
  201. package/dist/emulation/catalog.js.map +1 -0
  202. package/dist/emulation/trace_style.d.ts +3 -0
  203. package/dist/emulation/trace_style.d.ts.map +1 -0
  204. package/dist/emulation/trace_style.js +10 -0
  205. package/dist/emulation/trace_style.js.map +1 -0
  206. package/dist/emulation/types.d.ts +8 -0
  207. package/dist/emulation/types.d.ts.map +1 -0
  208. package/dist/emulation/types.js +2 -0
  209. package/dist/emulation/types.js.map +1 -0
  210. package/dist/skills/index.d.ts +5 -0
  211. package/dist/skills/index.d.ts.map +1 -0
  212. package/dist/skills/index.js +36 -0
  213. package/dist/skills/index.js.map +1 -0
  214. package/dist/skills/loader.d.ts +3 -0
  215. package/dist/skills/loader.d.ts.map +1 -0
  216. package/dist/skills/loader.js +137 -0
  217. package/dist/skills/loader.js.map +1 -0
  218. package/dist/skills/registry.d.ts +3 -0
  219. package/dist/skills/registry.d.ts.map +1 -0
  220. package/dist/skills/registry.js +5 -0
  221. package/dist/skills/registry.js.map +1 -0
  222. package/dist/skills/types.d.ts +11 -0
  223. package/dist/skills/types.d.ts.map +1 -0
  224. package/dist/skills/types.js +2 -0
  225. package/dist/skills/types.js.map +1 -0
  226. package/dist/types.d.ts +93 -0
  227. package/dist/types.d.ts.map +1 -0
  228. package/dist/types.js +5 -0
  229. package/dist/types.js.map +1 -0
  230. package/dist/ui/core/factory.d.ts +4 -0
  231. package/dist/ui/core/factory.d.ts.map +1 -0
  232. package/dist/ui/core/factory.js +7 -0
  233. package/dist/ui/core/factory.js.map +1 -0
  234. package/dist/ui/core/index.d.ts +5 -0
  235. package/dist/ui/core/index.d.ts.map +1 -0
  236. package/dist/ui/core/index.js +4 -0
  237. package/dist/ui/core/index.js.map +1 -0
  238. package/dist/ui/core/input.d.ts +22 -0
  239. package/dist/ui/core/input.d.ts.map +1 -0
  240. package/dist/ui/core/input.js +15 -0
  241. package/dist/ui/core/input.js.map +1 -0
  242. package/dist/ui/core/input_segments.d.ts +19 -0
  243. package/dist/ui/core/input_segments.d.ts.map +1 -0
  244. package/dist/ui/core/input_segments.js +367 -0
  245. package/dist/ui/core/input_segments.js.map +1 -0
  246. package/dist/ui/core/input_state.d.ts +24 -0
  247. package/dist/ui/core/input_state.d.ts.map +1 -0
  248. package/dist/ui/core/input_state.js +2 -0
  249. package/dist/ui/core/input_state.js.map +1 -0
  250. package/dist/ui/core/layout_yoga.d.ts +11 -0
  251. package/dist/ui/core/layout_yoga.d.ts.map +1 -0
  252. package/dist/ui/core/layout_yoga.js +102 -0
  253. package/dist/ui/core/layout_yoga.js.map +1 -0
  254. package/dist/ui/core/style.d.ts +3 -0
  255. package/dist/ui/core/style.d.ts.map +1 -0
  256. package/dist/ui/core/style.js +37 -0
  257. package/dist/ui/core/style.js.map +1 -0
  258. package/dist/ui/core/types.d.ts +50 -0
  259. package/dist/ui/core/types.d.ts.map +1 -0
  260. package/dist/ui/core/types.js +2 -0
  261. package/dist/ui/core/types.js.map +1 -0
  262. package/dist/ui/ink/index.d.ts +2 -0
  263. package/dist/ui/ink/index.d.ts.map +1 -0
  264. package/dist/ui/ink/index.js +2 -0
  265. package/dist/ui/ink/index.js.map +1 -0
  266. package/dist/ui/ink/render.d.ts +6 -0
  267. package/dist/ui/ink/render.d.ts.map +1 -0
  268. package/dist/ui/ink/render.js +14 -0
  269. package/dist/ui/ink/render.js.map +1 -0
  270. package/dist/ui/views/app.d.ts +28 -0
  271. package/dist/ui/views/app.d.ts.map +1 -0
  272. package/dist/ui/views/app.js +59 -0
  273. package/dist/ui/views/app.js.map +1 -0
  274. package/dist/ui/views/header.d.ts +11 -0
  275. package/dist/ui/views/header.d.ts.map +1 -0
  276. package/dist/ui/views/header.js +28 -0
  277. package/dist/ui/views/header.js.map +1 -0
  278. package/dist/ui/views/input_area.d.ts +45 -0
  279. package/dist/ui/views/input_area.d.ts.map +1 -0
  280. package/dist/ui/views/input_area.js +183 -0
  281. package/dist/ui/views/input_area.js.map +1 -0
  282. package/dist/ui/views/message_list.d.ts +12 -0
  283. package/dist/ui/views/message_list.d.ts.map +1 -0
  284. package/dist/ui/views/message_list.js +381 -0
  285. package/dist/ui/views/message_list.js.map +1 -0
  286. package/dist/ui/views/status_bar.d.ts +18 -0
  287. package/dist/ui/views/status_bar.d.ts.map +1 -0
  288. package/dist/ui/views/status_bar.js +72 -0
  289. package/dist/ui/views/status_bar.js.map +1 -0
  290. package/dist/ui/vue/index.d.ts +5 -0
  291. package/dist/ui/vue/index.d.ts.map +1 -0
  292. package/dist/ui/vue/index.js +50 -0
  293. package/dist/ui/vue/index.js.map +1 -0
  294. package/dist/utils/clipboard.d.ts +2 -0
  295. package/dist/utils/clipboard.d.ts.map +1 -0
  296. package/dist/utils/clipboard.js +39 -0
  297. package/dist/utils/clipboard.js.map +1 -0
  298. package/dist/utils/clipboard_image.d.ts +2 -0
  299. package/dist/utils/clipboard_image.d.ts.map +1 -0
  300. package/dist/utils/clipboard_image.js +37 -0
  301. package/dist/utils/clipboard_image.js.map +1 -0
  302. package/dist/utils/diff.d.ts +2 -0
  303. package/dist/utils/diff.d.ts.map +1 -0
  304. package/dist/utils/diff.js +49 -0
  305. package/dist/utils/diff.js.map +1 -0
  306. package/dist/utils/image_preview.d.ts +2 -0
  307. package/dist/utils/image_preview.d.ts.map +1 -0
  308. package/dist/utils/image_preview.js +37 -0
  309. package/dist/utils/image_preview.js.map +1 -0
  310. package/dist/utils/models.d.ts +8 -0
  311. package/dist/utils/models.d.ts.map +1 -0
  312. package/dist/utils/models.js +85 -0
  313. package/dist/utils/models.js.map +1 -0
  314. package/dist/utils/shell.d.ts +4 -0
  315. package/dist/utils/shell.d.ts.map +1 -0
  316. package/dist/utils/shell.js +57 -0
  317. package/dist/utils/shell.js.map +1 -0
  318. package/dist/utils/tool_summary.d.ts +3 -0
  319. package/dist/utils/tool_summary.d.ts.map +1 -0
  320. package/dist/utils/tool_summary.js +54 -0
  321. package/dist/utils/tool_summary.js.map +1 -0
  322. package/dist/utils/tool_trace.d.ts +9 -0
  323. package/dist/utils/tool_trace.d.ts.map +1 -0
  324. package/dist/utils/tool_trace.js +183 -0
  325. package/dist/utils/tool_trace.js.map +1 -0
  326. package/package.json +41 -0
  327. package/src/App.tsx +576 -0
  328. package/src/agent/agent.ts +407 -0
  329. package/src/agent/backends/anthropic.ts +76 -0
  330. package/src/agent/backends/gemini.ts +107 -0
  331. package/src/agent/backends/inception.ts +23 -0
  332. package/src/agent/backends/index.ts +16 -0
  333. package/src/agent/backends/openai.ts +23 -0
  334. package/src/agent/backends/openai_compatible.ts +131 -0
  335. package/src/agent/backends/types.ts +59 -0
  336. package/src/agent/commands/clipboard.ts +77 -0
  337. package/src/agent/commands/config.ts +130 -0
  338. package/src/agent/commands/debug.ts +23 -0
  339. package/src/agent/commands/emulation.ts +80 -0
  340. package/src/agent/commands/execution.ts +9 -0
  341. package/src/agent/commands/help.ts +20 -0
  342. package/src/agent/commands/history.ts +13 -0
  343. package/src/agent/commands/index.ts +40 -0
  344. package/src/agent/commands/model.ts +11 -0
  345. package/src/agent/commands/models.ts +116 -0
  346. package/src/agent/commands/permissions.ts +64 -0
  347. package/src/agent/commands/retry.ts +9 -0
  348. package/src/agent/commands/shell.ts +68 -0
  349. package/src/agent/commands/skills.ts +54 -0
  350. package/src/agent/commands/status.ts +19 -0
  351. package/src/agent/commands/types.ts +78 -0
  352. package/src/agent/factory.ts +60 -0
  353. package/src/agent/index.ts +20 -0
  354. package/src/agent/runtime/capabilities.ts +6 -0
  355. package/src/agent/runtime/memory.ts +23 -0
  356. package/src/agent/runtime/policy.ts +48 -0
  357. package/src/agent/runtime/session.ts +18 -0
  358. package/src/agent/runtime/tracing.ts +23 -0
  359. package/src/agent/tools/file.ts +173 -0
  360. package/src/agent/tools/index.ts +46 -0
  361. package/src/agent/tools/search.ts +137 -0
  362. package/src/agent/tools/shell.ts +65 -0
  363. package/src/agent/tools/skills.ts +28 -0
  364. package/src/agent/tools/types.ts +10 -0
  365. package/src/agent/tools/zerg.ts +50 -0
  366. package/src/cli.tsx +80 -0
  367. package/src/components/FullScreen.tsx +73 -0
  368. package/src/components/Header.tsx +27 -0
  369. package/src/components/InputArea.tsx +551 -0
  370. package/src/components/MessageList.tsx +25 -0
  371. package/src/components/StatusBar.tsx +49 -0
  372. package/src/components/index.tsx +6 -0
  373. package/src/config/types.ts +11 -0
  374. package/src/config.ts +178 -0
  375. package/src/debug/logger.ts +14 -0
  376. package/src/emulation/README.md +24 -0
  377. package/src/emulation/catalog.ts +82 -0
  378. package/src/emulation/trace_style.ts +8 -0
  379. package/src/emulation/types.ts +7 -0
  380. package/src/skills/index.ts +36 -0
  381. package/src/skills/loader.ts +135 -0
  382. package/src/skills/registry.ts +6 -0
  383. package/src/skills/types.ts +10 -0
  384. package/src/types.ts +83 -0
  385. package/src/ui/README.md +44 -0
  386. package/src/ui/core/factory.ts +9 -0
  387. package/src/ui/core/index.ts +4 -0
  388. package/src/ui/core/input.ts +38 -0
  389. package/src/ui/core/input_segments.ts +375 -0
  390. package/src/ui/core/input_state.ts +17 -0
  391. package/src/ui/core/layout_yoga.ts +122 -0
  392. package/src/ui/core/style.ts +38 -0
  393. package/src/ui/core/types.ts +53 -0
  394. package/src/ui/ink/index.tsx +1 -0
  395. package/src/ui/ink/render.tsx +49 -0
  396. package/src/ui/views/app.ts +99 -0
  397. package/src/ui/views/header.ts +42 -0
  398. package/src/ui/views/input_area.ts +244 -0
  399. package/src/ui/views/message_list.ts +427 -0
  400. package/src/ui/views/status_bar.ts +104 -0
  401. package/src/ui/vue/index.ts +53 -0
  402. package/src/utils/clipboard.ts +39 -0
  403. package/src/utils/clipboard_image.ts +40 -0
  404. package/src/utils/diff.ts +52 -0
  405. package/src/utils/image_preview.ts +36 -0
  406. package/src/utils/models.ts +98 -0
  407. package/src/utils/shell.ts +63 -0
  408. package/src/utils/tool_summary.ts +56 -0
  409. package/src/utils/tool_trace.ts +206 -0
  410. package/tsconfig.json +22 -0
  411. package/vite.config.ts +363 -0
@@ -0,0 +1,347 @@
1
+ // Standard library
2
+ import { existsSync, readFileSync } from 'fs';
3
+ import { extname } from 'path';
4
+ import { AnthropicBackend } from './backends/index.js';
5
+ import { AllowAllPolicy } from './runtime/policy.js';
6
+ import { NoopTracer } from './runtime/tracing.js';
7
+ import { defaultTools, executeTool, getToolDefinitions, getTool } from './tools/index.js';
8
+ export class AgentError extends Error {
9
+ code;
10
+ constructor(message, code) {
11
+ super(message);
12
+ this.code = code;
13
+ this.name = 'AgentError';
14
+ }
15
+ }
16
+ // --- Agent Class ---
17
+ export class Agent {
18
+ config;
19
+ eventHandlers = new Set();
20
+ backend;
21
+ policy;
22
+ tracer;
23
+ streamChunkSize = 32;
24
+ constructor(config = {}) {
25
+ const apiKey = config.apiKey || process.env.ANTHROPIC_API_KEY || '';
26
+ this.config = {
27
+ model: config.model || 'claude-opus-4-20250514',
28
+ apiKey,
29
+ apiEndpoint: config.apiEndpoint || 'https://api.anthropic.com/v1/messages',
30
+ maxTokens: config.maxTokens || 4096,
31
+ maxIterations: config.maxIterations || 10,
32
+ tools: config.tools || defaultTools,
33
+ systemPrompt: config.systemPrompt || this.getDefaultSystemPrompt(),
34
+ backend: config.backend || new AnthropicBackend({ apiKey, apiEndpoint: config.apiEndpoint }),
35
+ policy: config.policy || new AllowAllPolicy(),
36
+ tracer: config.tracer || new NoopTracer()
37
+ };
38
+ this.backend = this.config.backend;
39
+ this.policy = this.config.policy;
40
+ this.tracer = this.config.tracer;
41
+ }
42
+ hasApiKey() {
43
+ return !!this.config.apiKey && this.config.apiKey.length > 0;
44
+ }
45
+ getDefaultSystemPrompt() {
46
+ return `You are ZTC (Zerg Terminal Client), an AI assistant that helps users interact with the Zerg continual AI system and manage local development tasks.
47
+
48
+ You have access to tools for:
49
+ - Reading and writing files
50
+ - Listing directory contents
51
+ - Running shell commands
52
+ - Querying the Zerg system
53
+
54
+ Be concise and helpful. When using tools, explain what you're doing briefly. If a task requires multiple steps, proceed through them systematically.`;
55
+ }
56
+ // Event handling
57
+ on(handler) {
58
+ this.eventHandlers.add(handler);
59
+ return () => this.eventHandlers.delete(handler);
60
+ }
61
+ emit(event) {
62
+ for (const handler of this.eventHandlers) {
63
+ handler(event);
64
+ }
65
+ }
66
+ // Convert messages to API format
67
+ formatMessages(messages) {
68
+ return messages
69
+ .filter((m) => m.role === 'user' || m.role === 'assistant')
70
+ .map(m => ({
71
+ role: m.role,
72
+ content: m.role === 'user' ? this.buildContentBlocks(m.content) : m.content
73
+ }));
74
+ }
75
+ contentLength(content) {
76
+ if (typeof content === 'string')
77
+ return content.length;
78
+ return content.reduce((sum, block) => {
79
+ if (block.type === 'text')
80
+ return sum + block.text.length;
81
+ return sum + block.data.length;
82
+ }, 0);
83
+ }
84
+ buildContentBlocks(content) {
85
+ const trimmed = content.trimStart();
86
+ if (trimmed.startsWith('[') && trimmed.includes('"tool_use_id"')) {
87
+ return content;
88
+ }
89
+ const imageRegex = /\[image ([^\]]+)\]/g;
90
+ let match;
91
+ let cursor = 0;
92
+ const blocks = [];
93
+ while ((match = imageRegex.exec(content)) !== null) {
94
+ const start = match.index;
95
+ const end = match.index + match[0].length;
96
+ if (start > cursor) {
97
+ blocks.push({ type: 'text', text: content.slice(cursor, start) });
98
+ }
99
+ const path = match[1].trim();
100
+ const imageBlock = this.loadImageBlock(path);
101
+ if (imageBlock) {
102
+ blocks.push(imageBlock);
103
+ }
104
+ else {
105
+ blocks.push({ type: 'text', text: match[0] });
106
+ }
107
+ cursor = end;
108
+ }
109
+ if (blocks.length === 0)
110
+ return content;
111
+ if (cursor < content.length) {
112
+ blocks.push({ type: 'text', text: content.slice(cursor) });
113
+ }
114
+ const merged = [];
115
+ for (const block of blocks) {
116
+ const last = merged[merged.length - 1];
117
+ if (block.type === 'text' && last?.type === 'text') {
118
+ last.text += block.text;
119
+ continue;
120
+ }
121
+ merged.push(block);
122
+ }
123
+ const hasImage = merged.some(block => block.type === 'image');
124
+ return hasImage ? merged : content;
125
+ }
126
+ loadImageBlock(path) {
127
+ try {
128
+ if (!existsSync(path))
129
+ return null;
130
+ const ext = extname(path).toLowerCase();
131
+ const mediaType = this.getImageMediaType(ext);
132
+ if (!mediaType)
133
+ return null;
134
+ const buffer = readFileSync(path);
135
+ return {
136
+ type: 'image',
137
+ mediaType,
138
+ data: buffer.toString('base64'),
139
+ path
140
+ };
141
+ }
142
+ catch {
143
+ return null;
144
+ }
145
+ }
146
+ getImageMediaType(ext) {
147
+ switch (ext) {
148
+ case '.png':
149
+ return 'image/png';
150
+ case '.jpg':
151
+ case '.jpeg':
152
+ return 'image/jpeg';
153
+ case '.webp':
154
+ return 'image/webp';
155
+ case '.gif':
156
+ return 'image/gif';
157
+ case '.bmp':
158
+ return 'image/bmp';
159
+ case '.tif':
160
+ case '.tiff':
161
+ return 'image/tiff';
162
+ case '.heic':
163
+ case '.heif':
164
+ return 'image/heic';
165
+ default:
166
+ return null;
167
+ }
168
+ }
169
+ // Type guards
170
+ isTextBlock(block) {
171
+ return block.type === 'text';
172
+ }
173
+ isToolUseBlock(block) {
174
+ return block.type === 'tool_use';
175
+ }
176
+ buildRequest(messages) {
177
+ return {
178
+ model: this.config.model,
179
+ maxTokens: this.config.maxTokens,
180
+ system: this.config.systemPrompt,
181
+ messages: this.formatMessages(messages),
182
+ tools: getToolDefinitions(this.config.tools)
183
+ };
184
+ }
185
+ estimateUsage(request, response) {
186
+ const inputChars = request.system.length + request.messages.reduce((sum, msg) => sum + this.contentLength(msg.content), 0);
187
+ const outputChars = response.content
188
+ .filter(this.isTextBlock)
189
+ .reduce((sum, block) => sum + block.text.length, 0);
190
+ const inputTokens = Math.max(1, Math.ceil(inputChars / 4));
191
+ const outputTokens = Math.max(1, Math.ceil(outputChars / 4));
192
+ return {
193
+ inputTokens,
194
+ outputTokens,
195
+ totalTokens: inputTokens + outputTokens,
196
+ estimated: true
197
+ };
198
+ }
199
+ mergeUsage(current, next) {
200
+ if (!current)
201
+ return next;
202
+ return {
203
+ inputTokens: current.inputTokens + next.inputTokens,
204
+ outputTokens: current.outputTokens + next.outputTokens,
205
+ totalTokens: current.totalTokens + next.totalTokens,
206
+ estimated: current.estimated || next.estimated
207
+ };
208
+ }
209
+ async emitStreamText(text) {
210
+ this.emit({ type: 'stream_start' });
211
+ for (let i = 0; i < text.length; i += this.streamChunkSize) {
212
+ const chunk = text.slice(i, i + this.streamChunkSize);
213
+ this.emit({ type: 'stream_delta', content: chunk });
214
+ await new Promise(resolve => setTimeout(resolve, 10));
215
+ }
216
+ this.emit({ type: 'stream_end' });
217
+ }
218
+ // Main execution loop
219
+ async run(messages) {
220
+ if (!this.hasApiKey()) {
221
+ throw new AgentError('No API key configured. Use /config key <key> to set one.', 'NO_API_KEY');
222
+ }
223
+ const allToolCalls = [];
224
+ let iterations = 0;
225
+ let finalContent = '';
226
+ let totalUsage = null;
227
+ while (iterations < this.config.maxIterations) {
228
+ iterations++;
229
+ this.emit({ type: 'thinking_start' });
230
+ try {
231
+ // Call the API
232
+ const request = this.buildRequest(messages);
233
+ this.tracer.event({ type: 'api_request', timestamp: new Date() });
234
+ const response = await this.callAPI(request);
235
+ this.tracer.event({ type: 'api_response', timestamp: new Date(), data: { stopReason: response.stopReason } });
236
+ this.emit({ type: 'thinking_end' });
237
+ const usage = response.usage ?? this.estimateUsage(request, response);
238
+ totalUsage = this.mergeUsage(totalUsage, usage);
239
+ this.emit({ type: 'token_usage', usage: totalUsage });
240
+ // Check for tool use
241
+ const toolUseBlocks = response.content.filter(this.isToolUseBlock);
242
+ if (toolUseBlocks.length === 0) {
243
+ // No tools, extract text and finish
244
+ const textBlocks = response.content.filter(this.isTextBlock);
245
+ finalContent = textBlocks.map(b => b.text).join('\n');
246
+ await this.emitStreamText(finalContent);
247
+ break;
248
+ }
249
+ // Execute tools
250
+ const toolResults = [];
251
+ for (const toolBlock of toolUseBlocks) {
252
+ const toolCall = {
253
+ id: toolBlock.id,
254
+ name: toolBlock.name,
255
+ args: toolBlock.input,
256
+ status: 'running',
257
+ startedAt: new Date()
258
+ };
259
+ allToolCalls.push(toolCall);
260
+ const tool = getTool(toolBlock.name, this.config.tools);
261
+ const policyDecision = this.policy.evaluateTool({
262
+ name: toolBlock.name,
263
+ args: toolBlock.input,
264
+ capabilities: tool?.capabilities || []
265
+ });
266
+ if (!policyDecision.allowed) {
267
+ const reason = policyDecision.reason || 'Policy denied tool execution';
268
+ toolCall.status = 'error';
269
+ toolCall.error = reason;
270
+ toolCall.completedAt = new Date();
271
+ toolResults.push({ tool_use_id: toolBlock.id, content: `Error: ${reason}` });
272
+ this.emit({ type: 'tool_error', tool: toolBlock.name, error: reason });
273
+ this.tracer.event({
274
+ type: 'policy_denied',
275
+ timestamp: new Date(),
276
+ data: { tool: toolBlock.name, reason }
277
+ });
278
+ continue;
279
+ }
280
+ this.tracer.event({
281
+ type: 'tool_start',
282
+ timestamp: new Date(),
283
+ data: { tool: toolBlock.name }
284
+ });
285
+ this.emit({ type: 'tool_start', tool: toolBlock.name, args: toolBlock.input });
286
+ try {
287
+ const result = await executeTool(toolBlock.name, toolBlock.input, this.config.tools);
288
+ toolCall.status = 'complete';
289
+ toolCall.result = result;
290
+ toolCall.completedAt = new Date();
291
+ toolResults.push({ tool_use_id: toolBlock.id, content: result });
292
+ this.emit({ type: 'tool_end', tool: toolBlock.name, result });
293
+ this.tracer.event({
294
+ type: 'tool_end',
295
+ timestamp: new Date(),
296
+ data: { tool: toolBlock.name }
297
+ });
298
+ }
299
+ catch (err) {
300
+ const error = err.message;
301
+ toolCall.status = 'error';
302
+ toolCall.error = error;
303
+ toolCall.completedAt = new Date();
304
+ toolResults.push({ tool_use_id: toolBlock.id, content: `Error: ${error}` });
305
+ this.emit({ type: 'tool_error', tool: toolBlock.name, error });
306
+ this.tracer.event({
307
+ type: 'tool_error',
308
+ timestamp: new Date(),
309
+ data: { tool: toolBlock.name, error }
310
+ });
311
+ }
312
+ }
313
+ // Add assistant message with tool use
314
+ const textContent = response.content
315
+ .filter(this.isTextBlock)
316
+ .map(b => b.text)
317
+ .join('\n');
318
+ messages.push({
319
+ id: `assistant_${Date.now()}`,
320
+ role: 'assistant',
321
+ content: textContent || '[Using tools...]',
322
+ timestamp: new Date(),
323
+ toolCalls: allToolCalls.slice(-toolUseBlocks.length)
324
+ });
325
+ // Add tool results as user message (API format)
326
+ messages.push({
327
+ id: `tool_${Date.now()}`,
328
+ role: 'user',
329
+ content: JSON.stringify(toolResults),
330
+ timestamp: new Date()
331
+ });
332
+ }
333
+ catch (err) {
334
+ const error = err.message;
335
+ this.emit({ type: 'error', error });
336
+ throw err;
337
+ }
338
+ }
339
+ return { content: finalContent, toolCalls: allToolCalls, usage: totalUsage || undefined };
340
+ }
341
+ // API call
342
+ async callAPI(request) {
343
+ return this.backend.generate(request);
344
+ }
345
+ }
346
+ export default Agent;
347
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/agent/agent.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAI/B,OAAO,EAAE,gBAAgB,EAA4G,MAAM,qBAAqB,CAAC;AACjK,OAAO,EAAE,cAAc,EAAU,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAU,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAiB1F,MAAM,OAAO,UAAW,SAAQ,KAAK;IACC;IAApC,YAAY,OAAe,EAAS,IAAa;QAC/C,KAAK,CAAC,OAAO,CAAC,CAAC;QADmB,SAAI,GAAJ,IAAI,CAAS;QAE/C,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AAID,sBAAsB;AAEtB,MAAM,OAAO,KAAK;IAC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AAW,CAAC;oBACpC,SAAS,EAAE,IAAI,IAAI,EAAE;iBACtB,CAAC,CAAC;YAEL,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,KAAK,GAAI,GAAa,CAAC,OAAO,CAAC;gBACrC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;gBACpC,MAAM,GAAG,CAAC;YACZ,CAAC;QACH,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,IAAI,SAAS,EAAE,CAAC;IAC5F,CAAC;IAED,WAAW;IACH,KAAK,CAAC,OAAO,CAAC,OAAuB;QAC3C,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;CACF;AAED,eAAe,KAAK,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { AgentBackend, BackendRequest, BackendResponse } from './types.js';
2
+ interface AnthropicBackendConfig {
3
+ apiKey: string;
4
+ apiEndpoint?: string;
5
+ }
6
+ export declare class AnthropicBackend implements AgentBackend {
7
+ private apiKey;
8
+ private apiEndpoint;
9
+ constructor(config: AnthropicBackendConfig);
10
+ generate(request: BackendRequest): Promise<BackendResponse>;
11
+ }
12
+ export {};
13
+ //# sourceMappingURL=anthropic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/agent/backends/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE3E,UAAU,sBAAsB;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAWD,qBAAa,gBAAiB,YAAW,YAAY;IACnD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,WAAW,CAAS;gBAEhB,MAAM,EAAE,sBAAsB;IAKpC,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;CAkDlE"}
@@ -0,0 +1,54 @@
1
+ export class AnthropicBackend {
2
+ apiKey;
3
+ apiEndpoint;
4
+ constructor(config) {
5
+ this.apiKey = config.apiKey;
6
+ this.apiEndpoint = config.apiEndpoint || 'https://api.anthropic.com/v1/messages';
7
+ }
8
+ async generate(request) {
9
+ const body = {
10
+ model: request.model,
11
+ max_tokens: request.maxTokens,
12
+ system: request.system,
13
+ messages: request.messages.map(message => ({
14
+ role: message.role,
15
+ content: typeof message.content === 'string'
16
+ ? message.content
17
+ : message.content.map(block => (block.type === 'text'
18
+ ? { type: 'text', text: block.text }
19
+ : { type: 'image', source: { type: 'base64', media_type: block.mediaType, data: block.data } }))
20
+ })),
21
+ tools: request.tools.map(t => ({
22
+ name: t.name,
23
+ description: t.description,
24
+ input_schema: t.parameters
25
+ }))
26
+ };
27
+ const response = await fetch(this.apiEndpoint, {
28
+ method: 'POST',
29
+ headers: {
30
+ 'Content-Type': 'application/json',
31
+ 'x-api-key': this.apiKey,
32
+ 'anthropic-version': '2023-06-01'
33
+ },
34
+ body: JSON.stringify(body)
35
+ });
36
+ if (!response.ok) {
37
+ const errorText = await response.text();
38
+ throw new Error(`API error (${response.status}): ${errorText}`);
39
+ }
40
+ const data = await response.json();
41
+ const inputTokens = data.usage?.input_tokens ?? 0;
42
+ const outputTokens = data.usage?.output_tokens ?? 0;
43
+ return {
44
+ content: data.content,
45
+ stopReason: data.stop_reason,
46
+ usage: data.usage ? {
47
+ inputTokens,
48
+ outputTokens,
49
+ totalTokens: inputTokens + outputTokens
50
+ } : undefined
51
+ };
52
+ }
53
+ }
54
+ //# sourceMappingURL=anthropic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/agent/backends/anthropic.ts"],"names":[],"mappings":"AAgBA,MAAM,OAAO,gBAAgB;IACnB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AAM,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE;YAC7C,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,WAAW,EAAE,IAAI,CAAC,MAAM;gBACxB,mBAAmB,EAAE,YAAY;aAClC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CAAC,cAAc,QAAQ,CAAC,MAAM,MAAM,SAAS,EAAE,CAAC,CAAC;QAClE,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAuB,CAAC;QACxD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,EAAE,YAAY,IAAI,CAAC,CAAC;QAClD,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,EAAE,aAAa,IAAI,CAAC,CAAC;QACpD,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,UAAU,EAAE,IAAI,CAAC,WAAW;YAC5B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;gBAClB,WAAW;gBACX,YAAY;gBACZ,WAAW,EAAE,WAAW,GAAG,YAAY;aACxC,CAAC,CAAC,CAAC,SAAS;SACd,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ import { AgentBackend, BackendRequest, BackendResponse } from './types.js';
2
+ interface GeminiConfig {
3
+ apiKey: string;
4
+ apiEndpoint?: string;
5
+ }
6
+ export declare class GeminiBackend implements AgentBackend {
7
+ private apiKey;
8
+ private apiEndpoint;
9
+ constructor(config: GeminiConfig);
10
+ generate(request: BackendRequest): Promise<BackendResponse>;
11
+ }
12
+ export {};
13
+ //# sourceMappingURL=gemini.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../../src/agent/backends/gemini.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe,EAAgB,MAAM,YAAY,CAAC;AAEzF,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAwBD,qBAAa,aAAc,YAAW,YAAY;IAChD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,WAAW,CAAS;gBAEhB,MAAM,EAAE,YAAY;IAK1B,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;CAoElE"}
@@ -0,0 +1,71 @@
1
+ export class GeminiBackend {
2
+ apiKey;
3
+ apiEndpoint;
4
+ constructor(config) {
5
+ this.apiKey = config.apiKey;
6
+ this.apiEndpoint = config.apiEndpoint || 'https://generativelanguage.googleapis.com/v1beta/models';
7
+ }
8
+ async generate(request) {
9
+ const url = `${this.apiEndpoint}/${encodeURIComponent(request.model)}:generateContent?key=${this.apiKey}`;
10
+ const mapParts = (content) => {
11
+ if (typeof content === 'string') {
12
+ return [{ text: content }];
13
+ }
14
+ return content.map(block => {
15
+ if (block.type === 'text') {
16
+ return { text: block.text };
17
+ }
18
+ return { inlineData: { mimeType: block.mediaType, data: block.data } };
19
+ });
20
+ };
21
+ const body = {
22
+ systemInstruction: { parts: [{ text: request.system }] },
23
+ contents: request.messages.map(m => ({
24
+ role: m.role === 'assistant' ? 'model' : 'user',
25
+ parts: mapParts(m.content)
26
+ })),
27
+ tools: [{
28
+ functionDeclarations: request.tools.map(t => ({
29
+ name: t.name,
30
+ description: t.description,
31
+ parameters: t.parameters
32
+ }))
33
+ }]
34
+ };
35
+ const response = await fetch(url, {
36
+ method: 'POST',
37
+ headers: { 'Content-Type': 'application/json' },
38
+ body: JSON.stringify(body)
39
+ });
40
+ if (!response.ok) {
41
+ const errorText = await response.text();
42
+ throw new Error(`API error (${response.status}): ${errorText}`);
43
+ }
44
+ const data = await response.json();
45
+ const candidate = data.candidates?.[0];
46
+ const blocks = [];
47
+ const parts = candidate?.content?.parts || [];
48
+ for (const part of parts) {
49
+ if (part.text) {
50
+ blocks.push({ type: 'text', text: part.text });
51
+ }
52
+ if (part.functionCall?.name) {
53
+ blocks.push({
54
+ type: 'tool_use',
55
+ id: `${part.functionCall.name}_${Date.now()}`,
56
+ name: part.functionCall.name,
57
+ input: part.functionCall.args || {}
58
+ });
59
+ }
60
+ }
61
+ const inputTokens = data.usageMetadata?.promptTokenCount ?? 0;
62
+ const outputTokens = data.usageMetadata?.candidatesTokenCount ?? 0;
63
+ const totalTokens = data.usageMetadata?.totalTokenCount ?? (inputTokens + outputTokens);
64
+ return {
65
+ content: blocks,
66
+ stopReason: candidate?.finishReason || 'unknown',
67
+ usage: data.usageMetadata ? { inputTokens, outputTokens, totalTokens } : undefined
68
+ };
69
+ }
70
+ }
71
+ //# sourceMappingURL=gemini.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gemini.js","sourceRoot":"","sources":["../../../src/agent/backends/gemini.ts"],"names":[],"mappings":"AA6BA,MAAM,OAAO,aAAa;IAChB,MAAM,CAAS;IACf,WAAW,CAAS;IAE5B,YAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,yDAAyD,CAAC;IACrG,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAuB;QACpC,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,WAAW,IAAI,kBAAkB,CAAC,OAAO,CAAC,KAAK,CAAC,wBAAwB,IAAI,CAAC,MAAM,EAAE,CAAC;QAC1G,MAAM,QAAQ,GAAG,CAAC,OAAsD,EAAE,EAAE;YAC1E,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;gBAChC,OAAO,CAAC,EAAE,IAA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e,IAAI,CAAC,WAAW,GAAG,YAAY,CAAC,CAAC;QAExF,OAAO;YACL,OAAO,EAAE,MAAM;YACf,UAAU,EAAE,SAAS,EAAE,YAAY,IAAI,SAAS;YAChD,KAAK,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS;SACnF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ import { AgentBackend, BackendRequest, BackendResponse } from './types.js';
2
+ interface InceptionConfig {
3
+ apiKey: string;
4
+ apiEndpoint?: string;
5
+ }
6
+ export declare class InceptionBackend implements AgentBackend {
7
+ private backend;
8
+ constructor(config: InceptionConfig);
9
+ generate(request: BackendRequest): Promise<BackendResponse>;
10
+ }
11
+ export {};
12
+ //# sourceMappingURL=inception.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inception.d.ts","sourceRoot":"","sources":["../../../src/agent/backends/inception.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE3E,UAAU,eAAe;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,gBAAiB,YAAW,YAAY;IACnD,OAAO,CAAC,OAAO,CAA0B;gBAE7B,MAAM,EAAE,eAAe;IAQ7B,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;CAGlE"}
@@ -0,0 +1,15 @@
1
+ import { OpenAICompatibleBackend } from './openai_compatible.js';
2
+ export class InceptionBackend {
3
+ backend;
4
+ constructor(config) {
5
+ this.backend = new OpenAICompatibleBackend({
6
+ apiKey: config.apiKey,
7
+ baseUrl: config.apiEndpoint || 'https://api.inceptionlabs.ai/v1',
8
+ apiPath: '/chat/completions'
9
+ });
10
+ }
11
+ async generate(request) {
12
+ return this.backend.generate(request);
13
+ }
14
+ }
15
+ //# sourceMappingURL=inception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inception.js","sourceRoot":"","sources":["../../../src/agent/backends/inception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAQjE,MAAM,OAAO,gBAAgB;IACnB,OAAO,CAA0B;IAEzC,YAAY,MAAuB;QACjC,IAAI,CAAC,OAAO,GAAG,IAAI,uBAAuB,CAAC;YACzC,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM,CAAC,WAAW,IAAI,iCAAiC;YAChE,OAAO,EAAE,mBAAmB;SAC7B,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAuB;QACpC,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ export { AnthropicBackend } from './anthropic.js';
2
+ export { OpenAIBackend } from './openai.js';
3
+ export { OpenAICompatibleBackend } from './openai_compatible.js';
4
+ export { InceptionBackend } from './inception.js';
5
+ export { GeminiBackend } from './gemini.js';
6
+ export type { AgentBackend, BackendRequest, BackendResponse, ContentBlock, TextBlock, ToolUseBlock, LlmMessage, RequestContentBlock, TokenUsage } from './types.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agent/backends/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,YAAY,EACV,YAAY,EACZ,cAAc,EACd,eAAe,EACf,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,UAAU,EACV,mBAAmB,EACnB,UAAU,EACX,MAAM,YAAY,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { AnthropicBackend } from './anthropic.js';
2
+ export { OpenAIBackend } from './openai.js';
3
+ export { OpenAICompatibleBackend } from './openai_compatible.js';
4
+ export { InceptionBackend } from './inception.js';
5
+ export { GeminiBackend } from './gemini.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/agent/backends/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { AgentBackend, BackendRequest, BackendResponse } from './types.js';
2
+ interface OpenAIConfig {
3
+ apiKey: string;
4
+ apiEndpoint?: string;
5
+ }
6
+ export declare class OpenAIBackend implements AgentBackend {
7
+ private backend;
8
+ constructor(config: OpenAIConfig);
9
+ generate(request: BackendRequest): Promise<BackendResponse>;
10
+ }
11
+ export {};
12
+ //# sourceMappingURL=openai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/agent/backends/openai.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE3E,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,aAAc,YAAW,YAAY;IAChD,OAAO,CAAC,OAAO,CAA0B;gBAE7B,MAAM,EAAE,YAAY;IAQ1B,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;CAGlE"}
@@ -0,0 +1,15 @@
1
+ import { OpenAICompatibleBackend } from './openai_compatible.js';
2
+ export class OpenAIBackend {
3
+ backend;
4
+ constructor(config) {
5
+ this.backend = new OpenAICompatibleBackend({
6
+ apiKey: config.apiKey,
7
+ baseUrl: config.apiEndpoint || 'https://api.openai.com/v1',
8
+ apiPath: '/chat/completions'
9
+ });
10
+ }
11
+ async generate(request) {
12
+ return this.backend.generate(request);
13
+ }
14
+ }
15
+ //# sourceMappingURL=openai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.js","sourceRoot":"","sources":["../../../src/agent/backends/openai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAQjE,MAAM,OAAO,aAAa;IAChB,OAAO,CAA0B;IAEzC,YAAY,MAAoB;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,uBAAuB,CAAC;YACzC,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM,CAAC,WAAW,IAAI,2BAA2B;YAC1D,OAAO,EAAE,mBAAmB;SAC7B,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAuB;QACpC,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;CACF"}