diff --git a/packages/core/src/services/ai/providers/rules/anthropic.ts b/packages/core/src/services/ai/providers/rules/anthropic.ts index e8288ee40..a5df4df40 100644 --- a/packages/core/src/services/ai/providers/rules/anthropic.ts +++ b/packages/core/src/services/ai/providers/rules/anthropic.ts @@ -1,5 +1,3 @@ -import { MessageRole } from '@latitude-data/compiler' - import { AppliedRules, ProviderRules } from '.' import { enforceAllSystemMessagesFirst } from './helpers/enforceAllSystemMessagesFirst' @@ -11,7 +9,7 @@ export function applyAnthropicRules(appliedRule: AppliedRules): AppliedRules { }) const roles = rule.messages.map((m) => m.role) - const onlySystemMessages = roles.every((r) => r === MessageRole.system) + const onlySystemMessages = roles.every((r) => r === 'system') if (!onlySystemMessages) return rule const rules = [ diff --git a/packages/core/src/services/ai/providers/rules/google.test.ts b/packages/core/src/services/ai/providers/rules/google.test.ts index 043827cd6..f960b89bb 100644 --- a/packages/core/src/services/ai/providers/rules/google.test.ts +++ b/packages/core/src/services/ai/providers/rules/google.test.ts @@ -1,4 +1,4 @@ -import { Message, MessageRole } from '@latitude-data/compiler' +import type { Message } from '@latitude-data/compiler' import { beforeAll, describe, expect, it } from 'vitest' import { applyCustomRules, ProviderRules } from '.' @@ -59,22 +59,22 @@ describe('applyGoogleRules', () => { expect(appliedMessages[1]).toEqual(messages[1]) expect(appliedMessages[2]).toEqual(messages[2]) expect(appliedMessages[4]).toEqual({ - role: MessageRole.assistant, + role: 'assistant', content: [{ type: 'text', text: messages[4]!.content }], }) expect(appliedMessages[3]).toEqual({ - role: MessageRole.user, + role: 'user', content: [{ type: 'text', text: messages[3]!.content }], }) expect(appliedMessages[3]).toEqual({ - role: MessageRole.user, + role: 'user', content: [{ type: 'text', text: messages[3]!.content }], }) expect(appliedMessages[5]).toEqual({ - role: MessageRole.user, + role: 'user', content: [ { type: 'text', text: 'Use a short response' }, { type: 'text', text: 'Second a short response' }, diff --git a/packages/core/src/services/ai/providers/rules/helpers/enforceAllSystemMessagesFirst.ts b/packages/core/src/services/ai/providers/rules/helpers/enforceAllSystemMessagesFirst.ts index 7db21d10d..ec8c94e0e 100644 --- a/packages/core/src/services/ai/providers/rules/helpers/enforceAllSystemMessagesFirst.ts +++ b/packages/core/src/services/ai/providers/rules/helpers/enforceAllSystemMessagesFirst.ts @@ -1,8 +1,8 @@ -import { ContentType, MessageRole } from '@latitude-data/compiler' +import type { ContentType, Message, MessageRole } from '@latitude-data/compiler' import { AppliedRules, ProviderRules } from '../index' -const system = MessageRole.system +const SYSTEM_ROLE = 'system' export function enforceAllSystemMessagesFirst( appliedRule: AppliedRules, @@ -13,7 +13,7 @@ export function enforceAllSystemMessagesFirst( ): AppliedRules { const messages = appliedRule.messages const firstNonSystemMessageIndex = messages.findIndex( - (m) => m.role !== system, + (m) => m.role !== SYSTEM_ROLE, ) if (firstNonSystemMessageIndex === -1) { @@ -23,7 +23,7 @@ export function enforceAllSystemMessagesFirst( const messagesAfterFirstNonSystemMessage = messages.slice( firstNonSystemMessageIndex, ) - if (!messagesAfterFirstNonSystemMessage.some((m) => m.role === system)) { + if (!messagesAfterFirstNonSystemMessage.some((m) => m.role === SYSTEM_ROLE)) { return appliedRule } @@ -39,15 +39,15 @@ export function enforceAllSystemMessagesFirst( rules, messages: messages.map((m, i) => { if (i < firstNonSystemMessageIndex) return m - if (m.role !== system) return m + if (m.role !== SYSTEM_ROLE) return m return { ...m, - role: MessageRole.user, + role: 'user' as MessageRole, content: Array.isArray(m.content) ? m.content - : [{ type: ContentType.text, text: m.content }], - } + : [{ type: 'text' as ContentType, text: m.content }], + } as Message }), } } diff --git a/packages/core/src/services/ai/providers/rules/providerMetadata/index.ts b/packages/core/src/services/ai/providers/rules/providerMetadata/index.ts index 20b2e8901..d9a6bd006 100644 --- a/packages/core/src/services/ai/providers/rules/providerMetadata/index.ts +++ b/packages/core/src/services/ai/providers/rules/providerMetadata/index.ts @@ -1,4 +1,4 @@ -import { Message, MessageRole } from '@latitude-data/compiler' +import type { Message } from '@latitude-data/compiler' import { Providers } from '../../models' @@ -121,7 +121,7 @@ export function extractMessageMetadata({ if (Object.keys(rest).length === 0) return common - if (role === MessageRole.user && Object.hasOwnProperty.call(rest, 'name')) { + if (role === 'user' && Object.hasOwnProperty.call(rest, 'name')) { // @ts-ignore const name = rest.name common = { diff --git a/packages/core/src/services/ai/providers/rules/vercel.test.ts b/packages/core/src/services/ai/providers/rules/vercel.test.ts index 6ba0cbd0b..4e141ac9f 100644 --- a/packages/core/src/services/ai/providers/rules/vercel.test.ts +++ b/packages/core/src/services/ai/providers/rules/vercel.test.ts @@ -1,4 +1,4 @@ -import { Message } from '@latitude-data/compiler' +import type { Message } from '@latitude-data/compiler' import { describe, expect, it } from 'vitest' import { PartialConfig } from '../../helpers' diff --git a/packages/core/src/services/ai/providers/rules/vercel.ts b/packages/core/src/services/ai/providers/rules/vercel.ts index a769fbf6f..c9423aab4 100644 --- a/packages/core/src/services/ai/providers/rules/vercel.ts +++ b/packages/core/src/services/ai/providers/rules/vercel.ts @@ -1,7 +1,6 @@ -import { +import type { ContentType, Message, - MessageRole, SystemMessage, TextContent, } from '@latitude-data/compiler' @@ -72,7 +71,7 @@ function groupContentMetadata({ const key = getProviderMetadataKey(provider) if (typeof content === 'string') { - const baseMsg = { type: ContentType.text, text: content } + const baseMsg = { type: 'text' as ContentType, text: content } if (!messageMetadata) return [baseMsg] return [ @@ -108,7 +107,7 @@ export function vercelSdkRules( provider: Providers, ): AppliedRules { const messages = rules.messages.flatMap((message) => { - if (message.role === MessageRole.system) { + if (message.role === 'system') { return flattenSystemMessage({ message, provider }) }