@clawroom/sdk 0.2.2 → 0.2.3
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/package.json +3 -4
- package/src/client.ts +5 -27
- package/src/index.ts +0 -6
- package/src/protocol.ts +3 -41
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clawroom/sdk",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.3",
|
|
4
|
+
"description": "ClawRoom SDK — polling client and protocol types for connecting any agent to the ClawRoom marketplace",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "./src/index.ts",
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
"clawroom",
|
|
15
15
|
"sdk",
|
|
16
16
|
"agent",
|
|
17
|
-
"marketplace"
|
|
18
|
-
"websocket"
|
|
17
|
+
"marketplace"
|
|
19
18
|
],
|
|
20
19
|
"files": [
|
|
21
20
|
"src"
|
package/src/client.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AgentMessage,
|
|
3
3
|
ServerClaimAck,
|
|
4
|
-
ServerMessage,
|
|
5
4
|
ServerTask,
|
|
6
5
|
} from "./protocol.js";
|
|
7
6
|
|
|
@@ -11,9 +10,7 @@ const HEARTBEAT_INTERVAL_MS = 30_000;
|
|
|
11
10
|
const POLL_INTERVAL_MS = 10_000;
|
|
12
11
|
|
|
13
12
|
type TaskCallback = (task: ServerTask) => void;
|
|
14
|
-
type TaskListCallback = (tasks: ServerTask[]) => void;
|
|
15
13
|
type ClaimAckCallback = (ack: ServerClaimAck) => void;
|
|
16
|
-
type ErrorCallback = (error: ServerMessage & { type: "server.error" }) => void;
|
|
17
14
|
|
|
18
15
|
export type ClawroomClientOptions = {
|
|
19
16
|
/** HTTP base URL. Defaults to https://clawroom.site9.ai/api/agents */
|
|
@@ -26,14 +23,14 @@ export type ClawroomClientOptions = {
|
|
|
26
23
|
skills: string[];
|
|
27
24
|
/** Optional logger */
|
|
28
25
|
log?: {
|
|
29
|
-
info?: (...args: unknown[]) => void;
|
|
30
|
-
warn?: (...args: unknown[]) => void;
|
|
31
|
-
error?: (...args: unknown[]) => void;
|
|
26
|
+
info?: (message: string, ...args: unknown[]) => void;
|
|
27
|
+
warn?: (message: string, ...args: unknown[]) => void;
|
|
28
|
+
error?: (message: string, ...args: unknown[]) => void;
|
|
32
29
|
};
|
|
33
30
|
};
|
|
34
31
|
|
|
35
32
|
/**
|
|
36
|
-
*
|
|
33
|
+
* ClawRoom SDK client using HTTP polling.
|
|
37
34
|
*
|
|
38
35
|
* Agents register with /heartbeat and fetch work from /poll.
|
|
39
36
|
* All agent actions (complete, fail, progress) use HTTP POST.
|
|
@@ -68,12 +65,10 @@ export class ClawroomClient {
|
|
|
68
65
|
private readonly httpBase: string;
|
|
69
66
|
|
|
70
67
|
private taskCallbacks: TaskCallback[] = [];
|
|
71
|
-
private taskListCallbacks: TaskListCallback[] = [];
|
|
72
68
|
private claimAckCallbacks: ClaimAckCallback[] = [];
|
|
73
|
-
private errorCallbacks: ErrorCallback[] = [];
|
|
74
69
|
|
|
75
70
|
constructor(private readonly options: ClawroomClientOptions) {
|
|
76
|
-
this.httpBase = (options.endpoint || DEFAULT_ENDPOINT).replace(
|
|
71
|
+
this.httpBase = (options.endpoint || DEFAULT_ENDPOINT).replace(/\/+$/, "");
|
|
77
72
|
}
|
|
78
73
|
|
|
79
74
|
connect(): void {
|
|
@@ -95,9 +90,7 @@ export class ClawroomClient {
|
|
|
95
90
|
}
|
|
96
91
|
|
|
97
92
|
onTask(cb: TaskCallback): void { this.taskCallbacks.push(cb); }
|
|
98
|
-
onTaskList(cb: TaskListCallback): void { this.taskListCallbacks.push(cb); }
|
|
99
93
|
onClaimAck(cb: ClaimAckCallback): void { this.claimAckCallbacks.push(cb); }
|
|
100
|
-
onError(cb: ErrorCallback): void { this.errorCallbacks.push(cb); }
|
|
101
94
|
|
|
102
95
|
// ── Heartbeat ───────────────────────────────────────────────────
|
|
103
96
|
|
|
@@ -161,19 +154,4 @@ export class ClawroomClient {
|
|
|
161
154
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
162
155
|
return res.json();
|
|
163
156
|
}
|
|
164
|
-
|
|
165
|
-
// ── Message handling ──────────────────────────────────────────────
|
|
166
|
-
|
|
167
|
-
private handleMessage(raw: string): void {
|
|
168
|
-
let msg: ServerMessage;
|
|
169
|
-
try { msg = JSON.parse(raw) as ServerMessage; } catch { return; }
|
|
170
|
-
switch (msg.type) {
|
|
171
|
-
case "server.welcome": this.options.log?.info?.(`[clawroom] welcome, agentId=${msg.agentId}`); break;
|
|
172
|
-
case "server.pong": break;
|
|
173
|
-
case "server.task": for (const cb of this.taskCallbacks) cb(msg); break;
|
|
174
|
-
case "server.task_list": for (const cb of this.taskListCallbacks) cb(msg.tasks); break;
|
|
175
|
-
case "server.claim_ack": for (const cb of this.claimAckCallbacks) cb(msg); break;
|
|
176
|
-
case "server.error": for (const cb of this.errorCallbacks) cb(msg); break;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
157
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,19 +3,13 @@ export type { ClawroomClientOptions } from "./client.js";
|
|
|
3
3
|
|
|
4
4
|
export type {
|
|
5
5
|
AgentMessage,
|
|
6
|
-
AgentHello,
|
|
7
6
|
AgentHeartbeat,
|
|
8
7
|
AgentClaim,
|
|
9
8
|
AgentComplete,
|
|
10
9
|
AgentProgress,
|
|
11
10
|
AgentResultFile,
|
|
12
11
|
AgentFail,
|
|
13
|
-
AgentRelease,
|
|
14
12
|
ServerMessage,
|
|
15
|
-
ServerWelcome,
|
|
16
|
-
ServerPong,
|
|
17
13
|
ServerTask,
|
|
18
|
-
ServerTaskList,
|
|
19
14
|
ServerClaimAck,
|
|
20
|
-
ServerError,
|
|
21
15
|
} from "./protocol.js";
|
package/src/protocol.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
//
|
|
1
|
+
// ClawRoom protocol types.
|
|
2
2
|
// These define the messages exchanged between agents and the server.
|
|
3
3
|
|
|
4
4
|
// ---- Agent -> Server ----
|
|
5
5
|
|
|
6
|
-
export interface AgentHello {
|
|
7
|
-
type: "agent.hello";
|
|
8
|
-
deviceId: string;
|
|
9
|
-
skills: string[];
|
|
10
|
-
kind?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
6
|
export interface AgentHeartbeat {
|
|
14
7
|
type: "agent.heartbeat";
|
|
15
8
|
}
|
|
@@ -45,32 +38,15 @@ export interface AgentFail {
|
|
|
45
38
|
reason: string;
|
|
46
39
|
}
|
|
47
40
|
|
|
48
|
-
export interface AgentRelease {
|
|
49
|
-
type: "agent.release";
|
|
50
|
-
taskId: string;
|
|
51
|
-
reason: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
41
|
export type AgentMessage =
|
|
55
|
-
| AgentHello
|
|
56
42
|
| AgentHeartbeat
|
|
57
43
|
| AgentClaim
|
|
58
44
|
| AgentComplete
|
|
59
45
|
| AgentProgress
|
|
60
|
-
| AgentFail
|
|
61
|
-
| AgentRelease;
|
|
46
|
+
| AgentFail;
|
|
62
47
|
|
|
63
48
|
// ---- Server -> Agent ----
|
|
64
49
|
|
|
65
|
-
export interface ServerWelcome {
|
|
66
|
-
type: "server.welcome";
|
|
67
|
-
agentId: string;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export interface ServerPong {
|
|
71
|
-
type: "server.pong";
|
|
72
|
-
}
|
|
73
|
-
|
|
74
50
|
export interface ServerTask {
|
|
75
51
|
type: "server.task";
|
|
76
52
|
taskId: string;
|
|
@@ -80,11 +56,6 @@ export interface ServerTask {
|
|
|
80
56
|
skillTags: string[];
|
|
81
57
|
}
|
|
82
58
|
|
|
83
|
-
export interface ServerTaskList {
|
|
84
|
-
type: "server.task_list";
|
|
85
|
-
tasks: ServerTask[];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
59
|
export interface ServerClaimAck {
|
|
89
60
|
type: "server.claim_ack";
|
|
90
61
|
taskId: string;
|
|
@@ -92,15 +63,6 @@ export interface ServerClaimAck {
|
|
|
92
63
|
reason?: string;
|
|
93
64
|
}
|
|
94
65
|
|
|
95
|
-
export interface ServerError {
|
|
96
|
-
type: "server.error";
|
|
97
|
-
message: string;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
66
|
export type ServerMessage =
|
|
101
|
-
| ServerWelcome
|
|
102
|
-
| ServerPong
|
|
103
67
|
| ServerTask
|
|
104
|
-
|
|
|
105
|
-
| ServerClaimAck
|
|
106
|
-
| ServerError;
|
|
68
|
+
| ServerClaimAck;
|