@lantos1618/better-ui 0.2.3 → 0.4.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.
Files changed (83) hide show
  1. package/README.md +271 -354
  2. package/dist/ThemeProvider-BYeqWMsn.d.mts +187 -0
  3. package/dist/ThemeProvider-BaVZaDBO.d.ts +187 -0
  4. package/dist/auth/index.d.mts +56 -0
  5. package/dist/auth/index.d.ts +56 -0
  6. package/dist/auth/index.js +104 -0
  7. package/dist/auth/index.mjs +67 -0
  8. package/dist/chunk-Y6FXYEAI.mjs +10 -0
  9. package/dist/components/index.d.mts +258 -0
  10. package/dist/components/index.d.ts +258 -0
  11. package/dist/components/index.js +1977 -0
  12. package/dist/components/index.mjs +1922 -0
  13. package/dist/index.d.mts +75 -0
  14. package/dist/index.d.ts +75 -0
  15. package/dist/index.js +587 -0
  16. package/dist/index.mjs +557 -0
  17. package/dist/persistence/index.d.mts +11 -0
  18. package/dist/persistence/index.d.ts +11 -0
  19. package/dist/persistence/index.js +66 -0
  20. package/dist/persistence/index.mjs +41 -0
  21. package/dist/react/index.d.mts +91 -0
  22. package/dist/react/index.d.ts +91 -0
  23. package/dist/react/index.js +284 -0
  24. package/dist/react/index.mjs +257 -0
  25. package/dist/tool-Ca2x-VNK.d.mts +361 -0
  26. package/dist/tool-Ca2x-VNK.d.ts +361 -0
  27. package/dist/types-CAOfGUPH.d.mts +31 -0
  28. package/dist/types-CAOfGUPH.d.ts +31 -0
  29. package/package.json +85 -30
  30. package/src/theme.css +101 -0
  31. package/lib/aui/README.md +0 -136
  32. package/lib/aui/__tests__/aui-complete.test.ts +0 -251
  33. package/lib/aui/__tests__/aui-comprehensive.test.ts +0 -376
  34. package/lib/aui/__tests__/aui-concise.test.ts +0 -278
  35. package/lib/aui/__tests__/aui-integration.test.ts +0 -309
  36. package/lib/aui/__tests__/aui-simple.test.ts +0 -116
  37. package/lib/aui/__tests__/aui.test.ts +0 -269
  38. package/lib/aui/__tests__/concise-api.test.ts +0 -165
  39. package/lib/aui/__tests__/core.test.ts +0 -265
  40. package/lib/aui/__tests__/simple-api.test.ts +0 -200
  41. package/lib/aui/ai-assistant.ts +0 -408
  42. package/lib/aui/ai-control.ts +0 -353
  43. package/lib/aui/client/use-aui.ts +0 -55
  44. package/lib/aui/client-control.ts +0 -551
  45. package/lib/aui/client-executor.ts +0 -417
  46. package/lib/aui/components/ToolRenderer.tsx +0 -22
  47. package/lib/aui/core.ts +0 -137
  48. package/lib/aui/demo.tsx +0 -89
  49. package/lib/aui/examples/ai-complete-demo.tsx +0 -359
  50. package/lib/aui/examples/ai-control-demo.tsx +0 -356
  51. package/lib/aui/examples/ai-control-tools.ts +0 -308
  52. package/lib/aui/examples/concise-api.tsx +0 -153
  53. package/lib/aui/examples/index.tsx +0 -163
  54. package/lib/aui/examples/quick-demo.tsx +0 -91
  55. package/lib/aui/examples/simple-demo.tsx +0 -71
  56. package/lib/aui/examples/simple-tools.tsx +0 -160
  57. package/lib/aui/examples/user-api.tsx +0 -208
  58. package/lib/aui/examples/user-requested.tsx +0 -174
  59. package/lib/aui/examples/weather-search-tools.tsx +0 -119
  60. package/lib/aui/examples.tsx +0 -367
  61. package/lib/aui/hooks/useAUITool.ts +0 -142
  62. package/lib/aui/hooks/useAUIToolEnhanced.ts +0 -343
  63. package/lib/aui/hooks/useAUITools.ts +0 -195
  64. package/lib/aui/index.ts +0 -156
  65. package/lib/aui/provider.tsx +0 -45
  66. package/lib/aui/server-control.ts +0 -386
  67. package/lib/aui/server-executor.ts +0 -165
  68. package/lib/aui/server.ts +0 -167
  69. package/lib/aui/tool-registry.ts +0 -380
  70. package/lib/aui/tools/advanced-examples.tsx +0 -86
  71. package/lib/aui/tools/ai-complete.ts +0 -375
  72. package/lib/aui/tools/api-tools.tsx +0 -230
  73. package/lib/aui/tools/data-tools.tsx +0 -232
  74. package/lib/aui/tools/dom-tools.tsx +0 -202
  75. package/lib/aui/tools/examples.ts +0 -43
  76. package/lib/aui/tools/file-tools.tsx +0 -202
  77. package/lib/aui/tools/form-tools.tsx +0 -233
  78. package/lib/aui/tools/index.ts +0 -8
  79. package/lib/aui/tools/navigation-tools.tsx +0 -172
  80. package/lib/aui/tools/notification-tools.ts +0 -213
  81. package/lib/aui/tools/state-tools.tsx +0 -209
  82. package/lib/aui/types.ts +0 -47
  83. package/lib/aui/vercel-ai.ts +0 -100
