@pi-chamber/web 1.0.2 → 1.0.3-rc.1
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/assets/{DiagramView-C3jwAdba.js → DiagramView-CXjieF51.js} +1 -1
- package/dist/assets/DiffView-CXg8TAtI.js +18 -0
- package/dist/assets/{FileSaveConflictDialog-BDHl1ERM.js → FileSaveConflictDialog-a-HOCgyP.js} +1 -1
- package/dist/assets/{FilesView-DjD5jjcd.js → FilesView-Dcd9ltOX.js} +1 -1
- package/dist/assets/{GitView-D_TzczhS.js → GitView-DF2nsuSA.js} +3 -3
- package/dist/assets/{JsonTreeView-BTMtZylb.js → JsonTreeView-BRU2mRTd.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-DnZhLsfY.js → MarkdownRendererImpl-CeYMkg1A.js} +5 -5
- package/dist/assets/{PatchDiff-D4jQKTZA.js → PatchDiff-kSTpjhu6.js} +1 -1
- package/dist/assets/{SessionSwitcherContent-BX6P7l8U.js → SessionSwitcherContent-BsXDFt24.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-DGvRKfRw.js → SessionSwitcherDropdown-D8fSObHr.js} +2 -2
- package/dist/assets/{SessionUnreadDot-CPTTyo0r.js → SessionUnreadDot-BpsHyrri.js} +1 -1
- package/dist/assets/SettingsView-OEl7QmXC.js +6 -0
- package/dist/assets/{SettingsWindow-MrdvHysy.js → SettingsWindow-BMBCj_L_.js} +1 -1
- package/dist/assets/{ToolOutputDialog-9UTlcthG.js → ToolOutputDialog-KOVdmTqm.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-D_HifNve.js → ToolPartDiffPreview-B9xuVvkm.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-CvqZNzUR.js → VirtualizedFileDiff-CV_Cpmqu.js} +4 -4
- package/dist/assets/{collapsible-BencOwkW.js → collapsible-BH1vXEAI.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-B1Zc3P5v.js → computeVirtualFileMetrics-yHZbtf5H.js} +2 -2
- package/dist/assets/{contextFileOpenGuard-CJZHfvjH.js → contextFileOpenGuard-BA2pkQY_.js} +1 -1
- package/dist/assets/{gitStatusPredicates-C7tetvAB.js → gitStatusPredicates-CpGQLvMK.js} +1 -1
- package/dist/assets/index-5fyXnZFi.css +1 -0
- package/dist/assets/{index-CpSdU-d4.js → index-C-sV_9sb.js} +3 -3
- package/dist/assets/{index-DYXaDVnz.js → index-D_FGGnQQ.js} +1 -1
- package/dist/assets/{isDiffPlainText-DMMH-XmY.js → isDiffPlainText-BNyusJZz.js} +1 -1
- package/dist/assets/{isFilePlainText-DcCgFOGI.js → isFilePlainText-CMAUe7qD.js} +1 -1
- package/dist/assets/{main-BZu7VLeY.js → main-BMLgZ5yn.js} +2 -2
- package/dist/assets/{main-DvtT25LM.js → main-DNq1n9F_.js} +3 -3
- package/dist/assets/{markdownCore-D6HZ46BO.js → markdownCore-CZWcaNr2.js} +2 -2
- package/dist/assets/{miniChat-CLS1HbGi.js → miniChat-B2AgUZqL.js} +2 -2
- package/dist/assets/{mobile-BuCJ5Obm.js → mobile-BsGiRUUg.js} +2 -2
- package/dist/assets/{renderElectronMiniChatApp-BtREv0kE.js → renderElectronMiniChatApp-UV9dnnbf.js} +2 -2
- package/dist/assets/renderMobileApp-BMifduGA.js +11 -0
- package/dist/assets/runtimeEndpointReset-CkvC02dQ.js +53 -0
- package/dist/assets/{runtimeSurface-Bm6cRkok.js → runtimeSurface-BdndJV2m.js} +1 -1
- package/dist/assets/{useAppFontEffects-SHxBpd4f.js → useAppFontEffects-CclUs9KY.js} +98 -98
- package/dist/assets/{useFilesViewSearch-CJ6yYAoc.js → useFilesViewSearch-CI5Gy1cp.js} +1 -1
- package/dist/assets/{usePushVisibilityBeacon-mnTxlkQZ.js → usePushVisibilityBeacon-aDmGZrTW.js} +3 -3
- package/dist/assets/{useSwitcherItems-DWUNXYMV.js → useSwitcherItems-BZKyNjhp.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-B4enwgcI.js → vendor-codemirror-language-data-C6LBD7qA.js} +2 -2
- package/dist/assets/{web-components-ldhQxnFE.js → web-components-Cdnmh4Xb.js} +4 -4
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/lib/pi/model-config-store.js +146 -20
- package/server/lib/pi/model-config-store.test.js +153 -21
- package/server/lib/pi/routes.js +42 -1
- package/server/lib/pi/routes.test.js +104 -2
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +3 -2
- package/server/lib/pi/session-daemon/session-daemon.js +322 -58
- package/server/lib/pi/session-daemon/session-daemon.test.js +335 -0
- package/server/lib/pi/session-daemon/session-failed-create-cleanup.test.js +372 -0
- package/server/lib/pi/session-persistence-gap.test.js +731 -0
- package/dist/assets/DiffView-CqPv7nw1.js +0 -18
- package/dist/assets/SettingsView-CD0EfMno.js +0 -2
- package/dist/assets/index-Dwz16owi.css +0 -1
- package/dist/assets/renderMobileApp-UF8ITb8A.js +0 -11
- package/dist/assets/runtimeEndpointReset-BcdDES-U.js +0 -53
|
@@ -1709,6 +1709,341 @@ describe('Pi session daemon spike', () => {
|
|
|
1709
1709
|
await client.close();
|
|
1710
1710
|
});
|
|
1711
1711
|
|
|
1712
|
+
it('adds a single model to an existing file provider without replacing other models', async () => {
|
|
1713
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-'));
|
|
1714
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1715
|
+
const added = [];
|
|
1716
|
+
const session = new FakeSession();
|
|
1717
|
+
session.modelRuntime.getProvider = (providerId) => providerId === 'custom'
|
|
1718
|
+
? { id: 'custom', name: 'Custom', baseUrl: 'https://api.example.test/v1' }
|
|
1719
|
+
: undefined;
|
|
1720
|
+
session.modelRuntime.getModels = (providerId) => providerId === 'custom' || providerId === undefined
|
|
1721
|
+
? [{ provider: 'custom', id: 'model-1', name: 'Model 1', api: 'openai-completions', baseUrl: 'https://api.example.test/v1', reasoning: false, contextWindow: 128_000, maxTokens: 16_384, input: ['text'], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } }]
|
|
1722
|
+
: [];
|
|
1723
|
+
session.modelRuntime.getModel = (providerId, modelId) => providerId === 'custom' && modelId === 'model-1'
|
|
1724
|
+
? { provider: 'custom', id: 'model-1' }
|
|
1725
|
+
: undefined;
|
|
1726
|
+
const modelConfigStore = {
|
|
1727
|
+
get: async (providerId) => providerId === 'custom'
|
|
1728
|
+
? { providerId: 'custom', label: 'Custom', baseUrl: 'https://api.example.test/v1', api: 'openai-completions', models: [{ id: 'model-1', providerId: 'custom', label: 'Model 1' }] }
|
|
1729
|
+
: null,
|
|
1730
|
+
addModel: async (input) => {
|
|
1731
|
+
added.push(input);
|
|
1732
|
+
return { providerId: input.providerId, label: 'Custom', baseUrl: 'https://api.example.test/v1', api: 'openai-completions', models: [{ id: 'model-1', providerId: 'custom', label: 'Model 1' }, { id: 'model-2', providerId: 'custom', label: 'Model 2' }] };
|
|
1733
|
+
},
|
|
1734
|
+
};
|
|
1735
|
+
daemon = createSessionDaemon({
|
|
1736
|
+
endpoint, credential, cwd: root, modelConfigStore,
|
|
1737
|
+
createRuntime: async () => ({ session, async dispose() {} }),
|
|
1738
|
+
});
|
|
1739
|
+
await daemon.start();
|
|
1740
|
+
const client = connectClient(endpoint);
|
|
1741
|
+
await client.authenticate();
|
|
1742
|
+
const result = await client.request('providers.models.add', {
|
|
1743
|
+
providerId: 'custom',
|
|
1744
|
+
model: { id: ' model-2 ', label: 'Model 2' },
|
|
1745
|
+
});
|
|
1746
|
+
expect(result.result).toEqual({ config: { providerId: 'custom', label: 'Custom', baseUrl: 'https://api.example.test/v1', api: 'openai-completions', models: [{ id: 'model-1', providerId: 'custom', label: 'Model 1' }, { id: 'model-2', providerId: 'custom', label: 'Model 2' }] } });
|
|
1747
|
+
expect(added).toHaveLength(1);
|
|
1748
|
+
expect(added[0]).toEqual({ providerId: 'custom', model: { id: ' model-2 ', label: 'Model 2' } });
|
|
1749
|
+
expect(JSON.stringify(result.result)).not.toContain('CUSTOM_KEY');
|
|
1750
|
+
await client.close();
|
|
1751
|
+
});
|
|
1752
|
+
|
|
1753
|
+
it('seeds a missing file provider from live runtime metadata only when safely representable', async () => {
|
|
1754
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-'));
|
|
1755
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1756
|
+
const added = [];
|
|
1757
|
+
const session = new FakeSession();
|
|
1758
|
+
session.modelRuntime.getProvider = (providerId) => providerId === 'live-custom'
|
|
1759
|
+
? { id: 'live-custom', name: 'Live Custom', baseUrl: 'https://api.example.test/v1' }
|
|
1760
|
+
: undefined;
|
|
1761
|
+
session.modelRuntime.getModels = (providerId) => providerId === 'live-custom' || providerId === undefined
|
|
1762
|
+
? [
|
|
1763
|
+
{ provider: 'live-custom', id: 'existing', name: 'Existing', api: 'openai-completions', baseUrl: 'https://api.example.test/v1', reasoning: false, contextWindow: 128_000, maxTokens: 16_384, input: ['text'], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } },
|
|
1764
|
+
]
|
|
1765
|
+
: [];
|
|
1766
|
+
session.modelRuntime.getModel = () => undefined;
|
|
1767
|
+
const modelConfigStore = {
|
|
1768
|
+
get: async () => null,
|
|
1769
|
+
addModel: async (input) => {
|
|
1770
|
+
added.push(input);
|
|
1771
|
+
return { providerId: input.providerId, label: input.seed.label, baseUrl: input.seed.baseUrl, api: input.seed.api, models: [{ id: input.model.id, providerId: input.providerId, label: input.model.label }] };
|
|
1772
|
+
},
|
|
1773
|
+
};
|
|
1774
|
+
daemon = createSessionDaemon({
|
|
1775
|
+
endpoint, credential, cwd: root, modelConfigStore,
|
|
1776
|
+
createRuntime: async () => ({ session, async dispose() {} }),
|
|
1777
|
+
});
|
|
1778
|
+
await daemon.start();
|
|
1779
|
+
const client = connectClient(endpoint);
|
|
1780
|
+
await client.authenticate();
|
|
1781
|
+
const result = await client.request('providers.models.add', {
|
|
1782
|
+
providerId: 'live-custom',
|
|
1783
|
+
model: { id: 'new-model', label: 'New Model', contextWindow: 32_000, supportsThinking: true },
|
|
1784
|
+
});
|
|
1785
|
+
expect(result.result.config).toMatchObject({ providerId: 'live-custom', label: 'Live Custom', baseUrl: 'https://api.example.test/v1', api: 'openai-completions' });
|
|
1786
|
+
expect(added).toHaveLength(1);
|
|
1787
|
+
expect(added[0]).toEqual({
|
|
1788
|
+
providerId: 'live-custom',
|
|
1789
|
+
model: { id: 'new-model', label: 'New Model', contextWindow: 32_000, supportsThinking: true },
|
|
1790
|
+
seed: { label: 'Live Custom', baseUrl: 'https://api.example.test/v1', api: 'openai-completions' },
|
|
1791
|
+
});
|
|
1792
|
+
await client.close();
|
|
1793
|
+
});
|
|
1794
|
+
|
|
1795
|
+
it('reaches the store for native providers and extensions without explicit models', async () => {
|
|
1796
|
+
const cases = [
|
|
1797
|
+
{
|
|
1798
|
+
name: 'native',
|
|
1799
|
+
providerId: 'native-p',
|
|
1800
|
+
modelRuntime: {
|
|
1801
|
+
getProvider: () => ({ id: 'native-p', name: 'Native' }),
|
|
1802
|
+
getModels: () => [{ provider: 'native-p', id: 'm', api: 'openai-completions', baseUrl: 'https://api.example.test/v1' }],
|
|
1803
|
+
getModel: () => undefined,
|
|
1804
|
+
getRegisteredProviderConfig: () => undefined,
|
|
1805
|
+
},
|
|
1806
|
+
},
|
|
1807
|
+
{
|
|
1808
|
+
name: 'extension-without-models',
|
|
1809
|
+
providerId: 'ext-p',
|
|
1810
|
+
modelRuntime: {
|
|
1811
|
+
getProvider: () => ({ id: 'ext-p', name: 'Ext' }),
|
|
1812
|
+
getModels: () => [{ provider: 'ext-p', id: 'm', api: 'openai-completions', baseUrl: 'https://api.example.test/v1' }],
|
|
1813
|
+
getModel: () => undefined,
|
|
1814
|
+
getRegisteredProviderConfig: () => ({ baseUrl: 'https://override.test' }),
|
|
1815
|
+
},
|
|
1816
|
+
},
|
|
1817
|
+
{
|
|
1818
|
+
name: 'custom-stream-without-models',
|
|
1819
|
+
providerId: 'stream-p',
|
|
1820
|
+
modelRuntime: {
|
|
1821
|
+
getProvider: () => ({ id: 'stream-p', name: 'Stream' }),
|
|
1822
|
+
getModels: () => [{ provider: 'stream-p', id: 'm', api: 'openai-completions', baseUrl: 'https://api.example.test/v1' }],
|
|
1823
|
+
getModel: () => undefined,
|
|
1824
|
+
getRegisteredProviderConfig: () => ({ streamSimple: async () => {}, api: 'openai-completions' }),
|
|
1825
|
+
},
|
|
1826
|
+
},
|
|
1827
|
+
];
|
|
1828
|
+
for (const testCase of cases) {
|
|
1829
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-'));
|
|
1830
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1831
|
+
let written = 0;
|
|
1832
|
+
const session = new FakeSession();
|
|
1833
|
+
session.modelRuntime = { ...session.modelRuntime, ...testCase.modelRuntime };
|
|
1834
|
+
const modelConfigStore = {
|
|
1835
|
+
get: async () => ({ providerId: testCase.providerId, label: 'Label', baseUrl: 'https://api.example.test/v1', api: 'openai-completions', models: [] }),
|
|
1836
|
+
addModel: async (input) => {
|
|
1837
|
+
written += 1;
|
|
1838
|
+
expect(input).toEqual({ providerId: testCase.providerId, model: { id: 'model-1', label: 'Model 1' } });
|
|
1839
|
+
return { providerId: testCase.providerId, label: 'Label', baseUrl: 'https://api.example.test/v1', api: 'openai-completions', models: [{ id: 'model-1', providerId: testCase.providerId, label: 'Model 1' }] };
|
|
1840
|
+
},
|
|
1841
|
+
};
|
|
1842
|
+
daemon = createSessionDaemon({
|
|
1843
|
+
endpoint, credential, cwd: root, modelConfigStore,
|
|
1844
|
+
createRuntime: async () => ({ session, async dispose() {} }),
|
|
1845
|
+
});
|
|
1846
|
+
await daemon.start();
|
|
1847
|
+
const client = connectClient(endpoint);
|
|
1848
|
+
await client.authenticate();
|
|
1849
|
+
const result = await client.request('providers.models.add', {
|
|
1850
|
+
providerId: testCase.providerId,
|
|
1851
|
+
model: { id: 'model-1', label: 'Model 1' },
|
|
1852
|
+
});
|
|
1853
|
+
expect(result.result.config.providerId, testCase.name).toBe(testCase.providerId);
|
|
1854
|
+
expect(written, testCase.name).toBe(1);
|
|
1855
|
+
expect(JSON.stringify(result.result)).not.toContain('CUSTOM_KEY');
|
|
1856
|
+
await client.close();
|
|
1857
|
+
await daemon.stop();
|
|
1858
|
+
daemon = undefined;
|
|
1859
|
+
}
|
|
1860
|
+
});
|
|
1861
|
+
|
|
1862
|
+
it('rejects explicit extension models, ambiguous, duplicate, and missing providers before writing', async () => {
|
|
1863
|
+
const cases = [
|
|
1864
|
+
{
|
|
1865
|
+
name: 'extension-with-models',
|
|
1866
|
+
providerId: 'ext-models-p',
|
|
1867
|
+
modelRuntime: {
|
|
1868
|
+
getProvider: () => ({ id: 'ext-models-p', name: 'Ext' }),
|
|
1869
|
+
getModels: () => [{ provider: 'ext-models-p', id: 'm', api: 'openai-completions', baseUrl: 'https://api.example.test/v1' }],
|
|
1870
|
+
getModel: () => undefined,
|
|
1871
|
+
getRegisteredProviderConfig: () => ({ baseUrl: 'https://override.test', models: [{ id: 'm' }] }),
|
|
1872
|
+
},
|
|
1873
|
+
fileConfig: { providerId: 'ext-models-p', label: 'Ext', baseUrl: 'https://api.example.test/v1', api: 'openai-completions', models: [] },
|
|
1874
|
+
expected: 'INVALID_ARGUMENT',
|
|
1875
|
+
},
|
|
1876
|
+
{
|
|
1877
|
+
name: 'extension-models-with-stream',
|
|
1878
|
+
providerId: 'ext-stream-models-p',
|
|
1879
|
+
modelRuntime: {
|
|
1880
|
+
getProvider: () => ({ id: 'ext-stream-models-p', name: 'Ext' }),
|
|
1881
|
+
getModels: () => [{ provider: 'ext-stream-models-p', id: 'm', api: 'openai-completions', baseUrl: 'https://api.example.test/v1' }],
|
|
1882
|
+
getModel: () => undefined,
|
|
1883
|
+
getRegisteredProviderConfig: () => ({ streamSimple: async () => {}, api: 'openai-completions', models: [{ id: 'm' }] }),
|
|
1884
|
+
},
|
|
1885
|
+
fileConfig: { providerId: 'ext-stream-models-p', label: 'Ext', baseUrl: 'https://api.example.test/v1', api: 'openai-completions', models: [] },
|
|
1886
|
+
expected: 'INVALID_ARGUMENT',
|
|
1887
|
+
},
|
|
1888
|
+
{
|
|
1889
|
+
name: 'ambiguous-base-url',
|
|
1890
|
+
providerId: 'amb-p',
|
|
1891
|
+
modelRuntime: {
|
|
1892
|
+
getProvider: () => ({ id: 'amb-p', name: 'Amb' }),
|
|
1893
|
+
getModels: () => [
|
|
1894
|
+
{ provider: 'amb-p', id: 'a', api: 'openai-completions', baseUrl: 'https://one.test' },
|
|
1895
|
+
{ provider: 'amb-p', id: 'b', api: 'openai-completions', baseUrl: 'https://two.test' },
|
|
1896
|
+
],
|
|
1897
|
+
getModel: () => undefined,
|
|
1898
|
+
getRegisteredNativeProvider: () => undefined,
|
|
1899
|
+
getRegisteredProviderConfig: () => undefined,
|
|
1900
|
+
},
|
|
1901
|
+
fileConfig: null,
|
|
1902
|
+
expected: 'INVALID_ARGUMENT',
|
|
1903
|
+
},
|
|
1904
|
+
{
|
|
1905
|
+
name: 'unsupported-api',
|
|
1906
|
+
providerId: 'bedrock-p',
|
|
1907
|
+
modelRuntime: {
|
|
1908
|
+
getProvider: () => ({ id: 'bedrock-p', name: 'Bedrock' }),
|
|
1909
|
+
getModels: () => [{ provider: 'bedrock-p', id: 'm', api: 'bedrock-converse-stream', baseUrl: 'https://bedrock.test' }],
|
|
1910
|
+
getModel: () => undefined,
|
|
1911
|
+
getRegisteredNativeProvider: () => undefined,
|
|
1912
|
+
getRegisteredProviderConfig: () => undefined,
|
|
1913
|
+
},
|
|
1914
|
+
fileConfig: null,
|
|
1915
|
+
expected: 'INVALID_ARGUMENT',
|
|
1916
|
+
},
|
|
1917
|
+
{
|
|
1918
|
+
name: 'duplicate-live',
|
|
1919
|
+
providerId: 'dup-p',
|
|
1920
|
+
modelRuntime: {
|
|
1921
|
+
getProvider: () => ({ id: 'dup-p', name: 'Dup' }),
|
|
1922
|
+
getModels: () => [{ provider: 'dup-p', id: 'model-1', api: 'openai-completions', baseUrl: 'https://api.example.test/v1' }],
|
|
1923
|
+
getModel: (providerId, modelId) => providerId === 'dup-p' && modelId === 'model-1' ? { provider: 'dup-p', id: 'model-1' } : undefined,
|
|
1924
|
+
getRegisteredNativeProvider: () => undefined,
|
|
1925
|
+
getRegisteredProviderConfig: () => undefined,
|
|
1926
|
+
},
|
|
1927
|
+
fileConfig: { providerId: 'dup-p', label: 'Dup', baseUrl: 'https://api.example.test/v1', api: 'openai-completions', models: [] },
|
|
1928
|
+
expected: 'INVALID_ARGUMENT',
|
|
1929
|
+
},
|
|
1930
|
+
{
|
|
1931
|
+
name: 'missing-live',
|
|
1932
|
+
providerId: 'ghost-p',
|
|
1933
|
+
modelRuntime: {
|
|
1934
|
+
getProvider: () => undefined,
|
|
1935
|
+
getModels: () => [],
|
|
1936
|
+
getModel: () => undefined,
|
|
1937
|
+
getRegisteredNativeProvider: () => undefined,
|
|
1938
|
+
getRegisteredProviderConfig: () => undefined,
|
|
1939
|
+
},
|
|
1940
|
+
fileConfig: null,
|
|
1941
|
+
expected: 'PROVIDER_NOT_FOUND',
|
|
1942
|
+
},
|
|
1943
|
+
];
|
|
1944
|
+
for (const testCase of cases) {
|
|
1945
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-'));
|
|
1946
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1947
|
+
let written = 0;
|
|
1948
|
+
const session = new FakeSession();
|
|
1949
|
+
session.modelRuntime = { ...session.modelRuntime, ...testCase.modelRuntime };
|
|
1950
|
+
const modelConfigStore = {
|
|
1951
|
+
get: async () => testCase.fileConfig,
|
|
1952
|
+
addModel: async () => { written += 1; throw new Error('must not write'); },
|
|
1953
|
+
};
|
|
1954
|
+
daemon = createSessionDaemon({
|
|
1955
|
+
endpoint, credential, cwd: root, modelConfigStore,
|
|
1956
|
+
createRuntime: async () => ({ session, async dispose() {} }),
|
|
1957
|
+
});
|
|
1958
|
+
await daemon.start();
|
|
1959
|
+
const client = connectClient(endpoint);
|
|
1960
|
+
await client.authenticate();
|
|
1961
|
+
const requestId = `request-${Math.random()}`;
|
|
1962
|
+
const errorPromise = client.next((message) => message.kind === 'error');
|
|
1963
|
+
client.socket.write(`${JSON.stringify({ protocolVersion: 1, kind: 'request', requestId, command: 'providers.models.add', payload: { providerId: testCase.providerId, model: { id: 'model-1', label: 'Model 1' } } })}\n`);
|
|
1964
|
+
await expect(errorPromise).resolves.toMatchObject({ error: { code: testCase.expected } });
|
|
1965
|
+
expect(written, testCase.name).toBe(0);
|
|
1966
|
+
await client.close();
|
|
1967
|
+
await daemon.stop();
|
|
1968
|
+
daemon = undefined;
|
|
1969
|
+
}
|
|
1970
|
+
});
|
|
1971
|
+
|
|
1972
|
+
it('maps a locked concurrent duplicate to INVALID_ARGUMENT, not config corruption', async () => {
|
|
1973
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-'));
|
|
1974
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1975
|
+
const session = new FakeSession();
|
|
1976
|
+
session.modelRuntime.getProvider = (providerId) => providerId === 'custom'
|
|
1977
|
+
? { id: 'custom', name: 'Custom', baseUrl: 'https://api.example.test/v1' }
|
|
1978
|
+
: undefined;
|
|
1979
|
+
session.modelRuntime.getModels = () => [{ provider: 'custom', id: 'model-1', name: 'Model 1', api: 'openai-completions', baseUrl: 'https://api.example.test/v1', reasoning: false, contextWindow: 128_000, maxTokens: 16_384, input: ['text'], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } }];
|
|
1980
|
+
session.modelRuntime.getModel = () => undefined;
|
|
1981
|
+
const duplicate = Object.assign(new Error('The model already exists for this provider.'), { code: 'PI_MODEL_DUPLICATE' });
|
|
1982
|
+
const modelConfigStore = {
|
|
1983
|
+
get: async () => ({ providerId: 'custom', label: 'Custom', baseUrl: 'https://api.example.test/v1', api: 'openai-completions', models: [{ id: 'model-1', providerId: 'custom', label: 'Model 1' }] }),
|
|
1984
|
+
addModel: async () => { throw duplicate; },
|
|
1985
|
+
};
|
|
1986
|
+
daemon = createSessionDaemon({
|
|
1987
|
+
endpoint, credential, cwd: root, modelConfigStore,
|
|
1988
|
+
createRuntime: async () => ({ session, async dispose() {} }),
|
|
1989
|
+
});
|
|
1990
|
+
await daemon.start();
|
|
1991
|
+
const client = connectClient(endpoint);
|
|
1992
|
+
await client.authenticate();
|
|
1993
|
+
const requestId = `request-${Math.random()}`;
|
|
1994
|
+
const errorPromise = client.next((message) => message.kind === 'error');
|
|
1995
|
+
client.socket.write(`${JSON.stringify({ protocolVersion: 1, kind: 'request', requestId, command: 'providers.models.add', payload: { providerId: 'custom', model: { id: 'model-2', label: 'Model 2' } } })}\n`);
|
|
1996
|
+
await expect(errorPromise).resolves.toMatchObject({ error: { code: 'INVALID_ARGUMENT' } });
|
|
1997
|
+
await client.close();
|
|
1998
|
+
await daemon.stop();
|
|
1999
|
+
daemon = undefined;
|
|
2000
|
+
});
|
|
2001
|
+
|
|
2002
|
+
it('defers manual model adds while streaming and recreates after settlement', async () => {
|
|
2003
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-provider-busy-'));
|
|
2004
|
+
const endpoint = testDaemonEndpoint(root);
|
|
2005
|
+
const session = new FakeSession();
|
|
2006
|
+
session.modelRuntime.getProvider = (providerId) => providerId === 'custom' ? { id: 'custom', name: 'Custom', baseUrl: 'https://api.example.test/v1' } : undefined;
|
|
2007
|
+
session.modelRuntime.getModels = () => [{ provider: 'custom', id: 'model-1', name: 'Model 1', api: 'openai-completions', baseUrl: 'https://api.example.test/v1', reasoning: false, contextWindow: 128_000, maxTokens: 16_384, input: ['text'], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } }];
|
|
2008
|
+
session.modelRuntime.getModel = (providerId, modelId) => providerId === 'custom' && modelId === 'model-1' ? { provider: 'custom', id: 'model-1' } : undefined;
|
|
2009
|
+
const runtimeState = { createCount: 0, disposeCount: 0 };
|
|
2010
|
+
const modelConfigStore = {
|
|
2011
|
+
get: async () => ({ providerId: 'custom', label: 'Custom', baseUrl: 'https://api.example.test/v1', api: 'openai-completions', models: [{ id: 'model-1', providerId: 'custom', label: 'Model 1' }] }),
|
|
2012
|
+
addModel: async (input) => ({ providerId: input.providerId, label: 'Custom', baseUrl: 'https://api.example.test/v1', api: 'openai-completions', models: [{ id: 'model-1', providerId: 'custom', label: 'Model 1' }, { id: 'model-2', providerId: 'custom', label: 'Model 2' }] }),
|
|
2013
|
+
};
|
|
2014
|
+
daemon = createSessionDaemon({
|
|
2015
|
+
endpoint,
|
|
2016
|
+
credential,
|
|
2017
|
+
cwd: root,
|
|
2018
|
+
modelConfigStore,
|
|
2019
|
+
createRuntime: async () => {
|
|
2020
|
+
runtimeState.createCount += 1;
|
|
2021
|
+
return { cwd: root, session, async dispose() { runtimeState.disposeCount += 1; } };
|
|
2022
|
+
},
|
|
2023
|
+
});
|
|
2024
|
+
await daemon.start();
|
|
2025
|
+
const client = connectClient(endpoint);
|
|
2026
|
+
await client.authenticate();
|
|
2027
|
+
await client.request('sessions.create', { cwd: root });
|
|
2028
|
+
session.isStreaming = true;
|
|
2029
|
+
const result = await client.request('providers.models.add', {
|
|
2030
|
+
providerId: 'custom',
|
|
2031
|
+
model: { id: 'model-2', label: 'Model 2' },
|
|
2032
|
+
});
|
|
2033
|
+
expect(result.result).toMatchObject({ config: { providerId: 'custom' }, deferred: true });
|
|
2034
|
+
expect(runtimeState).toEqual({ createCount: 1, disposeCount: 0 });
|
|
2035
|
+
const providerChange = client.next((message) => message.event === 'extension.catalog' && message.payload?.providers === true);
|
|
2036
|
+
session.isStreaming = false;
|
|
2037
|
+
session.emit({ type: 'agent_settled' });
|
|
2038
|
+
await expect.poll(() => runtimeState.disposeCount).toBe(1);
|
|
2039
|
+
expect(runtimeState.createCount).toBe(2);
|
|
2040
|
+
await expect(providerChange).resolves.toMatchObject({
|
|
2041
|
+
event: 'extension.catalog',
|
|
2042
|
+
payload: { providers: true },
|
|
2043
|
+
});
|
|
2044
|
+
await client.close();
|
|
2045
|
+
});
|
|
2046
|
+
|
|
1712
2047
|
it('runs persisted API-key and interactive OAuth logins without exposing credential values in daemon responses', async () => {
|
|
1713
2048
|
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-'));
|
|
1714
2049
|
const endpoint = testDaemonEndpoint(root);
|