Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(blocks): add action config for ai answer ui component #6580

Merged
merged 2 commits into from
Mar 27, 2024

Conversation

Flrande
Copy link
Member

@Flrande Flrande commented Mar 27, 2024

const pageModeSpecs = PageEditorBlockSpecs.map(spec => {
    if (spec.schema.model.flavour === 'affine:page') {
      const newPageSpec: BlockSpec = {
        ...spec,
        view: {
          ...spec.view,
          widgets: {
            ...spec.view.widgets,
            [AFFINE_AI_ACTION_PANEL_WIDGET]: literal`${unsafeStatic(
              AFFINE_AI_ACTION_PANEL_WIDGET
            )}`,
          },
        },
        setup: (slots, disposableGroup) => {
          let answer = '';
          disposableGroup.add(
            slots.widgetConnected.on(view => {
              if (view.component instanceof AffineAIActionPanelWidget) {
                view.component.config = {
                  answerRenderer: answer => html`<div>${answer}</div>`,
                  generateAnswer: ({ input, update, finish, signal }) => {
                    const interval = setInterval(() => {
                      answer += input;
                      update(answer);
                    }, 1000);
                    const timeout = setTimeout(() => {
                      clearInterval(interval);
                      // finish('error');
                      finish('success');
                    }, 5000);
                    signal.addEventListener('abort', () => {
                      clearInterval(interval);
                      clearTimeout(timeout);
                    });
                  },

                  finishStateConfig: {
                    responses: [
                      {
                        icon: InsertBelowIcon,
                        text: 'Example Response',
                        handler: () => {},
                      },
                    ],
                    actions: [
                      {
                        head: 'Example Action',
                        items: [
                          {
                            icon: InsertBelowIcon,
                            text: 'Example Action',
                            handler: () => {},
                          },
                        ],
                      },
                    ],
                  },
                  errorStateConfig: {
                    upgrade: () => {},
                    responses: [],
                  },
                };
              }
            })
          );
        },
      };
      return newPageSpec;
    }
    return spec;
  });
CleanShot.2024-03-27.at.11.29.05.mp4

Copy link

vercel bot commented Mar 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
blocksuite ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 27, 2024 5:09am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
blocksuite-docs ⬜️ Ignored (Inspect) Visit Preview Mar 27, 2024 5:09am

@Flrande Flrande merged commit 5516874 into master Mar 27, 2024
19 checks passed
@Flrande Flrande deleted the flrande/ai-answer-0327 branch March 27, 2024 06:19
darkskygit pushed a commit to toeverything/AFFiNE that referenced this pull request Apr 10, 2024
## Features
- toeverything/blocksuite#6679 @pengx17
- toeverything/blocksuite#6620 @doouding
- toeverything/blocksuite#6602 @golok727
- toeverything/blocksuite#6661 @Flrande
- toeverything/blocksuite#6591 @fundon
- toeverything/blocksuite#6634 @golok727
- toeverything/blocksuite#6626 @regischen
- toeverything/blocksuite#6630 @Saul-Mirone
- toeverything/blocksuite#6605 @donteatfriedrice
- toeverything/blocksuite#6614 @zzj3720
- toeverything/blocksuite#6508 @doouding
- toeverything/blocksuite#6578 @donteatfriedrice
- toeverything/blocksuite#6572 @zzj3720
- toeverything/blocksuite#6571 @golok727
- toeverything/blocksuite#6573 @fundon
- toeverything/blocksuite#6580 @Flrande
- toeverything/blocksuite#6540 @golok727
- toeverything/blocksuite#6567 @Flrande
- toeverything/blocksuite#6565 @zzj3720
- toeverything/blocksuite#6561 @zzj3720

## Bugfix
- toeverything/blocksuite#6677 @donteatfriedrice
- toeverything/blocksuite#6681 @fundon
- toeverything/blocksuite#6673 @fundon
- toeverything/blocksuite#6652 @fundon
- toeverything/blocksuite#6641 @fourdim
- toeverything/blocksuite#6649 @golok727
- toeverything/blocksuite#6648 @doouding
- toeverything/blocksuite#6662 @Flrande
- toeverything/blocksuite#6659 @zkwolf
- toeverything/blocksuite#6644 @doouding
- toeverything/blocksuite#6633 @golok727
- toeverything/blocksuite#6632 @golok727
- toeverything/blocksuite#6622 @RubaXa
- toeverything/blocksuite#6622 @RubaXa
- toeverything/blocksuite#6622 @RubaXa
- toeverything/blocksuite#6622 @RubaXa
- toeverything/blocksuite#6622 @RubaXa
- toeverything/blocksuite#6600 @fourdim
- toeverything/blocksuite#6617 @zzj3720
- toeverything/blocksuite#6618 @Flrande
- toeverything/blocksuite#6576 @fundon
- toeverything/blocksuite#6595 @fundon
- toeverything/blocksuite#6596 @zzj3720
- toeverything/blocksuite#6574 @fundon
- toeverything/blocksuite#6593 @Saul-Mirone
- toeverything/blocksuite#6588 @zzj3720
- toeverything/blocksuite#6590 @zzj3720
- toeverything/blocksuite#6589 @zzj3720
- toeverything/blocksuite#6584 @lawvs
- toeverything/blocksuite#6579 @fundon
- toeverything/blocksuite#6538 @golok727
- toeverything/blocksuite#6570 @zzj3720
- toeverything/blocksuite#6569 @zzj3720
- toeverything/blocksuite#6564 @zzj3720
- toeverything/blocksuite#6563 @zzj3720

## Refactor
- toeverything/blocksuite#6683 @doodlewind
- toeverything/blocksuite#6668 @Flrande
- toeverything/blocksuite#6635 @donteatfriedrice
- toeverything/blocksuite#6653 @fundon
- toeverything/blocksuite#6615 @Flrande
- toeverything/blocksuite#6534 @Saul-Mirone
- toeverything/blocksuite#6553 @golok727

## Misc
- chore(examples): cleanup types
- toeverything/blocksuite#6664 @fourdim
- toeverything/blocksuite#6657 @fourdim
- toeverything/blocksuite#6654 @fourdim
- toeverything/blocksuite#6587 @Saul-Mirone
- toeverything/blocksuite#6562 @donteatfriedrice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants