plugin-agent-orchestrator 1.0.16 → 1.0.18
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/client/AgentRunsTab.d.ts +2 -0
- package/dist/client/HarnessProfilesTab.d.ts +2 -0
- package/dist/client/index.js +1 -1
- package/dist/client/skill-hub/components/LoopSettings.d.ts +2 -0
- package/dist/client/skill-hub/index.d.ts +2 -1
- package/dist/client/skill-hub/tools/InteractionSchemasProvider.d.ts +1 -14
- package/dist/client/skill-hub/tools/loopTemplates.d.ts +22 -0
- package/dist/client/skill-hub/tools/registerSkillLoopCards.d.ts +1 -0
- package/dist/client/tools/PlanApprovalCard.d.ts +3 -0
- package/dist/client/tools/registerOrchestratorCards.d.ts +1 -0
- package/dist/externalVersion.js +6 -6
- package/dist/server/collections/agent-harness-profiles.d.ts +2 -0
- package/dist/server/collections/agent-harness-profiles.js +89 -0
- package/dist/server/collections/agent-loop-events.d.ts +2 -0
- package/dist/server/collections/agent-loop-events.js +101 -0
- package/dist/server/collections/agent-loop-runs.d.ts +2 -0
- package/dist/server/collections/agent-loop-runs.js +188 -0
- package/dist/server/collections/agent-loop-steps.d.ts +2 -0
- package/dist/server/collections/agent-loop-steps.js +174 -0
- package/dist/server/collections/orchestrator-config.js +7 -0
- package/dist/server/collections/skill-executions.js +12 -0
- package/dist/server/collections/skill-loop-configs.d.ts +3 -0
- package/dist/server/collections/skill-loop-configs.js +94 -0
- package/dist/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.d.ts +7 -0
- package/dist/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.js +55 -0
- package/dist/server/migrations/20260524001000-add-plan-approval-and-harness-profiles.d.ts +12 -0
- package/dist/server/migrations/20260524001000-add-plan-approval-and-harness-profiles.js +162 -0
- package/dist/server/plugin.d.ts +2 -0
- package/dist/server/plugin.js +13 -0
- package/dist/server/resources/agent-loop.d.ts +3 -0
- package/dist/server/resources/agent-loop.js +205 -0
- package/dist/server/services/AgentHarness.d.ts +42 -0
- package/dist/server/services/AgentHarness.js +565 -0
- package/dist/server/services/AgentLoopController.d.ts +205 -0
- package/dist/server/services/AgentLoopController.js +940 -0
- package/dist/server/services/AgentLoopRepository.d.ts +20 -0
- package/dist/server/services/AgentLoopRepository.js +210 -0
- package/dist/server/services/AgentLoopService.d.ts +149 -0
- package/dist/server/services/AgentLoopService.js +133 -0
- package/dist/server/services/AgentPlanValidator.d.ts +4 -0
- package/dist/server/services/AgentPlanValidator.js +99 -0
- package/dist/server/services/AgentPlannerService.d.ts +8 -0
- package/dist/server/services/AgentPlannerService.js +119 -0
- package/dist/server/services/AgentRegistryService.d.ts +13 -0
- package/dist/server/services/AgentRegistryService.js +178 -0
- package/dist/server/services/ExecutionSpanService.d.ts +2 -0
- package/dist/server/skill-hub/plugin.d.ts +3 -0
- package/dist/server/skill-hub/plugin.js +137 -54
- package/dist/server/tools/agent-loop.d.ts +235 -0
- package/dist/server/tools/agent-loop.js +406 -0
- package/dist/server/tools/delegate-task.js +37 -350
- package/dist/server/tools/orchestrator-plan.d.ts +205 -0
- package/dist/server/tools/orchestrator-plan.js +291 -0
- package/dist/server/tools/skill-execute.js +2 -0
- package/package.json +2 -2
- package/src/client/AgentRunsTab.tsx +764 -0
- package/src/client/HarnessProfilesTab.tsx +247 -0
- package/src/client/OrchestratorSettings.tsx +40 -2
- package/src/client/RulesTab.tsx +103 -6
- package/src/client/plugin.tsx +27 -54
- package/src/client/skill-hub/components/LoopSettings.tsx +331 -0
- package/src/client/skill-hub/index.tsx +51 -75
- package/src/client/skill-hub/tools/InteractionSchemasProvider.tsx +56 -16
- package/src/client/skill-hub/tools/SkillHubCard.tsx +35 -4
- package/src/client/skill-hub/tools/loopTemplates.ts +52 -0
- package/src/client/skill-hub/tools/registerSkillLoopCards.ts +58 -0
- package/src/client/tools/PlanApprovalCard.tsx +175 -0
- package/src/client/tools/registerOrchestratorCards.ts +7 -0
- package/src/server/collections/agent-harness-profiles.ts +59 -0
- package/src/server/collections/agent-loop-events.ts +71 -0
- package/src/server/collections/agent-loop-runs.ts +158 -0
- package/src/server/collections/agent-loop-steps.ts +144 -0
- package/src/server/collections/orchestrator-config.ts +7 -0
- package/src/server/collections/skill-executions.ts +63 -51
- package/src/server/collections/skill-loop-configs.ts +65 -0
- package/src/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.ts +30 -0
- package/src/server/migrations/20260524001000-add-plan-approval-and-harness-profiles.ts +142 -0
- package/src/server/plugin.ts +15 -0
- package/src/server/resources/agent-loop.ts +183 -0
- package/src/server/services/AgentHarness.ts +663 -0
- package/src/server/services/AgentLoopController.ts +1128 -0
- package/src/server/services/AgentLoopRepository.ts +194 -0
- package/src/server/services/AgentLoopService.ts +161 -0
- package/src/server/services/AgentPlanValidator.ts +73 -0
- package/src/server/services/AgentPlannerService.ts +93 -0
- package/src/server/services/AgentRegistryService.ts +169 -0
- package/src/server/services/ExecutionSpanService.ts +2 -0
- package/src/server/skill-hub/plugin.ts +881 -771
- package/src/server/tools/agent-loop.ts +399 -0
- package/src/server/tools/delegate-task.ts +48 -463
- package/src/server/tools/orchestrator-plan.ts +279 -0
- package/src/server/tools/skill-execute.ts +68 -64
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { AgentLoopService } from '../services/AgentLoopService';
|
|
3
|
+
export declare function createAgentLoopTools(plugin: any, service: AgentLoopService): ({
|
|
4
|
+
scope: "CUSTOM";
|
|
5
|
+
execution: "backend";
|
|
6
|
+
defaultPermission: "ALLOW";
|
|
7
|
+
introduction: {
|
|
8
|
+
title: string;
|
|
9
|
+
about: string;
|
|
10
|
+
};
|
|
11
|
+
definition: {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
schema: z.ZodObject<{
|
|
15
|
+
goal: z.ZodString;
|
|
16
|
+
leaderUsername: z.ZodOptional<z.ZodString>;
|
|
17
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
18
|
+
messageId: z.ZodOptional<z.ZodString>;
|
|
19
|
+
policy: z.ZodOptional<z.ZodObject<{
|
|
20
|
+
maxIterations: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
maxStepAttempts: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
allowReplan: z.ZodOptional<z.ZodBoolean>;
|
|
23
|
+
requireVerification: z.ZodOptional<z.ZodBoolean>;
|
|
24
|
+
stopOnApprovalRequired: z.ZodOptional<z.ZodBoolean>;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
maxIterations?: number;
|
|
27
|
+
maxStepAttempts?: number;
|
|
28
|
+
allowReplan?: boolean;
|
|
29
|
+
requireVerification?: boolean;
|
|
30
|
+
stopOnApprovalRequired?: boolean;
|
|
31
|
+
}, {
|
|
32
|
+
maxIterations?: number;
|
|
33
|
+
maxStepAttempts?: number;
|
|
34
|
+
allowReplan?: boolean;
|
|
35
|
+
requireVerification?: boolean;
|
|
36
|
+
stopOnApprovalRequired?: boolean;
|
|
37
|
+
}>>;
|
|
38
|
+
metadata: z.ZodOptional<z.ZodAny>;
|
|
39
|
+
plan: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
40
|
+
id: z.ZodOptional<z.ZodString>;
|
|
41
|
+
key: z.ZodOptional<z.ZodString>;
|
|
42
|
+
planKey: z.ZodOptional<z.ZodString>;
|
|
43
|
+
parentStepId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
44
|
+
title: z.ZodOptional<z.ZodString>;
|
|
45
|
+
description: z.ZodOptional<z.ZodString>;
|
|
46
|
+
type: z.ZodOptional<z.ZodEnum<["reasoning", "skill", "tool", "sub_agent", "verification"]>>;
|
|
47
|
+
target: z.ZodOptional<z.ZodString>;
|
|
48
|
+
input: z.ZodOptional<z.ZodAny>;
|
|
49
|
+
dependsOn: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
50
|
+
maxAttempts: z.ZodOptional<z.ZodNumber>;
|
|
51
|
+
metadata: z.ZodOptional<z.ZodAny>;
|
|
52
|
+
}, "strip", z.ZodTypeAny, {
|
|
53
|
+
type?: "reasoning" | "skill" | "tool" | "sub_agent" | "verification";
|
|
54
|
+
key?: string;
|
|
55
|
+
title?: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
metadata?: any;
|
|
58
|
+
input?: any;
|
|
59
|
+
planKey?: string;
|
|
60
|
+
target?: string;
|
|
61
|
+
dependsOn?: string[];
|
|
62
|
+
id?: string;
|
|
63
|
+
parentStepId?: string | number;
|
|
64
|
+
maxAttempts?: number;
|
|
65
|
+
}, {
|
|
66
|
+
type?: "reasoning" | "skill" | "tool" | "sub_agent" | "verification";
|
|
67
|
+
key?: string;
|
|
68
|
+
title?: string;
|
|
69
|
+
description?: string;
|
|
70
|
+
metadata?: any;
|
|
71
|
+
input?: any;
|
|
72
|
+
planKey?: string;
|
|
73
|
+
target?: string;
|
|
74
|
+
dependsOn?: string[];
|
|
75
|
+
id?: string;
|
|
76
|
+
parentStepId?: string | number;
|
|
77
|
+
maxAttempts?: number;
|
|
78
|
+
}>, "many">>;
|
|
79
|
+
}, "strip", z.ZodTypeAny, {
|
|
80
|
+
leaderUsername?: string;
|
|
81
|
+
metadata?: any;
|
|
82
|
+
sessionId?: string;
|
|
83
|
+
goal?: string;
|
|
84
|
+
messageId?: string;
|
|
85
|
+
policy?: {
|
|
86
|
+
maxIterations?: number;
|
|
87
|
+
maxStepAttempts?: number;
|
|
88
|
+
allowReplan?: boolean;
|
|
89
|
+
requireVerification?: boolean;
|
|
90
|
+
stopOnApprovalRequired?: boolean;
|
|
91
|
+
};
|
|
92
|
+
plan?: {
|
|
93
|
+
type?: "reasoning" | "skill" | "tool" | "sub_agent" | "verification";
|
|
94
|
+
key?: string;
|
|
95
|
+
title?: string;
|
|
96
|
+
description?: string;
|
|
97
|
+
metadata?: any;
|
|
98
|
+
input?: any;
|
|
99
|
+
planKey?: string;
|
|
100
|
+
target?: string;
|
|
101
|
+
dependsOn?: string[];
|
|
102
|
+
id?: string;
|
|
103
|
+
parentStepId?: string | number;
|
|
104
|
+
maxAttempts?: number;
|
|
105
|
+
}[];
|
|
106
|
+
}, {
|
|
107
|
+
leaderUsername?: string;
|
|
108
|
+
metadata?: any;
|
|
109
|
+
sessionId?: string;
|
|
110
|
+
goal?: string;
|
|
111
|
+
messageId?: string;
|
|
112
|
+
policy?: {
|
|
113
|
+
maxIterations?: number;
|
|
114
|
+
maxStepAttempts?: number;
|
|
115
|
+
allowReplan?: boolean;
|
|
116
|
+
requireVerification?: boolean;
|
|
117
|
+
stopOnApprovalRequired?: boolean;
|
|
118
|
+
};
|
|
119
|
+
plan?: {
|
|
120
|
+
type?: "reasoning" | "skill" | "tool" | "sub_agent" | "verification";
|
|
121
|
+
key?: string;
|
|
122
|
+
title?: string;
|
|
123
|
+
description?: string;
|
|
124
|
+
metadata?: any;
|
|
125
|
+
input?: any;
|
|
126
|
+
planKey?: string;
|
|
127
|
+
target?: string;
|
|
128
|
+
dependsOn?: string[];
|
|
129
|
+
id?: string;
|
|
130
|
+
parentStepId?: string | number;
|
|
131
|
+
maxAttempts?: number;
|
|
132
|
+
}[];
|
|
133
|
+
}>;
|
|
134
|
+
};
|
|
135
|
+
invoke: (ctx: any, args: any) => Promise<{
|
|
136
|
+
status: "success" | "error";
|
|
137
|
+
content: string;
|
|
138
|
+
}>;
|
|
139
|
+
} | {
|
|
140
|
+
scope: "CUSTOM";
|
|
141
|
+
execution: "backend";
|
|
142
|
+
defaultPermission: "ALLOW";
|
|
143
|
+
introduction: {
|
|
144
|
+
title: string;
|
|
145
|
+
about: string;
|
|
146
|
+
};
|
|
147
|
+
definition: {
|
|
148
|
+
name: string;
|
|
149
|
+
description: string;
|
|
150
|
+
schema: z.ZodObject<{
|
|
151
|
+
runId: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
|
152
|
+
}, "strip", z.ZodTypeAny, {
|
|
153
|
+
runId?: string | number;
|
|
154
|
+
}, {
|
|
155
|
+
runId?: string | number;
|
|
156
|
+
}>;
|
|
157
|
+
};
|
|
158
|
+
invoke: (ctx: any, args: any) => Promise<{
|
|
159
|
+
status: "success" | "error";
|
|
160
|
+
content: string;
|
|
161
|
+
}>;
|
|
162
|
+
} | {
|
|
163
|
+
scope: "CUSTOM";
|
|
164
|
+
execution: "backend";
|
|
165
|
+
defaultPermission: "ALLOW";
|
|
166
|
+
introduction: {
|
|
167
|
+
title: string;
|
|
168
|
+
about: string;
|
|
169
|
+
};
|
|
170
|
+
definition: {
|
|
171
|
+
name: string;
|
|
172
|
+
description: string;
|
|
173
|
+
schema: z.ZodObject<{
|
|
174
|
+
stepId: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
|
175
|
+
status: z.ZodEnum<["running", "succeeded", "failed", "skipped"]>;
|
|
176
|
+
output: z.ZodOptional<z.ZodAny>;
|
|
177
|
+
error: z.ZodOptional<z.ZodString>;
|
|
178
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
179
|
+
skillExecutionId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
180
|
+
agentExecutionSpanId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
181
|
+
metadata: z.ZodOptional<z.ZodAny>;
|
|
182
|
+
}, "strip", z.ZodTypeAny, {
|
|
183
|
+
error?: string;
|
|
184
|
+
status?: "running" | "succeeded" | "failed" | "skipped";
|
|
185
|
+
metadata?: any;
|
|
186
|
+
output?: any;
|
|
187
|
+
skillExecutionId?: string | number;
|
|
188
|
+
reason?: string;
|
|
189
|
+
stepId?: string | number;
|
|
190
|
+
agentExecutionSpanId?: string | number;
|
|
191
|
+
}, {
|
|
192
|
+
error?: string;
|
|
193
|
+
status?: "running" | "succeeded" | "failed" | "skipped";
|
|
194
|
+
metadata?: any;
|
|
195
|
+
output?: any;
|
|
196
|
+
skillExecutionId?: string | number;
|
|
197
|
+
reason?: string;
|
|
198
|
+
stepId?: string | number;
|
|
199
|
+
agentExecutionSpanId?: string | number;
|
|
200
|
+
}>;
|
|
201
|
+
};
|
|
202
|
+
invoke: (ctx: any, args: any) => Promise<{
|
|
203
|
+
status: "success" | "error";
|
|
204
|
+
content: string;
|
|
205
|
+
}>;
|
|
206
|
+
} | {
|
|
207
|
+
scope: "CUSTOM";
|
|
208
|
+
execution: "backend";
|
|
209
|
+
defaultPermission: "ALLOW";
|
|
210
|
+
introduction: {
|
|
211
|
+
title: string;
|
|
212
|
+
about: string;
|
|
213
|
+
};
|
|
214
|
+
definition: {
|
|
215
|
+
name: string;
|
|
216
|
+
description: string;
|
|
217
|
+
schema: z.ZodObject<{
|
|
218
|
+
stepId: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
|
219
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
220
|
+
approval: z.ZodOptional<z.ZodAny>;
|
|
221
|
+
}, "strip", z.ZodTypeAny, {
|
|
222
|
+
reason?: string;
|
|
223
|
+
stepId?: string | number;
|
|
224
|
+
approval?: any;
|
|
225
|
+
}, {
|
|
226
|
+
reason?: string;
|
|
227
|
+
stepId?: string | number;
|
|
228
|
+
approval?: any;
|
|
229
|
+
}>;
|
|
230
|
+
};
|
|
231
|
+
invoke: (ctx: any, args: any) => Promise<{
|
|
232
|
+
status: "success" | "error";
|
|
233
|
+
content: string;
|
|
234
|
+
}>;
|
|
235
|
+
})[];
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var agent_loop_exports = {};
|
|
28
|
+
__export(agent_loop_exports, {
|
|
29
|
+
createAgentLoopTools: () => createAgentLoopTools
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(agent_loop_exports);
|
|
32
|
+
var import_zod = require("zod");
|
|
33
|
+
var import_ExecutionSpanService = require("../services/ExecutionSpanService");
|
|
34
|
+
const stepSchema = import_zod.z.object({
|
|
35
|
+
id: import_zod.z.string().optional(),
|
|
36
|
+
key: import_zod.z.string().optional(),
|
|
37
|
+
planKey: import_zod.z.string().optional(),
|
|
38
|
+
parentStepId: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]).optional(),
|
|
39
|
+
title: import_zod.z.string().optional(),
|
|
40
|
+
description: import_zod.z.string().optional(),
|
|
41
|
+
type: import_zod.z.enum(["reasoning", "skill", "tool", "sub_agent", "verification"]).optional(),
|
|
42
|
+
target: import_zod.z.string().optional(),
|
|
43
|
+
input: import_zod.z.any().optional(),
|
|
44
|
+
dependsOn: import_zod.z.array(import_zod.z.string()).optional(),
|
|
45
|
+
maxAttempts: import_zod.z.number().int().min(1).max(10).optional(),
|
|
46
|
+
metadata: import_zod.z.any().optional()
|
|
47
|
+
});
|
|
48
|
+
const policySchema = import_zod.z.object({
|
|
49
|
+
maxIterations: import_zod.z.number().int().min(1).max(100).optional(),
|
|
50
|
+
maxStepAttempts: import_zod.z.number().int().min(1).max(10).optional(),
|
|
51
|
+
allowReplan: import_zod.z.boolean().optional(),
|
|
52
|
+
requireVerification: import_zod.z.boolean().optional(),
|
|
53
|
+
stopOnApprovalRequired: import_zod.z.boolean().optional()
|
|
54
|
+
}).optional();
|
|
55
|
+
function toolResult(status, payload) {
|
|
56
|
+
return {
|
|
57
|
+
status,
|
|
58
|
+
content: typeof payload === "string" ? payload : JSON.stringify(payload)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function valuesFromCtx(ctx) {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
return ((_b = (_a = ctx == null ? void 0 : ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.values) || {};
|
|
64
|
+
}
|
|
65
|
+
function currentUserId(ctx) {
|
|
66
|
+
var _a, _b, _c, _d;
|
|
67
|
+
return ((_b = (_a = ctx == null ? void 0 : ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id) || ((_d = (_c = ctx == null ? void 0 : ctx.auth) == null ? void 0 : _c.user) == null ? void 0 : _d.id);
|
|
68
|
+
}
|
|
69
|
+
function resolveSessionId(ctx, args) {
|
|
70
|
+
var _a, _b, _c;
|
|
71
|
+
const values = valuesFromCtx(ctx);
|
|
72
|
+
return (args == null ? void 0 : args.sessionId) || values.sessionId || ((_b = (_a = ctx == null ? void 0 : ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.sessionId) || ((_c = ctx == null ? void 0 : ctx.state) == null ? void 0 : _c.sessionId);
|
|
73
|
+
}
|
|
74
|
+
function resolveMessageId(ctx, args) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
const values = valuesFromCtx(ctx);
|
|
77
|
+
return (args == null ? void 0 : args.messageId) || values.messageId || ((_b = (_a = ctx == null ? void 0 : ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.messageId);
|
|
78
|
+
}
|
|
79
|
+
function normalizeEmployeeUsername(raw) {
|
|
80
|
+
if (!raw) return null;
|
|
81
|
+
if (typeof raw === "string") return raw;
|
|
82
|
+
return raw.username || raw.aiEmployeeUsername || raw.name || null;
|
|
83
|
+
}
|
|
84
|
+
async function resolveLeaderUsername(ctx, plugin, args) {
|
|
85
|
+
var _a, _b, _c, _d, _e, _f;
|
|
86
|
+
const values = valuesFromCtx(ctx);
|
|
87
|
+
const direct = normalizeEmployeeUsername(
|
|
88
|
+
(args == null ? void 0 : args.leaderUsername) || (ctx == null ? void 0 : ctx._currentAIEmployee) || ((_a = ctx == null ? void 0 : ctx.state) == null ? void 0 : _a.currentAIEmployee) || ((_c = (_b = ctx == null ? void 0 : ctx.runtime) == null ? void 0 : _b.context) == null ? void 0 : _c.currentAIEmployee) || values.aiEmployee
|
|
89
|
+
);
|
|
90
|
+
if (direct) return direct;
|
|
91
|
+
const sessionId = resolveSessionId(ctx, args);
|
|
92
|
+
if (!sessionId) return void 0;
|
|
93
|
+
try {
|
|
94
|
+
const repo = ((_e = (_d = ctx == null ? void 0 : ctx.db) == null ? void 0 : _d.getRepository) == null ? void 0 : _e.call(_d, "aiConversations")) || plugin.db.getRepository("aiConversations");
|
|
95
|
+
const conversation = await repo.findOne({ filter: { sessionId } });
|
|
96
|
+
return normalizeEmployeeUsername((conversation == null ? void 0 : conversation.aiEmployeeUsername) || ((_f = conversation == null ? void 0 : conversation.get) == null ? void 0 : _f.call(conversation, "aiEmployeeUsername")));
|
|
97
|
+
} catch {
|
|
98
|
+
return void 0;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function setLoopTraceContext(ctx, snapshot, step) {
|
|
102
|
+
if (!ctx || !(snapshot == null ? void 0 : snapshot.run)) return;
|
|
103
|
+
const existing = (0, import_ExecutionSpanService.getOrchestratorTraceContext)(ctx) || {};
|
|
104
|
+
(0, import_ExecutionSpanService.setOrchestratorTraceContext)(ctx, {
|
|
105
|
+
...existing,
|
|
106
|
+
rootRunId: snapshot.run.rootRunId || existing.rootRunId,
|
|
107
|
+
leaderUsername: snapshot.run.leaderUsername || existing.leaderUsername,
|
|
108
|
+
agentLoopRunId: String(snapshot.run.id),
|
|
109
|
+
agentLoopStepId: (step == null ? void 0 : step.id) ? String(step.id) : void 0
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function planFromArgs(plan) {
|
|
113
|
+
return Array.isArray(plan) ? plan : [];
|
|
114
|
+
}
|
|
115
|
+
function createAgentLoopTools(plugin, service) {
|
|
116
|
+
return [
|
|
117
|
+
{
|
|
118
|
+
scope: "CUSTOM",
|
|
119
|
+
execution: "backend",
|
|
120
|
+
defaultPermission: "ALLOW",
|
|
121
|
+
introduction: {
|
|
122
|
+
title: "Agent Loop - Start",
|
|
123
|
+
about: "Create a persistent agent loop run and initial plan for a user goal."
|
|
124
|
+
},
|
|
125
|
+
definition: {
|
|
126
|
+
name: "agent_loop_start",
|
|
127
|
+
description: "Start a persistent agent loop run. Use this first when the user asks for a multi-step task. Provide a concrete plan with small executable steps before calling other tools.",
|
|
128
|
+
schema: import_zod.z.object({
|
|
129
|
+
goal: import_zod.z.string().min(1).describe("The user goal to complete."),
|
|
130
|
+
leaderUsername: import_zod.z.string().optional().describe("Leader AI employee username. Usually omit; inferred from chat."),
|
|
131
|
+
sessionId: import_zod.z.string().optional(),
|
|
132
|
+
messageId: import_zod.z.string().optional(),
|
|
133
|
+
policy: policySchema,
|
|
134
|
+
metadata: import_zod.z.any().optional(),
|
|
135
|
+
plan: import_zod.z.array(stepSchema).optional().describe("Initial plan steps. Use stable planKey values for dependencies.")
|
|
136
|
+
})
|
|
137
|
+
},
|
|
138
|
+
invoke: async (ctx, args) => {
|
|
139
|
+
try {
|
|
140
|
+
const leaderUsername = await resolveLeaderUsername(ctx, plugin, args);
|
|
141
|
+
const snapshot = await service.createRun({
|
|
142
|
+
goal: args.goal,
|
|
143
|
+
leaderUsername,
|
|
144
|
+
sessionId: resolveSessionId(ctx, args),
|
|
145
|
+
messageId: resolveMessageId(ctx, args),
|
|
146
|
+
userId: currentUserId(ctx),
|
|
147
|
+
policy: args.policy,
|
|
148
|
+
metadata: args.metadata,
|
|
149
|
+
plan: planFromArgs(args.plan)
|
|
150
|
+
});
|
|
151
|
+
setLoopTraceContext(ctx, snapshot, snapshot.nextStep);
|
|
152
|
+
return toolResult("success", snapshot);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
return toolResult("error", (error == null ? void 0 : error.message) || String(error));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
scope: "CUSTOM",
|
|
160
|
+
execution: "backend",
|
|
161
|
+
defaultPermission: "ALLOW",
|
|
162
|
+
introduction: {
|
|
163
|
+
title: "Agent Loop - Status",
|
|
164
|
+
about: "Read the current run, steps, and next executable step."
|
|
165
|
+
},
|
|
166
|
+
definition: {
|
|
167
|
+
name: "agent_loop_status",
|
|
168
|
+
description: "Fetch an agent loop run. Call this before executing the next step so subsequent skill/tool calls can be linked to the current loop step.",
|
|
169
|
+
schema: import_zod.z.object({
|
|
170
|
+
runId: import_zod.z.union([import_zod.z.string(), import_zod.z.number()])
|
|
171
|
+
})
|
|
172
|
+
},
|
|
173
|
+
invoke: async (ctx, args) => {
|
|
174
|
+
try {
|
|
175
|
+
const snapshot = await service.getRunSnapshot(args.runId);
|
|
176
|
+
setLoopTraceContext(ctx, snapshot, snapshot.nextStep);
|
|
177
|
+
return toolResult("success", snapshot);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
return toolResult("error", (error == null ? void 0 : error.message) || String(error));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
scope: "CUSTOM",
|
|
185
|
+
execution: "backend",
|
|
186
|
+
defaultPermission: "ALLOW",
|
|
187
|
+
introduction: {
|
|
188
|
+
title: "Agent Loop - Update Step",
|
|
189
|
+
about: "Move a plan step through running, succeeded, failed, or skipped states."
|
|
190
|
+
},
|
|
191
|
+
definition: {
|
|
192
|
+
name: "agent_loop_update_step",
|
|
193
|
+
description: 'Update one plan step after executing the corresponding skill/tool/sub-agent action. Use status="running" before the action and status="succeeded" or "failed" after it.',
|
|
194
|
+
schema: import_zod.z.object({
|
|
195
|
+
stepId: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]),
|
|
196
|
+
status: import_zod.z.enum(["running", "succeeded", "failed", "skipped"]),
|
|
197
|
+
output: import_zod.z.any().optional(),
|
|
198
|
+
error: import_zod.z.string().optional(),
|
|
199
|
+
reason: import_zod.z.string().optional(),
|
|
200
|
+
skillExecutionId: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]).optional(),
|
|
201
|
+
agentExecutionSpanId: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]).optional(),
|
|
202
|
+
metadata: import_zod.z.any().optional()
|
|
203
|
+
})
|
|
204
|
+
},
|
|
205
|
+
invoke: async (ctx, args) => {
|
|
206
|
+
try {
|
|
207
|
+
let snapshot;
|
|
208
|
+
if (args.status === "running") {
|
|
209
|
+
snapshot = await service.startStep(args.stepId, {
|
|
210
|
+
userId: currentUserId(ctx),
|
|
211
|
+
agentExecutionSpanId: args.agentExecutionSpanId
|
|
212
|
+
});
|
|
213
|
+
const currentStep = snapshot.steps.find((step) => String(step.id) === String(args.stepId));
|
|
214
|
+
setLoopTraceContext(ctx, snapshot, currentStep);
|
|
215
|
+
} else if (args.status === "succeeded") {
|
|
216
|
+
snapshot = await service.completeStep(args.stepId, args.output === void 0 ? {} : args.output, {
|
|
217
|
+
userId: currentUserId(ctx),
|
|
218
|
+
skillExecutionId: args.skillExecutionId,
|
|
219
|
+
agentExecutionSpanId: args.agentExecutionSpanId,
|
|
220
|
+
metadata: args.metadata
|
|
221
|
+
});
|
|
222
|
+
setLoopTraceContext(ctx, snapshot, snapshot.nextStep);
|
|
223
|
+
} else if (args.status === "failed") {
|
|
224
|
+
snapshot = await service.failStep(args.stepId, args.error || "Step failed.", {
|
|
225
|
+
userId: currentUserId(ctx),
|
|
226
|
+
metadata: args.metadata
|
|
227
|
+
});
|
|
228
|
+
setLoopTraceContext(ctx, snapshot, snapshot.nextStep);
|
|
229
|
+
} else {
|
|
230
|
+
snapshot = await service.skipStep(args.stepId, args.reason || "Skipped.", {
|
|
231
|
+
userId: currentUserId(ctx)
|
|
232
|
+
});
|
|
233
|
+
setLoopTraceContext(ctx, snapshot, snapshot.nextStep);
|
|
234
|
+
}
|
|
235
|
+
return toolResult("success", snapshot);
|
|
236
|
+
} catch (error) {
|
|
237
|
+
return toolResult("error", (error == null ? void 0 : error.message) || String(error));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
scope: "CUSTOM",
|
|
243
|
+
execution: "backend",
|
|
244
|
+
defaultPermission: "ALLOW",
|
|
245
|
+
introduction: {
|
|
246
|
+
title: "Agent Loop - Replan",
|
|
247
|
+
about: "Replace pending work or append new plan steps when execution needs a new path."
|
|
248
|
+
},
|
|
249
|
+
definition: {
|
|
250
|
+
name: "agent_loop_replan",
|
|
251
|
+
description: "Update the plan when a step fails, required context is missing, or a better execution path is discovered.",
|
|
252
|
+
schema: import_zod.z.object({
|
|
253
|
+
runId: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]),
|
|
254
|
+
reason: import_zod.z.string().optional(),
|
|
255
|
+
mode: import_zod.z.enum(["replace_pending", "append"]).optional(),
|
|
256
|
+
plan: import_zod.z.array(stepSchema).min(1)
|
|
257
|
+
})
|
|
258
|
+
},
|
|
259
|
+
invoke: async (ctx, args) => {
|
|
260
|
+
try {
|
|
261
|
+
await service.replan(args.runId, args.plan, {
|
|
262
|
+
reason: args.reason,
|
|
263
|
+
mode: args.mode || "replace_pending",
|
|
264
|
+
userId: currentUserId(ctx)
|
|
265
|
+
});
|
|
266
|
+
const snapshot = await service.getRunSnapshot(args.runId);
|
|
267
|
+
setLoopTraceContext(ctx, snapshot, snapshot.nextStep);
|
|
268
|
+
return toolResult("success", snapshot);
|
|
269
|
+
} catch (error) {
|
|
270
|
+
return toolResult("error", (error == null ? void 0 : error.message) || String(error));
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
scope: "CUSTOM",
|
|
276
|
+
execution: "backend",
|
|
277
|
+
defaultPermission: "ALLOW",
|
|
278
|
+
introduction: {
|
|
279
|
+
title: "Agent Loop - Request Approval",
|
|
280
|
+
about: "Pause a run and request user approval or edited input for a step."
|
|
281
|
+
},
|
|
282
|
+
definition: {
|
|
283
|
+
name: "agent_loop_request_approval",
|
|
284
|
+
description: "Pause the loop when a step needs user approval, user-edited input, or an ASK/human-review tool cannot run headlessly.",
|
|
285
|
+
schema: import_zod.z.object({
|
|
286
|
+
stepId: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]),
|
|
287
|
+
reason: import_zod.z.string().optional(),
|
|
288
|
+
approval: import_zod.z.any().optional()
|
|
289
|
+
})
|
|
290
|
+
},
|
|
291
|
+
invoke: async (ctx, args) => {
|
|
292
|
+
try {
|
|
293
|
+
const snapshot = await service.requestApproval(args.stepId, args.approval || {}, {
|
|
294
|
+
reason: args.reason,
|
|
295
|
+
userId: currentUserId(ctx)
|
|
296
|
+
});
|
|
297
|
+
setLoopTraceContext(ctx, snapshot, snapshot.nextStep);
|
|
298
|
+
return toolResult("success", snapshot);
|
|
299
|
+
} catch (error) {
|
|
300
|
+
return toolResult("error", (error == null ? void 0 : error.message) || String(error));
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
scope: "CUSTOM",
|
|
306
|
+
execution: "backend",
|
|
307
|
+
defaultPermission: "ALLOW",
|
|
308
|
+
introduction: {
|
|
309
|
+
title: "Agent Loop - Resume",
|
|
310
|
+
about: "Resume a waiting run after user approval or rejection."
|
|
311
|
+
},
|
|
312
|
+
definition: {
|
|
313
|
+
name: "agent_loop_resume",
|
|
314
|
+
description: "Resume a run that is waiting for user approval. Pass editedInput when the user changed step input.",
|
|
315
|
+
schema: import_zod.z.object({
|
|
316
|
+
runId: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]),
|
|
317
|
+
stepId: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]).optional(),
|
|
318
|
+
approved: import_zod.z.boolean(),
|
|
319
|
+
editedInput: import_zod.z.any().optional()
|
|
320
|
+
})
|
|
321
|
+
},
|
|
322
|
+
invoke: async (ctx, args) => {
|
|
323
|
+
try {
|
|
324
|
+
const snapshot = await service.resumeRun(args.runId, {
|
|
325
|
+
stepId: args.stepId,
|
|
326
|
+
approved: args.approved,
|
|
327
|
+
editedInput: args.editedInput,
|
|
328
|
+
userId: currentUserId(ctx),
|
|
329
|
+
ctx
|
|
330
|
+
});
|
|
331
|
+
setLoopTraceContext(ctx, snapshot, snapshot.nextStep);
|
|
332
|
+
return toolResult("success", snapshot);
|
|
333
|
+
} catch (error) {
|
|
334
|
+
return toolResult("error", (error == null ? void 0 : error.message) || String(error));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
scope: "CUSTOM",
|
|
340
|
+
execution: "backend",
|
|
341
|
+
defaultPermission: "ALLOW",
|
|
342
|
+
introduction: {
|
|
343
|
+
title: "Agent Loop - Finish",
|
|
344
|
+
about: "Finish a run with final answer and optional evidence."
|
|
345
|
+
},
|
|
346
|
+
definition: {
|
|
347
|
+
name: "agent_loop_finish",
|
|
348
|
+
description: 'Finish the agent loop after all required steps and verification are complete. Use status="failed" if the goal cannot be completed.',
|
|
349
|
+
schema: import_zod.z.object({
|
|
350
|
+
runId: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]),
|
|
351
|
+
finalAnswer: import_zod.z.string().optional(),
|
|
352
|
+
status: import_zod.z.enum(["succeeded", "failed"]).optional(),
|
|
353
|
+
summary: import_zod.z.string().optional(),
|
|
354
|
+
evidence: import_zod.z.any().optional()
|
|
355
|
+
})
|
|
356
|
+
},
|
|
357
|
+
invoke: async (ctx, args) => {
|
|
358
|
+
try {
|
|
359
|
+
const snapshot = await service.finishRun(args.runId, args.finalAnswer || "", {
|
|
360
|
+
status: args.status || "succeeded",
|
|
361
|
+
summary: args.summary,
|
|
362
|
+
evidence: args.evidence,
|
|
363
|
+
userId: currentUserId(ctx)
|
|
364
|
+
});
|
|
365
|
+
setLoopTraceContext(ctx, snapshot);
|
|
366
|
+
return toolResult("success", snapshot);
|
|
367
|
+
} catch (error) {
|
|
368
|
+
return toolResult("error", (error == null ? void 0 : error.message) || String(error));
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
scope: "CUSTOM",
|
|
374
|
+
execution: "backend",
|
|
375
|
+
defaultPermission: "ALLOW",
|
|
376
|
+
introduction: {
|
|
377
|
+
title: "Agent Loop - Cancel",
|
|
378
|
+
about: "Cancel a run and skip unfinished steps."
|
|
379
|
+
},
|
|
380
|
+
definition: {
|
|
381
|
+
name: "agent_loop_cancel",
|
|
382
|
+
description: "Cancel an agent loop run. Use this when the user stops the task or the goal is no longer valid.",
|
|
383
|
+
schema: import_zod.z.object({
|
|
384
|
+
runId: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]),
|
|
385
|
+
reason: import_zod.z.string().optional()
|
|
386
|
+
})
|
|
387
|
+
},
|
|
388
|
+
invoke: async (ctx, args) => {
|
|
389
|
+
try {
|
|
390
|
+
const snapshot = await service.cancelRun(args.runId, {
|
|
391
|
+
reason: args.reason,
|
|
392
|
+
userId: currentUserId(ctx)
|
|
393
|
+
});
|
|
394
|
+
setLoopTraceContext(ctx, snapshot);
|
|
395
|
+
return toolResult("success", snapshot);
|
|
396
|
+
} catch (error) {
|
|
397
|
+
return toolResult("error", (error == null ? void 0 : error.message) || String(error));
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
];
|
|
402
|
+
}
|
|
403
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
404
|
+
0 && (module.exports = {
|
|
405
|
+
createAgentLoopTools
|
|
406
|
+
});
|