@the-ai-company/cbio-node-runtime 0.39.0 → 1.0.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.
Files changed (113) hide show
  1. package/README.md +116 -54
  2. package/dist/clients/agent/client.d.ts +9 -0
  3. package/dist/clients/agent/client.js +72 -0
  4. package/dist/clients/agent/client.js.map +1 -0
  5. package/dist/clients/agent/contracts.d.ts +34 -0
  6. package/dist/clients/agent/contracts.js +2 -0
  7. package/dist/clients/agent/contracts.js.map +1 -0
  8. package/dist/clients/agent/index.d.ts +3 -0
  9. package/dist/clients/agent/index.js +2 -0
  10. package/dist/clients/agent/index.js.map +1 -0
  11. package/dist/clients/owner/client.d.ts +18 -0
  12. package/dist/clients/owner/client.js +169 -0
  13. package/dist/clients/owner/client.js.map +1 -0
  14. package/dist/clients/owner/contracts.d.ts +34 -0
  15. package/dist/clients/owner/contracts.js +2 -0
  16. package/dist/clients/owner/contracts.js.map +1 -0
  17. package/dist/clients/owner/index.d.ts +3 -0
  18. package/dist/clients/owner/index.js +2 -0
  19. package/dist/clients/owner/index.js.map +1 -0
  20. package/dist/runtime/index.d.ts +8 -10
  21. package/dist/runtime/index.js +8 -7
  22. package/dist/runtime/index.js.map +1 -1
  23. package/dist/storage/fs.d.ts +1 -0
  24. package/dist/storage/fs.js +28 -0
  25. package/dist/storage/fs.js.map +1 -1
  26. package/dist/storage/memory.d.ts +1 -0
  27. package/dist/storage/memory.js +20 -0
  28. package/dist/storage/memory.js.map +1 -1
  29. package/dist/storage/provider.d.ts +2 -0
  30. package/dist/vault-core/contracts.d.ts +230 -0
  31. package/dist/vault-core/contracts.js +2 -0
  32. package/dist/vault-core/contracts.js.map +1 -0
  33. package/dist/vault-core/core.d.ts +21 -0
  34. package/dist/vault-core/core.js +335 -0
  35. package/dist/vault-core/core.js.map +1 -0
  36. package/dist/vault-core/defaults.d.ts +141 -0
  37. package/dist/vault-core/defaults.js +602 -0
  38. package/dist/vault-core/defaults.js.map +1 -0
  39. package/dist/vault-core/errors.d.ts +4 -0
  40. package/dist/vault-core/errors.js +9 -0
  41. package/dist/vault-core/errors.js.map +1 -0
  42. package/dist/vault-core/index.d.ts +6 -0
  43. package/dist/vault-core/index.js +5 -0
  44. package/dist/vault-core/index.js.map +1 -0
  45. package/dist/vault-core/persistence.d.ts +87 -0
  46. package/dist/vault-core/persistence.js +309 -0
  47. package/dist/vault-core/persistence.js.map +1 -0
  48. package/dist/vault-core/ports.d.ts +101 -0
  49. package/dist/vault-core/ports.js +2 -0
  50. package/dist/vault-core/ports.js.map +1 -0
  51. package/dist/vault-ingress/defaults.d.ts +14 -0
  52. package/dist/vault-ingress/defaults.js +41 -0
  53. package/dist/vault-ingress/defaults.js.map +1 -0
  54. package/dist/vault-ingress/flow-factories.d.ts +24 -0
  55. package/dist/vault-ingress/flow-factories.js +48 -0
  56. package/dist/vault-ingress/flow-factories.js.map +1 -0
  57. package/dist/vault-ingress/index.d.ts +81 -0
  58. package/dist/vault-ingress/index.js +357 -0
  59. package/dist/vault-ingress/index.js.map +1 -0
  60. package/docs/ARCHITECTURE.md +44 -76
  61. package/docs/REFERENCE.md +217 -218
  62. package/docs/WORKS_WITH_CUSTOM_FETCH.md +16 -191
  63. package/docs/es/README.md +8 -24
  64. package/docs/fr/README.md +8 -24
  65. package/docs/ja/README.md +8 -24
  66. package/docs/ko/README.md +8 -24
  67. package/docs/pt/README.md +8 -24
  68. package/docs/zh/README.md +21 -7
  69. package/package.json +2 -10
  70. package/dist/agent/agent.d.ts +0 -267
  71. package/dist/agent/agent.js +0 -689
  72. package/dist/agent/agent.js.map +0 -1
  73. package/dist/audit/ActivityLog.d.ts +0 -25
  74. package/dist/audit/ActivityLog.js +0 -71
  75. package/dist/audit/ActivityLog.js.map +0 -1
  76. package/dist/http/authClient.d.ts +0 -26
  77. package/dist/http/authClient.js +0 -132
  78. package/dist/http/authClient.js.map +0 -1
  79. package/dist/http/genericSecretValidator.d.ts +0 -11
  80. package/dist/http/genericSecretValidator.js +0 -42
  81. package/dist/http/genericSecretValidator.js.map +0 -1
  82. package/dist/http/localAuthProxy.d.ts +0 -33
  83. package/dist/http/localAuthProxy.js +0 -93
  84. package/dist/http/localAuthProxy.js.map +0 -1
  85. package/dist/http/localSecretIngress.d.ts +0 -33
  86. package/dist/http/localSecretIngress.js +0 -162
  87. package/dist/http/localSecretIngress.js.map +0 -1
  88. package/dist/http/secretAcquisition.d.ts +0 -54
  89. package/dist/http/secretAcquisition.js +0 -177
  90. package/dist/http/secretAcquisition.js.map +0 -1
  91. package/dist/protocol/childSecretNaming.d.ts +0 -7
  92. package/dist/protocol/childSecretNaming.js +0 -12
  93. package/dist/protocol/childSecretNaming.js.map +0 -1
  94. package/dist/protocol/identity.d.ts +0 -8
  95. package/dist/protocol/identity.js +0 -16
  96. package/dist/protocol/identity.js.map +0 -1
  97. package/dist/sealed/index.d.ts +0 -6
  98. package/dist/sealed/index.js +0 -6
  99. package/dist/sealed/index.js.map +0 -1
  100. package/dist/vault/secretPolicy.d.ts +0 -3
  101. package/dist/vault/secretPolicy.js +0 -14
  102. package/dist/vault/secretPolicy.js.map +0 -1
  103. package/dist/vault/vault.d.ts +0 -100
  104. package/dist/vault/vault.js +0 -603
  105. package/dist/vault/vault.js.map +0 -1
  106. package/docs/TODO-multi-vault.md +0 -29
  107. package/docs/spec/runtime/README.md +0 -44
  108. package/docs/spec/runtime/activity-log.md +0 -71
  109. package/docs/spec/runtime/exposure-surfaces.md +0 -99
  110. package/docs/spec/runtime/managed-agent-record.md +0 -52
  111. package/docs/spec/runtime/merge-rules.md +0 -52
  112. package/docs/spec/runtime/secret-origin-policy.md +0 -46
  113. package/docs/spec/runtime/secret-validation.md +0 -113
