Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/lang-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openuidev/lang-core",
"version": "0.2.8",
"version": "0.2.9",
"description": "Framework-agnostic core for OpenUI Lang: parser, prompt generation, validation, and type definitions",
"license": "MIT",
"type": "module",
Expand Down
21 changes: 21 additions & 0 deletions packages/lang-core/src/__tests__/library.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,27 @@ describe("per-library registry", () => {
expect(spec.schema).toEqual(lib.toJSONSchema());
});

it("toSpec carries the createLibrary id, omitted when unset", () => {
const Text = defineComponent({
name: "TextContent",
props: z.object({ text: z.string() }),
description: "text",
component: Dummy,
});

const named = createLibrary({
components: [Text],
root: "TextContent",
id: "acme-support@3",
});
expect(named.id).toBe("acme-support@3");
expect(named.toSpec().id).toBe("acme-support@3");

const anonymous = createLibrary({ components: [Text], root: "TextContent" });
expect(anonymous.id).toBeUndefined();
expect("id" in anonymous.toSpec()).toBe(false);
});

it("toJSONSchema carries defineComponent descriptions on $defs entries", () => {
const Text = defineComponent({
name: "TextContent",
Expand Down
4 changes: 4 additions & 0 deletions packages/lang-core/src/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export interface Library<C = unknown> {
readonly components: Record<string, DefinedComponent<any, C>>;
readonly componentGroups: ComponentGroup[] | undefined;
readonly root: string | undefined;
readonly id: string | undefined;

prompt(options?: PromptOptions): string;
toSpec(): PromptSpec;
Expand All @@ -346,6 +347,7 @@ export interface LibraryDefinition<C = unknown> {
components: DefinedComponent<any, C>[];
componentGroups?: ComponentGroup[];
root?: string;
id?: string;
}

/**
Expand All @@ -371,6 +373,7 @@ export function createLibrary<C = unknown>(input: LibraryDefinition<C>): Library
components: componentsRecord,
componentGroups: input.componentGroups,
root: input.root,
id: input.id,

prompt(options?: PromptOptions): string {
const spec: PromptSpec = {
Expand All @@ -388,6 +391,7 @@ export function createLibrary<C = unknown>(input: LibraryDefinition<C>): Library
components: buildComponentSpecs(componentsRecord, reg),
componentGroups: input.componentGroups,
schema: buildJSONSchema(),
...(input.id !== undefined ? { id: input.id } : {}),
};
},

Expand Down
1 change: 1 addition & 0 deletions packages/lang-core/src/parser/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface ComponentGroup {
}

export interface BaseSpec {
id?: string;
root?: string;
components: Record<string, ComponentPromptSpec>;
componentGroups?: ComponentGroup[];
Expand Down
Loading