Skip to content

base

Estimated time to read: 18 minutes

POML TypeScript API


Classes

BufferCollection

Defined in: packages/poml/base.tsx:413

Accessors

instance
Get Signature

get static instance(): BufferCollection

Defined in: packages/poml/base.tsx:422

Returns

BufferCollection

Methods

clear()

static clear(): void

Defined in: packages/poml/base.tsx:460

Returns

void

get()

static get\<T>(key): undefined | T

Defined in: packages/poml/base.tsx:440

Type Parameters
T

T

Parameters
key

string

Returns

undefined | T

set()

static set(key, value): void

Defined in: packages/poml/base.tsx:445

Parameters
key

string

value

any

Returns

void


ErrorCollection

Defined in: packages/poml/base.tsx:328

A can to hold all the errors.

Accessors

instance
Get Signature

get static instance(): ErrorCollection

Defined in: packages/poml/base.tsx:335

Returns

ErrorCollection

Methods

add()

static add(error): void

Defined in: packages/poml/base.tsx:342

Parameters
error

PomlError

Returns

void

clear()

static clear(): void

Defined in: packages/poml/base.tsx:362

Returns

void

empty()

static empty(): boolean

Defined in: packages/poml/base.tsx:358

Returns

boolean

first()

static first(): PomlError

Defined in: packages/poml/base.tsx:346

Returns

PomlError

last()

static last(): PomlError

Defined in: packages/poml/base.tsx:350

Returns

PomlError

list()

static list(): PomlError[]

Defined in: packages/poml/base.tsx:354

Returns

PomlError[]


PomlComponent

Defined in: packages/poml/base.tsx:639

Constructors

Constructor

new PomlComponent(officialName, componentFunc, options): PomlComponent

Defined in: packages/poml/base.tsx:644

Parameters
officialName

string

componentFunc

any

options

ComponentOptions

Returns

PomlComponent

Accessors

name
Get Signature

get name(): string

Defined in: packages/poml/base.tsx:650

Returns

string

Methods

getAliases()

getAliases(lower): string[]

Defined in: packages/poml/base.tsx:654

Parameters
lower

boolean = true

Returns

string[]

isPublic()

isPublic(): boolean

Defined in: packages/poml/base.tsx:690

Returns

boolean

mro()

mro(): PomlComponent[]

Defined in: packages/poml/base.tsx:724

Returns

PomlComponent[]

parameters()

parameters(): Parameter[]

Defined in: packages/poml/base.tsx:706

Returns

Parameter[]

render()

render(props): any

Defined in: packages/poml/base.tsx:842

Parameters
props

any

Returns

any

spec()

spec(): undefined | ComponentSpec

Defined in: packages/poml/base.tsx:702

Returns

undefined | ComponentSpec

style()

style(props, stylesheet?): any

Defined in: packages/poml/base.tsx:751

Parameters
props

any

stylesheet?

StyleSheet

Returns

any

fromSpec()

static fromSpec(spec): PomlComponent

Defined in: packages/poml/base.tsx:694

Parameters
spec

ComponentSpec

Returns

PomlComponent


ReadError

Defined in: packages/poml/base.tsx:285

Extends

  • PomlError

Constructors

Constructor

new ReadError(message, startIndex?, endIndex?, sourcePath?, options?): ReadError

Defined in: packages/poml/base.tsx:286

Parameters
message

string

startIndex?

number

endIndex?

number

sourcePath?

string

options?

PomlErrorOptions

Returns

ReadError

Overrides

PomlError.constructor

Properties

cause?

optional cause: unknown

Defined in: node_modules/typescript/lib/lib.es2022.error.d.ts:26

Inherited from

PomlError.cause

endIndex?

optional endIndex: number

Defined in: packages/poml/base.tsx:289

message

message: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1077

Inherited from

PomlError.message

name

name: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1076

Inherited from

PomlError.name

severity

severity: "error" | "warning" = 'error'

Defined in: packages/poml/base.tsx:267

Inherited from

PomlError.severity

sourcePath?

