@credal/sdk 0.1.12 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/cjs/BaseClient.d.ts +9 -1
  2. package/dist/cjs/BaseClient.js +10 -2
  3. package/dist/cjs/Client.d.ts +2 -1
  4. package/dist/cjs/Client.js +1 -1
  5. package/dist/cjs/api/resources/copilots/client/Client.d.ts +22 -2
  6. package/dist/cjs/api/resources/copilots/client/Client.js +81 -17
  7. package/dist/cjs/api/resources/copilots/client/requests/ExportCopilotsRequest.d.ts +21 -0
  8. package/dist/cjs/api/resources/copilots/client/requests/ExportCopilotsRequest.js +3 -0
  9. package/dist/cjs/api/resources/copilots/client/requests/index.d.ts +1 -0
  10. package/dist/cjs/api/resources/copilots/types/ExportCopilotsResponse.d.ts +9 -0
  11. package/dist/cjs/api/resources/copilots/types/ExportCopilotsResponse.js +3 -0
  12. package/dist/cjs/api/resources/copilots/types/ExportedCopilot.d.ts +24 -0
  13. package/dist/cjs/api/resources/copilots/types/ExportedCopilot.js +3 -0
  14. package/dist/cjs/api/resources/copilots/types/index.d.ts +2 -0
  15. package/dist/cjs/api/resources/copilots/types/index.js +2 -0
  16. package/dist/cjs/api/resources/documentCatalog/client/Client.d.ts +2 -2
  17. package/dist/cjs/api/resources/documentCatalog/client/Client.js +9 -17
  18. package/dist/cjs/api/resources/documentCollections/client/Client.d.ts +2 -2
  19. package/dist/cjs/api/resources/documentCollections/client/Client.js +15 -20
  20. package/dist/cjs/api/resources/search/client/Client.d.ts +2 -2
  21. package/dist/cjs/api/resources/search/client/Client.js +3 -14
  22. package/dist/cjs/api/resources/users/client/Client.d.ts +2 -2
  23. package/dist/cjs/api/resources/users/client/Client.js +3 -14
  24. package/dist/cjs/auth/BearerAuthProvider.d.ts +14 -0
  25. package/dist/cjs/auth/BearerAuthProvider.js +72 -0
  26. package/dist/cjs/auth/index.d.ts +1 -0
  27. package/dist/cjs/auth/index.js +5 -0
  28. package/dist/cjs/core/auth/AuthProvider.d.ts +4 -1
  29. package/dist/cjs/core/auth/BearerToken.d.ts +3 -1
  30. package/dist/cjs/core/auth/BearerToken.js +7 -6
  31. package/dist/cjs/version.d.ts +1 -1
  32. package/dist/cjs/version.js +1 -1
  33. package/dist/esm/BaseClient.d.mts +9 -1
  34. package/dist/esm/BaseClient.mjs +9 -2
  35. package/dist/esm/Client.d.mts +2 -1
  36. package/dist/esm/Client.mjs +2 -2
  37. package/dist/esm/api/resources/copilots/client/Client.d.mts +22 -2
  38. package/dist/esm/api/resources/copilots/client/Client.mjs +83 -19
  39. package/dist/esm/api/resources/copilots/client/requests/ExportCopilotsRequest.d.mts +21 -0
  40. package/dist/esm/api/resources/copilots/client/requests/ExportCopilotsRequest.mjs +2 -0
  41. package/dist/esm/api/resources/copilots/client/requests/index.d.mts +1 -0
  42. package/dist/esm/api/resources/copilots/types/ExportCopilotsResponse.d.mts +9 -0
  43. package/dist/esm/api/resources/copilots/types/ExportCopilotsResponse.mjs +2 -0
  44. package/dist/esm/api/resources/copilots/types/ExportedCopilot.d.mts +24 -0
  45. package/dist/esm/api/resources/copilots/types/ExportedCopilot.mjs +2 -0
  46. package/dist/esm/api/resources/copilots/types/index.d.mts +2 -0
  47. package/dist/esm/api/resources/copilots/types/index.mjs +2 -0
  48. package/dist/esm/api/resources/documentCatalog/client/Client.d.mts +2 -2
  49. package/dist/esm/api/resources/documentCatalog/client/Client.mjs +10 -18
  50. package/dist/esm/api/resources/documentCollections/client/Client.d.mts +2 -2
  51. package/dist/esm/api/resources/documentCollections/client/Client.mjs +17 -22
  52. package/dist/esm/api/resources/search/client/Client.d.mts +2 -2
  53. package/dist/esm/api/resources/search/client/Client.mjs +5 -16
  54. package/dist/esm/api/resources/users/client/Client.d.mts +2 -2
  55. package/dist/esm/api/resources/users/client/Client.mjs +5 -16
  56. package/dist/esm/auth/BearerAuthProvider.d.mts +14 -0
  57. package/dist/esm/auth/BearerAuthProvider.mjs +35 -0
  58. package/dist/esm/auth/index.d.mts +1 -0
  59. package/dist/esm/auth/index.mjs +1 -0
  60. package/dist/esm/core/auth/AuthProvider.d.mts +4 -1
  61. package/dist/esm/core/auth/BearerToken.d.mts +3 -1
  62. package/dist/esm/core/auth/BearerToken.mjs +7 -6
  63. package/dist/esm/version.d.mts +1 -1
  64. package/dist/esm/version.mjs +1 -1
  65. package/package.json +1 -1
  66. package/reference.md +72 -0
