@agent-native/dispatch 0.30.0 → 0.30.2
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/lib/workspace-apps.d.ts.map +1 -1
- package/dist/lib/workspace-apps.js +3 -1
- package/dist/lib/workspace-apps.js.map +1 -1
- package/dist/lib/workspace-apps.test.js +17 -3
- package/dist/lib/workspace-apps.test.js.map +1 -1
- package/dist/routes/pages/$appId.d.ts.map +1 -1
- package/dist/routes/pages/$appId.js +4 -3
- package/dist/routes/pages/$appId.js.map +1 -1
- package/dist/routes/pages/_index.d.ts.map +1 -1
- package/dist/routes/pages/_index.js +7 -2
- package/dist/routes/pages/_index.js.map +1 -1
- package/dist/routes/pages/_index.test.d.ts +2 -0
- package/dist/routes/pages/_index.test.d.ts.map +1 -0
- package/dist/routes/pages/_index.test.js +29 -0
- package/dist/routes/pages/_index.test.js.map +1 -0
- package/package.json +4 -4
- package/src/components/workspace-app-card.spec.tsx +8 -0
- package/src/components/workspace-app-host.spec.tsx +14 -6
- package/src/lib/workspace-apps.test.ts +20 -2
- package/src/lib/workspace-apps.ts +3 -1
- package/src/routes/pages/$appId.tsx +4 -3
- package/src/routes/pages/_index.test.ts +34 -0
- package/src/routes/pages/_index.tsx +7 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-apps.d.ts","sourceRoot":"","sources":["../../src/lib/workspace-apps.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;IACjC,UAAU,CAAC,EAAE,SAAS,GAAG,KAAK,CA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OAAO,CAGpE;AAED,wBAAgB,uCAAuC,CACrD,GAAG,EAAE,IAAI,CAAC,mBAAmB,EAAE,IAAI,GAAG,YAAY,CAAC,GAClD,OAAO,CAET;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUvE;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,mBAAmB,GAAG,MAAM,GAAG,IAAI,CAUxE;AAED,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,IAAI,CAAC,mBAAmB,EAAE,MAAM,GAAG,KAAK,CAAC,GAC7C;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAMjC;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,sBAAsB,EAC3B,UAAU,EAAE,MAAM,GACjB,MAAM,GAAG,IAAI,CA0Df;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAEtE;AAED,wBAAgB,iCAAiC,IAAI,OAAO,CAK3D;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAgB5D;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,SAAS,mBAAmB,EAAE,GAAG,SAAS,GAC/C,mBAAmB,EAAE,CAiBvB"}
|
|
@@ -181,7 +181,9 @@ export function isPendingBuilderHref(app) {
|
|
|
181
181
|
export function shouldOpenWorkspaceAppInTopWindow() {
|
|
182
182
|
if (typeof window === "undefined")
|
|
183
183
|
return false;
|
|
184
|
-
|
|
184
|
+
// A generic iframe is an inline host by design. Only Builder owns the
|
|
185
|
+
// parent navigation contract for workspace apps.
|
|
186
|
+
return isInBuilderFrame();
|
|
185
187
|
}
|
|
186
188
|
export function navigateToWorkspaceApp(href) {
|
|
187
189
|
if (typeof window === "undefined")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-apps.js","sourceRoot":"","sources":["../../src/lib/workspace-apps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,4BAA4B,EAAE,MAAM,iDAAiD,CAAC;AAE/F,OAAO,EACL,mCAAmC,EACnC,oBAAoB,GACrB,MAAM,yBAAyB,CAAC;AAoCjC,MAAM,UAAU,wBAAwB,CAAC,KAAa;IACpD,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC;AACnD,CAAC;AAED,SAAS,wBAAwB;IAC/B,MAAM,aAAa,GACjB,OAAO,IAGR,CAAC,GAAG,CAAC;IACN,MAAM,UAAU,GACd,UAGD,CAAC,OAAO,EAAE,GAAG,CAAC;IACf,MAAM,GAAG,GAAG,EAAE,GAAG,UAAU,EAAE,GAAG,aAAa,EAAE,CAAC;IAChD,IACE,GAAG,CAAC,IAAI,KAAK,IAAI;QACjB,GAAG,CAAC,IAAI,KAAK,YAAY;QACzB,GAAG,CAAC,QAAQ,KAAK,YAAY,EAC7B,CAAC;QACD,OAAO,YAAY,CAAC;IACtB,CAAC;IACD,IACE,GAAG,CAAC,GAAG,KAAK,IAAI;QAChB,GAAG,CAAC,IAAI,KAAK,aAAa;QAC1B,GAAG,CAAC,IAAI,KAAK,MAAM;QACnB,GAAG,CAAC,QAAQ,KAAK,aAAa;QAC9B,GAAG,CAAC,QAAQ,KAAK,MAAM,EACvB,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC/B,GAA4C;IAE5C,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,EAAE,IAAI,E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,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;QAC5C,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,+EAA+E;QAC/E,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CACzC,IAAgD;IAEhD,MAAM,MAAM,GAAG,IAAI,GAAG,EAA+B,CAAC;IACtD,KAAK,MAAM,EAAE,IAAI,0BAA0B,EAAE,CAAC;QAC5C,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE;YACb,EAAE;YACF,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;YAC9C,qEAAqE;YACrE,mEAAmE;YACnE,iDAAiD;YACjD,IAAI,EAAE,GAAG;YACT,GAAG,EAAE,mCAAmC,CAAC,EAAE,CAAC;YAC5C,MAAM,EAAE,OAAO;SAChB,CAAC,CAAC;IACL,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,IAAI,IAAI,EAAE;QAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAEtD,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import { CHAT_FIRST_DEFAULT_APP_IDS } from \"@agent-native/core/client/chat-first\";\nimport { isInBuilderFrame } from \"@agent-native/core/client/host\";\nimport { withBuilderUtmTrackingParams } from \"@agent-native/core/shared/builder-link-tracking\";\n\nimport {\n CANONICAL_WORKSPACE_SSO_APP_ORIGINS,\n isWorkspaceSsoAppUrl,\n} from \"../shared/workspace-sso\";\n\nexport interface WorkspaceAppSummary {\n id: string;\n name: string;\n description?: string;\n path: string;\n url?: string | null;\n isDispatch?: boolean;\n audience?: \"internal\" | \"public\";\n visibility?: \"private\" | \"org\";\n publicPaths?: string[];\n protectedPaths?: string[];\n status?: \"ready\" | \"pending\";\n statusLabel?: string;\n builderUrl?: string | null;\n branchName?: string | null;\n createdAt?: string | null;\n createdBy?: string | null;\n owner?: string | null;\n teams?: string[];\n agentCardUrl?: string | null;\n agentCardReachable?: boolean;\n a2aEndpointUrl?: string | null;\n agentName?: string | null;\n agentSkillsCount?: number | null;\n archived?: boolean;\n workspaceSso?: boolean;\n}\n\ninterface WorkspaceAppHrefSource {\n path?: string | null;\n url?: string | null;\n workspaceSso?: boolean;\n}\n\nexport function isDispatchWorkspaceAppId(appId: string): boolean {\n return appId.trim().toLowerCase() === \"dispatch\";\n}\n\nfunction clientRuntimeEnvironment(): \"production\" | \"development\" {\n const importMetaEnv = (\n import.meta as unknown as {\n env?: Record<string, string | boolean | undefined>;\n }\n ).env;\n const processEnv = (\n globalThis as typeof globalThis & {\n process?: { env?: Record<string, string | boolean | undefined> };\n }\n ).process?.env;\n const env = { ...processEnv, ...importMetaEnv };\n if (\n env.PROD === true ||\n env.MODE === \"production\" ||\n env.NODE_ENV === \"production\"\n ) {\n return \"production\";\n }\n if (\n env.DEV === true ||\n env.MODE === \"development\" ||\n env.MODE === \"test\" ||\n env.NODE_ENV === \"development\" ||\n env.NODE_ENV === \"test\"\n ) {\n return \"development\";\n }\n return \"production\";\n}\n\n/**\n * The workspace SSO action only accepts an exact registered app identity and\n * origin. The catalog's boolean is a server-derived projection for custom\n * registrations; the URL check keeps malformed metadata out of the action.\n */\nexport function isWorkspaceSsoApp(\n app: WorkspaceAppHrefSource & { id: string },\n): boolean {\n const rawUrl = app.url?.trim();\n if (!rawUrl) return false;\n try {\n const url = new URL(rawUrl);\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\") return false;\n if (app.workspaceSso === true) return true;\n return isWorkspaceSsoAppUrl(\n { id: app.id, url: rawUrl },\n { nodeEnv: clientRuntimeEnvironment() },\n );\n // coercion-ok: malformed app metadata is not eligible for workspace SSO.\n } catch {\n return false;\n }\n}\n\nfunction isCanonicalWorkspaceSsoOrigin(rawUrl: string): boolean {\n try {\n const origin = new URL(rawUrl).origin;\n return Object.values(CANONICAL_WORKSPACE_SSO_APP_ORIGINS).some(\n (canonicalOrigin) => canonicalOrigin === origin,\n );\n } catch {\n // coercion-ok: malformed app metadata is not a canonical first-party app.\n return false;\n }\n}\n\n/**\n * A mounted app URL leaves Dispatch's `/apps/:id` host route. Canonical\n * first-party origins can stay inline even at `/`, while external published\n * apps must open at their own origin regardless of their path.\n */\nexport function isPathMountedWorkspaceApp(\n app: WorkspaceAppHrefSource,\n): boolean {\n const rawUrl = app.url?.trim();\n if (rawUrl) {\n try {\n const pathname = new URL(rawUrl).pathname.replace(/\\/+$/, \"\") || \"/\";\n return pathname !== \"/\" || !isCanonicalWorkspaceSsoOrigin(rawUrl);\n // coercion-ok: invalid absolute URLs use the mounted path fallback.\n } catch {\n // Fall through to the mounted path for relative manifest values.\n }\n }\n const path = app.path?.trim().replace(/\\/+$/, \"\") || \"/\";\n return path !== \"/\";\n}\n\nexport function isDefaultWorkspaceAppHiddenId(appId: string): boolean {\n const normalized = appId.trim().toLowerCase();\n return normalized === \"chat\" || isDispatchWorkspaceAppId(normalized);\n}\n\nexport function isWorkspaceAppVisibleInDefaultLaunchers(\n app: Pick<WorkspaceAppSummary, \"id\" | \"isDispatch\">,\n): boolean {\n return !app.isDispatch && !isDefaultWorkspaceAppHiddenId(app.id);\n}\n\nexport function workspaceAppRoute(appId: string): string {\n return `/apps/${encodeURIComponent(appId)}`;\n}\n\nexport function workspaceAppIdFromRoute(pathname: string): string | null {\n const match = pathname.match(/^\\/apps\\/([^/]+)(?:\\/|$)/);\n if (!match) return null;\n try {\n const appId = decodeURIComponent(match[1]).trim();\n return appId || null;\n } catch {\n // coercion-ok: malformed app routes are inactive, not app ids.\n return null;\n }\n}\n\nexport function workspaceAppHref(app: WorkspaceAppSummary): string | null {\n if (app.status === \"pending\") {\n return app.builderUrl\n ? withBuilderUtmTrackingParams(app.builderUrl, {\n campaign: \"product\",\n content: \"dispatch_branch\",\n })\n : null;\n }\n return app.path || app.url || null;\n}\n\nexport function workspaceAppEmbedTarget(\n app: Pick<WorkspaceAppSummary, \"path\" | \"url\">,\n): { path?: string; url?: string } {\n const url = app.url?.trim();\n if (url) return { url };\n\n const path = app.path.trim();\n return path.startsWith(\"/\") ? { path } : path ? { url: path } : {};\n}\n\n/**\n * Resolve an app route without an embed ticket so the target can render its\n * own error document when session setup fails.\n */\nexport function workspaceAppDirectHref(\n app: WorkspaceAppHrefSource,\n targetPath: string,\n): string | null {\n const target = targetPath.trim();\n if (!target || !target.startsWith(\"/\") || target.startsWith(\"//\")) {\n return null;\n }\n\n let targetUrl: URL;\n try {\n targetUrl = new URL(target, \"https://agent-native.invalid\");\n } catch {\n // coercion-ok: invalid relative target input has no safe href.\n return null;\n }\n const targetPathname = targetUrl.pathname || \"/\";\n\n let absoluteBase: URL | null = null;\n const rawUrl = app.url?.trim();\n if (rawUrl) {\n try {\n const parsedBase = new URL(rawUrl);\n if (parsedBase.protocol === \"http:\" || parsedBase.protocol === \"https:\") {\n absoluteBase = parsedBase;\n }\n // coercion-ok: invalid app URLs use the mounted path fallback below.\n } catch {\n absoluteBase = null;\n }\n }\n\n const mountedPath = app.path?.trim();\n const basePath = absoluteBase\n ? absoluteBase.pathname\n : mountedPath\n ? `/${mountedPath.replace(/^[/\\\\]+/, \"\").split(/[?#]/, 1)[0]}`\n : null;\n if (!basePath) return null;\n\n const normalizedBasePath = basePath.replace(/\\/+$/, \"\") || \"/\";\n const targetIsMountedPath =\n normalizedBasePath !== \"/\" &&\n (targetPathname === normalizedBasePath ||\n targetPathname.startsWith(`${normalizedBasePath}/`));\n const resolvedPath = targetIsMountedPath\n ? targetPathname\n : normalizedBasePath === \"/\"\n ? targetPathname\n : targetPathname === \"/\"\n ? normalizedBasePath\n : `${normalizedBasePath}/${targetPathname.replace(/^\\/+/, \"\")}`;\n\n if (absoluteBase) {\n absoluteBase.pathname = resolvedPath;\n absoluteBase.search = targetUrl.search;\n absoluteBase.hash = targetUrl.hash;\n return absoluteBase.toString();\n }\n\n return `${resolvedPath}${targetUrl.search}${targetUrl.hash}`;\n}\n\nexport function isPendingBuilderHref(app: WorkspaceAppSummary): boolean {\n return app.status === \"pending\" && !!app.builderUrl;\n}\n\nexport function shouldOpenWorkspaceAppInTopWindow(): boolean {\n if (typeof window === \"undefined\") return false;\n return isInBuilderFrame() || window.parent !== window;\n}\n\nexport function navigateToWorkspaceApp(href: string): boolean {\n if (typeof window === \"undefined\") return false;\n\n try {\n const targetUrl = new URL(href, window.location.href);\n if (targetUrl.protocol !== \"http:\" && targetUrl.protocol !== \"https:\") {\n return false;\n }\n const targetWindow =\n shouldOpenWorkspaceAppInTopWindow() && window.top ? window.top : window;\n targetWindow.location.href = targetUrl.href;\n return true;\n } catch {\n // coercion-ok: a blocked top-window assignment is an expected fallback signal.\n return false;\n }\n}\n\n/**\n * Keep the chat-first rail useful before a workspace manifest is populated.\n * Mounted workspace rows still win, so custom names and routes remain the\n * source of truth once an app exists in the workspace.\n */\nexport function mergeChatFirstWorkspaceApps(\n apps: readonly WorkspaceAppSummary[] | undefined,\n): WorkspaceAppSummary[] {\n const merged = new Map<string, WorkspaceAppSummary>();\n for (const id of CHAT_FIRST_DEFAULT_APP_IDS) {\n merged.set(id, {\n id,\n name: id.charAt(0).toUpperCase() + id.slice(1),\n // The five default rows are hosted sibling apps, not routes owned by\n // Dispatch. Keep a mounted path for legacy callers, but give embed\n // session resolution the exact canonical origin.\n path: \"/\",\n url: CANONICAL_WORKSPACE_SSO_APP_ORIGINS[id],\n status: \"ready\",\n });\n }\n for (const app of apps ?? []) merged.set(app.id, app);\n\n return [...merged.values()];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"workspace-apps.js","sourceRoot":"","sources":["../../src/lib/workspace-apps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC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AG,EAA+B,CAAC;IACtD,KAAK,MAAM,EAAE,IAAI,0BAA0B,EAAE,CAAC;QAC5C,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE;YACb,EAAE;YACF,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;YAC9C,qEAAqE;YACrE,mEAAmE;YACnE,iDAAiD;YACjD,IAAI,EAAE,GAAG;YACT,GAAG,EAAE,mCAAmC,CAAC,EAAE,CAAC;YAC5C,MAAM,EAAE,OAAO;SAChB,CAAC,CAAC;IACL,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,IAAI,IAAI,EAAE;QAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAEtD,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import { CHAT_FIRST_DEFAULT_APP_IDS } from \"@agent-native/core/client/chat-first\";\nimport { isInBuilderFrame } from \"@agent-native/core/client/host\";\nimport { withBuilderUtmTrackingParams } from \"@agent-native/core/shared/builder-link-tracking\";\n\nimport {\n CANONICAL_WORKSPACE_SSO_APP_ORIGINS,\n isWorkspaceSsoAppUrl,\n} from \"../shared/workspace-sso\";\n\nexport interface WorkspaceAppSummary {\n id: string;\n name: string;\n description?: string;\n path: string;\n url?: string | null;\n isDispatch?: boolean;\n audience?: \"internal\" | \"public\";\n visibility?: \"private\" | \"org\";\n publicPaths?: string[];\n protectedPaths?: string[];\n status?: \"ready\" | \"pending\";\n statusLabel?: string;\n builderUrl?: string | null;\n branchName?: string | null;\n createdAt?: string | null;\n createdBy?: string | null;\n owner?: string | null;\n teams?: string[];\n agentCardUrl?: string | null;\n agentCardReachable?: boolean;\n a2aEndpointUrl?: string | null;\n agentName?: string | null;\n agentSkillsCount?: number | null;\n archived?: boolean;\n workspaceSso?: boolean;\n}\n\ninterface WorkspaceAppHrefSource {\n path?: string | null;\n url?: string | null;\n workspaceSso?: boolean;\n}\n\nexport function isDispatchWorkspaceAppId(appId: string): boolean {\n return appId.trim().toLowerCase() === \"dispatch\";\n}\n\nfunction clientRuntimeEnvironment(): \"production\" | \"development\" {\n const importMetaEnv = (\n import.meta as unknown as {\n env?: Record<string, string | boolean | undefined>;\n }\n ).env;\n const processEnv = (\n globalThis as typeof globalThis & {\n process?: { env?: Record<string, string | boolean | undefined> };\n }\n ).process?.env;\n const env = { ...processEnv, ...importMetaEnv };\n if (\n env.PROD === true ||\n env.MODE === \"production\" ||\n env.NODE_ENV === \"production\"\n ) {\n return \"production\";\n }\n if (\n env.DEV === true ||\n env.MODE === \"development\" ||\n env.MODE === \"test\" ||\n env.NODE_ENV === \"development\" ||\n env.NODE_ENV === \"test\"\n ) {\n return \"development\";\n }\n return \"production\";\n}\n\n/**\n * The workspace SSO action only accepts an exact registered app identity and\n * origin. The catalog's boolean is a server-derived projection for custom\n * registrations; the URL check keeps malformed metadata out of the action.\n */\nexport function isWorkspaceSsoApp(\n app: WorkspaceAppHrefSource & { id: string },\n): boolean {\n const rawUrl = app.url?.trim();\n if (!rawUrl) return false;\n try {\n const url = new URL(rawUrl);\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\") return false;\n if (app.workspaceSso === true) return true;\n return isWorkspaceSsoAppUrl(\n { id: app.id, url: rawUrl },\n { nodeEnv: clientRuntimeEnvironment() },\n );\n // coercion-ok: malformed app metadata is not eligible for workspace SSO.\n } catch {\n return false;\n }\n}\n\nfunction isCanonicalWorkspaceSsoOrigin(rawUrl: string): boolean {\n try {\n const origin = new URL(rawUrl).origin;\n return Object.values(CANONICAL_WORKSPACE_SSO_APP_ORIGINS).some(\n (canonicalOrigin) => canonicalOrigin === origin,\n );\n } catch {\n // coercion-ok: malformed app metadata is not a canonical first-party app.\n return false;\n }\n}\n\n/**\n * A mounted app URL leaves Dispatch's `/apps/:id` host route. Canonical\n * first-party origins can stay inline even at `/`, while external published\n * apps must open at their own origin regardless of their path.\n */\nexport function isPathMountedWorkspaceApp(\n app: WorkspaceAppHrefSource,\n): boolean {\n const rawUrl = app.url?.trim();\n if (rawUrl) {\n try {\n const pathname = new URL(rawUrl).pathname.replace(/\\/+$/, \"\") || \"/\";\n return pathname !== \"/\" || !isCanonicalWorkspaceSsoOrigin(rawUrl);\n // coercion-ok: invalid absolute URLs use the mounted path fallback.\n } catch {\n // Fall through to the mounted path for relative manifest values.\n }\n }\n const path = app.path?.trim().replace(/\\/+$/, \"\") || \"/\";\n return path !== \"/\";\n}\n\nexport function isDefaultWorkspaceAppHiddenId(appId: string): boolean {\n const normalized = appId.trim().toLowerCase();\n return normalized === \"chat\" || isDispatchWorkspaceAppId(normalized);\n}\n\nexport function isWorkspaceAppVisibleInDefaultLaunchers(\n app: Pick<WorkspaceAppSummary, \"id\" | \"isDispatch\">,\n): boolean {\n return !app.isDispatch && !isDefaultWorkspaceAppHiddenId(app.id);\n}\n\nexport function workspaceAppRoute(appId: string): string {\n return `/apps/${encodeURIComponent(appId)}`;\n}\n\nexport function workspaceAppIdFromRoute(pathname: string): string | null {\n const match = pathname.match(/^\\/apps\\/([^/]+)(?:\\/|$)/);\n if (!match) return null;\n try {\n const appId = decodeURIComponent(match[1]).trim();\n return appId || null;\n } catch {\n // coercion-ok: malformed app routes are inactive, not app ids.\n return null;\n }\n}\n\nexport function workspaceAppHref(app: WorkspaceAppSummary): string | null {\n if (app.status === \"pending\") {\n return app.builderUrl\n ? withBuilderUtmTrackingParams(app.builderUrl, {\n campaign: \"product\",\n content: \"dispatch_branch\",\n })\n : null;\n }\n return app.path || app.url || null;\n}\n\nexport function workspaceAppEmbedTarget(\n app: Pick<WorkspaceAppSummary, \"path\" | \"url\">,\n): { path?: string; url?: string } {\n const url = app.url?.trim();\n if (url) return { url };\n\n const path = app.path.trim();\n return path.startsWith(\"/\") ? { path } : path ? { url: path } : {};\n}\n\n/**\n * Resolve an app route without an embed ticket so the target can render its\n * own error document when session setup fails.\n */\nexport function workspaceAppDirectHref(\n app: WorkspaceAppHrefSource,\n targetPath: string,\n): string | null {\n const target = targetPath.trim();\n if (!target || !target.startsWith(\"/\") || target.startsWith(\"//\")) {\n return null;\n }\n\n let targetUrl: URL;\n try {\n targetUrl = new URL(target, \"https://agent-native.invalid\");\n } catch {\n // coercion-ok: invalid relative target input has no safe href.\n return null;\n }\n const targetPathname = targetUrl.pathname || \"/\";\n\n let absoluteBase: URL | null = null;\n const rawUrl = app.url?.trim();\n if (rawUrl) {\n try {\n const parsedBase = new URL(rawUrl);\n if (parsedBase.protocol === \"http:\" || parsedBase.protocol === \"https:\") {\n absoluteBase = parsedBase;\n }\n // coercion-ok: invalid app URLs use the mounted path fallback below.\n } catch {\n absoluteBase = null;\n }\n }\n\n const mountedPath = app.path?.trim();\n const basePath = absoluteBase\n ? absoluteBase.pathname\n : mountedPath\n ? `/${mountedPath.replace(/^[/\\\\]+/, \"\").split(/[?#]/, 1)[0]}`\n : null;\n if (!basePath) return null;\n\n const normalizedBasePath = basePath.replace(/\\/+$/, \"\") || \"/\";\n const targetIsMountedPath =\n normalizedBasePath !== \"/\" &&\n (targetPathname === normalizedBasePath ||\n targetPathname.startsWith(`${normalizedBasePath}/`));\n const resolvedPath = targetIsMountedPath\n ? targetPathname\n : normalizedBasePath === \"/\"\n ? targetPathname\n : targetPathname === \"/\"\n ? normalizedBasePath\n : `${normalizedBasePath}/${targetPathname.replace(/^\\/+/, \"\")}`;\n\n if (absoluteBase) {\n absoluteBase.pathname = resolvedPath;\n absoluteBase.search = targetUrl.search;\n absoluteBase.hash = targetUrl.hash;\n return absoluteBase.toString();\n }\n\n return `${resolvedPath}${targetUrl.search}${targetUrl.hash}`;\n}\n\nexport function isPendingBuilderHref(app: WorkspaceAppSummary): boolean {\n return app.status === \"pending\" && !!app.builderUrl;\n}\n\nexport function shouldOpenWorkspaceAppInTopWindow(): boolean {\n if (typeof window === \"undefined\") return false;\n // A generic iframe is an inline host by design. Only Builder owns the\n // parent navigation contract for workspace apps.\n return isInBuilderFrame();\n}\n\nexport function navigateToWorkspaceApp(href: string): boolean {\n if (typeof window === \"undefined\") return false;\n\n try {\n const targetUrl = new URL(href, window.location.href);\n if (targetUrl.protocol !== \"http:\" && targetUrl.protocol !== \"https:\") {\n return false;\n }\n const targetWindow =\n shouldOpenWorkspaceAppInTopWindow() && window.top ? window.top : window;\n targetWindow.location.href = targetUrl.href;\n return true;\n } catch {\n // coercion-ok: a blocked top-window assignment is an expected fallback signal.\n return false;\n }\n}\n\n/**\n * Keep the chat-first rail useful before a workspace manifest is populated.\n * Mounted workspace rows still win, so custom names and routes remain the\n * source of truth once an app exists in the workspace.\n */\nexport function mergeChatFirstWorkspaceApps(\n apps: readonly WorkspaceAppSummary[] | undefined,\n): WorkspaceAppSummary[] {\n const merged = new Map<string, WorkspaceAppSummary>();\n for (const id of CHAT_FIRST_DEFAULT_APP_IDS) {\n merged.set(id, {\n id,\n name: id.charAt(0).toUpperCase() + id.slice(1),\n // The five default rows are hosted sibling apps, not routes owned by\n // Dispatch. Keep a mounted path for legacy callers, but give embed\n // session resolution the exact canonical origin.\n path: \"/\",\n url: CANONICAL_WORKSPACE_SSO_APP_ORIGINS[id],\n status: \"ready\",\n });\n }\n for (const app of apps ?? []) merged.set(app.id, app);\n\n return [...merged.values()];\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @vitest-environment happy-dom
|
|
2
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
3
|
-
import { navigateToWorkspaceApp, workspaceAppDirectHref, workspaceAppEmbedTarget, } from "./workspace-apps.js";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
3
|
+
import { navigateToWorkspaceApp, shouldOpenWorkspaceAppInTopWindow, workspaceAppDirectHref, workspaceAppEmbedTarget, } from "./workspace-apps.js";
|
|
4
4
|
describe("workspaceAppEmbedTarget", () => {
|
|
5
5
|
it("uses the app URL as the embed root when a mount path is also present", () => {
|
|
6
6
|
expect(workspaceAppEmbedTarget({
|
|
@@ -32,7 +32,11 @@ describe("workspaceAppDirectHref", () => {
|
|
|
32
32
|
});
|
|
33
33
|
});
|
|
34
34
|
describe("navigateToWorkspaceApp", () => {
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
window.history.replaceState({}, "", "/");
|
|
37
|
+
});
|
|
35
38
|
afterEach(() => {
|
|
39
|
+
window.history.replaceState({}, "", "/");
|
|
36
40
|
Object.defineProperty(window, "parent", {
|
|
37
41
|
configurable: true,
|
|
38
42
|
value: window,
|
|
@@ -42,8 +46,16 @@ describe("navigateToWorkspaceApp", () => {
|
|
|
42
46
|
value: window,
|
|
43
47
|
});
|
|
44
48
|
});
|
|
45
|
-
it("
|
|
49
|
+
it("keeps a normal iframe inline", () => {
|
|
50
|
+
Object.defineProperty(window, "parent", {
|
|
51
|
+
configurable: true,
|
|
52
|
+
value: {},
|
|
53
|
+
});
|
|
54
|
+
expect(shouldOpenWorkspaceAppInTopWindow()).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
it("uses the top window when Dispatch is inside a Builder webview", () => {
|
|
46
57
|
const topWindow = { location: { href: "" } };
|
|
58
|
+
window.history.replaceState({}, "", "/?builder.preview=interact");
|
|
47
59
|
Object.defineProperty(window, "parent", {
|
|
48
60
|
configurable: true,
|
|
49
61
|
value: {},
|
|
@@ -52,6 +64,7 @@ describe("navigateToWorkspaceApp", () => {
|
|
|
52
64
|
configurable: true,
|
|
53
65
|
value: topWindow,
|
|
54
66
|
});
|
|
67
|
+
expect(shouldOpenWorkspaceAppInTopWindow()).toBe(true);
|
|
55
68
|
navigateToWorkspaceApp("/mail");
|
|
56
69
|
expect(topWindow.location.href).toBe(new URL("/mail", window.location.href).href);
|
|
57
70
|
});
|
|
@@ -64,6 +77,7 @@ describe("navigateToWorkspaceApp", () => {
|
|
|
64
77
|
},
|
|
65
78
|
});
|
|
66
79
|
const topWindow = { location };
|
|
80
|
+
window.history.replaceState({}, "", "/?builder.preview=interact");
|
|
67
81
|
Object.defineProperty(window, "parent", {
|
|
68
82
|
configurable: true,
|
|
69
83
|
value: {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-apps.test.js","sourceRoot":"","sources":["../../src/lib/workspace-apps.test.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"workspace-apps.test.js","sourceRoot":"","sources":["../../src/lib/workspace-apps.test.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAErE,OAAO,EACL,sBAAsB,EACtB,iCAAiC,EACjC,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAE1B,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,EAAE,CAAC,sEAAsE,EAAE,GAAG,EAAE;QAC9E,MAAM,CACJ,uBAAuB,CAAC;YACtB,IAAI,EAAE,UAAU;YAChB,GAAG,EAAE,wCAAwC;SAC9C,CAAC,CACH,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,wCAAwC,EAAE,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,GAAG,EAAE;QACrE,MAAM,CAAC,uBAAuB,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;YACvE,IAAI,EAAE,UAAU;SACjB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC9D,MAAM,C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B,KAAK,EAAE,SAAS;SACjB,CAAC,CAAC;QAEH,MAAM,CAAC,sBAAsB,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClE,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// @vitest-environment happy-dom\nimport { afterEach, beforeEach, describe, expect, it } from \"vitest\";\n\nimport {\n navigateToWorkspaceApp,\n shouldOpenWorkspaceAppInTopWindow,\n workspaceAppDirectHref,\n workspaceAppEmbedTarget,\n} from \"./workspace-apps\";\n\ndescribe(\"workspaceAppEmbedTarget\", () => {\n it(\"uses the app URL as the embed root when a mount path is also present\", () => {\n expect(\n workspaceAppEmbedTarget({\n path: \"/content\",\n url: \"https://workspace.example.test/content\",\n }),\n ).toEqual({ url: \"https://workspace.example.test/content\" });\n });\n\n it(\"falls back to the mounted path when no app URL is available\", () => {\n expect(workspaceAppEmbedTarget({ path: \"/content\", url: null })).toEqual({\n path: \"/content\",\n });\n });\n});\n\ndescribe(\"workspaceAppDirectHref\", () => {\n it(\"joins an app-relative route onto an absolute app URL\", () => {\n expect(\n workspaceAppDirectHref(\n { path: \"/atlas\", url: \"https://workspace.example.test/atlas\" },\n \"/emails?status=failed#latest\",\n ),\n ).toBe(\"https://workspace.example.test/atlas/emails?status=failed#latest\");\n });\n\n it(\"does not duplicate a mount path already present in the target\", () => {\n expect(\n workspaceAppDirectHref(\n { path: \"/atlas\", url: \"https://workspace.example.test/atlas\" },\n \"/atlas\",\n ),\n ).toBe(\"https://workspace.example.test/atlas\");\n });\n\n it(\"resolves a mounted relative app path\", () => {\n expect(workspaceAppDirectHref({ path: \"/atlas\" }, \"/emails\")).toBe(\n \"/atlas/emails\",\n );\n });\n\n it(\"falls back to a safe mount path when the app URL is invalid\", () => {\n expect(\n workspaceAppDirectHref(\n { path: \"/atlas\", url: \"javascript:alert(1)\" },\n \"/\",\n ),\n ).toBe(\"/atlas\");\n });\n\n it(\"rejects an unsafe target path\", () => {\n expect(workspaceAppDirectHref({ path: \"/atlas\" }, \"//evil.example\")).toBe(\n null,\n );\n });\n});\n\ndescribe(\"navigateToWorkspaceApp\", () => {\n beforeEach(() => {\n window.history.replaceState({}, \"\", \"/\");\n });\n\n afterEach(() => {\n window.history.replaceState({}, \"\", \"/\");\n Object.defineProperty(window, \"parent\", {\n configurable: true,\n value: window,\n });\n Object.defineProperty(window, \"top\", {\n configurable: true,\n value: window,\n });\n });\n\n it(\"keeps a normal iframe inline\", () => {\n Object.defineProperty(window, \"parent\", {\n configurable: true,\n value: {},\n });\n\n expect(shouldOpenWorkspaceAppInTopWindow()).toBe(false);\n });\n\n it(\"uses the top window when Dispatch is inside a Builder webview\", () => {\n const topWindow = { location: { href: \"\" } } as unknown as Window;\n window.history.replaceState({}, \"\", \"/?builder.preview=interact\");\n Object.defineProperty(window, \"parent\", {\n configurable: true,\n value: {},\n });\n Object.defineProperty(window, \"top\", {\n configurable: true,\n value: topWindow,\n });\n\n expect(shouldOpenWorkspaceAppInTopWindow()).toBe(true);\n navigateToWorkspaceApp(\"/mail\");\n\n expect(topWindow.location.href).toBe(\n new URL(\"/mail\", window.location.href).href,\n );\n });\n\n it(\"reports when the embedded top window rejects navigation\", () => {\n const location = {} as Location;\n Object.defineProperty(location, \"href\", {\n configurable: true,\n set: () => {\n throw new Error(\"Top navigation is blocked\");\n },\n });\n const topWindow = { location } as unknown as Window;\n window.history.replaceState({}, \"\", \"/?builder.preview=interact\");\n Object.defineProperty(window, \"parent\", {\n configurable: true,\n value: {},\n });\n Object.defineProperty(window, \"top\", {\n configurable: true,\n value: topWindow,\n });\n\n expect(navigateToWorkspaceApp(\"/mail\")).toBe(false);\n });\n\n it(\"rejects non-http navigation targets\", () => {\n const topWindow = { location: { href: \"\" } } as unknown as Window;\n Object.defineProperty(window, \"parent\", {\n configurable: true,\n value: {},\n });\n Object.defineProperty(window, \"top\", {\n configurable: true,\n value: topWindow,\n });\n\n expect(navigateToWorkspaceApp(\"javascript:alert(1)\")).toBe(false);\n expect(topWindow.location.href).toBe(\"\");\n });\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"$appId.d.ts","sourceRoot":"","sources":["../../../src/routes/pages/$appId.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"$appId.d.ts","sourceRoot":"","sources":["../../../src/routes/pages/$appId.tsx"],"names":[],"mappings":"AAWA,OAAO,EAKL,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACxB,MAAM,cAAc,CAAC;AActB,wBAAgB,IAAI;;IAEnB;AA2CD,wBAAsB,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,kBAAkB,iBAQ1D;AAED,wBAAsB,YAAY,CAAC,EACjC,MAAM,EACN,YAAY,GACb,EAAE,wBAAwB,oBAS1B;AAED,MAAM,CAAC,OAAO,UAAU,yBAAyB,oDA0IhD"}
|
|
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { appPath } from "@agent-native/core/client/api-path";
|
|
3
3
|
import { useActionQuery } from "@agent-native/core/client/hooks";
|
|
4
4
|
import { useT } from "@agent-native/core/client/i18n";
|
|
5
|
+
import { withSsrHtmlContentType } from "@agent-native/core/shared";
|
|
5
6
|
import { withBuilderUtmTrackingParams } from "@agent-native/core/shared/builder-link-tracking";
|
|
6
7
|
import { IconArrowLeft, IconArrowUpRight, IconClockHour4, } from "@tabler/icons-react";
|
|
7
8
|
import { useEffect, useMemo, useState } from "react";
|
|
@@ -63,16 +64,16 @@ export async function loader({ params }) {
|
|
|
63
64
|
return null;
|
|
64
65
|
const selfTarget = dispatchSelfRedirect(appId);
|
|
65
66
|
if (selfTarget)
|
|
66
|
-
throw redirect(selfTarget);
|
|
67
|
+
throw withSsrHtmlContentType(redirect(selfTarget));
|
|
67
68
|
const target = await resolveServerCatchAllTarget(appId);
|
|
68
69
|
if (target)
|
|
69
|
-
throw redirect(target);
|
|
70
|
+
throw withSsrHtmlContentType(redirect(target));
|
|
70
71
|
return null;
|
|
71
72
|
}
|
|
72
73
|
export async function clientLoader({ params, serverLoader, }) {
|
|
73
74
|
const selfTarget = dispatchSelfRedirect(params.appId);
|
|
74
75
|
if (selfTarget)
|
|
75
|
-
throw redirect(selfTarget);
|
|
76
|
+
throw withSsrHtmlContentType(redirect(selfTarget));
|
|
76
77
|
// Defer to the server loader so the built-in template fallback runs on
|
|
77
78
|
// SPA navigations too (e.g. clicking a `/<template-id>` link inside
|
|
78
79
|
// dispatch). Without this the client side would only check the workspace
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"$appId.js","sourceRoot":"","sources":["../../../src/routes/pages/$appId.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAC;AACtD,OAAO,EAAE,4BAA4B,EAAE,MAAM,iDAAiD,CAAC;AAC/F,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,cAAc,GACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,SAAS,GAGV,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA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AC,CAAC,6BAA6B,CAAC,GAC9B,EACL,aAAG,SAAS,EAAC,+BAA+B,aAC1C,gBAAM,SAAS,EAAC,2BAA2B,kBAAG,KAAK,IAAQ,YAC1D,CAAC,CAAC,0CAA0C,CAAC,IAC5C,EACJ,KAAC,MAAM,IAAC,OAAO,kBACb,KAAC,IAAI,IAAC,EAAE,EAAE,OAAO,CAAC,OAAO,CAAC,YACvB,CAAC,CAAC,2BAA2B,CAAC,GAC1B,GACA,IACL,CACP,IACG,GACQ,CACjB,CAAC;AACJ,CAAC","sourcesContent":["import { appPath } from \"@agent-native/core/client/api-path\";\nimport { useActionQuery } from \"@agent-native/core/client/hooks\";\nimport { useT } from \"@agent-native/core/client/i18n\";\nimport { withBuilderUtmTrackingParams } from \"@agent-native/core/shared/builder-link-tracking\";\nimport {\n IconArrowLeft,\n IconArrowUpRight,\n IconClockHour4,\n} from \"@tabler/icons-react\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport {\n Link,\n Navigate,\n redirect,\n useParams,\n type ClientLoaderFunctionArgs,\n type LoaderFunctionArgs,\n} from \"react-router\";\n\nimport { ActionQueryError } from \"../../components/action-query-error\";\nimport { DispatchShell } from \"../../components/dispatch-shell\";\nimport { Badge } from \"../../components/ui/badge\";\nimport { Button } from \"../../components/ui/button\";\nimport { Spinner } from \"../../components/ui/spinner\";\nimport { resolveServerCatchAllTarget } from \"../../lib/catch-all-target\";\nimport {\n navigateToWorkspaceApp,\n workspaceAppHref,\n type WorkspaceAppSummary,\n} from \"../../lib/workspace-apps\";\n\nexport function meta() {\n return [{ title: \"Workspace app - Dispatch\" }];\n}\n\n/**\n * Catch-all for `/dispatch/<segment>` paths that don't match an explicit\n * Dispatch route. When `<segment>` is the id of a workspace app sibling\n * (e.g. `/dispatch/todo` after Builder.io routes a \"navigate to /todo\"\n * call through Dispatch's mount point), bounce to the absolute `/<appId>`\n * so the user lands on the actual app instead of a 404 inside Dispatch.\n *\n * Server-side redirect: we resolve the workspace app manifest via the\n * shared `loadWorkspaceAppsManifest()` helper, which checks the\n * `AGENT_NATIVE_WORKSPACE_APPS_JSON` env var, then the\n * `.agent-native/workspace-apps.json` file written by `workspace-deploy.ts`,\n * then a live filesystem scan of `apps/` for local dev. We then throw\n * `redirect(\"/<appId>\")`. React Router 7 does not prepend the basename to\n * absolute paths returned from a loader, so the redirect escapes Dispatch's\n * `/dispatch` mount cleanly.\n *\n * Why a catch-all instead of fixing the agent prompt: Builder.io currently\n * resolves \"navigate to /todo\" relative to Dispatch's mount, sending the\n * user to /dispatch/todo. The same wrong path then gets captured as the\n * OAuth callbackURL, so Google sign-in completes back at /dispatch/todo\n * and looks broken. This route fixes both the post-creation navigation\n * and the OAuth round-trip from a single place.\n *\n * Built-in template fallback: when no workspace manifest is available\n * (framework dev with each template on its own port, hosted dispatch with\n * no sibling apps), redirect to the matching first-party template's deploy\n * URL — `http://localhost:<devPort>` in dev, `https://<id>.agent-native.com`\n * in production. Without this, a user visiting `/forms` on dispatch is\n * forced to sign in (auth guard) and then lands on this route's \"Page not\n * found\" pane after the post-login reload.\n *\n * `appId === \"dispatch\"` short-circuit: when the segment matches Dispatch\n * itself (e.g. `/dispatch/dispatch`), we go straight to the overview rather\n * than chaining through `/dispatch` (which polled `useActionQuery` re-fired\n * `window.location.assign` against and looped forever in production).\n */\nfunction dispatchSelfRedirect(appId: string | undefined): string | null {\n if (appId === \"dispatch\") return appPath(\"/overview\");\n return null;\n}\n\nexport async function loader({ params }: LoaderFunctionArgs) {\n const appId = params.appId;\n if (!appId) return null;\n const selfTarget = dispatchSelfRedirect(appId);\n if (selfTarget) throw redirect(selfTarget);\n const target = await resolveServerCatchAllTarget(appId);\n if (target) throw redirect(target);\n return null;\n}\n\nexport async function clientLoader({\n params,\n serverLoader,\n}: ClientLoaderFunctionArgs) {\n const selfTarget = dispatchSelfRedirect(params.appId);\n if (selfTarget) throw redirect(selfTarget);\n // Defer to the server loader so the built-in template fallback runs on\n // SPA navigations too (e.g. clicking a `/<template-id>` link inside\n // dispatch). Without this the client side would only check the workspace\n // apps query, which never lists the static first-party templates and so\n // the user would land on the \"Page not found\" pane.\n return serverLoader();\n}\n\nexport default function WorkspaceAppCatchAllRoute() {\n const t = useT();\n const { appId } = useParams();\n const appsQuery = useActionQuery(\"list-workspace-apps\", {\n includeAgentCards: false,\n });\n const { data: apps = [], isLoading } = appsQuery;\n const app = useMemo(\n () =>\n (apps as WorkspaceAppSummary[]).find((item) => item.id === appId) ?? null,\n [appId, apps],\n );\n const href = app ? workspaceAppHref(app) : null;\n const isSelfReference = appId === \"dispatch\";\n const hasApp = app !== null;\n const appIsPending = app?.status === \"pending\";\n const [navigationFailed, setNavigationFailed] = useState(false);\n\n useEffect(() => {\n if (isSelfReference) return;\n if (!hasApp || appIsPending || !href) {\n setNavigationFailed(false);\n return;\n }\n setNavigationFailed(!navigateToWorkspaceApp(href));\n }, [appIsPending, hasApp, href, isSelfReference]);\n\n if (isSelfReference) {\n return <Navigate to={appPath(\"/overview\")} replace />;\n }\n\n if (appsQuery.isError) {\n return (\n <DispatchShell\n title={t(\"dispatch.pages.dataLoadFailed\")}\n description={t(\"dispatch.pages.pageNotFoundDescription\")}\n >\n <ActionQueryError\n error={appsQuery.error}\n onRetry={() => void appsQuery.refetch()}\n />\n </DispatchShell>\n );\n }\n\n if (navigationFailed && href) {\n return (\n <DispatchShell\n title={t(\"dispatch.pages.dataLoadFailed\")}\n description={t(\"dispatch.pages.pageNotFoundDescription\")}\n >\n <ActionQueryError\n onRetry={() => setNavigationFailed(!navigateToWorkspaceApp(href))}\n />\n </DispatchShell>\n );\n }\n\n if (\n (isLoading && !app) ||\n (app && app.status !== \"pending\" && href && !navigationFailed)\n ) {\n return (\n <div className=\"flex h-screen w-full items-center justify-center\">\n <Spinner className=\"size-8\" />\n </div>\n );\n }\n\n return (\n <DispatchShell\n title={app?.name || t(\"dispatch.pages.pageNotFound\")}\n description={t(\"dispatch.pages.pageNotFoundDescription\")}\n >\n <div className=\"max-w-2xl rounded-lg bg-card p-5\">\n <Button asChild size=\"sm\" variant=\"ghost\" className=\"-ml-2 mb-4\">\n <Link to={appPath(\"/overview\")}>\n <IconArrowLeft size={15} className=\"mr-1.5\" />\n {t(\"dispatch.nav.overview\")}\n </Link>\n </Button>\n\n {app?.status === \"pending\" ? (\n <div className=\"space-y-4\">\n <div className=\"flex flex-wrap items-center gap-2\">\n <h2 className=\"text-base font-semibold text-foreground\">\n {app.name}\n </h2>\n <Badge\n variant=\"outline\"\n className=\"gap-1 border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300\"\n >\n <IconClockHour4 size={12} />\n {t(\"dispatch.pages.building\")}\n </Badge>\n </div>\n <p className=\"text-sm text-muted-foreground\">\n {t(\"dispatch.pages.appBuildingPrefix\")}{\" \"}\n <span className=\"font-mono text-foreground\">{app.path}</span>{\" \"}\n {t(\"dispatch.pages.appBuildingSuffix\")}\n </p>\n {app.builderUrl ? (\n <Button asChild>\n <a\n href={withBuilderUtmTrackingParams(app.builderUrl, {\n campaign: \"product\",\n content: \"dispatch_branch\",\n })}\n target=\"_blank\"\n rel=\"noreferrer\"\n >\n {t(\"dispatch.pages.openBuilderBranch\", {\n defaultValue: \"Open in Builder\",\n })}\n <IconArrowUpRight size={15} className=\"ml-1.5\" />\n </a>\n </Button>\n ) : null}\n </div>\n ) : (\n <div className=\"space-y-3\">\n <h2 className=\"text-base font-semibold text-foreground\">\n {t(\"dispatch.pages.pageNotFound\")}\n </h2>\n <p className=\"text-sm text-muted-foreground\">\n <span className=\"font-mono text-foreground\">/{appId}</span> isn't\n {t(\"dispatch.pages.notDispatchOrWorkspaceApp\")}\n </p>\n <Button asChild>\n <Link to={appPath(\"/apps\")}>\n {t(\"dispatch.pages.browseApps\")}\n </Link>\n </Button>\n </div>\n )}\n </div>\n </DispatchShell>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"$appId.js","sourceRoot":"","sources":["../../../src/routes/pages/$appId.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,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,GAAI,EAC3B,CAAC,CAAC,yBAAyB,CAAC,IACvB,IACJ,EACN,aAAG,SAAS,EAAC,+BAA+B,aACzC,CAAC,CAAC,kCAAkC,CAAC,EAAE,GAAG,EAC3C,eAAM,SAAS,EAAC,2BAA2B,YAAE,GAAG,CAAC,IAAI,GAAQ,EAAC,GAAG,EAChE,CAAC,CAAC,kCAAkC,CAAC,IACpC,EACH,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAChB,KAAC,MAAM,IAAC,OAAO,kBACb,aACE,IAAI,EAAE,4BAA4B,CAAC,GAAG,CAAC,UAAU,EAAE;oCACjD,QAAQ,EAAE,SAAS;oCACnB,OAAO,EAAE,iBAAiB;iCAC3B,CAAC,EACF,MAAM,EAAC,QAAQ,EACf,GAAG,EAAC,YAAY,aAEf,CAAC,CAAC,kCAAkC,EAAE;wCACrC,YAAY,EAAE,iBAAiB;qCAChC,CAAC,EACF,KAAC,gBAAgB,IAAC,IAAI,EAAE,EAAE,EAAE,SAAS,EAAC,QAAQ,GAAG,IAC/C,GACG,CACV,CAAC,CAAC,CAAC,IAAI,IACJ,CACP,CAAC,CAAC,CAAC,CACF,eAAK,SAAS,EAAC,WAAW,aACxB,aAAI,SAAS,EAAC,yCAAyC,YACpD,CAAC,CAAC,6BAA6B,CAAC,GAC9B,EACL,aAAG,SAAS,EAAC,+BAA+B,aAC1C,gBAAM,SAAS,EAAC,2BAA2B,kBAAG,KAAK,IAAQ,YAC1D,CAAC,CAAC,0CAA0C,CAAC,IAC5C,EACJ,KAAC,MAAM,IAAC,OAAO,kBACb,KAAC,IAAI,IAAC,EAAE,EAAE,OAAO,CAAC,OAAO,CAAC,YACvB,CAAC,CAAC,2BAA2B,CAAC,GAC1B,GACA,IACL,CACP,IACG,GACQ,CACjB,CAAC;AACJ,CAAC","sourcesContent":["import { appPath } from \"@agent-native/core/client/api-path\";\nimport { useActionQuery } from \"@agent-native/core/client/hooks\";\nimport { useT } from \"@agent-native/core/client/i18n\";\nimport { withSsrHtmlContentType } from \"@agent-native/core/shared\";\nimport { withBuilderUtmTrackingParams } from \"@agent-native/core/shared/builder-link-tracking\";\nimport {\n IconArrowLeft,\n IconArrowUpRight,\n IconClockHour4,\n} from \"@tabler/icons-react\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport {\n Link,\n Navigate,\n redirect,\n useParams,\n type ClientLoaderFunctionArgs,\n type LoaderFunctionArgs,\n} from \"react-router\";\n\nimport { ActionQueryError } from \"../../components/action-query-error\";\nimport { DispatchShell } from \"../../components/dispatch-shell\";\nimport { Badge } from \"../../components/ui/badge\";\nimport { Button } from \"../../components/ui/button\";\nimport { Spinner } from \"../../components/ui/spinner\";\nimport { resolveServerCatchAllTarget } from \"../../lib/catch-all-target\";\nimport {\n navigateToWorkspaceApp,\n workspaceAppHref,\n type WorkspaceAppSummary,\n} from \"../../lib/workspace-apps\";\n\nexport function meta() {\n return [{ title: \"Workspace app - Dispatch\" }];\n}\n\n/**\n * Catch-all for `/dispatch/<segment>` paths that don't match an explicit\n * Dispatch route. When `<segment>` is the id of a workspace app sibling\n * (e.g. `/dispatch/todo` after Builder.io routes a \"navigate to /todo\"\n * call through Dispatch's mount point), bounce to the absolute `/<appId>`\n * so the user lands on the actual app instead of a 404 inside Dispatch.\n *\n * Server-side redirect: we resolve the workspace app manifest via the\n * shared `loadWorkspaceAppsManifest()` helper, which checks the\n * `AGENT_NATIVE_WORKSPACE_APPS_JSON` env var, then the\n * `.agent-native/workspace-apps.json` file written by `workspace-deploy.ts`,\n * then a live filesystem scan of `apps/` for local dev. We then throw\n * `redirect(\"/<appId>\")`. React Router 7 does not prepend the basename to\n * absolute paths returned from a loader, so the redirect escapes Dispatch's\n * `/dispatch` mount cleanly.\n *\n * Why a catch-all instead of fixing the agent prompt: Builder.io currently\n * resolves \"navigate to /todo\" relative to Dispatch's mount, sending the\n * user to /dispatch/todo. The same wrong path then gets captured as the\n * OAuth callbackURL, so Google sign-in completes back at /dispatch/todo\n * and looks broken. This route fixes both the post-creation navigation\n * and the OAuth round-trip from a single place.\n *\n * Built-in template fallback: when no workspace manifest is available\n * (framework dev with each template on its own port, hosted dispatch with\n * no sibling apps), redirect to the matching first-party template's deploy\n * URL — `http://localhost:<devPort>` in dev, `https://<id>.agent-native.com`\n * in production. Without this, a user visiting `/forms` on dispatch is\n * forced to sign in (auth guard) and then lands on this route's \"Page not\n * found\" pane after the post-login reload.\n *\n * `appId === \"dispatch\"` short-circuit: when the segment matches Dispatch\n * itself (e.g. `/dispatch/dispatch`), we go straight to the overview rather\n * than chaining through `/dispatch` (which polled `useActionQuery` re-fired\n * `window.location.assign` against and looped forever in production).\n */\nfunction dispatchSelfRedirect(appId: string | undefined): string | null {\n if (appId === \"dispatch\") return appPath(\"/overview\");\n return null;\n}\n\nexport async function loader({ params }: LoaderFunctionArgs) {\n const appId = params.appId;\n if (!appId) return null;\n const selfTarget = dispatchSelfRedirect(appId);\n if (selfTarget) throw withSsrHtmlContentType(redirect(selfTarget));\n const target = await resolveServerCatchAllTarget(appId);\n if (target) throw withSsrHtmlContentType(redirect(target));\n return null;\n}\n\nexport async function clientLoader({\n params,\n serverLoader,\n}: ClientLoaderFunctionArgs) {\n const selfTarget = dispatchSelfRedirect(params.appId);\n if (selfTarget) throw withSsrHtmlContentType(redirect(selfTarget));\n // Defer to the server loader so the built-in template fallback runs on\n // SPA navigations too (e.g. clicking a `/<template-id>` link inside\n // dispatch). Without this the client side would only check the workspace\n // apps query, which never lists the static first-party templates and so\n // the user would land on the \"Page not found\" pane.\n return serverLoader();\n}\n\nexport default function WorkspaceAppCatchAllRoute() {\n const t = useT();\n const { appId } = useParams();\n const appsQuery = useActionQuery(\"list-workspace-apps\", {\n includeAgentCards: false,\n });\n const { data: apps = [], isLoading } = appsQuery;\n const app = useMemo(\n () =>\n (apps as WorkspaceAppSummary[]).find((item) => item.id === appId) ?? null,\n [appId, apps],\n );\n const href = app ? workspaceAppHref(app) : null;\n const isSelfReference = appId === \"dispatch\";\n const hasApp = app !== null;\n const appIsPending = app?.status === \"pending\";\n const [navigationFailed, setNavigationFailed] = useState(false);\n\n useEffect(() => {\n if (isSelfReference) return;\n if (!hasApp || appIsPending || !href) {\n setNavigationFailed(false);\n return;\n }\n setNavigationFailed(!navigateToWorkspaceApp(href));\n }, [appIsPending, hasApp, href, isSelfReference]);\n\n if (isSelfReference) {\n return <Navigate to={appPath(\"/overview\")} replace />;\n }\n\n if (appsQuery.isError) {\n return (\n <DispatchShell\n title={t(\"dispatch.pages.dataLoadFailed\")}\n description={t(\"dispatch.pages.pageNotFoundDescription\")}\n >\n <ActionQueryError\n error={appsQuery.error}\n onRetry={() => void appsQuery.refetch()}\n />\n </DispatchShell>\n );\n }\n\n if (navigationFailed && href) {\n return (\n <DispatchShell\n title={t(\"dispatch.pages.dataLoadFailed\")}\n description={t(\"dispatch.pages.pageNotFoundDescription\")}\n >\n <ActionQueryError\n onRetry={() => setNavigationFailed(!navigateToWorkspaceApp(href))}\n />\n </DispatchShell>\n );\n }\n\n if (\n (isLoading && !app) ||\n (app && app.status !== \"pending\" && href && !navigationFailed)\n ) {\n return (\n <div className=\"flex h-screen w-full items-center justify-center\">\n <Spinner className=\"size-8\" />\n </div>\n );\n }\n\n return (\n <DispatchShell\n title={app?.name || t(\"dispatch.pages.pageNotFound\")}\n description={t(\"dispatch.pages.pageNotFoundDescription\")}\n >\n <div className=\"max-w-2xl rounded-lg bg-card p-5\">\n <Button asChild size=\"sm\" variant=\"ghost\" className=\"-ml-2 mb-4\">\n <Link to={appPath(\"/overview\")}>\n <IconArrowLeft size={15} className=\"mr-1.5\" />\n {t(\"dispatch.nav.overview\")}\n </Link>\n </Button>\n\n {app?.status === \"pending\" ? (\n <div className=\"space-y-4\">\n <div className=\"flex flex-wrap items-center gap-2\">\n <h2 className=\"text-base font-semibold text-foreground\">\n {app.name}\n </h2>\n <Badge\n variant=\"outline\"\n className=\"gap-1 border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300\"\n >\n <IconClockHour4 size={12} />\n {t(\"dispatch.pages.building\")}\n </Badge>\n </div>\n <p className=\"text-sm text-muted-foreground\">\n {t(\"dispatch.pages.appBuildingPrefix\")}{\" \"}\n <span className=\"font-mono text-foreground\">{app.path}</span>{\" \"}\n {t(\"dispatch.pages.appBuildingSuffix\")}\n </p>\n {app.builderUrl ? (\n <Button asChild>\n <a\n href={withBuilderUtmTrackingParams(app.builderUrl, {\n campaign: \"product\",\n content: \"dispatch_branch\",\n })}\n target=\"_blank\"\n rel=\"noreferrer\"\n >\n {t(\"dispatch.pages.openBuilderBranch\", {\n defaultValue: \"Open in Builder\",\n })}\n <IconArrowUpRight size={15} className=\"ml-1.5\" />\n </a>\n </Button>\n ) : null}\n </div>\n ) : (\n <div className=\"space-y-3\">\n <h2 className=\"text-base font-semibold text-foreground\">\n {t(\"dispatch.pages.pageNotFound\")}\n </h2>\n <p className=\"text-sm text-muted-foreground\">\n <span className=\"font-mono text-foreground\">/{appId}</span> isn't\n {t(\"dispatch.pages.notDispatchOrWorkspaceApp\")}\n </p>\n <Button asChild>\n <Link to={appPath(\"/apps\")}>\n {t(\"dispatch.pages.browseApps\")}\n </Link>\n </Button>\n </div>\n )}\n </div>\n </DispatchShell>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_index.d.ts","sourceRoot":"","sources":["../../../src/routes/pages/_index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"_index.d.ts","sourceRoot":"","sources":["../../../src/routes/pages/_index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AASjE,wBAAgB,IAAI;;;;;;;;;;;;;;;KAanB;AAkBD,wBAAgB,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,kBAAkB,QAIjD;AAED,wBAAgB,YAAY,CAAC,EAAE,GAAG,EAAE,EAAE,kBAAkB,QAIvD;AAED,wBAAgB,eAAe,oDAM9B;AAED,MAAM,CAAC,OAAO,UAAU,SAAS,SAEhC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { appPath } from "@agent-native/core/client/api-path";
|
|
3
|
+
import { withSsrHtmlContentType } from "@agent-native/core/shared";
|
|
3
4
|
import { redirect } from "react-router";
|
|
4
5
|
import { Spinner } from "../../components/ui/spinner.js";
|
|
5
6
|
const SEO_TITLE = "Dispatch - Open Source workspace control plane for AI agents";
|
|
@@ -34,10 +35,14 @@ function buildTarget(url) {
|
|
|
34
35
|
return appPath(`/overview${url.search}${url.hash}`);
|
|
35
36
|
}
|
|
36
37
|
export function loader({ url }) {
|
|
37
|
-
throw redirect(buildTarget(url))
|
|
38
|
+
throw withSsrHtmlContentType(redirect(buildTarget(url)), {
|
|
39
|
+
varyByQuery: true,
|
|
40
|
+
});
|
|
38
41
|
}
|
|
39
42
|
export function clientLoader({ url }) {
|
|
40
|
-
throw redirect(buildTarget(url))
|
|
43
|
+
throw withSsrHtmlContentType(redirect(buildTarget(url)), {
|
|
44
|
+
varyByQuery: true,
|
|
45
|
+
});
|
|
41
46
|
}
|
|
42
47
|
export function HydrateFallback() {
|
|
43
48
|
return (_jsx("div", { className: "flex items-center justify-center h-screen w-full", children: _jsx(Spinner, { className: "size-8" }) }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_index.js","sourceRoot":"","sources":["../../../src/routes/pages/_index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAA2B,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAEtD,MAAM,SAAS,GACb,8DAA8D,CAAC;AACjE,MAAM,eAAe,GACnB,iIAAiI,CAAC;AAEpI,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,EAAE,KAAK,EAAE,SAAS,EAAE;QACpB;YACE,IAA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BAAgB,EAAE,OAAO,EAAE,eAAe,EAAE;QACxD,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE;QAC5C,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,SAAS,EAAE;QAC7C,EAAE,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,eAAe,EAAE;KAC1D,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,WAAW,CAAC,GAAQ;IAC3B,OAAO,OAAO,CAAC,YAAY,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,EAAE,GAAG,EAAsB;IAChD,MAAM,sBAAsB,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE;QACvD,WAAW,EAAE,IAAI;KAClB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,EAAE,GAAG,EAAsB;IACtD,MAAM,sBAAsB,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE;QACvD,WAAW,EAAE,IAAI;KAClB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,CACL,cAAK,SAAS,EAAC,kDAAkD,YAC/D,KAAC,OAAO,IAAC,SAAS,EAAC,QAAQ,GAAG,GAC1B,CACP,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,SAAS;IAC/B,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { appPath } from \"@agent-native/core/client/api-path\";\nimport { withSsrHtmlContentType } from \"@agent-native/core/shared\";\nimport { redirect, type LoaderFunctionArgs } from \"react-router\";\n\nimport { Spinner } from \"../../components/ui/spinner\";\n\nconst SEO_TITLE =\n \"Dispatch - Open Source workspace control plane for AI agents\";\nconst SEO_DESCRIPTION =\n \"Open Source workspace control plane for AI agents to manage apps, secrets, approvals, messages, jobs, and cross-app delegation.\";\n\nexport function meta() {\n return [\n { title: SEO_TITLE },\n {\n name: \"description\",\n content: SEO_DESCRIPTION,\n },\n { property: \"og:title\", content: SEO_TITLE },\n { property: \"og:description\", content: SEO_DESCRIPTION },\n { name: \"twitter:card\", content: \"summary\" },\n { name: \"twitter:title\", content: SEO_TITLE },\n { name: \"twitter:description\", content: SEO_DESCRIPTION },\n ];\n}\n\n/**\n * Run the redirect on both the server and the client. A client-only\n * `<Navigate>` can drop during hydration (before the route tree is fully\n * attached), leaving the user stranded on `/` with a blank main area while\n * the layout chrome around it still renders. A `loader` redirect runs as\n * part of the server response and the navigation completes before the app\n * hydrates; `clientLoader` covers SPA-style navigations to `/`.\n *\n * We preserve `?` and `#` so deep-links like `?thread=<id>` from a Slack\n * \"Open thread\" button survive the bounce — `useThreadDeepLink` in\n * `root.tsx` reads them after the redirect lands and opens `/chat`.\n */\nfunction buildTarget(url: URL): string {\n return appPath(`/overview${url.search}${url.hash}`);\n}\n\nexport function loader({ url }: LoaderFunctionArgs) {\n throw withSsrHtmlContentType(redirect(buildTarget(url)), {\n varyByQuery: true,\n });\n}\n\nexport function clientLoader({ url }: LoaderFunctionArgs) {\n throw withSsrHtmlContentType(redirect(buildTarget(url)), {\n varyByQuery: true,\n });\n}\n\nexport function HydrateFallback() {\n return (\n <div className=\"flex items-center justify-center h-screen w-full\">\n <Spinner className=\"size-8\" />\n </div>\n );\n}\n\nexport default function IndexPage() {\n return null;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_index.test.d.ts","sourceRoot":"","sources":["../../../src/routes/pages/_index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { SSR_QUERY_CACHE_KEY_HEADER } from "@agent-native/core/shared";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { clientLoader, loader } from "./_index.js";
|
|
4
|
+
function expectOverviewRedirect(routeLoader) {
|
|
5
|
+
let thrown;
|
|
6
|
+
try {
|
|
7
|
+
routeLoader({
|
|
8
|
+
url: new URL("https://dispatch.example/?thread=thread-1"),
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
thrown = error;
|
|
13
|
+
}
|
|
14
|
+
expect(thrown).toBeInstanceOf(Response);
|
|
15
|
+
const response = thrown;
|
|
16
|
+
expect(response.status).toBe(302);
|
|
17
|
+
expect(response.headers.get("location")).toBe("/overview?thread=thread-1");
|
|
18
|
+
expect(response.headers.get("content-type")).toBe("text/html; charset=utf-8");
|
|
19
|
+
expect(response.headers.get(SSR_QUERY_CACHE_KEY_HEADER)).toBe("query");
|
|
20
|
+
}
|
|
21
|
+
describe("Dispatch root route", () => {
|
|
22
|
+
it("marks the server redirect as cacheable HTML", () => {
|
|
23
|
+
expectOverviewRedirect(loader);
|
|
24
|
+
});
|
|
25
|
+
it("marks the client redirect as cacheable HTML", () => {
|
|
26
|
+
expectOverviewRedirect(clientLoader);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=_index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_index.test.js","sourceRoot":"","sources":["../../../src/routes/pages/_index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEhD,SAAS,sBAAsB,CAC7B,WAAgD;IAEhD,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,WAAW,CAAC;YACV,GAAG,EAAE,IAAI,GAAG,CAAC,2CAA2C,CAAC;SACjD,CAAC,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,GAAG,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IACxC,MAAM,QAAQ,GAAG,MAAkB,CAAC;IACpC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;IAC3E,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IAC9E,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACzE,CAAC;AAED,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,sBAAsB,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,sBAAsB,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { SSR_QUERY_CACHE_KEY_HEADER } from \"@agent-native/core/shared\";\nimport { describe, expect, it } from \"vitest\";\n\nimport { clientLoader, loader } from \"./_index\";\n\nfunction expectOverviewRedirect(\n routeLoader: typeof loader | typeof clientLoader,\n) {\n let thrown: unknown;\n try {\n routeLoader({\n url: new URL(\"https://dispatch.example/?thread=thread-1\"),\n } as never);\n } catch (error) {\n thrown = error;\n }\n\n expect(thrown).toBeInstanceOf(Response);\n const response = thrown as Response;\n expect(response.status).toBe(302);\n expect(response.headers.get(\"location\")).toBe(\"/overview?thread=thread-1\");\n expect(response.headers.get(\"content-type\")).toBe(\"text/html; charset=utf-8\");\n expect(response.headers.get(SSR_QUERY_CACHE_KEY_HEADER)).toBe(\"query\");\n}\n\ndescribe(\"Dispatch root route\", () => {\n it(\"marks the server redirect as cacheable HTML\", () => {\n expectOverviewRedirect(loader);\n });\n\n it(\"marks the client redirect as cacheable HTML\", () => {\n expectOverviewRedirect(clientLoader);\n });\n});\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-native/dispatch",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.2",
|
|
4
4
|
"description": "Dispatch — workspace control plane for agent-native apps. Vault, integrations, destinations, scheduled jobs, and cross-app delegation, shipped as a single drop-in package.",
|
|
5
5
|
"homepage": "https://github.com/BuilderIO/agent-native#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"tailwind-merge": "^3.5.0",
|
|
88
88
|
"vaul": "^1.1.2",
|
|
89
89
|
"zod": "^4.3.6",
|
|
90
|
-
"@agent-native/toolkit": "0.16.
|
|
90
|
+
"@agent-native/toolkit": "0.16.6"
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
93
|
"@react-router/dev": "^8.1.0",
|
|
@@ -101,10 +101,10 @@
|
|
|
101
101
|
"typescript-7": "npm:typescript@^7.0.2",
|
|
102
102
|
"vite": "8.1.0",
|
|
103
103
|
"vitest": "^4.1.5",
|
|
104
|
-
"@agent-native/core": "0.
|
|
104
|
+
"@agent-native/core": "0.0.0-beta-20260819161541"
|
|
105
105
|
},
|
|
106
106
|
"peerDependencies": {
|
|
107
|
-
"@agent-native/core": "
|
|
107
|
+
"@agent-native/core": "0.0.0-beta-20260819161541",
|
|
108
108
|
"react": ">=19.2.7",
|
|
109
109
|
"react-dom": ">=19.2.7",
|
|
110
110
|
"react-router": ">=8"
|
|
@@ -35,11 +35,18 @@ vi.mock("@agent-native/core/client/i18n", () => ({
|
|
|
35
35
|
String(values?.defaultValue ?? key),
|
|
36
36
|
}));
|
|
37
37
|
|
|
38
|
+
const frameState = vi.hoisted(() => ({ inBuilderFrame: false }));
|
|
39
|
+
|
|
40
|
+
vi.mock("@agent-native/core/client/host", () => ({
|
|
41
|
+
isInBuilderFrame: () => frameState.inBuilderFrame,
|
|
42
|
+
}));
|
|
43
|
+
|
|
38
44
|
describe("WorkspaceAppCard", () => {
|
|
39
45
|
let container: HTMLDivElement;
|
|
40
46
|
let root: Root;
|
|
41
47
|
|
|
42
48
|
beforeEach(() => {
|
|
49
|
+
frameState.inBuilderFrame = false;
|
|
43
50
|
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
|
|
44
51
|
container = document.createElement("div");
|
|
45
52
|
document.body.appendChild(container);
|
|
@@ -127,6 +134,7 @@ describe("WorkspaceAppCard", () => {
|
|
|
127
134
|
});
|
|
128
135
|
|
|
129
136
|
it("opens mounted workspace apps at their published URL", async () => {
|
|
137
|
+
frameState.inBuilderFrame = true;
|
|
130
138
|
const originalParent = window.parent;
|
|
131
139
|
const originalTop = window.top;
|
|
132
140
|
const topWindow = { location: { href: "" } } as unknown as Window;
|
|
@@ -382,8 +382,9 @@ describe("WorkspaceAppKeepAlive", () => {
|
|
|
382
382
|
expect(clientState.workspaceSsoMutateAsync).not.toHaveBeenCalled();
|
|
383
383
|
});
|
|
384
384
|
|
|
385
|
-
it("mints custom SSO before navigating
|
|
385
|
+
it("mints custom SSO before navigating a Builder-hosted surface", async () => {
|
|
386
386
|
clientState.workspaceSsoEnabled = true;
|
|
387
|
+
clientState.inBuilderFrame = true;
|
|
387
388
|
const navigateToTopWindow = vi.fn(() => true);
|
|
388
389
|
Object.defineProperty(window, "parent", {
|
|
389
390
|
configurable: true,
|
|
@@ -535,9 +536,8 @@ describe("WorkspaceAppKeepAlive", () => {
|
|
|
535
536
|
).toBe("Workspace SSO is temporarily unavailable");
|
|
536
537
|
});
|
|
537
538
|
|
|
538
|
-
it("
|
|
539
|
+
it("keeps a normal iframe app inline", async () => {
|
|
539
540
|
const topWindow = { location: { href: "" } } as unknown as Window;
|
|
540
|
-
const expectedUrl = new URL("/mail", window.location.href).href;
|
|
541
541
|
Object.defineProperty(window, "parent", {
|
|
542
542
|
configurable: true,
|
|
543
543
|
value: {},
|
|
@@ -552,15 +552,22 @@ describe("WorkspaceAppKeepAlive", () => {
|
|
|
552
552
|
<WorkspaceAppFrame app={{ id: "mail", name: "Mail", path: "/mail" }} />,
|
|
553
553
|
);
|
|
554
554
|
await Promise.resolve();
|
|
555
|
+
await Promise.resolve();
|
|
556
|
+
await Promise.resolve();
|
|
555
557
|
});
|
|
556
558
|
|
|
557
|
-
expect(topWindow.location.href).toBe(
|
|
558
|
-
expect(clientState.legacyMutateAsync).
|
|
559
|
-
|
|
559
|
+
expect(topWindow.location.href).toBe("");
|
|
560
|
+
expect(clientState.legacyMutateAsync).toHaveBeenCalledWith({
|
|
561
|
+
app: "mail",
|
|
562
|
+
path: "/mail",
|
|
563
|
+
chrome: "minimal",
|
|
564
|
+
});
|
|
565
|
+
expect(container.querySelector("iframe")).not.toBeNull();
|
|
560
566
|
});
|
|
561
567
|
|
|
562
568
|
it("falls back to the embedded app when top-window navigation is blocked", async () => {
|
|
563
569
|
const navigateToTopWindow = vi.fn(() => false);
|
|
570
|
+
clientState.inBuilderFrame = true;
|
|
564
571
|
Object.defineProperty(window, "parent", {
|
|
565
572
|
configurable: true,
|
|
566
573
|
value: {},
|
|
@@ -594,6 +601,7 @@ describe("WorkspaceAppKeepAlive", () => {
|
|
|
594
601
|
"/mail/emails?status=failed#latest",
|
|
595
602
|
window.location.href,
|
|
596
603
|
).href;
|
|
604
|
+
clientState.inBuilderFrame = true;
|
|
597
605
|
Object.defineProperty(window, "parent", {
|
|
598
606
|
configurable: true,
|
|
599
607
|
value: {},
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// @vitest-environment happy-dom
|
|
2
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
navigateToWorkspaceApp,
|
|
6
|
+
shouldOpenWorkspaceAppInTopWindow,
|
|
6
7
|
workspaceAppDirectHref,
|
|
7
8
|
workspaceAppEmbedTarget,
|
|
8
9
|
} from "./workspace-apps";
|
|
@@ -66,7 +67,12 @@ describe("workspaceAppDirectHref", () => {
|
|
|
66
67
|
});
|
|
67
68
|
|
|
68
69
|
describe("navigateToWorkspaceApp", () => {
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
window.history.replaceState({}, "", "/");
|
|
72
|
+
});
|
|
73
|
+
|
|
69
74
|
afterEach(() => {
|
|
75
|
+
window.history.replaceState({}, "", "/");
|
|
70
76
|
Object.defineProperty(window, "parent", {
|
|
71
77
|
configurable: true,
|
|
72
78
|
value: window,
|
|
@@ -77,8 +83,18 @@ describe("navigateToWorkspaceApp", () => {
|
|
|
77
83
|
});
|
|
78
84
|
});
|
|
79
85
|
|
|
80
|
-
it("
|
|
86
|
+
it("keeps a normal iframe inline", () => {
|
|
87
|
+
Object.defineProperty(window, "parent", {
|
|
88
|
+
configurable: true,
|
|
89
|
+
value: {},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
expect(shouldOpenWorkspaceAppInTopWindow()).toBe(false);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("uses the top window when Dispatch is inside a Builder webview", () => {
|
|
81
96
|
const topWindow = { location: { href: "" } } as unknown as Window;
|
|
97
|
+
window.history.replaceState({}, "", "/?builder.preview=interact");
|
|
82
98
|
Object.defineProperty(window, "parent", {
|
|
83
99
|
configurable: true,
|
|
84
100
|
value: {},
|
|
@@ -88,6 +104,7 @@ describe("navigateToWorkspaceApp", () => {
|
|
|
88
104
|
value: topWindow,
|
|
89
105
|
});
|
|
90
106
|
|
|
107
|
+
expect(shouldOpenWorkspaceAppInTopWindow()).toBe(true);
|
|
91
108
|
navigateToWorkspaceApp("/mail");
|
|
92
109
|
|
|
93
110
|
expect(topWindow.location.href).toBe(
|
|
@@ -104,6 +121,7 @@ describe("navigateToWorkspaceApp", () => {
|
|
|
104
121
|
},
|
|
105
122
|
});
|
|
106
123
|
const topWindow = { location } as unknown as Window;
|
|
124
|
+
window.history.replaceState({}, "", "/?builder.preview=interact");
|
|
107
125
|
Object.defineProperty(window, "parent", {
|
|
108
126
|
configurable: true,
|
|
109
127
|
value: {},
|
|
@@ -256,7 +256,9 @@ export function isPendingBuilderHref(app: WorkspaceAppSummary): boolean {
|
|
|
256
256
|
|
|
257
257
|
export function shouldOpenWorkspaceAppInTopWindow(): boolean {
|
|
258
258
|
if (typeof window === "undefined") return false;
|
|
259
|
-
|
|
259
|
+
// A generic iframe is an inline host by design. Only Builder owns the
|
|
260
|
+
// parent navigation contract for workspace apps.
|
|
261
|
+
return isInBuilderFrame();
|
|
260
262
|
}
|
|
261
263
|
|
|
262
264
|
export function navigateToWorkspaceApp(href: string): boolean {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { appPath } from "@agent-native/core/client/api-path";
|
|
2
2
|
import { useActionQuery } from "@agent-native/core/client/hooks";
|
|
3
3
|
import { useT } from "@agent-native/core/client/i18n";
|
|
4
|
+
import { withSsrHtmlContentType } from "@agent-native/core/shared";
|
|
4
5
|
import { withBuilderUtmTrackingParams } from "@agent-native/core/shared/builder-link-tracking";
|
|
5
6
|
import {
|
|
6
7
|
IconArrowLeft,
|
|
@@ -78,9 +79,9 @@ export async function loader({ params }: LoaderFunctionArgs) {
|
|
|
78
79
|
const appId = params.appId;
|
|
79
80
|
if (!appId) return null;
|
|
80
81
|
const selfTarget = dispatchSelfRedirect(appId);
|
|
81
|
-
if (selfTarget) throw redirect(selfTarget);
|
|
82
|
+
if (selfTarget) throw withSsrHtmlContentType(redirect(selfTarget));
|
|
82
83
|
const target = await resolveServerCatchAllTarget(appId);
|
|
83
|
-
if (target) throw redirect(target);
|
|
84
|
+
if (target) throw withSsrHtmlContentType(redirect(target));
|
|
84
85
|
return null;
|
|
85
86
|
}
|
|
86
87
|
|
|
@@ -89,7 +90,7 @@ export async function clientLoader({
|
|
|
89
90
|
serverLoader,
|
|
90
91
|
}: ClientLoaderFunctionArgs) {
|
|
91
92
|
const selfTarget = dispatchSelfRedirect(params.appId);
|
|
92
|
-
if (selfTarget) throw redirect(selfTarget);
|
|
93
|
+
if (selfTarget) throw withSsrHtmlContentType(redirect(selfTarget));
|
|
93
94
|
// Defer to the server loader so the built-in template fallback runs on
|
|
94
95
|
// SPA navigations too (e.g. clicking a `/<template-id>` link inside
|
|
95
96
|
// dispatch). Without this the client side would only check the workspace
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SSR_QUERY_CACHE_KEY_HEADER } from "@agent-native/core/shared";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { clientLoader, loader } from "./_index";
|
|
5
|
+
|
|
6
|
+
function expectOverviewRedirect(
|
|
7
|
+
routeLoader: typeof loader | typeof clientLoader,
|
|
8
|
+
) {
|
|
9
|
+
let thrown: unknown;
|
|
10
|
+
try {
|
|
11
|
+
routeLoader({
|
|
12
|
+
url: new URL("https://dispatch.example/?thread=thread-1"),
|
|
13
|
+
} as never);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
thrown = error;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
expect(thrown).toBeInstanceOf(Response);
|
|
19
|
+
const response = thrown as Response;
|
|
20
|
+
expect(response.status).toBe(302);
|
|
21
|
+
expect(response.headers.get("location")).toBe("/overview?thread=thread-1");
|
|
22
|
+
expect(response.headers.get("content-type")).toBe("text/html; charset=utf-8");
|
|
23
|
+
expect(response.headers.get(SSR_QUERY_CACHE_KEY_HEADER)).toBe("query");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe("Dispatch root route", () => {
|
|
27
|
+
it("marks the server redirect as cacheable HTML", () => {
|
|
28
|
+
expectOverviewRedirect(loader);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("marks the client redirect as cacheable HTML", () => {
|
|
32
|
+
expectOverviewRedirect(clientLoader);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { appPath } from "@agent-native/core/client/api-path";
|
|
2
|
+
import { withSsrHtmlContentType } from "@agent-native/core/shared";
|
|
2
3
|
import { redirect, type LoaderFunctionArgs } from "react-router";
|
|
3
4
|
|
|
4
5
|
import { Spinner } from "../../components/ui/spinner";
|
|
@@ -40,11 +41,15 @@ function buildTarget(url: URL): string {
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
export function loader({ url }: LoaderFunctionArgs) {
|
|
43
|
-
throw redirect(buildTarget(url))
|
|
44
|
+
throw withSsrHtmlContentType(redirect(buildTarget(url)), {
|
|
45
|
+
varyByQuery: true,
|
|
46
|
+
});
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
export function clientLoader({ url }: LoaderFunctionArgs) {
|
|
47
|
-
throw redirect(buildTarget(url))
|
|
50
|
+
throw withSsrHtmlContentType(redirect(buildTarget(url)), {
|
|
51
|
+
varyByQuery: true,
|
|
52
|
+
});
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
export function HydrateFallback() {
|