ydc-agent 1.0.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.
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Models Route
3
+ */
4
+
5
+ import { Router } from 'express';
6
+ import { authenticate } from '../auth-middleware.js';
7
+ import { listAdvancedVersions, getVersionInfo, getDefaultAdvancedVersion } from '../advanced-versions.js';
8
+
9
+ const router = Router();
10
+
11
+ // Parse custom agents from env
12
+ function getCustomAgents() {
13
+ const raw = process.env.YDC_CUSTOM_AGENTS || '';
14
+ if (!raw) return [];
15
+
16
+ return raw.split(',').map(entry => {
17
+ const trimmed = entry.trim();
18
+ if (!trimmed) return null;
19
+
20
+ // Format: name:id or just id
21
+ const colonIndex = trimmed.indexOf(':');
22
+ if (colonIndex > 0) {
23
+ return {
24
+ name: trimmed.substring(0, colonIndex),
25
+ id: trimmed.substring(colonIndex + 1)
26
+ };
27
+ }
28
+ return { name: trimmed, id: trimmed };
29
+ }).filter(Boolean);
30
+ }
31
+
32
+ router.get('/v1/models', authenticate, (req, res) => {
33
+ const baseModels = [
34
+ {
35
+ id: 'advanced',
36
+ object: 'model',
37
+ created: Math.floor(Date.now() / 1000),
38
+ owned_by: 'you-com',
39
+ permission: [],
40
+ root: 'advanced',
41
+ parent: null
42
+ },
43
+ {
44
+ id: 'express',
45
+ object: 'model',
46
+ created: Math.floor(Date.now() / 1000),
47
+ owned_by: 'you-com',
48
+ permission: [],
49
+ root: 'express',
50
+ parent: null
51
+ },
52
+ {
53
+ id: 'research',
54
+ object: 'model',
55
+ created: Math.floor(Date.now() / 1000),
56
+ owned_by: 'you-com',
57
+ permission: [],
58
+ root: 'research',
59
+ parent: null
60
+ }
61
+ ];
62
+
63
+ // Add custom agents from env/CLI
64
+ const customAgents = getCustomAgents();
65
+ const customModels = customAgents.map(agent => ({
66
+ id: agent.name,
67
+ object: 'model',
68
+ created: Math.floor(Date.now() / 1000),
69
+ owned_by: 'you-com',
70
+ permission: [],
71
+ root: 'custom',
72
+ parent: null,
73
+ agent_id: agent.id,
74
+ description: `Custom agent${agent.name !== agent.id ? ` (${agent.id})` : ''}`
75
+ }));
76
+
77
+ const advancedVersionModels = listAdvancedVersions().map(version => {
78
+ const versionInfo = getVersionInfo(version);
79
+ return {
80
+ id: version,
81
+ object: 'model',
82
+ created: Math.floor(Date.now() / 1000),
83
+ owned_by: 'you-com',
84
+ permission: [],
85
+ root: 'advanced',
86
+ parent: 'advanced',
87
+ description: versionInfo.description,
88
+ tools: versionInfo.tools
89
+ };
90
+ });
91
+
92
+ res.json({
93
+ object: 'list',
94
+ data: [...baseModels, ...customModels, ...advancedVersionModels]
95
+ });
96
+ });
97
+
98
+ router.get('/v1/versions', authenticate, (req, res) => {
99
+ const versions = listAdvancedVersions().map(version => getVersionInfo(version));
100
+ res.json({
101
+ object: 'list',
102
+ data: versions,
103
+ default_version: getDefaultAdvancedVersion(),
104
+ temperature_mapping: {
105
+ "0.0-0.5": "Uses medium verbosity versions with reduced workflow steps",
106
+ "0.5-1.0": "Uses high verbosity versions with increased workflow steps"
107
+ }
108
+ });
109
+ });
110
+
111
+ export default router;
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * OpenAI-Compatible HTTP Server for You.com Agents
5
+ * Provides a REST API that mimics OpenAI's chat completions endpoint
6
+ * Supports multi-user, multi-conversation sessions
7
+ */
8
+
9
+ import express from 'express';
10
+ import cors from 'cors';
11
+ import { createServer } from 'http';
12
+
13
+ // Import routes
14
+ import chatRoutes from './lib/routes/chat.js';
15
+ import modelsRoutes from './lib/routes/models.js';
16
+ import conversationsRoutes from './lib/routes/conversations.js';
17
+ import healthRoutes from './lib/routes/health.js';
18
+ import anthropicRoutes from './lib/routes/anthropic-messages.js';
19
+
20
+ // Import config
21
+ import { storeConfig, initDatabase } from './lib/conversation-store.js';
22
+ import { authConfig } from './lib/auth-middleware.js';
23
+ import { listAdvancedVersions, getDefaultAdvancedVersion } from './lib/advanced-versions.js';
24
+
25
+ const app = express();
26
+ const startPort = parseInt(process.env.YDC_OPENAI_PORT) || 3002;
27
+ const API_KEY = process.env.YDC_API_KEY;
28
+
29
+ // Function to find available port
30
+ async function findAvailablePort(startPort, maxAttempts = 10) {
31
+ for (let i = 0; i < maxAttempts; i++) {
32
+ const port = startPort + i;
33
+ try {
34
+ await new Promise((resolve, reject) => {
35
+ const server = createServer();
36
+ server.listen(port, () => {
37
+ server.close(() => resolve());
38
+ });
39
+ server.on('error', reject);
40
+ });
41
+ return port;
42
+ } catch (error) {
43
+ if (error.code !== 'EADDRINUSE') {
44
+ throw error;
45
+ }
46
+ }
47
+ }
48
+ throw new Error(`No available port found starting from ${startPort}`);
49
+ }
50
+
51
+ // Middleware
52
+ app.use(cors());
53
+ app.use(express.json());
54
+
55
+ // Routes
56
+ app.use(chatRoutes);
57
+ app.use(modelsRoutes);
58
+ app.use(conversationsRoutes);
59
+ app.use(healthRoutes);
60
+ app.use(anthropicRoutes);
61
+
62
+ // Start server with auto port detection
63
+ async function startServer() {
64
+ try {
65
+ // Initialize database (handles missing better-sqlite3 gracefully)
66
+ await initDatabase();
67
+
68
+ const port = await findAvailablePort(startPort);
69
+ app.set('port', port);
70
+
71
+ app.listen(port, () => {
72
+ console.log(`šŸš€ You.com OpenAI-Compatible Server running on port ${port}`);
73
+ console.log(`šŸ“‹ Base URL: http://localhost:${port}`);
74
+ console.log(`šŸ”‘ YDC API Key configured: ${!!API_KEY}`);
75
+ console.log(`šŸ“¦ Conversation Store: ${storeConfig.STORE_TYPE}${storeConfig.STORE_TYPE === 'sqlite' && storeConfig.isDbConnected() ? ` (${storeConfig.DB_PATH})` : ''}`);
76
+ console.log(`šŸ” Token Auth: ${authConfig.REQUIRE_TOKEN_AUTH ? `enabled (${authConfig.ACCESS_TOKENS_COUNT} tokens)` : 'disabled (accept all)'}`);
77
+ console.log(`\nšŸ“– Endpoints:`);
78
+ console.log(` POST http://localhost:${port}/v1/chat/completions (OpenAI)`);
79
+ console.log(` POST http://localhost:${port}/v1/messages (Anthropic/Claude)`);
80
+ console.log(` GET http://localhost:${port}/v1/models`);
81
+ console.log(` GET http://localhost:${port}/v1/versions`);
82
+ console.log(` GET http://localhost:${port}/health`);
83
+ console.log(` GET/POST/DELETE http://localhost:${port}/v1/conversations`);
84
+
85
+ try {
86
+ const versions = listAdvancedVersions();
87
+ const defaultVersion = getDefaultAdvancedVersion();
88
+ console.log(`\nšŸŽÆ Advanced Versions: ${versions.length} available (default: ${defaultVersion})`);
89
+ } catch (error) {
90
+ console.error('āŒ Error loading advanced versions:', error.message);
91
+ }
92
+ });
93
+ } catch (error) {
94
+ console.error('āŒ Failed to start server:', error.message);
95
+ process.exit(1);
96
+ }
97
+ }
98
+
99
+ startServer();
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "ydc-agent",
3
+ "version": "1.0.0",
4
+ "description": "MCP server for You.com Agents API - Express, Research, Advanced agents with multi-turn conversations, streaming, OpenAI and Anthropic/Claude API compatibility",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "bin": {
8
+ "ydc-agent": "./index.js"
9
+ },
10
+ "files": [
11
+ "index.js",
12
+ "openai-server.js",
13
+ "lib/",
14
+ "README.md",
15
+ "README_ZH_TW.md",
16
+ "README_ZH_CN.md",
17
+ "README_JA.md"
18
+ ],
19
+ "scripts": {
20
+ "start": "node index.js",
21
+ "start:openai": "node openai-server.js",
22
+ "test": "node tests/test.js",
23
+ "test:api": "node tests/test-api.js",
24
+ "test:streaming": "node tests/test-streaming.js",
25
+ "test:mcp": "node tests/test-mcp-tools.js",
26
+ "load-test": "node tools/load-test.js",
27
+ "prepublishOnly": "echo 'Ready to publish'"
28
+ },
29
+ "dependencies": {
30
+ "@modelcontextprotocol/sdk": "^1.25.1",
31
+ "sql.js": "^1.11.0"
32
+ },
33
+ "optionalDependencies": {
34
+ "chalk": "^5.6.2",
35
+ "cli-progress": "^3.12.0",
36
+ "cli-table3": "^0.6.5",
37
+ "cors": "^2.8.5",
38
+ "express": "^4.18.2",
39
+ "node-fetch": "^3.3.2"
40
+ },
41
+ "engines": {
42
+ "node": ">=18.0.0"
43
+ },
44
+ "keywords": [
45
+ "mcp",
46
+ "you.com",
47
+ "ydc",
48
+ "agents",
49
+ "ai",
50
+ "research",
51
+ "advanced",
52
+ "streaming",
53
+ "openai",
54
+ "chat",
55
+ "conversation"
56
+ ],
57
+ "author": "linuxdo-ref",
58
+ "license": "MIT",
59
+ "homepage": "https://github.com/linuxdo-ref/ydc-agent",
60
+ "repository": {
61
+ "type": "git",
62
+ "url": "git+https://github.com/linuxdo-ref/ydc-agent.git"
63
+ },
64
+ "bugs": {
65
+ "url": "https://github.com/linuxdo-ref/ydc-agent/issues"
66
+ },
67
+ "publishConfig": {
68
+ "access": "public"
69
+ }
70
+ }