Skip to content

Commit

Permalink
add create card instance command
Browse files Browse the repository at this point in the history
  • Loading branch information
burieberry committed Feb 20, 2025
1 parent 868be56 commit f577894
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/host/app/commands/create-card-instance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { service } from '@ember/service';

import { type LooseSingleCardDocument } from '@cardstack/runtime-common';

import type * as BaseCommandModule from 'https://cardstack.com/base/command';

import HostBaseCommand from '../lib/host-base-command';

import CardService from '../services/card-service';

export default class CreateCardInstanceCommand extends HostBaseCommand<
typeof BaseCommandModule.CreateInstanceInput
> {
@service declare private cardService: CardService;

description = `Create a new card instance given a card ref and realm.`;

async getInputType() {
let commandModule = await this.loadCommandModule();
const { CreateInstanceInput } = commandModule;
return CreateInstanceInput;
}

protected async run(
input: BaseCommandModule.CreateInstanceInput,
): Promise<undefined> {
if (!input.module || !input.realm) {
throw new Error(
"Create instance command can't run because it doesn't have all the fields in arguments returned by open ai",
);
}
let doc: LooseSingleCardDocument = {
data: {
meta: {
adoptsFrom: input.module,
realmURL: input.realm,
},
},
};
await this.cardService.createFromSerialized(doc.data, doc);
}
}

0 comments on commit f577894

Please sign in to comment.