claudish 3.3.4 → 3.3.6

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 (2) hide show
  1. package/dist/index.js +111 -33
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -57065,40 +57065,45 @@ class OpenAIHandler {
57065
57065
  return payload;
57066
57066
  }
57067
57067
  convertMessagesToResponsesAPI(messages) {
57068
- return messages.filter((msg) => msg.role !== "system").map((msg) => {
57068
+ const result = [];
57069
+ for (const msg of messages) {
57070
+ if (msg.role === "system")
57071
+ continue;
57069
57072
  if (msg.role === "tool") {
57070
- return {
57071
- role: "user",
57072
- content: [
57073
- {
57074
- type: "input_text",
57075
- text: `[Tool Result for ${msg.tool_call_id}]: ${typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)}`
57076
- }
57077
- ]
57078
- };
57073
+ result.push({
57074
+ type: "function_call_output",
57075
+ call_id: msg.tool_call_id,
57076
+ output: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
57077
+ });
57078
+ continue;
57079
57079
  }
57080
57080
  if (msg.role === "assistant" && msg.tool_calls) {
57081
- const content = [];
57082
57081
  if (msg.content) {
57083
57082
  const textContent = typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content);
57084
57083
  if (textContent) {
57085
- content.push({ type: "output_text", text: textContent });
57084
+ result.push({
57085
+ type: "message",
57086
+ role: "assistant",
57087
+ content: [{ type: "output_text", text: textContent }]
57088
+ });
57086
57089
  }
57087
57090
  }
57088
57091
  for (const toolCall of msg.tool_calls) {
57089
57092
  if (toolCall.type === "function") {
57090
- content.push({
57093
+ result.push({
57091
57094
  type: "function_call",
57092
- id: toolCall.id,
57095
+ call_id: toolCall.id,
57093
57096
  name: toolCall.function.name,
57094
- arguments: toolCall.function.arguments
57097
+ arguments: toolCall.function.arguments,
57098
+ status: "completed"
57095
57099
  });
57096
57100
  }
57097
57101
  }
57098
- return { role: "assistant", content };
57102
+ continue;
57099
57103
  }
57100
57104
  if (typeof msg.content === "string") {
57101
- return {
57105
+ result.push({
57106
+ type: "message",
57102
57107
  role: msg.role,
57103
57108
  content: [
57104
57109
  {
@@ -57106,7 +57111,8 @@ class OpenAIHandler {
57106
57111
  text: msg.content
57107
57112
  }
57108
57113
  ]
57109
- };
57114
+ });
57115
+ continue;
57110
57116
  }
57111
57117
  if (Array.isArray(msg.content)) {
57112
57118
  const convertedContent = msg.content.map((block) => {
@@ -57117,20 +57123,28 @@ class OpenAIHandler {
57117
57123
  };
57118
57124
  }
57119
57125
  if (block.type === "image_url") {
57126
+ const imageUrl = typeof block.image_url === "string" ? block.image_url : block.image_url?.url || block.image_url;
57120
57127
  return {
57121
57128
  type: "input_image",
57122
- image_url: block.image_url
57129
+ image_url: imageUrl
57123
57130
  };
57124
57131
  }
57125
57132
  return block;
57126
57133
  });
57127
- return {
57134
+ result.push({
57135
+ type: "message",
57128
57136
  role: msg.role,
57129
57137
  content: convertedContent
57130
- };
57138
+ });
57139
+ continue;
57131
57140
  }
57132
- return msg;
57133
- });
57141
+ if (msg.role) {
57142
+ result.push({ type: "message", ...msg });
57143
+ } else {
57144
+ result.push(msg);
57145
+ }
57146
+ }
57147
+ return result;
57134
57148
  }
57135
57149
  buildResponsesPayload(claudeRequest, messages, tools) {
57136
57150
  const convertedMessages = this.convertMessagesToResponsesAPI(messages);
@@ -57168,9 +57182,12 @@ class OpenAIHandler {
57168
57182
  const encoder = new TextEncoder;
57169
57183
  const decoder = new TextDecoder;
57170
57184
  let buffer = "";
57171
- let contentIndex = 0;
57185
+ let blockIndex = 0;
57172
57186
  let inputTokens = 0;
57173
57187
  let outputTokens = 0;
57188
+ let hasTextContent = false;
57189
+ let hasToolUse = false;
57190
+ const functionCalls = new Map;
57174
57191
  const stream = new ReadableStream({
57175
57192
  start: async (controller) => {
57176
57193
  const messageStart = {
@@ -57209,48 +57226,109 @@ data: ${JSON.stringify(messageStart)}
57209
57226
  try {
57210
57227
  const event = JSON.parse(data);
57211
57228
  if (event.type === "response.output_text.delta") {
57212
- if (contentIndex === 0) {
57229
+ if (!hasTextContent) {
57213
57230
  const blockStart = {
57214
57231
  type: "content_block_start",
57215
- index: 0,
57232
+ index: blockIndex,
57216
57233
  content_block: { type: "text", text: "" }
57217
57234
  };
57218
57235
  controller.enqueue(encoder.encode(`event: content_block_start
57219
57236
  data: ${JSON.stringify(blockStart)}
57220
57237
 
57221
57238
  `));
57222
- contentIndex = 1;
57239
+ hasTextContent = true;
57223
57240
  }
57224
57241
  const delta = {
57225
57242
  type: "content_block_delta",
57226
- index: 0,
57243
+ index: blockIndex,
57227
57244
  delta: { type: "text_delta", text: event.delta || "" }
57228
57245
  };
57229
57246
  controller.enqueue(encoder.encode(`event: content_block_delta
57230
57247
  data: ${JSON.stringify(delta)}
57231
57248
 
57232
57249
  `));
57250
+ } else if (event.type === "response.output_item.added") {
57251
+ if (event.item?.type === "function_call") {
57252
+ const callId = event.item.call_id || event.item.id;
57253
+ const fnIndex = blockIndex + functionCalls.size + (hasTextContent ? 1 : 0);
57254
+ functionCalls.set(callId, {
57255
+ name: event.item.name || "",
57256
+ arguments: "",
57257
+ index: fnIndex
57258
+ });
57259
+ if (hasTextContent && !hasToolUse) {
57260
+ const blockStop = { type: "content_block_stop", index: blockIndex };
57261
+ controller.enqueue(encoder.encode(`event: content_block_stop
57262
+ data: ${JSON.stringify(blockStop)}
57263
+
57264
+ `));
57265
+ blockIndex++;
57266
+ }
57267
+ const toolStart = {
57268
+ type: "content_block_start",
57269
+ index: fnIndex,
57270
+ content_block: {
57271
+ type: "tool_use",
57272
+ id: callId,
57273
+ name: event.item.name || "",
57274
+ input: {}
57275
+ }
57276
+ };
57277
+ controller.enqueue(encoder.encode(`event: content_block_start
57278
+ data: ${JSON.stringify(toolStart)}
57279
+
57280
+ `));
57281
+ hasToolUse = true;
57282
+ }
57283
+ } else if (event.type === "response.function_call_arguments.delta") {
57284
+ const callId = event.call_id || event.item_id;
57285
+ const fnCall = functionCalls.get(callId);
57286
+ if (fnCall) {
57287
+ fnCall.arguments += event.delta || "";
57288
+ const delta = {
57289
+ type: "content_block_delta",
57290
+ index: fnCall.index,
57291
+ delta: { type: "input_json_delta", partial_json: event.delta || "" }
57292
+ };
57293
+ controller.enqueue(encoder.encode(`event: content_block_delta
57294
+ data: ${JSON.stringify(delta)}
57295
+
57296
+ `));
57297
+ }
57298
+ } else if (event.type === "response.output_item.done") {
57299
+ if (event.item?.type === "function_call") {
57300
+ const callId = event.item.call_id || event.item.id;
57301
+ const fnCall = functionCalls.get(callId);
57302
+ if (fnCall) {
57303
+ const blockStop = { type: "content_block_stop", index: fnCall.index };
57304
+ controller.enqueue(encoder.encode(`event: content_block_stop
57305
+ data: ${JSON.stringify(blockStop)}
57306
+
57307
+ `));
57308
+ }
57309
+ }
57233
57310
  } else if (event.type === "response.completed") {
57234
57311
  if (event.response?.usage) {
57235
57312
  inputTokens = event.response.usage.input_tokens || 0;
57236
57313
  outputTokens = event.response.usage.output_tokens || 0;
57237
57314
  }
57238
- } else if (event.type === "response.function_call_arguments.delta") {}
57315
+ }
57239
57316
  } catch (parseError) {
57240
57317
  log(`[OpenAIHandler] Error parsing Responses event: ${parseError}`);
57241
57318
  }
57242
57319
  }
57243
57320
  }
57244
- if (contentIndex > 0) {
57245
- const blockStop = { type: "content_block_stop", index: 0 };
57321
+ if (hasTextContent && !hasToolUse) {
57322
+ const blockStop = { type: "content_block_stop", index: blockIndex };
57246
57323
  controller.enqueue(encoder.encode(`event: content_block_stop
57247
57324
  data: ${JSON.stringify(blockStop)}
57248
57325
 
57249
57326
  `));
57250
57327
  }
57328
+ const stopReason = hasToolUse ? "tool_use" : "end_turn";
57251
57329
  const messageDelta = {
57252
57330
  type: "message_delta",
57253
- delta: { stop_reason: "end_turn", stop_sequence: null },
57331
+ delta: { stop_reason: stopReason, stop_sequence: null },
57254
57332
  usage: { output_tokens: outputTokens }
57255
57333
  };
57256
57334
  controller.enqueue(encoder.encode(`event: message_delta
@@ -59369,7 +59447,7 @@ function printAvailableModelsJSON() {
59369
59447
  console.log(JSON.stringify(output, null, 2));
59370
59448
  }
59371
59449
  }
59372
- var __filename6, __dirname6, VERSION = "3.3.2", CACHE_MAX_AGE_DAYS3 = 2, MODELS_JSON_PATH, ALL_MODELS_JSON_PATH2;
59450
+ var __filename6, __dirname6, VERSION = "3.3.5", CACHE_MAX_AGE_DAYS3 = 2, MODELS_JSON_PATH, ALL_MODELS_JSON_PATH2;
59373
59451
  var init_cli = __esm(() => {
59374
59452
  init_dist11();
59375
59453
  init_model_loader2();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claudish",
3
- "version": "3.3.4",
3
+ "version": "3.3.6",
4
4
  "description": "Run Claude Code with any model - OpenRouter, Ollama, LM Studio & local models",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",