@gitterm/sdk 0.0.1 → 0.0.3

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/README.md CHANGED
@@ -12,13 +12,62 @@ bun add @gitterm/sdk
12
12
  npm install @gitterm/sdk
13
13
  ```
14
14
 
15
+ ## Switching servers (hosted vs self-hosted)
16
+
17
+ The default API is the hosted service at `https://api.gitterm.dev`. Self-hosted
18
+ instances use the same SDK — pass your instance’s base URL as `serverUrl`.
19
+
20
+ | Deployment | Example `serverUrl` |
21
+ | ----------- | ----------------------------- |
22
+ | Hosted | `https://api.gitterm.dev` |
23
+ | Self-hosted | `https://gitterm.example.com` |
24
+ | Local dev | `http://localhost:3000` |
25
+
26
+ ### Explicit client (recommended for apps)
27
+
28
+ ```ts
29
+ import { createGittermClient } from "@gitterm/sdk";
30
+
31
+ // Hosted
32
+ const hosted = createGittermClient({
33
+ serverUrl: "https://api.gitterm.dev",
34
+ token: process.env.GITTERM_API_TOKEN,
35
+ });
36
+
37
+ // Self-hosted / local
38
+ const selfHosted = createGittermClient({
39
+ serverUrl: "https://gitterm.example.com", // or http://localhost:3000
40
+ token: process.env.GITTERM_API_TOKEN,
41
+ });
42
+ ```
43
+
44
+ ### Environment variables
45
+
46
+ ```bash
47
+ export GITTERM_SERVER_URL=https://gitterm.example.com
48
+ export GITTERM_API_TOKEN=gt_...
49
+ ```
50
+
51
+ ```ts
52
+ // Picks up GITTERM_SERVER_URL + GITTERM_API_TOKEN
53
+ const client = createGittermClient();
54
+ ```
55
+
56
+ ### CLI saved login
57
+
58
+ If you omit both options, the SDK also reads `~/.config/gitterm/cli.json` written by
59
+ `gitterm login` / `gitterm login --server <url>`.
60
+
61
+ **Resolution order:** constructor options → `GITTERM_SERVER_URL` / `GITTERM_API_TOKEN` → CLI config file.
62
+
63
+ Create tokens in the dashboard under **Settings → Account → API tokens**, or via
64
+ `gitterm login` (device-code flow). Tokens are the same `gt_...` shape on hosted and
65
+ self-hosted.
66
+
15
67
  ## Usage
16
68
 
17
69
  ### With an explicit API token
18
70
 
19
- Create a token in the GitTerm dashboard under **Settings → Account → API tokens**
20
- (revocable, optional expiry), or obtain one via `gitterm login`.
21
-
22
71
  ```ts
23
72
  import { createGittermClient } from "@gitterm/sdk";
24
73
 
@@ -32,13 +81,10 @@ const { workspaces } = await client.workspaces.list();
32
81
 
33
82
  ### With the CLI's saved login
34
83
 
35
- If you omit `serverUrl`/`token`, the SDK reads the config written by `gitterm login`
36
- (`~/.config/gitterm/cli.json`), falling back to the `GITTERM_SERVER_URL` and
37
- `GITTERM_API_TOKEN` environment variables.
38
-
39
84
  ```ts
40
85
  const client = createGittermClient();
41
86
  const status = await client.auth.status();
87
+ // status + client.serverUrl show which account and server you hit
42
88
  ```
43
89
 
44
90
  ### API
@@ -47,14 +93,24 @@ const status = await client.auth.status();
47
93
  client.auth.status(); // -> { userId, email, name, plan, authMethod }
48
94
  client.workspaces.list(options?); // -> { workspaces, pagination }
49
95
  client.workspaces.get(workspaceId);
96
+ client.workspaces.getRuntimeAccess(workspaceId); // read-only; never resumes compute
97
+ client.workspaces.ensureRunning(workspaceId, options?);
50
98
  client.workspaces.pause(workspaceId);
51
99
  client.workspaces.restart(workspaceId);
52
100
  client.workspaces.terminate(workspaceId);
53
- client.workspaces.create(input); // needs agentTypeId + cloudProviderId, see catalog
101
+ client.workspaces.createSandbox({
102
+ idempotencyKey, repo, branch, baseCommit, checkoutRef,
103
+ agent, provider, persistent, // provider is optional
104
+ });
54
105
  client.catalog.agentTypes();
55
106
  client.catalog.cloudProviders();
107
+ client.catalog.resolveSandboxDefaults({ agent, provider });
56
108
  ```
57
109
 
110
+ `agent` is the unique enabled agent name (for example `"OpenCode"`).
111
+ `provider` is the unique enabled provider name (for example `"E2B"`).
112
+ Omit `provider` to use the preferred default sandbox provider.
113
+
58
114
  ### Errors
59
115
 
60
116
  Every method throws `GittermError` with a stable `code`:
@@ -71,24 +127,35 @@ try {
71
127
  }
