@qduc/term2 0.1.2 → 0.1.4

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 (216) hide show
  1. package/dist/agent.d.ts.map +1 -1
  2. package/dist/agent.js +5 -0
  3. package/dist/agent.js.map +1 -1
  4. package/dist/app.d.ts.map +1 -1
  5. package/dist/app.js +3 -1
  6. package/dist/app.js.map +1 -1
  7. package/dist/cli.js +2 -1
  8. package/dist/cli.js.map +1 -1
  9. package/dist/components/ApprovalPrompt.d.ts.map +1 -1
  10. package/dist/components/ApprovalPrompt.js +20 -0
  11. package/dist/components/ApprovalPrompt.js.map +1 -1
  12. package/dist/components/ChatMessage.js +1 -1
  13. package/dist/components/ChatMessage.js.map +1 -1
  14. package/dist/components/InputBox.d.ts.map +1 -1
  15. package/dist/components/InputBox.js +3 -8
  16. package/dist/components/InputBox.js.map +1 -1
  17. package/dist/components/MarkdownRenderer.js +1 -1
  18. package/dist/components/MarkdownRenderer.js.map +1 -1
  19. package/dist/components/ModelSelectionMenu.error-tabs.test.d.ts +2 -0
  20. package/dist/components/ModelSelectionMenu.error-tabs.test.d.ts.map +1 -0
  21. package/dist/components/ModelSelectionMenu.error-tabs.test.js +18 -0
  22. package/dist/components/ModelSelectionMenu.error-tabs.test.js.map +1 -0
  23. package/dist/components/SettingsSelectionMenu.js +1 -1
  24. package/dist/components/SettingsSelectionMenu.js.map +1 -1
  25. package/dist/components/SlashCommandMenu.js +2 -2
  26. package/dist/components/SlashCommandMenu.js.map +1 -1
  27. package/dist/hooks/use-conversation.d.ts.map +1 -1
  28. package/dist/hooks/use-conversation.js +53 -508
  29. package/dist/hooks/use-conversation.js.map +1 -1
  30. package/dist/hooks/use-model-selection.d.ts.map +1 -1
  31. package/dist/hooks/use-model-selection.js +7 -3
  32. package/dist/hooks/use-model-selection.js.map +1 -1
  33. package/dist/hooks/use-settings-completion.d.ts.map +1 -1
  34. package/dist/hooks/use-settings-completion.js +5 -0
  35. package/dist/hooks/use-settings-completion.js.map +1 -1
  36. package/dist/hooks/use-settings-completion.test.js +6 -0
  37. package/dist/hooks/use-settings-completion.test.js.map +1 -1
  38. package/dist/hooks/use-settings-value-completion.d.ts.map +1 -1
  39. package/dist/hooks/use-settings-value-completion.js +1 -0
  40. package/dist/hooks/use-settings-value-completion.js.map +1 -1
  41. package/dist/lib/editor-impl.test.d.ts +2 -0
  42. package/dist/lib/editor-impl.test.d.ts.map +1 -0
  43. package/dist/lib/editor-impl.test.js +188 -0
  44. package/dist/lib/editor-impl.test.js.map +1 -0
  45. package/dist/lib/openai-agent-client.d.ts.map +1 -1
  46. package/dist/lib/openai-agent-client.js +35 -15
  47. package/dist/lib/openai-agent-client.js.map +1 -1
  48. package/dist/lib/openai-agent-client.public-methods.test.d.ts +2 -0
  49. package/dist/lib/openai-agent-client.public-methods.test.d.ts.map +1 -0
  50. package/dist/lib/openai-agent-client.public-methods.test.js +188 -0
  51. package/dist/lib/openai-agent-client.public-methods.test.js.map +1 -0
  52. package/dist/lib/tool-invoke.test.js +1 -1
  53. package/dist/lib/tool-invoke.test.js.map +1 -1
  54. package/dist/providers/github-copilot/converters.d.ts +45 -0
  55. package/dist/providers/github-copilot/converters.d.ts.map +1 -0
  56. package/dist/providers/github-copilot/converters.js +118 -0
  57. package/dist/providers/github-copilot/converters.js.map +1 -0
  58. package/dist/providers/github-copilot/converters.test.d.ts +2 -0
  59. package/dist/providers/github-copilot/converters.test.d.ts.map +1 -0
  60. package/dist/providers/github-copilot/converters.test.js +162 -0
  61. package/dist/providers/github-copilot/converters.test.js.map +1 -0
  62. package/dist/providers/github-copilot/github-copilot.provider.d.ts +2 -0
  63. package/dist/providers/github-copilot/github-copilot.provider.d.ts.map +1 -0
  64. package/dist/providers/github-copilot/github-copilot.provider.js +75 -0
  65. package/dist/providers/github-copilot/github-copilot.provider.js.map +1 -0
  66. package/dist/providers/github-copilot/github-copilot.provider.test.d.ts +2 -0
  67. package/dist/providers/github-copilot/github-copilot.provider.test.d.ts.map +1 -0
  68. package/dist/providers/github-copilot/github-copilot.provider.test.js +26 -0
  69. package/dist/providers/github-copilot/github-copilot.provider.test.js.map +1 -0
  70. package/dist/providers/github-copilot/index.d.ts +4 -0
  71. package/dist/providers/github-copilot/index.d.ts.map +1 -0
  72. package/dist/providers/github-copilot/index.js +4 -0
  73. package/dist/providers/github-copilot/index.js.map +1 -0
  74. package/dist/providers/github-copilot/model-direct.d.ts +34 -0
  75. package/dist/providers/github-copilot/model-direct.d.ts.map +1 -0
  76. package/dist/providers/github-copilot/model-direct.js +443 -0
  77. package/dist/providers/github-copilot/model-direct.js.map +1 -0
  78. package/dist/providers/github-copilot/model.d.ts +24 -0
  79. package/dist/providers/github-copilot/model.d.ts.map +1 -0
  80. package/dist/providers/github-copilot/model.delta.test.d.ts +2 -0
  81. package/dist/providers/github-copilot/model.delta.test.d.ts.map +1 -0
  82. package/dist/providers/github-copilot/model.delta.test.js +15 -0
  83. package/dist/providers/github-copilot/model.delta.test.js.map +1 -0
  84. package/dist/providers/github-copilot/model.js +581 -0
  85. package/dist/providers/github-copilot/model.js.map +1 -0
  86. package/dist/providers/github-copilot/provider.d.ts +20 -0
  87. package/dist/providers/github-copilot/provider.d.ts.map +1 -0
  88. package/dist/providers/github-copilot/provider.js +30 -0
  89. package/dist/providers/github-copilot/provider.js.map +1 -0
  90. package/dist/providers/github-copilot/provider.test.d.ts +2 -0
  91. package/dist/providers/github-copilot/provider.test.d.ts.map +1 -0
  92. package/dist/providers/github-copilot/provider.test.js +52 -0
  93. package/dist/providers/github-copilot/provider.test.js.map +1 -0
  94. package/dist/providers/github-copilot/utils.d.ts +20 -0
  95. package/dist/providers/github-copilot/utils.d.ts.map +1 -0
  96. package/dist/providers/github-copilot/utils.js +142 -0
  97. package/dist/providers/github-copilot/utils.js.map +1 -0
  98. package/dist/providers/github-copilot/utils.test.d.ts +2 -0
  99. package/dist/providers/github-copilot/utils.test.d.ts.map +1 -0
  100. package/dist/providers/github-copilot/utils.test.js +21 -0
  101. package/dist/providers/github-copilot/utils.test.js.map +1 -0
  102. package/dist/providers/openai-compatible/model.d.ts.map +1 -1
  103. package/dist/providers/openai-compatible/model.js +13 -2
  104. package/dist/providers/openai-compatible/model.js.map +1 -1
  105. package/dist/providers/openai-compatible/reasoning-content.test.js +2 -2
  106. package/dist/providers/openai-compatible/reasoning-content.test.js.map +1 -1
  107. package/dist/providers/openrouter/converters.d.ts.map +1 -1
  108. package/dist/providers/openrouter/converters.js +64 -46
  109. package/dist/providers/openrouter/converters.js.map +1 -1
  110. package/dist/providers/openrouter/converters.test.js +13 -12
  111. package/dist/providers/openrouter/converters.test.js.map +1 -1
  112. package/dist/providers/openrouter/merge-messages.test.d.ts +2 -0
  113. package/dist/providers/openrouter/merge-messages.test.d.ts.map +1 -0
  114. package/dist/providers/openrouter/merge-messages.test.js +83 -0
  115. package/dist/providers/openrouter/merge-messages.test.js.map +1 -0
  116. package/dist/providers/openrouter/reasoning-content.test.js +2 -2
  117. package/dist/providers/openrouter/reasoning-content.test.js.map +1 -1
  118. package/dist/providers/openrouter.test.js +30 -21
  119. package/dist/providers/openrouter.test.js.map +1 -1
  120. package/dist/reproduce_issue.test.d.ts +2 -0
  121. package/dist/reproduce_issue.test.d.ts.map +1 -0
  122. package/dist/reproduce_issue.test.js +31 -0
  123. package/dist/reproduce_issue.test.js.map +1 -0
  124. package/dist/services/conversation-store.test.js +12 -11
  125. package/dist/services/conversation-store.test.js.map +1 -1
  126. package/dist/services/settings-service.d.ts +12 -3
  127. package/dist/services/settings-service.d.ts.map +1 -1
  128. package/dist/services/settings-service.js +26 -0
  129. package/dist/services/settings-service.js.map +1 -1
  130. package/dist/tools/ask-mentor.d.ts +1 -1
  131. package/dist/tools/ask-mentor.d.ts.map +1 -1
  132. package/dist/tools/ask-mentor.js +1 -0
  133. package/dist/tools/ask-mentor.js.map +1 -1
  134. package/dist/tools/edit-healing.d.ts +24 -0
  135. package/dist/tools/edit-healing.d.ts.map +1 -0
  136. package/dist/tools/edit-healing.js +230 -0
  137. package/dist/tools/edit-healing.js.map +1 -0
  138. package/dist/tools/edit-healing.test.d.ts +2 -0
  139. package/dist/tools/edit-healing.test.d.ts.map +1 -0
  140. package/dist/tools/edit-healing.test.js +34 -0
  141. package/dist/tools/edit-healing.test.js.map +1 -0
  142. package/dist/tools/find-files.d.ts +2 -2
  143. package/dist/tools/find-files.d.ts.map +1 -1
  144. package/dist/tools/find-files.js +2 -0
  145. package/dist/tools/find-files.js.map +1 -1
  146. package/dist/tools/grep.d.ts +1 -1
  147. package/dist/tools/grep.d.ts.map +1 -1
  148. package/dist/tools/grep.js +1 -0
  149. package/dist/tools/grep.js.map +1 -1
  150. package/dist/tools/read-file.d.ts.map +1 -1
  151. package/dist/tools/read-file.js +10 -9
  152. package/dist/tools/read-file.js.map +1 -1
  153. package/dist/tools/read-file.test.js +24 -19
  154. package/dist/tools/read-file.test.js.map +1 -1
  155. package/dist/tools/search-replace.d.ts +3 -1
  156. package/dist/tools/search-replace.d.ts.map +1 -1
  157. package/dist/tools/search-replace.js +331 -19
  158. package/dist/tools/search-replace.js.map +1 -1
  159. package/dist/tools/search-replace.test.js +241 -2
  160. package/dist/tools/search-replace.test.js.map +1 -1
  161. package/dist/tools/search.d.ts +4 -4
  162. package/dist/tools/search.d.ts.map +1 -1
  163. package/dist/tools/search.js +4 -0
  164. package/dist/tools/search.js.map +1 -1
  165. package/dist/tools/shell.d.ts +2 -2
  166. package/dist/tools/shell.d.ts.map +1 -1
  167. package/dist/tools/shell.js +2 -0
  168. package/dist/tools/shell.js.map +1 -1
  169. package/dist/tools/types.d.ts +2 -2
  170. package/dist/tools/types.d.ts.map +1 -1
  171. package/dist/tools/web-fetch.d.ts +20 -0
  172. package/dist/tools/web-fetch.d.ts.map +1 -0
  173. package/dist/tools/web-fetch.js +300 -0
  174. package/dist/tools/web-fetch.js.map +1 -0
  175. package/dist/tools/web-fetch.test.d.ts +2 -0
  176. package/dist/tools/web-fetch.test.d.ts.map +1 -0
  177. package/dist/tools/web-fetch.test.js +94 -0
  178. package/dist/tools/web-fetch.test.js.map +1 -0
  179. package/dist/utils/command-safety/index.d.ts +2 -2
  180. package/dist/utils/command-safety/index.d.ts.map +1 -1
  181. package/dist/utils/command-safety/index.js +7 -6
  182. package/dist/utils/command-safety/index.js.map +1 -1
  183. package/dist/utils/command-safety.find.test.js +19 -21
  184. package/dist/utils/command-safety.find.test.js.map +1 -1
  185. package/dist/utils/conversation-event-handler.d.ts +63 -0
  186. package/dist/utils/conversation-event-handler.d.ts.map +1 -0
  187. package/dist/utils/conversation-event-handler.js +132 -0
  188. package/dist/utils/conversation-event-handler.js.map +1 -0
  189. package/dist/utils/conversation-event-handler.test.d.ts +2 -0
  190. package/dist/utils/conversation-event-handler.test.d.ts.map +1 -0
  191. package/dist/utils/conversation-event-handler.test.js +281 -0
  192. package/dist/utils/conversation-event-handler.test.js.map +1 -0
  193. package/dist/utils/conversation-utils.d.ts +41 -0
  194. package/dist/utils/conversation-utils.d.ts.map +1 -0
  195. package/dist/utils/conversation-utils.js +109 -0
  196. package/dist/utils/conversation-utils.js.map +1 -0
  197. package/dist/utils/conversation-utils.test.d.ts +2 -0
  198. package/dist/utils/conversation-utils.test.d.ts.map +1 -0
  199. package/dist/utils/conversation-utils.test.js +190 -0
  200. package/dist/utils/conversation-utils.test.js.map +1 -0
  201. package/dist/utils/ink-render-options.d.ts +9 -0
  202. package/dist/utils/ink-render-options.d.ts.map +1 -0
  203. package/dist/utils/ink-render-options.js +8 -0
  204. package/dist/utils/ink-render-options.js.map +1 -0
  205. package/dist/utils/message-utils.d.ts +17 -0
  206. package/dist/utils/message-utils.d.ts.map +1 -0
  207. package/dist/utils/message-utils.js +52 -0
  208. package/dist/utils/message-utils.js.map +1 -0
  209. package/dist/utils/message-utils.test.d.ts +2 -0
  210. package/dist/utils/message-utils.test.d.ts.map +1 -0
  211. package/dist/utils/message-utils.test.js +48 -0
  212. package/dist/utils/message-utils.test.js.map +1 -0
  213. package/dist/utils/settings-command.d.ts.map +1 -1
  214. package/dist/utils/settings-command.js +13 -4
  215. package/dist/utils/settings-command.js.map +1 -1
  216. package/package.json +10 -4
