agent-comms 3.26.0 → 3.28.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -1
- package/dist/bridges/user/web/dist/bundle.js +12 -12
- package/dist/bridges/user/web/dist/mesh-worker.js +4 -4
- package/dist/bridges/user/web/dist/sw.js +1 -1
- package/dist/bridges/user/web/frontend/api.d.ts +3 -19
- package/dist/bridges/user/web/frontend/api.d.ts.map +1 -1
- package/dist/bridges/user/web/frontend/api.js +2 -62
- package/dist/bridges/user/web/frontend/api.js.map +1 -1
- package/dist/bridges/user/web/frontend/dispatch-action.d.ts +10 -0
- package/dist/bridges/user/web/frontend/dispatch-action.d.ts.map +1 -0
- package/dist/bridges/user/web/frontend/dispatch-action.js +62 -0
- package/dist/bridges/user/web/frontend/dispatch-action.js.map +1 -0
- package/dist/bridges/user/web/frontend/main.js +36 -65
- package/dist/bridges/user/web/frontend/main.js.map +1 -1
- package/dist/bridges/user/web/frontend/mesh-client.d.ts +23 -16
- package/dist/bridges/user/web/frontend/mesh-client.d.ts.map +1 -1
- package/dist/bridges/user/web/frontend/mesh-client.js +173 -80
- package/dist/bridges/user/web/frontend/mesh-client.js.map +1 -1
- package/dist/bridges/user/web/frontend/mesh-worker.d.ts.map +1 -1
- package/dist/bridges/user/web/frontend/mesh-worker.js +6 -58
- package/dist/bridges/user/web/frontend/mesh-worker.js.map +1 -1
- package/dist/bridges/user/web/frontend/state.d.ts +0 -2
- package/dist/bridges/user/web/frontend/state.d.ts.map +1 -1
- package/dist/bridges/user/web/frontend/state.js +0 -5
- package/dist/bridges/user/web/frontend/state.js.map +1 -1
- package/dist/bridges/user/web/frontend/types.d.ts +0 -14
- package/dist/bridges/user/web/frontend/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=`agent-comms-v1`,t=[{"revision":"
|
|
1
|
+
var e=`agent-comms-v1`,t=[{"revision":"8a4992468857b25c713cb4e44a32c2c1","url":"mesh-worker.js"},{"revision":"f1ee3afb8c9e8f0d7315fd93d6457316","url":"index.html"},{"revision":"36c03e56733856c1b2136805b421e1b0","url":"bundle.js"}].map(e=>e.url);self.addEventListener(`install`,n=>{n.waitUntil(self.caches.open(e).then(async e=>e.addAll(t)).then(async()=>self.skipWaiting()))}),self.addEventListener(`activate`,t=>{t.waitUntil(self.caches.keys().then(async t=>Promise.all(t.filter(t=>t!==e).map(async e=>self.caches.delete(e)))))});var n=200,r=300;function i(e,t){return e.method===`GET`&&t.status>=n&&t.status<r}self.addEventListener(`fetch`,t=>{if(new URL(t.request.url).pathname.startsWith(`/api/`)){t.respondWith(fetch(t.request).then(n=>{if(i(t.request,n)){let r=n.clone();self.caches.open(e).then(async e=>e.put(t.request,r))}return n}).catch(async()=>self.caches.open(e).then(async e=>e.match(t.request)).then(e=>e??new Response(`Offline`,{status:503}))));return}t.respondWith(self.caches.open(e).then(async e=>e.match(t.request)).then(async n=>n||fetch(t.request).then(n=>{if(i(t.request,n)){let r=n.clone();self.caches.open(e).then(async e=>e.put(t.request,r))}return n})))}),self.addEventListener(`push`,e=>{let t=`Agent Comms`,n=`New message`;if(e.data)try{let r=e.data.json();typeof r.title==`string`&&(t=r.title),typeof r.body==`string`&&(n=r.body)}catch{let t=e.data.text();t&&(n=t)}e.waitUntil(self.registration.showNotification(t,{body:n,data:{url:self.location.origin}}))}),self.addEventListener(`notificationclick`,e=>{e.notification.close();let t=e.notification.data,n=typeof t==`object`&&t&&`url`in t&&typeof t.url==`string`?t.url:self.location.origin;e.waitUntil(self.clients.matchAll({type:`window`,includeUncontrolled:!0}).then(async e=>{for(let t of e)if(t.url===n&&`focus`in t)return t.focus();return self.clients.openWindow(n)}))});
|
|
@@ -1,31 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* API client — typed REST
|
|
2
|
+
* API client — typed REST communication with the comms server.
|
|
3
3
|
*
|
|
4
|
-
* REST for initial data fetches
|
|
5
|
-
* All methods are typed against the interfaces in types.ts.
|
|
4
|
+
* REST for initial data fetches and the /api/action test-scaffolding endpoint. Real-time state, patches, actions, and delivery events all go through MeshClient/mesh-client.ts's own oRPC client now -- this file no longer carries a WebSocket client of its own. All methods are typed against the interfaces in types.ts.
|
|
6
5
|
*
|
|
7
6
|
* JSON boundaries use runtime validation with type predicates — no assertions.
|
|
8
7
|
*/
|
|
9
|
-
import type { Action, ActionResult, AgentsResponse, MeshGraph, MeshTraceResult, MessagesResponse, RoomsResponse
|
|
8
|
+
import type { Action, ActionResult, AgentsResponse, MeshGraph, MeshTraceResult, MessagesResponse, RoomsResponse } from "./types.js";
|
|
10
9
|
export declare function fetchAgents(): Promise<AgentsResponse>;
|
|
11
10
|
export declare function fetchRooms(): Promise<RoomsResponse>;
|
|
12
11
|
export declare function fetchRoomMessages(roomId: string, since?: string): Promise<MessagesResponse>;
|
|
13
12
|
export declare function fetchMeshGraph(): Promise<MeshGraph>;
|
|
14
13
|
export declare function fetchMeshTrace(target: string, timeoutMs?: number): Promise<MeshTraceResult>;
|
|
15
14
|
export declare function postAction(action: Action): Promise<ActionResult>;
|
|
16
|
-
export interface WsEventHandler {
|
|
17
|
-
onOpen?: () => void;
|
|
18
|
-
onClose?: () => void;
|
|
19
|
-
onFrame?: (frame: WsFrame) => void;
|
|
20
|
-
}
|
|
21
|
-
export declare class CommsWs {
|
|
22
|
-
private ws;
|
|
23
|
-
private reconnectTimer;
|
|
24
|
-
private readonly handler;
|
|
25
|
-
constructor(handler: Readonly<WsEventHandler>);
|
|
26
|
-
connect(): void;
|
|
27
|
-
sendAction(action: Action): void;
|
|
28
|
-
disconnect(): void;
|
|
29
|
-
private scheduleReconnect;
|
|
30
|
-
}
|
|
31
15
|
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../../../src/bridges/user/web/frontend/api.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../../../src/bridges/user/web/frontend/api.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,MAAM,EACN,YAAY,EACZ,cAAc,EACd,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,aAAa,EACd,MAAM,YAAY,CAAC;AA+CpB,wBAAsB,WAAW,IAAI,OAAO,CAAC,cAAc,CAAC,CAK3D;AAED,wBAAsB,UAAU,IAAI,OAAO,CAAC,aAAa,CAAC,CAKzD;AAED,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,gBAAgB,CAAC,CAS3B;AAaD,wBAAsB,cAAc,IAAI,OAAO,CAAC,SAAS,CAAC,CAMzD;AAED,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,CAAC,CAQ1B;AAED,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAStE"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* API client — typed REST
|
|
2
|
+
* API client — typed REST communication with the comms server.
|
|
3
3
|
*
|
|
4
|
-
* REST for initial data fetches
|
|
5
|
-
* All methods are typed against the interfaces in types.ts.
|
|
4
|
+
* REST for initial data fetches and the /api/action test-scaffolding endpoint. Real-time state, patches, actions, and delivery events all go through MeshClient/mesh-client.ts's own oRPC client now -- this file no longer carries a WebSocket client of its own. All methods are typed against the interfaces in types.ts.
|
|
6
5
|
*
|
|
7
6
|
* JSON boundaries use runtime validation with type predicates — no assertions.
|
|
8
7
|
*/
|
|
@@ -26,9 +25,6 @@ function isActionResult(value) {
|
|
|
26
25
|
return false;
|
|
27
26
|
return (typeof value.content === "string" && typeof value.isError === "boolean");
|
|
28
27
|
}
|
|
29
|
-
function isWsFrame(value) {
|
|
30
|
-
return isObject(value) && typeof value.type === "string";
|
|
31
|
-
}
|
|
32
28
|
function isMeshGraph(value) {
|
|
33
29
|
return (isObject(value) && Array.isArray(value.nodes) && Array.isArray(value.edges));
|
|
34
30
|
}
|
|
@@ -114,60 +110,4 @@ export async function postAction(action) {
|
|
|
114
110
|
throw new Error("Invalid action result");
|
|
115
111
|
return body;
|
|
116
112
|
}
|
|
117
|
-
// ---------------------------------------------------------------------------
|
|
118
|
-
// WebSocket client
|
|
119
|
-
// ---------------------------------------------------------------------------
|
|
120
|
-
/** Delay before attempting to reconnect a dropped WebSocket connection. */
|
|
121
|
-
const RECONNECT_DELAY_MS = 3000;
|
|
122
|
-
export class CommsWs {
|
|
123
|
-
ws;
|
|
124
|
-
reconnectTimer;
|
|
125
|
-
handler;
|
|
126
|
-
constructor(handler) {
|
|
127
|
-
this.handler = handler;
|
|
128
|
-
}
|
|
129
|
-
connect() {
|
|
130
|
-
const proto = location.protocol === "https:" ? "wss:" : "ws:";
|
|
131
|
-
const ws = new WebSocket(`${proto}//${location.host}`);
|
|
132
|
-
this.ws = ws;
|
|
133
|
-
ws.onopen = () => {
|
|
134
|
-
this.handler.onOpen?.();
|
|
135
|
-
};
|
|
136
|
-
ws.onclose = () => {
|
|
137
|
-
this.handler.onClose?.();
|
|
138
|
-
this.scheduleReconnect();
|
|
139
|
-
};
|
|
140
|
-
ws.onerror = () => {
|
|
141
|
-
// onclose will fire after this
|
|
142
|
-
};
|
|
143
|
-
ws.onmessage = (e) => {
|
|
144
|
-
const raw = JSON.parse(typeof e.data === "string" ? e.data : String(e.data));
|
|
145
|
-
if (!isWsFrame(raw))
|
|
146
|
-
return;
|
|
147
|
-
this.handler.onFrame?.(raw);
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
sendAction(action) {
|
|
151
|
-
const ws = this.ws;
|
|
152
|
-
if (ws?.readyState === WebSocket.OPEN) {
|
|
153
|
-
ws.send(JSON.stringify(action));
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
disconnect() {
|
|
157
|
-
if (this.reconnectTimer !== undefined) {
|
|
158
|
-
clearTimeout(this.reconnectTimer);
|
|
159
|
-
this.reconnectTimer = undefined;
|
|
160
|
-
}
|
|
161
|
-
const ws = this.ws;
|
|
162
|
-
if (ws) {
|
|
163
|
-
ws.close();
|
|
164
|
-
}
|
|
165
|
-
this.ws = undefined;
|
|
166
|
-
}
|
|
167
|
-
scheduleReconnect() {
|
|
168
|
-
this.reconnectTimer = setTimeout(() => {
|
|
169
|
-
this.connect();
|
|
170
|
-
}, RECONNECT_DELAY_MS);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
113
|
//# sourceMappingURL=api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../../src/bridges/user/web/frontend/api.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../../src/bridges/user/web/frontend/api.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,8EAA8E;AAC9E,qDAAqD;AACrD,8EAA8E;AAE9E,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAc;IACxC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IACpC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KA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uB,CAAC,CAAC;IACpE,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps a legacy flat action object (`{action: "send", target, content}`, matching the browser Action union in types.ts) onto a call against the matching named oRPC procedure.
|
|
3
|
+
*
|
|
4
|
+
* Generic over any client built from a contract that includes meshContract's own 13 action procedures -- both mesh-worker.ts's upstream client (MeshOrpcClient, built from the real server's meshContract) and mesh-client.ts's own client (built from tab-contract.ts's TabContract, which spreads meshContract's procedures verbatim) satisfy this structurally, so the same mapping serves both call sites instead of being hand-duplicated a second time.
|
|
5
|
+
*/
|
|
6
|
+
import type { ContractRouterClient } from "@orpc/contract";
|
|
7
|
+
import type { meshContract, ActionResult } from "../contract.js";
|
|
8
|
+
export type ActionDispatchClient = Pick<ContractRouterClient<typeof meshContract>, "send" | "dm" | "joinRoom" | "leaveRoom" | "createRoom" | "listRooms" | "listAgents" | "readRoom" | "destroyRoom" | "invite" | "declineInvite" | "kick" | "renameAgent">;
|
|
9
|
+
export declare function dispatchAction(client: Readonly<ActionDispatchClient>, action: Readonly<Record<string, unknown>>): Promise<ActionResult>;
|
|
10
|
+
//# sourceMappingURL=dispatch-action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch-action.d.ts","sourceRoot":"","sources":["../../../../../src/bridges/user/web/frontend/dispatch-action.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEjE,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,oBAAoB,CAAC,OAAO,YAAY,CAAC,EACvC,MAAM,GACN,IAAI,GACJ,UAAU,GACV,WAAW,GACX,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,UAAU,GACV,aAAa,GACb,QAAQ,GACR,eAAe,GACf,MAAM,GACN,aAAa,CAChB,CAAC;AAEF,wBAAsB,cAAc,CAClC,MAAM,EAAE,QAAQ,CAAC,oBAAoB,CAAC,EACtC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACxC,OAAO,CAAC,YAAY,CAAC,CAwDvB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps a legacy flat action object (`{action: "send", target, content}`, matching the browser Action union in types.ts) onto a call against the matching named oRPC procedure.
|
|
3
|
+
*
|
|
4
|
+
* Generic over any client built from a contract that includes meshContract's own 13 action procedures -- both mesh-worker.ts's upstream client (MeshOrpcClient, built from the real server's meshContract) and mesh-client.ts's own client (built from tab-contract.ts's TabContract, which spreads meshContract's procedures verbatim) satisfy this structurally, so the same mapping serves both call sites instead of being hand-duplicated a second time.
|
|
5
|
+
*/
|
|
6
|
+
export async function dispatchAction(client, action) {
|
|
7
|
+
const str = (key) => {
|
|
8
|
+
const value = action[key];
|
|
9
|
+
return typeof value === "string" ? value : "";
|
|
10
|
+
};
|
|
11
|
+
const optStr = (key) => {
|
|
12
|
+
const value = action[key];
|
|
13
|
+
return typeof value === "string" ? value : undefined;
|
|
14
|
+
};
|
|
15
|
+
const roomType = () => {
|
|
16
|
+
const value = action.type;
|
|
17
|
+
return value === "public" || value === "private" || value === "secret"
|
|
18
|
+
? value
|
|
19
|
+
: "public";
|
|
20
|
+
};
|
|
21
|
+
switch (action.action) {
|
|
22
|
+
case "send":
|
|
23
|
+
return client.send({ target: str("target"), content: str("content") });
|
|
24
|
+
case "dm":
|
|
25
|
+
return client.dm({ target: str("target"), content: str("content") });
|
|
26
|
+
case "join_room":
|
|
27
|
+
return client.joinRoom({ room: str("room") });
|
|
28
|
+
case "leave_room":
|
|
29
|
+
return client.leaveRoom({ room: optStr("room") });
|
|
30
|
+
case "create_room":
|
|
31
|
+
return client.createRoom({
|
|
32
|
+
name: str("name"),
|
|
33
|
+
type: roomType(),
|
|
34
|
+
description: optStr("description"),
|
|
35
|
+
});
|
|
36
|
+
case "list_rooms":
|
|
37
|
+
return client.listRooms({});
|
|
38
|
+
case "list_agents":
|
|
39
|
+
return client.listAgents({});
|
|
40
|
+
case "read_room":
|
|
41
|
+
return client.readRoom({ room: optStr("room") });
|
|
42
|
+
case "destroy_room":
|
|
43
|
+
return client.destroyRoom({ room: str("room") });
|
|
44
|
+
case "invite":
|
|
45
|
+
return client.invite({ room: str("room"), agent: str("agent") });
|
|
46
|
+
case "decline_invite":
|
|
47
|
+
return client.declineInvite({
|
|
48
|
+
room: str("room"),
|
|
49
|
+
reason: str("reason"),
|
|
50
|
+
});
|
|
51
|
+
case "kick":
|
|
52
|
+
return client.kick({ room: str("room"), agent: str("agent") });
|
|
53
|
+
case "rename_agent":
|
|
54
|
+
return client.renameAgent({ agent: str("agent"), name: str("name") });
|
|
55
|
+
default:
|
|
56
|
+
return {
|
|
57
|
+
content: `Unknown action: ${String(action.action)}`,
|
|
58
|
+
isError: true,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=dispatch-action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch-action.js","sourceRoot":"","sources":["../../../../../src/bridges/user/web/frontend/dispatch-action.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAsBH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAAsC,EACtC,MAAyC;IAEzC,MAAM,GAAG,GAAG,CAAC,GAAW,EAAU,EAAE;QAClC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAChD,CAAC,CAAC;IACF,MAAM,MAAM,GAAG,CAAC,GAAW,EAAsB,EAAE;QACjD,MAAM,KAAK,GAAG,MAAM,CAAC,GAA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,OAAO,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QAC/B,KAAK,WAAW;YACd,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACnD,KAAK,cAAc;YACjB,OAAO,MAAM,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACnD,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACnE,KAAK,gBAAgB;YACnB,OAAO,MAAM,CAAC,aAAa,CAAC;gBAC1B,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC;gBACjB,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC;aACtB,CAAC,CAAC;QACL,KAAK,MAAM;YACT,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACjE,KAAK,cAAc;YACjB,OAAO,MAAM,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACxE;YACE,OAAO;gBACL,OAAO,EAAE,mBAAmB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;gBACnD,OAAO,EAAE,IAAI;aACd,CAAC;IACN,CAAC;AACH,CAAC"}
|
|
@@ -9,7 +9,7 @@ import { createRoot } from "react-dom/client";
|
|
|
9
9
|
import { MantineProvider } from "@mantine/core";
|
|
10
10
|
import { useEffect } from "react";
|
|
11
11
|
import { App } from "./components/App.js";
|
|
12
|
-
import {
|
|
12
|
+
import { fetchAgents, fetchMeshGraph, fetchRoomMessages, fetchRooms, } from "./api.js";
|
|
13
13
|
import { parseInput, routeAction } from "./input.js";
|
|
14
14
|
import { State } from "./state.js";
|
|
15
15
|
import { useClientState } from "./use-client-state.js";
|
|
@@ -38,6 +38,7 @@ const state = new State();
|
|
|
38
38
|
// Mesh client — real-time state via SharedWorker
|
|
39
39
|
// ---------------------------------------------------------------------------
|
|
40
40
|
const meshClient = new MeshClient();
|
|
41
|
+
let wasConnected = false;
|
|
41
42
|
meshClient.subscribe((meshState) => {
|
|
42
43
|
// Apply real-time mesh state updates on top of the REST-fetched baseline. The MeshClient delivers authoritative state from the mesh worker, which maintains a local copy of all agents and rooms.
|
|
43
44
|
if (meshState.agents.length > 0) {
|
|
@@ -47,6 +48,26 @@ meshClient.subscribe((meshState) => {
|
|
|
47
48
|
state.setRooms(meshState.rooms);
|
|
48
49
|
}
|
|
49
50
|
state.setConnected(meshState.connected);
|
|
51
|
+
if (meshState.connected !== wasConnected) {
|
|
52
|
+
wasConnected = meshState.connected;
|
|
53
|
+
addMessage({
|
|
54
|
+
type: "system",
|
|
55
|
+
text: meshState.connected
|
|
56
|
+
? "Connected to mesh"
|
|
57
|
+
: "Disconnected — reconnecting...",
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
meshClient.onDelivery((event) => {
|
|
62
|
+
const msg = deliveryEventToMessage(event, state.get().currentRoom);
|
|
63
|
+
if (msg)
|
|
64
|
+
addMessage(msg);
|
|
65
|
+
if (event.type === "member_joined" ||
|
|
66
|
+
event.type === "member_left" ||
|
|
67
|
+
event.type === "member_status" ||
|
|
68
|
+
event.type === "name_changed") {
|
|
69
|
+
void refreshState();
|
|
70
|
+
}
|
|
50
71
|
});
|
|
51
72
|
// Don't auto-connect the MeshClient on first load. The user must explicitly connect to avoid Chrome's "access device" prompt appearing before the user understands the UI. meshClient.connect() is called from onConnectToMesh().
|
|
52
73
|
// ---------------------------------------------------------------------------
|
|
@@ -56,63 +77,17 @@ function addMessage(msg) {
|
|
|
56
77
|
state.addMessage(msg);
|
|
57
78
|
}
|
|
58
79
|
// ---------------------------------------------------------------------------
|
|
59
|
-
// WebSocket
|
|
60
|
-
// ---------------------------------------------------------------------------
|
|
61
|
-
let pendingAction;
|
|
62
|
-
const ws = new CommsWs({
|
|
63
|
-
onOpen: () => {
|
|
64
|
-
state.setConnected(true);
|
|
65
|
-
addMessage({ type: "system", text: "Connected to mesh" });
|
|
66
|
-
},
|
|
67
|
-
onClose: () => {
|
|
68
|
-
state.setConnected(false);
|
|
69
|
-
addMessage({ type: "system", text: "Disconnected — reconnecting..." });
|
|
70
|
-
},
|
|
71
|
-
onFrame: handleFrame,
|
|
72
|
-
});
|
|
73
|
-
function handleFrame(frame) {
|
|
74
|
-
const s = state.get();
|
|
75
|
-
switch (frame.type) {
|
|
76
|
-
case "delivery": {
|
|
77
|
-
const msg = deliveryEventToMessage(frame.event, s.currentRoom);
|
|
78
|
-
if (msg)
|
|
79
|
-
addMessage(msg);
|
|
80
|
-
if (frame.event.type === "member_joined" ||
|
|
81
|
-
frame.event.type === "member_left" ||
|
|
82
|
-
frame.event.type === "member_status" ||
|
|
83
|
-
frame.event.type === "name_changed") {
|
|
84
|
-
void refreshState();
|
|
85
|
-
}
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
case "result":
|
|
89
|
-
addMessage({ type: "system", text: frame.result.content });
|
|
90
|
-
if (!frame.result.isError) {
|
|
91
|
-
if (pendingAction?.action === "join_room" &&
|
|
92
|
-
(state.get().currentRoom === undefined ||
|
|
93
|
-
state.get().currentRoom === "")) {
|
|
94
|
-
const roomId = pendingAction.room;
|
|
95
|
-
state.setDmTarget(undefined);
|
|
96
|
-
state.setCurrentRoom(roomId);
|
|
97
|
-
}
|
|
98
|
-
void refreshState();
|
|
99
|
-
}
|
|
100
|
-
pendingAction = undefined;
|
|
101
|
-
break;
|
|
102
|
-
case "error":
|
|
103
|
-
addMessage({ type: "status", text: `Error: ${frame.message}` });
|
|
104
|
-
break;
|
|
105
|
-
case "state":
|
|
106
|
-
state.applyState(frame.agents, frame.rooms);
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// ---------------------------------------------------------------------------
|
|
111
80
|
// Actions
|
|
112
81
|
// ---------------------------------------------------------------------------
|
|
113
|
-
function sendAction(action) {
|
|
114
|
-
|
|
115
|
-
|
|
82
|
+
async function sendAction(action) {
|
|
83
|
+
const result = await meshClient.sendAction(action);
|
|
84
|
+
addMessage({
|
|
85
|
+
type: result.isError ? "status" : "system",
|
|
86
|
+
text: result.isError ? `Error: ${result.content}` : result.content,
|
|
87
|
+
});
|
|
88
|
+
if (!result.isError) {
|
|
89
|
+
void refreshState();
|
|
90
|
+
}
|
|
116
91
|
}
|
|
117
92
|
async function refreshState() {
|
|
118
93
|
if (!isLocalServer)
|
|
@@ -135,7 +110,7 @@ async function onJoinRoom(roomId) {
|
|
|
135
110
|
state.setDmTarget(undefined);
|
|
136
111
|
state.setCurrentRoom(roomId);
|
|
137
112
|
state.clearMessages();
|
|
138
|
-
sendAction({ action: "join_room", room: roomId });
|
|
113
|
+
void sendAction({ action: "join_room", room: roomId });
|
|
139
114
|
// Load history (skip REST fetch on standalone PWA — no server)
|
|
140
115
|
if (isLocalServer) {
|
|
141
116
|
const messages = await fetchRoomMessages(roomId);
|
|
@@ -154,7 +129,7 @@ function onLeaveRoom() {
|
|
|
154
129
|
if (currentRoom !== undefined && currentRoom !== "") {
|
|
155
130
|
// currentRoom is the room's real owner-qualified id -- resolve it back to the plain name it was created with for the confirmation message, the same way ChatArea's own header resolves it for display.
|
|
156
131
|
const roomName = s.rooms.find((room) => room.id === currentRoom)?.name ?? currentRoom;
|
|
157
|
-
sendAction({ action: "leave_room", room: currentRoom });
|
|
132
|
+
void sendAction({ action: "leave_room", room: currentRoom });
|
|
158
133
|
state.setCurrentRoom(undefined);
|
|
159
134
|
state.clearMessages();
|
|
160
135
|
addMessage({ type: "system", text: `Left room "${roomName}"` });
|
|
@@ -177,7 +152,7 @@ function handleSendAction(text) {
|
|
|
177
152
|
}
|
|
178
153
|
switch (result.kind) {
|
|
179
154
|
case "action":
|
|
180
|
-
sendAction(result.action);
|
|
155
|
+
void sendAction(result.action);
|
|
181
156
|
break;
|
|
182
157
|
case "local":
|
|
183
158
|
addMessage({ type: "system", text: result.result.text });
|
|
@@ -193,19 +168,17 @@ function onCreateRoom(name, type, description) {
|
|
|
193
168
|
type,
|
|
194
169
|
...(description ? { description } : {}),
|
|
195
170
|
};
|
|
196
|
-
sendAction(action);
|
|
171
|
+
void sendAction(action);
|
|
197
172
|
}
|
|
198
173
|
function onJoinRoomInput(roomName) {
|
|
199
174
|
void onJoinRoom(roomName);
|
|
200
175
|
}
|
|
201
176
|
function onRenameAgent(agentId, newName) {
|
|
202
|
-
sendAction({ action: "rename_agent", agent: agentId, name: newName });
|
|
177
|
+
void sendAction({ action: "rename_agent", agent: agentId, name: newName });
|
|
203
178
|
}
|
|
204
179
|
function onConnectToMesh() {
|
|
205
180
|
localStorage.setItem("agent-comms-connected", "true");
|
|
206
181
|
meshClient.connect();
|
|
207
|
-
if (isLocalServer)
|
|
208
|
-
ws.connect();
|
|
209
182
|
}
|
|
210
183
|
// ---------------------------------------------------------------------------
|
|
211
184
|
// Root — subscribes to state and keeps the URL in sync
|
|
@@ -226,8 +199,6 @@ const deepLink = parseDeepLink(location.search);
|
|
|
226
199
|
const previouslyConnected = hasConnectedBefore(localStorage);
|
|
227
200
|
if (isLocalServer || previouslyConnected) {
|
|
228
201
|
meshClient.connect();
|
|
229
|
-
if (isLocalServer)
|
|
230
|
-
ws.connect();
|
|
231
202
|
}
|
|
232
203
|
// Initial state fetch, then resolve any deep link from the URL
|
|
233
204
|
void refreshState().then(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../../src/bridges/user/web/frontend/main.tsx"],"names":[],"mappings":";AAAA;;;;GAIG;AAEH,OAAO,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AQ,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,MAAM;YACT,KAAK,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACnC,MAAM;QACR,KAAK,IAAI;YACP,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACjC,MAAM;IACV,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MeshClient — main-thread API for the mesh SharedWorker.
|
|
3
3
|
*
|
|
4
|
-
* Creates a SharedWorker from the built mesh-worker.js bundle and
|
|
5
|
-
* provides a typed interface for the React frontend to:
|
|
4
|
+
* Creates a SharedWorker from the built mesh-worker.js bundle and provides a typed interface for the React frontend to:
|
|
6
5
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* - Query current mesh state (agents, rooms)
|
|
7
|
+
* - Execute actions (send, join, create room, etc.)
|
|
8
|
+
* - Subscribe to real-time state changes (patches)
|
|
10
9
|
*
|
|
11
|
-
* The
|
|
12
|
-
* server's /ws/mesh endpoint shared across all tabs.
|
|
10
|
+
* The public subscribe()/get()/disconnect()/sendAction()/connect() surface is unchanged from before the oRPC migration -- internally, agents/rooms are now driven by consuming the worker's own tab-contract.ts subscribeEvents() stream over a real oRPC message-port client, rather than parsing raw postMessage frames. The one signal the new stream doesn't yet carry as its own discrete event -- connected/disconnected, which describes the worker's own upstream socket state to the real server, not this class's own message-port channel to the worker -- is read from the legacy protocol's own "connected"/"disconnected" broadcasts, still fully live on the same port (mesh-worker.ts's own PR4 kept both protocols coexisting deliberately for exactly this kind of narrow reuse, rather than re-deriving an equivalent signal via a second, redundant mechanism).
|
|
13
11
|
*/
|
|
14
|
-
import type { Agent, Room } from "./types.js";
|
|
12
|
+
import type { Agent, ActionResult, DeliveryEvent, Room } from "./types.js";
|
|
15
13
|
type AgentIdentity = Agent;
|
|
16
14
|
type RoomLike = Room;
|
|
17
15
|
export type MeshStateListener = (state: MeshClientState) => void;
|
|
16
|
+
export type MeshDeliveryListener = (event: DeliveryEvent) => void;
|
|
18
17
|
export interface MeshClientState {
|
|
19
18
|
agents: AgentIdentity[];
|
|
20
19
|
rooms: RoomLike[];
|
|
@@ -22,27 +21,35 @@ export interface MeshClientState {
|
|
|
22
21
|
}
|
|
23
22
|
export declare class MeshClient {
|
|
24
23
|
private worker;
|
|
24
|
+
private client;
|
|
25
25
|
private state;
|
|
26
26
|
private readonly listeners;
|
|
27
|
-
private
|
|
28
|
-
private
|
|
27
|
+
private readonly deliveryListeners;
|
|
28
|
+
private eventPumpGeneration;
|
|
29
|
+
constructor();
|
|
29
30
|
/** Connect to the mesh SharedWorker. Idempotent. */
|
|
30
31
|
connect(): void;
|
|
31
32
|
/** Get the current mesh state (snapshot). */
|
|
32
33
|
get(): Readonly<MeshClientState>;
|
|
33
34
|
/** Subscribe to state changes. Returns an unsubscribe function. */
|
|
34
35
|
subscribe(listener: MeshStateListener): () => void;
|
|
35
|
-
/**
|
|
36
|
-
|
|
36
|
+
/** Subscribe to delivery events (room messages, DMs, invites, ...). Returns an unsubscribe function. */
|
|
37
|
+
onDelivery(listener: MeshDeliveryListener): () => void;
|
|
38
|
+
/** Send an action through the mesh worker, returning the real result. */
|
|
39
|
+
sendAction(action: Record<string, unknown>): Promise<ActionResult>;
|
|
37
40
|
/** Disconnect and clean up. */
|
|
38
41
|
disconnect(): void;
|
|
39
42
|
/**
|
|
40
|
-
*
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
* Consumes the worker's own subscribeEvents() stream for as long as this generation is current, mirroring mesh-worker.ts's own pumpEvents: resuming by lastEventId after any transport-level drop is this loop's own job, not something either RetryLinkPlugin or the underlying transport does transparently on its own (confirmed empirically in an earlier stage of this migration).
|
|
44
|
+
*/
|
|
45
|
+
private pumpEvents;
|
|
46
|
+
private applyMeshEvent;
|
|
47
|
+
private applyPatch;
|
|
48
|
+
private postLegacyInit;
|
|
49
|
+
/**
|
|
50
|
+
* Probe localhost ports sequentially for the web server's /ws/mesh endpoint. Matches the server's port discovery: starts at 19877, walks up. Sends an init message to the worker on first successful WS upgrade.
|
|
43
51
|
*/
|
|
44
52
|
private probeLocalMesh;
|
|
45
|
-
private postToWorker;
|
|
46
53
|
private notify;
|
|
47
54
|
}
|
|
48
55
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mesh-client.d.ts","sourceRoot":"","sources":["../../../../../src/bridges/user/web/frontend/mesh-client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mesh-client.d.ts","sourceRoot":"","sources":["../../../../../src/bridges/user/web/frontend/mesh-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAS3E,KAAK,aAAa,GAAG,KAAK,CAAC;AAC3B,KAAK,QAAQ,GAAG,IAAI,CAAC;AAGrB,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;AACjE,MAAM,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;AAwBlE,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;CACpB;AAWD,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,KAAK,CAIX;IACF,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgC;IAC1D,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmC;IACrE,OAAO,CAAC,mBAAmB,CAAK;;IAWhC,oDAAoD;IACpD,OAAO,IAAI,IAAI;IAyCf,6CAA6C;IAC7C,GAAG,IAAI,QAAQ,C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