@svadmin/core 0.6.1 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svadmin/core",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Core SDK — hooks, types, context, i18n, permissions, router",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -0,0 +1,32 @@
1
+ // Chat provider — headless interface for AI chat integration
2
+
3
+ export interface ChatMessage {
4
+ id: string;
5
+ role: 'user' | 'assistant' | 'system';
6
+ content: string;
7
+ timestamp: number;
8
+ }
9
+
10
+ /**
11
+ * ChatProvider interface for integrating AI chat into admin panels.
12
+ * Implement `sendMessage` to connect to any AI backend (OpenAI, self-hosted, etc.)
13
+ *
14
+ * Return a `string` for non-streaming responses, or an `AsyncGenerator<string>`
15
+ * for streaming (SSE / chunked) responses.
16
+ */
17
+ export interface ChatProvider {
18
+ sendMessage(
19
+ messages: ChatMessage[],
20
+ options?: { signal?: AbortSignal },
21
+ ): Promise<string> | AsyncGenerator<string, void, unknown>;
22
+ }
23
+
24
+ let chatProvider: ChatProvider | null = null;
25
+
26
+ export function setChatProvider(provider: ChatProvider): void {
27
+ chatProvider = provider;
28
+ }
29
+
30
+ export function getChatProvider(): ChatProvider | null {
31
+ return chatProvider;
32
+ }
package/src/index.ts CHANGED
@@ -35,6 +35,8 @@ export { notify, closeNotification, setNotificationProvider, getNotificationProv
35
35
  export { t, setLocale, getLocale, getAvailableLocales, addTranslations, useTranslation } from './i18n.svelte';
36
36
  export { audit, setAuditHandler, setAuditLogProvider, getAuditLogProvider } from './audit';
37
37
  export type { AuditLogProvider } from './audit';
38
+ export { setChatProvider, getChatProvider } from './chatProvider';
39
+ export type { ChatProvider, ChatMessage } from './chatProvider';
38
40
  export { getTheme, setTheme, toggleTheme, getResolvedTheme, getColorTheme, setColorTheme, colorThemes } from './theme.svelte';
39
41
  export type { ThemeMode, ColorTheme } from './theme.svelte';
40
42
  export { setUnsavedChanges, getUnsavedChanges, initUnsavedChangesNotifier } from './unsaved-changes.svelte';
package/src/useCan.ts CHANGED
@@ -39,16 +39,19 @@ export function useCan(resourceOrOptions: string | UseCanOptions, action?: Actio
39
39
  ? { resource: resourceOrOptions, action: action ?? 'list', params }
40
40
  : resourceOrOptions;
41
41
 
42
+ // @tanstack/svelte-query v6 Accessor pattern
42
43
  const query = createQuery<CanResult>(() => ({
43
- queryKey: ['useCan', options.resource, options.action, options.params],
44
+ queryKey: ['useCan', options.resource, options.action, options.params] as const,
44
45
  queryFn: () => canAccessAsync(options.resource, options.action, options.params),
45
46
  enabled: options.queryOptions?.enabled ?? true,
46
47
  staleTime: options.queryOptions?.staleTime ?? 5 * 60 * 1000, // 5 min default cache
47
48
  }));
48
49
 
50
+ // Access via query store — use safe property access with fallbacks
49
51
  return {
50
- get allowed() { return query.data?.can ?? true; },
51
- get reason() { return query.data?.reason; },
52
+ get allowed() { return (query.data as CanResult | undefined)?.can ?? true; },
53
+ get reason() { return (query.data as CanResult | undefined)?.reason; },
52
54
  get isLoading() { return query.isLoading; },
53
55
  };
54
56
  }
57
+