@nextclaw/bibo-api 0.0.0-stage → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NextClaw contributors
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 CHANGED
@@ -1,3 +1,13 @@
1
- # Temporary Holding Version
1
+ # @nextclaw/bibo-api
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Public Bibo space API client. Node 22+ and modern fetch runtimes. No model access is required.
4
+
5
+ ```js
6
+ import { BiboApi } from '@nextclaw/bibo-api';
7
+ const bibo = new BiboApi({ token: process.env.BIBO_API_TOKEN });
8
+ console.log(await bibo.me());
9
+ console.log(await bibo.call('task.list', { open: true }));
10
+ ```
11
+
12
+ Create a scoped token in Bibo → account menu → 接入与授权. Keep tokens private.
13
+ [Documentation](https://app.bibo.bot/docs/) · [Source](https://github.com/Peiiii/bibo)
@@ -0,0 +1,56 @@
1
+ export type * from "./space.types.js";
2
+ export type BiboScope = "space:read" | "space:write";
3
+ export type BiboIntegration = {
4
+ id: string;
5
+ name: string;
6
+ scopes: BiboScope[];
7
+ createdAt: string;
8
+ expiresAt: string;
9
+ lastUsedAt: string | null;
10
+ };
11
+ export type BiboIdentity = {
12
+ userId: string;
13
+ integration: BiboIntegration;
14
+ };
15
+ export type BiboActionDefinition = {
16
+ action: string;
17
+ domain: string;
18
+ description: string;
19
+ input: string;
20
+ readOnly: boolean;
21
+ };
22
+ export declare class BiboApiError extends Error {
23
+ readonly status: number;
24
+ readonly code: string;
25
+ readonly requestId?: string | undefined;
26
+ readonly retryAfter?: number | undefined;
27
+ constructor(message: string, status: number, code: string, requestId?: string | undefined, retryAfter?: number | undefined);
28
+ }
29
+ /** Origins only: credentials must never follow an arbitrary path or redirect. */
30
+ export declare function normalizeBiboEndpoint(value?: string): string;
31
+ export declare class BiboApi {
32
+ readonly endpoint: string;
33
+ private readonly token;
34
+ private readonly fetcher;
35
+ private readonly timeoutMs;
36
+ constructor(options: {
37
+ token: string;
38
+ endpoint?: string;
39
+ fetch?: typeof fetch;
40
+ timeoutMs?: number;
41
+ });
42
+ private response;
43
+ private json;
44
+ me: () => Promise<BiboIdentity>;
45
+ actions: () => Promise<BiboActionDefinition[]>;
46
+ call: <T = unknown>(action: string, input?: Record<string, unknown>) => Promise<T>;
47
+ revoke: () => Promise<{
48
+ revoked: string;
49
+ }>;
50
+ uploadAsset: (bytes: Uint8Array) => Promise<{
51
+ id: string;
52
+ url: string;
53
+ webUrl: string;
54
+ }>;
55
+ downloadAsset: (id: string) => Promise<Uint8Array>;
56
+ }
package/dist/index.js ADDED
@@ -0,0 +1,77 @@
1
+ export class BiboApiError extends Error {
2
+ status;
3
+ code;
4
+ requestId;
5
+ retryAfter;
6
+ constructor(message, status, code, requestId, retryAfter) {
7
+ super(message);
8
+ this.status = status;
9
+ this.code = code;
10
+ this.requestId = requestId;
11
+ this.retryAfter = retryAfter;
12
+ this.name = "BiboApiError";
13
+ }
14
+ }
15
+ /** Origins only: credentials must never follow an arbitrary path or redirect. */
16
+ export function normalizeBiboEndpoint(value = "https://app.bibo.bot") {
17
+ const url = new URL(value);
18
+ const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
19
+ if ((url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) || url.username || url.password
20
+ || url.search || url.hash || (url.pathname !== "/" && url.pathname !== "")) {
21
+ throw new Error("Endpoint must be an HTTPS origin (HTTP is allowed only on loopback).");
22
+ }
23
+ return url.origin;
24
+ }
25
+ export class BiboApi {
26
+ endpoint;
27
+ token;
28
+ fetcher;
29
+ timeoutMs;
30
+ constructor(options) {
31
+ this.endpoint = normalizeBiboEndpoint(options.endpoint);
32
+ if (!options.token || /\s/.test(options.token))
33
+ throw new Error("A Bibo access token is required.");
34
+ this.token = options.token;
35
+ this.fetcher = options.fetch ?? globalThis.fetch.bind(globalThis);
36
+ this.timeoutMs = options.timeoutMs ?? 30_000;
37
+ }
38
+ async response(path, init = {}) {
39
+ let response;
40
+ try {
41
+ response = await this.fetcher(`${this.endpoint}/api/v1/${path}`, {
42
+ ...init, redirect: "error", credentials: "omit",
43
+ signal: init.signal ?? AbortSignal.timeout(this.timeoutMs),
44
+ headers: { ...Object.fromEntries(new Headers(init.headers)), authorization: `Bearer ${this.token}` },
45
+ });
46
+ }
47
+ catch {
48
+ throw new BiboApiError("Could not reach Bibo. Check the endpoint and connection.", 0, "NETWORK_ERROR");
49
+ }
50
+ if (!response.ok) {
51
+ const value = await response.json().catch(() => null);
52
+ throw new BiboApiError(value?.error?.message ?? `Bibo request failed (${response.status}).`, response.status, value?.error?.code ?? "HTTP_ERROR", value?.requestId, Number(response.headers.get("retry-after")) || undefined);
53
+ }
54
+ return response;
55
+ }
56
+ async json(path, init) {
57
+ const response = await this.response(path, init);
58
+ const value = await response.json().catch(() => null);
59
+ if (!value || !("result" in value))
60
+ throw new BiboApiError("Invalid Bibo response.", response.status, "INVALID_RESPONSE");
61
+ return value.result;
62
+ }
63
+ me = () => this.json("me");
64
+ actions = () => this.json("actions");
65
+ call = (action, input = {}) => this.json("space", {
66
+ method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ action, input }),
67
+ });
68
+ revoke = () => this.json("auth/revoke", { method: "POST" });
69
+ uploadAsset = (bytes) => this.json("assets", {
70
+ method: "POST", headers: { "content-type": "application/octet-stream" }, body: new Uint8Array(bytes).buffer,
71
+ });
72
+ downloadAsset = async (id) => {
73
+ if (!/^[a-f0-9-]{36}$/.test(id))
74
+ throw new Error("Invalid asset ID.");
75
+ return new Uint8Array(await (await this.response(`assets/${id}`)).arrayBuffer());
76
+ };
77
+ }
@@ -0,0 +1,101 @@
1
+ export type BiboSpaceDomain = "projects" | "tasks" | "events" | "inbox" | "files" | "notes";
2
+ export type BiboProject = {
3
+ id: string;
4
+ name: string;
5
+ createdAt: string;
6
+ updatedAt: string;
7
+ version: number;
8
+ };
9
+ export type BiboSubtask = {
10
+ id: string;
11
+ title: string;
12
+ done: boolean;
13
+ };
14
+ export type BiboTask = {
15
+ id: string;
16
+ projectId: string | null;
17
+ title: string;
18
+ description: string;
19
+ status: "planned" | "active" | "done" | "cancelled";
20
+ priority: "low" | "medium" | "high";
21
+ startAt: string | null;
22
+ completedAt: string | null;
23
+ dueAt: string | null;
24
+ subtasks: BiboSubtask[];
25
+ source: {
26
+ kind: "user" | "agent";
27
+ sessionId?: string;
28
+ integrationId?: string;
29
+ };
30
+ createdAt: string;
31
+ updatedAt: string;
32
+ version: number;
33
+ };
34
+ export type BiboEvent = {
35
+ id: string;
36
+ title: string;
37
+ description: string;
38
+ startAt: string;
39
+ endAt: string;
40
+ source: {
41
+ kind: "user" | "agent";
42
+ sessionId?: string;
43
+ integrationId?: string;
44
+ };
45
+ createdAt: string;
46
+ updatedAt: string;
47
+ version: number;
48
+ };
49
+ export type BiboInboxItem = {
50
+ id: string;
51
+ kind: "agent" | "reminder" | "decision";
52
+ title: string;
53
+ body: string;
54
+ source: {
55
+ kind: "bibo" | "session" | "task" | "event" | "file";
56
+ id?: string;
57
+ };
58
+ createdAt: string;
59
+ updatedAt: string;
60
+ readAt: string | null;
61
+ resolvedAt: string | null;
62
+ version: number;
63
+ };
64
+ export type BiboFile = {
65
+ id: string;
66
+ path: string;
67
+ kind: "folder" | "note" | "document" | "artifact";
68
+ createdAt: string;
69
+ updatedAt: string;
70
+ version: number | string;
71
+ };
72
+ export type BiboFileDetail = BiboFile & {
73
+ content: string | null;
74
+ uri: string;
75
+ preview?: {
76
+ totalBytes: number;
77
+ readBytes: number;
78
+ truncated: boolean;
79
+ binary: boolean;
80
+ };
81
+ };
82
+ export type BiboOverview = {
83
+ inbox: BiboInboxItem[];
84
+ events: BiboEvent[];
85
+ tasks: BiboTask[];
86
+ notes: BiboFile[];
87
+ projects: Array<{
88
+ id: string;
89
+ name: string;
90
+ total: number;
91
+ done: number;
92
+ }>;
93
+ counts: {
94
+ unread: number;
95
+ activeTasks: number;
96
+ };
97
+ };
98
+ export type BiboSpaceAction = {
99
+ action: string;
100
+ input?: Record<string, unknown>;
101
+ };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@nextclaw/bibo-api",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Bibo public space API client and shared types",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Peiiii/bibo.git",
10
+ "directory": "packages/bibo-api"
11
+ },
12
+ "homepage": "https://app.bibo.bot/docs/",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "sideEffects": false,
25
+ "engines": {
26
+ "node": ">=22"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "devDependencies": {
32
+ "typescript": "^5.9.3",
33
+ "tsx": "^4.21.0",
34
+ "@types/node": "^24.13.3"
35
+ },
36
+ "scripts": {
37
+ "build": "tsc -p tsconfig.json",
38
+ "tsc": "tsc -p tsconfig.check.json --noEmit",
39
+ "test": "tsx --test src/*.test.ts"
40
+ }
6
41
  }