@contractspec/module.ai-chat 4.0.3 → 4.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.
- package/README.md +130 -10
- package/dist/adapters/ai-sdk-bundle-adapter.d.ts +18 -0
- package/dist/adapters/index.d.ts +4 -0
- package/dist/browser/core/index.js +1138 -21
- package/dist/browser/index.js +2816 -651
- package/dist/browser/presentation/components/index.js +3143 -358
- package/dist/browser/presentation/hooks/index.js +961 -43
- package/dist/browser/presentation/index.js +2784 -666
- package/dist/core/agent-adapter.d.ts +53 -0
- package/dist/core/agent-tools-adapter.d.ts +12 -0
- package/dist/core/chat-service.d.ts +49 -1
- package/dist/core/contracts-context.d.ts +46 -0
- package/dist/core/contracts-context.test.d.ts +1 -0
- package/dist/core/conversation-store.d.ts +16 -2
- package/dist/core/create-chat-route.d.ts +3 -0
- package/dist/core/export-formatters.d.ts +29 -0
- package/dist/core/export-formatters.test.d.ts +1 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.js +1138 -21
- package/dist/core/local-storage-conversation-store.d.ts +33 -0
- package/dist/core/message-types.d.ts +6 -0
- package/dist/core/surface-planner-tools.d.ts +23 -0
- package/dist/core/surface-planner-tools.test.d.ts +1 -0
- package/dist/core/thinking-levels.d.ts +38 -0
- package/dist/core/thinking-levels.test.d.ts +1 -0
- package/dist/core/workflow-tools.d.ts +18 -0
- package/dist/core/workflow-tools.test.d.ts +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2816 -651
- package/dist/node/core/index.js +1138 -21
- package/dist/node/index.js +2816 -651
- package/dist/node/presentation/components/index.js +3143 -358
- package/dist/node/presentation/hooks/index.js +961 -43
- package/dist/node/presentation/index.js +2787 -669
- package/dist/presentation/components/ChatContainer.d.ts +3 -1
- package/dist/presentation/components/ChatExportToolbar.d.ts +25 -0
- package/dist/presentation/components/ChatMessage.d.ts +16 -1
- package/dist/presentation/components/ChatSidebar.d.ts +26 -0
- package/dist/presentation/components/ChatWithExport.d.ts +34 -0
- package/dist/presentation/components/ChatWithSidebar.d.ts +19 -0
- package/dist/presentation/components/ThinkingLevelPicker.d.ts +16 -0
- package/dist/presentation/components/ToolResultRenderer.d.ts +33 -0
- package/dist/presentation/components/index.d.ts +6 -0
- package/dist/presentation/components/index.js +3143 -358
- package/dist/presentation/hooks/index.d.ts +2 -0
- package/dist/presentation/hooks/index.js +961 -43
- package/dist/presentation/hooks/useChat.d.ts +44 -2
- package/dist/presentation/hooks/useConversations.d.ts +18 -0
- package/dist/presentation/hooks/useMessageSelection.d.ts +13 -0
- package/dist/presentation/index.js +2787 -669
- package/package.json +14 -18
|
@@ -4,8 +4,10 @@ export interface ChatContainerProps {
|
|
|
4
4
|
className?: string;
|
|
5
5
|
/** Show scroll-to-bottom button when scrolled up */
|
|
6
6
|
showScrollButton?: boolean;
|
|
7
|
+
/** Optional header content (e.g. export toolbar) */
|
|
8
|
+
headerContent?: React.ReactNode;
|
|
7
9
|
}
|
|
8
10
|
/**
|
|
9
11
|
* Container component for chat messages with scrolling
|
|
10
12
|
*/
|
|
11
|
-
export declare function ChatContainer({ children, className, showScrollButton, }: ChatContainerProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function ChatContainer({ children, className, showScrollButton, headerContent, }: ChatContainerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ChatMessage, ChatConversation } from '../../core/message-types';
|
|
2
|
+
export type ExportFormat = 'markdown' | 'txt' | 'json';
|
|
3
|
+
export interface ChatExportToolbarProps {
|
|
4
|
+
messages: ChatMessage[];
|
|
5
|
+
conversation?: ChatConversation | null;
|
|
6
|
+
selectedIds: Set<string>;
|
|
7
|
+
/** Called after export (for feedback/analytics) */
|
|
8
|
+
onExported?: (format: ExportFormat, count: number) => void;
|
|
9
|
+
/** Optional: show selection summary (e.g. "3 selected") */
|
|
10
|
+
showSelectionSummary?: boolean;
|
|
11
|
+
/** Optional: select all / clear selection buttons */
|
|
12
|
+
onSelectAll?: () => void;
|
|
13
|
+
onClearSelection?: () => void;
|
|
14
|
+
selectedCount?: number;
|
|
15
|
+
totalCount?: number;
|
|
16
|
+
/** New conversation callback */
|
|
17
|
+
onCreateNew?: () => void;
|
|
18
|
+
/** Fork conversation callback (optional messageId to fork from) */
|
|
19
|
+
onFork?: (upToMessageId?: string) => Promise<string | null>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Toolbar for exporting chat conversations to Markdown, TXT, or JSON.
|
|
23
|
+
* Exports selected messages when any are selected; otherwise exports all.
|
|
24
|
+
*/
|
|
25
|
+
export declare function ChatExportToolbar({ messages, conversation, selectedIds, onExported, showSelectionSummary, onSelectAll, onClearSelection, selectedCount, totalCount, onCreateNew, onFork, }: ChatExportToolbarProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
import type { ChatMessage as ChatMessageType } from '../../core/message-types';
|
|
2
3
|
export interface ChatMessageProps {
|
|
3
4
|
message: ChatMessageType;
|
|
@@ -6,8 +7,22 @@ export interface ChatMessageProps {
|
|
|
6
7
|
showCopy?: boolean;
|
|
7
8
|
/** Show avatar */
|
|
8
9
|
showAvatar?: boolean;
|
|
10
|
+
/** Enable selection checkbox */
|
|
11
|
+
selectable?: boolean;
|
|
12
|
+
/** Whether this message is selected */
|
|
13
|
+
selected?: boolean;
|
|
14
|
+
/** Called when selection is toggled */
|
|
15
|
+
onSelect?: (id: string) => void;
|
|
16
|
+
/** Enable edit (user messages only) */
|
|
17
|
+
editable?: boolean;
|
|
18
|
+
/** Called when message is edited */
|
|
19
|
+
onEdit?: (messageId: string, newContent: string) => void | Promise<void>;
|
|
20
|
+
/** Host-provided renderer for tool results with presentationKey */
|
|
21
|
+
presentationRenderer?: (key: string, data?: unknown) => React.ReactNode;
|
|
22
|
+
/** Host-provided renderer for tool results with formKey */
|
|
23
|
+
formRenderer?: (key: string, defaultValues?: Record<string, unknown>) => React.ReactNode;
|
|
9
24
|
}
|
|
10
25
|
/**
|
|
11
26
|
* Chat message component
|
|
12
27
|
*/
|
|
13
|
-
export declare function ChatMessage({ message, className, showCopy, showAvatar, }: ChatMessageProps): import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
export declare function ChatMessage({ message, className, showCopy, showAvatar, selectable, selected, onSelect, editable, onEdit, presentationRenderer, formRenderer, }: ChatMessageProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ChatConversation } from '../../core/message-types';
|
|
2
|
+
import type { ConversationStore } from '../../core/conversation-store';
|
|
3
|
+
export interface ChatSidebarProps {
|
|
4
|
+
store: ConversationStore;
|
|
5
|
+
selectedConversationId: string | null;
|
|
6
|
+
onSelectConversation: (id: string | null) => void;
|
|
7
|
+
onCreateNew: () => void;
|
|
8
|
+
projectId?: string;
|
|
9
|
+
tags?: string[];
|
|
10
|
+
limit?: number;
|
|
11
|
+
className?: string;
|
|
12
|
+
/** Collapsible on mobile */
|
|
13
|
+
collapsed?: boolean;
|
|
14
|
+
/** Optional: update conversation (for project/tags edit) */
|
|
15
|
+
onUpdateConversation?: (id: string, updates: {
|
|
16
|
+
projectId?: string;
|
|
17
|
+
projectName?: string;
|
|
18
|
+
tags?: string[];
|
|
19
|
+
}) => Promise<void>;
|
|
20
|
+
/** Selected conversation for meta display */
|
|
21
|
+
selectedConversation?: ChatConversation | null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Sidebar listing conversations with new/delete actions
|
|
25
|
+
*/
|
|
26
|
+
export declare function ChatSidebar({ store, selectedConversationId, onSelectConversation, onCreateNew, projectId, tags, limit, className, collapsed, onUpdateConversation, selectedConversation, }: ChatSidebarProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { ChatMessage as ChatMessageType, ChatConversation } from '../../core/message-types';
|
|
3
|
+
import type { ThinkingLevel } from '../../core/thinking-levels';
|
|
4
|
+
export interface ChatWithExportProps {
|
|
5
|
+
messages: ChatMessageType[];
|
|
6
|
+
conversation?: ChatConversation | null;
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
className?: string;
|
|
9
|
+
/** Show export toolbar */
|
|
10
|
+
showExport?: boolean;
|
|
11
|
+
/** Show message selection checkboxes */
|
|
12
|
+
showMessageSelection?: boolean;
|
|
13
|
+
/** Show scroll-to-bottom button */
|
|
14
|
+
showScrollButton?: boolean;
|
|
15
|
+
/** New conversation callback */
|
|
16
|
+
onCreateNew?: () => void;
|
|
17
|
+
/** Fork conversation callback */
|
|
18
|
+
onFork?: (upToMessageId?: string) => Promise<string | null>;
|
|
19
|
+
/** Edit message callback */
|
|
20
|
+
onEditMessage?: (messageId: string, newContent: string) => Promise<void>;
|
|
21
|
+
/** Thinking level (instant, thinking, extra_thinking, max) */
|
|
22
|
+
thinkingLevel?: ThinkingLevel;
|
|
23
|
+
/** Called when thinking level changes */
|
|
24
|
+
onThinkingLevelChange?: (level: ThinkingLevel) => void;
|
|
25
|
+
/** Host-provided renderer for tool results with presentationKey */
|
|
26
|
+
presentationRenderer?: (key: string, data?: unknown) => React.ReactNode;
|
|
27
|
+
/** Host-provided renderer for tool results with formKey */
|
|
28
|
+
formRenderer?: (key: string, defaultValues?: Record<string, unknown>) => React.ReactNode;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Chat container with export and message selection.
|
|
32
|
+
* Composes ChatContainer, ChatExportToolbar, and useMessageSelection.
|
|
33
|
+
*/
|
|
34
|
+
export declare function ChatWithExport({ messages, conversation, children, className, showExport, showMessageSelection, showScrollButton, onCreateNew, onFork, onEditMessage, thinkingLevel, onThinkingLevelChange, presentationRenderer, formRenderer, }: ChatWithExportProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type ConversationStore } from '../../core/conversation-store';
|
|
3
|
+
import type { UseChatOptions } from '../hooks/useChat';
|
|
4
|
+
export interface ChatWithSidebarProps extends Omit<UseChatOptions, 'store' | 'conversationId'> {
|
|
5
|
+
/** Optional store (defaults to LocalStorage) */
|
|
6
|
+
store?: ConversationStore;
|
|
7
|
+
projectId?: string;
|
|
8
|
+
tags?: string[];
|
|
9
|
+
className?: string;
|
|
10
|
+
/** Host-provided renderer for tool results with presentationKey */
|
|
11
|
+
presentationRenderer?: (key: string, data?: unknown) => React.ReactNode;
|
|
12
|
+
/** Host-provided renderer for tool results with formKey */
|
|
13
|
+
formRenderer?: (key: string, defaultValues?: Record<string, unknown>) => React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Full chat layout with sidebar (conversation history) and main chat area.
|
|
17
|
+
* Uses a shared store for persistence.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ChatWithSidebar({ store, projectId, tags, className, thinkingLevel: initialThinkingLevel, presentationRenderer, formRenderer, ...useChatOptions }: ChatWithSidebarProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ThinkingLevel } from '../../core/thinking-levels';
|
|
2
|
+
export interface ThinkingLevelPickerProps {
|
|
3
|
+
/** Currently selected level */
|
|
4
|
+
value: ThinkingLevel;
|
|
5
|
+
/** Called when selection changes */
|
|
6
|
+
onChange: (value: ThinkingLevel) => void;
|
|
7
|
+
/** Additional class name */
|
|
8
|
+
className?: string;
|
|
9
|
+
/** Compact mode (smaller) */
|
|
10
|
+
compact?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Picker for thinking level: instant, thinking, extra thinking, max.
|
|
14
|
+
* Maps to provider-specific reasoning options (Anthropic budgetTokens, OpenAI reasoningEffort).
|
|
15
|
+
*/
|
|
16
|
+
export declare function ThinkingLevelPicker({ value, onChange, className, compact, }: ThinkingLevelPickerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/** Tool result shape for presentation rendering */
|
|
3
|
+
export interface PresentationToolResult {
|
|
4
|
+
presentationKey: string;
|
|
5
|
+
data?: unknown;
|
|
6
|
+
}
|
|
7
|
+
/** Tool result shape for form rendering */
|
|
8
|
+
export interface FormToolResult {
|
|
9
|
+
formKey: string;
|
|
10
|
+
defaultValues?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/** Type guard for presentation tool result */
|
|
13
|
+
export declare function isPresentationToolResult(result: unknown): result is PresentationToolResult;
|
|
14
|
+
/** Type guard for form tool result */
|
|
15
|
+
export declare function isFormToolResult(result: unknown): result is FormToolResult;
|
|
16
|
+
export interface ToolResultRendererProps {
|
|
17
|
+
/** Tool name */
|
|
18
|
+
toolName: string;
|
|
19
|
+
/** Tool result from AI */
|
|
20
|
+
result: unknown;
|
|
21
|
+
/** Host-provided presentation renderer */
|
|
22
|
+
presentationRenderer?: (key: string, data?: unknown) => React.ReactNode;
|
|
23
|
+
/** Host-provided form renderer */
|
|
24
|
+
formRenderer?: (key: string, defaultValues?: Record<string, unknown>) => React.ReactNode;
|
|
25
|
+
/** Fallback: render raw JSON when no custom renderer */
|
|
26
|
+
showRawFallback?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Renders tool results with optional host-driven presentation or form components.
|
|
30
|
+
* When result has presentationKey/formKey and host provides a renderer, uses it.
|
|
31
|
+
* Otherwise falls back to raw JSON display.
|
|
32
|
+
*/
|
|
33
|
+
export declare function ToolResultRenderer({ toolName, result, presentationRenderer, formRenderer, showRawFallback, }: ToolResultRendererProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
export { ChatContainer } from './ChatContainer';
|
|
5
5
|
export { ChatMessage } from './ChatMessage';
|
|
6
6
|
export { ChatInput } from './ChatInput';
|
|
7
|
+
export { ChatExportToolbar } from './ChatExportToolbar';
|
|
8
|
+
export { ChatWithExport } from './ChatWithExport';
|
|
9
|
+
export { ChatSidebar } from './ChatSidebar';
|
|
10
|
+
export { ChatWithSidebar } from './ChatWithSidebar';
|
|
7
11
|
export { ModelPicker } from './ModelPicker';
|
|
12
|
+
export { ThinkingLevelPicker } from './ThinkingLevelPicker';
|
|
8
13
|
export { ContextIndicator } from './ContextIndicator';
|
|
9
14
|
export { CodePreview } from './CodePreview';
|
|
15
|
+
export { ToolResultRenderer, isPresentationToolResult, isFormToolResult, type PresentationToolResult, type FormToolResult, } from './ToolResultRenderer';
|