agents-library 0.1.0
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/dist/base-agent.d.ts +172 -0
- package/dist/base-agent.d.ts.map +1 -0
- package/dist/base-agent.js +255 -0
- package/dist/base-agent.js.map +1 -0
- package/dist/base-bot.d.ts +282 -0
- package/dist/base-bot.d.ts.map +1 -0
- package/dist/base-bot.js +375 -0
- package/dist/base-bot.js.map +1 -0
- package/dist/common/result.d.ts +51 -0
- package/dist/common/result.d.ts.map +1 -0
- package/dist/common/result.js +45 -0
- package/dist/common/result.js.map +1 -0
- package/dist/common/types.d.ts +57 -0
- package/dist/common/types.d.ts.map +1 -0
- package/dist/common/types.js +42 -0
- package/dist/common/types.js.map +1 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +108 -0
- package/dist/index.js.map +1 -0
- package/dist/kadi-event-publisher.d.ts +163 -0
- package/dist/kadi-event-publisher.d.ts.map +1 -0
- package/dist/kadi-event-publisher.js +286 -0
- package/dist/kadi-event-publisher.js.map +1 -0
- package/dist/memory/arcadedb-adapter.d.ts +159 -0
- package/dist/memory/arcadedb-adapter.d.ts.map +1 -0
- package/dist/memory/arcadedb-adapter.js +314 -0
- package/dist/memory/arcadedb-adapter.js.map +1 -0
- package/dist/memory/file-storage-adapter.d.ts +122 -0
- package/dist/memory/file-storage-adapter.d.ts.map +1 -0
- package/dist/memory/file-storage-adapter.js +352 -0
- package/dist/memory/file-storage-adapter.js.map +1 -0
- package/dist/memory/memory-service.d.ts +208 -0
- package/dist/memory/memory-service.d.ts.map +1 -0
- package/dist/memory/memory-service.js +410 -0
- package/dist/memory/memory-service.js.map +1 -0
- package/dist/memory/types.d.ts +126 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +41 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/producer-tool-utils.d.ts +474 -0
- package/dist/producer-tool-utils.d.ts.map +1 -0
- package/dist/producer-tool-utils.js +664 -0
- package/dist/producer-tool-utils.js.map +1 -0
- package/dist/providers/anthropic-provider.d.ts +160 -0
- package/dist/providers/anthropic-provider.d.ts.map +1 -0
- package/dist/providers/anthropic-provider.js +527 -0
- package/dist/providers/anthropic-provider.js.map +1 -0
- package/dist/providers/model-manager-provider.d.ts +91 -0
- package/dist/providers/model-manager-provider.d.ts.map +1 -0
- package/dist/providers/model-manager-provider.js +355 -0
- package/dist/providers/model-manager-provider.js.map +1 -0
- package/dist/providers/provider-manager.d.ts +111 -0
- package/dist/providers/provider-manager.d.ts.map +1 -0
- package/dist/providers/provider-manager.js +337 -0
- package/dist/providers/provider-manager.js.map +1 -0
- package/dist/providers/types.d.ts +145 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +23 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/shadow-agent-factory.d.ts +623 -0
- package/dist/shadow-agent-factory.d.ts.map +1 -0
- package/dist/shadow-agent-factory.js +1117 -0
- package/dist/shadow-agent-factory.js.map +1 -0
- package/dist/types/agent-config.d.ts +307 -0
- package/dist/types/agent-config.d.ts.map +1 -0
- package/dist/types/agent-config.js +15 -0
- package/dist/types/agent-config.js.map +1 -0
- package/dist/types/event-schemas.d.ts +358 -0
- package/dist/types/event-schemas.d.ts.map +1 -0
- package/dist/types/event-schemas.js +188 -0
- package/dist/types/event-schemas.js.map +1 -0
- package/dist/types/tool-schemas.d.ts +498 -0
- package/dist/types/tool-schemas.d.ts.map +1 -0
- package/dist/types/tool-schemas.js +457 -0
- package/dist/types/tool-schemas.js.map +1 -0
- package/dist/utils/logger.d.ts +135 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +205 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/timer.d.ts +186 -0
- package/dist/utils/timer.d.ts.map +1 -0
- package/dist/utils/timer.js +211 -0
- package/dist/utils/timer.js.map +1 -0
- package/dist/worker-agent-factory.d.ts +688 -0
- package/dist/worker-agent-factory.d.ts.map +1 -0
- package/dist/worker-agent-factory.js +1517 -0
- package/dist/worker-agent-factory.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared KĀDI Event Publisher Utility
|
|
3
|
+
* ====================================
|
|
4
|
+
*
|
|
5
|
+
* Common publisher logic extracted from mcp-client-slack and mcp-client-discord
|
|
6
|
+
* to eliminate code duplication (DRY principle).
|
|
7
|
+
*
|
|
8
|
+
* Architecture:
|
|
9
|
+
* - Generic event publishing to KĀDI broker
|
|
10
|
+
* - Platform-agnostic connection management
|
|
11
|
+
* - Graceful degradation pattern (stub mode if broker unavailable)
|
|
12
|
+
* - Retry logic with exponential backoff
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const publisher = new KadiEventPublisher({
|
|
17
|
+
* brokerUrl: 'ws://localhost:8080/kadi',
|
|
18
|
+
* clientName: 'mcp-client-slack',
|
|
19
|
+
* networks: ['slack']
|
|
20
|
+
* });
|
|
21
|
+
* await publisher.connect();
|
|
22
|
+
* await publisher.publishEvent('slack.app_mention.U12345', event);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import { KadiClient, z } from '@kadi.build/core';
|
|
26
|
+
/**
|
|
27
|
+
* Validates topic pattern against standard format: {platform}.{event_type}.{bot_id}
|
|
28
|
+
*
|
|
29
|
+
* @param topic - Topic string to validate
|
|
30
|
+
* @returns True if topic matches pattern, false otherwise
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* validateTopicPattern('slack.app_mention.U12345') // true
|
|
35
|
+
* validateTopicPattern('discord.mention.67890') // true
|
|
36
|
+
* validateTopicPattern('invalid-topic') // false
|
|
37
|
+
* validateTopicPattern('slack.app_mention') // false (missing bot_id)
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function validateTopicPattern(topic) {
|
|
41
|
+
// Pattern: {platform}.{event_type}.{bot_id}
|
|
42
|
+
// - platform: lowercase letters (e.g., 'slack', 'discord')
|
|
43
|
+
// - event_type: lowercase letters with underscores (e.g., 'app_mention', 'mention')
|
|
44
|
+
// - bot_id: alphanumeric with hyphens/underscores (e.g., 'U12345', 'bot-123')
|
|
45
|
+
const pattern = /^[a-z]+\.[a-z_]+\.[a-zA-Z0-9_-]+$/;
|
|
46
|
+
return pattern.test(topic);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Shared KĀDI Event Publisher
|
|
50
|
+
*
|
|
51
|
+
* Provides common event publishing functionality for all MCP clients.
|
|
52
|
+
* Handles connection management, retry logic, graceful degradation,
|
|
53
|
+
* and error handling.
|
|
54
|
+
*/
|
|
55
|
+
export class KadiEventPublisher {
|
|
56
|
+
client = null;
|
|
57
|
+
enabled = false;
|
|
58
|
+
config;
|
|
59
|
+
/**
|
|
60
|
+
* Create a new KĀDI Event Publisher
|
|
61
|
+
*
|
|
62
|
+
* @param config - Publisher configuration with broker URL, client name, and networks
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const publisher = new KadiEventPublisher({
|
|
67
|
+
* brokerUrl: 'ws://localhost:8080/kadi',
|
|
68
|
+
* clientName: 'mcp-client-slack',
|
|
69
|
+
* networks: ['slack']
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
constructor(config) {
|
|
74
|
+
// Set defaults for optional fields
|
|
75
|
+
this.config = {
|
|
76
|
+
brokerUrl: config.brokerUrl,
|
|
77
|
+
clientName: config.clientName,
|
|
78
|
+
networks: config.networks,
|
|
79
|
+
version: config.version || '1.0.0'
|
|
80
|
+
};
|
|
81
|
+
// Graceful degradation: Check if broker URL is valid
|
|
82
|
+
const hasValidBrokerUrl = config.brokerUrl &&
|
|
83
|
+
(config.brokerUrl.startsWith('ws://') ||
|
|
84
|
+
config.brokerUrl.startsWith('wss://'));
|
|
85
|
+
if (hasValidBrokerUrl) {
|
|
86
|
+
this.enabled = true;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
console.log('⚠️ KĀDI broker URL not configured - running in stub mode');
|
|
90
|
+
console.log(' Set KADI_BROKER_URL to enable event publishing');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Create a new KadiClient instance
|
|
95
|
+
* Must be called before each connection attempt to avoid handshake state issues
|
|
96
|
+
*
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
createClient() {
|
|
100
|
+
const client = new KadiClient({
|
|
101
|
+
name: this.config.clientName,
|
|
102
|
+
version: this.config.version,
|
|
103
|
+
brokers: {
|
|
104
|
+
default: { url: this.config.brokerUrl, networks: this.config.networks }
|
|
105
|
+
},
|
|
106
|
+
defaultBroker: 'default',
|
|
107
|
+
});
|
|
108
|
+
// Register a dummy tool to make agent visible in system snapshots
|
|
109
|
+
// This is a test to verify that broker filters agents without tools
|
|
110
|
+
const addNumberInputSchema = z.object({
|
|
111
|
+
a: z.number().describe('First number'),
|
|
112
|
+
b: z.number().describe('Second number')
|
|
113
|
+
});
|
|
114
|
+
client.registerTool({
|
|
115
|
+
name: 'addNumber',
|
|
116
|
+
description: 'Dummy tool for testing - adds two numbers together',
|
|
117
|
+
input: addNumberInputSchema,
|
|
118
|
+
output: z.object({
|
|
119
|
+
result: z.number().describe('Sum of a and b')
|
|
120
|
+
})
|
|
121
|
+
}, async (params) => {
|
|
122
|
+
return { result: params.a + params.b };
|
|
123
|
+
});
|
|
124
|
+
return client;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Connect to KĀDI broker with retry logic
|
|
128
|
+
*
|
|
129
|
+
* Establishes WebSocket connection and performs authentication handshake.
|
|
130
|
+
* Retries with exponential backoff when broker is not ready (e.g., during startup).
|
|
131
|
+
* Logs connection status for debugging.
|
|
132
|
+
*
|
|
133
|
+
* Retry schedule: 5 attempts with exponential backoff (1s, 2s, 4s, 8s, 16s)
|
|
134
|
+
*
|
|
135
|
+
* @throws {Error} If connection fails after all retries
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* await publisher.connect();
|
|
140
|
+
* console.log('Connected to KĀDI broker');
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
async connect() {
|
|
144
|
+
if (!this.enabled) {
|
|
145
|
+
console.log('[KĀDI] Publisher: Event publishing disabled {mode: stub}');
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const maxRetries = 5;
|
|
149
|
+
const baseDelayMs = 1000;
|
|
150
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
151
|
+
console.log(`[KĀDI] Publisher: Attempting connection to broker (attempt ${attempt}/${maxRetries})...`);
|
|
152
|
+
// Create a fresh client for each attempt to avoid handshake state issues
|
|
153
|
+
this.client = this.createClient();
|
|
154
|
+
try {
|
|
155
|
+
const agentId = await this.client.connect();
|
|
156
|
+
console.log(`[KĀDI] Publisher: Connected successfully {agentId: ${agentId ?? 'unknown'}, networks: ${JSON.stringify(this.config.networks)}}`);
|
|
157
|
+
return; // Success - exit retry loop
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
const isLastAttempt = attempt === maxRetries;
|
|
161
|
+
// Disconnect failed client to clean up resources
|
|
162
|
+
try {
|
|
163
|
+
await this.client.disconnect();
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// Ignore disconnect errors
|
|
167
|
+
}
|
|
168
|
+
if (isLastAttempt) {
|
|
169
|
+
console.error(`[KĀDI] Publisher: Connection failed after ${maxRetries} attempts {error: ${error.message || 'Unknown error'}}`);
|
|
170
|
+
this.client = null; // Clear client on final failure
|
|
171
|
+
throw error; // Fail-fast after all retries exhausted
|
|
172
|
+
}
|
|
173
|
+
// Exponential backoff: 1s, 2s, 4s, 8s, 16s
|
|
174
|
+
const delayMs = baseDelayMs * Math.pow(2, attempt - 1);
|
|
175
|
+
console.warn(`[KĀDI] Publisher: Connection failed, retrying in ${delayMs}ms... {error: ${error.message || 'Unknown error'}}`);
|
|
176
|
+
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Publish an event to a specific KĀDI broker topic
|
|
182
|
+
*
|
|
183
|
+
* Generic event publishing method. Accepts any event data and publishes
|
|
184
|
+
* it to the specified topic. Validation should be done by the caller.
|
|
185
|
+
*
|
|
186
|
+
* @param topic - Topic pattern (e.g., 'slack.app_mention.U12345', 'discord.mention.67890')
|
|
187
|
+
* @param event - Event data to publish (must be JSON-serializable)
|
|
188
|
+
* @param metadata - Optional metadata for logging (e.g., { eventId, user, textPreview })
|
|
189
|
+
*
|
|
190
|
+
* @throws {Error} If publish fails (fail-fast, no retry)
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* await publisher.publishEvent(
|
|
195
|
+
* 'slack.app_mention.U12345',
|
|
196
|
+
* {
|
|
197
|
+
* id: '1234567890.123456',
|
|
198
|
+
* user: 'U12345678',
|
|
199
|
+
* text: 'Hello bot!',
|
|
200
|
+
* channel: 'C12345678',
|
|
201
|
+
* bot_id: 'U87654321',
|
|
202
|
+
* timestamp: '2025-11-29T12:00:00Z'
|
|
203
|
+
* },
|
|
204
|
+
* { eventId: '1234567890.123456', user: 'U12345678', textPreview: 'Hello bot!' }
|
|
205
|
+
* );
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
async publishEvent(topic, event, metadata) {
|
|
209
|
+
// Validate topic pattern
|
|
210
|
+
if (!validateTopicPattern(topic)) {
|
|
211
|
+
console.warn(`[KĀDI] Publisher: Topic pattern validation failed {topic: ${topic}, expected: {platform}.{event_type}.{bot_id}}`);
|
|
212
|
+
}
|
|
213
|
+
if (!this.client || !this.enabled) {
|
|
214
|
+
console.log('[KĀDI] Publisher: Event publishing disabled, event not published {mode: stub}');
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
await this.client.publish(topic, event, {
|
|
219
|
+
broker: 'default',
|
|
220
|
+
network: this.config.networks[0] || 'global'
|
|
221
|
+
});
|
|
222
|
+
// Log with metadata if provided, otherwise generic log
|
|
223
|
+
if (metadata) {
|
|
224
|
+
const logParts = [`topic: ${topic}`];
|
|
225
|
+
if (metadata.eventId)
|
|
226
|
+
logParts.push(`eventId: ${metadata.eventId}`);
|
|
227
|
+
if (metadata.user)
|
|
228
|
+
logParts.push(`user: ${metadata.user}`);
|
|
229
|
+
if (metadata.textPreview)
|
|
230
|
+
logParts.push(`textPreview: "${metadata.textPreview}"`);
|
|
231
|
+
console.log(`[KĀDI] Publisher: Event published successfully {${logParts.join(', ')}}`);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
console.log(`[KĀDI] Publisher: Event published successfully {topic: ${topic}}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
// Fail-fast on publish errors (no retry)
|
|
239
|
+
console.error(`[KĀDI] Publisher: Event publication failed {topic: ${topic}, error: ${error.message || 'Unknown error'}}`);
|
|
240
|
+
throw error;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Disconnect from KĀDI broker
|
|
245
|
+
*
|
|
246
|
+
* Performs cleanup and gracefully closes WebSocket connection.
|
|
247
|
+
* Safe to call multiple times (idempotent).
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* await publisher.disconnect();
|
|
252
|
+
* console.log('Disconnected from KĀDI broker');
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
async disconnect() {
|
|
256
|
+
if (!this.client || !this.enabled) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
console.log('[KĀDI] Publisher: Disconnecting from broker...');
|
|
260
|
+
try {
|
|
261
|
+
await this.client.disconnect();
|
|
262
|
+
console.log('[KĀDI] Publisher: Disconnected successfully');
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
console.error(`[KĀDI] Publisher: Disconnection failed {error: ${error.message || 'Unknown error'}}`);
|
|
266
|
+
// Don't throw - best effort cleanup
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Check if publisher is connected and enabled
|
|
271
|
+
*
|
|
272
|
+
* @returns True if connected to broker and publishing is enabled
|
|
273
|
+
*/
|
|
274
|
+
isConnected() {
|
|
275
|
+
return this.client !== null && this.enabled;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Get current publisher configuration
|
|
279
|
+
*
|
|
280
|
+
* @returns Current publisher configuration
|
|
281
|
+
*/
|
|
282
|
+
getConfig() {
|
|
283
|
+
return { ...this.config };
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=kadi-event-publisher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kadi-event-publisher.js","sourceRoot":"","sources":["../src/kadi-event-publisher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,4CAA4C;IAC5C,2DAA2D;IAC3D,oFAAoF;IACpF,8EAA8E;IAC9E,MAAM,OAAO,GAAG,mCAAmC,CAAC;IACpD,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAmBD;;;;;;GAMG;AACH,MAAM,OAAO,kBAAkB;IACrB,MAAM,GAAsB,IAAI,CAAC;IACjC,OAAO,GAAY,KAAK,CAAC;IACzB,MAAM,CAA4B;IAE1C;;;;;;;;;;;;;OAaG;IACH,YAAY,MAAu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AI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YAC/B,OAAO,CAAC,GAAG,CAAC,6CAA6C,CAAC,CAAC;QAC7D,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,kDAAkD,KAAK,CAAC,OAAO,IAAI,eAAe,GAAG,CAAC,CAAC;YACrG,oCAAoC;QACtC,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,WAAW;QAChB,OAAO,IAAI,CAAC,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACI,SAAS;QACd,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ArcadeDB Adapter
|
|
3
|
+
*
|
|
4
|
+
* Provides database operations for long-term memory storage using ArcadeDB.
|
|
5
|
+
* Supports vertex/edge operations and Cypher queries with connection pooling.
|
|
6
|
+
*/
|
|
7
|
+
import type { Result } from '../common/result.js';
|
|
8
|
+
import type { DatabaseError } from '../common/types.js';
|
|
9
|
+
/**
|
|
10
|
+
* ArcadeDB Client Configuration
|
|
11
|
+
*/
|
|
12
|
+
export interface ArcadeDBClientConfig {
|
|
13
|
+
host: string;
|
|
14
|
+
port: number;
|
|
15
|
+
database: string;
|
|
16
|
+
username: string;
|
|
17
|
+
password: string;
|
|
18
|
+
timeout?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* ArcadeDB Client
|
|
22
|
+
*
|
|
23
|
+
* Low-level HTTP client for ArcadeDB REST API
|
|
24
|
+
* Handles connection, authentication, and query execution
|
|
25
|
+
*/
|
|
26
|
+
export declare class ArcadeDBClient {
|
|
27
|
+
private readonly config;
|
|
28
|
+
private connected;
|
|
29
|
+
private readonly baseUrl;
|
|
30
|
+
private readonly auth;
|
|
31
|
+
private readonly timeout;
|
|
32
|
+
/**
|
|
33
|
+
* Create ArcadeDB Client
|
|
34
|
+
*
|
|
35
|
+
* @param config - Client configuration
|
|
36
|
+
*/
|
|
37
|
+
constructor(config: ArcadeDBClientConfig);
|
|
38
|
+
/**
|
|
39
|
+
* Connect to ArcadeDB
|
|
40
|
+
*
|
|
41
|
+
* Verifies connectivity by executing a test query
|
|
42
|
+
*
|
|
43
|
+
* @returns Result indicating connection success or error
|
|
44
|
+
*/
|
|
45
|
+
connect(): Promise<Result<void, DatabaseError>>;
|
|
46
|
+
/**
|
|
47
|
+
* Disconnect from ArcadeDB
|
|
48
|
+
*
|
|
49
|
+
* Marks client as disconnected (no persistent connection to close)
|
|
50
|
+
*
|
|
51
|
+
* @returns Result indicating disconnect success
|
|
52
|
+
*/
|
|
53
|
+
disconnect(): Promise<Result<void, DatabaseError>>;
|
|
54
|
+
/**
|
|
55
|
+
* Check if client is connected
|
|
56
|
+
*
|
|
57
|
+
* @returns True if connected
|
|
58
|
+
*/
|
|
59
|
+
isConnected(): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Execute query
|
|
62
|
+
*
|
|
63
|
+
* Supports both SQL and Cypher languages
|
|
64
|
+
*
|
|
65
|
+
* @param command - Query command
|
|
66
|
+
* @param params - Optional query parameters
|
|
67
|
+
* @param language - Query language ('sql' or 'cypher'), defaults to 'sql'
|
|
68
|
+
* @returns Result with query results or error
|
|
69
|
+
*/
|
|
70
|
+
query(command: string, params?: Record<string, any>, language?: 'sql' | 'cypher'): Promise<Result<any[], DatabaseError>>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Vertex properties
|
|
74
|
+
*/
|
|
75
|
+
export interface VertexProperties {
|
|
76
|
+
[key: string]: any;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Edge properties
|
|
80
|
+
*/
|
|
81
|
+
export interface EdgeProperties {
|
|
82
|
+
[key: string]: any;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Vertex result with @rid
|
|
86
|
+
*/
|
|
87
|
+
export interface VertexResult {
|
|
88
|
+
'@rid': string;
|
|
89
|
+
[key: string]: any;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* ArcadeDB Adapter
|
|
93
|
+
*
|
|
94
|
+
* High-level adapter for graph database operations
|
|
95
|
+
* Provides vertex/edge operations using Cypher queries
|
|
96
|
+
*/
|
|
97
|
+
export declare class ArcadeDBAdapter {
|
|
98
|
+
private readonly dbUrl;
|
|
99
|
+
private readonly username;
|
|
100
|
+
private readonly password;
|
|
101
|
+
private readonly timeout;
|
|
102
|
+
private client;
|
|
103
|
+
/**
|
|
104
|
+
* Create ArcadeDB Adapter
|
|
105
|
+
*
|
|
106
|
+
* @param dbUrl - Database connection URL (format: http://host:port/database)
|
|
107
|
+
* @param username - Database username
|
|
108
|
+
* @param password - Database password
|
|
109
|
+
* @param timeout - Query timeout in milliseconds
|
|
110
|
+
*/
|
|
111
|
+
constructor(dbUrl: string, username?: string, password?: string, timeout?: number);
|
|
112
|
+
/**
|
|
113
|
+
* Parse database URL into config
|
|
114
|
+
*
|
|
115
|
+
* @returns Client configuration
|
|
116
|
+
*/
|
|
117
|
+
private parseDbUrl;
|
|
118
|
+
/**
|
|
119
|
+
* Connect to database
|
|
120
|
+
*
|
|
121
|
+
* Creates client instance and establishes connection
|
|
122
|
+
*
|
|
123
|
+
* @returns Result indicating success or error
|
|
124
|
+
*/
|
|
125
|
+
connect(): Promise<Result<void, DatabaseError>>;
|
|
126
|
+
/**
|
|
127
|
+
* Disconnect from database
|
|
128
|
+
*
|
|
129
|
+
* @returns Result indicating success or error
|
|
130
|
+
*/
|
|
131
|
+
disconnect(): Promise<Result<void, DatabaseError>>;
|
|
132
|
+
/**
|
|
133
|
+
* Execute Cypher query
|
|
134
|
+
*
|
|
135
|
+
* @param cypher - Cypher query command
|
|
136
|
+
* @param params - Optional query parameters
|
|
137
|
+
* @returns Result with query results or error
|
|
138
|
+
*/
|
|
139
|
+
query(cypher: string, params?: Record<string, any>): Promise<Result<any[], DatabaseError>>;
|
|
140
|
+
/**
|
|
141
|
+
* Create vertex
|
|
142
|
+
*
|
|
143
|
+
* @param type - Vertex type (label)
|
|
144
|
+
* @param properties - Vertex properties
|
|
145
|
+
* @returns Result with vertex @rid or error
|
|
146
|
+
*/
|
|
147
|
+
createVertex(type: string, properties: VertexProperties): Promise<Result<string, DatabaseError>>;
|
|
148
|
+
/**
|
|
149
|
+
* Create edge
|
|
150
|
+
*
|
|
151
|
+
* @param fromRid - Source vertex @rid
|
|
152
|
+
* @param toRid - Target vertex @rid
|
|
153
|
+
* @param type - Edge type (label)
|
|
154
|
+
* @param properties - Optional edge properties
|
|
155
|
+
* @returns Result with edge @rid or error
|
|
156
|
+
*/
|
|
157
|
+
createEdge(fromRid: string, toRid: string, type: string, properties?: EdgeProperties): Promise<Result<string, DatabaseError>>;
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=arcadedb-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arcadedb-adapter.d.ts","sourceRoot":"","sources":["../../src/memory/arcadedb-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAWxD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,qBAAa,cAAc;IAWb,OAAO,CAAC,QAAQ,CAAC,MAAM;IAVnC,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC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