@svadmin/core 0.6.0 → 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.0",
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
+ }
@@ -94,6 +94,9 @@ const locales: Record<string, Locale> = {
94
94
  'auth.forgotPassword': '忘记密码',
95
95
  'auth.resetPassword': '重置密码',
96
96
  'auth.email': '邮箱',
97
+ 'auth.usernameOrEmail': '用户名或邮箱',
98
+ 'auth.usernameOrEmailRequired': '请输入用户名或邮箱',
99
+ 'auth.identifierPlaceholder': '用户名 / name@example.com',
97
100
  'auth.password': '密码',
98
101
  'auth.confirmPassword': '确认密码',
99
102
  'auth.rememberMe': '记住我',
@@ -223,6 +226,9 @@ const locales: Record<string, Locale> = {
223
226
  'auth.forgotPassword': 'Forgot Password',
224
227
  'auth.resetPassword': 'Reset Password',
225
228
  'auth.email': 'Email',
229
+ 'auth.usernameOrEmail': 'Username or Email',
230
+ 'auth.usernameOrEmailRequired': 'Username or Email is required',
231
+ 'auth.identifierPlaceholder': 'username or name@example.com',
226
232
  'auth.password': 'Password',
227
233
  'auth.confirmPassword': 'Confirm Password',
228
234
  'auth.rememberMe': 'Remember me',
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
+