@@ -1,4 +1,5 @@
1
1
  import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient.js";
2
+ import { type NormalizedClientOptionsWithAuth } from "../../../../BaseClient.js";
2
3
  import * as core from "../../../../core/index.js";
3
4
  import type * as Credal from "../../../index.js";
4
5
  export declare namespace SearchClient {
@@ -8,7 +9,7 @@ export declare namespace SearchClient {
8
9
  }
9
10
  }
10
11
  export declare class SearchClient {
11
- protected readonly _options: SearchClient.Options;
12
+ protected readonly _options: NormalizedClientOptionsWithAuth<SearchClient.Options>;
12
13
  constructor(options?: SearchClient.Options);
13
14
  /**
14
15
  * Search across all documents in a document collection using the document metadata and contents.
@@ -38,5 +39,4 @@ export declare class SearchClient {
38
39
  */
39
40
  searchDocumentCollection(request: Credal.SearchDocumentCollectionRequest, requestOptions?: SearchClient.RequestOptions): core.HttpResponsePromise<Credal.SearchDocumentCollectionResponse>;
40
41
  private __searchDocumentCollection;
41
- protected _getAuthorizationHeader(): Promise<string>;
42
42
  }
@@ -51,7 +51,7 @@ const environments = __importStar(require("../../../../environments.js"));
51
51
  const errors = __importStar(require("../../../../errors/index.js"));
