@personaai/runtime 0.7.1 → 0.9.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/dist/index.d.cts CHANGED
@@ -1,4 +1,6 @@
1
- import { ChatMessageInput, LogLevel, Logger } from '@personaai/sdk';
1
+ import { ChatMessageInput, CreateRestToolInput, LogLevel, Logger } from '@personaai/sdk';
2
+ import { RcpTool } from 'rcp-sdk';
3
+ export { RcpTool } from 'rcp-sdk';
2
4
 
3
5
  type RuntimeMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
4
6
  /** A single uploaded file — present on `RuntimeRequest.file` for a multipart `POST /files`. */
@@ -148,6 +150,13 @@ interface RuntimeHooks {
148
150
  onVoiceSessionCreate?(ctx: VoiceSessionCreateContext): void | Promise<void>;
149
151
  }
150
152
 
153
+ /**
154
+ * One REST tool definition served by the manifest route — identical to
155
+ * `CreateRestToolInput` from `@personaai/sdk@^0.7.0` (also `defineRestTool`'s
156
+ * return type from `@personaai/sdk/rest-tools`), aliased under this name for
157
+ * clarity at the call site (`createRuntime({ restToolsManifest: { tools } })`).
158
+ */
159
+ type RestToolManifestEntry = CreateRestToolInput;
151
160
  /**
152
161
  * The single point of contact between the host's auth world and the
153
162
  * runtime's world. Receives the inbound request (with `userId: null`) and
@@ -186,6 +195,46 @@ interface RuntimeCapabilities {
186
195
  /** The Architect co-pilot — builds/edits Agents on the caller's behalf via tool calls. @default false */
187
196
  architect?: boolean;
188
197
  }
