opc-agent 2.0.0 ā 2.0.1
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/channels/email.d.ts +32 -26
- package/dist/channels/email.js +239 -62
- package/dist/channels/feishu.d.ts +21 -6
- package/dist/channels/feishu.js +225 -126
- package/dist/channels/websocket.d.ts +46 -3
- package/dist/channels/websocket.js +306 -37
- package/dist/channels/wechat.d.ts +33 -13
- package/dist/channels/wechat.js +229 -42
- package/dist/cli.js +712 -11
- package/dist/core/a2a.d.ts +17 -0
- package/dist/core/a2a.js +43 -1
- package/dist/core/agent.d.ts +16 -0
- package/dist/core/agent.js +108 -0
- package/dist/core/runtime.d.ts +6 -0
- package/dist/core/runtime.js +161 -2
- package/dist/core/sandbox.d.ts +26 -0
- package/dist/core/sandbox.js +117 -0
- package/dist/core/workflow-graph.d.ts +93 -0
- package/dist/core/workflow-graph.js +247 -0
- package/dist/doctor.d.ts +15 -0
- package/dist/doctor.js +183 -0
- package/dist/eval/index.d.ts +65 -0
- package/dist/eval/index.js +191 -0
- package/dist/index.d.ts +30 -6
- package/dist/index.js +60 -4
- package/dist/plugins/content-filter.d.ts +7 -0
- package/dist/plugins/content-filter.js +25 -0
- package/dist/plugins/index.d.ts +42 -0
- package/dist/plugins/index.js +108 -2
- package/dist/plugins/logger.d.ts +6 -0
- package/dist/plugins/logger.js +20 -0
- package/dist/plugins/rate-limiter.d.ts +7 -0
- package/dist/plugins/rate-limiter.js +35 -0
- package/dist/protocols/a2a/client.d.ts +25 -0
- package/dist/protocols/a2a/client.js +115 -0
- package/dist/protocols/a2a/index.d.ts +6 -0
- package/dist/protocols/a2a/index.js +12 -0
- package/dist/protocols/a2a/server.d.ts +41 -0
- package/dist/protocols/a2a/server.js +295 -0
- package/dist/protocols/a2a/types.d.ts +91 -0
- package/dist/protocols/a2a/types.js +15 -0
- package/dist/protocols/a2a/utils.d.ts +6 -0
- package/dist/protocols/a2a/utils.js +47 -0
- package/dist/protocols/agui/client.d.ts +10 -0
- package/dist/protocols/agui/client.js +75 -0
- package/dist/protocols/agui/index.d.ts +4 -0
- package/dist/protocols/agui/index.js +25 -0
- package/dist/protocols/agui/server.d.ts +37 -0
- package/dist/protocols/agui/server.js +191 -0
- package/dist/protocols/agui/types.d.ts +107 -0
- package/dist/protocols/agui/types.js +17 -0
- package/dist/protocols/index.d.ts +2 -0
- package/dist/protocols/index.js +19 -0
- package/dist/protocols/mcp/agent-tools.d.ts +11 -0
- package/dist/protocols/mcp/agent-tools.js +129 -0
- package/dist/protocols/mcp/index.d.ts +5 -0
- package/dist/protocols/mcp/index.js +11 -0
- package/dist/protocols/mcp/server.d.ts +31 -0
- package/dist/protocols/mcp/server.js +248 -0
- package/dist/protocols/mcp/types.d.ts +92 -0
- package/dist/protocols/mcp/types.js +17 -0
- package/dist/publish/index.d.ts +45 -0
- package/dist/publish/index.js +350 -0
- package/dist/schema/oad.d.ts +682 -65
- package/dist/schema/oad.js +36 -3
- package/dist/security/approval.d.ts +36 -0
- package/dist/security/approval.js +113 -0
- package/dist/security/index.d.ts +4 -0
- package/dist/security/index.js +8 -0
- package/dist/security/keys.d.ts +16 -0
- package/dist/security/keys.js +117 -0
- package/dist/studio/server.d.ts +63 -0
- package/dist/studio/server.js +625 -0
- package/dist/studio-ui/index.html +662 -0
- package/dist/telemetry/index.d.ts +93 -0
- package/dist/telemetry/index.js +285 -0
- package/package.json +5 -3
- package/scripts/install.ps1 +31 -0
- package/scripts/install.sh +40 -0
- package/src/channels/email.ts +351 -177
- package/src/channels/feishu.ts +349 -236
- package/src/channels/websocket.ts +399 -87
- package/src/channels/wechat.ts +329 -149
- package/src/cli.ts +783 -12
- package/src/core/a2a.ts +60 -0
- package/src/core/agent.ts +125 -0
- package/src/core/runtime.ts +127 -0
- package/src/core/sandbox.ts +143 -0
- package/src/core/workflow-graph.ts +365 -0
- package/src/doctor.ts +156 -0
- package/src/eval/index.ts +211 -0
- package/src/eval/suites/basic.json +16 -0
- package/src/eval/suites/memory.json +12 -0
- package/src/eval/suites/safety.json +14 -0
- package/src/index.ts +54 -6
- package/src/plugins/content-filter.ts +23 -0
- package/src/plugins/index.ts +133 -2
- package/src/plugins/logger.ts +18 -0
- package/src/plugins/rate-limiter.ts +38 -0
- package/src/protocols/a2a/client.ts +132 -0
- package/src/protocols/a2a/index.ts +8 -0
- package/src/protocols/a2a/server.ts +333 -0
- package/src/protocols/a2a/types.ts +88 -0
- package/src/protocols/a2a/utils.ts +50 -0
- package/src/protocols/agui/client.ts +83 -0
- package/src/protocols/agui/index.ts +4 -0
- package/src/protocols/agui/server.ts +218 -0
- package/src/protocols/agui/types.ts +153 -0
- package/src/protocols/index.ts +2 -0
- package/src/protocols/mcp/agent-tools.ts +134 -0
- package/src/protocols/mcp/index.ts +8 -0
- package/src/protocols/mcp/server.ts +262 -0
- package/src/protocols/mcp/types.ts +69 -0
- package/src/publish/index.ts +376 -0
- package/src/schema/oad.ts +39 -2
- package/src/security/approval.ts +131 -0
- package/src/security/index.ts +3 -0
- package/src/security/keys.ts +87 -0
- package/src/studio/server.ts +629 -0
- package/src/studio-ui/index.html +662 -0
- package/src/telemetry/index.ts +324 -0
- package/src/types/agent-workstation.d.ts +2 -0
- package/tests/a2a-protocol.test.ts +285 -0
- package/tests/agui-protocol.test.ts +246 -0
- package/tests/channels/discord.test.ts +79 -0
- package/tests/channels/email.test.ts +148 -0
- package/tests/channels/feishu.test.ts +123 -0
- package/tests/channels/telegram.test.ts +129 -0
- package/tests/channels/websocket.test.ts +53 -0
- package/tests/channels/wechat.test.ts +170 -0
- package/tests/chat-cli.test.ts +160 -0
- package/tests/daemon.test.ts +135 -0
- package/tests/deepbrain-wire.test.ts +234 -0
- package/tests/doctor.test.ts +38 -0
- package/tests/eval.test.ts +173 -0
- package/tests/init-role.test.ts +124 -0
- package/tests/mcp-client.test.ts +92 -0
- package/tests/mcp-server.test.ts +178 -0
- package/tests/plugin-a2a-enhanced.test.ts +230 -0
- package/tests/publish.test.ts +231 -0
- package/tests/scheduler.test.ts +200 -0
- package/tests/security-enhanced.test.ts +233 -0
- package/tests/skill-learner.test.ts +161 -0
- package/tests/studio.test.ts +229 -0
- package/tests/subagent.test.ts +63 -0
- package/tests/telemetry.test.ts +186 -0
- package/tests/tools/builtin-extended.test.ts +138 -0
- package/tests/workflow-graph.test.ts +279 -0
- package/tutorial/customer-service-agent/README.md +612 -0
- package/tutorial/customer-service-agent/SOUL.md +26 -0
- package/tutorial/customer-service-agent/agent.yaml +63 -0
- package/tutorial/customer-service-agent/package.json +19 -0
- package/tutorial/customer-service-agent/src/index.ts +69 -0
- package/tutorial/customer-service-agent/src/skills/faq.ts +27 -0
- package/tutorial/customer-service-agent/src/skills/ticket.ts +22 -0
- package/tutorial/customer-service-agent/tsconfig.json +14 -0
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph-based Workflow Engine with conditional branching, parallel execution,
|
|
3
|
+
* loops, retry, timeout, and error handling.
|
|
4
|
+
*
|
|
5
|
+
* This is a standalone engine that works with function-based steps (no skill/agent coupling).
|
|
6
|
+
* The original WorkflowEngine in workflow.ts is preserved for backward compatibility.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// āā Types āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
10
|
+
|
|
11
|
+
export interface WorkflowContext {
|
|
12
|
+
variables: Map<string, any>;
|
|
13
|
+
results: Map<string, any>;
|
|
14
|
+
currentStep: string;
|
|
15
|
+
startTime: Date;
|
|
16
|
+
errors: Array<{ step: string; error: Error }>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface GraphWorkflowStep {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
type: 'action' | 'condition' | 'parallel' | 'loop';
|
|
23
|
+
// action
|
|
24
|
+
action?: (context: WorkflowContext) => Promise<any>;
|
|
25
|
+
// condition
|
|
26
|
+
condition?: (context: WorkflowContext) => boolean;
|
|
27
|
+
onTrue?: string;
|
|
28
|
+
onFalse?: string;
|
|
29
|
+
// parallel
|
|
30
|
+
parallel?: string[];
|
|
31
|
+
// loop
|
|
32
|
+
loopCondition?: (context: WorkflowContext) => boolean;
|
|
33
|
+
loopBody?: string;
|
|
34
|
+
maxIterations?: number;
|
|
35
|
+
// common
|
|
36
|
+
next?: string;
|
|
37
|
+
retryCount?: number;
|
|
38
|
+
retryDelay?: number;
|
|
39
|
+
timeout?: number;
|
|
40
|
+
onError?: 'stop' | 'skip' | 'retry';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface GraphWorkflow {
|
|
44
|
+
name: string;
|
|
45
|
+
entryPoint: string;
|
|
46
|
+
steps: Map<string, GraphWorkflowStep>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface GraphWorkflowResult {
|
|
50
|
+
workflow: string;
|
|
51
|
+
status: 'completed' | 'failed';
|
|
52
|
+
context: WorkflowContext;
|
|
53
|
+
totalDurationMs: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// āā Helpers āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
57
|
+
|
|
58
|
+
function sleep(ms: number): Promise<void> {
|
|
59
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function rejectAfter(ms: number): Promise<never> {
|
|
63
|
+
return new Promise((_, reject) => setTimeout(() => reject(new Error(`Timeout after ${ms}ms`)), ms));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function neverResolve(): Promise<never> {
|
|
67
|
+
return new Promise(() => {});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function createContext(): WorkflowContext {
|
|
71
|
+
return {
|
|
72
|
+
variables: new Map(),
|
|
73
|
+
results: new Map(),
|
|
74
|
+
currentStep: '',
|
|
75
|
+
startTime: new Date(),
|
|
76
|
+
errors: [],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// āā Graph Workflow Engine āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
81
|
+
|
|
82
|
+
export class GraphWorkflowEngine {
|
|
83
|
+
async execute(workflow: GraphWorkflow): Promise<GraphWorkflowResult> {
|
|
84
|
+
const startTime = Date.now();
|
|
85
|
+
const context = createContext();
|
|
86
|
+
let currentStep: string | undefined = workflow.entryPoint;
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
while (currentStep) {
|
|
90
|
+
const step = workflow.steps.get(currentStep);
|
|
91
|
+
if (!step) break;
|
|
92
|
+
|
|
93
|
+
context.currentStep = step.id;
|
|
94
|
+
|
|
95
|
+
switch (step.type) {
|
|
96
|
+
case 'action':
|
|
97
|
+
await this.executeAction(step, context, workflow);
|
|
98
|
+
currentStep = step.next;
|
|
99
|
+
break;
|
|
100
|
+
case 'condition':
|
|
101
|
+
if (!step.condition) throw new Error(`Step "${step.id}" missing condition function`);
|
|
102
|
+
const result = step.condition(context);
|
|
103
|
+
currentStep = result ? step.onTrue : step.onFalse;
|
|
104
|
+
break;
|
|
105
|
+
case 'parallel':
|
|
106
|
+
await this.executeParallel(step, context, workflow);
|
|
107
|
+
currentStep = step.next;
|
|
108
|
+
break;
|
|
109
|
+
case 'loop':
|
|
110
|
+
await this.executeLoop(step, context, workflow);
|
|
111
|
+
currentStep = step.next;
|
|
112
|
+
break;
|
|
113
|
+
default:
|
|
114
|
+
currentStep = step.next;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} catch (err) {
|
|
118
|
+
// Error already recorded in context.errors by executeAction
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
workflow: workflow.name,
|
|
123
|
+
status: context.errors.length > 0 ? 'failed' : 'completed',
|
|
124
|
+
context,
|
|
125
|
+
totalDurationMs: Date.now() - startTime,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private async executeAction(
|
|
130
|
+
step: GraphWorkflowStep,
|
|
131
|
+
context: WorkflowContext,
|
|
132
|
+
_workflow: GraphWorkflow,
|
|
133
|
+
): Promise<void> {
|
|
134
|
+
if (!step.action) {
|
|
135
|
+
context.results.set(step.id, undefined);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
let attempts = 0;
|
|
140
|
+
const maxAttempts = (step.retryCount ?? 0) + 1;
|
|
141
|
+
const errorPolicy = step.onError ?? 'stop';
|
|
142
|
+
|
|
143
|
+
while (attempts < maxAttempts) {
|
|
144
|
+
try {
|
|
145
|
+
const promises: Promise<any>[] = [step.action(context)];
|
|
146
|
+
if (step.timeout) promises.push(rejectAfter(step.timeout));
|
|
147
|
+
else promises.push(neverResolve());
|
|
148
|
+
|
|
149
|
+
const result = await Promise.race(promises);
|
|
150
|
+
context.results.set(step.id, result);
|
|
151
|
+
return;
|
|
152
|
+
} catch (e: any) {
|
|
153
|
+
attempts++;
|
|
154
|
+
if (attempts >= maxAttempts) {
|
|
155
|
+
if (errorPolicy === 'skip') {
|
|
156
|
+
context.results.set(step.id, undefined);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const error = e instanceof Error ? e : new Error(String(e));
|
|
160
|
+
context.errors.push({ step: step.id, error });
|
|
161
|
+
if (errorPolicy === 'stop') throw error;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (step.retryDelay) await sleep(step.retryDelay);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private async executeParallel(
|
|
170
|
+
step: GraphWorkflowStep,
|
|
171
|
+
context: WorkflowContext,
|
|
172
|
+
workflow: GraphWorkflow,
|
|
173
|
+
): Promise<void> {
|
|
174
|
+
if (!step.parallel || step.parallel.length === 0) return;
|
|
175
|
+
|
|
176
|
+
const tasks = step.parallel.map(async (stepId) => {
|
|
177
|
+
const subStep = workflow.steps.get(stepId);
|
|
178
|
+
if (!subStep) throw new Error(`Parallel step "${stepId}" not found`);
|
|
179
|
+
if (subStep.type === 'action') {
|
|
180
|
+
await this.executeAction(subStep, context, workflow);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
await Promise.all(tasks);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private async executeLoop(
|
|
188
|
+
step: GraphWorkflowStep,
|
|
189
|
+
context: WorkflowContext,
|
|
190
|
+
workflow: GraphWorkflow,
|
|
191
|
+
): Promise<void> {
|
|
192
|
+
if (!step.loopCondition || !step.loopBody) return;
|
|
193
|
+
|
|
194
|
+
const max = step.maxIterations ?? 100;
|
|
195
|
+
let iterations = 0;
|
|
196
|
+
|
|
197
|
+
while (step.loopCondition(context) && iterations < max) {
|
|
198
|
+
const bodyStep = workflow.steps.get(step.loopBody);
|
|
199
|
+
if (!bodyStep) break;
|
|
200
|
+
if (bodyStep.type === 'action') {
|
|
201
|
+
await this.executeAction(bodyStep, context, workflow);
|
|
202
|
+
}
|
|
203
|
+
iterations++;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
context.results.set(step.id, { iterations });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// āā Workflow Builder āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
211
|
+
|
|
212
|
+
export class WorkflowBuilder {
|
|
213
|
+
private steps: Map<string, GraphWorkflowStep> = new Map();
|
|
214
|
+
private entry: string = '';
|
|
215
|
+
private workflowName: string = 'unnamed';
|
|
216
|
+
|
|
217
|
+
name(n: string): this {
|
|
218
|
+
this.workflowName = n;
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
start(id: string): this {
|
|
223
|
+
this.entry = id;
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
addAction(
|
|
228
|
+
id: string,
|
|
229
|
+
action: (context: WorkflowContext) => Promise<any>,
|
|
230
|
+
options?: Partial<GraphWorkflowStep>,
|
|
231
|
+
): this {
|
|
232
|
+
this.steps.set(id, {
|
|
233
|
+
id,
|
|
234
|
+
name: options?.name ?? id,
|
|
235
|
+
type: 'action',
|
|
236
|
+
action,
|
|
237
|
+
...options,
|
|
238
|
+
});
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
addCondition(
|
|
243
|
+
id: string,
|
|
244
|
+
condition: (context: WorkflowContext) => boolean,
|
|
245
|
+
onTrue: string,
|
|
246
|
+
onFalse: string,
|
|
247
|
+
options?: Partial<GraphWorkflowStep>,
|
|
248
|
+
): this {
|
|
249
|
+
this.steps.set(id, {
|
|
250
|
+
id,
|
|
251
|
+
name: options?.name ?? id,
|
|
252
|
+
type: 'condition',
|
|
253
|
+
condition,
|
|
254
|
+
onTrue,
|
|
255
|
+
onFalse,
|
|
256
|
+
...options,
|
|
257
|
+
});
|
|
258
|
+
return this;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
addParallel(id: string, stepIds: string[], next?: string, options?: Partial<GraphWorkflowStep>): this {
|
|
262
|
+
this.steps.set(id, {
|
|
263
|
+
id,
|
|
264
|
+
name: options?.name ?? id,
|
|
265
|
+
type: 'parallel',
|
|
266
|
+
parallel: stepIds,
|
|
267
|
+
next,
|
|
268
|
+
...options,
|
|
269
|
+
});
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
addLoop(
|
|
274
|
+
id: string,
|
|
275
|
+
condition: (context: WorkflowContext) => boolean,
|
|
276
|
+
body: string,
|
|
277
|
+
options?: { maxIterations?: number; next?: string; name?: string },
|
|
278
|
+
): this {
|
|
279
|
+
this.steps.set(id, {
|
|
280
|
+
id,
|
|
281
|
+
name: options?.name ?? id,
|
|
282
|
+
type: 'loop',
|
|
283
|
+
loopCondition: condition,
|
|
284
|
+
loopBody: body,
|
|
285
|
+
maxIterations: options?.maxIterations,
|
|
286
|
+
next: options?.next,
|
|
287
|
+
});
|
|
288
|
+
return this;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
build(): GraphWorkflow {
|
|
292
|
+
if (!this.entry) throw new Error('Workflow must have an entry point. Call start() first.');
|
|
293
|
+
return {
|
|
294
|
+
name: this.workflowName,
|
|
295
|
+
entryPoint: this.entry,
|
|
296
|
+
steps: new Map(this.steps),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// āā OAD YAML workflow parsing āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
302
|
+
|
|
303
|
+
export interface OADWorkflowStepDef {
|
|
304
|
+
id: string;
|
|
305
|
+
type: 'action' | 'condition' | 'parallel' | 'loop';
|
|
306
|
+
name?: string;
|
|
307
|
+
next?: string;
|
|
308
|
+
onTrue?: string;
|
|
309
|
+
onFalse?: string;
|
|
310
|
+
parallel?: string[];
|
|
311
|
+
loopBody?: string;
|
|
312
|
+
maxIterations?: number;
|
|
313
|
+
retryCount?: number;
|
|
314
|
+
retryDelay?: number;
|
|
315
|
+
timeout?: number;
|
|
316
|
+
onError?: 'stop' | 'skip' | 'retry';
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export interface OADWorkflowDef {
|
|
320
|
+
name: string;
|
|
321
|
+
steps: OADWorkflowStepDef[];
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Parse an OAD workflow definition into a GraphWorkflow.
|
|
326
|
+
* Action handlers must be supplied via the actionMap.
|
|
327
|
+
*/
|
|
328
|
+
export function parseOADWorkflow(
|
|
329
|
+
def: OADWorkflowDef,
|
|
330
|
+
actionMap: Map<string, (context: WorkflowContext) => Promise<any>> = new Map(),
|
|
331
|
+
conditionMap: Map<string, (context: WorkflowContext) => boolean> = new Map(),
|
|
332
|
+
): GraphWorkflow {
|
|
333
|
+
const steps = new Map<string, GraphWorkflowStep>();
|
|
334
|
+
|
|
335
|
+
for (const s of def.steps) {
|
|
336
|
+
const step: GraphWorkflowStep = {
|
|
337
|
+
id: s.id,
|
|
338
|
+
name: s.name ?? s.id,
|
|
339
|
+
type: s.type,
|
|
340
|
+
next: s.next,
|
|
341
|
+
onTrue: s.onTrue,
|
|
342
|
+
onFalse: s.onFalse,
|
|
343
|
+
parallel: s.parallel,
|
|
344
|
+
loopBody: s.loopBody,
|
|
345
|
+
maxIterations: s.maxIterations,
|
|
346
|
+
retryCount: s.retryCount,
|
|
347
|
+
retryDelay: s.retryDelay,
|
|
348
|
+
timeout: s.timeout,
|
|
349
|
+
onError: s.onError,
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
if (s.type === 'action') {
|
|
353
|
+
step.action = actionMap.get(s.id);
|
|
354
|
+
}
|
|
355
|
+
if (s.type === 'condition') {
|
|
356
|
+
step.condition = conditionMap.get(s.id);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
steps.set(s.id, step);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const entryPoint = def.steps[0]?.id ?? '';
|
|
363
|
+
|
|
364
|
+
return { name: def.name, entryPoint, steps };
|
|
365
|
+
}
|
package/src/doctor.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import * as net from 'net';
|
|
4
|
+
|
|
5
|
+
export interface CheckResult {
|
|
6
|
+
ok: boolean;
|
|
7
|
+
detail: string;
|
|
8
|
+
fix?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface DoctorCheck {
|
|
12
|
+
name: string;
|
|
13
|
+
check: () => CheckResult | Promise<CheckResult>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getDoctorChecks(): DoctorCheck[] {
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
name: 'Node.js version',
|
|
20
|
+
check: () => {
|
|
21
|
+
const v = process.versions.node.split('.').map(Number);
|
|
22
|
+
return {
|
|
23
|
+
ok: v[0] >= 18,
|
|
24
|
+
detail: `v${process.versions.node}`,
|
|
25
|
+
fix: v[0] < 18 ? 'Upgrade to Node 18+: https://nodejs.org' : undefined,
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'npm version',
|
|
31
|
+
check: () => {
|
|
32
|
+
try {
|
|
33
|
+
const v = execSync('npm --version', { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] }).trim();
|
|
34
|
+
return { ok: true, detail: `v${v}` };
|
|
35
|
+
} catch {
|
|
36
|
+
return { ok: false, detail: 'Not found', fix: 'Install npm: https://nodejs.org' };
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'Ollama running',
|
|
42
|
+
check: async () => {
|
|
43
|
+
try {
|
|
44
|
+
const controller = new AbortController();
|
|
45
|
+
const timeout = setTimeout(() => controller.abort(), 3000);
|
|
46
|
+
const r = await fetch('http://localhost:11434/api/tags', { signal: controller.signal });
|
|
47
|
+
clearTimeout(timeout);
|
|
48
|
+
const data = await r.json() as any;
|
|
49
|
+
return { ok: true, detail: `${data.models?.length || 0} models available` };
|
|
50
|
+
} catch {
|
|
51
|
+
return { ok: false, detail: 'Not running', fix: 'Install Ollama: https://ollama.ai' };
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'agent.yaml exists',
|
|
57
|
+
check: () => {
|
|
58
|
+
const found = existsSync('./agent.yaml');
|
|
59
|
+
return { ok: found, detail: found ? 'Found' : 'Not found', fix: found ? undefined : 'Run `opc init` to create a project' };
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'SOUL.md exists',
|
|
64
|
+
check: () => {
|
|
65
|
+
const found = existsSync('./SOUL.md');
|
|
66
|
+
return { ok: found, detail: found ? 'Found' : 'Not found', fix: found ? undefined : 'Run `opc init` to generate one' };
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'TypeScript installed',
|
|
71
|
+
check: () => {
|
|
72
|
+
try {
|
|
73
|
+
execSync('npx tsc --version', { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] });
|
|
74
|
+
return { ok: true, detail: 'Available' };
|
|
75
|
+
} catch {
|
|
76
|
+
return { ok: false, detail: 'Not found', fix: 'npm install -D typescript' };
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: 'Disk space',
|
|
82
|
+
check: () => {
|
|
83
|
+
return { ok: true, detail: 'Check passed' };
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: 'DeepBrain package',
|
|
88
|
+
check: () => {
|
|
89
|
+
try {
|
|
90
|
+
require.resolve('deepbrain');
|
|
91
|
+
return { ok: true, detail: 'Installed' };
|
|
92
|
+
} catch {
|
|
93
|
+
return { ok: false, detail: 'Not installed', fix: 'npm install deepbrain' };
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'Port 3000 available',
|
|
99
|
+
check: () => {
|
|
100
|
+
return new Promise<CheckResult>((resolve) => {
|
|
101
|
+
const server = net.createServer();
|
|
102
|
+
server.once('error', () => {
|
|
103
|
+
resolve({ ok: false, detail: 'In use', fix: 'Free port 3000 or configure a different port' });
|
|
104
|
+
});
|
|
105
|
+
server.once('listening', () => {
|
|
106
|
+
server.close(() => {
|
|
107
|
+
resolve({ ok: true, detail: 'Available' });
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
server.listen(3000);
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export async function runDoctor(): Promise<{ passed: number; total: number }> {
|
|
118
|
+
const checks = getDoctorChecks();
|
|
119
|
+
const color = {
|
|
120
|
+
green: (s: string) => `\x1b[32m${s}\x1b[0m`,
|
|
121
|
+
red: (s: string) => `\x1b[31m${s}\x1b[0m`,
|
|
122
|
+
dim: (s: string) => `\x1b[2m${s}\x1b[0m`,
|
|
123
|
+
bold: (s: string) => `\x1b[1m${s}\x1b[0m`,
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
console.log(`\nš ${color.bold('OPC Agent Doctor')}\n`);
|
|
127
|
+
|
|
128
|
+
let passed = 0;
|
|
129
|
+
const total = checks.length;
|
|
130
|
+
|
|
131
|
+
for (const check of checks) {
|
|
132
|
+
try {
|
|
133
|
+
const result = await check.check();
|
|
134
|
+
const icon = result.ok ? color.green('ā
') : color.red('ā');
|
|
135
|
+
const name = check.name.padEnd(22);
|
|
136
|
+
console.log(` ${icon} ${name} ${result.detail}`);
|
|
137
|
+
if (!result.ok && result.fix) {
|
|
138
|
+
console.log(` ā ${result.fix}`);
|
|
139
|
+
}
|
|
140
|
+
if (result.ok) passed++;
|
|
141
|
+
} catch (err) {
|
|
142
|
+
const name = check.name.padEnd(22);
|
|
143
|
+
console.log(` ${color.red('ā')} ${name} Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
console.log(`\n Result: ${passed}/${total} checks passed`);
|
|
148
|
+
if (passed < total) {
|
|
149
|
+
console.log(`\n Fix the issues above to get the best experience.`);
|
|
150
|
+
} else {
|
|
151
|
+
console.log(`\n ${color.green('All checks passed!')} You're good to go.`);
|
|
152
|
+
}
|
|
153
|
+
console.log();
|
|
154
|
+
|
|
155
|
+
return { passed, total };
|
|
156
|
+
}
|