@contractspec/module.ai-chat 4.0.2 → 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
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { ChatAttachment, ChatConversation, ChatMessage } from '../../core/message-types';
|
|
2
|
-
import
|
|
2
|
+
import type { ConversationStore } from '../../core/conversation-store';
|
|
3
|
+
import type { ThinkingLevel } from '../../core/thinking-levels';
|
|
4
|
+
import { type ModelSelector, type ProviderMode, type ProviderName } from '@contractspec/lib.ai-providers';
|
|
5
|
+
import type { WorkflowComposer } from '@contractspec/lib.workflow-composer';
|
|
6
|
+
import type { WorkflowSpec } from '@contractspec/lib.contracts-spec/workflow';
|
|
7
|
+
import type { ContractsContextConfig } from '../../core/contracts-context';
|
|
8
|
+
import type { ResolvedSurfacePlan } from '@contractspec/lib.surface-runtime/runtime/resolve-bundle';
|
|
9
|
+
import type { SurfacePatchProposal } from '@contractspec/lib.surface-runtime/spec/types';
|
|
10
|
+
import type { McpClientConfig } from '@contractspec/lib.ai-agent/tools/mcp-client';
|
|
3
11
|
/** Tool definition for planner integration (reserved for bundle spec 07_ai_native_chat). */
|
|
4
12
|
export interface UseChatToolDef {
|
|
5
13
|
name: string;
|
|
@@ -24,6 +32,8 @@ export interface UseChatOptions {
|
|
|
24
32
|
proxyUrl?: string;
|
|
25
33
|
/** Initial conversation ID to resume */
|
|
26
34
|
conversationId?: string;
|
|
35
|
+
/** Optional store for persistence (enables history, fork, edit) */
|
|
36
|
+
store?: ConversationStore;
|
|
27
37
|
/** System prompt override */
|
|
28
38
|
systemPrompt?: string;
|
|
29
39
|
/** Enable streaming */
|
|
@@ -44,6 +54,28 @@ export interface UseChatOptions {
|
|
|
44
54
|
* Use requireApproval: true for tools that need user confirmation.
|
|
45
55
|
*/
|
|
46
56
|
tools?: UseChatToolDef[];
|
|
57
|
+
/** Thinking level: instant, thinking, extra_thinking, max. Maps to provider reasoning options. */
|
|
58
|
+
thinkingLevel?: ThinkingLevel;
|
|
59
|
+
/** Workflow creation tools: base workflows and optional composer */
|
|
60
|
+
workflowToolsConfig?: {
|
|
61
|
+
baseWorkflows: WorkflowSpec[];
|
|
62
|
+
composer?: WorkflowComposer;
|
|
63
|
+
};
|
|
64
|
+
/** Optional model selector for dynamic model selection by task dimension */
|
|
65
|
+
modelSelector?: ModelSelector;
|
|
66
|
+
/** Contracts-spec context: agent, data-views, operations, forms, presentations */
|
|
67
|
+
contractsContext?: ContractsContextConfig;
|
|
68
|
+
/** Surface plan config: enables propose-patch tool when used in surface-runtime */
|
|
69
|
+
surfacePlanConfig?: {
|
|
70
|
+
plan: ResolvedSurfacePlan;
|
|
71
|
+
onPatchProposal?: (proposal: SurfacePatchProposal) => void;
|
|
72
|
+
};
|
|
73
|
+
/** MCP server configs: tools from these servers are merged into chat tools */
|
|
74
|
+
mcpServers?: McpClientConfig[];
|
|
75
|
+
/** Agent mode: use provided agent instead of ChatService for generation */
|
|
76
|
+
agentMode?: {
|
|
77
|
+
agent: import('../../core/agent-adapter').ChatAgentAdapter;
|
|
78
|
+
};
|
|
47
79
|
}
|
|
48
80
|
/**
|
|
49
81
|
* Return type for useChat hook
|
|
@@ -58,7 +90,9 @@ export interface UseChatReturn {
|
|
|
58
90
|
/** Current error */
|
|
59
91
|
error: Error | null;
|
|
60
92
|
/** Send a message */
|
|
61
|
-
sendMessage: (content: string, attachments?: ChatAttachment[]
|
|
93
|
+
sendMessage: (content: string, attachments?: ChatAttachment[], options?: {
|
|
94
|
+
skipUserAppend?: boolean;
|
|
95
|
+
}) => Promise<void>;
|
|
62
96
|
/** Clear conversation and start fresh */
|
|
63
97
|
clearConversation: () => void;
|
|
64
98
|
/** Set conversation ID to resume */
|
|
@@ -67,6 +101,14 @@ export interface UseChatReturn {
|
|
|
67
101
|
regenerate: () => Promise<void>;
|
|
68
102
|
/** Stop current generation */
|
|
69
103
|
stop: () => void;
|
|
104
|
+
/** Start a new conversation (alias for clearConversation) */
|
|
105
|
+
createNewConversation: () => void;
|
|
106
|
+
/** Edit a user message and regenerate from that point */
|
|
107
|
+
editMessage: (messageId: string, newContent: string) => Promise<void>;
|
|
108
|
+
/** Fork current conversation, optionally up to a message; returns new conversation ID */
|
|
109
|
+
forkConversation: (upToMessageId?: string) => Promise<string | null>;
|
|
110
|
+
/** Update conversation metadata (title, projectId, tags) */
|
|
111
|
+
updateConversation: (updates: Parameters<ConversationStore['update']>[1]) => Promise<ChatConversation | null>;
|
|
70
112
|
/**
|
|
71
113
|
* Add tool approval response when tools have requireApproval.
|
|
72
114
|
* Required when stream pauses for approval. Full support requires server route.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ChatConversation } from '../../core/message-types';
|
|
2
|
+
import type { ConversationStore } from '../../core/conversation-store';
|
|
3
|
+
export interface UseConversationsOptions {
|
|
4
|
+
store: ConversationStore;
|
|
5
|
+
projectId?: string;
|
|
6
|
+
tags?: string[];
|
|
7
|
+
limit?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface UseConversationsReturn {
|
|
10
|
+
conversations: ChatConversation[];
|
|
11
|
+
isLoading: boolean;
|
|
12
|
+
refresh: () => Promise<void>;
|
|
13
|
+
deleteConversation: (id: string) => Promise<boolean>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Hook for listing and managing conversations from a store
|
|
17
|
+
*/
|
|
18
|
+
export declare function useConversations(options: UseConversationsOptions): UseConversationsReturn;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface UseMessageSelectionReturn {
|
|
2
|
+
selectedIds: Set<string>;
|
|
3
|
+
toggle: (id: string) => void;
|
|
4
|
+
selectAll: () => void;
|
|
5
|
+
clearSelection: () => void;
|
|
6
|
+
isSelected: (id: string) => boolean;
|
|
7
|
+
selectedCount: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Hook for managing message selection state.
|
|
11
|
+
* Selection persists when messages change; ids of non-existent messages are removed.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useMessageSelection(messageIds: string[]): UseMessageSelectionReturn;
|