knight-agent 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Host.d.ts +3 -11
- package/Host.d.ts.map +1 -1
- package/Host.js +4 -5
- package/Host.js.map +1 -1
- package/base/AbstractAgent.d.ts +1 -99
- package/base/AbstractAgent.d.ts.map +1 -1
- package/base/AbstractAgent.js +94 -20
- package/base/AbstractAgent.js.map +1 -1
- package/base/AbstractLLM.d.ts +43 -0
- package/base/AbstractLLM.d.ts.map +1 -0
- package/base/AbstractLLM.js +121 -0
- package/base/AbstractLLM.js.map +1 -0
- package/base/AbstractModule.d.ts +1 -0
- package/base/AbstractModule.d.ts.map +1 -1
- package/base/AbstractModule.js +3 -0
- package/base/AbstractModule.js.map +1 -1
- package/base/AbstractObject.d.ts +6 -4
- package/base/AbstractObject.d.ts.map +1 -1
- package/base/AbstractObject.js +6 -2
- package/base/AbstractObject.js.map +1 -1
- package/base/index.d.ts +1 -4
- package/base/index.d.ts.map +1 -1
- package/base/index.js +1 -4
- package/base/index.js.map +1 -1
- package/index.d.ts +2 -1
- package/index.d.ts.map +1 -1
- package/index.js +2 -6
- package/index.js.map +1 -1
- package/module/AgentModule/Agent.d.ts +1 -54
- package/module/AgentModule/Agent.d.ts.map +1 -1
- package/module/AgentModule/Agent.js +22 -207
- package/module/AgentModule/Agent.js.map +1 -1
- package/module/AgentModule/AgentModule.d.ts +1 -25
- package/module/AgentModule/AgentModule.d.ts.map +1 -1
- package/module/AgentModule/AgentModule.js +78 -63
- package/module/AgentModule/AgentModule.js.map +1 -1
- package/module/AgentModule/index.d.ts +1 -1
- package/module/AgentModule/index.d.ts.map +1 -1
- package/module/AgentModule/index.js +2 -15
- package/module/AgentModule/index.js.map +1 -1
- package/module/LLMModule/ClaudeLLM.d.ts +23 -0
- package/module/LLMModule/ClaudeLLM.d.ts.map +1 -0
- package/module/LLMModule/ClaudeLLM.js +138 -0
- package/module/LLMModule/ClaudeLLM.js.map +1 -0
- package/module/LLMModule/DeepSeekLLM.d.ts +24 -0
- package/module/LLMModule/DeepSeekLLM.d.ts.map +1 -0
- package/module/LLMModule/DeepSeekLLM.js +136 -0
- package/module/LLMModule/DeepSeekLLM.js.map +1 -0
- package/module/LLMModule/GeminiLLM.d.ts +23 -0
- package/module/LLMModule/GeminiLLM.d.ts.map +1 -0
- package/module/LLMModule/GeminiLLM.js +168 -0
- package/module/LLMModule/GeminiLLM.js.map +1 -0
- package/module/LLMModule/LLMModule.d.ts +33 -0
- package/module/LLMModule/LLMModule.d.ts.map +1 -0
- package/module/LLMModule/LLMModule.js +92 -0
- package/module/LLMModule/LLMModule.js.map +1 -0
- package/module/LLMModule/OpenAILLM.d.ts +23 -0
- package/module/LLMModule/OpenAILLM.d.ts.map +1 -0
- package/module/LLMModule/OpenAILLM.js +145 -0
- package/module/LLMModule/OpenAILLM.js.map +1 -0
- package/module/LLMModule/QWenLLM.d.ts +23 -0
- package/module/LLMModule/QWenLLM.d.ts.map +1 -0
- package/module/LLMModule/QWenLLM.js +137 -0
- package/module/LLMModule/QWenLLM.js.map +1 -0
- package/module/LLMModule/index.d.ts +7 -0
- package/module/LLMModule/index.d.ts.map +1 -0
- package/module/{SkillModule → LLMModule}/index.js +6 -1
- package/module/LLMModule/index.js.map +1 -0
- package/module/index.d.ts +1 -4
- package/module/index.d.ts.map +1 -1
- package/module/index.js +1 -4
- package/module/index.js.map +1 -1
- package/package.json +1 -1
- package/utility/AgentUtility.d.ts +38 -0
- package/utility/AgentUtility.d.ts.map +1 -0
- package/{base/AbstractTool.js → utility/AgentUtility.js} +1 -1
- package/utility/AgentUtility.js.map +1 -0
- package/utility/LLMUtility.d.ts +1328 -0
- package/utility/LLMUtility.d.ts.map +1 -0
- package/utility/LLMUtility.js +114 -0
- package/utility/LLMUtility.js.map +1 -0
- package/utility/index.d.ts +2 -1
- package/utility/index.d.ts.map +1 -1
- package/utility/index.js +2 -1
- package/utility/index.js.map +1 -1
- package/base/AbstractDialog.d.ts +0 -54
- package/base/AbstractDialog.d.ts.map +0 -1
- package/base/AbstractDialog.js +0 -86
- package/base/AbstractDialog.js.map +0 -1
- package/base/AbstractReason.d.ts +0 -44
- package/base/AbstractReason.d.ts.map +0 -1
- package/base/AbstractReason.js +0 -23
- package/base/AbstractReason.js.map +0 -1
- package/base/AbstractSkill.d.ts +0 -25
- package/base/AbstractSkill.d.ts.map +0 -1
- package/base/AbstractSkill.js +0 -3
- package/base/AbstractSkill.js.map +0 -1
- package/base/AbstractTool.d.ts +0 -34
- package/base/AbstractTool.d.ts.map +0 -1
- package/base/AbstractTool.js.map +0 -1
- package/docs/ARCHITECTURE.md +0 -601
- package/docs/README.md +0 -562
- package/module/AgentModule/Memory.d.ts +0 -55
- package/module/AgentModule/Memory.d.ts.map +0 -1
- package/module/AgentModule/Memory.js +0 -288
- package/module/AgentModule/Memory.js.map +0 -1
- package/module/DialogModule/Dialog.d.ts +0 -14
- package/module/DialogModule/Dialog.d.ts.map +0 -1
- package/module/DialogModule/Dialog.js +0 -27
- package/module/DialogModule/Dialog.js.map +0 -1
- package/module/DialogModule/DialogModule.d.ts +0 -39
- package/module/DialogModule/DialogModule.d.ts.map +0 -1
- package/module/DialogModule/DialogModule.js +0 -118
- package/module/DialogModule/DialogModule.js.map +0 -1
- package/module/DialogModule/index.d.ts +0 -3
- package/module/DialogModule/index.d.ts.map +0 -1
- package/module/DialogModule/index.js +0 -19
- package/module/DialogModule/index.js.map +0 -1
- package/module/ReasonModule/ChainReason.d.ts +0 -11
- package/module/ReasonModule/ChainReason.d.ts.map +0 -1
- package/module/ReasonModule/ChainReason.js +0 -34
- package/module/ReasonModule/ChainReason.js.map +0 -1
- package/module/ReasonModule/CommanderReason.d.ts +0 -15
- package/module/ReasonModule/CommanderReason.d.ts.map +0 -1
- package/module/ReasonModule/CommanderReason.js +0 -151
- package/module/ReasonModule/CommanderReason.js.map +0 -1
- package/module/ReasonModule/CompetitiveReason.d.ts +0 -13
- package/module/ReasonModule/CompetitiveReason.d.ts.map +0 -1
- package/module/ReasonModule/CompetitiveReason.js +0 -133
- package/module/ReasonModule/CompetitiveReason.js.map +0 -1
- package/module/ReasonModule/PlanReason.d.ts +0 -25
- package/module/ReasonModule/PlanReason.d.ts.map +0 -1
- package/module/ReasonModule/PlanReason.js +0 -133
- package/module/ReasonModule/PlanReason.js.map +0 -1
- package/module/ReasonModule/ReasonModule.d.ts +0 -41
- package/module/ReasonModule/ReasonModule.d.ts.map +0 -1
- package/module/ReasonModule/ReasonModule.js +0 -83
- package/module/ReasonModule/ReasonModule.js.map +0 -1
- package/module/ReasonModule/ReflectReason.d.ts +0 -15
- package/module/ReasonModule/ReflectReason.d.ts.map +0 -1
- package/module/ReasonModule/ReflectReason.js +0 -86
- package/module/ReasonModule/ReflectReason.js.map +0 -1
- package/module/ReasonModule/TreeReason.d.ts +0 -16
- package/module/ReasonModule/TreeReason.d.ts.map +0 -1
- package/module/ReasonModule/TreeReason.js +0 -139
- package/module/ReasonModule/TreeReason.js.map +0 -1
- package/module/ReasonModule/index.d.ts +0 -8
- package/module/ReasonModule/index.d.ts.map +0 -1
- package/module/ReasonModule/index.js +0 -24
- package/module/ReasonModule/index.js.map +0 -1
- package/module/SkillModule/SkillModule.d.ts +0 -42
- package/module/SkillModule/SkillModule.d.ts.map +0 -1
- package/module/SkillModule/SkillModule.js +0 -134
- package/module/SkillModule/SkillModule.js.map +0 -1
- package/module/SkillModule/index.d.ts +0 -2
- package/module/SkillModule/index.d.ts.map +0 -1
- package/module/SkillModule/index.js.map +0 -1
- package/module/ToolModule/ToolModule.d.ts +0 -57
- package/module/ToolModule/ToolModule.d.ts.map +0 -1
- package/module/ToolModule/ToolModule.js +0 -220
- package/module/ToolModule/ToolModule.js.map +0 -1
- package/module/ToolModule/ToolRAG.d.ts +0 -38
- package/module/ToolModule/ToolRAG.d.ts.map +0 -1
- package/module/ToolModule/ToolRAG.js +0 -124
- package/module/ToolModule/ToolRAG.js.map +0 -1
- package/module/ToolModule/index.d.ts +0 -3
- package/module/ToolModule/index.d.ts.map +0 -1
- package/module/ToolModule/index.js +0 -19
- package/module/ToolModule/index.js.map +0 -1
- package/utility/OpenAIUtility.d.ts +0 -333
- package/utility/OpenAIUtility.d.ts.map +0 -1
- package/utility/OpenAIUtility.js +0 -95
- package/utility/OpenAIUtility.js.map +0 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LLMModule = void 0;
|
|
4
|
+
const base_1 = require("../../base");
|
|
5
|
+
const utility_1 = require("../../utility");
|
|
6
|
+
const ClaudeLLM_1 = require("./ClaudeLLM");
|
|
7
|
+
const DeepSeekLLM_1 = require("./DeepSeekLLM");
|
|
8
|
+
const GeminiLLM_1 = require("./GeminiLLM");
|
|
9
|
+
const OpenAILLM_1 = require("./OpenAILLM");
|
|
10
|
+
const QWenLLM_1 = require("./QWenLLM");
|
|
11
|
+
/** 大模型管理模块 */
|
|
12
|
+
class LLMModule extends base_1.AbstractModule {
|
|
13
|
+
/** 构造函数 */
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this.llms = new utility_1.ObjectUtility.MapPool();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 从快照恢复大模型实例
|
|
20
|
+
* @param data 大模型快照
|
|
21
|
+
* @returns 恢复后的大模型实例
|
|
22
|
+
*/
|
|
23
|
+
restore(data) {
|
|
24
|
+
const llm = this.add(data.config);
|
|
25
|
+
llm.setId(data.id);
|
|
26
|
+
if (data.messages.length > 0) {
|
|
27
|
+
llm.messages.Import(data.messages);
|
|
28
|
+
}
|
|
29
|
+
return llm;
|
|
30
|
+
}
|
|
31
|
+
/** 获取大模型实例 */
|
|
32
|
+
get(id) {
|
|
33
|
+
return this.llms.Get(id);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 添加大模型实例
|
|
37
|
+
* @param config 大模型配置
|
|
38
|
+
* @return 大模型实例
|
|
39
|
+
*/
|
|
40
|
+
add(config) {
|
|
41
|
+
let llm;
|
|
42
|
+
const type = config.type;
|
|
43
|
+
switch (type) {
|
|
44
|
+
case "Claude":
|
|
45
|
+
llm = new ClaudeLLM_1.ClaudeLLM(config);
|
|
46
|
+
break;
|
|
47
|
+
case "DeepSeek":
|
|
48
|
+
llm = new DeepSeekLLM_1.DeepSeekLLM(config);
|
|
49
|
+
break;
|
|
50
|
+
case "Gemini":
|
|
51
|
+
llm = new GeminiLLM_1.GeminiLLM(config);
|
|
52
|
+
break;
|
|
53
|
+
case "OpenAI":
|
|
54
|
+
llm = new OpenAILLM_1.OpenAILLM(config);
|
|
55
|
+
break;
|
|
56
|
+
case "QWen":
|
|
57
|
+
llm = new QWenLLM_1.QWenLLM(config);
|
|
58
|
+
break;
|
|
59
|
+
default: throw new Error(`Unsupported LLM type: ${type}`);
|
|
60
|
+
}
|
|
61
|
+
this.llms.Set(llm.id, llm);
|
|
62
|
+
return llm;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 移除大模型实例
|
|
66
|
+
* @param id 大模型ID
|
|
67
|
+
* @returns 移除结果
|
|
68
|
+
*/
|
|
69
|
+
remove(id) {
|
|
70
|
+
const llm = this.llms.Get(id);
|
|
71
|
+
if (!llm) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
llm.OnDestroy();
|
|
75
|
+
this.llms.Remove(id);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
/** 移除全部大模型实例 */
|
|
79
|
+
removeAll() {
|
|
80
|
+
const llms = this.llms.ValuesToArray();
|
|
81
|
+
for (const llm of llms) {
|
|
82
|
+
llm.OnDestroy();
|
|
83
|
+
}
|
|
84
|
+
this.llms.RemoveAll();
|
|
85
|
+
}
|
|
86
|
+
OnDestroy() {
|
|
87
|
+
this.removeAll();
|
|
88
|
+
return super.OnDestroy();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.LLMModule = LLMModule;
|
|
92
|
+
//# sourceMappingURL=LLMModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LLMModule.js","sourceRoot":"","sources":["../../../src/module/LLMModule/LLMModule.ts"],"names":[],"mappings":";;;AAAA,qCAAyD;AACzD,2CAA0D;AAC1D,2CAAwC;AACxC,+CAA4C;AAC5C,2CAAwC;AACxC,2CAAwC;AACxC,uCAAoC;AAEpC,cAAc;AACd,MAAa,SAAU,SAAQ,qBAAc;IAKzC,WAAW;IACX;QAEI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,uBAAa,CAAC,OAAO,EAAe,CAAC;IACzD,CAAC;IACD;;;;OAIG;IACI,OAAO,CAAC,IAAyB;QAEpC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAAC,CAAC;QACrE,OAAO,GAAG,CAAC;IACf,CAAC;IACD,cAAc;IACP,GAAG,CAAsC,EAAU;QAEtD,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAI,EAAE,CAAC,CAAC;IAChC,CAAC;IACD;;;;OAIG;IACI,GAAG,CAAC,MAAyB;QAEhC,IAAI,GAAgB,CAAC;QACrB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACzB,QAAQ,IAAI,EACZ,CAAC;YACG,KAAK,QAAQ;gBAAE,GAAG,GAAG,IAAI,qBAAS,CAAC,MAAM,CAAC,CAAC;gBAAC,MAAM;YAClD,KAAK,UAAU;gBAAE,GAAG,GAAG,IAAI,yBAAW,CAAC,MAAM,CAAC,CAAC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
+
import { AbstractLLM } from "../../base";
|
|
2
|
+
import { LLMUtility } from "../../utility";
|
|
3
|
+
/** OpenAI大模型 */
|
|
4
|
+
export declare class OpenAILLM extends AbstractLLM<LLMUtility.OpenAI.Config, LLMUtility.OpenAI.MessageData> {
|
|
5
|
+
/** 构造函数 */
|
|
6
|
+
constructor(config?: LLMUtility.OpenAI.Config);
|
|
7
|
+
/** @override */
|
|
8
|
+
protected addSystemMessage(text: string): void;
|
|
9
|
+
/** @override */
|
|
10
|
+
protected addUserMessage(text: string): void;
|
|
11
|
+
/** @override */
|
|
12
|
+
protected addAssistantMessage(content: string, toolCalls?: Array<LLMUtility.ToolCall>): void;
|
|
13
|
+
/** @override */
|
|
14
|
+
protected addToolMessage(result: LLMUtility.ToolResult): void;
|
|
15
|
+
/** @override — 截断过长工具输出 */
|
|
16
|
+
protected compactMessages(): void;
|
|
17
|
+
/** @override — 停止原因 */
|
|
18
|
+
protected stopReason(reason: string): LLMUtility.FinishReason;
|
|
19
|
+
/** @override */
|
|
20
|
+
protected request(tools: LLMUtility.ToolDefinition[]): Promise<LLMUtility.Response>;
|
|
21
|
+
OnDestroy(): boolean;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=OpenAILLM.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenAILLM.d.ts","sourceRoot":"","sources":["../../../src/module/LLMModule/OpenAILLM.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAkB,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3D,gBAAgB;AAChB,qBAAa,SAAU,SAAQ,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,WAAW,CAAC;IAG/F,WAAW;gBACQ,MAAM,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,MAAM;IAgCpD,gBAAgB;IAChB,SAAS,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAM9C,gBAAgB;IAChB,SAAS,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAM5C,gBAAgB;IAChB,SAAS,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,IAAI;IAkB5F,gBAAgB;IAChB,SAAS,CAAC,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,GAAG,IAAI;IAM7D,2BAA2B;IAC3B,SAAS,CAAC,eAAe,IAAI,IAAI;IAYjC,uBAAuB;IACvB,SAAS,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,YAAY;IAW7D,gBAAgB;cACA,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,cAAc,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC;IAsDlF,SAAS,IAAI,OAAO;CAI9B"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpenAILLM = void 0;
|
|
4
|
+
const base_1 = require("../../base");
|
|
5
|
+
const utility_1 = require("../../utility");
|
|
6
|
+
/** OpenAI大模型 */
|
|
7
|
+
class OpenAILLM extends base_1.AbstractLLM {
|
|
8
|
+
/** 构造函数 */
|
|
9
|
+
constructor(config) {
|
|
10
|
+
super({
|
|
11
|
+
type: "OpenAI",
|
|
12
|
+
url: "https://api.openai.com/v1/chat/completions",
|
|
13
|
+
apiKey: "",
|
|
14
|
+
model: "gpt-4o",
|
|
15
|
+
timeout: 60000,
|
|
16
|
+
temperature: 1,
|
|
17
|
+
topP: 1,
|
|
18
|
+
maxTokens: 4096,
|
|
19
|
+
stop: undefined,
|
|
20
|
+
stream: false,
|
|
21
|
+
seed: undefined,
|
|
22
|
+
maxMessageCache: 10,
|
|
23
|
+
maxToolOutput: 800,
|
|
24
|
+
reasoningEffort: "medium",
|
|
25
|
+
responseFormat: "text",
|
|
26
|
+
jsonSchema: undefined,
|
|
27
|
+
streamOptions: undefined,
|
|
28
|
+
modalities: undefined,
|
|
29
|
+
store: undefined,
|
|
30
|
+
serviceTier: "auto",
|
|
31
|
+
safetyIdentifier: undefined,
|
|
32
|
+
webSearchOptions: undefined,
|
|
33
|
+
parallelToolCalls: undefined,
|
|
34
|
+
...config
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
// ======================== 受保护实现 ========================
|
|
38
|
+
/** @override */
|
|
39
|
+
addSystemMessage(text) {
|
|
40
|
+
const message = { role: "system", content: text, preserve: true };
|
|
41
|
+
this.messages.Add(message);
|
|
42
|
+
}
|
|
43
|
+
/** @override */
|
|
44
|
+
addUserMessage(text) {
|
|
45
|
+
const message = { role: "user", content: text };
|
|
46
|
+
this.messages.Add(message);
|
|
47
|
+
}
|
|
48
|
+
/** @override */
|
|
49
|
+
addAssistantMessage(content, toolCalls) {
|
|
50
|
+
const message = {
|
|
51
|
+
role: "assistant",
|
|
52
|
+
content: content || null,
|
|
53
|
+
tool_calls: toolCalls?.map((tc, i) => ({
|
|
54
|
+
index: i,
|
|
55
|
+
id: tc.id,
|
|
56
|
+
type: "function",
|
|
57
|
+
function: {
|
|
58
|
+
name: tc.name,
|
|
59
|
+
arguments: JSON.stringify(tc.arguments),
|
|
60
|
+
},
|
|
61
|
+
})),
|
|
62
|
+
};
|
|
63
|
+
this.messages.Add(message);
|
|
64
|
+
}
|
|
65
|
+
/** @override */
|
|
66
|
+
addToolMessage(result) {
|
|
67
|
+
const message = { role: "tool", tool_call_id: result.id, content: result.data };
|
|
68
|
+
this.messages.Add(message);
|
|
69
|
+
}
|
|
70
|
+
/** @override — 截断过长工具输出 */
|
|
71
|
+
compactMessages() {
|
|
72
|
+
const maxLen = this.config.maxToolOutput ?? 800;
|
|
73
|
+
this.messages.Compact((message) => {
|
|
74
|
+
if (message.role === "tool" && message.content && message.content.length > maxLen) {
|
|
75
|
+
return { ...message, content: message.content.slice(0, maxLen) + `\n[truncated: ${message.content.length - maxLen} chars omitted]` };
|
|
76
|
+
}
|
|
77
|
+
return message;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/** @override — 停止原因 */
|
|
81
|
+
stopReason(reason) {
|
|
82
|
+
switch (reason) {
|
|
83
|
+
case "stop": return "stop";
|
|
84
|
+
case "length": return "length";
|
|
85
|
+
case "tool_calls": return "tool_calls";
|
|
86
|
+
case "content_filter": return "content_filter";
|
|
87
|
+
default: return "unknown";
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** @override */
|
|
91
|
+
async request(tools) {
|
|
92
|
+
const messages = this.messages.All();
|
|
93
|
+
const body = {
|
|
94
|
+
model: this.config.model,
|
|
95
|
+
messages,
|
|
96
|
+
thinking: { type: "disabled" },
|
|
97
|
+
reasoning_effort: this.config.reasoningEffort,
|
|
98
|
+
frequency_penalty: undefined,
|
|
99
|
+
max_tokens: this.config.maxTokens,
|
|
100
|
+
presence_penalty: undefined,
|
|
101
|
+
response_format: this.config.responseFormat && this.config.responseFormat !== "text" ? { type: this.config.responseFormat === "json_schema" ? "json_object" : this.config.responseFormat } : undefined,
|
|
102
|
+
stop: this.config.stop,
|
|
103
|
+
stream: this.config.stream,
|
|
104
|
+
stream_options: undefined,
|
|
105
|
+
temperature: this.config.temperature,
|
|
106
|
+
top_p: this.config.topP,
|
|
107
|
+
tools: tools.length > 0 ? tools.map(t => ({ type: "function", function: { name: t.name, description: t.description, parameters: t.inputSchema } })) : undefined,
|
|
108
|
+
tool_choice: undefined,
|
|
109
|
+
logprobs: undefined,
|
|
110
|
+
top_logprobs: undefined,
|
|
111
|
+
seed: this.config.seed,
|
|
112
|
+
};
|
|
113
|
+
const response = await utility_1.NetworkUtility.HTTP.OnRequest(this.config.url, {
|
|
114
|
+
method: "post",
|
|
115
|
+
data: body,
|
|
116
|
+
headers: { "Authorization": `Bearer ${this.config.apiKey}`, "Content-Type": "application/json" },
|
|
117
|
+
timeout: this.config.timeout,
|
|
118
|
+
});
|
|
119
|
+
const data = response.data;
|
|
120
|
+
const choice = data.choices?.[0];
|
|
121
|
+
const message = choice?.message;
|
|
122
|
+
return {
|
|
123
|
+
id: data.id ?? "",
|
|
124
|
+
model: data.model ?? "",
|
|
125
|
+
content: message?.content ?? "",
|
|
126
|
+
toolCalls: message?.tool_calls?.map(tc => ({
|
|
127
|
+
id: tc.id,
|
|
128
|
+
name: tc.function.name,
|
|
129
|
+
arguments: typeof tc.function.arguments === "string" ? JSON.parse(tc.function.arguments) : tc.function.arguments,
|
|
130
|
+
})),
|
|
131
|
+
finishReason: this.stopReason(choice?.finish_reason),
|
|
132
|
+
usage: {
|
|
133
|
+
input: data.usage?.prompt_tokens ?? 0,
|
|
134
|
+
output: data.usage?.completion_tokens ?? 0,
|
|
135
|
+
total: data.usage?.total_tokens ?? 0,
|
|
136
|
+
},
|
|
137
|
+
raw: data,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
OnDestroy() {
|
|
141
|
+
return super.OnDestroy();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.OpenAILLM = OpenAILLM;
|
|
145
|
+
//# sourceMappingURL=OpenAILLM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenAILLM.js","sourceRoot":"","sources":["../../../src/module/LLMModule/OpenAILLM.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AACzC,2CAA2D;AAE3D,gBAAgB;AAChB,MAAa,SAAU,SAAQ,kBAAoE;IAG/F,WAAW;IACX,YAAmB,MAAiC;QAEhD,KAAK,CAAC;YACF,IAAI,EAAE,QAAQ;YACd,GAAG,EAAE,4CAA4C;YACjD,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,QAAQ;YACf,OAAO,EAAE,KAAK;YACd,WAAW,EAAE,CAAC;YACd,IAAI,EAAE,CAAC;YACP,SAAS,EAAE,IA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nH,CAAC,CAAC;YACH,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC;YACpD,KAAK,EAAE;gBACH,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,aAAa,IAAI,CAAC;gBACrC,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,iBAAiB,IAAI,CAAC;gBAC1C,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,YAAY,IAAI,CAAC;aACvC;YACD,GAAG,EAAE,IAAI;SACZ,CAAC;IACN,CAAC;IAEM,SAAS;QAEZ,OAAO,KAAK,CAAC,SAAS,EAAE,CAAC;IAC7B,CAAC;CACJ;AAhKD,8BAgKC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AbstractLLM } from "../../base";
|
|
2
|
+
import { LLMUtility } from "../../utility";
|
|
3
|
+
/** 通义千问大模型 */
|
|
4
|
+
export declare class QWenLLM extends AbstractLLM<LLMUtility.QWen.Config, LLMUtility.QWen.MessageData> {
|
|
5
|
+
/** 构造函数 */
|
|
6
|
+
constructor(config?: LLMUtility.QWen.Config);
|
|
7
|
+
/** @override */
|
|
8
|
+
protected addSystemMessage(text: string): void;
|
|
9
|
+
/** @override */
|
|
10
|
+
protected addUserMessage(text: string): void;
|
|
11
|
+
/** @override */
|
|
12
|
+
protected addAssistantMessage(content: string, toolCalls?: Array<LLMUtility.ToolCall>): void;
|
|
13
|
+
/** @override */
|
|
14
|
+
protected addToolMessage(result: LLMUtility.ToolResult): void;
|
|
15
|
+
/** @override — 截断过长工具输出 */
|
|
16
|
+
protected compactMessages(): void;
|
|
17
|
+
/** @override — 停止原因 */
|
|
18
|
+
protected stopReason(reason: string): LLMUtility.FinishReason;
|
|
19
|
+
/** @override */
|
|
20
|
+
protected request(tools: LLMUtility.ToolDefinition[]): Promise<LLMUtility.Response>;
|
|
21
|
+
OnDestroy(): boolean;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=QWenLLM.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QWenLLM.d.ts","sourceRoot":"","sources":["../../../src/module/LLMModule/QWenLLM.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAkB,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3D,cAAc;AACd,qBAAa,OAAQ,SAAQ,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC;IAGzF,WAAW;gBACQ,MAAM,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,MAAM;IA2BlD,gBAAgB;IAChB,SAAS,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAM9C,gBAAgB;IAChB,SAAS,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAM5C,gBAAgB;IAChB,SAAS,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,IAAI;IAe5F,gBAAgB;IAChB,SAAS,CAAC,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,GAAG,IAAI;IAM7D,2BAA2B;IAC3B,SAAS,CAAC,eAAe,IAAI,IAAI;IAYjC,uBAAuB;IACvB,SAAS,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,YAAY;IAW7D,gBAAgB;cACA,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,cAAc,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC;IAsDlF,SAAS,IAAI,OAAO;CAI9B"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QWenLLM = void 0;
|
|
4
|
+
const base_1 = require("../../base");
|
|
5
|
+
const utility_1 = require("../../utility");
|
|
6
|
+
/** 通义千问大模型 */
|
|
7
|
+
class QWenLLM extends base_1.AbstractLLM {
|
|
8
|
+
/** 构造函数 */
|
|
9
|
+
constructor(config) {
|
|
10
|
+
super({
|
|
11
|
+
type: "QWen",
|
|
12
|
+
url: "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
|
|
13
|
+
apiKey: "",
|
|
14
|
+
model: "qwen-plus",
|
|
15
|
+
timeout: 60000,
|
|
16
|
+
temperature: 1,
|
|
17
|
+
topP: 1,
|
|
18
|
+
maxTokens: 4096,
|
|
19
|
+
stop: undefined,
|
|
20
|
+
stream: false,
|
|
21
|
+
seed: undefined,
|
|
22
|
+
maxMessageCache: 10,
|
|
23
|
+
maxToolOutput: 800,
|
|
24
|
+
enableSearch: false,
|
|
25
|
+
vlHighResolutionImages: false,
|
|
26
|
+
repetitionPenalty: undefined,
|
|
27
|
+
thinking: { type: "disabled" },
|
|
28
|
+
responseFormat: "text",
|
|
29
|
+
...config
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
// ======================== 受保护实现 ========================
|
|
33
|
+
/** @override */
|
|
34
|
+
addSystemMessage(text) {
|
|
35
|
+
const message = { role: "system", content: text, preserve: true };
|
|
36
|
+
this.messages.Add(message);
|
|
37
|
+
}
|
|
38
|
+
/** @override */
|
|
39
|
+
addUserMessage(text) {
|
|
40
|
+
const message = { role: "user", content: text };
|
|
41
|
+
this.messages.Add(message);
|
|
42
|
+
}
|
|
43
|
+
/** @override */
|
|
44
|
+
addAssistantMessage(content, toolCalls) {
|
|
45
|
+
const message = {
|
|
46
|
+
role: "assistant",
|
|
47
|
+
content: content || null,
|
|
48
|
+
tool_calls: toolCalls?.map((tc, i) => ({
|
|
49
|
+
index: i,
|
|
50
|
+
id: tc.id,
|
|
51
|
+
type: "function",
|
|
52
|
+
function: { name: tc.name, arguments: JSON.stringify(tc.arguments) },
|
|
53
|
+
}))
|
|
54
|
+
};
|
|
55
|
+
this.messages.Add(message);
|
|
56
|
+
}
|
|
57
|
+
/** @override */
|
|
58
|
+
addToolMessage(result) {
|
|
59
|
+
const message = { role: "tool", tool_call_id: result.id, content: result.data };
|
|
60
|
+
this.messages.Add(message);
|
|
61
|
+
}
|
|
62
|
+
/** @override — 截断过长工具输出 */
|
|
63
|
+
compactMessages() {
|
|
64
|
+
const maxLen = this.config.maxToolOutput ?? 800;
|
|
65
|
+
this.messages.Compact((message) => {
|
|
66
|
+
if (message.role === "tool" && message.content && message.content.length > maxLen) {
|
|
67
|
+
return { ...message, content: message.content.slice(0, maxLen) + `\n[truncated: ${message.content.length - maxLen} chars omitted]` };
|
|
68
|
+
}
|
|
69
|
+
return message;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** @override — 停止原因 */
|
|
73
|
+
stopReason(reason) {
|
|
74
|
+
switch (reason) {
|
|
75
|
+
case "stop": return "stop";
|
|
76
|
+
case "length": return "length";
|
|
77
|
+
case "tool_calls": return "tool_calls";
|
|
78
|
+
case "content_filter": return "content_filter";
|
|
79
|
+
default: return "unknown";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** @override */
|
|
83
|
+
async request(tools) {
|
|
84
|
+
const messages = this.messages.All();
|
|
85
|
+
const body = {
|
|
86
|
+
model: this.config.model,
|
|
87
|
+
messages,
|
|
88
|
+
thinking: this.config.thinking,
|
|
89
|
+
enable_search: this.config.enableSearch || undefined,
|
|
90
|
+
vl_high_resolution_images: this.config.vlHighResolutionImages || undefined,
|
|
91
|
+
repetition_penalty: this.config.repetitionPenalty,
|
|
92
|
+
response_format: this.config.responseFormat && this.config.responseFormat !== "text" ? { type: this.config.responseFormat } : undefined,
|
|
93
|
+
temperature: this.config.temperature,
|
|
94
|
+
top_p: this.config.topP,
|
|
95
|
+
max_tokens: this.config.maxTokens,
|
|
96
|
+
stop: this.config.stop,
|
|
97
|
+
stream: this.config.stream,
|
|
98
|
+
stream_options: undefined,
|
|
99
|
+
frequency_penalty: undefined,
|
|
100
|
+
presence_penalty: undefined,
|
|
101
|
+
tools: tools.length > 0 ? tools.map(t => ({ type: "function", function: { name: t.name, description: t.description, parameters: t.inputSchema } })) : undefined,
|
|
102
|
+
tool_choice: undefined,
|
|
103
|
+
seed: this.config.seed,
|
|
104
|
+
};
|
|
105
|
+
const response = await utility_1.NetworkUtility.HTTP.OnRequest(this.config.url, {
|
|
106
|
+
method: "post",
|
|
107
|
+
data: body,
|
|
108
|
+
headers: { "Authorization": `Bearer ${this.config.apiKey}`, "Content-Type": "application/json" },
|
|
109
|
+
timeout: this.config.timeout,
|
|
110
|
+
});
|
|
111
|
+
const data = response.data;
|
|
112
|
+
const choice = data.choices?.[0];
|
|
113
|
+
const message = choice?.message;
|
|
114
|
+
return {
|
|
115
|
+
id: data.id ?? "",
|
|
116
|
+
model: data.model ?? "",
|
|
117
|
+
content: message?.content ?? "",
|
|
118
|
+
toolCalls: message?.tool_calls?.map(tc => ({
|
|
119
|
+
id: tc.id,
|
|
120
|
+
name: tc.function.name,
|
|
121
|
+
arguments: typeof tc.function.arguments === "string" ? JSON.parse(tc.function.arguments) : tc.function.arguments,
|
|
122
|
+
})),
|
|
123
|
+
finishReason: this.stopReason(choice?.finish_reason),
|
|
124
|
+
usage: {
|
|
125
|
+
input: data.usage?.prompt_tokens ?? 0,
|
|
126
|
+
output: data.usage?.completion_tokens ?? 0,
|
|
127
|
+
total: data.usage?.total_tokens ?? 0,
|
|
128
|
+
},
|
|
129
|
+
raw: data,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
OnDestroy() {
|
|
133
|
+
return super.OnDestroy();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.QWenLLM = QWenLLM;
|
|
137
|
+
//# sourceMappingURL=QWenLLM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QWenLLM.js","sourceRoot":"","sources":["../../../src/module/LLMModule/QWenLLM.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AACz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S,EAAE,OAAO,EAAE,CAAC,QAAQ,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS;aACnH,CAAC,CAAC;YACH,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC;YACpD,KAAK,EAAE;gBACH,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,aAAa,IAAI,CAAC;gBACrC,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,iBAAiB,IAAI,CAAC;gBAC1C,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,YAAY,IAAI,CAAC;aACvC;YACD,GAAG,EAAE,IAAI;SACZ,CAAC;IACN,CAAC;IAEM,SAAS;QAEZ,OAAO,KAAK,CAAC,SAAS,EAAE,CAAC;IAC7B,CAAC;CACJ;AAxJD,0BAwJC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/module/LLMModule/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
|
|
@@ -14,5 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./LLMModule"), exports);
|
|
18
|
+
__exportStar(require("./ClaudeLLM"), exports);
|
|
19
|
+
__exportStar(require("./DeepSeekLLM"), exports);
|
|
20
|
+
__exportStar(require("./GeminiLLM"), exports);
|
|
21
|
+
__exportStar(require("./OpenAILLM"), exports);
|
|
22
|
+
__exportStar(require("./QWenLLM"), exports);
|
|
18
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/module/LLMModule/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,8CAA4B;AAC5B,gDAA8B;AAC9B,8CAA4B;AAC5B,8CAA4B;AAC5B,4CAA0B"}
|
package/module/index.d.ts
CHANGED
package/module/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/module/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/module/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
|
package/module/index.js
CHANGED
|
@@ -14,9 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./LLMModule"), exports);
|
|
17
18
|
__exportStar(require("./AgentModule"), exports);
|
|
18
|
-
__exportStar(require("./ToolModule"), exports);
|
|
19
|
-
__exportStar(require("./ReasonModule"), exports);
|
|
20
|
-
__exportStar(require("./DialogModule"), exports);
|
|
21
|
-
__exportStar(require("./SkillModule"), exports);
|
|
22
19
|
//# sourceMappingURL=index.js.map
|
package/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/module/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/module/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,gDAA8B"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { LLMUtility } from "./LLMUtility";
|
|
2
|
+
/** 智能体工具 */
|
|
3
|
+
export declare namespace AgentUtility {
|
|
4
|
+
/** 大模型Token用量 */
|
|
5
|
+
interface Usage {
|
|
6
|
+
/** 输入 token */
|
|
7
|
+
input: number;
|
|
8
|
+
/** 输出 token */
|
|
9
|
+
output: number;
|
|
10
|
+
/** 总计 token */
|
|
11
|
+
total: number;
|
|
12
|
+
}
|
|
13
|
+
/** 会话数据 */
|
|
14
|
+
interface SessionData {
|
|
15
|
+
/** 用户输入 */
|
|
16
|
+
input: string;
|
|
17
|
+
/** 智能体输出 */
|
|
18
|
+
output: string;
|
|
19
|
+
/** 用量信息 */
|
|
20
|
+
usage: Usage;
|
|
21
|
+
/** 时间戳 */
|
|
22
|
+
timestamp: number;
|
|
23
|
+
}
|
|
24
|
+
/** 智能体快照 — 包含对话记录与大模型快照,供 AgentModule.restore 完整恢复 */
|
|
25
|
+
interface AgentSnapshot {
|
|
26
|
+
/** 智能体ID */
|
|
27
|
+
id: string;
|
|
28
|
+
/** 大模型快照 */
|
|
29
|
+
llmSnapshot: LLMUtility.Snapshot;
|
|
30
|
+
/** 对话记录 */
|
|
31
|
+
turns: SessionData[];
|
|
32
|
+
/** 创建时间戳 */
|
|
33
|
+
createdAt: number;
|
|
34
|
+
/** 导出时间戳 */
|
|
35
|
+
exportAt: number;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=AgentUtility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentUtility.d.ts","sourceRoot":"","sources":["../../src/utility/AgentUtility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,YAAY;AACZ,yBAAiB,YAAY,CAC7B;IACI,iBAAiB;IACjB,UAAiB,KAAK;QAElB,eAAe;QACf,KAAK,EAAE,MAAM,CAAC;QACd,eAAe;QACf,MAAM,EAAE,MAAM,CAAC;QACf,eAAe;QACf,KAAK,EAAE,MAAM,CAAC;KACjB;IAED,WAAW;IACX,UAAiB,WAAW;QAExB,WAAW;QACX,KAAK,EAAE,MAAM,CAAC;QACd,YAAY;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,WAAW;QACX,KAAK,EAAE,KAAK,CAAC;QACb,UAAU;QACV,SAAS,EAAE,MAAM,CAAC;KACrB;IACD,sDAAsD;IACtD,UAAiB,aAAa;QAE1B,YAAY;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,YAAY;QACZ,WAAW,EAAE,UAAU,CAAC,QAAQ,CAAC;QACjC,WAAW;QACX,KAAK,EAAE,WAAW,EAAE,CAAC;QACrB,YAAY;QACZ,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY;QACZ,QAAQ,EAAE,MAAM,CAAC;KACpB;CAGJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentUtility.js","sourceRoot":"","sources":["../../src/utility/AgentUtility.ts"],"names":[],"mappings":""}
|