52
52
  class SearchClient {
53
53
  constructor(options = {}) {
54
- this._options = (0, BaseClient_js_1.normalizeClientOptions)(options);
54
+ this._options = (0, BaseClient_js_1.normalizeClientOptionsWithAuth)(options);
55
55
  }
56
56
  /**
57
57
  * Search across all documents in a document collection using the document metadata and contents.
@@ -85,7 +85,8 @@ class SearchClient {
85
85
  __searchDocumentCollection(request, requestOptions) {
86
86
  return __awaiter(this, void 0, void 0, function* () {
87
87
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
88
- const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
88
+ const _authRequest = yield this._options.authProvider.getAuthRequest();
89
+ const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
89
90
  const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
90
91
  url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/search/searchDocumentCollection"),
91
92
  method: "POST",
@@ -130,17 +131,5 @@ class SearchClient {
130
131
  }
131
132
  });
132
133
  }
133
- _getAuthorizationHeader() {
134
- return __awaiter(this, void 0, void 0, function* () {
135
- var _a;
136
- const bearer = (_a = (yield core.Supplier.get(this._options.apiKey))) !== null && _a !== void 0 ? _a : process === null || process === void 0 ? void 0 : process.env.CREDAL_API_KEY;
137
- if (bearer == null) {
138
- throw new errors.CredalError({
139
- message: "Please specify a bearer by either passing it in to the constructor or initializing a CREDAL_API_KEY environment variable",
140
- });
141
- }
142
- return `Bearer ${bearer}`;
143
- });
144
- }
145
134
  }
146
135
  exports.SearchClient = SearchClient;
@@ -1,4 +1,5 @@
1
1
  import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient.js";
2
+ import { type NormalizedClientOptionsWithAuth } from "../../../../BaseClient.js";
2
3
  import * as core from "../../../../core/index.js";
3
4
  import type * as Credal from "../../../index.js";
4
5
  export declare namespace UsersClient {
@@ -8,7 +9,7 @@ export declare namespace UsersClient {
8
9
  }
9
10
  }
10
11
  export declare class UsersClient {
11
- protected readonly _options: UsersClient.Options;
12
+ protected readonly _options: NormalizedClientOptionsWithAuth<UsersClient.Options>;
12
13
  constructor(options?: UsersClient.Options);
13
14
  /**
14
15
  * Bulk patch metadata for users
@@ -33,5 +34,4 @@ export declare class UsersClient {
33
34
  */
34
35
  metadata(request: Credal.UserMetadataPatch[], requestOptions?: UsersClient.RequestOptions): core.HttpResponsePromise<void>;
35
36
  private __metadata;
36
- protected _getAuthorizationHeader(): Promise<string>;
37
37
  }
@@ -51,7 +51,7 @@ const environments = __importStar(require("../../../../environments.js"));
51
51
  const errors = __importStar(require("../../../../errors/index.js"));