@@ -0,0 +1,187 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React from 'react';
3
+ import { UIMessage, ChatStatus } from 'ai';
4
+ import { T as Tool } from './tool-Ca2x-VNK.mjs';
5
+ import { P as PersistenceAdapter, T as Thread$1 } from './types-CAOfGUPH.mjs';
6
+
7
+ interface ToolStateEntry {
8
+ output: unknown;
9
+ loading: boolean;
10
+ error: string | null;
11
+ version: number;
12
+ toolName?: string;
13
+ /** HITL confirmation status */
14
+ status?: 'pending' | 'confirmed' | 'rejected';
15
+ /** Entity group key — "toolName:groupKey(input)" — groups related calls */
16
+ entityId?: string;
17
+ /** Raw tool input, stored for conditional confirm checks */
18
+ toolInput?: unknown;
19
+ /** Auto-incrementing insertion order (store-assigned) */
20
+ seqNo?: number;
21
+ }
22
+ interface ToolStateStore {
23
+ get: (toolCallId: string) => ToolStateEntry | undefined;
24
+ set: (toolCallId: string, entry: ToolStateEntry) => void;
25
+ /** Remove all entries (e.g. when switching threads) */
26
+ clear: () => void;
27
+ subscribe: (toolCallId: string, listener: () => void) => () => void;
28
+ subscribeAll: (listener: () => void) => () => void;
29
+ getSnapshot: () => Map<string, ToolStateEntry>;
30
+ /** Returns Map with highest-seqNo entry per entityId + all ungrouped entries */
31
+ getLatestPerEntity: () => Map<string, ToolStateEntry>;
32
+ /** Returns the oldest (lowest seqNo) entry with the given entityId — the "anchor" */
33
+ findAnchor: (entityId: string) => {
34
+ toolCallId: string;
35
+ entry: ToolStateEntry;
36
+ } | undefined;
37
+ }
38
+ declare function createToolStateStore(): ToolStateStore;
39
+ declare function useToolState(store: ToolStateStore, toolCallId: string): ToolStateEntry | undefined;
40
+
41
+ /** Parsed tool part from a UIMessage */
42
+ interface ToolPartInfo {
43
+ toolName: string;
44
+ toolCallId: string;
45
+ state: string;
46
+ output: unknown;
47
+ }
48
+ interface ChatContextValue {
49
+ messages: UIMessage[];
50
+ sendMessage: (text: string) => void;
51
+ isLoading: boolean;
52
+ status: ChatStatus;
53
+ tools: Record<string, Tool>;
54
+ executeToolDirect: (toolName: string, toolInput: Record<string, unknown>, toolCallId: string) => Promise<void>;
55
+ getOnAction: (toolCallId: string, toolName: string) => (input: Record<string, unknown>) => void;
56
+ toolStateStore: ToolStateStore;
57
+ /** Approve and execute a HITL tool, then feed result back to AI */
58
+ confirmTool: (toolCallId: string, toolName: string, toolInput: Record<string, unknown>) => Promise<void>;
59
+ /** Reject a HITL tool and notify AI */
60
+ rejectTool: (toolCallId: string, toolName: string) => Promise<void>;
61
+ /** Retry a failed tool execution */
62
+ retryTool: (toolCallId: string, toolName: string, toolInput: unknown) => void;
63
+ /** Available threads (only when persistence is configured) */
64
+ threads?: Thread$1[];
65
+ /** Current thread ID */
66
+ threadId?: string;
67
+ /** Create a new thread (only when persistence is configured) */
68
+ createThread?: (title?: string) => Promise<Thread$1>;
69
+ /** Switch to a different thread (only when persistence is configured) */
70
+ switchThread?: (threadId: string) => Promise<void>;
71
+ /** Delete a thread (only when persistence is configured) */
72
+ deleteThread?: (threadId: string) => Promise<void>;
73
+ }
74
+ interface ChatProviderProps {
75
+ endpoint?: string;
76
+ tools: Record<string, Tool>;
77
+ toolStateStore?: ToolStateStore;
78
+ /** Persistence adapter for thread/message storage */
79
+ persistence?: PersistenceAdapter;
80
+ /** Active thread ID (used with persistence) */
81
+ threadId?: string;
82
+ children: React.ReactNode;
83
+ }
84
+ /**
85
+ * Hook to access chat context. Must be used within a ChatProvider.
86
+ */
87
+ declare function useChatContext(): ChatContextValue;
88
+ declare function ChatProvider({ endpoint, tools, toolStateStore: externalStore, persistence, threadId, children }: ChatProviderProps): react_jsx_runtime.JSX.Element;
89
+
90
+ interface ThreadProps {
91
+ className?: string;
92
+ emptyMessage?: string;
93
+ suggestions?: string[];
94
+ }
95
+ /**
96
+ * Message list with auto-scroll.
97
+ * Renders messages from ChatContext, maps over messages, renders text parts and tool parts.
98
+ */
99
+ declare function Thread({ className, emptyMessage, suggestions }: ThreadProps): react_jsx_runtime.JSX.Element;
100
+
101
+ interface MessageProps {
102
+ message: UIMessage;
103
+ tools: Record<string, Tool>;
104
+ toolStateStore: ToolStateStore;
105
+ getOnAction: (toolCallId: string, toolName: string) => (input: Record<string, unknown>) => void;
106
+ onConfirm?: (toolCallId: string, toolName: string, toolInput: Record<string, unknown>) => void;
107
+ onReject?: (toolCallId: string, toolName: string) => void;
108
+ onRetry?: (toolCallId: string, toolName: string, toolInput: unknown) => void;
109
+ className?: string;
110
+ }
111
+ /**
112
+ * Renders a single UIMessage.
113
+ * - User messages: right-aligned bubble (plain text)
114
+ * - Assistant messages: left-aligned bubble (rendered markdown)
115
+ * - Tool parts: renders tool.View automatically
116
+ */
117
+ declare function Message({ message, tools, toolStateStore, getOnAction, onConfirm, onReject, onRetry, className }: MessageProps): react_jsx_runtime.JSX.Element | null;
118
+
119
+ interface ComposerProps {
120
+ className?: string;
121
+ placeholder?: string;
122
+ }
123
+ /**
124
+ * Input form with text input and send button.
125
+ * Uses ChatContext to send messages. Disabled during loading.
126
+ */
127
+ declare function Composer({ className, placeholder }: ComposerProps): react_jsx_runtime.JSX.Element;
128
+
129
+ interface ToolResultProps {
130
+ toolName: string;
131
+ toolCallId: string;
132
+ output: unknown;
133
+ toolInput?: unknown;
134
+ hasResult: boolean;
135
+ /** Tool part state from the AI SDK (e.g. 'partial-call', 'call', 'output-available') */
136
+ toolPartState?: string;
137
+ toolStateStore: ToolStateStore;
138
+ tools: Record<string, Tool>;
139
+ getOnAction: (toolCallId: string, toolName: string) => (input: Record<string, unknown>) => void;
140
+ onConfirm?: (toolCallId: string, toolName: string, toolInput: Record<string, unknown>) => void;
141
+ onReject?: (toolCallId: string, toolName: string) => void;
142
+ onRetry?: (toolCallId: string, toolName: string, toolInput: unknown) => void;
143
+ className?: string;
144
+ }
145
+ /**
146
+ * Renders a tool's View component given tool name and output.
147
+ * Uses the tool state store for in-place updates (e.g. counter clicks),
148
+ * falling back to message part state.
149
+ *
150
+ * For HITL tools (confirm: true), renders a confirmation card when
151
+ * the tool is awaiting user approval.
152
+ *
153
+ * Supports groupKey-based in-place updates: when an older call (anchor) with
154
+ * the same entityId exists, followup calls update the anchor's data and render nothing.
155
+ */
156
+ declare function ToolResult({ toolName, toolCallId, output, toolInput, hasResult, toolPartState, toolStateStore, tools, getOnAction, onConfirm, onReject, onRetry, className, }: ToolResultProps): react_jsx_runtime.JSX.Element | null;
157
+
158
+ interface ChatProps {
159
+ endpoint?: string;
160
+ tools: Record<string, Tool>;
161
+ className?: string;
162
+ placeholder?: string;
163
+ emptyMessage?: string;
164
+ suggestions?: string[];
165
+ }
166
+ /**
167
+ * Convenience all-in-one chat component.
168
+ * Combines ChatProvider + Thread + Composer into a single drop-in component.
169
+ */
170
+ declare function Chat({ endpoint, tools, className, placeholder, emptyMessage, suggestions, }: ChatProps): react_jsx_runtime.JSX.Element;
171
+
172
+ interface ThemeProviderProps {
173
+ /** Theme name — sets data-theme attribute. Default: 'dark' */
174
+ theme?: string;
175
+ /** Override individual CSS variables */
176
+ variables?: Record<string, string>;
177
+ /** Additional CSS class */
178
+ className?: string;
179
+ children: React.ReactNode;
180
+ }
181
+ /**
182
+ * Wraps children with a themed container.
183
+ * Sets `data-theme` for CSS variable scoping and applies inline variable overrides.
184
+ */
185
+ declare function ThemeProvider({ theme, variables, className, children, }: ThemeProviderProps): react_jsx_runtime.JSX.Element;
186
+
187
+ export { type ChatProviderProps as C, type MessageProps as M, type ToolPartInfo as T, type ThreadProps as a, type ComposerProps as b, type ToolResultProps as c, type ChatProps as d, type ThemeProviderProps as e, type ToolStateStore as f, type ToolStateEntry as g, ChatProvider as h, Thread as i, Message as j, Composer as k, ToolResult as l, Chat as m, createToolStateStore as n, useToolState as o, ThemeProvider as p, useChatContext as u };
@@ -0,0 +1,187 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React from 'react';
3
+ import { UIMessage, ChatStatus } from 'ai';
4
+ import { T as Tool } from './tool-Ca2x-VNK.js';
5
+ import { P as PersistenceAdapter, T as Thread$1 } from './types-CAOfGUPH.js';
6
+
7
+ interface ToolStateEntry {
8
+ output: unknown;
9
+ loading: boolean;
10
+ error: string | null;
11
+ version: number;
12
+ toolName?: string;
13
+ /** HITL confirmation status */
14
+ status?: 'pending' | 'confirmed' | 'rejected';
15
+ /** Entity group key — "toolName:groupKey(input)" — groups related calls */
16
+ entityId?: string;
17
+ /** Raw tool input, stored for conditional confirm checks */
18
+ toolInput?: unknown;
19
+ /** Auto-incrementing insertion order (store-assigned) */
20
+ seqNo?: number;
21
+ }
22
+ interface ToolStateStore {
23
+ get: (toolCallId: string) => ToolStateEntry | undefined;
24
+ set: (toolCallId: string, entry: ToolStateEntry) => void;
25
+ /** Remove all entries (e.g. when switching threads) */
26
+ clear: () => void;
27
+ subscribe: (toolCallId: string, listener: () => void) => () => void;
28
+ subscribeAll: (listener: () => void) => () => void;
29
+ getSnapshot: () => Map<string, ToolStateEntry>;
30
+ /** Returns Map with highest-seqNo entry per entityId + all ungrouped entries */
31
+ getLatestPerEntity: () => Map<string, ToolStateEntry>;
32
+ /** Returns the oldest (lowest seqNo) entry with the given entityId — the "anchor" */
33
+ findAnchor: (entityId: string) => {
34
+ toolCallId: string;
35
+ entry: ToolStateEntry;
36
+ } | undefined;
37
+ }
38
+ declare function createToolStateStore(): ToolStateStore;
39
+ declare function useToolState(store: ToolStateStore, toolCallId: string): ToolStateEntry | undefined;
40
+
41
+ /** Parsed tool part from a UIMessage */
42
+ interface ToolPartInfo {
43
+ toolName: string;
44
+ toolCallId: string;
45
+ state: string;
46
+ output: unknown;
47
+ }
48
+ interface ChatContextValue {
49
+ messages: UIMessage[];
50
+ sendMessage: (text: string) => void;
51
+ isLoading: boolean;
52
+ status: ChatStatus;
53
+ tools: Record<string, Tool>;
54
+ executeToolDirect: (toolName: string, toolInput: Record<string, unknown>, toolCallId: string) => Promise<void>;
55
+ getOnAction: (toolCallId: string, toolName: string) => (input: Record<string, unknown>) => void;
56
+ toolStateStore: ToolStateStore;
57
+ /** Approve and execute a HITL tool, then feed result back to AI */
58
+ confirmTool: (toolCallId: string, toolName: string, toolInput: Record<string, unknown>) => Promise<void>;
59
+ /** Reject a HITL tool and notify AI */
60
+ rejectTool: (toolCallId: string, toolName: string) => Promise<void>;
61
+ /** Retry a failed tool execution */
62
+ retryTool: (toolCallId: string, toolName: string, toolInput: unknown) => void;
63
+ /** Available threads (only when persistence is configured) */
64
+ threads?: Thread$1[];
65
+ /** Current thread ID */
66
+ threadId?: string;
67
+ /** Create a new thread (only when persistence is configured) */
68
+ createThread?: (title?: string) => Promise<Thread$1>;
69
+ /** Switch to a different thread (only when persistence is configured) */
70
+ switchThread?: (threadId: string) => Promise<void>;
71
+ /** Delete a thread (only when persistence is configured) */
72
+ deleteThread?: (threadId: string) => Promise<void>;
73
+ }
74
+ interface ChatProviderProps {
75
+ endpoint?: string;
76
+ tools: Record<string, Tool>;
77
+ toolStateStore?: ToolStateStore;
78
+ /** Persistence adapter for thread/message storage */
79
+ persistence?: PersistenceAdapter;
80
+ /** Active thread ID (used with persistence) */
81
+ threadId?: string;
82
+ children: React.ReactNode;
83
+ }
84
+ /**
85
+ * Hook to access chat context. Must be used within a ChatProvider.
86
+ */
87
+ declare function useChatContext(): ChatContextValue;
88
+ declare function ChatProvider({ endpoint, tools, toolStateStore: externalStore, persistence, threadId, children }: ChatProviderProps): react_jsx_runtime.JSX.Element;
89
+
90
+ interface ThreadProps {
91
+ className?: string;
92
+ emptyMessage?: string;
93
+ suggestions?: string[];
94
+ }
95
+ /**
96
+ * Message list with auto-scroll.
97
+ * Renders messages from ChatContext, maps over messages, renders text parts and tool parts.
98
+ */
99
+ declare function Thread({ className, emptyMessage, suggestions }: ThreadProps): react_jsx_runtime.JSX.Element;
100
+
101
+ interface MessageProps {
102
+ message: UIMessage;
103
+ tools: Record<string, Tool>;
104
+ toolStateStore: ToolStateStore;
105
+ getOnAction: (toolCallId: string, toolName: string) => (input: Record<string, unknown>) => void;
106
+ onConfirm?: (toolCallId: string, toolName: string, toolInput: Record<string, unknown>) => void;
107
+ onReject?: (toolCallId: string, toolName: string) => void;
108
+ onRetry?: (toolCallId: string, toolName: string, toolInput: unknown) => void;
109
+ className?: string;
110
+ }
111
+ /**
112
+ * Renders a single UIMessage.
113
+ * - User messages: right-aligned bubble (plain text)
114
+ * - Assistant messages: left-aligned bubble (rendered markdown)
115
+ * - Tool parts: renders tool.View automatically
116
+ */
117
+ declare function Message({ message, tools, toolStateStore, getOnAction, onConfirm, onReject, onRetry, className }: MessageProps): react_jsx_runtime.JSX.Element | null;
118
+
119
+ interface ComposerProps {
120
+ className?: string;
121
+ placeholder?: string;
122
+ }
123
+ /**
124
+ * Input form with text input and send button.
125
+ * Uses ChatContext to send messages. Disabled during loading.
126
+ */
127
+ declare function Composer({ className, placeholder }: ComposerProps): react_jsx_runtime.JSX.Element;
128
+
129
+ interface ToolResultProps {
130
+ toolName: string;
131
+ toolCallId: string;
132
+ output: unknown;
133
+ toolInput?: unknown;
134
+ hasResult: boolean;
135
+ /** Tool part state from the AI SDK (e.g. 'partial-call', 'call', 'output-available') */
136
+ toolPartState?: string;
137
+ toolStateStore: ToolStateStore;
138
+ tools: Record<string, Tool>;
139
+ getOnAction: (toolCallId: string, toolName: string) => (input: Record<string, unknown>) => void;
140
+ onConfirm?: (toolCallId: string, toolName: string, toolInput: Record<string, unknown>) => void;
141
+ onReject?: (toolCallId: string, toolName: string) => void;
142
+ onRetry?: (toolCallId: string, toolName: string, toolInput: unknown) => void;
143
+ className?: string;
144
+ }
145
+ /**
146
+ * Renders a tool's View component given tool name and output.
147
+ * Uses the tool state store for in-place updates (e.g. counter clicks),
148
+ * falling back to message part state.
149
+ *
150
+ * For HITL tools (confirm: true), renders a confirmation card when
151
+ * the tool is awaiting user approval.
152
+ *
153
+ * Supports groupKey-based in-place updates: when an older call (anchor) with
154
+ * the same entityId exists, followup calls update the anchor's data and render nothing.
155
+ */
156
+ declare function ToolResult({ toolName, toolCallId, output, toolInput, hasResult, toolPartState, toolStateStore, tools, getOnAction, onConfirm, onReject, onRetry, className, }: ToolResultProps): react_jsx_runtime.JSX.Element | null;
157
+
158
+ interface ChatProps {
159
+ endpoint?: string;
160
+ tools: Record<string, Tool>;
161
+ className?: string;
162
+ placeholder?: string;
163
+ emptyMessage?: string;
164
+ suggestions?: string[];
165
+ }
166
+ /**
167
+ * Convenience all-in-one chat component.
168
+ * Combines ChatProvider + Thread + Composer into a single drop-in component.
169
+ */
170
+ declare function Chat({ endpoint, tools, className, placeholder, emptyMessage, suggestions, }: ChatProps): react_jsx_runtime.JSX.Element;
171
+
172
+ interface ThemeProviderProps {
173
+ /** Theme name — sets data-theme attribute. Default: 'dark' */
174
+ theme?: string;
175
+ /** Override individual CSS variables */
176
+ variables?: Record<string, string>;
177
+ /** Additional CSS class */
178
+ className?: string;
179
+ children: React.ReactNode;
180
+ }
181
+ /**
182
+ * Wraps children with a themed container.
183
+ * Sets `data-theme` for CSS variable scoping and applies inline variable overrides.
184
+ */
185
+ declare function ThemeProvider({ theme, variables, className, children, }: ThemeProviderProps): react_jsx_runtime.JSX.Element;
186
+
187
+ export { type ChatProviderProps as C, type MessageProps as M, type ToolPartInfo as T, type ThreadProps as a, type ComposerProps as b, type ToolResultProps as c, type ChatProps as d, type ThemeProviderProps as e, type ToolStateStore as f, type ToolStateEntry as g, ChatProvider as h, Thread as i, Message as j, Composer as k, ToolResult as l, Chat as m, createToolStateStore as n, useToolState as o, ThemeProvider as p, useChatContext as u };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * JWT authentication helper.
3
+ * Uses `jose` (dynamically imported — zero cost if unused).
4
+ */
5
+ interface JwtAuthOptions {
6
+ /** JWT secret (string or Uint8Array) */
7
+ secret: string | Uint8Array;
8
+ /** Allowed algorithms (default: ['HS256']) */
9
+ algorithms?: string[];
10
+ /** Expected issuer */
11
+ issuer?: string;
12
+ /** Expected audience */
13
+ audience?: string;
14
+ }
15
+ /**
16
+ * Creates an auth callback that verifies JWT Bearer tokens.
17
+ * Compatible with the `auth` option in createNextJSToolHandler / createExpressToolHandler.
18
+ */
19
+ declare function jwtAuth(options: JwtAuthOptions): (headers: Headers) => Promise<Record<string, unknown>>;
20
+
21
+ /**
22
+ * BetterAuth integration helper.
23
+ * Works with any BetterAuth instance.
24
+ */
25
+ interface BetterAuthInstance {
26
+ api: {
27
+ getSession(options: {
28
+ headers: Headers;
29
+ }): Promise<{
30
+ session: Record<string, unknown> | null;
31
+ user: Record<string, unknown> | null;
32
+ } | null>;
33
+ };
34
+ }
35
+ /**
36
+ * Creates an auth callback from a BetterAuth instance.
37
+ * Compatible with the `auth` option in createNextJSToolHandler / createExpressToolHandler.
38
+ */
39
+ declare function betterAuth(authInstance: BetterAuthInstance): (headers: Headers) => Promise<Record<string, unknown>>;
40
+
41
+ /**
42
+ * Cookie-based session authentication helper.
43
+ */
44
+ interface SessionAuthOptions {
45
+ /** Cookie name to extract (default: 'session') */
46
+ cookieName?: string;
47
+ /** Verification function — receives the cookie value, returns user/session data */
48
+ verify: (sessionToken: string) => Promise<Record<string, unknown>>;
49
+ }
50
+ /**
51
+ * Creates an auth callback that extracts and verifies a session cookie.
52
+ * Compatible with the `auth` option in createNextJSToolHandler / createExpressToolHandler.
53
+ */
54
+ declare function sessionAuth(options: SessionAuthOptions): (headers: Headers) => Promise<Record<string, unknown>>;
55
+
56
+ export { type BetterAuthInstance, type JwtAuthOptions, type SessionAuthOptions, betterAuth, jwtAuth, sessionAuth };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * JWT authentication helper.
3
+ * Uses `jose` (dynamically imported — zero cost if unused).
4
+ */
5
+ interface JwtAuthOptions {
6
+ /** JWT secret (string or Uint8Array) */
7
+ secret: string | Uint8Array;
8
+ /** Allowed algorithms (default: ['HS256']) */
9
+ algorithms?: string[];
10
+ /** Expected issuer */
11
+ issuer?: string;
12
+ /** Expected audience */
13
+ audience?: string;
14
+ }
15
+ /**
16
+ * Creates an auth callback that verifies JWT Bearer tokens.
17
+ * Compatible with the `auth` option in createNextJSToolHandler / createExpressToolHandler.
18
+ */
19
+ declare function jwtAuth(options: JwtAuthOptions): (headers: Headers) => Promise<Record<string, unknown>>;
20
+
21
+ /**
22
+ * BetterAuth integration helper.
23
+ * Works with any BetterAuth instance.
24
+ */
25
+ interface BetterAuthInstance {
26
+ api: {
27
+ getSession(options: {
28
+ headers: Headers;
29
+ }): Promise<{
30
+ session: Record<string, unknown> | null;
31
+ user: Record<string, unknown> | null;
32
+ } | null>;
33
+ };
34
+ }
35
+ /**
36
+ * Creates an auth callback from a BetterAuth instance.
37
+ * Compatible with the `auth` option in createNextJSToolHandler / createExpressToolHandler.
38
+ */
39
+ declare function betterAuth(authInstance: BetterAuthInstance): (headers: Headers) => Promise<Record<string, unknown>>;
40
+
41
+ /**
42
+ * Cookie-based session authentication helper.
43
+ */
44
+ interface SessionAuthOptions {
45
+ /** Cookie name to extract (default: 'session') */
46
+ cookieName?: string;
47
+ /** Verification function — receives the cookie value, returns user/session data */
48
+ verify: (sessionToken: string) => Promise<Record<string, unknown>>;
49
+ }
50
+ /**
51
+ * Creates an auth callback that extracts and verifies a session cookie.
52
+ * Compatible with the `auth` option in createNextJSToolHandler / createExpressToolHandler.
53
+ */
54
+ declare function sessionAuth(options: SessionAuthOptions): (headers: Headers) => Promise<Record<string, unknown>>;
55
+
56
+ export { type BetterAuthInstance, type JwtAuthOptions, type SessionAuthOptions, betterAuth, jwtAuth, sessionAuth };
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/auth/index.ts
31
+ var auth_exports = {};
32
+ __export(auth_exports, {
33
+ betterAuth: () => betterAuth,
34
+ jwtAuth: () => jwtAuth,
35
+ sessionAuth: () => sessionAuth
36
+ });
37
+ module.exports = __toCommonJS(auth_exports);
38
+
39
+ // src/auth/jwt.ts
40
+ function jwtAuth(options) {
41
+ return async (headers) => {
42
+ const authHeader = headers.get("authorization");
43
+ if (!authHeader?.startsWith("Bearer ")) {
44
+ throw new Error("Missing or invalid Authorization header");
45
+ }
46
+ const token = authHeader.slice(7);
47
+ const { jwtVerify } = await import("jose");
48
+ const secret = typeof options.secret === "string" ? new TextEncoder().encode(options.secret) : options.secret;
49
+ const { payload } = await jwtVerify(token, secret, {
50
+ algorithms: options.algorithms,
51
+ issuer: options.issuer,
52
+ audience: options.audience
53
+ });
54
+ return payload;
55
+ };
56
+ }
57
+
58
+ // src/auth/better-auth.ts
59
+ function betterAuth(authInstance) {
60
+ return async (headers) => {
61
+ const result = await authInstance.api.getSession({ headers });
62
+ if (!result?.session) {
63
+ throw new Error("No active session");
64
+ }
65
+ return {
66
+ session: result.session,
67
+ user: result.user
68
+ };
69
+ };
70
+ }
71
+
72
+ // src/auth/session.ts
73
+ function sessionAuth(options) {
74
+ const cookieName = options.cookieName ?? "session";
75
+ return async (headers) => {
76
+ const cookieHeader = headers.get("cookie");
77
+ if (!cookieHeader) {
78
+ throw new Error("No cookies present");
79
+ }
80
+ const cookies = parseCookies(cookieHeader);
81
+ const token = cookies[cookieName];
82
+ if (!token) {
83
+ throw new Error(`Session cookie "${cookieName}" not found`);
84
+ }
85
+ return options.verify(token);
86
+ };
87
+ }
88
+ function parseCookies(cookieHeader) {
89
+ const cookies = {};
90
+ for (const pair of cookieHeader.split(";")) {
91
+ const [key, ...rest] = pair.split("=");
92
+ const name = key?.trim();
93
+ if (name) {
94
+ cookies[name] = rest.join("=").trim();
95
+ }
96
+ }
97
+ return cookies;
98
+ }
99
+ // Annotate the CommonJS export names for ESM import in node:
100
+ 0 && (module.exports = {
101
+ betterAuth,
102
+ jwtAuth,
103
+ sessionAuth
104
+ });
@@ -0,0 +1,67 @@
1
+ import "../chunk-Y6FXYEAI.mjs";
2
+
3
+ // src/auth/jwt.ts
4
+ function jwtAuth(options) {
5
+ return async (headers) => {
6
+ const authHeader = headers.get("authorization");
7
+ if (!authHeader?.startsWith("Bearer ")) {
8
+ throw new Error("Missing or invalid Authorization header");
9
+ }
10
+ const token = authHeader.slice(7);
11
+ const { jwtVerify } = await import("jose");
12
+ const secret = typeof options.secret === "string" ? new TextEncoder().encode(options.secret) : options.secret;
13
+ const { payload } = await jwtVerify(token, secret, {
14
+ algorithms: options.algorithms,
15
+ issuer: options.issuer,
16
+ audience: options.audience
17
+ });
18
+ return payload;
19
+ };
20
+ }
21
+
22
+ // src/auth/better-auth.ts
23
+ function betterAuth(authInstance) {
24
+ return async (headers) => {
25
+ const result = await authInstance.api.getSession({ headers });
26
+ if (!result?.session) {
27
+ throw new Error("No active session");
28
+ }
29
+ return {
30
+ session: result.session,
31
+ user: result.user
32
+ };
33
+ };
34
+ }
35
+
36
+ // src/auth/session.ts
37
+ function sessionAuth(options) {
38
+ const cookieName = options.cookieName ?? "session";
39
+ return async (headers) => {
40
+ const cookieHeader = headers.get("cookie");
41
+ if (!cookieHeader) {
42
+ throw new Error("No cookies present");
43
+ }
44
+ const cookies = parseCookies(cookieHeader);
45
+ const token = cookies[cookieName];
46
+ if (!token) {
47
+ throw new Error(`Session cookie "${cookieName}" not found`);
48
+ }
49
+ return options.verify(token);
50
+ };
51
+ }
52
+ function parseCookies(cookieHeader) {
53
+ const cookies = {};
54
+ for (const pair of cookieHeader.split(";")) {
55
+ const [key, ...rest] = pair.split("=");
56
+ const name = key?.trim();
57
+ if (name) {
58
+ cookies[name] = rest.join("=").trim();
59
+ }
60
+ }
61
+ return cookies;
62
+ }
63
+ export {
64
+ betterAuth,
65
+ jwtAuth,
66
+ sessionAuth
67
+ };
@@ -0,0 +1,10 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ export {
9
+ __require
10
+ };