@ai-setting/roy-agent-core 1.7.48 → 1.7.50
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/config/index.js +7 -7
- package/dist/env/agent/index.js +10 -10
- package/dist/env/commands/index.js +7 -7
- package/dist/env/context/index.js +3 -3
- package/dist/env/debug/index.js +7 -7
- package/dist/env/event-source/index.js +17 -14
- package/dist/env/hook/index.js +9 -6
- package/dist/env/index.js +39 -34
- package/dist/env/llm/index.js +7 -7
- package/dist/env/log-trace/index.js +7 -7
- package/dist/env/mcp/index.js +7 -7
- package/dist/env/memory/index.js +11 -11
- package/dist/env/plugin/index.js +7 -7
- package/dist/env/prompt/index.js +8 -8
- package/dist/env/session/index.js +8 -7
- package/dist/env/skill/index.js +7 -7
- package/dist/env/task/delegate/index.js +8 -8
- package/dist/env/task/index.js +17 -17
- package/dist/env/task/plugins/index.js +10 -9
- package/dist/env/task/storage/index.js +2 -2
- package/dist/env/task/tools/index.js +3 -3
- package/dist/env/tool/built-in/index.js +2 -2
- package/dist/env/tool/index.js +8 -8
- package/dist/env/workflow/engine/index.js +13 -9
- package/dist/env/workflow/hooks/index.js +25 -0
- package/dist/env/workflow/index.js +20 -17
- package/dist/env/workflow/nodes/index.js +2 -2
- package/dist/env/workflow/plugins/index.js +18 -0
- package/dist/env/workflow/service/index.js +2 -2
- package/dist/env/workflow/storage/index.js +3 -3
- package/dist/env/workflow/tools/index.js +12 -11
- package/dist/env/workflow/utils/index.js +4 -4
- package/dist/index.js +80 -70
- package/dist/shared/@ai-setting/{roy-agent-core-0r90298w.js → roy-agent-core-0cfaqnz9.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-5j4awbgc.js → roy-agent-core-1cv9j4dg.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-v5vs1jby.js → roy-agent-core-2gay3sjt.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-9cqpdrnk.js → roy-agent-core-2k4xffaa.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-dabnevwe.js → roy-agent-core-35s1w7tc.js} +230 -96
- package/dist/shared/@ai-setting/{roy-agent-core-bjrtwfta.js → roy-agent-core-3tv1q6f2.js} +27 -11
- package/dist/shared/@ai-setting/{roy-agent-core-3j4by8rj.js → roy-agent-core-4z3rq5gw.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-zbb3sk72.js → roy-agent-core-5apmk4qw.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-jfptxs4f.js → roy-agent-core-6167phd4.js} +6 -2
- package/dist/shared/@ai-setting/{roy-agent-core-8nv07zgr.js → roy-agent-core-7evvpfwc.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-vsrfzaze.js → roy-agent-core-7g03zkkb.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-tm57tmds.js → roy-agent-core-8s9jd2qy.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-4kbvfnn1.js → roy-agent-core-978b6wfx.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-9csa89jx.js +46 -0
- package/dist/shared/@ai-setting/{roy-agent-core-y1n63tse.js → roy-agent-core-9jzysq50.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-4m02hnqf.js → roy-agent-core-ak4dc3kg.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-rgpkygbc.js → roy-agent-core-athdr2m0.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-83mk8wrn.js → roy-agent-core-avyd65je.js} +12 -6
- package/dist/shared/@ai-setting/{roy-agent-core-223v204d.js → roy-agent-core-cg9f4zch.js} +69 -4
- package/dist/shared/@ai-setting/{roy-agent-core-a9pbda78.js → roy-agent-core-dsevjbck.js} +38 -10
- package/dist/shared/@ai-setting/{roy-agent-core-4cj6hram.js → roy-agent-core-dv714bqh.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-amp8qckb.js → roy-agent-core-dwx9hjwx.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-d94ddn0r.js → roy-agent-core-f28va833.js} +8 -7
- package/dist/shared/@ai-setting/roy-agent-core-fs36xgcs.js +13 -0
- package/dist/shared/@ai-setting/{roy-agent-core-55hkeft7.js → roy-agent-core-fvs48d38.js} +26 -6
- package/dist/shared/@ai-setting/{roy-agent-core-nvcqp6p9.js → roy-agent-core-gpf2059p.js} +17 -13
- package/dist/shared/@ai-setting/{roy-agent-core-wn59p0zw.js → roy-agent-core-k8b440n3.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-pd0exvnq.js → roy-agent-core-nde5gzta.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-9qn92jhf.js → roy-agent-core-ne2t1pay.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-y1fp2mgf.js → roy-agent-core-p8ak03s0.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-6vbgswjw.js → roy-agent-core-q6twb0df.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-zrgaemma.js → roy-agent-core-q9gnnv6v.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-hxazjj4p.js → roy-agent-core-qamktze3.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-54wzmvnb.js → roy-agent-core-qcspfszy.js} +11 -4
- package/dist/shared/@ai-setting/{roy-agent-core-p1p9mr8f.js → roy-agent-core-qm9jda8p.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-4nnv0dze.js → roy-agent-core-rnwr39b0.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-3b2ceffs.js → roy-agent-core-rpnjzztt.js} +51 -76
- package/dist/shared/@ai-setting/{roy-agent-core-yjqj3taz.js → roy-agent-core-rpwn590p.js} +13 -13
- package/dist/shared/@ai-setting/{roy-agent-core-za09t5g3.js → roy-agent-core-rx16h2m1.js} +12 -6
- package/dist/shared/@ai-setting/{roy-agent-core-ajtsk20z.js → roy-agent-core-s7jpkfm1.js} +75 -754
- package/dist/shared/@ai-setting/{roy-agent-core-ygnva439.js → roy-agent-core-skzjs973.js} +6 -5
- package/dist/shared/@ai-setting/{roy-agent-core-1rm32m5t.js → roy-agent-core-t37wbysj.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-ead21w5c.js → roy-agent-core-tdbv7ff4.js} +5 -3
- package/dist/shared/@ai-setting/{roy-agent-core-333apxaa.js → roy-agent-core-tjg71zqp.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-hkj5v9xq.js → roy-agent-core-vrsxhw9e.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-7p5zf8ay.js → roy-agent-core-vy69rpxy.js} +13 -13
- package/dist/shared/@ai-setting/roy-agent-core-wxsgay02.js +302 -0
- package/dist/shared/@ai-setting/{roy-agent-core-yjjqm4ww.js → roy-agent-core-x8n1r7h4.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-gy1zfe0d.js → roy-agent-core-yd21n6c7.js} +76 -13
- package/dist/shared/@ai-setting/{roy-agent-core-xyys5m1a.js → roy-agent-core-yhsssn86.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-zd077w51.js +1037 -0
- package/dist/shared/@ai-setting/{roy-agent-core-qvaqmj3f.js → roy-agent-core-zd3ddm4k.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-ze068vc9.js +37 -0
- package/package.json +1 -1
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentComponentAdapter,
|
|
3
3
|
init_agent_component_adapter
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-6167phd4.js";
|
|
5
5
|
import"./roy-agent-core-1db4vpc6.js";
|
|
6
|
+
import"./roy-agent-core-ze068vc9.js";
|
|
6
7
|
import"./roy-agent-core-e25xkv53.js";
|
|
7
|
-
import"./roy-agent-core-
|
|
8
|
-
import"./roy-agent-core-
|
|
9
|
-
import"./roy-agent-core-
|
|
10
|
-
import"./roy-agent-core-
|
|
8
|
+
import"./roy-agent-core-4z3rq5gw.js";
|
|
9
|
+
import"./roy-agent-core-k8b440n3.js";
|
|
10
|
+
import"./roy-agent-core-5apmk4qw.js";
|
|
11
|
+
import"./roy-agent-core-dsevjbck.js";
|
|
11
12
|
import"./roy-agent-core-8seq65bp.js";
|
|
12
13
|
import"./roy-agent-core-jnszp0jq.js";
|
|
13
14
|
import"./roy-agent-core-fs0mn2jk.js";
|
|
@@ -3,17 +3,17 @@ import {
|
|
|
3
3
|
} from "./roy-agent-core-az13yzmc.js";
|
|
4
4
|
import {
|
|
5
5
|
BaseComponent
|
|
6
|
-
} from "./roy-agent-core-
|
|
6
|
+
} from "./roy-agent-core-tdbv7ff4.js";
|
|
7
7
|
import {
|
|
8
8
|
globalHookManager,
|
|
9
9
|
init_global_hook_manager
|
|
10
|
-
} from "./roy-agent-core-
|
|
10
|
+
} from "./roy-agent-core-4z3rq5gw.js";
|
|
11
11
|
import {
|
|
12
12
|
init_context
|
|
13
|
-
} from "./roy-agent-core-
|
|
13
|
+
} from "./roy-agent-core-k8b440n3.js";
|
|
14
14
|
import {
|
|
15
15
|
getEnvContextOrEmpty
|
|
16
|
-
} from "./roy-agent-core-
|
|
16
|
+
} from "./roy-agent-core-5apmk4qw.js";
|
|
17
17
|
import {
|
|
18
18
|
createLogger,
|
|
19
19
|
init_logger
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createHook
|
|
3
|
-
|
|
2
|
+
createHook,
|
|
3
|
+
init_hook
|
|
4
|
+
} from "./roy-agent-core-qcspfszy.js";
|
|
4
5
|
import {
|
|
5
6
|
HookManager
|
|
6
|
-
} from "./roy-agent-core-
|
|
7
|
+
} from "./roy-agent-core-4z3rq5gw.js";
|
|
7
8
|
|
|
8
9
|
// src/env/component.ts
|
|
10
|
+
init_hook();
|
|
9
11
|
class BaseComponent {
|
|
10
12
|
_status = "created";
|
|
11
13
|
_enabled = true;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
exports_node_registry_helper,
|
|
3
3
|
init_node_registry_helper
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-vrsxhw9e.js";
|
|
5
5
|
import {
|
|
6
6
|
askUserTool,
|
|
7
7
|
createRunWorkflowTool,
|
|
@@ -13,18 +13,18 @@ import {
|
|
|
13
13
|
createWorkflowSearchTool,
|
|
14
14
|
createWorkflowTagListTool,
|
|
15
15
|
createWorkflowValidateTool
|
|
16
|
-
} from "./roy-agent-core-
|
|
16
|
+
} from "./roy-agent-core-q9gnnv6v.js";
|
|
17
17
|
import {
|
|
18
18
|
WorkflowService
|
|
19
|
-
} from "./roy-agent-core-
|
|
19
|
+
} from "./roy-agent-core-7evvpfwc.js";
|
|
20
20
|
import {
|
|
21
21
|
WorkflowEngine,
|
|
22
22
|
exports_engine,
|
|
23
23
|
init_engine
|
|
24
|
-
} from "./roy-agent-core-
|
|
24
|
+
} from "./roy-agent-core-35s1w7tc.js";
|
|
25
25
|
import {
|
|
26
26
|
BaseComponent
|
|
27
|
-
} from "./roy-agent-core-
|
|
27
|
+
} from "./roy-agent-core-tdbv7ff4.js";
|
|
28
28
|
import {
|
|
29
29
|
createLogger,
|
|
30
30
|
init_logger
|
|
@@ -104,7 +104,7 @@ class WorkflowComponent extends BaseComponent {
|
|
|
104
104
|
return;
|
|
105
105
|
try {
|
|
106
106
|
const { NodeRegistry } = await import("../../env/workflow/engine/index.js");
|
|
107
|
-
const { registerDecoratorNodeType: registerDecoratorNodeType2 } = await import("./roy-agent-core-
|
|
107
|
+
const { registerDecoratorNodeType: registerDecoratorNodeType2 } = await import("./roy-agent-core-9jzysq50.js");
|
|
108
108
|
this.nodeRegistry = new NodeRegistry;
|
|
109
109
|
registerDecoratorNodeType2(this.nodeRegistry);
|
|
110
110
|
this.decoratorsRegistered = true;
|
|
@@ -134,14 +134,14 @@ class WorkflowComponent extends BaseComponent {
|
|
|
134
134
|
}
|
|
135
135
|
async runWorkflow(definition, input, options) {
|
|
136
136
|
const { NodeRegistry } = await import("../../env/workflow/engine/index.js");
|
|
137
|
-
const { registerDecoratorNodeType: registerDecoratorNodeType2 } = await import("./roy-agent-core-
|
|
137
|
+
const { registerDecoratorNodeType: registerDecoratorNodeType2 } = await import("./roy-agent-core-9jzysq50.js");
|
|
138
138
|
const toolComponent = this.toolComponent || this._workflowEnv?.getComponent("tool");
|
|
139
139
|
const skillComponent = this._workflowEnv?.getComponent("skill");
|
|
140
140
|
let agentRunner = this.agentRunner;
|
|
141
141
|
if (!agentRunner && this._workflowEnv) {
|
|
142
142
|
const agentComponent = this._workflowEnv.getComponent("agent");
|
|
143
143
|
if (agentComponent) {
|
|
144
|
-
const { AgentComponentAdapter } = await import("./roy-agent-core-
|
|
144
|
+
const { AgentComponentAdapter } = await import("./roy-agent-core-skzjs973.js");
|
|
145
145
|
agentRunner = new AgentComponentAdapter(agentComponent, {}, this.sessionComponent);
|
|
146
146
|
}
|
|
147
147
|
}
|
|
@@ -163,7 +163,7 @@ class WorkflowComponent extends BaseComponent {
|
|
|
163
163
|
if (this.workflowService) {
|
|
164
164
|
this.workflowService = null;
|
|
165
165
|
try {
|
|
166
|
-
const { closeDatabase } = await import("./roy-agent-core-
|
|
166
|
+
const { closeDatabase } = await import("./roy-agent-core-2k4xffaa.js");
|
|
167
167
|
closeDatabase();
|
|
168
168
|
componentLogger.info("[WorkflowComponent] SQLite database closed");
|
|
169
169
|
} catch (error) {
|
|
@@ -241,9 +241,9 @@ class WorkflowComponent extends BaseComponent {
|
|
|
241
241
|
}
|
|
242
242
|
async initSqliteService() {
|
|
243
243
|
try {
|
|
244
|
-
const { getDatabase, initializeTables } = await import("./roy-agent-core-
|
|
245
|
-
const { WorkflowRepository } = await import("./roy-agent-core-
|
|
246
|
-
const { TagRepository } = await import("./roy-agent-core-
|
|
244
|
+
const { getDatabase, initializeTables } = await import("./roy-agent-core-2k4xffaa.js");
|
|
245
|
+
const { WorkflowRepository } = await import("./roy-agent-core-1cv9j4dg.js");
|
|
246
|
+
const { TagRepository } = await import("./roy-agent-core-ne2t1pay.js");
|
|
247
247
|
const db = getDatabase();
|
|
248
248
|
initializeTables();
|
|
249
249
|
const workflowRepository = new WorkflowRepository(db);
|
|
@@ -309,7 +309,7 @@ class WorkflowComponent extends BaseComponent {
|
|
|
309
309
|
this.workflowService = null;
|
|
310
310
|
this.nodeRegistry = null;
|
|
311
311
|
try {
|
|
312
|
-
const { closeDatabase } = await import("./roy-agent-core-
|
|
312
|
+
const { closeDatabase } = await import("./roy-agent-core-2k4xffaa.js");
|
|
313
313
|
closeDatabase();
|
|
314
314
|
} catch {}
|
|
315
315
|
this._status = "stopped";
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LarkCardPatchNotifier,
|
|
3
|
+
formatDurationMs
|
|
4
|
+
} from "./roy-agent-core-zd077w51.js";
|
|
5
|
+
import {
|
|
6
|
+
WorkflowHookPoints,
|
|
7
|
+
init_workflow_hook_points
|
|
8
|
+
} from "./roy-agent-core-9csa89jx.js";
|
|
9
|
+
import {
|
|
10
|
+
init_context
|
|
11
|
+
} from "./roy-agent-core-k8b440n3.js";
|
|
12
|
+
import {
|
|
13
|
+
getEnvContextOrEmpty
|
|
14
|
+
} from "./roy-agent-core-5apmk4qw.js";
|
|
15
|
+
import {
|
|
16
|
+
TracedAs,
|
|
17
|
+
init_decorator
|
|
18
|
+
} from "./roy-agent-core-dsevjbck.js";
|
|
19
|
+
import {
|
|
20
|
+
createLogger,
|
|
21
|
+
init_logger
|
|
22
|
+
} from "./roy-agent-core-8seq65bp.js";
|
|
23
|
+
import {
|
|
24
|
+
__legacyDecorateClassTS
|
|
25
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
26
|
+
|
|
27
|
+
// src/env/workflow/plugins/lark-cli-workflow-notify-plugin.ts
|
|
28
|
+
init_decorator();
|
|
29
|
+
init_logger();
|
|
30
|
+
init_context();
|
|
31
|
+
init_workflow_hook_points();
|
|
32
|
+
var logger = createLogger("lark-cli:workflow-notify");
|
|
33
|
+
|
|
34
|
+
class LarkCliWorkflowNotifyHook {
|
|
35
|
+
name;
|
|
36
|
+
priority;
|
|
37
|
+
description;
|
|
38
|
+
pluginName;
|
|
39
|
+
sourceId;
|
|
40
|
+
hookPoints = [
|
|
41
|
+
WorkflowHookPoints.BEFORE_RUN,
|
|
42
|
+
WorkflowHookPoints.AFTER_RUN,
|
|
43
|
+
WorkflowHookPoints.BEFORE_NODE,
|
|
44
|
+
WorkflowHookPoints.AFTER_NODE
|
|
45
|
+
];
|
|
46
|
+
config;
|
|
47
|
+
cardNotifier;
|
|
48
|
+
cardMessageIds = new Map;
|
|
49
|
+
lastNodeNotifyTimestamps = new Map;
|
|
50
|
+
static CARD_START_FAILED_SENTINEL = "__wf_card_start_failed__";
|
|
51
|
+
static CARD_START_INFLIGHT_SENTINEL = "__wf_card_start_inflight__";
|
|
52
|
+
constructor(config = {}) {
|
|
53
|
+
this.name = config.pluginName || "LarkCliWorkflowNotifyPlugin";
|
|
54
|
+
this.priority = config.priority ?? 5;
|
|
55
|
+
this.description = "LarkCli workflow 进展通知 Hook(卡片模式)";
|
|
56
|
+
this.pluginName = config.pluginName;
|
|
57
|
+
this.sourceId = config.sourceId;
|
|
58
|
+
this.config = {
|
|
59
|
+
enabled: true,
|
|
60
|
+
priority: 5,
|
|
61
|
+
...config
|
|
62
|
+
};
|
|
63
|
+
this.cardNotifier = config.cardNotifier ?? new LarkCardPatchNotifier;
|
|
64
|
+
}
|
|
65
|
+
async execute(ctx) {
|
|
66
|
+
if (!this.config.enabled)
|
|
67
|
+
return;
|
|
68
|
+
const env = getEnvContextOrEmpty();
|
|
69
|
+
if (this.pluginName && this.sourceId) {
|
|
70
|
+
const key = `${this.sourceId}:${this.pluginName}`;
|
|
71
|
+
if (env.pluginEnabled && env.pluginEnabled[key] !== true) {
|
|
72
|
+
logger.debug(`Plugin not enabled for source: ${key}`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
switch (ctx.hookPoint) {
|
|
77
|
+
case WorkflowHookPoints.BEFORE_RUN:
|
|
78
|
+
await this.onBeforeRun(ctx);
|
|
79
|
+
break;
|
|
80
|
+
case WorkflowHookPoints.AFTER_RUN:
|
|
81
|
+
await this.onAfterRun(ctx);
|
|
82
|
+
break;
|
|
83
|
+
case WorkflowHookPoints.BEFORE_NODE:
|
|
84
|
+
await this.onBeforeNode(ctx);
|
|
85
|
+
break;
|
|
86
|
+
case WorkflowHookPoints.AFTER_NODE:
|
|
87
|
+
await this.onAfterNode(ctx);
|
|
88
|
+
break;
|
|
89
|
+
default:
|
|
90
|
+
logger.debug(`ignored hook point: ${ctx.hookPoint}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async onBeforeRun(ctx) {
|
|
94
|
+
const data = ctx.data;
|
|
95
|
+
if (!data?.runId)
|
|
96
|
+
return;
|
|
97
|
+
await this.sendCardStart(data);
|
|
98
|
+
}
|
|
99
|
+
async onBeforeNode(ctx) {
|
|
100
|
+
const data = ctx.data;
|
|
101
|
+
if (!data?.runId)
|
|
102
|
+
return;
|
|
103
|
+
if (this.shouldThrottleNodeStart(data.runId))
|
|
104
|
+
return;
|
|
105
|
+
const timestamp = new Date().toISOString();
|
|
106
|
+
await this.patchCard(data, {
|
|
107
|
+
currentNode: data.nodeId,
|
|
108
|
+
currentNodeType: data.nodeType,
|
|
109
|
+
processSteps: [
|
|
110
|
+
{
|
|
111
|
+
title: `${data.nodeId} 开始`,
|
|
112
|
+
timestamp,
|
|
113
|
+
category: data.nodeType
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
async onAfterNode(ctx) {
|
|
119
|
+
const data = ctx.data;
|
|
120
|
+
if (!data?.runId)
|
|
121
|
+
return;
|
|
122
|
+
const timestamp = new Date().toISOString();
|
|
123
|
+
const nodeStatus = String(data.status);
|
|
124
|
+
const succeeded = nodeStatus === "completed" || nodeStatus === "skipped";
|
|
125
|
+
const statusText = succeeded ? "完成" : "失败";
|
|
126
|
+
const durationText = formatDurationMs(data.durationMs);
|
|
127
|
+
const description = data.error ?? (durationText ? `耗时 ${durationText}` : succeeded ? undefined : `节点状态:${nodeStatus}`);
|
|
128
|
+
const processSteps = [
|
|
129
|
+
{
|
|
130
|
+
title: `${data.nodeId} ${statusText}`,
|
|
131
|
+
timestamp,
|
|
132
|
+
endTimestamp: timestamp,
|
|
133
|
+
description,
|
|
134
|
+
category: data.nodeType
|
|
135
|
+
}
|
|
136
|
+
];
|
|
137
|
+
const milestones = succeeded || !data.error ? [] : [
|
|
138
|
+
{
|
|
139
|
+
title: `节点失败:${data.nodeId}`,
|
|
140
|
+
timestamp,
|
|
141
|
+
description: data.error
|
|
142
|
+
}
|
|
143
|
+
];
|
|
144
|
+
await this.patchCard(data, {
|
|
145
|
+
currentNode: data.nodeId,
|
|
146
|
+
currentNodeType: data.nodeType,
|
|
147
|
+
milestones,
|
|
148
|
+
processSteps
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
async onAfterRun(ctx) {
|
|
152
|
+
const data = ctx.data;
|
|
153
|
+
if (!data?.runId)
|
|
154
|
+
return;
|
|
155
|
+
const messageId = this.cardMessageIds.get(data.runId);
|
|
156
|
+
if (!messageId || messageId === LarkCliWorkflowNotifyHook.CARD_START_FAILED_SENTINEL || messageId === LarkCliWorkflowNotifyHook.CARD_START_INFLIGHT_SENTINEL) {
|
|
157
|
+
logger.debug(`onAfterRun: no card for run ${data.runId}, skip`);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const status = this.mapRunStatus(data.status);
|
|
161
|
+
const target = this.resolveTarget();
|
|
162
|
+
const profile = target.profile;
|
|
163
|
+
try {
|
|
164
|
+
await this.cardNotifier.finishWorkflow({
|
|
165
|
+
messageId,
|
|
166
|
+
chatId: target.chatId,
|
|
167
|
+
profile,
|
|
168
|
+
status,
|
|
169
|
+
meta: this.buildWorkflowMeta(data),
|
|
170
|
+
completedNodes: data.completedNodes,
|
|
171
|
+
totalNodes: data.totalNodes,
|
|
172
|
+
durationMs: data.durationMs,
|
|
173
|
+
error: data.error ?? data.stopReason,
|
|
174
|
+
finalStep: data.status === "completed" ? undefined : data.stopReason
|
|
175
|
+
});
|
|
176
|
+
this.cardMessageIds.delete(data.runId);
|
|
177
|
+
this.lastNodeNotifyTimestamps.delete(`node:${data.runId}`);
|
|
178
|
+
} catch (err) {
|
|
179
|
+
logger.error(`sendCardFinish failed for workflow run ${data.runId}: ${err.message}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async sendCardStart(data) {
|
|
183
|
+
if (!this.cardNotifier)
|
|
184
|
+
return;
|
|
185
|
+
const claim = this.cardMessageIds.get(data.runId);
|
|
186
|
+
if (claim) {
|
|
187
|
+
logger.debug(`sendCardStart: run ${data.runId} 已有首卡(${claim})→ 跳过重复建卡`);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
this.cardMessageIds.set(data.runId, LarkCliWorkflowNotifyHook.CARD_START_INFLIGHT_SENTINEL);
|
|
191
|
+
const target = this.resolveTarget();
|
|
192
|
+
if (!target.chatId) {
|
|
193
|
+
this.cardMessageIds.delete(data.runId);
|
|
194
|
+
logger.debug(`sendCardStart: no chatId for run ${data.runId}, skip`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
const res = await this.cardNotifier.startWorkflow({
|
|
199
|
+
chatId: target.chatId,
|
|
200
|
+
profile: target.profile,
|
|
201
|
+
meta: this.buildWorkflowMeta(data),
|
|
202
|
+
totalNodes: data.totalNodes,
|
|
203
|
+
completedNodes: data.completedNodes ?? 0,
|
|
204
|
+
milestones: [
|
|
205
|
+
{
|
|
206
|
+
title: "Workflow 启动",
|
|
207
|
+
timestamp: new Date().toISOString(),
|
|
208
|
+
description: data.workflowName
|
|
209
|
+
}
|
|
210
|
+
]
|
|
211
|
+
});
|
|
212
|
+
this.cardMessageIds.set(data.runId, res.messageId);
|
|
213
|
+
logger.debug(`sendCardStart: run ${data.runId} → message ${res.messageId} ` + `(pinned=${res.pinned}) chat=${target.chatId}`);
|
|
214
|
+
} catch (err) {
|
|
215
|
+
this.cardMessageIds.set(data.runId, LarkCliWorkflowNotifyHook.CARD_START_FAILED_SENTINEL);
|
|
216
|
+
logger.error(`sendCardStart failed for run ${data.runId}: ${err.message}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
async patchCard(data, extra) {
|
|
220
|
+
if (!this.cardNotifier)
|
|
221
|
+
return;
|
|
222
|
+
const messageId = this.cardMessageIds.get(data.runId);
|
|
223
|
+
if (!messageId) {
|
|
224
|
+
logger.debug(`patchCard: no card for run ${data.runId}, skip`);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (messageId === LarkCliWorkflowNotifyHook.CARD_START_FAILED_SENTINEL || messageId === LarkCliWorkflowNotifyHook.CARD_START_INFLIGHT_SENTINEL) {
|
|
228
|
+
logger.debug(`patchCard: card not ready for run ${data.runId} (${messageId}), skip`);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const target = this.resolveTarget();
|
|
232
|
+
if (!target.chatId) {
|
|
233
|
+
logger.debug(`patchCard: no chatId for run ${data.runId}, skip`);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
try {
|
|
237
|
+
await this.cardNotifier.updateWorkflow({
|
|
238
|
+
messageId,
|
|
239
|
+
chatId: target.chatId,
|
|
240
|
+
profile: target.profile,
|
|
241
|
+
status: "running",
|
|
242
|
+
meta: this.buildWorkflowMeta(data),
|
|
243
|
+
completedNodes: data.completedNodes,
|
|
244
|
+
totalNodes: data.totalNodes,
|
|
245
|
+
currentNode: extra.currentNode,
|
|
246
|
+
currentNodeType: extra.currentNodeType,
|
|
247
|
+
milestones: extra.milestones,
|
|
248
|
+
processSteps: extra.processSteps
|
|
249
|
+
});
|
|
250
|
+
} catch (err) {
|
|
251
|
+
logger.error(`patchCard failed for run ${data.runId}: ${err.message}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
resolveTarget() {
|
|
255
|
+
const env = getEnvContextOrEmpty();
|
|
256
|
+
const rc = env.replyChannel;
|
|
257
|
+
return {
|
|
258
|
+
chatId: rc?.chatId,
|
|
259
|
+
profile: rc?.profile
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
buildWorkflowMeta(data) {
|
|
263
|
+
const run = data;
|
|
264
|
+
return {
|
|
265
|
+
runId: data.runId,
|
|
266
|
+
workflowName: data.workflowName,
|
|
267
|
+
workflowId: run.workflowId,
|
|
268
|
+
input: run.input
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
mapRunStatus(status) {
|
|
272
|
+
switch (String(status)) {
|
|
273
|
+
case "completed":
|
|
274
|
+
return "completed";
|
|
275
|
+
case "stopped":
|
|
276
|
+
return "stopped";
|
|
277
|
+
default:
|
|
278
|
+
return "failed";
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
shouldThrottleNodeStart(runId) {
|
|
282
|
+
const throttleMs = this.config.nodeThrottleMs ?? 3000;
|
|
283
|
+
if (throttleMs <= 0)
|
|
284
|
+
return false;
|
|
285
|
+
const key = `node:${runId}`;
|
|
286
|
+
const now = Date.now();
|
|
287
|
+
const last = this.lastNodeNotifyTimestamps.get(key);
|
|
288
|
+
if (last && now - last < throttleMs) {
|
|
289
|
+
logger.debug(`[throttle] skip before.node patch for run ${runId} (${now - last}ms ago)`);
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
this.lastNodeNotifyTimestamps.set(key, now);
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
__legacyDecorateClassTS([
|
|
297
|
+
TracedAs("lark-cli-workflow-notify.execute")
|
|
298
|
+
], LarkCliWorkflowNotifyHook.prototype, "execute", null);
|
|
299
|
+
function createLarkCliWorkflowNotifyHook(config = {}) {
|
|
300
|
+
return new LarkCliWorkflowNotifyHook(config);
|
|
301
|
+
}
|
|
302
|
+
export { LarkCliWorkflowNotifyHook, createLarkCliWorkflowNotifyHook };
|
|
@@ -2,6 +2,10 @@ import {
|
|
|
2
2
|
MemorySessionStore,
|
|
3
3
|
SQLiteSessionStore
|
|
4
4
|
} from "./roy-agent-core-h93v6p6y.js";
|
|
5
|
+
import {
|
|
6
|
+
init_loose_json,
|
|
7
|
+
tryParseJsonFromText
|
|
8
|
+
} from "./roy-agent-core-ze068vc9.js";
|
|
5
9
|
import {
|
|
6
10
|
init_search_query_parser,
|
|
7
11
|
matchesQuery,
|
|
@@ -12,11 +16,11 @@ import {
|
|
|
12
16
|
} from "./roy-agent-core-7hh0brvs.js";
|
|
13
17
|
import {
|
|
14
18
|
BaseComponent
|
|
15
|
-
} from "./roy-agent-core-
|
|
19
|
+
} from "./roy-agent-core-tdbv7ff4.js";
|
|
16
20
|
import {
|
|
17
21
|
TracedAs,
|
|
18
22
|
init_decorator
|
|
19
|
-
} from "./roy-agent-core-
|
|
23
|
+
} from "./roy-agent-core-dsevjbck.js";
|
|
20
24
|
import {
|
|
21
25
|
createLogger,
|
|
22
26
|
init_logger
|
|
@@ -63,9 +67,50 @@ var SESSION_CONFIG_REGISTRATION = {
|
|
|
63
67
|
|
|
64
68
|
// src/env/session/session-component.ts
|
|
65
69
|
init_search_query_parser();
|
|
70
|
+
init_loose_json();
|
|
66
71
|
import path from "path";
|
|
67
72
|
import { z } from "zod";
|
|
68
73
|
var logger = createLogger("session");
|
|
74
|
+
function normalizeAgentCheckpoint(data) {
|
|
75
|
+
return {
|
|
76
|
+
title: data.title || "Untitled Checkpoint",
|
|
77
|
+
processKeyPoints: data.processKeyPoints || [],
|
|
78
|
+
currentState: data.currentState || "",
|
|
79
|
+
nextSteps: data.nextSteps || [],
|
|
80
|
+
userIntents: data.userIntents || [],
|
|
81
|
+
rawResponse: JSON.stringify(data)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
var DEGRADED_TEXT_SENTINELS = new Set([
|
|
85
|
+
"[hint extraction failed]"
|
|
86
|
+
]);
|
|
87
|
+
function isUsableCheckpointText(text) {
|
|
88
|
+
const raw = (text ?? "").trim();
|
|
89
|
+
if (!raw)
|
|
90
|
+
return false;
|
|
91
|
+
return !DEGRADED_TEXT_SENTINELS.has(raw.toLowerCase());
|
|
92
|
+
}
|
|
93
|
+
function buildCheckpointFromFinalText(finalText) {
|
|
94
|
+
if (!isUsableCheckpointText(finalText))
|
|
95
|
+
return;
|
|
96
|
+
const raw = finalText.trim();
|
|
97
|
+
const parsed = tryParseJsonFromText(raw);
|
|
98
|
+
if (parsed && (parsed.title || parsed.currentState || parsed.processKeyPoints)) {
|
|
99
|
+
return normalizeAgentCheckpoint(parsed);
|
|
100
|
+
}
|
|
101
|
+
const lines = raw.split(`
|
|
102
|
+
`).map((l) => l.trim()).filter(Boolean);
|
|
103
|
+
const heading = lines.find((l) => /^#{1,6}\s+/.test(l)) ?? lines[0] ?? "";
|
|
104
|
+
const title = heading.replace(/^#{1,6}\s+/, "").replace(/^[*_`\s]+|[*_`\s]+$/g, "").slice(0, 80);
|
|
105
|
+
return {
|
|
106
|
+
title: title || "Untitled Checkpoint",
|
|
107
|
+
processKeyPoints: [],
|
|
108
|
+
currentState: raw,
|
|
109
|
+
nextSteps: [],
|
|
110
|
+
userIntents: [],
|
|
111
|
+
rawResponse: raw
|
|
112
|
+
};
|
|
113
|
+
}
|
|
69
114
|
function sleep(ms) {
|
|
70
115
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
71
116
|
}
|
|
@@ -598,7 +643,10 @@ class SessionComponent extends BaseComponent {
|
|
|
598
643
|
persistSession: false,
|
|
599
644
|
extraTools: [submitTool]
|
|
600
645
|
});
|
|
601
|
-
const hint = hintData?.guidance_prompt || "
|
|
646
|
+
const hint = hintData?.guidance_prompt || "";
|
|
647
|
+
if (!hint) {
|
|
648
|
+
logger.warn("[SessionComponent] Compact hint unavailable (compact-hint did not submit) — returning empty hint", { sessionId });
|
|
649
|
+
}
|
|
602
650
|
logger.info("[SessionComponent] Compact hint generated", {
|
|
603
651
|
sessionId,
|
|
604
652
|
hintLength: hint.length
|
|
@@ -646,20 +694,26 @@ class SessionComponent extends BaseComponent {
|
|
|
646
694
|
}
|
|
647
695
|
};
|
|
648
696
|
const agentComponent = this.env.getComponent("agent");
|
|
649
|
-
await agentComponent.run("compact", userQuery, {
|
|
697
|
+
const runResult = await agentComponent.run("compact", userQuery, {
|
|
650
698
|
sessionId,
|
|
651
699
|
persistSession: false,
|
|
652
700
|
extraTools: [submitTool]
|
|
653
701
|
});
|
|
654
|
-
const data = checkpointData
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
702
|
+
const data = checkpointData;
|
|
703
|
+
if (data) {
|
|
704
|
+
summaryResult = normalizeAgentCheckpoint(data);
|
|
705
|
+
} else {
|
|
706
|
+
const fallback = buildCheckpointFromFinalText(runResult?.finalText) ?? buildCheckpointFromFinalText(options?.scenarioHint);
|
|
707
|
+
if (!fallback) {
|
|
708
|
+
throw new Error(`compact agent returned no usable checkpoint output ` + `(no workflow_submit_output call, no usable finalText or scenarioHint); ` + `refusing to archive ${messages.length} messages for session ${sessionId}`);
|
|
709
|
+
}
|
|
710
|
+
if (runResult?.finalText?.trim()) {
|
|
711
|
+
logger.warn(`[SessionComponent] compact agent did not call workflow_submit_output; ` + `falling back to its finalText for the checkpoint (session=${sessionId}, ` + `finalTextLength=${runResult.finalText.length})`);
|
|
712
|
+
} else {
|
|
713
|
+
logger.warn(`[SessionComponent] compact agent produced neither a tool call nor text; ` + `falling back to scenarioHint for the checkpoint (session=${sessionId})`);
|
|
714
|
+
}
|
|
715
|
+
summaryResult = fallback;
|
|
716
|
+
}
|
|
663
717
|
} catch (error) {
|
|
664
718
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
665
719
|
logger.error(`[SessionComponent] Compact agent failed: ${errorMessage}`);
|
|
@@ -744,6 +798,15 @@ class SessionComponent extends BaseComponent {
|
|
|
744
798
|
i--;
|
|
745
799
|
}
|
|
746
800
|
}
|
|
801
|
+
if (recentMessages.length === 0) {
|
|
802
|
+
const FALLBACK_MESSAGE_LIMIT = 6;
|
|
803
|
+
const tail = messages.filter((m) => !m.metadata?.isCheckpoint).slice(-FALLBACK_MESSAGE_LIMIT).filter((m) => typeof m.content === "string" && m.content.trim()).map((m) => ({ role: m.role, content: m.content }));
|
|
804
|
+
logger.debug("[SessionComponent] extractRecentMessages fell back to raw tail", {
|
|
805
|
+
turnCount,
|
|
806
|
+
fallbackMessages: tail.length
|
|
807
|
+
});
|
|
808
|
+
return tail;
|
|
809
|
+
}
|
|
747
810
|
logger.debug("[SessionComponent] Extracted recent messages", {
|
|
748
811
|
turnCount,
|
|
749
812
|
messagesExtracted: recentMessages.length
|