heyio 3.3.5 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) hide show
  1. package/CODE_OF_CONDUCT.md +83 -0
  2. package/LICENSE +21 -0
  3. package/README.md +203 -151
  4. package/dist/daemon/cli.js +7153 -0
  5. package/dist/daemon/index.js +6421 -0
  6. package/dist/web/assets/index-CbptHIYU.js +520 -0
  7. package/{public → dist/web}/index.html +1 -1
  8. package/package.json +45 -48
  9. package/dist/api/middleware/auth.d.ts +0 -14
  10. package/dist/api/middleware/auth.d.ts.map +0 -1
  11. package/dist/api/middleware/auth.js +0 -130
  12. package/dist/api/middleware/auth.js.map +0 -1
  13. package/dist/api/notifications.d.ts +0 -14
  14. package/dist/api/notifications.d.ts.map +0 -1
  15. package/dist/api/notifications.js +0 -114
  16. package/dist/api/notifications.js.map +0 -1
  17. package/dist/api/routes/activity.d.ts +0 -3
  18. package/dist/api/routes/activity.d.ts.map +0 -1
  19. package/dist/api/routes/activity.js +0 -28
  20. package/dist/api/routes/activity.js.map +0 -1
  21. package/dist/api/routes/attachments.d.ts +0 -3
  22. package/dist/api/routes/attachments.d.ts.map +0 -1
  23. package/dist/api/routes/attachments.js +0 -83
  24. package/dist/api/routes/attachments.js.map +0 -1
  25. package/dist/api/routes/config.d.ts +0 -3
  26. package/dist/api/routes/config.d.ts.map +0 -1
  27. package/dist/api/routes/config.js +0 -107
  28. package/dist/api/routes/config.js.map +0 -1
  29. package/dist/api/routes/conversations.d.ts +0 -3
  30. package/dist/api/routes/conversations.d.ts.map +0 -1
  31. package/dist/api/routes/conversations.js +0 -25
  32. package/dist/api/routes/conversations.js.map +0 -1
  33. package/dist/api/routes/health.d.ts +0 -3
  34. package/dist/api/routes/health.d.ts.map +0 -1
  35. package/dist/api/routes/health.js +0 -39
  36. package/dist/api/routes/health.js.map +0 -1
  37. package/dist/api/routes/inbox.d.ts +0 -3
  38. package/dist/api/routes/inbox.d.ts.map +0 -1
  39. package/dist/api/routes/inbox.js +0 -139
  40. package/dist/api/routes/inbox.js.map +0 -1
  41. package/dist/api/routes/schedules.d.ts +0 -3
  42. package/dist/api/routes/schedules.d.ts.map +0 -1
  43. package/dist/api/routes/schedules.js +0 -116
  44. package/dist/api/routes/schedules.js.map +0 -1
  45. package/dist/api/routes/skills.d.ts +0 -2
  46. package/dist/api/routes/skills.d.ts.map +0 -1
  47. package/dist/api/routes/skills.js +0 -127
  48. package/dist/api/routes/skills.js.map +0 -1
  49. package/dist/api/routes/squads.d.ts +0 -3
  50. package/dist/api/routes/squads.d.ts.map +0 -1
  51. package/dist/api/routes/squads.js +0 -578
  52. package/dist/api/routes/squads.js.map +0 -1
  53. package/dist/api/routes/usage.d.ts +0 -3
  54. package/dist/api/routes/usage.d.ts.map +0 -1
  55. package/dist/api/routes/usage.js +0 -55
  56. package/dist/api/routes/usage.js.map +0 -1
  57. package/dist/api/routes/wiki.d.ts +0 -2
  58. package/dist/api/routes/wiki.d.ts.map +0 -1
  59. package/dist/api/routes/wiki.js +0 -75
  60. package/dist/api/routes/wiki.js.map +0 -1
  61. package/dist/api/server.d.ts +0 -7
  62. package/dist/api/server.d.ts.map +0 -1
  63. package/dist/api/server.js +0 -183
  64. package/dist/api/server.js.map +0 -1
  65. package/dist/config.d.ts +0 -3
  66. package/dist/config.d.ts.map +0 -1
  67. package/dist/config.js +0 -3
  68. package/dist/config.js.map +0 -1
  69. package/dist/copilot/client.d.ts +0 -5
  70. package/dist/copilot/client.d.ts.map +0 -1
  71. package/dist/copilot/client.js +0 -38
  72. package/dist/copilot/client.js.map +0 -1
  73. package/dist/copilot/health-monitor.d.ts +0 -14
  74. package/dist/copilot/health-monitor.d.ts.map +0 -1
  75. package/dist/copilot/health-monitor.js +0 -70
  76. package/dist/copilot/health-monitor.js.map +0 -1
  77. package/dist/copilot/orchestrator.d.ts +0 -5
  78. package/dist/copilot/orchestrator.d.ts.map +0 -1
  79. package/dist/copilot/orchestrator.js +0 -227
  80. package/dist/copilot/orchestrator.js.map +0 -1
  81. package/dist/copilot/tools.d.ts +0 -80
  82. package/dist/copilot/tools.d.ts.map +0 -1
  83. package/dist/copilot/tools.js +0 -1067
  84. package/dist/copilot/tools.js.map +0 -1
  85. package/dist/index.d.ts +0 -3
  86. package/dist/index.d.ts.map +0 -1
  87. package/dist/index.js +0 -94
  88. package/dist/index.js.map +0 -1
  89. package/dist/logging/logger.d.ts +0 -6
  90. package/dist/logging/logger.d.ts.map +0 -1
  91. package/dist/logging/logger.js +0 -33
  92. package/dist/logging/logger.js.map +0 -1
  93. package/dist/models/index.d.ts +0 -6
  94. package/dist/models/index.d.ts.map +0 -1
  95. package/dist/models/index.js +0 -4
  96. package/dist/models/index.js.map +0 -1
  97. package/dist/models/pricing.d.ts +0 -25
  98. package/dist/models/pricing.d.ts.map +0 -1
  99. package/dist/models/pricing.js +0 -96
  100. package/dist/models/pricing.js.map +0 -1
  101. package/dist/models/registry.d.ts +0 -34
  102. package/dist/models/registry.d.ts.map +0 -1
  103. package/dist/models/registry.js +0 -109
  104. package/dist/models/registry.js.map +0 -1
  105. package/dist/models/token-tracker.d.ts +0 -41
  106. package/dist/models/token-tracker.d.ts.map +0 -1
  107. package/dist/models/token-tracker.js +0 -103
  108. package/dist/models/token-tracker.js.map +0 -1
  109. package/dist/scheduler/engine.d.ts +0 -12
  110. package/dist/scheduler/engine.d.ts.map +0 -1
  111. package/dist/scheduler/engine.js +0 -128
  112. package/dist/scheduler/engine.js.map +0 -1
  113. package/dist/skills/discover.d.ts +0 -22
  114. package/dist/skills/discover.d.ts.map +0 -1
  115. package/dist/skills/discover.js +0 -228
  116. package/dist/skills/discover.js.map +0 -1
  117. package/dist/skills/index.d.ts +0 -5
  118. package/dist/skills/index.d.ts.map +0 -1
  119. package/dist/skills/index.js +0 -3
  120. package/dist/skills/index.js.map +0 -1
  121. package/dist/skills/store.d.ts +0 -56
  122. package/dist/skills/store.d.ts.map +0 -1
  123. package/dist/skills/store.js +0 -154
  124. package/dist/skills/store.js.map +0 -1
  125. package/dist/squad/agent.d.ts +0 -65
  126. package/dist/squad/agent.d.ts.map +0 -1
  127. package/dist/squad/agent.js +0 -544
  128. package/dist/squad/agent.js.map +0 -1
  129. package/dist/squad/autonomy.d.ts +0 -16
  130. package/dist/squad/autonomy.d.ts.map +0 -1
  131. package/dist/squad/autonomy.js +0 -63
  132. package/dist/squad/autonomy.js.map +0 -1
  133. package/dist/squad/event-bus.d.ts +0 -22
  134. package/dist/squad/event-bus.d.ts.map +0 -1
  135. package/dist/squad/event-bus.js +0 -56
  136. package/dist/squad/event-bus.js.map +0 -1
  137. package/dist/squad/execution/index.d.ts +0 -14
  138. package/dist/squad/execution/index.d.ts.map +0 -1
  139. package/dist/squad/execution/index.js +0 -8
  140. package/dist/squad/execution/index.js.map +0 -1
  141. package/dist/squad/execution/instance.d.ts +0 -45
  142. package/dist/squad/execution/instance.d.ts.map +0 -1
  143. package/dist/squad/execution/instance.js +0 -171
  144. package/dist/squad/execution/instance.js.map +0 -1
  145. package/dist/squad/execution/planning.d.ts +0 -20
  146. package/dist/squad/execution/planning.d.ts.map +0 -1
  147. package/dist/squad/execution/planning.js +0 -62
  148. package/dist/squad/execution/planning.js.map +0 -1
  149. package/dist/squad/execution/pr.d.ts +0 -15
  150. package/dist/squad/execution/pr.d.ts.map +0 -1
  151. package/dist/squad/execution/pr.js +0 -109
  152. package/dist/squad/execution/pr.js.map +0 -1
  153. package/dist/squad/execution/review.d.ts +0 -21
  154. package/dist/squad/execution/review.d.ts.map +0 -1
  155. package/dist/squad/execution/review.js +0 -151
  156. package/dist/squad/execution/review.js.map +0 -1
  157. package/dist/squad/execution/runner.d.ts +0 -52
  158. package/dist/squad/execution/runner.d.ts.map +0 -1
  159. package/dist/squad/execution/runner.js +0 -93
  160. package/dist/squad/execution/runner.js.map +0 -1
  161. package/dist/squad/execution/tasks.d.ts +0 -22
  162. package/dist/squad/execution/tasks.d.ts.map +0 -1
  163. package/dist/squad/execution/tasks.js +0 -108
  164. package/dist/squad/execution/tasks.js.map +0 -1
  165. package/dist/squad/execution/worktree.d.ts +0 -27
  166. package/dist/squad/execution/worktree.d.ts.map +0 -1
  167. package/dist/squad/execution/worktree.js +0 -141
  168. package/dist/squad/execution/worktree.js.map +0 -1
  169. package/dist/squad/hiring.d.ts +0 -57
  170. package/dist/squad/hiring.d.ts.map +0 -1
  171. package/dist/squad/hiring.js +0 -588
  172. package/dist/squad/hiring.js.map +0 -1
  173. package/dist/squad/index.d.ts +0 -8
  174. package/dist/squad/index.d.ts.map +0 -1
  175. package/dist/squad/index.js +0 -6
  176. package/dist/squad/index.js.map +0 -1
  177. package/dist/squad/manager.d.ts +0 -58
  178. package/dist/squad/manager.d.ts.map +0 -1
  179. package/dist/squad/manager.js +0 -351
  180. package/dist/squad/manager.js.map +0 -1
  181. package/dist/squad/model-selector.d.ts +0 -29
  182. package/dist/squad/model-selector.d.ts.map +0 -1
  183. package/dist/squad/model-selector.js +0 -64
  184. package/dist/squad/model-selector.js.map +0 -1
  185. package/dist/squad/name-generator.d.ts +0 -16
  186. package/dist/squad/name-generator.d.ts.map +0 -1
  187. package/dist/squad/name-generator.js +0 -111
  188. package/dist/squad/name-generator.js.map +0 -1
  189. package/dist/squad/roles/templates.d.ts +0 -7
  190. package/dist/squad/roles/templates.d.ts.map +0 -1
  191. package/dist/squad/roles/templates.js +0 -104
  192. package/dist/squad/roles/templates.js.map +0 -1
  193. package/dist/squad/skill-parser.d.ts +0 -36
  194. package/dist/squad/skill-parser.d.ts.map +0 -1
  195. package/dist/squad/skill-parser.js +0 -90
  196. package/dist/squad/skill-parser.js.map +0 -1
  197. package/dist/squad/source-resolver.d.ts +0 -20
  198. package/dist/squad/source-resolver.d.ts.map +0 -1
  199. package/dist/squad/source-resolver.js +0 -51
  200. package/dist/squad/source-resolver.js.map +0 -1
  201. package/dist/store/activity.d.ts +0 -51
  202. package/dist/store/activity.d.ts.map +0 -1
  203. package/dist/store/activity.js +0 -197
  204. package/dist/store/activity.js.map +0 -1
  205. package/dist/store/conversations.d.ts +0 -25
  206. package/dist/store/conversations.d.ts.map +0 -1
  207. package/dist/store/conversations.js +0 -76
  208. package/dist/store/conversations.js.map +0 -1
  209. package/dist/store/db.d.ts +0 -5
  210. package/dist/store/db.d.ts.map +0 -1
  211. package/dist/store/db.js +0 -290
  212. package/dist/store/db.js.map +0 -1
  213. package/dist/store/inbox.d.ts +0 -67
  214. package/dist/store/inbox.d.ts.map +0 -1
  215. package/dist/store/inbox.js +0 -192
  216. package/dist/store/inbox.js.map +0 -1
  217. package/dist/store/schedules.d.ts +0 -53
  218. package/dist/store/schedules.d.ts.map +0 -1
  219. package/dist/store/schedules.js +0 -160
  220. package/dist/store/schedules.js.map +0 -1
  221. package/dist/wiki/index.d.ts +0 -3
  222. package/dist/wiki/index.d.ts.map +0 -1
  223. package/dist/wiki/index.js +0 -2
  224. package/dist/wiki/index.js.map +0 -1
  225. package/dist/wiki/store.d.ts +0 -81
  226. package/dist/wiki/store.d.ts.map +0 -1
  227. package/dist/wiki/store.js +0 -270
  228. package/dist/wiki/store.js.map +0 -1
  229. package/node_modules/@io/shared/dist/config.d.ts +0 -26
  230. package/node_modules/@io/shared/dist/config.d.ts.map +0 -1
  231. package/node_modules/@io/shared/dist/config.js +0 -53
  232. package/node_modules/@io/shared/dist/config.js.map +0 -1
  233. package/node_modules/@io/shared/dist/constants.d.ts +0 -19
  234. package/node_modules/@io/shared/dist/constants.d.ts.map +0 -1
  235. package/node_modules/@io/shared/dist/constants.js +0 -51
  236. package/node_modules/@io/shared/dist/constants.js.map +0 -1
  237. package/node_modules/@io/shared/dist/index.d.ts +0 -12
  238. package/node_modules/@io/shared/dist/index.d.ts.map +0 -1
  239. package/node_modules/@io/shared/dist/index.js +0 -3
  240. package/node_modules/@io/shared/dist/index.js.map +0 -1
  241. package/node_modules/@io/shared/dist/types/agents.d.ts +0 -3
  242. package/node_modules/@io/shared/dist/types/agents.d.ts.map +0 -1
  243. package/node_modules/@io/shared/dist/types/agents.js +0 -2
  244. package/node_modules/@io/shared/dist/types/agents.js.map +0 -1
  245. package/node_modules/@io/shared/dist/types/api.d.ts +0 -33
  246. package/node_modules/@io/shared/dist/types/api.d.ts.map +0 -1
  247. package/node_modules/@io/shared/dist/types/api.js +0 -2
  248. package/node_modules/@io/shared/dist/types/api.js.map +0 -1
  249. package/node_modules/@io/shared/dist/types/attachments.d.ts +0 -10
  250. package/node_modules/@io/shared/dist/types/attachments.d.ts.map +0 -1
  251. package/node_modules/@io/shared/dist/types/attachments.js +0 -2
  252. package/node_modules/@io/shared/dist/types/attachments.js.map +0 -1
  253. package/node_modules/@io/shared/dist/types/events.d.ts +0 -44
  254. package/node_modules/@io/shared/dist/types/events.d.ts.map +0 -1
  255. package/node_modules/@io/shared/dist/types/events.js +0 -2
  256. package/node_modules/@io/shared/dist/types/events.js.map +0 -1
  257. package/node_modules/@io/shared/dist/types/history.d.ts +0 -33
  258. package/node_modules/@io/shared/dist/types/history.d.ts.map +0 -1
  259. package/node_modules/@io/shared/dist/types/history.js +0 -2
  260. package/node_modules/@io/shared/dist/types/history.js.map +0 -1
  261. package/node_modules/@io/shared/dist/types/messages.d.ts +0 -15
  262. package/node_modules/@io/shared/dist/types/messages.d.ts.map +0 -1
  263. package/node_modules/@io/shared/dist/types/messages.js +0 -2
  264. package/node_modules/@io/shared/dist/types/messages.js.map +0 -1
  265. package/node_modules/@io/shared/dist/types/squads.d.ts +0 -46
  266. package/node_modules/@io/shared/dist/types/squads.d.ts.map +0 -1
  267. package/node_modules/@io/shared/dist/types/squads.js +0 -2
  268. package/node_modules/@io/shared/dist/types/squads.js.map +0 -1
  269. package/node_modules/@io/shared/dist/types/tokens.d.ts +0 -19
  270. package/node_modules/@io/shared/dist/types/tokens.d.ts.map +0 -1
  271. package/node_modules/@io/shared/dist/types/tokens.js +0 -2
  272. package/node_modules/@io/shared/dist/types/tokens.js.map +0 -1
  273. package/node_modules/@io/shared/package.json +0 -18
  274. package/node_modules/@io/shared/src/config.ts +0 -85
  275. package/node_modules/@io/shared/src/constants.ts +0 -54
  276. package/node_modules/@io/shared/src/index.ts +0 -46
  277. package/node_modules/@io/shared/src/types/agents.ts +0 -3
  278. package/node_modules/@io/shared/src/types/api.ts +0 -35
  279. package/node_modules/@io/shared/src/types/attachments.ts +0 -9
  280. package/node_modules/@io/shared/src/types/events.ts +0 -86
  281. package/node_modules/@io/shared/src/types/history.ts +0 -37
  282. package/node_modules/@io/shared/src/types/messages.ts +0 -15
  283. package/node_modules/@io/shared/src/types/squads.ts +0 -56
  284. package/node_modules/@io/shared/src/types/tokens.ts +0 -19
  285. package/node_modules/@io/shared/tsconfig.json +0 -9
  286. package/node_modules/@io/shared/tsconfig.tsbuildinfo +0 -1
  287. package/public/assets/index-BywBQCtu.js +0 -510
  288. package/public/assets/index-BywBQCtu.js.map +0 -1
  289. /package/{public → dist/web}/assets/index-B6F0UZkW.css +0 -0
