@commandgarden/cli 1.1.0 → 1.1.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/dist/main.js +12343 -101
- package/node_modules/@commandgarden/app/dist/client/assets/index-58UrF1aG.js +197 -0
- package/node_modules/@commandgarden/app/dist/client/assets/index-DErcb2Kp.css +1 -0
- package/node_modules/@commandgarden/app/dist/client/index.html +19 -0
- package/node_modules/@commandgarden/app/dist/server/daemon-client.js +61 -0
- package/node_modules/@commandgarden/app/dist/server/main.js +63 -0
- package/node_modules/@commandgarden/app/dist/server/routes/audit.js +20 -0
- package/node_modules/@commandgarden/app/dist/server/routes/config.js +13 -0
- package/node_modules/@commandgarden/app/dist/server/routes/connectors.js +35 -0
- package/node_modules/@commandgarden/app/dist/server/routes/index.js +14 -0
- package/node_modules/@commandgarden/app/dist/server/routes/preferences.js +32 -0
- package/node_modules/@commandgarden/app/dist/server/routes/run.js +46 -0
- package/node_modules/@commandgarden/app/dist/server/routes/status.js +11 -0
- package/node_modules/@commandgarden/app/dist/server/store.js +55 -0
- package/node_modules/@commandgarden/app/package.json +42 -0
- package/node_modules/@commandgarden/daemon/dist/audit-store.d.ts +18 -0
- package/node_modules/@commandgarden/daemon/dist/audit-store.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/audit-store.js +97 -0
- package/node_modules/@commandgarden/daemon/dist/audit-store.js.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/auth.d.ts +5 -0
- package/node_modules/@commandgarden/daemon/dist/auth.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/auth.js +27 -0
- package/node_modules/@commandgarden/daemon/dist/auth.js.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/config.d.ts +109 -0
- package/node_modules/@commandgarden/daemon/dist/config.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/config.js +45 -0
- package/node_modules/@commandgarden/daemon/dist/config.js.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/main.d.ts +2 -0
- package/node_modules/@commandgarden/daemon/dist/main.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/main.js +58 -0
- package/node_modules/@commandgarden/daemon/dist/main.js.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/registry.d.ts +21 -0
- package/node_modules/@commandgarden/daemon/dist/registry.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/registry.js +70 -0
- package/node_modules/@commandgarden/daemon/dist/registry.js.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/server.d.ts +15 -0
- package/node_modules/@commandgarden/daemon/dist/server.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/server.js +336 -0
- package/node_modules/@commandgarden/daemon/dist/server.js.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/sse-manager.d.ts +10 -0
- package/node_modules/@commandgarden/daemon/dist/sse-manager.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/sse-manager.js +37 -0
- package/node_modules/@commandgarden/daemon/dist/sse-manager.js.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/validator.d.ts +10 -0
- package/node_modules/@commandgarden/daemon/dist/validator.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/validator.js +19 -0
- package/node_modules/@commandgarden/daemon/dist/validator.js.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/ws-relay.d.ts +30 -0
- package/node_modules/@commandgarden/daemon/dist/ws-relay.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/ws-relay.js +111 -0
- package/node_modules/@commandgarden/daemon/dist/ws-relay.js.map +1 -0
- package/node_modules/@commandgarden/daemon/package.json +30 -0
- package/node_modules/@commandgarden/shared/dist/capabilities.d.ts +7 -0
- package/node_modules/@commandgarden/shared/dist/capabilities.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/capabilities.js +23 -0
- package/node_modules/@commandgarden/shared/dist/capabilities.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/connector.d.ts +377 -0
- package/node_modules/@commandgarden/shared/dist/connector.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/connector.js +29 -0
- package/node_modules/@commandgarden/shared/dist/connector.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/events.d.ts +33 -0
- package/node_modules/@commandgarden/shared/dist/events.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/events.js +34 -0
- package/node_modules/@commandgarden/shared/dist/events.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/evaluator.d.ts +8 -0
- package/node_modules/@commandgarden/shared/dist/expression/evaluator.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/evaluator.js +49 -0
- package/node_modules/@commandgarden/shared/dist/expression/evaluator.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/filters.d.ts +3 -0
- package/node_modules/@commandgarden/shared/dist/expression/filters.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/filters.js +8 -0
- package/node_modules/@commandgarden/shared/dist/expression/filters.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/index.d.ts +5 -0
- package/node_modules/@commandgarden/shared/dist/expression/index.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/index.js +5 -0
- package/node_modules/@commandgarden/shared/dist/expression/index.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/parser.d.ts +22 -0
- package/node_modules/@commandgarden/shared/dist/expression/parser.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/parser.js +85 -0
- package/node_modules/@commandgarden/shared/dist/expression/parser.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/tokenizer.d.ts +7 -0
- package/node_modules/@commandgarden/shared/dist/expression/tokenizer.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/tokenizer.js +76 -0
- package/node_modules/@commandgarden/shared/dist/expression/tokenizer.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/index.d.ts +8 -0
- package/node_modules/@commandgarden/shared/dist/index.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/index.js +15 -0
- package/node_modules/@commandgarden/shared/dist/index.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/loader.d.ts +17 -0
- package/node_modules/@commandgarden/shared/dist/loader.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/loader.js +76 -0
- package/node_modules/@commandgarden/shared/dist/loader.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/pipeline.d.ts +339 -0
- package/node_modules/@commandgarden/shared/dist/pipeline.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/pipeline.js +97 -0
- package/node_modules/@commandgarden/shared/dist/pipeline.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/protocol.d.ts +58 -0
- package/node_modules/@commandgarden/shared/dist/protocol.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/protocol.js +26 -0
- package/node_modules/@commandgarden/shared/dist/protocol.js.map +1 -0
- package/node_modules/@commandgarden/shared/package.json +32 -0
- package/package.json +55 -42
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// src/audit-store.ts
|
|
2
|
+
import Database from 'better-sqlite3';
|
|
3
|
+
import { chmodSync } from 'node:fs';
|
|
4
|
+
export class AuditStore {
|
|
5
|
+
db;
|
|
6
|
+
constructor(dbPath) {
|
|
7
|
+
this.db = new Database(dbPath);
|
|
8
|
+
this.db.pragma('journal_mode = WAL');
|
|
9
|
+
this.db.exec(`CREATE TABLE IF NOT EXISTS audit_events (
|
|
10
|
+
id TEXT PRIMARY KEY, timestamp TEXT NOT NULL, type TEXT NOT NULL,
|
|
11
|
+
user TEXT NOT NULL, connector TEXT NOT NULL, args TEXT NOT NULL,
|
|
12
|
+
domains TEXT NOT NULL, capabilities TEXT NOT NULL, row_count INTEGER,
|
|
13
|
+
columns TEXT, duration_ms INTEGER NOT NULL, error TEXT, denial_reason TEXT
|
|
14
|
+
)`);
|
|
15
|
+
this.migrate();
|
|
16
|
+
if (dbPath !== ':memory:') {
|
|
17
|
+
try {
|
|
18
|
+
chmodSync(dbPath, 0o600);
|
|
19
|
+
}
|
|
20
|
+
catch { /* ignore for read-only fs */ }
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
migrate() {
|
|
24
|
+
const cols = new Set(this.db.pragma('table_info(audit_events)').map(c => c.name));
|
|
25
|
+
const additions = [
|
|
26
|
+
['correlation_id', 'TEXT'],
|
|
27
|
+
['connector_hash', 'TEXT'],
|
|
28
|
+
['steps', 'TEXT'],
|
|
29
|
+
['source', 'TEXT'],
|
|
30
|
+
['previous_value', 'TEXT'],
|
|
31
|
+
['new_value', 'TEXT'],
|
|
32
|
+
];
|
|
33
|
+
for (const [name, type] of additions) {
|
|
34
|
+
if (!cols.has(name)) {
|
|
35
|
+
this.db.exec(`ALTER TABLE audit_events ADD COLUMN ${name} ${type}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
insert(event) {
|
|
40
|
+
this.db.prepare(`INSERT INTO audit_events (id, timestamp, type, user, connector, args, domains,
|
|
41
|
+
capabilities, row_count, columns, duration_ms, error, denial_reason,
|
|
42
|
+
correlation_id, connector_hash, steps, source, previous_value, new_value)
|
|
43
|
+
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`).run(event.id, event.timestamp, event.type, event.user, event.connector, JSON.stringify(event.args), JSON.stringify(event.domains), JSON.stringify(event.capabilities), event.rowCount ?? null, event.columns ? JSON.stringify(event.columns) : null, event.durationMs, event.error ?? null, event.denialReason ?? null, event.correlationId ?? null, event.connectorHash ?? null, event.steps ? JSON.stringify(event.steps) : null, event.source ?? null, event.previousValue ?? null, event.newValue ?? null);
|
|
44
|
+
}
|
|
45
|
+
list(opts) {
|
|
46
|
+
let sql = 'SELECT * FROM audit_events WHERE 1=1';
|
|
47
|
+
const params = [];
|
|
48
|
+
if (opts?.connector) {
|
|
49
|
+
sql += ' AND connector LIKE ?';
|
|
50
|
+
params.push(opts.connector.replace('*', '%'));
|
|
51
|
+
}
|
|
52
|
+
if (opts?.type) {
|
|
53
|
+
sql += ' AND type LIKE ?';
|
|
54
|
+
params.push(opts.type.replace('*', '%'));
|
|
55
|
+
}
|
|
56
|
+
if (opts?.since) {
|
|
57
|
+
sql += ' AND timestamp >= ?';
|
|
58
|
+
params.push(opts.since.toISOString());
|
|
59
|
+
}
|
|
60
|
+
sql += ' ORDER BY timestamp DESC';
|
|
61
|
+
if (opts?.limit) {
|
|
62
|
+
sql += ' LIMIT ?';
|
|
63
|
+
params.push(opts.limit);
|
|
64
|
+
}
|
|
65
|
+
return this.db.prepare(sql).all(...params).map(r => this.toEvent(r));
|
|
66
|
+
}
|
|
67
|
+
getById(id) {
|
|
68
|
+
const row = this.db.prepare('SELECT * FROM audit_events WHERE id = ?').get(id);
|
|
69
|
+
return row ? this.toEvent(row) : undefined;
|
|
70
|
+
}
|
|
71
|
+
prune(retentionDays) {
|
|
72
|
+
const cutoff = new Date(Date.now() - retentionDays * 86_400_000).toISOString();
|
|
73
|
+
return this.db.prepare('DELETE FROM audit_events WHERE timestamp < ?').run(cutoff).changes;
|
|
74
|
+
}
|
|
75
|
+
close() { this.db.close(); }
|
|
76
|
+
toEvent(r) {
|
|
77
|
+
return {
|
|
78
|
+
id: r.id, timestamp: r.timestamp,
|
|
79
|
+
type: r.type, user: r.user,
|
|
80
|
+
connector: r.connector,
|
|
81
|
+
args: JSON.parse(r.args), domains: JSON.parse(r.domains),
|
|
82
|
+
capabilities: JSON.parse(r.capabilities),
|
|
83
|
+
rowCount: r.row_count,
|
|
84
|
+
columns: r.columns ? JSON.parse(r.columns) : undefined,
|
|
85
|
+
durationMs: r.duration_ms,
|
|
86
|
+
error: r.error,
|
|
87
|
+
denialReason: r.denial_reason,
|
|
88
|
+
correlationId: r.correlation_id,
|
|
89
|
+
connectorHash: r.connector_hash,
|
|
90
|
+
steps: r.steps ? JSON.parse(r.steps) : undefined,
|
|
91
|
+
source: r.source,
|
|
92
|
+
previousValue: r.previous_value,
|
|
93
|
+
newValue: r.new_value,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=audit-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-store.js","sourceRoot":"","sources":["../src/audit-store.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC,MAAM,OAAO,UAAU;IACb,EAAE,CAAoB;IAE9B,YAAY,MAAc;QACxB,IAAI,CAAC,EAAE,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC/B,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;QACrC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;;;;;MAKX,CAAC,CAAC;QACJ,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,IAAI,MAAM,KAAK,UAAU,EAAE,CAAC;YAC1B,IAAI,CAAC;gBAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC,CAAC,6BAA6B,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAEO,OAAO;QACb,MAAM,IAAI,GAAG,IAAI,GAAG,CACjB,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,0BAA0B,CAAwB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CACpF,CAAC;QACF,MAAM,SAAS,GAAuB;YACpC,CAAC,gBAAgB,EAAE,MAAM,CAAC;YAC1B,CAAC,gBAAgB,EAAE,MAAM,CAAC;YAC1B,CAAC,OAAO,EAAE,MAAM,CAAC;YACjB,CAAC,QAAQ,EAAE,MAAM,CAAC;YAClB,CAAC,gBAAgB,EAAE,MAAM,CAAC;YAC1B,CAAC,WA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AAK,CAAC,CAAC,CAAC,KAAe,CAAkB,CAAC,CAAC,CAAC,SAAS;YAC3E,MAAM,EAAE,CAAC,CAAC,MAA4B;YACtC,aAAa,EAAE,CAAC,CAAC,cAAoC;YACrD,QAAQ,EAAE,CAAC,CAAC,SAA+B;SAC5C,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function generateSessionToken(): string;
|
|
2
|
+
export declare function writeSessionToken(token: string, tokenPath: string): void;
|
|
3
|
+
export declare function readSessionToken(tokenPath: string): string | null;
|
|
4
|
+
export declare function validateToken(incoming: string, expected: string): boolean;
|
|
5
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAKA,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAGxE;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMjE;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAKzE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/auth.ts
|
|
2
|
+
import { randomBytes, timingSafeEqual } from 'node:crypto';
|
|
3
|
+
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
4
|
+
import { dirname } from 'node:path';
|
|
5
|
+
export function generateSessionToken() {
|
|
6
|
+
return randomBytes(32).toString('hex');
|
|
7
|
+
}
|
|
8
|
+
export function writeSessionToken(token, tokenPath) {
|
|
9
|
+
mkdirSync(dirname(tokenPath), { recursive: true });
|
|
10
|
+
writeFileSync(tokenPath, token, { mode: 0o600 });
|
|
11
|
+
}
|
|
12
|
+
export function readSessionToken(tokenPath) {
|
|
13
|
+
try {
|
|
14
|
+
return readFileSync(tokenPath, 'utf-8').trim();
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function validateToken(incoming, expected) {
|
|
21
|
+
if (incoming.length === 0 || incoming.length !== expected.length)
|
|
22
|
+
return false;
|
|
23
|
+
const a = Buffer.from(incoming);
|
|
24
|
+
const b = Buffer.from(expected);
|
|
25
|
+
return timingSafeEqual(a, b);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,UAAU,oBAAoB;IAClC,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAa,EAAE,SAAiB;IAChE,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACnD,aAAa,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,SAAiB;IAChD,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,QAAgB,EAAE,QAAgB;IAC9D,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC/E,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChC,OAAO,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const configSchema: z.ZodObject<{
|
|
3
|
+
daemon: z.ZodDefault<z.ZodObject<{
|
|
4
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
5
|
+
host: z.ZodDefault<z.ZodString>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
port: number;
|
|
8
|
+
host: string;
|
|
9
|
+
}, {
|
|
10
|
+
port?: number | undefined;
|
|
11
|
+
host?: string | undefined;
|
|
12
|
+
}>>;
|
|
13
|
+
security: z.ZodDefault<z.ZodObject<{
|
|
14
|
+
extensionId: z.ZodDefault<z.ZodString>;
|
|
15
|
+
highRiskCapabilities: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
16
|
+
approvedHighRisk: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
17
|
+
approvalRequired: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
18
|
+
autoApproveConnectors: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
19
|
+
approvalTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
extensionId: string;
|
|
22
|
+
highRiskCapabilities: string[];
|
|
23
|
+
approvedHighRisk: string[];
|
|
24
|
+
approvalRequired: string[];
|
|
25
|
+
autoApproveConnectors: string[];
|
|
26
|
+
approvalTimeoutMs: number;
|
|
27
|
+
}, {
|
|
28
|
+
extensionId?: string | undefined;
|
|
29
|
+
highRiskCapabilities?: string[] | undefined;
|
|
30
|
+
approvedHighRisk?: string[] | undefined;
|
|
31
|
+
approvalRequired?: string[] | undefined;
|
|
32
|
+
autoApproveConnectors?: string[] | undefined;
|
|
33
|
+
approvalTimeoutMs?: number | undefined;
|
|
34
|
+
}>>;
|
|
35
|
+
connectors: z.ZodDefault<z.ZodObject<{
|
|
36
|
+
paths: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
37
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
|
+
paths: string[];
|
|
39
|
+
}, {
|
|
40
|
+
paths?: string[] | undefined;
|
|
41
|
+
}>>;
|
|
42
|
+
audit: z.ZodDefault<z.ZodObject<{
|
|
43
|
+
retentionDays: z.ZodDefault<z.ZodNumber>;
|
|
44
|
+
dbPath: z.ZodDefault<z.ZodString>;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
retentionDays: number;
|
|
47
|
+
dbPath: string;
|
|
48
|
+
}, {
|
|
49
|
+
retentionDays?: number | undefined;
|
|
50
|
+
dbPath?: string | undefined;
|
|
51
|
+
}>>;
|
|
52
|
+
output: z.ZodDefault<z.ZodObject<{
|
|
53
|
+
defaultFormat: z.ZodDefault<z.ZodEnum<["table", "json", "csv"]>>;
|
|
54
|
+
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
defaultFormat: "table" | "json" | "csv";
|
|
56
|
+
}, {
|
|
57
|
+
defaultFormat?: "table" | "json" | "csv" | undefined;
|
|
58
|
+
}>>;
|
|
59
|
+
}, "strip", z.ZodTypeAny, {
|
|
60
|
+
daemon: {
|
|
61
|
+
port: number;
|
|
62
|
+
host: string;
|
|
63
|
+
};
|
|
64
|
+
security: {
|
|
65
|
+
extensionId: string;
|
|
66
|
+
highRiskCapabilities: string[];
|
|
67
|
+
approvedHighRisk: string[];
|
|
68
|
+
approvalRequired: string[];
|
|
69
|
+
autoApproveConnectors: string[];
|
|
70
|
+
approvalTimeoutMs: number;
|
|
71
|
+
};
|
|
72
|
+
connectors: {
|
|
73
|
+
paths: string[];
|
|
74
|
+
};
|
|
75
|
+
audit: {
|
|
76
|
+
retentionDays: number;
|
|
77
|
+
dbPath: string;
|
|
78
|
+
};
|
|
79
|
+
output: {
|
|
80
|
+
defaultFormat: "table" | "json" | "csv";
|
|
81
|
+
};
|
|
82
|
+
}, {
|
|
83
|
+
daemon?: {
|
|
84
|
+
port?: number | undefined;
|
|
85
|
+
host?: string | undefined;
|
|
86
|
+
} | undefined;
|
|
87
|
+
security?: {
|
|
88
|
+
extensionId?: string | undefined;
|
|
89
|
+
highRiskCapabilities?: string[] | undefined;
|
|
90
|
+
approvedHighRisk?: string[] | undefined;
|
|
91
|
+
approvalRequired?: string[] | undefined;
|
|
92
|
+
autoApproveConnectors?: string[] | undefined;
|
|
93
|
+
approvalTimeoutMs?: number | undefined;
|
|
94
|
+
} | undefined;
|
|
95
|
+
connectors?: {
|
|
96
|
+
paths?: string[] | undefined;
|
|
97
|
+
} | undefined;
|
|
98
|
+
audit?: {
|
|
99
|
+
retentionDays?: number | undefined;
|
|
100
|
+
dbPath?: string | undefined;
|
|
101
|
+
} | undefined;
|
|
102
|
+
output?: {
|
|
103
|
+
defaultFormat?: "table" | "json" | "csv" | undefined;
|
|
104
|
+
} | undefined;
|
|
105
|
+
}>;
|
|
106
|
+
export type DaemonConfig = z.infer<typeof configSchema>;
|
|
107
|
+
export declare function expandHome(p: string): string;
|
|
108
|
+
export declare function loadConfig(configPath?: string): DaemonConfig;
|
|
109
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuBvB,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAExD,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAK5C;AAED,wBAAgB,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,YAAY,CAM5D"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/config.ts
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { parse as parseYaml } from 'yaml';
|
|
4
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { homedir } from 'node:os';
|
|
7
|
+
export const configSchema = z.object({
|
|
8
|
+
daemon: z.object({
|
|
9
|
+
port: z.number().int().min(1024).max(65535).default(19825),
|
|
10
|
+
host: z.string().default('127.0.0.1'),
|
|
11
|
+
}).default({}),
|
|
12
|
+
security: z.object({
|
|
13
|
+
extensionId: z.string().default(''),
|
|
14
|
+
highRiskCapabilities: z.array(z.string()).default(['js_evaluate', 'cookie_write']),
|
|
15
|
+
approvedHighRisk: z.array(z.string()).default([]),
|
|
16
|
+
approvalRequired: z.array(z.string()).default([]),
|
|
17
|
+
autoApproveConnectors: z.array(z.string()).default([]),
|
|
18
|
+
approvalTimeoutMs: z.number().int().positive().default(120_000),
|
|
19
|
+
}).default({}),
|
|
20
|
+
connectors: z.object({
|
|
21
|
+
paths: z.array(z.string()).default(['./connectors', '~/.commandgarden/connectors']),
|
|
22
|
+
}).default({}),
|
|
23
|
+
audit: z.object({
|
|
24
|
+
retentionDays: z.number().int().positive().default(90),
|
|
25
|
+
dbPath: z.string().default('~/.commandgarden/audit.db'),
|
|
26
|
+
}).default({}),
|
|
27
|
+
output: z.object({
|
|
28
|
+
defaultFormat: z.enum(['table', 'json', 'csv']).default('table'),
|
|
29
|
+
}).default({}),
|
|
30
|
+
});
|
|
31
|
+
export function expandHome(p) {
|
|
32
|
+
if (p.startsWith('~/') || p.startsWith('~\\')) {
|
|
33
|
+
return join(homedir(), p.slice(2));
|
|
34
|
+
}
|
|
35
|
+
return p;
|
|
36
|
+
}
|
|
37
|
+
export function loadConfig(configPath) {
|
|
38
|
+
const path = configPath ?? join(homedir(), '.commandgarden', 'config.yaml');
|
|
39
|
+
if (!existsSync(path))
|
|
40
|
+
return configSchema.parse({});
|
|
41
|
+
const raw = readFileSync(path, 'utf-8');
|
|
42
|
+
const parsed = parseYaml(raw);
|
|
43
|
+
return configSchema.parse(parsed ?? {});
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACf,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;QAC1D,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC;KACtC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;IACd,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Aa,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;KACjE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;CACf,CAAC,CAAC;AAIH,MAAM,UAAU,UAAU,CAAC,CAAS;IAClC,IAAI,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9C,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,UAAmB;IAC5C,MAAM,IAAI,GAAG,UAAU,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,gBAAgB,EAAE,aAAa,CAAC,CAAC;IAC5E,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACrD,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACxC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;IAC9B,OAAO,YAAY,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// src/main.ts
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { homedir, userInfo } from 'node:os';
|
|
4
|
+
import { createAuditEvent } from '@commandgarden/shared';
|
|
5
|
+
import { loadConfig, expandHome } from './config.js';
|
|
6
|
+
import { generateSessionToken, writeSessionToken } from './auth.js';
|
|
7
|
+
import { AuditStore } from './audit-store.js';
|
|
8
|
+
import { ConnectorRegistry } from './registry.js';
|
|
9
|
+
import { WsRelay } from './ws-relay.js';
|
|
10
|
+
import { createServer } from './server.js';
|
|
11
|
+
async function main() {
|
|
12
|
+
const cgHome = join(homedir(), '.commandgarden');
|
|
13
|
+
const configPath = join(cgHome, 'config.yaml');
|
|
14
|
+
const config = loadConfig(configPath);
|
|
15
|
+
// Auth token
|
|
16
|
+
const sessionToken = generateSessionToken();
|
|
17
|
+
const tokenPath = join(cgHome, 'session-token');
|
|
18
|
+
writeSessionToken(sessionToken, tokenPath);
|
|
19
|
+
console.log(`Session token written to ${tokenPath}`);
|
|
20
|
+
// Audit store
|
|
21
|
+
const dbPath = expandHome(config.audit.dbPath);
|
|
22
|
+
const auditStore = new AuditStore(dbPath);
|
|
23
|
+
const pruned = auditStore.prune(config.audit.retentionDays);
|
|
24
|
+
if (pruned > 0) {
|
|
25
|
+
console.log(`Pruned ${pruned} old audit events`);
|
|
26
|
+
auditStore.insert(createAuditEvent({
|
|
27
|
+
type: 'config.changed', connector: '_system/prune', user: userInfo().username,
|
|
28
|
+
source: 'audit.prune',
|
|
29
|
+
previousValue: String(pruned), newValue: '0',
|
|
30
|
+
args: { retentionDays: String(config.audit.retentionDays) },
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
// Connector registry
|
|
34
|
+
const connectorPaths = config.connectors.paths.map(expandHome);
|
|
35
|
+
const registry = new ConnectorRegistry(connectorPaths);
|
|
36
|
+
const { loaded, errors } = registry.load();
|
|
37
|
+
console.log(`Loaded ${loaded} connectors`);
|
|
38
|
+
if (errors.length > 0)
|
|
39
|
+
console.warn('Connector errors:', errors);
|
|
40
|
+
// WebSocket relay
|
|
41
|
+
const wsRelay = new WsRelay();
|
|
42
|
+
// Server
|
|
43
|
+
const app = await createServer({ config, configPath, sessionToken, registry, auditStore, wsRelay });
|
|
44
|
+
const address = await app.listen({ port: config.daemon.port, host: config.daemon.host });
|
|
45
|
+
console.log(`Daemon listening on ${address}`);
|
|
46
|
+
// Graceful shutdown
|
|
47
|
+
const shutdown = async () => {
|
|
48
|
+
console.log('Shutting down...');
|
|
49
|
+
wsRelay.detach();
|
|
50
|
+
await app.close();
|
|
51
|
+
auditStore.close();
|
|
52
|
+
process.exit(0);
|
|
53
|
+
};
|
|
54
|
+
process.on('SIGINT', shutdown);
|
|
55
|
+
process.on('SIGTERM', shutdown);
|
|
56
|
+
}
|
|
57
|
+
main().catch((err) => { console.error('Failed to start daemon:', err); process.exit(1); });
|
|
58
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,gBAAgB,CAAC,CAAC;IACjD,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;IAEtC,aAAa;IACb,MAAM,YAAY,GAAG,oBAAoB,EAAE,CAAC;IAC5C,MAAM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private paths;
|
|
4
|
+
private connectors;
|
|
5
|
+
private meta;
|
|
6
|
+
constructor(paths: string[]);
|
|
7
|
+
load(): {
|
|
8
|
+
loaded: number;
|
|
9
|
+
errors: string[];
|
|
10
|
+
};
|
|
11
|
+
private resolveFileRefs;
|
|
12
|
+
get(key: string): ConnectorDef | undefined;
|
|
13
|
+
list(): ConnectorDef[];
|
|
14
|
+
keys(): string[];
|
|
15
|
+
getWithMeta(key: string): {
|
|
16
|
+
connector: ConnectorDef;
|
|
17
|
+
yamlContent: string;
|
|
18
|
+
filePath: string;
|
|
19
|
+
} | undefined;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkD,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1G,qBAAa,iBAAiB;IAIhB,OAAO,CAAC,KAAK;IAHzB,OAAO,CAAC,UAAU,CAAmC;IACrD,OAAO,CAAC,IAAI,CAAgE;gBAExD,KAAK,EAAE,MAAM,EAAE;IAEnC,IAAI,IAAI;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE;IAyB5C,OAAO,CAAC,eAAe;IAcvB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAC1C,IAAI,IAAI,YAAY,EAAE;IACtB,IAAI,IAAI,MAAM,EAAE;IAEhB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,SAAS,EAAE,YAAY,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS;CAMzG"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// src/registry.ts
|
|
2
|
+
import { readdirSync, readFileSync, existsSync } from 'node:fs';
|
|
3
|
+
import { join, resolve, dirname } from 'node:path';
|
|
4
|
+
import { parseConnectorYaml, validateConnectorSemantics } from '@commandgarden/shared';
|
|
5
|
+
export class ConnectorRegistry {
|
|
6
|
+
paths;
|
|
7
|
+
connectors = new Map();
|
|
8
|
+
meta = new Map();
|
|
9
|
+
constructor(paths) {
|
|
10
|
+
this.paths = paths;
|
|
11
|
+
}
|
|
12
|
+
load() {
|
|
13
|
+
const errors = [];
|
|
14
|
+
let loaded = 0;
|
|
15
|
+
this.connectors.clear();
|
|
16
|
+
this.meta.clear();
|
|
17
|
+
for (const dir of this.paths) {
|
|
18
|
+
const resolved = resolve(dir);
|
|
19
|
+
if (!existsSync(resolved))
|
|
20
|
+
continue;
|
|
21
|
+
for (const file of readdirSync(resolved).filter(f => f.endsWith('.yaml') || f.endsWith('.yml'))) {
|
|
22
|
+
const content = readFileSync(join(resolved, file), 'utf-8');
|
|
23
|
+
const result = parseConnectorYaml(content);
|
|
24
|
+
if (!result.ok) {
|
|
25
|
+
errors.push(`${file}: ${result.error.message}`);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const fileErr = this.resolveFileRefs(result.data, join(resolved, file));
|
|
29
|
+
if (fileErr) {
|
|
30
|
+
errors.push(`${file}: ${fileErr}`);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const semErrs = validateConnectorSemantics(result.data);
|
|
34
|
+
if (semErrs.length > 0) {
|
|
35
|
+
errors.push(`${file}: ${semErrs.join('; ')}`);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const key = `${result.data.site}/${result.data.name}`;
|
|
39
|
+
this.connectors.set(key, result.data);
|
|
40
|
+
this.meta.set(key, { yamlContent: content, filePath: join(resolved, file) });
|
|
41
|
+
loaded++;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return { loaded, errors };
|
|
45
|
+
}
|
|
46
|
+
resolveFileRefs(connector, yamlPath) {
|
|
47
|
+
const baseDir = dirname(yamlPath);
|
|
48
|
+
for (const step of connector.pipeline) {
|
|
49
|
+
if (step.step === 'js_evaluate' && step.file) {
|
|
50
|
+
const filePath = join(baseDir, step.file);
|
|
51
|
+
if (!existsSync(filePath)) {
|
|
52
|
+
return `js_evaluate file not found: ${step.file}`;
|
|
53
|
+
}
|
|
54
|
+
step.code = readFileSync(filePath, 'utf-8');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
get(key) { return this.connectors.get(key); }
|
|
60
|
+
list() { return [...this.connectors.values()]; }
|
|
61
|
+
keys() { return [...this.connectors.keys()]; }
|
|
62
|
+
getWithMeta(key) {
|
|
63
|
+
const connector = this.connectors.get(key);
|
|
64
|
+
const m = this.meta.get(key);
|
|
65
|
+
if (!connector || !m)
|
|
66
|
+
return undefined;
|
|
67
|
+
return { connector, ...m };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAClB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAqB,MAAM,uBAAuB,CAAC;AAE1G,MAAM,OAAO,iBAAiB;IAIR;IAHZ,UAAU,GAAG,IAAI,GAAG,EAAwB,CAAC;IAC7C,IAAI,GAAG,IAAI,GAAG,EAAqD,CAAC;IAE5E,YAAoB,KAAe;QAAf,UAAK,GAAL,KAAK,CAAU;IAAG,CAAC;IAEvC,IAAI;QACF,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;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AE,CAAC,CAAC,CAAC,CAAC;IAChE,IAAI,KAAe,OAAO,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAExD,WAAW,CAAC,GAAW;QACrB,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC3C,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,SAAS,IAAI,CAAC,CAAC;YAAE,OAAO,SAAS,CAAC;QACvC,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,EAAE,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Fastify from 'fastify';
|
|
2
|
+
import type { DaemonConfig } from './config.js';
|
|
3
|
+
import type { ConnectorRegistry } from './registry.js';
|
|
4
|
+
import type { AuditStore } from './audit-store.js';
|
|
5
|
+
import { WsRelay } from './ws-relay.js';
|
|
6
|
+
export interface ServerDeps {
|
|
7
|
+
config: DaemonConfig;
|
|
8
|
+
configPath: string;
|
|
9
|
+
sessionToken: string;
|
|
10
|
+
registry: ConnectorRegistry;
|
|
11
|
+
auditStore: AuditStore;
|
|
12
|
+
wsRelay: WsRelay;
|
|
13
|
+
}
|
|
14
|
+
export declare function createServer(deps: ServerDeps): Promise<Fastify.FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, Fastify.FastifyBaseLogger, Fastify.FastifyTypeProviderDefault>>;
|
|
15
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;AAM9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAKxC,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,YAAY,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,UAAU,sSA+TlD"}
|