@ebowwa/coder 0.7.66 → 0.7.68

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
  }
@@ -5269,20 +5332,6 @@ async function createMessageStream(messages, options) {
5269
5332
  signal
5270
5333
  } = options;
5271
5334
  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
5335
  const providerInfo = resolveProvider(model);
5287
5336
  let apiEndpoint;
5288
5337
  let headers;
@@ -5312,6 +5361,37 @@ async function createMessageStream(messages, options) {
5312
5361
  "anthropic-version": "2023-06-01"
5313
5362
  };
5314
5363
  }
5364
+ const cachedMessages = buildCachedMessages(messages, cacheConfig);
5365
+ const cachedSystemPrompt = buildSystemPrompt(systemPrompt, cacheConfig);
5366
+ let requestMessages;
5367
+ if (apiFormat === "openai") {
5368
+ const openAIMessages = convertMessagesToOpenAIFormat(cachedMessages);
5369
+ if (cachedSystemPrompt) {
5370
+ const systemText = typeof cachedSystemPrompt === "string" ? cachedSystemPrompt : cachedSystemPrompt.map((b) => b.text).join(`
5371
+
5372
+ `);
5373
+ requestMessages = [
5374
+ { role: "system", content: systemText },
5375
+ ...openAIMessages
5376
+ ];
5377
+ } else {
5378
+ requestMessages = openAIMessages;
5379
+ }
5380
+ } else {
5381
+ requestMessages = cachedMessages.map((m) => ({
5382
+ role: m.role,
5383
+ content: m.content
5384
+ }));
5385
+ }
5386
+ const request = {
5387
+ model,
5388
+ max_tokens: maxTokens,
5389
+ messages: requestMessages,
5390
+ stream: true
5391
+ };
5392
+ if (cachedSystemPrompt && apiFormat === "anthropic") {
5393
+ request.system = cachedSystemPrompt;
5394
+ }
5315
5395
  if (tools && tools.length > 0) {
5316
5396
  if (apiFormat === "openai") {
5317
5397
  request.tools = convertToolsToOpenAIFormat(tools);
@@ -34289,6 +34369,84 @@ var init_stream_highlighter = __esm(() => {
34289
34369
  };
34290
34370
  });
34291
34371
 
34372
+ // packages/src/interfaces/ui/terminal/cli/interactive/scroll-handler.ts
34373
+ function handleScrollEvent(event, currentOffset, totalMessages, config = {}) {
34374
+ const { pageScrollAmount, lineScrollAmount } = { ...DEFAULT_SCROLL_CONFIG, ...config };
34375
+ const maxScroll = Math.max(0, Math.max(totalMessages - 1, 10));
34376
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34377
+ console.error("[ScrollHandler] Event:", {
34378
+ code: event.code,
34379
+ shift: event.shift,
34380
+ ctrl: event.ctrl,
34381
+ alt: event.alt,
34382
+ is_special: event.is_special
34383
+ });
34384
+ }
34385
+ if (KeyEvents.isPageUp(event)) {
34386
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34387
+ console.error("[ScrollHandler] PageUp detected, scrolling up");
34388
+ }
34389
+ return { handled: true, newOffset: Math.min(currentOffset + pageScrollAmount, maxScroll) };
34390
+ }
34391
+ if (KeyEvents.isPageDown(event)) {
34392
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34393
+ console.error("[ScrollHandler] PageDown detected, scrolling down");
34394
+ }
34395
+ return { handled: true, newOffset: Math.max(0, currentOffset - pageScrollAmount) };
34396
+ }
34397
+ if (KeyEvents.isHome(event)) {
34398
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34399
+ console.error("[ScrollHandler] Home detected, resetting to bottom");
34400
+ }
34401
+ return { handled: true, newOffset: 0 };
34402
+ }
34403
+ if (KeyEvents.isUp(event) && event.alt) {
34404
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34405
+ console.error("[ScrollHandler] Alt+Up detected, scrolling up");
34406
+ }
34407
+ return { handled: true, newOffset: Math.min(currentOffset + lineScrollAmount, maxScroll) };
34408
+ }
34409
+ if (KeyEvents.isDown(event) && event.alt) {
34410
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34411
+ console.error("[ScrollHandler] Alt+Down detected, scrolling down");
34412
+ }
34413
+ return { handled: true, newOffset: Math.max(0, currentOffset - lineScrollAmount) };
34414
+ }
34415
+ if (KeyEvents.isUp(event) && event.ctrl) {
34416
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34417
+ console.error("[ScrollHandler] Ctrl+Up detected, scrolling up");
34418
+ }
34419
+ return { handled: true, newOffset: Math.min(currentOffset + lineScrollAmount, maxScroll) };
34420
+ }
34421
+ if (KeyEvents.isDown(event) && event.ctrl) {
34422
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34423
+ console.error("[ScrollHandler] Ctrl+Down detected, scrolling down");
34424
+ }
34425
+ return { handled: true, newOffset: Math.max(0, currentOffset - lineScrollAmount) };
34426
+ }
34427
+ if (KeyEvents.isUp(event) && event.shift) {
34428
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34429
+ console.error("[ScrollHandler] Shift+Up detected, scrolling up");
34430
+ }
34431
+ return { handled: true, newOffset: Math.min(currentOffset + lineScrollAmount, maxScroll) };
34432
+ }
34433
+ if (KeyEvents.isDown(event) && event.shift) {
34434
+ if (process.env.CODER_DEBUG_SCROLL === "1") {
34435
+ console.error("[ScrollHandler] Shift+Down detected, scrolling down");
34436
+ }
34437
+ return { handled: true, newOffset: Math.max(0, currentOffset - lineScrollAmount) };
34438
+ }
34439
+ return { handled: false, newOffset: currentOffset };
34440
+ }
34441
+ var DEFAULT_SCROLL_CONFIG;
34442
+ var init_scroll_handler = __esm(() => {
34443
+ init_input_handler();
34444
+ DEFAULT_SCROLL_CONFIG = {
34445
+ pageScrollAmount: 3,
34446
+ lineScrollAmount: 1
34447
+ };
34448
+ });
34449
+
34292
34450
  // packages/src/interfaces/ui/terminal/cli/interactive/interactive-runner.ts
