@geminixiang/mikan 1.0.0-beta.4 → 1.0.0-beta.41

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 (661) hide show
  1. package/CHANGELOG.md +714 -0
  2. package/README.md +99 -36
  3. package/dist/adapter.d.ts +11 -1
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +18 -1
  6. package/dist/adapter.js.map +1 -1
  7. package/dist/adapters/discord/bot.d.ts +6 -7
  8. package/dist/adapters/discord/bot.d.ts.map +1 -1
  9. package/dist/adapters/discord/bot.js +88 -122
  10. package/dist/adapters/discord/bot.js.map +1 -1
  11. package/dist/adapters/discord/components.d.ts +33 -0
  12. package/dist/adapters/discord/components.d.ts.map +1 -0
  13. package/dist/adapters/discord/components.js +32 -0
  14. package/dist/adapters/discord/components.js.map +1 -0
  15. package/dist/adapters/discord/context.d.ts +3 -1
  16. package/dist/adapters/discord/context.d.ts.map +1 -1
  17. package/dist/adapters/discord/context.js +66 -217
  18. package/dist/adapters/discord/context.js.map +1 -1
  19. package/dist/adapters/discord/format.d.ts +3 -0
  20. package/dist/adapters/discord/format.d.ts.map +1 -0
  21. package/dist/adapters/discord/format.js +86 -0
  22. package/dist/adapters/discord/format.js.map +1 -0
  23. package/dist/adapters/github/bot.d.ts +89 -0
  24. package/dist/adapters/github/bot.d.ts.map +1 -0
  25. package/dist/adapters/github/bot.js +653 -0
  26. package/dist/adapters/github/bot.js.map +1 -0
  27. package/dist/adapters/github/client.d.ts +122 -0
  28. package/dist/adapters/github/client.d.ts.map +1 -0
  29. package/dist/adapters/github/client.js +314 -0
  30. package/dist/adapters/github/client.js.map +1 -0
  31. package/dist/adapters/github/cloudbuild.d.ts +19 -0
  32. package/dist/adapters/github/cloudbuild.d.ts.map +1 -0
  33. package/dist/adapters/github/cloudbuild.js +71 -0
  34. package/dist/adapters/github/cloudbuild.js.map +1 -0
  35. package/dist/adapters/github/context.d.ts +12 -0
  36. package/dist/adapters/github/context.d.ts.map +1 -0
  37. package/dist/adapters/github/context.js +101 -0
  38. package/dist/adapters/github/context.js.map +1 -0
  39. package/dist/adapters/github/gcp-auth.d.ts +28 -0
  40. package/dist/adapters/github/gcp-auth.d.ts.map +1 -0
  41. package/dist/adapters/github/gcp-auth.js +196 -0
  42. package/dist/adapters/github/gcp-auth.js.map +1 -0
  43. package/dist/adapters/github/github-ops.d.ts +91 -0
  44. package/dist/adapters/github/github-ops.d.ts.map +1 -0
  45. package/dist/adapters/github/github-ops.js +406 -0
  46. package/dist/adapters/github/github-ops.js.map +1 -0
  47. package/dist/adapters/github/ids.d.ts +34 -0
  48. package/dist/adapters/github/ids.d.ts.map +1 -0
  49. package/dist/adapters/github/ids.js +57 -0
  50. package/dist/adapters/github/ids.js.map +1 -0
  51. package/dist/adapters/github/repo.d.ts +33 -0
  52. package/dist/adapters/github/repo.d.ts.map +1 -0
  53. package/dist/adapters/github/repo.js +141 -0
  54. package/dist/adapters/github/repo.js.map +1 -0
  55. package/dist/adapters/github/tool-pack.d.ts +14 -0
  56. package/dist/adapters/github/tool-pack.d.ts.map +1 -0
  57. package/dist/adapters/github/tool-pack.js +56 -0
  58. package/dist/adapters/github/tool-pack.js.map +1 -0
  59. package/dist/adapters/github/tools/checks.d.ts +19 -0
  60. package/dist/adapters/github/tools/checks.d.ts.map +1 -0
  61. package/dist/adapters/github/tools/checks.js +105 -0
  62. package/dist/adapters/github/tools/checks.js.map +1 -0
  63. package/dist/adapters/github/tools/issue.d.ts +21 -0
  64. package/dist/adapters/github/tools/issue.d.ts.map +1 -0
  65. package/dist/adapters/github/tools/issue.js +48 -0
  66. package/dist/adapters/github/tools/issue.js.map +1 -0
  67. package/dist/adapters/github/tools/pr.d.ts +22 -0
  68. package/dist/adapters/github/tools/pr.d.ts.map +1 -0
  69. package/dist/adapters/github/tools/pr.js +48 -0
  70. package/dist/adapters/github/tools/pr.js.map +1 -0
  71. package/dist/adapters/github/tools/read.d.ts +21 -0
  72. package/dist/adapters/github/tools/read.d.ts.map +1 -0
  73. package/dist/adapters/github/tools/read.js +141 -0
  74. package/dist/adapters/github/tools/read.js.map +1 -0
  75. package/dist/adapters/github/tools/review-reply.d.ts +17 -0
  76. package/dist/adapters/github/tools/review-reply.d.ts.map +1 -0
  77. package/dist/adapters/github/tools/review-reply.js +38 -0
  78. package/dist/adapters/github/tools/review-reply.js.map +1 -0
  79. package/dist/adapters/github/tools/sync.d.ts +17 -0
  80. package/dist/adapters/github/tools/sync.d.ts.map +1 -0
  81. package/dist/adapters/github/tools/sync.js +34 -0
  82. package/dist/adapters/github/tools/sync.js.map +1 -0
  83. package/dist/adapters/github/types.d.ts +373 -0
  84. package/dist/adapters/github/types.d.ts.map +1 -0
  85. package/dist/adapters/github/types.js +2 -0
  86. package/dist/adapters/github/types.js.map +1 -0
  87. package/dist/adapters/intake.d.ts +16 -5
  88. package/dist/adapters/intake.d.ts.map +1 -1
  89. package/dist/adapters/intake.js +86 -23
  90. package/dist/adapters/intake.js.map +1 -1
  91. package/dist/adapters/markdown-tables.d.ts +37 -0
  92. package/dist/adapters/markdown-tables.d.ts.map +1 -0
  93. package/dist/adapters/markdown-tables.js +164 -0
  94. package/dist/adapters/markdown-tables.js.map +1 -0
  95. package/dist/adapters/progressive-renderer.d.ts +7 -0
  96. package/dist/adapters/progressive-renderer.d.ts.map +1 -0
  97. package/dist/adapters/progressive-renderer.js +440 -0
  98. package/dist/adapters/progressive-renderer.js.map +1 -0
  99. package/dist/adapters/shared.d.ts +23 -10
  100. package/dist/adapters/shared.d.ts.map +1 -1
  101. package/dist/adapters/shared.js +60 -22
  102. package/dist/adapters/shared.js.map +1 -1
  103. package/dist/adapters/slack/assistant.d.ts +101 -0
  104. package/dist/adapters/slack/assistant.d.ts.map +1 -0
  105. package/dist/adapters/slack/assistant.js +204 -0
  106. package/dist/adapters/slack/assistant.js.map +1 -0
  107. package/dist/adapters/slack/blocks.d.ts +14 -0
  108. package/dist/adapters/slack/blocks.d.ts.map +1 -1
  109. package/dist/adapters/slack/blocks.js +105 -147
  110. package/dist/adapters/slack/blocks.js.map +1 -1
  111. package/dist/adapters/slack/bot.d.ts +95 -13
  112. package/dist/adapters/slack/bot.d.ts.map +1 -1
  113. package/dist/adapters/slack/bot.js +545 -211
  114. package/dist/adapters/slack/bot.js.map +1 -1
  115. package/dist/adapters/slack/context.d.ts +3 -1
  116. package/dist/adapters/slack/context.d.ts.map +1 -1
  117. package/dist/adapters/slack/context.js +11 -17
  118. package/dist/adapters/slack/context.js.map +1 -1
  119. package/dist/adapters/slack/response-lifecycle.d.ts.map +1 -1
  120. package/dist/adapters/slack/response-lifecycle.js +197 -323
  121. package/dist/adapters/slack/response-lifecycle.js.map +1 -1
  122. package/dist/adapters/slack/session.d.ts.map +1 -1
  123. package/dist/adapters/slack/session.js +7 -11
  124. package/dist/adapters/slack/session.js.map +1 -1
  125. package/dist/adapters/slack/stream-limits.d.ts +35 -0
  126. package/dist/adapters/slack/stream-limits.d.ts.map +1 -0
  127. package/dist/adapters/slack/stream-limits.js +56 -0
  128. package/dist/adapters/slack/stream-limits.js.map +1 -0
  129. package/dist/adapters/slack/tool-pack.d.ts +11 -0
  130. package/dist/adapters/slack/tool-pack.d.ts.map +1 -0
  131. package/dist/adapters/slack/tool-pack.js +45 -0
  132. package/dist/adapters/slack/tool-pack.js.map +1 -0
  133. package/dist/adapters/slack/tools/attach.js +1 -1
  134. package/dist/adapters/slack/tools/attach.js.map +1 -1
  135. package/dist/adapters/slack/tools/blockkit.d.ts +14 -0
  136. package/dist/adapters/slack/tools/blockkit.d.ts.map +1 -0
  137. package/dist/adapters/slack/tools/blockkit.js +106 -0
  138. package/dist/adapters/slack/tools/blockkit.js.map +1 -0
  139. package/dist/adapters/slack/types.d.ts +40 -2
  140. package/dist/adapters/slack/types.d.ts.map +1 -1
  141. package/dist/adapters/slack/types.js.map +1 -1
  142. package/dist/adapters/telegram/bot.d.ts +8 -9
  143. package/dist/adapters/telegram/bot.d.ts.map +1 -1
  144. package/dist/adapters/telegram/bot.js +115 -163
  145. package/dist/adapters/telegram/bot.js.map +1 -1
  146. package/dist/adapters/telegram/context.d.ts +2 -0
  147. package/dist/adapters/telegram/context.d.ts.map +1 -1
  148. package/dist/adapters/telegram/context.js +53 -188
  149. package/dist/adapters/telegram/context.js.map +1 -1
  150. package/dist/adapters/types.d.ts +132 -12
  151. package/dist/adapters/types.d.ts.map +1 -1
  152. package/dist/adapters/types.js.map +1 -1
  153. package/dist/agent-events.d.ts +3 -2
  154. package/dist/agent-events.d.ts.map +1 -1
  155. package/dist/agent-events.js +19 -1
  156. package/dist/agent-events.js.map +1 -1
  157. package/dist/agent.d.ts +14 -19
  158. package/dist/agent.d.ts.map +1 -1
  159. package/dist/agent.js +841 -298
  160. package/dist/agent.js.map +1 -1
  161. package/dist/cli/arg-grammar.d.ts +25 -0
  162. package/dist/cli/arg-grammar.d.ts.map +1 -0
  163. package/dist/cli/arg-grammar.js +61 -0
  164. package/dist/cli/arg-grammar.js.map +1 -0
  165. package/dist/cli/boot.d.ts +5 -0
  166. package/dist/cli/boot.d.ts.map +1 -0
  167. package/dist/cli/boot.js +117 -0
  168. package/dist/cli/boot.js.map +1 -0
  169. package/dist/cli/download.d.ts.map +1 -0
  170. package/dist/{download.js → cli/download.js} +2 -0
  171. package/dist/cli/download.js.map +1 -0
  172. package/dist/cli/ext-dev.d.ts +2 -0
  173. package/dist/cli/ext-dev.d.ts.map +1 -0
  174. package/dist/cli/ext-dev.js +188 -0
  175. package/dist/cli/ext-dev.js.map +1 -0
  176. package/dist/cli/ext.d.ts +2 -0
  177. package/dist/cli/ext.d.ts.map +1 -0
  178. package/dist/cli/ext.js +324 -0
  179. package/dist/cli/ext.js.map +1 -0
  180. package/dist/cli/office.d.ts +2 -0
  181. package/dist/cli/office.d.ts.map +1 -0
  182. package/dist/cli/office.js +91 -0
  183. package/dist/cli/office.js.map +1 -0
  184. package/dist/cli/types.d.ts +16 -0
  185. package/dist/cli/types.d.ts.map +1 -0
  186. package/dist/cli/types.js +2 -0
  187. package/dist/cli/types.js.map +1 -0
  188. package/dist/commands/admin.d.ts.map +1 -1
  189. package/dist/commands/admin.js +3 -2
  190. package/dist/commands/admin.js.map +1 -1
  191. package/dist/commands/auto-reply.d.ts.map +1 -1
  192. package/dist/commands/auto-reply.js +5 -9
  193. package/dist/commands/auto-reply.js.map +1 -1
  194. package/dist/commands/extensions.d.ts +18 -6
  195. package/dist/commands/extensions.d.ts.map +1 -1
  196. package/dist/commands/extensions.js +64 -14
  197. package/dist/commands/extensions.js.map +1 -1
  198. package/dist/commands/login.d.ts +2 -1
  199. package/dist/commands/login.d.ts.map +1 -1
  200. package/dist/commands/login.js +40 -5
  201. package/dist/commands/login.js.map +1 -1
  202. package/dist/commands/manifest.d.ts +37 -0
  203. package/dist/commands/manifest.d.ts.map +1 -0
  204. package/dist/commands/manifest.js +151 -0
  205. package/dist/commands/manifest.js.map +1 -0
  206. package/dist/commands/model.d.ts +2 -3
  207. package/dist/commands/model.d.ts.map +1 -1
  208. package/dist/commands/model.js +63 -24
  209. package/dist/commands/model.js.map +1 -1
  210. package/dist/commands/new.d.ts.map +1 -1
  211. package/dist/commands/new.js +15 -3
  212. package/dist/commands/new.js.map +1 -1
  213. package/dist/commands/registry.d.ts +2 -2
  214. package/dist/commands/registry.d.ts.map +1 -1
  215. package/dist/commands/registry.js +1 -2
  216. package/dist/commands/registry.js.map +1 -1
  217. package/dist/commands/sandbox.d.ts.map +1 -1
  218. package/dist/commands/sandbox.js +83 -33
  219. package/dist/commands/sandbox.js.map +1 -1
  220. package/dist/commands/session-view.d.ts.map +1 -1
  221. package/dist/commands/session-view.js +6 -3
  222. package/dist/commands/session-view.js.map +1 -1
  223. package/dist/commands/types.d.ts +79 -7
  224. package/dist/commands/types.d.ts.map +1 -1
  225. package/dist/commands/types.js.map +1 -1
  226. package/dist/config.d.ts +23 -8
  227. package/dist/config.d.ts.map +1 -1
  228. package/dist/config.js +222 -135
  229. package/dist/config.js.map +1 -1
  230. package/dist/env-manifest.d.ts +30 -0
  231. package/dist/env-manifest.d.ts.map +1 -0
  232. package/dist/env-manifest.js +233 -0
  233. package/dist/env-manifest.js.map +1 -0
  234. package/dist/events.d.ts.map +1 -1
  235. package/dist/events.js +20 -81
  236. package/dist/events.js.map +1 -1
  237. package/dist/execution-resolver.d.ts +7 -8
  238. package/dist/execution-resolver.d.ts.map +1 -1
  239. package/dist/execution-resolver.js +106 -110
  240. package/dist/execution-resolver.js.map +1 -1
  241. package/dist/extension-schedules.d.ts +31 -0
  242. package/dist/extension-schedules.d.ts.map +1 -0
  243. package/dist/extension-schedules.js +229 -0
  244. package/dist/extension-schedules.js.map +1 -0
  245. package/dist/harness/auth.d.ts +2 -1
  246. package/dist/harness/auth.d.ts.map +1 -1
  247. package/dist/harness/auth.js +11 -5
  248. package/dist/harness/auth.js.map +1 -1
  249. package/dist/harness/event-format.d.ts +27 -0
  250. package/dist/harness/event-format.d.ts.map +1 -0
  251. package/dist/harness/event-format.js +160 -0
  252. package/dist/harness/event-format.js.map +1 -0
  253. package/dist/harness/extensions/loader.d.ts +27 -49
  254. package/dist/harness/extensions/loader.d.ts.map +1 -1
  255. package/dist/harness/extensions/loader.js +486 -130
  256. package/dist/harness/extensions/loader.js.map +1 -1
  257. package/dist/harness/extensions/registry.d.ts +107 -2
  258. package/dist/harness/extensions/registry.d.ts.map +1 -1
  259. package/dist/harness/extensions/registry.js +316 -0
  260. package/dist/harness/extensions/registry.js.map +1 -1
  261. package/dist/harness/extensions/types.d.ts +482 -42
  262. package/dist/harness/extensions/types.d.ts.map +1 -1
  263. package/dist/harness/extensions/types.js.map +1 -1
  264. package/dist/harness/index.d.ts +18 -8
  265. package/dist/harness/index.d.ts.map +1 -1
  266. package/dist/harness/index.js +7 -4
  267. package/dist/harness/index.js.map +1 -1
  268. package/dist/harness/models.d.ts +7 -4
  269. package/dist/harness/models.d.ts.map +1 -1
  270. package/dist/harness/models.js +46 -24
  271. package/dist/harness/models.js.map +1 -1
  272. package/dist/harness/runner.d.ts +50 -54
  273. package/dist/harness/runner.d.ts.map +1 -1
  274. package/dist/harness/runner.js +232 -46
  275. package/dist/harness/runner.js.map +1 -1
  276. package/dist/harness/session-store.d.ts +11 -5
  277. package/dist/harness/session-store.d.ts.map +1 -1
  278. package/dist/harness/session-store.js +141 -36
  279. package/dist/harness/session-store.js.map +1 -1
  280. package/dist/harness/settings.d.ts +2 -20
  281. package/dist/harness/settings.d.ts.map +1 -1
  282. package/dist/harness/settings.js +12 -1
  283. package/dist/harness/settings.js.map +1 -1
  284. package/dist/harness/skills.d.ts +10 -29
  285. package/dist/harness/skills.d.ts.map +1 -1
  286. package/dist/harness/skills.js +48 -6
  287. package/dist/harness/skills.js.map +1 -1
  288. package/dist/harness/subagent-profiles.d.ts +8 -0
  289. package/dist/harness/subagent-profiles.d.ts.map +1 -0
  290. package/dist/harness/subagent-profiles.js +299 -0
  291. package/dist/harness/subagent-profiles.js.map +1 -0
  292. package/dist/harness/subagent-runner.d.ts +45 -0
  293. package/dist/harness/subagent-runner.d.ts.map +1 -0
  294. package/dist/harness/subagent-runner.js +680 -0
  295. package/dist/harness/subagent-runner.js.map +1 -0
  296. package/dist/harness/types.d.ts +267 -1
  297. package/dist/harness/types.d.ts.map +1 -1
  298. package/dist/harness/types.js.map +1 -1
  299. package/dist/harness/usage.d.ts +6 -0
  300. package/dist/harness/usage.d.ts.map +1 -0
  301. package/dist/harness/usage.js +32 -0
  302. package/dist/harness/usage.js.map +1 -0
  303. package/dist/index.d.ts +36 -8
  304. package/dist/index.d.ts.map +1 -1
  305. package/dist/index.js +22 -6
  306. package/dist/index.js.map +1 -1
  307. package/dist/main.js +391 -127
  308. package/dist/main.js.map +1 -1
  309. package/dist/observability/instrument.js +7 -5
  310. package/dist/observability/instrument.js.map +1 -1
  311. package/dist/observability/sentry.d.ts +2 -0
  312. package/dist/observability/sentry.d.ts.map +1 -1
  313. package/dist/observability/sentry.js +10 -2
  314. package/dist/observability/sentry.js.map +1 -1
  315. package/dist/office/address.d.ts +31 -0
  316. package/dist/office/address.d.ts.map +1 -0
  317. package/dist/office/address.js +113 -0
  318. package/dist/office/address.js.map +1 -0
  319. package/dist/office/index.d.ts +11 -0
  320. package/dist/office/index.d.ts.map +1 -0
  321. package/dist/office/index.js +11 -0
  322. package/dist/office/index.js.map +1 -0
  323. package/dist/office/layout.d.ts +27 -0
  324. package/dist/office/layout.d.ts.map +1 -0
  325. package/dist/office/layout.js +97 -0
  326. package/dist/office/layout.js.map +1 -0
  327. package/dist/office/migration.d.ts +44 -0
  328. package/dist/office/migration.d.ts.map +1 -0
  329. package/dist/office/migration.js +255 -0
  330. package/dist/office/migration.js.map +1 -0
  331. package/dist/office/registry.d.ts +75 -0
  332. package/dist/office/registry.d.ts.map +1 -0
  333. package/dist/office/registry.js +646 -0
  334. package/dist/office/registry.js.map +1 -0
  335. package/dist/office/types.d.ts +71 -0
  336. package/dist/office/types.d.ts.map +1 -0
  337. package/dist/office/types.js +2 -0
  338. package/dist/office/types.js.map +1 -0
  339. package/dist/packages/admin.d.ts +17 -0
  340. package/dist/packages/admin.d.ts.map +1 -0
  341. package/dist/packages/admin.js +98 -0
  342. package/dist/packages/admin.js.map +1 -0
  343. package/dist/packages/index.d.ts +6 -0
  344. package/dist/packages/index.d.ts.map +1 -0
  345. package/dist/packages/index.js +6 -0
  346. package/dist/packages/index.js.map +1 -0
  347. package/dist/packages/inspect.d.ts +11 -0
  348. package/dist/packages/inspect.d.ts.map +1 -0
  349. package/dist/packages/inspect.js +98 -0
  350. package/dist/packages/inspect.js.map +1 -0
  351. package/dist/packages/materialize.d.ts +40 -0
  352. package/dist/packages/materialize.d.ts.map +1 -0
  353. package/dist/packages/materialize.js +297 -0
  354. package/dist/packages/materialize.js.map +1 -0
  355. package/dist/packages/resolve.d.ts +25 -0
  356. package/dist/packages/resolve.d.ts.map +1 -0
  357. package/dist/packages/resolve.js +208 -0
  358. package/dist/packages/resolve.js.map +1 -0
  359. package/dist/packages/source.d.ts +39 -0
  360. package/dist/packages/source.d.ts.map +1 -0
  361. package/dist/packages/source.js +189 -0
  362. package/dist/packages/source.js.map +1 -0
  363. package/dist/packages/types.d.ts +104 -0
  364. package/dist/packages/types.d.ts.map +1 -0
  365. package/dist/packages/types.js +2 -0
  366. package/dist/packages/types.js.map +1 -0
  367. package/dist/provisioner.d.ts +66 -0
  368. package/dist/provisioner.d.ts.map +1 -1
  369. package/dist/provisioner.js +335 -13
  370. package/dist/provisioner.js.map +1 -1
  371. package/dist/runtime/conversation-runtime.d.ts +1 -1
  372. package/dist/runtime/conversation-runtime.d.ts.map +1 -1
  373. package/dist/runtime/conversation-runtime.js +562 -118
  374. package/dist/runtime/conversation-runtime.js.map +1 -1
  375. package/dist/runtime/session-lifecycle.d.ts +38 -0
  376. package/dist/runtime/session-lifecycle.d.ts.map +1 -0
  377. package/dist/runtime/session-lifecycle.js +193 -0
  378. package/dist/runtime/session-lifecycle.js.map +1 -0
  379. package/dist/runtime/types.d.ts +66 -7
  380. package/dist/runtime/types.d.ts.map +1 -1
  381. package/dist/runtime/types.js.map +1 -1
  382. package/dist/sandbox/cloudflare.d.ts +3 -0
  383. package/dist/sandbox/cloudflare.d.ts.map +1 -1
  384. package/dist/sandbox/cloudflare.js +13 -1
  385. package/dist/sandbox/cloudflare.js.map +1 -1
  386. package/dist/sandbox/container.d.ts +4 -0
  387. package/dist/sandbox/container.d.ts.map +1 -1
  388. package/dist/sandbox/container.js +13 -3
  389. package/dist/sandbox/container.js.map +1 -1
  390. package/dist/sandbox/firecracker.d.ts +3 -0
  391. package/dist/sandbox/firecracker.d.ts.map +1 -1
  392. package/dist/sandbox/firecracker.js +13 -2
  393. package/dist/sandbox/firecracker.js.map +1 -1
  394. package/dist/sandbox/gondolin.d.ts +57 -0
  395. package/dist/sandbox/gondolin.d.ts.map +1 -0
  396. package/dist/sandbox/gondolin.js +764 -0
  397. package/dist/sandbox/gondolin.js.map +1 -0
  398. package/dist/sandbox/host.d.ts +3 -0
  399. package/dist/sandbox/host.d.ts.map +1 -1
  400. package/dist/sandbox/host.js +18 -3
  401. package/dist/sandbox/host.js.map +1 -1
  402. package/dist/sandbox/identity.d.ts +44 -0
  403. package/dist/sandbox/identity.d.ts.map +1 -0
  404. package/dist/sandbox/identity.js +68 -0
  405. package/dist/sandbox/identity.js.map +1 -0
  406. package/dist/sandbox/image.d.ts.map +1 -1
  407. package/dist/sandbox/image.js +2 -0
  408. package/dist/sandbox/image.js.map +1 -1
  409. package/dist/sandbox/index.d.ts +17 -4
  410. package/dist/sandbox/index.d.ts.map +1 -1
  411. package/dist/sandbox/index.js +37 -3
  412. package/dist/sandbox/index.js.map +1 -1
  413. package/dist/sandbox/types.d.ts +65 -1
  414. package/dist/sandbox/types.d.ts.map +1 -1
  415. package/dist/sandbox/types.js.map +1 -1
  416. package/dist/sandbox/utils.d.ts +14 -0
  417. package/dist/sandbox/utils.d.ts.map +1 -1
  418. package/dist/sandbox/utils.js +68 -1
  419. package/dist/sandbox/utils.js.map +1 -1
  420. package/dist/sessions/chat-history-sync.d.ts +25 -0
  421. package/dist/sessions/chat-history-sync.d.ts.map +1 -0
  422. package/dist/sessions/{agent-memory-file-manager.js → chat-history-sync.js} +135 -131
  423. package/dist/sessions/chat-history-sync.js.map +1 -0
  424. package/dist/sessions/conversation-log.d.ts +9 -0
  425. package/dist/sessions/conversation-log.d.ts.map +1 -0
  426. package/dist/sessions/conversation-log.js +50 -0
  427. package/dist/sessions/conversation-log.js.map +1 -0
  428. package/dist/sessions/history-line.d.ts +29 -0
  429. package/dist/sessions/history-line.d.ts.map +1 -0
  430. package/dist/sessions/history-line.js +45 -0
  431. package/dist/sessions/history-line.js.map +1 -0
  432. package/dist/sessions/rotation.d.ts +2 -0
  433. package/dist/sessions/rotation.d.ts.map +1 -0
  434. package/dist/sessions/rotation.js +39 -0
  435. package/dist/sessions/rotation.js.map +1 -0
  436. package/dist/sessions/session-key.d.ts +33 -0
  437. package/dist/sessions/session-key.d.ts.map +1 -0
  438. package/dist/sessions/session-key.js +115 -0
  439. package/dist/sessions/session-key.js.map +1 -0
  440. package/dist/sessions/store.d.ts +15 -7
  441. package/dist/sessions/store.d.ts.map +1 -1
  442. package/dist/sessions/store.js +127 -36
  443. package/dist/sessions/store.js.map +1 -1
  444. package/dist/sessions/types.d.ts +19 -5
  445. package/dist/sessions/types.d.ts.map +1 -1
  446. package/dist/sessions/types.js.map +1 -1
  447. package/dist/settings-mutation.d.ts +40 -0
  448. package/dist/settings-mutation.d.ts.map +1 -0
  449. package/dist/settings-mutation.js +61 -0
  450. package/dist/settings-mutation.js.map +1 -0
  451. package/dist/subagent-progress.d.ts +39 -0
  452. package/dist/subagent-progress.d.ts.map +1 -0
  453. package/dist/subagent-progress.js +225 -0
  454. package/dist/subagent-progress.js.map +1 -0
  455. package/dist/tools/bash.d.ts +3 -1
  456. package/dist/tools/bash.d.ts.map +1 -1
  457. package/dist/tools/bash.js +26 -18
  458. package/dist/tools/bash.js.map +1 -1
  459. package/dist/tools/edit.d.ts.map +1 -1
  460. package/dist/tools/edit.js +14 -13
  461. package/dist/tools/edit.js.map +1 -1
  462. package/dist/tools/event.d.ts +1 -1
  463. package/dist/tools/event.d.ts.map +1 -1
  464. package/dist/tools/event.js +58 -45
  465. package/dist/tools/event.js.map +1 -1
  466. package/dist/tools/generate-image.d.ts +23 -0
  467. package/dist/tools/generate-image.d.ts.map +1 -0
  468. package/dist/tools/generate-image.js +65 -0
  469. package/dist/tools/generate-image.js.map +1 -0
  470. package/dist/tools/host-fn-tool.d.ts +21 -0
  471. package/dist/tools/host-fn-tool.d.ts.map +1 -0
  472. package/dist/tools/host-fn-tool.js +32 -0
  473. package/dist/tools/host-fn-tool.js.map +1 -0
  474. package/dist/tools/index.d.ts +19 -2
  475. package/dist/tools/index.d.ts.map +1 -1
  476. package/dist/tools/index.js +25 -2
  477. package/dist/tools/index.js.map +1 -1
  478. package/dist/tools/react.d.ts +15 -0
  479. package/dist/tools/react.d.ts.map +1 -0
  480. package/dist/tools/react.js +29 -0
  481. package/dist/tools/react.js.map +1 -0
  482. package/dist/tools/read.d.ts +1 -0
  483. package/dist/tools/read.d.ts.map +1 -1
  484. package/dist/tools/read.js +39 -33
  485. package/dist/tools/read.js.map +1 -1
  486. package/dist/tools/sandbox.d.ts +2 -2
  487. package/dist/tools/sandbox.d.ts.map +1 -1
  488. package/dist/tools/sandbox.js +14 -9
  489. package/dist/tools/sandbox.js.map +1 -1
  490. package/dist/tools/subagent-slots.d.ts +28 -0
  491. package/dist/tools/subagent-slots.d.ts.map +1 -0
  492. package/dist/tools/subagent-slots.js +72 -0
  493. package/dist/tools/subagent-slots.js.map +1 -0
  494. package/dist/tools/subagent.d.ts +61 -0
  495. package/dist/tools/subagent.d.ts.map +1 -0
  496. package/dist/tools/subagent.js +434 -0
  497. package/dist/tools/subagent.js.map +1 -0
  498. package/dist/tools/types.d.ts +40 -32
  499. package/dist/tools/types.d.ts.map +1 -1
  500. package/dist/tools/types.js.map +1 -1
  501. package/dist/tools/write.d.ts.map +1 -1
  502. package/dist/tools/write.js +2 -8
  503. package/dist/tools/write.js.map +1 -1
  504. package/dist/trigger.d.ts +2 -1
  505. package/dist/trigger.d.ts.map +1 -1
  506. package/dist/trigger.js +6 -9
  507. package/dist/trigger.js.map +1 -1
  508. package/dist/types.d.ts +411 -59
  509. package/dist/types.d.ts.map +1 -1
  510. package/dist/types.js +2 -2
  511. package/dist/types.js.map +1 -1
  512. package/dist/utils/file-guards.d.ts +9 -0
  513. package/dist/utils/file-guards.d.ts.map +1 -1
  514. package/dist/utils/file-guards.js +44 -1
  515. package/dist/utils/file-guards.js.map +1 -1
  516. package/dist/vault/disabled.d.ts +9 -0
  517. package/dist/vault/disabled.d.ts.map +1 -0
  518. package/dist/vault/disabled.js +25 -0
  519. package/dist/vault/disabled.js.map +1 -0
  520. package/dist/vault/index.d.ts +45 -2
  521. package/dist/vault/index.d.ts.map +1 -1
  522. package/dist/vault/index.js +127 -36
  523. package/dist/vault/index.js.map +1 -1
  524. package/dist/vault/types.d.ts +6 -2
  525. package/dist/vault/types.d.ts.map +1 -1
  526. package/dist/vault/types.js.map +1 -1
  527. package/dist/web/admin/portal.d.ts +31 -3
  528. package/dist/web/admin/portal.d.ts.map +1 -1
  529. package/dist/web/admin/portal.js +850 -345
  530. package/dist/web/admin/portal.js.map +1 -1
  531. package/dist/web/admin/provider-models.js +1 -1
  532. package/dist/web/admin/provider-models.js.map +1 -1
  533. package/dist/web/admin/types.d.ts +23 -3
  534. package/dist/web/admin/types.d.ts.map +1 -1
  535. package/dist/web/admin/types.js.map +1 -1
  536. package/dist/web/login/oauth.d.ts +2 -3
  537. package/dist/web/login/oauth.d.ts.map +1 -1
  538. package/dist/web/login/oauth.js +1 -32
  539. package/dist/web/login/oauth.js.map +1 -1
  540. package/dist/web/login/portal.d.ts +1 -1
  541. package/dist/web/login/portal.d.ts.map +1 -1
  542. package/dist/web/login/portal.js +13 -36
  543. package/dist/web/login/portal.js.map +1 -1
  544. package/dist/web/login/types.d.ts +0 -11
  545. package/dist/web/login/types.d.ts.map +1 -1
  546. package/dist/web/login/types.js.map +1 -1
  547. package/dist/web/portal-shell.d.ts +21 -0
  548. package/dist/web/portal-shell.d.ts.map +1 -0
  549. package/dist/{portal-shell.js → web/portal-shell.js} +67 -2
  550. package/dist/web/portal-shell.js.map +1 -0
  551. package/dist/web/server.d.ts +3 -2
  552. package/dist/web/server.d.ts.map +1 -1
  553. package/dist/web/server.js +11 -4
  554. package/dist/web/server.js.map +1 -1
  555. package/dist/web/session-view/portal.d.ts +1 -1
  556. package/dist/web/session-view/portal.d.ts.map +1 -1
  557. package/dist/web/session-view/portal.js +37 -28
  558. package/dist/web/session-view/portal.js.map +1 -1
  559. package/dist/web/session-view/service.d.ts +1 -1
  560. package/dist/web/session-view/service.d.ts.map +1 -1
  561. package/dist/web/session-view/service.js +61 -18
  562. package/dist/web/session-view/service.js.map +1 -1
  563. package/dist/web/session-view/types.d.ts +0 -3
  564. package/dist/web/session-view/types.d.ts.map +1 -1
  565. package/dist/web/session-view/types.js.map +1 -1
  566. package/dist/web/token-store.js +1 -1
  567. package/dist/web/token-store.js.map +1 -1
  568. package/dist/workspace-projection/index.d.ts +10 -0
  569. package/dist/workspace-projection/index.d.ts.map +1 -0
  570. package/dist/workspace-projection/index.js +120 -0
  571. package/dist/workspace-projection/index.js.map +1 -0
  572. package/dist/workspace-projection/types.d.ts +16 -0
  573. package/dist/workspace-projection/types.d.ts.map +1 -0
  574. package/dist/workspace-projection/types.js +2 -0
  575. package/dist/workspace-projection/types.js.map +1 -0
  576. package/package.json +68 -37
  577. package/dist/adapters/streaming.d.ts +0 -18
  578. package/dist/adapters/streaming.d.ts.map +0 -1
  579. package/dist/adapters/streaming.js +0 -44
  580. package/dist/adapters/streaming.js.map +0 -1
  581. package/dist/adapters/telegram/html.d.ts +0 -3
  582. package/dist/adapters/telegram/html.d.ts.map +0 -1
  583. package/dist/adapters/telegram/html.js +0 -98
  584. package/dist/adapters/telegram/html.js.map +0 -1
  585. package/dist/commands/parse.d.ts +0 -7
  586. package/dist/commands/parse.d.ts.map +0 -1
  587. package/dist/commands/parse.js +0 -14
  588. package/dist/commands/parse.js.map +0 -1
  589. package/dist/download.d.ts.map +0 -1
  590. package/dist/download.js.map +0 -1
  591. package/dist/model-registry.d.ts +0 -4
  592. package/dist/model-registry.d.ts.map +0 -1
  593. package/dist/model-registry.js +0 -7
  594. package/dist/model-registry.js.map +0 -1
  595. package/dist/portal-shell.d.ts +0 -4
  596. package/dist/portal-shell.d.ts.map +0 -1
  597. package/dist/portal-shell.js.map +0 -1
  598. package/dist/runtime/agent-run-controller.d.ts +0 -31
  599. package/dist/runtime/agent-run-controller.d.ts.map +0 -1
  600. package/dist/runtime/agent-run-controller.js +0 -195
  601. package/dist/runtime/agent-run-controller.js.map +0 -1
  602. package/dist/sandbox/path-context.d.ts +0 -3
  603. package/dist/sandbox/path-context.d.ts.map +0 -1
  604. package/dist/sandbox/path-context.js +0 -20
  605. package/dist/sandbox/path-context.js.map +0 -1
  606. package/dist/sessions/agent-memory-file-manager.d.ts +0 -19
  607. package/dist/sessions/agent-memory-file-manager.d.ts.map +0 -1
  608. package/dist/sessions/agent-memory-file-manager.js.map +0 -1
  609. package/dist/sessions/metadata.d.ts +0 -3
  610. package/dist/sessions/metadata.d.ts.map +0 -1
  611. package/dist/sessions/metadata.js +0 -11
  612. package/dist/sessions/metadata.js.map +0 -1
  613. package/dist/sessions/policy.d.ts +0 -6
  614. package/dist/sessions/policy.d.ts.map +0 -1
  615. package/dist/sessions/policy.js +0 -23
  616. package/dist/sessions/policy.js.map +0 -1
  617. package/dist/store.d.ts +0 -46
  618. package/dist/store.d.ts.map +0 -1
  619. package/dist/store.js +0 -177
  620. package/dist/store.js.map +0 -1
  621. package/dist/tools/truncate.d.ts +0 -33
  622. package/dist/tools/truncate.d.ts.map +0 -1
  623. package/dist/tools/truncate.js +0 -184
  624. package/dist/tools/truncate.js.map +0 -1
  625. package/dist/utils/date.d.ts +0 -10
  626. package/dist/utils/date.d.ts.map +0 -1
  627. package/dist/utils/date.js +0 -23
  628. package/dist/utils/date.js.map +0 -1
  629. package/dist/utils/env.d.ts +0 -3
  630. package/dist/utils/env.d.ts.map +0 -1
  631. package/dist/utils/env.js +0 -12
  632. package/dist/utils/env.js.map +0 -1
  633. package/dist/utils/fs-atomic.d.ts +0 -10
  634. package/dist/utils/fs-atomic.d.ts.map +0 -1
  635. package/dist/utils/fs-atomic.js +0 -45
  636. package/dist/utils/fs-atomic.js.map +0 -1
  637. package/dist/utils/html.d.ts +0 -2
  638. package/dist/utils/html.d.ts.map +0 -1
  639. package/dist/utils/html.js +0 -4
  640. package/dist/utils/html.js.map +0 -1
  641. package/dist/utils/http-body.d.ts +0 -10
  642. package/dist/utils/http-body.d.ts.map +0 -1
  643. package/dist/utils/http-body.js +0 -34
  644. package/dist/utils/http-body.js.map +0 -1
  645. package/dist/vault/routing.d.ts +0 -3
  646. package/dist/vault/routing.d.ts.map +0 -1
  647. package/dist/vault/routing.js +0 -13
  648. package/dist/vault/routing.js.map +0 -1
  649. package/dist/web/agent-events/portal.d.ts +0 -3
  650. package/dist/web/agent-events/portal.d.ts.map +0 -1
  651. package/dist/web/agent-events/portal.js +0 -18
  652. package/dist/web/agent-events/portal.js.map +0 -1
  653. package/dist/web/request.d.ts +0 -3
  654. package/dist/web/request.d.ts.map +0 -1
  655. package/dist/web/request.js +0 -13
  656. package/dist/web/request.js.map +0 -1
  657. package/dist/web/session-view/command.d.ts +0 -4
  658. package/dist/web/session-view/command.d.ts.map +0 -1
  659. package/dist/web/session-view/command.js +0 -7
  660. package/dist/web/session-view/command.js.map +0 -1
  661. /package/dist/{download.d.ts → cli/download.d.ts} +0 -0
