@bike4mind/cli 0.2.5-feat-server-side-tool-execution.17096 → 0.2.5-feat-auto-context-customization.17096

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.
@@ -291,7 +291,7 @@ import {
291
291
  validateQuestMasterArtifactV2,
292
292
  validateReactArtifactV2,
293
293
  validateSvgArtifactV2
294
- } from "./chunk-WR6YZRQV.js";
294
+ } from "./chunk-2RFX62SX.js";
295
295
  import "./chunk-PDX44BCA.js";
296
296
  export {
297
297
  ALL_IMAGE_MODELS,
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  SubtractCreditsSchema,
4
4
  subtractCredits
5
- } from "./chunk-LEG2UM5Q.js";
6
- import "./chunk-LYNNVNEC.js";
5
+ } from "./chunk-GXADX53I.js";
6
+ import "./chunk-RM2KFSVU.js";
7
7
  import "./chunk-AMDXHL6S.js";
8
- import "./chunk-WR6YZRQV.js";
8
+ import "./chunk-2RFX62SX.js";
9
9
  import "./chunk-PDX44BCA.js";
10
10
  export {
11
11
  SubtractCreditsSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bike4mind/cli",
3
- "version": "0.2.5-feat-server-side-tool-execution.17096+d6b936a82",
3
+ "version": "0.2.5-feat-auto-context-customization.17096+23b9f23d6",
4
4
  "type": "module",
5
5
  "description": "Interactive CLI tool for Bike4Mind with ReAct agents",
6
6
  "license": "UNLICENSED",
@@ -33,7 +33,6 @@
33
33
  "scripts": {
34
34
  "dev": "tsx src/index.tsx",
35
35
  "build": "tsup",
36
- "postbuild": "node scripts/bundle-mcp-proxy.mjs",
37
36
  "typecheck": "tsc --noEmit",
38
37
  "test": "vitest run",
39
38
  "test:watch": "vitest",
@@ -103,11 +102,10 @@
103
102
  },
104
103
  "devDependencies": {
105
104
  "@bike4mind/agents": "0.1.0",
106
- "@bike4mind/common": "2.37.1-feat-server-side-tool-execution.17096+d6b936a82",
107
- "@bike4mind/mcp": "1.19.6-feat-server-side-tool-execution.17096+d6b936a82",
108
- "@bike4mind/mcp-server-b4m-proxy": "1.0.1-feat-server-side-tool-execution.17096+d6b936a82",
109
- "@bike4mind/services": "2.32.2-feat-server-side-tool-execution.17096+d6b936a82",
110
- "@bike4mind/utils": "2.1.1-feat-server-side-tool-execution.17096+d6b936a82",
105
+ "@bike4mind/common": "2.37.1-feat-auto-context-customization.17096+23b9f23d6",
106
+ "@bike4mind/mcp": "1.19.6-feat-auto-context-customization.17096+23b9f23d6",
107
+ "@bike4mind/services": "2.32.2-feat-auto-context-customization.17096+23b9f23d6",
108
+ "@bike4mind/utils": "2.1.1-feat-auto-context-customization.17096+23b9f23d6",
111
109
  "@types/diff": "^5.0.9",
112
110
  "@types/jsonwebtoken": "^9.0.4",
113
111
  "@types/node": "^22.9.0",
@@ -119,5 +117,5 @@
119
117
  "typescript": "^5.9.3",
120
118
  "vitest": "^3.2.4"
121
119
  },
122
- "gitHead": "d6b936a82aed081ee4ef534a0e5260bc9fbe5714"
120
+ "gitHead": "23b9f23d64c9e7444d7eebf7034f6cdd4ce6db45"
123
121
  }
