diff --git a/package.json b/package.json index 852a2b3c4..ab91a75a7 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,8 @@ { "private": true, - "workspaces": { - "packages": [ - "packages/*", - "meta/*" - ] - }, + "workspaces": [ + "packages/*" + ], "scripts": { "build": "turbo run build:cmd", "build:all": "yarn build", diff --git a/packages/base-types/src/node/utils/trace.ts b/packages/base-types/src/node/utils/trace.ts index f34ce592f..dd8971107 100644 --- a/packages/base-types/src/node/utils/trace.ts +++ b/packages/base-types/src/node/utils/trace.ts @@ -19,6 +19,9 @@ export enum TraceType { ENTITY_FILLING = 'entity-filling', CHANNEL_ACTION = 'channel-action', KNOWLEDGE_BASE = 'knowledgeBase', + COMPLETION_START = 'completion-start', + COMPLETION_CONTINUE = 'completion-continue', + COMPLETION_END = 'completion-end', } export interface BaseTraceFramePath { diff --git a/packages/base-types/src/trace/completion/completion-continue-trace.ts b/packages/base-types/src/trace/completion/completion-continue-trace.ts new file mode 100644 index 000000000..1556f221a --- /dev/null +++ b/packages/base-types/src/trace/completion/completion-continue-trace.ts @@ -0,0 +1,18 @@ +import type { BaseTraceFrame } from '@base-types/node/utils'; +import { TraceType } from '@base-types/node/utils'; + +export interface CompletionContinueTrace extends BaseTraceFrame { + type: TraceType.COMPLETION_CONTINUE; +} + +export interface CompletionContinueTracePayload { + completion: string; + tokens?: { + answer: number; + query: number; + total: number; + }; +} + +export const isCompletionContinueTrace = (trace: BaseTraceFrame): trace is CompletionContinueTrace => + trace.type === TraceType.COMPLETION_CONTINUE; diff --git a/packages/base-types/src/trace/completion/completion-end-trace.ts b/packages/base-types/src/trace/completion/completion-end-trace.ts new file mode 100644 index 000000000..6c8fa2bf3 --- /dev/null +++ b/packages/base-types/src/trace/completion/completion-end-trace.ts @@ -0,0 +1,9 @@ +import type { BaseTraceFrame } from '@base-types/node/utils'; +import { TraceType } from '@base-types/node/utils'; + +export interface CompletionEndTrace extends BaseTraceFrame { + type: TraceType.COMPLETION_END; +} + +export const isCompletionEndTrace = (trace: BaseTraceFrame): trace is CompletionEndTrace => + trace.type === TraceType.COMPLETION_END; diff --git a/packages/base-types/src/trace/completion/completion-start-trace.ts b/packages/base-types/src/trace/completion/completion-start-trace.ts new file mode 100644 index 000000000..67e58fb3c --- /dev/null +++ b/packages/base-types/src/trace/completion/completion-start-trace.ts @@ -0,0 +1,46 @@ +import type { BaseTraceFrame } from '@base-types/node/utils'; +import { TraceType } from '@base-types/node/utils'; + +export interface CompletionStartTrace extends BaseTraceFrame { + type: TraceType.COMPLETION_START; +} + +export interface CompletionStartTraceSpeak extends CompletionStartTrace { + payload: CompletionStartTraceSpeakPayload; +} + +export interface CompletionStartTraceText extends CompletionStartTrace { + payload: CompletionStartTraceTextPayload; +} + +export type CompletionStartTracePayload = CompletionStartTraceSpeakPayload | CompletionStartTraceTextPayload; + +export interface CompletionStartTraceSpeakPayload extends BaseCompletionStartTracePayload { + type: TraceType.SPEAK; + voice?: string; +} + +export interface CompletionStartTraceTextPayload extends BaseCompletionStartTracePayload { + type: TraceType.TEXT; + delay?: number; +} + +export interface BaseCompletionStartTracePayload { + type: TraceType.TEXT | TraceType.SPEAK; + completion: string; + tokens?: { + model: string; + answer: number; + query: number; + total: number; + }; +} + +export const isCompletionStartTrace = (trace: BaseTraceFrame): trace is CompletionStartTrace => + trace.type === TraceType.COMPLETION_START; + +export const isCompletionStartTraceSpeak = (trace: CompletionStartTrace): trace is CompletionStartTraceSpeak => + trace.payload.type === TraceType.SPEAK; + +export const isCompletionStartTraceText = (trace: CompletionStartTrace): trace is CompletionStartTraceText => + trace.payload.type === TraceType.TEXT; diff --git a/packages/base-types/src/trace/completion/index.ts b/packages/base-types/src/trace/completion/index.ts new file mode 100644 index 000000000..a4e34af9b --- /dev/null +++ b/packages/base-types/src/trace/completion/index.ts @@ -0,0 +1,3 @@ +export * from './completion-continue-trace'; +export * from './completion-end-trace'; +export * from './completion-start-trace'; diff --git a/packages/base-types/src/trace/index.ts b/packages/base-types/src/trace/index.ts index 12cfc8df2..b68d87f5a 100644 --- a/packages/base-types/src/trace/index.ts +++ b/packages/base-types/src/trace/index.ts @@ -12,6 +12,15 @@ import type { IntentRequest } from '@base-types/request'; import type { Log as RuntimeLog } from '@base-types/runtimeLogs'; import type { AnyRecord } from '@voiceflow/common'; +import type { CompletionContinueTrace, CompletionEndTrace, CompletionStartTrace } from './completion'; + +export { + CompletionContinueTrace, + CompletionEndTrace, + CompletionStartTrace, + CompletionStartTraceSpeak, + CompletionStartTraceText, +} from './completion'; export { TraceFrame as CardV2 } from '@base-types/node/cardV2'; export { TraceFrame as Carousel } from '@base-types/node/carousel'; export { TraceFrame as End } from '@base-types/node/exit'; @@ -121,4 +130,7 @@ export type AnyTrace = | CarouselTrace | CardV2Trace | EntityFillingTrace - | ChannelActionTrace; + | ChannelActionTrace + | CompletionStartTrace + | CompletionContinueTrace + | CompletionEndTrace;