@agent-os-sdk/client 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.
Files changed (147) hide show
  1. package/README.md +71 -0
  2. package/dist/client/AgentOsClient.d.ts +161 -0
  3. package/dist/client/AgentOsClient.d.ts.map +1 -0
  4. package/dist/client/AgentOsClient.js +217 -0
  5. package/dist/client/helpers.d.ts +63 -0
  6. package/dist/client/helpers.d.ts.map +1 -0
  7. package/dist/client/helpers.js +55 -0
  8. package/dist/client/raw.d.ts +138 -0
  9. package/dist/client/raw.d.ts.map +1 -0
  10. package/dist/client/raw.js +97 -0
  11. package/dist/generated/index.d.ts +2 -0
  12. package/dist/generated/index.d.ts.map +1 -0
  13. package/dist/generated/index.js +1 -0
  14. package/dist/generated/openapi.d.ts +6810 -0
  15. package/dist/generated/openapi.d.ts.map +1 -0
  16. package/dist/generated/openapi.js +5 -0
  17. package/dist/index.d.ts +72 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +86 -0
  20. package/dist/modules/a2a.d.ts +48 -0
  21. package/dist/modules/a2a.d.ts.map +1 -0
  22. package/dist/modules/a2a.js +37 -0
  23. package/dist/modules/agents.d.ts +137 -0
  24. package/dist/modules/agents.d.ts.map +1 -0
  25. package/dist/modules/agents.js +154 -0
  26. package/dist/modules/audit.d.ts +55 -0
  27. package/dist/modules/audit.d.ts.map +1 -0
  28. package/dist/modules/audit.js +38 -0
  29. package/dist/modules/builder.d.ts +65 -0
  30. package/dist/modules/builder.d.ts.map +1 -0
  31. package/dist/modules/builder.js +119 -0
  32. package/dist/modules/checkpoints.d.ts +53 -0
  33. package/dist/modules/checkpoints.d.ts.map +1 -0
  34. package/dist/modules/checkpoints.js +39 -0
  35. package/dist/modules/credentials.d.ts +89 -0
  36. package/dist/modules/credentials.d.ts.map +1 -0
  37. package/dist/modules/credentials.js +79 -0
  38. package/dist/modules/crons.d.ts +72 -0
  39. package/dist/modules/crons.d.ts.map +1 -0
  40. package/dist/modules/crons.js +66 -0
  41. package/dist/modules/dlq.d.ts +60 -0
  42. package/dist/modules/dlq.d.ts.map +1 -0
  43. package/dist/modules/dlq.js +56 -0
  44. package/dist/modules/evaluation.d.ts +119 -0
  45. package/dist/modules/evaluation.d.ts.map +1 -0
  46. package/dist/modules/evaluation.js +96 -0
  47. package/dist/modules/files.d.ts +68 -0
  48. package/dist/modules/files.d.ts.map +1 -0
  49. package/dist/modules/files.js +66 -0
  50. package/dist/modules/graphs.d.ts +51 -0
  51. package/dist/modules/graphs.d.ts.map +1 -0
  52. package/dist/modules/graphs.js +29 -0
  53. package/dist/modules/info.d.ts +27 -0
  54. package/dist/modules/info.d.ts.map +1 -0
  55. package/dist/modules/info.js +27 -0
  56. package/dist/modules/knowledge.d.ts +91 -0
  57. package/dist/modules/knowledge.d.ts.map +1 -0
  58. package/dist/modules/knowledge.js +80 -0
  59. package/dist/modules/mcp.d.ts +39 -0
  60. package/dist/modules/mcp.d.ts.map +1 -0
  61. package/dist/modules/mcp.js +38 -0
  62. package/dist/modules/me.d.ts +27 -0
  63. package/dist/modules/me.d.ts.map +1 -0
  64. package/dist/modules/me.js +19 -0
  65. package/dist/modules/members.d.ts +77 -0
  66. package/dist/modules/members.d.ts.map +1 -0
  67. package/dist/modules/members.js +77 -0
  68. package/dist/modules/metrics.d.ts +16 -0
  69. package/dist/modules/metrics.d.ts.map +1 -0
  70. package/dist/modules/metrics.js +24 -0
  71. package/dist/modules/playground.d.ts +42 -0
  72. package/dist/modules/playground.d.ts.map +1 -0
  73. package/dist/modules/playground.js +48 -0
  74. package/dist/modules/prompts.d.ts +87 -0
  75. package/dist/modules/prompts.d.ts.map +1 -0
  76. package/dist/modules/prompts.js +87 -0
  77. package/dist/modules/runs.d.ts +181 -0
  78. package/dist/modules/runs.d.ts.map +1 -0
  79. package/dist/modules/runs.js +187 -0
  80. package/dist/modules/store.d.ts +37 -0
  81. package/dist/modules/store.d.ts.map +1 -0
  82. package/dist/modules/store.js +48 -0
  83. package/dist/modules/tenants.d.ts +42 -0
  84. package/dist/modules/tenants.d.ts.map +1 -0
  85. package/dist/modules/tenants.js +45 -0
  86. package/dist/modules/threads.d.ts +181 -0
  87. package/dist/modules/threads.d.ts.map +1 -0
  88. package/dist/modules/threads.js +178 -0
  89. package/dist/modules/tools.d.ts +44 -0
  90. package/dist/modules/tools.d.ts.map +1 -0
  91. package/dist/modules/tools.js +39 -0
  92. package/dist/modules/traces.d.ts +79 -0
  93. package/dist/modules/traces.d.ts.map +1 -0
  94. package/dist/modules/traces.js +56 -0
  95. package/dist/modules/triggers.d.ts +71 -0
  96. package/dist/modules/triggers.d.ts.map +1 -0
  97. package/dist/modules/triggers.js +67 -0
  98. package/dist/modules/usage.d.ts +26 -0
  99. package/dist/modules/usage.d.ts.map +1 -0
  100. package/dist/modules/usage.js +19 -0
  101. package/dist/modules/vectorStores.d.ts +97 -0
  102. package/dist/modules/vectorStores.d.ts.map +1 -0
  103. package/dist/modules/vectorStores.js +87 -0
  104. package/dist/modules/workspaces.d.ts +52 -0
  105. package/dist/modules/workspaces.d.ts.map +1 -0
  106. package/dist/modules/workspaces.js +59 -0
  107. package/dist/sse/client.d.ts +62 -0
  108. package/dist/sse/client.d.ts.map +1 -0
  109. package/dist/sse/client.js +66 -0
  110. package/package.json +50 -0
  111. package/src/client/AgentOsClient.ts +269 -0
  112. package/src/client/helpers.ts +98 -0
  113. package/src/client/raw.ts +241 -0
  114. package/src/generated/index.ts +2 -0
  115. package/src/generated/openapi.ts +6810 -0
  116. package/src/generated/swagger.json +8549 -0
  117. package/src/index.ts +161 -0
  118. package/src/modules/a2a.ts +64 -0
  119. package/src/modules/agents.ts +229 -0
  120. package/src/modules/audit.ts +74 -0
  121. package/src/modules/builder.ts +166 -0
  122. package/src/modules/checkpoints.ts +78 -0
  123. package/src/modules/credentials.ts +144 -0
  124. package/src/modules/crons.ts +114 -0
  125. package/src/modules/dlq.ts +93 -0
  126. package/src/modules/evaluation.ts +189 -0
  127. package/src/modules/files.ts +112 -0
  128. package/src/modules/graphs.ts +50 -0
  129. package/src/modules/info.ts +35 -0
  130. package/src/modules/knowledge.ts +147 -0
  131. package/src/modules/mcp.ts +59 -0
  132. package/src/modules/me.ts +32 -0
  133. package/src/modules/members.ts +117 -0
  134. package/src/modules/metrics.ts +27 -0
  135. package/src/modules/playground.ts +68 -0
  136. package/src/modules/prompts.ts +147 -0
  137. package/src/modules/runs.ts +277 -0
  138. package/src/modules/store.ts +65 -0
  139. package/src/modules/tenants.ts +67 -0
  140. package/src/modules/threads.ts +287 -0
  141. package/src/modules/tools.ts +65 -0
  142. package/src/modules/traces.ts +117 -0
  143. package/src/modules/triggers.ts +113 -0
  144. package/src/modules/usage.ts +32 -0
  145. package/src/modules/vectorStores.ts +160 -0
  146. package/src/modules/workspaces.ts +89 -0
  147. package/src/sse/client.ts +100 -0
