@agent-native/core 0.165.0 → 0.165.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/corpus/README.md CHANGED
@@ -31,4 +31,4 @@ rg -n "defineAction|useActionQuery" node_modules/@agent-native/core/corpus
31
31
 
32
32
  ## Generated Counts
33
33
 
34
- - template files: 8484
34
+ - template files: 8485
@@ -0,0 +1,6 @@
1
+ ---
2
+ type: fixed
3
+ date: 2026-08-20
4
+ ---
5
+
6
+ Dispatch chat now loads its OpenRouter provider reliably in production.
@@ -19,9 +19,11 @@
19
19
  "@agent-native/toolkit": "workspace:*",
20
20
  "@fontsource-variable/inter": "^5.2.8",
21
21
  "@libsql/client": "^0.15.8",
22
+ "@openrouter/ai-sdk-provider": "^2.9.1",
22
23
  "@radix-ui/react-tooltip": "^1.2.7",
23
24
  "@tabler/icons-react": "catalog:",
24
25
  "@tanstack/react-query": "^5.99.2",
26
+ "ai": "6.0.258",
25
27
  "h3": "catalog:",
26
28
  "isbot": "^5",
27
29
  "next-themes": "^0.4.6",
@@ -12,6 +12,8 @@ NPM_CONFIG_PRODUCTION = "false"
12
12
 
13
13
  [context.production.environment]
14
14
  AGENT_NATIVE_HOSTED_HARNESS = "true"
15
+ AGENT_NATIVE_ENABLE_KEEP_WARM = "1"
16
+ AGENT_NATIVE_DISABLE_KEEP_WARM_BACKGROUND = "1"
15
17
  # Macros owns its schema at release time (`migrate:production` above), so
16
18
  # production request functions must not probe the database for migrations.
17
19
  # Preview functions still run request-path migrations because previews do not
@@ -239,6 +239,15 @@ function compareMcpUrl(value) {
239
239
  return value.trim().replace(/\/+$/, "");
240
240
  }
241
241
  }
242
+ function startMcpOAuthReconnect(server) {
243
+ const returnUrl = `${window.location.pathname}${window.location.search}${window.location.hash}`;
244
+ const params = new URLSearchParams({
245
+ serverId: server.id,
246
+ scope: server.scope,
247
+ return: returnUrl,
248
+ });
249
+ window.location.assign(agentNativePath(`/_agent-native/mcp/servers/oauth/start?${params}`));
250
+ }
242
251
  function McpServerStatus({ server, onReconnect, reconnecting = false, reconnectError, }) {
243
252
  const t = useT();
244
253
  if (server.status.state === "connected") {
@@ -362,7 +371,9 @@ function McpIntegrationsSection({ query }) {
362
371
  return (_jsxs("div", { className: "flex items-start gap-3 py-3.5", children: [_jsx("span", { className: "mt-0.5 flex size-9 shrink-0 items-center justify-center rounded-lg border border-border/70 bg-background text-muted-foreground", children: _jsx(IconServer, { className: "size-4" }) }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { className: "truncate text-sm font-medium text-foreground", children: server.name }), _jsx("span", { className: "text-[11px] text-muted-foreground", children: server.scope === "user"
363
372
  ? t("mcpIntegrations.personal")
364
373
  : t("mcpIntegrations.sharedWithWorkspace") })] }), _jsx(McpServerStatus, { server: server, onReconnect: server.status.state === "error"
365
- ? () => void reconnect(server)
374
+ ? () => server.authMode === "oauth"
375
+ ? startMcpOAuthReconnect(server)
376
+ : void reconnect(server)
366
377
  : undefined, reconnecting: reconnectingKey === key, reconnectError: reconnectError?.key === key
367
378
  ? reconnectError.message
368
379
  : undefined })] }), canRemove && (_jsx("button", { type: "button", onClick: () => void removeServer(server), disabled: deleteServer.isPending, className: "shrink-0 rounded-md border border-border px-2.5 py-1.5 text-xs font-medium text-foreground transition-colors hover:bg-accent disabled:opacity-50", children: deleteTarget === key ? "Confirm" : "Remove" }))] }, key));
