@personaai/runtime 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -8
- package/dist/index.cjs +40 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -6
- package/dist/index.d.ts +11 -6
- package/dist/index.js +40 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -292,9 +292,12 @@ interface RuntimeCapabilities {
|
|
|
292
292
|
/** What {@link CreateRuntimeOptions.selectVersion} is asked about. */
|
|
293
293
|
interface VersionSelectionContext {
|
|
294
294
|
userId: string;
|
|
295
|
-
agentId: string;
|
|
296
295
|
/** Which route is starting the run. */
|
|
297
|
-
kind: 'chat' | 'voice';
|
|
296
|
+
kind: 'chat' | 'voice' | 'messages' | 'workflow';
|
|
297
|
+
/** The Agent (absent for `kind: 'workflow'`, whose choice applies to every agent step). */
|
|
298
|
+
agentId?: string;
|
|
299
|
+
/** Set for `kind: 'workflow'`. */
|
|
300
|
+
workflowId?: string;
|
|
298
301
|
}
|
|
299
302
|
/** Which published version of an Agent a run uses. Empty = the Agent's own default. */
|
|
300
303
|
interface VersionSelection {
|
|
@@ -495,7 +498,8 @@ interface CreateRuntimeOptions {
|
|
|
495
498
|
/**
|
|
496
499
|
* Picks the published version a run uses, per request — canaries, beta
|
|
497
500
|
* users on `development`, pinning one customer to a version. Applies to
|
|
498
|
-
* `/chat
|
|
501
|
+
* `/chat`, `/voice/sessions`, `/messages/agent` and workflow runs (their
|
|
502
|
+
* agent steps). Return `undefined` for the default.
|
|
499
503
|
*/
|
|
500
504
|
selectVersion?: (ctx: VersionSelectionContext) => VersionSelection | undefined | Promise<VersionSelection | undefined>;
|
|
501
505
|
/**
|
|
@@ -514,8 +518,9 @@ interface CreateRuntimeOptions {
|
|
|
514
518
|
*/
|
|
515
519
|
allowClientVersionSelection?: boolean;
|
|
516
520
|
/**
|
|
517
|
-
* Forward the incoming `traceparent` header to Persona on `/chat`,
|
|
518
|
-
*
|
|
521
|
+
* Forward the incoming `traceparent` header to Persona on `/chat`,
|
|
522
|
+
* `/voice/sessions`, `/messages/agent` and workflow runs, so their traces
|
|
523
|
+
* join your own OpenTelemetry trace. @default true
|
|
519
524
|
*/
|
|
520
525
|
forwardTraceparent?: boolean;
|
|
521
526
|
/** Receive Persona webhooks at `POST /webhooks/persona`. See {@link WebhooksOptions}. Unset by default. */
|
|
@@ -546,7 +551,7 @@ declare class RuntimeHttpError extends Error {
|
|
|
546
551
|
constructor(status: number, code: string, message: string);
|
|
547
552
|
}
|
|
548
553
|
|
|
549
|
-
declare const RUNTIME_VERSION = "0.
|
|
554
|
+
declare const RUNTIME_VERSION = "0.24.0";
|
|
550
555
|
|
|
551
556
|
/** The API key scope each capability needs (`*` covers everything). */
|
|
552
557
|
declare const CAPABILITY_SCOPES: Record<keyof RuntimeCapabilities, string[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -292,9 +292,12 @@ interface RuntimeCapabilities {
|
|
|
292
292
|
/** What {@link CreateRuntimeOptions.selectVersion} is asked about. */
|
|
293
293
|
interface VersionSelectionContext {
|
|
294
294
|
userId: string;
|
|
295
|
-
agentId: string;
|
|
296
295
|
/** Which route is starting the run. */
|
|
297
|
-
kind: 'chat' | 'voice';
|
|
296
|
+
kind: 'chat' | 'voice' | 'messages' | 'workflow';
|
|
297
|
+
/** The Agent (absent for `kind: 'workflow'`, whose choice applies to every agent step). */
|
|
298
|
+
agentId?: string;
|
|
299
|
+
/** Set for `kind: 'workflow'`. */
|
|
300
|
+
workflowId?: string;
|
|
298
301
|
}
|
|
299
302
|
/** Which published version of an Agent a run uses. Empty = the Agent's own default. */
|
|
300
303
|
interface VersionSelection {
|
|
@@ -495,7 +498,8 @@ interface CreateRuntimeOptions {
|
|
|
495
498
|
/**
|
|
496
499
|
* Picks the published version a run uses, per request — canaries, beta
|
|
497
500
|
* users on `development`, pinning one customer to a version. Applies to
|
|
498
|
-
* `/chat
|
|
501
|
+
* `/chat`, `/voice/sessions`, `/messages/agent` and workflow runs (their
|
|
502
|
+
* agent steps). Return `undefined` for the default.
|
|
499
503
|
*/
|
|
500
504
|
selectVersion?: (ctx: VersionSelectionContext) => VersionSelection | undefined | Promise<VersionSelection | undefined>;
|
|
501
505
|
/**
|
|
@@ -514,8 +518,9 @@ interface CreateRuntimeOptions {
|
|
|
514
518
|
*/
|
|
515
519
|
allowClientVersionSelection?: boolean;
|
|
516
520
|
/**
|
|
517
|
-
* Forward the incoming `traceparent` header to Persona on `/chat`,
|
|
518
|
-
*
|
|
521
|
+
* Forward the incoming `traceparent` header to Persona on `/chat`,
|
|
522
|
+
* `/voice/sessions`, `/messages/agent` and workflow runs, so their traces
|
|
523
|
+
* join your own OpenTelemetry trace. @default true
|
|
519
524
|
*/
|
|
520
525
|
forwardTraceparent?: boolean;
|
|
521
526
|
/** Receive Persona webhooks at `POST /webhooks/persona`. See {@link WebhooksOptions}. Unset by default. */
|
|
@@ -546,7 +551,7 @@ declare class RuntimeHttpError extends Error {
|
|
|
546
551
|
constructor(status: number, code: string, message: string);
|
|
547
552
|
}
|
|
548
553
|
|
|
549
|
-
declare const RUNTIME_VERSION = "0.
|
|
554
|
+
declare const RUNTIME_VERSION = "0.24.0";
|
|
550
555
|
|
|
551
556
|
/** The API key scope each capability needs (`*` covers everything). */
|
|
552
557
|
declare const CAPABILITY_SCOPES: Record<keyof RuntimeCapabilities, string[]>;
|
package/dist/index.js
CHANGED
|
@@ -169,7 +169,7 @@ function evictStaleRuns(runs, now, graceMs = DEFAULT_RUN_GRACE_MS, maxTracked =
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
// src/version.ts
|
|
172
|
-
var RUNTIME_VERSION = "0.
|
|
172
|
+
var RUNTIME_VERSION = "0.24.0";
|
|
173
173
|
|
|
174
174
|
// src/routes/health.ts
|
|
175
175
|
var alwaysOnCapabilities = {
|
|
@@ -335,17 +335,18 @@ function validateTurnContext(value) {
|
|
|
335
335
|
return context;
|
|
336
336
|
}
|
|
337
337
|
var ENVIRONMENTS = ["development", "production"];
|
|
338
|
-
function clientVersionFields(body) {
|
|
338
|
+
function clientVersionFields(body, envField = "environment") {
|
|
339
339
|
const out = {};
|
|
340
|
-
|
|
341
|
-
|
|
340
|
+
const env = body[envField];
|
|
341
|
+
if (env !== void 0 && env !== null) {
|
|
342
|
+
if (!ENVIRONMENTS.includes(env)) {
|
|
342
343
|
throw new RuntimeHttpError(
|
|
343
344
|
400,
|
|
344
345
|
"INVALID_REQUEST",
|
|
345
|
-
|
|
346
|
+
`"${envField}" must be "development" or "production".`
|
|
346
347
|
);
|
|
347
348
|
}
|
|
348
|
-
out.environment =
|
|
349
|
+
out.environment = env;
|
|
349
350
|
}
|
|
350
351
|
if (body.agentVersion !== void 0 && body.agentVersion !== null) {
|
|
351
352
|
const v = body.agentVersion;
|
|
@@ -360,10 +361,10 @@ function clientVersionFields(body) {
|
|
|
360
361
|
}
|
|
361
362
|
return out;
|
|
362
363
|
}
|
|
363
|
-
async function resolveRunVersion(body, ctx, selection) {
|
|
364
|
+
async function resolveRunVersion(body, ctx, selection, envField = "environment") {
|
|
364
365
|
const { selectVersion, defaultEnvironment, allowClientVersionSelection } = ctx.versioning;
|
|
365
366
|
if (allowClientVersionSelection) {
|
|
366
|
-
const fromClient = clientVersionFields(body);
|
|
367
|
+
const fromClient = clientVersionFields(body, envField);
|
|
367
368
|
if (fromClient.environment || fromClient.agentVersion) return fromClient;
|
|
368
369
|
}
|
|
369
370
|
if (selectVersion) {
|
|
@@ -1027,8 +1028,11 @@ var createVoiceSession = async (request, ctx) => {
|
|
|
1027
1028
|
agentId,
|
|
1028
1029
|
kind: "voice"
|
|
1029
1030
|
});
|
|
1031
|
+
const traceparent = incomingTraceparent(request.headers, ctx.forwardTraceparent);
|
|
1030
1032
|
const ticket = await ctx.client.voice.createSession(agentId, {
|
|
1031
1033
|
...version,
|
|
1034
|
+
// `traceparent` needs @personaai/sdk >= 0.27 (older SDKs ignore it).
|
|
1035
|
+
...traceparent ? { traceparent } : {},
|
|
1032
1036
|
...threadId ? { threadId } : {},
|
|
1033
1037
|
...contextOverride ? { contextOverride } : {},
|
|
1034
1038
|
...context ? { context } : {},
|
|
@@ -1119,12 +1123,23 @@ var sendAgentMessage = async (request, ctx) => {
|
|
|
1119
1123
|
const prompt = requireStringField(body, "prompt");
|
|
1120
1124
|
const channel = optionalChannel(body);
|
|
1121
1125
|
const displayName = optionalStringField(body, "displayName");
|
|
1126
|
+
const version = await resolveRunVersion(body, ctx, {
|
|
1127
|
+
userId: request.userId,
|
|
1128
|
+
agentId,
|
|
1129
|
+
kind: "messages"
|
|
1130
|
+
});
|
|
1131
|
+
const traceparent = incomingTraceparent(request.headers, ctx.forwardTraceparent);
|
|
1132
|
+
const runOptions = {
|
|
1133
|
+
...version,
|
|
1134
|
+
...traceparent ? { traceparent } : {}
|
|
1135
|
+
};
|
|
1122
1136
|
const delivery = await ctx.client.messages.sendFromAgent({
|
|
1123
1137
|
agentId,
|
|
1124
1138
|
to,
|
|
1125
1139
|
prompt,
|
|
1126
1140
|
...channel ? { channel } : {},
|
|
1127
|
-
...displayName ? { displayName } : {}
|
|
1141
|
+
...displayName ? { displayName } : {},
|
|
1142
|
+
...runOptions
|
|
1128
1143
|
});
|
|
1129
1144
|
return json(200, delivery);
|
|
1130
1145
|
};
|
|
@@ -1820,11 +1835,26 @@ var workflowStreamRoute = async (request, ctx) => {
|
|
|
1820
1835
|
workflowId,
|
|
1821
1836
|
input: body.input
|
|
1822
1837
|
};
|
|
1838
|
+
const agentVersion = await resolveRunVersion(
|
|
1839
|
+
request.body ?? {},
|
|
1840
|
+
ctx,
|
|
1841
|
+
{ userId, workflowId, kind: "workflow" },
|
|
1842
|
+
"agentEnvironment"
|
|
1843
|
+
);
|
|
1844
|
+
if (agentVersion.environment) runCtx.environment = agentVersion.environment;
|
|
1845
|
+
if (agentVersion.agentVersion) runCtx.agentVersion = agentVersion.agentVersion;
|
|
1846
|
+
const traceparent = incomingTraceparent(request.headers, ctx.forwardTraceparent);
|
|
1823
1847
|
await ctx.hooks?.beforeRun?.(runCtx);
|
|
1848
|
+
const runOptions = {
|
|
1849
|
+
...agentVersion.environment ? { agentEnvironment: agentVersion.environment } : {},
|
|
1850
|
+
...agentVersion.agentVersion ? { agentVersion: agentVersion.agentVersion } : {},
|
|
1851
|
+
...traceparent ? { traceparent } : {}
|
|
1852
|
+
};
|
|
1824
1853
|
const stream = ctx.client.workflows.stream(workflowId, {
|
|
1825
1854
|
input: body.input,
|
|
1826
1855
|
dryRun: body.dryRun,
|
|
1827
|
-
version: body.version
|
|
1856
|
+
version: body.version,
|
|
1857
|
+
...runOptions
|
|
1828
1858
|
});
|
|
1829
1859
|
const runId = crypto.randomUUID();
|
|
1830
1860
|
const driver = new RunDriver(runId, runCtx, stream, ctx.hooks, ctx.mode);
|