@agentuity/core 2.0.9 → 2.0.11
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/dist/services/coder/agents.d.ts +170 -0
- package/dist/services/coder/agents.d.ts.map +1 -0
- package/dist/services/coder/agents.js +77 -0
- package/dist/services/coder/agents.js.map +1 -0
- package/dist/services/coder/api-reference.d.ts.map +1 -1
- package/dist/services/coder/api-reference.js +393 -41
- package/dist/services/coder/api-reference.js.map +1 -1
- package/dist/services/coder/client.d.ts +44 -2
- package/dist/services/coder/client.d.ts.map +1 -1
- package/dist/services/coder/client.js +89 -3
- package/dist/services/coder/client.js.map +1 -1
- package/dist/services/coder/close-codes.d.ts +76 -0
- package/dist/services/coder/close-codes.d.ts.map +1 -0
- package/dist/services/coder/close-codes.js +77 -0
- package/dist/services/coder/close-codes.js.map +1 -0
- package/dist/services/coder/discover.d.ts +1 -1
- package/dist/services/coder/discover.js +2 -2
- package/dist/services/coder/discover.js.map +1 -1
- package/dist/services/coder/index.d.ts +9 -2
- package/dist/services/coder/index.d.ts.map +1 -1
- package/dist/services/coder/index.js +6 -1
- package/dist/services/coder/index.js.map +1 -1
- package/dist/services/coder/protocol.d.ts +1855 -0
- package/dist/services/coder/protocol.d.ts.map +1 -0
- package/dist/services/coder/protocol.js +976 -0
- package/dist/services/coder/protocol.js.map +1 -0
- package/dist/services/coder/sessions.d.ts +9 -0
- package/dist/services/coder/sessions.d.ts.map +1 -1
- package/dist/services/coder/sessions.js +30 -6
- package/dist/services/coder/sessions.js.map +1 -1
- package/dist/services/coder/sse.d.ts +255 -0
- package/dist/services/coder/sse.d.ts.map +1 -0
- package/dist/services/coder/sse.js +676 -0
- package/dist/services/coder/sse.js.map +1 -0
- package/dist/services/coder/types.d.ts +1013 -0
- package/dist/services/coder/types.d.ts.map +1 -1
- package/dist/services/coder/types.js +215 -1
- package/dist/services/coder/types.js.map +1 -1
- package/dist/services/coder/websocket.d.ts +346 -0
- package/dist/services/coder/websocket.d.ts.map +1 -0
- package/dist/services/coder/websocket.js +791 -0
- package/dist/services/coder/websocket.js.map +1 -0
- package/dist/services/oauth/types.d.ts +10 -0
- package/dist/services/oauth/types.d.ts.map +1 -1
- package/dist/services/oauth/types.js +3 -0
- package/dist/services/oauth/types.js.map +1 -1
- package/dist/services/project/deploy.d.ts +1 -1
- package/dist/services/sandbox/run.d.ts +2 -2
- package/dist/services/sandbox/types.d.ts +2 -2
- package/package.json +2 -2
- package/src/services/coder/agents.ts +148 -0
- package/src/services/coder/api-reference.ts +411 -45
- package/src/services/coder/client.ts +133 -2
- package/src/services/coder/close-codes.ts +83 -0
- package/src/services/coder/discover.ts +2 -2
- package/src/services/coder/index.ts +29 -1
- package/src/services/coder/protocol.ts +1200 -0
- package/src/services/coder/sessions.ts +40 -10
- package/src/services/coder/sse.ts +796 -0
- package/src/services/coder/types.ts +249 -1
- package/src/services/coder/websocket.ts +943 -0
- package/src/services/oauth/types.ts +3 -0
|
@@ -14,12 +14,22 @@ import {
|
|
|
14
14
|
coderGetSession,
|
|
15
15
|
coderListConnectableSessions,
|
|
16
16
|
coderListSessions,
|
|
17
|
+
coderResumeSession,
|
|
17
18
|
coderUpdateSession,
|
|
18
19
|
type CoderCreateSessionParams,
|
|
19
20
|
type CoderUpdateSessionResponse,
|
|
20
21
|
type CoderListConnectableSessionsParams,
|
|
21
22
|
type CoderListSessionsParamsWithOrg,
|
|
22
23
|
} from './sessions.ts';
|
|
24
|
+
import {
|
|
25
|
+
coderArchiveCustomAgent,
|
|
26
|
+
coderCreateCustomAgent,
|
|
27
|
+
coderGetCustomAgent,
|
|
28
|
+
coderListCustomAgents,
|
|
29
|
+
coderListCustomAgentVersions,
|
|
30
|
+
coderPublishCustomAgent,
|
|
31
|
+
coderUpdateCustomAgent,
|
|
32
|
+
} from './agents.ts';
|
|
23
33
|
import {
|
|
24
34
|
coderCreateSkillBucket,
|
|
25
35
|
coderDeleteSavedSkill,
|
|
@@ -48,6 +58,10 @@ import { coderListUsers, type CoderListUsersParamsWithOrg } from './users.ts';
|
|
|
48
58
|
import type {
|
|
49
59
|
CoderGitHubAccountListResponse,
|
|
50
60
|
CoderGitHubRepositoryListResponse,
|
|
61
|
+
CoderCustomAgent,
|
|
62
|
+
CoderCustomAgentListResponse,
|
|
63
|
+
CoderCustomAgentVersionListResponse,
|
|
64
|
+
CoderCreateCustomAgentRequest,
|
|
51
65
|
CoderListUsersResponse,
|
|
52
66
|
CoderSavedSkill,
|
|
53
67
|
CoderSavedSkillListResponse,
|
|
@@ -60,6 +74,7 @@ import type {
|
|
|
60
74
|
CoderSkillBucket,
|
|
61
75
|
CoderSkillBucketListResponse,
|
|
62
76
|
CoderCreateSkillBucketRequest,
|
|
77
|
+
CoderUpdateCustomAgentRequest,
|
|
63
78
|
CoderCreateWorkspaceRequest,
|
|
64
79
|
CoderWorkspaceDetail,
|
|
65
80
|
CoderWorkspaceListResponse,
|
|
@@ -71,7 +86,7 @@ import { normalizeCoderUrl } from './util.ts';
|
|
|
71
86
|
export const CoderClientOptionsSchema = z
|
|
72
87
|
.object({
|
|
73
88
|
apiKey: z.string().optional().describe('API key for authentication'),
|
|
74
|
-
url: z.string().optional().describe('Base URL for the Coder
|
|
89
|
+
url: z.string().optional().describe('Base URL for the Coder HTTP API'),
|
|
75
90
|
region: z.string().optional().describe('Region used for Catalyst URL resolution'),
|
|
76
91
|
orgId: z.string().optional().describe('Organization ID for multi-tenant operations'),
|
|
77
92
|
logger: z.custom<Logger>().optional().describe('Custom logger implementation'),
|
|
@@ -79,8 +94,13 @@ export const CoderClientOptionsSchema = z
|
|
|
79
94
|
.describe('Configuration options for constructing a CoderClient');
|
|
80
95
|
export type CoderClientOptions = z.infer<typeof CoderClientOptionsSchema>;
|
|
81
96
|
|
|
97
|
+
export interface CoderRemoteAttachPreparationOptions {
|
|
98
|
+
timeoutMs?: number;
|
|
99
|
+
pollIntervalMs?: number;
|
|
100
|
+
}
|
|
101
|
+
|
|
82
102
|
/**
|
|
83
|
-
* Ergonomic client for Coder
|
|
103
|
+
* Ergonomic client for Coder session management APIs.
|
|
84
104
|
*
|
|
85
105
|
* URL resolution strategy:
|
|
86
106
|
* 1) options.url
|
|
@@ -214,6 +234,54 @@ export class CoderClient {
|
|
|
214
234
|
return coderArchiveSession(client, { sessionId, orgId: this.#orgId });
|
|
215
235
|
}
|
|
216
236
|
|
|
237
|
+
/**
|
|
238
|
+
* Requests that a wakeable sandbox session be resumed.
|
|
239
|
+
*/
|
|
240
|
+
async resumeSession(sessionId: string): Promise<CoderLifecycleResponse> {
|
|
241
|
+
const client = await this.#getClient();
|
|
242
|
+
return coderResumeSession(client, { sessionId, orgId: this.#orgId });
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Makes sure a paused remote session is attachable before opening the controller socket.
|
|
247
|
+
*/
|
|
248
|
+
async prepareSessionForRemoteAttach(
|
|
249
|
+
sessionId: string,
|
|
250
|
+
options: CoderRemoteAttachPreparationOptions = {}
|
|
251
|
+
): Promise<CoderSession> {
|
|
252
|
+
const timeoutMs = options.timeoutMs ?? 30_000;
|
|
253
|
+
const pollIntervalMs = options.pollIntervalMs ?? 1_000;
|
|
254
|
+
let session = await this.getSession(sessionId);
|
|
255
|
+
|
|
256
|
+
if (session.historyOnly === true) {
|
|
257
|
+
return session;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (session.wakeAvailable === true && session.runtimeAvailable === false) {
|
|
261
|
+
await this.resumeSession(sessionId);
|
|
262
|
+
const deadline = Date.now() + timeoutMs;
|
|
263
|
+
|
|
264
|
+
while (Date.now() < deadline) {
|
|
265
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
266
|
+
try {
|
|
267
|
+
session = await this.getSession(sessionId);
|
|
268
|
+
} catch (err) {
|
|
269
|
+
this.#logger.debug(
|
|
270
|
+
'coder remote attach poll failed for %s: %s',
|
|
271
|
+
sessionId,
|
|
272
|
+
err instanceof Error ? err.message : String(err)
|
|
273
|
+
);
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (session.historyOnly === true || session.runtimeAvailable !== false) {
|
|
277
|
+
return session;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return session;
|
|
283
|
+
}
|
|
284
|
+
|
|
217
285
|
/**
|
|
218
286
|
* Lists sessions the caller can connect to.
|
|
219
287
|
*/
|
|
@@ -256,6 +324,69 @@ export class CoderClient {
|
|
|
256
324
|
return coderDeleteWorkspace(client, { workspaceId });
|
|
257
325
|
}
|
|
258
326
|
|
|
327
|
+
/**
|
|
328
|
+
* Lists custom agents in the org library.
|
|
329
|
+
*/
|
|
330
|
+
async listCustomAgents(options?: {
|
|
331
|
+
includeArchived?: boolean;
|
|
332
|
+
}): Promise<CoderCustomAgentListResponse> {
|
|
333
|
+
const client = await this.#getClient();
|
|
334
|
+
return coderListCustomAgents(client, { ...options, orgId: this.#orgId });
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Retrieves a custom agent by id or slug.
|
|
339
|
+
*/
|
|
340
|
+
async getCustomAgent(agentIdOrSlug: string): Promise<CoderCustomAgent> {
|
|
341
|
+
const client = await this.#getClient();
|
|
342
|
+
return coderGetCustomAgent(client, { agentIdOrSlug, orgId: this.#orgId });
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Creates a new custom-agent draft.
|
|
347
|
+
*/
|
|
348
|
+
async createCustomAgent(body: CoderCreateCustomAgentRequest): Promise<CoderCustomAgent> {
|
|
349
|
+
const client = await this.#getClient();
|
|
350
|
+
return coderCreateCustomAgent(client, { body, orgId: this.#orgId });
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Updates an existing custom-agent draft.
|
|
355
|
+
*/
|
|
356
|
+
async updateCustomAgent(
|
|
357
|
+
agentIdOrSlug: string,
|
|
358
|
+
body: CoderUpdateCustomAgentRequest
|
|
359
|
+
): Promise<CoderCustomAgent> {
|
|
360
|
+
const client = await this.#getClient();
|
|
361
|
+
return coderUpdateCustomAgent(client, { agentIdOrSlug, body, orgId: this.#orgId });
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Publishes the latest custom-agent draft as a new immutable version.
|
|
366
|
+
*/
|
|
367
|
+
async publishCustomAgent(agentIdOrSlug: string): Promise<CoderCustomAgent> {
|
|
368
|
+
const client = await this.#getClient();
|
|
369
|
+
return coderPublishCustomAgent(client, { agentIdOrSlug, orgId: this.#orgId });
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Archives a custom agent from the org library.
|
|
374
|
+
*/
|
|
375
|
+
async archiveCustomAgent(agentIdOrSlug: string): Promise<CoderCustomAgent> {
|
|
376
|
+
const client = await this.#getClient();
|
|
377
|
+
return coderArchiveCustomAgent(client, { agentIdOrSlug, orgId: this.#orgId });
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Lists published versions for a custom agent.
|
|
382
|
+
*/
|
|
383
|
+
async listCustomAgentVersions(
|
|
384
|
+
agentIdOrSlug: string
|
|
385
|
+
): Promise<CoderCustomAgentVersionListResponse> {
|
|
386
|
+
const client = await this.#getClient();
|
|
387
|
+
return coderListCustomAgentVersions(client, { agentIdOrSlug, orgId: this.#orgId });
|
|
388
|
+
}
|
|
389
|
+
|
|
259
390
|
/**
|
|
260
391
|
* Lists saved skills in the caller's library.
|
|
261
392
|
*/
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket close codes for the Coder Hub.
|
|
3
|
+
*
|
|
4
|
+
* These codes use the 4xxx private range defined by RFC 6455, allowing
|
|
5
|
+
* application-specific close reasons that trigger terminal disconnection
|
|
6
|
+
* (no automatic reconnect).
|
|
7
|
+
*
|
|
8
|
+
* @module coder/close-codes
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { CODER_WS_CLOSE_CODE, isTerminalCloseCode } from '@agentuity/core/coder';
|
|
13
|
+
*
|
|
14
|
+
* // Check if a close code is terminal (should not reconnect)
|
|
15
|
+
* if (isTerminalCloseCode(4401)) {
|
|
16
|
+
* console.log('Auth failed, will not reconnect');
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* // Use close codes when closing connections
|
|
20
|
+
* client.close(CODER_WS_CLOSE_CODE.AUTH_REQUIRED, 'Invalid API key');
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Application-defined WebSocket close codes for the Coder Hub.
|
|
26
|
+
*
|
|
27
|
+
* These codes indicate specific error conditions that should not trigger
|
|
28
|
+
* automatic reconnection. The 4xxx range is reserved for application use
|
|
29
|
+
* per RFC 6455.
|
|
30
|
+
*/
|
|
31
|
+
export const CODER_WS_CLOSE_CODE = {
|
|
32
|
+
/** Invalid request parameters (4000 range equivalent) */
|
|
33
|
+
BAD_REQUEST: 4400,
|
|
34
|
+
/** Authentication required or credentials invalid */
|
|
35
|
+
AUTH_REQUIRED: 4401,
|
|
36
|
+
/** Authenticated but not authorized for this resource */
|
|
37
|
+
FORBIDDEN: 4403,
|
|
38
|
+
/** The requested session does not exist */
|
|
39
|
+
SESSION_NOT_FOUND: 4404,
|
|
40
|
+
/** Service temporarily unavailable */
|
|
41
|
+
UNAVAILABLE: 4408,
|
|
42
|
+
/** Session already has an active lead connection */
|
|
43
|
+
SESSION_ACTIVE: 4409,
|
|
44
|
+
/** Reconnecting driver with stale instance ID */
|
|
45
|
+
STALE_DRIVER: 4410,
|
|
46
|
+
/** Rate limit exceeded */
|
|
47
|
+
RATE_LIMITED: 4429,
|
|
48
|
+
/** Internal server error */
|
|
49
|
+
INTERNAL_ERROR: 4500,
|
|
50
|
+
} as const;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Union type of all valid Coder Hub WebSocket close codes.
|
|
54
|
+
*/
|
|
55
|
+
export type CoderWsCloseCode = (typeof CODER_WS_CLOSE_CODE)[keyof typeof CODER_WS_CLOSE_CODE];
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Determines if a close code indicates a terminal error that should not
|
|
59
|
+
* trigger automatic reconnection.
|
|
60
|
+
*
|
|
61
|
+
* Close codes in the 4000-4999 range are application-defined terminal errors.
|
|
62
|
+
* The WebSocket client should NOT attempt to reconnect when receiving these codes.
|
|
63
|
+
*
|
|
64
|
+
* @param code - The WebSocket close code to check
|
|
65
|
+
* @returns `true` if the code indicates a terminal error, `false` otherwise
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* client.onClose((code, reason) => {
|
|
70
|
+
* if (isTerminalCloseCode(code)) {
|
|
71
|
+
* console.log('Terminal error, will not reconnect:', reason);
|
|
72
|
+
* } else {
|
|
73
|
+
* console.log('Transient error, will attempt reconnect');
|
|
74
|
+
* }
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export function isTerminalCloseCode(code: number): boolean {
|
|
79
|
+
if (code === CODER_WS_CLOSE_CODE.UNAVAILABLE || code === CODER_WS_CLOSE_CODE.RATE_LIMITED) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return code >= 4000 && code < 5000;
|
|
83
|
+
}
|
|
@@ -4,12 +4,12 @@ import { normalizeCoderUrl } from './util.ts';
|
|
|
4
4
|
|
|
5
5
|
export const DiscoverCoderUrlDataSchema = z
|
|
6
6
|
.object({
|
|
7
|
-
url: z.string().describe('Discovered base URL for the organization
|
|
7
|
+
url: z.string().describe('Discovered base URL for the organization Coder URL'),
|
|
8
8
|
})
|
|
9
9
|
.describe('Response payload for coder URL discovery');
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Discovers the org-specific Coder
|
|
12
|
+
* Discovers the org-specific Coder URL.
|
|
13
13
|
*
|
|
14
14
|
* Calls `GET /coder` on the Catalyst API. The org is resolved server-side
|
|
15
15
|
* from the API key's auth context (not via query parameters).
|
|
@@ -20,6 +20,7 @@ export {
|
|
|
20
20
|
coderGetSession,
|
|
21
21
|
coderListConnectableSessions,
|
|
22
22
|
coderListSessions,
|
|
23
|
+
coderResumeSession,
|
|
23
24
|
coderUpdateSession,
|
|
24
25
|
CoderCreateSessionParamsSchema,
|
|
25
26
|
CoderGetSessionParamsSchema,
|
|
@@ -30,6 +31,7 @@ export {
|
|
|
30
31
|
} from './sessions.ts';
|
|
31
32
|
|
|
32
33
|
export * from './skills.ts';
|
|
34
|
+
export * from './agents.ts';
|
|
33
35
|
export * from './workspaces.ts';
|
|
34
36
|
export * from './github.ts';
|
|
35
37
|
|
|
@@ -53,7 +55,7 @@ export { coderGetLoopState, CoderGetLoopStateParamsSchema } from './loop-state.t
|
|
|
53
55
|
export type { CoderListUsersParamsWithOrg } from './users.ts';
|
|
54
56
|
export { coderListUsers, CoderListUsersParamsWithOrgSchema } from './users.ts';
|
|
55
57
|
|
|
56
|
-
export type { CoderClientOptions } from './client.ts';
|
|
58
|
+
export type { CoderClientOptions, CoderRemoteAttachPreparationOptions } from './client.ts';
|
|
57
59
|
export { CoderClient, CoderClientOptionsSchema } from './client.ts';
|
|
58
60
|
|
|
59
61
|
export type { CoderErrorCode, CoderErrorContext } from './util.ts';
|
|
@@ -70,3 +72,29 @@ export {
|
|
|
70
72
|
} from './util.ts';
|
|
71
73
|
|
|
72
74
|
export { default as CoderAPIReference } from './api-reference.ts';
|
|
75
|
+
|
|
76
|
+
export * from './protocol.ts';
|
|
77
|
+
|
|
78
|
+
export { CODER_WS_CLOSE_CODE, type CoderWsCloseCode, isTerminalCloseCode } from './close-codes.ts';
|
|
79
|
+
|
|
80
|
+
export type { CoderHubWebSocketState, CoderHubWebSocketOptions } from './websocket.ts';
|
|
81
|
+
export {
|
|
82
|
+
CoderHubWebSocketClient,
|
|
83
|
+
CoderHubWebSocketOptionsSchema,
|
|
84
|
+
CoderHubWebSocketError,
|
|
85
|
+
subscribeToCoderHub,
|
|
86
|
+
} from './websocket.ts';
|
|
87
|
+
|
|
88
|
+
export type {
|
|
89
|
+
CoderSSEOptions,
|
|
90
|
+
CoderSSEEvent,
|
|
91
|
+
CoderSSEClientOptions,
|
|
92
|
+
CoderSSEState,
|
|
93
|
+
} from './sse.ts';
|
|
94
|
+
export {
|
|
95
|
+
CoderSSEOptionsSchema,
|
|
96
|
+
CoderSSEClientOptionsSchema,
|
|
97
|
+
CoderSSEError,
|
|
98
|
+
CoderSSEClient,
|
|
99
|
+
streamCoderSessionSSE,
|
|
100
|
+
} from './sse.ts';
|