tarsk 0.4.4 → 0.4.6

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 (366) hide show
  1. package/dist/index.js +447375 -37
  2. package/package.json +2 -2
  3. package/dist/agent/agent.error-utils.d.ts +0 -14
  4. package/dist/agent/agent.error-utils.js +0 -52
  5. package/dist/agent/agent.event-transformer.d.ts +0 -55
  6. package/dist/agent/agent.event-transformer.js +0 -175
  7. package/dist/agent/agent.executor.d.ts +0 -26
  8. package/dist/agent/agent.executor.js +0 -286
  9. package/dist/agent/agent.model-resolver.d.ts +0 -22
  10. package/dist/agent/agent.model-resolver.js +0 -67
  11. package/dist/agent/agent.process-manager.d.ts +0 -57
  12. package/dist/agent/agent.process-manager.js +0 -262
  13. package/dist/agent/agent.processing-state-manager.d.ts +0 -74
  14. package/dist/agent/agent.processing-state-manager.js +0 -87
  15. package/dist/agent/agent.prompt-loader.d.ts +0 -16
  16. package/dist/agent/agent.prompt-loader.js +0 -227
  17. package/dist/agent/agent.subagent-executor.d.ts +0 -35
  18. package/dist/agent/agent.subagent-executor.js +0 -135
  19. package/dist/bun/index.d.ts +0 -2
  20. package/dist/bun/index.js +0 -165
  21. package/dist/cli.d.ts +0 -3
  22. package/dist/cli.js +0 -22
  23. package/dist/core/crypto.d.ts +0 -29
  24. package/dist/core/crypto.js +0 -166
  25. package/dist/core/dev-server-cache.d.ts +0 -46
  26. package/dist/core/dev-server-cache.js +0 -59
  27. package/dist/core/env-manager.d.ts +0 -3
  28. package/dist/core/env-manager.js +0 -60
  29. package/dist/core/error-responses.d.ts +0 -61
  30. package/dist/core/error-responses.js +0 -64
  31. package/dist/core/logger.d.ts +0 -10
  32. package/dist/core/logger.js +0 -47
  33. package/dist/core/paths.d.ts +0 -22
  34. package/dist/core/paths.js +0 -26
  35. package/dist/core/random-words.d.ts +0 -18
  36. package/dist/core/random-words.js +0 -135
  37. package/dist/core/response-builder.d.ts +0 -50
  38. package/dist/core/response-builder.js +0 -56
  39. package/dist/core/route-helpers.d.ts +0 -47
  40. package/dist/core/route-helpers.js +0 -54
  41. package/dist/core/run-command-detector.d.ts +0 -26
  42. package/dist/core/run-command-detector.js +0 -98
  43. package/dist/core/stream-helper.d.ts +0 -44
  44. package/dist/core/stream-helper.js +0 -50
  45. package/dist/core/utils.d.ts +0 -43
  46. package/dist/core/utils.js +0 -113
  47. package/dist/core/validation.d.ts +0 -10
  48. package/dist/core/validation.js +0 -20
  49. package/dist/database/database.d.ts +0 -40
  50. package/dist/database/database.encryption.d.ts +0 -33
  51. package/dist/database/database.encryption.js +0 -62
  52. package/dist/database/database.js +0 -480
  53. package/dist/database/database.state.d.ts +0 -52
  54. package/dist/database/database.state.js +0 -119
  55. package/dist/database/database.test-utils.d.ts +0 -22
  56. package/dist/database/database.test-utils.js +0 -39
  57. package/dist/database/database.types.d.ts +0 -3
  58. package/dist/database/database.types.js +0 -2
  59. package/dist/features/agents/agents.manager.d.ts +0 -24
  60. package/dist/features/agents/agents.manager.js +0 -200
  61. package/dist/features/ask-user/ask-user.routes.d.ts +0 -9
  62. package/dist/features/ask-user/ask-user.routes.js +0 -35
  63. package/dist/features/chat/chat-delete.route.d.ts +0 -15
  64. package/dist/features/chat/chat-delete.route.js +0 -36
  65. package/dist/features/chat/chat-post.route.d.ts +0 -11
  66. package/dist/features/chat/chat-post.route.js +0 -270
  67. package/dist/features/chat/chat-stop.route.d.ts +0 -21
  68. package/dist/features/chat/chat-stop.route.js +0 -22
  69. package/dist/features/chat/chat-subscribe.route.d.ts +0 -9
  70. package/dist/features/chat/chat-subscribe.route.js +0 -71
  71. package/dist/features/chat/chat.routes.d.ts +0 -22
  72. package/dist/features/chat/chat.routes.js +0 -29
  73. package/dist/features/conversations/conversations-delete.route.d.ts +0 -16
  74. package/dist/features/conversations/conversations-delete.route.js +0 -34
  75. package/dist/features/conversations/conversations-get-all.route.d.ts +0 -16
  76. package/dist/features/conversations/conversations-get-all.route.js +0 -39
  77. package/dist/features/conversations/conversations-get-by-id.route.d.ts +0 -16
  78. package/dist/features/conversations/conversations-get-by-id.route.js +0 -38
  79. package/dist/features/conversations/conversations-get-deleted.route.d.ts +0 -15
  80. package/dist/features/conversations/conversations-get-deleted.route.js +0 -34
  81. package/dist/features/conversations/conversations-get-messages.route.d.ts +0 -16
  82. package/dist/features/conversations/conversations-get-messages.route.js +0 -49
  83. package/dist/features/conversations/conversations.content.d.ts +0 -28
  84. package/dist/features/conversations/conversations.content.js +0 -142
  85. package/dist/features/conversations/conversations.database.d.ts +0 -108
  86. package/dist/features/conversations/conversations.database.js +0 -373
  87. package/dist/features/conversations/conversations.manager.d.ts +0 -130
  88. package/dist/features/conversations/conversations.manager.js +0 -162
  89. package/dist/features/conversations/conversations.routes.d.ts +0 -21
  90. package/dist/features/conversations/conversations.routes.js +0 -38
  91. package/dist/features/conversations/token-usage.route.d.ts +0 -41
  92. package/dist/features/conversations/token-usage.route.js +0 -419
  93. package/dist/features/git/git-commit.route.d.ts +0 -12
  94. package/dist/features/git/git-commit.route.js +0 -39
  95. package/dist/features/git/git-create-branch.route.d.ts +0 -28
  96. package/dist/features/git/git-create-branch.route.js +0 -119
  97. package/dist/features/git/git-create-pr.route.d.ts +0 -13
  98. package/dist/features/git/git-create-pr.route.js +0 -50
  99. package/dist/features/git/git-create-repo.route.d.ts +0 -14
  100. package/dist/features/git/git-create-repo.route.js +0 -108
  101. package/dist/features/git/git-diff.route.d.ts +0 -30
  102. package/dist/features/git/git-diff.route.js +0 -189
  103. package/dist/features/git/git-fetch.route.d.ts +0 -12
  104. package/dist/features/git/git-fetch.route.js +0 -31
  105. package/dist/features/git/git-generate-commit-message.route.d.ts +0 -12
  106. package/dist/features/git/git-generate-commit-message.route.js +0 -76
  107. package/dist/features/git/git-generate-pr-info.route.d.ts +0 -13
  108. package/dist/features/git/git-generate-pr-info.route.js +0 -147
  109. package/dist/features/git/git-github-status.route.d.ts +0 -16
  110. package/dist/features/git/git-github-status.route.js +0 -68
  111. package/dist/features/git/git-log.route.d.ts +0 -17
  112. package/dist/features/git/git-log.route.js +0 -33
  113. package/dist/features/git/git-pr-status.route.d.ts +0 -15
  114. package/dist/features/git/git-pr-status.route.js +0 -33
  115. package/dist/features/git/git-pull.route.d.ts +0 -12
  116. package/dist/features/git/git-pull.route.js +0 -35
  117. package/dist/features/git/git-push.route.d.ts +0 -12
  118. package/dist/features/git/git-push.route.js +0 -46
  119. package/dist/features/git/git-status-cache.database.d.ts +0 -7
  120. package/dist/features/git/git-status-cache.database.js +0 -53
  121. package/dist/features/git/git-status.route.d.ts +0 -15
  122. package/dist/features/git/git-status.route.js +0 -62
  123. package/dist/features/git/git-sync-branch.route.d.ts +0 -4
  124. package/dist/features/git/git-sync-branch.route.js +0 -208
  125. package/dist/features/git/git-unified-status.route.d.ts +0 -30
  126. package/dist/features/git/git-unified-status.route.js +0 -165
  127. package/dist/features/git/git-username.route.d.ts +0 -3
  128. package/dist/features/git/git-username.route.js +0 -24
  129. package/dist/features/git/git.manager.d.ts +0 -139
  130. package/dist/features/git/git.manager.js +0 -352
  131. package/dist/features/git/git.routes.d.ts +0 -4
  132. package/dist/features/git/git.routes.js +0 -116
  133. package/dist/features/git/git.utils.d.ts +0 -82
  134. package/dist/features/git/git.utils.js +0 -1040
  135. package/dist/features/mcp/mcp.config.d.ts +0 -27
  136. package/dist/features/mcp/mcp.config.js +0 -148
  137. package/dist/features/mcp/mcp.manager.d.ts +0 -61
  138. package/dist/features/mcp/mcp.manager.js +0 -254
  139. package/dist/features/mcp/mcp.popular.json +0 -103
  140. package/dist/features/mcp/mcp.routes.d.ts +0 -13
  141. package/dist/features/mcp/mcp.routes.js +0 -159
  142. package/dist/features/mcp/mcp.types.d.ts +0 -80
  143. package/dist/features/mcp/mcp.types.js +0 -8
  144. package/dist/features/metadata/metadata.manager.d.ts +0 -126
  145. package/dist/features/metadata/metadata.manager.js +0 -423
  146. package/dist/features/models/model-info-aihubmix.d.ts +0 -25
  147. package/dist/features/models/model-info-aihubmix.js +0 -117
  148. package/dist/features/models/model-info-openrouter.d.ts +0 -25
  149. package/dist/features/models/model-info-openrouter.js +0 -104
  150. package/dist/features/models/model-info.d.ts +0 -37
  151. package/dist/features/models/model-info.js +0 -39
  152. package/dist/features/models/models-catalog.d.ts +0 -49
  153. package/dist/features/models/models-catalog.js +0 -80
  154. package/dist/features/models/models-catalog.route.d.ts +0 -43
  155. package/dist/features/models/models-catalog.route.js +0 -15
  156. package/dist/features/models/models-get-available.route.d.ts +0 -36
  157. package/dist/features/models/models-get-available.route.js +0 -66
  158. package/dist/features/models/models-get-enabled.route.d.ts +0 -33
  159. package/dist/features/models/models-get-enabled.route.js +0 -45
  160. package/dist/features/models/models-get-model-info.route.d.ts +0 -31
  161. package/dist/features/models/models-get-model-info.route.js +0 -84
  162. package/dist/features/models/models-model-disable.route.d.ts +0 -15
  163. package/dist/features/models/models-model-disable.route.js +0 -20
  164. package/dist/features/models/models-model-enable.route.d.ts +0 -13
  165. package/dist/features/models/models-model-enable.route.js +0 -20
  166. package/dist/features/models/models-provider-refresh.route.d.ts +0 -17
  167. package/dist/features/models/models-provider-refresh.route.js +0 -20
  168. package/dist/features/models/models.manager.d.ts +0 -58
  169. package/dist/features/models/models.manager.js +0 -138
  170. package/dist/features/models/models.routes.d.ts +0 -18
  171. package/dist/features/models/models.routes.js +0 -83
  172. package/dist/features/models/open-router-models.d.ts +0 -38
  173. package/dist/features/models/open-router-models.js +0 -73
  174. package/dist/features/models/openai-models.d.ts +0 -63
  175. package/dist/features/models/openai-models.js +0 -150
  176. package/dist/features/onboarding/onboarding-get-git-check.route.d.ts +0 -11
  177. package/dist/features/onboarding/onboarding-get-git-check.route.js +0 -28
  178. package/dist/features/onboarding/onboarding-get-status.route.d.ts +0 -12
  179. package/dist/features/onboarding/onboarding-get-status.route.js +0 -15
  180. package/dist/features/onboarding/onboarding-post-complete.route.d.ts +0 -12
  181. package/dist/features/onboarding/onboarding-post-complete.route.js +0 -15
  182. package/dist/features/onboarding/onboarding-post-reset.route.d.ts +0 -12
  183. package/dist/features/onboarding/onboarding-post-reset.route.js +0 -15
  184. package/dist/features/onboarding/onboarding.routes.d.ts +0 -18
  185. package/dist/features/onboarding/onboarding.routes.js +0 -28
  186. package/dist/features/project-todos/project-todos.database.d.ts +0 -38
  187. package/dist/features/project-todos/project-todos.database.js +0 -91
  188. package/dist/features/project-todos/project-todos.routes.d.ts +0 -4
  189. package/dist/features/project-todos/project-todos.routes.js +0 -94
  190. package/dist/features/projects/projects-ai-files.route.d.ts +0 -148
  191. package/dist/features/projects/projects-ai-files.route.js +0 -425
  192. package/dist/features/projects/projects-commands.route.d.ts +0 -27
  193. package/dist/features/projects/projects-commands.route.js +0 -39
  194. package/dist/features/projects/projects-create.route.d.ts +0 -19
  195. package/dist/features/projects/projects-create.route.js +0 -37
  196. package/dist/features/projects/projects-delete.route.d.ts +0 -24
  197. package/dist/features/projects/projects-delete.route.js +0 -34
  198. package/dist/features/projects/projects-get.route.d.ts +0 -47
  199. package/dist/features/projects/projects-get.route.js +0 -36
  200. package/dist/features/projects/projects-list.route.d.ts +0 -58
  201. package/dist/features/projects/projects-list.route.js +0 -59
  202. package/dist/features/projects/projects-open-folder.route.d.ts +0 -10
  203. package/dist/features/projects/projects-open-folder.route.js +0 -11
  204. package/dist/features/projects/projects-open.route.d.ts +0 -26
  205. package/dist/features/projects/projects-open.route.js +0 -49
  206. package/dist/features/projects/projects-package-scripts.route.d.ts +0 -15
  207. package/dist/features/projects/projects-package-scripts.route.js +0 -96
  208. package/dist/features/projects/projects-run-command.route.d.ts +0 -8
  209. package/dist/features/projects/projects-run-command.route.js +0 -21
  210. package/dist/features/projects/projects-run.route.d.ts +0 -51
  211. package/dist/features/projects/projects-run.route.js +0 -74
  212. package/dist/features/projects/projects-update.route.d.ts +0 -24
  213. package/dist/features/projects/projects-update.route.js +0 -81
  214. package/dist/features/projects/projects.creator.d.ts +0 -33
  215. package/dist/features/projects/projects.creator.js +0 -555
  216. package/dist/features/projects/projects.database.d.ts +0 -61
  217. package/dist/features/projects/projects.database.js +0 -212
  218. package/dist/features/projects/projects.manager.d.ts +0 -291
  219. package/dist/features/projects/projects.manager.js +0 -426
  220. package/dist/features/projects/projects.open-with.d.ts +0 -27
  221. package/dist/features/projects/projects.open-with.js +0 -156
  222. package/dist/features/projects/projects.routes.d.ts +0 -20
  223. package/dist/features/projects/projects.routes.js +0 -255
  224. package/dist/features/projects/terminal-session-manager.d.ts +0 -55
  225. package/dist/features/projects/terminal-session-manager.js +0 -90
  226. package/dist/features/providers/provider-resolver.d.ts +0 -13
  227. package/dist/features/providers/provider-resolver.js +0 -22
  228. package/dist/features/providers/providers-get-credits.route.d.ts +0 -15
  229. package/dist/features/providers/providers-get-credits.route.js +0 -51
  230. package/dist/features/providers/providers-get.route.d.ts +0 -16
  231. package/dist/features/providers/providers-get.route.js +0 -32
  232. package/dist/features/providers/providers-open-external.route.d.ts +0 -15
  233. package/dist/features/providers/providers-open-external.route.js +0 -49
  234. package/dist/features/providers/providers-post-bulk-keys.route.d.ts +0 -14
  235. package/dist/features/providers/providers-post-bulk-keys.route.js +0 -31
  236. package/dist/features/providers/providers-post-keys.route.d.ts +0 -14
  237. package/dist/features/providers/providers-post-keys.route.js +0 -25
  238. package/dist/features/providers/providers.routes.d.ts +0 -19
  239. package/dist/features/providers/providers.routes.js +0 -31
  240. package/dist/features/rules/rules-post.route.d.ts +0 -43
  241. package/dist/features/rules/rules-post.route.js +0 -89
  242. package/dist/features/rules/rules.manager.d.ts +0 -36
  243. package/dist/features/rules/rules.manager.js +0 -203
  244. package/dist/features/rules/rules.routes.d.ts +0 -12
  245. package/dist/features/rules/rules.routes.js +0 -13
  246. package/dist/features/run/run-get-running.route.d.ts +0 -15
  247. package/dist/features/run/run-get-running.route.js +0 -21
  248. package/dist/features/run/run-post-start.route.d.ts +0 -8
  249. package/dist/features/run/run-post-start.route.js +0 -21
  250. package/dist/features/run/run-post-stop.route.d.ts +0 -15
  251. package/dist/features/run/run-post-stop.route.js +0 -24
  252. package/dist/features/run/run-post-suggest.route.d.ts +0 -15
  253. package/dist/features/run/run-post-suggest.route.js +0 -21
  254. package/dist/features/run/run-put-command.route.d.ts +0 -15
  255. package/dist/features/run/run-put-command.route.js +0 -24
  256. package/dist/features/run/run.routes.d.ts +0 -19
  257. package/dist/features/run/run.routes.js +0 -31
  258. package/dist/features/scaffold/index.d.ts +0 -7
  259. package/dist/features/scaffold/index.js +0 -5
  260. package/dist/features/scaffold/scaffold-get-templates.route.d.ts +0 -27
  261. package/dist/features/scaffold/scaffold-get-templates.route.js +0 -17
  262. package/dist/features/scaffold/scaffold-post.route.d.ts +0 -8
  263. package/dist/features/scaffold/scaffold-post.route.js +0 -30
  264. package/dist/features/scaffold/scaffold.routes.d.ts +0 -10
  265. package/dist/features/scaffold/scaffold.routes.js +0 -16
  266. package/dist/features/scaffold/scaffold.runner.d.ts +0 -48
  267. package/dist/features/scaffold/scaffold.runner.js +0 -475
  268. package/dist/features/scaffold/scaffold.types.d.ts +0 -26
  269. package/dist/features/scaffold/scaffold.types.js +0 -5
  270. package/dist/features/skills/skills.activation.d.ts +0 -31
  271. package/dist/features/skills/skills.activation.js +0 -155
  272. package/dist/features/skills/skills.manager.d.ts +0 -35
  273. package/dist/features/skills/skills.manager.js +0 -251
  274. package/dist/features/slash-commands/slash-commands-delete.route.d.ts +0 -23
  275. package/dist/features/slash-commands/slash-commands-delete.route.js +0 -36
  276. package/dist/features/slash-commands/slash-commands-get.route.d.ts +0 -53
  277. package/dist/features/slash-commands/slash-commands-get.route.js +0 -54
  278. package/dist/features/slash-commands/slash-commands-post.route.d.ts +0 -39
  279. package/dist/features/slash-commands/slash-commands-post.route.js +0 -70
  280. package/dist/features/slash-commands/slash-commands-put.route.d.ts +0 -23
  281. package/dist/features/slash-commands/slash-commands-put.route.js +0 -36
  282. package/dist/features/slash-commands/slash-commands.manager.d.ts +0 -46
  283. package/dist/features/slash-commands/slash-commands.manager.js +0 -265
  284. package/dist/features/slash-commands/slash-commands.routes.d.ts +0 -13
  285. package/dist/features/slash-commands/slash-commands.routes.js +0 -20
  286. package/dist/features/threads/threads-ai-files.route.d.ts +0 -153
  287. package/dist/features/threads/threads-ai-files.route.js +0 -287
  288. package/dist/features/threads/threads-conversation-folder-path.route.d.ts +0 -14
  289. package/dist/features/threads/threads-conversation-folder-path.route.js +0 -23
  290. package/dist/features/threads/threads-create.route.d.ts +0 -22
  291. package/dist/features/threads/threads-create.route.js +0 -60
  292. package/dist/features/threads/threads-delete.route.d.ts +0 -25
  293. package/dist/features/threads/threads-delete.route.js +0 -35
  294. package/dist/features/threads/threads-files.route.d.ts +0 -15
  295. package/dist/features/threads/threads-files.route.js +0 -20
  296. package/dist/features/threads/threads-fix-comments.route.d.ts +0 -26
  297. package/dist/features/threads/threads-fix-comments.route.js +0 -45
  298. package/dist/features/threads/threads-get.route.d.ts +0 -30
  299. package/dist/features/threads/threads-get.route.js +0 -38
  300. package/dist/features/threads/threads-list.route.d.ts +0 -56
  301. package/dist/features/threads/threads-list.route.js +0 -58
  302. package/dist/features/threads/threads-messages.route.d.ts +0 -28
  303. package/dist/features/threads/threads-messages.route.js +0 -110
  304. package/dist/features/threads/threads-open.route.d.ts +0 -26
  305. package/dist/features/threads/threads-open.route.js +0 -62
  306. package/dist/features/threads/threads-select.route.d.ts +0 -25
  307. package/dist/features/threads/threads-select.route.js +0 -35
  308. package/dist/features/threads/threads-update.route.d.ts +0 -15
  309. package/dist/features/threads/threads-update.route.js +0 -30
  310. package/dist/features/threads/threads.database.d.ts +0 -68
  311. package/dist/features/threads/threads.database.js +0 -215
  312. package/dist/features/threads/threads.manager.d.ts +0 -204
  313. package/dist/features/threads/threads.manager.js +0 -505
  314. package/dist/features/threads/threads.routes.d.ts +0 -20
  315. package/dist/features/threads/threads.routes.js +0 -230
  316. package/dist/features/todos/todos.database.d.ts +0 -14
  317. package/dist/features/todos/todos.database.js +0 -31
  318. package/dist/features/updates/updates.routes.d.ts +0 -13
  319. package/dist/features/updates/updates.routes.js +0 -40
  320. package/dist/index.d.ts +0 -3
  321. package/dist/project-analyzer.d.ts +0 -26
  322. package/dist/project-analyzer.js +0 -307
  323. package/dist/server.d.ts +0 -12
  324. package/dist/server.js +0 -142
  325. package/dist/tools/agent-tool.d.ts +0 -49
  326. package/dist/tools/agent-tool.js +0 -131
  327. package/dist/tools/ask-user.d.ts +0 -25
  328. package/dist/tools/ask-user.js +0 -74
  329. package/dist/tools/ast-grep.d.ts +0 -28
  330. package/dist/tools/ast-grep.js +0 -273
  331. package/dist/tools/bash.d.ts +0 -33
  332. package/dist/tools/bash.js +0 -186
  333. package/dist/tools/edit-diff.d.ts +0 -24
  334. package/dist/tools/edit-diff.js +0 -136
  335. package/dist/tools/edit.d.ts +0 -28
  336. package/dist/tools/edit.js +0 -78
  337. package/dist/tools/find.d.ts +0 -31
  338. package/dist/tools/find.js +0 -117
  339. package/dist/tools/grep.d.ts +0 -37
  340. package/dist/tools/grep.js +0 -231
  341. package/dist/tools/index.d.ts +0 -93
  342. package/dist/tools/index.js +0 -110
  343. package/dist/tools/ls.d.ts +0 -31
  344. package/dist/tools/ls.js +0 -108
  345. package/dist/tools/mcp-tools.d.ts +0 -31
  346. package/dist/tools/mcp-tools.js +0 -59
  347. package/dist/tools/path-utils.d.ts +0 -14
  348. package/dist/tools/path-utils.js +0 -87
  349. package/dist/tools/read.d.ts +0 -27
  350. package/dist/tools/read.js +0 -86
  351. package/dist/tools/resolve-bin.d.ts +0 -5
  352. package/dist/tools/resolve-bin.js +0 -28
  353. package/dist/tools/shell.d.ts +0 -7
  354. package/dist/tools/shell.js +0 -143
  355. package/dist/tools/skill-reference-tool.d.ts +0 -30
  356. package/dist/tools/skill-reference-tool.js +0 -171
  357. package/dist/tools/skill-tool.d.ts +0 -33
  358. package/dist/tools/skill-tool.js +0 -213
  359. package/dist/tools/todo.d.ts +0 -20
  360. package/dist/tools/todo.js +0 -168
  361. package/dist/tools/tool-helpers.d.ts +0 -78
  362. package/dist/tools/tool-helpers.js +0 -109
  363. package/dist/tools/truncate.d.ts +0 -31
  364. package/dist/tools/truncate.js +0 -164
  365. package/dist/tools/write.d.ts +0 -21
  366. package/dist/tools/write.js +0 -65
