@agent-native/core 0.7.67 → 0.7.68
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/cli/workspacify.d.ts.map +1 -1
- package/dist/cli/workspacify.js +26 -4
- package/dist/cli/workspacify.js.map +1 -1
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +3 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/route-chunk-recovery.d.ts +15 -0
- package/dist/client/route-chunk-recovery.d.ts.map +1 -0
- package/dist/client/route-chunk-recovery.js +180 -0
- package/dist/client/route-chunk-recovery.js.map +1 -0
- package/dist/integrations/a2a-continuations-store.d.ts.map +1 -1
- package/dist/integrations/a2a-continuations-store.js +22 -5
- package/dist/integrations/a2a-continuations-store.js.map +1 -1
- package/dist/scripts/call-agent.d.ts.map +1 -1
- package/dist/scripts/call-agent.js +2 -1
- package/dist/scripts/call-agent.js.map +1 -1
- package/dist/server/agent-discovery.d.ts +3 -0
- package/dist/server/agent-discovery.d.ts.map +1 -1
- package/dist/server/agent-discovery.js +12 -3
- package/dist/server/agent-discovery.js.map +1 -1
- package/dist/templates/workspace-core/src/server/index.ts +12 -2
- package/package.json +1 -1
- package/src/templates/workspace-core/src/server/index.ts +12 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspacify.d.ts","sourceRoot":"","sources":["../../src/cli/workspacify.ts"],"names":[],"mappings":"AA2BA,MAAM,WAAW,kBAAkB;IACjC,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAC;IACf,6BAA6B;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+BAA+B;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,gEAAgE;IAChE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,wEAAwE;IACxE,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"workspacify.d.ts","sourceRoot":"","sources":["../../src/cli/workspacify.ts"],"names":[],"mappings":"AA2BA,MAAM,WAAW,kBAAkB;IACjC,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAC;IACf,6BAA6B;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+BAA+B;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,gEAAgE;IAChE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,wEAAwE;IACxE,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,IAAI,CA8F7D;AA2DD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM,CAGrE"}
|
package/dist/cli/workspacify.js
CHANGED
|
@@ -103,10 +103,7 @@ export function workspacifyApp(opts) {
|
|
|
103
103
|
fileName: "auth.ts",
|
|
104
104
|
exportName: "defaultAuthPlugin",
|
|
105
105
|
});
|
|
106
|
-
|
|
107
|
-
fileName: "agent-chat.ts",
|
|
108
|
-
exportName: "defaultAgentChatPlugin",
|
|
109
|
-
});
|
|
106
|
+
writeInheritedStarterAgentChatPlugin(appDir, workspaceCoreName, opts.appName);
|
|
110
107
|
}
|
|
111
108
|
}
|
|
112
109
|
function writeInheritedStarterPlugin(appDir, workspaceCoreName, opts) {
|
|
@@ -125,6 +122,31 @@ function writeInheritedStarterPlugin(appDir, workspaceCoreName, opts) {
|
|
|
125
122
|
"",
|
|
126
123
|
].join("\n"));
|
|
127
124
|
}
|
|
125
|
+
function writeInheritedStarterAgentChatPlugin(appDir, workspaceCoreName, appId) {
|
|
126
|
+
const pluginsDir = path.join(appDir, "server", "plugins");
|
|
127
|
+
fs.mkdirSync(pluginsDir, { recursive: true });
|
|
128
|
+
const pluginPath = path.join(pluginsDir, "agent-chat.ts");
|
|
129
|
+
fs.writeFileSync(pluginPath, [
|
|
130
|
+
`import {`,
|
|
131
|
+
` createAgentChatPlugin,`,
|
|
132
|
+
` loadActionsFromStaticRegistry,`,
|
|
133
|
+
` type AgentChatPluginOptions,`,
|
|
134
|
+
`} from "@agent-native/core/server";`,
|
|
135
|
+
`import * as workspaceServer from ${JSON.stringify(`${workspaceCoreName}/server`)};`,
|
|
136
|
+
`import actionsRegistry from "../../.generated/actions-registry.js";`,
|
|
137
|
+
"",
|
|
138
|
+
`const createWorkspaceAgentChatPlugin = (workspaceServer as Record<string, unknown>).createWorkspaceAgentChatPlugin;`,
|
|
139
|
+
`const options = {`,
|
|
140
|
+
` appId: ${JSON.stringify(appId)},`,
|
|
141
|
+
` actions: loadActionsFromStaticRegistry(actionsRegistry),`,
|
|
142
|
+
`} satisfies AgentChatPluginOptions;`,
|
|
143
|
+
"",
|
|
144
|
+
`export default typeof createWorkspaceAgentChatPlugin === "function"`,
|
|
145
|
+
` ? (createWorkspaceAgentChatPlugin as (options: AgentChatPluginOptions) => unknown)(options)`,
|
|
146
|
+
` : createAgentChatPlugin(options);`,
|
|
147
|
+
"",
|
|
148
|
+
].join("\n"));
|
|
149
|
+
}
|
|
128
150
|
/**
|
|
129
151
|
* Parse a workspace core package name into its npm scope.
|
|
130
152
|
* "@my-company/shared" → "my-company"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspacify.js","sourceRoot":"","sources":["../../src/cli/workspacify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,2BAA2B,GAAG,QAAQ,CAAC;AAiB7C,MAAM,UAAU,cAAc,CAAC,IAAwB;IACrD,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAA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,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACvB,CAAC","sourcesContent":["/**\n * Transform a standalone template directory into a workspace app in place.\n *\n * Called after copying any template under `apps/<name>/` inside an enterprise\n * workspace. The transform:\n *\n * 1. Rewrites package.json:\n * - @agent-native/core stays as a regular npm dep\n * - Adds @<workspace-scope>/shared as a workspace:* dep so the app\n * inherits shared plugins/skills/AGENTS.md via the three-layer model.\n * 2. Removes files that only make sense in standalone apps\n * (`learnings.defaults.md`, etc.).\n * 3. Replaces starter's stock auth/chat wrappers with inherited wrappers so\n * the workspace core can own those plugin slots while framework defaults\n * still mount when the workspace core is empty.\n * 4. Leaves app source code untouched. The three-layer framework\n * auto-discovers workspace-core via `agent-native.workspaceCore` in the\n * workspace root package.json — no per-app wiring needed.\n *\n * This means any first-party template under templates/* is usable as a\n * workspace app without maintaining a parallel copy.\n */\nimport fs from \"fs\";\nimport path from \"path\";\n\nconst POSTGRES_DEPENDENCY_VERSION = \"^3.4.9\";\n\nexport interface WorkspacifyOptions {\n /** Target app directory (already populated with the copied template) */\n appDir: string;\n /** App name (e.g. \"mail\") */\n appName: string;\n /** Source template name (e.g. \"starter\" when appName is \"crm\") */\n templateName?: string;\n /** Workspace root directory */\n workspaceRoot: string;\n /** Shared workspace package name (e.g. \"@my-company/shared\") */\n workspaceCoreName: string;\n /** Version range to use for the published @agent-native/core package */\n coreDependencyVersion?: string;\n}\n\nexport function workspacifyApp(opts: WorkspacifyOptions): void {\n const { appDir, workspaceCoreName } = opts;\n const coreDependencyVersion = opts.coreDependencyVersion ?? \"latest\";\n\n // 1) Rewrite package.json to add the workspace core dep and resolve\n // @agent-native/core workspace:* refs to the CLI package's published\n // range (it's an npm package, not a workspace member). Other workspace:* deps (e.g.\n // @agent-native/scheduling) stay as-is — they resolve within the workspace\n // because the required package is scaffolded alongside the app.\n const pkgPath = path.join(appDir, \"package.json\");\n if (fs.existsSync(pkgPath)) {\n try {\n const pkg = JSON.parse(fs.readFileSync(pkgPath, \"utf-8\"));\n for (const depType of [\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n ] as const) {\n const deps = pkg[depType];\n if (!deps) continue;\n for (const [key, val] of Object.entries(deps)) {\n if (\n typeof val === \"string\" &&\n val.startsWith(\"workspace:\") &&\n key === \"@agent-native/core\"\n ) {\n deps[key] = coreDependencyVersion;\n }\n }\n }\n // Ensure the dependency on the workspace shared package is present.\n pkg.dependencies = pkg.dependencies ?? {};\n pkg.dependencies[workspaceCoreName] = \"workspace:*\";\n // Core loads postgres-js lazily when DATABASE_URL points at Postgres.\n // Add the runtime package to workspace apps so production bundles do\n // not fail only after a hosted Postgres database is configured.\n pkg.dependencies.postgres ??= POSTGRES_DEPENDENCY_VERSION;\n // pnpm build-script approvals belong at the workspace root. Leaving the\n // template's per-app setting in place makes pnpm warn on every install.\n if (pkg.pnpm && typeof pkg.pnpm === \"object\") {\n delete pkg.pnpm.onlyBuiltDependencies;\n if (Object.keys(pkg.pnpm).length === 0) {\n delete pkg.pnpm;\n }\n }\n fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + \"\\n\");\n } catch {\n // Non-fatal: leave package.json unchanged.\n }\n }\n\n // 2) Remove standalone-only files that would confuse the workspace layout.\n for (const f of [\n \"learnings.defaults.md\",\n // If the template shipped its own workspace marker / stray monorepo\n // files, strip them here too.\n ]) {\n const p = path.join(appDir, f);\n if (fs.existsSync(p)) fs.unlinkSync(p);\n }\n\n // 3) Templates document action commands from the framework repo layout.\n // Workspace apps live under apps/<name>, so point every agent at the\n // generated app directory instead.\n const agentsPath = path.join(appDir, \"AGENTS.md\");\n if (fs.existsSync(agentsPath)) {\n try {\n let content = fs.readFileSync(agentsPath, \"utf-8\");\n content = content\n .replace(\n \"The terminal cwd is the framework root. Always `cd` to this template's root before running any action:\",\n `The terminal cwd is the workspace root. Always \\`cd\\` to this app's root before running any action:`,\n )\n .replace(\n /cd templates\\/[^ \\n]+ && pnpm action/g,\n `cd apps/${opts.appName} && pnpm action`,\n );\n fs.writeFileSync(agentsPath, content);\n } catch {\n // Non-fatal: leave AGENTS.md unchanged.\n }\n }\n\n if ((opts.templateName ?? opts.appName) === \"starter\") {\n writeInheritedStarterPlugin(appDir, workspaceCoreName, {\n fileName: \"auth.ts\",\n exportName: \"defaultAuthPlugin\",\n });\n writeInheritedStarterPlugin(appDir, workspaceCoreName, {\n fileName: \"agent-chat.ts\",\n exportName: \"defaultAgentChatPlugin\",\n });\n }\n}\n\nfunction writeInheritedStarterPlugin(\n appDir: string,\n workspaceCoreName: string,\n opts: { fileName: string; exportName: string },\n): void {\n const pluginsDir = path.join(appDir, \"server\", \"plugins\");\n fs.mkdirSync(pluginsDir, { recursive: true });\n const pluginPath = path.join(pluginsDir, opts.fileName);\n fs.writeFileSync(\n pluginPath,\n [\n `import { ${opts.exportName} as frameworkDefault } from \"@agent-native/core/server\";`,\n `import * as workspaceServer from ${JSON.stringify(`${workspaceCoreName}/server`)};`,\n \"\",\n `const workspacePlugin = (workspaceServer as Record<string, unknown>).${opts.exportName};`,\n \"\",\n 'export default typeof workspacePlugin === \"function\"',\n \" ? workspacePlugin\",\n \" : frameworkDefault;\",\n \"\",\n ].join(\"\\n\"),\n );\n}\n\n/**\n * Parse a workspace core package name into its npm scope.\n * \"@my-company/shared\" → \"my-company\"\n * \"shared\" → \"\" (no scope — shouldn't happen)\n */\nexport function parseWorkspaceScope(workspaceCoreName: string): string {\n const m = workspaceCoreName.match(/^@([^/]+)\\//);\n return m ? m[1] : \"\";\n}\n"]}
|
|
1
|
+
{"version":3,"file":"workspacify.js","sourceRoot":"","sources":["../../src/cli/workspacify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,2BAA2B,GAAG,QAAQ,CAAC;AAiB7C,MAAM,UAAU,cAAc,CAAC,IAAwB;IACrD,MAAM,EAAE,MAAM,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AAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;IAC1D,EAAE,CAAC,aAAa,CACd,UAAU,EACV;QACE,UAAU;QACV,0BAA0B;QAC1B,kCAAkC;QAClC,gCAAgC;QAChC,qCAAqC;QACrC,oCAAoC,IAAI,CAAC,SAAS,CAAC,GAAG,iBAAiB,SAAS,CAAC,GAAG;QACpF,qEAAqE;QACrE,EAAE;QACF,qHAAqH;QACrH,mBAAmB;QACnB,YAAY,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG;QACpC,4DAA4D;QAC5D,qCAAqC;QACrC,EAAE;QACF,qEAAqE;QACrE,+FAA+F;QAC/F,qCAAqC;QACrC,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,iBAAyB;IAC3D,MAAM,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IACjD,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACvB,CAAC","sourcesContent":["/**\n * Transform a standalone template directory into a workspace app in place.\n *\n * Called after copying any template under `apps/<name>/` inside an enterprise\n * workspace. The transform:\n *\n * 1. Rewrites package.json:\n * - @agent-native/core stays as a regular npm dep\n * - Adds @<workspace-scope>/shared as a workspace:* dep so the app\n * inherits shared plugins/skills/AGENTS.md via the three-layer model.\n * 2. Removes files that only make sense in standalone apps\n * (`learnings.defaults.md`, etc.).\n * 3. Replaces starter's stock auth/chat wrappers with inherited wrappers so\n * the workspace core can own those plugin slots while framework defaults\n * still mount when the workspace core is empty.\n * 4. Leaves app source code untouched. The three-layer framework\n * auto-discovers workspace-core via `agent-native.workspaceCore` in the\n * workspace root package.json — no per-app wiring needed.\n *\n * This means any first-party template under templates/* is usable as a\n * workspace app without maintaining a parallel copy.\n */\nimport fs from \"fs\";\nimport path from \"path\";\n\nconst POSTGRES_DEPENDENCY_VERSION = \"^3.4.9\";\n\nexport interface WorkspacifyOptions {\n /** Target app directory (already populated with the copied template) */\n appDir: string;\n /** App name (e.g. \"mail\") */\n appName: string;\n /** Source template name (e.g. \"starter\" when appName is \"crm\") */\n templateName?: string;\n /** Workspace root directory */\n workspaceRoot: string;\n /** Shared workspace package name (e.g. \"@my-company/shared\") */\n workspaceCoreName: string;\n /** Version range to use for the published @agent-native/core package */\n coreDependencyVersion?: string;\n}\n\nexport function workspacifyApp(opts: WorkspacifyOptions): void {\n const { appDir, workspaceCoreName } = opts;\n const coreDependencyVersion = opts.coreDependencyVersion ?? \"latest\";\n\n // 1) Rewrite package.json to add the workspace core dep and resolve\n // @agent-native/core workspace:* refs to the CLI package's published\n // range (it's an npm package, not a workspace member). Other workspace:* deps (e.g.\n // @agent-native/scheduling) stay as-is — they resolve within the workspace\n // because the required package is scaffolded alongside the app.\n const pkgPath = path.join(appDir, \"package.json\");\n if (fs.existsSync(pkgPath)) {\n try {\n const pkg = JSON.parse(fs.readFileSync(pkgPath, \"utf-8\"));\n for (const depType of [\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n ] as const) {\n const deps = pkg[depType];\n if (!deps) continue;\n for (const [key, val] of Object.entries(deps)) {\n if (\n typeof val === \"string\" &&\n val.startsWith(\"workspace:\") &&\n key === \"@agent-native/core\"\n ) {\n deps[key] = coreDependencyVersion;\n }\n }\n }\n // Ensure the dependency on the workspace shared package is present.\n pkg.dependencies = pkg.dependencies ?? {};\n pkg.dependencies[workspaceCoreName] = \"workspace:*\";\n // Core loads postgres-js lazily when DATABASE_URL points at Postgres.\n // Add the runtime package to workspace apps so production bundles do\n // not fail only after a hosted Postgres database is configured.\n pkg.dependencies.postgres ??= POSTGRES_DEPENDENCY_VERSION;\n // pnpm build-script approvals belong at the workspace root. Leaving the\n // template's per-app setting in place makes pnpm warn on every install.\n if (pkg.pnpm && typeof pkg.pnpm === \"object\") {\n delete pkg.pnpm.onlyBuiltDependencies;\n if (Object.keys(pkg.pnpm).length === 0) {\n delete pkg.pnpm;\n }\n }\n fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + \"\\n\");\n } catch {\n // Non-fatal: leave package.json unchanged.\n }\n }\n\n // 2) Remove standalone-only files that would confuse the workspace layout.\n for (const f of [\n \"learnings.defaults.md\",\n // If the template shipped its own workspace marker / stray monorepo\n // files, strip them here too.\n ]) {\n const p = path.join(appDir, f);\n if (fs.existsSync(p)) fs.unlinkSync(p);\n }\n\n // 3) Templates document action commands from the framework repo layout.\n // Workspace apps live under apps/<name>, so point every agent at the\n // generated app directory instead.\n const agentsPath = path.join(appDir, \"AGENTS.md\");\n if (fs.existsSync(agentsPath)) {\n try {\n let content = fs.readFileSync(agentsPath, \"utf-8\");\n content = content\n .replace(\n \"The terminal cwd is the framework root. Always `cd` to this template's root before running any action:\",\n `The terminal cwd is the workspace root. Always \\`cd\\` to this app's root before running any action:`,\n )\n .replace(\n /cd templates\\/[^ \\n]+ && pnpm action/g,\n `cd apps/${opts.appName} && pnpm action`,\n );\n fs.writeFileSync(agentsPath, content);\n } catch {\n // Non-fatal: leave AGENTS.md unchanged.\n }\n }\n\n if ((opts.templateName ?? opts.appName) === \"starter\") {\n writeInheritedStarterPlugin(appDir, workspaceCoreName, {\n fileName: \"auth.ts\",\n exportName: \"defaultAuthPlugin\",\n });\n writeInheritedStarterAgentChatPlugin(\n appDir,\n workspaceCoreName,\n opts.appName,\n );\n }\n}\n\nfunction writeInheritedStarterPlugin(\n appDir: string,\n workspaceCoreName: string,\n opts: { fileName: string; exportName: string },\n): void {\n const pluginsDir = path.join(appDir, \"server\", \"plugins\");\n fs.mkdirSync(pluginsDir, { recursive: true });\n const pluginPath = path.join(pluginsDir, opts.fileName);\n fs.writeFileSync(\n pluginPath,\n [\n `import { ${opts.exportName} as frameworkDefault } from \"@agent-native/core/server\";`,\n `import * as workspaceServer from ${JSON.stringify(`${workspaceCoreName}/server`)};`,\n \"\",\n `const workspacePlugin = (workspaceServer as Record<string, unknown>).${opts.exportName};`,\n \"\",\n 'export default typeof workspacePlugin === \"function\"',\n \" ? workspacePlugin\",\n \" : frameworkDefault;\",\n \"\",\n ].join(\"\\n\"),\n );\n}\n\nfunction writeInheritedStarterAgentChatPlugin(\n appDir: string,\n workspaceCoreName: string,\n appId: string,\n): void {\n const pluginsDir = path.join(appDir, \"server\", \"plugins\");\n fs.mkdirSync(pluginsDir, { recursive: true });\n const pluginPath = path.join(pluginsDir, \"agent-chat.ts\");\n fs.writeFileSync(\n pluginPath,\n [\n `import {`,\n ` createAgentChatPlugin,`,\n ` loadActionsFromStaticRegistry,`,\n ` type AgentChatPluginOptions,`,\n `} from \"@agent-native/core/server\";`,\n `import * as workspaceServer from ${JSON.stringify(`${workspaceCoreName}/server`)};`,\n `import actionsRegistry from \"../../.generated/actions-registry.js\";`,\n \"\",\n `const createWorkspaceAgentChatPlugin = (workspaceServer as Record<string, unknown>).createWorkspaceAgentChatPlugin;`,\n `const options = {`,\n ` appId: ${JSON.stringify(appId)},`,\n ` actions: loadActionsFromStaticRegistry(actionsRegistry),`,\n `} satisfies AgentChatPluginOptions;`,\n \"\",\n `export default typeof createWorkspaceAgentChatPlugin === \"function\"`,\n ` ? (createWorkspaceAgentChatPlugin as (options: AgentChatPluginOptions) => unknown)(options)`,\n ` : createAgentChatPlugin(options);`,\n \"\",\n ].join(\"\\n\"),\n );\n}\n\n/**\n * Parse a workspace core package name into its npm scope.\n * \"@my-company/shared\" → \"my-company\"\n * \"shared\" → \"\" (no scope — shouldn't happen)\n */\nexport function parseWorkspaceScope(workspaceCoreName: string): string {\n const m = workspaceCoreName.match(/^@([^/]+)\\//);\n return m ? m[1] : \"\";\n}\n"]}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export { Turnstile, type TurnstileProps } from "./Turnstile.js";
|
|
|
25
25
|
export { OpenSourceBadge, PoweredByBadge, type OpenSourceBadgeProps, type PoweredByBadgeProps, } from "./PoweredByBadge.js";
|
|
26
26
|
export { FeedbackButton, type FeedbackButtonProps } from "./FeedbackButton.js";
|
|
27
27
|
export { ErrorBoundary } from "./ErrorBoundary.js";
|
|
28
|
+
export { installRouteChunkRecovery } from "./route-chunk-recovery.js";
|
|
28
29
|
export { ClientOnly } from "./ClientOnly.js";
|
|
29
30
|
export { DefaultSpinner } from "./DefaultSpinner.js";
|
|
30
31
|
export { AgentTerminal, type AgentTerminalProps } from "./terminal/index.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,eAAe,EACf,aAAa,EACb,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EACL,eAAe,EACf,UAAU,EACV,WAAW,EACX,OAAO,GACR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EACL,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,GAC7B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,GAC7B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,SAAS,EACT,cAAc,EACd,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,O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
|
+
import { installRouteChunkRecovery } from "./route-chunk-recovery.js";
|
|
2
|
+
installRouteChunkRecovery();
|
|
1
3
|
export { sendToAgentChat, generateTabId, } from "./agent-chat.js";
|
|
2
4
|
export { DEV_MODE_USER_EMAIL } from "./dev-mode.js";
|
|
3
5
|
export { useAgentChatGenerating } from "./use-agent-chat.js";
|
|
@@ -26,6 +28,7 @@ export { Turnstile } from "./Turnstile.js";
|
|
|
26
28
|
export { OpenSourceBadge, PoweredByBadge, } from "./PoweredByBadge.js";
|
|
27
29
|
export { FeedbackButton } from "./FeedbackButton.js";
|
|
28
30
|
export { ErrorBoundary } from "./ErrorBoundary.js";
|
|
31
|
+
export { installRouteChunkRecovery } from "./route-chunk-recovery.js";
|
|
29
32
|
export { ClientOnly } from "./ClientOnly.js";
|
|
30
33
|
export { DefaultSpinner } from "./DefaultSpinner.js";
|
|
31
34
|
export { AgentTerminal } from "./terminal/index.js";
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,aAAa,GAEd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EACL,eAAe,EACf,UAAU,EACV,WAAW,EACX,OAAO,GACR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EACL,aAAa,GAGd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,GAEnB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,kBAAkB,GAEnB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,SAAS,EACT,cAAc,EACd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pC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAEtE,yBAAyB,EAAE,CAAC;AAE5B,OAAO,EACL,eAAe,EACf,aAAa,GAEd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EACL,eAAe,EACf,UAAU,EACV,WAAW,EACX,OAAO,GACR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EACL,aAAa,GAGd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,GAEnB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,kBAAkB,GAEnB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,SAAS,EACT,cAAc,EACd,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,UAAU,EAAoB,MAAM,kBAAkB,CAAC;AAChE,OAAO,EACL,WAAW,EACX,cAAc,EACd,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,GAElB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,GAElB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,mBAAmB,GAGpB,MAAM,0BAA0B,CAAC;AACl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GAKd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,UAAU,EACV,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,yBAAyB,EACzB,YAAY,EACZ,0BAA0B,GAS3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,cAAc,EACd,iBAAiB,GAElB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,WAAW,EACX,WAAW,EACX,eAAe,GAIhB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,YAAY,EACZ,cAAc,EACd,2BAA2B,GAE5B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,sBAAsB,EACtB,cAAc,GACf,MAAM,0BAA0B,CAAC;AAClC,yBAAyB;AACzB,OAAO,EACL,WAAW,GAEZ,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,iBAAiB,GAElB,MAAM,mCAAmC,CAAC;AAC3C,sCAAsC;AACtC,OAAO,EACL,mBAAmB,EACnB,qBAAqB,GAKtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["import { installRouteChunkRecovery } from \"./route-chunk-recovery.js\";\n\ninstallRouteChunkRecovery();\n\nexport {\n sendToAgentChat,\n generateTabId,\n type AgentChatMessage,\n} from \"./agent-chat.js\";\nexport { DEV_MODE_USER_EMAIL } from \"./dev-mode.js\";\nexport { useAgentChatGenerating } from \"./use-agent-chat.js\";\nexport { useDevMode } from \"./use-dev-mode.js\";\nexport {\n agentNativePath,\n appApiPath,\n appBasePath,\n appPath,\n} from \"./api-path.js\";\nexport { useSendToAgentChat } from \"./use-send-to-agent-chat.js\";\nexport {\n useChatModels,\n type UseChatModelsResult,\n type EngineModelGroup,\n} from \"./use-chat-models.js\";\nexport {\n CodeRequiredDialog,\n type CodeRequiredDialogProps,\n} from \"./components/CodeRequiredDialog.js\";\nexport {\n CodeAgentIndicator,\n type CodeAgentIndicatorProps,\n} from \"./components/CodeAgentIndicator.js\";\nexport {\n useDbSync,\n useFileWatcher,\n useScreenRefreshKey,\n} from \"./use-db-sync.js\";\nexport { cn } from \"./utils.js\";\nexport { ApiKeySettings } from \"./components/ApiKeySettings.js\";\nexport { useSession, type AuthSession } from \"./use-session.js\";\nexport {\n sendToFrame,\n onFrameMessage,\n requestUserInfo,\n getFrameOrigin,\n getCallbackOrigin,\n isInFrame,\n enterStyleEditing,\n enterTextEditing,\n exitSelectionMode,\n type UserInfo,\n} from \"./frame.js\";\nexport {\n getBuilderParentOrigin,\n isInBuilderFrame,\n sendToBuilderChat,\n type BuilderChatMessage,\n} from \"./builder-frame.js\";\nexport {\n NewWorkspaceAppFlow,\n type NewWorkspaceAppFlowProps,\n type VaultSecretOption,\n} from \"./NewWorkspaceAppFlow.js\";\nexport {\n AssistantChat,\n clearChatStorage,\n type AssistantChatProps,\n type AssistantChatHandle,\n} from \"./AssistantChat.js\";\nexport {\n MultiTabAssistantChat,\n type MultiTabAssistantChatProps,\n type MultiTabAssistantChatHeaderProps,\n} from \"./MultiTabAssistantChat.js\";\nexport { createAgentChatAdapter } from \"./agent-chat-adapter.js\";\nexport {\n useChatThreads,\n type ChatThreadSummary,\n type ChatThreadData,\n} from \"./use-chat-threads.js\";\nexport {\n AgentPanel,\n AgentSidebar,\n AgentToggleButton,\n focusAgentChat,\n type AgentPanelProps,\n type AgentSidebarProps,\n} from \"./AgentPanel.js\";\n// Deprecated — use AgentSidebar + AgentToggleButton instead\nexport {\n ProductionAgentPanel,\n type ProductionAgentPanelProps,\n} from \"./ProductionAgentPanel.js\";\nexport {\n useProductionAgent,\n type ProductionAgentMessage,\n type UseProductionAgentOptions,\n type UseProductionAgentResult,\n} from \"./useProductionAgent.js\";\nexport { Turnstile, type TurnstileProps } from \"./Turnstile.js\";\nexport {\n OpenSourceBadge,\n PoweredByBadge,\n type OpenSourceBadgeProps,\n type PoweredByBadgeProps,\n} from \"./PoweredByBadge.js\";\nexport { FeedbackButton, type FeedbackButtonProps } from \"./FeedbackButton.js\";\nexport { ErrorBoundary } from \"./ErrorBoundary.js\";\nexport { installRouteChunkRecovery } from \"./route-chunk-recovery.js\";\nexport { ClientOnly } from \"./ClientOnly.js\";\nexport { DefaultSpinner } from \"./DefaultSpinner.js\";\nexport { AgentTerminal, type AgentTerminalProps } from \"./terminal/index.js\";\nexport {\n trackEvent,\n trackSessionStatus,\n configureTracking,\n} from \"./analytics.js\";\nexport {\n useCollaborativeDoc,\n emailToColor,\n emailToName,\n type UseCollaborativeDocOptions,\n type UseCollaborativeDocResult,\n type CollabUser,\n} from \"../collab/client.js\";\nexport {\n ResourcesPanel,\n ResourceTree,\n ResourceEditor,\n useResources,\n useResourceTree,\n useResource,\n useCreateResource,\n useUpdateResource,\n useDeleteResource,\n useUploadResource,\n type Resource,\n type ResourceMeta,\n type TreeNode,\n type ResourceScope,\n type ResourceTreeProps,\n type ResourceEditorProps,\n} from \"./resources/index.js\";\nexport type {\n AppToFrameMessage,\n FrameToAppMessage,\n FrameMessage,\n CodeCompleteMessage,\n ChatRunningMessage,\n} from \"./frame-protocol.js\";\nexport {\n CommandMenu,\n useCommandMenuShortcut,\n openAgentSidebar,\n submitToAgent,\n type CommandMenuProps,\n type CommandGroupProps,\n type CommandItemProps,\n type CommandShortcutProps,\n} from \"./CommandMenu.js\";\nexport {\n DevOverlay,\n useDevOverlayShortcut,\n registerDevPanel,\n unregisterDevPanel,\n listDevPanels,\n subscribeDevPanels,\n useDevOption,\n clearAllDevOverlayStorage,\n devOptionKey,\n DEV_OVERLAY_STORAGE_PREFIX,\n type DevOverlayProps,\n type DevPanel,\n type DevOption,\n type DevBooleanOption,\n type DevSelectOption,\n type DevStringOption,\n type DevActionOption,\n type DevOptionValue,\n} from \"./dev-overlay/index.js\";\nexport {\n useActionQuery,\n useActionMutation,\n type ActionRegistry,\n} from \"./use-action.js\";\nexport {\n ShareButton,\n ShareDialog,\n VisibilityBadge,\n type ShareButtonProps,\n type ShareDialogProps,\n type VisibilityBadgeProps,\n} from \"./sharing/index.js\";\nexport {\n postNavigate,\n isInAgentEmbed,\n AGENT_NAVIGATE_MESSAGE_TYPE,\n type AgentNavigateMessage,\n} from \"./embed.js\";\nexport { IframeEmbed, parseEmbedBody } from \"./IframeEmbed.js\";\nexport {\n useAvatarUrl,\n uploadAvatar,\n invalidateAvatarCache,\n} from \"./use-avatar.js\";\nexport {\n ObservabilityDashboard,\n ThumbsFeedback,\n} from \"./observability/index.js\";\n// Presence UI components\nexport {\n PresenceBar,\n type PresenceBarProps,\n} from \"./components/PresenceBar.js\";\nexport {\n AgentPresenceChip,\n type AgentPresenceChipProps,\n} from \"./components/AgentPresenceChip.js\";\n// Structured data collaboration hooks\nexport {\n useCollaborativeMap,\n useCollaborativeArray,\n type UseCollaborativeMapOptions,\n type UseCollaborativeMapResult,\n type UseCollaborativeArrayOptions,\n type UseCollaborativeArrayResult,\n} from \"../collab/client-struct.js\";\nexport { NotificationsBell } from \"./notifications/index.js\";\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface RouteChunkRecoveryState {
|
|
2
|
+
intendedHref: string | null;
|
|
3
|
+
intendedAt: number;
|
|
4
|
+
routeModuleFailureAt: number;
|
|
5
|
+
recoveryHref: string | null;
|
|
6
|
+
recovering: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function createRouteChunkRecoveryState(): RouteChunkRecoveryState;
|
|
9
|
+
export declare function isRouteModuleReloadMessage(value: unknown): boolean;
|
|
10
|
+
export declare function isDynamicImportFailureMessage(value: unknown): boolean;
|
|
11
|
+
export declare function rememberIntendedNavigation(state: RouteChunkRecoveryState, href: string, now?: number): void;
|
|
12
|
+
export declare function getFreshIntendedNavigation(state: RouteChunkRecoveryState, currentHref: string, now?: number): string | null;
|
|
13
|
+
export declare function intendedHrefFromClick(win: Window, event: MouseEvent): string | null;
|
|
14
|
+
export declare function installRouteChunkRecovery(win?: Window | undefined): void;
|
|
15
|
+
//# sourceMappingURL=route-chunk-recovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-chunk-recovery.d.ts","sourceRoot":"","sources":["../../src/client/route-chunk-recovery.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,wBAAgB,6BAA6B,IAAI,uBAAuB,CAQvE;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAKlE;AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAOrE;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,uBAAuB,EAC9B,IAAI,EAAE,MAAM,EACZ,GAAG,SAAa,GACf,IAAI,CAGN;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,uBAAuB,EAC9B,WAAW,EAAE,MAAM,EACnB,GAAG,SAAa,GACf,MAAM,GAAG,IAAI,CAKf;AA2BD,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,UAAU,GAChB,MAAM,GAAG,IAAI,CAaf;AAuED,wBAAgB,yBAAyB,CACvC,GAAG,GAAE,MAAM,GAAG,SAA8D,QAuD7E"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
const INSTALL_KEY = "__agentNativeRouteChunkRecoveryInstalled";
|
|
2
|
+
const INTENDED_NAV_MAX_AGE_MS = 15_000;
|
|
3
|
+
export function createRouteChunkRecoveryState() {
|
|
4
|
+
return {
|
|
5
|
+
intendedHref: null,
|
|
6
|
+
intendedAt: 0,
|
|
7
|
+
routeModuleFailureAt: 0,
|
|
8
|
+
recoveryHref: null,
|
|
9
|
+
recovering: false,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function isRouteModuleReloadMessage(value) {
|
|
13
|
+
return (typeof value === "string" &&
|
|
14
|
+
/Error loading route module `[^`]+`, reloading page\.\.\./.test(value));
|
|
15
|
+
}
|
|
16
|
+
export function isDynamicImportFailureMessage(value) {
|
|
17
|
+
if (typeof value !== "string")
|
|
18
|
+
return false;
|
|
19
|
+
return (value.includes("Failed to fetch dynamically imported module") ||
|
|
20
|
+
value.includes("error loading dynamically imported module") ||
|
|
21
|
+
value.includes("Importing a module script failed"));
|
|
22
|
+
}
|
|
23
|
+
export function rememberIntendedNavigation(state, href, now = Date.now()) {
|
|
24
|
+
state.intendedHref = href;
|
|
25
|
+
state.intendedAt = now;
|
|
26
|
+
}
|
|
27
|
+
export function getFreshIntendedNavigation(state, currentHref, now = Date.now()) {
|
|
28
|
+
if (!state.intendedHref)
|
|
29
|
+
return null;
|
|
30
|
+
if (now - state.intendedAt > INTENDED_NAV_MAX_AGE_MS)
|
|
31
|
+
return null;
|
|
32
|
+
if (state.intendedHref === currentHref)
|
|
33
|
+
return null;
|
|
34
|
+
return state.intendedHref;
|
|
35
|
+
}
|
|
36
|
+
function anchorFromTarget(target) {
|
|
37
|
+
let node = target;
|
|
38
|
+
while (node) {
|
|
39
|
+
if (node.tagName?.toUpperCase() === "A" &&
|
|
40
|
+
typeof node.href === "string") {
|
|
41
|
+
return node;
|
|
42
|
+
}
|
|
43
|
+
node = node.parentElement;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
function sameOriginHref(win, href) {
|
|
48
|
+
try {
|
|
49
|
+
const url = new URL(href, win.location.href);
|
|
50
|
+
return url.origin === win.location.origin ? url.href : null;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function intendedHrefFromClick(win, event) {
|
|
57
|
+
if (event.defaultPrevented)
|
|
58
|
+
return null;
|
|
59
|
+
if (event.button !== 0)
|
|
60
|
+
return null;
|
|
61
|
+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
const anchor = anchorFromTarget(event.target);
|
|
65
|
+
if (!anchor)
|
|
66
|
+
return null;
|
|
67
|
+
if (anchor.hasAttribute("download"))
|
|
68
|
+
return null;
|
|
69
|
+
const target = anchor.getAttribute("target");
|
|
70
|
+
if (target && target !== "_self")
|
|
71
|
+
return null;
|
|
72
|
+
return sameOriginHref(win, anchor.href);
|
|
73
|
+
}
|
|
74
|
+
function hardNavigate(win, href) {
|
|
75
|
+
try {
|
|
76
|
+
win.location.assign(href);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
win.location.href = href;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function recoverToIntendedNavigation(win, state) {
|
|
83
|
+
const target = getFreshIntendedNavigation(state, win.location.href);
|
|
84
|
+
if (!target)
|
|
85
|
+
return false;
|
|
86
|
+
state.recovering = true;
|
|
87
|
+
state.recoveryHref = target;
|
|
88
|
+
try {
|
|
89
|
+
win.history.replaceState(win.history.state, "", target);
|
|
90
|
+
}
|
|
91
|
+
catch { }
|
|
92
|
+
hardNavigate(win, target);
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
function patchHistoryMethod(win, state, method) {
|
|
96
|
+
const original = win.history[method];
|
|
97
|
+
win.history[method] = function patchedHistoryMethod(...args) {
|
|
98
|
+
if (typeof args[2] === "string" || args[2] instanceof URL) {
|
|
99
|
+
const href = sameOriginHref(win, String(args[2]));
|
|
100
|
+
if (href)
|
|
101
|
+
rememberIntendedNavigation(state, href);
|
|
102
|
+
}
|
|
103
|
+
return original.apply(this, args);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function patchReload(win, state) {
|
|
107
|
+
const originalReload = win.location.reload.bind(win.location);
|
|
108
|
+
const patchedReload = function patchedReload() {
|
|
109
|
+
if (state.recoveryHref &&
|
|
110
|
+
Date.now() - state.routeModuleFailureAt <= 1_000) {
|
|
111
|
+
hardNavigate(win, state.recoveryHref);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (Date.now() - state.routeModuleFailureAt <= 1_000 &&
|
|
115
|
+
recoverToIntendedNavigation(win, state)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
originalReload();
|
|
119
|
+
};
|
|
120
|
+
try {
|
|
121
|
+
Object.defineProperty(win.location, "reload", {
|
|
122
|
+
configurable: true,
|
|
123
|
+
value: patchedReload,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
try {
|
|
128
|
+
win.location.reload = patchedReload;
|
|
129
|
+
}
|
|
130
|
+
catch { }
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export function installRouteChunkRecovery(win = typeof window === "undefined" ? undefined : window) {
|
|
134
|
+
const consoleRef = win
|
|
135
|
+
?.console;
|
|
136
|
+
if (!win?.document ||
|
|
137
|
+
!win.location ||
|
|
138
|
+
!win.history ||
|
|
139
|
+
typeof win.addEventListener !== "function" ||
|
|
140
|
+
!consoleRef) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const installedTarget = win;
|
|
144
|
+
if (installedTarget[INSTALL_KEY])
|
|
145
|
+
return;
|
|
146
|
+
installedTarget[INSTALL_KEY] = true;
|
|
147
|
+
const state = createRouteChunkRecoveryState();
|
|
148
|
+
win.document.addEventListener("click", (event) => {
|
|
149
|
+
const href = intendedHrefFromClick(win, event);
|
|
150
|
+
if (href)
|
|
151
|
+
rememberIntendedNavigation(state, href);
|
|
152
|
+
}, true);
|
|
153
|
+
patchHistoryMethod(win, state, "pushState");
|
|
154
|
+
patchHistoryMethod(win, state, "replaceState");
|
|
155
|
+
patchReload(win, state);
|
|
156
|
+
win.addEventListener("unhandledrejection", (event) => {
|
|
157
|
+
const reason = event.reason;
|
|
158
|
+
const message = String(reason?.message || reason || "");
|
|
159
|
+
if (!isDynamicImportFailureMessage(message))
|
|
160
|
+
return;
|
|
161
|
+
state.routeModuleFailureAt = Date.now();
|
|
162
|
+
if (recoverToIntendedNavigation(win, state)) {
|
|
163
|
+
event.preventDefault();
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
// React Router catches stale route-module import failures and reloads the
|
|
167
|
+
// current URL. Its console message is the only signal exposed before reload.
|
|
168
|
+
const originalError = consoleRef.error.bind(consoleRef);
|
|
169
|
+
try {
|
|
170
|
+
consoleRef.error = (...args) => {
|
|
171
|
+
if (args.some(isRouteModuleReloadMessage)) {
|
|
172
|
+
state.routeModuleFailureAt = Date.now();
|
|
173
|
+
recoverToIntendedNavigation(win, state);
|
|
174
|
+
}
|
|
175
|
+
originalError(...args);
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
catch { }
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=route-chunk-recovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-chunk-recovery.js","sourceRoot":"","sources":["../../src/client/route-chunk-recovery.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,0CAA0C,CAAC;AAC/D,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAUvC,MAAM,UAAU,6BAA6B;IAC3C,OAAO;QACL,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,CAAC;QACb,oBAAoB,EAAE,CAAC;QACvB,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,KAAK;KAClB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,KAAc;IACvD,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,0DAA0D,CAAC,IAAI,CAAC,KAAK,CAAC,CAC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AAI,CAAC,0BAA0B,CAAC,EAAE,CAAC;gBAC1C,KAAK,CAAC,oBAAoB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBACxC,2BAA2B,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAC1C,CAAC;YACD,aAAa,CAAC,GAAG,IAAI,CAAC,CAAC;QACzB,CAAC,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;AACZ,CAAC","sourcesContent":["const INSTALL_KEY = \"__agentNativeRouteChunkRecoveryInstalled\";\nconst INTENDED_NAV_MAX_AGE_MS = 15_000;\n\nexport interface RouteChunkRecoveryState {\n intendedHref: string | null;\n intendedAt: number;\n routeModuleFailureAt: number;\n recoveryHref: string | null;\n recovering: boolean;\n}\n\nexport function createRouteChunkRecoveryState(): RouteChunkRecoveryState {\n return {\n intendedHref: null,\n intendedAt: 0,\n routeModuleFailureAt: 0,\n recoveryHref: null,\n recovering: false,\n };\n}\n\nexport function isRouteModuleReloadMessage(value: unknown): boolean {\n return (\n typeof value === \"string\" &&\n /Error loading route module `[^`]+`, reloading page\\.\\.\\./.test(value)\n );\n}\n\nexport function isDynamicImportFailureMessage(value: unknown): boolean {\n if (typeof value !== \"string\") return false;\n return (\n value.includes(\"Failed to fetch dynamically imported module\") ||\n value.includes(\"error loading dynamically imported module\") ||\n value.includes(\"Importing a module script failed\")\n );\n}\n\nexport function rememberIntendedNavigation(\n state: RouteChunkRecoveryState,\n href: string,\n now = Date.now(),\n): void {\n state.intendedHref = href;\n state.intendedAt = now;\n}\n\nexport function getFreshIntendedNavigation(\n state: RouteChunkRecoveryState,\n currentHref: string,\n now = Date.now(),\n): string | null {\n if (!state.intendedHref) return null;\n if (now - state.intendedAt > INTENDED_NAV_MAX_AGE_MS) return null;\n if (state.intendedHref === currentHref) return null;\n return state.intendedHref;\n}\n\nfunction anchorFromTarget(\n target: EventTarget | null,\n): HTMLAnchorElement | null {\n let node = target as HTMLElement | null;\n while (node) {\n if (\n node.tagName?.toUpperCase() === \"A\" &&\n typeof (node as HTMLAnchorElement).href === \"string\"\n ) {\n return node as HTMLAnchorElement;\n }\n node = node.parentElement;\n }\n return null;\n}\n\nfunction sameOriginHref(win: Window, href: string): string | null {\n try {\n const url = new URL(href, win.location.href);\n return url.origin === win.location.origin ? url.href : null;\n } catch {\n return null;\n }\n}\n\nexport function intendedHrefFromClick(\n win: Window,\n event: MouseEvent,\n): string | null {\n if (event.defaultPrevented) return null;\n if (event.button !== 0) return null;\n if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {\n return null;\n }\n\n const anchor = anchorFromTarget(event.target);\n if (!anchor) return null;\n if (anchor.hasAttribute(\"download\")) return null;\n const target = anchor.getAttribute(\"target\");\n if (target && target !== \"_self\") return null;\n return sameOriginHref(win, anchor.href);\n}\n\nfunction hardNavigate(win: Window, href: string): void {\n try {\n win.location.assign(href);\n } catch {\n win.location.href = href;\n }\n}\n\nfunction recoverToIntendedNavigation(\n win: Window,\n state: RouteChunkRecoveryState,\n): boolean {\n const target = getFreshIntendedNavigation(state, win.location.href);\n if (!target) return false;\n state.recovering = true;\n state.recoveryHref = target;\n try {\n win.history.replaceState(win.history.state, \"\", target);\n } catch {}\n hardNavigate(win, target);\n return true;\n}\n\nfunction patchHistoryMethod(\n win: Window,\n state: RouteChunkRecoveryState,\n method: \"pushState\" | \"replaceState\",\n): void {\n const original = win.history[method];\n win.history[method] = function patchedHistoryMethod(...args) {\n if (typeof args[2] === \"string\" || args[2] instanceof URL) {\n const href = sameOriginHref(win, String(args[2]));\n if (href) rememberIntendedNavigation(state, href);\n }\n return original.apply(this, args);\n };\n}\n\nfunction patchReload(win: Window, state: RouteChunkRecoveryState): void {\n const originalReload = win.location.reload.bind(win.location);\n const patchedReload = function patchedReload() {\n if (\n state.recoveryHref &&\n Date.now() - state.routeModuleFailureAt <= 1_000\n ) {\n hardNavigate(win, state.recoveryHref);\n return;\n }\n if (\n Date.now() - state.routeModuleFailureAt <= 1_000 &&\n recoverToIntendedNavigation(win, state)\n ) {\n return;\n }\n originalReload();\n };\n\n try {\n Object.defineProperty(win.location, \"reload\", {\n configurable: true,\n value: patchedReload,\n });\n } catch {\n try {\n win.location.reload = patchedReload;\n } catch {}\n }\n}\n\nexport function installRouteChunkRecovery(\n win: Window | undefined = typeof window === \"undefined\" ? undefined : window,\n) {\n const consoleRef = (win as unknown as { console?: Console } | undefined)\n ?.console;\n if (\n !win?.document ||\n !win.location ||\n !win.history ||\n typeof win.addEventListener !== \"function\" ||\n !consoleRef\n ) {\n return;\n }\n\n const installedTarget = win as unknown as Record<string, boolean>;\n if (installedTarget[INSTALL_KEY]) return;\n installedTarget[INSTALL_KEY] = true;\n\n const state = createRouteChunkRecoveryState();\n\n win.document.addEventListener(\n \"click\",\n (event) => {\n const href = intendedHrefFromClick(win, event);\n if (href) rememberIntendedNavigation(state, href);\n },\n true,\n );\n\n patchHistoryMethod(win, state, \"pushState\");\n patchHistoryMethod(win, state, \"replaceState\");\n patchReload(win, state);\n\n win.addEventListener(\"unhandledrejection\", (event) => {\n const reason = (event as PromiseRejectionEvent).reason;\n const message = String(reason?.message || reason || \"\");\n if (!isDynamicImportFailureMessage(message)) return;\n state.routeModuleFailureAt = Date.now();\n if (recoverToIntendedNavigation(win, state)) {\n event.preventDefault();\n }\n });\n\n // React Router catches stale route-module import failures and reloads the\n // current URL. Its console message is the only signal exposed before reload.\n const originalError = consoleRef.error.bind(consoleRef);\n try {\n consoleRef.error = (...args: unknown[]) => {\n if (args.some(isRouteModuleReloadMessage)) {\n state.routeModuleFailureAt = Date.now();\n recoverToIntendedNavigation(win, state);\n }\n originalError(...args);\n };\n } catch {}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"a2a-continuations-store.d.ts","sourceRoot":"","sources":["../../src/integrations/a2a-continuations-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"a2a-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B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,GAAG,OAAO,CAAC,eAAe,CAAC,CA6C3B;AAED,wBAAsB,oCAAoC,CACxD,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAWjC;AA8BD,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAQjC;AAED,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CA0CjC;AAED,wBAAsB,wBAAwB,CAC5C,KAAK,SAAI,GACR,OAAO,CAAC,eAAe,EAAE,CAAC,CAmC5B;AAED,wBAAsB,4BAA4B,CAChD,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CA0BjC;AAED,wBAAsB,yBAAyB,CAC7C,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC,CAUf;AAED,wBAAsB,uBAAuB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUvE;AAED,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,MAAM,EACV,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC,CAUf"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getDbExec, isPostgres, intType } from "../db/client.js";
|
|
2
2
|
let _initPromise;
|
|
3
3
|
const PROCESSING_STUCK_AFTER_MS = 5 * 60 * 1000;
|
|
4
|
+
const PROCESSING_NEXT_CHECK_STALE_AFTER_MS = 60 * 1000;
|
|
4
5
|
async function ensureTable() {
|
|
5
6
|
if (!_initPromise) {
|
|
6
7
|
_initPromise = (async () => {
|
|
@@ -156,18 +157,31 @@ export async function claimA2AContinuation(id) {
|
|
|
156
157
|
const client = getDbExec();
|
|
157
158
|
const now = Date.now();
|
|
158
159
|
const processingCutoff = now - PROCESSING_STUCK_AFTER_MS;
|
|
160
|
+
const staleNextCheckCutoff = now - PROCESSING_NEXT_CHECK_STALE_AFTER_MS;
|
|
159
161
|
const result = await client.execute({
|
|
160
162
|
sql: isPostgres()
|
|
161
163
|
? `UPDATE integration_a2a_continuations
|
|
162
164
|
SET status = ?, attempts = attempts + 1, updated_at = ?
|
|
163
165
|
WHERE id = ?
|
|
164
|
-
AND (
|
|
166
|
+
AND (
|
|
167
|
+
status = 'pending'
|
|
168
|
+
OR (
|
|
169
|
+
status = 'processing'
|
|
170
|
+
AND (updated_at <= ? OR next_check_at <= ?)
|
|
171
|
+
)
|
|
172
|
+
)
|
|
165
173
|
RETURNING *`
|
|
166
174
|
: `UPDATE integration_a2a_continuations
|
|
167
175
|
SET status = ?, attempts = attempts + 1, updated_at = ?
|
|
168
176
|
WHERE id = ?
|
|
169
|
-
AND (
|
|
170
|
-
|
|
177
|
+
AND (
|
|
178
|
+
status = 'pending'
|
|
179
|
+
OR (
|
|
180
|
+
status = 'processing'
|
|
181
|
+
AND (updated_at <= ? OR next_check_at <= ?)
|
|
182
|
+
)
|
|
183
|
+
)`,
|
|
184
|
+
args: ["processing", now, id, processingCutoff, staleNextCheckCutoff],
|
|
171
185
|
});
|
|
172
186
|
const rows = result.rows ?? [];
|
|
173
187
|
if (isPostgres()) {
|
|
@@ -187,6 +201,8 @@ export async function claimDueA2AContinuations(limit = 5) {
|
|
|
187
201
|
await ensureTable();
|
|
188
202
|
const client = getDbExec();
|
|
189
203
|
const now = Date.now();
|
|
204
|
+
const processingCutoff = now - PROCESSING_STUCK_AFTER_MS;
|
|
205
|
+
const staleNextCheckCutoff = now - PROCESSING_NEXT_CHECK_STALE_AFTER_MS;
|
|
190
206
|
// If a processor dies while holding a delivery claim, retry the final send.
|
|
191
207
|
// The stale cutoff preserves the in-flight delivery guard while keeping
|
|
192
208
|
// final integration replies at-least-once.
|
|
@@ -199,8 +215,9 @@ export async function claimDueA2AContinuations(limit = 5) {
|
|
|
199
215
|
await client.execute({
|
|
200
216
|
sql: `UPDATE integration_a2a_continuations
|
|
201
217
|
SET status = ?, next_check_at = ?, updated_at = ?
|
|
202
|
-
WHERE status = 'processing'
|
|
203
|
-
|
|
218
|
+
WHERE status = 'processing'
|
|
219
|
+
AND (updated_at <= ? OR next_check_at <= ?)`,
|
|
220
|
+
args: ["pending", now, now, processingCutoff, staleNextCheckCutoff],
|
|
204
221
|
});
|
|
205
222
|
const { rows } = await client.execute({
|
|
206
223
|
sql: `SELECT id FROM integration_a2a_continuations
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"a2a-continuations-store.js","sourceRoot":"","sources":["../../src/integrations/a2a-continuations-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAGjE,IAAI,YAAuC,CAAC;AAC5C,MAAM,yBAAyB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAEhD,KAAK,UAAU,WAAW;IACxB,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,CAAC,KAAK,IAAI,EAAE;YACzB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;YAC3B,MAAM,MAAM,CAAC,OAAO,CAAC;;;;;;;;;;;;;;;qBAeN,OAAO,EAAE;0BACJ,OAAO,EAAE;;uBAEZ,OAAO,EAAE;uBACT,OAAO,EAAE;yBACP,OAAO,EAAE;;OAE3B,CAAC,CAAC;YACH,MAAM,MAAM,CAAC,OAAO,CAClB,sHAAsH,CACvH,CAAC;YACF,MAAM,MAAM,CAAC,OAAO,CAClB,yHAAyH,CAC1H,CAAC;YACF,MAAM,MAAM,CAAC,OAAO,CAClB,mJAAmJ,CACpJ,CAAC;YACF,IAAI,CAAC;gBACH,MAAM,MAAM,CAAC,OAAO,CAClB,0E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,SAAS,EAAE,CAAC;IAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,MAAM,CAAC,OAAO,CAAC;QACnB,GAAG,EAAE;;kEAEyD;QAC9D,IAAI,EAAE,CAAC,SAAS,EAAE,GAAG,GAAG,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC;KAC1C,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,EAAU;IACtD,MAAM,WAAW,EAAE,CAAC;IACpB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,MAAM,CAAC,OAAO,CAAC;QACnB,GAAG,EAAE;;+EAEsE;QAC3E,IAAI,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC;KAClC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,EAAU,EACV,YAAoB;IAEpB,MAAM,WAAW,EAAE,CAAC;IACpB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,MAAM,CAAC,OAAO,CAAC;QACnB,GAAG,EAAE;;iDAEwC;QAC7C,IAAI,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;KACvD,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { getDbExec, isPostgres, intType } from \"../db/client.js\";\nimport type { IncomingMessage } from \"./types.js\";\n\nlet _initPromise: Promise<void> | undefined;\nconst PROCESSING_STUCK_AFTER_MS = 5 * 60 * 1000;\n\nasync function ensureTable(): Promise<void> {\n if (!_initPromise) {\n _initPromise = (async () => {\n const client = getDbExec();\n await client.execute(`\n CREATE TABLE IF NOT EXISTS integration_a2a_continuations (\n id TEXT PRIMARY KEY,\n integration_task_id TEXT NOT NULL,\n platform TEXT NOT NULL,\n external_thread_id TEXT NOT NULL,\n incoming_payload TEXT NOT NULL,\n placeholder_ref TEXT,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n agent_name TEXT NOT NULL,\n agent_url TEXT NOT NULL,\n a2a_task_id TEXT NOT NULL,\n a2a_auth_token TEXT,\n status TEXT NOT NULL,\n attempts ${intType()} NOT NULL DEFAULT 0,\n next_check_at ${intType()} NOT NULL,\n error_message TEXT,\n created_at ${intType()} NOT NULL,\n updated_at ${intType()} NOT NULL,\n completed_at ${intType()}\n )\n `);\n await client.execute(\n `CREATE INDEX IF NOT EXISTS idx_a2a_continuations_status_next ON integration_a2a_continuations(status, next_check_at)`,\n );\n await client.execute(\n `CREATE INDEX IF NOT EXISTS idx_a2a_continuations_integration_task ON integration_a2a_continuations(integration_task_id)`,\n );\n await client.execute(\n `CREATE UNIQUE INDEX IF NOT EXISTS idx_a2a_continuations_remote_task ON integration_a2a_continuations(integration_task_id, agent_url, a2a_task_id)`,\n );\n try {\n await client.execute(\n `ALTER TABLE integration_a2a_continuations ADD COLUMN a2a_auth_token TEXT`,\n );\n } catch {\n // Column already exists.\n }\n })();\n }\n return _initPromise;\n}\n\nexport type A2AContinuationStatus =\n | \"pending\"\n | \"processing\"\n | \"delivering\"\n | \"completed\"\n | \"failed\";\n\nexport interface A2AContinuation {\n id: string;\n integrationTaskId: string;\n platform: string;\n externalThreadId: string;\n incoming: IncomingMessage;\n placeholderRef: string | null;\n ownerEmail: string;\n orgId: string | null;\n agentName: string;\n agentUrl: string;\n a2aTaskId: string;\n a2aAuthToken: string | null;\n status: A2AContinuationStatus;\n attempts: number;\n nextCheckAt: number;\n errorMessage: string | null;\n createdAt: number;\n updatedAt: number;\n completedAt: number | null;\n}\n\nfunction rowToContinuation(row: Record<string, unknown>): A2AContinuation {\n return {\n id: row.id as string,\n integrationTaskId: row.integration_task_id as string,\n platform: row.platform as string,\n externalThreadId: row.external_thread_id as string,\n incoming: JSON.parse(row.incoming_payload as string) as IncomingMessage,\n placeholderRef: (row.placeholder_ref as string | null) ?? null,\n ownerEmail: row.owner_email as string,\n orgId: (row.org_id as string | null) ?? null,\n agentName: row.agent_name as string,\n agentUrl: row.agent_url as string,\n a2aTaskId: row.a2a_task_id as string,\n a2aAuthToken: (row.a2a_auth_token as string | null) ?? null,\n status: row.status as A2AContinuationStatus,\n attempts: Number(row.attempts ?? 0),\n nextCheckAt: Number(row.next_check_at ?? 0),\n errorMessage: (row.error_message as string | null) ?? null,\n createdAt: Number(row.created_at ?? 0),\n updatedAt: Number(row.updated_at ?? 0),\n completedAt:\n row.completed_at == null ? null : Number(row.completed_at as number),\n };\n}\n\nexport async function insertA2AContinuation(input: {\n integrationTaskId: string;\n platform: string;\n externalThreadId: string;\n incoming: IncomingMessage;\n placeholderRef?: string | null;\n ownerEmail: string;\n orgId?: string | null;\n agentName: string;\n agentUrl: string;\n a2aTaskId: string;\n a2aAuthToken?: string | null;\n}): Promise<A2AContinuation> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const id = `a2a-cont-${now}-${Math.random().toString(36).slice(2, 8)}`;\n const payload = JSON.stringify(input.incoming);\n\n try {\n await client.execute({\n sql: `INSERT INTO integration_a2a_continuations\n (id, integration_task_id, platform, external_thread_id, incoming_payload,\n placeholder_ref, owner_email, org_id, agent_name, agent_url, a2a_task_id, a2a_auth_token,\n status, attempts, next_check_at, created_at, updated_at)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n args: [\n id,\n input.integrationTaskId,\n input.platform,\n input.externalThreadId,\n payload,\n input.placeholderRef ?? null,\n input.ownerEmail,\n input.orgId ?? null,\n input.agentName,\n input.agentUrl,\n input.a2aTaskId,\n input.a2aAuthToken ?? null,\n \"pending\",\n 0,\n now,\n now,\n now,\n ],\n });\n return (await getA2AContinuation(id))!;\n } catch (err: any) {\n if (!isDuplicateContinuationError(err)) throw err;\n const existing = await findA2AContinuation(\n input.integrationTaskId,\n input.agentUrl,\n input.a2aTaskId,\n );\n if (existing) return existing;\n throw err;\n }\n}\n\nexport async function getA2AContinuationForIntegrationTask(\n integrationTaskId: string,\n): Promise<A2AContinuation | null> {\n await ensureTable();\n const client = getDbExec();\n const { rows } = await client.execute({\n sql: `SELECT * FROM integration_a2a_continuations\n WHERE integration_task_id = ?\n ORDER BY created_at ASC\n LIMIT 1`,\n args: [integrationTaskId],\n });\n return rows[0] ? rowToContinuation(rows[0] as Record<string, unknown>) : null;\n}\n\nfunction isDuplicateContinuationError(err: unknown): boolean {\n const e = err as { code?: string; message?: string } | null;\n if (!e) return false;\n if (e.code === \"23505\") return true;\n const msg = String(e.message ?? \"\").toLowerCase();\n return (\n msg.includes(\"unique\") ||\n msg.includes(\"duplicate entry\") ||\n msg.includes(\"duplicate key\")\n );\n}\n\nasync function findA2AContinuation(\n integrationTaskId: string,\n agentUrl: string,\n a2aTaskId: string,\n): Promise<A2AContinuation | null> {\n await ensureTable();\n const client = getDbExec();\n const { rows } = await client.execute({\n sql: `SELECT * FROM integration_a2a_continuations\n WHERE integration_task_id = ? AND agent_url = ? AND a2a_task_id = ?\n LIMIT 1`,\n args: [integrationTaskId, agentUrl, a2aTaskId],\n });\n return rows[0] ? rowToContinuation(rows[0] as Record<string, unknown>) : null;\n}\n\nexport async function getA2AContinuation(\n id: string,\n): Promise<A2AContinuation | null> {\n await ensureTable();\n const client = getDbExec();\n const { rows } = await client.execute({\n sql: `SELECT * FROM integration_a2a_continuations WHERE id = ? LIMIT 1`,\n args: [id],\n });\n return rows[0] ? rowToContinuation(rows[0] as Record<string, unknown>) : null;\n}\n\nexport async function claimA2AContinuation(\n id: string,\n): Promise<A2AContinuation | null> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const processingCutoff = now - PROCESSING_STUCK_AFTER_MS;\n const result = await client.execute({\n sql: isPostgres()\n ? `UPDATE integration_a2a_continuations\n SET status = ?, attempts = attempts + 1, updated_at = ?\n WHERE id = ?\n AND (status = 'pending' OR (status = 'processing' AND updated_at <= ?))\n RETURNING *`\n : `UPDATE integration_a2a_continuations\n SET status = ?, attempts = attempts + 1, updated_at = ?\n WHERE id = ?\n AND (status = 'pending' OR (status = 'processing' AND updated_at <= ?))`,\n args: [\"processing\", now, id, processingCutoff],\n });\n const rows = result.rows ?? [];\n if (isPostgres()) {\n return rows[0]\n ? rowToContinuation(rows[0] as Record<string, unknown>)\n : null;\n }\n const affected = (result as any)?.rowsAffected ?? (result as any)?.rowCount;\n if (affected === 0) return null;\n const fetched = await getA2AContinuation(id);\n if (!fetched || fetched.status !== \"processing\") return null;\n return fetched;\n}\n\nexport async function claimDueA2AContinuations(\n limit = 5,\n): Promise<A2AContinuation[]> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n // If a processor dies while holding a delivery claim, retry the final send.\n // The stale cutoff preserves the in-flight delivery guard while keeping\n // final integration replies at-least-once.\n await client.execute({\n sql: `UPDATE integration_a2a_continuations\n SET status = ?, next_check_at = ?, updated_at = ?\n WHERE status = 'delivering' AND updated_at <= ?`,\n args: [\"pending\", now, now, now - 5 * 60 * 1000],\n });\n await client.execute({\n sql: `UPDATE integration_a2a_continuations\n SET status = ?, next_check_at = ?, updated_at = ?\n WHERE status = 'processing' AND updated_at <= ?`,\n args: [\"pending\", now, now, now - 5 * 60 * 1000],\n });\n const { rows } = await client.execute({\n sql: `SELECT id FROM integration_a2a_continuations\n WHERE status = 'pending' AND next_check_at <= ?\n ORDER BY next_check_at ASC\n LIMIT ?`,\n args: [now, limit],\n });\n const claimed: A2AContinuation[] = [];\n for (const row of rows) {\n const continuation = await claimA2AContinuation(row.id as string);\n if (continuation) claimed.push(continuation);\n }\n return claimed;\n}\n\nexport async function claimA2AContinuationDelivery(\n id: string,\n): Promise<A2AContinuation | null> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const result = await client.execute({\n sql: isPostgres()\n ? `UPDATE integration_a2a_continuations\n SET status = ?, updated_at = ?\n WHERE id = ? AND status = 'processing'\n RETURNING *`\n : `UPDATE integration_a2a_continuations\n SET status = ?, updated_at = ?\n WHERE id = ? AND status = 'processing'`,\n args: [\"delivering\", now, id],\n });\n const rows = result.rows ?? [];\n if (isPostgres()) {\n return rows[0]\n ? rowToContinuation(rows[0] as Record<string, unknown>)\n : null;\n }\n const affected = (result as any)?.rowsAffected ?? (result as any)?.rowCount;\n if (affected === 0) return null;\n const fetched = await getA2AContinuation(id);\n if (!fetched || fetched.status !== \"delivering\") return null;\n return fetched;\n}\n\nexport async function rescheduleA2AContinuation(\n id: string,\n delayMs: number,\n): Promise<void> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n await client.execute({\n sql: `UPDATE integration_a2a_continuations\n SET status = ?, next_check_at = ?, updated_at = ?\n WHERE id = ? AND status IN ('processing', 'delivering')`,\n args: [\"pending\", now + delayMs, now, id],\n });\n}\n\nexport async function completeA2AContinuation(id: string): Promise<void> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n await client.execute({\n sql: `UPDATE integration_a2a_continuations\n SET status = ?, updated_at = ?, completed_at = ?\n WHERE id = ? AND status IN ('processing', 'delivering', 'completed')`,\n args: [\"completed\", now, now, id],\n });\n}\n\nexport async function failA2AContinuation(\n id: string,\n errorMessage: string,\n): Promise<void> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n await client.execute({\n sql: `UPDATE integration_a2a_continuations\n SET status = ?, updated_at = ?, error_message = ?\n WHERE id = ? AND status <> 'completed'`,\n args: [\"failed\", now, errorMessage.slice(0, 2000), id],\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"a2a-continuations-store.js","sourceRoot":"","sources":["../../src/integrations/a2a-continuations-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAGjE,IAAI,YAAuC,CAAC;AAC5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,EAAE,CAAC;IACvB,MAAM,MAAM,CAAC,OAAO,CAAC;QACnB,GAAG,EAAE;;+EAEsE;QAC3E,IAAI,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC;KAClC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,EAAU,EACV,YAAoB;IAEpB,MAAM,WAAW,EAAE,CAAC;IACpB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,MAAM,CAAC,OAAO,CAAC;QACnB,GAAG,EAAE;;iDAEwC;QAC7C,IAAI,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;KACvD,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { getDbExec, isPostgres, intType } from \"../db/client.js\";\nimport type { IncomingMessage } from \"./types.js\";\n\nlet _initPromise: Promise<void> | undefined;\nconst PROCESSING_STUCK_AFTER_MS = 5 * 60 * 1000;\nconst PROCESSING_NEXT_CHECK_STALE_AFTER_MS = 60 * 1000;\n\nasync function ensureTable(): Promise<void> {\n if (!_initPromise) {\n _initPromise = (async () => {\n const client = getDbExec();\n await client.execute(`\n CREATE TABLE IF NOT EXISTS integration_a2a_continuations (\n id TEXT PRIMARY KEY,\n integration_task_id TEXT NOT NULL,\n platform TEXT NOT NULL,\n external_thread_id TEXT NOT NULL,\n incoming_payload TEXT NOT NULL,\n placeholder_ref TEXT,\n owner_email TEXT NOT NULL,\n org_id TEXT,\n agent_name TEXT NOT NULL,\n agent_url TEXT NOT NULL,\n a2a_task_id TEXT NOT NULL,\n a2a_auth_token TEXT,\n status TEXT NOT NULL,\n attempts ${intType()} NOT NULL DEFAULT 0,\n next_check_at ${intType()} NOT NULL,\n error_message TEXT,\n created_at ${intType()} NOT NULL,\n updated_at ${intType()} NOT NULL,\n completed_at ${intType()}\n )\n `);\n await client.execute(\n `CREATE INDEX IF NOT EXISTS idx_a2a_continuations_status_next ON integration_a2a_continuations(status, next_check_at)`,\n );\n await client.execute(\n `CREATE INDEX IF NOT EXISTS idx_a2a_continuations_integration_task ON integration_a2a_continuations(integration_task_id)`,\n );\n await client.execute(\n `CREATE UNIQUE INDEX IF NOT EXISTS idx_a2a_continuations_remote_task ON integration_a2a_continuations(integration_task_id, agent_url, a2a_task_id)`,\n );\n try {\n await client.execute(\n `ALTER TABLE integration_a2a_continuations ADD COLUMN a2a_auth_token TEXT`,\n );\n } catch {\n // Column already exists.\n }\n })();\n }\n return _initPromise;\n}\n\nexport type A2AContinuationStatus =\n | \"pending\"\n | \"processing\"\n | \"delivering\"\n | \"completed\"\n | \"failed\";\n\nexport interface A2AContinuation {\n id: string;\n integrationTaskId: string;\n platform: string;\n externalThreadId: string;\n incoming: IncomingMessage;\n placeholderRef: string | null;\n ownerEmail: string;\n orgId: string | null;\n agentName: string;\n agentUrl: string;\n a2aTaskId: string;\n a2aAuthToken: string | null;\n status: A2AContinuationStatus;\n attempts: number;\n nextCheckAt: number;\n errorMessage: string | null;\n createdAt: number;\n updatedAt: number;\n completedAt: number | null;\n}\n\nfunction rowToContinuation(row: Record<string, unknown>): A2AContinuation {\n return {\n id: row.id as string,\n integrationTaskId: row.integration_task_id as string,\n platform: row.platform as string,\n externalThreadId: row.external_thread_id as string,\n incoming: JSON.parse(row.incoming_payload as string) as IncomingMessage,\n placeholderRef: (row.placeholder_ref as string | null) ?? null,\n ownerEmail: row.owner_email as string,\n orgId: (row.org_id as string | null) ?? null,\n agentName: row.agent_name as string,\n agentUrl: row.agent_url as string,\n a2aTaskId: row.a2a_task_id as string,\n a2aAuthToken: (row.a2a_auth_token as string | null) ?? null,\n status: row.status as A2AContinuationStatus,\n attempts: Number(row.attempts ?? 0),\n nextCheckAt: Number(row.next_check_at ?? 0),\n errorMessage: (row.error_message as string | null) ?? null,\n createdAt: Number(row.created_at ?? 0),\n updatedAt: Number(row.updated_at ?? 0),\n completedAt:\n row.completed_at == null ? null : Number(row.completed_at as number),\n };\n}\n\nexport async function insertA2AContinuation(input: {\n integrationTaskId: string;\n platform: string;\n externalThreadId: string;\n incoming: IncomingMessage;\n placeholderRef?: string | null;\n ownerEmail: string;\n orgId?: string | null;\n agentName: string;\n agentUrl: string;\n a2aTaskId: string;\n a2aAuthToken?: string | null;\n}): Promise<A2AContinuation> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const id = `a2a-cont-${now}-${Math.random().toString(36).slice(2, 8)}`;\n const payload = JSON.stringify(input.incoming);\n\n try {\n await client.execute({\n sql: `INSERT INTO integration_a2a_continuations\n (id, integration_task_id, platform, external_thread_id, incoming_payload,\n placeholder_ref, owner_email, org_id, agent_name, agent_url, a2a_task_id, a2a_auth_token,\n status, attempts, next_check_at, created_at, updated_at)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n args: [\n id,\n input.integrationTaskId,\n input.platform,\n input.externalThreadId,\n payload,\n input.placeholderRef ?? null,\n input.ownerEmail,\n input.orgId ?? null,\n input.agentName,\n input.agentUrl,\n input.a2aTaskId,\n input.a2aAuthToken ?? null,\n \"pending\",\n 0,\n now,\n now,\n now,\n ],\n });\n return (await getA2AContinuation(id))!;\n } catch (err: any) {\n if (!isDuplicateContinuationError(err)) throw err;\n const existing = await findA2AContinuation(\n input.integrationTaskId,\n input.agentUrl,\n input.a2aTaskId,\n );\n if (existing) return existing;\n throw err;\n }\n}\n\nexport async function getA2AContinuationForIntegrationTask(\n integrationTaskId: string,\n): Promise<A2AContinuation | null> {\n await ensureTable();\n const client = getDbExec();\n const { rows } = await client.execute({\n sql: `SELECT * FROM integration_a2a_continuations\n WHERE integration_task_id = ?\n ORDER BY created_at ASC\n LIMIT 1`,\n args: [integrationTaskId],\n });\n return rows[0] ? rowToContinuation(rows[0] as Record<string, unknown>) : null;\n}\n\nfunction isDuplicateContinuationError(err: unknown): boolean {\n const e = err as { code?: string; message?: string } | null;\n if (!e) return false;\n if (e.code === \"23505\") return true;\n const msg = String(e.message ?? \"\").toLowerCase();\n return (\n msg.includes(\"unique\") ||\n msg.includes(\"duplicate entry\") ||\n msg.includes(\"duplicate key\")\n );\n}\n\nasync function findA2AContinuation(\n integrationTaskId: string,\n agentUrl: string,\n a2aTaskId: string,\n): Promise<A2AContinuation | null> {\n await ensureTable();\n const client = getDbExec();\n const { rows } = await client.execute({\n sql: `SELECT * FROM integration_a2a_continuations\n WHERE integration_task_id = ? AND agent_url = ? AND a2a_task_id = ?\n LIMIT 1`,\n args: [integrationTaskId, agentUrl, a2aTaskId],\n });\n return rows[0] ? rowToContinuation(rows[0] as Record<string, unknown>) : null;\n}\n\nexport async function getA2AContinuation(\n id: string,\n): Promise<A2AContinuation | null> {\n await ensureTable();\n const client = getDbExec();\n const { rows } = await client.execute({\n sql: `SELECT * FROM integration_a2a_continuations WHERE id = ? LIMIT 1`,\n args: [id],\n });\n return rows[0] ? rowToContinuation(rows[0] as Record<string, unknown>) : null;\n}\n\nexport async function claimA2AContinuation(\n id: string,\n): Promise<A2AContinuation | null> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const processingCutoff = now - PROCESSING_STUCK_AFTER_MS;\n const staleNextCheckCutoff = now - PROCESSING_NEXT_CHECK_STALE_AFTER_MS;\n const result = await client.execute({\n sql: isPostgres()\n ? `UPDATE integration_a2a_continuations\n SET status = ?, attempts = attempts + 1, updated_at = ?\n WHERE id = ?\n AND (\n status = 'pending'\n OR (\n status = 'processing'\n AND (updated_at <= ? OR next_check_at <= ?)\n )\n )\n RETURNING *`\n : `UPDATE integration_a2a_continuations\n SET status = ?, attempts = attempts + 1, updated_at = ?\n WHERE id = ?\n AND (\n status = 'pending'\n OR (\n status = 'processing'\n AND (updated_at <= ? OR next_check_at <= ?)\n )\n )`,\n args: [\"processing\", now, id, processingCutoff, staleNextCheckCutoff],\n });\n const rows = result.rows ?? [];\n if (isPostgres()) {\n return rows[0]\n ? rowToContinuation(rows[0] as Record<string, unknown>)\n : null;\n }\n const affected = (result as any)?.rowsAffected ?? (result as any)?.rowCount;\n if (affected === 0) return null;\n const fetched = await getA2AContinuation(id);\n if (!fetched || fetched.status !== \"processing\") return null;\n return fetched;\n}\n\nexport async function claimDueA2AContinuations(\n limit = 5,\n): Promise<A2AContinuation[]> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const processingCutoff = now - PROCESSING_STUCK_AFTER_MS;\n const staleNextCheckCutoff = now - PROCESSING_NEXT_CHECK_STALE_AFTER_MS;\n // If a processor dies while holding a delivery claim, retry the final send.\n // The stale cutoff preserves the in-flight delivery guard while keeping\n // final integration replies at-least-once.\n await client.execute({\n sql: `UPDATE integration_a2a_continuations\n SET status = ?, next_check_at = ?, updated_at = ?\n WHERE status = 'delivering' AND updated_at <= ?`,\n args: [\"pending\", now, now, now - 5 * 60 * 1000],\n });\n await client.execute({\n sql: `UPDATE integration_a2a_continuations\n SET status = ?, next_check_at = ?, updated_at = ?\n WHERE status = 'processing'\n AND (updated_at <= ? OR next_check_at <= ?)`,\n args: [\"pending\", now, now, processingCutoff, staleNextCheckCutoff],\n });\n const { rows } = await client.execute({\n sql: `SELECT id FROM integration_a2a_continuations\n WHERE status = 'pending' AND next_check_at <= ?\n ORDER BY next_check_at ASC\n LIMIT ?`,\n args: [now, limit],\n });\n const claimed: A2AContinuation[] = [];\n for (const row of rows) {\n const continuation = await claimA2AContinuation(row.id as string);\n if (continuation) claimed.push(continuation);\n }\n return claimed;\n}\n\nexport async function claimA2AContinuationDelivery(\n id: string,\n): Promise<A2AContinuation | null> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const result = await client.execute({\n sql: isPostgres()\n ? `UPDATE integration_a2a_continuations\n SET status = ?, updated_at = ?\n WHERE id = ? AND status = 'processing'\n RETURNING *`\n : `UPDATE integration_a2a_continuations\n SET status = ?, updated_at = ?\n WHERE id = ? AND status = 'processing'`,\n args: [\"delivering\", now, id],\n });\n const rows = result.rows ?? [];\n if (isPostgres()) {\n return rows[0]\n ? rowToContinuation(rows[0] as Record<string, unknown>)\n : null;\n }\n const affected = (result as any)?.rowsAffected ?? (result as any)?.rowCount;\n if (affected === 0) return null;\n const fetched = await getA2AContinuation(id);\n if (!fetched || fetched.status !== \"delivering\") return null;\n return fetched;\n}\n\nexport async function rescheduleA2AContinuation(\n id: string,\n delayMs: number,\n): Promise<void> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n await client.execute({\n sql: `UPDATE integration_a2a_continuations\n SET status = ?, next_check_at = ?, updated_at = ?\n WHERE id = ? AND status IN ('processing', 'delivering')`,\n args: [\"pending\", now + delayMs, now, id],\n });\n}\n\nexport async function completeA2AContinuation(id: string): Promise<void> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n await client.execute({\n sql: `UPDATE integration_a2a_continuations\n SET status = ?, updated_at = ?, completed_at = ?\n WHERE id = ? AND status IN ('processing', 'delivering', 'completed')`,\n args: [\"completed\", now, now, id],\n });\n}\n\nexport async function failA2AContinuation(\n id: string,\n errorMessage: string,\n): Promise<void> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n await client.execute({\n sql: `UPDATE integration_a2a_continuations\n SET status = ?, updated_at = ?, error_message = ?\n WHERE id = ? AND status <> 'completed'`,\n args: [\"failed\", now, errorMessage.slice(0, 2000), id],\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call-agent.d.ts","sourceRoot":"","sources":["../../src/scripts/call-agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAoErE,eAAO,MAAM,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"call-agent.d.ts","sourceRoot":"","sources":["../../src/scripts/call-agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAoErE,eAAO,MAAM,IAAI,EAAE,UAsBlB,CAAC;AAEF,wBAAsB,GAAG,CACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,OAAO,CAAC,EAAE,gBAAgB,EAC1B,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,CAoNjB;AAkDD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CASzE"}
|
|
@@ -45,7 +45,8 @@ export const tool = {
|
|
|
45
45
|
description: "Call a DIFFERENT, separately-deployed agent app to ask a question or delegate a task. This is strictly for cross-app A2A communication — for example, asking the mail agent to send an email while you are the calendar agent. NEVER use this to call your own app or perform actions you can do with your own tools. Using call-agent on yourself will fail and waste time. " +
|
|
46
46
|
"IMPORTANT — handling the response: " +
|
|
47
47
|
"(a) If it contains a URL or ID, copy it VERBATIM into your reply. Do not 'correct' or pluralize the path (e.g. /deck/ → /decks/), normalize casing, or change the slug — any edit breaks the link. " +
|
|
48
|
-
'(b) If it does NOT contain a URL/ID and the user asked for one, say so explicitly (e.g. "the agent created the deck but didn\'t return a link — open the app directly to view it"). NEVER invent a URL, slug, or path — guessing produces broken links that look real.'
|
|
48
|
+
'(b) If it does NOT contain a URL/ID and the user asked for one, say so explicitly (e.g. "the agent created the deck but didn\'t return a link — open the app directly to view it"). NEVER invent a URL, slug, or path — guessing produces broken links that look real. ' +
|
|
49
|
+
"(c) If the downstream response reports missing credentials, never repeat raw env var names, Vault key names, token names, secret names, or other credential identifiers. Tell the user the target app needs its LLM/provider connection configured.",
|
|
49
50
|
parameters: {
|
|
50
51
|
type: "object",
|
|
51
52
|
properties: {
|
|
@@ -1 +1 @@
|
|
|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CAA4C;AAC5C,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,QAAgB;IAC/D,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IACpC,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACzC,4EAA4E;IAC5E,8EAA8E;IAC9E,OAAO,IAAI,CAAC,OAAO,CACjB,qDAAqD,EACrD,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,EAAE,CAChD,CAAC;AACJ,CAAC","sourcesContent":["import type { ActionTool } from \"../agent/types.js\";\nimport type { ActionRunContext } from \"../agent/production-agent.js\";\nimport { findAgent, discoverAgents } from \"../server/agent-discovery.js\";\nimport {\n A2AClient,\n A2ATaskTimeoutError,\n callAgent,\n signA2AToken,\n} from \"../a2a/client.js\";\nimport { A2A_CONTINUATION_QUEUED_MARKER } from \"../integrations/a2a-continuation-marker.js\";\nimport {\n formatLlmCredentialErrorMessage,\n isLlmCredentialError,\n} from \"../agent/engine/credential-errors.js\";\nimport {\n getRequestUserEmail,\n getRequestOrgId,\n isIntegrationCallerRequest,\n getIntegrationRequestContext,\n} from \"../server/request-context.js\";\nimport { getOrgDomain, getOrgA2ASecret } from \"../org/context.js\";\n\nconst DEFAULT_SERVERLESS_INTEGRATION_A2A_TIMEOUT_MS = 18_000;\nconst NETLIFY_INTEGRATION_A2A_TIMEOUT_MS = 50_000;\nconst INTEGRATION_A2A_TOKEN_TTL = \"30m\";\n\nfunction parseTimeoutMs(value: string | undefined): number | undefined {\n if (!value) return undefined;\n const parsed = Number(value);\n if (!Number.isFinite(parsed) || parsed <= 0) return undefined;\n return Math.floor(parsed);\n}\n\nfunction isServerlessHost(): boolean {\n // Detection mirrors db/migrations.ts:297-301. On Cloudflare Workers/Pages,\n // `process.env` is shimmed and CF_PAGES isn't reliably populated at runtime —\n // the canonical signal is the `__cf_env` global injected by workerd.\n return (\n !!process.env.NETLIFY ||\n !!process.env.AWS_LAMBDA_FUNCTION_NAME ||\n !!process.env.VERCEL ||\n \"__cf_env\" in globalThis\n );\n}\n\nfunction getIntegrationCallTimeoutMs(): number | undefined {\n if (!isServerlessHost() || !isIntegrationCallerRequest()) return undefined;\n\n const configured = parseTimeoutMs(\n process.env.AGENT_NATIVE_INTEGRATION_A2A_TIMEOUT_MS,\n );\n if (configured !== undefined) return configured;\n\n // Netlify's current synchronous function budget is 60s, but leave room for\n // cold start, polling overhead, and the caller's final platform response.\n if (process.env.NETLIFY) return NETLIFY_INTEGRATION_A2A_TIMEOUT_MS;\n\n return DEFAULT_SERVERLESS_INTEGRATION_A2A_TIMEOUT_MS;\n}\n\nfunction formatDownstreamLlmCredentialFailure(\n agentName: string,\n value: unknown,\n): string | null {\n return isLlmCredentialError(value)\n ? formatLlmCredentialErrorMessage({ agentName })\n : null;\n}\n\nexport const tool: ActionTool = {\n description:\n \"Call a DIFFERENT, separately-deployed agent app to ask a question or delegate a task. This is strictly for cross-app A2A communication — for example, asking the mail agent to send an email while you are the calendar agent. NEVER use this to call your own app or perform actions you can do with your own tools. Using call-agent on yourself will fail and waste time. \" +\n \"IMPORTANT — handling the response: \" +\n \"(a) If it contains a URL or ID, copy it VERBATIM into your reply. Do not 'correct' or pluralize the path (e.g. /deck/ → /decks/), normalize casing, or change the slug — any edit breaks the link. \" +\n '(b) If it does NOT contain a URL/ID and the user asked for one, say so explicitly (e.g. \"the agent created the deck but didn\\'t return a link — open the app directly to view it\"). NEVER invent a URL, slug, or path — guessing produces broken links that look real.',\n parameters: {\n type: \"object\",\n properties: {\n agent: {\n type: \"string\",\n description:\n \"Name or URL of a DIFFERENT deployed agent app (e.g. 'mail', 'calendar', 'analytics'). Must not be the current app's own name.\",\n },\n message: {\n type: \"string\",\n description: \"The message/question to send to the other agent\",\n },\n },\n required: [\"agent\", \"message\"],\n },\n};\n\nexport async function run(\n args: Record<string, string>,\n context?: ActionRunContext,\n selfAppId?: string,\n): Promise<string> {\n const { agent: agentIdOrName, message } = args;\n\n if (!agentIdOrName) return \"Error: --agent is required\";\n if (!message) return \"Error: --message is required\";\n\n // Prevent self-calls — the agent must use its own registered tools instead\n if (selfAppId && agentIdOrName.toLowerCase() === selfAppId.toLowerCase()) {\n return `Error: You cannot use call-agent to call yourself (${selfAppId}). Use your own registered actions/tools instead. call-agent is only for communicating with OTHER separately-deployed apps.`;\n }\n\n const agent = await findAgent(agentIdOrName, selfAppId);\n if (!agent) {\n const available = (await discoverAgents(selfAppId))\n .map((a) => a.name)\n .join(\", \");\n return `Error: Agent \"${agentIdOrName}\" not found. Available agents: ${available || \"(none)\"}`;\n }\n\n // Append a small cross-app hint to the outgoing message so the receiving\n // agent (which may be on an older deploy without the receiver-side hint\n // in handlers.ts) still emits fully-qualified URLs. This is belt-and-\n // suspenders with the receiver hint — but it works against any current\n // deployment, no redeploy required.\n const messageWithHint =\n `${message}\\n\\n` +\n `[Note: this request comes from another app via A2A. The caller cannot see your local UI, deck list, or navigation — only the literal text you put in your reply. ` +\n `If you create or reference a deck/document/design/dashboard, include its FULLY-QUALIFIED URL (e.g. ${agent.url}/deck/<id>) in your reply, not a relative path. ` +\n `Use only artifact IDs and URL paths returned by successful actions — never invent slugs, IDs, or hosts.]`;\n\n try {\n // If we have a send context, use streaming so the UI shows progressive text\n if (context?.send) {\n const callerEmail = getRequestUserEmail();\n\n // Build metadata with identity\n const a2aMetadata: Record<string, unknown> = {};\n if (callerEmail) a2aMetadata.userEmail = callerEmail;\n\n // Include org domain for cross-app org resolution\n let callerOrgDomain: string | undefined;\n let callerOrgSecret: string | undefined;\n const orgId = getRequestOrgId();\n if (orgId) {\n try {\n const domain = await getOrgDomain(orgId);\n if (domain) {\n callerOrgDomain = domain;\n a2aMetadata.orgDomain = domain;\n }\n } catch {}\n try {\n const secret = await getOrgA2ASecret(orgId);\n if (secret) callerOrgSecret = secret;\n } catch {}\n }\n\n // Sign JWT with identity + org domain for the streaming client\n let apiKey: string | undefined;\n if (callerEmail && (callerOrgSecret || process.env.A2A_SECRET)) {\n try {\n apiKey = await signA2AToken(\n callerEmail,\n callerOrgDomain,\n callerOrgSecret,\n {\n expiresIn: INTEGRATION_A2A_TOKEN_TTL,\n preferGlobalSecret: true,\n },\n );\n } catch {}\n }\n\n const client = new A2AClient(agent.url, apiKey);\n\n if (process.env.NODE_ENV === \"production\" && callerEmail) {\n try {\n const { listOAuthAccountsByOwner } =\n await import(\"../oauth-tokens/store.js\");\n const accounts = await listOAuthAccountsByOwner(\n \"google\",\n callerEmail,\n );\n const tokens = accounts[0]?.tokens;\n if (tokens?.access_token) {\n a2aMetadata.googleToken = tokens.access_token;\n }\n } catch {}\n }\n\n let responseText = \"\";\n let lastSentLength = 0;\n\n context.send({\n type: \"agent_call\",\n agent: agent.name,\n status: \"start\",\n });\n\n const emitNewText = (newText: string) => {\n if (newText.length > lastSentLength) {\n context.send!({\n type: \"agent_call_text\",\n agent: agent.name,\n text: newText.slice(lastSentLength),\n });\n lastSentLength = newText.length;\n }\n responseText = newText;\n };\n\n // Skip the SSE streaming attempt and go straight to async + poll.\n // Why: on Netlify (Lambda), the receiving server has no streaming\n // response support, so message/stream returns a single JSON-RPC error\n // body in a 200 response that our SSE parser silently consumes — the\n // `for await` loop yields nothing AND keeps the connection open until\n // the function timeout, eating the current serverless budget. By the\n // time we get to the sync fallback, Lambda is dead and the second fetch\n // errors out as \"fetch failed\". Async+poll has its own short fetches\n // with their own budgets, so it works reliably across hosts. The\n // trade-off is we lose progressive in-UI text streaming for cross-app\n // A2A calls, but the receiving agent's full response still surfaces via\n // the tool_result event below.\n try {\n // Apply a polling cap ONLY for integration-platform callers on\n // serverless hosts. Normal chat, local Node, self-hosted Node, and\n // Docker can wait for slow-but-valid answers; integration processors\n // still need to finish before their current function execution dies.\n const callTimeoutMs = getIntegrationCallTimeoutMs();\n responseText = await callAgent(agent.url, messageWithHint, {\n apiKey,\n userEmail: callerEmail,\n orgDomain: callerOrgDomain,\n orgSecret: callerOrgSecret,\n ...(callTimeoutMs ? { timeoutMs: callTimeoutMs } : {}),\n });\n responseText =\n formatDownstreamLlmCredentialFailure(agent.name, responseText) ??\n responseText;\n // Some agents reply with relative paths (e.g. slides emits\n // \"/deck/abc\"). Those resolve against the caller's host, not the\n // receiver's, so they're broken for the user. Expand any leading-slash\n // URL into a fully-qualified one rooted at the receiving agent's host.\n responseText = expandRelativeUrls(responseText, agent.url);\n // Mirror the response into the streaming UI so the user sees it.\n if (responseText) emitNewText(responseText);\n } catch (pollErr: any) {\n if (pollErr instanceof A2ATaskTimeoutError) {\n const queued = await enqueueIntegrationContinuationIfPossible(\n pollErr,\n agent,\n callerEmail,\n );\n if (queued) {\n responseText = `${A2A_CONTINUATION_QUEUED_MARKER}\\nThe ${agent.name} agent is still working. Do not send an interim reply to the user; the final result will be posted to the originating integration thread automatically.`;\n } else {\n const reason = pollErr?.message ?? \"unknown error\";\n responseText = `The ${agent.name} agent is taking longer than expected and didn't reply in time. (${reason})`;\n }\n } else {\n const reason = pollErr?.message ?? \"unknown error\";\n responseText =\n formatDownstreamLlmCredentialFailure(agent.name, pollErr) ??\n `The ${agent.name} agent is taking longer than expected and didn't reply in time. (${reason})`;\n }\n }\n\n context.send({\n type: \"agent_call\",\n agent: agent.name,\n status: \"done\",\n });\n\n return responseText || \"(empty response)\";\n }\n\n // No context — use the async + poll call so we don't get cut off at the\n // serverless gateway's ~30s timeout. callAgent defaults to async:true.\n const email = getRequestUserEmail();\n let domain: string | undefined;\n let orgSecret: string | undefined;\n const currentOrgId = getRequestOrgId();\n if (currentOrgId) {\n try {\n domain = (await getOrgDomain(currentOrgId)) ?? undefined;\n } catch {}\n try {\n orgSecret = (await getOrgA2ASecret(currentOrgId)) ?? undefined;\n } catch {}\n }\n const response = await callAgent(agent.url, messageWithHint, {\n userEmail: email,\n orgDomain: domain,\n orgSecret,\n });\n const sanitized =\n formatDownstreamLlmCredentialFailure(agent.name, response) ?? response;\n return expandRelativeUrls(sanitized, agent.url) || \"(empty response)\";\n } catch (err: any) {\n const msg = err?.message ?? String(err);\n const credentialMessage = formatDownstreamLlmCredentialFailure(\n agent.name,\n err,\n );\n if (credentialMessage) return credentialMessage;\n // Friendlier message for the common timeout case so the calling agent can\n // decide whether to give up or retry.\n if (/timeout|did not complete|Inactivity|504/i.test(msg)) {\n return `The ${agent.name} agent is taking longer than expected. Please try again, ask a simpler question, or open the ${agent.name} app directly.`;\n }\n return `Error calling ${agent.name}: ${msg}`;\n }\n}\n\nasync function enqueueIntegrationContinuationIfPossible(\n error: A2ATaskTimeoutError,\n agent: { name: string; url: string },\n ownerEmail: string | undefined,\n): Promise<boolean> {\n const integration = getIntegrationRequestContext();\n if (!integration || !ownerEmail) return false;\n\n try {\n const [{ insertA2AContinuation }, { dispatchA2AContinuation }] =\n await Promise.all([\n import(\"../integrations/a2a-continuations-store.js\"),\n import(\"../integrations/a2a-continuation-processor.js\"),\n ]);\n const continuation = await insertA2AContinuation({\n integrationTaskId: integration.taskId,\n platform: integration.incoming.platform,\n externalThreadId: integration.incoming.externalThreadId,\n incoming: integration.incoming,\n placeholderRef: integration.placeholderRef,\n ownerEmail,\n orgId: getRequestOrgId() ?? null,\n agentName: agent.name,\n agentUrl: agent.url,\n a2aTaskId: error.taskId,\n // Do not persist the short-lived JWT used for the initial send. The\n // continuation processor can mint a fresh token for each poll.\n a2aAuthToken: null,\n });\n await dispatchA2AContinuation(continuation.id).catch((err) => {\n console.error(\n `[call-agent] Failed to dispatch A2A continuation ${continuation.id}:`,\n err,\n );\n });\n return true;\n } catch (err) {\n console.error(\"[call-agent] Failed to enqueue A2A continuation:\", err);\n return false;\n }\n}\n\n// Expand bare leading-slash paths (e.g. \"/deck/abc\") into fully-qualified URLs\n// rooted at the receiving agent's host. The receiver doesn't always know it's\n// being called cross-app, so it may emit relative paths that resolve against\n// the caller's host (broken). Match a path that starts at a word boundary,\n// begins with `/`, and has at least one path segment after that. Skip if it\n// already looks like a fully-qualified URL.\nexport function expandRelativeUrls(text: string, agentUrl: string): string {\n if (!text || !agentUrl) return text;\n const base = agentUrl.replace(/\\/$/, \"\");\n // Path must start at boundary (start, whitespace, or punctuation that isn't\n // ':' — to avoid mangling `https://example.com/foo` or markdown link bodies).\n return text.replace(\n /(^|[\\s(\\[<\"'`])(\\/[a-z0-9_-][a-z0-9_/?&=%#.,:-]*)/gi,\n (_match, lead, path) => `${lead}${base}${path}`,\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"call-agent.js","sourceRoot":"","sources":["../../src/scripts/call-agent.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,SAAS,EACT,YAAY,GACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAC5F,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,GACrB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,0BAA0B,EAC1B,4BAA4B,GAC7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAElE,MAAM,6CAA6C,GAAG,MAAM,CAAC;AAC7D,MAAM,kCAAkC,GAAG,MAAM,CAAC;AAClD,MAAM,yBAAyB,GAAG,KAAK,CAAC;AAExC,SAAS,cAAc,CAAC,KAAyB;IAC/C,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IAC9D,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC5B,CAA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,EAAE,GAAG,EACtE,GAAG,CACJ,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,kDAAkD,EAAE,GAAG,CAAC,CAAC;QACvE,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,+EAA+E;AAC/E,8EAA8E;AAC9E,6EAA6E;AAC7E,2EAA2E;AAC3E,4EAA4E;AAC5E,4CAA4C;AAC5C,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,QAAgB;IAC/D,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IACpC,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACzC,4EAA4E;IAC5E,8EAA8E;IAC9E,OAAO,IAAI,CAAC,OAAO,CACjB,qDAAqD,EACrD,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,EAAE,CAChD,CAAC;AACJ,CAAC","sourcesContent":["import type { ActionTool } from \"../agent/types.js\";\nimport type { ActionRunContext } from \"../agent/production-agent.js\";\nimport { findAgent, discoverAgents } from \"../server/agent-discovery.js\";\nimport {\n A2AClient,\n A2ATaskTimeoutError,\n callAgent,\n signA2AToken,\n} from \"../a2a/client.js\";\nimport { A2A_CONTINUATION_QUEUED_MARKER } from \"../integrations/a2a-continuation-marker.js\";\nimport {\n formatLlmCredentialErrorMessage,\n isLlmCredentialError,\n} from \"../agent/engine/credential-errors.js\";\nimport {\n getRequestUserEmail,\n getRequestOrgId,\n isIntegrationCallerRequest,\n getIntegrationRequestContext,\n} from \"../server/request-context.js\";\nimport { getOrgDomain, getOrgA2ASecret } from \"../org/context.js\";\n\nconst DEFAULT_SERVERLESS_INTEGRATION_A2A_TIMEOUT_MS = 18_000;\nconst NETLIFY_INTEGRATION_A2A_TIMEOUT_MS = 50_000;\nconst INTEGRATION_A2A_TOKEN_TTL = \"30m\";\n\nfunction parseTimeoutMs(value: string | undefined): number | undefined {\n if (!value) return undefined;\n const parsed = Number(value);\n if (!Number.isFinite(parsed) || parsed <= 0) return undefined;\n return Math.floor(parsed);\n}\n\nfunction isServerlessHost(): boolean {\n // Detection mirrors db/migrations.ts:297-301. On Cloudflare Workers/Pages,\n // `process.env` is shimmed and CF_PAGES isn't reliably populated at runtime —\n // the canonical signal is the `__cf_env` global injected by workerd.\n return (\n !!process.env.NETLIFY ||\n !!process.env.AWS_LAMBDA_FUNCTION_NAME ||\n !!process.env.VERCEL ||\n \"__cf_env\" in globalThis\n );\n}\n\nfunction getIntegrationCallTimeoutMs(): number | undefined {\n if (!isServerlessHost() || !isIntegrationCallerRequest()) return undefined;\n\n const configured = parseTimeoutMs(\n process.env.AGENT_NATIVE_INTEGRATION_A2A_TIMEOUT_MS,\n );\n if (configured !== undefined) return configured;\n\n // Netlify's current synchronous function budget is 60s, but leave room for\n // cold start, polling overhead, and the caller's final platform response.\n if (process.env.NETLIFY) return NETLIFY_INTEGRATION_A2A_TIMEOUT_MS;\n\n return DEFAULT_SERVERLESS_INTEGRATION_A2A_TIMEOUT_MS;\n}\n\nfunction formatDownstreamLlmCredentialFailure(\n agentName: string,\n value: unknown,\n): string | null {\n return isLlmCredentialError(value)\n ? formatLlmCredentialErrorMessage({ agentName })\n : null;\n}\n\nexport const tool: ActionTool = {\n description:\n \"Call a DIFFERENT, separately-deployed agent app to ask a question or delegate a task. This is strictly for cross-app A2A communication — for example, asking the mail agent to send an email while you are the calendar agent. NEVER use this to call your own app or perform actions you can do with your own tools. Using call-agent on yourself will fail and waste time. \" +\n \"IMPORTANT — handling the response: \" +\n \"(a) If it contains a URL or ID, copy it VERBATIM into your reply. Do not 'correct' or pluralize the path (e.g. /deck/ → /decks/), normalize casing, or change the slug — any edit breaks the link. \" +\n '(b) If it does NOT contain a URL/ID and the user asked for one, say so explicitly (e.g. \"the agent created the deck but didn\\'t return a link — open the app directly to view it\"). NEVER invent a URL, slug, or path — guessing produces broken links that look real. ' +\n \"(c) If the downstream response reports missing credentials, never repeat raw env var names, Vault key names, token names, secret names, or other credential identifiers. Tell the user the target app needs its LLM/provider connection configured.\",\n parameters: {\n type: \"object\",\n properties: {\n agent: {\n type: \"string\",\n description:\n \"Name or URL of a DIFFERENT deployed agent app (e.g. 'mail', 'calendar', 'analytics'). Must not be the current app's own name.\",\n },\n message: {\n type: \"string\",\n description: \"The message/question to send to the other agent\",\n },\n },\n required: [\"agent\", \"message\"],\n },\n};\n\nexport async function run(\n args: Record<string, string>,\n context?: ActionRunContext,\n selfAppId?: string,\n): Promise<string> {\n const { agent: agentIdOrName, message } = args;\n\n if (!agentIdOrName) return \"Error: --agent is required\";\n if (!message) return \"Error: --message is required\";\n\n // Prevent self-calls — the agent must use its own registered tools instead\n if (selfAppId && agentIdOrName.toLowerCase() === selfAppId.toLowerCase()) {\n return `Error: You cannot use call-agent to call yourself (${selfAppId}). Use your own registered actions/tools instead. call-agent is only for communicating with OTHER separately-deployed apps.`;\n }\n\n const agent = await findAgent(agentIdOrName, selfAppId);\n if (!agent) {\n const available = (await discoverAgents(selfAppId))\n .map((a) => a.name)\n .join(\", \");\n return `Error: Agent \"${agentIdOrName}\" not found. Available agents: ${available || \"(none)\"}`;\n }\n\n // Append a small cross-app hint to the outgoing message so the receiving\n // agent (which may be on an older deploy without the receiver-side hint\n // in handlers.ts) still emits fully-qualified URLs. This is belt-and-\n // suspenders with the receiver hint — but it works against any current\n // deployment, no redeploy required.\n const messageWithHint =\n `${message}\\n\\n` +\n `[Note: this request comes from another app via A2A. The caller cannot see your local UI, deck list, or navigation — only the literal text you put in your reply. ` +\n `If you create or reference a deck/document/design/dashboard, include its FULLY-QUALIFIED URL (e.g. ${agent.url}/deck/<id>) in your reply, not a relative path. ` +\n `Use only artifact IDs and URL paths returned by successful actions — never invent slugs, IDs, or hosts.]`;\n\n try {\n // If we have a send context, use streaming so the UI shows progressive text\n if (context?.send) {\n const callerEmail = getRequestUserEmail();\n\n // Build metadata with identity\n const a2aMetadata: Record<string, unknown> = {};\n if (callerEmail) a2aMetadata.userEmail = callerEmail;\n\n // Include org domain for cross-app org resolution\n let callerOrgDomain: string | undefined;\n let callerOrgSecret: string | undefined;\n const orgId = getRequestOrgId();\n if (orgId) {\n try {\n const domain = await getOrgDomain(orgId);\n if (domain) {\n callerOrgDomain = domain;\n a2aMetadata.orgDomain = domain;\n }\n } catch {}\n try {\n const secret = await getOrgA2ASecret(orgId);\n if (secret) callerOrgSecret = secret;\n } catch {}\n }\n\n // Sign JWT with identity + org domain for the streaming client\n let apiKey: string | undefined;\n if (callerEmail && (callerOrgSecret || process.env.A2A_SECRET)) {\n try {\n apiKey = await signA2AToken(\n callerEmail,\n callerOrgDomain,\n callerOrgSecret,\n {\n expiresIn: INTEGRATION_A2A_TOKEN_TTL,\n preferGlobalSecret: true,\n },\n );\n } catch {}\n }\n\n const client = new A2AClient(agent.url, apiKey);\n\n if (process.env.NODE_ENV === \"production\" && callerEmail) {\n try {\n const { listOAuthAccountsByOwner } =\n await import(\"../oauth-tokens/store.js\");\n const accounts = await listOAuthAccountsByOwner(\n \"google\",\n callerEmail,\n );\n const tokens = accounts[0]?.tokens;\n if (tokens?.access_token) {\n a2aMetadata.googleToken = tokens.access_token;\n }\n } catch {}\n }\n\n let responseText = \"\";\n let lastSentLength = 0;\n\n context.send({\n type: \"agent_call\",\n agent: agent.name,\n status: \"start\",\n });\n\n const emitNewText = (newText: string) => {\n if (newText.length > lastSentLength) {\n context.send!({\n type: \"agent_call_text\",\n agent: agent.name,\n text: newText.slice(lastSentLength),\n });\n lastSentLength = newText.length;\n }\n responseText = newText;\n };\n\n // Skip the SSE streaming attempt and go straight to async + poll.\n // Why: on Netlify (Lambda), the receiving server has no streaming\n // response support, so message/stream returns a single JSON-RPC error\n // body in a 200 response that our SSE parser silently consumes — the\n // `for await` loop yields nothing AND keeps the connection open until\n // the function timeout, eating the current serverless budget. By the\n // time we get to the sync fallback, Lambda is dead and the second fetch\n // errors out as \"fetch failed\". Async+poll has its own short fetches\n // with their own budgets, so it works reliably across hosts. The\n // trade-off is we lose progressive in-UI text streaming for cross-app\n // A2A calls, but the receiving agent's full response still surfaces via\n // the tool_result event below.\n try {\n // Apply a polling cap ONLY for integration-platform callers on\n // serverless hosts. Normal chat, local Node, self-hosted Node, and\n // Docker can wait for slow-but-valid answers; integration processors\n // still need to finish before their current function execution dies.\n const callTimeoutMs = getIntegrationCallTimeoutMs();\n responseText = await callAgent(agent.url, messageWithHint, {\n apiKey,\n userEmail: callerEmail,\n orgDomain: callerOrgDomain,\n orgSecret: callerOrgSecret,\n ...(callTimeoutMs ? { timeoutMs: callTimeoutMs } : {}),\n });\n responseText =\n formatDownstreamLlmCredentialFailure(agent.name, responseText) ??\n responseText;\n // Some agents reply with relative paths (e.g. slides emits\n // \"/deck/abc\"). Those resolve against the caller's host, not the\n // receiver's, so they're broken for the user. Expand any leading-slash\n // URL into a fully-qualified one rooted at the receiving agent's host.\n responseText = expandRelativeUrls(responseText, agent.url);\n // Mirror the response into the streaming UI so the user sees it.\n if (responseText) emitNewText(responseText);\n } catch (pollErr: any) {\n if (pollErr instanceof A2ATaskTimeoutError) {\n const queued = await enqueueIntegrationContinuationIfPossible(\n pollErr,\n agent,\n callerEmail,\n );\n if (queued) {\n responseText = `${A2A_CONTINUATION_QUEUED_MARKER}\\nThe ${agent.name} agent is still working. Do not send an interim reply to the user; the final result will be posted to the originating integration thread automatically.`;\n } else {\n const reason = pollErr?.message ?? \"unknown error\";\n responseText = `The ${agent.name} agent is taking longer than expected and didn't reply in time. (${reason})`;\n }\n } else {\n const reason = pollErr?.message ?? \"unknown error\";\n responseText =\n formatDownstreamLlmCredentialFailure(agent.name, pollErr) ??\n `The ${agent.name} agent is taking longer than expected and didn't reply in time. (${reason})`;\n }\n }\n\n context.send({\n type: \"agent_call\",\n agent: agent.name,\n status: \"done\",\n });\n\n return responseText || \"(empty response)\";\n }\n\n // No context — use the async + poll call so we don't get cut off at the\n // serverless gateway's ~30s timeout. callAgent defaults to async:true.\n const email = getRequestUserEmail();\n let domain: string | undefined;\n let orgSecret: string | undefined;\n const currentOrgId = getRequestOrgId();\n if (currentOrgId) {\n try {\n domain = (await getOrgDomain(currentOrgId)) ?? undefined;\n } catch {}\n try {\n orgSecret = (await getOrgA2ASecret(currentOrgId)) ?? undefined;\n } catch {}\n }\n const response = await callAgent(agent.url, messageWithHint, {\n userEmail: email,\n orgDomain: domain,\n orgSecret,\n });\n const sanitized =\n formatDownstreamLlmCredentialFailure(agent.name, response) ?? response;\n return expandRelativeUrls(sanitized, agent.url) || \"(empty response)\";\n } catch (err: any) {\n const msg = err?.message ?? String(err);\n const credentialMessage = formatDownstreamLlmCredentialFailure(\n agent.name,\n err,\n );\n if (credentialMessage) return credentialMessage;\n // Friendlier message for the common timeout case so the calling agent can\n // decide whether to give up or retry.\n if (/timeout|did not complete|Inactivity|504/i.test(msg)) {\n return `The ${agent.name} agent is taking longer than expected. Please try again, ask a simpler question, or open the ${agent.name} app directly.`;\n }\n return `Error calling ${agent.name}: ${msg}`;\n }\n}\n\nasync function enqueueIntegrationContinuationIfPossible(\n error: A2ATaskTimeoutError,\n agent: { name: string; url: string },\n ownerEmail: string | undefined,\n): Promise<boolean> {\n const integration = getIntegrationRequestContext();\n if (!integration || !ownerEmail) return false;\n\n try {\n const [{ insertA2AContinuation }, { dispatchA2AContinuation }] =\n await Promise.all([\n import(\"../integrations/a2a-continuations-store.js\"),\n import(\"../integrations/a2a-continuation-processor.js\"),\n ]);\n const continuation = await insertA2AContinuation({\n integrationTaskId: integration.taskId,\n platform: integration.incoming.platform,\n externalThreadId: integration.incoming.externalThreadId,\n incoming: integration.incoming,\n placeholderRef: integration.placeholderRef,\n ownerEmail,\n orgId: getRequestOrgId() ?? null,\n agentName: agent.name,\n agentUrl: agent.url,\n a2aTaskId: error.taskId,\n // Do not persist the short-lived JWT used for the initial send. The\n // continuation processor can mint a fresh token for each poll.\n a2aAuthToken: null,\n });\n await dispatchA2AContinuation(continuation.id).catch((err) => {\n console.error(\n `[call-agent] Failed to dispatch A2A continuation ${continuation.id}:`,\n err,\n );\n });\n return true;\n } catch (err) {\n console.error(\"[call-agent] Failed to enqueue A2A continuation:\", err);\n return false;\n }\n}\n\n// Expand bare leading-slash paths (e.g. \"/deck/abc\") into fully-qualified URLs\n// rooted at the receiving agent's host. The receiver doesn't always know it's\n// being called cross-app, so it may emit relative paths that resolve against\n// the caller's host (broken). Match a path that starts at a word boundary,\n// begins with `/`, and has at least one path segment after that. Skip if it\n// already looks like a fully-qualified URL.\nexport function expandRelativeUrls(text: string, agentUrl: string): string {\n if (!text || !agentUrl) return text;\n const base = agentUrl.replace(/\\/$/, \"\");\n // Path must start at boundary (start, whitespace, or punctuation that isn't\n // ':' — to avoid mangling `https://example.com/foo` or markdown link bodies).\n return text.replace(\n /(^|[\\s(\\[<\"'`])(\\/[a-z0-9_-][a-z0-9_/?&=%#.,:-]*)/gi,\n (_match, lead, path) => `${lead}${base}${path}`,\n );\n}\n"]}
|
|
@@ -5,6 +5,9 @@ export interface DiscoveredAgent {
|
|
|
5
5
|
url: string;
|
|
6
6
|
color: string;
|
|
7
7
|
}
|
|
8
|
+
export declare function shouldIncludeRemoteAgentManifest(manifest: {
|
|
9
|
+
id?: string | null;
|
|
10
|
+
}, selfAppId?: string): boolean;
|
|
8
11
|
/**
|
|
9
12
|
* Get built-in agents (static, no DB). Used as fallback and for seeding.
|
|
10
13
|
*/
|
|
@@ -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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E,eAAe,EAOnD,CAAC"}
|
|
@@ -21,6 +21,17 @@ const BUILTIN_AGENTS = visibleTemplates()
|
|
|
21
21
|
const HIDDEN_FIRST_PARTY_AGENT_IDS = new Set(TEMPLATES.filter((template) => template.hidden && template.prodUrl).map((template) => template.name));
|
|
22
22
|
const WORKSPACE_APPS_ENV_KEY = "AGENT_NATIVE_WORKSPACE_APPS_JSON";
|
|
23
23
|
const WORKSPACE_APPS_MANIFEST_FILE = "workspace-apps.json";
|
|
24
|
+
export function shouldIncludeRemoteAgentManifest(manifest, selfAppId) {
|
|
25
|
+
const id = manifest.id?.trim();
|
|
26
|
+
if (!id)
|
|
27
|
+
return false;
|
|
28
|
+
const normalizedId = id.toLowerCase();
|
|
29
|
+
const normalizedSelfAppId = selfAppId?.trim().toLowerCase();
|
|
30
|
+
if (normalizedSelfAppId && normalizedId === normalizedSelfAppId) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return !HIDDEN_FIRST_PARTY_AGENT_IDS.has(normalizedId);
|
|
34
|
+
}
|
|
24
35
|
/**
|
|
25
36
|
* Get built-in agents (static, no DB). Used as fallback and for seeding.
|
|
26
37
|
*/
|
|
@@ -64,9 +75,7 @@ export async function discoverAgents(selfAppId) {
|
|
|
64
75
|
if (!full)
|
|
65
76
|
continue;
|
|
66
77
|
const manifest = parseRemoteAgentManifest(full.content, r.path);
|
|
67
|
-
if (!manifest || manifest
|
|
68
|
-
continue;
|
|
69
|
-
if (HIDDEN_FIRST_PARTY_AGENT_IDS.has(manifest.id))
|
|
78
|
+
if (!manifest || !shouldIncludeRemoteAgentManifest(manifest, selfAppId))
|
|
70
79
|
continue;
|
|
71
80
|
// If the resource override carries a localhost URL but we're running
|
|
72
81
|
// in production (e.g. a stale dev-time seed got promoted to the prod
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-discovery.js","sourceRoot":"","sources":["../../src/server/agent-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAA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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, visibleTemplates } 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 the public template allow-list\n * without depending on @agent-native/shared-app-config at runtime.\n */\nconst BUILTIN_AGENTS: AgentEntry[] = visibleTemplates()\n .filter((template) => !!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((template) => template.hidden && template.prodUrl).map(\n (template) => template.name,\n ),\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\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, resourceListAccessible } =\n await import(\"../resources/store.js\");\n const { DEV_MODE_USER_EMAIL } = await import(\"./auth.js\");\n\n const isDevMode =\n typeof process !== \"undefined\" && process.env?.NODE_ENV !== \"production\";\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(\n ...(isDevMode\n ? await resourceListAccessible(DEV_MODE_USER_EMAIL, prefix)\n : await resourceList(SHARED_OWNER, prefix)),\n );\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 || manifest.id === selfAppId) continue;\n if (HIDDEN_FIRST_PARTY_AGENT_IDS.has(manifest.id)) 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 if (\n !isDevMode &&\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/agent-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAoBvE;;;;GAIG;AACH,MAAM,cAAc,GAAiB,gBAAgB,EAAE;KACpD,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;KACxC,GAAG,CAAC,CAAC,QA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,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, visibleTemplates } 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 the public template allow-list\n * without depending on @agent-native/shared-app-config at runtime.\n */\nconst BUILTIN_AGENTS: AgentEntry[] = visibleTemplates()\n .filter((template) => !!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((template) => template.hidden && template.prodUrl).map(\n (template) => template.name,\n ),\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, resourceListAccessible } =\n await import(\"../resources/store.js\");\n const { DEV_MODE_USER_EMAIL } = await import(\"./auth.js\");\n\n const isDevMode =\n typeof process !== \"undefined\" && process.env?.NODE_ENV !== \"production\";\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(\n ...(isDevMode\n ? await resourceListAccessible(DEV_MODE_USER_EMAIL, prefix)\n : await resourceList(SHARED_OWNER, prefix)),\n );\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 if (\n !isDevMode &&\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,7 +1,17 @@
|
|
|
1
1
|
// Export workspace-wide server plugin overrides here when you need them.
|
|
2
2
|
// Starter apps inherit these exports, so provide explicit framework defaults
|
|
3
3
|
// to keep generated workspaces warning-free until a workspace customizes them.
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
createAgentChatPlugin,
|
|
6
6
|
defaultAuthPlugin,
|
|
7
|
+
type AgentChatPluginOptions,
|
|
7
8
|
} from "@agent-native/core/server";
|
|
9
|
+
|
|
10
|
+
export function createWorkspaceAgentChatPlugin(
|
|
11
|
+
options?: AgentChatPluginOptions,
|
|
12
|
+
) {
|
|
13
|
+
return createAgentChatPlugin(options);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const defaultAgentChatPlugin = createWorkspaceAgentChatPlugin();
|
|
17
|
+
export { defaultAuthPlugin };
|
package/package.json
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
// Export workspace-wide server plugin overrides here when you need them.
|
|
2
2
|
// Starter apps inherit these exports, so provide explicit framework defaults
|
|
3
3
|
// to keep generated workspaces warning-free until a workspace customizes them.
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
createAgentChatPlugin,
|
|
6
6
|
defaultAuthPlugin,
|
|
7
|
+
type AgentChatPluginOptions,
|
|
7
8
|
} from "@agent-native/core/server";
|
|
9
|
+
|
|
10
|
+
export function createWorkspaceAgentChatPlugin(
|
|
11
|
+
options?: AgentChatPluginOptions,
|
|
12
|
+
) {
|
|
13
|
+
return createAgentChatPlugin(options);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const defaultAgentChatPlugin = createWorkspaceAgentChatPlugin();
|
|
17
|
+
export { defaultAuthPlugin };
|