@adamancyzhang/claude-orchestrator 0.1.0 → 0.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/README.md +437 -0
- package/bin/claude-orchestrator +2 -17
- package/dist/cli/commands.d.ts +20 -0
- package/dist/cli/commands.js +192 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/config.d.ts +15 -0
- package/dist/config.js +39 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +342 -0
- package/dist/index.js.map +1 -0
- package/dist/models/schemas.d.ts +308 -0
- package/dist/models/schemas.js +167 -0
- package/dist/models/schemas.js.map +1 -0
- package/dist/modules/context-store.d.ts +10 -0
- package/dist/modules/context-store.js +25 -0
- package/dist/modules/context-store.js.map +1 -0
- package/dist/modules/message-router.d.ts +12 -0
- package/dist/modules/message-router.js +94 -0
- package/dist/modules/message-router.js.map +1 -0
- package/dist/modules/registry.d.ts +11 -0
- package/dist/modules/registry.js +53 -0
- package/dist/modules/registry.js.map +1 -0
- package/dist/modules/task-queue.d.ts +10 -0
- package/dist/modules/task-queue.js +103 -0
- package/dist/modules/task-queue.js.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +425 -0
- package/dist/server.js.map +1 -0
- package/dist/utils/output.d.ts +1 -0
- package/dist/utils/output.js +10 -0
- package/dist/utils/output.js.map +1 -0
- package/dist/zk/client.d.ts +54 -0
- package/dist/zk/client.js +417 -0
- package/dist/zk/client.js.map +1 -0
- package/dist/zk/paths.d.ts +16 -0
- package/dist/zk/paths.js +40 -0
- package/dist/zk/paths.js.map +1 -0
- package/dist/zk/watcher.d.ts +11 -0
- package/dist/zk/watcher.js +16 -0
- package/dist/zk/watcher.js.map +1 -0
- package/package.json +23 -6
- package/scripts/install.js +0 -123
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const InstanceStatus: z.ZodEnum<["idle", "busy", "blocked"]>;
|
|
3
|
+
export type InstanceStatus = z.infer<typeof InstanceStatus>;
|
|
4
|
+
export declare const InstanceRole: z.ZodEnum<["architect", "developer", "tester", "general"]>;
|
|
5
|
+
export type InstanceRole = z.infer<typeof InstanceRole>;
|
|
6
|
+
export declare const TaskStatus: z.ZodEnum<["pending", "claimed", "completed"]>;
|
|
7
|
+
export type TaskStatus = z.infer<typeof TaskStatus>;
|
|
8
|
+
export declare const TaskPriority: z.ZodNumber;
|
|
9
|
+
export type TaskPriority = z.infer<typeof TaskPriority>;
|
|
10
|
+
export declare const TaskPriorityName: Record<number, string>;
|
|
11
|
+
export declare const MessageType: z.ZodEnum<["direct", "broadcast", "help"]>;
|
|
12
|
+
export type MessageType = z.infer<typeof MessageType>;
|
|
13
|
+
export declare const InstanceSchema: z.ZodObject<{
|
|
14
|
+
id: z.ZodString;
|
|
15
|
+
name: z.ZodString;
|
|
16
|
+
role: z.ZodDefault<z.ZodEnum<["architect", "developer", "tester", "general"]>>;
|
|
17
|
+
status: z.ZodDefault<z.ZodEnum<["idle", "busy", "blocked"]>>;
|
|
18
|
+
current_task_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
19
|
+
connected_since: z.ZodString;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
status: "idle" | "busy" | "blocked";
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
role: "architect" | "developer" | "tester" | "general";
|
|
25
|
+
current_task_id: string | null;
|
|
26
|
+
connected_since: string;
|
|
27
|
+
}, {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
connected_since: string;
|
|
31
|
+
status?: "idle" | "busy" | "blocked" | undefined;
|
|
32
|
+
role?: "architect" | "developer" | "tester" | "general" | undefined;
|
|
33
|
+
current_task_id?: string | null | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
export type Instance = z.infer<typeof InstanceSchema>;
|
|
36
|
+
export declare const TaskSchema: z.ZodObject<{
|
|
37
|
+
id: z.ZodDefault<z.ZodString>;
|
|
38
|
+
title: z.ZodString;
|
|
39
|
+
description: z.ZodDefault<z.ZodString>;
|
|
40
|
+
priority: z.ZodDefault<z.ZodNumber>;
|
|
41
|
+
status: z.ZodDefault<z.ZodEnum<["pending", "claimed", "completed"]>>;
|
|
42
|
+
created_by: z.ZodDefault<z.ZodString>;
|
|
43
|
+
assigned_to: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
44
|
+
created_at: z.ZodString;
|
|
45
|
+
claimed_at: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
46
|
+
completed_at: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
47
|
+
claimed_by: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
48
|
+
result: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
49
|
+
}, "strip", z.ZodTypeAny, {
|
|
50
|
+
status: "pending" | "claimed" | "completed";
|
|
51
|
+
id: string;
|
|
52
|
+
title: string;
|
|
53
|
+
description: string;
|
|
54
|
+
priority: number;
|
|
55
|
+
created_by: string;
|
|
56
|
+
assigned_to: string | null;
|
|
57
|
+
created_at: string;
|
|
58
|
+
claimed_at: string | null;
|
|
59
|
+
completed_at: string | null;
|
|
60
|
+
claimed_by: string | null;
|
|
61
|
+
result: string | null;
|
|
62
|
+
}, {
|
|
63
|
+
title: string;
|
|
64
|
+
created_at: string;
|
|
65
|
+
status?: "pending" | "claimed" | "completed" | undefined;
|
|
66
|
+
id?: string | undefined;
|
|
67
|
+
description?: string | undefined;
|
|
68
|
+
priority?: number | undefined;
|
|
69
|
+
created_by?: string | undefined;
|
|
70
|
+
assigned_to?: string | null | undefined;
|
|
71
|
+
claimed_at?: string | null | undefined;
|
|
72
|
+
completed_at?: string | null | undefined;
|
|
73
|
+
claimed_by?: string | null | undefined;
|
|
74
|
+
result?: string | null | undefined;
|
|
75
|
+
}>;
|
|
76
|
+
export type Task = z.infer<typeof TaskSchema>;
|
|
77
|
+
export declare const MessageSchema: z.ZodObject<{
|
|
78
|
+
id: z.ZodDefault<z.ZodString>;
|
|
79
|
+
type: z.ZodDefault<z.ZodEnum<["direct", "broadcast", "help"]>>;
|
|
80
|
+
from_instance: z.ZodDefault<z.ZodString>;
|
|
81
|
+
from_name: z.ZodDefault<z.ZodString>;
|
|
82
|
+
to_instance: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
83
|
+
content: z.ZodString;
|
|
84
|
+
created_at: z.ZodString;
|
|
85
|
+
read: z.ZodDefault<z.ZodBoolean>;
|
|
86
|
+
}, "strip", z.ZodTypeAny, {
|
|
87
|
+
type: "direct" | "broadcast" | "help";
|
|
88
|
+
id: string;
|
|
89
|
+
created_at: string;
|
|
90
|
+
from_instance: string;
|
|
91
|
+
from_name: string;
|
|
92
|
+
to_instance: string | null;
|
|
93
|
+
content: string;
|
|
94
|
+
read: boolean;
|
|
95
|
+
}, {
|
|
96
|
+
created_at: string;
|
|
97
|
+
content: string;
|
|
98
|
+
type?: "direct" | "broadcast" | "help" | undefined;
|
|
99
|
+
id?: string | undefined;
|
|
100
|
+
from_instance?: string | undefined;
|
|
101
|
+
from_name?: string | undefined;
|
|
102
|
+
to_instance?: string | null | undefined;
|
|
103
|
+
read?: boolean | undefined;
|
|
104
|
+
}>;
|
|
105
|
+
export type Message = z.infer<typeof MessageSchema>;
|
|
106
|
+
export declare const ContextEntrySchema: z.ZodObject<{
|
|
107
|
+
key: z.ZodString;
|
|
108
|
+
value: z.ZodString;
|
|
109
|
+
updated_by: z.ZodDefault<z.ZodString>;
|
|
110
|
+
updated_at: z.ZodString;
|
|
111
|
+
}, "strip", z.ZodTypeAny, {
|
|
112
|
+
value: string;
|
|
113
|
+
key: string;
|
|
114
|
+
updated_by: string;
|
|
115
|
+
updated_at: string;
|
|
116
|
+
}, {
|
|
117
|
+
value: string;
|
|
118
|
+
key: string;
|
|
119
|
+
updated_at: string;
|
|
120
|
+
updated_by?: string | undefined;
|
|
121
|
+
}>;
|
|
122
|
+
export type ContextEntry = z.infer<typeof ContextEntrySchema>;
|
|
123
|
+
export declare function createInstance(overrides: {
|
|
124
|
+
id?: string;
|
|
125
|
+
name: string;
|
|
126
|
+
role?: InstanceRole;
|
|
127
|
+
}): Instance;
|
|
128
|
+
export declare function createTask(overrides: {
|
|
129
|
+
title: string;
|
|
130
|
+
description?: string;
|
|
131
|
+
priority?: number;
|
|
132
|
+
created_by?: string;
|
|
133
|
+
assigned_to?: string | null;
|
|
134
|
+
}): Task;
|
|
135
|
+
export declare function createMessage(overrides: {
|
|
136
|
+
type?: MessageType;
|
|
137
|
+
from_instance: string;
|
|
138
|
+
from_name: string;
|
|
139
|
+
to_instance: string;
|
|
140
|
+
content: string;
|
|
141
|
+
}): Message;
|
|
142
|
+
export declare function createContextEntry(overrides: {
|
|
143
|
+
key: string;
|
|
144
|
+
value: string;
|
|
145
|
+
updated_by?: string;
|
|
146
|
+
}): ContextEntry;
|
|
147
|
+
export declare const RegisterInstanceInput: z.ZodObject<{
|
|
148
|
+
name: z.ZodString;
|
|
149
|
+
role: z.ZodDefault<z.ZodEnum<["architect", "developer", "tester", "general"]>>;
|
|
150
|
+
instance_id: z.ZodOptional<z.ZodString>;
|
|
151
|
+
}, "strip", z.ZodTypeAny, {
|
|
152
|
+
name: string;
|
|
153
|
+
role: "architect" | "developer" | "tester" | "general";
|
|
154
|
+
instance_id?: string | undefined;
|
|
155
|
+
}, {
|
|
156
|
+
name: string;
|
|
157
|
+
role?: "architect" | "developer" | "tester" | "general" | undefined;
|
|
158
|
+
instance_id?: string | undefined;
|
|
159
|
+
}>;
|
|
160
|
+
export declare const HeartbeatInput: z.ZodObject<{
|
|
161
|
+
instance_id: z.ZodString;
|
|
162
|
+
current_task: z.ZodOptional<z.ZodString>;
|
|
163
|
+
}, "strip", z.ZodTypeAny, {
|
|
164
|
+
instance_id: string;
|
|
165
|
+
current_task?: string | undefined;
|
|
166
|
+
}, {
|
|
167
|
+
instance_id: string;
|
|
168
|
+
current_task?: string | undefined;
|
|
169
|
+
}>;
|
|
170
|
+
export declare const PushTaskInput: z.ZodObject<{
|
|
171
|
+
title: z.ZodString;
|
|
172
|
+
description: z.ZodDefault<z.ZodString>;
|
|
173
|
+
priority: z.ZodDefault<z.ZodNumber>;
|
|
174
|
+
instance_id: z.ZodDefault<z.ZodString>;
|
|
175
|
+
assignee: z.ZodOptional<z.ZodString>;
|
|
176
|
+
}, "strip", z.ZodTypeAny, {
|
|
177
|
+
title: string;
|
|
178
|
+
description: string;
|
|
179
|
+
priority: number;
|
|
180
|
+
instance_id: string;
|
|
181
|
+
assignee?: string | undefined;
|
|
182
|
+
}, {
|
|
183
|
+
title: string;
|
|
184
|
+
description?: string | undefined;
|
|
185
|
+
priority?: number | undefined;
|
|
186
|
+
instance_id?: string | undefined;
|
|
187
|
+
assignee?: string | undefined;
|
|
188
|
+
}>;
|
|
189
|
+
export declare const ClaimTaskInput: z.ZodObject<{
|
|
190
|
+
instance_id: z.ZodString;
|
|
191
|
+
}, "strip", z.ZodTypeAny, {
|
|
192
|
+
instance_id: string;
|
|
193
|
+
}, {
|
|
194
|
+
instance_id: string;
|
|
195
|
+
}>;
|
|
196
|
+
export declare const CompleteTaskInput: z.ZodObject<{
|
|
197
|
+
instance_id: z.ZodString;
|
|
198
|
+
task_id: z.ZodString;
|
|
199
|
+
result: z.ZodString;
|
|
200
|
+
}, "strip", z.ZodTypeAny, {
|
|
201
|
+
result: string;
|
|
202
|
+
instance_id: string;
|
|
203
|
+
task_id: string;
|
|
204
|
+
}, {
|
|
205
|
+
result: string;
|
|
206
|
+
instance_id: string;
|
|
207
|
+
task_id: string;
|
|
208
|
+
}>;
|
|
209
|
+
export declare const ListTasksInput: z.ZodObject<{
|
|
210
|
+
status: z.ZodOptional<z.ZodString>;
|
|
211
|
+
}, "strip", z.ZodTypeAny, {
|
|
212
|
+
status?: string | undefined;
|
|
213
|
+
}, {
|
|
214
|
+
status?: string | undefined;
|
|
215
|
+
}>;
|
|
216
|
+
export declare const SendMessageInput: z.ZodObject<{
|
|
217
|
+
instance_id: z.ZodString;
|
|
218
|
+
content: z.ZodString;
|
|
219
|
+
to_instance: z.ZodOptional<z.ZodString>;
|
|
220
|
+
broadcast: z.ZodDefault<z.ZodBoolean>;
|
|
221
|
+
}, "strip", z.ZodTypeAny, {
|
|
222
|
+
broadcast: boolean;
|
|
223
|
+
content: string;
|
|
224
|
+
instance_id: string;
|
|
225
|
+
to_instance?: string | undefined;
|
|
226
|
+
}, {
|
|
227
|
+
content: string;
|
|
228
|
+
instance_id: string;
|
|
229
|
+
broadcast?: boolean | undefined;
|
|
230
|
+
to_instance?: string | undefined;
|
|
231
|
+
}>;
|
|
232
|
+
export declare const PollMessagesInput: z.ZodObject<{
|
|
233
|
+
instance_id: z.ZodString;
|
|
234
|
+
}, "strip", z.ZodTypeAny, {
|
|
235
|
+
instance_id: string;
|
|
236
|
+
}, {
|
|
237
|
+
instance_id: string;
|
|
238
|
+
}>;
|
|
239
|
+
export declare const WaitForMessageInput: z.ZodObject<{
|
|
240
|
+
instance_id: z.ZodString;
|
|
241
|
+
timeout_seconds: z.ZodDefault<z.ZodNumber>;
|
|
242
|
+
}, "strip", z.ZodTypeAny, {
|
|
243
|
+
instance_id: string;
|
|
244
|
+
timeout_seconds: number;
|
|
245
|
+
}, {
|
|
246
|
+
instance_id: string;
|
|
247
|
+
timeout_seconds?: number | undefined;
|
|
248
|
+
}>;
|
|
249
|
+
export declare const MarkReadInput: z.ZodObject<{
|
|
250
|
+
instance_id: z.ZodString;
|
|
251
|
+
message_id: z.ZodString;
|
|
252
|
+
}, "strip", z.ZodTypeAny, {
|
|
253
|
+
instance_id: string;
|
|
254
|
+
message_id: string;
|
|
255
|
+
}, {
|
|
256
|
+
instance_id: string;
|
|
257
|
+
message_id: string;
|
|
258
|
+
}>;
|
|
259
|
+
export declare const DismissMessageInput: z.ZodObject<{
|
|
260
|
+
instance_id: z.ZodString;
|
|
261
|
+
message_id: z.ZodString;
|
|
262
|
+
}, "strip", z.ZodTypeAny, {
|
|
263
|
+
instance_id: string;
|
|
264
|
+
message_id: string;
|
|
265
|
+
}, {
|
|
266
|
+
instance_id: string;
|
|
267
|
+
message_id: string;
|
|
268
|
+
}>;
|
|
269
|
+
export declare const RequestHelpInput: z.ZodObject<{
|
|
270
|
+
instance_id: z.ZodString;
|
|
271
|
+
question: z.ZodString;
|
|
272
|
+
context: z.ZodOptional<z.ZodString>;
|
|
273
|
+
}, "strip", z.ZodTypeAny, {
|
|
274
|
+
instance_id: string;
|
|
275
|
+
question: string;
|
|
276
|
+
context?: string | undefined;
|
|
277
|
+
}, {
|
|
278
|
+
instance_id: string;
|
|
279
|
+
question: string;
|
|
280
|
+
context?: string | undefined;
|
|
281
|
+
}>;
|
|
282
|
+
export declare const SetContextInput: z.ZodObject<{
|
|
283
|
+
key: z.ZodString;
|
|
284
|
+
value: z.ZodString;
|
|
285
|
+
instance_id: z.ZodDefault<z.ZodString>;
|
|
286
|
+
}, "strip", z.ZodTypeAny, {
|
|
287
|
+
value: string;
|
|
288
|
+
key: string;
|
|
289
|
+
instance_id: string;
|
|
290
|
+
}, {
|
|
291
|
+
value: string;
|
|
292
|
+
key: string;
|
|
293
|
+
instance_id?: string | undefined;
|
|
294
|
+
}>;
|
|
295
|
+
export declare const GetContextInput: z.ZodObject<{
|
|
296
|
+
key: z.ZodString;
|
|
297
|
+
}, "strip", z.ZodTypeAny, {
|
|
298
|
+
key: string;
|
|
299
|
+
}, {
|
|
300
|
+
key: string;
|
|
301
|
+
}>;
|
|
302
|
+
export declare const DeleteContextInput: z.ZodObject<{
|
|
303
|
+
key: z.ZodString;
|
|
304
|
+
}, "strip", z.ZodTypeAny, {
|
|
305
|
+
key: string;
|
|
306
|
+
}, {
|
|
307
|
+
key: string;
|
|
308
|
+
}>;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// ── Enums ──
|
|
3
|
+
export const InstanceStatus = z.enum(["idle", "busy", "blocked"]);
|
|
4
|
+
export const InstanceRole = z.enum(["architect", "developer", "tester", "general"]);
|
|
5
|
+
export const TaskStatus = z.enum(["pending", "claimed", "completed"]);
|
|
6
|
+
export const TaskPriority = z.number().int().min(0).max(2);
|
|
7
|
+
export const TaskPriorityName = {
|
|
8
|
+
0: "HIGH",
|
|
9
|
+
1: "MEDIUM",
|
|
10
|
+
2: "LOW",
|
|
11
|
+
};
|
|
12
|
+
export const MessageType = z.enum(["direct", "broadcast", "help"]);
|
|
13
|
+
// ── Data Models ──
|
|
14
|
+
function utcNow() {
|
|
15
|
+
return new Date().toISOString();
|
|
16
|
+
}
|
|
17
|
+
export const InstanceSchema = z.object({
|
|
18
|
+
id: z.string(),
|
|
19
|
+
name: z.string(),
|
|
20
|
+
role: InstanceRole.default("general"),
|
|
21
|
+
status: InstanceStatus.default("idle"),
|
|
22
|
+
current_task_id: z.string().nullable().default(null),
|
|
23
|
+
connected_since: z.string(),
|
|
24
|
+
});
|
|
25
|
+
export const TaskSchema = z.object({
|
|
26
|
+
id: z.string().default(""),
|
|
27
|
+
title: z.string(),
|
|
28
|
+
description: z.string().default(""),
|
|
29
|
+
priority: TaskPriority.default(1),
|
|
30
|
+
status: TaskStatus.default("pending"),
|
|
31
|
+
created_by: z.string().default(""),
|
|
32
|
+
assigned_to: z.string().nullable().default(null),
|
|
33
|
+
created_at: z.string(),
|
|
34
|
+
claimed_at: z.string().nullable().default(null),
|
|
35
|
+
completed_at: z.string().nullable().default(null),
|
|
36
|
+
claimed_by: z.string().nullable().default(null),
|
|
37
|
+
result: z.string().nullable().default(null),
|
|
38
|
+
});
|
|
39
|
+
export const MessageSchema = z.object({
|
|
40
|
+
id: z.string().default(""),
|
|
41
|
+
type: MessageType.default("direct"),
|
|
42
|
+
from_instance: z.string().default(""),
|
|
43
|
+
from_name: z.string().default(""),
|
|
44
|
+
to_instance: z.string().nullable().default(null),
|
|
45
|
+
content: z.string(),
|
|
46
|
+
created_at: z.string(),
|
|
47
|
+
read: z.boolean().default(false),
|
|
48
|
+
});
|
|
49
|
+
export const ContextEntrySchema = z.object({
|
|
50
|
+
key: z.string(),
|
|
51
|
+
value: z.string(),
|
|
52
|
+
updated_by: z.string().default(""),
|
|
53
|
+
updated_at: z.string(),
|
|
54
|
+
});
|
|
55
|
+
// ── Factory helpers (mirrors Python Field(default_factory=...)) ──
|
|
56
|
+
export function createInstance(overrides) {
|
|
57
|
+
return InstanceSchema.parse({
|
|
58
|
+
id: overrides.id ?? crypto.randomUUID().replace(/-/g, ""),
|
|
59
|
+
name: overrides.name,
|
|
60
|
+
role: overrides.role ?? "general",
|
|
61
|
+
status: "idle",
|
|
62
|
+
current_task_id: null,
|
|
63
|
+
connected_since: utcNow(),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export function createTask(overrides) {
|
|
67
|
+
return TaskSchema.parse({
|
|
68
|
+
id: "",
|
|
69
|
+
title: overrides.title,
|
|
70
|
+
description: overrides.description ?? "",
|
|
71
|
+
priority: overrides.priority ?? 1,
|
|
72
|
+
status: "pending",
|
|
73
|
+
created_by: overrides.created_by ?? "",
|
|
74
|
+
assigned_to: overrides.assigned_to ?? null,
|
|
75
|
+
created_at: utcNow(),
|
|
76
|
+
claimed_at: null,
|
|
77
|
+
completed_at: null,
|
|
78
|
+
claimed_by: null,
|
|
79
|
+
result: null,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
export function createMessage(overrides) {
|
|
83
|
+
return MessageSchema.parse({
|
|
84
|
+
id: "",
|
|
85
|
+
type: overrides.type ?? "direct",
|
|
86
|
+
from_instance: overrides.from_instance,
|
|
87
|
+
from_name: overrides.from_name,
|
|
88
|
+
to_instance: overrides.to_instance,
|
|
89
|
+
content: overrides.content,
|
|
90
|
+
created_at: utcNow(),
|
|
91
|
+
read: false,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
export function createContextEntry(overrides) {
|
|
95
|
+
return ContextEntrySchema.parse({
|
|
96
|
+
key: overrides.key,
|
|
97
|
+
value: overrides.value,
|
|
98
|
+
updated_by: overrides.updated_by ?? "",
|
|
99
|
+
updated_at: utcNow(),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
// ── Tool input schemas ──
|
|
103
|
+
export const RegisterInstanceInput = z.object({
|
|
104
|
+
name: z.string().min(1),
|
|
105
|
+
role: InstanceRole.default("general"),
|
|
106
|
+
instance_id: z.string().optional(),
|
|
107
|
+
});
|
|
108
|
+
export const HeartbeatInput = z.object({
|
|
109
|
+
instance_id: z.string(),
|
|
110
|
+
current_task: z.string().optional(),
|
|
111
|
+
});
|
|
112
|
+
export const PushTaskInput = z.object({
|
|
113
|
+
title: z.string().min(1),
|
|
114
|
+
description: z.string().default(""),
|
|
115
|
+
priority: TaskPriority.default(1),
|
|
116
|
+
instance_id: z.string().default(""),
|
|
117
|
+
assignee: z.string().optional(),
|
|
118
|
+
});
|
|
119
|
+
export const ClaimTaskInput = z.object({
|
|
120
|
+
instance_id: z.string(),
|
|
121
|
+
});
|
|
122
|
+
export const CompleteTaskInput = z.object({
|
|
123
|
+
instance_id: z.string(),
|
|
124
|
+
task_id: z.string(),
|
|
125
|
+
result: z.string(),
|
|
126
|
+
});
|
|
127
|
+
export const ListTasksInput = z.object({
|
|
128
|
+
status: z.string().optional(),
|
|
129
|
+
});
|
|
130
|
+
export const SendMessageInput = z.object({
|
|
131
|
+
instance_id: z.string(),
|
|
132
|
+
content: z.string().min(1),
|
|
133
|
+
to_instance: z.string().optional(),
|
|
134
|
+
broadcast: z.boolean().default(false),
|
|
135
|
+
});
|
|
136
|
+
export const PollMessagesInput = z.object({
|
|
137
|
+
instance_id: z.string(),
|
|
138
|
+
});
|
|
139
|
+
export const WaitForMessageInput = z.object({
|
|
140
|
+
instance_id: z.string(),
|
|
141
|
+
timeout_seconds: z.number().int().min(1).default(30),
|
|
142
|
+
});
|
|
143
|
+
export const MarkReadInput = z.object({
|
|
144
|
+
instance_id: z.string(),
|
|
145
|
+
message_id: z.string(),
|
|
146
|
+
});
|
|
147
|
+
export const DismissMessageInput = z.object({
|
|
148
|
+
instance_id: z.string(),
|
|
149
|
+
message_id: z.string(),
|
|
150
|
+
});
|
|
151
|
+
export const RequestHelpInput = z.object({
|
|
152
|
+
instance_id: z.string(),
|
|
153
|
+
question: z.string().min(1),
|
|
154
|
+
context: z.string().optional(),
|
|
155
|
+
});
|
|
156
|
+
export const SetContextInput = z.object({
|
|
157
|
+
key: z.string().min(1),
|
|
158
|
+
value: z.string(),
|
|
159
|
+
instance_id: z.string().default(""),
|
|
160
|
+
});
|
|
161
|
+
export const GetContextInput = z.object({
|
|
162
|
+
key: z.string(),
|
|
163
|
+
});
|
|
164
|
+
export const DeleteContextInput = z.object({
|
|
165
|
+
key: z.string(),
|
|
166
|
+
});
|
|
167
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/models/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,cAAc;AAEd,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAGlE,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAGpF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC;AAGtE,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAG3D,MAAM,CAAC,MAAM,gBAAgB,GAA2B;IACtD,CAAC,EAAE,MAAM;IACT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,EAAE;IACvB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC/B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACtB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;CACpC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;CAChB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;CAChB,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ZkClient } from "../zk/client.js";
|
|
2
|
+
import { type ContextEntry } from "../models/schemas.js";
|
|
3
|
+
export declare class ContextStore {
|
|
4
|
+
private zk;
|
|
5
|
+
constructor(zk: ZkClient);
|
|
6
|
+
set(key: string, value: string, updatedBy?: string): Promise<ContextEntry>;
|
|
7
|
+
get(key: string): Promise<string | null>;
|
|
8
|
+
delete(key: string): Promise<void>;
|
|
9
|
+
listKeys(): Promise<string[]>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createContextEntry, } from "../models/schemas.js";
|
|
2
|
+
export class ContextStore {
|
|
3
|
+
zk;
|
|
4
|
+
constructor(zk) {
|
|
5
|
+
this.zk = zk;
|
|
6
|
+
}
|
|
7
|
+
async set(key, value, updatedBy = "") {
|
|
8
|
+
const entry = createContextEntry({ key, value, updated_by: updatedBy });
|
|
9
|
+
await this.zk.setContext(key, entry);
|
|
10
|
+
return entry;
|
|
11
|
+
}
|
|
12
|
+
async get(key) {
|
|
13
|
+
const data = await this.zk.getContext(key);
|
|
14
|
+
if (!data)
|
|
15
|
+
return null;
|
|
16
|
+
return data.value ?? null;
|
|
17
|
+
}
|
|
18
|
+
async delete(key) {
|
|
19
|
+
await this.zk.deleteContext(key);
|
|
20
|
+
}
|
|
21
|
+
async listKeys() {
|
|
22
|
+
return this.zk.listContextKeys();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=context-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-store.js","sourceRoot":"","sources":["../../src/modules/context-store.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,GAEnB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,OAAO,YAAY;IACH;IAApB,YAAoB,EAAY;QAAZ,OAAE,GAAF,EAAE,CAAU;IAAG,CAAC;IAEpC,KAAK,CAAC,GAAG,CACP,GAAW,EACX,KAAa,EACb,YAAoB,EAAE;QAEtB,MAAM,KAAK,GAAG,kBAAkB,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC;QACxE,MAAM,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,KAA2C,CAAC,CAAC;QAC3E,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC;QACvB,OAAQ,IAAI,CAAC,KAAgB,IAAI,IAAI,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW;QACtB,MAAM,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,OAAO,IAAI,CAAC,EAAE,CAAC,eAAe,EAAE,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ZkClient } from "../zk/client.js";
|
|
2
|
+
import { type Message } from "../models/schemas.js";
|
|
3
|
+
export declare class MessageRouter {
|
|
4
|
+
private zk;
|
|
5
|
+
constructor(zk: ZkClient);
|
|
6
|
+
send(fromInstance: string, fromName: string, content: string, toInstance?: string, broadcast?: boolean): Promise<Message[]>;
|
|
7
|
+
poll(instanceId: string): Promise<Message[]>;
|
|
8
|
+
waitForMessage(instanceId: string, timeoutSeconds?: number): Promise<Message[]>;
|
|
9
|
+
markRead(instanceId: string, messageId: string): Promise<void>;
|
|
10
|
+
dismissMessage(instanceId: string, messageId: string): Promise<void>;
|
|
11
|
+
requestHelp(fromInstance: string, fromName: string, question: string, ctx?: string): Promise<Message[]>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { MessageSchema, createMessage, } from "../models/schemas.js";
|
|
2
|
+
function utcNow() {
|
|
3
|
+
return new Date().toISOString();
|
|
4
|
+
}
|
|
5
|
+
export class MessageRouter {
|
|
6
|
+
zk;
|
|
7
|
+
constructor(zk) {
|
|
8
|
+
this.zk = zk;
|
|
9
|
+
}
|
|
10
|
+
async send(fromInstance, fromName, content, toInstance, broadcast = false) {
|
|
11
|
+
const messages = [];
|
|
12
|
+
const msgType = broadcast ? "broadcast" : "direct";
|
|
13
|
+
let targets;
|
|
14
|
+
if (broadcast) {
|
|
15
|
+
const instances = await this.zk.listInstances();
|
|
16
|
+
targets = instances
|
|
17
|
+
.map((i) => i.id)
|
|
18
|
+
.filter((id) => id !== fromInstance);
|
|
19
|
+
}
|
|
20
|
+
else if (toInstance) {
|
|
21
|
+
targets = [toInstance];
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw new Error("Must specify to_instance or broadcast=true");
|
|
25
|
+
}
|
|
26
|
+
for (const targetId of targets) {
|
|
27
|
+
const msg = createMessage({
|
|
28
|
+
type: msgType,
|
|
29
|
+
from_instance: fromInstance,
|
|
30
|
+
from_name: fromName,
|
|
31
|
+
to_instance: targetId,
|
|
32
|
+
content,
|
|
33
|
+
});
|
|
34
|
+
const msgId = await this.zk.createMessage(targetId, msg);
|
|
35
|
+
msg.id = msgId;
|
|
36
|
+
messages.push(msg);
|
|
37
|
+
}
|
|
38
|
+
return messages;
|
|
39
|
+
}
|
|
40
|
+
async poll(instanceId) {
|
|
41
|
+
const raw = await this.zk.listMessages(instanceId);
|
|
42
|
+
const messages = [];
|
|
43
|
+
for (const [msgId, data] of raw) {
|
|
44
|
+
data.id = msgId;
|
|
45
|
+
const msg = MessageSchema.parse(data);
|
|
46
|
+
if (!msg.read) {
|
|
47
|
+
msg.read = true;
|
|
48
|
+
await this.zk.updateMessage(instanceId, msgId, msg);
|
|
49
|
+
}
|
|
50
|
+
messages.push(msg);
|
|
51
|
+
}
|
|
52
|
+
return messages;
|
|
53
|
+
}
|
|
54
|
+
async waitForMessage(instanceId, timeoutSeconds = 30) {
|
|
55
|
+
// First check if there are already messages
|
|
56
|
+
const existing = await this.poll(instanceId);
|
|
57
|
+
if (existing.length > 0)
|
|
58
|
+
return existing;
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
const timer = setTimeout(() => resolve([]), timeoutSeconds * 1000);
|
|
61
|
+
this.zk.watchMessageDir(instanceId, async () => {
|
|
62
|
+
clearTimeout(timer);
|
|
63
|
+
const msgs = await this.poll(instanceId);
|
|
64
|
+
resolve(msgs);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async markRead(instanceId, messageId) {
|
|
69
|
+
const data = await this.zk.getMessage(instanceId, messageId);
|
|
70
|
+
if (!data) {
|
|
71
|
+
throw new Error(`Message ${messageId} not found for instance ${instanceId}`);
|
|
72
|
+
}
|
|
73
|
+
data.read = true;
|
|
74
|
+
await this.zk.updateMessage(instanceId, messageId, data);
|
|
75
|
+
}
|
|
76
|
+
async dismissMessage(instanceId, messageId) {
|
|
77
|
+
await this.zk.deleteMessage(instanceId, messageId);
|
|
78
|
+
}
|
|
79
|
+
async requestHelp(fromInstance, fromName, question, ctx) {
|
|
80
|
+
let content = question;
|
|
81
|
+
if (ctx) {
|
|
82
|
+
content = `${question}\n\nContext:\n${ctx}`;
|
|
83
|
+
}
|
|
84
|
+
// Set message type to "help" by modifying after creation
|
|
85
|
+
const messages = await this.send(fromInstance, fromName, content, undefined, true);
|
|
86
|
+
// Update type to "help" for each message
|
|
87
|
+
for (const msg of messages) {
|
|
88
|
+
msg.type = "help";
|
|
89
|
+
await this.zk.updateMessage(msg.to_instance, msg.id, msg);
|
|
90
|
+
}
|
|
91
|
+
return messages;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=message-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-router.js","sourceRoot":"","sources":["../../src/modules/message-router.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,aAAa,GAGd,MAAM,sBAAsB,CAAC;AAE9B,SAAS,MAAM;IACb,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC;AAED,MAAM,OAAO,aAAa;IACJ;IAApB,YAAoB,EAAY;QAAZ,OAAE,GAAF,EA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zk/client.js";
|
|
2
|
+
import { type Instance } from "../models/schemas.js";
|
|
3
|
+
export declare class InstanceRegistry {
|
|
4
|
+
private zk;
|
|
5
|
+
constructor(zk: ZkClient);
|
|
6
|
+
register(name: string, role?: string, instanceId?: string): Promise<Instance>;
|
|
7
|
+
heartbeat(instanceId: string, currentTask?: string): Promise<void>;
|
|
8
|
+
get(instanceId: string): Promise<Instance | null>;
|
|
9
|
+
listAll(): Promise<Instance[]>;
|
|
10
|
+
unregister(instanceId: string): Promise<void>;
|
|
11
|
+
}
|