@brazosd/node 0.1.1 → 0.1.3

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.
Files changed (6) hide show
  1. package/README.md +77 -1
  2. package/browser.d.ts +7631 -0
  3. package/browser.js +11233 -0
  4. package/index.d.ts +1133 -68
  5. package/index.js +2069 -114
  6. package/package.json +12 -2
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Brazosd Node.js SDK
2
2
 
3
- Node.js 22+ 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:
@@ -85,6 +121,46 @@ const client = createClient({
85
121
 
86
122
  Each client keeps its own URL, credential provider and request configuration. Concurrent clients do not share global authentication state. Public operations work without credentials when `apiUrl` is supplied. A schema-defined `Authorization` parameter, when present, takes precedence over the client's credential provider.
87
123
 
124
+ ## Sign in with Brazosd
125
+
126
+ SSO requires `@brazosd/node` 0.1.2 or later. `createSSO()` supports
127
+ `org-user` (same-organization user API credentials) and
128
+ `identity` (an identity JWT for users from any organization):
129
+
130
+ ```js
131
+ import { createSSO } from '@brazosd/node';
132
+
133
+ const sso = createSSO({
134
+ appId: process.env.BRAZOSD_APP_ID,
135
+ redirectUri: 'https://your-app.example/auth/brazosd/callback',
136
+ loginSecret: process.env.SSO_LOGIN_SECRET, // 32 random bytes as base64url
137
+ });
138
+ const { authorizationUrl, setCookie } = await sso.beginLogin('identity');
139
+ // Send setCookie, then redirect to authorizationUrl.
140
+ // On the registered callback:
141
+ // const { tokens, identity, clearCookie } = await sso.completeLogin(url, cookie);
142
+ ```
143
+
144
+ The SDK binds the browser transaction with an encrypted HttpOnly cookie, state
145
+ and PKCE. Service credentials remain on the app server. Store the verified
146
+ identity or user credentials in your own server session and send an opaque
147
+ session cookie to the browser. Identity JWTs contain `account_id`, `org_id`,
148
+ `user_id` and `sub=String(account_id)`; `(iss, sub)` is the recommended identity
149
+ key. They cannot call Brazosd APIs or refresh API credentials.
150
+
151
+ `sso.userClient({getTokens, saveTokens})` refreshes org-user credentials and
152
+ keeps each user's identity isolated. Shared session stores must compare-and-swap
153
+ updates using the `expectedRefreshToken` supplied to `saveTokens`. Call
154
+ `sso.revoke(tokens)` on logout and delete the app session. No failures fall back
155
+ to service-user permissions.
156
+
157
+ JWT verification uses strict issuer/audience/type/signature/expiry checks and
158
+ memory plus SQLite JWKS caching. The default cache is
159
+ `~/.cache/brazosd-sso/jwks.sqlite`; supply a `SQLiteSSOKeyCache` or `SSOKeyCache`
160
+ adapter for other storage. See the [SSO integration guide](../../docs/api/sso.md)
161
+ for callbacks, session lifecycle, private deployments and complete examples.
162
+ Install or update with `npm install @brazosd/node@^0.1.2`.
163
+
88
164
  ## Errors and cancellation
89
165
 
90
166
  API errors throw `BrazosdError` with `status` and a bounded response `body`. Handle permission errors, conflicts and throttling explicitly. Generated calls return a `CancelablePromise`: call `.cancel()` before completion to abort the HTTP request. Cancellation rejects with `CancelError`. A client-wide `signal` is also supported; cancel a returned stream through its `Response.body`.