opc-agent 0.3.0 → 0.5.0

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.
Files changed (53) hide show
  1. package/README.md +20 -0
  2. package/dist/channels/voice.d.ts +43 -0
  3. package/dist/channels/voice.js +67 -0
  4. package/dist/channels/webhook.d.ts +40 -0
  5. package/dist/channels/webhook.js +193 -0
  6. package/dist/cli.js +143 -13
  7. package/dist/core/a2a.d.ts +46 -0
  8. package/dist/core/a2a.js +99 -0
  9. package/dist/core/hitl.d.ts +41 -0
  10. package/dist/core/hitl.js +100 -0
  11. package/dist/core/performance.d.ts +50 -0
  12. package/dist/core/performance.js +148 -0
  13. package/dist/core/versioning.d.ts +29 -0
  14. package/dist/core/versioning.js +114 -0
  15. package/dist/core/workflow.d.ts +59 -0
  16. package/dist/core/workflow.js +174 -0
  17. package/dist/deploy/openclaw.d.ts +14 -0
  18. package/dist/deploy/openclaw.js +208 -0
  19. package/dist/index.d.ts +13 -0
  20. package/dist/index.js +18 -1
  21. package/dist/schema/oad.d.ts +352 -15
  22. package/dist/schema/oad.js +41 -2
  23. package/dist/templates/executive-assistant.d.ts +20 -0
  24. package/dist/templates/executive-assistant.js +70 -0
  25. package/dist/templates/financial-advisor.d.ts +15 -0
  26. package/dist/templates/financial-advisor.js +60 -0
  27. package/dist/templates/legal-assistant.d.ts +15 -0
  28. package/dist/templates/legal-assistant.js +70 -0
  29. package/examples/customer-service-demo/README.md +90 -0
  30. package/examples/customer-service-demo/oad.yaml +107 -0
  31. package/package.json +46 -46
  32. package/src/channels/voice.ts +106 -0
  33. package/src/channels/webhook.ts +199 -0
  34. package/src/cli.ts +524 -384
  35. package/src/core/a2a.ts +143 -0
  36. package/src/core/hitl.ts +138 -0
  37. package/src/core/performance.ts +187 -0
  38. package/src/core/versioning.ts +106 -0
  39. package/src/core/workflow.ts +235 -0
  40. package/src/deploy/openclaw.ts +200 -0
  41. package/src/index.ts +15 -0
  42. package/src/schema/oad.ts +45 -1
  43. package/src/templates/executive-assistant.ts +71 -0
  44. package/src/templates/financial-advisor.ts +60 -0
  45. package/src/templates/legal-assistant.ts +71 -0
  46. package/tests/a2a.test.ts +66 -0
  47. package/tests/hitl.test.ts +71 -0
  48. package/tests/performance.test.ts +115 -0
  49. package/tests/templates.test.ts +77 -0
  50. package/tests/versioning.test.ts +75 -0
  51. package/tests/voice.test.ts +61 -0
  52. package/tests/webhook.test.ts +29 -0
  53. package/tests/workflow.test.ts +143 -0
