Repository navigation
Expand file tree
/
Copy pathproject-normalize.js
More file actions
45 lines (42 loc) · 1.79 KB
/
Copy pathproject-normalize.js
File metadata and controls
45 lines (42 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
const ModePresets = require('./public/core/mode-presets');
// Deliberate ALLOW-LIST: only the fields listed here cross to the client. A
// new relay field is silently dropped until added here; the project token
// must never leak and is intentionally absent (see below).
function normalizeProject(p) {
return {
id: p.id,
name: p.name,
path: p.path,
// '' for a console project. The full `host` object (id/name/status) is
// attached separately by server.js#resolveProject from its hosts cache —
// this module has no relay transport to fetch it with, and ssh_argv must
// never reach here at all (see docs/security — ssh-hosts.md).
hostId: p.host_id || '',
allowedMcpIds: p.allowed_mcp_ids || [],
allowedModels: p.allowed_models || [],
chatTemplates: (p.chat_templates || []).map(t => ({
id: t.id,
name: t.name,
model: t.model,
mode: t.mode || 'text',
voice: t.voice || '',
systemPrompt: t.system_prompt || '',
presetFor: ModePresets.normalize(t.preset_for),
})),
permissionPolicy: p.permission_policy ? {
defaultMode: p.permission_policy.default_mode || 'default',
allowedTools: p.permission_policy.allowed_tools || [],
deniedTools: p.permission_policy.denied_tools || [],
} : null,
sessionFolders: p.session_folders || [],
// 'home' | 'work' | 'both'; relay treats a missing mode as both. defaultFor
// lists the modes this project is the default project of.
mode: p.mode === 'home' || p.mode === 'work' ? p.mode : 'both',
defaultFor: Array.isArray(p.default_for) ? p.default_for : [],
// No `token`: relay is the sole project-token authority. Never cache or
// forward the secret here.
createdAt: p.created_at || '',
};
}
module.exports = { normalizeProject };