yuangs 2.0.21 → 2.6.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/agent/AgentPipeline.d.ts +4 -0
- package/dist/agent/AgentPipeline.js +84 -0
- package/dist/agent/AgentPipeline.js.map +1 -0
- package/dist/agent/actions.d.ts +4 -0
- package/dist/agent/actions.js +53 -0
- package/dist/agent/actions.js.map +1 -0
- package/dist/agent/context.d.ts +4 -0
- package/dist/agent/context.js +22 -0
- package/dist/agent/context.js.map +1 -0
- package/dist/agent/index.d.ts +2 -0
- package/dist/agent/index.js +21 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/intent.d.ts +2 -0
- package/dist/agent/intent.js +28 -0
- package/dist/agent/intent.js.map +1 -0
- package/dist/agent/interpret.d.ts +3 -0
- package/dist/agent/interpret.js +39 -0
- package/dist/agent/interpret.js.map +1 -0
- package/dist/agent/llm.d.ts +7 -0
- package/dist/agent/llm.js +76 -0
- package/dist/agent/llm.js.map +1 -0
- package/dist/agent/plan.d.ts +13 -0
- package/dist/agent/plan.js +3 -0
- package/dist/agent/plan.js.map +1 -0
- package/dist/agent/planExecutor.d.ts +10 -0
- package/dist/agent/planExecutor.js +74 -0
- package/dist/agent/planExecutor.js.map +1 -0
- package/dist/agent/prompt.d.ts +2 -0
- package/dist/agent/prompt.js +55 -0
- package/dist/agent/prompt.js.map +1 -0
- package/dist/agent/record.d.ts +14 -0
- package/dist/agent/record.js +20 -0
- package/dist/agent/record.js.map +1 -0
- package/dist/agent/replay.d.ts +2 -0
- package/dist/agent/replay.js +25 -0
- package/dist/agent/replay.js.map +1 -0
- package/dist/agent/selectModel.d.ts +2 -0
- package/dist/agent/selectModel.js +19 -0
- package/dist/agent/selectModel.js.map +1 -0
- package/dist/agent/skills.d.ts +31 -0
- package/dist/agent/skills.js +110 -0
- package/dist/agent/skills.js.map +1 -0
- package/dist/agent/types.d.ts +59 -0
- package/dist/agent/types.js +3 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/cli.js +8 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/handleAIChat.js +35 -29
- package/dist/commands/handleAIChat.js.map +1 -1
- package/dist/core/executor.js +3 -2
- package/dist/core/executor.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentPipeline = void 0;
|
|
4
|
+
const intent_1 = require("./intent");
|
|
5
|
+
const context_1 = require("./context");
|
|
6
|
+
const prompt_1 = require("./prompt");
|
|
7
|
+
const selectModel_1 = require("./selectModel");
|
|
8
|
+
const llm_1 = require("./llm");
|
|
9
|
+
const interpret_1 = require("./interpret");
|
|
10
|
+
const planExecutor_1 = require("./planExecutor");
|
|
11
|
+
const record_1 = require("./record");
|
|
12
|
+
const skills_1 = require("./skills");
|
|
13
|
+
const crypto_1 = require("crypto");
|
|
14
|
+
class AgentPipeline {
|
|
15
|
+
async run(input, mode) {
|
|
16
|
+
const id = (0, crypto_1.randomUUID)();
|
|
17
|
+
// 1. Intent Analysis
|
|
18
|
+
const intent = (0, intent_1.inferIntent)(input, mode);
|
|
19
|
+
// 2. Context Assembly
|
|
20
|
+
const context = (0, context_1.buildContext)(input);
|
|
21
|
+
// 3. Prompt Construction
|
|
22
|
+
const prompt = (0, prompt_1.buildPrompt)(intent, context, mode, input.rawInput);
|
|
23
|
+
// 4. Model Selection
|
|
24
|
+
const model = (0, selectModel_1.selectModel)(intent, input.options?.model);
|
|
25
|
+
// 5. LLM Execution
|
|
26
|
+
const result = await (0, llm_1.runLLM)({
|
|
27
|
+
prompt,
|
|
28
|
+
model,
|
|
29
|
+
stream: mode === 'chat',
|
|
30
|
+
onChunk: mode === 'chat'
|
|
31
|
+
? (s) => process.stdout.write(s)
|
|
32
|
+
: undefined,
|
|
33
|
+
});
|
|
34
|
+
// 6. Result Interpretation -> Plan
|
|
35
|
+
const isStreaming = mode === 'chat';
|
|
36
|
+
const plan = (0, interpret_1.interpretResultToPlan)(result, intent, mode, isStreaming);
|
|
37
|
+
result.plan = plan; // Attach plan to result for recording
|
|
38
|
+
// 7. Save Execution Record (before execution for safety)
|
|
39
|
+
(0, record_1.saveRecord)({
|
|
40
|
+
id,
|
|
41
|
+
timestamp: Date.now(),
|
|
42
|
+
mode,
|
|
43
|
+
input,
|
|
44
|
+
prompt,
|
|
45
|
+
model,
|
|
46
|
+
llmResult: result,
|
|
47
|
+
action: plan.tasks[0]?.type === 'shell' ? {
|
|
48
|
+
type: 'execute',
|
|
49
|
+
command: plan.tasks[0].payload.command,
|
|
50
|
+
risk: plan.tasks[0].payload.risk
|
|
51
|
+
} : { type: 'print', content: result.rawText }, // For backward compatibility with record.action
|
|
52
|
+
});
|
|
53
|
+
// 8. Plan Execution
|
|
54
|
+
const summary = await (0, planExecutor_1.executePlan)(plan, input.options);
|
|
55
|
+
// 9. Post-execution: Learn Skill if successful
|
|
56
|
+
(0, skills_1.learnSkillFromRecord)({
|
|
57
|
+
id,
|
|
58
|
+
timestamp: Date.now(),
|
|
59
|
+
mode,
|
|
60
|
+
input,
|
|
61
|
+
prompt,
|
|
62
|
+
model,
|
|
63
|
+
llmResult: result,
|
|
64
|
+
action: plan.tasks[0]?.type === 'shell' ? {
|
|
65
|
+
type: 'execute',
|
|
66
|
+
command: plan.tasks[0].payload.command,
|
|
67
|
+
risk: plan.tasks[0].payload.risk
|
|
68
|
+
} : { type: 'print', content: result.rawText },
|
|
69
|
+
}, summary.success);
|
|
70
|
+
// Log execution metrics if verbose
|
|
71
|
+
if (input.options?.verbose) {
|
|
72
|
+
console.log(`\n${'-'.repeat(50)}`);
|
|
73
|
+
console.log(`Execution ID: ${id}`);
|
|
74
|
+
console.log(`Model: ${model}`);
|
|
75
|
+
console.log(`Latency: ${result.latencyMs}ms`);
|
|
76
|
+
if (result.tokens) {
|
|
77
|
+
console.log(`Tokens: ${result.tokens.total}`);
|
|
78
|
+
}
|
|
79
|
+
console.log(`${'-'.repeat(50)}\n`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.AgentPipeline = AgentPipeline;
|
|
84
|
+
//# sourceMappingURL=AgentPipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentPipeline.js","sourceRoot":"","sources":["../../src/agent/AgentPipeline.ts"],"names":[],"mappings":";;;AAKA,qCAAuC;AACvC,uCAAyC;AACzC,qCAAuC;AACvC,+CAA4C;AAC5C,+BAA+B;AAC/B,2CAAoD;AACpD,iDAA6C;AAC7C,qCAAsC;AACtC,qCAAgD;AAChD,mCAAoC;AAEpC,MAAa,aAAa;IACtB,KAAK,CAAC,GAAG,CAAC,KAAiB,EAAE,IAAe;QACxC,MAAM,EAAE,GAAG,IAAA,mBAAU,GAAE,CAAC;QAExB,qBAAqB;QACrB,MAAM,MAAM,GAAG,IAAA,oBAAW,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAExC,sBAAsB;QACtB,MAAM,OAAO,GAAG,IAAA,sBAAY,EAAC,KAAK,CAAC,CAAC;QAEpC,yBAAyB;QACzB,MAAM,MAAM,GAAG,IAAA,oBAAW,EAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;QAElE,qBAAqB;QACrB,MAAM,KAAK,GAAG,IAAA,yBAAW,EAAC,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAExD,mBAAmB;QACnB,MAAM,MAAM,GAAG,MAAM,IAAA,YAAM,EAAC;YACxB,MAAM;YACN,KAAK;YACL,MAAM,EAAE,IAAI,KAAK,MAAM;YACvB,OAAO,EAAE,IAAI,KAAK,MAAM;gBACpB,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;gBAChC,CAAC,CAAC,SAAS;SAClB,CAAC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C,CAAC,OAAO,CAAC,OAAO;gBACtC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI;aACnC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE;SACjD,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAEpB,mCAAmC;QACnC,IAAI,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC;YACzB,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YACnC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;YACnC,OAAO,CAAC,GAAG,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC;YAC/B,OAAO,CAAC,GAAG,CAAC,YAAY,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;YAC9C,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;gBAChB,OAAO,CAAC,GAAG,CAAC,WAAW,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;YAClD,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QACvC,CAAC;IACL,CAAC;CACJ;AA9ED,sCA8EC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.executeAction = executeAction;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const util_1 = require("util");
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
const readline_1 = __importDefault(require("readline"));
|
|
11
|
+
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
12
|
+
async function executeAction(action, options) {
|
|
13
|
+
if (action.type === 'print') {
|
|
14
|
+
console.log(action.content);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (action.type === 'confirm') {
|
|
18
|
+
const ok = options?.autoYes || await confirm('Execute this action?');
|
|
19
|
+
if (ok) {
|
|
20
|
+
await executeAction(action.next, options);
|
|
21
|
+
}
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (action.type === 'execute') {
|
|
25
|
+
try {
|
|
26
|
+
console.log(chalk_1.default.cyan(`\nExecuting: ${action.command}\n`));
|
|
27
|
+
const { stdout, stderr } = await execAsync(action.command, {
|
|
28
|
+
shell: typeof process.env.SHELL === 'string' ? process.env.SHELL : undefined
|
|
29
|
+
});
|
|
30
|
+
if (stdout)
|
|
31
|
+
console.log(stdout);
|
|
32
|
+
if (stderr)
|
|
33
|
+
console.error(chalk_1.default.yellow(stderr));
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error(chalk_1.default.red(`Execution failed: ${error.message}`));
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function confirm(message) {
|
|
42
|
+
const rl = readline_1.default.createInterface({
|
|
43
|
+
input: process.stdin,
|
|
44
|
+
output: process.stdout,
|
|
45
|
+
});
|
|
46
|
+
return new Promise((resolve) => {
|
|
47
|
+
rl.question(chalk_1.default.cyan(`${message} (y/N): `), (answer) => {
|
|
48
|
+
rl.close();
|
|
49
|
+
resolve(answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/agent/actions.ts"],"names":[],"mappings":";;;;;AAQA,sCA8BC;AArCD,iDA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K,CAAC,eAAK,CAAC,GAAG,CAAC,qBAAqB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC/D,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;AACL,CAAC;AAED,KAAK,UAAU,OAAO,CAAC,OAAe;IAClC,MAAM,EAAE,GAAG,kBAAQ,CAAC,eAAe,CAAC;QAChC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;KACzB,CAAC,CAAC;IAEH,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,EAAE,CAAC,QAAQ,CAAC,eAAK,CAAC,IAAI,CAAC,GAAG,OAAO,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE;YACrD,EAAE,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,GAAG,IAAI,MAAM,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,CAAC;QAC5E,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildContext = buildContext;
|
|
4
|
+
exports.getAgentContextBuffer = getAgentContextBuffer;
|
|
5
|
+
const contextBuffer_1 = require("../commands/contextBuffer");
|
|
6
|
+
// Create a singleton instance for the agent
|
|
7
|
+
const globalContextBuffer = new contextBuffer_1.ContextBuffer();
|
|
8
|
+
function buildContext(input) {
|
|
9
|
+
const items = globalContextBuffer.export();
|
|
10
|
+
return {
|
|
11
|
+
files: items.map(item => ({
|
|
12
|
+
path: item.path,
|
|
13
|
+
content: item.content,
|
|
14
|
+
})),
|
|
15
|
+
gitDiff: undefined, // Will be enhanced later
|
|
16
|
+
history: [], // Will be populated from conversation history
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function getAgentContextBuffer() {
|
|
20
|
+
return globalContextBuffer;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/agent/context.ts"],"names":[],"mappings":";;AAMA,oCAWC;AAED,sDAEC;AApBD,6DAA0D;AAE1D,4CAA4C;AAC5C,MAAM,mBAAmB,GAAG,IAAI,6BAAa,EAAE,CAAC;AAEhD,SAAgB,YAAY,CAAC,KAAiB;IAC1C,MAAM,KAAK,GAAG,mBAAmB,CAAC,MAAM,EAAE,CAAC;IAE3C,OAAO;QACH,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACtB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;SACxB,CAAC,CAAC;QACH,OAAO,EAAE,SAAS,EAAE,yBAAyB;QAC7C,OAAO,EAAE,EAAE,EAAE,8CAA8C;KAC9D,CAAC;AACN,CAAC;AAED,SAAgB,qBAAqB;IACjC,OAAO,mBAAmB,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.AgentPipeline = void 0;
|
|
18
|
+
var AgentPipeline_1 = require("./AgentPipeline");
|
|
19
|
+
Object.defineProperty(exports, "AgentPipeline", { enumerable: true, get: function () { return AgentPipeline_1.AgentPipeline; } });
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,0CAAwB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inferIntent = inferIntent;
|
|
4
|
+
const capabilityInference_1 = require("../core/capabilityInference");
|
|
5
|
+
const capabilities_1 = require("../core/capabilities");
|
|
6
|
+
function inferIntent(input, mode) {
|
|
7
|
+
if (mode === 'chat') {
|
|
8
|
+
return {
|
|
9
|
+
type: 'chat',
|
|
10
|
+
capabilities: {
|
|
11
|
+
reasoning: true,
|
|
12
|
+
streaming: true,
|
|
13
|
+
longContext: true,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
// For command mode, use the existing capability inference
|
|
18
|
+
const capReq = (0, capabilityInference_1.inferCapabilityRequirement)(input.rawInput);
|
|
19
|
+
return {
|
|
20
|
+
type: 'shell',
|
|
21
|
+
capabilities: {
|
|
22
|
+
reasoning: capReq.required.includes(capabilities_1.AtomicCapability.REASONING),
|
|
23
|
+
code: capReq.required.includes(capabilities_1.AtomicCapability.CODE_GENERATION),
|
|
24
|
+
longContext: capReq.required.includes(capabilities_1.AtomicCapability.LONG_CONTEXT),
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=intent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent.js","sourceRoot":"","sources":["../../src/agent/intent.ts"],"names":[],"mappings":";;AAIA,kCA0BC;AA7BD,qEAAyE;AACzE,uDAAwD;AAExD,SAAgB,WAAW,CACvB,KAAiB,EACjB,IAAe;IAEf,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QAClB,OAAO;YACH,IAAI,EAAE,MAAM;YACZ,YAAY,EAAE;gBACV,SAAS,EAAE,IAAI;gBACf,SAAS,EAAE,IAAI;gBACf,WAAW,EAAE,IAAI;aACpB;SACJ,CAAC;IACN,CAAC;IAED,0DAA0D;IAC1D,MAAM,MAAM,GAAG,IAAA,gDAA0B,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAE1D,OAAO;QACH,IAAI,EAAE,OAAO;QACb,YAAY,EAAE;YACV,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,+BAAgB,CAAC,SAAS,CAAC;YAC/D,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,+BAAgB,CAAC,eAAe,CAAC;YAChE,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,+BAAgB,CAAC,YAAY,CAAC;SACvE;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interpretResultToPlan = interpretResultToPlan;
|
|
4
|
+
function interpretResultToPlan(result, intent, mode, alreadyStreamed = false) {
|
|
5
|
+
if (mode === 'chat') {
|
|
6
|
+
const tasks = alreadyStreamed ? [] : [{
|
|
7
|
+
id: 'chat-response',
|
|
8
|
+
description: '输出 AI 回答',
|
|
9
|
+
type: 'custom',
|
|
10
|
+
status: 'pending',
|
|
11
|
+
payload: { kind: 'print', text: result.rawText }
|
|
12
|
+
}];
|
|
13
|
+
return {
|
|
14
|
+
goal: '回答用户咨询',
|
|
15
|
+
tasks: tasks
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const aiPlan = result.parsed;
|
|
19
|
+
if (!aiPlan || (!aiPlan.command && !aiPlan.macro)) {
|
|
20
|
+
throw new Error('AI 未能生成有效的执行计划');
|
|
21
|
+
}
|
|
22
|
+
const command = aiPlan.command || aiPlan.macro; // 暂时简化处理
|
|
23
|
+
return {
|
|
24
|
+
goal: aiPlan.plan || '执行 Shell 命令',
|
|
25
|
+
tasks: [
|
|
26
|
+
{
|
|
27
|
+
id: 'exec-shell',
|
|
28
|
+
description: `执行命令: ${command}`,
|
|
29
|
+
type: 'shell',
|
|
30
|
+
status: 'pending',
|
|
31
|
+
payload: {
|
|
32
|
+
command: command,
|
|
33
|
+
risk: aiPlan.risk ?? 'medium'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=interpret.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interpret.js","sourceRoot":"","sources":["../../src/agent/interpret.ts"],"names":[],"mappings":";;AAGA,sDA2CC;AA3CD,SAAgB,qBAAqB,CACjC,MAAiB,EACjB,MAAmB,EACnB,IAAe,EACf,kBAA2B,KAAK;IAEhC,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QAClB,MAAM,KAAK,GAAG,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBAClC,EAAE,EAAE,eAAe;gBACnB,WAAW,EAAE,UAAU;gBACvB,IAAI,EAAE,QAAiB;gBACvB,MAAM,EAAE,SAAkB;gBAC1B,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE;aACnD,CAAC,CAAC;QAEH,OAAO;YACH,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,KAAK;SACf,CAAC;IACN,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS;IAEzD,OAAO;QACH,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,aAAa;QAClC,KAAK,EAAE;YACH;gBACI,EAAE,EAAE,YAAY;gBAChB,WAAW,EAAE,SAAS,OAAO,EAAE;gBAC/B,IAAI,EAAE,OAAO;gBACb,MAAM,EAAE,SAAS;gBACjB,OAAO,EAAE;oBACL,OAAO,EAAE,OAAO;oBAChB,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,QAAQ;iBAChC;aACJ;SACJ;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runLLM = runLLM;
|
|
7
|
+
const client_1 = require("../ai/client");
|
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
const validation_1 = require("../core/validation");
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const os_1 = __importDefault(require("os"));
|
|
13
|
+
const validation_2 = require("../core/validation");
|
|
14
|
+
const CONFIG_FILE = path_1.default.join(os_1.default.homedir(), '.yuangs.json');
|
|
15
|
+
function getUserConfig() {
|
|
16
|
+
if (fs_1.default.existsSync(CONFIG_FILE)) {
|
|
17
|
+
try {
|
|
18
|
+
const content = fs_1.default.readFileSync(CONFIG_FILE, 'utf8');
|
|
19
|
+
return JSON.parse(content);
|
|
20
|
+
}
|
|
21
|
+
catch (e) { }
|
|
22
|
+
}
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
async function runLLM({ prompt, model, stream, onChunk, }) {
|
|
26
|
+
const start = Date.now();
|
|
27
|
+
if (stream) {
|
|
28
|
+
let raw = '';
|
|
29
|
+
await (0, client_1.callAI_Stream)(prompt.messages, model, (chunk) => {
|
|
30
|
+
raw += chunk;
|
|
31
|
+
onChunk?.(chunk);
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
rawText: raw,
|
|
35
|
+
latencyMs: Date.now() - start,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// Non-streaming mode with optional schema
|
|
39
|
+
const config = getUserConfig();
|
|
40
|
+
const url = config.aiProxyUrl || validation_1.DEFAULT_AI_PROXY_URL;
|
|
41
|
+
const headers = {
|
|
42
|
+
'Content-Type': 'application/json',
|
|
43
|
+
'X-Client-ID': 'npm_yuangs',
|
|
44
|
+
'Origin': 'https://cli.want.biz',
|
|
45
|
+
'Referer': 'https://cli.want.biz/',
|
|
46
|
+
'account': config.accountType || validation_1.DEFAULT_ACCOUNT_TYPE,
|
|
47
|
+
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Mobile/15E148 Safari/604.1',
|
|
48
|
+
'Accept': 'application/json'
|
|
49
|
+
};
|
|
50
|
+
const data = {
|
|
51
|
+
model: model || config.defaultModel || validation_1.DEFAULT_MODEL,
|
|
52
|
+
messages: prompt.messages,
|
|
53
|
+
stream: false
|
|
54
|
+
};
|
|
55
|
+
try {
|
|
56
|
+
const response = await axios_1.default.post(url, data, { headers });
|
|
57
|
+
const rawText = response.data.choices[0]?.message?.content || '';
|
|
58
|
+
let parsed = undefined;
|
|
59
|
+
if (prompt.outputSchema) {
|
|
60
|
+
const parseResult = (0, validation_2.safeParseJSON)(rawText, prompt.outputSchema, {});
|
|
61
|
+
if (parseResult.success) {
|
|
62
|
+
parsed = parseResult.data;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
rawText,
|
|
67
|
+
parsed,
|
|
68
|
+
latencyMs: Date.now() - start,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
const errorMsg = error.response?.data?.error?.message || error.response?.data?.message || error.message || '未知错误';
|
|
73
|
+
throw new Error(`AI 请求失败: ${errorMsg}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=llm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm.js","sourceRoot":"","sources":["../../src/agent/llm.ts"],"names":[],"mappings":";;;;;AAqBA,wBAkEC;AAtFD,yCAA6C;AAC7C,kDAA0B;AAC1B,mDAAsH;AACtH,4CAAoB;AACpB,gDAAwB;AACxB,4CAAoB;AACpB,mDAAmD;AAEnD,MAAM,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,cAAc,CAAC,CAAC;AAE5D,SAAS,aAAa;IAClB,IAAI,YAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAC7B,IAAI,CAAC;YACD,MAAM,OAAO,GAAG,YAAE,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;YACrD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC;AAEM,KAAK,UAAU,MAAM,CAAC,EACzB,MAAM,EACN,KAAK,EACL,MAAM,EACN,OAAO,GAMV;IACG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I,MAAM,CAAC,YAAY,EAAE,CAAC;YACtB,MAAM,WAAW,GAAG,IAAA,0BAAa,EAAC,OAAO,EAAE,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;YACpE,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;gBACtB,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC;YAC9B,CAAC;QACL,CAAC;QAED,OAAO;YACH,OAAO;YACP,MAAM;YACN,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;SAChC,CAAC;IACN,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,IAAI,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,IAAI,KAAK,CAAC,OAAO,IAAI,MAAM,CAAC;QAClH,MAAM,IAAI,KAAK,CAAC,YAAY,QAAQ,EAAE,CAAC,CAAC;IAC5C,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface AgentPlan {
|
|
2
|
+
goal: string;
|
|
3
|
+
tasks: AgentTask[];
|
|
4
|
+
}
|
|
5
|
+
export interface AgentTask {
|
|
6
|
+
id: string;
|
|
7
|
+
description: string;
|
|
8
|
+
type: 'llm' | 'shell' | 'custom';
|
|
9
|
+
dependsOn?: string[];
|
|
10
|
+
payload?: any;
|
|
11
|
+
status: 'pending' | 'running' | 'success' | 'failed';
|
|
12
|
+
result?: any;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.js","sourceRoot":"","sources":["../../src/agent/plan.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AgentPlan } from './plan';
|
|
2
|
+
export interface PlanExecutionSummary {
|
|
3
|
+
success: boolean;
|
|
4
|
+
completedCount: number;
|
|
5
|
+
totalCount: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function executePlan(plan: AgentPlan, options?: {
|
|
8
|
+
autoYes?: boolean;
|
|
9
|
+
verbose?: boolean;
|
|
10
|
+
}): Promise<PlanExecutionSummary>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.executePlan = executePlan;
|
|
7
|
+
const actions_1 = require("./actions");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
async function executePlan(plan, options) {
|
|
10
|
+
const completed = new Set();
|
|
11
|
+
const failed = new Set();
|
|
12
|
+
if (options?.verbose) {
|
|
13
|
+
console.log(chalk_1.default.bold.cyan(`\n🚀 开始执行计划: ${plan.goal}`));
|
|
14
|
+
console.log(chalk_1.default.gray(`共 ${plan.tasks.length} 个任务\n`));
|
|
15
|
+
}
|
|
16
|
+
for (const task of plan.tasks) {
|
|
17
|
+
// 检查依赖
|
|
18
|
+
if (task.dependsOn?.some(depId => !completed.has(depId))) {
|
|
19
|
+
if (options?.verbose) {
|
|
20
|
+
console.log(chalk_1.default.yellow(`⏭️ 跳过任务 ${task.id}: 依赖未完成`));
|
|
21
|
+
}
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (failed.has(task.id))
|
|
25
|
+
continue;
|
|
26
|
+
try {
|
|
27
|
+
task.status = 'running';
|
|
28
|
+
if (options?.verbose) {
|
|
29
|
+
console.log(chalk_1.default.cyan(`⚙️ 执行任务 ${task.id}: ${task.description}`));
|
|
30
|
+
}
|
|
31
|
+
await executeTask(task, options);
|
|
32
|
+
task.status = 'success';
|
|
33
|
+
completed.add(task.id);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
task.status = 'failed';
|
|
37
|
+
failed.add(task.id);
|
|
38
|
+
console.error(chalk_1.default.red(`❌ 任务 ${task.id} 失败: ${error.message}`));
|
|
39
|
+
// 如果一个任务失败,后续依赖它的任务都会被跳过
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (options?.verbose) {
|
|
43
|
+
console.log(chalk_1.default.bold.green(`\n✅ 计划执行完成 (${completed.size}/${plan.tasks.length} 成功)\n`));
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
success: failed.size === 0 && completed.size > 0,
|
|
47
|
+
completedCount: completed.size,
|
|
48
|
+
totalCount: plan.tasks.length
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async function executeTask(task, options) {
|
|
52
|
+
switch (task.type) {
|
|
53
|
+
case 'shell':
|
|
54
|
+
await (0, actions_1.executeAction)({
|
|
55
|
+
type: 'confirm',
|
|
56
|
+
next: {
|
|
57
|
+
type: 'execute',
|
|
58
|
+
command: task.payload.command,
|
|
59
|
+
risk: task.payload.risk || 'medium'
|
|
60
|
+
}
|
|
61
|
+
}, options);
|
|
62
|
+
break;
|
|
63
|
+
case 'custom':
|
|
64
|
+
if (task.payload?.kind === 'print' && task.payload?.text) {
|
|
65
|
+
console.log(task.payload.text);
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
case 'llm':
|
|
69
|
+
// 未来可以支持任务中再次调用 LLM (Recursive Agent)
|
|
70
|
+
console.log(chalk_1.default.gray(`[LLM Task] ${task.description} (Not implemented in MVP)`));
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=planExecutor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planExecutor.js","sourceRoot":"","sources":["../../src/agent/planExecutor.ts"],"names":[],"mappings":";;;;;AAUA,kCAkDC;AA3DD,uCAA0C;AAC1C,kDAA0B;AAQnB,KAAK,UAAU,WAAW,CAC7B,IAAe,EACf,OAAkD;IAElD,MAAM,SAAS,GAAG,IAAI,GAAG,EAA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IAAI,CAAC,CAAC;YACnC,CAAC;YACD,MAAM;QAEV,KAAK,KAAK;YACN,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,cAAc,IAAI,CAAC,WAAW,2BAA2B,CAAC,CAAC,CAAC;YACnF,MAAM;IACd,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildPrompt = buildPrompt;
|
|
4
|
+
const prompt_1 = require("../ai/prompt");
|
|
5
|
+
const os_1 = require("../core/os");
|
|
6
|
+
const macros_1 = require("../core/macros");
|
|
7
|
+
const validation_1 = require("../core/validation");
|
|
8
|
+
const skills_1 = require("./skills");
|
|
9
|
+
function buildPrompt(intent, context, mode, input) {
|
|
10
|
+
if (mode === 'chat') {
|
|
11
|
+
return buildChatPrompt(context, input);
|
|
12
|
+
}
|
|
13
|
+
return buildCommandPromptObject(input, context);
|
|
14
|
+
}
|
|
15
|
+
function buildChatPrompt(context, input) {
|
|
16
|
+
const messages = [
|
|
17
|
+
...(context.history ?? []),
|
|
18
|
+
];
|
|
19
|
+
// Add context files if available
|
|
20
|
+
if (context.files && context.files.length > 0) {
|
|
21
|
+
const contextDesc = context.files.map(f => `File: ${f.path}\n\`\`\`\n${f.content}\n\`\`\``).join('\n\n');
|
|
22
|
+
messages.push({
|
|
23
|
+
role: 'system',
|
|
24
|
+
content: `Context:\n${contextDesc}`,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
messages.push({
|
|
28
|
+
role: 'user',
|
|
29
|
+
content: input,
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
system: 'You are a helpful AI assistant with expertise in software development, system administration, and problem-solving.',
|
|
33
|
+
messages,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function buildCommandPromptObject(input, context) {
|
|
37
|
+
const os = (0, os_1.getOSProfile)();
|
|
38
|
+
const macros = (0, macros_1.getMacros)();
|
|
39
|
+
const skills = (0, skills_1.getRelevantSkills)(input);
|
|
40
|
+
let promptText = (0, prompt_1.buildCommandPrompt)(input, os, macros);
|
|
41
|
+
if (skills.length > 0) {
|
|
42
|
+
const skillList = skills.map(s => `- ${s.name}: 当遇到 "${s.whenToUse}" 时,你可以参考计划: ${s.planTemplate.goal}`).join('\n');
|
|
43
|
+
promptText = `【参考技能库】\n${skillList}\n\n${promptText}`;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
messages: [
|
|
47
|
+
{
|
|
48
|
+
role: 'user',
|
|
49
|
+
content: promptText,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
outputSchema: validation_1.aiCommandPlanSchema,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/agent/prompt.ts"],"names":[],"mappings":";;AAYA,kCAWC;AAjBD,yCAA8E;AAC9E,mCAA0C;AAC1C,2CAA2C;AAC3C,mDAAyD;AACzD,qCAA6C;AAE7C,SAAgB,WAAW,CACvB,MAAmB,EACnB,OAAqB,EACrB,IAAe,EACf,KAAa;IAEb,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QAClB,OAAO,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,wBAAwB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,eAAe,CACpB,OAAqB,EACrB,KAAa;IAEb,MAAM,QAAQ,GAAU;QACpB,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;KAC7B,CAAC;IAEF,iCAAiC;IACjC,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5C,MAAM,WAAW,G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 +1,14 @@
|
|
|
1
|
+
import { AgentInput, AgentMode, AgentPrompt, LLMResult, AgentAction } from './types';
|
|
2
|
+
export interface ExecutionRecord {
|
|
3
|
+
id: string;
|
|
4
|
+
timestamp: number;
|
|
5
|
+
mode: AgentMode;
|
|
6
|
+
input: AgentInput;
|
|
7
|
+
prompt: AgentPrompt;
|
|
8
|
+
model: string;
|
|
9
|
+
llmResult: LLMResult;
|
|
10
|
+
action: AgentAction;
|
|
11
|
+
}
|
|
12
|
+
export declare function saveRecord(record: ExecutionRecord): void;
|
|
13
|
+
export declare function getRecords(): ExecutionRecord[];
|
|
14
|
+
export declare function getRecordById(id: string): ExecutionRecord | undefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.saveRecord = saveRecord;
|
|
4
|
+
exports.getRecords = getRecords;
|
|
5
|
+
exports.getRecordById = getRecordById;
|
|
6
|
+
const records = [];
|
|
7
|
+
function saveRecord(record) {
|
|
8
|
+
records.push(record);
|
|
9
|
+
// Keep only last 100 records in memory
|
|
10
|
+
if (records.length > 100) {
|
|
11
|
+
records.shift();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function getRecords() {
|
|
15
|
+
return [...records];
|
|
16
|
+
}
|
|
17
|
+
function getRecordById(id) {
|
|
18
|
+
return records.find(r => r.id === id);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["../../src/agent/record.ts"],"names":[],"mappings":";;AAqBA,gCAMC;AAED,gCAEC;AAED,sCAEC;AAhBD,MAAM,OAAO,GAAsB,EAAE,CAAC;AAEtC,SAAgB,UAAU,CAAC,MAAuB;IAC9C,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrB,uCAAuC;IACvC,IAAI,OAAO,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QACvB,OAAO,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;AACL,CAAC;AAED,SAAgB,UAAU;IACtB,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC;AACxB,CAAC;AAED,SAAgB,aAAa,CAAC,EAAU;IACpC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1C,CAAC"}
|