@@ -0,0 +1,143 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest';
2
+ import { WorkflowEngine, WorkflowDefinition } from '../src/core/workflow';
3
+ import { BaseSkill } from '../src/skills/base';
4
+ import type { AgentContext, Message, SkillResult, MemoryStore } from '../src/core/types';
5
+
6
+ class EchoSkill extends BaseSkill {
7
+ name = 'echo';
8
+ description = 'Echo input';
9
+ async execute(_ctx: AgentContext, msg: Message): Promise<SkillResult> {
10
+ return this.match(`echo:${msg.content}`, 1.0);
11
+ }
12
+ }
13
+
14
+ class UpperSkill extends BaseSkill {
15
+ name = 'upper';
16
+ description = 'Uppercase';
17
+ async execute(_ctx: AgentContext, msg: Message): Promise<SkillResult> {
18
+ return this.match(msg.content.toUpperCase(), 1.0);
19
+ }
20
+ }
21
+
22
+ class FailSkill extends BaseSkill {
23
+ name = 'fail';
24
+ description = 'Always fails';
25
+ async execute(): Promise<SkillResult> {
26
+ throw new Error('intentional failure');
27
+ }
28
+ }
29
+
30
+ const mockMemory: MemoryStore = {
31
+ get: async () => null,
32
+ set: async () => {},
33
+ getConversation: async () => [],
34
+ addMessage: async () => {},
35
+ clear: async () => {},
36
+ };
37
+
38
+ const mockContext: AgentContext = {
39
+ agentName: 'test',
40
+ sessionId: 'test-session',
41
+ messages: [],
42
+ memory: mockMemory,
43
+ metadata: {},
44
+ };
45
+
46
+ describe('WorkflowEngine', () => {
47
+ let engine: WorkflowEngine;
48
+
49
+ beforeEach(() => {
50
+ engine = new WorkflowEngine();
51
+ engine.registerSkill(new EchoSkill());
52
+ engine.registerSkill(new UpperSkill());
53
+ engine.registerSkill(new FailSkill());
54
+ });
55
+
56
+ it('should register and list workflows', () => {
57
+ const wf: WorkflowDefinition = { name: 'test', steps: [] };
58
+ engine.registerWorkflow(wf);
59
+ expect(engine.listWorkflows()).toHaveLength(1);
60
+ expect(engine.getWorkflow('test')).toBeDefined();
61
+ });
62
+
63
+ it('should run sequential steps', async () => {
64
+ const wf: WorkflowDefinition = {
65
+ name: 'seq',
66
+ steps: [
67
+ { id: 's1', type: 'skill', name: 'echo' },
68
+ { id: 's2', type: 'skill', name: 'upper' },
69
+ ],
70
+ };
71
+ engine.registerWorkflow(wf);
72
+ const result = await engine.run('seq', mockContext, 'hello');
73
+ expect(result.status).toBe('completed');
74
+ expect(result.steps).toHaveLength(2);
75
+ });
76
+
77
+ it('should handle parallel steps', async () => {
78
+ const wf: WorkflowDefinition = {
79
+ name: 'par',
80
+ steps: [{
81
+ id: 'p1', type: 'parallel', name: 'parallel',
82
+ parallel: [
83
+ { id: 's1', type: 'skill', name: 'echo' },
84
+ { id: 's2', type: 'skill', name: 'upper' },
85
+ ],
86
+ }],
87
+ };
88
+ engine.registerWorkflow(wf);
89
+ const result = await engine.run('par', mockContext, 'test');
90
+ expect(result.status).toBe('completed');
91
+ });
92
+
93
+ it('should handle conditional branching', async () => {
94
+ const wf: WorkflowDefinition = {
95
+ name: 'cond',
96
+ steps: [{
97
+ id: 'c1', type: 'condition', name: 'check',
98
+ condition: 'contains:hello',
99
+ branches: {
100
+ if: [{ id: 's1', type: 'skill', name: 'echo' }],
101
+ else: [{ id: 's2', type: 'skill', name: 'upper' }],
102
+ },
103
+ }],
104
+ };
105
+ engine.registerWorkflow(wf);
106
+ const r1 = await engine.run('cond', mockContext, 'hello world');
107
+ expect(r1.steps.find(s => s.stepId === 's1')).toBeDefined();
108
+ });
109
+
110
+ it('should handle step failures with stop policy', async () => {
111
+ const wf: WorkflowDefinition = {
112
+ name: 'fail-wf',
113
+ onError: 'stop',
114
+ steps: [
115
+ { id: 's1', type: 'skill', name: 'fail' },
116
+ { id: 's2', type: 'skill', name: 'echo' },
117
+ ],
118
+ };
119
+ engine.registerWorkflow(wf);
120
+ const result = await engine.run('fail-wf', mockContext, 'test');
121
+ expect(result.status).toBe('failed');
122
+ });
123
+
124
+ it('should retry failed steps', async () => {
125
+ const wf: WorkflowDefinition = {
126
+ name: 'retry-wf',
127
+ steps: [{ id: 's1', type: 'skill', name: 'fail', retries: 2 }],
128
+ };
129
+ engine.registerWorkflow(wf);
130
+ const result = await engine.run('retry-wf', mockContext, 'test');
131
+ expect(result.steps[0].status).toBe('error');
132
+ });
133
+
134
+ it('should throw on unknown workflow', async () => {
135
+ await expect(engine.run('nonexistent', mockContext)).rejects.toThrow();
136
+ });
137
+
138
+ it('should unregister workflows', () => {
139
+ engine.registerWorkflow({ name: 'temp', steps: [] });
140
+ engine.unregisterWorkflow('temp');
141
+ expect(engine.getWorkflow('temp')).toBeUndefined();
142
+ });
143
+ });