@yuriai/web 0.2.25 → 0.2.27-beta.3
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 +21 -1
- package/dist/assets/AgentAvatar-kIN4sZMz.js +1 -0
- package/dist/assets/AssistantView-C2KQZ6a4.js +3 -0
- package/dist/assets/{DiagramView-DN_rHdr9.js → DiagramView-DK0iXm9b.js} +1 -1
- package/dist/assets/{FadeInOnReveal-555z1y1N.js → FadeInOnReveal-BJA9Za3T.js} +1 -1
- package/dist/assets/{GuiPluginSurface-BPMATuPa.js → GuiPluginSurface-Dz2CdSUA.js} +1 -1
- package/dist/assets/{GuiPluginWindow-CAmfr79x.js → GuiPluginWindow-l4FYY6S-.js} +1 -1
- package/dist/assets/Icon-BP1sfnHn.js +1 -0
- package/dist/assets/{ImageLoadingPlaceholder-BMsQLN_b.js → ImageLoadingPlaceholder-DCWssLJG.js} +1 -1
- package/dist/assets/{LoadingImage-DI7sb_H_.js → LoadingImage-C_Hryaqe.js} +1 -1
- package/dist/assets/MarkdownRenderer-Y6uQXIFH.js +2 -0
- package/dist/assets/{MarkdownRendererImpl-B9K5q0Lc.js → MarkdownRendererImpl-qKp1tQrP.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-9gUEVQck.js → MarkstreamRendererImpl-B_JTod0h.js} +1 -1
- package/dist/assets/MobileDetailNavigation-B3rUx5Ve.js +1 -0
- package/dist/assets/{MobileResizableSheet-_6OvPSMI.js → MobileResizableSheet-F1zSUD1S.js} +1 -1
- package/dist/assets/{MobileShareBridge-BrdOiu_r.js → MobileShareBridge-F70fkIfS.js} +3 -3
- package/dist/assets/MobileTabPageHeader-0esgB2TO.js +2 -0
- package/dist/assets/MultiRunWindow-D8m6R_4x.js +1 -0
- package/dist/assets/{OnboardingScreen-g8PDztN3.js → OnboardingScreen-BAsPVV_W.js} +1 -1
- package/dist/assets/{OverlayScrollbar-COv8rH_z.js → OverlayScrollbar-wiRM4AGj.js} +1 -1
- package/dist/assets/SettingsView-izzjIckv.js +29 -0
- package/dist/assets/SettingsWindow-CSuHDq_c.js +1 -0
- package/dist/assets/{TerminalView-BLer-ZhM.js → TerminalView-BtM5-BVx.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DI-s2TBb.js → ToolOutputDialog-DJs9w1_J.js} +2 -2
- package/dist/assets/{YuriLogo-BP4j1iqV.js → YuriLogo-aBS6wlYU.js} +1 -1
- package/dist/assets/appThemeRegistry-BY5rY9-W.js +1 -0
- package/dist/assets/{assistant-attachment-cache-Cis9yYGt.js → assistant-attachment-cache-B9iHLlm2.js} +1 -1
- package/dist/assets/{button-Be1cqulG.js → button-Dt6Ygbc7.js} +1 -1
- package/dist/assets/{capgoAdapter-B31jIkD8.js → capgoAdapter-MQ1qpf60.js} +1 -1
- package/dist/assets/collapsible-Dm7OHk7m.js +1 -0
- package/dist/assets/{device-hj359GjJ.js → device-BjRYYXNT.js} +1 -1
- package/dist/assets/{diagram-hEIRiKol.js → diagram-DWZaG3_v.js} +1 -1
- package/dist/assets/dialog-CTYD3Sbr.css +1 -0
- package/dist/assets/dialog-CjQeHVOc.js +1 -0
- package/dist/assets/{dropdown-menu.styles-xxM2ofOp.js → dropdown-menu.styles-PdxueXzN.js} +1 -1
- package/dist/assets/{es-Clj7CS2r.js → es-BjI1GHJ5.js} +3 -3
- package/dist/assets/{fileMentionTouchSelection-CTh0Mc2g.js → fileMentionTouchSelection-D7QtVxjI.js} +2 -2
- package/dist/assets/{fileQueries-COS23nLq.js → fileQueries-5a1jkme2.js} +1 -1
- package/dist/assets/{fileReferenceActions-Cus9oSW7.js → fileReferenceActions-BAoEu4z8.js} +1 -1
- package/dist/assets/{fr-dmrFQLCO.js → fr-Bs7ndHkb.js} +4 -4
- package/dist/assets/{gitApi-deADOzlN.js → gitApi-BxQmH8Wg.js} +1 -1
- package/dist/assets/{gitApiHttp-BBRKl9WX.js → gitApiHttp-DHrRqnYh.js} +3 -3
- package/dist/assets/{gui-BHEKelUx.js → gui-9enrif_1.js} +1 -1
- package/dist/assets/{host-DrqLUbqt.js → host-D1EpSUMR.js} +1 -1
- package/dist/assets/image-loading-Dq1g_wpm.js +1 -0
- package/dist/assets/{input-DTdHYZ6r.js → input-Dq4usRDa.js} +1 -1
- package/dist/assets/insertionBoundaries-CKQL85zy.js +1 -0
- package/dist/assets/{ja-Co0dxiN_.js → ja-DkdV26EW.js} +4 -4
- package/dist/assets/{ko-BltElAGq.js → ko-B0qoC5da.js} +4 -4
- package/dist/assets/main-CNwFqQQd.js +2 -0
- package/dist/assets/main-DPhcXanT.js +169 -0
- package/dist/assets/{markdownHeightCache-DnR01ECa.js → markdownHeightCache-C1u0bWDL.js} +1 -1
- package/dist/assets/{markdownTheme-DHoKvD6O.js → markdownTheme-hpURsgju.js} +1 -1
- package/dist/assets/{mcpQueries-Cpb22_60.js → mcpQueries-D2IxTr4k.js} +1 -1
- package/dist/assets/miniChat-CF2vb25D.js +2 -0
- package/dist/assets/mobile-C24qSj44.js +2 -0
- package/dist/assets/{mobileBackNavigation-BibkyIeB.js → mobileBackNavigation-vpCg1S7j.js} +1 -1
- package/dist/assets/{multirun-CPvUnP91.js → multirun-DT-dFXud.js} +2 -2
- package/dist/assets/{native-BMAEg2E6.js → native-De1DIkLZ.js} +1 -1
- package/dist/assets/{native-config-DA8S8EqV.js → native-config-ncdoz9Wl.js} +1 -1
- package/dist/assets/{persistence-CBL0OOdj.js → persistence-JyLTFv27.js} +1 -1
- package/dist/assets/{pl-qd6Wnl7H.js → pl-D27Y_GBs.js} +4 -4
- package/dist/assets/projectMeta-CG8NLahh.js +1 -0
- package/dist/assets/{pt-BR-CsOFfQXS.js → pt-BR-DbocEu4b.js} +3 -3
- package/dist/assets/{react-BYRXYlGz.js → react-CURmDhtB.js} +1 -1
- package/dist/assets/{readiness-RiznV1AX.js → readiness-DSJs_3v4.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-DdGqTh4X.js → renderElectronMiniChatApp-ChZCxxH6.js} +2 -2
- package/dist/assets/renderMobileApp-CRv3Il6P.js +28 -0
- package/dist/assets/{runtime-file-download-B_c7JBoS.js → runtime-file-download-CcNIVp7u.js} +1 -1
- package/dist/assets/{runtime-file-resource-DpTxBCsp.js → runtime-file-resource-6np6lzoV.js} +1 -1
- package/dist/assets/runtimeConfig-CZrflo-r.js +2 -0
- package/dist/assets/runtimeEndpointReset-BL9hV6J1.css +1 -0
- package/dist/assets/runtimeEndpointReset-Cx3RE97b.js +149 -0
- package/dist/assets/scheduledTaskNavigation-rhgnZaaj.js +1 -0
- package/dist/assets/sessionChangeSummary-8C8nv-EP.css +1 -0
- package/dist/assets/sessionChangeSummary-CVUA1AFw.js +1 -0
- package/dist/assets/{sessionLookup-B7kUOIpO.js → sessionLookup-C3_vQwLe.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-CQZ16rbO.js → sortable-tabs-strip-C1QmKFdb.js} +1 -1
- package/dist/assets/speechSettingsQueries-BSQ-2JTv.js +4 -0
- package/dist/assets/src-NKCZI3Lg.css +2 -0
- package/dist/assets/{store-7wItZZ7_.js → store-DvN2L3vf.js} +4 -4
- package/dist/assets/{terminalApi-C0_GUlPR.js → terminalApi-B5o8UqWA.js} +1 -1
- package/dist/assets/{textarea-BU8JtaSQ.js → textarea-vtIQM2iP.js} +1 -1
- package/dist/assets/{tooltip-C8DhNU1d.js → tooltip-BpG2mxrT.js} +1 -1
- package/dist/assets/{touch-gestures-zegXCZEP.js → touch-gestures-K2_ZOkKW.js} +1 -1
- package/dist/assets/types-CNTgeeM1.js +2 -0
- package/dist/assets/{uk-BNrdZFvK.js → uk-B_JwElWz.js} +3 -3
- package/dist/assets/{useAppFontEffects-Bs6kVjrE.js → useAppFontEffects-BguV1Hfa.js} +55 -51
- package/dist/assets/useAppFontEffects-RpgNbjA4.css +1 -0
- package/dist/assets/{useAssistantUIStore-NlYBroMc.js → useAssistantUIStore-C9FPlYQz.js} +1 -1
- package/dist/assets/{useDesktopWindowControlsLayout-COBTly74.js → useDesktopWindowControlsLayout-CwgkVw9f.js} +1 -1
- package/dist/assets/useEffectiveDirectory-Ci6Z13kj.js +1 -0
- package/dist/assets/{useFontPreferences-DQAS94Z4.js → useFontPreferences-DMiP_Yy-.js} +1 -1
- package/dist/assets/useMobileNavigationStore-TCj7ZnhV.js +418 -0
- package/dist/assets/{useThemeSystem-8jhE4Zyk.js → useThemeSystem-CGF5jnIh.js} +1 -1
- package/dist/assets/{useUIStore-96W41KFb.js → useUIStore-DI7va1HH.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-BZUO0Si5.js → useWorkerHighlightedLines-HKhuYGSj.js} +1 -1
- package/dist/assets/{vendor-base-ui-CdzJ6My_.js → vendor-base-ui-BQjbsJ43.js} +1 -1
- package/dist/assets/{vendor-cmdk-RDxC-9Iz.js → vendor-cmdk-C3oBVL9X.js} +1 -1
- package/dist/assets/{vendor-dnd-kit-accessibility-COSwgjFs.js → vendor-dnd-kit-accessibility-DxpFzZhi.js} +1 -1
- package/dist/assets/{vendor-dnd-kit-core-5pNnzVdw.js → vendor-dnd-kit-core-B3g3zWQd.js} +1 -1
- package/dist/assets/{vendor-dnd-kit-sortable-Dm50I0m7.js → vendor-dnd-kit-sortable-BKewx0Py.js} +1 -1
- package/dist/assets/{vendor-framer-motion-BQ3-sJMO.js → vendor-framer-motion-C1twy-GF.js} +1 -1
- package/dist/assets/{vendor-markstream-react-Bm0cO70Z.js → vendor-markstream-react-BlbOg72y.js} +3 -3
- package/dist/assets/vendor-motion-BmLx2V78.js +1 -0
- package/dist/assets/{vendor-opencode-client-fxfj4IA_.js → vendor-opencode-client-UL_TecvQ.js} +1 -1
- package/dist/assets/{vendor-opencode-plugin-CQ5ogY33.js → vendor-opencode-plugin-Bw7Q6Nv9.js} +1 -1
- package/dist/assets/{vendor-pierre-diffs-DPBtNDJ5.js → vendor-pierre-diffs-Bj9Nqn6w.js} +1 -1
- package/dist/assets/{vendor-react-BP2cRVqX.js → vendor-react-D5d-V1vN.js} +1 -1
- package/dist/assets/{vendor-react-drawio-Ck9ZKdNN.js → vendor-react-drawio-C-iPmmED.js} +1 -1
- package/dist/assets/{vendor-reactuses-core-BJ-jJ4YM.js → vendor-reactuses-core-BcebBLwF.js} +1 -1
- package/dist/assets/{vendor-solid-js-Dmt4_-Zk.js → vendor-solid-js-0T254UHG.js} +1 -1
- package/dist/assets/{vendor-sonner-ZS8XIOVl.js → vendor-sonner-r2EJnfoo.js} +1 -1
- package/dist/assets/{vendor-stream-diffs-TgIdH4lX.js → vendor-stream-diffs-BnLmeqg2.js} +2 -2
- package/dist/assets/{vendor-tanstack-react-query-CdqCAt40.js → vendor-tanstack-react-query-C4SG3JZB.js} +1 -1
- package/dist/assets/vendor-tanstack-react-virtual-BeZn51tF.js +1 -0
- package/dist/assets/{vendor-zustand-o69pgTEK.js → vendor-zustand-B43HCgwC.js} +1 -1
- package/dist/assets/{zh-CN-DMvJXS23.js → zh-CN-DhFFdHQu.js} +4 -4
- package/dist/assets/{zh-TW-D0wsKLs1.js → zh-TW-BvehppXO.js} +4 -4
- package/dist/index.html +18 -18
- package/dist/mini-chat.html +18 -18
- package/dist/mobile.html +18 -18
- package/package.json +1 -1
- package/server/lib/assistants/DOCUMENTATION.md +68 -37
- package/server/lib/assistants/cards.js +4 -0
- package/server/lib/assistants/cards.test.js +11 -1
- package/server/lib/assistants/contact-attachments.http.test.js +31 -7
- package/server/lib/assistants/contact-store.js +70 -27
- package/server/lib/assistants/contact-store.test.js +88 -8
- package/server/lib/assistants/contact-tools.js +68 -84
- package/server/lib/assistants/contact-tools.test.js +85 -42
- package/server/lib/assistants/harness.js +6 -3
- package/server/lib/assistants/harness.test.js +25 -10
- package/server/lib/assistants/routes.js +25 -3
- package/server/lib/assistants/service.js +283 -146
- package/server/lib/assistants/service.test.js +954 -54
- package/server/lib/assistants/weixin/DOCUMENTATION.md +142 -0
- package/server/lib/assistants/weixin/api.js +113 -0
- package/server/lib/assistants/weixin/api.test.js +80 -0
- package/server/lib/assistants/weixin/routes.js +23 -0
- package/server/lib/assistants/weixin/routes.test.js +41 -0
- package/server/lib/assistants/weixin/runtime.js +357 -0
- package/server/lib/assistants/weixin/runtime.test.js +286 -0
- package/server/lib/assistants/weixin/store.js +103 -0
- package/server/lib/assistants/weixin/typing.js +88 -0
- package/server/lib/assistants/weixin/typing.test.js +185 -0
- package/server/lib/assistants/yuri-project.http.test.js +47 -0
- package/server/lib/assistants/yuri-tools.js +1 -1
- package/server/lib/assistants/yuri-tools.test.js +3 -2
- package/server/lib/git/DOCUMENTATION.md +6 -0
- package/server/lib/git/branches.test.js +18 -0
- package/server/lib/git/service.js +6 -3
- package/server/lib/llm/DOCUMENTATION.md +15 -7
- package/server/lib/llm/bridge-client.js +58 -34
- package/server/lib/llm/bridge-client.test.js +123 -16
- package/server/lib/notifications/APNS.md +7 -4
- package/server/lib/notifications/DOCUMENTATION.md +3 -1
- package/server/lib/notifications/apns-runtime.js +14 -8
- package/server/lib/notifications/apns-runtime.test.js +28 -0
- package/server/lib/notifications/family-completion-gate.js +37 -31
- package/server/lib/notifications/family-completion-gate.test.js +32 -0
- package/server/lib/opencode/DOCUMENTATION.md +6 -0
- package/server/lib/opencode/hmr-isolation.test.js +56 -0
- package/server/lib/opencode/lifecycle.js +23 -27
- package/server/lib/opencode/network-runtime.js +8 -14
- package/server/lib/opencode/network-runtime.test.js +4 -4
- package/server/lib/opencode/proxy.js +2 -1
- package/server/lib/opencode/proxy.test.js +1 -0
- package/server/lib/opencode/shutdown-runtime.js +1 -1
- package/server/lib/opencode/shutdown-runtime.test.js +12 -0
- package/server/lib/relay/DOCUMENTATION.md +8 -1
- package/server/lib/relay/relay-server.e2e.test.ts +102 -1
- package/server/lib/relay/service.js +1 -1
- package/server/lib/relay/service.test.js +14 -1
- package/server/lib/request-cors.js +1 -1
- package/server/lib/request-cors.test.js +13 -1
- package/server/lib/session-goal/DOCUMENTATION.md +3 -0
- package/server/lib/session-goal/runtime.js +0 -4
- package/server/lib/session-index/DOCUMENTATION.md +18 -4
- package/server/lib/session-index/event-ingest.js +6 -0
- package/server/lib/session-index/event-ingest.test.js +10 -0
- package/server/lib/session-index/service.js +89 -13
- package/server/lib/session-index/service.test.js +144 -1
- package/server/lib/session-metadata/routes.test.js +44 -0
- package/server/lib/tts/DOCUMENTATION.md +24 -2
- package/server/lib/tts/direct-speech.test.js +28 -3
- package/server/opencode-proxy.test.js +5 -5
- package/dist/assets/AgentAvatar--wjVXk3I.js +0 -1
- package/dist/assets/AssistantView-CSpW-4g6.js +0 -3
- package/dist/assets/Icon-Bn4Eec3Y.js +0 -1
- package/dist/assets/MarkdownRenderer-DP2a0lfG.js +0 -2
- package/dist/assets/MobileDetailNavigation-C9NHt08G.js +0 -1
- package/dist/assets/MobileTabPageHeader-qe23xT2-.js +0 -2
- package/dist/assets/MultiRunWindow-CvHADKf9.js +0 -1
- package/dist/assets/SettingsView-DK8Jkkhd.js +0 -29
- package/dist/assets/SettingsWindow-EP8KZok8.js +0 -1
- package/dist/assets/appThemeRegistry-BnQF2GlY.js +0 -1
- package/dist/assets/collapsible-DqfguRMp.js +0 -1
- package/dist/assets/dialog-BS-KgM5J.js +0 -1
- package/dist/assets/image-loading-DJZLvhMd.js +0 -1
- package/dist/assets/insertionBoundaries-h2be7xbf.js +0 -1
- package/dist/assets/main-BpBrYqtJ.js +0 -169
- package/dist/assets/main-C2QklNP4.js +0 -2
- package/dist/assets/miniChat-C-9deNrt.js +0 -2
- package/dist/assets/mobile-DW7tEL-k.js +0 -2
- package/dist/assets/projectMeta-BwAS96mf.js +0 -1
- package/dist/assets/renderMobileApp-Bipi0hKv.js +0 -28
- package/dist/assets/runtimeConfig-Dx7Y6Yvp.js +0 -2
- package/dist/assets/runtimeEndpointReset-0buInzjw.js +0 -149
- package/dist/assets/runtimeEndpointReset-HYSytKO-.css +0 -1
- package/dist/assets/scheduledTaskNavigation-CYozx15H.js +0 -1
- package/dist/assets/sessionChangeSummary-BGisROOB.js +0 -1
- package/dist/assets/sessionChangeSummary-CRYRvpy7.css +0 -1
- package/dist/assets/speechSettingsQueries-CWXTghOr.js +0 -4
- package/dist/assets/src-BFsc_2gs.css +0 -2
- package/dist/assets/types-C9aO7yfx.js +0 -2
- package/dist/assets/useEffectiveDirectory-Bg0LmEqP.js +0 -1
- package/dist/assets/useMobileNavigationStore-hhiMBg5n.js +0 -418
- package/dist/assets/vendor-motion-B4xmxmaP.js +0 -1
- package/dist/assets/vendor-tanstack-react-virtual-B_EO--9t.js +0 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# WeChat text channel
|
|
2
|
+
|
|
3
|
+
This Host-owned channel connects a QR-authorized personal WeChat account to one
|
|
4
|
+
existing Yuri Bot. It uses Tencent's public `openclaw-weixin` iLink wire reference,
|
|
5
|
+
not WorkBuddy OAuth/private proxy APIs, personal-WeChat hooks or the WeChat customer
|
|
6
|
+
service protocol. No OpenClaw runtime or new dependency is installed.
|
|
7
|
+
|
|
8
|
+
## Ownership and UI
|
|
9
|
+
|
|
10
|
+
- `api.js`: fixed HTTPS origin, official-host validation for QR redirects, bounded
|
|
11
|
+
JSON decoding, lossless uint64 message IDs, separate HTTP/business errors.
|
|
12
|
+
- `store.js`: private SQLite binding, platform cursor, incoming dedup receipts,
|
|
13
|
+
ordered outgoing deliveries and process-owner lease.
|
|
14
|
+
- `runtime.js`: QR lifecycle, owner-only admission, bounded output reconciliation,
|
|
15
|
+
retry/ambiguity and shutdown. `routes.js` exposes authenticated settings only.
|
|
16
|
+
- `typing.js`: optional per-binding live typing state, ticket lifetime, bounded
|
|
17
|
+
refresh/backoff and serialized cancellation; no persisted presence or UI state.
|
|
18
|
+
- `assistants/service.channelPage()` is an internal bounded, ascending durable
|
|
19
|
+
output seam. It validates the Bot and uses the contact-store generation. It does
|
|
20
|
+
not expose credentials or replace the contact execution engine.
|
|
21
|
+
- Shared `AssistantChannelsGroup` appears last in each **saved** Bot's settings,
|
|
22
|
+
after scheduled tasks. One labelled **Message channels** group owns its card;
|
|
23
|
+
WeChat is its first channel. It is not a global setting or one search entry per
|
|
24
|
+
dynamic Bot. Web, desktop, hosted mobile and Capacitor configure the active Host
|
|
25
|
+
through `runtimeFetch`; standalone VS Code explicitly returns 501.
|
|
26
|
+
|
|
27
|
+
## Authorization and persistence
|
|
28
|
+
|
|
29
|
+
The QR-confirmed `ilink_user_id` is the only accepted sender. Group messages,
|
|
30
|
+
other senders and messages without a stable platform ID never invoke tools. Each
|
|
31
|
+
bound account maps to exactly one Bot within the Host data directory. The account
|
|
32
|
+
can use that Bot's existing tools and Host permissions; the UI discloses this before
|
|
33
|
+
scanning. This is not a separate remote-execution sandbox.
|
|
34
|
+
|
|
35
|
+
Bindings live under `<yuriDataDir>/weixin/channel.sqlite`. The directory is 0700
|
|
36
|
+
and database is 0600, with SQLite secure-delete enabled. Tokens are **not encrypted
|
|
37
|
+
at rest**; the host OS user must protect its data directory/backups (on Windows,
|
|
38
|
+
OS ACLs remain necessary). They never enter settings/snapshot DTOs, transcript,
|
|
39
|
+
model context, URLs, logs or config sync. QR/verification data stays in memory;
|
|
40
|
+
route responses use `Cache-Control: no-store`, UI Query caches have zero GC retention,
|
|
41
|
+
and QR images are generated locally rather than sent to an external image service.
|
|
42
|
+
|
|
43
|
+
Disconnect aborts local receiving/sending, fences late completions and deletes
|
|
44
|
+
local credentials and pending deliveries; it does not erase Bot history or cancel
|
|
45
|
+
already admitted work. The public reference has no general server-side token
|
|
46
|
+
revocation API, so this is not a promise to revoke the platform's authorization.
|
|
47
|
+
Deleting a Bot also forgets its local connection. Failed revision-checked Bot
|
|
48
|
+
deletion leaves the connection intact.
|
|
49
|
+
|
|
50
|
+
## Delivery semantics
|
|
51
|
+
|
|
52
|
+
Incoming receipt, reply context and platform cursor commit together before calling
|
|
53
|
+
`service.send()`. Namespaced IDs keep admission idempotent across duplicates and
|
|
54
|
+
restarts. Incoming and outgoing work is separate from the long-poll receiver; pending
|
|
55
|
+
plus admitted receipt count applies backpressure at 100, with 20 admissions per pass.
|
|
56
|
+
Each active account has one receiver and one outbound scheduler. The process lease
|
|
57
|
+
renews every 2 seconds and expires after 60 seconds; another process sharing this
|
|
58
|
+
data directory cannot steal a live account. After any network wait, epoch/lease
|
|
59
|
+
checks fence stale writes. Cross-machine copies of credentials/data are unsupported.
|
|
60
|
+
|
|
61
|
+
Binding starts at the current contact tip, so existing history/greetings are not
|
|
62
|
+
sent. Subsequent **public assistant replies**, including App-initiated and background
|
|
63
|
+
task replies, sync to the paired owner. Plain text is sent as text; current cards
|
|
64
|
+
become title/name text, not interactive WeChat cards or deeplinks. Internal settle
|
|
65
|
+
markers are omitted and failures use a safe generic message, never raw tool errors.
|
|
66
|
+
Media input gets a text-only explanation and never invokes tools. Generation reset
|
|
67
|
+
drops queued output from the previous transcript. An already submitted HTTP request
|
|
68
|
+
cannot be recalled, including during disconnect/reset.
|
|
69
|
+
|
|
70
|
+
Replies are split by Unicode code points into at most 3500-character segments;
|
|
71
|
+
stable client IDs and ordered outbox rows survive restart. This is not a server-side
|
|
72
|
+
exactly-once guarantee. An uncertain HTTP result is marked **delivery unknown** and
|
|
73
|
+
blocks later output until the owner explicitly retries. New inbound context may
|
|
74
|
+
unblock a known rejected reply but never automatically retries an unknown send.
|
|
75
|
+
Authentication expiry stays expired until new authorization; receiver network errors
|
|
76
|
+
retry with 1–30 second capped backoff. Users can manually retry other blocked sends.
|
|
77
|
+
The platform's reply-context lifetime and active-push quota are not specified here.
|
|
78
|
+
|
|
79
|
+
Contact execution itself remains process-local. A crash with an admitted request
|
|
80
|
+
does **not** rerun tools; recovery sends an interruption/check-status notice. A crash
|
|
81
|
+
between contact completion and receipt acknowledgement can conservatively produce
|
|
82
|
+
that notice even if some output committed. Completed receipts keep only IDs/states;
|
|
83
|
+
sent outbox rows clear text. Dedup metadata is retained for the binding lifetime and
|
|
84
|
+
removed on disconnect. There is no autonomous contact-run recovery.
|
|
85
|
+
|
|
86
|
+
Shutdown awaits channel operations before closing assistant storage. UI polling is
|
|
87
|
+
limited to the mounted selected Bot (2s QR, 15s connected, no background polling),
|
|
88
|
+
not the composer or global Bot catalog. QR generation reruns only for changed QR
|
|
89
|
+
content and stale runtime mutations cannot overwrite a new Host's cache.
|
|
90
|
+
|
|
91
|
+
## Protocol and verification limits
|
|
92
|
+
|
|
93
|
+
### Typing presence
|
|
94
|
+
|
|
95
|
+
Only live `yuri:contact-turn-start/end` events drive typing, including App-initiated
|
|
96
|
+
or background contact turns whose public replies also sync to WeChat. Binding or
|
|
97
|
+
restarting does not infer activity from persisted receipts/history, and historical
|
|
98
|
+
end events or streaming deltas never start an indicator. A turn already running
|
|
99
|
+
before binding is not backfilled. Overlapping live turn IDs share one indicator;
|
|
100
|
+
the last completion, error or cancellation stops it.
|
|
101
|
+
|
|
102
|
+
The Host obtains a per-user `typing_ticket` through `getconfig`, then calls
|
|
103
|
+
`sendtyping` with status 1 to start/refresh and 2 to cancel. This is native protocol
|
|
104
|
+
presence, not a placeholder text message. Successful tickets stay only in memory
|
|
105
|
+
for at most 24 hours, scoped to the binding epoch and paired peer. A refresh reads
|
|
106
|
+
the latest conversation context. Idle bindings make no typing requests. Each
|
|
107
|
+
active binding has at most one serial typing loop, with one refresh per 8 seconds
|
|
108
|
+
after the preceding request; token deltas and duplicate starts add no requests.
|
|
109
|
+
The cadence and cache duration are Yuri client policy, not a guarantee of WeChat's
|
|
110
|
+
indicator TTL. Missing/rejected tickets and request failures retry with 2–60 second
|
|
111
|
+
capped backoff while the live turn remains active.
|
|
112
|
+
|
|
113
|
+
Typing requests have a 5-second deadline and never block admission or text delivery.
|
|
114
|
+
The end event aborts a pending start/refresh, fences late configuration results and
|
|
115
|
+
serializes a best-effort cancellation before the next turn's start. Cancellation
|
|
116
|
+
uses its own deadline, not the already aborted start signal. Disconnect/deletion
|
|
117
|
+
retires the binding before awaiting cancellation and removing credentials; shutdown
|
|
118
|
+
also awaits cancellation before closing storage/releasing the process lease. A
|
|
119
|
+
lost lease or changed epoch cannot send/cancel presence for another owner. Tickets
|
|
120
|
+
and transient turn tracking are discarded on unbind, expiry or ownership loss.
|
|
121
|
+
Optional presence failures are not surfaced as a broken text channel. Process death
|
|
122
|
+
or a failed cancel cannot guarantee immediate removal in the WeChat client.
|
|
123
|
+
|
|
124
|
+
### QR profile fields
|
|
125
|
+
|
|
126
|
+
The public QR request sends `bot_type` and `local_token_list`; neither its request
|
|
127
|
+
nor confirmation flow exposes nickname/avatar configuration. Do not append guessed
|
|
128
|
+
profile fields or alter QR payloads to claim that WeChat adopts the Yuri Bot's
|
|
129
|
+
profile. `base_info.bot_agent` is observability metadata, not the contact name or
|
|
130
|
+
avatar. There is no public profile-update endpoint in this protocol reference.
|
|
131
|
+
|
|
132
|
+
Reference: https://github.com/Tencent/openclaw-weixin/blob/main/docs/protocol.md
|
|
133
|
+
(protocol baseline 2.4.10; `bot_agent: Yuri`). Public source availability does not
|
|
134
|
+
establish third-party product admission, all-account availability, service SLA,
|
|
135
|
+
unlimited proactive notifications or arbitrary rich-card support.
|
|
136
|
+
|
|
137
|
+
Focused tests cover wire behavior, business errors, QR fencing, owner isolation,
|
|
138
|
+
dedup, restart, conflicting bindings, process lease, shutdown, generation changes,
|
|
139
|
+
unknown delivery, HTTP protection, typing cadence/cancellation/stale completions,
|
|
140
|
+
and real contact-pipeline execution with a fake WeChat service. Real-account
|
|
141
|
+
QR/verification, phone-visible delivery and typing presentation still require
|
|
142
|
+
manual testing; mocks and builds are not evidence of platform acceptance.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
// Wire-format reference: Tencent/openclaw-weixin (MIT), docs/protocol.md.
|
|
4
|
+
// This is a Yuri transport, not an OpenClaw runtime or a WorkBuddy login client.
|
|
5
|
+
const API_ORIGIN = 'https://ilinkai.weixin.qq.com';
|
|
6
|
+
const PROTOCOL_VERSION = '2.4.10';
|
|
7
|
+
const MAX_RESPONSE_BYTES = 2 * 1024 * 1024;
|
|
8
|
+
|
|
9
|
+
export class WeixinError extends Error {
|
|
10
|
+
constructor(code, { ret = null, ambiguous = false } = {}) {
|
|
11
|
+
super(code);
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.ret = ret;
|
|
14
|
+
this.ambiguous = ambiguous;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function weixinOrigin(value = API_ORIGIN) {
|
|
19
|
+
let url;
|
|
20
|
+
try { url = new URL(value.includes('://') ? value : `https://${value}`); } catch { throw new WeixinError('invalid_response'); }
|
|
21
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.port
|
|
22
|
+
|| !url.hostname.endsWith('.weixin.qq.com') || url.pathname !== '/' || url.search || url.hash) {
|
|
23
|
+
throw new WeixinError('invalid_response');
|
|
24
|
+
}
|
|
25
|
+
return url.origin;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function createWeixinAPI({ fetchImpl = fetch } = {}) {
|
|
29
|
+
const request = async (origin, route, { token, body, signal, timeoutMs = 15_000, sending = false, allowEmpty = false } = {}) => {
|
|
30
|
+
const headers = {
|
|
31
|
+
'Content-Type': 'application/json',
|
|
32
|
+
'iLink-App-Id': 'bot',
|
|
33
|
+
'iLink-App-ClientVersion': String(0x02040a),
|
|
34
|
+
};
|
|
35
|
+
if (body !== undefined) {
|
|
36
|
+
headers.AuthorizationType = 'ilink_bot_token';
|
|
37
|
+
headers['X-WECHAT-UIN'] = Buffer.from(String(randomBytes(4).readUInt32BE())).toString('base64');
|
|
38
|
+
}
|
|
39
|
+
if (token) headers.Authorization = `Bearer ${token}`;
|
|
40
|
+
let response;
|
|
41
|
+
try {
|
|
42
|
+
response = await fetchImpl(`${weixinOrigin(origin)}${route}`, {
|
|
43
|
+
method: body === undefined ? 'GET' : 'POST', headers,
|
|
44
|
+
...(body === undefined ? {} : { body: JSON.stringify(token ? {
|
|
45
|
+
...body, base_info: { channel_version: PROTOCOL_VERSION, bot_agent: 'Yuri' },
|
|
46
|
+
} : body) }),
|
|
47
|
+
redirect: 'error',
|
|
48
|
+
signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) : AbortSignal.timeout(timeoutMs),
|
|
49
|
+
});
|
|
50
|
+
} catch {
|
|
51
|
+
if (signal?.aborted) throw new WeixinError('cancelled');
|
|
52
|
+
throw new WeixinError('network_error', { ambiguous: sending });
|
|
53
|
+
}
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
if (response.status === 401 || response.status === 403) throw new WeixinError('auth_expired');
|
|
56
|
+
throw new WeixinError('network_error', { ambiguous: sending && response.status >= 500 });
|
|
57
|
+
}
|
|
58
|
+
let text = '';
|
|
59
|
+
try {
|
|
60
|
+
if (allowEmpty && !response.body) return {};
|
|
61
|
+
const reader = response.body.getReader();
|
|
62
|
+
const chunks = [];
|
|
63
|
+
let size = 0;
|
|
64
|
+
while (true) {
|
|
65
|
+
const { done, value } = await reader.read();
|
|
66
|
+
if (done) break;
|
|
67
|
+
size += value.byteLength;
|
|
68
|
+
if (size > MAX_RESPONSE_BYTES) { await reader.cancel(); throw new Error('response_too_large'); }
|
|
69
|
+
chunks.push(value);
|
|
70
|
+
}
|
|
71
|
+
text = Buffer.concat(chunks).toString('utf8');
|
|
72
|
+
if (allowEmpty && !text.trim()) return {};
|
|
73
|
+
// Weixin IDs are uint64; preserve digits before JSON's number conversion.
|
|
74
|
+
const data = JSON.parse(text.replace(/("message_id"\s*:\s*)(\d+)(?=\s*[,}])/g, '$1"$2"'));
|
|
75
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) throw new Error('invalid_response');
|
|
76
|
+
if (data.ret === -14 || data.errcode === -14) throw new WeixinError('auth_expired');
|
|
77
|
+
if ((data.ret !== undefined && data.ret !== 0) || (data.errcode !== undefined && data.errcode !== 0)) {
|
|
78
|
+
throw new WeixinError(sending ? 'reply_unavailable' : 'upstream_error', { ret: data.ret ?? data.errcode });
|
|
79
|
+
}
|
|
80
|
+
return data;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (error instanceof WeixinError) throw error;
|
|
83
|
+
throw new WeixinError('invalid_response', { ambiguous: sending });
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
getQRCode: (signal, localTokens = []) => request(API_ORIGIN, '/ilink/bot/get_bot_qrcode?bot_type=3', {
|
|
88
|
+
body: { local_token_list: localTokens.slice(0, 10) }, signal,
|
|
89
|
+
}),
|
|
90
|
+
getQRStatus: (origin, qrcode, verifyCode, signal) => request(origin, `/ilink/bot/get_qrcode_status?${new URLSearchParams({
|
|
91
|
+
qrcode, ...(verifyCode ? { verify_code: verifyCode } : {}),
|
|
92
|
+
})}`, { signal, timeoutMs: 40_000 }),
|
|
93
|
+
getUpdates: (binding, signal) => request(binding.base_url, '/ilink/bot/getupdates', {
|
|
94
|
+
token: binding.token, body: { get_updates_buf: binding.cursor }, signal, timeoutMs: 40_000,
|
|
95
|
+
}),
|
|
96
|
+
getConfig: (binding, signal) => request(binding.base_url, '/ilink/bot/getconfig', {
|
|
97
|
+
token: binding.token, signal, timeoutMs: 5000,
|
|
98
|
+
body: { ilink_user_id: binding.peer_id, context_token: binding.context_token || undefined },
|
|
99
|
+
}),
|
|
100
|
+
sendTyping: (binding, ticket, status, signal) => request(binding.base_url, '/ilink/bot/sendtyping', {
|
|
101
|
+
token: binding.token, signal, timeoutMs: 5000, allowEmpty: true,
|
|
102
|
+
body: { ilink_user_id: binding.peer_id, typing_ticket: ticket, status },
|
|
103
|
+
}),
|
|
104
|
+
sendText: (binding, delivery, signal) => request(binding.base_url, '/ilink/bot/sendmessage', {
|
|
105
|
+
token: binding.token, signal, sending: true,
|
|
106
|
+
body: { msg: {
|
|
107
|
+
from_user_id: '', to_user_id: binding.peer_id, client_id: delivery.id,
|
|
108
|
+
message_type: 2, message_state: 2, context_token: binding.context_token || undefined,
|
|
109
|
+
item_list: [{ type: 1, text_item: { text: delivery.text } }],
|
|
110
|
+
} },
|
|
111
|
+
}),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createWeixinAPI, weixinOrigin } from './api.js';
|
|
3
|
+
|
|
4
|
+
const binding = { base_url: 'https://ilinkai.weixin.qq.com', token: 'test-token', peer_id: 'owner', cursor: 'cursor', context_token: 'context' };
|
|
5
|
+
|
|
6
|
+
describe('Weixin wire transport', () => {
|
|
7
|
+
it('uses QR POST, app headers and private local-token hints without bot authorization', async () => {
|
|
8
|
+
const fetchImpl = vi.fn(async () => Response.json({ qrcode: 'opaque', qrcode_img_content: 'https://example.com/qr' }));
|
|
9
|
+
await createWeixinAPI({ fetchImpl }).getQRCode(undefined, ['existing']);
|
|
10
|
+
const [url, init] = fetchImpl.mock.calls[0];
|
|
11
|
+
expect(url).toBe('https://ilinkai.weixin.qq.com/ilink/bot/get_bot_qrcode?bot_type=3');
|
|
12
|
+
expect(init.method).toBe('POST');
|
|
13
|
+
expect(init.headers.Authorization).toBeUndefined();
|
|
14
|
+
expect(init.redirect).toBe('error');
|
|
15
|
+
expect(JSON.parse(init.body)).toEqual({ local_token_list: ['existing'] });
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('preserves uint64 message IDs and passes cursor, owner and context through the text API', async () => {
|
|
19
|
+
const fetchImpl = vi.fn(async (url) => url.endsWith('getupdates')
|
|
20
|
+
? new Response('{"ret":0,"msgs":[{"message_id":18446744073709551615}],"get_updates_buf":"next"}')
|
|
21
|
+
: Response.json({ ret: 0 }));
|
|
22
|
+
const api = createWeixinAPI({ fetchImpl });
|
|
23
|
+
expect((await api.getUpdates(binding)).msgs[0].message_id).toBe('18446744073709551615');
|
|
24
|
+
await api.sendText(binding, { id: 'delivery-id', text: '你好' });
|
|
25
|
+
const [, init] = fetchImpl.mock.calls[1];
|
|
26
|
+
expect(init.headers.Authorization).toBe('Bearer test-token');
|
|
27
|
+
expect(init.headers.AuthorizationType).toBe('ilink_bot_token');
|
|
28
|
+
expect(JSON.parse(init.body)).toMatchObject({
|
|
29
|
+
base_info: { bot_agent: 'Yuri' },
|
|
30
|
+
msg: { client_id: 'delivery-id', to_user_id: 'owner', context_token: 'context', item_list: [{ type: 1, text_item: { text: '你好' } }] },
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('does not treat HTTP 200 with a failed business code as delivered', async () => {
|
|
35
|
+
const api = createWeixinAPI({ fetchImpl: async () => Response.json({ ret: -2, errmsg: 'private upstream body' }) });
|
|
36
|
+
await expect(api.sendText(binding, { id: 'id', text: 'reply' })).rejects.toMatchObject({ code: 'reply_unavailable', ret: -2, ambiguous: false });
|
|
37
|
+
const expired = createWeixinAPI({ fetchImpl: async () => Response.json({ ret: -14 }) });
|
|
38
|
+
await expect(expired.getUpdates(binding)).rejects.toMatchObject({ code: 'auth_expired' });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('requests a per-user ticket and sends start/cancel with authenticated bot metadata', async () => {
|
|
42
|
+
const fetchImpl = vi.fn(async (url) => url.endsWith('getconfig')
|
|
43
|
+
? Response.json({ ret: 0, typing_ticket: 'test-ticket' }) : new Response(null, { status: 204 }));
|
|
44
|
+
const api = createWeixinAPI({ fetchImpl });
|
|
45
|
+
const signal = new AbortController().signal;
|
|
46
|
+
const config = await api.getConfig(binding, signal);
|
|
47
|
+
await api.sendTyping(binding, config.typing_ticket, 1, signal);
|
|
48
|
+
await api.sendTyping(binding, config.typing_ticket, 2);
|
|
49
|
+
expect(fetchImpl.mock.calls.map(([url]) => new URL(url).pathname)).toEqual([
|
|
50
|
+
'/ilink/bot/getconfig', '/ilink/bot/sendtyping', '/ilink/bot/sendtyping',
|
|
51
|
+
]);
|
|
52
|
+
expect(JSON.parse(fetchImpl.mock.calls[0][1].body)).toEqual({
|
|
53
|
+
ilink_user_id: 'owner', context_token: 'context', base_info: { channel_version: '2.4.10', bot_agent: 'Yuri' },
|
|
54
|
+
});
|
|
55
|
+
for (const [index, status] of [[1, 1], [2, 2]]) {
|
|
56
|
+
const init = fetchImpl.mock.calls[index][1];
|
|
57
|
+
expect(init.headers.Authorization).toBe('Bearer test-token');
|
|
58
|
+
expect(JSON.parse(init.body)).toMatchObject({ ilink_user_id: 'owner', typing_ticket: 'test-ticket', status });
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('does not ignore failed typing business codes or accept an empty ticket response as valid JSON', async () => {
|
|
63
|
+
const failed = createWeixinAPI({ fetchImpl: async () => Response.json({ ret: -2 }) });
|
|
64
|
+
await expect(failed.sendTyping(binding, 'ticket', 1)).rejects.toMatchObject({ code: 'upstream_error' });
|
|
65
|
+
const empty = createWeixinAPI({ fetchImpl: async () => new Response('') });
|
|
66
|
+
await expect(empty.getConfig(binding)).rejects.toMatchObject({ code: 'invalid_response' });
|
|
67
|
+
await expect(empty.sendTyping(binding, 'ticket', 2)).resolves.toEqual({});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('distinguishes uncertain send failures and never exposes upstream credentials', async () => {
|
|
71
|
+
const api = createWeixinAPI({ fetchImpl: async () => { throw new Error('test-token context secret'); } });
|
|
72
|
+
await expect(api.sendText(binding, { id: 'id', text: 'reply' })).rejects.toMatchObject({ message: 'network_error', ambiguous: true });
|
|
73
|
+
await expect(api.getUpdates(binding)).rejects.toMatchObject({ ambiguous: false });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it.each(['http://ilinkai.weixin.qq.com', 'https://evil.example', 'https://ilinkai.weixin.qq.com.evil.example',
|
|
77
|
+
'https://user:password@ilinkai.weixin.qq.com', 'https://ilinkai.weixin.qq.com:8443', 'https://ilinkai.weixin.qq.com/path'])('rejects credential redirects to %s', (url) => {
|
|
78
|
+
expect(() => weixinOrigin(url)).toThrow('invalid_response');
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const failureStatus = (code) => code === 'not_found' ? 404
|
|
2
|
+
: ['account_in_use', 'already_bound', 'channel_in_use'].includes(code) ? 409
|
|
3
|
+
: ['network_error', 'upstream_error', 'invalid_response'].includes(code) ? 502 : 400;
|
|
4
|
+
|
|
5
|
+
/** Runs behind the Host's existing authenticated Yuri route gate. No public webhook. */
|
|
6
|
+
export function registerWeixinRoutes(app, runtime) {
|
|
7
|
+
const root = '/api/yuri/assistants/:assistantID/weixin';
|
|
8
|
+
const respond = (res, work) => {
|
|
9
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
10
|
+
Promise.resolve().then(work).then((body) => res.json(body)).catch((error) => {
|
|
11
|
+
const allowed = new Set(['not_found', 'account_in_use', 'already_bound', 'channel_in_use', 'network_error',
|
|
12
|
+
'upstream_error', 'invalid_response', 'validation_error', 'auth_expired', 'cancelled']);
|
|
13
|
+
const code = allowed.has(error?.code) ? error.code : 'channel_error';
|
|
14
|
+
// Never return upstream bodies, credentials or QR-status payloads as errors.
|
|
15
|
+
res.status(failureStatus(code)).json({ error: code });
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
app.get(root, (req, res) => respond(res, () => runtime.status(req.params.assistantID)));
|
|
19
|
+
app.post(`${root}/login`, (req, res) => respond(res, () => runtime.startLogin(req.params.assistantID, req.body?.language)));
|
|
20
|
+
app.post(`${root}/verify`, (req, res) => respond(res, () => runtime.verify(req.params.assistantID, req.body?.code)));
|
|
21
|
+
app.post(`${root}/retry`, (req, res) => respond(res, () => runtime.retry(req.params.assistantID)));
|
|
22
|
+
app.delete(root, (req, res) => respond(res, () => runtime.disconnect(req.params.assistantID)));
|
|
23
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import request from 'supertest';
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { registerWeixinRoutes } from './routes.js';
|
|
5
|
+
|
|
6
|
+
describe('authenticated Bot WeChat routes', () => {
|
|
7
|
+
it('keeps the existing authentication boundary, has explicit routes and no-store QR responses', async () => {
|
|
8
|
+
const app = express();
|
|
9
|
+
app.use(express.json());
|
|
10
|
+
app.use('/api/yuri', (req, res, next) => req.headers.authorization === 'Bearer test-owner' ? next() : res.sendStatus(401));
|
|
11
|
+
const runtime = {
|
|
12
|
+
status: vi.fn(() => ({ status: 'disconnected', error: null })),
|
|
13
|
+
startLogin: vi.fn(async () => ({ status: 'waiting', qrCode: 'https://example.com/scan', error: null })),
|
|
14
|
+
verify: vi.fn(() => ({ status: 'verify', error: null })),
|
|
15
|
+
retry: vi.fn(() => ({ status: 'connected', error: null })),
|
|
16
|
+
disconnect: vi.fn(() => ({ status: 'disconnected', error: null })),
|
|
17
|
+
};
|
|
18
|
+
registerWeixinRoutes(app, runtime);
|
|
19
|
+
const root = '/api/yuri/assistants/bot/weixin';
|
|
20
|
+
await request(app).post(`${root}/login`).send({}).expect(401);
|
|
21
|
+
expect(runtime.startLogin).not.toHaveBeenCalled();
|
|
22
|
+
const response = await request(app).post(`${root}/login`).auth('test-owner', { type: 'bearer' }).send({ language: 'zh-CN' }).expect(200);
|
|
23
|
+
expect(response.headers['cache-control']).toBe('no-store');
|
|
24
|
+
expect(response.body).toMatchObject({ status: 'waiting' });
|
|
25
|
+
expect(runtime.startLogin).toHaveBeenCalledWith('bot', 'zh-CN');
|
|
26
|
+
await request(app).post(`${root}/verify`).auth('test-owner', { type: 'bearer' }).send({ code: '123456' }).expect(200);
|
|
27
|
+
expect(runtime.verify).toHaveBeenCalledWith('bot', '123456');
|
|
28
|
+
await request(app).delete(root).auth('test-owner', { type: 'bearer' }).expect(200);
|
|
29
|
+
expect(runtime.disconnect).toHaveBeenCalledWith('bot');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('redacts untrusted errors and reports binding conflicts as conflicts', async () => {
|
|
33
|
+
const app = express();
|
|
34
|
+
registerWeixinRoutes(app, { status: () => { throw new Error('credential=private-token'); },
|
|
35
|
+
startLogin: () => { throw Object.assign(new Error('private upstream response'), { code: 'account_in_use' }); } });
|
|
36
|
+
const response = await request(app).get('/api/yuri/assistants/bot/weixin').expect(400);
|
|
37
|
+
expect(response.body).toEqual({ error: 'channel_error' });
|
|
38
|
+
const conflict = await request(app).post('/api/yuri/assistants/bot/weixin/login').expect(409);
|
|
39
|
+
expect(conflict.body).toEqual({ error: 'account_in_use' });
|
|
40
|
+
});
|
|
41
|
+
});
|