@continuonai/rcan-ts 0.1.1

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,353 @@
1
+ /**
2
+ * RCAN Robot URI — addressing scheme for RCAN v1.2.
3
+ *
4
+ * Format: rcan://<registry>/<manufacturer>/<model>/<version>/<device-id>
5
+ * Example: rcan://registry.rcan.dev/acme/robotarm/v2/unit-001
6
+ */
7
+ declare class RobotURIError extends Error {
8
+ constructor(message: string);
9
+ }
10
+ interface RobotURIOptions {
11
+ manufacturer: string;
12
+ model: string;
13
+ version: string;
14
+ deviceId: string;
15
+ registry?: string;
16
+ }
17
+ declare class RobotURI {
18
+ readonly registry: string;
19
+ readonly manufacturer: string;
20
+ readonly model: string;
21
+ readonly version: string;
22
+ readonly deviceId: string;
23
+ private constructor();
24
+ /** Parse a RCAN URI string. Throws RobotURIError on invalid input. */
25
+ static parse(uri: string): RobotURI;
26
+ /** Build a RCAN URI from components. */
27
+ static build(opts: RobotURIOptions): RobotURI;
28
+ /** Full URI string: rcan://registry/manufacturer/model/version/device-id */
29
+ toString(): string;
30
+ /** Short namespace: manufacturer/model */
31
+ get namespace(): string;
32
+ /** HTTPS registry URL for this robot */
33
+ get registryUrl(): string;
34
+ /** Check if two URIs refer to the same robot */
35
+ equals(other: RobotURI): boolean;
36
+ toJSON(): object;
37
+ }
38
+
39
+ /**
40
+ * RCAN Message — command envelope for RCAN v1.2.
41
+ *
42
+ * A RCANMessage wraps a robot command with:
43
+ * - RCAN protocol version
44
+ * - Target Robot URI
45
+ * - Command name and parameters
46
+ * - Optional AI confidence score (§16)
47
+ * - Optional model identity (§16)
48
+ * - Optional Ed25519 signature
49
+ */
50
+
51
+ interface SignatureBlock {
52
+ alg: string;
53
+ kid: string;
54
+ sig: string;
55
+ }
56
+ interface RCANMessageData {
57
+ rcan?: string;
58
+ cmd: string;
59
+ target: string | RobotURI;
60
+ params?: Record<string, unknown>;
61
+ confidence?: number;
62
+ modelIdentity?: string;
63
+ model_identity?: string;
64
+ signature?: SignatureBlock;
65
+ timestamp?: string;
66
+ [key: string]: unknown;
67
+ }
68
+ declare class RCANMessageError extends Error {
69
+ constructor(message: string);
70
+ }
71
+ declare class RCANMessage {
72
+ readonly rcan: string;
73
+ readonly cmd: string;
74
+ readonly target: string;
75
+ readonly params: Record<string, unknown>;
76
+ readonly confidence: number | undefined;
77
+ readonly modelIdentity: string | undefined;
78
+ readonly signature: SignatureBlock | undefined;
79
+ readonly timestamp: string;
80
+ constructor(data: RCANMessageData);
81
+ /** Whether this message has a signature block */
82
+ get isSigned(): boolean;
83
+ /** Whether this message was generated by an AI model (has confidence score) */
84
+ get isAiDriven(): boolean;
85
+ /** Serialize to a plain object */
86
+ toJSON(): Record<string, unknown>;
87
+ /** Serialize to JSON string */
88
+ toJSONString(indent?: number): string;
89
+ /** Parse from a plain object or JSON string */
90
+ static fromJSON(data: string | Record<string, unknown>): RCANMessage;
91
+ }
92
+
93
+ /**
94
+ * RCAN Safety Gates — confidence and human-in-the-loop gating (§16).
95
+ */
96
+ declare class GateError extends Error {
97
+ constructor(message: string);
98
+ }
99
+ declare class ConfidenceGate {
100
+ readonly threshold: number;
101
+ constructor(threshold?: number);
102
+ /** Returns true if the confidence score meets the threshold. */
103
+ allows(confidence: number): boolean;
104
+ /** Returns the margin (positive = allowed, negative = blocked). */
105
+ margin(confidence: number): number;
106
+ /** Throw if confidence is below threshold. */
107
+ assert(confidence: number, action?: string): void;
108
+ }
109
+ type ApprovalStatus = "approved" | "denied" | "pending";
110
+ interface PendingApproval {
111
+ token: string;
112
+ action: string;
113
+ context: Record<string, unknown>;
114
+ createdAt: string;
115
+ status: ApprovalStatus;
116
+ reason?: string;
117
+ }
118
+ declare class HiTLGate {
119
+ private _pending;
120
+ /**
121
+ * Request human approval for an action.
122
+ * Returns an approval token to poll or pass to approve/deny.
123
+ */
124
+ request(action: string, context?: Record<string, unknown>): string;
125
+ /** Approve a pending request. */
126
+ approve(token: string): void;
127
+ /** Deny a pending request with an optional reason. */
128
+ deny(token: string, reason?: string): void;
129
+ /** Check the status of a pending approval. */
130
+ check(token: string): ApprovalStatus;
131
+ /** Get all pending approvals. */
132
+ get pendingApprovals(): PendingApproval[];
133
+ /** Get the full approval record. */
134
+ getApproval(token: string): PendingApproval | undefined;
135
+ /** Clear resolved (approved/denied) approvals. */
136
+ clearResolved(): void;
137
+ }
138
+
139
+ /**
140
+ * RCAN Audit Chain — tamper-evident commitment records (§16).
141
+ *
142
+ * Each CommitmentRecord is sealed with an HMAC-SHA256 over its content.
143
+ * Records are chained via previousHash, creating a forensic audit trail.
144
+ */
145
+ interface CommitmentRecordData {
146
+ action: string;
147
+ robotUri?: string;
148
+ confidence?: number;
149
+ modelIdentity?: string;
150
+ params?: Record<string, unknown>;
151
+ safetyApproved?: boolean;
152
+ }
153
+ interface CommitmentRecordJSON {
154
+ recordId: string;
155
+ action: string;
156
+ robotUri: string;
157
+ confidence?: number;
158
+ modelIdentity?: string;
159
+ params: Record<string, unknown>;
160
+ safetyApproved: boolean;
161
+ timestamp: string;
162
+ contentHash: string;
163
+ previousHash: string | null;
164
+ hmac: string;
165
+ }
166
+ declare class AuditError extends Error {
167
+ constructor(message: string);
168
+ }
169
+ declare class CommitmentRecord {
170
+ readonly recordId: string;
171
+ readonly action: string;
172
+ readonly robotUri: string;
173
+ readonly confidence: number | undefined;
174
+ readonly modelIdentity: string | undefined;
175
+ readonly params: Record<string, unknown>;
176
+ readonly safetyApproved: boolean;
177
+ readonly timestamp: string;
178
+ readonly contentHash: string;
179
+ readonly previousHash: string | null;
180
+ readonly hmac: string;
181
+ private constructor();
182
+ static create(data: CommitmentRecordData, secret: string, previousHash?: string | null): CommitmentRecord;
183
+ verify(secret: string): boolean;
184
+ toJSON(): CommitmentRecordJSON;
185
+ static fromJSON(obj: CommitmentRecordJSON): CommitmentRecord;
186
+ }
187
+ interface ChainVerifyResult {
188
+ valid: boolean;
189
+ count: number;
190
+ errors: string[];
191
+ }
192
+ declare class AuditChain {
193
+ private _records;
194
+ private _secret;
195
+ constructor(secret: string);
196
+ get records(): readonly CommitmentRecord[];
197
+ append(data: CommitmentRecordData): CommitmentRecord;
198
+ verifyAll(): ChainVerifyResult;
199
+ toJSONL(): string;
200
+ static fromJSONL(text: string, secret: string): AuditChain;
201
+ }
202
+
203
+ /**
204
+ * RCAN Validation — validate messages, configs, and URIs.
205
+ *
206
+ * Each function returns a ValidationResult with ok, issues, warnings, info.
207
+ */
208
+ interface ValidationResult {
209
+ ok: boolean;
210
+ issues: string[];
211
+ warnings: string[];
212
+ info: string[];
213
+ }
214
+ declare function validateURI(uri: string): ValidationResult;
215
+ declare function validateMessage(data: unknown): ValidationResult;
216
+ interface RCANConfig {
217
+ rcan_version?: string;
218
+ metadata?: {
219
+ manufacturer?: string;
220
+ model?: string;
221
+ version?: string;
222
+ rrn?: string;
223
+ rcan_uri?: string;
224
+ };
225
+ agent?: {
226
+ provider?: string;
227
+ model?: string;
228
+ confidence_gates?: Array<{
229
+ threshold?: number;
230
+ }>;
231
+ hitl_gates?: Array<Record<string, unknown>>;
232
+ commitment_chain?: {
233
+ enabled?: boolean;
234
+ };
235
+ signing?: {
236
+ enabled?: boolean;
237
+ };
238
+ };
239
+ rcan_protocol?: {
240
+ jwt_auth?: {
241
+ enabled?: boolean;
242
+ };
243
+ };
244
+ [key: string]: unknown;
245
+ }
246
+ declare function validateConfig(config: RCANConfig): ValidationResult;
247
+
248
+ /**
249
+ * RCAN error class hierarchy.
250
+ * All errors extend RCANError which extends the built-in Error.
251
+ */
252
+ declare class RCANError extends Error {
253
+ constructor(message: string);
254
+ }
255
+ declare class RCANAddressError extends RCANError {
256
+ constructor(message: string);
257
+ }
258
+ declare class RCANValidationError extends RCANError {
259
+ constructor(message: string);
260
+ }
261
+ declare class RCANGateError extends RCANError {
262
+ gateType: string;
263
+ value?: number | undefined;
264
+ threshold?: number | undefined;
265
+ constructor(message: string, gateType: string, value?: number | undefined, threshold?: number | undefined);
266
+ }
267
+ declare class RCANSignatureError extends RCANError {
268
+ constructor(message: string);
269
+ }
270
+ declare class RCANRegistryError extends RCANError {
271
+ constructor(message: string);
272
+ }
273
+
274
+ /**
275
+ * rcan-ts — RegistryClient
276
+ * TypeScript parity with rcan-py RegistryClient.
277
+ *
278
+ * @see https://rcan.dev/spec#section-registry
279
+ */
280
+ interface RobotRegistration {
281
+ manufacturer: string;
282
+ model: string;
283
+ version: string;
284
+ device_id: string;
285
+ description?: string;
286
+ contact_email?: string;
287
+ verification_tier?: string;
288
+ source?: string;
289
+ }
290
+ interface Robot extends RobotRegistration {
291
+ rrn: string;
292
+ registered_at: string;
293
+ updated_at: string;
294
+ verification_tier: string;
295
+ status: string;
296
+ }
297
+ interface RegistrationResult {
298
+ rrn: string;
299
+ api_key: string;
300
+ }
301
+ interface ListResult {
302
+ robots: Robot[];
303
+ total: number;
304
+ limit: number;
305
+ offset: number;
306
+ }
307
+ declare class RegistryClient {
308
+ private baseUrl;
309
+ private apiKey?;
310
+ private timeout;
311
+ constructor(opts?: {
312
+ baseUrl?: string;
313
+ apiKey?: string;
314
+ timeout?: number;
315
+ });
316
+ private _fetch;
317
+ private _authHeaders;
318
+ private _checkResponse;
319
+ /** Register a new robot. Returns RRN + API key. */
320
+ register(robot: RobotRegistration): Promise<RegistrationResult>;
321
+ /** Look up a robot by RRN. */
322
+ get(rrn: string): Promise<Robot>;
323
+ /** List robots with optional pagination and tier filter. */
324
+ list(opts?: {
325
+ limit?: number;
326
+ offset?: number;
327
+ tier?: string;
328
+ }): Promise<ListResult>;
329
+ /** Update robot fields. Requires API key. */
330
+ patch(rrn: string, updates: Partial<Robot>): Promise<Robot>;
331
+ /** Delete (soft-delete) a robot. Requires API key. */
332
+ delete(rrn: string): Promise<void>;
333
+ /** Search robots by query, manufacturer, model, or tier. */
334
+ search(opts: {
335
+ q?: string;
336
+ manufacturer?: string;
337
+ model?: string;
338
+ tier?: string;
339
+ }): Promise<Robot[]>;
340
+ }
341
+
342
+ /**
343
+ * rcan-ts — Official TypeScript SDK for RCAN v1.2
344
+ * Robot Communication and Accountability Network
345
+ *
346
+ * @see https://rcan.dev
347
+ * @see https://github.com/continuonai/rcan-ts
348
+ */
349
+
350
+ declare const VERSION = "0.1.0";
351
+ declare const RCAN_VERSION = "1.2";
352
+
353
+ export { type ApprovalStatus, AuditChain, AuditError, type ChainVerifyResult, CommitmentRecord, type CommitmentRecordData, type CommitmentRecordJSON, ConfidenceGate, GateError, HiTLGate, type ListResult, type PendingApproval, RCANAddressError, type RCANConfig, RCANError, RCANGateError, RCANMessage, type RCANMessageData, RCANMessageError, RCANRegistryError, RCANSignatureError, RCANValidationError, RCAN_VERSION, type RegistrationResult, RegistryClient, type Robot, type RobotRegistration, RobotURI, RobotURIError, type RobotURIOptions, type SignatureBlock, VERSION, type ValidationResult, validateConfig, validateMessage, validateURI };