Skip to content

Conversation

@graydawnc
Copy link
Collaborator

@graydawnc graydawnc commented Apr 16, 2024

Add copy config to AIPanelAnswerConfig:

export interface CopyConfig {
  allowed: boolean;
  onCopy: () => boolean | Promise<boolean>;
}

When an action response can be copied, can config it in finishStateConfig, different types of actions can be configured with different copy behaviors, which need to be implemented according to the specific type:

    finishStateConfig: {
      responses: buildDefaultResponse(panel),
      actions: [],
      copy: {
        allowed: true,
        onCopy: () => {
          return copyTextAnswer(panel);
        },
      },
    },

For example, for rich text response, copy rich text content to clipboard:

export const copyTextAnswer = async (panel: AffineAIPanelWidget) => {
  const host = panel.host;
  if (panel.state !== 'finished' || !panel.answer) {
    return false;
  }
  const previewDoc = await markDownToDoc(host, panel.answer);
  const models = previewDoc
    .getBlocksByFlavour('affine:note')
    .map(b => b.model)
    .flatMap(model => model.children);
  const slice = Slice.fromModels(previewDoc, models);
  await host.std.clipboard.copySlice(slice);
  return true;
};

@graydawnc graydawnc marked this pull request as draft April 16, 2024 10:47
@vercel
Copy link

vercel bot commented Apr 16, 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 Apr 17, 2024 1:52pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
blocksuite-docs ⬜️ Ignored (Inspect) Visit Preview Apr 17, 2024 1:52pm

@graphite-app
Copy link

graphite-app bot commented Apr 17, 2024

Merge activity

  • Apr 17, 9:43 AM EDT: The merge label 'merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Apr 17, 9:43 AM EDT: donteatfriedrice added this pull request to the Graphite merge queue.
  • Apr 17, 9:51 AM EDT: donteatfriedrice merged this pull request with the Graphite merge queue.

Add copy config to AIPanelAnswerConfig:

```
export interface CopyConfig {
  allowed: boolean;
  onCopy: () => boolean | Promise<boolean>;
}
```

When an action response can be copied, can config it in finishStateConfig, different types of actions can be configured with different copy behaviors, which need to be implemented according to the specific type:

```
    finishStateConfig: {
      responses: buildDefaultResponse(panel),
      actions: [],
      copy: {
        allowed: true,
        onCopy: () => {
          return copyTextAnswer(panel);
        },
      },
    },
```

For example, for rich text response, copy rich text content to clipboard:

```
export const copyTextAnswer = async (panel: AffineAIPanelWidget) => {
  const host = panel.host;
  if (panel.state !== 'finished' || !panel.answer) {
    return false;
  }
  const previewDoc = await markDownToDoc(host, panel.answer);
  const models = previewDoc
    .getBlocksByFlavour('affine:note')
    .map(b => b.model)
    .flatMap(model => model.children);
  const slice = Slice.fromModels(previewDoc, models);
  await host.std.clipboard.copySlice(slice);
  return true;
};
```
@graydawnc graydawnc force-pushed the feat/support-copy-ai-answer branch from 9ef3478 to 49c12fe Compare April 17, 2024 13:44
@graphite-app graphite-app bot merged commit 49c12fe into master Apr 17, 2024
@graphite-app graphite-app bot deleted the feat/support-copy-ai-answer branch April 17, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants