@cjhyy/code-shell 0.1.5 → 0.1.7

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 (158) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/anthropic-UBSB5AQH.js +1 -0
  3. package/dist/arena/index.js +1 -104
  4. package/dist/arena-OW55ZCHT.js +3 -0
  5. package/dist/bwrap-PVZMLHZR.js +2 -0
  6. package/dist/chunk-2NS3JMNK.js +1 -0
  7. package/dist/chunk-3QP5BQ3L.js +1 -0
  8. package/dist/chunk-B7K2OWKC.js +2 -0
  9. package/dist/chunk-EWWK56K6.js +2 -0
  10. package/dist/chunk-FU7AHZNN.js +1 -0
  11. package/dist/chunk-HIJ2XXGX.js +1 -0
  12. package/dist/chunk-KCXSARAA.js +1 -0
  13. package/dist/chunk-NFH3UQ3E.js +2 -0
  14. package/dist/chunk-NMBYBGC7.js +250 -0
  15. package/dist/chunk-NVAZJ5XS.js +2 -0
  16. package/dist/chunk-O5HFCH2U.js +1 -0
  17. package/dist/chunk-P6JSTIFM.js +1 -0
  18. package/dist/chunk-PGANL6F2.js +3 -0
  19. package/dist/chunk-Q4O2HGWS.js +251 -0
  20. package/dist/chunk-QTWU7UNA.js +5 -0
  21. package/dist/chunk-RP26WO4R.js +1 -0
  22. package/dist/chunk-SNFAPSLA.js +1 -0
  23. package/dist/chunk-T222K6IV.js +18 -0
  24. package/dist/chunk-TKJA6W36.js +3 -0
  25. package/dist/chunk-UDPUTFQT.js +2 -0
  26. package/dist/chunk-W47Z7MGS.js +33 -0
  27. package/dist/chunk-WI6FSWGU.js +1 -0
  28. package/dist/chunk-WOP6MJKW.js +1 -0
  29. package/dist/chunk-XDOWC7EG.js +4 -0
  30. package/dist/chunk-Y2NS6HPO.js +641 -0
  31. package/dist/cli/main.js +303 -22037
  32. package/dist/cli/updater.d.ts +8 -0
  33. package/dist/client-base-6ZZJJYDY.js +1 -0
  34. package/dist/compaction-ECVQVOCT.js +1 -0
  35. package/dist/devtools-SGDUOOM4.js +1 -0
  36. package/dist/engine/engine.d.ts +15 -0
  37. package/dist/export-md-U72T7NW7.js +22 -0
  38. package/dist/file-history-7FQFEQOL.js +1 -0
  39. package/dist/index.d.ts +1 -1
  40. package/dist/index.js +1 -347
  41. package/dist/llm/token-counter.d.ts +17 -0
  42. package/dist/manager-C3TDN6MS.js +1 -0
  43. package/dist/mcp-manager-OP4XYV53.js +1 -0
  44. package/dist/memory-BNI4WEWL.js +1 -0
  45. package/dist/model-cache-HEDXI7UJ.js +1 -0
  46. package/dist/model-fetcher-BJ64META.js +1 -0
  47. package/dist/off-7SDVMMXW.js +1 -0
  48. package/dist/openai-KEWQ54TM.js +1 -0
  49. package/dist/openrouter-models-AM6M52D6.js +1 -0
  50. package/dist/openrouter-sync-5JNBL3Z6.js +1 -0
  51. package/dist/product/index.js +1 -21
  52. package/dist/run/index.js +1 -48
  53. package/dist/seatbelt-WBYROQT6.js +37 -0
  54. package/dist/session/session-manager.d.ts +2 -0
  55. package/dist/session-manager-AGWS5SMJ.js +1 -0
  56. package/dist/settings/schema.d.ts +72 -6
  57. package/dist/tool-summary-5UE62VU4.js +2 -0
  58. package/dist/tool-system/builtin/bash.d.ts +7 -1
  59. package/dist/tool-system/context.d.ts +7 -0
  60. package/dist/tool-system/investigation-guard.d.ts +9 -0
  61. package/dist/tool-system/sandbox/bwrap.d.ts +13 -0
  62. package/dist/tool-system/sandbox/index.d.ts +71 -0
  63. package/dist/tool-system/sandbox/off.d.ts +2 -0
  64. package/dist/tool-system/sandbox/seatbelt.d.ts +18 -0
  65. package/dist/types.d.ts +4 -0
  66. package/dist/ui/components/SessionPicker.d.ts +2 -0
  67. package/dist/ui/components/SpinnerWithVerb.d.ts +2 -2
  68. package/dist/ui/components/StatusLine.d.ts +2 -2
  69. package/dist/updater-OCNU2K2Z.js +1 -0
  70. package/package.json +8 -10
  71. package/skills-builtin/codeshell-help.md +135 -0
  72. package/dist/anthropic-IBTI4WL2.cjs +0 -10
  73. package/dist/anthropic-PRZZKHEZ.js +0 -10
  74. package/dist/arena/index.cjs +0 -104
  75. package/dist/arena-KBQOPLFV.cjs +0 -261
  76. package/dist/arena-O2L4TN6A.js +0 -261
  77. package/dist/chunk-2EP3CLEN.js +0 -44
  78. package/dist/chunk-2YW4FPFG.cjs +0 -101
  79. package/dist/chunk-3OA5G4TM.js +0 -47
  80. package/dist/chunk-52LGZKT3.cjs +0 -47
  81. package/dist/chunk-55XGPMAP.cjs +0 -146
  82. package/dist/chunk-5ECBT4YA.js +0 -450
  83. package/dist/chunk-6QVAYW7C.cjs +0 -438
  84. package/dist/chunk-6S4BJ65N.js +0 -113
  85. package/dist/chunk-76HYEPDM.js +0 -307
  86. package/dist/chunk-76W334S4.js +0 -54
  87. package/dist/chunk-7EG3V4JY.cjs +0 -113
  88. package/dist/chunk-7JVTYEEC.js +0 -340
  89. package/dist/chunk-7K6SDRRF.js +0 -9047
  90. package/dist/chunk-7Y6S3OCX.js +0 -438
  91. package/dist/chunk-A5LCRPDP.cjs +0 -54
  92. package/dist/chunk-BSW22MPA.js +0 -146
  93. package/dist/chunk-BUU5PZK2.cjs +0 -9048
  94. package/dist/chunk-BWTOS5BH.cjs +0 -5128
  95. package/dist/chunk-BXCY2FSE.js +0 -203
  96. package/dist/chunk-C5YQBIRK.js +0 -5128
  97. package/dist/chunk-HEKQCI7B.cjs +0 -224
  98. package/dist/chunk-HS2MFNUC.cjs +0 -44
  99. package/dist/chunk-IK4EWJBP.cjs +0 -203
  100. package/dist/chunk-JMR33QVF.cjs +0 -169
  101. package/dist/chunk-KOVYSDHZ.cjs +0 -340
  102. package/dist/chunk-KS3RYAYL.cjs +0 -45
  103. package/dist/chunk-MD32R22I.js +0 -50
  104. package/dist/chunk-MY5XHADU.cjs +0 -216
  105. package/dist/chunk-NUNC3VFB.cjs +0 -307
  106. package/dist/chunk-QRM7IF2S.cjs +0 -4711
  107. package/dist/chunk-R47ROHGL.cjs +0 -298
  108. package/dist/chunk-RMYKO74M.js +0 -1252
  109. package/dist/chunk-SFXHZSRF.js +0 -101
  110. package/dist/chunk-SIHHIQLO.js +0 -224
  111. package/dist/chunk-SNT563K3.cjs +0 -107
  112. package/dist/chunk-T6VYG46N.js +0 -105
  113. package/dist/chunk-TUY2T5KP.cjs +0 -105
  114. package/dist/chunk-VIAGTYYW.js +0 -169
  115. package/dist/chunk-VYL4EFRC.cjs +0 -1252
  116. package/dist/chunk-W22P377T.js +0 -299
  117. package/dist/chunk-WASS5YWB.js +0 -215
  118. package/dist/chunk-XDIQWQJ4.js +0 -4711
  119. package/dist/chunk-YIQBXAYU.cjs +0 -264
  120. package/dist/chunk-YJ77GQK5.js +0 -107
  121. package/dist/chunk-YUI524OE.cjs +0 -450
  122. package/dist/chunk-ZBPSQCPU.js +0 -264
  123. package/dist/cli/main.cjs +0 -22133
  124. package/dist/client-base-HTF236ZD.cjs +0 -9
  125. package/dist/client-base-QKRKCOWB.js +0 -9
  126. package/dist/compaction-6VU2T643.js +0 -33
  127. package/dist/compaction-OKUNTCA7.cjs +0 -33
  128. package/dist/devtools-T2NIZBJK.cjs +0 -6
  129. package/dist/devtools-YXWHOVKR.js +0 -6
  130. package/dist/export-md-RXDW6F5W.cjs +0 -135
  131. package/dist/export-md-XXKZANW5.js +0 -135
  132. package/dist/file-history-KYPE3ECT.cjs +0 -7
  133. package/dist/file-history-LF4F7X26.js +0 -7
  134. package/dist/index.cjs +0 -347
  135. package/dist/manager-C2IUXKRC.js +0 -7
  136. package/dist/manager-YYKWYTRM.cjs +0 -7
  137. package/dist/mcp-manager-QMKWPBZ4.js +0 -8
  138. package/dist/mcp-manager-Z3OKI74O.cjs +0 -8
  139. package/dist/memory-5LWZ6FI2.cjs +0 -9
  140. package/dist/memory-VIJLBAMQ.js +0 -9
  141. package/dist/model-cache-5KIYL5SL.js +0 -13
  142. package/dist/model-cache-OED3IM4R.cjs +0 -13
  143. package/dist/model-fetcher-HKGICACL.js +0 -8
  144. package/dist/model-fetcher-UR6WJOQP.cjs +0 -8
  145. package/dist/openai-JR2WEKOF.js +0 -10
  146. package/dist/openai-YBTOET4O.cjs +0 -10
  147. package/dist/openrouter-models-OU4GRZQY.cjs +0 -15
  148. package/dist/openrouter-models-TGKDKY52.js +0 -15
  149. package/dist/openrouter-sync-BBHUM3R6.cjs +0 -11
  150. package/dist/openrouter-sync-UXUSJCIR.js +0 -11
  151. package/dist/product/index.cjs +0 -21
  152. package/dist/run/index.cjs +0 -48
  153. package/dist/session-manager-Q22BBMD3.js +0 -8
  154. package/dist/session-manager-XODQVL3C.cjs +0 -8
  155. package/dist/tool-summary-63DPIS7G.cjs +0 -31
  156. package/dist/tool-summary-NP5CDBKG.js +0 -31
  157. package/dist/updater-QW473OF4.cjs +0 -17
  158. package/dist/updater-VFUAHCVY.js +0 -17
