Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions admin-dashboard/src/lib/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type RuntimeConfig = {
declare global {
interface Window {
__INSFORGE_RUNTIME_CONFIG__?: RuntimeConfig
__INSFORGE_MANAGED_ANALYTICS__?: { measurementId: string };
dataLayer?: unknown[]
gtag?: (...args: unknown[]) => void
__INSFORGE_GA4_NAVIGATION_TRACKING__?: boolean
Expand Down Expand Up @@ -110,6 +111,13 @@ export function initializeAnalytics(): void {
const configuredId = runtime?.gaMeasurementId || import.meta.env.VITE_GA_MEASUREMENT_ID
if (!import.meta.env.PROD || !configuredId || measurementId) return

const managed = window.__INSFORGE_MANAGED_ANALYTICS__
if (managed?.measurementId === configuredId) {
measurementId = configuredId
analyticsContext = safeProperties(commonProperties(runtime))
return
}

measurementId = configuredId
window.dataLayer = window.dataLayer || []
window.gtag = window.gtag || function (..._args: unknown[]) {
Expand Down
8 changes: 8 additions & 0 deletions ai-pdf-chatbot/lib/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type RuntimeConfig = {
declare global {
interface Window {
__INSFORGE_RUNTIME_CONFIG__?: RuntimeConfig;
__INSFORGE_MANAGED_ANALYTICS__?: { measurementId: string };
dataLayer?: unknown[];
gtag?: (...args: unknown[]) => void;
__INSFORGE_GA4_NAVIGATION_TRACKING__?: boolean;
Expand Down Expand Up @@ -112,6 +113,13 @@ export function initializeAnalytics(): void {
const configuredId = runtime?.gaMeasurementId || process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID;
if (process.env.NODE_ENV !== 'production' || !configuredId || measurementId) return;

const managed = window.__INSFORGE_MANAGED_ANALYTICS__;
if (managed?.measurementId === configuredId) {
measurementId = configuredId;
analyticsContext = safeProperties(commonProperties(runtime));
return;
}

measurementId = configuredId;
window.dataLayer = window.dataLayer || [];
window.gtag = window.gtag || function (..._args: unknown[]) {
Expand Down
10 changes: 10 additions & 0 deletions blank/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
VITE_INSFORGE_BASE_URL=https://your-app.region.insforge.app
VITE_INSFORGE_ANON_KEY=your_insforge_anon_key_here

# Local/standalone analytics fallback. InsForge publishing injects this at runtime.
VITE_GA_MEASUREMENT_ID=
VITE_INSFORGE_APP_ID=
VITE_INSFORGE_ENVIRONMENT_ID=
VITE_INSFORGE_TEMPLATE_ID=blank
VITE_INSFORGE_TEMPLATE_VERSION_ID=
VITE_INSFORGE_RELEASE_ID=
18 changes: 18 additions & 0 deletions blank/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
MIT License

Copyright (c) 2026 Lexmount

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 changes: 11 additions & 0 deletions blank/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Blank Web App

A minimal Vite + React starter for InsForge.

- `src/lib/insforge.ts` reads the public endpoint and anon key injected by the platform.
- Analytics is automatic in published releases and has a GA4 fallback for standalone hosting.
- `src/lib/ai.ts` is opt-in: call it only when the application's existing AI switch is enabled.
- `functions/ai-chat.ts` keeps provider credentials server-side and requires an authenticated user.

Run `npm install && npm run dev` for local development. Copy `.env.example` to `.env.local` when
working outside the managed InsForge workspace.
42 changes: 42 additions & 0 deletions blank/functions/ai-chat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { createClient } from 'npm:@insforge/sdk'

const cors = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
}
const json = (status: number, body: unknown) => new Response(JSON.stringify(body), {
status,
headers: { ...cors, 'Content-Type': 'application/json' },
})
type Message = { role: 'system' | 'user' | 'assistant'; content: string }

export default async function handler(request: Request): Promise<Response> {
if (request.method === 'OPTIONS') return new Response(null, { status: 204, headers: cors })
if (request.method !== 'POST') return json(405, { error: 'method_not_allowed' })
const token = request.headers.get('Authorization')?.replace(/^Bearer\s+/i, '')
if (!token) return json(401, { error: 'authentication_required' })

const client = createClient({ baseUrl: Deno.env.get('INSFORGE_BASE_URL'), edgeFunctionToken: token })
const { data: identity } = await client.auth.getCurrentUser()
if (!identity?.user?.id) return json(401, { error: 'authentication_required' })

let input: { messages?: Message[] }
try { input = await request.json() } catch { return json(400, { error: 'invalid_json' }) }
const messages = (input.messages ?? []).slice(0, 30).filter((message) =>
['system', 'user', 'assistant'].includes(message.role)
&& typeof message.content === 'string'
&& message.content.length > 0
&& message.content.length <= 20_000
)
if (!messages.length || messages.length !== input.messages?.length) return json(422, { error: 'invalid_messages' })

const model = Deno.env.get('AI_DEFAULT_MODEL')
if (!model) return json(503, { error: 'ai_not_enabled' })
try {
const completion = await client.ai.chat.completions.create({ model, messages, maxTokens: 1200 })
return json(200, { content: completion.choices?.[0]?.message?.content ?? '' })
} catch (error) {
return json(502, { error: 'ai_request_failed', detail: error instanceof Error ? error.message : 'AI request failed' })
}
}
13 changes: 13 additions & 0 deletions blank/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>InsForge App</title>
</head>
<body>
<div id="root"></div>
<script vite-ignore src="/.well-known/insforge-runtime-config.js"></script>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading
Loading