198
+ /**
199
+ * Serves a list of code-defined REST tools (built with `defineRestTool`
200
+ * from `@personaai/sdk/rest-tools`) as a JSON manifest at
201
+ * `GET {mountPath}/rest-tools/manifest` — register that URL in the Persona
202
+ * dashboard as a REST Tool Source and it discovers/calls these tools live,
203
+ * the same way it discovers an MCP server's tools. This is host-side
204
+ * static data the runtime *serves*, not a Persona-proxy capability — it
205
+ * never calls `PersonaClient` and works even with no `resolveUser`
206
+ * traffic at all.
207
+ */
208
+ interface RestToolsManifestOptions {
209
+ /** REST tool definitions to serve — build each with `defineRestTool` from `@personaai/sdk/rest-tools`, or pass a plain object of the same shape. */
210
+ tools: RestToolManifestEntry[];
211
+ /**
212
+ * Required `Authorization: Bearer <token>` value the manifest route
213
+ * checks incoming requests against — must match the API Key configured
214
+ * on the Persona-side REST Tool Source. Omitting this leaves the route
215
+ * open (no auth) — only acceptable for local/dev testing.
216
+ */
217
+ authToken?: string;
218
+ }
219
+ /**
220
+ * Serves a list of code-defined RCP (REST Connector Protocol, npm `rcp-sdk`)
221
+ * tools as a conformant `{ rcpVersion, auth, tools }` manifest at
222
+ * `GET {mountPath}/rcp/manifest` — register that URL as an RCP source and
223
+ * any RCP client (Persona included) discovers/calls these tools live.
224
+ * Independent of {@link RestToolsManifestOptions} — unrelated protocols,
225
+ * both servable from the same runtime instance if you want both.
226
+ */
227
+ interface RcpManifestOptions {
228
+ /** RCP tool definitions to serve — build each with `defineTool` from `rcp-sdk/server`. */
229
+ tools: RcpTool[];
230
+ /**
231
+ * Required `Authorization: Bearer <token>` value the manifest route
232
+ * checks incoming requests against. Omitting this leaves the route open
233
+ * (`auth: { type: 'none' }` in the served manifest) — only acceptable
234
+ * for local/dev testing.
235
+ */
236
+ authToken?: string;
237
+ }
189
238
  interface CreateRuntimeOptions {
190
239
  /** Base URL of the Persona Developer Platform API, e.g. "https://api.persona.hasanraiyan.me". */
191
240
  baseUrl: string;
@@ -228,6 +277,10 @@ interface CreateRuntimeOptions {
228
277
  maxTrackedRuns?: number;
229
278
  /** Opt-in switches for Project-level admin surface. See {@link RuntimeCapabilities} — everything defaults to off. */
230
279
  capabilities?: RuntimeCapabilities;
280
+ /** Serves a code-defined REST tool list for a Persona REST Tool Source to discover. See {@link RestToolsManifestOptions}. Unset by default — the route only exists when this is provided. */
281
+ restToolsManifest?: RestToolsManifestOptions;
282
+ /** Serves a conformant RCP manifest for any RCP client to discover. See {@link RcpManifestOptions}. Unset by default — the route only exists when this is provided. */
283
+ rcpManifest?: RcpManifestOptions;
231
284
  /** Log level for the runtime — off by default. Overrides the global level set via `setLogLevel()` from `@personaai/sdk`. */
232
285
  logLevel?: LogLevel;
233
286
  /** Custom logger instance — when provided, `logLevel` is ignored. */
@@ -256,4 +309,4 @@ declare class RuntimeHttpError extends Error {
256
309
 
257
310
  declare const RUNTIME_VERSION = "0.5.4";
258
311
 
259
- export { type CreateRuntimeOptions, type ErrorContext, type FileUploadContext, type MemoryWriteContext, RUNTIME_VERSION, type ResolveUser, 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 };
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
@@ -1,4 +1,6 @@
1
- import { ChatMessageInput, LogLevel, Logger } from '@personaai/sdk';
1
+ import { ChatMessageInput, CreateRestToolInput, LogLevel, Logger } from '@personaai/sdk';
2
+ import { RcpTool } from 'rcp-sdk';
3
+ export { RcpTool } from 'rcp-sdk';
2
4
 
3
5
  type RuntimeMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
4
6
  /** A single uploaded file — present on `RuntimeRequest.file` for a multipart `POST /files`. */
@@ -148,6 +150,13 @@ interface RuntimeHooks {
148
150
  onVoiceSessionCreate?(ctx: VoiceSessionCreateContext): void | Promise<void>;
149
151
  }
150
152
 
153
+ /**
154
+ * One REST tool definition served by the manifest route — identical to
155
+ * `CreateRestToolInput` from `@personaai/sdk@^0.7.0` (also `defineRestTool`'s
156
+ * return type from `@personaai/sdk/rest-tools`), aliased under this name for
157
+ * clarity at the call site (`createRuntime({ restToolsManifest: { tools } })`).
158
+ */
159
+ type RestToolManifestEntry = CreateRestToolInput;
151
160
  /**
152
161
  * The single point of contact between the host's auth world and the
153
162
  * runtime's world. Receives the inbound request (with `userId: null`) and
@@ -186,6 +195,46 @@ interface RuntimeCapabilities {
186
195
  /** The Architect co-pilot — builds/edits Agents on the caller's behalf via tool calls. @default false */
187
196
  architect?: boolean;
188
197
  }
198
+ /**
199
+ * Serves a list of code-defined REST tools (built with `defineRestTool`
200
+ * from `@personaai/sdk/rest-tools`) as a JSON manifest at
201
+ * `GET {mountPath}/rest-tools/manifest` — register that URL in the Persona
202
+ * dashboard as a REST Tool Source and it discovers/calls these tools live,
203
+ * the same way it discovers an MCP server's tools. This is host-side
204
+ * static data the runtime *serves*, not a Persona-proxy capability — it
205
+ * never calls `PersonaClient` and works even with no `resolveUser`
206
+ * traffic at all.
207
+ */
208
+ interface RestToolsManifestOptions {
209
+ /** REST tool definitions to serve — build each with `defineRestTool` from `@personaai/sdk/rest-tools`, or pass a plain object of the same shape. */
210
+ tools: RestToolManifestEntry[];
211
+ /**
212
+ * Required `Authorization: Bearer <token>` value the manifest route
213
+ * checks incoming requests against — must match the API Key configured
214
+ * on the Persona-side REST Tool Source. Omitting this leaves the route
215
+ * open (no auth) — only acceptable for local/dev testing.
216
+ */
217
+ authToken?: string;
218
+ }
219
+ /**
220
+ * Serves a list of code-defined RCP (REST Connector Protocol, npm `rcp-sdk`)
221
+ * tools as a conformant `{ rcpVersion, auth, tools }` manifest at
222
+ * `GET {mountPath}/rcp/manifest` — register that URL as an RCP source and
223
+ * any RCP client (Persona included) discovers/calls these tools live.
224
+ * Independent of {@link RestToolsManifestOptions} — unrelated protocols,
225
+ * both servable from the same runtime instance if you want both.
226
+ */
227
+ interface RcpManifestOptions {
228
+ /** RCP tool definitions to serve — build each with `defineTool` from `rcp-sdk/server`. */
229
+ tools: RcpTool[];
230
+ /**
231
+ * Required `Authorization: Bearer <token>` value the manifest route
232
+ * checks incoming requests against. Omitting this leaves the route open
233
+ * (`auth: { type: 'none' }` in the served manifest) — only acceptable
234
+ * for local/dev testing.
235
+ */
236
+ authToken?: string;
237
+ }
189
238
  interface CreateRuntimeOptions {
190
239
  /** Base URL of the Persona Developer Platform API, e.g. "https://api.persona.hasanraiyan.me". */
191
240
  baseUrl: string;
@@ -228,6 +277,10 @@ interface CreateRuntimeOptions {
228
277
  maxTrackedRuns?: number;
229
278
  /** Opt-in switches for Project-level admin surface. See {@link RuntimeCapabilities} — everything defaults to off. */
230
279
  capabilities?: RuntimeCapabilities;
280
+ /** Serves a code-defined REST tool list for a Persona REST Tool Source to discover. See {@link RestToolsManifestOptions}. Unset by default — the route only exists when this is provided. */
281
+ restToolsManifest?: RestToolsManifestOptions;
282
+ /** Serves a conformant RCP manifest for any RCP client to discover. See {@link RcpManifestOptions}. Unset by default — the route only exists when this is provided. */
283
+ rcpManifest?: RcpManifestOptions;
231
284
  /** Log level for the runtime — off by default. Overrides the global level set via `setLogLevel()` from `@personaai/sdk`. */
232
285
  logLevel?: LogLevel;
233
286
  /** Custom logger instance — when provided, `logLevel` is ignored. */
@@ -256,4 +309,4 @@ declare class RuntimeHttpError extends Error {
256
309
 
257
310
  declare const RUNTIME_VERSION = "0.5.4";
258
311
 
259
- export { type CreateRuntimeOptions, type ErrorContext, type FileUploadContext, type MemoryWriteContext, RUNTIME_VERSION, type ResolveUser, 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 };
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
@@ -161,6 +161,91 @@ var healthRoute = async (_request, ctx) => {
161
161
  };
162
162
  };
163
163
 
164
+ // src/routeHelpers.ts
165
+ function json(status, value) {
166
+ return {
167
+ kind: "buffered",
168
+ status,
169
+ headers: { "content-type": "application/json" },
170
+ body: JSON.stringify(value)
171
+ };
172
+ }
173
+ function noContent() {
174
+ return { kind: "buffered", status: 204, headers: {}, body: "" };
175
+ }
176
+ function requireParam(params, name) {
177
+ const value = params[name];
178
+ if (!value) {
179
+ throw new RuntimeHttpError(400, "INVALID_REQUEST", `"${name}" path parameter is required.`);
180
+ }
181
+ return value;
182
+ }
183
+ function requireQueryParam(query, name) {
184
+ const value = query[name];
185
+ if (!value) {
186
+ throw new RuntimeHttpError(400, "INVALID_REQUEST", `"${name}" query parameter is required.`);
187
+ }
188
+ return value;
189
+ }
190
+ function toInt(value) {
191
+ if (value === void 0) return void 0;
192
+ const parsed = Number.parseInt(value, 10);
193
+ return Number.isNaN(parsed) ? void 0 : parsed;
194
+ }
195
+ function requireBodyObject(body) {
196
+ if (typeof body !== "object" || body === null) {
197
+ throw new RuntimeHttpError(400, "INVALID_REQUEST", "Request body must be a JSON object.");
198
+ }
199
+ return body;
200
+ }
201
+ function requireStringField(body, field) {
202
+ const value = body[field];
203
+ if (typeof value !== "string" || value.length === 0) {
204
+ throw new RuntimeHttpError(
205
+ 400,
206
+ "INVALID_REQUEST",
207
+ `"${field}" is required and must be a string.`
208
+ );
209
+ }
210
+ return value;
211
+ }
212
+
213
+ // src/routes/restToolsManifest.ts
214
+ var restToolsManifestRoute = async (request, ctx) => {
215
+ const manifest = ctx.restToolsManifest;
216
+ if (!manifest) {
217
+ throw new RuntimeHttpError(404, "NOT_FOUND", "No REST tools manifest is configured.");
218
+ }
219
+ if (manifest.authToken) {
220
+ const header = request.headers.authorization;
221
+ const expected = `Bearer ${manifest.authToken}`;
222
+ if (header !== expected) {
223
+ throw new RuntimeHttpError(401, "UNAUTHORIZED", "Invalid or missing manifest bearer token.");
224
+ }
225
+ }
226
+ return json(200, { tools: manifest.tools });
227
+ };
228
+
229
+ // src/routes/rcpManifest.ts
230
+ var rcpManifestRoute = async (request, ctx) => {
231
+ const manifest = ctx.rcpManifest;
232
+ if (!manifest) {
233
+ throw new RuntimeHttpError(404, "NOT_FOUND", "No RCP manifest is configured.");
234
+ }
235
+ if (manifest.authToken) {
236
+ const header = request.headers.authorization;
237
+ const expected = `Bearer ${manifest.authToken}`;
238
+ if (header !== expected) {
239
+ throw new RuntimeHttpError(401, "UNAUTHORIZED", "Invalid or missing manifest bearer token.");
240
+ }
241
+ }
242
+ return json(200, {
243
+ rcpVersion: "0.1",
244
+ auth: manifest.authToken ? { type: "header", header: "Authorization", scheme: "Bearer" } : { type: "none" },
245
+ tools: manifest.tools
246
+ });
247
+ };
248
+
164
249
  // src/runDriver.ts
165
250
  import { EventType } from "@personaai/sdk";
166
251
  function formatSseFrame(event) {
@@ -619,55 +704,6 @@ function createResumeRoute(expectedKind) {
619
704
  };
620
705
  }
621
706
 
622
- // src/routeHelpers.ts
623
- function json(status, value) {
624
- return {
625
- kind: "buffered",
626
- status,
627
- headers: { "content-type": "application/json" },
628
- body: JSON.stringify(value)
629
- };
630
- }
631
- function noContent() {
632
- return { kind: "buffered", status: 204, headers: {}, body: "" };
633
- }
634
- function requireParam(params, name) {
635
- const value = params[name];
636
- if (!value) {
637
- throw new RuntimeHttpError(400, "INVALID_REQUEST", `"${name}" path parameter is required.`);
638
- }
639
- return value;
640
- }
641
- function requireQueryParam(query, name) {
642
- const value = query[name];
643
- if (!value) {
644
- throw new RuntimeHttpError(400, "INVALID_REQUEST", `"${name}" query parameter is required.`);
645
- }
646
- return value;
647
- }
648
- function toInt(value) {
649
- if (value === void 0) return void 0;
650
- const parsed = Number.parseInt(value, 10);
651
- return Number.isNaN(parsed) ? void 0 : parsed;
652
- }
653
- function requireBodyObject(body) {
654
- if (typeof body !== "object" || body === null) {
655
- throw new RuntimeHttpError(400, "INVALID_REQUEST", "Request body must be a JSON object.");
656
- }
657
- return body;
658
- }
659
- function requireStringField(body, field) {
660
- const value = body[field];
661
- if (typeof value !== "string" || value.length === 0) {
662
- throw new RuntimeHttpError(
663
- 400,
664
- "INVALID_REQUEST",
665
- `"${field}" is required and must be a string.`
666
- );
667
- }
668
- return value;
669
- }
670
-
671
707
  // src/routes/threads.ts
672
708
  var listThreads = async (request, ctx) => {
673
709
  const items = await ctx.client.threads.list({
@@ -1435,6 +1471,22 @@ function createRuntime(options) {
1435
1471
  );
1436
1472
  const capabilities = resolveCapabilities(options.capabilities);
1437
1473
  const routes = buildRoutes(capabilities);
1474
+ if (options.restToolsManifest) {
1475
+ routes.push({
1476
+ method: "GET",
1477
+ pattern: ["rest-tools", "manifest"],
1478
+ handler: restToolsManifestRoute,
1479
+ requiresAuth: false
1480
+ });
1481
+ }
1482
+ if (options.rcpManifest) {
1483
+ routes.push({
1484
+ method: "GET",
1485
+ pattern: ["rcp", "manifest"],
1486
+ handler: rcpManifestRoute,
1487
+ requiresAuth: false
1488
+ });
1489
+ }
1438
1490
  const mode = resolveMode(options);
1439
1491
  const heartbeatIntervalMs = options.heartbeatIntervalMs ?? 15e3;
1440
1492
  const runGraceMs = options.runGraceMs ?? DEFAULT_RUN_GRACE_MS;
@@ -1600,7 +1652,9 @@ function createRuntime(options) {
1600
1652
  heartbeatIntervalMs,
1601
1653
  runs,
1602
1654
  capabilities,
1603
- logger: routeLogger
1655
+ logger: routeLogger,
1656
+ restToolsManifest: options.restToolsManifest,
1657
+ rcpManifest: options.rcpManifest
1604
1658
  });
1605
1659
  const durationMs = Date.now() - startMs;
1606
1660
  logger.info("handle succeeded", {