@stablebaseline/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 +119 -0
- package/dist/index.cjs +117 -0
- package/dist/index.d.cts +17842 -0
- package/dist/index.d.ts +17842 -0
- package/dist/index.js +90 -0
- package/openapi.json +19378 -0
- package/package.json +69 -0
- package/src/client.ts +164 -0
- package/src/index.ts +20 -0
- package/src/types.generated.ts +17745 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
var DEFAULT_BASE_URL = "https://api.stablebaseline.io/functions/v1/cloud-serve/api/v1";
|
|
3
|
+
function makeAuthHeader(opts) {
|
|
4
|
+
const token = opts.accessToken ?? opts.apiKey;
|
|
5
|
+
if (!token) return {};
|
|
6
|
+
return { Authorization: `Bearer ${token}` };
|
|
7
|
+
}
|
|
8
|
+
var StableBaselineToolError = class extends Error {
|
|
9
|
+
constructor(status, code, message, details) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.details = details;
|
|
14
|
+
this.name = "StableBaselineToolError";
|
|
15
|
+
}
|
|
16
|
+
status;
|
|
17
|
+
code;
|
|
18
|
+
details;
|
|
19
|
+
};
|
|
20
|
+
var StableBaseline = class {
|
|
21
|
+
fetch;
|
|
22
|
+
baseUrl;
|
|
23
|
+
authHeader;
|
|
24
|
+
signal;
|
|
25
|
+
/**
|
|
26
|
+
* Strongly-typed dispatch surface. Every entry is one of the 163 MCP tools.
|
|
27
|
+
*
|
|
28
|
+
* const orgs = await sb.tools.listOrganisations({});
|
|
29
|
+
* const doc = await sb.tools.createDocument({ folderId, title, cdmd });
|
|
30
|
+
*/
|
|
31
|
+
tools;
|
|
32
|
+
constructor(opts = {}) {
|
|
33
|
+
if (!opts.apiKey && !opts.accessToken) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
"StableBaseline: provide either `apiKey` (sta_*) or `accessToken` (OAuth Bearer)."
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
this.fetch = opts.fetch ?? globalThis.fetch.bind(globalThis);
|
|
39
|
+
this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
40
|
+
this.authHeader = makeAuthHeader(opts);
|
|
41
|
+
this.signal = opts.signal;
|
|
42
|
+
const self = this;
|
|
43
|
+
this.tools = new Proxy({}, {
|
|
44
|
+
get(_target, prop) {
|
|
45
|
+
if (typeof prop !== "string") return void 0;
|
|
46
|
+
return (input) => self.callTool(prop, input);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** Call a tool by name. Mainly an escape hatch — prefer `client.tools.<toolName>`. */
|
|
51
|
+
async callTool(name, input) {
|
|
52
|
+
const url = `${this.baseUrl}/tools/${encodeURIComponent(name)}`;
|
|
53
|
+
const res = await this.fetch(url, {
|
|
54
|
+
method: "POST",
|
|
55
|
+
headers: { "Content-Type": "application/json", ...this.authHeader },
|
|
56
|
+
body: JSON.stringify(input ?? {}),
|
|
57
|
+
signal: this.signal
|
|
58
|
+
});
|
|
59
|
+
if (!res.ok) {
|
|
60
|
+
let body = null;
|
|
61
|
+
try {
|
|
62
|
+
body = await res.json();
|
|
63
|
+
} catch {
|
|
64
|
+
}
|
|
65
|
+
const errEnvelope = body?.error ?? {};
|
|
66
|
+
throw new StableBaselineToolError(
|
|
67
|
+
res.status,
|
|
68
|
+
errEnvelope.code ?? `http_${res.status}`,
|
|
69
|
+
errEnvelope.message ?? `${res.status} ${res.statusText}`,
|
|
70
|
+
errEnvelope.details
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return res.json();
|
|
74
|
+
}
|
|
75
|
+
/** Fetch the live OpenAPI spec from the server. Useful for code generation. */
|
|
76
|
+
async openapi() {
|
|
77
|
+
const res = await this.fetch(`${this.baseUrl}/openapi.json`, { signal: this.signal });
|
|
78
|
+
if (!res.ok) throw new Error(`Failed to fetch OpenAPI: ${res.status}`);
|
|
79
|
+
return res.json();
|
|
80
|
+
}
|
|
81
|
+
/** Lightweight tool-catalogue discovery without parsing the full OpenAPI doc. */
|
|
82
|
+
async listTools() {
|
|
83
|
+
const res = await this.fetch(`${this.baseUrl}/tools`, { signal: this.signal });
|
|
84
|
+
if (!res.ok) throw new Error(`Failed to list tools: ${res.status}`);
|
|
85
|
+
return res.json();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
export {
|
|
89
|
+
StableBaseline
|
|
90
|
+
};
|