WeKnora/internal/im
qilifan 9afb8b7b68 feat(im,datasource): support Lark, Feishu's international edition
Lark and Feishu are the same product deployed on two isolated clouds
(open.larksuite.com and open.feishu.cn). WeKnora touches both from two
places — the IM bot and the Wiki data-source connector — and this brings
Lark to parity across both. Neither API surface differs, so rather than
duplicate either implementation, each is parametrized by a Region and
registered twice.

IM (internal/im/feishu):
  Every API call routes through a.api(), which prefixes the region's
  host, and the WebSocket client passes larkws.WithDomain — the SDK
  defaults to open.feishu.cn, so Lark long connections would otherwise
  fail to authenticate.

Data source (internal/datasource/connector/feishu):
  Lark was half-supported: the client honoured a base_url override and a
  LarkBaseURL constant existed, but the connector registered only as
  "feishu" and the UI never exposed base_url, so Lark wikis could not be
  configured at all. Lark is now its own connector type. base_url is kept
  as an explicit override so data sources that pointed a "feishu"
  connector at open.larksuite.com keep working.

Bugs found and fixed along the way:

- Wiki resource links were hardcoded to https://feishu.cn/wiki/{token} in
  four places, so a Lark wiki linked into the wrong cloud entirely.
- Bot identity is now platform-prefixed (feishu:cli_x vs lark:cli_x).
  BotIdentity carries a unique index, so without this a Lark channel
  would be rejected as a duplicate of an unrelated Feishu bot sharing an
  app_id.
- The card image cache is now keyed by app_id. image_keys are issued per
  app on one cloud; a Feishu key handed to a Lark app fails the card
  update with code=200570.
- The datasource doc claimed Lark "adapts automatically" — it could not,
  since the UI had no way to reach base_url.

Permissions are where the clouds genuinely diverge. Identical APIs do not
mean identical permission catalogues: aily:file:read, aily:file:write and
corehr:file:download exist on Feishu but not on Lark, so pasting Feishu's
scope JSON into Lark fails to import. That JSON is also over-broad (it
covers products WeKnora never calls) and simultaneously incomplete (it
omits the drive:*/docx:* scopes the connector needs). Lark therefore gets
its own list, derived from the 17 endpoints the code actually calls and
checked identifier-by-identifier against Lark's own API reference, plus a
full Feishu→Lark mapping table marking each scope verified, unverified,
or absent. Both features use tenant_access_token only — no user_access_
token exists anywhere in the repo — so the user dimension stays empty.

Known limitation: Region.ThinkingText makes Lark's initial card
placeholder English, but once streaming starts the think-block headers
come from the shared MarkdownThinkStyle and are Chinese on every platform
(Lark, Slack, Telegram, Mattermost alike). Fixing that means threading a
locale through FormatIMDisplayContent, which has no platform context — a
cross-platform change, not a Lark one. Documented as such.

The channel-creation 400 message is now derived from validIMPlatforms so
the list cannot drift as platforms are added.

