@xsai/shared-chat 0.4.0-beta.8 → 0.4.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.d.ts CHANGED
@@ -36,17 +36,28 @@ interface TextContentPart {
36
36
  }
37
37
 
38
38
  interface ToolCall {
39
- function: {
40
- arguments: string;
41
- name: string;
42
- };
39
+ function: ToolCallFunction | ToolCallFunctionWithoutArguments | ToolCallFunctionWithoutName;
43
40
  id: string;
44
41
  type: 'function';
45
42
  }
43
+ interface ToolCallFunction {
44
+ arguments: string;
45
+ name: string;
46
+ }
47
+ interface ToolCallFunctionWithoutArguments {
48
+ arguments?: never;
49
+ name: string;
50
+ }
51
+ interface ToolCallFunctionWithoutName {
52
+ arguments: string;
53
+ name?: never;
54
+ }
46
55
 
47
56
  interface AssistantMessage {
48
57
  content?: (RefusalContentPart | TextContentPart)[] | string;
49
58
  name?: string;
59
+ /** @remarks OpenAI doesn't support this, but some providers do. */
60
+ reasoning_content?: string;
50
61
  refusal?: string;
51
62
  role: 'assistant';
52
63
  tool_calls?: ToolCall[];
@@ -160,6 +171,8 @@ interface ChatOptions extends CommonRequestOptions {
160
171
  temperature?: number;
161
172
  toolChoice?: ToolChoice;
162
173
  tools?: Tool[];
174
+ /** @remarks OpenAI doesn't support this, but some providers do. */
175
+ topK?: number;
163
176
  /** @default 1 */
164
177
  topP?: number;
165
178
  }
package/dist/index.js CHANGED
@@ -49,30 +49,32 @@ const executeTool = async ({ abortSignal, messages, toolCall, tools }) => {
49
49
  const availableToolsErrorMsg = availableTools == null || availableTools.length === 0 ? "No tools are available" : `Available tools: ${availableTools.join(", ")}`;
50
50
  throw new Error(`Model tried to call unavailable tool "${toolCall.function.name}", ${availableToolsErrorMsg}.`);
51
51
  }
52
- const toolCallId = toolCall.id;
53
- const toolName = toolCall.function.name;
52
+ if (toolCall.function.name == null)
53
+ throw new Error(`Missing toolCall.function.name: ${JSON.stringify(toolCall)}`);
54
+ if (toolCall.function.arguments == null)
55
+ throw new Error(`Missing toolCall.function.arguments: ${JSON.stringify(toolCall)}`);
54
56
  const parsedArgs = JSON.parse(toolCall.function.arguments);
55
57
  const result = wrapToolResult(await tool.execute(parsedArgs, {
56
58
  abortSignal,
57
59
  messages,
58
- toolCallId
60
+ toolCallId: toolCall.id
59
61
  }));
60
62
  const completionToolCall = {
61
63
  args: toolCall.function.arguments,
62
- toolCallId,
64
+ toolCallId: toolCall.id,
63
65
  toolCallType: toolCall.type,
64
- toolName
66
+ toolName: toolCall.function.name
65
67
  };
66
68
  const completionToolResult = {
67
69
  args: parsedArgs,
68
70
  result,
69
- toolCallId,
70
- toolName
71
+ toolCallId: toolCall.id,
72
+ toolName: toolCall.function.name
71
73
  };
72
74
  const message = {
73
75
  content: result,
74
76
  role: "tool",
75
- tool_call_id: toolCallId
77
+ tool_call_id: toolCall.id
76
78
  };
77
79
  return {
78
80
  completionToolCall,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xsai/shared-chat",
3
3
  "type": "module",
4
- "version": "0.4.0-beta.8",
4
+ "version": "0.4.0",
5
5
  "description": "extra-small AI SDK.",
6
6
  "author": "Moeru AI",
7
7
  "license": "MIT",
@@ -29,7 +29,7 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@xsai/shared": "~0.4.0-beta.8"
32
+ "@xsai/shared": "~0.4.0"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "pkgroll"