@agentuity/core 1.0.49 → 1.0.50

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 (41) hide show
  1. package/dist/services/oauth/flow.d.ts +51 -0
  2. package/dist/services/oauth/flow.d.ts.map +1 -0
  3. package/dist/services/oauth/flow.js +183 -0
  4. package/dist/services/oauth/flow.js.map +1 -0
  5. package/dist/services/oauth/index.d.ts +1 -0
  6. package/dist/services/oauth/index.d.ts.map +1 -1
  7. package/dist/services/oauth/index.js +1 -0
  8. package/dist/services/oauth/index.js.map +1 -1
  9. package/dist/services/oauth/types.d.ts +34 -0
  10. package/dist/services/oauth/types.d.ts.map +1 -1
  11. package/dist/services/oauth/types.js +52 -0
  12. package/dist/services/oauth/types.js.map +1 -1
  13. package/dist/services/sandbox/create.d.ts +2 -0
  14. package/dist/services/sandbox/create.d.ts.map +1 -1
  15. package/dist/services/sandbox/create.js +4 -0
  16. package/dist/services/sandbox/create.js.map +1 -1
  17. package/dist/services/sandbox/index.d.ts +2 -0
  18. package/dist/services/sandbox/index.d.ts.map +1 -1
  19. package/dist/services/sandbox/index.js +1 -0
  20. package/dist/services/sandbox/index.js.map +1 -1
  21. package/dist/services/sandbox/job.d.ts +227 -0
  22. package/dist/services/sandbox/job.d.ts.map +1 -0
  23. package/dist/services/sandbox/job.js +109 -0
  24. package/dist/services/sandbox/job.js.map +1 -0
  25. package/dist/services/sandbox/types.d.ts +35 -0
  26. package/dist/services/sandbox/types.d.ts.map +1 -1
  27. package/dist/services/sandbox/types.js +23 -0
  28. package/dist/services/sandbox/types.js.map +1 -1
  29. package/dist/services/sandbox/util.d.ts +1 -0
  30. package/dist/services/sandbox/util.d.ts.map +1 -1
  31. package/dist/services/sandbox/util.js +1 -0
  32. package/dist/services/sandbox/util.js.map +1 -1
  33. package/package.json +2 -2
  34. package/src/services/oauth/flow.ts +215 -0
  35. package/src/services/oauth/index.ts +1 -0
  36. package/src/services/oauth/types.ts +66 -0
  37. package/src/services/sandbox/create.ts +4 -0
  38. package/src/services/sandbox/index.ts +18 -0
  39. package/src/services/sandbox/job.ts +161 -0
  40. package/src/services/sandbox/types.ts +29 -0
  41. package/src/services/sandbox/util.ts +1 -0
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/services/sandbox/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,IAAI,CAAC;IAC5C,mBAAmB;IACnB,oBAAoB;IACpB,cAAc;IACd,qBAAqB;IACrB,mBAAmB;IACnB,qBAAqB;IACrB,oBAAoB;CACpB,CAAC,CAAC;AAGH;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,eAAe,CAAC,sBAAsB,CAAC,EASvE,CAAC;AAEL;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,eAAe,CAAC,sBAAsB,CAAC,EAEvE,CAAC;AAEL;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,eAAe,CAAC,wBAAwB,CAAC,EAE3E,CAAC;AAEL;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAC,kBAAkB,CAAC,EAE/D,CAAC;AAEL;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,eAAe,CAAC,wBAAwB,CAAC,EAG3E,CAAC;AAEL;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,eAAe,CAAC,uBAAuB,CAAC,EAGzE,CAAC;AAEL;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,eAAe,CAAC,yBAAyB,CAAC,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AO,EAAE,MAAM,EAAE,EAAE;QACtC,IAAI,UAAmB,CAAC;QACxB,IAAI,CAAC;YACJ,UAAU,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,MAAM,CAAC,GAAG,CAAC,CAAC;YACZ,OAAO;QACR,CAAC;QACD,IAAI,UAAU,EAAE,CAAC;YAChB,MAAM,OAAO,GAAG,GAAG,EAAE;gBACpB,QAAQ,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC1C,QAAQ,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC3C,CAAC,CAAC;YACF,MAAM,OAAO,GAAG,GAAG,EAAE;gBACpB,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,CAAC;YACX,CAAC,CAAC;YACF,MAAM,OAAO,GAAG,CAAC,GAAU,EAAE,EAAE;gBAC9B,OAAO,EAAE,CAAC;gBACV,MAAM,CAAC,GAAG,CAAC,CAAC;YACb,CAAC,CAAC;YACF,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAChC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACP,OAAO,EAAE,CAAC;QACX,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentuity/core",
3
- "version": "1.0.49",
3
+ "version": "1.0.50",
4
4
  "license": "Apache-2.0",
