opc-agent 1.0.0 → 1.1.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/CHANGELOG.md +7 -0
- package/README.md +232 -88
- package/README.zh-CN.md +334 -56
- package/dist/channels/discord.d.ts +44 -0
- package/dist/channels/discord.js +189 -0
- package/dist/channels/feishu.d.ts +47 -0
- package/dist/channels/feishu.js +221 -0
- package/dist/cli.js +1 -32
- package/dist/core/watch.d.ts +73 -0
- package/dist/core/watch.js +106 -0
- package/dist/i18n/index.js +60 -9
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -1
- package/docs/.vitepress/config.ts +13 -2
- package/docs/zh/api/cli.md +54 -0
- package/docs/zh/api/oad-schema.md +86 -2
- package/docs/zh/api/sdk.md +102 -0
- package/docs/zh/guide/concepts.md +90 -14
- package/docs/zh/guide/configuration.md +109 -13
- package/docs/zh/guide/deployment.md +79 -1
- package/docs/zh/guide/getting-started.md +41 -17
- package/docs/zh/guide/templates.md +79 -17
- package/docs/zh/guide/testing.md +75 -5
- package/docs/zh/index.md +13 -13
- package/package.json +1 -1
- package/src/channels/discord.ts +192 -0
- package/src/channels/feishu.ts +236 -0
- package/src/cli.ts +1 -35
- package/src/core/watch.ts +178 -0
- package/src/i18n/index.ts +60 -9
- package/src/index.ts +8 -0
- package/tests/i18n.test.ts +1 -1
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { BaseChannel } from './index';
|
|
2
|
+
import type { Message } from '../core/types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Feishu / Lark Channel — v1.1.0
|
|
6
|
+
*
|
|
7
|
+
* Supports:
|
|
8
|
+
* - Event Subscription (webhook) mode for receiving messages
|
|
9
|
+
* - Bot send via Feishu Open API
|
|
10
|
+
* - URL verification challenge
|
|
11
|
+
* - Message card (interactive) responses
|
|
12
|
+
* - Group chat & P2P messaging
|
|
13
|
+
*
|
|
14
|
+
* Env vars:
|
|
15
|
+
* FEISHU_APP_ID, FEISHU_APP_SECRET — app credentials
|
|
16
|
+
* FEISHU_VERIFICATION_TOKEN — event subscription verification
|
|
17
|
+
* FEISHU_ENCRYPT_KEY — (optional) event encryption key
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export interface FeishuChannelConfig {
|
|
21
|
+
/** Feishu App ID */
|
|
22
|
+
appId?: string;
|
|
23
|
+
/** Feishu App Secret */
|
|
24
|
+
appSecret?: string;
|
|
25
|
+
/** Verification token for event subscription */
|
|
26
|
+
verificationToken?: string;
|
|
27
|
+
/** Encrypt key (optional, for encrypted events) */
|
|
28
|
+
encryptKey?: string;
|
|
29
|
+
/** Webhook server port (default: 3002) */
|
|
30
|
+
port?: number;
|
|
31
|
+
/** API base URL (use 'https://open.larksuite.com' for Lark international) */
|
|
32
|
+
apiBase?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface FeishuTokenCache {
|
|
36
|
+
token: string;
|
|
37
|
+
expiresAt: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class FeishuChannel extends BaseChannel {
|
|
41
|
+
readonly type = 'feishu';
|
|
42
|
+
private config: Required<Pick<FeishuChannelConfig, 'port' | 'apiBase'>> & FeishuChannelConfig;
|
|
43
|
+
private server: import('http').Server | null = null;
|
|
44
|
+
private tokenCache: FeishuTokenCache | null = null;
|
|
45
|
+
private processedEvents = new Set<string>();
|
|
46
|
+
|
|
47
|
+
constructor(config: FeishuChannelConfig = {}) {
|
|
48
|
+
super();
|
|
49
|
+
this.config = {
|
|
50
|
+
appId: config.appId ?? process.env.FEISHU_APP_ID ?? '',
|
|
51
|
+
appSecret: config.appSecret ?? process.env.FEISHU_APP_SECRET ?? '',
|
|
52
|
+
verificationToken: config.verificationToken ?? process.env.FEISHU_VERIFICATION_TOKEN ?? '',
|
|
53
|
+
encryptKey: config.encryptKey ?? process.env.FEISHU_ENCRYPT_KEY,
|
|
54
|
+
port: config.port ?? 3002,
|
|
55
|
+
apiBase: config.apiBase ?? 'https://open.feishu.cn',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async start(): Promise<void> {
|
|
60
|
+
if (!this.config.appId || !this.config.appSecret) {
|
|
61
|
+
console.warn('[FeishuChannel] Missing appId/appSecret. Set FEISHU_APP_ID and FEISHU_APP_SECRET.');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const express = (await import('express')).default;
|
|
66
|
+
const app = express();
|
|
67
|
+
app.use(express.json());
|
|
68
|
+
|
|
69
|
+
// Event subscription endpoint
|
|
70
|
+
app.post('/feishu/event', async (req, res) => {
|
|
71
|
+
try {
|
|
72
|
+
const body = req.body;
|
|
73
|
+
|
|
74
|
+
// URL verification challenge
|
|
75
|
+
if (body.type === 'url_verification') {
|
|
76
|
+
res.json({ challenge: body.challenge });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Deduplicate events
|
|
81
|
+
const eventId = body.header?.event_id;
|
|
82
|
+
if (eventId && this.processedEvents.has(eventId)) {
|
|
83
|
+
res.json({ ok: true });
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (eventId) {
|
|
87
|
+
this.processedEvents.add(eventId);
|
|
88
|
+
// Prune old events (keep last 1000)
|
|
89
|
+
if (this.processedEvents.size > 1000) {
|
|
90
|
+
const arr = [...this.processedEvents];
|
|
91
|
+
this.processedEvents = new Set(arr.slice(-500));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Verify token
|
|
96
|
+
if (this.config.verificationToken && body.header?.token !== this.config.verificationToken) {
|
|
97
|
+
res.status(403).json({ error: 'Invalid verification token' });
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Handle im.message.receive_v1
|
|
102
|
+
const event = body.event;
|
|
103
|
+
if (body.header?.event_type === 'im.message.receive_v1' && this.handler) {
|
|
104
|
+
const msgBody = event?.message;
|
|
105
|
+
if (!msgBody) { res.json({ ok: true }); return; }
|
|
106
|
+
|
|
107
|
+
// Only handle text messages for now
|
|
108
|
+
const msgType = msgBody.message_type;
|
|
109
|
+
let content = '';
|
|
110
|
+
if (msgType === 'text') {
|
|
111
|
+
try {
|
|
112
|
+
const parsed = JSON.parse(msgBody.content);
|
|
113
|
+
content = parsed.text ?? '';
|
|
114
|
+
} catch {
|
|
115
|
+
content = msgBody.content ?? '';
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
// Acknowledge non-text silently
|
|
119
|
+
res.json({ ok: true });
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Strip @bot mentions
|
|
124
|
+
content = content.replace(/@_user_\d+/g, '').trim();
|
|
125
|
+
if (!content) { res.json({ ok: true }); return; }
|
|
126
|
+
|
|
127
|
+
const chatId = msgBody.chat_id;
|
|
128
|
+
const senderId = event.sender?.sender_id?.open_id ?? 'unknown';
|
|
129
|
+
|
|
130
|
+
const msg: Message = {
|
|
131
|
+
id: `feishu_${msgBody.message_id}`,
|
|
132
|
+
role: 'user',
|
|
133
|
+
content,
|
|
134
|
+
timestamp: parseInt(msgBody.create_time, 10) || Date.now(),
|
|
135
|
+
metadata: {
|
|
136
|
+
sessionId: `feishu_${chatId}`,
|
|
137
|
+
chatId,
|
|
138
|
+
userId: senderId,
|
|
139
|
+
platform: 'feishu',
|
|
140
|
+
messageId: msgBody.message_id,
|
|
141
|
+
chatType: msgBody.chat_type, // 'p2p' or 'group'
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const response = await this.handler(msg);
|
|
146
|
+
await this.sendTextMessage(chatId, response.content);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
res.json({ ok: true });
|
|
150
|
+
} catch (err) {
|
|
151
|
+
console.error('[FeishuChannel] Error handling event:', err);
|
|
152
|
+
res.status(500).json({ error: 'Internal error' });
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
app.get('/health', (_req, res) => {
|
|
157
|
+
res.json({ status: 'ok', channel: 'feishu' });
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
this.server = app.listen(this.config.port, () => {
|
|
161
|
+
console.log(`[FeishuChannel] Listening on port ${this.config.port}`);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async stop(): Promise<void> {
|
|
166
|
+
if (this.server) {
|
|
167
|
+
this.server.close();
|
|
168
|
+
this.server = null;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Get tenant access token (cached) */
|
|
173
|
+
private async getAccessToken(): Promise<string> {
|
|
174
|
+
if (this.tokenCache && Date.now() < this.tokenCache.expiresAt) {
|
|
175
|
+
return this.tokenCache.token;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const resp = await fetch(`${this.config.apiBase}/open-apis/auth/v3/tenant_access_token/internal`, {
|
|
179
|
+
method: 'POST',
|
|
180
|
+
headers: { 'Content-Type': 'application/json' },
|
|
181
|
+
body: JSON.stringify({
|
|
182
|
+
app_id: this.config.appId,
|
|
183
|
+
app_secret: this.config.appSecret,
|
|
184
|
+
}),
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const data = await resp.json() as { tenant_access_token: string; expire: number; code: number };
|
|
188
|
+
if (data.code !== 0) {
|
|
189
|
+
throw new Error(`[FeishuChannel] Failed to get access token: ${JSON.stringify(data)}`);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
this.tokenCache = {
|
|
193
|
+
token: data.tenant_access_token,
|
|
194
|
+
expiresAt: Date.now() + (data.expire - 60) * 1000, // refresh 60s early
|
|
195
|
+
};
|
|
196
|
+
return this.tokenCache.token;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Send a text message to a chat */
|
|
200
|
+
async sendTextMessage(chatId: string, text: string): Promise<void> {
|
|
201
|
+
const token = await this.getAccessToken();
|
|
202
|
+
const resp = await fetch(`${this.config.apiBase}/open-apis/im/v1/messages?receive_id_type=chat_id`, {
|
|
203
|
+
method: 'POST',
|
|
204
|
+
headers: {
|
|
205
|
+
'Content-Type': 'application/json',
|
|
206
|
+
'Authorization': `Bearer ${token}`,
|
|
207
|
+
},
|
|
208
|
+
body: JSON.stringify({
|
|
209
|
+
receive_id: chatId,
|
|
210
|
+
msg_type: 'text',
|
|
211
|
+
content: JSON.stringify({ text }),
|
|
212
|
+
}),
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
if (!resp.ok) {
|
|
216
|
+
console.error('[FeishuChannel] Failed to send message:', await resp.text());
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Send an interactive card message */
|
|
221
|
+
async sendCardMessage(chatId: string, card: Record<string, unknown>): Promise<void> {
|
|
222
|
+
const token = await this.getAccessToken();
|
|
223
|
+
await fetch(`${this.config.apiBase}/open-apis/im/v1/messages?receive_id_type=chat_id`, {
|
|
224
|
+
method: 'POST',
|
|
225
|
+
headers: {
|
|
226
|
+
'Content-Type': 'application/json',
|
|
227
|
+
'Authorization': `Bearer ${token}`,
|
|
228
|
+
},
|
|
229
|
+
body: JSON.stringify({
|
|
230
|
+
receive_id: chatId,
|
|
231
|
+
msg_type: 'interactive',
|
|
232
|
+
content: JSON.stringify(card),
|
|
233
|
+
}),
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
package/src/cli.ts
CHANGED
|
@@ -520,41 +520,7 @@ program
|
|
|
520
520
|
});
|
|
521
521
|
});
|
|
522
522
|
|
|
523
|
-
//
|
|
524
|
-
|
|
525
|
-
program
|
|
526
|
-
.command('publish')
|
|
527
|
-
.description('Validate and package for OPC Registry')
|
|
528
|
-
.option('-f, --file <file>', 'OAD file', 'oad.yaml')
|
|
529
|
-
.action(async (opts: { file: string }) => {
|
|
530
|
-
try {
|
|
531
|
-
const runtime = new AgentRuntime();
|
|
532
|
-
const config = await runtime.loadConfig(opts.file);
|
|
533
|
-
const trust = config.spec.dtv?.trust?.level ?? 'sandbox';
|
|
534
|
-
|
|
535
|
-
console.log(`\n${icon.package} Publishing: ${color.bold(config.metadata.name)} v${config.metadata.version}`);
|
|
536
|
-
console.log(` ${icon.success} OAD validation passed`);
|
|
537
|
-
|
|
538
|
-
const manifest = {
|
|
539
|
-
name: config.metadata.name,
|
|
540
|
-
version: config.metadata.version,
|
|
541
|
-
description: config.metadata.description,
|
|
542
|
-
author: config.metadata.author,
|
|
543
|
-
license: config.metadata.license,
|
|
544
|
-
trust,
|
|
545
|
-
channels: config.spec.channels.map((c: any) => c.type),
|
|
546
|
-
skills: config.spec.skills.map((s: any) => s.name),
|
|
547
|
-
publishedAt: new Date().toISOString(),
|
|
548
|
-
};
|
|
549
|
-
|
|
550
|
-
fs.writeFileSync('opc-manifest.json', JSON.stringify(manifest, null, 2));
|
|
551
|
-
console.log(` ${icon.file} Generated opc-manifest.json`);
|
|
552
|
-
console.log(`\n🚧 OPC Registry is coming soon. Manifest saved locally.\n`);
|
|
553
|
-
} catch (err) {
|
|
554
|
-
console.error(`${icon.error} Publish failed:`, err instanceof Error ? err.message : err);
|
|
555
|
-
process.exit(1);
|
|
556
|
-
}
|
|
557
|
-
});
|
|
523
|
+
// (publish command moved to marketplace section below)
|
|
558
524
|
|
|
559
525
|
// ── Deploy command ───────────────────────────────────────────
|
|
560
526
|
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ProcessWatcher — Background process output monitoring with pattern matching.
|
|
5
|
+
*
|
|
6
|
+
* Inspired by Hermes Agent's watch_patterns feature.
|
|
7
|
+
* Set patterns to watch for in background process output and get callbacks
|
|
8
|
+
* when they match — no polling needed.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* const watcher = new ProcessWatcher();
|
|
12
|
+
* watcher.watch(childProcess.stdout, {
|
|
13
|
+
* patterns: [
|
|
14
|
+
* { regex: /listening on port (\d+)/, label: 'server-ready' },
|
|
15
|
+
* { regex: /error|Error|ERROR/, label: 'error-detected' },
|
|
16
|
+
* { regex: /build completed/, label: 'build-done', once: true },
|
|
17
|
+
* ],
|
|
18
|
+
* onMatch: (match) => console.log(`[${match.label}] ${match.line}`),
|
|
19
|
+
* });
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export interface WatchPattern {
|
|
23
|
+
/** Regex to match against each line of output */
|
|
24
|
+
regex: RegExp;
|
|
25
|
+
/** Human-readable label for this pattern */
|
|
26
|
+
label: string;
|
|
27
|
+
/** If true, auto-remove after first match */
|
|
28
|
+
once?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface WatchMatch {
|
|
32
|
+
/** Pattern label */
|
|
33
|
+
label: string;
|
|
34
|
+
/** The full line that matched */
|
|
35
|
+
line: string;
|
|
36
|
+
/** Regex match groups */
|
|
37
|
+
groups: string[];
|
|
38
|
+
/** Timestamp of match */
|
|
39
|
+
timestamp: number;
|
|
40
|
+
/** Stream source */
|
|
41
|
+
stream: 'stdout' | 'stderr';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface WatchOptions {
|
|
45
|
+
/** Patterns to match */
|
|
46
|
+
patterns: WatchPattern[];
|
|
47
|
+
/** Callback on match */
|
|
48
|
+
onMatch: (match: WatchMatch) => void;
|
|
49
|
+
/** Optional: max matches to keep in history (default: 100) */
|
|
50
|
+
maxHistory?: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class ProcessWatcher extends EventEmitter {
|
|
54
|
+
private watchers = new Map<string, {
|
|
55
|
+
patterns: WatchPattern[];
|
|
56
|
+
onMatch: (match: WatchMatch) => void;
|
|
57
|
+
history: WatchMatch[];
|
|
58
|
+
maxHistory: number;
|
|
59
|
+
}>();
|
|
60
|
+
|
|
61
|
+
private watcherIdCounter = 0;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Start watching a readable stream for patterns.
|
|
65
|
+
* Returns a watcher ID that can be used to stop watching.
|
|
66
|
+
*/
|
|
67
|
+
watch(
|
|
68
|
+
stream: NodeJS.ReadableStream,
|
|
69
|
+
options: WatchOptions,
|
|
70
|
+
streamName: 'stdout' | 'stderr' = 'stdout',
|
|
71
|
+
): string {
|
|
72
|
+
const id = `watcher_${++this.watcherIdCounter}`;
|
|
73
|
+
const state = {
|
|
74
|
+
patterns: [...options.patterns],
|
|
75
|
+
onMatch: options.onMatch,
|
|
76
|
+
history: [] as WatchMatch[],
|
|
77
|
+
maxHistory: options.maxHistory ?? 100,
|
|
78
|
+
};
|
|
79
|
+
this.watchers.set(id, state);
|
|
80
|
+
|
|
81
|
+
let buffer = '';
|
|
82
|
+
|
|
83
|
+
const onData = (chunk: Buffer | string) => {
|
|
84
|
+
buffer += chunk.toString();
|
|
85
|
+
const lines = buffer.split('\n');
|
|
86
|
+
buffer = lines.pop() ?? ''; // Keep incomplete line in buffer
|
|
87
|
+
|
|
88
|
+
for (const line of lines) {
|
|
89
|
+
this.matchLine(id, line, streamName);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
stream.on('data', onData);
|
|
94
|
+
stream.on('end', () => {
|
|
95
|
+
// Process remaining buffer
|
|
96
|
+
if (buffer) this.matchLine(id, buffer, streamName);
|
|
97
|
+
this.watchers.delete(id);
|
|
98
|
+
this.emit('watcher:end', id);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return id;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Watch both stdout and stderr of a ChildProcess.
|
|
106
|
+
*/
|
|
107
|
+
watchProcess(
|
|
108
|
+
proc: { stdout?: NodeJS.ReadableStream | null; stderr?: NodeJS.ReadableStream | null },
|
|
109
|
+
options: WatchOptions,
|
|
110
|
+
): string[] {
|
|
111
|
+
const ids: string[] = [];
|
|
112
|
+
if (proc.stdout) ids.push(this.watch(proc.stdout, options, 'stdout'));
|
|
113
|
+
if (proc.stderr) ids.push(this.watch(proc.stderr, options, 'stderr'));
|
|
114
|
+
return ids;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Stop a specific watcher */
|
|
118
|
+
unwatch(id: string): void {
|
|
119
|
+
this.watchers.delete(id);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Get match history for a watcher */
|
|
123
|
+
getHistory(id: string): WatchMatch[] {
|
|
124
|
+
return this.watchers.get(id)?.history ?? [];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Add a pattern to an existing watcher */
|
|
128
|
+
addPattern(id: string, pattern: WatchPattern): void {
|
|
129
|
+
const state = this.watchers.get(id);
|
|
130
|
+
if (state) state.patterns.push(pattern);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Remove a pattern by label from a watcher */
|
|
134
|
+
removePattern(id: string, label: string): void {
|
|
135
|
+
const state = this.watchers.get(id);
|
|
136
|
+
if (state) {
|
|
137
|
+
state.patterns = state.patterns.filter(p => p.label !== label);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private matchLine(watcherId: string, line: string, stream: 'stdout' | 'stderr'): void {
|
|
142
|
+
const state = this.watchers.get(watcherId);
|
|
143
|
+
if (!state) return;
|
|
144
|
+
|
|
145
|
+
const toRemove: number[] = [];
|
|
146
|
+
|
|
147
|
+
for (let i = 0; i < state.patterns.length; i++) {
|
|
148
|
+
const pattern = state.patterns[i];
|
|
149
|
+
const m = line.match(pattern.regex);
|
|
150
|
+
if (m) {
|
|
151
|
+
const match: WatchMatch = {
|
|
152
|
+
label: pattern.label,
|
|
153
|
+
line,
|
|
154
|
+
groups: m.slice(1),
|
|
155
|
+
timestamp: Date.now(),
|
|
156
|
+
stream,
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
state.history.push(match);
|
|
160
|
+
if (state.history.length > state.maxHistory) {
|
|
161
|
+
state.history.shift();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
state.onMatch(match);
|
|
165
|
+
this.emit('match', match);
|
|
166
|
+
|
|
167
|
+
if (pattern.once) {
|
|
168
|
+
toRemove.push(i);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Remove once-patterns in reverse order
|
|
174
|
+
for (let i = toRemove.length - 1; i >= 0; i--) {
|
|
175
|
+
state.patterns.splice(toRemove[i], 1);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
package/src/i18n/index.ts
CHANGED
|
@@ -18,16 +18,33 @@ const messages: Record<Locale, I18nMessages> = {
|
|
|
18
18
|
'agent.notUnderstood': 'I\'m not sure I understand. Could you rephrase?',
|
|
19
19
|
'agent.handoff': 'Let me connect you with a human agent.',
|
|
20
20
|
'cli.init.success': 'Created agent project: {name}',
|
|
21
|
+
'cli.init.prompt.name': 'Agent name:',
|
|
22
|
+
'cli.init.prompt.template': 'Choose a template:',
|
|
23
|
+
'cli.init.prompt.provider': 'Choose an LLM provider:',
|
|
21
24
|
'cli.build.success': 'Build successful: {name} v{version}',
|
|
22
25
|
'cli.test.pass': 'All tests passed',
|
|
23
26
|
'cli.test.fail': '{count} test(s) failed',
|
|
27
|
+
'cli.run.starting': 'Starting agent "{name}"...',
|
|
28
|
+
'cli.run.listening': 'Agent "{name}" is running at http://localhost:{port}',
|
|
29
|
+
'cli.deploy.success': 'Deployed "{name}" to {target}',
|
|
30
|
+
'cli.deploy.error': 'Deploy failed: {error}',
|
|
31
|
+
'cli.validate.success': 'OAD validation passed',
|
|
32
|
+
'cli.validate.error': 'OAD validation failed: {error}',
|
|
33
|
+
'cli.analytics.title': 'Agent Analytics',
|
|
34
|
+
'cli.analytics.noData': 'No analytics data yet',
|
|
24
35
|
'cli.stats.title': 'Agent Analytics',
|
|
25
36
|
'cli.stats.messages': 'Messages Processed',
|
|
26
37
|
'cli.stats.avgTime': 'Avg Response Time',
|
|
27
38
|
'cli.stats.errors': 'Errors',
|
|
28
39
|
'cli.stats.uptime': 'Uptime',
|
|
40
|
+
'cli.chat.welcome': 'Chat with your agent. Type "exit" to quit.',
|
|
41
|
+
'cli.dev.watching': 'Watching for changes...',
|
|
42
|
+
'cli.publish.success': 'Published "{name}" v{version}',
|
|
29
43
|
'plugin.loaded': 'Plugin "{name}" loaded',
|
|
30
44
|
'plugin.error': 'Plugin "{name}" failed: {error}',
|
|
45
|
+
'kb.added': 'Added "{file}" to knowledge base',
|
|
46
|
+
'kb.searchResults': '{count} results found',
|
|
47
|
+
'kb.noResults': 'No results found',
|
|
31
48
|
'web.title': 'OPC Agent',
|
|
32
49
|
'web.chat.placeholder': 'Type a message...',
|
|
33
50
|
'web.chat.send': 'Send',
|
|
@@ -50,22 +67,39 @@ const messages: Record<Locale, I18nMessages> = {
|
|
|
50
67
|
'zh-CN': {
|
|
51
68
|
'agent.started': '智能体 "{name}" 启动成功',
|
|
52
69
|
'agent.stopped': '智能体 "{name}" 已停止',
|
|
53
|
-
'agent.error': '
|
|
54
|
-
'agent.greeting': '
|
|
55
|
-
'agent.farewell': '
|
|
56
|
-
'agent.notUnderstood': '
|
|
57
|
-
'agent.handoff': '
|
|
58
|
-
'cli.init.success': '
|
|
59
|
-
'cli.
|
|
70
|
+
'agent.error': '发生错误:{error}',
|
|
71
|
+
'agent.greeting': '你好!有什么可以帮你的?',
|
|
72
|
+
'agent.farewell': '再见!祝你愉快。',
|
|
73
|
+
'agent.notUnderstood': '抱歉,我没太理解你的意思。能换个方式描述一下吗?',
|
|
74
|
+
'agent.handoff': '我来帮你转接人工客服。',
|
|
75
|
+
'cli.init.success': '已创建智能体项目:{name}',
|
|
76
|
+
'cli.init.prompt.name': '智能体名称:',
|
|
77
|
+
'cli.init.prompt.template': '选择一个模板:',
|
|
78
|
+
'cli.init.prompt.provider': '选择大语言模型供应商:',
|
|
79
|
+
'cli.build.success': '构建成功:{name} v{version}',
|
|
60
80
|
'cli.test.pass': '所有测试通过',
|
|
61
81
|
'cli.test.fail': '{count} 个测试失败',
|
|
62
|
-
'cli.
|
|
82
|
+
'cli.run.starting': '正在启动智能体 "{name}"...',
|
|
83
|
+
'cli.run.listening': '智能体 "{name}" 已在 http://localhost:{port} 上运行',
|
|
84
|
+
'cli.deploy.success': '已将 "{name}" 部署到 {target}',
|
|
85
|
+
'cli.deploy.error': '部署失败:{error}',
|
|
86
|
+
'cli.validate.success': 'OAD 配置校验通过',
|
|
87
|
+
'cli.validate.error': 'OAD 配置校验失败:{error}',
|
|
88
|
+
'cli.analytics.title': '智能体数据分析',
|
|
89
|
+
'cli.analytics.noData': '暂无分析数据',
|
|
90
|
+
'cli.stats.title': '智能体数据分析',
|
|
63
91
|
'cli.stats.messages': '已处理消息',
|
|
64
92
|
'cli.stats.avgTime': '平均响应时间',
|
|
65
93
|
'cli.stats.errors': '错误数',
|
|
66
94
|
'cli.stats.uptime': '运行时间',
|
|
95
|
+
'cli.chat.welcome': '开始和智能体对话吧。输入 "exit" 退出。',
|
|
96
|
+
'cli.dev.watching': '正在监听文件变更...',
|
|
97
|
+
'cli.publish.success': '已发布 "{name}" v{version}',
|
|
67
98
|
'plugin.loaded': '插件 "{name}" 已加载',
|
|
68
|
-
'plugin.error': '插件 "{name}"
|
|
99
|
+
'plugin.error': '插件 "{name}" 出错:{error}',
|
|
100
|
+
'kb.added': '已将 "{file}" 添加到知识库',
|
|
101
|
+
'kb.searchResults': '找到 {count} 条结果',
|
|
102
|
+
'kb.noResults': '未找到相关结果',
|
|
69
103
|
'web.title': 'OPC 智能体',
|
|
70
104
|
'web.chat.placeholder': '输入消息...',
|
|
71
105
|
'web.chat.send': '发送',
|
|
@@ -94,16 +128,33 @@ const messages: Record<Locale, I18nMessages> = {
|
|
|
94
128
|
'agent.notUnderstood': '申し訳ございません、理解できませんでした。別の言い方でお願いできますか?',
|
|
95
129
|
'agent.handoff': 'オペレーターにおつなぎします。',
|
|
96
130
|
'cli.init.success': 'エージェントプロジェクトを作成しました: {name}',
|
|
131
|
+
'cli.init.prompt.name': 'エージェント名:',
|
|
132
|
+
'cli.init.prompt.template': 'テンプレートを選択:',
|
|
133
|
+
'cli.init.prompt.provider': 'LLMプロバイダーを選択:',
|
|
97
134
|
'cli.build.success': 'ビルド成功: {name} v{version}',
|
|
98
135
|
'cli.test.pass': '全テスト合格',
|
|
99
136
|
'cli.test.fail': '{count} 件のテストが失敗しました',
|
|
137
|
+
'cli.run.starting': 'エージェント「{name}」を起動中...',
|
|
138
|
+
'cli.run.listening': 'エージェント「{name}」が http://localhost:{port} で稼働中',
|
|
139
|
+
'cli.deploy.success': '「{name}」を {target} にデプロイしました',
|
|
140
|
+
'cli.deploy.error': 'デプロイ失敗: {error}',
|
|
141
|
+
'cli.validate.success': 'OADバリデーション成功',
|
|
142
|
+
'cli.validate.error': 'OADバリデーション失敗: {error}',
|
|
143
|
+
'cli.analytics.title': 'エージェント分析',
|
|
144
|
+
'cli.analytics.noData': '分析データがありません',
|
|
100
145
|
'cli.stats.title': 'エージェント分析',
|
|
101
146
|
'cli.stats.messages': '処理済みメッセージ',
|
|
102
147
|
'cli.stats.avgTime': '平均応答時間',
|
|
103
148
|
'cli.stats.errors': 'エラー数',
|
|
104
149
|
'cli.stats.uptime': '稼働時間',
|
|
150
|
+
'cli.chat.welcome': 'エージェントとチャットしましょう。"exit"で終了。',
|
|
151
|
+
'cli.dev.watching': 'ファイル変更を監視中...',
|
|
152
|
+
'cli.publish.success': '「{name}」v{version} を公開しました',
|
|
105
153
|
'plugin.loaded': 'プラグイン「{name}」を読み込みました',
|
|
106
154
|
'plugin.error': 'プラグイン「{name}」でエラー: {error}',
|
|
155
|
+
'kb.added': '「{file}」をナレッジベースに追加しました',
|
|
156
|
+
'kb.searchResults': '{count} 件の結果が見つかりました',
|
|
157
|
+
'kb.noResults': '結果が見つかりませんでした',
|
|
107
158
|
'web.title': 'OPC エージェント',
|
|
108
159
|
'web.chat.placeholder': 'メッセージを入力...',
|
|
109
160
|
'web.chat.send': '送信',
|
package/src/index.ts
CHANGED
|
@@ -100,3 +100,11 @@ export { sanitizeInput, detectInjection, securityHeaders, corsMiddleware, APIKey
|
|
|
100
100
|
export type { SecurityHeadersConfig, CORSConfig, APIKeyEntry } from './core/security';
|
|
101
101
|
export { createLoggingPlugin, createAnalyticsPlugin, createRateLimitPlugin } from './plugins';
|
|
102
102
|
export type { PluginManifest } from './plugins';
|
|
103
|
+
|
|
104
|
+
// v1.1.0 modules
|
|
105
|
+
export { FeishuChannel } from './channels/feishu';
|
|
106
|
+
export type { FeishuChannelConfig } from './channels/feishu';
|
|
107
|
+
export { DiscordChannel } from './channels/discord';
|
|
108
|
+
export type { DiscordChannelConfig } from './channels/discord';
|
|
109
|
+
export { ProcessWatcher } from './core/watch';
|
|
110
|
+
export type { WatchPattern, WatchMatch, WatchOptions } from './core/watch';
|
package/tests/i18n.test.ts
CHANGED