@jambonz/llm 0.1.0 → 0.2.0

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/index.cjs CHANGED
@@ -224,6 +224,28 @@ async function* streamFromOpenAI(client, req, options) {
224
224
  };
225
225
  yield endEvent;
226
226
  }
227
+ function appendOpenAIAssistantToolCall(history, toolCalls) {
228
+ const wireMessage = {
229
+ role: "assistant",
230
+ content: null,
231
+ tool_calls: toolCalls.map((tc) => ({
232
+ id: tc.id,
233
+ type: "function",
234
+ function: {
235
+ name: tc.name,
236
+ arguments: typeof tc.arguments === "string" ? tc.arguments : JSON.stringify(tc.arguments ?? {})
237
+ }
238
+ }))
239
+ };
240
+ return [
241
+ ...history,
242
+ {
243
+ role: "assistant",
244
+ content: "",
245
+ vendorRaw: wireMessage
246
+ }
247
+ ];
248
+ }
227
249
  function appendOpenAIToolResult(history, toolCallId, result) {
228
250
  const content = typeof result === "string" ? result : JSON.stringify(result);
229
251
  const wireMessage = {
@@ -445,6 +467,9 @@ var OpenAIAdapter = class {
445
467
  knownModels: openAIManifest.knownModels
446
468
  });
447
469
  }
470
+ appendAssistantToolCall(history, toolCalls) {
471
+ return appendOpenAIAssistantToolCall(history, toolCalls);
472
+ }
448
473
  appendToolResult(history, toolCallId, result) {
449
474
  return appendOpenAIToolResult(history, toolCallId, result);
450
475
  }
@@ -795,6 +820,25 @@ var AnthropicAdapter = class {
795
820
  };
796
821
  yield endEvent;
797
822
  }
823
+ appendAssistantToolCall(history, toolCalls) {
824
+ const wireMessage = {
825
+ role: "assistant",
826
+ content: toolCalls.map((tc) => ({
827
+ type: "tool_use",
828
+ id: tc.id,
829
+ name: tc.name,
830
+ input: tc.arguments ?? {}
831
+ }))
832
+ };
833
+ return [
834
+ ...history,
835
+ {
836
+ role: "assistant",
837
+ content: "",
838
+ vendorRaw: wireMessage
839
+ }
840
+ ];
841
+ }
798
842
  appendToolResult(history, toolCallId, result) {
799
843
  const content = typeof result === "string" ? result : JSON.stringify(result);
800
844
  const wireMessage = {
@@ -1010,6 +1054,25 @@ async function* streamFromGemini(client, req) {
1010
1054
  };
1011
1055
  yield endEvent;
1012
1056
  }
1057
+ function appendGeminiAssistantToolCall(history, toolCalls) {
1058
+ const wireMessage = {
1059
+ role: "model",
1060
+ parts: toolCalls.map((tc) => ({
1061
+ functionCall: {
1062
+ name: parseToolName(tc.id),
1063
+ args: tc.arguments ?? {}
1064
+ }
1065
+ }))
1066
+ };
1067
+ return [
1068
+ ...history,
1069
+ {
1070
+ role: "assistant",
1071
+ content: "",
1072
+ vendorRaw: wireMessage
1073
+ }
1074
+ ];
1075
+ }
1013
1076
  function appendGeminiToolResult(history, toolCallId, result) {
1014
1077
  const name = parseToolName(toolCallId);
1015
1078
  const content = typeof result === "string" ? result : JSON.stringify(result);
@@ -1232,6 +1295,9 @@ var GoogleAdapter = class {
1232
1295
  stream(req) {
1233
1296
  return streamFromGemini(this.ensureClient(), req);
1234
1297
  }
1298
+ appendAssistantToolCall(history, toolCalls) {
1299
+ return appendGeminiAssistantToolCall(history, toolCalls);
1300
+ }
1235
1301
  appendToolResult(history, toolCallId, result) {
1236
1302
  return appendGeminiToolResult(history, toolCallId, result);
1237
1303
  }
@@ -1399,6 +1465,9 @@ var VertexGeminiAdapter = class {
1399
1465
  stream(req) {
1400
1466
  return streamFromGemini(this.ensureClient(), req);
1401
1467
  }
1468
+ appendAssistantToolCall(history, toolCalls) {
1469
+ return appendGeminiAssistantToolCall(history, toolCalls);
1470
+ }
1402
1471
  appendToolResult(history, toolCallId, result) {
1403
1472
  return appendGeminiToolResult(history, toolCallId, result);
1404
1473
  }
@@ -1565,6 +1634,9 @@ var VertexOpenAIAdapter = class {
1565
1634
  knownModels: vertexOpenAIManifest.knownModels
1566
1635
  });
1567
1636
  }
1637
+ appendAssistantToolCall(history, toolCalls) {
1638
+ return appendOpenAIAssistantToolCall(history, toolCalls);
1639
+ }
1568
1640
  appendToolResult(history, toolCallId, result) {
1569
1641
  return appendOpenAIToolResult(history, toolCallId, result);
1570
1642
  }
@@ -1954,6 +2026,26 @@ var BedrockAdapter = class {
1954
2026
  };
1955
2027
  yield endEvent;
1956
2028
  }
2029
+ appendAssistantToolCall(history, toolCalls) {
2030
+ const wireMessage = {
2031
+ role: "assistant",
2032
+ content: toolCalls.map((tc) => ({
2033
+ toolUse: {
2034
+ toolUseId: tc.id,
2035
+ name: tc.name,
2036
+ input: tc.arguments ?? {}
2037
+ }
2038
+ }))
2039
+ };
2040
+ return [
2041
+ ...history,
2042
+ {
2043
+ role: "assistant",
2044
+ content: "",
2045
+ vendorRaw: wireMessage
2046
+ }
2047
+ ];
2048
+ }
1957
2049
  appendToolResult(history, toolCallId, result) {
1958
2050
  const text = typeof result === "string" ? result : JSON.stringify(result);
1959
2051
  const wireMessage = {