72
128
  ```
73
129
 
74
- Codes: `NOT_LOGGED_IN`, `UNAUTHORIZED`, `NOT_FOUND`, `FORBIDDEN`, `BAD_REQUEST`,
75
- `SERVER_ERROR`, `NETWORK`.
130
+ Workspace lifecycle failures are also exposed as `WorkspaceLifecycleError`, with stable
131
+ `WORKSPACE_TERMINATED`, `WORKSPACE_NON_RECOVERABLE`, `WORKSPACE_START_TIMEOUT`, and
132
+ `WORKSPACE_RESTART_FAILED` codes. General codes are
133
+ `NOT_LOGGED_IN`, `UNAUTHORIZED`, `NOT_FOUND`, `FORBIDDEN`, `BAD_REQUEST`,
134
+ `SERVER_ERROR`, and `NETWORK`.
135
+
136
+ The package ships self-contained declarations from `dist`; TypeScript consumers do not
137
+ need GitTerm's API package or tRPC server types.
76
138
 
77
139
  ### Obtaining a token programmatically
78
140
 
79
- The device-code flow used by `gitterm login` is exposed for integrations:
141
+ The device-code flow used by `gitterm login` is exposed for integrations. Pass the
142
+ server URL of the instance you want to log into:
80
143
 
81
144
  ```ts
82
145
  import { loginWithDeviceCode, saveConfig, DEFAULT_GITTERM_SERVER_URL } from "@gitterm/sdk";
83
146
 
