@agent-native/core 0.18.0 → 0.18.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.
@@ -1 +1 @@
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;AAQvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAMlE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAwB5D,OAAO,EAIL,KAAK,oBAAoB,EAC1B,MAAM,qCAAqC,CAAC;AAS7C;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAMD,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mFAAmF;IACnF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAC7D;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB;;;;;;;;OAQG;IACH,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAC;IACnC;;;OA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AAG,EAAE,KAAK,EACV,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,OAAO,CAAC,CAmMlB;AAMD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAEzE"}
@@ -901,6 +901,17 @@ function createAuthGuardFn() {
901
901
  if (p === "/_agent-native/a2a") {
902
902
  return;
903
903
  }
904
+ // MCP protocol endpoint. `mountMCP` runs its own `verifyAuth` (Bearer
905
+ // ACCESS_TOKEN/ACCESS_TOKENS or A2A_SECRET JWT, open in dev) and is the
906
+ // authoritative gate — exactly like A2A above. Without this bypass the
907
+ // guard's blanket 401-for-/_agent-native/* below shadows that check, so
908
+ // an external coding agent (Claude Code / Codex / Cowork) connecting via
909
+ // the stdio proxy or HTTP can never reach it. Exact path only: the MCP
910
+ // handler returns early for `/_agent-native/mcp/*` management subroutes,
911
+ // which keep their normal session auth.
912
+ if (p === "/_agent-native/mcp") {
913
+ return;
914
+ }
904
915
  // Internal processor endpoint for the A2A async-mode fanout. Mirrors the
905
916
  // integration webhook fanout: when `message/send` is called with
906
917
  // `async: true`, the JSON-RPC handler enqueues to a2a_tasks and self-
@@ -1000,8 +1011,8 @@ function createAuthGuardFn() {
1000
1011
  return { error: "Unauthorized" };
1001
1012
  }
1002
1013
  // Local-dev convenience: on the first page GET of a freshly-scaffolded
1003
- // app, transparently create + sign in `dev@local` instead of showing the
1004
- // sign-up form. Gated on NODE_ENV=development AND no real users in the
1014
+ // app, transparently create + sign in `dev@local.test` instead of
1015
+ // showing the sign-up form. Gated on NODE_ENV=development AND no real users in the
1005
1016
  // DB, so production and any app that has ever had a real signup are
1006
1017
  // unaffected. See maybeAutoCreateDevSession for full conditions.
1007
1018
  if (getMethod(event) === "GET") {
@@ -1015,28 +1026,38 @@ function createAuthGuardFn() {
1015
1026
  });
1016
1027
  };
1017
1028
  }
1018
- const AUTO_DEV_ACCOUNT_EMAIL = "dev@local";
1029
+ // `.test` is an RFC 6761 reserved TLD that never resolves, so this stays a
1030
+ // safe local-only address while still passing better-auth's `z.email()`
1031
+ // validator (a bare `dev@local` has no TLD and is rejected as INVALID_EMAIL,
1032
+ // which silently broke the zero-setup auto-sign-in on every fresh dev DB).
1033
+ const AUTO_DEV_ACCOUNT_EMAIL = "dev@local.test";
1019
1034
  const AUTO_DEV_ACCOUNT_PASSWORD = "local-dev-account";
