@wavebirdai/api 0.0.0-stage → 0.1.0-beta.10
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/LICENSE +21 -0
- package/README.md +99 -2
- package/bin/wavebird-next.mjs +69 -0
- package/build.mjs +10 -0
- package/dist/browser.d.ts +31 -0
- package/dist/browser.js +220 -0
- package/dist/generation.js +98 -0
- package/dist/postgres-turn-storage.js +81 -0
- package/dist/server.d.ts +76 -0
- package/dist/server.js +471 -0
- package/dist/turn-journal.js +155 -0
- package/examples/next-js/.env.example +6 -0
- package/examples/next-js/app/api/generate/route.js +6 -0
- package/examples/next-js/app/api/sponsor-consent/route.js +4 -0
- package/examples/next-js/app/api/sponsor-session/route.js +5 -0
- package/examples/next-js/app/api/sponsor-slot/route.js +3 -0
- package/examples/next-js/app/layout.jsx +3 -0
- package/examples/next-js/app/page.jsx +70 -0
- package/examples/next-js/lib/auth.js +33 -0
- package/examples/next-js/lib/model.js +3 -0
- package/examples/next-js/lib/publisher.js +37 -0
- package/examples/next-js/lib/turn-store.js +9 -0
- package/examples/next-js/package.json +7 -0
- package/examples/next-ts/.env.example +6 -0
- package/examples/next-ts/app/api/generate/route.ts +6 -0
- package/examples/next-ts/app/api/sponsor-consent/route.ts +4 -0
- package/examples/next-ts/app/api/sponsor-session/route.ts +5 -0
- package/examples/next-ts/app/api/sponsor-slot/route.ts +3 -0
- package/examples/next-ts/app/layout.tsx +5 -0
- package/examples/next-ts/app/page.tsx +71 -0
- package/examples/next-ts/lib/auth.ts +33 -0
- package/examples/next-ts/lib/model.ts +3 -0
- package/examples/next-ts/lib/publisher.ts +37 -0
- package/examples/next-ts/lib/turn-store.ts +10 -0
- package/examples/next-ts/package.json +8 -0
- package/examples/next-ts/tsconfig.json +20 -0
- package/package.json +21 -4
- package/src/browser.d.ts +31 -0
- package/src/browser.js +220 -0
- package/src/generation.js +98 -0
- package/src/postgres-turn-storage.js +81 -0
- package/src/server.d.ts +76 -0
- package/src/server.js +471 -0
- package/src/turn-journal.js +155 -0
- package/templates/NEXT-SETUP.md +12 -0
- package/templates/WavebirdPlacement.jsx +41 -0
- package/templates/WavebirdPlacement.tsx +47 -0
- package/templates/model.js +3 -0
- package/templates/model.ts +3 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
import { createPublisherAds } from "@wavebirdai/api/browser";
|
|
5
|
+
|
|
6
|
+
export function WavebirdPlacement({ clientId, userId, conversationId, onReady }) {
|
|
7
|
+
const target = useRef(null);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (!target.current || !clientId || !userId || !conversationId) return;
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
let disposed = false;
|
|
12
|
+
let ads = null;
|
|
13
|
+
void fetch("/api/sponsor-session", { cache: "no-store", signal: controller.signal }).then(async response => {
|
|
14
|
+
if (!response.ok) return;
|
|
15
|
+
const sessionId = (await response.json()).session_id;
|
|
16
|
+
if (disposed || !/^[A-Za-z0-9_-]{1,128}$/.test(sessionId)) return;
|
|
17
|
+
ads = createPublisherAds({
|
|
18
|
+
target: target.current,
|
|
19
|
+
clientId,
|
|
20
|
+
surfaceId: "chat_assistant",
|
|
21
|
+
jobType: "chat",
|
|
22
|
+
timing: "during",
|
|
23
|
+
consentMode: "wavebird_consent",
|
|
24
|
+
userId,
|
|
25
|
+
conversationId,
|
|
26
|
+
sessionId,
|
|
27
|
+
turnBinding: true,
|
|
28
|
+
rendererUrl: "https://api.wavebird.ai/v1/render.js",
|
|
29
|
+
placementEndpoint: "/api/sponsor-slot",
|
|
30
|
+
consentEndpoint: "/api/sponsor-consent",
|
|
31
|
+
privacySettingsTarget: "#wavebird-privacy-settings"
|
|
32
|
+
});
|
|
33
|
+
onReady?.(ads);
|
|
34
|
+
}).catch(() => {});
|
|
35
|
+
return () => { disposed = true; controller.abort(); onReady?.(null); ads?.dispose(); };
|
|
36
|
+
}, [clientId, userId, conversationId, onReady]);
|
|
37
|
+
return <>
|
|
38
|
+
<button id="wavebird-privacy-settings" type="button">Sponsored choices</button>
|
|
39
|
+
<section ref={target} aria-label="Sponsored placement area" style={{ width: "100%", maxWidth: 728, height: 346 }} />
|
|
40
|
+
</>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
import { createPublisherAds, type PublisherAds } from "@wavebirdai/api/browser";
|
|
5
|
+
|
|
6
|
+
export function WavebirdPlacement({ clientId, userId, conversationId, onReady }: {
|
|
7
|
+
clientId: string;
|
|
8
|
+
userId: string;
|
|
9
|
+
conversationId: string;
|
|
10
|
+
onReady?: (ads: PublisherAds | null) => void;
|
|
11
|
+
}) {
|
|
12
|
+
const target = useRef<HTMLElement | null>(null);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (!target.current || !clientId || !userId || !conversationId) return;
|
|
15
|
+
const container = target.current;
|
|
16
|
+
const controller = new AbortController();
|
|
17
|
+
let disposed = false;
|
|
18
|
+
let ads: PublisherAds | null = null;
|
|
19
|
+
void fetch("/api/sponsor-session", { cache: "no-store", signal: controller.signal }).then(async response => {
|
|
20
|
+
if (!response.ok) return;
|
|
21
|
+
const sessionId = (await response.json()).session_id;
|
|
22
|
+
if (disposed || !/^[A-Za-z0-9_-]{1,128}$/.test(sessionId)) return;
|
|
23
|
+
ads = createPublisherAds({
|
|
24
|
+
target: container,
|
|
25
|
+
clientId,
|
|
26
|
+
surfaceId: "chat_assistant",
|
|
27
|
+
jobType: "chat",
|
|
28
|
+
timing: "during",
|
|
29
|
+
consentMode: "wavebird_consent",
|
|
30
|
+
userId,
|
|
31
|
+
conversationId,
|
|
32
|
+
sessionId,
|
|
33
|
+
turnBinding: true,
|
|
34
|
+
rendererUrl: "https://api.wavebird.ai/v1/render.js",
|
|
35
|
+
placementEndpoint: "/api/sponsor-slot",
|
|
36
|
+
consentEndpoint: "/api/sponsor-consent",
|
|
37
|
+
privacySettingsTarget: "#wavebird-privacy-settings"
|
|
38
|
+
});
|
|
39
|
+
onReady?.(ads);
|
|
40
|
+
}).catch(() => {});
|
|
41
|
+
return () => { disposed = true; controller.abort(); onReady?.(null); ads?.dispose(); };
|
|
42
|
+
}, [clientId, userId, conversationId, onReady]);
|
|
43
|
+
return <>
|
|
44
|
+
<button id="wavebird-privacy-settings" type="button">Sponsored choices</button>
|
|
45
|
+
<section ref={target} aria-label="Sponsored placement area" style={{ width: "100%", maxWidth: 728, height: 346 }} />
|
|
46
|
+
</>;
|
|
47
|
+
}
|