@kaiban/sdk 0.1.8 → 0.2.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.
- package/README.md +142 -19
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/lib/client.js +54 -0
- package/dist/cjs/lib/http/HttpClient.js +243 -0
- package/dist/cjs/lib/http/errors.js +143 -0
- package/dist/cjs/lib/http/types.js +2 -0
- package/dist/cjs/lib/resources/ActivitiesClient.js +164 -0
- package/dist/cjs/lib/resources/AgentsClient.js +196 -0
- package/dist/cjs/lib/resources/BoardsClient.js +78 -0
- package/dist/cjs/lib/resources/CardsClient.js +352 -0
- package/dist/cjs/lib/resources/ExternalChannelsClient.js +78 -0
- package/dist/cjs/lib/resources/ModelCost.js +87 -0
- package/dist/cjs/lib/resources/ResourcesClient.js +78 -0
- package/dist/cjs/lib/resources/TeamsClient.js +96 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/test/helpers/mockFetch.js +27 -0
- package/dist/cjs/types/entities/a2a-dataparts.js +17 -0
- package/dist/cjs/types/entities/activities.js +76 -0
- package/dist/cjs/types/entities/agent.js +28 -0
- package/dist/cjs/types/entities/board.js +2 -0
- package/dist/cjs/types/entities/card.js +29 -0
- package/dist/cjs/types/entities/costs.js +2 -0
- package/dist/cjs/types/entities/external-channel.js +19 -0
- package/dist/cjs/types/entities/index.js +25 -0
- package/dist/cjs/types/entities/resource.js +10 -0
- package/dist/cjs/types/entities/shared.js +3 -0
- package/dist/cjs/types/entities/team.js +2 -0
- package/dist/cjs/types/entities.js +17 -0
- package/dist/cjs/types/responses.js +2 -0
- package/dist/esm/index.js +5 -0
- package/dist/{lib → esm/lib}/client.js +9 -9
- package/dist/{lib → esm/lib}/http/HttpClient.js +1 -1
- package/dist/{lib → esm/lib}/resources/CardsClient.js +1 -1
- package/dist/esm/types/entities/a2a-dataparts.js +14 -0
- package/dist/esm/types/entities/index.js +9 -0
- package/dist/esm/types/entities.js +1 -0
- package/dist/esm/types/requests.js +19 -0
- package/dist/types/types/entities/a2a-dataparts.d.ts +202 -0
- package/package.json +16 -7
- package/dist/index.js +0 -5
- package/dist/types/entities/a2a-dataparts.d.ts +0 -11
- package/dist/types/entities/a2a-dataparts.js +0 -3
- package/dist/types/entities/index.js +0 -9
- package/dist/types/entities.js +0 -1
- /package/dist/{types → cjs/types}/requests.js +0 -0
- /package/dist/{lib → esm/lib}/http/errors.js +0 -0
- /package/dist/{lib → esm/lib}/http/types.js +0 -0
- /package/dist/{lib → esm/lib}/resources/ActivitiesClient.js +0 -0
- /package/dist/{lib → esm/lib}/resources/AgentsClient.js +0 -0
- /package/dist/{lib → esm/lib}/resources/BoardsClient.js +0 -0
- /package/dist/{lib → esm/lib}/resources/ExternalChannelsClient.js +0 -0
- /package/dist/{lib → esm/lib}/resources/ModelCost.js +0 -0
- /package/dist/{lib → esm/lib}/resources/ResourcesClient.js +0 -0
- /package/dist/{lib → esm/lib}/resources/TeamsClient.js +0 -0
- /package/dist/{test → esm/test}/helpers/mockFetch.js +0 -0
- /package/dist/{types → esm/types}/entities/activities.js +0 -0
- /package/dist/{types → esm/types}/entities/agent.js +0 -0
- /package/dist/{types → esm/types}/entities/board.js +0 -0
- /package/dist/{types → esm/types}/entities/card.js +0 -0
- /package/dist/{types → esm/types}/entities/costs.js +0 -0
- /package/dist/{types → esm/types}/entities/external-channel.js +0 -0
- /package/dist/{types → esm/types}/entities/resource.js +0 -0
- /package/dist/{types → esm/types}/entities/shared.js +0 -0
- /package/dist/{types → esm/types}/entities/team.js +0 -0
- /package/dist/{types → esm/types}/responses.js +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{lib → types/lib}/client.d.ts +0 -0
- /package/dist/{lib → types/lib}/http/HttpClient.d.ts +0 -0
- /package/dist/{lib → types/lib}/http/errors.d.ts +0 -0
- /package/dist/{lib → types/lib}/http/types.d.ts +0 -0
- /package/dist/{lib → types/lib}/resources/ActivitiesClient.d.ts +0 -0
- /package/dist/{lib → types/lib}/resources/AgentsClient.d.ts +0 -0
- /package/dist/{lib → types/lib}/resources/BoardsClient.d.ts +0 -0
- /package/dist/{lib → types/lib}/resources/CardsClient.d.ts +0 -0
- /package/dist/{lib → types/lib}/resources/ExternalChannelsClient.d.ts +0 -0
- /package/dist/{lib → types/lib}/resources/ModelCost.d.ts +0 -0
- /package/dist/{lib → types/lib}/resources/ResourcesClient.d.ts +0 -0
- /package/dist/{lib → types/lib}/resources/TeamsClient.d.ts +0 -0
- /package/dist/{test → types/test}/helpers/mockFetch.d.ts +0 -0
- /package/dist/types/{entities → types/entities}/activities.d.ts +0 -0
- /package/dist/types/{entities → types/entities}/agent.d.ts +0 -0
- /package/dist/types/{entities → types/entities}/board.d.ts +0 -0
- /package/dist/types/{entities → types/entities}/card.d.ts +0 -0
- /package/dist/types/{entities → types/entities}/costs.d.ts +0 -0
- /package/dist/types/{entities → types/entities}/external-channel.d.ts +0 -0
- /package/dist/types/{entities → types/entities}/index.d.ts +0 -0
- /package/dist/types/{entities → types/entities}/resource.d.ts +0 -0
- /package/dist/types/{entities → types/entities}/shared.d.ts +0 -0
- /package/dist/types/{entities → types/entities}/team.d.ts +0 -0
- /package/dist/types/{entities.d.ts → types/entities.d.ts} +0 -0
- /package/dist/types/{requests.d.ts → types/requests.d.ts} +0 -0
- /package/dist/types/{responses.d.ts → types/responses.d.ts} +0 -0
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CardsClient = void 0;
|
|
4
|
+
const entities_1 = require("../../types/entities");
|
|
5
|
+
// Minimal create-activity payload aligned to backend activity schema
|
|
6
|
+
// Activity types are shared in entities
|
|
7
|
+
/**
|
|
8
|
+
* Client for managing cards in the Kaiban platform
|
|
9
|
+
* Cards represent work items, tasks, or tickets within boards
|
|
10
|
+
* @category Resources
|
|
11
|
+
*/
|
|
12
|
+
class CardsClient {
|
|
13
|
+
constructor(http) {
|
|
14
|
+
this.http = http;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* List cards with pagination, filters, and sorting
|
|
18
|
+
*
|
|
19
|
+
* @param params - Optional query parameters for filtering and pagination
|
|
20
|
+
* @param params.cursor - Cursor for the next page of results
|
|
21
|
+
* @param params.limit - Number of items per page
|
|
22
|
+
* @param params.order_by - Fields to sort by
|
|
23
|
+
* @param options - Optional request configuration
|
|
24
|
+
*
|
|
25
|
+
* @returns A paginated list of cards
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // List cards with filters
|
|
30
|
+
* const result = await client.cards.list({
|
|
31
|
+
* limit: 20,
|
|
32
|
+
* order_by: ['created_at']
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
list(params, options) {
|
|
37
|
+
return this.http.list('/cards', params, options);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Iterate through all cards using async generator
|
|
41
|
+
* Automatically handles pagination by following next_page_token
|
|
42
|
+
*
|
|
43
|
+
* @param params - Optional query parameters (excluding cursor)
|
|
44
|
+
* @param options - Optional request configuration
|
|
45
|
+
*
|
|
46
|
+
* @yields Individual Card objects
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // Process all cards
|
|
51
|
+
* for await (const card of client.cards.listAll()) {
|
|
52
|
+
* console.log(card.title, card.status);
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
async *listAll(params, options) {
|
|
57
|
+
let cursor = undefined;
|
|
58
|
+
do {
|
|
59
|
+
const page = await this.list({ ...(params || {}), after: cursor }, options);
|
|
60
|
+
for (const item of page.data)
|
|
61
|
+
yield item;
|
|
62
|
+
cursor = page.pagination.next_cursor;
|
|
63
|
+
} while (cursor);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get a single card by ID
|
|
67
|
+
*
|
|
68
|
+
* @param cardId - The unique identifier of the card
|
|
69
|
+
* @param options - Optional request configuration
|
|
70
|
+
*
|
|
71
|
+
* @returns The card object
|
|
72
|
+
*
|
|
73
|
+
* @throws {Error} If the card is not found or request fails
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const card = await client.cards.get('card-123');
|
|
78
|
+
* console.log(card.title, card.description);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
get(cardId, options) {
|
|
82
|
+
return this.http.get(`/card/${encodeURIComponent(cardId)}`, options);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Create a new card with optional activity tracking
|
|
86
|
+
*
|
|
87
|
+
* @param data - Card creation data
|
|
88
|
+
* @param data.title - The card title
|
|
89
|
+
* @param data.board_id - The board this card belongs to
|
|
90
|
+
* @param data.column_key - The column where the card should be placed
|
|
91
|
+
* @param options - Optional request configuration
|
|
92
|
+
* @param options.create_activity - If true, creates a 'card_created' activity
|
|
93
|
+
*
|
|
94
|
+
* @returns The newly created card
|
|
95
|
+
*
|
|
96
|
+
* @throws {Error} If creation fails
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const card = await client.cards.create({
|
|
101
|
+
* title: 'New Task',
|
|
102
|
+
* board_id: 'board-123',
|
|
103
|
+
* team_id: 'team-456',
|
|
104
|
+
* column_key: 'todo',
|
|
105
|
+
* description: 'Task description'
|
|
106
|
+
* }, { create_activity: true });
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
async create(data, options) {
|
|
110
|
+
const card = await this.http.post('/cards', data, options);
|
|
111
|
+
if (options?.create_activity) {
|
|
112
|
+
await this.createActivity(card.id, {
|
|
113
|
+
board_id: card.board_id,
|
|
114
|
+
team_id: card.team_id,
|
|
115
|
+
type: entities_1.ActivityType.CARD_CREATED,
|
|
116
|
+
description: 'Card created',
|
|
117
|
+
actor: { id: 'sdk', type: 'system', name: 'Kaiban SDK' },
|
|
118
|
+
}, options);
|
|
119
|
+
}
|
|
120
|
+
return card;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Update a card's properties
|
|
124
|
+
*
|
|
125
|
+
* @param cardId - The unique identifier of the card to update
|
|
126
|
+
* @param data - Card data with fields to update
|
|
127
|
+
* @param options - Optional request configuration
|
|
128
|
+
*
|
|
129
|
+
* @returns The updated card object
|
|
130
|
+
*
|
|
131
|
+
* @throws {Error} If the card is not found or update fails
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* const updated = await client.cards.update('card-123', {
|
|
136
|
+
* title: 'Updated Title',
|
|
137
|
+
* status: 'in_progress'
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
update(cardId, data, options) {
|
|
142
|
+
return this.http.put(`/card/${encodeURIComponent(cardId)}`, data, options);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Delete a card by ID
|
|
146
|
+
*
|
|
147
|
+
* @param cardId - The unique identifier of the card to delete
|
|
148
|
+
* @param options - Optional request configuration
|
|
149
|
+
*
|
|
150
|
+
* @returns Promise that resolves when the card is deleted
|
|
151
|
+
*
|
|
152
|
+
* @throws {Error} If the card is not found or deletion fails
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* await client.cards.delete('card-123');
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
delete(cardId, options) {
|
|
160
|
+
return this.http.delete(`/card/${encodeURIComponent(cardId)}`, options);
|
|
161
|
+
}
|
|
162
|
+
// Activity operations moved to ActivitiesClient
|
|
163
|
+
/**
|
|
164
|
+
* Move a card to a new column and automatically record the activity
|
|
165
|
+
* This is a convenience method that combines update and activity creation
|
|
166
|
+
*
|
|
167
|
+
* @param cardId - The unique identifier of the card to move
|
|
168
|
+
* @param newColumnKey - The key of the destination column
|
|
169
|
+
* @param options - Optional request configuration
|
|
170
|
+
* @param options.actor - The actor performing the move (defaults to SDK system actor)
|
|
171
|
+
*
|
|
172
|
+
* @returns The updated card object
|
|
173
|
+
*
|
|
174
|
+
* @throws {Error} If the card is not found or move fails
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* // Move card to 'in_progress' column
|
|
179
|
+
* const card = await client.cards.moveToColumn('card-123', 'in_progress', {
|
|
180
|
+
* actor: {
|
|
181
|
+
* id: 'user-456',
|
|
182
|
+
* type: 'user',
|
|
183
|
+
* name: 'John Doe'
|
|
184
|
+
* }
|
|
185
|
+
* });
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
async moveToColumn(cardId, newColumnKey, options) {
|
|
189
|
+
const current = await this.get(cardId, options);
|
|
190
|
+
const oldColumn = current.column_key;
|
|
191
|
+
const updated = await this.update(cardId, { column_key: newColumnKey }, options);
|
|
192
|
+
await this.createActivity(cardId, {
|
|
193
|
+
board_id: updated.board_id,
|
|
194
|
+
team_id: updated.team_id,
|
|
195
|
+
type: entities_1.ActivityType.CARD_COLUMN_CHANGED,
|
|
196
|
+
description: `Moved card from ${oldColumn} to ${newColumnKey}`,
|
|
197
|
+
actor: options?.actor || { id: 'sdk', type: 'system', name: 'Kaiban SDK' },
|
|
198
|
+
changes: [{ field: 'column_key', old_value: oldColumn, new_value: newColumnKey }],
|
|
199
|
+
}, options);
|
|
200
|
+
return updated;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Create a new activity for a card
|
|
204
|
+
* Activities track changes, comments, and events on cards
|
|
205
|
+
*
|
|
206
|
+
* @param cardId - The unique identifier of the card
|
|
207
|
+
* @param data - Activity creation data (card_id is automatically added)
|
|
208
|
+
* @param data.board_id - The board ID
|
|
209
|
+
* @param data.team_id - The team ID
|
|
210
|
+
* @param data.type - The type of activity (e.g., 'card_created', 'card_updated', 'comment')
|
|
211
|
+
* @param data.description - A description of the activity
|
|
212
|
+
* @param data.actor - The actor who performed the activity
|
|
213
|
+
* @param options - Optional request configuration
|
|
214
|
+
*
|
|
215
|
+
* @returns The created activity object
|
|
216
|
+
*
|
|
217
|
+
* @throws {Error} If the card is not found or creation fails
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* const activity = await client.cards.createActivity('card-123', {
|
|
222
|
+
* board_id: 'board-456',
|
|
223
|
+
* team_id: 'team-789',
|
|
224
|
+
* type: 'comment',
|
|
225
|
+
* description: 'Added a comment',
|
|
226
|
+
* actor: {
|
|
227
|
+
* id: 'user-001',
|
|
228
|
+
* type: 'user',
|
|
229
|
+
* name: 'Jane Doe'
|
|
230
|
+
* }
|
|
231
|
+
* });
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
createActivity(cardId, data, options) {
|
|
235
|
+
return this.http.post(`/card/${encodeURIComponent(cardId)}/activities`, {
|
|
236
|
+
...data,
|
|
237
|
+
card_id: cardId,
|
|
238
|
+
}, options);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Create multiple activities for a card in a single batch request
|
|
242
|
+
* This is more efficient than creating activities one by one
|
|
243
|
+
*
|
|
244
|
+
* @param cardId - The unique identifier of the card
|
|
245
|
+
* @param data - Array of activity creation data (card_id is automatically added to each)
|
|
246
|
+
* @param options - Optional request configuration
|
|
247
|
+
*
|
|
248
|
+
* @returns The batch creation result
|
|
249
|
+
*
|
|
250
|
+
* @throws {Error} If the card is not found or batch creation fails
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* const activities = await client.cards.createBatchActivities('card-123', [
|
|
255
|
+
* {
|
|
256
|
+
* board_id: 'board-456',
|
|
257
|
+
* team_id: 'team-789',
|
|
258
|
+
* type: 'comment',
|
|
259
|
+
* description: 'First comment',
|
|
260
|
+
* actor: { id: 'user-001', type: 'user', name: 'Jane Doe' }
|
|
261
|
+
* },
|
|
262
|
+
* {
|
|
263
|
+
* board_id: 'board-456',
|
|
264
|
+
* team_id: 'team-789',
|
|
265
|
+
* type: 'card_updated',
|
|
266
|
+
* description: 'Updated priority',
|
|
267
|
+
* actor: { id: 'user-001', type: 'user', name: 'Jane Doe' }
|
|
268
|
+
* }
|
|
269
|
+
* ]);
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
createBatchActivities(cardId, data, options) {
|
|
273
|
+
return this.http.post(`/activities:batch`, {
|
|
274
|
+
items: data.map((item) => ({
|
|
275
|
+
...item,
|
|
276
|
+
card_id: cardId,
|
|
277
|
+
})),
|
|
278
|
+
}, options);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* List activities for a specific card with pagination, filters, and sorting
|
|
282
|
+
*
|
|
283
|
+
* @param cardId - The unique identifier of the card
|
|
284
|
+
* @param params - Optional query parameters for filtering and pagination
|
|
285
|
+
* @param params.limit - Number of items per page
|
|
286
|
+
* @param params.after - Cursor to navigate forwards
|
|
287
|
+
* @param params.before - Cursor to navigate backwards
|
|
288
|
+
* @param params.order_by - Fields to sort by
|
|
289
|
+
* @param options - Optional request configuration
|
|
290
|
+
*
|
|
291
|
+
* @returns A paginated list of activities
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```typescript
|
|
295
|
+
* // Get first page of activities
|
|
296
|
+
* const result = await client.cards.listActivities('card-123', {
|
|
297
|
+
* limit: 20,
|
|
298
|
+
* order_by: '-created_at'
|
|
299
|
+
* });
|
|
300
|
+
* console.log(result.data); // Array of Activity objects
|
|
301
|
+
*
|
|
302
|
+
* // Get next page
|
|
303
|
+
* if (result.pagination.next_cursor) {
|
|
304
|
+
* const nextPage = await client.cards.listActivities('card-123', {
|
|
305
|
+
* limit: 20,
|
|
306
|
+
* after: result.pagination.next_cursor
|
|
307
|
+
* });
|
|
308
|
+
* }
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
listActivities(cardId, params, options) {
|
|
312
|
+
return this.http.list(`/card/${encodeURIComponent(cardId)}/activities`, params, options);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Iterate through all activities for a card using async generator
|
|
316
|
+
* Automatically handles pagination by following next_cursor
|
|
317
|
+
*
|
|
318
|
+
* @param cardId - The unique identifier of the card
|
|
319
|
+
* @param params - Optional query parameters (excluding after/before cursors)
|
|
320
|
+
* @param params.limit - Number of items per page (used internally for pagination)
|
|
321
|
+
* @param params.order_by - Fields to sort by
|
|
322
|
+
* @param options - Optional request configuration
|
|
323
|
+
*
|
|
324
|
+
* @yields Individual Activity objects
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```typescript
|
|
328
|
+
* // Process all activities for a card
|
|
329
|
+
* for await (const activity of client.cards.listAllActivities('card-123')) {
|
|
330
|
+
* console.log(activity.type, activity.description);
|
|
331
|
+
* }
|
|
332
|
+
*
|
|
333
|
+
* // With custom page size and ordering
|
|
334
|
+
* for await (const activity of client.cards.listAllActivities('card-123', {
|
|
335
|
+
* limit: 100,
|
|
336
|
+
* order_by: '-created_at'
|
|
337
|
+
* })) {
|
|
338
|
+
* console.log(activity);
|
|
339
|
+
* }
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
async *listAllActivities(cardId, params, options) {
|
|
343
|
+
let cursor = undefined;
|
|
344
|
+
do {
|
|
345
|
+
const page = await this.listActivities(cardId, { ...(params || {}), after: cursor }, options);
|
|
346
|
+
for (const item of page.data)
|
|
347
|
+
yield item;
|
|
348
|
+
cursor = page.pagination.next_cursor;
|
|
349
|
+
} while (cursor);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
exports.CardsClient = CardsClient;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExternalChannelsClient = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Client for managing external channels in the Kaiban platform
|
|
6
|
+
* External channels represent integrations with external communication platforms
|
|
7
|
+
* @category Resources
|
|
8
|
+
*/
|
|
9
|
+
class ExternalChannelsClient {
|
|
10
|
+
constructor(http) {
|
|
11
|
+
this.http = http;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* List external channels with pagination, filters, and sorting
|
|
15
|
+
*
|
|
16
|
+
* @param params - Optional query parameters for filtering and pagination
|
|
17
|
+
* @param params.cursor - Cursor for the next page of results
|
|
18
|
+
* @param params.limit - Number of items per page
|
|
19
|
+
* @param params.order_by - Fields to sort by
|
|
20
|
+
* @param options - Optional request configuration
|
|
21
|
+
*
|
|
22
|
+
* @returns A paginated list of external channels
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const result = await client.externalChannels.list({ limit: 15 });
|
|
27
|
+
* console.log(result.items);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
list(params, options) {
|
|
31
|
+
return this.http.list('/external-channels', params, options);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Iterate through all external channels using async generator
|
|
35
|
+
* Automatically handles pagination by following next_page_token
|
|
36
|
+
*
|
|
37
|
+
* @param params - Optional query parameters (excluding cursor)
|
|
38
|
+
* @param options - Optional request configuration
|
|
39
|
+
*
|
|
40
|
+
* @yields Individual ExternalChannel objects
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* for await (const channel of client.externalChannels.listAll()) {
|
|
45
|
+
* console.log(channel.id, channel.platform, channel.name);
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
async *listAll(params, options) {
|
|
50
|
+
let cursor = undefined;
|
|
51
|
+
do {
|
|
52
|
+
const page = await this.list({ ...(params || {}), after: cursor }, options);
|
|
53
|
+
for (const item of page.data)
|
|
54
|
+
yield item;
|
|
55
|
+
cursor = page.pagination.next_cursor;
|
|
56
|
+
} while (cursor);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get a single external channel by ID
|
|
60
|
+
*
|
|
61
|
+
* @param id - The unique identifier of the external channel
|
|
62
|
+
* @param options - Optional request configuration
|
|
63
|
+
*
|
|
64
|
+
* @returns The external channel object
|
|
65
|
+
*
|
|
66
|
+
* @throws {Error} If the channel is not found or request fails
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const channel = await client.externalChannels.get('channel-123');
|
|
71
|
+
* console.log(channel.platform, channel.configuration);
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
get(id, options) {
|
|
75
|
+
return this.http.get(`/external-channel/${encodeURIComponent(id)}`, options);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.ExternalChannelsClient = ExternalChannelsClient;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelCost = void 0;
|
|
4
|
+
const MODELS_COST = {
|
|
5
|
+
'gpt-4o-mini': {
|
|
6
|
+
input_price: 0.6,
|
|
7
|
+
output_price: 2.4,
|
|
8
|
+
per_tokens: 1000000,
|
|
9
|
+
},
|
|
10
|
+
'gpt-5-mini': {
|
|
11
|
+
input_price: 0.25,
|
|
12
|
+
output_price: 2.0,
|
|
13
|
+
per_tokens: 1000000,
|
|
14
|
+
},
|
|
15
|
+
'gpt-5': {
|
|
16
|
+
input_price: 1.5,
|
|
17
|
+
output_price: 10.0,
|
|
18
|
+
per_tokens: 1000000,
|
|
19
|
+
},
|
|
20
|
+
'gpt-5-nano': {
|
|
21
|
+
input_price: 0.05,
|
|
22
|
+
output_price: 0.4,
|
|
23
|
+
per_tokens: 1000000,
|
|
24
|
+
},
|
|
25
|
+
'gpt-4o': {
|
|
26
|
+
input_price: 5.0,
|
|
27
|
+
output_price: 20.0,
|
|
28
|
+
per_tokens: 1000000,
|
|
29
|
+
},
|
|
30
|
+
'text-embedding-3-small': {
|
|
31
|
+
input_price: 0.02,
|
|
32
|
+
output_price: 0.0,
|
|
33
|
+
per_tokens: 1000000,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
class ModelCost {
|
|
37
|
+
calculateCosts(costs) {
|
|
38
|
+
let totalCost = 0;
|
|
39
|
+
let totalTokens = 0;
|
|
40
|
+
const costsByModel = costs.map((line) => {
|
|
41
|
+
const modelConfig = MODELS_COST[line.model];
|
|
42
|
+
const reasoning = line.reasoningTokens ?? 0;
|
|
43
|
+
// Output tokens charged = visible output + reasoning tokens
|
|
44
|
+
const chargedOutputTokens = line.outputTokens + reasoning;
|
|
45
|
+
// If the model is not configured, return a neutral line with zero cost
|
|
46
|
+
if (!modelConfig) {
|
|
47
|
+
const modelTotalTokens = line.inputTokens + chargedOutputTokens;
|
|
48
|
+
return {
|
|
49
|
+
model: line.model,
|
|
50
|
+
inputTokens: line.inputTokens,
|
|
51
|
+
outputTokens: line.outputTokens,
|
|
52
|
+
reasoningTokens: reasoning,
|
|
53
|
+
chargedOutputTokens,
|
|
54
|
+
totalTokens: modelTotalTokens,
|
|
55
|
+
inputCost: 0,
|
|
56
|
+
outputCost: 0,
|
|
57
|
+
totalCost: 0,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// Cost of input tokens
|
|
61
|
+
const inputCost = (line.inputTokens * modelConfig.input_price) / modelConfig.per_tokens;
|
|
62
|
+
// Cost of output tokens (includes reasoning)
|
|
63
|
+
const outputCost = (chargedOutputTokens * modelConfig.output_price) / modelConfig.per_tokens;
|
|
64
|
+
const modelTotalCost = inputCost + outputCost;
|
|
65
|
+
const modelTotalTokens = line.inputTokens + chargedOutputTokens;
|
|
66
|
+
totalCost += modelTotalCost;
|
|
67
|
+
totalTokens += modelTotalTokens;
|
|
68
|
+
return {
|
|
69
|
+
model: line.model,
|
|
70
|
+
inputTokens: line.inputTokens,
|
|
71
|
+
outputTokens: line.outputTokens,
|
|
72
|
+
reasoningTokens: reasoning,
|
|
73
|
+
chargedOutputTokens,
|
|
74
|
+
totalTokens: modelTotalTokens,
|
|
75
|
+
inputCost,
|
|
76
|
+
outputCost,
|
|
77
|
+
totalCost: modelTotalCost,
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
totalCost,
|
|
82
|
+
totalTokens,
|
|
83
|
+
costsByModel,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.ModelCost = ModelCost;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResourcesClient = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Client for managing resources in the Kaiban platform
|
|
6
|
+
* Resources can include documents, files, or other materials
|
|
7
|
+
* @category Resources
|
|
8
|
+
*/
|
|
9
|
+
class ResourcesClient {
|
|
10
|
+
constructor(http) {
|
|
11
|
+
this.http = http;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* List resources with pagination, filters, and sorting
|
|
15
|
+
*
|
|
16
|
+
* @param params - Optional query parameters for filtering and pagination
|
|
17
|
+
* @param params.cursor - Cursor for the next page of results
|
|
18
|
+
* @param params.limit - Number of items per page
|
|
19
|
+
* @param params.order_by - Fields to sort by
|
|
20
|
+
* @param options - Optional request configuration
|
|
21
|
+
*
|
|
22
|
+
* @returns A paginated list of resources
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const result = await client.resources.list({ limit: 25 });
|
|
27
|
+
* console.log(result.items);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
list(params, options) {
|
|
31
|
+
return this.http.list('/resources', params, options);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Iterate through all resources using async generator
|
|
35
|
+
* Automatically handles pagination by following next_page_token
|
|
36
|
+
*
|
|
37
|
+
* @param params - Optional query parameters (excluding cursor)
|
|
38
|
+
* @param options - Optional request configuration
|
|
39
|
+
*
|
|
40
|
+
* @yields Individual Resource objects
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* for await (const resource of client.resources.listAll()) {
|
|
45
|
+
* console.log(resource.id, resource.name);
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
async *listAll(params, options) {
|
|
50
|
+
let cursor = undefined;
|
|
51
|
+
do {
|
|
52
|
+
const page = await this.list({ ...(params || {}), after: cursor }, options);
|
|
53
|
+
for (const item of page.data)
|
|
54
|
+
yield item;
|
|
55
|
+
cursor = page.pagination.next_cursor;
|
|
56
|
+
} while (cursor);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get a single resource by ID
|
|
60
|
+
*
|
|
61
|
+
* @param id - The unique identifier of the resource
|
|
62
|
+
* @param options - Optional request configuration
|
|
63
|
+
*
|
|
64
|
+
* @returns The resource object
|
|
65
|
+
*
|
|
66
|
+
* @throws {Error} If the resource is not found or request fails
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const resource = await client.resources.get('resource-123');
|
|
71
|
+
* console.log(resource.name, resource.type);
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
get(id, options) {
|
|
75
|
+
return this.http.get(`/resource/${encodeURIComponent(id)}`, options);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.ResourcesClient = ResourcesClient;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TeamsClient = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Client for managing teams in the Kaiban platform
|
|
6
|
+
* @category Resources
|
|
7
|
+
*/
|
|
8
|
+
class TeamsClient {
|
|
9
|
+
constructor(http) {
|
|
10
|
+
this.http = http;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* List teams with pagination, filters, and sorting
|
|
14
|
+
*
|
|
15
|
+
* @param params - Optional query parameters for filtering and pagination
|
|
16
|
+
* @param params.cursor - Cursor for pagination (from previous/next response)
|
|
17
|
+
* @param params.limit - Number of items per page (default: 50, max: 100)
|
|
18
|
+
* @param params.order_by - Fields to sort by. Use - prefix for descending order
|
|
19
|
+
* @param params.filters - Filter parameters (e.g., { status: 'active' })
|
|
20
|
+
* @param options - Optional request configuration
|
|
21
|
+
*
|
|
22
|
+
* @returns A paginated list of teams
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Basic pagination
|
|
27
|
+
* const result = await client.teams.list({ limit: 20 });
|
|
28
|
+
* console.log(result.data); // Current page items
|
|
29
|
+
* console.log(result.pagination.next_cursor); // Use for next page
|
|
30
|
+
*
|
|
31
|
+
* // With sorting
|
|
32
|
+
* const sorted = await client.teams.list({
|
|
33
|
+
* order_by: '-created_at',
|
|
34
|
+
* limit: 50
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // With filters
|
|
38
|
+
* const filtered = await client.teams.list({
|
|
39
|
+
* filters: { status: 'active' }
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* // Next page
|
|
43
|
+
* const nextPage = await client.teams.list({
|
|
44
|
+
* cursor: result.pagination.next_cursor
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
list(params, options) {
|
|
49
|
+
return this.http.list('/teams', params, options);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Iterate through all teams using async generator
|
|
53
|
+
* Automatically handles pagination by following next_page_token
|
|
54
|
+
*
|
|
55
|
+
* @param params - Optional query parameters (excluding cursor)
|
|
56
|
+
* @param options - Optional request configuration
|
|
57
|
+
*
|
|
58
|
+
* @yields Individual Team objects
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* for await (const team of client.teams.listAll()) {
|
|
63
|
+
* console.log(team.id, team.name);
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
async *listAll(params, options) {
|
|
68
|
+
let cursor = undefined;
|
|
69
|
+
do {
|
|
70
|
+
const page = await this.list({ ...(params || {}), after: cursor }, options);
|
|
71
|
+
for (const item of page.data)
|
|
72
|
+
yield item;
|
|
73
|
+
cursor = page.pagination.next_cursor;
|
|
74
|
+
} while (cursor);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get a single team by ID
|
|
78
|
+
*
|
|
79
|
+
* @param id - The unique identifier of the team
|
|
80
|
+
* @param options - Optional request configuration
|
|
81
|
+
*
|
|
82
|
+
* @returns The team object
|
|
83
|
+
*
|
|
84
|
+
* @throws {Error} If the team is not found or request fails
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const team = await client.teams.get('team-123');
|
|
89
|
+
* console.log(team.name);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
get(id, options) {
|
|
93
|
+
return this.http.get(`/team/${encodeURIComponent(id)}`, options);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.TeamsClient = TeamsClient;
|