Skip to content
Closed
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
1 change: 1 addition & 0 deletions typescript/packages/common-runtime/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./common_runtime.js";
89 changes: 89 additions & 0 deletions typescript/packages/lookslike-high-level/bundle-type-defs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import fs from 'fs-extra';
import path from 'path';
import {glob} from 'glob';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const outputPath = path.resolve(__dirname, 'src', 'virtualTypeDefs.js');

const modules = [
'@commontools/common-html',
'@commontools/common-builder',
'@commontools/common-runner',
'@commontools/common-runtime',
'@commontools/common-propagator',
];

// Collect lib.d.ts from TypeScript
const tsLibDir = path.join(
path.dirname(path.dirname(new URL(await import.meta.resolve('typescript')).pathname)),
'lib/'
);
const tsLibPath = path.join(
tsLibDir,
'lib.es2015.d.ts'
);
console.log('tsLibPath', tsLibPath);
const libDts = fs.readFileSync(tsLibPath, 'utf-8');

// Collect module .d.ts files
const moduleTypeDefs = {};

modules.forEach(async (module) => {
let dtsPath;
if (module === '@commontools/common-runtime') {
dtsPath = path.resolve(__dirname, '..', 'common-runtime');
} else if (module.startsWith('@commontools/')) {
dtsPath = path.resolve(__dirname, '..', module.replace('@commontools/', ''), 'lib');
} else if (module.startsWith('../') || module.startsWith('./')) {
dtsPath = path.resolve(__dirname, module.replace('.js', '.d.ts'));
}

const dtsFiles = module === '@commontools/common-runtime'
? ['common_runtime.d.ts', 'common_runtime_bg.wasm.d.ts', 'index.d.ts']
: glob.sync('*.d.ts', { cwd: dtsPath });

dtsFiles.forEach((file) => {
console.log('file', file);
moduleTypeDefs[`node_modules/${module}/${file}`] = fs.readFileSync(path.join(dtsPath, file), 'utf-8');
});
});

const libFiles = glob.sync('lib.*.d.ts', { cwd: tsLibDir });
libFiles.forEach((libFile) => {
const content = fs.readFileSync(path.join(tsLibDir, libFile), 'utf-8');
moduleTypeDefs[libFile] = content;
});

// Corrected data.d.ts
moduleTypeDefs['../data.d.ts'] = `
export type Recipe = {
// Define the properties of Recipe here
name: string;
// ... other properties
};

export function launch(recipe: Recipe, props: any): void;
`;

// Add this new entry for the JavaScript file
moduleTypeDefs['../data.js'] = `
// This file can be empty or contain any necessary JavaScript code
`;

// Combine all type definitions
const virtualTypeDefs = {
'lib.es2015.d.ts': libDts,
...moduleTypeDefs,
};

// Generate the virtualTypeDefs.js file
const fileContent = `export const virtualTypeDefs = ${JSON.stringify(virtualTypeDefs, null, 2)};`;

fs.ensureDirSync(path.dirname(outputPath));
fs.writeFileSync(outputPath, fileContent, 'utf-8');

console.log('Bundled type definitions successfully.');
8 changes: 7 additions & 1 deletion typescript/packages/lookslike-high-level/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
},
"homepage": "https://github.com/commontoolsinc/labs#readme",
"devDependencies": {
"fs-extra": "^11.2.0",
"glob": "^11.0.0",
"jsdom": "^25.0.0",
"typescript": "^5.2.2",
"vite": "^5.2.0",
Expand All @@ -35,10 +37,14 @@
"../common-frp:build",
"../common-html:build",
"../lookslike-sagas:build",
"../llm-client:build"
"../llm-client:build",
"bundle-type-defs"
],
"command": "vite build"
},
"bundle-type-defs": {
"command": "node bundle-type-defs.js"
},
"clean": {
"command": "rm -rf ./lib ./dist ./.wireit ./node_modules"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Charm, ID, UI, NAME, addCharms, launch } from "../data.js";
import { CellImpl, isCell, charmById } from "@commontools/common-runner";
import { repeat } from "lit/directives/repeat.js";
import { iframe } from "../recipes/iframe.js";
import { runRemote } from "../runRemote.js";