@@ -0,0 +1,48 @@
1
+ function normalizeMethod(method) {
2
+ const normalized = method.trim().toUpperCase();
3
+ if (!normalized) {
4
+ throw new Error("VAULT_FLOW_METHOD_REQUIRED");
5
+ }
6
+ return normalized;
7
+ }
8
+ export function createOwnerHttpFlowBoundary(boundary) {
9
+ const normalized = {
10
+ ...boundary,
11
+ method: normalizeMethod(boundary.method),
12
+ };
13
+ if (normalized.mode !== "send_secret" && !normalized.responseSecret) {
14
+ throw new Error("VAULT_FLOW_RESPONSE_SECRET_REQUIRED");
15
+ }
16
+ return normalized;
17
+ }
18
+ export function createStandardAcquireBoundary(input) {
19
+ return createOwnerHttpFlowBoundary({
20
+ mode: "acquire_secret",
21
+ targetUrl: input.targetUrl,
22
+ method: input.method ?? "POST",
23
+ responseVisibility: "shape_only",
24
+ responseSecret: {
25
+ kind: "json_field",
26
+ field: input.responseField,
27
+ storeAlias: input.storeAlias,
28
+ },
29
+ });
30
+ }
31
+ export function createStandardDispatchBoundary(input) {
32
+ return createOwnerHttpFlowBoundary({
33
+ mode: "send_secret",
34
+ targetUrl: input.targetUrl,
35
+ method: input.method,
36
+ responseVisibility: "passthrough",
37
+ });
38
+ }
39
+ export function toOwnerHttpFlowBoundary(flow) {
40
+ return createOwnerHttpFlowBoundary({
41
+ mode: flow.mode,
42
+ targetUrl: flow.targetUrl,
43
+ method: flow.method,
44
+ responseVisibility: flow.responseVisibility,
45
+ responseSecret: flow.responseSecret,
46
+ });
47
+ }
48
+ //# sourceMappingURL=flow-factories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-factories.js","sourceRoot":"","sources":["../../src/vault-ingress/flow-factories.ts"],"names":[],"mappings":"AAcA,SAAS,eAAe,CAAC,MAAc;IACrC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC/C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,QAA+B;IACzE,MAAM,UAAU,GAAG;QACjB,GAAG,QAAQ;QACX,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC;KACzC,CAAC;IACF,IAAI,UAAU,CAAC,IAAI,KAAK,aAAa,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC;QACpE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,KAK7C;IACC,OAAO,2BAA2B,CAAC;QACjC,IAAI,EAAE,gBAAgB;QACtB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,MAAM;QAC9B,kBAAkB,EAAE,YAAY;QAChC,cAAc,EAAE;YACd,IAAI,EAAE,YAAY;YAClB,KAAK,EAAE,KAAK,CAAC,aAAa;YAC1B,UAAU,EAAE,KAAK,CAAC,UAAU;SAC7B;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,8BAA8B,CAAC,KAG9C;IACC,OAAO,2BAA2B,CAAC;QACjC,IAAI,EAAE,aAAa;QACnB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,kBAAkB,EAAE,aAAa;KAClC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,IAGvC;IACC,OAAO,2BAA2B,CAAC;QACjC,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;QAC3C,cAAc,EAAE,IAAI,CAAC,cAAc;KACpC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,81 @@
1
+ import { type AgentCapability, type VaultCore, type VaultCoreDependencies, type DispatchRequest, type DispatchResult, type Clock, type OwnerAuditRequest, type OwnerRegisterAgentIdentityCommand, type OwnerRegisterCustomHttpFlowCommand, type OwnerRegisterOwnerIdentityCommand, type CustomHttpFlowDefinition, type OwnerIdentityRecord, type SecretRecord, type VaultId } from "../vault-core/index.js";
2
+ export type RedactedResponseShape = null | string | number | boolean | RedactedResponseShape[] | {
3
+ [key: string]: RedactedResponseShape;
4
+ };
5
+ export type VaultAcquireSecretFlow = "oauth_token_response.access_token" | "oauth_token_response.refresh_token" | "openid_token_response.id_token";
6
+ export interface VaultCapabilityResolver {
7
+ resolve(vaultId: VaultId, agentId: string, capabilityId: string): Promise<AgentCapability>;
8
+ }
9
+ export interface VaultAgentDispatchRequest {
10
+ vaultId: string;
11
+ requestId: string;
12
+ requestedAt: string;
13
+ agentId: string;
14
+ capabilityId: string;
15
+ secretAlias?: string;
16
+ targetUrl: string;
17
+ method: string;
18
+ headers?: Record<string, string>;
19
+ body?: string;
20
+ proof: {
21
+ signature: string;
22
+ };
23
+ }
24
+ export interface VaultAgentDispatchResponse {
25
+ ok: true;
26
+ result: DispatchResult;
27
+ }
28
+ export interface VaultAgentDispatchErrorResponse {
29
+ ok: false;
30
+ error: {
31
+ code: string;
32
+ message: string;
33
+ };
34
+ }
35
+ export interface VaultAcquireSecretInput {
36
+ alias: string;
37
+ issuerId: string;
38
+ url: string;
39
+ flow: VaultAcquireSecretFlow;
40
+ method?: string;
41
+ headers?: Record<string, string>;
42
+ body?: string;
43
+ requestedAt?: string;
44
+ }
45
+ export interface VaultAcquireSecretResult {
46
+ vaultId: VaultId;
47
+ alias: string;
48
+ status: "stored";
49
+ responseStatus: number;
50
+ contentType: string | null;
51
+ responseShape: RedactedResponseShape;
52
+ }
53
+ export interface VaultCustomFlowResolver {
54
+ get(vaultId: VaultId, flowId: string): Promise<CustomHttpFlowDefinition | null>;
55
+ }
56
+ export interface VaultService {
57
+ readonly vaultId: VaultCore["vaultId"];
58
+ bootstrapOwnerIdentity(request: OwnerIdentityRecord): Promise<void>;
59
+ registerAgentIdentity(request: OwnerRegisterAgentIdentityCommand): Promise<void>;
60
+ registerOwnerIdentity(request: OwnerRegisterOwnerIdentityCommand): Promise<void>;
61
+ registerCustomFlow(request: OwnerRegisterCustomHttpFlowCommand): Promise<void>;
62
+ writeSecret(request: import("../vault-core/index.js").VaultWriteSecretCommand): Promise<SecretRecord>;
63
+ acquireSecret(request: VaultAcquireSecretInput): Promise<VaultAcquireSecretResult>;
64
+ dispatch(request: DispatchRequest): Promise<DispatchResult>;
65
+ handleAgentDispatch(request: VaultAgentDispatchRequest): Promise<VaultAgentDispatchResponse | VaultAgentDispatchErrorResponse>;
66
+ readAudit(request: OwnerAuditRequest): Promise<readonly import("../vault-core/index.js").AuditEntry[]>;
67
+ }
68
+ export declare function createVaultService(deps: VaultCoreDependencies, options?: {
69
+ capabilities?: VaultCapabilityResolver;
70
+ customFlows?: VaultCustomFlowResolver;
71
+ clock?: Clock;
72
+ fetchImpl?: typeof fetch;
73
+ }): VaultService;
74
+ export declare function wrapVaultCoreAsVaultService(core: VaultCore, options?: {
75
+ capabilities?: VaultCapabilityResolver;
76
+ customFlows?: VaultCustomFlowResolver;
77
+ clock?: Clock;
78
+ fetchImpl?: typeof fetch;
79
+ }): VaultService;
80
+ export type { OwnerHttpFlowBoundary } from "./flow-factories.js";
81
+ export { createOwnerHttpFlowBoundary, createStandardAcquireBoundary, createStandardDispatchBoundary, toOwnerHttpFlowBoundary, } from "./flow-factories.js";
@@ -0,0 +1,357 @@
1
+ import { createVaultCore, } from "../vault-core/index.js";
2
+ import { createOwnerHttpFlowBoundary, createStandardAcquireBoundary, toOwnerHttpFlowBoundary, } from "./flow-factories.js";
3
+ class LocalVaultService {
4
+ _authority;
5
+ _capabilities;
6
+ _customFlows;
7
+ _clock;
8
+ _fetchImpl;
9
+ constructor(_authority, _capabilities, _customFlows, _clock, _fetchImpl = fetch) {
10
+ this._authority = _authority;
11
+ this._capabilities = _capabilities;
12
+ this._customFlows = _customFlows;
13
+ this._clock = _clock;
14
+ this._fetchImpl = _fetchImpl;
15
+ }
16
+ get vaultId() {
17
+ return this._authority.vaultId;
18
+ }
19
+ bootstrapOwnerIdentity(request) {
20
+ return this._authority.bootstrapOwnerIdentity(request);
21
+ }
22
+ registerAgentIdentity(request) {
23
+ return this._authority.registerAgentIdentity(request);
24
+ }
25
+ registerOwnerIdentity(request) {
26
+ return this._authority.registerOwnerIdentity(request);
27
+ }
28
+ registerCustomFlow(request) {
29
+ return this._authority.registerCustomFlow(request);
30
+ }
31
+ writeSecret(request) {
32
+ return this._authority.writeSecret(request);
33
+ }
34
+ redactResponseShape(value) {
35
+ if (value === null || value === undefined) {
36
+ return null;
37
+ }
38
+ if (Array.isArray(value)) {
39
+ return value.map((entry) => this.redactResponseShape(entry));
40
+ }
41
+ if (typeof value === "object") {
42
+ return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, this.redactResponseShape(entry)]));
43
+ }
44
+ return null;
45
+ }
46
+ buildAcquireResponseShape(flow, payload) {
47
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
48
+ return this.redactResponseShape(payload);
49
+ }
50
+ const record = payload;
51
+ const response = {};
52
+ switch (flow) {
53
+ case "oauth_token_response.access_token":
54
+ case "oauth_token_response.refresh_token":
55
+ case "openid_token_response.id_token": {
56
+ if ("token_type" in record) {
57
+ response.token_type = typeof record.token_type === "string" ? record.token_type : null;
58
+ }
59
+ if ("expires_in" in record) {
60
+ response.expires_in = typeof record.expires_in === "number" ? record.expires_in : null;
61
+ }
62
+ if ("scope" in record) {
63
+ response.scope = typeof record.scope === "string" ? record.scope : null;
64
+ }
65
+ break;
66
+ }
67
+ }
68
+ return response;
69
+ }
70
+ extractSecretForFlow(flow, payload) {
71
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
72
+ throw new Error("VAULT_ACQUISITION_RESPONSE_INVALID");
73
+ }
74
+ const record = payload;
75
+ switch (flow) {
76
+ case "oauth_token_response.access_token": {
77
+ if (typeof record.access_token !== "string" || !record.access_token) {
78
+ throw new Error("VAULT_ACQUISITION_SECRET_NOT_FOUND");
79
+ }
80
+ return record.access_token;
81
+ }
82
+ case "oauth_token_response.refresh_token": {
83
+ if (typeof record.refresh_token !== "string" || !record.refresh_token) {
84
+ throw new Error("VAULT_ACQUISITION_SECRET_NOT_FOUND");
85
+ }
86
+ return record.refresh_token;
87
+ }
88
+ case "openid_token_response.id_token": {
89
+ if (typeof record.id_token !== "string" || !record.id_token) {
90
+ throw new Error("VAULT_ACQUISITION_SECRET_NOT_FOUND");
91
+ }
92
+ return record.id_token;
93
+ }
94
+ }
95
+ }
96
+ parseRawResponse(contentType, rawPayload) {
97
+ if (!rawPayload) {
98
+ return null;
99
+ }
100
+ if (contentType?.includes("json")) {
101
+ return JSON.parse(rawPayload);
102
+ }
103
+ try {
104
+ return JSON.parse(rawPayload);
105
+ }
106
+ catch {
107
+ return rawPayload;
108
+ }
109
+ }
110
+ async fetchAndParse(request) {
111
+ const response = await this._fetchImpl(request.url, {
112
+ method: request.method ?? "GET",
113
+ headers: request.headers,
114
+ body: request.body,
115
+ });
116
+ const contentType = response.headers.get("content-type");
117
+ const rawBody = await response.text();
118
+ return {
119
+ contentType,
120
+ rawBody,
121
+ parsedBody: this.parseRawResponse(contentType, rawBody),
122
+ responseStatus: response.status,
123
+ };
124
+ }
125
+ extractCustomFlowSecret(flow, payload) {
126
+ if (!flow.responseSecret) {
127
+ return null;
128
+ }
129
+ if (flow.responseSecret.kind === "json_field") {
130
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
131
+ throw new Error("VAULT_CUSTOM_FLOW_RESPONSE_INVALID");
132
+ }
133
+ const value = payload[flow.responseSecret.field];
134
+ if (typeof value !== "string" || !value) {
135
+ throw new Error("VAULT_CUSTOM_FLOW_SECRET_NOT_FOUND");
136
+ }
137
+ return value;
138
+ }
139
+ return null;
140
+ }
141
+ async acquireSecret(request) {
142
+ const standardBoundary = createStandardAcquireBoundary({
143
+ targetUrl: request.url,
144
+ method: request.method,
145
+ responseField: request.flow === "oauth_token_response.access_token"
146
+ ? "access_token"
147
+ : request.flow === "oauth_token_response.refresh_token"
148
+ ? "refresh_token"
149
+ : "id_token",
150
+ storeAlias: request.alias,
151
+ });
152
+ const payload = await this.fetchAndParse(request);
153
+ const targetBindings = [{
154
+ kind: "site",
155
+ targetId: request.issuerId,
156
+ targetUrl: standardBoundary.targetUrl,
157
+ methods: [standardBoundary.method],
158
+ paths: [new URL(standardBoundary.targetUrl).pathname || "/"],
159
+ }];
160
+ await this._authority.writeSecret({
161
+ kind: "issuer.write_secret",
162
+ vaultId: this._authority.vaultId,
163
+ issuer: {
164
+ kind: "trusted_issuer",
165
+ id: request.issuerId,
166
+ },
167
+ alias: request.alias,
168
+ plaintext: this.extractSecretForFlow(request.flow, payload.parsedBody),
169
+ issuerSiteId: request.issuerId,
170
+ targetBindings,
171
+ requestedAt: request.requestedAt ?? (this._clock?.nowIso() ?? new Date().toISOString()),
172
+ });
173
+ return {
174
+ vaultId: this._authority.vaultId,
175
+ alias: request.alias,
176
+ status: "stored",
177
+ responseStatus: payload.responseStatus,
178
+ contentType: payload.contentType,
179
+ responseShape: this.buildAcquireResponseShape(request.flow, payload.parsedBody),
180
+ };
181
+ }
182
+ dispatch(request) {
183
+ return this._authority.dispatchSecret(request);
184
+ }
185
+ async handleAgentDispatch(request) {
186
+ try {
187
+ const vaultId = { value: request.vaultId };
188
+ const capability = await this.resolveCapability(vaultId, request.agentId, request.capabilityId);
189
+ const customFlow = capability.operation === "custom_http"
190
+ ? await this.resolveCustomFlow(vaultId, capability.customFlowId)
191
+ : null;
192
+ const boundary = customFlow
193
+ ? toOwnerHttpFlowBoundary(customFlow)
194
+ : createOwnerHttpFlowBoundary({
195
+ mode: "send_secret",
196
+ targetUrl: request.targetUrl,
197
+ method: request.method,
198
+ responseVisibility: "passthrough",
199
+ });
200
+ if (customFlow) {
201
+ if (request.targetUrl !== boundary.targetUrl || request.method.toUpperCase() !== boundary.method.toUpperCase()) {
202
+ throw new Error("VAULT_CUSTOM_FLOW_BINDING_MISMATCH");
203
+ }
204
+ }
205
+ if (boundary.mode === "acquire_secret") {
206
+ if (!customFlow) {
207
+ throw new Error("VAULT_CUSTOM_FLOW_NOT_FOUND");
208
+ }
209
+ const authorization = await this._authority.authorizeDispatch({
210
+ vaultId,
211
+ requestId: request.requestId,
212
+ requestedAt: request.requestedAt,
213
+ agent: {
214
+ kind: "agent",
215
+ id: request.agentId,
216
+ },
217
+ capability,
218
+ proof: {
219
+ agentId: request.agentId,
220
+ signature: request.proof.signature,
221
+ requestId: request.requestId,
222
+ requestedAt: request.requestedAt,
223
+ },
224
+ secretAlias: undefined,
225
+ targetUrl: request.targetUrl,
226
+ method: request.method,
227
+ headers: request.headers,
228
+ body: request.body,
229
+ });
230
+ if (authorization.decision !== "allow") {
231
+ throw new Error("VAULT_CUSTOM_FLOW_DENIED");
232
+ }
233
+ const payload = await this.fetchAndParse({
234
+ url: request.targetUrl,
235
+ method: request.method,
236
+ headers: request.headers,
237
+ body: request.body,
238
+ });
239
+ const acquiredSecret = this.extractCustomFlowSecret(customFlow, payload.parsedBody);
240
+ if (!acquiredSecret || !customFlow.responseSecret) {
241
+ throw new Error("VAULT_CUSTOM_FLOW_SECRET_NOT_FOUND");
242
+ }
243
+ await this._authority.storeCustomFlowSecret(customFlow, customFlow.responseSecret.storeAlias, acquiredSecret);
244
+ return {
245
+ ok: true,
246
+ result: {
247
+ vaultId,
248
+ requestId: request.requestId,
249
+ status: "succeeded",
250
+ targetUrl: request.targetUrl,
251
+ method: request.method,
252
+ responseStatus: payload.responseStatus,
253
+ responseBody: boundary.responseVisibility === "shape_only"
254
+ ? JSON.stringify(this.redactResponseShape(payload.parsedBody))
255
+ : payload.rawBody,
256
+ },
257
+ };
258
+ }
259
+ const result = await this._authority.dispatchSecret({
260
+ vaultId,
261
+ requestId: request.requestId,
262
+ requestedAt: request.requestedAt,
263
+ agent: {
264
+ kind: "agent",
265
+ id: request.agentId,
266
+ },
267
+ capability,
268
+ proof: {
269
+ agentId: request.agentId,
270
+ signature: request.proof.signature,
271
+ requestId: request.requestId,
272
+ requestedAt: request.requestedAt,
273
+ },
274
+ secretAlias: request.secretAlias,
275
+ targetUrl: request.targetUrl,
276
+ method: request.method,
277
+ headers: request.headers,
278
+ body: request.body,
279
+ });
280
+ if (boundary.mode === "bidirectional_secret") {
281
+ if (!customFlow) {
282
+ throw new Error("VAULT_CUSTOM_FLOW_NOT_FOUND");
283
+ }
284
+ const parsedBody = this.parseBody(result.responseBody);
285
+ const acquiredSecret = this.extractCustomFlowSecret(customFlow, parsedBody);
286
+ if (!acquiredSecret || !customFlow.responseSecret) {
287
+ throw new Error("VAULT_CUSTOM_FLOW_SECRET_NOT_FOUND");
288
+ }
289
+ await this._authority.storeCustomFlowSecret(customFlow, customFlow.responseSecret.storeAlias, acquiredSecret);
290
+ }
291
+ return {
292
+ ok: true,
293
+ result: boundary.responseVisibility === "shape_only"
294
+ ? {
295
+ ...result,
296
+ responseBody: JSON.stringify(this.redactResponseShape(this.parseBody(result.responseBody))),
297
+ }
298
+ : result,
299
+ };
300
+ }
301
+ catch (error) {
302
+ const message = error instanceof Error ? error.message : String(error);
303
+ const code = error instanceof Error && "code" in error && typeof error.code === "string"
304
+ ? error.code
305
+ : "VAULT_AGENT_DISPATCH_REJECTED";
306
+ return {
307
+ ok: false,
308
+ error: { code, message },
309
+ };
310
+ }
311
+ }
312
+ readAudit(request) {
313
+ return this._authority.getAudit(request.actor, request.query, {
314
+ requestId: request.requestId,
315
+ requestedAt: request.requestedAt,
316
+ proof: request.proof,
317
+ });
318
+ }
319
+ async resolveCapability(vaultId, agentId, capabilityId) {
320
+ if (!this._capabilities) {
321
+ throw new Error("VAULT_CAPABILITY_RESOLVER_NOT_CONFIGURED");
322
+ }
323
+ return this._capabilities.resolve(vaultId, agentId, capabilityId);
324
+ }
325
+ parseBody(body) {
326
+ if (!body) {
327
+ return null;
328
+ }
329
+ try {
330
+ return JSON.parse(body);
331
+ }
332
+ catch {
333
+ return body;
334
+ }
335
+ }
336
+ async resolveCustomFlow(vaultId, flowId) {
337
+ if (!flowId) {
338
+ throw new Error("VAULT_CUSTOM_FLOW_NOT_PROVIDED");
339
+ }
340
+ if (!this._customFlows) {
341
+ throw new Error("VAULT_CUSTOM_FLOW_RESOLVER_NOT_CONFIGURED");
342
+ }
343
+ const flow = await this._customFlows.get(vaultId, flowId);
344
+ if (!flow) {
345
+ throw new Error("VAULT_CUSTOM_FLOW_NOT_FOUND");
346
+ }
347
+ return flow;
348
+ }
349
+ }
350
+ export function createVaultService(deps, options = {}) {
351
+ return new LocalVaultService(createVaultCore(deps), options.capabilities, options.customFlows ?? deps.customFlows, options.clock, options.fetchImpl);
352
+ }
353
+ export function wrapVaultCoreAsVaultService(core, options = {}) {
354
+ return new LocalVaultService(core, options.capabilities, options.customFlows, options.clock, options.fetchImpl);
355
+ }
356
+ export { createOwnerHttpFlowBoundary, createStandardAcquireBoundary, createStandardDispatchBoundary, toOwnerHttpFlowBoundary, } from "./flow-factories.js";
357
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/vault-ingress/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,GAiBhB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,2BAA2B,EAC3B,6BAA6B,EAC7B,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AA0F7B,MAAM,iBAAiB;IAEF;IACA;IACA;IACA;IACA;IALnB,YACmB,UAAqB,EACrB,aAAuC,EACvC,YAAsC,EACtC,MAAc,EACd,aAA2B,KAAK;QAJhC,eAAU,GAAV,UAAU,CAAW;QACrB,kBAAa,GAAb,aAAa,CAA0B;QACvC,iBAAY,GAAZ,YAAY,CAA0B;QACtC,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAsB;IAChD,CAAC;IAEJ,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;IACjC,CAAC;IAED,sBAAsB,CAAC,OAA4B;QACjD,OAAO,IAAI,CAAC,UAAU,CAAC,sBAAsB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CAAC;QACD,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC/D,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,MAAM,UAAU,kBAAkB,CAChC,IAA2B,EAC3B,UAKI,EAAE;IAEN,OAAO,IAAI,iBAAiB,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;AACvJ,CAAC;AAED,MAAM,UAAU,2BAA2B,CACzC,IAAe,EACf,UAKI,EAAE;IAEN,OAAO,IAAI,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;AAClH,CAAC;AAGD,OAAO,EACL,2BAA2B,EAC3B,6BAA6B,EAC7B,8BAA8B,EAC9B,uBAAuB,GACxB,MAAM,qBAAqB,CAAC"}
@@ -1,100 +1,68 @@
1
- # CBIO Runtime Architecture
1
+ # Architecture
2
2
 
