New features: - HLS video encoding/streaming (hls routes, hls-encoder) and a media transcripts pipeline (transcripts route + media-transcript queries) - AI assistant chat vs. run model: agent-course-generation worker/queue, run-monitor pane, chat-changes card, content ask-ai bar - Per-theme course-page previews across org landing-page themes (bold, classic, corporate, editorial, etc.) with a shared course token/component set - View-as-student mode and login-link / link-invite invite flows Refactor: - Extract packages/core consolidating config (env, storage, dashboard-url), services and utils previously duplicated under apps/api/src/config - Remove legacy agent service modules (chat-tools, chat-context, context-window, document, fetch-url, lesson-content) - Relax Cross-Origin-Resource-Policy to allow cross-origin media embedding - Add format script to tenant-router so turbo run format covers it
94 lines
2.1 KiB
TypeScript
94 lines
2.1 KiB
TypeScript
import { dev } from '$app/environment';
|
|
import { get } from 'svelte/store';
|
|
import { globalStore } from '$lib/utils/store/app';
|
|
|
|
const USERJOT_APP_ID = 'cm4a6vcmp00jpmdb5n66rmkzz';
|
|
|
|
let isInitialized = false;
|
|
|
|
function isWidgetAllowed(): boolean {
|
|
if (dev) return false;
|
|
if (get(globalStore).isOrgSite) return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
function ensureSdkLoaded(): void {
|
|
if (window.uj) return;
|
|
|
|
window.$ujq = window.$ujq || [];
|
|
window.uj =
|
|
window.uj ||
|
|
(new Proxy({} as Window['uj'], {
|
|
get:
|
|
(_, prop) =>
|
|
(...args: unknown[]) =>
|
|
window.$ujq.push([prop, ...args])
|
|
}) as Window['uj']);
|
|
|
|
const script = document.createElement('script');
|
|
script.type = 'module';
|
|
script.async = true;
|
|
script.src = 'https://cdn.userjot.com/sdk/v2/uj.js';
|
|
const nonce = document.querySelector('script[nonce]')?.getAttribute('nonce');
|
|
if (nonce) script.setAttribute('nonce', nonce);
|
|
document.head.appendChild(script);
|
|
}
|
|
|
|
export function initUserJot(): void {
|
|
if (isInitialized) return;
|
|
if (!isWidgetAllowed()) return;
|
|
|
|
ensureSdkLoaded();
|
|
|
|
window.uj.init(USERJOT_APP_ID, {
|
|
trigger: 'custom',
|
|
position: 'right',
|
|
theme: 'auto'
|
|
});
|
|
|
|
isInitialized = true;
|
|
}
|
|
|
|
type UserJotIdentity = {
|
|
id: string;
|
|
email?: string;
|
|
fullname?: string | null;
|
|
avatarUrl?: string | null;
|
|
};
|
|
|
|
export function identifyUserJotUser({ id, email, fullname, avatarUrl }: UserJotIdentity): void {
|
|
if (!isWidgetAllowed()) return;
|
|
|
|
ensureSdkLoaded();
|
|
|
|
const [firstName, ...rest] = (fullname ?? '').trim().split(/\s+/);
|
|
const lastName = rest.join(' ');
|
|
|
|
window.uj.identify({
|
|
id,
|
|
email,
|
|
firstName: firstName || undefined,
|
|
lastName: lastName || undefined,
|
|
avatar: avatarUrl ?? undefined
|
|
});
|
|
}
|
|
|
|
export function clearUserJotUser(): void {
|
|
if (!isWidgetAllowed()) return;
|
|
|
|
ensureSdkLoaded();
|
|
|
|
window.uj.identify(null);
|
|
}
|
|
|
|
export type UserJotWidgetSection = 'feedback' | 'roadmap' | 'updates';
|
|
|
|
export function showUserJotWidget(section: UserJotWidgetSection): void {
|
|
if (!isWidgetAllowed()) return;
|
|
|
|
ensureSdkLoaded();
|
|
|
|
window.uj.showWidget({ section });
|
|
}
|