Documentation
Classes
Msg

Class: Msg

Utility class for creating and checking message types.

Constructors

new Msg()

new Msg(): Msg

Returns

Msg

Methods

assistant()

static assistant(content, opts?): Assistant

Create an assistant message. Cleans indentation and newlines by default.

Parameters

ParameterTypeDescription
contentstring-
opts?object-
opts.cleanContent?booleanWhether to clean extra newlines and indentation. Defaults to true.
opts.name?stringCustom name for the message.

Returns

Assistant

Source

src/prompt/utils/message.ts:56 (opens in a new tab)


funcCall()

static funcCall(function_call, opts?): FuncCall

Create a function call message with argumets.

Parameters

ParameterTypeDescription
function_callobject-
function_call.argumentsstringArguments to pass to the function.
function_call.name?stringName of the function to call.
opts?object-
opts.name?stringThe name descriptor for the message.(message.name)

Returns

FuncCall

Source

src/prompt/utils/message.ts:74 (opens in a new tab)


funcResult()

static funcResult(content, name): FuncResult

Create a function result message.

Parameters

ParameterType
contentJsonifiable
namestring

Returns

FuncResult

Source

src/prompt/utils/message.ts:95 (opens in a new tab)


getMessage()

static getMessage(response): Assistant | FuncCall | ToolCall

Get the narrowed message from an EnrichedResponse.

Parameters

ParameterType
responseany

Returns

Assistant | FuncCall | ToolCall

Source

src/prompt/utils/message.ts:130 (opens in a new tab)


isAssistant()

static isAssistant(message): message is Assistant

Check if a message is an assistant message.

Parameters

ParameterType
messageMsg

Returns

message is Assistant

Source

src/prompt/utils/message.ts:165 (opens in a new tab)


isFuncCall()

static isFuncCall(message): message is FuncCall

Check if a message is a function call message with arguments.

Parameters

ParameterType
messageMsg

Returns

message is FuncCall

Source

src/prompt/utils/message.ts:169 (opens in a new tab)


isFuncResult()

static isFuncResult(message): message is FuncResult

Check if a message is a function result message.

Parameters

ParameterType
messageMsg

Returns

message is FuncResult

Source

src/prompt/utils/message.ts:173 (opens in a new tab)


isSystem()

static isSystem(message): message is System

Check if a message is a system message.

Parameters

ParameterType
messageMsg

Returns

message is System

Source

src/prompt/utils/message.ts:157 (opens in a new tab)


isToolCall()

static isToolCall(message): message is ToolCall

Check if a message is a tool calls message.

Parameters

ParameterType
messageMsg

Returns

message is ToolCall

Source

src/prompt/utils/message.ts:177 (opens in a new tab)


isToolResult()

static isToolResult(message): message is ToolResult

Check if a message is a tool call result message.

Parameters

ParameterType
messageMsg

Returns

message is ToolResult

Source

src/prompt/utils/message.ts:181 (opens in a new tab)


isUser()

static isUser(message): message is User

Check if a message is a user message.

Parameters

ParameterType
messageMsg

Returns

message is User

Source

src/prompt/utils/message.ts:161 (opens in a new tab)


narrow()

narrow(message)

static narrow(message): System

Narrow a ChatModel.Message to a specific type.

Parameters
ParameterType
messageSystem
Returns

System

Source

src/prompt/utils/message.ts:186 (opens in a new tab)

narrow(message)

static narrow(message): User

Parameters
ParameterType
messageUser
Returns

User

Source

src/prompt/utils/message.ts:187 (opens in a new tab)

narrow(message)

static narrow(message): Assistant

Parameters
ParameterType
messageAssistant
Returns

Assistant

Source

src/prompt/utils/message.ts:188 (opens in a new tab)

narrow(message)

static narrow(message): FuncCall

Parameters
ParameterType
messageFuncCall
Returns

FuncCall

Source

src/prompt/utils/message.ts:189 (opens in a new tab)

narrow(message)

static narrow(message): FuncResult

Parameters
ParameterType
messageFuncResult
Returns

FuncResult

Source

src/prompt/utils/message.ts:190 (opens in a new tab)

narrow(message)

static narrow(message): ToolCall

Parameters
ParameterType
messageToolCall
Returns

ToolCall

Source

src/prompt/utils/message.ts:191 (opens in a new tab)

narrow(message)

static narrow(message): ToolResult

Parameters
ParameterType
messageToolResult
Returns

ToolResult

Source

src/prompt/utils/message.ts:192 (opens in a new tab)


narrowResponseMessage()

static narrowResponseMessage(msg): Assistant | FuncCall | ToolCall

Narrow a message received from the API. It only responds with role=assistant

Parameters

ParameterType
msgMsg

Returns

Assistant | FuncCall | ToolCall

Source

src/prompt/utils/message.ts:140 (opens in a new tab)


system()

static system(content, opts?): System

Create a system message. Cleans indentation and newlines by default.

Parameters

ParameterTypeDescription
contentstring-
opts?object-
opts.cleanContent?booleanWhether to clean extra newlines and indentation. Defaults to true.
opts.name?stringCustom name for the message.

Returns

System

Source

src/prompt/utils/message.ts:20 (opens in a new tab)


toolCall()

static toolCall(tool_calls, opts?): ToolCall

Create a function call message with argumets.

Parameters

ParameterTypeDescription
tool_callsTool[]-
opts?object-
opts.name?stringThe name descriptor for the message.(message.name)

Returns

ToolCall

Source

src/prompt/utils/message.ts:101 (opens in a new tab)


toolResult()

static toolResult(content, tool_call_id, opts?): ToolResult

Create a tool call result message.

Parameters

ParameterTypeDescription
contentJsonifiable-
tool_call_idstring-
opts?object-
opts.name?stringThe name of the tool which was called

Returns

ToolResult

Source

src/prompt/utils/message.ts:117 (opens in a new tab)


user()

static user(content, opts?): User

Create a user message. Cleans indentation and newlines by default.

Parameters

ParameterTypeDescription
contentstring-
opts?object-
opts.cleanContent?booleanWhether to clean extra newlines and indentation. Defaults to true.
opts.name?stringCustom name for the message.

Returns

User

Source

src/prompt/utils/message.ts:38 (opens in a new tab)