52
52
  class UsersClient {
53
53
  constructor(options = {}) {
54
- this._options = (0, BaseClient_js_1.normalizeClientOptions)(options);
54
+ this._options = (0, BaseClient_js_1.normalizeClientOptionsWithAuth)(options);
55
55
  }
56
56
  /**
57
57
  * Bulk patch metadata for users
@@ -80,7 +80,8 @@ class UsersClient {
80
80
  __metadata(request, requestOptions) {
81
81
  return __awaiter(this, void 0, void 0, function* () {
82
82
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
83
- const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
83
+ const _authRequest = yield this._options.authProvider.getAuthRequest();
84
+ const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
84
85
  const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
85
86
  url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/users/metadata"),
86
87
  method: "PATCH",
@@ -122,17 +123,5 @@ class UsersClient {
122
123
  }
123
124
  });
124
125
  }
125
- _getAuthorizationHeader() {
126
- return __awaiter(this, void 0, void 0, function* () {
127
- var _a;
128
- const bearer = (_a = (yield core.Supplier.get(this._options.apiKey))) !== null && _a !== void 0 ? _a : process === null || process === void 0 ? void 0 : process.env.CREDAL_API_KEY;
129
- if (bearer == null) {
130
- throw new errors.CredalError({
131
- message: "Please specify a bearer by either passing it in to the constructor or initializing a CREDAL_API_KEY environment variable",
132
- });
133
- }
134
- return `Bearer ${bearer}`;
135
- });
136
- }
137
126
  }
138
127
  exports.UsersClient = UsersClient;
@@ -0,0 +1,14 @@
1
+ import * as core from "../core/index.js";
2
+ export declare namespace BearerAuthProvider {
3
+ interface Options {
4
+ apiKey?: core.Supplier<core.BearerToken | undefined>;
5
+ }
6
+ }
7
+ export declare class BearerAuthProvider implements core.AuthProvider {
8
+ private readonly token;
9
+ constructor(options: BearerAuthProvider.Options);
10
+ static canCreate(options: BearerAuthProvider.Options): boolean;
11
+ getAuthRequest(_arg?: {
12
+ endpointMetadata?: core.EndpointMetadata;
13
+ }): Promise<core.AuthRequest>;
14
+ }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ // This file was auto-generated by Fern from our API Definition.
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
+ return new (P || (P = Promise))(function (resolve, reject) {
39
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ };
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.BearerAuthProvider = void 0;
47
+ const core = __importStar(require("../core/index.js"));
48
+ const errors = __importStar(require("../errors/index.js"));
49
+ class BearerAuthProvider {
50
+ constructor(options) {
51
+ this.token = options.apiKey;
52
+ }
53
+ static canCreate(options) {
54
+ var _a;
55
+ return options.apiKey != null || ((_a = process.env) === null || _a === void 0 ? void 0 : _a.CREDAL_API_KEY) != null;
56
+ }
57
+ getAuthRequest(_arg) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ var _a, _b;
60
+ const apiKey = (_a = (yield core.Supplier.get(this.token))) !== null && _a !== void 0 ? _a : (_b = process.env) === null || _b === void 0 ? void 0 : _b.CREDAL_API_KEY;
61
+ if (apiKey == null) {
62
+ throw new errors.CredalError({
63
+ message: "Please specify a apiKey by either passing it in to the constructor or initializing a CREDAL_API_KEY environment variable",
64
+ });
65
+ }
66
+ return {
67
+ headers: { Authorization: `Bearer ${apiKey}` },
68
+ };
69
+ });
70
+ }
71
+ }
72
+ exports.BearerAuthProvider = BearerAuthProvider;
@@ -0,0 +1 @@
1
+ export { BearerAuthProvider } from "./BearerAuthProvider.js";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BearerAuthProvider = void 0;
4
+ var BearerAuthProvider_js_1 = require("./BearerAuthProvider.js");
5
+ Object.defineProperty(exports, "BearerAuthProvider", { enumerable: true, get: function () { return BearerAuthProvider_js_1.BearerAuthProvider; } });
@@ -1,4 +1,7 @@
1
+ import type { EndpointMetadata } from "../fetcher/EndpointMetadata.js";
1
2
  import type { AuthRequest } from "./AuthRequest.js";
2
3
  export interface AuthProvider {
3
- getAuthRequest(): Promise<AuthRequest>;
4
+ getAuthRequest(arg?: {
5
+ endpointMetadata?: EndpointMetadata;
6
+ }): Promise<AuthRequest>;
4
7
  }
@@ -1,5 +1,7 @@
1
1
  export type BearerToken = string;
2
+ declare function toAuthorizationHeader(token: string | undefined): string | undefined;
2
3
  export declare const BearerToken: {
3
- toAuthorizationHeader: (token: BearerToken | undefined) => string | undefined;
4
+ toAuthorizationHeader: typeof toAuthorizationHeader;
4
5
  fromAuthorizationHeader: (header: string) => BearerToken;
5
6
  };
7
+ export {};
@@ -2,13 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BearerToken = void 0;
4
4
  const BEARER_AUTH_HEADER_PREFIX = /^Bearer /i;
5
+ function toAuthorizationHeader(token) {
6
+ if (token == null) {
7
+ return undefined;
8
+ }
9
+ return `Bearer ${token}`;
10
+ }
5
11
  exports.BearerToken = {
6
- toAuthorizationHeader: (token) => {
7
- if (token == null) {
8
- return undefined;
9
- }
10
- return `Bearer ${token}`;
11
- },
12
+ toAuthorizationHeader: toAuthorizationHeader,
12
13
  fromAuthorizationHeader: (header) => {
13
14
  return header.replace(BEARER_AUTH_HEADER_PREFIX, "").trim();
14
15
  },
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.1.12";
1
+ export declare const SDK_VERSION = "0.1.14";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "0.1.12";
4
+ exports.SDK_VERSION = "0.1.14";
@@ -29,4 +29,12 @@ export interface BaseRequestOptions {
29
29
  /** Additional headers to include in the request. */
30
30
  headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
31
31
  }
32
- export declare function normalizeClientOptions<T extends BaseClientOptions>(options: T): T;
32
+ export type NormalizedClientOptions<T extends BaseClientOptions> = T & {
33
+ logging: core.logging.Logger;
34
+ authProvider?: core.AuthProvider;
35
+ };
36
+ export type NormalizedClientOptionsWithAuth<T extends BaseClientOptions> = NormalizedClientOptions<T> & {
37
+ authProvider: core.AuthProvider;
38
+ };
39
+ export declare function normalizeClientOptions<T extends BaseClientOptions>(options: T): NormalizedClientOptions<T>;
40
+ export declare function normalizeClientOptionsWithAuth<T extends BaseClientOptions>(options: T): NormalizedClientOptionsWithAuth<T>;
@@ -1,14 +1,21 @@
1
1
  // This file was auto-generated by Fern from our API Definition.
