cloud-pc-templates 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/handlers/ollamacloud.js +67 -46
- package/package.json +1 -1
package/handlers/ollamacloud.js
CHANGED
|
@@ -19,36 +19,41 @@ function promptForApiKey() {
|
|
|
19
19
|
stdin.resume();
|
|
20
20
|
|
|
21
21
|
let apiKey = '';
|
|
22
|
-
let isFirstInput = true;
|
|
23
22
|
|
|
24
|
-
stdin.on('data', (
|
|
25
|
-
const
|
|
23
|
+
stdin.on('data', (buffer) => {
|
|
24
|
+
const chunk = buffer.toString();
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
process.
|
|
26
|
+
// Process each character in the chunk (handles pasted text)
|
|
27
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
28
|
+
const char = chunk[i];
|
|
29
|
+
|
|
30
|
+
if (char === '\n' || char === '\r' || char === '\u0004') {
|
|
31
|
+
// Enter or EOF
|
|
32
|
+
if (stdin.isTTY) {
|
|
33
|
+
stdin.setRawMode(false);
|
|
34
|
+
}
|
|
35
|
+
stdin.pause();
|
|
36
|
+
stdin.removeAllListeners('data');
|
|
37
|
+
console.log('');
|
|
38
|
+
resolve(apiKey);
|
|
39
|
+
return;
|
|
40
|
+
} else if (char === '\u0003') {
|
|
41
|
+
// Ctrl+C
|
|
42
|
+
if (stdin.isTTY) {
|
|
43
|
+
stdin.setRawMode(false);
|
|
44
|
+
}
|
|
45
|
+
process.exit();
|
|
46
|
+
} else if (char === '\x7f' || char === '\b') {
|
|
47
|
+
// Backspace
|
|
48
|
+
if (apiKey.length > 0) {
|
|
49
|
+
apiKey = apiKey.slice(0, -1);
|
|
50
|
+
process.stdout.write('\x1b[D\x1b[K');
|
|
51
|
+
}
|
|
52
|
+
} else if (char >= '\x20' && char <= '\x7e') {
|
|
53
|
+
// Printable character
|
|
54
|
+
apiKey += char;
|
|
55
|
+
process.stdout.write('*');
|
|
47
56
|
}
|
|
48
|
-
} else if (char >= '\x20' && char <= '\x7e') {
|
|
49
|
-
// Printable character
|
|
50
|
-
apiKey += char;
|
|
51
|
-
process.stdout.write('*');
|
|
52
57
|
}
|
|
53
58
|
});
|
|
54
59
|
});
|
|
@@ -92,30 +97,46 @@ async function downloadAndRunProxy(endpoint) {
|
|
|
92
97
|
// Get API key from user
|
|
93
98
|
const apiKey = await promptForApiKey();
|
|
94
99
|
|
|
95
|
-
// Run the proxy with API key passed as
|
|
100
|
+
// Run the proxy with API key passed as command-line argument
|
|
96
101
|
return new Promise((resolve, reject) => {
|
|
97
|
-
const
|
|
98
|
-
const child = spawn('node', [tempFile], { env });
|
|
102
|
+
const child = spawn('node', [tempFile, apiKey]);
|
|
99
103
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
console.log(` - Endpoint: ${endpoint}`);
|
|
111
|
-
}
|
|
112
|
-
resolve();
|
|
113
|
-
}, 1000);
|
|
114
|
-
} else {
|
|
115
|
-
reject(new Error('Proxy process failed'));
|
|
104
|
+
let serverReady = false;
|
|
105
|
+
|
|
106
|
+
// Capture stdout to detect when server is ready
|
|
107
|
+
child.stdout.on('data', (data) => {
|
|
108
|
+
const output = data.toString();
|
|
109
|
+
console.log(output);
|
|
110
|
+
|
|
111
|
+
// Check if server indicates it's ready
|
|
112
|
+
if (output.includes('listening') || output.includes('started') || output.includes('running')) {
|
|
113
|
+
serverReady = true;
|
|
116
114
|
}
|
|
117
115
|
});
|
|
118
116
|
|
|
117
|
+
// Capture stderr for error messages
|
|
118
|
+
child.stderr.on('data', (data) => {
|
|
119
|
+
console.error(data.toString());
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Wait a bit for server to start, then validate
|
|
123
|
+
setTimeout(async () => {
|
|
124
|
+
try {
|
|
125
|
+
const isHealthy = await checkHealthEndpoint(endpoint);
|
|
126
|
+
if (isHealthy) {
|
|
127
|
+
console.log('✓ Logged in');
|
|
128
|
+
console.log(` - Endpoint checked: ${endpoint}`);
|
|
129
|
+
resolve();
|
|
130
|
+
} else {
|
|
131
|
+
console.log('✓ Proxy started');
|
|
132
|
+
console.log(` - Endpoint: ${endpoint}`);
|
|
133
|
+
resolve();
|
|
134
|
+
}
|
|
135
|
+
} catch (error) {
|
|
136
|
+
reject(error);
|
|
137
|
+
}
|
|
138
|
+
}, 2000);
|
|
139
|
+
|
|
119
140
|
child.on('error', reject);
|
|
120
141
|
});
|
|
121
142
|
}
|