assistant-cloud 0.1.28 → 0.1.30
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/AssistantCloud.d.ts +15 -11
- package/dist/AssistantCloud.d.ts.map +1 -1
- package/dist/AssistantCloud.js +24 -24
- package/dist/AssistantCloud.js.map +1 -1
- package/dist/AssistantCloudAPI.d.ts +46 -43
- package/dist/AssistantCloudAPI.d.ts.map +1 -1
- package/dist/AssistantCloudAPI.js +66 -79
- package/dist/AssistantCloudAPI.js.map +1 -1
- package/dist/AssistantCloudAuthStrategy.d.ts +28 -25
- package/dist/AssistantCloudAuthStrategy.d.ts.map +1 -1
- package/dist/AssistantCloudAuthStrategy.js +98 -135
- package/dist/AssistantCloudAuthStrategy.js.map +1 -1
- package/dist/AssistantCloudAuthTokens.d.ts +10 -7
- package/dist/AssistantCloudAuthTokens.d.ts.map +1 -1
- package/dist/AssistantCloudAuthTokens.js +13 -9
- package/dist/AssistantCloudAuthTokens.js.map +1 -1
- package/dist/AssistantCloudFiles.d.ts +20 -17
- package/dist/AssistantCloudFiles.d.ts.map +1 -1
- package/dist/AssistantCloudFiles.js +22 -18
- package/dist/AssistantCloudFiles.js.map +1 -1
- package/dist/AssistantCloudRuns.d.ts +53 -50
- package/dist/AssistantCloudRuns.d.ts.map +1 -1
- package/dist/AssistantCloudRuns.js +42 -38
- package/dist/AssistantCloudRuns.js.map +1 -1
- package/dist/AssistantCloudThreadMessages.d.ts +27 -24
- package/dist/AssistantCloudThreadMessages.d.ts.map +1 -1
- package/dist/AssistantCloudThreadMessages.js +25 -15
- package/dist/AssistantCloudThreadMessages.js.map +1 -1
- package/dist/AssistantCloudThreads.d.ts +37 -34
- package/dist/AssistantCloudThreads.d.ts.map +1 -1
- package/dist/AssistantCloudThreads.js +33 -28
- package/dist/AssistantCloudThreads.js.map +1 -1
- package/dist/CloudMessagePersistence.d.ts +49 -44
- package/dist/CloudMessagePersistence.d.ts.map +1 -1
- package/dist/CloudMessagePersistence.js +90 -101
- package/dist/CloudMessagePersistence.js.map +1 -1
- package/dist/FormattedCloudPersistence.d.ts +40 -36
- package/dist/FormattedCloudPersistence.d.ts.map +1 -1
- package/dist/FormattedCloudPersistence.js +32 -36
- package/dist/FormattedCloudPersistence.js.map +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.js +5 -5
- package/dist/instrumentMcpSampling.d.ts +39 -36
- package/dist/instrumentMcpSampling.d.ts.map +1 -1
- package/dist/instrumentMcpSampling.js +61 -68
- package/dist/instrumentMcpSampling.js.map +1 -1
- package/dist/tests/setup.d.ts +1 -2
- package/dist/tests/setup.js +3 -4
- package/dist/tests/setup.js.map +1 -1
- package/package.json +5 -5
- package/src/AssistantCloudAuthStrategy.ts +3 -9
- package/src/tests/AssistantCloudFiles.test.ts +4 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/tests/setup.d.ts.map +0 -1
package/dist/AssistantCloud.d.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { type AssistantCloudConfig, type AssistantCloudTelemetryConfig } from "./AssistantCloudAPI.js";
|
|
2
|
-
import { AssistantCloudAuthTokens } from "./AssistantCloudAuthTokens.js";
|
|
3
1
|
import { AssistantCloudRuns } from "./AssistantCloudRuns.js";
|
|
2
|
+
import { AssistantCloudConfig, AssistantCloudTelemetryConfig } from "./AssistantCloudAPI.js";
|
|
3
|
+
import { AssistantCloudAuthTokens } from "./AssistantCloudAuthTokens.js";
|
|
4
4
|
import { AssistantCloudThreads } from "./AssistantCloudThreads.js";
|
|
5
5
|
import { AssistantCloudFiles } from "./AssistantCloudFiles.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
|
|
7
|
+
//#region src/AssistantCloud.d.ts
|
|
8
|
+
declare class AssistantCloud {
|
|
9
|
+
readonly threads: AssistantCloudThreads;
|
|
10
|
+
readonly auth: {
|
|
11
|
+
tokens: AssistantCloudAuthTokens;
|
|
12
|
+
};
|
|
13
|
+
readonly runs: AssistantCloudRuns;
|
|
14
|
+
readonly files: AssistantCloudFiles;
|
|
15
|
+
readonly telemetry: AssistantCloudTelemetryConfig;
|
|
16
|
+
constructor(config: AssistantCloudConfig);
|
|
15
17
|
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { AssistantCloud };
|
|
16
20
|
//# sourceMappingURL=AssistantCloud.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantCloud.d.ts","
|
|
1
|
+
{"version":3,"file":"AssistantCloud.d.ts","names":[],"sources":["../src/AssistantCloud.ts"],"mappings":";;;;;;;cAUa,cAAA;EAAA,SACK,OAAA,EAAO,qBAAA;EAAA,SACP,IAAA;;;WACA,IAAA,EAAI,kBAAA;EAAA,SACJ,KAAA,EAAK,mBAAA;EAAA,SACL,SAAA,EAAW,6BAAA;cAEf,MAAA,EAAQ,oBAAA;AAAA"}
|
package/dist/AssistantCloud.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { AssistantCloudAPI
|
|
1
|
+
import { AssistantCloudAPI } from "./AssistantCloudAPI.js";
|
|
2
2
|
import { AssistantCloudAuthTokens } from "./AssistantCloudAuthTokens.js";
|
|
3
3
|
import { AssistantCloudRuns } from "./AssistantCloudRuns.js";
|
|
4
4
|
import { AssistantCloudThreads } from "./AssistantCloudThreads.js";
|
|
5
5
|
import { AssistantCloudFiles } from "./AssistantCloudFiles.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
6
|
+
//#region src/AssistantCloud.ts
|
|
7
|
+
var AssistantCloud = class {
|
|
8
|
+
threads;
|
|
9
|
+
auth;
|
|
10
|
+
runs;
|
|
11
|
+
files;
|
|
12
|
+
telemetry;
|
|
13
|
+
constructor(config) {
|
|
14
|
+
const api = new AssistantCloudAPI(config);
|
|
15
|
+
this.threads = new AssistantCloudThreads(api);
|
|
16
|
+
this.auth = { tokens: new AssistantCloudAuthTokens(api) };
|
|
17
|
+
this.runs = new AssistantCloudRuns(api);
|
|
18
|
+
this.files = new AssistantCloudFiles(api);
|
|
19
|
+
const t = config.telemetry;
|
|
20
|
+
this.telemetry = t === false ? { enabled: false } : t === true || t === void 0 ? { enabled: true } : {
|
|
21
|
+
enabled: t.enabled !== false,
|
|
22
|
+
...t
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { AssistantCloud };
|
|
28
|
+
|
|
29
29
|
//# sourceMappingURL=AssistantCloud.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantCloud.js","
|
|
1
|
+
{"version":3,"file":"AssistantCloud.js","names":[],"sources":["../src/AssistantCloud.ts"],"sourcesContent":["import {\n AssistantCloudAPI,\n type AssistantCloudConfig,\n type AssistantCloudTelemetryConfig,\n} from \"./AssistantCloudAPI\";\nimport { AssistantCloudAuthTokens } from \"./AssistantCloudAuthTokens\";\nimport { AssistantCloudRuns } from \"./AssistantCloudRuns\";\nimport { AssistantCloudThreads } from \"./AssistantCloudThreads\";\nimport { AssistantCloudFiles } from \"./AssistantCloudFiles\";\n\nexport class AssistantCloud {\n public readonly threads;\n public readonly auth;\n public readonly runs;\n public readonly files;\n public readonly telemetry: AssistantCloudTelemetryConfig;\n\n constructor(config: AssistantCloudConfig) {\n const api = new AssistantCloudAPI(config);\n this.threads = new AssistantCloudThreads(api);\n this.auth = {\n tokens: new AssistantCloudAuthTokens(api),\n };\n this.runs = new AssistantCloudRuns(api);\n this.files = new AssistantCloudFiles(api);\n\n const t = config.telemetry;\n this.telemetry =\n t === false\n ? { enabled: false }\n : t === true || t === undefined\n ? { enabled: true }\n : { enabled: t.enabled !== false, ...t };\n }\n}\n"],"mappings":";;;;;;AAUA,IAAa,iBAAb,MAA4B;CAC1B;CACA;CACA;CACA;CACA;CAEA,YAAY,QAA8B;EACxC,MAAM,MAAM,IAAI,kBAAkB,MAAM;EACxC,KAAK,UAAU,IAAI,sBAAsB,GAAG;EAC5C,KAAK,OAAO,EACV,QAAQ,IAAI,yBAAyB,GAAG,EAC1C;EACA,KAAK,OAAO,IAAI,mBAAmB,GAAG;EACtC,KAAK,QAAQ,IAAI,oBAAoB,GAAG;EAExC,MAAM,IAAI,OAAO;EACjB,KAAK,YACH,MAAM,QACF,EAAE,SAAS,MAAM,IACjB,MAAM,QAAQ,MAAM,KAAA,IAClB,EAAE,SAAS,KAAK,IAChB;GAAE,SAAS,EAAE,YAAY;GAAO,GAAG;EAAE;CAC/C;AACF"}
|
|
@@ -1,52 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { AssistantCloudAuthStrategy } from "./AssistantCloudAuthStrategy.js";
|
|
2
|
+
import { AssistantCloudRunReport } from "./AssistantCloudRuns.js";
|
|
3
|
+
|
|
4
|
+
//#region src/AssistantCloudAPI.d.ts
|
|
5
|
+
type AssistantCloudTelemetryConfig = {
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Called before each telemetry report is sent.
|
|
9
|
+
* Return a modified report to enrich it (e.g. add `model_id`),
|
|
10
|
+
* or return `null` to skip the report.
|
|
11
|
+
*/
|
|
12
|
+
beforeReport?: (report: AssistantCloudRunReport) => AssistantCloudRunReport | null;
|
|
11
13
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
type AssistantCloudConfig = ({
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
authToken: () => Promise<string | null>;
|
|
15
17
|
} | {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
apiKey: string;
|
|
20
|
+
userId: string;
|
|
21
|
+
workspaceId: string;
|
|
20
22
|
} | {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
baseUrl: string;
|
|
24
|
+
anonymous: true;
|
|
23
25
|
}) & {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Client-side run telemetry reporting. Default: `true`.
|
|
28
|
+
*
|
|
29
|
+
* When enabled, the SDK automatically reports run metadata (status, step
|
|
30
|
+
* count, tool calls, and token usage) to Assistant Cloud after each
|
|
31
|
+
* assistant message is saved. No message content is sent.
|
|
32
|
+
*
|
|
33
|
+
* - `true` / `undefined` — enabled with defaults
|
|
34
|
+
* - `false` — disabled
|
|
35
|
+
* - `{ beforeReport }` — enabled with a hook to enrich or filter reports
|
|
36
|
+
*/
|
|
37
|
+
telemetry?: boolean | AssistantCloudTelemetryConfig;
|
|
36
38
|
};
|
|
37
39
|
type MakeRequestOptions = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
method?: "POST" | "PUT" | "DELETE" | undefined;
|
|
41
|
+
headers?: Record<string, string> | undefined;
|
|
42
|
+
query?: Record<string, string | number | boolean> | undefined;
|
|
43
|
+
body?: object | undefined;
|
|
42
44
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
declare class AssistantCloudAPI {
|
|
46
|
+
_auth: AssistantCloudAuthStrategy;
|
|
47
|
+
_baseUrl: string;
|
|
48
|
+
constructor(config: AssistantCloudConfig);
|
|
49
|
+
initializeAuth(): Promise<boolean>;
|
|
50
|
+
makeRawRequest(endpoint: string, options?: MakeRequestOptions): Promise<Response>;
|
|
51
|
+
makeRequest(endpoint: string, options?: MakeRequestOptions): Promise<any>;
|
|
50
52
|
}
|
|
51
|
-
|
|
53
|
+
//#endregion
|
|
54
|
+
export { AssistantCloudAPI, AssistantCloudConfig, AssistantCloudTelemetryConfig };
|
|
52
55
|
//# sourceMappingURL=AssistantCloudAPI.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantCloudAPI.d.ts","
|
|
1
|
+
{"version":3,"file":"AssistantCloudAPI.d.ts","names":[],"sources":["../src/AssistantCloudAPI.ts"],"mappings":";;;;KAQY,6BAAA;EACV,OAAA;EADU;;;;;EAOV,YAAA,IACE,MAAA,EAAQ,uBAAA,KACL,uBAAuB;AAAA;AAAA,KAGlB,oBAAA;EAEN,OAAA;EACA,SAAA,QAAiB,OAAA;AAAA;EAGjB,OAAA;EACA,MAAA;EACA,MAAA;EACA,WAAA;AAAA;EAGA,OAAA;EACA,SAAA;AAAA;EANA;;;;;;;;AAoB+C;AACnD;;EADA,SAAA,aAAsB,6BAA6B;AAAA;AAAA,KAUhD,kBAAA;EACH,MAAA;EACA,OAAA,GAAU,MAAA;EACV,KAAA,GAAQ,MAAM;EACd,IAAA;AAAA;AAAA,cAGW,iBAAA;EACJ,KAAA,EAAO,0BAAA;EACP,QAAA;cAEK,MAAA,EAAQ,oBAAA;EAuBP,cAAA,IAAc,OAAA;EAId,cAAA,CACX,QAAA,UACA,OAAA,GAAS,kBAAA,GAAuB,OAAA,CAAA,QAAA;EAkDrB,WAAA,CAAY,QAAA,UAAkB,OAAA,GAAS,kBAAA,GAAuB,OAAA;AAAA"}
|
|
@@ -1,80 +1,67 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
catch (error) {
|
|
68
|
-
if (error instanceof CloudAPIError)
|
|
69
|
-
throw error;
|
|
70
|
-
throw new Error(`Request failed with status ${response.status}, ${text}`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return response;
|
|
74
|
-
}
|
|
75
|
-
async makeRequest(endpoint, options = {}) {
|
|
76
|
-
const response = await this.makeRawRequest(endpoint, options);
|
|
77
|
-
return response.json();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
1
|
+
import { AssistantCloudAPIKeyAuthStrategy, AssistantCloudAnonymousAuthStrategy, AssistantCloudJWTAuthStrategy } from "./AssistantCloudAuthStrategy.js";
|
|
2
|
+
//#region src/AssistantCloudAPI.ts
|
|
3
|
+
var CloudAPIError = class extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "APIError";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
var AssistantCloudAPI = class {
|
|
10
|
+
_auth;
|
|
11
|
+
_baseUrl;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
if ("authToken" in config) {
|
|
14
|
+
this._baseUrl = config.baseUrl;
|
|
15
|
+
this._auth = new AssistantCloudJWTAuthStrategy(config.authToken);
|
|
16
|
+
} else if ("apiKey" in config) {
|
|
17
|
+
this._baseUrl = (config.baseUrl ?? "https://backend.assistant-api.com").replace(/\/$/, "");
|
|
18
|
+
this._auth = new AssistantCloudAPIKeyAuthStrategy(config.apiKey, config.userId, config.workspaceId);
|
|
19
|
+
} else if ("anonymous" in config) {
|
|
20
|
+
this._baseUrl = config.baseUrl;
|
|
21
|
+
this._auth = new AssistantCloudAnonymousAuthStrategy(config.baseUrl);
|
|
22
|
+
} else throw new Error("Invalid configuration: Must provide authToken, apiKey, or anonymous configuration");
|
|
23
|
+
}
|
|
24
|
+
async initializeAuth() {
|
|
25
|
+
return !!this._auth.getAuthHeaders();
|
|
26
|
+
}
|
|
27
|
+
async makeRawRequest(endpoint, options = {}) {
|
|
28
|
+
const authHeaders = await this._auth.getAuthHeaders();
|
|
29
|
+
if (!authHeaders) throw new Error("Authorization failed");
|
|
30
|
+
const headers = {
|
|
31
|
+
...authHeaders,
|
|
32
|
+
...options.headers,
|
|
33
|
+
"Content-Type": "application/json"
|
|
34
|
+
};
|
|
35
|
+
const queryParams = new URLSearchParams();
|
|
36
|
+
if (options.query) for (const [key, value] of Object.entries(options.query)) {
|
|
37
|
+
if (value === false) continue;
|
|
38
|
+
if (value === true) queryParams.set(key, "true");
|
|
39
|
+
else queryParams.set(key, value.toString());
|
|
40
|
+
}
|
|
41
|
+
const url = new URL(`${this._baseUrl}/v1${endpoint}`);
|
|
42
|
+
url.search = queryParams.toString();
|
|
43
|
+
const response = await fetch(url, {
|
|
44
|
+
method: options.method ?? "GET",
|
|
45
|
+
headers,
|
|
46
|
+
body: options.body ? JSON.stringify(options.body) : null
|
|
47
|
+
});
|
|
48
|
+
this._auth.readAuthHeaders(response.headers);
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
const text = await response.text();
|
|
51
|
+
try {
|
|
52
|
+
throw new CloudAPIError(JSON.parse(text).message);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (error instanceof CloudAPIError) throw error;
|
|
55
|
+
throw new Error(`Request failed with status ${response.status}, ${text}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return response;
|
|
59
|
+
}
|
|
60
|
+
async makeRequest(endpoint, options = {}) {
|
|
61
|
+
return (await this.makeRawRequest(endpoint, options)).json();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
export { AssistantCloudAPI };
|
|
66
|
+
|
|
80
67
|
//# sourceMappingURL=AssistantCloudAPI.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantCloudAPI.js","
|
|
1
|
+
{"version":3,"file":"AssistantCloudAPI.js","names":[],"sources":["../src/AssistantCloudAPI.ts"],"sourcesContent":["import {\n type AssistantCloudAuthStrategy,\n AssistantCloudJWTAuthStrategy,\n AssistantCloudAPIKeyAuthStrategy,\n AssistantCloudAnonymousAuthStrategy,\n} from \"./AssistantCloudAuthStrategy\";\nimport type { AssistantCloudRunReport } from \"./AssistantCloudRuns\";\n\nexport type AssistantCloudTelemetryConfig = {\n enabled?: boolean;\n /**\n * Called before each telemetry report is sent.\n * Return a modified report to enrich it (e.g. add `model_id`),\n * or return `null` to skip the report.\n */\n beforeReport?: (\n report: AssistantCloudRunReport,\n ) => AssistantCloudRunReport | null;\n};\n\nexport type AssistantCloudConfig = (\n | {\n baseUrl: string;\n authToken: () => Promise<string | null>;\n }\n | {\n baseUrl?: string;\n apiKey: string;\n userId: string;\n workspaceId: string;\n }\n | {\n baseUrl: string;\n anonymous: true;\n }\n) & {\n /**\n * Client-side run telemetry reporting. Default: `true`.\n *\n * When enabled, the SDK automatically reports run metadata (status, step\n * count, tool calls, and token usage) to Assistant Cloud after each\n * assistant message is saved. No message content is sent.\n *\n * - `true` / `undefined` — enabled with defaults\n * - `false` — disabled\n * - `{ beforeReport }` — enabled with a hook to enrich or filter reports\n */\n telemetry?: boolean | AssistantCloudTelemetryConfig;\n};\n\nclass CloudAPIError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"APIError\";\n }\n}\n\ntype MakeRequestOptions = {\n method?: \"POST\" | \"PUT\" | \"DELETE\" | undefined;\n headers?: Record<string, string> | undefined;\n query?: Record<string, string | number | boolean> | undefined;\n body?: object | undefined;\n};\n\nexport class AssistantCloudAPI {\n public _auth: AssistantCloudAuthStrategy;\n public _baseUrl;\n\n constructor(config: AssistantCloudConfig) {\n if (\"authToken\" in config) {\n this._baseUrl = config.baseUrl;\n this._auth = new AssistantCloudJWTAuthStrategy(config.authToken);\n } else if (\"apiKey\" in config) {\n this._baseUrl = (\n config.baseUrl ?? \"https://backend.assistant-api.com\"\n ).replace(/\\/$/, \"\");\n this._auth = new AssistantCloudAPIKeyAuthStrategy(\n config.apiKey,\n config.userId,\n config.workspaceId,\n );\n } else if (\"anonymous\" in config) {\n this._baseUrl = config.baseUrl;\n this._auth = new AssistantCloudAnonymousAuthStrategy(config.baseUrl);\n } else {\n throw new Error(\n \"Invalid configuration: Must provide authToken, apiKey, or anonymous configuration\",\n );\n }\n }\n\n public async initializeAuth() {\n return !!this._auth.getAuthHeaders();\n }\n\n public async makeRawRequest(\n endpoint: string,\n options: MakeRequestOptions = {},\n ) {\n const authHeaders = await this._auth.getAuthHeaders();\n if (!authHeaders) throw new Error(\"Authorization failed\");\n\n const headers = {\n ...authHeaders,\n ...options.headers,\n \"Content-Type\": \"application/json\",\n };\n\n const queryParams = new URLSearchParams();\n if (options.query) {\n for (const [key, value] of Object.entries(options.query)) {\n if (value === false) continue;\n if (value === true) {\n queryParams.set(key, \"true\");\n } else {\n queryParams.set(key, value.toString());\n }\n }\n }\n\n const url = new URL(`${this._baseUrl}/v1${endpoint}`);\n url.search = queryParams.toString();\n\n const response = await fetch(url, {\n method: options.method ?? \"GET\",\n headers,\n body: options.body ? JSON.stringify(options.body) : null,\n });\n\n this._auth.readAuthHeaders(response.headers);\n\n if (!response.ok) {\n const text = await response.text();\n try {\n const body = JSON.parse(text);\n throw new CloudAPIError(body.message);\n } catch (error) {\n if (error instanceof CloudAPIError) throw error;\n throw new Error(\n `Request failed with status ${response.status}, ${text}`,\n );\n }\n }\n\n return response;\n }\n\n public async makeRequest(endpoint: string, options: MakeRequestOptions = {}) {\n const response = await this.makeRawRequest(endpoint, options);\n return response.json();\n }\n}\n"],"mappings":";;AAkDA,IAAM,gBAAN,cAA4B,MAAM;CAChC,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;AASA,IAAa,oBAAb,MAA+B;CAC7B;CACA;CAEA,YAAY,QAA8B;EACxC,IAAI,eAAe,QAAQ;GACzB,KAAK,WAAW,OAAO;GACvB,KAAK,QAAQ,IAAI,8BAA8B,OAAO,SAAS;EACjE,OAAO,IAAI,YAAY,QAAQ;GAC7B,KAAK,YACH,OAAO,WAAW,qCAClB,QAAQ,OAAO,EAAE;GACnB,KAAK,QAAQ,IAAI,iCACf,OAAO,QACP,OAAO,QACP,OAAO,WACT;EACF,OAAO,IAAI,eAAe,QAAQ;GAChC,KAAK,WAAW,OAAO;GACvB,KAAK,QAAQ,IAAI,oCAAoC,OAAO,OAAO;EACrE,OACE,MAAM,IAAI,MACR,mFACF;CAEJ;CAEA,MAAa,iBAAiB;EAC5B,OAAO,CAAC,CAAC,KAAK,MAAM,eAAe;CACrC;CAEA,MAAa,eACX,UACA,UAA8B,CAAC,GAC/B;EACA,MAAM,cAAc,MAAM,KAAK,MAAM,eAAe;EACpD,IAAI,CAAC,aAAa,MAAM,IAAI,MAAM,sBAAsB;EAExD,MAAM,UAAU;GACd,GAAG;GACH,GAAG,QAAQ;GACX,gBAAgB;EAClB;EAEA,MAAM,cAAc,IAAI,gBAAgB;EACxC,IAAI,QAAQ,OACV,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,KAAK,GAAG;GACxD,IAAI,UAAU,OAAO;GACrB,IAAI,UAAU,MACZ,YAAY,IAAI,KAAK,MAAM;QAE3B,YAAY,IAAI,KAAK,MAAM,SAAS,CAAC;EAEzC;EAGF,MAAM,MAAM,IAAI,IAAI,GAAG,KAAK,SAAS,KAAK,UAAU;EACpD,IAAI,SAAS,YAAY,SAAS;EAElC,MAAM,WAAW,MAAM,MAAM,KAAK;GAChC,QAAQ,QAAQ,UAAU;GAC1B;GACA,MAAM,QAAQ,OAAO,KAAK,UAAU,QAAQ,IAAI,IAAI;EACtD,CAAC;EAED,KAAK,MAAM,gBAAgB,SAAS,OAAO;EAE3C,IAAI,CAAC,SAAS,IAAI;GAChB,MAAM,OAAO,MAAM,SAAS,KAAK;GACjC,IAAI;IAEF,MAAM,IAAI,cADG,KAAK,MAAM,IACG,EAAE,OAAO;GACtC,SAAS,OAAO;IACd,IAAI,iBAAiB,eAAe,MAAM;IAC1C,MAAM,IAAI,MACR,8BAA8B,SAAS,OAAO,IAAI,MACpD;GACF;EACF;EAEA,OAAO;CACT;CAEA,MAAa,YAAY,UAAkB,UAA8B,CAAC,GAAG;EAE3E,QAAO,MADgB,KAAK,eAAe,UAAU,OAAO,GAC5C,KAAK;CACvB;AACF"}
|
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
//#region src/AssistantCloudAuthStrategy.d.ts
|
|
2
|
+
type AssistantCloudAuthStrategy = {
|
|
3
|
+
readonly strategy: "anon" | "jwt" | "api-key";
|
|
4
|
+
getAuthHeaders(): Promise<Record<string, string> | false>;
|
|
5
|
+
readAuthHeaders(headers: Headers): void;
|
|
5
6
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
declare class AssistantCloudJWTAuthStrategy implements AssistantCloudAuthStrategy {
|
|
8
|
+
#private;
|
|
9
|
+
readonly strategy = "jwt";
|
|
10
|
+
private cachedToken;
|
|
11
|
+
private tokenExpiry;
|
|
12
|
+
constructor(authTokenCallback: () => Promise<string | null>);
|
|
13
|
+
getAuthHeaders(): Promise<Record<string, string> | false>;
|
|
14
|
+
readAuthHeaders(headers: Headers): void;
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
declare class AssistantCloudAPIKeyAuthStrategy implements AssistantCloudAuthStrategy {
|
|
17
|
+
#private;
|
|
18
|
+
readonly strategy = "api-key";
|
|
19
|
+
constructor(apiKey: string, userId: string, workspaceId: string);
|
|
20
|
+
getAuthHeaders(): Promise<Record<string, string>>;
|
|
21
|
+
readAuthHeaders(): void;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
declare class AssistantCloudAnonymousAuthStrategy implements AssistantCloudAuthStrategy {
|
|
24
|
+
readonly strategy = "anon";
|
|
25
|
+
private baseUrl;
|
|
26
|
+
private jwtStrategy;
|
|
27
|
+
constructor(baseUrl: string);
|
|
28
|
+
getAuthHeaders(): Promise<Record<string, string> | false>;
|
|
29
|
+
readAuthHeaders(headers: Headers): void;
|
|
29
30
|
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { AssistantCloudAPIKeyAuthStrategy, AssistantCloudAnonymousAuthStrategy, AssistantCloudAuthStrategy, AssistantCloudJWTAuthStrategy };
|
|
30
33
|
//# sourceMappingURL=AssistantCloudAuthStrategy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantCloudAuthStrategy.d.ts","
|
|
1
|
+
{"version":3,"file":"AssistantCloudAuthStrategy.d.ts","names":[],"sources":["../src/AssistantCloudAuthStrategy.ts"],"mappings":";KAAY,0BAAA;EAAA,SACD,QAAA;EACT,cAAA,IAAkB,OAAA,CAAQ,MAAA;EAC1B,eAAA,CAAgB,OAAA,EAAS,OAAA;AAAA;AAAA,cAiCd,6BAAA,YAAyC,0BAAA;EAAA;WACpC,QAAA;EAAA,QAER,WAAA;EAAA,QACA,WAAA;cAGI,iBAAA,QAAyB,OAAA;EAIxB,cAAA,IAAkB,OAAA,CAAQ,MAAA;EAsBhC,eAAA,CAAgB,OAAA,EAAS,OAAA;AAAA;AAAA,cAcrB,gCAAA,YAA4C,0BAAA;EAAA;WACvC,QAAA;cAMJ,MAAA,UAAgB,MAAA,UAAgB,WAAA;EAM/B,cAAA,IAAkB,OAAA,CAAQ,MAAA;EAQhC,eAAA;AAAA;AAAA,cAOI,mCAAA,YAA+C,0BAAA;EAAA,SAC1C,QAAA;EAAA,QAER,OAAA;EAAA,QACA,WAAA;cAEI,OAAA;EA8DC,cAAA,IAAkB,OAAA,CAAQ,MAAA;EAIhC,eAAA,CAAgB,OAAA,EAAS,OAAA;AAAA"}
|