@@ -1,227 +0,0 @@
1
- import { approveAll } from '@github/copilot-sdk';
2
- import { loadConfig } from '../config.js';
3
- import { createChildLogger } from '../logging/logger.js';
4
- import { recordTokenUsage } from '../models/token-tracker.js';
5
- import { getActiveSkillsContent } from '../skills/index.js';
6
- import { listSquads } from '../squad/manager.js';
7
- import { appendConversationMessage } from '../store/conversations.js';
8
- import { getDatabase } from '../store/db.js';
9
- import { getOrchestratorScopes, getPageListing } from '../wiki/index.js';
10
- import { getClient } from './client.js';
11
- import { createOrchestratorTools } from './tools.js';
12
- let logger;
13
- let session;
14
- let sessionId;
15
- let currentModel = '';
16
- const messageQueue = [];
17
- let processing = false;
18
- const SYSTEM_MESSAGE_BASE = `You are IO, an AI orchestrator daemon. You help users manage their software projects through intelligent conversation and by coordinating specialized agent squads.
19
-
20
- ## Your Capabilities
21
- - Answer general questions directly
22
- - Manage squads: create, monitor, and coordinate teams of AI agents for specific projects
23
- - Delegate project-specific work to the appropriate squad's team lead
24
- - Track token usage and costs across all squads
25
- - Manage the inbox: squads send you deliverables and questions that need user attention
26
-
27
- ## Routing Rules
28
- - If the user's message relates to a project that has an assigned squad, delegate to that squad using the delegate_to_squad tool
29
- - If the user asks about squad status, use the appropriate squad tools
30
- - For general questions unrelated to any squad's project, answer directly
31
- - NEVER answer project-specific questions yourself if a squad exists for that project
32
-
33
- ## Tool Selection: delegate_to_squad vs run_squad_instance
34
- - **delegate_to_squad**: Use for planning, research, analysis, questions, reviews, or any task that does NOT require writing code. This is a lightweight message to the team lead.
35
- - **run_squad_instance**: ONLY use when the user explicitly wants code written, committed, and a PR created. This spins up a full worktree, holds a meeting, assigns tasks, and creates a pull request. Never use this for planning or research.
36
-
37
- ## Delegation Behavior
38
- - When you delegate to a squad, immediately tell the user you've delegated. Example: "I've handed this off to [squad name]. They'll deliver their results to your inbox when done."
39
- - Do NOT wait for or relay the squad's full response — the squad will deliver via your inbox
40
- - If the user explicitly asks for something to be delivered to their inbox (e.g., "put that in my inbox", "send me a summary in inbox"), delegate and confirm immediately
41
- - Keep your delegation confirmations brief and conversational
42
-
43
- ## Inbox Rules
44
- - When a squad has a pending question, proactively tell the user about it
45
- - Use list_inbox to check for unread items when the user asks about notifications or inbox
46
- - When the user answers a squad's question, use respond_to_inbox to deliver their response and unblock the squad
47
- - Summarize deliverables in a friendly, readable way when presenting them to the user
48
- `;
49
- /**
50
- * Build the system message with current squad registry context.
51
- */
52
- async function buildSystemMessage() {
53
- try {
54
- const config = loadConfig();
55
- const squads = await listSquads();
56
- const wikiListing = getPageListing(getOrchestratorScopes());
57
- const skillsContent = await getActiveSkillsContent('orchestrator');
58
- const timezoneSection = `\n## User Timezone\nThe user's configured timezone is **${config.timezone}**. When the user mentions times (e.g., "at 3pm", "every morning at 9"), interpret them in this timezone. When creating schedules with cron expressions, convert from the user's timezone to UTC.\n`;
59
- const wikiSection = `\n## Wiki Knowledge\n${wikiListing}\n\nUse read_wiki to access page content. Use write_wiki to record important knowledge.\n`;
60
- if (squads.length === 0) {
61
- return `${SYSTEM_MESSAGE_BASE}${timezoneSection}\n## Active Squads\n(No squads currently active)${wikiSection}${skillsContent}`;
62
- }
63
- const squadList = squads
64
- .map((s) => `- **${s.name}**: project at \`${s.projectPath}\`${s.repoUrl ? ` (${s.repoUrl})` : ''} [autonomy: ${s.autonomyTier}]`)
65
- .join('\n');
66
- return `${SYSTEM_MESSAGE_BASE}${timezoneSection}\n## Active Squads\n${squadList}\n\nWhen a user's message mentions any of the above projects (by name, path, or related topic), delegate to the corresponding squad.${wikiSection}${skillsContent}`;
67
- }
68
- catch {
69
- return `${SYSTEM_MESSAGE_BASE}\n## Active Squads\n(Unable to load squad registry)\n`;
70
- }
71
- }
72
- export async function initOrchestrator(config) {
73
- logger = createChildLogger('orchestrator');
74
- const client = await getClient();
75
- currentModel = config.defaultModel;
76
- const systemMessage = await buildSystemMessage();
77
- const sessionOptions = {
78
- model: config.defaultModel,
79
- streaming: true,
80
- tools: createOrchestratorTools(),
81
- systemMessage: { mode: 'replace', content: systemMessage },
82
- onPermissionRequest: approveAll,
83
- infiniteSessions: {
84
- enabled: true,
85
- backgroundCompactionThreshold: 0.8,
86
- bufferExhaustionThreshold: 0.95,
87
- },
88
- };
89
- // Try to resume existing session
90
- const savedSessionId = await getSavedSessionId();
91
- if (savedSessionId) {
92
- try {
93
- session = await client.resumeSession(savedSessionId, sessionOptions);
94
- sessionId = savedSessionId;
95
- subscribeToUsage(session);
96
- logger.info({ sessionId }, 'Resumed orchestrator session');
97
- return;
98
- }
99
- catch {
100
- logger.info({ sessionId: savedSessionId }, 'Previous session expired, creating new one');
101
- }
102
- }
103
- // Create new session
104
- session = await client.createSession(sessionOptions);
105
- sessionId = session.sessionId;
106
- subscribeToUsage(session);
107
- await saveSessionId(sessionId);
108
- logger.info({ sessionId }, 'Created new orchestrator session');
109
- }
110
- function subscribeToUsage(sess) {
111
- sess.on('assistant.usage', (event) => {
112
- const data = event.data;
113
- if (data.inputTokens || data.outputTokens) {
114
- recordTokenUsage({
115
- agentRole: 'orchestrator',
116
- model: data.model,
117
- inputTokens: data.inputTokens ?? 0,
118
- outputTokens: data.outputTokens ?? 0,
119
- }).catch((err) => logger.error({ err }, 'Failed to record token usage'));
120
- }
121
- });
122
- }
123
- export function sendMessage(prompt, source, onDelta) {
124
- return new Promise((resolve, reject) => {
125
- messageQueue.push({ prompt, source, onDelta, resolve, reject });
126
- processQueue();
127
- });
128
- }
129
- async function processQueue() {
130
- if (processing || messageQueue.length === 0)
131
- return;
132
- processing = true;
133
- while (messageQueue.length > 0) {
134
- const msg = messageQueue.shift();
135
- try {
136
- const response = await processMessage(msg);
137
- msg.resolve(response);
138
- }
139
- catch (err) {
140
- logger.error({ err }, 'Error processing message');
141
- msg.reject(err);
142
- }
143
- }
144
- processing = false;
145
- }
146
- async function processMessage(msg) {
147
- if (!session) {
148
- throw new Error('Orchestrator session not initialized');
149
- }
150
- // Check if the configured model has changed — if so, recreate the session
151
- const freshConfig = loadConfig();
152
- if (freshConfig.defaultModel !== currentModel) {
153
- logger.info({ from: currentModel, to: freshConfig.defaultModel }, 'Default model changed, recreating orchestrator session');
154
- currentModel = freshConfig.defaultModel;
155
- const client = await getClient();
156
- const systemMessage = await buildSystemMessage();
157
- session = await client.createSession({
158
- model: currentModel,
159
- streaming: true,
160
- tools: createOrchestratorTools(),
161
- systemMessage: { mode: 'replace', content: systemMessage },
162
- onPermissionRequest: approveAll,
163
- infiniteSessions: {
164
- enabled: true,
165
- backgroundCompactionThreshold: 0.8,
166
- bufferExhaustionThreshold: 0.95,
167
- },
168
- });
169
- sessionId = session.sessionId;
170
- subscribeToUsage(session);
171
- await saveSessionId(sessionId);
172
- logger.info({ sessionId, model: currentModel }, 'Orchestrator session recreated with new model');
173
- }
174
- await appendConversationMessage({
175
- role: 'user',
176
- content: msg.prompt,
177
- source: msg.source,
178
- });
179
- let accumulated = '';
180
- msg.onDelta('', false);
181
- // Subscribe to streaming deltas
182
- const unsubDelta = session.on('assistant.message_delta', (event) => {
183
- accumulated += event.data.deltaContent;
184
- msg.onDelta(accumulated, false);
185
- });
186
- try {
187
- const result = await session.sendAndWait({ prompt: msg.prompt }, 600_000);
188
- const finalContent = typeof result?.data?.content === 'string' && result.data.content.length > 0
189
- ? result.data.content
190
- : accumulated || '(No response)';
191
- await appendConversationMessage({
192
- role: 'assistant',
193
- content: finalContent,
194
- source: msg.source,
195
- });
196
- msg.onDelta(finalContent, true);
197
- return finalContent;
198
- }
199
- finally {
200
- unsubDelta();
201
- }
202
- }
203
- export async function destroyOrchestrator() {
204
- session = undefined;
205
- sessionId = undefined;
206
- }
207
- async function getSavedSessionId() {
208
- try {
209
- const db = getDatabase();
210
- const result = await db.execute("SELECT value FROM io_state WHERE key = 'orchestrator_session_id'");
211
- if (result.rows.length > 0) {
212
- return result.rows[0].value;
213
- }
214
- return undefined;
215
- }
216
- catch {
217
- return undefined;
218
- }
219
- }
220
- async function saveSessionId(id) {
221
- const db = getDatabase();
222
- await db.execute({
223
- sql: "INSERT OR REPLACE INTO io_state (key, value) VALUES ('orchestrator_session_id', ?)",
224
- args: [id],
225
- });
226
- }
227
- //# sourceMappingURL=orchestrator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../../src/copilot/orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAiB,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,kBAAk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BAAyB,CAAC;YAC/B,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,YAAY;YACrB,MAAM,EAAE,GAAG,CAAC,MAAM;SAClB,CAAC,CAAC;QACH,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;QAEhC,OAAO,YAAY,CAAC;IACrB,CAAC;YAAS,CAAC;QACV,UAAU,EAAE,CAAC;IACd,CAAC;AACF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACxC,OAAO,GAAG,SAAS,CAAC;IACpB,SAAS,GAAG,SAAS,CAAC;AACvB,CAAC;AAED,KAAK,UAAU,iBAAiB;IAC/B,IAAI,CAAC;QACJ,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,OAAO,CAC9B,kEAAkE,CAClE,CAAC;QACF,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAe,CAAC;QACvC,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,EAAU;IACtC,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;IACzB,MAAM,EAAE,CAAC,OAAO,CAAC;QAChB,GAAG,EAAE,oFAAoF;QACzF,IAAI,EAAE,CAAC,EAAE,CAAC;KACV,CAAC,CAAC;AACJ,CAAC"}
@@ -1,80 +0,0 @@
1
- export declare function createOrchestratorTools(): (import("@github/copilot-sdk").Tool<Record<string, never>> | import("@github/copilot-sdk").Tool<{
2
- squadName: string;
3
- }> | import("@github/copilot-sdk").Tool<{
4
- repoUrl: string;
5
- name?: string | undefined;
6
- universe?: string | undefined;
7
- removedRoles?: string[] | undefined;
8
- }> | import("@github/copilot-sdk").Tool<{
9
- squadName: string;
10
- universe: string;
11
- }> | import("@github/copilot-sdk").Tool<{
12
- squadName: string;
13
- member: string;
14
- newDisplayName: string;
15
- }> | import("@github/copilot-sdk").Tool<{
16
- squadName: string;
17
- member: string;
18
- }> | import("@github/copilot-sdk").Tool<{
19
- squadName: string;
20
- role: string;
21
- }> | import("@github/copilot-sdk").Tool<{
22
- squadName: string;
23
- message: string;
24
- attachmentIds?: string[] | undefined;
25
- }> | import("@github/copilot-sdk").Tool<{
26
- squadName: string;
27
- objective: string;
28
- issueRef?: string | undefined;
29
- attachmentIds?: string[] | undefined;
30
- }> | import("@github/copilot-sdk").Tool<{
31
- status?: "unread" | "read" | "resolved" | undefined;
32
- }> | import("@github/copilot-sdk").Tool<{
33
- entryId: string;
34
- response: string;
35
- }> | import("@github/copilot-sdk").Tool<{
36
- name: string;
37
- targetType: "orchestrator" | "squad";
38
- cron: string;
39
- prompt: string;
40
- targetId?: string | undefined;
41
- }> | import("@github/copilot-sdk").Tool<{
42
- scheduleId: string;
43
- }> | import("@github/copilot-sdk").Tool<{
44
- scope: "io" | "shared";
45
- pageName?: string | undefined;
46
- }> | import("@github/copilot-sdk").Tool<{
47
- scope: "io" | "shared";
48
- pageName: string;
49
- content: string;
50
- }> | import("@github/copilot-sdk").Tool<{
51
- keyword: string;
52
- }> | import("@github/copilot-sdk").Tool<{
53
- name: string;
54
- url: string;
55
- }> | import("@github/copilot-sdk").Tool<{
56
- skillName: string;
57
- targetType: "orchestrator" | "squad";
58
- targetId?: string | undefined;
59
- }> | import("@github/copilot-sdk").Tool<{
60
- skillName: string;
61
- }> | import("@github/copilot-sdk").Tool<{
62
- kind: "deliverable" | "question" | "note";
63
- title: string;
64
- content: string;
65
- }> | import("@github/copilot-sdk").Tool<{
66
- scope: "io" | "shared";
67
- page: string;
68
- }> | import("@github/copilot-sdk").Tool<{
69
- id: string;
70
- name?: string | undefined;
71
- cron?: string | undefined;
72
- prompt?: string | undefined;
73
- enabled?: boolean | undefined;
74
- }> | import("@github/copilot-sdk").Tool<{
75
- activityType?: string;
76
- squadId?: string;
77
- agentRole?: string;
78
- limit?: number;
79
- }>)[];
80
- //# sourceMappingURL=tools.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/copilot/tools.ts"],"names":[],"mappings":"AAoEA,wBAAgB,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA0lCpB,MAAM;cACX,MAAM;gBACJ,MAAM;YACV,MAAM;MAwBjB"}