Skip to content

Commit 838df0e

Browse files
authored
Change CardDef.id to be RRI (#4845)
1 parent 88461dd commit 838df0e

31 files changed

Lines changed: 162 additions & 123 deletions

packages/ai-bot/tests/prompt-construction-test.ts

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ module('buildPromptForModel', (hooks) => {
146146
currentFile: 'http://localhost:4201/experiments/Author/1',
147147
moduleInspectorPanel: 'preview',
148148
previewPanelSelection: {
149-
cardId: 'http://localhost:4201/experiments/Author/1',
149+
cardId: rri('http://localhost:4201/experiments/Author/1'),
150150
format: 'isolated',
151151
},
152152
},
@@ -245,7 +245,7 @@ Current date and time: 2025-06-11T11:43:00.533Z
245245
},
246246
moduleInspectorPanel: 'preview',
247247
previewPanelSelection: {
248-
cardId: 'http://localhost:4201/experiments/Author/1',
248+
cardId: rri('http://localhost:4201/experiments/Author/1'),
249249
format: 'isolated',
250250
},
251251
},
@@ -464,7 +464,7 @@ Current date and time: 2025-06-11T11:43:00.533Z
464464
body: 'Hey',
465465
data: {
466466
context: {
467-
openCardIds: ['http://localhost:4201/experiments/Author/1'],
467+
openCardIds: [rri('http://localhost:4201/experiments/Author/1')],
468468
tools: [],
469469
submode: 'interact',
470470
realmUrl: 'http://localhost:4201/experiments',
@@ -1426,7 +1426,7 @@ Attached Files (files with newer versions don't show their content):
14261426
},
14271427
],
14281428
context: {
1429-
openCardIds: ['http://localhost:4201/experiments/Friend/1'],
1429+
openCardIds: [rri('http://localhost:4201/experiments/Friend/1')],
14301430
submode: 'interact',
14311431
tools: [],
14321432
functions: [],
@@ -1593,16 +1593,19 @@ Attached Files (files with newer versions don't show their content):
15931593
body: 'set the name to dave',
15941594
data: {
15951595
context: {
1596-
openCardIds: ['http://localhost:4201/experiments/Friend/1'],
1596+
openCardIds: [rri('http://localhost:4201/experiments/Friend/1')],
15971597
tools: [
1598-
getPatchTool('http://localhost:4201/experiments/Friend/1', {
1599-
attributes: {
1600-
type: 'object',
1601-
properties: {
1602-
firstName: { type: 'string' },
1598+
getPatchTool(
1599+
rri('http://localhost:4201/experiments/Friend/1'),
1600+
{
1601+
attributes: {
1602+
type: 'object',
1603+
properties: {
1604+
firstName: { type: 'string' },
1605+
},
16031606
},
16041607
},
1605-
}),
1608+
),
16061609
],
16071610
submode: 'interact',
16081611
functions: [],
@@ -1679,7 +1682,7 @@ Attached Files (files with newer versions don't show their content):
16791682
body: 'set the name to dave',
16801683
data: {
16811684
context: {
1682-
openCardIds: ['http://localhost:4201/drafts/Author/1'],
1685+
openCardIds: [rri('http://localhost:4201/drafts/Author/1')],
16831686
tools: [],
16841687
submode: 'code',
16851688
functions: [],
@@ -1755,7 +1758,7 @@ Attached Files (files with newer versions don't show their content):
17551758
let cardMessageContent = eventList[0].content as CardMessageContent;
17561759
cardMessageContent.data.context ||= {};
17571760
cardMessageContent.data.context.tools = [
1758-
getPatchTool('http://localhost:4201/drafts/Author/1', {
1761+
getPatchTool(rri('http://localhost:4201/drafts/Author/1'), {
17591762
attributes: { firstName: { type: 'string' } },
17601763
}),
17611764
];
@@ -1811,13 +1814,16 @@ Attached Files (files with newer versions don't show their content):
18111814
body: 'set the name to dave',
18121815
data: {
18131816
context: {
1814-
openCardIds: ['http://localhost:4201/experiments/Friend/1'],
1817+
openCardIds: [rri('http://localhost:4201/experiments/Friend/1')],
18151818
tools: [
1816-
getPatchTool('http://localhost:4201/experiments/Friend/1', {
1817-
attributes: {
1818-
firstName: { type: 'string' },
1819+
getPatchTool(
1820+
rri('http://localhost:4201/experiments/Friend/1'),
1821+
{
1822+
attributes: {
1823+
firstName: { type: 'string' },
1824+
},
18191825
},
1820-
}),
1826+
),
18211827
],
18221828
submode: 'interact',
18231829
functions: [],
@@ -1842,16 +1848,19 @@ Attached Files (files with newer versions don't show their content):
18421848
body: 'set the location to home',
18431849
data: {
18441850
context: {
1845-
openCardIds: ['http://localhost:4201/experiments/Meeting/2'],
1851+
openCardIds: [rri('http://localhost:4201/experiments/Meeting/2')],
18461852
tools: [
1847-
getPatchTool('http://localhost:4201/experiments/Meeting/2', {
1848-
attributes: {
1849-
type: 'object',
1850-
properties: {
1851-
location: { type: 'string' },
1853+
getPatchTool(
1854+
rri('http://localhost:4201/experiments/Meeting/2'),
1855+
{
1856+
attributes: {
1857+
type: 'object',
1858+
properties: {
1859+
location: { type: 'string' },
1860+
},
18521861
},
18531862
},
1854-
}),
1863+
),
18551864
],
18561865
submode: 'interact',
18571866
functions: [],
@@ -2364,7 +2373,7 @@ Attached Files (files with newer versions don't show their content):
23642373
clientGeneratedId: '5bb0493e-64a3-4d8b-a99a-722daf084bee',
23652374
data: {
23662375
context: {
2367-
openCardIds: ['http://localhost:4201/drafts/Author/1'],
2376+
openCardIds: [rri('http://localhost:4201/drafts/Author/1')],
23682377
tools: [
23692378
{
23702379
type: 'function',
@@ -2485,7 +2494,7 @@ Attached Files (files with newer versions don't show their content):
24852494
clientGeneratedId: 'd93c899f-9123-4b31-918c-a525afb40a7e',
24862495
data: {
24872496
context: {
2488-
openCardIds: ['http://localhost:4201/drafts/Author/1'],
2497+
openCardIds: [rri('http://localhost:4201/drafts/Author/1')],
24892498
tools: [
24902499
{
24912500
type: 'function',
@@ -2583,7 +2592,7 @@ Attached Files (files with newer versions don't show their content):
25832592
format: 'org.matrix.custom.html',
25842593
data: {
25852594
context: {
2586-
openCardIds: ['http://localhost:4201/drafts/Author/1'],
2595+
openCardIds: [rri('http://localhost:4201/drafts/Author/1')],
25872596
functions: [],
25882597
},
25892598
},
@@ -2665,7 +2674,7 @@ Attached Files (files with newer versions don't show their content):
26652674
}),
26662675
},
26672676
context: {
2668-
openCardIds: ['http://localhost:4201/drafts/Author/1'],
2677+
openCardIds: [rri('http://localhost:4201/drafts/Author/1')],
26692678
tools: [],
26702679
submode: 'interact',
26712680
functions: [],

packages/base/card-api.gts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,7 +2356,7 @@ export type EditCardFn = (
23562356
opts?: { useBaseTemplate?: boolean },
23572357
) => void;
23582358

2359-
export type SaveCardFn = (id: string) => void;
2359+
export type SaveCardFn = (id: RealmResourceIdentifier) => void;
23602360

23612361
export type DeleteCardFn = (cardOrId: CardDef | URL | string) => Promise<void>;
23622362

@@ -2740,7 +2740,9 @@ export class FileDef extends BaseDef {
27402740
}
27412741
}
27422742

2743-
@field id = contains(ReadOnlyField);
2743+
@field id: RealmResourceIdentifier = contains(
2744+
ReadOnlyField,
2745+
) as unknown as RealmResourceIdentifier;
27442746
@field sourceUrl = contains(StringField);
27452747
@field url = contains(StringField);
27462748
@field name = contains(StringField);
@@ -2900,7 +2902,9 @@ export class CardDef extends BaseDef {
29002902
// notify glimmer to rerender this card
29012903
notifyCardTracking(this);
29022904
}
2903-
@field id = contains(ReadOnlyField);
2905+
@field id: RealmResourceIdentifier = contains(
2906+
ReadOnlyField,
2907+
) as unknown as RealmResourceIdentifier;
29042908
@field cardInfo = contains(CardInfoField);
29052909
@field cardTitle = contains(StringField, {
29062910
computeVia: function (this: CardDef) {
@@ -3462,7 +3466,7 @@ function trackRuntimeRelationshipModuleDependencies(
34623466
}
34633467
}
34643468

3465-
export function setId(instance: CardDef, id: string) {
3469+
export function setId(instance: CardDef, id: RealmResourceIdentifier) {
34663470
let field = getField(instance, 'id');
34673471
if (field) {
34683472
setField(instance, field, id);

packages/base/matrix-event.gts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
CodeRef,
2828
APP_BOXEL_LLM_MODE,
2929
type LLMMode,
30+
type RealmResourceIdentifier,
3031
} from '@cardstack/runtime-common';
3132
import { type SerializedFile } from './file-api';
3233

@@ -191,7 +192,7 @@ export interface BoxelErrorForContext {
191192

192193
export interface BoxelContext {
193194
agentId?: string;
194-
openCardIds?: string[];
195+
openCardIds?: RealmResourceIdentifier[];
195196
realmUrl?: string;
196197
realmPermissions?: {
197198
canRead: boolean;
@@ -210,7 +211,7 @@ export interface BoxelContext {
210211
currentFile?: string;
211212
moduleInspectorPanel?: string;
212213
previewPanelSelection?: {
213-
cardId: string;
214+
cardId: RealmResourceIdentifier;
214215
format: string;
215216
};
216217
selectedCodeRef?: CodeRef;

packages/catalog-realm/commands/collect-submission-files.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
planModuleInstall,
1010
type ListingPathResolver,
1111
type LooseSingleCardDocument,
12+
type RealmResourceIdentifier,
1213
type Relationship,
1314
} from '@cardstack/runtime-common';
1415
import type { CopyInstanceMeta } from '@cardstack/runtime-common/catalog';
@@ -310,11 +311,11 @@ export default class CollectSubmissionFilesCommand extends Command<
310311
let getCardCommand = new GetCardCommand(this.commandContext);
311312
let serializeCardCommand = new SerializeCardCommand(this.commandContext);
312313

313-
const instancesById = new Map<string, CardDef>();
314-
const visited = new Set<string>();
315-
const queue: string[] = instances
314+
const instancesById = new Map<RealmResourceIdentifier, CardDef>();
315+
const visited = new Set<RealmResourceIdentifier>();
316+
const queue: RealmResourceIdentifier[] = instances
316317
.map((instance) => instance.id)
317-
.filter((id): id is string => typeof id === 'string');
318+
.filter((id): id is RealmResourceIdentifier => typeof id === 'string');
318319

319320
while (queue.length > 0) {
320321
const id = queue.shift();

packages/catalog-realm/crm-app/components/base-task-planner.gts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export type FilterType = 'status' | 'assignee';
8585

8686
// Type definitions for the card structure
8787
export interface TaskCard extends CardDef {
88-
id: string;
8988
status?: {
9089
label: string;
9190
index: number;

packages/catalog-realm/sprint-planner/components/base-task-planner.gts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export type FilterType = 'status' | 'assignee';
8585

8686
// Type definitions for the card structure
8787
export interface TaskCard extends CardDef {
88-
id: string;
8988
status?: {
9089
label: string;
9190
index: number;

packages/experiments-realm/components/base-task-planner.gts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export type FilterType = 'status' | 'assignee';
8585

8686
// Type definitions for the card structure
8787
export interface TaskCard extends CardDef {
88-
id: string;
8988
status?: {
9089
label: string;
9190
index: number;

packages/host/app/commands/listing-install.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
PlanBuilder,
1212
extractRelationshipIds,
1313
type Relationship,
14+
type RealmResourceIdentifier,
1415
} from '@cardstack/runtime-common';
1516
import { logger } from '@cardstack/runtime-common';
1617
import type { CopyInstanceMeta } from '@cardstack/runtime-common/catalog';
@@ -162,11 +163,11 @@ export default class ListingInstallCommand extends HostBaseCommand<
162163

163164
// Walk relationships by fetching linked cards and enqueueing their ids.
164165
private async expandInstances(instances: CardDef[]): Promise<CardDef[]> {
165-
let instancesById = new Map<string, CardDef>();
166-
let visited = new Set<string>();
167-
let queue: string[] = instances
166+
let instancesById = new Map<RealmResourceIdentifier, CardDef>();
167+
let visited = new Set<RealmResourceIdentifier>();
168+
let queue: RealmResourceIdentifier[] = instances
168169
.map((instance) => instance.id)
169-
.filter((id): id is string => typeof id === 'string');
170+
.filter((id): id is RealmResourceIdentifier => typeof id === 'string');
170171

171172
// - Queue of ids to traverse; visited prevents duplicate relationship ids.
172173
// - Each loop extracts relationship ids and enqueues them, so we descend

packages/host/app/commands/open-create-listing-modal.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { service } from '@ember/service';
22

3-
import { isFieldDef } from '@cardstack/runtime-common';
3+
import {
4+
isFieldDef,
5+
type RealmResourceIdentifier,
6+
} from '@cardstack/runtime-common';
47
import { loadCardDef } from '@cardstack/runtime-common/code-ref';
58

69
import type * as BaseCommandModule from 'https://cardstack.com/base/command';
@@ -42,7 +45,7 @@ export default class OpenCreateListingModalCommand extends HostBaseCommand<
4245
this.operatorModeStateService.showCreateListingModal({
4346
codeRef: input.codeRef,
4447
targetRealm: input.targetRealm,
45-
openCardIds: input.openCardIds,
48+
openCardIds: input.openCardIds as RealmResourceIdentifier[] | undefined,
4649
declarationKind,
4750
});
4851
}

packages/host/app/commands/show-card.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default class ShowCardCommand extends HostBaseCommand<
7878
}
7979
this.playgroundPanelService.persistSelections(
8080
internalKeyFor(cardDefRef, undefined),
81-
input.cardId,
81+
rri(input.cardId),
8282
(input.format as Format) || 'isolated',
8383
undefined,
8484
);

0 commit comments

Comments
 (0)