@amigo-ai/sdk 0.1.1

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.js ADDED
@@ -0,0 +1,739 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, { get: all[name], enumerable: true });
6
+ };
7
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+
9
+ // src/core/errors.ts
10
+ var errors_exports = {};
11
+ __export(errors_exports, {
12
+ AmigoError: () => AmigoError,
13
+ AuthenticationError: () => AuthenticationError,
14
+ BadRequestError: () => BadRequestError,
15
+ ConfigurationError: () => ConfigurationError,
16
+ ConflictError: () => ConflictError,
17
+ NetworkError: () => NetworkError,
18
+ NotFoundError: () => NotFoundError,
19
+ ParseError: () => ParseError,
20
+ PermissionError: () => PermissionError,
21
+ RateLimitError: () => RateLimitError,
22
+ ServerError: () => ServerError,
23
+ ServiceUnavailableError: () => ServiceUnavailableError,
24
+ ValidationError: () => ValidationError,
25
+ createApiError: () => createApiError,
26
+ createErrorMiddleware: () => createErrorMiddleware,
27
+ isAmigoError: () => isAmigoError
28
+ });
29
+
30
+ // src/core/utils.ts
31
+ async function extractData(responsePromise) {
32
+ const result = await responsePromise;
33
+ const data = result.data;
34
+ if (data === void 0 || data === null) {
35
+ throw new ParseError("Expected response data to be present for successful request", "response");
36
+ }
37
+ return data;
38
+ }
39
+ async function* parseNdjsonStream(response) {
40
+ const body = response.body;
41
+ if (!body) return;
42
+ const reader = body.getReader();
43
+ const decoder = new TextDecoder();
44
+ let bufferedText = "";
45
+ try {
46
+ while (true) {
47
+ const { done, value } = await reader.read();
48
+ if (done) break;
49
+ bufferedText += decoder.decode(value, { stream: true });
50
+ let newlineIndex;
51
+ while ((newlineIndex = bufferedText.indexOf("\n")) !== -1) {
52
+ const line = bufferedText.slice(0, newlineIndex).trim();
53
+ bufferedText = bufferedText.slice(newlineIndex + 1);
54
+ if (!line) continue;
55
+ try {
56
+ yield JSON.parse(line);
57
+ } catch (err) {
58
+ throw new ParseError("Failed to parse NDJSON line", "json", err);
59
+ }
60
+ }
61
+ }
62
+ const trailing = bufferedText.trim();
63
+ if (trailing) {
64
+ try {
65
+ yield JSON.parse(trailing);
66
+ } catch (err) {
67
+ throw new ParseError("Failed to parse trailing NDJSON line", "json", err);
68
+ }
69
+ }
70
+ } finally {
71
+ reader.releaseLock();
72
+ }
73
+ }
74
+ async function parseResponseBody(response) {
75
+ try {
76
+ const text = await response.text();
77
+ if (!text) return void 0;
78
+ try {
79
+ return JSON.parse(text);
80
+ } catch {
81
+ return text;
82
+ }
83
+ } catch {
84
+ return void 0;
85
+ }
86
+ }
87
+ function isNetworkError(error) {
88
+ if (!(error instanceof Error)) return false;
89
+ return error instanceof TypeError || error.message.includes("fetch") || error.message.includes("Failed to fetch") || error.message.includes("Network request failed") || error.message.includes("ECONNREFUSED") || error.message.includes("ETIMEDOUT") || error.message.includes("ENOTFOUND") || error.message.includes("network");
90
+ }
91
+
92
+ // src/core/errors.ts
93
+ var AmigoError = class extends Error {
94
+ constructor(message, options) {
95
+ super(message);
96
+ /**
97
+ * Unique error code for programmatic error handling
98
+ */
99
+ __publicField(this, "errorCode");
100
+ /**
101
+ * HTTP status code if applicable
102
+ */
103
+ __publicField(this, "statusCode");
104
+ /**
105
+ * Additional context data
106
+ */
107
+ __publicField(this, "context");
108
+ this.name = this.constructor.name;
109
+ Object.setPrototypeOf(this, new.target.prototype);
110
+ if (Error.captureStackTrace) {
111
+ Error.captureStackTrace(this, this.constructor);
112
+ }
113
+ Object.assign(this, options);
114
+ }
115
+ /**
116
+ * Returns a JSON-serializable representation of the error
117
+ */
118
+ toJSON() {
119
+ return {
120
+ name: this.name,
121
+ message: this.message,
122
+ code: this.errorCode,
123
+ statusCode: this.statusCode,
124
+ context: this.context,
125
+ stack: this.stack
126
+ };
127
+ }
128
+ };
129
+ var BadRequestError = class extends AmigoError {
130
+ };
131
+ var AuthenticationError = class extends AmigoError {
132
+ };
133
+ var PermissionError = class extends AmigoError {
134
+ };
135
+ var NotFoundError = class extends AmigoError {
136
+ };
137
+ var ConflictError = class extends AmigoError {
138
+ };
139
+ var RateLimitError = class extends AmigoError {
140
+ };
141
+ var ServerError = class extends AmigoError {
142
+ };
143
+ var ServiceUnavailableError = class extends ServerError {
144
+ };
145
+ var ConfigurationError = class extends AmigoError {
146
+ constructor(message, field) {
147
+ super(message);
148
+ this.field = field;
149
+ this.context = { field };
150
+ }
151
+ };
152
+ var ValidationError = class extends BadRequestError {
153
+ constructor(msg, fieldErrors) {
154
+ super(msg);
155
+ this.fieldErrors = fieldErrors;
156
+ }
157
+ };
158
+ var NetworkError = class extends AmigoError {
159
+ constructor(message, originalError, request) {
160
+ super(message, { cause: originalError });
161
+ this.originalError = originalError;
162
+ this.request = request;
163
+ this.context = { request };
164
+ }
165
+ };
166
+ var ParseError = class extends AmigoError {
167
+ constructor(message, parseType, originalError) {
168
+ super(message, { cause: originalError });
169
+ this.parseType = parseType;
170
+ this.originalError = originalError;
171
+ this.context = { parseType };
172
+ }
173
+ };
174
+ function isAmigoError(error) {
175
+ return error instanceof AmigoError;
176
+ }
177
+ function createApiError(response, body) {
178
+ const map = {
179
+ 400: BadRequestError,
180
+ 401: AuthenticationError,
181
+ 403: PermissionError,
182
+ 404: NotFoundError,
183
+ 409: ConflictError,
184
+ 422: ValidationError,
185
+ 429: RateLimitError,
186
+ 500: ServerError,
187
+ 503: ServiceUnavailableError
188
+ };
189
+ const errorMessageKeys = ["message", "error", "detail"];
190
+ const ErrorClass = map[response.status] ?? AmigoError;
191
+ let message = `HTTP ${response.status} ${response.statusText}`;
192
+ if (body && typeof body === "object") {
193
+ for (const key of errorMessageKeys) {
194
+ if (key in body) {
195
+ message = String(body[key]);
196
+ break;
197
+ }
198
+ }
199
+ }
200
+ const options = {
201
+ status: response.status,
202
+ code: body && typeof body === "object" && "code" in body ? body.code : void 0,
203
+ response: body
204
+ };
205
+ const error = new ErrorClass(message, options);
206
+ return error;
207
+ }
208
+ function createErrorMiddleware() {
209
+ return {
210
+ onResponse: async ({ response }) => {
211
+ if (!response.ok) {
212
+ const body = await parseResponseBody(response);
213
+ throw createApiError(response, body);
214
+ }
215
+ },
216
+ onError: async ({ error, request }) => {
217
+ if (isNetworkError(error)) {
218
+ throw new NetworkError(
219
+ `Network error: ${error instanceof Error ? error.message : String(error)}`,
220
+ error instanceof Error ? error : new Error(String(error)),
221
+ {
222
+ url: request?.url,
223
+ method: request?.method
224
+ }
225
+ );
226
+ }
227
+ throw error;
228
+ }
229
+ };
230
+ }
231
+
232
+ // src/core/openapi-client.ts
233
+ import createClient from "openapi-fetch";
234
+
235
+ // src/core/auth.ts
236
+ async function getBearerToken(config) {
237
+ const url = `${config.baseUrl}/v1/${config.orgId}/user/signin_with_api_key`;
238
+ try {
239
+ const response = await fetch(url, {
240
+ method: "POST",
241
+ headers: {
242
+ "x-api-key": config.apiKey,
243
+ "x-api-key-id": config.apiKeyId,
244
+ "x-user-id": config.userId
245
+ }
246
+ });
247
+ if (!response.ok) {
248
+ const body = await parseResponseBody(response);
249
+ const apiError = createApiError(response, body);
250
+ if (response.status === 401) {
251
+ throw new AuthenticationError(`Authentication failed: ${apiError.message}`, {
252
+ ...apiError,
253
+ context: { ...apiError.context, endpoint: "signin_with_api_key" }
254
+ });
255
+ }
256
+ throw apiError;
257
+ }
258
+ return await response.json();
259
+ } catch (err) {
260
+ if (err instanceof AmigoError) {
261
+ throw err;
262
+ }
263
+ if (isNetworkError(err)) {
264
+ throw new NetworkError("Failed to connect to authentication endpoint", err, {
265
+ url,
266
+ method: "POST"
267
+ });
268
+ }
269
+ throw new ParseError(
270
+ "Failed to parse authentication response",
271
+ "json",
272
+ err instanceof Error ? err : new Error(String(err))
273
+ );
274
+ }
275
+ }
276
+ function createAuthMiddleware(config) {
277
+ let token = null;
278
+ let refreshPromise = null;
279
+ const shouldRefreshToken = (tokenData) => {
280
+ if (!tokenData.expires_at) return false;
281
+ const expiryTime = new Date(tokenData.expires_at).getTime();
282
+ const currentTime = Date.now();
283
+ const timeUntilExpiry = expiryTime - currentTime;
284
+ const refreshThreshold = 5 * 60 * 1e3;
285
+ return timeUntilExpiry <= refreshThreshold;
286
+ };
287
+ const ensureValidToken = async () => {
288
+ if (!token || shouldRefreshToken(token)) {
289
+ if (!refreshPromise) {
290
+ refreshPromise = getBearerToken(config);
291
+ try {
292
+ token = await refreshPromise;
293
+ } finally {
294
+ refreshPromise = null;
295
+ }
296
+ } else {
297
+ token = await refreshPromise;
298
+ }
299
+ }
300
+ return token;
301
+ };
302
+ return {
303
+ onRequest: async ({ request }) => {
304
+ try {
305
+ const validToken = await ensureValidToken();
306
+ if (validToken?.id_token) {
307
+ request.headers.set("Authorization", `Bearer ${validToken.id_token}`);
308
+ }
309
+ } catch (error) {
310
+ token = null;
311
+ throw error;
312
+ }
313
+ return request;
314
+ },
315
+ onResponse: async ({ response }) => {
316
+ if (response.status === 401) {
317
+ token = null;
318
+ }
319
+ },
320
+ onError: async ({ error }) => {
321
+ token = null;
322
+ throw error;
323
+ }
324
+ };
325
+ }
326
+
327
+ // src/core/retry.ts
328
+ var DEFAULT_RETRYABLE_STATUS = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
329
+ var DEFAULT_RETRYABLE_METHODS = /* @__PURE__ */ new Set(["GET"]);
330
+ function resolveRetryOptions(options) {
331
+ return {
332
+ maxAttempts: options?.maxAttempts ?? 3,
333
+ backoffBaseMs: options?.backoffBaseMs ?? 250,
334
+ maxDelayMs: options?.maxDelayMs ?? 3e4,
335
+ retryOnStatus: new Set(options?.retryOnStatus ?? DEFAULT_RETRYABLE_STATUS),
336
+ retryOnMethods: new Set(options?.retryOnMethods ?? DEFAULT_RETRYABLE_METHODS)
337
+ };
338
+ }
339
+ function clamp(value, min, max) {
340
+ return Math.max(min, Math.min(max, value));
341
+ }
342
+ function parseRetryAfterMs(headerValue, maxDelayMs) {
343
+ if (!headerValue) return null;
344
+ const seconds = Number(headerValue);
345
+ if (Number.isFinite(seconds)) {
346
+ return clamp(seconds * 1e3, 0, maxDelayMs);
347
+ }
348
+ const date = new Date(headerValue);
349
+ const ms = date.getTime() - Date.now();
350
+ if (Number.isFinite(ms)) {
351
+ return clamp(ms, 0, maxDelayMs);
352
+ }
353
+ return null;
354
+ }
355
+ function computeBackoffWithJitterMs(attemptIndexZeroBased, baseMs, capMs) {
356
+ const windowMs = Math.min(capMs, baseMs * Math.pow(2, attemptIndexZeroBased));
357
+ return Math.random() * windowMs;
358
+ }
359
+ function isAbortError(err) {
360
+ return typeof err === "object" && err !== null && "name" in err && err["name"] === "AbortError";
361
+ }
362
+ function isNetworkError2(err) {
363
+ return err instanceof TypeError && !isAbortError(err);
364
+ }
365
+ async function abortableSleep(ms, signal) {
366
+ if (ms <= 0) {
367
+ signal?.throwIfAborted?.();
368
+ return;
369
+ }
370
+ await new Promise((resolve, reject) => {
371
+ const rejectWith = signal?.reason instanceof Error ? signal.reason : signal?.reason ?? new Error("AbortError");
372
+ if (signal?.aborted) {
373
+ reject(rejectWith);
374
+ return;
375
+ }
376
+ const t = setTimeout(() => {
377
+ off();
378
+ resolve();
379
+ }, ms);
380
+ const onAbort = () => {
381
+ off();
382
+ clearTimeout(t);
383
+ reject(rejectWith);
384
+ };
385
+ const off = () => signal?.removeEventListener("abort", onAbort);
386
+ signal?.addEventListener("abort", onAbort, { once: true });
387
+ });
388
+ }
389
+ function createRetryingFetch(retryOptions, baseFetch) {
390
+ const resolved = resolveRetryOptions(retryOptions);
391
+ const underlying = baseFetch ?? globalThis.fetch;
392
+ const retryingFetch = async (input, init) => {
393
+ const inputMethod = typeof Request !== "undefined" && input instanceof Request ? input.method : void 0;
394
+ const method = (init?.method ?? inputMethod ?? "GET").toUpperCase();
395
+ const signal = init?.signal;
396
+ const isMethodRetryableByDefault = resolved.retryOnMethods.has(method);
397
+ const maxAttempts = Math.max(1, resolved.maxAttempts);
398
+ for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
399
+ let response = null;
400
+ let error = null;
401
+ try {
402
+ response = await underlying(input, init);
403
+ } catch (err) {
404
+ error = err;
405
+ }
406
+ if (!error && response && response.ok) {
407
+ return response;
408
+ }
409
+ let shouldRetry = false;
410
+ let delayMs = null;
411
+ if (isNetworkError2(error)) {
412
+ shouldRetry = isMethodRetryableByDefault;
413
+ if (shouldRetry) {
414
+ delayMs = computeBackoffWithJitterMs(
415
+ attempt - 1,
416
+ resolved.backoffBaseMs,
417
+ resolved.maxDelayMs
418
+ );
419
+ }
420
+ } else if (response) {
421
+ const status = response.status;
422
+ if (method === "POST") {
423
+ if (status === 429) {
424
+ const ra = response.headers.get("Retry-After");
425
+ const parsed = parseRetryAfterMs(ra, resolved.maxDelayMs);
426
+ if (parsed !== null) {
427
+ shouldRetry = true;
428
+ delayMs = parsed;
429
+ }
430
+ }
431
+ } else if (isMethodRetryableByDefault && resolved.retryOnStatus.has(status)) {
432
+ const ra = response.headers.get("Retry-After");
433
+ delayMs = parseRetryAfterMs(ra, resolved.maxDelayMs) ?? computeBackoffWithJitterMs(attempt - 1, resolved.backoffBaseMs, resolved.maxDelayMs);
434
+ shouldRetry = true;
435
+ }
436
+ }
437
+ const attemptsRemain = attempt < maxAttempts;
438
+ if (!shouldRetry || !attemptsRemain) {
439
+ if (error) throw error;
440
+ return response;
441
+ }
442
+ if (signal?.aborted) {
443
+ if (error) throw error;
444
+ return response;
445
+ }
446
+ await abortableSleep(delayMs ?? 0, signal ?? void 0);
447
+ }
448
+ throw new Error("Retry loop exited unexpectedly");
449
+ };
450
+ return retryingFetch;
451
+ }
452
+
453
+ // src/core/openapi-client.ts
454
+ function createAmigoFetch(config, mockFetch) {
455
+ const wrappedFetch = createRetryingFetch(
456
+ config.retry,
457
+ mockFetch ?? globalThis.fetch
458
+ );
459
+ const client = createClient({
460
+ baseUrl: config.baseUrl,
461
+ fetch: wrappedFetch
462
+ });
463
+ client.use(createErrorMiddleware());
464
+ client.use(createAuthMiddleware(config));
465
+ return client;
466
+ }
467
+
468
+ // src/resources/organization.ts
469
+ var OrganizationResource = class {
470
+ constructor(c, orgId) {
471
+ this.c = c;
472
+ this.orgId = orgId;
473
+ }
474
+ /**
475
+ * Get organization details
476
+ * @param headers - The headers
477
+ * @returns The organization details
478
+ */
479
+ async getOrganization(headers) {
480
+ return extractData(
481
+ this.c.GET("/v1/{organization}/organization/", {
482
+ params: { path: { organization: this.orgId } },
483
+ headers
484
+ })
485
+ );
486
+ }
487
+ };
488
+
489
+ // src/resources/conversation.ts
490
+ var ConversationResource = class {
491
+ constructor(c, orgId) {
492
+ this.c = c;
493
+ this.orgId = orgId;
494
+ }
495
+ async createConversation(body, queryParams, headers, options) {
496
+ const resp = await this.c.POST("/v1/{organization}/conversation/", {
497
+ params: { path: { organization: this.orgId }, query: queryParams },
498
+ body,
499
+ headers: {
500
+ Accept: "application/x-ndjson",
501
+ ...headers ?? {}
502
+ },
503
+ // Ensure we receive a stream for NDJSON
504
+ parseAs: "stream",
505
+ ...options?.signal && { signal: options.signal }
506
+ });
507
+ return parseNdjsonStream(
508
+ resp.response
509
+ );
510
+ }
511
+ async interactWithConversation(conversationId, input, queryParams, headers, options) {
512
+ let bodyToSend;
513
+ if (queryParams.request_format === "text") {
514
+ if (typeof input !== "string") {
515
+ throw new BadRequestError("textMessage is required when request_format is 'text'");
516
+ }
517
+ const form = new FormData();
518
+ const blob = new Blob([input], { type: "text/plain; charset=utf-8" });
519
+ form.append("recorded_message", blob, "message.txt");
520
+ bodyToSend = form;
521
+ } else if (queryParams.request_format === "voice") {
522
+ if (typeof input === "string") {
523
+ throw new BadRequestError(
524
+ "voice input must be a byte source when request_format is 'voice'"
525
+ );
526
+ }
527
+ bodyToSend = input;
528
+ } else {
529
+ throw new BadRequestError("Unsupported or missing request_format in params");
530
+ }
531
+ const normalizedQuery = {
532
+ ...queryParams,
533
+ request_audio_config: typeof queryParams.request_audio_config === "object" && queryParams.request_audio_config !== null ? JSON.stringify(queryParams.request_audio_config) : queryParams.request_audio_config ?? void 0
534
+ };
535
+ const resp = await this.c.POST("/v1/{organization}/conversation/{conversation_id}/interact", {
536
+ params: {
537
+ path: { organization: this.orgId, conversation_id: conversationId },
538
+ query: normalizedQuery
539
+ },
540
+ body: bodyToSend,
541
+ headers: {
542
+ Accept: "application/x-ndjson",
543
+ ...headers ?? {}
544
+ },
545
+ parseAs: "stream",
546
+ ...options?.signal && { signal: options.signal }
547
+ });
548
+ return parseNdjsonStream(resp.response);
549
+ }
550
+ async getConversations(queryParams, headers) {
551
+ return extractData(
552
+ this.c.GET("/v1/{organization}/conversation/", {
553
+ params: { path: { organization: this.orgId }, query: queryParams },
554
+ headers
555
+ })
556
+ );
557
+ }
558
+ async getConversationMessages(conversationId, queryParams, headers) {
559
+ return extractData(
560
+ this.c.GET("/v1/{organization}/conversation/{conversation_id}/messages/", {
561
+ params: {
562
+ path: { organization: this.orgId, conversation_id: conversationId },
563
+ query: queryParams
564
+ },
565
+ headers
566
+ })
567
+ );
568
+ }
569
+ async finishConversation(conversationId, headers) {
570
+ await this.c.POST("/v1/{organization}/conversation/{conversation_id}/finish/", {
571
+ params: { path: { organization: this.orgId, conversation_id: conversationId } },
572
+ headers,
573
+ // No content is expected; parse as text to access raw Response
574
+ parseAs: "text"
575
+ });
576
+ return;
577
+ }
578
+ async recommendResponsesForInteraction(conversationId, interactionId, headers) {
579
+ return extractData(
580
+ this.c.GET(
581
+ "/v1/{organization}/conversation/{conversation_id}/interaction/{interaction_id}/recommend_responses",
582
+ {
583
+ params: {
584
+ path: {
585
+ organization: this.orgId,
586
+ conversation_id: conversationId,
587
+ interaction_id: interactionId
588
+ }
589
+ },
590
+ headers
591
+ }
592
+ )
593
+ );
594
+ }
595
+ async getInteractionInsights(conversationId, interactionId, headers) {
596
+ return extractData(
597
+ this.c.GET(
598
+ "/v1/{organization}/conversation/{conversation_id}/interaction/{interaction_id}/insights",
599
+ {
600
+ params: {
601
+ path: {
602
+ organization: this.orgId,
603
+ conversation_id: conversationId,
604
+ interaction_id: interactionId
605
+ }
606
+ },
607
+ headers
608
+ }
609
+ )
610
+ );
611
+ }
612
+ // Note: the OpenAPI response schema isn't correct for this endpoint.
613
+ // TODO -- fix response typing.
614
+ async getMessageSource(conversationId, messageId, headers) {
615
+ return extractData(
616
+ this.c.GET("/v1/{organization}/conversation/{conversation_id}/messages/{message_id}/source", {
617
+ params: {
618
+ path: {
619
+ organization: this.orgId,
620
+ conversation_id: conversationId,
621
+ message_id: messageId
622
+ }
623
+ },
624
+ headers
625
+ })
626
+ );
627
+ }
628
+ async generateConversationStarters(body, headers) {
629
+ return extractData(
630
+ this.c.POST("/v1/{organization}/conversation/conversation_starter", {
631
+ params: { path: { organization: this.orgId } },
632
+ body,
633
+ headers
634
+ })
635
+ );
636
+ }
637
+ };
638
+
639
+ // src/resources/services.ts
640
+ var ServiceResource = class {
641
+ constructor(c, orgId) {
642
+ this.c = c;
643
+ this.orgId = orgId;
644
+ }
645
+ /**
646
+ * Get services
647
+ * @param headers - The headers
648
+ * @returns The services
649
+ */
650
+ async getServices(queryParams, headers) {
651
+ return extractData(
652
+ this.c.GET("/v1/{organization}/service/", {
653
+ params: { path: { organization: this.orgId }, query: queryParams },
654
+ headers
655
+ })
656
+ );
657
+ }
658
+ };
659
+
660
+ // src/resources/user.ts
661
+ var UserResource = class {
662
+ constructor(c, orgId) {
663
+ this.c = c;
664
+ this.orgId = orgId;
665
+ }
666
+ async getUsers(queryParams, headers) {
667
+ return extractData(
668
+ this.c.GET("/v1/{organization}/user/", {
669
+ params: { path: { organization: this.orgId }, query: queryParams },
670
+ headers
671
+ })
672
+ );
673
+ }
674
+ async createUser(body, headers) {
675
+ return extractData(
676
+ this.c.POST("/v1/{organization}/user/invite", {
677
+ params: { path: { organization: this.orgId } },
678
+ body,
679
+ headers
680
+ })
681
+ );
682
+ }
683
+ async deleteUser(userId, headers) {
684
+ await this.c.DELETE("/v1/{organization}/user/{requested_user_id}", {
685
+ params: { path: { organization: this.orgId, requested_user_id: userId } },
686
+ headers
687
+ });
688
+ return;
689
+ }
690
+ async updateUser(userId, body, headers) {
691
+ await this.c.POST("/v1/{organization}/user/{requested_user_id}/user", {
692
+ params: { path: { organization: this.orgId, requested_user_id: userId } },
693
+ body,
694
+ headers
695
+ });
696
+ return;
697
+ }
698
+ };
699
+
700
+ // src/index.ts
701
+ var defaultBaseUrl = "https://api.amigo.ai";
702
+ var AmigoClient = class {
703
+ constructor(config) {
704
+ __publicField(this, "organizations");
705
+ __publicField(this, "conversations");
706
+ __publicField(this, "services");
707
+ __publicField(this, "users");
708
+ __publicField(this, "config");
709
+ this.config = validateConfig(config);
710
+ const api = createAmigoFetch(this.config);
711
+ this.organizations = new OrganizationResource(api, this.config.orgId);
712
+ this.conversations = new ConversationResource(api, this.config.orgId);
713
+ this.services = new ServiceResource(api, this.config.orgId);
714
+ this.users = new UserResource(api, this.config.orgId);
715
+ }
716
+ };
717
+ function validateConfig(config) {
718
+ if (!config.apiKey) {
719
+ throw new ConfigurationError("API key is required", "apiKey");
720
+ }
721
+ if (!config.apiKeyId) {
722
+ throw new ConfigurationError("API key ID is required", "apiKeyId");
723
+ }
724
+ if (!config.userId) {
725
+ throw new ConfigurationError("User ID is required", "userId");
726
+ }
727
+ if (!config.orgId) {
728
+ throw new ConfigurationError("Organization ID is required", "orgId");
729
+ }
730
+ if (!config.baseUrl) {
731
+ config.baseUrl = defaultBaseUrl;
732
+ }
733
+ return config;
734
+ }
735
+ export {
736
+ AmigoClient,
737
+ errors_exports as errors
738
+ };
739
+ //# sourceMappingURL=index.js.map