@sisu-ai/mw-tool-calling 9.0.1 → 9.0.2

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.
Files changed (2) hide show
  1. package/dist/index.js +19 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -40,12 +40,18 @@ export const toolCalling = async (ctx, next) => {
40
40
  messages: ctx.messages.length,
41
41
  });
42
42
  const allowTools = i === 0 ? "auto" : "none";
43
- const genOpts = { toolChoice: allowTools, signal: ctx.signal };
43
+ const genOpts = {
44
+ toolChoice: allowTools,
45
+ signal: ctx.signal,
46
+ };
44
47
  if (allowTools !== "none") {
45
48
  genOpts.tools = aliasedTools; // Pass renamed tools to adapter
46
49
  genOpts.parallelToolCalls = false;
47
50
  }
48
- const out = (await ctx.model.generate(ctx.messages, genOpts));
51
+ const out = await ctx.model.generate(ctx.messages, genOpts);
52
+ if (!out || typeof out !== "object" || !("message" in out)) {
53
+ throw new Error("[tool-calling] model did not return a message");
54
+ }
49
55
  const msg = out.message;
50
56
  const toolCalls = msg.tool_calls;
51
57
  if (toolCalls && toolCalls.length > 0) {
@@ -105,11 +111,11 @@ export const toolCalling = async (ctx, next) => {
105
111
  ctx.log.debug?.("[tool-calling] reusing cached tool result for duplicate call", { name: call.name, id: call.id });
106
112
  }
107
113
  // Prefer tool_call_id when available (tools API)
108
- const toolMsg = { role: "tool", content: JSON.stringify(result) };
109
- if (call.id)
110
- toolMsg.tool_call_id = call.id;
111
- else
112
- toolMsg.name = call.name;
114
+ const toolMsg = {
115
+ role: "tool",
116
+ content: JSON.stringify(result),
117
+ ...(call.id ? { tool_call_id: call.id } : { name: call.name }),
118
+ };
113
119
  ctx.messages.push(toolMsg);
114
120
  ctx.log.debug?.("[tool-calling] tool result appended", {
115
121
  name: call.name,
@@ -143,7 +149,7 @@ export const iterativeToolCalling = async (ctx, next) => {
143
149
  parallelToolCalls: false,
144
150
  signal: ctx.signal,
145
151
  };
146
- const out = (await ctx.model.generate(ctx.messages, genOpts));
152
+ const out = await ctx.model.generate(ctx.messages, genOpts);
147
153
  const msg = out.message;
148
154
  const toolCalls = msg.tool_calls;
149
155
  if (toolCalls && toolCalls.length > 0) {
@@ -203,11 +209,11 @@ export const iterativeToolCalling = async (ctx, next) => {
203
209
  id: call.id,
204
210
  });
205
211
  }
206
- const toolMsg = { role: "tool", content: JSON.stringify(result) };
207
- if (call.id)
208
- toolMsg.tool_call_id = call.id;
209
- else
210
- toolMsg.name = call.name;
212
+ const toolMsg = {
213
+ role: "tool",
214
+ content: JSON.stringify(result),
215
+ ...(call.id ? { tool_call_id: call.id } : { name: call.name }),
216
+ };
211
217
  ctx.messages.push(toolMsg);
212
218
  }
213
219
  continue; // next round may call more tools
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sisu-ai/mw-tool-calling",
3
- "version": "9.0.1",
3
+ "version": "9.0.2",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",