support import from code
This commit is contained in:
parent
089f4302d2
commit
c900201417
@ -337,27 +337,20 @@ function App() {
|
|||||||
// Set input state
|
// Set input state
|
||||||
setIsImportedFromCode(true);
|
setIsImportedFromCode(true);
|
||||||
|
|
||||||
console.log(code);
|
|
||||||
|
|
||||||
// Set up this project
|
// Set up this project
|
||||||
// TODO*
|
|
||||||
// setGeneratedCode(code);
|
|
||||||
setStack(stack);
|
setStack(stack);
|
||||||
// setAppHistory([
|
|
||||||
// {
|
// Set up the import commit
|
||||||
// type: "code_create",
|
const commit = createCommit({
|
||||||
// parentIndex: null,
|
type: "code_create",
|
||||||
// code,
|
parentHash: null,
|
||||||
// inputs: { code },
|
date_created: new Date(),
|
||||||
// },
|
variants: [{ code }],
|
||||||
// ]);
|
selectedVariantIndex: 0,
|
||||||
// setVariant(0, {
|
inputs: null,
|
||||||
// type: "code_create",
|
});
|
||||||
// parentIndex: null,
|
addCommit(commit);
|
||||||
// code,
|
setHead(commit.hash);
|
||||||
// });
|
|
||||||
// setCurrentVariantIndex(0);
|
|
||||||
// setCurrentVersion(0);
|
|
||||||
|
|
||||||
// Set the app state
|
// Set the app state
|
||||||
setAppState(AppState.CODE_READY);
|
setAppState(AppState.CODE_READY);
|
||||||
|
|||||||
@ -22,7 +22,11 @@ export default function HistoryDisplay({ shouldDisableReverts }: Props) {
|
|||||||
// TODO: Clean this up
|
// TODO: Clean this up
|
||||||
|
|
||||||
const newHistory = Object.values(commits).flatMap((commit) => {
|
const newHistory = Object.values(commits).flatMap((commit) => {
|
||||||
if (commit.type === "ai_create" || commit.type === "ai_edit") {
|
if (
|
||||||
|
commit.type === "ai_create" ||
|
||||||
|
commit.type === "ai_edit" ||
|
||||||
|
commit.type === "code_create"
|
||||||
|
) {
|
||||||
return {
|
return {
|
||||||
type: commit.type,
|
type: commit.type,
|
||||||
hash: commit.hash,
|
hash: commit.hash,
|
||||||
|
|||||||
@ -17,8 +17,12 @@ export type BaseCommit = {
|
|||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
|
|
||||||
// TODO: Move to a different file
|
// TODO: Move to a different file
|
||||||
|
// TODO: Fix the type to be better
|
||||||
export function createCommit(
|
export function createCommit(
|
||||||
commit: Omit<AiCreateCommit, "hash"> | Omit<AiEditCommit, "hash">
|
commit:
|
||||||
|
| Omit<AiCreateCommit, "hash">
|
||||||
|
| Omit<AiEditCommit, "hash">
|
||||||
|
| Omit<CodeCreateCommit, "hash">
|
||||||
): Commit {
|
): Commit {
|
||||||
const hash = nanoid();
|
const hash = nanoid();
|
||||||
return { ...commit, hash };
|
return { ...commit, hash };
|
||||||
@ -38,7 +42,12 @@ export type AiEditCommit = BaseCommit & {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Commit = AiCreateCommit | AiEditCommit;
|
export type CodeCreateCommit = BaseCommit & {
|
||||||
|
type: "code_create";
|
||||||
|
inputs: null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Commit = AiCreateCommit | AiEditCommit | CodeCreateCommit;
|
||||||
|
|
||||||
export type RenderedHistoryItem = {
|
export type RenderedHistoryItem = {
|
||||||
type: string;
|
type: string;
|
||||||
|
|||||||
@ -8,23 +8,20 @@ export function extractHistory(
|
|||||||
|
|
||||||
let currentCommitHash: CommitHash | null = hash;
|
let currentCommitHash: CommitHash | null = hash;
|
||||||
while (currentCommitHash !== null) {
|
while (currentCommitHash !== null) {
|
||||||
const commit: Commit = commits[currentCommitHash];
|
const commit: Commit | null = commits[currentCommitHash];
|
||||||
|
|
||||||
if (commit) {
|
if (commit) {
|
||||||
if (commit.type === "ai_create") {
|
|
||||||
// Don't include the image for ai_create
|
|
||||||
flatHistory.unshift(commit.variants[commit.selectedVariantIndex].code);
|
|
||||||
} else if (commit.type === "ai_edit") {
|
|
||||||
flatHistory.unshift(commit.variants[commit.selectedVariantIndex].code);
|
flatHistory.unshift(commit.variants[commit.selectedVariantIndex].code);
|
||||||
|
|
||||||
|
// For edits, add the prompt to the history
|
||||||
|
if (commit.type === "ai_edit") {
|
||||||
flatHistory.unshift(commit.inputs.prompt);
|
flatHistory.unshift(commit.inputs.prompt);
|
||||||
}
|
}
|
||||||
// } else if (item.type === "code_create") {
|
|
||||||
// flatHistory.unshift(item.code);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Move to the parent of the current item
|
// Move to the parent of the current item
|
||||||
currentCommitHash = commit.parentHash;
|
currentCommitHash = commit.parentHash;
|
||||||
} else {
|
} else {
|
||||||
|
// TODO*: Send to Sentry
|
||||||
throw new Error("Malformed history: missing parent index");
|
throw new Error("Malformed history: missing parent index");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,6 +36,8 @@ export function summarizeHistoryItem(commit: Commit) {
|
|||||||
return "Create";
|
return "Create";
|
||||||
case "ai_edit":
|
case "ai_edit":
|
||||||
return commit.inputs.prompt;
|
return commit.inputs.prompt;
|
||||||
|
case "code_create":
|
||||||
|
return "Imported from code";
|
||||||
default: {
|
default: {
|
||||||
const exhaustiveCheck: never = commitType;
|
const exhaustiveCheck: never = commitType;
|
||||||
throw new Error(`Unhandled case: ${exhaustiveCheck}`);
|
throw new Error(`Unhandled case: ${exhaustiveCheck}`);
|
||||||
|
|||||||
@ -3,13 +3,17 @@ import { useProjectStore } from "../../store/project-store";
|
|||||||
function Variants() {
|
function Variants() {
|
||||||
const { head, commits, updateSelectedVariantIndex } = useProjectStore();
|
const { head, commits, updateSelectedVariantIndex } = useProjectStore();
|
||||||
|
|
||||||
// TODO: Is HEAD null right? And check variants.length === 0 ||
|
// TODO*: Is HEAD null right? And check variants.length === 0 ||
|
||||||
if (head === null) {
|
if (head === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const variants = commits[head || ""].variants;
|
const variants = commits[head].variants;
|
||||||
const selectedVariantIndex = commits[head || ""].selectedVariantIndex;
|
const selectedVariantIndex = commits[head].selectedVariantIndex;
|
||||||
|
|
||||||
|
if (variants.length <= 1) {
|
||||||
|
return <div className="mt-2"></div>;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mt-4 mb-4">
|
<div className="mt-4 mb-4">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user