@clawhive/openclaw-plugin 0.2.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.
Files changed (80) hide show
  1. package/README.md +217 -0
  2. package/dist/api.d.ts +6 -0
  3. package/dist/api.js +6 -0
  4. package/dist/index.d.ts +4 -0
  5. package/dist/index.js +324 -0
  6. package/dist/runtime-api.d.ts +1 -0
  7. package/dist/runtime-api.js +1 -0
  8. package/dist/setup-entry.d.ts +4 -0
  9. package/dist/setup-entry.js +3 -0
  10. package/dist/src/agency-install/claimLoop.d.ts +41 -0
  11. package/dist/src/agency-install/claimLoop.js +188 -0
  12. package/dist/src/agent-panel/claimLoop.d.ts +32 -0
  13. package/dist/src/agent-panel/claimLoop.js +118 -0
  14. package/dist/src/agent-panel/executor.d.ts +8 -0
  15. package/dist/src/agent-panel/executor.js +368 -0
  16. package/dist/src/agent-panel/plan.d.ts +20 -0
  17. package/dist/src/agent-panel/plan.js +111 -0
  18. package/dist/src/agent-panel/prompts.d.ts +38 -0
  19. package/dist/src/agent-panel/prompts.js +87 -0
  20. package/dist/src/agent-panel/types.d.ts +45 -0
  21. package/dist/src/agent-panel/types.js +1 -0
  22. package/dist/src/agents.d.ts +44 -0
  23. package/dist/src/agents.js +195 -0
  24. package/dist/src/authorization.d.ts +34 -0
  25. package/dist/src/authorization.js +183 -0
  26. package/dist/src/channel.d.ts +5 -0
  27. package/dist/src/channel.js +93 -0
  28. package/dist/src/claimPolling.d.ts +9 -0
  29. package/dist/src/claimPolling.js +13 -0
  30. package/dist/src/client.d.ts +386 -0
  31. package/dist/src/client.js +595 -0
  32. package/dist/src/config.d.ts +28 -0
  33. package/dist/src/config.js +94 -0
  34. package/dist/src/defaults.d.ts +40 -0
  35. package/dist/src/defaults.js +52 -0
  36. package/dist/src/deviceCode.d.ts +16 -0
  37. package/dist/src/deviceCode.js +65 -0
  38. package/dist/src/heartbeat.d.ts +25 -0
  39. package/dist/src/heartbeat.js +65 -0
  40. package/dist/src/imageAttachments.d.ts +14 -0
  41. package/dist/src/imageAttachments.js +81 -0
  42. package/dist/src/inbound.d.ts +10 -0
  43. package/dist/src/inbound.js +140 -0
  44. package/dist/src/installMutex.d.ts +4 -0
  45. package/dist/src/installMutex.js +18 -0
  46. package/dist/src/market-install/claimLoop.d.ts +41 -0
  47. package/dist/src/market-install/claimLoop.js +183 -0
  48. package/dist/src/market-install/downloader.d.ts +36 -0
  49. package/dist/src/market-install/downloader.js +133 -0
  50. package/dist/src/market-install/executor.d.ts +28 -0
  51. package/dist/src/market-install/executor.js +352 -0
  52. package/dist/src/market-install/types.d.ts +62 -0
  53. package/dist/src/market-install/types.js +1 -0
  54. package/dist/src/market-install/verifier.d.ts +32 -0
  55. package/dist/src/market-install/verifier.js +60 -0
  56. package/dist/src/market-publish/packager.d.ts +34 -0
  57. package/dist/src/market-publish/packager.js +168 -0
  58. package/dist/src/market-publish/publishFlow.d.ts +70 -0
  59. package/dist/src/market-publish/publishFlow.js +107 -0
  60. package/dist/src/market-publish/uploader.d.ts +73 -0
  61. package/dist/src/market-publish/uploader.js +132 -0
  62. package/dist/src/openclawVersion.d.ts +4 -0
  63. package/dist/src/openclawVersion.js +13 -0
  64. package/dist/src/outbound.d.ts +13 -0
  65. package/dist/src/outbound.js +41 -0
  66. package/dist/src/pairing.d.ts +32 -0
  67. package/dist/src/pairing.js +64 -0
  68. package/dist/src/runtime.d.ts +52 -0
  69. package/dist/src/runtime.js +26 -0
  70. package/dist/src/telemetry.d.ts +34 -0
  71. package/dist/src/telemetry.js +89 -0
  72. package/dist/src/transport/realtime.d.ts +49 -0
  73. package/dist/src/transport/realtime.js +273 -0
  74. package/dist/src/transport.d.ts +38 -0
  75. package/dist/src/transport.js +15 -0
  76. package/dist/src/wake.d.ts +31 -0
  77. package/dist/src/wake.js +101 -0
  78. package/openclaw.config.example.yaml +10 -0
  79. package/openclaw.plugin.json +122 -0
  80. package/package.json +84 -0
