@ebowwa/coder 0.7.66 → 0.7.69

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.
package/dist/index.js CHANGED
@@ -4876,6 +4876,69 @@ function convertToolsToOpenAIFormat(tools) {
4876
4876
  }
4877
4877
  }));
4878
4878
  }
4879
+ function convertMessagesToOpenAIFormat(messages) {
4880
+ const result = [];
4881
+ for (const msg of messages) {
4882
+ if (msg.role === "assistant") {
4883
+ const toolCalls = [];
4884
+ const textParts = [];
4885
+ for (const block of msg.content) {
4886
+ if (block.type === "text") {
4887
+ textParts.push(block.text);
4888
+ } else if (block.type === "tool_use") {
4889
+ toolCalls.push({
4890
+ id: block.id,
4891
+ type: "function",
4892
+ function: {
4893
+ name: block.name,
4894
+ arguments: JSON.stringify(block.input)
4895
+ }
4896
+ });
4897
+ } else if (block.type === "thinking" || block.type === "redacted_thinking") {}
4898
+ }
4899
+ const openAIMsg = {
4900
+ role: "assistant",
4901
+ content: textParts.join(`
4902
+ `) || null
4903
+ };
4904
+ if (toolCalls.length > 0) {
4905
+ openAIMsg.tool_calls = toolCalls;
4906
+ }
4907
+ result.push(openAIMsg);
4908
+ } else if (msg.role === "user") {
4909
+ const textParts = [];
4910
+ const toolResults = [];
4911
+ for (const block of msg.content) {
4912
+ if (block.type === "text") {
4913
+ textParts.push(block.text);
4914
+ } else if (block.type === "tool_result") {
4915
+ const contentStr = typeof block.content === "string" ? block.content : block.content.map((c) => c.type === "text" ? c.text : JSON.stringify(c)).join(`
4916
+ `);
4917
+ toolResults.push({
4918
+ tool_use_id: block.tool_use_id,
4919
+ content: contentStr,
4920
+ is_error: block.is_error
4921
+ });
4922
+ }
4923
+ }
4924
+ if (textParts.length > 0) {
4925
+ result.push({
4926
+ role: "user",
4927
+ content: textParts.join(`
4928
+ `)
4929
+ });
4930
+ }
4931
+ for (const tr of toolResults) {
4932
+ result.push({
4933
+ role: "tool",
4934
+ tool_call_id: tr.tool_use_id,
4935
+ content: tr.content
4936
+ });
4937
+ }
4938
+ }
4939
+ }
4940
+ return result;
4941
+ }
4879
4942
  function calculateCost2(model, usage) {
4880
4943
  return calculateCost(model, usage);
4881
4944
  }
@@ -5162,6 +5225,7 @@ async function executeStreamAttempt(request, headers, apiEndpoint, signal, model
5162
5225
  }
5163
5226
  }
