Skip to content

Commit 87899a1

Browse files
committed
feat: enhance output type for function call and add content conversion utility
1 parent a57c238 commit 87899a1

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/routes/messages/responses-translation.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ const createFunctionCallOutput = (
246246
): ResponseFunctionCallOutputItem => ({
247247
type: "function_call_output",
248248
call_id: block.tool_use_id,
249-
output: block.content,
249+
output: convertToolResultContent(block.content),
250250
status: block.is_error ? "incomplete" : "completed",
251251
})
252252

@@ -268,7 +268,7 @@ When using the BashOutput tool, follow these rules:
268268
- Only Bash Tool run_in_background set to true, Use BashOutput to read the output later
269269
### TodoWrite tool
270270
When using the TodoWrite tool, follow these rules:
271-
- Skip using the TodoWrite tool for straightforward tasks (roughly the easiest 25%).
271+
- Skip using the TodoWrite tool for simple or straightforward tasks (roughly the easiest 25%).
272272
- Do not make single-step todo lists.
273273
- When you made a todo, update it after having performed one of the sub-tasks that you shared on the todo list.`
274274

@@ -636,3 +636,27 @@ const parseUserId = (
636636

637637
return { safetyIdentifier, promptCacheKey }
638638
}
639+
640+
const convertToolResultContent = (
641+
content: string | Array<AnthropicTextBlock> | Array<AnthropicImageBlock>,
642+
): string | Array<ResponseInputContent> => {
643+
if (typeof content === "string") {
644+
return content
645+
}
646+
647+
if (Array.isArray(content)) {
648+
if (content.length > 0 && content[0].type === "text") {
649+
return (content as Array<AnthropicTextBlock>).map((block) =>
650+
createTextContent(block.text),
651+
)
652+
}
653+
654+
if (content.length > 0 && content[0].type === "image") {
655+
return (content as Array<AnthropicImageBlock>).map((block) =>
656+
createImageContent(block),
657+
)
658+
}
659+
}
660+
661+
return ""
662+
}

src/services/copilot/create-responses.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface ResponseFunctionToolCallItem {
4444
export interface ResponseFunctionCallOutputItem {
4545
type: "function_call_output"
4646
call_id: string
47-
output: string
47+
output: string | Array<ResponseInputContent>
4848
status?: "in_progress" | "completed" | "incomplete"
4949
}
5050

@@ -57,11 +57,10 @@ export type ResponseInputItem =
5757
export type ResponseInputContent =
5858
| ResponseInputText
5959
| ResponseInputImage
60-
| ResponseContentTextLike
6160
| Record<string, unknown>
6261

6362
export interface ResponseInputText {
64-
type?: "input_text" | "text" | "output_text"
63+
type?: "input_text" | "output_text"
6564
text: string
6665
}
6766

@@ -72,11 +71,6 @@ export interface ResponseInputImage {
7271
detail?: "low" | "high" | "auto"
7372
}
7473

75-
export interface ResponseContentTextLike {
76-
type?: "text"
77-
text: string
78-
}
79-
8074
export interface ResponsesResult {
8175
id: string
8276
object: "response"

0 commit comments

Comments
 (0)