@blockrun/cc 0.8.0 → 0.8.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/dist/proxy/server.js +18 -2
- package/package.json +1 -1
package/dist/proxy/server.js
CHANGED
|
@@ -37,9 +37,20 @@ function detectModelSwitch(parsed) {
|
|
|
37
37
|
if (!parsed.messages || parsed.messages.length === 0)
|
|
38
38
|
return null;
|
|
39
39
|
const last = parsed.messages[parsed.messages.length - 1];
|
|
40
|
-
if (last.role !== 'user'
|
|
40
|
+
if (last.role !== 'user')
|
|
41
41
|
return null;
|
|
42
|
-
|
|
42
|
+
let content = '';
|
|
43
|
+
if (typeof last.content === 'string') {
|
|
44
|
+
content = last.content;
|
|
45
|
+
}
|
|
46
|
+
else if (Array.isArray(last.content)) {
|
|
47
|
+
const textBlock = last.content.find(b => b.type === 'text' && b.text);
|
|
48
|
+
if (textBlock && textBlock.text)
|
|
49
|
+
content = textBlock.text;
|
|
50
|
+
}
|
|
51
|
+
if (!content)
|
|
52
|
+
return null;
|
|
53
|
+
content = content.trim().toLowerCase();
|
|
43
54
|
const match = content.match(/^use\s+(.+)$/);
|
|
44
55
|
if (!match)
|
|
45
56
|
return null;
|
|
@@ -82,10 +93,15 @@ export function createProxy(options) {
|
|
|
82
93
|
});
|
|
83
94
|
req.on('end', async () => {
|
|
84
95
|
try {
|
|
96
|
+
debug(options, `request: ${req.method} ${req.url} currentModel=${currentModel || 'none'}`);
|
|
85
97
|
if (body) {
|
|
86
98
|
try {
|
|
87
99
|
const parsed = JSON.parse(body);
|
|
88
100
|
// Intercept "use <model>" commands for in-session model switching
|
|
101
|
+
if (parsed.messages) {
|
|
102
|
+
const last = parsed.messages[parsed.messages.length - 1];
|
|
103
|
+
debug(options, `last msg role=${last?.role} content-type=${typeof last?.content} content=${JSON.stringify(last?.content).slice(0, 200)}`);
|
|
104
|
+
}
|
|
89
105
|
const switchCmd = detectModelSwitch(parsed);
|
|
90
106
|
if (switchCmd) {
|
|
91
107
|
currentModel = switchCmd;
|