qarpeo 0.1.13 → 0.1.15

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 (33) hide show
  1. package/README.md +7 -13
  2. package/dist/chunks/auth-schema.mjs +119 -147
  3. package/dist/cli/index.mjs +1 -1
  4. package/dist/module.mjs +96 -21
  5. package/dist/runtime/ai.d.ts +4 -2
  6. package/dist/runtime/ai.mjs +8 -2
  7. package/dist/runtime/app/composables/ai.d.ts +74 -0
  8. package/dist/runtime/app/composables/ai.mjs +148 -0
  9. package/dist/runtime/app/composables/auth.d.ts +16 -1
  10. package/dist/runtime/app/composables/auth.mjs +23 -34
  11. package/dist/runtime/app/composables/void-client.d.ts +3 -0
  12. package/dist/runtime/app/composables/void-client.mjs +4 -0
  13. package/dist/runtime/blob.mjs +1 -1
  14. package/dist/runtime/db.mjs +1 -1
  15. package/dist/runtime/server/routes/agents/[agent]/history.get.d.ts +1 -1
  16. package/dist/runtime/server/routes/auth/handler.d.ts +2 -0
  17. package/dist/runtime/server/routes/auth/handler.mjs +11 -0
  18. package/dist/runtime/server/utils/auth.d.ts +66 -0
  19. package/dist/runtime/server/utils/auth.mjs +58 -0
  20. package/dist/runtime/server/utils/realtime.mjs +1 -1
  21. package/dist/runtime/server/utils/void-ai.d.ts +7 -0
  22. package/dist/runtime/server/utils/void-ai.mjs +47 -0
  23. package/dist/runtime/server/utils/void-auth.d.ts +2 -0
  24. package/dist/runtime/server/utils/void-auth.mjs +9 -0
  25. package/dist/runtime/server/utils/void-db.d.ts +8 -0
  26. package/dist/runtime/server/utils/void-db.mjs +38 -0
  27. package/dist/runtime/server/utils/void-seed.d.ts +11 -0
  28. package/dist/runtime/server/utils/void-seed.mjs +3 -0
  29. package/dist/runtime/types/ai.d.ts +2 -0
  30. package/dist/runtime/types/imports.d.ts +65 -6
  31. package/dist/types.d.ts +1 -1
  32. package/dist/utils/auth-schema.d.ts +3 -5
  33. package/package.json +3 -2
@@ -8,7 +8,8 @@ import {
8
8
  speechToText,
9
9
  generateText,
10
10
  streamText,
11
- embedText
11
+ embedText,
12
+ similaritySearch
12
13
  } from "./server/utils/ai.mjs";
13
14
  export {
14
15
  generateImage,
@@ -19,7 +20,8 @@ export {
19
20
  speechToText,
20
21
  generateText,
21
22
  streamText,
22
- embedText
23
+ embedText,
24
+ similaritySearch
23
25
  };
24
26
  export function getAIBinding(bindingName, event) {
25
27
  const resolvedBinding = resolveRuntimeBinding("ai", bindingName, "AI");
@@ -86,6 +88,9 @@ export function createAI(bindingName, event) {
86
88
  },
87
89
  embed: (text, options) => {
88
90
  return embedText(text, { binding: resolvedBinding, event, ...options });
91
+ },
92
+ similaritySearch: (indexName, query, options) => {
93
+ return similaritySearch(indexName, query, { binding: resolvedBinding, event, ...options });
89
94
  }
90
95
  };
91
96
  }
@@ -104,3 +109,4 @@ export const ai = new Proxy({}, {
104
109
  }
105
110
  });
106
111
  export { useChat, useAgentChat } from "./app/composables/chat.mjs";
