@cjhyy/code-shell 0.1.6 → 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 (154) hide show
  1. package/dist/anthropic-UBSB5AQH.js +1 -0
  2. package/dist/arena/index.js +1 -104
  3. package/dist/arena-OW55ZCHT.js +3 -0
  4. package/dist/bwrap-PVZMLHZR.js +2 -0
  5. package/dist/chunk-2NS3JMNK.js +1 -0
  6. package/dist/chunk-3QP5BQ3L.js +1 -0
  7. package/dist/chunk-B7K2OWKC.js +2 -0
  8. package/dist/chunk-EWWK56K6.js +2 -0
  9. package/dist/chunk-FU7AHZNN.js +1 -0
  10. package/dist/chunk-HIJ2XXGX.js +1 -0
  11. package/dist/chunk-KCXSARAA.js +1 -0
  12. package/dist/chunk-NFH3UQ3E.js +2 -0
  13. package/dist/chunk-NMBYBGC7.js +250 -0
  14. package/dist/chunk-NVAZJ5XS.js +2 -0
  15. package/dist/chunk-O5HFCH2U.js +1 -0
  16. package/dist/chunk-P6JSTIFM.js +1 -0
  17. package/dist/chunk-PGANL6F2.js +3 -0
  18. package/dist/chunk-Q4O2HGWS.js +251 -0
  19. package/dist/chunk-QTWU7UNA.js +5 -0
  20. package/dist/chunk-RP26WO4R.js +1 -0
  21. package/dist/chunk-SNFAPSLA.js +1 -0
  22. package/dist/chunk-T222K6IV.js +18 -0
  23. package/dist/chunk-TKJA6W36.js +3 -0
  24. package/dist/chunk-UDPUTFQT.js +2 -0
  25. package/dist/chunk-W47Z7MGS.js +33 -0
  26. package/dist/chunk-WI6FSWGU.js +1 -0
  27. package/dist/chunk-WOP6MJKW.js +1 -0
  28. package/dist/chunk-XDOWC7EG.js +4 -0
  29. package/dist/chunk-Y2NS6HPO.js +641 -0
  30. package/dist/cli/main.js +303 -22060
  31. package/dist/client-base-6ZZJJYDY.js +1 -0
  32. package/dist/compaction-ECVQVOCT.js +1 -0
  33. package/dist/devtools-SGDUOOM4.js +1 -0
  34. package/dist/engine/engine.d.ts +8 -0
  35. package/dist/export-md-U72T7NW7.js +22 -0
  36. package/dist/file-history-7FQFEQOL.js +1 -0
  37. package/dist/index.d.ts +1 -1
  38. package/dist/index.js +1 -347
  39. package/dist/llm/token-counter.d.ts +17 -0
  40. package/dist/manager-C3TDN6MS.js +1 -0
  41. package/dist/mcp-manager-OP4XYV53.js +1 -0
  42. package/dist/memory-BNI4WEWL.js +1 -0
  43. package/dist/model-cache-HEDXI7UJ.js +1 -0
  44. package/dist/model-fetcher-BJ64META.js +1 -0
  45. package/dist/off-7SDVMMXW.js +1 -0
  46. package/dist/openai-KEWQ54TM.js +1 -0
  47. package/dist/openrouter-models-AM6M52D6.js +1 -0
  48. package/dist/openrouter-sync-5JNBL3Z6.js +1 -0
  49. package/dist/product/index.js +1 -21
  50. package/dist/run/index.js +1 -48
  51. package/dist/seatbelt-WBYROQT6.js +37 -0
  52. package/dist/session/session-manager.d.ts +2 -0
  53. package/dist/session-manager-AGWS5SMJ.js +1 -0
  54. package/dist/settings/schema.d.ts +72 -6
  55. package/dist/tool-summary-5UE62VU4.js +2 -0
  56. package/dist/tool-system/builtin/bash.d.ts +7 -1
  57. package/dist/tool-system/context.d.ts +7 -0
  58. package/dist/tool-system/sandbox/bwrap.d.ts +13 -0
  59. package/dist/tool-system/sandbox/index.d.ts +71 -0
  60. package/dist/tool-system/sandbox/off.d.ts +2 -0
  61. package/dist/tool-system/sandbox/seatbelt.d.ts +18 -0
  62. package/dist/types.d.ts +4 -0
  63. package/dist/ui/components/SessionPicker.d.ts +2 -0
  64. package/dist/ui/components/SpinnerWithVerb.d.ts +2 -2
  65. package/dist/ui/components/StatusLine.d.ts +2 -2
  66. package/dist/updater-OCNU2K2Z.js +1 -0
  67. package/package.json +7 -10
  68. package/dist/anthropic-IBTI4WL2.cjs +0 -10
  69. package/dist/anthropic-PRZZKHEZ.js +0 -10
  70. package/dist/arena/index.cjs +0 -104
  71. package/dist/arena-2LTLIXOL.js +0 -261
  72. package/dist/arena-ADB7DRFI.cjs +0 -261
  73. package/dist/chunk-2YW4FPFG.cjs +0 -101
  74. package/dist/chunk-3OA5G4TM.js +0 -47
  75. package/dist/chunk-3QO25N6E.js +0 -4711
  76. package/dist/chunk-3SBSUOWZ.js +0 -447
  77. package/dist/chunk-52LGZKT3.cjs +0 -47
  78. package/dist/chunk-55XGPMAP.cjs +0 -146
  79. package/dist/chunk-6QVAYW7C.cjs +0 -438
  80. package/dist/chunk-6S4BJ65N.js +0 -113
  81. package/dist/chunk-76HYEPDM.js +0 -307
  82. package/dist/chunk-7BI3V74Y.cjs +0 -447
  83. package/dist/chunk-7EG3V4JY.cjs +0 -113
  84. package/dist/chunk-7JVTYEEC.js +0 -340
  85. package/dist/chunk-7QIM3BKD.js +0 -44
  86. package/dist/chunk-7Y6S3OCX.js +0 -438
  87. package/dist/chunk-ABRRONJ7.js +0 -107
  88. package/dist/chunk-BSW22MPA.js +0 -146
  89. package/dist/chunk-BXCY2FSE.js +0 -203
  90. package/dist/chunk-BZ5TNE7L.js +0 -5128
  91. package/dist/chunk-DDB6QOKJ.cjs +0 -1252
  92. package/dist/chunk-HEKQCI7B.cjs +0 -224
  93. package/dist/chunk-IK4EWJBP.cjs +0 -203
  94. package/dist/chunk-ILHE7XLT.cjs +0 -107
  95. package/dist/chunk-JMR33QVF.cjs +0 -169
  96. package/dist/chunk-KAQHULYN.js +0 -54
  97. package/dist/chunk-KE4EQOWA.js +0 -294
  98. package/dist/chunk-KOVYSDHZ.cjs +0 -340
  99. package/dist/chunk-KS3RYAYL.cjs +0 -45
  100. package/dist/chunk-MD32R22I.js +0 -50
  101. package/dist/chunk-MV7YI4WO.cjs +0 -293
  102. package/dist/chunk-MY5XHADU.cjs +0 -216
  103. package/dist/chunk-NUNC3VFB.cjs +0 -307
  104. package/dist/chunk-PKGRTCCY.js +0 -9092
  105. package/dist/chunk-QARL3IDQ.js +0 -1252
  106. package/dist/chunk-S754JHLR.cjs +0 -54
  107. package/dist/chunk-SFXHZSRF.js +0 -101
  108. package/dist/chunk-SIHHIQLO.js +0 -224
  109. package/dist/chunk-T6VYG46N.js +0 -105
  110. package/dist/chunk-TNLGBJYS.cjs +0 -44
  111. package/dist/chunk-TUY2T5KP.cjs +0 -105
  112. package/dist/chunk-UXOCVJJ6.cjs +0 -9092
  113. package/dist/chunk-VIAGTYYW.js +0 -169
  114. package/dist/chunk-WASS5YWB.js +0 -215
  115. package/dist/chunk-WZJV6DJC.cjs +0 -5128
  116. package/dist/chunk-YIQBXAYU.cjs +0 -264
  117. package/dist/chunk-YKIAELDZ.cjs +0 -4711
  118. package/dist/chunk-ZBPSQCPU.js +0 -264
  119. package/dist/cli/main.cjs +0 -22156
  120. package/dist/client-base-HTF236ZD.cjs +0 -9
  121. package/dist/client-base-QKRKCOWB.js +0 -9
  122. package/dist/compaction-6VU2T643.js +0 -33
  123. package/dist/compaction-OKUNTCA7.cjs +0 -33
  124. package/dist/devtools-T2NIZBJK.cjs +0 -6
  125. package/dist/devtools-YXWHOVKR.js +0 -6
  126. package/dist/export-md-RXDW6F5W.cjs +0 -135
  127. package/dist/export-md-XXKZANW5.js +0 -135
  128. package/dist/file-history-KYPE3ECT.cjs +0 -7
  129. package/dist/file-history-LF4F7X26.js +0 -7
  130. package/dist/index.cjs +0 -347
  131. package/dist/manager-D65VFAPX.js +0 -7
  132. package/dist/manager-TTF5VHJC.cjs +0 -7
  133. package/dist/mcp-manager-QMKWPBZ4.js +0 -8
  134. package/dist/mcp-manager-Z3OKI74O.cjs +0 -8
  135. package/dist/memory-5LWZ6FI2.cjs +0 -9
  136. package/dist/memory-VIJLBAMQ.js +0 -9
  137. package/dist/model-cache-5KIYL5SL.js +0 -13
  138. package/dist/model-cache-OED3IM4R.cjs +0 -13
  139. package/dist/model-fetcher-HKGICACL.js +0 -8
  140. package/dist/model-fetcher-UR6WJOQP.cjs +0 -8
  141. package/dist/openai-JR2WEKOF.js +0 -10
  142. package/dist/openai-YBTOET4O.cjs +0 -10
  143. package/dist/openrouter-models-H56GHBHN.js +0 -15
  144. package/dist/openrouter-models-TWUFWZ5T.cjs +0 -15
  145. package/dist/openrouter-sync-5VMGN6C2.cjs +0 -11
  146. package/dist/openrouter-sync-ALEMF5IU.js +0 -11
  147. package/dist/product/index.cjs +0 -21
  148. package/dist/run/index.cjs +0 -48
  149. package/dist/session-manager-Q22BBMD3.js +0 -8
  150. package/dist/session-manager-XODQVL3C.cjs +0 -8
  151. package/dist/tool-summary-63DPIS7G.cjs +0 -31
  152. package/dist/tool-summary-NP5CDBKG.js +0 -31
  153. package/dist/updater-I7QBW4DP.cjs +0 -17
  154. package/dist/updater-NVME5S3Z.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
