pi-web 0.9.1 → 0.10.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.
package/build/server/server.js
CHANGED
|
@@ -299,6 +299,37 @@ function registerDiscoveredSessionKey(managed, event) {
|
|
|
299
299
|
const key = buildSessionKey(managed.cwd, basename(sessionPath));
|
|
300
300
|
registerManagedSessionKey(managed, key);
|
|
301
301
|
}
|
|
302
|
+
function deriveModelSupportsImages(model) {
|
|
303
|
+
if (!model || typeof model !== 'object')
|
|
304
|
+
return null;
|
|
305
|
+
const input = model.input;
|
|
306
|
+
if (!Array.isArray(input))
|
|
307
|
+
return null;
|
|
308
|
+
return input.includes('image');
|
|
309
|
+
}
|
|
310
|
+
function updateSessionModelCapability(managed, event) {
|
|
311
|
+
if (!event || typeof event !== 'object')
|
|
312
|
+
return;
|
|
313
|
+
if (event.type === 'model_changed') {
|
|
314
|
+
const supports = deriveModelSupportsImages(event.model);
|
|
315
|
+
if (supports != null)
|
|
316
|
+
managed.currentModelSupportsImages = supports;
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (event.type === 'response') {
|
|
320
|
+
if (event.command === 'get_state') {
|
|
321
|
+
const supports = deriveModelSupportsImages(event.data?.model);
|
|
322
|
+
if (supports != null)
|
|
323
|
+
managed.currentModelSupportsImages = supports;
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
if (event.command === 'set_model' && event.success) {
|
|
327
|
+
const supports = deriveModelSupportsImages(event.data);
|
|
328
|
+
if (supports != null)
|
|
329
|
+
managed.currentModelSupportsImages = supports;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
302
333
|
function createManagedSession(cwd, sessionFile) {
|
|
303
334
|
const sessionPath = sessionFile ? getSessionFilePath(cwd, sessionFile, AGENT) : undefined;
|
|
304
335
|
let managed = null;
|
|
@@ -317,6 +348,7 @@ function createManagedSession(cwd, sessionFile) {
|
|
|
317
348
|
managed.isAgentRunning = false;
|
|
318
349
|
cleanupIfIdle(managed);
|
|
319
350
|
}
|
|
351
|
+
updateSessionModelCapability(managed, event);
|
|
320
352
|
registerDiscoveredSessionKey(managed, event);
|
|
321
353
|
broadcast(managed, { type: 'rpc_event', event });
|
|
322
354
|
},
|
|
@@ -346,6 +378,7 @@ function createManagedSession(cwd, sessionFile) {
|
|
|
346
378
|
rpc,
|
|
347
379
|
clients: new Set(),
|
|
348
380
|
isAgentRunning: false,
|
|
381
|
+
currentModelSupportsImages: null,
|
|
349
382
|
keys: new Set(),
|
|
350
383
|
idleCleanupTimer: null,
|
|
351
384
|
isClosing: false,
|
|
@@ -394,7 +427,19 @@ wss.on('connection', (ws) => {
|
|
|
394
427
|
sendToSocket(ws, { type: 'error', message: 'no active session' });
|
|
395
428
|
return;
|
|
396
429
|
}
|
|
397
|
-
|
|
430
|
+
const command = msg.command;
|
|
431
|
+
const isPromptLikeCommand = command?.type === 'prompt' || command?.type === 'steer' || command?.type === 'follow_up';
|
|
432
|
+
const hasImages = Array.isArray(command?.images) && command.images.length > 0;
|
|
433
|
+
if (isPromptLikeCommand &&
|
|
434
|
+
hasImages &&
|
|
435
|
+
managed.currentModelSupportsImages === false) {
|
|
436
|
+
sendToSocket(ws, {
|
|
437
|
+
type: 'error',
|
|
438
|
+
message: 'selected model does not support file attachments',
|
|
439
|
+
});
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
managed.rpc.send(command);
|
|
398
443
|
return;
|
|
399
444
|
}
|
|
400
445
|
if (msg.type === 'ping') {
|