@xmemo/client 0.4.154 → 0.4.156

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.
@@ -0,0 +1,67 @@
1
+ import { JSON_MCP_CLIENT_DEFINITIONS } from './json-clients.js';
2
+
3
+ export function createMcpClients(deps) {
4
+ const clients = new Map();
5
+
6
+ clients.set('codex', {
7
+ label: 'Codex',
8
+ defaultConfigPath: deps.defaultCodexConfigPath,
9
+ buildSnippet: deps.codexTomlSnippet,
10
+ writeConfig: deps.appendTomlServerConfig,
11
+ configKind: 'toml'
12
+ });
13
+
14
+ for (const definition of deps.JSON_MCP_CLIENT_DEFINITIONS) {
15
+ if (definition.id === 'qwen') {
16
+ clients.set('hermes', hermesClient(deps));
17
+ }
18
+ clients.set(definition.id, jsonClient(definition, deps));
19
+ }
20
+
21
+ if (!clients.has('hermes')) {
22
+ clients.set('hermes', hermesClient(deps));
23
+ }
24
+
25
+ return clients;
26
+ }
27
+
28
+ function jsonClient(definition, deps) {
29
+ return {
30
+ label: definition.label,
31
+ defaultConfigPath: deps[definition.defaultConfigPath],
32
+ buildSnippet: (mcpUrl, identity) => deps.jsonClientSnippet(definition.id, mcpUrl, identity),
33
+ writeConfig: (configPath, mcpUrl, identity) => deps.mergeJsonClientMcpConfig(definition.id, configPath, mcpUrl, identity),
34
+ configKind: definition.configKind,
35
+ authentication: definition.authentication
36
+ };
37
+ }
38
+
39
+ function hermesClient(deps) {
40
+ return {
41
+ label: 'Hermes',
42
+ defaultConfigPath: deps.defaultHermesConfigPath,
43
+ buildSnippet: deps.hermesYamlSnippet,
44
+ writeConfig: deps.mergeHermesMcpConfig,
45
+ configKind: 'yaml'
46
+ };
47
+ }
48
+
49
+ export function supportedMcpClients(mcpClients) {
50
+ const clients = Array.from(mcpClients.entries()).map(([id, client]) => ({
51
+ id,
52
+ label: client.label,
53
+ configKind: client.configKind
54
+ }));
55
+ clients.push({ id: 'copilot-cli', label: 'Copilot CLI', configKind: 'local-proxy' });
56
+ return clients;
57
+ }
58
+
59
+ export function supportedMcpClientIds(mcpClients) {
60
+ return Array.from(mcpClients.keys());
61
+ }
62
+
63
+ export function usesClientOAuth(clientId) {
64
+ return JSON_MCP_CLIENT_DEFINITIONS.some(
65
+ (definition) => definition.id === clientId && definition.authentication === 'oauth'
66
+ );
67
+ }
@@ -0,0 +1,155 @@
1
+ import {
2
+ AGENT_ID_HEADER,
3
+ AGENT_INSTANCE_ENV_VAR,
4
+ AGENT_INSTANCE_HEADER,
5
+ COMMAND_NAME,
6
+ DEFAULT_PROXY_PORT,
7
+ MCP_SERVER_NAME,
8
+ TOKEN_ENV_VAR
9
+ } from '../constants.js';
10
+ import { codexTomlSnippet } from './codex.js';
11
+ import {
12
+ jsonClientConfig,
13
+ jsonMcpClientDefinition
14
+ } from './json-clients.js';
15
+
16
+ export function mcpConfigTemplate(clientId, mcpUrl, options = {}) {
17
+ if (clientId === 'codex') {
18
+ return {
19
+ client: clientId,
20
+ serverName: MCP_SERVER_NAME,
21
+ snippetFormat: 'toml',
22
+ snippet: codexTomlSnippet(mcpUrl),
23
+ requiresEnv: [TOKEN_ENV_VAR],
24
+ optionalEnv: [AGENT_INSTANCE_ENV_VAR],
25
+ agentIdentity: {
26
+ agentId: 'codex',
27
+ agentIdHeader: AGENT_ID_HEADER,
28
+ agentInstanceEnvVar: AGENT_INSTANCE_ENV_VAR,
29
+ agentInstanceHeader: AGENT_INSTANCE_HEADER
30
+ },
31
+ agentInstanceGeneration: agentInstanceGenerationPolicy(clientId, options),
32
+ writesTokenValue: false
33
+ };
34
+ }
35
+
36
+ const jsonDefinition = jsonMcpClientDefinition(clientId);
37
+ if (jsonDefinition) {
38
+ return jsonDefinition.authentication === 'oauth'
39
+ ? oauthJsonMcpTemplate(clientId, mcpUrl, jsonClientConfig(clientId, mcpUrl), options)
40
+ : bearerJsonMcpTemplate(clientId, mcpUrl, jsonClientConfig(clientId, mcpUrl), options);
41
+ }
42
+
43
+ return {
44
+ client: clientId,
45
+ serverName: MCP_SERVER_NAME,
46
+ snippetFormat: 'json',
47
+ snippet: {
48
+ mcpServers: {
49
+ [MCP_SERVER_NAME]: {
50
+ type: 'http',
51
+ url: mcpUrl,
52
+ headers: {
53
+ Authorization: `Bearer \${${TOKEN_ENV_VAR}}`,
54
+ [AGENT_ID_HEADER]: clientId,
55
+ [AGENT_INSTANCE_HEADER]: `\${${AGENT_INSTANCE_ENV_VAR}}`
56
+ }
57
+ }
58
+ }
59
+ },
60
+ requiresEnv: [TOKEN_ENV_VAR],
61
+ optionalEnv: [AGENT_INSTANCE_ENV_VAR],
62
+ agentIdentity: {
63
+ agentId: clientId,
64
+ agentIdHeader: AGENT_ID_HEADER,
65
+ agentInstanceEnvVar: AGENT_INSTANCE_ENV_VAR,
66
+ agentInstanceHeader: AGENT_INSTANCE_HEADER
67
+ },
68
+ agentInstanceGeneration: agentInstanceGenerationPolicy(clientId, options),
69
+ writesTokenValue: false
70
+ };
71
+ }
72
+
73
+ export function mcpLocalProxyTemplate(clientId, proxyUrl, options = {}) {
74
+ return {
75
+ client: clientId,
76
+ serverName: MCP_SERVER_NAME,
77
+ snippetFormat: 'json',
78
+ snippet: {
79
+ mcpServers: {
80
+ [MCP_SERVER_NAME]: {
81
+ type: 'http',
82
+ url: proxyUrl
83
+ }
84
+ }
85
+ },
86
+ requiresCredential: [`${COMMAND_NAME} login`, `${COMMAND_NAME} token add --from-stdin`],
87
+ requiresLocalCommand: `${COMMAND_NAME} mcp proxy --port ${new URL(proxyUrl).port || DEFAULT_PROXY_PORT}`,
88
+ agentIdentity: {
89
+ agentId: clientId,
90
+ agentIdHeader: AGENT_ID_HEADER,
91
+ agentInstanceEnvVar: AGENT_INSTANCE_ENV_VAR,
92
+ agentInstanceHeader: AGENT_INSTANCE_HEADER
93
+ },
94
+ agentInstanceGeneration: agentInstanceGenerationPolicy(clientId, options),
95
+ writesTokenValue: false
96
+ };
97
+ }
98
+
99
+ export function agentInstanceGenerationPolicy(clientId, options = {}) {
100
+ const automaticCommand = options.mcpClients?.has(clientId)
101
+ ? `${COMMAND_NAME} mcp add ${clientId} --write`
102
+ : clientId === 'copilot-cli'
103
+ ? `${COMMAND_NAME} setup copilot --write`
104
+ : null;
105
+ return {
106
+ requiredForHeaders: true,
107
+ stablePerInstall: true,
108
+ automaticCommand,
109
+ generatedPattern: `xmemo-${clientId}-<uuid>`,
110
+ storagePath: `~/.config/xmemo/agent-instances/${clientId}.json`,
111
+ manualEnvVar: AGENT_INSTANCE_ENV_VAR
112
+ };
113
+ }
114
+
115
+ function bearerJsonMcpTemplate(clientId, mcpUrl, snippet, options) {
116
+ return {
117
+ client: clientId,
118
+ serverName: MCP_SERVER_NAME,
119
+ snippetFormat: 'json',
120
+ snippet,
121
+ requiresEnv: [TOKEN_ENV_VAR],
122
+ optionalEnv: [AGENT_INSTANCE_ENV_VAR],
123
+ authentication: 'env-bearer',
124
+ agentIdentity: {
125
+ agentId: clientId,
126
+ agentIdHeader: AGENT_ID_HEADER,
127
+ agentInstanceEnvVar: AGENT_INSTANCE_ENV_VAR,
128
+ agentInstanceHeader: AGENT_INSTANCE_HEADER
129
+ },
130
+ agentInstanceGeneration: agentInstanceGenerationPolicy(clientId, options),
131
+ mcpUrl,
132
+ writesTokenValue: false
133
+ };
134
+ }
135
+
136
+ function oauthJsonMcpTemplate(clientId, mcpUrl, snippet, options) {
137
+ return {
138
+ client: clientId,
139
+ serverName: MCP_SERVER_NAME,
140
+ snippetFormat: 'json',
141
+ snippet,
142
+ requiresEnv: [],
143
+ optionalEnv: [AGENT_INSTANCE_ENV_VAR],
144
+ authentication: 'oauth',
145
+ agentIdentity: {
146
+ agentId: clientId,
147
+ agentIdHeader: AGENT_ID_HEADER,
148
+ agentInstanceEnvVar: AGENT_INSTANCE_ENV_VAR,
149
+ agentInstanceHeader: AGENT_INSTANCE_HEADER
150
+ },
151
+ agentInstanceGeneration: agentInstanceGenerationPolicy(clientId, options),
152
+ mcpUrl,
153
+ writesTokenValue: false
154
+ };
155
+ }
@@ -0,0 +1,25 @@
1
+ export {
2
+ configRoot,
3
+ defaultAntigravity2ConfigPath,
4
+ defaultAntigravityCliConfigPath,
5
+ defaultAntigravityConfigPath,
6
+ defaultAntigravityIdeConfigPath,
7
+ defaultClaudeConfigPath,
8
+ defaultClaudecodeConfigPath,
9
+ defaultClineConfigPath,
10
+ defaultCodexConfigPath,
11
+ defaultContinueConfigPath,
12
+ defaultCopilotConfigPath,
13
+ defaultCursorConfigPath,
14
+ defaultGeminiConfigPath,
15
+ defaultHermesConfigPath,
16
+ defaultJetbrainsConfigPath,
17
+ defaultKiroConfigPath,
18
+ defaultOpencodeConfigPath,
19
+ defaultOpenclawConfigPath,
20
+ defaultQwenConfigPath,
21
+ defaultTraeConfigPath,
22
+ defaultTraeSoloConfigPath,
23
+ defaultWindsurfConfigPath,
24
+ defaultZedConfigPath
25
+ } from './mcp/paths.js';