claudish 3.3.4 → 3.3.5

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 +97 -28
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -57065,17 +57065,17 @@ 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
57081
  const content = [];
@@ -57089,16 +57089,17 @@ class OpenAIHandler {
57089
57089
  if (toolCall.type === "function") {
57090
57090
  content.push({
57091
57091
  type: "function_call",
57092
- id: toolCall.id,
57092
+ call_id: toolCall.id,
57093
57093
  name: toolCall.function.name,
57094
57094
  arguments: toolCall.function.arguments
57095
57095
  });
57096
57096
  }
57097
57097
  }
57098
- return { role: "assistant", content };
57098
+ result.push({ role: "assistant", content });
57099
+ continue;
57099
57100
  }
57100
57101
  if (typeof msg.content === "string") {
57101
- return {
57102
+ result.push({
57102
57103
  role: msg.role,
57103
57104
  content: [
57104
57105
  {
@@ -57106,7 +57107,8 @@ class OpenAIHandler {
57106
57107
  text: msg.content
57107
57108
  }
57108
57109
  ]
57109
- };
57110
+ });
57111
+ continue;
57110
57112
  }
57111
57113
  if (Array.isArray(msg.content)) {
57112
57114
  const convertedContent = msg.content.map((block) => {
@@ -57117,20 +57119,23 @@ class OpenAIHandler {
57117
57119
  };
57118
57120
  }
57119
57121
  if (block.type === "image_url") {
57122
+ const imageUrl = typeof block.image_url === "string" ? block.image_url : block.image_url?.url || block.image_url;
57120
57123
  return {
57121
57124
  type: "input_image",
57122
- image_url: block.image_url
57125
+ image_url: imageUrl
57123
57126
  };
57124
57127
  }
57125
57128
  return block;
57126
57129
  });
57127
- return {
57130
+ result.push({
57128
57131
  role: msg.role,
57129
57132
  content: convertedContent
57130
- };
57133
+ });
57134
+ continue;
57131
57135
  }
57132
- return msg;
57133
- });
57136
+ result.push(msg);
57137
+ }
57138
+ return result;
57134
57139
  }
