Skip to content

Commit a96de42

Browse files
committed
Bug fixes
1 parent 97efa95 commit a96de42

File tree

3 files changed

+66
-15
lines changed

3 files changed

+66
-15
lines changed

apps/sim/app/api/wand/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ Use this context to calculate relative dates like "yesterday", "last week", "beg
262262
)
263263

264264
const apiUrl = useWandAzure
265-
? `${azureEndpoint}/openai/v1/responses?api-version=${azureApiVersion}`
265+
? `${azureEndpoint?.replace(/\/$/, '')}/openai/v1/responses?api-version=${azureApiVersion}`
266266
: 'https://api.openai.com/v1/responses'
267267

268268
const headers: Record<string, string> = {
@@ -461,7 +461,7 @@ Use this context to calculate relative dates like "yesterday", "last week", "beg
461461
}
462462

463463
const apiUrl = useWandAzure
464-
? `${azureEndpoint}/openai/v1/responses?api-version=${azureApiVersion}`
464+
? `${azureEndpoint?.replace(/\/$/, '')}/openai/v1/responses?api-version=${azureApiVersion}`
465465
: 'https://api.openai.com/v1/responses'
466466

467467
const headers: Record<string, string> = {

apps/sim/lib/copilot/chat-title.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export async function generateChatTitle(message: string): Promise<string | null>
2424

2525
try {
2626
const apiUrl = useChatTitleAzure
27-
? `${azureEndpoint}/openai/v1/responses?api-version=${azureApiVersion}`
27+
? `${azureEndpoint?.replace(/\/$/, '')}/openai/v1/responses?api-version=${azureApiVersion}`
2828
: 'https://api.openai.com/v1/responses'
2929

3030
const headers: Record<string, string> = {

apps/sim/providers/responses-utils.ts

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ export function buildResponsesInputFromMessages(messages: Message[]): ResponsesI
5757
continue
5858
}
5959

60-
if (message.content) {
60+
if (
61+
message.content &&
62+
(message.role === 'system' || message.role === 'user' || message.role === 'assistant')
63+
) {
6164
input.push({
6265
role: message.role,
6366
content: message.content,
@@ -200,6 +203,28 @@ export function convertResponseOutputToInputItems(output: unknown): ResponsesInp
200203
content: text,
201204
})
202205
}
206+
207+
const toolCalls = Array.isArray(item.tool_calls) ? item.tool_calls : []
208+
for (const toolCall of toolCalls) {
209+
const callId = toolCall?.id
210+
const name = toolCall?.function?.name ?? toolCall?.name
211+
if (!callId || !name) {
212+
continue
213+
}
214+
215+
const argumentsValue =
216+
typeof toolCall?.function?.arguments === 'string'
217+
? toolCall.function.arguments
218+
: JSON.stringify(toolCall?.function?.arguments ?? {})
219+
220+
items.push({
221+
type: 'function_call',
222+
call_id: callId,
223+
name,
224+
arguments: argumentsValue,
225+
})
226+
}
227+
203228
continue
204229
}
205230

@@ -233,28 +258,54 @@ export function extractResponseToolCalls(output: unknown): ResponsesToolCall[] {
233258
return []
234259
}
235260

236-
return output
237-
.map((item) => {
238-
if (!item || item.type !== 'function_call') {
239-
return null
240-
}
261+
const toolCalls: ResponsesToolCall[] = []
262+
263+
for (const item of output) {
264+
if (!item || typeof item !== 'object') {
265+
continue
266+
}
241267

268+
if (item.type === 'function_call') {
242269
const callId = item.call_id ?? item.id
243270
const name = item.name ?? item.function?.name
244271
if (!callId || !name) {
245-
return null
272+
continue
246273
}
247274

248275
const argumentsValue =
249276
typeof item.arguments === 'string' ? item.arguments : JSON.stringify(item.arguments ?? {})
250277

251-
return {
278+
toolCalls.push({
252279
id: callId,
253280
name,
254281
arguments: argumentsValue,
282+
})
283+
continue
284+
}
285+
286+
if (item.type === 'message' && Array.isArray(item.tool_calls)) {
287+
for (const toolCall of item.tool_calls) {
288+
const callId = toolCall?.id
289+
const name = toolCall?.function?.name ?? toolCall?.name
290+
if (!callId || !name) {
291+
continue
292+
}
293+
294+
const argumentsValue =
295+
typeof toolCall?.function?.arguments === 'string'
296+
? toolCall.function.arguments
297+
: JSON.stringify(toolCall?.function?.arguments ?? {})
298+
299+
toolCalls.push({
300+
id: callId,
301+
name,
302+
arguments: argumentsValue,
303+
})
255304
}
256-
})
257-
.filter(Boolean) as ResponsesToolCall[]
305+
}
306+
}
307+
308+
return toolCalls
258309
}
259310

260311
/**
@@ -269,8 +320,8 @@ export function parseResponsesUsage(usage: any): ResponsesUsageTokens | undefine
269320
const outputTokens = Number(usage.output_tokens ?? 0)
270321
const cachedTokens = Number(usage.input_tokens_details?.cached_tokens ?? 0)
271322
const reasoningTokens = Number(usage.output_tokens_details?.reasoning_tokens ?? 0)
272-
const completionTokens = outputTokens + reasoningTokens
273-
const totalTokens = inputTokens + completionTokens
323+
const completionTokens = outputTokens
324+
const totalTokens = inputTokens + outputTokens
274325

275326
return {
276327
promptTokens: inputTokens,

0 commit comments

Comments
 (0)