qarpeo 0.1.13 → 0.1.14

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 (34) hide show
  1. package/README.md +7 -13
  2. package/dist/chunks/auth-schema.mjs +119 -147
  3. package/dist/chunks/wrangler.mjs +1 -1
  4. package/dist/cli/index.mjs +2 -2
  5. package/dist/module.mjs +142 -22
  6. package/dist/runtime/ai.d.ts +4 -2
  7. package/dist/runtime/ai.mjs +8 -2
  8. package/dist/runtime/app/composables/ai.d.ts +74 -0
  9. package/dist/runtime/app/composables/ai.mjs +148 -0
  10. package/dist/runtime/app/composables/auth.d.ts +16 -1
  11. package/dist/runtime/app/composables/auth.mjs +23 -34
  12. package/dist/runtime/app/composables/void-client.d.ts +3 -0
  13. package/dist/runtime/app/composables/void-client.mjs +4 -0
  14. package/dist/runtime/blob.mjs +1 -1
  15. package/dist/runtime/db.mjs +1 -1
  16. package/dist/runtime/server/routes/agents/[agent]/history.get.d.ts +1 -1
  17. package/dist/runtime/server/routes/auth/handler.d.ts +2 -0
  18. package/dist/runtime/server/routes/auth/handler.mjs +11 -0
  19. package/dist/runtime/server/utils/auth.d.ts +66 -0
  20. package/dist/runtime/server/utils/auth.mjs +58 -0
  21. package/dist/runtime/server/utils/realtime.mjs +1 -1
  22. package/dist/runtime/server/utils/void-ai.d.ts +7 -0
  23. package/dist/runtime/server/utils/void-ai.mjs +47 -0
  24. package/dist/runtime/server/utils/void-auth.d.ts +2 -0
  25. package/dist/runtime/server/utils/void-auth.mjs +9 -0
  26. package/dist/runtime/server/utils/void-db.d.ts +8 -0
  27. package/dist/runtime/server/utils/void-db.mjs +38 -0
  28. package/dist/runtime/server/utils/void-seed.d.ts +11 -0
  29. package/dist/runtime/server/utils/void-seed.mjs +3 -0
  30. package/dist/runtime/types/ai.d.ts +2 -0
  31. package/dist/runtime/types/imports.d.ts +65 -6
  32. package/dist/types.d.ts +1 -1
  33. package/dist/utils/auth-schema.d.ts +3 -5
  34. package/package.json +3 -2
package/dist/module.mjs CHANGED
@@ -4,7 +4,7 @@ import { fileURLToPath } from 'node:url';
4
4
  import { defineNuxtModule, useLogger, createResolver, addTemplate, addComponent, hasNuxtModule, installModule, addNitroPlugin, addImports, addServerImports, addTypeTemplate, updateTemplates, addServerImportsDir, addServerHandler, addRouteMiddleware, addPlugin, extendPages } from '@nuxt/kit';
5
5
  import { defu } from 'defu';
6
6
  import { join, resolve, extname, basename, dirname, normalize, relative } from 'pathe';
7
- import { c as createWranglerConfig, r as resolveBindingName, a as checkDrizzleVersion, s as scanSchemaExports, b as resolveProjectName, f as findQueueFiles, d as findJobFiles, g as generateDevWranglerConfig, e as applyD1Migrations, h as findSchemaFiles } from './chunks/wrangler.mjs';
7
+ import { c as createWranglerConfig, r as resolveProjectName, a as resolveBindingName, b as checkDrizzleVersion, s as scanSchemaExports, f as findQueueFiles, d as findJobFiles, g as generateDevWranglerConfig, e as applyD1Migrations, h as findSchemaFiles } from './chunks/wrangler.mjs';
8
8
  import { generateAuthSchema } from './chunks/auth-schema.mjs';
9
9
  export { getActiveAuthTableNames } from './chunks/auth-schema.mjs';
10
10
  import { createHash } from 'node:crypto';
@@ -19,7 +19,7 @@ import 'drizzle-orm/node-sqlite';
19
19
  import 'node:process';
20
20
  import 'node:readline/promises';
21
21
 
22
- const version = "0.1.13";
22
+ const version = "0.1.14";
23
23
 
