opc-agent 2.1.0 → 3.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/README.md +603 -545
- package/dist/channels/voice.d.ts +59 -0
- package/dist/channels/voice.js +351 -1
- package/dist/cli.js +172 -1
- package/dist/core/agent.d.ts +4 -0
- package/dist/core/agent.js +35 -0
- package/dist/core/collaboration.d.ts +89 -0
- package/dist/core/collaboration.js +201 -0
- package/dist/deploy/index.d.ts +40 -0
- package/dist/deploy/index.js +261 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +47 -3
- package/dist/mcp/servers/calculator-mcp.d.ts +3 -0
- package/dist/mcp/servers/calculator-mcp.js +65 -0
- package/dist/mcp/servers/crypto-mcp.d.ts +3 -0
- package/dist/mcp/servers/crypto-mcp.js +108 -0
- package/dist/mcp/servers/database-mcp.d.ts +3 -0
- package/dist/mcp/servers/database-mcp.js +73 -0
- package/dist/mcp/servers/datetime-mcp.d.ts +3 -0
- package/dist/mcp/servers/datetime-mcp.js +71 -0
- package/dist/mcp/servers/filesystem.d.ts +3 -0
- package/dist/mcp/servers/filesystem.js +101 -0
- package/dist/mcp/servers/github-mcp.d.ts +3 -0
- package/dist/mcp/servers/github-mcp.js +60 -0
- package/dist/mcp/servers/index.d.ts +21 -0
- package/dist/mcp/servers/index.js +50 -0
- package/dist/mcp/servers/json-mcp.d.ts +3 -0
- package/dist/mcp/servers/json-mcp.js +126 -0
- package/dist/mcp/servers/memory-mcp.d.ts +3 -0
- package/dist/mcp/servers/memory-mcp.js +60 -0
- package/dist/mcp/servers/regex-mcp.d.ts +3 -0
- package/dist/mcp/servers/regex-mcp.js +56 -0
- package/dist/mcp/servers/web-mcp.d.ts +3 -0
- package/dist/mcp/servers/web-mcp.js +51 -0
- package/dist/schema/oad.d.ts +292 -12
- package/dist/schema/oad.js +12 -1
- package/dist/security/guardrails.d.ts +50 -0
- package/dist/security/guardrails.js +197 -0
- package/dist/studio/server.d.ts +31 -1
- package/dist/studio/server.js +154 -3
- package/dist/studio-ui/index.html +1278 -662
- package/dist/tools/integrations/calendar.d.ts +3 -0
- package/dist/tools/integrations/calendar.js +73 -0
- package/dist/tools/integrations/code-exec.d.ts +3 -0
- package/dist/tools/integrations/code-exec.js +42 -0
- package/dist/tools/integrations/csv-analyzer.d.ts +3 -0
- package/dist/tools/integrations/csv-analyzer.js +142 -0
- package/dist/tools/integrations/database.d.ts +3 -0
- package/dist/tools/integrations/database.js +44 -0
- package/dist/tools/integrations/email-send.d.ts +3 -0
- package/dist/tools/integrations/email-send.js +104 -0
- package/dist/tools/integrations/git-tool.d.ts +3 -0
- package/dist/tools/integrations/git-tool.js +49 -0
- package/dist/tools/integrations/github-tool.d.ts +3 -0
- package/dist/tools/integrations/github-tool.js +77 -0
- package/dist/tools/integrations/image-gen.d.ts +3 -0
- package/dist/tools/integrations/image-gen.js +58 -0
- package/dist/tools/integrations/index.d.ts +30 -0
- package/dist/tools/integrations/index.js +107 -0
- package/dist/tools/integrations/jira.d.ts +3 -0
- package/dist/tools/integrations/jira.js +85 -0
- package/dist/tools/integrations/notion.d.ts +3 -0
- package/dist/tools/integrations/notion.js +71 -0
- package/dist/tools/integrations/npm-tool.d.ts +3 -0
- package/dist/tools/integrations/npm-tool.js +49 -0
- package/dist/tools/integrations/pdf-reader.d.ts +3 -0
- package/dist/tools/integrations/pdf-reader.js +91 -0
- package/dist/tools/integrations/slack.d.ts +3 -0
- package/dist/tools/integrations/slack.js +67 -0
- package/dist/tools/integrations/summarizer.d.ts +3 -0
- package/dist/tools/integrations/summarizer.js +49 -0
- package/dist/tools/integrations/translator.d.ts +3 -0
- package/dist/tools/integrations/translator.js +48 -0
- package/dist/tools/integrations/trello.d.ts +3 -0
- package/dist/tools/integrations/trello.js +60 -0
- package/dist/tools/integrations/vector-search.d.ts +3 -0
- package/dist/tools/integrations/vector-search.js +44 -0
- package/dist/tools/integrations/web-scraper.d.ts +3 -0
- package/dist/tools/integrations/web-scraper.js +48 -0
- package/dist/tools/integrations/web-search.d.ts +3 -0
- package/dist/tools/integrations/web-search.js +60 -0
- package/dist/tools/integrations/webhook.d.ts +3 -0
- package/dist/tools/integrations/webhook.js +39 -0
- package/dist/ui/components.d.ts +10 -0
- package/dist/ui/components.js +123 -0
- package/package.json +3 -3
- package/src/channels/voice.ts +365 -0
- package/src/cli.ts +176 -2
- package/src/core/agent.ts +38 -0
- package/src/core/collaboration.ts +275 -0
- package/src/deploy/index.ts +255 -0
- package/src/index.ts +21 -1
- package/src/mcp/servers/calculator-mcp.ts +65 -0
- package/src/mcp/servers/crypto-mcp.ts +73 -0
- package/src/mcp/servers/database-mcp.ts +72 -0
- package/src/mcp/servers/datetime-mcp.ts +69 -0
- package/src/mcp/servers/filesystem.ts +66 -0
- package/src/mcp/servers/github-mcp.ts +58 -0
- package/src/mcp/servers/index.ts +63 -0
- package/src/mcp/servers/json-mcp.ts +102 -0
- package/src/mcp/servers/memory-mcp.ts +56 -0
- package/src/mcp/servers/regex-mcp.ts +53 -0
- package/src/mcp/servers/web-mcp.ts +49 -0
- package/src/schema/oad.ts +13 -0
- package/src/security/guardrails.ts +248 -0
- package/src/studio/server.ts +166 -4
- package/src/studio-ui/index.html +1278 -662
- package/src/tools/integrations/calendar.ts +73 -0
- package/src/tools/integrations/code-exec.ts +39 -0
- package/src/tools/integrations/csv-analyzer.ts +92 -0
- package/src/tools/integrations/database.ts +44 -0
- package/src/tools/integrations/email-send.ts +76 -0
- package/src/tools/integrations/git-tool.ts +42 -0
- package/src/tools/integrations/github-tool.ts +76 -0
- package/src/tools/integrations/image-gen.ts +56 -0
- package/src/tools/integrations/index.ts +92 -0
- package/src/tools/integrations/jira.ts +83 -0
- package/src/tools/integrations/notion.ts +71 -0
- package/src/tools/integrations/npm-tool.ts +48 -0
- package/src/tools/integrations/pdf-reader.ts +58 -0
- package/src/tools/integrations/slack.ts +65 -0
- package/src/tools/integrations/summarizer.ts +49 -0
- package/src/tools/integrations/translator.ts +48 -0
- package/src/tools/integrations/trello.ts +60 -0
- package/src/tools/integrations/vector-search.ts +42 -0
- package/src/tools/integrations/web-scraper.ts +47 -0
- package/src/tools/integrations/web-search.ts +58 -0
- package/src/tools/integrations/webhook.ts +38 -0
- package/src/ui/components.ts +127 -0
- package/tests/brain-seed-extended.test.ts +490 -0
- package/tests/collaboration.test.ts +319 -0
- package/tests/deploy-and-dag.test.ts +196 -0
- package/tests/guardrails.test.ts +177 -0
- package/tests/integrations.test.ts +249 -0
- package/tests/mcp-servers.test.ts +260 -0
- package/tests/voice-enhanced.test.ts +169 -0
- package/dist/dtv/data.d.ts +0 -18
- package/dist/dtv/data.js +0 -25
- package/dist/dtv/trust.d.ts +0 -19
- package/dist/dtv/trust.js +0 -40
- package/dist/dtv/value.d.ts +0 -23
- package/dist/dtv/value.js +0 -38
- package/dist/marketplace/index.d.ts +0 -34
- package/dist/marketplace/index.js +0 -202
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { VoiceChannel, createVoiceProviders, EdgeTTSProvider, WhisperSTTProvider, OpenAITTSProvider } from '../src/channels/voice';
|
|
3
|
+
import type { STTProvider, TTSProvider, VoiceConfig } from '../src/channels/voice';
|
|
4
|
+
|
|
5
|
+
describe('VoiceChannel Enhanced', () => {
|
|
6
|
+
// ── VoiceConfig Parsing ───────────────────────────────────
|
|
7
|
+
|
|
8
|
+
it('should parse VoiceConfig with edge-tts', () => {
|
|
9
|
+
const config: VoiceConfig = {
|
|
10
|
+
sttProvider: 'whisper',
|
|
11
|
+
ttsProvider: 'edge-tts',
|
|
12
|
+
voice: 'en-US-GuyNeural',
|
|
13
|
+
language: 'en',
|
|
14
|
+
};
|
|
15
|
+
const { stt, tts } = createVoiceProviders(config);
|
|
16
|
+
expect(stt).toBeUndefined(); // no API key
|
|
17
|
+
expect(tts).toBeDefined();
|
|
18
|
+
expect(tts!.name).toBe('edge-tts');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should parse VoiceConfig with whisper + openai-tts', () => {
|
|
22
|
+
const config: VoiceConfig = {
|
|
23
|
+
sttProvider: 'whisper',
|
|
24
|
+
ttsProvider: 'openai-tts',
|
|
25
|
+
sttApiKey: 'sk-test',
|
|
26
|
+
ttsApiKey: 'sk-test',
|
|
27
|
+
voice: 'nova',
|
|
28
|
+
};
|
|
29
|
+
const { stt, tts } = createVoiceProviders(config);
|
|
30
|
+
expect(stt).toBeDefined();
|
|
31
|
+
expect(stt!.name).toBe('whisper');
|
|
32
|
+
expect(tts).toBeDefined();
|
|
33
|
+
expect(tts!.name).toBe('openai-tts');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should return undefined for web-speech (node-only)', () => {
|
|
37
|
+
const { stt } = createVoiceProviders({
|
|
38
|
+
sttProvider: 'web-speech',
|
|
39
|
+
ttsProvider: 'edge-tts',
|
|
40
|
+
});
|
|
41
|
+
expect(stt).toBeUndefined();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// ── Transcribe (mock) ─────────────────────────────────────
|
|
45
|
+
|
|
46
|
+
it('should transcribe audio with mock STT provider', async () => {
|
|
47
|
+
const mockSTT: STTProvider = {
|
|
48
|
+
name: 'mock-stt',
|
|
49
|
+
transcribe: vi.fn().mockResolvedValue('Hello world'),
|
|
50
|
+
};
|
|
51
|
+
const channel = new VoiceChannel({ sttProvider: mockSTT });
|
|
52
|
+
const text = await channel.transcribe(Buffer.from('audio-data'));
|
|
53
|
+
expect(text).toBe('Hello world');
|
|
54
|
+
expect(mockSTT.transcribe).toHaveBeenCalled();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should throw if no STT provider for transcribe', async () => {
|
|
58
|
+
const channel = new VoiceChannel();
|
|
59
|
+
await expect(channel.transcribe(Buffer.from('audio'))).rejects.toThrow('No STT provider');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// ── Synthesize (mock) ─────────────────────────────────────
|
|
63
|
+
|
|
64
|
+
it('should synthesize text with mock TTS provider', async () => {
|
|
65
|
+
const mockTTS: TTSProvider = {
|
|
66
|
+
name: 'mock-tts',
|
|
67
|
+
synthesize: vi.fn().mockResolvedValue(Buffer.from('audio-output')),
|
|
68
|
+
};
|
|
69
|
+
const channel = new VoiceChannel({ ttsProvider: mockTTS });
|
|
70
|
+
const audio = await channel.synthesize('Hello world');
|
|
71
|
+
expect(audio).toEqual(Buffer.from('audio-output'));
|
|
72
|
+
expect(mockTTS.synthesize).toHaveBeenCalledWith('Hello world', { voice: undefined });
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should throw if no TTS provider for synthesize', async () => {
|
|
76
|
+
const channel = new VoiceChannel();
|
|
77
|
+
await expect(channel.synthesize('Hello')).rejects.toThrow('No TTS provider');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// ── Conversation Mode ─────────────────────────────────────
|
|
81
|
+
|
|
82
|
+
it('should start and stop conversation mode', async () => {
|
|
83
|
+
const channel = new VoiceChannel();
|
|
84
|
+
await channel.startConversation(async (text) => `Echo: ${text}`);
|
|
85
|
+
expect(channel.isConversationActive()).toBe(true);
|
|
86
|
+
channel.stopConversation();
|
|
87
|
+
expect(channel.isConversationActive()).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// ── processConversationTurn ───────────────────────────────
|
|
91
|
+
|
|
92
|
+
it('should process a conversation turn', async () => {
|
|
93
|
+
const mockSTT: STTProvider = {
|
|
94
|
+
name: 'mock-stt',
|
|
95
|
+
transcribe: vi.fn().mockResolvedValue('What time is it?'),
|
|
96
|
+
};
|
|
97
|
+
const mockTTS: TTSProvider = {
|
|
98
|
+
name: 'mock-tts',
|
|
99
|
+
synthesize: vi.fn().mockResolvedValue(Buffer.from('audio-response')),
|
|
100
|
+
};
|
|
101
|
+
const channel = new VoiceChannel({ sttProvider: mockSTT, ttsProvider: mockTTS });
|
|
102
|
+
|
|
103
|
+
const result = await channel.processConversationTurn(
|
|
104
|
+
Buffer.from('audio'),
|
|
105
|
+
async (text) => `It is 3pm, you said: ${text}`,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
expect(result.text).toBe('What time is it?');
|
|
109
|
+
expect(result.response).toContain('3pm');
|
|
110
|
+
expect(result.audioResponse).toBeDefined();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// ── processAudio with handler ─────────────────────────────
|
|
114
|
+
|
|
115
|
+
it('should process audio end-to-end', async () => {
|
|
116
|
+
const mockSTT: STTProvider = {
|
|
117
|
+
name: 'mock-stt',
|
|
118
|
+
transcribe: vi.fn().mockResolvedValue('Hello agent'),
|
|
119
|
+
};
|
|
120
|
+
const mockTTS: TTSProvider = {
|
|
121
|
+
name: 'mock-tts',
|
|
122
|
+
synthesize: vi.fn().mockResolvedValue(Buffer.from('tts-audio')),
|
|
123
|
+
};
|
|
124
|
+
const channel = new VoiceChannel({ sttProvider: mockSTT, ttsProvider: mockTTS });
|
|
125
|
+
channel.onMessage(async (msg) => ({
|
|
126
|
+
id: 'r1',
|
|
127
|
+
role: 'assistant' as const,
|
|
128
|
+
content: `Reply to: ${msg.content}`,
|
|
129
|
+
timestamp: Date.now(),
|
|
130
|
+
}));
|
|
131
|
+
|
|
132
|
+
const result = await channel.processAudio(Buffer.from('raw-audio'));
|
|
133
|
+
expect(result.text).toBe('Hello agent');
|
|
134
|
+
expect(result.response).toBe('Reply to: Hello agent');
|
|
135
|
+
expect(result.audioResponse).toBeDefined();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// ── Provider instances ────────────────────────────────────
|
|
139
|
+
|
|
140
|
+
it('should create EdgeTTSProvider with default voice', () => {
|
|
141
|
+
const provider = new EdgeTTSProvider();
|
|
142
|
+
expect(provider.name).toBe('edge-tts');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('should create EdgeTTSProvider with custom voice', () => {
|
|
146
|
+
const provider = new EdgeTTSProvider('zh-CN-XiaoxiaoNeural');
|
|
147
|
+
expect(provider.name).toBe('edge-tts');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// ── Channel lifecycle ─────────────────────────────────────
|
|
151
|
+
|
|
152
|
+
it('should start and stop channel', async () => {
|
|
153
|
+
const channel = new VoiceChannel();
|
|
154
|
+
expect(channel.isRunning()).toBe(false);
|
|
155
|
+
await channel.start();
|
|
156
|
+
expect(channel.isRunning()).toBe(true);
|
|
157
|
+
await channel.stop();
|
|
158
|
+
expect(channel.isRunning()).toBe(false);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('should set STT/TTS providers dynamically', () => {
|
|
162
|
+
const channel = new VoiceChannel();
|
|
163
|
+
const mockSTT: STTProvider = { name: 'test-stt', transcribe: vi.fn() };
|
|
164
|
+
const mockTTS: TTSProvider = { name: 'test-tts', synthesize: vi.fn() };
|
|
165
|
+
channel.setSTTProvider(mockSTT);
|
|
166
|
+
channel.setTTSProvider(mockTTS);
|
|
167
|
+
// No error means success
|
|
168
|
+
});
|
|
169
|
+
});
|
package/dist/dtv/data.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export interface DataSource {
|
|
2
|
-
readonly name: string;
|
|
3
|
-
readonly type: string;
|
|
4
|
-
read(key: string): Promise<unknown>;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* MRGConfig reader — read-only data layer for agents.
|
|
8
|
-
* Agents can read business data but cannot modify source systems.
|
|
9
|
-
*/
|
|
10
|
-
export declare class MRGConfigReader implements DataSource {
|
|
11
|
-
readonly name = "mrg-config";
|
|
12
|
-
readonly type = "config";
|
|
13
|
-
private data;
|
|
14
|
-
constructor(initial?: Record<string, unknown>);
|
|
15
|
-
read(key: string): Promise<unknown>;
|
|
16
|
-
load(data: Record<string, unknown>): void;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=data.d.ts.map
|
package/dist/dtv/data.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MRGConfigReader = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* MRGConfig reader — read-only data layer for agents.
|
|
6
|
-
* Agents can read business data but cannot modify source systems.
|
|
7
|
-
*/
|
|
8
|
-
class MRGConfigReader {
|
|
9
|
-
name = 'mrg-config';
|
|
10
|
-
type = 'config';
|
|
11
|
-
data;
|
|
12
|
-
constructor(initial) {
|
|
13
|
-
this.data = new Map(Object.entries(initial ?? {}));
|
|
14
|
-
}
|
|
15
|
-
async read(key) {
|
|
16
|
-
return this.data.get(key);
|
|
17
|
-
}
|
|
18
|
-
load(data) {
|
|
19
|
-
for (const [k, v] of Object.entries(data)) {
|
|
20
|
-
this.data.set(k, v);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.MRGConfigReader = MRGConfigReader;
|
|
25
|
-
//# sourceMappingURL=data.js.map
|
package/dist/dtv/trust.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { TrustLevelType } from '../schema/oad';
|
|
2
|
-
/**
|
|
3
|
-
* Trust levels: sandbox → verified → certified → listed
|
|
4
|
-
*
|
|
5
|
-
* - sandbox: No network, no file system, limited capabilities
|
|
6
|
-
* - verified: Identity verified, basic capabilities
|
|
7
|
-
* - certified: Passed security audit, full capabilities
|
|
8
|
-
* - listed: Published in OPC marketplace
|
|
9
|
-
*/
|
|
10
|
-
export declare class TrustManager {
|
|
11
|
-
private level;
|
|
12
|
-
constructor(level?: TrustLevelType);
|
|
13
|
-
getLevel(): TrustLevelType;
|
|
14
|
-
canAccessNetwork(): boolean;
|
|
15
|
-
canAccessFileSystem(): boolean;
|
|
16
|
-
canPublish(): boolean;
|
|
17
|
-
upgrade(to: TrustLevelType): void;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=trust.d.ts.map
|
package/dist/dtv/trust.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TrustManager = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Trust levels: sandbox → verified → certified → listed
|
|
6
|
-
*
|
|
7
|
-
* - sandbox: No network, no file system, limited capabilities
|
|
8
|
-
* - verified: Identity verified, basic capabilities
|
|
9
|
-
* - certified: Passed security audit, full capabilities
|
|
10
|
-
* - listed: Published in OPC marketplace
|
|
11
|
-
*/
|
|
12
|
-
class TrustManager {
|
|
13
|
-
level;
|
|
14
|
-
constructor(level = 'sandbox') {
|
|
15
|
-
this.level = level;
|
|
16
|
-
}
|
|
17
|
-
getLevel() {
|
|
18
|
-
return this.level;
|
|
19
|
-
}
|
|
20
|
-
canAccessNetwork() {
|
|
21
|
-
return this.level !== 'sandbox';
|
|
22
|
-
}
|
|
23
|
-
canAccessFileSystem() {
|
|
24
|
-
return this.level === 'certified' || this.level === 'listed';
|
|
25
|
-
}
|
|
26
|
-
canPublish() {
|
|
27
|
-
return this.level === 'listed';
|
|
28
|
-
}
|
|
29
|
-
upgrade(to) {
|
|
30
|
-
const order = ['sandbox', 'verified', 'certified', 'listed'];
|
|
31
|
-
const currentIdx = order.indexOf(this.level);
|
|
32
|
-
const targetIdx = order.indexOf(to);
|
|
33
|
-
if (targetIdx <= currentIdx) {
|
|
34
|
-
throw new Error(`Cannot downgrade trust from ${this.level} to ${to}`);
|
|
35
|
-
}
|
|
36
|
-
this.level = to;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.TrustManager = TrustManager;
|
|
40
|
-
//# sourceMappingURL=trust.js.map
|
package/dist/dtv/value.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Value tracking — metrics and ROI for agent operations.
|
|
3
|
-
*/
|
|
4
|
-
export interface ValueMetric {
|
|
5
|
-
name: string;
|
|
6
|
-
value: number;
|
|
7
|
-
unit: string;
|
|
8
|
-
timestamp: number;
|
|
9
|
-
}
|
|
10
|
-
export declare class ValueTracker {
|
|
11
|
-
private metrics;
|
|
12
|
-
private trackedNames;
|
|
13
|
-
constructor(metricNames?: string[]);
|
|
14
|
-
record(name: string, value: number, unit?: string): void;
|
|
15
|
-
getMetrics(name: string): ValueMetric[];
|
|
16
|
-
getAverage(name: string): number;
|
|
17
|
-
getSummary(): Record<string, {
|
|
18
|
-
count: number;
|
|
19
|
-
average: number;
|
|
20
|
-
last: number;
|
|
21
|
-
}>;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=value.d.ts.map
|
package/dist/dtv/value.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValueTracker = void 0;
|
|
4
|
-
class ValueTracker {
|
|
5
|
-
metrics = new Map();
|
|
6
|
-
trackedNames;
|
|
7
|
-
constructor(metricNames = []) {
|
|
8
|
-
this.trackedNames = new Set(metricNames);
|
|
9
|
-
}
|
|
10
|
-
record(name, value, unit = '') {
|
|
11
|
-
if (!this.metrics.has(name)) {
|
|
12
|
-
this.metrics.set(name, []);
|
|
13
|
-
}
|
|
14
|
-
this.metrics.get(name).push({ name, value, unit, timestamp: Date.now() });
|
|
15
|
-
}
|
|
16
|
-
getMetrics(name) {
|
|
17
|
-
return this.metrics.get(name) ?? [];
|
|
18
|
-
}
|
|
19
|
-
getAverage(name) {
|
|
20
|
-
const m = this.getMetrics(name);
|
|
21
|
-
if (m.length === 0)
|
|
22
|
-
return 0;
|
|
23
|
-
return m.reduce((sum, v) => sum + v.value, 0) / m.length;
|
|
24
|
-
}
|
|
25
|
-
getSummary() {
|
|
26
|
-
const result = {};
|
|
27
|
-
for (const [name, values] of this.metrics) {
|
|
28
|
-
result[name] = {
|
|
29
|
-
count: values.length,
|
|
30
|
-
average: this.getAverage(name),
|
|
31
|
-
last: values[values.length - 1]?.value ?? 0,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
return result;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.ValueTracker = ValueTracker;
|
|
38
|
-
//# sourceMappingURL=value.js.map
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export interface AgentManifest {
|
|
2
|
-
name: string;
|
|
3
|
-
version: string;
|
|
4
|
-
description: string;
|
|
5
|
-
author: string;
|
|
6
|
-
license: string;
|
|
7
|
-
oadVersion: string;
|
|
8
|
-
channels: string[];
|
|
9
|
-
skills: string[];
|
|
10
|
-
files: string[];
|
|
11
|
-
checksum: string;
|
|
12
|
-
publishedAt: string;
|
|
13
|
-
homepage?: string;
|
|
14
|
-
repository?: string;
|
|
15
|
-
tags?: string[];
|
|
16
|
-
}
|
|
17
|
-
export interface PublishOptions {
|
|
18
|
-
oadPath: string;
|
|
19
|
-
outputDir?: string;
|
|
20
|
-
includeKnowledge?: boolean;
|
|
21
|
-
}
|
|
22
|
-
export interface InstallOptions {
|
|
23
|
-
source: string;
|
|
24
|
-
targetDir?: string;
|
|
25
|
-
}
|
|
26
|
-
export declare function publishAgent(options: PublishOptions): Promise<{
|
|
27
|
-
archivePath: string;
|
|
28
|
-
manifest: AgentManifest;
|
|
29
|
-
}>;
|
|
30
|
-
export declare function installAgent(options: InstallOptions): Promise<{
|
|
31
|
-
dir: string;
|
|
32
|
-
manifest: AgentManifest;
|
|
33
|
-
}>;
|
|
34
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.publishAgent = publishAgent;
|
|
37
|
-
exports.installAgent = installAgent;
|
|
38
|
-
/**
|
|
39
|
-
* Agent Marketplace - Package, publish, and install agents
|
|
40
|
-
*/
|
|
41
|
-
const fs = __importStar(require("fs"));
|
|
42
|
-
const path = __importStar(require("path"));
|
|
43
|
-
const crypto = __importStar(require("crypto"));
|
|
44
|
-
const child_process_1 = require("child_process");
|
|
45
|
-
function computeChecksum(filePath) {
|
|
46
|
-
const content = fs.readFileSync(filePath);
|
|
47
|
-
return crypto.createHash('sha256').update(content).digest('hex').slice(0, 16);
|
|
48
|
-
}
|
|
49
|
-
async function publishAgent(options) {
|
|
50
|
-
const { oadPath, outputDir = '.', includeKnowledge = false } = options;
|
|
51
|
-
const absOad = path.resolve(oadPath);
|
|
52
|
-
const baseDir = path.dirname(absOad);
|
|
53
|
-
if (!fs.existsSync(absOad)) {
|
|
54
|
-
throw new Error(`OAD file not found: ${absOad}`);
|
|
55
|
-
}
|
|
56
|
-
// Dynamic import yaml
|
|
57
|
-
const yaml = await Promise.resolve().then(() => __importStar(require('js-yaml')));
|
|
58
|
-
const oadContent = fs.readFileSync(absOad, 'utf-8');
|
|
59
|
-
const oad = yaml.load(oadContent);
|
|
60
|
-
const name = oad.metadata?.name ?? 'unnamed-agent';
|
|
61
|
-
const version = oad.metadata?.version ?? '0.0.0';
|
|
62
|
-
const safeName = name.toLowerCase().replace(/[^a-z0-9-]/g, '-');
|
|
63
|
-
// Collect files to package
|
|
64
|
-
const filesToPack = [
|
|
65
|
-
{ rel: path.basename(absOad), abs: absOad },
|
|
66
|
-
];
|
|
67
|
-
// Include common files
|
|
68
|
-
const extras = ['.env.example', 'README.md', 'package.json'];
|
|
69
|
-
for (const f of extras) {
|
|
70
|
-
const fp = path.join(baseDir, f);
|
|
71
|
-
if (fs.existsSync(fp)) {
|
|
72
|
-
filesToPack.push({ rel: f, abs: fp });
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// Include knowledge base if requested
|
|
76
|
-
if (includeKnowledge) {
|
|
77
|
-
const kbFile = path.join(baseDir, '.opc-knowledge.json');
|
|
78
|
-
if (fs.existsSync(kbFile)) {
|
|
79
|
-
filesToPack.push({ rel: '.opc-knowledge.json', abs: kbFile });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
// Include prompts directory if exists
|
|
83
|
-
const promptsDir = path.join(baseDir, 'prompts');
|
|
84
|
-
if (fs.existsSync(promptsDir) && fs.statSync(promptsDir).isDirectory()) {
|
|
85
|
-
const promptFiles = fs.readdirSync(promptsDir);
|
|
86
|
-
for (const pf of promptFiles) {
|
|
87
|
-
filesToPack.push({ rel: `prompts/${pf}`, abs: path.join(promptsDir, pf) });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// Build manifest
|
|
91
|
-
const manifest = {
|
|
92
|
-
name: safeName,
|
|
93
|
-
version,
|
|
94
|
-
description: oad.metadata?.description ?? '',
|
|
95
|
-
author: oad.metadata?.author ?? '',
|
|
96
|
-
license: oad.metadata?.license ?? 'Apache-2.0',
|
|
97
|
-
oadVersion: 'opc/v1',
|
|
98
|
-
channels: (oad.spec?.channels ?? []).map((c) => c.type),
|
|
99
|
-
skills: (oad.spec?.skills ?? []).map((s) => s.name),
|
|
100
|
-
files: filesToPack.map(f => f.rel),
|
|
101
|
-
checksum: '',
|
|
102
|
-
publishedAt: new Date().toISOString(),
|
|
103
|
-
tags: oad.metadata?.marketplace?.tags,
|
|
104
|
-
};
|
|
105
|
-
// Create staging directory
|
|
106
|
-
const stageDir = path.join(outputDir, `.opc-stage-${safeName}`);
|
|
107
|
-
fs.mkdirSync(stageDir, { recursive: true });
|
|
108
|
-
for (const f of filesToPack) {
|
|
109
|
-
const dest = path.join(stageDir, f.rel);
|
|
110
|
-
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
111
|
-
fs.copyFileSync(f.abs, dest);
|
|
112
|
-
}
|
|
113
|
-
// Write manifest
|
|
114
|
-
fs.writeFileSync(path.join(stageDir, 'opc-manifest.json'), JSON.stringify(manifest, null, 2));
|
|
115
|
-
// Create tar.gz
|
|
116
|
-
const archiveName = `${safeName}-${version}.tar.gz`;
|
|
117
|
-
const archivePath = path.join(outputDir, archiveName);
|
|
118
|
-
try {
|
|
119
|
-
(0, child_process_1.execSync)(`tar -czf "${archivePath}" -C "${stageDir}" .`, { stdio: 'pipe' });
|
|
120
|
-
}
|
|
121
|
-
catch {
|
|
122
|
-
// Fallback: just zip the directory content list
|
|
123
|
-
// On Windows without tar, create a simple zip-like package
|
|
124
|
-
const packageData = {
|
|
125
|
-
manifest,
|
|
126
|
-
files: filesToPack.map(f => ({
|
|
127
|
-
path: f.rel,
|
|
128
|
-
content: fs.readFileSync(f.abs, 'utf-8'),
|
|
129
|
-
})),
|
|
130
|
-
};
|
|
131
|
-
fs.writeFileSync(archivePath.replace('.tar.gz', '.opc.json'), JSON.stringify(packageData, null, 2));
|
|
132
|
-
}
|
|
133
|
-
// Compute checksum
|
|
134
|
-
if (fs.existsSync(archivePath)) {
|
|
135
|
-
manifest.checksum = computeChecksum(archivePath);
|
|
136
|
-
}
|
|
137
|
-
// Cleanup staging
|
|
138
|
-
fs.rmSync(stageDir, { recursive: true, force: true });
|
|
139
|
-
// Write final manifest
|
|
140
|
-
fs.writeFileSync(path.join(outputDir, 'opc-manifest.json'), JSON.stringify(manifest, null, 2));
|
|
141
|
-
return { archivePath: fs.existsSync(archivePath) ? archivePath : archivePath.replace('.tar.gz', '.opc.json'), manifest };
|
|
142
|
-
}
|
|
143
|
-
async function installAgent(options) {
|
|
144
|
-
const { source, targetDir } = options;
|
|
145
|
-
const absSource = path.resolve(source);
|
|
146
|
-
if (!fs.existsSync(absSource)) {
|
|
147
|
-
throw new Error(`Package not found: ${absSource}`);
|
|
148
|
-
}
|
|
149
|
-
let manifest;
|
|
150
|
-
let installDir;
|
|
151
|
-
if (absSource.endsWith('.opc.json')) {
|
|
152
|
-
// JSON package format
|
|
153
|
-
const pkg = JSON.parse(fs.readFileSync(absSource, 'utf-8'));
|
|
154
|
-
manifest = pkg.manifest;
|
|
155
|
-
installDir = targetDir ?? path.join('.', manifest.name);
|
|
156
|
-
fs.mkdirSync(installDir, { recursive: true });
|
|
157
|
-
for (const f of pkg.files) {
|
|
158
|
-
const dest = path.join(installDir, f.path);
|
|
159
|
-
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
160
|
-
fs.writeFileSync(dest, f.content, 'utf-8');
|
|
161
|
-
}
|
|
162
|
-
fs.writeFileSync(path.join(installDir, 'opc-manifest.json'), JSON.stringify(manifest, null, 2));
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
// tar.gz format
|
|
166
|
-
const tmpDir = path.join(path.dirname(absSource), '.opc-extract-tmp');
|
|
167
|
-
fs.mkdirSync(tmpDir, { recursive: true });
|
|
168
|
-
try {
|
|
169
|
-
(0, child_process_1.execSync)(`tar -xzf "${absSource}" -C "${tmpDir}"`, { stdio: 'pipe' });
|
|
170
|
-
}
|
|
171
|
-
catch {
|
|
172
|
-
throw new Error('Failed to extract package. Ensure tar is available.');
|
|
173
|
-
}
|
|
174
|
-
const manifestPath = path.join(tmpDir, 'opc-manifest.json');
|
|
175
|
-
if (!fs.existsSync(manifestPath)) {
|
|
176
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
177
|
-
throw new Error('Invalid package: missing opc-manifest.json');
|
|
178
|
-
}
|
|
179
|
-
manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
|
|
180
|
-
installDir = targetDir ?? path.join('.', manifest.name);
|
|
181
|
-
// Move files
|
|
182
|
-
fs.mkdirSync(installDir, { recursive: true });
|
|
183
|
-
const copyRecursive = (src, dest) => {
|
|
184
|
-
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
185
|
-
for (const entry of entries) {
|
|
186
|
-
const srcPath = path.join(src, entry.name);
|
|
187
|
-
const destPath = path.join(dest, entry.name);
|
|
188
|
-
if (entry.isDirectory()) {
|
|
189
|
-
fs.mkdirSync(destPath, { recursive: true });
|
|
190
|
-
copyRecursive(srcPath, destPath);
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
fs.copyFileSync(srcPath, destPath);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
copyRecursive(tmpDir, installDir);
|
|
198
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
199
|
-
}
|
|
200
|
-
return { dir: installDir, manifest };
|
|
201
|
-
}
|
|
202
|
-
//# sourceMappingURL=index.js.map
|