Commit Graph
35 Commits
Author SHA1 Message Date
Bogdan Chadkin 0c6a5ebbba refactor: migrate dashboard to postgrest (#3902)
Bumped type-fest everywhere to cast DashboardProject view
2024-08-09 17:47:49 +02:00
Bogdan Chadkin a904d2cdc7 feat: add markdown embed component (#3884)
Ref https://github.com/webstudio-is/webstudio/issues/3485

Added component with descendants support.

<img width="861" alt="Screenshot 2024-08-06 at 15 53 33"
src="https://github.com/user-attachments/assets/4c488573-f52c-4661-b626-cedc113ee10c">
2024-08-07 00:51:41 +02:00
Bogdan Chadkin 8ed3400167 build: switch to eslint 9 (#3877)
We finally can switch to the latest eslint
with new config format.
2024-08-05 09:23:57 +02:00
Oleg Isonen e0552f0815 fix: Ensure AI doesn't return json markdown (#3809)
## Description

Detect route started returning json in markdown instead of pure json
`json\n[\"generate-template-prompt\"]\n`

## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env` file
2024-07-28 14:26:17 +02:00
Bogdan Chadkin a58f2eff04 build: run all tests and typechecks in CI (#3661)
Here improved our checks. No longet rely on "checks" script but run
"test" and "typescript" scripts from each package in monorepo.

Would also make each package less boilerplaty.
2024-07-02 18:21:05 +03:00
Ivan Starkov 4d0574d573 build: Update typescript (#3637)
## Description

1. What is this PR about (link the issue and add a short description)

## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env` file
2024-06-28 11:46:13 +03:00
Oleg Isonen 0cf24fbcd5 chore: Update gpt 3.5 model and improve reliability (#3541)
Closes https://github.com/webstudio-is/webstudio/issues/3517

## Description

Completion would often start with \`\`\`json instead of the actual json
that we want to parse, so I added a command to not start with \`\`\`json

## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env` file
2024-06-12 10:41:12 +02:00
Bogdan Chadkin 7128bc9204 build: publish 0.151.0 (#3297) 2024-05-04 16:56:39 +04:00
Ivan Starkov 6d5e55b892 build: Update react + typescript hotfix (#3194)
## Description

Use canary react 

## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env.example`
and the `builder/env-check.js` if mandatory
2024-04-17 22:23:37 +03:00
Bogdan Chadkin 6f3ac9d20a refactor: drop fetch polyfills (#3125)
Remix Vite no longer polyfills streams and fetch.
Should be safe to drop them.

Stream polyfills broke ai, fetch broke trpc.
2024-04-10 10:56:56 +07:00
Bogdan Chadkin ecc7c75e84 build: remove unused build scripts (#3123)
dev, build and dts are not necessary in not published packages and can
be removed. Builder vite setup is able to access webstudio export
conditions. Only prisma client need to be built before builder.

This will reduce CI time which runs build many times in various
workflows.
2024-04-09 20:46:22 +07:00
Bogdan Chadkin 9136430cb5 refactor: restructure ai package (#3118)
Here refactored ai package to better split server and client parts and
not leak babel to client.

This save ~100kB in our bundle size.
2024-04-09 13:05:48 +07:00
Bogdan Chadkin b93a7ab181 refactor: bump prisma (#3115)
Here bumped prisma to the latest version
which supports new driver adapters as preview feature.

Also simplified prisma-client build and got rid from build-package
script. prisma-client package files are now commonjs only to avoid
issues with modern bundlers.
2024-04-08 21:27:39 +07:00
Oleg Isonen cd0174807d chore: use console.info instead of console.log (#3049)
## Description

We allow console.info (btw we should also allow warn/error/info), we
only disallow console.log in the linter because that's what we use for
debugging.

## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @TrySound , I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env.example`
and the `builder/env-check.js` if mandatory
2024-03-24 12:52:46 +01:00
Ivan Starkov bdbb33f7b6 fix: Update zod (#2996)
## Description

fixes email validation hangs
https://github.com/colinhacks/zod/issues/2580


## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env.example`
and the `builder/env-check.js` if mandatory
2024-03-12 14:03:43 +03:00
Ivan Starkov f89f53486f feat: Add anonymous logger of prompts (#2497)
## Description

1. What is this PR about (link the issue and add a short description)

## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env.example`
and the `builder/env-check.js` if mandatory
2023-10-16 23:23:39 +03:00
GiuseppeandGiuseppe Gurgone cf6a1f8e3e fix: Instruct model to rewrite text when necessary (#2487)
Improve how the model writes, instructing it to ignore the
current value.

Co-authored-by: Giuseppe Gurgone <gsppe@users.noreply.github.com>
2023-10-15 23:08:37 +02:00
Giuseppe 0cefb0385c fix: Miscellaneous AI fixes (#2483)
Fixes:

- Disable Radix components via feat flag
- classNames should be optional when generating templates
- Prevent unwrapped JSX to fail
- Use shared computeSelectorForInstanceId when inserting templates and deleting instances
- Add extra instruction for GPT to fill required values just in case
2023-10-15 21:39:57 +02:00
Ivan Starkov cfba6556d0 fix: AI Command Bar error processing (#2472)
## Description

Rate Limiting toasts.
Mic enable toast.
Improved Error messages toasts for debugability reasons. 


## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env.example`
and the `builder/env-check.js` if mandatory
2023-10-15 13:59:27 +03:00
Bogdan Chadkin 724ad6c9c3 feat: add attribution to images generated by ai (#2477)
Added title prop with `Credit: author` for attribution.

<img width="978" alt="image"
src="https://github.com/webstudio-is/webstudio/assets/5635476/1e984fe1-f57d-4441-ae72-8fa3314133b1">
2023-10-15 12:14:15 +04:00
Giuseppe acfc8c4166 fix: Improve operations detection (#2470)
After detecting a command via /rest/ai/detect we invoke the /rest/ai
endpoint with the command. If the command is not a text generation, we
run the operations chain that supports multiple operations in the same
prompt.

Instead of refactoring the entire operations chain to support
configurable operations, for now in this PR I am just prepending the
user prompt with the `command` name in order to help the AI
disambiguate.
2023-10-13 17:40:47 +02:00
Giuseppe b2ffc4b0b6 refactor: AI improvements (#2461)
Some smaller AI prompt improvements.
2023-10-12 19:35:47 +02:00
Giuseppe c069ff0d18 fix: Suggest to generate custom styles when requested (#2458)
When asking specific values that don't have a Tailwind class, the AI
should generate custom classes using Tailwind's square brackets
notation.

Tweaking the prompts to ask for this
2023-10-12 15:51:18 +02:00
Bogdan Chadkin 81e58fe1f5 feat: search images in pexels with ai (#2453)
Added basic support for generating images with ai. AI generates jsx with
`<img alt="">` and we use the alt to search images in pexels.
2023-10-12 11:57:06 +04:00
Giuseppe ec15ed4cd9 fix: AI fixes and improvements (#2451) 2023-10-11 14:05:26 +02:00
Giuseppe dda50628a6 refactor: Split AI commands detection and execution (#2444)
As per title the PR splits command detection and execution in two
endpoints.

We will first make a request to the /rest/ai/detect endpoint which will
return an array with one or multiple detected commands for the prompt.
Once we have that we execute them in parallel.

Rewrote the temporary UI completion handler to do all the above. Error
handling will still have to be polished to account for special cases
like rate limiting etc.
2023-10-10 17:53:12 +02:00
Giuseppe 309d178ae5 refactor: Rename StreamingTextResponse to RemixStreamingTextResponse (#2434)
As per title rename StreamingTextResponse to RemixStreamingTextResponse,
this is to it is more explicit why we have the class
2023-10-09 15:50:55 +02:00
Giuseppe a054b4cf6d fix: JSX attributes parsing (#2435)
Removes markdown code block delimiters from JSX the parser utility and
adds a new utility to extract code blocks from LLM responses.

There was a bug in the previous implementation where we were parsing the JSX stripped out of code blocks
delimiters but when extracting the props from the source string we were slicing the original string with delimiters.
2023-10-09 14:41:25 +02:00
Giuseppe 4040b8ccc2 refactor: Replace request helper with ai request handler (#2433)
The AI request helper now takes a `Promise<Response>` coming from
calling fetch() outside of the helper eg. `handleAiRequest(fetch(...))`

In this PR I also fixed the casing of GPT* types
2023-10-09 11:41:46 +02:00
Giuseppe 43b2e7e23c feat: Merge copywriter with commands (#2419)
Unifies the operations AI endpoint with the copywriter feature. Introducing a chain to do feature-detection on user prompts.
2023-10-09 10:43:14 +02:00
Bogdan Chadkin 7e824eb1e4 build: bump checks (#2425)
- esbuild
- jest
- eslint
- eslint-typescript

Also removed "jest" binary from packages and use the one installed in
the root
and deduplicated all deps (got a little messy recently).
2023-10-06 16:33:33 +04:00
Giuseppe b3dd7f18c4 feat: AI Operations (#2391)
Implements an operation-based system to accomplish a number of edit
tasks on a JSX+CSS representation of a selected Webstudio tree.

Every JSX element has the instance id as data-ws-id and therefore the
LLM knows what to edit.

The idea is to create a number of operations (aiOperations)
specs/schemas with Zod describing unique edit tasks, make a
discriminated union, convert them to JSON Schema. We then inject this
information and the current JSX+CSS in the LLM prompt asking the model
to generate an array of operations.

The LLM responds with an array of operations (aiOperations) to fulfill
the user request. We then process these doing the necessary
transformations to convert these to a Webstudio-friendly format
(wsOperations) and send them to the client where we apply them (see
applyOperations).

Some of these operations are going to be "intermediate" operations for
now.

Generating quality user interfaces might be challenging with LLMs.

Having to do so within a generic operations framework like the one
described above makes it even more challenging.

For this reason when it comes to generating user interfaces, the
Operation chain instead offers an operation called
generateTemplatePrompt that provides information about insertion point
in the existing UI and a prompt, possibly enhanced.

Another chain can use these information and a more sophisticated prompt
and model to then generate the user interface and return a
generateInsertTemplate wsOperation. Webstudio does exactly this in a
rest endpoint, using the template-generator chain with gpt4 instead of
gpt-3.5-turbo.
2023-10-06 09:07:59 +02:00
Giuseppe 99be84b56b refactor: Rework LLM client types and implementations (#2417)
Refactor the LLM client, responses shape and web client to support
streaming and regular json request in a single helper.
2023-10-05 09:28:10 +02:00
Giuseppe ccf0280a20 feat: AI Copywriter (#2314)
## Description

Implement AI copywriter functionality behind feature flag. The final UI is not included in this branch.

The feature consists of:

- a `copywriter` chain to generate the copy with AI
- a /rest/ai/copy endpoint to handle generation requests. The response
is streamed as plain text
- the temporary test UI which is a tab in the right sidebar. 
 
For every selected instance it allows to generate copy for it and its
subtree. A `collectTextInstances` utility creates an array of text nodes
objects with the following shape:

```ts
{
  instanceId: string;
  index: number;
  type: "Heading" | "Paragraph" | "Text";
  text: string; // current text or empty
}
```

The AI responds with an array of these where the text property contains
the generated text. The frontend parses incrementally and updates a
Webstudio instance by `instanceId`.

The `index` is used to replace the proper text node in the
`instance.children` array. When all the children are text nodes these
are merged into a single text node, otherwise the AI would generate
`children.length` copy. We identify this case by setting the `index` to
`-1`.
2023-10-03 10:34:26 +02:00
Giuseppe 61c7960d3c feat: AI Package (#2307)
This PR introduces the baseline `@webstudio-is/ai` package which
includes:

1. A LLM Abstraction (types) for messages format to make requests to a
model
2. An implementation of the above that uses the OpenAI chat completion
endpoint
3. A common interface for chains. Chains are regular async functions
that can execute an arbitrary number of steps, including calling a LLM
via a model client.

The idea is that a builder API route can use any of these chains to
perform a task that requires AI. For example generate text copy, images,
a theme etc.
2023-09-25 10:59:44 +02:00