@lelu-auth/lelu 0.1.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/LICENSE +21 -0
- package/README.md +55 -0
- package/dist/client-BD9h8CBT.d.mts +235 -0
- package/dist/client-BD9h8CBT.d.ts +235 -0
- package/dist/express/index.d.mts +31 -0
- package/dist/express/index.d.ts +31 -0
- package/dist/express/index.js +277 -0
- package/dist/express/index.js.map +1 -0
- package/dist/express/index.mjs +275 -0
- package/dist/express/index.mjs.map +1 -0
- package/dist/index.d.mts +104 -0
- package/dist/index.d.ts +104 -0
- package/dist/index.js +306 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +296 -0
- package/dist/index.mjs.map +1 -0
- package/dist/langchain/index.d.mts +110 -0
- package/dist/langchain/index.d.ts +110 -0
- package/dist/langchain/index.js +159 -0
- package/dist/langchain/index.js.map +1 -0
- package/dist/langchain/index.mjs +156 -0
- package/dist/langchain/index.mjs.map +1 -0
- package/dist/react/index.d.mts +52 -0
- package/dist/react/index.d.ts +52 -0
- package/dist/react/index.js +670 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +666 -0
- package/dist/react/index.mjs.map +1 -0
- package/package.json +95 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Abenezer <abenezergetachew0923@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Lelu
|
|
2
|
+
|
|
3
|
+
The TypeScript SDK for Lelu — the confidence-aware authorization engine for autonomous AI agents.
|
|
4
|
+
|
|
5
|
+
Lelu provides confidence-aware access control, human-in-the-loop approvals, and SOC 2-ready audit trails for your autonomous agents.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @lelu-auth/lelu
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createClient } from "@lelu-auth/lelu";
|
|
17
|
+
|
|
18
|
+
// Initialize the client
|
|
19
|
+
const lelu = createClient({
|
|
20
|
+
baseUrl: "http://localhost:8082"
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Authorize an agent action
|
|
24
|
+
async function runAgent() {
|
|
25
|
+
const { allowed, reason } = await lelu.agentAuthorize({
|
|
26
|
+
agentId: "agent-123",
|
|
27
|
+
action: "read_database",
|
|
28
|
+
resource: "users_table",
|
|
29
|
+
context: {
|
|
30
|
+
confidence: 0.95
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (allowed) {
|
|
35
|
+
console.log("Action permitted!");
|
|
36
|
+
} else {
|
|
37
|
+
console.log("Action denied:", reason);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
- **Confidence-Aware**: Dynamically adjust permissions based on the AI agent's confidence level.
|
|
45
|
+
- **Human-in-the-loop**: Require human approval for low-confidence or high-risk actions.
|
|
46
|
+
- **Audit Trails**: SOC 2-ready logging of all agent decisions and actions.
|
|
47
|
+
- **Framework Agnostic**: Works with LangChain, AutoGPT, or custom agent frameworks.
|
|
48
|
+
|
|
49
|
+
## Documentation
|
|
50
|
+
|
|
51
|
+
For full documentation, visit [https://github.com/lelu-auth/lelu](https://github.com/lelu-auth/lelu).
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
MIT
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const AuthRequestSchema: z.ZodObject<{
|
|
4
|
+
userId: z.ZodString;
|
|
5
|
+
action: z.ZodString;
|
|
6
|
+
resource: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
userId: string;
|
|
9
|
+
action: string;
|
|
10
|
+
resource?: Record<string, string> | undefined;
|
|
11
|
+
}, {
|
|
12
|
+
userId: string;
|
|
13
|
+
action: string;
|
|
14
|
+
resource?: Record<string, string> | undefined;
|
|
15
|
+
}>;
|
|
16
|
+
declare const AgentContextSchema: z.ZodObject<{
|
|
17
|
+
/** LLM confidence score — 0.0 to 1.0 */
|
|
18
|
+
confidence: z.ZodNumber;
|
|
19
|
+
/** User the agent is acting on behalf of */
|
|
20
|
+
actingFor: z.ZodOptional<z.ZodString>;
|
|
21
|
+
/** Requested agent scope */
|
|
22
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
confidence: number;
|
|
25
|
+
actingFor?: string | undefined;
|
|
26
|
+
scope?: string | undefined;
|
|
27
|
+
}, {
|
|
28
|
+
confidence: number;
|
|
29
|
+
actingFor?: string | undefined;
|
|
30
|
+
scope?: string | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
declare const AgentAuthRequestSchema: z.ZodObject<{
|
|
33
|
+
actor: z.ZodString;
|
|
34
|
+
action: z.ZodString;
|
|
35
|
+
resource: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
36
|
+
context: z.ZodObject<{
|
|
37
|
+
/** LLM confidence score — 0.0 to 1.0 */
|
|
38
|
+
confidence: z.ZodNumber;
|
|
39
|
+
/** User the agent is acting on behalf of */
|
|
40
|
+
actingFor: z.ZodOptional<z.ZodString>;
|
|
41
|
+
/** Requested agent scope */
|
|
42
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
confidence: number;
|
|
45
|
+
actingFor?: string | undefined;
|
|
46
|
+
scope?: string | undefined;
|
|
47
|
+
}, {
|
|
48
|
+
confidence: number;
|
|
49
|
+
actingFor?: string | undefined;
|
|
50
|
+
scope?: string | undefined;
|
|
51
|
+
}>;
|
|
52
|
+
}, "strip", z.ZodTypeAny, {
|
|
53
|
+
action: string;
|
|
54
|
+
actor: string;
|
|
55
|
+
context: {
|
|
56
|
+
confidence: number;
|
|
57
|
+
actingFor?: string | undefined;
|
|
58
|
+
scope?: string | undefined;
|
|
59
|
+
};
|
|
60
|
+
resource?: Record<string, string> | undefined;
|
|
61
|
+
}, {
|
|
62
|
+
action: string;
|
|
63
|
+
actor: string;
|
|
64
|
+
context: {
|
|
65
|
+
confidence: number;
|
|
66
|
+
actingFor?: string | undefined;
|
|
67
|
+
scope?: string | undefined;
|
|
68
|
+
};
|
|
69
|
+
resource?: Record<string, string> | undefined;
|
|
70
|
+
}>;
|
|
71
|
+
declare const MintTokenRequestSchema: z.ZodObject<{
|
|
72
|
+
scope: z.ZodString;
|
|
73
|
+
actingFor: z.ZodOptional<z.ZodString>;
|
|
74
|
+
ttlSeconds: z.ZodOptional<z.ZodNumber>;
|
|
75
|
+
}, "strip", z.ZodTypeAny, {
|
|
76
|
+
scope: string;
|
|
77
|
+
actingFor?: string | undefined;
|
|
78
|
+
ttlSeconds?: number | undefined;
|
|
79
|
+
}, {
|
|
80
|
+
scope: string;
|
|
81
|
+
actingFor?: string | undefined;
|
|
82
|
+
ttlSeconds?: number | undefined;
|
|
83
|
+
}>;
|
|
84
|
+
declare const DelegateScopeRequestSchema: z.ZodObject<{
|
|
85
|
+
delegator: z.ZodString;
|
|
86
|
+
delegatee: z.ZodString;
|
|
87
|
+
scopedTo: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
88
|
+
ttlSeconds: z.ZodOptional<z.ZodNumber>;
|
|
89
|
+
confidence: z.ZodOptional<z.ZodNumber>;
|
|
90
|
+
actingFor: z.ZodOptional<z.ZodString>;
|
|
91
|
+
tenantId: z.ZodOptional<z.ZodString>;
|
|
92
|
+
}, "strip", z.ZodTypeAny, {
|
|
93
|
+
delegator: string;
|
|
94
|
+
delegatee: string;
|
|
95
|
+
confidence?: number | undefined;
|
|
96
|
+
actingFor?: string | undefined;
|
|
97
|
+
ttlSeconds?: number | undefined;
|
|
98
|
+
scopedTo?: string[] | undefined;
|
|
99
|
+
tenantId?: string | undefined;
|
|
100
|
+
}, {
|
|
101
|
+
delegator: string;
|
|
102
|
+
delegatee: string;
|
|
103
|
+
confidence?: number | undefined;
|
|
104
|
+
actingFor?: string | undefined;
|
|
105
|
+
ttlSeconds?: number | undefined;
|
|
106
|
+
scopedTo?: string[] | undefined;
|
|
107
|
+
tenantId?: string | undefined;
|
|
108
|
+
}>;
|
|
109
|
+
interface AuthDecision {
|
|
110
|
+
allowed: boolean;
|
|
111
|
+
reason: string;
|
|
112
|
+
traceId: string;
|
|
113
|
+
}
|
|
114
|
+
interface AgentAuthDecision {
|
|
115
|
+
allowed: boolean;
|
|
116
|
+
reason: string;
|
|
117
|
+
traceId: string;
|
|
118
|
+
downgradedScope: string | undefined;
|
|
119
|
+
requiresHumanReview: boolean;
|
|
120
|
+
confidenceUsed: number;
|
|
121
|
+
}
|
|
122
|
+
interface MintTokenResult {
|
|
123
|
+
token: string;
|
|
124
|
+
tokenId: string;
|
|
125
|
+
expiresAt: Date;
|
|
126
|
+
}
|
|
127
|
+
interface DelegateScopeRequest {
|
|
128
|
+
/** Agent delegating the scope */
|
|
129
|
+
delegator: string;
|
|
130
|
+
/** Agent receiving the constrained sub-scope */
|
|
131
|
+
delegatee: string;
|
|
132
|
+
/** Actions to grant (must be subset of policy's can_delegate.scoped_to) */
|
|
133
|
+
scopedTo?: string[];
|
|
134
|
+
/** Token TTL in seconds — capped by the policy's max_ttl_seconds */
|
|
135
|
+
ttlSeconds?: number;
|
|
136
|
+
/** Delegator's confidence score — checked against require_confidence_above */
|
|
137
|
+
confidence?: number;
|
|
138
|
+
/** User the delegated agent acts on behalf of */
|
|
139
|
+
actingFor?: string;
|
|
140
|
+
tenantId?: string;
|
|
141
|
+
}
|
|
142
|
+
interface DelegateScopeResult {
|
|
143
|
+
token: string;
|
|
144
|
+
tokenId: string;
|
|
145
|
+
expiresAt: Date;
|
|
146
|
+
delegator: string;
|
|
147
|
+
delegatee: string;
|
|
148
|
+
grantedScopes: string[];
|
|
149
|
+
traceId: string;
|
|
150
|
+
}
|
|
151
|
+
interface RevokeTokenResult {
|
|
152
|
+
success: boolean;
|
|
153
|
+
}
|
|
154
|
+
type AuthRequest = z.infer<typeof AuthRequestSchema>;
|
|
155
|
+
type AgentAuthRequest = z.infer<typeof AgentAuthRequestSchema>;
|
|
156
|
+
type AgentContext = z.infer<typeof AgentContextSchema>;
|
|
157
|
+
type MintTokenRequest = z.infer<typeof MintTokenRequestSchema>;
|
|
158
|
+
interface ClientConfig {
|
|
159
|
+
/** Base URL of the Auth Permission Engine (default: http://localhost:8080) */
|
|
160
|
+
baseUrl?: string;
|
|
161
|
+
/** Request timeout in milliseconds (default: 5000) */
|
|
162
|
+
timeoutMs?: number;
|
|
163
|
+
/** Optional bearer token for authenticating with the engine */
|
|
164
|
+
apiKey?: string;
|
|
165
|
+
}
|
|
166
|
+
declare class AuthEngineError extends Error {
|
|
167
|
+
readonly status?: number | undefined;
|
|
168
|
+
readonly details?: unknown | undefined;
|
|
169
|
+
constructor(message: string, status?: number | undefined, details?: unknown | undefined);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* LeluClient is the core SDK entry-point. It communicates with the local
|
|
174
|
+
* Auth Permission Engine sidecar over HTTP/JSON.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* const lelu = new LeluClient({ baseUrl: "http://localhost:8080" });
|
|
179
|
+
*
|
|
180
|
+
* const decision = await lelu.agentAuthorize({
|
|
181
|
+
* actor: "invoice_bot",
|
|
182
|
+
* action: "approve_refunds",
|
|
183
|
+
* context: { confidence: 0.92, actingFor: "user_123" },
|
|
184
|
+
* });
|
|
185
|
+
*
|
|
186
|
+
* if (!decision.allowed) {
|
|
187
|
+
* console.log(decision.reason);
|
|
188
|
+
* }
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
declare class LeluClient {
|
|
192
|
+
private readonly baseUrl;
|
|
193
|
+
private readonly timeoutMs;
|
|
194
|
+
private readonly apiKey;
|
|
195
|
+
constructor(cfg?: ClientConfig);
|
|
196
|
+
/**
|
|
197
|
+
* Checks whether a human user is permitted to perform an action.
|
|
198
|
+
*/
|
|
199
|
+
authorize(req: AuthRequest): Promise<AuthDecision>;
|
|
200
|
+
/**
|
|
201
|
+
* Checks whether an AI agent is permitted to perform an action, taking the
|
|
202
|
+
* confidence score into account (Confidence-Aware Auth ★).
|
|
203
|
+
*/
|
|
204
|
+
agentAuthorize(req: AgentAuthRequest): Promise<AgentAuthDecision>;
|
|
205
|
+
/**
|
|
206
|
+
* Mints a scoped JWT for an agent with an optional TTL.
|
|
207
|
+
* Default TTL is 60 seconds.
|
|
208
|
+
*/
|
|
209
|
+
mintToken(req: MintTokenRequest): Promise<MintTokenResult>;
|
|
210
|
+
/**
|
|
211
|
+
* Immediately revokes a JIT token by its ID.
|
|
212
|
+
*/
|
|
213
|
+
revokeToken(tokenId: string): Promise<RevokeTokenResult>;
|
|
214
|
+
/**
|
|
215
|
+
* Delegates a constrained sub-scope from one agent to another.
|
|
216
|
+
*
|
|
217
|
+
* Validates the delegation rule in the loaded policy, caps the TTL to the
|
|
218
|
+
* policy maximum, and mints a child JIT token scoped to the granted actions.
|
|
219
|
+
*
|
|
220
|
+
* The delegator's `confidence` score is checked against the policy's
|
|
221
|
+
* `require_confidence_above` before delegation is granted.
|
|
222
|
+
*/
|
|
223
|
+
delegateScope(req: DelegateScopeRequest): Promise<DelegateScopeResult>;
|
|
224
|
+
/**
|
|
225
|
+
* Returns true if the engine is reachable and healthy.
|
|
226
|
+
*/
|
|
227
|
+
isHealthy(): Promise<boolean>;
|
|
228
|
+
private headers;
|
|
229
|
+
private post;
|
|
230
|
+
private delete;
|
|
231
|
+
private get;
|
|
232
|
+
private parseResponse;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export { type AgentAuthDecision as A, type ClientConfig as C, type DelegateScopeRequest as D, LeluClient as L, type MintTokenRequest as M, type RevokeTokenResult as R, type AgentAuthRequest as a, AgentAuthRequestSchema as b, type AgentContext as c, AgentContextSchema as d, type AuthDecision as e, AuthEngineError as f, type AuthRequest as g, AuthRequestSchema as h, DelegateScopeRequestSchema as i, type DelegateScopeResult as j, MintTokenRequestSchema as k, type MintTokenResult as l };
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const AuthRequestSchema: z.ZodObject<{
|
|
4
|
+
userId: z.ZodString;
|
|
5
|
+
action: z.ZodString;
|
|
6
|
+
resource: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
userId: string;
|
|
9
|
+
action: string;
|
|
10
|
+
resource?: Record<string, string> | undefined;
|
|
11
|
+
}, {
|
|
12
|
+
userId: string;
|
|
13
|
+
action: string;
|
|
14
|
+
resource?: Record<string, string> | undefined;
|
|
15
|
+
}>;
|
|
16
|
+
declare const AgentContextSchema: z.ZodObject<{
|
|
17
|
+
/** LLM confidence score — 0.0 to 1.0 */
|
|
18
|
+
confidence: z.ZodNumber;
|
|
19
|
+
/** User the agent is acting on behalf of */
|
|
20
|
+
actingFor: z.ZodOptional<z.ZodString>;
|
|
21
|
+
/** Requested agent scope */
|
|
22
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
confidence: number;
|
|
25
|
+
actingFor?: string | undefined;
|
|
26
|
+
scope?: string | undefined;
|
|
27
|
+
}, {
|
|
28
|
+
confidence: number;
|
|
29
|
+
actingFor?: string | undefined;
|
|
30
|
+
scope?: string | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
declare const AgentAuthRequestSchema: z.ZodObject<{
|
|
33
|
+
actor: z.ZodString;
|
|
34
|
+
action: z.ZodString;
|
|
35
|
+
resource: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
36
|
+
context: z.ZodObject<{
|
|
37
|
+
/** LLM confidence score — 0.0 to 1.0 */
|
|
38
|
+
confidence: z.ZodNumber;
|
|
39
|
+
/** User the agent is acting on behalf of */
|
|
40
|
+
actingFor: z.ZodOptional<z.ZodString>;
|
|
41
|
+
/** Requested agent scope */
|
|
42
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
confidence: number;
|
|
45
|
+
actingFor?: string | undefined;
|
|
46
|
+
scope?: string | undefined;
|
|
47
|
+
}, {
|
|
48
|
+
confidence: number;
|
|
49
|
+
actingFor?: string | undefined;
|
|
50
|
+
scope?: string | undefined;
|
|
51
|
+
}>;
|
|
52
|
+
}, "strip", z.ZodTypeAny, {
|
|
53
|
+
action: string;
|
|
54
|
+
actor: string;
|
|
55
|
+
context: {
|
|
56
|
+
confidence: number;
|
|
57
|
+
actingFor?: string | undefined;
|
|
58
|
+
scope?: string | undefined;
|
|
59
|
+
};
|
|
60
|
+
resource?: Record<string, string> | undefined;
|
|
61
|
+
}, {
|
|
62
|
+
action: string;
|
|
63
|
+
actor: string;
|
|
64
|
+
context: {
|
|
65
|
+
confidence: number;
|
|
66
|
+
actingFor?: string | undefined;
|
|
67
|
+
scope?: string | undefined;
|
|
68
|
+
};
|
|
69
|
+
resource?: Record<string, string> | undefined;
|
|
70
|
+
}>;
|
|
71
|
+
declare const MintTokenRequestSchema: z.ZodObject<{
|
|
72
|
+
scope: z.ZodString;
|
|
73
|
+
actingFor: z.ZodOptional<z.ZodString>;
|
|
74
|
+
ttlSeconds: z.ZodOptional<z.ZodNumber>;
|
|
75
|
+
}, "strip", z.ZodTypeAny, {
|
|
76
|
+
scope: string;
|
|
77
|
+
actingFor?: string | undefined;
|
|
78
|
+
ttlSeconds?: number | undefined;
|
|
79
|
+
}, {
|
|
80
|
+
scope: string;
|
|
81
|
+
actingFor?: string | undefined;
|
|
82
|
+
ttlSeconds?: number | undefined;
|
|
83
|
+
}>;
|
|
84
|
+
declare const DelegateScopeRequestSchema: z.ZodObject<{
|
|
85
|
+
delegator: z.ZodString;
|
|
86
|
+
delegatee: z.ZodString;
|
|
87
|
+
scopedTo: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
88
|
+
ttlSeconds: z.ZodOptional<z.ZodNumber>;
|
|
89
|
+
confidence: z.ZodOptional<z.ZodNumber>;
|
|
90
|
+
actingFor: z.ZodOptional<z.ZodString>;
|
|
91
|
+
tenantId: z.ZodOptional<z.ZodString>;
|
|
92
|
+
}, "strip", z.ZodTypeAny, {
|
|
93
|
+
delegator: string;
|
|
94
|
+
delegatee: string;
|
|
95
|
+
confidence?: number | undefined;
|
|
96
|
+
actingFor?: string | undefined;
|
|
97
|
+
ttlSeconds?: number | undefined;
|
|
98
|
+
scopedTo?: string[] | undefined;
|
|
99
|
+
tenantId?: string | undefined;
|
|
100
|
+
}, {
|
|
101
|
+
delegator: string;
|
|
102
|
+
delegatee: string;
|
|
103
|
+
confidence?: number | undefined;
|
|
104
|
+
actingFor?: string | undefined;
|
|
105
|
+
ttlSeconds?: number | undefined;
|
|
106
|
+
scopedTo?: string[] | undefined;
|
|
107
|
+
tenantId?: string | undefined;
|
|
108
|
+
}>;
|
|
109
|
+
interface AuthDecision {
|
|
110
|
+
allowed: boolean;
|
|
111
|
+
reason: string;
|
|
112
|
+
traceId: string;
|
|
113
|
+
}
|
|
114
|
+
interface AgentAuthDecision {
|
|
115
|
+
allowed: boolean;
|
|
116
|
+
reason: string;
|
|
117
|
+
traceId: string;
|
|
118
|
+
downgradedScope: string | undefined;
|
|
119
|
+
requiresHumanReview: boolean;
|
|
120
|
+
confidenceUsed: number;
|
|
121
|
+
}
|
|
122
|
+
interface MintTokenResult {
|
|
123
|
+
token: string;
|
|
124
|
+
tokenId: string;
|
|
125
|
+
expiresAt: Date;
|
|
126
|
+
}
|
|
127
|
+
interface DelegateScopeRequest {
|
|
128
|
+
/** Agent delegating the scope */
|
|
129
|
+
delegator: string;
|
|
130
|
+
/** Agent receiving the constrained sub-scope */
|
|
131
|
+
delegatee: string;
|
|
132
|
+
/** Actions to grant (must be subset of policy's can_delegate.scoped_to) */
|
|
133
|
+
scopedTo?: string[];
|
|
134
|
+
/** Token TTL in seconds — capped by the policy's max_ttl_seconds */
|
|
135
|
+
ttlSeconds?: number;
|
|
136
|
+
/** Delegator's confidence score — checked against require_confidence_above */
|
|
137
|
+
confidence?: number;
|
|
138
|
+
/** User the delegated agent acts on behalf of */
|
|
139
|
+
actingFor?: string;
|
|
140
|
+
tenantId?: string;
|
|
141
|
+
}
|
|
142
|
+
interface DelegateScopeResult {
|
|
143
|
+
token: string;
|
|
144
|
+
tokenId: string;
|
|
145
|
+
expiresAt: Date;
|
|
146
|
+
delegator: string;
|
|
147
|
+
delegatee: string;
|
|
148
|
+
grantedScopes: string[];
|
|
149
|
+
traceId: string;
|
|
150
|
+
}
|
|
151
|
+
interface RevokeTokenResult {
|
|
152
|
+
success: boolean;
|
|
153
|
+
}
|
|
154
|
+
type AuthRequest = z.infer<typeof AuthRequestSchema>;
|
|
155
|
+
type AgentAuthRequest = z.infer<typeof AgentAuthRequestSchema>;
|
|
156
|
+
type AgentContext = z.infer<typeof AgentContextSchema>;
|
|
157
|
+
type MintTokenRequest = z.infer<typeof MintTokenRequestSchema>;
|
|
158
|
+
interface ClientConfig {
|
|
159
|
+
/** Base URL of the Auth Permission Engine (default: http://localhost:8080) */
|
|
160
|
+
baseUrl?: string;
|
|
161
|
+
/** Request timeout in milliseconds (default: 5000) */
|
|
162
|
+
timeoutMs?: number;
|
|
163
|
+
/** Optional bearer token for authenticating with the engine */
|
|
164
|
+
apiKey?: string;
|
|
165
|
+
}
|
|
166
|
+
declare class AuthEngineError extends Error {
|
|
167
|
+
readonly status?: number | undefined;
|
|
168
|
+
readonly details?: unknown | undefined;
|
|
169
|
+
constructor(message: string, status?: number | undefined, details?: unknown | undefined);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* LeluClient is the core SDK entry-point. It communicates with the local
|
|
174
|
+
* Auth Permission Engine sidecar over HTTP/JSON.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* const lelu = new LeluClient({ baseUrl: "http://localhost:8080" });
|
|
179
|
+
*
|
|
180
|
+
* const decision = await lelu.agentAuthorize({
|
|
181
|
+
* actor: "invoice_bot",
|
|
182
|
+
* action: "approve_refunds",
|
|
183
|
+
* context: { confidence: 0.92, actingFor: "user_123" },
|
|
184
|
+
* });
|
|
185
|
+
*
|
|
186
|
+
* if (!decision.allowed) {
|
|
187
|
+
* console.log(decision.reason);
|
|
188
|
+
* }
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
declare class LeluClient {
|
|
192
|
+
private readonly baseUrl;
|
|
193
|
+
private readonly timeoutMs;
|
|
194
|
+
private readonly apiKey;
|
|
195
|
+
constructor(cfg?: ClientConfig);
|
|
196
|
+
/**
|
|
197
|
+
* Checks whether a human user is permitted to perform an action.
|
|
198
|
+
*/
|
|
199
|
+
authorize(req: AuthRequest): Promise<AuthDecision>;
|
|
200
|
+
/**
|
|
201
|
+
* Checks whether an AI agent is permitted to perform an action, taking the
|
|
202
|
+
* confidence score into account (Confidence-Aware Auth ★).
|
|
203
|
+
*/
|
|
204
|
+
agentAuthorize(req: AgentAuthRequest): Promise<AgentAuthDecision>;
|
|
205
|
+
/**
|
|
206
|
+
* Mints a scoped JWT for an agent with an optional TTL.
|
|
207
|
+
* Default TTL is 60 seconds.
|
|
208
|
+
*/
|
|
209
|
+
mintToken(req: MintTokenRequest): Promise<MintTokenResult>;
|
|
210
|
+
/**
|
|
211
|
+
* Immediately revokes a JIT token by its ID.
|
|
212
|
+
*/
|
|
213
|
+
revokeToken(tokenId: string): Promise<RevokeTokenResult>;
|
|
214
|
+
/**
|
|
215
|
+
* Delegates a constrained sub-scope from one agent to another.
|
|
216
|
+
*
|
|
217
|
+
* Validates the delegation rule in the loaded policy, caps the TTL to the
|
|
218
|
+
* policy maximum, and mints a child JIT token scoped to the granted actions.
|
|
219
|
+
*
|
|
220
|
+
* The delegator's `confidence` score is checked against the policy's
|
|
221
|
+
* `require_confidence_above` before delegation is granted.
|
|
222
|
+
*/
|
|
223
|
+
delegateScope(req: DelegateScopeRequest): Promise<DelegateScopeResult>;
|
|
224
|
+
/**
|
|
225
|
+
* Returns true if the engine is reachable and healthy.
|
|
226
|
+
*/
|
|
227
|
+
isHealthy(): Promise<boolean>;
|
|
228
|
+
private headers;
|
|
229
|
+
private post;
|
|
230
|
+
private delete;
|
|
231
|
+
private get;
|
|
232
|
+
private parseResponse;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export { type AgentAuthDecision as A, type ClientConfig as C, type DelegateScopeRequest as D, LeluClient as L, type MintTokenRequest as M, type RevokeTokenResult as R, type AgentAuthRequest as a, AgentAuthRequestSchema as b, type AgentContext as c, AgentContextSchema as d, type AuthDecision as e, AuthEngineError as f, type AuthRequest as g, AuthRequestSchema as h, DelegateScopeRequestSchema as i, type DelegateScopeResult as j, MintTokenRequestSchema as k, type MintTokenResult as l };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { RequestHandler } from 'express';
|
|
2
|
+
import { L as LeluClient } from '../client-BD9h8CBT.mjs';
|
|
3
|
+
import 'zod';
|
|
4
|
+
|
|
5
|
+
interface AuthorizeOptions {
|
|
6
|
+
/** Base URL of the Lelu engine (default: http://localhost:8080) */
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
/** API key for the Lelu engine */
|
|
9
|
+
apiKey?: string;
|
|
10
|
+
/** HTTP header that carries the actor identifier (default: x-actor) */
|
|
11
|
+
actorHeader?: string;
|
|
12
|
+
/** Confidence score to pass to the engine (default: 1.0) */
|
|
13
|
+
confidence?: number;
|
|
14
|
+
/** Explicit LeluClient instance (overrides baseUrl/apiKey) */
|
|
15
|
+
client?: LeluClient;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Express middleware factory that calls the Lelu engine and either calls
|
|
19
|
+
* `next()` (allowed) or returns a 403 JSON response (denied / human_review).
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* import express from "express";
|
|
23
|
+
* import { authorize } from "@lelu/sdk/express";
|
|
24
|
+
*
|
|
25
|
+
* const app = express();
|
|
26
|
+
* app.get("/sensitive", authorize("files.read", { confidence: 0.9 }), handler);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function authorize(action: string, opts?: AuthorizeOptions): RequestHandler;
|
|
30
|
+
|
|
31
|
+
export { type AuthorizeOptions, authorize };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { RequestHandler } from 'express';
|
|
2
|
+
import { L as LeluClient } from '../client-BD9h8CBT.js';
|
|
3
|
+
import 'zod';
|
|
4
|
+
|
|
5
|
+
interface AuthorizeOptions {
|
|
6
|
+
/** Base URL of the Lelu engine (default: http://localhost:8080) */
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
/** API key for the Lelu engine */
|
|
9
|
+
apiKey?: string;
|
|
10
|
+
/** HTTP header that carries the actor identifier (default: x-actor) */
|
|
11
|
+
actorHeader?: string;
|
|
12
|
+
/** Confidence score to pass to the engine (default: 1.0) */
|
|
13
|
+
confidence?: number;
|
|
14
|
+
/** Explicit LeluClient instance (overrides baseUrl/apiKey) */
|
|
15
|
+
client?: LeluClient;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Express middleware factory that calls the Lelu engine and either calls
|
|
19
|
+
* `next()` (allowed) or returns a 403 JSON response (denied / human_review).
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* import express from "express";
|
|
23
|
+
* import { authorize } from "@lelu/sdk/express";
|
|
24
|
+
*
|
|
25
|
+
* const app = express();
|
|
26
|
+
* app.get("/sensitive", authorize("files.read", { confidence: 0.9 }), handler);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function authorize(action: string, opts?: AuthorizeOptions): RequestHandler;
|
|
30
|
+
|
|
31
|
+
export { type AuthorizeOptions, authorize };
|