mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08:00
chore: standardize package references (#9346)
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import {
|
||||
type GfxCommonBlockProps,
|
||||
GfxCompatible,
|
||||
} from '@blocksuite/affine/block-std/gfx';
|
||||
import { BlockModel, defineBlockSchema } from '@blocksuite/affine/store';
|
||||
|
||||
type AIChatProps = {
|
||||
messages: string; // JSON string of ChatMessage[]
|
||||
sessionId: string; // forked session id
|
||||
rootWorkspaceId: string; // workspace id of root chat session
|
||||
rootDocId: string; // doc id of root chat session
|
||||
} & Omit<GfxCommonBlockProps, 'rotate'>;
|
||||
|
||||
export const AIChatBlockSchema = defineBlockSchema({
|
||||
flavour: 'affine:embed-ai-chat',
|
||||
props: (): AIChatProps => ({
|
||||
xywh: '[0,0,0,0]',
|
||||
index: 'a0',
|
||||
lockedBySelf: false,
|
||||
scale: 1,
|
||||
messages: '',
|
||||
sessionId: '',
|
||||
rootWorkspaceId: '',
|
||||
rootDocId: '',
|
||||
}),
|
||||
metadata: {
|
||||
version: 1,
|
||||
role: 'content',
|
||||
children: [],
|
||||
},
|
||||
toModel: () => {
|
||||
return new AIChatBlockModel();
|
||||
},
|
||||
});
|
||||
|
||||
export class AIChatBlockModel extends GfxCompatible<AIChatProps>(BlockModel) {}
|
||||
|
||||
declare global {
|
||||
// oxlint-disable-next-line @typescript-eslint/no-namespace
|
||||
namespace BlockSuite {
|
||||
interface EdgelessBlockModelMap {
|
||||
'affine:embed-ai-chat': AIChatBlockModel;
|
||||
}
|
||||
interface BlockModels {
|
||||
'affine:embed-ai-chat': AIChatBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export const CHAT_BLOCK_WIDTH = 300;
|
||||
export const CHAT_BLOCK_HEIGHT = 320;
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './ai-chat-model';
|
||||
export * from './consts';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,25 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
// Define the Zod schema
|
||||
const ChatMessageSchema = z.object({
|
||||
id: z.string(),
|
||||
content: z.string(),
|
||||
role: z.union([z.literal('user'), z.literal('assistant')]),
|
||||
createdAt: z.string(),
|
||||
attachments: z.array(z.string()).optional(),
|
||||
userId: z.string().optional(),
|
||||
userName: z.string().optional(),
|
||||
avatarUrl: z.string().optional(),
|
||||
});
|
||||
|
||||
export const ChatMessagesSchema = z.array(ChatMessageSchema);
|
||||
|
||||
// Derive the TypeScript type from the Zod schema
|
||||
export type ChatMessage = z.infer<typeof ChatMessageSchema>;
|
||||
|
||||
export type MessageRole = 'user' | 'assistant';
|
||||
export type MessageUserInfo = {
|
||||
userId?: string;
|
||||
userName?: string;
|
||||
avatarUrl?: string;
|
||||
};
|
||||
1
packages/frontend/core/src/blocksuite/blocks/index.ts
Normal file
1
packages/frontend/core/src/blocksuite/blocks/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './ai-chat-block';
|
||||
@@ -25,9 +25,9 @@ import {
|
||||
type SerializedXYWH,
|
||||
} from '@blocksuite/affine/global/utils';
|
||||
import type { Doc } from '@blocksuite/affine/store';
|
||||
import type { ChatMessage } from '@toeverything/infra/blocksuite';
|
||||
import type { TemplateResult } from 'lit';
|
||||
|
||||
import type { ChatMessage } from '../../../blocks';
|
||||
import { insertFromMarkdown } from '../../_common';
|
||||
import { AIProvider, type AIUserInfo } from '../provider';
|
||||
import { reportResponse } from '../utils/action-reporter';
|
||||
|
||||
@@ -16,9 +16,9 @@ import {
|
||||
import { assertExists } from '@blocksuite/affine/global/utils';
|
||||
import { Slice } from '@blocksuite/affine/store';
|
||||
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
||||
import { AIChatBlockModel } from '@toeverything/infra';
|
||||
import type { TemplateResult } from 'lit';
|
||||
|
||||
import { AIChatBlockModel } from '../../../blocks';
|
||||
import { getContentFromSlice } from '../../_common';
|
||||
import { AIProvider } from '../provider';
|
||||
import { reportResponse } from '../utils/action-reporter';
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { EditorHost } from '@blocksuite/affine/block-std';
|
||||
import { type AIError, openFileOrFiles } from '@blocksuite/affine/blocks';
|
||||
import type { ChatMessage } from '@toeverything/infra';
|
||||
import { css, html, LitElement, nothing } from 'lit';
|
||||
import { property, query, state } from 'lit/decorators.js';
|
||||
import { classMap } from 'lit/directives/class-map.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
|
||||
import type { ChatMessage } from '../../../blocks';
|
||||
import {
|
||||
ChatAbortIcon,
|
||||
ChatClearIcon,
|
||||
|
||||
@@ -8,16 +8,16 @@ import {
|
||||
NotificationProvider,
|
||||
TelemetryProvider,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import {
|
||||
type AIChatBlockModel,
|
||||
type ChatMessage,
|
||||
ChatMessagesSchema,
|
||||
} from '@toeverything/infra/blocksuite';
|
||||
import { html, LitElement, nothing } from 'lit';
|
||||
import { property, query, state } from 'lit/decorators.js';
|
||||
import { classMap } from 'lit/directives/class-map.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
|
||||
import {
|
||||
type AIChatBlockModel,
|
||||
type ChatMessage,
|
||||
ChatMessagesSchema,
|
||||
} from '../../../blocks';
|
||||
import {
|
||||
ChatBlockPeekViewActions,
|
||||
constructUserInfoWithMessages,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { AIError } from '@blocksuite/affine/blocks';
|
||||
import type { ChatMessage } from '@toeverything/infra/blocksuite';
|
||||
|
||||
import type { ChatMessage } from '../../../blocks';
|
||||
|
||||
export type ChatStatus =
|
||||
| 'success'
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import type { EdgelessRootService } from '@blocksuite/affine/blocks';
|
||||
import { Bound } from '@blocksuite/affine/global/utils';
|
||||
|
||||
import {
|
||||
type AIChatBlockModel,
|
||||
CHAT_BLOCK_HEIGHT,
|
||||
CHAT_BLOCK_WIDTH,
|
||||
} from '@toeverything/infra';
|
||||
} from '../../../blocks';
|
||||
|
||||
/**
|
||||
* Calculates the bounding box for a child block
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { BlockComponent } from '@blocksuite/affine/block-std';
|
||||
import { Peekable } from '@blocksuite/affine/blocks';
|
||||
import { computed } from '@preact/signals-core';
|
||||
import {
|
||||
type AIChatBlockModel,
|
||||
ChatMessagesSchema,
|
||||
} from '@toeverything/infra/blocksuite';
|
||||
import { html } from 'lit';
|
||||
|
||||
import { type AIChatBlockModel, ChatMessagesSchema } from '../../../blocks';
|
||||
import { ChatWithAIIcon } from '../_common/icon';
|
||||
import { AIChatBlockStyles } from './styles';
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import type { EditorHost } from '@blocksuite/block-std';
|
||||
import type { AffineAIPanelState } from '@blocksuite/blocks';
|
||||
import type {
|
||||
ChatMessage,
|
||||
MessageRole,
|
||||
MessageUserInfo,
|
||||
} from '@toeverything/infra/blocksuite';
|
||||
import { css, html, LitElement } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
import { classMap } from 'lit/directives/class-map.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
|
||||
import type {
|
||||
ChatMessage,
|
||||
MessageRole,
|
||||
MessageUserInfo,
|
||||
} from '../../../../blocks';
|
||||
import type { TextRendererOptions } from '../../../_common/components/text-renderer';
|
||||
import { UserInfoTemplate } from './user-info';
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { MessageRole, MessageUserInfo } from '@toeverything/infra';
|
||||
import { baseTheme } from '@toeverything/theme';
|
||||
import { css, html, LitElement, type TemplateResult, unsafeCSS } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
|
||||
import type { MessageRole, MessageUserInfo } from '../../../../blocks';
|
||||
import { AffineAIIcon } from '../../_common/icon';
|
||||
|
||||
export class UserInfo extends LitElement {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
toReactNode,
|
||||
type useConfirmModal,
|
||||
} from '@affine/component';
|
||||
import { AIChatBlockSchema } from '@affine/core/blocksuite/blocks';
|
||||
import { AttachmentPreviewErrorBoundary } from '@affine/core/components/attachment-viewer/error';
|
||||
import { PDFViewerEmbedded } from '@affine/core/components/attachment-viewer/pdf-viewer-embedded';
|
||||
import { buildAttachmentProps } from '@affine/core/components/attachment-viewer/utils';
|
||||
@@ -66,11 +67,7 @@ import {
|
||||
import { Bound } from '@blocksuite/affine/global/utils';
|
||||
import { type BlockSnapshot, Text } from '@blocksuite/affine/store';
|
||||
import type { ReferenceParams } from '@blocksuite/affine-model';
|
||||
import {
|
||||
AIChatBlockSchema,
|
||||
type DocProps,
|
||||
type FrameworkProvider,
|
||||
} from '@toeverything/infra';
|
||||
import { type DocProps, type FrameworkProvider } from '@toeverything/infra';
|
||||
import { type TemplateResult } from 'lit';
|
||||
import { customElement } from 'lit/decorators.js';
|
||||
import { literal } from 'lit/static-html.js';
|
||||
|
||||
@@ -10,11 +10,11 @@ import type {
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { AffineReference } from '@blocksuite/affine/blocks';
|
||||
import type { Block, BlockModel } from '@blocksuite/affine/store';
|
||||
import type { AIChatBlockModel } from '@toeverything/infra';
|
||||
import { Entity, LiveData } from '@toeverything/infra';
|
||||
import type { TemplateResult } from 'lit';
|
||||
import { firstValueFrom, map, race } from 'rxjs';
|
||||
|
||||
import type { AIChatBlockModel } from '../../../blocksuite/blocks';
|
||||
import { resolveLinkToDoc } from '../../navigation';
|
||||
import type { WorkbenchService } from '../../workbench';
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { AffineSchemas } from '@blocksuite/affine/blocks/schemas';
|
||||
import { Schema } from '@blocksuite/affine/store';
|
||||
import { AIChatBlockSchema } from '@toeverything/infra';
|
||||
|
||||
import { AIChatBlockSchema } from '../../blocksuite/blocks';
|
||||
|
||||
let _schema: Schema | null = null;
|
||||
export function getAFFiNEWorkspaceSchema() {
|
||||
|
||||
Reference in New Issue
Block a user