checkpoint
This commit is contained in:
parent
754e7afd5b
commit
f5440bfddc
|
|
@ -20,7 +20,7 @@ type IPrompt = TLBaseShape<
|
||||||
w: number
|
w: number
|
||||||
h: number
|
h: number
|
||||||
prompt: string
|
prompt: string
|
||||||
output: string
|
value: string
|
||||||
agentBinding: string | null
|
agentBinding: string | null
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|
@ -37,7 +37,7 @@ export class PromptShape extends BaseBoxShapeUtil<IPrompt> {
|
||||||
w: 300,
|
w: 300,
|
||||||
h: 50,
|
h: 50,
|
||||||
prompt: "",
|
prompt: "",
|
||||||
output: "",
|
value: "",
|
||||||
agentBinding: null,
|
agentBinding: null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -84,12 +84,15 @@ export class PromptShape extends BaseBoxShapeUtil<IPrompt> {
|
||||||
this.editor.updateShape<IPrompt>({
|
this.editor.updateShape<IPrompt>({
|
||||||
id: shape.id,
|
id: shape.id,
|
||||||
type: "prompt",
|
type: "prompt",
|
||||||
props: { output: partial, agentBinding: done ? null : 'someone' },
|
props: { value: partial, agentBinding: done ? null : 'someone' },
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlePrompt = () => {
|
const handlePrompt = () => {
|
||||||
|
if (shape.props.agentBinding) {
|
||||||
|
return
|
||||||
|
}
|
||||||
let processedPrompt = shape.props.prompt;
|
let processedPrompt = shape.props.prompt;
|
||||||
for (const [key, sourceShape] of Object.entries(inputMap)) {
|
for (const [key, sourceShape] of Object.entries(inputMap)) {
|
||||||
const pattern = `{${key}}`;
|
const pattern = `{${key}}`;
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ export class SocialShapeUtil extends BaseBoxShapeUtil<ISocialShape> {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HTMLContainer style={{ padding: 4, borderRadius: 4, border: '1px solid #ccc', outline: shape.props.syntaxError ? '2px solid orange' : 'none' }} onPointerDown={(e) => e.stopPropagation()}>
|
<HTMLContainer style={{ padding: 4, borderRadius: 4, border: '1px solid #ccc', outline: shape.props.syntaxError ? '2px solid orange' : 'none' }} onPointerDown={(e) => e.stopPropagation()}>
|
||||||
<textarea style={{ width: '100%', height: '50%', border: '1px solid lightgrey', resize: 'none', pointerEvents: 'all' }} value={shape.props.text} onChange={(e) => handleTextChange(e.target.value)} />
|
<textarea style={{ width: '100%', height: '60%', border: '1px solid lightgrey', resize: 'none', pointerEvents: 'all' }} value={shape.props.text} onChange={(e) => handleTextChange(e.target.value)} />
|
||||||
<ValueInterface
|
<ValueInterface
|
||||||
type={shape.props.valueType ?? null}
|
type={shape.props.valueType ?? null}
|
||||||
value={shape.props.values[currentUser] ?? defaultValues[shape.props.valueType as keyof typeof defaultValues]}
|
value={shape.props.values[currentUser] ?? defaultValues[shape.props.valueType as keyof typeof defaultValues]}
|
||||||
|
|
@ -103,13 +103,21 @@ export class SocialShapeUtil extends BaseBoxShapeUtil<ISocialShape> {
|
||||||
private updateValue(shapeId: TLShapeId) {
|
private updateValue(shapeId: TLShapeId) {
|
||||||
const shape = this.editor.getShape(shapeId) as ISocialShape
|
const shape = this.editor.getShape(shapeId) as ISocialShape
|
||||||
const valueType = shape.props.valueType
|
const valueType = shape.props.valueType
|
||||||
console.log("SHAPE", shape)
|
// console.log("SHAPE", shape)
|
||||||
const vals = Array.from(Object.values(shape.props.values))
|
const vals = Array.from(Object.values(shape.props.values))
|
||||||
console.log("VALS", vals)
|
// console.log("VALS", vals)
|
||||||
// const functionBody = `return (${shape.props.text.replace(valueType, vals)})`
|
|
||||||
|
// Check for "sum" or "average" followed by whitespace or end of string
|
||||||
|
const invalidFunctionUsage = /\b(sum|average)(\s|$)/.test(shape.props.text)
|
||||||
|
|
||||||
|
if (invalidFunctionUsage) {
|
||||||
|
this.updateProps(shape, { syntaxError: true })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const functionBody = `return ${shape.props.text.replace(valueType, 'VALUES')};`
|
const functionBody = `return ${shape.props.text.replace(valueType, 'VALUES')};`
|
||||||
|
|
||||||
console.log("FUNCTION BODY", functionBody)
|
// console.log("FUNCTION BODY", functionBody)
|
||||||
const sum = (vals: number[] | boolean[]) => {
|
const sum = (vals: number[] | boolean[]) => {
|
||||||
if (valueType === 'SCALAR') {
|
if (valueType === 'SCALAR') {
|
||||||
return (vals as number[]).reduce((acc, val) => acc + val, 0)
|
return (vals as number[]).reduce((acc, val) => acc + val, 0)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue