Skip to content

feat(protocol): preserve media attachment names - #3548

Open
chengluyu wants to merge 7 commits into
mainfrom
feat/preserve-media-attachment-names
Open

feat(protocol): preserve media attachment names#3548
chengluyu wants to merge 7 commits into
mainfrom
feat/preserve-media-attachment-names

Conversation

@chengluyu

@chengluyu chengluyu commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. This is the server-side companion for MoonshotAI/kimi-code-app#532.

Problem

The file store retained original filenames, but image and video message parts dropped them while passing through kap-server, agent events, and transcript reconstruction. Clients therefore lost media filenames after an authoritative transcript refresh, a cold rebuild, or steering.

What changed

  • Added optional filename metadata to image and video message content.
  • Preserved filenames through media resolution, live message projection, turn-start events, cold transcript reconstruction, and steered user frames.
  • Kept historical records valid when the optional name is absent and left provider media payload behavior unchanged.
  • Added regression coverage for ordinary prompts, cold rebuilds, and both immediate and deferred steering paths.
  • Persisted the already-uploaded filename in transcript attachment metadata so authorized session clients can restore it.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (not applicable: internal companion change).
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0dedb84

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-04T20:31:20.360876Z 0dedb84 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Sep 4, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@0dedb84
npx https://pkg.pr.new/@moonshot-ai/kimi-code@0dedb84

commit: 0dedb84

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fe96535219

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

content.push({
type: 'image',
source: { kind: 'url', url: buildDaemonFileUrl(finalFile.meta.id) },
name: part.name ?? file.meta.name,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update the exact prompt response assertions

For file-backed images and videos, this now emits a non-empty name, but the existing integration tests in packages/kap-server/test/prompts.test.ts still compare the complete response against objects without that property. In particular, carries an uncompressed uploaded image... and carries an uploaded video... will fail whenever the kap-server suite runs, so update those expectations to include the preserved filenames rather than reverting the behavior.

AGENTS.md reference: AGENTS.md:L61-L61

Useful? React with 👍 / 👎.

else if (part.type === 'video' && part.source.kind === 'session_media') parts.push({ type: 'video_url', videoUrl: { url: buildDaemonFileUrl(part.source.file_id), id: part.source.file_id } });
else if (part.type === 'image' && part.source.kind === 'url') parts.push({ type: 'image_url', imageUrl: { url: part.source.url, id: part.source.id, name: part.name } });
else if (part.type === 'image' && part.source.kind === 'base64') parts.push({ type: 'image_url', imageUrl: { url: `data:${part.source.media_type};base64,${part.source.data}`, name: part.name } });
else if (part.type === 'image' && part.source.kind === 'session_media') parts.push({ type: 'image_url', imageUrl: { url: buildDaemonFileUrl(part.source.file_id), id: part.source.file_id, name: part.name } });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore names for nameless session-media references

When a client reuses an existing session_media attachment without the new optional name field—as existing clients and historical prompt payloads do—this conversion copies undefined even though assertPromptSessionMediaRefs opens a SessionMediaFile whose persisted metadata includes the original name. Consequently the core part, turn.started attachment, and reconstructed transcript remain nameless; enrich session-media parts from the store metadata when the request omits the name, including the analogous video path.

Useful? React with 👍 / 👎.

content.push({
type: 'image',
source: { kind: 'base64', media_type: compressed.mimeType, data: compressed.base64 },
name: part.name,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve names when base64 images are downgraded

When a named base64 image resolves to a MIME type unsupported by the model, the earlier branch returns before reaching this preserved-name path and constructs the resulting file attachment with the generic image.<ext> name. Thus a valid request such as a named TIFF loses its filename in both the response and cold transcript; use the supplied part.name as the attachment name, with the generated name only as a fallback.

Useful? React with 👍 / 👎.

@chengluyu

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fe96535219

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

content.push({
type: 'image',
source: { kind: 'url', url: buildDaemonFileUrl(finalFile.meta.id) },
name: part.name ?? file.meta.name,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve requested names when uploaded images are downgraded

When a named source.kind === 'file' image has an unsupported model MIME type, such as AVIF, the earlier downgrade branch constructs both the notice and file attachment from file.meta.name and returns before reaching this new part.name fallback. Consequently supported uploaded images preserve the request's filename while unsupported uploaded images silently revert to the upload-store name; apply the same part.name ?? file.meta.name selection in the downgrade branch.

Useful? React with 👍 / 👎.

@chengluyu

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 54d002d2ce

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

export const imageContentSchema = z.object({
type: z.literal('image'),
source: imageSourceSchema,
name: z.string().min(1).optional(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add media names to the shared protocol schemas

When a consumer parses prompt responses, message history, or prompt.submitted/prompt.steered events through @moonshot-ai/protocol, packages/protocol/src/message.ts still omits name from both media schemas, so Zod strips the newly emitted field and the exported ImageContent/VideoContent types cannot expose it. Update the shared image and video schemas alongside this kap-server schema so protocol consumers actually retain the filename.

Useful? React with 👍 / 👎.

@chengluyu

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 670f9ba148

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chengluyu

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 0dedb84fdc

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant