@agentuity/core 2.0.0 → 2.0.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.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Authentication service types.
3
+ *
4
+ * @module services/auth
5
+ */
6
+ export type { AuthUser, AuthSession, AuthContext, AuthOrgContext, AuthApiKeyPermissions, AuthApiKeyContext, AuthMethod, AgentuityAuth, AuthOrgHelpers, AuthApiKeyHelpers, AuthInterface, } from './types';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/auth/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EACX,QAAQ,EACR,WAAW,EACX,WAAW,EACX,cAAc,EACd,qBAAqB,EACrB,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,aAAa,GACb,MAAM,SAAS,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Authentication service types.
3
+ *
4
+ * @module services/auth
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/auth/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Core authentication types for Agentuity.
3
+ *
4
+ * These types are defined in @agentuity/core to avoid circular dependencies
5
+ * and allow packages like @agentuity/runtime to use auth types without
6
+ * pulling in heavy dependencies like drizzle-orm.
7
+ *
8
+ * @module services/auth/types
9
+ */
10
+ /**
11
+ * Canonical authenticated user type for Agentuity Auth.
12
+ *
13
+ * Common fields include:
14
+ * - `id` – Stable user identifier
15
+ * - `email` – Primary email address
16
+ * - `name` – Display name
17
+ * - `image` – Avatar URL (if configured)
18
+ * - `createdAt` / `updatedAt` – Timestamps
19
+ */
20
+ export interface AuthUser {
21
+ id: string;
22
+ email: string;
23
+ name?: string | null;
24
+ image?: string | null;
25
+ createdAt?: Date | string;
26
+ updatedAt?: Date | string;
27
+ }
28
+ /**
29
+ * Auth session type with organization plugin fields.
30
+ */
31
+ export interface AuthSession {
32
+ id: string;
33
+ userId: string;
34
+ expiresAt: Date | string;
35
+ /** Active organization ID from the organization plugin */
36
+ activeOrganizationId?: string;
37
+ ipAddress?: string | null;
38
+ userAgent?: string | null;
39
+ createdAt?: Date | string;
40
+ updatedAt?: Date | string;
41
+ }
42
+ /**
43
+ * Auth context containing user, session, and org data.
44
+ * This is the full auth context available on AgentContext.auth and c.var.auth.
45
+ * Session may be null for API key authentication.
46
+ */
47
+ export interface AuthContext<TUser = AuthUser, TSession = AuthSession | null> {
48
+ user: TUser;
49
+ session: TSession;
50
+ org: AuthOrgContext | null;
51
+ }
52
+ /**
53
+ * Organization context from the organization plugin.
54
+ */
55
+ export interface AuthOrgContext {
56
+ /** Organization ID */
57
+ id: string;
58
+ /** Organization slug (URL-friendly identifier) */
59
+ slug?: string | null;
60
+ /** Organization display name */
61
+ name?: string | null;
62
+ /** Member's role in this organization (e.g., 'owner', 'admin', 'member') */
63
+ role?: string | null;
64
+ /** Member ID for this user in this organization */
65
+ memberId?: string | null;
66
+ /** Organization metadata (if enabled) */
67
+ metadata?: unknown;
68
+ }
69
+ /**
70
+ * API key permissions format.
71
+ * Maps resource names to arrays of allowed actions.
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * const permissions: AuthApiKeyPermissions = {
76
+ * project: ['read', 'write'],
77
+ * user: ['read'],
78
+ * admin: ['*'], // wildcard - all actions
79
+ * };
80
+ * ```
81
+ */
82
+ export interface AuthApiKeyPermissions {
83
+ [key: string]: string[];
84
+ }
85
+ /**
86
+ * API key context when request is authenticated via API key.
87
+ */
88
+ export interface AuthApiKeyContext {
89
+ /** API key ID */
90
+ id: string;
91
+ /** Display name of the API key */
92
+ name?: string | null;
93
+ /** Permissions associated with this API key */
94
+ permissions: AuthApiKeyPermissions;
95
+ /** User ID the API key belongs to */
96
+ userId?: string | null;
97
+ }
98
+ /**
99
+ * Authentication method used for the current request.
100
+ */
101
+ export type AuthMethod = 'session' | 'api-key' | 'bearer';
102
+ /**
103
+ * Generic authentication interface exposed on Hono context.
104
+ *
105
+ * This type is intentionally provider-agnostic.
106
+ *
107
+ * @typeParam TUser - Domain user type (defaults to unknown for flexibility).
108
+ * @typeParam TRaw - Underlying auth context (defaults to unknown for flexibility).
109
+ */
110
+ export interface AgentuityAuth<TUser = unknown, TRaw = unknown> {
111
+ /** Get the authenticated user, throws if not authenticated */
112
+ getUser(): Promise<TUser>;
113
+ /** Get the raw JWT token */
114
+ getToken(): Promise<string | null>;
115
+ /** Raw provider-specific auth object or auth context */
116
+ raw: TRaw;
117
+ }
118
+ /**
119
+ * Organization helpers available on the auth context.
120
+ */
121
+ export interface AuthOrgHelpers {
122
+ /** Active organization context if available, null otherwise */
123
+ org: AuthOrgContext | null;
124
+ /** Returns active org or null (never throws) */
125
+ getOrg(): Promise<AuthOrgContext | null>;
126
+ /** Convenience accessor for the member's role on the active org */
127
+ getOrgRole(): Promise<string | null>;
128
+ /** True if the current member's role is one of the provided roles */
129
+ hasOrgRole(...roles: string[]): Promise<boolean>;
130
+ }
131
+ /**
132
+ * API key helpers available on the auth context.
133
+ */
134
+ export interface AuthApiKeyHelpers {
135
+ /** How this request was authenticated */
136
+ authMethod: AuthMethod;
137
+ /** API key context when request is authenticated via API key, null otherwise */
138
+ apiKey: AuthApiKeyContext | null;
139
+ /**
140
+ * Check if the API key has the required permissions.
141
+ * All specified actions must be present for the resource.
142
+ * Supports '*' wildcard which matches any action.
143
+ *
144
+ * @param resource - The resource to check (e.g., 'project', 'user')
145
+ * @param actions - Actions required (e.g., 'read', 'write')
146
+ * @returns true if all actions are permitted, false otherwise
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * // Check for specific permission
151
+ * if (c.var.auth.hasPermission('project', 'write')) { ... }
152
+ *
153
+ * // Check for multiple permissions (all required)
154
+ * if (c.var.auth.hasPermission('project', 'read', 'write')) { ... }
155
+ * ```
156
+ */
157
+ hasPermission(resource: string, ...actions: string[]): boolean;
158
+ }
159
+ /**
160
+ * Full authentication interface available on `c.var.auth` and `ctx.auth`.
161
+ *
162
+ * This is the primary interface you'll use to access authentication data
163
+ * in your route handlers and agents. It provides:
164
+ *
165
+ * - User data via `getUser()`
166
+ * - Organization helpers via `getOrg()`, `getOrgRole()`, `hasOrgRole()`
167
+ * - API key helpers via `apiKey`, `hasPermission()`
168
+ * - Token access via `getToken()`
169
+ *
170
+ * @example Route handler
171
+ * ```typescript
172
+ * app.get('/api/profile', async (c) => {
173
+ * const user = await c.var.auth.getUser();
174
+ * const org = await c.var.auth.getOrg();
175
+ * return c.json({ user, org });
176
+ * });
177
+ * ```
178
+ *
179
+ * @example Agent handler
180
+ * ```typescript
181
+ * handler: async (ctx, input) => {
182
+ * if (!ctx.auth) return { error: 'Unauthorized' };
183
+ * const user = await ctx.auth.getUser();
184
+ * return { message: `Hello, ${user.email}!` };
185
+ * }
186
+ * ```
187
+ *
188
+ * @typeParam TUser - User type (extends AuthUser, defaults to AuthUser)
189
+ */
190
+ export interface AuthInterface<TUser extends AuthUser = AuthUser> extends AgentuityAuth<TUser, AuthContext<TUser>>, AuthOrgHelpers, AuthApiKeyHelpers {
191
+ }
192
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/services/auth/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH;;;;;;;;;GASG;AACH,MAAM,WAAW,QAAQ;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAC1B,SAAS,CAAC,E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,KAAK,SAAS,QAAQ,GAAG,QAAQ,CAC/D,SAAQ,aAAa,CAAC,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAC/C,cAAc,EACd,iBAAiB;CAAG"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Core authentication types for Agentuity.
3
+ *
4
+ * These types are defined in @agentuity/core to avoid circular dependencies
5
+ * and allow packages like @agentuity/runtime to use auth types without
6
+ * pulling in heavy dependencies like drizzle-orm.
7
+ *
8
+ * @module services/auth/types
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/services/auth/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -1,4 +1,5 @@
1
1
  export * from './adapter.ts';
