Skip to content

Commit

Permalink
Merge pull request #18 from docker/cm/prompts-method
Browse files Browse the repository at this point in the history
Fix output
  • Loading branch information
ColinMcNeil authored Aug 20, 2024
2 parents 4e6b721 + 7e437fb commit cd6fd7f
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/extension/ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,34 @@ class OutputParser {
this.callback = callback;
}
updateOutput = (line: any) => {
let output = [...this.output];
if (line.method === 'functions') {
const functions = line.params;
for (const func of functions) {
const functionId = func.id;
const existingFunction = output.find(o =>
const existingFunction = this.output.find(o =>
o.method === 'functions'
&&
o.params.find((p: { id: string }) => p.id === functionId)
);
if (existingFunction) {
const existingFunctionParamsIndex = existingFunction.params.findIndex((p: { id: string }) => p.id === functionId);
existingFunction.params[existingFunctionParamsIndex] = { ...existingFunction.params[existingFunctionParamsIndex], ...func };
output = output.map(
this.output = this.output.map(
o => o.method === 'functions'
?
{ ...o, params: o.params.map((p: { id: string }) => p.id === functionId ? { ...p, ...func } : p) }
:
o
);
} else {
output = [...output, line];
this.output = [...this.output, line];
}
}
}
else {
output = [...output, line];
this.output = [...this.output, line];
}
this.callback(output);
this.callback(this.output);
}
}

Expand All @@ -76,12 +75,14 @@ export function App() {

const [runOut, setRunOut] = React.useState<any[]>([]);

const runOutput = new OutputParser(setRunOut);

const scrollRef = React.useRef<HTMLDivElement>(null);

const [showDebug, setShowDebug] = React.useState(false);

useEffect(() => {
const runOutput = new OutputParser(setRunOut);

try {
client.docker.cli.exec("pull", ["vonwig/function_write_files"]).then(() => {
client.docker.cli.exec("run", [
Expand Down Expand Up @@ -167,8 +168,6 @@ export function App() {

const startPrompt = async () => {
track('start-prompt');

const runOutput = new OutputParser(setRunOut);
runOutput.updateOutput({ method: 'message', params: { debug: 'Pulling images' } })

runOutput.updateOutput({ method: 'message', params: { debug: 'Running prompts...' } })
Expand Down

0 comments on commit cd6fd7f

Please sign in to comment.