@agent-native/core 0.158.3 → 0.158.4

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.
@@ -17,11 +17,11 @@ declare const _default: import("../../action.js").ActionDefinition<{
17
17
  id?: undefined;
18
18
  provider?: undefined;
19
19
  } | {
20
- error?: undefined;
21
20
  configured?: undefined;
22
21
  connectPath?: undefined;
23
22
  url: string;
24
23
  id: string;
25
24
  provider: string;
25
+ error?: undefined;
26
26
  }>;
27
27
  export default _default;
@@ -137,13 +137,13 @@ export declare function screenMemoryMcpToolDefinitions(): ({
137
137
  inputSchema: {
138
138
  type: string;
139
139
  properties: {
140
- count?: undefined;
141
140
  query?: undefined;
142
141
  minutes?: undefined;
143
142
  limit?: undefined;
144
143
  clientHint?: undefined;
145
144
  timestamp?: undefined;
146
145
  chapterId?: undefined;
146
+ count?: undefined;
147
147
  startAt?: undefined;
148
148
  endAt?: undefined;
149
149
  reason?: undefined;
@@ -159,7 +159,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
159
159
  inputSchema: {
160
160
  type: string;
161
161
  properties: {
162
- count?: undefined;
163
162
  query: {
164
163
  type: string;
165
164
  description: string;
@@ -175,6 +174,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
175
174
  clientHint?: undefined;
176
175
  timestamp?: undefined;
177
176
  chapterId?: undefined;
177
+ count?: undefined;
178
178
  startAt?: undefined;
179
179
  endAt?: undefined;
180
180
  reason?: undefined;
@@ -190,7 +190,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
190
190
  inputSchema: {
191
191
  type: string;
192
192
  properties: {
193
- count?: undefined;
194
193
  minutes: {
195
194
  type: string;
196
195
  description: string;
@@ -200,6 +199,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
200
199
  clientHint?: undefined;
201
200
  timestamp?: undefined;
202
201
  chapterId?: undefined;
202
+ count?: undefined;
203
203
  startAt?: undefined;
204
204
  endAt?: undefined;
205
205
  reason?: undefined;
@@ -216,7 +216,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
216
216
  type: string;
217
217
  required: string[];
218
218
  properties: {
219
- count?: undefined;
220
219
  query: {
221
220
  type: string;
222
221
  description: string;
@@ -235,6 +234,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
235
234
  };
236
235
  timestamp?: undefined;
237
236
  chapterId?: undefined;
237
+ count?: undefined;
238
238
  startAt?: undefined;
239
239
  endAt?: undefined;
240
240
  reason?: undefined;
@@ -250,7 +250,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
250
250
  type: string;
251
251
  required: string[];
252
252
  properties: {
253
- count?: undefined;
254
253
  query?: undefined;
255
254
  minutes?: undefined;
256
255
  limit?: undefined;
@@ -264,6 +263,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
264
263
  description: string;
265
264
  };
266
265
  chapterId?: undefined;
266
+ count?: undefined;
267
267
  startAt?: undefined;
268
268
  endAt?: undefined;
269
269
  includeMicrophone?: undefined;
@@ -314,13 +314,13 @@ export declare function screenMemoryMcpToolDefinitions(): ({
314
314
  type: string;
315
315
  required: string[];
316
316
  properties: {
317
- count?: undefined;
318
317
  query?: undefined;
319
318
  minutes?: undefined;
320
319
  limit?: undefined;
321
320
  clientHint?: undefined;
322
321
  timestamp?: undefined;
323
322
  chapterId?: undefined;
323
+ count?: undefined;
324
324
  startAt: {
325
325
  type: string;
326
326
  description: string;
@@ -349,13 +349,13 @@ export declare function screenMemoryMcpToolDefinitions(): ({
349
349
  type: string;
350
350
  required: string[];
351
351
  properties: {
352
- count?: undefined;
353
352
  query?: undefined;
354
353
  minutes?: undefined;
355
354
  limit?: undefined;
356
355
  clientHint?: undefined;
357
356
  timestamp?: undefined;
358
357
  chapterId?: undefined;
358
+ count?: undefined;
359
359
  startAt?: undefined;
360
360
  endAt?: undefined;
361
361
  reason?: undefined;
@@ -16,18 +16,18 @@ export declare function createNotificationsHandler(): import("h3").EventHandlerW
16
16
  error?: undefined;
17
17
  ok?: undefined;
18
18
  } | {
19
- count?: undefined;
20
19
  updated: number;
21
20
  error?: undefined;
22
21
  ok?: undefined;
23
- } | {
24
22
  count?: undefined;
23
+ } | {
25
24
  updated?: undefined;
26
25
  error: string;
27
26
  ok?: undefined;
28
- } | {
29
27
  count?: undefined;
28
+ } | {
30
29
  updated?: undefined;
31
30
  error?: undefined;
32
31
  ok: boolean;
32
+ count?: undefined;
33
33
  }>>;
@@ -41,16 +41,16 @@ export declare function createObservabilityHandler(): import("h3").EventHandlerW
41
41
  thumbsUpRate: number;
42
42
  avgEvalScore: number;
43
43
  } | {
44
+ error?: undefined;
44
45
  summary: import("./types.js").TraceSummary;
45
46
  spans: import("./types.js").TraceSpan[];
46
47
  id?: undefined;
47
- error?: undefined;
48
48
  ok?: undefined;
49
49
  } | {
50
+ error?: undefined;
50
51
  summary?: undefined;
51
52
  spans?: undefined;
52
53
  id: string;
53
- error?: undefined;
54
54
  ok?: undefined;
55
55
  } | {
56
56
  summary?: undefined;
@@ -59,9 +59,9 @@ export declare function createObservabilityHandler(): import("h3").EventHandlerW
59
59
  error: any;
60
60
  ok?: undefined;
61
61
  } | {
62
+ error?: undefined;
62
63
  summary?: undefined;
63
64
  spans?: undefined;
64
65
  id?: undefined;
65
- error?: undefined;
66
66
  ok: boolean;
67
67
  }>>;
@@ -15,6 +15,6 @@ export declare function createProgressHandler(): import("h3").EventHandlerWithFe
15
15
  error: string;
16
16
  ok?: undefined;
17
17
  } | {
18
- ok: boolean;
19
18
  error?: undefined;
19
+ ok: boolean;
20
20
  }>>;
@@ -27,10 +27,10 @@ export declare function resolveAgentEngineApiKeyWriteTarget(event: H3Event, scop
27
27
  export declare function createAgentEngineApiKeyHandler(): import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
28
28
  error: any;
29
29
  } | {
30
+ error?: undefined;
30
31
  ok: boolean;
31
32
  key: string;
32
33
  baseUrlKey?: string;
33
34
  scope: AgentEngineApiKeyScope;
34
- error?: undefined;
35
35
  }>>;
36
36
  export {};
@@ -1535,6 +1535,21 @@ function escapeHtmlAttr(value) {
1535
1535
  .replace(/>/g, "&gt;")
1536
1536
  .replace(/"/g, "&quot;");
1537
1537
  }
1538
+ const DESKTOP_MAGIC_LINK_CALLBACK_PATH = "/_agent-native/auth/magic-link/desktop-callback";
1539
+ const DESKTOP_MAGIC_LINK_LANDING_PATH = "/_agent-native/auth/magic-link/desktop-landing";
1540
+ const BETTER_AUTH_MAGIC_LINK_VERIFY_PATH = "/_agent-native/auth/ba/magic-link/verify";
1541
+ function desktopMagicLinkLandingPage(verificationUrl) {
1542
+ const safeVerificationUrl = escapeHtmlAttr(verificationUrl);
1543
+ const html = `<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Continue sign-in</title></head><body><main><h1>Continue signing in</h1><p>Click continue to finish signing in to the Agent Native desktop app.</p><form method="get" action="${safeVerificationUrl}"><button type="submit">Continue</button></form></main></body></html>`;
1544
+ return new Response(html, {
1545
+ status: 200,
1546
+ headers: {
1547
+ "cache-control": "no-store",
1548
+ "content-type": "text/html; charset=utf-8",
1549
+ "referrer-policy": "no-referrer",
1550
+ },
1551
+ });
1552
+ }
1538
1553
  function injectLoginSocialImageMeta(loginHtml, event) {
1539
1554
  const headCloseIdx = loginHtml.indexOf("</head>");
1540
1555
  if (headCloseIdx === -1)
@@ -3034,6 +3049,53 @@ async function mountBetterAuthRoutes(app, options) {
3034
3049
  // Magic-link verification happens in the system browser, so native shells
3035
3050
  // need the verified browser session copied into the same one-time exchange
3036
3051
  // used by Google OAuth before they can establish their own WebView session.
3052
+ // Keep the desktop email URL itself non-consuming: mail security scanners
3053
+ // commonly prefetch GET links, while Better Auth consumes a magic-link token
3054
+ // on the first verification GET. The explicit form action below is the only
3055
+ // request that reaches Better Auth's consuming verification endpoint.
3056
+ app.use(DESKTOP_MAGIC_LINK_LANDING_PATH, defineEventHandler((event) => {
3057
+ if (!isReadMethod(event)) {
3058
+ setResponseStatus(event, 405);
3059
+ return { error: "Method not allowed" };
3060
+ }
3061
+ const query = getQuery(event);
3062
+ const token = typeof query.token === "string" ? query.token.trim() : "";
3063
+ const callbackURL = typeof query.callbackURL === "string" ? query.callbackURL : "";
3064
+ if (!token || !callbackURL) {
3065
+ setResponseStatus(event, 400);
3066
+ return { error: "Invalid desktop magic-link" };
3067
+ }
3068
+ let callback;
3069
+ try {
3070
+ callback = new URL(callbackURL, getOrigin(event));
3071
+ }
3072
+ catch {
3073
+ setResponseStatus(event, 400);
3074
+ return { error: "Invalid desktop magic-link" };
3075
+ }
3076
+ if (callback.origin !== new URL(getOrigin(event)).origin ||
3077
+ !callback.pathname.endsWith(DESKTOP_MAGIC_LINK_CALLBACK_PATH) ||
3078
+ !normalizeDesktopFlowId(callback.searchParams.get("flow_id")) ||
3079
+ !normalizeDesktopFlowVerifier(callback.searchParams.get("verifier"))) {
3080
+ setResponseStatus(event, 400);
3081
+ return { error: "Invalid desktop magic-link" };
3082
+ }
3083
+ const verificationURL = new URL(getOrigin(event));
3084
+ verificationURL.pathname =
3085
+ getAppBasePath() + BETTER_AUTH_MAGIC_LINK_VERIFY_PATH;
3086
+ verificationURL.searchParams.set("token", token);
3087
+ for (const key of [
3088
+ "callbackURL",
3089
+ "newUserCallbackURL",
3090
+ "errorCallbackURL",
3091
+ ]) {
3092
+ const value = query[key];
3093
+ if (typeof value === "string" && value) {
3094
+ verificationURL.searchParams.set(key, value);
3095
+ }
3096
+ }
3097
+ return desktopMagicLinkLandingPage(verificationURL.toString());
3098
+ }));
3037
3099
  app.use("/_agent-native/auth/magic-link/desktop-callback", defineEventHandler(async (event) => {
3038
3100
  if (!isReadMethod(event)) {
3039
3101
  setResponseStatus(event, 405);
@@ -3041,18 +3103,42 @@ async function mountBetterAuthRoutes(app, options) {
3041
3103
  }
3042
3104
  const flowId = normalizeDesktopFlowId(getQuery(event).flow_id);
3043
3105
  const verifier = normalizeDesktopFlowVerifier(getQuery(event).verifier);
3106
+ const callbackError = getQuery(event).error;
3044
3107
  if (!flowId) {
3045
3108
  setResponseStatus(event, 400);
3046
3109
  return { error: "Missing flow_id" };
3047
3110
  }
3048
3111
  if (!verifier) {
3112
+ setDesktopExchangeError(flowId, {
3113
+ message: AUTH_MAGIC_LINK_FALLBACK,
3114
+ code: "missing_verifier",
3115
+ });
3116
+ return oauthErrorPage(AUTH_MAGIC_LINK_FALLBACK);
3117
+ }
3118
+ if (typeof callbackError === "string" && callbackError.trim()) {
3119
+ const code = callbackError
3120
+ .trim()
3121
+ .replace(/[^a-z0-9_-]/gi, "_")
3122
+ .slice(0, 64);
3123
+ setDesktopExchangeError(flowId, {
3124
+ message: AUTH_MAGIC_LINK_FALLBACK,
3125
+ code: code || "callback_error",
3126
+ });
3127
+ logGoogleOAuthDebug(event, "magic-link-callback-error", {
3128
+ flowId,
3129
+ message: callbackError,
3130
+ code: code || "callback_error",
3131
+ });
3049
3132
  return oauthErrorPage(AUTH_MAGIC_LINK_FALLBACK);
3050
3133
  }
3051
3134
  const session = await getSession(event);
3052
3135
  if (!session?.email || !session.token) {
3053
3136
  setDesktopExchangeError(flowId, {
3054
3137
  message: AUTH_MAGIC_LINK_FALLBACK,
3055
- code: "callback_error",
3138
+ code: "callback_session_missing",
3139
+ });
3140
+ logGoogleOAuthDebug(event, "magic-link-callback-session-missing", {
3141
+ flowId,
3056
3142
  });
3057
3143
  return oauthErrorPage(AUTH_MAGIC_LINK_FALLBACK);
3058
3144
  }
@@ -3068,11 +3154,18 @@ async function mountBetterAuthRoutes(app, options) {
3068
3154
  });
3069
3155
  setDesktopExchangeError(flowId, {
3070
3156
  message: AUTH_MAGIC_LINK_FALLBACK,
3071
- code: "callback_error",
3157
+ code: "callback_session_persist_failed",
3158
+ });
3159
+ logGoogleOAuthDebug(event, "magic-link-callback-session-persist-failed", {
3160
+ flowId,
3072
3161
  });
3073
3162
  return oauthErrorPage(AUTH_MAGIC_LINK_FALLBACK);
3074
3163
  }
3075
- if (!(await claimDesktopMagicLinkFlow(flowId, verifier, session.token, session.email))) {
3164
+ const claimed = await claimDesktopMagicLinkFlow(flowId, verifier, session.token, session.email);
3165
+ if (!claimed) {
3166
+ logGoogleOAuthDebug(event, "magic-link-callback-flow-claim-failed", {
3167
+ flowId,
3168
+ });
3076
3169
  return oauthErrorPage(AUTH_MAGIC_LINK_FALLBACK);
3077
3170
  }
3078
3171
  return oauthDesktopExchangePage("Sign-in complete. You can return to the app.", !isElectronRequest(event));
@@ -152,6 +152,15 @@ export declare function getBetterAuth(config?: BetterAuthConfig): Promise<Better
152
152
  * Use this in hot paths where you know init has already happened.
153
153
  */
154
154
  export declare function getBetterAuthSync(): BetterAuthInstance | undefined;
155
+ /**
156
+ * Email security scanners commonly prefetch ordinary GET links. Better Auth
157
+ * intentionally consumes a magic-link token on that first GET, so a scanner
158
+ * can otherwise spend a desktop flow before the user ever clicks it. Keep the
159
+ * normal web link unchanged and put only desktop flows behind an explicit
160
+ * confirmation page that hands the original verification URL back after the
161
+ * user acts.
162
+ */
163
+ export declare function desktopMagicLinkLandingUrl(value: string): string | undefined;
155
164
  /**
156
165
  * The subset of Better Auth's internal adapter we use for federated-SSO
157
166
  * JIT account linking. Better Auth owns these writes (id + timestamp +
@@ -549,6 +549,53 @@ export async function getBetterAuth(config) {
549
549
  export function getBetterAuthSync() {
550
550
  return _auth;
551
551
  }
552
+ const BETTER_AUTH_MAGIC_LINK_VERIFY_MARKER = "/_agent-native/auth/ba/magic-link/verify";
553
+ const DESKTOP_MAGIC_LINK_CALLBACK_MARKER = "/_agent-native/auth/magic-link/desktop-callback";
554
+ const DESKTOP_MAGIC_LINK_LANDING_MARKER = "/_agent-native/auth/magic-link/desktop-landing";
555
+ /**
556
+ * Email security scanners commonly prefetch ordinary GET links. Better Auth
557
+ * intentionally consumes a magic-link token on that first GET, so a scanner
558
+ * can otherwise spend a desktop flow before the user ever clicks it. Keep the
559
+ * normal web link unchanged and put only desktop flows behind an explicit
560
+ * confirmation page that hands the original verification URL back after the
561
+ * user acts.
562
+ */
563
+ export function desktopMagicLinkLandingUrl(value) {
564
+ try {
565
+ const verificationUrl = new URL(value);
566
+ const callbackValue = verificationUrl.searchParams.get("callbackURL");
567
+ if (!callbackValue)
568
+ return undefined;
569
+ const callbackUrl = new URL(callbackValue, verificationUrl.origin);
570
+ if (callbackUrl.origin !== verificationUrl.origin)
571
+ return undefined;
572
+ if (!callbackUrl.pathname.endsWith(DESKTOP_MAGIC_LINK_CALLBACK_MARKER)) {
573
+ return undefined;
574
+ }
575
+ const verifyMarkerIndex = verificationUrl.pathname.lastIndexOf(BETTER_AUTH_MAGIC_LINK_VERIFY_MARKER);
576
+ if (verifyMarkerIndex < 0)
577
+ return undefined;
578
+ const landingUrl = new URL(verificationUrl.origin);
579
+ landingUrl.pathname =
580
+ verificationUrl.pathname.slice(0, verifyMarkerIndex) +
581
+ DESKTOP_MAGIC_LINK_LANDING_MARKER;
582
+ for (const key of [
583
+ "token",
584
+ "callbackURL",
585
+ "newUserCallbackURL",
586
+ "errorCallbackURL",
587
+ ]) {
588
+ const queryValue = verificationUrl.searchParams.get(key);
589
+ if (queryValue)
590
+ landingUrl.searchParams.set(key, queryValue);
591
+ }
592
+ return landingUrl.toString();
593
+ }
594
+ catch {
595
+ // coercion-ok: malformed provider URLs keep the original link unchanged.
596
+ return undefined;
597
+ }
598
+ }
552
599
  /**
553
600
  * Replace the only unverified credential account and add Google in one
554
601
  * database transaction. The read in ensureGoogleAuthIdentityWithAdapter is
@@ -1118,9 +1165,10 @@ async function createBetterAuthInstance(config) {
1118
1165
  const magicLinkUrl = appBasePath
1119
1166
  ? url.replace(/(\/\/[^/]+)(\/)/, `$1${appBasePath}$2`)
1120
1167
  : url;
1168
+ const deliveredMagicLinkUrl = desktopMagicLinkLandingUrl(magicLinkUrl) ?? magicLinkUrl;
1121
1169
  const { subject, html, text, appSender } = renderMagicLinkEmail({
1122
1170
  email,
1123
- magicLinkUrl,
1171
+ magicLinkUrl: deliveredMagicLinkUrl,
1124
1172
  });
1125
1173
  await sendEmail({ to: email, subject, html, text, appSender });
1126
1174
  },
@@ -26,8 +26,8 @@ export declare function createRealtimeTokenHandler(): import("h3").EventHandlerW
26
26
  expiresAt?: undefined;
27
27
  ttlSeconds?: undefined;
28
28
  } | {
29
+ error?: undefined;
29
30
  token: string;
30
31
  expiresAt: string;
31
32
  ttlSeconds: number;
32
- error?: undefined;
33
33
  }>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-native/core",
3
- "version": "0.158.3",
3
+ "version": "0.158.4",
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": {