@rebyteai/agent-server 0.2.4 → 0.3.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 +1 -1
- package/dist/index.js +4 -4
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { Hono } from "hono";
|
|
3
3
|
import { HTTPException } from "hono/http-exception";
|
|
4
|
-
import
|
|
4
|
+
import OpenAI from "openai";
|
|
5
5
|
var maxFileSize = 5 * 1024 * 1024;
|
|
6
6
|
var invalid = (message) => new HTTPException(400, { message });
|
|
7
7
|
function createAgentApp(options) {
|
|
8
8
|
if (!options.apiKey || !options.agentId) throw new Error("API key and Agent ID are required");
|
|
9
|
-
const client = new
|
|
9
|
+
const client = new OpenAI({ apiKey: options.apiKey, baseURL: options.baseURL ?? "https://api.rebyte.ai/v1", maxRetries: 0 });
|
|
10
10
|
const sessions = client.beta.agents.sessions;
|
|
11
11
|
const app = new Hono();
|
|
12
12
|
async function owned(id) {
|
|
@@ -16,7 +16,7 @@ function createAgentApp(options) {
|
|
|
16
16
|
}
|
|
17
17
|
app.get("/api/health", (c) => c.json({ ok: true, api: "agents", agentId: options.agentId }));
|
|
18
18
|
app.post("/api/sessions", async (c) => {
|
|
19
|
-
const session = await sessions.create({ agent_id: options.agentId, environment:
|
|
19
|
+
const session = await sessions.create({ agent_id: options.agentId, environment: { type: "openai_hosted" } });
|
|
20
20
|
return c.json(session, 201);
|
|
21
21
|
});
|
|
22
22
|
app.get("/api/sessions/:id", async (c) => c.json(await owned(c.req.param("id"))));
|
|
@@ -111,7 +111,7 @@ function createAgentApp(options) {
|
|
|
111
111
|
app.onError((error, c) => {
|
|
112
112
|
if (error instanceof HTTPException) return c.json({ error: { message: error.message } }, error.status);
|
|
113
113
|
if (error instanceof SyntaxError) return c.json({ error: { message: "Invalid JSON" } }, 400);
|
|
114
|
-
if (error instanceof
|
|
114
|
+
if (error instanceof OpenAI.APIError) return c.json({ error: { message: error.message, code: error.code } }, error.status >= 400 && error.status < 600 ? error.status : 502);
|
|
115
115
|
console.error("Agents app request failed", error);
|
|
116
116
|
return c.json({ error: { message: "The example server failed" } }, 500);
|
|
117
117
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebyteai/agent-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"hono": "^4.9.9",
|
|
20
|
-
"
|
|
20
|
+
"openai": "7.15.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"tsup": "^8.5.0",
|