opc-agent 1.1.0 → 1.1.2

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 (142) hide show
  1. package/CHANGELOG.md +51 -51
  2. package/CONTRIBUTING.md +75 -75
  3. package/README.md +341 -101
  4. package/README.zh-CN.md +382 -55
  5. package/dist/channels/web.js +256 -256
  6. package/dist/cli.js +1 -32
  7. package/dist/deploy/hermes.js +22 -22
  8. package/dist/deploy/openclaw.js +31 -31
  9. package/dist/i18n/index.js +60 -9
  10. package/dist/templates/code-reviewer.js +5 -5
  11. package/dist/templates/customer-service.js +2 -2
  12. package/dist/templates/data-analyst.js +5 -5
  13. package/dist/templates/knowledge-base.js +2 -2
  14. package/dist/templates/sales-assistant.js +4 -4
  15. package/dist/templates/teacher.js +6 -6
  16. package/docs/.vitepress/config.ts +103 -92
  17. package/docs/api/cli.md +48 -48
  18. package/docs/api/oad-schema.md +64 -64
  19. package/docs/api/sdk.md +80 -80
  20. package/docs/guide/concepts.md +51 -51
  21. package/docs/guide/configuration.md +79 -79
  22. package/docs/guide/deployment.md +42 -42
  23. package/docs/guide/getting-started.md +44 -44
  24. package/docs/guide/templates.md +28 -28
  25. package/docs/guide/testing.md +84 -84
  26. package/docs/index.md +27 -27
  27. package/docs/zh/api/cli.md +54 -0
  28. package/docs/zh/api/oad-schema.md +87 -3
  29. package/docs/zh/api/sdk.md +102 -0
  30. package/docs/zh/guide/concepts.md +104 -28
  31. package/docs/zh/guide/configuration.md +135 -39
  32. package/docs/zh/guide/deployment.md +81 -3
  33. package/docs/zh/guide/getting-started.md +82 -58
  34. package/docs/zh/guide/templates.md +84 -22
  35. package/docs/zh/guide/testing.md +88 -18
  36. package/docs/zh/index.md +27 -27
  37. package/examples/customer-service-demo/README.md +90 -90
  38. package/examples/customer-service-demo/oad.yaml +107 -107
  39. package/package.json +1 -1
  40. package/src/analytics/index.ts +66 -66
  41. package/src/channels/discord.ts +192 -192
  42. package/src/channels/email.ts +177 -177
  43. package/src/channels/feishu.ts +236 -236
  44. package/src/channels/index.ts +15 -15
  45. package/src/channels/slack.ts +160 -160
  46. package/src/channels/telegram.ts +90 -90
  47. package/src/channels/voice.ts +106 -106
  48. package/src/channels/web.ts +596 -596
  49. package/src/channels/webhook.ts +199 -199
  50. package/src/channels/websocket.ts +87 -87
  51. package/src/channels/wechat.ts +149 -149
  52. package/src/cli.ts +1 -35
  53. package/src/core/a2a.ts +143 -143
  54. package/src/core/agent.ts +152 -152
  55. package/src/core/analytics-engine.ts +186 -186
  56. package/src/core/auth.ts +57 -57
  57. package/src/core/cache.ts +141 -141
  58. package/src/core/compose.ts +77 -77
  59. package/src/core/config.ts +14 -14
  60. package/src/core/errors.ts +148 -148
  61. package/src/core/hitl.ts +138 -138
  62. package/src/core/knowledge.ts +210 -210
  63. package/src/core/logger.ts +57 -57
  64. package/src/core/orchestrator.ts +215 -215
  65. package/src/core/performance.ts +187 -187
  66. package/src/core/rate-limiter.ts +128 -128
  67. package/src/core/room.ts +109 -109
  68. package/src/core/runtime.ts +152 -152
  69. package/src/core/sandbox.ts +101 -101
  70. package/src/core/security.ts +171 -171
  71. package/src/core/types.ts +68 -68
  72. package/src/core/versioning.ts +106 -106
  73. package/src/core/watch.ts +178 -178
  74. package/src/core/workflow.ts +235 -235
  75. package/src/deploy/hermes.ts +156 -156
  76. package/src/deploy/openclaw.ts +200 -200
  77. package/src/dtv/data.ts +29 -29
  78. package/src/dtv/trust.ts +43 -43
  79. package/src/dtv/value.ts +47 -47
  80. package/src/i18n/index.ts +216 -165
  81. package/src/index.ts +110 -110
  82. package/src/marketplace/index.ts +223 -223
  83. package/src/memory/deepbrain.ts +108 -108
  84. package/src/memory/index.ts +34 -34
  85. package/src/plugins/index.ts +208 -208
  86. package/src/providers/index.ts +183 -183
  87. package/src/schema/oad.ts +155 -155
  88. package/src/skills/base.ts +16 -16
  89. package/src/skills/document.ts +100 -100
  90. package/src/skills/http.ts +35 -35
  91. package/src/skills/index.ts +27 -27
  92. package/src/skills/scheduler.ts +80 -80
  93. package/src/skills/webhook-trigger.ts +59 -59
  94. package/src/templates/code-reviewer.ts +34 -34
  95. package/src/templates/customer-service.ts +80 -80
  96. package/src/templates/data-analyst.ts +70 -70
  97. package/src/templates/executive-assistant.ts +71 -71
  98. package/src/templates/financial-advisor.ts +60 -60
  99. package/src/templates/knowledge-base.ts +31 -31
  100. package/src/templates/legal-assistant.ts +71 -71
  101. package/src/templates/sales-assistant.ts +79 -79
  102. package/src/templates/teacher.ts +79 -79
  103. package/src/testing/index.ts +181 -181
  104. package/src/tools/calculator.ts +73 -73
  105. package/src/tools/datetime.ts +149 -149
  106. package/src/tools/json-transform.ts +187 -187
  107. package/src/tools/mcp.ts +76 -76
  108. package/src/tools/text-analysis.ts +116 -116
  109. package/templates/Dockerfile +15 -15
  110. package/templates/code-reviewer/README.md +27 -27
  111. package/templates/code-reviewer/oad.yaml +41 -41
  112. package/templates/customer-service/README.md +22 -22
  113. package/templates/customer-service/oad.yaml +36 -36
  114. package/templates/docker-compose.yml +21 -21
  115. package/templates/knowledge-base/README.md +28 -28
  116. package/templates/knowledge-base/oad.yaml +38 -38
  117. package/templates/sales-assistant/README.md +26 -26
  118. package/templates/sales-assistant/oad.yaml +43 -43
  119. package/tests/a2a.test.ts +66 -66
  120. package/tests/agent.test.ts +72 -72
  121. package/tests/analytics.test.ts +50 -50
  122. package/tests/channel.test.ts +39 -39
  123. package/tests/e2e.test.ts +134 -134
  124. package/tests/errors.test.ts +83 -83
  125. package/tests/hitl.test.ts +71 -71
  126. package/tests/i18n.test.ts +41 -41
  127. package/tests/mcp.test.ts +54 -54
  128. package/tests/oad.test.ts +68 -68
  129. package/tests/performance.test.ts +115 -115
  130. package/tests/plugin.test.ts +74 -74
  131. package/tests/room.test.ts +106 -106
  132. package/tests/runtime.test.ts +42 -42
  133. package/tests/sandbox.test.ts +46 -46
  134. package/tests/security.test.ts +60 -60
  135. package/tests/templates.test.ts +77 -77
  136. package/tests/v070.test.ts +76 -76
  137. package/tests/versioning.test.ts +75 -75
  138. package/tests/voice.test.ts +61 -61
  139. package/tests/webhook.test.ts +29 -29
  140. package/tests/workflow.test.ts +143 -143
  141. package/tsconfig.json +19 -19
  142. package/vitest.config.ts +9 -9
