@copilotkitnext/core 1.54.1-next.0 → 1.54.1-next.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.
- package/dist/index.cjs +22 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +14 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +22 -3
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +22 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1537,7 +1537,7 @@ var RunHandler = class {
|
|
|
1537
1537
|
let isArgumentError = false;
|
|
1538
1538
|
let parsedArgs;
|
|
1539
1539
|
try {
|
|
1540
|
-
parsedArgs =
|
|
1540
|
+
parsedArgs = parseToolArguments(handlerArgs, toolCall.function.name);
|
|
1541
1541
|
} catch (error) {
|
|
1542
1542
|
const parseError = error instanceof Error ? error : new Error(String(error));
|
|
1543
1543
|
errorMessage = parseError.message;
|
|
@@ -1647,7 +1647,7 @@ var RunHandler = class {
|
|
|
1647
1647
|
if (wildcardTool?.handler) {
|
|
1648
1648
|
let parsedArgs;
|
|
1649
1649
|
try {
|
|
1650
|
-
parsedArgs =
|
|
1650
|
+
parsedArgs = parseToolArguments(toolCall.function.arguments, toolCall.function.name);
|
|
1651
1651
|
} catch (error) {
|
|
1652
1652
|
const parseError = error instanceof Error ? error : new Error(String(error));
|
|
1653
1653
|
errorMessage = parseError.message;
|
|
@@ -1894,6 +1894,25 @@ function ensureObjectArgs(parsed, toolName) {
|
|
|
1894
1894
|
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) return parsed;
|
|
1895
1895
|
throw new Error(`Tool arguments for ${toolName} parsed to non-object (${typeof parsed})`);
|
|
1896
1896
|
}
|
|
1897
|
+
/**
|
|
1898
|
+
* Parses raw tool call arguments into a validated object.
|
|
1899
|
+
*
|
|
1900
|
+
* Some LLM providers (e.g. @ai-sdk/openai-compatible) may send empty string "",
|
|
1901
|
+
* null, or undefined instead of "{}". This function normalises those cases to an
|
|
1902
|
+
* empty object so callers don't crash on JSON.parse("").
|
|
1903
|
+
*
|
|
1904
|
+
* A debug-level warning is emitted when the fallback triggers so silent coercion
|
|
1905
|
+
* is observable in logs.
|
|
1906
|
+
*
|
|
1907
|
+
* @internal Exported for testing only.
|
|
1908
|
+
*/
|
|
1909
|
+
function parseToolArguments(rawArgs, toolName) {
|
|
1910
|
+
if (rawArgs === "" || rawArgs === null || rawArgs === void 0) {
|
|
1911
|
+
_copilotkitnext_shared.logger.debug(`[parseToolArguments] Tool "${toolName}" received empty/null/undefined arguments — defaulting to {}`);
|
|
1912
|
+
return {};
|
|
1913
|
+
}
|
|
1914
|
+
return ensureObjectArgs(typeof rawArgs === "string" ? JSON.parse(rawArgs) : rawArgs, toolName);
|
|
1915
|
+
}
|
|
1897
1916
|
|
|
1898
1917
|
//#endregion
|
|
1899
1918
|
//#region src/core/state-manager.ts
|
|
@@ -3171,6 +3190,7 @@ exports.empty = empty;
|
|
|
3171
3190
|
exports.ensureObjectArgs = ensureObjectArgs;
|
|
3172
3191
|
exports.ofType = ofType;
|
|
3173
3192
|
exports.on = on;
|
|
3193
|
+
exports.parseToolArguments = parseToolArguments;
|
|
3174
3194
|
exports.props = props;
|
|
3175
3195
|
exports.select = select;
|
|
3176
3196
|
exports.ɵcreateThreadStore = createThreadStore;
|