Repository navigation
Conversation
Greptile SummaryThis PR fixes the inability to read full text content from Feishu CardKit streaming cards by passing the undocumented
Confidence Score: 4/5Safe to merge; changes are additive with clean fallback behaviour and solid test coverage. The core Feishu fix is well-implemented — it adds the undocumented param, parses the new response format, falls back gracefully on parse failure, and is backed by three new tests. The server-chat.ts snapshot expansion is additive and validated by a new test. The one minor inconsistency (the rows field is declared in the type but never iterated over) is a P2 cleanup item that does not affect the primary user path or introduce any regressions. No files require special attention; extensions/feishu/src/send.ts has one minor type/logic gap around rows worth a follow-up.
|
| Filename | Overview |
|---|---|
| extensions/feishu/src/send.ts | Adds card_msg_content_type=raw_card_content param to both message.get and message.list, and a new extractJsonCardTexts helper + json_card parsing branch in parseInteractiveCardContent. Logic is sound with proper fallback; minor inconsistency between the typed rows field and missing recursion over it. |
| extensions/feishu/src/send.test.ts | Three new test cases cover param forwarding, json_card parsing with nested column_set elements, and fallback on invalid JSON — good coverage of the new code paths. |
| src/gateway/server-chat.ts | Promotes many additional session row fields (fastMode, verboseLevel, sendPolicy, responseUsage, etc.) to the top level of the session snapshot object. Additive change that mirrors what was already done for totalTokens/contextTokens. |
| src/gateway/server-chat.agent-events.test.ts | Adds a lifecycle test validating that promoted session metadata fields are present at the top level of the broadcast payload; also fixes the module mock for loadGatewaySessionRow to prevent test bleed. |
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/feishu/src/send.ts
Line: 189-212
Comment:
**`rows` field typed but never recursed into**
The node type includes `rows?: unknown[]`, and the comment references "form elements, etc." as a motivation for recursion — but there is no corresponding loop over `rows`. Any CardKit elements that store text inside rows (e.g., a `form` element with row-based layout) would be silently skipped.
Either add the recursion or remove the `rows` field from the type to keep the declared surface and the implementation in sync:
```suggestion
const node = el as {
tag?: string;
property?: { content?: string };
elements?: unknown[];
columns?: unknown[];
};
if (node.tag === "plain_text" && typeof node.property?.content === "string") {
texts.push(node.property.content);
}
if (node.tag === "markdown" && typeof (node as { content?: string }).content === "string") {
texts.push((node as { content?: string }).content!);
}
// Recurse into nested structures (column_set columns, form elements, etc.)
if (Array.isArray(node.elements)) {
texts.push(...extractJsonCardTexts(node.elements));
}
if (Array.isArray(node.columns)) {
for (const col of node.columns) {
if (
col &&
typeof col === "object" &&
Array.isArray((col as { elements?: unknown[] }).elements)
) {
texts.push(...extractJsonCardTexts((col as { elements: unknown[] }).elements));
}
}
}
```
Or, if rows are intentionally planned for the future, add a `// TODO: recurse into rows` comment so it is not forgotten.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(feishu): read full CardKit streaming..." | Re-trigger Greptile
| rows?: unknown[]; | ||
| }; | ||
| if (node.tag === "plain_text" && typeof node.property?.content === "string") { | ||
| texts.push(node.property.content); | ||
| } | ||
| if (node.tag === "markdown" && typeof (node as { content?: string }).content === "string") { | ||
| texts.push((node as { content?: string }).content!); | ||
| } | ||
| // Recurse into nested structures (column_set columns, form elements, etc.) | ||
| if (Array.isArray(node.elements)) { | ||
| texts.push(...extractJsonCardTexts(node.elements)); | ||
| } | ||
| if (Array.isArray(node.columns)) { | ||
| for (const col of node.columns) { | ||
| if ( | ||
| col && | ||
| typeof col === "object" && | ||
| Array.isArray((col as { elements?: unknown[] }).elements) | ||
| ) { | ||
| texts.push(...extractJsonCardTexts((col as { elements: unknown[] }).elements)); | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
rows field typed but never recursed into
The node type includes rows?: unknown[], and the comment references "form elements, etc." as a motivation for recursion — but there is no corresponding loop over rows. Any CardKit elements that store text inside rows (e.g., a form element with row-based layout) would be silently skipped.
Either add the recursion or remove the rows field from the type to keep the declared surface and the implementation in sync:
| rows?: unknown[]; | |
| }; | |
| if (node.tag === "plain_text" && typeof node.property?.content === "string") { | |
| texts.push(node.property.content); | |
| } | |
| if (node.tag === "markdown" && typeof (node as { content?: string }).content === "string") { | |
| texts.push((node as { content?: string }).content!); | |
| } | |
| // Recurse into nested structures (column_set columns, form elements, etc.) | |
| if (Array.isArray(node.elements)) { | |
| texts.push(...extractJsonCardTexts(node.elements)); | |
| } | |
| if (Array.isArray(node.columns)) { | |
| for (const col of node.columns) { | |
| if ( | |
| col && | |
| typeof col === "object" && | |
| Array.isArray((col as { elements?: unknown[] }).elements) | |
| ) { | |
| texts.push(...extractJsonCardTexts((col as { elements: unknown[] }).elements)); | |
| } | |
| } | |
| } | |
| } | |
| const node = el as { | |
| tag?: string; | |
| property?: { content?: string }; | |
| elements?: unknown[]; | |
| columns?: unknown[]; | |
| }; | |
| if (node.tag === "plain_text" && typeof node.property?.content === "string") { | |
| texts.push(node.property.content); | |
| } | |
| if (node.tag === "markdown" && typeof (node as { content?: string }).content === "string") { | |
| texts.push((node as { content?: string }).content!); | |
| } | |
| // Recurse into nested structures (column_set columns, form elements, etc.) | |
| if (Array.isArray(node.elements)) { | |
| texts.push(...extractJsonCardTexts(node.elements)); | |
| } | |
| if (Array.isArray(node.columns)) { | |
| for (const col of node.columns) { | |
| if ( | |
| col && | |
| typeof col === "object" && | |
| Array.isArray((col as { elements?: unknown[] }).elements) | |
| ) { | |
| texts.push(...extractJsonCardTexts((col as { elements: unknown[] }).elements)); | |
| } | |
| } | |
| } |
Or, if rows are intentionally planned for the future, add a // TODO: recurse into rows comment so it is not forgotten.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/feishu/src/send.ts
Line: 189-212
Comment:
**`rows` field typed but never recursed into**
The node type includes `rows?: unknown[]`, and the comment references "form elements, etc." as a motivation for recursion — but there is no corresponding loop over `rows`. Any CardKit elements that store text inside rows (e.g., a `form` element with row-based layout) would be silently skipped.
Either add the recursion or remove the `rows` field from the type to keep the declared surface and the implementation in sync:
```suggestion
const node = el as {
tag?: string;
property?: { content?: string };
elements?: unknown[];
columns?: unknown[];
};
if (node.tag === "plain_text" && typeof node.property?.content === "string") {
texts.push(node.property.content);
}
if (node.tag === "markdown" && typeof (node as { content?: string }).content === "string") {
texts.push((node as { content?: string }).content!);
}
// Recurse into nested structures (column_set columns, form elements, etc.)
if (Array.isArray(node.elements)) {
texts.push(...extractJsonCardTexts(node.elements));
}
if (Array.isArray(node.columns)) {
for (const col of node.columns) {
if (
col &&
typeof col === "object" &&
Array.isArray((col as { elements?: unknown[] }).elements)
) {
texts.push(...extractJsonCardTexts((col as { elements: unknown[] }).elements));
}
}
}
```
Or, if rows are intentionally planned for the future, add a `// TODO: recurse into rows` comment so it is not forgotten.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9649267f22
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // eslint-disable-next-line @typescript-eslint/no-explicit-any -- card_msg_content_type is not in the SDK types yet | ||
| const listParams: any = { |
There was a problem hiding this comment.
Restore type safety for Feishu list query params
This change introduces // eslint-disable-next-line @typescript-eslint/no-explicit-any and const listParams: any, which violates the documented repo rule in AGENTS.md (“Never add @ts-nocheck and do not disable no-explicit-any”). More importantly, it removes compile-time validation for the message.list query shape, so future SDK type changes or param typos here can silently pass CI and only fail when thread reads run in production; please use a typed local param shape (or a narrowly scoped cast) instead of disabling the rule.
Useful? React with 👍 / 👎.
9649267 to
cf582f3
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cf582f3a5e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (Array.isArray(jsonCard.body?.elements)) { | ||
| parts.push(...extractJsonCardTexts(jsonCard.body!.elements)); |
There was a problem hiding this comment.
Parse top-level json_card elements
With card_msg_content_type=raw_card_content, interactive messages can be wrapped as {"json_card":"..."}. This new branch only reads jsonCard.body.elements, but schema 1.0 cards store textual blocks in top-level elements (which the legacy parser path already handled). In that case parts stays empty, then fallback parsing runs against the wrapper object (not the parsed card), and the function returns [Interactive Card] instead of the actual text. Please also extract from jsonCard.elements before falling through.
Useful? React with 👍 / 👎.
EronFan
left a comment
There was a problem hiding this comment.
Review: ✅ Approve with suggestions
Solid fix overall — the approach is well-researched and the test coverage is thorough. Three issues to address before merge:
1. 🔴 Missing top-level json_card.elements extraction (P1)
When a schema 1.0 card has textual content at jsonCard.elements (not inside jsonCard.body.elements), the current code skips it entirely and falls through to legacy parsing. But legacy parsing runs against the parsed wrapper object — not the parsed card — so it returns [Interactive Card] instead of the actual text.
Fix: Also extract from jsonCard.elements before falling through:
if (Array.isArray(jsonCard.elements)) {
parts.push(...extractJsonCardTexts(jsonCard.elements));
}2. 🟡 rows field typed but never recursed into (P1)
extractJsonCardTexts types columns?: unknown[] and recurses into it, but the node type also has rows?: unknown[] which is never handled. If CardKit form elements store text inside rows, it is silently dropped.
Fix: Either recurse into rows (since the type already claims it exists) or remove rows from the type declaration to keep surface area and implementation in sync:
if (Array.isArray(node.rows)) {
for (const row of node.rows) {
if (row && typeof row === object && Array.isArray((row as { elements?: unknown[] }).elements)) {
texts.push(...extractJsonCardTexts((row as { elements: unknown[] }).elements));
}
}
}3. 🟡 Type safety: avoid Record<string, string> cast
Using params: { card_msg_content_type: raw_card_content } as Record<string, string> disables compile-time checking for the entire params object. If someone later adds another param with a non-string type, it passes silently.
Better approach: a narrow scoped cast:
const cardParams = { card_msg_content_type: raw_card_content } as Record<string, string>;
params: cardParams,Or just as Record<'card_msg_content_type', string>.
Non-blocking notes:
- The
// TODO: recurse into rowsapproach is fine if rows handling is deferred — just add the comment so it is not forgotten. - Test coverage for the three cases is solid.
Overall the approach is correct. Fix items 1 (critical bug) and 2 (completeness) and this is good to merge.
|
Addressing the 3 Greptile items: Item 1 (top-level json_card.elements): Confirmed critical. The code only checks jsonCard.body.elements, missing schema 1.0 cards that store text in jsonCard.elements. Please also extract from jsonCard.elements before falling through to legacy parsing. Item 2 (rows recursion): Confirmed completeness issue. The rows field is typed but not handled in extractJsonCardTexts. Either add rows recursion or remove rows from the type. Item 3 (type safety): Type cast noted. A narrowly scoped cast (as Record<'card_msg_content_type', string>) would be cleaner than Record<string, string>. Overall the approach is sound and the test coverage is solid. These are all pre-merge fixable items. |
CI Failure AnalysisAll CI failures in this PR are pre-existing on EvidenceOur PR only modifies Main branch CI (run 23627455328) also fails the same jobs:
Our Changes
|
|
Thanks for the thorough review @EronFan! All 3 items addressed: Item 1 (schema 1.0 elements): Fixed — now also extracts from Item 2 (rows recursion): Already removed in the previous commit — confirmed Item 3 (type cast): For Changes pushed — CI should re-run shortly. |
|
All 3 items confirmed addressed:
The feishu extension CI job (extension-fast-feishu) passes. The pre-existing main CI failures are unrelated to this PR. This PR looks good to merge. |
e7ea88f to
9fff12d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9fff12dff4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (node.tag === "plain_text" && typeof node.property?.content === "string") { | ||
| texts.push(node.property.content); | ||
| } | ||
| if (node.tag === "markdown" && typeof (node as { content?: string }).content === "string") { | ||
| texts.push((node as { content?: string }).content!); |
There was a problem hiding this comment.
Handle div nodes when extracting json_card text
With card_msg_content_type=raw_card_content, interactive content can arrive in json_card.elements using schema 1.0 blocks like {"tag":"div","text":{"content":"..."}} (which the legacy parser handled). extractJsonCardTexts currently only collects plain_text and markdown, so json_card payloads containing only div text produce no parts and fall through to parsing the wrapper object, resulting in [Interactive Card] instead of the message text. This regresses thread/message reads for existing schema 1.0 cards unless div.text.content is also extracted (or fallback parsing is applied to the parsed jsonCard object).
Useful? React with 👍 / 👎.
1e2b37c to
4b94e46
Compare
4b94e46 to
0e256f3
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e256f314a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| @@ -122,6 +122,110 @@ describe("getMessageFeishu", () => { | |||
| }); | |||
| expect(mockConvertMarkdownTables).toHaveBeenCalledWith("hello", "preserve"); | |||
| expect(result).toEqual({ messageId: "om_send", chatId: "oc_send" }); | |||
|
|
|||
| it("passes card_msg_content_type param to message.get", async () => { | |||
There was a problem hiding this comment.
Close the first test before declaring new test cases
it("passes card_msg_content_type param to message.get", ...) is currently declared inside the callback of it("sends text without requiring Feishu runtime text helpers", ...) because the outer test is missing its closing }); before this line. In Vitest/Jest-style runners, defining tests during test execution is invalid and can throw a nested-test error, which means this suite can fail and the newly added CardKit assertions won’t actually run as independent test cases.
Useful? React with 👍 / 👎.
51490d8 to
6ec6946
Compare
6ec6946 to
d571323
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d5713233f0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (typeof jsonCard.config?.summary?.content === "string") { | ||
| parts.push(jsonCard.config.summary.content); |
There was a problem hiding this comment.
Avoid prepending summary when body already has full card text
parseInteractiveCardContent always appends config.summary.content before body elements, but streaming cards written by this plugin store only a truncated prefix in summary and the full reply in body content (extensions/feishu/src/streaming-card.ts updates summary via truncateSummary during close). In that common path, reads become "<truncated prefix>\n<full reply>", duplicating the opening text and inflating downstream thread context/token usage; summary should be fallback-only (or deduplicated) when body extraction already succeeds.
Useful? React with 👍 / 👎.
2172598 to
2fb2d64
Compare
2fb2d64 to
d03a87c
Compare
d03a87c to
64e6dab
Compare
…ntent param - Add card_msg_content_type=raw_card_content param to message.get and message.list API calls so the IM API returns the full json_card structure instead of fallback screenshot content for CardKit streaming cards. - Extend parseInteractiveCardContent to extract text from the json_card format: reads config.summary.content and recursively extracts plain_text/markdown nodes from body.elements. Falls through to existing element parsing on failure. - Add extractJsonCardTexts helper for recursive text extraction from nested CardKit element structures (column_set, nested elements, etc.). - Add tests for json_card parsing, param passing, and fallback behavior.
The 'sends text without requiring Feishu runtime text helpers' test was missing its closing '});', causing subsequent test cases to be nested inside it. This fixes test isolation.
64e6dab to
68d3e30
Compare
|
Closing — no longer needed. Thanks for the review @EronFan. |
Problem
When reading messages that were sent as CardKit streaming cards (created via
POST /cardkit/v1/cards), the IM API (GET /im/v1/messages/{message_id}) returns fallback content (a screenshot image + placeholder text like[Interactive Card]) instead of the actual card text content. This makes it impossible to retrieve the full text of bot replies that use streaming cards.Root Cause
CardKit streaming cards are referenced by
card_idin the message body ({"type":"card","data":{"card_id":"xxx"}}). The CardKit API only provides write endpoints — there is no read API to fetch card content bycard_id. However, the IM message read API supports an undocumented query parametercard_msg_content_type=raw_card_contentthat instructs the API to inline the full card structure as ajson_cardfield in the response content.Fix
1. Pass
card_msg_content_typeparameterAdd
card_msg_content_type: "raw_card_content"to both:client.im.message.get()— used bygetMessageFeishu()for single message readsclient.im.message.list()— used bylistFeishuThreadMessages()for thread history2. Parse
json_cardformat inparseInteractiveCardContentBefore the existing element-based parsing, check for the
json_cardfield (a JSON string) and extract text from:config.summary.content— the card summary (streaming cards write the full reply text here)body.elements— recursively extractplain_textandmarkdownnodes, including nested structures likecolumn_setFalls through to the existing
elements/body.elementsparsing ifjson_cardis absent or unparseable.3. Tests
Added 3 new test cases:
card_msg_content_typeparam is passed tomessage.getjson_cardformat is correctly parsed (summary + nested body elements)json_cardcontains invalid JSONRelated Issues
References
card_msg_content_type=raw_card_contentparameter in itsfetchCardContentfunction (src/messaging/inbound/parse-io.ts).