84
- const { token } = await loginWithDeviceCode(DEFAULT_GITTERM_SERVER_URL, {
147
+ // Hosted: DEFAULT_GITTERM_SERVER_URL ("https://api.gitterm.dev")
148
+ // Self-hosted: "https://gitterm.example.com" or "http://localhost:3000"
149
+ const serverUrl = process.env.GITTERM_SERVER_URL ?? DEFAULT_GITTERM_SERVER_URL;
150
+
151
+ const { token } = await loginWithDeviceCode(serverUrl, {
85
152
  onCode: ({ verificationUri, userCode }) => {
86
153
  console.log(`Visit ${verificationUri} and enter ${userCode}`);
87
154
  },
88
155
  });
89
156
 
90
157
  await saveConfig({
91
- serverUrl: DEFAULT_GITTERM_SERVER_URL,
158
+ serverUrl,
92
159
  token,
93
160
  createdAt: Date.now(),
94
161
  });
@@ -0,0 +1,40 @@
1
+ import type { AgentType, AuthStatus, CloudProvider, Workspace, WorkspaceCreateInput, WorkspaceCreateResult, WorkspaceEnsureRunningResult, WorkspaceListOptions, WorkspaceListResult, WorkspaceRestartResult, WorkspaceRuntimeAccess, WorkspacePauseResult, WorkspaceTerminateResult, SandboxDefaults, SandboxDefaultsInput } from "./types.js";
2
+ export type GittermClientOptions = {
3
+ serverUrl?: string;
4
+ token?: string;
5
+ configPath?: string;
6
+ fetch?: typeof fetch;
7
+ };
8
+ export type GittermClient = {
9
+ serverUrl: string;
10
+ auth: {
11
+ status(): Promise<AuthStatus>;
12
+ };
13
+ workspaces: {
14
+ list(input?: WorkspaceListOptions): Promise<WorkspaceListResult>;
15
+ get(workspaceId: string): Promise<Workspace>;
16
+ getRuntimeAccess(workspaceId: string): Promise<WorkspaceRuntimeAccess>;
17
+ ensureRunning(workspaceId: string, options?: {
18
+ timeoutMs?: number;
19
+ pollIntervalMs?: number;
20
+ }): Promise<WorkspaceEnsureRunningResult>;
21
+ pause(workspaceId: string): Promise<WorkspacePauseResult>;
22
+ restart(workspaceId: string): Promise<WorkspaceRestartResult>;
23
+ terminate(workspaceId: string): Promise<WorkspaceTerminateResult>;
24
+ create(input: WorkspaceCreateInput): Promise<WorkspaceCreateResult>;
25
+ createSandbox(input: WorkspaceCreateInput): Promise<WorkspaceCreateResult>;
26
+ };
27
+ catalog: {
28
+ agentTypes(input?: {
29
+ serverOnly?: boolean;
30
+ }): Promise<AgentType[]>;
31
+ cloudProviders(input?: {
32
+ localOnly?: boolean;
33
+ cloudOnly?: boolean;
34
+ sandboxOnly?: boolean;
35
+ nonSandboxOnly?: boolean;
36
+ }): Promise<CloudProvider[]>;
37
+ resolveSandboxDefaults(input: SandboxDefaultsInput): Promise<SandboxDefaults>;
38
+ };
39
+ };
40
+ export declare function createGittermClient(options?: GittermClientOptions): GittermClient;
@@ -0,0 +1,11 @@
1
+ export declare const DEFAULT_GITTERM_SERVER_URL = "https://api.gitterm.dev";
2
+ export type CliConfig = {
3
+ serverUrl: string;
4
+ token: string;
5
+ createdAt: number;
6
+ };
7
+ export declare function getConfigPath(configPath?: string): string;
8
+ export declare function loadConfig(configPath?: string): Promise<CliConfig | null>;
9
+ export declare function loadConfigSync(configPath?: string): CliConfig | null;
10
+ export declare function saveConfig(config: CliConfig, configPath?: string): Promise<void>;
11
+ export declare function deleteConfig(configPath?: string): Promise<void>;
@@ -0,0 +1,15 @@
1
+ export type DeviceCodeInfo = {
2
+ deviceCode: string;
3
+ userCode: string;
4
+ verificationUri: string;
5
+ intervalSeconds: number;
6
+ expiresInSeconds: number;
7
+ };
8
+ export type LoginWithDeviceCodeOptions = {
9
+ clientName?: string;
10
+ fetch?: typeof fetch;
11
+ onCode?: (code: Omit<DeviceCodeInfo, "deviceCode">) => void | Promise<void>;
12
+ };
13
+ export declare function loginWithDeviceCode(serverUrl: string, options?: LoginWithDeviceCodeOptions): Promise<{
14
+ token: string;
15
+ }>;
@@ -0,0 +1,15 @@
1
+ export type GittermErrorCode = "NOT_LOGGED_IN" | "UNAUTHORIZED" | "NOT_FOUND" | "FORBIDDEN" | "BAD_REQUEST" | "SERVER_ERROR" | "NETWORK" | WorkspaceLifecycleErrorCode;
2
+ export type WorkspaceLifecycleErrorCode = "WORKSPACE_TERMINATED" | "WORKSPACE_NON_RECOVERABLE" | "WORKSPACE_START_TIMEOUT" | "WORKSPACE_RESTART_FAILED";
3
+ export declare class GittermError extends Error {
4
+ readonly code: GittermErrorCode;
5
+ readonly cause?: unknown;
6
+ constructor(code: GittermErrorCode, message: string, options?: {
7
+ cause?: unknown;
8
+ });
9
+ }
10
+ export declare class WorkspaceLifecycleError extends GittermError {
11
+ readonly code: WorkspaceLifecycleErrorCode;
12
+ constructor(code: WorkspaceLifecycleErrorCode, message: string, options?: {
13
+ cause?: unknown;
14
+ });
15
+ }
package/dist/index.d.ts CHANGED
@@ -1,213 +1,8 @@
1
- /**
2
- * Hand-maintained public type surface for @gitterm/sdk.
3
- *
4
- * External npm consumers resolve these types instead of the TypeScript
5
- * sources, because the sources derive types from the private @gitterm/api
6
- * router. Keep this file in sync with src/types.ts and src/client.ts.
7
- *
8
- * TODO: replace with generated declarations once the AppRouter types can be
9
- * bundled into a standalone .d.ts.
10
- */
11
-
12
- export const DEFAULT_GITTERM_SERVER_URL: string;
13
-
14
- export type CliConfig = {
15
- serverUrl: string;
16
- token: string;
17
- createdAt: number;
18
- };
19
-
20
- export type GittermErrorCode =
21
- | "NOT_LOGGED_IN"
22
- | "UNAUTHORIZED"
23
- | "NOT_FOUND"
24
- | "FORBIDDEN"
25
- | "BAD_REQUEST"
26
- | "SERVER_ERROR"
27
- | "NETWORK";
28
-
29
- export class GittermError extends Error {
30
- readonly code: GittermErrorCode;
31
- readonly cause?: unknown;
32
- constructor(code: GittermErrorCode, message: string, options?: { cause?: unknown });
33
- }
34
-
35
- export type GittermClientOptions = {
36
- serverUrl?: string;
37
- token?: string;
38
- configPath?: string;
39
- fetch?: typeof fetch;
40
- };
41
-
42
- export type AuthStatus = {
43
- loggedIn: true;
44
- userId: string;
45
- email: string;
46
- name: string;
47
- plan: string;
48
- authMethod: "session" | "apiToken";
49
- };
50
-
51
- export type WorkspaceStatus = "pending" | "running" | "paused" | "terminated";
52
- export type WorkspaceHostingType = "cloud" | "local";
53
-
54
- export type Workspace = {
55
- id: string;
56
- name: string | null;
57
- status: WorkspaceStatus;
58
- repositoryUrl: string | null;
59
- repositoryBranch: string | null;
60
- baseCommit: string | null;
61
- checkoutRef: string | null;
62
- domain: string;
63
- subdomain: string | null;
64
- persistent: boolean;
65
- hostingType: WorkspaceHostingType;
66
- serverOnly: boolean;
67
- workspaceProfile: string;
68
- cloudProviderId: string;
69
- agentType: { id: string; name: string; description: string | null } | null;
70
- image: { id: string; name: string; imageId: string } | null;
71
- startedAt: string | null;
72
- stoppedAt: string | null;
73
- terminatedAt: string | null;
74
- lastActiveAt: string | null;
75
- updatedAt: string | null;
76
- };
77
-
78
- export type WorkspaceRuntimeAccess = {
79
- workspaceId: string;
80
- status: WorkspaceStatus;
81
- url: string | null;
82
- headers?: Record<string, string>;
83
- password?: string;
84
- directory: string;
85
- repo: string | null;
86
- branch: string | null;
87
- baseCommit: string | null;
88
- checkoutRef: string | null;
89
- persistent: boolean;
90
- recoverable: boolean;
91
- providerKey: string | null;
92
- };
93
-
94
- export type WorkspaceCreateResult = {
95
- workspace: Workspace;
96
- runtime: WorkspaceRuntimeAccess;
97
- };
98
-
99
- export type WorkspaceListOptions = {
100
- limit?: number;
101
- offset?: number;
102
- status?: "all" | "active" | "terminated";
103
- };
104
-
105
- export type WorkspaceListResult = {
106
- workspaces: Workspace[];
107
- pagination: {
108
- total: number;
109
- limit: number;
110
- offset: number;
111
- hasMore: boolean;
112
- };
113
- };
114
-
115
- export type WorkspaceCreateInput = {
116
- name?: string;
117
- repo?: string;
118
- branch?: string;
119
- baseCommit?: string;
120
- checkoutRef?: string;
121
- subdomain?: string;
122
- agentTypeId: string;
123
- cloudProviderId: string;
124
- regionId?: string;
125
- gitIntegrationId?: string;
126
- persistent: boolean;
127
- workspaceProfile?: "standard" | "ssh-enabled";
128
- };
129
-
130
- export type WorkspaceStopResult = { durationMinutes: number };
131
- export type WorkspacePauseResult = WorkspaceStopResult;
132
- export type WorkspaceRestartResult = { status: WorkspaceStatus };
133
- export type WorkspaceTerminateResult = {
134
- workspace: Workspace | null;
135
- cleanupInBackground: boolean;
136
- };
137
- export type WorkspaceEnsureRunningResult = {
138
- workspace: Workspace;
139
- runtime: WorkspaceRuntimeAccess;
140
- };
141
-
142
- export type AgentType = {
143
- id: string;
144
- name: string;
145
- description: string | null;
146
- serverOnly: boolean;
147
- isEnabled: boolean;
148
- createdAt: Date | string;
149
- updatedAt: Date | string;
150
- };
151
-
152
- export type CloudProvider = Record<string, unknown> & {
153
- id: string;
154
- name: string;
155
- providerKey: string;
156
- regions?: Array<Record<string, unknown>>;
157
- };
158
-
159
- export type GittermClient = {
160
- serverUrl: string;
161
- auth: {
162
- status(): Promise<AuthStatus>;
163
- };
164
- workspaces: {
165
- list(input?: WorkspaceListOptions): Promise<WorkspaceListResult>;
166
- get(workspaceId: string): Promise<Workspace>;
167
- getRuntimeAccess(workspaceId: string): Promise<WorkspaceRuntimeAccess>;
168
- ensureRunning(
169
- workspaceId: string,
170
- options?: { timeoutMs?: number; pollIntervalMs?: number },
171
- ): Promise<WorkspaceEnsureRunningResult>;
172
- pause(workspaceId: string): Promise<WorkspacePauseResult>;
173
- restart(workspaceId: string): Promise<WorkspaceRestartResult>;
174
- terminate(workspaceId: string): Promise<WorkspaceTerminateResult>;
175
- create(input: WorkspaceCreateInput): Promise<WorkspaceCreateResult>;
176
- createSandbox(input: WorkspaceCreateInput): Promise<WorkspaceCreateResult>;
177
- };
178
- catalog: {
179
- agentTypes(input?: { serverOnly?: boolean }): Promise<AgentType[]>;
180
- cloudProviders(input?: {
181
- localOnly?: boolean;
182
- cloudOnly?: boolean;
183
- sandboxOnly?: boolean;
184
- nonSandboxOnly?: boolean;
185
- }): Promise<CloudProvider[]>;
186
- };
187
- };
188
-
189
- export function createGittermClient(options?: GittermClientOptions): GittermClient;
190
- export function getConfigPath(configPath?: string): string;
191
- export function loadConfig(configPath?: string): Promise<CliConfig | null>;
192
- export function loadConfigSync(configPath?: string): CliConfig | null;
193
- export function saveConfig(config: CliConfig, configPath?: string): Promise<void>;
194
- export function deleteConfig(configPath?: string): Promise<void>;
195
-
196
- export type DeviceCodeInfo = {
197
- deviceCode: string;
198
- userCode: string;
199
- verificationUri: string;
200
- intervalSeconds: number;
201
- expiresInSeconds: number;
202
- };
203
-
204
- export type LoginWithDeviceCodeOptions = {
205
- clientName?: string;
206
- fetch?: typeof fetch;
207
- onCode?: (code: Omit<DeviceCodeInfo, "deviceCode">) => void | Promise<void>;
208
- };
209
-
210
- export function loginWithDeviceCode(
211
- serverUrl: string,
212
- options?: LoginWithDeviceCodeOptions,
213
- ): Promise<{ token: string }>;
1
+ export { createGittermClient, type GittermClient, type GittermClientOptions } from "./client.js";
2
+ export { DEFAULT_GITTERM_SERVER_URL, getConfigPath, loadConfig, loadConfigSync, saveConfig, deleteConfig, } from "./config.js";
3
+ export type { CliConfig } from "./config.js";
4
+ export { loginWithDeviceCode } from "./device-login.js";
5
+ export type { DeviceCodeInfo, LoginWithDeviceCodeOptions } from "./device-login.js";
6
+ export { GittermError, WorkspaceLifecycleError } from "./errors.js";
7
+ export type { GittermErrorCode, WorkspaceLifecycleErrorCode } from "./errors.js";
8
+ export type { AgentType, AuthStatus, CloudProvider, SandboxDefaults, Workspace, WorkspaceCreateInput, WorkspaceCreateResult, WorkspaceEnsureRunningResult, WorkspaceHostingType, WorkspaceListOptions, WorkspaceListResult, WorkspaceRestartResult, WorkspaceRuntimeAccess, WorkspaceStatus, WorkspacePauseResult, WorkspaceTerminateResult, SandboxDefaultsInput, } from "./types.js";
package/dist/index.js CHANGED
@@ -62,6 +62,13 @@ class GittermError extends Error {
62
62
  }
63
63
  }
64
64
 
65
+ class WorkspaceLifecycleError extends GittermError {
66
+ constructor(code, message, options = {}) {
67
+ super(code, message, options);
68
+ this.name = "WorkspaceLifecycleError";
69
+ }
70
+ }
71
+
65
72
  // src/client.ts
66
73
  function envValue(name) {
67
74
  const value = typeof process !== "undefined" ? process.env[name] : undefined;
@@ -121,7 +128,7 @@ function normalizeWorkspace(workspace) {
121
128
  imageId: workspace.image.imageId
122
129
  } : null,
123
130
  startedAt: toIso(workspace.startedAt),
124
- stoppedAt: toIso(workspace.stoppedAt),
131
+ pausedAt: toIso(workspace.pausedAt),
125
132
  terminatedAt: toIso(workspace.terminatedAt),
126
133
  lastActiveAt: toIso(workspace.lastActiveAt),
127
134
  updatedAt: toIso(workspace.updatedAt)
@@ -172,6 +179,24 @@ async function runWithServer(serverUrl, operation) {
172
179
  });
173
180
  }