3
- This document defines the architectural boundaries and naming rules for the runtime.
3
+ Current product architecture is vault-first.
4
4
 
5
- For cross-language runtime rules that Node and Rust must share, see [spec/runtime/README.md](./spec/runtime/README.md).
5
+ ## Public Modules
6
6
 
7
- ## Layer Boundaries
7
+ - `vault-core`
8
+ Stores secret plaintext, validates writes, validates dispatch, appends audit, invokes trusted executors.
8
9
 
9
- - `runtime/`: public consumer surface only.
10
- - `protocol/`: protocol adapters and identity/crypto helpers layered on top of `cbio-protocol`.
11
- - `vault/`: local secret storage, persistence, recovery, and secret policy enforcement.
12
- - `agent/`: identity and managed-agent orchestration.
13
- - `http/`: HTTP-facing workflows and local proxy helpers.
14
- - `audit/`: activity log data structures and persistence helpers.
15
- - `docs/`: examples, guidance, and integration patterns. Not executable product logic.
16
- - `docs/spec/runtime/`: shared runtime contracts for multi-language implementations.
10
+ - `clients/owner`
11
+ Owner-facing client for secret writes and audit reads.
17
12
 
18
- ## Naming Rules
13
+ - `clients/agent`
14
+ Agent-facing client for signed dispatch requests. It never receives secret plaintext.
19
15
 
