agent-comms 1.0.0 → 1.0.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.
Files changed (51) hide show
  1. package/README.md +108 -0
  2. package/bin.js +29 -0
  3. package/dist/bridges/claude-code/channel.d.ts +17 -0
  4. package/dist/bridges/claude-code/channel.d.ts.map +1 -0
  5. package/dist/bridges/claude-code/channel.js +143 -0
  6. package/dist/bridges/claude-code/channel.js.map +1 -0
  7. package/dist/bridges/codex/stop_hook.d.ts +13 -0
  8. package/dist/bridges/codex/stop_hook.d.ts.map +1 -0
  9. package/dist/bridges/codex/stop_hook.js +99 -0
  10. package/dist/bridges/codex/stop_hook.js.map +1 -0
  11. package/dist/bridges/codex/tool.d.ts +14 -0
  12. package/dist/bridges/codex/tool.d.ts.map +1 -0
  13. package/dist/bridges/codex/tool.js +71 -0
  14. package/dist/bridges/codex/tool.js.map +1 -0
  15. package/dist/bridges/opencode/plugin.d.ts +23 -0
  16. package/dist/bridges/opencode/plugin.d.ts.map +1 -0
  17. package/dist/bridges/opencode/plugin.js +73 -0
  18. package/dist/bridges/opencode/plugin.js.map +1 -0
  19. package/dist/bridges/pi/index.d.ts +11 -0
  20. package/dist/bridges/pi/index.d.ts.map +1 -0
  21. package/dist/bridges/pi/index.js +140 -0
  22. package/dist/bridges/pi/index.js.map +1 -0
  23. package/dist/cli.d.ts +16 -0
  24. package/dist/cli.d.ts.map +1 -0
  25. package/dist/cli.js +505 -0
  26. package/dist/cli.js.map +1 -0
  27. package/dist/core/bridge.d.ts +77 -0
  28. package/dist/core/bridge.d.ts.map +1 -0
  29. package/dist/core/bridge.js +224 -0
  30. package/dist/core/bridge.js.map +1 -0
  31. package/dist/core/index.d.ts +13 -0
  32. package/dist/core/index.d.ts.map +1 -0
  33. package/dist/core/index.js +11 -0
  34. package/dist/core/index.js.map +1 -0
  35. package/dist/core/nanoid.d.ts +6 -0
  36. package/dist/core/nanoid.d.ts.map +1 -0
  37. package/dist/core/nanoid.js +19 -0
  38. package/dist/core/nanoid.js.map +1 -0
  39. package/dist/core/store.d.ts +60 -0
  40. package/dist/core/store.d.ts.map +1 -0
  41. package/dist/core/store.js +431 -0
  42. package/dist/core/store.js.map +1 -0
  43. package/dist/core/tool.d.ts +40 -0
  44. package/dist/core/tool.d.ts.map +1 -0
  45. package/dist/core/tool.js +210 -0
  46. package/dist/core/tool.js.map +1 -0
  47. package/dist/core/types.d.ts +308 -0
  48. package/dist/core/types.d.ts.map +1 -0
  49. package/dist/core/types.js +168 -0
  50. package/dist/core/types.js.map +1 -0
  51. package/package.json +73 -8
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Tool handler — processes BusAction objects and returns human-readable results.
3
+ *
4
+ * This is the shared logic that every bridge calls into. Bridges just:
5
+ * 1. Parse the LLM's tool call into a BusAction
6
+ * 2. Call handleAction(action)
7
+ * 3. Return the result string to the LLM
8
+ */
9
+ import { BusError } from "./store.js";
10
+ export class BusTool {
11
+ store;
12
+ constructor(store) {
13
+ this.store = store;
14
+ }
15
+ async handle(ctx, action) {
16
+ try {
17
+ switch (action.action) {
18
+ case "register":
19
+ return await this.register(ctx, action);
20
+ case "update":
21
+ return await this.update(ctx, action);
22
+ case "whoami":
23
+ return await this.whoami(ctx);
24
+ case "create_room":
25
+ return await this.createRoom(ctx, action);
26
+ case "list_rooms":
27
+ return await this.listRooms(ctx);
28
+ case "join_room":
29
+ return await this.joinRoom(ctx, action);
30
+ case "leave_room":
31
+ return await this.leaveRoom(ctx, action);
32
+ case "send":
33
+ return await this.send(ctx, action);
34
+ case "dm":
35
+ return await this.dm(ctx, action);
36
+ case "list_agents":
37
+ return await this.listAgents(ctx);
38
+ case "read_room":
39
+ return await this.readRoom(ctx, action);
40
+ case "invite":
41
+ return await this.invite(ctx, action);
42
+ case "kick":
43
+ return await this.kick(ctx, action);
44
+ case "destroy_room":
45
+ return await this.destroyRoom(ctx, action);
46
+ default:
47
+ return {
48
+ content: `Unknown action: ${JSON.stringify(action).slice(0, 100)}`,
49
+ isError: true,
50
+ };
51
+ }
52
+ }
53
+ catch (err) {
54
+ if (err instanceof BusError) {
55
+ return {
56
+ content: `Error: ${err.message} (${err.code})`,
57
+ isError: true,
58
+ };
59
+ }
60
+ return {
61
+ content: `Internal error: ${err instanceof Error ? err.message : String(err)}`,
62
+ isError: true,
63
+ };
64
+ }
65
+ }
66
+ async register(ctx, action) {
67
+ const agent = await this.store.registerAgent({
68
+ name: action.name,
69
+ harness: ctx.harness,
70
+ pid: ctx.pid,
71
+ visibility: action.visibility,
72
+ tags: action.tags,
73
+ });
74
+ return {
75
+ content: `Registered as ${agent.name} (${agent.id}) with visibility "${agent.visibility}".`,
76
+ isError: false,
77
+ };
78
+ }
79
+ async update(ctx, action) {
80
+ const patch = {};
81
+ if (action.visibility !== undefined)
82
+ patch.visibility = action.visibility;
83
+ if (action.status !== undefined)
84
+ patch.status = action.status;
85
+ if (action.name !== undefined)
86
+ patch.name = action.name;
87
+ if (action.tags !== undefined)
88
+ patch.tags = action.tags;
89
+ const agent = await this.store.updateAgent(ctx.agentId, patch);
90
+ return {
91
+ content: `Updated: name=${agent.name}, visibility=${agent.visibility}, status=${agent.status}`,
92
+ isError: false,
93
+ };
94
+ }
95
+ async whoami(ctx) {
96
+ const agent = await this.store.getAgent(ctx.agentId);
97
+ if (!agent)
98
+ return { content: "Not registered.", isError: true };
99
+ return {
100
+ content: [
101
+ `ID: ${agent.id}`,
102
+ `Name: ${agent.name}`,
103
+ `Harness: ${agent.harness}`,
104
+ `Visibility: ${agent.visibility}`,
105
+ `Status: ${agent.status}`,
106
+ `Tags: ${agent.tags.join(", ") || "(none)"}`,
107
+ `Rooms: ${agent.subscribedRooms.join(", ") || "(none)"}`,
108
+ ].join("\n"),
109
+ isError: false,
110
+ };
111
+ }
112
+ async createRoom(ctx, action) {
113
+ const room = await this.store.createRoom({
114
+ name: action.name,
115
+ type: action.type,
116
+ owner: ctx.agentId,
117
+ description: action.description,
118
+ });
119
+ // Auto-join the creator
120
+ await this.store.joinRoom(room.id, ctx.agentId);
121
+ return {
122
+ content: `Created ${room.type} room "${room.name}" (${room.id}).`,
123
+ isError: false,
124
+ };
125
+ }
126
+ async listRooms(ctx) {
127
+ const rooms = await this.store.listRooms(ctx.agentId);
128
+ if (rooms.length === 0)
129
+ return { content: "No rooms found.", isError: false };
130
+ const lines = rooms.map((r) => {
131
+ const memberFlag = r.members.includes(ctx.agentId) ? "✓" : " ";
132
+ return `[${memberFlag}] ${r.type.padEnd(7)} ${r.name} (${String(r.members.length)} members) — ${r.description}`;
133
+ });
134
+ return {
135
+ content: `Rooms ([✓] = joined):\n${lines.join("\n")}`,
136
+ isError: false,
137
+ };
138
+ }
139
+ async joinRoom(ctx, action) {
140
+ const roomId = action.room;
141
+ const room = await this.store.joinRoom(roomId, ctx.agentId);
142
+ return {
143
+ content: `Joined room "${room.name}" (${String(room.members.length)} members).`,
144
+ isError: false,
145
+ };
146
+ }
147
+ async leaveRoom(ctx, action) {
148
+ await this.store.leaveRoom(action.room, ctx.agentId);
149
+ return { content: `Left room "${action.room}".`, isError: false };
150
+ }
151
+ async send(ctx, action) {
152
+ const roomId = action.target;
153
+ const msg = await this.store.sendRoomMessage(roomId, ctx.agentId, action.content, action.replyTo);
154
+ return {
155
+ content: `Sent to ${action.target}: ${msg.id}`,
156
+ isError: false,
157
+ };
158
+ }
159
+ async dm(ctx, action) {
160
+ const targetId = action.target;
161
+ const msg = await this.store.sendDm(ctx.agentId, targetId, action.content);
162
+ return {
163
+ content: `DM sent to ${action.target}: ${msg.id}`,
164
+ isError: false,
165
+ };
166
+ }
167
+ async listAgents(ctx) {
168
+ const agents = await this.store.listAgents(ctx.agentId);
169
+ if (agents.length === 0)
170
+ return { content: "No other agents online.", isError: false };
171
+ const lines = agents.map((a) => {
172
+ const self = a.id === ctx.agentId ? " (you)" : "";
173
+ return `${a.id} ${a.name.padEnd(25)} ${a.harness.padEnd(12)} ${a.status.padEnd(7)} ${a.visibility}${self}`;
174
+ });
175
+ return {
176
+ content: `Agents:\n ID Name Harness Status Visibility\n${lines.map((l) => ` ${l}`).join("\n")}`,
177
+ isError: false,
178
+ };
179
+ }
180
+ async readRoom(ctx, action) {
181
+ const roomId = action.room;
182
+ const messages = await this.store.readRoomMessages(roomId, action.since);
183
+ if (messages.length === 0)
184
+ return { content: "No messages.", isError: false };
185
+ const lines = messages.map((m) => {
186
+ const time = m.timestamp.slice(11, 19);
187
+ return `[${time}] ${m.from}: ${m.content}`;
188
+ });
189
+ return { content: lines.join("\n"), isError: false };
190
+ }
191
+ async invite(ctx, action) {
192
+ await this.store.inviteToRoom(action.room, action.agent, ctx.agentId);
193
+ return {
194
+ content: `Invited ${action.agent} to ${action.room}.`,
195
+ isError: false,
196
+ };
197
+ }
198
+ async kick(ctx, action) {
199
+ await this.store.kickFromRoom(action.room, action.agent, ctx.agentId);
200
+ return {
201
+ content: `Kicked ${action.agent} from ${action.room}.`,
202
+ isError: false,
203
+ };
204
+ }
205
+ async destroyRoom(ctx, action) {
206
+ await this.store.destroyRoom(action.room, ctx.agentId);
207
+ return { content: `Destroyed room "${action.room}".`, isError: false };
208
+ }
209
+ }
210
+ //# sourceMappingURL=tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/core/tool.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,OAAO,EAAY,QAAQ,EAAE,MAAM,YAAY,CAAC;AAchD,MAAM,OAAO,OAAO;IACW;IAA7B,YAA6B,KAAe;QAAf,UAAK,GAAL,KAAK,CAAU;IAAG,CAAC;IAEhD,KAAK,CAAC,MAAM,CAAC,GAAgB,EAAE,MAAiB;QAC9C,IAAI,CAAC;YACH,QAAQ,MAAM,CAAC,MAAM,EAAE,CAAC;gBACtB,KAAK,UAAU;oBACb,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;gBAC1C,KAAK,QAAQ;oBACX,OAAO,MAAM,IAA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,CAAC;IAEO,KAAK,CAAC,WAAW,CACvB,GAAgB,EAChB,MAA8C;QAE9C,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QACvD,OAAO,EAAE,OAAO,EAAE,mBAAmB,MAAM,CAAC,IAAI,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IACzE,CAAC;CACF"}
@@ -0,0 +1,308 @@
1
+ /**
2
+ * Agent Comms — shared protocol types and Zod schemas.
3
+ *
4
+ * Every type is derived from its Zod schema (single source of truth).
5
+ * Use `Schema.parse(raw)` at JSON boundaries instead of `JSON.parse(raw) as T`.
6
+ * Use `Schema.is(value)` for type narrowing.
7
+ */
8
+ import { z } from "zod";
9
+ export type AgentId = string;
10
+ export type RoomId = string;
11
+ export declare const Visibility: z.ZodUnion<readonly [z.ZodLiteral<"visible">, z.ZodLiteral<"hidden">, z.ZodLiteral<"ghost">]> & {
12
+ is(value: unknown): value is "visible" | "hidden" | "ghost";
13
+ };
14
+ export type Visibility = z.infer<typeof Visibility>;
15
+ export declare const AgentStatus: z.ZodUnion<readonly [z.ZodLiteral<"active">, z.ZodLiteral<"idle">, z.ZodLiteral<"busy">, z.ZodLiteral<"offline">]> & {
16
+ is(value: unknown): value is "active" | "idle" | "busy" | "offline";
17
+ };
18
+ export type AgentStatus = z.infer<typeof AgentStatus>;
19
+ export declare const RoomType: z.ZodUnion<readonly [z.ZodLiteral<"public">, z.ZodLiteral<"private">, z.ZodLiteral<"secret">]> & {
20
+ is(value: unknown): value is "public" | "private" | "secret";
21
+ };
22
+ export type RoomType = z.infer<typeof RoomType>;
23
+ export declare const AgentIdentitySchema: z.ZodObject<{
24
+ id: z.ZodString;
25
+ name: z.ZodString;
26
+ harness: z.ZodString;
27
+ pid: z.ZodNumber;
28
+ startedAt: z.ZodString;
29
+ visibility: z.ZodUnion<readonly [z.ZodLiteral<"visible">, z.ZodLiteral<"hidden">, z.ZodLiteral<"ghost">]> & {
30
+ is(value: unknown): value is "visible" | "hidden" | "ghost";
31
+ };
32
+ status: z.ZodUnion<readonly [z.ZodLiteral<"active">, z.ZodLiteral<"idle">, z.ZodLiteral<"busy">, z.ZodLiteral<"offline">]> & {
33
+ is(value: unknown): value is "active" | "idle" | "busy" | "offline";
34
+ };
35
+ tags: z.ZodArray<z.ZodString>;
36
+ subscribedRooms: z.ZodArray<z.ZodString>;
37
+ }, z.core.$strip> & {
38
+ is(value: unknown): value is {
39
+ id: string;
40
+ name: string;
41
+ harness: string;
42
+ pid: number;
43
+ startedAt: string;
44
+ visibility: "visible" | "hidden" | "ghost";
45
+ status: "active" | "idle" | "busy" | "offline";
46
+ tags: string[];
47
+ subscribedRooms: string[];
48
+ };
49
+ };
50
+ export type AgentIdentity = z.infer<typeof AgentIdentitySchema>;
51
+ export declare const RoomSchema: z.ZodObject<{
52
+ id: z.ZodString;
53
+ name: z.ZodString;
54
+ type: z.ZodUnion<readonly [z.ZodLiteral<"public">, z.ZodLiteral<"private">, z.ZodLiteral<"secret">]> & {
55
+ is(value: unknown): value is "public" | "private" | "secret";
56
+ };
57
+ owner: z.ZodString;
58
+ createdAt: z.ZodString;
59
+ description: z.ZodString;
60
+ members: z.ZodArray<z.ZodString>;
61
+ invited: z.ZodArray<z.ZodString>;
62
+ }, z.core.$strip> & {
63
+ is(value: unknown): value is {
64
+ id: string;
65
+ name: string;
66
+ type: "public" | "private" | "secret";
67
+ owner: string;
68
+ createdAt: string;
69
+ description: string;
70
+ members: string[];
71
+ invited: string[];
72
+ };
73
+ };
74
+ export type Room = z.infer<typeof RoomSchema>;
75
+ export declare const RoomMessageSchema: z.ZodObject<{
76
+ id: z.ZodString;
77
+ from: z.ZodString;
78
+ room: z.ZodString;
79
+ content: z.ZodString;
80
+ timestamp: z.ZodString;
81
+ replyTo: z.ZodOptional<z.ZodString>;
82
+ }, z.core.$strip> & {
83
+ is(value: unknown): value is {
84
+ id: string;
85
+ from: string;
86
+ room: string;
87
+ content: string;
88
+ timestamp: string;
89
+ replyTo?: string | undefined;
90
+ };
91
+ };
92
+ export type RoomMessage = z.infer<typeof RoomMessageSchema>;
93
+ export declare const DmMessageSchema: z.ZodObject<{
94
+ id: z.ZodString;
95
+ from: z.ZodString;
96
+ to: z.ZodString;
97
+ content: z.ZodString;
98
+ timestamp: z.ZodString;
99
+ }, z.core.$strip> & {
100
+ is(value: unknown): value is {
101
+ id: string;
102
+ from: string;
103
+ to: string;
104
+ content: string;
105
+ timestamp: string;
106
+ };
107
+ };
108
+ export type DmMessage = z.infer<typeof DmMessageSchema>;
109
+ export declare const DeliveryEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
110
+ type: z.ZodLiteral<"room_message">;
111
+ message: z.ZodObject<{
112
+ id: z.ZodString;
113
+ from: z.ZodString;
114
+ room: z.ZodString;
115
+ content: z.ZodString;
116
+ timestamp: z.ZodString;
117
+ replyTo: z.ZodOptional<z.ZodString>;
118
+ }, z.core.$strip> & {
119
+ is(value: unknown): value is {
120
+ id: string;
121
+ from: string;
122
+ room: string;
123
+ content: string;
124
+ timestamp: string;
125
+ replyTo?: string | undefined;
126
+ };
127
+ };
128
+ }, z.core.$strip>, z.ZodObject<{
129
+ type: z.ZodLiteral<"dm">;
130
+ message: z.ZodObject<{
131
+ id: z.ZodString;
132
+ from: z.ZodString;
133
+ to: z.ZodString;
134
+ content: z.ZodString;
135
+ timestamp: z.ZodString;
136
+ }, z.core.$strip> & {
137
+ is(value: unknown): value is {
138
+ id: string;
139
+ from: string;
140
+ to: string;
141
+ content: string;
142
+ timestamp: string;
143
+ };
144
+ };
145
+ }, z.core.$strip>, z.ZodObject<{
146
+ type: z.ZodLiteral<"room_invite">;
147
+ room: z.ZodString;
148
+ from: z.ZodString;
149
+ }, z.core.$strip>, z.ZodObject<{
150
+ type: z.ZodLiteral<"member_joined">;
151
+ room: z.ZodString;
152
+ agent: z.ZodString;
153
+ }, z.core.$strip>, z.ZodObject<{
154
+ type: z.ZodLiteral<"member_left">;
155
+ room: z.ZodString;
156
+ agent: z.ZodString;
157
+ }, z.core.$strip>], "type"> & {
158
+ is(value: unknown): value is {
159
+ type: "room_message";
160
+ message: {
161
+ id: string;
162
+ from: string;
163
+ room: string;
164
+ content: string;
165
+ timestamp: string;
166
+ replyTo?: string | undefined;
167
+ };
168
+ } | {
169
+ type: "dm";
170
+ message: {
171
+ id: string;
172
+ from: string;
173
+ to: string;
174
+ content: string;
175
+ timestamp: string;
176
+ };
177
+ } | {
178
+ type: "room_invite";
179
+ room: string;
180
+ from: string;
181
+ } | {
182
+ type: "member_joined";
183
+ room: string;
184
+ agent: string;
185
+ } | {
186
+ type: "member_left";
187
+ room: string;
188
+ agent: string;
189
+ };
190
+ };
191
+ export type DeliveryEvent = z.infer<typeof DeliveryEventSchema>;
192
+ export declare const BusActionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
193
+ action: z.ZodLiteral<"register">;
194
+ name: z.ZodString;
195
+ visibility: z.ZodUnion<readonly [z.ZodLiteral<"visible">, z.ZodLiteral<"hidden">, z.ZodLiteral<"ghost">]> & {
196
+ is(value: unknown): value is "visible" | "hidden" | "ghost";
197
+ };
198
+ tags: z.ZodArray<z.ZodString>;
199
+ }, z.core.$strip>, z.ZodObject<{
200
+ action: z.ZodLiteral<"update">;
201
+ visibility: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"visible">, z.ZodLiteral<"hidden">, z.ZodLiteral<"ghost">]> & {
202
+ is(value: unknown): value is "visible" | "hidden" | "ghost";
203
+ }>;
204
+ status: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"active">, z.ZodLiteral<"idle">, z.ZodLiteral<"busy">, z.ZodLiteral<"offline">]> & {
205
+ is(value: unknown): value is "active" | "idle" | "busy" | "offline";
206
+ }>;
207
+ name: z.ZodOptional<z.ZodString>;
208
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
209
+ }, z.core.$strip>, z.ZodObject<{
210
+ action: z.ZodLiteral<"whoami">;
211
+ }, z.core.$strip>, z.ZodObject<{
212
+ action: z.ZodLiteral<"create_room">;
213
+ name: z.ZodString;
214
+ type: z.ZodUnion<readonly [z.ZodLiteral<"public">, z.ZodLiteral<"private">, z.ZodLiteral<"secret">]> & {
215
+ is(value: unknown): value is "public" | "private" | "secret";
216
+ };
217
+ description: z.ZodString;
218
+ }, z.core.$strip>, z.ZodObject<{
219
+ action: z.ZodLiteral<"list_rooms">;
220
+ }, z.core.$strip>, z.ZodObject<{
221
+ action: z.ZodLiteral<"join_room">;
222
+ room: z.ZodString;
223
+ }, z.core.$strip>, z.ZodObject<{
224
+ action: z.ZodLiteral<"leave_room">;
225
+ room: z.ZodString;
226
+ }, z.core.$strip>, z.ZodObject<{
227
+ action: z.ZodLiteral<"send">;
228
+ target: z.ZodString;
229
+ content: z.ZodString;
230
+ replyTo: z.ZodOptional<z.ZodString>;
231
+ }, z.core.$strip>, z.ZodObject<{
232
+ action: z.ZodLiteral<"dm">;
233
+ target: z.ZodString;
234
+ content: z.ZodString;
235
+ }, z.core.$strip>, z.ZodObject<{
236
+ action: z.ZodLiteral<"list_agents">;
237
+ }, z.core.$strip>, z.ZodObject<{
238
+ action: z.ZodLiteral<"read_room">;
239
+ room: z.ZodString;
240
+ since: z.ZodOptional<z.ZodString>;
241
+ }, z.core.$strip>, z.ZodObject<{
242
+ action: z.ZodLiteral<"invite">;
243
+ room: z.ZodString;
244
+ agent: z.ZodString;
245
+ }, z.core.$strip>, z.ZodObject<{
246
+ action: z.ZodLiteral<"kick">;
247
+ room: z.ZodString;
248
+ agent: z.ZodString;
249
+ }, z.core.$strip>, z.ZodObject<{
250
+ action: z.ZodLiteral<"destroy_room">;
251
+ room: z.ZodString;
252
+ }, z.core.$strip>], "action"> & {
253
+ is(value: unknown): value is {
254
+ action: "register";
255
+ name: string;
256
+ visibility: "visible" | "hidden" | "ghost";
257
+ tags: string[];
258
+ } | {
259
+ action: "update";
260
+ visibility?: "visible" | "hidden" | "ghost" | undefined;
261
+ status?: "active" | "idle" | "busy" | "offline" | undefined;
262
+ name?: string | undefined;
263
+ tags?: string[] | undefined;
264
+ } | {
265
+ action: "whoami";
266
+ } | {
267
+ action: "create_room";
268
+ name: string;
269
+ type: "public" | "private" | "secret";
270
+ description: string;
271
+ } | {
272
+ action: "list_rooms";
273
+ } | {
274
+ action: "join_room";
275
+ room: string;
276
+ } | {
277
+ action: "leave_room";
278
+ room: string;
279
+ } | {
280
+ action: "send";
281
+ target: string;
282
+ content: string;
283
+ replyTo?: string | undefined;
284
+ } | {
285
+ action: "dm";
286
+ target: string;
287
+ content: string;
288
+ } | {
289
+ action: "list_agents";
290
+ } | {
291
+ action: "read_room";
292
+ room: string;
293
+ since?: string | undefined;
294
+ } | {
295
+ action: "invite";
296
+ room: string;
297
+ agent: string;
298
+ } | {
299
+ action: "kick";
300
+ room: string;
301
+ agent: string;
302
+ } | {
303
+ action: "destroy_room";
304
+ room: string;
305
+ };
306
+ };
307
+ export type BusAction = z.infer<typeof BusActionSchema>;
308
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAqBxB,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAC7B,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAM5B,eAAO,MAAM,UAAU;cApBT,OAAO,GAAG,KAAK,kCAAc;CAsB1C,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAEpD,eAAO,MAAM,WAAW;cAzBV,OAAO,GAAG,KAAK,0CAAc;CAgC1C,CAAC;AACF,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEtD,eAAO,MAAM,QAAQ;cA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