@yuriai/web 0.2.27-beta.8 → 0.2.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AgentAvatar-BJ42lGZD.js → AgentAvatar-BybF1ayP.js} +1 -1
- package/dist/assets/AssistantContactStatus-BwpxTn0d.js +3 -0
- package/dist/assets/{AssistantUnreadBadge-QwhBfXpC.js → AssistantUnreadBadge-DqThZdCe.js} +1 -1
- package/dist/assets/{AssistantView-D7ryIKL0.js → AssistantView-DPUDCXoY.js} +1 -1
- package/dist/assets/{DiagramView-ERrGEBDp.js → DiagramView-CHVLoYrV.js} +1 -1
- package/dist/assets/{FadeInOnReveal-Bu2GvaM9.js → FadeInOnReveal-Cj3JXYvE.js} +1 -1
- package/dist/assets/{GuiPluginSurface-MzQgEZNr.js → GuiPluginSurface-CBZYeKHb.js} +1 -1
- package/dist/assets/{GuiPluginWindow-DZMmlQzx.js → GuiPluginWindow-_Z5wycnH.js} +1 -1
- package/dist/assets/{Icon-Dj4CCqCP.js → Icon-CeRMtJa8.js} +1 -1
- package/dist/assets/{ImageLoadingPlaceholder-BnFXgUuO.js → ImageLoadingPlaceholder-DjLaKB4o.js} +1 -1
- package/dist/assets/{LoadingImage-PBnivDKv.js → LoadingImage-DG3otL5V.js} +1 -1
- package/dist/assets/MarkdownRenderer-C8rv6z7p.js +2 -0
- package/dist/assets/{MarkdownRendererImpl-CfyXL4rg.js → MarkdownRendererImpl-_plqOlsV.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-BGadklK1.js → MarkstreamRendererImpl-bs8HZ4Ra.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-DqajQdB4.js → MobileDetailNavigation-SeT764Ps.js} +1 -1
- package/dist/assets/{MobileResizableSheet-BvdUgwA3.js → MobileResizableSheet-BY1-oo_E.js} +1 -1
- package/dist/assets/{MobileShareBridge-3oPoYnry.js → MobileShareBridge-Dw8gLtJD.js} +2 -2
- package/dist/assets/MobileTabPageHeader-EsrOCLyg.js +2 -0
- package/dist/assets/{MultiRunWindow-yhs0Ih5_.js → MultiRunWindow-C-Qw_g7N.js} +1 -1
- package/dist/assets/{OnboardingScreen-Bi1VWFQC.js → OnboardingScreen-CGqabMbp.js} +1 -1
- package/dist/assets/{OverlayScrollbar-BBDwGvGO.js → OverlayScrollbar-AGSWQKg-.js} +1 -1
- package/dist/assets/{SettingsView-BSf-SJUA.js → SettingsView-BLfFnnnX.js} +14 -14
- package/dist/assets/{SettingsWindow-BvSXVMTm.js → SettingsWindow-lyYO8Byy.js} +1 -1
- package/dist/assets/{TerminalView-DhL01N7e.js → TerminalView-OHqpkHzz.js} +1 -1
- package/dist/assets/{ToolOutputDialog-C8lnH4Ky.js → ToolOutputDialog-DU4Pb1s0.js} +1 -1
- package/dist/assets/{YuriLogo-D8asj1CS.js → YuriLogo-Bb6yHagP.js} +1 -1
- package/dist/assets/{appThemeRegistry-C-maYSdv.js → appThemeRegistry-9j-rCSlE.js} +1 -1
- package/dist/assets/{button-vXOdzd8x.js → button-Bjh2BSXh.js} +1 -1
- package/dist/assets/{capgoAdapter-DJ_h2x5D.js → capgoAdapter-DERfot6h.js} +1 -1
- package/dist/assets/{collapsible-DwDQs3Wa.js → collapsible-BEAHoxNi.js} +1 -1
- package/dist/assets/{context-menu-BabBujQ-.js → context-menu-BxLcot-3.js} +1 -1
- package/dist/assets/device-BcRP6Tjd.js +2 -0
- package/dist/assets/{diagram-HwgrQxY5.js → diagram-CXVm2vzI.js} +1 -1
- package/dist/assets/{dialog-Dnf626tb.js → dialog-nshKUSE5.js} +1 -1
- package/dist/assets/{dropdown-menu.styles-CBc_a-Nv.js → dropdown-menu.styles-M78xpvb2.js} +1 -1
- package/dist/assets/{es-BQkO-Odr.js → es-N9ZkQwG9.js} +2 -2
- package/dist/assets/fileMentionAutocompleteState-BZJqfgae.js +2 -0
- package/dist/assets/{fileMentionTouchSelection-CKPnEetl.js → fileMentionTouchSelection-B9NbPN9D.js} +2 -2
- package/dist/assets/{fileReferenceActions-g7KZLi_G.js → fileReferenceActions-CrIAce3K.js} +1 -1
- package/dist/assets/{fr-C852roK5.js → fr-CIGqV46N.js} +2 -2
- package/dist/assets/{gitApi-CVq5oKCd.js → gitApi-CY3D5CF0.js} +1 -1
- package/dist/assets/{gitApiHttp-BYOIbYIh.js → gitApiHttp-B7vYwgBh.js} +4 -4
- package/dist/assets/{gui-M_Rbwkyu.js → gui-CJjEj3l4.js} +1 -1
- package/dist/assets/host-CnVx34Dh.js +1 -0
- package/dist/assets/{image-loading-D5UhMj7Z.js → image-loading-D6kOgU4w.js} +1 -1
- package/dist/assets/{input-BtM712b1.js → input-3Re4pmHm.js} +1 -1
- package/dist/assets/insertionBoundaries-DK7XYF8d.js +1 -0
- package/dist/assets/{ja-BqC39qK6.js → ja-DAhnTq6V.js} +2 -2
- package/dist/assets/{ko-BMaChAWh.js → ko-FbMgNKcI.js} +2 -2
- package/dist/assets/main-B_THXYMs.js +2 -0
- package/dist/assets/main-CpcudEZb.js +169 -0
- package/dist/assets/{markdownHeightCache-Bf8iisO4.js → markdownHeightCache-DVWGXtAX.js} +1 -1
- package/dist/assets/{mcpQueries-DpXqegX5.js → mcpQueries-CdOYmUdO.js} +1 -1
- package/dist/assets/miniChat-DxZiTnAZ.js +2 -0
- package/dist/assets/mobile-BJuATiaC.js +2 -0
- package/dist/assets/{mobileBackNavigation-DZcI7aZg.js → mobileBackNavigation-CgZndzFA.js} +1 -1
- package/dist/assets/{multirun-hzspPepd.js → multirun-BlaYsQi2.js} +1 -1
- package/dist/assets/{native-H7K64Ulc.js → native-BYMhr-xH.js} +1 -1
- package/dist/assets/{native-config-CddZtLQ1.js → native-config-BpsFKLGl.js} +1 -1
- package/dist/assets/{persistence-BT8045Ue.js → persistence-CWuLIq1J.js} +2 -2
- package/dist/assets/{pl-Ubs8p28T.js → pl-DzX0cbiQ.js} +2 -2
- package/dist/assets/{projectMeta-CEf0QPmD.js → projectMeta-CnXHTolN.js} +1 -1
- package/dist/assets/{pt-BR-8rAOjJrs.js → pt-BR-C5yvwyDK.js} +2 -2
- package/dist/assets/queue-abort-optimistic-DCLBpirg.js +1 -0
- package/dist/assets/{readiness-Dyr7314z.js → readiness-U16Qor79.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-n-nhgy1V.js +2 -0
- package/dist/assets/renderMobileApp-DBj_7RlD.js +28 -0
- package/dist/assets/{runtimeConfig-B8VHHNxj.js → runtimeConfig-BBgkLVr_.js} +1 -1
- package/dist/assets/runtimeEndpointReset-BvSQVFfx.js +149 -0
- package/dist/assets/{scheduledTaskNavigation-Zm87Nydi.js → scheduledTaskNavigation-EomDNVu2.js} +1 -1
- package/dist/assets/sessionLookup-C_CCp7MJ.js +1 -0
- package/dist/assets/{sortable-tabs-strip-D4pVoodN.js → sortable-tabs-strip-p16Pn6Zz.js} +1 -1
- package/dist/assets/{speechSettingsQueries-RlCLMBtr.js → speechSettingsQueries-CBSEAKyj.js} +2 -2
- package/dist/assets/src-u-YDfCVw.css +2 -0
- package/dist/assets/{store-ME7oHni1.js → store-DVfZQktm.js} +4 -3
- package/dist/assets/{terminalApi-BSaclMDJ.js → terminalApi-rl9mZAlB.js} +1 -1
- package/dist/assets/{textarea-B98rsLs7.js → textarea-C6VQ7dHH.js} +1 -1
- package/dist/assets/{tooltip-B9810jbK.js → tooltip-Dnc6GA-X.js} +1 -1
- package/dist/assets/types-DnZw0gLD.js +2 -0
- package/dist/assets/{uk-LzwzUApL.js → uk-zbDcUpBy.js} +2 -2
- package/dist/assets/{useAppFontEffects-D2C1sBYM.js → useAppFontEffects-CEgDiZHu.js} +49 -49
- package/dist/assets/{useAssistantUIStore-TUN_ycy5.js → useAssistantUIStore-CfaQV3ID.js} +1 -1
- package/dist/assets/useDesktopWindowControlsLayout-B2o4IFmd.js +1 -0
- package/dist/assets/useEffectiveDirectory-BOYMJ6k7.js +1 -0
- package/dist/assets/{useFontPreferences-BlhlCJCX.js → useFontPreferences-DeqW9nRx.js} +1 -1
- package/dist/assets/useMobileNavigationStore-DlvrZQ49.js +17 -0
- package/dist/assets/{useUIStore-DRx6OgCp.js → useUIStore-C6CE42oh.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-D093jNsH.js → useWorkerHighlightedLines-EcJThS4x.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-BBOP6WNx.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-D-FVCeks.js → zh-CN-BHRJ7CF3.js} +2 -2
- package/dist/assets/{zh-TW-B9iH_NXL.js → zh-TW-BFI_YFd-.js} +2 -2
- package/dist/index.html +12 -12
- package/dist/mini-chat.html +12 -12
- package/dist/mobile.html +12 -12
- package/package.json +1 -1
- package/server/index.js +2 -145
- package/server/lib/assistants/DOCUMENTATION.md +63 -10
- 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 +128 -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 +52 -14
- package/server/lib/assistants/channels/PROTOCOLS.md +23 -1
- package/server/lib/assistants/channels/dingtalk-chat-adapter.js +19 -7
- package/server/lib/assistants/channels/dingtalk-chat-adapter.test.js +8 -0
- package/server/lib/assistants/channels/routes.js +12 -0
- package/server/lib/assistants/channels/routes.test.js +34 -0
- package/server/lib/assistants/channels/runtime.js +117 -26
- package/server/lib/assistants/channels/runtime.test.js +179 -5
- package/server/lib/assistants/channels/sdk-adapters.js +15 -3
- package/server/lib/assistants/channels/sdk-adapters.test.js +17 -0
- package/server/lib/assistants/channels/store.js +9 -6
- package/server/lib/assistants/channels/store.test.js +21 -11
- package/server/lib/assistants/channels/transport.js +2 -1
- package/server/lib/assistants/channels/wecom-chat-adapter.js +16 -2
- package/server/lib/assistants/channels/wecom-chat-adapter.test.js +21 -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 +80 -34
- package/server/lib/assistants/harness.test.js +68 -20
- package/server/lib/assistants/resource-reference.integration.test.js +284 -0
- package/server/lib/assistants/routes.js +0 -3
- package/server/lib/assistants/service.js +116 -69
- package/server/lib/assistants/service.test.js +31 -17
- package/server/lib/assistants/weixin/DOCUMENTATION.md +34 -9
- package/server/lib/assistants/weixin/api.js +43 -1
- package/server/lib/assistants/weixin/api.test.js +28 -0
- package/server/lib/assistants/weixin/chat-adapter.js +8 -2
- package/server/lib/assistants/weixin/inbound.js +5 -3
- package/server/lib/assistants/weixin/inbound.test.js +20 -0
- package/server/lib/assistants/weixin/runtime.js +27 -18
- package/server/lib/assistants/weixin/runtime.test.js +36 -0
- package/server/lib/assistants/weixin/store.js +8 -4
- package/server/lib/assistants/weixin/store.test.js +21 -0
- package/server/lib/assistants/yuri-project.http.test.js +9 -3
- 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 +9 -0
- 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-dtkObamV.js +0 -3
- package/dist/assets/MarkdownRenderer-BajF4gUU.js +0 -2
- package/dist/assets/MobileTabPageHeader-B6cRyIRH.js +0 -2
- package/dist/assets/device-BjRYYXNT.js +0 -2
- package/dist/assets/host-BW3FEJdU.js +0 -1
- package/dist/assets/insertionBoundaries-Dx3WAY6i.js +0 -1
- package/dist/assets/main-9uP2z1qT.js +0 -2
- package/dist/assets/main-Mey7bCWf.js +0 -169
- package/dist/assets/miniChat-DqZvVkme.js +0 -2
- package/dist/assets/mobile-DXAWjYcN.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-DoOq8Cuo.js +0 -2
- package/dist/assets/renderMobileApp-TTxtOb8b.js +0 -28
- package/dist/assets/runtimeEndpointReset-BC6XWntz.js +0 -149
- package/dist/assets/sessionLookup-De53jDwM.js +0 -1
- package/dist/assets/src-lE4uqaHS.css +0 -2
- package/dist/assets/types-DFf9vd1b.js +0 -2
- package/dist/assets/useDesktopWindowControlsLayout-BjKaHN0x.js +0 -1
- package/dist/assets/useEffectiveDirectory-TEvyiQSC.js +0 -1
- package/dist/assets/useMobileNavigationStore-DTvJV9s-.js +0 -23
- package/dist/assets/vendor-opencode-client-ZeOZ4Efz.js +0 -23
- package/dist/assets/vendor-solid-js-9wmPZH9g.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
|
@@ -55,7 +55,8 @@ The seam is deliberately narrow so an SDK upgrade changes only the bridge:
|
|
|
55
55
|
|
|
56
56
|
`service.channelPage()` is the internal bounded, ascending public-output seam. It
|
|
57
57
|
validates the Bot, uses the contact-store generation and returns only assistant
|
|
58
|
-
rows
|
|
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.
|
|
59
60
|
|
|
60
61
|
## Runtime API
|
|
61
62
|
|
|
@@ -67,6 +68,8 @@ createAssistantChannelsRuntime({
|
|
|
67
68
|
|
|
68
69
|
- `status(assistantID, provider)` — sync read; validates the Bot first.
|
|
69
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.
|
|
70
73
|
- `transfer(assistantID, provider, input)` — explicitly move a local binding using
|
|
71
74
|
`{ sourceAssistantID, revision }`, without returning or re-entering its secret.
|
|
72
75
|
- `retry(assistantID, provider)` — explicit reconnect only.
|
|
@@ -83,16 +86,31 @@ createAssistantChannelsRuntime({
|
|
|
83
86
|
| PUT | same | save + connect |
|
|
84
87
|
| POST | same `/retry` | reconnect without resending unknown output |
|
|
85
88
|
| POST | same `/transfer` | confirmed local rebind with source revision check |
|
|
89
|
+
| POST | same `/discover` | bounded, abortable user-ID discovery before Save |
|
|
86
90
|
| DELETE | same | disconnect |
|
|
87
91
|
|
|
88
|
-
Save input is `{ clientID, clientSecret?, ownerID
|
|
89
|
-
`ownerID`
|
|
90
|
-
|
|
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
|
|
91
97
|
requires `clientSecret`; an update with the same `clientID` and an empty or omitted
|
|
92
98
|
secret keeps the stored one. A new `clientID` requires a new secret.
|
|
93
99
|
Responses are `Cache-Control: no-store` and contain only safe error codes — no
|
|
94
100
|
upstream bodies, secrets or routing targets.
|
|
95
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
|
+
|
|
96
114
|
Status shape:
|
|
97
115
|
|
|
98
116
|
```json
|
|
@@ -144,7 +162,7 @@ Adapters are injected by provider key and must implement exactly:
|
|
|
144
162
|
```js
|
|
145
163
|
{
|
|
146
164
|
connect({ config, signal, onReady, onMessage, onError }): Promise<void>,
|
|
147
|
-
send({ config, target, text, id, signal }): Promise<void>,
|
|
165
|
+
send({ config, target, text, image?, id, signal, beforeSend? }): Promise<void>,
|
|
148
166
|
}
|
|
149
167
|
```
|
|
150
168
|
|
|
@@ -164,6 +182,22 @@ Adapters are injected by provider key and must implement exactly:
|
|
|
164
182
|
user-controlled URL. An abort after submission must reject with `ambiguous: true`
|
|
165
183
|
so the row becomes `unknown` instead of being retried.
|
|
166
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.
|
|
167
201
|
|
|
168
202
|
## Authorization and persistence
|
|
169
203
|
|
|
@@ -228,7 +262,7 @@ removes all three rows, receipts and deliveries in one transaction.
|
|
|
228
262
|
without a new slot, even when the backlog is full.
|
|
229
263
|
- **Isolation:** each account has one receiver, one serial inbound worker and one
|
|
230
264
|
serial outbound scheduler. A slow Bot cannot block another account.
|
|
231
|
-
- **Output source:**
|
|
265
|
+
- **Output source:** externally eligible public assistant replies, including
|
|
232
266
|
background replies, come from `channelPage`. Binding starts at the current
|
|
233
267
|
contact tip, so previous history/greetings are not sent. Internal settle markers
|
|
234
268
|
are omitted; failures use a safe generic message.
|
|
@@ -236,8 +270,11 @@ removes all three rows, receipts and deliveries in one transaction.
|
|
|
236
270
|
go only to the channel that admitted the original input. Its persisted contact
|
|
237
271
|
`turnID` is the reserved `channel:*`/`weixin:*` receipt ID, and exact receipt
|
|
238
272
|
ownership by binding epoch gates delivery; another channel never broadcasts it.
|
|
239
|
-
|
|
240
|
-
|
|
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.
|
|
241
278
|
Each enterprise receipt keeps its own private reply target, so a later sender
|
|
242
279
|
cannot redirect an earlier reply. The inbox target column is added in place for
|
|
243
280
|
existing databases; legacy receipts without a target and without a fixed owner
|
|
@@ -249,11 +286,12 @@ removes all three rows, receipts and deliveries in one transaction.
|
|
|
249
286
|
- **Unknown delivery:** a crash or abort during `sending`, or an ambiguous adapter
|
|
250
287
|
error, marks the row `unknown`. It is never automatically resent and status
|
|
251
288
|
reports `delivery_unknown`. `retry` only reconnects and does not clear it.
|
|
252
|
-
Definitively failed rows may be retried explicitly
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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.
|
|
257
295
|
- **Reconnect:** connection failures retry with 1–30 second capped exponential
|
|
258
296
|
backoff. Authentication failure and SDK `connection_replaced` become a sticky
|
|
259
297
|
`error` until an explicit save or retry, so bad credentials or mutual-kick loops
|
|
@@ -278,7 +316,7 @@ removes all three rows, receipts and deliveries in one transaction.
|
|
|
278
316
|
|
|
279
317
|
## Not in this layer
|
|
280
318
|
|
|
281
|
-
Live typing/presence, platform media download, template cards, interactive
|
|
319
|
+
Live typing/presence, inbound platform media download, template cards, interactive
|
|
282
320
|
callbacks and per-provider protocol routing are intentionally absent. Those belong
|
|
283
321
|
to adapters or a shared SDK. This layer also does not promise server-side
|
|
284
322
|
exactly-once delivery or platform token revocation.
|
|
@@ -22,7 +22,7 @@ runtime resolution fallback.
|
|
|
22
22
|
|
|
23
23
|
`transport.js` remains the owner of the small HTTP helpers
|
|
24
24
|
(`channelError`, `requestJSON`, `officialURL`). Channel adapters use
|
|
25
|
-
`requestJSON` for
|
|
25
|
+
`requestJSON` for documented outbound REST calls (JSON or multipart) and do **not** use the
|
|
26
26
|
removed `socketLoop`; no adapter opens a raw WebSocket or decodes protobuf.
|
|
27
27
|
|
|
28
28
|
## Feishu
|
|
@@ -50,6 +50,12 @@ Wire evidence: `@larksuite/channel@0.7.1` and
|
|
|
50
50
|
short row IDs verbatim and hashes longer ones to 40 hex characters.
|
|
51
51
|
`tenant_access_token/internal` uses `{app_id, app_secret}` and caches until
|
|
52
52
|
`expire - 180s`.
|
|
53
|
+
- Image output first uploads multipart `image_type=message` and `image` to
|
|
54
|
+
`POST /open-apis/im/v1/images`, then sends `msg_type: image` with
|
|
55
|
+
`content: {"image_key": ...}` and the same durable UUID policy. The app needs
|
|
56
|
+
`im:resource` or `im:resource:upload` in addition to message-send permission.
|
|
57
|
+
Upload failure never counts as a submitted chat message.
|
|
58
|
+
Reference: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/image/create
|
|
53
59
|
|
|
54
60
|
ACK durability: the Chat adapter's normalized `message` path is not awaited by
|
|
55
61
|
the vendor dispatcher, so it cannot gate the ACK. `sdk-adapters.js` therefore
|
|
@@ -115,6 +121,11 @@ Wire evidence: official `https://github.com/WecomTeam/aibot-node-sdk`,
|
|
|
115
121
|
outbox as sent (platform accepted, not proof the user read it). Nonzero ACKs are
|
|
116
122
|
definite failures; timeout, cancellation or disconnection after submission are
|
|
117
123
|
`delivery_unknown` and are never automatically resent.
|
|
124
|
+
- Native images use public `uploadMedia(buffer, {type:'image', filename})` and
|
|
125
|
+
`sendMediaMessage(chatid, 'image', media_id)` from the installed official SDK.
|
|
126
|
+
The SDK owns init/chunk/finish and the final message ACK; Yuri does not write
|
|
127
|
+
its own chunk framing. Local-WebSocket tests exercise the full SDK upload plus
|
|
128
|
+
final-ACK wait. Real-account acceptance/quotas still require platform testing.
|
|
118
129
|
- A configured owner fixes the private recipient; otherwise the runtime's private
|
|
119
130
|
durable `target.userID` supplies it. Missing recipients fail before sending.
|
|
120
131
|
- Incoming messages preserve `msgid` for durable dedup, use standard Chat `Message`
|
|
@@ -129,6 +140,17 @@ Wire evidence: official `https://github.com/WecomTeam/aibot-node-sdk`,
|
|
|
129
140
|
|
|
130
141
|
## DingTalk
|
|
131
142
|
|
|
143
|
+
Image output uploads multipart `type=image`/`media` to the official legacy
|
|
144
|
+
`https://oapi.dingtalk.com/media/upload` endpoint, then uses the existing private
|
|
145
|
+
batch-send API with `msgKey: sampleImageMsg` and `msgParam: {photoURL: media_id}`.
|
|
146
|
+
The legacy upload API requires the access token in its query; it is ephemeral,
|
|
147
|
+
never persisted/logged or included in a transcript/error. Generated local images
|
|
148
|
+
need no publicly hosted URL. Platform size/format/permission failures remain
|
|
149
|
+
explicit delivery failures rather than a false text-only success. No automatic
|
|
150
|
+
lossy resize, new image dependency or public image-hosting service is introduced.
|
|
151
|
+
References: https://developers.dingtalk.com/document/app/upload-media-files and
|
|
152
|
+
https://open.dingtalk.com/document/orgapp/types-of-messages-sent-by-robots
|
|
153
|
+
|
|
132
154
|
Wire evidence: `dingtalk-stream@2.1.5` `dist/client.mjs` and
|
|
133
155
|
`src/client.ts` of `open-dingtalk/dingtalk-stream-sdk-nodejs`; OpenAPI metadata
|
|
134
156
|
from `@alicloud/dingtalk@2.2.48` (`robot_1_0`, `oauth2_1_0`).
|
|
@@ -423,11 +423,11 @@ export class DingTalkChatAdapter {
|
|
|
423
423
|
}
|
|
424
424
|
}
|
|
425
425
|
|
|
426
|
-
async send({ config, target, text, signal } = {}) {
|
|
426
|
+
async send({ config, target, text, image, signal, beforeSend } = {}) {
|
|
427
427
|
const credentials = credentialsFrom(config);
|
|
428
428
|
const userId = config.ownerID || target?.userID;
|
|
429
429
|
if (!nonEmptyString(userId)) throw channelError('invalid_response');
|
|
430
|
-
await this._sendText({ credentials, userId, text: typeof text === 'string' ? text : '', signal });
|
|
430
|
+
await this._sendText({ credentials, userId, text: typeof text === 'string' ? text : '', image, signal, beforeSend });
|
|
431
431
|
}
|
|
432
432
|
|
|
433
433
|
// ── internals ──────────────────────────────────────────────────────────
|
|
@@ -565,14 +565,26 @@ export class DingTalkChatAdapter {
|
|
|
565
565
|
return json.accessToken;
|
|
566
566
|
}
|
|
567
567
|
|
|
568
|
-
async _sendText({ credentials, userId, text, signal } = {}) {
|
|
568
|
+
async _sendText({ credentials, userId, text, image, signal, beforeSend } = {}) {
|
|
569
569
|
const token = await this._accessToken(credentials, { signal });
|
|
570
|
+
let mediaID;
|
|
571
|
+
if (image) {
|
|
572
|
+
const form = new FormData();
|
|
573
|
+
form.set('type', 'image');
|
|
574
|
+
form.set('media', new Blob([image.buffer], { type: image.mime }), image.filename);
|
|
575
|
+
const uploaded = await requestJSON(`https://oapi.dingtalk.com/media/upload?${new URLSearchParams({ access_token: token, type: 'image' })}`, {
|
|
576
|
+
body: form, signal, fetchImpl: this.fetchImpl,
|
|
577
|
+
});
|
|
578
|
+
if (uploaded?.errcode !== 0 || !nonEmptyString(uploaded?.media_id)) throw channelError('delivery_failed');
|
|
579
|
+
mediaID = uploaded.media_id;
|
|
580
|
+
}
|
|
581
|
+
beforeSend?.();
|
|
570
582
|
const json = await requestJSON(`${DINGTALK_ORIGIN}${BATCH_SEND_PATH}`, {
|
|
571
583
|
body: {
|
|
572
584
|
robotCode: credentials.clientId,
|
|
573
585
|
userIds: [userId],
|
|
574
|
-
msgKey: 'sampleText',
|
|
575
|
-
msgParam: JSON.stringify({ content: text }),
|
|
586
|
+
msgKey: image ? 'sampleImageMsg' : 'sampleText',
|
|
587
|
+
msgParam: JSON.stringify(image ? { photoURL: mediaID } : { content: text }),
|
|
576
588
|
},
|
|
577
589
|
headers: { 'x-acs-dingtalk-access-token': token },
|
|
578
590
|
signal,
|
|
@@ -618,7 +630,7 @@ export function createDingtalkSdkAdapter(options = {}) {
|
|
|
618
630
|
}
|
|
619
631
|
},
|
|
620
632
|
|
|
621
|
-
async send({ config, target, text, signal } = {}) {
|
|
633
|
+
async send({ config, target, text, image, signal, beforeSend } = {}) {
|
|
622
634
|
if (!config) throw channelError('invalid_response');
|
|
623
635
|
const adapter = new DingTalkChatAdapter({
|
|
624
636
|
...options,
|
|
@@ -627,7 +639,7 @@ export function createDingtalkSdkAdapter(options = {}) {
|
|
|
627
639
|
ownerId: config.ownerID,
|
|
628
640
|
tokenCache: tokens,
|
|
629
641
|
});
|
|
630
|
-
await adapter.send({ config, target, text, signal });
|
|
642
|
+
await adapter.send({ config, target, text, image, signal, beforeSend });
|
|
631
643
|
},
|
|
632
644
|
};
|
|
633
645
|
}
|
|
@@ -92,6 +92,14 @@ afterEach(() => {
|
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
describe('dingtalk Chat SDK adapter', () => {
|
|
95
|
+
it('uploads local image bytes and sends sampleImageMsg only to the original private user', async () => {
|
|
96
|
+
const fetchImpl = vi.fn(async (url) => Response.json(String(url).includes('accessToken') ? { accessToken: 'token', expireIn: 7200 }
|
|
97
|
+
: String(url).includes('/media/upload') ? { errcode: 0, media_id: '@uploaded' } : {}));
|
|
98
|
+
const bridge = createDingtalkSdkAdapter({ fetchImpl });
|
|
99
|
+
await bridge.send({ config, image: { buffer: Buffer.from('image'), mime: 'image/png', filename: 'image.png' } });
|
|
100
|
+
expect(fetchImpl.mock.calls[1][1].body).toBeInstanceOf(FormData);
|
|
101
|
+
expect(JSON.parse(fetchImpl.mock.calls[2][1].body)).toEqual({ robotCode: config.clientID, userIds: [config.ownerID], msgKey: 'sampleImageMsg', msgParam: JSON.stringify({ photoURL: '@uploaded' }) });
|
|
102
|
+
});
|
|
95
103
|
it('accepts platform-scoped private senders without a binding and replies to the persisted user', async () => {
|
|
96
104
|
const h = harness();
|
|
97
105
|
const controller = new AbortController();
|
|
@@ -17,6 +17,8 @@ const SAFE_ERRORS = new Set([
|
|
|
17
17
|
'cancelled',
|
|
18
18
|
'binding_changed',
|
|
19
19
|
'connection_replaced',
|
|
20
|
+
'owner_required',
|
|
21
|
+
'discovery_timeout',
|
|
20
22
|
]);
|
|
21
23
|
|
|
22
24
|
const failureStatus = (code) => code === 'channel_disabled' ? 403
|
|
@@ -43,5 +45,15 @@ export function registerAssistantChannelRoutes(app, runtime) {
|
|
|
43
45
|
app.put(root, (req, res) => respond(res, () => runtime.save(req.params.assistantID, req.params.provider, req.body)));
|
|
44
46
|
app.post(`${root}/retry`, (req, res) => respond(res, () => runtime.retry(req.params.assistantID, req.params.provider)));
|
|
45
47
|
app.post(`${root}/transfer`, (req, res) => respond(res, () => runtime.transfer(req.params.assistantID, req.params.provider, req.body)));
|
|
48
|
+
app.post(`${root}/discover`, (req, res) => {
|
|
49
|
+
const controller = new AbortController();
|
|
50
|
+
const cancel = () => controller.abort();
|
|
51
|
+
res.once('close', cancel);
|
|
52
|
+
respond(res, async () => {
|
|
53
|
+
try {
|
|
54
|
+
return await runtime.discover(req.params.assistantID, req.params.provider, req.body, { signal: controller.signal });
|
|
55
|
+
} finally { res.off('close', cancel); }
|
|
56
|
+
});
|
|
57
|
+
});
|
|
46
58
|
app.delete(root, (req, res) => respond(res, () => runtime.disconnect(req.params.assistantID, req.params.provider)));
|
|
47
59
|
}
|
|
@@ -20,6 +20,7 @@ describe('authenticated enterprise channel routes', () => {
|
|
|
20
20
|
await request(app).put(root).send({}).expect(403, { error: 'channel_disabled' });
|
|
21
21
|
await request(app).post(`${root}/retry`).send({}).expect(403, { error: 'channel_disabled' });
|
|
22
22
|
await request(app).post(`${root}/transfer`).send({}).expect(403, { error: 'channel_disabled' });
|
|
23
|
+
await request(app).post(`${root}/discover`).send({}).expect(403, { error: 'channel_disabled' });
|
|
23
24
|
await request(app).delete(root).expect(403, { error: 'channel_disabled' });
|
|
24
25
|
await runtime.close();
|
|
25
26
|
});
|
|
@@ -41,6 +42,7 @@ describe('authenticated enterprise channel routes', () => {
|
|
|
41
42
|
})),
|
|
42
43
|
retry: vi.fn(async () => ({ provider: 'feishu', status: 'reconnecting', error: null })),
|
|
43
44
|
transfer: vi.fn(async () => ({ provider: 'feishu', status: 'connecting', error: null })),
|
|
45
|
+
discover: vi.fn(async () => ({ ownerID: 'ou_user' })),
|
|
44
46
|
disconnect: vi.fn(async () => ({ provider: 'feishu', status: 'disconnected', error: null })),
|
|
45
47
|
};
|
|
46
48
|
registerAssistantChannelRoutes(app, runtime);
|
|
@@ -61,6 +63,11 @@ describe('authenticated enterprise channel routes', () => {
|
|
|
61
63
|
await request(app).post(`${root}/transfer`).auth('test-owner', { type: 'bearer' })
|
|
62
64
|
.send({ sourceAssistantID: 'old', revision: 'r1' }).expect(200);
|
|
63
65
|
expect(runtime.transfer).toHaveBeenCalledWith('bot', 'feishu', { sourceAssistantID: 'old', revision: 'r1' });
|
|
66
|
+
await request(app).post(`${root}/discover`).send({ clientID: 'client' }).expect(401);
|
|
67
|
+
expect(runtime.discover).not.toHaveBeenCalled();
|
|
68
|
+
await request(app).post(`${root}/discover`).auth('test-owner', { type: 'bearer' })
|
|
69
|
+
.send({ clientID: 'client', clientSecret: 'secret' }).expect('Cache-Control', 'no-store').expect(200, { ownerID: 'ou_user' });
|
|
70
|
+
expect(runtime.discover).toHaveBeenCalledWith('bot', 'feishu', { clientID: 'client', clientSecret: 'secret' }, { signal: expect.any(AbortSignal) });
|
|
64
71
|
await request(app).delete(root).auth('test-owner', { type: 'bearer' }).expect(200);
|
|
65
72
|
expect(runtime.disconnect).toHaveBeenCalledWith('bot', 'feishu');
|
|
66
73
|
});
|
|
@@ -102,4 +109,31 @@ describe('authenticated enterprise channel routes', () => {
|
|
|
102
109
|
await request(app).put(root).send({}).expect(409, { error: 'connection_replaced' });
|
|
103
110
|
await request(app).post(`${root}/retry`).expect(409, { error: 'binding_changed' });
|
|
104
111
|
});
|
|
112
|
+
|
|
113
|
+
it('aborts discovery when the HTTP caller closes the request', async () => {
|
|
114
|
+
const app = express();
|
|
115
|
+
app.use(express.json());
|
|
116
|
+
let signal;
|
|
117
|
+
registerAssistantChannelRoutes(app, {
|
|
118
|
+
discover: async (_assistantID, _provider, _body, options) => {
|
|
119
|
+
signal = options.signal;
|
|
120
|
+
return new Promise((_, reject) => signal.addEventListener('abort', () => reject(Object.assign(new Error('cancelled'), { code: 'cancelled' })), { once: true }));
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
const server = app.listen(0, '127.0.0.1');
|
|
124
|
+
try {
|
|
125
|
+
await new Promise((resolve) => server.once('listening', resolve));
|
|
126
|
+
const controller = new AbortController();
|
|
127
|
+
const pending = fetch(`http://127.0.0.1:${server.address().port}/api/yuri/assistants/bot/channels/wecom/discover`, {
|
|
128
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}', signal: controller.signal,
|
|
129
|
+
}).catch(() => {});
|
|
130
|
+
await vi.waitFor(() => expect(signal).toBeDefined());
|
|
131
|
+
controller.abort();
|
|
132
|
+
await pending;
|
|
133
|
+
await vi.waitFor(() => expect(signal.aborted).toBe(true));
|
|
134
|
+
} finally {
|
|
135
|
+
server.closeAllConnections();
|
|
136
|
+
await new Promise((resolve) => server.close(resolve));
|
|
137
|
+
}
|
|
138
|
+
});
|
|
105
139
|
});
|
|
@@ -3,6 +3,7 @@ import { setTimeout as delay } from 'node:timers/promises';
|
|
|
3
3
|
import { createAssistantChannelStore } from './store.js';
|
|
4
4
|
import { encodeWeixinTOON } from '../weixin/toon.js';
|
|
5
5
|
import { isMessageChannelTurn } from '../message-channel-origin.js';
|
|
6
|
+
import { prepareChannelOutput, readChannelDeliveryImage, channelImageFailure } from '../channel-output.js';
|
|
6
7
|
|
|
7
8
|
const digest = (value) => createHash('sha256').update(value).digest('hex');
|
|
8
9
|
const PROVIDER = /^[a-z][a-z0-9_]{1,31}$/;
|
|
@@ -10,7 +11,6 @@ const MAX_PLATFORM_ID = 256;
|
|
|
10
11
|
const MAX_ACCOUNT_FIELD = 512;
|
|
11
12
|
const MAX_SECRET = 4096;
|
|
12
13
|
const MAX_TEXT = 20_000;
|
|
13
|
-
const MAX_CHUNK = 3500;
|
|
14
14
|
const MAX_TARGET_BYTES = 16_384;
|
|
15
15
|
const BACKLOG_MAX = 100;
|
|
16
16
|
const AUTH_ERRORS = new Set(['auth_failed', 'auth_expired']);
|
|
@@ -146,15 +146,6 @@ const parseTarget = (value) => {
|
|
|
146
146
|
} catch { return undefined; }
|
|
147
147
|
};
|
|
148
148
|
|
|
149
|
-
const chunkText = (text) => {
|
|
150
|
-
const chars = Array.from(text);
|
|
151
|
-
const chunks = [];
|
|
152
|
-
for (let index = 0; index < chars.length; index += MAX_CHUNK) {
|
|
153
|
-
chunks.push(chars.slice(index, index + MAX_CHUNK).join(''));
|
|
154
|
-
}
|
|
155
|
-
return chunks;
|
|
156
|
-
};
|
|
157
|
-
|
|
158
149
|
/**
|
|
159
150
|
* Generic Host-owned long-connection channel framework for WeCom, Feishu and
|
|
160
151
|
* DingTalk. Platform wire behavior lives in injected adapters; this module owns
|
|
@@ -168,6 +159,7 @@ export function createAssistantChannelsRuntime({
|
|
|
168
159
|
env = process.env,
|
|
169
160
|
clock = Date.now,
|
|
170
161
|
intervalMs = 2000,
|
|
162
|
+
discoveryTimeoutMs = 90_000,
|
|
171
163
|
} = {}) {
|
|
172
164
|
const configured = String(env.YURI_CHANNELS_ENABLED ?? '').trim().toLowerCase();
|
|
173
165
|
const development = env.NODE_ENV === 'development'
|
|
@@ -191,7 +183,7 @@ export function createAssistantChannelsRuntime({
|
|
|
191
183
|
hasSecret: false, transport: 'websocket',
|
|
192
184
|
};
|
|
193
185
|
},
|
|
194
|
-
save: disabled, retry: disabled, disconnect: disabled, transfer: disabled,
|
|
186
|
+
save: disabled, retry: disabled, disconnect: disabled, transfer: disabled, discover: disabled,
|
|
195
187
|
forget: async () => {}, onTurnEvent: () => {}, close: async () => {},
|
|
196
188
|
};
|
|
197
189
|
}
|
|
@@ -204,6 +196,8 @@ export function createAssistantChannelsRuntime({
|
|
|
204
196
|
const operations = new Set();
|
|
205
197
|
const recovered = new Set();
|
|
206
198
|
const retiring = new Set();
|
|
199
|
+
const discoveries = new Map();
|
|
200
|
+
const pendingAccounts = new Set();
|
|
207
201
|
const lifetime = new AbortController();
|
|
208
202
|
let closed = false;
|
|
209
203
|
let ownsLease = false;
|
|
@@ -438,25 +432,31 @@ export function createAssistantChannelsRuntime({
|
|
|
438
432
|
}
|
|
439
433
|
};
|
|
440
434
|
|
|
441
|
-
const enqueuePage = (binding, page) => {
|
|
435
|
+
const enqueuePage = async (binding, page) => {
|
|
442
436
|
if (!binding.owner_id && !binding.target) {
|
|
443
437
|
store.collect(binding, page, [], clock());
|
|
444
438
|
return;
|
|
445
439
|
}
|
|
446
|
-
const deliveries =
|
|
440
|
+
const deliveries = [];
|
|
441
|
+
const receiverSignal = receivers.get(channelKey(binding.assistant_id, binding.provider))?.controller.signal;
|
|
442
|
+
const signal = receiverSignal ? AbortSignal.any([lifetime.signal, receiverSignal]) : lifetime.signal;
|
|
443
|
+
const assertCurrent = () => {
|
|
444
|
+
if (!isCurrent(binding) || service.channelPage(binding.assistant_id, { tipOnly: true }).generation !== page.generation) throw new ChannelError('cancelled');
|
|
445
|
+
};
|
|
446
|
+
for (const message of page.messages) {
|
|
447
447
|
const receipt = store.receipt(message.turnID, binding.epoch);
|
|
448
|
-
if (isMessageChannelTurn(message.turnID) && !receipt)
|
|
448
|
+
if (isMessageChannelTurn(message.turnID) && !receipt) continue;
|
|
449
449
|
// A channel reply uses its own durable sender, not another later sender.
|
|
450
|
-
if (receipt && !receipt.target && !binding.owner_id)
|
|
451
|
-
const
|
|
452
|
-
:
|
|
453
|
-
|
|
454
|
-
return chunkText(text).filter(Boolean).map((chunk, index) => ({
|
|
450
|
+
if (receipt && !receipt.target && !binding.owner_id) continue;
|
|
451
|
+
const output = await prepareChannelOutput(message, { service, assistantID: binding.assistant_id,
|
|
452
|
+
generation: page.generation, language: binding.language, failureText: feedback(binding.language, 'failed'), signal, assertCurrent });
|
|
453
|
+
deliveries.push(...output.map((part, index) => ({
|
|
455
454
|
id: `yuri_${digest(`${binding.epoch}:${page.generation}:${message.messageID}:${index}`)}`,
|
|
456
|
-
|
|
455
|
+
...part,
|
|
457
456
|
...(receipt ? { target: receipt.target || '' } : {}),
|
|
458
|
-
}));
|
|
459
|
-
}
|
|
457
|
+
})));
|
|
458
|
+
}
|
|
459
|
+
assertCurrent();
|
|
460
460
|
store.collect(binding, page, deliveries, clock());
|
|
461
461
|
};
|
|
462
462
|
|
|
@@ -475,9 +475,8 @@ export function createAssistantChannelsRuntime({
|
|
|
475
475
|
if (!row || row.epoch !== binding.epoch || isSticky(row)) return;
|
|
476
476
|
const delivery = store.nextDelivery(binding.epoch);
|
|
477
477
|
if (!delivery) return;
|
|
478
|
-
//
|
|
479
|
-
//
|
|
480
|
-
if (delivery.state !== 'pending') return;
|
|
478
|
+
// Only pending output is eligible; failed/unknown rows stay durable without
|
|
479
|
+
// blocking later replies. Unknown sends are never automatically retried.
|
|
481
480
|
if (!adapter) {
|
|
482
481
|
store.patch(binding.epoch, { status: 'error', error: 'unsupported_provider', updated_at: clock() });
|
|
483
482
|
return;
|
|
@@ -485,10 +484,18 @@ export function createAssistantChannelsRuntime({
|
|
|
485
484
|
store.markDelivery(delivery.id, 'sending');
|
|
486
485
|
const signal = AbortSignal.any([lifetime.signal, receiver.controller.signal]);
|
|
487
486
|
try {
|
|
487
|
+
const image = await readChannelDeliveryImage(service, binding.assistant_id, delivery.image ? JSON.parse(delivery.image) : null, signal);
|
|
488
|
+
if (!isCurrent(binding) || signal.aborted
|
|
489
|
+
|| service.channelPage(binding.assistant_id, { tipOnly: true }).generation !== row.generation) throw new ChannelError('cancelled');
|
|
488
490
|
await adapter.send({
|
|
489
491
|
config: configOf(row),
|
|
490
492
|
target: parseTarget(delivery.target),
|
|
491
493
|
text: delivery.text,
|
|
494
|
+
...(image ? { image } : {}),
|
|
495
|
+
beforeSend: () => {
|
|
496
|
+
signal.throwIfAborted();
|
|
497
|
+
if (!isCurrent(binding) || service.channelPage(binding.assistant_id, { tipOnly: true }).generation !== row.generation) throw new ChannelError('cancelled');
|
|
498
|
+
},
|
|
492
499
|
id: delivery.id,
|
|
493
500
|
signal,
|
|
494
501
|
});
|
|
@@ -525,6 +532,9 @@ export function createAssistantChannelsRuntime({
|
|
|
525
532
|
store.patch(binding.epoch, { error: 'delivery_unknown', updated_at: clock() });
|
|
526
533
|
} else {
|
|
527
534
|
store.failDelivery(delivery.id);
|
|
535
|
+
if (delivery.image && delivery.attempts >= 2) {
|
|
536
|
+
store.enqueue(binding.epoch, `${delivery.id}:image-failed`, channelImageFailure(binding.language), delivery.target);
|
|
537
|
+
}
|
|
528
538
|
// A send failure never proves the connection is ready/connected.
|
|
529
539
|
store.patch(binding.epoch, {
|
|
530
540
|
error: store.hasBlocked(binding.epoch) ? 'delivery_failed' : code,
|
|
@@ -549,7 +559,7 @@ export function createAssistantChannelsRuntime({
|
|
|
549
559
|
throw error;
|
|
550
560
|
}
|
|
551
561
|
if (!isCurrent(binding)) return;
|
|
552
|
-
enqueuePage(binding, page);
|
|
562
|
+
await enqueuePage(binding, page);
|
|
553
563
|
const key = channelKey(binding.assistant_id, binding.provider);
|
|
554
564
|
if (!inboundWork.has(key)) {
|
|
555
565
|
const work = track(processIncoming(binding, page.generation)).catch((error) => setError(binding, error));
|
|
@@ -570,6 +580,7 @@ export function createAssistantChannelsRuntime({
|
|
|
570
580
|
try {
|
|
571
581
|
ownsLease = store.acquire(owner, clock());
|
|
572
582
|
if (!ownsLease) {
|
|
583
|
+
for (const entry of discoveries.values()) entry.controller.abort();
|
|
573
584
|
for (const key of [...receivers.keys()]) stopReceiver(key);
|
|
574
585
|
return;
|
|
575
586
|
}
|
|
@@ -642,6 +653,77 @@ export function createAssistantChannelsRuntime({
|
|
|
642
653
|
};
|
|
643
654
|
};
|
|
644
655
|
|
|
656
|
+
// Discovery is an explicit, bounded credential probe, never a saved binding
|
|
657
|
+
// or a second message execution pipeline. The first private sender is shown
|
|
658
|
+
// to the user for confirmation through the normal Save action.
|
|
659
|
+
const discover = async (assistantID, provider, input, { signal } = {}) => {
|
|
660
|
+
assertProvider(provider);
|
|
661
|
+
assertOwner();
|
|
662
|
+
const adapter = adapters[provider];
|
|
663
|
+
if (!adapter) throw new ChannelError('unsupported_provider');
|
|
664
|
+
service.channelPage(assistantID, { tipOnly: true });
|
|
665
|
+
const existing = store.get(assistantID, provider);
|
|
666
|
+
const field = exactField(input?.clientID, MAX_ACCOUNT_FIELD);
|
|
667
|
+
const secret = typeof input?.clientSecret === 'string' ? input.clientSecret.trim() : '';
|
|
668
|
+
if (field.invalid || !field.value || secret.length > MAX_SECRET) throw new ChannelError('validation_error');
|
|
669
|
+
const clientID = field.value;
|
|
670
|
+
const accountKey = JSON.stringify([provider, clientID]);
|
|
671
|
+
const clientSecret = secret || (existing?.client_id === clientID ? existing.client_secret : '');
|
|
672
|
+
if (!clientSecret) throw new ChannelError('validation_error');
|
|
673
|
+
const key = channelKey(assistantID, provider);
|
|
674
|
+
if (retiring.has(key)) throw new ChannelError('channel_in_use');
|
|
675
|
+
if (store.listAll().some((row) => row.provider === provider && row.client_id === clientID && row.assistant_id !== assistantID)
|
|
676
|
+
|| pendingAccounts.has(accountKey)) {
|
|
677
|
+
throw new ChannelError('account_in_use');
|
|
678
|
+
}
|
|
679
|
+
const controller = new AbortController();
|
|
680
|
+
const active = AbortSignal.any([controller.signal, lifetime.signal, AbortSignal.timeout(discoveryTimeoutMs), ...(signal ? [signal] : [])]);
|
|
681
|
+
const entry = { assistantID, provider, clientID, controller, done: null };
|
|
682
|
+
discoveries.set(key, entry);
|
|
683
|
+
pendingAccounts.add(accountKey);
|
|
684
|
+
retiring.add(key);
|
|
685
|
+
entry.done = (async () => {
|
|
686
|
+
let connection;
|
|
687
|
+
let onAbort;
|
|
688
|
+
try {
|
|
689
|
+
await Promise.allSettled([stopReceiver(key), bindingWork.get(key), inboundWork.get(key)]);
|
|
690
|
+
assertOwner();
|
|
691
|
+
service.channelPage(assistantID, { tipOnly: true });
|
|
692
|
+
if (active.aborted) throw new ChannelError('cancelled');
|
|
693
|
+
return await new Promise((resolve, reject) => {
|
|
694
|
+
const fail = (error) => reject(new ChannelError(safeError(error)));
|
|
695
|
+
onAbort = () => reject(new ChannelError(active.reason?.name === 'TimeoutError' ? 'discovery_timeout' : 'cancelled'));
|
|
696
|
+
active.addEventListener('abort', onAbort, { once: true });
|
|
697
|
+
connection = Promise.resolve().then(() => adapter.connect({
|
|
698
|
+
config: { clientID, clientSecret, ownerID: '' }, signal: active,
|
|
699
|
+
onReady: () => {},
|
|
700
|
+
onMessage: async (message) => {
|
|
701
|
+
if (active.aborted) return false;
|
|
702
|
+
try {
|
|
703
|
+
assertOwner();
|
|
704
|
+
service.channelPage(assistantID, { tipOnly: true });
|
|
705
|
+
const sender = exactField(message?.senderID, MAX_ACCOUNT_FIELD);
|
|
706
|
+
if (message?.chatType !== 'private' || sender.invalid || !sender.value) return false;
|
|
707
|
+
resolve({ ownerID: sender.value });
|
|
708
|
+
return true;
|
|
709
|
+
} catch (error) { fail(error); return false; }
|
|
710
|
+
},
|
|
711
|
+
onError: fail,
|
|
712
|
+
})).then(() => { if (!active.aborted) fail(new ChannelError('network_error')); }, fail);
|
|
713
|
+
});
|
|
714
|
+
} finally {
|
|
715
|
+
controller.abort();
|
|
716
|
+
if (onAbort) active.removeEventListener('abort', onAbort);
|
|
717
|
+
await connection;
|
|
718
|
+
discoveries.delete(key);
|
|
719
|
+
pendingAccounts.delete(accountKey);
|
|
720
|
+
retiring.delete(key);
|
|
721
|
+
if (!closed) void track(tick());
|
|
722
|
+
}
|
|
723
|
+
})();
|
|
724
|
+
return entry.done;
|
|
725
|
+
};
|
|
726
|
+
|
|
645
727
|
const save = async (assistantID, provider, input) => {
|
|
646
728
|
assertProvider(provider);
|
|
647
729
|
assertOwner();
|
|
@@ -659,6 +741,7 @@ export function createAssistantChannelsRuntime({
|
|
|
659
741
|
}
|
|
660
742
|
const clientID = clientIDField.value;
|
|
661
743
|
const ownerID = ownerIDField.value;
|
|
744
|
+
if (!ownerID) throw new ChannelError('owner_required');
|
|
662
745
|
const accountChanged = Boolean(existing && existing.client_id !== clientID);
|
|
663
746
|
// A new account must bring its own secret; never reuse a previous account's
|
|
664
747
|
// credential after the client ID changes.
|
|
@@ -669,8 +752,11 @@ export function createAssistantChannelsRuntime({
|
|
|
669
752
|
const expectedEpoch = existing?.epoch ?? null;
|
|
670
753
|
const key = channelKey(assistantID, provider);
|
|
671
754
|
if (retiring.has(key)) throw new ChannelError('channel_in_use');
|
|
755
|
+
const accountKey = JSON.stringify([provider, clientID]);
|
|
756
|
+
if (pendingAccounts.has(accountKey)) throw new ChannelError('account_in_use');
|
|
672
757
|
const account = store.listAll().find((row) => row.provider === provider && row.client_id === clientID);
|
|
673
758
|
if (account && account.assistant_id !== assistantID) throw new ChannelError('account_in_use');
|
|
759
|
+
pendingAccounts.add(accountKey);
|
|
674
760
|
retiring.add(key);
|
|
675
761
|
let bound = false;
|
|
676
762
|
try {
|
|
@@ -704,6 +790,7 @@ export function createAssistantChannelsRuntime({
|
|
|
704
790
|
bound = true;
|
|
705
791
|
} finally {
|
|
706
792
|
retiring.delete(key);
|
|
793
|
+
pendingAccounts.delete(accountKey);
|
|
707
794
|
// Account conflict, a failed write or a stale binding must not strand the
|
|
708
795
|
// previous receiver; resume it from its untouched row.
|
|
709
796
|
if (!bound && !closed) void track(tick());
|
|
@@ -808,6 +895,9 @@ export function createAssistantChannelsRuntime({
|
|
|
808
895
|
if (closed) return;
|
|
809
896
|
if (!ownsLease) ownsLease = store.acquire(owner, clock());
|
|
810
897
|
if (!ownsLease || !store.owns(owner, clock())) return;
|
|
898
|
+
const pendingDiscoveries = [...discoveries.values()].filter((entry) => entry.assistantID === assistantID);
|
|
899
|
+
for (const entry of pendingDiscoveries) entry.controller.abort();
|
|
900
|
+
await Promise.allSettled(pendingDiscoveries.map((entry) => entry.done));
|
|
811
901
|
const rows = store.listByAssistant(assistantID);
|
|
812
902
|
if (!rows.length) return;
|
|
813
903
|
const keys = rows.map((row) => channelKey(assistantID, row.provider));
|
|
@@ -844,6 +934,7 @@ export function createAssistantChannelsRuntime({
|
|
|
844
934
|
|
|
845
935
|
return {
|
|
846
936
|
status,
|
|
937
|
+
discover: (assistantID, provider, input, options) => track(discover(assistantID, provider, input, options)),
|
|
847
938
|
save: (assistantID, provider, input) => track(save(assistantID, provider, input)),
|
|
848
939
|
transfer: (assistantID, provider, input) => track(transfer(assistantID, provider, input)),
|
|
849
940
|
retry: (assistantID, provider) => track(retry(assistantID, provider)),
|