palaryn 0.1.0 → 0.3.2
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/README.md +243 -588
- package/dist/sdk/typescript/src/client.js +2 -2
- package/dist/sdk/typescript/src/client.js.map +1 -1
- package/dist/src/anomaly/detector.d.ts +7 -4
- package/dist/src/anomaly/detector.d.ts.map +1 -1
- package/dist/src/anomaly/detector.js +22 -12
- package/dist/src/anomaly/detector.js.map +1 -1
- package/dist/src/audit/logger.d.ts +10 -0
- package/dist/src/audit/logger.d.ts.map +1 -1
- package/dist/src/audit/logger.js +52 -38
- package/dist/src/audit/logger.js.map +1 -1
- package/dist/src/auth/routes.d.ts.map +1 -1
- package/dist/src/auth/routes.js +35 -0
- package/dist/src/auth/routes.js.map +1 -1
- package/dist/src/budget/manager.d.ts +5 -0
- package/dist/src/budget/manager.d.ts.map +1 -1
- package/dist/src/budget/manager.js +32 -0
- package/dist/src/budget/manager.js.map +1 -1
- package/dist/src/budget/model-pricing.d.ts +20 -0
- package/dist/src/budget/model-pricing.d.ts.map +1 -0
- package/dist/src/budget/model-pricing.js +107 -0
- package/dist/src/budget/model-pricing.js.map +1 -0
- package/dist/src/budget/usage-extractor.d.ts +3 -1
- package/dist/src/budget/usage-extractor.d.ts.map +1 -1
- package/dist/src/budget/usage-extractor.js +47 -3
- package/dist/src/budget/usage-extractor.js.map +1 -1
- package/dist/src/config/defaults.d.ts.map +1 -1
- package/dist/src/config/defaults.js +65 -13
- package/dist/src/config/defaults.js.map +1 -1
- package/dist/src/dlp/tool-patterns.d.ts +7 -0
- package/dist/src/dlp/tool-patterns.d.ts.map +1 -0
- package/dist/src/dlp/tool-patterns.js +34 -0
- package/dist/src/dlp/tool-patterns.js.map +1 -0
- package/dist/src/executor/filesystem-executor.d.ts +28 -0
- package/dist/src/executor/filesystem-executor.d.ts.map +1 -0
- package/dist/src/executor/filesystem-executor.js +192 -0
- package/dist/src/executor/filesystem-executor.js.map +1 -0
- package/dist/src/executor/http-executor.d.ts.map +1 -1
- package/dist/src/executor/http-executor.js +22 -2
- package/dist/src/executor/http-executor.js.map +1 -1
- package/dist/src/executor/index.d.ts +4 -0
- package/dist/src/executor/index.d.ts.map +1 -1
- package/dist/src/executor/index.js +9 -1
- package/dist/src/executor/index.js.map +1 -1
- package/dist/src/executor/shell-executor.d.ts +22 -0
- package/dist/src/executor/shell-executor.d.ts.map +1 -0
- package/dist/src/executor/shell-executor.js +119 -0
- package/dist/src/executor/shell-executor.js.map +1 -0
- package/dist/src/executor/sql-executor.d.ts +29 -0
- package/dist/src/executor/sql-executor.d.ts.map +1 -0
- package/dist/src/executor/sql-executor.js +114 -0
- package/dist/src/executor/sql-executor.js.map +1 -0
- package/dist/src/executor/websocket-executor.d.ts +26 -0
- package/dist/src/executor/websocket-executor.d.ts.map +1 -0
- package/dist/src/executor/websocket-executor.js +205 -0
- package/dist/src/executor/websocket-executor.js.map +1 -0
- package/dist/src/interceptor/index.d.ts +2 -0
- package/dist/src/interceptor/index.d.ts.map +1 -0
- package/dist/src/interceptor/index.js +6 -0
- package/dist/src/interceptor/index.js.map +1 -0
- package/dist/src/interceptor/provider-interceptor.d.ts +36 -0
- package/dist/src/interceptor/provider-interceptor.d.ts.map +1 -0
- package/dist/src/interceptor/provider-interceptor.js +302 -0
- package/dist/src/interceptor/provider-interceptor.js.map +1 -0
- package/dist/src/mcp/auth-verifier.d.ts.map +1 -1
- package/dist/src/mcp/auth-verifier.js +3 -2
- package/dist/src/mcp/auth-verifier.js.map +1 -1
- package/dist/src/mcp/bridge.d.ts +14 -10
- package/dist/src/mcp/bridge.d.ts.map +1 -1
- package/dist/src/mcp/bridge.js +51 -227
- package/dist/src/mcp/bridge.js.map +1 -1
- package/dist/src/mcp/http-transport.d.ts +2 -0
- package/dist/src/mcp/http-transport.d.ts.map +1 -1
- package/dist/src/mcp/http-transport.js +117 -66
- package/dist/src/mcp/http-transport.js.map +1 -1
- package/dist/src/mcp/internal-auth.d.ts +13 -0
- package/dist/src/mcp/internal-auth.d.ts.map +1 -0
- package/dist/src/mcp/internal-auth.js +12 -0
- package/dist/src/mcp/internal-auth.js.map +1 -0
- package/dist/src/mcp/tool-definitions.d.ts +41 -0
- package/dist/src/mcp/tool-definitions.d.ts.map +1 -0
- package/dist/src/mcp/tool-definitions.js +491 -0
- package/dist/src/mcp/tool-definitions.js.map +1 -0
- package/dist/src/middleware/auth.js.map +1 -1
- package/dist/src/middleware/session.js.map +1 -1
- package/dist/src/middleware/validate.d.ts +8 -0
- package/dist/src/middleware/validate.d.ts.map +1 -1
- package/dist/src/middleware/validate.js +45 -0
- package/dist/src/middleware/validate.js.map +1 -1
- package/dist/src/policy/engine.d.ts +4 -0
- package/dist/src/policy/engine.d.ts.map +1 -1
- package/dist/src/policy/engine.js +117 -0
- package/dist/src/policy/engine.js.map +1 -1
- package/dist/src/saas/routes.d.ts.map +1 -1
- package/dist/src/saas/routes.js +355 -22
- package/dist/src/saas/routes.js.map +1 -1
- package/dist/src/server/app.d.ts.map +1 -1
- package/dist/src/server/app.js +24 -3
- package/dist/src/server/app.js.map +1 -1
- package/dist/src/server/gateway.d.ts.map +1 -1
- package/dist/src/server/gateway.js +17 -0
- package/dist/src/server/gateway.js.map +1 -1
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +18 -0
- package/dist/src/server/index.js.map +1 -1
- package/dist/src/storage/interfaces.d.ts +14 -3
- package/dist/src/storage/interfaces.d.ts.map +1 -1
- package/dist/src/storage/memory.d.ts +2 -0
- package/dist/src/storage/memory.d.ts.map +1 -1
- package/dist/src/storage/memory.js +6 -0
- package/dist/src/storage/memory.js.map +1 -1
- package/dist/src/storage/postgres.d.ts +5 -0
- package/dist/src/storage/postgres.d.ts.map +1 -1
- package/dist/src/storage/postgres.js +16 -0
- package/dist/src/storage/postgres.js.map +1 -1
- package/dist/src/storage/redis.d.ts +10 -0
- package/dist/src/storage/redis.d.ts.map +1 -1
- package/dist/src/storage/redis.js +65 -0
- package/dist/src/storage/redis.js.map +1 -1
- package/dist/src/types/budget.d.ts +4 -0
- package/dist/src/types/budget.d.ts.map +1 -1
- package/dist/src/types/config.d.ts +58 -0
- package/dist/src/types/config.d.ts.map +1 -1
- package/dist/src/types/events.d.ts +1 -0
- package/dist/src/types/events.d.ts.map +1 -1
- package/dist/src/types/policy.d.ts +11 -1
- package/dist/src/types/policy.d.ts.map +1 -1
- package/dist/src/types/tool-result.d.ts +11 -0
- package/dist/src/types/tool-result.d.ts.map +1 -1
- package/dist/tests/unit/app-routes.test.d.ts +2 -0
- package/dist/tests/unit/app-routes.test.d.ts.map +1 -0
- package/dist/tests/unit/app-routes.test.js +715 -0
- package/dist/tests/unit/app-routes.test.js.map +1 -0
- package/dist/tests/unit/audit-logger.test.js +105 -0
- package/dist/tests/unit/audit-logger.test.js.map +1 -1
- package/dist/tests/unit/auth-providers.test.d.ts +2 -0
- package/dist/tests/unit/auth-providers.test.d.ts.map +1 -0
- package/dist/tests/unit/auth-providers.test.js +279 -0
- package/dist/tests/unit/auth-providers.test.js.map +1 -0
- package/dist/tests/unit/auth-routes-extended.test.d.ts +2 -0
- package/dist/tests/unit/auth-routes-extended.test.d.ts.map +1 -0
- package/dist/tests/unit/auth-routes-extended.test.js +993 -0
- package/dist/tests/unit/auth-routes-extended.test.js.map +1 -0
- package/dist/tests/unit/auth-verifier.test.d.ts +2 -0
- package/dist/tests/unit/auth-verifier.test.d.ts.map +1 -0
- package/dist/tests/unit/auth-verifier.test.js +505 -0
- package/dist/tests/unit/auth-verifier.test.js.map +1 -0
- package/dist/tests/unit/billing-routes.test.d.ts +2 -0
- package/dist/tests/unit/billing-routes.test.d.ts.map +1 -0
- package/dist/tests/unit/billing-routes.test.js +432 -0
- package/dist/tests/unit/billing-routes.test.js.map +1 -0
- package/dist/tests/unit/config-defaults.test.d.ts +2 -0
- package/dist/tests/unit/config-defaults.test.d.ts.map +1 -0
- package/dist/tests/unit/config-defaults.test.js +119 -0
- package/dist/tests/unit/config-defaults.test.js.map +1 -0
- package/dist/tests/unit/defaults.test.js +0 -10
- package/dist/tests/unit/defaults.test.js.map +1 -1
- package/dist/tests/unit/filesystem-executor.test.d.ts +2 -0
- package/dist/tests/unit/filesystem-executor.test.d.ts.map +1 -0
- package/dist/tests/unit/filesystem-executor.test.js +280 -0
- package/dist/tests/unit/filesystem-executor.test.js.map +1 -0
- package/dist/tests/unit/gateway-branches.test.d.ts +2 -0
- package/dist/tests/unit/gateway-branches.test.d.ts.map +1 -0
- package/dist/tests/unit/gateway-branches.test.js +1039 -0
- package/dist/tests/unit/gateway-branches.test.js.map +1 -0
- package/dist/tests/unit/http-executor-branches.test.d.ts +2 -0
- package/dist/tests/unit/http-executor-branches.test.d.ts.map +1 -0
- package/dist/tests/unit/http-executor-branches.test.js +495 -0
- package/dist/tests/unit/http-executor-branches.test.js.map +1 -0
- package/dist/tests/unit/logger.test.d.ts +2 -0
- package/dist/tests/unit/logger.test.d.ts.map +1 -0
- package/dist/tests/unit/logger.test.js +97 -0
- package/dist/tests/unit/logger.test.js.map +1 -0
- package/dist/tests/unit/mcp-internal-auth.test.d.ts +2 -0
- package/dist/tests/unit/mcp-internal-auth.test.d.ts.map +1 -0
- package/dist/tests/unit/mcp-internal-auth.test.js +445 -0
- package/dist/tests/unit/mcp-internal-auth.test.js.map +1 -0
- package/dist/tests/unit/metrics.test.js +102 -0
- package/dist/tests/unit/metrics.test.js.map +1 -1
- package/dist/tests/unit/model-pricing.test.d.ts +2 -0
- package/dist/tests/unit/model-pricing.test.d.ts.map +1 -0
- package/dist/tests/unit/model-pricing.test.js +87 -0
- package/dist/tests/unit/model-pricing.test.js.map +1 -0
- package/dist/tests/unit/oauth-stores.test.d.ts +2 -0
- package/dist/tests/unit/oauth-stores.test.d.ts.map +1 -0
- package/dist/tests/unit/oauth-stores.test.js +260 -0
- package/dist/tests/unit/oauth-stores.test.js.map +1 -0
- package/dist/tests/unit/policy-engine.test.js +466 -0
- package/dist/tests/unit/policy-engine.test.js.map +1 -1
- package/dist/tests/unit/provider-interceptor.test.d.ts +2 -0
- package/dist/tests/unit/provider-interceptor.test.d.ts.map +1 -0
- package/dist/tests/unit/provider-interceptor.test.js +472 -0
- package/dist/tests/unit/provider-interceptor.test.js.map +1 -0
- package/dist/tests/unit/saas-routes-branches.test.d.ts +2 -0
- package/dist/tests/unit/saas-routes-branches.test.d.ts.map +1 -0
- package/dist/tests/unit/saas-routes-branches.test.js +2165 -0
- package/dist/tests/unit/saas-routes-branches.test.js.map +1 -0
- package/dist/tests/unit/saas-routes-crud.test.d.ts +2 -0
- package/dist/tests/unit/saas-routes-crud.test.d.ts.map +1 -0
- package/dist/tests/unit/saas-routes-crud.test.js +332 -0
- package/dist/tests/unit/saas-routes-crud.test.js.map +1 -0
- package/dist/tests/unit/saas-routes-data.test.d.ts +2 -0
- package/dist/tests/unit/saas-routes-data.test.d.ts.map +1 -0
- package/dist/tests/unit/saas-routes-data.test.js +405 -0
- package/dist/tests/unit/saas-routes-data.test.js.map +1 -0
- package/dist/tests/unit/saas-routes.test.js +3 -3
- package/dist/tests/unit/saas-routes.test.js.map +1 -1
- package/dist/tests/unit/shell-executor.test.d.ts +2 -0
- package/dist/tests/unit/shell-executor.test.d.ts.map +1 -0
- package/dist/tests/unit/shell-executor.test.js +145 -0
- package/dist/tests/unit/shell-executor.test.js.map +1 -0
- package/dist/tests/unit/sql-executor.test.d.ts +2 -0
- package/dist/tests/unit/sql-executor.test.d.ts.map +1 -0
- package/dist/tests/unit/sql-executor.test.js +177 -0
- package/dist/tests/unit/sql-executor.test.js.map +1 -0
- package/dist/tests/unit/stream-proxy.test.d.ts +2 -0
- package/dist/tests/unit/stream-proxy.test.d.ts.map +1 -0
- package/dist/tests/unit/stream-proxy.test.js +147 -0
- package/dist/tests/unit/stream-proxy.test.js.map +1 -0
- package/dist/tests/unit/tool-definitions.test.d.ts +2 -0
- package/dist/tests/unit/tool-definitions.test.d.ts.map +1 -0
- package/dist/tests/unit/tool-definitions.test.js +184 -0
- package/dist/tests/unit/tool-definitions.test.js.map +1 -0
- package/dist/tests/unit/usage-extractor.test.js +140 -0
- package/dist/tests/unit/usage-extractor.test.js.map +1 -1
- package/dist/tests/unit/webhook-handler.test.d.ts +2 -0
- package/dist/tests/unit/webhook-handler.test.d.ts.map +1 -0
- package/dist/tests/unit/webhook-handler.test.js +453 -0
- package/dist/tests/unit/webhook-handler.test.js.map +1 -0
- package/dist/tests/unit/webhook-routes.test.d.ts +2 -0
- package/dist/tests/unit/webhook-routes.test.d.ts.map +1 -0
- package/dist/tests/unit/webhook-routes.test.js +69 -0
- package/dist/tests/unit/webhook-routes.test.js.map +1 -0
- package/dist/tests/unit/websocket-executor.test.d.ts +2 -0
- package/dist/tests/unit/websocket-executor.test.d.ts.map +1 -0
- package/dist/tests/unit/websocket-executor.test.js +121 -0
- package/dist/tests/unit/websocket-executor.test.js.map +1 -0
- package/package.json +8 -2
- package/policy-packs/demo_fail.yaml +41 -0
- package/policy-packs/full_tools.yaml +136 -0
- package/src/admin/index.ts +1 -0
- package/src/admin/routes.ts +509 -0
- package/src/admin/templates.ts +572 -0
- package/src/anomaly/detector.ts +730 -0
- package/src/anomaly/index.ts +1 -0
- package/src/approval/manager.ts +569 -0
- package/src/approval/webhook.ts +133 -0
- package/src/audit/logger.ts +490 -0
- package/src/auth/index.ts +5 -0
- package/src/auth/password.ts +21 -0
- package/src/auth/pkce.ts +22 -0
- package/src/auth/providers.ts +208 -0
- package/src/auth/routes.ts +561 -0
- package/src/auth/session.ts +84 -0
- package/src/billing/index.ts +6 -0
- package/src/billing/plan-enforcer.ts +135 -0
- package/src/billing/routes.ts +229 -0
- package/src/billing/stripe-client.ts +58 -0
- package/src/billing/webhook-handler.ts +182 -0
- package/src/billing/webhook-routes.ts +28 -0
- package/src/budget/manager.ts +679 -0
- package/src/budget/model-pricing.ts +119 -0
- package/src/budget/usage-extractor.ts +214 -0
- package/src/cli.ts +91 -0
- package/src/config/defaults.ts +261 -0
- package/src/config/validate.ts +88 -0
- package/src/dlp/composite-scanner.ts +213 -0
- package/src/dlp/index.ts +9 -0
- package/src/dlp/interfaces.ts +34 -0
- package/src/dlp/patterns.ts +30 -0
- package/src/dlp/prompt-injection-backend.ts +181 -0
- package/src/dlp/prompt-injection-patterns.ts +302 -0
- package/src/dlp/regex-backend.ts +181 -0
- package/src/dlp/scanner.ts +502 -0
- package/src/dlp/text-normalizer.ts +225 -0
- package/src/dlp/tool-patterns.ts +35 -0
- package/src/dlp/trufflehog-backend.ts +190 -0
- package/src/executor/filesystem-executor.ts +196 -0
- package/src/executor/http-executor.ts +349 -0
- package/src/executor/index.ts +9 -0
- package/src/executor/interfaces.ts +11 -0
- package/src/executor/noop-executor.ts +23 -0
- package/src/executor/registry.ts +64 -0
- package/src/executor/shell-executor.ts +148 -0
- package/src/executor/slack-executor.ts +176 -0
- package/src/executor/sql-executor.ts +146 -0
- package/src/executor/websocket-executor.ts +211 -0
- package/src/index.ts +24 -0
- package/src/interceptor/index.ts +1 -0
- package/src/interceptor/provider-interceptor.ts +315 -0
- package/src/mcp/auth-verifier.ts +152 -0
- package/src/mcp/bridge.ts +703 -0
- package/src/mcp/http-transport.ts +698 -0
- package/src/mcp/index.ts +9 -0
- package/src/mcp/internal-auth.ts +14 -0
- package/src/mcp/oauth-pages.ts +139 -0
- package/src/mcp/oauth-postgres-stores.ts +278 -0
- package/src/mcp/oauth-provider.ts +536 -0
- package/src/mcp/oauth-stores.ts +202 -0
- package/src/mcp/server.ts +55 -0
- package/src/mcp/tool-definitions.ts +562 -0
- package/src/metrics/collector.ts +357 -0
- package/src/metrics/index.ts +1 -0
- package/src/middleware/auth.ts +814 -0
- package/src/middleware/session.ts +85 -0
- package/src/middleware/validate.ts +130 -0
- package/src/policy/engine.ts +815 -0
- package/src/policy/index.ts +2 -0
- package/src/policy/opa-engine.ts +829 -0
- package/src/proxy/forward-proxy.ts +649 -0
- package/src/proxy/index.ts +1 -0
- package/src/ratelimit/limiter.ts +196 -0
- package/src/replay/engine.ts +142 -0
- package/src/replay/index.ts +1 -0
- package/src/saas/index.ts +1 -0
- package/src/saas/routes.ts +2178 -0
- package/src/server/app.ts +985 -0
- package/src/server/errors.ts +49 -0
- package/src/server/gateway.ts +1130 -0
- package/src/server/index.ts +307 -0
- package/src/server/logger.ts +255 -0
- package/src/server/stream-proxy.ts +202 -0
- package/src/storage/file-persistence.ts +315 -0
- package/src/storage/index.ts +4 -0
- package/src/storage/interfaces.ts +287 -0
- package/src/storage/memory.ts +686 -0
- package/src/storage/postgres.ts +1831 -0
- package/src/storage/redis.ts +835 -0
- package/src/tracing/index.ts +1 -0
- package/src/tracing/provider.ts +100 -0
- package/src/trust/calculator.ts +141 -0
- package/src/trust/index.ts +7 -0
- package/src/types/budget.ts +36 -0
- package/src/types/config.ts +278 -0
- package/src/types/events.ts +41 -0
- package/src/types/express.d.ts +14 -0
- package/src/types/index.ts +7 -0
- package/src/types/policy.ts +83 -0
- package/src/types/stripe-config.ts +11 -0
- package/src/types/subscription.ts +59 -0
- package/src/types/tool-call.ts +47 -0
- package/src/types/tool-result.ts +82 -0
- package/src/types/user.ts +125 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { BudgetState } from '../types/budget';
|
|
2
|
+
import { AuditEvent, EventType } from '../types/events';
|
|
3
|
+
import { PolicyPack } from '../types/policy';
|
|
4
|
+
import {
|
|
5
|
+
User,
|
|
6
|
+
OAuthAccount,
|
|
7
|
+
OAuthProvider,
|
|
8
|
+
Workspace,
|
|
9
|
+
WorkspaceMember,
|
|
10
|
+
Session,
|
|
11
|
+
UserApiKey,
|
|
12
|
+
} from '../types/user';
|
|
13
|
+
import { Subscription } from '../types/subscription';
|
|
14
|
+
|
|
15
|
+
import { ToolResult } from '../types/tool-result';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Record stored by the ApprovalStore. Mirrors the shape created by ApprovalManager.
|
|
19
|
+
*/
|
|
20
|
+
export interface ApprovalRecord {
|
|
21
|
+
approval_id: string;
|
|
22
|
+
tool_call_id: string;
|
|
23
|
+
task_id: string;
|
|
24
|
+
workspace_id: string;
|
|
25
|
+
actor_id: string;
|
|
26
|
+
requesting_api_key_id?: string;
|
|
27
|
+
tool_name: string;
|
|
28
|
+
tool_capability: string;
|
|
29
|
+
args_summary: string;
|
|
30
|
+
scope: string;
|
|
31
|
+
reason: string;
|
|
32
|
+
token_hash: string;
|
|
33
|
+
status: 'pending' | 'approved' | 'denied' | 'expired';
|
|
34
|
+
created_at: string;
|
|
35
|
+
expires_at: string;
|
|
36
|
+
resolved_at?: string;
|
|
37
|
+
resolved_by?: string;
|
|
38
|
+
denial_reason?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Storage interface for budget state.
|
|
43
|
+
* Implementations: InMemoryBudgetStore, PostgresBudgetStore, RedisBudgetStore
|
|
44
|
+
*/
|
|
45
|
+
export interface BudgetStore {
|
|
46
|
+
getTaskState(taskId: string): BudgetState | undefined;
|
|
47
|
+
setTaskState(taskId: string, state: BudgetState): void;
|
|
48
|
+
|
|
49
|
+
getCounter(key: string): number;
|
|
50
|
+
incrementCounter(key: string, amount: number): void;
|
|
51
|
+
|
|
52
|
+
getRetryCount(toolCallId: string): number;
|
|
53
|
+
incrementRetryCount(toolCallId: string): number;
|
|
54
|
+
|
|
55
|
+
/** Enumerate all task states (for BudgetManager hydration). */
|
|
56
|
+
getAllTaskStates?(): Map<string, BudgetState>;
|
|
57
|
+
/** Enumerate all counters (for BudgetManager hydration). */
|
|
58
|
+
getAllCounters?(): Map<string, number>;
|
|
59
|
+
/** Enumerate all retry counts (for BudgetManager hydration). */
|
|
60
|
+
getAllRetryCounts?(): Map<string, number>;
|
|
61
|
+
|
|
62
|
+
/** Wait for all pending async writes to complete. */
|
|
63
|
+
flush?(): Promise<void>;
|
|
64
|
+
|
|
65
|
+
reset(): void;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Storage interface for audit events.
|
|
70
|
+
* Implementations: InMemoryAuditStore, PostgresAuditStore, RedisAuditStore
|
|
71
|
+
*/
|
|
72
|
+
export interface AuditStore {
|
|
73
|
+
append(event: AuditEvent): void;
|
|
74
|
+
getByTaskId(taskId: string): AuditEvent[];
|
|
75
|
+
getByToolCallId(toolCallId: string): AuditEvent[];
|
|
76
|
+
getByEventType(eventType: EventType): AuditEvent[];
|
|
77
|
+
getAll(): AuditEvent[];
|
|
78
|
+
deleteByTaskId(taskId: string): void;
|
|
79
|
+
deleteBySessionId(sessionId: string): void;
|
|
80
|
+
clear(): void;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Storage interface for approval records.
|
|
85
|
+
* Implementations: InMemoryApprovalStore, PostgresApprovalStore, RedisApprovalStore
|
|
86
|
+
*/
|
|
87
|
+
export interface ApprovalStore {
|
|
88
|
+
save(approvalId: string, approval: ApprovalRecord): void;
|
|
89
|
+
getById(approvalId: string): ApprovalRecord | undefined;
|
|
90
|
+
/** Look up an approval by token hash (SHA-256 hex digest). */
|
|
91
|
+
getByToken(tokenHash: string): ApprovalRecord | undefined;
|
|
92
|
+
getByToolCallId(toolCallId: string): ApprovalRecord | undefined;
|
|
93
|
+
/** Find an approved approval for the given task + actor + tool combination. */
|
|
94
|
+
findApproved?(taskId: string, actorId: string, toolName: string, capability: string): ApprovalRecord | undefined;
|
|
95
|
+
findPending(workspaceId?: string): ApprovalRecord[];
|
|
96
|
+
/** Index a token hash to an approval ID for reverse lookup. */
|
|
97
|
+
indexToken(tokenHash: string, approvalId: string): void;
|
|
98
|
+
/**
|
|
99
|
+
* Atomically update an approval only if its current status matches expectedStatus.
|
|
100
|
+
* Returns true if the update succeeded, false if the status had already changed.
|
|
101
|
+
* Used to prevent race conditions where two concurrent callers both approve/deny.
|
|
102
|
+
*/
|
|
103
|
+
compareAndSetStatus?(approvalId: string, expectedStatus: string, approval: ApprovalRecord): boolean | Promise<boolean>;
|
|
104
|
+
/** Wait for all pending async writes to complete. */
|
|
105
|
+
flush?(): Promise<void>;
|
|
106
|
+
clear(): void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Storage interface for idempotency deduplication.
|
|
111
|
+
* Stores tool_call_id -> ToolResult mappings for dedup.
|
|
112
|
+
*/
|
|
113
|
+
export interface IdempotencyStore {
|
|
114
|
+
get(toolCallId: string): ToolResult | undefined | Promise<ToolResult | undefined>;
|
|
115
|
+
set(toolCallId: string, result: ToolResult, ttlMs: number): void;
|
|
116
|
+
has(toolCallId: string): boolean | Promise<boolean>;
|
|
117
|
+
/** Wait for all pending async writes to complete. */
|
|
118
|
+
flush?(): Promise<void>;
|
|
119
|
+
clear(): void;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Storage interface for rate limiting.
|
|
124
|
+
*/
|
|
125
|
+
export interface RateLimitStore {
|
|
126
|
+
/**
|
|
127
|
+
* Record a hit and check if the rate limit is exceeded.
|
|
128
|
+
* @param key - Rate limit key (e.g., "actor:agent-001" or "workspace:ws-001")
|
|
129
|
+
* @param windowMs - Time window in milliseconds
|
|
130
|
+
* @param maxRequests - Maximum requests allowed in the window
|
|
131
|
+
* @returns { allowed: boolean, current: number, limit: number, resetAt: number }
|
|
132
|
+
*/
|
|
133
|
+
hit(key: string, windowMs: number, maxRequests: number): {
|
|
134
|
+
allowed: boolean;
|
|
135
|
+
current: number;
|
|
136
|
+
limit: number;
|
|
137
|
+
resetAt: number;
|
|
138
|
+
};
|
|
139
|
+
/** Bulk-hydrate local cache from persistent backend (e.g. Redis). */
|
|
140
|
+
hydrateAll?(): Promise<void>;
|
|
141
|
+
reset(): void;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ---------------------------------------------------------------------------
|
|
145
|
+
// SaaS Store Interfaces
|
|
146
|
+
// ---------------------------------------------------------------------------
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Storage interface for user accounts.
|
|
150
|
+
*/
|
|
151
|
+
export interface UserStore {
|
|
152
|
+
create(user: User): void;
|
|
153
|
+
getById(id: string): User | undefined;
|
|
154
|
+
getByEmail(email: string): User | undefined;
|
|
155
|
+
update(id: string, updates: Partial<Pick<User, 'display_name' | 'avatar_url' | 'password_hash' | 'status' | 'onboarding_completed' | 'updated_at'>>): User | undefined;
|
|
156
|
+
delete(id: string): boolean;
|
|
157
|
+
list(): User[];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Storage interface for OAuth accounts (provider links).
|
|
162
|
+
*/
|
|
163
|
+
export interface OAuthAccountStore {
|
|
164
|
+
create(account: OAuthAccount): void;
|
|
165
|
+
getById(id: string): OAuthAccount | undefined;
|
|
166
|
+
getByProvider(provider: OAuthProvider, providerUserId: string): OAuthAccount | undefined;
|
|
167
|
+
getByUserId(userId: string): OAuthAccount[];
|
|
168
|
+
update(id: string, updates: Partial<Pick<OAuthAccount, 'access_token_encrypted' | 'refresh_token_encrypted' | 'token_expires_at' | 'updated_at'>>): OAuthAccount | undefined;
|
|
169
|
+
delete(id: string): boolean;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Storage interface for workspaces.
|
|
174
|
+
*/
|
|
175
|
+
export interface WorkspaceStore {
|
|
176
|
+
create(workspace: Workspace): void;
|
|
177
|
+
getById(id: string): Workspace | undefined;
|
|
178
|
+
getBySlug(slug: string): Workspace | undefined;
|
|
179
|
+
getByOwner(userId: string): Workspace[];
|
|
180
|
+
update(id: string, updates: Partial<Pick<Workspace, 'name' | 'slug' | 'plan' | 'settings' | 'updated_at'>>): Workspace | undefined;
|
|
181
|
+
delete(id: string): boolean;
|
|
182
|
+
list(): Workspace[];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Storage interface for workspace membership.
|
|
187
|
+
*/
|
|
188
|
+
export interface WorkspaceMemberStore {
|
|
189
|
+
create(member: WorkspaceMember): void;
|
|
190
|
+
getById(id: string): WorkspaceMember | undefined;
|
|
191
|
+
getByWorkspace(workspaceId: string): WorkspaceMember[];
|
|
192
|
+
getByUser(userId: string): WorkspaceMember[];
|
|
193
|
+
getByWorkspaceAndUser(workspaceId: string, userId: string): WorkspaceMember | undefined;
|
|
194
|
+
update(id: string, updates: Partial<Pick<WorkspaceMember, 'role'>>): WorkspaceMember | undefined;
|
|
195
|
+
delete(id: string): boolean;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Storage interface for sessions.
|
|
200
|
+
*/
|
|
201
|
+
export interface SessionStore {
|
|
202
|
+
create(session: Session): void;
|
|
203
|
+
getById(id: string): Session | undefined;
|
|
204
|
+
getByUserId(userId: string): Session[];
|
|
205
|
+
update(id: string, updates: Partial<Pick<Session, 'workspace_id' | 'last_active_at'>>): Session | undefined;
|
|
206
|
+
delete(id: string): boolean;
|
|
207
|
+
deleteExpired(): number;
|
|
208
|
+
deleteByUserId(userId: string): number;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Storage interface for user-generated API keys.
|
|
213
|
+
*/
|
|
214
|
+
export interface UserApiKeyStore {
|
|
215
|
+
create(apiKey: UserApiKey): void;
|
|
216
|
+
getById(id: string): UserApiKey | undefined;
|
|
217
|
+
getByKeyHash(keyHash: string): UserApiKey | undefined;
|
|
218
|
+
/** Verify a raw token against all stored keys (supports salted and unsalted hashes) */
|
|
219
|
+
verifyToken?(token: string): UserApiKey | undefined;
|
|
220
|
+
getByWorkspace(workspaceId: string): UserApiKey[];
|
|
221
|
+
getByUser(userId: string): UserApiKey[];
|
|
222
|
+
update(id: string, updates: Partial<Pick<UserApiKey, 'name' | 'roles' | 'tags' | 'revoked' | 'last_used_at'>>): UserApiKey | undefined;
|
|
223
|
+
delete(id: string): boolean;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Storage interface for subscriptions (Stripe billing).
|
|
228
|
+
*/
|
|
229
|
+
export interface SubscriptionStore {
|
|
230
|
+
create(subscription: Subscription): void;
|
|
231
|
+
getById(id: string): Subscription | undefined;
|
|
232
|
+
getByWorkspace(workspaceId: string): Subscription | undefined;
|
|
233
|
+
getByStripeCustomerId(customerId: string): Subscription | undefined;
|
|
234
|
+
getByStripeSubscriptionId(subscriptionId: string): Subscription | undefined;
|
|
235
|
+
update(id: string, updates: Partial<Subscription>): Subscription | undefined;
|
|
236
|
+
delete(id: string): boolean;
|
|
237
|
+
list(): Subscription[];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Storage interface for workspace policy packs.
|
|
242
|
+
*/
|
|
243
|
+
export interface PolicyStore {
|
|
244
|
+
getByWorkspaceId(workspaceId: string): PolicyPack | undefined;
|
|
245
|
+
set(workspaceId: string, policy: PolicyPack): void;
|
|
246
|
+
delete(workspaceId: string): boolean;
|
|
247
|
+
list(): Map<string, PolicyPack>;
|
|
248
|
+
clear(): void;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// ---------------------------------------------------------------------------
|
|
252
|
+
// Per-Workspace Rate Limit & Budget Configuration
|
|
253
|
+
// ---------------------------------------------------------------------------
|
|
254
|
+
|
|
255
|
+
export interface WorkspaceRateLimitConfig {
|
|
256
|
+
actor_max_per_window?: number;
|
|
257
|
+
workspace_max_per_window?: number;
|
|
258
|
+
window_ms?: number;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export interface WorkspaceBudgetConfig {
|
|
262
|
+
task_budget_usd?: number;
|
|
263
|
+
user_daily_budget_usd?: number;
|
|
264
|
+
user_monthly_budget_usd?: number;
|
|
265
|
+
workspace_daily_budget_usd?: number;
|
|
266
|
+
workspace_monthly_budget_usd?: number;
|
|
267
|
+
max_steps_per_task?: number;
|
|
268
|
+
max_retries_per_call?: number;
|
|
269
|
+
max_wall_clock_ms?: number;
|
|
270
|
+
token_pricing?: Record<string, import('../types/budget').TokenPricing>;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface RateLimitConfigStore {
|
|
274
|
+
getByWorkspaceId(workspaceId: string): WorkspaceRateLimitConfig | undefined;
|
|
275
|
+
set(workspaceId: string, config: WorkspaceRateLimitConfig): void;
|
|
276
|
+
delete(workspaceId: string): boolean;
|
|
277
|
+
list(): Map<string, WorkspaceRateLimitConfig>;
|
|
278
|
+
clear(): void;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface BudgetConfigStore {
|
|
282
|
+
getByWorkspaceId(workspaceId: string): WorkspaceBudgetConfig | undefined;
|
|
283
|
+
set(workspaceId: string, config: WorkspaceBudgetConfig): void;
|
|
284
|
+
delete(workspaceId: string): boolean;
|
|
285
|
+
list(): Map<string, WorkspaceBudgetConfig>;
|
|
286
|
+
clear(): void;
|
|
287
|
+
}
|