@@ -1,340 +0,0 @@
1
- import {
2
- LLMClientBase
3
- } from "./chunk-6S4BJ65N.js";
4
- import {
5
- ContextLimitError,
6
- LLMError,
7
- LLMRateLimitError
8
- } from "./chunk-SFXHZSRF.js";
9
- import {
10
- logger
11
- } from "./chunk-BXCY2FSE.js";
12
- import {
13
- init_esm_shims
14
- } from "./chunk-MD32R22I.js";
15
-
16
- // src/llm/providers/openai.ts
17
- init_esm_shims();
18
- import OpenAI from "openai";
19
- var OpenAIClient = class extends LLMClientBase {
20
- _client = null;
21
- constructor(config) {
22
- super(config);
23
- }
24
- initClient() {
25
- }
26
- get client() {
27
- if (!this._client) {
28
- this._client = new OpenAI({
29
- apiKey: this.config.apiKey ?? process.env.OPENAI_API_KEY,
30
- ...this.config.baseUrl ? { baseURL: this.config.baseUrl } : {},
31
- timeout: this.timeout
32
- });
33
- }
34
- return this._client;
35
- }
36
- async createMessage(options) {
37
- return this.withRetry(async () => {
38
- const messages = this.buildMessages(options.systemPrompt, options.messages);
39
- const tools = options.tools?.length ? this.convertTools(options.tools) : void 0;
40
- const span = logger.span("llm.request", {
41
- cat: "llm",
42
- provider: this.provider,
43
- model: this.model,
44
- stream: !!(options.stream && options.onChunk),
45
- messageCount: messages.length,
46
- toolCount: tools?.length ?? 0
47
- });
48
- try {
49
- const response = options.stream && options.onChunk ? await this.streamMessage(options, messages, tools) : await this.nonStreamMessage(options, messages, tools);
50
- span.end({
51
- stopReason: response.stopReason,
52
- promptTokens: response.usage?.promptTokens,
53
- completionTokens: response.usage?.completionTokens,
54
- cacheReadTokens: response.usage?.cacheReadTokens,
55
- cacheCreationTokens: response.usage?.cacheCreationTokens
56
- });
57
- return response;
58
- } catch (err) {
59
- span.fail(err);
60
- throw err;
61
- }
62
- });
63
- }
64
- async nonStreamMessage(options, messages, tools) {
65
- try {
66
- const response = await this.client.chat.completions.create(
67
- {
68
- model: this.model,
69
- max_tokens: options.maxTokens ?? this.maxTokens,
70
- messages,
71
- ...tools ? { tools } : {},
72
- ...options.temperature !== void 0 ? { temperature: options.temperature } : { temperature: this.temperature }
73
- },
74
- { signal: options.signal }
75
- );
76
- const choice = response.choices[0];
77
- if (!choice) throw new LLMError("No response from OpenAI", "openai");
78
- const usage = {
79
- promptTokens: response.usage?.prompt_tokens ?? 0,
80
- completionTokens: response.usage?.completion_tokens ?? 0,
81
- totalTokens: response.usage?.total_tokens ?? 0
82
- };
83
- this.recordUsage(usage, options);
84
- return this.processChoice(choice, usage);
85
- } catch (err) {
86
- this.handleApiError(err);
87
- throw err;
88
- }
89
- }
90
- async streamMessage(options, messages, tools) {
91
- try {
92
- const stream = await this.client.chat.completions.create(
93
- {
94
- model: this.model,
95
- max_tokens: options.maxTokens ?? this.maxTokens,
96
- messages,
97
- stream: true,
98
- stream_options: { include_usage: true },
99
- ...tools ? { tools } : {},
100
- ...options.temperature !== void 0 ? { temperature: options.temperature } : { temperature: this.temperature }
101
- },
102
- { signal: options.signal }
103
- );
104
- let text = "";
105
- let reasoningContent = "";
106
- const toolCallsMap = /* @__PURE__ */ new Map();
107
- let streamUsage;
108
- const streamStartedAt = Date.now();
109
- let firstByteLogged = false;
110
- for await (const chunk of stream) {
111
- if (chunk.usage) {
112
- streamUsage = chunk.usage;
113
- }
114
- const delta = chunk.choices[0]?.delta;
115
- if (!delta) continue;
116
- const reasoningDelta = delta.reasoning_content;
117
- if (typeof reasoningDelta === "string" && reasoningDelta.length > 0) {
118
- reasoningContent += reasoningDelta;
119
- }
120
- if (delta.content) {
121
- if (!firstByteLogged) {
122
- firstByteLogged = true;
123
- logger.debug("llm.first_byte", {
124
- cat: "llm",
125
- provider: this.provider,
126
- model: this.model,
127
- ttft_ms: Date.now() - streamStartedAt
128
- });
129
- }
130
- text += delta.content;
131
- options.onChunk?.({ type: "text", text: delta.content });
132
- }
133
- if (delta.tool_calls) {
134
- for (const tc of delta.tool_calls) {
135
- const idx = tc.index;
136
- if (!toolCallsMap.has(idx)) {
137
- toolCallsMap.set(idx, { id: tc.id ?? "", name: tc.function?.name ?? "", args: "" });
138
- options.onChunk?.({
139
- type: "tool_use_start",
140
- toolCall: { id: tc.id, toolName: tc.function?.name }
141
- });
142
- }
143
- const existing = toolCallsMap.get(idx);
144
- if (tc.id) existing.id = tc.id;
145
- if (tc.function?.name) existing.name = tc.function.name;
146
- if (tc.function?.arguments) {
147
- existing.args += tc.function.arguments;
148
- if (existing.id) {
149
- try {
150
- const parsed = JSON.parse(existing.args || "{}");
151
- options.onChunk?.({
152
- type: "tool_use_delta",
153
- toolCall: { id: existing.id, toolName: existing.name, args: parsed }
154
- });
155
- } catch {
156
- }
157
- }
158
- }
159
- }
160
- }
161
- if (chunk.choices[0]?.finish_reason) {
162
- options.onChunk?.({ type: "stop", stopReason: chunk.choices[0].finish_reason });
163
- }
164
- }
165
- const toolCalls = [];
166
- for (const [, tc] of toolCallsMap) {
167
- let args = {};
168
- try {
169
- args = JSON.parse(tc.args || "{}");
170
- } catch {
171
- }
172
- toolCalls.push({ id: tc.id, toolName: tc.name, args });
173
- }
174
- const usage = {
175
- promptTokens: streamUsage?.prompt_tokens ?? 0,
176
- completionTokens: streamUsage?.completion_tokens ?? 0,
177
- totalTokens: streamUsage?.total_tokens ?? 0
178
- };
179
- this.recordUsage(usage, options);
180
- return {
181
- text,
182
- toolCalls,
183
- usage,
184
- stopReason: "stop",
185
- ...reasoningContent ? { reasoningContent } : {}
186
- };
187
- } catch (err) {
188
- this.handleApiError(err);
189
- throw err;
190
- }
191
- }
192
- processChoice(choice, usage) {
193
- const text = choice.message.content ?? "";
194
- const toolCalls = [];
195
- if (choice.message.tool_calls) {
196
- for (const tc of choice.message.tool_calls) {
197
- let args = {};
198
- try {
199
- args = JSON.parse(tc.function.arguments || "{}");
200
- } catch {
201
- }
202
- toolCalls.push({
203
- id: tc.id,
204
- toolName: tc.function.name,
205
- args
206
- });
207
- }
208
- }
209
- const reasoningContent = extractReasoningContent(
210
- choice.message
211
- );
212
- return {
213
- text,
214
- toolCalls,
215
- usage,
216
- stopReason: choice.finish_reason ?? void 0,
217
- ...reasoningContent ? { reasoningContent } : {}
218
- };
219
- }
220
- buildMessages(systemPrompt, messages) {
221
- const result = [{ role: "system", content: systemPrompt }];
222
- const needsReasoningBackfill = isDeepSeekThinkingModel(this.model);
223
- for (const msg of messages) {
224
- if (msg.role === "system") continue;
225
- if (msg.role === "assistant") {
226
- const param = { role: "assistant" };
227
- let reasoningContent;
228
- if (typeof msg.content === "string") {
229
- param.content = msg.content;
230
- } else {
231
- const textParts = [];
232
- const toolCalls = [];
233
- for (const block of msg.content) {
234
- if (block.type === "text" && block.text) {
235
- textParts.push(block.text);
236
- } else if (block.type === "tool_use" && block.id && block.name) {
237
- toolCalls.push({
238
- id: block.id,
239
- type: "function",
240
- function: {
241
- name: block.name,
242
- arguments: JSON.stringify(block.input ?? {})
243
- }
244
- });
245
- } else if (block.type === "reasoning" && block.reasoningContent) {
246
- reasoningContent = block.reasoningContent;
247
- }
248
- if (!reasoningContent && block.reasoningContent) {
249
- reasoningContent = block.reasoningContent;
250
- }
251
- }
252
- if (textParts.length) param.content = textParts.join("\n");
253
- if (toolCalls.length) param.tool_calls = toolCalls;
254
- }
255
- if (!reasoningContent && needsReasoningBackfill) {
256
- reasoningContent = "";
257
- }
258
- if (reasoningContent !== void 0) {
259
- param.reasoning_content = reasoningContent;
260
- }
261
- result.push(param);
262
- } else if (msg.role === "tool") {
263
- result.push({
264
- role: "tool",
265
- tool_call_id: msg.tool_call_id ?? "",
266
- content: typeof msg.content === "string" ? msg.content : ""
267
- });
268
- } else {
269
- if (typeof msg.content === "string") {
270
- result.push({ role: "user", content: msg.content });
271
- } else {
272
- const textParts = [];
273
- const toolResults = [];
274
- for (const block of msg.content) {
275
- if (block.type === "tool_result" && block.tool_use_id) {
276
- toolResults.push({
277
- tool_use_id: block.tool_use_id,
278
- content: typeof block.content === "string" ? block.content : ""
279
- });
280
- } else if (block.type === "text" && block.text) {
281
- textParts.push(block.text);
282
- }
283
- }
284
- for (const tr of toolResults) {
285
- result.push({
286
- role: "tool",
287
- tool_call_id: tr.tool_use_id,
288
- content: tr.content
289
- });
290
- }
291
- if (textParts.length > 0) {
292
- result.push({ role: "user", content: textParts.join("\n") });
293
- }
294
- }
295
- }
296
- }
297
- return result;
298
- }
299
- convertTools(tools) {
300
- return tools.map((t) => ({
301
- type: "function",
302
- function: {
303
- name: t.name,
304
- description: t.description,
305
- parameters: t.inputSchema
306
- }
307
- }));
308
- }
309
- handleApiError(err) {
310
- if (err instanceof OpenAI.APIError) {
311
- if (err.status === 429) {
312
- throw new LLMRateLimitError("openai");
313
- }
314
- const msg = (err.message ?? "").toLowerCase();
315
- if (msg.includes("context_length_exceeded") || msg.includes("maximum context length") || msg.includes("too many tokens") || msg.includes("prompt is too long")) {
316
- throw new ContextLimitError("openai");
317
- }
318
- if (err.status === 401 && msg.includes("provider returned error")) {
319
- throw new LLMError(
320
- `OpenAI-compatible endpoint returned 401 "Provider returned error". Two likely causes: (1) the API key is invalid/revoked, or (2) the upstream provider rejects tool calls for this model (common on OpenRouter's gpt-4o-mini route). Verify the key, then try a tool-capable model such as openai/gpt-4.1-mini or anthropic/claude-3.5-haiku.`,
321
- "openai",
322
- { status: err.status }
323
- );
324
- }
325
- throw new LLMError(`OpenAI API error: ${err.message}`, "openai", { status: err.status });
326
- }
327
- throw err;
328
- }
329
- };
330
- function extractReasoningContent(msg) {
331
- const candidate = msg.reasoning_content ?? msg.reasoning;
332
- return typeof candidate === "string" && candidate.length > 0 ? candidate : void 0;
333
- }
334
- function isDeepSeekThinkingModel(model) {
335
- return /^deepseek-v4(?:-|$)/i.test(model);
336
- }
337
-
338
- export {
339
- OpenAIClient
340
- };