@yuriai/web 0.2.27-beta.6 → 0.2.27
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 +8 -0
- package/dist/assets/{AgentAvatar-Bi1vvWPC.js → AgentAvatar-DNm_jMna.js} +1 -1
- package/dist/assets/AssistantContactStatus-BPRpgMFh.js +3 -0
- package/dist/assets/{AssistantUnreadBadge-DdJyySwn.js → AssistantUnreadBadge-BssH-RvV.js} +1 -1
- package/dist/assets/AssistantView-CxQv-9Ms.js +1 -0
- package/dist/assets/{DiagramView-CI4bTtxy.js → DiagramView-DPpG0fwx.js} +1 -1
- package/dist/assets/{FadeInOnReveal-BB4qEnAn.js → FadeInOnReveal-S6UbimjB.js} +1 -1
- package/dist/assets/{GuiPluginSurface-CguxFUbM.js → GuiPluginSurface-BOf0JA1T.js} +1 -1
- package/dist/assets/{GuiPluginWindow-DOJ7wuRH.js → GuiPluginWindow-OrYkfQ4m.js} +1 -1
- package/dist/assets/{Icon-t2xvbAyN.js → Icon-BE4mEwzV.js} +1 -1
- package/dist/assets/{ImageLoadingPlaceholder-D1L13TK0.js → ImageLoadingPlaceholder-CBFJC_KD.js} +1 -1
- package/dist/assets/{LoadingImage-5rY_edNm.js → LoadingImage-NLq7_P-i.js} +1 -1
- package/dist/assets/MarkdownRenderer-BaMotAOQ.js +2 -0
- package/dist/assets/{MarkdownRendererImpl-cE-0AYRg.js → MarkdownRendererImpl-Cv6UnGG7.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-BZyqDl82.js → MarkstreamRendererImpl-Rb9O6wkW.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-tbfsMfB-.js → MobileDetailNavigation-CK4KbkeS.js} +1 -1
- package/dist/assets/{MobileResizableSheet-BeRmT6_x.js → MobileResizableSheet-Deidw1br.js} +1 -1
- package/dist/assets/{MobileShareBridge-C3Equ3P_.js → MobileShareBridge-CO_OWEfq.js} +2 -2
- package/dist/assets/MobileTabPageHeader-DbC8L6A4.js +2 -0
- package/dist/assets/{MultiRunWindow-CAM2XPII.js → MultiRunWindow-DtVW9NTV.js} +1 -1
- package/dist/assets/{OnboardingScreen-4ftRerP5.js → OnboardingScreen-C8ld4wO7.js} +1 -1
- package/dist/assets/{OverlayScrollbar-CF0PCvQz.js → OverlayScrollbar-B3auC2WH.js} +1 -1
- package/dist/assets/{SettingsView-2tk4WH7R.js → SettingsView-Cm7woZWl.js} +15 -15
- package/dist/assets/{SettingsWindow-B9zbeJaW.js → SettingsWindow-CdL4PFxW.js} +1 -1
- package/dist/assets/{TerminalView-DfxvTHye.js → TerminalView-CwRB6Yyr.js} +1 -1
- package/dist/assets/{ToolOutputDialog-CrjDIhru.js → ToolOutputDialog-B4BfmoVH.js} +1 -1
- package/dist/assets/{YuriLogo-QvS1ZEHi.js → YuriLogo-BOx0s0Ue.js} +1 -1
- package/dist/assets/{appThemeRegistry-Bb_DtiV9.js → appThemeRegistry-B6woJIX5.js} +1 -1
- package/dist/assets/{assistant-attachment-cache-B9iHLlm2.js → assistant-attachment-cache-B_qRvy-k.js} +1 -1
- package/dist/assets/{button-DinGM3tu.js → button-BXxwtxsG.js} +1 -1
- package/dist/assets/{capgoAdapter-DufzjXRs.js → capgoAdapter-C5HFS-rx.js} +1 -1
- package/dist/assets/{collapsible-Bh1GLNYV.js → collapsible-BEm0787p.js} +1 -1
- package/dist/assets/context-menu-DUwvVUDY.js +1 -0
- package/dist/assets/{desktopRelayRestore-CoLLVJw8.js → desktopRelayRestore-D1UX7HW2.js} +1 -1
- package/dist/assets/device-BcRP6Tjd.js +2 -0
- package/dist/assets/{diagram-BmG-7Jb4.js → diagram-DyY8dxjZ.js} +1 -1
- package/dist/assets/{dialog-BXssfGXA.js → dialog-CLca6ojn.js} +1 -1
- package/dist/assets/dropdown-menu.styles-DGaALKP0.js +1 -0
- package/dist/assets/{es-HP_Ise0X.js → es-CrsHvgue.js} +2 -2
- package/dist/assets/feishu-Ct1ZxlzQ.svg +6 -0
- package/dist/assets/fileMentionAutocompleteState-BZJqfgae.js +2 -0
- package/dist/assets/{fileMentionTouchSelection-DSl0tj2r.js → fileMentionTouchSelection-C4dvP8GY.js} +2 -2
- package/dist/assets/{fileQueries-5a1jkme2.js → fileQueries-BeXkd3o6.js} +1 -1
- package/dist/assets/{fileReferenceActions-CGpBSFq4.js → fileReferenceActions-CrIAce3K.js} +1 -1
- package/dist/assets/{fr-D0kJXJ6U.js → fr-CEgiRlfa.js} +2 -2
- package/dist/assets/{gitApi-Wo0IZow9.js → gitApi-D2G9ny2O.js} +1 -1
- package/dist/assets/{gitApiHttp-De9liKnG.js → gitApiHttp-B7vYwgBh.js} +4 -4
- package/dist/assets/{gui-9enrif_1.js → gui-CJjEj3l4.js} +1 -1
- package/dist/assets/host-CnVx34Dh.js +1 -0
- package/dist/assets/{image-loading-Dq1g_wpm.js → image-loading-D5UhMj7Z.js} +1 -1
- package/dist/assets/{input-v8-rVbo-.js → input-D59Q2pm8.js} +1 -1
- package/dist/assets/insertionBoundaries-CedfTSM5.js +1 -0
- package/dist/assets/{ja-BjHKXazE.js → ja-CX-_p9jZ.js} +2 -2
- package/dist/assets/{ko-Llwnl876.js → ko-D5xlLYJM.js} +2 -2
- package/dist/assets/main-CxpUooVS.js +2 -0
- package/dist/assets/main-Dpm4KxWX.js +169 -0
- package/dist/assets/{markdownHeightCache-BVV2dktw.js → markdownHeightCache-D2VWb_4E.js} +1 -1
- package/dist/assets/{mcpQueries-BoBrB4a4.js → mcpQueries-DQ3KthDF.js} +1 -1
- package/dist/assets/miniChat-CTdj8Ug9.js +2 -0
- package/dist/assets/mobile-ChbA3Q8j.js +2 -0
- package/dist/assets/{mobileBackNavigation-DMSzAvb6.js → mobileBackNavigation-BJqt3oHk.js} +1 -1
- package/dist/assets/{multirun-BhWttsRQ.js → multirun-BILeETbd.js} +1 -1
- package/dist/assets/{native-DSvNnKAm.js → native-BYMhr-xH.js} +1 -1
- package/dist/assets/{native-config-DjdrW_9n.js → native-config-BIY0Cr-l.js} +1 -1
- package/dist/assets/{persistence-CfrHIiIS.js → persistence-CWuLIq1J.js} +2 -2
- package/dist/assets/{pl-BOd_idqn.js → pl-BjH81A_q.js} +2 -2
- package/dist/assets/projectMeta-B9_Uh8YH.js +1 -0
- package/dist/assets/{pt-BR-B8djxMsl.js → pt-BR-Dp5oK2x3.js} +2 -2
- package/dist/assets/{queryRuntime-Dkpnq3Z1.js → queryRuntime-CTcigFdj.js} +1 -1
- package/dist/assets/queue-abort-optimistic-CS5jTJq-.js +1 -0
- package/dist/assets/react-DRe85o5s.js +1 -0
- package/dist/assets/readiness-BNIgH81X.js +1 -0
- package/dist/assets/renderElectronMiniChatApp-asOqV7FB.js +2 -0
- package/dist/assets/renderMobileApp-DAfque7-.js +28 -0
- package/dist/assets/runtime-fetch-D0YWp3FJ.js +1 -0
- package/dist/assets/{runtime-file-download-CcNIVp7u.js → runtime-file-download-Cf1WxfeW.js} +1 -1
- package/dist/assets/{runtime-file-resource-6np6lzoV.js → runtime-file-resource-UJjHUF2C.js} +1 -1
- package/dist/assets/runtimeConfig-BX8JirIc.js +2 -0
- package/dist/assets/runtimeEndpointReset-CFQgUiUr.js +149 -0
- package/dist/assets/scheduledTaskNavigation-EomDNVu2.js +1 -0
- package/dist/assets/sessionLookup-BxAaxPOw.js +1 -0
- package/dist/assets/{sortable-tabs-strip-yKyqsqut.js → sortable-tabs-strip-DpbW5MqX.js} +1 -1
- package/dist/assets/speechSettingsQueries-CC0fusUo.js +4 -0
- package/dist/assets/src-BMKjN2ip.css +2 -0
- package/dist/assets/{store-CUBymvAC.js → store-CkIHVrmT.js} +4 -3
- package/dist/assets/{terminalApi-BblSkqch.js → terminalApi-rl9mZAlB.js} +1 -1
- package/dist/assets/{textarea-B39OCNPV.js → textarea-7eTptEtD.js} +1 -1
- package/dist/assets/{tooltip-d8TNN4lx.js → tooltip-BPwoSTzO.js} +1 -1
- package/dist/assets/types-CUtSV1V8.js +2 -0
- package/dist/assets/{uk-BNd7CjVO.js → uk-BEfkaLtM.js} +2 -2
- package/dist/assets/{useAppFontEffects-BVoVpJYO.js → useAppFontEffects-Ck2PdQRx.js} +52 -52
- package/dist/assets/{useAssistantUIStore-Bp6TxG5E.js → useAssistantUIStore-CfaQV3ID.js} +1 -1
- package/dist/assets/useDesktopWindowControlsLayout-DxxOUZj1.js +1 -0
- package/dist/assets/useEffectiveDirectory-CNCQfN_x.js +1 -0
- package/dist/assets/{useFontPreferences-BFyBjtQ6.js → useFontPreferences-DeqW9nRx.js} +1 -1
- package/dist/assets/useMobileNavigationStore-BmVr5a5c.js +17 -0
- package/dist/assets/useUIStore-C6CE42oh.js +1 -0
- package/dist/assets/{useWorkerHighlightedLines-CPxG8Fya.js → useWorkerHighlightedLines-CN_RGaSw.js} +1 -1
- package/dist/assets/{vendor-effect-DV9F8PTZ.js → vendor-effect-X1Hqc7ba.js} +13 -13
- package/dist/assets/vendor-opencode-client-cQ47ywrT.js +23 -0
- package/dist/assets/{vendor-opencode-plugin-CgKz9Hcy.js → vendor-opencode-plugin-BmdTE4Te.js} +1 -1
- package/dist/assets/vendor-opencode-schema-DWT45VBX.js +1 -0
- package/dist/assets/vendor-solid-js-D98iXT7C.js +1 -0
- package/dist/assets/vendor-zod-DZzbCm1s.js +55 -0
- package/dist/assets/{zh-CN-BkTAEOZG.js → zh-CN-DipfA56P.js} +2 -2
- package/dist/assets/{zh-TW-x8SfMzfc.js → zh-TW-B7pXMVjt.js} +2 -2
- package/dist/index.html +18 -18
- package/dist/mini-chat.html +18 -18
- package/dist/mobile.html +18 -18
- package/package.json +6 -1
- package/server/index.js +2 -145
- package/server/lib/assistants/DOCUMENTATION.md +69 -11
- package/server/lib/assistants/cards.js +1 -1
- package/server/lib/assistants/channel-image.js +92 -0
- package/server/lib/assistants/channel-image.test.js +76 -0
- package/server/lib/assistants/channel-output-store.test.js +41 -0
- package/server/lib/assistants/channel-output.integration.test.js +114 -0
- package/server/lib/assistants/channel-output.js +90 -0
- package/server/lib/assistants/channel-output.test.js +79 -0
- package/server/lib/assistants/channels/DOCUMENTATION.md +329 -0
- package/server/lib/assistants/channels/PROTOCOLS.md +250 -0
- package/server/lib/assistants/channels/dingtalk-chat-adapter.js +645 -0
- package/server/lib/assistants/channels/dingtalk-chat-adapter.test.js +423 -0
- package/server/lib/assistants/channels/integration.test.js +44 -0
- package/server/lib/assistants/channels/routes.js +59 -0
- package/server/lib/assistants/channels/routes.test.js +139 -0
- package/server/lib/assistants/channels/runtime.js +958 -0
- package/server/lib/assistants/channels/runtime.test.js +897 -0
- package/server/lib/assistants/channels/sdk-adapters.js +383 -0
- package/server/lib/assistants/channels/sdk-adapters.test.js +384 -0
- package/server/lib/assistants/channels/store.js +249 -0
- package/server/lib/assistants/channels/store.test.js +296 -0
- package/server/lib/assistants/channels/transport.js +42 -0
- package/server/lib/assistants/channels/transport.test.js +23 -0
- package/server/lib/assistants/channels/wecom-chat-adapter.js +703 -0
- package/server/lib/assistants/channels/wecom-chat-adapter.test.js +130 -0
- package/server/lib/assistants/contact-store.js +9 -3
- package/server/lib/assistants/contact-store.test.js +27 -0
- package/server/lib/assistants/contact-tools.js +65 -75
- package/server/lib/assistants/contact-tools.test.js +114 -22
- package/server/lib/assistants/harness.js +79 -34
- package/server/lib/assistants/harness.test.js +52 -20
- package/server/lib/assistants/message-channel-origin.js +7 -0
- package/server/lib/assistants/resource-reference.integration.test.js +284 -0
- package/server/lib/assistants/routes.js +14 -4
- package/server/lib/assistants/service.js +116 -69
- package/server/lib/assistants/service.test.js +31 -17
- package/server/lib/assistants/weixin/DOCUMENTATION.md +121 -14
- package/server/lib/assistants/weixin/api.js +45 -1
- package/server/lib/assistants/weixin/api.test.js +28 -0
- package/server/lib/assistants/weixin/chat-adapter.js +113 -0
- package/server/lib/assistants/weixin/chat-adapter.test.js +62 -0
- package/server/lib/assistants/weixin/inbound.js +149 -0
- package/server/lib/assistants/weixin/inbound.test.js +141 -0
- package/server/lib/assistants/weixin/media.js +79 -0
- package/server/lib/assistants/weixin/media.test.js +66 -0
- package/server/lib/assistants/weixin/runtime.js +105 -74
- package/server/lib/assistants/weixin/runtime.test.js +192 -4
- package/server/lib/assistants/weixin/store.js +16 -8
- package/server/lib/assistants/weixin/store.test.js +93 -0
- package/server/lib/assistants/weixin/toon.js +49 -0
- package/server/lib/assistants/weixin/toon.test.js +25 -0
- package/server/lib/assistants/yuri-project.http.test.js +9 -3
- package/server/lib/github/DOCUMENTATION.md +9 -8
- package/server/lib/llm/bridge-plugin.bundle.js +188 -188
- package/server/lib/notifications/DOCUMENTATION.md +6 -0
- package/server/lib/notifications/runtime.js +26 -15
- package/server/lib/notifications/runtime.test.js +14 -13
- package/server/lib/opencode/DOCUMENTATION.md +10 -1
- package/server/lib/opencode/auth.d.ts +6 -2
- package/server/lib/opencode/core-routes.js +0 -1
- package/server/lib/opencode/feature-routes-runtime.js +0 -24
- package/server/lib/opencode/location-release.d.ts +5 -1
- package/server/lib/opencode/managed-capabilities/scheduled-task.js +1 -1
- package/server/lib/opencode/managed-capabilities-runtime.test.js +1 -1
- package/server/lib/opencode/native-goal.js +15 -0
- package/server/lib/opencode/native-goal.test.js +17 -0
- package/server/lib/opencode/settings-helpers.js +0 -6
- package/server/lib/opencode/shutdown-runtime.js +0 -2
- package/server/lib/projects/project-config.js +3 -6
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +10 -35
- package/server/lib/scheduled-tasks/managed-tool-route.js +1 -30
- package/server/lib/scheduled-tasks/routes.js +0 -26
- package/server/lib/scheduled-tasks/runtime.js +33 -257
- package/server/lib/scheduled-tasks/runtime.test.js +24 -65
- package/server/lib/session-metadata/DOCUMENTATION.md +9 -12
- package/server/lib/session-metadata/routes.js +4 -38
- package/server/lib/session-metadata/routes.test.js +2 -2
- package/dist/assets/AssistantContactStatus-CWq-PDz6.js +0 -3
- package/dist/assets/AssistantView-Br1iETTs.js +0 -1
- package/dist/assets/MarkdownRenderer-BlGxjOei.js +0 -2
- package/dist/assets/MobileTabPageHeader-DQRqAAEf.js +0 -2
- package/dist/assets/context-menu-DpbkRkk1.js +0 -1
- package/dist/assets/device-BjRYYXNT.js +0 -2
- package/dist/assets/host-FR_grJxM.js +0 -1
- package/dist/assets/insertionBoundaries-CZz7TWJv.js +0 -1
- package/dist/assets/main-Bp9HHqTr.js +0 -2
- package/dist/assets/main-DOwAfmxJ.js +0 -169
- package/dist/assets/miniChat-BJDgCrfF.js +0 -2
- package/dist/assets/mobile-GM9931J_.js +0 -2
- package/dist/assets/projectMeta-31PobC-M.js +0 -1
- package/dist/assets/react-B9v0P7kT.js +0 -1
- package/dist/assets/readiness-CYNnsekT.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-N2r999Bf.js +0 -2
- package/dist/assets/renderMobileApp-CU1ec6Ak.js +0 -28
- package/dist/assets/runtime-fetch-D4ja813o.js +0 -1
- package/dist/assets/runtimeConfig-Db7yfo6L.js +0 -2
- package/dist/assets/runtimeEndpointReset-DO5WVetV.js +0 -149
- package/dist/assets/scheduledTaskNavigation-Bsrhv3Ow.js +0 -1
- package/dist/assets/sessionLookup-DRVy7LM1.js +0 -1
- package/dist/assets/speechSettingsQueries-DU25rmGc.js +0 -4
- package/dist/assets/src-Bckdo2XS.css +0 -2
- package/dist/assets/types-BqFQhQTt.js +0 -2
- package/dist/assets/useDesktopWindowControlsLayout-CYx1LNO5.js +0 -1
- package/dist/assets/useEffectiveDirectory-D8FFE5Yn.js +0 -1
- package/dist/assets/useMobileNavigationStore-BHMFeMjo.js +0 -23
- package/dist/assets/useUIStore-BbYD420L.js +0 -1
- package/dist/assets/vendor-opencode-client-UL_TecvQ.js +0 -12
- package/dist/assets/vendor-solid-js-0T254UHG.js +0 -1
- package/dist/assets/vendor-zod-Dzk5kdUU.js +0 -39
- package/server/lib/session-goal/DOCUMENTATION.md +0 -371
- package/server/lib/session-goal/capability.js +0 -57
- package/server/lib/session-goal/capability.test.js +0 -33
- package/server/lib/session-goal/objectives.js +0 -61
- package/server/lib/session-goal/routes.js +0 -274
- package/server/lib/session-goal/routes.test.js +0 -211
- package/server/lib/session-goal/runtime.js +0 -2452
- package/server/lib/session-goal/runtime.test.js +0 -2125
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import { prepareChannelOutput, readChannelDeliveryImage } from './channel-output.js';
|
|
6
|
+
import { loadChannelImage } from './channel-image.js';
|
|
7
|
+
import { createAssistantsService } from './service.js';
|
|
8
|
+
|
|
9
|
+
const png = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aKxkAAAAASUVORK5CYII=', 'base64');
|
|
10
|
+
const cleanups = [];
|
|
11
|
+
afterEach(async () => { while (cleanups.length) await cleanups.pop()(); });
|
|
12
|
+
const options = (overrides = {}) => ({ service: { prepareChannelImage: vi.fn(async () => ({ attachmentID: 'att_image' })) },
|
|
13
|
+
assistantID: 'bot', generation: 0, language: 'zh-CN', failureText: 'failed', assertCurrent: () => {}, ...overrides });
|
|
14
|
+
|
|
15
|
+
describe('shared channel image output', () => {
|
|
16
|
+
it.each(['session', 'assistant', 'schedule', 'future-card'])('silently excludes %s cards instead of sending title/link fallbacks', async (cardType) => {
|
|
17
|
+
const input = options();
|
|
18
|
+
const card = { type: 'card', cardType, title: 'Internal title', name: 'Internal name', url: 'yuri://internal' };
|
|
19
|
+
expect(await prepareChannelOutput({ messageID: 'card', text: '', cards: [card] }, input)).toEqual([]);
|
|
20
|
+
expect(await prepareChannelOutput({ messageID: 'card-parts', parts: [card], cards: [card] }, input)).toEqual([]);
|
|
21
|
+
expect(input.service.prepareChannelImage).not.toHaveBeenCalled();
|
|
22
|
+
expect(await prepareChannelOutput({ messageID: 'mixed', parts: [{ type: 'text', text: 'Normal reply' }, card,
|
|
23
|
+
{ type: 'file', mime: 'image/png', attachmentID: 'att_image' }] }, input))
|
|
24
|
+
.toEqual([{ text: 'Normal reply' }, { text: '', image: { attachmentID: 'att_image' } }]);
|
|
25
|
+
});
|
|
26
|
+
it('keeps prose/image order, parses escaped/spaced/reference URLs, ignores code and ordinary links', async () => {
|
|
27
|
+
const input = options();
|
|
28
|
+
const output = await prepareChannelOutput({ messageID: 'm', text: 'Before  after ![b][ref]\n\n[ref]: https://example.com/b.png\n\n`` [link](/file.png)' }, input);
|
|
29
|
+
expect(output.map((part) => part.image ? 'image' : part.text)).toEqual(['Before', 'image', 'after', 'image', '`` [link](/file.png)']);
|
|
30
|
+
expect(input.service.prepareChannelImage.mock.calls.map(([, source]) => source.url)).toEqual(['/a b.png', 'https://example.com/b.png']);
|
|
31
|
+
expect(JSON.stringify(output)).not.toContain('/a b.png');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('supports attachment-only replies and partial failure without dropping later content', async () => {
|
|
35
|
+
const input = options();
|
|
36
|
+
input.service.prepareChannelImage.mockRejectedValueOnce(new Error('private path and credential'));
|
|
37
|
+
const result = await prepareChannelOutput({ messageID: 'm', parts: [{ type: 'file', mime: 'image/png', attachmentID: 'one' },
|
|
38
|
+
{ type: 'text', text: 'next' }, { type: 'file', mime: 'image/jpeg', url: 'data:image/jpeg;base64,AA==' }] }, input);
|
|
39
|
+
expect(result).toEqual([{ text: '图片未能发送,请在 Yuri 中查看原图。' }, { text: 'next' }, { text: '', image: { attachmentID: 'att_image' } }]);
|
|
40
|
+
expect(JSON.stringify(result)).not.toMatch(/private|credential|data:/);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('fences late image preparation after a reset', async () => {
|
|
44
|
+
let current = true;
|
|
45
|
+
const input = options({ assertCurrent: () => { if (!current) throw new Error('cancelled'); } });
|
|
46
|
+
input.service.prepareChannelImage.mockImplementation(async () => { current = false; return { attachmentID: 'old' }; });
|
|
47
|
+
await expect(prepareChannelOutput({ messageID: 'm', text: '' }, input)).rejects.toThrow('cancelled');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('snapshots local generated images into owned durable attachments and reuses them after source removal', async () => {
|
|
51
|
+
const directory = await fs.mkdtemp(path.join(os.tmpdir(), 'yuri-channel-images-'));
|
|
52
|
+
cleanups.push(() => fs.rm(directory, { recursive: true, force: true }));
|
|
53
|
+
const service = createAssistantsService({ dbPath: path.join(directory, 'assistants.sqlite'), dataDir: directory,
|
|
54
|
+
buildOpenCodeUrl: () => 'http://127.0.0.1:1', getOpenCodeAuthHeaders: () => ({}),
|
|
55
|
+
getAllowedRoots: () => [directory], createChatCompletion: async () => ({ choices: [] }) });
|
|
56
|
+
cleanups.push(() => service.close());
|
|
57
|
+
const bot = service.createAssistant({ name: 'Image test', providerID: 'p', modelID: 'm', workspacePath: directory });
|
|
58
|
+
const source = path.join(directory, 'generated.png');
|
|
59
|
+
await fs.writeFile(source, png);
|
|
60
|
+
const image = await service.prepareChannelImage(bot.id, { url: source }, { generation: 0, uploadID: 'test-image' });
|
|
61
|
+
await fs.unlink(source);
|
|
62
|
+
expect(await service.prepareChannelImage(bot.id, { url: source }, { generation: 0, uploadID: 'test-image' })).toEqual(image);
|
|
63
|
+
expect(await readChannelDeliveryImage(service, bot.id, image)).toMatchObject({ buffer: png, mime: 'image/png' });
|
|
64
|
+
const other = service.createAssistant({ name: 'Other', providerID: 'p', modelID: 'm' });
|
|
65
|
+
await expect(readChannelDeliveryImage(service, other.id, image)).rejects.toMatchObject({ code: 'not_found' });
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it.each(['https://127.0.0.1/a.png', 'https://[::1]/a.png', 'https://[::ffff:127.0.0.1]/a.png', 'http://example.com/a.png',
|
|
69
|
+
'https://user:password@example.com/a.png', 'https://169.254.169.254/a.png', 'https://10.0.0.1/a.png'])('rejects unsafe remote image %s', async (url) => {
|
|
70
|
+
await expect(loadChannelImage({ url }, { cwd: os.tmpdir(), allowedRoots: [] })).rejects.toMatchObject({ code: 'image_unavailable' });
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('rejects disguised HTML/SVG and bounds inline bytes', async () => {
|
|
74
|
+
const input = { cwd: os.tmpdir(), allowedRoots: [] };
|
|
75
|
+
await expect(loadChannelImage({ url: 'data:image/png;base64,PGh0bWw+' }, input)).rejects.toThrow();
|
|
76
|
+
await expect(loadChannelImage({ url: 'data:image/svg+xml;base64,PHN2Zz4=' }, input)).rejects.toThrow();
|
|
77
|
+
expect(await loadChannelImage({ url: `data:image/png;base64,${png.toString('base64')}` }, input)).toMatchObject({ buffer: png, mime: 'image/png' });
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
# Enterprise message channels
|
|
2
|
+
|
|
3
|
+
Host-owned long-connection channel framework for enterprise platforms. It connects
|
|
4
|
+
one platform account to one existing Yuri Bot and reuses the Bot's normal contact
|
|
5
|
+
pipeline, tools and permissions. WeCom, Feishu and DingTalk wire behavior lives in
|
|
6
|
+
injected Chat SDK bridges (`sdk-adapters.js` and `dingtalk-chat-adapter.js`);
|
|
7
|
+
`runtime.js` and `store.js` own durable
|
|
8
|
+
storage, authorization, lifecycle and delivery semantics.
|
|
9
|
+
|
|
10
|
+
No public webhook, OAuth callback or platform protocol route is exposed here.
|
|
11
|
+
The shared runtime never constructs platform payloads, signs requests, refreshes
|
|
12
|
+
tokens or decides how a platform acknowledges a message. Those belong to the
|
|
13
|
+
adapter seam so a shared SDK can replace adapter internals without changing this
|
|
14
|
+
module.
|
|
15
|
+
|
|
16
|
+
## Chat adapter boundary
|
|
17
|
+
|
|
18
|
+
Platform implementations are supplied by the Host from a shared Chat SDK bridge.
|
|
19
|
+
Each `adapters[provider]` consumes a Chat SDK adapter internally;
|
|
20
|
+
the bridge is responsible for its dependency, protocol framing and reconnect
|
|
21
|
+
plumbing. This framework only sees `connect`/`send` and never imports the SDK,
|
|
22
|
+
registers SDK routes, or adds per-platform tables, queues or clocks.
|
|
23
|
+
|
|
24
|
+
Feishu reuses its existing Chat Adapter; WeCom and DingTalk implement the Chat SDK
|
|
25
|
+
Adapter interface over their official connection SDKs. The WeChat Bot
|
|
26
|
+
Adapter lives in `../weixin/chat-adapter.js` and is consumed by its existing
|
|
27
|
+
personal-channel runtime. Its QR authorization, typing, media behavior and private
|
|
28
|
+
database remain there. No second Chat state, lock or history engine is started.
|
|
29
|
+
SDK versions, ACK/ready evidence and platform limitations live in `PROTOCOLS.md`.
|
|
30
|
+
|
|
31
|
+
The seam is deliberately narrow so an SDK upgrade changes only the bridge:
|
|
32
|
+
|
|
33
|
+
- the framework owns Bot ownership, optional sender authorization, durable dedup,
|
|
34
|
+
bounded queues, transcript generation, lease and lifecycle;
|
|
35
|
+
- the adapter owns wire authentication, heartbeats, receipts, platform payloads
|
|
36
|
+
and target validation;
|
|
37
|
+
- both share one `{ connect, send }` contract and one `onMessage` receipt promise.
|
|
38
|
+
|
|
39
|
+
## Module map
|
|
40
|
+
|
|
41
|
+
- `store.js`: private SQLite binding, durable inbound receipts, ordered outbound
|
|
42
|
+
deliveries, routing targets and the process-owner lease.
|
|
43
|
+
- `runtime.js`: enablement policy, connect lifecycle, optional sender restriction,
|
|
44
|
+
bounded metadata projection, output reconciliation, dedup, retry/ambiguity and
|
|
45
|
+
shutdown.
|
|
46
|
+
- `routes.js`: authenticated settings/mutation routes behind the Host gate.
|
|
47
|
+
- `sdk-adapters.js`: vendor Chat Adapter bridges and provider registry.
|
|
48
|
+
- `dingtalk-chat-adapter.js`: Chat Adapter extension using the official Stream SDK.
|
|
49
|
+
- `wecom-chat-adapter.js`: Chat Adapter extension using the official WeCom SDK,
|
|
50
|
+
including platform-acknowledged sends rather than fire-and-forget writes.
|
|
51
|
+
- `transport.js`: bounded HTTP helpers for adapter-owned platform API calls;
|
|
52
|
+
platform sockets and protocol framing remain SDK-owned.
|
|
53
|
+
- `../weixin/toon.js`: reused JSON-only TOON encoder. Channel metadata does not
|
|
54
|
+
copy or fork it.
|
|
55
|
+
|
|
56
|
+
`service.channelPage()` is the internal bounded, ascending public-output seam. It
|
|
57
|
+
validates the Bot, uses the contact-store generation and returns only assistant
|
|
58
|
+
rows eligible for external delivery, excluding replies to built-in Yuri IM input.
|
|
59
|
+
It does not expose credentials or replace the contact execution engine.
|
|
60
|
+
|
|
61
|
+
## Runtime API
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
createAssistantChannelsRuntime({
|
|
65
|
+
directory, service, adapters, refreshAllowedRoots, env, clock, intervalMs,
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- `status(assistantID, provider)` — sync read; validates the Bot first.
|
|
70
|
+
- `save(assistantID, provider, input)` — save configuration and connect.
|
|
71
|
+
- `discover(assistantID, provider, input, { signal })` — temporarily connect and
|
|
72
|
+
return the first private sender's `{ ownerID }`, without saving or running tools.
|
|
73
|
+
- `transfer(assistantID, provider, input)` — explicitly move a local binding using
|
|
74
|
+
`{ sourceAssistantID, revision }`, without returning or re-entering its secret.
|
|
75
|
+
- `retry(assistantID, provider)` — explicit reconnect only.
|
|
76
|
+
- `disconnect(assistantID, provider)` — delete local configuration and queues.
|
|
77
|
+
- `forget(assistantID)` — delete every provider for a deleted Bot.
|
|
78
|
+
- `onTurnEvent(event)` — receipt completion from contact turn events.
|
|
79
|
+
- `close()` — drain channel work, release the lease and close SQLite.
|
|
80
|
+
|
|
81
|
+
`registerAssistantChannelRoutes(app, runtime)` registers:
|
|
82
|
+
|
|
83
|
+
| Method | Path | Behavior |
|
|
84
|
+
|---|---|---|
|
|
85
|
+
| GET | `/api/yuri/assistants/:assistantID/channels/:provider` | status |
|
|
86
|
+
| PUT | same | save + connect |
|
|
87
|
+
| POST | same `/retry` | reconnect without resending unknown output |
|
|
88
|
+
| POST | same `/transfer` | confirmed local rebind with source revision check |
|
|
89
|
+
| POST | same `/discover` | bounded, abortable user-ID discovery before Save |
|
|
90
|
+
| DELETE | same | disconnect |
|
|
91
|
+
|
|
92
|
+
Save input is `{ clientID, clientSecret?, ownerID, language? }`. A non-empty
|
|
93
|
+
`ownerID` is required on every save (`owner_required` otherwise) and restricts the
|
|
94
|
+
channel to that private sender. Existing unrestricted bindings remain readable and
|
|
95
|
+
operational until explicitly updated; no silent owner selection/migration occurs.
|
|
96
|
+
The first save
|
|
97
|
+
requires `clientSecret`; an update with the same `clientID` and an empty or omitted
|
|
98
|
+
secret keeps the stored one. A new `clientID` requires a new secret.
|
|
99
|
+
Responses are `Cache-Control: no-store` and contain only safe error codes — no
|
|
100
|
+
upstream bodies, secrets or routing targets.
|
|
101
|
+
|
|
102
|
+
Discovery takes `{ clientID, clientSecret? }` and the same credential-preservation
|
|
103
|
+
rules as Save. It returns only `{ ownerID }` after the first valid private message;
|
|
104
|
+
groups and missing/oversized sender IDs do not qualify. The user confirms that ID
|
|
105
|
+
through Save. The discovery message never enters the assistant execution pipeline.
|
|
106
|
+
Credentials stay in the temporary connection, not SQLite or response DTOs.
|
|
107
|
+
The request expires after 90 seconds (`discovery_timeout`), and HTTP disconnect,
|
|
108
|
+
Bot deletion, lease loss and Host shutdown abort it. A discovery owns its lane and
|
|
109
|
+
reserves its provider/account against concurrent saves or probes. It cannot take
|
|
110
|
+
another Bot's bound account. An existing connection on this lane is drained first
|
|
111
|
+
and resumed unchanged after discovery completes, fails or is cancelled. No other
|
|
112
|
+
provider/account is stopped. Platform ACK/reconnect behavior remains adapter-owned.
|
|
113
|
+
|
|
114
|
+
Status shape:
|
|
115
|
+
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"provider": "wecom",
|
|
119
|
+
"status": "disabled|disconnected|connecting|connected|reconnecting|error",
|
|
120
|
+
"error": null,
|
|
121
|
+
"configured": true,
|
|
122
|
+
"clientID": "…",
|
|
123
|
+
"ownerID": "…",
|
|
124
|
+
"hasSecret": true,
|
|
125
|
+
"transport": "websocket"
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`clientID`, `ownerID` and `hasSecret` appear only when configured. The secret
|
|
130
|
+
itself never appears in any DTO, error, transcript, model context or log.
|
|
131
|
+
Unconfigured Bots may also receive `transferSources`: safe source Bot IDs, names,
|
|
132
|
+
client IDs and binding revisions for this provider. The UI uses the same move
|
|
133
|
+
button, warning and confirmation text as WeChat. It offers matching accounts
|
|
134
|
+
instead of telling users to manually unlink the other Bot first.
|
|
135
|
+
|
|
136
|
+
Transfer drains and stops the source lane under source/destination mutation locks,
|
|
137
|
+
then atomically moves credentials and rotates the epoch. It starts at the target
|
|
138
|
+
Bot's current transcript tip, preserves receipt IDs against replay, and discards
|
|
139
|
+
the old Bot's pending input and queued replies. Chat history and already-started
|
|
140
|
+
tasks are not moved or cancelled. Stale revisions, an occupied destination or
|
|
141
|
+
failed writes preserve the original binding and resume its receiver. Other
|
|
142
|
+
providers/accounts are untouched. The host lease still prevents taking a binding
|
|
143
|
+
from another process; this operation only moves a binding in this Host's store.
|
|
144
|
+
|
|
145
|
+
## Enablement policy
|
|
146
|
+
|
|
147
|
+
Before opening storage or creating a timer, the runtime resolves policy from its
|
|
148
|
+
environment. `NODE_ENV=development` or `YURI_ELECTRON_DEV=1/true` disables channels
|
|
149
|
+
by default. Only an explicit `YURI_CHANNELS_ENABLED=1/true` opts in; `0/false` or
|
|
150
|
+
an unrecognized non-empty value disables them in every environment. Production
|
|
151
|
+
defaults remain enabled.
|
|
152
|
+
|
|
153
|
+
A disabled runtime does not open/create SQLite, acquire a lease, poll, send or
|
|
154
|
+
mutate bindings. Status returns `disabled`; save, retry and disconnect fail with
|
|
155
|
+
`channel_disabled` (403). `forget` and `close` are no-ops, so development cannot
|
|
156
|
+
erase production channel credentials or delete their bindings.
|
|
157
|
+
|
|
158
|
+
## Adapter contract
|
|
159
|
+
|
|
160
|
+
Adapters are injected by provider key and must implement exactly:
|
|
161
|
+
|
|
162
|
+
```js
|
|
163
|
+
{
|
|
164
|
+
connect({ config, signal, onReady, onMessage, onError }): Promise<void>,
|
|
165
|
+
send({ config, target, text, image?, id, signal, beforeSend? }): Promise<void>,
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
- `config` is `{ clientID, clientSecret, ownerID, language }`.
|
|
170
|
+
- `connect` resolves or rejects only when that connection ends. It calls
|
|
171
|
+
`onReady()` after authentication and `onError(error)` for asynchronous transport
|
|
172
|
+
failures. Errors carry a safe `code`; `ambiguous` marks an indeterminate send.
|
|
173
|
+
The framework sends only while the latest connection reported `onReady`; a
|
|
174
|
+
transport error or connection end immediately closes that output lane.
|
|
175
|
+
- `onMessage(message)` must return a Promise that the adapter awaits before
|
|
176
|
+
acknowledging the platform. It persists a durable receipt; it does not wait for
|
|
177
|
+
model execution. A missing or overlong stable `id` is never admitted.
|
|
178
|
+
- Inbound shape:
|
|
179
|
+
`{ id, senderID, chatType: 'private'|'group', text, metadata?, target? }`.
|
|
180
|
+
- `send` receives the current config, the private `target` snapshot and a stable
|
|
181
|
+
delivery `id`. The adapter re-validates `target`; the framework never follows a
|
|
182
|
+
user-controlled URL. An abort after submission must reject with `ambiguous: true`
|
|
183
|
+
so the row becomes `unknown` instead of being retried.
|
|
184
|
+
- Adapters must honor `signal`; shutdown and disconnect abort platform I/O.
|
|
185
|
+
- Output is either plain `text` or one `image: { buffer, mime, filename }`.
|
|
186
|
+
The shared `../channel-output.js` projector snapshots published Markdown/file
|
|
187
|
+
images through the existing contact attachment store. Outbox's additive `image`
|
|
188
|
+
column defaults to empty for legacy text rows and stores only the descriptor;
|
|
189
|
+
bytes are materialized immediately before dispatch and cleared from the row on
|
|
190
|
+
success. Each image retains its own target and stable ID, so partial failure or
|
|
191
|
+
restart cannot resend earlier text. A blocked image produces a safe failure
|
|
192
|
+
notice; unknown delivery stays unknown and is not automatically resent.
|
|
193
|
+
After upload, adapters call `beforeSend()` to fence a reset/rebind before the
|
|
194
|
+
actual platform send. Upload failure is definite (no chat message was submitted),
|
|
195
|
+
unlike an interrupted/ambiguous final send. Source/size bounds live in
|
|
196
|
+
`../DOCUMENTATION.md` under message channel output.
|
|
197
|
+
- Internal Yuri cards of every type are unsupported output: the shared projector
|
|
198
|
+
silently skips them without title/anchor/deeplink fallback or an error notice.
|
|
199
|
+
Card-only rows advance the feed without creating deliveries/retries; ordinary
|
|
200
|
+
text and images in mixed output still send. The original Yuri cards are unchanged.
|
|
201
|
+
|
|
202
|
+
## Authorization and persistence
|
|
203
|
+
|
|
204
|
+
Only platform-delivered `private` messages with a valid sender identity may execute
|
|
205
|
+
tools. A saved non-empty `ownerID` adds an exact sender restriction. With an empty
|
|
206
|
+
ID, administrators must control access through the platform's Bot/application
|
|
207
|
+
availability and permissions. Group messages and messages without a valid sender
|
|
208
|
+
or stable platform ID are ignored. Receiving a message never saves an owner binding.
|
|
209
|
+
All allowed users share this Bot's existing context; this is not per-user isolation.
|
|
210
|
+
|
|
211
|
+
Account IDs, owner IDs and secrets are never truncated. An overlong value is a
|
|
212
|
+
`validation_error`; a changed `clientID` must supply its own secret rather than
|
|
213
|
+
silently reusing the previous account's credential. Changing the owner or account
|
|
214
|
+
starts the new binding at the current transcript tip, so replies produced while
|
|
215
|
+
the previous owner was disconnected are never leaked to the new destination. A
|
|
216
|
+
same-identity save keeps the existing watermark and durable receipts.
|
|
217
|
+
|
|
218
|
+
Bindings live under `<yuriDataDir>/channels/channel.sqlite`. The directory is 0700
|
|
219
|
+
and the database 0600, with SQLite secure-delete enabled. Secrets are **not
|
|
220
|
+
encrypted at rest**; the host OS user must protect the data directory and backups
|
|
221
|
+
(on Windows, OS ACLs remain necessary). The same `provider + clientID` maps to at
|
|
222
|
+
most one Bot in the data directory; a second Bot receives `account_in_use` (409).
|
|
223
|
+
Different enterprise accounts can bind different Bots, including multiple accounts
|
|
224
|
+
of the same provider. The personal-WeChat single-entry/rebind restriction belongs
|
|
225
|
+
only to `../weixin/` and never limits these enterprise bindings.
|
|
226
|
+
|
|
227
|
+
`target` is platform routing metadata (for example a reply handle or session
|
|
228
|
+
webhook). It is persisted only in this private database and per outbox row. It is
|
|
229
|
+
never added to model context, transcript text or HTTP DTOs. The framework replies
|
|
230
|
+
to the configured owner destination, or, without a binding, to the latest accepted
|
|
231
|
+
private sender. The runtime derives `target.userID` from the authenticated platform
|
|
232
|
+
sender, overriding any supplied routing field; queued output keeps its destination
|
|
233
|
+
snapshot. There is no push destination before the first accepted private message,
|
|
234
|
+
and earlier public output is not backfilled when a recipient first appears.
|
|
235
|
+
|
|
236
|
+
Inbound `metadata` is projected before storage: credential-shaped keys, media/file
|
|
237
|
+
references, URLs and raw event envelopes are dropped or replaced, nesting and
|
|
238
|
+
total size are bounded, and the result is encoded as TOON in an ordinary text part
|
|
239
|
+
labelled external content. This is a conservative projection, not proof that a
|
|
240
|
+
linked article or media body was read. Text is capped at 20,000 characters.
|
|
241
|
+
Internal `platform` and `chatType` labels are omitted from content metadata.
|
|
242
|
+
Ordinary text with only these labels remains one original text part, with no
|
|
243
|
+
TOON appendix; actual media/transcription descriptors retain their content hints.
|
|
244
|
+
|
|
245
|
+
## Shared three-provider state
|
|
246
|
+
|
|
247
|
+
One `channel` row exists per `(assistantID, provider)`. The three enterprise
|
|
248
|
+
providers share the same SQLite file, receipt table, outbox table and process
|
|
249
|
+
lease; there is no per-platform queue, worker, database or reconnect loop. Each
|
|
250
|
+
account still has one receiver and one serial input/output lane, so providers
|
|
251
|
+
cannot consume each other's queue or block each other's replies. Deleting a Bot
|
|
252
|
+
removes all three rows, receipts and deliveries in one transaction.
|
|
253
|
+
|
|
254
|
+
## Delivery semantics
|
|
255
|
+
|
|
256
|
+
- **Durability:** the receipt, private routing target and deduplicated stable ID
|
|
257
|
+
commit before `onMessage` resolves. IDs are namespaced by provider, client account
|
|
258
|
+
and owner, so platform replays and restarts cannot re-execute admitted tools.
|
|
259
|
+
- **Backpressure:** pending plus admitted receipts cap at 100; each pass admits at
|
|
260
|
+
most 20. Adapters may treat `backlog_full` as retryable and must not acknowledge.
|
|
261
|
+
A platform replay whose stable ID already has a durable receipt is acknowledged
|
|
262
|
+
without a new slot, even when the backlog is full.
|
|
263
|
+
- **Isolation:** each account has one receiver, one serial inbound worker and one
|
|
264
|
+
serial outbound scheduler. A slow Bot cannot block another account.
|
|
265
|
+
- **Output source:** externally eligible public assistant replies, including
|
|
266
|
+
background replies, come from `channelPage`. Binding starts at the current
|
|
267
|
+
contact tip, so previous history/greetings are not sent. Internal settle markers
|
|
268
|
+
are omitted; failures use a safe generic message.
|
|
269
|
+
All channels attached to the same Bot share its contact context, but replies
|
|
270
|
+
go only to the channel that admitted the original input. Its persisted contact
|
|
271
|
+
`turnID` is the reserved `channel:*`/`weixin:*` receipt ID, and exact receipt
|
|
272
|
+
ownership by binding epoch gates delivery; another channel never broadcasts it.
|
|
273
|
+
Built-in Yuri IM replies stay in the Yuri conversation: the shared contact feed
|
|
274
|
+
resolves their persisted `turnID` to the original admitted user row and excludes
|
|
275
|
+
them from every external channel. Only proactive turns without a channel origin,
|
|
276
|
+
such as scheduled-task result reviews, may be pushed to all eligible bound
|
|
277
|
+
platforms. Selection never uses the latest conversation turn.
|
|
278
|
+
Each enterprise receipt keeps its own private reply target, so a later sender
|
|
279
|
+
cannot redirect an earlier reply. The inbox target column is added in place for
|
|
280
|
+
existing databases; legacy receipts without a target and without a fixed owner
|
|
281
|
+
are not guessed from the latest sender. The feed watermark still advances over
|
|
282
|
+
filtered replies. Channels are not separate conversation contexts.
|
|
283
|
+
- **Generation:** a transcript wipe changes `channelPage().generation`. Queued
|
|
284
|
+
output from the previous generation is deleted, and late async work is fenced by
|
|
285
|
+
epoch, lease and generation.
|
|
286
|
+
- **Unknown delivery:** a crash or abort during `sending`, or an ambiguous adapter
|
|
287
|
+
error, marks the row `unknown`. It is never automatically resent and status
|
|
288
|
+
reports `delivery_unknown`. `retry` only reconnects and does not clear it.
|
|
289
|
+
Definitively failed rows may be retried explicitly after capped automatic attempts.
|
|
290
|
+
Pending rows retain their sequence order, but `unknown` and `blocked` rows are
|
|
291
|
+
bypassed so one failed notification cannot prevent later replies or Bot execution.
|
|
292
|
+
Their durable state and error indicator survive later successful sends and restart.
|
|
293
|
+
Saving the same account/owner preserves unknown rows; disconnecting discards that
|
|
294
|
+
channel's queued replies as well as its credentials.
|
|
295
|
+
- **Reconnect:** connection failures retry with 1–30 second capped exponential
|
|
296
|
+
backoff. Authentication failure and SDK `connection_replaced` become a sticky
|
|
297
|
+
`error` until an explicit save or retry, so bad credentials or mutual-kick loops
|
|
298
|
+
cannot hot-loop. Output is only attempted after `onReady`; a send failure never
|
|
299
|
+
marks the lane connected. While sticky, new inbound receipts are not admitted
|
|
300
|
+
and already durable but unadmitted work waits for an explicit reconnect.
|
|
301
|
+
- **Save and concurrency:** a save drains admitted inbound work and aborts the old
|
|
302
|
+
receiver under a per-channel mutation lock. Owner/account changes revalidate the
|
|
303
|
+
binding epoch after the wait; a conflict or failed write resumes the previous
|
|
304
|
+
receiver instead of stranding it. `retry` and `disconnect` share the same lock
|
|
305
|
+
and revalidate the epoch after draining.
|
|
306
|
+
- **Disconnect:** deletes local credentials, receipts and queued replies. It does
|
|
307
|
+
not cancel already admitted contact work; late output is fenced and discarded.
|
|
308
|
+
- **Bot deletion:** `forget(assistantID)` removes every provider's local binding
|
|
309
|
+
and queues for that Bot.
|
|
310
|
+
- **Shutdown:** `close()` stops new work, aborts platform I/O, awaits all tracked
|
|
311
|
+
channel operations, releases the process lease and only then closes SQLite. The
|
|
312
|
+
owning Host must close channels before `service.close()`.
|
|
313
|
+
- **Lease:** one process sharing the data directory owns channels for 60 seconds,
|
|
314
|
+
renewed each tick (default 2 seconds). Another enabled process cannot steal a
|
|
315
|
+
live account and responds `channel_in_use` until the lease expires.
|
|
316
|
+
|
|
317
|
+
## Not in this layer
|
|
318
|
+
|
|
319
|
+
Live typing/presence, inbound platform media download, template cards, interactive
|
|
320
|
+
callbacks and per-provider protocol routing are intentionally absent. Those belong
|
|
321
|
+
to adapters or a shared SDK. This layer also does not promise server-side
|
|
322
|
+
exactly-once delivery or platform token revocation.
|
|
323
|
+
|
|
324
|
+
## Validation
|
|
325
|
+
|
|
326
|
+
Focused Vitest suite: `bunx vitest run --project @yuriai/web packages/web/server/lib/assistants/channels`.
|
|
327
|
+
It uses real SQLite and the real assistant service for the end-to-end
|
|
328
|
+
channel → Bot → durable reply path. Adapter wire tests live with their adapters and
|
|
329
|
+
do not prove real-account permissions, quotas or mobile rendering.
|