@supernal/interface-nextjs 1.0.26 → 1.0.28

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/dist/index.d.mts CHANGED
@@ -1,8 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React$1 from 'react';
3
- import { NavigationGraph, NavigationPath, NavigationContext, ToolMetadata } from '@supernal/interface/browser';
4
- import { AIInterface } from '@supernal/interface';
5
- export { AICommand, AIResponse } from '@supernal/interface';
3
+ import { NavigationGraph, NavigationPath, NavigationContext, ToolMetadata, AIInterface } from '@supernal/interface/browser';
4
+ export { AICommand, AIResponse } from '@supernal/interface/browser';
6
5
 
7
6
  interface SupernalProviderProps {
8
7
  children: React$1.ReactNode;
@@ -134,15 +133,173 @@ interface ChatContextType {
134
133
  sendMessage: (text: string) => Promise<void>;
135
134
  clearMessages: () => void;
136
135
  isLoading: boolean;
136
+ /** Whether real AI mode is active (API key is valid) */
137
+ isAiMode: boolean;
137
138
  }
138
139
  declare function useChatContext(): ChatContextType;
139
- declare function ChatProvider({ children, mode, apiKey, onToolExecute, }: {
140
+ declare function ChatProvider({ children, mode, apiKey: propApiKey, onToolExecute, }: {
140
141
  children: React$1.ReactNode;
141
142
  mode?: 'fuzzy' | 'ai';
142
143
  apiKey?: string;
143
144
  onToolExecute?: (tool: string, result: any) => void;
144
145
  }): react_jsx_runtime.JSX.Element;
145
146
 
147
+ type ApiKeyStatus = 'none' | 'validating' | 'valid' | 'invalid' | 'locked';
148
+ interface UseApiKeyStorageOptions {
149
+ /**
150
+ * Enable encrypted storage (requires passphrase)
151
+ * @default false
152
+ */
153
+ encrypted?: boolean;
154
+ /**
155
+ * Callback when passphrase is needed for encrypted storage
156
+ */
157
+ onPassphraseRequired?: () => Promise<string>;
158
+ /**
159
+ * Callback when passphrase is invalid
160
+ */
161
+ onPassphraseInvalid?: () => void;
162
+ }
163
+ /**
164
+ * Hook for managing API key storage with validation
165
+ *
166
+ * This is the simple single-site version using localStorage.
167
+ * Compatible with future VaultClient integration for cross-site support.
168
+ *
169
+ * Features:
170
+ * - localStorage persistence (single site)
171
+ * - Format validation (sk-ant-* prefix, minimum length)
172
+ * - Optional live validation with Anthropic API
173
+ * - Masked display for security
174
+ * - Optional encryption at rest (Phase 1 of vault system)
175
+ *
176
+ * @param options - Configuration options
177
+ */
178
+ declare function useApiKeyStorage(options?: UseApiKeyStorageOptions): {
179
+ hasApiKey: boolean;
180
+ isLocked: boolean;
181
+ setApiKey: (key: string, validate?: boolean) => Promise<boolean>;
182
+ clearApiKey: () => void;
183
+ revalidate: () => Promise<boolean>;
184
+ unlock: (passphrase: string) => Promise<boolean>;
185
+ lock: () => void;
186
+ apiKey: string | null;
187
+ status: ApiKeyStatus;
188
+ error: string | null;
189
+ maskedKey: string | null;
190
+ };
191
+ type UseApiKeyStorageReturn = ReturnType<typeof useApiKeyStorage>;
192
+
193
+ interface ApiKeyProviderProps {
194
+ children: React$1.ReactNode;
195
+ /**
196
+ * Optional initial API key (e.g., from environment variable for dev)
197
+ * If provided and no key is in storage, this will be used
198
+ */
199
+ initialApiKey?: string;
200
+ }
201
+ declare function ApiKeyProvider({ children, initialApiKey }: ApiKeyProviderProps): react_jsx_runtime.JSX.Element;
202
+ /**
203
+ * Hook to access API key state and methods
204
+ * Must be used within ApiKeyProvider
205
+ */
206
+ declare function useApiKey(): UseApiKeyStorageReturn;
207
+ /**
208
+ * Hook to optionally access API key state
209
+ * Returns null if not within ApiKeyProvider (no error thrown)
210
+ */
211
+ declare function useApiKeyOptional(): UseApiKeyStorageReturn | null;
212
+
213
+ /**
214
+ * ClaudeClient - Simple direct API client for BYOK mode
215
+ *
216
+ * This client makes direct calls to the Anthropic API using the user's API key.
217
+ * It's designed for the BYOK (Bring Your Own Key) flow where users provide
218
+ * their own Anthropic API key.
219
+ *
220
+ * Note: This requires the 'anthropic-dangerous-direct-browser-access' header
221
+ * which Anthropic provides for browser-based applications.
222
+ *
223
+ * For production cross-site key management, see:
224
+ * docs/research/cross-site-key-management-byok.md
225
+ */
226
+ interface ClaudeMessage {
227
+ role: 'user' | 'assistant';
228
+ content: string;
229
+ }
230
+ interface ClaudeResponse {
231
+ id: string;
232
+ type: 'message';
233
+ role: 'assistant';
234
+ content: Array<{
235
+ type: 'text';
236
+ text: string;
237
+ }>;
238
+ model: string;
239
+ stop_reason: 'end_turn' | 'max_tokens' | 'stop_sequence' | null;
240
+ usage: {
241
+ input_tokens: number;
242
+ output_tokens: number;
243
+ };
244
+ }
245
+ interface ClaudeClientConfig {
246
+ apiKey: string;
247
+ model?: string;
248
+ maxTokens?: number;
249
+ systemPrompt?: string;
250
+ }
251
+ interface SendMessageOptions {
252
+ /** Conversation history to include */
253
+ messages?: ClaudeMessage[];
254
+ /** Override system prompt for this request */
255
+ systemPrompt?: string;
256
+ /** Override max tokens for this request */
257
+ maxTokens?: number;
258
+ /** Temperature (0-1) for response randomness */
259
+ temperature?: number;
260
+ }
261
+ interface SendMessageResult {
262
+ success: boolean;
263
+ message: string;
264
+ response?: ClaudeResponse;
265
+ error?: string;
266
+ usage?: {
267
+ inputTokens: number;
268
+ outputTokens: number;
269
+ estimatedCost: number;
270
+ };
271
+ }
272
+ /**
273
+ * Simple Claude API client for BYOK mode
274
+ */
275
+ declare class ClaudeClient {
276
+ private apiKey;
277
+ private model;
278
+ private maxTokens;
279
+ private systemPrompt;
280
+ constructor(config: ClaudeClientConfig);
281
+ /**
282
+ * Send a message to Claude and get a response
283
+ */
284
+ sendMessage(userMessage: string, options?: SendMessageOptions): Promise<SendMessageResult>;
285
+ /**
286
+ * Update the API key
287
+ */
288
+ setApiKey(apiKey: string): void;
289
+ /**
290
+ * Update the model
291
+ */
292
+ setModel(model: string): void;
293
+ /**
294
+ * Update the system prompt
295
+ */
296
+ setSystemPrompt(systemPrompt: string): void;
297
+ }
298
+ /**
299
+ * Create a Claude client instance
300
+ */
301
+ declare function createClaudeClient(config: ClaudeClientConfig): ClaudeClient;
302
+
146
303
  /**
147
304
  * Type definitions for ChatBubble component
148
305
  */
@@ -341,6 +498,18 @@ declare const Components: {
341
498
  readonly ChatInput: "chat-message-input";
342
499
  readonly ChatSendButton: "chat-send-button";
343
500
  readonly ChatClearButton: "chat-clear-button";
501
+ readonly ChatMoreMenu: "chat-more-menu";
502
+ readonly ChatMoreMenuButton: "chat-more-menu-button";
503
+ readonly ApiKeySection: "api-key-section";
504
+ readonly ApiKeyInput: "api-key-input";
505
+ readonly ApiKeySubmitButton: "api-key-submit-button";
506
+ readonly ApiKeyClearButton: "api-key-clear-button";
507
+ readonly ApiKeyConfigureButton: "api-key-configure-button";
508
+ readonly ApiKeyStatus: "api-key-status";
509
+ readonly ApiKeyMasked: "api-key-masked";
510
+ readonly ApiKeyError: "api-key-error";
511
+ readonly ApiKeyShowToggle: "api-key-show-toggle";
512
+ readonly ApiKeyCancelButton: "api-key-cancel-button";
344
513
  };
345
514
  /**
346
515
  * ChatBubbleVariant - Display modes for the chat interface
@@ -507,4 +676,4 @@ declare function scoreToolMatch(query: string, tool: ToolMetadata): number;
507
676
  */
508
677
  declare function findBestMatch(query: string, tools: ToolMetadata[]): FuzzyMatchResult;
509
678
 
510
- export { AutoNavigationContext, ChatBubble, type ChatBubbleSettings, ChatBubbleSettingsModal, ChatBubbleVariant, type ChatBubbleVariantType, type ChatBubbleVariantValue, ChatInputProvider, ChatProvider, CodeBlock, type CommandResult, Components, DemoAIInterface, type FuzzyMatchResult, FuzzyMatcher, MermaidDiagram, MessageRenderer, NavigationContextProvider, PageLayout, type PageLayoutType, type PageLayoutValue, SubtitleOverlay, SupernalProvider, type SupernalProviderProps, type ToolExecutionResult, ToolManager, type ToolMenuCategory, ToolMenuPopup, ToolMenuPopupTrigger, type UseToolMenuReturn, findBestMatch, scoreToolMatch, useAllContexts, useChatContext, useChatInput, useCurrentContext, useNavigate, useNavigationGraph, useNavigationPath, useRegisterTool, useToolMenu };
679
+ export { ApiKeyProvider, type ApiKeyStatus, AutoNavigationContext, ChatBubble, type ChatBubbleSettings, ChatBubbleSettingsModal, ChatBubbleVariant, type ChatBubbleVariantType, type ChatBubbleVariantValue, ChatInputProvider, ChatProvider, ClaudeClient, type ClaudeClientConfig, type ClaudeMessage, type ClaudeResponse, CodeBlock, type CommandResult, Components, DemoAIInterface, type FuzzyMatchResult, FuzzyMatcher, MermaidDiagram, MessageRenderer, NavigationContextProvider, PageLayout, type PageLayoutType, type PageLayoutValue, type SendMessageOptions, type SendMessageResult, SubtitleOverlay, SupernalProvider, type SupernalProviderProps, type ToolExecutionResult, ToolManager, type ToolMenuCategory, ToolMenuPopup, ToolMenuPopupTrigger, type UseApiKeyStorageReturn, type UseToolMenuReturn, createClaudeClient, findBestMatch, scoreToolMatch, useAllContexts, useApiKey, useApiKeyOptional, useApiKeyStorage, useChatContext, useChatInput, useCurrentContext, useNavigate, useNavigationGraph, useNavigationPath, useRegisterTool, useToolMenu };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React$1 from 'react';
3
- import { NavigationGraph, NavigationPath, NavigationContext, ToolMetadata } from '@supernal/interface/browser';
4
- import { AIInterface } from '@supernal/interface';
5
- export { AICommand, AIResponse } from '@supernal/interface';
3
+ import { NavigationGraph, NavigationPath, NavigationContext, ToolMetadata, AIInterface } from '@supernal/interface/browser';
4
+ export { AICommand, AIResponse } from '@supernal/interface/browser';
6
5
 
7
6
  interface SupernalProviderProps {
8
7
  children: React$1.ReactNode;
@@ -134,15 +133,173 @@ interface ChatContextType {
134
133
  sendMessage: (text: string) => Promise<void>;
135
134
  clearMessages: () => void;
136
135
  isLoading: boolean;
136
+ /** Whether real AI mode is active (API key is valid) */
137
+ isAiMode: boolean;
137
138
  }
138
139
  declare function useChatContext(): ChatContextType;
139
- declare function ChatProvider({ children, mode, apiKey, onToolExecute, }: {
140
+ declare function ChatProvider({ children, mode, apiKey: propApiKey, onToolExecute, }: {
140
141
  children: React$1.ReactNode;
141
142
  mode?: 'fuzzy' | 'ai';
142
143
  apiKey?: string;
143
144
  onToolExecute?: (tool: string, result: any) => void;
144
145
  }): react_jsx_runtime.JSX.Element;
145
146
 
147
+ type ApiKeyStatus = 'none' | 'validating' | 'valid' | 'invalid' | 'locked';
148
+ interface UseApiKeyStorageOptions {
149
+ /**
150
+ * Enable encrypted storage (requires passphrase)
151
+ * @default false
152
+ */
153
+ encrypted?: boolean;
154
+ /**
155
+ * Callback when passphrase is needed for encrypted storage
156
+ */
157
+ onPassphraseRequired?: () => Promise<string>;
158
+ /**
159
+ * Callback when passphrase is invalid
160
+ */
161
+ onPassphraseInvalid?: () => void;
162
+ }
163
+ /**
164
+ * Hook for managing API key storage with validation
165
+ *
166
+ * This is the simple single-site version using localStorage.
167
+ * Compatible with future VaultClient integration for cross-site support.
168
+ *
169
+ * Features:
170
+ * - localStorage persistence (single site)
171
+ * - Format validation (sk-ant-* prefix, minimum length)
172
+ * - Optional live validation with Anthropic API
173
+ * - Masked display for security
174
+ * - Optional encryption at rest (Phase 1 of vault system)
175
+ *
176
+ * @param options - Configuration options
177
+ */
178
+ declare function useApiKeyStorage(options?: UseApiKeyStorageOptions): {
179
+ hasApiKey: boolean;
180
+ isLocked: boolean;
181
+ setApiKey: (key: string, validate?: boolean) => Promise<boolean>;
182
+ clearApiKey: () => void;
183
+ revalidate: () => Promise<boolean>;
184
+ unlock: (passphrase: string) => Promise<boolean>;
185
+ lock: () => void;
186
+ apiKey: string | null;
187
+ status: ApiKeyStatus;
188
+ error: string | null;
189
+ maskedKey: string | null;
190
+ };
191
+ type UseApiKeyStorageReturn = ReturnType<typeof useApiKeyStorage>;
192
+
193
+ interface ApiKeyProviderProps {
194
+ children: React$1.ReactNode;
195
+ /**
196
+ * Optional initial API key (e.g., from environment variable for dev)
197
+ * If provided and no key is in storage, this will be used
198
+ */
199
+ initialApiKey?: string;
200
+ }
201
+ declare function ApiKeyProvider({ children, initialApiKey }: ApiKeyProviderProps): react_jsx_runtime.JSX.Element;
202
+ /**
203
+ * Hook to access API key state and methods
204
+ * Must be used within ApiKeyProvider
205
+ */
206
+ declare function useApiKey(): UseApiKeyStorageReturn;
207
+ /**
208
+ * Hook to optionally access API key state
209
+ * Returns null if not within ApiKeyProvider (no error thrown)
210
+ */
211
+ declare function useApiKeyOptional(): UseApiKeyStorageReturn | null;
212
+
213
+ /**
214
+ * ClaudeClient - Simple direct API client for BYOK mode
215
+ *
216
+ * This client makes direct calls to the Anthropic API using the user's API key.
217
+ * It's designed for the BYOK (Bring Your Own Key) flow where users provide
218
+ * their own Anthropic API key.
219
+ *
220
+ * Note: This requires the 'anthropic-dangerous-direct-browser-access' header
221
+ * which Anthropic provides for browser-based applications.
222
+ *
223
+ * For production cross-site key management, see:
224
+ * docs/research/cross-site-key-management-byok.md
225
+ */
226
+ interface ClaudeMessage {
227
+ role: 'user' | 'assistant';
228
+ content: string;
229
+ }
230
+ interface ClaudeResponse {
231
+ id: string;
232
+ type: 'message';
233
+ role: 'assistant';
234
+ content: Array<{
235
+ type: 'text';
236
+ text: string;
237
+ }>;
238
+ model: string;
239
+ stop_reason: 'end_turn' | 'max_tokens' | 'stop_sequence' | null;
240
+ usage: {
241
+ input_tokens: number;
242
+ output_tokens: number;
243
+ };
244
+ }
245
+ interface ClaudeClientConfig {
246
+ apiKey: string;
247
+ model?: string;
248
+ maxTokens?: number;
249
+ systemPrompt?: string;
250
+ }
251
+ interface SendMessageOptions {
252
+ /** Conversation history to include */
253
+ messages?: ClaudeMessage[];
254
+ /** Override system prompt for this request */
255
+ systemPrompt?: string;
256
+ /** Override max tokens for this request */
257
+ maxTokens?: number;
258
+ /** Temperature (0-1) for response randomness */
259
+ temperature?: number;
260
+ }
261
+ interface SendMessageResult {
262
+ success: boolean;
263
+ message: string;
264
+ response?: ClaudeResponse;
265
+ error?: string;
266
+ usage?: {
267
+ inputTokens: number;
268
+ outputTokens: number;
269
+ estimatedCost: number;
270
+ };
271
+ }
272
+ /**
273
+ * Simple Claude API client for BYOK mode
274
+ */
275
+ declare class ClaudeClient {
276
+ private apiKey;
277
+ private model;
278
+ private maxTokens;
279
+ private systemPrompt;
280
+ constructor(config: ClaudeClientConfig);
281
+ /**
282
+ * Send a message to Claude and get a response
283
+ */
284
+ sendMessage(userMessage: string, options?: SendMessageOptions): Promise<SendMessageResult>;
285
+ /**
286
+ * Update the API key
287
+ */
288
+ setApiKey(apiKey: string): void;
289
+ /**
290
+ * Update the model
291
+ */
292
+ setModel(model: string): void;
293
+ /**
294
+ * Update the system prompt
295
+ */
296
+ setSystemPrompt(systemPrompt: string): void;
297
+ }
298
+ /**
299
+ * Create a Claude client instance
300
+ */
301
+ declare function createClaudeClient(config: ClaudeClientConfig): ClaudeClient;
302
+
146
303
  /**
147
304
  * Type definitions for ChatBubble component
148
305
  */
@@ -341,6 +498,18 @@ declare const Components: {
341
498
  readonly ChatInput: "chat-message-input";
342
499
  readonly ChatSendButton: "chat-send-button";
343
500
  readonly ChatClearButton: "chat-clear-button";
501
+ readonly ChatMoreMenu: "chat-more-menu";
502
+ readonly ChatMoreMenuButton: "chat-more-menu-button";
503
+ readonly ApiKeySection: "api-key-section";
504
+ readonly ApiKeyInput: "api-key-input";
505
+ readonly ApiKeySubmitButton: "api-key-submit-button";
506
+ readonly ApiKeyClearButton: "api-key-clear-button";
507
+ readonly ApiKeyConfigureButton: "api-key-configure-button";
508
+ readonly ApiKeyStatus: "api-key-status";
509
+ readonly ApiKeyMasked: "api-key-masked";
510
+ readonly ApiKeyError: "api-key-error";
511
+ readonly ApiKeyShowToggle: "api-key-show-toggle";
512
+ readonly ApiKeyCancelButton: "api-key-cancel-button";
344
513
  };
345
514
  /**
346
515
  * ChatBubbleVariant - Display modes for the chat interface
@@ -507,4 +676,4 @@ declare function scoreToolMatch(query: string, tool: ToolMetadata): number;
507
676
  */
508
677
  declare function findBestMatch(query: string, tools: ToolMetadata[]): FuzzyMatchResult;
509
678
 
510
- export { AutoNavigationContext, ChatBubble, type ChatBubbleSettings, ChatBubbleSettingsModal, ChatBubbleVariant, type ChatBubbleVariantType, type ChatBubbleVariantValue, ChatInputProvider, ChatProvider, CodeBlock, type CommandResult, Components, DemoAIInterface, type FuzzyMatchResult, FuzzyMatcher, MermaidDiagram, MessageRenderer, NavigationContextProvider, PageLayout, type PageLayoutType, type PageLayoutValue, SubtitleOverlay, SupernalProvider, type SupernalProviderProps, type ToolExecutionResult, ToolManager, type ToolMenuCategory, ToolMenuPopup, ToolMenuPopupTrigger, type UseToolMenuReturn, findBestMatch, scoreToolMatch, useAllContexts, useChatContext, useChatInput, useCurrentContext, useNavigate, useNavigationGraph, useNavigationPath, useRegisterTool, useToolMenu };
679
+ export { ApiKeyProvider, type ApiKeyStatus, AutoNavigationContext, ChatBubble, type ChatBubbleSettings, ChatBubbleSettingsModal, ChatBubbleVariant, type ChatBubbleVariantType, type ChatBubbleVariantValue, ChatInputProvider, ChatProvider, ClaudeClient, type ClaudeClientConfig, type ClaudeMessage, type ClaudeResponse, CodeBlock, type CommandResult, Components, DemoAIInterface, type FuzzyMatchResult, FuzzyMatcher, MermaidDiagram, MessageRenderer, NavigationContextProvider, PageLayout, type PageLayoutType, type PageLayoutValue, type SendMessageOptions, type SendMessageResult, SubtitleOverlay, SupernalProvider, type SupernalProviderProps, type ToolExecutionResult, ToolManager, type ToolMenuCategory, ToolMenuPopup, ToolMenuPopupTrigger, type UseApiKeyStorageReturn, type UseToolMenuReturn, createClaudeClient, findBestMatch, scoreToolMatch, useAllContexts, useApiKey, useApiKeyOptional, useApiKeyStorage, useChatContext, useChatInput, useCurrentContext, useNavigate, useNavigationGraph, useNavigationPath, useRegisterTool, useToolMenu };