20
- ### 1. One name, one layer
16
+ - `vault-ingress`
17
+ Accepts request-shaped calls, resolves capability inside the vault boundary, performs trusted acquisition flows, and forwards dispatch into vault-core internals.
21
18
 
22
- Do not use the same term for different layers of authority or behavior.
19
+ ## Core Rules
23
20
 
24
- - Protocol-level privileges must be named differently from runtime handle permissions.
25
- - Internal storage records must not be named like public API concepts.
21
+ 1. Secret plaintext exists only inside vault-core.
22
+ 2. Only owner and trusted issuer paths may write secrets.
23
+ 3. Agent can only request dispatch through capability + proof.
24
+ 4. Vault validates and audits every dispatch.
26
25
 
27
- Good examples:
26
+ ## Current HTTP Secret Flows
28
27
 
29
- - `issuedCapabilities`: privileges embedded into a signed identity document
30
- - `runtimePermissions`: permissions granted to a returned `CbioAgent` handle
28
+ The current runtime surface supports two explicit flow classes:
31
29
 
32
- ### 2. Name by responsibility
30
+ - `acquire_secret`
31
+ Vault performs an acquisition flow, stores the extracted secret, and returns only protocol metadata plus a flow-specific redacted response shape.
33
32
 
34
- Names should describe what the code does, not merely what topic it is near.
33
+ - `send_secret`
34
+ Vault sends a stored secret to an approved target and returns the remote response as normal agent-visible output.
35
+ This is the standard secret-use path, not the acquisition path.
35
36
 