@@ -6,10 +6,10 @@
6
6
  * The split/normalize logic itself doesn't differ across platforms — only the
7
7
  * markup wrappers — so it lives here once.
8
8
  */
9
- import { appendFileSync } from "fs";
10
- import { mkdir, writeFile } from "fs/promises";
11
- import { dirname, join } from "path";
12
- import { ensureDirExists } from "../utils/file-guards.js";
9
+ import { appendFileSync } from "node:fs";
10
+ import { mkdir, writeFile } from "node:fs/promises";
11
+ import { dirname, join } from "node:path";
12
+ import { sameOffice } from "../office/index.js";
13
13
  import * as log from "../log.js";
14
14
  import { reportUserFacingError } from "../observability/sentry.js";
15
15
  export function createChatResponseErrorReporter(resolve) {
@@ -120,18 +120,54 @@ export function splitText(text, limit, formatContinuation) {
120
120
  return parts;
121
121
  }
122
122
  /**
123
- * Append a JSON-serializable entry to `${workingDir}/${channel}/log.jsonl`,
124
- * creating the directory on first use. This is the single write path every
123
+ * Append a JSON-serializable entry to the office's `log.jsonl`,
124
+ * materializing the office on first use. This is the single write path every
125
125
  * adapter uses for human-readable message history.
126
126
  */
127
- export function appendChannelLog(workingDir, channel, entry) {
128
- const dir = join(workingDir, channel);
129
- ensureDirExists(dir);
130
- appendFileSync(join(dir, "log.jsonl"), `${JSON.stringify(entry)}\n`);
127
+ export function appendChannelLog(office, entry) {
128
+ office.ensure();
129
+ appendFileSync(office.logPath, `${JSON.stringify(entry)}\n`);
130
+ }
131
+ /**
132
+ * Save incoming platform files under the office's attachments directory.
133
+ *
134
+ * The one owner of the attachment convention: sanitized
135
+ * `<timestamp>_<name>` filenames, the `<office key>/attachments/<file>`
136
+ * workspace-relative localPath the agent reads, and office materialization
137
+ * before the first write. Download mechanics and failure policy stay with
138
+ * the adapter — failures come back in `failed` for the caller to throw or
139
+ * warn about, matching its platform's behavior.
140
+ */
141
+ export async function saveIncomingAttachments(office, items) {
142
+ if (items.length === 0)
143
+ return { saved: [], failed: [] };
144
+ // Attachment downloads can be the office's first write; materialize (and
145
+ // register) it before composing office-relative attachment paths.
146
+ office.ensure();
147
+ await mkdir(office.attachmentsDir, { recursive: true });
148
+ // Results keep the caller's item order regardless of download completion
149
+ // order — platform message logs list attachments as the platform sent them.
150
+ const results = await Promise.all(items.map(async (item) => {
151
+ const sanitized = item.name.replace(/[^a-zA-Z0-9._-]/g, "_");
152
+ const filename = `${item.timestampMs ?? Date.now()}_${sanitized}`;
153
+ try {
154
+ await item.download(join(office.attachmentsDir, filename));
155
+ return {
156
+ saved: { original: item.name, localPath: `${office.key}/attachments/${filename}` },
157
+ };
158
+ }
159
+ catch (error) {
160
+ return { failed: { name: item.name, error } };
161
+ }
162
+ }));
163
+ return {
164
+ saved: results.flatMap((result) => (result.saved ? [result.saved] : [])),
165
+ failed: results.flatMap((result) => (result.failed ? [result.failed] : [])),
166
+ };
131
167
  }
132
168
  /** Convenience for appending the bot's own outbound message. */
133
- export function appendBotResponseLog(workingDir, channel, text, ts, threadTs, extraFields = {}) {
134
- appendChannelLog(workingDir, channel, {
169
+ export function appendBotResponseLog(office, text, ts, threadTs, extraFields = {}) {
170
+ appendChannelLog(office, {
135
171
  date: new Date().toISOString(),
136
172
  ts,
137
173
  ...(threadTs ? { threadTs } : {}),
@@ -150,23 +186,25 @@ export function appendBotResponseLog(workingDir, channel, text, ts, threadTs, ex
150
186
  * 2. The bare conversationId, if running.
151
187
  */
152
188
  export function resolveStopTarget(input) {
153
- const { handler, conversationId, sessionKey } = input;
154
- if (sessionKey && handler.isRunning(sessionKey))
189
+ const { handler, address, sessionKey } = input;
190
+ if (sessionKey && handler.isRunning(address, sessionKey))
155
191
  return sessionKey;
156
- if (handler.isRunning(conversationId))
157
- return conversationId;
192
+ if (handler.isRunning(address, address.conversationId))
193
+ return address.conversationId;
158
194
  return null;
159
195
  }
160
196
  /**
161
- * Return the single running scoped session for this conversation, or null when
162
- * there are zero or multiple matches.
197
+ * Return the single running scoped session for this office, or null when there
198
+ * are zero or multiple matches. Another platform's identically named
199
+ * conversation is a different office and is never a stop target.
163
200
  */
164
- export function resolveOnlyScopedStopTarget(handler, conversationId) {
201
+ export function resolveOnlyScopedStopTarget(handler, address) {
165
202
  const runningScopes = handler
166
203
  .getRunningSessions()
167
- .map((s) => s.sessionKey)
168
- .filter((k) => k.startsWith(`${conversationId}:`));
169
- return runningScopes.length === 1 ? runningScopes[0] : null;
204
+ .filter((session) => sameOffice(session.address, address))
205
+ .map((session) => session.sessionKey)
206
+ .filter((key) => key.startsWith(`${address.conversationId}:`));
207
+ return runningScopes.length === 1 ? (runningScopes[0] ?? null) : null;
170
208
  }
171
209
  /**
172
210
  * Render tool-call args for human display. Drops `label` (already in the
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/adapters/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAenE,MAAM,UAAU,+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AAK,SAAS;gBACzC,CAAC,CAAC,GAAG,KAAK,IAAI,MAAM,IAAI,MAAM,GAAG,KAAK,EAAE;gBACxC,CAAC,CAAC,KAAK,CACV,CAAC;YACF,SAAS;QACX,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,GAAW,EAAE,QAAgB;IACnE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,QAAQ,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;IACrE,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC;IAC5C,MAAM,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,MAAM,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AACjD,CAAC","sourcesContent":["/**\n * Helpers shared across platform adapters.\n *\n * The agent runner is platform-agnostic: it hands strings and structured tool\n * results to each adapter, which decides how to split, format, and route them.\n * The split/normalize logic itself doesn't differ across platforms — only the\n * markup wrappers — so it lives here once.\n */\n\nimport { appendFileSync } from \"fs\";\nimport { mkdir, writeFile } from \"fs/promises\";\nimport { dirname, join } from \"path\";\nimport type { MessagingEventHandler } from \"../adapter.js\";\nimport { ensureDirExists } from \"../utils/file-guards.js\";\nimport * as log from \"../log.js\";\nimport { reportUserFacingError } from \"../observability/sentry.js\";\nexport type {\n ChatResponseErrorContext,\n ChatResponseErrorOperation,\n ChatResponseErrorReporter,\n ResolveStopTargetInput,\n RetryOptions,\n} from \"./types.js\";\nimport type {\n ChatResponseErrorContext,\n ChatResponseErrorReporter,\n RetryOptions,\n ResolveStopTargetInput,\n} from \"./types.js\";\n\nexport function createChatResponseErrorReporter(\n resolve: () => Omit<ChatResponseErrorContext, \"operation\" | \"extra\">,\n): ChatResponseErrorReporter {\n return (err, operation, extra) => {\n reportChatResponseError(err, { ...resolve(), operation, extra });\n };\n}\n\nfunction reportChatResponseError(err: unknown, context: ChatResponseErrorContext): void {\n reportUserFacingError(err, {\n domain: \"chat_platform\",\n surface: \"chat_response\",\n operation: context.operation,\n severity: context.operation === \"set_working\" ? \"warning\" : \"error\",\n platform: context.platform,\n context: {\n conversationId: context.conversationId,\n channelId: context.channelId,\n chatId: context.chatId,\n messageId: context.messageId,\n sessionKey: context.sessionKey,\n responseMessageId: context.responseMessageId,\n threadTs: context.threadTs,\n replyTargetId: context.replyTargetId,\n replyToId: context.replyToId,\n conversationKind: context.conversationKind,\n isThreaded: context.isThreaded,\n ...context.extra,\n },\n });\n}\n\nexport class MessagingEventQueue {\n private queue: Array<() => Promise<void>> = [];\n private processing = false;\n\n constructor(private readonly name: string = \"\") {}\n\n enqueue(work: () => Promise<void>): void {\n this.queue.push(work);\n this.processNext();\n }\n\n size(): number {\n return this.queue.length;\n }\n\n private async processNext(): Promise<void> {\n if (this.processing || this.queue.length === 0) return;\n this.processing = true;\n const work = this.queue.shift()!;\n try {\n await work();\n } catch (err) {\n log.logWarning(\n `${this.name ? this.name + \" \" : \"\"}queue error`,\n err instanceof Error ? err.message : String(err),\n );\n }\n this.processing = false;\n this.processNext();\n }\n}\n\n// RetryOptions is defined in ./types.ts and re-exported from the top of this file.\n\n/**\n * Run `fn` and retry with exponential backoff when its error matches\n * `isRateLimited`. Other errors propagate immediately. Each platform supplies\n * its own predicate so we don't have to know every SDK's error shape here.\n */\nexport async function withRetry<T>(fn: () => Promise<T>, opts: RetryOptions): Promise<T> {\n const maxAttempts = opts.maxAttempts ?? 3;\n const baseDelayMs = opts.baseDelayMs ?? 1000;\n let lastError: Error | undefined;\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n try {\n return await fn();\n } catch (err) {\n lastError = err instanceof Error ? err : new Error(String(err));\n\n const isLastAttempt = attempt === maxAttempts - 1;\n if (isLastAttempt || !opts.isRateLimited(lastError)) {\n throw lastError;\n }\n\n const delay = baseDelayMs * Math.pow(2, attempt);\n log.logWarning(\n `Retrying after error in ${delay}ms (attempt ${attempt + 1}/${maxAttempts}): ${lastError.message}`,\n );\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n throw lastError;\n}\n\n/**\n * Split `text` into chunks no larger than `limit`, appending a continuation\n * marker (e.g. `_(continued 1)_`) at the end of every part except the last.\n *\n * Each adapter passes its own `formatContinuation` so the marker uses the\n * platform's italic / emphasis convention.\n */\nexport function splitText(\n text: string,\n limit: number,\n formatContinuation: (partNum: number) => string,\n): string[] {\n if (text.length <= limit) return [text];\n const parts: string[] = [];\n let remaining = text;\n let partNum = 1;\n while (remaining.length > 0) {\n const suffixReserve = formatContinuation(partNum).length + 8;\n const chunkLimit = Math.max(1, limit - suffixReserve);\n const chunk = remaining.slice(0, chunkLimit);\n remaining = remaining.slice(chunkLimit);\n const suffix = remaining.length > 0 ? `\\n${formatContinuation(partNum)}` : \"\";\n parts.push(chunk + suffix);\n partNum++;\n }\n return parts;\n}\n\n/**\n * Append a JSON-serializable entry to `${workingDir}/${channel}/log.jsonl`,\n * creating the directory on first use. This is the single write path every\n * adapter uses for human-readable message history.\n */\nexport function appendChannelLog(workingDir: string, channel: string, entry: object): void {\n const dir = join(workingDir, channel);\n ensureDirExists(dir);\n appendFileSync(join(dir, \"log.jsonl\"), `${JSON.stringify(entry)}\\n`);\n}\n\n/** Convenience for appending the bot's own outbound message. */\nexport function appendBotResponseLog(\n workingDir: string,\n channel: string,\n text: string,\n ts: string,\n threadTs?: string,\n extraFields: Record<string, unknown> = {},\n): void {\n appendChannelLog(workingDir, channel, {\n date: new Date().toISOString(),\n ts,\n ...(threadTs ? { threadTs } : {}),\n user: \"bot\",\n text,\n attachments: [],\n isMessagingBot: true,\n ...extraFields,\n });\n}\n\n// ResolveStopTargetInput is defined in ./types.ts and re-exported from the top of this file.\n\n/**\n * Pick which session key a `/stop` should target without applying any\n * platform-specific fallback policy. Order:\n * 1. The provided sessionKey, if running.\n * 2. The bare conversationId, if running.\n */\nexport function resolveStopTarget(input: ResolveStopTargetInput): string | null {\n const { handler, conversationId, sessionKey } = input;\n\n if (sessionKey && handler.isRunning(sessionKey)) return sessionKey;\n if (handler.isRunning(conversationId)) return conversationId;\n return null;\n}\n\n/**\n * Return the single running scoped session for this conversation, or null when\n * there are zero or multiple matches.\n */\nexport function resolveOnlyScopedStopTarget(\n handler: MessagingEventHandler,\n conversationId: string,\n): string | null {\n const runningScopes = handler\n .getRunningSessions()\n .map((s) => s.sessionKey)\n .filter((k) => k.startsWith(`${conversationId}:`));\n\n return runningScopes.length === 1 ? runningScopes[0] : null;\n}\n\n/**\n * Render tool-call args for human display. Drops `label` (already in the\n * heading) and folds `path` + `offset`/`limit` into a single `path:start-end`\n * line. Pure data normalization with no platform-specific markup.\n */\nexport function formatToolArgs(args: Record<string, unknown> | undefined): string {\n if (!args) return \"\";\n const lines: string[] = [];\n\n for (const [key, value] of Object.entries(args)) {\n if (key === \"label\" || key === \"offset\" || key === \"limit\") continue;\n\n if (key === \"path\" && typeof value === \"string\") {\n const offset = args.offset as number | undefined;\n const limit = args.limit as number | undefined;\n lines.push(\n offset !== undefined && limit !== undefined\n ? `${value}:${offset}-${offset + limit}`\n : value,\n );\n continue;\n }\n\n lines.push(typeof value === \"string\" ? value : JSON.stringify(value));\n }\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Fetch `url` and write the response body to `destPath`, creating parent\n * directories as needed. Throws on non-2xx responses or write failures.\n */\nexport async function downloadUrlToFile(url: string, destPath: string): Promise<void> {\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n const buffer = await response.arrayBuffer();\n await mkdir(dirname(destPath), { recursive: true });\n await writeFile(destPath, Buffer.from(buffer));\n}\n"]}
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/adapters/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAe,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAmBnE,MAAM,UAAU,+BAA+B,CAC7C,OAAoE;IAEpE,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE;QAC/B,uBAAuB,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IACnE,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB,CAAC,GAAY,EAAE,OAAiC;IAC9E,qBAAqB,CAAC,GAAG,EAAE;QACzB,MAAM,EAAE,eAAe;QACvB,OAAO,EAAE,eAAe;QACxB,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,QAAQ,EAAE,OAAO,CAAC,SAAS,KAAK,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO;QACnE,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,OAAO,EAAE;YACP,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,SAAS,EAAE,OAAO,CAAC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CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,GAAW,EAAE,QAAgB;IACnE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,QAAQ,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;IACrE,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC;IAC5C,MAAM,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,MAAM,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AACjD,CAAC","sourcesContent":["/**\n * Helpers shared across platform adapters.\n *\n * The agent runner is platform-agnostic: it hands strings and structured tool\n * results to each adapter, which decides how to split, format, and route them.\n * The split/normalize logic itself doesn't differ across platforms — only the\n * markup wrappers — so it lives here once.\n */\n\nimport { appendFileSync } from \"node:fs\";\nimport { mkdir, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport type { MessagingEventHandler, OfficeAddress } from \"../adapter.js\";\nimport { sameOffice, type Office } from \"../office/index.js\";\nimport * as log from \"../log.js\";\nimport { reportUserFacingError } from \"../observability/sentry.js\";\nexport type {\n ChatResponseErrorContext,\n ChatResponseErrorOperation,\n ChatResponseErrorReporter,\n IncomingAttachment,\n ResolveStopTargetInput,\n RetryOptions,\n SavedAttachments,\n} from \"./types.js\";\nimport type {\n ChatResponseErrorContext,\n ChatResponseErrorReporter,\n IncomingAttachment,\n RetryOptions,\n ResolveStopTargetInput,\n SavedAttachments,\n} from \"./types.js\";\n\nexport function createChatResponseErrorReporter(\n resolve: () => Omit<ChatResponseErrorContext, \"operation\" | \"extra\">,\n): ChatResponseErrorReporter {\n return (err, operation, extra) => {\n reportChatResponseError(err, { ...resolve(), operation, extra });\n };\n}\n\nfunction reportChatResponseError(err: unknown, context: ChatResponseErrorContext): void {\n reportUserFacingError(err, {\n domain: \"chat_platform\",\n surface: \"chat_response\",\n operation: context.operation,\n severity: context.operation === \"set_working\" ? \"warning\" : \"error\",\n platform: context.platform,\n context: {\n conversationId: context.conversationId,\n channelId: context.channelId,\n chatId: context.chatId,\n messageId: context.messageId,\n sessionKey: context.sessionKey,\n responseMessageId: context.responseMessageId,\n threadTs: context.threadTs,\n replyTargetId: context.replyTargetId,\n replyToId: context.replyToId,\n conversationKind: context.conversationKind,\n isThreaded: context.isThreaded,\n ...context.extra,\n },\n });\n}\n\nexport class MessagingEventQueue {\n private queue: Array<() => Promise<void>> = [];\n private processing = false;\n\n constructor(private readonly name: string = \"\") {}\n\n enqueue(work: () => Promise<void>): void {\n this.queue.push(work);\n this.processNext();\n }\n\n size(): number {\n return this.queue.length;\n }\n\n private async processNext(): Promise<void> {\n if (this.processing || this.queue.length === 0) return;\n this.processing = true;\n const work = this.queue.shift()!;\n try {\n await work();\n } catch (err) {\n log.logWarning(\n `${this.name ? this.name + \" \" : \"\"}queue error`,\n err instanceof Error ? err.message : String(err),\n );\n }\n this.processing = false;\n this.processNext();\n }\n}\n\n// RetryOptions is defined in ./types.ts and re-exported from the top of this file.\n\n/**\n * Run `fn` and retry with exponential backoff when its error matches\n * `isRateLimited`. Other errors propagate immediately. Each platform supplies\n * its own predicate so we don't have to know every SDK's error shape here.\n */\nexport async function withRetry<T>(fn: () => Promise<T>, opts: RetryOptions): Promise<T> {\n const maxAttempts = opts.maxAttempts ?? 3;\n const baseDelayMs = opts.baseDelayMs ?? 1000;\n let lastError: Error | undefined;\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n try {\n return await fn();\n } catch (err) {\n lastError = err instanceof Error ? err : new Error(String(err));\n\n const isLastAttempt = attempt === maxAttempts - 1;\n if (isLastAttempt || !opts.isRateLimited(lastError)) {\n throw lastError;\n }\n\n const delay = baseDelayMs * Math.pow(2, attempt);\n log.logWarning(\n `Retrying after error in ${delay}ms (attempt ${attempt + 1}/${maxAttempts}): ${lastError.message}`,\n );\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n throw lastError;\n}\n\n/**\n * Split `text` into chunks no larger than `limit`, appending a continuation\n * marker (e.g. `_(continued 1)_`) at the end of every part except the last.\n *\n * Each adapter passes its own `formatContinuation` so the marker uses the\n * platform's italic / emphasis convention.\n */\nexport function splitText(\n text: string,\n limit: number,\n formatContinuation: (partNum: number) => string,\n): string[] {\n if (text.length <= limit) return [text];\n const parts: string[] = [];\n let remaining = text;\n let partNum = 1;\n while (remaining.length > 0) {\n const suffixReserve = formatContinuation(partNum).length + 8;\n const chunkLimit = Math.max(1, limit - suffixReserve);\n const chunk = remaining.slice(0, chunkLimit);\n remaining = remaining.slice(chunkLimit);\n const suffix = remaining.length > 0 ? `\\n${formatContinuation(partNum)}` : \"\";\n parts.push(chunk + suffix);\n partNum++;\n }\n return parts;\n}\n\n/**\n * Append a JSON-serializable entry to the office's `log.jsonl`,\n * materializing the office on first use. This is the single write path every\n * adapter uses for human-readable message history.\n */\nexport function appendChannelLog(office: Office, entry: object): void {\n office.ensure();\n appendFileSync(office.logPath, `${JSON.stringify(entry)}\\n`);\n}\n\n/**\n * Save incoming platform files under the office's attachments directory.\n *\n * The one owner of the attachment convention: sanitized\n * `<timestamp>_<name>` filenames, the `<office key>/attachments/<file>`\n * workspace-relative localPath the agent reads, and office materialization\n * before the first write. Download mechanics and failure policy stay with\n * the adapter — failures come back in `failed` for the caller to throw or\n * warn about, matching its platform's behavior.\n */\nexport async function saveIncomingAttachments(\n office: Office,\n items: readonly IncomingAttachment[],\n): Promise<SavedAttachments> {\n if (items.length === 0) return { saved: [], failed: [] };\n // Attachment downloads can be the office's first write; materialize (and\n // register) it before composing office-relative attachment paths.\n office.ensure();\n await mkdir(office.attachmentsDir, { recursive: true });\n\n // Results keep the caller's item order regardless of download completion\n // order — platform message logs list attachments as the platform sent them.\n const results = await Promise.all(\n items.map(async (item) => {\n const sanitized = item.name.replace(/[^a-zA-Z0-9._-]/g, \"_\");\n const filename = `${item.timestampMs ?? Date.now()}_${sanitized}`;\n try {\n await item.download(join(office.attachmentsDir, filename));\n return {\n saved: { original: item.name, localPath: `${office.key}/attachments/${filename}` },\n };\n } catch (error) {\n return { failed: { name: item.name, error } };\n }\n }),\n );\n return {\n saved: results.flatMap((result) => (result.saved ? [result.saved] : [])),\n failed: results.flatMap((result) => (result.failed ? [result.failed] : [])),\n };\n}\n\n/** Convenience for appending the bot's own outbound message. */\nexport function appendBotResponseLog(\n office: Office,\n text: string,\n ts: string,\n threadTs?: string,\n extraFields: Record<string, unknown> = {},\n): void {\n appendChannelLog(office, {\n date: new Date().toISOString(),\n ts,\n ...(threadTs ? { threadTs } : {}),\n user: \"bot\",\n text,\n attachments: [],\n isMessagingBot: true,\n ...extraFields,\n });\n}\n\n// ResolveStopTargetInput is defined in ./types.ts and re-exported from the top of this file.\n\n/**\n * Pick which session key a `/stop` should target without applying any\n * platform-specific fallback policy. Order:\n * 1. The provided sessionKey, if running.\n * 2. The bare conversationId, if running.\n */\nexport function resolveStopTarget(input: ResolveStopTargetInput): string | null {\n const { handler, address, sessionKey } = input;\n\n if (sessionKey && handler.isRunning(address, sessionKey)) return sessionKey;\n if (handler.isRunning(address, address.conversationId)) return address.conversationId;\n return null;\n}\n\n/**\n * Return the single running scoped session for this office, or null when there\n * are zero or multiple matches. Another platform's identically named\n * conversation is a different office and is never a stop target.\n */\nexport function resolveOnlyScopedStopTarget(\n handler: MessagingEventHandler,\n address: OfficeAddress,\n): string | null {\n const runningScopes = handler\n .getRunningSessions()\n .filter((session) => sameOffice(session.address, address))\n .map((session) => session.sessionKey)\n .filter((key) => key.startsWith(`${address.conversationId}:`));\n\n return runningScopes.length === 1 ? (runningScopes[0] ?? null) : null;\n}\n\n/**\n * Render tool-call args for human display. Drops `label` (already in the\n * heading) and folds `path` + `offset`/`limit` into a single `path:start-end`\n * line. Pure data normalization with no platform-specific markup.\n */\nexport function formatToolArgs(args: Record<string, unknown> | undefined): string {\n if (!args) return \"\";\n const lines: string[] = [];\n\n for (const [key, value] of Object.entries(args)) {\n if (key === \"label\" || key === \"offset\" || key === \"limit\") continue;\n\n if (key === \"path\" && typeof value === \"string\") {\n const offset = args.offset as number | undefined;\n const limit = args.limit as number | undefined;\n lines.push(\n offset !== undefined && limit !== undefined\n ? `${value}:${offset}-${offset + limit}`\n : value,\n );\n continue;\n }\n\n lines.push(typeof value === \"string\" ? value : JSON.stringify(value));\n }\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Fetch `url` and write the response body to `destPath`, creating parent\n * directories as needed. Throws on non-2xx responses or write failures.\n */\nexport async function downloadUrlToFile(url: string, destPath: string): Promise<void> {\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n const buffer = await response.arrayBuffer();\n await mkdir(dirname(destPath), { recursive: true });\n await writeFile(destPath, Buffer.from(buffer));\n}\n"]}
@@ -0,0 +1,101 @@
1
+ /** The `assistant_thread` payload on the `assistant_view` lifecycle events. */
2
+ export interface AssistantThreadPayload {
3
+ user_id?: string;
4
+ channel_id?: string;
5
+ thread_ts?: string;
6
+ context?: AgentContext;
7
+ }
8
+ /**
9
+ * Which channel the person is viewing beside the pane. Slack spells this
10
+ * `context` on `app_home_opened` and `app_context_changed`, and `app_context`
11
+ * on `message.im` — the asymmetry is Slack's, normalized here.
12
+ */
13
+ export interface AgentContext {
14
+ channel_id?: string;
15
+ team_id?: string;
16
+ enterprise_id?: string | null;
17
+ }
18
+ export interface SuggestedPrompt {
19
+ title: string;
20
+ message: string;
21
+ }
22
+ /** What the adapter needs from the bot to serve this surface. */
23
+ export interface AssistantSurfaceOps {
24
+ postInThread(channel: string, threadTs: string, text: string): Promise<string>;
25
+ /** `threadTs` omitted pins the prompts to the DM instead of one thread. */
26
+ setSuggestedPrompts(channel: string, threadTs: string | undefined, prompts: SuggestedPrompt[]): Promise<void>;
27
+ setTitle(channel: string, threadTs: string, title: string): Promise<void>;
28
+ /** Human-readable channel name for context, when the bot knows it. */
29
+ channelName(channelId: string): string | undefined;
30
+ }
31
+ /**
32
+ * Which conversations belong to this surface, and the context Slack last
33
+ * reported for each.
34
+ *
35
+ * Two levels, because the two manifest keys register at different grains: an
36
+ * `agent_view` DM is known before any thread exists, while an
37
+ * `assistant_view` thread is known individually.
38
+ *
39
+ * In memory on purpose: transient UI state that Slack re-sends on open and on
40
+ * every change, so a restart self-heals on the next interaction. Persisting it
41
+ * would add a store to keep consistent for nothing that survives the trip.
42
+ */
43
+ export declare class AssistantThreadRegistry {
44
+ private threads;
45
+ private channels;
46
+ private titled;
47
+ private key;
48
+ /** An `assistant_view` thread. */
49
+ remember(channelId: string, threadTs: string, context?: AgentContext): void;
50
+ /** An `agent_view` DM, which has no thread yet. */
51
+ rememberChannel(channelId: string, context?: AgentContext): void;
52
+ /** Thread context, falling back to the channel's. */
53
+ contextFor(channelId: string, threadTs: string): AgentContext | undefined;
54
+ channelContext(channelId: string): AgentContext | undefined;
55
+ /**
56
+ * Whether this thread is part of the pane — either registered individually,
57
+ * or living in a DM known to be the agent surface. The second case is what
58
+ * makes titles work under `agent_view`, where Slack opens threads itself and
59
+ * never announces them.
60
+ */
61
+ isAgentSurface(channelId: string, threadTs: string): boolean;
62
+ /** True the first time a thread is seen, so a title is set exactly once. */
63
+ claimTitle(channelId: string, threadTs: string): boolean;
64
+ }
65
+ /**
66
+ * `assistant_view`: a new conversation opened. Greet, and offer prompts for
67
+ * that thread.
68
+ *
69
+ * Failures are logged, never thrown. A greeting that did not post is a worse
70
+ * pane, not a broken conversation, and taking the socket handler down over it
71
+ * would break the surface entirely.
72
+ */
73
+ export declare function handleAssistantThreadStarted(ops: AssistantSurfaceOps, registry: AssistantThreadRegistry, thread: AssistantThreadPayload): Promise<void>;
74
+ /**
75
+ * `agent_view`: the person opened the app's DM. Refresh the prompts pinned to
76
+ * it — and deliberately do not greet, because Slack sends this on *every*
77
+ * open, so a greeting here would arrive again and again.
78
+ */
79
+ export declare function handleAgentDmOpened(ops: AssistantSurfaceOps, registry: AssistantThreadRegistry, channelId: string, context?: AgentContext): Promise<void>;
80
+ /**
81
+ * The person navigated elsewhere. Recorded at both grains so the next turn —
82
+ * and the next prompt refresh — knows where they are, whichever manifest key
83
+ * this app uses.
84
+ */
85
+ export declare function handleAgentContextChanged(registry: AssistantThreadRegistry, payload: {
86
+ channel_id?: string;
87
+ thread_ts?: string;
88
+ context?: AgentContext;
89
+ }): void;
90
+ /**
91
+ * Title a conversation from the first thing the person said, so the pane's
92
+ * sidebar is navigable. Without it every past conversation looks the same.
93
+ */
94
+ export declare function titleAssistantThread(ops: AssistantSurfaceOps, registry: AssistantThreadRegistry, channelId: string, threadTs: string, firstMessage: string): Promise<void>;
95
+ /**
96
+ * First line, trimmed to something a sidebar can show. Deliberately not a
97
+ * model call: a title is worth having immediately and cheaply, and the
98
+ * person's own words label the conversation better than a paraphrase.
99
+ */
100
+ export declare function summarizeTitle(message: string): string;
101
+ //# sourceMappingURL=assistant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assistant.d.ts","sourceRoot":"","sources":["../../../src/adapters/slack/assistant.ts"],"names":[],"mappings":"AAoCA,+EAA+E;AAC/E,MAAM,WAAW,sBAAsB;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;I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E,MAAM,GAAG,YAAY,GAAG,SAAS,CAE1D;IAED;;;;;OAKG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAE3D;IAED,4EAA4E;IAC5E,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAKvD;CACF;AAED;;;;;;;GAOG;AACH,wBAAsB,4BAA4B,CAChD,GAAG,EAAE,mBAAmB,EACxB,QAAQ,EAAE,uBAAuB,EACjC,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAgBf;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,mBAAmB,EACxB,QAAQ,EAAE,uBAAuB,EACjC,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,IAAI,CAAC,CAcf;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,uBAAuB,EACjC,OAAO,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,YAAY,CAAA;CAAE,GAC3E,IAAI,CAaN;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,mBAAmB,EACxB,QAAQ,EAAE,uBAAuB,EACjC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC,CAMf;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAQtD"}
@@ -0,0 +1,204 @@
1
+ /**
2
+ * Slack's agent / assistant surface — the app's own pane, separate from
3
+ * channels and ordinary DMs.
4
+ *
5
+ * There are two of these, not one, and they differ in which events signal
6
+ * "someone opened a conversation":
7
+ *
8
+ * | Manifest key | Opened signal | Prompts |
9
+ * | ----------------- | ------------------------------------ | ------------- |
10
+ * | `agent_view` | `app_home_opened` with tab=`messages` | pinned to the DM |
11
+ * | `assistant_view` | `assistant_thread_started` | per thread |
12
+ *
13
+ * Slack's own words for the newer one: "rely on the `app_home_opened` event to
14
+ * know when a user has actively opened a DM with your app", and
15
+ * "the `assistant_thread_started` event no longer indicates this". What the
16
+ * docs do *not* say is whether `assistant_thread_started` still fires for an
17
+ * `agent_view` app — so both paths are handled rather than guessed at, which
18
+ * also means an app on either manifest key works without a migration.
19
+ *
20
+ * The two signals need different behaviour, and conflating them would be a
21
+ * bug: `assistant_thread_started` fires once per new conversation, so greeting
22
+ * is right; `app_home_opened` fires **every time the pane is opened**, so
23
+ * greeting there would nag. The agent path therefore only refreshes the
24
+ * pinned prompts, which is idempotent.
25
+ *
26
+ * Session semantics are deliberately unchanged. Each conversation is a thread
27
+ * and mikan already scopes a thread to its own session — the right shape,
28
+ * because the pane's sidebar is a list of separate conversations rather than
29
+ * one transcript. Continuity across them comes from the office's memory.
30
+ *
31
+ * Suggested prompts are deterministic, varying only with the channel Slack
32
+ * says the person is viewing. Enough to feel aware without spending a model
33
+ * call before they have typed anything.
34
+ */
35
+ import * as log from "../../log.js";
36
+ const GREETING = "有什麼我可以幫忙的?";
37
+ const GREETING_WITH_CHANNEL = (channel) => `有什麼我可以幫忙的?我看得到你正在 #${channel}。`;
38
+ /** Prompts offered with no channel context — general-purpose starting points. */
39
+ const DEFAULT_PROMPTS = [
40
+ { title: "看看工作區", message: "這個工作區裡有什麼?先給我一個概覽。" },
41
+ { title: "最近的變更", message: "最近的程式碼變更有哪些?挑重要的說。" },
42
+ { title: "排一個提醒", message: "幫我排一個每天早上的提醒。" },
43
+ ];
44
+ /**
45
+ * Prompts when Slack tells us which channel the person is looking at. Naming
46
+ * the channel is the cheap half of "context-aware": it costs nothing and it is
47
+ * what makes the suggestions feel addressed to the moment.
48
+ */
49
+ function promptsFor(channel) {
50
+ if (!channel)
51
+ return DEFAULT_PROMPTS;
52
+ return [
53
+ { title: `#${channel} 在討論什麼`, message: `幫我摘要 #${channel} 最近的討論。` },
54
+ { title: "有什麼要我接手", message: `#${channel} 裡有沒有需要我處理或追蹤的事?` },
55
+ { title: "看看工作區", message: "這個工作區裡有什麼?先給我一個概覽。" },
56
+ ];
57
+ }
58
+ /**
59
+ * Which conversations belong to this surface, and the context Slack last
60
+ * reported for each.
61
+ *
62
+ * Two levels, because the two manifest keys register at different grains: an
63
+ * `agent_view` DM is known before any thread exists, while an
64
+ * `assistant_view` thread is known individually.
65
+ *
66
+ * In memory on purpose: transient UI state that Slack re-sends on open and on
67
+ * every change, so a restart self-heals on the next interaction. Persisting it
68
+ * would add a store to keep consistent for nothing that survives the trip.
69
+ */
70
+ export class AssistantThreadRegistry {
71
+ constructor() {
72
+ this.threads = new Map();
73
+ this.channels = new Map();
74
+ this.titled = new Set();
75
+ }
76
+ key(channelId, threadTs) {
77
+ return `${channelId}\n${threadTs}`;
78
+ }
79
+ /** An `assistant_view` thread. */
80
+ remember(channelId, threadTs, context) {
81
+ this.threads.set(this.key(channelId, threadTs), context ?? {});
82
+ }
83
+ /** An `agent_view` DM, which has no thread yet. */
84
+ rememberChannel(channelId, context) {
85
+ this.channels.set(channelId, context ?? {});
86
+ }
87
+ /** Thread context, falling back to the channel's. */
88
+ contextFor(channelId, threadTs) {
89
+ return this.threads.get(this.key(channelId, threadTs)) ?? this.channels.get(channelId);
90
+ }
91
+ channelContext(channelId) {
92
+ return this.channels.get(channelId);
93
+ }
94
+ /**
95
+ * Whether this thread is part of the pane — either registered individually,
96
+ * or living in a DM known to be the agent surface. The second case is what
97
+ * makes titles work under `agent_view`, where Slack opens threads itself and
98
+ * never announces them.
99
+ */
100
+ isAgentSurface(channelId, threadTs) {
101
+ return this.threads.has(this.key(channelId, threadTs)) || this.channels.has(channelId);
102
+ }
103
+ /** True the first time a thread is seen, so a title is set exactly once. */
104
+ claimTitle(channelId, threadTs) {
105
+ const key = this.key(channelId, threadTs);
106
+ if (this.titled.has(key))
107
+ return false;
108
+ this.titled.add(key);
109
+ return true;
110
+ }
111
+ }
112
+ /**
113
+ * `assistant_view`: a new conversation opened. Greet, and offer prompts for
114
+ * that thread.
115
+ *
116
+ * Failures are logged, never thrown. A greeting that did not post is a worse
117
+ * pane, not a broken conversation, and taking the socket handler down over it
118
+ * would break the surface entirely.
119
+ */
120
+ export async function handleAssistantThreadStarted(ops, registry, thread) {
121
+ const channelId = thread.channel_id;
122
+ const threadTs = thread.thread_ts;
123
+ if (!channelId || !threadTs)
124
+ return;
125
+ registry.remember(channelId, threadTs, thread.context);
126
+ const channel = thread.context?.channel_id
127
+ ? ops.channelName(thread.context.channel_id)
128
+ : undefined;
129
+ await swallow("greeting", () => ops.postInThread(channelId, threadTs, channel ? GREETING_WITH_CHANNEL(channel) : GREETING));
130
+ await swallow("setSuggestedPrompts", () => ops.setSuggestedPrompts(channelId, threadTs, promptsFor(channel)));
131
+ }
132
+ /**
133
+ * `agent_view`: the person opened the app's DM. Refresh the prompts pinned to
134
+ * it — and deliberately do not greet, because Slack sends this on *every*
135
+ * open, so a greeting here would arrive again and again.
136
+ */
137
+ export async function handleAgentDmOpened(ops, registry, channelId, context) {
138
+ if (!channelId)
139
+ return;
140
+ registry.rememberChannel(channelId, context);
141
+ const channel = context?.channel_id ? ops.channelName(context.channel_id) : undefined;
142
+ // The agent surface is otherwise silent, and its failure mode — no prompts,
143
+ // untitled conversations — looks identical from the outside to Slack simply
144
+ // not sending the event. This line is the difference between the two, and
145
+ // is the first thing to look for when the pane seems inert.
146
+ log.logInfo(`[${channelId}] Slack agent DM opened${channel ? ` (viewing #${channel})` : ""}; refreshing suggested prompts`);
147
+ await swallow("setSuggestedPrompts", () => ops.setSuggestedPrompts(channelId, undefined, promptsFor(channel)));
148
+ }
149
+ /**
150
+ * The person navigated elsewhere. Recorded at both grains so the next turn —
151
+ * and the next prompt refresh — knows where they are, whichever manifest key
152
+ * this app uses.
153
+ */
154
+ export function handleAgentContextChanged(registry, payload) {
155
+ if (!payload.channel_id)
156
+ return;
157
+ // Logged for the same reason as the open event: these two are the whole
158
+ // agent surface, and whether either is subscribed is otherwise invisible
159
+ // from inside mikan.
160
+ log.logInfo(`[${payload.channel_id}] Slack agent context changed${payload.context?.channel_id ? ` (viewing ${payload.context.channel_id})` : ""}`);
161
+ if (payload.thread_ts) {
162
+ registry.remember(payload.channel_id, payload.thread_ts, payload.context);
163
+ return;
164
+ }
165
+ registry.rememberChannel(payload.channel_id, payload.context);
166
+ }
167
+ /**
168
+ * Title a conversation from the first thing the person said, so the pane's
169
+ * sidebar is navigable. Without it every past conversation looks the same.
170
+ */
171
+ export async function titleAssistantThread(ops, registry, channelId, threadTs, firstMessage) {
172
+ if (!registry.isAgentSurface(channelId, threadTs))
173
+ return;
174
+ if (!registry.claimTitle(channelId, threadTs))
175
+ return;
176
+ const title = summarizeTitle(firstMessage);
177
+ if (!title)
178
+ return;
179
+ await swallow("setTitle", () => ops.setTitle(channelId, threadTs, title));
180
+ }
181
+ /**
182
+ * First line, trimmed to something a sidebar can show. Deliberately not a
183
+ * model call: a title is worth having immediately and cheaply, and the
184
+ * person's own words label the conversation better than a paraphrase.
185
+ */
186
+ export function summarizeTitle(message) {
187
+ const firstLine = message
188
+ .replace(/<@[^>]+>/g, "")
189
+ .split("\n")
190
+ .map((line) => line.trim())
191
+ .find((line) => line.length > 0);
192
+ if (!firstLine)
193
+ return "";
194
+ return firstLine.length <= 50 ? firstLine : `${firstLine.slice(0, 49)}…`;
195
+ }
196
+ async function swallow(label, run) {
197
+ try {
198
+ await run();
199
+ }
200
+ catch (err) {
201
+ log.logWarning(`Slack agent surface ${label} failed`, err instanceof Error ? err.message : String(err));
202
+ }
203
+ }
204
+ //# sourceMappingURL=assistant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assistant.js","sourceRoot":"","sources":["../../../src/adapters/slack/assistant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;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AC,GAAG,CAAC,QAAQ,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,MAAM,SAAS,GAAG,OAAO;SACtB,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;SACxB,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACnC,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,CAAC;IAC1B,OAAO,SAAS,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC;AAC3E,CAAC;AAED,KAAK,UAAU,OAAO,CAAC,KAAa,EAAE,GAA2B;IAC/D,IAAI,CAAC;QACH,MAAM,GAAG,EAAE,CAAC;IACd,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,GAAG,CAAC,UAAU,CACZ,uBAAuB,KAAK,SAAS,EACrC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CACjD,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["/**\n * Slack's agent / assistant surface — the app's own pane, separate from\n * channels and ordinary DMs.\n *\n * There are two of these, not one, and they differ in which events signal\n * \"someone opened a conversation\":\n *\n * | Manifest key | Opened signal | Prompts |\n * | ----------------- | ------------------------------------ | ------------- |\n * | `agent_view` | `app_home_opened` with tab=`messages` | pinned to the DM |\n * | `assistant_view` | `assistant_thread_started` | per thread |\n *\n * Slack's own words for the newer one: \"rely on the `app_home_opened` event to\n * know when a user has actively opened a DM with your app\", and\n * \"the `assistant_thread_started` event no longer indicates this\". What the\n * docs do *not* say is whether `assistant_thread_started` still fires for an\n * `agent_view` app — so both paths are handled rather than guessed at, which\n * also means an app on either manifest key works without a migration.\n *\n * The two signals need different behaviour, and conflating them would be a\n * bug: `assistant_thread_started` fires once per new conversation, so greeting\n * is right; `app_home_opened` fires **every time the pane is opened**, so\n * greeting there would nag. The agent path therefore only refreshes the\n * pinned prompts, which is idempotent.\n *\n * Session semantics are deliberately unchanged. Each conversation is a thread\n * and mikan already scopes a thread to its own session — the right shape,\n * because the pane's sidebar is a list of separate conversations rather than\n * one transcript. Continuity across them comes from the office's memory.\n *\n * Suggested prompts are deterministic, varying only with the channel Slack\n * says the person is viewing. Enough to feel aware without spending a model\n * call before they have typed anything.\n */\nimport * as log from \"../../log.js\";\n\n/** The `assistant_thread` payload on the `assistant_view` lifecycle events. */\nexport interface AssistantThreadPayload {\n user_id?: string;\n channel_id?: string;\n thread_ts?: string;\n context?: AgentContext;\n}\n\n/**\n * Which channel the person is viewing beside the pane. Slack spells this\n * `context` on `app_home_opened` and `app_context_changed`, and `app_context`\n * on `message.im` — the asymmetry is Slack's, normalized here.\n */\nexport interface AgentContext {\n channel_id?: string;\n team_id?: string;\n enterprise_id?: string | null;\n}\n\nexport interface SuggestedPrompt {\n title: string;\n message: string;\n}\n\n/** What the adapter needs from the bot to serve this surface. */\nexport interface AssistantSurfaceOps {\n postInThread(channel: string, threadTs: string, text: string): Promise<string>;\n /** `threadTs` omitted pins the prompts to the DM instead of one thread. */\n setSuggestedPrompts(\n channel: string,\n threadTs: string | undefined,\n prompts: SuggestedPrompt[],\n ): Promise<void>;\n setTitle(channel: string, threadTs: string, title: string): Promise<void>;\n /** Human-readable channel name for context, when the bot knows it. */\n channelName(channelId: string): string | undefined;\n}\n\nconst GREETING = \"有什麼我可以幫忙的?\";\nconst GREETING_WITH_CHANNEL = (channel: string) =>\n `有什麼我可以幫忙的?我看得到你正在 #${channel}。`;\n\n/** Prompts offered with no channel context — general-purpose starting points. */\nconst DEFAULT_PROMPTS: SuggestedPrompt[] = [\n { title: \"看看工作區\", message: \"這個工作區裡有什麼?先給我一個概覽。\" },\n { title: \"最近的變更\", message: \"最近的程式碼變更有哪些?挑重要的說。\" },\n { title: \"排一個提醒\", message: \"幫我排一個每天早上的提醒。\" },\n];\n\n/**\n * Prompts when Slack tells us which channel the person is looking at. Naming\n * the channel is the cheap half of \"context-aware\": it costs nothing and it is\n * what makes the suggestions feel addressed to the moment.\n */\nfunction promptsFor(channel: string | undefined): SuggestedPrompt[] {\n if (!channel) return DEFAULT_PROMPTS;\n return [\n { title: `#${channel} 在討論什麼`, message: `幫我摘要 #${channel} 最近的討論。` },\n { title: \"有什麼要我接手\", message: `#${channel} 裡有沒有需要我處理或追蹤的事?` },\n { title: \"看看工作區\", message: \"這個工作區裡有什麼?先給我一個概覽。\" },\n ];\n}\n\n/**\n * Which conversations belong to this surface, and the context Slack last\n * reported for each.\n *\n * Two levels, because the two manifest keys register at different grains: an\n * `agent_view` DM is known before any thread exists, while an\n * `assistant_view` thread is known individually.\n *\n * In memory on purpose: transient UI state that Slack re-sends on open and on\n * every change, so a restart self-heals on the next interaction. Persisting it\n * would add a store to keep consistent for nothing that survives the trip.\n */\nexport class AssistantThreadRegistry {\n private threads = new Map<string, AgentContext>();\n private channels = new Map<string, AgentContext>();\n private titled = new Set<string>();\n\n private key(channelId: string, threadTs: string): string {\n return `${channelId}\\n${threadTs}`;\n }\n\n /** An `assistant_view` thread. */\n remember(channelId: string, threadTs: string, context?: AgentContext): void {\n this.threads.set(this.key(channelId, threadTs), context ?? {});\n }\n\n /** An `agent_view` DM, which has no thread yet. */\n rememberChannel(channelId: string, context?: AgentContext): void {\n this.channels.set(channelId, context ?? {});\n }\n\n /** Thread context, falling back to the channel's. */\n contextFor(channelId: string, threadTs: string): AgentContext | undefined {\n return this.threads.get(this.key(channelId, threadTs)) ?? this.channels.get(channelId);\n }\n\n channelContext(channelId: string): AgentContext | undefined {\n return this.channels.get(channelId);\n }\n\n /**\n * Whether this thread is part of the pane — either registered individually,\n * or living in a DM known to be the agent surface. The second case is what\n * makes titles work under `agent_view`, where Slack opens threads itself and\n * never announces them.\n */\n isAgentSurface(channelId: string, threadTs: string): boolean {\n return this.threads.has(this.key(channelId, threadTs)) || this.channels.has(channelId);\n }\n\n /** True the first time a thread is seen, so a title is set exactly once. */\n claimTitle(channelId: string, threadTs: string): boolean {\n const key = this.key(channelId, threadTs);\n if (this.titled.has(key)) return false;\n this.titled.add(key);\n return true;\n }\n}\n\n/**\n * `assistant_view`: a new conversation opened. Greet, and offer prompts for\n * that thread.\n *\n * Failures are logged, never thrown. A greeting that did not post is a worse\n * pane, not a broken conversation, and taking the socket handler down over it\n * would break the surface entirely.\n */\nexport async function handleAssistantThreadStarted(\n ops: AssistantSurfaceOps,\n registry: AssistantThreadRegistry,\n thread: AssistantThreadPayload,\n): Promise<void> {\n const channelId = thread.channel_id;\n const threadTs = thread.thread_ts;\n if (!channelId || !threadTs) return;\n\n registry.remember(channelId, threadTs, thread.context);\n const channel = thread.context?.channel_id\n ? ops.channelName(thread.context.channel_id)\n : undefined;\n\n await swallow(\"greeting\", () =>\n ops.postInThread(channelId, threadTs, channel ? GREETING_WITH_CHANNEL(channel) : GREETING),\n );\n await swallow(\"setSuggestedPrompts\", () =>\n ops.setSuggestedPrompts(channelId, threadTs, promptsFor(channel)),\n );\n}\n\n/**\n * `agent_view`: the person opened the app's DM. Refresh the prompts pinned to\n * it — and deliberately do not greet, because Slack sends this on *every*\n * open, so a greeting here would arrive again and again.\n */\nexport async function handleAgentDmOpened(\n ops: AssistantSurfaceOps,\n registry: AssistantThreadRegistry,\n channelId: string,\n context?: AgentContext,\n): Promise<void> {\n if (!channelId) return;\n registry.rememberChannel(channelId, context);\n const channel = context?.channel_id ? ops.channelName(context.channel_id) : undefined;\n // The agent surface is otherwise silent, and its failure mode — no prompts,\n // untitled conversations — looks identical from the outside to Slack simply\n // not sending the event. This line is the difference between the two, and\n // is the first thing to look for when the pane seems inert.\n log.logInfo(\n `[${channelId}] Slack agent DM opened${channel ? ` (viewing #${channel})` : \"\"}; refreshing suggested prompts`,\n );\n await swallow(\"setSuggestedPrompts\", () =>\n ops.setSuggestedPrompts(channelId, undefined, promptsFor(channel)),\n );\n}\n\n/**\n * The person navigated elsewhere. Recorded at both grains so the next turn —\n * and the next prompt refresh — knows where they are, whichever manifest key\n * this app uses.\n */\nexport function handleAgentContextChanged(\n registry: AssistantThreadRegistry,\n payload: { channel_id?: string; thread_ts?: string; context?: AgentContext },\n): void {\n if (!payload.channel_id) return;\n // Logged for the same reason as the open event: these two are the whole\n // agent surface, and whether either is subscribed is otherwise invisible\n // from inside mikan.\n log.logInfo(\n `[${payload.channel_id}] Slack agent context changed${payload.context?.channel_id ? ` (viewing ${payload.context.channel_id})` : \"\"}`,\n );\n if (payload.thread_ts) {\n registry.remember(payload.channel_id, payload.thread_ts, payload.context);\n return;\n }\n registry.rememberChannel(payload.channel_id, payload.context);\n}\n\n/**\n * Title a conversation from the first thing the person said, so the pane's\n * sidebar is navigable. Without it every past conversation looks the same.\n */\nexport async function titleAssistantThread(\n ops: AssistantSurfaceOps,\n registry: AssistantThreadRegistry,\n channelId: string,\n threadTs: string,\n firstMessage: string,\n): Promise<void> {\n if (!registry.isAgentSurface(channelId, threadTs)) return;\n if (!registry.claimTitle(channelId, threadTs)) return;\n const title = summarizeTitle(firstMessage);\n if (!title) return;\n await swallow(\"setTitle\", () => ops.setTitle(channelId, threadTs, title));\n}\n\n/**\n * First line, trimmed to something a sidebar can show. Deliberately not a\n * model call: a title is worth having immediately and cheaply, and the\n * person's own words label the conversation better than a paraphrase.\n */\nexport function summarizeTitle(message: string): string {\n const firstLine = message\n .replace(/<@[^>]+>/g, \"\")\n .split(\"\\n\")\n .map((line) => line.trim())\n .find((line) => line.length > 0);\n if (!firstLine) return \"\";\n return firstLine.length <= 50 ? firstLine : `${firstLine.slice(0, 49)}…`;\n}\n\nasync function swallow(label: string, run: () => Promise<unknown>): Promise<void> {\n try {\n await run();\n } catch (err) {\n log.logWarning(\n `Slack agent surface ${label} failed`,\n err instanceof Error ? err.message : String(err),\n );\n }\n}\n"]}
@@ -1,4 +1,18 @@
1
1
  import type { KnownBlock } from "@slack/types";
2
+ /**
3
+ * Resolve response-source mentions to Slack's native form.
4
+ *
5
+ * The response source is platform-neutral: the model writes `<@userName>`
6
+ * from the prompt's Users table, and the adapter owns the conversion to
7
+ * `<@U…>` — Slack only links and notifies on the raw user id. Lookup covers
8
+ * userName and displayName case-insensitively; native-id mentions pass
9
+ * through, and unknown names stay verbatim rather than guessing.
10
+ */
11
+ export declare function resolveSlackMentions(source: string, users: Iterable<{
12
+ id: string;
13
+ userName: string;
14
+ displayName: string;
15
+ }>): string;
2
16
  export declare function renderSlackBlocks(source: string): {
3
17
  text: string;
4
18
  blocks: KnownBlock[];
@@ -1 +1 @@
1
- {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../../src/adapters/slack/blocks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AA4H/C,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,EAAE,CAAA;CAAE,CAwDxF"}
1
+ {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../../src/adapters/slack/blocks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AA8B/C;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,QAAQ,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,GACrE,MAAM,CAiBR;AAuDD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,EAAE,CAAA;CAAE,CA6BxF"}