@nanocollective/nanocoder 1.16.4 → 1.16.5
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/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +4 -29
- package/dist/commands/init.js.map +1 -1
- package/dist/components/tool-confirmation.d.ts.map +1 -1
- package/dist/components/tool-confirmation.js +5 -19
- package/dist/components/tool-confirmation.js.map +1 -1
- package/dist/config/themes.js +2 -2
- package/dist/hooks/useChatHandler.d.ts.map +1 -1
- package/dist/hooks/useChatHandler.js +10 -71
- package/dist/hooks/useChatHandler.js.map +1 -1
- package/dist/hooks/useDirectoryTrust.d.ts.map +1 -1
- package/dist/hooks/useDirectoryTrust.js +4 -4
- package/dist/hooks/useDirectoryTrust.js.map +1 -1
- package/dist/hooks/useToolHandler.d.ts +0 -1
- package/dist/hooks/useToolHandler.d.ts.map +1 -1
- package/dist/hooks/useToolHandler.js +9 -75
- package/dist/hooks/useToolHandler.js.map +1 -1
- package/dist/message-handler.d.ts.map +1 -1
- package/dist/message-handler.js +6 -11
- package/dist/message-handler.js.map +1 -1
- package/dist/models/models-dev-client.spec.js +1 -0
- package/dist/models/models-dev-client.spec.js.map +1 -1
- package/dist/utils/error-formatter.d.ts +22 -0
- package/dist/utils/error-formatter.d.ts.map +1 -0
- package/dist/utils/error-formatter.js +27 -0
- package/dist/utils/error-formatter.js.map +1 -0
- package/dist/utils/error-formatter.spec.d.ts +2 -0
- package/dist/utils/error-formatter.spec.d.ts.map +1 -0
- package/dist/utils/error-formatter.spec.js +147 -0
- package/dist/utils/error-formatter.spec.js.map +1 -0
- package/dist/utils/fuzzy-matching.spec.js +1 -0
- package/dist/utils/fuzzy-matching.spec.js.map +1 -1
- package/dist/utils/tool-args-parser.d.ts +37 -0
- package/dist/utils/tool-args-parser.d.ts.map +1 -0
- package/dist/utils/tool-args-parser.js +50 -0
- package/dist/utils/tool-args-parser.js.map +1 -0
- package/dist/utils/tool-args-parser.spec.d.ts +2 -0
- package/dist/utils/tool-args-parser.spec.d.ts.map +1 -0
- package/dist/utils/tool-args-parser.spec.js +111 -0
- package/dist/utils/tool-args-parser.spec.js.map +1 -0
- package/dist/utils/tool-cancellation.d.ts +21 -0
- package/dist/utils/tool-cancellation.d.ts.map +1 -0
- package/dist/utils/tool-cancellation.js +27 -0
- package/dist/utils/tool-cancellation.js.map +1 -0
- package/dist/utils/tool-cancellation.spec.d.ts +2 -0
- package/dist/utils/tool-cancellation.spec.d.ts.map +1 -0
- package/dist/utils/tool-cancellation.spec.js +186 -0
- package/dist/utils/tool-cancellation.spec.js.map +1 -0
- package/dist/utils/tool-result-display.d.ts +15 -0
- package/dist/utils/tool-result-display.d.ts.map +1 -0
- package/dist/utils/tool-result-display.js +51 -0
- package/dist/utils/tool-result-display.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse tool arguments from various formats
|
|
3
|
+
* Handles both string-encoded JSON and already-parsed objects
|
|
4
|
+
*
|
|
5
|
+
* This utility eliminates the repeated pattern of JSON parsing that appears
|
|
6
|
+
* throughout the codebase when handling tool call arguments.
|
|
7
|
+
*
|
|
8
|
+
* ## Error Handling Modes
|
|
9
|
+
*
|
|
10
|
+
* **Lenient mode (strict=false, default)**: Used for display/UI purposes where
|
|
11
|
+
* graceful degradation is acceptable. If JSON parsing fails, returns the
|
|
12
|
+
* unparsed string, allowing the application to continue.
|
|
13
|
+
*
|
|
14
|
+
* **Strict mode (strict=true)**: Used for tool execution where malformed
|
|
15
|
+
* arguments must be caught early. Throws an error if JSON parsing fails,
|
|
16
|
+
* preventing execution with invalid data.
|
|
17
|
+
*
|
|
18
|
+
* @param args - Arguments in any format (string, object, etc.)
|
|
19
|
+
* @param options - Parsing options
|
|
20
|
+
* @param options.strict - If true, throw error on parse failure. If false, return unparsed value. Default: false
|
|
21
|
+
* @returns Parsed arguments as the specified type
|
|
22
|
+
* @throws Error if strict=true and JSON parsing fails
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Lenient parsing for display
|
|
26
|
+
* const parsedArgs = parseToolArguments(toolCall.function.arguments);
|
|
27
|
+
*
|
|
28
|
+
* // Strict parsing for tool execution
|
|
29
|
+
* const parsedArgs = parseToolArguments(toolCall.function.arguments, {strict: true});
|
|
30
|
+
*
|
|
31
|
+
* // With type parameter
|
|
32
|
+
* const typedArgs = parseToolArguments<{path: string}>(args, {strict: true});
|
|
33
|
+
*/
|
|
34
|
+
export function parseToolArguments(args, options = {}) {
|
|
35
|
+
const { strict = false } = options;
|
|
36
|
+
if (typeof args === 'string') {
|
|
37
|
+
try {
|
|
38
|
+
return JSON.parse(args);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
if (strict) {
|
|
42
|
+
throw new Error(`Error: Invalid tool arguments: ${e.message}`);
|
|
43
|
+
}
|
|
44
|
+
// If parsing fails in lenient mode, return as-is (will be cast to T)
|
|
45
|
+
return args;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return args;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=tool-args-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-args-parser.js","sourceRoot":"","sources":["../../source/utils/tool-args-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,kBAAkB,CACjC,IAAa,EACb,UAA8B,EAAE;IAEhC,MAAM,EAAC,MAAM,GAAG,KAAK,EAAC,GAAG,OAAO,CAAC;IAEjC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC;YACJ,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAM,CAAC;QAC9B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,IAAI,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,KAAK,CACd,kCAAmC,CAAW,CAAC,OAAO,EAAE,CACxD,CAAC;YACH,CAAC;YACD,qEAAqE;YACrE,OAAO,IAAS,CAAC;QAClB,CAAC;IACF,CAAC;IACD,OAAO,IAAS,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-args-parser.spec.d.ts","sourceRoot":"","sources":["../../source/utils/tool-args-parser.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { parseToolArguments } from './tool-args-parser.js';
|
|
3
|
+
console.log(`\ntool-args-parser.spec.ts`);
|
|
4
|
+
// Tests for lenient mode (default, strict=false)
|
|
5
|
+
test('parseToolArguments - parses valid JSON string in lenient mode', t => {
|
|
6
|
+
const input = '{"path": "/test", "count": 42}';
|
|
7
|
+
const result = parseToolArguments(input);
|
|
8
|
+
t.deepEqual(result, { path: '/test', count: 42 });
|
|
9
|
+
});
|
|
10
|
+
test('parseToolArguments - returns object as-is in lenient mode', t => {
|
|
11
|
+
const input = { path: '/test', count: 42 };
|
|
12
|
+
const result = parseToolArguments(input);
|
|
13
|
+
t.deepEqual(result, input);
|
|
14
|
+
});
|
|
15
|
+
test('parseToolArguments - returns unparsed string on parse failure in lenient mode', t => {
|
|
16
|
+
const input = '{invalid json}';
|
|
17
|
+
const result = parseToolArguments(input);
|
|
18
|
+
t.is(result, input); // Should return the string as-is
|
|
19
|
+
});
|
|
20
|
+
test('parseToolArguments - handles empty object string in lenient mode', t => {
|
|
21
|
+
const input = '{}';
|
|
22
|
+
const result = parseToolArguments(input);
|
|
23
|
+
t.deepEqual(result, {});
|
|
24
|
+
});
|
|
25
|
+
test('parseToolArguments - handles array JSON in lenient mode', t => {
|
|
26
|
+
const input = '[1, 2, 3]';
|
|
27
|
+
const result = parseToolArguments(input);
|
|
28
|
+
t.deepEqual(result, [1, 2, 3]);
|
|
29
|
+
});
|
|
30
|
+
test('parseToolArguments - handles null in lenient mode', t => {
|
|
31
|
+
const result = parseToolArguments(null);
|
|
32
|
+
t.is(result, null);
|
|
33
|
+
});
|
|
34
|
+
test('parseToolArguments - handles undefined in lenient mode', t => {
|
|
35
|
+
const result = parseToolArguments(undefined);
|
|
36
|
+
t.is(result, undefined);
|
|
37
|
+
});
|
|
38
|
+
test('parseToolArguments - handles number in lenient mode', t => {
|
|
39
|
+
const result = parseToolArguments(42);
|
|
40
|
+
t.is(result, 42);
|
|
41
|
+
});
|
|
42
|
+
// Tests for strict mode (strict=true)
|
|
43
|
+
test('parseToolArguments - parses valid JSON string in strict mode', t => {
|
|
44
|
+
const input = '{"path": "/test", "count": 42}';
|
|
45
|
+
const result = parseToolArguments(input, { strict: true });
|
|
46
|
+
t.deepEqual(result, { path: '/test', count: 42 });
|
|
47
|
+
});
|
|
48
|
+
test('parseToolArguments - returns object as-is in strict mode', t => {
|
|
49
|
+
const input = { path: '/test', count: 42 };
|
|
50
|
+
const result = parseToolArguments(input, { strict: true });
|
|
51
|
+
t.deepEqual(result, input);
|
|
52
|
+
});
|
|
53
|
+
test('parseToolArguments - throws on parse failure in strict mode', t => {
|
|
54
|
+
const input = '{invalid json}';
|
|
55
|
+
const error = t.throws(() => {
|
|
56
|
+
parseToolArguments(input, { strict: true });
|
|
57
|
+
});
|
|
58
|
+
t.true(error?.message.includes('Error: Invalid tool arguments'));
|
|
59
|
+
});
|
|
60
|
+
test('parseToolArguments - throws on malformed JSON in strict mode', t => {
|
|
61
|
+
const input = '{"unclosed": ';
|
|
62
|
+
const error = t.throws(() => {
|
|
63
|
+
parseToolArguments(input, { strict: true });
|
|
64
|
+
});
|
|
65
|
+
t.true(error?.message.includes('Error: Invalid tool arguments'));
|
|
66
|
+
});
|
|
67
|
+
test('parseToolArguments - handles empty object string in strict mode', t => {
|
|
68
|
+
const input = '{}';
|
|
69
|
+
const result = parseToolArguments(input, { strict: true });
|
|
70
|
+
t.deepEqual(result, {});
|
|
71
|
+
});
|
|
72
|
+
// Tests for type parameter
|
|
73
|
+
test('parseToolArguments - respects type parameter', t => {
|
|
74
|
+
const input = '{"path": "/test", "count": 42}';
|
|
75
|
+
const result = parseToolArguments(input);
|
|
76
|
+
t.deepEqual(result, { path: '/test', count: 42 });
|
|
77
|
+
});
|
|
78
|
+
// Edge cases
|
|
79
|
+
test('parseToolArguments - handles nested JSON', t => {
|
|
80
|
+
const input = '{"outer": {"inner": {"value": 123}}}';
|
|
81
|
+
const result = parseToolArguments(input);
|
|
82
|
+
t.deepEqual(result, { outer: { inner: { value: 123 } } });
|
|
83
|
+
});
|
|
84
|
+
test('parseToolArguments - handles JSON with special characters', t => {
|
|
85
|
+
const input = '{"message": "Hello \\"world\\"", "newline": "test\\nline"}';
|
|
86
|
+
const result = parseToolArguments(input);
|
|
87
|
+
t.deepEqual(result, { message: 'Hello "world"', newline: 'test\nline' });
|
|
88
|
+
});
|
|
89
|
+
test('parseToolArguments - preserves boolean values', t => {
|
|
90
|
+
const input = '{"enabled": true, "disabled": false}';
|
|
91
|
+
const result = parseToolArguments(input);
|
|
92
|
+
t.deepEqual(result, { enabled: true, disabled: false });
|
|
93
|
+
});
|
|
94
|
+
test('parseToolArguments - preserves null values in JSON', t => {
|
|
95
|
+
const input = '{"value": null}';
|
|
96
|
+
const result = parseToolArguments(input);
|
|
97
|
+
t.deepEqual(result, { value: null });
|
|
98
|
+
});
|
|
99
|
+
// Comparison between strict and lenient modes
|
|
100
|
+
test('parseToolArguments - lenient vs strict behavior on invalid JSON', t => {
|
|
101
|
+
const invalidJson = '{broken}';
|
|
102
|
+
// Lenient mode: returns unparsed string
|
|
103
|
+
const lenientResult = parseToolArguments(invalidJson);
|
|
104
|
+
t.is(lenientResult, invalidJson);
|
|
105
|
+
// Strict mode: throws error
|
|
106
|
+
const error = t.throws(() => {
|
|
107
|
+
parseToolArguments(invalidJson, { strict: true });
|
|
108
|
+
});
|
|
109
|
+
t.true(error?.message.includes('Error: Invalid tool arguments'));
|
|
110
|
+
});
|
|
111
|
+
//# sourceMappingURL=tool-args-parser.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-args-parser.spec.js","sourceRoot":"","sources":["../../source/utils/tool-args-parser.spec.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,KAAK,CAAC;AACvB,OAAO,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AAEtD,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAE1C,iDAAiD;AACjD,IAAI,CAAC,+DAA+D,EAAE,CAAC,CAAC,EAAE;IACzE,MAAM,KAAK,GAAG,gCAAgC,CAAC;IAC/C,MAAM,MAAM,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,EAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAC,CAAC,CAAC;AACjD,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,2DAA2D,EAAE,CAAC,CAAC,EAAE;IACrE,MAAM,KAAK,GAAG,EAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAC,CAAC;IACzC,MAAM,MAAM,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC5B,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,+EAA+E,EAAE,CAAC,CAAC,EAAE;IACzF,MAAM,KAAK,GAAG,gBAAgB,CAAC;IAC/B,MAAM,MAAM,GAAG,kBAAkB,CAAU,KAAK,CAAC,CAAC;IAClD,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,iCAAiC;AACvD,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,kEAAkE,EAAE,CAAC,CAAC,EAAE;IAC5E,MAAM,KAAK,GAAG,IAAI,CAAC;IACnB,MAAM,MAAM,GAAG,kBAAkB,CAAC,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,EAAE,KAAK,EAAC,CAAC,CAAC;AACvD,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,oDAAoD,EAAE,CAAC,CAAC,EAAE;IAC9D,MAAM,KAAK,GAAG,iBAAiB,CAAC;IAChC,MAAM,MAAM,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,EAAC,KAAK,EAAE,IAAI,EAAC,CAAC,CAAC;AACpC,CAAC,CAAC,CAAC;AAEH,8CAA8C;AAC9C,IAAI,CAAC,iEAAiE,EAAE,CAAC,CAAC,EAAE;IAC3E,MAAM,WAAW,GAAG,UAAU,CAAC;IAE/B,wCAAwC;IACxC,MAAM,aAAa,GAAG,kBAAkB,CAAU,WAAW,CAAC,CAAC;IAC/D,CAAC,CAAC,EAAE,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;IAEjC,4BAA4B;IAC5B,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE;QAC3B,kBAAkB,CAAC,WAAW,EAAE,EAAC,MAAM,EAAE,IAAI,EAAC,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;IACH,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,+BAA+B,CAAC,CAAC,CAAC;AAClE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ToolCall, ToolResult } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create cancellation results for tool calls
|
|
4
|
+
* Used when user cancels tool execution to maintain conversation state integrity
|
|
5
|
+
*
|
|
6
|
+
* This utility eliminates duplication of cancellation result creation logic
|
|
7
|
+
*
|
|
8
|
+
* @param toolCalls - Array of tool calls that were cancelled
|
|
9
|
+
* @returns Array of tool results indicating cancellation
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const cancellationResults = createCancellationResults(pendingToolCalls);
|
|
13
|
+
* const toolMessages = cancellationResults.map(result => ({
|
|
14
|
+
* role: 'tool' as const,
|
|
15
|
+
* content: result.content,
|
|
16
|
+
* tool_call_id: result.tool_call_id,
|
|
17
|
+
* name: result.name,
|
|
18
|
+
* }));
|
|
19
|
+
*/
|
|
20
|
+
export declare function createCancellationResults(toolCalls: ToolCall[]): ToolResult[];
|
|
21
|
+
//# sourceMappingURL=tool-cancellation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-cancellation.d.ts","sourceRoot":"","sources":["../../source/utils/tool-cancellation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAE,UAAU,EAAC,MAAM,eAAe,CAAC;AAExD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,UAAU,EAAE,CAO7E"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create cancellation results for tool calls
|
|
3
|
+
* Used when user cancels tool execution to maintain conversation state integrity
|
|
4
|
+
*
|
|
5
|
+
* This utility eliminates duplication of cancellation result creation logic
|
|
6
|
+
*
|
|
7
|
+
* @param toolCalls - Array of tool calls that were cancelled
|
|
8
|
+
* @returns Array of tool results indicating cancellation
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const cancellationResults = createCancellationResults(pendingToolCalls);
|
|
12
|
+
* const toolMessages = cancellationResults.map(result => ({
|
|
13
|
+
* role: 'tool' as const,
|
|
14
|
+
* content: result.content,
|
|
15
|
+
* tool_call_id: result.tool_call_id,
|
|
16
|
+
* name: result.name,
|
|
17
|
+
* }));
|
|
18
|
+
*/
|
|
19
|
+
export function createCancellationResults(toolCalls) {
|
|
20
|
+
return toolCalls.map(toolCall => ({
|
|
21
|
+
tool_call_id: toolCall.id,
|
|
22
|
+
role: 'tool',
|
|
23
|
+
name: toolCall.function.name,
|
|
24
|
+
content: 'Tool execution was cancelled by the user.',
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=tool-cancellation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-cancellation.js","sourceRoot":"","sources":["../../source/utils/tool-cancellation.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,yBAAyB,CAAC,SAAqB;IAC9D,OAAO,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACjC,YAAY,EAAE,QAAQ,CAAC,EAAE;QACzB,IAAI,EAAE,MAAe;QACrB,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI;QAC5B,OAAO,EAAE,2CAA2C;KACpD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-cancellation.spec.d.ts","sourceRoot":"","sources":["../../source/utils/tool-cancellation.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { createCancellationResults } from './tool-cancellation.js';
|
|
3
|
+
console.log(`\ntool-cancellation.spec.ts`);
|
|
4
|
+
// Helper to create mock tool calls
|
|
5
|
+
function createMockToolCall(id, name, args = {}) {
|
|
6
|
+
return {
|
|
7
|
+
id,
|
|
8
|
+
function: {
|
|
9
|
+
name,
|
|
10
|
+
arguments: args,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
// Basic functionality tests
|
|
15
|
+
test('createCancellationResults - creates result for single tool call', t => {
|
|
16
|
+
const toolCalls = [createMockToolCall('call-1', 'ReadFile', { path: '/test' })];
|
|
17
|
+
const results = createCancellationResults(toolCalls);
|
|
18
|
+
t.is(results.length, 1);
|
|
19
|
+
t.is(results[0].tool_call_id, 'call-1');
|
|
20
|
+
t.is(results[0].role, 'tool');
|
|
21
|
+
t.is(results[0].name, 'ReadFile');
|
|
22
|
+
t.is(results[0].content, 'Tool execution was cancelled by the user.');
|
|
23
|
+
});
|
|
24
|
+
test('createCancellationResults - creates results for multiple tool calls', t => {
|
|
25
|
+
const toolCalls = [
|
|
26
|
+
createMockToolCall('call-1', 'ReadFile', { path: '/test1' }),
|
|
27
|
+
createMockToolCall('call-2', 'WriteFile', { path: '/test2' }),
|
|
28
|
+
createMockToolCall('call-3', 'ExecuteBash', { command: 'ls' }),
|
|
29
|
+
];
|
|
30
|
+
const results = createCancellationResults(toolCalls);
|
|
31
|
+
t.is(results.length, 3);
|
|
32
|
+
t.is(results[0].tool_call_id, 'call-1');
|
|
33
|
+
t.is(results[1].tool_call_id, 'call-2');
|
|
34
|
+
t.is(results[2].tool_call_id, 'call-3');
|
|
35
|
+
});
|
|
36
|
+
test('createCancellationResults - handles empty array', t => {
|
|
37
|
+
const toolCalls = [];
|
|
38
|
+
const results = createCancellationResults(toolCalls);
|
|
39
|
+
t.is(results.length, 0);
|
|
40
|
+
t.deepEqual(results, []);
|
|
41
|
+
});
|
|
42
|
+
// Field mapping tests
|
|
43
|
+
test('createCancellationResults - correctly maps tool_call_id from id', t => {
|
|
44
|
+
const toolCalls = [createMockToolCall('unique-id-123', 'SomeTool')];
|
|
45
|
+
const results = createCancellationResults(toolCalls);
|
|
46
|
+
t.is(results[0].tool_call_id, 'unique-id-123');
|
|
47
|
+
});
|
|
48
|
+
test('createCancellationResults - correctly maps name from function.name', t => {
|
|
49
|
+
const toolCalls = [createMockToolCall('call-1', 'CustomToolName')];
|
|
50
|
+
const results = createCancellationResults(toolCalls);
|
|
51
|
+
t.is(results[0].name, 'CustomToolName');
|
|
52
|
+
});
|
|
53
|
+
test('createCancellationResults - sets role to "tool"', t => {
|
|
54
|
+
const toolCalls = [createMockToolCall('call-1', 'AnyTool')];
|
|
55
|
+
const results = createCancellationResults(toolCalls);
|
|
56
|
+
t.is(results[0].role, 'tool');
|
|
57
|
+
});
|
|
58
|
+
test('createCancellationResults - sets consistent cancellation message', t => {
|
|
59
|
+
const toolCalls = [
|
|
60
|
+
createMockToolCall('call-1', 'Tool1'),
|
|
61
|
+
createMockToolCall('call-2', 'Tool2'),
|
|
62
|
+
];
|
|
63
|
+
const results = createCancellationResults(toolCalls);
|
|
64
|
+
// All results should have the same cancellation message
|
|
65
|
+
t.is(results[0].content, 'Tool execution was cancelled by the user.');
|
|
66
|
+
t.is(results[1].content, 'Tool execution was cancelled by the user.');
|
|
67
|
+
});
|
|
68
|
+
// Edge cases with tool names
|
|
69
|
+
test('createCancellationResults - handles tools with special characters in name', t => {
|
|
70
|
+
const toolCalls = [createMockToolCall('call-1', 'Tool_With_Underscores')];
|
|
71
|
+
const results = createCancellationResults(toolCalls);
|
|
72
|
+
t.is(results[0].name, 'Tool_With_Underscores');
|
|
73
|
+
});
|
|
74
|
+
test('createCancellationResults - handles tools with numbers in name', t => {
|
|
75
|
+
const toolCalls = [createMockToolCall('call-1', 'Tool123')];
|
|
76
|
+
const results = createCancellationResults(toolCalls);
|
|
77
|
+
t.is(results[0].name, 'Tool123');
|
|
78
|
+
});
|
|
79
|
+
test('createCancellationResults - handles tools with camelCase name', t => {
|
|
80
|
+
const toolCalls = [createMockToolCall('call-1', 'readFileContents')];
|
|
81
|
+
const results = createCancellationResults(toolCalls);
|
|
82
|
+
t.is(results[0].name, 'readFileContents');
|
|
83
|
+
});
|
|
84
|
+
// Edge cases with tool call IDs
|
|
85
|
+
test('createCancellationResults - handles very long tool call IDs', t => {
|
|
86
|
+
const longId = 'a'.repeat(1000);
|
|
87
|
+
const toolCalls = [createMockToolCall(longId, 'SomeTool')];
|
|
88
|
+
const results = createCancellationResults(toolCalls);
|
|
89
|
+
t.is(results[0].tool_call_id, longId);
|
|
90
|
+
});
|
|
91
|
+
test('createCancellationResults - handles UUID-style IDs', t => {
|
|
92
|
+
const uuid = '550e8400-e29b-41d4-a716-446655440000';
|
|
93
|
+
const toolCalls = [createMockToolCall(uuid, 'SomeTool')];
|
|
94
|
+
const results = createCancellationResults(toolCalls);
|
|
95
|
+
t.is(results[0].tool_call_id, uuid);
|
|
96
|
+
});
|
|
97
|
+
// Arguments handling (should be ignored in cancellation)
|
|
98
|
+
test('createCancellationResults - ignores tool arguments', t => {
|
|
99
|
+
const complexArgs = {
|
|
100
|
+
path: '/very/long/path',
|
|
101
|
+
options: { recursive: true, force: true },
|
|
102
|
+
metadata: { created: new Date(), author: 'test' },
|
|
103
|
+
};
|
|
104
|
+
const toolCalls = [createMockToolCall('call-1', 'ComplexTool', complexArgs)];
|
|
105
|
+
const results = createCancellationResults(toolCalls);
|
|
106
|
+
// Result should not include arguments
|
|
107
|
+
t.false('arguments' in results[0]);
|
|
108
|
+
// Only expected fields should be present
|
|
109
|
+
t.is(Object.keys(results[0]).length, 4); // tool_call_id, role, name, content
|
|
110
|
+
});
|
|
111
|
+
// Multiple tool calls with same name
|
|
112
|
+
test('createCancellationResults - handles multiple calls to same tool', t => {
|
|
113
|
+
const toolCalls = [
|
|
114
|
+
createMockToolCall('call-1', 'ReadFile', { path: '/file1' }),
|
|
115
|
+
createMockToolCall('call-2', 'ReadFile', { path: '/file2' }),
|
|
116
|
+
createMockToolCall('call-3', 'ReadFile', { path: '/file3' }),
|
|
117
|
+
];
|
|
118
|
+
const results = createCancellationResults(toolCalls);
|
|
119
|
+
t.is(results.length, 3);
|
|
120
|
+
// All should have same name but different IDs
|
|
121
|
+
t.is(results[0].name, 'ReadFile');
|
|
122
|
+
t.is(results[1].name, 'ReadFile');
|
|
123
|
+
t.is(results[2].name, 'ReadFile');
|
|
124
|
+
t.is(results[0].tool_call_id, 'call-1');
|
|
125
|
+
t.is(results[1].tool_call_id, 'call-2');
|
|
126
|
+
t.is(results[2].tool_call_id, 'call-3');
|
|
127
|
+
});
|
|
128
|
+
// Result structure validation
|
|
129
|
+
test('createCancellationResults - result has correct structure', t => {
|
|
130
|
+
const toolCalls = [createMockToolCall('call-1', 'TestTool')];
|
|
131
|
+
const results = createCancellationResults(toolCalls);
|
|
132
|
+
const result = results[0];
|
|
133
|
+
t.true('tool_call_id' in result);
|
|
134
|
+
t.true('role' in result);
|
|
135
|
+
t.true('name' in result);
|
|
136
|
+
t.true('content' in result);
|
|
137
|
+
t.is(typeof result.tool_call_id, 'string');
|
|
138
|
+
t.is(typeof result.role, 'string');
|
|
139
|
+
t.is(typeof result.name, 'string');
|
|
140
|
+
t.is(typeof result.content, 'string');
|
|
141
|
+
});
|
|
142
|
+
// Array immutability test
|
|
143
|
+
test('createCancellationResults - does not modify input array', t => {
|
|
144
|
+
const toolCalls = [
|
|
145
|
+
createMockToolCall('call-1', 'Tool1'),
|
|
146
|
+
createMockToolCall('call-2', 'Tool2'),
|
|
147
|
+
];
|
|
148
|
+
const originalLength = toolCalls.length;
|
|
149
|
+
const originalFirstId = toolCalls[0].id;
|
|
150
|
+
createCancellationResults(toolCalls);
|
|
151
|
+
t.is(toolCalls.length, originalLength);
|
|
152
|
+
t.is(toolCalls[0].id, originalFirstId);
|
|
153
|
+
});
|
|
154
|
+
// Real-world scenario test
|
|
155
|
+
test('createCancellationResults - realistic multi-tool cancellation', t => {
|
|
156
|
+
const toolCalls = [
|
|
157
|
+
createMockToolCall('tc-001', 'ReadFile', {
|
|
158
|
+
path: '/project/config.json',
|
|
159
|
+
}),
|
|
160
|
+
createMockToolCall('tc-002', 'FindFiles', {
|
|
161
|
+
pattern: '**/*.ts',
|
|
162
|
+
path: '/project',
|
|
163
|
+
}),
|
|
164
|
+
createMockToolCall('tc-003', 'ExecuteBash', {
|
|
165
|
+
command: 'npm test',
|
|
166
|
+
}),
|
|
167
|
+
createMockToolCall('tc-004', 'WriteFile', {
|
|
168
|
+
path: '/output.txt',
|
|
169
|
+
content: 'test',
|
|
170
|
+
}),
|
|
171
|
+
];
|
|
172
|
+
const results = createCancellationResults(toolCalls);
|
|
173
|
+
t.is(results.length, 4);
|
|
174
|
+
// Verify all have correct structure and cancellation message
|
|
175
|
+
results.forEach((result, index) => {
|
|
176
|
+
t.is(result.tool_call_id, `tc-00${index + 1}`);
|
|
177
|
+
t.is(result.role, 'tool');
|
|
178
|
+
t.is(result.content, 'Tool execution was cancelled by the user.');
|
|
179
|
+
});
|
|
180
|
+
// Verify specific tool names are preserved
|
|
181
|
+
t.is(results[0].name, 'ReadFile');
|
|
182
|
+
t.is(results[1].name, 'FindFiles');
|
|
183
|
+
t.is(results[2].name, 'ExecuteBash');
|
|
184
|
+
t.is(results[3].name, 'WriteFile');
|
|
185
|
+
});
|
|
186
|
+
//# sourceMappingURL=tool-cancellation.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-cancellation.spec.js","sourceRoot":"","sources":["../../source/utils/tool-cancellation.spec.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,KAAK,CAAC;AAEvB,OAAO,EAAC,yBAAyB,EAAC,MAAM,qBAAqB,CAAC;AAE9D,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAE3C,mCAAmC;AACnC,SAAS,kBAAkB,CAC1B,EAAU,EACV,IAAY,EACZ,OAAgC,EAAE;IAElC,OAAO;QACN,EAAE;QACF,QAAQ,EAAE;YACT,IAAI;YACJ,SAAS,EAAE,IAAI;SACf;KACD,CAAC;AACH,CAAC;AAED,4BAA4B;AAC5B,IAAI,CAAC,iEAAiE,EAAE,CAAC,CAAC,EAAE;IAC3E,MAAM,SAAS,GAAG,CAAC,kBAAkB,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAC,IAAI,EAAE,OAAO,EAAC,CAAC,CAAC,CAAC;IAC9E,MAAM,OAAO,GAAG,yBAAyB,CAAC,SAAS,CAAC,CAAC;IAErD,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACxB,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CA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AC,CAAC,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACnC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACrC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AACpC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ToolCall, ToolResult } from '../types/index.js';
|
|
3
|
+
import type { ToolManager } from '../tools/tool-manager.js';
|
|
4
|
+
/**
|
|
5
|
+
* Display tool result with proper formatting
|
|
6
|
+
* Extracted to eliminate duplication between useChatHandler and useToolHandler
|
|
7
|
+
*
|
|
8
|
+
* @param toolCall - The tool call that was executed
|
|
9
|
+
* @param result - The result from tool execution
|
|
10
|
+
* @param toolManager - The tool manager instance (for formatters)
|
|
11
|
+
* @param addToChatQueue - Function to add components to chat queue
|
|
12
|
+
* @param componentKeyCounter - Counter for generating unique React keys
|
|
13
|
+
*/
|
|
14
|
+
export declare function displayToolResult(toolCall: ToolCall, result: ToolResult, toolManager: ToolManager | null, addToChatQueue: (component: React.ReactNode) => void, componentKeyCounter: number): Promise<void>;
|
|
15
|
+
//# sourceMappingURL=tool-result-display.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-result-display.d.ts","sourceRoot":"","sources":["../../source/utils/tool-result-display.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAC,QAAQ,EAAE,UAAU,EAAC,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAKtD;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CACtC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,UAAU,EAClB,WAAW,EAAE,WAAW,GAAG,IAAI,EAC/B,cAAc,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,KAAK,IAAI,EACpD,mBAAmB,EAAE,MAAM,GACzB,OAAO,CAAC,IAAI,CAAC,CAqEf"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { parseToolArguments } from '../utils/tool-args-parser.js';
|
|
4
|
+
import ToolMessage from '../components/tool-message.js';
|
|
5
|
+
import ErrorMessage from '../components/error-message.js';
|
|
6
|
+
/**
|
|
7
|
+
* Display tool result with proper formatting
|
|
8
|
+
* Extracted to eliminate duplication between useChatHandler and useToolHandler
|
|
9
|
+
*
|
|
10
|
+
* @param toolCall - The tool call that was executed
|
|
11
|
+
* @param result - The result from tool execution
|
|
12
|
+
* @param toolManager - The tool manager instance (for formatters)
|
|
13
|
+
* @param addToChatQueue - Function to add components to chat queue
|
|
14
|
+
* @param componentKeyCounter - Counter for generating unique React keys
|
|
15
|
+
*/
|
|
16
|
+
export async function displayToolResult(toolCall, result, toolManager, addToChatQueue, componentKeyCounter) {
|
|
17
|
+
// Check if this is an error result
|
|
18
|
+
const isError = result.content.startsWith('Error: ');
|
|
19
|
+
if (isError) {
|
|
20
|
+
// Display as error message
|
|
21
|
+
const errorMessage = result.content.replace(/^Error: /, '');
|
|
22
|
+
addToChatQueue(_jsx(ErrorMessage, { message: errorMessage, hideBox: true }, `tool-error-${result.tool_call_id}-${componentKeyCounter}-${Date.now()}`));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (toolManager) {
|
|
26
|
+
const formatter = toolManager.getToolFormatter(result.name);
|
|
27
|
+
if (formatter) {
|
|
28
|
+
try {
|
|
29
|
+
const parsedArgs = parseToolArguments(toolCall.function.arguments);
|
|
30
|
+
const formattedResult = await formatter(parsedArgs, result.content);
|
|
31
|
+
if (React.isValidElement(formattedResult)) {
|
|
32
|
+
addToChatQueue(React.cloneElement(formattedResult, {
|
|
33
|
+
key: `tool-result-${result.tool_call_id}-${componentKeyCounter}-${Date.now()}`,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
addToChatQueue(_jsx(ToolMessage, { title: `⚒ ${result.name}`, message: String(formattedResult), hideBox: true }, `tool-result-${result.tool_call_id}-${componentKeyCounter}-${Date.now()}`));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// If formatter fails, show raw result
|
|
42
|
+
addToChatQueue(_jsx(ToolMessage, { title: `⚒ ${result.name}`, message: result.content, hideBox: true }, `tool-result-${result.tool_call_id}-${componentKeyCounter}`));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// No formatter, show raw result
|
|
47
|
+
addToChatQueue(_jsx(ToolMessage, { title: `⚒ ${result.name}`, message: result.content, hideBox: true }, `tool-result-${result.tool_call_id}-${componentKeyCounter}`));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=tool-result-display.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-result-display.js","sourceRoot":"","sources":["../../source/utils/tool-result-display.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAC,kBAAkB,EAAC,MAAM,0BAA0B,CAAC;AAC5D,OAAO,WAAW,MAAM,2BAA2B,CAAC;AACpD,OAAO,YAAY,MAAM,4BAA4B,CAAC;AAEtD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACtC,QAAkB,EAClB,MAAkB,EAClB,WAA+B,EAC/B,cAAoD,EACpD,mBAA2B;IAE3B,mCAAmC;IACnC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IAErD,IAAI,OAAO,EAAE,CAAC;QACb,2BAA2B;QAC3B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AAI,EAAE,EACzB,OAAO,EAAE,MAAM,CAAC,OAAO,EACvB,OAAO,EAAE,IAAI,IAHR,eAAe,MAAM,CAAC,YAAY,IAAI,mBAAmB,EAAE,CAI/D,CACF,CAAC;YACH,CAAC;QACF,CAAC;aAAM,CAAC;YACP,gCAAgC;YAChC,cAAc,CACb,KAAC,WAAW,IAEX,KAAK,EAAE,KAAK,MAAM,CAAC,IAAI,EAAE,EACzB,OAAO,EAAE,MAAM,CAAC,OAAO,EACvB,OAAO,EAAE,IAAI,IAHR,eAAe,MAAM,CAAC,YAAY,IAAI,mBAAmB,EAAE,CAI/D,CACF,CAAC;QACH,CAAC;IACF,CAAC;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nanocollective/nanocoder",
|
|
3
3
|
"main": "dist/cli.js",
|
|
4
|
-
"version": "1.16.
|
|
4
|
+
"version": "1.16.5",
|
|
5
5
|
"description": "A local-first CLI coding agent that brings the power of agentic coding tools like Claude Code and Gemini CLI to local models or controlled APIs like OpenRouter",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"cli",
|