@deksden-com/cpa-kit 0.0.0-stage → 0.1.4
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/CHANGELOG.md +8 -0
- package/NOTICE +1 -0
- package/README.md +27 -2
- package/dist/chunk-T47QB7AC.js +234 -0
- package/dist/chunk-T47QB7AC.js.map +1 -0
- package/dist/client/index.d.ts +35 -0
- package/dist/client/index.js +99 -0
- package/dist/client/index.js.map +1 -0
- package/dist/contracts/index.d.ts +571 -0
- package/dist/contracts/index.js +41 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/server/index.d.ts +317 -0
- package/dist/server/index.js +2277 -0
- package/dist/server/index.js.map +1 -0
- package/package.json +53 -3
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { ErrorCode, ErrorDto, Command, Actor, OperationDto, Capabilities, CredentialDto, ReleaseDto, ModelsDto, AcceptResult, StatusDto, ModelDto, ListDto, ImportPreviewDto } from '../contracts/index.js';
|
|
2
|
+
import 'zod';
|
|
3
|
+
|
|
4
|
+
declare class CpaError extends Error {
|
|
5
|
+
code: ErrorCode;
|
|
6
|
+
retryable: boolean;
|
|
7
|
+
retryAt: string | null;
|
|
8
|
+
constructor(code: ErrorCode, message: string, retryable?: boolean, retryAt?: string | null);
|
|
9
|
+
}
|
|
10
|
+
declare function safeError(error: unknown, operationId?: string | null): ErrorDto;
|
|
11
|
+
declare function redactText(text: string): string;
|
|
12
|
+
declare function safeResult(value: Record<string, unknown>): Record<string, unknown>;
|
|
13
|
+
declare function canonical(value: unknown): string;
|
|
14
|
+
declare const hash: (value: unknown) => string;
|
|
15
|
+
declare const newId: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
16
|
+
declare function confined(root: string, name: string): string;
|
|
17
|
+
declare function protectedDir(path: string): Promise<void>;
|
|
18
|
+
declare function atomicJson(path: string, value: unknown): Promise<void>;
|
|
19
|
+
/** POSIX advisory lock: held by a child until stdin closes, survives lease expiry but not process death. */
|
|
20
|
+
declare function osLock(path: string, timeoutMs?: number, options?: {
|
|
21
|
+
mode?: 0o600 | 0o660;
|
|
22
|
+
}): Promise<() => Promise<void>>;
|
|
23
|
+
|
|
24
|
+
interface StoredOperation {
|
|
25
|
+
dto: OperationDto;
|
|
26
|
+
command: Command;
|
|
27
|
+
actor: Actor;
|
|
28
|
+
payloadHash: string;
|
|
29
|
+
fence: number;
|
|
30
|
+
leaseUntil: string | null;
|
|
31
|
+
owner: string | null;
|
|
32
|
+
privateState: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
interface OperationStore {
|
|
35
|
+
accept(command: Command, actor: Actor): Promise<{
|
|
36
|
+
operation: StoredOperation;
|
|
37
|
+
reused: boolean;
|
|
38
|
+
}>;
|
|
39
|
+
get(id: string): Promise<StoredOperation | null>;
|
|
40
|
+
list(): Promise<StoredOperation[]>;
|
|
41
|
+
update(id: string, revision: number, fn: (value: StoredOperation) => void): Promise<StoredOperation>;
|
|
42
|
+
writer<T>(action: () => Promise<T>): Promise<T>;
|
|
43
|
+
reap(now?: number): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
declare function createFsOperationStore(options: {
|
|
46
|
+
root: string;
|
|
47
|
+
clock?: () => number;
|
|
48
|
+
lockTimeoutMs?: number;
|
|
49
|
+
}): OperationStore;
|
|
50
|
+
|
|
51
|
+
interface Credential {
|
|
52
|
+
id: string;
|
|
53
|
+
provider: string;
|
|
54
|
+
body: Record<string, unknown>;
|
|
55
|
+
digest: string;
|
|
56
|
+
}
|
|
57
|
+
interface Candidate {
|
|
58
|
+
id: string;
|
|
59
|
+
actorId: string;
|
|
60
|
+
instanceId: string;
|
|
61
|
+
createdAt: number;
|
|
62
|
+
expiresAt: number;
|
|
63
|
+
credentials: Credential[];
|
|
64
|
+
skipped: number;
|
|
65
|
+
reasons: Record<string, number>;
|
|
66
|
+
preview?: {
|
|
67
|
+
revision: string;
|
|
68
|
+
expiresAt: number;
|
|
69
|
+
mode: "merge" | "replace";
|
|
70
|
+
overwriteIds: string[];
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
interface UploadFile {
|
|
74
|
+
name: string;
|
|
75
|
+
data: Uint8Array;
|
|
76
|
+
}
|
|
77
|
+
declare const defaultLimits: {
|
|
78
|
+
uploadBytes: number;
|
|
79
|
+
entries: number;
|
|
80
|
+
jsonBytes: number;
|
|
81
|
+
acceptedBytes: number;
|
|
82
|
+
expandedBytes: number;
|
|
83
|
+
ratio: number;
|
|
84
|
+
parseMs: number;
|
|
85
|
+
};
|
|
86
|
+
type ImportLimits = typeof defaultLimits;
|
|
87
|
+
declare function parseCredential(data: Uint8Array, limits?: {
|
|
88
|
+
uploadBytes: number;
|
|
89
|
+
entries: number;
|
|
90
|
+
jsonBytes: number;
|
|
91
|
+
acceptedBytes: number;
|
|
92
|
+
expandedBytes: number;
|
|
93
|
+
ratio: number;
|
|
94
|
+
parseMs: number;
|
|
95
|
+
}): Credential | null;
|
|
96
|
+
declare function importFiles(files: UploadFile[], limits?: ImportLimits, duplicatePolicy?: "collapse" | "reject"): Promise<{
|
|
97
|
+
credentials: Credential[];
|
|
98
|
+
skipped: number;
|
|
99
|
+
reasons: Record<string, number>;
|
|
100
|
+
}>;
|
|
101
|
+
interface StagingStore {
|
|
102
|
+
upload(files: UploadFile[], actorId: string, instanceId: string): Promise<string>;
|
|
103
|
+
stage(uploadId: string, actorId: string, instanceId: string): Promise<Candidate>;
|
|
104
|
+
get(id: string, actorId: string, instanceId: string, admin?: boolean): Promise<Candidate>;
|
|
105
|
+
save(candidate: Candidate): Promise<void>;
|
|
106
|
+
remove(id: string): Promise<void>;
|
|
107
|
+
reap(protectedIds: Set<string>): Promise<void>;
|
|
108
|
+
}
|
|
109
|
+
declare function createFsStagingStore(options: {
|
|
110
|
+
root: string;
|
|
111
|
+
limits?: ImportLimits;
|
|
112
|
+
clock?: () => number;
|
|
113
|
+
duplicatePolicy?: "collapse" | "reject";
|
|
114
|
+
}): StagingStore;
|
|
115
|
+
/** Trusted CLI only: never expose directory paths as HTTP inputs. */
|
|
116
|
+
declare function readCredentialDirectory(root: string, limits?: {
|
|
117
|
+
uploadBytes: number;
|
|
118
|
+
entries: number;
|
|
119
|
+
jsonBytes: number;
|
|
120
|
+
acceptedBytes: number;
|
|
121
|
+
expandedBytes: number;
|
|
122
|
+
ratio: number;
|
|
123
|
+
parseMs: number;
|
|
124
|
+
}): Promise<UploadFile[]>;
|
|
125
|
+
|
|
126
|
+
interface Snapshot {
|
|
127
|
+
revision: string;
|
|
128
|
+
credentials: CredentialDto[];
|
|
129
|
+
}
|
|
130
|
+
interface ApplyInput {
|
|
131
|
+
credentials: Credential[];
|
|
132
|
+
mode: "merge" | "replace";
|
|
133
|
+
overwriteIds: string[];
|
|
134
|
+
confirmedRemovals: string[];
|
|
135
|
+
expectedRevision: string;
|
|
136
|
+
}
|
|
137
|
+
interface BackendContext {
|
|
138
|
+
phase(phase: "prepare" | "switch" | "verify" | "commit", state?: Record<string, unknown>): Promise<void>;
|
|
139
|
+
check(): Promise<void>;
|
|
140
|
+
}
|
|
141
|
+
interface Backend {
|
|
142
|
+
capabilities: Capabilities;
|
|
143
|
+
managementAvailability: "available" | "unavailable" | "unknown";
|
|
144
|
+
snapshot(): Promise<Snapshot>;
|
|
145
|
+
apply(input: ApplyInput, ctx: BackendContext): Promise<Record<string, unknown>>;
|
|
146
|
+
delete(id: string, expectedRevision: string, ctx: BackendContext): Promise<Record<string, unknown>>;
|
|
147
|
+
recover(state: Record<string, unknown>): Promise<"verified" | "rolled_back" | "unknown">;
|
|
148
|
+
}
|
|
149
|
+
interface RuntimeLifecycle {
|
|
150
|
+
stop(): Promise<void>;
|
|
151
|
+
start(): Promise<void>;
|
|
152
|
+
inspect(): Promise<{
|
|
153
|
+
version: string | null;
|
|
154
|
+
state: "running" | "stopped" | "unknown";
|
|
155
|
+
}>;
|
|
156
|
+
}
|
|
157
|
+
declare function createReadOnlyBackend(): Backend;
|
|
158
|
+
declare function createInferenceCatalog(options: {
|
|
159
|
+
baseUrl: string;
|
|
160
|
+
secret: () => Promise<string>;
|
|
161
|
+
fetch?: typeof fetch;
|
|
162
|
+
timeoutMs?: number;
|
|
163
|
+
}): () => Promise<{
|
|
164
|
+
id: string;
|
|
165
|
+
capabilities: string[];
|
|
166
|
+
}[]>;
|
|
167
|
+
declare function createManagedFileBackend(options: {
|
|
168
|
+
root: string;
|
|
169
|
+
activePath: string;
|
|
170
|
+
lifecycle: RuntimeLifecycle;
|
|
171
|
+
verify: () => Promise<void>;
|
|
172
|
+
allowUnknownDeletion?: boolean;
|
|
173
|
+
}): Backend;
|
|
174
|
+
interface ManagementTransport {
|
|
175
|
+
request(path: string, init?: RequestInit): Promise<unknown>;
|
|
176
|
+
}
|
|
177
|
+
declare function createManagementTransport(options: {
|
|
178
|
+
baseUrl: string;
|
|
179
|
+
secret: () => Promise<string>;
|
|
180
|
+
fetch?: typeof fetch;
|
|
181
|
+
timeoutMs?: number;
|
|
182
|
+
}): ManagementTransport;
|
|
183
|
+
declare function createPostgresManagementBackend(options: {
|
|
184
|
+
transport: ManagementTransport;
|
|
185
|
+
singleController: boolean;
|
|
186
|
+
verifiedProtocol: boolean;
|
|
187
|
+
allowUnknownDeletion?: boolean;
|
|
188
|
+
}): Backend;
|
|
189
|
+
|
|
190
|
+
interface Authorization {
|
|
191
|
+
check(actor: Actor, instanceId: string, action: string): Promise<boolean>;
|
|
192
|
+
}
|
|
193
|
+
interface Maintenance {
|
|
194
|
+
enter(operationId: string, timeoutMs: number): Promise<void>;
|
|
195
|
+
leave(operationId: string): Promise<void>;
|
|
196
|
+
}
|
|
197
|
+
interface ReleaseAdapter {
|
|
198
|
+
list(): Promise<ReleaseDto[]>;
|
|
199
|
+
discover(): Promise<Record<string, unknown>>;
|
|
200
|
+
install(id: string, ctx: BackendContext): Promise<Record<string, unknown>>;
|
|
201
|
+
activate(id: string, ctx: BackendContext): Promise<Record<string, unknown>>;
|
|
202
|
+
delete(id: string): Promise<Record<string, unknown>>;
|
|
203
|
+
rollback(id: string, ctx: BackendContext): Promise<Record<string, unknown>>;
|
|
204
|
+
recover(state: Record<string, unknown>): Promise<"verified" | "rolled_back" | "unknown">;
|
|
205
|
+
}
|
|
206
|
+
interface ManagerConfig {
|
|
207
|
+
instanceId: string;
|
|
208
|
+
connection: {
|
|
209
|
+
baseUrl: string;
|
|
210
|
+
secretReference: string;
|
|
211
|
+
wireCapabilities: string[];
|
|
212
|
+
};
|
|
213
|
+
modelTtlMs?: number;
|
|
214
|
+
drainTimeoutMs?: number;
|
|
215
|
+
}
|
|
216
|
+
interface ManagerAdapters {
|
|
217
|
+
store: OperationStore;
|
|
218
|
+
staging: StagingStore;
|
|
219
|
+
backend: Backend;
|
|
220
|
+
authorization: Authorization;
|
|
221
|
+
lifecycle?: RuntimeLifecycle;
|
|
222
|
+
catalog?: () => Promise<{
|
|
223
|
+
id: string;
|
|
224
|
+
capabilities: string[];
|
|
225
|
+
}[]>;
|
|
226
|
+
probe?: (input: {
|
|
227
|
+
modelId: string;
|
|
228
|
+
protocol: string;
|
|
229
|
+
reasoningProfile: string | null;
|
|
230
|
+
}, signal: AbortSignal) => Promise<Record<string, unknown>>;
|
|
231
|
+
maintenance?: Maintenance;
|
|
232
|
+
releases?: ReleaseAdapter;
|
|
233
|
+
clock?: () => number;
|
|
234
|
+
onAudit?: (event: {
|
|
235
|
+
operationId: string;
|
|
236
|
+
kind: string;
|
|
237
|
+
state: string;
|
|
238
|
+
}) => Promise<void>;
|
|
239
|
+
modelCache?: {
|
|
240
|
+
get(): Promise<ModelsDto | null>;
|
|
241
|
+
put(value: ModelsDto): Promise<void>;
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
declare function createCpaManager(config: ManagerConfig, adapters: ManagerAdapters): {
|
|
245
|
+
connectionDescriptor: () => {
|
|
246
|
+
wireCapabilities: string[];
|
|
247
|
+
baseUrl: string;
|
|
248
|
+
secretReference: string;
|
|
249
|
+
};
|
|
250
|
+
accept: (input: unknown, actor: Actor) => Promise<AcceptResult>;
|
|
251
|
+
status: (actor: Actor) => Promise<StatusDto>;
|
|
252
|
+
credentials: (actor: Actor) => Promise<{
|
|
253
|
+
apiVersion: 1;
|
|
254
|
+
instanceId: string;
|
|
255
|
+
items: CredentialDto[];
|
|
256
|
+
nextCursor: null;
|
|
257
|
+
}>;
|
|
258
|
+
models: (actor: Actor) => Promise<{
|
|
259
|
+
stale: boolean;
|
|
260
|
+
apiVersion: 1;
|
|
261
|
+
instanceId: string;
|
|
262
|
+
models: ModelDto[];
|
|
263
|
+
fetchedAt: string | null;
|
|
264
|
+
expiresAt: string | null;
|
|
265
|
+
revision: string;
|
|
266
|
+
}>;
|
|
267
|
+
releases: (actor: Actor) => Promise<ListDto<ReleaseDto>>;
|
|
268
|
+
operations: (actor: Actor, options?: {
|
|
269
|
+
limit?: number;
|
|
270
|
+
cursor?: string;
|
|
271
|
+
}) => Promise<ListDto<OperationDto>>;
|
|
272
|
+
operation: (id: string, actor: Actor) => Promise<OperationDto>;
|
|
273
|
+
preview: (candidateId: string, actor: Actor, options?: {
|
|
274
|
+
mode?: "merge" | "replace";
|
|
275
|
+
overwriteIds?: string[];
|
|
276
|
+
}) => Promise<ImportPreviewDto>;
|
|
277
|
+
upload: (files: UploadFile[], actor: Actor) => Promise<{
|
|
278
|
+
apiVersion: 1;
|
|
279
|
+
uploadId: string;
|
|
280
|
+
}>;
|
|
281
|
+
executeOperation: (id: string) => Promise<OperationDto | undefined>;
|
|
282
|
+
recoverOperations: () => Promise<void>;
|
|
283
|
+
reapStaging: () => Promise<void>;
|
|
284
|
+
};
|
|
285
|
+
type CpaManager = ReturnType<typeof createCpaManager>;
|
|
286
|
+
declare const executeOperation: (manager: CpaManager, id: string) => Promise<OperationDto | undefined>;
|
|
287
|
+
declare const recoverOperations: (manager: CpaManager) => Promise<void>;
|
|
288
|
+
declare const reapStaging: (manager: CpaManager) => Promise<void>;
|
|
289
|
+
|
|
290
|
+
declare function createLinuxRuntimeLifecycle(options: {
|
|
291
|
+
helperPath: string;
|
|
292
|
+
version: () => Promise<string | null>;
|
|
293
|
+
timeoutMs?: number;
|
|
294
|
+
}): RuntimeLifecycle;
|
|
295
|
+
interface ApprovedRelease {
|
|
296
|
+
id: string;
|
|
297
|
+
version: string;
|
|
298
|
+
url: string;
|
|
299
|
+
sha256: string;
|
|
300
|
+
asset: "binary" | "tar.gz";
|
|
301
|
+
binaryName?: string;
|
|
302
|
+
}
|
|
303
|
+
interface ApprovedReleaseSource {
|
|
304
|
+
discover(): Promise<ApprovedRelease[]>;
|
|
305
|
+
allowedHosts: string[];
|
|
306
|
+
}
|
|
307
|
+
declare function createManagedReleaseAdapter(options: {
|
|
308
|
+
root: string;
|
|
309
|
+
activePath: string;
|
|
310
|
+
source: ApprovedReleaseSource;
|
|
311
|
+
runtime: RuntimeLifecycle;
|
|
312
|
+
verify: () => Promise<void>;
|
|
313
|
+
fetch?: typeof fetch;
|
|
314
|
+
maxDownloadBytes?: number;
|
|
315
|
+
}): ReleaseAdapter;
|
|
316
|
+
|
|
317
|
+
export { type ApplyInput, type ApprovedRelease, type ApprovedReleaseSource, type Authorization, type Backend, type BackendContext, type Candidate, CpaError, type CpaManager, type Credential, type ImportLimits, type Maintenance, type ManagementTransport, type ManagerAdapters, type ManagerConfig, type OperationStore, type ReleaseAdapter, type RuntimeLifecycle, type Snapshot, type StagingStore, type StoredOperation, type UploadFile, atomicJson, canonical, confined, createCpaManager, createFsOperationStore, createFsStagingStore, createInferenceCatalog, createLinuxRuntimeLifecycle, createManagedFileBackend, createManagedReleaseAdapter, createManagementTransport, createPostgresManagementBackend, createReadOnlyBackend, defaultLimits, executeOperation, hash, importFiles, newId, osLock, parseCredential, protectedDir, readCredentialDirectory, reapStaging, recoverOperations, redactText, safeError, safeResult };
|