5
5
  "author": "Agentuity employees and contributors",
6
6
  "type": "module",
@@ -89,7 +89,7 @@
89
89
  "zod": "^4.3.5"
90
90
  },
91
91
  "devDependencies": {
92
- "@agentuity/test-utils": "1.0.49",
92
+ "@agentuity/test-utils": "1.0.50",
93
93
  "@types/bun": "latest",
94
94
  "bun-types": "latest",
95
95
  "esbuild": "^0.25.0",
@@ -0,0 +1,215 @@
1
+ import { getEnv } from '../env.ts';
2
+ import { OAuthResponseError } from './util.ts';
3
+ import { OAuthTokenResponseSchema, OAuthUserInfoSchema } from './types.ts';
4
+ import type { OAuthFlowConfig, OAuthTokenResponse, OAuthUserInfo } from './types.ts';
5
+
6
+ const DEFAULT_TIMEOUT_MS = 30_000;
7
+
8
+ /**
9
+ * Resolve OAuth configuration by merging explicit config with environment variables.
10
+ * Priority: explicit config > env vars > issuer-derived URLs > defaults.
11
+ */
12
+ function resolveConfig(config?: OAuthFlowConfig) {
13
+ const clientId = config?.clientId ?? getEnv('OAUTH_CLIENT_ID');
14
+ const clientSecret = config?.clientSecret ?? getEnv('OAUTH_CLIENT_SECRET');
15
+ const issuer = config?.issuer ?? getEnv('OAUTH_ISSUER');
16
+ const authorizeUrl =
17
+ config?.authorizeUrl ??
18
+ getEnv('OAUTH_AUTHORIZE_URL') ??
19
+ (issuer ? `${issuer}/authorize` : undefined);
20
+ const tokenUrl =
21
+ config?.tokenUrl ??
22
+ getEnv('OAUTH_TOKEN_URL') ??
23
+ (issuer ? `${issuer}/oauth/token` : undefined);
24
+ const userinfoUrl =
25
+ config?.userinfoUrl ??
26
+ getEnv('OAUTH_USERINFO_URL') ??
27
+ (issuer ? `${issuer}/userinfo` : undefined);
28
+ const scopes = config?.scopes ?? getEnv('OAUTH_SCOPES') ?? 'openid profile email';
29
+
30
+ const prompt = config?.prompt;
31
+
32
+ return { clientId, clientSecret, issuer, authorizeUrl, tokenUrl, userinfoUrl, scopes, prompt };
33
+ }
34
+
35
+ /**
36
+ * Build an OAuth 2.0 authorization URL for redirecting the user to the OIDC provider.
37
+ *
38
+ * @param redirectUri - The callback URL the provider will redirect to after authentication
39
+ * @param config - Optional OAuth configuration. Falls back to environment variables.
40
+ * @returns The full authorization URL to redirect the user to
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * // Uses OAUTH_CLIENT_ID, OAUTH_AUTHORIZE_URL (or OAUTH_ISSUER) from env
45
+ * const url = buildAuthorizeUrl('http://localhost:3500/api/oauth/login');
46
+ *
47
+ * // Or with explicit config
48
+ * const url = buildAuthorizeUrl('http://localhost:3500/api/oauth/login', {
49
+ * issuer: 'https://auth.agentuity.cloud',
50
+ * clientId: 'my-client-id',
51
+ * });
52
+ * ```
53
+ */
54
+ export function buildAuthorizeUrl(redirectUri: string, config?: OAuthFlowConfig): string {
55
+ const resolved = resolveConfig(config);
56
+
57
+ if (!resolved.authorizeUrl) {
58
+ throw new OAuthResponseError({
59
+ message:
60
+ 'No authorize URL configured. Set OAUTH_AUTHORIZE_URL or OAUTH_ISSUER environment variable.',
61
+ });
62
+ }
63
+ if (!resolved.clientId) {
64
+ throw new OAuthResponseError({
65
+ message: 'No client ID configured. Set OAUTH_CLIENT_ID environment variable.',
66
+ });
67
+ }
68
+
69
+ const params = new URLSearchParams({
70
+ client_id: resolved.clientId,
71
+ redirect_uri: redirectUri,
72
+ response_type: 'code',
73
+ scope: resolved.scopes,
74
+ });
75
+
76
+ if (resolved.prompt) {
77
+ params.set('prompt', resolved.prompt);
78
+ }
79
+
80
+ return `${resolved.authorizeUrl}?${params.toString()}`;
81
+ }
82
+
83
+ /**
84
+ * Exchange an authorization code for an access token.
85
+ *
86
+ * @param code - The authorization code received from the OAuth callback
87
+ * @param redirectUri - The same redirect URI used in the authorization request
88
+ * @param config - Optional OAuth configuration. Falls back to environment variables.
89
+ * @returns The token response including access_token, and optionally refresh_token, id_token, etc.
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * const token = await exchangeToken(code, 'http://localhost:3500/api/oauth/login');
94
+ * console.log(token.access_token);
95
+ * ```
96
+ */
97
+ export async function exchangeToken(
98
+ code: string,
99
+ redirectUri: string,
100
+ config?: OAuthFlowConfig
101
+ ): Promise<OAuthTokenResponse> {
102
+ const resolved = resolveConfig(config);
103
+
104
+ if (!resolved.tokenUrl) {
105
+ throw new OAuthResponseError({
106
+ message:
107
+ 'No token URL configured. Set OAUTH_TOKEN_URL or OAUTH_ISSUER environment variable.',
108
+ });
109
+ }
110
+ if (!resolved.clientId) {
111
+ throw new OAuthResponseError({
112
+ message: 'No client ID configured. Set OAUTH_CLIENT_ID environment variable.',
113
+ });
114
+ }
115
+ if (!resolved.clientSecret) {
116
+ throw new OAuthResponseError({
117
+ message: 'No client secret configured. Set OAUTH_CLIENT_SECRET environment variable.',
118
+ });
119
+ }
120
+
121
+ const controller = new AbortController();
122
+ const timer = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS);
123
+
124
+ let response: Response;
125
+ try {
126
+ response = await fetch(resolved.tokenUrl, {
127
+ method: 'POST',
128
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
129
+ body: new URLSearchParams({
130
+ grant_type: 'authorization_code',
131
+ code,
132
+ redirect_uri: redirectUri,
133
+ client_id: resolved.clientId,
134
+ client_secret: resolved.clientSecret,
135
+ }),
136
+ signal: controller.signal,
137
+ });
138
+ } catch (err) {
139
+ clearTimeout(timer);
140
+ if (err instanceof DOMException && err.name === 'AbortError') {
141
+ throw new OAuthResponseError({
142
+ message: `Token exchange timed out after ${DEFAULT_TIMEOUT_MS}ms`,
143
+ });
144
+ }
145
+ throw err;
146
+ }
147
+ clearTimeout(timer);
148
+
149
+ if (!response.ok) {
150
+ const error = await response.text();
151
+ throw new OAuthResponseError({
152
+ message: `Token exchange failed (${response.status}): ${error}`,
153
+ });
154
+ }
155
+
156
+ const data = await response.json();
157
+ return OAuthTokenResponseSchema.parse(data);
158
+ }
159
+
160
+ /**
161
+ * Fetch user information from the OIDC userinfo endpoint using an access token.
162
+ *
163
+ * @param accessToken - The access token obtained from the token exchange
164
+ * @param config - Optional OAuth configuration. Falls back to environment variables.
165
+ * @returns The user info including sub, name, email, and any additional claims
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * const user = await fetchUserInfo(token.access_token);
170
+ * console.log(user.name, user.email);
171
+ * ```
172
+ */
173
+ export async function fetchUserInfo(
174
+ accessToken: string,
175
+ config?: OAuthFlowConfig
176
+ ): Promise<OAuthUserInfo> {
177
+ const resolved = resolveConfig(config);
178
+
179
+ if (!resolved.userinfoUrl) {
180
+ throw new OAuthResponseError({
181
+ message:
182
+ 'No userinfo URL configured. Set OAUTH_USERINFO_URL or OAUTH_ISSUER environment variable.',
183
+ });
184
+ }
185
+
186
+ const controller = new AbortController();
187
+ const timer = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS);
188
+
189
+ let response: Response;
190
+ try {
191
+ response = await fetch(resolved.userinfoUrl, {
192
+ headers: { Authorization: `Bearer ${accessToken}` },
193
+ signal: controller.signal,
194
+ });
195
+ } catch (err) {
196
+ clearTimeout(timer);
197
+ if (err instanceof DOMException && err.name === 'AbortError') {
198
+ throw new OAuthResponseError({
199
+ message: `Userinfo request timed out after ${DEFAULT_TIMEOUT_MS}ms`,
200
+ });
201
+ }
202
+ throw err;
203
+ }
204
+ clearTimeout(timer);
205
+
206
+ if (!response.ok) {
207
+ const error = await response.text();
208
+ throw new OAuthResponseError({
209
+ message: `Failed to fetch user info (${response.status}): ${error}`,
210
+ });
211
+ }
212
+
213
+ const data = await response.json();
214
+ return OAuthUserInfoSchema.parse(data);
215
+ }
@@ -6,3 +6,4 @@ export * from './scopes.ts';
6
6
  export * from './members.ts';
