@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,296 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
6
|
+
import { createAssistantChannelStore } from './store.js';
|
|
7
|
+
|
|
8
|
+
const Database = createRequire(import.meta.url)('better-sqlite3');
|
|
9
|
+
const cleanup = [];
|
|
10
|
+
afterEach(() => { while (cleanup.length) cleanup.pop()(); });
|
|
11
|
+
const directory = () => {
|
|
12
|
+
const value = fs.mkdtempSync(path.join(os.tmpdir(), 'yuri-channels-store-'));
|
|
13
|
+
cleanup.push(() => fs.rmSync(value, { recursive: true, force: true }));
|
|
14
|
+
return value;
|
|
15
|
+
};
|
|
16
|
+
const bind = (store, assistantID = 'bot', overrides = {}) => store.bind({
|
|
17
|
+
assistant_id: assistantID,
|
|
18
|
+
provider: 'wecom',
|
|
19
|
+
client_id: 'client',
|
|
20
|
+
client_secret: 'fake-secret',
|
|
21
|
+
owner_id: 'owner',
|
|
22
|
+
language: 'zh-CN',
|
|
23
|
+
generation: 0,
|
|
24
|
+
ordinal: 0,
|
|
25
|
+
updated_at: 1,
|
|
26
|
+
...overrides,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('enterprise channel private store', () => {
|
|
30
|
+
it('adds receipt routing to an existing database without losing receipts or bindings', () => {
|
|
31
|
+
const dir = directory();
|
|
32
|
+
const original = createAssistantChannelStore(dir);
|
|
33
|
+
const binding = bind(original);
|
|
34
|
+
original.accept(binding, [{ id: 'old-receipt', text: 'existing', payload: '' }]);
|
|
35
|
+
original.close();
|
|
36
|
+
const db = new Database(path.join(dir, 'channel.sqlite'));
|
|
37
|
+
db.exec('ALTER TABLE inbox DROP COLUMN target');
|
|
38
|
+
db.close();
|
|
39
|
+
const store = createAssistantChannelStore(dir);
|
|
40
|
+
cleanup.push(() => store.close());
|
|
41
|
+
expect(store.get('bot', 'wecom')).toMatchObject({ epoch: binding.epoch });
|
|
42
|
+
expect(store.receipt('old-receipt', binding.epoch)).toEqual({ id: 'old-receipt', target: '' });
|
|
43
|
+
store.accept(binding, [{ id: 'new-receipt', text: 'new', payload: '', target: '{"userID":"alice"}' }]);
|
|
44
|
+
expect(store.receipt('new-receipt', binding.epoch)).toEqual({ id: 'new-receipt', target: '{"userID":"alice"}' });
|
|
45
|
+
expect(store.receipt('new-receipt', 'other-epoch')).toBeUndefined();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('atomically moves one account while keeping receipts and dropping old queued content', () => {
|
|
49
|
+
const store = createAssistantChannelStore(directory());
|
|
50
|
+
cleanup.push(() => store.close());
|
|
51
|
+
const source = bind(store, 'source');
|
|
52
|
+
store.accept(source, [{ id: 'receipt', text: 'old request', payload: '', target: '' }]);
|
|
53
|
+
store.collect(source, { generation: 0, ordinal: 1 }, [{ id: 'old-output', text: 'old reply' }], 1);
|
|
54
|
+
const input = { sourceAssistantID: 'source', assistantID: 'target', provider: 'wecom', revision: source.epoch, generation: 2, ordinal: 8, updatedAt: 2 };
|
|
55
|
+
expect(() => store.transfer({ ...input, revision: 'stale' })).toThrow('binding_changed');
|
|
56
|
+
expect(store.get('source', 'wecom')).toMatchObject({ epoch: source.epoch });
|
|
57
|
+
const moved = store.transfer(input);
|
|
58
|
+
expect(store.get('source', 'wecom')).toBeNull();
|
|
59
|
+
expect(moved).toMatchObject({ assistant_id: 'target', client_id: 'client', client_secret: 'fake-secret', generation: 2, ordinal: 8 });
|
|
60
|
+
expect(moved.epoch).not.toBe(source.epoch);
|
|
61
|
+
expect(store.hasReceipt('receipt')).toBe(true);
|
|
62
|
+
expect(store.pending(moved.epoch)).toEqual([]);
|
|
63
|
+
expect(store.nextDelivery(moved.epoch)).toBeUndefined();
|
|
64
|
+
expect(store.accept(moved, [{ id: 'receipt', text: 'replay' }])).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('rolls back receipts, output and ownership when moving the binding fails', () => {
|
|
68
|
+
const dir = directory();
|
|
69
|
+
const store = createAssistantChannelStore(dir);
|
|
70
|
+
cleanup.push(() => store.close());
|
|
71
|
+
const source = bind(store, 'source');
|
|
72
|
+
store.accept(source, [{ id: 'pending', text: 'keep request', payload: '' }]);
|
|
73
|
+
store.collect(source, { generation: 0, ordinal: 1 }, [{ id: 'output', text: 'keep reply' }], 1);
|
|
74
|
+
const db = new Database(path.join(dir, 'channel.sqlite'));
|
|
75
|
+
try {
|
|
76
|
+
db.exec("CREATE TRIGGER fail_transfer BEFORE UPDATE OF assistant_id ON channel BEGIN SELECT RAISE(ABORT, 'move_failed'); END");
|
|
77
|
+
expect(() => store.transfer({ sourceAssistantID: 'source', assistantID: 'target', provider: 'wecom', revision: source.epoch, generation: 0, ordinal: 0, updatedAt: 2 })).toThrow('move_failed');
|
|
78
|
+
expect(store.get('source', 'wecom')).toMatchObject({ epoch: source.epoch });
|
|
79
|
+
expect(store.get('target', 'wecom')).toBeNull();
|
|
80
|
+
expect(store.pending(source.epoch)).toEqual([expect.objectContaining({ id: 'pending', text: 'keep request' })]);
|
|
81
|
+
expect(store.nextDelivery(source.epoch)).toMatchObject({ id: 'output', text: 'keep reply' });
|
|
82
|
+
} finally { db.close(); }
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('creates a 0700 directory and 0600 database and enforces account ownership', () => {
|
|
86
|
+
const dir = directory();
|
|
87
|
+
const store = createAssistantChannelStore(dir);
|
|
88
|
+
cleanup.push(() => store.close());
|
|
89
|
+
expect(fs.statSync(dir).mode & 0o777).toBe(0o700);
|
|
90
|
+
expect(fs.statSync(path.join(dir, 'channel.sqlite')).mode & 0o777).toBe(0o600);
|
|
91
|
+
bind(store);
|
|
92
|
+
expect(() => bind(store, 'other')).toThrow('account_in_use');
|
|
93
|
+
expect(store.get('bot', 'wecom')).toMatchObject({
|
|
94
|
+
client_id: 'client', owner_id: 'owner', client_secret: 'fake-secret', status: 'connecting',
|
|
95
|
+
});
|
|
96
|
+
expect(store.get('other', 'wecom')).toBeNull();
|
|
97
|
+
// Same client ID on another provider is a separate account.
|
|
98
|
+
expect(bind(store, 'other', { provider: 'feishu' })).toMatchObject({ provider: 'feishu' });
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it.each(['wecom', 'feishu', 'dingtalk'])('allows independent %s accounts to bind different Bots', (provider) => {
|
|
102
|
+
const store = createAssistantChannelStore(directory());
|
|
103
|
+
cleanup.push(() => store.close());
|
|
104
|
+
bind(store, 'bot-one', { provider, client_id: 'account-one' });
|
|
105
|
+
bind(store, 'bot-two', { provider, client_id: 'account-two' });
|
|
106
|
+
expect(store.get('bot-one', provider)).toMatchObject({ client_id: 'account-one' });
|
|
107
|
+
expect(store.get('bot-two', provider)).toMatchObject({ client_id: 'account-two' });
|
|
108
|
+
expect(() => bind(store, 'bot-three', { provider, client_id: 'account-one' })).toThrow('account_in_use');
|
|
109
|
+
store.unlink('bot-two', provider);
|
|
110
|
+
expect(store.get('bot-one', provider)).toMatchObject({ client_id: 'account-one' });
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('deduplicates stable inbound IDs across restart and keeps private routing out of text', () => {
|
|
114
|
+
const dir = directory();
|
|
115
|
+
let store = createAssistantChannelStore(dir);
|
|
116
|
+
const binding = bind(store);
|
|
117
|
+
expect(store.accept(binding, [
|
|
118
|
+
{ id: 'm1', text: 'hello', payload: 'meta', target: '{"reply":"opaque"}' },
|
|
119
|
+
{ id: 'm1', text: 'duplicate', payload: 'changed', target: '{"reply":"hijack"}' },
|
|
120
|
+
])).toBe(true);
|
|
121
|
+
expect(store.pending(binding.epoch)).toEqual([
|
|
122
|
+
expect.objectContaining({ id: 'm1', text: 'hello', payload: 'meta', state: 'pending' }),
|
|
123
|
+
]);
|
|
124
|
+
expect(store.hasReceipt('m1')).toBe(true);
|
|
125
|
+
expect(store.get('bot', 'wecom').target).toBe('{"reply":"opaque"}');
|
|
126
|
+
store.close();
|
|
127
|
+
store = createAssistantChannelStore(dir);
|
|
128
|
+
cleanup.push(() => store.close());
|
|
129
|
+
const restarted = store.get('bot', 'wecom');
|
|
130
|
+
expect(store.accept(restarted, [{ id: 'm1', text: 'replay', payload: '', target: '' }])).toBe(false);
|
|
131
|
+
expect(store.pending(restarted.epoch)).toEqual([
|
|
132
|
+
expect.objectContaining({ id: 'm1', text: 'hello', payload: 'meta' }),
|
|
133
|
+
]);
|
|
134
|
+
expect(store.get('bot', 'wecom').target).toBe('{"reply":"opaque"}');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('rotates epoch on update but preserves pending work for the same identity', () => {
|
|
138
|
+
const store = createAssistantChannelStore(directory());
|
|
139
|
+
cleanup.push(() => store.close());
|
|
140
|
+
const binding = bind(store);
|
|
141
|
+
store.accept(binding, [{ id: 'm1', text: 'pending', target: '{"reply":"opaque"}' }]);
|
|
142
|
+
const updated = bind(store, 'bot', { client_secret: 'new-secret', language: 'en' });
|
|
143
|
+
expect(updated.epoch).not.toBe(binding.epoch);
|
|
144
|
+
expect(updated).toMatchObject({ client_secret: 'new-secret', language: 'en', status: 'connecting' });
|
|
145
|
+
expect(store.pending(updated.epoch)).toEqual([expect.objectContaining({ id: 'm1', text: 'pending' })]);
|
|
146
|
+
expect(store.get('bot', 'wecom').target).toBe('{"reply":"opaque"}');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('drops the previous owner account queues and routing target on identity change', () => {
|
|
150
|
+
const store = createAssistantChannelStore(directory());
|
|
151
|
+
cleanup.push(() => store.close());
|
|
152
|
+
const binding = bind(store);
|
|
153
|
+
store.accept(binding, [{ id: 'm1', text: 'old owner', target: '{"reply":"old"}' }]);
|
|
154
|
+
store.collect(binding, { generation: 0, ordinal: 1 }, [{ id: 'out', text: 'old reply' }], 2);
|
|
155
|
+
const updated = bind(store, 'bot', {
|
|
156
|
+
client_id: 'new-client', owner_id: 'new-owner', generation: 7, ordinal: 50,
|
|
157
|
+
});
|
|
158
|
+
expect(store.pending(updated.epoch)).toEqual([]);
|
|
159
|
+
expect(store.nextDelivery(updated.epoch)).toBeUndefined();
|
|
160
|
+
expect(store.get('bot', 'wecom')).toMatchObject({
|
|
161
|
+
client_id: 'new-client', owner_id: 'new-owner', target: '', generation: 7, ordinal: 50,
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('recovers admitted receipts without replay, marks interrupted sends unknown and clears private text', () => {
|
|
166
|
+
const dir = directory();
|
|
167
|
+
const store = createAssistantChannelStore(dir);
|
|
168
|
+
cleanup.push(() => store.close());
|
|
169
|
+
const binding = bind(store);
|
|
170
|
+
store.accept(binding, [
|
|
171
|
+
{ id: 'admitted', text: 'private text', payload: 'private meta', target: '{"reply":"opaque"}' },
|
|
172
|
+
{ id: 'pending', text: 'still pending' },
|
|
173
|
+
]);
|
|
174
|
+
store.markInbox('admitted', 'admitted');
|
|
175
|
+
store.collect(binding, { generation: 0, ordinal: 0 }, [{ id: 'out', text: 'reply' }], 2);
|
|
176
|
+
store.markDelivery('out', 'sending');
|
|
177
|
+
store.recover(binding.epoch, 'interrupted feedback');
|
|
178
|
+
expect(store.pending(binding.epoch)).toEqual([expect.objectContaining({ id: 'pending', text: 'still pending' })]);
|
|
179
|
+
// An indeterminate send stays durable but does not block interruption feedback.
|
|
180
|
+
expect(store.nextDelivery(binding.epoch)).toEqual(expect.objectContaining({
|
|
181
|
+
id: 'admitted:interrupted', text: 'interrupted feedback', state: 'pending',
|
|
182
|
+
}));
|
|
183
|
+
expect(store.hasUnknown(binding.epoch)).toBe(true);
|
|
184
|
+
const db = new Database(path.join(dir, 'channel.sqlite'));
|
|
185
|
+
cleanup.push(() => db.close());
|
|
186
|
+
expect(db.prepare("SELECT text,payload,state FROM inbox WHERE id='admitted'").get())
|
|
187
|
+
.toEqual({ text: '', payload: '', state: 'done' });
|
|
188
|
+
expect(db.prepare("SELECT text FROM outbox WHERE id='admitted:interrupted'").get().text).toBe('interrupted feedback');
|
|
189
|
+
expect(db.prepare("SELECT state FROM outbox WHERE id='out'").get().state).toBe('unknown');
|
|
190
|
+
// retry re-queues definitively failed rows only; unknown stays unknown.
|
|
191
|
+
store.retry(binding.epoch);
|
|
192
|
+
expect(store.nextDelivery(binding.epoch)).toEqual(expect.objectContaining({ id: 'admitted:interrupted', state: 'pending' }));
|
|
193
|
+
expect(db.prepare("SELECT state FROM outbox WHERE id='out'").get().state).toBe('unknown');
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('drops queued output from an older transcript generation and keeps stable IDs idempotent', () => {
|
|
197
|
+
const store = createAssistantChannelStore(directory());
|
|
198
|
+
cleanup.push(() => store.close());
|
|
199
|
+
const binding = bind(store);
|
|
200
|
+
store.collect(binding, { generation: 0, ordinal: 1 }, [{ id: 'old', text: 'old' }], 2);
|
|
201
|
+
store.collect(binding, { generation: 1, ordinal: 2 }, [{ id: 'new', text: 'new' }], 3);
|
|
202
|
+
expect(store.nextDelivery(binding.epoch)).toEqual(expect.objectContaining({ id: 'new', text: 'new' }));
|
|
203
|
+
expect(store.get('bot', 'wecom')).toMatchObject({ generation: 1, ordinal: 2 });
|
|
204
|
+
// Replaying the same delivery ID after a restart must not duplicate output.
|
|
205
|
+
store.collect(binding, { generation: 1, ordinal: 2 }, [{ id: 'new', text: 'new' }], 4);
|
|
206
|
+
expect(store.nextDelivery(binding.epoch)).toEqual(expect.objectContaining({ id: 'new' }));
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('serializes delivery retries, blocks after repeated definite failure and never clears unknown', () => {
|
|
210
|
+
const store = createAssistantChannelStore(directory());
|
|
211
|
+
cleanup.push(() => store.close());
|
|
212
|
+
const binding = bind(store);
|
|
213
|
+
store.collect(binding, { generation: 0, ordinal: 0 }, [{ id: 'out', text: 'reply' }], 1);
|
|
214
|
+
store.markDelivery('out', 'sending');
|
|
215
|
+
store.failDelivery('out');
|
|
216
|
+
expect(store.nextDelivery(binding.epoch)).toEqual(expect.objectContaining({ id: 'out', state: 'pending' }));
|
|
217
|
+
store.markDelivery('out', 'sending');
|
|
218
|
+
store.failDelivery('out');
|
|
219
|
+
store.markDelivery('out', 'sending');
|
|
220
|
+
store.failDelivery('out');
|
|
221
|
+
expect(store.hasBlocked(binding.epoch)).toBe(true);
|
|
222
|
+
expect(store.nextDelivery(binding.epoch)).toBeUndefined();
|
|
223
|
+
store.retry(binding.epoch);
|
|
224
|
+
expect(store.nextDelivery(binding.epoch)).toEqual(expect.objectContaining({ id: 'out', state: 'pending' }));
|
|
225
|
+
store.markDelivery('out', 'unknown');
|
|
226
|
+
store.retry(binding.epoch);
|
|
227
|
+
expect(store.hasUnknown(binding.epoch)).toBe(true);
|
|
228
|
+
expect(store.nextDelivery(binding.epoch)).toBeUndefined();
|
|
229
|
+
expect(store.hasReceipt('missing')).toBe(false);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('preserves pending output order across restart while bypassing durable failed/unknown sends', () => {
|
|
233
|
+
const dir = directory();
|
|
234
|
+
let store = createAssistantChannelStore(dir);
|
|
235
|
+
cleanup.push(() => store.close());
|
|
236
|
+
const binding = bind(store);
|
|
237
|
+
store.collect(binding, { generation: 0, ordinal: 0 }, [
|
|
238
|
+
{ id: 'first', text: 'first' },
|
|
239
|
+
{ id: 'failed', text: 'failed' },
|
|
240
|
+
{ id: 'second', text: 'second' },
|
|
241
|
+
{ id: 'third', text: 'third' },
|
|
242
|
+
], 1);
|
|
243
|
+
store.markDelivery('first', 'unknown');
|
|
244
|
+
store.markDelivery('failed', 'blocked');
|
|
245
|
+
store.close();
|
|
246
|
+
store = createAssistantChannelStore(dir);
|
|
247
|
+
expect(store.nextDelivery(binding.epoch)).toEqual(expect.objectContaining({ id: 'second', state: 'pending' }));
|
|
248
|
+
store.sent('second');
|
|
249
|
+
expect(store.nextDelivery(binding.epoch)).toEqual(expect.objectContaining({ id: 'third', state: 'pending' }));
|
|
250
|
+
expect(store.hasUnknown(binding.epoch)).toBe(true);
|
|
251
|
+
expect(store.hasBlocked(binding.epoch)).toBe(true);
|
|
252
|
+
store.retry(binding.epoch);
|
|
253
|
+
expect(store.nextDelivery(binding.epoch)).toEqual(expect.objectContaining({ id: 'failed', state: 'pending' }));
|
|
254
|
+
expect(store.hasUnknown(binding.epoch)).toBe(true);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it('leases one process at a time and expires a dead owner', () => {
|
|
258
|
+
const store = createAssistantChannelStore(directory());
|
|
259
|
+
cleanup.push(() => store.close());
|
|
260
|
+
expect(store.acquire('a', 1_000)).toBe(true);
|
|
261
|
+
expect(store.acquire('b', 1_000)).toBe(false);
|
|
262
|
+
expect(store.owns('a', 1_000)).toBe(true);
|
|
263
|
+
expect(store.owns('b', 1_000)).toBe(false);
|
|
264
|
+
expect(store.acquire('b', 61_000)).toBe(true);
|
|
265
|
+
expect(store.owns('a', 61_000)).toBe(false);
|
|
266
|
+
store.release('b');
|
|
267
|
+
expect(store.owns('b', 61_000)).toBe(false);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('bounds each admission pass to 20 while backlog counts pending and admitted', () => {
|
|
271
|
+
const store = createAssistantChannelStore(directory());
|
|
272
|
+
cleanup.push(() => store.close());
|
|
273
|
+
const binding = bind(store);
|
|
274
|
+
store.accept(binding, Array.from({ length: 25 }, (_, index) => ({ id: `m${index}`, text: 'x' })));
|
|
275
|
+
expect(store.pending(binding.epoch)).toHaveLength(20);
|
|
276
|
+
expect(store.backlog(binding.epoch)).toBe(25);
|
|
277
|
+
store.markInbox('m0', 'admitted');
|
|
278
|
+
expect(store.backlog(binding.epoch)).toBe(25);
|
|
279
|
+
store.finishTurn('m0');
|
|
280
|
+
expect(store.backlog(binding.epoch)).toBe(24);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('forgets every provider for one Bot in one transaction', () => {
|
|
284
|
+
const store = createAssistantChannelStore(directory());
|
|
285
|
+
cleanup.push(() => store.close());
|
|
286
|
+
const wecom = bind(store);
|
|
287
|
+
const feishu = bind(store, 'bot', { provider: 'feishu' });
|
|
288
|
+
store.accept(wecom, [{ id: 'm1', text: 'x' }]);
|
|
289
|
+
store.collect(feishu, { generation: 0, ordinal: 0 }, [{ id: 'out', text: 'y' }], 1);
|
|
290
|
+
store.forget('bot');
|
|
291
|
+
expect(store.get('bot', 'wecom')).toBeNull();
|
|
292
|
+
expect(store.get('bot', 'feishu')).toBeNull();
|
|
293
|
+
expect(store.pending(wecom.epoch)).toEqual([]);
|
|
294
|
+
expect(store.nextDelivery(feishu.epoch)).toBeUndefined();
|
|
295
|
+
});
|
|
296
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const channelError = (code, ambiguous = false) => Object.assign(new Error(code), { code, ambiguous });
|
|
2
|
+
|
|
3
|
+
export function officialURL(value, { protocol = 'https:', hosts, path } = {}) {
|
|
4
|
+
let url;
|
|
5
|
+
try { url = new URL(value); } catch { throw channelError('invalid_response'); }
|
|
6
|
+
if (url.protocol !== protocol || !hosts.includes(url.hostname) || url.port || url.username || url.password
|
|
7
|
+
|| url.hash || (path && url.pathname !== path)) throw channelError('invalid_response');
|
|
8
|
+
return url.href;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function requestJSON(url, { body, headers, signal, fetchImpl = fetch, sending = false } = {}) {
|
|
12
|
+
const requestSignal = signal ? AbortSignal.any([signal, AbortSignal.timeout(20_000)]) : AbortSignal.timeout(20_000);
|
|
13
|
+
requestSignal.throwIfAborted();
|
|
14
|
+
let response;
|
|
15
|
+
try {
|
|
16
|
+
const multipart = body instanceof FormData;
|
|
17
|
+
response = await fetchImpl(url, { method: 'POST', redirect: 'error', signal: requestSignal,
|
|
18
|
+
headers: { ...(!multipart ? { 'Content-Type': 'application/json' } : {}), ...headers }, body: multipart ? body : JSON.stringify(body) });
|
|
19
|
+
} catch { throw channelError(signal?.aborted ? 'cancelled' : 'network_error', sending); }
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
await response.body?.cancel().catch(() => {});
|
|
22
|
+
throw channelError([401, 403].includes(response.status) ? 'auth_expired' : 'network_error', sending && response.status >= 500);
|
|
23
|
+
}
|
|
24
|
+
if (!response.body) throw channelError('invalid_response', sending);
|
|
25
|
+
const reader = response.body.getReader();
|
|
26
|
+
const chunks = [];
|
|
27
|
+
let size = 0;
|
|
28
|
+
try {
|
|
29
|
+
while (true) {
|
|
30
|
+
requestSignal.throwIfAborted();
|
|
31
|
+
const { done, value } = await reader.read();
|
|
32
|
+
if (done) break;
|
|
33
|
+
size += value.byteLength;
|
|
34
|
+
if (size > 1024 * 1024) throw channelError('invalid_response', sending);
|
|
35
|
+
chunks.push(value);
|
|
36
|
+
}
|
|
37
|
+
return JSON.parse(Buffer.concat(chunks, size).toString('utf8'));
|
|
38
|
+
} catch (error) {
|
|
39
|
+
await reader.cancel().catch(() => {});
|
|
40
|
+
throw error?.code === 'invalid_response' ? error : channelError('invalid_response', sending);
|
|
41
|
+
} finally { reader.releaseLock(); }
|
|
42
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { officialURL, requestJSON } from './transport.js';
|
|
3
|
+
|
|
4
|
+
describe('enterprise channel outbound boundaries', () => {
|
|
5
|
+
it('accepts only explicitly allowed TLS hosts and paths', () => {
|
|
6
|
+
const rules = { hosts: ['open.feishu.cn'], path: '/callback/ws/endpoint' };
|
|
7
|
+
expect(officialURL('https://open.feishu.cn/callback/ws/endpoint', rules)).toContain('open.feishu.cn');
|
|
8
|
+
for (const url of ['http://open.feishu.cn/callback/ws/endpoint', 'https://open.feishu.cn.evil.example/callback/ws/endpoint',
|
|
9
|
+
'https://user:secret@open.feishu.cn/callback/ws/endpoint', 'https://open.feishu.cn:8443/callback/ws/endpoint',
|
|
10
|
+
'https://open.feishu.cn/other', 'https://127.0.0.1/callback/ws/endpoint']) expect(() => officialURL(url, rules)).toThrow('invalid_response');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('does not forward raw HTTP errors and bounds JSON bodies', async () => {
|
|
14
|
+
const fetchImpl = vi.fn(async () => new Response('private upstream secret', { status: 403 }));
|
|
15
|
+
await expect(requestJSON('https://example.com', { fetchImpl })).rejects.toMatchObject({ code: 'auth_expired' });
|
|
16
|
+
expect(fetchImpl.mock.calls[0][1].redirect).toBe('error');
|
|
17
|
+
await expect(requestJSON('https://example.com', { sending: true, fetchImpl: async () => { throw new Error('private-token'); } }))
|
|
18
|
+
.rejects.toMatchObject({ code: 'network_error', ambiguous: true });
|
|
19
|
+
await expect(requestJSON('https://example.com', { fetchImpl: async () => new Response('x'.repeat(1024 * 1024 + 1)) }))
|
|
20
|
+
.rejects.toMatchObject({ code: 'invalid_response' });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
});
|