Skip to content

Fix metadata filtering by package in Studio - #1048

Merged
hotlong merged 2 commits into
mainfrom
claude/fix-metadata-filtering-on-package-switch
Apr 2, 2026
Merged

Fix metadata filtering by package in Studio#1048
hotlong merged 2 commits into
mainfrom
claude/fix-metadata-filtering-on-package-switch

Conversation

@Claude

@ClaudeClaudeAI commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

When switching packages in Studio's left sidebar, the metadata panel displayed items from all packages instead of filtering by the selected package. Two root causes: (1) selectedMeta state persisted across package switches, and (2) client.meta.getItem() lacked package filtering despite getItems() already supporting it.

Changes

Frontend

  • Clear selectedMeta state in handleSelectPackage to prevent stale metadata display
  • Thread packageId through PluginHostMetadataViewerPropsMetadataInspector
  • Pass selectedPackage.manifest.id from App to both object and metadata views

Client API

  • Add optional packageId parameter to meta.getItem(type, name, options?)
  • Construct ?package= query string when packageId provided

Backend

  • Extract packageId from query.package in /metadata/:type/:name handler
  • Pass to protocol.getMetaItem({ type, name, packageId })

All changes maintain backward compatibility—packageId is optional throughout.

// Before: metadata from all packages displayedawaitclient.meta.getItem('flow','my_flow')// After: scoped to selected packageawaitclient.meta.getItem('flow','my_flow',{packageId: 'my-package'})

@vercel

vercelBot commented Apr 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
objectstack-playReadyReadyPreview, CommentApr 2, 2026 1:29am
specReadyReadyPreview, CommentApr 2, 2026 1:29am

Request Review

- Clear selectedMeta when switching packages in App.tsx
- Add packageId parameter to client.meta.getItem() method
- Pass selectedPackage.manifest.id through PluginHost to MetadataInspector
- Update backend http-dispatcher to extract and pass packageId to protocol.getMetaItem()
- Update MetadataViewerProps to include optional packageId field
- MetadataInspector now filters metadata by package when packageId is provided
Agent-Logs-Url: https://github.com/objectstack-ai/spec/sessions/fd48007b-701b-4729-85ba-26954cf662ce
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
@ClaudeClaudeAI changed the title [WIP] Fix metadata display issue when switching packages in StudioFix metadata filtering by package in StudioApr 2, 2026
@Claude
ClaudeAI requested a review from hotlongApril 2, 2026 01:28
@hotlong
hotlong marked this pull request as ready for review April 2, 2026 02:42
CopilotAI review requested due to automatic review settings April 2, 2026 02:42
@hotlong
hotlong merged commit da5c2f1 into mainApr 2, 2026
3 checks passed

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to ensure Studio’s metadata inspector is scoped to the currently selected package by clearing stale selection state on package switch and threading an optional packageId filter from Studio UI → client API → backend handler.

Changes:

  • Studio: clear selectedMeta when switching packages and pass selectedPackage.manifest.id into PluginHost/viewer props.
  • Studio plugin/viewer plumbing: add packageId?: string to MetadataViewerProps and forward it through the default viewer into MetadataInspector.
  • Client + runtime: add optional { packageId } to client.meta.getItem(...) and forward ?package= through the runtime metadata handler into protocol.getMetaItem(...).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
packages/runtime/src/http-dispatcher.tsExtracts query.package and forwards it as packageId to protocol.getMetaItem(...).
packages/client/src/index.tsExtends meta.getItem to accept { packageId?: string } and appends ?package= when provided.
apps/studio/src/plugins/types.tsAdds optional packageId to MetadataViewerProps.
apps/studio/src/plugins/plugin-host.tsxAccepts packageId and forwards it into the resolved viewer component.
apps/studio/src/plugins/built-in/default-plugin.tsxForwards packageId into MetadataInspector.
apps/studio/src/components/MetadataInspector.tsxUses packageId when calling client.meta.getItem(...) and reloads when it changes.
apps/studio/src/App.tsxClears selectedMeta on package switch and passes selected package ID into PluginHost.

Comment on lines 436 to 441
// Try Protocol Service First (Preferred)
const protocol = await this.resolveService('protocol');
if (protocol && typeof protocol.getMetaItem === 'function') {
try {
const data = await protocol.getMetaItem({ type: singularType, name });
const data = await protocol.getMetaItem({ type: singularType, name, packageId });
return { handled: true, response: this.success(data) };

CopilotAIApr 2, 2026

Copy link

Choose a reason for hiding this comment

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

packageId is being passed into protocol.getMetaItem(...), but the current protocol implementation in this repo (packages/objectql/src/protocol.ts) defines getMetaItem(request: { type, name }) and ignores any packageId field, so this change won’t actually scope lookups by package. To make package filtering effective, update the protocol contract + implementation to accept packageId and use it when resolving from SchemaRegistry (prefer ${packageId}:${name} / _packageId-tagged items) and in any DB fallback query (e.g., include packageId in the where clause when provided).

Copilot uses AI. Check for mistakes.
Comment on lines 441 to 443
return { handled: true, response: this.success(data) };
} catch (e: any) {
// Protocol might throw if not found or not supported

CopilotAIApr 2, 2026

Copy link

Choose a reason for hiding this comment

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

If protocol.getMetaItem(...) throws, this handler falls through to the broker-based lookup below, which currently does not receive packageId. That means package scoping can be lost depending on which backend implementation is active. Consider ensuring the fallback path also receives the package filter (or explicitly returning a scoped-not-found) to keep behavior consistent.

Copilot uses AI. Check for mistakes.
Comment on lines +387 to +388
// Extract optional package filter from query string
const packageId = query?.package || undefined;

CopilotAIApr 2, 2026

Copy link

Choose a reason for hiding this comment

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

There are existing unit tests for handleMetadata, but none assert the new query.packagepackageId behavior for GET /meta/:type/:name. Add a test that passes a query object with package set and verifies the protocol is invoked with that packageId (and/or that the scoped item is returned).

Copilot uses AI. Check for mistakes.
Sign up for freeto 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.

Studio 左侧切换软件包时元数据未按包过滤

3 participants

@Claude@hotlong