7
7
  export * from './keys.ts';
8
8
  export * from './util.ts';
9
+ export * from './flow.ts';
@@ -238,3 +238,69 @@ export type OAuthUserConsentRevokeResponse = z.infer<typeof OAuthUserConsentRevo
238
238
  export type OAuthScopesResponse = z.infer<typeof OAuthScopesResponseSchema>;
239
239
  export type OAuthOrgMembersResponse = z.infer<typeof OAuthOrgMembersResponseSchema>;
240
240
  export type OAuthKeysRotateResponse = z.infer<typeof OAuthKeysRotateResponseSchema>;
241
+
242
+ // ============================================================================
243
+ // OAuth 2.0 Authorization Code Flow Types
244
+ // ============================================================================
245
+
246
+ export const OAuthFlowConfigSchema = z.object({
247
+ clientId: z.string().optional().describe('OAuth client ID. Defaults to OAUTH_CLIENT_ID env var'),
248
+ clientSecret: z
249
+ .string()
250
+ .optional()
251
+ .describe('OAuth client secret. Defaults to OAUTH_CLIENT_SECRET env var'),
252
+ issuer: z
253
+ .string()
254
+ .optional()
255
+ .describe(
256
+ 'OIDC issuer base URL. Defaults to OAUTH_ISSUER env var. Used to derive authorize/token/userinfo URLs'
257
+ ),
258
+ authorizeUrl: z
259
+ .string()
260
+ .optional()
261
+ .describe('Authorization endpoint. Defaults to OAUTH_AUTHORIZE_URL or {issuer}/authorize'),
262
+ tokenUrl: z
263
+ .string()
264
+ .optional()
265
+ .describe('Token endpoint. Defaults to OAUTH_TOKEN_URL or {issuer}/oauth/token'),
266
+ userinfoUrl: z
267
+ .string()
268
+ .optional()
269
+ .describe('UserInfo endpoint. Defaults to OAUTH_USERINFO_URL or {issuer}/userinfo'),
270
+ scopes: z
271
+ .string()
272
+ .optional()
273
+ .describe('Space-separated scopes. Defaults to OAUTH_SCOPES or "openid profile email"'),
274
+ prompt: z
275
+ .enum(['none', 'login', 'consent', 'select_account'])
276
+ .optional()
277
+ .describe(
278
+ 'OIDC prompt parameter. Controls authentication UX: "login" forces re-auth, "consent" forces consent screen, "none" fails if not authenticated, "select_account" lets user pick an account'
279
+ ),
280
+ });
281
+
282
+ export type OAuthFlowConfig = z.infer<typeof OAuthFlowConfigSchema>;
283
+
284
+ export const OAuthTokenResponseSchema = z.object({
285
+ access_token: z.string(),
286
+ token_type: z.string().optional(),
287
+ expires_in: z.number().optional(),
288
+ refresh_token: z.string().optional(),
289
+ scope: z.string().optional(),
290
+ id_token: z.string().optional(),
291
+ });
292
+
293
+ export type OAuthTokenResponse = z.infer<typeof OAuthTokenResponseSchema>;
294
+
295
+ export const OAuthUserInfoSchema = z
296
+ .object({
297
+ sub: z.string(),
298
+ name: z.string().optional(),
299
+ given_name: z.string().optional(),
300
+ family_name: z.string().optional(),
301
+ email: z.string().optional(),
302
+ email_verified: z.boolean().optional(),
303
+ })
304
+ .catchall(z.unknown());
305
+
306
+ export type OAuthUserInfo = z.infer<typeof OAuthUserInfoSchema>;
@@ -133,6 +133,10 @@ export const SandboxCreateDataSchema = z
133
133
  'failed',