@@ -0,0 +1,581 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { CopilotClient } from '@github/copilot-sdk';
5
+ // Load simple.md system prompt (same as other providers)
6
+ const SIMPLE_PROMPT_PATH = path.join(import.meta.dirname, '../../prompts/simple.md');
7
+ const SIMPLE_PROMPT = fs.readFileSync(SIMPLE_PROMPT_PATH, 'utf-8').trim();
8
+ import { buildMessagesFromRequest, extractFunctionToolsFromRequest, normalizeUsage, } from './converters.js';
9
+ // Global map to store pending tool resolutions: SessionID -> CallID -> ResolveFunction
10
+ // This allows us to "detach" the tool execution from the SDK's internal loop
11
+ // and hand it over to the Agent Runner, then resume it later.
12
+ const pendingResolutions = new Map();
13
+ // Singleton client - SDK manages CLI process lifecycle
14
+ export let sharedClient = null;
15
+ export async function getClient() {
16
+ if (!sharedClient) {
17
+ sharedClient = new CopilotClient();
18
+ await sharedClient.start();
19
+ }
20
+ return sharedClient;
21
+ }
22
+ export function extractCopilotTextDelta(accumulated, incoming) {
23
+ if (!incoming)
24
+ return '';
25
+ if (!accumulated)
26
+ return incoming;
27
+ // 1. If incoming starts with accumulated, it's definitely an accumulation
28
+ if (incoming.startsWith(accumulated)) {
29
+ return incoming.slice(accumulated.length);
30
+ }
31
+ // 2. Check for overlap: find the longest suffix of 'accumulated' that is a prefix of 'incoming'
32
+ // We only check up to a reasonable length to avoid O(N^2) on very long outputs,
33
+ // though usually deltas are small.
34
+ const maxOverlap = Math.min(accumulated.length, incoming.length);
35
+ for (let len = maxOverlap; len > 0; len--) {
36
+ const suffix = accumulated.slice(-len);
37
+ const prefix = incoming.slice(0, len);
38
+ if (suffix === prefix) {
39
+ return incoming.slice(len);
40
+ }
41
+ }
42
+ // 3. No overlap found, treat as a pure delta
43
+ return incoming;
44
+ }
45
+ /**
46
+ * Force stop the shared client (for cleanup/error recovery)
47
+ */
48
+ export async function forceStopClient() {
49
+ if (sharedClient) {
50
+ try {
51
+ await sharedClient.forceStop();
52
+ }
53
+ catch {
54
+ // Ignore errors during cleanup
55
+ }
56
+ sharedClient = null;
57
+ }
58
+ }
59
+ export class GitHubCopilotModel {
60
+ name;
61
+ #modelId;
62
+ #settingsService;
63
+ #loggingService;
64
+ #sessionMap;
65
+ #activeSessions;
66
+ constructor(deps) {
67
+ this.name = 'GitHubCopilot';
68
+ this.#settingsService = deps.settingsService;
69
+ this.#loggingService = deps.loggingService;
70
+ this.#sessionMap = deps.sessionMap || new Map();
71
+ this.#activeSessions = deps.activeSessions || new Map();
72
+ this.#modelId =
73
+ deps.modelId ||
74
+ this.#settingsService.get('agent.github-copilot.model') ||
75
+ this.#settingsService.get('agent.model') ||
76
+ 'gpt-4o';
77
+ }
78
+ async getResponse(request) {
79
+ // For non-streaming requests, collect all events and build response
80
+ const events = [];
81
+ for await (const event of this.getStreamedResponse(request)) {
82
+ events.push(event);
83
+ }
84
+ // Find the response_done event
85
+ const doneEvent = events.find((e) => e.type === 'response_done');
86
+ if (doneEvent?.response) {
87
+ return {
88
+ responseId: doneEvent.response.id || randomUUID(),
89
+ output: doneEvent.response.output || [],
90
+ usage: normalizeUsage(doneEvent.response.usage),
91
+ };
92
+ }
93
+ // Fallback: build response from accumulated events
94
+ const textDeltas = events
95
+ .filter((e) => e.type === 'output_text_delta')
96
+ .map((e) => e.delta)
97
+ .join('');
98
+ return {
99
+ responseId: randomUUID(),
100
+ output: textDeltas ? [{
101
+ type: 'message',
102
+ role: 'assistant',
103
+ status: 'completed',
104
+ content: [{ type: 'output_text', text: textDeltas }],
105
+ }] : [],
106
+ usage: normalizeUsage({}),
107
+ };
108
+ }
109
+ async *getStreamedResponse(request) {
110
+ const client = await getClient();
111
+ const resolvedModelId = this.#resolveModelFromRequest(request) || this.#modelId;
112
+ const messages = buildMessagesFromRequest(request, resolvedModelId, this.#loggingService);
113
+ this.#loggingService.debug('GitHubCopilot stream start', {
114
+ messageCount: messages.length,
115
+ modelId: resolvedModelId,
116
+ previousResponseId: request.previousResponseId || request.providerData?.previousResponseId,
117
+ });
118
+ const tools = extractFunctionToolsFromRequest(request);
119
+ // Wrap tools with the "Trap" handler that suspends execution
120
+ const copilotTools = tools.map((t) => ({
121
+ name: t.function.name,
122
+ description: t.function.description,
123
+ parameters: t.function.parameters,
124
+ handler: async (_args, invocation) => {
125
+ this.#loggingService.debug('Copilot tool trap activated', {
126
+ tool: invocation.toolName,
127
+ callId: invocation.toolCallId,
128
+ });
129
+ return new Promise((resolve) => {
130
+ if (!pendingResolutions.has(invocation.sessionId)) {
131
+ pendingResolutions.set(invocation.sessionId, new Map());
132
+ }
133
+ pendingResolutions.get(invocation.sessionId).set(invocation.toolCallId, resolve);
134
+ });
135
+ },
136
+ }));
137
+ let session;
138
+ let hasPendingToolResolutions = false;
139
+ try {
140
+ // Check both the standard request field and our custom providerData fallback
141
+ const prevResponseId = request.previousResponseId || request.providerData?.previousResponseId;
142
+ const prevSessionId = prevResponseId
143
+ ? this.#sessionMap.get(prevResponseId)
144
+ : undefined;
145
+ // Check if there are pending tool resolutions for this session BEFORE we decide on re-registration
146
+ // This is critical: if we're resuming a suspended tool, we MUST NOT re-register handlers
147
+ // because the SDK is waiting on the original handler's promise
148
+ if (prevSessionId) {
149
+ const existingResolutions = pendingResolutions.get(prevSessionId);
150
+ hasPendingToolResolutions = existingResolutions ? existingResolutions.size > 0 : false;
151
+ this.#loggingService.debug('Checking pending tool resolutions before session setup', {
152
+ prevSessionId,
153
+ hasPendingToolResolutions,
154
+ pendingCallIds: existingResolutions ? Array.from(existingResolutions.keys()) : [],
155
+ });
156
+ }
157
+ // First, try to get a cached session object
158
+ const cachedSession = prevSessionId
159
+ ? this.#activeSessions.get(prevSessionId)
160
+ : undefined;
161
+ if (cachedSession) {
162
+ // Reuse the cached session
163
+ this.#loggingService.debug('Reusing cached GitHubCopilot session', {
164
+ sessionId: prevSessionId,
165
+ hasPendingToolResolutions,
166
+ });
167
+ session = cachedSession;
168
+ // CRITICAL: Only re-register tools if there are NO pending resolutions
169
+ // If there ARE pending resolutions, the SDK is waiting on the original handlers' promises
170
+ // Re-registering would create new handlers and break the promise chain
171
+ if (!hasPendingToolResolutions) {
172
+ this.#loggingService.debug('Re-registering tools for new turn (no pending resolutions)');
173
+ session.registerTools(copilotTools);
174
+ }
175
+ else {
176
+ this.#loggingService.debug('Skipping tool re-registration (pending resolutions exist)');
177
+ }
178
+ }
179
+ else if (prevSessionId) {
180
+ // Session ID exists but no cached object - need to resume from server
181
+ // IMPORTANT: If there are pending resolutions but no cached session,
182
+ // those promises are orphaned (the original session object is gone).
183
+ // We must clear them and proceed fresh.
184
+ if (hasPendingToolResolutions) {
185
+ this.#loggingService.warn('Orphaned pending resolutions detected (cached session gone)', {
186
+ sessionId: prevSessionId,
187
+ pendingCallIds: Array.from(pendingResolutions.get(prevSessionId)?.keys() || []),
188
+ });
189
+ pendingResolutions.delete(prevSessionId);
190
+ hasPendingToolResolutions = false;
191
+ }
192
+ this.#loggingService.debug('Resuming GitHubCopilot session from server', {
193
+ sessionId: prevSessionId,
194
+ });
195
+ session = await client.resumeSession(prevSessionId, {
196
+ streaming: true,
197
+ tools: copilotTools,
198
+ });
199
+ // Cache the resumed session for future turns
200
+ this.#activeSessions.set(session.sessionId, session);
201
+ }
202
+ else {
203
+ // No previous session - create a new one
204
+ this.#loggingService.debug('Creating new GitHubCopilot session');
205
+ session = await client.createSession({
206
+ model: resolvedModelId,
207
+ streaming: true,
208
+ tools: copilotTools,
209
+ availableTools: copilotTools.map((t) => t.name),
210
+ systemMessage: {
211
+ mode: 'replace',
212
+ content: SIMPLE_PROMPT,
213
+ },
214
+ });
215
+ // Cache the new session for future turns
216
+ this.#activeSessions.set(session.sessionId, session);
217
+ }
218
+ }
219
+ catch (err) {
220
+ this.#loggingService.error('GitHubCopilot session creation/resumption failed', {
221
+ error: err.message,
222
+ });
223
+ // Emit error as a model event since ResponseStreamEvent doesn't have error type
224
+ yield {
225
+ type: 'model',
226
+ event: { type: 'error', message: `Failed to create/resume Copilot session: ${err.message}` },
227
+ };
228
+ return;
229
+ }
230
+ const state = {
231
+ accumulated: '',
232
+ accumulatedReasoningText: '',
233
+ accumulatedToolCalls: [],
234
+ responseId: randomUUID(),
235
+ usageData: null,
236
+ };
237
+ // Track new sessionId for future resumption
238
+ this.#sessionMap.set(state.responseId, session.sessionId);
239
+ // Set up event handlers and collect events via async iteration
240
+ const eventQueue = [];
241
+ let resolveNext = null;
242
+ let done = false;
243
+ let error = null;
244
+ const pushEvent = (event) => {
245
+ if (resolveNext) {
246
+ resolveNext({ value: event, done: false });
247
+ resolveNext = null;
248
+ }
249
+ else {
250
+ eventQueue.push(event);
251
+ }
252
+ };
253
+ // Track unsubscribe function for cleanup
254
+ let unsubscribeEvents = null;
255
+ const finish = (err) => {
256
+ done = true;
257
+ error = err || null;
258
+ // Unsubscribe from events to prevent handler accumulation
259
+ if (unsubscribeEvents) {
260
+ unsubscribeEvents();
261
+ unsubscribeEvents = null;
262
+ }
263
+ // If there was an error, remove session from cache so a fresh one is created next time
264
+ if (err && session) {
265
+ this.#activeSessions.delete(session.sessionId);
266
+ }
267
+ if (resolveNext) {
268
+ if (err) {
269
+ resolveNext = null;
270
+ throw err;
271
+ }
272
+ resolveNext({ value: undefined, done: true });
273
+ resolveNext = null;
274
+ }
275
+ };
276
+ // Register event handlers on the session (returns unsubscribe function)
277
+ unsubscribeEvents = session.on(async (event) => {
278
+ try {
279
+ switch (event.type) {
280
+ case 'assistant.message_delta':
281
+ // Streaming text chunk
282
+ if (event.data?.deltaContent) {
283
+ const delta = extractCopilotTextDelta(state.accumulated, event.data.deltaContent);
284
+ if (delta) {
285
+ state.accumulated += delta;
286
+ pushEvent({
287
+ type: 'output_text_delta',
288
+ delta,
289
+ });
290
+ }
291
+ }
292
+ break;
293
+ case 'assistant.reasoning_delta':
294
+ // Streaming reasoning (O1/O3 models)
295
+ if (event.data?.deltaContent) {
296
+ state.accumulatedReasoningText += event.data.deltaContent;
297
+ // Emit as model event for reasoning channel
298
+ pushEvent({
299
+ type: 'model',
300
+ event: {
301
+ type: 'reasoning_delta',
302
+ content: event.data.deltaContent,
303
+ },
304
+ });
305
+ }
306
+ break;
307
+ case 'tool.execution_start':
308
+ // Tool call requested
309
+ if (event.data) {
310
+ this.#loggingService.debug('GitHubCopilot tool.execution_start', {
311
+ data: event.data,
312
+ });
313
+ const toolName = event.data.toolName;
314
+ if (!toolName) {
315
+ this.#loggingService.error('GitHubCopilot tool execution missing name', { data: event.data });
316
+ break;
317
+ }
318
+ const rawArgs = event.data.arguments || event.data.args || {};
319
+ const argsString = typeof rawArgs === 'string'
320
+ ? rawArgs
321
+ : JSON.stringify(rawArgs);
322
+ const toolCall = {
323
+ type: 'function_call',
324
+ callId: event.data.toolCallId || event.data.callId || randomUUID(),
325
+ name: toolName,
326
+ arguments: argsString,
327
+ };
328
+ state.accumulatedToolCalls.push(toolCall);
329
+ // Check if this is a user tool that requires external handling
330
+ // We look it up in our 'copilotTools' list
331
+ const isUserTool = copilotTools.some((t) => t.name === toolName);
332
+ if (isUserTool) {
333
+ this.#loggingService.debug('Detaching stream for user tool execution', {
334
+ tool: toolName,
335
+ callId: toolCall.callId,
336
+ });
337
+ // Yield the function call event to the Runner (streaming)
338
+ pushEvent({
339
+ type: 'model',
340
+ event: {
341
+ type: 'function_call',
342
+ callId: toolCall.callId,
343
+ name: toolCall.name,
344
+ arguments: toolCall.arguments,
345
+ }
346
+ });
347
+ // WAIT FOR TRAP: Ensure the SDK handler has actually run and registered the promise
348
+ // This prevents a race condition where the next turn starts before the trap is set.
349
+ // We poll for up to 1 second.
350
+ let attempts = 0;
351
+ const maxAttempts = 20;
352
+ while (attempts < maxAttempts) {
353
+ const sessionPending = pendingResolutions.get(session.sessionId);
354
+ if (sessionPending && sessionPending.has(toolCall.callId)) {
355
+ this.#loggingService.debug('Trap confirmed: pending resolution registered', {
356
+ callId: toolCall.callId,
357
+ attempts
358
+ });
359
+ break;
360
+ }
361
+ await new Promise(r => setTimeout(r, 50));
362
+ attempts++;
363
+ }
364
+ if (attempts >= maxAttempts) {
365
+ this.#loggingService.error('Trap timeout: Handler did not register promise in time', {
366
+ callId: toolCall.callId
367
+ });
368
+ }
369
+ // IMPORTANT: Emit response_done so the Runner captures the responseId.
370
+ // This allows the next turn to pass 'previousResponseId' correctly,
371
+ // which we need to look up the session and resume the suspended tool.
372
+ const output = this.#buildStreamOutput(state);
373
+ pushEvent({
374
+ type: 'response_done',
375
+ response: {
376
+ id: state.responseId,
377
+ usage: normalizeUsage(state.usageData),
378
+ output,
379
+ },
380
+ });
381
+ // SIGNAL COMPLETION OF THIS STREAM SEGMENT
382
+ finish();
383
+ return; // Stop processing further events in this loop
384
+ }
385
+ // If it's an internal tool (like report_intent), we just let it run
386
+ // The SDK will call the internal handler, get the result, and continue streaming
387
+ // We don't emit anything to the Runner yet.
388
+ }
389
+ break;
390
+ case 'session.usage':
391
+ // Usage data
392
+ if (event.data) {
393
+ state.usageData = event.data;
394
+ }
395
+ break;
396
+ case 'session.idle':
397
+ // Session complete - emit response_done
398
+ this.#loggingService.debug('GitHubCopilot stream done', {
399
+ text: state.accumulated,
400
+ toolCalls: state.accumulatedToolCalls.length,
401
+ });
402
+ const output = this.#buildStreamOutput(state);
403
+ pushEvent({
404
+ type: 'response_done',
405
+ response: {
406
+ id: state.responseId,
407
+ usage: normalizeUsage(state.usageData),
408
+ output,
409
+ },
410
+ });
411
+ finish();
412
+ break;
413
+ case 'session.error':
414
+ // Handle errors
415
+ this.#loggingService.error('GitHubCopilot session error', {
416
+ error: event.data?.message,
417
+ });
418
+ // Emit error as a model event since ResponseStreamEvent doesn't have error type
419
+ pushEvent({
420
+ type: 'model',
421
+ event: { type: 'error', message: event.data?.message || 'Unknown error' },
422
+ });
423
+ finish(new Error(event.data?.message || 'Session error'));
424
+ break;
425
+ }
426
+ }
427
+ catch (err) {
428
+ this.#loggingService.error('GitHubCopilot event processing error', {
429
+ error: err.message,
430
+ eventType: event.type,
431
+ });
432
+ }
433
+ });
434
+ // Send the messages to start the conversation
435
+ // Check if we are in "Resume/Tool Output" mode
436
+ const sessionResolutions = pendingResolutions.get(session.sessionId);
437
+ let isResumingTool = false;
438
+ if (sessionResolutions && sessionResolutions.size > 0) {
439
+ this.#loggingService.debug('Attempting to resolve suspended tool calls', {
440
+ sessionId: session.sessionId,
441
+ pendingCallIds: Array.from(sessionResolutions.keys()),
442
+ inputItemCount: Array.isArray(request.input) ? request.input.length : 0,
443
+ });
444
+ // Look for tool outputs in the request input that match pending traps
445
+ // The Runner appends the output to the history
446
+ if (request.input && Array.isArray(request.input)) {
447
+ for (const item of request.input) {
448
+ // Check for function_call_output type (mapped from SDK)
449
+ if (item.type === 'function_call_output') {
450
+ const callId = item.callId;
451
+ const hasPending = callId && sessionResolutions.has(callId);
452
+ this.#loggingService.debug('Checking input item for tool resolution', {
453
+ type: item.type,
454
+ callId,
455
+ hasPending,
456
+ });
457
+ if (hasPending) {
458
+ const output = item.output;
459
+ this.#loggingService.debug('Resolving suspended tool call', {
460
+ callId,
461
+ outputLength: output?.length,
462
+ outputPreview: typeof output === 'string' ? output.slice(0, 50) : 'obj',
463
+ });
464
+ const resolve = sessionResolutions.get(callId);
465
+ resolve(output); // UNBLOCK the SDK handler!
466
+ sessionResolutions.delete(callId);
467
+ isResumingTool = true;
468
+ }
469
+ }
470
+ }
471
+ }
472
+ }
473
+ else {
474
+ this.#loggingService.debug('No pending tool resolutions for this session', {
475
+ sessionId: session.sessionId,
476
+ });
477
+ }
478
+ // Only send a new prompt if we are NOT resuming a tool call
479
+ if (!isResumingTool) {
480
+ try {
481
+ // Build the prompt from the last user message
482
+ const lastUserMessage = messages.filter(m => m.role === 'user').pop();
483
+ const prompt = lastUserMessage?.content || '';
484
+ if (prompt) {
485
+ await session.send({
486
+ prompt,
487
+ });
488
+ }
489
+ else {
490
+ // If no prompt and no tool resume, we might assume it's just a continue?
491
+ // Or maybe we should send an empty space to trigger generation?
492
+ // For now, assume if prompt is empty it might be an issue, but let's try sending it.
493
+ // Actually Copilot SDK might error on empty prompt.
494
+ }
495
+ }
496
+ catch (err) {
497
+ this.#loggingService.error('GitHubCopilot send failed', {
498
+ error: err.message,
499
+ });
500
+ yield {
501
+ type: 'model',
502
+ event: { type: 'error', message: `Failed to send message: ${err.message}` },
503
+ };
504
+ try {
505
+ await session.abort();
506
+ }
507
+ catch {
508
+ // Ignore abort errors
509
+ }
510
+ // Clean up event handler before returning
511
+ if (unsubscribeEvents) {
512
+ unsubscribeEvents();
513
+ unsubscribeEvents = null;
514
+ }
515
+ // Remove session from cache on error
516
+ this.#activeSessions.delete(session.sessionId);
517
+ return;
518
+ }
519
+ }
520
+ // If isResumingTool is true, we simply let the event loop below capture the continuation events!
521
+ // Yield events as they come in
522
+ while (!done || eventQueue.length > 0) {
523
+ if (eventQueue.length > 0) {
524
+ yield eventQueue.shift();
525
+ }
526
+ else if (!done) {
527
+ // Wait for next event
528
+ yield await new Promise((resolve) => {
529
+ resolveNext = (result) => {
530
+ if (result.done) {
531
+ // Signal completion
532
+ resolve({ type: 'model', event: '[DONE]' });
533
+ }
534
+ else {
535
+ resolve(result.value);
536
+ }
537
+ };
538
+ });
539
+ }
540
+ }
541
+ if (error) {
542
+ throw error;
543
+ }
544
+ }
545
+ #buildStreamOutput(state) {
546
+ const output = [];
547
+ // Add assistant message if there's text content
548
+ if (state.accumulated) {
549
+ output.push({
550
+ type: 'message',
551
+ role: 'assistant',
552
+ status: 'completed',
553
+ content: [{ type: 'output_text', text: state.accumulated }],
554
+ ...(state.accumulatedReasoningText
555
+ ? { reasoning: state.accumulatedReasoningText }
556
+ : {}),
557
+ });
558
+ }
559
+ // Add tool calls as separate output items
560
+ for (const toolCall of state.accumulatedToolCalls) {
561
+ output.push({
562
+ type: 'function_call',
563
+ callId: toolCall.callId,
564
+ name: toolCall.name,
565
+ arguments: toolCall.arguments,
566
+ status: 'completed',
567
+ ...(state.accumulatedReasoningText
568
+ ? { reasoning: state.accumulatedReasoningText }
569
+ : {}),
570
+ });
571
+ }
572
+ return output;
573
+ }
574
+ #resolveModelFromRequest(req) {
575
+ if (req?.providerData?.model) {
576
+ return req.providerData.model;
577
+ }
578
+ return undefined;
579
+ }
580
+ }
581
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../../source/providers/github-copilot/model.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAuB,MAAM,qBAAqB,CAAC;AAEzE,yDAAyD;AACzD,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,yBAAyB,CAAC,CAAC;AACrF,MAAM,aAAa,GAAG,EAAE,CAAC,YAAY,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;AAK1E,OAAO,EACH,wBAAwB,EACxB,+BAA+B,EAC/B,cAAc,GACjB,MAAM,iBAAiB,CAAC;AAEzB,uFAAuF;AACvF,6EAA6E;AAC7E,8DAA8D;AAC9D,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAA8C,CAAC;AAEjF,uDAAuD;AACvD,MAAM,CAAC,IAAI,YAAY,GAAyB,IAAI,CAAC;AAErD,MAAM,CAAC,KAAK,UAAU,SAAS;IAC3B,IAAI,CAAC,YAAY,EAAE,CAAC;QAChB,YAAY,GAAG,IAAI,aAAa,EAAE,CAAC;QACnC,MAAM,YAAY,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IACD,OAAO,YAAY,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,WAAmB,EAAE,QAAgB;IACzE,IAAI,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AAQ,CAAC,IAAI;gBACnB,SAAS,EAAE,QAAQ,CAAC,SAAS;gBAC7B,MAAM,EAAE,WAAW;gBACnB,GAAG,CAAC,KAAK,CAAC,wBAAwB;oBAC9B,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,wBAAwB,EAAE;oBAC/C,CAAC,CAAC,EAAE,CAAC;aACZ,CAAC,CAAC;QACP,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,wBAAwB,CAAC,GAAiB;QACtC,IAAK,GAAW,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;YACpC,OAAQ,GAAW,CAAC,YAAY,CAAC,KAAK,CAAC;QAC3C,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ"}
@@ -0,0 +1,20 @@
1
+ import { type ModelProvider, type Model } from '@openai/agents-core';
2
+ import type { ILoggingService, ISettingsService } from '../../services/service-interfaces.js';
3
+ /**
4
+ * GitHubCopilotProvider - Uses the Direct model that lets Copilot SDK
5
+ * control tool execution flow without trying to integrate with
6
+ * OpenAI Agents SDK's approval pattern.
7
+ */
8
+ export declare class GitHubCopilotProvider implements ModelProvider {
9
+ #private;
10
+ constructor(deps: {
11
+ settingsService: ISettingsService;
12
+ loggingService: ILoggingService;
13
+ });
14
+ getModel(modelName?: string): Promise<Model> | Model;
15
+ }
16
+ export declare function createGitHubCopilotProvider(deps: {
17
+ settingsService: ISettingsService;
18
+ loggingService: ILoggingService;
19
+ }): GitHubCopilotProvider;
20
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../source/providers/github-copilot/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAErE,OAAO,KAAK,EACR,eAAe,EACf,gBAAgB,EACnB,MAAM,sCAAsC,CAAC;AAG9C;;;;GAIG;AACH,qBAAa,qBAAsB,YAAW,aAAa;;gBAM3C,IAAI,EAAE;QACd,eAAe,EAAE,gBAAgB,CAAC;QAClC,cAAc,EAAE,eAAe,CAAC;KACnC;IAKD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK;CASvD;AAGD,wBAAgB,2BAA2B,CAAC,IAAI,EAAE;IAC9C,eAAe,EAAE,gBAAgB,CAAC;IAClC,cAAc,EAAE,eAAe,CAAC;CACnC,GAAG,qBAAqB,CAExB"}
@@ -0,0 +1,30 @@
1
+ import { GitHubCopilotDirectModel } from './model-direct.js';
2
+ /**
3
+ * GitHubCopilotProvider - Uses the Direct model that lets Copilot SDK
4
+ * control tool execution flow without trying to integrate with
5
+ * OpenAI Agents SDK's approval pattern.
6
+ */
7
+ export class GitHubCopilotProvider {
8
+ #settingsService;
9
+ #loggingService;
10
+ #sessionMap = new Map(); // Mapping of responseId -> sessionId
11
+ #activeSessions = new Map(); // Cache of sessionId -> actual session object
12
+ constructor(deps) {
13
+ this.#settingsService = deps.settingsService;
14
+ this.#loggingService = deps.loggingService;
15
+ }
16
+ getModel(modelName) {
17
+ return new GitHubCopilotDirectModel({
18
+ settingsService: this.#settingsService,
19
+ loggingService: this.#loggingService,
20
+ modelId: modelName,
21
+ sessionMap: this.#sessionMap,
22
+ activeSessions: this.#activeSessions,
23
+ });
24
+ }
25
+ }
26
+ // Export factory function for dependency injection
27
+ export function createGitHubCopilotProvider(deps) {
28
+ return new GitHubCopilotProvider(deps);
29
+ }
30
+ //# sourceMappingURL=provider.js.map