2
+ import { BearerAuthProvider } from "./auth/BearerAuthProvider.mjs";
2
3
  import { mergeHeaders } from "./core/headers.mjs";
3
4
  import * as core from "./core/index.mjs";
4
5
  export function normalizeClientOptions(options) {
5
6
  const headers = mergeHeaders({
6
7
  "X-Fern-Language": "JavaScript",
7
8
  "X-Fern-SDK-Name": "@credal/sdk",
8
- "X-Fern-SDK-Version": "0.1.12",
9
- "User-Agent": "@credal/sdk/0.1.12",
9
+ "X-Fern-SDK-Version": "0.1.14",
10
+ "User-Agent": "@credal/sdk/0.1.14",
10
11
  "X-Fern-Runtime": core.RUNTIME.type,
11
12
  "X-Fern-Runtime-Version": core.RUNTIME.version,
12
13
  }, options === null || options === void 0 ? void 0 : options.headers);
13
14
  return Object.assign(Object.assign({}, options), { logging: core.logging.createLogger(options === null || options === void 0 ? void 0 : options.logging), headers });
14
15
  }
16
+ export function normalizeClientOptionsWithAuth(options) {
17
+ var _a;
18
+ const normalized = normalizeClientOptions(options);
19
+ (_a = normalized.authProvider) !== null && _a !== void 0 ? _a : (normalized.authProvider = new BearerAuthProvider(options));
20
+ return normalized;
21
+ }
@@ -4,6 +4,7 @@ import { DocumentCollectionsClient } from "./api/resources/documentCollections/c
4
4
  import { SearchClient } from "./api/resources/search/client/Client.mjs";
5
5
  import { UsersClient } from "./api/resources/users/client/Client.mjs";
6
6
  import type { BaseClientOptions, BaseRequestOptions } from "./BaseClient.mjs";
7
+ import { type NormalizedClientOptionsWithAuth } from "./BaseClient.mjs";
7
8
  export declare namespace CredalClient {
8
9
  interface Options extends BaseClientOptions {
9
10
  }
@@ -11,7 +12,7 @@ export declare namespace CredalClient {
11
12
  }
12
13
  }