@@ -1,79 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * B4M MCP Proxy Wrapper
4
- *
5
- * This wrapper script reads the CLI configuration to get the current JWT token
6
- * and API URL, then launches the MCP proxy with those credentials.
7
- *
8
- * This allows the MCP proxy to authenticate with the B4M backend without
9
- * requiring users to manually set environment variables.
10
- *
11
- * The wrapper reads from ~/.bike4mind/config.json to get:
12
- * - auth.accessToken (JWT token)
13
- * - apiConfig.customUrl (custom API URL, if set)
14
- */
15
-
16
- import { spawn } from 'child_process';
17
- import { join, dirname } from 'path';
18
- import { homedir } from 'os';
19
- import { readFileSync } from 'fs';
20
- import { fileURLToPath } from 'url';
21
-
22
- const __dirname = dirname(fileURLToPath(import.meta.url));
23
-
24
- // Read config to get current JWT token and API URL
25
- const configPath = process.env.B4M_CONFIG_PATH || join(homedir(), '.bike4mind', 'config.json');
26
-
27
- let authToken = '';
28
- let apiUrl = 'https://api.bike4mind.com';
29
-
30
- try {
31
- const configData = readFileSync(configPath, 'utf-8');
32
- const config = JSON.parse(configData);
33
-
34
- // Get JWT access token
35
- authToken = config.auth?.accessToken || '';
36
-
37
- // Get custom API URL if configured
38
- apiUrl = config.apiConfig?.customUrl || apiUrl;
39
-
40
- if (!authToken) {
41
- console.warn('⚠️ Warning: No authentication token found in config');
42
- console.warn(' B4M server tools will not be available.');
43
- console.warn(' Run /login in the CLI to authenticate.');
44
- }
45
- } catch (error) {
46
- // Config doesn't exist or is invalid
47
- // This is OK - user might not be authenticated yet
48
- if (error.code !== 'ENOENT') {
49
- console.error('Warning: Could not read B4M config:', error.message);
50
- }
51
- }
52
-
53
- // Path to the bundled MCP proxy
54
- const mcpProxyPath = join(__dirname, '../dist/mcp-proxy/index.js');
55
-
56
- // Launch MCP proxy with dynamic environment variables
57
- const child = spawn('node', [mcpProxyPath], {
58
- stdio: 'inherit', // Inherit stdin/stdout/stderr for MCP protocol
59
- env: {
60
- ...process.env,
61
- B4M_AUTH_TOKEN: authToken,
62
- B4M_API_URL: apiUrl,
63
- B4M_TIMEOUT: process.env.B4M_TIMEOUT || '30000',
64
- },
65
- });
66
-
67
- // Handle process exit
68
- child.on('exit', (code) => {
69
- process.exit(code || 0);
70
- });
71
-
72
- // Handle signals
73
- process.on('SIGINT', () => {
74
- child.kill('SIGINT');
75
- });
76
-
77
- process.on('SIGTERM', () => {
78
- child.kill('SIGTERM');
79
- });
@@ -1,47 +0,0 @@
1
- /**
2
- * HTTP client for communicating with B4M backend API
3
- * Handles authentication, request/response formatting, and error handling
4
- */
5
- export interface ToolExecuteRequest {
6
- tool: string;
7
- params: Record<string, unknown>;
8
- }
9
- export interface ToolExecuteResponse {
10
- success: boolean;
11
- data?: unknown;
12
- error?: {
13
- code: string;
14
- message: string;
15
- details?: Record<string, unknown>;
16
- };
17
- metadata?: {
18
- executionTime: number;
19
- tool: string;
20
- };
21
- }
22
- export interface ClientConfig {
23
- /** Base URL for B4M API (e.g., https://api.bike4mind.com or http://localhost:3000) */
24
- apiUrl: string;
25
- /** JWT authentication token */
26
- authToken: string;
27
- /** Request timeout in milliseconds */
28
- timeout?: number;
29
- }
30
- /**
31
- * Client for executing tools via B4M backend API
32
- */
33
- export declare class B4MApiClient {
34
- private readonly apiUrl;
35
- private readonly authToken;
36
- private readonly timeout;
37
- constructor(config: ClientConfig);
38
- /**
39
- * Execute a tool via the backend API
40
- */
41
- executeTool(tool: string, params: Record<string, unknown>): Promise<ToolExecuteResponse>;
42
- /**
43
- * Test connection to backend API
44
- */
45
- testConnection(): Promise<boolean>;
46
- }
47
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnC,CAAC;IACF,QAAQ,CAAC,EAAE;QACT,aAAa,EAAE,MAAM,CAAC;QACtB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED,MAAM,WAAW,YAAY;IAC3B,sFAAsF;IACtF,MAAM,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,sCAAsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,YAAY;IAMhC;;OAEG;IACG,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAgG9F;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;CAezC"}
@@ -1,124 +0,0 @@
1
- /**
2
- * HTTP client for communicating with B4M backend API
3
- * Handles authentication, request/response formatting, and error handling
4
- */
5
- /**
6
- * Client for executing tools via B4M backend API
7
- */
8
- export class B4MApiClient {
9
- apiUrl;
10
- authToken;
11
- timeout;
12
- constructor(config) {
13
- this.apiUrl = config.apiUrl.replace(/\/$/, ''); // Remove trailing slash
14
- this.authToken = config.authToken;
15
- this.timeout = config.timeout || 30000; // 30s default
16
- }
17
- /**
18
- * Execute a tool via the backend API
19
- */
20
- async executeTool(tool, params) {
21
- const url = `${this.apiUrl}/api/tools/execute`;
22
- const requestBody = {
23
- tool,
24
- params,
25
- };
26
- try {
27
- // Create abort controller for timeout
28
- const controller = new AbortController();
29
- const timeoutId = setTimeout(() => controller.abort(), this.timeout);
30
- const response = await fetch(url, {
31
- method: 'POST',
32
- headers: {
33
- 'Content-Type': 'application/json',
34
- Authorization: `Bearer ${this.authToken}`,
35
- 'User-Agent': 'B4M-MCP-Proxy/1.0',
36
- },
37
- body: JSON.stringify(requestBody),
38
- signal: controller.signal,
39
- });
40
- clearTimeout(timeoutId);
41
- // Parse response
42
- const data = (await response.json());
43
- // Check for HTTP errors
44
- if (!response.ok) {
45
- // Handle authentication errors with helpful message
46
- if (response.status === 401) {
47
- return {
48
- success: false,
49
- error: {
50
- code: 'AUTHENTICATION_REQUIRED',
51
- message: 'Authentication required. Please run /login in the CLI to authenticate with your B4M account.',
52
- details: data.error?.details,
53
- },
54
- metadata: data.metadata,
55
- };
56
- }
57
- return {
58
- success: false,
59
- error: {
60
- code: data.error?.code || 'HTTP_ERROR',
61
- message: data.error?.message || `HTTP ${response.status}: ${response.statusText}`,
62
- details: data.error?.details,
63
- },
64
- metadata: data.metadata,
65
- };
66
- }
67
- return data;
68
- }
69
- catch (error) {
70
- // Handle timeout
71
- if (error instanceof Error && error.name === 'AbortError') {
72
- return {
73
- success: false,
74
- error: {
75
- code: 'TIMEOUT',
76
- message: `Request timeout after ${this.timeout}ms`,
77
- },
78
- };
79
- }
80
- // Handle network errors
81
- if (error instanceof TypeError) {
82
- return {
83
- success: false,
84
- error: {
85
- code: 'NETWORK_ERROR',
86
- message: 'Failed to connect to B4M API',
87
- details: {
88
- error: error.message,
89
- },
90
- },
91
- };
92
- }
93
- // Unknown error
94
- return {
95
- success: false,
96
- error: {
97
- code: 'UNKNOWN_ERROR',
98
- message: error instanceof Error ? error.message : 'An unknown error occurred',
99
- details: {
100
- error: String(error),
101
- },
102
- },
103
- };
104
- }
105
- }
106
- /**
107
- * Test connection to backend API
108
- */
109
- async testConnection() {
110
- try {
111
- const controller = new AbortController();
112
- const timeoutId = setTimeout(() => controller.abort(), 5000);
113
- const response = await fetch(`${this.apiUrl}/api/health`, {
114
- signal: controller.signal,
115
- });
116
- clearTimeout(timeoutId);
117
- return response.ok;
118
- }
119
- catch {
120
- return false;
121
- }
122
- }
123
- }
124
- //# sourceMappingURL=client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA8BH;;GAEG;AACH,MAAM,OAAO,YAAY;IACN,MAAM,CAAS;IACf,SAAS,CAAS;IAClB,OAAO,CAAS;IAEjC,YAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,wBAAwB;QACxE,IAAI,CAAC,SAAS,GAAG,M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AM,CAAC,KAAK,CAAC;qBACrB;iBACF;aACF,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,cAAc;QAClB,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;YACzC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;YAE7D,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,aAAa,EAAE;gBACxD,MAAM,EAAE,UAAU,CAAC,MAAM;aAC1B,CAAC,CAAC;YAEH,YAAY,CAAC,SAAS,CAAC,CAAC;YACxB,OAAO,QAAQ,CAAC,EAAE,CAAC;QACrB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
@@ -1,32 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * B4M MCP Proxy Server
4
- *
5
- * This MCP server acts as a proxy between Claude CLI and B4M backend API.
6
- * It executes tools server-side using B4M company API keys, ensuring
7
- * keys are never exposed to clients.
8
- *
9
- * Environment Variables:
10
- * - B4M_API_URL: Base URL for B4M API (default: https://api.bike4mind.com)
11
- * - B4M_AUTH_TOKEN: JWT authentication token (required)
12
- * - B4M_TIMEOUT: Request timeout in milliseconds (default: 30000)
13
- *
14
- * Usage:
15
- * node dist/index.js
16
- *
17
- * MCP Configuration (claude_desktop_config.json):
18
- * {
19
- * "mcpServers": {
20
- * "b4m-tools": {
21
- * "command": "node",
22
- * "args": ["/path/to/mcp-server-b4m-proxy/dist/index.js"],
23
- * "env": {
24
- * "B4M_API_URL": "https://api.bike4mind.com",
25
- * "B4M_AUTH_TOKEN": "your-jwt-token"
26
- * }
27
- * }
28
- * }
29
- * }
30
- */
31
- export {};
32
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG"}
@@ -1,187 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * B4M MCP Proxy Server
4
- *
5
- * This MCP server acts as a proxy between Claude CLI and B4M backend API.
6
- * It executes tools server-side using B4M company API keys, ensuring
7
- * keys are never exposed to clients.
8
- *
9
- * Environment Variables:
10
- * - B4M_API_URL: Base URL for B4M API (default: https://api.bike4mind.com)
11
- * - B4M_AUTH_TOKEN: JWT authentication token (required)
12
- * - B4M_TIMEOUT: Request timeout in milliseconds (default: 30000)
13
- *
14
- * Usage:
15
- * node dist/index.js
16
- *
17
- * MCP Configuration (claude_desktop_config.json):
18
- * {
19
- * "mcpServers": {
20
- * "b4m-tools": {
21
- * "command": "node",
22
- * "args": ["/path/to/mcp-server-b4m-proxy/dist/index.js"],
23
- * "env": {
24
- * "B4M_API_URL": "https://api.bike4mind.com",
25
- * "B4M_AUTH_TOKEN": "your-jwt-token"
26
- * }
27
- * }
28
- * }
29
- * }
30
- */
31
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
32
- import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
33
- import { CallToolRequestSchema, ListToolsRequestSchema, McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js';
34
- import { B4MApiClient } from './client.js';
35
- // Configuration from environment
36
- const API_URL = process.env.B4M_API_URL || 'https://api.bike4mind.com';
37
- const AUTH_TOKEN = process.env.B4M_AUTH_TOKEN || '';
38
- const TIMEOUT = parseInt(process.env.B4M_TIMEOUT || '30000', 10);
39
- // Warn if no authentication token (but allow server to start)
40
- // The wrapper script (b4m-mcp-proxy.mjs) already logs a user-friendly warning
41
- if (!AUTH_TOKEN) {
42
- console.error('Warning: B4M_AUTH_TOKEN not set - tools will fail until authenticated');
43
- }
44
- // Initialize API client
45
- const client = new B4MApiClient({
46
- apiUrl: API_URL,
47
- authToken: AUTH_TOKEN,
48
- timeout: TIMEOUT,
49
- });
50
- /**
51
- * Tool definitions for MCP
52
- * These match the tools available in the backend
53
- */
54
- const TOOLS = [
55
- {
56
- name: 'weather',
57
- description: 'Get current weather information for any location worldwide. Returns temperature, conditions, humidity, wind speed, and more.',
58
- inputSchema: {
59
- type: 'object',
60
- properties: {
61
- location: {
62
- type: 'string',
63
- description: 'City name, state, and/or country (e.g., "San Francisco, CA" or "London, UK")',
64
- },
65
- units: {
66
- type: 'string',
67
- enum: ['metric', 'imperial', 'standard'],
68
- description: 'Temperature units (metric = Celsius, imperial = Fahrenheit, standard = Kelvin)',
69
- default: 'metric',
70
- },
71
- },
72
- required: ['location'],
73
- },
74
- },
75
- {
76
- name: 'serper',
77
- description: 'Search the web using Google via SerpAPI. Returns organic search results with titles, links, and snippets.',
78
- inputSchema: {
79
- type: 'object',
80
- properties: {
81
- query: {
82
- type: 'string',
83
- description: 'Search query to execute',
84
- },
85
- num_results: {
86
- type: 'number',
87
- description: 'Number of results to return (1-10, default: 3)',
88
- minimum: 1,
89
- maximum: 10,
90
- default: 3,
91
- },
92
- },
93
- required: ['query'],
94
- },
95
- },
96
- ];
97
- /**
98
- * Create and configure MCP server
99
- */
100
- const server = new Server({
101
- name: 'b4m-tools',
102
- version: '1.0.0',
103
- }, {
104
- capabilities: {
105
- tools: {},
106
- },
107
- });
108
- /**
109
- * Handle tool list requests
110
- */
111
- server.setRequestHandler(ListToolsRequestSchema, async () => {
112
- return {
113
- tools: TOOLS,
114
- };
115
- });
116
- /**
117
- * Handle tool execution requests
118
- */
119
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
120
- const { name: toolName, arguments: toolArgs } = request.params;
121
- try {
122
- // Validate tool exists
123
- const tool = TOOLS.find(t => t.name === toolName);
124
- if (!tool) {
125
- throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${toolName}`);
126
- }
127
- // Execute tool via backend API
128
- const result = await client.executeTool(toolName, toolArgs || {});
129
- // Handle backend errors
130
- if (!result.success) {
131
- throw new McpError(ErrorCode.InternalError, result.error?.message || 'Tool execution failed', result.error?.details);
132
- }
133
- // Return successful result
134
- return {
135
- content: [
136
- {
137
- type: 'text',
138
- text: JSON.stringify(result.data, null, 2),
139
- },
140
- ],
141
- };
142
- }
143
- catch (error) {
144
- // Re-throw McpErrors
145
- if (error instanceof McpError) {
146
- throw error;
147
- }
148
- // Wrap other errors
149
- throw new McpError(ErrorCode.InternalError, error instanceof Error ? error.message : 'Unknown error occurred', {
150
- error: String(error),
151
- });
152
- }
153
- });
154
- /**
155
- * Start the MCP server
156
- */
157
- async function main() {
158
- // Test connection to backend
159
- const isConnected = await client.testConnection();
160
- if (!isConnected) {
161
- console.error(`Warning: Could not connect to backend API at ${API_URL}`);
162
- console.error('Server will start but tool execution may fail.');
163
- }
164
- else {
165
- console.error(`Connected to B4M API at ${API_URL}`);
166
- }
167
- // Start stdio transport
168
- const transport = new StdioServerTransport();
169
- await server.connect(transport);
170
- console.error('B4M MCP Proxy Server running on stdio');
171
- console.error(`Available tools: ${TOOLS.map(t => t.name).join(', ')}`);
172
- }
173
- // Handle errors
174
- process.on('uncaughtException', error => {
175
- console.error('Uncaught exception:', error);
176
- process.exit(1);
177
- });
178
- process.on('unhandledRejection', reason => {
179
- console.error('Unhandled rejection:', reason);
180
- process.exit(1);
181
- });
182
- // Start server
183
- main().catch(error => {
184
- console.error('Failed to start server:', error);
185
- process.exit(1);
186
- });
187
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,QAAQ,EACR,SAAS,GAEV,MAAM,oCAAoC,CAAC;AAC5C,OAA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