112
+ export { useAIStream, useVectorSearch } from "./app/composables/ai.mjs";
@@ -0,0 +1,74 @@
1
+ import { useChat, useAgentChat, type UseChatOptions, type UseAgentChatOptions } from "./chat";
2
+ export interface UseAIStreamOptions {
3
+ /** Target API endpoint. Defaults to "/api/ai/stream" */
4
+ api?: string;
5
+ /** Model identifier override */
6
+ model?: string;
7
+ /** System prompt override */
8
+ system?: string;
9
+ /** Model temperature override */
10
+ temperature?: number;
11
+ /** Callback fired for each streamed delta chunk */
12
+ onDelta?: (delta: string) => void;
13
+ /** Callback fired when streaming finishes */
14
+ onFinish?: (fullText: string) => void;
15
+ /** Callback fired on error */
16
+ onError?: (err: Error) => void;
17
+ }
18
+ /**
19
+ * Reactive composable for streaming text completions from Cloudflare Workers AI via SSE.
20
+ *
21
+ * @example
22
+ * ```vue
23
+ * <script setup>
24
+ * const { text, isStreaming, send, abort } = useAIStream()
25
+ * </script>
26
+ * <template>
27
+ * <button @click="send('Explain quantum physics')">Generate</button>
28
+ * <div v-if="isStreaming">Streaming...</div>
29
+ * <p>{{ text }}</p>
30
+ * </template>
31
+ * ```
32
+ */
33
+ export declare function useAIStream(options?: UseAIStreamOptions): {
34
+ text: import("vue").Ref<string, string>;
35
+ isStreaming: import("vue").Ref<boolean, boolean>;
36
+ error: import("vue").Ref<Error | null, Error | null>;
37
+ send: (prompt: string, overrideOptions?: Partial<UseAIStreamOptions>) => Promise<string>;
38
+ abort: () => void;
39
+ reset: () => void;
40
+ };
41
+ export interface UseVectorSearchOptions {
42
+ /** Target API endpoint. Defaults to "/api/ai/search" */
43
+ api?: string;
44
+ /** Vector index name */
45
+ index?: string;
46
+ /** Number of results to return. Defaults to 5 */
47
+ topK?: number;
48
+ }
49
+ /**
50
+ * Reactive composable for vector similarity search via Cloudflare Vectorize.
51
+ *
52
+ * @example
53
+ * ```vue
54
+ * <script setup>
55
+ * const { results, isSearching, search } = useVectorSearch({ index: "articles" })
56
+ * </script>
57
+ * <template>
58
+ * <input @keydown.enter="search($event.target.value)" placeholder="Search semantic articles..." />
59
+ * <div v-if="isSearching">Searching...</div>
60
+ * <ul>
61
+ * <li v-for="res in results" :key="res.id">{{ res.metadata?.title || res.id }}</li>
62
+ * </ul>
63
+ * </template>
64
+ * ```
65
+ */
66
+ export declare function useVectorSearch<T = any>(options?: UseVectorSearchOptions): {
67
+ results: import("vue").Ref<any[], any[]>;
68
+ isSearching: import("vue").Ref<boolean, boolean>;
69
+ error: import("vue").Ref<Error | null, Error | null>;
70
+ search: (query: string, overrideOptions?: Partial<UseVectorSearchOptions>) => Promise<T[]>;
71
+ clear: () => void;
72
+ };
73
+ export { useChat, useAgentChat };
74
+ export type { UseChatOptions, UseAgentChatOptions };
@@ -0,0 +1,148 @@
1
+ import { ref } from "vue";
2
+ import { useChat, useAgentChat } from "./chat.mjs";
3
+ export function useAIStream(options = {}) {
4
+ const text = ref("");
5
+ const isStreaming = ref(false);
6
+ const error = ref(null);
7
+ let abortController = null;
8
+ const send = async (prompt, overrideOptions) => {
9
+ if (!prompt.trim() || isStreaming.value) return "";
10
+ text.value = "";
11
+ error.value = null;
12
+ isStreaming.value = true;
13
+ abortController = new AbortController();
14
+ const apiEndpoint = overrideOptions?.api || options.api || "/api/ai/stream";
15
+ const model = overrideOptions?.model || options.model;
16
+ const system = overrideOptions?.system || options.system;
17
+ const temperature = overrideOptions?.temperature ?? options.temperature;
18
+ try {
19
+ const res = await fetch(apiEndpoint, {
20
+ method: "POST",
21
+ headers: { "Content-Type": "application/json" },
22
+ body: JSON.stringify({ prompt, model, system, temperature }),
23
+ signal: abortController.signal
24
+ });
25
+ if (!res.ok) {
26
+ throw new Error(`HTTP ${res.status}: ${res.statusText}`);
27
+ }
28
+ if (!res.body) {
29
+ throw new Error("No response body received");
30
+ }
31
+ const reader = res.body.getReader();
32
+ const decoder = new TextDecoder();
33
+ let buffer = "";
34
+ while (true) {
35
+ const { done, value } = await reader.read();
36
+ if (done) break;
37
+ buffer += decoder.decode(value, { stream: true });
38
+ const events = buffer.split("\n\n");
39
+ buffer = events.pop() || "";
40
+ for (const rawEvent of events) {
41
+ if (!rawEvent.trim()) continue;
42
+ const lines = rawEvent.split("\n");
43
+ let eventType = "message";
44
+ let dataStr = "";
45
+ for (const line of lines) {
46
+ if (line.startsWith("event: ")) {
47
+ eventType = line.slice(7).trim();
48
+ } else if (line.startsWith("data: ")) {
49
+ dataStr = line.slice(6).trim();
50
+ }
51
+ }
52
+ if (eventType === "text-delta" && dataStr) {
53
+ try {
54
+ const data = JSON.parse(dataStr);
55
+ if (data.delta) {
56
+ text.value += data.delta;
57
+ options.onDelta?.(data.delta);
58
+ }
59
+ } catch {
60
+ }
61
+ } else if (eventType === "error" && dataStr) {
62
+ try {
63
+ const data = JSON.parse(dataStr);
64
+ throw new Error(data.message || "Streaming failed");
65
+ } catch (err) {
66
+ throw err;
67
+ }
68
+ }
69
+ }
70
+ }
71
+ options.onFinish?.(text.value);
72
+ return text.value;
73
+ } catch (err) {
74
+ if (err.name !== "AbortError") {
75
+ error.value = err;
76
+ options.onError?.(err);
77
+ }
78
+ return "";
79
+ } finally {
80
+ isStreaming.value = false;
81
+ abortController = null;
82
+ }
83
+ };
84
+ const abort = () => {
85
+ if (abortController) {
86
+ abortController.abort();
87
+ abortController = null;
88
+ isStreaming.value = false;
89
+ }
90
+ };
91
+ const reset = () => {
92
+ abort();
93
+ text.value = "";
94
+ error.value = null;
95
+ };
96
+ return {
97
+ text,
98
+ isStreaming,
99
+ error,
100
+ send,
101
+ abort,
102
+ reset
103
+ };
104
+ }
105
+ export function useVectorSearch(options = {}) {
106
+ const results = ref([]);
107
+ const isSearching = ref(false);
108
+ const error = ref(null);
109
+ const search = async (query, overrideOptions) => {
110
+ if (!query.trim()) return [];
111
+ isSearching.value = true;
112
+ error.value = null;
113
+ const apiEndpoint = overrideOptions?.api || options.api || "/api/ai/search";
114
+ const index = overrideOptions?.index || options.index || "default";
115
+ const topK = overrideOptions?.topK ?? options.topK ?? 5;
116
+ try {
117
+ const res = await fetch(apiEndpoint, {
118
+ method: "POST",
119
+ headers: { "Content-Type": "application/json" },
120
+ body: JSON.stringify({ query, index, topK })
121
+ });
122
+ if (!res.ok) {
123
+ throw new Error(`HTTP ${res.status}: ${res.statusText}`);
124
+ }
125
+ const data = await res.json();
126
+ const list = data.results || data.matches || data;
127
+ results.value = list;
128
+ return list;
129
+ } catch (err) {
130
+ error.value = err;
131
+ return [];
132
+ } finally {
133
+ isSearching.value = false;
134
+ }
135
+ };
136
+ const clear = () => {
137
+ results.value = [];
138
+ error.value = null;
139
+ };
140
+ return {
141
+ results,
142
+ isSearching,
143
+ error,
144
+ search,
145
+ clear
146
+ };
147
+ }
148
+ export { useChat, useAgentChat };
@@ -1,9 +1,20 @@
1
1
  import type { QarpeoUser, QarpeoSession, DeleteAccountOptions } from "../../types/auth";