@@ -1,183 +1,183 @@
1
- import type { Message } from '../core/types';
2
- import * as https from 'https';
3
- import * as http from 'http';
4
-
5
- export interface LLMProvider {
6
- name: string;
7
- chat(messages: Message[], systemPrompt?: string): Promise<string>;
8
- chatStream(messages: Message[], systemPrompt?: string): AsyncIterable<string>;
9
- }
10
-
11
- interface OpenAIMessage {
12
- role: 'system' | 'user' | 'assistant';
13
- content: string;
14
- }
15
-
16
- function getApiKey(): string {
17
- return process.env.OPC_LLM_API_KEY || process.env.OPENAI_API_KEY || '';
18
- }
19
-
20
- function getBaseUrl(): string {
21
- return process.env.OPC_LLM_BASE_URL || 'https://api.openai.com/v1';
22
- }
23
-
24
- class OpenAICompatibleProvider implements LLMProvider {
25
- name: string;
26
- private model: string;
27
- private baseUrl: string;
28
- private apiKey: string;
29
-
30
- constructor(name: string, model: string, baseUrl?: string, apiKey?: string) {
31
- this.name = name;
32
- this.model = model;
33
- this.baseUrl = baseUrl || getBaseUrl();
34
- this.apiKey = apiKey || getApiKey();
35
- }
36
-
37
- private formatMessages(messages: Message[], systemPrompt?: string): OpenAIMessage[] {
38
- const formatted: OpenAIMessage[] = [];
39
- if (systemPrompt) {
40
- formatted.push({ role: 'system', content: systemPrompt });
41
- }
42
- for (const m of messages) {
43
- formatted.push({ role: m.role as 'user' | 'assistant', content: m.content });
44
- }
45
- return formatted;
46
- }
47
-
48
- private async request(body: any): Promise<any> {
49
- if (!this.apiKey) {
50
- throw new Error('No API key configured. Set OPC_LLM_API_KEY or OPENAI_API_KEY environment variable.');
51
- }
52
-
53
- const url = new URL(`${this.baseUrl}/chat/completions`);
54
- const isHttps = url.protocol === 'https:';
55
- const lib = isHttps ? https : http;
56
-
57
- const postData = JSON.stringify(body);
58
-
59
- return new Promise((resolve, reject) => {
60
- const req = lib.request(
61
- {
62
- hostname: url.hostname,
63
- port: url.port || (isHttps ? 443 : 80),
64
- path: url.pathname,
65
- method: 'POST',
66
- headers: {
67
- 'Content-Type': 'application/json',
68
- Authorization: `Bearer ${this.apiKey}`,
69
- 'Content-Length': Buffer.byteLength(postData),
70
- },
71
- },
72
- (res) => {
73
- let data = '';
74
- res.on('data', (chunk: Buffer) => (data += chunk.toString()));
75
- res.on('end', () => {
76
- if (res.statusCode && res.statusCode >= 400) {
77
- reject(new Error(`LLM API error ${res.statusCode}: ${data}`));
78
- return;
79
- }
80
- try {
81
- resolve(JSON.parse(data));
82
- } catch {
83
- reject(new Error(`Invalid JSON response: ${data.slice(0, 200)}`));
84
- }
85
- });
86
- },
87
- );
88
- req.on('error', reject);
89
- req.write(postData);
90
- req.end();
91
- });
92
- }
93
-
94
- async chat(messages: Message[], systemPrompt?: string): Promise<string> {
95
- if (!this.apiKey) {
96
- // Stub mode when no API key
97
- const last = messages[messages.length - 1];
98
- return `[${this.name}/${this.model} - no API key] Echo: ${last?.content ?? ''}`;
99
- }
100
- const formatted = this.formatMessages(messages, systemPrompt);
101
- const result = await this.request({
102
- model: this.model,
103
- messages: formatted,
104
- temperature: 0.7,
105
- max_tokens: 2048,
106
- });
107
- return result.choices?.[0]?.message?.content ?? '';
108
- }
109
-
110
- async *chatStream(messages: Message[], systemPrompt?: string): AsyncIterable<string> {
111
- if (!this.apiKey) {
112
- const last = messages[messages.length - 1];
113
- yield `[${this.name}/${this.model} - no API key] Echo: ${last?.content ?? ''}`;
114
- return;
115
- }
116
-
117
- const formatted = this.formatMessages(messages, systemPrompt);
118
- const url = new URL(`${this.baseUrl}/chat/completions`);
119
- const isHttps = url.protocol === 'https:';
120
- const lib = isHttps ? https : http;
121
- const postData = JSON.stringify({
122
- model: this.model,
123
- messages: formatted,
124
- temperature: 0.7,
125
- max_tokens: 2048,
126
- stream: true,
127
- });
128
-
129
- const response = await new Promise<http.IncomingMessage>((resolve, reject) => {
130
- const req = lib.request(
131
- {
132
- hostname: url.hostname,
133
- port: url.port || (isHttps ? 443 : 80),
134
- path: url.pathname,
135
- method: 'POST',
136
- headers: {
137
- 'Content-Type': 'application/json',
138
- Authorization: `Bearer ${this.apiKey}`,
139
- 'Content-Length': Buffer.byteLength(postData),
140
- },
141
- },
142
- resolve,
143
- );
144
- req.on('error', reject);
145
- req.write(postData);
146
- req.end();
147
- });
148
-
149
- if (response.statusCode && response.statusCode >= 400) {
150
- let data = '';
151
- for await (const chunk of response) data += chunk.toString();
152
- throw new Error(`LLM API error ${response.statusCode}: ${data}`);
153
- }
154
-
155
- let buffer = '';
156
- for await (const chunk of response) {
157
- buffer += chunk.toString();
158
- const lines = buffer.split('\n');
159
- buffer = lines.pop() ?? '';
160
-
161
- for (const line of lines) {
162
- const trimmed = line.trim();
163
- if (!trimmed || !trimmed.startsWith('data: ')) continue;
164
- const data = trimmed.slice(6);
165
- if (data === '[DONE]') return;
166
- try {
167
- const parsed = JSON.parse(data);
168
- const content = parsed.choices?.[0]?.delta?.content;
169
- if (content) yield content;
170
- } catch {
171
- // skip malformed lines
172
- }
173
- }
174
- }
175
- }
176
- }
177
-
178
- export function createProvider(name: string = 'openai', model?: string, baseUrl?: string, apiKey?: string): LLMProvider {
179
- const finalModel = model || process.env.OPC_LLM_MODEL || 'gpt-4o-mini';
180
- return new OpenAICompatibleProvider(name, finalModel, baseUrl, apiKey);
181
- }
182
-
183
- export const SUPPORTED_PROVIDERS = ['openai', 'deepseek', 'qwen'] as const;
1
+ import type { Message } from '../core/types';
2
+ import * as https from 'https';
3
+ import * as http from 'http';
4
+
5
+ export interface LLMProvider {
6
+ name: string;
7
+ chat(messages: Message[], systemPrompt?: string): Promise<string>;
8
+ chatStream(messages: Message[], systemPrompt?: string): AsyncIterable<string>;
9
+ }
10
+
11
+ interface OpenAIMessage {
12
+ role: 'system' | 'user' | 'assistant';
13
+ content: string;
14
+ }
15
+
16
+ function getApiKey(): string {
17
+ return process.env.OPC_LLM_API_KEY || process.env.OPENAI_API_KEY || '';
18
+ }
19
+
20
+ function getBaseUrl(): string {
21
+ return process.env.OPC_LLM_BASE_URL || 'https://api.openai.com/v1';
22
+ }
23
+
24
+ class OpenAICompatibleProvider implements LLMProvider {
25
+ name: string;
26
+ private model: string;
27
+ private baseUrl: string;
28
+ private apiKey: string;
29
+
30
+ constructor(name: string, model: string, baseUrl?: string, apiKey?: string) {
31
+ this.name = name;
32
+ this.model = model;
33
+ this.baseUrl = baseUrl || getBaseUrl();
34
+ this.apiKey = apiKey || getApiKey();
35
+ }
36
+
37
+ private formatMessages(messages: Message[], systemPrompt?: string): OpenAIMessage[] {
38
+ const formatted: OpenAIMessage[] = [];
39
+ if (systemPrompt) {
40
+ formatted.push({ role: 'system', content: systemPrompt });
41
+ }
42
+ for (const m of messages) {
43
+ formatted.push({ role: m.role as 'user' | 'assistant', content: m.content });
44
+ }
45
+ return formatted;
46
+ }
47
+
48
+ private async request(body: any): Promise<any> {
49
+ if (!this.apiKey) {
50
+ throw new Error('No API key configured. Set OPC_LLM_API_KEY or OPENAI_API_KEY environment variable.');
51
+ }
52
+
53
+ const url = new URL(`${this.baseUrl}/chat/completions`);
54
+ const isHttps = url.protocol === 'https:';
55
+ const lib = isHttps ? https : http;
56
+
57
+ const postData = JSON.stringify(body);
58
+
59
+ return new Promise((resolve, reject) => {
60
+ const req = lib.request(
61
+ {
62
+ hostname: url.hostname,
63
+ port: url.port || (isHttps ? 443 : 80),
64
+ path: url.pathname,
65
+ method: 'POST',
66
+ headers: {
67
+ 'Content-Type': 'application/json',
68
+ Authorization: `Bearer ${this.apiKey}`,
69
+ 'Content-Length': Buffer.byteLength(postData),
70
+ },
71
+ },
72
+ (res) => {
73
+ let data = '';
74
+ res.on('data', (chunk: Buffer) => (data += chunk.toString()));
75
+ res.on('end', () => {
76
+ if (res.statusCode && res.statusCode >= 400) {
77
+ reject(new Error(`LLM API error ${res.statusCode}: ${data}`));
78
+ return;
79
+ }
80
+ try {
81
+ resolve(JSON.parse(data));
82
+ } catch {
83
+ reject(new Error(`Invalid JSON response: ${data.slice(0, 200)}`));
84
+ }
85
+ });
86
+ },
87
+ );
88
+ req.on('error', reject);
89
+ req.write(postData);
90
+ req.end();
91
+ });
92
+ }
93
+
94
+ async chat(messages: Message[], systemPrompt?: string): Promise<string> {
95
+ if (!this.apiKey) {
96
+ // Stub mode when no API key
97
+ const last = messages[messages.length - 1];
98
+ return `[${this.name}/${this.model} - no API key] Echo: ${last?.content ?? ''}`;
99
+ }
100
+ const formatted = this.formatMessages(messages, systemPrompt);
101
+ const result = await this.request({
102
+ model: this.model,
103
+ messages: formatted,
104
+ temperature: 0.7,
105
+ max_tokens: 2048,
106
+ });
107
+ return result.choices?.[0]?.message?.content ?? '';
108
+ }
109
+
110
+ async *chatStream(messages: Message[], systemPrompt?: string): AsyncIterable<string> {
111
+ if (!this.apiKey) {
112
+ const last = messages[messages.length - 1];
113
+ yield `[${this.name}/${this.model} - no API key] Echo: ${last?.content ?? ''}`;
114
+ return;
115
+ }
116
+
117
+ const formatted = this.formatMessages(messages, systemPrompt);
118
+ const url = new URL(`${this.baseUrl}/chat/completions`);
119
+ const isHttps = url.protocol === 'https:';
120
+ const lib = isHttps ? https : http;
121
+ const postData = JSON.stringify({
122
+ model: this.model,
123
+ messages: formatted,
124
+ temperature: 0.7,
125
+ max_tokens: 2048,
126
+ stream: true,
127
+ });
128
+
129
+ const response = await new Promise<http.IncomingMessage>((resolve, reject) => {
130
+ const req = lib.request(
131
+ {
132
+ hostname: url.hostname,
133
+ port: url.port || (isHttps ? 443 : 80),
134
+ path: url.pathname,
135
+ method: 'POST',
136
+ headers: {
137
+ 'Content-Type': 'application/json',
138
+ Authorization: `Bearer ${this.apiKey}`,
139
+ 'Content-Length': Buffer.byteLength(postData),
140
+ },
141
+ },
142
+ resolve,
143
+ );
144
+ req.on('error', reject);
145
+ req.write(postData);
146
+ req.end();
147
+ });
148
+
149
+ if (response.statusCode && response.statusCode >= 400) {
150
+ let data = '';
151
+ for await (const chunk of response) data += chunk.toString();
152
+ throw new Error(`LLM API error ${response.statusCode}: ${data}`);
153
+ }
154
+
155
+ let buffer = '';
156
+ for await (const chunk of response) {
157
+ buffer += chunk.toString();
158
+ const lines = buffer.split('\n');
159
+ buffer = lines.pop() ?? '';
160
+
161
+ for (const line of lines) {
162
+ const trimmed = line.trim();
163
+ if (!trimmed || !trimmed.startsWith('data: ')) continue;
164
+ const data = trimmed.slice(6);
165
+ if (data === '[DONE]') return;
166
+ try {
167
+ const parsed = JSON.parse(data);
168
+ const content = parsed.choices?.[0]?.delta?.content;
169
+ if (content) yield content;
170
+ } catch {
171
+ // skip malformed lines
172
+ }
173
+ }
174
+ }
175
+ }
176
+ }
177
+
178
+ export function createProvider(name: string = 'openai', model?: string, baseUrl?: string, apiKey?: string): LLMProvider {
179
+ const finalModel = model || process.env.OPC_LLM_MODEL || 'gpt-4o-mini';
180
+ return new OpenAICompatibleProvider(name, finalModel, baseUrl, apiKey);
181
+ }
182
+
183
+ export const SUPPORTED_PROVIDERS = ['openai', 'deepseek', 'qwen'] as const;
package/src/schema/oad.ts CHANGED
@@ -1,155 +1,155 @@
1
- import { z } from 'zod';
2
-
3
- // ─── OAD Schema v1 ───────────────────────────────────────────
4
-
5
- export const SkillRefSchema = z.object({
6
- name: z.string(),
7
- description: z.string().optional(),
8
- config: z.record(z.unknown()).optional(),
9
- });
10
-
11
- export const WorkflowStepSchema: z.ZodType<any> = z.lazy(() => z.object({
12
- id: z.string(),
13
- type: z.enum(['skill', 'tool', 'agent', 'condition', 'parallel']),
14
- name: z.string(),
15
- config: z.record(z.unknown()).optional(),
16
- condition: z.string().optional(),
17
- branches: z.object({ if: z.array(WorkflowStepSchema), else: z.array(WorkflowStepSchema).optional() }).optional(),
18
- parallel: z.array(WorkflowStepSchema).optional(),
19
- timeout: z.number().optional(),
20
- retries: z.number().optional(),
21
- }));
22
-
23
- export const WorkflowSchema = z.object({
24
- name: z.string(),
25
- description: z.string().optional(),
26
- version: z.string().optional(),
27
- steps: z.array(WorkflowStepSchema).default([]),
28
- onError: z.enum(['stop', 'skip', 'retry']).optional(),
29
- });
30
-
31
- export const VoiceSchema = z.object({
32
- enabled: z.boolean().default(false),
33
- sttProvider: z.string().optional(),
34
- ttsProvider: z.string().optional(),
35
- language: z.string().optional(),
36
- });
37
-
38
- export const WebhookSchema = z.object({
39
- path: z.string().optional(),
40
- secret: z.string().optional(),
41
- retryAttempts: z.number().optional(),
42
- });
43
-
44
- export const HITLSchema = z.object({
45
- enabled: z.boolean().default(false),
46
- requireApproval: z.array(z.string()).default([]),
47
- defaultTimeoutMs: z.number().default(60000),
48
- defaultAction: z.enum(['approve', 'deny']).default('deny'),
49
- });
50
-
51
- export const PluginRefSchema = z.object({
52
- name: z.string(),
53
- config: z.record(z.unknown()).optional(),
54
- });
55
-
56
- export const AuthSchema = z.object({
57
- enabled: z.boolean().default(false),
58
- apiKeys: z.array(z.string()).default([]),
59
- sessionIsolation: z.boolean().default(true),
60
- });
61
-
62
- export const ChannelSchema = z.object({
63
- type: z.enum(['web', 'websocket', 'telegram', 'cli', 'voice', 'webhook']),
64
- port: z.number().optional(),
65
- config: z.record(z.unknown()).optional(),
66
- });
67
-
68
- export const LongTermMemorySchema = z.object({
69
- provider: z.enum(['in-memory', 'deepbrain']).default('in-memory'),
70
- collection: z.string().optional(),
71
- config: z.record(z.unknown()).optional(),
72
- });
73
-
74
- export const MemorySchema = z.object({
75
- shortTerm: z.boolean().default(true),
76
- longTerm: z.union([z.boolean(), LongTermMemorySchema]).default(false),
77
- provider: z.string().optional(),
78
- });
79
-
80
- export const TrustLevel = z.enum(['sandbox', 'verified', 'certified', 'listed']);
81
-
82
- export const DTVSchema = z.object({
83
- trust: z.object({
84
- level: TrustLevel.default('sandbox'),
85
- }).optional(),
86
- value: z.object({
87
- metrics: z.array(z.string()).default([]),
88
- }).optional(),
89
- });
90
-
91
- export const ProviderSchema = z.object({
92
- default: z.string().default('deepseek'),
93
- allowed: z.array(z.string()).default(['openai', 'deepseek', 'qwen']),
94
- });
95
-
96
- export const MarketplaceSchema = z.object({
97
- certified: z.boolean().default(false),
98
- category: z.string().optional(),
99
- pricing: z.enum(['free', 'freemium', 'paid', 'enterprise']).optional(),
100
- tags: z.array(z.string()).optional(),
101
- });
102
-
103
- export const MetadataSchema = z.object({
104
- name: z.string(),
105
- version: z.string().default('1.0.0'),
106
- description: z.string().optional(),
107
- author: z.string().optional(),
108
- license: z.string().default('Apache-2.0'),
109
- marketplace: MarketplaceSchema.optional(),
110
- });
111
-
112
- export const RoomSchema = z.object({
113
- name: z.string(),
114
- agents: z.array(z.string()).default([]),
115
- topics: z.array(z.string()).default([]),
116
- });
117
-
118
- export const StreamingSchema = z.object({
119
- enabled: z.boolean().default(false),
120
- chunkSize: z.number().optional(),
121
- });
122
-
123
- export const SpecSchema = z.object({
124
- provider: ProviderSchema.optional(),
125
- model: z.string().default('deepseek-chat'),
126
- systemPrompt: z.string().optional(),
127
- skills: z.array(SkillRefSchema).default([]),
128
- channels: z.array(ChannelSchema).default([]),
129
- memory: MemorySchema.optional(),
130
- dtv: DTVSchema.optional(),
131
- room: RoomSchema.optional(),
132
- streaming: z.union([z.boolean(), StreamingSchema]).default(false),
133
- locale: z.enum(['en', 'zh-CN']).optional(),
134
- workflows: z.array(WorkflowSchema).optional(),
135
- voice: VoiceSchema.optional(),
136
- webhook: WebhookSchema.optional(),
137
- hitl: HITLSchema.optional(),
138
- auth: AuthSchema.optional(),
139
- plugins: z.array(PluginRefSchema).optional(),
140
- });
141
-
142
- export const OADSchema = z.object({
143
- apiVersion: z.literal('opc/v1'),
144
- kind: z.literal('Agent'),
145
- metadata: MetadataSchema,
146
- spec: SpecSchema,
147
- });
148
-
149
- export type OADDocument = z.infer<typeof OADSchema>;
150
- export type SkillRef = z.infer<typeof SkillRefSchema>;
151
- export type Channel = z.infer<typeof ChannelSchema>;
152
- export type Metadata = z.infer<typeof MetadataSchema>;
153
- export type Spec = z.infer<typeof SpecSchema>;
154
- export type DTVConfig = z.infer<typeof DTVSchema>;
155
- export type TrustLevelType = z.infer<typeof TrustLevel>;
1
+ import { z } from 'zod';
2
+
3
+ // ─── OAD Schema v1 ───────────────────────────────────────────
4
+
5
+ export const SkillRefSchema = z.object({
6
+ name: z.string(),
7
+ description: z.string().optional(),
8
+ config: z.record(z.unknown()).optional(),
9
+ });
10
+
11
+ export const WorkflowStepSchema: z.ZodType<any> = z.lazy(() => z.object({
12
+ id: z.string(),
13
+ type: z.enum(['skill', 'tool', 'agent', 'condition', 'parallel']),
14
+ name: z.string(),
15
+ config: z.record(z.unknown()).optional(),
16
+ condition: z.string().optional(),
17
+ branches: z.object({ if: z.array(WorkflowStepSchema), else: z.array(WorkflowStepSchema).optional() }).optional(),
18
+ parallel: z.array(WorkflowStepSchema).optional(),
19
+ timeout: z.number().optional(),
20
+ retries: z.number().optional(),
21
+ }));
22
+
23
+ export const WorkflowSchema = z.object({
24
+ name: z.string(),
25
+ description: z.string().optional(),
26
+ version: z.string().optional(),
27
+ steps: z.array(WorkflowStepSchema).default([]),
28
+ onError: z.enum(['stop', 'skip', 'retry']).optional(),
29
+ });
30
+
31
+ export const VoiceSchema = z.object({
32
+ enabled: z.boolean().default(false),
33
+ sttProvider: z.string().optional(),
34
+ ttsProvider: z.string().optional(),
35
+ language: z.string().optional(),
36
+ });
37
+
38
+ export const WebhookSchema = z.object({
39
+ path: z.string().optional(),
40
+ secret: z.string().optional(),
41
+ retryAttempts: z.number().optional(),
42
+ });
43
+
44
+ export const HITLSchema = z.object({
45
+ enabled: z.boolean().default(false),
46
+ requireApproval: z.array(z.string()).default([]),
47
+ defaultTimeoutMs: z.number().default(60000),
48
+ defaultAction: z.enum(['approve', 'deny']).default('deny'),
49
+ });
50
+
51
+ export const PluginRefSchema = z.object({
52
+ name: z.string(),
53
+ config: z.record(z.unknown()).optional(),
54
+ });
55
+
56
+ export const AuthSchema = z.object({
57
+ enabled: z.boolean().default(false),
58
+ apiKeys: z.array(z.string()).default([]),
59
+ sessionIsolation: z.boolean().default(true),
60
+ });
61
+
62
+ export const ChannelSchema = z.object({
63
+ type: z.enum(['web', 'websocket', 'telegram', 'cli', 'voice', 'webhook']),
64
+ port: z.number().optional(),
65
+ config: z.record(z.unknown()).optional(),
66
+ });
67
+
68
+ export const LongTermMemorySchema = z.object({
69
+ provider: z.enum(['in-memory', 'deepbrain']).default('in-memory'),
70
+ collection: z.string().optional(),
71
+ config: z.record(z.unknown()).optional(),
72
+ });
73
+
74
+ export const MemorySchema = z.object({
75
+ shortTerm: z.boolean().default(true),
76
+ longTerm: z.union([z.boolean(), LongTermMemorySchema]).default(false),
77
+ provider: z.string().optional(),
78
+ });
79
+
80
+ export const TrustLevel = z.enum(['sandbox', 'verified', 'certified', 'listed']);
81
+
82
+ export const DTVSchema = z.object({
83
+ trust: z.object({
84
+ level: TrustLevel.default('sandbox'),
85
+ }).optional(),
86
+ value: z.object({
87
+ metrics: z.array(z.string()).default([]),
88
+ }).optional(),
89
+ });
90
+
91
+ export const ProviderSchema = z.object({
92
+ default: z.string().default('deepseek'),
93
+ allowed: z.array(z.string()).default(['openai', 'deepseek', 'qwen']),
94
+ });
95
+
96
+ export const MarketplaceSchema = z.object({
97
+ certified: z.boolean().default(false),
98
+ category: z.string().optional(),
99
+ pricing: z.enum(['free', 'freemium', 'paid', 'enterprise']).optional(),
100
+ tags: z.array(z.string()).optional(),
101
+ });
102
+
103
+ export const MetadataSchema = z.object({
104
+ name: z.string(),
105
+ version: z.string().default('1.0.0'),
106
+ description: z.string().optional(),
107
+ author: z.string().optional(),
108
+ license: z.string().default('Apache-2.0'),
109
+ marketplace: MarketplaceSchema.optional(),
110
+ });
111
+
112
+ export const RoomSchema = z.object({
113
+ name: z.string(),
114
+ agents: z.array(z.string()).default([]),
115
+ topics: z.array(z.string()).default([]),
116
+ });
117
+
118
+ export const StreamingSchema = z.object({
119
+ enabled: z.boolean().default(false),
120
+ chunkSize: z.number().optional(),
121
+ });
122
+
123
+ export const SpecSchema = z.object({
124
+ provider: ProviderSchema.optional(),
125
+ model: z.string().default('deepseek-chat'),
126
+ systemPrompt: z.string().optional(),
127
+ skills: z.array(SkillRefSchema).default([]),
128
+ channels: z.array(ChannelSchema).default([]),
129
+ memory: MemorySchema.optional(),
130
+ dtv: DTVSchema.optional(),
131
+ room: RoomSchema.optional(),
132
+ streaming: z.union([z.boolean(), StreamingSchema]).default(false),
133
+ locale: z.enum(['en', 'zh-CN']).optional(),
134
+ workflows: z.array(WorkflowSchema).optional(),
135
+ voice: VoiceSchema.optional(),
136
+ webhook: WebhookSchema.optional(),
137
+ hitl: HITLSchema.optional(),
138
+ auth: AuthSchema.optional(),
139
+ plugins: z.array(PluginRefSchema).optional(),
140
+ });
141
+
142
+ export const OADSchema = z.object({
143
+ apiVersion: z.literal('opc/v1'),
144
+ kind: z.literal('Agent'),
145
+ metadata: MetadataSchema,
146
+ spec: SpecSchema,
147
+ });
148
+
149
+ export type OADDocument = z.infer<typeof OADSchema>;
150
+ export type SkillRef = z.infer<typeof SkillRefSchema>;
151
+ export type Channel = z.infer<typeof ChannelSchema>;
152
+ export type Metadata = z.infer<typeof MetadataSchema>;
153
+ export type Spec = z.infer<typeof SpecSchema>;
154
+ export type DTVConfig = z.infer<typeof DTVSchema>;
155
+ export type TrustLevelType = z.infer<typeof TrustLevel>;