Skip to content

PURISTA API


PURISTA API / @purista/ai / resolveBaseSessionId

Function: resolveBaseSessionId()

resolveBaseSessionId(context, payload): string

Defined in: packages/ai/src/runtime/sessionIdentity.ts:49

Resolves the base session id used for implicit session helpers.

Parameters

context

{ configs: { getConfig: ConfigGetterFunction; removeConfig: ConfigDeleteFunction; setConfig: ConfigSetterFunction; }; emit: EmitCustomMessageFunction<EmptyObject>; invokeAgent: EmptyObject; logger: Logger; message: Readonly<Command<MessagePayloadType, MessageParamsType>>; queue: QueueContext & QueueContext<QueueInvokeList>; resources: EmptyObject; secrets: { getSecret: SecretGetterFunction; removeSecret: SecretDeleteFunction; setSecret: SecretSetterFunction; }; service: EmptyObject; startActiveSpan: <F>(name, opts, context, fn) => Promise<F>; states: { getState: StateGetterFunction; removeState: StateDeleteFunction; setState: StateSetterFunction; }; stream: EmptyObject; wrapInSpan: <F>(name, opts, fn, context?) => Promise<F>; }

configs

{ getConfig: ConfigGetterFunction; removeConfig: ConfigDeleteFunction; setConfig: ConfigSetterFunction; }

the config store

configs.getConfig

ConfigGetterFunction

get a config value from the config store

configs.removeConfig

ConfigDeleteFunction

delete a config value from the config store

configs.setConfig

ConfigSetterFunction

set a config value in the config store

emit

EmitCustomMessageFunction<EmptyObject>

emit a custom message

invokeAgent

EmptyObject

Invokes an agent and returns the result.

logger

Logger

the logger instance

message

Readonly<Command<MessagePayloadType, MessageParamsType>>

the original message

queue

QueueContext & QueueContext<QueueInvokeList>

typed queue enqueue helpers

resources

EmptyObject

Provides resources defined in service builder and set via config during service creation

secrets

{ getSecret: SecretGetterFunction; removeSecret: SecretDeleteFunction; setSecret: SecretSetterFunction; }

the secret store

secrets.getSecret

SecretGetterFunction

get a secret from the secret store

secrets.removeSecret

SecretDeleteFunction

delete a secret from the secret store

secrets.setSecret

SecretSetterFunction

set a secret in the secret store

service

EmptyObject

Invokes a command and returns the result. It is recommended to validate the result against a schema which only contains the data you actually need.

Example

typescript
// define your invocation in command builder
.canInvoke('ServiceA', '1', 'test', responseOutputSchema, payloadSchema, parameterSchema)
.setCommandFunction(async function (context, payload, _parameter) {
const inputPayload = { my: 'input' }
const inputParameter = { search: 'for_me' }
const result = await context.service.ServiceA[1].test(inputPayload,inputParameter)
})

startActiveSpan

<F>(name, opts, context, fn) => Promise<F>

wrap given function in an opentelemetry active span

states

{ getState: StateGetterFunction; removeState: StateDeleteFunction; setState: StateSetterFunction; }

the state store

states.getState

StateGetterFunction

get a state value from the state store

states.removeState

StateDeleteFunction

delete a state value from the state store

states.setState

StateSetterFunction

set a state value in the state store

stream

EmptyObject

consumes stream responses from other service stream endpoints

wrapInSpan

<F>(name, opts, fn, context?) => Promise<F>

wrap given function in an opentelemetry span

|

{ configs: { getConfig: ConfigGetterFunction; removeConfig: ConfigDeleteFunction; setConfig: ConfigSetterFunction; }; emit: EmitCustomMessageFunction<EmptyObject>; invokeAgent: EmptyObject; logger: Logger; message: Readonly<StreamOpenRequest<MessagePayloadType, MessageParamsType>>; queue: QueueContext & QueueContext<QueueInvokeList>; resources: EmptyObject; secrets: { getSecret: SecretGetterFunction; removeSecret: SecretDeleteFunction; setSecret: SecretSetterFunction; }; service: EmptyObject; startActiveSpan: <F>(name, opts, context, fn) => Promise<F>; states: { getState: StateGetterFunction; removeState: StateDeleteFunction; setState: StateSetterFunction; }; stream: EmptyObject; wrapInSpan: <F>(name, opts, fn, context?) => Promise<F>; }

configs

{ getConfig: ConfigGetterFunction; removeConfig: ConfigDeleteFunction; setConfig: ConfigSetterFunction; }

the config store

configs.getConfig

ConfigGetterFunction

get a config value from the config store

configs.removeConfig

ConfigDeleteFunction

delete a config value from the config store

configs.setConfig

ConfigSetterFunction

set a config value in the config store

emit

EmitCustomMessageFunction<EmptyObject>

invokeAgent

EmptyObject

Invokes an agent and returns the result.

logger

Logger

the logger instance

message

Readonly<StreamOpenRequest<MessagePayloadType, MessageParamsType>>

queue

QueueContext & QueueContext<QueueInvokeList>

resources

EmptyObject

secrets

{ getSecret: SecretGetterFunction; removeSecret: SecretDeleteFunction; setSecret: SecretSetterFunction; }

the secret store

secrets.getSecret

SecretGetterFunction

get a secret from the secret store

secrets.removeSecret

SecretDeleteFunction

delete a secret from the secret store

secrets.setSecret

SecretSetterFunction

set a secret in the secret store

service

EmptyObject

startActiveSpan

<F>(name, opts, context, fn) => Promise<F>

wrap given function in an opentelemetry active span

states

{ getState: StateGetterFunction; removeState: StateDeleteFunction; setState: StateSetterFunction; }

the state store

states.getState

StateGetterFunction

get a state value from the state store

states.removeState

StateDeleteFunction

delete a state value from the state store

states.setState

StateSetterFunction

set a state value in the state store

stream

EmptyObject

wrapInSpan

<F>(name, opts, fn, context?) => Promise<F>

wrap given function in an opentelemetry span

payload

unknown

Returns

string