This commit is contained in:
2026-01-23 16:11:58 +08:00
parent aefd34b849
commit b90c279324
4 changed files with 416 additions and 11 deletions

View File

@@ -1,20 +1,29 @@
import { ConvexClient } from "convex/browser";
import { ConvexClient, ConvexHttpClient, AuthTokenFetcher } from "convex/browser";
import { api } from "./convex/_generated/api.js";
const url = process.env["CONVEX_URL"]
// const httpClient = new ConvexHttpClient(url!);
const client = new ConvexClient(url!);
console.log("Client created", url);
const authTokenFetcher: AuthTokenFetcher = async ({ forceRefreshToken }: { forceRefreshToken: boolean }) => {
console.log("AuthTokenFetcher called, forceRefreshToken:", forceRefreshToken);
return null;
}
const _auth = await client.setAuth(authTokenFetcher, () => { })
const auth = client.getAuth();
console.log("Client auth", auth);
const unsubscribe = client.onUpdate(api.abcv.get, {}, async (tasks) => {
console.log(tasks);
});
const list = await client.query(api.abcv.get, {});
console.log("Initial list:", list);
for (let i = 0; i < list.length; i++) {
const a = list[i];
console.log(`Item ${i}:`, a.title);
}
// const list = await client.query(api.abcv.get, {});
// console.log("Initial list:", list);
// for (let i = 0; i < list.length; i++) {
// const a = list[i];
// console.log(`Item ${i}:`, a.title);
// }
const list = await client.action(api.abcv.chat, { message: "Hello, 1+1=?" });
console.log("Chat response:", list);
await Bun.sleep(1000);
unsubscribe();
await client.close();