57135
57140
  buildResponsesPayload(claudeRequest, messages, tools) {
57136
57141
  const convertedMessages = this.convertMessagesToResponsesAPI(messages);
@@ -57168,9 +57173,12 @@ class OpenAIHandler {
57168
57173
  const encoder = new TextEncoder;
57169
57174
  const decoder = new TextDecoder;
57170
57175
  let buffer = "";
57171
- let contentIndex = 0;
57176
+ let blockIndex = 0;
57172
57177
  let inputTokens = 0;
57173
57178
  let outputTokens = 0;
57179
+ let hasTextContent = false;
57180
+ let hasToolUse = false;
57181
+ const functionCalls = new Map;
57174
57182
  const stream = new ReadableStream({
57175
57183
  start: async (controller) => {
57176
57184
  const messageStart = {
@@ -57209,48 +57217,109 @@ data: ${JSON.stringify(messageStart)}
57209
57217
  try {
57210
57218
  const event = JSON.parse(data);
57211
57219
  if (event.type === "response.output_text.delta") {
57212
- if (contentIndex === 0) {
57220
+ if (!hasTextContent) {
57213
57221
  const blockStart = {
57214
57222
  type: "content_block_start",
57215
- index: 0,
57223
+ index: blockIndex,
57216
57224
  content_block: { type: "text", text: "" }
57217
57225
  };
57218
57226
  controller.enqueue(encoder.encode(`event: content_block_start
57219
57227
  data: ${JSON.stringify(blockStart)}
57220
57228
 
57221
57229
  `));
57222
- contentIndex = 1;
57230
+ hasTextContent = true;
57223
57231
  }
57224
57232
  const delta = {
57225
57233
  type: "content_block_delta",
57226
- index: 0,
57234
+ index: blockIndex,
57227
57235
  delta: { type: "text_delta", text: event.delta || "" }
57228
57236
  };
57229
57237
  controller.enqueue(encoder.encode(`event: content_block_delta
57230
57238
  data: ${JSON.stringify(delta)}
57231
57239
 
57232
57240
  `));
57241
+ } else if (event.type === "response.output_item.added") {
57242
+ if (event.item?.type === "function_call") {
57243
+ const callId = event.item.call_id || event.item.id;
57244
+ const fnIndex = blockIndex + functionCalls.size + (hasTextContent ? 1 : 0);
57245
+ functionCalls.set(callId, {
57246
+ name: event.item.name || "",
57247
+ arguments: "",
57248
+ index: fnIndex
57249
+ });
57250
+ if (hasTextContent && !hasToolUse) {
57251
+ const blockStop = { type: "content_block_stop", index: blockIndex };
57252
+ controller.enqueue(encoder.encode(`event: content_block_stop
57253
+ data: ${JSON.stringify(blockStop)}
57254
+
57255
+ `));
57256
+ blockIndex++;
57257
+ }
57258
+ const toolStart = {
57259
+ type: "content_block_start",
57260
+ index: fnIndex,
57261
+ content_block: {
57262
+ type: "tool_use",
57263
+ id: callId,
57264
+ name: event.item.name || "",
57265
+ input: {}
57266
+ }
57267
+ };
57268
+ controller.enqueue(encoder.encode(`event: content_block_start
57269
+ data: ${JSON.stringify(toolStart)}
57270
+
57271
+ `));
57272
+ hasToolUse = true;
57273
+ }
57274
+ } else if (event.type === "response.function_call_arguments.delta") {
57275
+ const callId = event.call_id || event.item_id;
57276
+ const fnCall = functionCalls.get(callId);
57277
+ if (fnCall) {
57278
+ fnCall.arguments += event.delta || "";
57279
+ const delta = {
57280
+ type: "content_block_delta",
57281
+ index: fnCall.index,
57282
+ delta: { type: "input_json_delta", partial_json: event.delta || "" }
57283
+ };
57284
+ controller.enqueue(encoder.encode(`event: content_block_delta
57285
+ data: ${JSON.stringify(delta)}
57286
+
57287
+ `));
57288
+ }
57289
+ } else if (event.type === "response.output_item.done") {
57290
+ if (event.item?.type === "function_call") {
57291
+ const callId = event.item.call_id || event.item.id;
57292
+ const fnCall = functionCalls.get(callId);
57293
+ if (fnCall) {
57294
+ const blockStop = { type: "content_block_stop", index: fnCall.index };
57295
+ controller.enqueue(encoder.encode(`event: content_block_stop
57296
+ data: ${JSON.stringify(blockStop)}
57297
+
57298
+ `));
57299
+ }
57300
+ }
57233
57301
  } else if (event.type === "response.completed") {
57234
57302
  if (event.response?.usage) {
57235
57303
  inputTokens = event.response.usage.input_tokens || 0;
57236
57304
  outputTokens = event.response.usage.output_tokens || 0;
57237
57305
  }
57238
- } else if (event.type === "response.function_call_arguments.delta") {}
57306
+ }
57239
57307
  } catch (parseError) {
57240
57308
  log(`[OpenAIHandler] Error parsing Responses event: ${parseError}`);
57241
57309
  }
57242
57310
  }
57243
57311
  }
57244
- if (contentIndex > 0) {
57245
- const blockStop = { type: "content_block_stop", index: 0 };
57312
+ if (hasTextContent && !hasToolUse) {
57313
+ const blockStop = { type: "content_block_stop", index: blockIndex };
57246
57314
  controller.enqueue(encoder.encode(`event: content_block_stop
57247
57315
  data: ${JSON.stringify(blockStop)}
57248
57316
 
57249
57317
  `));
57250
57318
  }
57319
+ const stopReason = hasToolUse ? "tool_use" : "end_turn";
57251
57320
  const messageDelta = {
57252
57321
  type: "message_delta",
57253
- delta: { stop_reason: "end_turn", stop_sequence: null },
57322
+ delta: { stop_reason: stopReason, stop_sequence: null },
57254
57323
  usage: { output_tokens: outputTokens }
57255
57324
  };
57256
57325
  controller.enqueue(encoder.encode(`event: message_delta
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claudish",
3
- "version": "3.3.4",
3
+ "version": "3.3.5",
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",