opc-agent 2.0.0 → 2.0.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.
- package/README.md +545 -365
- package/dist/channels/email.d.ts +32 -26
- package/dist/channels/email.js +239 -62
- package/dist/channels/feishu.d.ts +21 -6
- package/dist/channels/feishu.js +225 -126
- package/dist/channels/websocket.d.ts +46 -3
- package/dist/channels/websocket.js +306 -37
- package/dist/channels/wechat.d.ts +33 -13
- package/dist/channels/wechat.js +229 -42
- package/dist/cli.js +712 -11
- package/dist/core/a2a.d.ts +17 -0
- package/dist/core/a2a.js +43 -1
- package/dist/core/agent.d.ts +16 -0
- package/dist/core/agent.js +108 -0
- package/dist/core/runtime.d.ts +6 -0
- package/dist/core/runtime.js +161 -2
- package/dist/core/sandbox.d.ts +26 -0
- package/dist/core/sandbox.js +117 -0
- package/dist/core/workflow-graph.d.ts +93 -0
- package/dist/core/workflow-graph.js +247 -0
- package/dist/doctor.d.ts +15 -0
- package/dist/doctor.js +183 -0
- package/dist/eval/index.d.ts +65 -0
- package/dist/eval/index.js +191 -0
- package/dist/index.d.ts +32 -6
- package/dist/index.js +63 -4
- package/dist/plugins/content-filter.d.ts +7 -0
- package/dist/plugins/content-filter.js +25 -0
- package/dist/plugins/index.d.ts +42 -0
- package/dist/plugins/index.js +108 -2
- package/dist/plugins/logger.d.ts +6 -0
- package/dist/plugins/logger.js +20 -0
- package/dist/plugins/rate-limiter.d.ts +7 -0
- package/dist/plugins/rate-limiter.js +35 -0
- package/dist/protocols/a2a/client.d.ts +25 -0
- package/dist/protocols/a2a/client.js +115 -0
- package/dist/protocols/a2a/index.d.ts +6 -0
- package/dist/protocols/a2a/index.js +12 -0
- package/dist/protocols/a2a/server.d.ts +41 -0
- package/dist/protocols/a2a/server.js +295 -0
- package/dist/protocols/a2a/types.d.ts +91 -0
- package/dist/protocols/a2a/types.js +15 -0
- package/dist/protocols/a2a/utils.d.ts +6 -0
- package/dist/protocols/a2a/utils.js +47 -0
- package/dist/protocols/agui/client.d.ts +10 -0
- package/dist/protocols/agui/client.js +75 -0
- package/dist/protocols/agui/index.d.ts +4 -0
- package/dist/protocols/agui/index.js +25 -0
- package/dist/protocols/agui/server.d.ts +37 -0
- package/dist/protocols/agui/server.js +191 -0
- package/dist/protocols/agui/types.d.ts +107 -0
- package/dist/protocols/agui/types.js +17 -0
- package/dist/protocols/index.d.ts +2 -0
- package/dist/protocols/index.js +19 -0
- package/dist/protocols/mcp/agent-tools.d.ts +11 -0
- package/dist/protocols/mcp/agent-tools.js +129 -0
- package/dist/protocols/mcp/index.d.ts +5 -0
- package/dist/protocols/mcp/index.js +11 -0
- package/dist/protocols/mcp/server.d.ts +31 -0
- package/dist/protocols/mcp/server.js +248 -0
- package/dist/protocols/mcp/types.d.ts +92 -0
- package/dist/protocols/mcp/types.js +17 -0
- package/dist/publish/index.d.ts +45 -0
- package/dist/publish/index.js +350 -0
- package/dist/schema/oad.d.ts +682 -65
- package/dist/schema/oad.js +36 -3
- package/dist/security/approval.d.ts +36 -0
- package/dist/security/approval.js +113 -0
- package/dist/security/index.d.ts +4 -0
- package/dist/security/index.js +8 -0
- package/dist/security/keys.d.ts +16 -0
- package/dist/security/keys.js +117 -0
- package/dist/studio/server.d.ts +63 -0
- package/dist/studio/server.js +625 -0
- package/dist/studio-ui/index.html +662 -0
- package/dist/telemetry/index.d.ts +93 -0
- package/dist/telemetry/index.js +285 -0
- package/package.json +5 -3
- package/scripts/install.ps1 +31 -0
- package/scripts/install.sh +40 -0
- package/src/channels/email.ts +351 -177
- package/src/channels/feishu.ts +349 -236
- package/src/channels/websocket.ts +399 -87
- package/src/channels/wechat.ts +329 -149
- package/src/cli.ts +783 -12
- package/src/core/a2a.ts +60 -0
- package/src/core/agent.ts +125 -0
- package/src/core/runtime.ts +127 -0
- package/src/core/sandbox.ts +143 -0
- package/src/core/workflow-graph.ts +365 -0
- package/src/doctor.ts +156 -0
- package/src/eval/index.ts +211 -0
- package/src/eval/suites/basic.json +16 -0
- package/src/eval/suites/memory.json +12 -0
- package/src/eval/suites/safety.json +14 -0
- package/src/index.ts +58 -6
- package/src/plugins/content-filter.ts +23 -0
- package/src/plugins/index.ts +133 -2
- package/src/plugins/logger.ts +18 -0
- package/src/plugins/rate-limiter.ts +38 -0
- package/src/protocols/a2a/client.ts +132 -0
- package/src/protocols/a2a/index.ts +8 -0
- package/src/protocols/a2a/server.ts +333 -0
- package/src/protocols/a2a/types.ts +88 -0
- package/src/protocols/a2a/utils.ts +50 -0
- package/src/protocols/agui/client.ts +83 -0
- package/src/protocols/agui/index.ts +4 -0
- package/src/protocols/agui/server.ts +218 -0
- package/src/protocols/agui/types.ts +153 -0
- package/src/protocols/index.ts +2 -0
- package/src/protocols/mcp/agent-tools.ts +134 -0
- package/src/protocols/mcp/index.ts +8 -0
- package/src/protocols/mcp/server.ts +262 -0
- package/src/protocols/mcp/types.ts +69 -0
- package/src/publish/index.ts +376 -0
- package/src/schema/oad.ts +39 -2
- package/src/security/approval.ts +131 -0
- package/src/security/index.ts +3 -0
- package/src/security/keys.ts +87 -0
- package/src/studio/server.ts +629 -0
- package/src/studio-ui/index.html +662 -0
- package/src/telemetry/index.ts +324 -0
- package/src/types/agent-workstation.d.ts +2 -0
- package/tests/a2a-protocol.test.ts +285 -0
- package/tests/agui-protocol.test.ts +246 -0
- package/tests/channels/discord.test.ts +79 -0
- package/tests/channels/email.test.ts +148 -0
- package/tests/channels/feishu.test.ts +123 -0
- package/tests/channels/telegram.test.ts +129 -0
- package/tests/channels/websocket.test.ts +53 -0
- package/tests/channels/wechat.test.ts +170 -0
- package/tests/chat-cli.test.ts +160 -0
- package/tests/daemon.test.ts +135 -0
- package/tests/deepbrain-wire.test.ts +234 -0
- package/tests/doctor.test.ts +38 -0
- package/tests/eval.test.ts +173 -0
- package/tests/init-role.test.ts +124 -0
- package/tests/mcp-client.test.ts +92 -0
- package/tests/mcp-server.test.ts +178 -0
- package/tests/plugin-a2a-enhanced.test.ts +230 -0
- package/tests/publish.test.ts +231 -0
- package/tests/scheduler.test.ts +200 -0
- package/tests/security-enhanced.test.ts +233 -0
- package/tests/skill-learner.test.ts +161 -0
- package/tests/studio.test.ts +229 -0
- package/tests/subagent.test.ts +63 -0
- package/tests/telemetry.test.ts +186 -0
- package/tests/tools/builtin-extended.test.ts +138 -0
- package/tests/workflow-graph.test.ts +279 -0
- package/tutorial/customer-service-agent/README.md +612 -0
- package/tutorial/customer-service-agent/SOUL.md +26 -0
- package/tutorial/customer-service-agent/agent.yaml +63 -0
- package/tutorial/customer-service-agent/package.json +19 -0
- package/tutorial/customer-service-agent/src/index.ts +69 -0
- package/tutorial/customer-service-agent/src/skills/faq.ts +27 -0
- package/tutorial/customer-service-agent/src/skills/ticket.ts +22 -0
- package/tutorial/customer-service-agent/tsconfig.json +14 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AGUIServer = exports.AGUIEventEmitter = void 0;
|
|
4
|
+
// ─── AGUIEventEmitter ────────────────────────────────────────
|
|
5
|
+
class AGUIEventEmitter {
|
|
6
|
+
res;
|
|
7
|
+
closed = false;
|
|
8
|
+
constructor(res) {
|
|
9
|
+
this.res = res;
|
|
10
|
+
}
|
|
11
|
+
emit(event) {
|
|
12
|
+
if (this.closed)
|
|
13
|
+
return;
|
|
14
|
+
const data = JSON.stringify(event);
|
|
15
|
+
this.res.write(`data: ${data}\n\n`);
|
|
16
|
+
}
|
|
17
|
+
textStart(messageId) {
|
|
18
|
+
this.emit({ type: 'TEXT_MESSAGE_START', messageId, role: 'assistant', timestamp: now() });
|
|
19
|
+
}
|
|
20
|
+
textContent(messageId, delta) {
|
|
21
|
+
this.emit({ type: 'TEXT_MESSAGE_CONTENT', messageId, delta, timestamp: now() });
|
|
22
|
+
}
|
|
23
|
+
textEnd(messageId) {
|
|
24
|
+
this.emit({ type: 'TEXT_MESSAGE_END', messageId, timestamp: now() });
|
|
25
|
+
}
|
|
26
|
+
toolCallStart(id, name) {
|
|
27
|
+
this.emit({ type: 'TOOL_CALL_START', toolCallId: id, toolCallName: name, timestamp: now() });
|
|
28
|
+
}
|
|
29
|
+
toolCallArgs(id, delta) {
|
|
30
|
+
this.emit({ type: 'TOOL_CALL_ARGS', toolCallId: id, delta, timestamp: now() });
|
|
31
|
+
}
|
|
32
|
+
toolCallEnd(id) {
|
|
33
|
+
this.emit({ type: 'TOOL_CALL_END', toolCallId: id, timestamp: now() });
|
|
34
|
+
}
|
|
35
|
+
stateSnapshot(snapshot) {
|
|
36
|
+
this.emit({ type: 'STATE_SNAPSHOT', snapshot, timestamp: now() });
|
|
37
|
+
}
|
|
38
|
+
stateDelta(delta) {
|
|
39
|
+
this.emit({ type: 'STATE_DELTA', delta, timestamp: now() });
|
|
40
|
+
}
|
|
41
|
+
runStarted(runId, threadId) {
|
|
42
|
+
this.emit({ type: 'RUN_STARTED', runId, ...(threadId ? { threadId } : {}), timestamp: now() });
|
|
43
|
+
}
|
|
44
|
+
runFinished(runId) {
|
|
45
|
+
this.emit({ type: 'RUN_FINISHED', runId, timestamp: now() });
|
|
46
|
+
}
|
|
47
|
+
runError(runId, message, code) {
|
|
48
|
+
this.emit({ type: 'RUN_ERROR', runId, message, ...(code ? { code } : {}), timestamp: now() });
|
|
49
|
+
}
|
|
50
|
+
stepStarted(stepId, stepName) {
|
|
51
|
+
this.emit({ type: 'STEP_STARTED', stepId, ...(stepName ? { stepName } : {}), timestamp: now() });
|
|
52
|
+
}
|
|
53
|
+
stepFinished(stepId) {
|
|
54
|
+
this.emit({ type: 'STEP_FINISHED', stepId, timestamp: now() });
|
|
55
|
+
}
|
|
56
|
+
messagesSnapshot(messages) {
|
|
57
|
+
this.emit({ type: 'MESSAGES_SNAPSHOT', messages, timestamp: now() });
|
|
58
|
+
}
|
|
59
|
+
custom(name, value) {
|
|
60
|
+
this.emit({ type: 'CUSTOM', name, value, timestamp: now() });
|
|
61
|
+
}
|
|
62
|
+
close() {
|
|
63
|
+
if (this.closed)
|
|
64
|
+
return;
|
|
65
|
+
this.closed = true;
|
|
66
|
+
this.res.end();
|
|
67
|
+
}
|
|
68
|
+
get isClosed() {
|
|
69
|
+
return this.closed;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.AGUIEventEmitter = AGUIEventEmitter;
|
|
73
|
+
// ─── AGUIServer ──────────────────────────────────────────────
|
|
74
|
+
class AGUIServer {
|
|
75
|
+
agent;
|
|
76
|
+
path;
|
|
77
|
+
constructor(agent, config) {
|
|
78
|
+
this.agent = agent;
|
|
79
|
+
this.path = config?.path ?? '/agui';
|
|
80
|
+
}
|
|
81
|
+
mount(server) {
|
|
82
|
+
const original = server.listeners('request')[0];
|
|
83
|
+
server.removeAllListeners('request');
|
|
84
|
+
server.on('request', (req, res) => {
|
|
85
|
+
const url = new URL(req.url || '/', `http://${req.headers.host || 'localhost'}`);
|
|
86
|
+
if (req.method === 'POST' && url.pathname === this.path) {
|
|
87
|
+
this.handleRun(req, res);
|
|
88
|
+
}
|
|
89
|
+
else if (req.method === 'OPTIONS' && url.pathname === this.path) {
|
|
90
|
+
res.writeHead(204, {
|
|
91
|
+
'Access-Control-Allow-Origin': '*',
|
|
92
|
+
'Access-Control-Allow-Methods': 'POST, OPTIONS',
|
|
93
|
+
'Access-Control-Allow-Headers': 'Content-Type',
|
|
94
|
+
});
|
|
95
|
+
res.end();
|
|
96
|
+
}
|
|
97
|
+
else if (original) {
|
|
98
|
+
original(req, res);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
res.writeHead(404);
|
|
102
|
+
res.end('Not Found');
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async handleRun(req, res) {
|
|
107
|
+
let body = '';
|
|
108
|
+
for await (const chunk of req)
|
|
109
|
+
body += chunk;
|
|
110
|
+
let request;
|
|
111
|
+
try {
|
|
112
|
+
request = JSON.parse(body);
|
|
113
|
+
if (!request.messages || !Array.isArray(request.messages)) {
|
|
114
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
115
|
+
res.end(JSON.stringify({ error: 'messages array required' }));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
121
|
+
res.end(JSON.stringify({ error: 'Invalid JSON' }));
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
// Set up SSE
|
|
125
|
+
res.writeHead(200, {
|
|
126
|
+
'Content-Type': 'text/event-stream',
|
|
127
|
+
'Cache-Control': 'no-cache',
|
|
128
|
+
'Connection': 'keep-alive',
|
|
129
|
+
'Access-Control-Allow-Origin': '*',
|
|
130
|
+
});
|
|
131
|
+
const emitter = new AGUIEventEmitter(res);
|
|
132
|
+
const runId = request.runId ?? `run_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
133
|
+
try {
|
|
134
|
+
await this.streamResponse(request, emitter, runId);
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
emitter.runError(runId, err?.message ?? 'Unknown error', 'INTERNAL_ERROR');
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
emitter.close();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async streamResponse(request, emitter, runId) {
|
|
144
|
+
emitter.runStarted(runId, request.threadId);
|
|
145
|
+
// Convert AG-UI messages to BaseAgent message format
|
|
146
|
+
const lastUserMsg = [...request.messages].reverse().find(m => m.role === 'user');
|
|
147
|
+
if (!lastUserMsg) {
|
|
148
|
+
emitter.runError(runId, 'No user message found', 'BAD_REQUEST');
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const message = {
|
|
152
|
+
id: lastUserMsg.id || `msg_${Date.now()}`,
|
|
153
|
+
role: 'user',
|
|
154
|
+
content: lastUserMsg.content,
|
|
155
|
+
timestamp: Date.now(),
|
|
156
|
+
metadata: {
|
|
157
|
+
channel: 'agui',
|
|
158
|
+
sessionId: request.threadId ?? 'agui-default',
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
const messageId = `msg_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
162
|
+
// Try streaming if agent supports it
|
|
163
|
+
try {
|
|
164
|
+
emitter.textStart(messageId);
|
|
165
|
+
let hasChunks = false;
|
|
166
|
+
for await (const chunk of this.agent.handleMessageStream(message)) {
|
|
167
|
+
hasChunks = true;
|
|
168
|
+
emitter.textContent(messageId, chunk);
|
|
169
|
+
}
|
|
170
|
+
if (!hasChunks) {
|
|
171
|
+
// Fallback to non-streaming
|
|
172
|
+
const response = await this.agent.handleMessage(message);
|
|
173
|
+
emitter.textContent(messageId, response.content);
|
|
174
|
+
}
|
|
175
|
+
emitter.textEnd(messageId);
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
// Fallback to non-streaming handleMessage
|
|
179
|
+
emitter.textStart(messageId);
|
|
180
|
+
const response = await this.agent.handleMessage(message);
|
|
181
|
+
emitter.textContent(messageId, response.content);
|
|
182
|
+
emitter.textEnd(messageId);
|
|
183
|
+
}
|
|
184
|
+
emitter.runFinished(runId);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.AGUIServer = AGUIServer;
|
|
188
|
+
function now() {
|
|
189
|
+
return new Date().toISOString();
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export type AGUIEventType = 'TEXT_MESSAGE_START' | 'TEXT_MESSAGE_CONTENT' | 'TEXT_MESSAGE_END' | 'TOOL_CALL_START' | 'TOOL_CALL_ARGS' | 'TOOL_CALL_END' | 'STATE_SNAPSHOT' | 'STATE_DELTA' | 'MESSAGES_SNAPSHOT' | 'RUN_STARTED' | 'RUN_FINISHED' | 'RUN_ERROR' | 'STEP_STARTED' | 'STEP_FINISHED' | 'CUSTOM';
|
|
2
|
+
export declare const AGUI_EVENT_TYPES: AGUIEventType[];
|
|
3
|
+
export interface AGUIEvent {
|
|
4
|
+
type: AGUIEventType;
|
|
5
|
+
timestamp: string;
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}
|
|
8
|
+
export interface TextMessageStartEvent extends AGUIEvent {
|
|
9
|
+
type: 'TEXT_MESSAGE_START';
|
|
10
|
+
messageId: string;
|
|
11
|
+
role: 'assistant';
|
|
12
|
+
}
|
|
13
|
+
export interface TextMessageContentEvent extends AGUIEvent {
|
|
14
|
+
type: 'TEXT_MESSAGE_CONTENT';
|
|
15
|
+
messageId: string;
|
|
16
|
+
delta: string;
|
|
17
|
+
}
|
|
18
|
+
export interface TextMessageEndEvent extends AGUIEvent {
|
|
19
|
+
type: 'TEXT_MESSAGE_END';
|
|
20
|
+
messageId: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ToolCallStartEvent extends AGUIEvent {
|
|
23
|
+
type: 'TOOL_CALL_START';
|
|
24
|
+
toolCallId: string;
|
|
25
|
+
toolCallName: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ToolCallArgsEvent extends AGUIEvent {
|
|
28
|
+
type: 'TOOL_CALL_ARGS';
|
|
29
|
+
toolCallId: string;
|
|
30
|
+
delta: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ToolCallEndEvent extends AGUIEvent {
|
|
33
|
+
type: 'TOOL_CALL_END';
|
|
34
|
+
toolCallId: string;
|
|
35
|
+
}
|
|
36
|
+
export interface StateSnapshotEvent extends AGUIEvent {
|
|
37
|
+
type: 'STATE_SNAPSHOT';
|
|
38
|
+
snapshot: Record<string, any>;
|
|
39
|
+
}
|
|
40
|
+
export interface StateDeltaEvent extends AGUIEvent {
|
|
41
|
+
type: 'STATE_DELTA';
|
|
42
|
+
delta: any[];
|
|
43
|
+
}
|
|
44
|
+
export interface MessagesSnapshotEvent extends AGUIEvent {
|
|
45
|
+
type: 'MESSAGES_SNAPSHOT';
|
|
46
|
+
messages: AGUIMessage[];
|
|
47
|
+
}
|
|
48
|
+
export interface RunStartedEvent extends AGUIEvent {
|
|
49
|
+
type: 'RUN_STARTED';
|
|
50
|
+
runId: string;
|
|
51
|
+
threadId?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface RunFinishedEvent extends AGUIEvent {
|
|
54
|
+
type: 'RUN_FINISHED';
|
|
55
|
+
runId: string;
|
|
56
|
+
}
|
|
57
|
+
export interface RunErrorEvent extends AGUIEvent {
|
|
58
|
+
type: 'RUN_ERROR';
|
|
59
|
+
runId: string;
|
|
60
|
+
message: string;
|
|
61
|
+
code?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface StepStartedEvent extends AGUIEvent {
|
|
64
|
+
type: 'STEP_STARTED';
|
|
65
|
+
stepId: string;
|
|
66
|
+
stepName?: string;
|
|
67
|
+
}
|
|
68
|
+
export interface StepFinishedEvent extends AGUIEvent {
|
|
69
|
+
type: 'STEP_FINISHED';
|
|
70
|
+
stepId: string;
|
|
71
|
+
}
|
|
72
|
+
export interface CustomEvent extends AGUIEvent {
|
|
73
|
+
type: 'CUSTOM';
|
|
74
|
+
name: string;
|
|
75
|
+
value: any;
|
|
76
|
+
}
|
|
77
|
+
export interface AGUIMessage {
|
|
78
|
+
id: string;
|
|
79
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
80
|
+
content: string;
|
|
81
|
+
name?: string;
|
|
82
|
+
toolCallId?: string;
|
|
83
|
+
toolCalls?: AGUIToolCall[];
|
|
84
|
+
}
|
|
85
|
+
export interface AGUIToolCall {
|
|
86
|
+
id: string;
|
|
87
|
+
type: 'function';
|
|
88
|
+
function: {
|
|
89
|
+
name: string;
|
|
90
|
+
arguments: string;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export interface AGUIRunRequest {
|
|
94
|
+
threadId?: string;
|
|
95
|
+
runId?: string;
|
|
96
|
+
messages: AGUIMessage[];
|
|
97
|
+
tools?: AGUIToolDefinition[];
|
|
98
|
+
context?: any[];
|
|
99
|
+
forwardedProps?: Record<string, any>;
|
|
100
|
+
}
|
|
101
|
+
export interface AGUIToolDefinition {
|
|
102
|
+
name: string;
|
|
103
|
+
description: string;
|
|
104
|
+
parameters: Record<string, any>;
|
|
105
|
+
}
|
|
106
|
+
export declare function isValidEventType(type: string): type is AGUIEventType;
|
|
107
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// AG-UI Protocol Types — Agent-User Interaction Protocol
|
|
3
|
+
// https://docs.ag-ui.com
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.AGUI_EVENT_TYPES = void 0;
|
|
6
|
+
exports.isValidEventType = isValidEventType;
|
|
7
|
+
exports.AGUI_EVENT_TYPES = [
|
|
8
|
+
'TEXT_MESSAGE_START', 'TEXT_MESSAGE_CONTENT', 'TEXT_MESSAGE_END',
|
|
9
|
+
'TOOL_CALL_START', 'TOOL_CALL_ARGS', 'TOOL_CALL_END',
|
|
10
|
+
'STATE_SNAPSHOT', 'STATE_DELTA', 'MESSAGES_SNAPSHOT',
|
|
11
|
+
'RUN_STARTED', 'RUN_FINISHED', 'RUN_ERROR',
|
|
12
|
+
'STEP_STARTED', 'STEP_FINISHED', 'CUSTOM',
|
|
13
|
+
];
|
|
14
|
+
function isValidEventType(type) {
|
|
15
|
+
return exports.AGUI_EVENT_TYPES.includes(type);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// Protocols barrel export
|
|
18
|
+
__exportStar(require("./agui"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MCPServerToolDefinition, MCPResourceDefinition } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Convert an OPC agent into MCP tool definitions.
|
|
4
|
+
* Works with any agent-like object that has name/handleMessage/brain.
|
|
5
|
+
*/
|
|
6
|
+
export declare function agentToMCPTools(agent: any): MCPServerToolDefinition[];
|
|
7
|
+
/**
|
|
8
|
+
* Expose agent files and brain pages as MCP resources.
|
|
9
|
+
*/
|
|
10
|
+
export declare function agentToMCPResources(agent: any, agentDir: string): MCPResourceDefinition[];
|
|
11
|
+
//# sourceMappingURL=agent-tools.d.ts.map
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.agentToMCPTools = agentToMCPTools;
|
|
4
|
+
exports.agentToMCPResources = agentToMCPResources;
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
/**
|
|
8
|
+
* Convert an OPC agent into MCP tool definitions.
|
|
9
|
+
* Works with any agent-like object that has name/handleMessage/brain.
|
|
10
|
+
*/
|
|
11
|
+
function agentToMCPTools(agent) {
|
|
12
|
+
const tools = [];
|
|
13
|
+
const agentName = agent?.name || agent?.config?.name || 'agent';
|
|
14
|
+
// 1. Chat tool
|
|
15
|
+
tools.push({
|
|
16
|
+
name: 'chat',
|
|
17
|
+
description: `Chat with ${agentName} agent`,
|
|
18
|
+
inputSchema: {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: { message: { type: 'string', description: 'Message to send to the agent' } },
|
|
21
|
+
required: ['message'],
|
|
22
|
+
},
|
|
23
|
+
handler: async (args) => {
|
|
24
|
+
if (typeof agent.handleMessage === 'function') {
|
|
25
|
+
const result = await agent.handleMessage({
|
|
26
|
+
role: 'user', content: args.message, channel: 'mcp',
|
|
27
|
+
});
|
|
28
|
+
return typeof result === 'string' ? result : result?.content || JSON.stringify(result);
|
|
29
|
+
}
|
|
30
|
+
return `Agent ${agentName} does not support handleMessage`;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
// 2. Memory search
|
|
34
|
+
tools.push({
|
|
35
|
+
name: 'memory_search',
|
|
36
|
+
description: 'Search agent memory/knowledge',
|
|
37
|
+
inputSchema: {
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: { query: { type: 'string', description: 'Search query' } },
|
|
40
|
+
required: ['query'],
|
|
41
|
+
},
|
|
42
|
+
handler: async (args) => {
|
|
43
|
+
const brain = agent.brain || agent.memory || agent.memoryStore;
|
|
44
|
+
if (brain && typeof brain.query === 'function') {
|
|
45
|
+
return await brain.query(args.query);
|
|
46
|
+
}
|
|
47
|
+
if (brain && typeof brain.search === 'function') {
|
|
48
|
+
return await brain.search(args.query);
|
|
49
|
+
}
|
|
50
|
+
return 'Memory search not available';
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
// 3. Memory store
|
|
54
|
+
tools.push({
|
|
55
|
+
name: 'memory_store',
|
|
56
|
+
description: 'Store knowledge in agent memory',
|
|
57
|
+
inputSchema: {
|
|
58
|
+
type: 'object',
|
|
59
|
+
properties: {
|
|
60
|
+
slug: { type: 'string', description: 'Identifier/key for the memory entry' },
|
|
61
|
+
content: { type: 'string', description: 'Content to store' },
|
|
62
|
+
},
|
|
63
|
+
required: ['slug', 'content'],
|
|
64
|
+
},
|
|
65
|
+
handler: async (args) => {
|
|
66
|
+
const brain = agent.brain || agent.memory || agent.memoryStore;
|
|
67
|
+
if (brain && typeof brain.put === 'function') {
|
|
68
|
+
await brain.put(args.slug, args.content);
|
|
69
|
+
return `Stored: ${args.slug}`;
|
|
70
|
+
}
|
|
71
|
+
if (brain && typeof brain.store === 'function') {
|
|
72
|
+
await brain.store(args.slug, args.content);
|
|
73
|
+
return `Stored: ${args.slug}`;
|
|
74
|
+
}
|
|
75
|
+
return 'Memory store not available';
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
// 4. Expose agent skills as individual tools
|
|
79
|
+
const skills = agent.skills || agent.skillRegistry?.list?.() || [];
|
|
80
|
+
for (const skill of Array.isArray(skills) ? skills : []) {
|
|
81
|
+
const skillName = skill.name || skill.id;
|
|
82
|
+
if (!skillName)
|
|
83
|
+
continue;
|
|
84
|
+
tools.push({
|
|
85
|
+
name: `skill_${skillName}`,
|
|
86
|
+
description: skill.description || `Execute ${skillName} skill`,
|
|
87
|
+
inputSchema: skill.inputSchema || {
|
|
88
|
+
type: 'object',
|
|
89
|
+
properties: { input: { type: 'string' } },
|
|
90
|
+
required: ['input'],
|
|
91
|
+
},
|
|
92
|
+
handler: async (args) => {
|
|
93
|
+
if (typeof skill.execute === 'function') {
|
|
94
|
+
return await skill.execute(args);
|
|
95
|
+
}
|
|
96
|
+
return `Skill ${skillName} not executable`;
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return tools;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Expose agent files and brain pages as MCP resources.
|
|
104
|
+
*/
|
|
105
|
+
function agentToMCPResources(agent, agentDir) {
|
|
106
|
+
const resources = [];
|
|
107
|
+
// Standard agent files
|
|
108
|
+
const standardFiles = [
|
|
109
|
+
{ name: 'SOUL.md', desc: 'Agent personality and identity' },
|
|
110
|
+
{ name: 'CONTEXT.md', desc: 'Agent context' },
|
|
111
|
+
{ name: 'AGENTS.md', desc: 'Agent instructions' },
|
|
112
|
+
{ name: 'USER.md', desc: 'User profile' },
|
|
113
|
+
{ name: 'agent.yaml', desc: 'Agent OAD configuration' },
|
|
114
|
+
];
|
|
115
|
+
for (const file of standardFiles) {
|
|
116
|
+
const filePath = (0, path_1.join)(agentDir, file.name);
|
|
117
|
+
if ((0, fs_1.existsSync)(filePath)) {
|
|
118
|
+
resources.push({
|
|
119
|
+
uri: `agent:///${file.name}`,
|
|
120
|
+
name: file.name,
|
|
121
|
+
description: file.desc,
|
|
122
|
+
mimeType: file.name.endsWith('.yaml') ? 'text/yaml' : 'text/markdown',
|
|
123
|
+
handler: async () => (0, fs_1.readFileSync)(filePath, 'utf-8'),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return resources;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=agent-tools.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { MCPServerConfig, MCPServerToolDefinition, MCPResourceDefinition, MCPPromptDefinition, MCPPromptArgument, MCPPromptMessage, JsonRpcRequest, JsonRpcResponse, } from './types';
|
|
2
|
+
export { MCP_ERRORS } from './types';
|
|
3
|
+
export { MCPServer } from './server';
|
|
4
|
+
export { agentToMCPTools, agentToMCPResources } from './agent-tools';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.agentToMCPResources = exports.agentToMCPTools = exports.MCPServer = exports.MCP_ERRORS = void 0;
|
|
4
|
+
var types_1 = require("./types");
|
|
5
|
+
Object.defineProperty(exports, "MCP_ERRORS", { enumerable: true, get: function () { return types_1.MCP_ERRORS; } });
|
|
6
|
+
var server_1 = require("./server");
|
|
7
|
+
Object.defineProperty(exports, "MCPServer", { enumerable: true, get: function () { return server_1.MCPServer; } });
|
|
8
|
+
var agent_tools_1 = require("./agent-tools");
|
|
9
|
+
Object.defineProperty(exports, "agentToMCPTools", { enumerable: true, get: function () { return agent_tools_1.agentToMCPTools; } });
|
|
10
|
+
Object.defineProperty(exports, "agentToMCPResources", { enumerable: true, get: function () { return agent_tools_1.agentToMCPResources; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MCPServerConfig, MCPServerToolDefinition, MCPResourceDefinition, MCPPromptDefinition, JsonRpcRequest, JsonRpcResponse } from './types';
|
|
2
|
+
export declare class MCPServer {
|
|
3
|
+
private config;
|
|
4
|
+
private tools;
|
|
5
|
+
private resources;
|
|
6
|
+
private prompts;
|
|
7
|
+
private sseClients;
|
|
8
|
+
private httpServer;
|
|
9
|
+
constructor(config: MCPServerConfig);
|
|
10
|
+
addTool(tool: MCPServerToolDefinition): void;
|
|
11
|
+
removeTool(name: string): void;
|
|
12
|
+
addResource(resource: MCPResourceDefinition): void;
|
|
13
|
+
removeResource(uri: string): void;
|
|
14
|
+
addPrompt(prompt: MCPPromptDefinition): void;
|
|
15
|
+
getToolCount(): number;
|
|
16
|
+
getResourceCount(): number;
|
|
17
|
+
getPromptCount(): number;
|
|
18
|
+
getConnectedClients(): number;
|
|
19
|
+
/** Serve over stdio — one JSON-RPC message per line */
|
|
20
|
+
serveStdio(): Promise<void>;
|
|
21
|
+
/** Serve over HTTP + SSE */
|
|
22
|
+
serveHTTP(port: number): Promise<void>;
|
|
23
|
+
/** Mount on existing HTTP server at a path prefix */
|
|
24
|
+
mount(server: any, path?: string): void;
|
|
25
|
+
stop(): void;
|
|
26
|
+
private handleHTTP;
|
|
27
|
+
handleMessage(msg: JsonRpcRequest): Promise<JsonRpcResponse | null>;
|
|
28
|
+
private rpcResult;
|
|
29
|
+
private rpcError;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=server.d.ts.map
|