@apteva/apteva-kit 0.1.101 → 0.1.104

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/LICENSE ADDED
@@ -0,0 +1,38 @@
1
+ Apteva Source Available License
2
+ Version 1.0
3
+
4
+ Copyright (c) 2024-present Apteva
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to use
8
+ the Software for personal, educational, or commercial purposes, subject to
9
+ the following conditions:
10
+
11
+ 1. USE: You may use, copy, and run the Software in its original or compiled
12
+ form as part of your own applications.
13
+
14
+ 2. NO MODIFICATIONS: You may not modify, adapt, alter, transform, or create
15
+ derivative works based on the Software. The Software must be used as
16
+ provided.
17
+
18
+ 3. NO REDISTRIBUTION OF SOURCE: You may not redistribute, publish, or share
19
+ the source code of the Software, in whole or in part, except as part of
20
+ a reference to this official repository.
21
+
22
+ 4. ATTRIBUTION: If you use the Software in a product or service, you must
23
+ include appropriate attribution to Apteva in your documentation or about
24
+ page.
25
+
26
+ 5. NO SUBLICENSING: You may not sublicense the Software or grant rights to
27
+ third parties beyond what is permitted here.
28
+
29
+ 6. NO WARRANTY: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
30
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
32
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
33
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
34
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
35
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36
+
37
+ For licensing inquiries or to request permission for uses not covered by
38
+ this license, please contact: legal@apteva.com
package/README.md CHANGED
@@ -156,6 +156,23 @@ npm run dev
156
156
  npm run type-check
