@capsulos/sdk 0.0.0-stage → 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.
package/src/types.ts ADDED
@@ -0,0 +1,185 @@
1
+ // The three axes of capsulos (docs/ARCHITECTURE.md):
2
+ // Provider — where a capsule runs (lambda, docker, later firecracker)
3
+ // Primitives — what a capsule exposes (process, fs, pty, ports)
4
+ // Drivers — how a primitive is implemented (fs: local, tmpfs, overlay, s3)
5
+
6
+ /** Where a capsule lives. Implemented by @capsulos/provider-* packages. */
7
+ export interface Provider {
8
+ readonly name: string;
9
+ /** Create a capsule and wait until it runs (see CreateOptions for the wait). */
10
+ create(spec: CapsuleSpec, opts?: CreateOptions): Promise<CapsuleHandle>;
11
+ get(id: string): Promise<CapsuleInfo | null>;
12
+ /** Capsules this provider knows about, optionally only those of one template. */
13
+ list(template?: string): Promise<CapsuleInfo[]>;
14
+ terminate(id: string): Promise<void>;
15
+ /** How to reach the daemon of an existing capsule (endpoint + auth headers). */
16
+ connect(id: string): Promise<Connection>;
17
+ }
18
+
19
+ export interface CreateOptions {
20
+ /**
21
+ * How long to wait for the capsule to run before giving up (provider
22
+ * default: 120 s). On timeout the provider terminates what it started, so
23
+ * nothing is left running without an owner, and throws a CapsuleError
24
+ * whose `capsuleId` names it.
25
+ */
26
+ timeoutMs?: number;
27
+ /** Abort the wait (same clean-up as a timeout). */
28
+ signal?: AbortSignal;
29
+ }
30
+
31
+ export interface HeadersOptions {
32
+ /** Discard any cached credential and mint a new one (after a 401/403). */
33
+ fresh?: boolean;
34
+ }
35
+
36
+ export interface Connection {
37
+ /** Base URL of capsulod, e.g. https://abc.microvm.lambda-url.us-east-1.on.aws */
38
+ baseUrl: string;
39
+ /** Headers every request must carry (e.g. X-aws-proxy-auth). Cached by the provider; `fresh` re-mints. */
40
+ headers(opts?: HeadersOptions): Promise<Record<string, string>>;
41
+ }
42
+
43
+ export type CapsuleState = 'pending' | 'running' | 'suspended' | 'terminated' | 'unknown';
44
+
45
+ export interface CapsuleInfo {
46
+ id: string;
47
+ provider: string;
48
+ state: CapsuleState;
49
+ template: string | null;
50
+ createdAt: Date | null;
51
+ /** When the provider terminated it (provider clock); null while alive or unknown. */
52
+ terminatedAt?: Date | null;
53
+ /** The provider's reason for the current state (e.g. why it died), when it gives one. */
54
+ stateReason?: string | null;
55
+ /** Where capsulod answers (the Connection's baseUrl), when the provider knows it without another call. */
56
+ endpoint?: string | null;
57
+ /** Version of the template the capsule runs (a MicrovmImage version on Lambda). */
58
+ templateVersion?: string | null;
59
+ /** The hard wall-clock limit it was created with. */
60
+ maxDurationSeconds?: number | null;
61
+ }
62
+
63
+ export interface CapsuleHandle extends CapsuleInfo {
64
+ connection: Connection;
65
+ }
66
+
67
+ /** A mount declared at creation. `posix` drivers are mounted in the kernel and seen by processes. */
68
+ export type MountSpec =
69
+ | { driver: 'local' }
70
+ | { driver: 'tmpfs'; sizeMb?: number }
71
+ | { driver: 'overlay'; lower: string }
72
+ | { driver: 's3'; bucket: string; prefix?: string; readOnly?: boolean; region?: string };
73
+
74
+ export interface MountResult {
75
+ path: string;
76
+ driver: string;
77
+ ok: boolean;
78
+ error?: string;
79
+ }
80
+
81
+ export interface Health {
82
+ ok: boolean;
83
+ version: string;
84
+ uptimeS: number;
85
+ /** True once the mount table was applied (by the boot hook or /configure). */
86
+ configured: boolean;
87
+ mounts?: MountResult[];
88
+ /** The template's long-running process (CAPSULOD_START), when the template declares one. */
89
+ service?: ServiceStatus;
90
+ }
91
+
92
+ export interface ServiceStatus {
93
+ cmd: string;
94
+ pid: number;
95
+ running: boolean;
96
+ restarts: number;
97
+ lastExitCode?: number;
98
+ startedAt?: string;
99
+ }
100
+
101
+ export interface IdlePolicy {
102
+ /** Suspend after this long without traffic (seconds). */
103
+ suspendAfterSeconds: number;
104
+ /** Destroy after this long suspended (seconds). */
105
+ destroyAfterSeconds: number;
106
+ }
107
+
108
+ export interface CapsuleSpec {
109
+ /** Template (image) name as registered with the provider. */
110
+ template: string;
111
+ /** Hard wall-clock limit for the capsule, in seconds. */
112
+ maxDurationSeconds?: number;
113
+ idle?: IdlePolicy;
114
+ mounts?: Record<string, MountSpec>;
115
+ /** Opaque per-capsule configuration delivered to the daemon at boot (never secrets). */
116
+ metadata?: Record<string, string>;
117
+ /** Idempotency key: creating twice with the same key returns the same capsule. */
118
+ clientToken?: string;
119
+ }
120
+
121
+ // ---- process primitive ----
122
+
123
+ export interface ExecOptions {
124
+ args?: string[];
125
+ cwd?: string;
126
+ env?: Record<string, string>;
127
+ stdin?: string;
128
+ timeoutMs?: number;
129
+ onStdout?: (chunk: string) => void;
130
+ onStderr?: (chunk: string) => void;
131
+ }
132
+
133
+ export interface ExecResult {
134
+ exitCode: number;
135
+ stdout: string;
136
+ stderr: string;
137
+ timeout: boolean;
138
+ error?: string;
139
+ durationMs: number;
140
+ }
141
+
142
+ export type ExecEvent =
143
+ | { type: 'stdout'; data: string }
144
+ | { type: 'stderr'; data: string }
145
+ | { type: 'exit'; exitCode: number; timeout?: boolean; error?: string };
146
+
147
+ // ---- pty primitive ----
148
+
149
+ export interface PtyOptions {
150
+ /** Program to run; defaults to bash when the template has it, else sh. */
151
+ cmd?: string;
152
+ args?: string[];
153
+ cwd?: string;
154
+ env?: Record<string, string>;
155
+ cols?: number;
156
+ rows?: number;
157
+ onData?: (chunk: Uint8Array) => void;
158
+ connectTimeoutMs?: number;
159
+ }
160
+
161
+ // ---- fs primitive ----
162
+
163
+ export interface FileEntry {
164
+ name: string;
165
+ path: string;
166
+ isDir: boolean;
167
+ size: number;
168
+ mode: string;
169
+ modTime: string;
170
+ }
171
+
172
+ export class CapsuleError extends Error {
173
+ /** The capsule the error is about, when there is one (e.g. the one a create() timeout terminated). */
174
+ readonly capsuleId?: string;
175
+
176
+ constructor(
177
+ message: string,
178
+ readonly status?: number,
179
+ opts: { capsuleId?: string } = {},
180
+ ) {
181
+ super(message);
182
+ this.name = 'CapsuleError';
183
+ if (opts.capsuleId) this.capsuleId = opts.capsuleId;
184
+ }
185
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.