1035
+ // Pre-fix local dev DBs may already contain a `dev@local` user. Treat that
1036
+ // legacy address as the dev account too, so the "any real users?" check
1037
+ // below doesn't mistake the old auto-account for a real signup (which would
1038
+ // permanently disable auto-create) and the post-logout guard still fires.
1039
+ const LEGACY_AUTO_DEV_ACCOUNT_EMAIL = "dev@local";
1020
1040
  /**
1021
1041
  * Local-dev convenience: skip the sign-up wall on first run.
1022
1042
  *
1023
1043
  * When NODE_ENV=development AND the `user` table has no rows for any
1024
- * email other than `dev@local`, transparently sign up (or sign back in
1044
+ * email other than the dev account (`dev@local.test`, or the legacy
1045
+ * `dev@local` on pre-fix DBs), transparently sign up (or sign back in
1025
1046
  * to) the auto-managed dev account and return a 302 to the original URL
1026
1047
  * with a session cookie set. A developer who just ran `pnpm dev` lands
1027
1048
  * in the app immediately instead of being asked to fill in name + email
1028
1049
  * + password to try the framework.
1029
1050
  *
1030
- * Auto-create fires exactly once per local DB: as soon as `dev@local`
1031
- * (or any real user) exists in the `user` table, the helper returns
1032
- * null and the normal login flow takes over. Signing out then leaves
1033
- * the user on the regular sign-in form; without this guard the
1051
+ * Auto-create fires exactly once per local DB: as soon as the dev
1052
+ * account (or any real user) exists in the `user` table, the helper
1053
+ * returns null and the normal login flow takes over. Signing out then
1054
+ * leaves the user on the regular sign-in form; without this guard the
1034
1055
  * post-logout reload would silently re-create the session.
1035
1056
  *
1036
1057
  * The fixed password is intentional: it means a developer who signs
1037
- * out can sign back in with `dev@local` / `local-dev-account` from
1038
- * the regular login form. To get the auto-flow back, drop the user
1039
- * row or wipe the local DB. Set
1058
+ * out can sign back in with `dev@local.test` / `local-dev-account`
1059
+ * from the regular login form. To get the auto-flow back, drop the
1060
+ * user row or wipe the local DB. Set
1040
1061
  * `AGENT_NATIVE_DISABLE_AUTO_DEV_ACCOUNT=1` to opt out entirely
1041
1062
  * (useful for tests that exercise the unauthenticated branch). This
1042
1063
  * is local-only — the helper is gated on NODE_ENV.
@@ -1048,22 +1069,28 @@ async function maybeAutoCreateDevSession(event, redirectTo) {
1048
1069
  return null;
1049
1070
  try {
1050
1071
  const db = getDbExec();
1072
+ // Exclude BOTH the current and the legacy dev-account email so a
1073
+ // pre-fix local DB that still holds a `dev@local` row isn't treated
1074
+ // as having a "real user" (which would permanently disable
1075
+ // auto-create on that DB).
1051
1076
  const { rows: realUsers } = await db.execute({
1052
- sql: 'SELECT 1 FROM "user" WHERE email != ? LIMIT 1',
1053
- args: [AUTO_DEV_ACCOUNT_EMAIL],
1077
+ sql: 'SELECT 1 FROM "user" WHERE email NOT IN (?, ?) LIMIT 1',
1078
+ args: [AUTO_DEV_ACCOUNT_EMAIL, LEGACY_AUTO_DEV_ACCOUNT_EMAIL],
1054
1079
  });
1055
1080
  if (realUsers.length > 0)
1056
1081
  return null;
1057
- // If `dev@local` already exists, this is not a freshly-scaffolded
1082
+ // If the dev account already exists, this is not a freshly-scaffolded
1058
1083
  // app — the user has been through the auto-create flow at least
1059
1084
  // once. Skip auto-create so signing out actually works: without
1060
1085
  // this guard, the post-logout reload immediately re-creates the
1061
- // session and the user is stuck in dev@local forever (or has to
1062
- // set AGENT_NATIVE_DISABLE_AUTO_DEV_ACCOUNT=1). To get the demo
1063
- // experience back, drop the row or wipe the local DB.
1086
+ // session and the user is stuck in the dev account forever (or has
1087
+ // to set AGENT_NATIVE_DISABLE_AUTO_DEV_ACCOUNT=1). To get the demo
1088
+ // experience back, drop the row or wipe the local DB. The legacy
1089
+ // `dev@local` address is matched too so pre-fix DBs still suppress
1090
+ // re-create after logout.
1064
1091
  const { rows: devUsers } = await db.execute({
1065
- sql: 'SELECT 1 FROM "user" WHERE email = ? LIMIT 1',
1066
- args: [AUTO_DEV_ACCOUNT_EMAIL],
1092
+ sql: 'SELECT 1 FROM "user" WHERE email IN (?, ?) LIMIT 1',
1093
+ args: [AUTO_DEV_ACCOUNT_EMAIL, LEGACY_AUTO_DEV_ACCOUNT_EMAIL],
1067
1094
  });
1068
1095
  if (devUsers.length > 0)
1069
1096
  return null;