@vybestack/llxprt-code-core 0.5.0-nightly.251108.557a0fe7 → 0.5.0-nightly.251110.c0116408
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/src/core/coreToolScheduler.js +5 -5
- package/dist/src/core/coreToolScheduler.js.map +1 -1
- package/dist/src/core/prompts.js +53 -0
- package/dist/src/core/prompts.js.map +1 -1
- package/dist/src/core/turn.js +19 -2
- package/dist/src/core/turn.js.map +1 -1
- package/dist/src/parsers/TextToolCallParser.d.ts +3 -1
- package/dist/src/parsers/TextToolCallParser.js +68 -20
- package/dist/src/parsers/TextToolCallParser.js.map +1 -1
- package/dist/src/providers/anthropic/AnthropicProvider.js +12 -18
- package/dist/src/providers/anthropic/AnthropicProvider.js.map +1 -1
- package/dist/src/providers/gemini/GeminiProvider.js +9 -1
- package/dist/src/providers/gemini/GeminiProvider.js.map +1 -1
- package/dist/src/providers/openai/OpenAIProvider.d.ts +27 -5
- package/dist/src/providers/openai/OpenAIProvider.js +1078 -117
- package/dist/src/providers/openai/OpenAIProvider.js.map +1 -1
- package/dist/src/providers/openai/ToolCallCollector.d.ts +77 -0
- package/dist/src/providers/openai/ToolCallCollector.js +150 -0
- package/dist/src/providers/openai/ToolCallCollector.js.map +1 -0
- package/dist/src/providers/openai/ToolCallExecutor.d.ts +65 -0
- package/dist/src/providers/openai/ToolCallExecutor.js +120 -0
- package/dist/src/providers/openai/ToolCallExecutor.js.map +1 -0
- package/dist/src/providers/openai/ToolCallNormalizer.d.ts +47 -0
- package/dist/src/providers/openai/ToolCallNormalizer.js +101 -0
- package/dist/src/providers/openai/ToolCallNormalizer.js.map +1 -0
- package/dist/src/providers/openai/ToolCallPipeline.d.ts +80 -0
- package/dist/src/providers/openai/ToolCallPipeline.js +137 -0
- package/dist/src/providers/openai/ToolCallPipeline.js.map +1 -0
- package/dist/src/providers/openai/ToolCallValidator.d.ts +55 -0
- package/dist/src/providers/openai/ToolCallValidator.js +108 -0
- package/dist/src/providers/openai/ToolCallValidator.js.map +1 -0
- package/dist/src/providers/openai/ToolNameValidator.d.ts +38 -0
- package/dist/src/providers/openai/ToolNameValidator.js +90 -0
- package/dist/src/providers/openai/ToolNameValidator.js.map +1 -0
- package/dist/src/providers/openai/test-types.d.ts +37 -0
- package/dist/src/providers/openai/test-types.js +3 -0
- package/dist/src/providers/openai/test-types.js.map +1 -0
- package/dist/src/providers/openai/toolNameUtils.d.ts +57 -0
- package/dist/src/providers/openai/toolNameUtils.js +180 -0
- package/dist/src/providers/openai/toolNameUtils.js.map +1 -0
- package/dist/src/providers/types/IProviderConfig.d.ts +6 -0
- package/dist/src/providers/utils/toolResponsePayload.d.ts +18 -0
- package/dist/src/providers/utils/toolResponsePayload.js +130 -0
- package/dist/src/providers/utils/toolResponsePayload.js.map +1 -0
- package/dist/src/runtime/AgentRuntimeLoader.js +5 -5
- package/dist/src/runtime/AgentRuntimeLoader.js.map +1 -1
- package/dist/src/services/history/HistoryService.js +7 -19
- package/dist/src/services/history/HistoryService.js.map +1 -1
- package/dist/src/tools/ToolFormatter.js +9 -40
- package/dist/src/tools/ToolFormatter.js.map +1 -1
- package/dist/src/tools/tool-registry.js +20 -9
- package/dist/src/tools/tool-registry.js.map +1 -1
- package/dist/src/tools/toolNameUtils.d.ts +43 -0
- package/dist/src/tools/toolNameUtils.js +126 -0
- package/dist/src/tools/toolNameUtils.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 Vybestack LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* ToolCallExecutor - Execute tool calls
|
|
18
|
+
*
|
|
19
|
+
* Responsible for executing normalized tool calls and handling execution results.
|
|
20
|
+
*/
|
|
21
|
+
import { DebugLogger } from '../../debug/index.js';
|
|
22
|
+
const logger = new DebugLogger('llxprt:providers:openai:toolCallExecutor');
|
|
23
|
+
/**
|
|
24
|
+
* ToolCallExecutor - Responsible for executing tool calls
|
|
25
|
+
*/
|
|
26
|
+
export class ToolCallExecutor {
|
|
27
|
+
toolRegistry = new Map();
|
|
28
|
+
/**
|
|
29
|
+
* Register tool function
|
|
30
|
+
*/
|
|
31
|
+
registerTool(name, fn) {
|
|
32
|
+
this.toolRegistry.set(name, fn);
|
|
33
|
+
logger.debug(`Registered tool: ${name}`);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Batch register tool functions
|
|
37
|
+
*/
|
|
38
|
+
registerTools(tools) {
|
|
39
|
+
for (const [name, fn] of Object.entries(tools)) {
|
|
40
|
+
this.registerTool(name, fn);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Execute single tool call
|
|
45
|
+
*/
|
|
46
|
+
async execute(normalizedCall) {
|
|
47
|
+
const startTime = Date.now();
|
|
48
|
+
try {
|
|
49
|
+
const toolFn = this.toolRegistry.get(normalizedCall.name);
|
|
50
|
+
if (!toolFn) {
|
|
51
|
+
throw new Error(`Tool '${normalizedCall.name}' is not registered`);
|
|
52
|
+
}
|
|
53
|
+
logger.debug(`Executing tool call ${normalizedCall.index}: ${normalizedCall.name}`);
|
|
54
|
+
const result = await toolFn(normalizedCall.args);
|
|
55
|
+
const executionTime = Date.now() - startTime;
|
|
56
|
+
logger.debug(`Tool call ${normalizedCall.index} completed in ${executionTime}ms`);
|
|
57
|
+
return {
|
|
58
|
+
index: normalizedCall.index,
|
|
59
|
+
name: normalizedCall.name,
|
|
60
|
+
success: true,
|
|
61
|
+
result,
|
|
62
|
+
executionTime,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
const executionTime = Date.now() - startTime;
|
|
67
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
68
|
+
logger.error(`Tool call ${normalizedCall.index} failed: ${errorMessage}`);
|
|
69
|
+
return {
|
|
70
|
+
index: normalizedCall.index,
|
|
71
|
+
name: normalizedCall.name,
|
|
72
|
+
success: false,
|
|
73
|
+
error: errorMessage,
|
|
74
|
+
executionTime,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Batch execute tool calls
|
|
80
|
+
*/
|
|
81
|
+
async executeBatch(normalizedCalls) {
|
|
82
|
+
// Execute sequentially to avoid resource conflicts
|
|
83
|
+
const results = [];
|
|
84
|
+
for (const call of normalizedCalls) {
|
|
85
|
+
const result = await this.execute(call);
|
|
86
|
+
results.push(result);
|
|
87
|
+
}
|
|
88
|
+
return results;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Check if tool is registered
|
|
92
|
+
*/
|
|
93
|
+
isToolRegistered(name) {
|
|
94
|
+
return this.toolRegistry.has(name);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get list of registered tool names
|
|
98
|
+
*/
|
|
99
|
+
getRegisteredTools() {
|
|
100
|
+
return Array.from(this.toolRegistry.keys());
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Remove registered tool
|
|
104
|
+
*/
|
|
105
|
+
unregisterTool(name) {
|
|
106
|
+
const removed = this.toolRegistry.delete(name);
|
|
107
|
+
if (removed) {
|
|
108
|
+
logger.debug(`Unregistered tool: ${name}`);
|
|
109
|
+
}
|
|
110
|
+
return removed;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Clear all registered tools
|
|
114
|
+
*/
|
|
115
|
+
clearTools() {
|
|
116
|
+
this.toolRegistry.clear();
|
|
117
|
+
logger.debug('Cleared all registered tools');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=ToolCallExecutor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolCallExecutor.js","sourceRoot":"","sources":["../../../../src/providers/openai/ToolCallExecutor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,0CAA0C,CAAC,CAAC;AAe3E;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACnB,YAAY,GAAG,IAAI,GAAG,EAAwB,CAAC;IAEvD;;OAEG;IACH,YAAY,CAAC,IAAY,EAAE,EAAgB;QACzC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAChC,MAAM,CAAC,KAAK,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,KAAmC;QAC/C,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/C,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CACX,cAAkC;QAElC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE7B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAC1D,IAAI,CAAC,MAAM,EAAE,CAA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AAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACxC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,gBAAgB,CAAC,IAAY;QAC3B,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,cAAc,CAAC,IAAY;QACzB,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,CAAC,KAAK,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,UAAU;QACR,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;QAC1B,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC/C,CAAC;CACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 Vybestack LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export interface NormalizedToolCall {
|
|
17
|
+
index: number;
|
|
18
|
+
name: string;
|
|
19
|
+
args: Record<string, unknown>;
|
|
20
|
+
originalArgs?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* ToolCallNormalizer - Responsible for normalizing tool calls
|
|
24
|
+
*/
|
|
25
|
+
export declare class ToolCallNormalizer {
|
|
26
|
+
/**
|
|
27
|
+
* Normalize tool calls
|
|
28
|
+
*/
|
|
29
|
+
normalize(validatedCall: ValidatedToolCall): NormalizedToolCall | null;
|
|
30
|
+
/**
|
|
31
|
+
* Normalize tool calls in batch
|
|
32
|
+
*/
|
|
33
|
+
normalizeBatch(validatedCalls: ValidatedToolCall[]): NormalizedToolCall[];
|
|
34
|
+
/**
|
|
35
|
+
* Normalize tool name
|
|
36
|
+
*/
|
|
37
|
+
private normalizeToolName;
|
|
38
|
+
/**
|
|
39
|
+
* Parse arguments string to object
|
|
40
|
+
*/
|
|
41
|
+
private parseArgs;
|
|
42
|
+
/**
|
|
43
|
+
* Validate normalization result
|
|
44
|
+
*/
|
|
45
|
+
validateNormalized(call: NormalizedToolCall): boolean;
|
|
46
|
+
}
|
|
47
|
+
import { ValidatedToolCall } from './ToolCallValidator.js';
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 Vybestack LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* ToolCallNormalizer - Normalizes tool calls
|
|
18
|
+
*
|
|
19
|
+
* Responsible for normalizing validated tool calls to standard format,
|
|
20
|
+
* preparing them for execution phase.
|
|
21
|
+
*/
|
|
22
|
+
import { DebugLogger } from '../../debug/index.js';
|
|
23
|
+
const logger = new DebugLogger('llxprt:providers:openai:toolCallNormalizer');
|
|
24
|
+
/**
|
|
25
|
+
* ToolCallNormalizer - Responsible for normalizing tool calls
|
|
26
|
+
*/
|
|
27
|
+
export class ToolCallNormalizer {
|
|
28
|
+
/**
|
|
29
|
+
* Normalize tool calls
|
|
30
|
+
*/
|
|
31
|
+
normalize(validatedCall) {
|
|
32
|
+
if (!validatedCall.isValid) {
|
|
33
|
+
logger.error(`Cannot normalize invalid tool call ${validatedCall.index}`);
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const normalized = {
|
|
38
|
+
index: validatedCall.index,
|
|
39
|
+
name: this.normalizeToolName(validatedCall.name),
|
|
40
|
+
args: this.parseArgs(validatedCall.args),
|
|
41
|
+
originalArgs: validatedCall.args,
|
|
42
|
+
};
|
|
43
|
+
logger.debug(`Normalized tool call ${validatedCall.index}: ${normalized.name}`);
|
|
44
|
+
return normalized;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
logger.error(`Failed to normalize tool call ${validatedCall.index}: ${error}`);
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Normalize tool calls in batch
|
|
53
|
+
*/
|
|
54
|
+
normalizeBatch(validatedCalls) {
|
|
55
|
+
return validatedCalls
|
|
56
|
+
.map((call) => this.normalize(call))
|
|
57
|
+
.filter((call) => call !== null);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Normalize tool name
|
|
61
|
+
*/
|
|
62
|
+
normalizeToolName(name) {
|
|
63
|
+
// Remove leading/trailing whitespace and convert to lowercase
|
|
64
|
+
return name.trim().toLowerCase();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Parse arguments string to object
|
|
68
|
+
*/
|
|
69
|
+
parseArgs(args) {
|
|
70
|
+
if (!args || !args.trim()) {
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const parsed = JSON.parse(args);
|
|
75
|
+
if (typeof parsed === 'object' && parsed !== null) {
|
|
76
|
+
return parsed;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
logger.warn('Tool call args is not a valid object, wrapping in {value}');
|
|
80
|
+
return { value: parsed };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
logger.warn(`Failed to parse tool call args as JSON: ${error}, treating as string`);
|
|
85
|
+
return { value: args };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Validate normalization result
|
|
90
|
+
*/
|
|
91
|
+
validateNormalized(call) {
|
|
92
|
+
if (!call.name || typeof call.name !== 'string') {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (!call.args || typeof call.args !== 'object') {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=ToolCallNormalizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolCallNormalizer.js","sourceRoot":"","sources":["../../../../src/providers/openai/ToolCallNormalizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,4CAA4C,CAAC,CAAC;AAS7E;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAC7B;;OAEG;IACH,SAAS,CAAC,a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ED,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAChC,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;gBAClD,OAAO,MAAM,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,IAAI,CACT,2DAA2D,CAC5D,CAAC;gBACF,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;YAC3B,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CACT,2CAA2C,KAAK,sBAAsB,CACvE,CAAC;YACF,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QACzB,CAAC;IACH,CAAC;IAED;;OAEG;IACH,kBAAkB,CAAC,IAAwB;QACzC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAChD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAChD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 Vybestack LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { ValidatedToolCall } from './ToolCallValidator.js';
|
|
17
|
+
import { NormalizedToolCall } from './ToolCallNormalizer.js';
|
|
18
|
+
import { ToolExecutionResult, ToolFunction } from './ToolCallExecutor.js';
|
|
19
|
+
export interface PipelineResult {
|
|
20
|
+
executed: ToolExecutionResult[];
|
|
21
|
+
normalized: NormalizedToolCall[];
|
|
22
|
+
failed: ValidatedToolCall[];
|
|
23
|
+
stats: {
|
|
24
|
+
collected: number;
|
|
25
|
+
validated: number;
|
|
26
|
+
normalized: number;
|
|
27
|
+
executed: number;
|
|
28
|
+
failed: number;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* ToolCallPipeline - Complete tool call processing pipeline
|
|
33
|
+
*/
|
|
34
|
+
export declare class ToolCallPipeline {
|
|
35
|
+
private collector;
|
|
36
|
+
private validator;
|
|
37
|
+
private normalizer;
|
|
38
|
+
private executor;
|
|
39
|
+
constructor(allowedToolNames?: string[]);
|
|
40
|
+
/**
|
|
41
|
+
* Add tool call fragment
|
|
42
|
+
*/
|
|
43
|
+
addFragment(index: number, fragment: Partial<ToolCallFragment>): void;
|
|
44
|
+
/**
|
|
45
|
+
* Process all collected tool calls
|
|
46
|
+
*/
|
|
47
|
+
process(): Promise<PipelineResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Register tool function
|
|
50
|
+
*/
|
|
51
|
+
registerTool(name: string, fn: ToolFunction): void;
|
|
52
|
+
/**
|
|
53
|
+
* Register tool functions in batch
|
|
54
|
+
*/
|
|
55
|
+
registerTools(tools: Record<string, ToolFunction>): void;
|
|
56
|
+
/**
|
|
57
|
+
* Check if tool is registered
|
|
58
|
+
*/
|
|
59
|
+
isToolRegistered(name: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Get pipeline statistics
|
|
62
|
+
*/
|
|
63
|
+
getStats(): {
|
|
64
|
+
collector: {
|
|
65
|
+
totalCalls: number;
|
|
66
|
+
completedCalls: number;
|
|
67
|
+
pendingFragments: number;
|
|
68
|
+
};
|
|
69
|
+
registeredTools: number;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Normalize single tool name (for non-streaming path)
|
|
73
|
+
*/
|
|
74
|
+
normalizeToolName(name: string, args?: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* Reset pipeline state
|
|
77
|
+
*/
|
|
78
|
+
reset(): void;
|
|
79
|
+
}
|
|
80
|
+
import { ToolCallFragment } from './ToolCallCollector.js';
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 Vybestack LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* ToolCallPipeline - Tool call processing pipeline
|
|
18
|
+
*
|
|
19
|
+
* Integrated solution for collection, validation, normalization, and execution phases.
|
|
20
|
+
* Replaces the original accumulation logic, providing reliable ToolCalls processing.
|
|
21
|
+
*/
|
|
22
|
+
import { DebugLogger } from '../../debug/index.js';
|
|
23
|
+
import { ToolCallCollector } from './ToolCallCollector.js';
|
|
24
|
+
import { ToolCallValidator } from './ToolCallValidator.js';
|
|
25
|
+
import { ToolCallNormalizer, } from './ToolCallNormalizer.js';
|
|
26
|
+
import { ToolCallExecutor, } from './ToolCallExecutor.js';
|
|
27
|
+
const logger = new DebugLogger('llxprt:providers:openai:toolCallPipeline');
|
|
28
|
+
/**
|
|
29
|
+
* ToolCallPipeline - Complete tool call processing pipeline
|
|
30
|
+
*/
|
|
31
|
+
export class ToolCallPipeline {
|
|
32
|
+
collector;
|
|
33
|
+
validator;
|
|
34
|
+
normalizer;
|
|
35
|
+
executor;
|
|
36
|
+
constructor(allowedToolNames = []) {
|
|
37
|
+
this.collector = new ToolCallCollector();
|
|
38
|
+
this.validator = new ToolCallValidator(allowedToolNames);
|
|
39
|
+
this.normalizer = new ToolCallNormalizer();
|
|
40
|
+
this.executor = new ToolCallExecutor();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Add tool call fragment
|
|
44
|
+
*/
|
|
45
|
+
addFragment(index, fragment) {
|
|
46
|
+
this.collector.addFragment(index, fragment);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Process all collected tool calls
|
|
50
|
+
*/
|
|
51
|
+
async process() {
|
|
52
|
+
logger.debug('Starting tool call pipeline processing');
|
|
53
|
+
// Phase 1: Collect complete calls
|
|
54
|
+
const candidates = this.collector.getCompleteCalls();
|
|
55
|
+
logger.debug(`Collected ${candidates.length} complete tool calls`);
|
|
56
|
+
// Phase 2: Validate calls
|
|
57
|
+
const validatedCalls = this.validator.validateBatch(candidates);
|
|
58
|
+
const validCalls = validatedCalls.filter((call) => call.isValid);
|
|
59
|
+
const invalidCalls = validatedCalls.filter((call) => !call.isValid);
|
|
60
|
+
logger.debug(`Validated ${validCalls.length} valid, ${invalidCalls.length} invalid tool calls`);
|
|
61
|
+
// Phase 3: Normalize calls
|
|
62
|
+
const normalizedCalls = this.normalizer.normalizeBatch(validCalls);
|
|
63
|
+
logger.debug(`Normalized ${normalizedCalls.length} tool calls`);
|
|
64
|
+
// Phase 4: Execute calls
|
|
65
|
+
const executionResults = await this.executor.executeBatch(normalizedCalls);
|
|
66
|
+
const successfulResults = executionResults.filter((result) => result.success);
|
|
67
|
+
const failedResults = executionResults.filter((result) => !result.success);
|
|
68
|
+
logger.debug(`Executed ${successfulResults.length} successful, ${failedResults.length} failed tool calls`);
|
|
69
|
+
// Reset collector for next batch
|
|
70
|
+
this.collector.reset();
|
|
71
|
+
const result = {
|
|
72
|
+
executed: executionResults,
|
|
73
|
+
normalized: normalizedCalls,
|
|
74
|
+
failed: invalidCalls,
|
|
75
|
+
stats: {
|
|
76
|
+
collected: candidates.length,
|
|
77
|
+
validated: validCalls.length,
|
|
78
|
+
normalized: normalizedCalls.length,
|
|
79
|
+
executed: successfulResults.length,
|
|
80
|
+
failed: invalidCalls.length + failedResults.length,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
logger.debug(`Pipeline processing completed: ${JSON.stringify(result.stats)}`);
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Register tool function
|
|
88
|
+
*/
|
|
89
|
+
registerTool(name, fn) {
|
|
90
|
+
this.executor.registerTool(name, fn);
|
|
91
|
+
this.validator.updateAllowedTools(this.executor.getRegisteredTools());
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Register tool functions in batch
|
|
95
|
+
*/
|
|
96
|
+
registerTools(tools) {
|
|
97
|
+
this.executor.registerTools(tools);
|
|
98
|
+
this.validator.updateAllowedTools(this.executor.getRegisteredTools());
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Check if tool is registered
|
|
102
|
+
*/
|
|
103
|
+
isToolRegistered(name) {
|
|
104
|
+
return this.executor.isToolRegistered(name);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get pipeline statistics
|
|
108
|
+
*/
|
|
109
|
+
getStats() {
|
|
110
|
+
return {
|
|
111
|
+
collector: this.collector.getStats(),
|
|
112
|
+
registeredTools: this.executor.getRegisteredTools().length,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Normalize single tool name (for non-streaming path)
|
|
117
|
+
*/
|
|
118
|
+
normalizeToolName(name, args) {
|
|
119
|
+
const mockValidatedCall = {
|
|
120
|
+
index: 0,
|
|
121
|
+
name: name || '',
|
|
122
|
+
args: args || '',
|
|
123
|
+
isValid: true,
|
|
124
|
+
validationErrors: [],
|
|
125
|
+
};
|
|
126
|
+
const normalized = this.normalizer.normalize(mockValidatedCall);
|
|
127
|
+
return normalized?.name || name || '';
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Reset pipeline state
|
|
131
|
+
*/
|
|
132
|
+
reset() {
|
|
133
|
+
this.collector.reset();
|
|
134
|
+
logger.debug('ToolCallPipeline reset');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=ToolCallPipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolCallPipeline.js","sourceRoot":"","sources":["../../../../src/providers/openai/ToolCallPipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAqB,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EACL,kBAAkB,GAEnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,gBAAgB,GAGjB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,0CAA0C,CAAC,CAAC;AAe3E;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACnB,SAAS,CAAoB;IAC7B,SAAS,CAAoB;IAC7B,UAAU,CAAqB;IAC/B,QAAQ,CAAmB;IAEnC,YAAY,mBAA6B,EAAE;QACzC,IAAI,CAAC,SAAS,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACzC,IAAI,CAAC,SAAS,GAAG,IAAI,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;QACzD,IAAI,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,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACxE,CAAC;IAED;;OAEG;IACH,gBAAgB,CAAC,IAAY;QAC3B,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;YACpC,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC,MAAM;SAC3D,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,iBAAiB,CAAC,IAAY,EAAE,IAAa;QAC3C,MAAM,iBAAiB,GAAG;YACxB,KAAK,EAAE,CAAC;YACR,IAAI,EAAE,IAAI,IAAI,EAAE;YAChB,IAAI,EAAE,IAAI,IAAI,EAAE;YAChB,OAAO,EAAE,IAAI;YACb,gBAAgB,EAAE,EAAE;SACrB,CAAC;QAEF,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;QAChE,OAAO,UAAU,EAAE,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 Vybestack LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export interface ValidationResult {
|
|
17
|
+
isValid: boolean;
|
|
18
|
+
errors: string[];
|
|
19
|
+
warnings: string[];
|
|
20
|
+
}
|
|
21
|
+
export interface ValidatedToolCall {
|
|
22
|
+
index: number;
|
|
23
|
+
name: string;
|
|
24
|
+
args?: string;
|
|
25
|
+
isValid: boolean;
|
|
26
|
+
validationErrors: string[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* ToolCallValidator - The verification tool calls the candidates.
|
|
30
|
+
*/
|
|
31
|
+
export declare class ToolCallValidator {
|
|
32
|
+
private allowedToolNames;
|
|
33
|
+
constructor(allowedToolNames?: string[]);
|
|
34
|
+
/**
|
|
35
|
+
* Validate tool call candidate
|
|
36
|
+
*/
|
|
37
|
+
validate(candidate: ToolCallCandidate): ValidatedToolCall;
|
|
38
|
+
/**
|
|
39
|
+
* Batch validate tool call candidates
|
|
40
|
+
*/
|
|
41
|
+
validateBatch(candidates: ToolCallCandidate[]): ValidatedToolCall[];
|
|
42
|
+
/**
|
|
43
|
+
* Check if tool name is valid
|
|
44
|
+
*/
|
|
45
|
+
private isValidToolName;
|
|
46
|
+
/**
|
|
47
|
+
* Check if parameters are valid JSON
|
|
48
|
+
*/
|
|
49
|
+
private isValidArgs;
|
|
50
|
+
/**
|
|
51
|
+
* Update allowed tool names list
|
|
52
|
+
*/
|
|
53
|
+
updateAllowedTools(allowedToolNames: string[]): void;
|
|
54
|
+
}
|
|
55
|
+
import { ToolCallCandidate } from './ToolCallCollector.js';
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 Vybestack LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* ToolCallValidator - Validates tool call candidates
|
|
18
|
+
*
|
|
19
|
+
* Responsible for validating collected tool call candidates to ensure they are valid
|
|
20
|
+
* and meet execution requirements.
|
|
21
|
+
*/
|
|
22
|
+
import { DebugLogger } from '../../debug/index.js';
|
|
23
|
+
const logger = new DebugLogger('llxprt:providers:openai:toolCallValidator');
|
|
24
|
+
/**
|
|
25
|
+
* ToolCallValidator - The verification tool calls the candidates.
|
|
26
|
+
*/
|
|
27
|
+
export class ToolCallValidator {
|
|
28
|
+
allowedToolNames;
|
|
29
|
+
constructor(allowedToolNames = []) {
|
|
30
|
+
this.allowedToolNames = new Set(allowedToolNames);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Validate tool call candidate
|
|
34
|
+
*/
|
|
35
|
+
validate(candidate) {
|
|
36
|
+
const result = {
|
|
37
|
+
index: candidate.index,
|
|
38
|
+
name: candidate.name || '',
|
|
39
|
+
args: candidate.args,
|
|
40
|
+
isValid: true,
|
|
41
|
+
validationErrors: [],
|
|
42
|
+
};
|
|
43
|
+
const errors = [];
|
|
44
|
+
// Check if name exists
|
|
45
|
+
if (!candidate.name || !candidate.name.trim()) {
|
|
46
|
+
errors.push('Tool call missing name');
|
|
47
|
+
result.isValid = false;
|
|
48
|
+
}
|
|
49
|
+
// Check if name is in allowed list
|
|
50
|
+
if (candidate.name &&
|
|
51
|
+
this.allowedToolNames.size > 0 &&
|
|
52
|
+
!this.allowedToolNames.has(candidate.name)) {
|
|
53
|
+
errors.push(`Tool name '${candidate.name}' is not in allowed list`);
|
|
54
|
+
result.isValid = false;
|
|
55
|
+
}
|
|
56
|
+
// Check name format
|
|
57
|
+
if (candidate.name && !this.isValidToolName(candidate.name)) {
|
|
58
|
+
errors.push(`Tool name '${candidate.name}' contains invalid characters`);
|
|
59
|
+
result.isValid = false;
|
|
60
|
+
}
|
|
61
|
+
// Check parameter format
|
|
62
|
+
if (candidate.args && !this.isValidArgs(candidate.args)) {
|
|
63
|
+
errors.push('Tool call arguments are not valid JSON');
|
|
64
|
+
result.isValid = false;
|
|
65
|
+
}
|
|
66
|
+
result.validationErrors = errors;
|
|
67
|
+
if (!result.isValid) {
|
|
68
|
+
logger.warn(`Tool call ${candidate.index} validation failed: ${errors.join(', ')}`);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
logger.debug(`Tool call ${candidate.index} validation passed`);
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Batch validate tool call candidates
|
|
77
|
+
*/
|
|
78
|
+
validateBatch(candidates) {
|
|
79
|
+
return candidates.map((candidate) => this.validate(candidate));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Check if tool name is valid
|
|
83
|
+
*/
|
|
84
|
+
isValidToolName(name) {
|
|
85
|
+
// Allow letters, numbers, underscores and hyphens
|
|
86
|
+
return /^[a-zA-Z0-9_-]+$/.test(name);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Check if parameters are valid JSON
|
|
90
|
+
*/
|
|
91
|
+
isValidArgs(args) {
|
|
92
|
+
try {
|
|
93
|
+
JSON.parse(args);
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Update allowed tool names list
|
|
102
|
+
*/
|
|
103
|
+
updateAllowedTools(allowedToolNames) {
|
|
104
|
+
this.allowedToolNames = new Set(allowedToolNames);
|
|
105
|
+
logger.debug(`Updated allowed tool names: ${allowedToolNames.join(', ')}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=ToolCallValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolCallValidator.js","sourceRoot":"","sources":["../../../../src/providers/openai/ToolCallValidator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,2CAA2C,CAAC,CAAC;AAgB5E;;GAEG;AACH,MAAM,OAAO,iBAAiB;IACpB,gBAAgB,CAAc;IAEtC,YAAY,mBAA6B,EAAE;QACzC,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,SAA4B;QACnC,MAAM,MAAM,GAAsB;YAChC,KAAK,EAAE,SAAS,CAAC,KAAK;YACtB,IAAI,EAAE,SAAS,CAAC,IAAI,IAAI,EAAE;YAC1B,IAAI,EAAE,SAAS,CAAC,IAAI;YACpB,OAAO,EAAE,IAAI;YACb,gBAAgB,EAAE,EAAE;SACrB,CAAC;QAEF,MAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,uBAAuB;QACvB,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;YAC9C,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;YACtC,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;QACzB,CAAC;QAED,mCAAmC;QACnC,IACE,SAAS,CAAC,IAAI;YACd,IAAI,CAAC,gBAAgB,CAAC,IAAI,GAAG,CAAC;YAC9B,CAAC,IAAI,CAAC,gBA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