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/README.md +1008 -0
- package/dist/index.cjs +1357 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2025 -0
- package/dist/index.d.ts +2025 -0
- package/dist/index.js +1291 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,1008 @@
|
|
|
1
|
+
# CodeMie Node.js SDK
|
|
2
|
+
|
|
3
|
+
TypeScript/JavaScript SDK for CodeMie services. This SDK provides a comprehensive interface to interact with CodeMie services, including LLM (Large Language Models), assistants, workflows, and tools.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [CodeMie Node.js SDK](#codemie-nodejs-sdk)
|
|
8
|
+
- [Table of Contents](#table-of-contents)
|
|
9
|
+
- [Installation](#installation)
|
|
10
|
+
- [Usage](#usage)
|
|
11
|
+
- [Basic Usage](#basic-usage)
|
|
12
|
+
- [ESM Import](#esm-import)
|
|
13
|
+
- [CommonJS Import](#commonjs-import)
|
|
14
|
+
- [Service Details](#service-details)
|
|
15
|
+
- [LLM Service](#llm-service)
|
|
16
|
+
- [Assistant Service](#assistant-service)
|
|
17
|
+
- [Core Methods](#core-methods)
|
|
18
|
+
- [Advanced Features](#advanced-features)
|
|
19
|
+
- [Datasource Service](#datasource-service)
|
|
20
|
+
- [Supported Datasource Types](#supported-datasource-types)
|
|
21
|
+
- [Core Methods](#core-methods-1)
|
|
22
|
+
- [Datasource Status](#datasource-status)
|
|
23
|
+
- [Best Practices for Datasources](#best-practices-for-datasources)
|
|
24
|
+
- [Integration Service](#integration-service)
|
|
25
|
+
- [Integration Types](#integration-types)
|
|
26
|
+
- [Core Methods](#core-methods-2)
|
|
27
|
+
- [Best Practices for Integrations](#best-practices-for-integrations)
|
|
28
|
+
- [Workflow Service](#workflow-service)
|
|
29
|
+
- [Core Methods](#core-methods-3)
|
|
30
|
+
- [Workflow Execution](#workflow-execution)
|
|
31
|
+
- [Workflow Configuration](#workflow-configuration)
|
|
32
|
+
- [Best Practices](#best-practices)
|
|
33
|
+
- [Real World Examples](#real-world-examples)
|
|
34
|
+
- [Setting Up an AI Assistant with Jira Integration](#setting-up-an-ai-assistant-with-jira-integration)
|
|
35
|
+
- [Managing Workflows](#managing-workflows)
|
|
36
|
+
- [Error Handling Best Practices](#error-handling-best-practices)
|
|
37
|
+
- [Error Handling](#error-handling)
|
|
38
|
+
- [Workflow Status Monitoring](#workflow-status-monitoring)
|
|
39
|
+
- [Error Handling](#error-handling-1)
|
|
40
|
+
- [TypeScript Support](#typescript-support)
|
|
41
|
+
- [Development](#development)
|
|
42
|
+
- [Pack and Publish](#pack-and-publish)
|
|
43
|
+
- [Unit Tests](#unit-tests)
|
|
44
|
+
- [E2E Tests](#e2e-tests)
|
|
45
|
+
- [Support](#support)
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm install codemie-sdk
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
or
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
yarn add codemie-sdk
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
|
|
61
|
+
### Basic Usage
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { CodeMieClient } from 'codemie-sdk';
|
|
65
|
+
|
|
66
|
+
// Initialize client with authentication parameters
|
|
67
|
+
const client = new CodeMieClient({
|
|
68
|
+
auth_server_url: 'https://keycloak.eks-core.aws.main.edp.projects.epam.com/auth',
|
|
69
|
+
auth_realm_name: 'codemie-prod',
|
|
70
|
+
codemie_api_domain: 'https://codemie.lab.epam.com/code-assistant-api',
|
|
71
|
+
username: process.env.USERNAME,
|
|
72
|
+
password: process.env.PASSWORD,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Initialize the client (required before making any requests)
|
|
76
|
+
await client.initialize();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### ESM Import
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { CodeMieClient } from 'codemie-sdk';
|
|
83
|
+
|
|
84
|
+
const client = new CodeMieClient({
|
|
85
|
+
auth_server_url: process.env.AUTH_SERVER_URL || 'https://keycloak.eks-core.aws.main.edp.projects.epam.com/auth',
|
|
86
|
+
auth_realm_name: process.env.AUTH_REALM_NAME || 'codemie-prod',
|
|
87
|
+
codemie_api_domain: process.env.CODEMIE_API_DOMAIN || 'https://codemie.lab.epam.com/code-assistant-api',
|
|
88
|
+
username: process.env.USERNAME,
|
|
89
|
+
password: process.env.PASSWORD,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Initialize the client (required before making any requests)
|
|
93
|
+
await client.initialize();
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### CommonJS Import
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
const { CodeMieClient } = require('codemie-sdk');
|
|
100
|
+
|
|
101
|
+
const client = new CodeMieClient({
|
|
102
|
+
// ... same configuration as above
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Initialize the client (required before making any requests)
|
|
106
|
+
await client.initialize();
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Service Details
|
|
110
|
+
|
|
111
|
+
### LLM Service
|
|
112
|
+
|
|
113
|
+
The LLM service provides access to language models and embedding models from various providers:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { LLMProvider, LLMModel } from 'codemie-sdk';
|
|
117
|
+
|
|
118
|
+
// List available LLM models
|
|
119
|
+
const llmModels = await client.llm.list();
|
|
120
|
+
|
|
121
|
+
// List available embedding models
|
|
122
|
+
const embeddingModels = await client.llm.listEmbeddings();
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Example usage with provider and feature checks:
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
// Get available models
|
|
129
|
+
const models = await client.llm.list();
|
|
130
|
+
|
|
131
|
+
// Find Azure OpenAI models
|
|
132
|
+
const azureModels = models.filter(m => m.provider === LLMProvider.AZURE_OPENAI);
|
|
133
|
+
|
|
134
|
+
// Find models supporting streaming and tools
|
|
135
|
+
const streamingToolModels = models.filter(m =>
|
|
136
|
+
m.features.streaming && m.features.tools
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
// Get default model
|
|
140
|
+
const defaultModel = models.find(m => m.default);
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Assistant Service
|
|
144
|
+
|
|
145
|
+
The Assistant service allows you to manage and interact with CodeMie assistants:
|
|
146
|
+
|
|
147
|
+
#### Core Methods
|
|
148
|
+
|
|
149
|
+
1. **List Assistants**
|
|
150
|
+
```typescript
|
|
151
|
+
const assistants = await client.assistants.list({
|
|
152
|
+
minimal_response: true, // Return minimal assistant info
|
|
153
|
+
scope: "visible_to_user", // or "created_by_user"
|
|
154
|
+
page: 0,
|
|
155
|
+
per_page: 12,
|
|
156
|
+
filters: {key: "value"} // Optional filters
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
2. **Get Assistant Details**
|
|
161
|
+
```typescript
|
|
162
|
+
// By ID
|
|
163
|
+
const assistant = await client.assistants.get("assistant-id");
|
|
164
|
+
|
|
165
|
+
// By Slug
|
|
166
|
+
const assistant = await client.assistants.getBySlug("assistant-slug");
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
3. **Create Assistant**
|
|
170
|
+
```typescript
|
|
171
|
+
const params: AssistantCreateParams = {
|
|
172
|
+
name: "My Assistant",
|
|
173
|
+
description: "Assistant description",
|
|
174
|
+
system_prompt: "Assistant instructions",
|
|
175
|
+
toolkits: [],
|
|
176
|
+
project: "my_project",
|
|
177
|
+
llm_model_type: "gpt-4o",
|
|
178
|
+
context: [],
|
|
179
|
+
user_prompts: [],
|
|
180
|
+
mcp_servers: [],
|
|
181
|
+
assistant_ids: [],
|
|
182
|
+
temperature: 0.7,
|
|
183
|
+
top_p: 0.9,
|
|
184
|
+
shared: false,
|
|
185
|
+
is_react: false,
|
|
186
|
+
is_global: false
|
|
187
|
+
};
|
|
188
|
+
await client.assistants.create(params);
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
4. **Update Assistant**
|
|
192
|
+
```typescript
|
|
193
|
+
const params: AssistantUpdateParams = {
|
|
194
|
+
name: "Updated Name",
|
|
195
|
+
description: "Updated description",
|
|
196
|
+
system_prompt: "Updated instructions",
|
|
197
|
+
project: "my_project",
|
|
198
|
+
llm_model_type: "gpt-4",
|
|
199
|
+
context: [],
|
|
200
|
+
user_prompts: [],
|
|
201
|
+
mcp_servers: [],
|
|
202
|
+
assistant_ids: [],
|
|
203
|
+
toolkits: []
|
|
204
|
+
};
|
|
205
|
+
await client.assistants.update("assistant-id", params);
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
5. **Delete Assistant**
|
|
209
|
+
```typescript
|
|
210
|
+
await client.assistants.delete("assistant-id");
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### Advanced Features
|
|
214
|
+
|
|
215
|
+
6. **Chat with Assistant**
|
|
216
|
+
```typescript
|
|
217
|
+
const params: AssistantChatParams = {
|
|
218
|
+
text: "Your message here",
|
|
219
|
+
history: [], // Previous conversation messages as ChatMessage[] or string
|
|
220
|
+
// Optional parameters
|
|
221
|
+
stream: false, // Set to true for streaming response
|
|
222
|
+
conversation_id: "optional-conversation-id",
|
|
223
|
+
llm_model: "gpt-4o",
|
|
224
|
+
system_prompt: "Override default system prompt",
|
|
225
|
+
background_task: false,
|
|
226
|
+
content_raw: "", // Raw content if needed
|
|
227
|
+
file_name: "", // For file processing
|
|
228
|
+
history_index: 0,
|
|
229
|
+
top_k: 1,
|
|
230
|
+
metadata: {} // Additional metadata
|
|
231
|
+
};
|
|
232
|
+
const response = await client.assistants.chat("assistant-id", params);
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
7. **Work with Prebuilt Assistants**
|
|
236
|
+
```typescript
|
|
237
|
+
// List prebuilt assistants
|
|
238
|
+
const prebuilt = await client.assistants.getPrebuilt();
|
|
239
|
+
|
|
240
|
+
// Get specific prebuilt assistant
|
|
241
|
+
const prebuiltAssistant = await client.assistants.getPrebuiltBySlug("assistant-slug");
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
8. **Get Available Tools**
|
|
245
|
+
```typescript
|
|
246
|
+
const tools = await client.assistants.getTools();
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Datasource Service
|
|
250
|
+
|
|
251
|
+
The Datasource service enables managing various types of data sources in CodeMie, including code repositories, Confluence spaces, Jira projects, files, and Google documents.
|
|
252
|
+
|
|
253
|
+
#### Supported Datasource Types
|
|
254
|
+
|
|
255
|
+
- `CODE`: Code repository datasources
|
|
256
|
+
- `CONFLUENCE`: Confluence knowledge base
|
|
257
|
+
- `JIRA`: Jira knowledge base
|
|
258
|
+
- `FILE`: File-based knowledge base
|
|
259
|
+
- `GOOGLE`: Google documents
|
|
260
|
+
|
|
261
|
+
#### Core Methods
|
|
262
|
+
|
|
263
|
+
1. **Create Datasource**
|
|
264
|
+
```typescript
|
|
265
|
+
import { DataSourceType, CodeDataSourceType } from 'codemie-sdk';
|
|
266
|
+
|
|
267
|
+
// Create Code Datasource
|
|
268
|
+
const codeParams: CodeDataSourceCreateParams = {
|
|
269
|
+
type: DataSourceType.CODE,
|
|
270
|
+
name: "my_repo",
|
|
271
|
+
project_name: "my_project",
|
|
272
|
+
description: "My code repository",
|
|
273
|
+
shared_with_project: true,
|
|
274
|
+
setting_id: null,
|
|
275
|
+
link: "https://github.com/user/repo",
|
|
276
|
+
branch: "main",
|
|
277
|
+
index_type: CodeDataSourceType.CODE,
|
|
278
|
+
files_filter: "*.ts",
|
|
279
|
+
embeddings_model: "model_name",
|
|
280
|
+
summarization_model: "gpt-4",
|
|
281
|
+
docs_generation: false
|
|
282
|
+
};
|
|
283
|
+
await client.datasources.create(codeParams);
|
|
284
|
+
|
|
285
|
+
// Create Confluence Datasource
|
|
286
|
+
const confluenceParams: ConfluenceDataSourceCreateParams = {
|
|
287
|
+
type: DataSourceType.CONFLUENCE,
|
|
288
|
+
name: "confluence_kb",
|
|
289
|
+
project_name: "my_project",
|
|
290
|
+
description: "Confluence space",
|
|
291
|
+
shared_with_project: true,
|
|
292
|
+
setting_id: null,
|
|
293
|
+
cql: "space = 'MYSPACE'",
|
|
294
|
+
include_restricted_content: false,
|
|
295
|
+
include_archived_content: false,
|
|
296
|
+
include_attachments: true,
|
|
297
|
+
include_comments: true,
|
|
298
|
+
keep_markdown_format: true,
|
|
299
|
+
keep_newlines: true
|
|
300
|
+
};
|
|
301
|
+
await client.datasources.create(confluenceParams);
|
|
302
|
+
|
|
303
|
+
// Create Jira Datasource
|
|
304
|
+
const jiraParams: JiraDataSourceCreateParams = {
|
|
305
|
+
type: DataSourceType.JIRA,
|
|
306
|
+
name: "jira_kb",
|
|
307
|
+
project_name: "my_project",
|
|
308
|
+
description: "Jira project",
|
|
309
|
+
shared_with_project: true,
|
|
310
|
+
setting_id: null,
|
|
311
|
+
jql: "project = 'MYPROJECT'"
|
|
312
|
+
};
|
|
313
|
+
await client.datasources.create(jiraParams);
|
|
314
|
+
|
|
315
|
+
// Create Google Doc Datasource
|
|
316
|
+
const googleParams: GoogleDataSourceCreateParams = {
|
|
317
|
+
type: DataSourceType.GOOGLE,
|
|
318
|
+
name: "google_doc",
|
|
319
|
+
project_name: "my_project",
|
|
320
|
+
description: "Google document",
|
|
321
|
+
shared_with_project: true,
|
|
322
|
+
setting_id: null,
|
|
323
|
+
google_doc: "document_url"
|
|
324
|
+
};
|
|
325
|
+
await client.datasources.create(googleParams);
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
2. **Update Datasource**
|
|
329
|
+
```typescript
|
|
330
|
+
// Update Code Datasource
|
|
331
|
+
const updateParams: CodeDataSourceUpdateParams = {
|
|
332
|
+
type: DataSourceType.CODE,
|
|
333
|
+
name: "my_repo",
|
|
334
|
+
project_name: "my_project",
|
|
335
|
+
description: "Updated description",
|
|
336
|
+
// Optional parameters
|
|
337
|
+
shared_with_project: true,
|
|
338
|
+
link: "https://github.com/user/repo",
|
|
339
|
+
branch: "develop",
|
|
340
|
+
index_type: CodeDataSourceType.CODE,
|
|
341
|
+
full_reindex: true,
|
|
342
|
+
skip_reindex: false,
|
|
343
|
+
resume_indexing: false,
|
|
344
|
+
incremental_reindex: false
|
|
345
|
+
};
|
|
346
|
+
const response = await client.datasources.update("datasource_id", updateParams);
|
|
347
|
+
|
|
348
|
+
// Update Confluence Datasource
|
|
349
|
+
const confluenceUpdateParams: ConfluenceDataSourceUpdateParams = {
|
|
350
|
+
type: DataSourceType.CONFLUENCE,
|
|
351
|
+
name: "confluence_kb",
|
|
352
|
+
project_name: "my_project",
|
|
353
|
+
description: "Updated description",
|
|
354
|
+
cql: "space = 'UPDATED_SPACE'",
|
|
355
|
+
full_reindex: true
|
|
356
|
+
};
|
|
357
|
+
const response = await client.datasources.update("datasource_id", confluenceUpdateParams);
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
3. **List Datasources**
|
|
361
|
+
```typescript
|
|
362
|
+
import { DataSourceType, DataSourceStatus, SortOrder } from 'codemie-sdk';
|
|
363
|
+
|
|
364
|
+
// List all datasources with filtering and pagination
|
|
365
|
+
const params: DataSourceListParams = {
|
|
366
|
+
page: 0,
|
|
367
|
+
per_page: 10,
|
|
368
|
+
sort_key: "update_date", // or "date"
|
|
369
|
+
sort_order: SortOrder.DESC, // or SortOrder.ASC
|
|
370
|
+
datasource_types: [DataSourceType.CODE, DataSourceType.CONFLUENCE],
|
|
371
|
+
projects: ["project1", "project2"],
|
|
372
|
+
owner: "John Doe",
|
|
373
|
+
status: DataSourceStatus.COMPLETED
|
|
374
|
+
};
|
|
375
|
+
const datasources = await client.datasources.list(params);
|
|
376
|
+
|
|
377
|
+
// Filter by multiple statuses
|
|
378
|
+
const inProgressAndFailed = await client.datasources.list({
|
|
379
|
+
datasource_types: [DataSourceType.JIRA],
|
|
380
|
+
status: [DataSourceStatus.IN_PROGRESS, DataSourceStatus.FAILED]
|
|
381
|
+
});
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
4. **Get Datasource Details**
|
|
385
|
+
```typescript
|
|
386
|
+
// Get single datasource by ID
|
|
387
|
+
const datasource = await client.datasources.get("datasource_id");
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
5. **Delete Datasource**
|
|
391
|
+
```typescript
|
|
392
|
+
// Delete datasource by ID
|
|
393
|
+
const result = await client.datasources.delete("datasource_id");
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
#### Datasource Status
|
|
397
|
+
|
|
398
|
+
```typescript
|
|
399
|
+
import { DataSourceStatus } from 'codemie-sdk';
|
|
400
|
+
|
|
401
|
+
// Available status constants
|
|
402
|
+
const statuses = {
|
|
403
|
+
COMPLETED: DataSourceStatus.COMPLETED, // Indexing completed successfully
|
|
404
|
+
FAILED: DataSourceStatus.FAILED, // Indexing failed
|
|
405
|
+
FETCHING: DataSourceStatus.FETCHING, // Fetching data from source
|
|
406
|
+
IN_PROGRESS: DataSourceStatus.IN_PROGRESS // Processing/indexing in progress
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
// Example: Check datasource status
|
|
410
|
+
const datasource = await client.datasources.get("datasource_id");
|
|
411
|
+
if (datasource.status === DataSourceStatus.COMPLETED) {
|
|
412
|
+
console.log("Datasource is ready to use");
|
|
413
|
+
} else if (datasource.status === DataSourceStatus.FAILED) {
|
|
414
|
+
console.log("Datasource indexing failed:", datasource.error_message);
|
|
415
|
+
}
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
#### Best Practices for Datasources
|
|
419
|
+
|
|
420
|
+
1. **Naming Convention**:
|
|
421
|
+
- Use lowercase letters and underscores for datasource names
|
|
422
|
+
- Keep names descriptive but concise
|
|
423
|
+
|
|
424
|
+
2. **Performance Optimization**:
|
|
425
|
+
- Use appropriate filters when listing datasources
|
|
426
|
+
- Consider pagination for large result sets
|
|
427
|
+
- Choose appropriate reindex options based on your needs
|
|
428
|
+
|
|
429
|
+
3. **Error Handling**:
|
|
430
|
+
- Always check datasource status after creation/update
|
|
431
|
+
- Handle potential failures gracefully
|
|
432
|
+
- Monitor processing information for issues
|
|
433
|
+
|
|
434
|
+
4. **Security**:
|
|
435
|
+
- Be careful with sensitive data in filters and queries
|
|
436
|
+
- Use proper access controls when sharing datasources
|
|
437
|
+
- Regularly review and clean up unused datasources
|
|
438
|
+
|
|
439
|
+
### Integration Service
|
|
440
|
+
|
|
441
|
+
The Integration service manages both user and project-level integrations in CodeMie, allowing you to configure and manage various integration settings.
|
|
442
|
+
|
|
443
|
+
#### Integration Types
|
|
444
|
+
|
|
445
|
+
- `USER`: User-level integrations
|
|
446
|
+
- `PROJECT`: Project-level integrations
|
|
447
|
+
|
|
448
|
+
#### Core Methods
|
|
449
|
+
|
|
450
|
+
1. **List Integrations**
|
|
451
|
+
```typescript
|
|
452
|
+
import { IntegrationType } from 'codemie-sdk';
|
|
453
|
+
|
|
454
|
+
// List user integrations with pagination
|
|
455
|
+
const params: IntegrationListParams = {
|
|
456
|
+
setting_type: IntegrationType.USER,
|
|
457
|
+
page: 0,
|
|
458
|
+
per_page: 10,
|
|
459
|
+
filters: { status: "active" } // optional filters
|
|
460
|
+
};
|
|
461
|
+
const userIntegrations = await client.integrations.list(params);
|
|
462
|
+
|
|
463
|
+
// List project integrations
|
|
464
|
+
const projectParams: IntegrationListParams = {
|
|
465
|
+
setting_type: IntegrationType.PROJECT,
|
|
466
|
+
per_page: 100
|
|
467
|
+
};
|
|
468
|
+
const projectIntegrations = await client.integrations.list(projectParams);
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
2. **Get Integration**
|
|
472
|
+
```typescript
|
|
473
|
+
// Get integration by ID
|
|
474
|
+
const integration = await client.integrations.get(
|
|
475
|
+
"integration_id",
|
|
476
|
+
IntegrationType.USER
|
|
477
|
+
);
|
|
478
|
+
|
|
479
|
+
// Get integration by alias
|
|
480
|
+
const integration = await client.integrations.getByAlias(
|
|
481
|
+
"integration_alias",
|
|
482
|
+
IntegrationType.PROJECT
|
|
483
|
+
);
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
3. **Create Integration**
|
|
487
|
+
```typescript
|
|
488
|
+
const params: IntegrationCreateParams = {
|
|
489
|
+
setting_type: IntegrationType.USER,
|
|
490
|
+
project_name: "my_project",
|
|
491
|
+
credential_type: CredentialTypes.JIRA,
|
|
492
|
+
credential_values: [
|
|
493
|
+
{ key: "url", value: "https://jira.example.com" },
|
|
494
|
+
{ key: "username", value: "user@example.com" },
|
|
495
|
+
{ key: "token", value: "api-token" }
|
|
496
|
+
],
|
|
497
|
+
alias: "my_integration",
|
|
498
|
+
default: false
|
|
499
|
+
};
|
|
500
|
+
await client.integrations.create(params);
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
4. **Update Integration**
|
|
504
|
+
```typescript
|
|
505
|
+
const params: IntegrationUpdateParams = {
|
|
506
|
+
setting_type: IntegrationType.USER,
|
|
507
|
+
project_name: "my_project",
|
|
508
|
+
credential_type: CredentialTypes.JIRA,
|
|
509
|
+
credential_values: [
|
|
510
|
+
{ key: "url", value: "https://jira.example.com" },
|
|
511
|
+
{ key: "username", value: "updated@example.com" },
|
|
512
|
+
{ key: "token", value: "new-api-token" }
|
|
513
|
+
],
|
|
514
|
+
alias: "updated_integration"
|
|
515
|
+
};
|
|
516
|
+
await client.integrations.update("integration_id", params);
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
5. **Delete Integration**
|
|
520
|
+
```typescript
|
|
521
|
+
await client.integrations.delete(
|
|
522
|
+
"integration_id",
|
|
523
|
+
IntegrationType.USER
|
|
524
|
+
);
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
#### Best Practices for Integrations
|
|
528
|
+
|
|
529
|
+
1. **Error Handling**:
|
|
530
|
+
- Handle `NotFoundError` when getting integrations by ID or alias
|
|
531
|
+
- Validate integration settings before creation/update
|
|
532
|
+
- Use appropriate setting type (USER/PROJECT) based on context
|
|
533
|
+
|
|
534
|
+
2. **Performance**:
|
|
535
|
+
- Use pagination for listing integrations
|
|
536
|
+
- Cache frequently accessed integrations when appropriate
|
|
537
|
+
- Use filters to reduce result set size
|
|
538
|
+
|
|
539
|
+
3. **Security**:
|
|
540
|
+
- Keep integration credentials secure
|
|
541
|
+
- Regularly review and update integration settings
|
|
542
|
+
- Use project-level integrations for team-wide settings
|
|
543
|
+
- Use user-level integrations for personal settings
|
|
544
|
+
|
|
545
|
+
### Workflow Service
|
|
546
|
+
|
|
547
|
+
The Workflow service enables you to create, manage, and execute workflows in CodeMie. Workflows allow you to automate complex processes and integrate various CodeMie services.
|
|
548
|
+
|
|
549
|
+
#### Core Methods
|
|
550
|
+
|
|
551
|
+
1. **Create Workflow**
|
|
552
|
+
```typescript
|
|
553
|
+
// Create new workflow
|
|
554
|
+
const workflowParams = {
|
|
555
|
+
name: "My Workflow",
|
|
556
|
+
description: "Workflow description",
|
|
557
|
+
project: "project-id",
|
|
558
|
+
yamlConfig: "your-yaml-configuration",
|
|
559
|
+
mode: "SEQUENTIAL", // Optional, defaults to SEQUENTIAL
|
|
560
|
+
shared: false, // Optional, defaults to false
|
|
561
|
+
iconUrl: "https://example.com/icon.png" // Optional
|
|
562
|
+
};
|
|
563
|
+
const result = await client.workflows.createWorkflow(workflowParams);
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
2. **Update Workflow**
|
|
567
|
+
```typescript
|
|
568
|
+
// Update existing workflow
|
|
569
|
+
const updateParams = {
|
|
570
|
+
name: "Updated Workflow",
|
|
571
|
+
description: "Updated description",
|
|
572
|
+
yamlConfig: "updated-yaml-config",
|
|
573
|
+
mode: "PARALLEL",
|
|
574
|
+
shared: false
|
|
575
|
+
};
|
|
576
|
+
const result = await client.workflows.update("workflow-id", updateParams);
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
3. **List Workflows**
|
|
580
|
+
```typescript
|
|
581
|
+
// List workflows with pagination and filtering
|
|
582
|
+
const workflows = await client.workflows.list({
|
|
583
|
+
page: 0,
|
|
584
|
+
perPage: 10,
|
|
585
|
+
projects: ["project1", "project2"] // Optional project filter
|
|
586
|
+
});
|
|
587
|
+
```
|
|
588
|
+
|
|
589
|
+
4. **Get Workflow Details**
|
|
590
|
+
```typescript
|
|
591
|
+
// Get workflow by ID
|
|
592
|
+
const workflow = await client.workflows.get("workflow-id");
|
|
593
|
+
|
|
594
|
+
// Get prebuilt workflows
|
|
595
|
+
const prebuiltWorkflows = await client.workflows.getPrebuilt();
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
5. **Delete Workflow**
|
|
599
|
+
```typescript
|
|
600
|
+
const result = await client.workflows.delete("workflow-id");
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
#### Workflow Execution
|
|
604
|
+
|
|
605
|
+
The SDK provides comprehensive workflow execution management through the WorkflowExecutionService:
|
|
606
|
+
|
|
607
|
+
1. **Run Workflow**
|
|
608
|
+
```typescript
|
|
609
|
+
// Simple workflow execution
|
|
610
|
+
const execution = await client.workflows.run("workflow-id", {userInput: "optional input"});
|
|
611
|
+
|
|
612
|
+
// Get execution service for advanced operations
|
|
613
|
+
const executionService = client.workflows.executions("workflow-id");
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
2. **Manage Executions**
|
|
617
|
+
```typescript
|
|
618
|
+
// List workflow executions
|
|
619
|
+
const executions = await executionService.list({
|
|
620
|
+
page: 0,
|
|
621
|
+
perPage: 10
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
// Get execution details
|
|
625
|
+
const execution = await executionService.get("execution-id");
|
|
626
|
+
|
|
627
|
+
// Abort running execution
|
|
628
|
+
const result = await executionService.abort("execution-id");
|
|
629
|
+
|
|
630
|
+
// Resume interrupted execution
|
|
631
|
+
const result = await executionService.resume("execution-id");
|
|
632
|
+
|
|
633
|
+
// Delete all executions
|
|
634
|
+
const result = await executionService.deleteAll();
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
3. **Work with Execution States**
|
|
638
|
+
```typescript
|
|
639
|
+
// Get execution states
|
|
640
|
+
const states = await executionService.states("execution-id").list();
|
|
641
|
+
|
|
642
|
+
// Get state output
|
|
643
|
+
const stateOutput = await executionService.states("execution-id").getOutput("state-id");
|
|
644
|
+
|
|
645
|
+
// Example of monitoring workflow with state verification
|
|
646
|
+
async function verifyWorkflowExecution(executionService, executionId) {
|
|
647
|
+
const execution = await executionService.get(executionId);
|
|
648
|
+
|
|
649
|
+
if (execution.status === "SUCCEEDED") {
|
|
650
|
+
// Get and verify states
|
|
651
|
+
const states = await executionService.states(executionId).list();
|
|
652
|
+
|
|
653
|
+
// States are ordered by completion date
|
|
654
|
+
if (states.length >= 2) {
|
|
655
|
+
console.log("Workflow completed successfully with multiple states");
|
|
656
|
+
}
|
|
657
|
+
} else if (execution.status === "FAILED") {
|
|
658
|
+
console.log(`Workflow failed: ${execution.errorMessage}`);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
#### Workflow Configuration
|
|
664
|
+
|
|
665
|
+
Workflows support various configuration options:
|
|
666
|
+
|
|
667
|
+
1. **Modes**:
|
|
668
|
+
- `SEQUENTIAL`: Tasks execute in sequence
|
|
669
|
+
- `PARALLEL`: Tasks can execute simultaneously
|
|
670
|
+
|
|
671
|
+
2. **YAML Configuration**:
|
|
672
|
+
```yaml
|
|
673
|
+
name: Example Workflow
|
|
674
|
+
description: Workflow description
|
|
675
|
+
tasks:
|
|
676
|
+
- name: task1
|
|
677
|
+
type: llm
|
|
678
|
+
config:
|
|
679
|
+
prompt: "Your prompt here"
|
|
680
|
+
model: "gpt-4o"
|
|
681
|
+
|
|
682
|
+
- name: task2
|
|
683
|
+
type: tool
|
|
684
|
+
config:
|
|
685
|
+
tool_name: "your-tool"
|
|
686
|
+
parameters:
|
|
687
|
+
param1: "value1"
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
#### Best Practices
|
|
691
|
+
|
|
692
|
+
1. **Workflow Design**:
|
|
693
|
+
- Keep workflows modular and focused
|
|
694
|
+
- Use clear, descriptive names for workflows and tasks
|
|
695
|
+
- Document workflow purpose and requirements
|
|
696
|
+
- Test workflows thoroughly before deployment
|
|
697
|
+
|
|
698
|
+
2. **Execution Management**:
|
|
699
|
+
- Monitor long-running workflows
|
|
700
|
+
- Implement proper error handling
|
|
701
|
+
- Use pagination for listing executions
|
|
702
|
+
- Clean up completed executions regularly
|
|
703
|
+
|
|
704
|
+
3. **Performance Optimization**:
|
|
705
|
+
- Choose appropriate workflow mode (SEQUENTIAL/PARALLEL)
|
|
706
|
+
- Manage resource usage in parallel workflows
|
|
707
|
+
- Consider task dependencies and ordering
|
|
708
|
+
- Use efficient task configurations
|
|
709
|
+
|
|
710
|
+
4. **Security**:
|
|
711
|
+
- Control workflow sharing carefully
|
|
712
|
+
- Validate user inputs
|
|
713
|
+
- Manage sensitive data appropriately
|
|
714
|
+
- Regular audit of workflow access
|
|
715
|
+
|
|
716
|
+
5. **Maintenance**:
|
|
717
|
+
- Regular review of workflow configurations
|
|
718
|
+
- Update workflows when dependencies change
|
|
719
|
+
- Monitor workflow performance
|
|
720
|
+
- Archive or remove unused workflows
|
|
721
|
+
|
|
722
|
+
### Real World Examples
|
|
723
|
+
|
|
724
|
+
This section provides practical examples of common use cases and complex workflows using the CodeMie SDK.
|
|
725
|
+
|
|
726
|
+
#### Setting Up an AI Assistant with Jira Integration
|
|
727
|
+
|
|
728
|
+
This example demonstrates setting up a complete workflow with Jira integration and AI assistant creation:
|
|
729
|
+
|
|
730
|
+
```typescript
|
|
731
|
+
import {
|
|
732
|
+
CodeMieClient,
|
|
733
|
+
AssistantCreateParams,
|
|
734
|
+
DataSourceCreateParams,
|
|
735
|
+
CredentialTypes,
|
|
736
|
+
IntegrationType,
|
|
737
|
+
DataSourceType,
|
|
738
|
+
ContextType
|
|
739
|
+
} from 'codemie-sdk';
|
|
740
|
+
|
|
741
|
+
async function setupAssistantWithJira() {
|
|
742
|
+
const client = new CodeMieClient({/* auth config */});
|
|
743
|
+
await client.initialize();
|
|
744
|
+
|
|
745
|
+
// 1. Create Jira Integration
|
|
746
|
+
const jiraIntegration = await client.integrations.create({
|
|
747
|
+
project_name: "your_project",
|
|
748
|
+
credential_type: CredentialTypes.JIRA,
|
|
749
|
+
credential_values: [
|
|
750
|
+
{ key: "url", value: "https://your-jira.atlassian.net" },
|
|
751
|
+
{ key: "username", value: "your-email@example.com" },
|
|
752
|
+
{ key: "token", value: "your-api-token" }
|
|
753
|
+
],
|
|
754
|
+
alias: "jira_integration",
|
|
755
|
+
setting_type: IntegrationType.USER
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
// 2. Create Jira Datasource
|
|
759
|
+
const datasource = await client.datasources.create({
|
|
760
|
+
name: "jira_knowledge_base",
|
|
761
|
+
project_name: "your_project",
|
|
762
|
+
description: "Jira project knowledge base",
|
|
763
|
+
setting_id: jiraIntegration.id,
|
|
764
|
+
type: DataSourceType.JIRA,
|
|
765
|
+
project_space_visible: true,
|
|
766
|
+
jql: "project = 'YOUR-PROJECT'"
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
// 3. Create AI Assistant with Jira Context
|
|
770
|
+
const assistant = await client.assistants.create({
|
|
771
|
+
name: "Jira Helper Assistant",
|
|
772
|
+
description: "Assistant for Jira queries",
|
|
773
|
+
system_prompt: "You are a helpful assistant with access to Jira data",
|
|
774
|
+
llm_model_type: "gpt-4",
|
|
775
|
+
project: "your_project",
|
|
776
|
+
context: [{
|
|
777
|
+
name: datasource.name,
|
|
778
|
+
context_type: ContextType.CODE
|
|
779
|
+
}],
|
|
780
|
+
toolkits: [
|
|
781
|
+
{
|
|
782
|
+
toolkit: "jira",
|
|
783
|
+
tools: [
|
|
784
|
+
{ name: "search_issues" },
|
|
785
|
+
{ name: "create_issue" }
|
|
786
|
+
]
|
|
787
|
+
}
|
|
788
|
+
]
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
return assistant;
|
|
792
|
+
}
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
#### Managing Workflows
|
|
796
|
+
|
|
797
|
+
Example of creating and executing a workflow:
|
|
798
|
+
|
|
799
|
+
```typescript
|
|
800
|
+
async function manageWorkflow() {
|
|
801
|
+
const client = new CodeMieClient({/* auth config */});
|
|
802
|
+
await client.initialize();
|
|
803
|
+
|
|
804
|
+
// Create workflow
|
|
805
|
+
const workflow = await client.workflows.create({
|
|
806
|
+
name: "Document Processing",
|
|
807
|
+
description: "Process and analyze documents",
|
|
808
|
+
project: "your_project",
|
|
809
|
+
mode: "SEQUENTIAL",
|
|
810
|
+
yamlConfig: `
|
|
811
|
+
name: Document Processing
|
|
812
|
+
description: Process and analyze documents
|
|
813
|
+
tasks:
|
|
814
|
+
- name: analyze_document
|
|
815
|
+
type: llm
|
|
816
|
+
config:
|
|
817
|
+
prompt: "Analyze the following document:"
|
|
818
|
+
model: "gpt-4"
|
|
819
|
+
|
|
820
|
+
- name: create_summary
|
|
821
|
+
type: tool
|
|
822
|
+
config:
|
|
823
|
+
tool_name: "document_summarizer"
|
|
824
|
+
parameters:
|
|
825
|
+
format: "markdown"
|
|
826
|
+
max_length: 500
|
|
827
|
+
`
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
// Execute workflow
|
|
831
|
+
const execution = await client.workflows.run(workflow.id, {
|
|
832
|
+
userInput: "Document content here"
|
|
833
|
+
});
|
|
834
|
+
|
|
835
|
+
// Monitor execution
|
|
836
|
+
const executionService = client.workflows.executions(workflow.id);
|
|
837
|
+
const states = await executionService.states(execution.id).list();
|
|
838
|
+
|
|
839
|
+
// Get execution results
|
|
840
|
+
const stateOutput = await executionService.states(execution.id)
|
|
841
|
+
.getOutput(states[states.length - 1].id);
|
|
842
|
+
|
|
843
|
+
return stateOutput;
|
|
844
|
+
}
|
|
845
|
+
```
|
|
846
|
+
|
|
847
|
+
### Error Handling Best Practices
|
|
848
|
+
|
|
849
|
+
Example of proper error handling in a complex operation:
|
|
850
|
+
|
|
851
|
+
```typescript
|
|
852
|
+
import { CodeMieError, ApiError, NotFoundError } from 'codemie-sdk';
|
|
853
|
+
|
|
854
|
+
async function robustOperation() {
|
|
855
|
+
const client = new CodeMieClient({/* auth config */});
|
|
856
|
+
|
|
857
|
+
try {
|
|
858
|
+
await client.initialize();
|
|
859
|
+
|
|
860
|
+
// Attempt to get or create assistant
|
|
861
|
+
try {
|
|
862
|
+
const assistant = await client.assistants.getBySlug("my-assistant");
|
|
863
|
+
return assistant;
|
|
864
|
+
} catch (error) {
|
|
865
|
+
if (error instanceof NotFoundError) {
|
|
866
|
+
// Assistant doesn't exist, create new one
|
|
867
|
+
return await client.assistants.create({
|
|
868
|
+
name: "My Assistant",
|
|
869
|
+
slug: "my-assistant",
|
|
870
|
+
// ... other configuration
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
throw error; // Re-throw if it's not a NotFoundError
|
|
874
|
+
}
|
|
875
|
+
} catch (error) {
|
|
876
|
+
if (error instanceof ApiError) {
|
|
877
|
+
console.error(`API Error: ${error.message}`, {
|
|
878
|
+
statusCode: error.statusCode,
|
|
879
|
+
details: error.details
|
|
880
|
+
});
|
|
881
|
+
} else if (error instanceof CodeMieError) {
|
|
882
|
+
console.error(`SDK Error: ${error.message}`);
|
|
883
|
+
} else {
|
|
884
|
+
console.error(`Unexpected error: ${error}`);
|
|
885
|
+
}
|
|
886
|
+
throw error;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
## Error Handling
|
|
892
|
+
|
|
893
|
+
Implement proper error handling for workflow operations:
|
|
894
|
+
|
|
895
|
+
```typescript
|
|
896
|
+
try {
|
|
897
|
+
const workflow = await client.workflows.get("workflow-id");
|
|
898
|
+
} catch (error) {
|
|
899
|
+
if (error.statusCode === 404) {
|
|
900
|
+
console.log("Workflow not found");
|
|
901
|
+
} else {
|
|
902
|
+
console.log(`API error: ${error.message}`);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
```
|
|
906
|
+
|
|
907
|
+
#### Workflow Status Monitoring
|
|
908
|
+
|
|
909
|
+
Monitor workflow execution status:
|
|
910
|
+
|
|
911
|
+
```typescript
|
|
912
|
+
async function monitorExecution(executionService, executionId) {
|
|
913
|
+
while (true) {
|
|
914
|
+
const execution = await executionService.get(executionId);
|
|
915
|
+
const status = execution.status;
|
|
916
|
+
|
|
917
|
+
if (status === "COMPLETED") {
|
|
918
|
+
console.log("Workflow completed successfully");
|
|
919
|
+
break;
|
|
920
|
+
} else if (status === "FAILED") {
|
|
921
|
+
console.log(`Workflow failed: ${execution.error}`);
|
|
922
|
+
break;
|
|
923
|
+
} else if (status === "ABORTED") {
|
|
924
|
+
console.log("Workflow was aborted");
|
|
925
|
+
break;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
await new Promise(resolve => setTimeout(resolve, 5000)); // Poll every 5 seconds
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
```
|
|
932
|
+
|
|
933
|
+
## Error Handling
|
|
934
|
+
|
|
935
|
+
The SDK throws typed errors that you can catch and handle:
|
|
936
|
+
|
|
937
|
+
```typescript
|
|
938
|
+
import { CodeMieError, ApiError, NotFoundError } from 'codemie-sdk';
|
|
939
|
+
|
|
940
|
+
try {
|
|
941
|
+
await client.assistants.get('non-existent-id');
|
|
942
|
+
} catch (error) {
|
|
943
|
+
if (error instanceof NotFoundError) {
|
|
944
|
+
console.log('Assistant not found');
|
|
945
|
+
} else if (error instanceof ApiError) {
|
|
946
|
+
console.log('API error:', error.message, error.statusCode);
|
|
947
|
+
} else if (error instanceof CodeMieError) {
|
|
948
|
+
console.log('SDK error:', error.message);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
```
|
|
952
|
+
|
|
953
|
+
## TypeScript Support
|
|
954
|
+
|
|
955
|
+
The SDK is written in TypeScript and provides full type definitions. All interfaces and types are exported for use in your TypeScript projects.
|
|
956
|
+
|
|
957
|
+
```typescript
|
|
958
|
+
import type {
|
|
959
|
+
Assistant,
|
|
960
|
+
AssistantCreateParams,
|
|
961
|
+
AssistantChatParams,
|
|
962
|
+
ToolKitDetails
|
|
963
|
+
} from 'codemie-sdk';
|
|
964
|
+
```
|
|
965
|
+
|
|
966
|
+
## Development
|
|
967
|
+
|
|
968
|
+
### Pack and Publish
|
|
969
|
+
|
|
970
|
+
To build the SDK locally:
|
|
971
|
+
|
|
972
|
+
```bash
|
|
973
|
+
npm install
|
|
974
|
+
npm run build
|
|
975
|
+
```
|
|
976
|
+
|
|
977
|
+
To publish the SDK to npm, ensure you have the correct version in `package.json`, then run:
|
|
978
|
+
|
|
979
|
+
```bash
|
|
980
|
+
npm run build && npm publish --access=public
|
|
981
|
+
```
|
|
982
|
+
|
|
983
|
+
### Unit Tests
|
|
984
|
+
|
|
985
|
+
To run unit tests simply execute:
|
|
986
|
+
|
|
987
|
+
```bash
|
|
988
|
+
npm run test
|
|
989
|
+
```
|
|
990
|
+
|
|
991
|
+
### E2E Tests
|
|
992
|
+
|
|
993
|
+
To run end-to-end tests, ensure you have the necessary environment variables set up for authentication and API endpoints:
|
|
994
|
+
|
|
995
|
+
```bash
|
|
996
|
+
cp .env.e2e.example .env.e2e
|
|
997
|
+
```
|
|
998
|
+
|
|
999
|
+
Update the `.env.e2e` file with your credentials and API endpoints.
|
|
1000
|
+
|
|
1001
|
+
Then run the tests:
|
|
1002
|
+
|
|
1003
|
+
```bash
|
|
1004
|
+
npm run test:e2e
|
|
1005
|
+
```
|
|
1006
|
+
|
|
1007
|
+
## Support
|
|
1008
|
+
For providing credentials please contact AI/Run CodeMie Team: Vadym_Vlasenko@epam.com or Nikita_Levyankov@epam.com
|