5164
5227
  if (choice?.finish_reason) {
5228
+ console.log(`[API] OpenAI finish_reason: ${choice.finish_reason}, content blocks: ${currentContent.length}, hasToolUse: ${!!currentToolUseBlock}`);
5165
5229
  if (currentTextBlock) {
5166
5230
  currentContent.push(currentTextBlock);
5167
5231
  currentTextBlock = null;
@@ -5269,20 +5333,6 @@ async function createMessageStream(messages, options) {
5269
5333
  signal
5270
5334
  } = options;
5271
5335
  const startTime = Date.now();
5272
- const cachedMessages = buildCachedMessages(messages, cacheConfig);
5273
- const cachedSystemPrompt = buildSystemPrompt(systemPrompt, cacheConfig);
5274
- const request = {
5275
- model,
5276
- max_tokens: maxTokens,
5277
- messages: cachedMessages.map((m) => ({
5278
- role: m.role,
5279
- content: m.content
5280
- })),
5281
- stream: true
5282
- };
5283
- if (cachedSystemPrompt) {
5284
- request.system = cachedSystemPrompt;
5285
- }
5286
5336
  const providerInfo = resolveProvider(model);
5287
5337
  let apiEndpoint;
5288
5338
  let headers;
@@ -5312,12 +5362,48 @@ async function createMessageStream(messages, options) {
5312
5362
  "anthropic-version": "2023-06-01"
5313
5363
  };
5314
5364
  }
5365
+ const cachedMessages = buildCachedMessages(messages, cacheConfig);
5366
+ const cachedSystemPrompt = buildSystemPrompt(systemPrompt, cacheConfig);
5367
+ let requestMessages;
5368
+ if (apiFormat === "openai") {
5369
+ const openAIMessages = convertMessagesToOpenAIFormat(cachedMessages);
5370
+ if (cachedSystemPrompt) {
5371
+ const systemText = typeof cachedSystemPrompt === "string" ? cachedSystemPrompt : cachedSystemPrompt.map((b) => b.text).join(`
5372
+
5373
+ `);
5374
+ requestMessages = [
5375
+ { role: "system", content: systemText },
5376
+ ...openAIMessages
5377
+ ];
5378
+ } else {
5379
+ requestMessages = openAIMessages;
5380
+ }
5381
+ } else {
5382
+ requestMessages = cachedMessages.map((m) => ({
5383
+ role: m.role,
5384
+ content: m.content
5385
+ }));
5386
+ }
5387
+ const request = {
5388
+ model,
5389
+ max_tokens: maxTokens,
5390
+ messages: requestMessages,
5391
+ stream: true
5392
+ };
5393
+ if (cachedSystemPrompt && apiFormat === "anthropic") {
5394
+ request.system = cachedSystemPrompt;
5395
+ }
5315
5396
  if (tools && tools.length > 0) {
5316
5397
  if (apiFormat === "openai") {
5317
- request.tools = convertToolsToOpenAIFormat(tools);
5398
+ const openaiTools = convertToolsToOpenAIFormat(tools);
5399
+ request.tools = openaiTools;
5400
+ console.log(`[API] Sending ${tools.length} tools to ${apiFormat} API:`, JSON.stringify(openaiTools).substring(0, 500));
5318
5401
  } else {
5319
5402
  request.tools = tools;
5403
+ console.log(`[API] Sending ${tools.length} tools to ${apiFormat} API (Anthropic format)`);
5320
5404
  }
5405
+ } else {
5406
+ console.log(`[API] No tools being sent to API`);
5321
5407
  }
5322
5408
  const shouldUseExtendedThinking = (extendedThinking?.enabled ?? false) || thinking && thinking.type !== "disabled";
5323
5409
  if (shouldUseExtendedThinking && supportsExtendedThinking(model)) {
@@ -34289,6 +34375,84 @@ var init_stream_highlighter = __esm(() => {
34289
34375
  };
34290
34376
  });
34291
34377
 
34378
+ // packages/src/interfaces/ui/terminal/cli/interactive/scroll-handler.ts
34379
+ function handleScrollEvent(event, currentOffset, totalMessages, config = {}) {
34380
+ const { pageScrollAmount, lineScrollAmount } = { ...DEFAULT_SCROLL_CONFIG, ...config };
34381
+ const maxScroll = Math.max(0, Math.max(totalMessages - 1, 10));
34382
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34383
+ console.error("[ScrollHandler] Event:", {
34384
+ code: event.code,
34385
+ shift: event.shift,
34386
+ ctrl: event.ctrl,
34387
+ alt: event.alt,
34388
+ is_special: event.is_special
34389
+ });
34390
+ }
34391
+ if (KeyEvents.isPageUp(event)) {
34392
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34393
+ console.error("[ScrollHandler] PageUp detected, scrolling up");
34394
+ }
34395
+ return { handled: true, newOffset: Math.min(currentOffset + pageScrollAmount, maxScroll) };
34396
+ }
34397
+ if (KeyEvents.isPageDown(event)) {
34398
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34399
+ console.error("[ScrollHandler] PageDown detected, scrolling down");
34400
+ }
34401
+ return { handled: true, newOffset: Math.max(0, currentOffset - pageScrollAmount) };
34402
+ }
34403
+ if (KeyEvents.isHome(event)) {
34404
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34405
+ console.error("[ScrollHandler] Home detected, resetting to bottom");
34406
+ }
34407
+ return { handled: true, newOffset: 0 };
34408
+ }
34409
+ if (KeyEvents.isUp(event) && event.alt) {
34410
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34411
+ console.error("[ScrollHandler] Alt+Up detected, scrolling up");
34412
+ }
34413
+ return { handled: true, newOffset: Math.min(currentOffset + lineScrollAmount, maxScroll) };
34414
+ }
34415
+ if (KeyEvents.isDown(event) && event.alt) {
34416
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34417
+ console.error("[ScrollHandler] Alt+Down detected, scrolling down");
34418
+ }
34419
+ return { handled: true, newOffset: Math.max(0, currentOffset - lineScrollAmount) };
34420
+ }
34421
+ if (KeyEvents.isUp(event) && event.ctrl) {
34422
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34423
+ console.error("[ScrollHandler] Ctrl+Up detected, scrolling up");
34424
+ }
34425
+ return { handled: true, newOffset: Math.min(currentOffset + lineScrollAmount, maxScroll) };
34426
+ }
34427
+ if (KeyEvents.isDown(event) && event.ctrl) {
34428
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34429
+ console.error("[ScrollHandler] Ctrl+Down detected, scrolling down");
34430
+ }
34431
+ return { handled: true, newOffset: Math.max(0, currentOffset - lineScrollAmount) };
34432
+ }
34433
+ if (KeyEvents.isUp(event) && event.shift) {
34434
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34435
+ console.error("[ScrollHandler] Shift+Up detected, scrolling up");
34436
+ }
34437
+ return { handled: true, newOffset: Math.min(currentOffset + lineScrollAmount, maxScroll) };
34438
+ }
34439
+ if (KeyEvents.isDown(event) && event.shift) {
34440
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34441
+ console.error("[ScrollHandler] Shift+Down detected, scrolling down");
34442
+ }
34443
+ return { handled: true, newOffset: Math.max(0, currentOffset - lineScrollAmount) };
34444
+ }
34445
+ return { handled: false, newOffset: currentOffset };
34446
+ }
34447
+ var DEFAULT_SCROLL_CONFIG;
34448
+ var init_scroll_handler = __esm(() => {
34449
+ init_input_handler();
34450
+ DEFAULT_SCROLL_CONFIG = {
34451
+ pageScrollAmount: 3,
34452
+ lineScrollAmount: 1
34453
+ };
34454
+ });
34455
+
34292
34456
  // packages/src/interfaces/ui/terminal/cli/interactive/interactive-runner.ts
