@personaai/runtime 0.9.1 → 0.9.4

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/dist/index.d.cts CHANGED
@@ -307,6 +307,6 @@ declare class RuntimeHttpError extends Error {
307
307
  constructor(status: number, code: string, message: string);
308
308
  }
309
309
 
310
- declare const RUNTIME_VERSION = "0.5.4";
310
+ declare const RUNTIME_VERSION = "0.9.4";
311
311
 
312
312
  export { type CreateRuntimeOptions, type ErrorContext, type FileUploadContext, type MemoryWriteContext, RUNTIME_VERSION, type RcpManifestOptions, type ResolveUser, type RestToolManifestEntry, type RestToolsManifestOptions, type RunContext, type RunResult, type Runtime, type RuntimeBinaryResponse, type RuntimeBufferedResponse, type RuntimeCapabilities, type RuntimeHooks, RuntimeHttpError, type RuntimeMethod, type RuntimeRequest, type RuntimeResponse, type RuntimeStreamResponse, type RuntimeUploadedFile, type ThreadCreateContext, type ToolCallContext, type VoiceSessionCreateContext, createRuntime };
package/dist/index.d.ts CHANGED
@@ -307,6 +307,6 @@ declare class RuntimeHttpError extends Error {
307
307
  constructor(status: number, code: string, message: string);
308
308
  }
309
309
 
310
- declare const RUNTIME_VERSION = "0.5.4";
310
+ declare const RUNTIME_VERSION = "0.9.4";
311
311
 
312
312
  export { type CreateRuntimeOptions, type ErrorContext, type FileUploadContext, type MemoryWriteContext, RUNTIME_VERSION, type RcpManifestOptions, type ResolveUser, type RestToolManifestEntry, type RestToolsManifestOptions, type RunContext, type RunResult, type Runtime, type RuntimeBinaryResponse, type RuntimeBufferedResponse, type RuntimeCapabilities, type RuntimeHooks, RuntimeHttpError, type RuntimeMethod, type RuntimeRequest, type RuntimeResponse, type RuntimeStreamResponse, type RuntimeUploadedFile, type ThreadCreateContext, type ToolCallContext, type VoiceSessionCreateContext, createRuntime };
package/dist/index.js CHANGED
@@ -131,7 +131,7 @@ function evictStaleRuns(runs, now, graceMs = DEFAULT_RUN_GRACE_MS, maxTracked =
131
131
  }
132
132
 
133
133
  // src/version.ts
134
- var RUNTIME_VERSION = "0.5.4";
134
+ var RUNTIME_VERSION = "0.9.4";
135
135
 
136
136
  // src/routes/health.ts
137
137
  var alwaysOnCapabilities = {
@@ -209,6 +209,33 @@ function requireStringField(body, field) {
209
209
  }
210
210
  return value;
211
211
  }
212
+ var MAX_TURN_CONTEXT_BYTES = 2e3;
213
+ function validateTurnContext(value) {
214
+ if (value === void 0) return void 0;
215
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
216
+ throw new RuntimeHttpError(400, "INVALID_CONTEXT", "context must be a flat object.");
217
+ }
218
+ const context = value;
219
+ for (const [key, entry] of Object.entries(context)) {
220
+ const entryType = typeof entry;
221
+ if (entryType !== "string" && entryType !== "number" && entryType !== "boolean") {
222
+ throw new RuntimeHttpError(
223
+ 400,
224
+ "INVALID_CONTEXT",
225
+ `context.${key} must be a string, number, or boolean.`
226
+ );
227
+ }
228
+ }
229
+ const byteLength = new TextEncoder().encode(JSON.stringify(context)).length;
230
+ if (byteLength > MAX_TURN_CONTEXT_BYTES) {
231
+ throw new RuntimeHttpError(
232
+ 400,
233
+ "CONTEXT_TOO_LARGE",
234
+ `context must be ${MAX_TURN_CONTEXT_BYTES} bytes or fewer when serialized.`
235
+ );
236
+ }
237
+ return context;
238
+ }
212
239
 
213
240
  // src/routes/restToolsManifest.ts