@customElement("common-window-manager")
export class CommonWindowManager extends LitElement {
Expand Down Expand Up @@ -88,6 +89,33 @@ export class CommonWindowManager extends LitElement {
const shiftHeld = event.detail.shiftHeld;
console.log("Unibox submitted:", value);

if (value.startsWith("https://commoner.m4ke.workers.dev/")) {
runRemote({ url: value });
return;
}

if (value === '' && shiftHeld) {
const charmValues = charm.getAsProxy();
let fieldsToInclude = Object.entries(charmValues).reduce(
(acc, [key, value]) => {
if (!key.startsWith("$") && !key.startsWith("_")) {
acc[key] = value
}
return acc;
},
{} as any
);
const data = JSON.stringify(fieldsToInclude, null, 2);
fetch('https://commoner.m4ke.workers.dev/', {
method: 'POST',
body: data,
}).then(r => r.json()).then(({hash}) => {
// console.log('rv', `https://commoner.m4ke.workers.dev/${hash}`)
window.open(`https://commoner.m4ke.workers.dev/${hash}`, '_blank');
})
return;
}

if (shiftHeld) {
charm.asSimpleCell(["addToPrompt"]).send({ prompt: value } as any);
} else {
Expand Down
122 changes: 41 additions & 81 deletions typescript/packages/lookslike-high-level/src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import { jsonImporter } from "./recipes/jsonImport.js";
import { prompt } from "./recipes/prompts.js";
import { wiki } from "./recipes/wiki.js";
import { helloIsolated } from "./recipes/helloIsolated.js";
import { coder } from "./recipes/coder.js";
import { runz } from "./recipes/runz.js";

export type Charm = {
[ID]: number;
Expand Down Expand Up @@ -66,42 +68,27 @@ export function addCharms(newCharms: CellImpl<any>[]) {
}

addCharms([
run(iframe, {
title: "two way binding counter",
prompt: "counter",
data: { counter: 0 },
}),
run(importCalendar, {}),
run(queryCollections, {
url: "/api/data/",
}),
run(todoList, {
title: "My TODOs",
items: ["Buy groceries", "Walk the dog", "Wash the car"].map((item) => ({
title: item,
done: false,
})),
}),
run(todoList, {
title: "My grocery shopping list",
items: ["milk", "eggs", "bread"].map((item) => ({
title: item,
done: false,
})),
}),
run(ticket, {
title: "Reservation for 'Counterstrike the Musical'",
show: "Counterstrike the Musical",
date: getFridayAndMondayDateStrings().startDate,
location: "New York",
}),
run(routine, {
title: "Morning routine",
// TODO: A lot more missing here, this is just to drive the suggestion.
locations: ["coffee shop with great baristas"],
}),
run(counters, {}),
]);
// run(coder, {
// title: "hello world", src: `const greeting: string = "Hello, TypeScript!";
// console.log(greeting);

// // You can also use TypeScript-specific features
// interface Person {
// name: string;
// age: number;
// }

// const printPerson = (person: Person) => {
// console.log(person.name, 'is', person.age, 'years old');
// };

// printPerson({ name: "Alice", age: 30 });`})
//
]);

setTimeout(() => {
launch(runz, { hash: "ef011d2367e0421df88ef23073fa882557989d7147c3e9f50fb1c42437932e6b" , data: {items: [{title:"hello", count: 123}]}});
}, 1000);

export type RecipeManifest = {
name: string;
Expand All @@ -123,50 +110,6 @@ function addRecipe(recipe: Recipe) {
}

export const recipes: RecipeManifest[] = [
{
name: "Explore dungeon game",
recipeId: addRecipe(dungeon),
},
{
name: "Create a new TODO list",
recipeId: addRecipe(todoList),
},
{
name: "Find places",
recipeId: addRecipe(localSearch),
},
{
name: "Find a LuftBnB place to stay",
recipeId: addRecipe(luftBnBSearch),
},
{
name: "JSON Importer",
recipeId: addRecipe(jsonImporter),
},
{
name: "Data Designer",
recipeId: addRecipe(dataDesigner),
},
{
name: "Create a counter",
recipeId: addRecipe(counter),
},
{
name: "Fetch JSON from a URL",
recipeId: addRecipe(fetchExample),
},
{
name: "Explore imagery prompts",
recipeId: addRecipe(prompt),
},
{
name: "Explore Halucinated wiki",
recipeId: addRecipe(wiki),
},
{
name: "Hello Isolated",
recipeId: addRecipe(helloIsolated),
},
];

// Helper for mock data
Expand All @@ -192,7 +135,7 @@ function getFridayAndMondayDateStrings() {
}

// Terrible hack to open a charm from a recipe
let openCharmOpener: (charmId: number) => void = () => {};
let openCharmOpener: (charmId: number) => void = () => { };
export const openCharm = (charmId: number) => openCharmOpener(charmId);
openCharm.set = (opener: (charmId: number) => void) => {
openCharmOpener = opener;
Expand All @@ -219,9 +162,26 @@ export function launch(recipe: Recipe, bindings: any) {
);
}
const charm = run(recipe, bindings);
persist(charm) // put in the collection / add a ts to make it unique id

openCharm(charm.get()[ID]);
}

import {createJsonSchema} from "@commontools/common-builder";

function persist(charm: CellImpl<any>) {
// let data = charm.get()
// let schema = createJsonSchema({}, data);
// let query = createDataQuery(schema)
// assert(id, "query", query)
// // asert all the things - if isCellReference is true, then check if the cell has an ID
// assert(hash, "hash")

// from the cells, determine the schema...
// write to synopsys both the schema and the data and recipe hash
// if shared synopsys ... this ID is enough to re-hydrate the charm ... including the recipe
}

(window as any).recipes = recipes;
(window as any).charms = charms;

Expand Down
Loading