opc-agent 4.1.24 → 4.2.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 +59 -119
- package/STUDIO-REWRITE-TASK.md +76 -0
- package/dist/core/a2a-http.d.ts +75 -0
- package/dist/core/a2a-http.d.ts.map +1 -0
- package/dist/core/a2a-http.js +217 -0
- package/dist/core/a2a-http.js.map +1 -0
- package/dist/core/a2a.d.ts +2 -0
- package/dist/core/a2a.d.ts.map +1 -1
- package/dist/core/a2a.js +6 -1
- package/dist/core/a2a.js.map +1 -1
- package/dist/core/gateway-registry.d.ts +116 -0
- package/dist/core/gateway-registry.d.ts.map +1 -0
- package/dist/core/gateway-registry.js +280 -0
- package/dist/core/gateway-registry.js.map +1 -0
- package/dist/core/priority-queue.d.ts +100 -0
- package/dist/core/priority-queue.d.ts.map +1 -0
- package/dist/core/priority-queue.js +181 -0
- package/dist/core/priority-queue.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -5
- package/dist/index.js.map +1 -1
- package/dist/studio/server.d.ts.map +1 -1
- package/dist/studio/server.js +6 -5
- package/dist/studio/server.js.map +1 -1
- package/dist/studio-ui/index.html +860 -2942
- package/package.json +66 -66
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Gateway — Remote managed tool provider pattern.
|
|
3
|
+
*
|
|
4
|
+
* Inspired by Hermes Agent v0.10's Tool Gateway feature.
|
|
5
|
+
* Allows agents to access remote tool services (web search, image gen, TTS,
|
|
6
|
+
* browser automation) through a unified gateway, removing the need for
|
|
7
|
+
* individual API keys per tool.
|
|
8
|
+
*
|
|
9
|
+
* Key features:
|
|
10
|
+
* - Subscription-based tool access (single API key → multiple tools)
|
|
11
|
+
* - Per-tool opt-in/opt-out via configuration
|
|
12
|
+
* - Auto-detection of gateway availability
|
|
13
|
+
* - Fallback to direct API keys when gateway unavailable
|
|
14
|
+
* - Usage tracking and quota enforcement
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* const gw = new ToolGateway({ endpoint: 'https://tools.example.com', apiKey: '...' });
|
|
18
|
+
* await gw.connect();
|
|
19
|
+
* const result = await gw.invoke('web-search', { query: 'hello' });
|
|
20
|
+
*/
|
|
21
|
+
import { EventEmitter } from 'events';
|
|
22
|
+
export interface ToolGatewayConfig {
|
|
23
|
+
/** Gateway endpoint URL */
|
|
24
|
+
endpoint: string;
|
|
25
|
+
/** API key / subscription token for the gateway */
|
|
26
|
+
apiKey: string;
|
|
27
|
+
/** Tools to enable (empty = all available) */
|
|
28
|
+
enabledTools?: string[];
|
|
29
|
+
/** Timeout for gateway calls (ms, default 60s) */
|
|
30
|
+
timeout?: number;
|
|
31
|
+
/** Whether to prefer gateway over direct API keys */
|
|
32
|
+
preferGateway?: boolean;
|
|
33
|
+
/** Retry config */
|
|
34
|
+
retry?: {
|
|
35
|
+
maxRetries?: number;
|
|
36
|
+
backoffMs?: number;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export interface GatewayTool {
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
description: string;
|
|
43
|
+
inputSchema: Record<string, unknown>;
|
|
44
|
+
category: 'search' | 'generation' | 'browser' | 'tts' | 'utility' | string;
|
|
45
|
+
quotaRemaining?: number;
|
|
46
|
+
available: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface GatewayInvocation {
|
|
49
|
+
toolId: string;
|
|
50
|
+
input: Record<string, unknown>;
|
|
51
|
+
requestId?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface GatewayResult {
|
|
54
|
+
toolId: string;
|
|
55
|
+
requestId: string;
|
|
56
|
+
status: 'success' | 'error' | 'quota_exceeded' | 'unavailable';
|
|
57
|
+
output?: unknown;
|
|
58
|
+
error?: string;
|
|
59
|
+
durationMs: number;
|
|
60
|
+
quotaRemaining?: number;
|
|
61
|
+
}
|
|
62
|
+
export interface GatewayStatus {
|
|
63
|
+
connected: boolean;
|
|
64
|
+
endpoint: string;
|
|
65
|
+
tools: GatewayTool[];
|
|
66
|
+
subscription?: {
|
|
67
|
+
tier: string;
|
|
68
|
+
quotaUsed: number;
|
|
69
|
+
quotaTotal: number;
|
|
70
|
+
resetAt?: string;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export declare class ToolGateway extends EventEmitter {
|
|
74
|
+
private config;
|
|
75
|
+
private tools;
|
|
76
|
+
private connected;
|
|
77
|
+
private logger;
|
|
78
|
+
private invocationCount;
|
|
79
|
+
constructor(config: ToolGatewayConfig);
|
|
80
|
+
/** Connect to gateway and discover available tools */
|
|
81
|
+
connect(): Promise<GatewayStatus>;
|
|
82
|
+
/** Invoke a tool through the gateway */
|
|
83
|
+
invoke(toolId: string, input: Record<string, unknown>): Promise<GatewayResult>;
|
|
84
|
+
/** Get a tool definition (for MCP/tool schema exposure) */
|
|
85
|
+
getTool(toolId: string): GatewayTool | undefined;
|
|
86
|
+
/** List all available tools */
|
|
87
|
+
listTools(): GatewayTool[];
|
|
88
|
+
/** Get current status */
|
|
89
|
+
getStatus(): GatewayStatus;
|
|
90
|
+
/** Check if gateway should be preferred over direct API call */
|
|
91
|
+
shouldUseGateway(toolId: string): boolean;
|
|
92
|
+
/** Disconnect from gateway */
|
|
93
|
+
disconnect(): void;
|
|
94
|
+
get isConnected(): boolean;
|
|
95
|
+
get totalInvocations(): number;
|
|
96
|
+
private request;
|
|
97
|
+
private generateRequestId;
|
|
98
|
+
}
|
|
99
|
+
export declare class ToolGatewayRegistry {
|
|
100
|
+
private gateways;
|
|
101
|
+
private toolToGateway;
|
|
102
|
+
private logger;
|
|
103
|
+
/** Register a gateway */
|
|
104
|
+
register(name: string, gateway: ToolGateway): void;
|
|
105
|
+
/** Find which gateway provides a tool */
|
|
106
|
+
findGateway(toolId: string): ToolGateway | undefined;
|
|
107
|
+
/** Invoke a tool, auto-routing to the right gateway */
|
|
108
|
+
invoke(toolId: string, input: Record<string, unknown>): Promise<GatewayResult>;
|
|
109
|
+
/** List all tools across all gateways */
|
|
110
|
+
listAllTools(): Array<GatewayTool & {
|
|
111
|
+
gateway: string;
|
|
112
|
+
}>;
|
|
113
|
+
/** Disconnect all gateways */
|
|
114
|
+
disconnectAll(): void;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=gateway-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-registry.d.ts","sourceRoot":"","sources":["../../src/core/gateway-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAKtC,MAAM,WAAW,iBAAiB;IAChC,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,kDAAkD;IAClD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,mBAAmB;IACnB,KAAK,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACrD;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,QAAQ,EAAE,QAAQ,GAAG,YAAY,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,CAAC;IAC3E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE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AE;IAI1B,yBAAyB;IACzB,SAAS,IAAI,aAAa;IAQ1B,gEAAgE;IAChE,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IASzC,8BAA8B;IAC9B,UAAU,IAAI,IAAI;IAMlB,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,IAAI,gBAAgB,IAAI,MAAM,CAE7B;YAIa,OAAO;IA2CrB,OAAO,CAAC,iBAAiB;CAG1B;AAID,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAuC;IACvD,OAAO,CAAC,aAAa,CAAkC;IACvD,OAAO,CAAC,MAAM,CAAuC;IAErD,yBAAyB;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI;IASlD,yCAAyC;IACzC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAKpD,uDAAuD;IACjD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IAcpF,yCAAyC;IACzC,YAAY,IAAI,KAAK,CAAC,WAAW,GAAG;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAUxD,8BAA8B;IAC9B,aAAa,IAAI,IAAI;CAOtB"}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tool Gateway — Remote managed tool provider pattern.
|
|
4
|
+
*
|
|
5
|
+
* Inspired by Hermes Agent v0.10's Tool Gateway feature.
|
|
6
|
+
* Allows agents to access remote tool services (web search, image gen, TTS,
|
|
7
|
+
* browser automation) through a unified gateway, removing the need for
|
|
8
|
+
* individual API keys per tool.
|
|
9
|
+
*
|
|
10
|
+
* Key features:
|
|
11
|
+
* - Subscription-based tool access (single API key → multiple tools)
|
|
12
|
+
* - Per-tool opt-in/opt-out via configuration
|
|
13
|
+
* - Auto-detection of gateway availability
|
|
14
|
+
* - Fallback to direct API keys when gateway unavailable
|
|
15
|
+
* - Usage tracking and quota enforcement
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
* const gw = new ToolGateway({ endpoint: 'https://tools.example.com', apiKey: '...' });
|
|
19
|
+
* await gw.connect();
|
|
20
|
+
* const result = await gw.invoke('web-search', { query: 'hello' });
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.ToolGatewayRegistry = exports.ToolGateway = void 0;
|
|
24
|
+
const events_1 = require("events");
|
|
25
|
+
const logger_1 = require("./logger");
|
|
26
|
+
// ─── Tool Gateway ────────────────────────────────────────────
|
|
27
|
+
class ToolGateway extends events_1.EventEmitter {
|
|
28
|
+
config;
|
|
29
|
+
tools = new Map();
|
|
30
|
+
connected = false;
|
|
31
|
+
logger = new logger_1.Logger('tool-gateway');
|
|
32
|
+
invocationCount = 0;
|
|
33
|
+
constructor(config) {
|
|
34
|
+
super();
|
|
35
|
+
this.config = {
|
|
36
|
+
endpoint: config.endpoint.replace(/\/$/, ''),
|
|
37
|
+
apiKey: config.apiKey,
|
|
38
|
+
enabledTools: config.enabledTools ?? [],
|
|
39
|
+
timeout: config.timeout ?? 60_000,
|
|
40
|
+
preferGateway: config.preferGateway ?? true,
|
|
41
|
+
retry: {
|
|
42
|
+
maxRetries: config.retry?.maxRetries ?? 2,
|
|
43
|
+
backoffMs: config.retry?.backoffMs ?? 1000,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** Connect to gateway and discover available tools */
|
|
48
|
+
async connect() {
|
|
49
|
+
try {
|
|
50
|
+
const res = await this.request('GET', '/tools');
|
|
51
|
+
const data = res;
|
|
52
|
+
this.tools.clear();
|
|
53
|
+
for (const tool of data.tools) {
|
|
54
|
+
// If enabledTools is specified, only include those
|
|
55
|
+
if (this.config.enabledTools.length === 0 ||
|
|
56
|
+
this.config.enabledTools.includes(tool.id)) {
|
|
57
|
+
this.tools.set(tool.id, tool);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
this.connected = true;
|
|
61
|
+
this.logger.info('Connected to tool gateway', {
|
|
62
|
+
endpoint: this.config.endpoint,
|
|
63
|
+
tools: this.tools.size,
|
|
64
|
+
});
|
|
65
|
+
this.emit('connected', this.getStatus());
|
|
66
|
+
return {
|
|
67
|
+
connected: true,
|
|
68
|
+
endpoint: this.config.endpoint,
|
|
69
|
+
tools: Array.from(this.tools.values()),
|
|
70
|
+
subscription: data.subscription,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
this.connected = false;
|
|
75
|
+
this.logger.error('Failed to connect to tool gateway', {
|
|
76
|
+
error: err.message,
|
|
77
|
+
});
|
|
78
|
+
throw err;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Invoke a tool through the gateway */
|
|
82
|
+
async invoke(toolId, input) {
|
|
83
|
+
if (!this.connected) {
|
|
84
|
+
throw new Error('Tool gateway not connected. Call connect() first.');
|
|
85
|
+
}
|
|
86
|
+
const tool = this.tools.get(toolId);
|
|
87
|
+
if (!tool) {
|
|
88
|
+
return {
|
|
89
|
+
toolId,
|
|
90
|
+
requestId: this.generateRequestId(),
|
|
91
|
+
status: 'unavailable',
|
|
92
|
+
error: `Tool "${toolId}" not available on this gateway`,
|
|
93
|
+
durationMs: 0,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (!tool.available) {
|
|
97
|
+
return {
|
|
98
|
+
toolId,
|
|
99
|
+
requestId: this.generateRequestId(),
|
|
100
|
+
status: 'unavailable',
|
|
101
|
+
error: `Tool "${toolId}" is currently unavailable`,
|
|
102
|
+
durationMs: 0,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const requestId = this.generateRequestId();
|
|
106
|
+
const start = Date.now();
|
|
107
|
+
try {
|
|
108
|
+
const result = await this.request('POST', '/invoke', {
|
|
109
|
+
toolId,
|
|
110
|
+
input,
|
|
111
|
+
requestId,
|
|
112
|
+
});
|
|
113
|
+
const durationMs = Date.now() - start;
|
|
114
|
+
this.invocationCount++;
|
|
115
|
+
const gatewayResult = {
|
|
116
|
+
toolId,
|
|
117
|
+
requestId,
|
|
118
|
+
status: 'success',
|
|
119
|
+
output: result.output,
|
|
120
|
+
durationMs,
|
|
121
|
+
quotaRemaining: result.quotaRemaining,
|
|
122
|
+
};
|
|
123
|
+
// Update quota info
|
|
124
|
+
if (gatewayResult.quotaRemaining !== undefined) {
|
|
125
|
+
tool.quotaRemaining = gatewayResult.quotaRemaining;
|
|
126
|
+
}
|
|
127
|
+
this.emit('invocation', gatewayResult);
|
|
128
|
+
return gatewayResult;
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
const durationMs = Date.now() - start;
|
|
132
|
+
const message = err.message;
|
|
133
|
+
const status = message.includes('quota') ? 'quota_exceeded' : 'error';
|
|
134
|
+
const gatewayResult = {
|
|
135
|
+
toolId,
|
|
136
|
+
requestId,
|
|
137
|
+
status,
|
|
138
|
+
error: message,
|
|
139
|
+
durationMs,
|
|
140
|
+
};
|
|
141
|
+
this.emit('invocation:error', gatewayResult);
|
|
142
|
+
return gatewayResult;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** Get a tool definition (for MCP/tool schema exposure) */
|
|
146
|
+
getTool(toolId) {
|
|
147
|
+
return this.tools.get(toolId);
|
|
148
|
+
}
|
|
149
|
+
/** List all available tools */
|
|
150
|
+
listTools() {
|
|
151
|
+
return Array.from(this.tools.values());
|
|
152
|
+
}
|
|
153
|
+
/** Get current status */
|
|
154
|
+
getStatus() {
|
|
155
|
+
return {
|
|
156
|
+
connected: this.connected,
|
|
157
|
+
endpoint: this.config.endpoint,
|
|
158
|
+
tools: Array.from(this.tools.values()),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/** Check if gateway should be preferred over direct API call */
|
|
162
|
+
shouldUseGateway(toolId) {
|
|
163
|
+
if (!this.connected)
|
|
164
|
+
return false;
|
|
165
|
+
if (!this.config.preferGateway)
|
|
166
|
+
return false;
|
|
167
|
+
const tool = this.tools.get(toolId);
|
|
168
|
+
if (!tool || !tool.available)
|
|
169
|
+
return false;
|
|
170
|
+
if (tool.quotaRemaining !== undefined && tool.quotaRemaining <= 0)
|
|
171
|
+
return false;
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
/** Disconnect from gateway */
|
|
175
|
+
disconnect() {
|
|
176
|
+
this.connected = false;
|
|
177
|
+
this.tools.clear();
|
|
178
|
+
this.emit('disconnected');
|
|
179
|
+
}
|
|
180
|
+
get isConnected() {
|
|
181
|
+
return this.connected;
|
|
182
|
+
}
|
|
183
|
+
get totalInvocations() {
|
|
184
|
+
return this.invocationCount;
|
|
185
|
+
}
|
|
186
|
+
// ─── Private helpers ─────────────────────────────────────────
|
|
187
|
+
async request(method, path, body) {
|
|
188
|
+
const url = `${this.config.endpoint}${path}`;
|
|
189
|
+
const controller = new AbortController();
|
|
190
|
+
const timer = setTimeout(() => controller.abort(), this.config.timeout);
|
|
191
|
+
let lastError;
|
|
192
|
+
const maxAttempts = 1 + (this.config.retry?.maxRetries ?? 0);
|
|
193
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
194
|
+
try {
|
|
195
|
+
const res = await fetch(url, {
|
|
196
|
+
method,
|
|
197
|
+
headers: {
|
|
198
|
+
'Content-Type': 'application/json',
|
|
199
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
200
|
+
'X-Client': 'opc-agent',
|
|
201
|
+
},
|
|
202
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
203
|
+
signal: controller.signal,
|
|
204
|
+
});
|
|
205
|
+
clearTimeout(timer);
|
|
206
|
+
if (!res.ok) {
|
|
207
|
+
const errBody = await res.text().catch(() => '');
|
|
208
|
+
throw new Error(`Gateway ${res.status}: ${errBody || res.statusText}`);
|
|
209
|
+
}
|
|
210
|
+
return await res.json();
|
|
211
|
+
}
|
|
212
|
+
catch (err) {
|
|
213
|
+
lastError = err;
|
|
214
|
+
if (attempt < maxAttempts - 1) {
|
|
215
|
+
await new Promise(r => setTimeout(r, (this.config.retry?.backoffMs ?? 1000) * (attempt + 1)));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
clearTimeout(timer);
|
|
220
|
+
throw lastError;
|
|
221
|
+
}
|
|
222
|
+
generateRequestId() {
|
|
223
|
+
return `gw_${++this.invocationCount}_${Date.now().toString(36)}`;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
exports.ToolGateway = ToolGateway;
|
|
227
|
+
// ─── Tool Gateway Registry (multi-gateway support) ───────────
|
|
228
|
+
class ToolGatewayRegistry {
|
|
229
|
+
gateways = new Map();
|
|
230
|
+
toolToGateway = new Map();
|
|
231
|
+
logger = new logger_1.Logger('tool-gateway-registry');
|
|
232
|
+
/** Register a gateway */
|
|
233
|
+
register(name, gateway) {
|
|
234
|
+
this.gateways.set(name, gateway);
|
|
235
|
+
// Index tools → gateway
|
|
236
|
+
for (const tool of gateway.listTools()) {
|
|
237
|
+
this.toolToGateway.set(tool.id, name);
|
|
238
|
+
}
|
|
239
|
+
this.logger.info('Gateway registered', { name, tools: gateway.listTools().length });
|
|
240
|
+
}
|
|
241
|
+
/** Find which gateway provides a tool */
|
|
242
|
+
findGateway(toolId) {
|
|
243
|
+
const name = this.toolToGateway.get(toolId);
|
|
244
|
+
return name ? this.gateways.get(name) : undefined;
|
|
245
|
+
}
|
|
246
|
+
/** Invoke a tool, auto-routing to the right gateway */
|
|
247
|
+
async invoke(toolId, input) {
|
|
248
|
+
const gateway = this.findGateway(toolId);
|
|
249
|
+
if (!gateway) {
|
|
250
|
+
return {
|
|
251
|
+
toolId,
|
|
252
|
+
requestId: 'none',
|
|
253
|
+
status: 'unavailable',
|
|
254
|
+
error: `No gateway provides tool "${toolId}"`,
|
|
255
|
+
durationMs: 0,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
return gateway.invoke(toolId, input);
|
|
259
|
+
}
|
|
260
|
+
/** List all tools across all gateways */
|
|
261
|
+
listAllTools() {
|
|
262
|
+
const result = [];
|
|
263
|
+
for (const [name, gw] of this.gateways) {
|
|
264
|
+
for (const tool of gw.listTools()) {
|
|
265
|
+
result.push({ ...tool, gateway: name });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return result;
|
|
269
|
+
}
|
|
270
|
+
/** Disconnect all gateways */
|
|
271
|
+
disconnectAll() {
|
|
272
|
+
for (const gw of this.gateways.values()) {
|
|
273
|
+
gw.disconnect();
|
|
274
|
+
}
|
|
275
|
+
this.gateways.clear();
|
|
276
|
+
this.toolToGateway.clear();
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
exports.ToolGatewayRegistry = ToolGatewayRegistry;
|
|
280
|
+
//# sourceMappingURL=gateway-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-registry.js","sourceRoot":"","sources":["../../src/core/gateway-registry.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAEH,mCAAsC;AACtC,qCAAkC;AAyDlC,gEAAgE;AAEhE,MAAa,WAAY,SAAQ,qBAAY;IACnC,MAAM,CAA8B;IACpC,KAAK,GAA6B,IAAI,GAAG,EAAE,CAAC;IAC5C,SAAS,GAAG,KAAK,CAAC;IAClB,MAAM,GAAG,IAAI,eAAM,CAAC,cAAc,CAAC,CAAC;IACpC,eAAe,GAAG,CAAC,CAAC;IAE5B,YAAY,MAAyB;QACnC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG;YACZ,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;YAC5C,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,EAAE;YACvC,OAA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DAuDC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Priority Queue / Fast Mode — Route requests through priority tiers
|
|
3
|
+
* for lower latency on supported providers.
|
|
4
|
+
*
|
|
5
|
+
* Inspired by Hermes Agent's /fast mode. Provides a priority-aware request
|
|
6
|
+
* queue that separates normal and fast-mode requests, ensuring fast-mode
|
|
7
|
+
* requests are processed first and routed to provider priority endpoints.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* const pq = new PriorityQueue();
|
|
11
|
+
* pq.enqueue({ id: 'req1', priority: 'fast', provider: 'openai', ... });
|
|
12
|
+
* const next = pq.dequeue(); // Always returns highest priority first
|
|
13
|
+
*/
|
|
14
|
+
import { EventEmitter } from 'events';
|
|
15
|
+
export type PriorityLevel = 'fast' | 'normal' | 'batch';
|
|
16
|
+
export interface PriorityRequest {
|
|
17
|
+
id: string;
|
|
18
|
+
priority: PriorityLevel;
|
|
19
|
+
provider: string;
|
|
20
|
+
model: string;
|
|
21
|
+
payload: unknown;
|
|
22
|
+
enqueuedAt: number;
|
|
23
|
+
metadata?: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
export interface PriorityConfig {
|
|
26
|
+
/** Maximum concurrent fast-mode requests per provider */
|
|
27
|
+
maxConcurrentFast?: number;
|
|
28
|
+
/** Maximum concurrent normal requests per provider */
|
|
29
|
+
maxConcurrentNormal?: number;
|
|
30
|
+
/** Timeout for fast-mode requests before fallback (ms, default 30s) */
|
|
31
|
+
fastTimeout?: number;
|
|
32
|
+
/** Providers that support priority routing */
|
|
33
|
+
supportedProviders?: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface ProviderPriorityEndpoint {
|
|
36
|
+
provider: string;
|
|
37
|
+
priorityUrl?: string;
|
|
38
|
+
priorityHeader?: {
|
|
39
|
+
key: string;
|
|
40
|
+
value: string;
|
|
41
|
+
};
|
|
42
|
+
priorityParam?: {
|
|
43
|
+
key: string;
|
|
44
|
+
value: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export declare class PriorityQueue extends EventEmitter {
|
|
48
|
+
private queues;
|
|
49
|
+
private activeCounts;
|
|
50
|
+
private config;
|
|
51
|
+
private endpoints;
|
|
52
|
+
constructor(config?: PriorityConfig);
|
|
53
|
+
/** Register a custom priority endpoint for a provider */
|
|
54
|
+
registerEndpoint(endpoint: ProviderPriorityEndpoint): void;
|
|
55
|
+
/** Check if a provider supports priority routing */
|
|
56
|
+
supportsPriority(provider: string): boolean;
|
|
57
|
+
/** Get priority endpoint configuration for a provider */
|
|
58
|
+
getEndpoint(provider: string): ProviderPriorityEndpoint | undefined;
|
|
59
|
+
/** Enqueue a request */
|
|
60
|
+
enqueue(request: PriorityRequest): void;
|
|
61
|
+
/** Dequeue the next highest-priority request that can run */
|
|
62
|
+
dequeue(): PriorityRequest | undefined;
|
|
63
|
+
/** Mark a request as completed, freeing a concurrency slot */
|
|
64
|
+
complete(provider: string, priority: PriorityLevel): void;
|
|
65
|
+
/** Get queue lengths */
|
|
66
|
+
getStats(): {
|
|
67
|
+
fast: number;
|
|
68
|
+
normal: number;
|
|
69
|
+
batch: number;
|
|
70
|
+
total: number;
|
|
71
|
+
active: Record<string, {
|
|
72
|
+
fast: number;
|
|
73
|
+
normal: number;
|
|
74
|
+
batch: number;
|
|
75
|
+
}>;
|
|
76
|
+
};
|
|
77
|
+
/** Drain all requests (for shutdown) */
|
|
78
|
+
drain(): PriorityRequest[];
|
|
79
|
+
/** Determine effective priority for a request (auto-upgrade/downgrade) */
|
|
80
|
+
static resolvePriority(requested: PriorityLevel, provider: string, supportedProviders: string[]): PriorityLevel;
|
|
81
|
+
private canRun;
|
|
82
|
+
private incrementActive;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Tracks per-session fast mode toggle (like /fast command).
|
|
86
|
+
*/
|
|
87
|
+
export declare class FastModeManager {
|
|
88
|
+
private sessions;
|
|
89
|
+
/** Toggle fast mode for a session, returns new state */
|
|
90
|
+
toggle(sessionId: string): boolean;
|
|
91
|
+
/** Set fast mode explicitly */
|
|
92
|
+
set(sessionId: string, enabled: boolean): void;
|
|
93
|
+
/** Check if session has fast mode enabled */
|
|
94
|
+
isEnabled(sessionId: string): boolean;
|
|
95
|
+
/** Get priority level for a session */
|
|
96
|
+
getPriority(sessionId: string): PriorityLevel;
|
|
97
|
+
/** Clear all state */
|
|
98
|
+
reset(): void;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=priority-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"priority-queue.d.ts","sourceRoot":"","sources":["../../src/core/priority-queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAItC,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;AAExD,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,aAAa,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,uEAAuE;IACvE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8CAA8C;IAC9C,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE;QAAE,GAAG,EA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