@artyfacts/openclaw 0.1.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.
@@ -0,0 +1,446 @@
1
+ /**
2
+ * Device authentication flow for Artyfacts OpenClaw adapter
3
+ *
4
+ * Implements device auth flow:
5
+ * 1. Request device code from Artyfacts
6
+ * 2. Display code for user to enter on website
7
+ * 3. Poll for completion
8
+ * 4. Store credentials locally
9
+ */
10
+ interface Credentials {
11
+ apiKey: string;
12
+ agentId: string;
13
+ agentName?: string;
14
+ expiresAt?: string;
15
+ }
16
+ /**
17
+ * Load stored credentials from disk
18
+ */
19
+ declare function loadCredentials(): Credentials | null;
20
+ /**
21
+ * Save credentials to disk
22
+ */
23
+ declare function saveCredentials(credentials: Credentials): void;
24
+ /**
25
+ * Clear stored credentials
26
+ */
27
+ declare function clearCredentials(): void;
28
+ /**
29
+ * Prompt user for manual API key entry
30
+ */
31
+ declare function promptForApiKey(): Promise<Credentials>;
32
+ /**
33
+ * Get credentials, running auth flow if needed
34
+ */
35
+ declare function getCredentials(options?: {
36
+ baseUrl?: string;
37
+ forceAuth?: boolean;
38
+ }): Promise<Credentials>;
39
+
40
+ /**
41
+ * OpenClaw executor for Artyfacts tasks
42
+ *
43
+ * Executes tasks by shelling out to the OpenClaw CLI.
44
+ * Uses the user's existing OpenClaw Gateway - no separate API key needed.
45
+ *
46
+ * Supports fetching full context (organization, project, artifact, related sections)
47
+ * to provide OpenClaw with the information needed to complete tasks effectively.
48
+ */
49
+ interface TaskContext {
50
+ /** Task ID (section ID) */
51
+ taskId: string;
52
+ /** Task heading/title */
53
+ heading: string;
54
+ /** Task content/description */
55
+ content: string;
56
+ /** Parent artifact ID */
57
+ artifactId: string;
58
+ /** Parent artifact title */
59
+ artifactTitle?: string;
60
+ /** Task priority (1=high, 2=medium, 3=low) */
61
+ priority?: number;
62
+ /** Additional context */
63
+ context?: Record<string, unknown>;
64
+ }
65
+ interface ExecutionResult {
66
+ /** Whether execution was successful */
67
+ success: boolean;
68
+ /** The generated output */
69
+ output: string;
70
+ /** Summary of what was accomplished */
71
+ summary: string;
72
+ /** Any error message if failed */
73
+ error?: string;
74
+ /** The prompt that was used (for debugging) */
75
+ promptUsed?: string;
76
+ }
77
+ interface ExecutorConfig {
78
+ /** Path to openclaw CLI (default: 'openclaw') */
79
+ openclawPath?: string;
80
+ /** Timeout in milliseconds (default: 5 minutes) */
81
+ timeout?: number;
82
+ /** System prompt prefix */
83
+ systemPromptPrefix?: string;
84
+ /** Artyfacts API base URL (for fetching context) */
85
+ baseUrl?: string;
86
+ /** Artyfacts API key (for fetching context) */
87
+ apiKey?: string;
88
+ /** Whether to use full context from API (default: true if apiKey provided) */
89
+ useFullContext?: boolean;
90
+ /** OpenClaw session key to use (optional) */
91
+ sessionKey?: string;
92
+ }
93
+ declare class OpenClawExecutor {
94
+ private config;
95
+ private contextFetcher;
96
+ constructor(config?: ExecutorConfig);
97
+ /**
98
+ * Check if OpenClaw CLI is installed
99
+ */
100
+ isInstalled(): Promise<boolean>;
101
+ /**
102
+ * Get OpenClaw version
103
+ */
104
+ getVersion(): Promise<string | null>;
105
+ /**
106
+ * Execute a task using OpenClaw CLI
107
+ */
108
+ execute(task: TaskContext): Promise<ExecutionResult>;
109
+ /**
110
+ * Run OpenClaw CLI with the given prompt
111
+ */
112
+ private runOpenClaw;
113
+ /**
114
+ * Build the task prompt
115
+ */
116
+ private buildTaskPrompt;
117
+ /**
118
+ * Parse the response to extract content and summary
119
+ */
120
+ private parseResponse;
121
+ }
122
+ declare function createExecutor(config?: ExecutorConfig): OpenClawExecutor;
123
+
124
+ /**
125
+ * SSE Event Listener for Artyfacts task assignments
126
+ *
127
+ * Connects to the Artyfacts SSE stream and listens for task_assigned events.
128
+ * Uses EventSource for automatic reconnection handling.
129
+ */
130
+ interface TaskAssignedEvent {
131
+ type: 'task_assigned';
132
+ timestamp: string;
133
+ data: {
134
+ taskId: string;
135
+ sectionId: string;
136
+ heading: string;
137
+ content: string;
138
+ artifactId: string;
139
+ artifactTitle?: string;
140
+ priority?: number;
141
+ assignedTo: string;
142
+ assignedAt: string;
143
+ };
144
+ }
145
+ interface McpConnectRequestEvent {
146
+ type: 'mcp_connect_request';
147
+ timestamp: string;
148
+ data: {
149
+ connection_id: string;
150
+ platform: string;
151
+ config: {
152
+ server_name?: string;
153
+ connection_string?: string;
154
+ api_key?: string;
155
+ [key: string]: unknown;
156
+ };
157
+ };
158
+ }
159
+ interface HeartbeatEvent {
160
+ type: 'heartbeat';
161
+ timestamp: string;
162
+ }
163
+ interface ConnectedEvent {
164
+ type: 'connected';
165
+ timestamp: string;
166
+ data: {
167
+ agentId: string;
168
+ };
169
+ }
170
+ type ArtyfactsEvent = TaskAssignedEvent | HeartbeatEvent | ConnectedEvent | McpConnectRequestEvent | {
171
+ type: string;
172
+ timestamp: string;
173
+ data?: Record<string, unknown>;
174
+ };
175
+ type EventCallback<T extends ArtyfactsEvent = ArtyfactsEvent> = (event: T) => void | Promise<void>;
176
+ interface ListenerConfig {
177
+ /** Artyfacts API key */
178
+ apiKey: string;
179
+ /** Agent ID to listen for */
180
+ agentId: string;
181
+ /** Base URL for Artyfacts API */
182
+ baseUrl?: string;
183
+ /** Callback for state changes */
184
+ onStateChange?: (state: ConnectionState) => void;
185
+ /** Callback for errors */
186
+ onError?: (error: Error) => void;
187
+ }
188
+ type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
189
+ declare class ArtyfactsListener {
190
+ private config;
191
+ private eventSource;
192
+ private callbacks;
193
+ private allCallbacks;
194
+ private state;
195
+ private reconnectAttempts;
196
+ private maxReconnectAttempts;
197
+ private reconnectDelay;
198
+ constructor(config: ListenerConfig);
199
+ /**
200
+ * Get current connection state
201
+ */
202
+ get connectionState(): ConnectionState;
203
+ /**
204
+ * Check if connected
205
+ */
206
+ get isConnected(): boolean;
207
+ /**
208
+ * Subscribe to all events
209
+ */
210
+ subscribe(callback: EventCallback): () => void;
211
+ /**
212
+ * Subscribe to a specific event type
213
+ */
214
+ on<T extends ArtyfactsEvent>(type: string, callback: EventCallback<T>): () => void;
215
+ /**
216
+ * Connect to the SSE stream
217
+ */
218
+ connect(): void;
219
+ /**
220
+ * Disconnect from the SSE stream
221
+ */
222
+ disconnect(): void;
223
+ /**
224
+ * Reconnect to the SSE stream
225
+ */
226
+ reconnect(): void;
227
+ /**
228
+ * Handle incoming SSE message
229
+ */
230
+ private handleMessage;
231
+ /**
232
+ * Safely call a callback, handling async and errors
233
+ */
234
+ private safeCallCallback;
235
+ /**
236
+ * Handle SSE error
237
+ */
238
+ private handleError;
239
+ /**
240
+ * Update connection state
241
+ */
242
+ private setState;
243
+ }
244
+ /**
245
+ * Create an Artyfacts event listener
246
+ */
247
+ declare function createListener(config: ListenerConfig): ArtyfactsListener;
248
+
249
+ /**
250
+ * Context fetcher for Artyfacts tasks
251
+ *
252
+ * Fetches full context including organization, project, artifact, and related sections.
253
+ */
254
+ interface OrganizationContext {
255
+ id: string;
256
+ name: string;
257
+ context?: string;
258
+ }
259
+ interface ProjectContext {
260
+ id: string;
261
+ name: string;
262
+ description?: string;
263
+ }
264
+ interface SectionContext {
265
+ id: string;
266
+ heading: string;
267
+ content?: string;
268
+ section_type?: string;
269
+ task_status?: string;
270
+ }
271
+ interface ArtifactContext {
272
+ id: string;
273
+ title: string;
274
+ summary?: string;
275
+ description?: string;
276
+ artifact_type?: string;
277
+ sections: SectionContext[];
278
+ }
279
+ interface TaskFullContext {
280
+ task: {
281
+ id: string;
282
+ heading: string;
283
+ content: string;
284
+ expected_output?: {
285
+ format?: string;
286
+ requirements?: string[];
287
+ };
288
+ priority?: number;
289
+ };
290
+ artifact: ArtifactContext;
291
+ project?: ProjectContext;
292
+ organization: OrganizationContext;
293
+ }
294
+ interface ContextFetcherConfig {
295
+ baseUrl: string;
296
+ apiKey: string;
297
+ }
298
+ declare class ContextFetcher {
299
+ private config;
300
+ constructor(config: ContextFetcherConfig);
301
+ /**
302
+ * Fetch full context for a task
303
+ */
304
+ fetchTaskContext(taskId: string): Promise<TaskFullContext>;
305
+ }
306
+ /**
307
+ * Build a rich prompt with full context
308
+ */
309
+ declare function buildPromptWithContext(context: TaskFullContext): string;
310
+ declare function createContextFetcher(config: ContextFetcherConfig): ContextFetcher;
311
+
312
+ /**
313
+ * MCP connection handler for OpenClaw
314
+ *
315
+ * Manages the configuration of Artyfacts MCP server in OpenClaw.
316
+ * OpenClaw uses `openclaw mcp set/unset` for MCP server management.
317
+ */
318
+ interface McpConfig {
319
+ /** Name for the MCP server entry */
320
+ name?: string;
321
+ /** API key for authentication */
322
+ apiKey: string;
323
+ /** Base URL for Artyfacts API */
324
+ baseUrl?: string;
325
+ /** Path to openclaw CLI */
326
+ openclawPath?: string;
327
+ }
328
+ interface McpStatus {
329
+ /** Whether MCP is configured */
330
+ configured: boolean;
331
+ /** Name of the configured server */
332
+ name?: string;
333
+ /** Any error message */
334
+ error?: string;
335
+ }
336
+ declare class McpHandler {
337
+ private config;
338
+ private openclawPath;
339
+ constructor(config: McpConfig);
340
+ /**
341
+ * Check if Artyfacts MCP server is already configured
342
+ */
343
+ isConfigured(): McpStatus;
344
+ /**
345
+ * Configure Artyfacts MCP server in OpenClaw
346
+ *
347
+ * Uses: openclaw mcp set <name> --command "npx" --args "-y @artyfacts/mcp-server"
348
+ */
349
+ configure(): boolean;
350
+ /**
351
+ * Alternative configuration approach using JSON config
352
+ */
353
+ private configureAlternative;
354
+ /**
355
+ * Print manual configuration instructions
356
+ */
357
+ private printManualInstructions;
358
+ /**
359
+ * Remove Artyfacts MCP configuration
360
+ */
361
+ remove(): boolean;
362
+ /**
363
+ * Ensure MCP is configured, configure if needed
364
+ */
365
+ ensureConfigured(): boolean;
366
+ }
367
+ declare function createMcpHandler(config: McpConfig): McpHandler;
368
+
369
+ /**
370
+ * Introspect OpenClaw local configuration
371
+ * Reads config files and returns structured data for Artyfacts import
372
+ */
373
+ interface CronJob {
374
+ jobId: string;
375
+ name?: string;
376
+ schedule: {
377
+ kind: 'at' | 'every' | 'cron';
378
+ at?: string;
379
+ every?: number;
380
+ cron?: string;
381
+ timezone?: string;
382
+ };
383
+ payload: {
384
+ kind: 'systemEvent' | 'agentTurn';
385
+ message?: string;
386
+ };
387
+ delivery?: {
388
+ mode: 'none' | 'announce' | 'webhook';
389
+ channel?: string;
390
+ to?: string;
391
+ };
392
+ enabled?: boolean;
393
+ }
394
+ interface HeartbeatConfig {
395
+ every?: string;
396
+ model?: string;
397
+ prompt?: string;
398
+ target?: string;
399
+ to?: string;
400
+ lightContext?: boolean;
401
+ isolatedSession?: boolean;
402
+ activeHours?: {
403
+ start: string;
404
+ end: string;
405
+ };
406
+ }
407
+ interface AgentConfig {
408
+ id: string;
409
+ name?: string;
410
+ default?: boolean;
411
+ heartbeat?: HeartbeatConfig;
412
+ model?: string;
413
+ systemPrompt?: string;
414
+ }
415
+ interface McpServer {
416
+ name: string;
417
+ command?: string;
418
+ args?: string[];
419
+ url?: string;
420
+ transport?: 'stdio' | 'http' | 'sse';
421
+ env?: Record<string, string>;
422
+ }
423
+ interface Skill {
424
+ name: string;
425
+ path: string;
426
+ description?: string;
427
+ content?: string;
428
+ }
429
+ interface OpenClawConfig {
430
+ crons: CronJob[];
431
+ heartbeat: HeartbeatConfig | null;
432
+ agents: AgentConfig[];
433
+ mcpServers: McpServer[];
434
+ skills: Skill[];
435
+ channels: string[];
436
+ }
437
+ /**
438
+ * Introspect all OpenClaw configuration
439
+ */
440
+ declare function introspect(): Promise<OpenClawConfig>;
441
+ /**
442
+ * Get a summary of the configuration for display
443
+ */
444
+ declare function summarize(config: OpenClawConfig): string;
445
+
446
+ export { type AgentConfig, ArtyfactsListener, ContextFetcher, type Credentials, type CronJob, type ExecutionResult, type ExecutorConfig, type HeartbeatConfig, type ListenerConfig, type McpConfig, type McpConnectRequestEvent, McpHandler, type McpServer, type McpStatus, type OpenClawConfig, OpenClawExecutor, type Skill, type TaskAssignedEvent, type TaskContext, type TaskFullContext, buildPromptWithContext, clearCredentials, createContextFetcher, createExecutor, createListener, createMcpHandler, getCredentials, introspect, loadCredentials, promptForApiKey, saveCredentials, summarize };