optional sourcePath: string

Defined in: packages/poml/base.tsx:290

stack?

optional stack: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1078

Inherited from

PomlError.stack

startIndex?

optional startIndex: number

Defined in: packages/poml/base.tsx:288

stackTraceLimit

static stackTraceLimit: number

Defined in: node_modules/@types/node/globals.d.ts:149

The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

Inherited from

PomlError.stackTraceLimit

Methods

captureStackTrace()

static captureStackTrace(targetObject, constructorOpt?): void

Defined in: node_modules/@types/node/globals.d.ts:133

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

function a() {
  b();
}

function b() {
  c();
}

function c() {
  // Create an error without stack trace to avoid calculating the stack trace twice.
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // Capture the stack trace above function b
  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  throw error;
}

a();
Parameters
targetObject

object

constructorOpt?

Function

Returns

void

Inherited from

PomlError.captureStackTrace

fromProps()

static fromProps(message, props, options?): ReadError

Defined in: packages/poml/base.tsx:297

Parameters
message

string

props

PropsBase

options?

PomlErrorOptions

Returns

ReadError

prepareStackTrace()

static prepareStackTrace(err, stackTraces): any

Defined in: node_modules/@types/node/globals.d.ts:137

Parameters
err

Error

stackTraces

CallSite[]

Returns

any

See

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from

PomlError.prepareStackTrace


SystemError

Defined in: packages/poml/base.tsx:278

Extends

  • PomlError

Constructors

Constructor

new SystemError(message, options?): SystemError

Defined in: packages/poml/base.tsx:279

Parameters
message

string

options?

ErrorOptions

Returns

SystemError

Overrides

PomlError.constructor

Properties

cause?

optional cause: unknown

Defined in: node_modules/typescript/lib/lib.es2022.error.d.ts:26

Inherited from

PomlError.cause

message

message: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1077

Inherited from

PomlError.message

name

name: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1076

Inherited from

PomlError.name

severity

severity: "error" | "warning" = 'error'

Defined in: packages/poml/base.tsx:267

Inherited from

ReadError.severity

stack?

optional stack: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1078

Inherited from

PomlError.stack

stackTraceLimit

static stackTraceLimit: number

Defined in: node_modules/@types/node/globals.d.ts:149

The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

Inherited from

PomlError.stackTraceLimit

Methods

captureStackTrace()

static captureStackTrace(targetObject, constructorOpt?): void

Defined in: node_modules/@types/node/globals.d.ts:133

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

function a() {
  b();
}

function b() {
  c();
}

function c() {
  // Create an error without stack trace to avoid calculating the stack trace twice.
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // Capture the stack trace above function b
  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  throw error;
}

a();
Parameters
targetObject

object

constructorOpt?

Function

Returns

void

Inherited from

PomlError.captureStackTrace

prepareStackTrace()

static prepareStackTrace(err, stackTraces): any

Defined in: node_modules/@types/node/globals.d.ts:137

Parameters
err

Error

stackTraces

CallSite[]

Returns

any

See

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from

PomlError.prepareStackTrace


WriteError

Defined in: packages/poml/base.tsx:308

Extends

  • PomlError

Constructors

Constructor

new WriteError(message, startIndex?, endIndex?, sourcePath?, irStartIndex?, irEndIndex?, relatedIr?, options?): WriteError

Defined in: packages/poml/base.tsx:309

Parameters
message

string

startIndex?

number

endIndex?

number

sourcePath?

string

irStartIndex?

number

irEndIndex?

number

relatedIr?

string

options?

PomlErrorOptions

Returns

WriteError

Overrides

PomlError.constructor

Properties

cause?

optional cause: unknown

Defined in: node_modules/typescript/lib/lib.es2022.error.d.ts:26

Inherited from

PomlError.cause

endIndex?

optional endIndex: number

Defined in: packages/poml/base.tsx:312

irEndIndex?

optional irEndIndex: number

Defined in: packages/poml/base.tsx:315

irStartIndex?

optional irStartIndex: number

