@the-ai-company/cbio-node-runtime 0.31.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.
- package/LICENSE +21 -0
- package/README.md +46 -0
- package/dist/agent/agent.d.ts +234 -0
- package/dist/agent/agent.js +565 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/audit/ActivityLog.d.ts +25 -0
- package/dist/audit/ActivityLog.js +66 -0
- package/dist/audit/ActivityLog.js.map +1 -0
- package/dist/errors.d.ts +28 -0
- package/dist/errors.js +37 -0
- package/dist/errors.js.map +1 -0
- package/dist/http/authClient.d.ts +26 -0
- package/dist/http/authClient.js +132 -0
- package/dist/http/authClient.js.map +1 -0
- package/dist/http/localAuthProxy.d.ts +33 -0
- package/dist/http/localAuthProxy.js +93 -0
- package/dist/http/localAuthProxy.js.map +1 -0
- package/dist/http/secretAcquisition.d.ts +54 -0
- package/dist/http/secretAcquisition.js +177 -0
- package/dist/http/secretAcquisition.js.map +1 -0
- package/dist/protocol/childSecretNaming.d.ts +7 -0
- package/dist/protocol/childSecretNaming.js +12 -0
- package/dist/protocol/childSecretNaming.js.map +1 -0
- package/dist/protocol/crypto.d.ts +23 -0
- package/dist/protocol/crypto.js +37 -0
- package/dist/protocol/crypto.js.map +1 -0
- package/dist/protocol/identity.d.ts +8 -0
- package/dist/protocol/identity.js +16 -0
- package/dist/protocol/identity.js.map +1 -0
- package/dist/runtime/index.d.ts +14 -0
- package/dist/runtime/index.js +11 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/sealed/index.d.ts +6 -0
- package/dist/sealed/index.js +6 -0
- package/dist/sealed/index.js.map +1 -0
- package/dist/sealed/seal.d.ts +19 -0
- package/dist/sealed/seal.js +56 -0
- package/dist/sealed/seal.js.map +1 -0
- package/dist/storage/fs.d.ts +16 -0
- package/dist/storage/fs.js +68 -0
- package/dist/storage/fs.js.map +1 -0
- package/dist/storage/memory.d.ts +11 -0
- package/dist/storage/memory.js +19 -0
- package/dist/storage/memory.js.map +1 -0
- package/dist/storage/provider.d.ts +12 -0
- package/dist/storage/provider.js +6 -0
- package/dist/storage/provider.js.map +1 -0
- package/dist/vault/secretPolicy.d.ts +3 -0
- package/dist/vault/secretPolicy.js +14 -0
- package/dist/vault/secretPolicy.js.map +1 -0
- package/dist/vault/vault.d.ts +91 -0
- package/dist/vault/vault.js +534 -0
- package/dist/vault/vault.js.map +1 -0
- package/docs/ARCHITECTURE.md +100 -0
- package/docs/REFERENCE.md +184 -0
- package/docs/TODO-multi-vault.md +29 -0
- package/docs/WORKS_WITH_CUSTOM_FETCH.md +196 -0
- package/docs/es/README.md +27 -0
- package/docs/fr/README.md +27 -0
- package/docs/ja/README.md +27 -0
- package/docs/ko/README.md +27 -0
- package/docs/pt/README.md +27 -0
- package/docs/spec/runtime/README.md +27 -0
- package/docs/spec/runtime/activity-log.md +67 -0
- package/docs/spec/runtime/managed-agent-record.md +52 -0
- package/docs/spec/runtime/merge-rules.md +52 -0
- package/docs/spec/runtime/secret-origin-policy.md +46 -0
- package/docs/zh/README.md +27 -0
- package/examples/minimal.ts +13 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Claw-biometric
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# cbio Node Runtime
|
|
2
|
+
|
|
3
|
+
Node.js runtime for cbio identity and credential vault. Library only.
|
|
4
|
+
|
|
5
|
+
**⚠️ Actively under development — not a stable release.**
|
|
6
|
+
|
|
7
|
+
**Source:** [https://github.com/TheAICompany/cbio-node-runtime](https://github.com/TheAICompany/cbio-node-runtime)
|
|
8
|
+
|
|
9
|
+
## Documentation / 文档 / ドキュメント / 문서 / Docs
|
|
10
|
+
|
|
11
|
+
- [English](README.md)
|
|
12
|
+
- [中文](docs/zh/README.md)
|
|
13
|
+
- [日本語](docs/ja/README.md)
|
|
14
|
+
- [한국어](docs/ko/README.md)
|
|
15
|
+
- [Español](docs/es/README.md)
|
|
16
|
+
- [Português](docs/pt/README.md)
|
|
17
|
+
- [Français](docs/fr/README.md)
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
- No CLI
|
|
22
|
+
- No TUI
|
|
23
|
+
|
|
24
|
+
Import and use `CbioIdentity`, `CbioAgent` from the main export.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @the-ai-company/cbio-node-runtime
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { CbioIdentity, generateIdentityKeys } from '@the-ai-company/cbio-node-runtime';
|
|
36
|
+
|
|
37
|
+
const keys = generateIdentityKeys();
|
|
38
|
+
const identity = await CbioIdentity.load({ privateKey: keys.privateKey });
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Build
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm run build
|
|
45
|
+
npm run test
|
|
46
|
+
```
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { Signer, KeyPair } from "../protocol/crypto.js";
|
|
2
|
+
import { CbioVault, type MergeResult, type SecretPolicy } from "../vault/vault.js";
|
|
3
|
+
import { AuthClient, type FetchWithAuthOptions } from "../http/authClient.js";
|
|
4
|
+
import { SecretAcquisition, type FetchJsonAndAddSecretOptions, type FetchJsonAndUpdateSecretOptions, type FetchResult } from "../http/secretAcquisition.js";
|
|
5
|
+
import type { ActivityLogEntry, ActivityLogMetadata } from "../audit/ActivityLog.js";
|
|
6
|
+
import { type IssuedAgentIdentity, type RevocationRecord } from "@the-ai-company/cbio-protocol";
|
|
7
|
+
import type { IStorageProvider } from "../storage/provider.js";
|
|
8
|
+
interface ManagedAgentRecord {
|
|
9
|
+
agentId: string;
|
|
10
|
+
publicKey: string;
|
|
11
|
+
privateKey: string;
|
|
12
|
+
issuedIdentity: IssuedAgentIdentity;
|
|
13
|
+
/** Vault storage key used when the managed agent was issued. Enables loadManagedAgent to restore the same binding. */
|
|
14
|
+
storageKey?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface IdentityLoadKeys {
|
|
17
|
+
privateKey: string;
|
|
18
|
+
publicKey?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface IdentityLoadOptions {
|
|
21
|
+
storage?: IStorageProvider;
|
|
22
|
+
storageKey?: string;
|
|
23
|
+
activityLog?: ActivityLogConfig;
|
|
24
|
+
issuedIdentity?: IssuedAgentIdentity;
|
|
25
|
+
}
|
|
26
|
+
export interface ActivityLogConfig {
|
|
27
|
+
enabled?: boolean;
|
|
28
|
+
key?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Protocol-level capability strings embedded into signed identities.
|
|
32
|
+
*/
|
|
33
|
+
export type IssuedCapabilityName = "vault:list" | "vault:fetch" | "vault:acquire" | "admin:secrets" | "admin:issue" | "identity:sign";
|
|
34
|
+
/**
|
|
35
|
+
* Valid runtime permission strings for a CbioAgent handle.
|
|
36
|
+
*/
|
|
37
|
+
export type RuntimePermissionName = "vault:list" | "vault:fetch" | "vault:acquire" | "admin:secrets" | "admin:issue" | "identity:sign";
|
|
38
|
+
/**
|
|
39
|
+
* Granular permissions for a CbioAgent handle.
|
|
40
|
+
* These are runtime switches that control access to specific facets.
|
|
41
|
+
*/
|
|
42
|
+
export type RuntimePermissions = Partial<Record<RuntimePermissionName, boolean>>;
|
|
43
|
+
/**
|
|
44
|
+
* Options for getAgent(). Mutually exclusive: either pass `permissions` OR `deriveFromIssuedIdentity`, not both.
|
|
45
|
+
* When deriving, pass `deriveFromIssuedIdentity: true` explicitly; only this literal has effect.
|
|
46
|
+
*/
|
|
47
|
+
export type GetAgentOptions = {
|
|
48
|
+
permissions: RuntimePermissions;
|
|
49
|
+
deriveFromIssuedIdentity?: never;
|
|
50
|
+
} | {
|
|
51
|
+
permissions?: never;
|
|
52
|
+
deriveFromIssuedIdentity?: true;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* CbioIdentity
|
|
56
|
+
*
|
|
57
|
+
* The primary Identity container. Represents an agent's identity and its associated vault.
|
|
58
|
+
* This is the high-privilege handle that contains administrative capabilities (.admin)
|
|
59
|
+
* and private keys.
|
|
60
|
+
*/
|
|
61
|
+
export declare class CbioIdentity {
|
|
62
|
+
#private;
|
|
63
|
+
readonly signer: Signer;
|
|
64
|
+
private readonly _vault;
|
|
65
|
+
readonly admin: CbioAdmin;
|
|
66
|
+
readonly agentId: string;
|
|
67
|
+
readonly publicKey: string;
|
|
68
|
+
private readonly _authClient;
|
|
69
|
+
private readonly _secretAcquisition;
|
|
70
|
+
private constructor();
|
|
71
|
+
/**
|
|
72
|
+
* Primary entry point: Load identity from keys and initialize vault.
|
|
73
|
+
*/
|
|
74
|
+
static load(keys: IdentityLoadKeys, options?: IdentityLoadOptions): Promise<CbioIdentity>;
|
|
75
|
+
fetchWithAuth(secretName: string, url: string, options?: FetchWithAuthOptions): Promise<Response>;
|
|
76
|
+
createFetchWithAuth(secretName: string): (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
77
|
+
getPublicKey(): Promise<string>;
|
|
78
|
+
getAgentId(): Promise<string>;
|
|
79
|
+
fetchJsonAndAddSecret<TResponse = unknown, TBody = unknown>(options: FetchJsonAndAddSecretOptions<TResponse, TBody>): Promise<FetchResult<TResponse>>;
|
|
80
|
+
fetchJsonAndUpdateSecret<TResponse = unknown, TBody = unknown>(options: FetchJsonAndUpdateSecretOptions<TResponse, TBody>): Promise<FetchResult<TResponse>>;
|
|
81
|
+
hasSecret(secretName: string): boolean;
|
|
82
|
+
listSecretNames(): string[];
|
|
83
|
+
/**
|
|
84
|
+
* Register a newly created child identity to the parent vault.
|
|
85
|
+
* @returns The child's publicKey (domain-level identifier). Use getChildIdentitySecretName(publicKey) from the protocol subpath for low-level vault access.
|
|
86
|
+
*/
|
|
87
|
+
registerChildIdentity(keys: KeyPair, options?: RegisterChildIdentityOptions): Promise<RegisterChildIdentityResult>;
|
|
88
|
+
authenticate(nonce: string): Promise<string>;
|
|
89
|
+
/**
|
|
90
|
+
* Create a standard Agent handle for this identity.
|
|
91
|
+
* The Agent handle DOES NOT have an .admin property and does not expose the signer/private key.
|
|
92
|
+
* This is the recommended handle to pass to an autonomous LLM.
|
|
93
|
+
*
|
|
94
|
+
* By default this returns a minimally privileged handle (`vault:fetch`, `vault:list`).
|
|
95
|
+
* Runtime permissions are only widened when passed explicitly or when
|
|
96
|
+
* `deriveFromIssuedIdentity` is set to `true`.
|
|
97
|
+
*/
|
|
98
|
+
getAgent(options?: GetAgentOptions): CbioAgent;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* CbioAgent
|
|
102
|
+
*
|
|
103
|
+
* A safety-wrapped version of an Identity designed for autonomous LLMs.
|
|
104
|
+
* It provides only the Standard facet (fetchWithAuth, etc.) by default and hides
|
|
105
|
+
* all administrative capabilities and private keys.
|
|
106
|
+
*/
|
|
107
|
+
export declare class CbioAgent {
|
|
108
|
+
#private;
|
|
109
|
+
readonly agentId: string;
|
|
110
|
+
readonly publicKey: string;
|
|
111
|
+
constructor(authClient: AuthClient, secretAcquisition: SecretAcquisition, agentId: string, publicKey: string, permissions?: RuntimePermissions);
|
|
112
|
+
/**
|
|
113
|
+
* View the runtime permissions granted to this handle.
|
|
114
|
+
*/
|
|
115
|
+
get permissions(): Readonly<RuntimePermissions>;
|
|
116
|
+
private _checkPermission;
|
|
117
|
+
fetchWithAuth(secretName: string, url: string, options?: FetchWithAuthOptions): Promise<Response>;
|
|
118
|
+
createFetchWithAuth(secretName: string): (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
119
|
+
getPublicKey(): Promise<string>;
|
|
120
|
+
getAgentId(): Promise<string>;
|
|
121
|
+
fetchJsonAndAddSecret<TResponse = unknown, TBody = unknown>(options: FetchJsonAndAddSecretOptions<TResponse, TBody>): Promise<FetchResult<TResponse>>;
|
|
122
|
+
fetchJsonAndUpdateSecret<TResponse = unknown, TBody = unknown>(options: FetchJsonAndUpdateSecretOptions<TResponse, TBody>): Promise<FetchResult<TResponse>>;
|
|
123
|
+
hasSecret(secretName: string): boolean;
|
|
124
|
+
listSecretNames(): string[];
|
|
125
|
+
/**
|
|
126
|
+
* Check if this agent handle has the specified runtime permission.
|
|
127
|
+
*/
|
|
128
|
+
can(permission: RuntimePermissionName): boolean;
|
|
129
|
+
}
|
|
130
|
+
export interface ManagedAgentContext {
|
|
131
|
+
agentId: string;
|
|
132
|
+
publicKey: string;
|
|
133
|
+
agent: CbioAgent;
|
|
134
|
+
}
|
|
135
|
+
export interface RegisterChildIdentityOptions {
|
|
136
|
+
/** Protocol-level capabilities embedded into the signed child identity. */
|
|
137
|
+
issuedCapabilities?: IssuedCapabilityName[];
|
|
138
|
+
}
|
|
139
|
+
export interface RegisterChildIdentityResult {
|
|
140
|
+
publicKey: string;
|
|
141
|
+
}
|
|
142
|
+
export interface ManagedAgentIssueConfig {
|
|
143
|
+
keys?: KeyPair;
|
|
144
|
+
secretName?: string;
|
|
145
|
+
/** Protocol-level capabilities embedded into the signed managed identity. */
|
|
146
|
+
issuedCapabilities?: IssuedCapabilityName[];
|
|
147
|
+
}
|
|
148
|
+
export interface ManagedAgentHandleConfig {
|
|
149
|
+
/** Runtime permissions granted to the returned `CbioAgent` handle. */
|
|
150
|
+
runtimePermissions?: RuntimePermissions;
|
|
151
|
+
}
|
|
152
|
+
export interface ManagedAgentStorageConfig {
|
|
153
|
+
storage?: IStorageProvider;
|
|
154
|
+
storageKey?: string;
|
|
155
|
+
activityLog?: ActivityLogConfig;
|
|
156
|
+
}
|
|
157
|
+
export interface ManagedAgentIssueOptions {
|
|
158
|
+
issue?: ManagedAgentIssueConfig;
|
|
159
|
+
handle?: ManagedAgentHandleConfig;
|
|
160
|
+
storage?: ManagedAgentStorageConfig;
|
|
161
|
+
}
|
|
162
|
+
export interface ManagedAgentLoadOptions {
|
|
163
|
+
handle?: ManagedAgentHandleConfig;
|
|
164
|
+
storage?: ManagedAgentStorageConfig;
|
|
165
|
+
}
|
|
166
|
+
export type ManagedAgentCapabilityStatus = "active" | "revoked" | "missing" | "invalid";
|
|
167
|
+
export interface ManagedAgentCapabilityInfo {
|
|
168
|
+
status: ManagedAgentCapabilityStatus;
|
|
169
|
+
capabilities: readonly IssuedCapabilityName[];
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* CbioManagementFacet
|
|
173
|
+
*
|
|
174
|
+
* Provides administrative (high-risk) capabilities for a CbioIdentity.
|
|
175
|
+
*/
|
|
176
|
+
declare class ManagedAgentSupport {
|
|
177
|
+
protected readonly _identity: CbioIdentity;
|
|
178
|
+
protected readonly _vault: CbioVault;
|
|
179
|
+
constructor(_identity: CbioIdentity, _vault: CbioVault);
|
|
180
|
+
protected getSecret(secretName: string): string | undefined;
|
|
181
|
+
addSecret(secretName: string, secretValue: string, options?: SecretPolicy): Promise<void>;
|
|
182
|
+
protected _getManagedAgentRecord(publicKey: string): ManagedAgentRecord | null;
|
|
183
|
+
protected _getManagedAgentRevocation(publicKey: string): RevocationRecord | null;
|
|
184
|
+
protected _isManagedAgentRevoked(publicKey: string): boolean;
|
|
185
|
+
protected _assertManagedAgentNotRevoked(publicKey: string): void;
|
|
186
|
+
}
|
|
187
|
+
export declare class CbioVaultAdmin {
|
|
188
|
+
private readonly _identity;
|
|
189
|
+
private readonly _vault;
|
|
190
|
+
constructor(_identity: CbioIdentity, _vault: CbioVault);
|
|
191
|
+
addSecret(secretName: string, secretValue: string, options?: SecretPolicy): Promise<void>;
|
|
192
|
+
getSecret(secretName: string): string | undefined;
|
|
193
|
+
hasSecret(secretName: string): boolean;
|
|
194
|
+
deleteSecret(secretName: string): Promise<void>;
|
|
195
|
+
setSecretAllowedOrigins(secretName: string, allowedOrigins: readonly string[]): Promise<void>;
|
|
196
|
+
getActivityLog(): Promise<readonly ActivityLogEntry[]>;
|
|
197
|
+
getActivityLogMetadata(): Promise<ActivityLogMetadata | null>;
|
|
198
|
+
mergeFrom(otherIdentity: CbioIdentity, options?: {
|
|
199
|
+
onConflict?: "abort" | "skip" | "overwrite";
|
|
200
|
+
}): Promise<MergeResult>;
|
|
201
|
+
seal(kdk: string): string;
|
|
202
|
+
loadFromSealedBlob(kdk: string, sealedBlob: string): void;
|
|
203
|
+
serializeToBlob(): Promise<string>;
|
|
204
|
+
saveVault(): Promise<void>;
|
|
205
|
+
/**
|
|
206
|
+
* One-time save of the vault to the given storage key.
|
|
207
|
+
* Does NOT change the bound storage for subsequent saveVault() or autosave.
|
|
208
|
+
* Binding is set during identity load (initFromStorage/initFromBlob).
|
|
209
|
+
*/
|
|
210
|
+
saveVaultAs(storageKey: string): Promise<void>;
|
|
211
|
+
}
|
|
212
|
+
export declare class CbioManagedAgentAdmin extends ManagedAgentSupport {
|
|
213
|
+
getManagedAgentCapabilities(publicKey: string): ManagedAgentCapabilityInfo;
|
|
214
|
+
revokeManagedAgent(publicKey: string, reason?: string): Promise<void>;
|
|
215
|
+
issueManagedAgent(options?: ManagedAgentIssueOptions): Promise<ManagedAgentContext>;
|
|
216
|
+
loadManagedAgent(publicKey: string, options?: ManagedAgentLoadOptions): Promise<ManagedAgentContext>;
|
|
217
|
+
}
|
|
218
|
+
export declare class CbioChildIdentityAdmin {
|
|
219
|
+
private readonly _identity;
|
|
220
|
+
private readonly _vault;
|
|
221
|
+
constructor(_identity: CbioIdentity, _vault: CbioVault);
|
|
222
|
+
/**
|
|
223
|
+
* Registers a child identity in the parent vault.
|
|
224
|
+
* @returns The child's publicKey (domain-level identifier). Use getChildIdentitySecretName from @the-ai-company/cbio-node-runtime/protocol for vault lookups.
|
|
225
|
+
*/
|
|
226
|
+
registerChildIdentity(keys: KeyPair, options?: RegisterChildIdentityOptions): Promise<RegisterChildIdentityResult>;
|
|
227
|
+
}
|
|
228
|
+
export declare class CbioAdmin {
|
|
229
|
+
readonly vault: CbioVaultAdmin;
|
|
230
|
+
readonly managedAgents: CbioManagedAgentAdmin;
|
|
231
|
+
readonly children: CbioChildIdentityAdmin;
|
|
232
|
+
constructor(identity: CbioIdentity, vault: CbioVault);
|
|
233
|
+
}
|
|
234
|
+
export {};
|