Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added new trace types for Response step (PL3-54) #446

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/base-types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export * as Button from './button';
export * as BaseButton from './button';
export * as Markup from './markup';
export * as BaseMarkup from './markup';
export * as Models from './models';
export * as BaseModels from './models';
export * as Node from './node';
Expand Down
3 changes: 3 additions & 0 deletions packages/base-types/src/markup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type MarkupNode = string | { attributes: Record<string, unknown>; text: Markup };

export type Markup = Array<MarkupNode>;
4 changes: 4 additions & 0 deletions packages/base-types/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export * as Utils from './utils';
export * as Visual from './visual';
export * as Zapier from './zapier';

// Voiceflow V3
export * as Image from '../trace/v3/image';
export * as Video from '../trace/v3/video';

export interface NextOnlyNode extends BaseNode, NodeNextID {
type: '_next';
}
Expand Down
10 changes: 10 additions & 0 deletions packages/base-types/src/node/utils/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ export enum TraceType {
NO_REPLY = 'no-reply',
ENTITY_FILLING = 'entity-filling',
CHANNEL_ACTION = 'channel-action',

// Voiceflow V3
V3_TEXT = 'v3.text',
V3_IMAGE = 'v3.image',
V3_JSON = 'v3.json',
V3_VIDEO = 'v3.video',
V3_DEBUG = 'v3.debug',
}

export interface BaseTraceFramePath<Event extends BaseEvent = BaseEvent> {
Expand All @@ -30,6 +37,9 @@ export interface BaseTraceFrame<Payload = any, TracePath extends BaseTraceFrameP
paths?: TracePath[];
payload: Payload;
defaultPath?: number;
style?: {
delay?: number;
};
Comment on lines +40 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea to move this out of the text trace's payload?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct. The new JSON variant seems to also have a sort of delay property, based on the Figma mocks.

}

export interface BaseResponseTrace {
Expand Down
13 changes: 12 additions & 1 deletion packages/base-types/src/trace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { IntentRequest } from '@base-types/request';
import { Log as RuntimeLog } from '@base-types/runtimeLogs';
import { AnyRecord } from '@voiceflow/common';

import * as V3 from './v3';

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';
Expand All @@ -23,6 +25,9 @@ export { TraceFrame as Text } from '@base-types/node/text';
export { BaseTraceFrame, TraceType } from '@base-types/node/utils/trace';
export { TraceFrame as Visual } from '@base-types/node/visual';

// Voiceflow V3
export * as V3 from './v3';

/** @deprecated */
export { TraceFrame as CarouselTrace } from '@base-types/node/carousel';
/** @deprecated */
Expand Down Expand Up @@ -120,4 +125,10 @@ export type AnyTrace =
| CarouselTrace
| CardV2Trace
| EntityFillingTrace
| ChannelActionTrace;
| ChannelActionTrace
// V3 traces
| V3.ImageTrace
| V3.JSONTrace
| V3.VideoTrace
| V3.TextTrace
| V3.DebugTrace;
76 changes: 76 additions & 0 deletions packages/base-types/src/trace/v3/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { BaseTraceFrame, TraceType } from '../../node/utils';

/**
* The logging level of the debug trace. This property can be used to
* filter for particular debug messages
*
* Definition of error levels is based on this article: https://sematext.com/blog/logging-levels/
*/
export enum DebugInfoLevel {
/**
* Used for finely detailed information to gain full visibility into the
* `general-runtime` and debug a Voiceflow porgram.
*
* Messages of this nature can be extremely verbose, e.g, may annotate each
* step of an algorithm.
*/
Trace = 'trace',

/**
* Less granular, but still detailed information compared to `Trace`.
* Used for troubleshooting and diagnosing issues or running an application
* in a dev environment.
*/
Debug = 'debug',

/**
* Standard log level indicating an event occurred in the `general-runtime`.
*
* Should not contain important debugging information, as this setting should not
* be enabled on a regular basis.
*/
Info = 'info',

/**
* Indicates an unexpected event that does NOT impede code execution. This
* may not necessarily be an error.
*/
Warn = 'warn',

/**
* Indicates an error that impedes code execution and causes non-business-logic
* to break, e.g, payment API call did not go through.
*/
Error = 'error',

/**
* Indicates a critical error that impedes critical business functionality, e.g,
* could not start the Voiceflow program because it was not compiled.
*/
Fatal = 'fatal',
}

/**
* Indicates the concern or component that spawned this particular debug message.
*/
export enum DebugCode {
/**
* Debug information that is not pinned down to any particular component.
*/
General = 'general',

/**
* Debug information arises from the knowledge base.
*/
KnowledgeBase = 'knowledge_base',
}

interface StepData {
code: DebugCode;
level: DebugInfoLevel;
details: Record<string, any>;
}

export interface TraceFrame extends BaseTraceFrame<StepData> {
type: TraceType.V3_DEBUG;
}
9 changes: 9 additions & 0 deletions packages/base-types/src/trace/v3/image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { BaseTraceFrame, TraceType } from '../../node/utils';

interface StepData {
url: string;
}

export interface TraceFrame extends BaseTraceFrame<StepData> {
type: TraceType.V3_IMAGE;
}
10 changes: 10 additions & 0 deletions packages/base-types/src/trace/v3/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export { TraceFrame as DebugTrace } from './debug';
export * as Debug from './debug';
export { TraceFrame as ImageTrace } from './image';
export * as Image from './image';
export { TraceFrame as JSONTrace } from './json';
export * as JSON from './json';
export { TraceFrame as TextTrace } from './text';
export * as Text from './text';
export { TraceFrame as VideoTrace } from './video';
export * as Video from './video';
9 changes: 9 additions & 0 deletions packages/base-types/src/trace/v3/json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { BaseTraceFrame, TraceType } from '../../node/utils';

interface StepData {
json: unknown;
}

export interface TraceFrame extends BaseTraceFrame<StepData> {
type: TraceType.V3_JSON;
}
11 changes: 11 additions & 0 deletions packages/base-types/src/trace/v3/text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Markup } from '@base-types/markup';

import { BaseTraceFrame, TraceType } from '../../node/utils';

interface StepData {
content: Markup;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data payload is subject to change due to a proposal by Tyler H to simply return Markdown rather than Markup. See slack thread here.

}

export interface TraceFrame extends BaseTraceFrame<StepData> {
type: TraceType.V3_TEXT;
}
9 changes: 9 additions & 0 deletions packages/base-types/src/trace/v3/video.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { BaseTraceFrame, TraceType } from '../../node/utils';

interface StepData {
url: string;
}

export interface TraceFrame extends BaseTraceFrame<StepData> {
type: TraceType.V3_VIDEO;
}