-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3e15c6
commit b201e70
Showing
47 changed files
with
1,123 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/common/infra/src/blocksuite/blocks/ai-chat-block/ai-chat-model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { GfxCompatible } from '@blocksuite/block-std/gfx'; | ||
import type { SerializedXYWH } from '@blocksuite/global/utils'; | ||
import { BlockModel, defineBlockSchema } from '@blocksuite/store'; | ||
|
||
type AIChatProps = { | ||
xywh: SerializedXYWH; | ||
index: string; | ||
scale: number; | ||
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 | ||
}; | ||
|
||
export const AIChatBlockSchema = defineBlockSchema({ | ||
flavour: 'affine:embed-ai-chat', | ||
props: (): AIChatProps => ({ | ||
xywh: '[0,0,0,0]', | ||
index: 'a0', | ||
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 { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
namespace BlockSuite { | ||
interface EdgelessBlockModelMap { | ||
'affine:embed-ai-chat': AIChatBlockModel; | ||
} | ||
interface BlockModels { | ||
'affine:embed-ai-chat': AIChatBlockModel; | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/common/infra/src/blocksuite/blocks/ai-chat-block/consts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const CHAT_BLOCK_WIDTH = 300; | ||
export const CHAT_BLOCK_HEIGHT = 320; |
3 changes: 3 additions & 0 deletions
3
packages/common/infra/src/blocksuite/blocks/ai-chat-block/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './ai-chat-model'; | ||
export * from './consts'; | ||
export * from './types'; |
25 changes: 25 additions & 0 deletions
25
packages/common/infra/src/blocksuite/blocks/ai-chat-block/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './ai-chat-block'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './blocks'; | ||
export { | ||
migratePages as forceUpgradePages, | ||
migrateGuidCompatibility, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.