@nomosprotocol/sdk 1.0.0 → 1.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.
@@ -0,0 +1,360 @@
1
+ interface VerifyDecisionParams {
2
+ /** Artifact ID from NOMOS Studio or the Exchange */
3
+ artifact_id: string;
4
+ /** The data fields this decision is based on */
5
+ decision_context: Record<string, unknown>;
6
+ /** Optional: the AI's proposed decision (for audit trail) */
7
+ proposed_decision?: string;
8
+ /** Optional: unique ID for idempotency */
9
+ correlation_id?: string;
10
+ }
11
+ interface ListArtifactsParams {
12
+ /** Filter by autonomy band */
13
+ band?: 'autonomous' | 'bounded' | 'human_governed';
14
+ /** Filter by domain */
15
+ domain?: string;
16
+ /** Filter by jurisdiction tag */
17
+ jurisdiction?: string;
18
+ /** Sort order */
19
+ sort?: 'newest' | 'top_rated' | 'most_used';
20
+ /** Number of results (default 20, max 100) */
21
+ limit?: number;
22
+ /** Pagination offset */
23
+ offset?: number;
24
+ }
25
+ interface GenerateGovernanceParams {
26
+ /** Policy documents as plain text */
27
+ policies: string[];
28
+ /** Historical decision logs (CSV rows or JSON objects) */
29
+ decision_logs?: Record<string, unknown>[];
30
+ /** Domain name (e.g. "loan_approval") */
31
+ domain?: string;
32
+ /** Organisation name */
33
+ organisation?: string;
34
+ }
35
+ interface DetectContradictionsParams {
36
+ /** Array of rules to check */
37
+ rules: Array<{
38
+ id: string;
39
+ condition: string;
40
+ outcome: string;
41
+ priority?: number;
42
+ }>;
43
+ }
44
+ type Verdict = 'auto_approved' | 'auto_rejected' | 'escalated' | 'pending_human_review';
45
+ interface VerifyDecisionResult {
46
+ /** Whether the decision is permitted under current governance */
47
+ allowed: boolean;
48
+ /** Machine-readable verdict */
49
+ verdict: Verdict;
50
+ /** Human-readable explanation */
51
+ verdict_description: string;
52
+ /** The rule that triggered this verdict (if any) */
53
+ rule_reference?: string;
54
+ /** SHA-256 hash of the audit record — store this for compliance */
55
+ audit_record?: string;
56
+ /** Artifact that governed this decision */
57
+ artifact_id: string;
58
+ /** Execution ID for tracing */
59
+ execution_id?: string;
60
+ /** ISO timestamp */
61
+ decided_at: string;
62
+ }
63
+ interface Artifact {
64
+ id: string;
65
+ title: string;
66
+ description?: string;
67
+ domain?: string;
68
+ verification_tier: 'DECLARED' | 'VALIDATED' | 'CERTIFIED' | 'PROVEN' | 'SOVEREIGN';
69
+ autonomy_band: 'autonomous' | 'bounded' | 'human_governed';
70
+ ari_score?: number;
71
+ rule_count?: number;
72
+ jurisdiction_tags: string[];
73
+ industry_tags: string[];
74
+ publisher_org?: string;
75
+ seal_hash?: string;
76
+ downloads: number;
77
+ rating?: number;
78
+ price_usd: number;
79
+ published_at?: string;
80
+ created_at: string;
81
+ }
82
+ interface ArtifactList {
83
+ data: Artifact[];
84
+ total: number;
85
+ limit: number;
86
+ offset: number;
87
+ }
88
+ interface Contradiction {
89
+ type: 'threshold_conflict' | 'role_conflict' | 'ghost_term' | 'rule_collision' | 'layer_divergence';
90
+ severity: 'critical' | 'warning' | 'info';
91
+ rule_ids: string[];
92
+ description: string;
93
+ suggested_resolution?: string;
94
+ }
95
+ interface DetectContradictionsResult {
96
+ contradiction_count: number;
97
+ contradictions: Contradiction[];
98
+ clean: boolean;
99
+ }
100
+ interface GenerateGovernanceResult {
101
+ artifact_id: string;
102
+ seal_hash: string;
103
+ ari_score: number;
104
+ autonomy_band: 'autonomous' | 'bounded' | 'human_governed';
105
+ rule_count: number;
106
+ verification_tier: string;
107
+ download_url?: string;
108
+ }
109
+ interface NomosConfig {
110
+ /** Base URL override — defaults to https://nomos.ai */
111
+ baseUrl?: string;
112
+ /** Max retries on 429 / 5xx (default: 3) */
113
+ maxRetries?: number;
114
+ /** Request timeout in ms (default: 30000) */
115
+ timeout?: number;
116
+ }
117
+ interface RequestOptions {
118
+ /** Per-request timeout override in ms */
119
+ timeout?: number;
120
+ /** Per-request max retries override */
121
+ maxRetries?: number;
122
+ /** Idempotency key — safe to retry the same request server-side */
123
+ idempotencyKey?: string;
124
+ /** Per-request API key — useful for multi-tenant platforms */
125
+ apiKey?: string;
126
+ }
127
+ interface NomosRawResponse {
128
+ /** x-request-id header value — include in support tickets */
129
+ requestId: string;
130
+ statusCode: number;
131
+ headers: Record<string, string>;
132
+ }
133
+ /** Every SDK response carries `.lastResponse` for debugging and tracing. */
134
+ type WithLastResponse<T> = T & {
135
+ lastResponse: NomosRawResponse;
136
+ };
137
+ type NomosWebhookEventType = 'artifact.sealed' | 'artifact.published' | 'decision.verified' | 'decision.escalated' | 'exchange.purchased' | 'exchange.reviewed' | 'drift.detected';
138
+ interface NomosWebhookEvent {
139
+ id: string;
140
+ type: NomosWebhookEventType;
141
+ created: number;
142
+ artifact_id?: string;
143
+ data: Record<string, unknown>;
144
+ }
145
+
146
+ interface HttpClientOptions {
147
+ apiKey: string;
148
+ baseUrl: string;
149
+ maxRetries: number;
150
+ timeout: number;
151
+ }
152
+ interface HttpResponse<T> {
153
+ data: T;
154
+ lastResponse: NomosRawResponse;
155
+ }
156
+ declare class HttpClient {
157
+ private readonly opts;
158
+ constructor(opts: HttpClientOptions);
159
+ get<T>(path: string, reqOpts?: RequestOptions): Promise<HttpResponse<T>>;
160
+ post<T>(path: string, body: unknown, reqOpts?: RequestOptions): Promise<HttpResponse<T>>;
161
+ private request;
162
+ }
163
+
164
+ declare class Decisions {
165
+ private readonly http;
166
+ constructor(http: HttpClient);
167
+ /**
168
+ * Verify whether an AI decision is permitted under a governance artifact.
169
+ *
170
+ * Public demo artifacts (`pub_*`) work without an API key.
171
+ * Custom artifacts require a valid API key.
172
+ *
173
+ * @example
174
+ * const result = await nomos.decisions.verify({
175
+ * artifact_id: 'pub_lending_v1',
176
+ * decision_context: { credit_score: 720, loan_amount: 50000 },
177
+ * });
178
+ *
179
+ * if (!result.allowed) {
180
+ * throw new Error(`Blocked: ${result.verdict_description}`);
181
+ * }
182
+ *
183
+ * // Debugging / tracing
184
+ * console.log(result.lastResponse.requestId);
185
+ *
186
+ * @example
187
+ * // Per-request options
188
+ * const result = await nomos.decisions.verify(params, {
189
+ * idempotencyKey: `verify-${transactionId}`,
190
+ * timeout: 5000,
191
+ * });
192
+ */
193
+ verify(params: VerifyDecisionParams, opts?: RequestOptions): Promise<WithLastResponse<VerifyDecisionResult>>;
194
+ }
195
+
196
+ declare class Artifacts {
197
+ private readonly http;
198
+ constructor(http: HttpClient);
199
+ /**
200
+ * Retrieve a single artifact by ID.
201
+ *
202
+ * @example
203
+ * const artifact = await nomos.artifacts.retrieve('loan_approval_v1');
204
+ * console.log(artifact.ari_score, artifact.autonomy_band);
205
+ * console.log(artifact.lastResponse.requestId); // for support tickets
206
+ */
207
+ retrieve(artifactId: string, opts?: RequestOptions): Promise<WithLastResponse<Artifact>>;
208
+ /**
209
+ * List published artifacts on the Exchange with optional filters.
210
+ *
211
+ * @example
212
+ * const { data, total } = await nomos.artifacts.list({ band: 'autonomous', limit: 10 });
213
+ *
214
+ * @example
215
+ * // With per-request options
216
+ * const page = await nomos.artifacts.list({ limit: 20 }, { timeout: 5000 });
217
+ */
218
+ list(params?: ListArtifactsParams, opts?: RequestOptions): Promise<WithLastResponse<ArtifactList>>;
219
+ /**
220
+ * Auto-paginating iterator — yields every artifact across all pages.
221
+ * Stops automatically when the last page is reached.
222
+ *
223
+ * @example
224
+ * for await (const artifact of nomos.artifacts.listAutoPaging({ band: 'autonomous' })) {
225
+ * console.log(artifact.title, artifact.ari_score);
226
+ * }
227
+ */
228
+ listAutoPaging(params?: ListArtifactsParams, opts?: RequestOptions): AsyncGenerator<Artifact>;
229
+ }
230
+
231
+ declare class Governance {
232
+ private readonly http;
233
+ constructor(http: HttpClient);
234
+ /**
235
+ * Generate a sealed .nomos governance artifact from policy documents
236
+ * and optional historical decision logs.
237
+ *
238
+ * @example
239
+ * const artifact = await nomos.governance.generate({
240
+ * policies: [policyText],
241
+ * decision_logs: historicalRows,
242
+ * domain: 'loan_approval',
243
+ * });
244
+ * console.log(artifact.ari_score, artifact.seal_hash);
245
+ */
246
+ generate(params: GenerateGovernanceParams, opts?: RequestOptions): Promise<WithLastResponse<GenerateGovernanceResult>>;
247
+ /**
248
+ * Detect contradictions and conflicts in a rule set before sealing.
249
+ *
250
+ * @example
251
+ * const report = await nomos.governance.detectContradictions({ rules });
252
+ * if (!report.clean) {
253
+ * console.log(report.contradictions);
254
+ * }
255
+ */
256
+ detectContradictions(params: DetectContradictionsParams, opts?: RequestOptions): Promise<WithLastResponse<DetectContradictionsResult>>;
257
+ }
258
+
259
+ declare class Webhooks {
260
+ /**
261
+ * Verify a NOMOS webhook signature and return the parsed event.
262
+ *
263
+ * Signature header format: `t=<unix_ts>,v1=<hmac_sha256_hex>`
264
+ * Signed payload: `<timestamp>.<raw_body>`
265
+ *
266
+ * @example
267
+ * // Express
268
+ * app.post('/webhooks/nomos', express.raw({ type: 'application/json' }), async (req, res) => {
269
+ * const event = await nomos.webhooks.constructEvent(
270
+ * req.body,
271
+ * req.headers['nomos-signature'] as string,
272
+ * process.env.NOMOS_WEBHOOK_SECRET!,
273
+ * );
274
+ * console.log(event.type, event.data);
275
+ * res.sendStatus(200);
276
+ * });
277
+ *
278
+ * @throws {NomosWebhookSignatureError} if signature is invalid, expired, or malformed
279
+ */
280
+ constructEvent(payload: string | Uint8Array, signature: string, secret: string, toleranceSeconds?: number): Promise<NomosWebhookEvent>;
281
+ /**
282
+ * Verify a webhook signature without parsing the event.
283
+ * Returns `true` if valid, `false` if not (never throws).
284
+ *
285
+ * @example
286
+ * const valid = await nomos.webhooks.verifySignature(rawBody, sig, secret);
287
+ * if (!valid) return res.sendStatus(400);
288
+ */
289
+ verifySignature(payload: string | Uint8Array, signature: string, secret: string, toleranceSeconds?: number): Promise<boolean>;
290
+ }
291
+
292
+ type NomosErrorCode = 'authentication_error' | 'authorization_error' | 'rate_limit_error' | 'validation_error' | 'not_found' | 'api_error' | 'network_error' | 'webhook_signature_error';
293
+ declare class NomosError extends Error {
294
+ readonly code: NomosErrorCode;
295
+ readonly status?: number;
296
+ readonly requestId?: string;
297
+ constructor(message: string, code: NomosErrorCode, status?: number, requestId?: string);
298
+ }
299
+ declare class NomosAuthenticationError extends NomosError {
300
+ constructor(message?: string, requestId?: string);
301
+ }
302
+ declare class NomosAuthorizationError extends NomosError {
303
+ constructor(message?: string, requestId?: string);
304
+ }
305
+ declare class NomosRateLimitError extends NomosError {
306
+ readonly retryAfter?: number;
307
+ constructor(message?: string, retryAfter?: number, requestId?: string);
308
+ }
309
+ declare class NomosValidationError extends NomosError {
310
+ readonly details?: unknown;
311
+ constructor(message: string, details?: unknown, requestId?: string);
312
+ }
313
+ declare class NomosNotFoundError extends NomosError {
314
+ constructor(message: string, requestId?: string);
315
+ }
316
+ declare class NomosAPIError extends NomosError {
317
+ constructor(message: string, status: number, requestId?: string);
318
+ }
319
+ declare class NomosNetworkError extends NomosError {
320
+ constructor(message: string);
321
+ }
322
+ declare class NomosWebhookSignatureError extends NomosError {
323
+ constructor(message: string);
324
+ }
325
+
326
+ type errors_NomosAPIError = NomosAPIError;
327
+ declare const errors_NomosAPIError: typeof NomosAPIError;
328
+ type errors_NomosAuthenticationError = NomosAuthenticationError;
329
+ declare const errors_NomosAuthenticationError: typeof NomosAuthenticationError;
330
+ type errors_NomosAuthorizationError = NomosAuthorizationError;
331
+ declare const errors_NomosAuthorizationError: typeof NomosAuthorizationError;
332
+ type errors_NomosError = NomosError;
333
+ declare const errors_NomosError: typeof NomosError;
334
+ type errors_NomosErrorCode = NomosErrorCode;
335
+ type errors_NomosNetworkError = NomosNetworkError;
336
+ declare const errors_NomosNetworkError: typeof NomosNetworkError;
337
+ type errors_NomosNotFoundError = NomosNotFoundError;
338
+ declare const errors_NomosNotFoundError: typeof NomosNotFoundError;
339
+ type errors_NomosRateLimitError = NomosRateLimitError;
340
+ declare const errors_NomosRateLimitError: typeof NomosRateLimitError;
341
+ type errors_NomosValidationError = NomosValidationError;
342
+ declare const errors_NomosValidationError: typeof NomosValidationError;
343
+ type errors_NomosWebhookSignatureError = NomosWebhookSignatureError;
344
+ declare const errors_NomosWebhookSignatureError: typeof NomosWebhookSignatureError;
345
+ declare namespace errors {
346
+ export { errors_NomosAPIError as NomosAPIError, errors_NomosAuthenticationError as NomosAuthenticationError, errors_NomosAuthorizationError as NomosAuthorizationError, errors_NomosError as NomosError, type errors_NomosErrorCode as NomosErrorCode, errors_NomosNetworkError as NomosNetworkError, errors_NomosNotFoundError as NomosNotFoundError, errors_NomosRateLimitError as NomosRateLimitError, errors_NomosValidationError as NomosValidationError, errors_NomosWebhookSignatureError as NomosWebhookSignatureError };
347
+ }
348
+
349
+ declare class Nomos {
350
+ readonly decisions: Decisions;
351
+ readonly artifacts: Artifacts;
352
+ readonly governance: Governance;
353
+ readonly webhooks: Webhooks;
354
+ /** Whether this instance is using a live or test API key. */
355
+ readonly mode: 'live' | 'test';
356
+ static readonly errors: typeof errors;
357
+ constructor(apiKey: string, config?: NomosConfig);
358
+ }
359
+
360
+ export { type Artifact, type ArtifactList, type Contradiction, type DetectContradictionsParams, type DetectContradictionsResult, type GenerateGovernanceParams, type GenerateGovernanceResult, type ListArtifactsParams, Nomos, NomosAPIError, NomosAuthenticationError, NomosAuthorizationError, type NomosConfig, NomosError, type NomosErrorCode, NomosNetworkError, NomosNotFoundError, NomosRateLimitError, type NomosRawResponse, NomosValidationError, type NomosWebhookEvent, type NomosWebhookEventType, NomosWebhookSignatureError, type RequestOptions, type Verdict, type VerifyDecisionParams, type VerifyDecisionResult, type WithLastResponse };