2
+ export * from './auth/index.ts';
2
3
  export * from './email/index.ts';
3
4
  export * from './exception.ts';
4
5
  export * from './keyvalue/index.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAElC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AAEzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,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AAE,YAAY,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export * from "./adapter.js";
2
+ export * from "./auth/index.js";
2
3
  export * from "./email/index.js";
3
4
  export * from "./exception.js";
4
5
  export * from "./keyvalue/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAElC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AAEzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AAEnC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAElC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AAEzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AAEnC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentuity/core",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "license": "Apache-2.0",
5
5
  "author": "Agentuity employees and contributors",
6
6
  "type": "module",
@@ -89,7 +89,7 @@
89
89
  "zod": "^4.3.5"
90
90
  },
91
91
  "devDependencies": {
92
- "@agentuity/test-utils": "2.0.0",
92
+ "@agentuity/test-utils": "2.0.1",
93
93
  "@types/bun": "latest",
94
94
  "bun-types": "latest",
95
95
  "esbuild": "^0.25.0",
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Authentication service types.
3
+ *
4
+ * @module services/auth
5
+ */
6
+
7
+ export type {
8
+ AuthUser,
9
+ AuthSession,
10
+ AuthContext,
11
+ AuthOrgContext,
12
+ AuthApiKeyPermissions,
13
+ AuthApiKeyContext,
14
+ AuthMethod,
15
+ AgentuityAuth,
16
+ AuthOrgHelpers,
17
+ AuthApiKeyHelpers,
18
+ AuthInterface,
19
+ } from './types';
@@ -0,0 +1,223 @@
1
+ /**
2
+ * Core authentication types for Agentuity.
3
+ *
4
+ * These types are defined in @agentuity/core to avoid circular dependencies
5
+ * and allow packages like @agentuity/runtime to use auth types without
6
+ * pulling in heavy dependencies like drizzle-orm.
7
+ *
8
+ * @module services/auth/types
9
+ */
10
+
11
+ // =============================================================================
12
+ // Canonical User/Session Types
13
+ // =============================================================================
14
+
15
+ /**
16
+ * Canonical authenticated user type for Agentuity Auth.
17
+ *
18
+ * Common fields include:
19
+ * - `id` – Stable user identifier
20
+ * - `email` – Primary email address
21
+ * - `name` – Display name
22
+ * - `image` – Avatar URL (if configured)
23
+ * - `createdAt` / `updatedAt` – Timestamps
24
+ */
25
+ export interface AuthUser {
26
+ id: string;
27
+ email: string;
28
+ name?: string | null;
29
+ image?: string | null;
30
+ createdAt?: Date | string;
31
+ updatedAt?: Date | string;
32
+ }
33
+
34
+ /**
35
+ * Auth session type with organization plugin fields.
36
+ */
37
+ export interface AuthSession {
38
+ id: string;
39
+ userId: string;
40
+ expiresAt: Date | string;
41
+ /** Active organization ID from the organization plugin */
42
+ activeOrganizationId?: string;
43
+ ipAddress?: string | null;
44
+ userAgent?: string | null;
45
+ createdAt?: Date | string;
46
+ updatedAt?: Date | string;
47
+ }
48
+
49
+ /**
50
+ * Auth context containing user, session, and org data.
51
+ * This is the full auth context available on AgentContext.auth and c.var.auth.
52
+ * Session may be null for API key authentication.
53
+ */
54
+ export interface AuthContext<TUser = AuthUser, TSession = AuthSession | null> {
55
+ user: TUser;
56
+ session: TSession;
57
+ org: AuthOrgContext | null;
58
+ }
59
+
60
+ /**
61
+ * Organization context from the organization plugin.
62
+ */
63
+ export interface AuthOrgContext {
64
+ /** Organization ID */
65
+ id: string;
66
+ /** Organization slug (URL-friendly identifier) */
67
+ slug?: string | null;
68
+ /** Organization display name */
69
+ name?: string | null;
70
+ /** Member's role in this organization (e.g., 'owner', 'admin', 'member') */
71
+ role?: string | null;
72
+ /** Member ID for this user in this organization */
73
+ memberId?: string | null;
74
+ /** Organization metadata (if enabled) */
75
+ metadata?: unknown;
76
+ }
77
+
78
+ // =============================================================================
79
+ // API Key Types
80
+ // =============================================================================
81
+
82
+ /**
83
+ * API key permissions format.
84
+ * Maps resource names to arrays of allowed actions.
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const permissions: AuthApiKeyPermissions = {
89
+ * project: ['read', 'write'],
90
+ * user: ['read'],
91
+ * admin: ['*'], // wildcard - all actions
92
+ * };
93
+ * ```
94
+ */
95
+ export interface AuthApiKeyPermissions {
96
+ [key: string]: string[];
97
+ }
98
+
99
+ /**
100
+ * API key context when request is authenticated via API key.
101
+ */
102
+ export interface AuthApiKeyContext {
103
+ /** API key ID */
104
+ id: string;
105
+ /** Display name of the API key */
106
+ name?: string | null;
107
+ /** Permissions associated with this API key */
108
+ permissions: AuthApiKeyPermissions;
109
+ /** User ID the API key belongs to */
110
+ userId?: string | null;
111
+ }
112
+
113
+ /**
114
+ * Authentication method used for the current request.
115
+ */
116
+ export type AuthMethod = 'session' | 'api-key' | 'bearer';
117
+
118
+ // =============================================================================
119
+ // Auth Interface
120
+ // =============================================================================
121
+
122
+ /**
123
+ * Generic authentication interface exposed on Hono context.
124
+ *
125
+ * This type is intentionally provider-agnostic.
126
+ *
127
+ * @typeParam TUser - Domain user type (defaults to unknown for flexibility).
128
+ * @typeParam TRaw - Underlying auth context (defaults to unknown for flexibility).
129
+ */
130
+ export interface AgentuityAuth<TUser = unknown, TRaw = unknown> {
131
+ /** Get the authenticated user, throws if not authenticated */
132
+ getUser(): Promise<TUser>;
133
+
134
+ /** Get the raw JWT token */
135
+ getToken(): Promise<string | null>;
136
+
137
+ /** Raw provider-specific auth object or auth context */
138
+ raw: TRaw;
139
+ }
140
+
141
+ /**
142
+ * Organization helpers available on the auth context.
143
+ */
144
+ export interface AuthOrgHelpers {
145
+ /** Active organization context if available, null otherwise */
146
+ org: AuthOrgContext | null;
147
+
148
+ /** Returns active org or null (never throws) */
149
+ getOrg(): Promise<AuthOrgContext | null>;
150
+
151
+ /** Convenience accessor for the member's role on the active org */
152
+ getOrgRole(): Promise<string | null>;
153
+
154
+ /** True if the current member's role is one of the provided roles */
155
+ hasOrgRole(...roles: string[]): Promise<boolean>;
156
+ }
157
+
158
+ /**
159
+ * API key helpers available on the auth context.
160
+ */
161
+ export interface AuthApiKeyHelpers {
162
+ /** How this request was authenticated */
163
+ authMethod: AuthMethod;
164
+
165
+ /** API key context when request is authenticated via API key, null otherwise */
166
+ apiKey: AuthApiKeyContext | null;
167
+
168
+ /**
169
+ * Check if the API key has the required permissions.
170
+ * All specified actions must be present for the resource.
171
+ * Supports '*' wildcard which matches any action.
172
+ *
173
+ * @param resource - The resource to check (e.g., 'project', 'user')
174
+ * @param actions - Actions required (e.g., 'read', 'write')
175
+ * @returns true if all actions are permitted, false otherwise
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * // Check for specific permission
180
+ * if (c.var.auth.hasPermission('project', 'write')) { ... }
181
+ *
182
+ * // Check for multiple permissions (all required)
183
+ * if (c.var.auth.hasPermission('project', 'read', 'write')) { ... }
184
+ * ```
185
+ */
186
+ hasPermission(resource: string, ...actions: string[]): boolean;
187
+ }
188
+
189
+ /**
190
+ * Full authentication interface available on `c.var.auth` and `ctx.auth`.
191
+ *
192
+ * This is the primary interface you'll use to access authentication data
193
+ * in your route handlers and agents. It provides:
194
+ *
195
+ * - User data via `getUser()`
196
+ * - Organization helpers via `getOrg()`, `getOrgRole()`, `hasOrgRole()`
197
+ * - API key helpers via `apiKey`, `hasPermission()`
198
+ * - Token access via `getToken()`
199
+ *
200
+ * @example Route handler
201
+ * ```typescript
202
+ * app.get('/api/profile', async (c) => {
203
+ * const user = await c.var.auth.getUser();
204
+ * const org = await c.var.auth.getOrg();
205
+ * return c.json({ user, org });
206
+ * });
207
+ * ```
208
+ *
209
+ * @example Agent handler
210
+ * ```typescript
211
+ * handler: async (ctx, input) => {
212
+ * if (!ctx.auth) return { error: 'Unauthorized' };
213
+ * const user = await ctx.auth.getUser();
214
+ * return { message: `Hello, ${user.email}!` };
215
+ * }
216
+ * ```
217
+ *
218
+ * @typeParam TUser - User type (extends AuthUser, defaults to AuthUser)
219
+ */
220
+ export interface AuthInterface<TUser extends AuthUser = AuthUser>
221
+ extends AgentuityAuth<TUser, AuthContext<TUser>>,
222
+ AuthOrgHelpers,
223
+ AuthApiKeyHelpers {}
@@ -1,4 +1,5 @@
1
1
  export * from './adapter.ts';
2
+ export * from './auth/index.ts';
2
3
  export * from './email/index.ts';
3
4
  export * from './exception.ts';
4
5
  export * from './keyvalue/index.ts';