@jaypie/llm 1.2.7 → 1.2.8
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/cjs/index.cjs +69 -12
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +69 -12
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -909,19 +909,51 @@ class AnthropicAdapter extends BaseProviderAdapter {
|
|
|
909
909
|
//
|
|
910
910
|
buildRequest(request) {
|
|
911
911
|
// Convert messages to Anthropic format
|
|
912
|
-
//
|
|
913
|
-
const messages =
|
|
914
|
-
|
|
915
|
-
const role = msg.role;
|
|
916
|
-
return role !== "system";
|
|
917
|
-
})
|
|
918
|
-
.map((msg) => {
|
|
912
|
+
// Handle different message types: regular messages, function calls, and function outputs
|
|
913
|
+
const messages = [];
|
|
914
|
+
for (const msg of request.messages) {
|
|
919
915
|
const typedMsg = msg;
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
}
|
|
924
|
-
|
|
916
|
+
// Skip system messages - Anthropic only accepts system as a top-level field
|
|
917
|
+
if (typedMsg.role === "system") {
|
|
918
|
+
continue;
|
|
919
|
+
}
|
|
920
|
+
// Handle FunctionCall messages - convert to assistant message with tool_use
|
|
921
|
+
if (typedMsg.type === LlmMessageType.FunctionCall) {
|
|
922
|
+
messages.push({
|
|
923
|
+
role: "assistant",
|
|
924
|
+
content: [
|
|
925
|
+
{
|
|
926
|
+
type: "tool_use",
|
|
927
|
+
id: typedMsg.call_id || "",
|
|
928
|
+
name: typedMsg.name || "",
|
|
929
|
+
input: JSON.parse(typedMsg.arguments || "{}"),
|
|
930
|
+
},
|
|
931
|
+
],
|
|
932
|
+
});
|
|
933
|
+
continue;
|
|
934
|
+
}
|
|
935
|
+
// Handle FunctionCallOutput messages - convert to user message with tool_result
|
|
936
|
+
if (typedMsg.type === LlmMessageType.FunctionCallOutput) {
|
|
937
|
+
messages.push({
|
|
938
|
+
role: "user",
|
|
939
|
+
content: [
|
|
940
|
+
{
|
|
941
|
+
type: "tool_result",
|
|
942
|
+
tool_use_id: typedMsg.call_id || "",
|
|
943
|
+
content: typedMsg.output || "",
|
|
944
|
+
},
|
|
945
|
+
],
|
|
946
|
+
});
|
|
947
|
+
continue;
|
|
948
|
+
}
|
|
949
|
+
// Handle regular messages with role and content
|
|
950
|
+
if (typedMsg.role && typedMsg.content !== undefined) {
|
|
951
|
+
messages.push({
|
|
952
|
+
role: typedMsg.role,
|
|
953
|
+
content: convertContentToAnthropic(typedMsg.content),
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
}
|
|
925
957
|
// Append instructions to last message if provided
|
|
926
958
|
if (request.instructions && messages.length > 0) {
|
|
927
959
|
const lastMsg = messages[messages.length - 1];
|
|
@@ -2909,6 +2941,31 @@ class OpenRouterAdapter extends BaseProviderAdapter {
|
|
|
2909
2941
|
});
|
|
2910
2942
|
}
|
|
2911
2943
|
}
|
|
2944
|
+
else if (message.type === LlmMessageType.FunctionCall) {
|
|
2945
|
+
// Handle FunctionCall messages from StreamLoop (issue #165)
|
|
2946
|
+
openRouterMessages.push({
|
|
2947
|
+
role: "assistant",
|
|
2948
|
+
content: null,
|
|
2949
|
+
toolCalls: [
|
|
2950
|
+
{
|
|
2951
|
+
id: message.call_id,
|
|
2952
|
+
type: "function",
|
|
2953
|
+
function: {
|
|
2954
|
+
name: message.name,
|
|
2955
|
+
arguments: message.arguments || "{}",
|
|
2956
|
+
},
|
|
2957
|
+
},
|
|
2958
|
+
],
|
|
2959
|
+
});
|
|
2960
|
+
}
|
|
2961
|
+
else if (message.type === LlmMessageType.FunctionCallOutput) {
|
|
2962
|
+
// Handle FunctionCallOutput messages from StreamLoop (issue #165)
|
|
2963
|
+
openRouterMessages.push({
|
|
2964
|
+
role: "tool",
|
|
2965
|
+
toolCallId: message.call_id,
|
|
2966
|
+
content: message.output || "",
|
|
2967
|
+
});
|
|
2968
|
+
}
|
|
2912
2969
|
}
|
|
2913
2970
|
return openRouterMessages;
|
|
2914
2971
|
}
|