codemie-sdk 0.1.64

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/index.cjs ADDED
@@ -0,0 +1,1357 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ ApiError: () => ApiError,
34
+ AssistantChatParamsSchema: () => AssistantChatParamsSchema,
35
+ AssistantCreateParamsSchema: () => AssistantCreateParamsSchema,
36
+ AssistantListParamsSchema: () => AssistantListParamsSchema,
37
+ AssistantUpdateParamsSchema: () => AssistantUpdateParamsSchema,
38
+ BackgroundTaskStatus: () => BackgroundTaskStatus,
39
+ ChatRole: () => ChatRole,
40
+ CodeDataSourceType: () => CodeDataSourceType,
41
+ CodeMieClient: () => CodeMieClient,
42
+ CodeMieError: () => CodeMieError,
43
+ ContextType: () => ContextType,
44
+ CredentialTypes: () => CredentialTypes,
45
+ DataSourceStatus: () => DataSourceStatus,
46
+ DataSourceType: () => DataSourceType,
47
+ ExecutionStatus: () => ExecutionStatus,
48
+ IntegrationCreateParamsSchema: () => IntegrationCreateParamsSchema,
49
+ IntegrationGetByAliasParamsSchema: () => IntegrationGetByAliasParamsSchema,
50
+ IntegrationGetParamsSchema: () => IntegrationGetParamsSchema,
51
+ IntegrationListParamsSchema: () => IntegrationListParamsSchema,
52
+ IntegrationType: () => IntegrationType,
53
+ IntegrationUpdateParamsSchema: () => IntegrationUpdateParamsSchema,
54
+ LLMProvider: () => LLMProvider,
55
+ NotFoundError: () => NotFoundError,
56
+ WorkflowCreateParamsSchema: () => WorkflowCreateParamsSchema,
57
+ WorkflowExecutionCreateParamsSchema: () => WorkflowExecutionCreateParamsSchema,
58
+ WorkflowExecutionListParamsSchema: () => WorkflowExecutionListParamsSchema,
59
+ WorkflowExecutionStateListParamsSchema: () => WorkflowExecutionStateListParamsSchema,
60
+ WorkflowListParamsSchema: () => WorkflowListParamsSchema,
61
+ WorkflowMode: () => WorkflowMode,
62
+ WorkflowUpdateParamsSchema: () => WorkflowUpdateParamsSchema
63
+ });
64
+ module.exports = __toCommonJS(index_exports);
65
+
66
+ // src/auth/credentials.ts
67
+ var import_node_https = require("https");
68
+ var import_axios = __toESM(require("axios"), 1);
69
+ var DEFAULT_CLIENT_ID = "codemie-sdk";
70
+ var KeycloakCredentials = class {
71
+ constructor(config) {
72
+ this.validateConfigCredentials(config);
73
+ this.config = config;
74
+ this.httpAgent = new import_node_https.Agent({
75
+ rejectUnauthorized: config.verifySSL
76
+ });
77
+ }
78
+ async getToken() {
79
+ const { serverUrl, realmName } = this.config;
80
+ const url = `${serverUrl}/realms/${realmName}/protocol/openid-connect/token`;
81
+ const payload = this.config.username && this.config.password ? this.createResourceOwnerCredentialsPayload() : this.createClientCredentialsPayload();
82
+ const { data } = await import_axios.default.post(url, this.createSearchParams(payload), {
83
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
84
+ httpsAgent: this.httpAgent
85
+ });
86
+ return data.access_token;
87
+ }
88
+ createResourceOwnerCredentialsPayload() {
89
+ const { username, password, clientId } = this.config;
90
+ return {
91
+ grant_type: "password",
92
+ username,
93
+ password,
94
+ client_id: clientId || DEFAULT_CLIENT_ID
95
+ };
96
+ }
97
+ createClientCredentialsPayload() {
98
+ const { clientId, clientSecret } = this.config;
99
+ return {
100
+ grant_type: "client_credentials",
101
+ client_id: clientId || DEFAULT_CLIENT_ID,
102
+ client_secret: clientSecret
103
+ };
104
+ }
105
+ createSearchParams(payload) {
106
+ return new URLSearchParams(
107
+ Object.fromEntries(Object.entries(payload).filter(([_, v]) => v !== void 0))
108
+ );
109
+ }
110
+ validateConfigCredentials(config) {
111
+ if (!(config.clientId && config.clientSecret || config.username && config.password)) {
112
+ throw new Error(
113
+ "Either client credentials (clientId, clientSecret) or user credentials (username, password) must be provided"
114
+ );
115
+ }
116
+ }
117
+ };
118
+
119
+ // src/utils/helpers.ts
120
+ function omitUndefined(obj) {
121
+ return Object.fromEntries(Object.entries(obj).filter(([_, value]) => value !== void 0));
122
+ }
123
+
124
+ // src/mappers/assistant.mapper.ts
125
+ var AssistantMapper = class {
126
+ static mapBaseModelApiResponse(response) {
127
+ return omitUndefined({
128
+ generated: response.generated,
129
+ time_elapsed: response.timeElapsed,
130
+ tokens_used: response.tokensUsed,
131
+ thoughts: response.thoughts,
132
+ task_id: response.taskId
133
+ });
134
+ }
135
+ };
136
+
137
+ // src/schemas/assistant.ts
138
+ var import_zod = require("zod");
139
+ var AssistantListParamsSchema = import_zod.z.object({
140
+ minimal_response: import_zod.z.boolean().default(true),
141
+ scope: import_zod.z.enum(["visible_to_user", "created_by_user"]).default("visible_to_user"),
142
+ page: import_zod.z.number().default(0),
143
+ per_page: import_zod.z.number().default(12),
144
+ filters: import_zod.z.record(import_zod.z.unknown()).optional()
145
+ }).readonly();
146
+ var AssistantCreateParamsSchema = import_zod.z.object({
147
+ name: import_zod.z.string(),
148
+ description: import_zod.z.string(),
149
+ icon_url: import_zod.z.string().optional(),
150
+ system_prompt: import_zod.z.string(),
151
+ project: import_zod.z.string(),
152
+ context: import_zod.z.array(
153
+ import_zod.z.object({
154
+ context_type: import_zod.z.enum(["knowledge_base", "code"]),
155
+ name: import_zod.z.string()
156
+ })
157
+ ),
158
+ llm_model_type: import_zod.z.string(),
159
+ toolkits: import_zod.z.array(
160
+ import_zod.z.object({
161
+ toolkit: import_zod.z.string(),
162
+ tools: import_zod.z.array(
163
+ import_zod.z.object({
164
+ name: import_zod.z.string(),
165
+ label: import_zod.z.string().optional(),
166
+ settings_config: import_zod.z.boolean(),
167
+ user_description: import_zod.z.string().optional(),
168
+ settings: import_zod.z.any().nullable().optional()
169
+ })
170
+ ),
171
+ label: import_zod.z.string(),
172
+ settings_config: import_zod.z.boolean(),
173
+ is_external: import_zod.z.boolean(),
174
+ settings: import_zod.z.any().optional()
175
+ })
176
+ ),
177
+ user_prompts: import_zod.z.array(import_zod.z.string()),
178
+ shared: import_zod.z.boolean().optional(),
179
+ is_react: import_zod.z.boolean().optional(),
180
+ is_global: import_zod.z.boolean().optional(),
181
+ slug: import_zod.z.string().optional(),
182
+ temperature: import_zod.z.number().optional(),
183
+ top_p: import_zod.z.number().optional(),
184
+ mcp_servers: import_zod.z.array(
185
+ import_zod.z.object({
186
+ name: import_zod.z.string(),
187
+ description: import_zod.z.string().optional(),
188
+ enabled: import_zod.z.boolean(),
189
+ config: import_zod.z.object({
190
+ command: import_zod.z.string(),
191
+ args: import_zod.z.array(import_zod.z.string()).optional(),
192
+ env: import_zod.z.record(import_zod.z.unknown()).optional(),
193
+ auth_token: import_zod.z.string().optional()
194
+ }).optional(),
195
+ mcp_connect_url: import_zod.z.string().optional(),
196
+ tools_tokens_size_limit: import_zod.z.number().optional(),
197
+ command: import_zod.z.string().optional(),
198
+ arguments: import_zod.z.string().optional(),
199
+ settings: import_zod.z.any().optional(),
200
+ mcp_connect_auth_token: import_zod.z.any().optional()
201
+ })
202
+ ),
203
+ assistant_ids: import_zod.z.array(import_zod.z.string())
204
+ }).readonly();
205
+ var AssistantUpdateParamsSchema = AssistantCreateParamsSchema;
206
+ var AssistantChatParamsSchema = import_zod.z.object({
207
+ conversation_id: import_zod.z.string().optional(),
208
+ text: import_zod.z.string(),
209
+ content_raw: import_zod.z.string().optional(),
210
+ file_name: import_zod.z.string().optional(),
211
+ llm_model: import_zod.z.string().optional(),
212
+ history: import_zod.z.union([
213
+ import_zod.z.array(
214
+ import_zod.z.object({
215
+ role: import_zod.z.enum(["Assistant", "User"]),
216
+ message: import_zod.z.string().optional()
217
+ })
218
+ ),
219
+ import_zod.z.string()
220
+ ]),
221
+ history_index: import_zod.z.number().optional(),
222
+ stream: import_zod.z.boolean().optional(),
223
+ top_k: import_zod.z.number().optional(),
224
+ system_prompt: import_zod.z.string().optional(),
225
+ background_task: import_zod.z.boolean().optional(),
226
+ metadata: import_zod.z.record(import_zod.z.unknown()).optional()
227
+ }).readonly();
228
+
229
+ // src/utils/http.ts
230
+ var import_node_https2 = require("https");
231
+ var import_axios2 = __toESM(require("axios"), 1);
232
+
233
+ // src/exceptions/exceptions.ts
234
+ var CodeMieError = class extends Error {
235
+ constructor(message) {
236
+ super(message);
237
+ this.name = "CodeMieError";
238
+ }
239
+ };
240
+ var ApiError = class extends CodeMieError {
241
+ constructor(message, statusCode, response) {
242
+ super(message);
243
+ this.name = "ApiError";
244
+ this.statusCode = statusCode;
245
+ this.response = response;
246
+ }
247
+ };
248
+ var NotFoundError = class extends ApiError {
249
+ constructor(resourceType, resourceId) {
250
+ super(`${resourceType} with ${resourceId} not found`, 404);
251
+ this.name = "NotFoundError";
252
+ }
253
+ };
254
+
255
+ // src/utils/http.ts
256
+ var ApiRequestHandler = class {
257
+ constructor(apiDomain, token, verifySSL = true) {
258
+ this.client = import_axios2.default.create({
259
+ baseURL: apiDomain.replace(/\/$/, ""),
260
+ // Remove trailing slash
261
+ validateStatus: (status) => status < 400,
262
+ headers: {
263
+ Authorization: `Bearer ${token}`,
264
+ "Content-Type": "application/json"
265
+ },
266
+ httpsAgent: new import_node_https2.Agent({
267
+ rejectUnauthorized: verifySSL
268
+ })
269
+ });
270
+ this.client.interceptors.response.use(
271
+ (response) => response,
272
+ (error) => this.processFailedResponse(error)
273
+ );
274
+ }
275
+ async request(method, path, config = {}) {
276
+ const response = await this.client.request({
277
+ method,
278
+ url: path,
279
+ ...config
280
+ });
281
+ return response.data;
282
+ }
283
+ async get(path, params, config = {}) {
284
+ return this.request("get", path, { ...config, params });
285
+ }
286
+ async post(path, data, config = {}) {
287
+ return this.request("post", path, { ...config, data });
288
+ }
289
+ async postMultipart(url, formData, params) {
290
+ const response = await this.client.post(url, formData, {
291
+ headers: {
292
+ "Content-Type": "multipart/form-data"
293
+ },
294
+ params
295
+ });
296
+ return response.data;
297
+ }
298
+ async put(path, data, config = {}) {
299
+ return this.request("put", path, { ...config, data });
300
+ }
301
+ async delete(path, config = {}) {
302
+ return this.request("delete", path, config);
303
+ }
304
+ async stream(path, data, config = {}) {
305
+ return this.client.post(path, data, {
306
+ ...config,
307
+ responseType: "stream"
308
+ });
309
+ }
310
+ processFailedResponse(error) {
311
+ const response = error.response;
312
+ const status = response?.status || 500;
313
+ const data = response?.data || {};
314
+ if (status === 404) {
315
+ throw new NotFoundError("Resource", "unknown");
316
+ }
317
+ if (status === 422) {
318
+ const errorMessage2 = [
319
+ data.error?.message,
320
+ data.error?.help,
321
+ JSON.stringify(data.error?.details ?? {})
322
+ ].filter(Boolean).join(". ");
323
+ throw new ApiError(errorMessage2 || "Validation error", status, data);
324
+ }
325
+ const errorMessage = [data.error?.message, data.error?.detail, data.error?.help].filter(Boolean).join(". ");
326
+ throw new ApiError(errorMessage, status, data);
327
+ }
328
+ };
329
+
330
+ // src/services/assistant.ts
331
+ var AssistantService = class {
332
+ constructor(apiDomain, token, verifySSL = true) {
333
+ this.api = new ApiRequestHandler(apiDomain, token, verifySSL);
334
+ }
335
+ /**
336
+ * Get list of available assistants.
337
+ */
338
+ async list(_params = {}) {
339
+ const params = AssistantListParamsSchema.parse(_params);
340
+ const response = await this.api.get(
341
+ "/v1/assistants",
342
+ {
343
+ ...params,
344
+ ...params.filters && { filters: JSON.stringify(params.filters) }
345
+ }
346
+ );
347
+ return response.data;
348
+ }
349
+ /**
350
+ * Get assistant by ID.
351
+ */
352
+ async get(assistantId) {
353
+ return this.api.get(`/v1/assistants/id/${assistantId}`);
354
+ }
355
+ /**
356
+ * Get assistant by slug.
357
+ */
358
+ async getBySlug(slug) {
359
+ return this.api.get(`/v1/assistants/slug/${slug}`);
360
+ }
361
+ /**
362
+ * Create a new assistant.
363
+ */
364
+ async create(_params) {
365
+ const params = AssistantCreateParamsSchema.parse(_params);
366
+ return this.api.post("/v1/assistants", params);
367
+ }
368
+ /**
369
+ * Update an existing assistant.
370
+ */
371
+ async update(assistantId, _params) {
372
+ const params = AssistantUpdateParamsSchema.parse(_params);
373
+ return this.api.put(`/v1/assistants/${assistantId}`, params);
374
+ }
375
+ /**
376
+ * Get list of available tools.
377
+ */
378
+ async getTools() {
379
+ return this.api.get("/v1/assistants/tools");
380
+ }
381
+ /**
382
+ * Delete an assistant by ID.
383
+ */
384
+ async delete(assistantId) {
385
+ return this.api.delete(`/v1/assistants/${assistantId}`);
386
+ }
387
+ /**
388
+ * Get list of prebuilt assistants.
389
+ */
390
+ async getPrebuilt() {
391
+ return this.api.get("/v1/assistants/prebuilt");
392
+ }
393
+ /**
394
+ * Get prebuilt assistant by slug.
395
+ */
396
+ async getPrebuiltBySlug(slug) {
397
+ return this.api.get(`/v1/assistants/prebuilt/${slug}`);
398
+ }
399
+ /**
400
+ * Send a chat request to an assistant.
401
+ */
402
+ async chat(assistantId, _params) {
403
+ const params = AssistantChatParamsSchema.parse(_params);
404
+ const response = await this.api.post(
405
+ `/v1/assistants/${assistantId}/model`,
406
+ params,
407
+ {
408
+ responseType: params.stream ? "stream" : void 0
409
+ }
410
+ );
411
+ return AssistantMapper.mapBaseModelApiResponse(response);
412
+ }
413
+ };
414
+
415
+ // src/services/datasource.ts
416
+ var import_form_data = __toESM(require("form-data"), 1);
417
+
418
+ // src/models/datasource.ts
419
+ var CodeDataSourceType = {
420
+ CODE: "code",
421
+ SUMMARY: "summary",
422
+ CHUNK_SUMMARY: "chunk-summary"
423
+ };
424
+ var DataSourceType = {
425
+ CODE: "code",
426
+ CONFLUENCE: "knowledge_base_confluence",
427
+ JIRA: "knowledge_base_jira",
428
+ FILE: "knowledge_base_file",
429
+ GOOGLE: "llm_routing_google",
430
+ PROVIDER: "provider",
431
+ SUMMARY: "summary",
432
+ CHUNK_SUMMARY: "chunk-summary",
433
+ JSON: "knowledge_base_json"
434
+ };
435
+ var DataSourceStatus = {
436
+ COMPLETED: "completed",
437
+ FAILED: "failed",
438
+ FETCHING: "fetching",
439
+ IN_PROGRESS: "in_progress"
440
+ };
441
+
442
+ // src/mappers/datasource.mapper.ts
443
+ var DatasourceMapper = class _DatasourceMapper {
444
+ /** Transforms API response into a client-friendly DataSource model, maintaining API-agnostic interface */
445
+ static mapDatasourceResponse(response) {
446
+ return omitUndefined({
447
+ id: response.id,
448
+ project_name: response.project_name,
449
+ name: response.repo_name,
450
+ description: response.description,
451
+ type: response.index_type,
452
+ embeddings_model: response.embeddings_model,
453
+ status: response.status,
454
+ setting_id: response.setting_id,
455
+ created_date: response.date,
456
+ created_by: response.created_by,
457
+ shared_with_project: response.project_space_visible,
458
+ update_date: response.update_date,
459
+ error_message: response.text,
460
+ user_abilities: response.user_abilities,
461
+ processing_info: response.processing_info ? _DatasourceMapper.mapDatasourceProcessingInfoResponse(response.processing_info) : void 0,
462
+ processed_documents: response.processed_files,
463
+ tokens_usage: response.tokens_usage,
464
+ code: response.code,
465
+ jira: response.jira,
466
+ confluence: response.confluence,
467
+ google_doc_link: response.google_doc_link
468
+ });
469
+ }
470
+ /** Converts processing metadata from API format to client model format with consistent property naming */
471
+ static mapDatasourceProcessingInfoResponse(response) {
472
+ return omitUndefined({
473
+ total_documents_count: response.total_documents,
474
+ skipped_documents_count: response.skipped_documents,
475
+ total_size_kb: response.total_size_kb,
476
+ average_file_size_bytes: response.average_file_size_bytes,
477
+ unique_extensions: response.unique_extensions,
478
+ filtered_documents: response.filtered_documents,
479
+ processed_documents_count: response.documents_count_key
480
+ });
481
+ }
482
+ /** Transforms datasource creation parameters into DTO format, applying type-specific mappings based on datasource type */
483
+ static mapDatasourceCreateToDto(create) {
484
+ return omitUndefined({
485
+ ..._DatasourceMapper.mapCommonDataSourceParams(create),
486
+ ...create.type === DataSourceType.CONFLUENCE && _DatasourceMapper.mapConfluenceDataSourceParams(create),
487
+ ...create.type === DataSourceType.JIRA && _DatasourceMapper.mapJiraDataSourceParams(create),
488
+ ...create.type === DataSourceType.GOOGLE && _DatasourceMapper.mapGoogleDataSourceParams(create),
489
+ ...create.type === DataSourceType.FILE && _DatasourceMapper.mapFileDataSourceParams(create),
490
+ ...create.type === DataSourceType.CODE && _DatasourceMapper.mapCodeDataSourceParams(create)
491
+ });
492
+ }
493
+ /** Converts datasource update parameters to DTO format with conditional inclusion of type-specific properties */
494
+ static mapDatasourceUpdateToDto(update) {
495
+ return omitUndefined({
496
+ ..._DatasourceMapper.mapCommonUpdateDataSourceParams(update),
497
+ ...update.type === DataSourceType.CONFLUENCE && _DatasourceMapper.mapConfluenceDataSourceParams(update),
498
+ ...update.type === DataSourceType.JIRA && _DatasourceMapper.mapJiraDataSourceParams(update),
499
+ ...update.type === DataSourceType.GOOGLE && _DatasourceMapper.mapGoogleDataSourceParams(update),
500
+ ...update.type === DataSourceType.FILE && _DatasourceMapper.mapFileDataSourceParams(update),
501
+ ...update.type === DataSourceType.CODE && _DatasourceMapper.mapCodeDataSourceParams(update)
502
+ });
503
+ }
504
+ /** Maps Confluence-specific configuration parameters for content filtering and pagination options */
505
+ static mapConfluenceDataSourceParams(params) {
506
+ return {
507
+ cql: params.cql,
508
+ include_restricted_content: params.include_restricted_content,
509
+ include_archived_content: params.include_archived_content,
510
+ include_attachments: params.include_attachments,
511
+ include_comments: params.include_comments,
512
+ keep_markdown_format: params.keep_markdown_format,
513
+ keep_newlines: params.keep_newlines,
514
+ max_pages: params.max_pages,
515
+ pages_per_request: params.pages_per_request
516
+ };
517
+ }
518
+ /** Maps Jira-specific parameters, transforming JQL (Jira Query Language) filter configuration */
519
+ static mapJiraDataSourceParams(params) {
520
+ return {
521
+ jql: params.jql
522
+ };
523
+ }
524
+ /** Maps Google Doc specific parameters with proper API naming conventions */
525
+ static mapGoogleDataSourceParams(params) {
526
+ return {
527
+ googleDoc: params.google_doc
528
+ };
529
+ }
530
+ /** Maps file upload datasource parameters, handling file reference collections */
531
+ static mapFileDataSourceParams(params) {
532
+ return {
533
+ files: params.files
534
+ };
535
+ }
536
+ /** Maps code repository specific parameters including indexing strategy and code processing settings */
537
+ static mapCodeDataSourceParams(params) {
538
+ return {
539
+ settingId: params.setting_id,
540
+ projectSpaceVisible: params.shared_with_project || false,
541
+ link: params.link,
542
+ branch: params.branch,
543
+ indexType: params.index_type,
544
+ filesFilter: params.files_filter,
545
+ embeddingsModel: params.embeddings_model,
546
+ summarizationModel: params.summarization_model,
547
+ prompt: params.prompt,
548
+ docsGeneration: params.docs_generation || false
549
+ };
550
+ }
551
+ /** Maps general datasource parameters common across all datasource types with appropriate fallback values */
552
+ static mapCommonDataSourceParams(params) {
553
+ return {
554
+ name: params.name,
555
+ project_name: params.project_name,
556
+ description: params.description,
557
+ project_space_visible: params.shared_with_project || false,
558
+ setting_id: params.setting_id || null,
559
+ type: params.type
560
+ };
561
+ }
562
+ static mapCommonUpdateDataSourceParams(params) {
563
+ return omitUndefined({
564
+ name: params.name,
565
+ project_name: params.project_name,
566
+ description: params.description,
567
+ project_space_visible: params.shared_with_project || false,
568
+ setting_id: params.setting_id || null,
569
+ type: params.type
570
+ });
571
+ }
572
+ };
573
+
574
+ // src/services/datasource.ts
575
+ var DATA_SOURCE_TO_PATH_PARAM = {
576
+ [DataSourceType.CODE]: "CODE",
577
+ [DataSourceType.CONFLUENCE]: "CONFLUENCE",
578
+ [DataSourceType.JIRA]: "JIRA",
579
+ [DataSourceType.FILE]: "FILE",
580
+ [DataSourceType.GOOGLE]: "GOOGLE",
581
+ [DataSourceType.PROVIDER]: "PROVIDER",
582
+ [DataSourceType.SUMMARY]: "SUMMARY",
583
+ [DataSourceType.CHUNK_SUMMARY]: "CHUNK_SUMMARY",
584
+ [DataSourceType.JSON]: "JSON"
585
+ };
586
+ var DatasourceService = class {
587
+ constructor(apiDomain, token, verifySSL = true) {
588
+ this.api = new ApiRequestHandler(apiDomain, token, verifySSL);
589
+ }
590
+ /**
591
+ * Create a new datasource.
592
+ */
593
+ async create(params) {
594
+ const dto = DatasourceMapper.mapDatasourceCreateToDto(params);
595
+ if (dto.type === DataSourceType.FILE) {
596
+ return this.createFileDatasource(dto);
597
+ }
598
+ return this.api.post(this.getCreateDatasourceUrl(dto.type, dto.project_name), dto);
599
+ }
600
+ /**
601
+ * Create a file datasource.
602
+ */
603
+ async createFileDatasource({
604
+ files,
605
+ ...datasource
606
+ }) {
607
+ const formData = new import_form_data.default();
608
+ for (const file of files) {
609
+ formData.append("files", Buffer.from(file.content), {
610
+ filename: file.name,
611
+ contentType: file.mime_type
612
+ });
613
+ }
614
+ return this.api.postMultipart(
615
+ this.getCreateDatasourceUrl(datasource.type, datasource.project_name),
616
+ formData,
617
+ datasource
618
+ );
619
+ }
620
+ /**
621
+ * Update an existing datasource.
622
+ */
623
+ async update(params) {
624
+ this.validateUpdateReindexParams(params);
625
+ const { full_reindex, skip_reindex, resume_indexing, incremental_reindex, ...data } = params;
626
+ const endpoint = params.type === DataSourceType.CODE ? `/v1/application/${params.project_name}/index/${params.name}` : `/v1/index/knowledge_base/${this.getKnowledgeBaseParam(params.type)}`;
627
+ const queryParams = {
628
+ full_reindex,
629
+ skip_reindex,
630
+ resume_indexing,
631
+ incremental_reindex
632
+ };
633
+ const { type, ...dto } = DatasourceMapper.mapDatasourceUpdateToDto(data);
634
+ return this.api.put(endpoint, dto, { params: queryParams });
635
+ }
636
+ /**
637
+ * List datasources with pagination and filtering support.
638
+ */
639
+ async list(params = {}) {
640
+ const queryParams = {
641
+ page: params.page || 0,
642
+ per_page: params.per_page || 10,
643
+ sort_key: params.sort_key || "update_date",
644
+ sort_order: params.sort_order || "desc"
645
+ };
646
+ if (params.datasource_types || params.projects || params.status || params.owner) {
647
+ const filters = {};
648
+ if (params.datasource_types) filters.index_type = params.datasource_types;
649
+ if (params.projects) filters.project = params.projects;
650
+ if (params.status) filters.status = params.status;
651
+ if (params.owner) filters.created_by = params.owner;
652
+ queryParams.filters = JSON.stringify(filters);
653
+ }
654
+ const response = await this.api.get(
655
+ "/v1/index",
656
+ queryParams
657
+ );
658
+ return response.data.map(DatasourceMapper.mapDatasourceResponse);
659
+ }
660
+ /**
661
+ * Get datasource by ID.
662
+ */
663
+ async get(datasourceId) {
664
+ const response = await this.api.get(`/v1/index/${datasourceId}`);
665
+ return DatasourceMapper.mapDatasourceResponse(response);
666
+ }
667
+ /**
668
+ * Delete a datasource by ID.
669
+ */
670
+ async delete(datasourceId) {
671
+ return this.api.delete(`/v1/index/${datasourceId}`);
672
+ }
673
+ getCreateDatasourceUrl(type, projectName) {
674
+ if (type === DataSourceType.CODE) {
675
+ return `/v1/application/${projectName}/index`;
676
+ }
677
+ return `/v1/index/knowledge_base/${this.getKnowledgeBaseParam(type)}`;
678
+ }
679
+ getKnowledgeBaseParam(type) {
680
+ return DATA_SOURCE_TO_PATH_PARAM[type].toLowerCase();
681
+ }
682
+ /**
683
+ * Validates update parameters for reindexing.
684
+ * @throws {Error} If the update parameters are invalid for the given datasource type.
685
+ */
686
+ validateUpdateReindexParams(updateParams) {
687
+ if (updateParams.type === DataSourceType.CONFLUENCE && updateParams.incremental_reindex) {
688
+ throw new Error("Confluence data sources only support full_reindex and resume_indexing");
689
+ }
690
+ if (updateParams.type === DataSourceType.JIRA && updateParams.resume_indexing) {
691
+ throw new Error("Jira data sources only support full_reindex and incremental_reindex");
692
+ }
693
+ if (updateParams.type === DataSourceType.CODE && updateParams.incremental_reindex) {
694
+ throw new Error("Code data sources do not support incremental_reindex");
695
+ }
696
+ if (updateParams.type === DataSourceType.GOOGLE && updateParams.incremental_reindex) {
697
+ throw new Error("Google data sources only support full_reindex");
698
+ }
699
+ }
700
+ };
701
+
702
+ // src/models/integration.ts
703
+ var CredentialTypes = {
704
+ JIRA: "Jira",
705
+ CONFLUENCE: "Confluence",
706
+ GIT: "Git",
707
+ KUBERNETES: "Kubernetes",
708
+ AWS: "AWS",
709
+ GCP: "GCP",
710
+ KEYCLOAK: "Keycloak",
711
+ AZURE: "Azure",
712
+ ELASTIC: "Elastic",
713
+ OPENAPI: "OpenAPI",
714
+ PLUGIN: "Plugin",
715
+ FILESYSTEM: "FileSystem",
716
+ SCHEDULER: "Scheduler",
717
+ WEBHOOK: "Webhook",
718
+ EMAIL: "Email",
719
+ AZURE_DEVOPS: "AzureDevOps",
720
+ SONAR: "Sonar",
721
+ SQL: "SQL",
722
+ TELEGRAM: "Telegram",
723
+ ZEPHYR_CLOUD: "ZephyrCloud",
724
+ ZEPHYR_SQUAD: "ZephyrSquad",
725
+ SERVICE_NOW: "ServiceNow",
726
+ DIAL: "DIAL",
727
+ A2A: "A2A",
728
+ MCP: "MCP"
729
+ };
730
+ var IntegrationType = {
731
+ USER: "user",
732
+ PROJECT: "project"
733
+ };
734
+
735
+ // src/schemas/integration.ts
736
+ var import_zod2 = require("zod");
737
+ var IntegrationListParamsSchema = import_zod2.z.object({
738
+ setting_type: import_zod2.z.enum([IntegrationType.USER, IntegrationType.PROJECT]).default(IntegrationType.USER),
739
+ page: import_zod2.z.number().default(0),
740
+ per_page: import_zod2.z.number().default(10),
741
+ filters: import_zod2.z.record(import_zod2.z.unknown()).optional()
742
+ }).readonly();
743
+ var IntegrationGetParamsSchema = import_zod2.z.object({
744
+ integration_id: import_zod2.z.string(),
745
+ setting_type: import_zod2.z.enum([IntegrationType.USER, IntegrationType.PROJECT]).default(IntegrationType.USER)
746
+ }).readonly();
747
+ var IntegrationGetByAliasParamsSchema = import_zod2.z.object({
748
+ alias: import_zod2.z.string(),
749
+ setting_type: import_zod2.z.enum([IntegrationType.USER, IntegrationType.PROJECT]).default(IntegrationType.USER)
750
+ }).readonly();
751
+ var CredentialValueSchema = import_zod2.z.object({
752
+ key: import_zod2.z.string(),
753
+ value: import_zod2.z.unknown()
754
+ });
755
+ var IntegrationCreateParamsSchema = import_zod2.z.object({
756
+ credential_type: import_zod2.z.enum(Object.values(CredentialTypes)),
757
+ credential_values: import_zod2.z.array(CredentialValueSchema),
758
+ project_name: import_zod2.z.string(),
759
+ setting_type: import_zod2.z.enum([IntegrationType.USER, IntegrationType.PROJECT]).default(IntegrationType.USER),
760
+ alias: import_zod2.z.string().optional(),
761
+ default: import_zod2.z.boolean().optional().default(false),
762
+ project: import_zod2.z.string().optional(),
763
+ enabled: import_zod2.z.boolean().optional().default(true),
764
+ external_id: import_zod2.z.string().optional()
765
+ }).readonly();
766
+ var IntegrationUpdateParamsSchema = IntegrationCreateParamsSchema;
767
+
768
+ // src/services/integration.ts
769
+ var IntegrationService = class {
770
+ constructor(apiDomain, token, verifySSL = true) {
771
+ this.api = new ApiRequestHandler(apiDomain, token, verifySSL);
772
+ }
773
+ /**
774
+ * Get base API path based on setting type.
775
+ */
776
+ getBasePath(settingType) {
777
+ return `/v1/settings/${settingType === IntegrationType.USER ? "user" : "project"}`;
778
+ }
779
+ /**
780
+ * Get list of available integrations.
781
+ */
782
+ async list(_params = {}) {
783
+ const params = IntegrationListParamsSchema.parse(_params);
784
+ const settingType = params.setting_type;
785
+ const queryParams = {
786
+ page: params.page,
787
+ per_page: params.per_page,
788
+ ...params.filters && { filters: JSON.stringify(params.filters) }
789
+ };
790
+ const response = await this.api.get(
791
+ this.getBasePath(settingType),
792
+ queryParams
793
+ );
794
+ return response.data;
795
+ }
796
+ /**
797
+ * Get integration by ID.
798
+ */
799
+ async get(_params) {
800
+ const params = IntegrationGetParamsSchema.parse(_params);
801
+ const settingType = params.setting_type;
802
+ const integrationId = params.integration_id;
803
+ const integrations = await this.list({
804
+ per_page: 100,
805
+ setting_type: settingType
806
+ });
807
+ const integration = integrations.find((i) => i.id === integrationId);
808
+ if (!integration) {
809
+ throw new NotFoundError("Integration", integrationId);
810
+ }
811
+ return integration;
812
+ }
813
+ /**
814
+ * Get integration by alias.
815
+ */
816
+ async getByAlias(_params) {
817
+ const params = IntegrationGetByAliasParamsSchema.parse(_params);
818
+ const settingType = params.setting_type;
819
+ const alias = params.alias;
820
+ const integrations = await this.list({
821
+ per_page: 100,
822
+ setting_type: settingType
823
+ });
824
+ const integration = integrations.find((i) => i.alias === alias);
825
+ if (!integration) {
826
+ throw new NotFoundError("Integration", alias);
827
+ }
828
+ return integration;
829
+ }
830
+ /**
831
+ * Create a new integration.
832
+ */
833
+ async create(_params) {
834
+ const params = IntegrationCreateParamsSchema.parse(_params);
835
+ const settingType = params.setting_type;
836
+ return this.api.post(this.getBasePath(settingType), {
837
+ ...params,
838
+ setting_type: settingType,
839
+ default: false
840
+ });
841
+ }
842
+ /**
843
+ * Update an existing integration.
844
+ */
845
+ async update(settingId, _params) {
846
+ const params = IntegrationUpdateParamsSchema.parse(_params);
847
+ const settingType = params.setting_type;
848
+ return this.api.put(`${this.getBasePath(settingType)}/${settingId}`, {
849
+ ...params,
850
+ setting_type: settingType,
851
+ default: false
852
+ });
853
+ }
854
+ /**
855
+ * Delete an integration by ID.
856
+ */
857
+ async delete(settingId, settingType = IntegrationType.USER) {
858
+ return this.api.delete(`${this.getBasePath(settingType)}/${settingId}`);
859
+ }
860
+ };
861
+
862
+ // src/services/llm.ts
863
+ var LLMService = class {
864
+ constructor(apiDomain, token, verifySSL = true) {
865
+ this.api = new ApiRequestHandler(apiDomain, token, verifySSL);
866
+ }
867
+ /**
868
+ * Get list of available LLM models.
869
+ */
870
+ async list() {
871
+ return this.api.get("/v1/llm_models");
872
+ }
873
+ /**
874
+ * Get list of available embeddings models.
875
+ */
876
+ async listEmbeddings() {
877
+ return this.api.get("/v1/embeddings_models");
878
+ }
879
+ };
880
+
881
+ // src/services/task.ts
882
+ var TaskService = class {
883
+ constructor(apiDomain, token, verifySSL = true) {
884
+ this.api = new ApiRequestHandler(apiDomain, token, verifySSL);
885
+ }
886
+ /**
887
+ * Get a background task by ID.
888
+ */
889
+ async get(taskId) {
890
+ return this.api.get(`/v1/tasks/${taskId}`);
891
+ }
892
+ };
893
+
894
+ // src/mappers/user.mapper.ts
895
+ var UserMapper = class {
896
+ static mapAboutUserResponse(response) {
897
+ return omitUndefined({
898
+ user_id: response.userId,
899
+ name: response.name,
900
+ username: response.username,
901
+ is_admin: response.isAdmin,
902
+ applications: response.applications,
903
+ applications_admin: response.applicationsAdmin,
904
+ picture: response.picture,
905
+ knowledge_bases: response.knowledgeBases
906
+ });
907
+ }
908
+ };
909
+
910
+ // src/services/user.ts
911
+ var UserService = class {
912
+ constructor(apiDomain, token, verifySSL = true) {
913
+ this.api = new ApiRequestHandler(apiDomain, token, verifySSL);
914
+ }
915
+ /**
916
+ * Get current user profile.
917
+ */
918
+ async aboutMe() {
919
+ const response = await this.api.get("/v1/user");
920
+ return UserMapper.mapAboutUserResponse(response);
921
+ }
922
+ /**
923
+ * Get user data and preferences.
924
+ */
925
+ async getData() {
926
+ return this.api.get("/v1/user/data");
927
+ }
928
+ };
929
+
930
+ // src/mappers/workflow.mapper.ts
931
+ var WorkflowMapper = class {
932
+ static mapWorkflowResponse(response) {
933
+ return omitUndefined({
934
+ id: response.id,
935
+ project: response.project,
936
+ name: response.name,
937
+ description: response.description,
938
+ yaml_config: response.yaml_config,
939
+ mode: response.mode,
940
+ shared: response.shared,
941
+ icon_url: response.icon_url,
942
+ created_date: response.date,
943
+ update_date: response.update_date,
944
+ created_by: response.created_by
945
+ });
946
+ }
947
+ static mapWorkflowExecutionResponse(response) {
948
+ return omitUndefined({
949
+ id: response.id,
950
+ execution_id: response.execution_id,
951
+ workflow_id: response.workflow_id,
952
+ overall_status: response.status,
953
+ created_date: response.date,
954
+ prompt: response.prompt,
955
+ updated_date: response.updated_date,
956
+ created_by: response.created_by,
957
+ tokens_usage: response.tokens_usage
958
+ });
959
+ }
960
+ };
961
+
962
+ // src/schemas/workflow.ts
963
+ var import_zod3 = require("zod");
964
+
965
+ // src/models/workflow.ts
966
+ var WorkflowMode = {
967
+ SEQUENTIAL: "Sequential",
968
+ AUTONOMOUS: "Autonomous"
969
+ };
970
+ var ExecutionStatus = {
971
+ IN_PROGRESS: "In Progress",
972
+ NOT_STARTED: "Not Started",
973
+ INTERRUPTED: "Interrupted",
974
+ FAILED: "Failed",
975
+ SUCCEEDED: "Succeeded",
976
+ ABORTED: "Aborted"
977
+ };
978
+
979
+ // src/schemas/workflow.ts
980
+ var WorkflowListParamsSchema = import_zod3.z.object({
981
+ page: import_zod3.z.number().default(0),
982
+ per_page: import_zod3.z.number().default(10),
983
+ projects: import_zod3.z.array(import_zod3.z.string()).optional()
984
+ }).readonly();
985
+ var WorkflowCreateParamsSchema = import_zod3.z.object({
986
+ project: import_zod3.z.string(),
987
+ name: import_zod3.z.string(),
988
+ description: import_zod3.z.string().optional(),
989
+ yaml_config: import_zod3.z.string(),
990
+ mode: import_zod3.z.enum([WorkflowMode.SEQUENTIAL, WorkflowMode.AUTONOMOUS]),
991
+ shared: import_zod3.z.boolean(),
992
+ icon_url: import_zod3.z.string().optional()
993
+ }).readonly();
994
+ var WorkflowUpdateParamsSchema = import_zod3.z.object({
995
+ project: import_zod3.z.string(),
996
+ name: import_zod3.z.string(),
997
+ description: import_zod3.z.string().optional(),
998
+ yaml_config: import_zod3.z.string(),
999
+ mode: import_zod3.z.enum([WorkflowMode.SEQUENTIAL, WorkflowMode.AUTONOMOUS]).optional(),
1000
+ shared: import_zod3.z.boolean().optional(),
1001
+ icon_url: import_zod3.z.string().optional()
1002
+ }).readonly();
1003
+ var WorkflowExecutionListParamsSchema = import_zod3.z.object({
1004
+ page: import_zod3.z.number().default(0),
1005
+ per_page: import_zod3.z.number().default(10)
1006
+ }).readonly();
1007
+ var WorkflowExecutionCreateParamsSchema = import_zod3.z.object({
1008
+ user_input: import_zod3.z.string().default("")
1009
+ }).readonly();
1010
+ var WorkflowExecutionStateListParamsSchema = import_zod3.z.object({
1011
+ page: import_zod3.z.number().default(0),
1012
+ per_page: import_zod3.z.number().default(10)
1013
+ }).readonly();
1014
+
1015
+ // src/services/workflow_execution_state.ts
1016
+ var WorkflowExecutionStateService = class {
1017
+ constructor(api, workflowId, executionId) {
1018
+ this.api = api;
1019
+ this.workflowId = workflowId;
1020
+ this.executionId = executionId;
1021
+ }
1022
+ /**
1023
+ * List states for the workflow execution with filtering and pagination support.
1024
+ */
1025
+ async list(_params = {}) {
1026
+ const params = WorkflowExecutionStateListParamsSchema.parse(_params);
1027
+ const queryParams = {
1028
+ page: params.page,
1029
+ per_page: params.per_page
1030
+ };
1031
+ const response = await this.api.get(
1032
+ `/v1/workflows/${this.workflowId}/executions/${this.executionId}/states`,
1033
+ { params: queryParams }
1034
+ );
1035
+ return response.data;
1036
+ }
1037
+ /**
1038
+ * Get output for a specific execution state.
1039
+ */
1040
+ async getOutput(stateId) {
1041
+ return this.api.get(
1042
+ `/v1/workflows/${this.workflowId}/executions/${this.executionId}/states/${stateId}/output`
1043
+ );
1044
+ }
1045
+ };
1046
+
1047
+ // src/services/workflow_execution.ts
1048
+ var WorkflowExecutionService = class {
1049
+ constructor(api, workflowId) {
1050
+ this.api = api;
1051
+ this.workflowId = workflowId;
1052
+ }
1053
+ /**
1054
+ * List executions for the workflow with filtering and pagination support.
1055
+ */
1056
+ async list(_params = {}) {
1057
+ const params = WorkflowExecutionListParamsSchema.parse(_params);
1058
+ const queryParams = {
1059
+ page: params.page,
1060
+ per_page: params.per_page
1061
+ };
1062
+ const response = await this.api.get(
1063
+ `/v1/workflows/${this.workflowId}/executions`,
1064
+ { params: queryParams }
1065
+ );
1066
+ return response.data.map(WorkflowMapper.mapWorkflowExecutionResponse);
1067
+ }
1068
+ /**
1069
+ * Create a new workflow execution.
1070
+ */
1071
+ async create(userInput = "") {
1072
+ const params = WorkflowExecutionCreateParamsSchema.parse({ user_input: userInput });
1073
+ return this.api.post(`/v1/workflows/${this.workflowId}/executions`, params);
1074
+ }
1075
+ /**
1076
+ * Get workflow execution by ID.
1077
+ */
1078
+ async get(executionId) {
1079
+ const response = await this.api.get(
1080
+ `/v1/workflows/${this.workflowId}/executions/${executionId}`
1081
+ );
1082
+ return WorkflowMapper.mapWorkflowExecutionResponse(response);
1083
+ }
1084
+ /**
1085
+ * Get states service for a specific workflow execution.
1086
+ */
1087
+ states(executionId) {
1088
+ return new WorkflowExecutionStateService(this.api, this.workflowId, executionId);
1089
+ }
1090
+ /**
1091
+ * Delete all workflow executions.
1092
+ */
1093
+ async deleteAll() {
1094
+ return this.api.delete(`/v1/workflows/${this.workflowId}/executions`);
1095
+ }
1096
+ /**
1097
+ * Abort a running workflow execution.
1098
+ */
1099
+ async abort(executionId) {
1100
+ return this.api.put(`/v1/workflows/${this.workflowId}/executions/${executionId}/abort`);
1101
+ }
1102
+ /**
1103
+ * Resume an interrupted workflow execution.
1104
+ */
1105
+ async resume(executionId) {
1106
+ return this.api.put(`/v1/workflows/${this.workflowId}/executions/${executionId}/resume`);
1107
+ }
1108
+ };
1109
+
1110
+ // src/services/workflow.ts
1111
+ var WorkflowService = class {
1112
+ constructor(apiDomain, token, verifySSL = true) {
1113
+ this.api = new ApiRequestHandler(apiDomain, token, verifySSL);
1114
+ }
1115
+ /**
1116
+ * Get list of prebuilt workflows.
1117
+ */
1118
+ async getPrebuilt() {
1119
+ const response = await this.api.get("/v1/workflows/prebuilt");
1120
+ return response.map(WorkflowMapper.mapWorkflowResponse);
1121
+ }
1122
+ /**
1123
+ * Create a new workflow.
1124
+ */
1125
+ async create(_params) {
1126
+ const params = WorkflowCreateParamsSchema.parse(_params);
1127
+ return this.api.post("/v1/workflows", params);
1128
+ }
1129
+ /**
1130
+ * Update an existing workflow.
1131
+ */
1132
+ async update(workflowId, _params) {
1133
+ const params = WorkflowUpdateParamsSchema.parse(_params);
1134
+ return this.api.put(`/v1/workflows/${workflowId}`, params);
1135
+ }
1136
+ /**
1137
+ * List workflows with filtering and pagination support.
1138
+ */
1139
+ async list(_params = {}) {
1140
+ const params = WorkflowListParamsSchema.parse(_params);
1141
+ const queryParams = {
1142
+ filters: JSON.stringify({
1143
+ page: params.page,
1144
+ per_page: params.per_page,
1145
+ ...params.projects?.length ? { projects: params.projects } : {}
1146
+ })
1147
+ };
1148
+ const workflows = await this.api.get("/v1/workflows", {
1149
+ params: queryParams
1150
+ });
1151
+ return workflows.data.map(WorkflowMapper.mapWorkflowResponse);
1152
+ }
1153
+ /**
1154
+ * Get workflow by ID.
1155
+ */
1156
+ async get(workflowId) {
1157
+ const response = await this.api.get(`/v1/workflows/id/${workflowId}`);
1158
+ return WorkflowMapper.mapWorkflowResponse(response);
1159
+ }
1160
+ /**
1161
+ * Delete a workflow by ID.
1162
+ */
1163
+ async delete(workflowId) {
1164
+ return this.api.delete(`/v1/workflows/${workflowId}`);
1165
+ }
1166
+ /**
1167
+ * Run a workflow by ID.
1168
+ */
1169
+ async run(workflowId, userInput = "") {
1170
+ return this.executions(workflowId).create(userInput);
1171
+ }
1172
+ /**
1173
+ * Get workflow execution service for the specified workflow.
1174
+ */
1175
+ executions(workflowId) {
1176
+ return new WorkflowExecutionService(this.api, workflowId);
1177
+ }
1178
+ };
1179
+
1180
+ // src/client/client.ts
1181
+ var CodeMieClient = class {
1182
+ constructor(config) {
1183
+ this.token = null;
1184
+ const {
1185
+ auth_server_url,
1186
+ auth_realm_name,
1187
+ codemie_api_domain,
1188
+ auth_client_id,
1189
+ auth_client_secret,
1190
+ username,
1191
+ password,
1192
+ verify_ssl = true
1193
+ } = config;
1194
+ this.auth = new KeycloakCredentials({
1195
+ serverUrl: auth_server_url,
1196
+ realmName: auth_realm_name,
1197
+ clientId: auth_client_id,
1198
+ clientSecret: auth_client_secret,
1199
+ username,
1200
+ password,
1201
+ verifySSL: verify_ssl
1202
+ });
1203
+ this.apiDomain = codemie_api_domain.replace(/\/$/, "");
1204
+ this.verifySSL = verify_ssl;
1205
+ this.token = "";
1206
+ this._assistants = new AssistantService(this.apiDomain, this.token, this.verifySSL);
1207
+ this._llms = new LLMService(this.apiDomain, this.token, this.verifySSL);
1208
+ this._integrations = new IntegrationService(this.apiDomain, this.token, this.verifySSL);
1209
+ this._tasks = new TaskService(this.apiDomain, this.token, this.verifySSL);
1210
+ this._users = new UserService(this.apiDomain, this.token, this.verifySSL);
1211
+ this._datasources = new DatasourceService(this.apiDomain, this.token, this.verifySSL);
1212
+ this._workflows = new WorkflowService(this.apiDomain, this.token, this.verifySSL);
1213
+ }
1214
+ /**
1215
+ * Get the AssistantService instance.
1216
+ */
1217
+ get assistants() {
1218
+ return this._assistants;
1219
+ }
1220
+ /**
1221
+ * Get the LLMService instance.
1222
+ */
1223
+ get llms() {
1224
+ return this._llms;
1225
+ }
1226
+ /**
1227
+ * Get the IntegrationService instance.
1228
+ */
1229
+ get integrations() {
1230
+ return this._integrations;
1231
+ }
1232
+ /**
1233
+ * Get the TaskService instance.
1234
+ */
1235
+ get tasks() {
1236
+ return this._tasks;
1237
+ }
1238
+ /**
1239
+ * Get the UserService instance.
1240
+ */
1241
+ get users() {
1242
+ return this._users;
1243
+ }
1244
+ /**
1245
+ * Get the DatasourceService instance.
1246
+ */
1247
+ get datasources() {
1248
+ return this._datasources;
1249
+ }
1250
+ /**
1251
+ * Get the WorkflowService instance.
1252
+ */
1253
+ get workflows() {
1254
+ return this._workflows;
1255
+ }
1256
+ /**
1257
+ * Initialize the client by obtaining the initial token.
1258
+ * This should be called after creating the client instance.
1259
+ */
1260
+ async initialize() {
1261
+ this.token = await this.auth.getToken();
1262
+ await this.refreshServices();
1263
+ }
1264
+ /**
1265
+ * Get the current access token or fetch a new one if not available.
1266
+ */
1267
+ async getToken() {
1268
+ if (!this.token) {
1269
+ this.token = await this.auth.getToken();
1270
+ await this.refreshServices();
1271
+ }
1272
+ return this.token;
1273
+ }
1274
+ /**
1275
+ * Force token refresh and update all services with the new token.
1276
+ */
1277
+ async refreshToken() {
1278
+ this.token = await this.auth.getToken();
1279
+ await this.refreshServices();
1280
+ return this.token;
1281
+ }
1282
+ /**
1283
+ * Reinitialize all services with the current token.
1284
+ */
1285
+ async refreshServices() {
1286
+ if (!this.token) {
1287
+ throw new Error("Token not available");
1288
+ }
1289
+ this._assistants = new AssistantService(this.apiDomain, this.token, this.verifySSL);
1290
+ this._llms = new LLMService(this.apiDomain, this.token, this.verifySSL);
1291
+ this._integrations = new IntegrationService(this.apiDomain, this.token, this.verifySSL);
1292
+ this._tasks = new TaskService(this.apiDomain, this.token, this.verifySSL);
1293
+ this._users = new UserService(this.apiDomain, this.token, this.verifySSL);
1294
+ this._datasources = new DatasourceService(this.apiDomain, this.token, this.verifySSL);
1295
+ this._workflows = new WorkflowService(this.apiDomain, this.token, this.verifySSL);
1296
+ }
1297
+ };
1298
+
1299
+ // src/models/assistant.ts
1300
+ var ContextType = /* @__PURE__ */ ((ContextType2) => {
1301
+ ContextType2["KNOWLEDGE_BASE"] = "knowledge_base";
1302
+ ContextType2["CODE"] = "code";
1303
+ return ContextType2;
1304
+ })(ContextType || {});
1305
+ var ChatRole = /* @__PURE__ */ ((ChatRole2) => {
1306
+ ChatRole2["ASSISTANT"] = "Assistant";
1307
+ ChatRole2["USER"] = "User";
1308
+ return ChatRole2;
1309
+ })(ChatRole || {});
1310
+
1311
+ // src/models/llm.ts
1312
+ var LLMProvider = {
1313
+ AZURE_OPENAI: "azure_openai",
1314
+ AWS_BEDROCK: "aws_bedrock",
1315
+ GOOGLE_VERTEXAI: "google_vertexai"
1316
+ };
1317
+
1318
+ // src/models/task.ts
1319
+ var BackgroundTaskStatus = {
1320
+ STARTED: "STARTED",
1321
+ COMPLETED: "COMPLETED",
1322
+ FAILED: "FAILED"
1323
+ };
1324
+ // Annotate the CommonJS export names for ESM import in node:
1325
+ 0 && (module.exports = {
1326
+ ApiError,
1327
+ AssistantChatParamsSchema,
1328
+ AssistantCreateParamsSchema,
1329
+ AssistantListParamsSchema,
1330
+ AssistantUpdateParamsSchema,
1331
+ BackgroundTaskStatus,
1332
+ ChatRole,
1333
+ CodeDataSourceType,
1334
+ CodeMieClient,
1335
+ CodeMieError,
1336
+ ContextType,
1337
+ CredentialTypes,
1338
+ DataSourceStatus,
1339
+ DataSourceType,
1340
+ ExecutionStatus,
1341
+ IntegrationCreateParamsSchema,
1342
+ IntegrationGetByAliasParamsSchema,
1343
+ IntegrationGetParamsSchema,
1344
+ IntegrationListParamsSchema,
1345
+ IntegrationType,
1346
+ IntegrationUpdateParamsSchema,
1347
+ LLMProvider,
1348
+ NotFoundError,
1349
+ WorkflowCreateParamsSchema,
1350
+ WorkflowExecutionCreateParamsSchema,
1351
+ WorkflowExecutionListParamsSchema,
1352
+ WorkflowExecutionStateListParamsSchema,
1353
+ WorkflowListParamsSchema,
1354
+ WorkflowMode,
1355
+ WorkflowUpdateParamsSchema
1356
+ });
1357
+ //# sourceMappingURL=index.cjs.map