@forg3t/sdk 0.1.3 → 0.1.5

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 CHANGED
@@ -1,63 +1,400 @@
1
- # @forg3t/sdk
2
-
3
- Official TypeScript SDK for the Forg3t Protocol. This SDK allows you to interact with the Forg3t Control Plane to manage projects, submit jobs, verify evidence, and handle webhooks.
4
-
5
- **[Forg3t.io](https://forg3t.io)** is the platform where you can manage your AI Unlearning operations, track compliance, and visualize evidence. This SDK enables you to integrate these capabilities directly into your applications.
6
-
7
- ## Installation
8
-
9
- ```bash
10
- npm install @forg3t/sdk
11
- # or
12
- yarn add @forg3t/sdk
13
- # or
14
- pnpm add @forg3t/sdk
15
- ```
16
-
17
- ## Quick Start
18
-
19
- Initialize the client with your project's API key. You can generate API keys from your [Forg3t Dashboard](https://forg3t.io/dashboard).
20
-
21
- ```typescript
22
- import { Forg3tClient } from '@forg3t/sdk';
23
-
24
- const client = new Forg3tClient({
25
- apiUrl: 'https://api.forg3t.io',
26
- apiKey: 'f3_sk_...',
27
- });
28
-
29
- async function main() {
30
- // Get Project Overview
31
- const project = await client.getProjectOverview('your-project-id');
32
- console.log('Project:', project);
33
-
34
- // Submit an Unlearning Job
35
- const job = await client.submitJob('your-project-id', {
36
- type: 'unlearning',
37
- parameters: {
38
- modelId: 'llama-2-7b',
39
- datasetId: 'copyrighted-books-subset'
40
- }
41
- });
42
- console.log('Unlearning Job Submitted:', job.id);
43
- }
44
-
45
- main().catch(console.error);
46
- ```
47
-
48
- ## Features
49
-
50
- - **AI Unlearning Operations**: Submit and track unlearning jobs programmatically.
51
- - **Verification Evidence**: Retrieve cryptographic proofs and PDF reports for audit trails.
52
- - **Project Management**: View project details and stats.
53
- - **API Key Management**: Create, rotate, and revoke API keys programmatically.
54
- - **Webhooks**: Manage and replay webhook deliveries for real-time integration.
55
-
56
- ## Documentation
57
-
58
- For comprehensive guides and API references, visit [docs.forg3t.io](https://docs.forg3t.io).
59
- To start unlearning your AI models, visit **[Forg3t.io](https://forg3t.io)**.
60
-
61
- ## License
62
-
63
- MIT
1
+ # @forg3t/sdk
2
+
3
+ Official TypeScript SDK for the Forg3t Protocol. This SDK allows you to interact with the Forg3t Control Plane to manage projects, submit jobs, verify evidence, and handle webhooks.
4
+
5
+ **[Forg3t.io](https://forg3t.io)** is the platform where you can manage your AI Unlearning operations, track compliance, and visualize evidence. This SDK enables you to integrate these capabilities directly into your applications.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @forg3t/sdk
11
+ # or
12
+ yarn add @forg3t/sdk
13
+ # or
14
+ pnpm add @forg3t/sdk
15
+ ```
16
+
17
+ ## Production Reality
18
+
19
+ This package is live and installable. It is not yet a fully self-serve enterprise onboarding product by itself.
20
+
21
+ Today, the truthful usage pattern is:
22
+
23
+ 1. Forg3t provisions or approves the tenant / project path.
24
+ 2. The customer receives a real project API key.
25
+ 3. The SDK connects to a real control-plane URL.
26
+ 4. Execution then depends on the architecture:
27
+ - API-only / retrieval-based systems use control-plane enforcement and evidence flows.
28
+ - Whitebox model changes require a customer-side whitebox worker path.
29
+
30
+ There is now also a live bearer-token bootstrap path for first-time tenant creation:
31
+
32
+ - `POST /v1/bootstrap/tenant`
33
+ - public hostname: `https://api.forg3t.io`
34
+ - auth mode: dashboard bearer token, not project API key
35
+
36
+ This closes the biggest admin-led onboarding gap. The published npm package now includes the bootstrap flow and request-creation surface, but the overall product is still not fully self-serve enterprise onboarding because tenant lifecycle cleanup, whitebox activation, and some runtime specialization paths remain operator-led.
37
+
38
+ ## Local Development
39
+ 1. **Build**: `npm run build`
40
+ 2. **Typecheck**: `node ../../node_modules/typescript/bin/tsc -p tsconfig.json --noEmit`
41
+ 3. **Examples**: `examples/whitebox-worker.ts` demonstrates customer-infra model editing.
42
+ 4. **Staging smoke**: `npm run smoke:staging` validates request -> job -> terminal status flow.
43
+
44
+ ### Customer Onboarding Smoke
45
+
46
+ Use this as the first real integration gate for a new signed-in customer session.
47
+ The production API hostname is:
48
+
49
+ ```bash
50
+ export FORG3T_API_URL=https://api.forg3t.io
51
+ export FORG3T_BEARER_TOKEN=eyJ...
52
+ ```
53
+
54
+ Then run the official onboarding smoke:
55
+
56
+ ```bash
57
+ npm run smoke:customer-onboarding
58
+ ```
59
+
60
+ This validates:
61
+ - bearer-token bootstrap
62
+ - project resolution
63
+ - API key creation
64
+ - unlearning request creation
65
+ - request detail fetch
66
+ - API key revoke
67
+ - job contract correctness
68
+ - first-customer path through the public API hostname
69
+
70
+ ### Cleanroom Release Smoke
71
+
72
+ For release verification from a clean temporary install:
73
+
74
+ ```bash
75
+ export FORG3T_ONBOARDING_SMOKE_EMAIL=onboarding-smoke@forg3t.io
76
+ export FORG3T_ONBOARDING_SMOKE_PASSWORD=...
77
+ export SUPABASE_ANON_KEY=...
78
+ npm run smoke:cleanroom
79
+ ```
80
+
81
+ This installs the package into a fresh temporary directory, runs bootstrap, creates a first request, fetches request detail, and revokes the temporary API key. It is the release-candidate gate we use before claiming the SDK package is ready to publish.
82
+
83
+ ### First-Time Tenant Bootstrap
84
+
85
+ If you are integrating from a signed-in dashboard or application session, instantiate the SDK with a bearer token and bootstrap the tenant path first:
86
+
87
+ ```typescript
88
+ import { Forg3tClient } from '@forg3t/sdk';
89
+
90
+ const client = new Forg3tClient({
91
+ apiUrl: 'https://api.forg3t.io',
92
+ bearerToken: process.env.FORG3T_BEARER_TOKEN,
93
+ });
94
+
95
+ async function main() {
96
+ const bootstrap = await client.bootstrapTenant({
97
+ tenantName: 'Northstar Bank',
98
+ projectName: 'Retail Banking Assistant',
99
+ integrationType: 'custom',
100
+ integrationName: 'Primary Banking Integration',
101
+ });
102
+
103
+ console.log({
104
+ created: bootstrap.created,
105
+ tenantId: bootstrap.tenant.id,
106
+ projectId: bootstrap.bootstrap.project.id,
107
+ apiKeyPrefix: bootstrap.bootstrap.apiKey.keyPrefix,
108
+ plaintextKeyReturned: Boolean(bootstrap.bootstrap.apiKey.plaintextKey),
109
+ });
110
+ }
111
+
112
+ main().catch((error) => {
113
+ console.error(error);
114
+ process.exit(1);
115
+ });
116
+ ```
117
+
118
+ Notes:
119
+
120
+ - First bootstrap returns the plaintext API key once.
121
+ - Repeating bootstrap with the same bearer token is idempotent and reuses the tenant resources.
122
+ - This flow is live on the control plane today.
123
+
124
+ ### First-Time Bootstrap + First Request
125
+
126
+ If you want the full SDK example in one run:
127
+
128
+ ```bash
129
+ export FORG3T_API_URL=https://api.forg3t.io
130
+ export FORG3T_BEARER_TOKEN=eyJ...
131
+ npm run example:bootstrap
132
+ ```
133
+
134
+ This example:
135
+
136
+ 1. bootstraps the tenant
137
+ 2. creates a temporary project API key
138
+ 3. submits the first request
139
+ 4. fetches request detail
140
+ 5. revokes the temporary API key
141
+
142
+ ### Repo Maintainer Smoke
143
+
144
+ If you are working inside the Forg3t SDK repo itself, you can also run the bundled smoke script:
145
+
146
+ ```bash
147
+ export FORG3T_API_URL=https://api.forg3t.io
148
+ export FORG3T_BEARER_TOKEN=eyJ...
149
+ npm run smoke:customer-onboarding
150
+ ```
151
+
152
+ ### Known Limitations
153
+ - **Node Runtime**: Whitebox worker and Python runner examples target Node.js + Python environments.
154
+ - **Onchain Verification**: Onchain anchoring is not required for whitebox execution flow and can be integrated later.
155
+
156
+
157
+
158
+ Initialize the client with your project's API key. You can generate API keys from your [Forg3t Dashboard](https://forg3t.io/dashboard).
159
+
160
+ ```typescript
161
+ import { Forg3tClient } from '@forg3t/sdk';
162
+
163
+ const client = new Forg3tClient({
164
+ apiUrl: process.env.FORG3T_API_URL,
165
+ apiKey: process.env.FORG3T_API_KEY,
166
+ });
167
+
168
+ async function main() {
169
+ const me = await client.getCurrentUser();
170
+ const projectId = process.env.FORG3T_PROJECT_ID || me.defaultProjectId;
171
+
172
+ if (!projectId) {
173
+ throw new Error('Set FORG3T_PROJECT_ID or configure a default project first.');
174
+ }
175
+
176
+ const project = await client.getProjectOverview(projectId);
177
+ console.log('Project:', project.name);
178
+ }
179
+
180
+ main().catch(console.error);
181
+ ```
182
+
183
+ ## Features
184
+
185
+ - **AI Unlearning Operations**: Submit and track unlearning jobs programmatically.
186
+ - **Verification Evidence**: Retrieve cryptographic proofs and PDF reports for audit trails.
187
+ - **Project Management**: View project details and stats.
188
+ - **API Key Management**: Create, rotate, and revoke API keys programmatically.
189
+ - **Webhooks**: Manage and replay webhook deliveries for real-time integration.
190
+
191
+ ### Evidence Retrieval
192
+
193
+ ```typescript
194
+ const evidence = await client.getEvidence(jobId);
195
+ // If API returns readiness shape:
196
+ if ('evidenceReady' in evidence && !evidence.evidenceReady) {
197
+ // retry later
198
+ }
199
+
200
+ const evidenceJson = await client.getEvidenceJson(jobId);
201
+ const evidencePdf = await client.getEvidencePdf(jobId, { saveToPath: './evidence.pdf' });
202
+ ```
203
+
204
+ ## Whitebox Worker (Customer Infra)
205
+
206
+ For real model-weight modifications, run a customer-side worker that claims `MODEL_UNLEARN` jobs and executes your training backend adapter in your own infrastructure.
207
+
208
+ ### 1) Submit a `MODEL_UNLEARN` job
209
+
210
+ ```typescript
211
+ import { Forg3tClient, buildModelUnlearningPayload } from '@forg3t/sdk';
212
+
213
+ const client = new Forg3tClient({ apiUrl: process.env.FORG3T_API_URL, apiKey: process.env.FORG3T_API_KEY });
214
+
215
+ const { claim, config } = buildModelUnlearningPayload({
216
+ claim: {
217
+ claim_type: 'DOCUMENT',
218
+ claim_payload: 'customer-record-123',
219
+ scope: 'project',
220
+ assertion: 'must_not_be_recalled'
221
+ },
222
+ model: {
223
+ uri: '/models/llama-7b.safetensors',
224
+ format: 'safetensors'
225
+ },
226
+ target: {
227
+ text: 'customer-record-123'
228
+ },
229
+ plan: {
230
+ method: 'gradient_surgery',
231
+ hyperparameters: { lr: 0.0005, max_steps: 400 }
232
+ }
233
+ });
234
+
235
+ await client.createJob('your-project-id', 'MODEL_UNLEARN', claim, config);
236
+ ```
237
+
238
+ For targeted whitebox localization, provide either:
239
+
240
+ - `config.parameters.target.tokenIds` (preferred), or
241
+ - tokenizer URI in `config.target_config.tokenizer.uri` / `config.parameters.tokenizer.uri`.
242
+
243
+ SDK preflight now enforces this for `MODEL_UNLEARN` submission. To bypass temporarily (not recommended), set:
244
+
245
+ ```bash
246
+ export FORG3T_ALLOW_MODEL_UNLEARN_WITHOUT_LOCALIZATION_INPUT=true
247
+ ```
248
+
249
+ If you use `createUnlearningRequest(...)` with `accessLevel: 'layer_a_and_b'`, include `execution.model.uri` so Control Plane can generate an executable `MODEL_UNLEARN` job:
250
+
251
+ ```typescript
252
+ await client.createUnlearningRequest('your-project-id', {
253
+ target: { type: 'document_id', value: 'customer-record-123' },
254
+ scope: { integrationIds: [] },
255
+ accessLevel: 'layer_a_and_b',
256
+ execution: {
257
+ model: { uri: '/models/llama-7b.safetensors', format: 'safetensors' },
258
+ plan: { method: 'suppression', hyperparameters: { suppression_factor: 0.85, max_edits: 2048 } }
259
+ }
260
+ });
261
+ ```
262
+
263
+ For `accessLevel: 'layer_a_only'`, provide explicit Layer A target config (`execution.target`). This now creates a first-class `BLACKBOX_SUPPRESS` job instead of overloading the retrieval contract:
264
+
265
+ ```typescript
266
+ await client.createUnlearningRequest('your-project-id', {
267
+ target: { type: 'concept', value: 'customer-record-123' },
268
+ scope: { integrationIds: [] },
269
+ accessLevel: 'layer_a_only',
270
+ execution: {
271
+ target: {
272
+ provider: 'openai',
273
+ model: 'gpt-4o-mini'
274
+ }
275
+ }
276
+ });
277
+ ```
278
+
279
+ ### 2) Run worker + adapter in your infra
280
+
281
+ Use the example worker at:
282
+ - `examples/whitebox-worker.ts`
283
+ - `examples/python/weight_surgery_runner.py`
284
+
285
+ Ops installers:
286
+ - `packages/worker/scripts/install-whitebox-gcp.sh` (one-command GCP rollout)
287
+ - `packages/worker/scripts/install-whitebox-airgapped.sh` (one-command offline bundle/install)
288
+
289
+ The worker now supports native adapter modes:
290
+ - `local_command`: run local Python/CLI training jobs inside customer infra.
291
+ - `http`: call your internal training gateway (Kubernetes/SageMaker/Slurm bridge).
292
+
293
+ Install Python deps for the example:
294
+
295
+ ```bash
296
+ pip install -r examples/python/requirements.txt
297
+ ```
298
+
299
+ Example environment for local command mode:
300
+
301
+ ```bash
302
+ export FORG3T_ADAPTER_MODE=local_command
303
+ export FORG3T_PYTHON_BIN=python3
304
+ export FORG3T_DEPLOYMENT_PROFILE=customer_online
305
+ ```
306
+
307
+ Example environment for HTTP mode:
308
+
309
+ ```bash
310
+ export FORG3T_ADAPTER_MODE=http
311
+ export FORG3T_UNLEARNING_URL=https://ml-internal.example.com/unlearn
312
+ export FORG3T_EVALUATION_URL=https://ml-internal.example.com/evaluate
313
+ export FORG3T_ADAPTER_BEARER_TOKEN=...
314
+ export FORG3T_DEPLOYMENT_PROFILE=cloud_managed
315
+ ```
316
+
317
+ Example environment for air-gapped customer deployments:
318
+
319
+ ```bash
320
+ export FORG3T_ADAPTER_MODE=local_command
321
+ export FORG3T_DEPLOYMENT_PROFILE=customer_airgapped
322
+ # optional: allow private DNS hostnames used by local control-plane
323
+ export FORG3T_AIRGAPPED_ALLOWED_HOSTS=cp.internal,forg3t-cp.lan
324
+ ```
325
+
326
+ ### 3) Enforce unlearning quality gates
327
+
328
+ `WhiteboxWorker` supports policy-based quality gates before completing a job:
329
+
330
+ - Presets:
331
+ - `strict`: evaluator required, localization required, `PASS` only.
332
+ - `balanced`: evaluator optional, localization optional, `PASS/REVIEW` allowed.
333
+
334
+ ```typescript
335
+ import { resolveWhiteboxQualityGatePolicy } from '@forg3t/sdk';
336
+
337
+ const strictPolicy = resolveWhiteboxQualityGatePolicy('strict');
338
+ const balancedPolicy = resolveWhiteboxQualityGatePolicy('balanced');
339
+ ```
340
+
341
+ ```typescript
342
+ import { WhiteboxWorker } from '@forg3t/sdk';
343
+
344
+ const worker = new WhiteboxWorker(client, adapter, {
345
+ projectId: process.env.FORG3T_PROJECT_ID!,
346
+ qualityGatePolicy: {
347
+ requireEvaluation: true,
348
+ maxLeakScore: 0.03,
349
+ allowedVerdicts: ['PASS'],
350
+ minChangedTensorCount: 1,
351
+ minChangedParamCount: 1,
352
+ requireModelHashTransition: true,
353
+ requireLocalization: true,
354
+ minLocalizationTokenCoverage: 0.5,
355
+ minLocalizedParamCount: 1,
356
+ minLocalizationConfidence: 0.6
357
+ },
358
+ qualityGateOnFailure: 'fail_job'
359
+ });
360
+ ```
361
+
362
+ Per-job override support:
363
+
364
+ - Include `quality_gate_preset` in `plan.hyperparameters` (`strict` or `balanced`) when creating `MODEL_UNLEARN` requests/jobs.
365
+ - Optional `quality_gate_policy` object can further override preset thresholds.
366
+
367
+ ### 4) Operational hardening (lease-token protected lifecycle)
368
+
369
+ Worker SDK now propagates `claimId` lease tokens on `heartbeat/complete/fail`, and control-plane can enforce strict token checks:
370
+
371
+ ```bash
372
+ export REQUIRE_JOB_CLAIM_TOKEN=1
373
+ ```
374
+
375
+ With this enabled, stale or foreign workers cannot ack jobs they did not claim.
376
+
377
+ ### 5) Privacy defaults (no raw claim payload in result telemetry)
378
+
379
+ `WhiteboxWorker` now defaults to `resultClaimMode: 'hash'` so raw `claim_payload` is not written back to control-plane results:
380
+
381
+ ```typescript
382
+ const worker = new WhiteboxWorker(client, adapter, {
383
+ projectId: process.env.FORG3T_PROJECT_ID!,
384
+ resultClaimMode: 'hash' // default: stores sha256 + payload length
385
+ });
386
+ ```
387
+
388
+ Modes:
389
+ - `hash` (default): sends `claim_payload_sha256` + length.
390
+ - `omit`: omits payload and hash, keeps only claim metadata.
391
+ - `raw`: sends full claim payload (only use if explicitly required).
392
+
393
+ ## Documentation
394
+
395
+ For comprehensive guides and API references, visit [docs.forg3t.io](https://docs.forg3t.io).
396
+ To start unlearning your AI models, visit **[Forg3t.io](https://forg3t.io)**.
397
+
398
+ ## License
399
+
400
+ MIT