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
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { LitElement, html, css } from "lit-element";
import { customElement, property } from "lit/decorators.js";
import { RecipeNode } from "../../data.js";
import {
WASM_SANDBOX,
SES_SANDBOX,
CONFIDENTIAL_COMPUTE_SANDBOX
} from "@commontools/runtime";

const styles = css``;

Expand All @@ -16,6 +21,9 @@ export class ComModuleCode extends LitElement {
return html`<pre>loading...</pre>`;
}

// HACK: force SES by default
this.node.evalMode = this.node.evalMode || SES_SANDBOX;

const codeChanged = (ev: CustomEvent) => {
if (!this.node) return;

Expand All @@ -38,12 +46,29 @@ export class ComModuleCode extends LitElement {
this.dispatchEvent(event);
};

const onChangeEvalMode = (ev: Event) => {
const select = ev.target as HTMLSelectElement;
this.node.evalMode = select.value as any;
this.requestUpdate();
};

return html`
<com-code .code=${this.node.body} @updated=${codeChanged}></com-code>
<com-data
.data=${JSON.stringify(this.value, null, 2)}
@updated=${dataChanged}
></com-data>
<select
name="evalMode"
@change=${onChangeEvalMode}
.value=${this.node.evalMode}
>
<option value=${SES_SANDBOX}>SES</option>
<option value=${WASM_SANDBOX}>WASM</option>
<option value=${CONFIDENTIAL_COMPUTE_SANDBOX}>
CONFIDENTIAL COMPUTE
</option>
</select>
`;
}
}
124 changes: 67 additions & 57 deletions typescript/packages/lookslike-prototype/src/data.ts
Original file line number Diff line number Diff line change
@@ -1,95 +1,105 @@
export type Recipe = RecipeNode[]
export type NodePath = [string, string]
import {
CONFIDENTIAL_COMPUTE_SANDBOX,
SES_SANDBOX,
WASM_SANDBOX
} from "@commontools/runtime";

export type Recipe = RecipeNode[];
export type NodePath = [string, string];
export type InputMap = { [port: string]: NodePath };

export type EvalMode =
| typeof WASM_SANDBOX
| typeof SES_SANDBOX
| typeof CONFIDENTIAL_COMPUTE_SANDBOX;

export type RecipeNode = {
id: string, // an actual unique ID
messages?: Message[], // could be empty if a user hand-authored the node etc.
contentType: string,
outputType: any,
in: InputMap,
body: string | object
id: string; // an actual unique ID
messages?: Message[]; // could be empty if a user hand-authored the node etc.
contentType: string;
outputType: any;
in: InputMap;
body: string | object;
evalMode?: EvalMode;
};

export type Message = {
role: 'user' | 'assistant',
content: string,
}
role: "user" | "assistant";
content: string;
};

export const emptyGraph: Recipe = [];
export const todoAppMockup: Recipe = [
{
"id": "todos",
"messages": [
id: "todos",
messages: [
{
"role": "user",
"content": "get my todos"
role: "user",
content: "get my todos"
},
{
"role": "assistant",
"content": "..."
role: "assistant",
content: "..."
}
],
"contentType": "text/javascript",
"in": {},
"outputType": {
"$id": "https://common.tools/stream.schema.json",
"type": {
"$id": "https://common.tools/todos.json"
contentType: "text/javascript",
in: {},
outputType: {
$id: "https://common.tools/stream.schema.json",
type: {
$id: "https://common.tools/todos.json"
}
},
"body": "return system.get('todos')"
body: "return system.get('todos')"
},
{
"id": "todoUi",
"messages": [
id: "todoUi",
messages: [
{
"role": "user",
"content": "render todo"
role: "user",
content: "render todo"
},
{
"role": "assistant",
"content": "..."
role: "assistant",
content: "..."
}
],
"contentType": "application/json+vnd.common.ui",
"in": {
"todos": [".", "todos"]
contentType: "application/json+vnd.common.ui",
in: {
todos: [".", "todos"]
},
"outputType": {
"$id": "https://common.tools/ui.schema.json"
outputType: {
$id: "https://common.tools/ui.schema.json"
},
"body": {
"tag": "ul",
"props": {
"className": "todo"
body: {
tag: "ul",
props: {
className: "todo"
},
"children": {
"type": "repeat",
"binding": "todos",
"template": {
"tag": "li",
"props": {},
"children": [
children: {
type: "repeat",
binding: "todos",
template: {
tag: "li",
props: {},
children: [
{
"tag": "input",
"props": {
"type": "checkbox",
"checked": { type: 'boolean', binding: 'checked' }
tag: "input",
props: {
type: "checkbox",
checked: { type: "boolean", binding: "checked" }
}
},
{
"tag": "span",
"props": {
"className": "todo-label"
tag: "span",
props: {
className: "todo-label"
},
"children": [
{ type: 'string', binding: 'label' }
]
children: [{ type: "string", binding: "label" }]
}
]
}
}
}
}
]
];
6 changes: 4 additions & 2 deletions typescript/packages/lookslike-prototype/src/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
WASM_SANDBOX,
SES_SANDBOX
} from "@commontools/runtime";
import { EvalMode } from "./data.js";

export function prepare(code: string) {
const func = new Function(
Expand All @@ -23,7 +24,8 @@ export function serializationBoundary(obj: any) {
export async function run(
id: string,
src: string,
inputs: { [key: string]: any }
inputs: { [key: string]: any },
evalMode: EvalMode = "ses"
) {
console.group("eval(" + id + ")");
const rt = new Runtime();
Expand All @@ -33,7 +35,7 @@ export async function run(

const module = await rt.eval(
id,
SES_SANDBOX,
evalMode,
"text/javascript",
code(src),
new Input(storage, Object.keys(inputs))
Expand Down
2 changes: 1 addition & 1 deletion typescript/packages/lookslike-prototype/src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async function executeNode(
if (typeof node.body !== "string") {
throw new Error("Expected a string");
}
const result = await run(node.id, node.body, inputs);
const result = await run(node.id, node.body, inputs, node.evalMode);
outputs[node.id].send(result);
break;
}
Expand Down