Tests: region invariants and per-region URL construction on both sides,
the Feishu/Lark bot-identity split, platform-to-channel mapping, base_url
override precedence, an end-to-end SendReply against a fake Open Platform
(token fetch, reply, thread-unsupported fallback, hard-error surfacing),
and a ListResources drive asserting wiki links never leak the other
cloud's host.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 11:05:54 +08:00
..
dingtalk fix(im): harden DingTalk file download with SSRF checks and pictureDownloadCode fallback 2026-07-09 15:38:13 +08:00
feishu feat(im,datasource): support Lark, Feishu's international edition 2026-07-17 11:05:54 +08:00
mattermost fix(security): harden outbound requests and file previews 2026-07-02 19:15:46 +08:00
qqbot fix(security): harden outbound requests and file previews 2026-07-02 19:15:46 +08:00
slack feat(im): align agent stream display with web thinking and tool progress 2026-06-24 10:33:55 +08:00
telegram fix(im): harden stream finalize and drop collapsed think header 2026-06-24 10:33:55 +08:00
wechat fix(im): clamp reconnect backoff to avoid int64 overflow → busy loop 2026-05-05 00:36:18 +08:00
wecom fix(im): address stream display review feedback 2026-06-24 10:33:55 +08:00
adapter.go feat(im,datasource): support Lark, Feishu's international edition 2026-07-17 11:05:54 +08:00
channel_mapping_test.go feat(im,datasource): support Lark, Feishu's international edition 2026-07-17 11:05:54 +08:00
cmd_clear.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
cmd_help.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
cmd_info.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
cmd_search.go fix(search): apply tag filters to knowledge search 2026-07-06 23:30:33 +08:00
cmd_stop.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
command.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
command_registry.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
content_rewrite_test.go feat(storage): add multi-instance storage backends per workspace 2026-07-15 14:54:39 +08:00
credentials.go refactor(im): move adapter factories into per-platform subpackages 2026-04-29 20:08:22 +08:00
identity_test.go test: address PR review follow-ups for OAuth and logger cleanup 2026-07-01 17:31:42 +08:00
im_file_service_test.go feat(storage): add multi-instance storage backends per workspace 2026-07-15 14:54:39 +08:00
mode.go refactor(im): move adapter factories into per-platform subpackages 2026-04-29 20:08:22 +08:00
oauth_notice_test.go feat(im): include per-service MCP OAuth URLs in IM auth notices 2026-07-01 17:53:54 +08:00
qaqueue.go feat: add unit tests for COS object name parsing and enhance error handling 2026-05-29 13:47:32 +08:00
service.go feat(resource): add stable resource registry with LLM-context alias compaction 2026-07-15 17:02:43 +08:00
service_agent_test.go fix(integrations): polish agent filter UX and embed session rebind 2026-06-24 20:09:19 +08:00
service_quote_test.go fix(im): anti-hallucination for non-text quotes and unprocessable media messages 2026-04-03 11:34:22 +08:00
session_not_found_test.go fix(im): recover from deleted session when GetSession returns app sentinel (#1499) 2026-05-27 11:51:11 +08:00
session_test.go fix(im): harden stream finalize and drop collapsed think header 2026-06-24 10:33:55 +08:00
session_title_test.go feat(im): IM session improvements — titles, in-flight recovery, classification 2026-06-12 17:01:28 +08:00
stream_display_test.go fix(im): harden stream finalize and drop collapsed think header 2026-06-24 10:33:55 +08:00
stream_lifecycle_test.go fix(im): address stream display review feedback 2026-06-24 10:33:55 +08:00
stream_section.go fix(im): address stream display review feedback 2026-06-24 10:33:55 +08:00
stream_test.go feat(im): align agent stream display with web thinking and tool progress 2026-06-24 10:33:55 +08:00
supervisor.go fix(im): prevent DingTalk stream connection from going stale 2026-06-22 15:04:23 +08:00
think.go feat(im,datasource): support Lark, Feishu's international edition 2026-07-17 11:05:54 +08:00
think_test.go fix(im): harden stream finalize and drop collapsed think header 2026-06-24 10:33:55 +08:00
tool_display.go fix(quick-qa): distinguish web and knowledge base retrieval in pipeline UI 2026-07-08 00:26:34 +08:00
tool_display_test.go fix(quick-qa): distinguish web and knowledge base retrieval in pipeline UI 2026-07-08 00:26:34 +08:00
types.go feat(im,datasource): support Lark, Feishu's international edition 2026-07-17 11:05:54 +08:00
types_summary_test.go fix(security): redact IM list credentials and harden MinerU SSRF 2026-07-02 17:58:20 +08:00
types_test.go feat(im,datasource): support Lark, Feishu's international edition 2026-07-17 11:05:54 +08:00