36
- Good:
37
+ The runtime does not attempt to enumerate or understand arbitrary remote protocols. Acquisition is limited to built-in standard flows rather than caller-defined extraction logic. Unsupported mixed or non-secret flows are outside the current production surface.
37
38
 
38
- - `startLocalAuthProxy`
39
- - `fetchWithAuth`
40
- - `getManagedAgentCapabilities`
39
+ This is deliberate rather than accidental:
41
40
 
42
- Bad:
41
+ - acquisition flows are treated as sensitive on the response path because they may mint or return new secret material
42
+ - built-in acquisition flows may still expose protocol-defined non-sensitive fields such as expiry or token type
43
+ - normal secret-backed dispatch is treated as a standard protocol call to an owner-approved target
43
44
 
44
- - vague helper names
45
- - names that only imply a provider or product example
45
+ If a target returns sensitive values during a normal dispatch flow, the vault does not try to reinterpret the remote protocol and redact it retroactively. That responsibility belongs to the remote protocol contract and the owner's authorization boundary.
46
46
 
47
- ### 3. Name public contracts by actual requirements
47
+ ## Owner-Defined Custom HTTP Flows
48
48
 
49
- Public option and parameter names must reflect what callers truly need.
49
+ The current runtime also exposes a narrow exception path for non-standard integrations:
50
50
 
