@kinqs/brainrouter-sdk 0.3.4

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 ADDED
@@ -0,0 +1,17 @@
1
+ # @kinqs/brainrouter-sdk
2
+
3
+ Typed client helpers for talking to a [BrainRouter](https://github.com/kinqsradiollc/BrainRouter) MCP server from your own Node or browser code. Used internally by the [`@kinqs/brainrouter-cli`](https://www.npmjs.com/package/@kinqs/brainrouter-cli) and the BrainRouter dashboard.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @kinqs/brainrouter-sdk @kinqs/brainrouter-types
9
+ ```
10
+
11
+ ## Status
12
+
13
+ Pre-1.0 — the SDK surface is shaped around the BrainRouter monorepo's own consumers (CLI, dashboard). Stable enough to use; expect minor renames before 1.0.
14
+
15
+ ## License
16
+
17
+ MIT
@@ -0,0 +1,114 @@
1
+ import { AddEvidenceRequest, AddEvidenceResponse, ContradictionsResponse, CursorPaginationParams, DiagnosticsBundle, EvidenceResponse, ExplainRecallRequest, HookRegisterRequest, HookRegisterResponse, HookStatusParams, HookStatusResponse, ImportMemoriesRequest, MeResponse, MemoriesResponse, MemoryEvidenceByRecordResponse, MemoryStatsResponse, MemoryWithEvidenceResponse, OperationsResponse, PublicUserRecord, ScenesResponse, SigninRequest, SigninResponse, SignupRequest, SignupResponse, UpdateMemoryRequest, WorkingContextRequest, WorkingContextResponse, WorkingOffloadRequest, WorkingOffloadResponse, WorkingResetRequest, WorkingResetResponse, ActiveSessionsResponse, CoreIdentityRecord, SkillActivationsResponse } from "@kinqs/brainrouter-types";
2
+ export declare class BrainRouterApiError extends Error {
3
+ status: number;
4
+ body: string;
5
+ constructor(status: number, message: string, body: string);
6
+ }
7
+ export declare class BrainRouterClient {
8
+ private baseUrl;
9
+ private apiKey;
10
+ private token;
11
+ constructor(baseUrl?: string, apiKey?: string, token?: string);
12
+ withApiKey(apiKey: string): BrainRouterClient;
13
+ withToken(token: string): BrainRouterClient;
14
+ private headers;
15
+ private get;
16
+ private post;
17
+ private put;
18
+ private patch;
19
+ private deleteReq;
20
+ private deleteWithBody;
21
+ private toError;
22
+ signIn(body: SigninRequest): Promise<SigninResponse>;
23
+ signUp(body: SignupRequest): Promise<SignupResponse>;
24
+ me(): Promise<MeResponse>;
25
+ updateMe(body: {
26
+ displayName: string;
27
+ }): Promise<{
28
+ success: boolean;
29
+ }>;
30
+ rotateApiKey(): Promise<{
31
+ apiKey: string;
32
+ }>;
33
+ getUsers(params?: CursorPaginationParams): Promise<{
34
+ users: PublicUserRecord[];
35
+ nextCursor: string | null;
36
+ limit: number;
37
+ hasMore: boolean;
38
+ }>;
39
+ createUser(payload: {
40
+ userId: string;
41
+ displayName?: string;
42
+ isAdmin?: boolean;
43
+ }): Promise<{
44
+ user: PublicUserRecord;
45
+ }>;
46
+ updateUserStatus(userId: string, status: "active" | "disabled"): Promise<{
47
+ success: boolean;
48
+ }>;
49
+ resetUserApiKey(userId: string): Promise<{
50
+ apiKey: string;
51
+ }>;
52
+ deleteUser(id: string): Promise<{
53
+ success: boolean;
54
+ }>;
55
+ getStats(): Promise<MemoryStatsResponse>;
56
+ getSkillActivations(): Promise<SkillActivationsResponse>;
57
+ getDiagnostics(userId?: string): Promise<DiagnosticsBundle>;
58
+ getMemories(params?: CursorPaginationParams & {
59
+ query?: string;
60
+ type?: string;
61
+ scene?: string;
62
+ skill?: string;
63
+ archived?: boolean;
64
+ }): Promise<MemoriesResponse>;
65
+ archiveMemory(id: string): Promise<{
66
+ success: boolean;
67
+ }>;
68
+ governanceDeleteMemory(id: string, reason: string): Promise<{
69
+ success: boolean;
70
+ }>;
71
+ updateMemory(id: string, body: UpdateMemoryRequest): Promise<MemoryWithEvidenceResponse>;
72
+ addEvidence(recordId: string, body: AddEvidenceRequest): Promise<AddEvidenceResponse>;
73
+ exportMemories(): Promise<import("@kinqs/brainrouter-types").MemoryExport>;
74
+ importMemories(body: ImportMemoriesRequest): Promise<import("@kinqs/brainrouter-types").ImportResult>;
75
+ getScenes(params?: CursorPaginationParams): Promise<ScenesResponse>;
76
+ deleteScene(id: string): Promise<{
77
+ success: boolean;
78
+ }>;
79
+ getPersona(): Promise<{
80
+ persona: CoreIdentityRecord | null;
81
+ }>;
82
+ getContradictions(params?: CursorPaginationParams): Promise<ContradictionsResponse>;
83
+ resolveContradiction(id: string, status: "resolved" | "dismissed"): Promise<{
84
+ success: boolean;
85
+ }>;
86
+ /** Get the operations/audit log (timeline events). */
87
+ getOperations(params?: CursorPaginationParams & {
88
+ userId?: string;
89
+ operation?: string;
90
+ sessionKey?: string;
91
+ createdAfter?: string;
92
+ createdBefore?: string;
93
+ }): Promise<OperationsResponse>;
94
+ /** Get all evidence for a specific memory record. */
95
+ getEvidenceByRecord(recordId: string): Promise<MemoryEvidenceByRecordResponse>;
96
+ /** Get evidence, optionally filtered by recordId and kind. */
97
+ getEvidence(params?: CursorPaginationParams & {
98
+ userId?: string;
99
+ recordId?: string;
100
+ kind?: string;
101
+ }): Promise<EvidenceResponse>;
102
+ /** Get a memory with evidence by record ID. */
103
+ getMemory(recordId: string): Promise<MemoryWithEvidenceResponse>;
104
+ /** Explain a recall query — returns full pipeline breakdown + recallExplanation. */
105
+ explainRecall(body: ExplainRecallRequest): Promise<import("@kinqs/brainrouter-types").RecallResult>;
106
+ getWorkingContext(params: WorkingContextRequest): Promise<WorkingContextResponse>;
107
+ offloadWorkingPayload(body: WorkingOffloadRequest): Promise<WorkingOffloadResponse>;
108
+ resetWorkingMemory(body: WorkingResetRequest): Promise<WorkingResetResponse>;
109
+ getActiveSessions(params?: {
110
+ userId?: string;
111
+ }): Promise<ActiveSessionsResponse>;
112
+ registerHook(body: HookRegisterRequest): Promise<HookRegisterResponse>;
113
+ getHookStatus(params?: HookStatusParams): Promise<HookStatusResponse>;
114
+ }
package/dist/client.js ADDED
@@ -0,0 +1,170 @@
1
+ export class BrainRouterApiError extends Error {
2
+ constructor(status, message, body) {
3
+ super(message);
4
+ this.status = status;
5
+ this.body = body;
6
+ this.name = "BrainRouterApiError";
7
+ }
8
+ }
9
+ export class BrainRouterClient {
10
+ constructor(baseUrl = "", apiKey = "", token = "") {
11
+ this.baseUrl = baseUrl;
12
+ this.apiKey = apiKey;
13
+ this.token = token;
14
+ }
15
+ withApiKey(apiKey) {
16
+ return new BrainRouterClient(this.baseUrl, apiKey, this.token);
17
+ }
18
+ withToken(token) {
19
+ return new BrainRouterClient(this.baseUrl, this.apiKey, token);
20
+ }
21
+ headers() {
22
+ if (this.token)
23
+ return { Authorization: `Bearer ${this.token}` };
24
+ if (this.apiKey)
25
+ return { Authorization: `Bearer ${this.apiKey}` };
26
+ return {};
27
+ }
28
+ async get(path, params) {
29
+ const query = params
30
+ ? new URLSearchParams(Object.entries(params)
31
+ .filter((entry) => {
32
+ const value = entry[1];
33
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
34
+ })
35
+ .map(([key, value]) => [key, String(value)])).toString()
36
+ : "";
37
+ const res = await fetch(`${this.baseUrl}${path}${query ? `?${query}` : ""}`, { headers: this.headers() });
38
+ if (!res.ok)
39
+ throw await this.toError(res);
40
+ return res.json();
41
+ }
42
+ async post(path, body) {
43
+ const res = await fetch(`${this.baseUrl}${path}`, {
44
+ method: "POST",
45
+ headers: { "Content-Type": "application/json", ...this.headers() },
46
+ body: JSON.stringify(body),
47
+ });
48
+ if (!res.ok)
49
+ throw await this.toError(res);
50
+ return res.json();
51
+ }
52
+ async put(path, body) {
53
+ const res = await fetch(`${this.baseUrl}${path}`, {
54
+ method: "PUT",
55
+ headers: { "Content-Type": "application/json", ...this.headers() },
56
+ body: JSON.stringify(body),
57
+ });
58
+ if (!res.ok)
59
+ throw await this.toError(res);
60
+ return res.json();
61
+ }
62
+ async patch(path, body) {
63
+ const res = await fetch(`${this.baseUrl}${path}`, {
64
+ method: "PATCH",
65
+ headers: { "Content-Type": "application/json", ...this.headers() },
66
+ body: JSON.stringify(body),
67
+ });
68
+ if (!res.ok)
69
+ throw await this.toError(res);
70
+ return res.json();
71
+ }
72
+ async deleteReq(path) {
73
+ const res = await fetch(`${this.baseUrl}${path}`, { method: "DELETE", headers: this.headers() });
74
+ if (!res.ok)
75
+ throw await this.toError(res);
76
+ return res.json();
77
+ }
78
+ async deleteWithBody(path, body) {
79
+ const res = await fetch(`${this.baseUrl}${path}`, {
80
+ method: "DELETE",
81
+ headers: { "Content-Type": "application/json", ...this.headers() },
82
+ body: JSON.stringify(body),
83
+ });
84
+ if (!res.ok)
85
+ throw await this.toError(res);
86
+ return res.json();
87
+ }
88
+ async toError(res) {
89
+ const body = await res.text();
90
+ let message = body || res.statusText;
91
+ try {
92
+ const parsed = JSON.parse(body);
93
+ if (typeof parsed.error === "string")
94
+ message = parsed.error;
95
+ }
96
+ catch {
97
+ // Keep raw text for non-JSON responses.
98
+ }
99
+ return new BrainRouterApiError(res.status, message, body);
100
+ }
101
+ // Auth Operations
102
+ signIn(body) { return this.post("/api/auth/signin", body); }
103
+ signUp(body) { return this.post("/api/auth/signup", body); }
104
+ me() { return this.get("/api/auth/me"); }
105
+ updateMe(body) { return this.put("/api/auth/me", body); }
106
+ rotateApiKey() { return this.post("/api/auth/rotate-key", {}); }
107
+ // Admin User Operations
108
+ getUsers(params) { return this.get("/api/users", params); }
109
+ createUser(payload) { return this.post("/api/users", payload); }
110
+ updateUserStatus(userId, status) { return this.put(`/api/users/${userId}/status`, { status }); }
111
+ resetUserApiKey(userId) { return this.post(`/api/users/${userId}/reset-key`, {}); }
112
+ deleteUser(id) { return this.deleteReq(`/api/users/${id}`); }
113
+ // Telemetry & L1/L2 Memory Operations
114
+ getStats() { return this.get("/api/stats"); }
115
+ getSkillActivations() { return this.get("/api/skills/activations"); }
116
+ getDiagnostics(userId) { return this.get("/api/governance/diagnostics", { userId }); }
117
+ getMemories(params) {
118
+ return this.get("/api/memories", params);
119
+ }
120
+ archiveMemory(id) { return this.deleteReq(`/api/memories/${id}`); }
121
+ governanceDeleteMemory(id, reason) { return this.deleteWithBody(`/api/memories/${id}`, { reason }); }
122
+ updateMemory(id, body) { return this.patch(`/api/memories/${id}`, body); }
123
+ addEvidence(recordId, body) { return this.post(`/api/memories/${recordId}/evidence`, body); }
124
+ exportMemories() { return this.get("/api/export"); }
125
+ importMemories(body) { return this.post("/api/import", body); }
126
+ getScenes(params) { return this.get("/api/scenes", params); }
127
+ deleteScene(id) { return this.deleteReq(`/api/scenes/${id}`); }
128
+ getPersona() { return this.get("/api/persona"); }
129
+ getContradictions(params) { return this.get("/api/contradictions", params); }
130
+ resolveContradiction(id, status) { return this.post(`/api/contradictions/${id}/resolve`, { status }); }
131
+ // Phase 3 — Observability & Recall Explainability
132
+ /** Get the operations/audit log (timeline events). */
133
+ getOperations(params) {
134
+ return this.get("/api/operations", params);
135
+ }
136
+ /** Get all evidence for a specific memory record. */
137
+ getEvidenceByRecord(recordId) {
138
+ return this.get(`/api/evidence/${recordId}`);
139
+ }
140
+ /** Get evidence, optionally filtered by recordId and kind. */
141
+ getEvidence(params) {
142
+ return this.get("/api/evidence", params);
143
+ }
144
+ /** Get a memory with evidence by record ID. */
145
+ getMemory(recordId) {
146
+ return this.get(`/api/memories/${recordId}`);
147
+ }
148
+ /** Explain a recall query — returns full pipeline breakdown + recallExplanation. */
149
+ explainRecall(body) {
150
+ return this.post("/api/recall/explain", body);
151
+ }
152
+ getWorkingContext(params) {
153
+ return this.get("/api/working/context", params);
154
+ }
155
+ offloadWorkingPayload(body) {
156
+ return this.post("/api/working/offload", body);
157
+ }
158
+ resetWorkingMemory(body) {
159
+ return this.post("/api/working/reset", body);
160
+ }
161
+ getActiveSessions(params) {
162
+ return this.get("/api/working/sessions", params);
163
+ }
164
+ registerHook(body) {
165
+ return this.post("/api/hooks/register", body);
166
+ }
167
+ getHookStatus(params) {
168
+ return this.get("/api/hooks/status", params);
169
+ }
170
+ }
@@ -0,0 +1 @@
1
+ export * from "./client.js";
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./client.js";
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@kinqs/brainrouter-sdk",
3
+ "version": "0.3.4",
4
+ "description": "BrainRouter SDK — typed client helpers for talking to a BrainRouter MCP server from your own Node/browser code.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc -p tsconfig.json",
13
+ "prepack": "npm run build"
14
+ },
15
+ "dependencies": {
16
+ "@kinqs/brainrouter-types": "^0.3.4"
17
+ },
18
+ "devDependencies": {
19
+ "typescript": "^5.5.4"
20
+ },
21
+ "keywords": [
22
+ "brainrouter",
23
+ "sdk",
24
+ "mcp",
25
+ "model-context-protocol",
26
+ "client",
27
+ "typescript"
28
+ ],
29
+ "license": "MIT",
30
+ "author": "BrainRouter contributors",
31
+ "homepage": "https://github.com/kinqsradiollc/BrainRouter#readme",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/kinqsradiollc/BrainRouter.git",
35
+ "directory": "packages/sdk"
36
+ },
37
+ "bugs": {
38
+ "url": "https://github.com/kinqsradiollc/BrainRouter/issues"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ }
43
+ }