@openchambery/web 1.19.7-beta.2 → 1.19.7-beta.21
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/AgentAvatar-DI2zs2WH.js +1 -0
- package/dist/assets/AssistantView-sV1PVQiM.js +2 -0
- package/dist/assets/DiagramView-D2hqP5VV.js +1 -0
- package/dist/assets/FadeInOnReveal-BWJcUp5P.js +1 -0
- package/dist/assets/Icon-4My8YZwt.js +1 -0
- package/dist/assets/MarkdownLoadingSkeleton-Vezjvk9B.js +3 -0
- package/dist/assets/MarkdownRenderer-x091Z--3.js +2 -0
- package/dist/assets/MarkdownRendererImpl-DML8BSro.js +7 -0
- package/dist/assets/MarkstreamRendererImpl-BK-HM2k3.js +1 -0
- package/dist/assets/{MarkstreamRendererImpl-CR0fBG5w.css → MarkstreamRendererImpl-Ca7RATbs.css} +1 -1
- package/dist/assets/MobileDetailNavigation-DcxkWiks.js +1 -0
- package/dist/assets/MobileShareBridge-TAGcOiyb.js +4 -0
- package/dist/assets/MobileSurface-zqlZzEFQ.js +2 -0
- package/dist/assets/{MultiRunWindow-khpnWyZO.js → MultiRunWindow-iH1d9S14.js} +1 -1
- package/dist/assets/OnboardingScreen-BNEtPmvw.js +1 -0
- package/dist/assets/OverlayScrollbar-BZB21Yp_.js +2 -0
- package/dist/assets/SettingsView-CzW23DZA.js +25 -0
- package/dist/assets/{SettingsWindow-Dx5rU9v5.js → SettingsWindow-DZXCWZid.js} +1 -1
- package/dist/assets/TerminalView-pU0wpD8s.js +8 -0
- package/dist/assets/ToolOutputDialog-Bt7JChFG.js +10 -0
- package/dist/assets/appThemeRegistry-BI7WR2Wo.js +1 -0
- package/dist/assets/{button-z0GOBtWi.js → button-Or0daT9o.js} +1 -1
- package/dist/assets/clipboard-BXxLshVq.js +1 -0
- package/dist/assets/{collapsible-D9zJRpeB.js → collapsible-C-kzSGkq.js} +1 -1
- package/dist/assets/context-menu-Dpjla5p4.js +1 -0
- package/dist/assets/desktopHosts-BzSE0sK7.js +1 -0
- package/dist/assets/desktopRelayRestore-BaKjk1kQ.js +1 -0
- package/dist/assets/{diagram-CoEqmReY.js → diagram-D0mT3mo1.js} +1 -1
- package/dist/assets/{dialog-HCE4eLUW.js → dialog-BkhHBTd4.js} +1 -1
- package/dist/assets/dropdown-menu.styles-Bzo6L3FH.js +1 -0
- package/dist/assets/{es-D9KcV5TX.js → es-BHqnSjoZ.js} +1 -1
- package/dist/assets/fileQueries-DFY6Kiy1.js +1 -0
- package/dist/assets/fileReferenceActions-Di_DoDex.js +1 -0
- package/dist/assets/{fr-DPA9qUl3.js → fr-BfrlJY9i.js} +1 -1
- package/dist/assets/{gitApi-DNTMAa3F.js → gitApi-CeFszLvk.js} +3 -3
- package/dist/assets/{input-BG3VWTIF.js → input-BUsGnzwe.js} +1 -1
- package/dist/assets/insertionBoundaries-DDJNusn2.js +4 -0
- package/dist/assets/{ja-Dsif3NoD.js → ja-DP-7qt-x.js} +1 -1
- package/dist/assets/{ko-Dixx4Ctg.js → ko-E2B5vGQP.js} +1 -1
- package/dist/assets/main-CjnOsKDL.js +169 -0
- package/dist/assets/main-j-Ij13jc.js +2 -0
- package/dist/assets/markdown-worker-BuveaH3O.js +1 -0
- package/dist/assets/markdownTheme-CVS01wHf.js +2 -0
- package/dist/assets/miniChat-DgxavREE.js +2 -0
- package/dist/assets/mobile-C0rwPMPM.js +2 -0
- package/dist/assets/multirun-ot7-bKg7.js +4 -0
- package/dist/assets/outsideFileGrants-BB4GPvCq.js +1 -0
- package/dist/assets/path-utils-jGozTg9d.js +1 -0
- package/dist/assets/persistence-CSZp1CNB.js +3 -0
- package/dist/assets/{pl-Bj78ZGgf.js → pl-r8X5gRM5.js} +1 -1
- package/dist/assets/platform-CenlWqxu.js +2 -0
- package/dist/assets/projectMeta-3yOEc0oI.js +3 -0
- package/dist/assets/{pt-BR-CFL3xSAf.js → pt-BR-DcpdXCf5.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-BPNvFA_N.js +2 -0
- package/dist/assets/renderMobileApp-CNog29Xy.js +28 -0
- package/dist/assets/runtimeConfig-D28kNEYO.js +2 -0
- package/dist/assets/runtimeEndpointReset-CorvFIRk.js +147 -0
- package/dist/assets/sessionChangeSummary-CX2MJIkc.js +1 -0
- package/dist/assets/sessionLookup-CbatbQf7.js +1 -0
- package/dist/assets/sortable-tabs-strip-C5gGnikj.js +1 -0
- package/dist/assets/src-Af9cMFKF.css +2 -0
- package/dist/assets/{store-DzpbXWX1.js → store-BDFdnk6l.js} +2 -2
- package/dist/assets/terminalApi-CIIs9vFx.js +1 -0
- package/dist/assets/textarea-CIO34TZz.js +1 -0
- package/dist/assets/toolHelpers-DEvVP9U0.js +2 -0
- package/dist/assets/{tooltip-CtH61mQh.js → tooltip-BSrJYYYc.js} +1 -1
- package/dist/assets/{uk-BY60Ub3Z.js → uk-Di0vl9V-.js} +1 -1
- package/dist/assets/url-CE_gAfNa.js +1 -0
- package/dist/assets/{ChatContainer-CnOrdAgs.js → useAppFontEffects-CDpeZWK4.js} +44 -39
- package/dist/assets/useAssistantUIStore-BHacrxe_.js +1 -0
- package/dist/assets/useDesktopWindowControlsLayout-D-xPByG0.js +1 -0
- package/dist/assets/useEffectiveDirectory-Dp-tez_r.js +1 -0
- package/dist/assets/useFontPreferences-BxOHKuVw.js +1 -0
- package/dist/assets/useMobileNavigationStore-DE1Pe9A9.js +412 -0
- package/dist/assets/useSessionAutoCleanup-jNJ_WC38.js +1 -0
- package/dist/assets/useUIStore-CqqO11ZI.js +1 -0
- package/dist/assets/useWorkerHighlightedLines-MDnGj3yv.js +7 -0
- package/dist/assets/utils-B0mQXN9L.js +1 -0
- package/dist/assets/{vendor-markstream-react-CwvbEg9R.js → vendor-markstream-react-C3K8YH0d.js} +4 -4
- package/dist/assets/{zh-CN-Cox1LaOW.js → zh-CN-coFCfeQE.js} +1 -1
- package/dist/assets/{zh-TW-B6RU0mxa.js → zh-TW-oDRZ1-yb.js} +1 -1
- package/dist/index.html +9 -11
- package/dist/mini-chat.html +9 -11
- package/dist/mobile.html +15 -17
- package/package.json +2 -1
- package/server/index.js +2 -0
- package/server/lib/assistant-delivery-parts.js +3 -1
- package/server/lib/assistant-delivery-parts.test.js +11 -0
- package/server/lib/assistants/DOCUMENTATION.md +76 -3
- package/server/lib/assistants/assign.js +225 -0
- package/server/lib/assistants/assign.test.js +118 -0
- package/server/lib/assistants/bubbles.js +45 -0
- package/server/lib/assistants/bubbles.test.js +36 -0
- package/server/lib/assistants/cards.js +148 -0
- package/server/lib/assistants/cards.test.js +116 -0
- package/server/lib/assistants/contact-store.js +284 -0
- package/server/lib/assistants/contact-store.test.js +131 -0
- package/server/lib/assistants/contact-tools.js +761 -0
- package/server/lib/assistants/contact-tools.test.js +328 -0
- package/server/lib/assistants/contracts.js +20 -1
- package/server/lib/assistants/harness.js +551 -0
- package/server/lib/assistants/harness.test.js +607 -0
- package/server/lib/assistants/routes.js +44 -4
- package/server/lib/assistants/service.js +930 -17
- package/server/lib/assistants/service.test.js +1163 -45
- package/server/lib/llm/DOCUMENTATION.md +84 -0
- package/server/lib/llm/catalog.js +100 -0
- package/server/lib/llm/catalog.test.js +78 -0
- package/server/lib/llm/completions.js +151 -0
- package/server/lib/llm/completions.test.js +127 -0
- package/server/lib/llm/generate.js +570 -0
- package/server/lib/llm/generate.test.js +459 -0
- package/server/lib/llm/routes.js +47 -0
- package/server/lib/llm/temp-directory.js +37 -0
- package/server/lib/notifications/APNS.md +23 -17
- package/server/lib/notifications/DOCUMENTATION.md +5 -4
- package/server/lib/notifications/apns-runtime.js +139 -20
- package/server/lib/notifications/apns-runtime.test.js +66 -7
- package/server/lib/notifications/apns-titles.js +62 -62
- package/server/lib/notifications/apns-titles.test.js +3 -1
- package/server/lib/notifications/routes.js +1 -1
- package/server/lib/notifications/runtime.js +177 -86
- package/server/lib/notifications/runtime.test.js +122 -0
- package/server/lib/opencode/feature-routes-runtime.js +30 -0
- package/server/lib/opencode/feature-routes-runtime.test.js +20 -0
- package/server/lib/opencode/settings-runtime.js +18 -2
- package/server/lib/session-goal/DOCUMENTATION.md +8 -1
- package/server/lib/session-goal/runtime.js +20 -0
- package/server/lib/session-index/DOCUMENTATION.md +3 -1
- package/server/lib/session-index/service.js +10 -4
- package/server/lib/session-index/service.test.js +37 -0
- package/server/lib/session-title/runtime.js +1 -0
- package/server/lib/session-title/runtime.test.js +11 -0
- package/dist/assets/AgentAvatar-ziUs4sw3.js +0 -1
- package/dist/assets/AssistantView-DF4yXFgS.js +0 -1
- package/dist/assets/ContextPanel-Cg_uCHzJ.js +0 -285
- package/dist/assets/DiagramView-DYh3Zn2y.js +0 -1
- package/dist/assets/FadeInOnReveal-BAlsRFJH.js +0 -1
- package/dist/assets/Icon-CLpn1mIz.js +0 -1
- package/dist/assets/MarkdownRendererImpl-QzUEpBEm.js +0 -7
- package/dist/assets/MarkstreamRendererImpl-CXrfeUia.js +0 -1
- package/dist/assets/MobileDetailNavigation-DJXEYfq4.js +0 -1
- package/dist/assets/MobileShareBridge-CliVo1YH.js +0 -4
- package/dist/assets/MobileSurface-9Xh6WQkY.js +0 -2
- package/dist/assets/OnboardingScreen-CJYyR54B.js +0 -1
- package/dist/assets/OverlayScrollbar-C-jZ8ITG.js +0 -2
- package/dist/assets/SettingsView-DyCZehFG.js +0 -25
- package/dist/assets/TerminalView-XSALfUaH.js +0 -8
- package/dist/assets/ToolOutputDialog-BfuXazW9.js +0 -10
- package/dist/assets/appThemeRegistry-DDWrniMM.js +0 -2
- package/dist/assets/clipboard-Bz0Zm9VJ.js +0 -1
- package/dist/assets/desktop-CfLlmafK.js +0 -1
- package/dist/assets/desktopHosts-C1Ns3DUu.js +0 -1
- package/dist/assets/desktopRelayRestore-LBt0CBOj.js +0 -1
- package/dist/assets/fileQueries-Dnn15WsA.js +0 -1
- package/dist/assets/insertionBoundaries-DMxuUnL_.js +0 -4
- package/dist/assets/main-B9HVtgXE.js +0 -2
- package/dist/assets/main-ZNyIs3Sn.js +0 -29
- package/dist/assets/markdown-worker-y3ewaqAK.js +0 -4
- package/dist/assets/markdownTheme-TdhQOZSN.js +0 -2
- package/dist/assets/miniChat-q0T0WGkZ.js +0 -2
- package/dist/assets/mobile-DEduvLJj.js +0 -2
- package/dist/assets/multirun-DU-wrxlG.js +0 -4
- package/dist/assets/persistence-CmjKImz2.js +0 -3
- package/dist/assets/platform-skqcMARt.js +0 -2
- package/dist/assets/projectMeta-DNWx6Uva.js +0 -3
- package/dist/assets/radio-BEonIX1k.js +0 -1
- package/dist/assets/renderElectronMiniChatApp--JYWY41L.js +0 -2
- package/dist/assets/renderMobileApp-B0Ix_uNo.js +0 -25
- package/dist/assets/runtime-switch-BkpTTbEi.js +0 -1
- package/dist/assets/runtimeConfig-BTDIG7mX.js +0 -2
- package/dist/assets/runtimeEndpointReset-CZQCYtVI.js +0 -4
- package/dist/assets/shikiHighlight-C9Cx56Qg.js +0 -1
- package/dist/assets/sortable-tabs-strip-Bj8N0VWf.js +0 -1
- package/dist/assets/src-2eFAiBLq.css +0 -2
- package/dist/assets/terminalApi-CNqqwjfG.js +0 -1
- package/dist/assets/url-KeihbE0d.js +0 -1
- package/dist/assets/useAppFontEffects-CKLSamae.js +0 -7
- package/dist/assets/useAssistantUIStore-DaplPyb0.js +0 -1
- package/dist/assets/useDesktopWindowControlsLayout-DJSkFfhT.js +0 -1
- package/dist/assets/useEffectiveDirectory-B3rbY1Kv.js +0 -1
- package/dist/assets/useFontPreferences-D8emhcNv.js +0 -1
- package/dist/assets/useMobileNavigationStore-CAvVUItx.js +0 -412
- package/dist/assets/useSessionAutoCleanup-DxNgqJ8s.js +0 -1
- package/dist/assets/useUIStore-B7KJS5G7.js +0 -1
- package/dist/assets/useWorkerHighlightedLines-DiDF68LR.js +0 -7
- package/dist/assets/utils-CTL16t2f.js +0 -1
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { detectSessionlessGenerate, generateOpenCodeText, _test } from './generate.js'
|
|
3
|
+
|
|
4
|
+
const completedAssistant = (text) => ({
|
|
5
|
+
info: {
|
|
6
|
+
role: 'assistant',
|
|
7
|
+
time: { completed: Date.now() },
|
|
8
|
+
},
|
|
9
|
+
parts: [{ type: 'text', text }],
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
describe('detectSessionlessGenerate', () => {
|
|
13
|
+
it('returns unavailable when the probe 404s', async () => {
|
|
14
|
+
const fetchImpl = vi.fn(async () => new Response('missing', { status: 404 }))
|
|
15
|
+
await expect(detectSessionlessGenerate({
|
|
16
|
+
fetchImpl,
|
|
17
|
+
baseUrl: 'http://127.0.0.1:4096',
|
|
18
|
+
headers: {},
|
|
19
|
+
})).resolves.toEqual({ available: false, mode: 'throwaway-session' })
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('returns available when the probe returns JSON', async () => {
|
|
23
|
+
const fetchImpl = vi.fn(async () => new Response(JSON.stringify({ ok: true }), {
|
|
24
|
+
status: 200,
|
|
25
|
+
headers: { 'Content-Type': 'application/json' },
|
|
26
|
+
}))
|
|
27
|
+
await expect(detectSessionlessGenerate({
|
|
28
|
+
fetchImpl,
|
|
29
|
+
baseUrl: 'http://127.0.0.1:4096',
|
|
30
|
+
headers: {},
|
|
31
|
+
})).resolves.toMatchObject({ available: true, mode: 'http' })
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('treats HTML 200 on /generate as unavailable', async () => {
|
|
35
|
+
const fetchImpl = vi.fn(async (url) => {
|
|
36
|
+
expect(String(url)).toMatch(/\/generate$/)
|
|
37
|
+
return new Response('<!doctype html><html><body>OpenChamber</body></html>', {
|
|
38
|
+
status: 200,
|
|
39
|
+
headers: { 'Content-Type': 'text/html; charset=utf-8' },
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
await expect(detectSessionlessGenerate({
|
|
43
|
+
fetchImpl,
|
|
44
|
+
baseUrl: 'http://127.0.0.1:4096',
|
|
45
|
+
headers: {},
|
|
46
|
+
})).resolves.toEqual({ available: false, mode: 'throwaway-session' })
|
|
47
|
+
expect(fetchImpl).toHaveBeenCalled()
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
describe('generateOpenCodeText', () => {
|
|
52
|
+
it('uses promptAsync with model+parts, waits for idle messages, and never calls v2 session.prompt', async () => {
|
|
53
|
+
const create = vi.fn(async () => ({ data: { id: 'ses_tmp' } }))
|
|
54
|
+
const update = vi.fn(async () => ({ data: { id: 'ses_tmp' } }))
|
|
55
|
+
const ids = vi.fn(async () => ({ data: ['bash', 'edit'] }))
|
|
56
|
+
const prompt = vi.fn(async () => {
|
|
57
|
+
throw new Error('v2 session.prompt must not be used')
|
|
58
|
+
})
|
|
59
|
+
const promptAsync = vi.fn(async () => ({ response: { status: 204 } }))
|
|
60
|
+
const status = vi.fn(async () => ({ data: { ses_tmp: { type: 'idle' } } }))
|
|
61
|
+
const messages = vi.fn(async () => ({ data: [completedAssistant('reply')] }))
|
|
62
|
+
const remove = vi.fn(async () => ({ data: true }))
|
|
63
|
+
const createOpencodeClient = vi.fn(() => ({
|
|
64
|
+
session: { create, update, prompt, promptAsync, status, messages, delete: remove },
|
|
65
|
+
tool: { ids },
|
|
66
|
+
}))
|
|
67
|
+
|
|
68
|
+
const result = await generateOpenCodeText({
|
|
69
|
+
buildOpenCodeUrl: () => 'http://127.0.0.1:4096',
|
|
70
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
71
|
+
providerID: 'opencode',
|
|
72
|
+
modelID: 'gpt-5-nano',
|
|
73
|
+
messages: [{ role: 'user', content: 'hi' }],
|
|
74
|
+
clientFactory: createOpencodeClient,
|
|
75
|
+
ensureTempDirectory: async () => '/tmp/openchamber-llm',
|
|
76
|
+
detect: async () => ({ available: false, mode: 'throwaway-session' }),
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
expect(create).toHaveBeenCalledWith(expect.objectContaining({
|
|
80
|
+
title: expect.stringContaining('[openchamber-llm]'),
|
|
81
|
+
}), expect.anything())
|
|
82
|
+
expect(update).toHaveBeenCalled()
|
|
83
|
+
expect(promptAsync).toHaveBeenCalledWith(expect.objectContaining({
|
|
84
|
+
sessionID: 'ses_tmp',
|
|
85
|
+
agent: 'openchamber-llm',
|
|
86
|
+
model: { providerID: 'opencode', modelID: 'gpt-5-nano' },
|
|
87
|
+
tools: { bash: false, edit: false },
|
|
88
|
+
parts: [{ type: 'text', text: 'User: hi', synthetic: false }],
|
|
89
|
+
}), expect.anything())
|
|
90
|
+
expect(prompt).not.toHaveBeenCalled()
|
|
91
|
+
expect(status).toHaveBeenCalled()
|
|
92
|
+
expect(messages).toHaveBeenCalledWith(expect.objectContaining({ sessionID: 'ses_tmp' }), expect.anything())
|
|
93
|
+
expect(remove).toHaveBeenCalled()
|
|
94
|
+
expect(result).toEqual({ text: 'reply', source: 'throwaway-session' })
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('forwards contact file parts on promptAsync so the model can see images', async () => {
|
|
98
|
+
const image = { type: 'file', mime: 'image/png', url: 'data:image/png;base64,aa', filename: 'shot.png' }
|
|
99
|
+
const file = { type: 'file', mime: 'text/plain', url: 'data:text/plain;base64,eA==', filename: 'notes.txt' }
|
|
100
|
+
const flattened = _test.flattenMessages([
|
|
101
|
+
{ role: 'user', content: 'look', parts: [image, file] },
|
|
102
|
+
])
|
|
103
|
+
expect(flattened.prompt).toContain('User: look')
|
|
104
|
+
expect(flattened.prompt).toContain('[image: shot.png (image/png)]')
|
|
105
|
+
expect(flattened.prompt).toContain('[file: notes.txt (text/plain)]')
|
|
106
|
+
expect(flattened.files).toEqual([image, file])
|
|
107
|
+
|
|
108
|
+
const promptAsync = vi.fn(async () => ({ response: { status: 204 } }))
|
|
109
|
+
const createOpencodeClient = vi.fn(() => ({
|
|
110
|
+
session: {
|
|
111
|
+
create: async () => ({ data: { id: 'ses_tmp' } }),
|
|
112
|
+
update: async () => ({ data: { id: 'ses_tmp' } }),
|
|
113
|
+
prompt: vi.fn(),
|
|
114
|
+
promptAsync,
|
|
115
|
+
status: async () => ({ data: { ses_tmp: { type: 'idle' } } }),
|
|
116
|
+
messages: async () => ({ data: [completedAssistant('saw it')] }),
|
|
117
|
+
delete: async () => ({ data: true }),
|
|
118
|
+
},
|
|
119
|
+
tool: { ids: async () => ({ data: [] }) },
|
|
120
|
+
}))
|
|
121
|
+
await generateOpenCodeText({
|
|
122
|
+
buildOpenCodeUrl: () => 'http://127.0.0.1:4096',
|
|
123
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
124
|
+
providerID: 'opencode',
|
|
125
|
+
modelID: 'gpt-5-nano',
|
|
126
|
+
messages: [{ role: 'user', content: 'look', parts: [image, file] }],
|
|
127
|
+
clientFactory: createOpencodeClient,
|
|
128
|
+
ensureTempDirectory: async () => '/tmp/openchamber-llm',
|
|
129
|
+
detect: async () => ({ available: false, mode: 'throwaway-session' }),
|
|
130
|
+
forwardImageParts: true,
|
|
131
|
+
})
|
|
132
|
+
expect(promptAsync.mock.calls[0][0].parts).toEqual([
|
|
133
|
+
expect.objectContaining({ type: 'text', synthetic: false }),
|
|
134
|
+
image,
|
|
135
|
+
file,
|
|
136
|
+
])
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('skips image bytes for non-vision generate and keeps text files plus the image description', async () => {
|
|
140
|
+
const image = { type: 'file', mime: 'image/png', url: 'data:image/png;base64,aa', filename: 'shot.png' }
|
|
141
|
+
const file = { type: 'file', mime: 'text/plain', url: 'data:text/plain;base64,eA==', filename: 'notes.txt' }
|
|
142
|
+
expect(_test.filesForPrompt([image, file], false)).toEqual([file])
|
|
143
|
+
const promptAsync = vi.fn(async () => ({ response: { status: 204 } }))
|
|
144
|
+
const createOpencodeClient = vi.fn(() => ({
|
|
145
|
+
session: {
|
|
146
|
+
create: async () => ({ data: { id: 'ses_tmp' } }),
|
|
147
|
+
update: async () => ({ data: { id: 'ses_tmp' } }),
|
|
148
|
+
prompt: vi.fn(),
|
|
149
|
+
promptAsync,
|
|
150
|
+
status: async () => ({ data: { ses_tmp: { type: 'idle' } } }),
|
|
151
|
+
messages: async () => ({ data: [completedAssistant('cannot see images')] }),
|
|
152
|
+
delete: async () => ({ data: true }),
|
|
153
|
+
},
|
|
154
|
+
tool: { ids: async () => ({ data: [] }) },
|
|
155
|
+
}))
|
|
156
|
+
await generateOpenCodeText({
|
|
157
|
+
buildOpenCodeUrl: () => 'http://127.0.0.1:4096',
|
|
158
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
159
|
+
providerID: 'opencode',
|
|
160
|
+
modelID: 'deepseek-v4-flash',
|
|
161
|
+
messages: [{ role: 'user', content: 'look', parts: [image, file] }],
|
|
162
|
+
clientFactory: createOpencodeClient,
|
|
163
|
+
ensureTempDirectory: async () => '/tmp/openchamber-llm',
|
|
164
|
+
detect: async () => ({ available: false, mode: 'throwaway-session' }),
|
|
165
|
+
})
|
|
166
|
+
expect(promptAsync.mock.calls[0][0].parts).toEqual([
|
|
167
|
+
expect.objectContaining({
|
|
168
|
+
type: 'text',
|
|
169
|
+
text: expect.stringContaining('[image: shot.png (image/png)]'),
|
|
170
|
+
}),
|
|
171
|
+
file,
|
|
172
|
+
])
|
|
173
|
+
expect(promptAsync.mock.calls[0][0].parts.some((part) => part.type === 'file' && part.mime.startsWith('image/'))).toBe(false)
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it('surfaces the OpenCode assistant error string after promptAsync 204', async () => {
|
|
177
|
+
const promptAsync = vi.fn(async () => ({ response: { status: 204 } }))
|
|
178
|
+
const prompt = vi.fn()
|
|
179
|
+
const createOpencodeClient = vi.fn(() => ({
|
|
180
|
+
session: {
|
|
181
|
+
create: async () => ({ data: { id: 'ses_tmp' } }),
|
|
182
|
+
update: async () => ({ data: { id: 'ses_tmp' } }),
|
|
183
|
+
prompt,
|
|
184
|
+
promptAsync,
|
|
185
|
+
status: async () => ({ data: { ses_tmp: { type: 'idle' } } }),
|
|
186
|
+
messages: async () => ({
|
|
187
|
+
data: [{
|
|
188
|
+
info: { role: 'assistant', error: { message: 'model refused the request' }, time: { completed: Date.now() } },
|
|
189
|
+
parts: [],
|
|
190
|
+
}],
|
|
191
|
+
}),
|
|
192
|
+
delete: async () => ({ data: true }),
|
|
193
|
+
},
|
|
194
|
+
tool: { ids: async () => ({ data: [] }) },
|
|
195
|
+
}))
|
|
196
|
+
|
|
197
|
+
await expect(generateOpenCodeText({
|
|
198
|
+
buildOpenCodeUrl: () => 'http://127.0.0.1:4096',
|
|
199
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
200
|
+
providerID: 'opencode',
|
|
201
|
+
modelID: 'gpt-5-nano',
|
|
202
|
+
messages: [{ role: 'user', content: 'hi' }],
|
|
203
|
+
clientFactory: createOpencodeClient,
|
|
204
|
+
ensureTempDirectory: async () => '/tmp/openchamber-llm',
|
|
205
|
+
detect: async () => ({ available: false, mode: 'throwaway-session' }),
|
|
206
|
+
})).rejects.toMatchObject({
|
|
207
|
+
code: 'upstream_error',
|
|
208
|
+
message: 'model refused the request',
|
|
209
|
+
})
|
|
210
|
+
expect(prompt).not.toHaveBeenCalled()
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
it('falls through to promptAsync when the /generate probe returns HTML 200', async () => {
|
|
214
|
+
const fetchImpl = vi.fn(async () => new Response('<!doctype html>', {
|
|
215
|
+
status: 200,
|
|
216
|
+
headers: { 'Content-Type': 'text/html' },
|
|
217
|
+
}))
|
|
218
|
+
const promptAsync = vi.fn(async () => ({ response: { status: 204 } }))
|
|
219
|
+
const prompt = vi.fn()
|
|
220
|
+
const result = await generateOpenCodeText({
|
|
221
|
+
buildOpenCodeUrl: () => 'http://127.0.0.1:4096',
|
|
222
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
223
|
+
providerID: 'opencode',
|
|
224
|
+
modelID: 'glm-5.3-flash',
|
|
225
|
+
messages: [{ role: 'user', content: 'hi' }],
|
|
226
|
+
fetchImpl,
|
|
227
|
+
clientFactory: () => ({
|
|
228
|
+
session: {
|
|
229
|
+
create: async () => ({ data: { id: 'ses_tmp' } }),
|
|
230
|
+
update: async () => ({ data: { id: 'ses_tmp' } }),
|
|
231
|
+
prompt,
|
|
232
|
+
promptAsync,
|
|
233
|
+
status: async () => ({ data: { ses_tmp: { type: 'idle' } } }),
|
|
234
|
+
messages: async () => ({ data: [completedAssistant('reply')] }),
|
|
235
|
+
delete: async () => ({ data: true }),
|
|
236
|
+
},
|
|
237
|
+
tool: { ids: async () => ({ data: [] }) },
|
|
238
|
+
}),
|
|
239
|
+
ensureTempDirectory: async () => '/tmp/openchamber-llm',
|
|
240
|
+
})
|
|
241
|
+
expect(result).toEqual({ text: 'reply', source: 'throwaway-session' })
|
|
242
|
+
expect(promptAsync).toHaveBeenCalled()
|
|
243
|
+
expect(prompt).not.toHaveBeenCalled()
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
it('forwards filtered throwaway session text deltas via onTextDelta and still returns full text', async () => {
|
|
247
|
+
const subscribers = new Set()
|
|
248
|
+
const globalEventHub = {
|
|
249
|
+
subscribeEvent(fn) {
|
|
250
|
+
subscribers.add(fn)
|
|
251
|
+
return () => { subscribers.delete(fn) }
|
|
252
|
+
},
|
|
253
|
+
emit(event) {
|
|
254
|
+
for (const fn of Array.from(subscribers)) fn(event)
|
|
255
|
+
},
|
|
256
|
+
}
|
|
257
|
+
const deltas = []
|
|
258
|
+
const onTextDelta = vi.fn((text) => { deltas.push(text) })
|
|
259
|
+
|
|
260
|
+
const promptAsync = vi.fn(async () => {
|
|
261
|
+
// Same-session text deltas
|
|
262
|
+
globalEventHub.emit({
|
|
263
|
+
payload: {
|
|
264
|
+
type: 'message.part.delta',
|
|
265
|
+
properties: {
|
|
266
|
+
sessionID: 'ses_tmp',
|
|
267
|
+
messageID: 'msg_asst',
|
|
268
|
+
partID: 'prt_1',
|
|
269
|
+
field: 'text',
|
|
270
|
+
delta: 'Hel',
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
})
|
|
274
|
+
globalEventHub.emit({
|
|
275
|
+
payload: {
|
|
276
|
+
type: 'message.part.delta',
|
|
277
|
+
properties: {
|
|
278
|
+
sessionID: 'ses_tmp',
|
|
279
|
+
messageID: 'msg_asst',
|
|
280
|
+
partID: 'prt_1',
|
|
281
|
+
field: 'text',
|
|
282
|
+
delta: 'lo',
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
})
|
|
286
|
+
// Other session — must be ignored
|
|
287
|
+
globalEventHub.emit({
|
|
288
|
+
payload: {
|
|
289
|
+
type: 'message.part.delta',
|
|
290
|
+
properties: {
|
|
291
|
+
sessionID: 'ses_other',
|
|
292
|
+
messageID: 'msg_other',
|
|
293
|
+
partID: 'prt_x',
|
|
294
|
+
field: 'text',
|
|
295
|
+
delta: 'NOPE',
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
})
|
|
299
|
+
// Same session, different messageID after lock — ignored
|
|
300
|
+
globalEventHub.emit({
|
|
301
|
+
payload: {
|
|
302
|
+
type: 'message.part.delta',
|
|
303
|
+
properties: {
|
|
304
|
+
sessionID: 'ses_tmp',
|
|
305
|
+
messageID: 'msg_other_asst',
|
|
306
|
+
partID: 'prt_2',
|
|
307
|
+
field: 'text',
|
|
308
|
+
delta: 'SKIP',
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
})
|
|
312
|
+
// Non-text field — ignored
|
|
313
|
+
globalEventHub.emit({
|
|
314
|
+
payload: {
|
|
315
|
+
type: 'message.part.delta',
|
|
316
|
+
properties: {
|
|
317
|
+
sessionID: 'ses_tmp',
|
|
318
|
+
messageID: 'msg_asst',
|
|
319
|
+
partID: 'prt_1',
|
|
320
|
+
field: 'reasoning',
|
|
321
|
+
delta: 'think',
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
})
|
|
325
|
+
return { response: { status: 204 } }
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
const result = await generateOpenCodeText({
|
|
329
|
+
buildOpenCodeUrl: () => 'http://127.0.0.1:4096',
|
|
330
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
331
|
+
providerID: 'opencode',
|
|
332
|
+
modelID: 'gpt-5-nano',
|
|
333
|
+
messages: [{ role: 'user', content: 'hi' }],
|
|
334
|
+
clientFactory: () => ({
|
|
335
|
+
session: {
|
|
336
|
+
create: async () => ({ data: { id: 'ses_tmp' } }),
|
|
337
|
+
update: async () => ({ data: { id: 'ses_tmp' } }),
|
|
338
|
+
prompt: vi.fn(),
|
|
339
|
+
promptAsync,
|
|
340
|
+
status: async () => ({ data: { ses_tmp: { type: 'idle' } } }),
|
|
341
|
+
messages: async () => ({ data: [completedAssistant('Hello')] }),
|
|
342
|
+
delete: async () => ({ data: true }),
|
|
343
|
+
},
|
|
344
|
+
tool: { ids: async () => ({ data: [] }) },
|
|
345
|
+
}),
|
|
346
|
+
ensureTempDirectory: async () => '/tmp/openchamber-llm',
|
|
347
|
+
detect: async () => ({ available: false, mode: 'throwaway-session' }),
|
|
348
|
+
onTextDelta,
|
|
349
|
+
globalEventHub,
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
expect(result).toEqual({ text: 'Hello', source: 'throwaway-session' })
|
|
353
|
+
expect(deltas).toEqual(['Hel', 'lo'])
|
|
354
|
+
expect(onTextDelta).toHaveBeenCalledTimes(2)
|
|
355
|
+
// Listener removed after complete — further emits must not reach onTextDelta
|
|
356
|
+
expect(subscribers.size).toBe(0)
|
|
357
|
+
globalEventHub.emit({
|
|
358
|
+
payload: {
|
|
359
|
+
type: 'message.part.delta',
|
|
360
|
+
properties: {
|
|
361
|
+
sessionID: 'ses_tmp',
|
|
362
|
+
messageID: 'msg_asst',
|
|
363
|
+
partID: 'prt_1',
|
|
364
|
+
field: 'text',
|
|
365
|
+
delta: 'late',
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
})
|
|
369
|
+
expect(onTextDelta).toHaveBeenCalledTimes(2)
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
it('removes the hub listener when generate fails after subscribe', async () => {
|
|
373
|
+
const subscribers = new Set()
|
|
374
|
+
const globalEventHub = {
|
|
375
|
+
subscribeEvent(fn) {
|
|
376
|
+
subscribers.add(fn)
|
|
377
|
+
return () => { subscribers.delete(fn) }
|
|
378
|
+
},
|
|
379
|
+
}
|
|
380
|
+
const onTextDelta = vi.fn()
|
|
381
|
+
|
|
382
|
+
await expect(generateOpenCodeText({
|
|
383
|
+
buildOpenCodeUrl: () => 'http://127.0.0.1:4096',
|
|
384
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
385
|
+
providerID: 'opencode',
|
|
386
|
+
modelID: 'gpt-5-nano',
|
|
387
|
+
messages: [{ role: 'user', content: 'hi' }],
|
|
388
|
+
clientFactory: () => ({
|
|
389
|
+
session: {
|
|
390
|
+
create: async () => ({ data: { id: 'ses_tmp' } }),
|
|
391
|
+
update: async () => ({ data: { id: 'ses_tmp' } }),
|
|
392
|
+
prompt: vi.fn(),
|
|
393
|
+
promptAsync: async () => ({ response: { status: 204 } }),
|
|
394
|
+
status: async () => ({ data: { ses_tmp: { type: 'idle' } } }),
|
|
395
|
+
messages: async () => ({
|
|
396
|
+
data: [{
|
|
397
|
+
info: { role: 'assistant', error: { message: 'boom' }, time: { completed: Date.now() } },
|
|
398
|
+
parts: [],
|
|
399
|
+
}],
|
|
400
|
+
}),
|
|
401
|
+
delete: async () => ({ data: true }),
|
|
402
|
+
},
|
|
403
|
+
tool: { ids: async () => ({ data: [] }) },
|
|
404
|
+
}),
|
|
405
|
+
ensureTempDirectory: async () => '/tmp/openchamber-llm',
|
|
406
|
+
detect: async () => ({ available: false, mode: 'throwaway-session' }),
|
|
407
|
+
onTextDelta,
|
|
408
|
+
globalEventHub,
|
|
409
|
+
})).rejects.toMatchObject({ code: 'upstream_error', message: 'boom' })
|
|
410
|
+
|
|
411
|
+
expect(subscribers.size).toBe(0)
|
|
412
|
+
})
|
|
413
|
+
|
|
414
|
+
it('does not invent deltas on the sessionless /generate JSON path', async () => {
|
|
415
|
+
const onTextDelta = vi.fn()
|
|
416
|
+
const subscribers = new Set()
|
|
417
|
+
const globalEventHub = {
|
|
418
|
+
subscribeEvent(fn) {
|
|
419
|
+
subscribers.add(fn)
|
|
420
|
+
return () => { subscribers.delete(fn) }
|
|
421
|
+
},
|
|
422
|
+
}
|
|
423
|
+
const fetchImpl = vi.fn(async () => new Response(JSON.stringify({ text: 'full reply' }), {
|
|
424
|
+
status: 200,
|
|
425
|
+
headers: { 'Content-Type': 'application/json' },
|
|
426
|
+
}))
|
|
427
|
+
|
|
428
|
+
const result = await generateOpenCodeText({
|
|
429
|
+
buildOpenCodeUrl: () => 'http://127.0.0.1:4096',
|
|
430
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
431
|
+
providerID: 'opencode',
|
|
432
|
+
modelID: 'gpt-5-nano',
|
|
433
|
+
messages: [{ role: 'user', content: 'hi' }],
|
|
434
|
+
fetchImpl,
|
|
435
|
+
detect: async () => ({ available: true, mode: 'http', url: 'http://127.0.0.1:4096/generate' }),
|
|
436
|
+
onTextDelta,
|
|
437
|
+
globalEventHub,
|
|
438
|
+
})
|
|
439
|
+
|
|
440
|
+
expect(result).toEqual({ text: 'full reply', source: 'generate' })
|
|
441
|
+
expect(onTextDelta).not.toHaveBeenCalled()
|
|
442
|
+
expect(subscribers.size).toBe(0)
|
|
443
|
+
})
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
describe('subscribeThrowawayTextDeltas', () => {
|
|
447
|
+
it('returns null without a callback or hub', () => {
|
|
448
|
+
expect(_test.subscribeThrowawayTextDeltas({
|
|
449
|
+
sessionID: 'ses_1',
|
|
450
|
+
onTextDelta: null,
|
|
451
|
+
globalEventHub: { subscribeEvent: () => () => {} },
|
|
452
|
+
})).toBeNull()
|
|
453
|
+
expect(_test.subscribeThrowawayTextDeltas({
|
|
454
|
+
sessionID: 'ses_1',
|
|
455
|
+
onTextDelta: () => {},
|
|
456
|
+
globalEventHub: null,
|
|
457
|
+
})).toBeNull()
|
|
458
|
+
})
|
|
459
|
+
})
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createChatCompletion, LlmError } from './completions.js';
|
|
2
|
+
import { loadConnectedCatalog } from './catalog.js';
|
|
3
|
+
import { createOpencodeClient } from '@opencode-ai/sdk/v2';
|
|
4
|
+
import { ensureLlmTempDirectory } from './temp-directory.js';
|
|
5
|
+
|
|
6
|
+
const fail = (res, error) => {
|
|
7
|
+
const code = error instanceof LlmError ? error.code : error?.code || 'internal_error';
|
|
8
|
+
const status = error instanceof LlmError
|
|
9
|
+
? error.statusCode
|
|
10
|
+
: code === 'no_provider'
|
|
11
|
+
? 400
|
|
12
|
+
: code === 'validation_error'
|
|
13
|
+
? 400
|
|
14
|
+
: code === 'upstream_error'
|
|
15
|
+
? 502
|
|
16
|
+
: 500;
|
|
17
|
+
res.status(status).json({ ok: false, error: code, message: error?.message || code });
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const registerLlmRoutes = (app, dependencies) => {
|
|
21
|
+
const client = () => createOpencodeClient({
|
|
22
|
+
baseUrl: dependencies.buildOpenCodeUrl('/', '').replace(/\/$/, ''),
|
|
23
|
+
headers: dependencies.getOpenCodeAuthHeaders(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
app.get('/api/openchamber/llm/models', (_req, res) => {
|
|
27
|
+
Promise.resolve()
|
|
28
|
+
.then(() => loadConnectedCatalog(client()))
|
|
29
|
+
.then((catalog) => res.json({ ok: true, ...catalog }))
|
|
30
|
+
.catch((error) => fail(res, error));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
app.post('/api/openchamber/llm/chat/completions', (req, res) => {
|
|
34
|
+
Promise.resolve()
|
|
35
|
+
.then(() => createChatCompletion({
|
|
36
|
+
body: req.body,
|
|
37
|
+
buildOpenCodeUrl: dependencies.buildOpenCodeUrl,
|
|
38
|
+
getOpenCodeAuthHeaders: dependencies.getOpenCodeAuthHeaders,
|
|
39
|
+
clientFactory: client,
|
|
40
|
+
ensureTempDirectory: ensureLlmTempDirectory,
|
|
41
|
+
}))
|
|
42
|
+
.then(({ completion }) => {
|
|
43
|
+
res.status(200).json(completion);
|
|
44
|
+
})
|
|
45
|
+
.catch((error) => fail(res, error));
|
|
46
|
+
});
|
|
47
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
/** @type {string | null} */
|
|
6
|
+
let tempDirectory = null;
|
|
7
|
+
/** @type {Promise<string> | null} */
|
|
8
|
+
let inflight = null;
|
|
9
|
+
|
|
10
|
+
export async function ensureLlmTempDirectory({ agentName, agentMarkdown }) {
|
|
11
|
+
if (tempDirectory) return tempDirectory;
|
|
12
|
+
if (!inflight) {
|
|
13
|
+
inflight = (async () => {
|
|
14
|
+
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'openchamber-llm-'));
|
|
15
|
+
const agentDir = path.join(root, '.opencode', 'agent');
|
|
16
|
+
await fs.mkdir(agentDir, { recursive: true });
|
|
17
|
+
await fs.writeFile(path.join(agentDir, `${agentName}.md`), agentMarkdown, 'utf8');
|
|
18
|
+
tempDirectory = root;
|
|
19
|
+
return root;
|
|
20
|
+
})().finally(() => {
|
|
21
|
+
inflight = null;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return inflight;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function stopLlmTempDirectory() {
|
|
28
|
+
const dir = tempDirectory;
|
|
29
|
+
tempDirectory = null;
|
|
30
|
+
inflight = null;
|
|
31
|
+
if (!dir) return;
|
|
32
|
+
try {
|
|
33
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
34
|
+
} catch {
|
|
35
|
+
// Best-effort cleanup of the throwaway generator workspace.
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -16,18 +16,22 @@ registered them — so a leaked device token alone can't be used to push.
|
|
|
16
16
|
3. On a trigger (ready/error/question/permission/goal_*), the server composes **generic,
|
|
17
17
|
content-free** text — a **locale-specific** scenario title (from `apns-titles.js`, keyed off
|
|
18
18
|
the locale stored with each device token at `POST /api/push/apns-token`) + the **session name**
|
|
19
|
-
as the body, no model/project/message content — plus a **`badge`** count (see below).
|
|
20
|
-
are
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
as the body, no model/project/message content — plus a **`badge`** count (see below).
|
|
20
|
+
**Contact turns are the exception:** APNs keeps the assistant nickname as the title and the
|
|
21
|
+
spoken message as the body (`preserveAlert`), and forwards `assistantID` so a tap opens that
|
|
22
|
+
conversation. Tokens are grouped by locale (relay signatures cover `title`, so mixed locales
|
|
23
|
+
cannot share one batch) and each group POSTs `{ tokens, title, body, badge, env,
|
|
24
|
+
data:{sessionId|assistantID}, publicKeyJwk, ts, sig }` to `POST /v1/push/send`
|
|
25
|
+
(`apns-runtime.js` → `sendViaRelay`). It does **not** gate on UI visibility (see below).
|
|
26
|
+
Legacy tokens without a locale fall back to English.
|
|
24
27
|
4. The **Push Relay** (`packages/relay-server/src/push/`, process `openchamber-push-relay`)
|
|
25
28
|
verifies the signature + `ts` freshness, derives `serverId`, and only delivers to tokens bound
|
|
26
29
|
to that server. It holds the project APNs `.p8` key, signs an ES256 JWT with Node crypto, and
|
|
27
30
|
sends each token to APNs over HTTP/2, returning per-token results; the server drops tokens
|
|
28
31
|
flagged `drop` (410 / BadDeviceToken). The Push database stores `token → serverId` bindings,
|
|
29
32
|
not application plaintext. Layer 1 (`openchamber-relay`) never sees these secrets.
|
|
30
|
-
5. Tapping a push deep-links
|
|
33
|
+
5. Tapping a session push deep-links via the forwarded `sessionId`. Tapping a contact push
|
|
34
|
+
opens that assistant via `assistantID` / `openchamber://assistant/<id>`.
|
|
31
35
|
|
|
32
36
|
## Live Activity (update / end)
|
|
33
37
|
|
|
@@ -116,8 +120,8 @@ is server-global, so every device token of a server sees the same badge.
|
|
|
116
120
|
|
|
117
121
|
Host (`apns-runtime.js`):
|
|
118
122
|
- `OPENCHAMBER_PUSH_RELAY_URL` (explicit send-URL override), `OPENCHAMBER_APNS_ENVIRONMENT`
|
|
119
|
-
(`
|
|
120
|
-
auto-generated — nothing to set.
|
|
123
|
+
(`production` default for TestFlight/App Store builds; set `sandbox` for Xcode development
|
|
124
|
+
builds). The signing keypair is auto-generated — nothing to set.
|
|
121
125
|
- Direct fallback: `OPENCHAMBER_APNS_KEY_ID`, `OPENCHAMBER_APNS_TEAM_ID`, `OPENCHAMBER_APNS_P8`
|
|
122
126
|
(or `_P8_PATH`), `OPENCHAMBER_APNS_BUNDLE_ID`, `OPENCHAMBER_PUSH_RELAY_DISABLED=true`.
|
|
123
127
|
|
|
@@ -136,8 +140,8 @@ device tokens, or signatures.
|
|
|
136
140
|
2. Give those values only to the Push process (environment or Docker secret). Do not put the
|
|
137
141
|
`.p8` on Layer 1 or on each OpenChamber Host when using Relay mode.
|
|
138
142
|
3. Xcode: confirm the Push Notifications capability; Clean Build Folder; run on device.
|
|
139
|
-
|
|
140
|
-
`OPENCHAMBER_APNS_ENVIRONMENT=
|
|
143
|
+
Hosts default to APNs `production` (TestFlight/App Store tokens). Xcode development
|
|
144
|
+
builds (sandbox tokens) need `OPENCHAMBER_APNS_ENVIRONMENT=sandbox`.
|
|
141
145
|
|
|
142
146
|
## Security posture
|
|
143
147
|
|
|
@@ -167,13 +171,15 @@ Who can read the alert text:
|
|
|
167
171
|
- **Apple APNs:** the alert text too — APNs always reads the alert payload of an `alert` push.
|
|
168
172
|
- **The device:** displays it.
|
|
169
173
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
Ordinary session triggers stay **content-free**: a fixed scenario title (localized per device) +
|
|
175
|
+
the session name only — no model, project, or message content (`runtime.js` →
|
|
176
|
+
`toApnsGenericPayload` → `localizeApnsPayload`). The session name is the single semi-personal
|
|
177
|
+
field that crosses the relay/Apple on that path.
|
|
178
|
+
|
|
179
|
+
Contact-turn alerts are an intentional exception: nickname + spoken message cross the relay so
|
|
180
|
+
the banner reads like a normal contact. To hide even that from Apple would require an end-to-end
|
|
181
|
+
**encrypted payload** (`mutable-content` + a Notification Service Extension that decrypts
|
|
182
|
+
on-device with a key never sent to the relay) — not implemented.
|
|
177
183
|
|
|
178
184
|
## Android (FCM) note
|
|
179
185
|
|
|
@@ -47,9 +47,10 @@ This module provides notification message preparation utilities for the web serv
|
|
|
47
47
|
- Returned API:
|
|
48
48
|
- `maybeSendPushForTrigger(payload)`
|
|
49
49
|
- Owns:
|
|
50
|
-
- top-level completion/question/permission trigger routing; completion is the sole task-status notification
|
|
51
|
-
-
|
|
52
|
-
-
|
|
50
|
+
- top-level completion/question/permission trigger routing; completion is the sole task-status notification. Ordinary push is limited to sidebar-visible root sessions. Child/subagent sessions, Assistant bindings (`openchamber.assistant.assistantID` unless `assigned.from === 'contact'`), scheduled-task sessions, small-model system sessions (`metadata.openchamber.smallModel.purpose`), and `smartfetch-secondary` titles are suppressed. Contact-assigned workers stay visible and still notify.
|
|
51
|
+
- contact-turn notifications (`sendContactTurnNotification`) are a separate SMS-style path: title is the assistant nickname, body is the spoken message text, on desktop / UI SSE / web-push / APNs. APNs does **not** rewrite these into the generic "Task completed" scenario title.
|
|
52
|
+
- top-level completion/error Live Activity `end` (`sendLiveActivityEnd`), independent of ordinary push settings and UI visibility, with the same hidden-session suppression; duplicate terminal events are idempotent at the token store
|
|
53
|
+
- session meta cache for sidebar-visibility suppression
|
|
53
54
|
- template resolution and fallback behavior
|
|
54
55
|
- native notification fanout and web push payload fanout
|
|
55
56
|
- push always fans out to every subscribed surface; another client's visibility never suppresses delivery
|
|
@@ -79,7 +80,7 @@ This module provides notification message preparation utilities for the web serv
|
|
|
79
80
|
- `sendApnsToAllUiSessions(payload)` — localizes scenario titles per stored token locale (`apns-titles.js`), groups tokens by locale, then signs + sends (no UI-visibility gate; iOS suppresses the foreground banner). Before a relay send, each token is checked against the in-memory registration success cache for the current register URL; cache hits skip `/v1/push/register-token`, misses are registered with bounded concurrency, and only successfully bound tokens are sent. Switching Relay/Push URL clears that cache so the next send re-binds persisted tokens to the new origin. No-ops with a single warning when APNs is unconfigured. Drops tokens on `410` / `BadDeviceToken` / `Unregistered`. Never sends Live Activity tokens.
|
|
80
81
|
- `reRegisterAllTokens()` — binds every persisted device token to the current Push origin (same success cache and URL-switch invalidation as send).
|
|
81
82
|
- `resolveApnsConfig()`
|
|
82
|
-
- Configuration (env first, then `settings.apnsConfig`): `OPENCHAMBER_PUSH_RELAY_URL` (optional send-URL override), `OPENCHAMBER_PUSH_RELAY_DISABLED`, `OPENCHAMBER_APNS_KEY_ID`, `OPENCHAMBER_APNS_TEAM_ID`, `OPENCHAMBER_APNS_P8` (PEM contents; literal `\n` accepted) or `OPENCHAMBER_APNS_P8_PATH`, `OPENCHAMBER_APNS_BUNDLE_ID` (default `com.yee94.openchamber`), `OPENCHAMBER_APNS_ENVIRONMENT` (`
|
|
83
|
+
- Configuration (env first, then `settings.apnsConfig`): `OPENCHAMBER_PUSH_RELAY_URL` (optional send-URL override), `OPENCHAMBER_PUSH_RELAY_DISABLED`, `OPENCHAMBER_APNS_KEY_ID`, `OPENCHAMBER_APNS_TEAM_ID`, `OPENCHAMBER_APNS_P8` (PEM contents; literal `\n` accepted) or `OPENCHAMBER_APNS_P8_PATH`, `OPENCHAMBER_APNS_BUNDLE_ID` (default `com.yee94.openchamber`), `OPENCHAMBER_APNS_ENVIRONMENT` (`production` default for TestFlight/App Store builds; set `sandbox` explicitly for Xcode development builds).
|
|
83
84
|
|
|
84
85
|
### Emitter runtime API (emitter-runtime.js)
|
|
85
86
|
- `createNotificationEmitterRuntime(dependencies)`: creates runtime for unified notification emission channels.
|