Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

chore(ai): entity=attachment (#2978)

Eric Hayesea532d484b4c
diff --git a/js/app/packages/app/component/ChatWithAgentButton.tsx b/js/app/packages/app/component/ChatWithAgentButton.tsx
index 2ba403f98c..df2cd6eeae 100644
--- a/js/app/packages/app/component/ChatWithAgentButton.tsx
+++ b/js/app/packages/app/component/ChatWithAgentButton.tsx
@@ -2,7 +2,6 @@ import { globalSplitManager } from '@app/signal/splitLayout';
import { toast } from '@core/component/Toast/Toast';
import { Tooltip } from '@core/component/Tooltip';
import type { Attachment } from '@core/component/AI/types';
-import { asFileType } from '@core/component/AI/util';
import { storeChatStateImmediate } from '@core/component/AI/util/storage';
import { createChat } from '@core/util/create';
import { AnimatedStarIcon } from '@macro-icons/wide/animating/star';
@@ -35,43 +34,20 @@ export type ChatWithAgentEntity =
function buildAttachment(entity: ChatWithAgentEntity): Attachment | undefined {
return match(entity)
.with({ type: 'email' }, (e) => ({
- id: `${e.id}-email-attachment`,
- attachmentId: e.id,
- attachmentType: 'email' as const,
- metadata: {
- type: 'email' as const,
- email_subject: e.name || 'No Subject',
- },
+ entity_id: e.id,
+ entity_type: 'email_thread' as const,
+ }))
+ .with({ type: 'document' }, (e) => ({
+ entity_id: e.id,
+ entity_type: 'document' as const,
}))
- .with({ type: 'document' }, (e) => {
- const fileType = asFileType(e.fileType);
- if (!fileType) return undefined;
- return {
- id: `${e.id}-document-attachment`,
- attachmentId: e.id,
- attachmentType: 'document' as const,
- metadata: {
- type: 'document' as const,
- document_type: fileType,
- document_name: e.name,
- },
- };
- })
.with({ type: 'project' }, (e) => ({
- id: `${e.id}-project-attachment`,
- attachmentId: e.id,
- attachmentType: 'project' as const,
- metadata: { type: 'project' as const, project_name: e.name },
+ entity_id: e.id,
+ entity_type: 'project' as const,
}))
.with({ type: 'channel' }, (e) => ({
- id: `${e.id}-channel-attachment`,
- attachmentId: e.id,
- attachmentType: 'channel' as const,
- metadata: {
- type: 'channel' as const,
- channel_type: e.channelType,
- channel_name: e.name,
- },
+ entity_id: e.id,
+ entity_type: 'channel' as const,
}))
.exhaustive();
}
diff --git a/js/app/packages/block-chat/definition.ts b/js/app/packages/block-chat/definition.ts
index cf3c12d887..e7ab4bd08f 100644
--- a/js/app/packages/block-chat/definition.ts
+++ b/js/app/packages/block-chat/definition.ts
@@ -2,13 +2,13 @@ import { defineBlock, type ExtractLoadType, LoadErrors } from '@core/block';
import { isErr, ok } from '@core/util/maybeResult';
import { cognitionApiServiceClient } from '@service-cognition/client';
import { AllModels } from '@service-cognition/generated/schemas';
-import type { ChatAttachmentWithName } from '@service-cognition/generated/schemas/chatAttachmentWithName';
+import type { Entity } from '@service-cognition/generated/schemas/entity';
import type { DocumentMetadata } from '@service-storage/generated/schemas/documentMetadata';
import BlockChat from './component/Block';
export const DEFAULT_CHAT_NAME = 'New Chat';
-export type AttachmentWithoutId = Omit<ChatAttachmentWithName, 'id'>;
+export type AttachmentWithoutId = Entity;
export const definition = defineBlock({
name: 'chat',
@@ -35,7 +35,6 @@ export const definition = defineBlock({
return ok({
...chat,
allModels: AllModels, // TODO maybe limit people with something more swag based on acoun
- isPersistent: chat.chat.isPersistent,
documentMetadata: {
documentId: chat.chat.id,
documentName: chat.chat.name,
diff --git a/js/app/packages/core/component/AI/component/debug/attachments.ts b/js/app/packages/core/component/AI/component/debug/attachments.ts
index f0122ba21e..8656f24468 100644
--- a/js/app/packages/core/component/AI/component/debug/attachments.ts
+++ b/js/app/packages/core/component/AI/component/debug/attachments.ts
@@ -1,111 +1,51 @@
import type { Attachment } from '../../types';
export const NUEROMANCER: Attachment = {
- attachmentId: '82b7aafb-cc7f-420d-9262-d000ecdf3bb5',
- id: '82b7aafb-cc7f-420d-9262-d000ecdf3bb5',
- attachmentType: 'document',
- metadata: {
- type: 'document',
- document_name: 'TEST_DOC neuromancer',
- document_type: 'pdf',
- },
+ entity_id: '82b7aafb-cc7f-420d-9262-d000ecdf3bb5',
+ entity_type: 'document',
};
export const LOST_IN_THE_MIDDLE: Attachment = {
- attachmentId: '7e3c1a4a-35e5-4e5c-b7d1-c65603cfab8f',
- attachmentType: 'document',
- id: '7e3c1a4a-35e5-4e5c-b7d1-c65603cfab8f',
- metadata: {
- type: 'document',
- document_name: 'TEST_DOC Lost in the middle',
- document_type: 'pdf',
- },
+ entity_id: '7e3c1a4a-35e5-4e5c-b7d1-c65603cfab8f',
+ entity_type: 'document',
};
export const NSW: Attachment = {
- attachmentId: '32e24a14-0934-4d59-85a0-7c6576e835b2',
- attachmentType: 'document',
- id: '32e24a14-0934-4d59-85a0-7c6576e835b2',
- metadata: {
- type: 'document',
- document_name: 'TEST_DOC NSW',
- document_type: 'pdf',
- },
+ entity_id: '32e24a14-0934-4d59-85a0-7c6576e835b2',
+ entity_type: 'document',
};
export const IHAVENOMOUTHANDIMUSTSCREAM: Attachment = {
- attachmentId: '17f374b7-5777-41ce-a942-be87275b887b',
- id: '17f374b7-5777-41ce-a942-be87275b887b',
- attachmentType: 'document',
- metadata: {
- type: 'document',
- document_name: 'TEST_DOC IHaveNoMouthAndIMustScream',
- document_type: 'pdf',
- },
+ entity_id: '17f374b7-5777-41ce-a942-be87275b887b',
+ entity_type: 'document',
};
export const PRD_PROPERTIES_V0: Attachment = {
- attachmentId: '8ed6478e-dbdf-46ca-9313-ebe757595132',
- id: '8ed6478e-dbdf-46ca-9313-ebe757595132',
- attachmentType: 'document',
- metadata: {
- type: 'document',
- document_name: 'TEST_DOC PRD Properties V0',
- document_type: 'md',
- },
+ entity_id: '8ed6478e-dbdf-46ca-9313-ebe757595132',
+ entity_type: 'document',
};
export const CHAT_RS: Attachment = {
- attachmentId: 'e37d3e28-653e-4679-9deb-f830150ec513',
- id: 'e37d3e28-653e-4679-9deb-f830150ec513',
- attachmentType: 'document',
- metadata: {
- type: 'document',
- document_name: 'TEST_DOC chat_rs',
- document_type: 'py',
- },
+ entity_id: 'e37d3e28-653e-4679-9deb-f830150ec513',
+ entity_type: 'document',
};
export const REQUEST_BUILDER_RS: Attachment = {
- attachmentId: 'f22d73e3-446e-49c6-b48d-7a5c10778471',
- id: 'f22d73e3-446e-49c6-b48d-7a5c10778471',
- attachmentType: 'document',
- metadata: {
- type: 'document',
- document_name: 'TEST_DOC request_builder_rs',
- document_type: 'py',
- },
+ entity_id: 'f22d73e3-446e-49c6-b48d-7a5c10778471',
+ entity_type: 'document',
};
export const CLIENT_RS: Attachment = {
- attachmentId: 'e7b37542-dc81-42b0-b6e0-8d06de4e436f',
- id: 'e7b37542-dc81-42b0-b6e0-8d06de4e436f',
- attachmentType: 'document',
- metadata: {
- type: 'document',
- document_name: 'TEST_DOC client_rs',
- document_type: 'py',
- },
+ entity_id: 'e7b37542-dc81-42b0-b6e0-8d06de4e436f',
+ entity_type: 'document',
};
export const RFD_DEMETERS_BROTH: Attachment = {
- attachmentId: '2914049e-75d4-4697-a841-085066caa4ec',
- id: '2914049e-75d4-4697-a841-085066caa4ec',
- attachmentType: 'document',
- metadata: {
- type: 'document',
- document_name: 'TEST_DOC RFD_ Demeters Broth',
- document_type: 'md',
- },
+ entity_id: '2914049e-75d4-4697-a841-085066caa4ec',
+ entity_type: 'document',
};
export const RFD_SOUND: Attachment = {
- attachmentId: '6da6b8c1-1eb6-48c9-b754-3aaaee373a69',
- id: '6da6b8c1-1eb6-48c9-b754-3aaaee373a69',
- attachmentType: 'document',
- metadata: {
- type: 'document',
- document_name: 'TEST_DOC RFD Sound',
- document_type: 'md',
- },
+ entity_id: '6da6b8c1-1eb6-48c9-b754-3aaaee373a69',
+ entity_type: 'document',
};
diff --git a/js/app/packages/core/component/AI/component/input/Attachment.tsx b/js/app/packages/core/component/AI/component/input/Attachment.tsx
index 64623d2184..e7842b80bb 100644
--- a/js/app/packages/core/component/AI/component/input/Attachment.tsx
+++ b/js/app/packages/core/component/AI/component/input/Attachment.tsx
@@ -10,6 +10,7 @@ import { toast } from '@core/component/Toast/Toast';
import XIcon from '@icon/regular/x.svg';
import Spinner from '@phosphor-icons/core/bold/spinner-gap-bold.svg?component-solid';
import Close from '@phosphor-icons/core/regular/x.svg?component-solid';
+import type { ItemType } from '@service-storage/client';
import type { Accessor } from 'solid-js';
import { createSignal, For, Match, Show, Suspense, Switch } from 'solid-js';
@@ -27,7 +28,7 @@ export function AttachmentList(props: AttachmentListProps) {
<Suspense>
<ChatAttachment
attachment={attachment}
- onRemove={() => props.removeAttachment(attachment.attachmentId)}
+ onRemove={() => props.removeAttachment(attachment.entity_id)}
/>
</Suspense>
)}
@@ -78,9 +79,9 @@ function ImageAttachment(props: {
/>
</Show>
<ImagePreview
- image={{ id: props.attachment.attachmentId }}
+ image={{ id: props.attachment.entity_id }}
variant="small"
- isDss={isDssImage(props.attachment)}
+ isDss={false}
onError={(e) => {
console.error('Failed to load image', e);
toast.failure('Failed to load image');
@@ -97,43 +98,44 @@ function ChatAttachment(props: {
}) {
return (
<Switch>
- <Match when={isImageAttachment(props.attachment)}>
+ <Match when={props.attachment.entity_type === 'static_file'}>
<ImageAttachment
attachment={props.attachment}
onRemove={props.onRemove}
/>
</Match>
<Match
- when={
- props.attachment.metadata?.type !== 'image' &&
- props.attachment.metadata
- }
+ when={['document', 'channel', 'project', 'email_thread'].includes(
+ props.attachment.entity_type
+ )}
>
- {(metadata) => (
- <div class="flex items-center px-1 space-x-1 hover:bg-hover hover-transition-bg cursor-default text-sm border border-edge-muted rounded-xs">
- <ItemPreview
- id={props.attachment.attachmentId}
- type={metadata().type}
- class="flex items-center gap-1 text-sm ring-0"
- textClass="truncate"
- iconSize="xs"
- disableHoverCard
+ <div class="flex items-center px-1 space-x-1 hover:bg-hover hover-transition-bg cursor-default text-sm border border-edge-muted rounded-xs">
+ <ItemPreview
+ id={props.attachment.entity_id}
+ type={
+ (props.attachment.entity_type === 'email_thread'
+ ? 'email'
+ : props.attachment.entity_type) as ItemType
+ }
+ class="flex items-center gap-1 text-sm ring-0"
+ textClass="truncate"
+ iconSize="xs"
+ disableHoverCard
+ />
+ <div
+ class="hover:bg-hover hover-transition-bg rounded-md p-1 items-center flex"
+ onClick={(e) => {
+ e.stopPropagation();
+ props.onRemove?.();
+ }}
+ >
+ <Close
+ width={12}
+ height={12}
+ class="text-ink-muted group-hover:text-failure"
/>
- <div
- class="hover:bg-hover hover-transition-bg rounded-md p-1 items-center flex"
- onClick={(e) => {
- e.stopPropagation();
- props.onRemove?.();
- }}
- >
- <Close
- width={12}
- height={12}
- class="text-ink-muted group-hover:text-failure"
- />
- </div>
</div>
- )}
+ </div>
</Match>
</Switch>
);
diff --git a/js/app/packages/core/component/AI/component/message/AssistantMessageActionMenu.tsx b/js/app/packages/core/component/AI/component/message/AssistantMessageActionMenu.tsx
index 292989c4c0..12ba2a8bde 100644
--- a/js/app/packages/core/component/AI/component/message/AssistantMessageActionMenu.tsx
+++ b/js/app/packages/core/component/AI/component/message/AssistantMessageActionMenu.tsx
@@ -1,4 +1,3 @@
-import { generateTitle } from '@service-cognition/client';
import {
DEFAULT_MODEL,
MODEL_PRETTYNAME,
@@ -10,11 +9,10 @@ import CheckIcon from '@phosphor-icons/core/bold/check-bold.svg?component-solid'
import ClipboardIcon from '@phosphor-icons/core/bold/clipboard-bold.svg?component-solid';
import NotesIcon from '@phosphor-icons/core/bold/file-md-bold.svg?component-solid';
import LoadingIcon from '@phosphor-icons/core/bold/spinner-gap-bold.svg?component-solid';
+import { generateTitle } from '@service-cognition/client';
import type { ChatMessageWithAttachments } from '@service-cognition/generated/schemas/chatMessageWithAttachments';
-import type { Model } from '@service-cognition/generated/schemas/model';
import { createCallback } from '@solid-primitives/rootless';
import { useSplitLayout } from 'app/component/split-layout/layout';
-import type { Component } from 'solid-js';
import { createSignal, Match, Show, Switch } from 'solid-js';
import { Dynamic } from 'solid-js/web';
import { extractMessageText } from './AssistantMessage';
@@ -25,17 +23,11 @@ type AssistantActionProps = {
export function AssistantMessageActionAndMetadata(props: AssistantActionProps) {
const modelName = () => {
- const prettyName: string | undefined =
- MODEL_PRETTYNAME[props.message?.model as Model];
- if (!prettyName) return MODEL_PRETTYNAME[DEFAULT_MODEL];
- return prettyName;
+ return MODEL_PRETTYNAME[DEFAULT_MODEL];
};
const modelIcon = () => {
- const icon: Component | undefined =
- MODEL_PROVIDER_ICON[props.message?.model as Model];
- if (!icon) return MODEL_PROVIDER_ICON[DEFAULT_MODEL];
- return icon;
+ return MODEL_PROVIDER_ICON[DEFAULT_MODEL];
};
const handleCopy = async () => {
diff --git a/js/app/packages/core/component/AI/component/message/UserMessage.tsx b/js/app/packages/core/component/AI/component/message/UserMessage.tsx
index 1dedd0a84e..ce35e81279 100644
--- a/js/app/packages/core/component/AI/component/message/UserMessage.tsx
+++ b/js/app/packages/core/component/AI/component/message/UserMessage.tsx
@@ -1,6 +1,4 @@
import type { ChatSendInput } from '@core/component/AI/component/input/buildRequest';
-import type { Model } from '@core/component/AI/types';
-import { isDssImage, isImageAttachment } from '@core/component/AI/util';
import { DeprecatedIconButton } from '@core/component/DeprecatedIconButton';
import { ImagePreview } from '@core/component/ImagePreview';
import { ItemPreview } from '@core/component/ItemPreview';
@@ -66,14 +64,11 @@ export function UserMessage(props: {
};
const imageAttachments = () =>
- props.message.attachments.filter((a) => isImageAttachment(a));
+ props.message.attachments.filter((a) => a.entity_type === 'static_file');
const itemPreviewAttachments = () =>
- props.message.attachments.filter(
- (a) =>
- // jail
- !isImageAttachment(a) &&
- ['channel', 'document', 'email', 'project'].includes(a.attachmentType)
+ props.message.attachments.filter((a) =>
+ ['channel', 'document', 'email_thread', 'project'].includes(a.entity_type)
);
return (
@@ -91,21 +86,23 @@ export function UserMessage(props: {
<For each={imageAttachments()}>
{(attachment) => (
<ImagePreview
- image={{ id: attachment.attachmentId }}
+ image={{ id: attachment.entity_id }}
variant="small"
- isDss={isDssImage(attachment)}
+ isDss={false}
/>
)}
</For>
<For each={itemPreviewAttachments()}>
{(attachment) => (
<ItemPreview
- id={attachment.attachmentId}
- // TODO: improve typing for item preview attachments
+ id={attachment.entity_id}
type={
- attachment.attachmentType as
+ (attachment.entity_type === 'email_thread'
+ ? 'email'
+ : attachment.entity_type) as
| 'channel'
| 'document'
+ | 'email'
| 'project'
}
/>
@@ -139,7 +136,7 @@ export function UserMessage(props: {
chatId={props.edit!.chatId}
attachments={props.message.attachments}
initialText={props.message.content.toString()}
- model={(props.message.model as Model) ?? DEFAULT_MODEL}
+ model={DEFAULT_MODEL}
onAccept={() => {}}
onCancel={() => setIsEditing(false)}
/>
diff --git a/js/app/packages/core/component/AI/hook/useEntityDropAttachment.ts b/js/app/packages/core/component/AI/hook/useEntityDropAttachment.ts
index e1919f7bd2..71b222e694 100644
--- a/js/app/packages/core/component/AI/hook/useEntityDropAttachment.ts
+++ b/js/app/packages/core/component/AI/hook/useEntityDropAttachment.ts
@@ -1,13 +1,12 @@
-import { match, P } from 'ts-pattern';
import { SUPPORTED_CHAT_ATTACHMENT_BLOCKS } from '@core/component/AI/constant';
import type { Attachment, Attachments } from '@core/component/AI/types';
-import { asFileType } from '@core/component/AI/util';
import { toast } from '@core/component/Toast/Toast';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
import type { EntityDragData, EntityDragEvent } from '@entity';
+import type { EntityType } from '@service-cognition/generated/schemas/entityType';
import { createDroppable, useDragDropContext } from '@thisbeyond/solid-dnd';
-import type { AttachmentType } from '@service-cognition/generated/schemas';
import { type Accessor, createMemo } from 'solid-js';
+import { match, P } from 'ts-pattern';
/**
* Hook to handle entity drag-and-drop for chat attachments.
@@ -60,7 +59,6 @@ export function useEntityDropAttachment(
if (!data || data.dragType !== 'entity') return;
const entityId = data.id;
- const entityName = data.name;
const entityType = data.type;
const fileType = 'fileType' in data ? data.fileType : undefined;
@@ -71,66 +69,31 @@ export function useEntityDropAttachment(
return;
}
- // Build the attachment based on entity type
- const attachment = match(entityType)
- .with('document', () => {
- const validFileType = asFileType(fileType);
- if (!validFileType) return;
- return {
- id: `${entityId}-document-attachment`,
- attachmentId: entityId,
- attachmentType: 'document' satisfies AttachmentType,
- metadata: {
- type: 'document',
- document_type: validFileType,
- document_name: entityName,
- },
- } satisfies Attachment;
- })
- .with('project', () => {
- return {
- id: `${entityId}-project-attachment`,
- attachmentId: entityId,
- attachmentType: 'project' satisfies AttachmentType,
- metadata: {
- type: 'project',
- project_name: entityName,
- },
- } satisfies Attachment;
- })
+ const attachment: Attachment | undefined = match(entityType)
+ .with('document', () => ({
+ entity_id: entityId,
+ entity_type: 'document' as EntityType,
+ }))
+ .with('project', () => ({
+ entity_id: entityId,
+ entity_type: 'project' as EntityType,
+ }))
.with(P.union('channel', 'channel_message'), () => {
- const channelType =
- 'channelType' in data ? data.channelType : 'organization';
const channelId =
'channelId' in data ? (data.channelId as string) : entityId;
-
- // TODO: channel_message attachments only reference the full channel, not the message
- return {
- id: `${channelId}-channel-attachment`,
- attachmentId: channelId,
- attachmentType: 'channel' satisfies AttachmentType,
- metadata: {
- type: 'channel',
- channel_type: channelType,
- channel_name: entityName,
- },
- } satisfies Attachment;
- })
- .with('email', () => {
return {
- id: `${entityId}-email-attachment`,
- attachmentId: entityId,
- attachmentType: 'email' satisfies AttachmentType,
- metadata: {
- type: 'email',
- email_subject: entityName,
- },
- } satisfies Attachment;
+ entity_id: channelId,
+ entity_type: 'channel' as EntityType,
+ };
})
+ .with('email', () => ({
+ entity_id: entityId,
+ entity_type: 'email_thread' as EntityType,
+ }))
.with('chat', () => undefined)
.with('call', () => undefined)
.with('automation', () => undefined)
- .exhaustive() satisfies Attachment | undefined;
+ .exhaustive();
if (attachment) {
attachments.addAttachment(attachment);
diff --git a/js/app/packages/core/component/AI/signal/attachment.ts b/js/app/packages/core/component/AI/signal/attachment.ts
index ee4c1634c1..fb107d6aa4 100644
--- a/js/app/packages/core/component/AI/signal/attachment.ts
+++ b/js/app/packages/core/component/AI/signal/attachment.ts
@@ -16,7 +16,7 @@ export function useAttachments(initial?: Attachment[]): Attachments {
// dedup
if (
attachments().some(
- (attached) => attached.attachmentId === newAttachment.attachmentId
+ (attached) => attached.entity_id === newAttachment.entity_id
)
)
return;
@@ -25,7 +25,7 @@ export function useAttachments(initial?: Attachment[]): Attachments {
const removeAttachment = (id: string) => {
const attached = attachments();
- const newAttachments = attached.filter((a) => a.attachmentId !== id);
+ const newAttachments = attached.filter((a) => a.entity_id !== id);
setAttachments(newAttachments);
};
@@ -61,14 +61,8 @@ export const useGetChatAttachmentInfo = () => {
}
return {
- id: `${item.id}-document-attachment`,
- attachmentId: item.id,
- attachmentType: 'document',
- metadata: {
- type: 'document',
- document_type: fileType,
- document_name: item.name,
- },
+ entity_id: item.id,
+ entity_type: 'document',
};
};
@@ -76,13 +70,8 @@ export const useGetChatAttachmentInfo = () => {
const item = history().find((item) => item.id === id);
if (!item || item.type !== 'project') return;
return {
- attachmentType: 'project',
- attachmentId: item.id,
- id: item.id,
- metadata: {
- type: 'project',
- project_name: item.name,
- },
+ entity_id: item.id,
+ entity_type: 'project',
};
};
@@ -95,26 +84,15 @@ export const useGetChatAttachmentInfo = () => {
if (!item) return;
return {
- id: `${item.id}-channel-attachment`,
- attachmentId: item.id,
- attachmentType: 'channel',
- metadata: {
- type: 'channel',
- channel_type: item.channel_type,
- channel_name: item.name ?? 'Channel',
- },
+ entity_id: item.id,
+ entity_type: 'channel',
};
};
const getEmailAttachment = (mention: ItemMention): Attachment | undefined => {
return {
- id: `${mention.itemId}-email-attachment`,
- attachmentId: mention.itemId,
- attachmentType: 'email',
- metadata: {
- type: 'email',
- email_subject: mention.documentName ?? 'No Subject',
- },
+ entity_id: mention.itemId,
+ entity_type: 'email_thread',
};
};
diff --git a/js/app/packages/core/component/AI/state/chatState.ts b/js/app/packages/core/component/AI/state/chatState.ts
index 7331f3a97b..89dba7f2d2 100644
--- a/js/app/packages/core/component/AI/state/chatState.ts
+++ b/js/app/packages/core/component/AI/state/chatState.ts
@@ -1,5 +1,5 @@
import type { ChatMessageWithAttachments } from '@core/component/AI/types';
-import type { ChatAttachmentWithName } from '@service-cognition/generated/schemas';
+import type { Entity } from '@service-cognition/generated/schemas/entity';
import { match, P } from 'ts-pattern';
// --- Phases ---
@@ -22,7 +22,7 @@ export type ChatEvent =
type: 'stream_user_message';
messageId: string;
content: string;
- attachments: ChatAttachmentWithName[];
+ attachments: Entity[];
}
| {
type: 'stream_done';
diff --git a/js/app/packages/core/component/AI/types/attachment.ts b/js/app/packages/core/component/AI/types/attachment.ts
index c511344838..1866f58e7a 100644
--- a/js/app/packages/core/component/AI/types/attachment.ts
+++ b/js/app/packages/core/component/AI/types/attachment.ts
@@ -1,4 +1,5 @@
-import type { ChatAttachmentWithName } from '@service-cognition/generated/schemas';
+import type { AttachmentMetadata as GeneratedAttachmentMetadata } from '@service-cognition/generated/schemas/attachmentMetadata';
+import type { Entity } from '@service-cognition/generated/schemas/entity';
import type { Accessor, Setter } from 'solid-js';
export type {
@@ -6,7 +7,7 @@ export type {
ChatMessageWithAttachments,
} from '@service-cognition/generated/schemas';
-export type Attachment = ChatAttachmentWithName;
+export type Attachment = Entity;
export type Attachments = {
attached: Accessor<Attachment[]>;
@@ -15,7 +16,10 @@ export type Attachments = {
removeAttachment: (id: string) => void;
};
-export type AttachmentPreview = Pick<Attachment, 'attachmentType' | 'metadata'>;
+export type AttachmentPreview = {
+ entity_type: Entity['entity_type'];
+ metadata?: GeneratedAttachmentMetadata;
+};
export type UploadError = 'upload' | 'extract';
diff --git a/js/app/packages/core/component/AI/util/attachment.ts b/js/app/packages/core/component/AI/util/attachment.ts
index 762da4e5eb..6b7e322b70 100644
--- a/js/app/packages/core/component/AI/util/attachment.ts
+++ b/js/app/packages/core/component/AI/util/attachment.ts
@@ -13,8 +13,8 @@ export const asFileType = (
};
export const isImageAttachment = (attachment: AttachmentPreview) => {
- if (attachment.attachmentType === 'image') return true;
- if (attachment.attachmentType === 'document') {
+ if (attachment.entity_type === 'static_file') return true;
+ if (attachment.entity_type === 'document') {
if (!attachment.metadata) return false;
if (attachment.metadata.type === 'image') return true;
if (attachment.metadata.type === 'document') {
@@ -31,7 +31,7 @@ export const isImageAttachment = (attachment: AttachmentPreview) => {
export const isDssImage = (
attachment: AttachmentPreview
): attachment is {
- attachmentType: 'document';
+ entity_type: 'document';
metadata: Extract<AttachmentMetadata, { type: 'document' }>;
} => {
if (!isImageAttachment(attachment)) return false;
diff --git a/js/app/packages/core/component/AI/util/mockMessage.ts b/js/app/packages/core/component/AI/util/mockMessage.ts
index 7c625a1eaa..65a826a853 100644
--- a/js/app/packages/core/component/AI/util/mockMessage.ts
+++ b/js/app/packages/core/component/AI/util/mockMessage.ts
@@ -1,6 +1,5 @@
import { uuid } from 'short-uuid';
-import { DEFAULT_MODEL } from '../constant';
-import { type ChatMessageWithAttachments, Model } from '../types';
+import type { ChatMessageWithAttachments } from '../types';
// TODO mock attachments
function user(text: string, _attachments: [] = []): ChatMessageWithAttachments {
@@ -9,7 +8,6 @@ function user(text: string, _attachments: [] = []): ChatMessageWithAttachments {
content: text,
id: uuid(),
role: 'user',
- model: Model[DEFAULT_MODEL],
};
}
diff --git a/js/app/packages/core/component/AI/util/uploadToChat.ts b/js/app/packages/core/component/AI/util/uploadToChat.ts
index feccf399fc..8be82511af 100644
--- a/js/app/packages/core/component/AI/util/uploadToChat.ts
+++ b/js/app/packages/core/component/AI/util/uploadToChat.ts
@@ -36,16 +36,19 @@ async function uploadFileForChat(
};
}
- let attachmentId: string;
+ let entityId: string;
+ let entityType: 'static_file' | 'document';
switch (result.destination) {
case 'static':
- attachmentId = result.id;
+ entityId = result.id;
+ entityType = 'static_file';
break;
case 'dss':
if (result.type !== 'document') {
throw new Error('Unexpected upload result');
}
- attachmentId = result.documentId;
+ entityId = result.documentId;
+ entityType = 'document';
break;
default:
throw new Error('Unexpected upload result');
@@ -54,10 +57,8 @@ async function uploadFileForChat(
return {
type: 'ok',
attachment: {
- attachmentId,
- attachmentType: preview.attachmentType,
- id: attachmentId,
- metadata: preview.metadata,
+ entity_id: entityId,
+ entity_type: entityType,
},
};
} catch (error) {
@@ -81,7 +82,7 @@ function previewFile(file: File): AttachmentPreview | undefined {
if (SUPPORTED_IMAGE_ATTACHMENT_EXTENSIONS.includes(fileType)) {
return {
- attachmentType: 'image',
+ entity_type: 'static_file',
metadata: {
type: 'image',
image_extension: fileType,
@@ -91,7 +92,7 @@ function previewFile(file: File): AttachmentPreview | undefined {
}
return {
- attachmentType: 'document',
+ entity_type: 'document',
metadata: {
type: 'document',
document_name: name,
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/chatAttachmentWithName.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/chatAttachmentWithName.ts
deleted file mode 100644
index 25b5bf576c..0000000000
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/chatAttachmentWithName.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * Generated by orval v7.21.0 🍺
- * Do not edit manually.
- * Document Cognition Service
- * OpenAPI spec version: 1.0.0
- */
-import type { AttachmentType } from './attachmentType';
-import type { ChatAttachmentWithNameMetadata } from './chatAttachmentWithNameMetadata';
-
-export interface ChatAttachmentWithName {
- /** Id of the attachment [Foreign Key to either document, chat or project] */
- attachmentId: string;
- /** Type of the attachment ['document' | 'chat' | 'project' | 'image' | 'channel'] */
- attachmentType: AttachmentType;
- /** Incremented int id of the attachment (not really used for anything) */
- id: string;
- metadata?: ChatAttachmentWithNameMetadata;
-}
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/chatAttachmentWithNameMetadata.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/chatAttachmentWithNameMetadata.ts
deleted file mode 100644
index d34fc06e18..0000000000
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/chatAttachmentWithNameMetadata.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-/**
- * Generated by orval v7.21.0 🍺
- * Do not edit manually.
- * Document Cognition Service
- * OpenAPI spec version: 1.0.0
- */
-import type { AttachmentMetadata } from './attachmentMetadata';
-
-export type ChatAttachmentWithNameMetadata = null | AttachmentMetadata;
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/chatMessageWithAttachments.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/chatMessageWithAttachments.ts
index e14500c9b8..6501e38a02 100644
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/chatMessageWithAttachments.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/chatMessageWithAttachments.ts
@@ -4,21 +4,18 @@
* Document Cognition Service
* OpenAPI spec version: 1.0.0
*/
-import type { ChatAttachmentWithName } from './chatAttachmentWithName';
+
import type { ChatMessageContent } from './chatMessageContent';
-import type { ChatMessageWithAttachmentsModel } from './chatMessageWithAttachmentsModel';
+import type { Entity } from './entity';
import type { Role } from './role';
export interface ChatMessageWithAttachments {
/** The ids of the attachments used to generate the message */
- attachments: ChatAttachmentWithName[];
+ attachments: Entity[];
/** Message content */
content: ChatMessageContent;
/** The chat message id */
id: string;
- /** The model used to generate the message
-kill */
- model?: ChatMessageWithAttachmentsModel;
/** Whether the chat is from the user or system */
role: Role;
}
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/chatMessageWithAttachmentsModel.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/chatMessageWithAttachmentsModel.ts
deleted file mode 100644
index a9642abea4..0000000000
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/chatMessageWithAttachmentsModel.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-/**
- * Generated by orval v7.21.0 🍺
- * Do not edit manually.
- * Document Cognition Service
- * OpenAPI spec version: 1.0.0
- */
-
-/**
- * The model used to generate the message
-kill
- */
-export type ChatMessageWithAttachmentsModel = string | null;
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponse.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponse.ts
index cb4482acdf..fd80c11e4f 100644
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponse.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponse.ts
@@ -4,33 +4,21 @@
* Document Cognition Service
* OpenAPI spec version: 1.0.0
*/
-import type { ChatAttachmentWithName } from './chatAttachmentWithName';
+
import type { ChatMessageWithAttachments } from './chatMessageWithAttachments';
import type { ChatResponseCreatedAt } from './chatResponseCreatedAt';
import type { ChatResponseModel } from './chatResponseModel';
import type { ChatResponseProjectId } from './chatResponseProjectId';
-import type { ChatResponseTokenCount } from './chatResponseTokenCount';
import type { ChatResponseUpdatedAt } from './chatResponseUpdatedAt';
-import type { ChatResponseWebCitationsItemItem1Item } from './chatResponseWebCitationsItemItem1Item';
-import type { Model } from './model';
/**
* The full chat response, matching the DCS API response shape.
*/
export interface ChatResponse {
- /**
- * Attachment context — attachments not attached to messages.
- * @deprecated
- */
- attachments: ChatAttachmentWithName[];
- /** Available models for the chat. */
- availableModels: Model[];
/** The time the chat was created. */
createdAt?: ChatResponseCreatedAt;
/** The chat uuid. */
id: string;
- /** Whether the chat is persistent or not. */
- isPersistent: boolean;
/** The messages in the chat. */
messages: ChatMessageWithAttachments[];
model?: ChatResponseModel;
@@ -38,12 +26,8 @@ export interface ChatResponse {
name: string;
/** The project id the chat belongs to. */
projectId?: ChatResponseProjectId;
- /** Current number of tokens in the chat. */
- tokenCount?: ChatResponseTokenCount;
/** The time the chat was last updated. */
updatedAt?: ChatResponseUpdatedAt;
/** Who the chat belongs to. */
userId: string;
- /** Message ID to web citation list. */
- webCitations: [string, ChatResponseWebCitationsItemItem1Item[]][];
}
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponseTokenCount.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponseTokenCount.ts
deleted file mode 100644
index 298d1690bc..0000000000
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponseTokenCount.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- * Generated by orval v7.21.0 🍺
- * Do not edit manually.
- * Document Cognition Service
- * OpenAPI spec version: 1.0.0
- */
-
-/**
- * Current number of tokens in the chat.
- */
-export type ChatResponseTokenCount = number | null;
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponseWebCitationsItemItem1Item.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponseWebCitationsItemItem1Item.ts
deleted file mode 100644
index 31c66d4a96..0000000000
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponseWebCitationsItemItem1Item.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * Generated by orval v7.21.0 🍺
- * Do not edit manually.
- * Document Cognition Service
- * OpenAPI spec version: 1.0.0
- */
-import type { ChatResponseWebCitationsItemItem1ItemDescription } from './chatResponseWebCitationsItemItem1ItemDescription';
-import type { ChatResponseWebCitationsItemItem1ItemFaviconUrl } from './chatResponseWebCitationsItemItem1ItemFaviconUrl';
-import type { ChatResponseWebCitationsItemItem1ItemImageUrl } from './chatResponseWebCitationsItemItem1ItemImageUrl';
-
-/**
- * A web citation associated with a chat message.
- */
-export type ChatResponseWebCitationsItemItem1Item = {
- /** A description of the cited page. */
- description?: ChatResponseWebCitationsItemItem1ItemDescription;
- /** The URL of the page's favicon. */
- favicon_url?: ChatResponseWebCitationsItemItem1ItemFaviconUrl;
- /** The URL of the page's image. */
- image_url?: ChatResponseWebCitationsItemItem1ItemImageUrl;
- /** The title of the cited page. */
- title: string;
- /** The URL of the citation. */
- url: string;
-};
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponseWebCitationsItemItem1ItemDescription.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponseWebCitationsItemItem1ItemDescription.ts
deleted file mode 100644
index 748aacd801..0000000000
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponseWebCitationsItemItem1ItemDescription.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- * Generated by orval v7.21.0 🍺
- * Do not edit manually.
- * Document Cognition Service
- * OpenAPI spec version: 1.0.0
- */
-
-/**
- * A description of the cited page.
- */
-export type ChatResponseWebCitationsItemItem1ItemDescription = string | null;
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponseWebCitationsItemItem1ItemFaviconUrl.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponseWebCitationsItemItem1ItemFaviconUrl.ts
deleted file mode 100644
index 7fd489293a..0000000000
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponseWebCitationsItemItem1ItemFaviconUrl.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- * Generated by orval v7.21.0 🍺
- * Do not edit manually.
- * Document Cognition Service
- * OpenAPI spec version: 1.0.0
- */
-
-/**
- * The URL of the page's favicon.
- */
-export type ChatResponseWebCitationsItemItem1ItemFaviconUrl = string | null;
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponseWebCitationsItemItem1ItemImageUrl.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponseWebCitationsItemItem1ItemImageUrl.ts
deleted file mode 100644
index 6eafae3497..0000000000
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/chatResponseWebCitationsItemItem1ItemImageUrl.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- * Generated by orval v7.21.0 🍺
- * Do not edit manually.
- * Document Cognition Service
- * OpenAPI spec version: 1.0.0
- */
-
-/**
- * The URL of the page's image.
- */
-export type ChatResponseWebCitationsItemItem1ItemImageUrl = string | null;
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/chatStreamOneOfSix.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/chatStreamOneOfSix.ts
index 02c64ae442..493ec3e56a 100644
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/chatStreamOneOfSix.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/chatStreamOneOfSix.ts
@@ -4,15 +4,16 @@
* Document Cognition Service
* OpenAPI spec version: 1.0.0
*/
-import type { ChatAttachmentWithName } from './chatAttachmentWithName';
+
import type { ChatStreamOneOfSixType } from './chatStreamOneOfSixType';
+import type { Entity } from './entity';
/**
* The user message that initiated this stream, sent as the first item
so other clients can add it to their local chat state.
*/
export type ChatStreamOneOfSix = {
- attachments: ChatAttachmentWithName[];
+ attachments: Entity[];
chat_id: string;
content: string;
message_id: string;
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/entity.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/entity.ts
new file mode 100644
index 0000000000..6c2a43eb02
--- /dev/null
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/entity.ts
@@ -0,0 +1,18 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * Document Cognition Service
+ * OpenAPI spec version: 1.0.0
+ */
+import type { EntityType } from './entityType';
+
+/**
+ * The Entity describes the minimum amount of information required to describe a unique thing in Macro
+This contains the type of the entity [EntityType] and the string id of that entity
+ */
+export interface Entity {
+ /** The id of that entity */
+ entity_id: string;
+ /** The type of entity we are describing */
+ entity_type: EntityType;
+}
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/entityType.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/entityType.ts
new file mode 100644
index 0000000000..d867033750
--- /dev/null
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/entityType.ts
@@ -0,0 +1,24 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * Document Cognition Service
+ * OpenAPI spec version: 1.0.0
+ */
+
+/**
+ * The type of an entity in Macro
+ */
+export type EntityType = (typeof EntityType)[keyof typeof EntityType];
+
+// eslint-disable-next-line @typescript-eslint/no-redeclare
+export const EntityType = {
+ user: 'user',
+ chat: 'chat',
+ channel: 'channel',
+ document: 'document',
+ project: 'project',
+ email_thread: 'email_thread',
+ team: 'team',
+ call: 'call',
+ static_file: 'static_file',
+} as const;
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/httpSendChatMessageRequestAttachments.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/httpSendChatMessageRequestAttachments.ts
index 05a47a697b..9b33b8cede 100644
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/httpSendChatMessageRequestAttachments.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/httpSendChatMessageRequestAttachments.ts
@@ -4,11 +4,9 @@
* Document Cognition Service
* OpenAPI spec version: 1.0.0
*/
-import type { ChatAttachmentWithName } from './chatAttachmentWithName';
+import type { Entity } from './entity';
/**
* Attachments for the message
*/
-export type HttpSendChatMessageRequestAttachments =
- | ChatAttachmentWithName[]
- | null;
+export type HttpSendChatMessageRequestAttachments = Entity[] | null;
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/index.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/index.ts
index 7959984654..14fe1de243 100644
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/index.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/index.ts
@@ -36,8 +36,6 @@ export * from './chat';
export * from './chatAttachment';
export * from './chatAttachmentChatId';
export * from './chatAttachmentMessageId';
-export * from './chatAttachmentWithName';
-export * from './chatAttachmentWithNameMetadata';
export * from './chatCreatedAt';
export * from './chatDeletedAt';
export * from './chatHistory';
@@ -48,7 +46,6 @@ export * from './chatMessageError';
export * from './chatMessageErrorStreamId';
export * from './chatMessageModel';
export * from './chatMessageWithAttachments';
-export * from './chatMessageWithAttachmentsModel';
export * from './chatModel';
export * from './chatPreview';
export * from './chatPreviewData';
@@ -67,12 +64,7 @@ export * from './chatResponse';
export * from './chatResponseCreatedAt';
export * from './chatResponseModel';
export * from './chatResponseProjectId';
-export * from './chatResponseTokenCount';
export * from './chatResponseUpdatedAt';
-export * from './chatResponseWebCitationsItemItem1Item';
-export * from './chatResponseWebCitationsItemItem1ItemDescription';
-export * from './chatResponseWebCitationsItemItem1ItemFaviconUrl';
-export * from './chatResponseWebCitationsItemItem1ItemImageUrl';
export * from './chatStream';
export * from './chatStreamOneOf';
export * from './chatStreamOneOfAllOf';
@@ -116,6 +108,8 @@ export * from './documentReferenceOneOf';
export * from './documentReferenceOneOfAllOf';
export * from './documentReferenceOneOfAllOfKind';
export * from './documentTextPart';
+export * from './entity';
+export * from './entityType';
export * from './extractionStatusEnum';
export * from './extractionStatusEnumOneOf';
export * from './extractionStatusEnumOneOfFive';
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/sendChatMessagePayloadAllOfAttachments.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/sendChatMessagePayloadAllOfAttachments.ts
index e17b66f1a3..45a02f79a1 100644
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/sendChatMessagePayloadAllOfAttachments.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/sendChatMessagePayloadAllOfAttachments.ts
@@ -4,11 +4,9 @@
* Document Cognition Service
* OpenAPI spec version: 1.0.0
*/
-import type { ChatAttachmentWithName } from './chatAttachmentWithName';
+import type { Entity } from './entity';
/**
* Use citation prompt
*/
-export type SendChatMessagePayloadAllOfAttachments =
- | ChatAttachmentWithName[]
- | null;
+export type SendChatMessagePayloadAllOfAttachments = Entity[] | null;
diff --git a/js/app/packages/service-clients/service-cognition/openapi.json b/js/app/packages/service-clients/service-cognition/openapi.json
index b6d333e893..7d1f9337c5 100644
--- a/js/app/packages/service-clients/service-cognition/openapi.json
+++ b/js/app/packages/service-clients/service-cognition/openapi.json
@@ -1375,35 +1375,6 @@
}
}
},
- "ChatAttachmentWithName": {
- "type": "object",
- "required": ["attachmentType", "attachmentId", "id"],
- "properties": {
- "attachmentId": {
- "type": "string",
- "description": "Id of the attachment [Foreign Key to either document, chat or project]"
- },
- "attachmentType": {
- "$ref": "#/components/schemas/AttachmentType",
- "description": "Type of the attachment ['document' | 'chat' | 'project' | 'image' | 'channel']"
- },
- "id": {
- "type": "string",
- "description": "Incremented int id of the attachment (not really used for anything)"
- },
- "metadata": {
- "oneOf": [
- {
- "type": "null"
- },
- {
- "$ref": "#/components/schemas/AttachmentMetadata",
- "description": "Metadata about the attachment, depending on the type"
- }
- ]
- }
- }
- },
"ChatHistory": {
"type": "object",
"required": ["conversation"],
@@ -1483,7 +1454,7 @@
"attachments": {
"type": "array",
"items": {
- "$ref": "#/components/schemas/ChatAttachmentWithName"
+ "$ref": "#/components/schemas/Entity"
},
"description": "The ids of the attachments used to generate the message"
},
@@ -1495,10 +1466,6 @@
"type": "string",
"description": "The chat message id"
},
- "model": {
- "type": ["string", "null"],
- "description": "The model used to generate the message\nkill"
- },
"role": {
"$ref": "#/components/schemas/Role",
"description": "Whether the chat is from the user or system"
@@ -1582,32 +1549,8 @@
"ChatResponse": {
"type": "object",
"description": "The full chat response, matching the DCS API response shape.",
- "required": [
- "id",
- "userId",
- "name",
- "messages",
- "attachments",
- "availableModels",
- "webCitations",
- "isPersistent"
- ],
+ "required": ["id", "userId", "name", "messages"],
"properties": {
- "attachments": {
- "type": "array",
- "items": {
- "$ref": "#/components/schemas/ChatAttachmentWithName"
- },
- "description": "Attachment context — attachments not attached to messages.",
- "deprecated": true
- },
- "availableModels": {
- "type": "array",
- "items": {
- "$ref": "#/components/schemas/Model"
- },
- "description": "Available models for the chat."
- },
"createdAt": {
"type": ["string", "null"],
"format": "date-time",
@@ -1617,10 +1560,6 @@
"type": "string",
"description": "The chat uuid."
},
- "isPersistent": {
- "type": "boolean",
- "description": "Whether the chat is persistent or not."
- },
"messages": {
"type": "array",
"items": {
@@ -1647,11 +1586,6 @@
"type": ["string", "null"],
"description": "The project id the chat belongs to."
},
- "tokenCount": {
- "type": ["integer", "null"],
- "format": "int64",
- "description": "Current number of tokens in the chat."
- },
"updatedAt": {
"type": ["string", "null"],
"format": "date-time",
@@ -1660,49 +1594,6 @@
"userId": {
"type": "string",
"description": "Who the chat belongs to."
- },
- "webCitations": {
- "type": "array",
- "items": {
- "type": "array",
- "items": false,
- "prefixItems": [
- {
- "type": "string"
- },
- {
- "type": "array",
- "items": {
- "type": "object",
- "description": "A web citation associated with a chat message.",
- "required": ["url", "title"],
- "properties": {
- "description": {
- "type": ["string", "null"],
- "description": "A description of the cited page."
- },
- "favicon_url": {
- "type": ["string", "null"],
- "description": "The URL of the page's favicon."
- },
- "image_url": {
- "type": ["string", "null"],
- "description": "The URL of the page's image."
- },
- "title": {
- "type": "string",
- "description": "The title of the cited page."
- },
- "url": {
- "type": "string",
- "description": "The URL of the citation."
- }
- }
- }
- }
- ]
- },
- "description": "Message ID to web citation list."
}
}
},
@@ -1759,7 +1650,7 @@
"attachments": {
"type": "array",
"items": {
- "$ref": "#/components/schemas/ChatAttachmentWithName"
+ "$ref": "#/components/schemas/Entity"
}
},
"chat_id": {
@@ -2076,6 +1967,36 @@
}
}
},
+ "Entity": {
+ "type": "object",
+ "description": "The Entity describes the minimum amount of information required to describe a unique thing in Macro\nThis contains the type of the entity [EntityType] and the string id of that entity",
+ "required": ["entity_type", "entity_id"],
+ "properties": {
+ "entity_id": {
+ "type": "string",
+ "description": "The id of that entity"
+ },
+ "entity_type": {
+ "$ref": "#/components/schemas/EntityType",
+ "description": "The type of entity we are describing"
+ }
+ }
+ },
+ "EntityType": {
+ "type": "string",
+ "description": "The type of an entity in Macro",
+ "enum": [
+ "user",
+ "chat",
+ "channel",
+ "document",
+ "project",
+ "email_thread",
+ "team",
+ "call",
+ "static_file"
+ ]
+ },
"ExtractionStatusEnum": {
"oneOf": [
{
@@ -2658,7 +2579,7 @@
"attachments": {
"type": ["array", "null"],
"items": {
- "$ref": "#/components/schemas/ChatAttachmentWithName"
+ "$ref": "#/components/schemas/Entity"
},
"description": "Attachments for the message"
},
@@ -2891,7 +2812,7 @@
"attachments": {
"type": ["array", "null"],
"items": {
- "$ref": "#/components/schemas/ChatAttachmentWithName"
+ "$ref": "#/components/schemas/Entity"
},
"description": "Use citation prompt"
},
diff --git a/rust/cloud-storage/.sqlx/query-c9f9b00be9d446b7d45cad5073e9d422689a29c2da56d6888ca37877bef372f0.json b/rust/cloud-storage/.sqlx/query-184633e8b40af8c1077847e8b20dbee5117d4a35ec182b62db7d4ea0507ee73c.json
similarity index 50%
rename from rust/cloud-storage/.sqlx/query-c9f9b00be9d446b7d45cad5073e9d422689a29c2da56d6888ca37877bef372f0.json
rename to rust/cloud-storage/.sqlx/query-184633e8b40af8c1077847e8b20dbee5117d4a35ec182b62db7d4ea0507ee73c.json
index 1537dcb194..313d7cf3a4 100644
--- a/rust/cloud-storage/.sqlx/query-c9f9b00be9d446b7d45cad5073e9d422689a29c2da56d6888ca37877bef372f0.json
+++ b/rust/cloud-storage/.sqlx/query-184633e8b40af8c1077847e8b20dbee5117d4a35ec182b62db7d4ea0507ee73c.json
@@ -1,17 +1,17 @@
{
"db_name": "PostgreSQL",
- "query": "\n INSERT INTO \"ChatAttachment\" (\"attachmentType\", \"attachmentId\", \"chatId\", \"messageId\")\n SELECT * FROM UNNEST($1::TEXT[], $2::TEXT[], $3::TEXT[], $4::TEXT[])\n ",
+ "query": "\n INSERT INTO \"ChatAttachment\" (\"entity_type\", \"entity_id\", \"chatId\", \"messageId\")\n SELECT * FROM UNNEST($1::TEXT[], $2::UUID[], $3::TEXT[], $4::TEXT[])\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"TextArray",
- "TextArray",
+ "UuidArray",
"TextArray",
"TextArray"
]
},
"nullable": []
},
- "hash": "c9f9b00be9d446b7d45cad5073e9d422689a29c2da56d6888ca37877bef372f0"
+ "hash": "184633e8b40af8c1077847e8b20dbee5117d4a35ec182b62db7d4ea0507ee73c"
}
diff --git a/rust/cloud-storage/.sqlx/query-1d0181be77c26e2242abd2aa0a3c9bf77b8247494b2f5937e3dc977dcfc8f90b.json b/rust/cloud-storage/.sqlx/query-1d0181be77c26e2242abd2aa0a3c9bf77b8247494b2f5937e3dc977dcfc8f90b.json
deleted file mode 100644
index dbdcc4795c..0000000000
--- a/rust/cloud-storage/.sqlx/query-1d0181be77c26e2242abd2aa0a3c9bf77b8247494b2f5937e3dc977dcfc8f90b.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO \"ChatAttachment\" (\"attachmentType\", \"attachmentId\", \"chatId\", \"messageId\")\n SELECT * FROM UNNEST($1::TEXT[], $2::TEXT[], $3::TEXT[], $4::TEXT[])\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "TextArray",
- "TextArray",
- "TextArray",
- "TextArray"
- ]
- },
- "nullable": []
- },
- "hash": "1d0181be77c26e2242abd2aa0a3c9bf77b8247494b2f5937e3dc977dcfc8f90b"
-}
diff --git a/rust/cloud-storage/.sqlx/query-f7d8f36ace58fb884736c3568cfb78ecce5d0bafb3be445dd141b2ca21865578.json b/rust/cloud-storage/.sqlx/query-1ed8b097d0371b977eab7215aba09ffc9721b22d7e9d8ea5d80d285dcf65e152.json
similarity index 61%
rename from rust/cloud-storage/.sqlx/query-f7d8f36ace58fb884736c3568cfb78ecce5d0bafb3be445dd141b2ca21865578.json
rename to rust/cloud-storage/.sqlx/query-1ed8b097d0371b977eab7215aba09ffc9721b22d7e9d8ea5d80d285dcf65e152.json
index 642afda53f..ecd2ef9747 100644
--- a/rust/cloud-storage/.sqlx/query-f7d8f36ace58fb884736c3568cfb78ecce5d0bafb3be445dd141b2ca21865578.json
+++ b/rust/cloud-storage/.sqlx/query-1ed8b097d0371b977eab7215aba09ffc9721b22d7e9d8ea5d80d285dcf65e152.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n ca.id,\n ca.\"chatId\" as \"chat_id\",\n ca.\"attachmentId\" as \"attachment_id\",\n ca.\"attachmentType\" as \"attachment_type: AttachmentType\",\n ca.\"messageId\" as \"message_id\"\n FROM\n \"ChatAttachment\" ca\n WHERE ca.\"chatId\" = $1\n ORDER BY ca.id ASC\n ",
+ "query": "\n SELECT\n ca.id,\n ca.\"chatId\" as \"chat_id\",\n ca.\"entity_id\"::TEXT as \"attachment_id!\",\n ca.\"entity_type\" as \"attachment_type: AttachmentType\",\n ca.\"messageId\" as \"message_id\"\n FROM\n \"ChatAttachment\" ca\n WHERE ca.\"chatId\" = $1\n ORDER BY ca.id ASC\n ",
"describe": {
"columns": [
{
@@ -15,7 +15,7 @@
},
{
"ordinal": 2,
- "name": "attachment_id",
+ "name": "attachment_id!",
"type_info": "Text"
},
{
@@ -37,10 +37,10 @@
"nullable": [
false,
true,
- false,
+ null,
false,
true
]
},
- "hash": "f7d8f36ace58fb884736c3568cfb78ecce5d0bafb3be445dd141b2ca21865578"
+ "hash": "1ed8b097d0371b977eab7215aba09ffc9721b22d7e9d8ea5d80d285dcf65e152"
}
diff --git a/rust/cloud-storage/.sqlx/query-3aefae84fc5944abc5595794391ccac5a746205e3c1bbd0bd37b114a67b40bb0.json b/rust/cloud-storage/.sqlx/query-3aefae84fc5944abc5595794391ccac5a746205e3c1bbd0bd37b114a67b40bb0.json
deleted file mode 100644
index 96144043c3..0000000000
--- a/rust/cloud-storage/.sqlx/query-3aefae84fc5944abc5595794391ccac5a746205e3c1bbd0bd37b114a67b40bb0.json
+++ /dev/null
@@ -1,46 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH attachment_info AS (\n SELECT\n ca.id,\n ca.\"attachmentType\",\n ca.\"attachmentId\",\n ca.\"messageId\",\n CASE\n WHEN ca.\"attachmentType\" = 'document' THEN d.name\n WHEN ca.\"attachmentType\" = 'chat' THEN c.name\n WHEN ca.\"attachmentType\" = 'project' THEN p.name\n WHEN ca.\"attachmentType\" = 'image' THEN d.name\n ELSE NULL\n END AS document_name,\n CASE\n WHEN ca.\"attachmentType\" = 'document' THEN d.\"fileType\"\n WHEN ca.\"attachmentType\" = 'image' THEN d.\"fileType\"\n ELSE NULL\n END as document_type\n FROM\n \"ChatAttachment\" ca\n LEFT JOIN\n \"Document\" d ON (\n (ca.\"attachmentType\" = 'document' AND ca.\"attachmentId\" = d.id)\n OR\n (ca.\"attachmentType\" = 'image' AND ca.\"attachmentId\" = d.id)\n )\n LEFT JOIN\n \"Chat\" c ON ca.\"attachmentType\" = 'chat' AND ca.\"attachmentId\" = c.id\n LEFT JOIN\n \"Project\" p ON ca.\"attachmentType\" = 'project' AND ca.\"attachmentId\" = p.id\n )\n SELECT\n cm.id AS \"id!\",\n cm.content,\n cm.role,\n cm.model,\n COALESCE(\n (\n SELECT json_agg(\n json_build_object(\n 'id', attachment_info.\"attachmentId\",\n 'attachmentType', attachment_info.\"attachmentType\",\n 'attachmentId', attachment_info.\"attachmentId\",\n 'documentName', attachment_info.document_name,\n 'documentType', attachment_info.document_type\n )\n )\n FROM attachment_info\n WHERE attachment_info.\"messageId\" = cm.id\n ),\n '[]'::json\n ) AS attachments\n FROM\n \"ChatMessage\" cm\n WHERE\n cm.\"chatId\" = $1\n ORDER BY\n cm.\"createdAt\" ASC\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "content",
- "type_info": "Jsonb"
- },
- {
- "ordinal": 2,
- "name": "role",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "model",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "attachments",
- "type_info": "Json"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- true,
- null
- ]
- },
- "hash": "3aefae84fc5944abc5595794391ccac5a746205e3c1bbd0bd37b114a67b40bb0"
-}
diff --git a/rust/cloud-storage/.sqlx/query-2ddddebfec3d3bded1e74b0e34abf9daee5e67d46eb8d977a6942669d5c8bdf5.json b/rust/cloud-storage/.sqlx/query-54880d69ab1555eb66227f63e0e4b3d940d114ee09eaa06916c48da29b8ce62e.json
similarity index 87%
rename from rust/cloud-storage/.sqlx/query-2ddddebfec3d3bded1e74b0e34abf9daee5e67d46eb8d977a6942669d5c8bdf5.json
rename to rust/cloud-storage/.sqlx/query-54880d69ab1555eb66227f63e0e4b3d940d114ee09eaa06916c48da29b8ce62e.json
index eb06e65e1f..d410732247 100644
--- a/rust/cloud-storage/.sqlx/query-2ddddebfec3d3bded1e74b0e34abf9daee5e67d46eb8d977a6942669d5c8bdf5.json
+++ b/rust/cloud-storage/.sqlx/query-54880d69ab1555eb66227f63e0e4b3d940d114ee09eaa06916c48da29b8ce62e.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n WITH SingleAttachmentChats AS (\n SELECT\n \"chatId\",\n COUNT(*) as attachment_count\n FROM \"ChatAttachment\"\n GROUP BY \"chatId\"\n HAVING COUNT(*) = 1\n )\n SELECT\n c.id,\n c.name,\n c.\"userId\" as \"user_id\",\n c.\"createdAt\"::timestamptz as \"created_at\",\n c.\"updatedAt\"::timestamptz as \"updated_at\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\",\n c.model,\n c.\"tokenCount\" as \"token_count\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\"\n FROM \"Chat\" c\n INNER JOIN \"ChatAttachment\" ca ON c.id = ca.\"chatId\"\n INNER JOIN SingleAttachmentChats sac ON c.id = sac.\"chatId\"\n WHERE\n ca.\"attachmentId\" = $1 AND c.\"userId\" = $2\n AND\n c.\"deletedAt\" IS NULL\n\n ORDER BY c.\"updatedAt\" DESC\n LIMIT 1;\n ",
+ "query": "\n WITH SingleAttachmentChats AS (\n SELECT\n \"chatId\",\n COUNT(*) as attachment_count\n FROM \"ChatAttachment\"\n GROUP BY \"chatId\"\n HAVING COUNT(*) = 1\n )\n SELECT\n c.id,\n c.name,\n c.\"userId\" as \"user_id\",\n c.\"createdAt\"::timestamptz as \"created_at\",\n c.\"updatedAt\"::timestamptz as \"updated_at\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\",\n c.model,\n c.\"tokenCount\" as \"token_count\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\"\n FROM \"Chat\" c\n INNER JOIN \"ChatAttachment\" ca ON c.id = ca.\"chatId\"\n INNER JOIN SingleAttachmentChats sac ON c.id = sac.\"chatId\"\n WHERE\n ca.\"entity_id\"::TEXT = $1 AND c.\"userId\" = $2\n AND\n c.\"deletedAt\" IS NULL\n\n ORDER BY c.\"updatedAt\" DESC\n LIMIT 1;\n ",
"describe": {
"columns": [
{
@@ -73,5 +73,5 @@
false
]
},
- "hash": "2ddddebfec3d3bded1e74b0e34abf9daee5e67d46eb8d977a6942669d5c8bdf5"
+ "hash": "54880d69ab1555eb66227f63e0e4b3d940d114ee09eaa06916c48da29b8ce62e"
}
diff --git a/rust/cloud-storage/.sqlx/query-6df8edb2ab31514a1ad2e48eecc81d52bf70ec8e34a2741be8f7a7b521d5074a.json b/rust/cloud-storage/.sqlx/query-6df8edb2ab31514a1ad2e48eecc81d52bf70ec8e34a2741be8f7a7b521d5074a.json
deleted file mode 100644
index ac1ba33a99..0000000000
--- a/rust/cloud-storage/.sqlx/query-6df8edb2ab31514a1ad2e48eecc81d52bf70ec8e34a2741be8f7a7b521d5074a.json
+++ /dev/null
@@ -1,46 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH attachment_info AS (\n SELECT\n ca.id,\n ca.\"attachmentType\",\n ca.\"attachmentId\",\n ca.\"messageId\",\n CASE\n WHEN ca.\"attachmentType\" = 'document' THEN d.name\n WHEN ca.\"attachmentType\" = 'chat' THEN c.name\n WHEN ca.\"attachmentType\" = 'project' THEN p.name\n WHEN ca.\"attachmentType\" = 'image' THEN d.name\n ELSE NULL\n END AS document_name,\n CASE\n WHEN ca.\"attachmentType\" = 'document' THEN d.\"fileType\"\n WHEN ca.\"attachmentType\" = 'image' THEN d.\"fileType\"\n ELSE NULL\n END as document_type\n FROM\n \"ChatAttachment\" ca\n LEFT JOIN\n \"Document\" d ON (\n (ca.\"attachmentType\" = 'document' AND ca.\"attachmentId\" = d.id)\n OR\n (ca.\"attachmentType\" = 'image' AND ca.\"attachmentId\" = d.id)\n )\n LEFT JOIN\n \"Chat\" c ON ca.\"attachmentType\" = 'chat' AND ca.\"attachmentId\" = c.id\n LEFT JOIN\n \"Project\" p ON ca.\"attachmentType\" = 'project' AND ca.\"attachmentId\" = p.id\n )\n SELECT\n cm.id AS \"id!\",\n cm.content,\n cm.role,\n cm.model,\n COALESCE(\n (\n SELECT json_agg(\n json_build_object(\n 'id', attachment_info.\"attachmentId\",\n 'attachmentType', attachment_info.\"attachmentType\",\n 'attachmentId', attachment_info.\"attachmentId\",\n 'documentName', attachment_info.document_name,\n 'documentType', attachment_info.document_type\n )\n )\n FROM attachment_info\n WHERE attachment_info.\"messageId\" = cm.id\n ),\n '[]'::json\n ) AS attachments\n FROM\n \"ChatMessage\" cm\n WHERE\n cm.\"chatId\" = $1\n ORDER BY\n cm.\"createdAt\" ASC\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "content",
- "type_info": "Jsonb"
- },
- {
- "ordinal": 2,
- "name": "role",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "model",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "attachments",
- "type_info": "Json"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- true,
- null
- ]
- },
- "hash": "6df8edb2ab31514a1ad2e48eecc81d52bf70ec8e34a2741be8f7a7b521d5074a"
-}
diff --git a/rust/cloud-storage/.sqlx/query-df7d76d4a45e69846e1023646321e5e667acc5d95bb68f0e2e1d127cec0da0eb.json b/rust/cloud-storage/.sqlx/query-733e693b7231777ab430290d378ba45d608cf5aa1d39c692c93fe06a5593f312.json
similarity index 60%
rename from rust/cloud-storage/.sqlx/query-df7d76d4a45e69846e1023646321e5e667acc5d95bb68f0e2e1d127cec0da0eb.json
rename to rust/cloud-storage/.sqlx/query-733e693b7231777ab430290d378ba45d608cf5aa1d39c692c93fe06a5593f312.json
index 5608624d22..a0d715326d 100644
--- a/rust/cloud-storage/.sqlx/query-df7d76d4a45e69846e1023646321e5e667acc5d95bb68f0e2e1d127cec0da0eb.json
+++ b/rust/cloud-storage/.sqlx/query-733e693b7231777ab430290d378ba45d608cf5aa1d39c692c93fe06a5593f312.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n ca.id,\n ca.\"attachmentType\" as \"attachment_type: AttachmentType\",\n ca.\"attachmentId\" as \"attachment_id\",\n ca.\"chatId\" as \"chat_id\",\n ca.\"messageId\" as \"message_id\"\n FROM\n \"ChatAttachment\" ca\n WHERE\n ca.\"id\" = $1\n LIMIT 1\n ",
+ "query": "\n SELECT\n ca.id,\n ca.\"entity_type\" as \"attachment_type: AttachmentType\",\n ca.\"entity_id\"::TEXT as \"attachment_id!\",\n ca.\"chatId\" as \"chat_id\",\n ca.\"messageId\" as \"message_id\"\n FROM\n \"ChatAttachment\" ca\n WHERE\n ca.\"id\" = $1\n LIMIT 1\n ",
"describe": {
"columns": [
{
@@ -15,7 +15,7 @@
},
{
"ordinal": 2,
- "name": "attachment_id",
+ "name": "attachment_id!",
"type_info": "Text"
},
{
@@ -37,10 +37,10 @@
"nullable": [
false,
false,
- false,
+ null,
true,
true
]
},
- "hash": "df7d76d4a45e69846e1023646321e5e667acc5d95bb68f0e2e1d127cec0da0eb"
+ "hash": "733e693b7231777ab430290d378ba45d608cf5aa1d39c692c93fe06a5593f312"
}
diff --git a/rust/cloud-storage/.sqlx/query-cad30765c51a8985f2d1235bcefaea7994099835b4b10ad06d9bb36f18e594da.json b/rust/cloud-storage/.sqlx/query-8af0c4dcb1957927aef3afb489b879fc666056bef965cfce73149d446b4c71bd.json
similarity index 50%
rename from rust/cloud-storage/.sqlx/query-cad30765c51a8985f2d1235bcefaea7994099835b4b10ad06d9bb36f18e594da.json
rename to rust/cloud-storage/.sqlx/query-8af0c4dcb1957927aef3afb489b879fc666056bef965cfce73149d446b4c71bd.json
index 6daf9e6fe2..1b652bcf7d 100644
--- a/rust/cloud-storage/.sqlx/query-cad30765c51a8985f2d1235bcefaea7994099835b4b10ad06d9bb36f18e594da.json
+++ b/rust/cloud-storage/.sqlx/query-8af0c4dcb1957927aef3afb489b879fc666056bef965cfce73149d446b4c71bd.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n INSERT INTO \"ChatAttachment\" (\"attachmentType\", \"attachmentId\", \"chatId\")\n VALUES ($1, $2, $3)\n RETURNING id;\n ",
+ "query": "\n INSERT INTO \"ChatAttachment\" (\"entity_type\", \"entity_id\", \"chatId\")\n VALUES ($1, $2, $3)\n RETURNING id;\n ",
"describe": {
"columns": [
{
@@ -12,7 +12,7 @@
"parameters": {
"Left": [
"Text",
- "Text",
+ "Uuid",
"Text"
]
},
@@ -20,5 +20,5 @@
false
]
},
- "hash": "cad30765c51a8985f2d1235bcefaea7994099835b4b10ad06d9bb36f18e594da"
+ "hash": "8af0c4dcb1957927aef3afb489b879fc666056bef965cfce73149d446b4c71bd"
}
diff --git a/rust/cloud-storage/.sqlx/query-69af04267546961d49bdd35751b2f89a5c06f05102a6b68a8fc36429f48eced1.json b/rust/cloud-storage/.sqlx/query-973904cf0ce82830a1a4db5d5ef93577a02892254df31144b5df44bdc5b58381.json
similarity index 59%
rename from rust/cloud-storage/.sqlx/query-69af04267546961d49bdd35751b2f89a5c06f05102a6b68a8fc36429f48eced1.json
rename to rust/cloud-storage/.sqlx/query-973904cf0ce82830a1a4db5d5ef93577a02892254df31144b5df44bdc5b58381.json
index 5a96fb6793..b166df2fe9 100644
--- a/rust/cloud-storage/.sqlx/query-69af04267546961d49bdd35751b2f89a5c06f05102a6b68a8fc36429f48eced1.json
+++ b/rust/cloud-storage/.sqlx/query-973904cf0ce82830a1a4db5d5ef93577a02892254df31144b5df44bdc5b58381.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n ca.id,\n ca.\"attachmentType\" as \"attachment_type: AttachmentType\",\n ca.\"attachmentId\" as \"attachment_id\",\n ca.\"chatId\" as \"chat_id\",\n ca.\"messageId\" as \"message_id\"\n FROM\n \"ChatAttachment\" ca\n WHERE\n ca.\"messageId\" = $1\n LIMIT 1\n ",
+ "query": "\n SELECT\n ca.id,\n ca.\"entity_type\" as \"attachment_type: AttachmentType\",\n ca.\"entity_id\"::TEXT as \"attachment_id!\",\n ca.\"chatId\" as \"chat_id\",\n ca.\"messageId\" as \"message_id\"\n FROM\n \"ChatAttachment\" ca\n WHERE\n ca.\"messageId\" = $1\n LIMIT 1\n ",
"describe": {
"columns": [
{
@@ -15,7 +15,7 @@
},
{
"ordinal": 2,
- "name": "attachment_id",
+ "name": "attachment_id!",
"type_info": "Text"
},
{
@@ -37,10 +37,10 @@
"nullable": [
false,
false,
- false,
+ null,
true,
true
]
},
- "hash": "69af04267546961d49bdd35751b2f89a5c06f05102a6b68a8fc36429f48eced1"
+ "hash": "973904cf0ce82830a1a4db5d5ef93577a02892254df31144b5df44bdc5b58381"
}
diff --git a/rust/cloud-storage/.sqlx/query-9a050086d79aa5be0e89a23048d2eb45a7f04dcc2fbdceed41497048a2410ce5.json b/rust/cloud-storage/.sqlx/query-9a050086d79aa5be0e89a23048d2eb45a7f04dcc2fbdceed41497048a2410ce5.json
new file mode 100644
index 0000000000..1b55805b1b
--- /dev/null
+++ b/rust/cloud-storage/.sqlx/query-9a050086d79aa5be0e89a23048d2eb45a7f04dcc2fbdceed41497048a2410ce5.json
@@ -0,0 +1,46 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n cm.id AS \"id!\",\n cm.content,\n cm.role,\n cm.model,\n COALESCE(\n (\n SELECT json_agg(\n json_build_object(\n 'entity_type', ca.\"entity_type\",\n 'entity_id', ca.\"entity_id\"::TEXT\n )\n )\n FROM \"ChatAttachment\" ca\n WHERE ca.\"messageId\" = cm.id\n ),\n '[]'::json\n ) AS attachments\n FROM\n \"ChatMessage\" cm\n WHERE\n cm.\"chatId\" = $1\n ORDER BY\n cm.\"createdAt\" ASC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "content",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 2,
+ "name": "role",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "model",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "attachments",
+ "type_info": "Json"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ null
+ ]
+ },
+ "hash": "9a050086d79aa5be0e89a23048d2eb45a7f04dcc2fbdceed41497048a2410ce5"
+}
diff --git a/rust/cloud-storage/.sqlx/query-bbd2b467cf8f1e277d3278fafdc5792183e42f6c00ae95aa0f4fe869292408f0.json b/rust/cloud-storage/.sqlx/query-bbd2b467cf8f1e277d3278fafdc5792183e42f6c00ae95aa0f4fe869292408f0.json
new file mode 100644
index 0000000000..14e2f4f6f8
--- /dev/null
+++ b/rust/cloud-storage/.sqlx/query-bbd2b467cf8f1e277d3278fafdc5792183e42f6c00ae95aa0f4fe869292408f0.json
@@ -0,0 +1,46 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n cm.id AS \"id!\",\n cm.content,\n cm.role,\n cm.model,\n COALESCE(\n (\n SELECT json_agg(\n json_build_object(\n 'entity_type', ca.\"entity_type\",\n 'entity_id', ca.\"entity_id\"::TEXT\n )\n )\n FROM \"ChatAttachment\" ca\n WHERE ca.\"messageId\" = cm.id\n ),\n '[]'::json\n ) AS attachments\n FROM\n \"ChatMessage\" cm\n WHERE\n cm.\"chatId\" = $1\n ORDER BY\n cm.\"createdAt\" ASC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "content",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 2,
+ "name": "role",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "model",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "attachments",
+ "type_info": "Json"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ null
+ ]
+ },
+ "hash": "bbd2b467cf8f1e277d3278fafdc5792183e42f6c00ae95aa0f4fe869292408f0"
+}
diff --git a/rust/cloud-storage/.sqlx/query-bca8bec6b99f7b9a3e8def2a53209e2d0f92546933588bad33bc3520d2ad2d10.json b/rust/cloud-storage/.sqlx/query-bca8bec6b99f7b9a3e8def2a53209e2d0f92546933588bad33bc3520d2ad2d10.json
new file mode 100644
index 0000000000..f7b8c0544e
--- /dev/null
+++ b/rust/cloud-storage/.sqlx/query-bca8bec6b99f7b9a3e8def2a53209e2d0f92546933588bad33bc3520d2ad2d10.json
@@ -0,0 +1,17 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"ChatAttachment\" (\"entity_type\", \"entity_id\", \"chatId\", \"messageId\")\n SELECT * FROM UNNEST($1::TEXT[], $2::UUID[], $3::TEXT[], $4::TEXT[])\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "UuidArray",
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "bca8bec6b99f7b9a3e8def2a53209e2d0f92546933588bad33bc3520d2ad2d10"
+}
diff --git a/rust/cloud-storage/.sqlx/query-5b80d3808a67dec493adf6f88ed7d642451d84970962ddb75a13d017b4837fbb.json b/rust/cloud-storage/.sqlx/query-cb4e7ca0b0a9c275fd8e4e2507017d2dcf7238a82ac9779e4887536003556e60.json
similarity index 89%
rename from rust/cloud-storage/.sqlx/query-5b80d3808a67dec493adf6f88ed7d642451d84970962ddb75a13d017b4837fbb.json
rename to rust/cloud-storage/.sqlx/query-cb4e7ca0b0a9c275fd8e4e2507017d2dcf7238a82ac9779e4887536003556e60.json
index 33f5fcf029..af2517bc84 100644
--- a/rust/cloud-storage/.sqlx/query-5b80d3808a67dec493adf6f88ed7d642451d84970962ddb75a13d017b4837fbb.json
+++ b/rust/cloud-storage/.sqlx/query-cb4e7ca0b0a9c275fd8e4e2507017d2dcf7238a82ac9779e4887536003556e60.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n WITH MultiAttachmentChats AS (\n SELECT\n \"chatId\",\n COUNT(*) as attachment_count\n FROM \"ChatAttachment\"\n GROUP BY \"chatId\"\n )\n SELECT\n c.id,\n c.name,\n c.\"userId\" as \"user_id\",\n c.\"createdAt\"::timestamptz as \"created_at\",\n c.\"updatedAt\"::timestamptz as \"updated_at\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\",\n c.model,\n c.\"tokenCount\" as \"token_count\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\"\n FROM \"Chat\" c\n INNER JOIN \"ChatAttachment\" ca ON c.id = ca.\"chatId\"\n INNER JOIN MultiAttachmentChats mac ON c.id = mac.\"chatId\"\n WHERE\n ca.\"attachmentId\" = $1 AND c.\"userId\" = $2\n AND\n c.\"deletedAt\" IS NULL\n ORDER BY c.\"updatedAt\" DESC;\n ",
+ "query": "\n WITH MultiAttachmentChats AS (\n SELECT\n \"chatId\",\n COUNT(*) as attachment_count\n FROM \"ChatAttachment\"\n GROUP BY \"chatId\"\n )\n SELECT\n c.id,\n c.name,\n c.\"userId\" as \"user_id\",\n c.\"createdAt\"::timestamptz as \"created_at\",\n c.\"updatedAt\"::timestamptz as \"updated_at\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\",\n c.model,\n c.\"tokenCount\" as \"token_count\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\"\n FROM \"Chat\" c\n INNER JOIN \"ChatAttachment\" ca ON c.id = ca.\"chatId\"\n INNER JOIN MultiAttachmentChats mac ON c.id = mac.\"chatId\"\n WHERE\n ca.\"entity_id\"::TEXT = $1 AND c.\"userId\" = $2\n AND\n c.\"deletedAt\" IS NULL\n ORDER BY c.\"updatedAt\" DESC;\n ",
"describe": {
"columns": [
{
@@ -73,5 +73,5 @@
false
]
},
- "hash": "5b80d3808a67dec493adf6f88ed7d642451d84970962ddb75a13d017b4837fbb"
+ "hash": "cb4e7ca0b0a9c275fd8e4e2507017d2dcf7238a82ac9779e4887536003556e60"
}
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 8917880531..e335c26f14 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -6755,6 +6755,7 @@ dependencies = [
"document_sub_type",
"doppleganger",
"macro_user_id",
+ "model-entity",
"model-error-response",
"model_file_type",
"model_user",
diff --git a/rust/cloud-storage/chat/src/domain/models/chat.rs b/rust/cloud-storage/chat/src/domain/models/chat.rs
index 90f0abd4e9..45e744fd7c 100644
--- a/rust/cloud-storage/chat/src/domain/models/chat.rs
+++ b/rust/cloud-storage/chat/src/domain/models/chat.rs
@@ -1,11 +1,9 @@
use ai::types::Model;
-use model::chat::{ChatAttachmentWithName, ChatMessageWithAttachments};
+use model::chat::ChatMessageWithAttachments;
use models_permissions::share_permission::access_level::AccessLevel;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
-use super::WebCitation;
-
/// Arguments for creating a new chat.
#[derive(Debug)]
pub struct CreateChatArgs {
@@ -66,15 +64,4 @@ pub struct ChatResponse {
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
/// The time the chat was last updated.
pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
- /// Attachment context — attachments not attached to messages.
- #[deprecated(note = "Attachments are now stateless and no longer float until message send")]
- pub attachments: Vec<ChatAttachmentWithName>,
- /// Current number of tokens in the chat.
- pub token_count: Option<i64>,
- /// Available models for the chat.
- pub available_models: Vec<Model>,
- /// Message ID to web citation list.
- pub web_citations: Vec<(String, Vec<WebCitation>)>,
- /// Whether the chat is persistent or not.
- pub is_persistent: bool,
}
diff --git a/rust/cloud-storage/chat/src/domain/service/message.rs b/rust/cloud-storage/chat/src/domain/service/message.rs
index f955560d16..c2f8670c0f 100644
--- a/rust/cloud-storage/chat/src/domain/service/message.rs
+++ b/rust/cloud-storage/chat/src/domain/service/message.rs
@@ -28,17 +28,13 @@ impl<R: MessageRepo, A: AttachmentService> MessageServiceImpl<R, A> {
async fn resolve_attachments(
&self,
user_id: &MacroUserIdStr<'_>,
- attachments: &[(AttachmentType, String)],
+ attachments: &[Entity<'_>],
) -> Result<Option<FormattedParts>> {
if attachments.is_empty() {
return Ok(None);
}
- let entities: Vec<Entity<'static>> = attachments
- .iter()
- .map(|(kind, id)| attachment_type_to_entity_type(kind).with_entity_string(id.clone()))
- .collect();
- let entity_refs: Vec<&Entity<'_>> = entities.iter().collect();
+ let entity_refs: Vec<&Entity<'_>> = attachments.iter().collect();
let non_empty = NonEmpty::new(entity_refs.as_slice()).expect("checked non-empty above");
let resolved = self
@@ -58,15 +54,18 @@ impl<R: MessageRepo, A: AttachmentService> MessageService for MessageServiceImpl
chat_id: &str,
message: NewChatMessage,
) -> Result<ResolvedMessageContent> {
- let attachment_pairs: Vec<_> = message
+ let entities: Vec<Entity<'static>> = message
.attachments
.as_deref()
.unwrap_or_default()
.iter()
- .map(|a| (a.attachment_type.clone(), a.attachment_id.clone()))
+ .map(|a| {
+ attachment_type_to_entity_type(&a.attachment_type)
+ .with_entity_string(a.attachment_id.clone())
+ })
.collect();
- let resolved = self.resolve_attachments(user_id, &attachment_pairs).await?;
+ let resolved = self.resolve_attachments(user_id, &entities).await?;
let message_id = self.repo.create(chat_id, message).await?;
@@ -101,13 +100,7 @@ impl<R: MessageRepo, A: AttachmentService> MessageService for MessageServiceImpl
.find(|m| m.id == message_id)
.ok_or(ChatErr::NotFound)?;
- let attachment_pairs: Vec<_> = msg
- .attachments
- .iter()
- .map(|a| (a.attachment_type.clone(), a.attachment_id.clone()))
- .collect();
-
- let resolved = self.resolve_attachments(user_id, &attachment_pairs).await?;
+ let resolved = self.resolve_attachments(user_id, &msg.attachments).await?;
self.repo
.update_message_content(chat_id, message_id, content)
diff --git a/rust/cloud-storage/chat/src/inbound/test.rs b/rust/cloud-storage/chat/src/inbound/test.rs
index 6d4884e1bc..dbdb24e059 100644
--- a/rust/cloud-storage/chat/src/inbound/test.rs
+++ b/rust/cloud-storage/chat/src/inbound/test.rs
@@ -50,11 +50,6 @@ impl ChatService for MockService {
model: None,
created_at: None,
updated_at: None,
- attachments: Vec::new(),
- token_count: None,
- available_models: Vec::new(),
- web_citations: Vec::new(),
- is_persistent: false,
},
user_access_level: AccessLevel::Owner,
})
diff --git a/rust/cloud-storage/chat/src/inbound/toolset/read_chat.rs b/rust/cloud-storage/chat/src/inbound/toolset/read_chat.rs
index 2ba0b7480b..60322dc503 100644
--- a/rust/cloud-storage/chat/src/inbound/toolset/read_chat.rs
+++ b/rust/cloud-storage/chat/src/inbound/toolset/read_chat.rs
@@ -99,7 +99,7 @@ where
attachment_ids: msg
.attachments
.into_iter()
- .map(|a| a.attachment_id)
+ .map(|a| a.entity_id.into_owned())
.collect(),
})
})
diff --git a/rust/cloud-storage/chat/src/outbound/postgres/mod.rs b/rust/cloud-storage/chat/src/outbound/postgres/mod.rs
index cc0ec588a0..792f78c4ae 100644
--- a/rust/cloud-storage/chat/src/outbound/postgres/mod.rs
+++ b/rust/cloud-storage/chat/src/outbound/postgres/mod.rs
@@ -49,13 +49,6 @@ impl PgChatRepo {
queries::get_messages::get_messages(&self.pool, chat_id).await
}
- async fn get_web_citations(
- &self,
- chat_id: &str,
- ) -> anyhow::Result<Vec<(String, Vec<WebCitation>)>> {
- queries::get_web_citations::get_web_citations(&self.pool, chat_id).await
- }
-
/// Store a resolved message without going through the trait.
pub async fn store_resolved_message_static(
&self,
@@ -130,8 +123,6 @@ impl ChatRepo for PgChatRepo {
let chat = self.get_metadata(chat_id).await?;
let mut messages = self.get_messages(chat_id).await.map_err(to_chat_err)?;
messages.retain(|m| m.role != ai::types::Role::System);
- let web_citations = self.get_web_citations(chat_id).await.unwrap_or_default();
-
Ok(ChatResponse {
id: chat.id,
user_id: chat.user_id,
@@ -141,11 +132,6 @@ impl ChatRepo for PgChatRepo {
project_id: chat.project_id,
created_at: chat.created_at,
updated_at: chat.updated_at,
- attachments: Vec::new(),
- token_count: chat.token_count,
- available_models: vec![FALLBACK_MODEL],
- web_citations,
- is_persistent: chat.is_persistent,
})
}
diff --git a/rust/cloud-storage/chat/src/outbound/postgres/queries/create_message.rs b/rust/cloud-storage/chat/src/outbound/postgres/queries/create_message.rs
index 5f20f403fb..3702f65129 100644
--- a/rust/cloud-storage/chat/src/outbound/postgres/queries/create_message.rs
+++ b/rust/cloud-storage/chat/src/outbound/postgres/queries/create_message.rs
@@ -1,9 +1,20 @@
//! Insert a new chat message with optional attachments.
use ai::types::Role;
-use model::chat::NewChatMessage;
+use model::chat::{AttachmentType, NewChatMessage};
+use model_entity::EntityType;
use sqlx::PgPool;
+fn attachment_type_to_entity_type(at: &AttachmentType) -> EntityType {
+ match at {
+ AttachmentType::Document => EntityType::Document,
+ AttachmentType::Image => EntityType::StaticFile,
+ AttachmentType::Channel => EntityType::Channel,
+ AttachmentType::Email => EntityType::EmailThread,
+ AttachmentType::Project => EntityType::Project,
+ }
+}
+
/// Insert a message into a chat, returning the message ID.
///
/// User messages also insert their attachments in the same transaction.
@@ -42,12 +53,12 @@ pub(crate) async fn create_message(
if message.role == Role::User {
let mut kinds = Vec::new();
- let mut ids = Vec::new();
+ let mut ids: Vec<uuid::Uuid> = Vec::new();
let mut chat_ids = Vec::new();
let mut message_ids = Vec::new();
for a in message.attachments.unwrap_or_default() {
- kinds.push(a.attachment_type.to_string());
- ids.push(a.attachment_id);
+ kinds.push(attachment_type_to_entity_type(&a.attachment_type).to_string());
+ ids.push(uuid::Uuid::parse_str(&a.attachment_id)?);
chat_ids.push(chat_id.to_string());
message_ids.push(message_id.clone());
}
@@ -55,8 +66,8 @@ pub(crate) async fn create_message(
if !kinds.is_empty() {
sqlx::query!(
r#"
- INSERT INTO "ChatAttachment" ("attachmentType", "attachmentId", "chatId", "messageId")
- SELECT * FROM UNNEST($1::TEXT[], $2::TEXT[], $3::TEXT[], $4::TEXT[])
+ INSERT INTO "ChatAttachment" ("entity_type", "entity_id", "chatId", "messageId")
+ SELECT * FROM UNNEST($1::TEXT[], $2::UUID[], $3::TEXT[], $4::TEXT[])
"#,
&kinds,
&ids,
diff --git a/rust/cloud-storage/chat/src/outbound/postgres/queries/get_messages.rs b/rust/cloud-storage/chat/src/outbound/postgres/queries/get_messages.rs
index 18389183a5..bd0126043f 100644
--- a/rust/cloud-storage/chat/src/outbound/postgres/queries/get_messages.rs
+++ b/rust/cloud-storage/chat/src/outbound/postgres/queries/get_messages.rs
@@ -1,18 +1,14 @@
//! Fetch all messages for a chat with their attachments.
use ai::types::{ChatMessageContent, Role};
-use model::chat::{
- AttachmentMetadata, AttachmentType, ChatAttachmentWithName, ChatMessageWithAttachments,
-};
+use model::chat::ChatMessageWithAttachments;
+use model_entity::{Entity, EntityType};
use sqlx::PgPool;
#[derive(serde::Deserialize, Debug)]
-#[serde(rename_all = "camelCase")]
struct RawAttachment {
- attachment_id: String,
- attachment_type: String,
- document_name: Option<String>,
- document_type: Option<model::document::FileType>,
+ entity_type: String,
+ entity_id: String,
}
/// Fetch all messages for a chat, with inline attachment metadata from DB joins.
@@ -23,37 +19,6 @@ pub(crate) async fn get_messages(
) -> anyhow::Result<Vec<ChatMessageWithAttachments>> {
let records = sqlx::query!(
r#"
- WITH attachment_info AS (
- SELECT
- ca.id,
- ca."attachmentType",
- ca."attachmentId",
- ca."messageId",
- CASE
- WHEN ca."attachmentType" = 'document' THEN d.name
- WHEN ca."attachmentType" = 'chat' THEN c.name
- WHEN ca."attachmentType" = 'project' THEN p.name
- WHEN ca."attachmentType" = 'image' THEN d.name
- ELSE NULL
- END AS document_name,
- CASE
- WHEN ca."attachmentType" = 'document' THEN d."fileType"
- WHEN ca."attachmentType" = 'image' THEN d."fileType"
- ELSE NULL
- END as document_type
- FROM
- "ChatAttachment" ca
- LEFT JOIN
- "Document" d ON (
- (ca."attachmentType" = 'document' AND ca."attachmentId" = d.id)
- OR
- (ca."attachmentType" = 'image' AND ca."attachmentId" = d.id)
- )
- LEFT JOIN
- "Chat" c ON ca."attachmentType" = 'chat' AND ca."attachmentId" = c.id
- LEFT JOIN
- "Project" p ON ca."attachmentType" = 'project' AND ca."attachmentId" = p.id
- )
SELECT
cm.id AS "id!",
cm.content,
@@ -63,15 +28,12 @@ pub(crate) async fn get_messages(
(
SELECT json_agg(
json_build_object(
- 'id', attachment_info."attachmentId",
- 'attachmentType', attachment_info."attachmentType",
- 'attachmentId', attachment_info."attachmentId",
- 'documentName', attachment_info.document_name,
- 'documentType', attachment_info.document_type
+ 'entity_type', ca."entity_type",
+ 'entity_id', ca."entity_id"::TEXT
)
)
- FROM attachment_info
- WHERE attachment_info."messageId" = cm.id
+ FROM "ChatAttachment" ca
+ WHERE ca."messageId" = cm.id
),
'[]'::json
) AS attachments
@@ -109,7 +71,6 @@ pub(crate) async fn get_messages(
content,
role,
attachments,
- model: record.model,
}
})
.collect();
@@ -117,50 +78,7 @@ pub(crate) async fn get_messages(
Ok(messages)
}
-fn parse_raw_attachment(raw: RawAttachment) -> Option<ChatAttachmentWithName> {
- match raw.attachment_type.as_str() {
- "document" => Some(ChatAttachmentWithName {
- id: raw.attachment_id.clone(),
- attachment_id: raw.attachment_id,
- attachment_type: AttachmentType::Document,
- metadata: raw.document_name.zip(raw.document_type).map(|(name, ft)| {
- AttachmentMetadata::Document {
- document_type: ft,
- document_name: name,
- }
- }),
- }),
- "image" => Some(ChatAttachmentWithName {
- id: raw.attachment_id.clone(),
- attachment_id: raw.attachment_id,
- attachment_type: AttachmentType::Image,
- metadata: raw.document_name.zip(raw.document_type).map(|(name, ft)| {
- AttachmentMetadata::Image {
- image_extension: ft,
- image_name: name,
- }
- }),
- }),
- "project" => Some(ChatAttachmentWithName {
- id: raw.attachment_id.clone(),
- attachment_id: raw.attachment_id,
- attachment_type: AttachmentType::Project,
- metadata: raw
- .document_name
- .map(|name| AttachmentMetadata::Project { project_name: name }),
- }),
- "channel" => Some(ChatAttachmentWithName {
- id: raw.attachment_id.clone(),
- attachment_id: raw.attachment_id,
- attachment_type: AttachmentType::Channel,
- metadata: None,
- }),
- "email" => Some(ChatAttachmentWithName {
- id: raw.attachment_id.clone(),
- attachment_id: raw.attachment_id,
- attachment_type: AttachmentType::Email,
- metadata: None,
- }),
- _ => None,
- }
+fn parse_raw_attachment(raw: RawAttachment) -> Option<Entity<'static>> {
+ let entity_type: EntityType = raw.entity_type.parse().ok()?;
+ Some(entity_type.with_entity_string(raw.entity_id))
}
diff --git a/rust/cloud-storage/chat/src/outbound/postgres/test.rs b/rust/cloud-storage/chat/src/outbound/postgres/test.rs
index b28027a9e0..f498e9064d 100644
--- a/rust/cloud-storage/chat/src/outbound/postgres/test.rs
+++ b/rust/cloud-storage/chat/src/outbound/postgres/test.rs
@@ -552,8 +552,6 @@ async fn get_chat_returns_full_response(pool: Pool<Postgres>) {
assert_eq!(response.user_id, "macro|[email protected]");
assert!(response.model.is_some());
assert!(response.messages.is_empty());
- assert!(response.web_citations.is_empty());
- assert!(!response.available_models.is_empty());
}
#[sqlx::test(
diff --git a/rust/cloud-storage/document_cognition_service/fixtures/chat_example.sql b/rust/cloud-storage/document_cognition_service/fixtures/chat_example.sql
index 99de656aa7..6100542d57 100644
--- a/rust/cloud-storage/document_cognition_service/fixtures/chat_example.sql
+++ b/rust/cloud-storage/document_cognition_service/fixtures/chat_example.sql
@@ -6,11 +6,11 @@ VALUES ('macro|[email protected]', '[email protected]','stripe_id','a1111111-1111-1111-1
-- Test Documents
INSERT INTO public."Document" ("id","name","fileType", "owner")
-VALUES ('document-one', 'test_document_name','pdf', 'macro|[email protected]');
+VALUES ('d0000001-0000-0000-0000-000000000001', 'test_document_name','pdf', 'macro|[email protected]');
INSERT INTO public."Document" ("id","name","fileType", "owner")
-VALUES ('document-two', 'test_document_name','pdf', 'macro|[email protected]');
+VALUES ('d0000002-0000-0000-0000-000000000002', 'test_document_name','pdf', 'macro|[email protected]');
INSERT INTO public."Document" ("id","name","fileType", "owner")
-VALUES ('document-three', 'test_document_name','pdf', 'macro|[email protected]');
+VALUES ('d0000003-0000-0000-0000-000000000003', 'test_document_name','pdf', 'macro|[email protected]');
-- Test Chats
INSERT INTO public."Chat" ("id","name","userId", "model", "createdAt", "updatedAt")
@@ -28,17 +28,17 @@ INSERT INTO public."ChatMessage" ("id", "content", "role", "chatId")
VALUES ('message-two', '"test-chat message 2"', 'user', 'chat-three');
-- Chat attachments on both chat
-INSERT INTO public."ChatAttachment" ("id", "chatId", "attachmentType", "attachmentId")
-VALUES ('chat-attachment-one', 'chat-one', 'document', 'document-two');
-INSERT INTO public."ChatAttachment" ("id", "chatId", "attachmentType", "attachmentId")
-VALUES ('chat-attachment-two', 'chat-one', 'document', 'document-two');
-INSERT INTO public."ChatAttachment" ("id", "chatId", "attachmentType", "attachmentId")
-VALUES ('chat-attachment-six', 'chat-two', 'document', 'document-two');
+INSERT INTO public."ChatAttachment" ("id", "chatId", "entity_type", "entity_id")
+VALUES ('chat-attachment-one', 'chat-one', 'document', 'd0000002-0000-0000-0000-000000000002');
+INSERT INTO public."ChatAttachment" ("id", "chatId", "entity_type", "entity_id")
+VALUES ('chat-attachment-two', 'chat-one', 'document', 'd0000002-0000-0000-0000-000000000002');
+INSERT INTO public."ChatAttachment" ("id", "chatId", "entity_type", "entity_id")
+VALUES ('chat-attachment-six', 'chat-two', 'document', 'd0000002-0000-0000-0000-000000000002');
-- Chat attachments on messages
-INSERT INTO public."ChatAttachment" ("id", "messageId", "attachmentType", "attachmentId")
-VALUES ('chat-attachment-three', 'message-one', 'document', 'document-one');
-INSERT INTO public."ChatAttachment" ("id", "messageId", "attachmentType", "attachmentId")
-VALUES ('chat-attachment-four', 'message-one', 'document', 'document-two');
-INSERT INTO public."ChatAttachment" ("id", "messageId", "attachmentType", "attachmentId")
-VALUES ('chat-attachment-five', 'message-one', 'document', 'document-three');
+INSERT INTO public."ChatAttachment" ("id", "messageId", "entity_type", "entity_id")
+VALUES ('chat-attachment-three', 'message-one', 'document', 'd0000001-0000-0000-0000-000000000001');
+INSERT INTO public."ChatAttachment" ("id", "messageId", "entity_type", "entity_id")
+VALUES ('chat-attachment-four', 'message-one', 'document', 'd0000002-0000-0000-0000-000000000002');
+INSERT INTO public."ChatAttachment" ("id", "messageId", "entity_type", "entity_id")
+VALUES ('chat-attachment-five', 'message-one', 'document', 'd0000003-0000-0000-0000-000000000003');
diff --git a/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs b/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs
index dc0f150095..b36db46406 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs
@@ -28,9 +28,8 @@ use macro_auth::headers::AccessTokenExtractor;
use macro_db_client::dcs::create_chat;
use macro_user_id::user_id::MacroUserIdStr;
use memory::domain::MemoryService;
-use model::chat::ChatAttachmentWithName;
use model::user::UserContext;
-use model_entity::EntityType;
+use model_entity::{Entity, EntityType};
use models_permissions::share_permission::SharePermissionV2;
use models_permissions::share_permission::access_level::AccessLevel;
use serde::{Deserialize, Serialize};
@@ -80,7 +79,7 @@ pub struct HttpSendChatMessageRequest {
pub additional_instructions: Option<String>,
/// Attachments for the message
#[serde(skip_serializing_if = "Option::is_none")]
- pub attachments: Option<Vec<ChatAttachmentWithName>>,
+ pub attachments: Option<Vec<Entity<'static>>>,
/// Which toolset to use. Defaults to `all`
#[serde(default)]
pub toolset: ToolSet,
@@ -135,7 +134,7 @@ impl IntoResponse for ChatMessageError {
(status = 403, description = "Forbidden"),
)
)]
-#[tracing::instrument(skip(state, model_access, user_context, bearer, request), fields(chat_id=?request.chat_id, user_id = %user_context.user_id, attachment_ids=?request.attachments.as_ref().map(|a| a.iter().map(|att| att.attachment_id.as_str()).collect::<Vec<_>>()).unwrap_or_default()), ret, err)]
+#[tracing::instrument(skip(state, model_access, user_context, bearer, request), fields(chat_id=?request.chat_id, user_id = %user_context.user_id, attachment_ids=?request.attachments.as_ref().map(|a| a.iter().map(|att| att.entity_id.as_ref()).collect::<Vec<_>>()).unwrap_or_default()), ret, err)]
pub async fn send_chat_message(
State(state): State<ApiContext>,
model_access: ChatModelAccess,
@@ -439,7 +438,7 @@ fn stream_and_save_message(
now: std::time::Instant,
user_message_content: String,
user_message_id: String,
- user_message_attachments: Vec<ChatAttachmentWithName>,
+ user_message_attachments: Vec<Entity<'static>>,
durable_stream_id: StreamId,
cancellation_sub: CancellationSubscription,
) {
diff --git a/rust/cloud-storage/document_cognition_service/src/api/stream/util/chat_message/mod.rs b/rust/cloud-storage/document_cognition_service/src/api/stream/util/chat_message/mod.rs
index 8ac439743b..81b4e104c7 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/stream/util/chat_message/mod.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/stream/util/chat_message/mod.rs
@@ -13,7 +13,8 @@ use ai::types::{ChatMessage, ChatMessageContent};
use anyhow::{Context, Result};
use chat::domain::models::ResolvedMessageContent;
use chat::domain::ports::MessageService;
-use model::chat::{NewAttachment, NewChatMessage};
+use model::chat::{AttachmentType, NewAttachment, NewChatMessage};
+use model_entity::EntityType;
use std::sync::Arc;
/// Stores the incoming user message and resolves its attachments in one step.
@@ -33,10 +34,19 @@ pub async fn store_incoming_message(
attachments: incoming_message.attachments.as_ref().map(|attachments| {
attachments
.iter()
- .cloned()
- .map(|attachment| NewAttachment {
- attachment_id: attachment.attachment_id,
- attachment_type: attachment.attachment_type,
+ .filter_map(|entity| {
+ let attachment_type = match entity.entity_type {
+ EntityType::Document => AttachmentType::Document,
+ EntityType::StaticFile => AttachmentType::Image,
+ EntityType::Channel => AttachmentType::Channel,
+ EntityType::EmailThread => AttachmentType::Email,
+ EntityType::Project => AttachmentType::Project,
+ _ => return None,
+ };
+ Some(NewAttachment {
+ attachment_id: entity.entity_id.clone().into_owned(),
+ attachment_type,
+ })
})
.collect()
}),
diff --git a/rust/cloud-storage/document_cognition_service/src/api/swagger.rs b/rust/cloud-storage/document_cognition_service/src/api/swagger.rs
index c3b9ea12b5..33dcb53a94 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/swagger.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/swagger.rs
@@ -32,9 +32,9 @@ use chat::inbound::{
use model::{
chat::{
- AttachmentMetadata, AttachmentType, Chat, ChatAttachment, ChatAttachmentWithName,
- ChatHistory, ChatMessage, ChatMessageWithAttachments, ConversationRecord,
- MessageWithAttachments, NewAttachment, NewChatMessage, NewMessageAttachment,
+ AttachmentMetadata, AttachmentType, Chat, ChatAttachment, ChatHistory, ChatMessage,
+ ChatMessageWithAttachments, ConversationRecord, MessageWithAttachments, NewAttachment,
+ NewChatMessage, NewMessageAttachment,
},
response::{GenericErrorResponse, StringIDResponse},
version::DocumentCognitionServiceApiVersion,
@@ -97,7 +97,6 @@ use utoipa::OpenApi;
Chat,
ChatAttachment,
AttachmentType,
- ChatAttachmentWithName,
ChatHistory,
ConversationRecord,
MessageWithAttachments,
diff --git a/rust/cloud-storage/document_cognition_service/src/model/chats.rs b/rust/cloud-storage/document_cognition_service/src/model/chats.rs
index 757d44c922..1e941e53bb 100644
--- a/rust/cloud-storage/document_cognition_service/src/model/chats.rs
+++ b/rust/cloud-storage/document_cognition_service/src/model/chats.rs
@@ -1,6 +1,7 @@
#![allow(deprecated)]
use ai::types::Model;
-use model::chat::{ChatAttachmentWithName, ChatMessageWithAttachments};
+use model::chat::ChatMessageWithAttachments;
+use model_entity::Entity;
use serde::{Deserialize, Serialize};
use unfurl_service::GetUnfurlResponse;
use utoipa::ToSchema;
@@ -26,7 +27,7 @@ pub struct ChatResponse {
pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
/// attachment context - attachments not attached to messages
#[deprecated(note = "Attachments are now stateless and no longer float until message send")]
- pub attachments: Vec<ChatAttachmentWithName>,
+ pub attachments: Vec<Entity<'static>>,
/// Current number of tokens in the chat
// kill
pub token_count: Option<i64>,
diff --git a/rust/cloud-storage/document_cognition_service/src/model/stream.rs b/rust/cloud-storage/document_cognition_service/src/model/stream.rs
index 8dad31b755..dc7fcb0916 100644
--- a/rust/cloud-storage/document_cognition_service/src/model/stream.rs
+++ b/rust/cloud-storage/document_cognition_service/src/model/stream.rs
@@ -1,6 +1,6 @@
use ai::types::AssistantMessagePart;
use ai::types::Model;
-use model::chat::ChatAttachmentWithName;
+use model_entity::Entity;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
@@ -32,7 +32,7 @@ pub struct SendChatMessagePayload {
pub additional_instructions: Option<String>,
/// Use citation prompt
#[serde(skip_serializing_if = "Option::is_none")]
- pub attachments: Option<Vec<ChatAttachmentWithName>>,
+ pub attachments: Option<Vec<Entity<'static>>>,
/// Which toolset to use. Defaults to `all`
#[serde(default)]
pub toolset: ToolSet,
@@ -93,7 +93,7 @@ pub enum ChatStream {
chat_id: String,
message_id: String,
content: String,
- attachments: Vec<ChatAttachmentWithName>,
+ attachments: Vec<Entity<'static>>,
},
/// Indicates a response from the chat completion API for a given message
diff --git a/rust/cloud-storage/document_cognition_service/src/service/get_chat.rs b/rust/cloud-storage/document_cognition_service/src/service/get_chat.rs
index da078dad70..9370a274a5 100644
--- a/rust/cloud-storage/document_cognition_service/src/service/get_chat.rs
+++ b/rust/cloud-storage/document_cognition_service/src/service/get_chat.rs
@@ -4,12 +4,7 @@ use crate::core::model::FALLBACK_MODEL;
use crate::model::chats::ChatResponse;
use ai::model_selection::ModelSelection;
use anyhow::Context;
-use doppleganger::Mirror;
-use macro_db_client::dcs::get_chat::{
- get_chat_db, get_messages, get_web_citations, raw_attachments,
-};
-use macro_db_client::dcs::get_document_name_and_type::get_document_name_and_type;
-use model::chat::{AttachmentMetadata, AttachmentType, ChatAttachmentWithName};
+use macro_db_client::dcs::get_chat::{get_chat_db, get_messages, get_web_citations};
use unfurl_service::GetUnfurlResponse;
#[tracing::instrument(err, skip(ctx))]
@@ -21,80 +16,8 @@ pub async fn get_chat(
let chat = get_chat_db(&ctx.db, chat_id)
.await
.context("Failed to get chat from database")?;
- let db = &ctx.db.clone();
- let raw_attachments = raw_attachments(&ctx.db, chat_id)
- .await
- .context("Failed to get raw attachments")?;
- // Get the document names for all the attachments
- let mut attachments: Vec<ChatAttachmentWithName> = Vec::new();
- for attachment in raw_attachments {
- let metadata = match attachment.attachment_type {
- AttachmentType::Image => {
- get_document_name_and_type(db.clone(), &attachment.attachment_id)
- .await
- .map(|(image_name, image_extension)| AttachmentMetadata::Image {
- image_name,
- image_extension,
- })
- .ok()
- }
- AttachmentType::Project => {
- get_document_name_and_type(db.clone(), &attachment.attachment_id)
- .await
- .map(|(name, _)| AttachmentMetadata::Project { project_name: name })
- .ok()
- }
-
- AttachmentType::Document => {
- get_document_name_and_type(db.clone(), &attachment.attachment_id)
- .await
- .map(
- |(document_name, document_type)| AttachmentMetadata::Document {
- document_type,
- document_name,
- },
- )
- .ok()
- }
- AttachmentType::Channel => ctx
- .scribe
- .channel
- .get_channel_metadata(attachment.attachment_id.as_str())
- .await
- .map(|channel_metadata| AttachmentMetadata::Channel {
- channel_name: channel_metadata.name,
- channel_type: model::comms::ChannelType::mirror(channel_metadata.channel_type),
- })
- .ok(),
- AttachmentType::Email => {
- let thread = ctx
- .scribe
- .email
- .get_email_messages_by_thread_id(&attachment.attachment_id, 0, 1)
- .await;
-
- thread
- .map(|thread| {
- thread
- .first()
- .and_then(|first| first.subject.clone())
- .unwrap_or("No Subject".into())
- })
- .map(|subject| AttachmentMetadata::Email {
- email_subject: subject,
- })
- .ok()
- }
- };
- attachments.push(ChatAttachmentWithName {
- attachment_type: attachment.attachment_type,
- attachment_id: attachment.attachment_id,
- metadata,
- id: attachment.id.clone(),
- });
- }
- let messages = get_messages(&ctx.db, chat_id, attachments.as_slice())
+ let messages = get_messages(&ctx.db, chat_id)
.await
.context("Failed to get messages")?;
@@ -136,7 +59,7 @@ pub async fn get_chat(
project_id: chat.project_id,
created_at: chat.created_at,
updated_at: chat.updated_at,
- attachments,
+ attachments: vec![],
token_count: chat.token_count,
available_models: model_selection.available_models,
web_citations,
diff --git a/rust/cloud-storage/macro_db_client/fixtures/chat_example.sql b/rust/cloud-storage/macro_db_client/fixtures/chat_example.sql
index 99de656aa7..6100542d57 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/chat_example.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/chat_example.sql
@@ -6,11 +6,11 @@ VALUES ('macro|[email protected]', '[email protected]','stripe_id','a1111111-1111-1111-1
-- Test Documents
INSERT INTO public."Document" ("id","name","fileType", "owner")
-VALUES ('document-one', 'test_document_name','pdf', 'macro|[email protected]');
+VALUES ('d0000001-0000-0000-0000-000000000001', 'test_document_name','pdf', 'macro|[email protected]');
INSERT INTO public."Document" ("id","name","fileType", "owner")
-VALUES ('document-two', 'test_document_name','pdf', 'macro|[email protected]');
+VALUES ('d0000002-0000-0000-0000-000000000002', 'test_document_name','pdf', 'macro|[email protected]');
INSERT INTO public."Document" ("id","name","fileType", "owner")
-VALUES ('document-three', 'test_document_name','pdf', 'macro|[email protected]');
+VALUES ('d0000003-0000-0000-0000-000000000003', 'test_document_name','pdf', 'macro|[email protected]');
-- Test Chats
INSERT INTO public."Chat" ("id","name","userId", "model", "createdAt", "updatedAt")
@@ -28,17 +28,17 @@ INSERT INTO public."ChatMessage" ("id", "content", "role", "chatId")
VALUES ('message-two', '"test-chat message 2"', 'user', 'chat-three');
-- Chat attachments on both chat
-INSERT INTO public."ChatAttachment" ("id", "chatId", "attachmentType", "attachmentId")
-VALUES ('chat-attachment-one', 'chat-one', 'document', 'document-two');
-INSERT INTO public."ChatAttachment" ("id", "chatId", "attachmentType", "attachmentId")
-VALUES ('chat-attachment-two', 'chat-one', 'document', 'document-two');
-INSERT INTO public."ChatAttachment" ("id", "chatId", "attachmentType", "attachmentId")
-VALUES ('chat-attachment-six', 'chat-two', 'document', 'document-two');
+INSERT INTO public."ChatAttachment" ("id", "chatId", "entity_type", "entity_id")
+VALUES ('chat-attachment-one', 'chat-one', 'document', 'd0000002-0000-0000-0000-000000000002');
+INSERT INTO public."ChatAttachment" ("id", "chatId", "entity_type", "entity_id")
+VALUES ('chat-attachment-two', 'chat-one', 'document', 'd0000002-0000-0000-0000-000000000002');
+INSERT INTO public."ChatAttachment" ("id", "chatId", "entity_type", "entity_id")
+VALUES ('chat-attachment-six', 'chat-two', 'document', 'd0000002-0000-0000-0000-000000000002');
-- Chat attachments on messages
-INSERT INTO public."ChatAttachment" ("id", "messageId", "attachmentType", "attachmentId")
-VALUES ('chat-attachment-three', 'message-one', 'document', 'document-one');
-INSERT INTO public."ChatAttachment" ("id", "messageId", "attachmentType", "attachmentId")
-VALUES ('chat-attachment-four', 'message-one', 'document', 'document-two');
-INSERT INTO public."ChatAttachment" ("id", "messageId", "attachmentType", "attachmentId")
-VALUES ('chat-attachment-five', 'message-one', 'document', 'document-three');
+INSERT INTO public."ChatAttachment" ("id", "messageId", "entity_type", "entity_id")
+VALUES ('chat-attachment-three', 'message-one', 'document', 'd0000001-0000-0000-0000-000000000001');
+INSERT INTO public."ChatAttachment" ("id", "messageId", "entity_type", "entity_id")
+VALUES ('chat-attachment-four', 'message-one', 'document', 'd0000002-0000-0000-0000-000000000002');
+INSERT INTO public."ChatAttachment" ("id", "messageId", "entity_type", "entity_id")
+VALUES ('chat-attachment-five', 'message-one', 'document', 'd0000003-0000-0000-0000-000000000003');
diff --git a/rust/cloud-storage/macro_db_client/fixtures/chat_with_attachment_summaries.sql b/rust/cloud-storage/macro_db_client/fixtures/chat_with_attachment_summaries.sql
index 1f467f5b26..15e118adb8 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/chat_with_attachment_summaries.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/chat_with_attachment_summaries.sql
@@ -22,31 +22,31 @@ INSERT INTO
)
VALUES
(
- 'document-id-0',
+ 'a0000000-0000-0000-0000-000000000000',
'document-name-0',
'md',
'test-userid'
),
(
- 'document-id-1',
+ 'a0000000-0000-0000-0000-000000000001',
'document-name-1',
'js',
'test-userid'
),
(
- 'document-id-2',
+ 'a0000000-0000-0000-0000-000000000002',
'document-name-2',
'rs',
'test-userid'
),
(
- 'document-id-img',
+ 'a0000000-0000-0000-0000-00000000000a',
'document-name-img',
'png',
'test-userid'
),
(
- 'document-id-never',
+ 'a0000000-0000-0000-0000-00000000000b',
'document-name-never',
'sql',
'test-userid'
@@ -125,49 +125,49 @@ VALUES
-- attachments --
-INSERT INTO
+INSERT INTO
public."ChatAttachment"
(
"id",
- "attachmentType",
- "attachmentId",
+ "entity_type",
+ "entity_id",
"messageId"
)
VALUES
(
'c0a0',
- 'image',
- 'document-id-img',
+ 'static_file',
+ 'a0000000-0000-0000-0000-00000000000a',
'c0m0'
),
(
'c0a1',
'document',
- 'document-id-0',
+ 'a0000000-0000-0000-0000-000000000000',
'c0m0'
),
(
'c0a2',
'document',
- 'document-id-0',
+ 'a0000000-0000-0000-0000-000000000000',
'c0m1'
),
(
'c0a3',
'document',
- 'document-id-1',
+ 'a0000000-0000-0000-0000-000000000001',
'c0m1'
),
(
'c0a4',
'document',
- 'document-id-2',
+ 'a0000000-0000-0000-0000-000000000002',
'c0m1'
),
(
'c1a0',
'document',
- 'document-id-0',
+ 'a0000000-0000-0000-0000-000000000000',
'c0m1'
);
@@ -181,19 +181,19 @@ INSERT INTO
VALUES
(
'd0v0-summary',
- 'document-id-0',
+ 'a0000000-0000-0000-0000-000000000000',
'v0',
'2025-06-10 00:00:00'
),
(
'd0v1-summary',
- 'document-id-0',
+ 'a0000000-0000-0000-0000-000000000000',
'v1',
'2025-06-11 00:00:00'
),
(
'd1v0-summary',
- 'document-id-1',
+ 'a0000000-0000-0000-0000-000000000001',
'v0',
'2025-06-12 00:00:00'
);
\ No newline at end of file
diff --git a/rust/cloud-storage/macro_db_client/migrations/20260430120001_chat_attachment_to_entity.down.sql b/rust/cloud-storage/macro_db_client/migrations/20260430120001_chat_attachment_to_entity.down.sql
new file mode 100644
index 0000000000..0ab5f8a959
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/migrations/20260430120001_chat_attachment_to_entity.down.sql
@@ -0,0 +1,29 @@
+-- Revert entity_type/entity_id back to attachmentType/attachmentId.
+
+BEGIN;
+
+-- Restore NOT NULL on old columns
+ALTER TABLE "ChatAttachment"
+ ALTER COLUMN "old_attachmentType" SET NOT NULL;
+ALTER TABLE "ChatAttachment"
+ ALTER COLUMN "old_attachmentId" SET NOT NULL;
+
+-- Rename old columns back
+ALTER TABLE "ChatAttachment"
+ RENAME COLUMN "old_attachmentType" TO "attachmentType";
+ALTER TABLE "ChatAttachment"
+ RENAME COLUMN "old_attachmentId" TO "attachmentId";
+
+-- Drop new columns
+ALTER TABLE "ChatAttachment"
+ DROP COLUMN "entity_type",
+ DROP COLUMN "entity_id";
+
+-- Drop new index
+DROP INDEX IF EXISTS "ChatAttachment_entity_type_entity_id_idx";
+
+-- Restore old index
+CREATE INDEX "ChatAttachment_attachmentType_attachmentId_idx"
+ ON "ChatAttachment" ("attachmentType", "attachmentId");
+
+COMMIT;
diff --git a/rust/cloud-storage/macro_db_client/migrations/20260430120001_chat_attachment_to_entity.up.sql b/rust/cloud-storage/macro_db_client/migrations/20260430120001_chat_attachment_to_entity.up.sql
new file mode 100644
index 0000000000..900173c57b
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/migrations/20260430120001_chat_attachment_to_entity.up.sql
@@ -0,0 +1,47 @@
+-- Rename ChatAttachment columns from attachmentType/attachmentId to entity_type/entity_id,
+-- convert legacy attachment type values to EntityType values,
+-- and cast entity_id to UUID.
+
+BEGIN;
+
+-- Add new columns
+ALTER TABLE "ChatAttachment"
+ ADD COLUMN "entity_type" TEXT,
+ ADD COLUMN "entity_id" UUID;
+
+-- Migrate data: map old attachmentType values to EntityType values, cast id to UUID
+UPDATE "ChatAttachment"
+SET
+ "entity_type" = CASE "attachmentType"
+ WHEN 'document' THEN 'document'
+ WHEN 'image' THEN 'static_file'
+ WHEN 'channel' THEN 'channel'
+ WHEN 'email' THEN 'email_thread'
+ WHEN 'project' THEN 'project'
+ ELSE 'document'
+ END,
+ "entity_id" = "attachmentId"::UUID;
+
+-- Make new columns non-nullable now that data is populated
+ALTER TABLE "ChatAttachment"
+ ALTER COLUMN "entity_type" SET NOT NULL,
+ ALTER COLUMN "entity_id" SET NOT NULL;
+
+-- Rename old columns instead of dropping, make nullable for new inserts
+ALTER TABLE "ChatAttachment"
+ RENAME COLUMN "attachmentType" TO "old_attachmentType";
+ALTER TABLE "ChatAttachment"
+ RENAME COLUMN "attachmentId" TO "old_attachmentId";
+ALTER TABLE "ChatAttachment"
+ ALTER COLUMN "old_attachmentType" DROP NOT NULL;
+ALTER TABLE "ChatAttachment"
+ ALTER COLUMN "old_attachmentId" DROP NOT NULL;
+
+-- Drop old index (references removed columns)
+DROP INDEX IF EXISTS "ChatAttachment_attachmentType_attachmentId_idx";
+
+-- Create new index on entity columns
+CREATE INDEX "ChatAttachment_entity_type_entity_id_idx"
+ ON "ChatAttachment" ("entity_type", "entity_id");
+
+COMMIT;
diff --git a/rust/cloud-storage/macro_db_client/src/dcs/append_attachment_to_chat.rs b/rust/cloud-storage/macro_db_client/src/dcs/append_attachment_to_chat.rs
index 8d8e923ac1..5719d6a796 100644
--- a/rust/cloud-storage/macro_db_client/src/dcs/append_attachment_to_chat.rs
+++ b/rust/cloud-storage/macro_db_client/src/dcs/append_attachment_to_chat.rs
@@ -1,20 +1,33 @@
-use model::{StringID, chat::NewChatAttachment};
+use model::StringID;
+use model::chat::{AttachmentType, NewChatAttachment};
+use model_entity::EntityType;
use sqlx::{Postgres, Transaction};
+fn attachment_type_to_entity_type(at: &AttachmentType) -> EntityType {
+ match at {
+ AttachmentType::Document => EntityType::Document,
+ AttachmentType::Image => EntityType::StaticFile,
+ AttachmentType::Channel => EntityType::Channel,
+ AttachmentType::Email => EntityType::EmailThread,
+ AttachmentType::Project => EntityType::Project,
+ }
+}
+
#[tracing::instrument(skip(transaction))]
async fn add_attachment(
transaction: &mut Transaction<'_, Postgres>,
new_attachment: NewChatAttachment,
) -> anyhow::Result<String> {
+ let entity_id = uuid::Uuid::parse_str(&new_attachment.attachment_id)?;
let attachment = sqlx::query_as!(
StringID,
r#"
- INSERT INTO "ChatAttachment" ("attachmentType", "attachmentId", "chatId")
+ INSERT INTO "ChatAttachment" ("entity_type", "entity_id", "chatId")
VALUES ($1, $2, $3)
RETURNING id;
"#,
- new_attachment.attachment_type.to_string(),
- new_attachment.attachment_id,
+ attachment_type_to_entity_type(&new_attachment.attachment_type).to_string(),
+ entity_id,
new_attachment.chat_id,
)
.fetch_one(transaction.as_mut())
diff --git a/rust/cloud-storage/macro_db_client/src/dcs/create_chat_message.rs b/rust/cloud-storage/macro_db_client/src/dcs/create_chat_message.rs
index 42334d8bca..bcc86ec33d 100644
--- a/rust/cloud-storage/macro_db_client/src/dcs/create_chat_message.rs
+++ b/rust/cloud-storage/macro_db_client/src/dcs/create_chat_message.rs
@@ -1,8 +1,19 @@
use ai::types::Role;
use anyhow::Context;
-use model::chat::NewChatMessage;
+use model::chat::{AttachmentType, NewChatMessage};
+use model_entity::EntityType;
use sqlx::PgPool;
+fn attachment_type_to_entity_type(at: &AttachmentType) -> EntityType {
+ match at {
+ AttachmentType::Document => EntityType::Document,
+ AttachmentType::Image => EntityType::StaticFile,
+ AttachmentType::Channel => EntityType::Channel,
+ AttachmentType::Email => EntityType::EmailThread,
+ AttachmentType::Project => EntityType::Project,
+ }
+}
+
#[tracing::instrument(skip(db), err)]
pub async fn create_chat_message(
db: PgPool,
@@ -35,25 +46,33 @@ pub async fn create_chat_message(
.context("failed to create chat message")
.map(|record| record.id)?;
- let (kinds, ids, chat_ids, message_ids) = message
+ let (kinds, ids, chat_ids, message_ids): (
+ Vec<String>,
+ Vec<uuid::Uuid>,
+ Vec<String>,
+ Vec<String>,
+ ) = message
.attachments
.clone()
.unwrap_or_default()
.into_iter()
- .map(|attachment| {
- (
- attachment.attachment_type.to_string(),
- attachment.attachment_id.to_string(),
+ .filter_map(|attachment| {
+ let entity_type =
+ attachment_type_to_entity_type(&attachment.attachment_type).to_string();
+ let entity_id = uuid::Uuid::parse_str(&attachment.attachment_id).ok()?;
+ Some((
+ entity_type,
+ entity_id,
chat_id.to_string(),
message_id.to_string(),
- )
+ ))
})
.collect::<(Vec<_>, Vec<_>, Vec<_>, Vec<_>)>();
// insert attachments for message
sqlx::query!(
r#"
- INSERT INTO "ChatAttachment" ("attachmentType", "attachmentId", "chatId", "messageId")
- SELECT * FROM UNNEST($1::TEXT[], $2::TEXT[], $3::TEXT[], $4::TEXT[])
+ INSERT INTO "ChatAttachment" ("entity_type", "entity_id", "chatId", "messageId")
+ SELECT * FROM UNNEST($1::TEXT[], $2::UUID[], $3::TEXT[], $4::TEXT[])
"#,
&kinds,
&ids,
diff --git a/rust/cloud-storage/macro_db_client/src/dcs/get_attachment.rs b/rust/cloud-storage/macro_db_client/src/dcs/get_attachment.rs
index 17666f33e7..3027bbf778 100644
--- a/rust/cloud-storage/macro_db_client/src/dcs/get_attachment.rs
+++ b/rust/cloud-storage/macro_db_client/src/dcs/get_attachment.rs
@@ -12,8 +12,8 @@ pub async fn get_attachment(
r#"
SELECT
ca.id,
- ca."attachmentType" as "attachment_type: AttachmentType",
- ca."attachmentId" as "attachment_id",
+ ca."entity_type" as "attachment_type: AttachmentType",
+ ca."entity_id"::TEXT as "attachment_id!",
ca."chatId" as "chat_id",
ca."messageId" as "message_id"
FROM
diff --git a/rust/cloud-storage/macro_db_client/src/dcs/get_attachments_for_message.rs b/rust/cloud-storage/macro_db_client/src/dcs/get_attachments_for_message.rs
index 86c2b070b5..8282397bde 100644
--- a/rust/cloud-storage/macro_db_client/src/dcs/get_attachments_for_message.rs
+++ b/rust/cloud-storage/macro_db_client/src/dcs/get_attachments_for_message.rs
@@ -13,8 +13,8 @@ pub async fn get_attachments_for_message(
r#"
SELECT
ca.id,
- ca."attachmentType" as "attachment_type: AttachmentType",
- ca."attachmentId" as "attachment_id",
+ ca."entity_type" as "attachment_type: AttachmentType",
+ ca."entity_id"::TEXT as "attachment_id!",
ca."chatId" as "chat_id",
ca."messageId" as "message_id"
FROM
diff --git a/rust/cloud-storage/macro_db_client/src/dcs/get_chat.rs b/rust/cloud-storage/macro_db_client/src/dcs/get_chat.rs
index a32ca2a6d9..62e4aee0d1 100644
--- a/rust/cloud-storage/macro_db_client/src/dcs/get_chat.rs
+++ b/rust/cloud-storage/macro_db_client/src/dcs/get_chat.rs
@@ -2,22 +2,15 @@
use ai::types::ChatMessageContent;
use ai::types::Role;
use anyhow::{Error, Result};
-use model::chat::{
- AttachmentMetadata, AttachmentType, Chat, ChatAttachment, ChatAttachmentWithName,
- ChatMessageWithAttachments,
-};
-use model::document::FileType;
+use model::chat::{AttachmentType, Chat, ChatAttachment, ChatMessageWithAttachments};
+use model_entity::{Entity, EntityType};
use sqlx::{Executor, Pool, Postgres};
use std::collections::HashMap;
-// TODO: @synoet this is a temp solution FIX
-#[derive(serde::Serialize, serde::Deserialize, Debug)]
-#[serde(rename_all = "camelCase")]
+#[derive(serde::Deserialize, Debug)]
struct RawAttachment {
- attachment_id: String,
- attachment_type: String,
- document_name: Option<String>,
- document_type: Option<FileType>,
+ entity_type: String,
+ entity_id: String,
}
#[tracing::instrument(skip(db))]
@@ -74,8 +67,8 @@ where
SELECT
ca.id,
ca."chatId" as "chat_id",
- ca."attachmentId" as "attachment_id",
- ca."attachmentType" as "attachment_type: AttachmentType",
+ ca."entity_id"::TEXT as "attachment_id!",
+ ca."entity_type" as "attachment_type: AttachmentType",
ca."messageId" as "message_id"
FROM
"ChatAttachment" ca
@@ -89,47 +82,12 @@ where
.map_err(Error::from)
}
-pub async fn get_messages<'e, T>(
- db: T,
- chat_id: &str,
- attachments: &[ChatAttachmentWithName],
-) -> Result<Vec<ChatMessageWithAttachments>>
+pub async fn get_messages<'e, T>(db: T, chat_id: &str) -> Result<Vec<ChatMessageWithAttachments>>
where
T: Executor<'e, Database = Postgres>,
{
let message_result = sqlx::query!(
r#"
- WITH attachment_info AS (
- SELECT
- ca.id,
- ca."attachmentType",
- ca."attachmentId",
- ca."messageId",
- CASE
- WHEN ca."attachmentType" = 'document' THEN d.name
- WHEN ca."attachmentType" = 'chat' THEN c.name
- WHEN ca."attachmentType" = 'project' THEN p.name
- WHEN ca."attachmentType" = 'image' THEN d.name
- ELSE NULL
- END AS document_name,
- CASE
- WHEN ca."attachmentType" = 'document' THEN d."fileType"
- WHEN ca."attachmentType" = 'image' THEN d."fileType"
- ELSE NULL
- END as document_type
- FROM
- "ChatAttachment" ca
- LEFT JOIN
- "Document" d ON (
- (ca."attachmentType" = 'document' AND ca."attachmentId" = d.id)
- OR
- (ca."attachmentType" = 'image' AND ca."attachmentId" = d.id)
- )
- LEFT JOIN
- "Chat" c ON ca."attachmentType" = 'chat' AND ca."attachmentId" = c.id
- LEFT JOIN
- "Project" p ON ca."attachmentType" = 'project' AND ca."attachmentId" = p.id
- )
SELECT
cm.id AS "id!",
cm.content,
@@ -139,15 +97,12 @@ where
(
SELECT json_agg(
json_build_object(
- 'id', attachment_info."attachmentId",
- 'attachmentType', attachment_info."attachmentType",
- 'attachmentId', attachment_info."attachmentId",
- 'documentName', attachment_info.document_name,
- 'documentType', attachment_info.document_type
+ 'entity_type', ca."entity_type",
+ 'entity_id', ca."entity_id"::TEXT
)
)
- FROM attachment_info
- WHERE attachment_info."messageId" = cm.id
+ FROM "ChatAttachment" ca
+ WHERE ca."messageId" = cm.id
),
'[]'::json
) AS attachments
@@ -162,84 +117,40 @@ where
)
.fetch_all(db)
.await?;
- // FIXME: @synoet this is messy
+
let messages: Vec<ChatMessageWithAttachments> = message_result
.into_iter()
.map(|record| {
- let attachments = match record.attachments {
- Some(raw_attachments) => {
- let attachments = serde_json::from_value(raw_attachments)
- .unwrap_or_else(|e| {
- tracing::error!(error=?e, "Error parsing attachments");
- Vec::new()
- })
- .into_iter()
- .filter_map(|raw: RawAttachment| match raw.attachment_type.as_str() {
- "document" => Some(ChatAttachmentWithName {
- id: raw.attachment_id.clone(),
- attachment_id: raw.attachment_id,
- attachment_type: AttachmentType::Document,
- metadata: raw.document_name.zip(raw.document_type).map(
- |(name, type_)| AttachmentMetadata::Document {
- document_type: type_,
- document_name: name,
- },
- ),
- }),
- "image" => Some(ChatAttachmentWithName {
- id: raw.attachment_id.clone(),
- attachment_id: raw.attachment_id,
- attachment_type: AttachmentType::Image,
- metadata: raw.document_name.zip(raw.document_type).map(
- |(name, type_)| AttachmentMetadata::Image {
- image_extension: type_,
- image_name: name,
- },
- ),
- }),
- "channel" => {
- // Reuse metadata from earlier attachments vector
- let metadata = attachments
- .iter()
- .find(|a| {
- a.attachment_id == raw.attachment_id
- && a.attachment_type == AttachmentType::Channel
- })
- .and_then(|a| a.metadata.clone());
- Some(ChatAttachmentWithName {
- id: raw.attachment_id.clone(),
- attachment_id: raw.attachment_id,
- attachment_type: AttachmentType::Channel,
- metadata,
- })
- }
- _ => None,
- })
- .collect();
-
- Some(attachments)
- }
- None => None,
- };
+ let attachments: Vec<Entity<'static>> = record
+ .attachments
+ .and_then(|raw_json| {
+ serde_json::from_value::<Vec<RawAttachment>>(raw_json)
+ .inspect_err(|e| tracing::error!(error=?e, "Error parsing attachments"))
+ .ok()
+ })
+ .map(|raws| raws.into_iter().filter_map(parse_raw_attachment).collect())
+ .unwrap_or_default();
- tracing::debug!("get chat\n{:?}", record.content.as_str());
let content =
serde_json::from_value::<ChatMessageContent>(record.content).expect("content");
let role = Role::try_from(record.role.as_str()).unwrap_or(Role::User);
- // serde_json::from_str::<Role>(&record.role).expect("role");
ChatMessageWithAttachments {
id: record.id,
content,
role,
- attachments: attachments.unwrap_or_default(),
- model: record.model,
+ attachments,
}
})
.collect();
Ok(messages)
}
+fn parse_raw_attachment(raw: RawAttachment) -> Option<Entity<'static>> {
+ let entity_type: EntityType = raw.entity_type.parse().ok()?;
+ Some(entity_type.with_entity_string(raw.entity_id))
+}
+
// and still we cope
#[derive(Debug, Clone)]
pub struct Citation {
diff --git a/rust/cloud-storage/macro_db_client/src/dcs/get_chats_for_attachment.rs b/rust/cloud-storage/macro_db_client/src/dcs/get_chats_for_attachment.rs
index 409f4e4a11..681386a80e 100644
--- a/rust/cloud-storage/macro_db_client/src/dcs/get_chats_for_attachment.rs
+++ b/rust/cloud-storage/macro_db_client/src/dcs/get_chats_for_attachment.rs
@@ -33,7 +33,7 @@ pub async fn get_latest_single_attachment_chat(
INNER JOIN "ChatAttachment" ca ON c.id = ca."chatId"
INNER JOIN SingleAttachmentChats sac ON c.id = sac."chatId"
WHERE
- ca."attachmentId" = $1 AND c."userId" = $2
+ ca."entity_id"::TEXT = $1 AND c."userId" = $2
AND
c."deletedAt" IS NULL
@@ -77,7 +77,7 @@ pub async fn get_multi_attachment_chat(
INNER JOIN "ChatAttachment" ca ON c.id = ca."chatId"
INNER JOIN MultiAttachmentChats mac ON c.id = mac."chatId"
WHERE
- ca."attachmentId" = $1 AND c."userId" = $2
+ ca."entity_id"::TEXT = $1 AND c."userId" = $2
AND
c."deletedAt" IS NULL
ORDER BY c."updatedAt" DESC;
@@ -99,7 +99,7 @@ mod tests {
let mut transaction = pool.begin().await?;
let chat = get_latest_single_attachment_chat(
&mut transaction,
- "document-two",
+ "d0000002-0000-0000-0000-000000000002",
)
.await?;
@@ -111,9 +111,12 @@ mod tests {
#[sqlx::test(fixtures(path = "../../fixtures", scripts("chat_example")))]
async fn test_get_multi_attachment_chat(pool: Pool<Postgres>) -> anyhow::Result<()> {
let mut transaction = pool.begin().await?;
- let chat =
- get_multi_attachment_chat(&mut transaction, "document-two", "macro|[email protected]")
- .await?;
+ let chat = get_multi_attachment_chat(
+ &mut transaction,
+ "d0000002-0000-0000-0000-000000000002",
+ )
+ .await?;
assert_eq!(chat.len(), 3);
Ok(())
}
diff --git a/rust/cloud-storage/model/Cargo.toml b/rust/cloud-storage/model/Cargo.toml
index 6afd353a92..db6950fe77 100644
--- a/rust/cloud-storage/model/Cargo.toml
+++ b/rust/cloud-storage/model/Cargo.toml
@@ -32,3 +32,4 @@ thiserror.workspace = true
tracing = { workspace = true }
utoipa = { workspace = true, features = ["axum_extras", "chrono"] }
uuid = { workspace = true }
+model-entity = { path = "../model-entity"}
diff --git a/rust/cloud-storage/model/src/chat/message.rs b/rust/cloud-storage/model/src/chat/message.rs
index c0388410fe..066afbf766 100644
--- a/rust/cloud-storage/model/src/chat/message.rs
+++ b/rust/cloud-storage/model/src/chat/message.rs
@@ -1,7 +1,7 @@
-use super::ChatAttachmentWithName;
use super::NewAttachment;
use ai::types::{ChatMessageContent, Model, Role};
use chrono::{DateTime, Utc};
+use model_entity::Entity;
use serde::{self, Deserialize, Serialize};
use utoipa::ToSchema;
@@ -29,10 +29,7 @@ pub struct ChatMessageWithAttachments {
pub role: Role,
/// The ids of the attachments used to generate the message
// transform to Vec<Entity<'static>>
- pub attachments: Vec<ChatAttachmentWithName>,
- /// The model used to generate the message
- /// kill
- pub model: Option<String>,
+ pub attachments: Vec<Entity<'static>>,
}
#[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone, ToSchema)]
diff --git a/rust/cloud-storage/model/src/chat/mod.rs b/rust/cloud-storage/model/src/chat/mod.rs
index 74f416935b..e261e444ef 100644
--- a/rust/cloud-storage/model/src/chat/mod.rs
+++ b/rust/cloud-storage/model/src/chat/mod.rs
@@ -102,35 +102,6 @@ pub enum AttachmentMetadata {
},
}
-#[derive(sqlx::FromRow, Serialize, Deserialize, Eq, PartialEq, Debug, Clone, ToSchema)]
-#[serde(rename_all = "camelCase")]
-pub struct ChatAttachmentWithName {
- /// Type of the attachment ['document' | 'chat' | 'project' | 'image' | 'channel']
- pub attachment_type: AttachmentType,
- /// Id of the attachment [Foreign Key to either document, chat or project]
- pub attachment_id: String,
- /// Incremented int id of the attachment (not really used for anything)
- pub id: String,
- /// Metadata about the attachment, depending on the type
- pub metadata: Option<AttachmentMetadata>,
-}
-
-impl ChatAttachmentWithName {
- pub fn name(&self) -> Option<&str> {
- self.metadata.as_ref().map(|meta| match meta {
- AttachmentMetadata::Channel { channel_name, .. } => channel_name.as_str(),
- AttachmentMetadata::Document { document_name, .. } => document_name.as_str(),
- AttachmentMetadata::Image { image_name, .. } => image_name.as_str(),
- AttachmentMetadata::Email { email_subject, .. } => email_subject.as_str(),
- AttachmentMetadata::Project { project_name: name } => name.as_str(),
- })
- }
-
- pub fn name_infallible(&self) -> &str {
- self.name().unwrap_or("unknown_attachment_name")
- }
-}
-
#[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct NewChatAttachment {
diff --git a/rust/cloud-storage/scribe/src/dcs/client.rs b/rust/cloud-storage/scribe/src/dcs/client.rs
index d50a2b67d9..d78f64ac17 100644
--- a/rust/cloud-storage/scribe/src/dcs/client.rs
+++ b/rust/cloud-storage/scribe/src/dcs/client.rs
@@ -41,7 +41,7 @@ impl DcsClient {
attachment_ids: m
.attachments
.iter()
- .map(|a| a.attachment_id.clone())
+ .map(|a| a.entity_id.clone().into_owned())
.collect(),
}
})