qlogicagent 0.2.1 → 0.4.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 (226) hide show
  1. package/README.md +45 -45
  2. package/package.json +56 -42
  3. package/dist/agent/agent.d.ts +0 -43
  4. package/dist/agent/agent.js +0 -113
  5. package/dist/agent/tool-loop.d.ts +0 -64
  6. package/dist/agent/tool-loop.js +0 -575
  7. package/dist/agent/types.d.ts +0 -175
  8. package/dist/agent/types.js +0 -14
  9. package/dist/cli/main.d.ts +0 -11
  10. package/dist/cli/main.js +0 -23
  11. package/dist/cli/stdio-server.d.ts +0 -45
  12. package/dist/cli/stdio-server.js +0 -463
  13. package/dist/config/config.d.ts +0 -17
  14. package/dist/config/config.js +0 -21
  15. package/dist/contracts/hooks.d.ts +0 -120
  16. package/dist/contracts/hooks.js +0 -7
  17. package/dist/contracts/index.d.ts +0 -10
  18. package/dist/contracts/index.js +0 -10
  19. package/dist/contracts/planner.d.ts +0 -35
  20. package/dist/contracts/planner.js +0 -2
  21. package/dist/contracts/skill-candidate.d.ts +0 -63
  22. package/dist/contracts/skill-candidate.js +0 -195
  23. package/dist/contracts/todo.d.ts +0 -14
  24. package/dist/contracts/todo.js +0 -9
  25. package/dist/index.d.ts +0 -13
  26. package/dist/index.js +0 -15
  27. package/dist/llm/builtin-providers.d.ts +0 -10
  28. package/dist/llm/builtin-providers.js +0 -531
  29. package/dist/llm/index.d.ts +0 -15
  30. package/dist/llm/index.js +0 -14
  31. package/dist/llm/llm-client.d.ts +0 -43
  32. package/dist/llm/llm-client.js +0 -67
  33. package/dist/llm/model-catalog.d.ts +0 -53
  34. package/dist/llm/model-catalog.js +0 -191
  35. package/dist/llm/provider-def.d.ts +0 -59
  36. package/dist/llm/provider-def.js +0 -12
  37. package/dist/llm/provider-registry.d.ts +0 -54
  38. package/dist/llm/provider-registry.js +0 -147
  39. package/dist/llm/transport.d.ts +0 -62
  40. package/dist/llm/transport.js +0 -27
  41. package/dist/llm/transports/anthropic-messages.d.ts +0 -31
  42. package/dist/llm/transports/anthropic-messages.js +0 -293
  43. package/dist/llm/transports/openai-chat.d.ts +0 -36
  44. package/dist/llm/transports/openai-chat.js +0 -165
  45. package/dist/orchestration/agent-registry.d.ts +0 -41
  46. package/dist/orchestration/agent-registry.js +0 -116
  47. package/dist/orchestration/approval-aware-tool-plan.d.ts +0 -32
  48. package/dist/orchestration/approval-aware-tool-plan.js +0 -87
  49. package/dist/orchestration/context-compression.d.ts +0 -220
  50. package/dist/orchestration/context-compression.js +0 -583
  51. package/dist/orchestration/conversation-repair.d.ts +0 -61
  52. package/dist/orchestration/conversation-repair.js +0 -429
  53. package/dist/orchestration/curator-scheduler.d.ts +0 -119
  54. package/dist/orchestration/curator-scheduler.js +0 -135
  55. package/dist/orchestration/embedded-failover-policy.d.ts +0 -110
  56. package/dist/orchestration/embedded-failover-policy.js +0 -168
  57. package/dist/orchestration/error-classification.d.ts +0 -12
  58. package/dist/orchestration/error-classification.js +0 -77
  59. package/dist/orchestration/failover-classification.d.ts +0 -8
  60. package/dist/orchestration/failover-classification.js +0 -381
  61. package/dist/orchestration/failover-error.d.ts +0 -33
  62. package/dist/orchestration/failover-error.js +0 -198
  63. package/dist/orchestration/fork-subagent.d.ts +0 -100
  64. package/dist/orchestration/fork-subagent.js +0 -98
  65. package/dist/orchestration/index.d.ts +0 -120
  66. package/dist/orchestration/index.js +0 -267
  67. package/dist/orchestration/memory-flush-policy.d.ts +0 -57
  68. package/dist/orchestration/memory-flush-policy.js +0 -85
  69. package/dist/orchestration/memory-provider.d.ts +0 -14
  70. package/dist/orchestration/memory-provider.js +0 -2
  71. package/dist/orchestration/parallel-tool-calls.d.ts +0 -41
  72. package/dist/orchestration/parallel-tool-calls.js +0 -59
  73. package/dist/orchestration/prompt-cache-strategy.d.ts +0 -126
  74. package/dist/orchestration/prompt-cache-strategy.js +0 -228
  75. package/dist/orchestration/reactive-compact.d.ts +0 -73
  76. package/dist/orchestration/reactive-compact.js +0 -78
  77. package/dist/orchestration/retry-loop.d.ts +0 -22
  78. package/dist/orchestration/retry-loop.js +0 -24
  79. package/dist/orchestration/skill-candidate.d.ts +0 -52
  80. package/dist/orchestration/skill-candidate.js +0 -141
  81. package/dist/orchestration/skill-consolidation.d.ts +0 -123
  82. package/dist/orchestration/skill-consolidation.js +0 -220
  83. package/dist/orchestration/skill-improvement.d.ts +0 -59
  84. package/dist/orchestration/skill-improvement.js +0 -66
  85. package/dist/orchestration/skill-similarity.d.ts +0 -98
  86. package/dist/orchestration/skill-similarity.js +0 -131
  87. package/dist/orchestration/streaming-tool-executor.d.ts +0 -73
  88. package/dist/orchestration/streaming-tool-executor.js +0 -96
  89. package/dist/orchestration/team-orchestration.d.ts +0 -195
  90. package/dist/orchestration/team-orchestration.js +0 -369
  91. package/dist/orchestration/team-tool-loop-wiring.d.ts +0 -92
  92. package/dist/orchestration/team-tool-loop-wiring.js +0 -147
  93. package/dist/orchestration/tool-choice-policy.d.ts +0 -54
  94. package/dist/orchestration/tool-choice-policy.js +0 -164
  95. package/dist/orchestration/tool-loop-state.d.ts +0 -50
  96. package/dist/orchestration/tool-loop-state.js +0 -133
  97. package/dist/orchestration/tool-schema.d.ts +0 -39
  98. package/dist/orchestration/tool-schema.js +0 -297
  99. package/dist/orchestration/transcript-repair.d.ts +0 -42
  100. package/dist/orchestration/transcript-repair.js +0 -426
  101. package/dist/orchestration/turn-loop-guard.d.ts +0 -86
  102. package/dist/orchestration/turn-loop-guard.js +0 -92
  103. package/dist/orchestration/web-browser-policy.d.ts +0 -17
  104. package/dist/orchestration/web-browser-policy.js +0 -39
  105. package/dist/runtime/context-compression.d.ts +0 -61
  106. package/dist/runtime/context-compression.js +0 -274
  107. package/dist/runtime/hook-registry.d.ts +0 -12
  108. package/dist/runtime/hook-registry.js +0 -53
  109. package/dist/runtime/memory-hooks.d.ts +0 -23
  110. package/dist/runtime/memory-hooks.js +0 -65
  111. package/dist/runtime/tool-eligibility.d.ts +0 -59
  112. package/dist/runtime/tool-eligibility.js +0 -111
  113. package/dist/skills/index.d.ts +0 -108
  114. package/dist/skills/index.js +0 -82
  115. package/dist/skills/memory-extractor.d.ts +0 -64
  116. package/dist/skills/memory-extractor.js +0 -173
  117. package/dist/skills/memory-query-tool.d.ts +0 -43
  118. package/dist/skills/memory-query-tool.js +0 -127
  119. package/dist/skills/memory-store.d.ts +0 -66
  120. package/dist/skills/memory-store.js +0 -228
  121. package/dist/skills/memory-tool.d.ts +0 -67
  122. package/dist/skills/memory-tool.js +0 -192
  123. package/dist/skills/portable-tool.d.ts +0 -71
  124. package/dist/skills/portable-tool.js +0 -14
  125. package/dist/skills/qmemory-adapter.d.ts +0 -52
  126. package/dist/skills/qmemory-adapter.js +0 -165
  127. package/dist/skills/skill-frontmatter.d.ts +0 -19
  128. package/dist/skills/skill-frontmatter.js +0 -344
  129. package/dist/skills/skill-guard.d.ts +0 -23
  130. package/dist/skills/skill-guard.js +0 -229
  131. package/dist/skills/skill-loader.d.ts +0 -16
  132. package/dist/skills/skill-loader.js +0 -303
  133. package/dist/skills/skill-source.d.ts +0 -119
  134. package/dist/skills/skill-source.js +0 -126
  135. package/dist/skills/skill-types.d.ts +0 -199
  136. package/dist/skills/skill-types.js +0 -6
  137. package/dist/skills/think-tool.d.ts +0 -16
  138. package/dist/skills/think-tool.js +0 -59
  139. package/dist/skills/todo-tool.d.ts +0 -63
  140. package/dist/skills/todo-tool.js +0 -114
  141. package/dist/skills/tools/agent-tool.d.ts +0 -91
  142. package/dist/skills/tools/agent-tool.js +0 -142
  143. package/dist/skills/tools/apply-patch-tool.d.ts +0 -29
  144. package/dist/skills/tools/apply-patch-tool.js +0 -184
  145. package/dist/skills/tools/ask-user-tool.d.ts +0 -80
  146. package/dist/skills/tools/ask-user-tool.js +0 -121
  147. package/dist/skills/tools/brief-tool.d.ts +0 -74
  148. package/dist/skills/tools/brief-tool.js +0 -95
  149. package/dist/skills/tools/browser-tool.d.ts +0 -114
  150. package/dist/skills/tools/browser-tool.js +0 -155
  151. package/dist/skills/tools/checkpoint-tool.d.ts +0 -66
  152. package/dist/skills/tools/checkpoint-tool.js +0 -102
  153. package/dist/skills/tools/config-tool.d.ts +0 -63
  154. package/dist/skills/tools/config-tool.js +0 -143
  155. package/dist/skills/tools/cron-tool.d.ts +0 -116
  156. package/dist/skills/tools/cron-tool.js +0 -175
  157. package/dist/skills/tools/edit-tool.d.ts +0 -43
  158. package/dist/skills/tools/edit-tool.js +0 -70
  159. package/dist/skills/tools/exec-tool.d.ts +0 -102
  160. package/dist/skills/tools/exec-tool.js +0 -133
  161. package/dist/skills/tools/image-generate-tool.d.ts +0 -62
  162. package/dist/skills/tools/image-generate-tool.js +0 -67
  163. package/dist/skills/tools/instructions-tool.d.ts +0 -103
  164. package/dist/skills/tools/instructions-tool.js +0 -187
  165. package/dist/skills/tools/lsp-tool.d.ts +0 -153
  166. package/dist/skills/tools/lsp-tool.js +0 -227
  167. package/dist/skills/tools/mcp-client-types.d.ts +0 -269
  168. package/dist/skills/tools/mcp-client-types.js +0 -53
  169. package/dist/skills/tools/mcp-tool.d.ts +0 -249
  170. package/dist/skills/tools/mcp-tool.js +0 -503
  171. package/dist/skills/tools/memory-tool.d.ts +0 -74
  172. package/dist/skills/tools/memory-tool.js +0 -88
  173. package/dist/skills/tools/monitor-tool.d.ts +0 -113
  174. package/dist/skills/tools/monitor-tool.js +0 -131
  175. package/dist/skills/tools/music-generate-tool.d.ts +0 -55
  176. package/dist/skills/tools/music-generate-tool.js +0 -62
  177. package/dist/skills/tools/notify-tool.d.ts +0 -53
  178. package/dist/skills/tools/notify-tool.js +0 -62
  179. package/dist/skills/tools/patch-tool.d.ts +0 -45
  180. package/dist/skills/tools/patch-tool.js +0 -505
  181. package/dist/skills/tools/pdf-tool.d.ts +0 -66
  182. package/dist/skills/tools/pdf-tool.js +0 -88
  183. package/dist/skills/tools/plan-mode-tool.d.ts +0 -59
  184. package/dist/skills/tools/plan-mode-tool.js +0 -122
  185. package/dist/skills/tools/read-tool.d.ts +0 -51
  186. package/dist/skills/tools/read-tool.js +0 -84
  187. package/dist/skills/tools/repl-tool.d.ts +0 -70
  188. package/dist/skills/tools/repl-tool.js +0 -69
  189. package/dist/skills/tools/search-tool.d.ts +0 -112
  190. package/dist/skills/tools/search-tool.js +0 -225
  191. package/dist/skills/tools/send-message-tool.d.ts +0 -51
  192. package/dist/skills/tools/send-message-tool.js +0 -76
  193. package/dist/skills/tools/skill-list-tool.d.ts +0 -33
  194. package/dist/skills/tools/skill-list-tool.js +0 -54
  195. package/dist/skills/tools/skill-manage-tool.d.ts +0 -73
  196. package/dist/skills/tools/skill-manage-tool.js +0 -153
  197. package/dist/skills/tools/skill-view-tool.d.ts +0 -37
  198. package/dist/skills/tools/skill-view-tool.js +0 -72
  199. package/dist/skills/tools/sleep-tool.d.ts +0 -49
  200. package/dist/skills/tools/sleep-tool.js +0 -81
  201. package/dist/skills/tools/structured-output-tool.d.ts +0 -116
  202. package/dist/skills/tools/structured-output-tool.js +0 -176
  203. package/dist/skills/tools/task-tool.d.ts +0 -104
  204. package/dist/skills/tools/task-tool.js +0 -161
  205. package/dist/skills/tools/team-tool.d.ts +0 -89
  206. package/dist/skills/tools/team-tool.js +0 -105
  207. package/dist/skills/tools/tool-search-tool.d.ts +0 -51
  208. package/dist/skills/tools/tool-search-tool.js +0 -110
  209. package/dist/skills/tools/tts-tool.d.ts +0 -38
  210. package/dist/skills/tools/tts-tool.js +0 -45
  211. package/dist/skills/tools/video-edit-tool.d.ts +0 -69
  212. package/dist/skills/tools/video-edit-tool.js +0 -74
  213. package/dist/skills/tools/video-generate-tool.d.ts +0 -62
  214. package/dist/skills/tools/video-generate-tool.js +0 -66
  215. package/dist/skills/tools/video-merge-tool.d.ts +0 -105
  216. package/dist/skills/tools/video-merge-tool.js +0 -92
  217. package/dist/skills/tools/video-upscale-tool.d.ts +0 -45
  218. package/dist/skills/tools/video-upscale-tool.js +0 -52
  219. package/dist/skills/tools/web-fetch-tool.d.ts +0 -78
  220. package/dist/skills/tools/web-fetch-tool.js +0 -92
  221. package/dist/skills/tools/web-search-tool.d.ts +0 -57
  222. package/dist/skills/tools/web-search-tool.js +0 -86
  223. package/dist/skills/tools/worktree-tool.d.ts +0 -69
  224. package/dist/skills/tools/worktree-tool.js +0 -147
  225. package/dist/skills/tools/write-tool.d.ts +0 -45
  226. package/dist/skills/tools/write-tool.js +0 -81