@@ -1,21 +0,0 @@
1
- /**
2
- * POST /api/chat/stop/:threadId
3
- * Stop active agent execution for a thread
4
- */
5
- import type { Context } from "hono";
6
- import type { ProcessingStateManager } from "../../agent/agent.processing-state-manager.js";
7
- export declare function stopChatGeneration(c: Context, processingStateManager: ProcessingStateManager): Promise<(Response & import("hono").TypedResponse<{
8
- error: {
9
- code: string;
10
- message: string;
11
- details?: import("hono/utils/types").JSONValue | undefined;
12
- timestamp: string;
13
- };
14
- }, any, "json">) | (Response & import("hono").TypedResponse<{
15
- success: false;
16
- message: string;
17
- }, 200, "json">) | (Response & import("hono").TypedResponse<{
18
- success: true;
19
- message: string;
20
- }, 200, "json">)>;
21
- //# sourceMappingURL=chat-stop.route.d.ts.map
@@ -1,22 +0,0 @@
1
- /**
2
- * POST /api/chat/stop/:threadId
3
- * Stop active agent execution for a thread
4
- */
5
- import { errorResponse } from "../../core/route-helpers.js";
6
- import { ErrorCodes } from "../../core/error-responses.js";
7
- export async function stopChatGeneration(c, processingStateManager) {
8
- const threadId = c.req.param("threadId");
9
- if (!threadId) {
10
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "threadId is required", 400);
11
- }
12
- if (!processingStateManager.isProcessing(threadId)) {
13
- return c.json({ success: false, message: "Thread is not currently processing" }, 200);
14
- }
15
- const aborted = processingStateManager.abortThread(threadId);
16
- if (aborted) {
17
- console.log(`[chat-stop] Successfully aborted thread ${threadId}`);
18
- return c.json({ success: true, message: "Generation stopped" }, 200);
19
- }
20
- return c.json({ success: false, message: "No active execution found for thread" }, 200);
21
- }
22
- //# sourceMappingURL=chat-stop.route.js.map
@@ -1,9 +0,0 @@
1
- /**
2
- * GET /api/chat/subscribe/:threadId
3
- * Subscribe to an in-progress thread's streaming events.
4
- * Replays buffered events then streams new events as they arrive.
5
- */
6
- import type { Context } from "hono";
7
- import type { ProcessingStateManager } from "../../agent/agent.processing-state-manager.js";
8
- export declare function subscribeToChatStream(c: Context, processingStateManager: ProcessingStateManager): Response;
9
- //# sourceMappingURL=chat-subscribe.route.d.ts.map
@@ -1,71 +0,0 @@
1
- /**
2
- * GET /api/chat/subscribe/:threadId
3
- * Subscribe to an in-progress thread's streaming events.
4
- * Replays buffered events then streams new events as they arrive.
5
- */
6
- import { stream } from "hono/streaming";
7
- export function subscribeToChatStream(c, processingStateManager) {
8
- const threadId = c.req.param("threadId");
9
- if (!threadId) {
10
- return c.json({ error: "threadId is required" }, 400);
11
- }
12
- if (!processingStateManager.isProcessing(threadId)) {
13
- return c.json({ error: "Thread is not currently processing" }, 404);
14
- }
15
- return stream(c, async (writer) => {
16
- // Replay buffered events
17
- const buffered = processingStateManager.getBufferedEvents(threadId);
18
- for (const event of buffered) {
19
- await writer.write(JSON.stringify(event) + "\n");
20
- }
21
- // Subscribe to new events
22
- let resolve = null;
23
- const queue = [];
24
- let done = false;
25
- const unsubscribe = processingStateManager.subscribe(threadId, (event) => {
26
- if (event.type === "complete") {
27
- done = true;
28
- queue.push(event);
29
- }
30
- else {
31
- queue.push(event);
32
- }
33
- // Wake up the writer loop
34
- if (resolve) {
35
- resolve();
36
- resolve = null;
37
- }
38
- });
39
- writer.onAbort(() => {
40
- done = true;
41
- unsubscribe();
42
- if (resolve) {
43
- resolve();
44
- resolve = null;
45
- }
46
- });
47
- try {
48
- while (!done) {
49
- // Drain all queued events
50
- while (queue.length > 0) {
51
- const event = queue.shift();
52
- await writer.write(JSON.stringify(event) + "\n");
53
- if (event.type === "complete") {
54
- done = true;
55
- break;
56
- }
57
- }
58
- if (!done) {
59
- // Wait for next event
60
- await new Promise((r) => {
61
- resolve = r;
62
- });
63
- }
64
- }
65
- }
66
- finally {
67
- unsubscribe();
68
- }
69
- });
70
- }
71
- //# sourceMappingURL=chat-subscribe.route.js.map
@@ -1,22 +0,0 @@
1
- /**
2
- * Chat routes for the REST API
3
- *
4
- * Handles chat message processing:
5
- * - POST /api/chat - Send a message to the agent
6
- * - DELETE /api/chat/:threadId - Start a new conversation
7
- */
8
- import { Hono } from "hono";
9
- import type { ThreadManager } from "../threads/threads.manager.js";
10
- import type { AgentExecutor } from "../../agent/agent.executor.js";
11
- import type { ConversationManager } from "../conversations/conversations.manager.js";
12
- import type { ProcessingStateManager } from "../../agent/agent.processing-state-manager.js";
13
- /**
14
- * Creates chat routes
15
- * @param threadManager - The ThreadManager instance
16
- * @param agentExecutor - The AgentExecutor instance
17
- * @param conversationManager - The ConversationManager instance
18
- * @param processingStateManager - The ProcessingStateManager instance
19
- * @returns Hono router with chat routes
20
- */
21
- export declare function createChatRoutes(threadManager: ThreadManager, agentExecutor: AgentExecutor, conversationManager: ConversationManager, processingStateManager: ProcessingStateManager): Hono;
22
- //# sourceMappingURL=chat.routes.d.ts.map
@@ -1,29 +0,0 @@
1
- /**
2
- * Chat routes for the REST API
3
- *
4
- * Handles chat message processing:
5
- * - POST /api/chat - Send a message to the agent
6
- * - DELETE /api/chat/:threadId - Start a new conversation
7
- */
8
- import { Hono } from "hono";
9
- import { postChatMessage } from "./chat-post.route.js";
10
- import { deleteChat } from "./chat-delete.route.js";
11
- import { subscribeToChatStream } from "./chat-subscribe.route.js";
12
- import { stopChatGeneration } from "./chat-stop.route.js";
13
- /**
14
- * Creates chat routes
15
- * @param threadManager - The ThreadManager instance
16
- * @param agentExecutor - The AgentExecutor instance
17
- * @param conversationManager - The ConversationManager instance
18
- * @param processingStateManager - The ProcessingStateManager instance
19
- * @returns Hono router with chat routes
20
- */
21
- export function createChatRoutes(threadManager, agentExecutor, conversationManager, processingStateManager) {
22
- const router = new Hono();
23
- router.post("/", (c) => postChatMessage(c, threadManager, agentExecutor, conversationManager, processingStateManager));
24
- router.post("/stop/:threadId", (c) => stopChatGeneration(c, processingStateManager));
25
- router.get("/subscribe/:threadId", (c) => subscribeToChatStream(c, processingStateManager));
26
- router.delete("/:threadId", (c) => deleteChat(c, threadManager));
27
- return router;
28
- }
29
- //# sourceMappingURL=chat.routes.js.map
@@ -1,16 +0,0 @@
1
- /**
2
- * DELETE /api/conversations/:threadId/:conversationId
3
- * Clear conversation history for a specific conversation (not all conversations)
4
- */
5
- import type { Context } from "hono";
6
- import type { ConversationManager } from "../conversations/conversations.manager.js";
7
- import type { ThreadManager } from "../threads/threads.manager.js";
8
- export declare function deleteConversation(c: Context, conversationManager: ConversationManager, threadManager: ThreadManager): Promise<(Response & import("hono").TypedResponse<{
9
- error: {
10
- code: string;
11
- message: string;
12
- details?: import("hono/utils/types").JSONValue | undefined;
13
- timestamp: string;
14
- };
15
- }, any, "json">) | (Response & import("hono").TypedResponse<import("hono/utils/types").JSONValue, any, "json">)>;
16
- //# sourceMappingURL=conversations-delete.route.d.ts.map
@@ -1,34 +0,0 @@
1
- /**
2
- * DELETE /api/conversations/:threadId/:conversationId
3
- * Clear conversation history for a specific conversation (not all conversations)
4
- */
5
- import { errorResponse, successResponse } from "../../core/route-helpers.js";
6
- import { ErrorCodes } from "../../core/error-responses.js";
7
- export async function deleteConversation(c, conversationManager, threadManager) {
8
- try {
9
- const threadId = c.req.param("threadId");
10
- const conversationId = c.req.param("conversationId");
11
- if (!threadId || typeof threadId !== "string") {
12
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "threadId is required and must be a string", 400);
13
- }
14
- if (!conversationId || typeof conversationId !== "string") {
15
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "conversationId is required and must be a string", 400);
16
- }
17
- // Verify thread exists
18
- const thread = await threadManager.getThread(threadId);
19
- if (!thread) {
20
- return errorResponse(c, ErrorCodes.THREAD_NOT_FOUND, `Thread not found: ${threadId}`, 404);
21
- }
22
- // Clear conversation history
23
- await conversationManager.clearChatHistory(thread.path, conversationId);
24
- return successResponse(c, {
25
- message: "Conversation history cleared successfully",
26
- threadId,
27
- conversationId,
28
- }, 200);
29
- }
30
- catch (error) {
31
- return errorResponse(c, ErrorCodes.HISTORY_CLEAR_ERROR, "Failed to clear conversation history", 500, error instanceof Error ? error.message : String(error));
32
- }
33
- }
34
- //# sourceMappingURL=conversations-delete.route.js.map
@@ -1,16 +0,0 @@
1
- /**
2
- * GET /api/conversations/:threadId
3
- * Get all conversation history for a thread (all conversations)
4
- */
5
- import type { Context } from "hono";
6
- import type { ConversationManager } from "../conversations/conversations.manager.js";
7
- import type { ThreadManager } from "../threads/threads.manager.js";
8
- export declare function getAllConversations(c: Context, conversationManager: ConversationManager, threadManager: ThreadManager): Promise<(Response & import("hono").TypedResponse<{
9
- error: {
10
- code: string;
11
- message: string;
12
- details?: import("hono/utils/types").JSONValue | undefined;
13
- timestamp: string;
14
- };
15
- }, any, "json">) | (Response & import("hono").TypedResponse<import("hono/utils/types").JSONValue, any, "json">)>;
16
- //# sourceMappingURL=conversations-get-all.route.d.ts.map
@@ -1,39 +0,0 @@
1
- /**
2
- * GET /api/conversations/:threadId
3
- * Get all conversation history for a thread (all conversations)
4
- */
5
- import { errorResponse, successResponse } from "../../core/route-helpers.js";
6
- import { ErrorCodes } from "../../core/error-responses.js";
7
- export async function getAllConversations(c, conversationManager, threadManager) {
8
- try {
9
- const threadId = c.req.param("threadId");
10
- if (!threadId || typeof threadId !== "string") {
11
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "threadId is required and must be a string", 400);
12
- }
13
- // Verify thread exists
14
- const thread = await threadManager.getThread(threadId);
15
- if (!thread) {
16
- return errorResponse(c, ErrorCodes.THREAD_NOT_FOUND, `Thread not found: ${threadId}`, 404);
17
- }
18
- // Get conversation history
19
- const history = await conversationManager.getConversationHistory(thread.path);
20
- if (!history) {
21
- return successResponse(c, {
22
- threadId,
23
- messages: [],
24
- lastUpdated: new Date().toISOString(),
25
- conversationIds: [],
26
- }, 200);
27
- }
28
- // Get all conversation IDs for this thread
29
- const conversationIds = await conversationManager.getConversationIds(thread.path);
30
- return successResponse(c, {
31
- ...history,
32
- conversationIds,
33
- }, 200);
34
- }
35
- catch (error) {
36
- return errorResponse(c, ErrorCodes.HISTORY_FETCH_ERROR, "Failed to fetch conversation history", 500, error instanceof Error ? error.message : String(error));
37
- }
38
- }
39
- //# sourceMappingURL=conversations-get-all.route.js.map
@@ -1,16 +0,0 @@
1
- /**
2
- * GET /api/conversations/:threadId/:conversationId
3
- * Get conversation history for a specific conversation within a thread
4
- */
5
- import type { Context } from "hono";
6
- import type { ConversationManager } from "../conversations/conversations.manager.js";
7
- import type { ThreadManager } from "../threads/threads.manager.js";
8
- export declare function getConversationById(c: Context, conversationManager: ConversationManager, threadManager: ThreadManager): Promise<(Response & import("hono").TypedResponse<{
9
- error: {
10
- code: string;
11
- message: string;
12
- details?: import("hono/utils/types").JSONValue | undefined;
13
- timestamp: string;
14
- };
15
- }, any, "json">) | (Response & import("hono").TypedResponse<import("hono/utils/types").JSONValue, any, "json">)>;
16
- //# sourceMappingURL=conversations-get-by-id.route.d.ts.map
@@ -1,38 +0,0 @@
1
- /**
2
- * GET /api/conversations/:threadId/:conversationId
3
- * Get conversation history for a specific conversation within a thread
4
- */
5
- import { errorResponse, successResponse } from "../../core/route-helpers.js";
6
- import { ErrorCodes } from "../../core/error-responses.js";
7
- export async function getConversationById(c, conversationManager, threadManager) {
8
- try {
9
- const threadId = c.req.param("threadId");
10
- const conversationId = c.req.param("conversationId");
11
- if (!threadId || typeof threadId !== "string") {
12
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "threadId is required and must be a string", 400);
13
- }
14
- if (!conversationId || typeof conversationId !== "string") {
15
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "conversationId is required and must be a string", 400);
16
- }
17
- // Verify thread exists
18
- const thread = await threadManager.getThread(threadId);
19
- if (!thread) {
20
- return errorResponse(c, ErrorCodes.THREAD_NOT_FOUND, `Thread not found: ${threadId}`, 404);
21
- }
22
- // Get conversation history for specific conversation
23
- const history = await conversationManager.getConversationHistoryByConversationId(thread.path, conversationId);
24
- if (!history) {
25
- return successResponse(c, {
26
- threadId,
27
- conversationId,
28
- messages: [],
29
- lastUpdated: new Date().toISOString(),
30
- }, 200);
31
- }
32
- return successResponse(c, history, 200);
33
- }
34
- catch (error) {
35
- return errorResponse(c, ErrorCodes.HISTORY_FETCH_ERROR, "Failed to fetch conversation history", 500, error instanceof Error ? error.message : String(error));
36
- }
37
- }
38
- //# sourceMappingURL=conversations-get-by-id.route.js.map
@@ -1,15 +0,0 @@
1
- /**
2
- * GET /api/conversations/:threadId/deleted
3
- * Get deleted conversation history for a thread
4
- */
5
- import type { Context } from "hono";
6
- import type { ConversationManager } from "../conversations/conversations.manager.js";
7
- export declare function getDeletedConversations(c: Context, conversationManager: ConversationManager): Promise<(Response & import("hono").TypedResponse<{
8
- error: {
9
- code: string;
10
- message: string;
11
- details?: import("hono/utils/types").JSONValue | undefined;
12
- timestamp: string;
13
- };
14
- }, any, "json">) | (Response & import("hono").TypedResponse<import("hono/utils/types").JSONValue, any, "json">)>;
15
- //# sourceMappingURL=conversations-get-deleted.route.d.ts.map
@@ -1,34 +0,0 @@
1
- /**
2
- * GET /api/conversations/:threadId/deleted
3
- * Get deleted conversation history for a thread
4
- */
5
- import { errorResponse, successResponse } from "../../core/route-helpers.js";
6
- import { ErrorCodes } from "../../core/error-responses.js";
7
- export async function getDeletedConversations(c, conversationManager) {
8
- try {
9
- const threadId = c.req.param("threadId");
10
- if (!threadId || typeof threadId !== "string") {
11
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "threadId is required and must be a string", 400);
12
- }
13
- // Get deleted conversation history (even if thread doesn't exist anymore)
14
- const deletedHistory = await conversationManager.getDeletedConversationHistory(`/data/${threadId}`);
15
- if (!deletedHistory) {
16
- return successResponse(c, {
17
- threadId,
18
- messages: [],
19
- lastUpdated: new Date().toISOString(),
20
- conversationIds: [],
21
- }, 200);
22
- }
23
- // Get deleted conversation IDs for this thread
24
- const deletedConversationIds = await conversationManager.getDeletedConversationIds(`/data/${threadId}`);
25
- return successResponse(c, {
26
- ...deletedHistory,
27
- conversationIds: deletedConversationIds,
28
- }, 200);
29
- }
30
- catch (error) {
31
- return errorResponse(c, ErrorCodes.DELETED_HISTORY_FETCH_ERROR, "Failed to fetch deleted conversation history", 500, error instanceof Error ? error.message : String(error));
32
- }
33
- }
34
- //# sourceMappingURL=conversations-get-deleted.route.js.map
@@ -1,16 +0,0 @@
1
- /**
2
- * GET /api/conversations/:threadId/:conversationId/messages/:count
3
- * Get the last N messages from a specific conversation
4
- */
5
- import type { Context } from "hono";
6
- import type { ConversationManager } from "../conversations/conversations.manager.js";
7
- import type { ThreadManager } from "../threads/threads.manager.js";
8
- export declare function getConversationMessages(c: Context, conversationManager: ConversationManager, threadManager: ThreadManager): Promise<(Response & import("hono").TypedResponse<{
9
- error: {
10
- code: string;
11
- message: string;
12
- details?: import("hono/utils/types").JSONValue | undefined;
13
- timestamp: string;
14
- };
15
- }, any, "json">) | (Response & import("hono").TypedResponse<import("hono/utils/types").JSONValue, any, "json">)>;
16
- //# sourceMappingURL=conversations-get-messages.route.d.ts.map
@@ -1,49 +0,0 @@
1
- /**
2
- * GET /api/conversations/:threadId/:conversationId/messages/:count
3
- * Get the last N messages from a specific conversation
4
- */
5
- import { errorResponse, successResponse } from "../../core/route-helpers.js";
6
- import { ErrorCodes } from "../../core/error-responses.js";
7
- export async function getConversationMessages(c, conversationManager, threadManager) {
8
- try {
9
- const threadId = c.req.param("threadId");
10
- const conversationId = c.req.param("conversationId");
11
- const countParam = c.req.param("count");
12
- if (!threadId || typeof threadId !== "string") {
13
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "threadId is required and must be a string", 400);
14
- }
15
- if (!conversationId || typeof conversationId !== "string") {
16
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "conversationId is required and must be a string", 400);
17
- }
18
- // Parse and validate count parameter
19
- let count = 10; // default
20
- if (countParam) {
21
- const parsedCount = parseInt(countParam, 10);
22
- if (isNaN(parsedCount) || parsedCount < 1) {
23
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "count must be a positive integer", 400);
24
- }
25
- if (parsedCount > 100) {
26
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "count cannot exceed 100", 400);
27
- }
28
- count = parsedCount;
29
- }
30
- // Verify thread exists
31
- const thread = await threadManager.getThread(threadId);
32
- if (!thread) {
33
- return errorResponse(c, ErrorCodes.THREAD_NOT_FOUND, `Thread not found: ${threadId}`, 404);
34
- }
35
- // Get last N messages
36
- const messages = await conversationManager.getLastMessages(thread.path, conversationId, count);
37
- return successResponse(c, {
38
- threadId,
39
- conversationId,
40
- count,
41
- messages,
42
- totalMessages: messages.length,
43
- }, 200);
44
- }
45
- catch (error) {
46
- return errorResponse(c, ErrorCodes.HISTORY_FETCH_ERROR, "Failed to fetch conversation messages", 500, error instanceof Error ? error.message : String(error));
47
- }
48
- }
49
- //# sourceMappingURL=conversations-get-messages.route.js.map
@@ -1,28 +0,0 @@
1
- /**
2
- * Helpers for extracting and normalizing conversation content from agent events.
3
- * Used when saving completed messages (store only final answer) and when
4
- * mapping stream events to thinking vs content for the UI.
5
- */
6
- import type { AgentEvent, ConversationMessage } from "@tarsk/shared";
7
- /**
8
- * Formats completed conversation messages into a single context string to prepend
9
- * to the next user prompt so the model retains conversation history.
10
- */
11
- export declare function formatConversationContext(messages: ConversationMessage[], maxMessages?: number): string;
12
- /**
13
- * Parses assistant message content into content blocks when it is a JSON array
14
- * (e.g. [{ type: 'reasoning', text: '...' }, { type: 'text', text: '...' }, { type: 'tool_use', ... }]).
15
- * Returns null if content is not a structured array.
16
- */
17
- export declare function parseAssistantContentBlocks(content: string): Array<{
18
- type: string;
19
- [key: string]: unknown;
20
- }> | null;
21
- /** Returns true if content looks like tool result/use JSON */
22
- export declare function isToolLikeContent(content: string): boolean;
23
- /**
24
- * Returns only the final assistant answer text from events (no user message, no tool JSON).
25
- * Use this when persisting response content so the stored file stays clean.
26
- */
27
- export declare function extractAssistantContent(events: AgentEvent[] | undefined, fallback: string): string;
28
- //# sourceMappingURL=conversations.content.d.ts.map
@@ -1,142 +0,0 @@
1
- /**
2
- * Helpers for extracting and normalizing conversation content from agent events.
3
- * Used when saving completed messages (store only final answer) and when
4
- * mapping stream events to thinking vs content for the UI.
5
- */
6
- /** Max number of prior exchanges to include in context (user + assistant pairs) */
7
- const DEFAULT_MAX_CONTEXT_MESSAGES = 10;
8
- /**
9
- * Formats completed conversation messages into a single context string to prepend
10
- * to the next user prompt so the model retains conversation history.
11
- */
12
- export function formatConversationContext(messages, maxMessages = DEFAULT_MAX_CONTEXT_MESSAGES) {
13
- const completed = messages.filter((m) => m.response != null);
14
- const recent = completed.slice(-maxMessages);
15
- if (recent.length === 0)
16
- return "";
17
- const lines = ["Previous conversation:"];
18
- for (const m of recent) {
19
- lines.push(`User: ${m.request.message}`);
20
- lines.push(`Assistant: ${m.response.content}`);
21
- }
22
- return lines.join("\n");
23
- }
24
- const extractTextBlocksFromContent = (content) => {
25
- const trimmed = content.trim();
26
- if (!trimmed.startsWith("[") && !trimmed.startsWith("{")) {
27
- return [];
28
- }
29
- try {
30
- const parsed = JSON.parse(trimmed);
31
- if (Array.isArray(parsed)) {
32
- return parsed
33
- .filter((block) => block && typeof block === "object" && block.type === "text")
34
- .map((block) => (typeof block.text === "string" ? block.text : ""))
35
- .filter((text) => text.length > 0);
36
- }
37
- if (parsed &&
38
- typeof parsed === "object" &&
39
- "text" in parsed &&
40
- typeof parsed.text === "string") {
41
- return [parsed.text];
42
- }
43
- }
44
- catch {
45
- // ignore
46
- }
47
- return [];
48
- };
49
- /**
50
- * Parses assistant message content into content blocks when it is a JSON array
51
- * (e.g. [{ type: 'reasoning', text: '...' }, { type: 'text', text: '...' }, { type: 'tool_use', ... }]).
52
- * Returns null if content is not a structured array.
53
- */
54
- export function parseAssistantContentBlocks(content) {
55
- const trimmed = content.trim();
56
- if (!trimmed.startsWith("["))
57
- return null;
58
- try {
59
- const parsed = JSON.parse(trimmed);
60
- if (!Array.isArray(parsed) || parsed.length === 0)
61
- return null;
62
- const blocks = [];
63
- for (const item of parsed) {
64
- if (item && typeof item === "object" && "type" in item) {
65
- blocks.push(item);
66
- }
67
- }
68
- return blocks.length > 0 ? blocks : null;
69
- }
70
- catch {
71
- return null;
72
- }
73
- }
74
- /** Returns true if content looks like tool result/use JSON */
75
- export function isToolLikeContent(content) {
76
- const trimmed = content.trim();
77
- if (!trimmed.startsWith("[") && !trimmed.startsWith("{"))
78
- return false;
79
- try {
80
- const parsed = JSON.parse(trimmed);
81
- if (Array.isArray(parsed)) {
82
- return parsed.some((item) => item &&
83
- typeof item === "object" &&
84
- "type" in item &&
85
- (item.type === "tool-result" ||
86
- item.type === "tool_use"));
87
- }
88
- return (typeof parsed === "object" &&
89
- parsed !== null &&
90
- "type" in parsed &&
91
- (parsed.type === "tool-result" ||
92
- parsed.type === "tool_use"));
93
- }
94
- catch {
95
- return false;
96
- }
97
- }
98
- /**
99
- * Returns only the final assistant answer text from events (no user message, no tool JSON).
100
- * Use this when persisting response content so the stored file stays clean.
101
- */
102
- export function extractAssistantContent(events, fallback) {
103
- if (!events || events.length === 0) {
104
- return fallback;
105
- }
106
- const resultEvent = [...events].reverse().find((event) => event.type === "result");
107
- if (resultEvent &&
108
- typeof resultEvent.content === "string" &&
109
- resultEvent.content.trim().length > 0) {
110
- return resultEvent.content;
111
- }
112
- const assistantMessages = events.filter((event) => event.type === "message" && event.role === "assistant");
113
- let lastTextBlock = null;
114
- const assistantChunks = [];
115
- for (const event of assistantMessages) {
116
- if (typeof event.content !== "string") {
117
- continue;
118
- }
119
- if (isToolLikeContent(event.content)) {
120
- continue;
121
- }
122
- assistantChunks.push(event.content);
123
- const textBlocks = extractTextBlocksFromContent(event.content);
124
- if (textBlocks.length > 0) {
125
- lastTextBlock = textBlocks[textBlocks.length - 1];
126
- }
127
- }
128
- if (lastTextBlock) {
129
- return lastTextBlock;
130
- }
131
- if (assistantChunks.length === 0) {
132
- // Fall back to the last error event content so the message is saved to history
133
- const lastError = [...events].reverse().find((e) => e.type === "error");
134
- if (lastError && typeof lastError.content === "string" && lastError.content.trim().length > 0) {
135
- return lastError.content;
136
- }
137
- return fallback;
138
- }
139
- const combined = assistantChunks.join("");
140
- return combined.trim().length > 0 ? combined : fallback;
141
- }
142
- //# sourceMappingURL=conversations.content.js.map