@adonis-agora/agent 0.7.1 → 0.8.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @adonis-agora/agent
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#23](https://github.com/DavideCarvalho/adonis-agent/pull/23) [`19c9ffd`](https://github.com/DavideCarvalho/adonis-agent/commit/19c9ffd9c285c7cab4e487c8bda73f7ce668be9e) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Add `authzActorResolver` (exported from `@adonis-agora/agent/authz`) — resolve the agent `Actor` from the Agora context populated by authkit (`userRef`, `tenantId`) plus authz `effectiveRoles` (the union global ∪ app ∪ store). Structural, zero hard dependency; authkit+authz apps can drop hand-written actor resolvers. Fail-closed: no identity in context → 401.
8
+
3
9
  ## 0.7.1
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Structural, dependency-free reader for the Agora runtime context — mirrors
3
+ * `@adonis-agora/authz`'s `agora/context.ts`. The Agora context library publishes a READ accessor
4
+ * on the well-known symbol slot. We never import that package; when the slot is absent (context not
5
+ * installed) the reader degrades to `undefined` and the caller fails closed.
6
+ */
7
+ /** The symbol slot the Agora context library writes its read accessor into. */
8
+ export declare const AGORA_CONTEXT_ACCESSOR: unique symbol;
9
+ /**
10
+ * The slice of the context accessor this package reads. `userRef` and `tenantId` are direct
11
+ * accessor fields (authkit writes them via the `set` slot); we never read `globalRoles` here —
12
+ * authz's `effectiveRoles` does that internally.
13
+ */
14
+ export interface AgoraContextAccessor {
15
+ tenantId?: string;
16
+ userRef?: {
17
+ type?: string;
18
+ id?: string | number;
19
+ };
20
+ get?: () => unknown;
21
+ }
22
+ /** Read the active Agora context accessor from the global slot, if present. */
23
+ export declare function readContextAccessor(): AgoraContextAccessor | undefined;
24
+ //# sourceMappingURL=agora-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agora-context.d.ts","sourceRoot":"","sources":["../../../src/authz/agora-context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,eAAwC,CAAC;AAE5E;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAClD,GAAG,CAAC,EAAE,MAAM,OAAO,CAAC;CACrB;AAED,+EAA+E;AAC/E,wBAAgB,mBAAmB,IAAI,oBAAoB,GAAG,SAAS,CAItE"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Structural, dependency-free reader for the Agora runtime context — mirrors
3
+ * `@adonis-agora/authz`'s `agora/context.ts`. The Agora context library publishes a READ accessor
4
+ * on the well-known symbol slot. We never import that package; when the slot is absent (context not
5
+ * installed) the reader degrades to `undefined` and the caller fails closed.
6
+ */
7
+ /** The symbol slot the Agora context library writes its read accessor into. */
8
+ export const AGORA_CONTEXT_ACCESSOR = Symbol.for('@agora/context:accessor');
9
+ /** Read the active Agora context accessor from the global slot, if present. */
10
+ export function readContextAccessor() {
11
+ const slot = globalThis[AGORA_CONTEXT_ACCESSOR];
12
+ if (slot == null || typeof slot !== 'object')
13
+ return undefined;
14
+ return slot;
15
+ }
16
+ //# sourceMappingURL=agora-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agora-context.js","sourceRoot":"","sources":["../../../src/authz/agora-context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAa5E,+EAA+E;AAC/E,MAAM,UAAU,mBAAmB;IACjC,MAAM,IAAI,GAAI,UAAsC,CAAC,sBAAsB,CAAC,CAAC;IAC7E,IAAI,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAC/D,OAAO,IAA4B,CAAC;AACtC,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { ActorResolver } from '../spi/actor-resolver.js';
2
+ import type { Actor } from '../types.js';
3
+ import type { AuthzTenantScope } from './authz-tool-authorizer.js';
4
+ /**
5
+ * The structural slice of `@adonis-agora/authz`'s `AuthzService` this resolver needs: the user's
6
+ * effective roles (authz's union of global (context) ∪ app (`resolveRoles`) ∪ store (DB)). Typed
7
+ * structurally so `@adonis-agora/authz` stays an OPTIONAL lazy peer — zero import of the package.
8
+ */
9
+ export interface AuthzRolesSourceLike {
10
+ effectiveRoles(user: unknown, scope?: AuthzTenantScope): Promise<string[]>;
11
+ }
12
+ /** Options for {@link AuthzActorResolver} / {@link authzActorResolver}. */
13
+ export interface AuthzActorResolverConfig {
14
+ /** The `@adonis-agora/authz` `AuthzService` (or any structural match) the resolver reads roles from. */
15
+ authz: AuthzRolesSourceLike;
16
+ }
17
+ /**
18
+ * An {@link ActorResolver} that reads the caller from the Agora context authkit populates
19
+ * (`userRef`, `tenantId`) and takes the caller's roles from authz (`effectiveRoles`). It ignores
20
+ * the transport `req` and reads the active Agora context store, so it needs no `ctx.auth` and is
21
+ * framework-agnostic.
22
+ *
23
+ * Security posture — FAIL-CLOSED: no `userRef.id` in context → throws (the provider replies 401).
24
+ * An identity is never fabricated. The context `userRef` is passed straight to `effectiveRoles`;
25
+ * authz reads its `.id`/`.type` and re-reads `globalRoles` from the same context, so global roles
26
+ * (e.g. `ADMIN`) land in the result with no extra wiring.
27
+ */
28
+ export declare class AuthzActorResolver implements ActorResolver {
29
+ #private;
30
+ constructor(config: AuthzActorResolverConfig);
31
+ resolve(_req: unknown): Promise<Actor>;
32
+ }
33
+ /** Factory for {@link AuthzActorResolver}. */
34
+ export declare function authzActorResolver(config: AuthzActorResolverConfig): ActorResolver;
35
+ //# sourceMappingURL=authz-actor-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authz-actor-resolver.d.ts","sourceRoot":"","sources":["../../../src/authz/authz-actor-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CAC5E;AAED,2EAA2E;AAC3E,MAAM,WAAW,wBAAwB;IACvC,wGAAwG;IACxG,KAAK,EAAE,oBAAoB,CAAC;CAC7B;AAED;;;;;;;;;;GAUG;AACH,qBAAa,kBAAmB,YAAW,aAAa;;gBAG1C,MAAM,EAAE,wBAAwB;IAItC,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC;CAsB7C;AAED,8CAA8C;AAC9C,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,aAAa,CAElF"}
@@ -0,0 +1,41 @@
1
+ import { readContextAccessor } from './agora-context.js';
2
+ /**
3
+ * An {@link ActorResolver} that reads the caller from the Agora context authkit populates
4
+ * (`userRef`, `tenantId`) and takes the caller's roles from authz (`effectiveRoles`). It ignores
5
+ * the transport `req` and reads the active Agora context store, so it needs no `ctx.auth` and is
6
+ * framework-agnostic.
7
+ *
8
+ * Security posture — FAIL-CLOSED: no `userRef.id` in context → throws (the provider replies 401).
9
+ * An identity is never fabricated. The context `userRef` is passed straight to `effectiveRoles`;
10
+ * authz reads its `.id`/`.type` and re-reads `globalRoles` from the same context, so global roles
11
+ * (e.g. `ADMIN`) land in the result with no extra wiring.
12
+ */
13
+ export class AuthzActorResolver {
14
+ #authz;
15
+ constructor(config) {
16
+ this.#authz = config.authz;
17
+ }
18
+ async resolve(_req) {
19
+ const accessor = readContextAccessor();
20
+ const ref = accessor?.userRef;
21
+ if (ref?.id === undefined || ref.id === null || String(ref.id).length === 0) {
22
+ throw new Error('authzActorResolver: no authenticated identity in @agora/context. The agent route must ' +
23
+ 'sit behind authkit auth middleware (which populates the context), with the ' +
24
+ '@adonis-agora/context provider registered.');
25
+ }
26
+ const scope = accessor?.tenantId
27
+ ? { tenantId: accessor.tenantId }
28
+ : undefined;
29
+ const roles = await this.#authz.effectiveRoles(ref, scope);
30
+ return {
31
+ id: String(ref.id),
32
+ roles,
33
+ ...(accessor?.tenantId ? { tenantRef: accessor.tenantId } : {}),
34
+ };
35
+ }
36
+ }
37
+ /** Factory for {@link AuthzActorResolver}. */
38
+ export function authzActorResolver(config) {
39
+ return new AuthzActorResolver(config);
40
+ }
41
+ //# sourceMappingURL=authz-actor-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authz-actor-resolver.js","sourceRoot":"","sources":["../../../src/authz/authz-actor-resolver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAkBzD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,kBAAkB;IACpB,MAAM,CAAuB;IAEtC,YAAY,MAAgC;QAC1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAa;QACzB,MAAM,QAAQ,GAAG,mBAAmB,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,QAAQ,EAAE,OAAO,CAAC;QAC9B,IAAI,GAAG,EAAE,EAAE,KAAK,SAAS,IAAI,GAAG,CAAC,EAAE,KAAK,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5E,MAAM,IAAI,KAAK,CACb,wFAAwF;gBACtF,6EAA6E;gBAC7E,4CAA4C,CAC/C,CAAC;QACJ,CAAC;QAED,MAAM,KAAK,GAAiC,QAAQ,EAAE,QAAQ;YAC5D,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE;YACjC,CAAC,CAAC,SAAS,CAAC;QACd,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAE3D,OAAO;YACL,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,KAAK;YACL,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChE,CAAC;IACJ,CAAC;CACF;AAED,8CAA8C;AAC9C,MAAM,UAAU,kBAAkB,CAAC,MAAgC;IACjE,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC"}
@@ -1,3 +1,5 @@
1
1
  export { AuthzToolAuthorizer, authzToolAuthorizer, defaultUserFromActor, } from './authz-tool-authorizer.js';
2
2
  export type { AuthzToolAuthorizerConfig, AuthzServiceLike, AuthzTenantScope, } from './authz-tool-authorizer.js';
3
+ export { AuthzActorResolver, authzActorResolver } from './authz-actor-resolver.js';
4
+ export type { AuthzActorResolverConfig, AuthzRolesSourceLike } from './authz-actor-resolver.js';
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/authz/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,yBAAyB,EACzB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/authz/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,yBAAyB,EACzB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACnF,YAAY,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export { AuthzToolAuthorizer, authzToolAuthorizer, defaultUserFromActor, } from './authz-tool-authorizer.js';
2
+ export { AuthzActorResolver, authzActorResolver } from './authz-actor-resolver.js';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/authz/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/authz/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AAMpC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "0.7.1";
1
+ export declare const VERSION = "0.8.0";
2
2
  export * from './types.js';
3
3
  export * from './spi/tool.js';
4
4
  export * from './spi/model-provider.js';
package/dist/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const VERSION = '0.7.1';
1
+ export const VERSION = '0.8.0';
2
2
  export * from './types.js';
3
3
  export * from './spi/tool.js';
4
4
  export * from './spi/model-provider.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonis-agora/agent",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.",
5
5
  "license": "MIT",
6
6
  "repository": {