@mquan/portal 0.0.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 +168 -0
- package/dist/src/api.d.ts +5 -0
- package/dist/src/api.js +357 -0
- package/dist/src/api.js.map +1 -0
- package/dist/src/cli.d.ts +17 -0
- package/dist/src/cli.js +618 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/daemon-lifecycle.d.ts +24 -0
- package/dist/src/daemon-lifecycle.js +107 -0
- package/dist/src/daemon-lifecycle.js.map +1 -0
- package/dist/src/daemon.d.ts +17 -0
- package/dist/src/daemon.js +90 -0
- package/dist/src/daemon.js.map +1 -0
- package/dist/src/doctor.d.ts +14 -0
- package/dist/src/doctor.js +51 -0
- package/dist/src/doctor.js.map +1 -0
- package/dist/src/entrypoint.d.ts +2 -0
- package/dist/src/entrypoint.js +14 -0
- package/dist/src/entrypoint.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +5 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/launch.d.ts +41 -0
- package/dist/src/launch.js +186 -0
- package/dist/src/launch.js.map +1 -0
- package/dist/src/mcp.d.ts +9 -0
- package/dist/src/mcp.js +132 -0
- package/dist/src/mcp.js.map +1 -0
- package/dist/src/network/client.d.ts +67 -0
- package/dist/src/network/client.js +540 -0
- package/dist/src/network/client.js.map +1 -0
- package/dist/src/network/coordinator.d.ts +83 -0
- package/dist/src/network/coordinator.js +225 -0
- package/dist/src/network/coordinator.js.map +1 -0
- package/dist/src/network/protocol.d.ts +1352 -0
- package/dist/src/network/protocol.js +360 -0
- package/dist/src/network/protocol.js.map +1 -0
- package/dist/src/network/server.d.ts +28 -0
- package/dist/src/network/server.js +474 -0
- package/dist/src/network/server.js.map +1 -0
- package/dist/src/network/tasks.d.ts +65 -0
- package/dist/src/network/tasks.js +276 -0
- package/dist/src/network/tasks.js.map +1 -0
- package/dist/src/portal-index.d.ts +21 -0
- package/dist/src/portal-index.js +140 -0
- package/dist/src/portal-index.js.map +1 -0
- package/dist/src/provider/claude-managed.d.ts +34 -0
- package/dist/src/provider/claude-managed.js +125 -0
- package/dist/src/provider/claude-managed.js.map +1 -0
- package/dist/src/provider/claude.d.ts +24 -0
- package/dist/src/provider/claude.js +114 -0
- package/dist/src/provider/claude.js.map +1 -0
- package/dist/src/provider/codex/app-server-client.d.ts +43 -0
- package/dist/src/provider/codex/app-server-client.js +143 -0
- package/dist/src/provider/codex/app-server-client.js.map +1 -0
- package/dist/src/provider/codex/index.d.ts +3 -0
- package/dist/src/provider/codex/index.js +4 -0
- package/dist/src/provider/codex/index.js.map +1 -0
- package/dist/src/provider/codex/managed-runner.d.ts +12 -0
- package/dist/src/provider/codex/managed-runner.js +162 -0
- package/dist/src/provider/codex/managed-runner.js.map +1 -0
- package/dist/src/provider/codex/probe.d.ts +2 -0
- package/dist/src/provider/codex/probe.js +33 -0
- package/dist/src/provider/codex/probe.js.map +1 -0
- package/dist/src/provider/codex/protocol.d.ts +193 -0
- package/dist/src/provider/codex/protocol.js +10 -0
- package/dist/src/provider/codex/protocol.js.map +1 -0
- package/dist/src/provider/codex/provider.d.ts +35 -0
- package/dist/src/provider/codex/provider.js +289 -0
- package/dist/src/provider/codex/provider.js.map +1 -0
- package/dist/src/provider/codex/remote-app-server.d.ts +16 -0
- package/dist/src/provider/codex/remote-app-server.js +80 -0
- package/dist/src/provider/codex/remote-app-server.js.map +1 -0
- package/dist/src/provider/codex/websocket-client.d.ts +40 -0
- package/dist/src/provider/codex/websocket-client.js +174 -0
- package/dist/src/provider/codex/websocket-client.js.map +1 -0
- package/dist/src/provider/types.d.ts +35 -0
- package/dist/src/provider/types.js +2 -0
- package/dist/src/provider/types.js.map +1 -0
- package/dist/src/recall/embedding.d.ts +28 -0
- package/dist/src/recall/embedding.js +142 -0
- package/dist/src/recall/embedding.js.map +1 -0
- package/dist/src/recall/types.d.ts +35 -0
- package/dist/src/recall/types.js +2 -0
- package/dist/src/recall/types.js.map +1 -0
- package/dist/src/rpc/client.d.ts +6 -0
- package/dist/src/rpc/client.js +58 -0
- package/dist/src/rpc/client.js.map +1 -0
- package/dist/src/rpc/protocol.d.ts +21 -0
- package/dist/src/rpc/protocol.js +11 -0
- package/dist/src/rpc/protocol.js.map +1 -0
- package/dist/src/rpc/server.d.ts +12 -0
- package/dist/src/rpc/server.js +154 -0
- package/dist/src/rpc/server.js.map +1 -0
- package/dist/src/runtime/paths.d.ts +8 -0
- package/dist/src/runtime/paths.js +18 -0
- package/dist/src/runtime/paths.js.map +1 -0
- package/dist/src/service.d.ts +127 -0
- package/dist/src/service.js +637 -0
- package/dist/src/service.js.map +1 -0
- package/dist/src/session-profile.d.ts +39 -0
- package/dist/src/session-profile.js +186 -0
- package/dist/src/session-profile.js.map +1 -0
- package/dist/src/storage/database.d.ts +9 -0
- package/dist/src/storage/database.js +354 -0
- package/dist/src/storage/database.js.map +1 -0
- package/dist/src/storage/repository.d.ts +275 -0
- package/dist/src/storage/repository.js +1291 -0
- package/dist/src/storage/repository.js.map +1 -0
- package/dist/src/version.d.ts +1 -0
- package/dist/src/version.js +2 -0
- package/dist/src/version.js.map +1 -0
- package/docs/architecture-plan.md +191 -0
- package/docs/mvp-plan.md +111 -0
- package/docs/remote-demo.md +346 -0
- package/package.json +47 -0
package/dist/src/mcp.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import * as z from "zod/v4";
|
|
5
|
+
import { callRpc } from "./rpc/client.js";
|
|
6
|
+
import { resolvePortalPaths } from "./runtime/paths.js";
|
|
7
|
+
import { PORTAL_VERSION } from "./version.js";
|
|
8
|
+
import { isEntrypoint } from "./entrypoint.js";
|
|
9
|
+
export function createPortalMcpServer(identity, rpcCall) {
|
|
10
|
+
const server = new McpServer({ name: "portal", version: PORTAL_VERSION });
|
|
11
|
+
const authenticated = (params = {}) => ({
|
|
12
|
+
...params,
|
|
13
|
+
sessionId: identity.sessionId,
|
|
14
|
+
token: identity.token,
|
|
15
|
+
});
|
|
16
|
+
server.registerTool("portal.sessions", {
|
|
17
|
+
description: "List cached current and historical local Codex and Claude sessions in this workspace. Set refresh only when newly created local history is required; remote agents are listed by portal.peers.",
|
|
18
|
+
inputSchema: {
|
|
19
|
+
refresh: z.boolean().optional().describe("Refresh local transcript history before listing; defaults false and may be slow"),
|
|
20
|
+
},
|
|
21
|
+
annotations: { readOnlyHint: true },
|
|
22
|
+
}, async (input) => result(() => rpcCall("agent.sessions", authenticated(input))));
|
|
23
|
+
server.registerTool("portal.peers", {
|
|
24
|
+
description: "Discover live, unauthenticated remote agents connected to this managed session's Portal server.",
|
|
25
|
+
inputSchema: {
|
|
26
|
+
query: z.string().min(1).max(256).optional(),
|
|
27
|
+
capability: z.enum(["message", "task"]).optional(),
|
|
28
|
+
limit: z.number().int().min(1).max(100).optional(),
|
|
29
|
+
},
|
|
30
|
+
annotations: { readOnlyHint: true },
|
|
31
|
+
}, async (input) => result(() => rpcCall("agent.peers", authenticated(input))));
|
|
32
|
+
server.registerTool("portal.recall", {
|
|
33
|
+
description: "Search indexed peer-session context without knowing which session contains it.",
|
|
34
|
+
inputSchema: {
|
|
35
|
+
query: z.string().min(1).describe("Natural-language or exact context query"),
|
|
36
|
+
providers: z.array(z.enum(["codex", "claude"])).optional(),
|
|
37
|
+
limit: z.number().int().min(1).max(50).optional(),
|
|
38
|
+
refresh: z.boolean().optional().describe("Refresh changed transcripts before recall; defaults true"),
|
|
39
|
+
},
|
|
40
|
+
annotations: { readOnlyHint: true },
|
|
41
|
+
}, async (input) => result(() => rpcCall("agent.recall", authenticated(input))));
|
|
42
|
+
server.registerTool("portal.delegate", {
|
|
43
|
+
description: "Offer an asynchronous task to one live remote agent. Returns after the remote Portal durably receives the offer; progress and results arrive as automatic turns.",
|
|
44
|
+
inputSchema: {
|
|
45
|
+
target: z.string().min(1).describe("Exact remote agent name or route ID from portal.peers"),
|
|
46
|
+
objective: z.string().min(1).max(4_096),
|
|
47
|
+
context: z.string().min(1).max(16_384).optional(),
|
|
48
|
+
expectedResult: z.string().min(1).max(2_048).optional(),
|
|
49
|
+
ttlSeconds: z.number().int().min(30).max(86_400).optional(),
|
|
50
|
+
},
|
|
51
|
+
annotations: { readOnlyHint: false, idempotentHint: false },
|
|
52
|
+
}, async (input) => result(() => rpcCall("agent.delegate", authenticated(input))));
|
|
53
|
+
server.registerTool("portal.task.update", {
|
|
54
|
+
description: "Send an acceptance, progress update, question, answer, result, decline, or failure for a remote Portal task.",
|
|
55
|
+
inputSchema: {
|
|
56
|
+
taskId: z.string().min(1),
|
|
57
|
+
action: z.enum(["accepted", "declined", "running", "progress", "question", "answer", "completed", "failed"]),
|
|
58
|
+
message: z.string().min(1).optional(),
|
|
59
|
+
reason: z.string().min(1).optional(),
|
|
60
|
+
question: z.string().min(1).optional(),
|
|
61
|
+
answer: z.string().min(1).optional(),
|
|
62
|
+
result: z.string().min(1).optional(),
|
|
63
|
+
error: z.string().min(1).optional(),
|
|
64
|
+
artifactReferences: z.array(z.string().min(1)).max(16).optional(),
|
|
65
|
+
},
|
|
66
|
+
annotations: { readOnlyHint: false, idempotentHint: false },
|
|
67
|
+
}, async (input) => result(() => rpcCall("agent.task.update", authenticated(input))));
|
|
68
|
+
server.registerTool("portal.send", {
|
|
69
|
+
description: "Send an attributed message to a local session or a live remote agent. Targets returned by portal.peers are supported directly; remote delivery becomes an asynchronous task offer whose progress and result return as automatic turns.",
|
|
70
|
+
inputSchema: {
|
|
71
|
+
target: z.string().min(1).optional().describe("Local session reference, or remote agent name, route ID, or session ID from portal.peers"),
|
|
72
|
+
message: z.string().min(1),
|
|
73
|
+
idempotencyKey: z.string().min(1).optional(),
|
|
74
|
+
replyTo: z.string().min(1).optional(),
|
|
75
|
+
},
|
|
76
|
+
annotations: { readOnlyHint: false, idempotentHint: false },
|
|
77
|
+
}, async ({ message, ...input }) => result(() => rpcCall("agent.send", authenticated({ ...input, body: message }))));
|
|
78
|
+
server.registerTool("portal.inbox", {
|
|
79
|
+
description: "Claim durable peer messages. On the next call, acknowledge message IDs only after processing them.",
|
|
80
|
+
inputSchema: {
|
|
81
|
+
acknowledge: z.array(z.string().min(1)).max(100).optional(),
|
|
82
|
+
},
|
|
83
|
+
annotations: { readOnlyHint: false },
|
|
84
|
+
}, async (input) => result(() => rpcCall("agent.inbox", authenticated(input))));
|
|
85
|
+
return server;
|
|
86
|
+
}
|
|
87
|
+
async function result(operation) {
|
|
88
|
+
try {
|
|
89
|
+
const value = await operation();
|
|
90
|
+
return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
return {
|
|
94
|
+
isError: true,
|
|
95
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export async function runMcp(environment = process.env) {
|
|
100
|
+
const sessionId = environment.PORTAL_SESSION_ID;
|
|
101
|
+
const token = environment.PORTAL_SESSION_TOKEN;
|
|
102
|
+
if (!sessionId || !token) {
|
|
103
|
+
throw new Error("Portal MCP requires PORTAL_SESSION_ID and PORTAL_SESSION_TOKEN");
|
|
104
|
+
}
|
|
105
|
+
const socketPath = environment.PORTAL_SOCKET_PATH ?? resolvePortalPaths(environment).socketPath;
|
|
106
|
+
const rpcCall = (method, params) => callRpc({ socketPath, timeoutMs: method === "agent.send" ? 15 * 60_000 : 30_000 }, method, params);
|
|
107
|
+
await rpcCall("agent.connect", { sessionId, token });
|
|
108
|
+
const server = createPortalMcpServer({ sessionId, token }, rpcCall);
|
|
109
|
+
const transport = new StdioServerTransport();
|
|
110
|
+
let heartbeat;
|
|
111
|
+
await server.connect(transport);
|
|
112
|
+
const previousClose = transport.onclose;
|
|
113
|
+
transport.onclose = () => {
|
|
114
|
+
if (heartbeat !== undefined)
|
|
115
|
+
clearInterval(heartbeat);
|
|
116
|
+
void rpcCall("agent.disconnect", { sessionId, token }).catch(() => undefined);
|
|
117
|
+
previousClose?.();
|
|
118
|
+
};
|
|
119
|
+
heartbeat = setInterval(() => {
|
|
120
|
+
void rpcCall("agent.connect", { sessionId, token }).catch((error) => {
|
|
121
|
+
console.error(`Portal heartbeat failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
122
|
+
});
|
|
123
|
+
}, 45_000);
|
|
124
|
+
heartbeat.unref();
|
|
125
|
+
}
|
|
126
|
+
if (isEntrypoint(import.meta.url, process.argv[1])) {
|
|
127
|
+
await runMcp().catch((error) => {
|
|
128
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
129
|
+
process.exitCode = 1;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/mcp.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAS/C,MAAM,UAAU,qBAAqB,CAAC,QAAqB,EAAE,OAAmB;IAC9E,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC;IAC1E,MAAM,aAAa,GAAG,CAAC,MAAM,GAA4B,EAAE,EAA2B,E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MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACtG,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,MAAM,CAAC,CAAC;IACX,SAAS,CAAC,KAAK,EAAE,CAAC;AACpB,CAAC;AAED,IAAI,YAAY,CAAC,OAAO,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACnD,MAAM,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QAC7B,OAAO,CAAC,KAAK,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACtE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type AgentPresence, type AgentRegister, type AgentRenew, type ClientMessage, type Envelope, type EnvelopeAcknowledge, type EnvelopeAcknowledged, type NetworkTransport, type ServerHello, type ServerMessage } from "./protocol.js";
|
|
2
|
+
export interface WebSocketLike {
|
|
3
|
+
readonly readyState: number;
|
|
4
|
+
send(data: string): void;
|
|
5
|
+
close(code?: number, reason?: string): void;
|
|
6
|
+
addEventListener(type: "open", listener: () => void, options?: {
|
|
7
|
+
once?: boolean;
|
|
8
|
+
}): void;
|
|
9
|
+
addEventListener(type: "message", listener: (event: {
|
|
10
|
+
data: unknown;
|
|
11
|
+
}) => void): void;
|
|
12
|
+
addEventListener(type: "error", listener: () => void, options?: {
|
|
13
|
+
once?: boolean;
|
|
14
|
+
}): void;
|
|
15
|
+
addEventListener(type: "close", listener: () => void, options?: {
|
|
16
|
+
once?: boolean;
|
|
17
|
+
}): void;
|
|
18
|
+
}
|
|
19
|
+
export type RemoteClientState = "connecting" | "connected" | "reconnecting" | "closed";
|
|
20
|
+
export interface RemoteNetworkClientOptions {
|
|
21
|
+
clientId: string;
|
|
22
|
+
installationId: string;
|
|
23
|
+
connectTimeoutMs?: number;
|
|
24
|
+
requestTimeoutMs?: number;
|
|
25
|
+
reconnect?: boolean;
|
|
26
|
+
reconnectDelayMs?: number;
|
|
27
|
+
maximumReconnectDelayMs?: number;
|
|
28
|
+
webSocketFactory?: (url: string) => WebSocketLike;
|
|
29
|
+
now?: () => Date;
|
|
30
|
+
requestIdFactory?: () => string;
|
|
31
|
+
}
|
|
32
|
+
type RegisterInput = Omit<AgentRegister, "protocolVersion" | "type" | "requestId">;
|
|
33
|
+
type RenewInput = Omit<AgentRenew, "protocolVersion" | "type" | "requestId">;
|
|
34
|
+
type DiscoverInput = {
|
|
35
|
+
query?: string;
|
|
36
|
+
capability?: "message" | "task";
|
|
37
|
+
limit?: number;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Reusable client transport for the Portal relay protocol.
|
|
41
|
+
*
|
|
42
|
+
* A connection is usable only after the versioned hello exchange succeeds.
|
|
43
|
+
* Requests in flight when a socket drops are rejected (never silently
|
|
44
|
+
* replayed); later requests wait for the reconnect handshake.
|
|
45
|
+
*/
|
|
46
|
+
export declare class RemoteNetworkClient implements NetworkTransport {
|
|
47
|
+
#private;
|
|
48
|
+
readonly url: string;
|
|
49
|
+
private constructor();
|
|
50
|
+
static connect(url: string, options: RemoteNetworkClientOptions): Promise<RemoteNetworkClient>;
|
|
51
|
+
get state(): RemoteClientState;
|
|
52
|
+
get serverHello(): ServerHello | null;
|
|
53
|
+
onMessage(handler: (message: ServerMessage) => void | Promise<void>): () => void;
|
|
54
|
+
onEnvelope(handler: (envelope: Envelope) => void | Promise<void>): () => void;
|
|
55
|
+
onStateChange(handler: (state: RemoteClientState) => void): () => void;
|
|
56
|
+
onError(handler: (error: Error) => void): () => void;
|
|
57
|
+
register(input: RegisterInput): Promise<AgentPresence>;
|
|
58
|
+
renew(input: RenewInput): Promise<AgentPresence>;
|
|
59
|
+
unregister(routeId: string): Promise<void>;
|
|
60
|
+
discover(input?: DiscoverInput): Promise<AgentPresence[]>;
|
|
61
|
+
sendEnvelope(envelope: Envelope): Promise<EnvelopeAcknowledged>;
|
|
62
|
+
acknowledge(input: Omit<EnvelopeAcknowledge, "protocolVersion" | "type" | "requestId">): Promise<void>;
|
|
63
|
+
send(message: ClientMessage): Promise<void>;
|
|
64
|
+
close(): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
export declare function normalizeRemoteServerUrl(input: string): string;
|
|
67
|
+
export {};
|