13
14
  export declare class CredalClient {
14
- protected readonly _options: CredalClient.Options;
15
+ protected readonly _options: NormalizedClientOptionsWithAuth<CredalClient.Options>;
15
16
  protected _copilots: CopilotsClient | undefined;
16
17
  protected _documentCatalog: DocumentCatalogClient | undefined;
17
18
  protected _documentCollections: DocumentCollectionsClient | undefined;
@@ -4,10 +4,10 @@ import { DocumentCatalogClient } from "./api/resources/documentCatalog/client/Cl
4
4
  import { DocumentCollectionsClient } from "./api/resources/documentCollections/client/Client.mjs";
5
5
  import { SearchClient } from "./api/resources/search/client/Client.mjs";
6
6
  import { UsersClient } from "./api/resources/users/client/Client.mjs";
7
- import { normalizeClientOptions } from "./BaseClient.mjs";
7
+ import { normalizeClientOptionsWithAuth } from "./BaseClient.mjs";
8
8
  export class CredalClient {
9
9
  constructor(options = {}) {
10
- this._options = normalizeClientOptions(options);
10
+ this._options = normalizeClientOptionsWithAuth(options);
11
11
  }
12
12
  get copilots() {
13
13
  var _a;
@@ -1,4 +1,5 @@
1
1
  import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient.mjs";
2
+ import { type NormalizedClientOptionsWithAuth } from "../../../../BaseClient.mjs";
2
3
  import * as core from "../../../../core/index.mjs";
3
4
  import type * as Credal from "../../../index.mjs";
4
5
  export declare namespace CopilotsClient {
@@ -8,7 +9,7 @@ export declare namespace CopilotsClient {
8
9
  }
9
10
  }
10
11
  export declare class CopilotsClient {
11
- protected readonly _options: CopilotsClient.Options;
12
+ protected readonly _options: NormalizedClientOptionsWithAuth<CopilotsClient.Options>;
12
13
  constructor(options?: CopilotsClient.Options);
13
14
  /**
14
15
  * Create a new agent. The API key used will be added to the agent for future Requests
@@ -146,5 +147,24 @@ export declare class CopilotsClient {
146
147
  */
147
148
  deleteCopilot(request: Credal.DeleteCopilotRequest, requestOptions?: CopilotsClient.RequestOptions): core.HttpResponsePromise<Credal.DeleteCopilotResponse>;
148
149
  private __deleteCopilot;
149
- protected _getAuthorizationHeader(): Promise<string>;
150
+ /**
151
+ * Export copilot configurations for backup or migration purposes.
152
+ *
153
+ * **IMPORTANT**: This endpoint requires:
154
+ * - Admin privileges
155
+ * - The 'ai-usage-analytics-log.export' scope on the API key
156
+ *
157
+ * Returns all deployed copilots with their full configuration including model settings, tools, and deployment details. Optional date filters can be applied to narrow down results.
158
+ *
159
+ * @param {Credal.ExportCopilotsRequest} request
160
+ * @param {CopilotsClient.RequestOptions} requestOptions - Request-specific configuration.
161
+ *
162
+ * @example
163
+ * await client.copilots.export({
164
+ * agentCreatedFrom: "2024-01-01T00:00:00Z",
165
+ * agentCreatedTo: "2024-12-31T23:59:59Z"
166
+ * })
167
+ */
168
+ export(request?: Credal.ExportCopilotsRequest, requestOptions?: CopilotsClient.RequestOptions): core.HttpResponsePromise<Credal.ExportCopilotsResponse>;
169
+ private __export;
150
170
  }
@@ -8,14 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- import { normalizeClientOptions } from "../../../../BaseClient.mjs";
12
- import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.mjs";
11
+ import { normalizeClientOptionsWithAuth } from "../../../../BaseClient.mjs";
12
+ import { mergeHeaders } from "../../../../core/headers.mjs";
13
13
  import * as core from "../../../../core/index.mjs";
14
14
  import * as environments from "../../../../environments.mjs";
15
15
  import * as errors from "../../../../errors/index.mjs";
16
16
  export class CopilotsClient {
17
17
  constructor(options = {}) {
18
- this._options = normalizeClientOptions(options);
18
+ this._options = normalizeClientOptionsWithAuth(options);
19
19
  }
20
20
  /**
21
21
  * Create a new agent. The API key used will be added to the agent for future Requests
@@ -39,7 +39,8 @@ export class CopilotsClient {
39
39
  __createCopilot(request, requestOptions) {
40
40
  return __awaiter(this, void 0, void 0, function* () {
41
41
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
42
- const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
42
+ const _authRequest = yield this._options.authProvider.getAuthRequest();
43
+ const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
43
44
  const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
44
45
  url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/copilots/createCopilot"),
45
46
  method: "POST",
@@ -99,7 +100,8 @@ export class CopilotsClient {
99
100
  __createConversation(request, requestOptions) {
100
101
  return __awaiter(this, void 0, void 0, function* () {
101
102
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
102
- const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
103
+ const _authRequest = yield this._options.authProvider.getAuthRequest();
104
+ const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
103
105
  const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
104
106
  url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/copilots/createConversation"),
105
107
  method: "POST",
@@ -163,7 +165,8 @@ export class CopilotsClient {
163
165
  __provideMessageFeedback(request, requestOptions) {
164
166
  return __awaiter(this, void 0, void 0, function* () {
165
167
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
166
- const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
168
+ const _authRequest = yield this._options.authProvider.getAuthRequest();
169
+ const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
167
170
  const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
168
171
  url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/copilots/provideMessageFeedback"),
169
172
  method: "POST",
@@ -229,7 +232,8 @@ export class CopilotsClient {
229
232
  __sendMessage(request, requestOptions) {
230
233
  return __awaiter(this, void 0, void 0, function* () {
231
234
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
232
- const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
235
+ const _authRequest = yield this._options.authProvider.getAuthRequest();
236
+ const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
233
237
  const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
234
238
  url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/copilots/sendMessage"),
235
239
  method: "POST",
@@ -280,7 +284,8 @@ export class CopilotsClient {
280
284
  __streamMessage(request, requestOptions) {
281
285
  return __awaiter(this, void 0, void 0, function* () {
282
286
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
283
- const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
287
+ const _authRequest = yield this._options.authProvider.getAuthRequest();
288
+ const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
284
289
  const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
285
290
  url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/copilots/streamMessage"),
286
291
  method: "POST",
@@ -352,7 +357,8 @@ export class CopilotsClient {
352
357
  __addCollectionToCopilot(request, requestOptions) {
353
358
  return __awaiter(this, void 0, void 0, function* () {
354
359
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
355
- const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
360
+ const _authRequest = yield this._options.authProvider.getAuthRequest();
361
+ const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
356
362
  const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
357
363
  url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/copilots/addCollectionToCopilot"),
358
364
  method: "POST",
@@ -412,7 +418,8 @@ export class CopilotsClient {
412
418
  __removeCollectionFromCopilot(request, requestOptions) {
413
419
  return __awaiter(this, void 0, void 0, function* () {
414
420
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
415
- const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
421
+ const _authRequest = yield this._options.authProvider.getAuthRequest();
422
+ const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
416
423
  const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
417
424
  url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/copilots/removeCollectionFromCopilot"),
418
425
  method: "POST",
@@ -480,7 +487,8 @@ export class CopilotsClient {
480
487
  __updateConfiguration(request, requestOptions) {
481
488
  return __awaiter(this, void 0, void 0, function* () {
482
489
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
483
- const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
490
+ const _authRequest = yield this._options.authProvider.getAuthRequest();
491
+ const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
484
492
  const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
485
493
  url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/copilots/updateConfiguration"),
486
494
  method: "POST",
@@ -537,7 +545,8 @@ export class CopilotsClient {
537
545
  __deleteCopilot(request, requestOptions) {
538
546
  return __awaiter(this, void 0, void 0, function* () {
539
547
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
540
- const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
548
+ const _authRequest = yield this._options.authProvider.getAuthRequest();
549
+ const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
541
550
  const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
542
551
  url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/copilots/deleteCopilot"),
543
552
  method: "DELETE",
@@ -579,16 +588,71 @@ export class CopilotsClient {
579
588
  }
580
589
  });
581
590
  }
582
- _getAuthorizationHeader() {
583
- return __awaiter(this, void 0, void 0, function* () {
584
- var _a;
585
- const bearer = (_a = (yield core.Supplier.get(this._options.apiKey))) !== null && _a !== void 0 ? _a : process === null || process === void 0 ? void 0 : process.env.CREDAL_API_KEY;
586
- if (bearer == null) {
591
+ /**
592
+ * Export copilot configurations for backup or migration purposes.
593
+ *
594
+ * **IMPORTANT**: This endpoint requires:
595
+ * - Admin privileges
596
+ * - The 'ai-usage-analytics-log.export' scope on the API key
597
+ *
598
+ * Returns all deployed copilots with their full configuration including model settings, tools, and deployment details. Optional date filters can be applied to narrow down results.
599
+ *
600
+ * @param {Credal.ExportCopilotsRequest} request
601
+ * @param {CopilotsClient.RequestOptions} requestOptions - Request-specific configuration.
602
+ *
603
+ * @example
604
+ * await client.copilots.export({
605
+ * agentCreatedFrom: "2024-01-01T00:00:00Z",
606
+ * agentCreatedTo: "2024-12-31T23:59:59Z"
607
+ * })
608
+ */
609
+ export(request = {}, requestOptions) {
610
+ return core.HttpResponsePromise.fromPromise(this.__export(request, requestOptions));
611
+ }
612
+ __export() {
613
+ return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
614
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
615
+ const _authRequest = yield this._options.authProvider.getAuthRequest();
616
+ const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
617
+ const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
618
+ url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/copilots/export"),
619
+ method: "POST",
620
+ headers: _headers,
621
+ contentType: "application/json",
622
+ queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
623
+ requestType: "json",
624
+ body: request,
625
+ timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
626
+ maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
627
+ abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
628
+ fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
629
+ logging: this._options.logging,
630
+ });
631
+ if (_response.ok) {
632
+ return { data: _response.body, rawResponse: _response.rawResponse };
633
+ }
634
+ if (_response.error.reason === "status-code") {
587
635
  throw new errors.CredalError({
588
- message: "Please specify a bearer by either passing it in to the constructor or initializing a CREDAL_API_KEY environment variable",
636
+ statusCode: _response.error.statusCode,
637
+ body: _response.error.body,
638
+ rawResponse: _response.rawResponse,
589
639
  });
590
640
  }
591
- return `Bearer ${bearer}`;
641
+ switch (_response.error.reason) {
642
+ case "non-json":
643
+ throw new errors.CredalError({
644
+ statusCode: _response.error.statusCode,
645
+ body: _response.error.rawBody,
646
+ rawResponse: _response.rawResponse,
647
+ });
648
+ case "timeout":
649
+ throw new errors.CredalTimeoutError("Timeout exceeded when calling POST /v0/copilots/export.");
650
+ case "unknown":
651
+ throw new errors.CredalError({
652
+ message: _response.error.errorMessage,
653
+ rawResponse: _response.rawResponse,
654
+ });
655
+ }
592
656
  });
593
657
  }