134
134
  ])
135
135
  .describe('Current status of the sandbox'),
136
+ url: z
137
+ .string()
138
+ .optional()
139
+ .describe('Public URL for the sandbox (only set when a network port is configured)'),
136
140
  stdoutStreamId: z.string().optional().describe('Stream ID for reading stdout'),
137
141
  stdoutStreamUrl: z.string().optional().describe('URL for streaming stdout output'),
138
142
  stderrStreamId: z.string().optional().describe('Stream ID for reading stderr'),
@@ -78,6 +78,24 @@ export {
78
78
  executionGet,
79
79
  executionList,
80
80
  } from './execution.ts';
81
+ export type {
82
+ JobCreateParams,
83
+ JobGetParams,
84
+ JobListParams,
85
+ JobListResponse,
86
+ JobStopParams,
87
+ } from './job.ts';
88
+ export {
89
+ JobCreateParamsSchema,
90
+ JobGetParamsSchema,
91
+ JobListParamsSchema,
92
+ JobListResponseSchema,
93
+ JobStopParamsSchema,
94
+ jobCreate,
95
+ jobGet,
96
+ jobList,
97
+ jobStop,
98
+ } from './job.ts';
81
99
  export type {
82
100
  SandboxEventInfo,
83
101
  SandboxEventListParams,
@@ -0,0 +1,161 @@
1
+ import { type APIClient, APIResponseSchema } from '../api.ts';
2
+ import { CreateJobOptionsSchema, JobSchema, type Job } from './types.ts';
3
+ import { throwSandboxError } from './util.ts';
4
+ import { z } from 'zod';
5
+
6
+ export const CreateJobRequestSchema = CreateJobOptionsSchema;
7
+
8
+ export const CreateJobDataSchema = JobSchema;
9
+
10
+ export const CreateJobResponseSchema = APIResponseSchema(CreateJobDataSchema);
11
+
12
+ export const JobCreateParamsSchema = z.object({
13
+ sandboxId: z.string().describe('Sandbox ID where the job should run'),
14
+ options: CreateJobOptionsSchema.describe('Job creation options'),
15
+ orgId: z.string().optional().describe('Optional org id for CLI auth context'),
16
+ signal: z.custom<AbortSignal>().optional().describe('Optional abort signal for cancellation'),
17
+ });
18
+ export type JobCreateParams = z.infer<typeof JobCreateParamsSchema>;
19
+
20
+ export async function jobCreate(client: APIClient, params: JobCreateParams): Promise<Job> {
21
+ const { sandboxId, options, orgId, signal } = params;
22
+ const body: z.infer<typeof CreateJobRequestSchema> = {
23
+ command: options.command,
24
+ };
25
+ if (options.streams) {
26
+ body.streams = options.streams;
27
+ }
28
+
29
+ const queryParams = new URLSearchParams();
30
+ if (orgId) {
31
+ queryParams.set('orgId', orgId);
32
+ }
33
+ const queryString = queryParams.toString();
34
+ const url = `/sandbox/sandboxes/${sandboxId}/jobs${queryString ? `?${queryString}` : ''}`;
35
+
36
+ const resp = await client.post<z.infer<typeof CreateJobResponseSchema>>(
37
+ url,
38
+ body,
39
+ CreateJobResponseSchema,
40
+ CreateJobRequestSchema,
41
+ signal
42
+ );
43
+
44
+ if (resp.success) {
45
+ return resp.data;
46
+ }
47
+
48
+ throwSandboxError(resp, { sandboxId });
49
+ }
50
+
51
+ export const JobGetDataSchema = JobSchema;
52
+
53
+ export const JobGetResponseSchema = APIResponseSchema(JobGetDataSchema);
54
+
55
+ export const JobGetParamsSchema = z.object({
56
+ sandboxId: z.string().describe('Sandbox ID'),
57
+ jobId: z.string().describe('Job ID'),
58
+ orgId: z.string().optional().describe('Organization ID'),
59
+ signal: z.custom<AbortSignal>().optional().describe('Abort signal for cancellation'),
60
+ });
61
+ export type JobGetParams = z.infer<typeof JobGetParamsSchema>;
62
+
63
+ export async function jobGet(client: APIClient, params: JobGetParams): Promise<Job> {
64
+ const { sandboxId, jobId, orgId, signal } = params;
65
+ const queryParams = new URLSearchParams();
66
+ if (orgId) {
67
+ queryParams.set('orgId', orgId);
68
+ }
69
+ const queryString = queryParams.toString();
70
+ const url = `/sandbox/sandboxes/${sandboxId}/jobs/${jobId}${queryString ? `?${queryString}` : ''}`;
71
+
72
+ const resp = await client.get<z.infer<typeof JobGetResponseSchema>>(
73
+ url,
74
+ JobGetResponseSchema,
75
+ signal
76
+ );
77
+
78
+ if (resp.success) {
79
+ return resp.data;
80
+ }
81
+
82
+ throwSandboxError(resp, { sandboxId, jobId: params.jobId });
83
+ }
84
+
85
+ export const JobListDataSchema = z.object({
86
+ jobs: z.array(JobSchema).describe('List of jobs'),
87
+ });
88
+ export type JobListResponse = z.infer<typeof JobListDataSchema>;
89
+
90
+ export const JobListResponseSchema = APIResponseSchema(JobListDataSchema);
91
+
92
+ export const JobListParamsSchema = z.object({
93
+ sandboxId: z.string().describe('Sandbox ID'),
94
+ orgId: z.string().optional().describe('Organization ID'),
95
+ limit: z.number().optional().describe('Maximum number of results'),
96
+ signal: z.custom<AbortSignal>().optional().describe('Abort signal for cancellation'),
97
+ });
98
+ export type JobListParams = z.infer<typeof JobListParamsSchema>;
99
+
100
+ export async function jobList(client: APIClient, params: JobListParams): Promise<JobListResponse> {
101
+ const { sandboxId, orgId, limit, signal } = params;
102
+ const queryParams = new URLSearchParams();
103
+ if (orgId) {
104
+ queryParams.set('orgId', orgId);
105
+ }
106
+ if (limit !== undefined) {
107
+ queryParams.set('limit', String(limit));
108
+ }
109
+ const queryString = queryParams.toString();
110
+ const url = `/sandbox/sandboxes/${sandboxId}/jobs${queryString ? `?${queryString}` : ''}`;
111
+
112
+ const resp = await client.get<z.infer<typeof JobListResponseSchema>>(
113
+ url,
114
+ JobListResponseSchema,
115
+ signal
116
+ );
117
+
118
+ if (resp.success) {
119
+ return resp.data;
120
+ }
121
+
122
+ throwSandboxError(resp, { sandboxId });
123
+ }
124
+
125
+ export const JobStopDataSchema = JobSchema;
126
+
127
+ export const JobStopResponseSchema = APIResponseSchema(JobStopDataSchema);
128
+
129
+ export const JobStopParamsSchema = z.object({
130
+ sandboxId: z.string().describe('Sandbox ID'),
131
+ jobId: z.string().describe('Job ID'),
132
+ force: z.boolean().optional().describe('Force termination (SIGKILL)'),
133
+ orgId: z.string().optional().describe('Organization ID'),
134
+ signal: z.custom<AbortSignal>().optional().describe('Abort signal for cancellation'),
135
+ });
136
+ export type JobStopParams = z.infer<typeof JobStopParamsSchema>;
137
+
138
+ export async function jobStop(client: APIClient, params: JobStopParams): Promise<Job> {
139
+ const { sandboxId, jobId, force, orgId, signal } = params;
140
+ const queryParams = new URLSearchParams();
141
+ if (orgId) {
142
+ queryParams.set('orgId', orgId);
143
+ }
144
+ if (force) {
145
+ queryParams.set('force', 'true');
146
+ }
147
+ const queryString = queryParams.toString();
148
+ const url = `/sandbox/sandboxes/${sandboxId}/jobs/${jobId}${queryString ? `?${queryString}` : ''}`;
149
+
150
+ const resp = await client.delete<z.infer<typeof JobStopResponseSchema>>(
151
+ url,
152
+ JobStopResponseSchema,
153
+ signal
154
+ );
155
+
156
+ if (resp.success) {
157
+ return resp.data;
158
+ }
159
+
160
+ throwSandboxError(resp, { sandboxId, jobId: params.jobId });
161
+ }
@@ -167,6 +167,35 @@ export const ExecutionStatusSchema = z.enum([
167
167
  ]);
168
168
  export type ExecutionStatus = z.infer<typeof ExecutionStatusSchema>;
169
169
 
170
+ export const JobStatusSchema = z.enum(['pending', 'running', 'completed', 'failed', 'cancelled']);
171
+ export type JobStatus = z.infer<typeof JobStatusSchema>;
172
+
173
+ export const JobSchema = z.object({
174
+ jobId: z.string().describe('Unique identifier for the job'),
175
+ sandboxId: z.string().describe('ID of the sandbox where the job is running'),
176
+ command: z.array(z.string()).describe('Command and arguments being executed'),
177
+ status: JobStatusSchema.describe('Current status of the job'),
178
+ exitCode: z.number().optional().describe('Exit code of the job (set when completed)'),
179
+ startedAt: z.string().optional().describe('ISO timestamp when the job started'),
180
+ completedAt: z.string().optional().describe('ISO timestamp when the job completed'),
181
+ error: z.string().optional().describe('Error message if the job failed'),
182
+ stdoutStreamUrl: z.string().optional().describe('URL to stream stdout output'),
183
+ stderrStreamUrl: z.string().optional().describe('URL to stream stderr output'),
184
+ });
185
+ export type Job = z.infer<typeof JobSchema>;
186
+
187
+ export const CreateJobOptionsSchema = z.object({
188
+ command: z.array(z.string()).describe('Command and arguments to execute'),
189
+ streams: z
190
+ .object({
191
+ stdout: z.string().optional().describe('Stream ID for stdout output'),
192
+ stderr: z.string().optional().describe('Stream ID for stderr output'),
193
+ })
194
+ .optional()
195
+ .describe('Stream configuration for output redirection'),
196
+ });
197
+ export type CreateJobOptions = z.infer<typeof CreateJobOptionsSchema>;
198
+
170
199
  /** Read-only stream interface for consuming streams without write access */
171
200
  export const StreamReaderSchema = z.object({
172
201
  /** Unique stream identifier */
@@ -176,6 +176,7 @@ export const SnapshotNotFoundError = StructuredError('SnapshotNotFoundError')<{
176
176
  export const SandboxErrorContextSchema = z.object({
177
177
  sandboxId: z.string().optional().describe('sandbox id'),
178
178
  executionId: z.string().optional().describe('execution id'),
179
+ jobId: z.string().optional().describe('job id'),
179
180
  sessionId: z.string().nullish().describe('session id'),
180
181
  snapshotId: z.string().optional().describe('snapshot id'),
181
182
  });