@mclawnet/agent 0.2.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/cli.js +63 -71
- package/dist/backend-adapter.d.ts +53 -0
- package/dist/backend-adapter.d.ts.map +1 -0
- package/dist/chunk-YBQQZNRQ.js +780 -0
- package/dist/chunk-YBQQZNRQ.js.map +1 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/fs-handler.d.ts +39 -0
- package/dist/fs-handler.d.ts.map +1 -0
- package/dist/hub-connection.d.ts +60 -0
- package/dist/hub-connection.d.ts.map +1 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -726
- package/dist/index.js.map +1 -0
- package/dist/session-manager.d.ts +33 -0
- package/dist/session-manager.d.ts.map +1 -0
- package/dist/start.d.ts +15 -107
- package/dist/start.d.ts.map +1 -0
- package/dist/start.js +4 -713
- package/dist/start.js.map +1 -0
- package/package.json +23 -24
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { HubConnection, type HubConnectionOptions } from \"./hub-connection.js\";\nexport { SessionManager } from \"./session-manager.js\";\nexport {\n type BackendAdapter,\n type BackendProcess,\n type SpawnOptions,\n} from \"./backend-adapter.js\";\nexport { loadConfig, saveConfig, type AgentConfig } from \"./config.js\";\nexport { startAgent, type StartOptions } from \"./start.js\";\n\n// Re-export from @mclawnet/swarm for convenience\nexport {\n SwarmCoordinator,\n type RoleDefinition,\n loadRole,\n listRoles,\n initRoles,\n buildRolePrompt,\n} from \"@mclawnet/swarm\";\n"],"mappings":";;;;;;;;;AAWA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { BackendAdapter, SpawnOptions } from "./backend-adapter.js";
|
|
2
|
+
/**
|
|
3
|
+
* Manages active sessions, mapping ClawNet session IDs to BackendProcess instances.
|
|
4
|
+
*/
|
|
5
|
+
export declare class SessionManager {
|
|
6
|
+
private sessions;
|
|
7
|
+
private adapter;
|
|
8
|
+
private onOutput;
|
|
9
|
+
private onTurnComplete;
|
|
10
|
+
private onSessionError;
|
|
11
|
+
constructor(options: {
|
|
12
|
+
adapter: BackendAdapter;
|
|
13
|
+
onOutput: (sessionId: string, data: unknown) => void;
|
|
14
|
+
onTurnComplete: (sessionId: string, info: {
|
|
15
|
+
claudeSessionId?: string;
|
|
16
|
+
cost?: number;
|
|
17
|
+
duration?: number;
|
|
18
|
+
contextUsage?: {
|
|
19
|
+
used: number;
|
|
20
|
+
total: number;
|
|
21
|
+
};
|
|
22
|
+
}) => void;
|
|
23
|
+
onSessionError: (sessionId: string, error: string) => void;
|
|
24
|
+
});
|
|
25
|
+
createSession(options: SpawnOptions): Promise<string>;
|
|
26
|
+
sendInput(sessionId: string, input: string): void;
|
|
27
|
+
abortSession(sessionId: string): Promise<void>;
|
|
28
|
+
closeSession(sessionId: string): Promise<void>;
|
|
29
|
+
closeAll(): Promise<void>;
|
|
30
|
+
hasSession(sessionId: string): boolean;
|
|
31
|
+
get activeSessionCount(): number;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=session-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../src/session-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAkB,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzF;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAqC;IACrD,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,QAAQ,CAA6C;IAC7D,OAAO,CAAC,cAAc,CAQZ;IACV,OAAO,CAAC,cAAc,CAA6C;gBAEvD,OAAO,EAAE;QACnB,OAAO,EAAE,cAAc,CAAC;QACxB,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;QACrD,cAAc,EAAE,CACd,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE;YACJ,eAAe,CAAC,EAAE,MAAM,CAAC;YACzB,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,QAAQ,CAAC,EAAE,MAAM,CAAC;YAClB,YAAY,CAAC,EAAE;gBAAE,IAAI,EAAE,MAAM,CAAC;gBAAC,KAAK,EAAE,MAAM,CAAA;aAAE,CAAC;SAChD,KACE,IAAI,CAAC;QACV,cAAc,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;KAC5D;IAOK,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAgC3D,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAS3C,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS9C,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO9C,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAU/B,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAItC,IAAI,kBAAkB,IAAI,MAAM,CAE/B;CACF"}
|
package/dist/start.d.ts
CHANGED
|
@@ -1,110 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
heartbeatInterval?: number;
|
|
10
|
-
reconnectDelay?: number;
|
|
11
|
-
maxReconnectDelay?: number;
|
|
12
|
-
onMessage?: (data: unknown) => void;
|
|
13
|
-
onConnect?: (agentId: string) => void;
|
|
14
|
-
onDisconnect?: (code: number, reason: string) => void;
|
|
15
|
-
onError?: (err: Error) => void;
|
|
16
|
-
}
|
|
17
|
-
declare class HubConnection {
|
|
18
|
-
private ws;
|
|
19
|
-
private heartbeatTimer;
|
|
20
|
-
private reconnectTimer;
|
|
21
|
-
private reconnectDelay;
|
|
22
|
-
private destroyed;
|
|
23
|
-
private authState;
|
|
24
|
-
private proxySessions;
|
|
25
|
-
readonly hubUrl: string;
|
|
26
|
-
readonly token: string;
|
|
27
|
-
readonly hostname: string;
|
|
28
|
-
readonly gatewayPort: number;
|
|
29
|
-
readonly gatewayToken: string;
|
|
30
|
-
readonly heartbeatInterval: number;
|
|
31
|
-
readonly maxReconnectDelay: number;
|
|
32
|
-
/** Agent ID assigned by Hub after successful auth */
|
|
33
|
-
agentId: string | null;
|
|
34
|
-
private onMessage?;
|
|
35
|
-
private onConnectCb?;
|
|
36
|
-
private onDisconnect?;
|
|
37
|
-
private onError?;
|
|
38
|
-
constructor(opts: HubConnectionOptions);
|
|
39
|
-
/** Current WebSocket readyState (or CLOSED if no socket) */
|
|
40
|
-
get readyState(): number;
|
|
41
|
-
get isConnected(): boolean;
|
|
42
|
-
/** Open the connection to the hub (no token in URL) */
|
|
43
|
-
connect(): void;
|
|
44
|
-
/** Send a JSON message to the hub */
|
|
45
|
-
send(data: unknown): boolean;
|
|
46
|
-
/** Permanently close and stop reconnecting */
|
|
47
|
-
destroy(): void;
|
|
48
|
-
private startHeartbeat;
|
|
49
|
-
private stopHeartbeat;
|
|
50
|
-
private scheduleReconnect;
|
|
51
|
-
private cleanup;
|
|
52
|
-
/**
|
|
53
|
-
* Handle proxy protocol messages from the Hub.
|
|
54
|
-
* Returns true if the message was handled.
|
|
55
|
-
*/
|
|
56
|
-
private handleProxyMessage;
|
|
57
|
-
private openLocalGateway;
|
|
58
|
-
/**
|
|
59
|
-
* Intercept browser's "connect" request and patch it for the local gateway:
|
|
60
|
-
* - Inject gateway auth token
|
|
61
|
-
* - Remove `device` object (browser's device identity/signature doesn't apply
|
|
62
|
-
* through the proxy; the gateway will use token-only auth)
|
|
63
|
-
*/
|
|
64
|
-
private patchBrowserConnect;
|
|
65
|
-
private closeProxySession;
|
|
66
|
-
private closeAllProxySessions;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
interface AgentConfig {
|
|
70
|
-
hubUrl: string;
|
|
71
|
-
token: string;
|
|
72
|
-
port: number;
|
|
73
|
-
name: string;
|
|
74
|
-
}
|
|
75
|
-
/** Load config: CLI opts > env vars > config file > defaults */
|
|
76
|
-
declare function loadConfig(cliOpts?: Partial<AgentConfig>): AgentConfig;
|
|
77
|
-
/** Save config to ~/.clawnet/config.json */
|
|
78
|
-
declare function saveConfig(config: Partial<AgentConfig>): void;
|
|
79
|
-
|
|
80
|
-
interface GatewayHandle {
|
|
81
|
-
process: ChildProcess;
|
|
82
|
-
port: number;
|
|
83
|
-
close(): Promise<void>;
|
|
1
|
+
import { type AgentConfig } from "./config.js";
|
|
2
|
+
import { HubConnection } from "./hub-connection.js";
|
|
3
|
+
import { SessionManager } from "./session-manager.js";
|
|
4
|
+
import { SwarmCoordinator } from "@mclawnet/swarm";
|
|
5
|
+
import type { BackendAdapter } from "./backend-adapter.js";
|
|
6
|
+
export interface StartOptions {
|
|
7
|
+
config?: Partial<AgentConfig>;
|
|
8
|
+
adapter: BackendAdapter;
|
|
84
9
|
}
|
|
85
10
|
/**
|
|
86
|
-
*
|
|
87
|
-
* Uses `openclaw gateway run` command from the installed openclaw package.
|
|
11
|
+
* Start the ClawNet agent: connect to Hub and register a BackendAdapter.
|
|
88
12
|
*/
|
|
89
|
-
declare function
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
interface AgentStartOptions {
|
|
97
|
-
hubUrl?: string;
|
|
98
|
-
token?: string;
|
|
99
|
-
port?: string | number;
|
|
100
|
-
name?: string;
|
|
101
|
-
}
|
|
102
|
-
interface RunningAgent {
|
|
103
|
-
config: AgentConfig;
|
|
104
|
-
gateway: GatewayHandle | null;
|
|
105
|
-
hubConnection: HubConnection;
|
|
106
|
-
}
|
|
107
|
-
declare function startAgent(opts: AgentStartOptions): Promise<RunningAgent>;
|
|
108
|
-
declare function showStatus(): void;
|
|
109
|
-
|
|
110
|
-
export { type AgentConfig as A, type AgentStartOptions, HubConnection as H, type RunningAgent, type HubConnectionOptions as a, buildGatewayArgs as b, loadConfig as c, launchGateway as l, saveConfig as s, showStatus, startAgent };
|
|
13
|
+
export declare function startAgent(options: StartOptions): Promise<{
|
|
14
|
+
hub: HubConnection;
|
|
15
|
+
sessionManager: SessionManager;
|
|
16
|
+
swarmCoordinator: SwarmCoordinator;
|
|
17
|
+
}>;
|
|
18
|
+
//# sourceMappingURL=start.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../src/start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAa,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAK3D,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAC9B,OAAO,EAAE,cAAc,CAAC;CACzB;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC;IAC/D,GAAG,EAAE,aAAa,CAAC;IACnB,cAAc,EAAE,cAAc,CAAC;IAC/B,gBAAgB,EAAE,gBAAgB,CAAC;CACpC,CAAC,CAuFD"}
|