Defined in: packages/poml/base.tsx:314

message

message: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1077

Inherited from

PomlError.message

name

name: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1076

Inherited from

PomlError.name

relatedIr?

optional relatedIr: string

Defined in: packages/poml/base.tsx:316

severity

severity: "error" | "warning" = 'error'

Defined in: packages/poml/base.tsx:267

Inherited from

PomlError.severity

sourcePath?

optional sourcePath: string

Defined in: packages/poml/base.tsx:313

stack?

optional stack: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1078

Inherited from

PomlError.stack

startIndex?

optional startIndex: number

Defined in: packages/poml/base.tsx:311

stackTraceLimit

static stackTraceLimit: number

Defined in: node_modules/@types/node/globals.d.ts:149

The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

Inherited from

PomlError.stackTraceLimit

Methods

captureStackTrace()

static captureStackTrace(targetObject, constructorOpt?): void

Defined in: node_modules/@types/node/globals.d.ts:133

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

function a() {
  b();
}

function b() {
  c();
}

function c() {
  // Create an error without stack trace to avoid calculating the stack trace twice.
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // Capture the stack trace above function b
  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  throw error;
}

a();
Parameters
targetObject

object

constructorOpt?

Function

Returns

void

Inherited from

PomlError.captureStackTrace

prepareStackTrace()

static prepareStackTrace(err, stackTraces): any

Defined in: node_modules/@types/node/globals.d.ts:137

Parameters
err

Error

stackTraces

CallSite[]

Returns

any

See

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from

PomlError.prepareStackTrace

Interfaces

ComponentSpec

Defined in: packages/poml/base.tsx:615

Properties

baseComponents

baseComponents: string[]

Defined in: packages/poml/base.tsx:619

description

description: string

Defined in: packages/poml/base.tsx:617

example

example: string

Defined in: packages/poml/base.tsx:620

name?

optional name: string

Defined in: packages/poml/base.tsx:616

params

params: Parameter[]

Defined in: packages/poml/base.tsx:618


ContentMultiMediaBinary

Defined in: packages/poml/base.tsx:21

This is to show in the final rendered prompt.

Properties

alt?

optional alt: string

Defined in: packages/poml/base.tsx:24

base64

base64: string

Defined in: packages/poml/base.tsx:23

type

type: string

Defined in: packages/poml/base.tsx:22


ContentMultiMediaJson

Defined in: packages/poml/base.tsx:30

A JSON-serializable payload, but not a string.

Properties

content

content: any

Defined in: packages/poml/base.tsx:32

type

type: "application/json"

Defined in: packages/poml/base.tsx:31


ContentMultiMediaToolRequest

Defined in: packages/poml/base.tsx:38

Tool request generated by the model.

Properties

content

content: any

Defined in: packages/poml/base.tsx:40

id

id: string

Defined in: packages/poml/base.tsx:41

name

name: string

Defined in: packages/poml/base.tsx:42

type

type: "application/vnd.poml.toolrequest"

Defined in: packages/poml/base.tsx:39


ContentMultiMediaToolResponse

Defined in: packages/poml/base.tsx:48

Tool call result sent to the model.

Properties

content

content: RichContent

Defined in: packages/poml/base.tsx:50

id

id: string

Defined in: packages/poml/base.tsx:51

name

name: string

Defined in: packages/poml/base.tsx:52

type

type: "application/vnd.poml.toolresponse"

Defined in: packages/poml/base.tsx:49


Message

Defined in: packages/poml/base.tsx:63

Properties

content

content: RichContent

Defined in: packages/poml/base.tsx:65

speaker

speaker: Speaker

Defined in: packages/poml/base.tsx:64


Parameter

Defined in: packages/poml/base.tsx:605

Properties

choices

choices: string[]

Defined in: packages/poml/base.tsx:609

defaultValue

defaultValue: undefined | string

Defined in: packages/poml/base.tsx:611

description

description: string

Defined in: packages/poml/base.tsx:610

fallbackType

fallbackType: undefined | string

Defined in: packages/poml/base.tsx:608

