openviber 0.4.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.
@@ -0,0 +1,1691 @@
1
+ import { ModelMessage, LanguageModel } from 'ai';
2
+ export { Output, ToolLoopAgent, generateText, stepCountIs, streamText } from 'ai';
3
+ import * as _openrouter_ai_sdk_provider from '@openrouter/ai-sdk-provider';
4
+ import * as _ai_sdk_deepseek from '@ai-sdk/deepseek';
5
+ import * as _ai_sdk_openai from '@ai-sdk/openai';
6
+ import { z } from 'zod';
7
+ import * as zustand from 'zustand';
8
+ import { EventEmitter } from 'events';
9
+
10
+ /**
11
+ * Task - Individual execution units within a space
12
+ */
13
+ declare enum TaskStatus {
14
+ PENDING = "pending",
15
+ RUNNING = "running",
16
+ COMPLETED = "completed",
17
+ FAILED = "failed",
18
+ BLOCKED = "blocked",
19
+ CANCELLED = "cancelled"
20
+ }
21
+ interface TaskStep {
22
+ id: string;
23
+ description: string;
24
+ status: TaskStatus;
25
+ startedAt?: Date;
26
+ completedAt?: Date;
27
+ error?: string;
28
+ }
29
+ interface TaskDependency {
30
+ taskId: string;
31
+ type: "required" | "optional";
32
+ }
33
+ declare class Task$1 {
34
+ id: string;
35
+ title: string;
36
+ description: string;
37
+ status: TaskStatus;
38
+ assignedTo?: string;
39
+ priority: "low" | "medium" | "high";
40
+ estimatedTime?: string;
41
+ actualTime?: string;
42
+ dependencies: TaskDependency[];
43
+ steps: TaskStep[];
44
+ tags: string[];
45
+ metadata: Record<string, any>;
46
+ createdAt: Date;
47
+ updatedAt: Date;
48
+ startedAt?: Date;
49
+ completedAt?: Date;
50
+ error?: string;
51
+ constructor({ id, title, description, status, assignedTo, priority, estimatedTime, dependencies, steps, tags, metadata, }: {
52
+ id: string;
53
+ title: string;
54
+ description: string;
55
+ status?: TaskStatus;
56
+ assignedTo?: string;
57
+ priority?: "low" | "medium" | "high";
58
+ estimatedTime?: string;
59
+ dependencies?: TaskDependency[];
60
+ steps?: TaskStep[];
61
+ tags?: string[];
62
+ metadata?: Record<string, any>;
63
+ });
64
+ start(): void;
65
+ complete(): void;
66
+ fail(error: string): void;
67
+ block(reason: string): void;
68
+ cancel(): void;
69
+ isActionable(context?: {
70
+ getTaskStatus: (id: string) => TaskStatus | undefined;
71
+ }): boolean;
72
+ hasBlockingDependencies(context?: {
73
+ getTaskStatus: (id: string) => TaskStatus | undefined;
74
+ }): boolean;
75
+ private calculateDuration;
76
+ toJSON(): any;
77
+ static fromJSON(data: any): Task$1;
78
+ }
79
+
80
+ /**
81
+ * Plan - Manages the execution plan for a space
82
+ */
83
+
84
+ interface PlanSummary {
85
+ totalTasks: number;
86
+ completedTasks: number;
87
+ runningTasks: number;
88
+ pendingTasks: number;
89
+ failedTasks: number;
90
+ blockedTasks: number;
91
+ progressPercentage: number;
92
+ }
93
+ declare class Plan {
94
+ tasks: Task$1[];
95
+ goal: string;
96
+ createdAt: Date;
97
+ updatedAt: Date;
98
+ constructor({ tasks, goal }: {
99
+ tasks?: Task$1[];
100
+ goal: string;
101
+ });
102
+ addTask(task: Task$1): void;
103
+ removeTask(taskId: string): boolean;
104
+ getTaskById(taskId: string): Task$1 | undefined;
105
+ updateTaskStatus(taskId: string, status: TaskStatus): boolean;
106
+ getNextActionableTask(): Task$1 | undefined;
107
+ getAllActionableTasks(maxTasks?: number): Task$1[];
108
+ getTasksByStatus(status: TaskStatus): Task$1[];
109
+ getTasksByAssignee(assignee: string): Task$1[];
110
+ isComplete(): boolean;
111
+ hasFailedTasks(): boolean;
112
+ hasBlockedTasks(): boolean;
113
+ getProgressSummary(): PlanSummary;
114
+ reorderTasks(fromIndex: number, toIndex: number): void;
115
+ toJSON(): any;
116
+ static fromJSON(data: any): Plan;
117
+ }
118
+
119
+ /**
120
+ * Shared types for Viber engine
121
+ */
122
+ interface ViberError extends Error {
123
+ code: string;
124
+ details?: any;
125
+ }
126
+ interface StreamChunk {
127
+ type: 'text' | 'tool_call' | 'tool_result' | 'error' | 'done';
128
+ content?: string;
129
+ tool?: {
130
+ name: string;
131
+ args: any;
132
+ result?: any;
133
+ };
134
+ error?: ViberError;
135
+ }
136
+ interface ModelConfig$2 {
137
+ provider: 'openai' | 'anthropic' | 'deepseek' | 'local';
138
+ model: string;
139
+ temperature?: number;
140
+ maxTokens?: number;
141
+ }
142
+ interface StorageConfig {
143
+ type: 'local' | 'supabase';
144
+ basePath?: string;
145
+ supabaseUrl?: string;
146
+ supabaseKey?: string;
147
+ }
148
+ interface ViberConfig {
149
+ storage: StorageConfig;
150
+ model: ModelConfig$2;
151
+ streaming?: boolean;
152
+ debug?: boolean;
153
+ }
154
+ /**
155
+ * Space configuration - defines what the space is and how it works
156
+ */
157
+ interface SpaceConfig {
158
+ name: string;
159
+ description?: string;
160
+ icon?: string;
161
+ agents?: string[];
162
+ agentPool?: string[];
163
+ tools?: string[];
164
+ datasets?: string[];
165
+ quickMessages?: string[];
166
+ metadata?: Record<string, any>;
167
+ [key: string]: any;
168
+ }
169
+ /**
170
+ * Internal persistence format - what Viber saves to disk
171
+ */
172
+ interface SpaceModel {
173
+ spaceId: string;
174
+ name: string;
175
+ goal: string;
176
+ createdAt: string;
177
+ updatedAt: string;
178
+ teamAgents: string[];
179
+ plan?: any;
180
+ artifacts?: any[];
181
+ }
182
+ /**
183
+ * Running space status - exposed to UI layer
184
+ * Shows real-time progress and task information
185
+ */
186
+ interface SpaceState {
187
+ spaceId: string;
188
+ name: string;
189
+ goal: string;
190
+ createdAt: string;
191
+ updatedAt: string;
192
+ teamSize: number;
193
+ tasks?: {
194
+ total: number;
195
+ completed: number;
196
+ running: number;
197
+ pending: number;
198
+ failed: number;
199
+ };
200
+ progressPercentage?: number;
201
+ }
202
+
203
+ /**
204
+ * Configuration types for Viber agents and spaces
205
+ */
206
+
207
+ interface AgentConfig {
208
+ id?: string;
209
+ name: string;
210
+ description: string;
211
+ provider?: string;
212
+ model?: string;
213
+ llm?: {
214
+ provider: string;
215
+ model: string;
216
+ settings?: {
217
+ temperature?: number;
218
+ maxTokens?: number;
219
+ topP?: number;
220
+ frequencyPenalty?: number;
221
+ presencePenalty?: number;
222
+ };
223
+ };
224
+ systemPrompt?: string;
225
+ tools?: string[];
226
+ skills?: string[];
227
+ personality?: string;
228
+ temperature?: number;
229
+ maxTokens?: number;
230
+ topP?: number;
231
+ frequencyPenalty?: number;
232
+ presencePenalty?: number;
233
+ promptFile?: string;
234
+ [key: string]: any;
235
+ }
236
+
237
+ /**
238
+ * Message types for Viber - Using AI SDK v6 types directly
239
+ */
240
+
241
+ interface ViberMessage {
242
+ role: 'system' | 'user' | 'assistant' | 'function' | 'data' | 'tool';
243
+ content: any;
244
+ id?: string;
245
+ metadata?: {
246
+ agentName?: string;
247
+ timestamp?: number;
248
+ [key: string]: any;
249
+ };
250
+ }
251
+ type Message = ViberMessage;
252
+ /**
253
+ * Get text content from a message
254
+ */
255
+ declare function getTextContent(message: Message): string;
256
+ /**
257
+ * Queued message with metadata
258
+ */
259
+ interface QueuedMessage {
260
+ id: string;
261
+ content: string;
262
+ status: 'queued' | 'processing' | 'completed' | 'error';
263
+ timestamp: number;
264
+ edited?: boolean;
265
+ error?: string;
266
+ metadata?: any;
267
+ }
268
+ /**
269
+ * Queue state for UI
270
+ */
271
+ interface QueueState {
272
+ current?: QueuedMessage;
273
+ queue: QueuedMessage[];
274
+ processing: boolean;
275
+ }
276
+ /**
277
+ * Queue listener type
278
+ */
279
+ type QueueListener = (state: QueueState) => void;
280
+ /**
281
+ * Enhanced Message Queue with management capabilities
282
+ */
283
+ declare class MessageQueue {
284
+ private queue;
285
+ private current?;
286
+ private processing;
287
+ private listeners;
288
+ private nextId;
289
+ /**
290
+ * Add message to queue
291
+ */
292
+ add(content: string, metadata?: any): string;
293
+ /**
294
+ * Get next message from queue
295
+ */
296
+ next(): QueuedMessage | undefined;
297
+ /**
298
+ * Mark current message as complete
299
+ */
300
+ complete(messageId: string): void;
301
+ /**
302
+ * Mark current message as error
303
+ */
304
+ error(messageId: string, error: string): void;
305
+ /**
306
+ * Remove message from queue
307
+ */
308
+ remove(messageId: string): boolean;
309
+ /**
310
+ * Reorder queue
311
+ */
312
+ reorder(messageId: string, newIndex: number): void;
313
+ /**
314
+ * Edit queued message
315
+ */
316
+ edit(messageId: string, content: string): void;
317
+ /**
318
+ * Clear all queued messages
319
+ */
320
+ clear(): void;
321
+ /**
322
+ * Get queue state
323
+ */
324
+ getState(): QueueState;
325
+ /**
326
+ * Subscribe to queue changes
327
+ */
328
+ subscribe(listener: QueueListener): () => void;
329
+ /**
330
+ * Check if queue is empty
331
+ */
332
+ isEmpty(): boolean;
333
+ /**
334
+ * Check if processing
335
+ */
336
+ isProcessing(): boolean;
337
+ /**
338
+ * Notify listeners
339
+ */
340
+ private notify;
341
+ }
342
+ /**
343
+ * Conversation History management
344
+ */
345
+ declare class ConversationHistory {
346
+ messages: Message[];
347
+ add(message: Message): void;
348
+ getMessages(): Message[];
349
+ getLastN(n: number): Message[];
350
+ clear(): void;
351
+ toModelMessages(): ModelMessage[];
352
+ }
353
+
354
+ /**
355
+ * Agent - Config-driven agent implementation
356
+ *
357
+ * Agents are defined entirely by configuration, not code.
358
+ * Each agent is instantiated from a config object that defines
359
+ * its role, tools, and LLM settings.
360
+ */
361
+
362
+ interface AgentContext {
363
+ spaceId: string;
364
+ taskId?: string;
365
+ conversationHistory: ConversationHistory;
366
+ metadata?: Record<string, any>;
367
+ }
368
+ interface AgentResponse {
369
+ text: string;
370
+ toolCalls?: any[];
371
+ reasoning?: string;
372
+ metadata?: Record<string, any>;
373
+ }
374
+ /**
375
+ * Config-driven Agent implementation
376
+ * No subclasses needed - behavior is entirely config-driven
377
+ */
378
+ declare class Agent$1 {
379
+ id: string;
380
+ name: string;
381
+ description: string;
382
+ config: AgentConfig;
383
+ provider: string;
384
+ model: string;
385
+ temperature?: number;
386
+ maxTokens?: number;
387
+ topP?: number;
388
+ frequencyPenalty?: number;
389
+ presencePenalty?: number;
390
+ systemPrompt?: string;
391
+ tools: string[];
392
+ skills: string[];
393
+ personality?: string;
394
+ private skillInstructions;
395
+ private loadedSkillTools;
396
+ private skillsLoaded;
397
+ constructor(config: AgentConfig);
398
+ /**
399
+ * Ensure skills are loaded from registry
400
+ */
401
+ private ensureSkillsLoaded;
402
+ /**
403
+ * Get the system prompt for this agent
404
+ */
405
+ protected getSystemPrompt(context?: AgentContext): string;
406
+ /**
407
+ * Get the model provider for this agent
408
+ */
409
+ getModel(context?: {
410
+ spaceId?: string;
411
+ userId?: string;
412
+ }): LanguageModel;
413
+ /**
414
+ * Get tools available to this agent
415
+ */
416
+ protected getTools(context?: {
417
+ spaceId?: string;
418
+ }): Promise<any>;
419
+ /**
420
+ * Prepare debug info without actually calling streamText
421
+ */
422
+ prepareDebugInfo(options: {
423
+ messages: ViberMessage[];
424
+ system?: string;
425
+ spaceId?: string;
426
+ metadata?: Record<string, any>;
427
+ }): Promise<{
428
+ systemPrompt: string;
429
+ tools: any;
430
+ model: any;
431
+ agentInfo: any;
432
+ messages: any[];
433
+ }>;
434
+ /**
435
+ * Stream text - works with ViberMessage[] internally
436
+ * Converts to ModelMessage[] only when calling AI SDK
437
+ */
438
+ streamText(options: {
439
+ messages: ViberMessage[];
440
+ system?: string;
441
+ spaceId?: string;
442
+ metadata?: Record<string, any>;
443
+ [key: string]: any;
444
+ }): Promise<any>;
445
+ /**
446
+ * Generate text - works with ViberMessage[] internally
447
+ * Converts to ModelMessage[] only when calling AI SDK
448
+ */
449
+ generateText(options: {
450
+ messages: ViberMessage[];
451
+ system?: string;
452
+ spaceId?: string;
453
+ metadata?: Record<string, any>;
454
+ [key: string]: any;
455
+ }): Promise<any>;
456
+ /**
457
+ * Get agent summary
458
+ */
459
+ getSummary(): Record<string, any>;
460
+ }
461
+
462
+ /**
463
+ * ViberAgent - The space's conversational representative
464
+ *
465
+ * X is the interface between users and their spaces. Each space has an X agent
466
+ * that acts as its representative. When you need to interact with a space, you
467
+ * talk to X. ViberAgent merges TaskExecutor and Orchestrator functionality into a
468
+ * single, user-friendly interface.
469
+ */
470
+
471
+ interface ViberOptions {
472
+ model?: string;
473
+ storageRoot?: string;
474
+ defaultGoal?: string;
475
+ spaceId?: string;
476
+ singleAgentId?: string;
477
+ }
478
+ interface ViberStreamOptions {
479
+ messages?: any[];
480
+ tools?: any;
481
+ artifactId?: string;
482
+ [key: string]: any;
483
+ }
484
+ interface ViberAgentResponse extends AgentResponse {
485
+ plan?: Plan;
486
+ taskResults?: any[];
487
+ artifacts?: any[];
488
+ preservedSteps?: string[];
489
+ regeneratedSteps?: string[];
490
+ planChanges?: Record<string, any>;
491
+ }
492
+ declare class ViberAgent extends Agent$1 {
493
+ private space;
494
+ readonly spaceId: string;
495
+ private abortController?;
496
+ private singleAgentId?;
497
+ constructor(config: AgentConfig, space: Space$1, options?: ViberOptions);
498
+ /**
499
+ * Getter for space (needed for external access)
500
+ */
501
+ getSpace(): Space$1;
502
+ /**
503
+ * Override getSystemPrompt to include plan and artifacts context
504
+ */
505
+ getSystemPrompt(context?: AgentContext): string;
506
+ /**
507
+ * Generate text - uses new AI SDK-style signature
508
+ */
509
+ generateText(options: {
510
+ messages: any[];
511
+ system?: string;
512
+ [key: string]: any;
513
+ }): Promise<any>;
514
+ /**
515
+ * ViberAgent streamText - Orchestration Layer
516
+ * Responsibilities: History management, agent delegation, persistence
517
+ */
518
+ streamText(options: {
519
+ messages: any[];
520
+ system?: string;
521
+ spaceId?: string;
522
+ metadata?: Record<string, any>;
523
+ [key: string]: any;
524
+ }): Promise<any>;
525
+ /**
526
+ * Agent Mode Handler - Direct delegation with performance optimization
527
+ * Supports both single agent and parallel execution
528
+ */
529
+ private handleAgentMode;
530
+ /**
531
+ * Handle parallel execution of multiple agents
532
+ */
533
+ private handleParallelExecution;
534
+ /**
535
+ * Update space history with new messages
536
+ * Now supports per-task history
537
+ */
538
+ private updateSpaceHistory;
539
+ /**
540
+ * Optimize message context for single-agent performance
541
+ */
542
+ private optimizeContextForAgent;
543
+ /**
544
+ * Extract user prompt from messages for orchestration
545
+ */
546
+ private extractPromptFromMessages;
547
+ /**
548
+ * Handle message persistence after streaming completes
549
+ */
550
+ private handleMessagePersistence;
551
+ /**
552
+ * Save space to storage
553
+ */
554
+ private saveSpace;
555
+ /**
556
+ * Stop current operation
557
+ */
558
+ stop(): void;
559
+ /**
560
+ * Add message to queue (soft interrupt)
561
+ */
562
+ addMessage(message: string, metadata?: any): string;
563
+ /**
564
+ * Enrich context with space information
565
+ */
566
+ private enrichContext;
567
+ /**
568
+ * Create or update the space plan
569
+ */
570
+ createPlan(goal?: string): Promise<Plan>;
571
+ /**
572
+ * Adapt the plan based on new information or user feedback
573
+ */
574
+ adaptPlan(feedback: string): Promise<Plan>;
575
+ /**
576
+ * Get plan context for system prompt
577
+ */
578
+ private getPlanContext;
579
+ /**
580
+ * Get artifacts context for system prompt
581
+ */
582
+ private getArtifactsContext;
583
+ /**
584
+ * Get ViberAgent summary
585
+ */
586
+ getSummary(): Record<string, any>;
587
+ /**
588
+ * Static factory to start a new space
589
+ */
590
+ static start(goal: string, options?: ViberOptions): Promise<ViberAgent>;
591
+ /**
592
+ * Static factory to resume an existing space
593
+ */
594
+ static resume(spaceId: string, options?: ViberOptions): Promise<ViberAgent>;
595
+ }
596
+
597
+ /**
598
+ * Base Storage - Abstract storage interface for all Viber storage needs
599
+ */
600
+ interface ArtifactInfo {
601
+ id: string;
602
+ storageKey: string;
603
+ originalName: string;
604
+ mimeType: string;
605
+ sizeBytes: number;
606
+ category?: "input" | "intermediate" | "output";
607
+ metadata?: Record<string, any>;
608
+ createdAt?: string;
609
+ updatedAt?: string;
610
+ }
611
+ interface StorageAdapter {
612
+ readFile(path: string): Promise<Buffer>;
613
+ readTextFile(path: string): Promise<string>;
614
+ writeFile(path: string, data: Buffer | string): Promise<void>;
615
+ deleteFile(path: string): Promise<void>;
616
+ exists(path: string): Promise<boolean>;
617
+ mkdir(path: string): Promise<void>;
618
+ readdir(path: string): Promise<string[]>;
619
+ stat(path: string): Promise<any>;
620
+ saveArtifact(spaceId: string, artifact: ArtifactInfo, buffer: Buffer): Promise<ArtifactInfo>;
621
+ getArtifact(spaceId: string, artifactId: string): Promise<{
622
+ info: ArtifactInfo;
623
+ buffer: Buffer;
624
+ } | null>;
625
+ getArtifactInfo(spaceId: string, artifactId: string): Promise<ArtifactInfo | null>;
626
+ listArtifacts(spaceId: string): Promise<ArtifactInfo[]>;
627
+ deleteArtifact(spaceId: string, artifactId: string): Promise<void>;
628
+ }
629
+ /**
630
+ * Base storage class with common operations
631
+ */
632
+ declare class BaseStorage {
633
+ protected adapter: StorageAdapter;
634
+ protected basePath: string;
635
+ constructor(basePath?: string, adapter?: StorageAdapter);
636
+ /**
637
+ * Get full path relative to base
638
+ */
639
+ protected getPath(...segments: string[]): string;
640
+ /**
641
+ * Initialize storage (ensure directories exist)
642
+ */
643
+ initialize(): Promise<void>;
644
+ /**
645
+ * Read JSON file
646
+ */
647
+ readJSON<T = any>(relativePath: string): Promise<T | null>;
648
+ /**
649
+ * Read YAML file
650
+ */
651
+ readYaml<T = any>(relativePath: string): Promise<T | null>;
652
+ /**
653
+ * Write JSON file
654
+ */
655
+ writeJSON(relativePath: string, data: any): Promise<void>;
656
+ /**
657
+ * Write YAML file
658
+ */
659
+ writeYaml(relativePath: string, data: any): Promise<void>;
660
+ /**
661
+ * Check if file exists
662
+ */
663
+ exists(relativePath: string): Promise<boolean>;
664
+ /**
665
+ * Read text file
666
+ */
667
+ readTextFile(relativePath: string): Promise<string>;
668
+ /**
669
+ * Write file (text or binary)
670
+ */
671
+ writeFile(relativePath: string, data: Buffer | string): Promise<void>;
672
+ /**
673
+ * Delete file
674
+ */
675
+ delete(relativePath: string): Promise<void>;
676
+ /**
677
+ * List files in directory
678
+ */
679
+ list(relativePath?: string): Promise<string[]>;
680
+ /**
681
+ * Create directory
682
+ */
683
+ mkdir(relativePath: string): Promise<void>;
684
+ /**
685
+ * Read binary file
686
+ */
687
+ readFile(relativePath: string): Promise<Buffer>;
688
+ /**
689
+ * Copy file from one storage to another
690
+ */
691
+ copyFileTo(relativePath: string, targetStorage: BaseStorage, targetPath: string): Promise<void>;
692
+ /**
693
+ * Get file statistics (size, timestamps, etc.)
694
+ */
695
+ getArtifactFileStats(relativePath: string): Promise<any>;
696
+ }
697
+
698
+ /**
699
+ * Space Storage - Handles storage operations for spaces
700
+ */
701
+
702
+ interface StorageOptions {
703
+ rootPath: string;
704
+ spaceId: string;
705
+ adapter?: StorageAdapter;
706
+ }
707
+ declare class SpaceStorage extends BaseStorage {
708
+ private spaceId;
709
+ constructor(options: StorageOptions);
710
+ getSpacePath(): string;
711
+ getFilePath(filename: string): string;
712
+ saveFile(filename: string, data: any): Promise<void>;
713
+ saveFileBuffer(filename: string, data: Buffer): Promise<void>;
714
+ /**
715
+ * DEPRECATED: Use artifact operations below instead
716
+ * Save an artifact file (low-level file operation only)
717
+ */
718
+ saveArtifact(storageKey: string, buffer: Buffer, metadata: {
719
+ mimeType: string;
720
+ size: number;
721
+ artifactType?: string;
722
+ }, originalFilename?: string): Promise<void>;
723
+ /**
724
+ * Save a complete artifact (both file AND metadata)
725
+ */
726
+ saveCompleteArtifact(artifact: ArtifactInfo, buffer: Buffer): Promise<ArtifactInfo>;
727
+ /**
728
+ * Get a complete artifact (both file AND metadata)
729
+ */
730
+ getCompleteArtifact(artifactId: string): Promise<{
731
+ info: ArtifactInfo;
732
+ buffer: Buffer;
733
+ } | null>;
734
+ /**
735
+ * Get artifact metadata only (without loading the file)
736
+ */
737
+ getArtifactInfo(artifactId: string): Promise<ArtifactInfo | null>;
738
+ /**
739
+ * List all artifacts in this space
740
+ */
741
+ listArtifacts(): Promise<ArtifactInfo[]>;
742
+ /**
743
+ * Delete an artifact (both file AND metadata)
744
+ */
745
+ deleteCompleteArtifact(artifactId: string): Promise<void>;
746
+ listFiles(): Promise<string[]>;
747
+ createDirectory(dirname: string): Promise<void>;
748
+ getMetadata(): Promise<any>;
749
+ saveMetadata(metadata: any): Promise<void>;
750
+ getArtifact(filename: string): Promise<{
751
+ content: Buffer;
752
+ metadata?: any;
753
+ } | null>;
754
+ cleanup(): Promise<void>;
755
+ }
756
+ declare class SpaceStorageFactory {
757
+ private static getRootPath;
758
+ private static rootPath;
759
+ static setRootPath(rootPath: string): void;
760
+ static create(spaceId: string): Promise<SpaceStorage>;
761
+ static list(): Promise<string[]>;
762
+ static exists(spaceId: string): Promise<boolean>;
763
+ static delete(spaceId: string): Promise<void>;
764
+ }
765
+
766
+ /**
767
+ * Collaboration Module - Multi-Agent Collaboration Engine
768
+ *
769
+ * Provides:
770
+ * - Parallel agent execution
771
+ * - Agent-to-agent communication
772
+ * - Shared context management
773
+ * - Collaborative planning
774
+ */
775
+
776
+ interface AgentMessage {
777
+ from: string;
778
+ to: string;
779
+ content: string;
780
+ metadata?: Record<string, any>;
781
+ timestamp: Date;
782
+ }
783
+ interface SharedContext {
784
+ spaceId: string;
785
+ data: Record<string, any>;
786
+ updatedAt: Date;
787
+ updatedBy: string;
788
+ }
789
+ interface ParallelTask {
790
+ id: string;
791
+ agentId: string;
792
+ messages: any[];
793
+ system?: string;
794
+ metadata?: Record<string, any>;
795
+ priority?: number;
796
+ }
797
+ interface ParallelExecutionResult {
798
+ taskId: string;
799
+ agentId: string;
800
+ result: AgentResponse;
801
+ error?: Error;
802
+ duration: number;
803
+ }
804
+ /**
805
+ * Agent Collaboration Manager
806
+ * Handles agent-to-agent communication and shared context
807
+ */
808
+ declare class AgentCollaborationManager {
809
+ private space;
810
+ private messageQueue;
811
+ private sharedContext;
812
+ private listeners;
813
+ constructor(space: Space$1);
814
+ /**
815
+ * Send a message from one agent to another
816
+ */
817
+ sendMessage(from: string, to: string, content: string, metadata?: Record<string, any>): void;
818
+ /**
819
+ * Queue a message for an agent
820
+ */
821
+ private queueMessage;
822
+ /**
823
+ * Get pending messages for an agent
824
+ */
825
+ getMessages(agentId: string): AgentMessage[];
826
+ /**
827
+ * Subscribe to messages for an agent
828
+ */
829
+ subscribe(agentId: string, callback: (message: AgentMessage) => void): () => void;
830
+ /**
831
+ * Notify listeners of a new message
832
+ */
833
+ private notifyListeners;
834
+ /**
835
+ * Update shared context
836
+ */
837
+ updateContext(agentId: string, updates: Record<string, any>): void;
838
+ /**
839
+ * Get shared context
840
+ */
841
+ getContext(): SharedContext;
842
+ /**
843
+ * Get a specific value from shared context
844
+ */
845
+ getContextValue(key: string): any;
846
+ }
847
+ /**
848
+ * Parallel Execution Engine
849
+ * Executes multiple agent tasks in parallel
850
+ */
851
+ declare class ParallelExecutionEngine {
852
+ private space;
853
+ private maxConcurrency;
854
+ private activeTasks;
855
+ constructor(space: Space$1, maxConcurrency?: number);
856
+ /**
857
+ * Execute multiple tasks in parallel
858
+ */
859
+ executeParallel(tasks: ParallelTask[]): Promise<ParallelExecutionResult[]>;
860
+ /**
861
+ * Execute a single task
862
+ */
863
+ private executeTask;
864
+ /**
865
+ * Cancel a running task
866
+ */
867
+ cancelTask(taskId: string): void;
868
+ /**
869
+ * Get active task count
870
+ */
871
+ getActiveTaskCount(): number;
872
+ }
873
+ /**
874
+ * Collaborative Planner
875
+ * Helps agents plan together
876
+ */
877
+ declare class CollaborativePlanner {
878
+ private space;
879
+ private collaborationManager;
880
+ constructor(space: Space$1, collaborationManager: AgentCollaborationManager);
881
+ /**
882
+ * Create a collaborative plan with multiple agents
883
+ */
884
+ createCollaborativePlan(goal: string, agentIds: string[]): Promise<{
885
+ plan: any;
886
+ agentAssignments: Map<string, string[]>;
887
+ }>;
888
+ /**
889
+ * Merge multiple agent plans into one
890
+ */
891
+ private mergePlans;
892
+ /**
893
+ * Assign tasks to agents
894
+ */
895
+ private assignTasks;
896
+ }
897
+
898
+ /**
899
+ * Space - The top-level container for Viber work (formerly Space)
900
+ *
901
+ * A Space represents a project context that contains multiple tasks.
902
+ * Each space is managed by an XAgent that serves as its orchestrator.
903
+ *
904
+ * Key concepts:
905
+ * - Space: Project container with shared configuration
906
+ * - Task: Individual conversation threads within a space
907
+ * - Each task has its own conversation history and artifacts
908
+ */
909
+
910
+ interface SpaceTask {
911
+ id: string;
912
+ spaceId: string;
913
+ title: string;
914
+ history: ConversationHistory;
915
+ artifactIds: string[];
916
+ status: "active" | "completed" | "archived";
917
+ createdAt: Date;
918
+ updatedAt: Date;
919
+ }
920
+ declare class Space$1 {
921
+ spaceId: string;
922
+ userId?: string;
923
+ config: SpaceConfig;
924
+ history: ConversationHistory;
925
+ tasks: Map<string, SpaceTask>;
926
+ messageQueue: MessageQueue;
927
+ agents: Map<string, Agent$1>;
928
+ storage: SpaceStorage;
929
+ goal: string;
930
+ name: string;
931
+ viberAgent?: ViberAgent;
932
+ createdAt: Date;
933
+ updatedAt: Date;
934
+ plan?: Plan;
935
+ artifacts?: any[];
936
+ collaborationManager?: AgentCollaborationManager;
937
+ parallelEngine?: ParallelExecutionEngine;
938
+ collaborativePlanner?: CollaborativePlanner;
939
+ constructor({ spaceId, userId, config, history, messageQueue, agents, storage, goal, name, viberAgent, }: {
940
+ spaceId: string;
941
+ userId?: string;
942
+ config: SpaceConfig;
943
+ history: ConversationHistory;
944
+ messageQueue: MessageQueue;
945
+ agents: Map<string, Agent$1>;
946
+ storage: SpaceStorage;
947
+ goal: string;
948
+ name?: string;
949
+ viberAgent?: ViberAgent;
950
+ });
951
+ /**
952
+ * Get or create a task within this space
953
+ */
954
+ getOrCreateTask(taskId: string, title?: string): SpaceTask;
955
+ /**
956
+ * Get task by ID
957
+ */
958
+ getTask(taskId: string): SpaceTask | undefined;
959
+ /**
960
+ * Get all tasks in this space
961
+ */
962
+ getAllTasks(): SpaceTask[];
963
+ /**
964
+ * Update space task status (for conversation tasks, not Plan tasks)
965
+ */
966
+ updateSpaceTaskStatus(taskId: string, status: "active" | "completed" | "archived"): boolean;
967
+ getAgent(name: string): Agent$1 | undefined;
968
+ registerAgent(name: string, agent: Agent$1): void;
969
+ complete(): void;
970
+ getContext(): Record<string, any>;
971
+ createPlan(plan: Plan): Promise<void>;
972
+ updatePlan(plan: Plan): Promise<void>;
973
+ setName(name: string): Promise<void>;
974
+ getNextTask(): Promise<Task$1 | undefined>;
975
+ getParallelTasks(maxTasks?: number): Promise<Task$1[]>;
976
+ updateTaskStatus(taskId: string, status: TaskStatus): Promise<boolean>;
977
+ assignTask(taskId: string, agentName: string): Promise<boolean>;
978
+ isPlanComplete(): boolean;
979
+ hasFailedTasks(): boolean;
980
+ persistState(): Promise<void>;
981
+ loadState(): Promise<boolean>;
982
+ loadPlan(): Promise<Plan | undefined>;
983
+ getState(): SpaceState;
984
+ }
985
+ /**
986
+ * Start a new space
987
+ */
988
+ declare function startSpace({ goal, spaceId, userId, spaceRoot, name, model, }: {
989
+ goal: string;
990
+ spaceId?: string;
991
+ userId?: string;
992
+ spaceRoot?: string;
993
+ name?: string;
994
+ model?: string;
995
+ }): Promise<Space$1>;
996
+
997
+ /**
998
+ * AI Provider Management
999
+ * Handles initialization and configuration of different AI providers
1000
+ *
1001
+ * Philosophy: Keep it simple - agents specify their provider and model explicitly.
1002
+ *
1003
+ * To add a new provider (e.g., Google, Mistral, Cohere):
1004
+ * 1. Install: `pnpm add @ai-sdk/google`
1005
+ * 2. Import: `import { createGoogleGenerativeAI } from "@ai-sdk/google";`
1006
+ * 3. Add case: `case "google": return createGoogleGenerativeAI({...})`
1007
+ * 4. Add environment variable handling
1008
+ */
1009
+ type ModelProvider$1 = string;
1010
+ interface ModelConfig$1 {
1011
+ provider: ModelProvider$1;
1012
+ modelName: string;
1013
+ apiKey?: string;
1014
+ baseURL?: string;
1015
+ spaceId?: string;
1016
+ userId?: string;
1017
+ storageRoot?: string;
1018
+ teamConfig?: string;
1019
+ defaultGoal?: string;
1020
+ }
1021
+ /**
1022
+ * Get the appropriate AI provider instance
1023
+ */
1024
+ declare function getModelProvider(config: ModelConfig$1): _ai_sdk_openai.OpenAIProvider | _ai_sdk_deepseek.DeepSeekProvider | _openrouter_ai_sdk_provider.OpenRouterProvider;
1025
+ /**
1026
+ * Parse model string to extract provider and model name
1027
+ * Examples: "gpt-4o" -> { provider: "openai", modelName: "gpt-4o" }
1028
+ */
1029
+ declare function parseModelString(model: string): ModelConfig$1;
1030
+
1031
+ /**
1032
+ * Tool System for Viber
1033
+ *
1034
+ * Coordinates between custom tools and MCP tools.
1035
+ * Knows nothing about specific tool implementations.
1036
+ */
1037
+
1038
+ interface CoreTool {
1039
+ description: string;
1040
+ inputSchema: z.ZodSchema | any;
1041
+ execute: (args: any, context?: any) => Promise<any>;
1042
+ }
1043
+ /**
1044
+ * Build a tool map for streamText from an array of tool IDs
1045
+ * Delegates to appropriate providers without knowing their internals
1046
+ */
1047
+ declare function buildToolMap(toolIds: string[], context?: {
1048
+ spaceId?: string;
1049
+ }): Promise<Record<string, CoreTool>>;
1050
+ /**
1051
+ * Check if an object is a valid tool
1052
+ */
1053
+ declare function isValidTool(obj: any): boolean;
1054
+ /**
1055
+ * Clear MCP cache (useful for testing)
1056
+ */
1057
+ declare function clearToolCache(): void;
1058
+
1059
+ /**
1060
+ * Data types for Viber entities
1061
+ * Moved from lib/data/types.ts to make Viber the single source of truth
1062
+ */
1063
+ interface Agent {
1064
+ id: string;
1065
+ userId?: string;
1066
+ name: string;
1067
+ description: string;
1068
+ category?: string;
1069
+ icon?: string;
1070
+ logoUrl?: string;
1071
+ tags?: string[];
1072
+ systemPrompt?: string;
1073
+ llm?: {
1074
+ provider: string;
1075
+ model: string;
1076
+ settings?: {
1077
+ temperature?: number;
1078
+ maxTokens?: number;
1079
+ topP?: number;
1080
+ frequencyPenalty?: number;
1081
+ presencePenalty?: number;
1082
+ };
1083
+ };
1084
+ tools?: string[];
1085
+ author?: string;
1086
+ version?: string;
1087
+ usageExamples?: string[];
1088
+ requirements?: string[];
1089
+ createdAt?: string;
1090
+ updatedAt?: string;
1091
+ }
1092
+ interface Tool {
1093
+ id: string;
1094
+ userId?: string;
1095
+ name: string;
1096
+ description: string;
1097
+ type: "builtin" | "mcp" | "custom";
1098
+ vendor?: string;
1099
+ category?: string;
1100
+ icon?: string;
1101
+ logoUrl?: string;
1102
+ config?: Record<string, any>;
1103
+ configSchema?: any[];
1104
+ features?: string[];
1105
+ tags?: string[];
1106
+ status?: "active" | "inactive" | "deprecated";
1107
+ ready?: boolean;
1108
+ createdAt?: string;
1109
+ updatedAt?: string;
1110
+ }
1111
+ interface Space {
1112
+ id: string;
1113
+ userId?: string;
1114
+ name: string;
1115
+ description?: string;
1116
+ goal?: string;
1117
+ config?: Record<string, any>;
1118
+ teamConfig?: any;
1119
+ activeArtifactId?: string;
1120
+ createdAt?: string;
1121
+ updatedAt?: string;
1122
+ }
1123
+ interface Artifact {
1124
+ id: string;
1125
+ spaceId?: string;
1126
+ taskId?: string;
1127
+ userId?: string;
1128
+ category?: "input" | "intermediate" | "output";
1129
+ storageKey: string;
1130
+ originalName: string;
1131
+ mimeType: string;
1132
+ sizeBytes: number;
1133
+ metadata?: Record<string, any>;
1134
+ createdAt?: string;
1135
+ updatedAt?: string;
1136
+ }
1137
+ interface Conversation {
1138
+ id: string;
1139
+ spaceId?: string;
1140
+ userId?: string;
1141
+ title?: string;
1142
+ messages?: any[];
1143
+ metadata?: Record<string, any>;
1144
+ createdAt?: string;
1145
+ updatedAt?: string;
1146
+ }
1147
+ interface Task {
1148
+ id: string;
1149
+ spaceId?: string;
1150
+ userId?: string;
1151
+ title?: string;
1152
+ description?: string;
1153
+ status?: "pending" | "active" | "completed" | "failed";
1154
+ result?: any;
1155
+ metadata?: Record<string, any>;
1156
+ model?: string;
1157
+ mode?: string;
1158
+ systemMessage?: string;
1159
+ messages?: any[];
1160
+ supervision?: any;
1161
+ context?: any;
1162
+ createdAt?: string;
1163
+ updatedAt?: string;
1164
+ }
1165
+ interface ModelConfig {
1166
+ id: string;
1167
+ name: string;
1168
+ }
1169
+ interface ModelProvider {
1170
+ id: string;
1171
+ name: string;
1172
+ provider: string;
1173
+ enabled?: boolean;
1174
+ baseUrl?: string;
1175
+ apiKey?: string;
1176
+ models?: string[] | ModelConfig[];
1177
+ config?: Record<string, any>;
1178
+ createdAt?: string;
1179
+ updatedAt?: string;
1180
+ }
1181
+ interface Datasource {
1182
+ id: string;
1183
+ name: string;
1184
+ type: string;
1185
+ config?: Record<string, any>;
1186
+ createdAt?: string;
1187
+ updatedAt?: string;
1188
+ }
1189
+
1190
+ /**
1191
+ * DataAdapter interface for accessing agents, tools, spaces, etc.
1192
+ * This is an internal interface used by ViberDataManager.
1193
+ * External code should use ViberDataManager, not DataAdapter directly.
1194
+ */
1195
+
1196
+ /**
1197
+ * Internal adapter interface for data persistence
1198
+ * Implementations handle local files or remote database/API
1199
+ */
1200
+ interface DataAdapter {
1201
+ getAgents(): Promise<Agent[]>;
1202
+ getAgent(id: string): Promise<Agent | null>;
1203
+ saveAgent(agent: Agent): Promise<Agent>;
1204
+ deleteAgent(id: string): Promise<void>;
1205
+ cloneAgent(id: string): Promise<Agent>;
1206
+ getTools(): Promise<Tool[]>;
1207
+ getTool(id: string): Promise<Tool | null>;
1208
+ saveTool(tool: Tool): Promise<Tool>;
1209
+ deleteTool(id: string): Promise<void>;
1210
+ cloneTool(id: string): Promise<Tool>;
1211
+ getSpaces(): Promise<Space[]>;
1212
+ getSpace(id: string): Promise<Space | null>;
1213
+ saveSpace(space: Space): Promise<Space>;
1214
+ deleteSpace(id: string): Promise<void>;
1215
+ getArtifacts(spaceId: string): Promise<Artifact[]>;
1216
+ getArtifact(id: string): Promise<Artifact | null>;
1217
+ saveArtifact(artifact: Artifact): Promise<Artifact>;
1218
+ deleteArtifact(id: string): Promise<void>;
1219
+ getArtifactsBySpace(spaceId: string): Promise<Artifact[]>;
1220
+ getArtifactsByTask(taskId: string): Promise<Artifact[]>;
1221
+ getArtifactsByCategory(spaceOrTaskId: string, category: "input" | "intermediate" | "output", isTask?: boolean): Promise<Artifact[]>;
1222
+ getTasks(spaceId: string): Promise<Task[]>;
1223
+ getTask(id: string): Promise<Task | null>;
1224
+ saveTask(task: Task): Promise<Task>;
1225
+ deleteTask(id: string): Promise<void>;
1226
+ getConversations(spaceId: string): Promise<Conversation[]>;
1227
+ getConversation(id: string): Promise<Conversation | null>;
1228
+ saveConversation(conversation: Conversation): Promise<Conversation>;
1229
+ deleteConversation(id: string): Promise<void>;
1230
+ getModelProviders(): Promise<ModelProvider[]>;
1231
+ getModelProvider(id: string): Promise<ModelProvider | null>;
1232
+ saveModelProvider(provider: ModelProvider): Promise<ModelProvider>;
1233
+ deleteModelProvider(id: string): Promise<void>;
1234
+ getDatasources(): Promise<Datasource[]>;
1235
+ getDatasource(id: string): Promise<Datasource | null>;
1236
+ saveDatasource(datasource: Datasource): Promise<Datasource>;
1237
+ deleteDatasource(id: string): Promise<void>;
1238
+ }
1239
+
1240
+ /**
1241
+ * ViberDataManager - Unified Data Access Layer
1242
+ *
1243
+ * This is the single source of truth for all Viber data operations.
1244
+ * It unifies DataAdapter (metadata) and SpaceStorage (files) into one interface.
1245
+ *
1246
+ * Key features:
1247
+ * - Unified query interface for spaces, artifacts, tasks, agents, tools
1248
+ * - Automatic caching
1249
+ * - Real-time subscriptions (when supported)
1250
+ * - Optimistic updates
1251
+ */
1252
+
1253
+ interface SpaceFilters {
1254
+ userId?: string;
1255
+ name?: string;
1256
+ createdAfter?: Date;
1257
+ createdBefore?: Date;
1258
+ }
1259
+ interface ArtifactFilters {
1260
+ spaceId?: string;
1261
+ taskId?: string;
1262
+ category?: "input" | "intermediate" | "output";
1263
+ mimeType?: string;
1264
+ }
1265
+ interface TaskFilters {
1266
+ spaceId: string;
1267
+ status?: "active" | "completed" | "archived";
1268
+ createdAfter?: Date;
1269
+ }
1270
+ type Unsubscribe = () => void;
1271
+ type SubscriptionCallback<T> = (data: T) => void;
1272
+ /**
1273
+ * ViberDataManager - Central data access layer
1274
+ */
1275
+ declare class ViberDataManager {
1276
+ private dataAdapter;
1277
+ private cache;
1278
+ private subscriptions;
1279
+ private cacheTTL;
1280
+ constructor(dataAdapter?: DataAdapter);
1281
+ /**
1282
+ * Create a server-side instance (uses direct database access)
1283
+ * Uses dynamic import to avoid bundling server code in client
1284
+ *
1285
+ * NOTE: This should only be called from server-side code (API routes, server components)
1286
+ */
1287
+ static createServer(): Promise<ViberDataManager>;
1288
+ /**
1289
+ * Create a server-side instance synchronously (for use in server contexts)
1290
+ * This uses require() to avoid bundling in client code
1291
+ */
1292
+ static createServerSync(): ViberDataManager;
1293
+ /**
1294
+ * Create a client-side instance (uses API calls)
1295
+ * @deprecated Client-side direct usage is deprecated. Use server actions instead.
1296
+ */
1297
+ static createClient(): ViberDataManager;
1298
+ private getCacheKey;
1299
+ private getCached;
1300
+ private setCache;
1301
+ private invalidateCache;
1302
+ private notifySubscribers;
1303
+ /**
1304
+ * Get a single space by ID
1305
+ */
1306
+ getSpace(spaceId: string): Promise<Space | null>;
1307
+ /**
1308
+ * List all spaces with optional filters
1309
+ */
1310
+ listSpaces(filters?: SpaceFilters): Promise<Space[]>;
1311
+ /**
1312
+ * Create a new space
1313
+ */
1314
+ createSpace(space: Partial<Space>): Promise<Space>;
1315
+ /**
1316
+ * Update a space
1317
+ */
1318
+ updateSpace(spaceId: string, updates: Partial<Space>): Promise<Space>;
1319
+ /**
1320
+ * Delete a space
1321
+ */
1322
+ deleteSpace(spaceId: string): Promise<void>;
1323
+ /**
1324
+ * Subscribe to space changes
1325
+ */
1326
+ subscribeToSpace(spaceId: string, callback: SubscriptionCallback<Space | null>): Unsubscribe;
1327
+ /**
1328
+ * Subscribe to all spaces
1329
+ */
1330
+ subscribeToSpaces(callback: SubscriptionCallback<Space[]>): Unsubscribe;
1331
+ /**
1332
+ * Get artifacts for a space
1333
+ */
1334
+ getArtifacts(spaceId: string, filters?: ArtifactFilters): Promise<Artifact[]>;
1335
+ /**
1336
+ * Get a single artifact by ID
1337
+ */
1338
+ getArtifact(artifactId: string): Promise<Artifact | null>;
1339
+ /**
1340
+ * Create an artifact (metadata only - file upload handled separately)
1341
+ */
1342
+ createArtifact(spaceId: string, artifact: Partial<Artifact>): Promise<Artifact>;
1343
+ /**
1344
+ * Update an artifact
1345
+ */
1346
+ updateArtifact(artifactId: string, updates: Partial<Artifact>): Promise<Artifact>;
1347
+ /**
1348
+ * Delete an artifact
1349
+ */
1350
+ deleteArtifact(artifactId: string, spaceId: string): Promise<void>;
1351
+ /**
1352
+ * Subscribe to artifacts for a space
1353
+ */
1354
+ subscribeToArtifacts(spaceId: string, callback: SubscriptionCallback<Artifact[]>): Unsubscribe;
1355
+ /**
1356
+ * Get tasks for a space
1357
+ */
1358
+ getTasks(spaceId: string, filters?: TaskFilters): Promise<Task[]>;
1359
+ /**
1360
+ * Get a single task by ID
1361
+ */
1362
+ getTask(taskId: string): Promise<Task | null>;
1363
+ /**
1364
+ * Create a new task
1365
+ */
1366
+ createTask(spaceId: string, task: Partial<Task>): Promise<Task>;
1367
+ /**
1368
+ * Update a task
1369
+ */
1370
+ updateTask(taskId: string, updates: Partial<Task>): Promise<Task>;
1371
+ /**
1372
+ * Delete a task
1373
+ */
1374
+ deleteTask(taskId: string, spaceId: string): Promise<void>;
1375
+ /**
1376
+ * Subscribe to tasks for a space
1377
+ */
1378
+ subscribeToTasks(spaceId: string, callback: SubscriptionCallback<Task[]>): Unsubscribe;
1379
+ /**
1380
+ * Get all agents
1381
+ */
1382
+ getAgents(): Promise<Agent[]>;
1383
+ /**
1384
+ * Get a single agent by ID
1385
+ */
1386
+ getAgent(agentId: string): Promise<Agent | null>;
1387
+ /**
1388
+ * Get all tools
1389
+ */
1390
+ getTools(): Promise<Tool[]>;
1391
+ /**
1392
+ * Get a single tool by ID
1393
+ */
1394
+ getTool(toolId: string): Promise<Tool | null>;
1395
+ /**
1396
+ * Get SpaceStorage instance for a space
1397
+ */
1398
+ getSpaceStorage(spaceId: string): Promise<SpaceStorage>;
1399
+ /**
1400
+ * Upload an artifact file
1401
+ */
1402
+ uploadArtifactFile(spaceId: string, artifactId: string, file: File | Blob, filename: string): Promise<string>;
1403
+ /**
1404
+ * Download an artifact file
1405
+ */
1406
+ downloadArtifactFile(spaceId: string, storageKey: string): Promise<Blob>;
1407
+ /**
1408
+ * Delete an artifact file
1409
+ */
1410
+ deleteArtifactFile(spaceId: string, storageKey: string): Promise<void>;
1411
+ }
1412
+ declare function getViberDataManager(): ViberDataManager;
1413
+ /**
1414
+ * Get server-side ViberDataManager (for API routes and server components)
1415
+ * This uses direct database access, not API calls
1416
+ *
1417
+ * NOTE: This function can only be called from server-side code
1418
+ */
1419
+ declare function getViberDataManagerServer(): ViberDataManager;
1420
+
1421
+ interface ViberState {
1422
+ spaces: Map<string, Space>;
1423
+ currentSpaceId: string | null;
1424
+ artifacts: Map<string, Artifact[]>;
1425
+ tasks: Map<string, Task[]>;
1426
+ agents: Agent[];
1427
+ tools: Tool[];
1428
+ loading: {
1429
+ spaces: boolean;
1430
+ artifacts: Record<string, boolean>;
1431
+ tasks: Record<string, boolean>;
1432
+ agents: boolean;
1433
+ tools: boolean;
1434
+ };
1435
+ errors: {
1436
+ spaces: Error | null;
1437
+ artifacts: Record<string, Error | null>;
1438
+ tasks: Record<string, Error | null>;
1439
+ agents: Error | null;
1440
+ tools: Error | null;
1441
+ };
1442
+ setSpaces: (spaces: Space[]) => void;
1443
+ setSpace: (space: Space) => void;
1444
+ removeSpace: (spaceId: string) => void;
1445
+ setCurrentSpaceId: (spaceId: string | null) => void;
1446
+ setArtifacts: (spaceId: string, artifacts: Artifact[]) => void;
1447
+ addArtifact: (spaceId: string, artifact: Artifact) => void;
1448
+ updateArtifact: (spaceId: string, artifactId: string, updates: Partial<Artifact>) => void;
1449
+ removeArtifact: (spaceId: string, artifactId: string) => void;
1450
+ setTasks: (spaceId: string, tasks: Task[]) => void;
1451
+ addTask: (spaceId: string, task: Task) => void;
1452
+ updateTask: (spaceId: string, taskId: string, updates: Partial<Task>) => void;
1453
+ removeTask: (spaceId: string, taskId: string) => void;
1454
+ setAgents: (agents: Agent[]) => void;
1455
+ setTools: (tools: Tool[]) => void;
1456
+ setLoading: (key: string, value: boolean) => void;
1457
+ setError: (key: string, error: Error | null) => void;
1458
+ syncSpaces: () => Promise<void>;
1459
+ syncArtifacts: (spaceId: string) => Promise<void>;
1460
+ syncTasks: (spaceId: string) => Promise<void>;
1461
+ syncAgents: () => Promise<void>;
1462
+ syncTools: () => Promise<void>;
1463
+ }
1464
+ declare const useViberStore: zustand.UseBoundStore<Omit<zustand.StoreApi<ViberState>, "subscribe"> & {
1465
+ subscribe: {
1466
+ (listener: (selectedState: ViberState, previousSelectedState: ViberState) => void): () => void;
1467
+ <U>(selector: (state: ViberState) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
1468
+ equalityFn?: ((a: U, b: U) => boolean) | undefined;
1469
+ fireImmediately?: boolean;
1470
+ } | undefined): () => void;
1471
+ };
1472
+ }>;
1473
+ declare const useViberSpaces: () => Space[];
1474
+ declare const useViberCurrentSpace: () => Space | null;
1475
+ declare const useViberArtifacts: (spaceId: string | null | undefined) => Artifact[];
1476
+ declare const useViberTasks: (spaceId: string | null | undefined) => Task[];
1477
+
1478
+ /**
1479
+ * ViberController - Daemon controller for outbound connection to command center
1480
+ *
1481
+ * A Viber is a local agent daemon that connects OUTBOUND to a central command center
1482
+ * (Supen). This eliminates the need for public IPs or port forwarding.
1483
+ *
1484
+ * Features:
1485
+ * - Persistent WebSocket connection to command center
1486
+ * - Auto-reconnection on disconnect
1487
+ * - Heartbeat/health monitoring
1488
+ * - Task execution and event streaming
1489
+ */
1490
+
1491
+ interface ViberControllerConfig {
1492
+ /** WebSocket URL to connect to (e.g., wss://supen.app/vibers/ws) */
1493
+ serverUrl: string;
1494
+ /** Authentication token */
1495
+ token: string;
1496
+ /** Unique identifier for this viber */
1497
+ viberId: string;
1498
+ /** Human-readable name for this viber */
1499
+ viberName?: string;
1500
+ /** Milliseconds between reconnection attempts */
1501
+ reconnectInterval?: number;
1502
+ /** Milliseconds between heartbeat messages */
1503
+ heartbeatInterval?: number;
1504
+ /** Enable desktop control tools */
1505
+ enableDesktop?: boolean;
1506
+ }
1507
+ interface ViberSkillInfo {
1508
+ id: string;
1509
+ name: string;
1510
+ description: string;
1511
+ }
1512
+ interface ViberInfo {
1513
+ id: string;
1514
+ name: string;
1515
+ version: string;
1516
+ platform: string;
1517
+ capabilities: string[];
1518
+ runningTasks: string[];
1519
+ /** Skills available on this viber (from SKILL.md) */
1520
+ skills?: ViberSkillInfo[];
1521
+ }
1522
+ interface ViberStatus {
1523
+ platform: string;
1524
+ uptime: number;
1525
+ memory: NodeJS.MemoryUsage;
1526
+ runningTasks: number;
1527
+ }
1528
+ type ControllerServerMessage = {
1529
+ type: "task:submit";
1530
+ taskId: string;
1531
+ goal: string;
1532
+ options?: ViberOptions;
1533
+ messages?: {
1534
+ role: string;
1535
+ content: string;
1536
+ }[];
1537
+ } | {
1538
+ type: "task:stop";
1539
+ taskId: string;
1540
+ } | {
1541
+ type: "task:message";
1542
+ taskId: string;
1543
+ message: string;
1544
+ } | {
1545
+ type: "ping";
1546
+ } | {
1547
+ type: "config:update";
1548
+ config: Partial<ViberControllerConfig>;
1549
+ } | {
1550
+ type: "terminal:list";
1551
+ } | {
1552
+ type: "terminal:attach";
1553
+ target: string;
1554
+ } | {
1555
+ type: "terminal:detach";
1556
+ target: string;
1557
+ } | {
1558
+ type: "terminal:input";
1559
+ target: string;
1560
+ keys: string;
1561
+ } | {
1562
+ type: "terminal:resize";
1563
+ target: string;
1564
+ cols: number;
1565
+ rows: number;
1566
+ };
1567
+ type ControllerClientMessage = {
1568
+ type: "connected";
1569
+ viber: ViberInfo;
1570
+ } | {
1571
+ type: "task:started";
1572
+ taskId: string;
1573
+ spaceId: string;
1574
+ } | {
1575
+ type: "task:progress";
1576
+ taskId: string;
1577
+ event: any;
1578
+ } | {
1579
+ type: "task:completed";
1580
+ taskId: string;
1581
+ result: any;
1582
+ } | {
1583
+ type: "task:error";
1584
+ taskId: string;
1585
+ error: string;
1586
+ } | {
1587
+ type: "heartbeat";
1588
+ status: ViberStatus;
1589
+ } | {
1590
+ type: "pong";
1591
+ } | {
1592
+ type: "terminal:list";
1593
+ sessions: any[];
1594
+ panes: any[];
1595
+ } | {
1596
+ type: "terminal:attached";
1597
+ target: string;
1598
+ ok: boolean;
1599
+ error?: string;
1600
+ } | {
1601
+ type: "terminal:detached";
1602
+ target: string;
1603
+ } | {
1604
+ type: "terminal:output";
1605
+ target: string;
1606
+ data: string;
1607
+ } | {
1608
+ type: "terminal:resized";
1609
+ target: string;
1610
+ ok: boolean;
1611
+ };
1612
+ declare class ViberController extends EventEmitter {
1613
+ private config;
1614
+ private ws;
1615
+ private reconnectTimer;
1616
+ private heartbeatTimer;
1617
+ /** taskId -> AbortController for stop (daemon = thin runtime, no Space/agent instance) */
1618
+ private runningTasks;
1619
+ private isConnected;
1620
+ private shouldReconnect;
1621
+ /** Terminal manager for streaming tmux panes */
1622
+ private terminalManager;
1623
+ constructor(config: ViberControllerConfig);
1624
+ /**
1625
+ * Start the viber daemon
1626
+ */
1627
+ start(): Promise<void>;
1628
+ /**
1629
+ * Stop the viber daemon
1630
+ */
1631
+ stop(): Promise<void>;
1632
+ /**
1633
+ * Get current connection status
1634
+ */
1635
+ getStatus(): {
1636
+ connected: boolean;
1637
+ runningTasks: number;
1638
+ };
1639
+ private connect;
1640
+ private onConnected;
1641
+ private onDisconnected;
1642
+ private onError;
1643
+ private onMessage;
1644
+ private handleTaskSubmit;
1645
+ private handleTaskStop;
1646
+ private handleTaskMessage;
1647
+ private handleTerminalList;
1648
+ private handleTerminalAttach;
1649
+ private handleTerminalDetach;
1650
+ private handleTerminalInput;
1651
+ private handleTerminalResize;
1652
+ private send;
1653
+ private startHeartbeat;
1654
+ private stopHeartbeat;
1655
+ private scheduleReconnect;
1656
+ }
1657
+
1658
+ /**
1659
+ * Daemon runtime - thin clawdbot-alike assistant path
1660
+ *
1661
+ * No Space, no DataAdapter, no Storage. Loads a single agent config from file
1662
+ * and runs streamText. Viber Board owns persistence and context; daemon only
1663
+ * orchestrates local skills and the LLM.
1664
+ */
1665
+
1666
+ interface DaemonRunTaskOptions {
1667
+ model?: string;
1668
+ singleAgentId?: string;
1669
+ agentConfig?: AgentConfig;
1670
+ signal?: AbortSignal;
1671
+ }
1672
+ /**
1673
+ * Load agent config from file (no DataAdapter).
1674
+ * Tries built-in defaults then ~/.openviber/agents/{id}.yaml
1675
+ */
1676
+ declare function loadAgentConfig(agentId: string): Promise<AgentConfig | null>;
1677
+ /**
1678
+ * Run a single task: one agent, no Space, no storage.
1679
+ * Returns stream result and agent for summary.
1680
+ */
1681
+ declare function runTask(goal: string, options: DaemonRunTaskOptions & {
1682
+ taskId: string;
1683
+ }, messages?: {
1684
+ role: string;
1685
+ content: string;
1686
+ }[]): Promise<{
1687
+ streamResult: Awaited<ReturnType<Agent$1["streamText"]>>;
1688
+ agent: Agent$1;
1689
+ }>;
1690
+
1691
+ export { Agent$1 as Agent, AgentCollaborationManager, type AgentConfig, type AgentContext, type AgentMessage, type AgentResponse, type ArtifactFilters, type ArtifactInfo, BaseStorage, CollaborativePlanner, type ControllerClientMessage, type ControllerServerMessage, ConversationHistory, type CoreTool, type DaemonRunTaskOptions, type Message, MessageQueue, type ModelConfig$2 as ModelConfig, type ModelProvider$1 as ModelProvider, ParallelExecutionEngine, type ParallelExecutionResult, type ParallelTask, Plan, type PlanSummary, type QueueListener, type QueueState, type QueuedMessage, type SharedContext, Space$1 as Space, type SpaceConfig, type SpaceFilters, type SpaceModel, type SpaceState, SpaceStorage, SpaceStorageFactory, type SpaceTask, type StorageAdapter, type StorageConfig, type StorageOptions, type StreamChunk, type SubscriptionCallback, Task$1 as Task, type TaskDependency, type TaskFilters, TaskStatus, type TaskStep, type Unsubscribe, ViberAgent, type ViberAgentResponse, type ViberConfig, ViberController, type ViberControllerConfig, ViberDataManager, type ViberError, type ViberInfo, type ViberMessage, type ViberOptions, type ViberSkillInfo, type ViberStatus, type ViberStreamOptions, buildToolMap, clearToolCache, getModelProvider, getTextContent, getViberDataManager, getViberDataManagerServer, isValidTool, loadAgentConfig, parseModelString, runTask, startSpace, useViberArtifacts, useViberCurrentSpace, useViberSpaces, useViberStore, useViberTasks };