@pi-chamber/web 0.3.3 → 0.5.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/README.md +1 -0
- package/bin/lib/cli-startup.js +1 -0
- package/dist/assets/CommitSection-Cz-ACBaD.js +1 -0
- package/dist/assets/DiagramEditor-BNUOrd9m.js +1 -0
- package/dist/assets/DiagramView-D4YR9YRt.js +1 -0
- package/dist/assets/{DiffView-DGD9DMS7.js → DiffView-DPW8dcg_.js} +3 -3
- package/dist/assets/FilesView-BFGIdY6b.js +14 -0
- package/dist/assets/GitView-CKtiKOfJ.js +6 -0
- package/dist/assets/JsonTreeView-c-UJUw3D.js +1 -0
- package/dist/assets/{MarkdownRendererImpl-V1HMFCjr.js → MarkdownRendererImpl-CvC9eXoa.js} +2 -2
- package/dist/assets/PatchDiff-YGHsZUIR.js +1 -0
- package/dist/assets/PierreDiffViewer-CoXa-JJK.js +136 -0
- package/dist/assets/SessionSwitcherContent-B7eep3dO.js +1 -0
- package/dist/assets/SessionSwitcherDropdown-CZOFeJHH.js +2 -0
- package/dist/assets/SessionUnreadDot-ClpeYFPz.js +1 -0
- package/dist/assets/SettingsView-CPmHHDbQ.js +4 -0
- package/dist/assets/SettingsWindow-2CBpoJ8H.js +1 -0
- package/dist/assets/{ToolOutputDialog-2zKUdGYL.js → ToolOutputDialog-HMW-Kh19.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-C3nbNbxk.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-UMgLcO4Q.js → VirtualizedFileDiff-DEX83nQ0.js} +3 -3
- package/dist/assets/{SessionSwitcherDropdown-o1RjhCfF.js → WindowsWindowControls-PPk5H89-.js} +172 -118
- package/dist/assets/collapsible-Dux-9hAC.js +1 -0
- package/dist/assets/computeVirtualFileMetrics-Cy0nxMJB.js +3 -0
- package/dist/assets/contextFileOpenGuard-Dn_38hd9.js +1 -0
- package/dist/assets/index--zDkVFU6.css +1 -0
- package/dist/assets/index-DU2OBBy5.js +8 -0
- package/dist/assets/index-EN7MioVf.js +1 -0
- package/dist/assets/isDiffPlainText-DSWRVq-W.js +1 -0
- package/dist/assets/isFilePlainText-7RAjjrQ5.js +1 -0
- package/dist/assets/{main-CmkRaMOR.js → main-BGKjg-qW.js} +8 -8
- package/dist/assets/main-DGHrBx_u.js +2 -0
- package/dist/assets/markdownCore-BYPqQtbE.js +3 -0
- package/dist/assets/miniChat-DW2PVX49.js +2 -0
- package/dist/assets/mobile-0Gxc02iO.js +2 -0
- package/dist/assets/renderElectronMiniChatApp-C-qpqp1i.js +2 -0
- package/dist/assets/renderMobileApp-UB9bhC1x.js +14 -0
- package/dist/assets/{runtimeSurface-CkHYYg0E.js → runtimeSurface-DefD-2Iv.js} +1 -1
- package/dist/assets/{useInlineCommentController-DD31jQNC.js → useInlineCommentController-B8p2XwXA.js} +2 -2
- package/dist/assets/usePanelSlide-CbqVf-y8.js +56 -0
- package/dist/assets/usePushVisibilityBeacon-CvjN-47R.js +10 -0
- package/dist/assets/useSwitcherItems-B6_F-J-z.js +1 -0
- package/dist/assets/{vendor-codemirror-language-data-Dp_Z-0GD.js → vendor-codemirror-language-data-BhBdEPsJ.js} +2 -2
- package/dist/assets/{vendor-katex-CHD9BdDO.js → vendor-katex-CNckGUMB.js} +1 -1
- package/dist/assets/{vendor-marked-i_gIkIP3.js → vendor-marked-CX41MkDF.js} +1 -1
- package/dist/assets/{web-components-Cct1r-wn.js → web-components-C9yVPsWN.js} +2 -2
- package/dist/index.html +8 -5
- package/dist/mini-chat.html +7 -4
- package/dist/mobile.html +7 -4
- package/dist/sw.js +1 -1
- package/package.json +1 -1
- package/server/index.js +27 -5
- package/server/lib/fs/routes.js +0 -21
- package/server/lib/git/DOCUMENTATION.md +15 -5
- package/server/lib/git/issue-2746-longpaths.test.js +11 -11
- package/server/lib/git/routes.js +80 -4
- package/server/lib/git/routes.test.js +135 -0
- package/server/lib/git/service.js +144 -82
- package/server/lib/git/service.test.js +182 -36
- package/server/lib/pi/extension-protocol.js +62 -0
- package/server/lib/pi/extension-protocol.test.js +34 -0
- package/server/lib/pi/fixtures/pichamber-gui-demo.ts +251 -0
- package/server/lib/pi/routes-extension-events.test.js +152 -0
- package/server/lib/pi/routes.js +345 -7
- package/server/lib/pi/routes.test.js +43 -28
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +8 -5
- package/server/lib/pi/session-daemon/extension-bridge.js +488 -0
- package/server/lib/pi/session-daemon/message-entry-aliases.js +53 -13
- package/server/lib/pi/session-daemon/message-entry-aliases.test.js +110 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.e2e.test.js +215 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +559 -0
- package/server/lib/pi/session-daemon/session-daemon.js +483 -54
- package/server/lib/pi/session-daemon/session-daemon.test.js +212 -4
- package/server/lib/pi/session-daemon/session-retry-limits.js +55 -0
- package/server/lib/pi/session-daemon/session-retry-limits.test.js +53 -0
- package/server/lib/pi/session-daemon/skill-read-classifier.js +39 -0
- package/server/lib/pi/session-daemon/skill-read-classifier.test.js +41 -0
- package/server/lib/pi/session-daemon/supervisor.js +3 -0
- package/server/lib/pi/small-model-generation.js +104 -0
- package/server/lib/pi/small-model-generation.test.js +66 -0
- package/server/lib/preview/proxy-runtime.js +11 -1
- package/server/lib/preview/proxy-runtime.test.js +3 -0
- package/server/lib/relay/tunnel-host.js +1 -0
- package/server/lib/server/cors.js +0 -2
- package/server/lib/server/cors.test.js +4 -4
- package/server/lib/stt/DOCUMENTATION.md +38 -0
- package/server/lib/stt/audio.js +47 -0
- package/server/lib/stt/config-store.js +81 -0
- package/server/lib/stt/config-store.test.js +36 -0
- package/server/lib/stt/local/model-catalog.js +57 -0
- package/server/lib/stt/local/model-downloader.js +127 -0
- package/server/lib/stt/local/recognizer.js +64 -0
- package/server/lib/stt/local/sherpa-loader.js +43 -0
- package/server/lib/stt/local/worker-client.js +115 -0
- package/server/lib/stt/local/worker-process.js +64 -0
- package/server/lib/stt/protocol.js +38 -0
- package/server/lib/stt/protocol.test.js +17 -0
- package/server/lib/stt/providers/local-worker-provider.js +11 -0
- package/server/lib/stt/providers/openai-compatible-provider.js +31 -0
- package/server/lib/stt/providers/openai-compatible-provider.test.js +31 -0
- package/server/lib/stt/runtime.js +111 -0
- package/server/lib/stt/service.js +106 -0
- package/server/lib/stt/stream-manager.js +188 -0
- package/server/lib/stt/stream-manager.test.js +64 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +1 -1
- package/server/lib/ui-auth/ui-auth.js +8 -3
- package/server/lib/ui-auth/ui-auth.test.js +8 -0
- package/server/lib/workspace/host.js +19 -3
- package/dist/assets/CommitSection-BAYzLtBf.js +0 -1
- package/dist/assets/DiagramEditor-D1yc4joK.js +0 -1
- package/dist/assets/DiagramView-CAlJiG11.js +0 -1
- package/dist/assets/FilesView-DB5VI7EN.js +0 -14
- package/dist/assets/GitView-CFlPcSn9.js +0 -6
- package/dist/assets/JsonTreeView-CoX1ZscV.js +0 -1
- package/dist/assets/PatchDiff-D6Gs7K5B.js +0 -1
- package/dist/assets/PierreDiffViewer-COYd5Qr-.js +0 -136
- package/dist/assets/SettingsView-BYqvfMTS.js +0 -4
- package/dist/assets/SettingsWindow-CtNS0tQn.js +0 -1
- package/dist/assets/ToolPartDiffPreview-CBFC9min.js +0 -8
- package/dist/assets/collapsible-Kx4bmsQM.js +0 -1
- package/dist/assets/computeVirtualFileMetrics-DdOCbMyK.js +0 -3
- package/dist/assets/contextFileOpenGuard-BRldMp0d.js +0 -1
- package/dist/assets/index-BAqpUCjs.js +0 -8
- package/dist/assets/index-CuSNEV7s.js +0 -1
- package/dist/assets/index-riABQmQ_.css +0 -1
- package/dist/assets/isDiffPlainText-CGIf0q8p.js +0 -1
- package/dist/assets/isFilePlainText-D4hgTRxT.js +0 -1
- package/dist/assets/main-By_pvk90.js +0 -2
- package/dist/assets/markdownCore-CAVCyFnI.js +0 -2
- package/dist/assets/miniChat-_XK2gGZE.js +0 -2
- package/dist/assets/mobile-B4E4JqAf.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-Ca4hZgIz.js +0 -1
- package/dist/assets/renderMobileApp-ClA5Cnmw.js +0 -14
- package/dist/assets/usePanelSlide-a4c67FIY.js +0 -56
- package/dist/assets/useWindowTitle-DoHrUC5r.js +0 -10
- package/server/lib/pi/legacy-ui-model-defaults.js +0 -57
- package/server/lib/pi/legacy-ui-model-defaults.test.js +0 -65
package/server/lib/pi/routes.js
CHANGED
|
@@ -7,10 +7,13 @@ import { createPiArchiveStore } from './archive-store.js';
|
|
|
7
7
|
import { createPiAttachmentStore } from './attachment-store.js';
|
|
8
8
|
import { checkForUpdates } from '../package-manager.js';
|
|
9
9
|
import { listPiCustomThemes } from './custom-themes.js';
|
|
10
|
-
import { adoptLegacyUiModelDefaults } from './legacy-ui-model-defaults.js';
|
|
11
10
|
import { createPiSettingsStore } from './settings-store.js';
|
|
12
11
|
import { isPiThinkingLevel } from './thinking-levels.js';
|
|
13
12
|
import { createPiSessionFoldersStore } from './session-folders-store.js';
|
|
13
|
+
import {
|
|
14
|
+
MAX_EXTENSION_APP_HTML_CHARS,
|
|
15
|
+
sanitizeExtensionFormFields,
|
|
16
|
+
} from './extension-protocol.js';
|
|
14
17
|
import { createPiUiSettingsStore } from './ui-settings-store.js';
|
|
15
18
|
|
|
16
19
|
const UNAVAILABLE_CODES = new Set([
|
|
@@ -144,6 +147,23 @@ const projectRetryInfo = (value) => {
|
|
|
144
147
|
};
|
|
145
148
|
};
|
|
146
149
|
|
|
150
|
+
const projectCompactionInfo = (value) => {
|
|
151
|
+
if (!value || typeof value !== 'object' || !['running', 'retrying', 'completed', 'failed', 'aborted'].includes(value.phase)) return null;
|
|
152
|
+
return {
|
|
153
|
+
phase: value.phase,
|
|
154
|
+
...(['manual', 'threshold', 'overflow'].includes(value.reason) ? { reason: value.reason } : {}),
|
|
155
|
+
...(Number.isFinite(value.startedAt) && value.startedAt >= 0 ? { startedAt: Math.floor(value.startedAt) } : {}),
|
|
156
|
+
...(Number.isFinite(value.completedAt) && value.completedAt >= 0 ? { completedAt: Math.floor(value.completedAt) } : {}),
|
|
157
|
+
...(Number.isSafeInteger(value.attempt) && value.attempt > 0 ? { attempt: value.attempt } : {}),
|
|
158
|
+
...(Number.isSafeInteger(value.maxAttempts) && value.maxAttempts > 0 ? { maxAttempts: value.maxAttempts } : {}),
|
|
159
|
+
...(Number.isFinite(value.next) && value.next >= 0 ? { next: Math.floor(value.next) } : {}),
|
|
160
|
+
...(Number.isFinite(value.tokensBefore) && value.tokensBefore >= 0 ? { tokensBefore: Math.floor(value.tokensBefore) } : {}),
|
|
161
|
+
...(Number.isFinite(value.estimatedTokensAfter) && value.estimatedTokensAfter >= 0 ? { estimatedTokensAfter: Math.floor(value.estimatedTokensAfter) } : {}),
|
|
162
|
+
...(typeof value.willRetry === 'boolean' ? { willRetry: value.willRetry } : {}),
|
|
163
|
+
...(typeof value.message === 'string' ? { message: value.message } : {}),
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
|
|
147
167
|
const sanitizeNavigation = (value) => {
|
|
148
168
|
if (!value || typeof value !== 'object' || typeof value.targetEntryId !== 'string' || value.targetEntryId.length === 0) return null;
|
|
149
169
|
const previousLeafId = value.previousLeafId === null ? null : (typeof value.previousLeafId === 'string' ? value.previousLeafId : null);
|
|
@@ -167,7 +187,7 @@ const projectSessionDetail = (value) => {
|
|
|
167
187
|
if (!item || typeof item !== 'object' || !item.message || !Array.isArray(item.parts)) throw protocolMismatch();
|
|
168
188
|
const message = item.message;
|
|
169
189
|
if (typeof message.id !== 'string' || typeof message.sessionId !== 'string' || typeof message.directory !== 'string'
|
|
170
|
-
|| !Number.isFinite(message.createdAt) || (message.role !== 'user' && message.role !== 'assistant')) throw protocolMismatch();
|
|
190
|
+
|| !Number.isFinite(message.createdAt) || (message.role !== 'user' && message.role !== 'assistant' && message.role !== 'extension')) throw protocolMismatch();
|
|
171
191
|
const projected = {
|
|
172
192
|
id: message.id, sessionId: message.sessionId, directory: message.directory, role: message.role, createdAt: message.createdAt,
|
|
173
193
|
...(typeof message.parentId === 'string' ? { parentId: message.parentId } : {}),
|
|
@@ -183,6 +203,9 @@ const projectSessionDetail = (value) => {
|
|
|
183
203
|
}
|
|
184
204
|
: {}),
|
|
185
205
|
...(message.role === 'assistant' && message.usage && projectUsage(message.usage) ? { usage: projectUsage(message.usage) } : {}),
|
|
206
|
+
...(message.role === 'extension' && typeof message.customType === 'string' ? { customType: message.customType } : {}),
|
|
207
|
+
...(message.role === 'extension' && message.data !== undefined ? { data: message.data } : {}),
|
|
208
|
+
...(message.role === 'extension' && message.details !== undefined ? { details: message.details } : {}),
|
|
186
209
|
};
|
|
187
210
|
const parts = item.parts.map((part) => {
|
|
188
211
|
if (!part || typeof part !== 'object' || typeof part.type !== 'string' || typeof part.id !== 'string' || !Number.isSafeInteger(part.index)) throw protocolMismatch();
|
|
@@ -212,6 +235,7 @@ const projectSessionDetail = (value) => {
|
|
|
212
235
|
? value.lifecycle
|
|
213
236
|
: (isStreaming ? 'busy' : 'idle');
|
|
214
237
|
const retry = lifecycle === 'retry' ? projectRetryInfo(value.retry) : null;
|
|
238
|
+
const compaction = projectCompactionInfo(value.compaction);
|
|
215
239
|
return {
|
|
216
240
|
session: projectSession(value.session),
|
|
217
241
|
messages,
|
|
@@ -219,6 +243,7 @@ const projectSessionDetail = (value) => {
|
|
|
219
243
|
isStreaming,
|
|
220
244
|
lifecycle,
|
|
221
245
|
...(retry ? { retry } : {}),
|
|
246
|
+
...(compaction ? { compaction } : {}),
|
|
222
247
|
...(Number.isFinite(value.runStartedAt) ? { runStartedAt: Math.floor(value.runStartedAt) } : {}),
|
|
223
248
|
...(Number.isFinite(value.serverNow) ? { serverNow: Math.floor(value.serverNow) } : {}),
|
|
224
249
|
};
|
|
@@ -353,7 +378,9 @@ const projectSessionTree = (value) => {
|
|
|
353
378
|
return {
|
|
354
379
|
entryId: node.entryId,
|
|
355
380
|
...(typeof node.parentId === 'string' ? { parentId: node.parentId } : {}),
|
|
356
|
-
...(typeof node.title === 'string' ? { title: node.title } : {}),
|
|
381
|
+
...(typeof node.title === 'string' ? { title: node.title.slice(0, 256) } : {}),
|
|
382
|
+
...(typeof node.label === 'string' && node.label.length > 0 ? { label: node.label.slice(0, 256) } : {}),
|
|
383
|
+
...(typeof node.labelTimestamp === 'string' ? { labelTimestamp: node.labelTimestamp.slice(0, 64) } : {}),
|
|
357
384
|
updatedAt: node.updatedAt,
|
|
358
385
|
children: node.children.map(projectNode),
|
|
359
386
|
};
|
|
@@ -363,7 +390,56 @@ const projectSessionTree = (value) => {
|
|
|
363
390
|
|
|
364
391
|
const sessionIdFrom = (req) => typeof req.params.sessionId === 'string' && req.params.sessionId.length > 0 ? req.params.sessionId : undefined;
|
|
365
392
|
|
|
366
|
-
|
|
393
|
+
|
|
394
|
+
const projectExtensionPanelActions = (actions) => (
|
|
395
|
+
Array.isArray(actions)
|
|
396
|
+
? actions.filter((action) => action && typeof action === 'object' && typeof action.command === 'string').slice(0, 8)
|
|
397
|
+
: undefined
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
const projectExtensionPanelPayload = (panel) => ({
|
|
401
|
+
id: panel.id.slice(0, 128),
|
|
402
|
+
...(typeof panel.title === 'string' ? { title: panel.title.slice(0, 256) } : {}),
|
|
403
|
+
...(typeof panel.component === 'string' ? { component: panel.component.slice(0, 64) } : {}),
|
|
404
|
+
...(panel.props && typeof panel.props === 'object' && !Array.isArray(panel.props) ? { props: panel.props } : {}),
|
|
405
|
+
...(projectExtensionPanelActions(panel.actions) ? { actions: panel.actions } : {}),
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
const projectExtensionAppPayload = (app) => ({
|
|
409
|
+
appId: app.appId.slice(0, 128),
|
|
410
|
+
...(typeof app.title === 'string' ? { title: app.title.slice(0, 256) } : {}),
|
|
411
|
+
html: typeof app.html === 'string' ? app.html.slice(0, MAX_EXTENSION_APP_HTML_CHARS) : '',
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
const EXTENSION_COMMAND_PATTERN = /^[A-Za-z0-9][A-Za-z0-9:_-]{0,127}$/;
|
|
415
|
+
const OPAQUE_EXTENSION_ID_PATTERN = /^[a-f0-9]{16}$/;
|
|
416
|
+
|
|
417
|
+
export const projectExtensionList = (result) => {
|
|
418
|
+
if (!result || typeof result !== 'object' || typeof result.directory !== 'string'
|
|
419
|
+
|| !Array.isArray(result.extensions) || !Array.isArray(result.commands)) throw protocolMismatch();
|
|
420
|
+
const extensions = result.extensions.map((extension) => {
|
|
421
|
+
if (!extension || typeof extension !== 'object'
|
|
422
|
+
|| typeof extension.id !== 'string' || !OPAQUE_EXTENSION_ID_PATTERN.test(extension.id)
|
|
423
|
+
|| typeof extension.name !== 'string' || extension.name.length === 0 || extension.name.length > 256
|
|
424
|
+
|| extension.name.includes('/') || extension.name.includes('\\')) throw protocolMismatch();
|
|
425
|
+
return { id: extension.id, name: extension.name };
|
|
426
|
+
});
|
|
427
|
+
const commands = result.commands.map((command) => {
|
|
428
|
+
if (!command || typeof command !== 'object'
|
|
429
|
+
|| typeof command.name !== 'string' || !EXTENSION_COMMAND_PATTERN.test(command.name)
|
|
430
|
+
|| (command.description !== undefined && typeof command.description !== 'string')
|
|
431
|
+
|| (command.scope !== undefined && typeof command.scope !== 'string')) throw protocolMismatch();
|
|
432
|
+
return {
|
|
433
|
+
name: command.name,
|
|
434
|
+
...(typeof command.description === 'string' ? { description: command.description.slice(0, 500) } : {}),
|
|
435
|
+
source: 'extension',
|
|
436
|
+
...(typeof command.scope === 'string' ? { scope: command.scope.slice(0, 64) } : {}),
|
|
437
|
+
};
|
|
438
|
+
});
|
|
439
|
+
return { directory: result.directory, extensions, commands };
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
export const projectEventFrame = (frame) => {
|
|
367
443
|
if (!frame || frame.kind !== 'event' || typeof frame.event !== 'string' || !Number.isSafeInteger(frame.sequence)
|
|
368
444
|
|| !frame.payload || typeof frame.payload.sessionId !== 'string' || typeof frame.payload.directory !== 'string') return null;
|
|
369
445
|
const { sessionId, directory } = frame.payload;
|
|
@@ -371,12 +447,43 @@ const projectEventFrame = (frame) => {
|
|
|
371
447
|
switch (frame.event) {
|
|
372
448
|
case 'session.snapshot': {
|
|
373
449
|
const snapshot = frame.payload;
|
|
450
|
+
const snapshotExtensionStatuses = Array.isArray(snapshot.extensionStatuses)
|
|
451
|
+
? snapshot.extensionStatuses.filter((entry) => entry && typeof entry.key === 'string' && typeof entry.text === 'string' && entry.key.length > 0 && entry.key.length <= 128 && entry.text.length <= 1000).slice(0, 50).map((entry) => ({ key: entry.key.slice(0, 128), text: entry.text.slice(0, 1000) }))
|
|
452
|
+
: undefined;
|
|
453
|
+
const snapshotExtensionWidgets = Array.isArray(snapshot.extensionWidgets)
|
|
454
|
+
? snapshot.extensionWidgets.filter((entry) => entry && typeof entry.key === 'string' && Array.isArray(entry.lines) && entry.key.length > 0 && entry.key.length <= 128 && entry.lines.length <= 100).slice(0, 50).map((entry) => ({
|
|
455
|
+
key: entry.key.slice(0, 128),
|
|
456
|
+
lines: entry.lines.filter((line) => typeof line === 'string').map((line) => line.slice(0, 2000)).slice(0, 100),
|
|
457
|
+
...(entry.placement === 'belowEditor' ? { placement: 'belowEditor' } : { placement: 'aboveEditor' }),
|
|
458
|
+
}))
|
|
459
|
+
: undefined;
|
|
460
|
+
const snapshotExtensionDialogs = Array.isArray(snapshot.extensionDialogs)
|
|
461
|
+
? snapshot.extensionDialogs.filter((entry) => entry && typeof entry.requestId === 'string' && typeof entry.method === 'string' && typeof entry.title === 'string').slice(0, 20).map((entry) => ({
|
|
462
|
+
requestId: entry.requestId.slice(0, 512),
|
|
463
|
+
method: ['select', 'confirm', 'input', 'editor', 'form'].includes(entry.method) ? entry.method : 'confirm',
|
|
464
|
+
title: entry.title.slice(0, 512),
|
|
465
|
+
...(typeof entry.message === 'string' ? { message: entry.message.slice(0, 2000) } : {}),
|
|
466
|
+
...(Array.isArray(entry.options) ? { options: entry.options.filter((option) => typeof option === 'string').map((option) => option.slice(0, 256)).slice(0, 20) } : {}),
|
|
467
|
+
...(typeof entry.placeholder === 'string' ? { placeholder: entry.placeholder.slice(0, 512) } : {}),
|
|
468
|
+
...(typeof entry.prefill === 'string' ? { prefill: entry.prefill.slice(0, 10000) } : {}),
|
|
469
|
+
...(Array.isArray(entry.fields) ? { fields: sanitizeExtensionFormFields(entry.fields) } : {}),
|
|
470
|
+
...(Number.isFinite(entry.timeoutMs) ? { timeoutMs: Math.floor(entry.timeoutMs) } : {}),
|
|
471
|
+
}))
|
|
472
|
+
: undefined;
|
|
473
|
+
const snapshotExtensionPanels = Array.isArray(snapshot.extensionPanels)
|
|
474
|
+
? snapshot.extensionPanels.filter((entry) => entry && typeof entry.id === 'string' && entry.id.length > 0).slice(0, 24).map(projectExtensionPanelPayload)
|
|
475
|
+
: undefined;
|
|
476
|
+
const snapshotExtensionApps = Array.isArray(snapshot.extensionApps)
|
|
477
|
+
? snapshot.extensionApps.filter((entry) => entry && typeof entry.appId === 'string' && entry.appId.length > 0 && typeof entry.html === 'string' && entry.html.length > 0).slice(0, 8).map(projectExtensionAppPayload)
|
|
478
|
+
: undefined;
|
|
374
479
|
const lifecycle = ['idle', 'busy', 'retry', 'error', 'interrupted'].includes(snapshot.lifecycle) ? snapshot.lifecycle : 'idle';
|
|
375
480
|
const retry = lifecycle === 'retry' ? projectRetryInfo(snapshot.retry) : null;
|
|
481
|
+
const compaction = projectCompactionInfo(snapshot.compaction);
|
|
376
482
|
return { ...common, payload: { snapshot: {
|
|
377
483
|
sessionId, directory, isStreaming: snapshot.isStreaming === true,
|
|
378
484
|
lifecycle,
|
|
379
485
|
...(retry ? { retry } : {}),
|
|
486
|
+
...(compaction ? { compaction } : {}),
|
|
380
487
|
queue: { steering: Number.isSafeInteger(snapshot.queue?.steering) ? snapshot.queue.steering : 0, followUp: Number.isSafeInteger(snapshot.queue?.followUp) ? snapshot.queue.followUp : 0 },
|
|
381
488
|
...(snapshot.model && typeof snapshot.model.providerId === 'string' && typeof snapshot.model.modelId === 'string' ? { model: { providerId: snapshot.model.providerId, modelId: snapshot.model.modelId } } : {}),
|
|
382
489
|
...(typeof snapshot.thinking === 'string' ? { thinking: snapshot.thinking } : {}),
|
|
@@ -385,6 +492,14 @@ const projectEventFrame = (frame) => {
|
|
|
385
492
|
...(Number.isFinite(snapshot.runStartedAt) ? { runStartedAt: Math.floor(snapshot.runStartedAt) } : {}),
|
|
386
493
|
...(Number.isFinite(snapshot.serverNow) ? { serverNow: Math.floor(snapshot.serverNow) } : {}),
|
|
387
494
|
lastSequence: Number.isSafeInteger(snapshot.lastSequence) ? snapshot.lastSequence : frame.sequence,
|
|
495
|
+
...(snapshotExtensionStatuses ? { extensionStatuses: snapshotExtensionStatuses } : {}),
|
|
496
|
+
...(snapshotExtensionWidgets ? { extensionWidgets: snapshotExtensionWidgets } : {}),
|
|
497
|
+
...(snapshotExtensionDialogs ? { extensionDialogs: snapshotExtensionDialogs } : {}),
|
|
498
|
+
...(snapshotExtensionPanels ? { extensionPanels: snapshotExtensionPanels } : {}),
|
|
499
|
+
...(snapshotExtensionApps ? { extensionApps: snapshotExtensionApps } : {}),
|
|
500
|
+
...(typeof snapshot.extensionTitle === 'string' && snapshot.extensionTitle.length > 0
|
|
501
|
+
? { extensionTitle: snapshot.extensionTitle.replace(/[\u0000-\u001f\u007f]/g, ' ').trim().slice(0, 256) }
|
|
502
|
+
: {}),
|
|
388
503
|
} } };
|
|
389
504
|
}
|
|
390
505
|
case 'session.lifecycle': {
|
|
@@ -397,6 +512,7 @@ const projectEventFrame = (frame) => {
|
|
|
397
512
|
if (title.length === 0 || title.length > 256) return null;
|
|
398
513
|
return { ...common, payload: { title } };
|
|
399
514
|
}
|
|
515
|
+
case 'session.tree.updated': return { ...common, payload: {} };
|
|
400
516
|
case 'assistant.message.start': return { ...common, payload: { messageId: frame.payload.messageId, role: frame.payload.role, startedAt: frame.payload.startedAt, ...(typeof frame.payload.parentId === 'string' ? { parentId: frame.payload.parentId } : {}), ...(typeof frame.payload.text === 'string' ? { text: frame.payload.text } : {}), ...(frame.payload.model ? { model: frame.payload.model } : {}) } };
|
|
401
517
|
case 'assistant.message.delta':
|
|
402
518
|
case 'assistant.thinking.delta': return { ...common, payload: { messageId: frame.payload.messageId, contentIndex: frame.payload.contentIndex, delta: frame.payload.delta, ...(typeof frame.payload.partId === 'string' ? { partId: frame.payload.partId } : {}) } };
|
|
@@ -422,7 +538,10 @@ const projectEventFrame = (frame) => {
|
|
|
422
538
|
case 'session.queue': return { ...common, payload: { steering: frame.payload.steering, followUp: frame.payload.followUp } };
|
|
423
539
|
case 'session.model': return { ...common, payload: { model: frame.payload.model } };
|
|
424
540
|
case 'session.thinking': return { ...common, payload: { thinking: frame.payload.thinking } };
|
|
425
|
-
case 'session.compaction':
|
|
541
|
+
case 'session.compaction': {
|
|
542
|
+
const compaction = projectCompactionInfo(frame.payload);
|
|
543
|
+
return compaction ? { ...common, payload: compaction } : null;
|
|
544
|
+
}
|
|
426
545
|
case 'session.error': return {
|
|
427
546
|
...common,
|
|
428
547
|
payload: {
|
|
@@ -446,6 +565,126 @@ const projectEventFrame = (frame) => {
|
|
|
446
565
|
...(Number.isFinite(frame.payload.endedAt) ? { endedAt: frame.payload.endedAt } : {}),
|
|
447
566
|
},
|
|
448
567
|
};
|
|
568
|
+
case 'extension.entry': {
|
|
569
|
+
if (typeof frame.payload.id !== 'string' || frame.payload.id.length === 0 || frame.payload.id.length > 512) return null;
|
|
570
|
+
if (typeof frame.payload.customType !== 'string' || frame.payload.customType.length === 0 || frame.payload.customType.length > 256) return null;
|
|
571
|
+
if (!Number.isFinite(frame.payload.createdAt)) return null;
|
|
572
|
+
return { ...common, payload: { id: frame.payload.id.slice(0, 512), customType: frame.payload.customType.slice(0, 256), ...(frame.payload.data !== undefined ? { data: frame.payload.data } : {}), createdAt: frame.payload.createdAt } };
|
|
573
|
+
}
|
|
574
|
+
case 'extension.message': {
|
|
575
|
+
if (typeof frame.payload.id !== 'string' || frame.payload.id.length === 0 || frame.payload.id.length > 512) return null;
|
|
576
|
+
if (typeof frame.payload.customType !== 'string' || frame.payload.customType.length === 0 || frame.payload.customType.length > 256) return null;
|
|
577
|
+
if (typeof frame.payload.text !== 'string') return null;
|
|
578
|
+
if (!Number.isFinite(frame.payload.createdAt)) return null;
|
|
579
|
+
return { ...common, payload: { id: frame.payload.id.slice(0, 512), customType: frame.payload.customType.slice(0, 256), text: frame.payload.text.slice(0, 50000), ...(frame.payload.details !== undefined ? { details: frame.payload.details } : {}), createdAt: frame.payload.createdAt } };
|
|
580
|
+
}
|
|
581
|
+
case 'extension.notify': {
|
|
582
|
+
if (typeof frame.payload.message !== 'string' || frame.payload.message.length === 0) return null;
|
|
583
|
+
const level = ['info', 'warning', 'error'].includes(frame.payload.level) ? frame.payload.level : 'info';
|
|
584
|
+
return { ...common, payload: { message: frame.payload.message.slice(0, 2000), level } };
|
|
585
|
+
}
|
|
586
|
+
case 'extension.catalog': {
|
|
587
|
+
const providers = frame.payload.providers === true;
|
|
588
|
+
const resources = frame.payload.resources === true;
|
|
589
|
+
const commands = frame.payload.commands === true;
|
|
590
|
+
if (!providers && !resources && !commands) return null;
|
|
591
|
+
return { ...common, payload: { ...(providers ? { providers: true } : {}), ...(resources ? { resources: true } : {}), ...(commands ? { commands: true } : {}) } };
|
|
592
|
+
}
|
|
593
|
+
case 'extension.editor': {
|
|
594
|
+
if (typeof frame.payload.text !== 'string' || frame.payload.text.length > 100_000) return null;
|
|
595
|
+
return { ...common, payload: { text: frame.payload.text } };
|
|
596
|
+
}
|
|
597
|
+
case 'extension.title': {
|
|
598
|
+
if (frame.payload.title !== undefined && typeof frame.payload.title !== 'string') return null;
|
|
599
|
+
const title = typeof frame.payload.title === 'string'
|
|
600
|
+
? frame.payload.title.replace(/[\u0000-\u001f\u007f]/g, ' ').trim().slice(0, 256)
|
|
601
|
+
: '';
|
|
602
|
+
return { ...common, payload: title ? { title } : {} };
|
|
603
|
+
}
|
|
604
|
+
case 'extension.status': {
|
|
605
|
+
if (typeof frame.payload.key !== 'string' || frame.payload.key.length === 0 || frame.payload.key.length > 128) return null;
|
|
606
|
+
if (frame.payload.text !== undefined && typeof frame.payload.text !== 'string') return null;
|
|
607
|
+
return { ...common, payload: { key: frame.payload.key.slice(0, 128), ...(typeof frame.payload.text === 'string' ? { text: frame.payload.text.slice(0, 1000) } : {}) } };
|
|
608
|
+
}
|
|
609
|
+
case 'extension.widget': {
|
|
610
|
+
if (typeof frame.payload.key !== 'string' || frame.payload.key.length === 0 || frame.payload.key.length > 128) return null;
|
|
611
|
+
if (frame.payload.lines !== undefined) {
|
|
612
|
+
if (!Array.isArray(frame.payload.lines)) return null;
|
|
613
|
+
if (frame.payload.lines.length > 100) return null;
|
|
614
|
+
for (const line of frame.payload.lines) if (typeof line !== 'string' || line.length > 2000) return null;
|
|
615
|
+
}
|
|
616
|
+
if (frame.payload.placement !== undefined && frame.payload.placement !== 'aboveEditor' && frame.payload.placement !== 'belowEditor') return null;
|
|
617
|
+
return {
|
|
618
|
+
...common,
|
|
619
|
+
payload: {
|
|
620
|
+
key: frame.payload.key.slice(0, 128),
|
|
621
|
+
...(Array.isArray(frame.payload.lines) ? { lines: frame.payload.lines.map((line) => String(line).slice(0, 2000)).slice(0, 100) } : {}),
|
|
622
|
+
...(frame.payload.placement === 'belowEditor' ? { placement: 'belowEditor' } : frame.payload.placement === 'aboveEditor' ? { placement: 'aboveEditor' } : {}),
|
|
623
|
+
},
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
case 'extension.dialog': {
|
|
627
|
+
if (typeof frame.payload.requestId !== 'string' || frame.payload.requestId.length === 0 || frame.payload.requestId.length > 512) return null;
|
|
628
|
+
if (!['select', 'confirm', 'input', 'editor', 'form'].includes(frame.payload.method)) return null;
|
|
629
|
+
if (typeof frame.payload.title !== 'string' || frame.payload.title.length === 0 || frame.payload.title.length > 512) return null;
|
|
630
|
+
return {
|
|
631
|
+
...common,
|
|
632
|
+
payload: {
|
|
633
|
+
requestId: frame.payload.requestId.slice(0, 512),
|
|
634
|
+
method: frame.payload.method,
|
|
635
|
+
title: frame.payload.title.slice(0, 512),
|
|
636
|
+
...(typeof frame.payload.message === 'string' ? { message: frame.payload.message.slice(0, 2000) } : {}),
|
|
637
|
+
...(Array.isArray(frame.payload.options) ? { options: frame.payload.options.filter((option) => typeof option === 'string').map((option) => option.slice(0, 256)).slice(0, 20) } : {}),
|
|
638
|
+
...(typeof frame.payload.placeholder === 'string' ? { placeholder: frame.payload.placeholder.slice(0, 512) } : {}),
|
|
639
|
+
...(typeof frame.payload.prefill === 'string' ? { prefill: frame.payload.prefill.slice(0, 10000) } : {}),
|
|
640
|
+
...(Array.isArray(frame.payload.fields) ? { fields: sanitizeExtensionFormFields(frame.payload.fields) } : {}),
|
|
641
|
+
...(Number.isFinite(frame.payload.timeoutMs) && frame.payload.timeoutMs >= 0 && frame.payload.timeoutMs <= 600000 ? { timeoutMs: Math.floor(frame.payload.timeoutMs) } : {}),
|
|
642
|
+
},
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
case 'extension.dialog.dismiss': {
|
|
646
|
+
if (typeof frame.payload.requestId !== 'string' || frame.payload.requestId.length === 0 || frame.payload.requestId.length > 512) return null;
|
|
647
|
+
if (!['answered', 'cancelled', 'timeout', 'aborted', 'session-closed', 'daemon-stopped'].includes(frame.payload.reason)) return null;
|
|
648
|
+
return {
|
|
649
|
+
...common,
|
|
650
|
+
payload: {
|
|
651
|
+
requestId: frame.payload.requestId.slice(0, 512),
|
|
652
|
+
reason: frame.payload.reason,
|
|
653
|
+
},
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
case 'extension.ui': {
|
|
657
|
+
if (typeof frame.payload.id !== 'string' || frame.payload.id.length === 0 || frame.payload.id.length > 128) return null;
|
|
658
|
+
const hasBody = typeof frame.payload.component === 'string'
|
|
659
|
+
|| typeof frame.payload.title === 'string'
|
|
660
|
+
|| Array.isArray(frame.payload.actions);
|
|
661
|
+
const removed = frame.payload.removed === true || !hasBody;
|
|
662
|
+
return {
|
|
663
|
+
...common,
|
|
664
|
+
payload: removed
|
|
665
|
+
? { id: frame.payload.id.slice(0, 128), removed: true }
|
|
666
|
+
: projectExtensionPanelPayload(frame.payload),
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
case 'extension.app': {
|
|
670
|
+
if (typeof frame.payload.appId !== 'string' || frame.payload.appId.length === 0 || frame.payload.appId.length > 128) return null;
|
|
671
|
+
const html = typeof frame.payload.html === 'string' ? frame.payload.html : '';
|
|
672
|
+
if (html.length === 0) return { ...common, payload: { appId: frame.payload.appId.slice(0, 128), removed: true } };
|
|
673
|
+
if (html.length > MAX_EXTENSION_APP_HTML_CHARS) return null;
|
|
674
|
+
return { ...common, payload: projectExtensionAppPayload({ ...frame.payload, html }) };
|
|
675
|
+
}
|
|
676
|
+
case 'extension.error': {
|
|
677
|
+
if (typeof frame.payload.source !== 'string' || frame.payload.source.length === 0 || frame.payload.source.length > 512) return null;
|
|
678
|
+
if (typeof frame.payload.message !== 'string' || frame.payload.message.length === 0) return null;
|
|
679
|
+
return {
|
|
680
|
+
...common,
|
|
681
|
+
payload: {
|
|
682
|
+
source: frame.payload.source.slice(0, 512),
|
|
683
|
+
...(typeof frame.payload.event === 'string' ? { event: frame.payload.event.slice(0, 128) } : {}),
|
|
684
|
+
message: frame.payload.message.slice(0, 5000),
|
|
685
|
+
},
|
|
686
|
+
};
|
|
687
|
+
}
|
|
449
688
|
default: return null;
|
|
450
689
|
}
|
|
451
690
|
};
|
|
@@ -487,6 +726,7 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
487
726
|
uiSettingsStore = createPiUiSettingsStore(),
|
|
488
727
|
listCustomThemes = listPiCustomThemes,
|
|
489
728
|
updateChecker = checkForUpdates,
|
|
729
|
+
smallModelGenerator = async (input) => (await import('./small-model-generation.js')).generateWithSmallModel(input),
|
|
490
730
|
}) => {
|
|
491
731
|
app.get('/api/pi/ui-settings', async (_req, res) => {
|
|
492
732
|
try {
|
|
@@ -722,10 +962,40 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
722
962
|
}
|
|
723
963
|
});
|
|
724
964
|
|
|
965
|
+
app.post('/api/pi/small-model/generate', async (req, res) => {
|
|
966
|
+
const source = typeof req.body?.prompt === 'string' ? req.body.prompt.trim() : '';
|
|
967
|
+
const directory = typeof req.body?.directory === 'string' ? req.body.directory.trim() : '';
|
|
968
|
+
if (!source || source.length > 20_000 || !directory) {
|
|
969
|
+
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
try {
|
|
973
|
+
const settings = await settingsStore.read();
|
|
974
|
+
const model = settings.smallModel ?? settings.defaultModel;
|
|
975
|
+
const result = await smallModelGenerator({
|
|
976
|
+
directory,
|
|
977
|
+
model,
|
|
978
|
+
prompt: [
|
|
979
|
+
'Create a short task name for a Git worktree and branch.',
|
|
980
|
+
'Return only lowercase ASCII words separated by hyphens.',
|
|
981
|
+
'Use at most 48 characters. Do not include quotes, punctuation, a prefix, or explanation.',
|
|
982
|
+
'',
|
|
983
|
+
source,
|
|
984
|
+
].join('\n'),
|
|
985
|
+
});
|
|
986
|
+
if (!result || typeof result.text !== 'string' || result.text.trim().length === 0) throw protocolMismatch();
|
|
987
|
+
res.json({ text: result.text.trim() });
|
|
988
|
+
} catch (error) {
|
|
989
|
+
const code = typeof error?.code === 'string' ? error.code : 'SMALL_MODEL_FAILED';
|
|
990
|
+
const status = code === 'SMALL_MODEL_UNCONFIGURED' ? 409 : 503;
|
|
991
|
+
res.status(status).json({ error: { code } });
|
|
992
|
+
}
|
|
993
|
+
});
|
|
994
|
+
|
|
725
995
|
app.get('/api/pi/settings', async (_req, res) => {
|
|
726
996
|
try {
|
|
727
997
|
const pi = projectPiSettings(await getDaemonRuntime(getPiSessionDaemonRuntime).request('settings.get'));
|
|
728
|
-
const pichamber = await
|
|
998
|
+
const pichamber = await settingsStore.read();
|
|
729
999
|
res.json({ ...pi, pichamber });
|
|
730
1000
|
} catch (error) {
|
|
731
1001
|
writeDaemonError(res, error);
|
|
@@ -932,6 +1202,64 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
932
1202
|
}
|
|
933
1203
|
});
|
|
934
1204
|
|
|
1205
|
+
app.get('/api/pi/extensions', async (req, res) => {
|
|
1206
|
+
const directory = req.query?.directory;
|
|
1207
|
+
if (directory !== undefined && typeof directory !== 'string') {
|
|
1208
|
+
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
try {
|
|
1212
|
+
const result = await getDaemonRuntime(getPiSessionDaemonRuntime).request('extensions.list', {
|
|
1213
|
+
...(typeof directory === 'string' && directory.length > 0 ? { directory } : {}),
|
|
1214
|
+
});
|
|
1215
|
+
res.json(projectExtensionList(result));
|
|
1216
|
+
} catch (error) {
|
|
1217
|
+
writeDaemonError(res, error);
|
|
1218
|
+
}
|
|
1219
|
+
});
|
|
1220
|
+
|
|
1221
|
+
app.post('/api/pi/extensions/respond', async (req, res) => {
|
|
1222
|
+
const body = req.body;
|
|
1223
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)
|
|
1224
|
+
|| typeof body.requestId !== 'string' || body.requestId.length === 0
|
|
1225
|
+
|| (body.directory !== undefined && typeof body.directory !== 'string')) {
|
|
1226
|
+
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
1227
|
+
return;
|
|
1228
|
+
}
|
|
1229
|
+
let values;
|
|
1230
|
+
if (body.values !== undefined) {
|
|
1231
|
+
if (!body.values || typeof body.values !== 'object' || Array.isArray(body.values)) {
|
|
1232
|
+
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1235
|
+
values = {};
|
|
1236
|
+
for (const [key, entry] of Object.entries(body.values)) {
|
|
1237
|
+
if (typeof key !== 'string' || key.length === 0 || key.length > 128 || typeof entry !== 'string' || entry.length > 8_000) {
|
|
1238
|
+
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
values[key] = entry;
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
try {
|
|
1245
|
+
const result = await getDaemonRuntime(getPiSessionDaemonRuntime).request('extensions.respond', {
|
|
1246
|
+
requestId: body.requestId,
|
|
1247
|
+
...(typeof body.directory === 'string' && body.directory.length > 0 ? { directory: body.directory } : {}),
|
|
1248
|
+
...(body.cancelled === true ? { cancelled: true } : {}),
|
|
1249
|
+
...(body.confirmed === true ? { confirmed: true } : {}),
|
|
1250
|
+
...(typeof body.value === 'string' ? { value: body.value } : {}),
|
|
1251
|
+
...(values ? { values } : {}),
|
|
1252
|
+
});
|
|
1253
|
+
if (!result || typeof result !== 'object' || result.resolved !== true) {
|
|
1254
|
+
res.status(404).json({ error: { code: 'EXTENSION_DIALOG_NOT_PENDING' } });
|
|
1255
|
+
return;
|
|
1256
|
+
}
|
|
1257
|
+
res.status(204).end();
|
|
1258
|
+
} catch (error) {
|
|
1259
|
+
writeDaemonError(res, error);
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
|
|
935
1263
|
app.get('/api/pi/sessions/:sessionId/tree', async (req, res) => {
|
|
936
1264
|
const result = await requestSessionOperation(req, res, getPiSessionDaemonRuntime, 'sessions.tree');
|
|
937
1265
|
if (result !== undefined) res.json(projectSessionTree(result));
|
|
@@ -977,13 +1305,23 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
977
1305
|
});
|
|
978
1306
|
}
|
|
979
1307
|
|
|
980
|
-
for (const [suffix, command] of [['abort', 'sessions.abort'], ['model', 'sessions.setModel'], ['thinking', 'sessions.setThinking']
|
|
1308
|
+
for (const [suffix, command] of [['abort', 'sessions.abort'], ['model', 'sessions.setModel'], ['thinking', 'sessions.setThinking']]) {
|
|
981
1309
|
app.post(`/api/pi/sessions/:sessionId/${suffix}`, async (req, res) => {
|
|
982
1310
|
const result = await requestSessionOperation(req, res, getPiSessionDaemonRuntime, command, req.body && typeof req.body === 'object' ? req.body : {});
|
|
983
1311
|
if (result !== undefined) res.status(204).end();
|
|
984
1312
|
});
|
|
985
1313
|
}
|
|
986
1314
|
|
|
1315
|
+
app.post('/api/pi/sessions/:sessionId/compact', async (req, res) => {
|
|
1316
|
+
const result = await requestSessionOperation(req, res, getPiSessionDaemonRuntime, 'sessions.compact', req.body && typeof req.body === 'object' ? req.body : {});
|
|
1317
|
+
if (result === undefined) return;
|
|
1318
|
+
if (!result || result.accepted !== true) {
|
|
1319
|
+
writeDaemonError(res, protocolMismatch());
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
res.status(202).json({ accepted: true });
|
|
1323
|
+
});
|
|
1324
|
+
|
|
987
1325
|
app.post('/api/pi/attachments', async (req, res) => {
|
|
988
1326
|
try {
|
|
989
1327
|
const attachment = await attachmentStore.create(req.body ?? {});
|
|
@@ -100,6 +100,37 @@ describe('Pi runtime route', () => {
|
|
|
100
100
|
await expect((await fetch(`${base}/api/pi/update-check`)).json()).resolves.toEqual({ available: false, currentVersion: '1.0.0' });
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
+
it('generates a task name with the configured small model without exposing model details', async () => {
|
|
104
|
+
const calls = [];
|
|
105
|
+
const app = express();
|
|
106
|
+
app.use(express.json());
|
|
107
|
+
registerPiRuntimeRoutes(app, {
|
|
108
|
+
getPiSessionDaemonRuntime: () => null,
|
|
109
|
+
settingsStore: {
|
|
110
|
+
read: async () => ({ smallModel: { providerId: 'provider', modelId: 'small' } }),
|
|
111
|
+
},
|
|
112
|
+
smallModelGenerator: async (input) => {
|
|
113
|
+
calls.push(input);
|
|
114
|
+
return { text: 'fix-auth-timeout' };
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
server = await listen(app);
|
|
118
|
+
const response = await fetch(`http://127.0.0.1:${server.address().port}/api/pi/small-model/generate`, {
|
|
119
|
+
method: 'POST',
|
|
120
|
+
headers: { 'Content-Type': 'application/json' },
|
|
121
|
+
body: JSON.stringify({ directory: '/repo', prompt: 'Fix the authentication timeout' }),
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
expect(response.status).toBe(200);
|
|
125
|
+
await expect(response.json()).resolves.toEqual({ text: 'fix-auth-timeout' });
|
|
126
|
+
expect(calls).toHaveLength(1);
|
|
127
|
+
expect(calls[0]).toMatchObject({
|
|
128
|
+
directory: '/repo',
|
|
129
|
+
model: { providerId: 'provider', modelId: 'small' },
|
|
130
|
+
});
|
|
131
|
+
expect(calls[0].prompt).toContain('Fix the authentication timeout');
|
|
132
|
+
});
|
|
133
|
+
|
|
103
134
|
it('lists and selects only daemon-owned projects', async () => {
|
|
104
135
|
const calls = [];
|
|
105
136
|
const runtime = {
|
|
@@ -245,31 +276,6 @@ describe('Pi runtime route', () => {
|
|
|
245
276
|
await expect((await fetch(`${base}/defaults`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ defaultThinking: 'low' }) })).json()).resolves.toEqual({ pichamber: { version: 1, defaultThinking: 'low' } });
|
|
246
277
|
});
|
|
247
278
|
|
|
248
|
-
it('adopts leftover UI model defaults into the sidecar on settings read', async () => {
|
|
249
|
-
const settingsStore = {
|
|
250
|
-
read: async () => ({ version: 1 }),
|
|
251
|
-
update: async (patch) => ({ version: 1, ...patch }),
|
|
252
|
-
};
|
|
253
|
-
const uiSettingsStore = {
|
|
254
|
-
read: async () => ({ defaultModel: 'openai/gpt-5', themeMode: 'dark' }),
|
|
255
|
-
write: async () => ({}),
|
|
256
|
-
};
|
|
257
|
-
const runtime = {
|
|
258
|
-
request: async (command) => {
|
|
259
|
-
if (command === 'settings.get') return { global: {}, project: { trusted: false } };
|
|
260
|
-
throw new Error(`Unexpected command ${command}`);
|
|
261
|
-
},
|
|
262
|
-
};
|
|
263
|
-
const app = express();
|
|
264
|
-
app.use(express.json());
|
|
265
|
-
registerPiRuntimeRoutes(app, { getPiSessionDaemonRuntime: () => runtime, settingsStore, uiSettingsStore });
|
|
266
|
-
server = await listen(app);
|
|
267
|
-
await expect((await fetch(`http://127.0.0.1:${server.address().port}/api/pi/settings`)).json()).resolves.toEqual({
|
|
268
|
-
pi: { global: {}, project: { trusted: false } },
|
|
269
|
-
pichamber: { version: 1, defaultModel: { providerId: 'openai', modelId: 'gpt-5' } },
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
|
|
273
279
|
it('projects native resources without exposing daemon filesystem paths', async () => {
|
|
274
280
|
const calls = [];
|
|
275
281
|
const runtime = {
|
|
@@ -497,6 +503,7 @@ describe('Pi runtime route', () => {
|
|
|
497
503
|
if (command === 'sessions.tree') return { rootId: 'pi-session-7', nodes: [{ entryId: 'entry-7', updatedAt: 2, children: [], privatePath: '/private' }] };
|
|
498
504
|
if (command === 'sessions.list') return { sessions: [{ session: detail.session, updatedAt: 2 }] };
|
|
499
505
|
if (['sessions.prompt', 'sessions.steer', 'sessions.followUp'].includes(command)) return { accepted: true, messageId: 'message-1' };
|
|
506
|
+
if (command === 'sessions.compact') return { accepted: true };
|
|
500
507
|
return {};
|
|
501
508
|
},
|
|
502
509
|
};
|
|
@@ -515,9 +522,10 @@ describe('Pi runtime route', () => {
|
|
|
515
522
|
for (const suffix of ['prompt', 'steer', 'follow-up']) {
|
|
516
523
|
expect((await fetch(`${base}/${suffix}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ sessionId: 'other', text: 'hello' }) })).status).toBe(202);
|
|
517
524
|
}
|
|
518
|
-
for (const [suffix, body] of [['abort', {}], ['model', { model: { providerId: 'test', modelId: 'model' } }], ['thinking', { thinking: 'high' }]
|
|
525
|
+
for (const [suffix, body] of [['abort', {}], ['model', { model: { providerId: 'test', modelId: 'model' } }], ['thinking', { thinking: 'high' }]]) {
|
|
519
526
|
expect((await fetch(`${base}/${suffix}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ sessionId: 'other', ...body }) })).status).toBe(204);
|
|
520
527
|
}
|
|
528
|
+
expect((await fetch(`${base}/compact`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ sessionId: 'other', thinking: 'low' }) })).status).toBe(202);
|
|
521
529
|
const callsBeforeArchive = calls.length;
|
|
522
530
|
expect((await fetch(`${base}/archive`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ archived: false }) })).status).toBe(204);
|
|
523
531
|
expect(calls).toContainEqual({ command: 'archive.set', payload: ['pi-session-7', false] });
|
|
@@ -543,11 +551,13 @@ describe('Pi runtime route', () => {
|
|
|
543
551
|
const runtime = {
|
|
544
552
|
health: async () => ({ state: 'ready', protocolVersion: 1, capabilities: [] }),
|
|
545
553
|
subscribe: async ({ onEvent }) => {
|
|
546
|
-
onEvent({ protocolVersion: 1, kind: 'event', event: 'session.snapshot', sequence: 4, payload: { sessionId: 'pi-session-5', directory: '/workspace', isStreaming: true, lifecycle: 'retry', retry: { attempt: 1, next: 4_000, message: 'provider request timed out' }, queue: { steering: 0, followUp: 0 }, lastSequence: 4, endpoint: '/private/socket' } });
|
|
554
|
+
onEvent({ protocolVersion: 1, kind: 'event', event: 'session.snapshot', sequence: 4, payload: { sessionId: 'pi-session-5', directory: '/workspace', isStreaming: true, lifecycle: 'retry', retry: { attempt: 1, next: 4_000, message: 'provider request timed out' }, compaction: { phase: 'running', reason: 'overflow', startedAt: 3_000 }, queue: { steering: 0, followUp: 0 }, lastSequence: 4, endpoint: '/private/socket' } });
|
|
547
555
|
onEvent({ protocolVersion: 1, kind: 'event', event: 'assistant.message.start', sequence: 5, payload: { sessionId: 'pi-session-5', directory: '/workspace', messageId: 'assistant-1', parentId: 'user-1', role: 'assistant', startedAt: 1 } });
|
|
548
556
|
onEvent({ protocolVersion: 1, kind: 'event', event: 'assistant.message.end', sequence: 6, payload: { sessionId: 'pi-session-5', directory: '/workspace', messageId: 'assistant-1', durationMs: 42, continuing: true, error: { code: 'ASSISTANT_ERROR', message: 'provider request timed out' } } });
|
|
549
557
|
onEvent({ protocolVersion: 1, kind: 'event', event: 'session.lifecycle', sequence: 7, payload: { sessionId: 'pi-session-5', directory: '/workspace', state: 'retry', attempt: 2, next: 8_000, message: 'provider request timed out' } });
|
|
550
558
|
onEvent({ protocolVersion: 1, kind: 'event', event: 'session.error', sequence: 8, payload: { sessionId: 'pi-session-5', directory: '/workspace', code: 'ASSISTANT_ERROR', message: 'provider request timed out' } });
|
|
559
|
+
onEvent({ protocolVersion: 1, kind: 'event', event: 'session.tool.start', sequence: 9, payload: { sessionId: 'pi-session-5', directory: '/workspace', toolCallId: 'skill-read', partId: 'assistant-1:tool:skill-read', messageId: 'assistant-1', name: 'read', state: 'running', metadata: { pichamber: { skill: { name: 'review' } } }, privatePath: '/private/skill/SKILL.md' } });
|
|
560
|
+
onEvent({ protocolVersion: 1, kind: 'event', event: 'session.compaction', sequence: 10, payload: { sessionId: 'pi-session-5', directory: '/workspace', phase: 'completed', reason: 'overflow', startedAt: 3_000, completedAt: 9_000, tokensBefore: 120_000, estimatedTokensAfter: 24_000, willRetry: true, privateResult: 'hidden' } });
|
|
551
561
|
return () => {};
|
|
552
562
|
},
|
|
553
563
|
};
|
|
@@ -558,7 +568,7 @@ describe('Pi runtime route', () => {
|
|
|
558
568
|
const reader = response.body.getReader();
|
|
559
569
|
const first = await reader.read();
|
|
560
570
|
let text = new TextDecoder().decode(first.value);
|
|
561
|
-
while (!text.includes('"
|
|
571
|
+
while (!text.includes('"phase":"completed"')) {
|
|
562
572
|
const next = await reader.read();
|
|
563
573
|
if (next.done) break;
|
|
564
574
|
text += new TextDecoder().decode(next.value);
|
|
@@ -567,11 +577,16 @@ describe('Pi runtime route', () => {
|
|
|
567
577
|
expect(text).toContain('"name":"session.snapshot"');
|
|
568
578
|
expect(text).toContain('"lastSequence":4');
|
|
569
579
|
expect(text).toContain('"retry":{"attempt":1,"next":4000,"message":"provider request timed out"}');
|
|
580
|
+
expect(text).toContain('"compaction":{"phase":"running","reason":"overflow","startedAt":3000}');
|
|
570
581
|
expect(text).toContain('"parentId":"user-1"');
|
|
571
582
|
expect(text).toContain('"durationMs":42');
|
|
572
583
|
expect(text).toContain('"continuing":true');
|
|
573
584
|
expect(text).toContain('"state":"retry","attempt":2,"next":8000,"message":"provider request timed out"');
|
|
574
585
|
expect(text).toContain('"message":"provider request timed out"');
|
|
586
|
+
expect(text).toContain('"metadata":{"pichamber":{"skill":{"name":"review"}}}');
|
|
587
|
+
expect(text).toContain('"phase":"completed","reason":"overflow","startedAt":3000,"completedAt":9000,"tokensBefore":120000,"estimatedTokensAfter":24000,"willRetry":true');
|
|
588
|
+
expect(text).not.toContain('privatePath');
|
|
589
|
+
expect(text).not.toContain('privateResult');
|
|
575
590
|
expect(text).not.toContain('/private/socket');
|
|
576
591
|
});
|
|
577
592
|
|