174
181
  const code = mapTrpcCode(trpcCode);
182
+ if (/WORKSPACE_TERMINATED/.test(error.message)) {
183
+ throw new WorkspaceLifecycleError("WORKSPACE_TERMINATED", error.message, { cause: error });
184
+ }
185
+ if (/WORKSPACE_NON_RECOVERABLE/.test(error.message)) {
186
+ throw new WorkspaceLifecycleError("WORKSPACE_NON_RECOVERABLE", error.message, {
187
+ cause: error
188
+ });
189
+ }
190
+ if (/WORKSPACE_START_TIMEOUT/.test(error.message)) {
191
+ throw new WorkspaceLifecycleError("WORKSPACE_START_TIMEOUT", error.message, {
192
+ cause: error
193
+ });
194
+ }
195
+ if (/WORKSPACE_RESTART_FAILED/.test(error.message)) {
196
+ throw new WorkspaceLifecycleError("WORKSPACE_RESTART_FAILED", error.message, {
197
+ cause: error
198
+ });
199
+ }
175
200
  throw new GittermError(code, code === "UNAUTHORIZED" ? "Not logged in or token expired. Run: gitterm login" : error.message, { cause: error });
176
201
  }
177
202
  throw new GittermError("NETWORK", error instanceof Error ? error.message : "Network request failed", { cause: error });
