@brazosd/node 0.1.2 → 0.1.6
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 +38 -2
- package/browser.d.ts +8802 -0
- package/browser.js +13462 -0
- package/index.d.ts +2101 -152
- package/index.js +4141 -455
- package/package.json +11 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Brazosd Node.js SDK
|
|
2
2
|
|
|
3
|
-
Node.js 22.13+ ESM client generated from Brazosd's OpenAPI schemas, with automatic cloud-function identity and no runtime dependencies.
|
|
3
|
+
Node.js 22.13+ ESM client generated from Brazosd's OpenAPI schemas, with automatic cloud-function identity and no runtime dependencies. The `@brazosd/node/browser` entry supports browsers without Node filesystem or SSO dependencies.
|
|
4
4
|
|
|
5
5
|
Install the public npm package:
|
|
6
6
|
|
|
@@ -38,6 +38,42 @@ Methods use OpenAPI operation IDs and a single options object when parameters ar
|
|
|
38
38
|
|
|
39
39
|
All declared operations are generated, including Cloud Drive, sessions, snapshots, agents, organization management, cloud functions and SQLite databases. Availability is still determined by the caller's existing permissions and the endpoint's credential requirements.
|
|
40
40
|
|
|
41
|
+
## Client-side MCP
|
|
42
|
+
|
|
43
|
+
Register session tools using the [WebMCP](https://webmachinelearning.github.io/webmcp/) declaration style. This session bridge handles installation, the existing event stream, reconnect recovery and result submission:
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
import { createClient } from '@brazosd/node/browser';
|
|
47
|
+
|
|
48
|
+
const client = createClient({
|
|
49
|
+
apiUrl: 'https://api.brazosd.com/api/v1',
|
|
50
|
+
credentials: async () => ({ accessToken: await getCurrentAccessToken() }),
|
|
51
|
+
});
|
|
52
|
+
const modelContext = client.clientMCP(sessionId, {
|
|
53
|
+
namespace: 'browser',
|
|
54
|
+
storage: window.localStorage, // Optional bounded receipt cache.
|
|
55
|
+
onError: error => console.error(error),
|
|
56
|
+
});
|
|
57
|
+
const lifetime = new AbortController();
|
|
58
|
+
await modelContext.registerTool({
|
|
59
|
+
name: 'read_selection',
|
|
60
|
+
description: 'Read the browser selection',
|
|
61
|
+
inputSchema: { type: 'object', properties: {} },
|
|
62
|
+
execute() {
|
|
63
|
+
return { selection: window.getSelection()?.toString() ?? '' };
|
|
64
|
+
},
|
|
65
|
+
}, { signal: lifetime.signal });
|
|
66
|
+
await modelContext.connect();
|
|
67
|
+
// lifetime.abort(); // Unregister this tool when it is no longer available.
|
|
68
|
+
// modelContext.close(); // Stop communication; installations survive page refresh.
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Supply the current session owner's access token through your application's credential provider. On refresh, register callbacks before connecting. `registerTool()` accepts JSON return values and wraps them as MCP results; explicit MCP `content` results also work. Aborting a registration signal cancels its active callback signals and asynchronously removes the tool. Cleanup failures reach `onError`. Client MCPs bypass Agent tool and MCP whitelists. Missing callbacks and callback errors become error tool results. Sequential execution follows server `tool_execution_start` events.
|
|
72
|
+
|
|
73
|
+
The SDK provides a session-bound bridge with WebMCP-style declarations and lifecycle, independent of native browser WebMCP support. `namespace` defaults to `browser`. Duplicate names on one bridge are rejected; a fresh bridge can register the same definitions idempotently after refresh. `install(namespace, tools)` remains available for atomically replacing a whole set of MCP callbacks, and `uninstall(namespace)` removes that installation.
|
|
74
|
+
|
|
75
|
+
Callbacks receive `sessionId`, `runId`, `toolCallId`, `toolName`, `signal`, and a stable `idempotencyKey`. Side effects must use business-level idempotency across refresh and multiple tabs. Submission retries reuse the computed result; a 409 stops retries. Acceptance confirms storage, not model consumption near timeout. See the [client-side MCP guide](../../docs/api/client-side-mcp.md) for APIs, lifecycle and delivery semantics.
|
|
76
|
+
|
|
41
77
|
## Cloud Drive
|
|
42
78
|
|
|
43
79
|
Cloud Drive uses the generated operations directly:
|
|
@@ -70,7 +106,7 @@ For large uploads, use Node's `openAsBlob` to construct a file-backed `File`, an
|
|
|
70
106
|
|
|
71
107
|
## Authentication and permissions
|
|
72
108
|
|
|
73
|
-
Inside a cloud function, `createClient()` reads the access token and internal API URL from `/run/brazosd/identity/credentials.json`. The trusted runtime refreshes credentials and atomically replaces that file. Reads are coalesced and cached for at most one second, bounded by credential expiry. The SDK never reads a refresh token.
|
|
109
|
+
Inside a cloud function, `createClient()` reads the access token and internal API URL from `/run/brazosd/identity/credentials.json`. The trusted runtime refreshes credentials and atomically replaces that file. Reads are coalesced and cached for at most one second, bounded by credential expiry. The SDK never reads a refresh token. The runtime supplies the credentials outside the deployment directory after a warm-pool instance is assigned to a function.
|
|
74
110
|
|
|
75
111
|
A service user follows the same API authorization rules as other organization users. Enterprise service users start without grants; use existing user/group policies to grant API and resource access. Changes apply to subsequent API requests. Deactivating the service user or retiring the instance revokes access, including Anclax APIs. Creating a client does not grant permissions.
|
|
76
112
|
|