@dotsetlabs/tollgate 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 +885 -0
- package/dist/analyzers/filesystem.d.ts +26 -0
- package/dist/analyzers/filesystem.d.ts.map +1 -0
- package/dist/analyzers/filesystem.js +284 -0
- package/dist/analyzers/filesystem.js.map +1 -0
- package/dist/analyzers/http.d.ts +90 -0
- package/dist/analyzers/http.d.ts.map +1 -0
- package/dist/analyzers/http.js +433 -0
- package/dist/analyzers/http.js.map +1 -0
- package/dist/analyzers/index.d.ts +101 -0
- package/dist/analyzers/index.d.ts.map +1 -0
- package/dist/analyzers/index.js +342 -0
- package/dist/analyzers/index.js.map +1 -0
- package/dist/analyzers/loader.d.ts +114 -0
- package/dist/analyzers/loader.d.ts.map +1 -0
- package/dist/analyzers/loader.js +184 -0
- package/dist/analyzers/loader.js.map +1 -0
- package/dist/analyzers/prompt-injection.d.ts +95 -0
- package/dist/analyzers/prompt-injection.d.ts.map +1 -0
- package/dist/analyzers/prompt-injection.js +725 -0
- package/dist/analyzers/prompt-injection.js.map +1 -0
- package/dist/analyzers/sdk.d.ts +230 -0
- package/dist/analyzers/sdk.d.ts.map +1 -0
- package/dist/analyzers/sdk.js +283 -0
- package/dist/analyzers/sdk.js.map +1 -0
- package/dist/analyzers/shell.d.ts +20 -0
- package/dist/analyzers/shell.d.ts.map +1 -0
- package/dist/analyzers/shell.js +297 -0
- package/dist/analyzers/shell.js.map +1 -0
- package/dist/analyzers/sql.d.ts +37 -0
- package/dist/analyzers/sql.d.ts.map +1 -0
- package/dist/analyzers/sql.js +455 -0
- package/dist/analyzers/sql.js.map +1 -0
- package/dist/analyzers/types.d.ts +117 -0
- package/dist/analyzers/types.d.ts.map +1 -0
- package/dist/analyzers/types.js +46 -0
- package/dist/analyzers/types.js.map +1 -0
- package/dist/approval/interactive.d.ts +72 -0
- package/dist/approval/interactive.d.ts.map +1 -0
- package/dist/approval/interactive.js +550 -0
- package/dist/approval/interactive.js.map +1 -0
- package/dist/approval/terminal.d.ts +59 -0
- package/dist/approval/terminal.d.ts.map +1 -0
- package/dist/approval/terminal.js +238 -0
- package/dist/approval/terminal.js.map +1 -0
- package/dist/approval/types.d.ts +66 -0
- package/dist/approval/types.d.ts.map +1 -0
- package/dist/approval/types.js +2 -0
- package/dist/approval/types.js.map +1 -0
- package/dist/audit/exporter.d.ts +138 -0
- package/dist/audit/exporter.d.ts.map +1 -0
- package/dist/audit/exporter.js +366 -0
- package/dist/audit/exporter.js.map +1 -0
- package/dist/audit/logger.d.ts +156 -0
- package/dist/audit/logger.d.ts.map +1 -0
- package/dist/audit/logger.js +406 -0
- package/dist/audit/logger.js.map +1 -0
- package/dist/audit/redaction.d.ts +110 -0
- package/dist/audit/redaction.d.ts.map +1 -0
- package/dist/audit/redaction.js +307 -0
- package/dist/audit/redaction.js.map +1 -0
- package/dist/audit/schema.d.ts +76 -0
- package/dist/audit/schema.d.ts.map +1 -0
- package/dist/audit/schema.js +122 -0
- package/dist/audit/schema.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +34 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +431 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/export.d.ts +18 -0
- package/dist/cli/commands/export.d.ts.map +1 -0
- package/dist/cli/commands/export.js +63 -0
- package/dist/cli/commands/export.js.map +1 -0
- package/dist/cli/commands/init.d.ts +12 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +102 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/logs.d.ts +11 -0
- package/dist/cli/commands/logs.d.ts.map +1 -0
- package/dist/cli/commands/logs.js +60 -0
- package/dist/cli/commands/logs.js.map +1 -0
- package/dist/cli/commands/scan.d.ts +29 -0
- package/dist/cli/commands/scan.d.ts.map +1 -0
- package/dist/cli/commands/scan.js +251 -0
- package/dist/cli/commands/scan.js.map +1 -0
- package/dist/cli/commands/serve.d.ts +26 -0
- package/dist/cli/commands/serve.d.ts.map +1 -0
- package/dist/cli/commands/serve.js +424 -0
- package/dist/cli/commands/serve.js.map +1 -0
- package/dist/cli/commands/start.d.ts +20 -0
- package/dist/cli/commands/start.d.ts.map +1 -0
- package/dist/cli/commands/start.js +82 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/commands/stats.d.ts +10 -0
- package/dist/cli/commands/stats.d.ts.map +1 -0
- package/dist/cli/commands/stats.js +42 -0
- package/dist/cli/commands/stats.js.map +1 -0
- package/dist/cli/commands/templates.d.ts +26 -0
- package/dist/cli/commands/templates.d.ts.map +1 -0
- package/dist/cli/commands/templates.js +221 -0
- package/dist/cli/commands/templates.js.map +1 -0
- package/dist/cli/commands/validate.d.ts +12 -0
- package/dist/cli/commands/validate.d.ts.map +1 -0
- package/dist/cli/commands/validate.js +107 -0
- package/dist/cli/commands/validate.js.map +1 -0
- package/dist/cli/commands/wrap.d.ts +19 -0
- package/dist/cli/commands/wrap.d.ts.map +1 -0
- package/dist/cli/commands/wrap.js +59 -0
- package/dist/cli/commands/wrap.js.map +1 -0
- package/dist/cli/index.d.ts +17 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +202 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/ui.d.ts +139 -0
- package/dist/cli/ui.d.ts.map +1 -0
- package/dist/cli/ui.js +271 -0
- package/dist/cli/ui.js.map +1 -0
- package/dist/constants.d.ts +33 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +54 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors.d.ts +28 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +37 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/dist/orchestrator/index.d.ts +11 -0
- package/dist/orchestrator/index.d.ts.map +1 -0
- package/dist/orchestrator/index.js +10 -0
- package/dist/orchestrator/index.js.map +1 -0
- package/dist/orchestrator/manager.d.ts +127 -0
- package/dist/orchestrator/manager.d.ts.map +1 -0
- package/dist/orchestrator/manager.js +498 -0
- package/dist/orchestrator/manager.js.map +1 -0
- package/dist/orchestrator/types.d.ts +141 -0
- package/dist/orchestrator/types.d.ts.map +1 -0
- package/dist/orchestrator/types.js +9 -0
- package/dist/orchestrator/types.js.map +1 -0
- package/dist/policy/engine.d.ts +55 -0
- package/dist/policy/engine.d.ts.map +1 -0
- package/dist/policy/engine.js +288 -0
- package/dist/policy/engine.js.map +1 -0
- package/dist/policy/natural-language.d.ts +141 -0
- package/dist/policy/natural-language.d.ts.map +1 -0
- package/dist/policy/natural-language.js +552 -0
- package/dist/policy/natural-language.js.map +1 -0
- package/dist/policy/parser.d.ts +141 -0
- package/dist/policy/parser.d.ts.map +1 -0
- package/dist/policy/parser.js +314 -0
- package/dist/policy/parser.js.map +1 -0
- package/dist/policy/types.d.ts +428 -0
- package/dist/policy/types.d.ts.map +1 -0
- package/dist/policy/types.js +32 -0
- package/dist/policy/types.js.map +1 -0
- package/dist/policy/validator.d.ts +72 -0
- package/dist/policy/validator.d.ts.map +1 -0
- package/dist/policy/validator.js +453 -0
- package/dist/policy/validator.js.map +1 -0
- package/dist/proxy/bridge.d.ts +84 -0
- package/dist/proxy/bridge.d.ts.map +1 -0
- package/dist/proxy/bridge.js +217 -0
- package/dist/proxy/bridge.js.map +1 -0
- package/dist/proxy/client.d.ts +130 -0
- package/dist/proxy/client.d.ts.map +1 -0
- package/dist/proxy/client.js +290 -0
- package/dist/proxy/client.js.map +1 -0
- package/dist/proxy/server.d.ts +111 -0
- package/dist/proxy/server.d.ts.map +1 -0
- package/dist/proxy/server.js +444 -0
- package/dist/proxy/server.js.map +1 -0
- package/dist/scanner.d.ts +91 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +373 -0
- package/dist/scanner.js.map +1 -0
- package/dist/session/index.d.ts +32 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +31 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/manager.d.ts +166 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +454 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/session/sqlite-store.d.ts +54 -0
- package/dist/session/sqlite-store.d.ts.map +1 -0
- package/dist/session/sqlite-store.js +209 -0
- package/dist/session/sqlite-store.js.map +1 -0
- package/dist/session/types.d.ts +179 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +38 -0
- package/dist/session/types.js.map +1 -0
- package/dist/templates.d.ts +64 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +451 -0
- package/dist/templates.js.map +1 -0
- package/dist/utils/config.d.ts +57 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +104 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/errors.d.ts +18 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +35 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/logger.d.ts +144 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +300 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/wizard.d.ts +68 -0
- package/dist/wizard.d.ts.map +1 -0
- package/dist/wizard.js +395 -0
- package/dist/wizard.js.map +1 -0
- package/package.json +99 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite-backed Session Store for Tollgate
|
|
3
|
+
*
|
|
4
|
+
* Provides persistent session storage that survives process restarts.
|
|
5
|
+
* Uses the same database as the audit logger for consistency.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { SqliteSessionStore } from './sqlite-store.js';
|
|
10
|
+
* import { SessionManager } from './manager.js';
|
|
11
|
+
*
|
|
12
|
+
* const store = new SqliteSessionStore('./data/sessions.db');
|
|
13
|
+
* const manager = new SessionManager(store);
|
|
14
|
+
*
|
|
15
|
+
* // Sessions now persist across restarts
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import Database from 'better-sqlite3';
|
|
19
|
+
import { existsSync, mkdirSync } from 'node:fs';
|
|
20
|
+
import { dirname } from 'node:path';
|
|
21
|
+
import { sessionLogger as logger } from '../utils/logger.js';
|
|
22
|
+
// =============================================================================
|
|
23
|
+
// Schema
|
|
24
|
+
// =============================================================================
|
|
25
|
+
const SESSION_SCHEMA = `
|
|
26
|
+
CREATE TABLE IF NOT EXISTS session_grants (
|
|
27
|
+
id TEXT PRIMARY KEY,
|
|
28
|
+
created_at TEXT NOT NULL,
|
|
29
|
+
expires_at TEXT,
|
|
30
|
+
server TEXT NOT NULL,
|
|
31
|
+
scope TEXT NOT NULL,
|
|
32
|
+
scope_value TEXT,
|
|
33
|
+
tool TEXT,
|
|
34
|
+
granted_by TEXT NOT NULL,
|
|
35
|
+
usage_count INTEGER DEFAULT 0,
|
|
36
|
+
original_request_id TEXT
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
CREATE INDEX IF NOT EXISTS idx_session_grants_server ON session_grants(server);
|
|
40
|
+
CREATE INDEX IF NOT EXISTS idx_session_grants_expires ON session_grants(expires_at);
|
|
41
|
+
`;
|
|
42
|
+
// =============================================================================
|
|
43
|
+
// SQLite Session Store
|
|
44
|
+
// =============================================================================
|
|
45
|
+
/**
|
|
46
|
+
* SQLite-backed session store for persistent session grants.
|
|
47
|
+
*
|
|
48
|
+
* Features:
|
|
49
|
+
* - Sessions survive process restarts
|
|
50
|
+
* - Automatic cleanup of expired grants
|
|
51
|
+
* - Thread-safe via SQLite's locking
|
|
52
|
+
*/
|
|
53
|
+
export class SqliteSessionStore {
|
|
54
|
+
db;
|
|
55
|
+
insertStmt;
|
|
56
|
+
getStmt;
|
|
57
|
+
deleteStmt;
|
|
58
|
+
updateUsageStmt;
|
|
59
|
+
constructor(dbPath) {
|
|
60
|
+
// Ensure directory exists
|
|
61
|
+
const dir = dirname(dbPath);
|
|
62
|
+
if (!existsSync(dir)) {
|
|
63
|
+
mkdirSync(dir, { recursive: true });
|
|
64
|
+
}
|
|
65
|
+
this.db = new Database(dbPath);
|
|
66
|
+
this.db.pragma('journal_mode = WAL');
|
|
67
|
+
// Initialize schema
|
|
68
|
+
this.db.exec(SESSION_SCHEMA);
|
|
69
|
+
// Prepare statements
|
|
70
|
+
this.insertStmt = this.db.prepare(`
|
|
71
|
+
INSERT OR REPLACE INTO session_grants
|
|
72
|
+
(id, created_at, expires_at, server, scope, scope_value, tool, granted_by, usage_count, original_request_id)
|
|
73
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
74
|
+
`);
|
|
75
|
+
this.getStmt = this.db.prepare(`
|
|
76
|
+
SELECT * FROM session_grants WHERE id = ?
|
|
77
|
+
`);
|
|
78
|
+
this.deleteStmt = this.db.prepare(`
|
|
79
|
+
DELETE FROM session_grants WHERE id = ?
|
|
80
|
+
`);
|
|
81
|
+
this.updateUsageStmt = this.db.prepare(`
|
|
82
|
+
UPDATE session_grants SET usage_count = usage_count + 1 WHERE id = ?
|
|
83
|
+
`);
|
|
84
|
+
}
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
// SessionStore Interface
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
set(grant) {
|
|
89
|
+
this.insertStmt.run(grant.id, grant.createdAt.toISOString(), grant.expiresAt?.toISOString() ?? null, grant.server, grant.scope, grant.scopeValue ?? null, grant.tool ?? null, grant.grantedBy, grant.usageCount, grant.originalRequestId ?? null);
|
|
90
|
+
}
|
|
91
|
+
get(id) {
|
|
92
|
+
try {
|
|
93
|
+
const row = this.getStmt.get(id);
|
|
94
|
+
if (!row)
|
|
95
|
+
return undefined;
|
|
96
|
+
return this.rowToGrant(row);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
logger.error('Error getting grant', {
|
|
100
|
+
grantId: id,
|
|
101
|
+
error: error instanceof Error ? error.message : String(error),
|
|
102
|
+
});
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
findMatching(context) {
|
|
107
|
+
try {
|
|
108
|
+
const now = new Date().toISOString();
|
|
109
|
+
// Find all non-expired grants for this server
|
|
110
|
+
const stmt = this.db.prepare(`
|
|
111
|
+
SELECT * FROM session_grants
|
|
112
|
+
WHERE server = ?
|
|
113
|
+
AND (expires_at IS NULL OR expires_at > ?)
|
|
114
|
+
`);
|
|
115
|
+
const rows = stmt.all(context.server, now);
|
|
116
|
+
return rows.map((row) => this.rowToGrant(row));
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
logger.error('Error finding matching grants', {
|
|
120
|
+
server: context.server,
|
|
121
|
+
error: error instanceof Error ? error.message : String(error),
|
|
122
|
+
});
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
delete(id) {
|
|
127
|
+
const result = this.deleteStmt.run(id);
|
|
128
|
+
return result.changes > 0;
|
|
129
|
+
}
|
|
130
|
+
pruneExpired() {
|
|
131
|
+
const now = new Date().toISOString();
|
|
132
|
+
const stmt = this.db.prepare(`
|
|
133
|
+
DELETE FROM session_grants
|
|
134
|
+
WHERE expires_at IS NOT NULL AND expires_at <= ?
|
|
135
|
+
`);
|
|
136
|
+
const result = stmt.run(now);
|
|
137
|
+
return result.changes;
|
|
138
|
+
}
|
|
139
|
+
getAll() {
|
|
140
|
+
const stmt = this.db.prepare(`SELECT * FROM session_grants`);
|
|
141
|
+
const rows = stmt.all();
|
|
142
|
+
return rows.map((row) => this.rowToGrant(row));
|
|
143
|
+
}
|
|
144
|
+
clear() {
|
|
145
|
+
this.db.exec(`DELETE FROM session_grants`);
|
|
146
|
+
}
|
|
147
|
+
getStats() {
|
|
148
|
+
const now = new Date().toISOString();
|
|
149
|
+
const fiveMinutesFromNow = new Date(Date.now() + 5 * 60 * 1000).toISOString();
|
|
150
|
+
const statsStmt = this.db.prepare(`
|
|
151
|
+
SELECT
|
|
152
|
+
COUNT(*) as total,
|
|
153
|
+
SUM(CASE WHEN scope = 'exact' THEN 1 ELSE 0 END) as exact_count,
|
|
154
|
+
SUM(CASE WHEN scope = 'tool' THEN 1 ELSE 0 END) as tool_count,
|
|
155
|
+
SUM(CASE WHEN scope = 'server' THEN 1 ELSE 0 END) as server_count,
|
|
156
|
+
SUM(CASE WHEN scope = 'pattern' THEN 1 ELSE 0 END) as pattern_count,
|
|
157
|
+
COALESCE(SUM(usage_count), 0) as total_usage,
|
|
158
|
+
SUM(CASE WHEN expires_at IS NOT NULL AND expires_at <= ? THEN 1 ELSE 0 END) as expiring_soon
|
|
159
|
+
FROM session_grants
|
|
160
|
+
WHERE expires_at IS NULL OR expires_at > ?
|
|
161
|
+
`);
|
|
162
|
+
const result = statsStmt.get(fiveMinutesFromNow, now);
|
|
163
|
+
return {
|
|
164
|
+
activeGrants: result.total,
|
|
165
|
+
grantsByScope: {
|
|
166
|
+
exact: result.exact_count,
|
|
167
|
+
tool: result.tool_count,
|
|
168
|
+
server: result.server_count,
|
|
169
|
+
pattern: result.pattern_count,
|
|
170
|
+
},
|
|
171
|
+
totalUsage: result.total_usage,
|
|
172
|
+
expiringSoon: result.expiring_soon,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
// ---------------------------------------------------------------------------
|
|
176
|
+
// Additional Methods
|
|
177
|
+
// ---------------------------------------------------------------------------
|
|
178
|
+
/**
|
|
179
|
+
* Increment usage count for a grant.
|
|
180
|
+
* Called when a grant is used to authorize a tool call.
|
|
181
|
+
*/
|
|
182
|
+
incrementUsage(id) {
|
|
183
|
+
this.updateUsageStmt.run(id);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Close the database connection.
|
|
187
|
+
*/
|
|
188
|
+
close() {
|
|
189
|
+
this.db.close();
|
|
190
|
+
}
|
|
191
|
+
// ---------------------------------------------------------------------------
|
|
192
|
+
// Private Helpers
|
|
193
|
+
// ---------------------------------------------------------------------------
|
|
194
|
+
rowToGrant(row) {
|
|
195
|
+
return {
|
|
196
|
+
id: row.id,
|
|
197
|
+
createdAt: new Date(row.created_at),
|
|
198
|
+
expiresAt: row.expires_at ? new Date(row.expires_at) : null,
|
|
199
|
+
server: row.server,
|
|
200
|
+
scope: row.scope,
|
|
201
|
+
scopeValue: row.scope_value ?? undefined,
|
|
202
|
+
tool: row.tool ?? undefined,
|
|
203
|
+
grantedBy: row.granted_by,
|
|
204
|
+
usageCount: row.usage_count,
|
|
205
|
+
originalRequestId: row.original_request_id ?? undefined,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=sqlite-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-store.js","sourceRoot":"","sources":["../../src/session/sqlite-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,aAAa,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE7D,gFAAgF;AAChF,SAAS;AACT,gFAAgF;AAEhF,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;CAgBtB,CAAC;AAEF,gFAAgF;AAChF,uBAAuB;AACvB,gFAAgF;AAEhF;;;;;;;GAOG;AACH,MAAM,OAAO,kBAAkB;IACrB,EAAE,CAAoB;IACtB,UAAU,CAAqB;IAC/B,OAAO,CAAqB;IAC5B,UAAU,CAAqB;IAC/B,eAAe,CAAqB;IAE5C,YAAY,MAAc;QACxB,0BAA0B;QAC1B,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CA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;gBACzB,IAAI,EAAE,MAAM,CAAC,UAAU;gBACvB,MAAM,EAAE,MAAM,CAAC,YAAY;gBAC3B,OAAO,EAAE,MAAM,CAAC,aAAa;aAC9B;YACD,UAAU,EAAE,MAAM,CAAC,WAAW;YAC9B,YAAY,EAAE,MAAM,CAAC,aAAa;SACnC,CAAC;IACJ,CAAC;IAED,8EAA8E;IAC9E,qBAAqB;IACrB,8EAA8E;IAE9E;;;OAGG;IACH,cAAc,CAAC,EAAU;QACvB,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;IAED,8EAA8E;IAC9E,kBAAkB;IAClB,8EAA8E;IAEtE,UAAU,CAAC,GAAoB;QACrC,OAAO;YACL,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,SAAS,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC;YACnC,SAAS,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI;YAC3D,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,KAAK,EAAE,GAAG,CAAC,KAAqB;YAChC,UAAU,EAAE,GAAG,CAAC,WAAW,IAAI,SAAS;YACxC,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,SAAS;YAC3B,SAAS,EAAE,GAAG,CAAC,UAA4C;YAC3D,UAAU,EAAE,GAAG,CAAC,WAAW;YAC3B,iBAAiB,EAAE,GAAG,CAAC,mBAAmB,IAAI,SAAS;SACxD,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-based approval types for Tollgate
|
|
3
|
+
*
|
|
4
|
+
* Sessions allow users to grant time-bounded approval for tool calls,
|
|
5
|
+
* reducing approval fatigue while maintaining security through:
|
|
6
|
+
* - Time-limited grants (TTL)
|
|
7
|
+
* - Scoped permissions (exact, tool, server, pattern)
|
|
8
|
+
* - Full audit trail
|
|
9
|
+
*/
|
|
10
|
+
import type { ToolCallContext } from '../policy/types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Scope determines what future tool calls a session grant covers.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // 'exact' - Only this exact tool with these exact arguments
|
|
16
|
+
* // User approves: postgres:query with args { sql: "SELECT * FROM users" }
|
|
17
|
+
* // Matches: postgres:query with args { sql: "SELECT * FROM users" }
|
|
18
|
+
* // Does NOT match: postgres:query with args { sql: "SELECT * FROM orders" }
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // 'tool' - Any call to this tool on this server
|
|
22
|
+
* // User approves: postgres:query
|
|
23
|
+
* // Matches: postgres:query with ANY args
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // 'server' - Any tool call on this server
|
|
27
|
+
* // User approves: postgres
|
|
28
|
+
* // Matches: postgres:query, postgres:execute, postgres:list_tables, etc.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // 'pattern' - Tools matching a glob pattern on this server
|
|
32
|
+
* // User approves: postgres with pattern "read_*"
|
|
33
|
+
* // Matches: postgres:read_file, postgres:read_config
|
|
34
|
+
* // Does NOT match: postgres:write_file
|
|
35
|
+
*/
|
|
36
|
+
export type SessionScope = 'exact' | 'tool' | 'server' | 'pattern';
|
|
37
|
+
/**
|
|
38
|
+
* Predefined session durations for terminal UI.
|
|
39
|
+
* Users can select these via keyboard shortcuts.
|
|
40
|
+
*/
|
|
41
|
+
export type SessionDuration = 'once' | '5min' | '15min' | '30min' | 'session';
|
|
42
|
+
/**
|
|
43
|
+
* Converts a SessionDuration to TTL in seconds.
|
|
44
|
+
* 'session' returns -1 to indicate "until restart".
|
|
45
|
+
*/
|
|
46
|
+
export declare function durationToTtlSeconds(duration: SessionDuration): number;
|
|
47
|
+
/**
|
|
48
|
+
* A session grant represents a time-bounded approval for future tool calls.
|
|
49
|
+
*
|
|
50
|
+
* When a user approves a tool call, they can optionally grant a session
|
|
51
|
+
* that allows similar future calls without re-prompting.
|
|
52
|
+
*/
|
|
53
|
+
export interface SessionGrant {
|
|
54
|
+
/** Unique identifier for this grant */
|
|
55
|
+
readonly id: string;
|
|
56
|
+
/** When the grant was created */
|
|
57
|
+
readonly createdAt: Date;
|
|
58
|
+
/** When the grant expires (null = session lifetime) */
|
|
59
|
+
readonly expiresAt: Date | null;
|
|
60
|
+
/** Server this grant applies to */
|
|
61
|
+
readonly server: string;
|
|
62
|
+
/** Scope of the grant */
|
|
63
|
+
readonly scope: SessionScope;
|
|
64
|
+
/**
|
|
65
|
+
* Scope-specific value:
|
|
66
|
+
* - 'exact': JSON-stringified args
|
|
67
|
+
* - 'tool': tool name
|
|
68
|
+
* - 'server': undefined
|
|
69
|
+
* - 'pattern': glob pattern
|
|
70
|
+
*/
|
|
71
|
+
readonly scopeValue?: string;
|
|
72
|
+
/** Tool name (for 'exact' and 'tool' scopes) */
|
|
73
|
+
readonly tool?: string;
|
|
74
|
+
/** How this grant was created */
|
|
75
|
+
readonly grantedBy: 'terminal' | 'webhook' | 'api';
|
|
76
|
+
/** Number of times this grant has been used */
|
|
77
|
+
usageCount: number;
|
|
78
|
+
/** Original request that triggered this grant (for audit) */
|
|
79
|
+
readonly originalRequestId?: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Input for creating a new session grant.
|
|
83
|
+
*/
|
|
84
|
+
export interface CreateSessionGrantInput {
|
|
85
|
+
/** The tool call context that triggered approval */
|
|
86
|
+
context: ToolCallContext;
|
|
87
|
+
/** Scope of the grant */
|
|
88
|
+
scope: SessionScope;
|
|
89
|
+
/** Duration of the grant */
|
|
90
|
+
duration: SessionDuration;
|
|
91
|
+
/** How the grant was created */
|
|
92
|
+
grantedBy: 'terminal' | 'webhook' | 'api';
|
|
93
|
+
/** Pattern for 'pattern' scope */
|
|
94
|
+
pattern?: string;
|
|
95
|
+
/** ID of the original approval request (for audit linkage) */
|
|
96
|
+
originalRequestId?: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Result of checking if a session grant covers a tool call.
|
|
100
|
+
*/
|
|
101
|
+
export interface SessionCheckResult {
|
|
102
|
+
/** Whether a valid grant exists */
|
|
103
|
+
readonly granted: boolean;
|
|
104
|
+
/** The grant that covers this call (if granted) */
|
|
105
|
+
readonly grant?: SessionGrant;
|
|
106
|
+
/** Why the check failed (if not granted) */
|
|
107
|
+
readonly reason?: 'no_grant' | 'expired' | 'scope_mismatch';
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Configuration for session behavior in a tool policy.
|
|
111
|
+
* Enhanced from the original SessionConfig in policy/types.ts.
|
|
112
|
+
*/
|
|
113
|
+
export interface SessionPolicyConfig {
|
|
114
|
+
/**
|
|
115
|
+
* Whether to offer session options when prompting.
|
|
116
|
+
* @default true
|
|
117
|
+
*/
|
|
118
|
+
allowRemember?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Default scope when user doesn't specify.
|
|
121
|
+
* @default 'tool'
|
|
122
|
+
*/
|
|
123
|
+
defaultScope?: SessionScope;
|
|
124
|
+
/**
|
|
125
|
+
* Maximum TTL in seconds that can be granted.
|
|
126
|
+
* @default 1800 (30 minutes)
|
|
127
|
+
*/
|
|
128
|
+
maxTtl?: number;
|
|
129
|
+
/**
|
|
130
|
+
* Allowed durations to show in terminal UI.
|
|
131
|
+
* @default ['once', '5min', '15min', 'session']
|
|
132
|
+
*/
|
|
133
|
+
allowedDurations?: SessionDuration[];
|
|
134
|
+
/**
|
|
135
|
+
* Whether to persist grants to disk (survives restart).
|
|
136
|
+
* @default false
|
|
137
|
+
*/
|
|
138
|
+
persist?: boolean;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Default session policy configuration.
|
|
142
|
+
*/
|
|
143
|
+
export declare const DEFAULT_SESSION_CONFIG: Required<SessionPolicyConfig>;
|
|
144
|
+
/**
|
|
145
|
+
* Statistics about session usage.
|
|
146
|
+
*/
|
|
147
|
+
export interface SessionStats {
|
|
148
|
+
/** Total active grants */
|
|
149
|
+
activeGrants: number;
|
|
150
|
+
/** Grants by scope */
|
|
151
|
+
grantsByScope: Record<SessionScope, number>;
|
|
152
|
+
/** Total tool calls authorized via session */
|
|
153
|
+
totalUsage: number;
|
|
154
|
+
/** Grants expiring in the next 5 minutes */
|
|
155
|
+
expiringSoon: number;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Interface for session storage backends.
|
|
159
|
+
* Allows for in-memory or persistent storage.
|
|
160
|
+
*/
|
|
161
|
+
export interface SessionStore {
|
|
162
|
+
/** Store a new grant */
|
|
163
|
+
set(grant: SessionGrant): void;
|
|
164
|
+
/** Get a grant by ID */
|
|
165
|
+
get(id: string): SessionGrant | undefined;
|
|
166
|
+
/** Find grants that might match a context */
|
|
167
|
+
findMatching(context: ToolCallContext): SessionGrant[];
|
|
168
|
+
/** Remove a grant */
|
|
169
|
+
delete(id: string): boolean;
|
|
170
|
+
/** Remove all expired grants */
|
|
171
|
+
pruneExpired(): number;
|
|
172
|
+
/** Get all active grants */
|
|
173
|
+
getAll(): SessionGrant[];
|
|
174
|
+
/** Clear all grants */
|
|
175
|
+
clear(): void;
|
|
176
|
+
/** Get statistics */
|
|
177
|
+
getStats(): SessionStats;
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/session/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GA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AC;IAE5B,gCAAgC;IAChC,YAAY,IAAI,MAAM,CAAC;IAEvB,4BAA4B;IAC5B,MAAM,IAAI,YAAY,EAAE,CAAC;IAEzB,uBAAuB;IACvB,KAAK,IAAI,IAAI,CAAC;IAEd,qBAAqB;IACrB,QAAQ,IAAI,YAAY,CAAC;CAC1B"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-based approval types for Tollgate
|
|
3
|
+
*
|
|
4
|
+
* Sessions allow users to grant time-bounded approval for tool calls,
|
|
5
|
+
* reducing approval fatigue while maintaining security through:
|
|
6
|
+
* - Time-limited grants (TTL)
|
|
7
|
+
* - Scoped permissions (exact, tool, server, pattern)
|
|
8
|
+
* - Full audit trail
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Converts a SessionDuration to TTL in seconds.
|
|
12
|
+
* 'session' returns -1 to indicate "until restart".
|
|
13
|
+
*/
|
|
14
|
+
export function durationToTtlSeconds(duration) {
|
|
15
|
+
switch (duration) {
|
|
16
|
+
case 'once':
|
|
17
|
+
return 0;
|
|
18
|
+
case '5min':
|
|
19
|
+
return 5 * 60;
|
|
20
|
+
case '15min':
|
|
21
|
+
return 15 * 60;
|
|
22
|
+
case '30min':
|
|
23
|
+
return 30 * 60;
|
|
24
|
+
case 'session':
|
|
25
|
+
return -1; // Special value: no expiry until restart
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Default session policy configuration.
|
|
30
|
+
*/
|
|
31
|
+
export const DEFAULT_SESSION_CONFIG = {
|
|
32
|
+
allowRemember: true,
|
|
33
|
+
defaultScope: 'tool',
|
|
34
|
+
maxTtl: 30 * 60, // 30 minutes
|
|
35
|
+
allowedDurations: ['once', '5min', '15min', 'session'],
|
|
36
|
+
persist: false,
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/session/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA0CH;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAyB;IAC5D,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,MAAM;YACT,OAAO,CAAC,CAAC;QACX,KAAK,MAAM;YACT,OAAO,CAAC,GAAG,EAAE,CAAC;QAChB,KAAK,OAAO;YACV,OAAO,EAAE,GAAG,EAAE,CAAC;QACjB,KAAK,OAAO;YACV,OAAO,EAAE,GAAG,EAAE,CAAC;QACjB,KAAK,SAAS;YACZ,OAAO,CAAC,CAAC,CAAC,CAAC,yCAAyC;IACxD,CAAC;AACH,CAAC;AAuHD;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAkC;IACnE,aAAa,EAAE,IAAI;IACnB,YAAY,EAAE,MAAM;IACpB,MAAM,EAAE,EAAE,GAAG,EAAE,EAAE,aAAa;IAC9B,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC;IACtD,OAAO,EAAE,KAAK;CACf,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server Templates Library for Tollgate
|
|
3
|
+
*
|
|
4
|
+
* Extended collection of MCP server templates for quick configuration.
|
|
5
|
+
* These templates provide recommended policies for popular MCP servers.
|
|
6
|
+
*
|
|
7
|
+
* Usage via CLI:
|
|
8
|
+
* tollgate templates list # List all available templates
|
|
9
|
+
* tollgate templates show <name> # Show template details
|
|
10
|
+
* tollgate templates apply <name> # Add template to tollgate.yaml
|
|
11
|
+
*
|
|
12
|
+
* @module templates
|
|
13
|
+
*/
|
|
14
|
+
import type { ServerTemplate } from './wizard.js';
|
|
15
|
+
/**
|
|
16
|
+
* Template categories for organization.
|
|
17
|
+
*/
|
|
18
|
+
export type TemplateCategory = 'database' | 'filesystem' | 'web' | 'productivity' | 'developer' | 'ai' | 'communication';
|
|
19
|
+
/**
|
|
20
|
+
* Extended template with category and tags.
|
|
21
|
+
*/
|
|
22
|
+
export interface ExtendedTemplate extends ServerTemplate {
|
|
23
|
+
/** Category for grouping */
|
|
24
|
+
category: TemplateCategory;
|
|
25
|
+
/** Searchable tags */
|
|
26
|
+
tags: string[];
|
|
27
|
+
/** URL to MCP server documentation */
|
|
28
|
+
docsUrl?: string;
|
|
29
|
+
/** Whether the template has been verified/tested */
|
|
30
|
+
verified: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Complete template library.
|
|
34
|
+
*/
|
|
35
|
+
export declare const TEMPLATE_LIBRARY: ExtendedTemplate[];
|
|
36
|
+
/**
|
|
37
|
+
* Get all templates.
|
|
38
|
+
*/
|
|
39
|
+
export declare function getAllTemplates(): ExtendedTemplate[];
|
|
40
|
+
/**
|
|
41
|
+
* Get templates by category.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getTemplatesByCategory(category: TemplateCategory): ExtendedTemplate[];
|
|
44
|
+
/**
|
|
45
|
+
* Get template by name.
|
|
46
|
+
*/
|
|
47
|
+
export declare function getTemplateByName(name: string): ExtendedTemplate | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Search templates by keyword.
|
|
50
|
+
*/
|
|
51
|
+
export declare function searchTemplates(query: string): ExtendedTemplate[];
|
|
52
|
+
/**
|
|
53
|
+
* Get unique categories.
|
|
54
|
+
*/
|
|
55
|
+
export declare function getCategories(): TemplateCategory[];
|
|
56
|
+
/**
|
|
57
|
+
* Generate YAML configuration for a template.
|
|
58
|
+
*/
|
|
59
|
+
export declare function generateTemplateYaml(template: ExtendedTemplate, policyPreset?: 'strict' | 'balanced' | 'permissive'): string;
|
|
60
|
+
/**
|
|
61
|
+
* Generate full config file from multiple templates.
|
|
62
|
+
*/
|
|
63
|
+
export declare function generateFullConfig(templateNames: string[], policyPreset?: 'strict' | 'balanced' | 'permissive'): string;
|
|
64
|
+
//# sourceMappingURL=templates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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