name

name: string

Defined in: packages/poml/base.tsx:606

required

required: boolean

Defined in: packages/poml/base.tsx:612

type

type: string

Defined in: packages/poml/base.tsx:607


PropsBase

Defined in: packages/poml/base.tsx:126

Props base serves the following props subclass, as far as I can now think of: 1. Props for markup basic components 2. Props for serialization basic components 3. Props for essential general components 3.1. Props for other high-level components

Extended by

Properties

charLimit?

optional charLimit: number

Defined in: packages/poml/base.tsx:143

Soft character limit before truncation is applied.

className?

optional className: string

Defined in: packages/poml/base.tsx:128

originalEndIndex?

optional originalEndIndex: number

Defined in: packages/poml/base.tsx:133

originalStartIndex?

optional originalStartIndex: number

Defined in: packages/poml/base.tsx:132

priority?

optional priority: number

Defined in: packages/poml/base.tsx:147

Priority used when truncating globally. Lower numbers are dropped first.

sourcePath?

optional sourcePath: string

Defined in: packages/poml/base.tsx:136

speaker?

optional speaker: Speaker

Defined in: packages/poml/base.tsx:127

tokenLimit?

optional tokenLimit: number

Defined in: packages/poml/base.tsx:145

Soft token limit before truncation is applied.

whiteSpace?

optional whiteSpace: "filter" | "pre" | "trim"

Defined in: packages/poml/base.tsx:140

writerOptions?

optional writerOptions: object

Defined in: packages/poml/base.tsx:139


SourceMapMessage

Defined in: packages/poml/base.tsx:76

Properties

content

content: SourceMapRichContent[]

Defined in: packages/poml/base.tsx:82

endIndex

endIndex: number

Defined in: packages/poml/base.tsx:78

irEndIndex

irEndIndex: number

Defined in: packages/poml/base.tsx:80

irStartIndex

irStartIndex: number

Defined in: packages/poml/base.tsx:79

speaker

speaker: Speaker

Defined in: packages/poml/base.tsx:81

startIndex

startIndex: number

Defined in: packages/poml/base.tsx:77


SourceMapRichContent

Defined in: packages/poml/base.tsx:68

Properties

content

content: RichContent

Defined in: packages/poml/base.tsx:73

endIndex

endIndex: number

Defined in: packages/poml/base.tsx:70

irEndIndex

irEndIndex: number

Defined in: packages/poml/base.tsx:72

irStartIndex

irStartIndex: number

Defined in: packages/poml/base.tsx:71

startIndex

startIndex: number

Defined in: packages/poml/base.tsx:69


StyleSheet

Defined in: packages/poml/base.tsx:522

Stylesheet is a way to configure the props to be used in the components globally. It can be used to set multiple things, including markup syntax, presentation approach, text formats, and more, as long as they are supported by the components' props. If a globally set prop is not supported by a component, it will be ignored.

The style can be set for all components or for a specific component type, such as:

const stylesheet = {
  '*': {
    presentation: 'markup',
    markupLang: 'markdown',
    listStyle: 'unordered'
  },
  'table': {
    presentation: 'serialize',
    serializer: 'json'
  },
  Example: {
    messageInteraction: true
  },
  TaskDescription: {
    titleMarkupTransform: 'header',
    titleTextTransform: {
      case: 'upper'
    }
  }
}

The stylesheet can be then set via a StyleSheetProvider component:

<StyleSheetProvider stylesheet={stylesheet}><MyPrompt /></StyleSheetProvider>

Indexable

[match: string]: AnyProps

Type Aliases

ContentMultiMedia

ContentMultiMedia = ContentMultiMediaBinary | ContentMultiMediaJson | ContentMultiMediaToolRequest | ContentMultiMediaToolResponse

Defined in: packages/poml/base.tsx:55


RichContent

RichContent = string | (string | ContentMultiMedia)[]

Defined in: packages/poml/base.tsx:61


Speaker

Speaker = "system" | "human" | "ai" | "tool"

Defined in: packages/poml/base.tsx:15

