WeKnora/internal
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
..
agent feat(agent): enhance suggested questions API with tag scopes 2026-07-17 10:19:43 +08:00
application feat(agent): enhance suggested questions API with tag scopes 2026-07-17 10:19:43 +08:00
assets feat(assets): add ASR test audio file and embed it in the application 2026-04-02 21:27:27 +08:00
common fix(redis): harden TLS tests and surface TLS config at startup 2026-07-06 23:04:52 +08:00
config refactor(terminology): rename user-facing tenant labels to workspace 2026-07-14 16:14:43 +08:00
container feat(im,datasource): support Lark, Feishu's international edition 2026-07-17 11:05:54 +08:00
database feat(system-info): surface DB migration errors with troubleshooting links 2026-05-14 16:34:50 +08:00
datasource feat(im,datasource): support Lark, Feishu's international edition 2026-07-17 11:05:54 +08:00
errors refactor(terminology): rename user-facing tenant labels to workspace 2026-07-14 16:14:43 +08:00
event feat(mcp): prompt and resume OAuth authorization mid-conversation 2026-06-29 23:22:28 +08:00
handler feat(im,datasource): support Lark, Feishu's international edition 2026-07-17 11:05:54 +08:00
im feat(im,datasource): support Lark, Feishu's international edition 2026-07-17 11:05:54 +08:00
infrastructure fix(web-search): polish Keenable provider integration after #1946 2026-07-07 17:14:39 +08:00
llmreference feat(agent): add per-agent citation output toggle 2026-07-17 10:19:43 +08:00
llmresource fix(tests): update resource alias syntax from 'res:' to 'res://' in tests and registry 2026-07-15 17:02:43 +08:00
logger fix: harden document pipeline concurrency and diagnostics 2026-07-09 13:26:40 +08:00
mcp feat(im): include per-service MCP OAuth URLs in IM auth notices 2026-07-01 17:53:54 +08:00
middleware refactor(terminology): rename user-facing tenant labels to workspace 2026-07-14 16:14:43 +08:00
models feat(resource): add stable resource registry with LLM-context alias compaction 2026-07-15 17:02:43 +08:00
ratelimit feat(embed): add backend embed channels with auth and rate limiting (#1657) 2026-06-12 23:10:39 +08:00
router feat(chat): add session-scoped temporary attachments with async parsing 2026-07-16 17:41:27 +08:00
runtime fix(redis): harden TLS tests and surface TLS config at startup 2026-07-06 23:04:52 +08:00
sandbox perf(sandbox): compile command-substitution regexps once 2026-06-16 19:51:32 +08:00
searchutil fix(chat): use Markdown for LLM image context and normalize legacy XML 2026-07-15 18:10:31 +08:00
storageallowlist fix(storage): align default provider fallback with STORAGE_ALLOW_LIST 2026-07-15 11:05:00 +08:00
stream feat(redis): support TLS for Redis connections (#1930) 2026-07-06 23:02:02 +08:00
tracing/langfuse feat(observability): enhance Langfuse retrieve and rerank tracing 2026-06-16 01:09:23 +08:00
types feat(im,datasource): support Lark, Feishu's international edition 2026-07-17 11:05:54 +08:00
utils feat(resource): add stable resource registry with LLM-context alias compaction 2026-07-15 17:02:43 +08:00