594
658
  }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @example
3
+ * {
4
+ * agentCreatedFrom: "2024-01-01T00:00:00Z",
5
+ * agentCreatedTo: "2024-12-31T23:59:59Z"
6
+ * }
7
+ */
8
+ export interface ExportCopilotsRequest {
9
+ /** Filter copilots created on or after this datetime (ISO 8601 format). */
10
+ agentCreatedFrom?: string;
11
+ /** Filter copilots created before or on this datetime (ISO 8601 format). */
12
+ agentCreatedTo?: string;
13
+ /** Filter copilot versions created on or after this datetime (ISO 8601 format). */
14
+ versionCreatedFrom?: string;
15
+ /** Filter copilot versions created before or on this datetime (ISO 8601 format). */
16
+ versionCreatedTo?: string;
17
+ /** Maximum number of copilots to return. Must be a positive integer with a maximum value of 1000. Defaults to 100. */
18
+ limit?: number;
19
+ /** Cursor for pagination. Use the cursor returned in the previous response to fetch the next page of results. If not provided, returns the first page. */
20
+ cursor?: string;
21
+ }
@@ -0,0 +1,2 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ export {};
@@ -2,6 +2,7 @@ export type { AddCollectionToCopilotRequest } from "./AddCollectionToCopilotRequ
2
2
  export type { CreateConversationRequest } from "./CreateConversationRequest.mjs";
3
3
  export type { CreateCopilotRequest } from "./CreateCopilotRequest.mjs";
4
4
  export type { DeleteCopilotRequest } from "./DeleteCopilotRequest.mjs";
5
+ export type { ExportCopilotsRequest } from "./ExportCopilotsRequest.mjs";
5
6
  export type { ProvideMessageFeedbackRequest } from "./ProvideMessageFeedbackRequest.mjs";
6
7
  export type { RemoveCollectionFromCopilotRequest } from "./RemoveCollectionFromCopilotRequest.mjs";
7
8
  export type { SendMessageRequest } from "./SendMessageRequest.mjs";
@@ -0,0 +1,9 @@
1
+ import type * as Credal from "../../../index.mjs";
2
+ export interface ExportCopilotsResponse {
3
+ /** List of exported copilots matching the query filters. */
4
+ data: Credal.ExportedCopilot[];
5
+ /** Indicates whether there are more results available for pagination. */
6
+ hasMore: boolean;
7
+ /** Cursor to use for fetching the next page of results. This is a UUID string. If null or not present, there are no more results. */
8
+ nextCursor?: string;
9
+ }
@@ -0,0 +1,2 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ export {};