@agent-native/core 0.13.1 → 0.14.1
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/dist/agent/engine/builder-engine.d.ts.map +1 -1
- package/dist/agent/engine/builder-engine.js +5 -1
- package/dist/agent/engine/builder-engine.js.map +1 -1
- package/dist/agent/production-agent.d.ts +23 -1
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +82 -1
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/run-loop-with-resume.d.ts +45 -0
- package/dist/agent/run-loop-with-resume.d.ts.map +1 -0
- package/dist/agent/run-loop-with-resume.js +121 -0
- package/dist/agent/run-loop-with-resume.js.map +1 -0
- package/dist/agent/run-store.d.ts.map +1 -1
- package/dist/agent/run-store.js +8 -2
- package/dist/agent/run-store.js.map +1 -1
- package/dist/agent/types.d.ts +1 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +8 -45
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/ConnectBuilderCard.d.ts.map +1 -1
- package/dist/client/ConnectBuilderCard.js +24 -0
- package/dist/client/ConnectBuilderCard.js.map +1 -1
- package/dist/client/analytics.d.ts.map +1 -1
- package/dist/client/analytics.js +10 -1
- package/dist/client/analytics.js.map +1 -1
- package/dist/client/extensions/ExtensionsSidebarSection.js +1 -1
- package/dist/client/extensions/ExtensionsSidebarSection.js.map +1 -1
- package/dist/client/use-chat-threads.d.ts +0 -6
- package/dist/client/use-chat-threads.d.ts.map +1 -1
- package/dist/client/use-chat-threads.js +40 -52
- package/dist/client/use-chat-threads.js.map +1 -1
- package/dist/client/use-db-sync.d.ts.map +1 -1
- package/dist/client/use-db-sync.js +3 -1
- package/dist/client/use-db-sync.js.map +1 -1
- package/dist/db/client.d.ts.map +1 -1
- package/dist/db/client.js +9 -0
- package/dist/db/client.js.map +1 -1
- package/dist/db/create-get-db.d.ts.map +1 -1
- package/dist/db/create-get-db.js +7 -0
- package/dist/db/create-get-db.js.map +1 -1
- package/dist/extensions/actions.js +1 -1
- package/dist/extensions/actions.js.map +1 -1
- package/dist/extensions/fetch-tool.d.ts.map +1 -1
- package/dist/extensions/fetch-tool.js +46 -5
- package/dist/extensions/fetch-tool.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +82 -75
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/agent-discovery.d.ts +21 -0
- package/dist/server/agent-discovery.d.ts.map +1 -1
- package/dist/server/agent-discovery.js +18 -3
- package/dist/server/agent-discovery.js.map +1 -1
- package/dist/server/auth.d.ts +27 -0
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +71 -12
- package/dist/server/auth.js.map +1 -1
- package/dist/server/better-auth-instance.js +13 -0
- package/dist/server/better-auth-instance.js.map +1 -1
- package/dist/server/google-auth-mode.d.ts +20 -0
- package/dist/server/google-auth-mode.d.ts.map +1 -0
- package/dist/server/google-auth-mode.js +20 -0
- package/dist/server/google-auth-mode.js.map +1 -0
- package/dist/server/google-auth-plugin.d.ts +7 -0
- package/dist/server/google-auth-plugin.d.ts.map +1 -1
- package/dist/server/google-auth-plugin.js +21 -5
- package/dist/server/google-auth-plugin.js.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/onboarding-html.d.ts +7 -0
- package/dist/server/onboarding-html.d.ts.map +1 -1
- package/dist/server/onboarding-html.js +22 -3
- package/dist/server/onboarding-html.js.map +1 -1
- package/dist/server/sentry.d.ts.map +1 -1
- package/dist/server/sentry.js +41 -0
- package/dist/server/sentry.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,6 +5,27 @@ export interface DiscoveredAgent {
|
|
|
5
5
|
url: string;
|
|
6
6
|
color: string;
|
|
7
7
|
}
|
|
8
|
+
export interface WorkspaceAppManifestEntry {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
path: string;
|
|
13
|
+
url?: string | null;
|
|
14
|
+
isDispatch?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolve the workspace app manifest from the same fallback chain that
|
|
18
|
+
* `discoverWorkspaceAgents` uses: `AGENT_NATIVE_WORKSPACE_APPS_JSON` env →
|
|
19
|
+
* `.agent-native/workspace-apps.json` (or sibling) on disk → live filesystem
|
|
20
|
+
* scan of `apps/<id>/package.json` under the workspace root.
|
|
21
|
+
*
|
|
22
|
+
* Callers (e.g. the dispatch `/dispatch/<appId>` catch-all loader) need this
|
|
23
|
+
* to behave the same in production deploys (which write the manifest file)
|
|
24
|
+
* and during local dev (where new apps appear under `apps/` without an env
|
|
25
|
+
* restart). Reading only the env var would silently downgrade the behavior
|
|
26
|
+
* in both cases.
|
|
27
|
+
*/
|
|
28
|
+
export declare function loadWorkspaceAppsManifest(): WorkspaceAppManifestEntry[] | null;
|
|
8
29
|
export declare function shouldIncludeRemoteAgentManifest(manifest: {
|
|
9
30
|
id?: string | null;
|
|
10
31
|
}, selfAppId?: string): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-discovery.d.ts","sourceRoot":"","sources":["../../src/server/agent-discovery.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;
|
|
1
|
+
{"version":3,"file":"agent-discovery.d.ts","sourceRoot":"","sources":["../../src/server/agent-discovery.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAuCD,MAAM,WAAW,yBAAyB;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,IACrC,yBAAyB,EAAE,GAC3B,IAAI,CAMP;AAED,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE;IAAE,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EAChC,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAST;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,eAAe,EAAE,CAUtE;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,EAAE,CAAC,CAyE5B;AAED;;GAEG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAItC;AAmND;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,EAAE,eAAe,EAOnD,CAAC"}
|
|
@@ -19,6 +19,23 @@ const BUILTIN_AGENTS = TEMPLATES.filter((template) => (!template.hidden || templ
|
|
|
19
19
|
const HIDDEN_FIRST_PARTY_AGENT_IDS = new Set(TEMPLATES.filter((template) => template.hidden && !template.defaultAgent && template.prodUrl).map((template) => template.name));
|
|
20
20
|
const WORKSPACE_APPS_ENV_KEY = "AGENT_NATIVE_WORKSPACE_APPS_JSON";
|
|
21
21
|
const WORKSPACE_APPS_MANIFEST_FILE = "workspace-apps.json";
|
|
22
|
+
/**
|
|
23
|
+
* Resolve the workspace app manifest from the same fallback chain that
|
|
24
|
+
* `discoverWorkspaceAgents` uses: `AGENT_NATIVE_WORKSPACE_APPS_JSON` env →
|
|
25
|
+
* `.agent-native/workspace-apps.json` (or sibling) on disk → live filesystem
|
|
26
|
+
* scan of `apps/<id>/package.json` under the workspace root.
|
|
27
|
+
*
|
|
28
|
+
* Callers (e.g. the dispatch `/dispatch/<appId>` catch-all loader) need this
|
|
29
|
+
* to behave the same in production deploys (which write the manifest file)
|
|
30
|
+
* and during local dev (where new apps appear under `apps/` without an env
|
|
31
|
+
* restart). Reading only the env var would silently downgrade the behavior
|
|
32
|
+
* in both cases.
|
|
33
|
+
*/
|
|
34
|
+
export function loadWorkspaceAppsManifest() {
|
|
35
|
+
return (readWorkspaceAppsFromEnv() ??
|
|
36
|
+
readWorkspaceAppsFromManifestFile() ??
|
|
37
|
+
readWorkspaceAppsFromFilesystem());
|
|
38
|
+
}
|
|
22
39
|
export function shouldIncludeRemoteAgentManifest(manifest, selfAppId) {
|
|
23
40
|
const id = manifest.id?.trim();
|
|
24
41
|
if (!id)
|
|
@@ -292,9 +309,7 @@ function workspaceAppUrl(app) {
|
|
|
292
309
|
}
|
|
293
310
|
}
|
|
294
311
|
function discoverWorkspaceAgents(selfAppId) {
|
|
295
|
-
const workspaceApps =
|
|
296
|
-
readWorkspaceAppsFromManifestFile() ??
|
|
297
|
-
readWorkspaceAppsFromFilesystem();
|
|
312
|
+
const workspaceApps = loadWorkspaceAppsManifest();
|
|
298
313
|
if (!workspaceApps)
|
|
299
314
|
return [];
|
|
300
315
|
return workspaceApps
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-discovery.js","sourceRoot":"","sources":["../../src/server/agent-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7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YACd,WAAW,EACT,GAAG,CAAC,WAAW;gBACf,OAAO,EAAE,WAAW;gBACpB,4BAA4B,GAAG,CAAC,IAAI,EAAE;YACxC,GAAG;YACH,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,SAAS;SACT,CAAC;IAC9B,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,KAAK,EAA4B,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,0BAA0B,GACrC,cAAc,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACpD,EAAE,EAAE,GAAG,CAAC,EAAE;IACV,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,WAAW,EAAE,GAAG,CAAC,WAAW;IAC5B,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,cAAc;IAC5B,KAAK,EAAE,GAAG,CAAC,KAAK;CACjB,CAAC,CAAC,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { TEMPLATES } from \"../cli/templates-meta.js\";\n\nexport interface DiscoveredAgent {\n id: string;\n name: string;\n description: string;\n url: string;\n color: string;\n}\n\ninterface AgentEntry {\n id: string;\n name: string;\n description: string;\n url: string;\n devUrl?: string;\n devPort: number;\n color: string;\n}\n\n/**\n * Built-in agent registry. Derive this from the published CLI metadata so\n * connected-agent discovery stays aligned with first-party template metadata\n * without depending on @agent-native/shared-app-config at runtime.\n */\nconst BUILTIN_AGENTS: AgentEntry[] = TEMPLATES.filter(\n (template) =>\n (!template.hidden || template.defaultAgent) && !!template.prodUrl,\n).map((template) => ({\n id: template.name,\n name: template.label,\n description: template.description ?? template.hint,\n url: template.prodUrl!,\n devUrl: `http://localhost:${template.devPort}`,\n devPort: template.devPort,\n color: template.color,\n}));\n\nconst HIDDEN_FIRST_PARTY_AGENT_IDS = new Set(\n TEMPLATES.filter(\n (template) => template.hidden && !template.defaultAgent && template.prodUrl,\n ).map((template) => template.name),\n);\n\nconst WORKSPACE_APPS_ENV_KEY = \"AGENT_NATIVE_WORKSPACE_APPS_JSON\";\nconst WORKSPACE_APPS_MANIFEST_FILE = \"workspace-apps.json\";\n\ninterface WorkspaceAppManifestEntry {\n id: string;\n name: string;\n description: string;\n path: string;\n url?: string | null;\n isDispatch?: boolean;\n}\n\nexport function shouldIncludeRemoteAgentManifest(\n manifest: { id?: string | null },\n selfAppId?: string,\n): boolean {\n const id = manifest.id?.trim();\n if (!id) return false;\n const normalizedId = id.toLowerCase();\n const normalizedSelfAppId = selfAppId?.trim().toLowerCase();\n if (normalizedSelfAppId && normalizedId === normalizedSelfAppId) {\n return false;\n }\n return !HIDDEN_FIRST_PARTY_AGENT_IDS.has(normalizedId);\n}\n\n/**\n * Get built-in agents (static, no DB). Used as fallback and for seeding.\n */\nexport function getBuiltinAgents(selfAppId?: string): DiscoveredAgent[] {\n return BUILTIN_AGENTS.filter((app) => app.id !== selfAppId && app.url).map(\n (app) => ({\n id: app.id,\n name: app.name,\n description: app.description,\n url: resolveAgentUrl(app),\n color: app.color,\n }),\n );\n}\n\n/**\n * Discover all agents: built-in + custom agents stored as resources.\n * Custom agents override built-in agents with the same ID.\n */\nexport async function discoverAgents(\n selfAppId?: string,\n): Promise<DiscoveredAgent[]> {\n const builtins = getBuiltinAgents(selfAppId);\n const agentsById = new Map<string, DiscoveredAgent>();\n\n // Start with built-ins\n for (const agent of builtins) {\n agentsById.set(agent.id, agent);\n }\n\n // Overlay custom agents from resources\n try {\n const { resourceList, resourceGet, SHARED_OWNER } =\n await import(\"../resources/store.js\");\n\n const { parseRemoteAgentManifest, REMOTE_AGENT_RESOURCE_PREFIXES } =\n await import(\"../resources/metadata.js\");\n\n const resources: Array<{ id: string; path: string }> = [];\n for (const prefix of [...REMOTE_AGENT_RESOURCE_PREFIXES].reverse()) {\n resources.push(...(await resourceList(SHARED_OWNER, prefix)));\n }\n\n for (const r of resources) {\n if (!r.path.endsWith(\".json\")) continue;\n try {\n const full = await resourceGet(r.id);\n if (!full) continue;\n const manifest = parseRemoteAgentManifest(full.content, r.path);\n if (!manifest || !shouldIncludeRemoteAgentManifest(manifest, selfAppId))\n continue;\n\n // If the resource override carries a localhost URL but we're running\n // in production (e.g. a stale dev-time seed got promoted to the prod\n // DB), fall back to the matching built-in's prod URL instead of\n // letting the override win — otherwise outbound `call-agent` fetches\n // from a serverless function would target localhost and fail with\n // \"fetch failed\" instantly. The override still wins for non-localhost\n // URLs (the supported case for self-hosted custom agents).\n let url = manifest.url;\n const isProduction =\n typeof process !== \"undefined\" &&\n process.env?.NODE_ENV === \"production\";\n if (\n isProduction &&\n typeof url === \"string\" &&\n /^https?:\\/\\/(localhost|127\\.0\\.0\\.1|0\\.0\\.0\\.0)(:|\\/|$)/.test(url)\n ) {\n const builtin = agentsById.get(manifest.id);\n if (builtin?.url) url = builtin.url;\n }\n\n agentsById.set(manifest.id, {\n id: manifest.id,\n name: manifest.name,\n description: manifest.description || \"\",\n url,\n color: manifest.color || \"#6B7280\",\n });\n } catch {\n // Skip unreadable resources\n }\n }\n } catch {\n // Resources not available — use built-ins only\n }\n\n // Overlay sibling workspace apps last so same-origin workspaces prefer the\n // app mounted in this workspace over the public template with the same id.\n for (const agent of discoverWorkspaceAgents(selfAppId)) {\n agentsById.set(agent.id, agent);\n }\n\n return Array.from(agentsById.values());\n}\n\n/**\n * Look up a single agent by ID or name (case-insensitive).\n */\nexport async function findAgent(\n idOrName: string,\n selfAppId?: string,\n): Promise<DiscoveredAgent | undefined> {\n const lower = idOrName.toLowerCase();\n const agents = await discoverAgents(selfAppId);\n return agents.find((a) => a.id === lower || a.name.toLowerCase() === lower);\n}\n\nfunction isDevEnvironment(): boolean {\n return (\n typeof process !== \"undefined\" && process.env?.NODE_ENV !== \"production\"\n );\n}\n\nfunction resolveAgentUrl(app: AgentEntry): string {\n if (isDevEnvironment()) {\n return app.devUrl || `http://localhost:${app.devPort}`;\n }\n return app.url;\n}\n\nfunction readJson(file: string): any {\n try {\n return JSON.parse(fs.readFileSync(file, \"utf8\"));\n } catch {\n return null;\n }\n}\n\nfunction findWorkspaceRoot(startDir = process.cwd()): string | null {\n let dir = path.resolve(startDir);\n for (let i = 0; i < 20; i++) {\n const pkg = readJson(path.join(dir, \"package.json\"));\n if (typeof pkg?.[\"agent-native\"]?.workspaceCore === \"string\") {\n return dir;\n }\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n return null;\n}\n\nfunction titleCase(value: string): string {\n return value\n .split(/[-_\\s]+/)\n .filter(Boolean)\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \");\n}\n\nfunction parseWorkspaceAppsManifest(\n parsed: any,\n): WorkspaceAppManifestEntry[] | null {\n const rawApps = Array.isArray(parsed?.apps)\n ? parsed.apps\n : Array.isArray(parsed)\n ? parsed\n : null;\n if (!rawApps) return null;\n\n const apps = rawApps\n .map((entry) => {\n if (!entry || typeof entry !== \"object\") return null;\n const id = typeof entry.id === \"string\" ? entry.id.trim() : \"\";\n const pathValue = typeof entry.path === \"string\" ? entry.path.trim() : \"\";\n if (!id || !pathValue.startsWith(\"/\")) return null;\n return {\n id,\n name:\n typeof entry.name === \"string\" && entry.name.trim()\n ? entry.name.trim()\n : titleCase(id),\n description:\n typeof entry.description === \"string\" ? entry.description : \"\",\n path: pathValue,\n url:\n typeof entry.url === \"string\" && entry.url.trim()\n ? entry.url.trim()\n : null,\n isDispatch:\n typeof entry.isDispatch === \"boolean\"\n ? entry.isDispatch\n : id === \"dispatch\",\n } satisfies WorkspaceAppManifestEntry;\n })\n .filter((app): app is WorkspaceAppManifestEntry => !!app)\n .sort((a, b) => {\n if (a.id === \"dispatch\") return -1;\n if (b.id === \"dispatch\") return 1;\n return a.name.localeCompare(b.name);\n });\n\n return apps.length ? apps : null;\n}\n\nfunction readWorkspaceAppsFromEnv(): WorkspaceAppManifestEntry[] | null {\n const raw = process.env[WORKSPACE_APPS_ENV_KEY];\n if (!raw) return null;\n try {\n return parseWorkspaceAppsManifest(JSON.parse(raw));\n } catch {\n return null;\n }\n}\n\nfunction workspaceAppsManifestCandidates(): string[] {\n const candidates: string[] = [];\n try {\n candidates.push(\n path.join(process.cwd(), \".agent-native\", WORKSPACE_APPS_MANIFEST_FILE),\n path.join(process.cwd(), WORKSPACE_APPS_MANIFEST_FILE),\n );\n } catch {\n // Some edge runtimes do not expose process.cwd().\n }\n try {\n const moduleDir = path.dirname(fileURLToPath(import.meta.url));\n candidates.push(\n path.join(moduleDir, \".agent-native\", WORKSPACE_APPS_MANIFEST_FILE),\n path.join(moduleDir, WORKSPACE_APPS_MANIFEST_FILE),\n );\n } catch {\n // Some edge runtimes expose non-file module URLs. The env manifest still\n // works there, so skip file-relative candidates.\n }\n return candidates;\n}\n\nfunction readWorkspaceAppsFromManifestFile():\n | WorkspaceAppManifestEntry[]\n | null {\n for (const file of workspaceAppsManifestCandidates()) {\n if (!fs.existsSync(file)) continue;\n const apps = parseWorkspaceAppsManifest(readJson(file));\n if (apps) return apps;\n }\n return null;\n}\n\nfunction readWorkspaceAppsFromFilesystem(): WorkspaceAppManifestEntry[] | null {\n const workspaceRoot = findWorkspaceRoot();\n if (!workspaceRoot) return null;\n const appsDir = path.join(workspaceRoot, \"apps\");\n if (!fs.existsSync(appsDir)) return null;\n\n const apps = fs\n .readdirSync(appsDir, { withFileTypes: true })\n .filter((entry) => entry.isDirectory())\n .map((entry): WorkspaceAppManifestEntry | null => {\n const appDir = path.join(appsDir, entry.name);\n const pkg = readJson(path.join(appDir, \"package.json\"));\n if (!pkg) return null;\n return {\n id: entry.name,\n name: pkg.displayName || titleCase(entry.name),\n description: pkg.description || \"\",\n path: `/${entry.name}`,\n isDispatch: entry.name === \"dispatch\",\n } satisfies WorkspaceAppManifestEntry;\n })\n .filter((app): app is WorkspaceAppManifestEntry => !!app)\n .sort((a, b) => {\n if (a.id === \"dispatch\") return -1;\n if (b.id === \"dispatch\") return 1;\n return a.name.localeCompare(b.name);\n });\n\n return apps.length ? apps : null;\n}\n\nfunction workspaceBaseUrl(): string | null {\n return (\n process.env.WORKSPACE_GATEWAY_URL ||\n process.env.APP_URL ||\n process.env.URL ||\n process.env.DEPLOY_URL ||\n process.env.BETTER_AUTH_URL ||\n null\n );\n}\n\nfunction workspaceAppUrl(app: WorkspaceAppManifestEntry): string | null {\n if (app.url) return app.url;\n const base = workspaceBaseUrl();\n if (!base) return null;\n try {\n return new URL(app.path, `${base.replace(/\\/$/, \"\")}/`).toString();\n } catch {\n return null;\n }\n}\n\nfunction discoverWorkspaceAgents(selfAppId?: string): DiscoveredAgent[] {\n const workspaceApps =\n readWorkspaceAppsFromEnv() ??\n readWorkspaceAppsFromManifestFile() ??\n readWorkspaceAppsFromFilesystem();\n if (!workspaceApps) return [];\n\n return workspaceApps\n .filter((app) => app.id !== selfAppId)\n .map((app) => {\n const url = workspaceAppUrl(app);\n if (!url) return null;\n const builtin = BUILTIN_AGENTS.find((agent) => agent.id === app.id);\n return {\n id: app.id,\n name: app.name,\n description:\n app.description ||\n builtin?.description ||\n `Workspace app mounted at ${app.path}`,\n url,\n color: builtin?.color || \"#6B7280\",\n } satisfies DiscoveredAgent;\n })\n .filter((agent): agent is DiscoveredAgent => !!agent);\n}\n\n/**\n * Like `getBuiltinAgents`, but always returns the production URL — never the\n * env-resolved devUrl. Used by the resource seeder so that a one-time seed\n * (`ON CONFLICT DO NOTHING`) can't permanently bake a localhost URL into the\n * DB, which would override the built-in's prod URL for every later\n * production deploy.\n */\nexport const BUILTIN_AGENTS_FOR_SEEDING: DiscoveredAgent[] =\n BUILTIN_AGENTS.filter((app) => app.url).map((app) => ({\n id: app.id,\n name: app.name,\n description: app.description,\n url: app.url, // ALWAYS prod\n color: app.color,\n }));\n"]}
|
|
1
|
+
{"version":3,"file":"agent-discovery.js","sourceRoot":"","sources":["../../src/server/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MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC;QACpE,OAAO;YACL,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,WAAW,EACT,GAAG,CAAC,WAAW;gBACf,OAAO,EAAE,WAAW;gBACpB,4BAA4B,GAAG,CAAC,IAAI,EAAE;YACxC,GAAG;YACH,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,SAAS;SACT,CAAC;IAC9B,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,KAAK,EAA4B,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,0BAA0B,GACrC,cAAc,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACpD,EAAE,EAAE,GAAG,CAAC,EAAE;IACV,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,WAAW,EAAE,GAAG,CAAC,WAAW;IAC5B,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,cAAc;IAC5B,KAAK,EAAE,GAAG,CAAC,KAAK;CACjB,CAAC,CAAC,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { TEMPLATES } from \"../cli/templates-meta.js\";\n\nexport interface DiscoveredAgent {\n id: string;\n name: string;\n description: string;\n url: string;\n color: string;\n}\n\ninterface AgentEntry {\n id: string;\n name: string;\n description: string;\n url: string;\n devUrl?: string;\n devPort: number;\n color: string;\n}\n\n/**\n * Built-in agent registry. Derive this from the published CLI metadata so\n * connected-agent discovery stays aligned with first-party template metadata\n * without depending on @agent-native/shared-app-config at runtime.\n */\nconst BUILTIN_AGENTS: AgentEntry[] = TEMPLATES.filter(\n (template) =>\n (!template.hidden || template.defaultAgent) && !!template.prodUrl,\n).map((template) => ({\n id: template.name,\n name: template.label,\n description: template.description ?? template.hint,\n url: template.prodUrl!,\n devUrl: `http://localhost:${template.devPort}`,\n devPort: template.devPort,\n color: template.color,\n}));\n\nconst HIDDEN_FIRST_PARTY_AGENT_IDS = new Set(\n TEMPLATES.filter(\n (template) => template.hidden && !template.defaultAgent && template.prodUrl,\n ).map((template) => template.name),\n);\n\nconst WORKSPACE_APPS_ENV_KEY = \"AGENT_NATIVE_WORKSPACE_APPS_JSON\";\nconst WORKSPACE_APPS_MANIFEST_FILE = \"workspace-apps.json\";\n\nexport interface WorkspaceAppManifestEntry {\n id: string;\n name: string;\n description: string;\n path: string;\n url?: string | null;\n isDispatch?: boolean;\n}\n\n/**\n * Resolve the workspace app manifest from the same fallback chain that\n * `discoverWorkspaceAgents` uses: `AGENT_NATIVE_WORKSPACE_APPS_JSON` env →\n * `.agent-native/workspace-apps.json` (or sibling) on disk → live filesystem\n * scan of `apps/<id>/package.json` under the workspace root.\n *\n * Callers (e.g. the dispatch `/dispatch/<appId>` catch-all loader) need this\n * to behave the same in production deploys (which write the manifest file)\n * and during local dev (where new apps appear under `apps/` without an env\n * restart). Reading only the env var would silently downgrade the behavior\n * in both cases.\n */\nexport function loadWorkspaceAppsManifest():\n | WorkspaceAppManifestEntry[]\n | null {\n return (\n readWorkspaceAppsFromEnv() ??\n readWorkspaceAppsFromManifestFile() ??\n readWorkspaceAppsFromFilesystem()\n );\n}\n\nexport function shouldIncludeRemoteAgentManifest(\n manifest: { id?: string | null },\n selfAppId?: string,\n): boolean {\n const id = manifest.id?.trim();\n if (!id) return false;\n const normalizedId = id.toLowerCase();\n const normalizedSelfAppId = selfAppId?.trim().toLowerCase();\n if (normalizedSelfAppId && normalizedId === normalizedSelfAppId) {\n return false;\n }\n return !HIDDEN_FIRST_PARTY_AGENT_IDS.has(normalizedId);\n}\n\n/**\n * Get built-in agents (static, no DB). Used as fallback and for seeding.\n */\nexport function getBuiltinAgents(selfAppId?: string): DiscoveredAgent[] {\n return BUILTIN_AGENTS.filter((app) => app.id !== selfAppId && app.url).map(\n (app) => ({\n id: app.id,\n name: app.name,\n description: app.description,\n url: resolveAgentUrl(app),\n color: app.color,\n }),\n );\n}\n\n/**\n * Discover all agents: built-in + custom agents stored as resources.\n * Custom agents override built-in agents with the same ID.\n */\nexport async function discoverAgents(\n selfAppId?: string,\n): Promise<DiscoveredAgent[]> {\n const builtins = getBuiltinAgents(selfAppId);\n const agentsById = new Map<string, DiscoveredAgent>();\n\n // Start with built-ins\n for (const agent of builtins) {\n agentsById.set(agent.id, agent);\n }\n\n // Overlay custom agents from resources\n try {\n const { resourceList, resourceGet, SHARED_OWNER } =\n await import(\"../resources/store.js\");\n\n const { parseRemoteAgentManifest, REMOTE_AGENT_RESOURCE_PREFIXES } =\n await import(\"../resources/metadata.js\");\n\n const resources: Array<{ id: string; path: string }> = [];\n for (const prefix of [...REMOTE_AGENT_RESOURCE_PREFIXES].reverse()) {\n resources.push(...(await resourceList(SHARED_OWNER, prefix)));\n }\n\n for (const r of resources) {\n if (!r.path.endsWith(\".json\")) continue;\n try {\n const full = await resourceGet(r.id);\n if (!full) continue;\n const manifest = parseRemoteAgentManifest(full.content, r.path);\n if (!manifest || !shouldIncludeRemoteAgentManifest(manifest, selfAppId))\n continue;\n\n // If the resource override carries a localhost URL but we're running\n // in production (e.g. a stale dev-time seed got promoted to the prod\n // DB), fall back to the matching built-in's prod URL instead of\n // letting the override win — otherwise outbound `call-agent` fetches\n // from a serverless function would target localhost and fail with\n // \"fetch failed\" instantly. The override still wins for non-localhost\n // URLs (the supported case for self-hosted custom agents).\n let url = manifest.url;\n const isProduction =\n typeof process !== \"undefined\" &&\n process.env?.NODE_ENV === \"production\";\n if (\n isProduction &&\n typeof url === \"string\" &&\n /^https?:\\/\\/(localhost|127\\.0\\.0\\.1|0\\.0\\.0\\.0)(:|\\/|$)/.test(url)\n ) {\n const builtin = agentsById.get(manifest.id);\n if (builtin?.url) url = builtin.url;\n }\n\n agentsById.set(manifest.id, {\n id: manifest.id,\n name: manifest.name,\n description: manifest.description || \"\",\n url,\n color: manifest.color || \"#6B7280\",\n });\n } catch {\n // Skip unreadable resources\n }\n }\n } catch {\n // Resources not available — use built-ins only\n }\n\n // Overlay sibling workspace apps last so same-origin workspaces prefer the\n // app mounted in this workspace over the public template with the same id.\n for (const agent of discoverWorkspaceAgents(selfAppId)) {\n agentsById.set(agent.id, agent);\n }\n\n return Array.from(agentsById.values());\n}\n\n/**\n * Look up a single agent by ID or name (case-insensitive).\n */\nexport async function findAgent(\n idOrName: string,\n selfAppId?: string,\n): Promise<DiscoveredAgent | undefined> {\n const lower = idOrName.toLowerCase();\n const agents = await discoverAgents(selfAppId);\n return agents.find((a) => a.id === lower || a.name.toLowerCase() === lower);\n}\n\nfunction isDevEnvironment(): boolean {\n return (\n typeof process !== \"undefined\" && process.env?.NODE_ENV !== \"production\"\n );\n}\n\nfunction resolveAgentUrl(app: AgentEntry): string {\n if (isDevEnvironment()) {\n return app.devUrl || `http://localhost:${app.devPort}`;\n }\n return app.url;\n}\n\nfunction readJson(file: string): any {\n try {\n return JSON.parse(fs.readFileSync(file, \"utf8\"));\n } catch {\n return null;\n }\n}\n\nfunction findWorkspaceRoot(startDir = process.cwd()): string | null {\n let dir = path.resolve(startDir);\n for (let i = 0; i < 20; i++) {\n const pkg = readJson(path.join(dir, \"package.json\"));\n if (typeof pkg?.[\"agent-native\"]?.workspaceCore === \"string\") {\n return dir;\n }\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n return null;\n}\n\nfunction titleCase(value: string): string {\n return value\n .split(/[-_\\s]+/)\n .filter(Boolean)\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \");\n}\n\nfunction parseWorkspaceAppsManifest(\n parsed: any,\n): WorkspaceAppManifestEntry[] | null {\n const rawApps = Array.isArray(parsed?.apps)\n ? parsed.apps\n : Array.isArray(parsed)\n ? parsed\n : null;\n if (!rawApps) return null;\n\n const apps = rawApps\n .map((entry) => {\n if (!entry || typeof entry !== \"object\") return null;\n const id = typeof entry.id === \"string\" ? entry.id.trim() : \"\";\n const pathValue = typeof entry.path === \"string\" ? entry.path.trim() : \"\";\n if (!id || !pathValue.startsWith(\"/\")) return null;\n return {\n id,\n name:\n typeof entry.name === \"string\" && entry.name.trim()\n ? entry.name.trim()\n : titleCase(id),\n description:\n typeof entry.description === \"string\" ? entry.description : \"\",\n path: pathValue,\n url:\n typeof entry.url === \"string\" && entry.url.trim()\n ? entry.url.trim()\n : null,\n isDispatch:\n typeof entry.isDispatch === \"boolean\"\n ? entry.isDispatch\n : id === \"dispatch\",\n } satisfies WorkspaceAppManifestEntry;\n })\n .filter((app): app is WorkspaceAppManifestEntry => !!app)\n .sort((a, b) => {\n if (a.id === \"dispatch\") return -1;\n if (b.id === \"dispatch\") return 1;\n return a.name.localeCompare(b.name);\n });\n\n return apps.length ? apps : null;\n}\n\nfunction readWorkspaceAppsFromEnv(): WorkspaceAppManifestEntry[] | null {\n const raw = process.env[WORKSPACE_APPS_ENV_KEY];\n if (!raw) return null;\n try {\n return parseWorkspaceAppsManifest(JSON.parse(raw));\n } catch {\n return null;\n }\n}\n\nfunction workspaceAppsManifestCandidates(): string[] {\n const candidates: string[] = [];\n try {\n candidates.push(\n path.join(process.cwd(), \".agent-native\", WORKSPACE_APPS_MANIFEST_FILE),\n path.join(process.cwd(), WORKSPACE_APPS_MANIFEST_FILE),\n );\n } catch {\n // Some edge runtimes do not expose process.cwd().\n }\n try {\n const moduleDir = path.dirname(fileURLToPath(import.meta.url));\n candidates.push(\n path.join(moduleDir, \".agent-native\", WORKSPACE_APPS_MANIFEST_FILE),\n path.join(moduleDir, WORKSPACE_APPS_MANIFEST_FILE),\n );\n } catch {\n // Some edge runtimes expose non-file module URLs. The env manifest still\n // works there, so skip file-relative candidates.\n }\n return candidates;\n}\n\nfunction readWorkspaceAppsFromManifestFile():\n | WorkspaceAppManifestEntry[]\n | null {\n for (const file of workspaceAppsManifestCandidates()) {\n if (!fs.existsSync(file)) continue;\n const apps = parseWorkspaceAppsManifest(readJson(file));\n if (apps) return apps;\n }\n return null;\n}\n\nfunction readWorkspaceAppsFromFilesystem(): WorkspaceAppManifestEntry[] | null {\n const workspaceRoot = findWorkspaceRoot();\n if (!workspaceRoot) return null;\n const appsDir = path.join(workspaceRoot, \"apps\");\n if (!fs.existsSync(appsDir)) return null;\n\n const apps = fs\n .readdirSync(appsDir, { withFileTypes: true })\n .filter((entry) => entry.isDirectory())\n .map((entry): WorkspaceAppManifestEntry | null => {\n const appDir = path.join(appsDir, entry.name);\n const pkg = readJson(path.join(appDir, \"package.json\"));\n if (!pkg) return null;\n return {\n id: entry.name,\n name: pkg.displayName || titleCase(entry.name),\n description: pkg.description || \"\",\n path: `/${entry.name}`,\n isDispatch: entry.name === \"dispatch\",\n } satisfies WorkspaceAppManifestEntry;\n })\n .filter((app): app is WorkspaceAppManifestEntry => !!app)\n .sort((a, b) => {\n if (a.id === \"dispatch\") return -1;\n if (b.id === \"dispatch\") return 1;\n return a.name.localeCompare(b.name);\n });\n\n return apps.length ? apps : null;\n}\n\nfunction workspaceBaseUrl(): string | null {\n return (\n process.env.WORKSPACE_GATEWAY_URL ||\n process.env.APP_URL ||\n process.env.URL ||\n process.env.DEPLOY_URL ||\n process.env.BETTER_AUTH_URL ||\n null\n );\n}\n\nfunction workspaceAppUrl(app: WorkspaceAppManifestEntry): string | null {\n if (app.url) return app.url;\n const base = workspaceBaseUrl();\n if (!base) return null;\n try {\n return new URL(app.path, `${base.replace(/\\/$/, \"\")}/`).toString();\n } catch {\n return null;\n }\n}\n\nfunction discoverWorkspaceAgents(selfAppId?: string): DiscoveredAgent[] {\n const workspaceApps = loadWorkspaceAppsManifest();\n if (!workspaceApps) return [];\n\n return workspaceApps\n .filter((app) => app.id !== selfAppId)\n .map((app) => {\n const url = workspaceAppUrl(app);\n if (!url) return null;\n const builtin = BUILTIN_AGENTS.find((agent) => agent.id === app.id);\n return {\n id: app.id,\n name: app.name,\n description:\n app.description ||\n builtin?.description ||\n `Workspace app mounted at ${app.path}`,\n url,\n color: builtin?.color || \"#6B7280\",\n } satisfies DiscoveredAgent;\n })\n .filter((agent): agent is DiscoveredAgent => !!agent);\n}\n\n/**\n * Like `getBuiltinAgents`, but always returns the production URL — never the\n * env-resolved devUrl. Used by the resource seeder so that a one-time seed\n * (`ON CONFLICT DO NOTHING`) can't permanently bake a localhost URL into the\n * DB, which would override the built-in's prod URL for every later\n * production deploy.\n */\nexport const BUILTIN_AGENTS_FOR_SEEDING: DiscoveredAgent[] =\n BUILTIN_AGENTS.filter((app) => app.url).map((app) => ({\n id: app.id,\n name: app.name,\n description: app.description,\n url: app.url, // ALWAYS prod\n color: app.color,\n }));\n"]}
|
package/dist/server/auth.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { H3Event } from "h3";
|
|
|
2
2
|
import type { H3AppShim } from "./framework-request-handler.js";
|
|
3
3
|
type H3App = H3AppShim;
|
|
4
4
|
import type { BetterAuthConfig } from "./better-auth-instance.js";
|
|
5
|
+
import type { GoogleAuthMode } from "./google-auth-mode.js";
|
|
5
6
|
/**
|
|
6
7
|
* Get the configured session max age. Desktop SSO broker writes from
|
|
7
8
|
* OAuth flows read this so expiration stays consistent with the cookie.
|
|
@@ -97,12 +98,38 @@ export interface AuthOptions {
|
|
|
97
98
|
continueLabel?: string;
|
|
98
99
|
cancelLabel?: string;
|
|
99
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* Google sign-in flow: `'popup'`, `'redirect'`, or `'auto'` (default).
|
|
103
|
+
*
|
|
104
|
+
* - `'auto'` — popup in normal browsers, redirect in Electron. Always uses
|
|
105
|
+
* popup inside the Builder.io browser iframe (Google blocks framing).
|
|
106
|
+
* - `'popup'` — force popup everywhere.
|
|
107
|
+
* - `'redirect'` — force redirect everywhere except the Builder.io browser
|
|
108
|
+
* iframe, which stays popup for technical reasons.
|
|
109
|
+
*
|
|
110
|
+
* Falls back to the `GOOGLE_AUTH_MODE` env var, then `'auto'`.
|
|
111
|
+
*/
|
|
112
|
+
googleAuthMode?: GoogleAuthMode;
|
|
100
113
|
/**
|
|
101
114
|
* Additional Better Auth configuration (social providers, plugins, etc.)
|
|
102
115
|
*/
|
|
103
116
|
betterAuth?: BetterAuthConfig;
|
|
104
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* When set, the framework session cookie is shared across every subdomain
|
|
120
|
+
* matching this domain (e.g. `.agent-native.com`). Reads `COOKIE_DOMAIN`.
|
|
121
|
+
* Returns undefined when unset so cookies stay scoped to the origin host.
|
|
122
|
+
*/
|
|
123
|
+
export declare function getCookieDomain(): string | undefined;
|
|
105
124
|
export declare const COOKIE_NAME: string;
|
|
125
|
+
/**
|
|
126
|
+
* Cookie domain attribute spread into every `setCookie`/`deleteCookie`.
|
|
127
|
+
* Empty when `COOKIE_DOMAIN` isn't set so the cookie stays scoped to the
|
|
128
|
+
* single origin (current production default for non-first-party apps).
|
|
129
|
+
*/
|
|
130
|
+
export declare function cookieDomainAttrs(): {
|
|
131
|
+
domain?: string;
|
|
132
|
+
};
|
|
106
133
|
/**
|
|
107
134
|
* Check if we're in a development/test environment.
|
|
108
135
|
* Used for cookie security settings, not for auth bypass.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/server/auth.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAsChE,KAAK,KAAK,GAAG,SAAS,CAAC;AAQvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/server/auth.ts"],"names":[],"mappings":"AAcA,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AC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAmBD,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,QAWd;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,2BAA2B,QAOnC;AAmGD;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,CAG5C;AAwUD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CA6E5E;AA0CD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAQ7E;AAkyCD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,KAAK,EACV,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,OAAO,CAAC,CAqKlB;AAMD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAEzE"}
|
package/dist/server/auth.js
CHANGED
|
@@ -64,14 +64,58 @@ export function getSessionMaxAge() {
|
|
|
64
64
|
* `an_session` cookie and ping-pong each other into a logged-out state.
|
|
65
65
|
*
|
|
66
66
|
* When `APP_NAME` is set, suffix the cookie so each app gets its own slot.
|
|
67
|
+
*
|
|
68
|
+
* Workspace exception: in workspace mode (`AGENT_NATIVE_WORKSPACE=1`),
|
|
69
|
+
* every app shares the same origin AND the same DB, and cross-app SSO is
|
|
70
|
+
* the desired behavior — signing into Dispatch should mean you're signed
|
|
71
|
+
* in across the workspace's other apps too. Per-app suffixes break that.
|
|
72
|
+
* Use a single workspace-wide cookie so the legacy `an_session_*` token
|
|
73
|
+
* flow set by `setFrameworkSessionCookie` (which the Builder OAuth popup
|
|
74
|
+
* exchange relies on — see `desktop-exchange` and `oauthCallbackResponse`)
|
|
75
|
+
* is recognised by every app in the workspace.
|
|
76
|
+
*
|
|
77
|
+
* Cross-subdomain exception: when `COOKIE_DOMAIN` is set (e.g.
|
|
78
|
+
* `.agent-native.com` for first-party deploys where each app is its own
|
|
79
|
+
* subdomain — mail.agent-native.com, calendar.agent-native.com, …),
|
|
80
|
+
* use the unsuffixed `an_session` and emit `Domain=<COOKIE_DOMAIN>` so
|
|
81
|
+
* the cookie is shared across every subdomain. Signing into one app
|
|
82
|
+
* signs the user into all of them. Per-app suffixes would defeat the
|
|
83
|
+
* shared cookie since each subdomain reads a different name.
|
|
67
84
|
*/
|
|
68
85
|
const APP_NAME_SLUG = (process.env.APP_NAME || "")
|
|
69
86
|
.toLowerCase()
|
|
70
87
|
.replace(/[^a-z0-9]+/g, "_")
|
|
71
88
|
.replace(/^_+|_+$/g, "");
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
89
|
+
const IS_WORKSPACE_MODE = process.env.AGENT_NATIVE_WORKSPACE === "1";
|
|
90
|
+
/**
|
|
91
|
+
* When set, the framework session cookie is shared across every subdomain
|
|
92
|
+
* matching this domain (e.g. `.agent-native.com`). Reads `COOKIE_DOMAIN`.
|
|
93
|
+
* Returns undefined when unset so cookies stay scoped to the origin host.
|
|
94
|
+
*/
|
|
95
|
+
export function getCookieDomain() {
|
|
96
|
+
const raw = process.env.COOKIE_DOMAIN;
|
|
97
|
+
if (!raw)
|
|
98
|
+
return undefined;
|
|
99
|
+
const trimmed = raw.trim();
|
|
100
|
+
return trimmed || undefined;
|
|
101
|
+
}
|
|
102
|
+
const HAS_COOKIE_DOMAIN = !!getCookieDomain();
|
|
103
|
+
export const COOKIE_NAME = HAS_COOKIE_DOMAIN
|
|
104
|
+
? "an_session"
|
|
105
|
+
: IS_WORKSPACE_MODE
|
|
106
|
+
? "an_session_workspace"
|
|
107
|
+
: APP_NAME_SLUG
|
|
108
|
+
? `an_session_${APP_NAME_SLUG}`
|
|
109
|
+
: "an_session";
|
|
110
|
+
/**
|
|
111
|
+
* Cookie domain attribute spread into every `setCookie`/`deleteCookie`.
|
|
112
|
+
* Empty when `COOKIE_DOMAIN` isn't set so the cookie stays scoped to the
|
|
113
|
+
* single origin (current production default for non-first-party apps).
|
|
114
|
+
*/
|
|
115
|
+
export function cookieDomainAttrs() {
|
|
116
|
+
const domain = getCookieDomain();
|
|
117
|
+
return domain ? { domain } : {};
|
|
118
|
+
}
|
|
75
119
|
function getOAuthStateAppId() {
|
|
76
120
|
const raw = process.env.APP_NAME || process.env.npm_package_name;
|
|
77
121
|
if (!raw)
|
|
@@ -914,19 +958,27 @@ function isReadMethod(event) {
|
|
|
914
958
|
}
|
|
915
959
|
/**
|
|
916
960
|
* Cookie attributes that work in both same-site and third-party iframe
|
|
917
|
-
* contexts. Over HTTPS we emit `SameSite=None; Secure`
|
|
918
|
-
* to ship the cookie back inside a
|
|
919
|
-
*
|
|
961
|
+
* contexts. Over HTTPS we emit `SameSite=None; Secure; Partitioned` —
|
|
962
|
+
* `None`+`Secure` is required by browsers to ship the cookie back inside a
|
|
963
|
+
* cross-origin iframe at all; `Partitioned` keeps the cookie working under
|
|
964
|
+
* Chrome's third-party-cookie deprecation by binding it to the embedding
|
|
965
|
+
* site's storage partition. (Better Auth already sets the same trio on its
|
|
966
|
+
* own session cookie; this matches so the framework's legacy cookie —
|
|
967
|
+
* which the Builder OAuth popup exchange writes via
|
|
968
|
+
* `setFrameworkSessionCookie` — survives iframe contexts too.) Plain-HTTP
|
|
969
|
+
* dev keeps the default `SameSite=Lax`; `None` requires Secure, and
|
|
970
|
+
* `Partitioned` only takes effect alongside `Secure`.
|
|
920
971
|
*/
|
|
921
972
|
function crossSiteCookieAttrs(event) {
|
|
922
973
|
return isHttpsRequest(event)
|
|
923
|
-
? { sameSite: "none", secure: true }
|
|
974
|
+
? { sameSite: "none", secure: true, partitioned: true }
|
|
924
975
|
: { sameSite: "lax", secure: false };
|
|
925
976
|
}
|
|
926
977
|
export function setFrameworkSessionCookie(event, token) {
|
|
927
978
|
setCookie(event, COOKIE_NAME, token, {
|
|
928
979
|
httpOnly: true,
|
|
929
980
|
...crossSiteCookieAttrs(event),
|
|
981
|
+
...cookieDomainAttrs(),
|
|
930
982
|
path: "/",
|
|
931
983
|
maxAge: sessionMaxAge,
|
|
932
984
|
});
|
|
@@ -1738,6 +1790,7 @@ async function mountBetterAuthRoutes(app, options) {
|
|
|
1738
1790
|
setCookie(event, COOKIE_NAME, sessionToken, {
|
|
1739
1791
|
httpOnly: true,
|
|
1740
1792
|
...crossSiteCookieAttrs(event),
|
|
1793
|
+
...cookieDomainAttrs(),
|
|
1741
1794
|
path: "/",
|
|
1742
1795
|
maxAge: sessionMaxAge,
|
|
1743
1796
|
});
|
|
@@ -1758,6 +1811,7 @@ async function mountBetterAuthRoutes(app, options) {
|
|
|
1758
1811
|
setCookie(event, COOKIE_NAME, result.token, {
|
|
1759
1812
|
httpOnly: true,
|
|
1760
1813
|
...crossSiteCookieAttrs(event),
|
|
1814
|
+
...cookieDomainAttrs(),
|
|
1761
1815
|
path: "/",
|
|
1762
1816
|
maxAge: sessionMaxAge,
|
|
1763
1817
|
});
|
|
@@ -1829,7 +1883,7 @@ async function mountBetterAuthRoutes(app, options) {
|
|
|
1829
1883
|
const bearerToken = getBearerSessionToken(event);
|
|
1830
1884
|
if (bearerToken)
|
|
1831
1885
|
await removeSession(bearerToken);
|
|
1832
|
-
deleteCookie(event, COOKIE_NAME, { path: "/" });
|
|
1886
|
+
deleteCookie(event, COOKIE_NAME, { path: "/", ...cookieDomainAttrs() });
|
|
1833
1887
|
try {
|
|
1834
1888
|
await auth.api.signOut({ headers: event.headers });
|
|
1835
1889
|
}
|
|
@@ -1892,7 +1946,7 @@ async function mountBetterAuthRoutes(app, options) {
|
|
|
1892
1946
|
}
|
|
1893
1947
|
// 3. Drop the current request's cookie and best-effort sign out
|
|
1894
1948
|
// of Better Auth (so the response sets the proper expiry header).
|
|
1895
|
-
deleteCookie(event, COOKIE_NAME, { path: "/" });
|
|
1949
|
+
deleteCookie(event, COOKIE_NAME, { path: "/", ...cookieDomainAttrs() });
|
|
1896
1950
|
try {
|
|
1897
1951
|
await auth.api.signOut({ headers: event.headers });
|
|
1898
1952
|
}
|
|
@@ -1936,6 +1990,7 @@ async function mountBetterAuthRoutes(app, options) {
|
|
|
1936
1990
|
googleOnly: options.googleOnly,
|
|
1937
1991
|
marketing: options.marketing,
|
|
1938
1992
|
googleSignInNotice: options.googleSignInNotice,
|
|
1993
|
+
googleAuthMode: options.googleAuthMode,
|
|
1939
1994
|
});
|
|
1940
1995
|
_authGuardConfig = { loginHtml, publicPaths };
|
|
1941
1996
|
const guardFn = createAuthGuardFn();
|
|
@@ -1963,6 +2018,7 @@ function mountTokenOnlyRoutes(app, accessTokens, publicPaths = []) {
|
|
|
1963
2018
|
setCookie(event, COOKIE_NAME, sessionToken, {
|
|
1964
2019
|
httpOnly: true,
|
|
1965
2020
|
...crossSiteCookieAttrs(event),
|
|
2021
|
+
...cookieDomainAttrs(),
|
|
1966
2022
|
path: "/",
|
|
1967
2023
|
maxAge: sessionMaxAge,
|
|
1968
2024
|
});
|
|
@@ -1975,7 +2031,7 @@ function mountTokenOnlyRoutes(app, accessTokens, publicPaths = []) {
|
|
|
1975
2031
|
const bearerToken = getBearerSessionToken(event);
|
|
1976
2032
|
if (bearerToken)
|
|
1977
2033
|
await removeSession(bearerToken);
|
|
1978
|
-
deleteCookie(event, COOKIE_NAME, { path: "/" });
|
|
2034
|
+
deleteCookie(event, COOKIE_NAME, { path: "/", ...cookieDomainAttrs() });
|
|
1979
2035
|
if (isElectronRequest(event))
|
|
1980
2036
|
await clearDesktopSso();
|
|
1981
2037
|
return { ok: true };
|
|
@@ -2022,6 +2078,7 @@ function mountAuthFallbackRoutes(app) {
|
|
|
2022
2078
|
setCookie(event, COOKIE_NAME, result.token, {
|
|
2023
2079
|
httpOnly: true,
|
|
2024
2080
|
...crossSiteCookieAttrs(event),
|
|
2081
|
+
...cookieDomainAttrs(),
|
|
2025
2082
|
path: "/",
|
|
2026
2083
|
maxAge: sessionMaxAge,
|
|
2027
2084
|
});
|
|
@@ -2086,7 +2143,7 @@ function mountAuthFallbackRoutes(app) {
|
|
|
2086
2143
|
const bearerToken = getBearerSessionToken(event);
|
|
2087
2144
|
if (bearerToken)
|
|
2088
2145
|
await removeSession(bearerToken);
|
|
2089
|
-
deleteCookie(event, COOKIE_NAME, { path: "/" });
|
|
2146
|
+
deleteCookie(event, COOKIE_NAME, { path: "/", ...cookieDomainAttrs() });
|
|
2090
2147
|
try {
|
|
2091
2148
|
const auth = await getBetterAuth();
|
|
2092
2149
|
await auth.api.signOut({ headers: event.headers });
|
|
@@ -2157,6 +2214,7 @@ export async function autoMountAuth(app, options = {}) {
|
|
|
2157
2214
|
googleOnly: options.googleOnly,
|
|
2158
2215
|
marketing: options.marketing,
|
|
2159
2216
|
googleSignInNotice: options.googleSignInNotice,
|
|
2217
|
+
googleAuthMode: options.googleAuthMode,
|
|
2160
2218
|
});
|
|
2161
2219
|
}
|
|
2162
2220
|
if (options.publicPaths) {
|
|
@@ -2206,7 +2264,7 @@ export async function autoMountAuth(app, options = {}) {
|
|
|
2206
2264
|
const bearerToken = getBearerSessionToken(event);
|
|
2207
2265
|
if (bearerToken)
|
|
2208
2266
|
await removeSession(bearerToken);
|
|
2209
|
-
deleteCookie(event, COOKIE_NAME, { path: "/" });
|
|
2267
|
+
deleteCookie(event, COOKIE_NAME, { path: "/", ...cookieDomainAttrs() });
|
|
2210
2268
|
if (isElectronRequest(event))
|
|
2211
2269
|
await clearDesktopSso();
|
|
2212
2270
|
return { ok: true };
|
|
@@ -2253,6 +2311,7 @@ export async function autoMountAuth(app, options = {}) {
|
|
|
2253
2311
|
googleOnly: options.googleOnly,
|
|
2254
2312
|
marketing: options.marketing,
|
|
2255
2313
|
googleSignInNotice: options.googleSignInNotice,
|
|
2314
|
+
googleAuthMode: options.googleAuthMode,
|
|
2256
2315
|
});
|
|
2257
2316
|
_authGuardConfig = { loginHtml, publicPaths };
|
|
2258
2317
|
const guardFn = createAuthGuardFn();
|