34293
34457
  import process10 from "process";
34294
34458
  function createInitialState() {
@@ -34439,6 +34603,23 @@ class InteractiveRunner {
34439
34603
  this.state = { ...this.state, inputValue: "", cursorPos: 0 };
34440
34604
  return true;
34441
34605
  }
34606
+ if (process10.env.CODER_DEBUG_SCROLL === "1") {
34607
+ console.error("[InteractiveRunner] Key event:", {
34608
+ code: event.code,
34609
+ shift: event.shift,
34610
+ ctrl: event.ctrl,
34611
+ alt: event.alt,
34612
+ is_special: event.is_special
34613
+ });
34614
+ }
34615
+ const scrollResult = handleScrollEvent(event, this.state.scrollOffset, this.messageStore.messages.length);
34616
+ if (process10.env.CODER_DEBUG_SCROLL === "1") {
34617
+ console.error("[InteractiveRunner] Scroll result:", scrollResult);
34618
+ }
34619
+ if (scrollResult.handled) {
34620
+ this.state = { ...this.state, scrollOffset: scrollResult.newOffset };
34621
+ return true;
34622
+ }
34442
34623
  if (KeyEvents.isUp(event)) {
34443
34624
  return this._handleHistoryUp();
34444
34625
  }
@@ -34747,7 +34928,8 @@ class InteractiveRunner {
34747
34928
  searchMode: sessionSelectMode,
34748
34929
  searchQuery: "",
34749
34930
  searchResults,
34750
- searchSelected: 0
34931
+ searchSelected: 0,
34932
+ scrollOffset: this.state.scrollOffset
34751
34933
  };
34752
34934
  }
