@agent-native/core 0.7.23 → 0.7.24
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/README.md +2 -2
- package/dist/a2a/client.d.ts +10 -4
- package/dist/a2a/client.d.ts.map +1 -1
- package/dist/a2a/client.js +16 -1
- package/dist/a2a/client.js.map +1 -1
- package/dist/a2a/handlers.d.ts.map +1 -1
- package/dist/a2a/handlers.js +20 -17
- package/dist/a2a/handlers.js.map +1 -1
- package/dist/cli/create.d.ts +2 -1
- package/dist/cli/create.d.ts.map +1 -1
- package/dist/cli/create.js +13 -19
- package/dist/cli/create.js.map +1 -1
- package/dist/cli/index.js +23 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/workspace-dev.d.ts +3 -0
- package/dist/cli/workspace-dev.d.ts.map +1 -0
- package/dist/cli/workspace-dev.js +323 -0
- package/dist/cli/workspace-dev.js.map +1 -0
- package/dist/cli/workspacify.d.ts +3 -3
- package/dist/cli/workspacify.js +4 -4
- package/dist/cli/workspacify.js.map +1 -1
- package/dist/client/AgentPanel.d.ts.map +1 -1
- package/dist/client/AgentPanel.js +10 -9
- package/dist/client/AgentPanel.js.map +1 -1
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +2 -1
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
- package/dist/client/MultiTabAssistantChat.js +2 -1
- package/dist/client/MultiTabAssistantChat.js.map +1 -1
- package/dist/client/components/ui/tooltip.d.ts +8 -0
- package/dist/client/components/ui/tooltip.d.ts.map +1 -0
- package/dist/client/components/ui/tooltip.js +11 -0
- package/dist/client/components/ui/tooltip.js.map +1 -0
- package/dist/client/resources/ResourceTree.d.ts.map +1 -1
- package/dist/client/resources/ResourceTree.js +21 -17
- package/dist/client/resources/ResourceTree.js.map +1 -1
- package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
- package/dist/client/resources/ResourcesPanel.js +13 -11
- package/dist/client/resources/ResourcesPanel.js.map +1 -1
- package/dist/deploy/workspace-core.d.ts +1 -1
- package/dist/deploy/workspace-core.d.ts.map +1 -1
- package/dist/deploy/workspace-core.js +14 -11
- package/dist/deploy/workspace-core.js.map +1 -1
- package/dist/integrations/a2a-continuation-processor.d.ts +10 -0
- package/dist/integrations/a2a-continuation-processor.d.ts.map +1 -0
- package/dist/integrations/a2a-continuation-processor.js +150 -0
- package/dist/integrations/a2a-continuation-processor.js.map +1 -0
- package/dist/integrations/a2a-continuations-store.d.ts +41 -0
- package/dist/integrations/a2a-continuations-store.d.ts.map +1 -0
- package/dist/integrations/a2a-continuations-store.js +214 -0
- package/dist/integrations/a2a-continuations-store.js.map +1 -0
- package/dist/integrations/plugin.d.ts.map +1 -1
- package/dist/integrations/plugin.js +52 -0
- package/dist/integrations/plugin.js.map +1 -1
- package/dist/integrations/types.d.ts +5 -0
- package/dist/integrations/types.d.ts.map +1 -1
- package/dist/integrations/types.js.map +1 -1
- package/dist/integrations/webhook-handler.d.ts +6 -0
- package/dist/integrations/webhook-handler.d.ts.map +1 -1
- package/dist/integrations/webhook-handler.js +69 -15
- package/dist/integrations/webhook-handler.js.map +1 -1
- package/dist/org/handlers.d.ts.map +1 -1
- package/dist/org/handlers.js +22 -16
- package/dist/org/handlers.js.map +1 -1
- package/dist/scripts/call-agent.d.ts.map +1 -1
- package/dist/scripts/call-agent.js +91 -30
- package/dist/scripts/call-agent.js.map +1 -1
- package/dist/server/agent-discovery.d.ts.map +1 -1
- package/dist/server/agent-discovery.js +17 -105
- package/dist/server/agent-discovery.js.map +1 -1
- package/dist/server/agents-bundle.js +1 -1
- package/dist/server/agents-bundle.js.map +1 -1
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +29 -120
- package/dist/server/auth.js.map +1 -1
- package/dist/server/better-auth-instance.d.ts +1 -0
- package/dist/server/better-auth-instance.d.ts.map +1 -1
- package/dist/server/better-auth-instance.js.map +1 -1
- package/dist/server/builder-browser.d.ts.map +1 -1
- package/dist/server/builder-browser.js +7 -5
- package/dist/server/builder-browser.js.map +1 -1
- package/dist/server/framework-request-handler.js +1 -1
- package/dist/server/framework-request-handler.js.map +1 -1
- package/dist/server/onboarding-html.d.ts +1 -8
- package/dist/server/onboarding-html.d.ts.map +1 -1
- package/dist/server/onboarding-html.js +321 -152
- package/dist/server/onboarding-html.js.map +1 -1
- package/dist/server/request-context.d.ts +14 -3
- package/dist/server/request-context.d.ts.map +1 -1
- package/dist/server/request-context.js +3 -0
- package/dist/server/request-context.js.map +1 -1
- package/dist/templates/default/_gitignore +2 -0
- package/dist/templates/workspace-core/AGENTS.md +18 -71
- package/dist/templates/workspace-core/package.json +2 -20
- package/dist/templates/workspace-core/src/client/index.ts +2 -26
- package/dist/templates/workspace-core/src/index.ts +1 -21
- package/dist/templates/workspace-core/src/server/index.ts +3 -22
- package/dist/templates/workspace-root/README.md +17 -20
- package/dist/templates/workspace-root/_gitignore +3 -0
- package/dist/templates/workspace-root/package.json +6 -13
- package/dist/templates/workspace-root/pnpm-workspace.yaml +4 -2
- package/dist/vite/agents-bundle-plugin.js +2 -2
- package/dist/vite/agents-bundle-plugin.js.map +1 -1
- package/docs/content/authentication.md +3 -5
- package/docs/content/multi-app-workspace.md +38 -50
- package/package.json +1 -1
- package/src/templates/default/_gitignore +2 -0
- package/src/templates/workspace-core/AGENTS.md +18 -71
- package/src/templates/workspace-core/package.json +2 -20
- package/src/templates/workspace-core/src/client/index.ts +2 -26
- package/src/templates/workspace-core/src/index.ts +1 -21
- package/src/templates/workspace-core/src/server/index.ts +3 -22
- package/src/templates/workspace-root/README.md +17 -20
- package/src/templates/workspace-root/_gitignore +3 -0
- package/src/templates/workspace-root/package.json +6 -13
- package/src/templates/workspace-root/pnpm-workspace.yaml +4 -2
- package/dist/templates/default/.claude/settings.json +0 -100
- package/dist/templates/workspace-core/.agents/skills/company-policies/SKILL.md +0 -42
- package/dist/templates/workspace-core/actions/company-directory.ts +0 -38
- package/dist/templates/workspace-core/src/client/AuthenticatedLayout.tsx +0 -37
- package/dist/templates/workspace-core/src/credentials.ts +0 -67
- package/dist/templates/workspace-core/src/server/agent-chat-plugin.ts +0 -30
- package/dist/templates/workspace-core/src/server/auth-plugin.ts +0 -35
- package/dist/templates/workspace-core/styles/tokens.css +0 -22
- package/dist/templates/workspace-root/.github/workflows/ci.yml +0 -32
- package/dist/templates/workspace-root/scripts/workspace-dev.ts +0 -377
- package/src/templates/default/.claude/settings.json +0 -100
- package/src/templates/workspace-core/.agents/skills/company-policies/SKILL.md +0 -42
- package/src/templates/workspace-core/actions/company-directory.ts +0 -38
- package/src/templates/workspace-core/src/client/AuthenticatedLayout.tsx +0 -37
- package/src/templates/workspace-core/src/credentials.ts +0 -67
- package/src/templates/workspace-core/src/server/agent-chat-plugin.ts +0 -30
- package/src/templates/workspace-core/src/server/auth-plugin.ts +0 -35
- package/src/templates/workspace-core/styles/tokens.css +0 -22
- package/src/templates/workspace-root/.github/workflows/ci.yml +0 -32
- package/src/templates/workspace-root/scripts/workspace-dev.ts +0 -377
|
@@ -1,7 +1,38 @@
|
|
|
1
1
|
import { findAgent, discoverAgents } from "../server/agent-discovery.js";
|
|
2
|
-
import { A2AClient, callAgent, signA2AToken } from "../a2a/client.js";
|
|
3
|
-
import { getRequestUserEmail, getRequestOrgId, isIntegrationCallerRequest, } from "../server/request-context.js";
|
|
2
|
+
import { A2AClient, A2ATaskTimeoutError, callAgent, signA2AToken, } from "../a2a/client.js";
|
|
3
|
+
import { getRequestUserEmail, getRequestOrgId, isIntegrationCallerRequest, getIntegrationRequestContext, } from "../server/request-context.js";
|
|
4
4
|
import { getOrgDomain, getOrgA2ASecret } from "../org/context.js";
|
|
5
|
+
const DEFAULT_SERVERLESS_INTEGRATION_A2A_TIMEOUT_MS = 18_000;
|
|
6
|
+
const NETLIFY_INTEGRATION_A2A_TIMEOUT_MS = 50_000;
|
|
7
|
+
function parseTimeoutMs(value) {
|
|
8
|
+
if (!value)
|
|
9
|
+
return undefined;
|
|
10
|
+
const parsed = Number(value);
|
|
11
|
+
if (!Number.isFinite(parsed) || parsed <= 0)
|
|
12
|
+
return undefined;
|
|
13
|
+
return Math.floor(parsed);
|
|
14
|
+
}
|
|
15
|
+
function isServerlessHost() {
|
|
16
|
+
// Detection mirrors db/migrations.ts:297-301. On Cloudflare Workers/Pages,
|
|
17
|
+
// `process.env` is shimmed and CF_PAGES isn't reliably populated at runtime —
|
|
18
|
+
// the canonical signal is the `__cf_env` global injected by workerd.
|
|
19
|
+
return (!!process.env.NETLIFY ||
|
|
20
|
+
!!process.env.AWS_LAMBDA_FUNCTION_NAME ||
|
|
21
|
+
!!process.env.VERCEL ||
|
|
22
|
+
"__cf_env" in globalThis);
|
|
23
|
+
}
|
|
24
|
+
function getIntegrationCallTimeoutMs() {
|
|
25
|
+
if (!isServerlessHost() || !isIntegrationCallerRequest())
|
|
26
|
+
return undefined;
|
|
27
|
+
const configured = parseTimeoutMs(process.env.AGENT_NATIVE_INTEGRATION_A2A_TIMEOUT_MS);
|
|
28
|
+
if (configured !== undefined)
|
|
29
|
+
return configured;
|
|
30
|
+
// Netlify's current synchronous function budget is 60s, but leave room for
|
|
31
|
+
// cold start, polling overhead, and the caller's final platform response.
|
|
32
|
+
if (process.env.NETLIFY)
|
|
33
|
+
return NETLIFY_INTEGRATION_A2A_TIMEOUT_MS;
|
|
34
|
+
return DEFAULT_SERVERLESS_INTEGRATION_A2A_TIMEOUT_MS;
|
|
35
|
+
}
|
|
5
36
|
export const tool = {
|
|
6
37
|
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. " +
|
|
7
38
|
"IMPORTANT — handling the response: " +
|
|
@@ -119,33 +150,19 @@ export async function run(args, context, selfAppId) {
|
|
|
119
150
|
// response support, so message/stream returns a single JSON-RPC error
|
|
120
151
|
// body in a 200 response that our SSE parser silently consumes — the
|
|
121
152
|
// `for await` loop yields nothing AND keeps the connection open until
|
|
122
|
-
// the function timeout, eating the
|
|
123
|
-
// the sync fallback, Lambda is dead and the second fetch
|
|
124
|
-
// as "fetch failed". Async+poll has its own short fetches
|
|
125
|
-
// own budgets, so it works reliably across hosts. The
|
|
126
|
-
// we lose progressive in-UI text streaming for cross-app
|
|
127
|
-
// but the receiving agent's full response still surfaces via
|
|
128
|
-
// tool_result event below.
|
|
153
|
+
// the function timeout, eating the current serverless budget. By the
|
|
154
|
+
// time we get to the sync fallback, Lambda is dead and the second fetch
|
|
155
|
+
// errors out as "fetch failed". Async+poll has its own short fetches
|
|
156
|
+
// with their own budgets, so it works reliably across hosts. The
|
|
157
|
+
// trade-off is we lose progressive in-UI text streaming for cross-app
|
|
158
|
+
// A2A calls, but the receiving agent's full response still surfaces via
|
|
159
|
+
// the tool_result event below.
|
|
129
160
|
try {
|
|
130
|
-
// Apply
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
// bail before the lambda dies. On long-running hosts (local Node
|
|
136
|
-
// dev, self-hosted Node, Docker containers) the budget is
|
|
137
|
-
// effectively infinite, so the cap would just truncate
|
|
138
|
-
// slow-but-valid answers.
|
|
139
|
-
//
|
|
140
|
-
// Detection mirrors db/migrations.ts:297-301. On Cloudflare
|
|
141
|
-
// Workers/Pages, `process.env` is shimmed and CF_PAGES isn't
|
|
142
|
-
// reliably populated at runtime — the canonical signal is the
|
|
143
|
-
// `__cf_env` global injected by the workerd runtime.
|
|
144
|
-
const onServerlessHost = !!process.env.NETLIFY ||
|
|
145
|
-
!!process.env.AWS_LAMBDA_FUNCTION_NAME ||
|
|
146
|
-
!!process.env.VERCEL ||
|
|
147
|
-
"__cf_env" in globalThis;
|
|
148
|
-
const callTimeoutMs = onServerlessHost && isIntegrationCallerRequest() ? 18000 : undefined;
|
|
161
|
+
// Apply a polling cap ONLY for integration-platform callers on
|
|
162
|
+
// serverless hosts. Normal chat, local Node, self-hosted Node, and
|
|
163
|
+
// Docker can wait for slow-but-valid answers; integration processors
|
|
164
|
+
// still need to finish before their current function execution dies.
|
|
165
|
+
const callTimeoutMs = getIntegrationCallTimeoutMs();
|
|
149
166
|
responseText = await callAgent(agent.url, messageWithHint, {
|
|
150
167
|
userEmail: callerEmail,
|
|
151
168
|
orgDomain: callerOrgDomain,
|
|
@@ -162,8 +179,21 @@ export async function run(args, context, selfAppId) {
|
|
|
162
179
|
emitNewText(responseText);
|
|
163
180
|
}
|
|
164
181
|
catch (pollErr) {
|
|
165
|
-
|
|
166
|
-
|
|
182
|
+
if (pollErr instanceof A2ATaskTimeoutError) {
|
|
183
|
+
const queued = await enqueueIntegrationContinuationIfPossible(pollErr, agent, callerEmail);
|
|
184
|
+
if (queued) {
|
|
185
|
+
responseText = `The ${agent.name} agent is still working. I will update this thread with the final result when it finishes.`;
|
|
186
|
+
emitNewText(responseText);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
const reason = pollErr?.message ?? "unknown error";
|
|
190
|
+
responseText = `The ${agent.name} agent is taking longer than expected and didn't reply in time. (${reason})`;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
const reason = pollErr?.message ?? "unknown error";
|
|
195
|
+
responseText = `The ${agent.name} agent is taking longer than expected and didn't reply in time. (${reason})`;
|
|
196
|
+
}
|
|
167
197
|
}
|
|
168
198
|
context.send({
|
|
169
199
|
type: "agent_call",
|
|
@@ -205,6 +235,37 @@ export async function run(args, context, selfAppId) {
|
|
|
205
235
|
return `Error calling ${agent.name}: ${msg}`;
|
|
206
236
|
}
|
|
207
237
|
}
|
|
238
|
+
async function enqueueIntegrationContinuationIfPossible(error, agent, ownerEmail) {
|
|
239
|
+
const integration = getIntegrationRequestContext();
|
|
240
|
+
if (!integration || !ownerEmail)
|
|
241
|
+
return false;
|
|
242
|
+
try {
|
|
243
|
+
const [{ insertA2AContinuation }, { dispatchA2AContinuation }] = await Promise.all([
|
|
244
|
+
import("../integrations/a2a-continuations-store.js"),
|
|
245
|
+
import("../integrations/a2a-continuation-processor.js"),
|
|
246
|
+
]);
|
|
247
|
+
const continuation = await insertA2AContinuation({
|
|
248
|
+
integrationTaskId: integration.taskId,
|
|
249
|
+
platform: integration.incoming.platform,
|
|
250
|
+
externalThreadId: integration.incoming.externalThreadId,
|
|
251
|
+
incoming: integration.incoming,
|
|
252
|
+
placeholderRef: integration.placeholderRef,
|
|
253
|
+
ownerEmail,
|
|
254
|
+
orgId: getRequestOrgId() ?? null,
|
|
255
|
+
agentName: agent.name,
|
|
256
|
+
agentUrl: agent.url,
|
|
257
|
+
a2aTaskId: error.taskId,
|
|
258
|
+
});
|
|
259
|
+
await dispatchA2AContinuation(continuation.id).catch((err) => {
|
|
260
|
+
console.error(`[call-agent] Failed to dispatch A2A continuation ${continuation.id}:`, err);
|
|
261
|
+
});
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
catch (err) {
|
|
265
|
+
console.error("[call-agent] Failed to enqueue A2A continuation:", err);
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
208
269
|
// Expand bare leading-slash paths (e.g. "/deck/abc") into fully-qualified URLs
|
|
209
270
|
// rooted at the receiving agent's host. The receiver doesn't always know it's
|
|
210
271
|
// being called cross-app, so it may emit relative paths that resolve against
|
|
@@ -1 +1 @@
|
|
|
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,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,0BAA0B,GAC3B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,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AAI,gGAAgG,KAAK,CAAC,IAAI,gBAAgB,CAAC;QACrJ,CAAC;QACD,OAAO,iBAAiB,KAAK,CAAC,IAAI,KAAK,GAAG,EAAE,CAAC;IAC/C,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 { A2AClient, callAgent, signA2AToken } from \"../a2a/client.js\";\nimport {\n getRequestUserEmail,\n getRequestOrgId,\n isIntegrationCallerRequest,\n} from \"../server/request-context.js\";\nimport { getOrgDomain, getOrgA2ASecret } from \"../org/context.js\";\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/dashboard, include its FULLY-QUALIFIED URL (e.g. ${agent.url}/deck/<id>) in your reply, not a relative path. ` +\n `Use only IDs returned by your own actions — never invent slugs 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 } 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 26s budget. By the time we get to\n // the sync fallback, Lambda is dead and the second fetch errors out\n // as \"fetch failed\". Async+poll has its own short fetches with their\n // own budgets, so it works reliably across hosts. The trade-off is\n // we lose progressive in-UI text streaming for cross-app A2A calls,\n // but the receiving agent's full response still surfaces via the\n // tool_result event below.\n try {\n // Apply the 18s polling cap ONLY when we're on a serverless host\n // (Netlify / Vercel / AWS Lambda / Cloudflare Workers) AND the\n // call is from an integration-platform path. On those hosts the\n // function timeout (~26s on Netlify Pro) plus the platform's\n // deliver-by deadline are the binding budget, so dispatch must\n // bail before the lambda dies. On long-running hosts (local Node\n // dev, self-hosted Node, Docker containers) the budget is\n // effectively infinite, so the cap would just truncate\n // slow-but-valid answers.\n //\n // Detection mirrors db/migrations.ts:297-301. On Cloudflare\n // Workers/Pages, `process.env` is shimmed and CF_PAGES isn't\n // reliably populated at runtime — the canonical signal is the\n // `__cf_env` global injected by the workerd runtime.\n const onServerlessHost =\n !!process.env.NETLIFY ||\n !!process.env.AWS_LAMBDA_FUNCTION_NAME ||\n !!process.env.VERCEL ||\n \"__cf_env\" in globalThis;\n const callTimeoutMs =\n onServerlessHost && isIntegrationCallerRequest() ? 18000 : undefined;\n responseText = await callAgent(agent.url, messageWithHint, {\n userEmail: callerEmail,\n orgDomain: callerOrgDomain,\n orgSecret: callerOrgSecret,\n ...(callTimeoutMs ? { timeoutMs: callTimeoutMs } : {}),\n });\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 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\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 return expandRelativeUrls(response, agent.url) || \"(empty response)\";\n } catch (err: any) {\n const msg = err?.message ?? String(err);\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\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,EACL,mBAAmB,EACnB,eAAe,EACf,0BAA0B,EAC1B,4BAA4B,GAC7B,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K,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 {\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;\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\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/dashboard, include its FULLY-QUALIFIED URL (e.g. ${agent.url}/deck/<id>) in your reply, not a relative path. ` +\n `Use only IDs returned by your own actions — never invent slugs 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 } 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 userEmail: callerEmail,\n orgDomain: callerOrgDomain,\n orgSecret: callerOrgSecret,\n ...(callTimeoutMs ? { timeoutMs: callTimeoutMs } : {}),\n });\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 = `The ${agent.name} agent is still working. I will update this thread with the final result when it finishes.`;\n emitNewText(responseText);\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 = `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 return expandRelativeUrls(response, agent.url) || \"(empty response)\";\n } catch (err: any) {\n const msg = err?.message ?? String(err);\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 });\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-discovery.d.ts","sourceRoot":"","sources":["../../src/server/agent-discovery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent-discovery.d.ts","sourceRoot":"","sources":["../../src/server/agent-discovery.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AA6BD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,eAAe,EAAE,CAUtE;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,EAAE,CAAC,CAiE5B;AAED;;GAEG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAItC;AAeD;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,EAAE,eAAe,EAOnD,CAAC"}
|
|
@@ -1,113 +1,25 @@
|
|
|
1
|
+
import { visibleTemplates } from "../cli/templates-meta.js";
|
|
1
2
|
/**
|
|
2
|
-
* Built-in agent registry.
|
|
3
|
-
*
|
|
3
|
+
* Built-in agent registry. Derive this from the published CLI metadata so
|
|
4
|
+
* connected-agent discovery stays aligned with the public template allow-list
|
|
5
|
+
* without depending on @agent-native/shared-app-config at runtime.
|
|
4
6
|
*/
|
|
5
|
-
const BUILTIN_AGENTS =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
id: "calendar",
|
|
19
|
-
name: "Calendar",
|
|
20
|
-
description: "Google Calendar integration",
|
|
21
|
-
url: "https://calendar.agent-native.com",
|
|
22
|
-
devUrl: "http://localhost:8082",
|
|
23
|
-
devPort: 8082,
|
|
24
|
-
color: "#8B5CF6",
|
|
25
|
-
enabled: true,
|
|
26
|
-
mode: "prod",
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
id: "content",
|
|
30
|
-
name: "Content",
|
|
31
|
-
description: "Notion-like content workspace",
|
|
32
|
-
url: "https://content.agent-native.com",
|
|
33
|
-
devUrl: "http://localhost:8083",
|
|
34
|
-
devPort: 8083,
|
|
35
|
-
color: "#10B981",
|
|
36
|
-
enabled: true,
|
|
37
|
-
mode: "prod",
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
id: "analytics",
|
|
41
|
-
name: "Analytics",
|
|
42
|
-
description: "Analytics dashboard",
|
|
43
|
-
url: "https://analytics.agent-native.com",
|
|
44
|
-
devUrl: "http://localhost:8088",
|
|
45
|
-
devPort: 8088,
|
|
46
|
-
color: "#F59E0B",
|
|
47
|
-
enabled: true,
|
|
48
|
-
mode: "prod",
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
id: "slides",
|
|
52
|
-
name: "Slides",
|
|
53
|
-
description: "AI slide deck creator",
|
|
54
|
-
url: "https://slides.agent-native.com",
|
|
55
|
-
devUrl: "http://localhost:8086",
|
|
56
|
-
devPort: 8086,
|
|
57
|
-
color: "#EC4899",
|
|
58
|
-
enabled: true,
|
|
59
|
-
mode: "prod",
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
id: "videos",
|
|
63
|
-
name: "Videos",
|
|
64
|
-
description: "AI video creator",
|
|
65
|
-
url: "https://videos.agent-native.com",
|
|
66
|
-
devUrl: "http://localhost:8087",
|
|
67
|
-
devPort: 8087,
|
|
68
|
-
color: "#EF4444",
|
|
69
|
-
enabled: true,
|
|
70
|
-
mode: "prod",
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
id: "issues",
|
|
74
|
-
name: "Issues",
|
|
75
|
-
description: "Jira project tracker",
|
|
76
|
-
url: "https://issues.agent-native.com",
|
|
77
|
-
devUrl: "http://localhost:8091",
|
|
78
|
-
devPort: 8091,
|
|
79
|
-
color: "#6366F1",
|
|
80
|
-
enabled: true,
|
|
81
|
-
mode: "dev",
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
id: "forms",
|
|
85
|
-
name: "Forms",
|
|
86
|
-
description: "Form builder",
|
|
87
|
-
url: "https://forms.agent-native.com",
|
|
88
|
-
devUrl: "http://localhost:8084",
|
|
89
|
-
devPort: 8084,
|
|
90
|
-
color: "#06B6D4",
|
|
91
|
-
enabled: true,
|
|
92
|
-
mode: "prod",
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
id: "recruiting",
|
|
96
|
-
name: "Recruiting",
|
|
97
|
-
description: "AI-powered recruiting",
|
|
98
|
-
url: "https://recruiting.agent-native.com",
|
|
99
|
-
devUrl: "http://localhost:8090",
|
|
100
|
-
devPort: 8090,
|
|
101
|
-
color: "#16A34A",
|
|
102
|
-
enabled: true,
|
|
103
|
-
mode: "dev",
|
|
104
|
-
},
|
|
105
|
-
];
|
|
7
|
+
const BUILTIN_AGENTS = visibleTemplates()
|
|
8
|
+
.filter((template) => !!template.prodUrl)
|
|
9
|
+
.map((template) => ({
|
|
10
|
+
id: template.name,
|
|
11
|
+
name: template.label,
|
|
12
|
+
description: template.description ?? template.hint,
|
|
13
|
+
url: template.prodUrl,
|
|
14
|
+
devUrl: `http://localhost:${template.devPort}`,
|
|
15
|
+
devPort: template.devPort,
|
|
16
|
+
color: template.color,
|
|
17
|
+
}));
|
|
106
18
|
/**
|
|
107
19
|
* Get built-in agents (static, no DB). Used as fallback and for seeding.
|
|
108
20
|
*/
|
|
109
21
|
export function getBuiltinAgents(selfAppId) {
|
|
110
|
-
return BUILTIN_AGENTS.filter((app) => app.id !== selfAppId && app.
|
|
22
|
+
return BUILTIN_AGENTS.filter((app) => app.id !== selfAppId && app.url).map((app) => ({
|
|
111
23
|
id: app.id,
|
|
112
24
|
name: app.name,
|
|
113
25
|
description: app.description,
|
|
@@ -202,7 +114,7 @@ function resolveAgentUrl(app) {
|
|
|
202
114
|
* DB, which would override the built-in's prod URL for every later
|
|
203
115
|
* production deploy.
|
|
204
116
|
*/
|
|
205
|
-
export const BUILTIN_AGENTS_FOR_SEEDING = BUILTIN_AGENTS.filter((app) => app.
|
|
117
|
+
export const BUILTIN_AGENTS_FOR_SEEDING = BUILTIN_AGENTS.filter((app) => app.url).map((app) => ({
|
|
206
118
|
id: app.id,
|
|
207
119
|
name: app.name,
|
|
208
120
|
description: app.description,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-discovery.js","sourceRoot":"","sources":["../../src/server/agent-discovery.ts"],"names":[],"mappings":"AAqBA;;;GAGG;AACH,MAAM,cAAc,GAAiB;IACnC;QACE,EAAE,EAAE,MAAM;QACV,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,cAAc;QAC3B,GAAG,EAAE,+BAA+B;QACpC,MAAM,EAAE,uBAAuB;QAC/B,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,MAAM;KACb;IACD;QACE,EAAE,EAAE,UAAU;QACd,IAAI,EAAE,UAAU;QAChB,WAAW,EAAE,6BAA6B;QAC1C,GAAG,EAAE,mCAAmC;QACxC,MAAM,EAAE,uBAAuB;QAC/B,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,MAAM;KACb;IACD;QACE,EAAE,EAAE,SAAS;QACb,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,+BAA+B;QAC5C,GAAG,EAAE,kCAAkC;QACvC,MAAM,EAAE,uBAAuB;QAC/B,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,MAAM;KACb;IACD;QACE,EAAE,EAAE,WAAW;QACf,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE,qBAAqB;QAClC,GAAG,EAAE,oCAAoC;QACzC,MAAM,EAAE,uBAAuB;QAC/B,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,MAAM;KACb;IACD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AAE,GAAG,CAAC,WAAW;IAC5B,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,cAAc;IAC5B,KAAK,EAAE,GAAG,CAAC,KAAK;CACjB,CAAC,CAAC,CAAC","sourcesContent":["export 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 enabled: boolean;\n placeholder?: boolean;\n mode?: \"dev\" | \"prod\";\n}\n\n/**\n * Built-in agent registry. Mirrors DEFAULT_APPS from @agent-native/shared-app-config\n * but inlined here to avoid a cross-package dependency that breaks tsc.\n */\nconst BUILTIN_AGENTS: AgentEntry[] = [\n {\n id: \"mail\",\n name: \"Mail\",\n description: \"Email client\",\n url: \"https://mail.agent-native.com\",\n devUrl: \"http://localhost:8085\",\n devPort: 8085,\n color: \"#3B82F6\",\n enabled: true,\n mode: \"prod\",\n },\n {\n id: \"calendar\",\n name: \"Calendar\",\n description: \"Google Calendar integration\",\n url: \"https://calendar.agent-native.com\",\n devUrl: \"http://localhost:8082\",\n devPort: 8082,\n color: \"#8B5CF6\",\n enabled: true,\n mode: \"prod\",\n },\n {\n id: \"content\",\n name: \"Content\",\n description: \"Notion-like content workspace\",\n url: \"https://content.agent-native.com\",\n devUrl: \"http://localhost:8083\",\n devPort: 8083,\n color: \"#10B981\",\n enabled: true,\n mode: \"prod\",\n },\n {\n id: \"analytics\",\n name: \"Analytics\",\n description: \"Analytics dashboard\",\n url: \"https://analytics.agent-native.com\",\n devUrl: \"http://localhost:8088\",\n devPort: 8088,\n color: \"#F59E0B\",\n enabled: true,\n mode: \"prod\",\n },\n {\n id: \"slides\",\n name: \"Slides\",\n description: \"AI slide deck creator\",\n url: \"https://slides.agent-native.com\",\n devUrl: \"http://localhost:8086\",\n devPort: 8086,\n color: \"#EC4899\",\n enabled: true,\n mode: \"prod\",\n },\n {\n id: \"videos\",\n name: \"Videos\",\n description: \"AI video creator\",\n url: \"https://videos.agent-native.com\",\n devUrl: \"http://localhost:8087\",\n devPort: 8087,\n color: \"#EF4444\",\n enabled: true,\n mode: \"prod\",\n },\n {\n id: \"issues\",\n name: \"Issues\",\n description: \"Jira project tracker\",\n url: \"https://issues.agent-native.com\",\n devUrl: \"http://localhost:8091\",\n devPort: 8091,\n color: \"#6366F1\",\n enabled: true,\n mode: \"dev\",\n },\n {\n id: \"forms\",\n name: \"Forms\",\n description: \"Form builder\",\n url: \"https://forms.agent-native.com\",\n devUrl: \"http://localhost:8084\",\n devPort: 8084,\n color: \"#06B6D4\",\n enabled: true,\n mode: \"prod\",\n },\n {\n id: \"recruiting\",\n name: \"Recruiting\",\n description: \"AI-powered recruiting\",\n url: \"https://recruiting.agent-native.com\",\n devUrl: \"http://localhost:8090\",\n devPort: 8090,\n color: \"#16A34A\",\n enabled: true,\n mode: \"dev\",\n },\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(\n (app) => app.id !== selfAppId && app.enabled && !app.placeholder && app.url,\n ).map((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 * 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 resources = isDevMode\n ? await resourceListAccessible(DEV_MODE_USER_EMAIL, \"remote-agents/\")\n : await resourceList(SHARED_OWNER, \"remote-agents/\");\n const { parseRemoteAgentManifest } =\n await import(\"../resources/metadata.js\");\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\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 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\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(\n (app) => app.enabled && !app.placeholder && app.url,\n ).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,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAoB5D;;;;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,QAAQ,EAAE,EAAE,CAAC,CAAC;IAClB,EAAE,EAAE,QAAQ,CAAC,IAAI;IACjB,IAAI,EAAE,QAAQ,CAAC,KAAK;IACpB,WAAW,EAAE,QAAQ,CAAC,WAAW,IAAI,QAAQ,CAAC,IAAI;IAClD,GAAG,EAAE,QAAQ,CAAC,OAAQ;IACtB,MAAM,EAAE,oBAAoB,QAAQ,CAAC,OAAO,EAAE;IAC9C,OAAO,EAAE,QAAQ,CAAC,OAAO;IACzB,KAAK,EAAE,QAAQ,CAAC,KAAK;CACtB,CAAC,CAAC,CAAC;AAEN;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAkB;IACjD,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,SAAS,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CACxE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QACR,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,IAAI,EAAE,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SAAkB;IAElB,MAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IACrC,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,SAAS,CAAC,CAAC;IAC/C,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,gBAAgB;IACvB,OAAO,CACL,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,QAAQ,KAAK,YAAY,CACzE,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,GAAe;IACtC,IAAI,gBAAgB,EAAE,EAAE,CAAC;QACvB,OAAO,GAAG,CAAC,MAAM,IAAI,oBAAoB,GAAG,CAAC,OAAO,EAAE,CAAC;IACzD,CAAC;IACD,OAAO,GAAG,CAAC,GAAG,CAAC;AACjB,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 { 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\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 resources = isDevMode\n ? await resourceListAccessible(DEV_MODE_USER_EMAIL, \"remote-agents/\")\n : await resourceList(SHARED_OWNER, \"remote-agents/\");\n const { parseRemoteAgentManifest } =\n await import(\"../resources/metadata.js\");\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\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 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\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"]}
|
|
@@ -85,7 +85,7 @@ import path from "node:path";
|
|
|
85
85
|
* both the template and workspace-core paths can reuse it. `dirPrefix` is
|
|
86
86
|
* the display path that will be reported to the agent (e.g.
|
|
87
87
|
* `.agents/skills/<name>` for templates, or
|
|
88
|
-
* `<workspace-
|
|
88
|
+
* `<workspace-shared-package>/.agents/skills/<name>` for the workspace layer).
|
|
89
89
|
*/
|
|
90
90
|
function readSkillsDir(skillsDir, rootForRelative, out, skipExistingNames) {
|
|
91
91
|
if (!fs.existsSync(skillsDir))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents-bundle.js","sourceRoot":"","sources":["../../src/server/agents-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AA8CH,MAAM,KAAK,GAAiB,EAAE,QAAQ,EAAE,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AAEhF,IAAI,MAAM,GAAwB,IAAI,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;IAC3D,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,MAAM,GAAuB,EAAE,CAAC;IAEtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACnE,IAAI,CAAC,QAAQ;YAAE,SAAS;QACxB,MAAM,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC;QACnC,MAAM,OAAO,GAAG,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EAAE,CAAC,UAAU;iBACvB,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,gEAAgE;QAClE,CAAC;QACD,MAAM,GAAG,sBAAsB,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,eAAe,CAAC,CAAC;QAChE,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,GAAG,KAAK,CAAC;QACf,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAoB;IAC5D,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC7C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEpC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QAC9B,MAAM,MAAM,GACV,CAAC,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;YACrB,CAAC,CAAC,oBAAoB,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;YAChD,CAAC,CAAC,EAAE,CAAC;QACT,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,WAAW,IAAI,kBAAkB,GAAG,MAAM,EAAE,CAAC;IACxG,CAAC,CAAC,CAAC;IAEH,OAAO;;;;;;;;EAQP,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;UACR,CAAC;AACX,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,wBAAwB;IACtC,MAAM,GAAG,IAAI,CAAC;AAChB,CAAC","sourcesContent":["/**\n * Agents bundle — loads AGENTS.md and .agents/skills/ from the template.\n *\n * This is the single source of truth the framework's agent uses to mirror what\n * Claude Code / Codex / any other agent would see when running locally in the\n * repo. The filesystem is the canonical source; this module is just a loader\n * that works both in dev (direct fs read) and production (content bundled at\n * build time via the `virtual:agents-bundle` Vite plugin).\n *\n * Resolution order inside `loadAgentsBundle()`:\n * 1. Virtual module (`virtual:agents-bundle`) — inlined at build time by the\n * framework's Vite plugin. This is the ONLY path that works on edge\n * runtimes (Cloudflare Workers) where `readFileSync` doesn't exist.\n * 2. Filesystem fallback — `process.cwd()/AGENTS.md` +\n * `process.cwd()/.agents/skills/`. Only reliable in local dev and Node\n * production (`agent-native start`); not on Netlify/Vercel/CF at runtime.\n * 3. Empty bundle — everything silently returns empty strings.\n *\n * Result is cached in module scope so it's only computed once per cold start.\n */\n\nexport interface SkillMeta {\n name: string;\n description: string;\n}\n\nexport interface Skill {\n meta: SkillMeta;\n /** Contents of SKILL.md (the entry file of the skill). */\n content: string;\n /**\n * Filesystem path to the skill directory, relative to the template root\n * (e.g. `.agents/skills/create-deck`). The agent can read any file here via\n * shell in dev — skills are folders, not single files, and may contain\n * supporting assets, scripts, or additional markdown.\n */\n dir: string;\n /**\n * Files inside the skill directory (relative to the skill dir), excluding\n * `SKILL.md`. Lets the agent know what else is available without a separate\n * `ls` call. Empty array if the skill is single-file.\n */\n extraFiles: string[];\n}\n\nexport interface AgentsBundle {\n /** Contents of the template's AGENTS.md (empty string if missing). */\n agentsMd: string;\n /**\n * Contents of the workspace core's AGENTS.md, if the app is inside an\n * enterprise monorepo with a `workspaceCore` configured. Empty string\n * otherwise. Sits between the framework system prompt and the template's\n * AGENTS.md in the instruction stack.\n */\n workspaceAgentsMd?: string;\n /**\n * Map from skill name → skill content. Contains skills merged from the\n * workspace core layer (if present) and the template layer. On name\n * collision, the template's version wins so apps can override a shared\n * enterprise skill by dropping a same-named file under\n * `.agents/skills/<name>/`.\n */\n skills: Record<string, Skill>;\n}\n\nconst EMPTY: AgentsBundle = { agentsMd: \"\", workspaceAgentsMd: \"\", skills: {} };\n\nlet cached: AgentsBundle | null = null;\n\n/**\n * Parse the YAML frontmatter at the top of a skill file.\n * Only pulls out `name` and `description` — deliberately simple, no YAML lib.\n * Handles:\n * - Inline: `description: Some text`\n * - Folded scalar: `description: >-\\n multi\\n line` → \"multi line\"\n * - Literal scalar: `description: |\\n multi\\n line` → \"multi\\nline\"\n */\nexport function parseSkillFrontmatter(content: string): Partial<SkillMeta> {\n const match = content.match(/^---\\r?\\n([\\s\\S]+?)\\r?\\n---/);\n if (!match) return {};\n const lines = match[1].split(/\\r?\\n/);\n const result: Partial<SkillMeta> = {};\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n const keyMatch = line.match(/^([a-zA-Z_][a-zA-Z0-9_-]*):\\s*(.*)$/);\n if (!keyMatch) continue;\n const [, key, valueRaw] = keyMatch;\n const trimmed = valueRaw.trim();\n\n const isFolded = trimmed === \">\" || trimmed === \">-\";\n const isLiteral = trimmed === \"|\" || trimmed === \"|-\";\n\n let value: string;\n if (isFolded || isLiteral) {\n // Collect subsequent indented lines (at least one leading space).\n const block: string[] = [];\n let j = i + 1;\n while (j < lines.length) {\n const next = lines[j];\n if (next.length === 0) {\n block.push(\"\");\n j++;\n continue;\n }\n if (!/^\\s/.test(next)) break;\n block.push(next.replace(/^\\s+/, \"\"));\n j++;\n }\n // Trim trailing blank lines\n while (block.length > 0 && block[block.length - 1] === \"\") block.pop();\n value = isFolded\n ? block.filter((l) => l !== \"\").join(\" \")\n : block.join(\"\\n\");\n i = j - 1;\n } else {\n value = trimmed;\n }\n\n if (key === \"name\" && value) result.name = value;\n else if (key === \"description\" && value) result.description = value;\n }\n\n return result;\n}\n\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Paths to a workspace-core's agent resources, for merging into a template's\n * bundle. All fields optional — pass null for any missing piece.\n */\nexport interface WorkspaceAgentsSource {\n /** Absolute path to the workspace core's skills/ directory. */\n skillsDir: string | null;\n /** Absolute path to the workspace core's AGENTS.md. */\n agentsMdPath: string | null;\n /** Root dir (used to compute `dir` paths for workspace-core skills). */\n rootDir: string;\n}\n\n/**\n * Read one skills directory into a `Record<string, Skill>`. Extracted so\n * both the template and workspace-core paths can reuse it. `dirPrefix` is\n * the display path that will be reported to the agent (e.g.\n * `.agents/skills/<name>` for templates, or\n * `<workspace-core-package>/skills/<name>` for the workspace core).\n */\nfunction readSkillsDir(\n skillsDir: string,\n rootForRelative: string,\n out: Record<string, Skill>,\n skipExistingNames: boolean,\n): void {\n if (!fs.existsSync(skillsDir)) return;\n const entries = fs.readdirSync(skillsDir, { withFileTypes: true });\n for (const entry of entries) {\n if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;\n const skillDirAbs = path.join(skillsDir, entry.name);\n const skillFile = path.join(skillDirAbs, \"SKILL.md\");\n try {\n const realSkillFile = fs.realpathSync(skillFile);\n if (!fs.existsSync(realSkillFile)) continue;\n const content = fs.readFileSync(realSkillFile, \"utf-8\");\n const meta = parseSkillFrontmatter(content);\n const name = meta.name ?? entry.name;\n if (skipExistingNames && out[name]) continue; // Template wins\n\n const extraFiles: string[] = [];\n try {\n const walk = (subdir: string, prefix: string) => {\n for (const e of fs.readdirSync(subdir, { withFileTypes: true })) {\n const abs = path.join(subdir, e.name);\n const rel = prefix ? `${prefix}/${e.name}` : e.name;\n if (e.isDirectory() || e.isSymbolicLink()) {\n try {\n const stat = fs.statSync(abs);\n if (stat.isDirectory()) walk(abs, rel);\n } catch {}\n } else if (e.isFile() && e.name !== \"SKILL.md\") {\n extraFiles.push(rel);\n }\n }\n };\n walk(skillDirAbs, \"\");\n } catch {}\n extraFiles.sort();\n\n out[name] = {\n meta: { name, description: meta.description ?? \"\" },\n content,\n dir: path.relative(rootForRelative, skillDirAbs).replace(/\\\\/g, \"/\"),\n extraFiles,\n };\n } catch {\n // Skip unreadable skills\n }\n }\n}\n\n/**\n * Read AGENTS.md + all skills directly from the filesystem rooted at `cwd`.\n * Optionally also reads a workspace-core's AGENTS.md and skills directory\n * and merges them in (template wins on name collisions). Used by both the\n * Vite plugin (at build time) and the runtime fallback (in dev / Node prod).\n *\n * Synchronous — the Vite plugin's load hook calls it inline during the build.\n */\nexport function readAgentsBundleFromFs(\n cwd: string,\n workspaceSource: WorkspaceAgentsSource | null = null,\n): AgentsBundle {\n let agentsMd = \"\";\n try {\n const agentsMdPath = path.join(cwd, \"AGENTS.md\");\n if (fs.existsSync(agentsMdPath)) {\n agentsMd = fs.readFileSync(agentsMdPath, \"utf-8\");\n }\n } catch {}\n\n let workspaceAgentsMd = \"\";\n if (workspaceSource?.agentsMdPath) {\n try {\n if (fs.existsSync(workspaceSource.agentsMdPath)) {\n workspaceAgentsMd = fs.readFileSync(\n workspaceSource.agentsMdPath,\n \"utf-8\",\n );\n }\n } catch {}\n }\n\n // Merge skills: template first (so its entries are authoritative), then\n // workspace-core with skipExistingNames=true so same-named skills don't\n // overwrite the template's.\n const skills: Record<string, Skill> = {};\n try {\n const skillsDir = path.join(cwd, \".agents\", \"skills\");\n readSkillsDir(skillsDir, cwd, skills, false);\n } catch {}\n\n if (workspaceSource?.skillsDir) {\n try {\n readSkillsDir(\n workspaceSource.skillsDir,\n workspaceSource.rootDir,\n skills,\n true,\n );\n } catch {}\n }\n\n return { agentsMd, workspaceAgentsMd, skills };\n}\n\n/**\n * Load the agents bundle. Returns a cached result on subsequent calls.\n * Tries the virtual module first (works everywhere, including edge), then\n * falls back to filesystem reads from `process.cwd()` — which, when a\n * workspace core is present, also merges in the workspace core's skills\n * and AGENTS.md.\n */\nexport async function loadAgentsBundle(): Promise<AgentsBundle> {\n if (cached) return cached;\n\n // 1. Try the Vite-emitted virtual module. This is the path that works on\n // every deployment target because the content is inlined at build time.\n // The Vite plugin itself is responsible for merging workspace-core\n // content into the bundle it emits.\n try {\n // @ts-expect-error — virtual module is resolved at build time by our\n // Vite plugin; nothing exists at this path on disk.\n const mod = await import(\"virtual:agents-bundle\");\n if (mod && mod.default) {\n cached = mod.default as AgentsBundle;\n return cached;\n }\n } catch {\n // Virtual module not available — fall through to filesystem.\n }\n\n // 2. Filesystem fallback — works in dev / Node prod. If a workspace core\n // is present in the ancestor chain, merge its skills + AGENTS.md in.\n try {\n let workspaceSource: WorkspaceAgentsSource | null = null;\n try {\n const { getWorkspaceCoreExports } =\n await import(\"../deploy/workspace-core.js\");\n const ws = await getWorkspaceCoreExports(process.cwd());\n if (ws) {\n workspaceSource = {\n skillsDir: ws.skillsDir,\n agentsMdPath: ws.agentsMdPath,\n rootDir: ws.packageDir,\n };\n }\n } catch {\n // workspace-core discovery isn't available (e.g. edge runtime).\n }\n cached = readAgentsBundleFromFs(process.cwd(), workspaceSource);\n return cached;\n } catch {\n cached = EMPTY;\n return cached;\n }\n}\n\n/**\n * Generate the `<skills>` block to inject into the system prompt.\n *\n * Skills are folders at `.agents/skills/<name>/` containing a `SKILL.md` entry\n * file plus any number of supporting files (additional markdown, examples,\n * images, scripts). This block lists what's available and how to read them.\n *\n * In dev mode the agent has shell access and reads skills via `cat` — exactly\n * like running `claude` locally in the repo. In production mode the agent has\n * no shell; templates that need skill content at runtime should inline the\n * critical parts directly in `AGENTS.md`.\n */\nexport function generateSkillsPromptBlock(bundle: AgentsBundle): string {\n const entries = Object.values(bundle.skills);\n if (entries.length === 0) return \"\";\n\n const lines = entries.map((s) => {\n const extras =\n s.extraFiles.length > 0\n ? ` (also contains: ${s.extraFiles.join(\", \")})`\n : \"\";\n return `- \\`${s.meta.name}\\` at \\`${s.dir}/\\` — ${s.meta.description || \"(no description)\"}${extras}`;\n });\n\n return `<skills>\nThe following skills live in the repo at \\`.agents/skills/<name>/\\`. Each skill is a folder containing a \\`SKILL.md\\` entry file and sometimes supporting files. Read a skill BEFORE starting a task it applies to.\n\nTo read a skill in dev mode (when you have shell access):\n \\`shell(command=\"cat .agents/skills/<name>/SKILL.md\")\\`\n \\`shell(command=\"ls .agents/skills/<name>/\")\\` to see all files in the folder\n\nAvailable skills:\n${lines.join(\"\\n\")}\n</skills>`;\n}\n\n/** For tests — reset the module cache. */\nexport function __resetAgentsBundleCache(): void {\n cached = null;\n}\n"]}
|
|
1
|
+
{"version":3,"file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;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAoB;IAC5D,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC7C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEpC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QAC9B,MAAM,MAAM,GACV,CAAC,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;YACrB,CAAC,CAAC,oBAAoB,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;YAChD,CAAC,CAAC,EAAE,CAAC;QACT,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,WAAW,IAAI,kBAAkB,GAAG,MAAM,EAAE,CAAC;IACxG,CAAC,CAAC,CAAC;IAEH,OAAO;;;;;;;;EAQP,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;UACR,CAAC;AACX,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,wBAAwB;IACtC,MAAM,GAAG,IAAI,CAAC;AAChB,CAAC","sourcesContent":["/**\n * Agents bundle — loads AGENTS.md and .agents/skills/ from the template.\n *\n * This is the single source of truth the framework's agent uses to mirror what\n * Claude Code / Codex / any other agent would see when running locally in the\n * repo. The filesystem is the canonical source; this module is just a loader\n * that works both in dev (direct fs read) and production (content bundled at\n * build time via the `virtual:agents-bundle` Vite plugin).\n *\n * Resolution order inside `loadAgentsBundle()`:\n * 1. Virtual module (`virtual:agents-bundle`) — inlined at build time by the\n * framework's Vite plugin. This is the ONLY path that works on edge\n * runtimes (Cloudflare Workers) where `readFileSync` doesn't exist.\n * 2. Filesystem fallback — `process.cwd()/AGENTS.md` +\n * `process.cwd()/.agents/skills/`. Only reliable in local dev and Node\n * production (`agent-native start`); not on Netlify/Vercel/CF at runtime.\n * 3. Empty bundle — everything silently returns empty strings.\n *\n * Result is cached in module scope so it's only computed once per cold start.\n */\n\nexport interface SkillMeta {\n name: string;\n description: string;\n}\n\nexport interface Skill {\n meta: SkillMeta;\n /** Contents of SKILL.md (the entry file of the skill). */\n content: string;\n /**\n * Filesystem path to the skill directory, relative to the template root\n * (e.g. `.agents/skills/create-deck`). The agent can read any file here via\n * shell in dev — skills are folders, not single files, and may contain\n * supporting assets, scripts, or additional markdown.\n */\n dir: string;\n /**\n * Files inside the skill directory (relative to the skill dir), excluding\n * `SKILL.md`. Lets the agent know what else is available without a separate\n * `ls` call. Empty array if the skill is single-file.\n */\n extraFiles: string[];\n}\n\nexport interface AgentsBundle {\n /** Contents of the template's AGENTS.md (empty string if missing). */\n agentsMd: string;\n /**\n * Contents of the workspace core's AGENTS.md, if the app is inside an\n * enterprise monorepo with a `workspaceCore` configured. Empty string\n * otherwise. Sits between the framework system prompt and the template's\n * AGENTS.md in the instruction stack.\n */\n workspaceAgentsMd?: string;\n /**\n * Map from skill name → skill content. Contains skills merged from the\n * workspace core layer (if present) and the template layer. On name\n * collision, the template's version wins so apps can override a shared\n * enterprise skill by dropping a same-named file under\n * `.agents/skills/<name>/`.\n */\n skills: Record<string, Skill>;\n}\n\nconst EMPTY: AgentsBundle = { agentsMd: \"\", workspaceAgentsMd: \"\", skills: {} };\n\nlet cached: AgentsBundle | null = null;\n\n/**\n * Parse the YAML frontmatter at the top of a skill file.\n * Only pulls out `name` and `description` — deliberately simple, no YAML lib.\n * Handles:\n * - Inline: `description: Some text`\n * - Folded scalar: `description: >-\\n multi\\n line` → \"multi line\"\n * - Literal scalar: `description: |\\n multi\\n line` → \"multi\\nline\"\n */\nexport function parseSkillFrontmatter(content: string): Partial<SkillMeta> {\n const match = content.match(/^---\\r?\\n([\\s\\S]+?)\\r?\\n---/);\n if (!match) return {};\n const lines = match[1].split(/\\r?\\n/);\n const result: Partial<SkillMeta> = {};\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n const keyMatch = line.match(/^([a-zA-Z_][a-zA-Z0-9_-]*):\\s*(.*)$/);\n if (!keyMatch) continue;\n const [, key, valueRaw] = keyMatch;\n const trimmed = valueRaw.trim();\n\n const isFolded = trimmed === \">\" || trimmed === \">-\";\n const isLiteral = trimmed === \"|\" || trimmed === \"|-\";\n\n let value: string;\n if (isFolded || isLiteral) {\n // Collect subsequent indented lines (at least one leading space).\n const block: string[] = [];\n let j = i + 1;\n while (j < lines.length) {\n const next = lines[j];\n if (next.length === 0) {\n block.push(\"\");\n j++;\n continue;\n }\n if (!/^\\s/.test(next)) break;\n block.push(next.replace(/^\\s+/, \"\"));\n j++;\n }\n // Trim trailing blank lines\n while (block.length > 0 && block[block.length - 1] === \"\") block.pop();\n value = isFolded\n ? block.filter((l) => l !== \"\").join(\" \")\n : block.join(\"\\n\");\n i = j - 1;\n } else {\n value = trimmed;\n }\n\n if (key === \"name\" && value) result.name = value;\n else if (key === \"description\" && value) result.description = value;\n }\n\n return result;\n}\n\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Paths to a workspace-core's agent resources, for merging into a template's\n * bundle. All fields optional — pass null for any missing piece.\n */\nexport interface WorkspaceAgentsSource {\n /** Absolute path to the workspace core's skills/ directory. */\n skillsDir: string | null;\n /** Absolute path to the workspace core's AGENTS.md. */\n agentsMdPath: string | null;\n /** Root dir (used to compute `dir` paths for workspace-core skills). */\n rootDir: string;\n}\n\n/**\n * Read one skills directory into a `Record<string, Skill>`. Extracted so\n * both the template and workspace-core paths can reuse it. `dirPrefix` is\n * the display path that will be reported to the agent (e.g.\n * `.agents/skills/<name>` for templates, or\n * `<workspace-shared-package>/.agents/skills/<name>` for the workspace layer).\n */\nfunction readSkillsDir(\n skillsDir: string,\n rootForRelative: string,\n out: Record<string, Skill>,\n skipExistingNames: boolean,\n): void {\n if (!fs.existsSync(skillsDir)) return;\n const entries = fs.readdirSync(skillsDir, { withFileTypes: true });\n for (const entry of entries) {\n if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;\n const skillDirAbs = path.join(skillsDir, entry.name);\n const skillFile = path.join(skillDirAbs, \"SKILL.md\");\n try {\n const realSkillFile = fs.realpathSync(skillFile);\n if (!fs.existsSync(realSkillFile)) continue;\n const content = fs.readFileSync(realSkillFile, \"utf-8\");\n const meta = parseSkillFrontmatter(content);\n const name = meta.name ?? entry.name;\n if (skipExistingNames && out[name]) continue; // Template wins\n\n const extraFiles: string[] = [];\n try {\n const walk = (subdir: string, prefix: string) => {\n for (const e of fs.readdirSync(subdir, { withFileTypes: true })) {\n const abs = path.join(subdir, e.name);\n const rel = prefix ? `${prefix}/${e.name}` : e.name;\n if (e.isDirectory() || e.isSymbolicLink()) {\n try {\n const stat = fs.statSync(abs);\n if (stat.isDirectory()) walk(abs, rel);\n } catch {}\n } else if (e.isFile() && e.name !== \"SKILL.md\") {\n extraFiles.push(rel);\n }\n }\n };\n walk(skillDirAbs, \"\");\n } catch {}\n extraFiles.sort();\n\n out[name] = {\n meta: { name, description: meta.description ?? \"\" },\n content,\n dir: path.relative(rootForRelative, skillDirAbs).replace(/\\\\/g, \"/\"),\n extraFiles,\n };\n } catch {\n // Skip unreadable skills\n }\n }\n}\n\n/**\n * Read AGENTS.md + all skills directly from the filesystem rooted at `cwd`.\n * Optionally also reads a workspace-core's AGENTS.md and skills directory\n * and merges them in (template wins on name collisions). Used by both the\n * Vite plugin (at build time) and the runtime fallback (in dev / Node prod).\n *\n * Synchronous — the Vite plugin's load hook calls it inline during the build.\n */\nexport function readAgentsBundleFromFs(\n cwd: string,\n workspaceSource: WorkspaceAgentsSource | null = null,\n): AgentsBundle {\n let agentsMd = \"\";\n try {\n const agentsMdPath = path.join(cwd, \"AGENTS.md\");\n if (fs.existsSync(agentsMdPath)) {\n agentsMd = fs.readFileSync(agentsMdPath, \"utf-8\");\n }\n } catch {}\n\n let workspaceAgentsMd = \"\";\n if (workspaceSource?.agentsMdPath) {\n try {\n if (fs.existsSync(workspaceSource.agentsMdPath)) {\n workspaceAgentsMd = fs.readFileSync(\n workspaceSource.agentsMdPath,\n \"utf-8\",\n );\n }\n } catch {}\n }\n\n // Merge skills: template first (so its entries are authoritative), then\n // workspace-core with skipExistingNames=true so same-named skills don't\n // overwrite the template's.\n const skills: Record<string, Skill> = {};\n try {\n const skillsDir = path.join(cwd, \".agents\", \"skills\");\n readSkillsDir(skillsDir, cwd, skills, false);\n } catch {}\n\n if (workspaceSource?.skillsDir) {\n try {\n readSkillsDir(\n workspaceSource.skillsDir,\n workspaceSource.rootDir,\n skills,\n true,\n );\n } catch {}\n }\n\n return { agentsMd, workspaceAgentsMd, skills };\n}\n\n/**\n * Load the agents bundle. Returns a cached result on subsequent calls.\n * Tries the virtual module first (works everywhere, including edge), then\n * falls back to filesystem reads from `process.cwd()` — which, when a\n * workspace core is present, also merges in the workspace core's skills\n * and AGENTS.md.\n */\nexport async function loadAgentsBundle(): Promise<AgentsBundle> {\n if (cached) return cached;\n\n // 1. Try the Vite-emitted virtual module. This is the path that works on\n // every deployment target because the content is inlined at build time.\n // The Vite plugin itself is responsible for merging workspace-core\n // content into the bundle it emits.\n try {\n // @ts-expect-error — virtual module is resolved at build time by our\n // Vite plugin; nothing exists at this path on disk.\n const mod = await import(\"virtual:agents-bundle\");\n if (mod && mod.default) {\n cached = mod.default as AgentsBundle;\n return cached;\n }\n } catch {\n // Virtual module not available — fall through to filesystem.\n }\n\n // 2. Filesystem fallback — works in dev / Node prod. If a workspace core\n // is present in the ancestor chain, merge its skills + AGENTS.md in.\n try {\n let workspaceSource: WorkspaceAgentsSource | null = null;\n try {\n const { getWorkspaceCoreExports } =\n await import(\"../deploy/workspace-core.js\");\n const ws = await getWorkspaceCoreExports(process.cwd());\n if (ws) {\n workspaceSource = {\n skillsDir: ws.skillsDir,\n agentsMdPath: ws.agentsMdPath,\n rootDir: ws.packageDir,\n };\n }\n } catch {\n // workspace-core discovery isn't available (e.g. edge runtime).\n }\n cached = readAgentsBundleFromFs(process.cwd(), workspaceSource);\n return cached;\n } catch {\n cached = EMPTY;\n return cached;\n }\n}\n\n/**\n * Generate the `<skills>` block to inject into the system prompt.\n *\n * Skills are folders at `.agents/skills/<name>/` containing a `SKILL.md` entry\n * file plus any number of supporting files (additional markdown, examples,\n * images, scripts). This block lists what's available and how to read them.\n *\n * In dev mode the agent has shell access and reads skills via `cat` — exactly\n * like running `claude` locally in the repo. In production mode the agent has\n * no shell; templates that need skill content at runtime should inline the\n * critical parts directly in `AGENTS.md`.\n */\nexport function generateSkillsPromptBlock(bundle: AgentsBundle): string {\n const entries = Object.values(bundle.skills);\n if (entries.length === 0) return \"\";\n\n const lines = entries.map((s) => {\n const extras =\n s.extraFiles.length > 0\n ? ` (also contains: ${s.extraFiles.join(\", \")})`\n : \"\";\n return `- \\`${s.meta.name}\\` at \\`${s.dir}/\\` — ${s.meta.description || \"(no description)\"}${extras}`;\n });\n\n return `<skills>\nThe following skills live in the repo at \\`.agents/skills/<name>/\\`. Each skill is a folder containing a \\`SKILL.md\\` entry file and sometimes supporting files. Read a skill BEFORE starting a task it applies to.\n\nTo read a skill in dev mode (when you have shell access):\n \\`shell(command=\"cat .agents/skills/<name>/SKILL.md\")\\`\n \\`shell(command=\"ls .agents/skills/<name>/\")\\` to see all files in the folder\n\nAvailable skills:\n${lines.join(\"\\n\")}\n</skills>`;\n}\n\n/** For tests — reset the module cache. */\nexport function __resetAgentsBundleCache(): void {\n cached = null;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/server/auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/server/auth.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAsChE,KAAK,KAAK,GAAG,SAAS,CAAC;AASvB,OAAO,KA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