24
24
  function ensureDevEnv(rootDir) {
25
25
  const envPath = join(rootDir, ".env");
@@ -1226,6 +1226,12 @@ ${extraSources}
1226
1226
  nuxt.options.alias["#qarpeo/notifications"] = resolver.resolve("./runtime/server/utils/notifications");
1227
1227
  nuxt.options.alias["qarpeo/vapid"] = resolver.resolve("./runtime/server/utils/vapid");
1228
1228
  nuxt.options.alias["#qarpeo/vapid"] = resolver.resolve("./runtime/server/utils/vapid");
1229
+ nuxt.options.alias["void/db"] = resolver.resolve("./runtime/server/utils/void-db");
1230
+ nuxt.options.alias["void/seed"] = resolver.resolve("./runtime/server/utils/void-seed");
1231
+ nuxt.options.alias["void/auth"] = resolver.resolve("./runtime/server/utils/void-auth");
1232
+ nuxt.options.alias["void/ai"] = resolver.resolve("./runtime/server/utils/void-ai");
1233
+ nuxt.options.alias["void/client/vue"] = resolver.resolve("./runtime/app/composables/void-client");
1234
+ nuxt.options.alias["void/client"] = resolver.resolve("./runtime/app/composables/void-client");
1229
1235
  const emptyAgentsTemplate = addTemplate({
1230
1236
  filename: "qarpeo/agents-empty.mjs",
1231
1237
  write: true,
@@ -1271,9 +1277,12 @@ ${extraSources}
1271
1277
  const drizzleSeedDir = resolvePkgDir("drizzle-seed");
1272
1278
  nuxt.options.alias["drizzle-seed"] = drizzleSeedDir;
1273
1279
  nuxt.options.alias["drizzle-seed/"] = `${drizzleSeedDir}/`;
1274
- const authUtilsDir = resolvePkgDir("nuxt-auth-utils");
1275
- nuxt.options.alias["nuxt-auth-utils"] = authUtilsDir;
1276
- nuxt.options.alias["nuxt-auth-utils/"] = `${authUtilsDir}/`;
1280
+ const betterAuthDir = resolvePkgDir("better-auth");
1281
+ nuxt.options.alias["better-auth/vue"] = resolve(betterAuthDir, "dist/client/vue/index.mjs");
1282
+ nuxt.options.alias["better-auth/client"] = resolve(betterAuthDir, "dist/client/index.mjs");
1283
+ nuxt.options.alias["better-auth"] = resolve(betterAuthDir, "dist/index.mjs");
1284
+ const betterAuthAdapterDir = resolvePkgDir("@better-auth/drizzle-adapter");
1285
+ nuxt.options.alias["@better-auth/drizzle-adapter"] = resolve(betterAuthAdapterDir, "dist/index.mjs");
1277
1286
  const comarkNuxtDir = resolvePkgDir("@comark/nuxt");
1278
1287
  nuxt.options.alias["@comark/nuxt/utils"] = resolve(comarkNuxtDir, "dist/utils/index.js");
1279
1288
  nuxt.options.alias["@comark/nuxt/render"] = resolve(comarkNuxtDir, "dist/render.js");
@@ -1367,7 +1376,9 @@ ${extraSources}
1367
1376
  "@shikijs/engine-javascript",
1368
1377
  "@shikijs/langs",
1369
1378
  "@shikijs/themes",
1370
- "@shikijs/vscode-textmate"
1379
+ "@shikijs/vscode-textmate",
1380
+ "better-auth",
1381
+ "@better-auth/drizzle-adapter"
1371
1382
  );
1372
1383
  nuxt.options.vite = nuxt.options.vite || {};
1373
1384
  nuxt.options.vite.optimizeDeps = nuxt.options.vite.optimizeDeps || {};
@@ -1423,15 +1434,6 @@ ${extraSources}
1423
1434
  if (webAuthnEnabled) {
1424
1435
  nuxt.options.auth = defu(nuxt.options.auth || {}, { webAuthn: true });
1425
1436
  }
1426
- if (!hasNuxtModule("nuxt-auth-utils")) {
1427
- const authModuleOptions = webAuthnEnabled ? { webAuthn: true } : {};
1428
- try {
1429
- const authModulePath = fileURLToPath(import.meta.resolve("nuxt-auth-utils"));
1430
- await installModule(authModulePath, authModuleOptions);
1431
- } catch {
1432
- await installModule("nuxt-auth-utils", authModuleOptions);
1433
- }
1434
- }
1435
1437
  }
1436
1438
  if (options.cms && !hasNuxtModule("@comark/nuxt")) {
1437
1439
  try {
@@ -1486,6 +1488,51 @@ ${extraSources}
1486
1488
  const configPath = resolve(nuxt.options.buildDir, "wrangler.json");
1487
1489
  process.env.QARPEO_WRANGLER_CONFIG = configPath;
1488
1490
  process.env.QARPEO_PERSIST_PATH = resolve(nuxt.options.rootDir, ".wrangler/state/v3");
1491
+ nuxt.hook("ready", async () => {
1492
+ try {
1493
+ const { existsSync: existsSync2, mkdirSync, writeFileSync } = await import('node:fs');
1494
+ const voidDir = resolve(nuxt.options.rootDir, ".void");
1495
+ if (!existsSync2(voidDir)) {
1496
+ mkdirSync(voidDir, { recursive: true });
1497
+ }
1498
+ const inferenceImports = [
1499
+ "// Auto-generated by Qarpeo for Void Resource Inference",
1500
+ "// Triggers Void (void.cloud) to provision Cloudflare bindings automatically"
1501
+ ];
1502
+ if (options.db) inferenceImports.push('import { db } from "void/db"');
1503
+ if (options.kv) inferenceImports.push('import { kv } from "void/kv"');
1504
+ if (options.blob) inferenceImports.push('import { storage } from "void/storage"');
1505
+ if (options.ai) inferenceImports.push('import { ai } from "void/ai"');
1506
+ if (options.realtime) inferenceImports.push('import { defineLiveStream } from "void/live"');
1507
+ if (options.queue) inferenceImports.push('import { queues } from "void/queues"');
1508
+ writeFileSync(resolve(voidDir, "inference.ts"), inferenceImports.join("\n") + "\n", "utf-8");
1509
+ if (options.auth) {
1510
+ writeFileSync(
1511
+ resolve(voidDir, "better-auth-schema.ts"),
1512
+ generateAuthSchema(options.auth),
1513
+ "utf-8"
1514
+ );
1515
+ }
1516
+ const voidConfigPath = resolve(nuxt.options.rootDir, "void.config.ts");
1517
+ if (!existsSync2(voidConfigPath)) {
1518
+ const projectName = resolveProjectName(nuxt, options);
1519
+ const voidConfigContent = [
1520
+ 'import { defineConfig } from "void/config"',
1521
+ "",
1522
+ "export default defineConfig({",
1523
+ " cloudflare: {",
1524
+ ` name: "${projectName}",`,
1525
+ ' compatibility_date: "2026-02-24",',
1526
+ ' compatibility_flags: ["nodejs_compat", "nodejs_als"],',
1527
+ " },",
1528
+ "})",
1529
+ ""
1530
+ ].join("\n");
1531
+ writeFileSync(voidConfigPath, voidConfigContent, "utf-8");
1532
+ }
1533
+ } catch {
1534
+ }
1535
+ });
1489
1536
  if (options.remote) {
1490
1537
  process.env.QARPEO_CF_REMOTE = "1";
1491
1538
  const hasAccountId = process.env.CLOUDFLARE_ACCOUNT_ID || process.env.CF_ACCOUNT_ID;
@@ -1765,6 +1812,7 @@ export default queueHandler;
1765
1812
  });
1766
1813
  schemaTemplateDst = template.dst;
1767
1814
  nuxt.options.alias["#qarpeo/schema"] = schemaTemplateDst;
1815
+ nuxt.options.alias["@schema"] = schemaTemplateDst;
1768
1816
  const typesTemplate = addTemplate({
1769
1817
  filename: "qarpeo/db-types.ts",
1770
1818
  write: true,
@@ -1895,12 +1943,19 @@ export default queueHandler;
1895
1943
  const drizzleSeedDir = resolvePkgDir("drizzle-seed");
1896
1944
  nitroConfig.alias["drizzle-seed"] = drizzleSeedDir;
1897
1945
  nitroConfig.alias["drizzle-seed/"] = `${drizzleSeedDir}/`;
1898
- const authUtilsDir = resolvePkgDir("nuxt-auth-utils");
1899
- nitroConfig.alias["nuxt-auth-utils"] = authUtilsDir;
1900
- nitroConfig.alias["nuxt-auth-utils/"] = `${authUtilsDir}/`;
1901
1946
  const wranglerDir = resolvePkgDir("wrangler");
1902
1947
  nitroConfig.alias["wrangler"] = wranglerDir;
1903
1948
  nitroConfig.alias["wrangler/"] = `${wranglerDir}/`;
1949
+ const betterAuthDir = resolvePkgDir("better-auth");
1950
+ nitroConfig.alias["better-auth/vue"] = resolve(betterAuthDir, "dist/client/vue/index.mjs");
1951
+ nitroConfig.alias["better-auth/client"] = resolve(betterAuthDir, "dist/client/index.mjs");
1952
+ nitroConfig.alias["better-auth"] = resolve(betterAuthDir, "dist/index.mjs");
1953
+ const betterAuthAdapterDir = resolvePkgDir("@better-auth/drizzle-adapter");
1954
+ nitroConfig.alias["@better-auth/drizzle-adapter"] = resolve(betterAuthAdapterDir, "dist/index.mjs");
1955
+ nitroConfig.alias["void/db"] = resolver.resolve("./runtime/server/utils/void-db");
1956
+ nitroConfig.alias["void/seed"] = resolver.resolve("./runtime/server/utils/void-seed");
1957
+ nitroConfig.alias["void/auth"] = resolver.resolve("./runtime/server/utils/void-auth");
1958
+ nitroConfig.alias["void/ai"] = resolver.resolve("./runtime/server/utils/void-ai");
1904
1959
  const comarkNuxtDir = resolvePkgDir("@comark/nuxt");
1905
1960
  nitroConfig.alias["@comark/nuxt/utils"] = resolve(comarkNuxtDir, "dist/utils/index.js");
1906
1961
  nitroConfig.alias["@comark/nuxt/render"] = resolve(comarkNuxtDir, "dist/render.js");
@@ -2085,6 +2140,7 @@ export default queueHandler;
2085
2140
  if (isDrizzle && schemaTemplateDst) {
2086
2141
  nitroConfig.alias = nitroConfig.alias || {};
2087
2142
  nitroConfig.alias["#qarpeo/schema"] = schemaTemplateDst;
2143
+ nitroConfig.alias["@schema"] = schemaTemplateDst;
2088
2144
  const typesAlias = nuxt.options.alias["#qarpeo/db/types"];
2089
2145
  const zodAlias = nuxt.options.alias["#qarpeo/db/zod"];
2090
2146
  if (typesAlias) {
@@ -2422,6 +2478,14 @@ export default queueHandler;
2422
2478
  name: "schema",
2423
2479
  from: resolver.resolve("./runtime/server/utils/drizzle")
2424
2480
  },
2481
+ {
2482
+ name: "createDb",
2483
+ from: resolver.resolve("./runtime/server/utils/void-db")
2484
+ },
2485
+ {
2486
+ name: "defineSeed",
2487
+ from: resolver.resolve("./runtime/server/utils/void-seed")
2488
+ },
2425
2489
  {
2426
2490
  name: "useDB",
2427
2491
  from: "qarpeo/runtime"
@@ -2505,6 +2569,16 @@ export default queueHandler;
2505
2569
  ]);
2506
2570
  }
2507
2571
  if (options.ai) {
2572
+ addImports([
2573
+ {
2574
+ name: "useAIStream",
2575
+ from: resolver.resolve("./runtime/app/composables/ai")
2576
+ },
2577
+ {
2578
+ name: "useVectorSearch",
2579
+ from: resolver.resolve("./runtime/app/composables/ai")
2580
+ }
2581
+ ]);
2508
2582
  addServerImports([
2509
2583
  {
2510
2584
  name: "ai",
@@ -2716,6 +2790,24 @@ export default queueHandler;
2716
2790
  }
2717
2791
  ]);
2718
2792
  }
2793
+ addImports([
2794
+ {
2795
+ name: "useUserSession",
2796
+ from: resolver.resolve("./runtime/app/composables/auth")
2797
+ },
2798
+ {
2799
+ name: "useAuth",
2800
+ from: resolver.resolve("./runtime/app/composables/auth")
2801
+ },
2802
+ {
2803
+ name: "useSession",
2804
+ from: resolver.resolve("./runtime/app/composables/auth")
2805
+ },
2806
+ {
2807
+ name: "authClient",
2808
+ from: resolver.resolve("./runtime/app/composables/auth")
2809
+ }
2810
+ ]);
2719
2811
  if (options.auth) {
2720
2812
  const authConfig = typeof options.auth === "object" ? options.auth : {};
2721
2813
  const authPrefix = authConfig.prefix || "/api/auth";
@@ -2753,6 +2845,10 @@ export default queueHandler;
2753
2845
  path: resolver.resolve("./runtime/app/middleware/auth.global"),
2754
2846
  global: true
2755
2847
  });
2848
+ addServerHandler({
2849
+ route: `${authPrefix}/**`,
2850
+ handler: resolver.resolve("./runtime/server/routes/auth/handler")
2851
+ });
2756
2852
  addServerHandler({
2757
2853
  route: `${authPrefix}/user`,
2758
2854
  handler: resolver.resolve("./runtime/server/routes/auth/user.get")
@@ -2923,10 +3019,6 @@ export default queueHandler;
2923
3019
  handler: resolver.resolve("./runtime/server/routes/auth/organization/mfa.post")
2924
3020
  });
2925
3021
  addImports([
2926
- {
2927
- name: "useAuth",
2928
- from: resolver.resolve("./runtime/app/composables/auth")
2929
- },
2930
3022
  {
2931
3023
  name: "useOrganization",
2932
3024
  from: resolver.resolve("./runtime/app/composables/organization")
@@ -2957,6 +3049,26 @@ export default queueHandler;
2957
3049
  }
2958
3050
  ]);
2959
3051
  addServerImports([
3052
+ {
3053
+ name: "serverAuth",
3054
+ from: resolver.resolve("./runtime/server/utils/auth")
3055
+ },
3056
+ {
3057
+ name: "createAuth",
3058
+ from: resolver.resolve("./runtime/server/utils/auth")
3059
+ },
3060
+ {
3061
+ name: "useServerAuth",
3062
+ from: resolver.resolve("./runtime/server/utils/auth")
3063
+ },
3064
+ {
3065
+ name: "getServerSession",
3066
+ from: resolver.resolve("./runtime/server/utils/auth")
3067
+ },
3068
+ {
3069
+ name: "requireServerSession",
3070
+ from: resolver.resolve("./runtime/server/utils/auth")
3071
+ },
2960
3072
  {
2961
3073
  name: "handleOAuthSuccess",
2962
3074
  from: resolver.resolve("./runtime/server/utils/auth")
@@ -4038,6 +4150,14 @@ export const manifestCollections = ${JSON.stringify(cmsConfig.collections || {})
4038
4150
  {
4039
4151
  name: "useAgentChat",
4040
4152
  from: resolver.resolve("./runtime/app/composables/chat")
4153
+ },
4154
+ {
4155
+ name: "useAIStream",
4156
+ from: resolver.resolve("./runtime/app/composables/ai")
4157
+ },
4158
+ {
4159
+ name: "useVectorSearch",
4160
+ from: resolver.resolve("./runtime/app/composables/ai")
4041
4161
  }
4042
4162
  ]);
4043
4163
  addServerImports([
@@ -1,8 +1,8 @@
1
1
  import type { AiBinding, QarpeoAI } from "./types/ai";
2
2
  import type { CFEvent } from "./types/index";
3
- import { generateImage, textToImage, generateSpeech, textToSpeech, transcribeAudio, speechToText, generateText, streamText, embedText } from "./server/utils/ai";
3
+ import { generateImage, textToImage, generateSpeech, textToSpeech, transcribeAudio, speechToText, generateText, streamText, embedText, similaritySearch } from "./server/utils/ai";
4
4
  export type { AiBinding, AiOptions, QarpeoAI, GenerateImageOptions, GenerateImageResult, GenerateSpeechOptions, GenerateSpeechResult, TranscribeAudioInput, TranscribeAudioOptions, TranscribeAudioResult, StreamTextOptions, } from "./types/ai";
5
- export { generateImage, textToImage, generateSpeech, textToSpeech, transcribeAudio, speechToText, generateText, streamText, embedText, };
5
+ export { generateImage, textToImage, generateSpeech, textToSpeech, transcribeAudio, speechToText, generateText, streamText, embedText, similaritySearch, };
6
6
  /**
7
7
  * Returns the raw Cloudflare Workers AI binding from the active environment.
8
8
  *
@@ -23,3 +23,5 @@ export declare const useAI: (bindingName?: string, event?: CFEvent) => QarpeoAI;
23
23
  export declare const ai: QarpeoAI;
24
24
  export { useChat, useAgentChat } from "./app/composables/chat";
25
25
  export type { UseChatOptions, UseAgentChatOptions } from "./app/composables/chat";
26
+ export { useAIStream, useVectorSearch } from "./app/composables/ai";
27
+ export type { UseAIStreamOptions, UseVectorSearchOptions } from "./app/composables/ai";
@@ -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,