51
- Good:
51
+ - owner registers a `custom_http` flow
52
+ - the flow fixes `mode`, `targetUrl`, `method`, and `responseVisibility`
53
+ - agent capabilities reference `customFlowId`
54
+ - agent may trigger the flow, but may not redefine it
52
55
 
53
- - `IdentityLoadKeys`: requires `privateKey`, allows optional `publicKey`
56
+ The owner HTTP boundary itself is modeled as a factory surface:
54
57
 
55
- Bad:
58
+ - `createOwnerHttpFlowBoundary(...)`
59
+ - `createStandardAcquireBoundary(...)`
60
+ - `createStandardDispatchBoundary(...)`
56
61
 
57
- - names that imply stronger requirements than the implementation actually needs
62
+ This keeps the escape hatch inside the vault boundary rather than reopening caller-defined open extraction or open response policies.
58
63
 
59
- ### 4. Do not promote examples into core abstractions
64
+ Current custom modes are:
60
65
 
61
- Common configurations belong in docs, not in the core naming system.
62
-
63
- - External service examples such as OpenAI, Anthropic, or Resend are documentation concerns.
64
- - Core APIs should accept general configuration such as `upstreamBaseUrl`, `authHeaderName`, and `authPrefix`.
65
-
66
- ### 5. Split option objects by operation
67
-
68
- If one options type starts describing multiple operations, split it.
69
-
70
- A single options object may still group inputs that are consumed by one concrete operation path.
71
- For example, an identity load API may accept both storage binding and issued-identity binding if both are applied during the same load step.
72
-
73
- Good:
74
-
75
- - `ManagedAgentIssueOptions`
76
- - `ManagedAgentLoadOptions`
77
- - `RegisterChildIdentityOptions`
78
-
79
- Bad:
80
-
81
- - one broad options object that mixes issue, load, storage, and permission semantics
82
-
83
- ### 6. Internal escape hatches stay internal
84
-
85
- If a method exists only to let implementation pieces cooperate, it should not become part of the public API shape.
86
-
87
- - Prefer module-local coordination over public bridge methods.
88
- - Avoid exposing internal records, vault objects, or persistence schemas from `runtime/`.
89
-
90
- ## Review Checklist
91
-
92
- When evaluating a new function, type, or field name, ask:
93
-
94
- 1. Does this name describe one thing only?
95
- 2. Does it reveal the correct layer and authority level?
96
- 3. Would a user infer the correct behavior without reading implementation code?
97
- 4. Is this a stable domain concept, or just a popular example?
98
- 5. Is this exposing an internal detail as if it were public API?
99
-
100
- If any answer is "no", rename or split before expanding the API surface.
66
+ - `acquire_secret`
67
+ - `send_secret`
68
+ - `bidirectional_secret`