@kadi.build/core 0.0.1-alpha.2 → 0.0.1-alpha.4
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 +1122 -216
- package/dist/KadiClient.d.ts +303 -0
- package/dist/KadiClient.d.ts.map +1 -0
- package/dist/KadiClient.js +1162 -0
- package/dist/KadiClient.js.map +1 -0
- package/dist/errors/error-codes.d.ts +215 -0
- package/dist/errors/error-codes.d.ts.map +1 -0
- package/dist/errors/error-codes.js +295 -0
- package/dist/errors/error-codes.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/loadAbility.d.ts +65 -0
- package/dist/loadAbility.d.ts.map +1 -0
- package/dist/loadAbility.js +335 -0
- package/dist/loadAbility.js.map +1 -0
- package/dist/messages/BrokerMessages.d.ts +84 -0
- package/dist/messages/BrokerMessages.d.ts.map +1 -0
- package/dist/messages/BrokerMessages.js +127 -0
- package/dist/messages/BrokerMessages.js.map +1 -0
- package/dist/messages/MessageBuilder.d.ts +83 -0
- package/dist/messages/MessageBuilder.d.ts.map +1 -0
- package/dist/messages/MessageBuilder.js +144 -0
- package/dist/messages/MessageBuilder.js.map +1 -0
- package/dist/schemas/events.schemas.d.ts +177 -0
- package/dist/schemas/events.schemas.d.ts.map +1 -0
- package/dist/schemas/events.schemas.js +265 -0
- package/dist/schemas/events.schemas.js.map +1 -0
- package/dist/schemas/index.d.ts +3 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +4 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/kadi.schemas.d.ts +70 -0
- package/dist/schemas/kadi.schemas.d.ts.map +1 -0
- package/dist/schemas/kadi.schemas.js +120 -0
- package/dist/schemas/kadi.schemas.js.map +1 -0
- package/dist/transports/BrokerTransport.d.ts +96 -0
- package/dist/transports/BrokerTransport.d.ts.map +1 -0
- package/dist/transports/BrokerTransport.js +145 -0
- package/dist/transports/BrokerTransport.js.map +1 -0
- package/dist/transports/NativeTransport.d.ts +92 -0
- package/dist/transports/NativeTransport.d.ts.map +1 -0
- package/dist/transports/NativeTransport.js +221 -0
- package/dist/transports/NativeTransport.js.map +1 -0
- package/dist/transports/StdioTransport.d.ts +112 -0
- package/dist/transports/StdioTransport.d.ts.map +1 -0
- package/dist/transports/StdioTransport.js +440 -0
- package/dist/transports/StdioTransport.js.map +1 -0
- package/dist/transports/Transport.d.ts +93 -0
- package/dist/transports/Transport.d.ts.map +1 -0
- package/dist/transports/Transport.js +13 -0
- package/dist/transports/Transport.js.map +1 -0
- package/dist/types/broker.d.ts +31 -0
- package/dist/types/broker.d.ts.map +1 -0
- package/dist/types/broker.js +6 -0
- package/dist/types/broker.js.map +1 -0
- package/dist/types/core.d.ts +138 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +26 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/events.d.ts +186 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +16 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +13 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/protocol.d.ts +160 -0
- package/dist/types/protocol.d.ts.map +1 -0
- package/dist/types/protocol.js +5 -0
- package/dist/types/protocol.js.map +1 -0
- package/dist/utils/agentUtils.d.ts +102 -0
- package/dist/utils/agentUtils.d.ts.map +1 -0
- package/dist/utils/agentUtils.js +166 -0
- package/dist/utils/agentUtils.js.map +1 -0
- package/dist/utils/commandUtils.d.ts +45 -0
- package/dist/utils/commandUtils.d.ts.map +1 -0
- package/dist/utils/commandUtils.js +145 -0
- package/dist/utils/commandUtils.js.map +1 -0
- package/dist/utils/configUtils.d.ts +55 -0
- package/dist/utils/configUtils.d.ts.map +1 -0
- package/dist/utils/configUtils.js +100 -0
- package/dist/utils/configUtils.js.map +1 -0
- package/dist/utils/logger.d.ts +59 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +122 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/pathUtils.d.ts +48 -0
- package/dist/utils/pathUtils.d.ts.map +1 -0
- package/dist/utils/pathUtils.js +128 -0
- package/dist/utils/pathUtils.js.map +1 -0
- package/package.json +58 -5
- package/agent.json +0 -18
- package/broker.js +0 -214
- package/index.js +0 -382
- package/ipc.js +0 -220
- package/ipcInterfaces/pythonAbilityIPC.py +0 -177
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript implementation of JSON-RPC message builders
|
|
3
|
+
* Replaces the JavaScript message builder functionality
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Simple ID factory for generating unique message IDs
|
|
7
|
+
*/
|
|
8
|
+
export declare class IdFactory {
|
|
9
|
+
private counter;
|
|
10
|
+
next(): string;
|
|
11
|
+
uuid(): string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* JSON-RPC message builder
|
|
15
|
+
*/
|
|
16
|
+
export declare class JsonRpcBuilder {
|
|
17
|
+
private message;
|
|
18
|
+
constructor(method: string, params?: any, isNotification?: boolean);
|
|
19
|
+
/**
|
|
20
|
+
* Set the request ID
|
|
21
|
+
*/
|
|
22
|
+
id(id: string | number): this;
|
|
23
|
+
/**
|
|
24
|
+
* Add additional parameters
|
|
25
|
+
*/
|
|
26
|
+
params(additionalParams: any): this;
|
|
27
|
+
/**
|
|
28
|
+
* Build the final message
|
|
29
|
+
*/
|
|
30
|
+
build(): any;
|
|
31
|
+
/**
|
|
32
|
+
* Build and stringify
|
|
33
|
+
*/
|
|
34
|
+
toString(): string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* JSON-RPC response builder
|
|
38
|
+
*/
|
|
39
|
+
export declare class JsonRpcResponse {
|
|
40
|
+
private response;
|
|
41
|
+
constructor(id: string | number | null);
|
|
42
|
+
/**
|
|
43
|
+
* Set successful result
|
|
44
|
+
*/
|
|
45
|
+
result(data: any): this;
|
|
46
|
+
/**
|
|
47
|
+
* Set error
|
|
48
|
+
*/
|
|
49
|
+
error(code: number, message: string, data?: any): this;
|
|
50
|
+
/**
|
|
51
|
+
* Build the final response
|
|
52
|
+
*/
|
|
53
|
+
build(): any;
|
|
54
|
+
/**
|
|
55
|
+
* Build and stringify
|
|
56
|
+
*/
|
|
57
|
+
toString(): string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Common JSON-RPC error codes
|
|
61
|
+
*/
|
|
62
|
+
export declare const RpcErrorCodes: {
|
|
63
|
+
readonly PARSE_ERROR: -32700;
|
|
64
|
+
readonly INVALID_REQUEST: -32600;
|
|
65
|
+
readonly METHOD_NOT_FOUND: -32601;
|
|
66
|
+
readonly INVALID_PARAMS: -32602;
|
|
67
|
+
readonly INTERNAL_ERROR: -32603;
|
|
68
|
+
readonly SERVER_ERROR_START: -32099;
|
|
69
|
+
readonly SERVER_ERROR_END: -32000;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Helper function to create success response
|
|
73
|
+
*/
|
|
74
|
+
export declare function createSuccessResponse(id: string | number | null, result: any): any;
|
|
75
|
+
/**
|
|
76
|
+
* Helper function to create error response
|
|
77
|
+
*/
|
|
78
|
+
export declare function createErrorResponse(id: string | number | null, code: number, message: string, data?: any): any;
|
|
79
|
+
/**
|
|
80
|
+
* Helper function to create notification
|
|
81
|
+
*/
|
|
82
|
+
export declare function createNotification(method: string, params?: any): any;
|
|
83
|
+
//# sourceMappingURL=MessageBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageBuilder.d.ts","sourceRoot":"","sources":["../../src/messages/MessageBuilder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAAK;IAEpB,IAAI,IAAI,M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 -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript implementation of JSON-RPC message builders
|
|
3
|
+
* Replaces the JavaScript message builder functionality
|
|
4
|
+
*/
|
|
5
|
+
import { randomUUID } from 'node:crypto';
|
|
6
|
+
/**
|
|
7
|
+
* Simple ID factory for generating unique message IDs
|
|
8
|
+
*/
|
|
9
|
+
export class IdFactory {
|
|
10
|
+
counter = 0;
|
|
11
|
+
next() {
|
|
12
|
+
return `${Date.now()}-${++this.counter}`;
|
|
13
|
+
}
|
|
14
|
+
uuid() {
|
|
15
|
+
return randomUUID();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* JSON-RPC message builder
|
|
20
|
+
*/
|
|
21
|
+
export class JsonRpcBuilder {
|
|
22
|
+
message;
|
|
23
|
+
constructor(method, params, isNotification = false) {
|
|
24
|
+
this.message = {
|
|
25
|
+
jsonrpc: '2.0',
|
|
26
|
+
method
|
|
27
|
+
};
|
|
28
|
+
if (params !== undefined) {
|
|
29
|
+
this.message.params = params;
|
|
30
|
+
}
|
|
31
|
+
if (!isNotification) {
|
|
32
|
+
// Will be set later with id() method
|
|
33
|
+
this.message.id = null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Set the request ID
|
|
38
|
+
*/
|
|
39
|
+
id(id) {
|
|
40
|
+
this.message.id = id;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Add additional parameters
|
|
45
|
+
*/
|
|
46
|
+
params(additionalParams) {
|
|
47
|
+
if (this.message.params) {
|
|
48
|
+
this.message.params = { ...this.message.params, ...additionalParams };
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this.message.params = additionalParams;
|
|
52
|
+
}
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Build the final message
|
|
57
|
+
*/
|
|
58
|
+
build() {
|
|
59
|
+
return { ...this.message };
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Build and stringify
|
|
63
|
+
*/
|
|
64
|
+
toString() {
|
|
65
|
+
return JSON.stringify(this.build());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* JSON-RPC response builder
|
|
70
|
+
*/
|
|
71
|
+
export class JsonRpcResponse {
|
|
72
|
+
response;
|
|
73
|
+
constructor(id) {
|
|
74
|
+
this.response = {
|
|
75
|
+
jsonrpc: '2.0',
|
|
76
|
+
id
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Set successful result
|
|
81
|
+
*/
|
|
82
|
+
result(data) {
|
|
83
|
+
this.response.result = data;
|
|
84
|
+
delete this.response.error;
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Set error
|
|
89
|
+
*/
|
|
90
|
+
error(code, message, data) {
|
|
91
|
+
this.response.error = {
|
|
92
|
+
code,
|
|
93
|
+
message
|
|
94
|
+
};
|
|
95
|
+
if (data !== undefined) {
|
|
96
|
+
this.response.error.data = data;
|
|
97
|
+
}
|
|
98
|
+
delete this.response.result;
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Build the final response
|
|
103
|
+
*/
|
|
104
|
+
build() {
|
|
105
|
+
return { ...this.response };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Build and stringify
|
|
109
|
+
*/
|
|
110
|
+
toString() {
|
|
111
|
+
return JSON.stringify(this.build());
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Common JSON-RPC error codes
|
|
116
|
+
*/
|
|
117
|
+
export const RpcErrorCodes = {
|
|
118
|
+
PARSE_ERROR: -32700,
|
|
119
|
+
INVALID_REQUEST: -32600,
|
|
120
|
+
METHOD_NOT_FOUND: -32601,
|
|
121
|
+
INVALID_PARAMS: -32602,
|
|
122
|
+
INTERNAL_ERROR: -32603,
|
|
123
|
+
SERVER_ERROR_START: -32099,
|
|
124
|
+
SERVER_ERROR_END: -32000
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Helper function to create success response
|
|
128
|
+
*/
|
|
129
|
+
export function createSuccessResponse(id, result) {
|
|
130
|
+
return new JsonRpcResponse(id).result(result).build();
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Helper function to create error response
|
|
134
|
+
*/
|
|
135
|
+
export function createErrorResponse(id, code, message, data) {
|
|
136
|
+
return new JsonRpcResponse(id).error(code, message, data).build();
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Helper function to create notification
|
|
140
|
+
*/
|
|
141
|
+
export function createNotification(method, params) {
|
|
142
|
+
return new JsonRpcBuilder(method, params, true).build();
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=MessageBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageBuilder.js","sourceRoot":"","sources":["../../src/messages/MessageBuilder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,SAAS;IACZ,OAAO,GAAG,CAAC,CAAC;IAEpB,IAAI;QACF,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;IAC3C,CAAC;IAED,IAAI;QACF,OAAO,UAAU,EAAE,CAAC;IACtB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,cAAc;IACjB,OAAO,CAAM;IAErB,YAAY,MAAc,EAAE,MAAY,EAAE,cAAc,GAAG,KAAK;QAC9D,IAAI,CAAC,OAAO,GAAG;YACb,OAAO,EAAE,KAAK;YACd,MAAM;SACP,CAAC;QAEF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,IAAI,CAAC,OAAO,CAAC,MAAM,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C,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event System Schema Validation
|
|
3
|
+
* ------------------------------
|
|
4
|
+
* Zod schemas for validating event system parameters and messages.
|
|
5
|
+
* This ensures type safety and proper input validation for all event operations.
|
|
6
|
+
*
|
|
7
|
+
* The schemas follow the established patterns in the KADI broker for consistency
|
|
8
|
+
* and integrate with the existing validation middleware.
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
/**
|
|
12
|
+
* Event channel pattern validation schema.
|
|
13
|
+
*
|
|
14
|
+
* Enforces the hierarchical naming convention:
|
|
15
|
+
* - Format: namespace.event-name or namespace.category.event-name
|
|
16
|
+
* - Examples: 'system.startup', 'tool.completed', 'agent.status.changed'
|
|
17
|
+
* - Wildcards: '*' matches one segment, '#' matches multiple segments
|
|
18
|
+
*
|
|
19
|
+
* Rules:
|
|
20
|
+
* - Must start with lowercase letter
|
|
21
|
+
* - Segments separated by dots
|
|
22
|
+
* - Only lowercase letters, numbers, underscores, hyphens allowed
|
|
23
|
+
* - Wildcards * and # only allowed at end of segments
|
|
24
|
+
*/
|
|
25
|
+
export declare const EventChannelSchema: z.ZodString;
|
|
26
|
+
/**
|
|
27
|
+
* Schema for event subscription requests (kadi.event.subscribe)
|
|
28
|
+
*/
|
|
29
|
+
export declare const EventSubscribeSchema: z.ZodObject<{
|
|
30
|
+
channels: z.ZodArray<z.ZodString>;
|
|
31
|
+
networkId: z.ZodOptional<z.ZodString>;
|
|
32
|
+
filter: z.ZodOptional<z.ZodObject<{
|
|
33
|
+
publisherId: z.ZodOptional<z.ZodString>;
|
|
34
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
35
|
+
}, z.core.$strip>>;
|
|
36
|
+
}, z.core.$strict>;
|
|
37
|
+
export type EventSubscribeParams = z.infer<typeof EventSubscribeSchema>;
|
|
38
|
+
/**
|
|
39
|
+
* Schema for event subscription response
|
|
40
|
+
*/
|
|
41
|
+
export declare const EventSubscribeResultSchema: z.ZodObject<{
|
|
42
|
+
subscribed: z.ZodArray<z.ZodString>;
|
|
43
|
+
queueName: z.ZodString;
|
|
44
|
+
}, z.core.$strict>;
|
|
45
|
+
export type EventSubscribeResult = z.infer<typeof EventSubscribeResultSchema>;
|
|
46
|
+
/**
|
|
47
|
+
* Schema for event unsubscription requests (kadi.event.unsubscribe)
|
|
48
|
+
*/
|
|
49
|
+
export declare const EventUnsubscribeSchema: z.ZodObject<{
|
|
50
|
+
channels: z.ZodArray<z.ZodString>;
|
|
51
|
+
networkId: z.ZodOptional<z.ZodString>;
|
|
52
|
+
}, z.core.$strict>;
|
|
53
|
+
export type EventUnsubscribeParams = z.infer<typeof EventUnsubscribeSchema>;
|
|
54
|
+
/**
|
|
55
|
+
* Schema for event unsubscription response
|
|
56
|
+
*/
|
|
57
|
+
export declare const EventUnsubscribeResultSchema: z.ZodObject<{
|
|
58
|
+
unsubscribed: z.ZodArray<z.ZodString>;
|
|
59
|
+
}, z.core.$strict>;
|
|
60
|
+
export type EventUnsubscribeResult = z.infer<typeof EventUnsubscribeResultSchema>;
|
|
61
|
+
/**
|
|
62
|
+
* Schema for event publishing requests (kadi.event.publish)
|
|
63
|
+
*/
|
|
64
|
+
export declare const EventPublishSchema: z.ZodObject<{
|
|
65
|
+
channel: z.ZodString;
|
|
66
|
+
data: z.ZodUnknown;
|
|
67
|
+
networks: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
68
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
69
|
+
}, z.core.$strict>;
|
|
70
|
+
export type EventPublishParams = z.infer<typeof EventPublishSchema>;
|
|
71
|
+
/**
|
|
72
|
+
* Schema for event publishing response
|
|
73
|
+
*/
|
|
74
|
+
export declare const EventPublishResultSchema: z.ZodObject<{
|
|
75
|
+
published: z.ZodBoolean;
|
|
76
|
+
eventId: z.ZodString;
|
|
77
|
+
}, z.core.$strict>;
|
|
78
|
+
export type EventPublishResult = z.infer<typeof EventPublishResultSchema>;
|
|
79
|
+
/**
|
|
80
|
+
* Schema for event subscription listing requests (kadi.event.list)
|
|
81
|
+
*/
|
|
82
|
+
export declare const EventListSchema: z.ZodObject<{
|
|
83
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
84
|
+
networkId: z.ZodOptional<z.ZodString>;
|
|
85
|
+
}, z.core.$strict>;
|
|
86
|
+
export type EventListParams = z.infer<typeof EventListSchema>;
|
|
87
|
+
/**
|
|
88
|
+
* Schema for event subscription listing response
|
|
89
|
+
*/
|
|
90
|
+
export declare const EventListResultSchema: z.ZodObject<{
|
|
91
|
+
subscriptions: z.ZodArray<z.ZodObject<{
|
|
92
|
+
agentId: z.ZodString;
|
|
93
|
+
channels: z.ZodArray<z.ZodString>;
|
|
94
|
+
networks: z.ZodArray<z.ZodString>;
|
|
95
|
+
queueName: z.ZodString;
|
|
96
|
+
subscribedAt: z.ZodString;
|
|
97
|
+
}, z.core.$strip>>;
|
|
98
|
+
}, z.core.$strict>;
|
|
99
|
+
export type EventListResult = z.infer<typeof EventListResultSchema>;
|
|
100
|
+
/**
|
|
101
|
+
* Schema for validating event messages before delivery.
|
|
102
|
+
* This ensures all events have consistent structure when delivered to subscribers.
|
|
103
|
+
*/
|
|
104
|
+
export declare const EventMessageSchema: z.ZodObject<{
|
|
105
|
+
channel: z.ZodString;
|
|
106
|
+
data: z.ZodUnknown;
|
|
107
|
+
timestamp: z.ZodString;
|
|
108
|
+
publisherId: z.ZodString;
|
|
109
|
+
networkId: z.ZodString;
|
|
110
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
111
|
+
correlationId: z.ZodOptional<z.ZodString>;
|
|
112
|
+
version: z.ZodOptional<z.ZodString>;
|
|
113
|
+
eventId: z.ZodOptional<z.ZodString>;
|
|
114
|
+
publisherRole: z.ZodOptional<z.ZodString>;
|
|
115
|
+
}, z.core.$catchall<z.ZodUnknown>>>;
|
|
116
|
+
}, z.core.$strict>;
|
|
117
|
+
export type EventMessage = z.infer<typeof EventMessageSchema>;
|
|
118
|
+
/**
|
|
119
|
+
* Validation middleware for event system methods.
|
|
120
|
+
* Extends the existing ValidationMiddleware pattern to support event operations.
|
|
121
|
+
*/
|
|
122
|
+
export declare class EventValidationMiddleware {
|
|
123
|
+
/**
|
|
124
|
+
* Validates parameters for event system methods using appropriate schemas
|
|
125
|
+
*/
|
|
126
|
+
static validateEventParams<T>(method: string, params: unknown): T;
|
|
127
|
+
/**
|
|
128
|
+
* Validates event message structure before delivery
|
|
129
|
+
*/
|
|
130
|
+
static validateEventMessage(message: unknown): EventMessage;
|
|
131
|
+
/**
|
|
132
|
+
* Provides user-friendly error messages for common validation failures
|
|
133
|
+
*/
|
|
134
|
+
static getValidationHint(method: string, error: z.ZodError): string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Export all schemas for use in tests and external validation
|
|
138
|
+
*/
|
|
139
|
+
export declare const EventSchemas: {
|
|
140
|
+
readonly EventChannel: z.ZodString;
|
|
141
|
+
readonly EventSubscribe: z.ZodObject<{
|
|
142
|
+
channels: z.ZodArray<z.ZodString>;
|
|
143
|
+
networkId: z.ZodOptional<z.ZodString>;
|
|
144
|
+
filter: z.ZodOptional<z.ZodObject<{
|
|
145
|
+
publisherId: z.ZodOptional<z.ZodString>;
|
|
146
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
147
|
+
}, z.core.$strip>>;
|
|
148
|
+
}, z.core.$strict>;
|
|
149
|
+
readonly EventUnsubscribe: z.ZodObject<{
|
|
150
|
+
channels: z.ZodArray<z.ZodString>;
|
|
151
|
+
networkId: z.ZodOptional<z.ZodString>;
|
|
152
|
+
}, z.core.$strict>;
|
|
153
|
+
readonly EventPublish: z.ZodObject<{
|
|
154
|
+
channel: z.ZodString;
|
|
155
|
+
data: z.ZodUnknown;
|
|
156
|
+
networks: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
157
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
158
|
+
}, z.core.$strict>;
|
|
159
|
+
readonly EventList: z.ZodObject<{
|
|
160
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
161
|
+
networkId: z.ZodOptional<z.ZodString>;
|
|
162
|
+
}, z.core.$strict>;
|
|
163
|
+
readonly EventMessage: z.ZodObject<{
|
|
164
|
+
channel: z.ZodString;
|
|
165
|
+
data: z.ZodUnknown;
|
|
166
|
+
timestamp: z.ZodString;
|
|
167
|
+
publisherId: z.ZodString;
|
|
168
|
+
networkId: z.ZodString;
|
|
169
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
170
|
+
correlationId: z.ZodOptional<z.ZodString>;
|
|
171
|
+
version: z.ZodOptional<z.ZodString>;
|
|
172
|
+
eventId: z.ZodOptional<z.ZodString>;
|
|
173
|
+
publisherRole: z.ZodOptional<z.ZodString>;
|
|
174
|
+
}, z.core.$catchall<z.ZodUnknown>>>;
|
|
175
|
+
}, z.core.$strict>;
|
|
176
|
+
};
|
|
177
|
+
//# sourceMappingURL=events.schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.schemas.d.ts","sourceRoot":"","sources":["../../src/schemas/events.schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,kBAAkB,aAQuB,CAAC;AAMvD;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;;;;kBAqBtB,CAAC;AAEZ,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE;;GAEG;AACH,eAAO,MAAM,0BAA0B;;;kBAO5B,CAAC;AAEZ,MA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ACH,MAAM,CAAC,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY;IAI3D;;OAEG;IACH,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,GAAG,MAAM;CAyBpE;AAMD;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAOf,CAAC"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event System Schema Validation
|
|
3
|
+
* ------------------------------
|
|
4
|
+
* Zod schemas for validating event system parameters and messages.
|
|
5
|
+
* This ensures type safety and proper input validation for all event operations.
|
|
6
|
+
*
|
|
7
|
+
* The schemas follow the established patterns in the KADI broker for consistency
|
|
8
|
+
* and integrate with the existing validation middleware.
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { NetworkIdSchema } from './kadi.schemas.js';
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// EVENT CHANNEL VALIDATION
|
|
14
|
+
// ============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* Event channel pattern validation schema.
|
|
17
|
+
*
|
|
18
|
+
* Enforces the hierarchical naming convention:
|
|
19
|
+
* - Format: namespace.event-name or namespace.category.event-name
|
|
20
|
+
* - Examples: 'system.startup', 'tool.completed', 'agent.status.changed'
|
|
21
|
+
* - Wildcards: '*' matches one segment, '#' matches multiple segments
|
|
22
|
+
*
|
|
23
|
+
* Rules:
|
|
24
|
+
* - Must start with lowercase letter
|
|
25
|
+
* - Segments separated by dots
|
|
26
|
+
* - Only lowercase letters, numbers, underscores, hyphens allowed
|
|
27
|
+
* - Wildcards * and # only allowed at end of segments
|
|
28
|
+
*/
|
|
29
|
+
export const EventChannelSchema = z
|
|
30
|
+
.string()
|
|
31
|
+
.min(1, 'Event channel cannot be empty')
|
|
32
|
+
.max(128, 'Event channel too long')
|
|
33
|
+
.regex(/^[a-z][a-z0-9_-]*(?:\.[a-z0-9_*#-]+)*$/, 'Event channel must use lowercase with dots (e.g., "system.startup", "tool.*", "agent.#")')
|
|
34
|
+
.describe('Event channel pattern for subscriptions');
|
|
35
|
+
// ============================================================================
|
|
36
|
+
// EVENT SUBSCRIPTION SCHEMAS
|
|
37
|
+
// ============================================================================
|
|
38
|
+
/**
|
|
39
|
+
* Schema for event subscription requests (kadi.event.subscribe)
|
|
40
|
+
*/
|
|
41
|
+
export const EventSubscribeSchema = z
|
|
42
|
+
.object({
|
|
43
|
+
/** Array of event channel patterns to subscribe to */
|
|
44
|
+
channels: z
|
|
45
|
+
.array(EventChannelSchema)
|
|
46
|
+
.min(1, 'Must specify at least one channel')
|
|
47
|
+
.max(50, 'Too many channels in single subscription'),
|
|
48
|
+
/** Optional network to subscribe within - defaults to agent's networks */
|
|
49
|
+
networkId: NetworkIdSchema.optional(),
|
|
50
|
+
/** Optional filters to reduce event volume */
|
|
51
|
+
filter: z
|
|
52
|
+
.object({
|
|
53
|
+
/** Only receive events from specific publisher */
|
|
54
|
+
publisherId: z.string().optional(),
|
|
55
|
+
/** Only receive events with matching metadata */
|
|
56
|
+
metadata: z.record(z.string(), z.unknown()).optional()
|
|
57
|
+
})
|
|
58
|
+
.optional()
|
|
59
|
+
})
|
|
60
|
+
.strict(); // Prevent additional properties
|
|
61
|
+
/**
|
|
62
|
+
* Schema for event subscription response
|
|
63
|
+
*/
|
|
64
|
+
export const EventSubscribeResultSchema = z
|
|
65
|
+
.object({
|
|
66
|
+
/** Channels that were successfully subscribed to */
|
|
67
|
+
subscribed: z.array(EventChannelSchema),
|
|
68
|
+
/** Internal queue name for debugging/monitoring */
|
|
69
|
+
queueName: z.string()
|
|
70
|
+
})
|
|
71
|
+
.strict();
|
|
72
|
+
// ============================================================================
|
|
73
|
+
// EVENT UNSUBSCRIPTION SCHEMAS
|
|
74
|
+
// ============================================================================
|
|
75
|
+
/**
|
|
76
|
+
* Schema for event unsubscription requests (kadi.event.unsubscribe)
|
|
77
|
+
*/
|
|
78
|
+
export const EventUnsubscribeSchema = z
|
|
79
|
+
.object({
|
|
80
|
+
/** Channel patterns to unsubscribe from */
|
|
81
|
+
channels: z
|
|
82
|
+
.array(EventChannelSchema)
|
|
83
|
+
.min(1, 'Must specify at least one channel'),
|
|
84
|
+
/** Network to unsubscribe from - defaults to 'global' */
|
|
85
|
+
networkId: NetworkIdSchema.optional()
|
|
86
|
+
})
|
|
87
|
+
.strict();
|
|
88
|
+
/**
|
|
89
|
+
* Schema for event unsubscription response
|
|
90
|
+
*/
|
|
91
|
+
export const EventUnsubscribeResultSchema = z
|
|
92
|
+
.object({
|
|
93
|
+
/** Channels that were successfully unsubscribed */
|
|
94
|
+
unsubscribed: z.array(EventChannelSchema)
|
|
95
|
+
})
|
|
96
|
+
.strict();
|
|
97
|
+
// ============================================================================
|
|
98
|
+
// EVENT PUBLISHING SCHEMAS
|
|
99
|
+
// ============================================================================
|
|
100
|
+
/**
|
|
101
|
+
* Schema for event publishing requests (kadi.event.publish)
|
|
102
|
+
*/
|
|
103
|
+
export const EventPublishSchema = z
|
|
104
|
+
.object({
|
|
105
|
+
/** Event channel to publish to - must not contain wildcards */
|
|
106
|
+
channel: EventChannelSchema.refine((channel) => !channel.includes('*') && !channel.includes('#'), 'Cannot publish to wildcard channels - use specific channel names'),
|
|
107
|
+
/** Event payload data - any serializable value */
|
|
108
|
+
data: z.unknown(),
|
|
109
|
+
/** Networks to publish to - defaults to publisher's networks */
|
|
110
|
+
networks: z
|
|
111
|
+
.array(NetworkIdSchema)
|
|
112
|
+
.max(10, 'Cannot publish to more than 10 networks at once')
|
|
113
|
+
.optional(),
|
|
114
|
+
/** Optional metadata to include with the event */
|
|
115
|
+
metadata: z.record(z.string(), z.unknown()).optional()
|
|
116
|
+
})
|
|
117
|
+
.strict();
|
|
118
|
+
/**
|
|
119
|
+
* Schema for event publishing response
|
|
120
|
+
*/
|
|
121
|
+
export const EventPublishResultSchema = z
|
|
122
|
+
.object({
|
|
123
|
+
/** Whether the event was successfully published */
|
|
124
|
+
published: z.boolean(),
|
|
125
|
+
/** Unique identifier for this event (for tracking/debugging) */
|
|
126
|
+
eventId: z.string().uuid()
|
|
127
|
+
})
|
|
128
|
+
.strict();
|
|
129
|
+
// ============================================================================
|
|
130
|
+
// EVENT LISTING SCHEMAS
|
|
131
|
+
// ============================================================================
|
|
132
|
+
/**
|
|
133
|
+
* Schema for event subscription listing requests (kadi.event.list)
|
|
134
|
+
*/
|
|
135
|
+
export const EventListSchema = z
|
|
136
|
+
.object({
|
|
137
|
+
/** Filter subscriptions by agent ID */
|
|
138
|
+
agentId: z.string().optional(),
|
|
139
|
+
/** Filter subscriptions by network */
|
|
140
|
+
networkId: NetworkIdSchema.optional()
|
|
141
|
+
})
|
|
142
|
+
.strict();
|
|
143
|
+
/**
|
|
144
|
+
* Schema for event subscription listing response
|
|
145
|
+
*/
|
|
146
|
+
export const EventListResultSchema = z
|
|
147
|
+
.object({
|
|
148
|
+
/** Array of active subscriptions */
|
|
149
|
+
subscriptions: z.array(z.object({
|
|
150
|
+
agentId: z.string(),
|
|
151
|
+
channels: z.array(EventChannelSchema),
|
|
152
|
+
networks: z.array(NetworkIdSchema),
|
|
153
|
+
queueName: z.string(),
|
|
154
|
+
subscribedAt: z.string().datetime() // ISO 8601 timestamp
|
|
155
|
+
}))
|
|
156
|
+
})
|
|
157
|
+
.strict();
|
|
158
|
+
// ============================================================================
|
|
159
|
+
// EVENT MESSAGE SCHEMAS
|
|
160
|
+
// ============================================================================
|
|
161
|
+
/**
|
|
162
|
+
* Schema for validating event messages before delivery.
|
|
163
|
+
* This ensures all events have consistent structure when delivered to subscribers.
|
|
164
|
+
*/
|
|
165
|
+
export const EventMessageSchema = z
|
|
166
|
+
.object({
|
|
167
|
+
/** The channel this event was published to */
|
|
168
|
+
channel: EventChannelSchema,
|
|
169
|
+
/** Event-specific payload data */
|
|
170
|
+
data: z.unknown(),
|
|
171
|
+
/** ISO 8601 timestamp when event was published */
|
|
172
|
+
timestamp: z.string().datetime(),
|
|
173
|
+
/** ID of the agent/tool that published this event */
|
|
174
|
+
publisherId: z.string(),
|
|
175
|
+
/** Network where this event was published */
|
|
176
|
+
networkId: NetworkIdSchema,
|
|
177
|
+
/** Optional metadata for correlation and tracking */
|
|
178
|
+
metadata: z
|
|
179
|
+
.object({
|
|
180
|
+
/** For tracking related events across the system */
|
|
181
|
+
correlationId: z.string().optional(),
|
|
182
|
+
/** Event schema version for evolution */
|
|
183
|
+
version: z.string().optional(),
|
|
184
|
+
/** Event ID for deduplication and tracing */
|
|
185
|
+
eventId: z.string().uuid().optional(),
|
|
186
|
+
/** Role of the publisher (agent, tool, system) */
|
|
187
|
+
publisherRole: z.string().optional()
|
|
188
|
+
/** Additional custom metadata */
|
|
189
|
+
})
|
|
190
|
+
.catchall(z.unknown())
|
|
191
|
+
.optional() // Allow additional metadata fields
|
|
192
|
+
})
|
|
193
|
+
.strict();
|
|
194
|
+
// ============================================================================
|
|
195
|
+
// VALIDATION MIDDLEWARE INTEGRATION
|
|
196
|
+
// ============================================================================
|
|
197
|
+
/**
|
|
198
|
+
* Validation middleware for event system methods.
|
|
199
|
+
* Extends the existing ValidationMiddleware pattern to support event operations.
|
|
200
|
+
*/
|
|
201
|
+
export class EventValidationMiddleware {
|
|
202
|
+
/**
|
|
203
|
+
* Validates parameters for event system methods using appropriate schemas
|
|
204
|
+
*/
|
|
205
|
+
static validateEventParams(method, params) {
|
|
206
|
+
switch (method) {
|
|
207
|
+
case 'kadi.event.subscribe':
|
|
208
|
+
return EventSubscribeSchema.parse(params);
|
|
209
|
+
case 'kadi.event.unsubscribe':
|
|
210
|
+
return EventUnsubscribeSchema.parse(params);
|
|
211
|
+
case 'kadi.event.publish':
|
|
212
|
+
return EventPublishSchema.parse(params);
|
|
213
|
+
case 'kadi.event.list':
|
|
214
|
+
return EventListSchema.parse(params);
|
|
215
|
+
default:
|
|
216
|
+
// For non-event methods, return params as-is
|
|
217
|
+
return params;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Validates event message structure before delivery
|
|
222
|
+
*/
|
|
223
|
+
static validateEventMessage(message) {
|
|
224
|
+
return EventMessageSchema.parse(message);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Provides user-friendly error messages for common validation failures
|
|
228
|
+
*/
|
|
229
|
+
static getValidationHint(method, error) {
|
|
230
|
+
const firstError = error.issues[0];
|
|
231
|
+
switch (method) {
|
|
232
|
+
case 'kadi.event.subscribe':
|
|
233
|
+
if (firstError?.path.includes('channels')) {
|
|
234
|
+
return 'Check channel format: use lowercase with dots (e.g., "system.startup", "tool.*")';
|
|
235
|
+
}
|
|
236
|
+
break;
|
|
237
|
+
case 'kadi.event.publish':
|
|
238
|
+
if (firstError?.path.includes('channel')) {
|
|
239
|
+
return 'Channel must be specific (no wildcards) and use lowercase.separated format';
|
|
240
|
+
}
|
|
241
|
+
if (firstError?.path.includes('networks')) {
|
|
242
|
+
return 'Networks must be an array of valid network IDs';
|
|
243
|
+
}
|
|
244
|
+
break;
|
|
245
|
+
default:
|
|
246
|
+
return 'Check your event parameters for correct format and types';
|
|
247
|
+
}
|
|
248
|
+
return 'Check the event system documentation for parameter requirements';
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// ============================================================================
|
|
252
|
+
// SCHEMA EXPORTS FOR EXTERNAL USE
|
|
253
|
+
// ============================================================================
|
|
254
|
+
/**
|
|
255
|
+
* Export all schemas for use in tests and external validation
|
|
256
|
+
*/
|
|
257
|
+
export const EventSchemas = {
|
|
258
|
+
EventChannel: EventChannelSchema,
|
|
259
|
+
EventSubscribe: EventSubscribeSchema,
|
|
260
|
+
EventUnsubscribe: EventUnsubscribeSchema,
|
|
261
|
+
EventPublish: EventPublishSchema,
|
|
262
|
+
EventList: EventListSchema,
|
|
263
|
+
EventMessage: EventMessageSchema
|
|
264
|
+
};
|
|
265
|
+
//# sourceMappingURL=events.schemas.js.map
|