Variables

ValidSpeakers

const ValidSpeakers: string[]

Defined in: packages/poml/base.tsx:16

Functions

component()

Call Signature

component(name, options?): \<T>(fn) => T

Defined in: packages/poml/base.tsx:988

Usage: 1. component('my-component', ['mc'])(MyComponent) 2. component('my-component', { aliases: ['mc'], requiredProps: ['requiredProp'], unwantedProps: ['unwantedProp'], applyStyleSheet: false })(MyComponent)

Parameters
name

string

options?

string[]

Returns

\<T>(fn): T

Type Parameters
T

T

Parameters
fn

T

Returns

T

Call Signature

component(name, options?): \<T>(fn) => T

Defined in: packages/poml/base.tsx:989

Usage: 1. component('my-component', ['mc'])(MyComponent) 2. component('my-component', { aliases: ['mc'], requiredProps: ['requiredProp'], unwantedProps: ['unwantedProp'], applyStyleSheet: false })(MyComponent)

Parameters
name

string

options?

NonStrictComponentOptions

Returns

\<T>(fn): T

Type Parameters
T

T

Parameters
fn

T

Returns

T


expandRelative()

expandRelative(src): string

Defined in: packages/poml/base.tsx:594

Parameters

src

string

Returns

string


findComponentByAlias()

findComponentByAlias(alias, disabled?): string | PomlComponent

Defined in: packages/poml/base.tsx:1031

Find a component by its alias. If not found, return a string that suggests the closest match.

Parameters

alias

string

Alias or official name.

disabled?

Set\<string>

Returns

string | PomlComponent


findComponentByAliasOrUndefined()

findComponentByAliasOrUndefined(alias, disabled?): undefined | PomlComponent

Defined in: packages/poml/base.tsx:1038

Parameters

alias

string

disabled?

Set\<string>

Returns

undefined | PomlComponent


irElement()

irElement(type, props, ...children): DOMElement\<{[k: string]: undefined | { }; }, Element>

Defined in: packages/poml/base.tsx:154

Create an element that will be visible in the IR. Helper function for logging and debugging purposes.

Parameters

type

string

props

any

children

...ReactNode[]

Returns

DOMElement\<{[k: string]: undefined | { }; }, Element>


listComponents()

listComponents(): PomlComponent[]

Defined in: packages/poml/base.tsx:1045

Returns

PomlComponent[]


richContentFromSourceMap()

richContentFromSourceMap(contents): RichContent

Defined in: packages/poml/base.tsx:85

Parameters

contents

SourceMapRichContent[]

Returns

RichContent


SourceProvider()

SourceProvider(__namedParameters): Element

Defined in: packages/poml/base.tsx:588

Parameters

__namedParameters

PropsWithChildren\<{ source: string; }>

Returns

Element


StyleSheetProvider()

StyleSheetProvider(__namedParameters): Element

Defined in: packages/poml/base.tsx:532

Parameters

__namedParameters

PropsWithChildren\<{ stylesheet: StyleSheet; }>

Returns

Element


trimChildrenWhiteSpace()

trimChildrenWhiteSpace(children, props): (undefined | null | string | number | bigint | boolean | ReactElement\<unknown, string | JSXElementConstructor\<any>> | Iterable\<ReactNode, any, any> | Promise\<AwaitedReactNode>)[]

Defined in: packages/poml/base.tsx:180

Parameters

children

ReactNode

props

PropsBase

Returns

(undefined | null | string | number | bigint | boolean | ReactElement\<unknown, string | JSXElementConstructor\<any>> | Iterable\<ReactNode, any, any> | Promise\<AwaitedReactNode>)[]


unregisterComponent()

unregisterComponent(alias): void

Defined in: packages/poml/base.tsx:1023

Parameters

alias

string

Returns

void


useWithCatch()

useWithCatch\<T>(promise, props): void | T

Defined in: packages/poml/base.tsx:466

Type Parameters

T

T

Parameters

promise

Promise\<T>

props

PropsBase

Returns

void | T