@@ -1,293 +0,0 @@
1
- /**
2
- * Anthropic Messages Transport — SSE streaming for Claude API.
3
- *
4
- * POST {baseUrl}/v1/messages with stream: true
5
- * Auth: x-api-key: {apiKey} + anthropic-version header
6
- *
7
- * SSE event types:
8
- * message_start, content_block_start, content_block_delta,
9
- * content_block_stop, message_delta, message_stop
10
- *
11
- * Tool use is via content blocks with type "tool_use" + "input_json_delta".
12
- *
13
- * Aligned with Hermes anthropic_messages.py transport.
14
- */
15
- export class AnthropicMessagesTransport {
16
- baseUrl;
17
- apiVersion;
18
- timeoutMs;
19
- constructor(config) {
20
- this.baseUrl = config.baseUrl.replace(/\/+$/, "");
21
- this.apiVersion = config.apiVersion ?? "2023-06-01";
22
- this.timeoutMs = config.timeoutMs ?? 180_000;
23
- }
24
- async *stream(request, apiKey, signal) {
25
- const url = `${this.baseUrl}/v1/messages`;
26
- // Convert OpenAI-style messages → Anthropic format
27
- const { system, messages } = convertMessages(request.messages);
28
- const body = {
29
- model: request.model,
30
- messages,
31
- max_tokens: request.maxTokens ?? 8192,
32
- stream: true,
33
- };
34
- if (system)
35
- body.system = system;
36
- if (request.tools && request.tools.length > 0) {
37
- body.tools = request.tools.map(convertToolDef);
38
- if (request.toolChoice) {
39
- body.tool_choice =
40
- request.toolChoice === "auto"
41
- ? { type: "auto" }
42
- : request.toolChoice === "required"
43
- ? { type: "any" }
44
- : { type: "none" };
45
- }
46
- }
47
- if (request.temperature !== undefined)
48
- body.temperature = request.temperature;
49
- if (request.reasoning) {
50
- body.thinking = {
51
- type: "enabled",
52
- budget_tokens: mapReasoningEffortToBudget(request.reasoning.effort),
53
- };
54
- }
55
- const timeoutSignal = AbortSignal.timeout(this.timeoutMs);
56
- const combinedSignal = signal
57
- ? AbortSignal.any([signal, timeoutSignal])
58
- : timeoutSignal;
59
- const response = await fetch(url, {
60
- method: "POST",
61
- headers: {
62
- "Content-Type": "application/json",
63
- "x-api-key": apiKey,
64
- "anthropic-version": this.apiVersion,
65
- },
66
- body: JSON.stringify(body),
67
- signal: combinedSignal,
68
- });
69
- if (!response.ok) {
70
- const errorBody = await response.text().catch(() => "");
71
- throw new Error(`Anthropic API error ${response.status}: ${errorBody.slice(0, 500)}`);
72
- }
73
- if (!response.body) {
74
- throw new Error("Anthropic API returned no response body");
75
- }
76
- yield* this.parseSSEStream(response.body);
77
- }
78
- async *parseSSEStream(body) {
79
- const decoder = new TextDecoder();
80
- let buffer = "";
81
- let currentEvent = "";
82
- // Track active content blocks for tool_use accumulation
83
- const blocks = new Map();
84
- for await (const raw of body) {
85
- buffer += decoder.decode(raw, { stream: true });
86
- let newlineIdx;
87
- while ((newlineIdx = buffer.indexOf("\n")) !== -1) {
88
- const line = buffer.slice(0, newlineIdx).trim();
89
- buffer = buffer.slice(newlineIdx + 1);
90
- if (!line) {
91
- currentEvent = "";
92
- continue;
93
- }
94
- if (line.startsWith("event: ")) {
95
- currentEvent = line.slice(7).trim();
96
- continue;
97
- }
98
- if (!line.startsWith("data: "))
99
- continue;
100
- const data = line.slice(6);
101
- let parsed;
102
- try {
103
- parsed = JSON.parse(data);
104
- }
105
- catch {
106
- continue;
107
- }
108
- yield* this.mapEvent(currentEvent, parsed, blocks);
109
- }
110
- }
111
- }
112
- *mapEvent(event, data, blocks) {
113
- switch (event) {
114
- case "message_start": {
115
- // Extract usage from message_start
116
- const msg = data.message;
117
- const usage = msg?.usage;
118
- if (usage?.input_tokens) {
119
- yield {
120
- type: "usage",
121
- promptTokens: usage.input_tokens ?? 0,
122
- completionTokens: usage.output_tokens ?? 0,
123
- };
124
- }
125
- break;
126
- }
127
- case "content_block_start": {
128
- const index = data.index;
129
- const block = data.content_block;
130
- if (!block)
131
- break;
132
- const blockType = block.type;
133
- blocks.set(index, {
134
- type: blockType,
135
- id: block.id,
136
- name: block.name,
137
- });
138
- if (blockType === "tool_use") {
139
- yield {
140
- type: "tool_call_delta",
141
- index,
142
- id: block.id,
143
- name: block.name,
144
- arguments: "",
145
- };
146
- }
147
- else if (blockType === "thinking") {
148
- // Thinking block start — no chunk needed
149
- }
150
- break;
151
- }
152
- case "content_block_delta": {
153
- const index = data.index;
154
- const delta = data.delta;
155
- if (!delta)
156
- break;
157
- const deltaType = delta.type;
158
- if (deltaType === "text_delta") {
159
- yield { type: "delta", text: delta.text };
160
- }
161
- else if (deltaType === "input_json_delta") {
162
- yield {
163
- type: "tool_call_delta",
164
- index,
165
- arguments: delta.partial_json,
166
- };
167
- }
168
- else if (deltaType === "thinking_delta") {
169
- yield {
170
- type: "reasoning_delta",
171
- text: delta.thinking,
172
- };
173
- }
174
- break;
175
- }
176
- case "content_block_stop": {
177
- const index = data.index;
178
- blocks.delete(index);
179
- break;
180
- }
181
- case "message_delta": {
182
- const delta = data.delta;
183
- const usage = data.usage;
184
- if (usage) {
185
- yield {
186
- type: "usage",
187
- promptTokens: 0,
188
- completionTokens: usage.output_tokens ?? 0,
189
- };
190
- }
191
- if (delta?.stop_reason) {
192
- yield { type: "done", finishReason: mapAnthropicStopReason(delta.stop_reason) };
193
- }
194
- break;
195
- }
196
- case "message_stop":
197
- // Final event, no data needed
198
- break;
199
- case "error": {
200
- const error = data.error;
201
- throw new Error(`Anthropic stream error: ${error?.message ?? JSON.stringify(data)}`);
202
- }
203
- }
204
- }
205
- }
206
- // ── Stop reason normalization (Anthropic → OpenAI standard) ──────────────────
207
- function mapAnthropicStopReason(reason) {
208
- switch (reason) {
209
- case "end_turn":
210
- case "stop_sequence":
211
- return "stop";
212
- case "tool_use":
213
- return "tool_calls";
214
- case "max_tokens":
215
- return "length";
216
- default:
217
- return reason;
218
- }
219
- }
220
- // ── Reasoning effort → thinking budget (Hermes-aligned) ─────────────────────
221
- const THINKING_BUDGET = {
222
- xhigh: 32000,
223
- high: 16000,
224
- medium: 8000,
225
- low: 4000,
226
- };
227
- function mapReasoningEffortToBudget(effort) {
228
- return THINKING_BUDGET[effort] ?? THINKING_BUDGET.high;
229
- }
230
- // ── Message format conversion (OpenAI → Anthropic) ───────────────────────────
231
- function convertMessages(messages) {
232
- let system;
233
- const out = [];
234
- for (const msg of messages) {
235
- if (msg.role === "system") {
236
- // Anthropic requires system as a top-level param, not a message
237
- system = system ? `${system}\n\n${msg.content ?? ""}` : (msg.content ?? "");
238
- continue;
239
- }
240
- if (msg.role === "user") {
241
- out.push({ role: "user", content: msg.content ?? "" });
242
- }
243
- else if (msg.role === "assistant") {
244
- if (msg.tool_calls && msg.tool_calls.length > 0) {
245
- // Assistant message with tool calls
246
- const content = [];
247
- if (msg.content) {
248
- content.push({ type: "text", text: msg.content });
249
- }
250
- for (const tc of msg.tool_calls) {
251
- let input;
252
- try {
253
- input = JSON.parse(tc.function.arguments);
254
- }
255
- catch {
256
- input = {};
257
- }
258
- content.push({
259
- type: "tool_use",
260
- id: tc.id,
261
- name: tc.function.name,
262
- input,
263
- });
264
- }
265
- out.push({ role: "assistant", content });
266
- }
267
- else {
268
- out.push({ role: "assistant", content: msg.content ?? "" });
269
- }
270
- }
271
- else if (msg.role === "tool") {
272
- // Tool result → Anthropic user message with tool_result content blocks
273
- out.push({
274
- role: "user",
275
- content: [
276
- {
277
- type: "tool_result",
278
- tool_use_id: msg.tool_call_id ?? "",
279
- content: msg.content ?? "",
280
- },
281
- ],
282
- });
283
- }
284
- }
285
- return { system, messages: out };
286
- }
287
- function convertToolDef(tool) {
288
- return {
289
- name: tool.function.name,
290
- description: tool.function.description,
291
- input_schema: tool.function.parameters ?? { type: "object", properties: {} },
292
- };
293
- }
@@ -1,36 +0,0 @@
1
- /**
2
- * OpenAI Chat Completions Transport — SSE streaming implementation.
3
- *
4
- * Covers all OpenAI-compatible providers:
5
- * DeepSeek, Qwen, 硅基, Minimax, Moonshot, Groq, Together, OpenRouter, etc.
6
- *
7
- * POST {baseUrl}/v1/chat/completions with stream: true
8
- * Auth: Authorization: Bearer {apiKey}
9
- *
10
- * SSE format: lines prefixed with "data: ", JSON parsing per event.
11
- *
12
- * Adapted from admin-infer-proxy-client.ts SSE logic + Hermes openai_chat.py transport.
13
- */
14
- import type { LLMChunk, LLMRequest, LLMTransport } from "../transport.js";
15
- export interface OpenAIChatTransportConfig {
16
- baseUrl: string;
17
- /** Additional headers (e.g. for specific providers) */
18
- extraHeaders?: Record<string, string>;
19
- /** Timeout in ms (default 180_000) */
20
- timeoutMs?: number;
21
- /** Whether to include stream_options (default true). Set false for providers that reject it. */
22
- supportsStreamOptions?: boolean;
23
- /** Whether to omit temperature when it equals 0 (e.g. Moonshot rejects 0) */
24
- omitZeroTemperature?: boolean;
25
- }
26
- export declare class OpenAIChatTransport implements LLMTransport {
27
- private baseUrl;
28
- private extraHeaders;
29
- private timeoutMs;
30
- private supportsStreamOptions;
31
- private omitZeroTemperature;
32
- constructor(config: OpenAIChatTransportConfig);
33
- stream(request: LLMRequest, apiKey: string, signal?: AbortSignal): AsyncGenerator<LLMChunk>;
34
- private parseSSEStream;
35
- private mapChunk;
36
- }
@@ -1,165 +0,0 @@
1
- /**
2
- * OpenAI Chat Completions Transport — SSE streaming implementation.
3
- *
4
- * Covers all OpenAI-compatible providers:
5
- * DeepSeek, Qwen, 硅基, Minimax, Moonshot, Groq, Together, OpenRouter, etc.
6
- *
7
- * POST {baseUrl}/v1/chat/completions with stream: true
8
- * Auth: Authorization: Bearer {apiKey}
9
- *
10
- * SSE format: lines prefixed with "data: ", JSON parsing per event.
11
- *
12
- * Adapted from admin-infer-proxy-client.ts SSE logic + Hermes openai_chat.py transport.
13
- */
14
- export class OpenAIChatTransport {
15
- baseUrl;
16
- extraHeaders;
17
- timeoutMs;
18
- supportsStreamOptions;
19
- omitZeroTemperature;
20
- constructor(config) {
21
- // Strip trailing slash
22
- this.baseUrl = config.baseUrl.replace(/\/+$/, "");
23
- this.extraHeaders = config.extraHeaders ?? {};
24
- this.timeoutMs = config.timeoutMs ?? 180_000;
25
- this.supportsStreamOptions = config.supportsStreamOptions ?? true;
26
- this.omitZeroTemperature = config.omitZeroTemperature ?? false;
27
- }
28
- async *stream(request, apiKey, signal) {
29
- const url = `${this.baseUrl}/v1/chat/completions`;
30
- const body = {
31
- model: request.model,
32
- messages: request.messages,
33
- stream: true,
34
- };
35
- // stream_options: supported by most providers, but some reject it
36
- if (this.supportsStreamOptions) {
37
- body.stream_options = { include_usage: true };
38
- }
39
- if (request.tools && request.tools.length > 0) {
40
- body.tools = request.tools;
41
- if (request.toolChoice)
42
- body.tool_choice = request.toolChoice;
43
- }
44
- if (request.temperature !== undefined) {
45
- // Some providers (e.g. Moonshot/Kimi) reject temperature=0
46
- if (!(this.omitZeroTemperature && request.temperature === 0)) {
47
- body.temperature = request.temperature;
48
- }
49
- }
50
- if (request.maxTokens !== undefined)
51
- body.max_tokens = request.maxTokens;
52
- if (request.reasoning) {
53
- // DeepSeek-R1 / o1 style reasoning
54
- body.reasoning = request.reasoning;
55
- }
56
- const timeoutSignal = AbortSignal.timeout(this.timeoutMs);
57
- const combinedSignal = signal
58
- ? AbortSignal.any([signal, timeoutSignal])
59
- : timeoutSignal;
60
- const response = await fetch(url, {
61
- method: "POST",
62
- headers: {
63
- "Content-Type": "application/json",
64
- Authorization: `Bearer ${apiKey}`,
65
- ...this.extraHeaders,
66
- },
67
- body: JSON.stringify(body),
68
- signal: combinedSignal,
69
- });
70
- if (!response.ok) {
71
- const errorBody = await response.text().catch(() => "");
72
- throw new Error(`LLM API error ${response.status}: ${errorBody.slice(0, 500)}`);
73
- }
74
- if (!response.body) {
75
- throw new Error("LLM API returned no response body");
76
- }
77
- yield* this.parseSSEStream(response.body);
78
- }
79
- async *parseSSEStream(body) {
80
- const decoder = new TextDecoder();
81
- let buffer = "";
82
- for await (const raw of body) {
83
- buffer += decoder.decode(raw, { stream: true });
84
- // Process complete lines
85
- let newlineIdx;
86
- while ((newlineIdx = buffer.indexOf("\n")) !== -1) {
87
- const line = buffer.slice(0, newlineIdx).trim();
88
- buffer = buffer.slice(newlineIdx + 1);
89
- if (!line)
90
- continue;
91
- if (line.startsWith(":"))
92
- continue; // SSE comment
93
- if (!line.startsWith("data: "))
94
- continue;
95
- const data = line.slice(6);
96
- if (data === "[DONE]") {
97
- return;
98
- }
99
- let parsed;
100
- try {
101
- parsed = JSON.parse(data);
102
- }
103
- catch {
104
- continue; // Skip malformed JSON
105
- }
106
- yield* this.mapChunk(parsed);
107
- }
108
- }
109
- // Flush remaining buffer
110
- if (buffer.trim()) {
111
- const line = buffer.trim();
112
- if (line.startsWith("data: ") && line.slice(6) !== "[DONE]") {
113
- try {
114
- const parsed = JSON.parse(line.slice(6));
115
- yield* this.mapChunk(parsed);
116
- }
117
- catch {
118
- // ignore
119
- }
120
- }
121
- }
122
- }
123
- *mapChunk(chunk) {
124
- // Usage chunk (often sent at the end with stream_options)
125
- if (chunk.usage) {
126
- yield {
127
- type: "usage",
128
- promptTokens: chunk.usage.prompt_tokens ?? 0,
129
- completionTokens: chunk.usage.completion_tokens ?? 0,
130
- reasoningTokens: chunk.usage.completion_tokens_details?.reasoning_tokens,
131
- };
132
- }
133
- if (!chunk.choices || chunk.choices.length === 0)
134
- return;
135
- for (const choice of chunk.choices) {
136
- const delta = choice.delta;
137
- if (!delta)
138
- continue;
139
- // Reasoning content (DeepSeek-R1 style)
140
- if (delta.reasoning_content) {
141
- yield { type: "reasoning_delta", text: delta.reasoning_content };
142
- }
143
- // Text content
144
- if (delta.content) {
145
- yield { type: "delta", text: delta.content };
146
- }
147
- // Tool call deltas
148
- if (delta.tool_calls) {
149
- for (const tc of delta.tool_calls) {
150
- yield {
151
- type: "tool_call_delta",
152
- index: tc.index,
153
- id: tc.id,
154
- name: tc.function?.name,
155
- arguments: tc.function?.arguments ?? "",
156
- };
157
- }
158
- }
159
- // Finish reason
160
- if (choice.finish_reason) {
161
- yield { type: "done", finishReason: choice.finish_reason };
162
- }
163
- }
164
- }
165
- }
@@ -1,41 +0,0 @@
1
- /**
2
- * Built-in Agent Registry — CC-aligned agent definitions for fork/subagent.
3
- *
4
- * Each built-in agent defines a role with constrained tools, system prompt,
5
- * and execution budget. The LLM can invoke these via the AgentTool.
6
- */
7
- export interface AgentDefinition {
8
- /** Unique identifier for the agent (kebab-case). */
9
- name: string;
10
- /** Human-readable label. */
11
- label: string;
12
- /** Short description (appears in tool_search / LLM prompt). */
13
- description: string;
14
- /** Maximum turns this agent can execute before forced stop. */
15
- maxTurns: number;
16
- /** Tool access mode. */
17
- toolAccessMode: "full" | "read-only" | "none";
18
- /** Explicit allowed tool names (if empty, uses toolAccessMode filter). */
19
- allowedTools?: string[];
20
- /** Whether this agent can fork sub-agents itself. */
21
- canFork: boolean;
22
- /** System prompt override for this agent. */
23
- systemPromptSuffix?: string;
24
- }
25
- /**
26
- * Get the full list of built-in agent definitions.
27
- */
28
- export declare function getBuiltInAgents(): AgentDefinition[];
29
- /**
30
- * Look up a built-in agent by name.
31
- */
32
- export declare function getBuiltInAgent(name: string): AgentDefinition | undefined;
33
- /**
34
- * Check if a given agent name is a built-in agent.
35
- */
36
- export declare function isBuiltInAgent(name: string): boolean;
37
- /**
38
- * Resolve tool access for an agent definition.
39
- * Returns the set of tool names the agent is allowed to use.
40
- */
41
- export declare function resolveAgentToolSet(agent: AgentDefinition, availableTools: string[]): string[];
@@ -1,116 +0,0 @@
1
- /**
2
- * Built-in Agent Registry — CC-aligned agent definitions for fork/subagent.
3
- *
4
- * Each built-in agent defines a role with constrained tools, system prompt,
5
- * and execution budget. The LLM can invoke these via the AgentTool.
6
- */
7
- /** General-purpose sub-agent for delegated tasks. */
8
- const GENERAL_PURPOSE_AGENT = {
9
- name: "general",
10
- label: "General Purpose",
11
- description: "A general-purpose sub-agent that can perform any task with full tool access.",
12
- maxTurns: 200,
13
- toolAccessMode: "full",
14
- canFork: false,
15
- };
16
- /** Explore agent — read-only exploration (code search, file reading, analysis). */
17
- const EXPLORE_AGENT = {
18
- name: "explore",
19
- label: "Explore",
20
- description: "Fast read-only codebase exploration. Search files, read code, analyze structure. Cannot write or execute.",
21
- maxTurns: 50,
22
- toolAccessMode: "read-only",
23
- allowedTools: ["read_file", "search", "web_search", "web_fetch", "think", "memory_query", "tool_search"],
24
- canFork: false,
25
- };
26
- /** Plan agent — read-only planning mode (explore + propose, no execution). */
27
- const PLAN_AGENT = {
28
- name: "plan",
29
- label: "Plan",
30
- description: "Planning mode. Explore, analyze, and produce a structured plan. Cannot write files or execute commands.",
31
- maxTurns: 80,
32
- toolAccessMode: "read-only",
33
- allowedTools: ["read_file", "search", "web_search", "web_fetch", "think", "memory_query", "todo", "tool_search"],
34
- canFork: false,
35
- };
36
- /** Code agent — full execution capability for code tasks. */
37
- const CODE_AGENT = {
38
- name: "code",
39
- label: "Code",
40
- description: "A coding sub-agent with full tool access for implementation tasks.",
41
- maxTurns: 200,
42
- toolAccessMode: "full",
43
- canFork: true,
44
- };
45
- /** Research agent — web research and information gathering. */
46
- const RESEARCH_AGENT = {
47
- name: "research",
48
- label: "Research",
49
- description: "Web research and information gathering. Searches the web, fetches pages, and synthesizes findings.",
50
- maxTurns: 30,
51
- toolAccessMode: "read-only",
52
- allowedTools: ["web_search", "web_fetch", "read_file", "search", "think", "memory_query"],
53
- canFork: false,
54
- };
55
- /** Verification agent — runs tests and validates changes. */
56
- const VERIFY_AGENT = {
57
- name: "verify",
58
- label: "Verify",
59
- description: "Verification agent. Runs tests, checks build output, validates changes are correct.",
60
- maxTurns: 40,
61
- toolAccessMode: "full",
62
- allowedTools: ["exec", "read_file", "search", "think"],
63
- canFork: false,
64
- };
65
- const BUILT_IN_AGENTS = [
66
- GENERAL_PURPOSE_AGENT,
67
- EXPLORE_AGENT,
68
- PLAN_AGENT,
69
- CODE_AGENT,
70
- RESEARCH_AGENT,
71
- VERIFY_AGENT,
72
- ];
73
- /**
74
- * Get the full list of built-in agent definitions.
75
- */
76
- export function getBuiltInAgents() {
77
- return [...BUILT_IN_AGENTS];
78
- }
79
- /**
80
- * Look up a built-in agent by name.
81
- */
82
- export function getBuiltInAgent(name) {
83
- return BUILT_IN_AGENTS.find((a) => a.name === name);
84
- }
85
- /**
86
- * Check if a given agent name is a built-in agent.
87
- */
88
- export function isBuiltInAgent(name) {
89
- return BUILT_IN_AGENTS.some((a) => a.name === name);
90
- }
91
- /**
92
- * Resolve tool access for an agent definition.
93
- * Returns the set of tool names the agent is allowed to use.
94
- */
95
- export function resolveAgentToolSet(agent, availableTools) {
96
- if (agent.allowedTools && agent.allowedTools.length > 0) {
97
- const allowed = new Set(agent.allowedTools);
98
- return availableTools.filter((t) => allowed.has(t));
99
- }
100
- if (agent.toolAccessMode === "none")
101
- return [];
102
- if (agent.toolAccessMode === "read-only") {
103
- const writeTools = new Set([
104
- "file_edit", "create_file", "write_file", "replace_string_in_file",
105
- "multi_replace_string_in_file", "create_directory", "delete_file",
106
- "rename_file", "move_file", "exec", "run_in_terminal", "run_command",
107
- "git_commit", "git_push", "patch",
108
- ]);
109
- return availableTools.filter((t) => !writeTools.has(t));
110
- }
111
- // "full" — all tools except agent_tool itself (no recursive fork for non-canFork)
112
- if (!agent.canFork) {
113
- return availableTools.filter((t) => t !== "agent_tool" && t !== "team_create");
114
- }
115
- return [...availableTools];
116
- }
@@ -1,32 +0,0 @@
1
- import type { ToolCallBatch, ToolCallLike } from "./parallel-tool-calls.js";
2
- import type { ToolEligibilityLike } from "./tool-choice-policy.js";
3
- export type ToolExecutionStepContext = {
4
- stepIndex?: number;
5
- stepTotal?: number;
6
- stepSummary?: string;
7
- };
8
- export type ApprovalAwareToolCapability = {
9
- name: string;
10
- requiresApproval?: boolean;
11
- approvalMode?: string;
12
- };
13
- export type ApprovalAwareToolPlanStep = {
14
- stepIndex: number;
15
- stepCount: number;
16
- mode: "parallel" | "serial";
17
- callIds: string[];
18
- toolNames: string[];
19
- approvalRequired: boolean;
20
- approvalToolNames: string[];
21
- summary: string;
22
- };
23
- export declare function summarizeApprovalAwareToolPlan<TCall extends ToolCallLike>(params: {
24
- batches: Array<ToolCallBatch<TCall>>;
25
- toolCapabilities: readonly ApprovalAwareToolCapability[];
26
- eligibility?: readonly ToolEligibilityLike[];
27
- }): ApprovalAwareToolPlanStep[];
28
- export declare function buildApprovalAwareReason(params: {
29
- toolName: string;
30
- step: ApprovalAwareToolPlanStep | undefined;
31
- }): string;
32
- export declare function buildApprovalStepContext(step: ApprovalAwareToolPlanStep | undefined): ToolExecutionStepContext;