agent-swarm-kit 0.0.1 → 1.0.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/package.json CHANGED
@@ -1,12 +1,80 @@
1
- {
2
- "name": "agent-swarm-kit",
3
- "version": "0.0.1",
4
- "main": "index.mjs",
5
- "scripts": {
6
- "test": "echo \"Error: no test specified\" && exit 1"
7
- },
8
- "keywords": [],
9
- "author": "",
10
- "license": "ISC",
11
- "description": ""
12
- }
1
+ {
2
+ "name": "agent-swarm-kit",
3
+ "version": "1.0.0",
4
+ "description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
5
+ "author": {
6
+ "name": "Petr Tripolsky",
7
+ "email": "tripolskypetr@gmail.com",
8
+ "url": "https://github.com/tripolskypetr"
9
+ },
10
+ "funding": {
11
+ "type": "individual",
12
+ "url": "http://paypal.me/tripolskypetr"
13
+ },
14
+ "license": "MIT",
15
+ "homepage": "https://react-declarative-playground.github.io",
16
+ "keywords": [
17
+ "NVIDIA NIM",
18
+ "OpenAI",
19
+ "GPT4All",
20
+ "Ollama",
21
+ "LM Studio",
22
+ "llama",
23
+ "gpt",
24
+ "mistral"
25
+ ],
26
+ "files": [
27
+ "build",
28
+ "types.d.ts",
29
+ "README.md"
30
+ ],
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/react-declarative/react-declarative",
34
+ "documentation": "https://github.com/react-declarative/react-declarative/tree/master/docs"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/react-declarative/react-declarative/issues"
38
+ },
39
+ "scripts": {
40
+ "build": "rollup -c",
41
+ "test": "npm run build && node ./test/index.mjs",
42
+ "build:docs": "rimraf docs && mkdir docs && node ./scripts/dts-docs.cjs ./types.d.ts ./docs",
43
+ "docs:gpt": "node ./scripts/gpt-docs.mjs",
44
+ "repl": "dotenv -e .env -- npm run build && node -e \"import('./scripts/repl.mjs')\" --interactive"
45
+ },
46
+ "main": "build/index.cjs",
47
+ "module": "build/index.mjs",
48
+ "source": "src/index.ts",
49
+ "types": "./types.d.ts",
50
+ "exports": {
51
+ "require": "./build/index.cjs",
52
+ "types": "./types.d.ts",
53
+ "import": "./build/index.mjs",
54
+ "default": "./build/index.cjs"
55
+ },
56
+ "devDependencies": {
57
+ "@rollup/plugin-typescript": "11.1.6",
58
+ "@types/lodash-es": "4.17.12",
59
+ "@types/node": "22.9.0",
60
+ "@types/xml2js": "0.4.14",
61
+ "rimraf": "6.0.1",
62
+ "rollup": "3.29.5",
63
+ "glob": "11.0.1",
64
+ "gpt4all": "4.0.0",
65
+ "rollup-plugin-dts": "6.1.1",
66
+ "rollup-plugin-peer-deps-external": "2.2.4",
67
+ "tslib": "2.7.0",
68
+ "worker-testbed": "1.0.10"
69
+ },
70
+ "peerDependencies": {
71
+ "typescript": "^5.0.0"
72
+ },
73
+ "dependencies": {
74
+ "di-kit": "^1.0.12",
75
+ "di-scoped": "^1.0.11",
76
+ "functools-kit": "^1.0.72",
77
+ "lodash-es": "4.17.21",
78
+ "xml2js": "0.6.2"
79
+ }
80
+ }
package/types.d.ts ADDED
@@ -0,0 +1,470 @@
1
+ import * as di_scoped from 'di-scoped';
2
+ import * as functools_kit from 'functools-kit';
3
+ import { IPubsubArray, Subject } from 'functools-kit';
4
+
5
+ interface IModelMessage {
6
+ role: 'assistant' | 'system' | 'tool' | 'user' | 'resque';
7
+ agentName: string;
8
+ content: string;
9
+ tool_calls?: {
10
+ function: {
11
+ name: string;
12
+ arguments: {
13
+ [key: string]: any;
14
+ };
15
+ };
16
+ }[];
17
+ }
18
+
19
+ interface ILogger {
20
+ log(...args: any[]): void;
21
+ debug(...args: any[]): void;
22
+ }
23
+
24
+ interface IHistory {
25
+ push(message: IModelMessage): Promise<void>;
26
+ toArrayForAgent(prompt: string): Promise<IModelMessage[]>;
27
+ toArrayForRaw(): Promise<IModelMessage[]>;
28
+ }
29
+ interface IHistoryParams extends IHistorySchema {
30
+ agentName: AgentName;
31
+ clientId: string;
32
+ logger: ILogger;
33
+ }
34
+ interface IHistorySchema {
35
+ items: IPubsubArray<IModelMessage>;
36
+ }
37
+
38
+ interface ITool {
39
+ type: string;
40
+ function: {
41
+ name: string;
42
+ description: string;
43
+ parameters: {
44
+ type: string;
45
+ required: string[];
46
+ properties: {
47
+ [key: string]: {
48
+ type: string;
49
+ description: string;
50
+ enum?: string[];
51
+ };
52
+ };
53
+ };
54
+ };
55
+ }
56
+
57
+ interface ICompletion extends ICompletionSchema {
58
+ }
59
+ interface ICompletionArgs {
60
+ clientId: string;
61
+ agentName: AgentName;
62
+ messages: IModelMessage[];
63
+ tools?: ITool[];
64
+ }
65
+ interface ICompletionSchema {
66
+ completionName: CompletionName;
67
+ getCompletion(args: ICompletionArgs): Promise<IModelMessage>;
68
+ }
69
+ type CompletionName = string;
70
+
71
+ interface IAgentTool<T = Record<string, unknown>> extends ITool {
72
+ toolName: ToolName;
73
+ call(clientId: string, agentName: AgentName, params: T): Promise<void>;
74
+ validate(clientId: string, agentName: AgentName, params: T): Promise<boolean> | boolean;
75
+ }
76
+ interface IAgentParams extends Omit<IAgentSchema, keyof {
77
+ tools: never;
78
+ completion: never;
79
+ validate: never;
80
+ }> {
81
+ clientId: string;
82
+ logger: ILogger;
83
+ history: IHistory;
84
+ completion: ICompletion;
85
+ tools?: IAgentTool[];
86
+ validate: (output: string) => Promise<string | null>;
87
+ }
88
+ interface IAgentSchema {
89
+ agentName: AgentName;
90
+ completion: CompletionName;
91
+ prompt: string;
92
+ tools?: ToolName[];
93
+ validate?: (output: string) => Promise<string | null>;
94
+ }
95
+ interface IAgent {
96
+ execute: (input: string) => Promise<void>;
97
+ waitForOutput: () => Promise<string>;
98
+ commitToolOutput(content: string): Promise<void>;
99
+ commitSystemMessage(message: string): Promise<void>;
100
+ }
101
+ type AgentName = string;
102
+ type ToolName = string;
103
+
104
+ interface ISwarmParams extends Omit<ISwarmSchema, keyof {
105
+ agentList: never;
106
+ }> {
107
+ clientId: string;
108
+ logger: ILogger;
109
+ agentMap: Record<AgentName, IAgent>;
110
+ }
111
+ interface ISwarmSchema {
112
+ defaultAgent: AgentName;
113
+ swarmName: string;
114
+ agentList: string[];
115
+ }
116
+ interface ISwarm {
117
+ waitForOutput(): Promise<string>;
118
+ getAgentName(): Promise<AgentName>;
119
+ getAgent(): Promise<IAgent>;
120
+ setAgentName(agentName: AgentName): Promise<void>;
121
+ }
122
+ type SwarmName = string;
123
+
124
+ interface IContext {
125
+ clientId: string;
126
+ agentName: AgentName;
127
+ swarmName: SwarmName;
128
+ }
129
+ declare const ContextService: (new () => {
130
+ readonly context: IContext;
131
+ }) & Omit<{
132
+ new (context: IContext): {
133
+ readonly context: IContext;
134
+ };
135
+ }, "prototype"> & di_scoped.IScopedClassRun<[context: IContext]>;
136
+
137
+ declare class LoggerService implements ILogger {
138
+ private _logger;
139
+ log: (...args: any[]) => void;
140
+ debug: (...args: any[]) => void;
141
+ setLogger: (logger: ILogger) => void;
142
+ }
143
+
144
+ declare class ClientAgent implements IAgent {
145
+ readonly params: IAgentParams;
146
+ readonly _toolCommitSubject: Subject<void>;
147
+ readonly _outputSubject: Subject<string>;
148
+ constructor(params: IAgentParams);
149
+ _emitOuput: (result: string) => Promise<void>;
150
+ _resurrectModel: (reason?: string) => Promise<string>;
151
+ waitForOutput: () => Promise<string>;
152
+ getCompletion: () => Promise<IModelMessage>;
153
+ commitSystemMessage: (message: string) => Promise<void>;
154
+ commitToolOutput: (content: string) => Promise<void>;
155
+ execute: IAgent["execute"];
156
+ }
157
+
158
+ declare class AgentConnectionService implements IAgent {
159
+ private readonly loggerService;
160
+ private readonly contextService;
161
+ private readonly historyConnectionService;
162
+ private readonly agentSchemaService;
163
+ private readonly toolSchemaService;
164
+ private readonly completionSchemaService;
165
+ getAgent: ((clientId: string, agentName: string) => ClientAgent) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientAgent>;
166
+ execute: (input: string) => Promise<void>;
167
+ waitForOutput: () => Promise<string>;
168
+ commitToolOutput: (content: string) => Promise<void>;
169
+ commitSystemMessage: (message: string) => Promise<void>;
170
+ dispose: () => Promise<void>;
171
+ }
172
+
173
+ declare class ClientHistory implements IHistory {
174
+ readonly params: IHistoryParams;
175
+ constructor(params: IHistoryParams);
176
+ push: (message: IModelMessage) => Promise<void>;
177
+ toArrayForRaw: () => Promise<IModelMessage[]>;
178
+ toArrayForAgent: (prompt: string) => Promise<IModelMessage[]>;
179
+ }
180
+
181
+ declare class HistoryConnectionService implements IHistory {
182
+ private readonly loggerService;
183
+ private readonly contextService;
184
+ getItems: ((clientId: string) => IPubsubArray<IModelMessage>) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, IPubsubArray<IModelMessage>>;
185
+ getHistory: ((clientId: string, agentName: string) => ClientHistory) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientHistory>;
186
+ push: (message: IModelMessage) => Promise<void>;
187
+ toArrayForAgent: (prompt: string) => Promise<IModelMessage[]>;
188
+ toArrayForRaw: () => Promise<IModelMessage[]>;
189
+ dispose: () => Promise<void>;
190
+ }
191
+
192
+ declare class AgentSchemaService {
193
+ readonly loggerService: LoggerService;
194
+ private registry;
195
+ register: (key: AgentName, value: IAgentSchema) => void;
196
+ get: (key: AgentName) => IAgentSchema;
197
+ }
198
+
199
+ declare class ToolSchemaService {
200
+ private readonly loggerService;
201
+ private registry;
202
+ register: (key: ToolName, value: IAgentTool) => void;
203
+ get: (key: ToolName) => IAgentTool;
204
+ }
205
+
206
+ declare class ClientSwarm implements ISwarm {
207
+ readonly params: ISwarmParams;
208
+ private _activeAgent;
209
+ constructor(params: ISwarmParams);
210
+ waitForOutput: () => Promise<string>;
211
+ getAgentName: () => Promise<AgentName>;
212
+ getAgent: () => Promise<IAgent>;
213
+ setAgentName: (agentName: AgentName) => Promise<void>;
214
+ }
215
+
216
+ declare class SwarmConnectionService implements ISwarm {
217
+ private readonly loggerService;
218
+ private readonly contextService;
219
+ private readonly agentConnectionService;
220
+ private readonly swarmSchemaService;
221
+ getSwarm: ((clientId: string, swarmName: string) => ClientSwarm) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientSwarm>;
222
+ waitForOutput: () => Promise<string>;
223
+ getAgentName: () => Promise<string>;
224
+ getAgent: () => Promise<IAgent>;
225
+ setAgentName: (agentName: AgentName) => Promise<void>;
226
+ dispose: () => Promise<void>;
227
+ }
228
+
229
+ declare class SwarmSchemaService {
230
+ readonly loggerService: LoggerService;
231
+ private registry;
232
+ register: (key: SwarmName, value: ISwarmSchema) => void;
233
+ get: (key: SwarmName) => ISwarmSchema;
234
+ }
235
+
236
+ declare class CompletionSchemaService {
237
+ readonly loggerService: LoggerService;
238
+ private registry;
239
+ register: (key: string, value: ICompletionSchema) => void;
240
+ get: (key: string) => ICompletionSchema;
241
+ }
242
+
243
+ interface IIncomingMessage {
244
+ clientId: string;
245
+ data: string;
246
+ agentName: AgentName;
247
+ }
248
+ interface IOutgoingMessage {
249
+ clientId: string;
250
+ data: string;
251
+ agentName: AgentName;
252
+ }
253
+
254
+ interface ISessionParams extends ISessionSchema {
255
+ clientId: string;
256
+ logger: ILogger;
257
+ swarm: ISwarm;
258
+ }
259
+ interface ISessionSchema {
260
+ }
261
+ type SendMessageFn = (outgoing: IOutgoingMessage) => Promise<void> | void;
262
+ type ReceiveMessageFn = (incoming: IIncomingMessage) => Promise<void> | void;
263
+ interface ISession {
264
+ execute(content: string): Promise<string>;
265
+ connect(connector: SendMessageFn): ReceiveMessageFn;
266
+ commitToolOutput(content: string): Promise<void>;
267
+ commitSystemMessage(message: string): Promise<void>;
268
+ }
269
+ type SessionId = string;
270
+
271
+ declare class ClientSession implements ISession {
272
+ readonly params: ISessionParams;
273
+ constructor(params: ISessionParams);
274
+ execute: (message: string) => Promise<string>;
275
+ commitToolOutput: (content: string) => Promise<void>;
276
+ commitSystemMessage: (message: string) => Promise<void>;
277
+ connect: (connector: SendMessageFn) => ReceiveMessageFn;
278
+ }
279
+
280
+ declare class SessionConnectionService implements ISession {
281
+ private readonly loggerService;
282
+ private readonly contextService;
283
+ private readonly swarmConnectionService;
284
+ getSession: ((clientId: string, swarmName: string) => ClientSession) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, ClientSession>;
285
+ execute: (content: string) => Promise<string>;
286
+ connect: (connector: SendMessageFn) => ReceiveMessageFn;
287
+ commitToolOutput: (content: string) => Promise<void>;
288
+ commitSystemMessage: (message: string) => Promise<void>;
289
+ dispose: () => Promise<void>;
290
+ }
291
+
292
+ interface IAgentConnectionService extends AgentConnectionService {
293
+ }
294
+ type InternalKeys$3 = keyof {
295
+ getAgent: never;
296
+ };
297
+ type TAgentConnectionService = {
298
+ [key in Exclude<keyof IAgentConnectionService, InternalKeys$3>]: unknown;
299
+ };
300
+ declare class AgentPublicService implements TAgentConnectionService {
301
+ private readonly loggerService;
302
+ private readonly agentConnectionService;
303
+ execute: (input: string, clientId: string, agentName: AgentName) => Promise<void>;
304
+ waitForOutput: (clientId: string, agentName: AgentName) => Promise<string>;
305
+ commitToolOutput: (content: string, clientId: string, agentName: AgentName) => Promise<void>;
306
+ commitSystemMessage: (message: string, clientId: string, agentName: AgentName) => Promise<void>;
307
+ dispose: (clientId: string, agentName: AgentName) => Promise<void>;
308
+ }
309
+
310
+ interface IHistoryConnectionService extends HistoryConnectionService {
311
+ }
312
+ type InternalKeys$2 = keyof {
313
+ getHistory: never;
314
+ getItems: never;
315
+ };
316
+ type THistoryConnectionService = {
317
+ [key in Exclude<keyof IHistoryConnectionService, InternalKeys$2>]: unknown;
318
+ };
319
+ declare class HistoryPublicService implements THistoryConnectionService {
320
+ private readonly loggerService;
321
+ private readonly historyConnectionService;
322
+ push: (message: IModelMessage, clientId: string, agentName: AgentName) => Promise<void>;
323
+ toArrayForAgent: (prompt: string, clientId: string, agentName: AgentName) => Promise<IModelMessage[]>;
324
+ toArrayForRaw: (clientId: string, agentName: AgentName) => Promise<IModelMessage[]>;
325
+ dispose: (clientId: string, agentName: AgentName) => Promise<void>;
326
+ }
327
+
328
+ interface ISessionConnectionService extends SessionConnectionService {
329
+ }
330
+ type InternalKeys$1 = keyof {
331
+ getSession: never;
332
+ };
333
+ type TSessionConnectionService = {
334
+ [key in Exclude<keyof ISessionConnectionService, InternalKeys$1>]: unknown;
335
+ };
336
+ declare class SessionPublicService implements TSessionConnectionService {
337
+ private readonly loggerService;
338
+ private readonly sessionConnectionService;
339
+ execute: (content: string, clientId: string, swarmName: SwarmName) => Promise<string>;
340
+ connect: (connector: SendMessageFn, clientId: string, swarmName: SwarmName) => ReceiveMessageFn;
341
+ commitToolOutput: (content: string, clientId: string, swarmName: SwarmName) => Promise<void>;
342
+ commitSystemMessage: (message: string, clientId: string, swarmName: SwarmName) => Promise<void>;
343
+ dispose: (clientId: string, swarmName: SwarmName) => Promise<void>;
344
+ }
345
+
346
+ interface ISwarmConnectionService extends SwarmConnectionService {
347
+ }
348
+ type InternalKeys = keyof {
349
+ getSwarm: never;
350
+ };
351
+ type TSwarmConnectionService = {
352
+ [key in Exclude<keyof ISwarmConnectionService, InternalKeys>]: unknown;
353
+ };
354
+ declare class SwarmPublicService implements TSwarmConnectionService {
355
+ private readonly loggerService;
356
+ private readonly swarmConnectionService;
357
+ waitForOutput: (clientId: string, swarmName: SwarmName) => Promise<string>;
358
+ getAgentName: (clientId: string, swarmName: SwarmName) => Promise<string>;
359
+ getAgent: (clientId: string, swarmName: SwarmName) => Promise<IAgent>;
360
+ setAgentName: (agentName: AgentName, clientId: string, swarmName: SwarmName) => Promise<void>;
361
+ dispose: (clientId: string, swarmName: SwarmName) => Promise<void>;
362
+ }
363
+
364
+ declare class AgentValidationService {
365
+ private readonly loggerService;
366
+ private readonly toolValidationService;
367
+ private readonly completionValidationService;
368
+ private _agentMap;
369
+ addAgent: (agentName: AgentName, agentSchema: IAgentSchema) => void;
370
+ validate: (agentName: AgentName, source: string) => void;
371
+ }
372
+
373
+ declare class ToolValidationService {
374
+ private readonly loggerService;
375
+ private _toolMap;
376
+ addTool: (toolName: ToolName, toolSchema: IAgentTool) => void;
377
+ validate: (toolName: ToolName, source: string) => void;
378
+ }
379
+
380
+ declare class SessionValidationService {
381
+ private readonly loggerService;
382
+ private _sessionMap;
383
+ addSession: (clientId: SessionId, swarmName: SwarmName) => void;
384
+ getSessionList: () => string[];
385
+ getSwarm: (clientId: SessionId) => string;
386
+ validate: (clientId: SessionId, source: string) => void;
387
+ removeSession: (clientId: SessionId) => void;
388
+ }
389
+
390
+ declare class SwarmValidationService {
391
+ private readonly loggerService;
392
+ private readonly agentValidationService;
393
+ private _swarmMap;
394
+ addSwarm: (swarmName: SwarmName, swarmSchema: ISwarmSchema) => void;
395
+ getAgentList: (swarmName: SwarmName) => string[];
396
+ validate: (swarmName: SwarmName, source: string) => void;
397
+ }
398
+
399
+ declare class CompletionValidationService {
400
+ private readonly loggerService;
401
+ private _completionSet;
402
+ addCompletion: (completionName: CompletionName) => void;
403
+ validate: (completionName: CompletionName, source: string) => void;
404
+ }
405
+
406
+ declare const swarm: {
407
+ agentValidationService: AgentValidationService;
408
+ toolValidationService: ToolValidationService;
409
+ sessionValidationService: SessionValidationService;
410
+ swarmValidationService: SwarmValidationService;
411
+ completionValidationService: CompletionValidationService;
412
+ agentPublicService: AgentPublicService;
413
+ historyPublicService: HistoryPublicService;
414
+ sessionPublicService: SessionPublicService;
415
+ swarmPublicService: SwarmPublicService;
416
+ agentSchemaService: AgentSchemaService;
417
+ toolSchemaService: ToolSchemaService;
418
+ swarmSchemaService: SwarmSchemaService;
419
+ completionSchemaService: CompletionSchemaService;
420
+ agentConnectionService: AgentConnectionService;
421
+ historyConnectionService: HistoryConnectionService;
422
+ swarmConnectionService: SwarmConnectionService;
423
+ sessionConnectionService: SessionConnectionService;
424
+ loggerService: LoggerService;
425
+ contextService: {
426
+ readonly context: IContext;
427
+ };
428
+ };
429
+
430
+ declare const addAgent: (agentSchema: IAgentSchema) => string;
431
+
432
+ declare const addCompletion: (completionSchema: ICompletionSchema) => string;
433
+
434
+ declare const addSwarm: (swarmSchema: ISwarmSchema) => string;
435
+
436
+ declare const addTool: (toolSchema: IAgentTool) => string;
437
+
438
+ declare const makeConnection: (connector: ReceiveMessageFn, clientId: string, swarmName: SwarmName) => SendMessageFn;
439
+
440
+ declare const changeAgent: (agentName: AgentName, clientId: string) => Promise<void>;
441
+
442
+ declare const complete: (content: string, clientId: string, swarmName: SwarmName) => Promise<string>;
443
+
444
+ type TComplete = (content: string) => Promise<string>;
445
+ declare const session: (clientId: string, swarmName: SwarmName) => {
446
+ complete: TComplete;
447
+ dispose: () => Promise<void>;
448
+ };
449
+
450
+ declare const disposeConnection: (clientId: string, swarmName: SwarmName) => Promise<void>;
451
+
452
+ declare const getRawHistory: (clientId: string) => Promise<IModelMessage[]>;
453
+
454
+ declare const getAgentHistory: (clientId: string, agentName: AgentName) => Promise<IModelMessage[]>;
455
+
456
+ declare const commitToolOutput: (content: string, clientId: string) => void;
457
+
458
+ declare const commitSystemMessage: (content: string, clientId: string) => void;
459
+
460
+ declare const execute: (content: string, clientId: string) => Promise<string>;
461
+
462
+ declare const GLOBAL_CONFIG: {
463
+ CC_TOOL_CALL_EXCEPTION_PROMPT: string;
464
+ CC_EMPTY_OUTPUT_PLACEHOLDERS: string[];
465
+ CC_KEEP_MESSAGES: number;
466
+ CC_ANSWER_TIMEOUT_SECONDS: number;
467
+ };
468
+ declare const setConfig: (config: typeof GLOBAL_CONFIG) => void;
469
+
470
+ export { ContextService, type IAgentSchema, type IAgentTool, type ICompletionSchema, type ISwarmSchema, type ReceiveMessageFn, type SendMessageFn, addAgent, addCompletion, addSwarm, addTool, changeAgent, commitSystemMessage, commitToolOutput, complete, disposeConnection, execute, getAgentHistory, getRawHistory, makeConnection, session, setConfig, swarm };
package/index.mjs DELETED
@@ -1 +0,0 @@
1
- console.log("todo")