34293
34451
  import process10 from "process";
34294
34452
  function createInitialState() {
@@ -34439,6 +34597,23 @@ class InteractiveRunner {
34439
34597
  this.state = { ...this.state, inputValue: "", cursorPos: 0 };
34440
34598
  return true;
34441
34599
  }
34600
+ if (process10.env.CODER_DEBUG_SCROLL === "1") {
34601
+ console.error("[InteractiveRunner] Key event:", {
34602
+ code: event.code,
34603
+ shift: event.shift,
34604
+ ctrl: event.ctrl,
34605
+ alt: event.alt,
34606
+ is_special: event.is_special
34607
+ });
34608
+ }
34609
+ const scrollResult = handleScrollEvent(event, this.state.scrollOffset, this.messageStore.messages.length);
34610
+ if (process10.env.CODER_DEBUG_SCROLL === "1") {
34611
+ console.error("[InteractiveRunner] Scroll result:", scrollResult);
34612
+ }
34613
+ if (scrollResult.handled) {
34614
+ this.state = { ...this.state, scrollOffset: scrollResult.newOffset };
34615
+ return true;
34616
+ }
34442
34617
  if (KeyEvents.isUp(event)) {
34443
34618
  return this._handleHistoryUp();
34444
34619
  }
@@ -34736,18 +34911,19 @@ class InteractiveRunner {
34736
34911
  })) : [];
34737
34912
  return {
34738
34913
  messages: renderMessages,
34739
- inputValue,
34740
- cursorPos,
34741
- statusText,
34742
- isLoading,
34743
- streamingText,
34914
+ input_value: inputValue,
34915
+ cursor_pos: cursorPos,
34916
+ status_text: statusText,
34917
+ is_loading: isLoading,
34918
+ streaming_text: streamingText,
34744
34919
  model: this.props.model,
34745
- showHelp: helpMode,
34746
- helpText,
34747
- searchMode: sessionSelectMode,
34748
- searchQuery: "",
34749
- searchResults,
34750
- searchSelected: 0
34920
+ show_help: helpMode,
34921
+ help_text: helpText,
34922
+ search_mode: sessionSelectMode,
34923
+ search_query: "",
34924
+ search_results: searchResults,
34925
+ search_selected: 0,
34926
+ scroll_offset: this.state.scrollOffset
34751
34927
  };
34752
34928
  }
