opc-agent 4.0.40 → 4.0.41
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/dist/studio/server.js +6 -3
- package/package.json +1 -1
- package/serve-test.js +25 -0
- package/src/studio/server.ts +6 -3
- package/test-full.js +43 -0
- package/test-sidebar.js +22 -0
package/dist/studio/server.js
CHANGED
|
@@ -737,15 +737,18 @@ class StudioServer {
|
|
|
737
737
|
try {
|
|
738
738
|
const completionReq = (0, http_1.request)({
|
|
739
739
|
hostname: 'localhost',
|
|
740
|
-
port:
|
|
740
|
+
port: 3000,
|
|
741
741
|
path: '/v1/chat/completions',
|
|
742
742
|
method: 'POST',
|
|
743
743
|
headers: { 'Content-Type': 'application/json' },
|
|
744
744
|
}, (completionRes) => {
|
|
745
|
-
|
|
745
|
+
const ct = completionRes.headers['content-type'] || '';
|
|
746
|
+
if (completionRes.statusCode === 200 && (ct.includes('text/event-stream') || ct.includes('application/json'))) {
|
|
746
747
|
completionRes.pipe(res);
|
|
747
748
|
}
|
|
748
749
|
else {
|
|
750
|
+
// Drain the response to avoid leak
|
|
751
|
+
completionRes.resume();
|
|
749
752
|
// Fallback to simulated response
|
|
750
753
|
this.sendSimulatedResponse(res, lastMsg, agent);
|
|
751
754
|
}
|
|
@@ -1337,7 +1340,7 @@ class StudioServer {
|
|
|
1337
1340
|
const indexPath = (0, path_1.join)(this.config.staticDir, 'index.html');
|
|
1338
1341
|
if ((0, fs_1.existsSync)(indexPath)) {
|
|
1339
1342
|
const content = (0, fs_1.readFileSync)(indexPath, 'utf-8');
|
|
1340
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
1343
|
+
res.writeHead(200, { 'Content-Type': 'text/html', 'Cache-Control': 'no-cache, no-store, must-revalidate' });
|
|
1341
1344
|
res.end(content);
|
|
1342
1345
|
return;
|
|
1343
1346
|
}
|
package/package.json
CHANGED
package/serve-test.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const http = require('http');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const html = fs.readFileSync('C:/Users/mingjwan/tmp-opc-clone/dist/studio-ui/index.html', 'utf-8');
|
|
5
|
+
const agentsDir = path.join(require('os').homedir(), '.opc', 'agents');
|
|
6
|
+
|
|
7
|
+
const srv = http.createServer((req, res) => {
|
|
8
|
+
if (req.url === '/api/agents') {
|
|
9
|
+
const files = fs.readdirSync(agentsDir).filter(f => f.endsWith('.json'));
|
|
10
|
+
const agents = files.map(f => {
|
|
11
|
+
try { return JSON.parse(fs.readFileSync(path.join(agentsDir, f), 'utf-8')); } catch { return null; }
|
|
12
|
+
}).filter(Boolean);
|
|
13
|
+
res.writeHead(200, {'Content-Type':'application/json'});
|
|
14
|
+
res.end(JSON.stringify({agents}));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (req.url === '/api/templates') {
|
|
18
|
+
res.writeHead(200, {'Content-Type':'application/json'});
|
|
19
|
+
res.end(JSON.stringify({templates:[], industries:[]}));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
res.writeHead(200, {'Content-Type':'text/html; charset=utf-8'});
|
|
23
|
+
res.end(html);
|
|
24
|
+
});
|
|
25
|
+
srv.listen(4000, '0.0.0.0', () => console.log('Studio: http://localhost:4000'));
|
package/src/studio/server.ts
CHANGED
|
@@ -739,14 +739,17 @@ class StudioServer {
|
|
|
739
739
|
try {
|
|
740
740
|
const completionReq = httpRequest({
|
|
741
741
|
hostname: 'localhost',
|
|
742
|
-
port:
|
|
742
|
+
port: 3000,
|
|
743
743
|
path: '/v1/chat/completions',
|
|
744
744
|
method: 'POST',
|
|
745
745
|
headers: { 'Content-Type': 'application/json' },
|
|
746
746
|
}, (completionRes) => {
|
|
747
|
-
|
|
747
|
+
const ct = completionRes.headers['content-type'] || '';
|
|
748
|
+
if (completionRes.statusCode === 200 && (ct.includes('text/event-stream') || ct.includes('application/json'))) {
|
|
748
749
|
completionRes.pipe(res);
|
|
749
750
|
} else {
|
|
751
|
+
// Drain the response to avoid leak
|
|
752
|
+
completionRes.resume();
|
|
750
753
|
// Fallback to simulated response
|
|
751
754
|
this.sendSimulatedResponse(res, lastMsg, agent);
|
|
752
755
|
}
|
|
@@ -1348,7 +1351,7 @@ class StudioServer {
|
|
|
1348
1351
|
const indexPath = join(this.config.staticDir, 'index.html');
|
|
1349
1352
|
if (existsSync(indexPath)) {
|
|
1350
1353
|
const content = readFileSync(indexPath, 'utf-8');
|
|
1351
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
1354
|
+
res.writeHead(200, { 'Content-Type': 'text/html', 'Cache-Control': 'no-cache, no-store, must-revalidate' });
|
|
1352
1355
|
res.end(content);
|
|
1353
1356
|
return;
|
|
1354
1357
|
}
|
package/test-full.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const puppeteer = require('puppeteer-core');
|
|
2
|
+
(async () => {
|
|
3
|
+
const browser = await puppeteer.launch({executablePath: 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe', headless: true, args:['--no-sandbox']});
|
|
4
|
+
const page = await browser.newPage();
|
|
5
|
+
const errors = [];
|
|
6
|
+
page.on('pageerror', e => errors.push(e.message));
|
|
7
|
+
await page.goto('http://localhost:4000', {waitUntil:'networkidle0', timeout:10000});
|
|
8
|
+
|
|
9
|
+
const result = await page.evaluate(() => {
|
|
10
|
+
const sidebar = document.getElementById('sidebar-agent-list');
|
|
11
|
+
const sidebarHTML = sidebar ? sidebar.innerHTML : 'NOT FOUND';
|
|
12
|
+
const allPages = Array.from(document.querySelectorAll('.page')).map(p => p.id);
|
|
13
|
+
const activePage = document.querySelector('.page.active');
|
|
14
|
+
const navItems = Array.from(document.querySelectorAll('.sidebar .nav-item, .sidebar .agent-list-item, .sidebar .sidebar-section-title')).map(el => el.textContent.trim().substring(0, 30));
|
|
15
|
+
|
|
16
|
+
// Try clicking agent
|
|
17
|
+
if (typeof navigateToAgent === 'function') {
|
|
18
|
+
navigateToAgent('my-first-agent');
|
|
19
|
+
}
|
|
20
|
+
const afterClick = document.querySelector('.page.active');
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
sidebarHTML: sidebarHTML.substring(0, 300),
|
|
24
|
+
activePage: activePage ? activePage.id : 'none',
|
|
25
|
+
afterClick: afterClick ? afterClick.id : 'none',
|
|
26
|
+
navItems,
|
|
27
|
+
bodyFontSize: window.getComputedStyle(document.body).fontSize,
|
|
28
|
+
pageCount: allPages.length
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log('=== Full Validation ===');
|
|
33
|
+
console.log('JS errors:', errors.length ? errors : 'NONE');
|
|
34
|
+
console.log('Body font-size:', result.bodyFontSize);
|
|
35
|
+
console.log('Sidebar HTML:', result.sidebarHTML);
|
|
36
|
+
console.log('Nav items:', JSON.stringify(result.navItems));
|
|
37
|
+
console.log('Default active page:', result.activePage);
|
|
38
|
+
console.log('After click agent:', result.afterClick);
|
|
39
|
+
console.log('Total pages:', result.pageCount);
|
|
40
|
+
|
|
41
|
+
await browser.close();
|
|
42
|
+
process.exit(0);
|
|
43
|
+
})().catch(e => { console.error('FAIL:', e.message); process.exit(1); });
|
package/test-sidebar.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const puppeteer = require('puppeteer-core');
|
|
2
|
+
(async () => {
|
|
3
|
+
const browser = await puppeteer.launch({executablePath: 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe', headless: true, args:['--no-sandbox']});
|
|
4
|
+
const page = await browser.newPage();
|
|
5
|
+
const errors = [];
|
|
6
|
+
page.on('pageerror', e => errors.push(e.message));
|
|
7
|
+
page.on('console', m => { if(m.type()==='error') errors.push('CONSOLE:'+m.text()); });
|
|
8
|
+
await page.goto('http://localhost:4000', {waitUntil:'networkidle0', timeout:10000});
|
|
9
|
+
|
|
10
|
+
const result = await page.evaluate(() => {
|
|
11
|
+
const container = document.getElementById('sidebar-agent-list');
|
|
12
|
+
const html = container ? container.innerHTML : 'NOT FOUND';
|
|
13
|
+
const agents = window._sidebarAgents;
|
|
14
|
+
return { html: html.substring(0, 300), agents: agents ? agents.length : 'undefined', errors: [] };
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
console.log('JS errors:', errors.length ? errors : 'NONE');
|
|
18
|
+
console.log('Sidebar HTML:', result.html);
|
|
19
|
+
console.log('Agents count:', result.agents);
|
|
20
|
+
await browser.close();
|
|
21
|
+
process.exit(0);
|
|
22
|
+
})().catch(e => { console.error('FAIL:', e.message); process.exit(1); });
|