@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.cjs +104 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -2
- package/dist/index.d.ts +55 -2
- package/dist/index.js +104 -50
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -189,6 +189,91 @@ var healthRoute = async (_request, ctx) => {
|
|
|
189
189
|
};
|
|
190
190
|
};
|
|
191
191
|
|
|
192
|
+
// src/routeHelpers.ts
|
|
193
|
+
function json(status, value) {
|
|
194
|
+
return {
|
|
195
|
+
kind: "buffered",
|
|
196
|
+
status,
|
|
197
|
+
headers: { "content-type": "application/json" },
|
|
198
|
+
body: JSON.stringify(value)
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function noContent() {
|
|
202
|
+
return { kind: "buffered", status: 204, headers: {}, body: "" };
|
|
203
|
+
}
|
|
204
|
+
function requireParam(params, name) {
|
|
205
|
+
const value = params[name];
|
|
206
|
+
if (!value) {
|
|
207
|
+
throw new RuntimeHttpError(400, "INVALID_REQUEST", `"${name}" path parameter is required.`);
|
|
208
|
+
}
|
|
209
|
+
return value;
|
|
210
|
+
}
|
|
211
|
+
function requireQueryParam(query, name) {
|
|
212
|
+
const value = query[name];
|
|
213
|
+
if (!value) {
|
|
214
|
+
throw new RuntimeHttpError(400, "INVALID_REQUEST", `"${name}" query parameter is required.`);
|
|
215
|
+
}
|
|
216
|
+
return value;
|
|
217
|
+
}
|
|
218
|
+
function toInt(value) {
|
|
219
|
+
if (value === void 0) return void 0;
|
|
220
|
+
const parsed = Number.parseInt(value, 10);
|
|
221
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
222
|
+
}
|
|
223
|
+
function requireBodyObject(body) {
|
|
224
|
+
if (typeof body !== "object" || body === null) {
|
|
225
|
+
throw new RuntimeHttpError(400, "INVALID_REQUEST", "Request body must be a JSON object.");
|
|
226
|
+
}
|
|
227
|
+
return body;
|
|
228
|
+
}
|
|
229
|
+
function requireStringField(body, field) {
|
|
230
|
+
const value = body[field];
|
|
231
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
232
|
+
throw new RuntimeHttpError(
|
|
233
|
+
400,
|
|
234
|
+
"INVALID_REQUEST",
|
|
235
|
+
`"${field}" is required and must be a string.`
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
return value;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/routes/restToolsManifest.ts
|
|
242
|
+
var restToolsManifestRoute = async (request, ctx) => {
|
|
243
|
+
const manifest = ctx.restToolsManifest;
|
|
244
|
+
if (!manifest) {
|
|
245
|
+
throw new RuntimeHttpError(404, "NOT_FOUND", "No REST tools manifest is configured.");
|
|
246
|
+
}
|
|
247
|
+
if (manifest.authToken) {
|
|
248
|
+
const header = request.headers.authorization;
|
|
249
|
+
const expected = `Bearer ${manifest.authToken}`;
|
|
250
|
+
if (header !== expected) {
|
|
251
|
+
throw new RuntimeHttpError(401, "UNAUTHORIZED", "Invalid or missing manifest bearer token.");
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return json(200, { tools: manifest.tools });
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// src/routes/rcpManifest.ts
|
|
258
|
+
var rcpManifestRoute = async (request, ctx) => {
|
|
259
|
+
const manifest = ctx.rcpManifest;
|
|
260
|
+
if (!manifest) {
|
|
261
|
+
throw new RuntimeHttpError(404, "NOT_FOUND", "No RCP manifest is configured.");
|
|
262
|
+
}
|
|
263
|
+
if (manifest.authToken) {
|
|
264
|
+
const header = request.headers.authorization;
|
|
265
|
+
const expected = `Bearer ${manifest.authToken}`;
|
|
266
|
+
if (header !== expected) {
|
|
267
|
+
throw new RuntimeHttpError(401, "UNAUTHORIZED", "Invalid or missing manifest bearer token.");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return json(200, {
|
|
271
|
+
rcpVersion: "0.1",
|
|
272
|
+
auth: manifest.authToken ? { type: "header", header: "Authorization", scheme: "Bearer" } : { type: "none" },
|
|
273
|
+
tools: manifest.tools
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
|
|
192
277
|
// src/runDriver.ts
|
|
193
278
|
var import_sdk3 = require("@personaai/sdk");
|
|
194
279
|
function formatSseFrame(event) {
|
|
@@ -647,55 +732,6 @@ function createResumeRoute(expectedKind) {
|
|
|
647
732
|
};
|
|
648
733
|
}
|
|
649
734
|
|
|
650
|
-
// src/routeHelpers.ts
|
|
651
|
-
function json(status, value) {
|
|
652
|
-
return {
|
|
653
|
-
kind: "buffered",
|
|
654
|
-
status,
|
|
655
|
-
headers: { "content-type": "application/json" },
|
|
656
|
-
body: JSON.stringify(value)
|
|
657
|
-
};
|
|
658
|
-
}
|
|
659
|
-
function noContent() {
|
|
660
|
-
return { kind: "buffered", status: 204, headers: {}, body: "" };
|
|
661
|
-
}
|
|
662
|
-
function requireParam(params, name) {
|
|
663
|
-
const value = params[name];
|
|
664
|
-
if (!value) {
|
|
665
|
-
throw new RuntimeHttpError(400, "INVALID_REQUEST", `"${name}" path parameter is required.`);
|
|
666
|
-
}
|
|
667
|
-
return value;
|
|
668
|
-
}
|
|
669
|
-
function requireQueryParam(query, name) {
|
|
670
|
-
const value = query[name];
|
|
671
|
-
if (!value) {
|
|
672
|
-
throw new RuntimeHttpError(400, "INVALID_REQUEST", `"${name}" query parameter is required.`);
|
|
673
|
-
}
|
|
674
|
-
return value;
|
|
675
|
-
}
|
|
676
|
-
function toInt(value) {
|
|
677
|
-
if (value === void 0) return void 0;
|
|
678
|
-
const parsed = Number.parseInt(value, 10);
|
|
679
|
-
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
680
|
-
}
|
|
681
|
-
function requireBodyObject(body) {
|
|
682
|
-
if (typeof body !== "object" || body === null) {
|
|
683
|
-
throw new RuntimeHttpError(400, "INVALID_REQUEST", "Request body must be a JSON object.");
|
|
684
|
-
}
|
|
685
|
-
return body;
|
|
686
|
-
}
|
|
687
|
-
function requireStringField(body, field) {
|
|
688
|
-
const value = body[field];
|
|
689
|
-
if (typeof value !== "string" || value.length === 0) {
|
|
690
|
-
throw new RuntimeHttpError(
|
|
691
|
-
400,
|
|
692
|
-
"INVALID_REQUEST",
|
|
693
|
-
`"${field}" is required and must be a string.`
|
|
694
|
-
);
|
|
695
|
-
}
|
|
696
|
-
return value;
|
|
697
|
-
}
|
|
698
|
-
|
|
699
735
|
// src/routes/threads.ts
|
|
700
736
|
var listThreads = async (request, ctx) => {
|
|
701
737
|
const items = await ctx.client.threads.list({
|
|
@@ -1463,6 +1499,22 @@ function createRuntime(options) {
|
|
|
1463
1499
|
);
|
|
1464
1500
|
const capabilities = resolveCapabilities(options.capabilities);
|
|
1465
1501
|
const routes = buildRoutes(capabilities);
|
|
1502
|
+
if (options.restToolsManifest) {
|
|
1503
|
+
routes.push({
|
|
1504
|
+
method: "GET",
|
|
1505
|
+
pattern: ["rest-tools", "manifest"],
|
|
1506
|
+
handler: restToolsManifestRoute,
|
|
1507
|
+
requiresAuth: false
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
if (options.rcpManifest) {
|
|
1511
|
+
routes.push({
|
|
1512
|
+
method: "GET",
|
|
1513
|
+
pattern: ["rcp", "manifest"],
|
|
1514
|
+
handler: rcpManifestRoute,
|
|
1515
|
+
requiresAuth: false
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1466
1518
|
const mode = resolveMode(options);
|
|
1467
1519
|
const heartbeatIntervalMs = options.heartbeatIntervalMs ?? 15e3;
|
|
1468
1520
|
const runGraceMs = options.runGraceMs ?? DEFAULT_RUN_GRACE_MS;
|
|
@@ -1628,7 +1680,9 @@ function createRuntime(options) {
|
|
|
1628
1680
|
heartbeatIntervalMs,
|
|
1629
1681
|
runs,
|
|
1630
1682
|
capabilities,
|
|
1631
|
-
logger: routeLogger
|
|
1683
|
+
logger: routeLogger,
|
|
1684
|
+
restToolsManifest: options.restToolsManifest,
|
|
1685
|
+
rcpManifest: options.rcpManifest
|
|
1632
1686
|
});
|
|
1633
1687
|
const durationMs = Date.now() - startMs;
|
|
1634
1688
|
logger.info("handle succeeded", {
|