34753
34929
  _getHelpText(section) {
@@ -34849,6 +35025,7 @@ var init_interactive_runner = __esm(() => {
34849
35025
  init_native();
34850
35026
  init_spinner_frames();
34851
35027
  init_input_handler();
35028
+ init_scroll_handler();
34852
35029
  init_types4();
34853
35030
  });
34854
35031
 
@@ -34878,10 +35055,10 @@ init_cognitive_security();
34878
35055
  init_source();
34879
35056
  import process9 from "process";
34880
35057
 
34881
- // ../../node_modules/.bun/cli-cursor@5.0.0/node_modules/cli-cursor/index.js
35058
+ // ../../node_modules/.bun/ora@8.2.0/node_modules/ora/node_modules/cli-cursor/index.js
34882
35059
  import process5 from "process";
34883
35060
 
34884
- // ../../node_modules/.bun/restore-cursor@5.1.0/node_modules/restore-cursor/index.js
35061
+ // ../../node_modules/.bun/ora@8.2.0/node_modules/ora/node_modules/cli-cursor/node_modules/restore-cursor/index.js
34885
35062
  import process4 from "process";
34886
35063
 
34887
35064
  // ../../node_modules/.bun/mimic-function@5.0.1/node_modules/mimic-function/index.js
@@ -34930,7 +35107,7 @@ function mimicFunction(to, from, { ignoreNonConfigurable = false } = {}) {
34930
35107
  return to;
34931
35108
  }
34932
35109
 
34933
- // ../../node_modules/.bun/onetime@7.0.0/node_modules/onetime/index.js
35110
+ // ../../node_modules/.bun/ora@8.2.0/node_modules/ora/node_modules/cli-cursor/node_modules/restore-cursor/node_modules/onetime/index.js
34934
35111
  var calledFunctions = new WeakMap;
34935
35112
  var onetime = (function_, options = {}) => {
34936
35113
  if (typeof function_ !== "function") {
@@ -34961,7 +35138,7 @@ onetime.callCount = (function_) => {
34961
35138
  };
34962
35139
  var onetime_default = onetime;
34963
35140
 
34964
- // ../../node_modules/.bun/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
35141
+ // ../../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
35142
  var signals = [];
34966
35143
  signals.push("SIGHUP", "SIGINT", "SIGTERM");
34967
35144
  if (process.platform !== "win32") {
@@ -34971,7 +35148,7 @@ if (process.platform === "linux") {
34971
35148
  signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
34972
35149
  }
34973
35150
 
34974
- // ../../node_modules/.bun/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.js
35151
+ // ../../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
35152
  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
35153
  var kExitEmitter = Symbol.for("signal-exit emitter");
34977
35154
  var global = globalThis;
@@ -35169,7 +35346,7 @@ var {
35169
35346
  unload
35170
35347
  } = signalExitWrap(processOk(process3) ? new SignalExit(process3) : new SignalExitFallback);
35171
35348
 
35172
- // ../../node_modules/.bun/restore-cursor@5.1.0/node_modules/restore-cursor/index.js
35349
+ // ../../node_modules/.bun/ora@8.2.0/node_modules/ora/node_modules/cli-cursor/node_modules/restore-cursor/index.js
35173
35350
  var terminal = process4.stderr.isTTY ? process4.stderr : process4.stdout.isTTY ? process4.stdout : undefined;
35174
35351
  var restoreCursor = terminal ? onetime_default(() => {
35175
35352
  onExit(() => {
@@ -35178,7 +35355,7 @@ var restoreCursor = terminal ? onetime_default(() => {
35178
35355
  }) : () => {};
35179
35356
  var restore_cursor_default = restoreCursor;
35180
35357
 
35181
- // ../../node_modules/.bun/cli-cursor@5.0.0/node_modules/cli-cursor/index.js
35358
+ // ../../node_modules/.bun/ora@8.2.0/node_modules/ora/node_modules/cli-cursor/index.js
35182
35359
  var isHidden = false;
35183
35360
  var cliCursor = {};
35184
35361
  cliCursor.show = (writableStream = process5.stderr) => {
@@ -36231,3 +36408,6 @@ export {
36231
36408
  AskUserQuestionTool,
36232
36409
  AnalyzeImageTool
36233
36410
  };
36411
+
36412
+ //# debugId=0DF7A0DEA7CF8E8D64756E2164756E21
36413
+ //# sourceMappingURL=index.js.map