34753
34935
  _getHelpText(section) {
@@ -34849,6 +35031,7 @@ var init_interactive_runner = __esm(() => {
34849
35031
  init_native();
34850
35032
  init_spinner_frames();
34851
35033
  init_input_handler();
35034
+ init_scroll_handler();
34852
35035
  init_types4();
34853
35036
  });
34854
35037
 
@@ -34878,10 +35061,10 @@ init_cognitive_security();
34878
35061
  init_source();
34879
35062
  import process9 from "process";
34880
35063
 
34881
- // ../../node_modules/.bun/cli-cursor@5.0.0/node_modules/cli-cursor/index.js
35064
+ // ../../node_modules/.bun/ora@8.2.0/node_modules/ora/node_modules/cli-cursor/index.js
34882
35065
  import process5 from "process";
34883
35066
 
34884
- // ../../node_modules/.bun/restore-cursor@5.1.0/node_modules/restore-cursor/index.js
35067
+ // ../../node_modules/.bun/ora@8.2.0/node_modules/ora/node_modules/cli-cursor/node_modules/restore-cursor/index.js
34885
35068
  import process4 from "process";
34886
35069
 
34887
35070
  // ../../node_modules/.bun/mimic-function@5.0.1/node_modules/mimic-function/index.js
@@ -34930,7 +35113,7 @@ function mimicFunction(to, from, { ignoreNonConfigurable = false } = {}) {
34930
35113
  return to;
34931
35114
  }
34932
35115
 
34933
- // ../../node_modules/.bun/onetime@7.0.0/node_modules/onetime/index.js
35116
+ // ../../node_modules/.bun/ora@8.2.0/node_modules/ora/node_modules/cli-cursor/node_modules/restore-cursor/node_modules/onetime/index.js
34934
35117
  var calledFunctions = new WeakMap;
34935
35118
  var onetime = (function_, options = {}) => {
34936
35119
  if (typeof function_ !== "function") {
@@ -34961,7 +35144,7 @@ onetime.callCount = (function_) => {
34961
35144
  };
34962
35145
  var onetime_default = onetime;
34963
35146
 
34964
- // ../../node_modules/.bun/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
35147
+ // ../../node_modules/.bun/ora@8.2.0/node_modules/ora/node_modules/cli-cursor/node_modules/restore-cursor/node_modules/signal-exit/dist/mjs/signals.js
34965
35148
  var signals = [];
34966
35149
  signals.push("SIGHUP", "SIGINT", "SIGTERM");
34967
35150
  if (process.platform !== "win32") {
@@ -34971,7 +35154,7 @@ if (process.platform === "linux") {
34971
35154
  signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
34972
35155
  }
34973
35156
 
34974
- // ../../node_modules/.bun/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.js
35157
+ // ../../node_modules/.bun/ora@8.2.0/node_modules/ora/node_modules/cli-cursor/node_modules/restore-cursor/node_modules/signal-exit/dist/mjs/index.js
34975
35158
  var processOk = (process3) => !!process3 && typeof process3 === "object" && typeof process3.removeListener === "function" && typeof process3.emit === "function" && typeof process3.reallyExit === "function" && typeof process3.listeners === "function" && typeof process3.kill === "function" && typeof process3.pid === "number" && typeof process3.on === "function";
34976
35159
  var kExitEmitter = Symbol.for("signal-exit emitter");
34977
35160
  var global = globalThis;
@@ -35169,7 +35352,7 @@ var {
35169
35352
  unload
35170
35353
  } = signalExitWrap(processOk(process3) ? new SignalExit(process3) : new SignalExitFallback);
35171
35354
 
35172
- // ../../node_modules/.bun/restore-cursor@5.1.0/node_modules/restore-cursor/index.js
35355
+ // ../../node_modules/.bun/ora@8.2.0/node_modules/ora/node_modules/cli-cursor/node_modules/restore-cursor/index.js
35173
35356
  var terminal = process4.stderr.isTTY ? process4.stderr : process4.stdout.isTTY ? process4.stdout : undefined;
35174
35357
  var restoreCursor = terminal ? onetime_default(() => {
35175
35358
  onExit(() => {
@@ -35178,7 +35361,7 @@ var restoreCursor = terminal ? onetime_default(() => {
35178
35361
  }) : () => {};
35179
35362
  var restore_cursor_default = restoreCursor;
35180
35363
 
35181
- // ../../node_modules/.bun/cli-cursor@5.0.0/node_modules/cli-cursor/index.js
35364
+ // ../../node_modules/.bun/ora@8.2.0/node_modules/ora/node_modules/cli-cursor/index.js
35182
35365
  var isHidden = false;
35183
35366
  var cliCursor = {};
35184
35367
  cliCursor.show = (writableStream = process5.stderr) => {
@@ -36231,3 +36414,6 @@ export {
36231
36414
  AskUserQuestionTool,
36232
36415
  AnalyzeImageTool
36233
36416
  };
36417
+
36418
+ //# debugId=4856F1AFA237337364756E2164756E21
36419
+ //# sourceMappingURL=index.js.map