Skip to content

Commit 0a2937d

Browse files
committed
Tag entities with hash of zod schema and query by it
1 parent 6317cae commit 0a2937d

File tree

12 files changed

+286
-55
lines changed

12 files changed

+286
-55
lines changed

typescript/package-lock.json

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typescript/packages/common-system/src/rule-builder.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ export class Select<Match extends Selector = Selector> {
195195
return { ...this.#select };
196196
}
197197

198+
get constraints(): WhereBuilder {
199+
return this.#where;
200+
}
201+
198202
get clauses(): Clause[] {
199203
return this.#where.commit();
200204
}

typescript/packages/lookslike-high-level/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"merkle-reference": "^1.1.0",
6868
"mermaid": "^11.4.1",
6969
"panzoom": "^9.4.3",
70-
"zod": "^3.x.x",
70+
"zod": "^3.24.1",
7171
"zod-to-json-schema": "^3.23.3"
7272
},
7373
"overrides": {

typescript/packages/lookslike-high-level/src/components/shader-layer.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export class ShaderLayer extends LitElement {
88
@property({ type: Number }) width = 640;
99
@property({ type: Number }) height = 480;
1010
@property({ type: String }) blendMode = 'default';
11+
@property({ type: String, reflect: true }) errorMessage: string | null = null;
1112

1213
private canvasRef = createRef<HTMLCanvasElement>();
1314
private gl?: WebGLRenderingContext;
@@ -17,7 +18,6 @@ export class ShaderLayer extends LitElement {
1718
private animationFrame?: number;
1819
private startTime = performance.now();
1920
private vertexShader?: WebGLShader;
20-
private errorMessage: string | null = null;
2121

2222
static override styles = css`
2323
:host {
@@ -87,6 +87,7 @@ export class ShaderLayer extends LitElement {
8787
});
8888
if (!gl) {
8989
this.errorMessage = "WebGL not supported";
90+
this.requestUpdate();
9091
return;
9192
}
9293
this.gl = gl;
@@ -97,6 +98,7 @@ export class ShaderLayer extends LitElement {
9798
const vertexShader = gl.createShader(gl.VERTEX_SHADER);
9899
if (!vertexShader) {
99100
this.errorMessage = "Failed to create vertex shader";
101+
this.requestUpdate();
100102
return;
101103
}
102104
this.vertexShader = vertexShader;
@@ -113,6 +115,7 @@ export class ShaderLayer extends LitElement {
113115

114116
if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
115117
this.errorMessage = `Vertex shader error: ${gl.getShaderInfoLog(vertexShader)}`;
118+
this.requestUpdate();
116119
return;
117120
}
118121

@@ -138,12 +141,14 @@ export class ShaderLayer extends LitElement {
138141
const program = gl.createProgram();
139142
if (!program) {
140143
this.errorMessage = "Failed to create program";
144+
this.requestUpdate();
141145
return;
142146
}
143147

144148
const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
145149
if (!fragmentShader) {
146150
this.errorMessage = "Failed to create fragment shader";
151+
this.requestUpdate();
147152
return;
148153
}
149154

@@ -153,6 +158,7 @@ export class ShaderLayer extends LitElement {
153158
if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
154159
this.errorMessage = `Fragment shader error: ${gl.getShaderInfoLog(fragmentShader)}`;
155160
gl.deleteShader(fragmentShader);
161+
this.requestUpdate();
156162
return;
157163
}
158164

@@ -164,6 +170,7 @@ export class ShaderLayer extends LitElement {
164170
this.errorMessage = `Program linking error: ${gl.getProgramInfoLog(program)}`;
165171
gl.deleteShader(fragmentShader);
166172
gl.deleteProgram(program);
173+
this.requestUpdate();
167174
return;
168175
}
169176

typescript/packages/lookslike-high-level/src/data.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { musicLibrary } from "./spells/18_music.jsx";
6161
import { spellManager } from './spells/19_process_manager.jsx'
6262
import { shaderManager } from './spells/20_shader_editor.jsx'
6363
import { schemaGenerator } from './spells/21_model_builder.jsx'
64+
import { search } from './spells/22_search.jsx'
6465

6566
export type Charm = {
6667
[NAME]?: string;
@@ -260,6 +261,7 @@ addCharms([
260261
spellManager.spawn({ spellManager: 1 }),
261262
shaderManager.spawn({ shaderManager: 1 }),
262263
schemaGenerator.spawn({ schemaGenerator: 1 }),
264+
search.spawn({ search: 1 }),
263265
FetchService.spawn() as any,
264266
GmailService.spawn() as any,
265267
ViewService.spawn() as any,

typescript/packages/lookslike-high-level/src/spells/18_music.tsx

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ import { Reference } from "merkle-reference";
1010
import { importEntity, resolve } from "../sugar/sugar.jsx";
1111
import { Ref, UiFragment } from "../sugar/zod.js";
1212

13-
const Artist = z.object({
13+
export const Artist = z.object({
1414
name: z.string().min(1).max(255).describe("The name of the artist"),
1515
});
1616

17-
const Song = z.object({
17+
export const Song = z.object({
1818
title: z.string().min(1).max(255).describe("The title of the song"),
1919
artists: z.array(Artist).min(1).describe("The artists who performed the song"),
2020
duration: z.number().min(1).describe("The duration in seconds"),
2121
year: z.number().min(1900).max(2100).describe("The release year")
2222
});
2323

24-
const Album = z.object({
24+
export const Album = z.object({
2525
"album/title": z.string().min(1).max(255).describe("The album title"),
2626
artist: Artist.describe("The primary artist"),
2727
songs: z.array(Song).min(1).describe("The songs on the album"),
@@ -151,51 +151,51 @@ const playlistEditor = typedBehavior(Playlist, {
151151

152152
export const musicLibrary = typedBehavior(
153153
MusicLibrary.pick({
154-
focused: true,
154+
// focused: true,
155155
'~/common/ui/artist-list': true,
156156
'~/common/ui/song-list': true,
157157
'~/common/ui/album-list': true,
158158
'~/common/ui/playlist-list': true
159159
}), {
160-
render: ({ self, focused, '~/common/ui/artist-list': artistList, '~/common/ui/song-list': songList, '~/common/ui/album-list': albumList, '~/common/ui/playlist-list': playlistList }) => (
161-
<div entity={self}>
160+
render: ({
161+
self,
162+
'~/common/ui/artist-list': artistList,
163+
'~/common/ui/song-list': songList,
164+
'~/common/ui/album-list': albumList,
165+
'~/common/ui/playlist-list': playlistList
166+
}) => (
167+
<div entity={self} title="Music">
162168
<div>
163-
{focused ? (
164-
<div>
165-
<button onclick="~/on/close-editor">Close</button>
166-
<Charm self={focused} spell={songEditor as any} />
167-
</div>
168-
) : (
169-
<div>
170-
<h3>Add Artist</h3>
171-
<common-form
172-
schema={Artist}
173-
reset
174-
onsubmit="~/on/add-artist"
175-
/>
176-
<h3>Add Song</h3>
177-
<common-form
178-
schema={Song}
179-
referenceFields={new Set(['artists'])}
180-
reset
181-
onsubmit="~/on/add-song"
182-
/>
183-
<h3>Add Album</h3>
184-
<common-form
185-
schema={Album}
186-
referenceFields={new Set(['artist', 'songs'])}
187-
reset
188-
onsubmit="~/on/add-album"
189-
/>
190-
<h3>Add Playlist</h3>
191-
<common-form
192-
schema={Playlist}
193-
referenceFields={new Set(['songs'])}
194-
reset
195-
onsubmit="~/on/add-playlist"
196-
/>
197-
</div>
198-
)}
169+
<div>
170+
<h3>Add Artist</h3>
171+
<common-form
172+
schema={Artist}
173+
reset
174+
onsubmit="~/on/add-artist"
175+
/>
176+
<h3>Add Song</h3>
177+
<common-form
178+
schema={Song}
179+
referenceFields={new Set(['artists'])}
180+
reset
181+
onsubmit="~/on/add-song"
182+
/>
183+
<h3>Add Album</h3>
184+
<common-form
185+
schema={Album}
186+
referenceFields={new Set(['artist', 'songs'])}
187+
reset
188+
onsubmit="~/on/add-album"
189+
/>
190+
<h3>Add Playlist</h3>
191+
<common-form
192+
schema={Playlist}
193+
referenceFields={new Set(['songs'])}
194+
reset
195+
onsubmit="~/on/add-playlist"
196+
/>
197+
</div>
198+
199199
</div>
200200

201201
<div>

typescript/packages/lookslike-high-level/src/spells/19_process_manager.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { event, subview, Transact } from "../sugar.js";
1010
import { Charm as CharmComponent, initRules, typedBehavior, typedService } from "./spell.jsx";
1111
import { z } from "zod";
1212
import { fromString, Reference } from "merkle-reference";
13-
import { importEntity, resolve } from "../sugar/sugar.jsx";
13+
import { importEntity, resolve, tagWithSchema } from "../sugar/sugar.jsx";
1414
import { Ref, UiFragment } from "../sugar/zod.js";
1515
import { tsToExports } from "../localBuild.js";
1616
import { sendMessage } from "./stickers/chat.jsx";
@@ -40,7 +40,7 @@ const generateIdentifier = () => {
4040
};
4141

4242
// Define the core schemas
43-
const Spell = z.object({
43+
export const Spell = z.object({
4444
name: z.string().min(1).max(255).describe("The name of the spell"),
4545
sourceCode: z.string().min(1).max(8192).describe("The spell's source code"),
4646
notes: z.string().describe("Notes about the spell"),
@@ -163,6 +163,7 @@ const spellEditor = typedBehavior(Spell, {
163163
const ev = Session.resolve<SubmitEvent<z.infer<typeof Spell>>>(event);
164164
const spell = ev.detail.value;
165165
cmd.add(...Transact.set(self, spell))
166+
cmd.add(tagWithSchema(self, Spell))
166167
}),
167168

168169
onModifyWithAI: event("~/on/modify-with-ai")
@@ -674,7 +675,7 @@ export const spellManager = typedBehavior(
674675
'~/common/ui/charm-list': true
675676
}), {
676677
render: ({ self, editingSpell, focusedCharm, '~/common/ui/spell-list': spellList, '~/common/ui/charm-list': charmList }) => (
677-
<div entity={self}>
678+
<div entity={self} title="Spell Manager">
678679
<div>
679680
<details>
680681
<h3>Create New Spell</h3>

typescript/packages/lookslike-high-level/src/spells/20_shader_editor.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { event, subview, Transact } from "../sugar.js";
99
import { Charm, initRules, typedBehavior } from "./spell.jsx";
1010
import { z } from "zod";
1111
import { Reference } from "merkle-reference";
12-
import { importEntity, resolve } from "../sugar/sugar.jsx";
12+
import { importEntity, resolve, tagWithSchema } from "../sugar/sugar.jsx";
1313
import { Ref, UiFragment } from "../sugar/zod.js";
1414
import { llm, RESPONSE } from "../effects/fetch.jsx";
1515

@@ -45,7 +45,7 @@ const SHADER_TEMPLATE = ` precision mediump float;
4545
`;
4646

4747
// Define the core schemas
48-
const Shader = z.object({
48+
export const Shader = z.object({
4949
name: z.string().min(1).max(255).describe("The name of the shader"),
5050
sourceCode: z.string().min(1).max(8192).describe("The shader's GLSL source code"),
5151
notes: z.string().describe("Notes about the shader")
@@ -107,6 +107,7 @@ const shaderEditor = typedBehavior(Shader, {
107107
const ev = Session.resolve<SubmitEvent<z.infer<typeof Shader>>>(event);
108108
const shader = ev.detail.value;
109109
cmd.add(...Transact.set(self, shader))
110+
cmd.add(tagWithSchema(self, Shader))
110111
}),
111112

112113
onModifyWithAI: event("~/on/modify-with-ai")
@@ -156,7 +157,7 @@ export const shaderManager = typedBehavior(
156157
'~/common/ui/navigation': true
157158
}), {
158159
render: ({ self, editingShader, '~/common/ui/shader-list': shaderList, '~/common/ui/navigation': navigation }) => (
159-
<div entity={self}>
160+
<div entity={self} title="Genuary">
160161
<div>
161162
<details>
162163
<h3>Create New Shader</h3>

typescript/packages/lookslike-high-level/src/spells/21_model_builder.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ type SubmitEvent<T> = {
111111

112112
export const schemaGenerator = typedBehavior(SchemaGenerator, {
113113
render: ({ self, description, generatedCode, mermaidDiagram }) => (
114-
<div entity={self}>
114+
<div entity={self} title="Domain Model Generator">
115115
<h3>Domain Model Generator</h3>
116116
<common-form
117117
schema={DomainModel}

0 commit comments

Comments
 (0)