@@ -190,7 +215,15 @@ function createGittermClient(options = {}) {
190
215
  });
191
216
  const run = (operation) => runWithServer(credentials.serverUrl, operation);
192
217
  const createWorkspace = (input) => run(async () => {
193
- const result = await trpc.workspace.createWorkspace.mutate(input);
218
+ const { agent, provider, regionId, ...workspaceInput } = input;
219
+ const defaults = await trpc.workspace.resolveSandboxDefaults.query({ agent, provider });
220
+ const apiInput = {
221
+ ...workspaceInput,
222
+ agentTypeId: defaults.agentTypeId,
223
+ cloudProviderId: defaults.cloudProviderId,
224
+ regionId: regionId ?? defaults.regionId
225
+ };
226
+ const result = await trpc.workspace.createWorkspace.mutate(apiInput);
194
227
  const workspace = normalizeWorkspace(result.workspace);
195
228
  if (!workspace)
196
229
  throw new GittermError("SERVER_ERROR", "Workspace creation failed");
@@ -283,7 +316,8 @@ function createGittermClient(options = {}) {
283
316
  cloudProviders: (input) => run(async () => {
284
317
  const result = await trpc.workspace.listCloudProviders.query(input);
285
318
  return result.cloudProviders;
286
- })
319
+ }),
320
+ resolveSandboxDefaults: (input) => run(async () => trpc.workspace.resolveSandboxDefaults.query(input))
287
321
  }