2
+ /**
3
+ * Official Better Auth Vue Client Instance
4
+ */
5
+ export declare const authClient: any;
6
+ /**
7
+ * Standard Better Auth session composable compatible with Nuxt 5 SSR hydration.
8
+ */
9
+ export declare function useSession(): any;
2
10
  export declare function useUserSession(): {
3
11
  ready: import("vue").ComputedRef<boolean>;
4
12
  loggedIn: import("vue").ComputedRef<boolean>;
5
13
  user: import("vue").ComputedRef<any>;
6
- session: import("vue").Ref<any, any>;
14
+ session: import("vue").ComputedRef<any>;
15
+ data: import("vue").ComputedRef<any>;
16
+ isPending: import("vue").ComputedRef<boolean>;
17
+ error: import("vue").ComputedRef<any>;
7
18
  fetch: () => Promise<void>;
8
19
  clear: () => Promise<void>;
9
20
  };
@@ -25,6 +36,10 @@ export declare function useAuth(): {
25
36
  clear: () => Promise<void>;
26
37
  logout: (redirect?: string) => Promise<void>;
27
38
  logoutAll: (redirect?: string) => Promise<void>;
39
+ client: any;
40
+ signIn: any;
41
+ signUp: any;
42
+ signOut: any;
28
43
  mfaRequired: import("vue").ComputedRef<boolean>;
29
44
  mfaVerified: import("vue").ComputedRef<boolean>;
30
45
  deleteAccount: (options?: DeleteAccountOptions, redirect?: string) => Promise<void>;
@@ -1,42 +1,26 @@
1
1
  import { ref, computed } from "vue";
2
- import { useRuntimeConfig, navigateTo, useState, useRequestFetch, useRequestEvent } from "nuxt/app";
2
+ import { useRuntimeConfig, navigateTo } from "nuxt/app";
3
+ import { createAuthClient } from "better-auth/vue";
4
+ export const authClient = createAuthClient();
5
+ export function useSession() {
6
+ return authClient.useSession();
7
+ }
3
8
  export function useUserSession() {
4
- const serverEvent = import.meta.server ? useRequestEvent() : null;
5
- const sessionState = useState("nuxt-session", () => null);
6
- const authReadyState = useState("nuxt-auth-ready", () => false);
7
- const requestFetch = useRequestFetch();
9
+ const sessionResource = useSession();
8
10
  const clear = async () => {
9
- await requestFetch("/api/_auth/session", {
10
- method: "DELETE",
11
- onResponse({ response }) {
12
- if (import.meta.server && serverEvent) {
13
- const res = serverEvent.res;
14
- const getCookies = response.headers?.getSetCookie;
15
- if (typeof getCookies === "function") {
16
- for (const setCookie of getCookies.call(response.headers)) {
17
- if (res?.headers) res.headers.append("set-cookie", setCookie);
18
- else res?.appendHeader?.("set-cookie", setCookie);
19
- }
20
- }
21
- }
22
- }
23
- });
24
- sessionState.value = null;
11
+ await authClient.signOut();
25
12
  };
26
13
  const fetch = async () => {
27
- sessionState.value = await requestFetch("/api/_auth/session", {
28
- headers: { accept: "application/json" },
29
- retry: false
30
- }).catch(() => null);
31
- if (!authReadyState.value) {
32
- authReadyState.value = true;
33
- }
14
+ await sessionResource.value?.refetch?.();
34
15
  };
35
16
  return {
36
- ready: computed(() => authReadyState.value),
37
- loggedIn: computed(() => Boolean(sessionState.value?.user)),
38
- user: computed(() => sessionState.value?.user || null),
39
- session: sessionState,
17
+ ready: computed(() => !sessionResource.value?.isPending),
18
+ loggedIn: computed(() => Boolean(sessionResource.value?.data?.user)),
19
+ user: computed(() => sessionResource.value?.data?.user || null),
20
+ session: computed(() => sessionResource.value?.data?.session || null),
21
+ data: computed(() => sessionResource.value?.data || null),
22
+ isPending: computed(() => Boolean(sessionResource.value?.isPending)),
23
+ error: computed(() => sessionResource.value?.error || null),
40
24
  fetch,
41
25
  clear
42
26
  };
@@ -81,7 +65,7 @@ export function useAuth() {
81
65
  sessions.value = sessions.value.filter((s) => s.isCurrent);
82
66
  };
83
67
  const logout = async (redirect) => {
84
- await clear();
68
+ await authClient.signOut();
85
69
  const target = redirect || authConfig.redirect?.logout || "/login";
86
70
  if (target) {
87
71
  await navigateTo(target);
@@ -128,12 +112,17 @@ export function useAuth() {
128
112
  clear,
129
113
  logout,
130
114
  logoutAll,
115
+ // Better Auth methods & client
116
+ client: authClient,
117
+ signIn: authClient.signIn,
118
+ signUp: authClient.signUp,
119
+ signOut: authClient.signOut,
131
120
  // Enterprise Auth additions
132
121
  mfaRequired,
133
122
  mfaVerified,
134
123
  deleteAccount,
135
124
  loginWithSSO,
136
- // Phase 3: Multi-device session management
125
+ // Multi-device session management
137
126
  sessions,
138
127
  sessionsLoading,
139
128
  fetchSessions,
@@ -0,0 +1,3 @@
1
+ export declare const auth: import("better-auth/vue").VueAuthClient<import("better-auth").BetterAuthClientOptions>;
2
+ export declare const authClient: import("better-auth/vue").VueAuthClient<import("better-auth").BetterAuthClientOptions>;
3
+ export default auth;
@@ -0,0 +1,4 @@
1
+ import { createAuthClient } from "better-auth/vue";
2
+ export const auth = createAuthClient();
3
+ export const authClient = auth;
4
+ export default auth;
@@ -35,7 +35,7 @@ function assertValidPathname(pathname) {
35
35
  export function getR2Binding(bindingName, event) {
36
36
  const resolvedBinding = resolveRuntimeBinding("blob", bindingName, "BLOB");
37
37
  const env = getCloudflareEnv(event);
38
- const binding = env[resolvedBinding];
38
+ const binding = env[resolvedBinding] || env["STORAGE"] || env["BLOB"];
39
39
  if (!binding) {
40
40
  throw new Error(
41
41
  `[qarpeo] Cloudflare R2 binding "${resolvedBinding}" was not found. Check your wrangler.json or QARPEO_BLOB_BINDING environment variable.`
@@ -2,7 +2,7 @@ import { getCloudflareEnv, resolveRuntimeBinding } from "./bindings.mjs";
2
2
  export function getD1Binding(bindingName, event) {
3
3
  const resolvedBinding = resolveRuntimeBinding("db", bindingName, "DB");
4
4
  const env = getCloudflareEnv(event);
5
- const binding = env[resolvedBinding];
5
+ const binding = env[resolvedBinding] || env["DB"] || env["DATABASE"];
6
6
  if (!binding) {
7
7
  throw new Error(
8
8
  `[qarpeo] Cloudflare D1 binding "${resolvedBinding}" was not found. Check your wrangler.json or QARPEO_DB_BINDING environment variable.`
@@ -1,4 +1,4 @@
1
1
  declare const _default: import("nuxt/server").EventHandler<Promise<{
2
- messages: import("../../../../../types").AgentMessage[];
2
+ messages: import("../../../utils/void-ai").AgentMessage[];
3
3
  }>>;
4
4
  export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<Response>>;
2
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import { defineEventHandler, readRawBody } from "h3";
2
+ import { serverAuth } from "../../utils/auth.mjs";
3
+ export default defineEventHandler(async (event) => {
4
+ const auth = serverAuth(event);
5
+ const req = event.req instanceof Request ? event.req : new Request(`http://${event.headers?.get?.("host") || "localhost"}${event.path || "/api/auth"}`, {
6
+ method: event.method,
7
+ headers: event.headers,
8
+ body: ["POST", "PUT", "PATCH"].includes(event.method) ? await readRawBody(event) : void 0
9
+ });
10
+ return auth.handler(req);
11
+ });
@@ -1,3 +1,69 @@
1
+ /**
2
+ * Creates or retrieves a Better Auth instance connected to Cloudflare D1 via Drizzle.
3
+ */
4
+ export declare function serverAuth(event?: any): import("better-auth").Auth<{
5
+ database: (options: import("better-auth").BetterAuthOptions) => import("better-auth").DBAdapter<import("better-auth").BetterAuthOptions>;
6
+ secret: string;
7
+ baseURL: string | undefined;
8
+ emailAndPassword: {
9
+ enabled: true;
10
+ };
11
+ advanced: {
12
+ database: {
13
+ joins: true;
14
+ };
15
+ };
16
+ }>;
17
+ export declare const createAuth: typeof serverAuth;
18
+ export declare const useServerAuth: typeof serverAuth;
19
+ /**
20
+ * Fetches the current session from Better Auth on the server.
21
+ */
22
+ export declare function getServerSession(event: any): Promise<{
23
+ session: {
24
+ id: string;
25
+ createdAt: Date;
26
+ updatedAt: Date;
27
+ userId: string;
28
+ expiresAt: Date;
29
+ token: string;
30
+ ipAddress?: string | null | undefined | undefined;
31
+ userAgent?: string | null | undefined | undefined;
32
+ };
33
+ user: {
34
+ id: string;
35
+ createdAt: Date;
36
+ updatedAt: Date;
37
+ email: string;
38
+ emailVerified: boolean;
39
+ name: string;
40
+ image?: string | null | undefined | undefined;
41
+ };
42
+ } | null>;
43
+ /**
44
+ * Throws 401 if user is unauthenticated.
45
+ */
46
+ export declare function requireServerSession(event: any): Promise<{
47
+ session: {
48
+ id: string;
49
+ createdAt: Date;
50
+ updatedAt: Date;
51
+ userId: string;
52
+ expiresAt: Date;
53
+ token: string;
54
+ ipAddress?: string | null | undefined | undefined;
55
+ userAgent?: string | null | undefined | undefined;
56
+ };
57
+ user: {
58
+ id: string;
59
+ createdAt: Date;
60
+ updatedAt: Date;
61
+ email: string;
62
+ emailVerified: boolean;
63
+ name: string;
64
+ image?: string | null | undefined | undefined;
65
+ };
66
+ }>;
1
67
  import type { RequestEvent } from "nuxt/server";
2
68
  import type { QarpeoSession } from "../../types/auth";
3
69
  /** Ensures core auth tables (_qarpeo_users, _qarpeo_accounts, _qarpeo_sessions) exist in D1. */
@@ -1,3 +1,61 @@
1
+ import { betterAuth } from "better-auth";
2
+ import { drizzleAdapter } from "@better-auth/drizzle-adapter";
3
+ import { createError } from "h3";
4
+ import { useDrizzle } from "./drizzle.mjs";
5
+ import * as authSchema from "#qarpeo/auth/schema";
6
+ export function serverAuth(event) {
7
+ const db = useDrizzle(void 0, event);
8
+ const secret = process.env.BETTER_AUTH_SECRET || process.env.NUXT_BETTER_AUTH_SECRET || process.env.NUXT_APP_SECRET || "qarpeo-auth-secret-change-in-production-min-32-chars";
9
+ const baseURL = process.env.BETTER_AUTH_URL || process.env.NUXT_BETTER_AUTH_URL || void 0;
10
+ return betterAuth({
11
+ database: drizzleAdapter(db, {
12
+ provider: "sqlite",
13
+ schema: {
14
+ user: authSchema.user || authSchema.users,
15
+ session: authSchema.session || authSchema.sessions,
16
+ account: authSchema.account || authSchema.accounts,
17
+ verification: authSchema.verification || authSchema.verifications,
18
+ twoFactor: authSchema.twoFactor,
19
+ passkey: authSchema.passkey || authSchema.authenticators,
20
+ organization: authSchema.organization || authSchema.organizations,
21
+ member: authSchema.member || authSchema.members,
22
+ invitation: authSchema.invitation || authSchema.invitations
23
+ }
24
+ }),
25
+ secret,
26
+ baseURL,
27
+ emailAndPassword: {
28
+ enabled: true
29
+ },
30
+ advanced: {
31
+ database: {
32
+ joins: true
33
+ }
34
+ }
35
+ });
36
+ }
37
+ export const createAuth = serverAuth;
38
+ export const useServerAuth = serverAuth;
39
+ export async function getServerSession(event) {
40
+ const auth = serverAuth(event);
41
+ const req = event.req instanceof Request ? event.req : new Request(`http://${event.headers?.get?.("host") || "localhost"}${event.path || "/"}`, {
42
+ headers: event.headers,
43
+ method: event.method
44
+ });
45
+ return auth.api.getSession({
46
+ headers: req.headers
47
+ });
48
+ }
49
+ export async function requireServerSession(event) {
50
+ const session = await getServerSession(event);
51
+ if (!session?.user) {
52
+ throw createError({
53
+ statusCode: 401,
54
+ statusMessage: "Unauthorized"
55
+ });
56
+ }
57
+ return session;
58
+ }
1
59
  import { useNitroApp } from "nitro/app";
2
60
  import { getD1Binding } from "../../db.mjs";
3
61
  import { getQarpeoConfig } from "./config.mjs";
@@ -27,7 +27,7 @@ function resolveRoomAndEvent(arg1, arg2) {
27
27
  export function getRoomDurableObject(eventOrRoom, maybeRoom, bindingName = "QARPEO_ROOM_DO") {
28
28
  const { event, roomId } = resolveRoomAndEvent(eventOrRoom, maybeRoom);
29
29
  const env = getCloudflareEnv(event);
30
- const binding = env[bindingName];
30
+ const binding = env[bindingName] || env["VOID_LIVE"] || env["REALTIME"] || env["ROOM"];
31
31
  if (!binding || typeof binding.idFromName !== "function") {
32
32
  throw new Error(
33
33
  `[qarpeo.realtime] Durable Object binding "${bindingName}" is not available in the current environment. Ensure "qarpeo.realtime: true" or "qarpeo.do: true" is configured.`
@@ -0,0 +1,7 @@
1
+ import { ai, useAI, createAI, getAIBinding, generateImage, textToImage, generateSpeech, textToSpeech, transcribeAudio, speechToText, generateText, streamText, embedText } from "../../ai";
2
+ import { defineAgent, defineTool, useAgent, similaritySearch, getAgentDefinition, getAllAgentDefinitions, registerAgentDefinition } from "./ai";
3
+ import type { QarpeoAI, AiBinding, AiOptions } from "../../types/ai";
4
+ import type { AgentDefinition, AgentTool, AgentMessage, AgentContext } from "../../../types";
5
+ export { ai, useAI, createAI, getAIBinding, generateImage, textToImage, generateSpeech, textToSpeech, transcribeAudio, speechToText, generateText, streamText, embedText, defineAgent, defineTool, useAgent, similaritySearch, getAgentDefinition, getAllAgentDefinitions, registerAgentDefinition, };
6
+ export type { QarpeoAI, AiBinding, AiOptions, AgentDefinition, AgentTool, AgentMessage, AgentContext, };
7
+ export default ai;
@@ -0,0 +1,47 @@
1
+ import {
2
+ ai,
3
+ useAI,
4
+ createAI,
5
+ getAIBinding,
6
+ generateImage,
7
+ textToImage,
8
+ generateSpeech,
9
+ textToSpeech,
10
+ transcribeAudio,
11
+ speechToText,
12
+ generateText,
13
+ streamText,
14
+ embedText
15
+ } from "../../ai.mjs";
16
+ import {
17
+ defineAgent,
18
+ defineTool,
19
+ useAgent,
20
+ similaritySearch,
21
+ getAgentDefinition,
22
+ getAllAgentDefinitions,
23
+ registerAgentDefinition
24
+ } from "./ai.mjs";
25
+ export {
26
+ ai,
27
+ useAI,
28
+ createAI,
29
+ getAIBinding,
30
+ generateImage,
31
+ textToImage,
32
+ generateSpeech,
33
+ textToSpeech,
34
+ transcribeAudio,
35
+ speechToText,
36
+ generateText,
37
+ streamText,
38
+ embedText,
39
+ defineAgent,
40
+ defineTool,
41
+ useAgent,
42
+ similaritySearch,
43
+ getAgentDefinition,
44
+ getAllAgentDefinitions,
45
+ registerAgentDefinition
46
+ };
47
+ export default ai;
@@ -0,0 +1,2 @@
1
+ export declare const auth: any;
2
+ export default auth;
@@ -0,0 +1,9 @@
1
+ import { serverAuth } from "./auth.mjs";
2
+ export const auth = new Proxy({}, {
3
+ get(_target, prop) {
4
+ const instance = serverAuth();
5
+ const val = instance[prop];
6
+ return typeof val === "function" ? val.bind(instance) : val;
7
+ }
8
+ });
9
+ export default auth;
@@ -0,0 +1,8 @@
1
+ import { db, useDrizzle } from "./drizzle";
2
+ export { db, useDrizzle };
3
+ /**
4
+ * Creates or accesses a secondary or dynamically bound D1 database client.
5
+ * Compatible with `createDb(env.MY_OTHER_DB)` or `createDb("BINDING_NAME")`.
6
+ */
7
+ export declare function createDb(bindingOrName?: any): any;
8
+ export { eq, ne, gt, gte, lt, lte, and, or, not, desc, asc, like, ilike, notLike, inArray, notInArray, isNull, isNotNull, exists, notExists, between, notBetween, sql, } from "drizzle-orm";