@personaai/runtime 0.7.1 → 0.8.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 +75 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -2
- package/dist/index.d.ts +32 -2
- package/dist/index.js +75 -50
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -189,6 +189,71 @@ 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
|
+
|
|
192
257
|
// src/runDriver.ts
|
|
193
258
|
var import_sdk3 = require("@personaai/sdk");
|
|
194
259
|
function formatSseFrame(event) {
|
|
@@ -647,55 +712,6 @@ function createResumeRoute(expectedKind) {
|
|
|
647
712
|
};
|
|
648
713
|
}
|
|
649
714
|
|
|
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
715
|
// src/routes/threads.ts
|
|
700
716
|
var listThreads = async (request, ctx) => {
|
|
701
717
|
const items = await ctx.client.threads.list({
|
|
@@ -1463,6 +1479,14 @@ function createRuntime(options) {
|
|
|
1463
1479
|
);
|
|
1464
1480
|
const capabilities = resolveCapabilities(options.capabilities);
|
|
1465
1481
|
const routes = buildRoutes(capabilities);
|
|
1482
|
+
if (options.restToolsManifest) {
|
|
1483
|
+
routes.push({
|
|
1484
|
+
method: "GET",
|
|
1485
|
+
pattern: ["rest-tools", "manifest"],
|
|
1486
|
+
handler: restToolsManifestRoute,
|
|
1487
|
+
requiresAuth: false
|
|
1488
|
+
});
|
|
1489
|
+
}
|
|
1466
1490
|
const mode = resolveMode(options);
|
|
1467
1491
|
const heartbeatIntervalMs = options.heartbeatIntervalMs ?? 15e3;
|
|
1468
1492
|
const runGraceMs = options.runGraceMs ?? DEFAULT_RUN_GRACE_MS;
|
|
@@ -1628,7 +1652,8 @@ function createRuntime(options) {
|
|
|
1628
1652
|
heartbeatIntervalMs,
|
|
1629
1653
|
runs,
|
|
1630
1654
|
capabilities,
|
|
1631
|
-
logger: routeLogger
|
|
1655
|
+
logger: routeLogger,
|
|
1656
|
+
restToolsManifest: options.restToolsManifest
|
|
1632
1657
|
});
|
|
1633
1658
|
const durationMs = Date.now() - startMs;
|
|
1634
1659
|
logger.info("handle succeeded", {
|