- };
@@ -1,44 +0,0 @@
1
- import {
2
- FileRunStore,
3
- RunManager
4
- } from "./chunk-PKGRTCCY.js";
5
- import {
6
- init_esm_shims
7
- } from "./chunk-MD32R22I.js";
8
-
9
- // src/run/index.ts
10
- init_esm_shims();
11
-
12
- // src/run/factory.ts
13
- init_esm_shims();
14
- import { join } from "path";
15
- import { homedir } from "os";
16
- function createRunManager(options) {
17
- const runsDir = options.runsDir ?? join(homedir(), ".code-shell", "runs");
18
- const store = new FileRunStore(runsDir);
19
- return new RunManager({
20
- store,
21
- executor: {
22
- llm: options.llm,
23
- maxTurns: options.maxTurns ?? 30,
24
- maxContextTokens: options.maxContextTokens ?? 2e5,
25
- permissionMode: options.permissionMode ?? "acceptEdits",
26
- sessionStorageDir: options.sessionStorageDir,
27
- mcpServers: options.mcpServers,
28
- enabledBuiltinTools: options.enabledBuiltinTools,
29
- disabledBuiltinTools: options.disabledBuiltinTools,
30
- customSystemPrompt: options.customSystemPrompt,
31
- appendSystemPrompt: options.appendSystemPrompt,
32
- hooks: options.hooks
33
- },
34
- concurrency: options.concurrency ?? 1,
35
- runsDir,
36
- evaluator: options.evaluator,
37
- defaultTags: options.defaultTags,
38
- defaultMetadata: options.defaultMetadata
39
- });
40
- }
41
-
42
- export {
43
- createRunManager
44
- };