@@ -0,0 +1,386 @@
1
+ import type { ClaimedPanelTurn, PanelContribution, PanelContributionStatus, PanelPlan, PanelPlanAssignment, PanelTurnStatus } from "./agent-panel/types.js";
2
+ import type { MarketInstallAgentManifest, MarketInstallClaimedJob, MarketInstallReasonKind, MarketInstallUpdateStatus } from "./market-install/types.js";
3
+ export type ClawHivePluginConfig = {
4
+ projectUrl: string;
5
+ pluginToken?: string | null;
6
+ anonKey: string;
7
+ userId?: string | null;
8
+ pluginNodeId?: string | null;
9
+ nodeName?: string;
10
+ pluginVersion?: string;
11
+ };
12
+ export type DeviceCodeStartResult = {
13
+ device_code: string;
14
+ user_code: string;
15
+ verification_uri: string;
16
+ verification_uri_complete: string;
17
+ expires_in: number;
18
+ interval: number;
19
+ poll_interval_seconds: number;
20
+ };
21
+ export type DeviceCodeExchangeSuccess = {
22
+ status: "approved";
23
+ user_id: string;
24
+ plugin_token: string;
25
+ };
26
+ export type DeviceCodeExchangePending = {
27
+ status: "pending";
28
+ interval: number;
29
+ };
30
+ export type DeviceCodeExchangeResult = DeviceCodeExchangeSuccess | DeviceCodeExchangePending;
31
+ export declare class DeviceCodeExpiredError extends Error {
32
+ constructor();
33
+ }
34
+ export declare class DeviceCodeDeniedError extends Error {
35
+ constructor();
36
+ }
37
+ export type UserSession = {
38
+ access_token: string;
39
+ refresh_token: string;
40
+ expires_in?: number;
41
+ expires_at?: number;
42
+ token_type?: string;
43
+ };
44
+ export type PluginNode = {
45
+ id: string;
46
+ user_id: string;
47
+ node_name?: string | null;
48
+ plugin_version?: string | null;
49
+ plugin_status: "online" | "offline" | "degraded";
50
+ last_heartbeat_at?: string | null;
51
+ };
52
+ export type PluginRegisterResult = {
53
+ plugin_node: PluginNode;
54
+ user_id: string;
55
+ user_created: boolean;
56
+ realtime_topic: string;
57
+ heartbeat_interval: number;
58
+ user_session: UserSession;
59
+ };
60
+ export type PairingCodeResult = {
61
+ pair_token: string;
62
+ expires_at: string;
63
+ pairing_code: {
64
+ id: string;
65
+ expires_at: string;
66
+ max_attempts: number;
67
+ plugin_node_id: string;
68
+ };
69
+ };
70
+ export type SyncAgentInput = {
71
+ openclawAgentId: string;
72
+ name: string;
73
+ description?: string | null;
74
+ avatarUrl?: string | null;
75
+ config?: Record<string, unknown>;
76
+ };
77
+ export type SyncedAgent = {
78
+ id: string;
79
+ user_id: string;
80
+ openclaw_agent_id: string;
81
+ name: string;
82
+ description: string | null;
83
+ avatar_url: string | null;
84
+ source_type: string;
85
+ config: Record<string, unknown>;
86
+ created_at: string;
87
+ };
88
+ export type SyncAgentsResult = {
89
+ items: SyncedAgent[];
90
+ skipped: number;
91
+ };
92
+ export type AppendedMessage = {
93
+ id: string;
94
+ session_id: string;
95
+ agent_id: string;
96
+ user_id: string;
97
+ sequence: number;
98
+ role: string;
99
+ type: string;
100
+ content: string;
101
+ client_message_id?: string | null;
102
+ created_at: string;
103
+ metadata?: Record<string, unknown>;
104
+ };
105
+ export type SyncMessagesResult = {
106
+ items: AppendedMessage[];
107
+ next_cursor: number;
108
+ has_more: boolean;
109
+ };
110
+ export type MarketInstallClaimResult = {
111
+ job: MarketInstallClaimedJob | null;
112
+ };
113
+ export type MarketInstallUpdateResult = {
114
+ job: {
115
+ createdAt: string | null;
116
+ failureReason: string | null;
117
+ finishedAt?: string | null;
118
+ jobId: string;
119
+ listingId: string | null;
120
+ listingName: string | null;
121
+ reasonKind: string | null;
122
+ releaseId: string;
123
+ status: MarketInstallUpdateStatus | "queued" | "dispatched";
124
+ targetNodeId: string | null;
125
+ targetNodeName: string | null;
126
+ updatedAt: string;
127
+ version: string | null;
128
+ };
129
+ };
130
+ export type MarketInstallManifestResult = {
131
+ manifest: MarketInstallAgentManifest;
132
+ };
133
+ export type MarketListingStatus = "archived" | "draft" | "published" | "suspended";
134
+ export type CreateMarketListingParams = {
135
+ accessToken: string;
136
+ listingId?: string;
137
+ name: string;
138
+ slug: string;
139
+ authorDisplayName?: string;
140
+ summary?: string;
141
+ description?: string;
142
+ category?: string;
143
+ license?: string;
144
+ avatarUrl?: string;
145
+ tags?: string[];
146
+ sourceNodeId?: string | null;
147
+ status?: MarketListingStatus;
148
+ };
149
+ export type CreateMarketReleaseParams = {
150
+ accessToken: string;
151
+ listingId: string;
152
+ version: string;
153
+ storagePath: string;
154
+ fingerprint: string;
155
+ sourceType: "manifest" | "git_ref" | "plugin_node";
156
+ sourceRef: string;
157
+ publish: boolean;
158
+ minPluginVersion?: string;
159
+ minOpenClawVersion?: string;
160
+ compatibilityNotes?: string;
161
+ };
162
+ export type AgentPanelTurnClaimResult = {
163
+ turn: ClaimedPanelTurn | null;
164
+ };
165
+ export type ClawHiveApiErrorPayload = {
166
+ status: number;
167
+ error: string;
168
+ details?: unknown;
169
+ };
170
+ export declare class ClawHiveApiError extends Error {
171
+ readonly status: number;
172
+ readonly errorCode: string;
173
+ readonly details?: unknown;
174
+ constructor(payload: ClawHiveApiErrorPayload);
175
+ }
176
+ export declare class ClawHiveCloudApi {
177
+ private readonly config;
178
+ constructor(config: ClawHivePluginConfig);
179
+ get baseUrl(): string;
180
+ get userId(): string | null;
181
+ get pluginToken(): string | null;
182
+ private requireUserId;
183
+ private requirePluginToken;
184
+ startDeviceCode(opts?: {
185
+ nodeName?: string;
186
+ pluginVersion?: string;
187
+ description?: string;
188
+ }): Promise<DeviceCodeStartResult>;
189
+ exchangeDeviceCode(deviceCode: string): Promise<DeviceCodeExchangeResult>;
190
+ registerPluginNode(): Promise<PluginRegisterResult>;
191
+ createPairingCode(pluginNodeId: string, ttlSeconds?: number): Promise<PairingCodeResult>;
192
+ heartbeat(params: {
193
+ pluginNodeId: string;
194
+ status?: "online" | "offline" | "degraded";
195
+ }): Promise<{
196
+ plugin_node: PluginNode;
197
+ }>;
198
+ writeAgentMessage(params: {
199
+ pluginNodeId: string;
200
+ sessionId: string;
201
+ agentId: string;
202
+ content: string;
203
+ type?: "text" | "image" | "file" | "system";
204
+ metadata?: Record<string, unknown>;
205
+ clientMessageId?: string;
206
+ role?: "agent" | "system";
207
+ }): Promise<{
208
+ message: AppendedMessage;
209
+ }>;
210
+ syncAgents(agents: SyncAgentInput[]): Promise<SyncAgentsResult>;
211
+ refreshUserSession(refreshToken: string): Promise<UserSession>;
212
+ syncMessages(params: {
213
+ accessToken: string;
214
+ sessionId: string;
215
+ afterSequence?: number;
216
+ limit?: number;
217
+ }): Promise<SyncMessagesResult>;
218
+ getMessageAttachmentDownloadUrl(params: {
219
+ messageId: string;
220
+ storagePath: string;
221
+ }): Promise<{
222
+ signedUrl: string;
223
+ expiresIn: number;
224
+ mimeType: string;
225
+ }>;
226
+ /**
227
+ * Claim the oldest queued install job for the current plugin node.
228
+ */
229
+ claimInstallJob(params: {
230
+ pluginNodeId: string;
231
+ userId?: string;
232
+ }): Promise<MarketInstallClaimResult>;
233
+ /**
234
+ * Persist node-side install execution state back to the durable market job.
235
+ */
236
+ updateInstallJob(params: {
237
+ pluginNodeId: string;
238
+ jobId: string;
239
+ status: MarketInstallUpdateStatus;
240
+ userId?: string;
241
+ reasonKind?: MarketInstallReasonKind;
242
+ errorMessage?: string;
243
+ details?: Record<string, unknown>;
244
+ }): Promise<MarketInstallUpdateResult>;
245
+ /**
246
+ * Fetch the approved manifest payload for one claimed install job.
247
+ */
248
+ fetchInstallManifest(params: {
249
+ pluginNodeId: string;
250
+ jobId: string;
251
+ userId?: string;
252
+ }): Promise<MarketInstallManifestResult>;
253
+ /**
254
+ * Claim the oldest queued Agency install job for the current plugin node.
255
+ */
256
+ claimAgencyInstallJob(params: {
257
+ pluginNodeId: string;
258
+ userId?: string;
259
+ }): Promise<MarketInstallClaimResult>;
260
+ /**
261
+ * Persist node-side Agency install execution state back to the durable job.
262
+ */
263
+ updateAgencyInstallJob(params: {
264
+ pluginNodeId: string;
265
+ jobId: string;
266
+ status: MarketInstallUpdateStatus;
267
+ userId?: string;
268
+ reasonKind?: MarketInstallReasonKind;
269
+ errorMessage?: string;
270
+ details?: Record<string, unknown>;
271
+ }): Promise<MarketInstallUpdateResult>;
272
+ /**
273
+ * Fetch the approved Agency manifest payload for one claimed install job.
274
+ */
275
+ fetchAgencyInstallManifest(params: {
276
+ pluginNodeId: string;
277
+ jobId: string;
278
+ userId?: string;
279
+ }): Promise<MarketInstallManifestResult>;
280
+ createMarketListing(params: CreateMarketListingParams): Promise<{
281
+ listing: Record<string, unknown>;
282
+ }>;
283
+ createMarketRelease(params: CreateMarketReleaseParams): Promise<{
284
+ release: Record<string, unknown>;
285
+ }>;
286
+ claimPanelTurn(params: {
287
+ pluginNodeId: string;
288
+ userId?: string;
289
+ }): Promise<AgentPanelTurnClaimResult>;
290
+ updatePanelContribution(params: {
291
+ contributionId: string;
292
+ status: PanelContributionStatus;
293
+ content?: string | null;
294
+ errorMessage?: string | null;
295
+ startedAt?: string | null;
296
+ completedAt?: string | null;
297
+ assignment?: PanelPlanAssignment | null;
298
+ }): Promise<void>;
299
+ createPanelContribution(params: {
300
+ turnId: string;
301
+ agentId: string;
302
+ round: 1 | 2;
303
+ assignment?: PanelPlanAssignment | null;
304
+ }): Promise<{
305
+ contribution: PanelContribution;
306
+ }>;
307
+ updatePanelTurn(params: {
308
+ turnId: string;
309
+ status: PanelTurnStatus;
310
+ errorMessage?: string | null;
311
+ startedAt?: string | null;
312
+ completedAt?: string | null;
313
+ plan?: PanelPlan | null;
314
+ planStatus?: "pending" | "completed" | "fallback" | "failed";
315
+ planErrorMessage?: string | null;
316
+ }): Promise<void>;
317
+ /**
318
+ * Get signed download URL for a release package.
319
+ *
320
+ * This is used during install to obtain a time-limited signed URL for downloading
321
+ * the release package from Supabase Storage (D-12).
322
+ *
323
+ * The signed URL expires after 1 hour. If download fails with 403, the caller should
324
+ * retry by calling this method again to get a fresh signed URL.
325
+ *
326
+ * @param releaseId - Release UUID
327
+ * @param accessToken - User JWT access token
328
+ * @returns Signed URL, fingerprint, and expiry time
329
+ * @throws {ClawHiveApiError} If release is withdrawn (410), not found (404), or other errors
330
+ */
331
+ getSignedDownloadUrl(releaseId: string, accessToken: string): Promise<{
332
+ signed_url: string;
333
+ fingerprint: string;
334
+ expires_in: number;
335
+ }>;
336
+ /**
337
+ * Upload a release package to Supabase Storage.
338
+ *
339
+ * This is step 1 of the two-step publish flow (D-08):
340
+ * 1. Upload the tar.gz to Storage via this method → receive storage_path + fingerprint
341
+ * 2. Call market-releases-create with the storage_path + fingerprint + release metadata
342
+ *
343
+ * The upload is idempotent: uploading the same content to the same path is safe.
344
+ * Storage path format: releases/{listing_id}/{version}.tar.gz (D-09)
345
+ * Size limit: 10 MiB (D-10), enforced by the edge function
346
+ *
347
+ * Example usage:
348
+ * ```typescript
349
+ * import { packageAgentDirectory } from "./market-publish/packager.js";
350
+ *
351
+ * // Step 1: Package and upload
352
+ * const pkg = await packageAgentDirectory({ agentDir: "/path/to/agent" });
353
+ * const uploadResult = await client.uploadReleasePackage({
354
+ * listingId: "listing-uuid",
355
+ * version: "v1.0.0",
356
+ * buffer: pkg.buffer,
357
+ * fingerprint: pkg.fingerprint,
358
+ * accessToken: "user-jwt",
359
+ * });
360
+ *
361
+ * // Step 2: Create release record
362
+ * await client.createMarketRelease({
363
+ * listingId: uploadResult.listing_id,
364
+ * version: "v1.0.0",
365
+ * storagePath: uploadResult.storage_path,
366
+ * fingerprint: uploadResult.fingerprint,
367
+ * // ... other release metadata
368
+ * });
369
+ * ```
370
+ *
371
+ * @param params - Upload parameters
372
+ * @returns Upload result with storage_path and fingerprint
373
+ */
374
+ uploadReleasePackage(params: {
375
+ listingId: string;
376
+ version: string;
377
+ buffer: Buffer;
378
+ fingerprint: string;
379
+ accessToken: string;
380
+ onProgress?: (uploaded: number, total: number) => void;
381
+ }): Promise<{
382
+ storage_path: string;
383
+ fingerprint: string;
384
+ }>;
385
+ private request;
386
+ }