@baobox/sdk 0.1.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/LICENSE +21 -0
- package/README.md +125 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +18 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +210 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +116 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bright Qi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# @baobox/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript HTTP client for [Baobox](https://baobox.au) — an AI integration platform providing an agent runtime, eval engine, and observability trail.
|
|
4
|
+
|
|
5
|
+
This package is a thin wrapper around Baobox's REST API. It has zero business logic — all intelligence lives server-side. Making it public removes friction for partners and third-party users while keeping the runtime closed.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @baobox/sdk
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @baobox/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires Node.js 18+ (relies on native `fetch`).
|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { BaoboxClient } from "@baobox/sdk";
|
|
21
|
+
|
|
22
|
+
const sb = new BaoboxClient({
|
|
23
|
+
endpoint: "https://baobox-jv1.example.workers.dev",
|
|
24
|
+
apiKey: process.env.BAOBOX_API_KEY!,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const res = await sb.chat({
|
|
28
|
+
skillId: "sk_document_chaser",
|
|
29
|
+
message: "Review cli_01 and take whatever action is needed.",
|
|
30
|
+
sessionId: "ses_cli_01",
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
console.log(res.response); // "Sent chase email for bank_statement, payroll..."
|
|
34
|
+
console.log(res.meta.requestId); // "req_abc123" — matches server log
|
|
35
|
+
console.log(res.meta.trace); // [{ toolName, input, output, latencyMs }, ...]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## API surface
|
|
39
|
+
|
|
40
|
+
### Chat
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
const res = await sb.chat({
|
|
44
|
+
skillId: "sk_chase",
|
|
45
|
+
message: "...",
|
|
46
|
+
sessionId: "ses_1", // optional
|
|
47
|
+
metadata: { source: "kanban" }, // optional, forwarded to trace
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Returns `{ response, usage: { inputTokens, outputTokens }, sessionId, meta }` where `meta` carries `requestId`, `latencyMs`, `model`, and an optional `trace` array.
|
|
52
|
+
|
|
53
|
+
### Sessions
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
const session = await sb.sessions.create({ skillId: "sk_chase" });
|
|
57
|
+
const history = await sb.sessions.messages(session.id);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Admin (requires admin token)
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
await sb.admin.skills.upsert({
|
|
64
|
+
id: "sk_chase",
|
|
65
|
+
name: "Document Chaser",
|
|
66
|
+
systemPrompt: "...",
|
|
67
|
+
model: "MiniMax-M2.7",
|
|
68
|
+
tools: ["lookup_client_docs", "send_client_email"],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
await sb.admin.tools.upsert({
|
|
72
|
+
name: "lookup_client_docs",
|
|
73
|
+
description: "...",
|
|
74
|
+
inputSchema: { type: "object", properties: { /* ... */ } },
|
|
75
|
+
handlerType: "http",
|
|
76
|
+
handlerConfig: { url: "https://backend.example.com/tools/lookup", /* ... */ },
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Events (trace)
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const events = await sb.events.list({ sessionId: "ses_1", limit: 50 });
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Error handling
|
|
87
|
+
|
|
88
|
+
Every non-2xx response throws `BaoboxError`:
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { BaoboxError } from "@baobox/sdk";
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
await sb.chat({ skillId: "sk_missing", message: "..." });
|
|
95
|
+
} catch (err) {
|
|
96
|
+
if (err instanceof BaoboxError) {
|
|
97
|
+
console.error(err.status); // 404
|
|
98
|
+
console.error(err.code); // "SKILL_NOT_FOUND"
|
|
99
|
+
console.error(err.requestId); // server-side request id for log correlation
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Network failures surface as `BaoboxError` with `status: 0` and `code: "NETWORK"`; timeouts as `code: "TIMEOUT"`.
|
|
105
|
+
|
|
106
|
+
## Configuration
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
new BaoboxClient({
|
|
110
|
+
endpoint: "...", // required — Baobox worker URL
|
|
111
|
+
apiKey: "...", // required
|
|
112
|
+
orgId: "firm_a", // optional, observability tag
|
|
113
|
+
fetch: myFetch, // optional, injects custom fetch (tests / edge runtimes)
|
|
114
|
+
timeoutMs: 30_000, // optional, default 30s. Set 0 to disable.
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
MIT. See [LICENSE](./LICENSE).
|
|
121
|
+
|
|
122
|
+
## Related
|
|
123
|
+
|
|
124
|
+
- Tech Arch §4 — full SDK design rationale (Baobox internal doc)
|
|
125
|
+
- [Adoptive Co](https://adoptive.co) — consultancy using Baobox as a delivery tool
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class BaoboxError extends Error {
|
|
2
|
+
readonly status: number;
|
|
3
|
+
readonly code: string;
|
|
4
|
+
readonly requestId: string | null;
|
|
5
|
+
readonly body: unknown;
|
|
6
|
+
constructor(status: number, code: string, message: string, requestId: string | null, body: unknown);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAGA,qBAAa,WAAY,SAAQ,KAAK;IACpC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,SAAgB,IAAI,EAAE,OAAO,CAAC;gBAG5B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,IAAI,EAAE,OAAO;CAShB"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// SDK-specific error class. Thrown for any non-2xx response; carries the
|
|
2
|
+
// HTTP status, the server's error code + message when available, and the
|
|
3
|
+
// Baobox request_id so callers can correlate with server logs.
|
|
4
|
+
export class BaoboxError extends Error {
|
|
5
|
+
status;
|
|
6
|
+
code;
|
|
7
|
+
requestId;
|
|
8
|
+
body;
|
|
9
|
+
constructor(status, code, message, requestId, body) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "BaoboxError";
|
|
12
|
+
this.status = status;
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.requestId = requestId;
|
|
15
|
+
this.body = body;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,yEAAyE;AACzE,+DAA+D;AAC/D,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpB,MAAM,CAAS;IACf,IAAI,CAAS;IACb,SAAS,CAAgB;IACzB,IAAI,CAAU;IAE9B,YACE,MAAc,EACd,IAAY,EACZ,OAAe,EACf,SAAwB,EACxB,IAAa;QAEb,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ChatRequest, ChatResponse, Event, EventListRequest, Session, SessionMessage, Skill, BaoboxClientOptions, SkillUpsertRequest, Tool, ToolUpsertRequest } from "./types.js";
|
|
2
|
+
export { BaoboxError } from "./errors.js";
|
|
3
|
+
export type * from "./types.js";
|
|
4
|
+
export declare class BaoboxClient {
|
|
5
|
+
private readonly endpoint;
|
|
6
|
+
private readonly apiKey;
|
|
7
|
+
private readonly fetch;
|
|
8
|
+
private readonly timeoutMs;
|
|
9
|
+
readonly admin: {
|
|
10
|
+
skills: {
|
|
11
|
+
upsert: (req: SkillUpsertRequest) => Promise<Skill>;
|
|
12
|
+
};
|
|
13
|
+
tools: {
|
|
14
|
+
upsert: (req: ToolUpsertRequest) => Promise<Tool>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
readonly sessions: {
|
|
18
|
+
create: (req: {
|
|
19
|
+
skillId: string;
|
|
20
|
+
}) => Promise<Session>;
|
|
21
|
+
messages: (sessionId: string) => Promise<SessionMessage[]>;
|
|
22
|
+
};
|
|
23
|
+
readonly events: {
|
|
24
|
+
list: (req: EventListRequest) => Promise<Event[]>;
|
|
25
|
+
};
|
|
26
|
+
constructor(opts: BaoboxClientOptions);
|
|
27
|
+
chat(req: ChatRequest): Promise<ChatResponse>;
|
|
28
|
+
private createSession;
|
|
29
|
+
private listMessages;
|
|
30
|
+
private upsertSkill;
|
|
31
|
+
private upsertTool;
|
|
32
|
+
private listEvents;
|
|
33
|
+
private request;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],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UAAU;YAkCV,OAAO;CAoFtB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// @baobox/sdk — thin HTTP client for the Baobox runtime.
|
|
2
|
+
// No business logic here — everything smart lives server-side. This file
|
|
3
|
+
// is ~300 lines on purpose; if it grows past ~500, something that belongs
|
|
4
|
+
// in the runtime has leaked out.
|
|
5
|
+
import { BaoboxError } from "./errors.js";
|
|
6
|
+
export { BaoboxError } from "./errors.js";
|
|
7
|
+
export class BaoboxClient {
|
|
8
|
+
endpoint;
|
|
9
|
+
apiKey;
|
|
10
|
+
fetch;
|
|
11
|
+
timeoutMs;
|
|
12
|
+
// `admin` and `events` are pseudo-namespaces — just method bundles so
|
|
13
|
+
// call sites read as `sb.admin.skills.upsert(...)` rather than a flat
|
|
14
|
+
// `sb.upsertSkill(...)`. Matches Tech Arch §4.2.
|
|
15
|
+
admin;
|
|
16
|
+
sessions;
|
|
17
|
+
events;
|
|
18
|
+
constructor(opts) {
|
|
19
|
+
if (!opts.endpoint)
|
|
20
|
+
throw new Error("BaoboxClient: endpoint required");
|
|
21
|
+
if (!opts.apiKey)
|
|
22
|
+
throw new Error("BaoboxClient: apiKey required");
|
|
23
|
+
this.endpoint = opts.endpoint.replace(/\/+$/, "");
|
|
24
|
+
this.apiKey = opts.apiKey;
|
|
25
|
+
this.fetch = opts.fetch ?? globalThis.fetch;
|
|
26
|
+
this.timeoutMs = opts.timeoutMs ?? 30_000;
|
|
27
|
+
this.admin = {
|
|
28
|
+
skills: {
|
|
29
|
+
upsert: (req) => this.upsertSkill(req),
|
|
30
|
+
},
|
|
31
|
+
tools: {
|
|
32
|
+
upsert: (req) => this.upsertTool(req),
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
this.sessions = {
|
|
36
|
+
create: (req) => this.createSession(req),
|
|
37
|
+
messages: (id) => this.listMessages(id),
|
|
38
|
+
};
|
|
39
|
+
this.events = {
|
|
40
|
+
list: (req) => this.listEvents(req),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// --- Chat (core) ---
|
|
44
|
+
async chat(req) {
|
|
45
|
+
const body = await this.request("POST", "/api/v1/chat", {
|
|
46
|
+
skill_id: req.skillId,
|
|
47
|
+
message: req.message,
|
|
48
|
+
session_id: req.sessionId,
|
|
49
|
+
metadata: req.metadata,
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
response: body.data.response,
|
|
53
|
+
usage: {
|
|
54
|
+
inputTokens: body.data.usage.input_tokens,
|
|
55
|
+
outputTokens: body.data.usage.output_tokens,
|
|
56
|
+
},
|
|
57
|
+
sessionId: body.data.session_id,
|
|
58
|
+
meta: body.meta,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// --- Sessions ---
|
|
62
|
+
async createSession(req) {
|
|
63
|
+
const body = await this.request("POST", "/api/v1/sessions", { skill_id: req.skillId });
|
|
64
|
+
return {
|
|
65
|
+
id: body.data.id,
|
|
66
|
+
skillId: body.data.skill_id,
|
|
67
|
+
tenantId: body.data.tenant_id,
|
|
68
|
+
createdAt: body.data.created_at,
|
|
69
|
+
updatedAt: body.data.updated_at,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async listMessages(sessionId) {
|
|
73
|
+
const body = await this.request("GET", `/api/v1/sessions/${encodeURIComponent(sessionId)}/messages`);
|
|
74
|
+
return body.data.map((m) => ({
|
|
75
|
+
id: m.id,
|
|
76
|
+
sessionId: m.session_id,
|
|
77
|
+
role: m.role,
|
|
78
|
+
content: m.content,
|
|
79
|
+
tokenCount: m.token_count,
|
|
80
|
+
createdAt: m.created_at,
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
// --- Admin: skills ---
|
|
84
|
+
async upsertSkill(req) {
|
|
85
|
+
const body = await this.request("POST", "/api/v1/admin/skills", {
|
|
86
|
+
id: req.id,
|
|
87
|
+
name: req.name,
|
|
88
|
+
description: req.description,
|
|
89
|
+
system_prompt: req.systemPrompt,
|
|
90
|
+
model: req.model,
|
|
91
|
+
temperature: req.temperature,
|
|
92
|
+
max_tokens: req.maxTokens,
|
|
93
|
+
tools: req.tools,
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
id: body.data.id,
|
|
97
|
+
name: body.data.name,
|
|
98
|
+
description: body.data.description,
|
|
99
|
+
systemPrompt: body.data.system_prompt,
|
|
100
|
+
model: body.data.model,
|
|
101
|
+
temperature: body.data.temperature,
|
|
102
|
+
maxTokens: body.data.max_tokens,
|
|
103
|
+
tenantId: body.data.tenant_id,
|
|
104
|
+
createdAt: body.data.created_at,
|
|
105
|
+
updatedAt: body.data.updated_at,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
// --- Admin: tools ---
|
|
109
|
+
async upsertTool(req) {
|
|
110
|
+
const body = await this.request("POST", "/api/v1/admin/tools", {
|
|
111
|
+
name: req.name,
|
|
112
|
+
description: req.description,
|
|
113
|
+
input_schema: req.inputSchema,
|
|
114
|
+
handler_type: req.handlerType,
|
|
115
|
+
handler_config: req.handlerConfig,
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
id: body.data.id,
|
|
119
|
+
name: body.data.name,
|
|
120
|
+
description: body.data.description,
|
|
121
|
+
inputSchema: body.data.input_schema,
|
|
122
|
+
handlerType: body.data.handler_type,
|
|
123
|
+
handlerConfig: body.data.handler_config,
|
|
124
|
+
createdAt: body.data.created_at,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
// --- Events ---
|
|
128
|
+
async listEvents(req) {
|
|
129
|
+
const qs = new URLSearchParams({ session_id: req.sessionId });
|
|
130
|
+
if (req.limit !== undefined)
|
|
131
|
+
qs.set("limit", String(req.limit));
|
|
132
|
+
if (req.after !== undefined)
|
|
133
|
+
qs.set("after", req.after);
|
|
134
|
+
const body = await this.request("GET", `/api/v1/events?${qs.toString()}`);
|
|
135
|
+
return body.data.map((e) => ({
|
|
136
|
+
id: e.id,
|
|
137
|
+
sessionId: e.session_id,
|
|
138
|
+
requestId: e.request_id,
|
|
139
|
+
eventType: e.event_type,
|
|
140
|
+
content: e.content,
|
|
141
|
+
metadata: safeParseJson(e.metadata),
|
|
142
|
+
tokenCount: e.token_count,
|
|
143
|
+
latencyMs: e.latency_ms,
|
|
144
|
+
parentEventId: e.parent_event_id,
|
|
145
|
+
createdAt: e.created_at,
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
// --- core request plumbing ---
|
|
149
|
+
async request(method, path, body) {
|
|
150
|
+
const url = `${this.endpoint}${path}`;
|
|
151
|
+
const controller = new AbortController();
|
|
152
|
+
const timer = this.timeoutMs > 0
|
|
153
|
+
? setTimeout(() => controller.abort(), this.timeoutMs)
|
|
154
|
+
: null;
|
|
155
|
+
let res;
|
|
156
|
+
try {
|
|
157
|
+
res = await this.fetch(url, {
|
|
158
|
+
method,
|
|
159
|
+
headers: {
|
|
160
|
+
authorization: `Bearer ${this.apiKey}`,
|
|
161
|
+
...(body !== undefined ? { "content-type": "application/json" } : {}),
|
|
162
|
+
},
|
|
163
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
164
|
+
signal: controller.signal,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
const isAbort = err instanceof DOMException && err.name === "AbortError";
|
|
169
|
+
throw new BaoboxError(0, isAbort ? "TIMEOUT" : "NETWORK", isAbort
|
|
170
|
+
? `Request to ${path} timed out after ${this.timeoutMs}ms`
|
|
171
|
+
: `Network error calling ${path}: ${String(err)}`, null, null);
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
if (timer)
|
|
175
|
+
clearTimeout(timer);
|
|
176
|
+
}
|
|
177
|
+
const text = await res.text();
|
|
178
|
+
const parsed = text.length ? safeParseJson(text) : {};
|
|
179
|
+
if (!res.ok) {
|
|
180
|
+
const errObj = parsed.error;
|
|
181
|
+
throw new BaoboxError(res.status, errObj?.code ?? "HTTP_ERROR", errObj?.message ?? res.statusText, errObj?.request_id ?? null, parsed);
|
|
182
|
+
}
|
|
183
|
+
const envelope = parsed;
|
|
184
|
+
return {
|
|
185
|
+
data: envelope.data,
|
|
186
|
+
meta: envelope.metadata
|
|
187
|
+
? {
|
|
188
|
+
requestId: envelope.metadata.request_id,
|
|
189
|
+
latencyMs: envelope.metadata.latency_ms,
|
|
190
|
+
model: envelope.metadata.model,
|
|
191
|
+
trace: envelope.metadata.trace?.map((t) => ({
|
|
192
|
+
toolName: t.tool_name,
|
|
193
|
+
input: t.input,
|
|
194
|
+
output: t.output,
|
|
195
|
+
latencyMs: t.latency_ms,
|
|
196
|
+
})),
|
|
197
|
+
}
|
|
198
|
+
: { requestId: "", latencyMs: 0 },
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function safeParseJson(text) {
|
|
203
|
+
try {
|
|
204
|
+
return JSON.parse(text);
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
return {};
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,yEAAyE;AACzE,0EAA0E;AAC1E,iCAAiC;AAEjC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAgB1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAK1C,MAAM,OAAO,YAAY;IACN,QAAQ,CAAS;IACjB,MAAM,CAAS;IACf,KAAK,CAAU;IACf,SAAS,CAAS;IAEnC,sEAAsE;IACtE,sEAAsE;IACtE,iDAAiD;IACjC,KAAK,CAGnB;IACc,QAAQ,CAGtB;IACc,MAAM,CAEpB;IAEF,YAAY,IAAyB;QACnC,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACvE,IAAI,CAAC,IAAI,CAAC,MAAM;Y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AK,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;wBAC1C,QAAQ,EAAE,CAAC,CAAC,SAAS;wBACrB,KAAK,EAAE,CAAC,CAAC,KAAK;wBACd,MAAM,EAAE,CAAC,CAAC,MAAM;wBAChB,SAAS,EAAE,CAAC,CAAC,UAAU;qBACxB,CAAC,CAAC;iBACJ;gBACH,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE;SACpC,CAAC;IACJ,CAAC;CACF;AAED,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
export type BaoboxClientOptions = {
|
|
2
|
+
/** Full URL to the Baobox worker, e.g. "https://baobox-jv1.brightq.workers.dev" */
|
|
3
|
+
endpoint: string;
|
|
4
|
+
/** API key issued by Baobox admin. Hashes to one `api_keys` row. */
|
|
5
|
+
apiKey: string;
|
|
6
|
+
/** Optional tag for observability — not sent over the wire yet. */
|
|
7
|
+
orgId?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Optional `fetch` override. Use this in tests to inject a mock, or in
|
|
10
|
+
* edge runtimes that ship a non-global fetch (old Node, workerd variants).
|
|
11
|
+
* Defaults to globalThis.fetch.
|
|
12
|
+
*/
|
|
13
|
+
fetch?: typeof globalThis.fetch;
|
|
14
|
+
/** Request timeout in ms. Default 30 000. Set to 0 to disable. */
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
};
|
|
17
|
+
export type ChatRequest = {
|
|
18
|
+
skillId: string;
|
|
19
|
+
message: string;
|
|
20
|
+
sessionId?: string;
|
|
21
|
+
metadata?: Record<string, unknown>;
|
|
22
|
+
};
|
|
23
|
+
export type ChatResponse = {
|
|
24
|
+
response: string;
|
|
25
|
+
usage: {
|
|
26
|
+
inputTokens: number;
|
|
27
|
+
outputTokens: number;
|
|
28
|
+
};
|
|
29
|
+
sessionId?: string;
|
|
30
|
+
/** Full Baobox metadata envelope: request_id, latency, tool trace. */
|
|
31
|
+
meta: ResponseMeta;
|
|
32
|
+
};
|
|
33
|
+
export type ResponseMeta = {
|
|
34
|
+
requestId: string;
|
|
35
|
+
latencyMs: number;
|
|
36
|
+
model?: string;
|
|
37
|
+
trace?: ToolTrace[];
|
|
38
|
+
};
|
|
39
|
+
export type ToolTrace = {
|
|
40
|
+
toolName: string;
|
|
41
|
+
input: Record<string, unknown>;
|
|
42
|
+
output: unknown;
|
|
43
|
+
latencyMs: number;
|
|
44
|
+
};
|
|
45
|
+
export type Session = {
|
|
46
|
+
id: string;
|
|
47
|
+
skillId: string;
|
|
48
|
+
tenantId: string | null;
|
|
49
|
+
createdAt: string;
|
|
50
|
+
updatedAt: string;
|
|
51
|
+
};
|
|
52
|
+
export type SessionMessage = {
|
|
53
|
+
id: number;
|
|
54
|
+
sessionId: string;
|
|
55
|
+
role: "user" | "assistant";
|
|
56
|
+
content: string;
|
|
57
|
+
tokenCount: number;
|
|
58
|
+
createdAt: string;
|
|
59
|
+
};
|
|
60
|
+
export type SkillUpsertRequest = {
|
|
61
|
+
id?: string;
|
|
62
|
+
name: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
systemPrompt: string;
|
|
65
|
+
model?: string;
|
|
66
|
+
temperature?: number;
|
|
67
|
+
maxTokens?: number;
|
|
68
|
+
tools?: string[];
|
|
69
|
+
};
|
|
70
|
+
export type Skill = {
|
|
71
|
+
id: string;
|
|
72
|
+
name: string;
|
|
73
|
+
description: string;
|
|
74
|
+
systemPrompt: string;
|
|
75
|
+
model: string;
|
|
76
|
+
temperature: number;
|
|
77
|
+
maxTokens: number;
|
|
78
|
+
tenantId: string | null;
|
|
79
|
+
createdAt: string;
|
|
80
|
+
updatedAt: string;
|
|
81
|
+
};
|
|
82
|
+
export type ToolUpsertRequest = {
|
|
83
|
+
name: string;
|
|
84
|
+
description: string;
|
|
85
|
+
inputSchema: Record<string, unknown>;
|
|
86
|
+
handlerType: "builtin" | "http";
|
|
87
|
+
handlerConfig: Record<string, unknown>;
|
|
88
|
+
};
|
|
89
|
+
export type Tool = {
|
|
90
|
+
id: string;
|
|
91
|
+
name: string;
|
|
92
|
+
description: string;
|
|
93
|
+
inputSchema: string;
|
|
94
|
+
handlerType: "builtin" | "http";
|
|
95
|
+
handlerConfig: string;
|
|
96
|
+
createdAt: string;
|
|
97
|
+
};
|
|
98
|
+
export type EventType = "user_message" | "assistant_message" | "system_message" | "llm_call_start" | "llm_call_end" | "tool_call" | "tool_result" | "error";
|
|
99
|
+
export type Event = {
|
|
100
|
+
id: string;
|
|
101
|
+
sessionId: string;
|
|
102
|
+
requestId: string | null;
|
|
103
|
+
eventType: EventType;
|
|
104
|
+
content: string | null;
|
|
105
|
+
metadata: Record<string, unknown>;
|
|
106
|
+
tokenCount: number;
|
|
107
|
+
latencyMs: number;
|
|
108
|
+
parentEventId: string | null;
|
|
109
|
+
createdAt: string;
|
|
110
|
+
};
|
|
111
|
+
export type EventListRequest = {
|
|
112
|
+
sessionId: string;
|
|
113
|
+
limit?: number;
|
|
114
|
+
after?: string;
|
|
115
|
+
};
|
|
116
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,mBAAmB,GAAG;IAChC,mFAAmF;IACnF,QAAQ,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,kEAAkE;IAClE,SAAS,CAAC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tB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAIF,MAAM,MAAM,SAAS,GACjB,cAAc,GACd,mBAAmB,GACnB,gBAAgB,GAChB,gBAAgB,GAChB,cAAc,GACd,WAAW,GACX,aAAa,GACb,OAAO,CAAC;AAEZ,MAAM,MAAM,KAAK,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,SAAS,CAAC;IACrB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Request/response shapes sent over the wire. Kept intentionally minimal —
|
|
2
|
+
// Phase 1 covers the fields both the backend and the demo UI actually use.
|
|
3
|
+
// Adding a field later is a non-breaking change; removing one is breaking.
|
|
4
|
+
export {};
|
|
5
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@baobox/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript HTTP client for Baobox — agent runtime + eval + observability.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Bright Qi <bright@adoptive.co>",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/baobox-ai/baobox-sdk.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/baobox-ai/baobox-sdk#readme",
|
|
12
|
+
"bugs": { "url": "https://github.com/baobox-ai/baobox-sdk/issues" },
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
24
|
+
"engines": { "node": ">=18" },
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc -p tsconfig.build.json",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"test:watch": "vitest",
|
|
30
|
+
"clean": "rm -rf dist",
|
|
31
|
+
"prepublishOnly": "npm run clean && npm run build && npm test"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^20.14.0",
|
|
35
|
+
"typescript": "^5.5.4",
|
|
36
|
+
"vitest": "^2.1.4"
|
|
37
|
+
},
|
|
38
|
+
"keywords": ["baobox", "ai", "agent", "llm", "tool-calling", "sdk"],
|
|
39
|
+
"publishConfig": { "access": "public" }
|
|
40
|
+
}
|