@@ -26,8 +26,8 @@ export declare const getCollabState: import("h3").EventHandlerWithFetch<import("
26
26
  * Body: { update: string (base64), requestSource?: string }
27
27
  */
28
28
  export declare const postCollabUpdate: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
29
- error: string;
30
29
  ok?: undefined;
30
+ error: string;
31
31
  } | {
32
32
  error?: undefined;
33
33
  ok: boolean;
@@ -16,6 +16,7 @@ export interface McpOAuthFlow {
16
16
  clientInformation: StoredOAuthClientInformation;
17
17
  discoveryState?: McpOAuthDiscoveryState;
18
18
  returnUrl?: string;
19
+ replaceServerId?: string;
19
20
  expiresAt: number;
20
21
  }
21
22
  export interface McpOAuthRoutesOptions {
@@ -8,7 +8,7 @@ import { getH3App } from "../server/framework-request-handler.js";
8
8
  import { getAppUrl, resolveOAuthRedirectUri } from "../server/google-oauth.js";
9
9
  import { runWithRequestContext } from "../server/request-context.js";
10
10
  import { finishMcpOAuthAuthorization, startMcpOAuthAuthorization, validateMcpOAuthCallbackIssuer, } from "./oauth-client.js";
11
- import { addOAuthRemoteServer, normalizeServerName, validateRemoteUrl, } from "./remote-store.js";
11
+ import { addOAuthRemoteServer, listRemoteServers, normalizeServerName, replaceOAuthRemoteServer, validateRemoteUrl, } from "./remote-store.js";
12
12
  const FLOW_COOKIE = "an_mcp_oauth_flow";
13
13
  const FLOW_TTL_SECONDS = 10 * 60;
14
14
  const FLOW_COOKIE_CHUNK_SIZE = 2_800;
@@ -69,8 +69,33 @@ async function handleMcpOAuthStart(event) {
69
69
  if (!session?.email)
70
70
  return unauthorized(event);
71
71
  const query = getQuery(event);
72
- const rawUrl = text(query.url);
73
- const rawName = text(query.name);
72
+ const reconnectServerId = text(query.serverId);
73
+ const reconnectScope = query.scope === "org" ? "org" : "user";
74
+ const reconnectOrg = reconnectScope === "org" ? await getOrgContext(event) : null;
75
+ const reconnectScopeId = reconnectScope === "user" ? session.email : (reconnectOrg?.orgId ?? "");
76
+ let reconnectServer;
77
+ if (reconnectServerId) {
78
+ if (reconnectScope === "org" &&
79
+ (!reconnectScopeId || !isOrgAdmin(reconnectOrg?.role))) {
80
+ setResponseStatus(event, reconnectScopeId ? 403 : 400);
81
+ return {
82
+ error: reconnectScopeId
83
+ ? "Only organization owners and admins can reconnect an org MCP server."
84
+ : "Join an organization before reconnecting an org MCP server.",
85
+ };
86
+ }
87
+ reconnectServer = (await listRemoteServers(reconnectScope, reconnectScopeId)).find((server) => server.id === reconnectServerId);
88
+ if (!reconnectServer) {
89
+ setResponseStatus(event, 404);
90
+ return { error: "MCP server was not found." };
91
+ }
92
+ if (!reconnectServer.oauthSecretKey) {
93
+ setResponseStatus(event, 400);
94
+ return { error: "This MCP server does not use OAuth credentials." };
95
+ }
96
+ }
97
+ const rawUrl = reconnectServer?.url ?? text(query.url);
98
+ const rawName = reconnectServer?.name ?? text(query.name);
74
99
  const returnUrl = text(query.return);
75
100
  if (!rawUrl || !rawName) {
76
101
  setResponseStatus(event, 400);
@@ -159,6 +184,7 @@ async function handleMcpOAuthStart(event) {
159
184
  ? { discoveryState: started.discoveryState }
160
185
  : {}),
161
186
  ...(safeReturnUrl ? { returnUrl: safeReturnUrl } : {}),
187
+ ...(reconnectServerId ? { replaceServerId: reconnectServerId } : {}),
162
188
  expiresAt: Date.now() + FLOW_TTL_SECONDS * 1_000,
163
189
  };
164
190
  setMcpOAuthFlowCookie(event, flow, redirectUri.startsWith("https://"));
@@ -245,12 +271,14 @@ async function handleMcpOAuthCallback(event, options) {
245
271
  authorizationCode: code,
246
272
  iss,
247
273
  }));
248
- const result = await addOAuthRemoteServer(flow.scope, flow.scopeId, {
249
- name: flow.name,
250
- url: flow.url,
251
- description: flow.description,
252
- credentials: finished.credentials,
253
- });
274
+ const result = flow.replaceServerId
275
+ ? await replaceOAuthRemoteServer(flow.scope, flow.scopeId, flow.replaceServerId, finished.credentials)
276
+ : await addOAuthRemoteServer(flow.scope, flow.scopeId, {
277
+ name: flow.name,
278
+ url: flow.url,
279
+ description: flow.description,
280
+ credentials: finished.credentials,
281
+ });
254
282
  if (!result.ok) {
255
283
  setResponseStatus(event, 400);
256
284
  return { error: result.error };
@@ -107,6 +107,18 @@ export declare function addOAuthRemoteServer(scope: RemoteMcpScope, scopeId: str
107
107
  ok: false;
108
108
  error: string;
109
109
  }>;
110
+ /**
111
+ * Replace the OAuth grant for an existing server without changing its id or
112
+ * display name. Reconnect must update the saved grant in place; registering a
113
+ * second row makes the original connection impossible to repair.
114
+ */
115
+ export declare function replaceOAuthRemoteServer(scope: RemoteMcpScope, scopeId: string, serverId: string, credentials: McpOAuthCredentialBundle): Promise<{
116
+ ok: true;
117
+ server: StoredRemoteMcpServer;
118
+ } | {
119
+ ok: false;
120
+ error: string;
121
+ }>;
110
122
  export declare function addFirstPartyRemoteServer(orgId: string, input: {
111
123
  appId: string;
112
124
  name: string;
@@ -193,6 +193,77 @@ export async function addOAuthRemoteServer(scope, scopeId, input) {
193
193
  };
194
194
  }
195
195
  }
196
+ /**
197
+ * Replace the OAuth grant for an existing server without changing its id or
198
+ * display name. Reconnect must update the saved grant in place; registering a
199
+ * second row makes the original connection impossible to repair.
200
+ */
201
+ export async function replaceOAuthRemoteServer(scope, scopeId, serverId, credentials) {
202
+ const credentialResource = validateRemoteUrl(credentials.serverUrl);
203
+ if (!credentialResource.ok || !credentialResource.url) {
204
+ return {
205
+ ok: false,
206
+ error: "MCP server URL must match the OAuth credential resource URL",
207
+ };
208
+ }
209
+ const existing = await readList(scope, scopeId);
210
+ const index = existing.findIndex((server) => server.id === serverId);
211
+ const current = index >= 0 ? existing[index] : undefined;
212
+ if (!current)
213
+ return { ok: false, error: "MCP server was not found" };
214
+ if (!current.oauthSecretKey) {
215
+ return {
216
+ ok: false,
217
+ error: "This MCP server does not use OAuth credentials",
218
+ };
219
+ }
220
+ if (current.url !== credentialResource.url.toString()) {
221
+ return {
222
+ ok: false,
223
+ error: "MCP server URL must match the saved OAuth connection",
224
+ };
225
+ }
226
+ const nextSecretKey = `mcp_oauth:${shortId()}`;
227
+ const nextCredentials = {
228
+ ...credentials,
229
+ serverUrl: credentialResource.url.toString(),
230
+ };
231
+ try {
232
+ await saveMcpOAuthCredentials({
233
+ key: nextSecretKey,
234
+ scope,
235
+ scopeId,
236
+ credentials: nextCredentials,
237
+ });
238
+ const server = {
239
+ ...current,
240
+ url: nextCredentials.serverUrl,
241
+ oauthSecretKey: nextSecretKey,
242
+ };
243
+ const next = [...existing];
244
+ next[index] = server;
245
+ await writeList(scope, scopeId, next);
246
+ await revokeMcpOAuthCredentials({
247
+ key: current.oauthSecretKey,
248
+ scope,
249
+ scopeId,
250
+ serverUrl: current.url,
251
+ }).catch(() => undefined);
252
+ return { ok: true, server };
253
+ }
254
+ catch (err) {
255
+ await revokeMcpOAuthCredentials({
256
+ key: nextSecretKey,
257
+ scope,
258
+ scopeId,
259
+ serverUrl: nextCredentials.serverUrl,
260
+ }).catch(() => undefined);
261
+ return {
262
+ ok: false,
263
+ error: `Failed to replace MCP OAuth credentials: ${err?.message ?? err}`,
264
+ };
265
+ }
266
+ }
196
267
  export async function addFirstPartyRemoteServer(orgId, input) {
197
268
  const trust = await isFirstPartyRemoteEndpointTrusted(orgId, input.appId, input.url);
198
269
  if (!trust.ok)
@@ -13,13 +13,13 @@
13
13
  export declare function createNotificationsHandler(): import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<"" | import("./types.js").Notification[] | {
14
14
  count: number;
15
15
  updated?: undefined;
16
- ok?: undefined;
17
16
  error?: undefined;
17
+ ok?: undefined;
18
18
  } | {
19
19
  count?: undefined;
20
20
  updated: number;
21
- ok?: undefined;
22
21
  error?: undefined;
22
+ ok?: undefined;
23
23
  } | {
24
24
  count?: undefined;
25
25
  updated?: undefined;
@@ -28,6 +28,6 @@ export declare function createNotificationsHandler(): import("h3").EventHandlerW
28
28
  } | {
29
29
  count?: undefined;
30
30
  updated?: undefined;
31
- ok: boolean;
32
31
  error?: undefined;
32
+ ok: boolean;
33
33
  }>>;
@@ -51,8 +51,8 @@ export declare function handleDeleteResource(event: any): Promise<{
51
51
  error: string;
52
52
  ok?: undefined;
53
53
  } | {
54
- ok: boolean;
55
54
  error?: undefined;
55
+ ok: boolean;
56
56
  }>;
57
57
  /** POST /_agent-native/resources/upload — upload a file as a resource */
58
58
  export declare function handleUploadResource(event: any): Promise<import("./store.js").Resource | {
@@ -73,10 +73,10 @@ export declare function handleUploadResource(event: any): Promise<import("./stor
73
73
  runId: string | null;
74
74
  expiresAt: number | null;
75
75
  metadata: string | null;
76
+ error?: undefined;
76
77
  url: string;
77
78
  provider: string;
78
79
  storageSetupRequired?: undefined;
79
- error?: undefined;
80
80
  } | {
81
81
  error: string;
82
82
  storageSetupRequired: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-native/core",
3
- "version": "0.165.0",
3
+ "version": "0.165.1",
4
4
  "description": "Framework for agent-native application development — where AI agents and UI share SQL state, actions, and context",
5
5
  "homepage": "https://github.com/BuilderIO/agent-native#readme",
6
6
  "bugs": {
@@ -427,8 +427,8 @@
427
427
  "y-protocols": "^1.0.7",
428
428
  "yjs": "^13.6.32",
429
429
  "zod": "^4.3.6",
430
- "@agent-native/recap-cli": "0.5.5",
431
- "@agent-native/toolkit": "^0.16.8"
430
+ "@agent-native/toolkit": "^0.16.8",
431
+ "@agent-native/recap-cli": "0.5.5"
432
432
  },
433
433
  "devDependencies": {
434
434
  "@ai-sdk/anthropic": "^3.0.71",