@agent-native/core 0.17.2 → 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.
- package/dist/action.d.ts +27 -0
- package/dist/action.d.ts.map +1 -1
- package/dist/action.js +2 -0
- package/dist/action.js.map +1 -1
- package/dist/agent/production-agent.d.ts +4 -0
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/cli/index.js +16 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/mcp.d.ts +16 -0
- package/dist/cli/mcp.d.ts.map +1 -0
- package/dist/cli/mcp.js +583 -0
- package/dist/cli/mcp.js.map +1 -0
- package/dist/db/client.d.ts +17 -14
- package/dist/db/client.d.ts.map +1 -1
- package/dist/db/client.js +31 -27
- package/dist/db/client.js.map +1 -1
- package/dist/db/create-get-db.js +2 -2
- package/dist/db/create-get-db.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/build-server.d.ts +152 -0
- package/dist/mcp/build-server.d.ts.map +1 -0
- package/dist/mcp/build-server.js +349 -0
- package/dist/mcp/build-server.js.map +1 -0
- package/dist/mcp/builtin-tools.d.ts +39 -0
- package/dist/mcp/builtin-tools.d.ts.map +1 -0
- package/dist/mcp/builtin-tools.js +401 -0
- package/dist/mcp/builtin-tools.js.map +1 -0
- package/dist/mcp/index.d.ts +7 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +8 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/server.d.ts +3 -13
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +44 -179
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/stdio.d.ts +44 -0
- package/dist/mcp/stdio.d.ts.map +1 -0
- package/dist/mcp/stdio.js +209 -0
- package/dist/mcp/stdio.js.map +1 -0
- package/dist/mcp/workspace-resolve.d.ts +68 -0
- package/dist/mcp/workspace-resolve.d.ts.map +1 -0
- package/dist/mcp/workspace-resolve.js +205 -0
- package/dist/mcp/workspace-resolve.js.map +1 -0
- package/dist/server/action-discovery.d.ts.map +1 -1
- package/dist/server/action-discovery.js +3 -0
- package/dist/server/action-discovery.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +1 -0
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/auth.d.ts +9 -0
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +71 -19
- package/dist/server/auth.js.map +1 -1
- package/dist/server/better-auth-instance.d.ts.map +1 -1
- package/dist/server/better-auth-instance.js +15 -10
- package/dist/server/better-auth-instance.js.map +1 -1
- package/dist/server/core-routes-plugin.d.ts +5 -0
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +9 -0
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/server/deep-link.d.ts +55 -0
- package/dist/server/deep-link.d.ts.map +1 -0
- package/dist/server/deep-link.js +69 -0
- package/dist/server/deep-link.js.map +1 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/open-route.d.ts +12 -0
- package/dist/server/open-route.d.ts.map +1 -0
- package/dist/server/open-route.js +159 -0
- package/dist/server/open-route.js.map +1 -0
- package/dist/server/request-context.d.ts +8 -0
- package/dist/server/request-context.d.ts.map +1 -1
- package/dist/server/request-context.js.map +1 -1
- package/docs/content/external-agents.md +177 -0
- package/package.json +1 -1
package/dist/server/auth.d.ts
CHANGED
|
@@ -169,6 +169,15 @@ export declare function isDevEnvironment(): boolean;
|
|
|
169
169
|
* Exported for unit tests.
|
|
170
170
|
*/
|
|
171
171
|
export declare function safeReturnPath(raw: string | null | undefined): string;
|
|
172
|
+
/**
|
|
173
|
+
* Return the configured login HTML for this request, or `null` when no auth
|
|
174
|
+
* guard is installed. Used by the `/_agent-native/open` deep-link route to
|
|
175
|
+
* serve the same sign-in form the auth guard would — at the original deep
|
|
176
|
+
* link URL — so the login form's `window.location.replace(href)` success
|
|
177
|
+
* handler reloads the same URL and the (now authenticated) open route
|
|
178
|
+
* proceeds. Mirrors the rawPath/getLoginHtml resolution in the auth guard.
|
|
179
|
+
*/
|
|
180
|
+
export declare function getConfiguredLoginHtml(event: H3Event): string | null;
|
|
172
181
|
/**
|
|
173
182
|
* Create a new session in the legacy sessions table.
|
|
174
183
|
* Used by google-oauth.ts for mobile deep linking.
|
|
@@ -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;;;OA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293
|
return "/";
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* Return the configured login HTML for this request, or `null` when no auth
|
|
298
|
+
* guard is installed. Used by the `/_agent-native/open` deep-link route to
|
|
299
|
+
* serve the same sign-in form the auth guard would — at the original deep
|
|
300
|
+
* link URL — so the login form's `window.location.replace(href)` success
|
|
301
|
+
* handler reloads the same URL and the (now authenticated) open route
|
|
302
|
+
* proceeds. Mirrors the rawPath/getLoginHtml resolution in the auth guard.
|
|
303
|
+
*/
|
|
304
|
+
export function getConfiguredLoginHtml(event) {
|
|
305
|
+
const config = _authGuardConfig;
|
|
306
|
+
if (!config)
|
|
307
|
+
return null;
|
|
308
|
+
const url = event.node?.req?.url ?? event.path ?? "/";
|
|
309
|
+
const queryStart = url.indexOf("?");
|
|
310
|
+
const rawPath = queryStart >= 0 ? url.slice(0, queryStart) : url;
|
|
311
|
+
return config.getLoginHtml?.(event, rawPath) ?? config.loginHtml ?? null;
|
|
312
|
+
}
|
|
296
313
|
/**
|
|
297
314
|
* Read the desktop-SSO broker file, but only if the request is plausibly
|
|
298
315
|
* from the Electron desktop app *and* coming from the local machine.
|
|
@@ -851,6 +868,14 @@ function createAuthGuardFn() {
|
|
|
851
868
|
p === "/_agent-native/google/add-account/callback") {
|
|
852
869
|
return;
|
|
853
870
|
}
|
|
871
|
+
// The deep-link route resolves the *browser* session itself and serves
|
|
872
|
+
// the sign-in form inline when unauthenticated (so the post-login reload
|
|
873
|
+
// returns to the same deep link). It must bypass the guard's blanket
|
|
874
|
+
// 401-for-/_agent-native/* so an external-agent "Open in … →" link
|
|
875
|
+
// clicked in any browser/webview lands correctly.
|
|
876
|
+
if (p === "/_agent-native/open") {
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
854
879
|
// Integration webhook endpoints verify authenticity via platform-specific
|
|
855
880
|
// signature verification (Slack HMAC, Telegram token, etc.), not sessions.
|
|
856
881
|
if (/^\/_agent-native\/integrations\/[^/]+\/webhook$/.test(p)) {
|
|
@@ -876,6 +901,17 @@ function createAuthGuardFn() {
|
|
|
876
901
|
if (p === "/_agent-native/a2a") {
|
|
877
902
|
return;
|
|
878
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
|
+
}
|
|
879
915
|
// Internal processor endpoint for the A2A async-mode fanout. Mirrors the
|
|
880
916
|
// integration webhook fanout: when `message/send` is called with
|
|
881
917
|
// `async: true`, the JSON-RPC handler enqueues to a2a_tasks and self-
|
|
@@ -975,8 +1011,8 @@ function createAuthGuardFn() {
|
|
|
975
1011
|
return { error: "Unauthorized" };
|
|
976
1012
|
}
|
|
977
1013
|
// Local-dev convenience: on the first page GET of a freshly-scaffolded
|
|
978
|
-
// app, transparently create + sign in `dev@local` instead of
|
|
979
|
-
// 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
|
|
980
1016
|
// DB, so production and any app that has ever had a real signup are
|
|
981
1017
|
// unaffected. See maybeAutoCreateDevSession for full conditions.
|
|
982
1018
|
if (getMethod(event) === "GET") {
|
|
@@ -990,28 +1026,38 @@ function createAuthGuardFn() {
|
|
|
990
1026
|
});
|
|
991
1027
|
};
|
|
992
1028
|
}
|
|
993
|
-
|
|
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";
|
|
994
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";
|
|
995
1040
|
/**
|
|
996
1041
|
* Local-dev convenience: skip the sign-up wall on first run.
|
|
997
1042
|
*
|
|
998
1043
|
* When NODE_ENV=development AND the `user` table has no rows for any
|
|
999
|
-
* email other than `dev@local`,
|
|
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
|
|
1000
1046
|
* to) the auto-managed dev account and return a 302 to the original URL
|
|
1001
1047
|
* with a session cookie set. A developer who just ran `pnpm dev` lands
|
|
1002
1048
|
* in the app immediately instead of being asked to fill in name + email
|
|
1003
1049
|
* + password to try the framework.
|
|
1004
1050
|
*
|
|
1005
|
-
* Auto-create fires exactly once per local DB: as soon as
|
|
1006
|
-
* (or any real user) exists in the `user` table, the helper
|
|
1007
|
-
* null and the normal login flow takes over. Signing out then
|
|
1008
|
-
* 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
|
|
1009
1055
|
* post-logout reload would silently re-create the session.
|
|
1010
1056
|
*
|
|
1011
1057
|
* The fixed password is intentional: it means a developer who signs
|
|
1012
|
-
* out can sign back in with `dev@local` / `local-dev-account`
|
|
1013
|
-
* the regular login form. To get the auto-flow back, drop the
|
|
1014
|
-
* 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
|
|
1015
1061
|
* `AGENT_NATIVE_DISABLE_AUTO_DEV_ACCOUNT=1` to opt out entirely
|
|
1016
1062
|
* (useful for tests that exercise the unauthenticated branch). This
|
|
1017
1063
|
* is local-only — the helper is gated on NODE_ENV.
|
|
@@ -1023,22 +1069,28 @@ async function maybeAutoCreateDevSession(event, redirectTo) {
|
|
|
1023
1069
|
return null;
|
|
1024
1070
|
try {
|
|
1025
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).
|
|
1026
1076
|
const { rows: realUsers } = await db.execute({
|
|
1027
|
-
sql: 'SELECT 1 FROM "user" WHERE email
|
|
1028
|
-
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],
|
|
1029
1079
|
});
|
|
1030
1080
|
if (realUsers.length > 0)
|
|
1031
1081
|
return null;
|
|
1032
|
-
// If
|
|
1082
|
+
// If the dev account already exists, this is not a freshly-scaffolded
|
|
1033
1083
|
// app — the user has been through the auto-create flow at least
|
|
1034
1084
|
// once. Skip auto-create so signing out actually works: without
|
|
1035
1085
|
// this guard, the post-logout reload immediately re-creates the
|
|
1036
|
-
// session and the user is stuck in dev
|
|
1037
|
-
// set AGENT_NATIVE_DISABLE_AUTO_DEV_ACCOUNT=1). To get the demo
|
|
1038
|
-
// 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.
|
|
1039
1091
|
const { rows: devUsers } = await db.execute({
|
|
1040
|
-
sql: 'SELECT 1 FROM "user" WHERE email
|
|
1041
|
-
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],
|
|
1042
1094
|
});
|
|
1043
1095
|
if (devUsers.length > 0)
|
|
1044
1096
|
return null;
|