288
322
  };
289
323
  }
@@ -334,6 +368,7 @@ export {
334
368
  getConfigPath,
335
369
  deleteConfig,
336
370
  createGittermClient,
371
+ WorkspaceLifecycleError,
337
372
  GittermError,
338
373
  DEFAULT_GITTERM_SERVER_URL
339
374
  };
@@ -0,0 +1,133 @@
1
+ export type AuthStatus = {
2
+ loggedIn: true;
3
+ userId: string;
4
+ email: string;
5
+ name: string;
6
+ plan: string;
7
+ authMethod: "session" | "apiToken";
8
+ };
9
+ export type WorkspaceStatus = "pending" | "running" | "paused" | "terminated";
10
+ export type WorkspaceHostingType = "cloud" | "local";
11
+ export type Workspace = {
12
+ id: string;
13
+ name: string | null;
14
+ status: WorkspaceStatus;
15
+ repositoryUrl: string | null;
16
+ repositoryBranch: string | null;
17
+ baseCommit: string | null;
18
+ checkoutRef: string | null;
19
+ domain: string;
20
+ subdomain: string | null;
21
+ persistent: boolean;
22
+ hostingType: WorkspaceHostingType;
23
+ serverOnly: boolean;
24
+ workspaceProfile: string;
25
+ cloudProviderId: string;
26
+ agentType: {
27
+ id: string;
28
+ name: string;
29
+ description: string | null;
30
+ } | null;
31
+ image: {
32
+ id: string;
33
+ name: string;
34
+ imageId: string;
35
+ } | null;
36
+ startedAt: string | null;
37
+ pausedAt: string | null;
38
+ terminatedAt: string | null;
39
+ lastActiveAt: string | null;
40
+ updatedAt: string | null;
41
+ };
42
+ export type WorkspaceRuntimeAccess = {
43
+ workspaceId: string;
44
+ status: WorkspaceStatus;
45
+ url: string | null;
46
+ headers?: Record<string, string>;
47
+ password?: string;
48
+ directory: string;
49
+ repo: string | null;
50
+ branch: string | null;
51
+ baseCommit: string | null;
52
+ checkoutRef: string | null;
53
+ persistent: boolean;
54
+ recoverable: boolean;
55
+ providerKey: string | null;
56
+ };
57
+ export type WorkspaceCreateResult = {
58
+ workspace: Workspace;
59
+ runtime: WorkspaceRuntimeAccess;
60
+ };
61
+ export type WorkspaceListOptions = {
62
+ limit?: number;
63
+ offset?: number;
64
+ status?: "all" | "active" | "terminated";
65
+ };
66
+ export type WorkspaceListResult = {
67
+ workspaces: Workspace[];
68
+ pagination: {
69
+ total: number;
70
+ limit: number;
71
+ offset: number;
72
+ hasMore: boolean;
73
+ };
74
+ };
75
+ export type WorkspaceCreateInput = {
76
+ idempotencyKey?: string;
77
+ name?: string;
78
+ repo?: string;
79
+ branch?: string;
80
+ baseCommit?: string;
81
+ checkoutRef?: string;
82
+ subdomain?: string;
83
+ /** Unique enabled agent name. */
84
+ agent: string;
85
+ /** Unique enabled provider name. Optional when a preferred default exists. */
86
+ provider?: string;
87
+ regionId?: string;
88
+ gitIntegrationId?: string;
89
+ persistent: boolean;
90
+ workspaceProfile?: "standard" | "ssh-enabled";
91
+ modelCredentialIds?: string[];
92
+ };
93
+ export type WorkspaceRestartResult = {
94
+ status: WorkspaceStatus;
95
+ };
96
+ export type WorkspacePauseResult = {
97
+ durationMinutes: number;
98
+ };
99
+ export type WorkspaceTerminateResult = {
100
+ workspace: Workspace | null;
101
+ cleanupInBackground: boolean;
102
+ };
103
+ export type WorkspaceEnsureRunningResult = {
104
+ workspace: Workspace;
105
+ runtime: WorkspaceRuntimeAccess;
106
+ };
107
+ export type AgentType = {
108
+ id: string;
109
+ name: string;
110
+ description: string | null;
111
+ serverOnly: boolean;
112
+ isEnabled: boolean;
113
+ createdAt: Date | string;
114
+ updatedAt: Date | string;
115
+ };
116
+ export type CloudProvider = {
117
+ id: string;
118
+ name: string;
119
+ providerKey: string;
120
+ regions?: Array<Record<string, unknown>>;
121
+ [key: string]: unknown;
122
+ };
123
+ export type SandboxDefaults = {
124
+ agent: string;
125
+ provider: string;
126
+ agentTypeId: string;
127
+ cloudProviderId: string;
128
+ regionId?: string;
129
+ };
130
+ export type SandboxDefaultsInput = {
131
+ agent: string;
132
+ provider?: string;
133
+ };
package/package.json CHANGED
@@ -1,15 +1,14 @@
1
1
  {
2
2
  "name": "@gitterm/sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "files": [
5
- "dist",
6
- "src/index.d.ts"
5
+ "dist"
7
6
  ],
