@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
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LocalStorage-backed conversation store for web persistence
|
|
3
|
+
*/
|
|
4
|
+
import type { ChatConversation, ChatMessage, ConversationStatus } from './message-types';
|
|
5
|
+
import type { ConversationStore } from './conversation-store';
|
|
6
|
+
/**
|
|
7
|
+
* Conversation store backed by localStorage.
|
|
8
|
+
* Persists conversations across page reloads.
|
|
9
|
+
*/
|
|
10
|
+
export declare class LocalStorageConversationStore implements ConversationStore {
|
|
11
|
+
private readonly key;
|
|
12
|
+
private cache;
|
|
13
|
+
constructor(storageKey?: string);
|
|
14
|
+
private getMap;
|
|
15
|
+
private persist;
|
|
16
|
+
get(conversationId: string): Promise<ChatConversation | null>;
|
|
17
|
+
create(conversation: Omit<ChatConversation, 'id' | 'createdAt' | 'updatedAt'>): Promise<ChatConversation>;
|
|
18
|
+
update(conversationId: string, updates: Partial<Pick<ChatConversation, 'title' | 'status' | 'summary' | 'metadata' | 'projectId' | 'projectName' | 'tags'>>): Promise<ChatConversation | null>;
|
|
19
|
+
appendMessage(conversationId: string, message: Omit<ChatMessage, 'id' | 'conversationId' | 'createdAt' | 'updatedAt'>): Promise<ChatMessage>;
|
|
20
|
+
updateMessage(conversationId: string, messageId: string, updates: Partial<ChatMessage>): Promise<ChatMessage | null>;
|
|
21
|
+
delete(conversationId: string): Promise<boolean>;
|
|
22
|
+
list(options?: {
|
|
23
|
+
status?: ConversationStatus;
|
|
24
|
+
projectId?: string;
|
|
25
|
+
tags?: string[];
|
|
26
|
+
limit?: number;
|
|
27
|
+
offset?: number;
|
|
28
|
+
}): Promise<ChatConversation[]>;
|
|
29
|
+
fork(conversationId: string, upToMessageId?: string): Promise<ChatConversation>;
|
|
30
|
+
truncateAfter(conversationId: string, messageId: string): Promise<ChatConversation | null>;
|
|
31
|
+
search(query: string, limit?: number): Promise<ChatConversation[]>;
|
|
32
|
+
}
|
|
33
|
+
export declare function createLocalStorageConversationStore(storageKey?: string): ConversationStore;
|
|
@@ -98,6 +98,10 @@ export interface ChatConversation {
|
|
|
98
98
|
contextFiles?: string[];
|
|
99
99
|
messages: ChatMessage[];
|
|
100
100
|
summary?: string;
|
|
101
|
+
projectId?: string;
|
|
102
|
+
projectName?: string;
|
|
103
|
+
tags?: string[];
|
|
104
|
+
forkedFromId?: string;
|
|
101
105
|
metadata?: Record<string, unknown>;
|
|
102
106
|
}
|
|
103
107
|
/**
|
|
@@ -111,6 +115,8 @@ export interface SendMessageOptions {
|
|
|
111
115
|
maxTokens?: number;
|
|
112
116
|
temperature?: number;
|
|
113
117
|
stream?: boolean;
|
|
118
|
+
/** When true, do not append user message (for edit/regenerate flow) */
|
|
119
|
+
skipUserAppend?: boolean;
|
|
114
120
|
}
|
|
115
121
|
/**
|
|
116
122
|
* Streaming chunk from AI response (maps from AI SDK fullStream parts)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Surface planner tools for ai-chat.
|
|
3
|
+
* Enables the model to propose surface patches when used in surface-runtime contexts.
|
|
4
|
+
* Requires @contractspec/lib.surface-runtime (optional peer).
|
|
5
|
+
*/
|
|
6
|
+
import { type ToolSet } from 'ai';
|
|
7
|
+
import type { ResolvedSurfacePlan } from '@contractspec/lib.surface-runtime/runtime/resolve-bundle';
|
|
8
|
+
import { type PatchProposalConstraints } from '@contractspec/lib.surface-runtime/spec/validate-surface-patch';
|
|
9
|
+
import type { SurfacePatchProposal } from '@contractspec/lib.surface-runtime/spec/types';
|
|
10
|
+
export interface SurfacePlannerToolsConfig {
|
|
11
|
+
plan: ResolvedSurfacePlan;
|
|
12
|
+
/** Optional; derived from plan layout when omitted */
|
|
13
|
+
constraints?: PatchProposalConstraints;
|
|
14
|
+
/** Called when a valid proposal is produced; host app stores in plan.ai.proposals */
|
|
15
|
+
onPatchProposal?: (proposal: SurfacePatchProposal) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create AI SDK tools for surface patch proposals.
|
|
19
|
+
* Tool: propose-patch
|
|
20
|
+
*/
|
|
21
|
+
export declare function createSurfacePlannerTools(config: SurfacePlannerToolsConfig): ToolSet;
|
|
22
|
+
/** Build PlannerPromptInput from ResolvedSurfacePlan for system prompt. */
|
|
23
|
+
export declare function buildPlannerPromptInput(plan: ResolvedSurfacePlan): import('@contractspec/lib.surface-runtime/runtime/planner-prompt').PlannerPromptInput;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thinking level abstraction for AI chat.
|
|
3
|
+
* Maps to provider-specific reasoning options (Anthropic budgetTokens, OpenAI reasoningEffort).
|
|
4
|
+
*/
|
|
5
|
+
import type { ProviderName } from '@contractspec/lib.ai-providers';
|
|
6
|
+
/**
|
|
7
|
+
* Thinking level: controls how much internal reasoning the model performs.
|
|
8
|
+
*/
|
|
9
|
+
export type ThinkingLevel = 'instant' | 'thinking' | 'extra_thinking' | 'max';
|
|
10
|
+
/**
|
|
11
|
+
* Human-readable labels for UI
|
|
12
|
+
*/
|
|
13
|
+
export declare const THINKING_LEVEL_LABELS: Record<ThinkingLevel, string>;
|
|
14
|
+
/**
|
|
15
|
+
* Descriptions for tooltips
|
|
16
|
+
*/
|
|
17
|
+
export declare const THINKING_LEVEL_DESCRIPTIONS: Record<ThinkingLevel, string>;
|
|
18
|
+
/**
|
|
19
|
+
* Provider options for streamText/generateText (AI SDK).
|
|
20
|
+
* Keys match provider names; only the active provider's options are used.
|
|
21
|
+
*/
|
|
22
|
+
export interface ProviderOptionsMap {
|
|
23
|
+
anthropic?: {
|
|
24
|
+
thinking?: {
|
|
25
|
+
type: 'enabled';
|
|
26
|
+
budgetTokens: number;
|
|
27
|
+
};
|
|
28
|
+
effort?: 'low' | 'medium' | 'high';
|
|
29
|
+
};
|
|
30
|
+
openai?: {
|
|
31
|
+
reasoningEffort?: 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get provider-specific options for the given thinking level and provider.
|
|
36
|
+
* Returns options suitable for AI SDK streamText/generateText providerOptions.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getProviderOptions(level: ThinkingLevel | undefined, providerName: ProviderName): ProviderOptionsMap;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI SDK tools for workflow creation via chat.
|
|
3
|
+
* Leverages @contractspec/lib.workflow-composer for validation and composition.
|
|
4
|
+
*/
|
|
5
|
+
import { type ToolSet } from 'ai';
|
|
6
|
+
import type { WorkflowSpec } from '@contractspec/lib.contracts-spec/workflow';
|
|
7
|
+
import { WorkflowComposer } from '@contractspec/lib.workflow-composer';
|
|
8
|
+
export interface WorkflowToolsConfig {
|
|
9
|
+
/** Base workflows keyed by meta.key for compose and validate */
|
|
10
|
+
baseWorkflows: WorkflowSpec[];
|
|
11
|
+
/** Optional pre-configured composer with extensions; if not provided, a fresh one is used per compose */
|
|
12
|
+
composer?: WorkflowComposer;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create AI SDK tools for workflow creation.
|
|
16
|
+
* Tools: create_workflow_extension, compose_workflow, generate_workflow_spec_code.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createWorkflowTools(config: WorkflowToolsConfig): ToolSet;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -11,5 +11,7 @@ export * from './schema';
|
|
|
11
11
|
export * from './ai-chat.operations';
|
|
12
12
|
export * from './events';
|
|
13
13
|
export * from './ai-chat.feature';
|
|
14
|
-
export { ChatContainer, ChatMessage as ChatMessageComponent, ChatInput, } from './presentation/components';
|
|
15
|
-
export { useChat, useProviders } from './presentation/hooks';
|
|
14
|
+
export { ChatContainer, ChatMessage as ChatMessageComponent, ChatInput, ChatExportToolbar, ChatWithExport, ChatSidebar, ChatWithSidebar, ThinkingLevelPicker, } from './presentation/components';
|
|
15
|
+
export { useChat, useProviders, useMessageSelection, useConversations, } from './presentation/hooks';
|
|
16
|
+
export { createAiSdkBundleAdapter, type CreateAiSdkBundleAdapterDeps, } from './adapters';
|
|
17
|
+
export { createChatAgentAdapter, type ChatAgentAdapter, } from './core/agent-adapter';
|