package/src/index.ts ADDED
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Agent OS SDK - Fully Typed
3
+ *
4
+ * Internal typed SDK for Agent OS platform.
5
+ * All API calls are fully typed from OpenAPI specification.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { AgentOsClient, unwrap } from "@agent-os/sdk";
10
+ *
11
+ * const api = new AgentOsClient({
12
+ * baseUrl: import.meta.env.VITE_API_URL,
13
+ * tenantId: auth.tenantId,
14
+ * workspaceId: auth.workspaceId,
15
+ * token: auth.token,
16
+ * });
17
+ *
18
+ * // Style 1: Handle response manually
19
+ * const { data, error } = await api.agents.list();
20
+ * if (data) {
21
+ * data.items.forEach(agent => console.log(agent.name));
22
+ * }
23
+ *
24
+ * // Style 2: Unwrap (throws on error, returns data directly)
25
+ * const agents = await unwrap(api.agents.list());
26
+ * agents.items.forEach(agent => console.log(agent.name));
27
+ *
28
+ * // Streaming
29
+ * for await (const event of api.runs.createAndStream({
30
+ * agent_id: "...",
31
+ * input: { message: "Hello" },
32
+ * })) {
33
+ * console.log(event);
34
+ * }
35
+ * ```
36
+ */
37
+
38
+ // ============================================================================
39
+ // Main Client
40
+ // ============================================================================
41
+ export { AgentOsClient, type AgentOsClientOptions } from "./client/AgentOsClient.js";
42
+
43
+ // ============================================================================
44
+ // Helpers & Utilities
45
+ // ============================================================================
46
+ export {
47
+ unwrap,
48
+ toResult,
49
+ SDKError,
50
+ type PaginationParams,
51
+ type PaginatedResponse,
52
+ type Result,
53
+ type Unwrapped,
54
+ } from "./client/helpers.js";
55
+
56
+ // ============================================================================
57
+ // Raw Client & Core Types
58
+ // ============================================================================
59
+ export {
60
+ createRawClient,
61
+ createTypedClient,
62
+ type RawClient,
63
+ type TypedClient,
64
+ type ClientOptions,
65
+ type APIResponse,
66
+ } from "./client/raw.js";
67
+
68
+ // Export OpenAPI types
69
+ export type { paths, components } from "./client/raw.js";
70
+
71
+ // ============================================================================
72
+ // Module Classes
73
+ // ============================================================================
74
+
75
+ // Core modules
76
+ export { AgentsModule, type Agent, type AgentVersion, type AgentListResponse, type AgentGraphResponse } from "./modules/agents.js";
77
+ export { RunsModule, type Run, type RunEvent, type RunListResponse, type RunEventsResponse, type CreateRunResponse } from "./modules/runs.js";
78
+ export { ThreadsModule, type Thread, type ThreadState, type ThreadMessage, type ThreadRun, type ThreadListResponse, type ThreadMessagesResponse } from "./modules/threads.js";
79
+ export { ToolsModule, type Tool, type ToolListResponse } from "./modules/tools.js";
80
+ export { KnowledgeModule, type KnowledgeDataset, type KnowledgeSearchResponse } from "./modules/knowledge.js";
81
+ export { TriggersModule, type Trigger, type TriggerListResponse } from "./modules/triggers.js";
82
+ export { CredentialsModule, type Credential, type CredentialListResponse, type CredentialType } from "./modules/credentials.js";
83
+ export { BuilderModule, type BuilderChatRequest, type BuilderChatResponse, type BuilderStreamEvent, type GraphUpdateAction } from "./modules/builder.js";
84
+ export { MembersModule, type Member, type MemberListResponse } from "./modules/members.js";
85
+ export { TenantsModule, type Tenant } from "./modules/tenants.js";
86
+ export { WorkspacesModule, type Workspace, type WorkspaceListResponse } from "./modules/workspaces.js";
87
+
88
+ // Platform modules
89
+ export { PromptsModule, type Prompt, type PromptVersion, type PromptListResponse } from "./modules/prompts.js";
90
+ export { TracesModule, type Trace, type Span, type TraceListResponse, type SpanData, type FeedbackRequest } from "./modules/traces.js";
91
+ export { FilesModule, type StoredFile, type FileListResponse, type PresignedUpload } from "./modules/files.js";
92
+ export { VectorStoresModule, type VectorStore, type VectorStoreListResponse, type VectorQueryResult } from "./modules/vectorStores.js";
93
+ export { EvaluationModule, type EvalDataset, type Experiment, type ExampleData } from "./modules/evaluation.js";
94
+ export { CheckpointsModule, type Checkpoint, type CheckpointsResponse } from "./modules/checkpoints.js";
95
+ export { PlaygroundModule, type PlaygroundSession } from "./modules/playground.js";
96
+ export { CronsModule, type CronJob, type CronJobListResponse } from "./modules/crons.js";
97
+ export { DlqModule, type DlqMessage, type DlqListResponse } from "./modules/dlq.js";
98
+ export { StoreModule, type StoreValue } from "./modules/store.js";
99
+ export { AuditModule, type AuditLogEntry, type AuditListResponse } from "./modules/audit.js";
100
+ export { UsageModule, type UsageResponse, type UsageQuota } from "./modules/usage.js";
101
+ export { McpModule, type McpServer } from "./modules/mcp.js";
102
+ export { A2aModule, type JsonRpcRequest, type JsonRpcResponse, type A2aAgentCard } from "./modules/a2a.js";
103
+ export { MeModule, type MeResponse } from "./modules/me.js";
104
+ export { InfoModule, type ServerInfo } from "./modules/info.js";
105
+ export { MetricsModule, type MetricsResponse } from "./modules/metrics.js";
106
+ export { GraphsModule, type GraphValidationResult, type GraphIntrospectionResult } from "./modules/graphs.js";
107
+
108
+ // ============================================================================
109
+ // SSE Streaming
110
+ // ============================================================================
111
+ export { streamSSE, type SSEEvent, type SSEOptions, type RunStreamEvent } from "./sse/client.js";
112
+
113
+ // ============================================================================
114
+ // Convenience Type Re-exports
115
+ // ============================================================================
116
+ export type {
117
+ // Agent types
118
+ Agent as AgentSchema,
119
+ CreateAgentRequest,
120
+ UpdateAgentRequest,
121
+ AgentBundle,
122
+ CreateAgentVersionRequest,
123
+ // Run types
124
+ RunResponse,
125
+ RunDetailResponse,
126
+ WaitRunResponse,
127
+ BatchRunResponse,
128
+ CancelRunResponse,
129
+ ReplayRequest,
130
+ // Thread types
131
+ ThreadRequest,
132
+ ThreadSearchRequest,
133
+ AddMessageRequest,
134
+ // Checkpoint types
135
+ CheckpointDetail,
136
+ CheckpointListResponse,
137
+ // Credential types
138
+ CreateCredentialRequest,
139
+ UpdateCredentialRequest,
140
+ // Cron types
141
+ CreateCronJobRequest,
142
+ UpdateCronJobRequest,
143
+ // Member types
144
+ InviteMemberRequest,
145
+ UpdateMemberRequest,
146
+ // Prompt types
147
+ CreatePromptRequest,
148
+ CreatePromptVersionRequest,
149
+ // File types
150
+ CreatePresignedUploadRequest,
151
+ PresignedUploadResponse,
152
+ // Vector Store types
153
+ VectorStoreResponse,
154
+ VectorQueryRequest,
155
+ VectorQueryResponse,
156
+ // Evaluation types
157
+ CreateDatasetRequest,
158
+ CreateExperimentRequest,
159
+ // Error types
160
+ ProblemDetails,
161
+ } from "./client/raw.js";
@@ -0,0 +1,64 @@
1
+ /**
2
+ * A2A Module - Fully Typed (Agent-to-Agent Protocol)
3
+ */
4
+
5
+ import type { RawClient, APIResponse } from "../client/raw.js";
6
+
7
+ export interface JsonRpcRequest {
8
+ jsonrpc: "2.0";
9
+ method: string;
10
+ params?: unknown;
11
+ id?: string | number;
12
+ }
13
+
14
+ export interface JsonRpcResponse {
15
+ jsonrpc: "2.0";
16
+ result?: unknown;
17
+ error?: {
18
+ code: number;
19
+ message: string;
20
+ data?: unknown;
21
+ };
22
+ id?: string | number;
23
+ }
24
+
25
+ export interface A2aAgentCard {
26
+ agent_id: string;
27
+ name: string;
28
+ description?: string;
29
+ capabilities?: string[];
30
+ endpoint: string;
31
+ }
32
+
33
+ export class A2aModule {
34
+ constructor(private client: RawClient, private headers: () => Record<string, string>) { }
35
+
36
+ /**
37
+ * Send a JSON-RPC request to an agent.
38
+ */
39
+ async call(request: JsonRpcRequest): Promise<APIResponse<JsonRpcResponse>> {
40
+ return this.client.POST<JsonRpcResponse>("/v1/api/a2a", {
41
+ body: request,
42
+ headers: this.headers(),
43
+ });
44
+ }
45
+
46
+ /**
47
+ * Get agent card (discovery).
48
+ */
49
+ async getAgentCard(agentId: string): Promise<APIResponse<A2aAgentCard>> {
50
+ return this.client.GET<A2aAgentCard>("/v1/api/a2a/agents/{id}/card", {
51
+ params: { path: { id: agentId } },
52
+ headers: this.headers(),
53
+ });
54
+ }
55
+
56
+ /**
57
+ * List available A2A agents.
58
+ */
59
+ async listAgents(): Promise<APIResponse<{ items: A2aAgentCard[]; total: number }>> {
60
+ return this.client.GET<{ items: A2aAgentCard[]; total: number }>("/v1/api/a2a/agents", {
61
+ headers: this.headers(),
62
+ });
63
+ }
64
+ }
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Agents Module - Fully Typed
3
+ *
4
+ * Naming conventions:
5
+ * - get* for singular items: getAgent(id)
6
+ * - list* for collections: listAgents()
7
+ * - create*, update*, delete* for mutations
8
+ */
9
+
10
+ import type { RawClient, APIResponse, components } from "../client/raw.js";
11
+ import type { PaginationParams, PaginatedResponse } from "../client/helpers.js";
12
+
13
+ // Type aliases for this module
14
+ type AgentSchema = components["schemas"]["AgentBundleAgent"];
15
+ type AgentBundle = components["schemas"]["AgentBundle"];
16
+ type AgentVersionSchema = components["schemas"]["AgentBundleVersion"];
17
+
18
+ // Response types
19
+ export interface Agent {
20
+ id: string;
21
+ name: string;
22
+ description?: string;
23
+ workspace_id: string;
24
+ tenant_id: string;
25
+ created_at: string;
26
+ updated_at: string;
27
+ live_version_id?: string | null;
28
+ }
29
+
30
+ export interface AgentVersion {
31
+ id: string;
32
+ agent_id: string;
33
+ version_tag: string;
34
+ artifact_uri?: string;
35
+ artifact_hash?: string;
36
+ format?: string;
37
+ graph_spec?: unknown;
38
+ created_at: string;
39
+ }
40
+
41
+ export interface AgentGraphResponse {
42
+ mermaid?: string;
43
+ json?: unknown;
44
+ }
45
+
46
+ export interface GraphValidationResponse {
47
+ valid: boolean;
48
+ errors?: string[];
49
+ warnings?: string[];
50
+ }
51
+
52
+ export type AgentListResponse = PaginatedResponse<Agent>;
53
+ export type AgentVersionListResponse = PaginatedResponse<AgentVersion>;
54
+
55
+ export class AgentsModule {
56
+ constructor(private client: RawClient, private headers: () => Record<string, string>) { }
57
+
58
+ // ======================== CRUD ========================
59
+
60
+ /**
61
+ * List all agents in the workspace.
62
+ * @example
63
+ * ```ts
64
+ * const { data } = await client.agents.list({ limit: 10 });
65
+ * data?.items.forEach(agent => console.log(agent.name));
66
+ * ```
67
+ */
68
+ async list(params?: PaginationParams & {
69
+ workspace_id?: string;
70
+ }): Promise<APIResponse<AgentListResponse>> {
71
+ return this.client.GET<AgentListResponse>("/v1/api/agents", {
72
+ params: { query: params },
73
+ headers: this.headers(),
74
+ });
75
+ }
76
+
77
+ /**
78
+ * Get a single agent by ID.
79
+ * @example
80
+ * ```ts
81
+ * const { data: agent } = await client.agents.get("agent-uuid");
82
+ * ```
83
+ */
84
+ async get(agentId: string): Promise<APIResponse<Agent>> {
85
+ return this.client.GET<Agent>("/v1/api/agents/{agentId}", {
86
+ params: { path: { agentId } },
87
+ headers: this.headers(),
88
+ });
89
+ }
90
+
91
+ /**
92
+ * Create a new agent.
93
+ * @example
94
+ * ```ts
95
+ * const { data: agent } = await client.agents.create({
96
+ * name: "My Agent",
97
+ * description: "Does cool stuff"
98
+ * });
99
+ * ```
100
+ */
101
+ async create(body: {
102
+ name: string;
103
+ description?: string;
104
+ graph_json?: unknown;
105
+ }): Promise<APIResponse<Agent>> {
106
+ return this.client.POST<Agent>("/v1/api/agents", {
107
+ body,
108
+ headers: this.headers(),
109
+ });
110
+ }
111
+
112
+ /**
113
+ * Update an existing agent.
114
+ */
115
+ async update(agentId: string, body: {
116
+ name?: string;
117
+ description?: string;
118
+ live_version_id?: string;
119
+ }): Promise<APIResponse<Agent>> {
120
+ return this.client.PUT<Agent>("/v1/api/agents/{agentId}", {
121
+ params: { path: { agentId } },
122
+ body,
123
+ headers: this.headers(),
124
+ });
125
+ }
126
+
127
+ /**
128
+ * Delete an agent.
129
+ */
130
+ async delete(agentId: string): Promise<APIResponse<void>> {
131
+ return this.client.DELETE<void>("/v1/api/agents/{agentId}", {
132
+ params: { path: { agentId } },
133
+ headers: this.headers(),
134
+ });
135
+ }
136
+
137
+ // ======================== Versions ========================
138
+
139
+ /**
140
+ * List all versions of an agent.
141
+ * @example
142
+ * ```ts
143
+ * const { data } = await client.agents.listVersions("agent-uuid");
144
+ * ```
145
+ */
146
+ async listVersions(agentId: string): Promise<APIResponse<AgentVersion[]>> {
147
+ return this.client.GET<AgentVersion[]>("/v1/api/agents/{agentId}/versions", {
148
+ params: { path: { agentId } },
149
+ headers: this.headers(),
150
+ });
151
+ }
152
+
153
+ /** Alias for listVersions (convenience) */
154
+ versions = (agentId: string) => this.listVersions(agentId);
155
+
156
+ /**
157
+ * Create a new version of an agent.
158
+ */
159
+ async createVersion(agentId: string, body: {
160
+ version_tag: string;
161
+ artifact_uri?: string;
162
+ artifact_hash?: string;
163
+ format?: string;
164
+ graph_spec?: unknown;
165
+ }): Promise<APIResponse<AgentVersion>> {
166
+ return this.client.POST<AgentVersion>("/v1/api/agents/{agentId}/versions", {
167
+ params: { path: { agentId } },
168
+ body,
169
+ headers: this.headers(),
170
+ });
171
+ }
172
+
173
+ /**
174
+ * Get a specific version of an agent.
175
+ */
176
+ async getVersion(agentId: string, versionId: string): Promise<APIResponse<AgentVersion>> {
177
+ return this.client.GET<AgentVersion>("/v1/api/agents/{agentId}/versions/{versionId}", {
178
+ params: { path: { agentId, versionId } },
179
+ headers: this.headers(),
180
+ });
181
+ }
182
+
183
+ // ======================== Graph ========================
184
+
185
+ /**
186
+ * Get the graph for an agent (Mermaid or JSON).
187
+ */
188
+ async getGraph(agentId: string, format?: "mermaid" | "json"): Promise<APIResponse<AgentGraphResponse>> {
189
+ return this.client.GET<AgentGraphResponse>("/v1/api/agents/{agentId}/graph", {
190
+ params: { path: { agentId }, query: { format } },
191
+ headers: this.headers(),
192
+ });
193
+ }
194
+
195
+ /** Alias for getGraph (convenience) */
196
+ graph = (agentId: string, format?: "mermaid" | "json") => this.getGraph(agentId, format);
197
+
198
+ /**
199
+ * Validate the graph configuration.
200
+ */
201
+ async validateGraph(agentId: string): Promise<APIResponse<GraphValidationResponse>> {
202
+ return this.client.POST<GraphValidationResponse>("/v1/api/agents/{agentId}/graph/validate", {
203
+ params: { path: { agentId } },
204
+ headers: this.headers(),
205
+ });
206
+ }
207
+
208
+ // ======================== Import/Export ========================
209
+
210
+ /**
211
+ * Export an agent with all its versions.
212
+ */
213
+ async export(agentId: string): Promise<APIResponse<AgentBundle>> {
214
+ return this.client.GET<AgentBundle>("/v1/api/agents/{id}/export", {
215
+ params: { path: { id: agentId } },
216
+ headers: this.headers(),
217
+ });
218
+ }
219
+
220
+ /**
221
+ * Import an agent bundle.
222
+ */
223
+ async import(bundle: AgentBundle): Promise<APIResponse<Agent>> {
224
+ return this.client.POST<Agent>("/v1/api/agents/import", {
225
+ body: bundle,
226
+ headers: this.headers(),
227
+ });
228
+ }
229
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Audit Module - Fully Typed
3
+ */
4
+
5
+ import type { RawClient, APIResponse } from "../client/raw.js";
6
+
7
+ export interface AuditLogEntry {
8
+ id: string;
9
+ tenant_id: string;
10
+ workspace_id?: string;
11
+ actor: string;
12
+ actor_type: "user" | "system" | "api_token";
13
+ action: string;
14
+ resource: string;
15
+ resource_id?: string;
16
+ metadata?: Record<string, unknown>;
17
+ ip_address?: string;
18
+ user_agent?: string;
19
+ created_at: string;
20
+ }
21
+
22
+ export interface AuditListResponse {
23
+ items: AuditLogEntry[];
24
+ total: number;
25
+ }
26
+
27
+ export class AuditModule {
28
+ constructor(private client: RawClient, private headers: () => Record<string, string>) { }
29
+
30
+ /**
31
+ * List audit log entries.
32
+ */
33
+ async list(params?: {
34
+ actor?: string;
35
+ action?: string;
36
+ resource?: string;
37
+ workspace_id?: string;
38
+ from?: string;
39
+ to?: string;
40
+ skip?: number;
41
+ take?: number;
42
+ }): Promise<APIResponse<AuditListResponse>> {
43
+ return this.client.GET<AuditListResponse>("/v1/api/audit", {
44
+ params: { query: params },
45
+ headers: this.headers(),
46
+ });
47
+ }
48
+
49
+ /**
50
+ * Get a specific audit log entry.
51
+ */
52
+ async get(auditId: string): Promise<APIResponse<AuditLogEntry>> {
53
+ return this.client.GET<AuditLogEntry>("/v1/api/audit/{id}", {
54
+ params: { path: { id: auditId } },
55
+ headers: this.headers(),
56
+ });
57
+ }
58
+
59
+ /**
60
+ * Search audit logs by action pattern.
61
+ */
62
+ async search(params?: {
63
+ query?: string;
64
+ from?: string;
65
+ to?: string;
66
+ skip?: number;
67
+ take?: number;
68
+ }): Promise<APIResponse<AuditListResponse>> {
69
+ return this.client.GET<AuditListResponse>("/v1/api/audit/search", {
70
+ params: { query: params },
71
+ headers: this.headers(),
72
+ });
73
+ }
74
+ }
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Builder Module - Meta-Agent for Agent Building
3
+ *
4
+ * Connects to the kernel's meta-agent for AI-assisted agent creation.
5
+ * Uses SSE streaming for real-time responses and graph updates.
6
+ */
7
+
8
+ import { streamSSE, type SSEEvent, type SSEOptions } from "../sse/client.js";
9
+
10
+ export type BuilderChatRequest = {
11
+ message: string;
12
+ current_graph_spec?: Record<string, unknown>;
13
+ thread_id?: string;
14
+ };
15
+
16
+ export type GraphUpdateAction = {
17
+ action: string;
18
+ node_name?: string;
19
+ node_type?: string;
20
+ properties?: Record<string, unknown>;
21
+ edge_from?: string;
22
+ edge_to?: string;
23
+ };
24
+
25
+ export type BuilderStreamEvent =
26
+ | { type: "message"; data: { text: string } }
27
+ | { type: "graph_update"; data: GraphUpdateAction }
28
+ | { type: "done"; data: { response: string; actions: GraphUpdateAction[]; thread_id: string } }
29
+ | { type: "error"; data: { error: string } };
30
+
31
+ export type BuilderChatResponse = {
32
+ response: string;
33
+ actions: GraphUpdateAction[];
34
+ thread_id: string;
35
+ };
36
+
37
+ export class BuilderModule {
38
+ constructor(
39
+ private kernelBaseUrl: string,
40
+ private headers: () => Record<string, string>
41
+ ) { }
42
+
43
+ /**
44
+ * Stream chat with meta-agent (SSE).
45
+ * Returns async generator of events.
46
+ */
47
+ async *chat(
48
+ agentId: string,
49
+ request: BuilderChatRequest,
50
+ options?: SSEOptions
51
+ ): AsyncGenerator<BuilderStreamEvent> {
52
+ const url = `${this.kernelBaseUrl}/v1/internal/builder/${agentId}/chat`;
53
+
54
+ const response = await fetch(url, {
55
+ method: "POST",
56
+ headers: {
57
+ "Content-Type": "application/json",
58
+ Accept: "text/event-stream",
59
+ ...this.headers(),
60
+ },
61
+ body: JSON.stringify(request),
62
+ signal: options?.signal,
63
+ });
64
+
65
+ if (!response.ok) {
66
+ throw new Error(`Builder chat failed: ${response.status}`);
67
+ }
68
+
69
+ if (!response.body) {
70
+ throw new Error("No response body");
71
+ }
72
+
73
+ options?.onOpen?.();
74
+
75
+ const reader = response.body.getReader();
76
+ const decoder = new TextDecoder();
77
+ let buffer = "";
78
+
79
+ try {
80
+ while (true) {
81
+ const { done, value } = await reader.read();
82
+ if (done) break;
83
+
84
+ buffer += decoder.decode(value, { stream: true });
85
+ const lines = buffer.split("\n");
86
+ buffer = lines.pop() ?? "";
87
+
88
+ let eventType = "message";
89
+ let eventData = "";
90
+
91
+ for (const line of lines) {
92
+ if (line.startsWith("event:")) {
93
+ eventType = line.slice(6).trim();
94
+ } else if (line.startsWith("data:")) {
95
+ eventData = line.slice(5).trim();
96
+ } else if (line === "" && eventData) {
97
+ try {
98
+ const parsed = JSON.parse(eventData);
99
+ yield { type: eventType, data: parsed } as BuilderStreamEvent;
100
+ } catch {
101
+ // Skip invalid JSON
102
+ }
103
+ eventData = "";
104
+ eventType = "message";
105
+ }
106
+ }
107
+ }
108
+ } finally {
109
+ reader.releaseLock();
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Sync chat with meta-agent (no streaming).
115
+ */
116
+ async chatSync(
117
+ agentId: string,
118
+ request: BuilderChatRequest
119
+ ): Promise<BuilderChatResponse> {
120
+ const url = `${this.kernelBaseUrl}/v1/internal/builder/${agentId}/chat/sync`;
121
+
122
+ const response = await fetch(url, {
123
+ method: "POST",
124
+ headers: {
125
+ "Content-Type": "application/json",
126
+ ...this.headers(),
127
+ },
128
+ body: JSON.stringify(request),
129
+ });
130
+
131
+ if (!response.ok) {
132
+ const error = await response.text();
133
+ throw new Error(`Builder chat failed: ${response.status} - ${error}`);
134
+ }
135
+
136
+ return response.json();
137
+ }
138
+
139
+ /**
140
+ * Convenience method: chat and collect all events.
141
+ */
142
+ async chatCollect(
143
+ agentId: string,
144
+ request: BuilderChatRequest
145
+ ): Promise<BuilderChatResponse> {
146
+ let fullResponse = "";
147
+ const allActions: GraphUpdateAction[] = [];
148
+ let threadId = request.thread_id ?? "";
149
+
150
+ for await (const event of this.chat(agentId, request)) {
151
+ if (event.type === "message") {
152
+ fullResponse += event.data.text;
153
+ } else if (event.type === "graph_update") {
154
+ allActions.push(event.data);
155
+ } else if (event.type === "done") {
156
+ threadId = event.data.thread_id;
157
+ }
158
+ }
159
+
160
+ return {
161
+ response: fullResponse,
162
+ actions: allActions,
163
+ thread_id: threadId,
164
+ };
165
+ }
166
+ }