214
241
  var restToolsManifestRoute = async (request, ctx) => {
@@ -534,7 +561,12 @@ function parseChatBody(body) {
534
561
  messages: b.messages,
535
562
  threadId: typeof b.threadId === "string" ? b.threadId : void 0,
536
563
  resume: b.resume ?? void 0,
537
- contextOverride: typeof b.contextOverride === "string" ? b.contextOverride : void 0
564
+ contextOverride: typeof b.contextOverride === "string" ? b.contextOverride : void 0,
565
+ // Distinct from contextOverride above — never shown to the model, only
566
+ // ever read live by an RCP tool's resolver. validateTurnContext throws
567
+ // a 400 on any shape violation (not a flat string/number/boolean
568
+ // object, or over the byte cap) rather than coercing/dropping it.
569
+ context: validateTurnContext(b.context)
538
570
  };
539
571
  }
540
572
  var chatRoute = async (request, ctx) => {
@@ -546,7 +578,8 @@ var chatRoute = async (request, ctx) => {
546
578
  threadId: body.threadId,
547
579
  messageCount: body.messages?.length ?? 0,
548
580
  hasResume: !!body.resume,
549
- hasContextOverride: !!body.contextOverride
581
+ hasContextOverride: !!body.contextOverride,
582
+ hasContext: !!body.context
550
583
  });
551
584
  const userId = request.userId;
552
585
  const runCtx = {
@@ -564,7 +597,8 @@ var chatRoute = async (request, ctx) => {
564
597
  messages: body.messages,
565
598
  threadId: body.threadId,
566
599
  resume: body.resume,
567
- contextOverride: body.contextOverride
600
+ contextOverride: body.contextOverride,
601
+ context: body.context
568
602
  });
569
603
  const runId = crypto.randomUUID();
570
604
  logger.info("chat run created", {
@@ -757,9 +791,11 @@ var createVoiceSession = async (request, ctx) => {
757
791
  const agentId = requireStringField(body, "agentId");
758
792
  const threadId = typeof body.threadId === "string" && body.threadId ? body.threadId : void 0;
759
793
  const contextOverride = typeof body.contextOverride === "string" && body.contextOverride ? body.contextOverride : void 0;
794
+ const context = validateTurnContext(body.context);
760
795
  const ticket = await ctx.client.voice.createSession(agentId, {
761
796
  ...threadId ? { threadId } : {},
762
- ...contextOverride ? { contextOverride } : {}
797
+ ...contextOverride ? { contextOverride } : {},
798
+ ...context ? { context } : {}
763
799
  });
764
800
  await ctx.hooks?.onVoiceSessionCreate?.({
765
801
  userId: request.userId,
@@ -1357,6 +1393,17 @@ function buildRoutes(capabilities) {
1357
1393
  method: "GET",
1358
1394
  pattern: ["agents", ":id", "mcp-connections"],
1359
1395
  handler: getAgentMcpConnections
1396
+ },
1397
+ // MCP App resources and widget tool calls — always on for conversational widgets.
1398
+ {
1399
+ method: "GET",
1400
+ pattern: ["mcps", ":id", "resource"],
1401
+ handler: readMcpResource
1402
+ },
1403
+ {
1404
+ method: "POST",
1405
+ pattern: ["mcps", ":id", "call-tool"],
1406
+ handler: callMcpTool
1360
1407
  }
1361
1408
  ];
1362
1409
  if (capabilities.agentsWrite) {
@@ -1377,9 +1424,7 @@ function buildRoutes(capabilities) {
1377
1424
  { method: "PATCH", pattern: ["mcps", ":id"], handler: updateMcp },
1378
1425
  { method: "DELETE", pattern: ["mcps", ":id"], handler: deleteMcp },
1379
1426
  { method: "GET", pattern: ["mcps", ":id", "usage"], handler: getMcpUsage },
1380
- { method: "POST", pattern: ["mcps", ":id", "test"], handler: testMcpConnection },
1381
- { method: "GET", pattern: ["mcps", ":id", "resource"], handler: readMcpResource },
1382
- { method: "POST", pattern: ["mcps", ":id", "call-tool"], handler: callMcpTool }
1427
+ { method: "POST", pattern: ["mcps", ":id", "test"], handler: testMcpConnection }
1383
1428
  );
1384
1429
  }
1385
1430
  if (capabilities.providers) {