8
7
  "type": "module",
9
8
  "exports": {
10
9
  ".": {
11
- "types": "./src/index.d.ts",
12
- "bun": "./src/index.ts",
10
+ "types": "./dist/index.d.ts",
11
+ "bun": "./dist/index.js",
13
12
  "import": "./dist/index.js",
14
13
  "default": "./dist/index.js"
15
14
  }
@@ -18,7 +17,7 @@
18
17
  "access": "public"
19
18
  },
20
19
  "scripts": {
21
- "build": "bun build src/index.ts --outdir dist --target node --format esm --external @trpc/client && cp src/index.d.ts dist/index.d.ts",
20
+ "build": "rm -rf dist && bun build src/index.ts --outdir dist --target node --format esm --external @trpc/client && tsc -p tsconfig.build.json",
22
21
  "prepublishOnly": "bun run check-types && bun run build",
23
22
  "check-types": "tsc --noEmit"
24
23
  },
@@ -27,7 +26,6 @@
27
26
  },
28
27
  "devDependencies": {
29
28
  "@gitterm/api": "workspace:*",
30
- "@gitterm/config": "workspace:*",
31
29
  "@trpc/server": "catalog:",
32
30
  "@types/bun": "^1.2.6",
33
31
  "typescript": "^5.8.2"
package/src/index.d.ts DELETED
@@ -1,213 +0,0 @@
1
- /**
2
- * Hand-maintained public type surface for @gitterm/sdk.
3
- *
4
- * External npm consumers resolve these types instead of the TypeScript
5
- * sources, because the sources derive types from the private @gitterm/api
6
- * router. Keep this file in sync with src/types.ts and src/client.ts.
7
- *
8
- * TODO: replace with generated declarations once the AppRouter types can be
9
- * bundled into a standalone .d.ts.
10
- */
11
-
12
- export const DEFAULT_GITTERM_SERVER_URL: string;
13
-
14
- export type CliConfig = {
15
- serverUrl: string;
16
- token: string;
17
- createdAt: number;
18
- };
19
-
20
- export type GittermErrorCode =
21
- | "NOT_LOGGED_IN"
22
- | "UNAUTHORIZED"
23
- | "NOT_FOUND"
24
- | "FORBIDDEN"
25
- | "BAD_REQUEST"
26
- | "SERVER_ERROR"
27
- | "NETWORK";
28
-
29
- export class GittermError extends Error {
30
- readonly code: GittermErrorCode;
31
- readonly cause?: unknown;
32
- constructor(code: GittermErrorCode, message: string, options?: { cause?: unknown });
33
- }
34
-
35
- export type GittermClientOptions = {
36
- serverUrl?: string;
37
- token?: string;
38
- configPath?: string;
39
- fetch?: typeof fetch;
40
- };
41
-
42
- export type AuthStatus = {
43
- loggedIn: true;
44
- userId: string;
45
- email: string;
46
- name: string;
47
- plan: string;
48
- authMethod: "session" | "apiToken";
49
- };
50
-
51
- export type WorkspaceStatus = "pending" | "running" | "paused" | "terminated";
52
- export type WorkspaceHostingType = "cloud" | "local";
53
-
54
- export type Workspace = {
55
- id: string;
56
- name: string | null;
57
- status: WorkspaceStatus;
58
- repositoryUrl: string | null;
59
- repositoryBranch: string | null;
60
- baseCommit: string | null;
61
- checkoutRef: string | null;
62
- domain: string;
63
- subdomain: string | null;
64
- persistent: boolean;
65
- hostingType: WorkspaceHostingType;
66
- serverOnly: boolean;
67
- workspaceProfile: string;
68
- cloudProviderId: string;
69
- agentType: { id: string; name: string; description: string | null } | null;
70
- image: { id: string; name: string; imageId: string } | null;
71
- startedAt: string | null;
72
- stoppedAt: string | null;
73
- terminatedAt: string | null;
74
- lastActiveAt: string | null;
75
- updatedAt: string | null;
76
- };
77
-
78
- export type WorkspaceRuntimeAccess = {
79
- workspaceId: string;
80
- status: WorkspaceStatus;
81
- url: string | null;
82
- headers?: Record<string, string>;
83
- password?: string;
84
- directory: string;
85
- repo: string | null;
86
- branch: string | null;
87
- baseCommit: string | null;
88
- checkoutRef: string | null;
89
- persistent: boolean;
90
- recoverable: boolean;
91
- providerKey: string | null;
92
- };
93
-
94
- export type WorkspaceCreateResult = {
95
- workspace: Workspace;
96
- runtime: WorkspaceRuntimeAccess;
97
- };
98
-
99
- export type WorkspaceListOptions = {
100
- limit?: number;
101
- offset?: number;
102
- status?: "all" | "active" | "terminated";
103
- };
104
-
105
- export type WorkspaceListResult = {
106
- workspaces: Workspace[];
107
- pagination: {
108
- total: number;
109
- limit: number;
110
- offset: number;
111
- hasMore: boolean;
112
- };
113
- };
114
-
115
- export type WorkspaceCreateInput = {
116
- name?: string;
117
- repo?: string;
118
- branch?: string;
119
- baseCommit?: string;
120
- checkoutRef?: string;
121
- subdomain?: string;
122
- agentTypeId: string;
123
- cloudProviderId: string;
124
- regionId?: string;
125
- gitIntegrationId?: string;
126
- persistent: boolean;
127
- workspaceProfile?: "standard" | "ssh-enabled";
128
- };
129
-
130
- export type WorkspaceStopResult = { durationMinutes: number };
131
- export type WorkspacePauseResult = WorkspaceStopResult;
132
- export type WorkspaceRestartResult = { status: WorkspaceStatus };
133
- export type WorkspaceTerminateResult = {
134
- workspace: Workspace | null;
135
- cleanupInBackground: boolean;
136
- };
137
- export type WorkspaceEnsureRunningResult = {
138
- workspace: Workspace;
139
- runtime: WorkspaceRuntimeAccess;
140
- };
141
-
142
- export type AgentType = {
143
- id: string;
144
- name: string;
145
- description: string | null;
146
- serverOnly: boolean;
147
- isEnabled: boolean;
148
- createdAt: Date | string;
149
- updatedAt: Date | string;
150
- };
151
-
152
- export type CloudProvider = Record<string, unknown> & {
153
- id: string;
154
- name: string;
155
- providerKey: string;
156
- regions?: Array<Record<string, unknown>>;
157
- };
158
-
159
- export type GittermClient = {
160
- serverUrl: string;
161
- auth: {
162
- status(): Promise<AuthStatus>;
163
- };
164
- workspaces: {
165
- list(input?: WorkspaceListOptions): Promise<WorkspaceListResult>;
166
- get(workspaceId: string): Promise<Workspace>;
167
- getRuntimeAccess(workspaceId: string): Promise<WorkspaceRuntimeAccess>;
168
- ensureRunning(
169
- workspaceId: string,
170
- options?: { timeoutMs?: number; pollIntervalMs?: number },
171
- ): Promise<WorkspaceEnsureRunningResult>;
172
- pause(workspaceId: string): Promise<WorkspacePauseResult>;
173
- restart(workspaceId: string): Promise<WorkspaceRestartResult>;
174
- terminate(workspaceId: string): Promise<WorkspaceTerminateResult>;
175
- create(input: WorkspaceCreateInput): Promise<WorkspaceCreateResult>;
176
- createSandbox(input: WorkspaceCreateInput): Promise<WorkspaceCreateResult>;
177
- };
178
- catalog: {
179
- agentTypes(input?: { serverOnly?: boolean }): Promise<AgentType[]>;
180
- cloudProviders(input?: {
181
- localOnly?: boolean;
182
- cloudOnly?: boolean;
183
- sandboxOnly?: boolean;
184
- nonSandboxOnly?: boolean;
185
- }): Promise<CloudProvider[]>;
186
- };
187
- };
188
-
189
- export function createGittermClient(options?: GittermClientOptions): GittermClient;
190
- export function getConfigPath(configPath?: string): string;
191
- export function loadConfig(configPath?: string): Promise<CliConfig | null>;
192
- export function loadConfigSync(configPath?: string): CliConfig | null;
193
- export function saveConfig(config: CliConfig, configPath?: string): Promise<void>;
194
- export function deleteConfig(configPath?: string): Promise<void>;
195
-
196
- export type DeviceCodeInfo = {
197
- deviceCode: string;
198
- userCode: string;
199
- verificationUri: string;
200
- intervalSeconds: number;
201
- expiresInSeconds: number;
202
- };
203
-
204
- export type LoginWithDeviceCodeOptions = {
205
- clientName?: string;
206
- fetch?: typeof fetch;
207
- onCode?: (code: Omit<DeviceCodeInfo, "deviceCode">) => void | Promise<void>;
208
- };
209
-
210
- export function loginWithDeviceCode(
211
- serverUrl: string,
212
- options?: LoginWithDeviceCodeOptions,
213
- ): Promise<{ token: string }>;