157
157
  ```
158
158
 
159
+ ## Configuration
160
+
161
+ Before using the components with a live API, configure the client:
162
+
163
+ ```tsx
164
+ import { aptevaClient } from '@apteva/apteva-kit';
165
+
166
+ aptevaClient.configure({
167
+ apiUrl: 'https://your-api-url.com/agents',
168
+ apiKey: 'your-api-key'
169
+ });
170
+ ```
171
+
172
+ All components also support a `useMock` prop for development without an API.
173
+
159
174
  ## License
160
175
 
161
- MIT
176
+ This project is licensed under the [Apteva Source Available License](LICENSE).
177
+
178
+ You are free to use this software in your applications, but modification and redistribution of the source code is not permitted. See the [LICENSE](LICENSE) file for details.
package/dist/index.d.mts CHANGED
@@ -279,6 +279,7 @@ interface ChatProps {
279
279
  placeholder?: string;
280
280
  showHeader?: boolean;
281
281
  headerTitle?: string;
282
+ onHeaderBack?: () => void;
282
283
  enableFileUpload?: boolean;
283
284
  enableMarkdown?: boolean;
284
285
  enableWidgets?: boolean;
@@ -429,17 +430,165 @@ interface ButtonProps {
429
430
  }
430
431
  declare function Button({ widget, onAction }: ButtonProps): react_jsx_runtime.JSX.Element;
431
432
 
433
+ interface PageLayoutProps {
434
+ title?: string;
435
+ padding?: 'none' | 'sm' | 'md' | 'lg';
436
+ maxWidth?: 'sm' | 'md' | 'lg' | 'xl' | 'full';
437
+ }
438
+ interface RowLayoutProps {
439
+ columns?: number[];
440
+ gap?: 'none' | 'sm' | 'md' | 'lg';
441
+ align?: 'start' | 'center' | 'end' | 'stretch';
442
+ }
443
+ interface ColumnsLayoutProps {
444
+ count?: number;
445
+ gap?: 'none' | 'sm' | 'md' | 'lg';
446
+ }
447
+ interface StackLayoutProps {
448
+ gap?: 'none' | 'sm' | 'md' | 'lg';
449
+ align?: 'left' | 'center' | 'right' | 'stretch';
450
+ }
451
+ interface SidebarLayoutProps {
452
+ side?: 'left' | 'right';
453
+ width?: string;
454
+ collapsible?: boolean;
455
+ }
456
+ interface TabsLayoutProps {
457
+ labels: string[];
458
+ defaultTab?: number;
459
+ }
460
+ type LayoutType = 'page' | 'row' | 'columns' | 'stack' | 'sidebar' | 'tabs';
461
+ interface InterfaceNode {
462
+ type: 'layout' | string;
463
+ id: string;
464
+ layout?: LayoutType;
465
+ props: Record<string, any>;
466
+ children?: InterfaceNode[];
467
+ actions?: Action[];
468
+ metadata?: Record<string, any>;
469
+ isStreaming?: boolean;
470
+ }
471
+ interface InterfaceSpec {
472
+ version: 1;
473
+ root: InterfaceNode;
474
+ }
475
+ interface InterfaceUpdate {
476
+ op: 'replace' | 'update' | 'remove' | 'append' | 'prepend';
477
+ target: string;
478
+ node?: InterfaceNode;
479
+ props?: Record<string, any>;
480
+ }
481
+ interface KpiWidget extends Widget {
482
+ type: 'kpi';
483
+ props: {
484
+ label: string;
485
+ value: string | number;
486
+ change?: string;
487
+ trend?: 'up' | 'down' | 'flat';
488
+ icon?: string;
489
+ };
490
+ }
491
+ interface TextBlockWidget extends Widget {
492
+ type: 'text_block';
493
+ props: {
494
+ content: string;
495
+ variant?: 'heading' | 'body' | 'caption';
496
+ };
497
+ }
498
+ interface SpacerWidget extends Widget {
499
+ type: 'spacer';
500
+ props: {
501
+ height?: 'sm' | 'md' | 'lg';
502
+ variant?: 'line' | 'space';
503
+ };
504
+ }
505
+ interface AutoInterfaceProps {
506
+ agentId: string;
507
+ threadId?: string | null;
508
+ initialPrompt?: string;
509
+ initialInterface?: InterfaceSpec;
510
+ context?: string;
511
+ apiUrl?: string;
512
+ apiKey?: string;
513
+ onInterfaceChange?: (spec: InterfaceSpec) => void;
514
+ onAction?: (action: ActionEvent) => void;
515
+ onThreadChange?: (threadId: string) => void;
516
+ onError?: (error: Error) => void;
517
+ chatPosition?: 'right' | 'bottom';
518
+ chatWidth?: string;
519
+ chatCollapsible?: boolean;
520
+ chatPlaceholder?: string;
521
+ chatWelcomeTitle?: string;
522
+ useMock?: boolean;
523
+ theme?: 'light' | 'dark' | 'auto';
524
+ className?: string;
525
+ }
526
+
527
+ interface KpiProps {
528
+ widget: KpiWidget;
529
+ onAction?: (action: ActionEvent) => void;
530
+ }
531
+ declare function Kpi({ widget, onAction }: KpiProps): react_jsx_runtime.JSX.Element;
532
+
533
+ interface TextBlockProps {
534
+ widget: TextBlockWidget;
535
+ }
536
+ declare function TextBlock({ widget }: TextBlockProps): react_jsx_runtime.JSX.Element;
537
+
538
+ interface SpacerProps {
539
+ widget: SpacerWidget;
540
+ }
541
+ declare function Spacer({ widget }: SpacerProps): react_jsx_runtime.JSX.Element;
542
+
432
543
  declare function Threads({ threads, currentThreadId, onThreadSelect, onThreadDelete, onNewThread, variant, showSearch, showNewButton, groupBy, className, }: ThreadsProps): react_jsx_runtime.JSX.Element;
433
544
 
545
+ declare function AutoInterface({ agentId, threadId, initialPrompt, initialInterface, context, apiUrl, apiKey, onInterfaceChange, onAction, onThreadChange, onError, chatPosition, chatWidth, chatCollapsible, chatPlaceholder, chatWelcomeTitle, useMock, theme, className, }: AutoInterfaceProps): react_jsx_runtime.JSX.Element;
546
+
547
+ interface InterfaceRendererProps {
548
+ node: InterfaceNode;
549
+ onAction?: (action: ActionEvent) => void;
550
+ }
551
+ declare function InterfaceRenderer({ node, onAction }: InterfaceRendererProps): react_jsx_runtime.JSX.Element;
552
+
553
+ interface LayoutRendererProps {
554
+ node: InterfaceNode;
555
+ onAction?: (action: ActionEvent) => void;
556
+ renderNode: (node: InterfaceNode) => React.ReactNode;
557
+ }
558
+ declare function LayoutRenderer({ node, onAction, renderNode }: LayoutRendererProps): react_jsx_runtime.JSX.Element;
559
+
560
+ interface InterfaceSkeletonProps {
561
+ className?: string;
562
+ }
563
+ declare function InterfaceSkeleton({ className }: InterfaceSkeletonProps): react_jsx_runtime.JSX.Element;
564
+
434
565
  declare function getThemeScript(): string;
435
566
 
436
567
  interface AptevaClientConfig {
437
568
  apiUrl?: string;
438
569
  apiKey?: string;
439
570
  }
571
+ interface ResolvedConfig {
572
+ apiUrl: string;
573
+ apiKey: string;
574
+ }
440
575
  interface ChatMessage {
441
576
  role: 'user' | 'assistant' | 'system';
442
- content: string;
577
+ content: string | Array<{
578
+ type: 'text' | 'tool_use' | 'tool_result';
579
+ text?: string;
580
+ id?: string;
581
+ name?: string;
582
+ input?: any;
583
+ tool_use_id?: string;
584
+ content?: string | Array<{
585
+ type: string;
586
+ text?: string;
587
+ }>;
588
+ is_error?: boolean;
589
+ }>;
590
+ id?: string;
591
+ created_at?: string;
443
592
  }
444
593
  interface ChatRequest {
445
594
  agent_id: string;
@@ -477,7 +626,7 @@ interface StreamChunk {
477
626
  }
478
627
  declare class AptevaClient {
479
628
  private config;
480
- constructor();
629
+ constructor(config?: AptevaClientConfig);
481
630
  /**
482
631
  * Update client configuration (optional - users can override defaults)
483
632
  */
@@ -485,7 +634,7 @@ declare class AptevaClient {
485
634
  /**
486
635
  * Get current configuration
487
636
  */
488
- getConfig(): AptevaClientConfig;
637
+ getConfig(): ResolvedConfig;
489
638
  /**
490
639
  * Send a chat message to an agent
491
640
  */
@@ -509,10 +658,115 @@ declare class AptevaClient {
509
658
  }
510
659
  declare const aptevaClient: AptevaClient;
511
660
 
661
+ declare function useInterfaceState(initialSpec?: InterfaceSpec | null): {
662
+ spec: InterfaceSpec | null;
663
+ isStreaming: boolean;
664
+ setInterface: (newSpec: InterfaceSpec) => void;
665
+ clearInterface: () => void;
666
+ applyInterfaceUpdate: (update: InterfaceUpdate) => void;
667
+ applyInterfaceUpdates: (updates: InterfaceUpdate[]) => void;
668
+ setIsStreaming: react.Dispatch<react.SetStateAction<boolean>>;
669
+ getNode: (id: string) => InterfaceNode | null;
670
+ };
671
+
672
+ interface UseInterfaceAIOptions {
673
+ agentId: string;
674
+ apiUrl?: string;
675
+ apiKey?: string;
676
+ context?: string;
677
+ onInterface?: (spec: InterfaceSpec) => void;
678
+ onUpdates?: (updates: InterfaceUpdate[]) => void;
679
+ onError?: (error: Error) => void;
680
+ onStreamStart?: () => void;
681
+ onStreamEnd?: () => void;
682
+ }
683
+ declare function useInterfaceAI({ agentId, apiUrl, apiKey, context, onInterface, onUpdates, onError, onStreamStart, onStreamEnd, }: UseInterfaceAIOptions): {
684
+ sendMessage: (message: string) => Promise<void>;
685
+ threadId: string | null;
686
+ };
687
+
512
688
  declare function cn(...inputs: ClassValue[]): string;
513
689
 
514
690
  declare const mockMessages: Message[];
515
691
  declare const mockThreads: Thread[];
516
692
  declare const mockWidgets: Widget[];
517
693
 
518
- export { type Action, type ActionEvent, AptevaClient, type AptevaClientConfig, type AptevaKitControl, Button, type ButtonGroupWidget, type ButtonWidget, Card, type CardWidget, type ChartWidget, Chat, type ChatHandle, type ChatMessage, type ChatProps, type ChatRequest, type ChatResponse, Command, type CommandProps, type CommandResult, type FlowStep, type FlowWidget, type FormField, type FormWidget, type GalleryWidget, type ImageWidget, List, type ListItem, type ListWidget, type MapWidget, type Message, Prompt, type PromptProps, type SendMessageParams, Stream, type StreamChunk, type StreamProps, type SuggestedPrompt, type TableColumn, type TableWidget, type Thread, Threads, type ThreadsProps, type UseAptevaKitReturn, type Widget, Widgets, type WidgetsProps, aptevaClient, cn, getThemeScript, mockMessages, mockThreads, mockWidgets };
694
+ /**
695
+ * Parse a full interface spec from text containing @interface[{...}]
696
+ */
697
+ declare function parseInterfaceFromText(text: string): InterfaceSpec | null;
698
+ /**
699
+ * Parse update operations from text containing @update[{...}] or @update[[{...}, ...]]
700
+ */
701
+ declare function parseUpdatesFromText(text: string): InterfaceUpdate[];
702
+ /**
703
+ * Check if text contains interface syntax
704
+ */
705
+ declare function containsInterface(text: string): boolean;
706
+ /**
707
+ * Strip interface syntax from text, returning only plain text
708
+ */
709
+ declare function stripInterface(text: string): string;
710
+
711
+ /**
712
+ * Generate system prompt context for AutoInterface mode
713
+ * Tells the AI how to generate full interfaces with layouts and widgets
714
+ */
715
+ declare function generateInterfaceContext(): string;
716
+ /**
717
+ * Compact version for the initial prompt (separate API call)
718
+ */
719
+ declare function generateCompactInterfaceContext(): string;
720
+
721
+ /**
722
+ * Find a node by ID in the interface tree
723
+ */
724
+ declare function findNode(root: InterfaceNode, id: string): InterfaceNode | null;
725
+ /**
726
+ * Apply a single update operation to an InterfaceSpec
727
+ */
728
+ declare function applyUpdate(spec: InterfaceSpec, update: InterfaceUpdate): InterfaceSpec;
729
+ /**
730
+ * Apply multiple updates in sequence
731
+ */
732
+ declare function applyUpdates(spec: InterfaceSpec, updates: InterfaceUpdate[]): InterfaceSpec;
733
+
734
+ /**
735
+ * A content block from the API message format.
736
+ * API messages can have `content` as either a string or an array of these blocks.
737
+ */
738
+ interface ApiContentBlock {
739
+ type: 'text' | 'tool_use' | 'tool_result';
740
+ text?: string;
741
+ id?: string;
742
+ name?: string;
743
+ input?: any;
744
+ tool_use_id?: string;
745
+ content?: string | Array<{
746
+ type: string;
747
+ text?: string;
748
+ }>;
749
+ is_error?: boolean;
750
+ }
751
+ /**
752
+ * An API message as returned by the thread messages endpoint.
753
+ */
754
+ interface ApiMessage {
755
+ role: 'user' | 'assistant' | 'system';
756
+ content: string | ApiContentBlock[];
757
+ id?: string;
758
+ created_at?: string;
759
+ timestamp?: string;
760
+ }
761
+ /**
762
+ * Convert API messages (from thread history) to internal Message format.
763
+ *
764
+ * Key transformations:
765
+ * - Simple string content messages map directly
766
+ * - Assistant messages with tool_use blocks become content_segments
767
+ * - User messages with tool_result blocks are merged into the previous
768
+ * assistant message's tool segments (not shown as separate user messages)
769
+ */
770
+ declare function convertApiMessages(apiMessages: ApiMessage[]): Message[];
771
+
772
+ export { type Action, type ActionEvent, type ApiContentBlock, type ApiMessage, AptevaClient, type AptevaClientConfig, type AptevaKitControl, AutoInterface, type AutoInterfaceProps, Button, type ButtonGroupWidget, type ButtonWidget, Card, type CardWidget, type ChartWidget, Chat, type ChatHandle, type ChatMessage, type ChatProps, type ChatRequest, type ChatResponse, type ColumnsLayoutProps, Command, type CommandProps, type CommandResult, type FlowStep, type FlowWidget, type FormField, type FormWidget, type GalleryWidget, type ImageWidget, type InterfaceNode, InterfaceRenderer, InterfaceSkeleton, type InterfaceSpec, type InterfaceUpdate, Kpi, type KpiWidget, LayoutRenderer, type LayoutType, List, type ListItem, type ListWidget, type MapWidget, type Message, type PageLayoutProps, Prompt, type PromptProps, type RowLayoutProps, type SendMessageParams, type SidebarLayoutProps, Spacer, type SpacerWidget, type StackLayoutProps, Stream, type StreamChunk, type StreamProps, type SuggestedPrompt, type TableColumn, type TableWidget, type TabsLayoutProps, TextBlock, type TextBlockWidget, type Thread, Threads, type ThreadsProps, type UseAptevaKitReturn, type Widget, Widgets, type WidgetsProps, applyUpdate, applyUpdates, aptevaClient, cn, containsInterface, convertApiMessages, findNode, generateCompactInterfaceContext, generateInterfaceContext, getThemeScript, mockMessages, mockThreads, mockWidgets, parseInterfaceFromText, parseUpdatesFromText, stripInterface, useInterfaceAI, useInterfaceState };
package/dist/index.d.ts CHANGED
@@ -279,6 +279,7 @@ interface ChatProps {
279
279
  placeholder?: string;
280
280
  showHeader?: boolean;
281
281
  headerTitle?: string;
282
+ onHeaderBack?: () => void;
282
283
  enableFileUpload?: boolean;
283
284
  enableMarkdown?: boolean;
284
285
  enableWidgets?: boolean;
@@ -429,17 +430,165 @@ interface ButtonProps {
429
430
  }
430
431
  declare function Button({ widget, onAction }: ButtonProps): react_jsx_runtime.JSX.Element;
431
432
 
433
+ interface PageLayoutProps {
434
+ title?: string;
435
+ padding?: 'none' | 'sm' | 'md' | 'lg';
436
+ maxWidth?: 'sm' | 'md' | 'lg' | 'xl' | 'full';
437
+ }
438
+ interface RowLayoutProps {
439
+ columns?: number[];
440
+ gap?: 'none' | 'sm' | 'md' | 'lg';
441
+ align?: 'start' | 'center' | 'end' | 'stretch';
442
+ }
443
+ interface ColumnsLayoutProps {
444
+ count?: number;
445
+ gap?: 'none' | 'sm' | 'md' | 'lg';
446
+ }
447
+ interface StackLayoutProps {
448
+ gap?: 'none' | 'sm' | 'md' | 'lg';
449
+ align?: 'left' | 'center' | 'right' | 'stretch';
450
+ }
451
+ interface SidebarLayoutProps {
452
+ side?: 'left' | 'right';
453
+ width?: string;
454
+ collapsible?: boolean;
455
+ }
456
+ interface TabsLayoutProps {
457
+ labels: string[];
458
+ defaultTab?: number;
459
+ }
460
+ type LayoutType = 'page' | 'row' | 'columns' | 'stack' | 'sidebar' | 'tabs';
461
+ interface InterfaceNode {
462
+ type: 'layout' | string;
463
+ id: string;
464
+ layout?: LayoutType;
465
+ props: Record<string, any>;
466
+ children?: InterfaceNode[];
467
+ actions?: Action[];
468
+ metadata?: Record<string, any>;
469
+ isStreaming?: boolean;
470
+ }
471
+ interface InterfaceSpec {
472
+ version: 1;
473
+ root: InterfaceNode;
474
+ }
475
+ interface InterfaceUpdate {
476
+ op: 'replace' | 'update' | 'remove' | 'append' | 'prepend';
477
+ target: string;
478
+ node?: InterfaceNode;
479
+ props?: Record<string, any>;
480
+ }
481
+ interface KpiWidget extends Widget {
482
+ type: 'kpi';
483
+ props: {
484
+ label: string;
485
+ value: string | number;
486
+ change?: string;
487
+ trend?: 'up' | 'down' | 'flat';
488
+ icon?: string;
489
+ };
490
+ }
491
+ interface TextBlockWidget extends Widget {
492
+ type: 'text_block';
493
+ props: {
494
+ content: string;
495
+ variant?: 'heading' | 'body' | 'caption';
496
+ };
497
+ }
498
+ interface SpacerWidget extends Widget {
499
+ type: 'spacer';
500
+ props: {
501
+ height?: 'sm' | 'md' | 'lg';
502
+ variant?: 'line' | 'space';
503
+ };
504
+ }
505
+ interface AutoInterfaceProps {
506
+ agentId: string;
507
+ threadId?: string | null;
508
+ initialPrompt?: string;
509
+ initialInterface?: InterfaceSpec;
510
+ context?: string;
511
+ apiUrl?: string;
512
+ apiKey?: string;
513
+ onInterfaceChange?: (spec: InterfaceSpec) => void;
514
+ onAction?: (action: ActionEvent) => void;
515
+ onThreadChange?: (threadId: string) => void;
516
+ onError?: (error: Error) => void;
517
+ chatPosition?: 'right' | 'bottom';
518
+ chatWidth?: string;
519
+ chatCollapsible?: boolean;
520
+ chatPlaceholder?: string;
521
+ chatWelcomeTitle?: string;
522
+ useMock?: boolean;
523
+ theme?: 'light' | 'dark' | 'auto';
524
+ className?: string;
525
+ }
526
+
527
+ interface KpiProps {
528
+ widget: KpiWidget;
529
+ onAction?: (action: ActionEvent) => void;
530
+ }
531
+ declare function Kpi({ widget, onAction }: KpiProps): react_jsx_runtime.JSX.Element;
532
+
533
+ interface TextBlockProps {
534
+ widget: TextBlockWidget;
535
+ }
536
+ declare function TextBlock({ widget }: TextBlockProps): react_jsx_runtime.JSX.Element;
537
+
538
+ interface SpacerProps {
539
+ widget: SpacerWidget;
540
+ }
541
+ declare function Spacer({ widget }: SpacerProps): react_jsx_runtime.JSX.Element;
542
+
432
543
  declare function Threads({ threads, currentThreadId, onThreadSelect, onThreadDelete, onNewThread, variant, showSearch, showNewButton, groupBy, className, }: ThreadsProps): react_jsx_runtime.JSX.Element;
433
544
 
545
+ declare function AutoInterface({ agentId, threadId, initialPrompt, initialInterface, context, apiUrl, apiKey, onInterfaceChange, onAction, onThreadChange, onError, chatPosition, chatWidth, chatCollapsible, chatPlaceholder, chatWelcomeTitle, useMock, theme, className, }: AutoInterfaceProps): react_jsx_runtime.JSX.Element;
546
+
547
+ interface InterfaceRendererProps {
548
+ node: InterfaceNode;
549
+ onAction?: (action: ActionEvent) => void;
550
+ }
551
+ declare function InterfaceRenderer({ node, onAction }: InterfaceRendererProps): react_jsx_runtime.JSX.Element;
552
+
553
+ interface LayoutRendererProps {
554
+ node: InterfaceNode;
555
+ onAction?: (action: ActionEvent) => void;
556
+ renderNode: (node: InterfaceNode) => React.ReactNode;
557
+ }
558
+ declare function LayoutRenderer({ node, onAction, renderNode }: LayoutRendererProps): react_jsx_runtime.JSX.Element;
559
+
560
+ interface InterfaceSkeletonProps {
561
+ className?: string;
562
+ }
563
+ declare function InterfaceSkeleton({ className }: InterfaceSkeletonProps): react_jsx_runtime.JSX.Element;
564
+
434
565
  declare function getThemeScript(): string;
435
566
 
436
567
  interface AptevaClientConfig {
437
568
  apiUrl?: string;
438
569
  apiKey?: string;
439
570
  }
571
+ interface ResolvedConfig {
572
+ apiUrl: string;
573
+ apiKey: string;
574
+ }
440
575
  interface ChatMessage {
441
576
  role: 'user' | 'assistant' | 'system';
442
- content: string;
577
+ content: string | Array<{
578
+ type: 'text' | 'tool_use' | 'tool_result';
579
+ text?: string;
580
+ id?: string;
581
+ name?: string;
582
+ input?: any;
583
+ tool_use_id?: string;
584
+ content?: string | Array<{
585
+ type: string;
586
+ text?: string;
587
+ }>;
588
+ is_error?: boolean;
589
+ }>;
590
+ id?: string;
591
+ created_at?: string;
443
592
  }
444
593
  interface ChatRequest {
445
594
  agent_id: string;
@@ -477,7 +626,7 @@ interface StreamChunk {
477
626
  }
478
627
  declare class AptevaClient {
479
628
  private config;
480
- constructor();
629
+ constructor(config?: AptevaClientConfig);
481
630
  /**
482
631
  * Update client configuration (optional - users can override defaults)
483
632
  */
@@ -485,7 +634,7 @@ declare class AptevaClient {
485
634
  /**
486
635
  * Get current configuration
487
636
  */
488
- getConfig(): AptevaClientConfig;
637
+ getConfig(): ResolvedConfig;
489
638
  /**
490
639
  * Send a chat message to an agent
491
640
  */
@@ -509,10 +658,115 @@ declare class AptevaClient {
509
658
  }
510
659
  declare const aptevaClient: AptevaClient;
511
660
 
661
+ declare function useInterfaceState(initialSpec?: InterfaceSpec | null): {
662
+ spec: InterfaceSpec | null;
663
+ isStreaming: boolean;
664
+ setInterface: (newSpec: InterfaceSpec) => void;
665
+ clearInterface: () => void;
666
+ applyInterfaceUpdate: (update: InterfaceUpdate) => void;
667
+ applyInterfaceUpdates: (updates: InterfaceUpdate[]) => void;
668
+ setIsStreaming: react.Dispatch<react.SetStateAction<boolean>>;
669
+ getNode: (id: string) => InterfaceNode | null;
670
+ };
671
+
672
+ interface UseInterfaceAIOptions {
673
+ agentId: string;
674
+ apiUrl?: string;
675
+ apiKey?: string;
676
+ context?: string;
677
+ onInterface?: (spec: InterfaceSpec) => void;
678
+ onUpdates?: (updates: InterfaceUpdate[]) => void;
679
+ onError?: (error: Error) => void;
680
+ onStreamStart?: () => void;
681
+ onStreamEnd?: () => void;
682
+ }
683
+ declare function useInterfaceAI({ agentId, apiUrl, apiKey, context, onInterface, onUpdates, onError, onStreamStart, onStreamEnd, }: UseInterfaceAIOptions): {
684
+ sendMessage: (message: string) => Promise<void>;
685
+ threadId: string | null;
686
+ };
687
+
512
688
  declare function cn(...inputs: ClassValue[]): string;
513
689
 
514
690
  declare const mockMessages: Message[];
515
691
  declare const mockThreads: Thread[];
516
692
  declare const mockWidgets: Widget[];
517
693
 
518
- export { type Action, type ActionEvent, AptevaClient, type AptevaClientConfig, type AptevaKitControl, Button, type ButtonGroupWidget, type ButtonWidget, Card, type CardWidget, type ChartWidget, Chat, type ChatHandle, type ChatMessage, type ChatProps, type ChatRequest, type ChatResponse, Command, type CommandProps, type CommandResult, type FlowStep, type FlowWidget, type FormField, type FormWidget, type GalleryWidget, type ImageWidget, List, type ListItem, type ListWidget, type MapWidget, type Message, Prompt, type PromptProps, type SendMessageParams, Stream, type StreamChunk, type StreamProps, type SuggestedPrompt, type TableColumn, type TableWidget, type Thread, Threads, type ThreadsProps, type UseAptevaKitReturn, type Widget, Widgets, type WidgetsProps, aptevaClient, cn, getThemeScript, mockMessages, mockThreads, mockWidgets };
694
+ /**
695
+ * Parse a full interface spec from text containing @interface[{...}]
696
+ */
697
+ declare function parseInterfaceFromText(text: string): InterfaceSpec | null;
698
+ /**
699
+ * Parse update operations from text containing @update[{...}] or @update[[{...}, ...]]
700
+ */
701
+ declare function parseUpdatesFromText(text: string): InterfaceUpdate[];
702
+ /**
703
+ * Check if text contains interface syntax
704
+ */
705
+ declare function containsInterface(text: string): boolean;
706
+ /**
707
+ * Strip interface syntax from text, returning only plain text
708
+ */
709
+ declare function stripInterface(text: string): string;
710
+
711
+ /**
712
+ * Generate system prompt context for AutoInterface mode
713
+ * Tells the AI how to generate full interfaces with layouts and widgets
714
+ */
715
+ declare function generateInterfaceContext(): string;
716
+ /**
717
+ * Compact version for the initial prompt (separate API call)
718
+ */
719
+ declare function generateCompactInterfaceContext(): string;
720
+
721
+ /**
722
+ * Find a node by ID in the interface tree
723
+ */
724
+ declare function findNode(root: InterfaceNode, id: string): InterfaceNode | null;
725
+ /**
726
+ * Apply a single update operation to an InterfaceSpec
727
+ */
728
+ declare function applyUpdate(spec: InterfaceSpec, update: InterfaceUpdate): InterfaceSpec;
729
+ /**
730
+ * Apply multiple updates in sequence
731
+ */
732
+ declare function applyUpdates(spec: InterfaceSpec, updates: InterfaceUpdate[]): InterfaceSpec;
733
+
734
+ /**
735
+ * A content block from the API message format.
736
+ * API messages can have `content` as either a string or an array of these blocks.
737
+ */
738
+ interface ApiContentBlock {
739
+ type: 'text' | 'tool_use' | 'tool_result';
740
+ text?: string;
741
+ id?: string;
742
+ name?: string;
743
+ input?: any;
744
+ tool_use_id?: string;
745
+ content?: string | Array<{
746
+ type: string;
747
+ text?: string;
748
+ }>;
749
+ is_error?: boolean;
750
+ }
751
+ /**
752
+ * An API message as returned by the thread messages endpoint.
753
+ */
754
+ interface ApiMessage {
755
+ role: 'user' | 'assistant' | 'system';
756
+ content: string | ApiContentBlock[];
757
+ id?: string;
758
+ created_at?: string;
759
+ timestamp?: string;
760
+ }
761
+ /**
762
+ * Convert API messages (from thread history) to internal Message format.
763
+ *
764
+ * Key transformations:
765
+ * - Simple string content messages map directly
766
+ * - Assistant messages with tool_use blocks become content_segments
767
+ * - User messages with tool_result blocks are merged into the previous
768
+ * assistant message's tool segments (not shown as separate user messages)
769
+ */
770
+ declare function convertApiMessages(apiMessages: ApiMessage[]): Message[];
771
+
772
+ export { type Action, type ActionEvent, type ApiContentBlock, type ApiMessage, AptevaClient, type AptevaClientConfig, type AptevaKitControl, AutoInterface, type AutoInterfaceProps, Button, type ButtonGroupWidget, type ButtonWidget, Card, type CardWidget, type ChartWidget, Chat, type ChatHandle, type ChatMessage, type ChatProps, type ChatRequest, type ChatResponse, type ColumnsLayoutProps, Command, type CommandProps, type CommandResult, type FlowStep, type FlowWidget, type FormField, type FormWidget, type GalleryWidget, type ImageWidget, type InterfaceNode, InterfaceRenderer, InterfaceSkeleton, type InterfaceSpec, type InterfaceUpdate, Kpi, type KpiWidget, LayoutRenderer, type LayoutType, List, type ListItem, type ListWidget, type MapWidget, type Message, type PageLayoutProps, Prompt, type PromptProps, type RowLayoutProps, type SendMessageParams, type SidebarLayoutProps, Spacer, type SpacerWidget, type StackLayoutProps, Stream, type StreamChunk, type StreamProps, type SuggestedPrompt, type TableColumn, type TableWidget, type TabsLayoutProps, TextBlock, type TextBlockWidget, type Thread, Threads, type ThreadsProps, type UseAptevaKitReturn, type Widget, Widgets, type WidgetsProps, applyUpdate, applyUpdates, aptevaClient, cn, containsInterface, convertApiMessages, findNode, generateCompactInterfaceContext, generateInterfaceContext, getThemeScript, mockMessages, mockThreads, mockWidgets, parseInterfaceFromText, parseUpdatesFromText, stripInterface, useInterfaceAI, useInterfaceState };