mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-13 02:41:50 +08:00
feat: 添加工具调用支持,增强 CLI 工具和 MCP 管理功能
This commit is contained in:
@@ -19,7 +19,8 @@ export type CliOutputUnitType =
|
||||
| 'file_diff' // File modification diff
|
||||
| 'progress' // Progress updates
|
||||
| 'metadata' // Session/execution metadata
|
||||
| 'system'; // System events/messages
|
||||
| 'system' // System events/messages
|
||||
| 'tool_call'; // Tool invocation/result (Gemini tool_use/tool_result)
|
||||
|
||||
/**
|
||||
* Intermediate Representation unit
|
||||
@@ -295,6 +296,38 @@ export class JsonLinesParser implements IOutputParser {
|
||||
};
|
||||
}
|
||||
|
||||
// Gemini tool_use: {"type":"tool_use","timestamp":"...","tool_name":"...","tool_id":"...","parameters":{...}}
|
||||
if (json.type === 'tool_use' && json.tool_name) {
|
||||
return {
|
||||
type: 'tool_call',
|
||||
content: {
|
||||
tool: 'gemini',
|
||||
action: 'invoke',
|
||||
toolName: json.tool_name,
|
||||
toolId: json.tool_id,
|
||||
parameters: json.parameters,
|
||||
raw: json
|
||||
},
|
||||
timestamp
|
||||
};
|
||||
}
|
||||
|
||||
// Gemini tool_result: {"type":"tool_result","timestamp":"...","tool_id":"...","status":"...","output":"..."}
|
||||
if (json.type === 'tool_result' && json.tool_id) {
|
||||
return {
|
||||
type: 'tool_call',
|
||||
content: {
|
||||
tool: 'gemini',
|
||||
action: 'result',
|
||||
toolId: json.tool_id,
|
||||
status: json.status,
|
||||
output: json.output,
|
||||
raw: json
|
||||
},
|
||||
timestamp
|
||||
};
|
||||
}
|
||||
|
||||
// ========== Codex CLI --json format ==========
|
||||
// {"type":"thread.started","thread_id":"..."}
|
||||
// {"type":"turn.started"}
|
||||
@@ -733,6 +766,20 @@ export function flattenOutputUnits(
|
||||
}
|
||||
break;
|
||||
|
||||
case 'tool_call':
|
||||
// Format tool call/result
|
||||
if (unit.content.action === 'invoke') {
|
||||
const params = unit.content.parameters ? JSON.stringify(unit.content.parameters) : '';
|
||||
text += `[Tool] ${unit.content.toolName}(${params})`;
|
||||
} else if (unit.content.action === 'result') {
|
||||
const status = unit.content.status || 'unknown';
|
||||
const output = unit.content.output ? `: ${unit.content.output.substring(0, 200)}${unit.content.output.length > 200 ? '...' : ''}` : '';
|
||||
text += `[Tool Result] ${status}${output}`;
|
||||
} else {
|
||||
text += JSON.stringify(unit.content);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'metadata':
|
||||
case 'system':
|
||||
// Metadata and system events are typically excluded from prompt context
|
||||
|
||||
Reference in New Issue
Block a user