@ai-setting/roy-agent-core 1.5.88 → 1.5.90
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/env/agent/index.js +8 -8
- package/dist/env/event-source/index.js +12 -4
- package/dist/env/index.js +20 -15
- package/dist/env/llm/index.js +4 -2
- package/dist/env/prompt/index.js +2 -1
- package/dist/env/session/index.js +3 -4
- package/dist/env/session/storage/index.js +2 -2
- package/dist/env/task/delegate/index.js +3 -2
- package/dist/env/task/index.js +4 -3
- package/dist/env/task/plugins/index.js +7 -4
- package/dist/env/tool/built-in/index.js +2 -1
- package/dist/env/tool/index.js +11 -8
- package/dist/env/workflow/engine/index.js +5 -3
- package/dist/env/workflow/index.js +6 -4
- package/dist/env/workflow/nodes/index.js +1 -1
- package/dist/env/workflow/tools/index.js +7 -1
- package/dist/env/workflow/utils/index.js +5 -0
- package/dist/index.js +144 -32
- package/dist/shared/@ai-setting/{roy-agent-core-r0m0at3x.js → roy-agent-core-0r4ndyn9.js} +119 -7
- package/dist/shared/@ai-setting/{roy-agent-core-jymz9fzp.js → roy-agent-core-2c8eraxq.js} +126 -41
- package/dist/shared/@ai-setting/{roy-agent-core-0y64qaac.js → roy-agent-core-32m0nb9j.js} +119 -30
- package/dist/shared/@ai-setting/roy-agent-core-4yq23m5g.js +421 -0
- package/dist/shared/@ai-setting/{roy-agent-core-h2d1s8yd.js → roy-agent-core-5ykms33a.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-mmkyydw7.js → roy-agent-core-83d035pp.js} +91 -579
- package/dist/shared/@ai-setting/roy-agent-core-8wd3qwx5.js +35 -0
- package/dist/shared/@ai-setting/{roy-agent-core-yx0vw1aw.js → roy-agent-core-8zjntsbb.js} +102 -32
- package/dist/shared/@ai-setting/{roy-agent-core-29fh9mxg.js → roy-agent-core-bwjpte58.js} +1 -2
- package/dist/shared/@ai-setting/{roy-agent-core-vneyghpg.js → roy-agent-core-ddq5hcp5.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-qhhxx2x2.js → roy-agent-core-ds5f75pg.js} +2 -1
- package/dist/shared/@ai-setting/{roy-agent-core-4cdtdxqx.js → roy-agent-core-ewr1nw7t.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-hvdfgvfz.js +114 -0
- package/dist/shared/@ai-setting/{roy-agent-core-3arrpf7n.js → roy-agent-core-hxsbegfc.js} +229 -9
- package/dist/shared/@ai-setting/{roy-agent-core-9y09xfav.js → roy-agent-core-j0107ww1.js} +6 -418
- package/dist/shared/@ai-setting/{roy-agent-core-6mk0m4t3.js → roy-agent-core-m683wd1n.js} +283 -15
- package/dist/shared/@ai-setting/{roy-agent-core-bgw4dq11.js → roy-agent-core-mw4ty0ba.js} +44 -5
- package/dist/shared/@ai-setting/{roy-agent-core-7z4xtrmw.js → roy-agent-core-nqzt9ne4.js} +53 -0
- package/dist/shared/@ai-setting/roy-agent-core-pt7as39r.js +0 -0
- package/dist/shared/@ai-setting/{roy-agent-core-6n7xwv4v.js → roy-agent-core-rkz8r2sx.js} +5 -3
- package/dist/shared/@ai-setting/{roy-agent-core-c1j7ev4e.js → roy-agent-core-txwf64pd.js} +70 -0
- package/dist/shared/@ai-setting/{roy-agent-core-7fdzfsm6.js → roy-agent-core-w0kb72ve.js} +42 -213
- package/dist/shared/@ai-setting/roy-agent-core-w6bmrgap.js +581 -0
- package/dist/shared/@ai-setting/{roy-agent-core-qhjb153z.js → roy-agent-core-xnxyzaw4.js} +27 -4
- package/dist/shared/@ai-setting/roy-agent-core-yanpq5gb.js +116 -0
- package/dist/shared/@ai-setting/{roy-agent-core-hc20420t.js → roy-agent-core-z240ts1r.js} +27 -3
- package/dist/shared/@ai-setting/{roy-agent-core-q7sqeax6.js → roy-agent-core-zky9jse4.js} +163 -3
- package/package.json +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-x3gtyqax.js +0 -378
- /package/dist/shared/@ai-setting/{roy-agent-core-4f3976cd.js → roy-agent-core-k5hxvaf0.js} +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DAGManager,
|
|
3
|
+
init_dag_manager
|
|
4
|
+
} from "./roy-agent-core-4yq23m5g.js";
|
|
5
|
+
|
|
6
|
+
// src/env/workflow/utils/validate-workflow-definition.ts
|
|
7
|
+
init_dag_manager();
|
|
8
|
+
function validateWorkflowDefinition(definition) {
|
|
9
|
+
if (!definition || typeof definition !== "object") {
|
|
10
|
+
return {
|
|
11
|
+
valid: false,
|
|
12
|
+
errors: ["Workflow definition must be an object"]
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const def = definition;
|
|
16
|
+
if (!Array.isArray(def.nodes)) {
|
|
17
|
+
return {
|
|
18
|
+
valid: false,
|
|
19
|
+
errors: ["Workflow definition must have a 'nodes' array"]
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const dag = new DAGManager(definition, { allowCycles: false });
|
|
24
|
+
return dag.validate();
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return {
|
|
27
|
+
valid: false,
|
|
28
|
+
errors: [
|
|
29
|
+
`Validation error: ${error instanceof Error ? error.message : String(error)}`
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { validateWorkflowDefinition };
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
withTimeout
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-0r4ndyn9.js";
|
|
4
|
+
import {
|
|
5
|
+
truncateOutputInline
|
|
6
|
+
} from "./roy-agent-core-hxsbegfc.js";
|
|
4
7
|
import {
|
|
5
8
|
AskUserError,
|
|
6
9
|
init_workflow_hil
|
|
7
10
|
} from "./roy-agent-core-e25xkv53.js";
|
|
8
11
|
import {
|
|
9
12
|
AgentRegistry
|
|
10
|
-
} from "./roy-agent-core-
|
|
13
|
+
} from "./roy-agent-core-nqzt9ne4.js";
|
|
11
14
|
import {
|
|
12
15
|
ContextError
|
|
13
16
|
} from "./roy-agent-core-ctdhjv68.js";
|
|
14
17
|
import {
|
|
15
18
|
SessionMessageConverter
|
|
16
|
-
} from "./roy-agent-core-
|
|
19
|
+
} from "./roy-agent-core-txwf64pd.js";
|
|
17
20
|
import {
|
|
18
21
|
safeParseToolArgs
|
|
19
22
|
} from "./roy-agent-core-ce10b0ez.js";
|
|
@@ -112,23 +115,53 @@ function toLLMMessage(msg) {
|
|
|
112
115
|
toolName = toolResult?.toolName;
|
|
113
116
|
} else {
|
|
114
117
|
const toolCallParts = msg.content.filter((part) => part.type === "tool-call");
|
|
115
|
-
const
|
|
116
|
-
|
|
118
|
+
const hasMultimodalPart = msg.content.some((part) => part.type === "image" || part.type === "file");
|
|
119
|
+
if (hasMultimodalPart) {
|
|
120
|
+
const llmContentParts = [];
|
|
121
|
+
for (const part of msg.content) {
|
|
122
|
+
if (part.type === "text") {
|
|
123
|
+
llmContentParts.push({ type: "text", text: part.text || "" });
|
|
124
|
+
} else if (part.type === "image") {
|
|
125
|
+
llmContentParts.push({ type: "image", image: part.image });
|
|
126
|
+
} else if (part.type === "file") {
|
|
127
|
+
llmContentParts.push({
|
|
128
|
+
type: "file",
|
|
129
|
+
file: part.data ?? part.file,
|
|
130
|
+
mediaType: part.mediaType || "application/octet-stream"
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (msg.role === "assistant" && toolCallParts.length > 0) {
|
|
135
|
+
for (const part of toolCallParts) {
|
|
136
|
+
const argsString = typeof part.input === "string" ? part.input : JSON.stringify(part.input || {});
|
|
137
|
+
toolCalls = (toolCalls ?? []).concat([{
|
|
138
|
+
id: part.toolCallId,
|
|
139
|
+
name: part.toolName || "unknown",
|
|
140
|
+
arguments: argsString,
|
|
141
|
+
function: { name: part.toolName || "unknown", arguments: argsString }
|
|
142
|
+
}]);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
content = llmContentParts;
|
|
146
|
+
} else {
|
|
147
|
+
const contentParts = msg.content.filter((part) => part.type === "text").map((part) => part.text || "");
|
|
148
|
+
content = contentParts.join(`
|
|
117
149
|
`);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
name: toolName2,
|
|
125
|
-
arguments: argsString,
|
|
126
|
-
function: {
|
|
150
|
+
if (msg.role === "assistant" && toolCallParts.length > 0) {
|
|
151
|
+
toolCalls = toolCallParts.map((part) => {
|
|
152
|
+
const argsString = typeof part.input === "string" ? part.input : JSON.stringify(part.input || {});
|
|
153
|
+
const toolName2 = part.toolName || "unknown";
|
|
154
|
+
return {
|
|
155
|
+
id: part.toolCallId,
|
|
127
156
|
name: toolName2,
|
|
128
|
-
arguments: argsString
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
157
|
+
arguments: argsString,
|
|
158
|
+
function: {
|
|
159
|
+
name: toolName2,
|
|
160
|
+
arguments: argsString
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
}
|
|
132
165
|
}
|
|
133
166
|
}
|
|
134
167
|
} else {
|
|
@@ -303,6 +336,12 @@ class AgentComponent extends BaseComponent {
|
|
|
303
336
|
logger.info("[AgentComponent] Registered built-in workflow-agent");
|
|
304
337
|
this.registry.registerJsonExtractAgent();
|
|
305
338
|
logger.info("[AgentComponent] Registered built-in json-extract agent");
|
|
339
|
+
this.registry.registerWorkflowExtractAgent();
|
|
340
|
+
logger.info("[AgentComponent] Registered built-in workflow-extract agent");
|
|
341
|
+
this.registry.registerCompactAgent();
|
|
342
|
+
logger.info("[AgentComponent] Registered built-in compact agent");
|
|
343
|
+
this.registry.registerCompactHintAgent();
|
|
344
|
+
logger.info("[AgentComponent] Registered built-in compact-hint agent");
|
|
306
345
|
for (const agentDef of this.registry.list()) {
|
|
307
346
|
if (!this.agents.has(agentDef.name)) {
|
|
308
347
|
const systemPrompt = await this.registry.getSystemPrompt(agentDef.name);
|
|
@@ -504,7 +543,7 @@ class AgentComponent extends BaseComponent {
|
|
|
504
543
|
const allowedTools = context?.allowedTools ?? agent.config.allowedTools;
|
|
505
544
|
const deniedTools = context?.deniedTools ?? agent.config.deniedTools;
|
|
506
545
|
logger.debug(`[getAvailableTools] Filtering: allowed=${allowedTools}, denied=${deniedTools}`);
|
|
507
|
-
if (allowedTools
|
|
546
|
+
if (allowedTools !== undefined && allowedTools !== null) {
|
|
508
547
|
tools = tools.filter((t) => allowedTools.includes(t.name));
|
|
509
548
|
logger.debug(`[getAvailableTools] After allowedTools filter: ${tools.length} tools`, {
|
|
510
549
|
toolNames: tools.map((t) => t.name)
|
|
@@ -541,7 +580,8 @@ class AgentComponent extends BaseComponent {
|
|
|
541
580
|
throw new Error(`Agent not found: ${agentName}`);
|
|
542
581
|
}
|
|
543
582
|
const runId = `${agentName}:${++this.runCounter}`;
|
|
544
|
-
|
|
583
|
+
const querySummary = typeof query === "string" ? query.substring(0, 100) : query.filter((p) => p.type === "text").map((p) => p.text).join(" ").substring(0, 100) || "[multimodal query]";
|
|
584
|
+
logger.info(`Starting agent run: ${agentName} (runId=${runId})`, { query: querySummary });
|
|
545
585
|
agent.status = "running";
|
|
546
586
|
this.aborted.set(runId, false);
|
|
547
587
|
const abortController = new AbortController;
|
|
@@ -550,24 +590,25 @@ class AgentComponent extends BaseComponent {
|
|
|
550
590
|
this.doomLoopCaches.set(runId, new Map);
|
|
551
591
|
}
|
|
552
592
|
await this.resolveSystemPrompt(agent, agentName);
|
|
593
|
+
let resolvedSystemPrompt;
|
|
553
594
|
if (agent.config.systemPrompt) {
|
|
554
|
-
|
|
555
|
-
if (
|
|
595
|
+
resolvedSystemPrompt = agent.config.systemPrompt;
|
|
596
|
+
if (resolvedSystemPrompt.includes("{{workspace_dir}}")) {
|
|
556
597
|
const workspaceDir = this.env?.getComponent?.("config")?.get?.("workspace_dir") || process.cwd();
|
|
557
|
-
|
|
598
|
+
resolvedSystemPrompt = resolvedSystemPrompt.replaceAll("{{workspace_dir}}", String(workspaceDir));
|
|
558
599
|
}
|
|
559
|
-
if (
|
|
600
|
+
if (resolvedSystemPrompt.includes("{{memory}}")) {
|
|
560
601
|
try {
|
|
561
602
|
const memoryComponent = this.env?.getComponent?.("memory");
|
|
562
603
|
if (memoryComponent && typeof memoryComponent.recallMemory === "function") {
|
|
563
604
|
const memoryContent = await memoryComponent.recallMemory();
|
|
564
|
-
|
|
605
|
+
resolvedSystemPrompt = resolvedSystemPrompt.replaceAll("{{memory}}", memoryContent || "(No memory)");
|
|
565
606
|
} else {
|
|
566
|
-
|
|
607
|
+
resolvedSystemPrompt = resolvedSystemPrompt.replaceAll("{{memory}}", "(Memory component not available)");
|
|
567
608
|
}
|
|
568
609
|
} catch (err) {
|
|
569
610
|
logger.warn(`[AgentComponent._run] Failed to replace {{memory}}: ${err}`);
|
|
570
|
-
|
|
611
|
+
resolvedSystemPrompt = resolvedSystemPrompt.replaceAll("{{memory}}", "(Failed to load memory)");
|
|
571
612
|
}
|
|
572
613
|
}
|
|
573
614
|
}
|
|
@@ -588,7 +629,7 @@ class AgentComponent extends BaseComponent {
|
|
|
588
629
|
maxIterations: agent.config.maxIterations,
|
|
589
630
|
messages: [],
|
|
590
631
|
tools: this.getAvailableTools(agent, effectiveContext),
|
|
591
|
-
systemPrompt: agent.config.systemPrompt
|
|
632
|
+
systemPrompt: resolvedSystemPrompt ?? agent.config.systemPrompt ?? "You are a helpful assistant.",
|
|
592
633
|
context: effectiveContext
|
|
593
634
|
};
|
|
594
635
|
let historyMessageCount = 0;
|
|
@@ -960,6 +1001,7 @@ class AgentComponent extends BaseComponent {
|
|
|
960
1001
|
}
|
|
961
1002
|
this.aborted.delete(runId);
|
|
962
1003
|
this.abortControllers.delete(runId);
|
|
1004
|
+
this.doomLoopCaches.delete(runId);
|
|
963
1005
|
if (result.error) {
|
|
964
1006
|
this.pushEnvEvent({
|
|
965
1007
|
type: "agent.error",
|
|
@@ -1062,7 +1104,8 @@ ${additionInfo}`
|
|
|
1062
1104
|
sessionId: ctx.context.sessionId,
|
|
1063
1105
|
messageId: ctx.context.messageId
|
|
1064
1106
|
},
|
|
1065
|
-
abortSignal: ctx.context.abort
|
|
1107
|
+
abortSignal: ctx.context.abort,
|
|
1108
|
+
skipThresholdCheck: ctx.context.agentType === "sub"
|
|
1066
1109
|
});
|
|
1067
1110
|
const result = await withTimeout(llmPromise, 300000, "LLM invocation timeout after 300s");
|
|
1068
1111
|
logger.debug("[invokeLLM] LLMComponent.invoke returned successfully");
|
|
@@ -1148,6 +1191,7 @@ ${additionInfo}`
|
|
|
1148
1191
|
} else {
|
|
1149
1192
|
result = await withTimeout(toolPromise, 120000, `Tool '${toolName}' execution timeout after 120s`);
|
|
1150
1193
|
}
|
|
1194
|
+
result = truncateOutputInline(result, undefined, undefined, toolName);
|
|
1151
1195
|
} else if (this.toolComponent?.execute) {
|
|
1152
1196
|
const toolPromise = this.toolComponent.execute(request);
|
|
1153
1197
|
if (isLongRunningTool) {
|
|
@@ -1163,6 +1207,7 @@ ${additionInfo}`
|
|
|
1163
1207
|
} else {
|
|
1164
1208
|
result = await withTimeout(toolPromise, 120000, `Tool '${toolName}' execution timeout after 120s`);
|
|
1165
1209
|
}
|
|
1210
|
+
result = truncateOutputInline(result, undefined, undefined, toolName);
|
|
1166
1211
|
}
|
|
1167
1212
|
this.pushEnvEvent({
|
|
1168
1213
|
type: "tool.result",
|
|
@@ -1280,6 +1325,7 @@ ${additionInfo}`
|
|
|
1280
1325
|
logger.warn("SessionComponent not found, skipping session recording");
|
|
1281
1326
|
return;
|
|
1282
1327
|
}
|
|
1328
|
+
const filtered2 = [];
|
|
1283
1329
|
for (const msg of allMessages) {
|
|
1284
1330
|
if (msg.role === "system") {
|
|
1285
1331
|
continue;
|
|
@@ -1292,10 +1338,19 @@ ${additionInfo}`
|
|
|
1292
1338
|
continue;
|
|
1293
1339
|
}
|
|
1294
1340
|
}
|
|
1295
|
-
|
|
1341
|
+
filtered2.push(this.messageConverter.fromModelMessage(msg, { sessionID: sessionId }));
|
|
1342
|
+
}
|
|
1343
|
+
if (filtered2.length === 0) {
|
|
1344
|
+
return;
|
|
1296
1345
|
}
|
|
1346
|
+
await sessionComponent.addMessages(sessionId, filtered2);
|
|
1297
1347
|
} catch (err) {
|
|
1298
|
-
|
|
1348
|
+
const kind = err && typeof err === "object" && "kind" in err ? err.kind : undefined;
|
|
1349
|
+
if (kind === "lock_exhausted") {
|
|
1350
|
+
logger.error(`[recordSessionMessages] DROPPED ${filtered?.length ?? "?"} message(s) — SQLITE_BUSY retry exhausted after ${err.attempts ?? "?"} attempts. Session ${sessionId} is now inconsistent with LLM context. Original: ${err}`);
|
|
1351
|
+
} else {
|
|
1352
|
+
logger.error(`[recordSessionMessages] Failed to record session messages for ${sessionId}: ${err}`);
|
|
1353
|
+
}
|
|
1299
1354
|
}
|
|
1300
1355
|
}
|
|
1301
1356
|
isEmptyMessage(content) {
|
|
@@ -1375,4 +1430,19 @@ __legacyDecorateClassTS([
|
|
|
1375
1430
|
__legacyDecorateClassTS([
|
|
1376
1431
|
TracedAs("agent.component.getConversationHistory", { recordParams: true, recordResult: true, log: true })
|
|
1377
1432
|
], AgentComponent.prototype, "getConversationHistory", null);
|
|
1378
|
-
|
|
1433
|
+
// src/env/agent/summary-agent.ts
|
|
1434
|
+
class SummaryAgent {
|
|
1435
|
+
llmComponent;
|
|
1436
|
+
config;
|
|
1437
|
+
constructor(_promptComponent, llmComponent, config) {
|
|
1438
|
+
this.llmComponent = llmComponent;
|
|
1439
|
+
this.config = {
|
|
1440
|
+
type: "summary",
|
|
1441
|
+
promptName: "session/compact",
|
|
1442
|
+
maxIterations: 1,
|
|
1443
|
+
model: undefined,
|
|
1444
|
+
...config
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
export { AgentComponentConfigSchema, AgentComponent, SummaryAgent };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createAutoTaskPlugin
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-yanpq5gb.js";
|
|
4
4
|
import {
|
|
5
5
|
ContextError,
|
|
6
6
|
ErrorCodes
|
|
@@ -158,7 +158,6 @@ class BaseEnvironment extends BaseComponent {
|
|
|
158
158
|
"echo",
|
|
159
159
|
"glob",
|
|
160
160
|
"grep",
|
|
161
|
-
"read_file",
|
|
162
161
|
"write_file",
|
|
163
162
|
"edit_file",
|
|
164
163
|
"task_create",
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// src/env/task/delegate/process-registry.ts
|
|
2
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
3
|
+
|
|
4
|
+
// src/util/process/process-tree-killer.ts
|
|
5
|
+
import { spawn as _childProcessSpawn } from "child_process";
|
|
6
|
+
var spawnInjector;
|
|
7
|
+
function spawn(cmd, args, opts) {
|
|
8
|
+
if (spawnInjector)
|
|
9
|
+
return spawnInjector(cmd, args, opts);
|
|
10
|
+
return _childProcessSpawn(cmd, args, opts);
|
|
11
|
+
}
|
|
12
|
+
var platformOverride;
|
|
13
|
+
function currentPlatform() {
|
|
14
|
+
return platformOverride ?? process.platform;
|
|
15
|
+
}
|
|
16
|
+
function killProcessTree(pid, options) {
|
|
17
|
+
if (!Number.isInteger(pid) || pid <= 0) {
|
|
18
|
+
throw new Error(`Invalid PID: ${pid} (must be a positive integer)`);
|
|
19
|
+
}
|
|
20
|
+
const platform = currentPlatform();
|
|
21
|
+
const signal = options?.signal ?? "SIGKILL";
|
|
22
|
+
if (platform === "win32") {
|
|
23
|
+
return killOnWindows(pid);
|
|
24
|
+
}
|
|
25
|
+
return killOnPosix(pid, signal);
|
|
26
|
+
}
|
|
27
|
+
function killOnWindows(pid) {
|
|
28
|
+
try {
|
|
29
|
+
spawn("taskkill", ["/pid", String(pid), "/f", "/t"], {
|
|
30
|
+
stdio: "ignore",
|
|
31
|
+
windowsHide: true
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
pid,
|
|
35
|
+
platform: "win32",
|
|
36
|
+
signal: "taskkill /f /t",
|
|
37
|
+
success: true
|
|
38
|
+
};
|
|
39
|
+
} catch {
|
|
40
|
+
return {
|
|
41
|
+
pid,
|
|
42
|
+
platform: "win32",
|
|
43
|
+
signal: "taskkill /f /t",
|
|
44
|
+
success: false
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function killOnPosix(pid, signal) {
|
|
49
|
+
const platform = currentPlatform();
|
|
50
|
+
try {
|
|
51
|
+
process.kill(-pid, signal);
|
|
52
|
+
return {
|
|
53
|
+
pid,
|
|
54
|
+
platform,
|
|
55
|
+
signal,
|
|
56
|
+
success: true
|
|
57
|
+
};
|
|
58
|
+
} catch (err) {
|
|
59
|
+
const code = err.code;
|
|
60
|
+
if (code === "ESRCH" || code === "EPERM") {
|
|
61
|
+
return {
|
|
62
|
+
pid,
|
|
63
|
+
platform,
|
|
64
|
+
signal,
|
|
65
|
+
success: true
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
pid,
|
|
70
|
+
platform,
|
|
71
|
+
signal,
|
|
72
|
+
success: false
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/env/task/delegate/process-registry.ts
|
|
78
|
+
class ProcessRegistry {
|
|
79
|
+
pids = new Set;
|
|
80
|
+
register(pid) {
|
|
81
|
+
if (!Number.isInteger(pid) || pid <= 0) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.pids.add(pid);
|
|
85
|
+
}
|
|
86
|
+
unregister(pid) {
|
|
87
|
+
if (!Number.isInteger(pid)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
this.pids.delete(pid);
|
|
91
|
+
}
|
|
92
|
+
size() {
|
|
93
|
+
return this.pids.size;
|
|
94
|
+
}
|
|
95
|
+
killAll() {
|
|
96
|
+
if (this.pids.size === 0)
|
|
97
|
+
return;
|
|
98
|
+
for (const pid of Array.from(this.pids)) {
|
|
99
|
+
try {
|
|
100
|
+
killProcessTree(pid);
|
|
101
|
+
} catch {}
|
|
102
|
+
}
|
|
103
|
+
this.pids.clear();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
var processRegistryStorage = new AsyncLocalStorage;
|
|
107
|
+
function runWithProcessRegistryAsync(registry, fn) {
|
|
108
|
+
return processRegistryStorage.run(registry, fn);
|
|
109
|
+
}
|
|
110
|
+
function getCurrentProcessRegistry() {
|
|
111
|
+
return processRegistryStorage.getStore();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { killProcessTree, ProcessRegistry, runWithProcessRegistryAsync, getCurrentProcessRegistry };
|