Skip to content

The Open Standard for Generative UI

Add Optional Identifier for Component Libraries (#749)

ABd66cf7bb99eb
diff --git a/packages/lang-core/package.json b/packages/lang-core/package.json
index c7063a6d0..4773a1223 100644
--- a/packages/lang-core/package.json
+++ b/packages/lang-core/package.json
@@ -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",
diff --git a/packages/lang-core/src/__tests__/library.test.ts b/packages/lang-core/src/__tests__/library.test.ts
index 7c877ccc1..fbdbf617b 100644
--- a/packages/lang-core/src/__tests__/library.test.ts
+++ b/packages/lang-core/src/__tests__/library.test.ts
@@ -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",
diff --git a/packages/lang-core/src/library.ts b/packages/lang-core/src/library.ts
index 4008ab5bf..98af3bfe3 100644
--- a/packages/lang-core/src/library.ts
+++ b/packages/lang-core/src/library.ts
@@ -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;
@@ -346,6 +347,7 @@ export interface LibraryDefinition<C = unknown> {
components: DefinedComponent<any, C>[];
componentGroups?: ComponentGroup[];
root?: string;
+ id?: string;
}
/**
@@ -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 = {
@@ -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 } : {}),
};
},
diff --git a/packages/lang-core/src/parser/prompt.ts b/packages/lang-core/src/parser/prompt.ts
index d5dce4907..302ca80ce 100644
--- a/packages/lang-core/src/parser/prompt.ts
+++ b/packages/lang-core/src/parser/prompt.ts
@@ -27,6 +27,7 @@ export interface ComponentGroup {
}
export interface BaseSpec {
+ id?: string;
root?: string;
components: Record<string, ComponentPromptSpec>;
componentGroups?: ComponentGroup[];