condensationai 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Condensation contributors
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,72 @@
1
+ # condensationai
2
+
3
+ JavaScript and TypeScript SDK for Condensation. The package ships ESM, CommonJS,
4
+ and TypeScript declarations with no runtime dependencies. Requires Node.js 20+.
5
+
6
+ ## Install
7
+
8
+ ```sh
9
+ npm install condensationai
10
+ ```
11
+
12
+ Sign in at https://workspaces.condensation.ai/account using Codegraff and create a
13
+ sandbox API key. Set `CONDENSATION_API_KEY` in your server environment. Never
14
+ embed it in browser code or commit it to Git.
15
+
16
+ ```ts
17
+ import { Condensation } from 'condensationai';
18
+
19
+ const client = new Condensation();
20
+ const wallet = await client.wallet();
21
+ console.log(wallet.purchasedMicroUsd / 1_000_000);
22
+
23
+ const sandbox = await client.create({ language: 'python', autoStopMinutes: 5 });
24
+ try {
25
+ const result = await client.run(sandbox.id, 'python -c "print(1 + 1)"');
26
+ console.log(result.result);
27
+ } finally {
28
+ await client.delete(sandbox.id);
29
+ }
30
+ ```
31
+
32
+ The same example works in JavaScript. CommonJS: `const { Condensation } =
33
+ require('condensationai')`.
34
+
35
+ ## Billing and access
36
+
37
+ Purchased credits use the existing Codegraff balance, shared with nanohub and
38
+ Condensation. This first SDK release routes sandboxes through Codegraff's existing
39
+ gateway and uses that gateway's resource rates, not the Condensation fleet rates
40
+ on the pricing page. Condensation monthly bonuses do not fund this gateway path;
41
+ Build checkout remains disabled until that integration is ready. Inspect the
42
+ sandbox meter and configure a small auto-stop window. Stopped sandboxes can still
43
+ incur storage charges; delete them when finished.
44
+
45
+ SDK keys can read their owner's wallet and manage that account's sandboxes. They
46
+ cannot access inference, GitHub credentials, chat sessions, billing mutations, or
47
+ admin endpoints. They see the owner's Codegraff sandboxes too. The configured
48
+ monthly key budget is checked by the gateway at request admission; concurrent or
49
+ already-running work can exceed a budget. The shared account balance remains the
50
+ funding source.
51
+
52
+ ## API
53
+
54
+ - `wallet()`, `list()`, `get(id)`, `create(options)`
55
+ - `run(id, command, options)`, `runAsync(id, command, options)`
56
+ - `execution(id, execId)`, `cancelExecution(id, execId)`
57
+ - `uploadBase64(id, path, contentBase64)`, `downloadBase64(id, path)`
58
+ - `meter(id)`, `stop(id)`, `start(id)`, `delete(id)`
59
+
60
+ File operations reflect the gateway API. Its current download implementation is
61
+ text-oriented; arbitrary binary round trips are not guaranteed.
62
+
63
+ `new Condensation({ apiKey, baseUrl, timeoutMs, fetch })` supports explicit
64
+ configuration and injected fetch for tests. The default base URL is
65
+ `https://api.condensation.ai`; the default timeout is 120 seconds.
66
+
67
+ Requests never follow redirects or retry automatically. On a failed create,
68
+ command, or deletion, inspect state before repeating it: the server may have
69
+ completed the operation. `CondensationError.status` carries the HTTP status (zero
70
+ for a transport failure), and `.details` carries the API error body.
71
+
72
+ Source contract: `api/openapi.json` in the Condensation repository.
package/dist/index.cjs ADDED
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Condensation: () => Condensation,
24
+ CondensationError: () => CondensationError,
25
+ default: () => index_default
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+ var CondensationError = class extends Error {
29
+ constructor(message, status, details) {
30
+ super(message);
31
+ this.status = status;
32
+ this.details = details;
33
+ this.name = "CondensationError";
34
+ }
35
+ };
36
+ function identifier(value) {
37
+ if (!/^[a-zA-Z0-9_-]+$/.test(value)) throw new TypeError("Invalid sandbox or execution ID");
38
+ return value;
39
+ }
40
+ var Condensation = class {
41
+ apiKey;
42
+ baseUrl;
43
+ timeoutMs;
44
+ transport;
45
+ constructor(options = {}) {
46
+ const env = globalThis.process?.env;
47
+ const apiKey = options.apiKey || env?.CONDENSATION_API_KEY;
48
+ if (!apiKey) throw new TypeError("Set CONDENSATION_API_KEY or pass apiKey");
49
+ const url = new URL(options.baseUrl || "https://api.condensation.ai");
50
+ const local = url.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
51
+ if (url.protocol !== "https:" && !local || url.username || url.password || url.search || url.hash || url.pathname !== "/") throw new TypeError("baseUrl must be an HTTPS origin (HTTP is allowed for localhost)");
52
+ this.apiKey = apiKey;
53
+ this.baseUrl = url.origin;
54
+ this.timeoutMs = options.timeoutMs ?? 12e4;
55
+ this.transport = options.fetch || globalThis.fetch;
56
+ if (!Number.isFinite(this.timeoutMs) || this.timeoutMs <= 0) throw new TypeError("timeoutMs must be positive");
57
+ }
58
+ /** Requests are never retried automatically: a failed mutation may have succeeded. */
59
+ async request(method, path, body) {
60
+ let response;
61
+ try {
62
+ response = await this.transport(this.baseUrl + path, { method, headers: { authorization: `Bearer ${this.apiKey}`, "content-type": "application/json" }, body: body === void 0 ? void 0 : JSON.stringify(body), redirect: "error", signal: AbortSignal.timeout(this.timeoutMs) });
63
+ } catch {
64
+ throw new CondensationError("Connection failed or timed out. Check resource state before retrying a mutation.", 0, null);
65
+ }
66
+ const text = await response.text();
67
+ let data;
68
+ try {
69
+ data = text ? JSON.parse(text) : void 0;
70
+ } catch {
71
+ throw new CondensationError("The server returned an invalid response.", response.status, null);
72
+ }
73
+ if (!response.ok) {
74
+ const error = data?.error;
75
+ throw new CondensationError(typeof error === "string" ? error : error?.message || `Request failed (${response.status})`, response.status, data);
76
+ }
77
+ return data;
78
+ }
79
+ wallet() {
80
+ return this.request("GET", "/v1/wallet");
81
+ }
82
+ list() {
83
+ return this.request("GET", "/v1/sandboxes");
84
+ }
85
+ get(id) {
86
+ return this.request("GET", `/v1/sandboxes/${identifier(id)}`);
87
+ }
88
+ create(options = {}) {
89
+ return this.request("POST", "/v1/sandboxes", options);
90
+ }
91
+ run(id, command, options = {}) {
92
+ return this.request("POST", `/v1/sandboxes/${identifier(id)}/exec`, { ...options, command });
93
+ }
94
+ runAsync(id, command, options = {}) {
95
+ return this.request("POST", `/v1/sandboxes/${identifier(id)}/exec`, { ...options, command, async: true });
96
+ }
97
+ execution(id, execId) {
98
+ return this.request("GET", `/v1/sandboxes/${identifier(id)}/exec/${identifier(execId)}`);
99
+ }
100
+ cancelExecution(id, execId) {
101
+ return this.request("DELETE", `/v1/sandboxes/${identifier(id)}/exec/${identifier(execId)}`);
102
+ }
103
+ uploadBase64(id, path, contentBase64) {
104
+ return this.request("POST", `/v1/sandboxes/${identifier(id)}/upload`, { path, contentBase64 });
105
+ }
106
+ downloadBase64(id, path) {
107
+ return this.request("POST", `/v1/sandboxes/${identifier(id)}/download`, { path });
108
+ }
109
+ meter(id) {
110
+ return this.request("GET", `/v1/sandboxes/${identifier(id)}/meter`);
111
+ }
112
+ stop(id) {
113
+ return this.request("POST", `/v1/sandboxes/${identifier(id)}/stop`, {});
114
+ }
115
+ start(id) {
116
+ return this.request("POST", `/v1/sandboxes/${identifier(id)}/start`, {});
117
+ }
118
+ delete(id) {
119
+ return this.request("DELETE", `/v1/sandboxes/${identifier(id)}`);
120
+ }
121
+ };
122
+ var index_default = Condensation;
123
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["export interface Wallet {\n currency: 'USD'; accountId: string; purchasedMicroUsd: number;\n reservedMicroUsd: number; debtMicroUsd: number; condensationBonusMicroUsd: number;\n}\nexport interface SandboxInfo {\n id: string; state: string; cpu: number; memory: number; disk: number;\n language?: string; labels?: Record<string,string>; reservedCreditsMicro?: number;\n}\nexport interface CreateOptions {\n language?: 'javascript'|'typescript'|'python';\n autoStopMinutes?: number;\n labels?: Record<string,string>;\n}\nexport interface CommandOptions { cwd?: string; timeoutSeconds?: number; }\nexport interface CommandResult { exitCode: number; result: string; }\nexport interface AsyncCommand { execId: string; state: string; async: true; }\nexport interface ClientOptions {\n apiKey?: string; baseUrl?: string; timeoutMs?: number;\n /** Inject a standards-compliant fetch for testing or custom networking. */\n fetch?: typeof globalThis.fetch;\n}\nexport class CondensationError extends Error {\n constructor(message:string, public readonly status:number, public readonly details:unknown) {super(message);this.name='CondensationError';}\n}\nfunction identifier(value:string):string {\n if(!/^[a-zA-Z0-9_-]+$/.test(value))throw new TypeError('Invalid sandbox or execution ID');\n return value;\n}\nexport class Condensation {\n private readonly apiKey:string;\n private readonly baseUrl:string;\n private readonly timeoutMs:number;\n private readonly transport:typeof globalThis.fetch;\n constructor(options:ClientOptions={}) {\n const env=(globalThis as {process?:{env?:Record<string,string|undefined>}}).process?.env;\n const apiKey=options.apiKey||env?.CONDENSATION_API_KEY;\n if(!apiKey)throw new TypeError('Set CONDENSATION_API_KEY or pass apiKey');\n const url=new URL(options.baseUrl||'https://api.condensation.ai');\n const local=url.protocol==='http:'&&['localhost','127.0.0.1','[::1]'].includes(url.hostname);\n if((url.protocol!=='https:'&&!local)||url.username||url.password||url.search||url.hash||url.pathname!=='/')throw new TypeError('baseUrl must be an HTTPS origin (HTTP is allowed for localhost)');\n this.apiKey=apiKey;this.baseUrl=url.origin;this.timeoutMs=options.timeoutMs??120000;this.transport=options.fetch||globalThis.fetch;\n if(!Number.isFinite(this.timeoutMs)||this.timeoutMs<=0)throw new TypeError('timeoutMs must be positive');\n }\n /** Requests are never retried automatically: a failed mutation may have succeeded. */\n private async request<T>(method:string,path:string,body?:unknown):Promise<T> {\n let response:Response;\n try {response=await this.transport(this.baseUrl+path,{method,headers:{authorization:`Bearer ${this.apiKey}`,'content-type':'application/json'},body:body===undefined?undefined:JSON.stringify(body),redirect:'error',signal:AbortSignal.timeout(this.timeoutMs)});}\n catch {throw new CondensationError('Connection failed or timed out. Check resource state before retrying a mutation.',0,null);}\n const text=await response.text();let data:unknown;\n try{data=text?JSON.parse(text):undefined;}catch{throw new CondensationError('The server returned an invalid response.',response.status,null);}\n if(!response.ok){const error=(data as {error?:string|{message?:string}})?.error;throw new CondensationError(typeof error==='string'?error:error?.message||`Request failed (${response.status})`,response.status,data);}\n return data as T;\n }\n wallet():Promise<Wallet>{return this.request('GET','/v1/wallet');}\n list():Promise<SandboxInfo[]>{return this.request('GET','/v1/sandboxes');}\n get(id:string):Promise<SandboxInfo>{return this.request('GET',`/v1/sandboxes/${identifier(id)}`);}\n create(options:CreateOptions={}):Promise<SandboxInfo>{return this.request('POST','/v1/sandboxes',options);}\n run(id:string,command:string,options:CommandOptions={}):Promise<CommandResult>{return this.request('POST',`/v1/sandboxes/${identifier(id)}/exec`,{...options,command});}\n runAsync(id:string,command:string,options:CommandOptions={}):Promise<AsyncCommand>{return this.request('POST',`/v1/sandboxes/${identifier(id)}/exec`,{...options,command,async:true});}\n execution(id:string,execId:string):Promise<Record<string,unknown>>{return this.request('GET',`/v1/sandboxes/${identifier(id)}/exec/${identifier(execId)}`);}\n cancelExecution(id:string,execId:string):Promise<Record<string,unknown>>{return this.request('DELETE',`/v1/sandboxes/${identifier(id)}/exec/${identifier(execId)}`);}\n uploadBase64(id:string,path:string,contentBase64:string):Promise<{ok:boolean}>{return this.request('POST',`/v1/sandboxes/${identifier(id)}/upload`,{path,contentBase64});}\n downloadBase64(id:string,path:string):Promise<{contentBase64:string}>{return this.request('POST',`/v1/sandboxes/${identifier(id)}/download`,{path});}\n meter(id:string):Promise<Record<string,unknown>>{return this.request('GET',`/v1/sandboxes/${identifier(id)}/meter`);}\n stop(id:string):Promise<Record<string,unknown>>{return this.request('POST',`/v1/sandboxes/${identifier(id)}/stop`,{});}\n start(id:string):Promise<Record<string,unknown>>{return this.request('POST',`/v1/sandboxes/${identifier(id)}/start`,{});}\n delete(id:string):Promise<void>{return this.request('DELETE',`/v1/sandboxes/${identifier(id)}`);}\n}\nexport default Condensation;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBO,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAC3C,YAAY,SAAgC,QAA+B,SAAiB;AAAC,UAAM,OAAO;AAA9D;AAA+B;AAAiC,SAAK,OAAK;AAAA,EAAoB;AAC5I;AACA,SAAS,WAAW,O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E,CAAC,SAAS,WAAW,MAAM,CAAC,EAAE;AAAA,EAAE;AAAA,EACpK,aAAa,IAAU,MAAY,eAA2C;AAAC,WAAO,KAAK,QAAQ,QAAO,iBAAiB,WAAW,EAAE,CAAC,WAAU,EAAC,MAAK,cAAa,CAAC;AAAA,EAAE;AAAA,EACzK,eAAe,IAAU,MAA4C;AAAC,WAAO,KAAK,QAAQ,QAAO,iBAAiB,WAAW,EAAE,CAAC,aAAY,EAAC,KAAI,CAAC;AAAA,EAAE;AAAA,EACpJ,MAAM,IAA0C;AAAC,WAAO,KAAK,QAAQ,OAAM,iBAAiB,WAAW,EAAE,CAAC,QAAQ;AAAA,EAAE;AAAA,EACpH,KAAK,IAA0C;AAAC,WAAO,KAAK,QAAQ,QAAO,iBAAiB,WAAW,EAAE,CAAC,SAAQ,CAAC,CAAC;AAAA,EAAE;AAAA,EACtH,MAAM,IAA0C;AAAC,WAAO,KAAK,QAAQ,QAAO,iBAAiB,WAAW,EAAE,CAAC,UAAS,CAAC,CAAC;AAAA,EAAE;AAAA,EACxH,OAAO,IAAwB;AAAC,WAAO,KAAK,QAAQ,UAAS,iBAAiB,WAAW,EAAE,CAAC,EAAE;AAAA,EAAE;AAClG;AACA,IAAO,gBAAQ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,76 @@
1
+ export interface Wallet {
2
+ currency: 'USD';
3
+ accountId: string;
4
+ purchasedMicroUsd: number;
5
+ reservedMicroUsd: number;
6
+ debtMicroUsd: number;
7
+ condensationBonusMicroUsd: number;
8
+ }
9
+ export interface SandboxInfo {
10
+ id: string;
11
+ state: string;
12
+ cpu: number;
13
+ memory: number;
14
+ disk: number;
15
+ language?: string;
16
+ labels?: Record<string, string>;
17
+ reservedCreditsMicro?: number;
18
+ }
19
+ export interface CreateOptions {
20
+ language?: 'javascript' | 'typescript' | 'python';
21
+ autoStopMinutes?: number;
22
+ labels?: Record<string, string>;
23
+ }
24
+ export interface CommandOptions {
25
+ cwd?: string;
26
+ timeoutSeconds?: number;
27
+ }
28
+ export interface CommandResult {
29
+ exitCode: number;
30
+ result: string;
31
+ }
32
+ export interface AsyncCommand {
33
+ execId: string;
34
+ state: string;
35
+ async: true;
36
+ }
37
+ export interface ClientOptions {
38
+ apiKey?: string;
39
+ baseUrl?: string;
40
+ timeoutMs?: number;
41
+ /** Inject a standards-compliant fetch for testing or custom networking. */
42
+ fetch?: typeof globalThis.fetch;
43
+ }
44
+ export declare class CondensationError extends Error {
45
+ readonly status: number;
46
+ readonly details: unknown;
47
+ constructor(message: string, status: number, details: unknown);
48
+ }
49
+ export declare class Condensation {
50
+ private readonly apiKey;
51
+ private readonly baseUrl;
52
+ private readonly timeoutMs;
53
+ private readonly transport;
54
+ constructor(options?: ClientOptions);
55
+ /** Requests are never retried automatically: a failed mutation may have succeeded. */
56
+ private request;
57
+ wallet(): Promise<Wallet>;
58
+ list(): Promise<SandboxInfo[]>;
59
+ get(id: string): Promise<SandboxInfo>;
60
+ create(options?: CreateOptions): Promise<SandboxInfo>;
61
+ run(id: string, command: string, options?: CommandOptions): Promise<CommandResult>;
62
+ runAsync(id: string, command: string, options?: CommandOptions): Promise<AsyncCommand>;
63
+ execution(id: string, execId: string): Promise<Record<string, unknown>>;
64
+ cancelExecution(id: string, execId: string): Promise<Record<string, unknown>>;
65
+ uploadBase64(id: string, path: string, contentBase64: string): Promise<{
66
+ ok: boolean;
67
+ }>;
68
+ downloadBase64(id: string, path: string): Promise<{
69
+ contentBase64: string;
70
+ }>;
71
+ meter(id: string): Promise<Record<string, unknown>>;
72
+ stop(id: string): Promise<Record<string, unknown>>;
73
+ start(id: string): Promise<Record<string, unknown>>;
74
+ delete(id: string): Promise<void>;
75
+ }
76
+ export default Condensation;
@@ -0,0 +1,76 @@
1
+ export interface Wallet {
2
+ currency: 'USD';
3
+ accountId: string;
4
+ purchasedMicroUsd: number;
5
+ reservedMicroUsd: number;
6
+ debtMicroUsd: number;
7
+ condensationBonusMicroUsd: number;
8
+ }
9
+ export interface SandboxInfo {
10
+ id: string;
11
+ state: string;
12
+ cpu: number;
13
+ memory: number;
14
+ disk: number;
15
+ language?: string;
16
+ labels?: Record<string, string>;
17
+ reservedCreditsMicro?: number;
18
+ }
19
+ export interface CreateOptions {
20
+ language?: 'javascript' | 'typescript' | 'python';
21
+ autoStopMinutes?: number;
22
+ labels?: Record<string, string>;
23
+ }
24
+ export interface CommandOptions {
25
+ cwd?: string;
26
+ timeoutSeconds?: number;
27
+ }
28
+ export interface CommandResult {
29
+ exitCode: number;
30
+ result: string;
31
+ }
32
+ export interface AsyncCommand {
33
+ execId: string;
34
+ state: string;
35
+ async: true;
36
+ }
37
+ export interface ClientOptions {
38
+ apiKey?: string;
39
+ baseUrl?: string;
40
+ timeoutMs?: number;
41
+ /** Inject a standards-compliant fetch for testing or custom networking. */
42
+ fetch?: typeof globalThis.fetch;
43
+ }
44
+ export declare class CondensationError extends Error {
45
+ readonly status: number;
46
+ readonly details: unknown;
47
+ constructor(message: string, status: number, details: unknown);
48
+ }
49
+ export declare class Condensation {
50
+ private readonly apiKey;
51
+ private readonly baseUrl;
52
+ private readonly timeoutMs;
53
+ private readonly transport;
54
+ constructor(options?: ClientOptions);
55
+ /** Requests are never retried automatically: a failed mutation may have succeeded. */
56
+ private request;
57
+ wallet(): Promise<Wallet>;
58
+ list(): Promise<SandboxInfo[]>;
59
+ get(id: string): Promise<SandboxInfo>;
60
+ create(options?: CreateOptions): Promise<SandboxInfo>;
61
+ run(id: string, command: string, options?: CommandOptions): Promise<CommandResult>;
62
+ runAsync(id: string, command: string, options?: CommandOptions): Promise<AsyncCommand>;
63
+ execution(id: string, execId: string): Promise<Record<string, unknown>>;
64
+ cancelExecution(id: string, execId: string): Promise<Record<string, unknown>>;
65
+ uploadBase64(id: string, path: string, contentBase64: string): Promise<{
66
+ ok: boolean;
67
+ }>;
68
+ downloadBase64(id: string, path: string): Promise<{
69
+ contentBase64: string;
70
+ }>;
71
+ meter(id: string): Promise<Record<string, unknown>>;
72
+ stop(id: string): Promise<Record<string, unknown>>;
73
+ start(id: string): Promise<Record<string, unknown>>;
74
+ delete(id: string): Promise<void>;
75
+ }
76
+ export default Condensation;
package/dist/index.js ADDED
@@ -0,0 +1,102 @@
1
+ // src/index.ts
2
+ var CondensationError = class extends Error {
3
+ constructor(message, status, details) {
4
+ super(message);
5
+ this.status = status;
6
+ this.details = details;
7
+ this.name = "CondensationError";
8
+ }
9
+ };
10
+ function identifier(value) {
11
+ if (!/^[a-zA-Z0-9_-]+$/.test(value)) throw new TypeError("Invalid sandbox or execution ID");
12
+ return value;
13
+ }
14
+ var Condensation = class {
15
+ apiKey;
16
+ baseUrl;
17
+ timeoutMs;
18
+ transport;
19
+ constructor(options = {}) {
20
+ const env = globalThis.process?.env;
21
+ const apiKey = options.apiKey || env?.CONDENSATION_API_KEY;
22
+ if (!apiKey) throw new TypeError("Set CONDENSATION_API_KEY or pass apiKey");
23
+ const url = new URL(options.baseUrl || "https://api.condensation.ai");
24
+ const local = url.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
25
+ if (url.protocol !== "https:" && !local || url.username || url.password || url.search || url.hash || url.pathname !== "/") throw new TypeError("baseUrl must be an HTTPS origin (HTTP is allowed for localhost)");
26
+ this.apiKey = apiKey;
27
+ this.baseUrl = url.origin;
28
+ this.timeoutMs = options.timeoutMs ?? 12e4;
29
+ this.transport = options.fetch || globalThis.fetch;
30
+ if (!Number.isFinite(this.timeoutMs) || this.timeoutMs <= 0) throw new TypeError("timeoutMs must be positive");
31
+ }
32
+ /** Requests are never retried automatically: a failed mutation may have succeeded. */
33
+ async request(method, path, body) {
34
+ let response;
35
+ try {
36
+ response = await this.transport(this.baseUrl + path, { method, headers: { authorization: `Bearer ${this.apiKey}`, "content-type": "application/json" }, body: body === void 0 ? void 0 : JSON.stringify(body), redirect: "error", signal: AbortSignal.timeout(this.timeoutMs) });
37
+ } catch {
38
+ throw new CondensationError("Connection failed or timed out. Check resource state before retrying a mutation.", 0, null);
39
+ }
40
+ const text = await response.text();
41
+ let data;
42
+ try {
43
+ data = text ? JSON.parse(text) : void 0;
44
+ } catch {
45
+ throw new CondensationError("The server returned an invalid response.", response.status, null);
46
+ }
47
+ if (!response.ok) {
48
+ const error = data?.error;
49
+ throw new CondensationError(typeof error === "string" ? error : error?.message || `Request failed (${response.status})`, response.status, data);
50
+ }
51
+ return data;
52
+ }
53
+ wallet() {
54
+ return this.request("GET", "/v1/wallet");
55
+ }
56
+ list() {
57
+ return this.request("GET", "/v1/sandboxes");
58
+ }
59
+ get(id) {
60
+ return this.request("GET", `/v1/sandboxes/${identifier(id)}`);
61
+ }
62
+ create(options = {}) {
63
+ return this.request("POST", "/v1/sandboxes", options);
64
+ }
65
+ run(id, command, options = {}) {
66
+ return this.request("POST", `/v1/sandboxes/${identifier(id)}/exec`, { ...options, command });
67
+ }
68
+ runAsync(id, command, options = {}) {
69
+ return this.request("POST", `/v1/sandboxes/${identifier(id)}/exec`, { ...options, command, async: true });
70
+ }
71
+ execution(id, execId) {
72
+ return this.request("GET", `/v1/sandboxes/${identifier(id)}/exec/${identifier(execId)}`);
73
+ }
74
+ cancelExecution(id, execId) {
75
+ return this.request("DELETE", `/v1/sandboxes/${identifier(id)}/exec/${identifier(execId)}`);
76
+ }
77
+ uploadBase64(id, path, contentBase64) {
78
+ return this.request("POST", `/v1/sandboxes/${identifier(id)}/upload`, { path, contentBase64 });
79
+ }
80
+ downloadBase64(id, path) {
81
+ return this.request("POST", `/v1/sandboxes/${identifier(id)}/download`, { path });
82
+ }
83
+ meter(id) {
84
+ return this.request("GET", `/v1/sandboxes/${identifier(id)}/meter`);
85
+ }
86
+ stop(id) {
87
+ return this.request("POST", `/v1/sandboxes/${identifier(id)}/stop`, {});
88
+ }
89
+ start(id) {
90
+ return this.request("POST", `/v1/sandboxes/${identifier(id)}/start`, {});
91
+ }
92
+ delete(id) {
93
+ return this.request("DELETE", `/v1/sandboxes/${identifier(id)}`);
94
+ }
95
+ };
96
+ var index_default = Condensation;
97
+ export {
98
+ Condensation,
99
+ CondensationError,
100
+ index_default as default
101
+ };
102
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["export interface Wallet {\n currency: 'USD'; accountId: string; purchasedMicroUsd: number;\n reservedMicroUsd: number; debtMicroUsd: number; condensationBonusMicroUsd: number;\n}\nexport interface SandboxInfo {\n id: string; state: string; cpu: number; memory: number; disk: number;\n language?: string; labels?: Record<string,string>; reservedCreditsMicro?: number;\n}\nexport interface CreateOptions {\n language?: 'javascript'|'typescript'|'python';\n autoStopMinutes?: number;\n labels?: Record<string,string>;\n}\nexport interface CommandOptions { cwd?: string; timeoutSeconds?: number; }\nexport interface CommandResult { exitCode: number; result: string; }\nexport interface AsyncCommand { execId: string; state: string; async: true; }\nexport interface ClientOptions {\n apiKey?: string; baseUrl?: string; timeoutMs?: number;\n /** Inject a standards-compliant fetch for testing or custom networking. */\n fetch?: typeof globalThis.fetch;\n}\nexport class CondensationError extends Error {\n constructor(message:string, public readonly status:number, public readonly details:unknown) {super(message);this.name='CondensationError';}\n}\nfunction identifier(value:string):string {\n if(!/^[a-zA-Z0-9_-]+$/.test(value))throw new TypeError('Invalid sandbox or execution ID');\n return value;\n}\nexport class Condensation {\n private readonly apiKey:string;\n private readonly baseUrl:string;\n private readonly timeoutMs:number;\n private readonly transport:typeof globalThis.fetch;\n constructor(options:ClientOptions={}) {\n const env=(globalThis as {process?:{env?:Record<string,string|undefined>}}).process?.env;\n const apiKey=options.apiKey||env?.CONDENSATION_API_KEY;\n if(!apiKey)throw new TypeError('Set CONDENSATION_API_KEY or pass apiKey');\n const url=new URL(options.baseUrl||'https://api.condensation.ai');\n const local=url.protocol==='http:'&&['localhost','127.0.0.1','[::1]'].includes(url.hostname);\n if((url.protocol!=='https:'&&!local)||url.username||url.password||url.search||url.hash||url.pathname!=='/')throw new TypeError('baseUrl must be an HTTPS origin (HTTP is allowed for localhost)');\n this.apiKey=apiKey;this.baseUrl=url.origin;this.timeoutMs=options.timeoutMs??120000;this.transport=options.fetch||globalThis.fetch;\n if(!Number.isFinite(this.timeoutMs)||this.timeoutMs<=0)throw new TypeError('timeoutMs must be positive');\n }\n /** Requests are never retried automatically: a failed mutation may have succeeded. */\n private async request<T>(method:string,path:string,body?:unknown):Promise<T> {\n let response:Response;\n try {response=await this.transport(this.baseUrl+path,{method,headers:{authorization:`Bearer ${this.apiKey}`,'content-type':'application/json'},body:body===undefined?undefined:JSON.stringify(body),redirect:'error',signal:AbortSignal.timeout(this.timeoutMs)});}\n catch {throw new CondensationError('Connection failed or timed out. Check resource state before retrying a mutation.',0,null);}\n const text=await response.text();let data:unknown;\n try{data=text?JSON.parse(text):undefined;}catch{throw new CondensationError('The server returned an invalid response.',response.status,null);}\n if(!response.ok){const error=(data as {error?:string|{message?:string}})?.error;throw new CondensationError(typeof error==='string'?error:error?.message||`Request failed (${response.status})`,response.status,data);}\n return data as T;\n }\n wallet():Promise<Wallet>{return this.request('GET','/v1/wallet');}\n list():Promise<SandboxInfo[]>{return this.request('GET','/v1/sandboxes');}\n get(id:string):Promise<SandboxInfo>{return this.request('GET',`/v1/sandboxes/${identifier(id)}`);}\n create(options:CreateOptions={}):Promise<SandboxInfo>{return this.request('POST','/v1/sandboxes',options);}\n run(id:string,command:string,options:CommandOptions={}):Promise<CommandResult>{return this.request('POST',`/v1/sandboxes/${identifier(id)}/exec`,{...options,command});}\n runAsync(id:string,command:string,options:CommandOptions={}):Promise<AsyncCommand>{return this.request('POST',`/v1/sandboxes/${identifier(id)}/exec`,{...options,command,async:true});}\n execution(id:string,execId:string):Promise<Record<string,unknown>>{return this.request('GET',`/v1/sandboxes/${identifier(id)}/exec/${identifier(execId)}`);}\n cancelExecution(id:string,execId:string):Promise<Record<string,unknown>>{return this.request('DELETE',`/v1/sandboxes/${identifier(id)}/exec/${identifier(execId)}`);}\n uploadBase64(id:string,path:string,contentBase64:string):Promise<{ok:boolean}>{return this.request('POST',`/v1/sandboxes/${identifier(id)}/upload`,{path,contentBase64});}\n downloadBase64(id:string,path:string):Promise<{contentBase64:string}>{return this.request('POST',`/v1/sandboxes/${identifier(id)}/download`,{path});}\n meter(id:string):Promise<Record<string,unknown>>{return this.request('GET',`/v1/sandboxes/${identifier(id)}/meter`);}\n stop(id:string):Promise<Record<string,unknown>>{return this.request('POST',`/v1/sandboxes/${identifier(id)}/stop`,{});}\n start(id:string):Promise<Record<string,unknown>>{return this.request('POST',`/v1/sandboxes/${identifier(id)}/start`,{});}\n delete(id:string):Promise<void>{return this.request('DELETE',`/v1/sandboxes/${identifier(id)}`);}\n}\nexport default Condensation;\n"],
5
+ "mappings": ";AAqBO,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAC3C,YAAY,SAAgC,QAA+B,SAAiB;AAAC,UAAM,OAAO;AAA9D;AAA+B;AAAiC,SAAK,OAAK;AAAA,EAAoB;AAC5I;AACA,SAAS,WAAW,OAAqB;AACvC,MAAG,CAAC,mBAAmB,KAAK,KAAK,EAAE,OAAM,IAAI,UAAU,iCAAiC;AACxF,SAAO;AACT;AACO,IAAM,eAAN,MAAmB;AAAA,EACP;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACjB,YAAY,UAAsB,CAAC,GAAG;AACpC,UAAM,MAAK,WAAiE,SAAS;AACrF,UAAM,SAAO,QAAQ,UAAQ,KAAK;AAClC,QAAG,CAAC,OAAO,OAAM,IAAI,UAAU,yCAAyC;AACxE,UAAM,MAAI,IAAI,IAAI,QAAQ,WAAS,6BAA6B;AAChE,UAAM,QAAM,IAAI,aAAW,WAAS,CAAC,aAAY,aAAY,OAAO,EAAE,SAAS,IAAI,QAAQ;AAC3F,QAAI,IAAI,aAAW,YAAU,CAAC,SAAQ,IAAI,YAAU,IAAI,YAAU,IAAI,UAAQ,IAAI,QAAM,IAAI,aAAW,IAAI,OAAM,IAAI,UAAU,iEAAiE;AAChM,SAAK,SAAO;AAAO,SAAK,UAAQ,IAAI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,EAAE;AAAA,EACxH,OAAO,IAAwB;AAAC,WAAO,KAAK,QAAQ,UAAS,iBAAiB,WAAW,EAAE,CAAC,EAAE;AAAA,EAAE;AAClG;AACA,IAAO,gBAAQ;",
6
+ "names": []
7
+ }
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "condensationai",
3
+ "version": "0.1.0",
4
+ "description": "Condensation SDK for sandbox infrastructure and the shared Codegraff wallet",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md",
24
+ "LICENSE"
25
+ ],
26
+ "sideEffects": false,
27
+ "engines": {
28
+ "node": ">=20"
29
+ },
30
+ "scripts": {
31
+ "build": "node build.mjs",
32
+ "test": "node --test test/*.test.mjs",
33
+ "prepack": "npm run build && npm test"
34
+ },
35
+ "license": "MIT",
36
+ "homepage": "https://workspaces.condensation.ai/docs/sdk",
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "keywords": [
41
+ "condensation",
42
+ "sandbox",
43
+ "codegraff",
44
+ "ai",
45
+ "typescript"
46
+ ],
47
+ "devDependencies": {
48
+ "esbuild": "0.25.0",
49
+ "typescript": "5.9.3"
50
+ }
51
+ }