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