@axiom-lattice/client-sdk 8.1.0 → 8.3.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/dist/__tests__/abstract-client.namespaces.test.js +38 -0
- package/dist/__tests__/abstract-client.namespaces.test.js.map +1 -1
- package/dist/__tests__/platform.test.js +259 -0
- package/dist/__tests__/platform.test.js.map +1 -1
- package/dist/abstract-client.d.ts +37 -0
- package/dist/abstract-client.d.ts.map +1 -1
- package/dist/abstract-client.js +73 -0
- package/dist/abstract-client.js.map +1 -1
- package/dist/index.d.mts +3939 -0
- package/dist/index.d.ts +168 -4
- package/dist/index.js +557 -426
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +550 -419
- package/dist/index.mjs.map +1 -1
- package/dist/oidc-providers.d.ts +2 -2
- package/dist/oidc-providers.d.ts.map +1 -1
- package/dist/platform.d.ts +128 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +253 -1
- package/dist/platform.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
32
32
|
|
|
33
33
|
// src/wechat_lib/encoding-indexes.js
|
|
34
34
|
var require_encoding_indexes = __commonJS({
|
|
35
|
-
"src/wechat_lib/encoding-indexes.js"(
|
|
35
|
+
"src/wechat_lib/encoding-indexes.js"(exports2, module2) {
|
|
36
36
|
"use strict";
|
|
37
37
|
(function(global) {
|
|
38
38
|
"use strict";
|
|
@@ -74,13 +74,13 @@ var require_encoding_indexes = __commonJS({
|
|
|
74
74
|
"windows-1258": [8364, 129, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 138, 8249, 338, 141, 142, 143, 144, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 154, 8250, 339, 157, 158, 376, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 258, 196, 197, 198, 199, 200, 201, 202, 203, 768, 205, 206, 207, 272, 209, 777, 211, 212, 416, 214, 215, 216, 217, 218, 219, 220, 431, 771, 223, 224, 225, 226, 259, 228, 229, 230, 231, 232, 233, 234, 235, 769, 237, 238, 239, 273, 241, 803, 243, 244, 417, 246, 247, 248, 249, 250, 251, 252, 432, 8363, 255],
|
|
75
75
|
"x-mac-cyrillic": [1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071, 8224, 176, 1168, 163, 167, 8226, 182, 1030, 174, 169, 8482, 1026, 1106, 8800, 1027, 1107, 8734, 177, 8804, 8805, 1110, 181, 1169, 1032, 1028, 1108, 1031, 1111, 1033, 1113, 1034, 1114, 1112, 1029, 172, 8730, 402, 8776, 8710, 171, 187, 8230, 160, 1035, 1115, 1036, 1116, 1109, 8211, 8212, 8220, 8221, 8216, 8217, 247, 8222, 1038, 1118, 1039, 1119, 8470, 1025, 1105, 1103, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 8364]
|
|
76
76
|
};
|
|
77
|
-
})(
|
|
77
|
+
})(exports2 || {});
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
// src/wechat_lib/encoding.js
|
|
82
82
|
var require_encoding = __commonJS({
|
|
83
|
-
"src/wechat_lib/encoding.js"(
|
|
83
|
+
"src/wechat_lib/encoding.js"(exports2, module2) {
|
|
84
84
|
"use strict";
|
|
85
85
|
(function(global) {
|
|
86
86
|
"use strict";
|
|
@@ -95,10 +95,8 @@ var require_encoding = __commonJS({
|
|
|
95
95
|
}
|
|
96
96
|
var floor = Math.floor;
|
|
97
97
|
function ToDictionary(o) {
|
|
98
|
-
if (o === void 0)
|
|
99
|
-
|
|
100
|
-
if (o === Object(o))
|
|
101
|
-
return o;
|
|
98
|
+
if (o === void 0) return {};
|
|
99
|
+
if (o === Object(o)) return o;
|
|
102
100
|
throw TypeError("Could not convert argument to dictionary");
|
|
103
101
|
}
|
|
104
102
|
function stringToCodePoints(string) {
|
|
@@ -723,8 +721,7 @@ var require_encoding = __commonJS({
|
|
|
723
721
|
var encoders = {};
|
|
724
722
|
var decoders = {};
|
|
725
723
|
function indexCodePointFor(pointer, index2) {
|
|
726
|
-
if (!index2)
|
|
727
|
-
return null;
|
|
724
|
+
if (!index2) return null;
|
|
728
725
|
return index2[pointer] || null;
|
|
729
726
|
}
|
|
730
727
|
function indexPointerFor(code_point, index2) {
|
|
@@ -740,8 +737,7 @@ var require_encoding = __commonJS({
|
|
|
740
737
|
function indexGB18030RangesCodePointFor(pointer) {
|
|
741
738
|
if (pointer > 39419 && pointer < 189e3 || pointer > 1237575)
|
|
742
739
|
return null;
|
|
743
|
-
if (pointer === 7457)
|
|
744
|
-
return 59335;
|
|
740
|
+
if (pointer === 7457) return 59335;
|
|
745
741
|
var offset = 0;
|
|
746
742
|
var code_point_offset = 0;
|
|
747
743
|
var idx = index("gb18030-ranges");
|
|
@@ -758,8 +754,7 @@ var require_encoding = __commonJS({
|
|
|
758
754
|
return code_point_offset + pointer - offset;
|
|
759
755
|
}
|
|
760
756
|
function indexGB18030RangesPointerFor(code_point) {
|
|
761
|
-
if (code_point === 59335)
|
|
762
|
-
return 7457;
|
|
757
|
+
if (code_point === 59335) return 7457;
|
|
763
758
|
var offset = 0;
|
|
764
759
|
var pointer_offset = 0;
|
|
765
760
|
var idx = index("gb18030-ranges");
|
|
@@ -1821,13 +1816,13 @@ var require_encoding = __commonJS({
|
|
|
1821
1816
|
EncodingIndexes: global["encoding-indexes"]
|
|
1822
1817
|
};
|
|
1823
1818
|
}
|
|
1824
|
-
})(
|
|
1819
|
+
})(exports2 || {});
|
|
1825
1820
|
}
|
|
1826
1821
|
});
|
|
1827
1822
|
|
|
1828
1823
|
// src/index.ts
|
|
1829
|
-
var
|
|
1830
|
-
__export(
|
|
1824
|
+
var index_exports = {};
|
|
1825
|
+
__export(index_exports, {
|
|
1831
1826
|
AbstractClient: () => AbstractClient,
|
|
1832
1827
|
ApiError: () => ApiError,
|
|
1833
1828
|
AuthenticationError: () => AuthenticationError,
|
|
@@ -1853,7 +1848,7 @@ __export(src_exports, {
|
|
|
1853
1848
|
createSimpleMessageMerger: () => createSimpleMessageMerger,
|
|
1854
1849
|
normalizeToolResult: () => normalizeToolResult
|
|
1855
1850
|
});
|
|
1856
|
-
module.exports = __toCommonJS(
|
|
1851
|
+
module.exports = __toCommonJS(index_exports);
|
|
1857
1852
|
|
|
1858
1853
|
// src/types.ts
|
|
1859
1854
|
var ApiError = class extends Error {
|
|
@@ -1923,8 +1918,7 @@ async function* parseSseBody(body, options = {}) {
|
|
|
1923
1918
|
} catch {
|
|
1924
1919
|
throw new SseParseError("Invalid SSE JSON");
|
|
1925
1920
|
}
|
|
1926
|
-
if (options.strictJsonObject && (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)))
|
|
1927
|
-
throw new SseParseError("SSE data must be an object");
|
|
1921
|
+
if (options.strictJsonObject && (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))) throw new SseParseError("SSE data must be an object");
|
|
1928
1922
|
const result = { event, data: parsed, ...id === void 0 ? {} : { id }, ...retry === void 0 ? {} : { retry } };
|
|
1929
1923
|
event = "";
|
|
1930
1924
|
id = void 0;
|
|
@@ -1934,25 +1928,18 @@ async function* parseSseBody(body, options = {}) {
|
|
|
1934
1928
|
};
|
|
1935
1929
|
const processLine = (raw) => {
|
|
1936
1930
|
const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
|
|
1937
|
-
if (line === "")
|
|
1938
|
-
|
|
1939
|
-
if (line.startsWith(":"))
|
|
1940
|
-
return void 0;
|
|
1931
|
+
if (line === "") return dispatch();
|
|
1932
|
+
if (line.startsWith(":")) return void 0;
|
|
1941
1933
|
const separator = line.indexOf(":");
|
|
1942
1934
|
const field = separator < 0 ? line : line.slice(0, separator);
|
|
1943
1935
|
let value = separator < 0 ? "" : line.slice(separator + 1);
|
|
1944
|
-
if (value.startsWith(" "))
|
|
1945
|
-
|
|
1946
|
-
if (field === "
|
|
1947
|
-
|
|
1948
|
-
else if (field === "data")
|
|
1949
|
-
data.push(value);
|
|
1950
|
-
else if (field === "id")
|
|
1951
|
-
id = value;
|
|
1936
|
+
if (value.startsWith(" ")) value = value.slice(1);
|
|
1937
|
+
if (field === "event") event = value;
|
|
1938
|
+
else if (field === "data") data.push(value);
|
|
1939
|
+
else if (field === "id") id = value;
|
|
1952
1940
|
else if (field === "retry") {
|
|
1953
1941
|
const parsed = Number(value);
|
|
1954
|
-
if (!Number.isInteger(parsed) || parsed < 0 || !Number.isFinite(parsed))
|
|
1955
|
-
throw new SseParseError("Invalid SSE retry");
|
|
1942
|
+
if (!Number.isInteger(parsed) || parsed < 0 || !Number.isFinite(parsed)) throw new SseParseError("Invalid SSE retry");
|
|
1956
1943
|
retry = parsed;
|
|
1957
1944
|
}
|
|
1958
1945
|
return void 0;
|
|
@@ -1967,23 +1954,19 @@ async function* parseSseBody(body, options = {}) {
|
|
|
1967
1954
|
buffer += decoder.decode(chunk.value, { stream: true });
|
|
1968
1955
|
let index = findLineBreak(buffer);
|
|
1969
1956
|
while (index >= 0) {
|
|
1970
|
-
if (buffer[index] === "\r" && index === buffer.length - 1)
|
|
1971
|
-
break;
|
|
1957
|
+
if (buffer[index] === "\r" && index === buffer.length - 1) break;
|
|
1972
1958
|
const frame2 = processLine(buffer.slice(0, index));
|
|
1973
1959
|
buffer = buffer.slice(index + lineBreakLength(buffer, index));
|
|
1974
|
-
if (frame2)
|
|
1975
|
-
yield frame2;
|
|
1960
|
+
if (frame2) yield frame2;
|
|
1976
1961
|
index = findLineBreak(buffer);
|
|
1977
1962
|
}
|
|
1978
1963
|
}
|
|
1979
1964
|
if (buffer) {
|
|
1980
1965
|
const frame2 = processLine(buffer);
|
|
1981
|
-
if (frame2)
|
|
1982
|
-
yield frame2;
|
|
1966
|
+
if (frame2) yield frame2;
|
|
1983
1967
|
}
|
|
1984
1968
|
const frame = processLine("");
|
|
1985
|
-
if (frame)
|
|
1986
|
-
yield frame;
|
|
1969
|
+
if (frame) yield frame;
|
|
1987
1970
|
} finally {
|
|
1988
1971
|
await reader.cancel().catch(() => void 0);
|
|
1989
1972
|
reader.releaseLock();
|
|
@@ -1992,10 +1975,8 @@ async function* parseSseBody(body, options = {}) {
|
|
|
1992
1975
|
function findLineBreak(value) {
|
|
1993
1976
|
const lf = value.indexOf("\n");
|
|
1994
1977
|
const cr = value.indexOf("\r");
|
|
1995
|
-
if (lf < 0)
|
|
1996
|
-
|
|
1997
|
-
if (cr < 0)
|
|
1998
|
-
return lf;
|
|
1978
|
+
if (lf < 0) return cr;
|
|
1979
|
+
if (cr < 0) return lf;
|
|
1999
1980
|
return Math.min(lf, cr);
|
|
2000
1981
|
}
|
|
2001
1982
|
function lineBreakLength(value, index) {
|
|
@@ -2304,20 +2285,13 @@ var AbstractClient = class {
|
|
|
2304
2285
|
*/
|
|
2305
2286
|
auditLogs: async (params) => {
|
|
2306
2287
|
const searchParams = new URLSearchParams();
|
|
2307
|
-
if (params?.credentialId)
|
|
2308
|
-
|
|
2309
|
-
if (params?.
|
|
2310
|
-
|
|
2311
|
-
if (params?.
|
|
2312
|
-
|
|
2313
|
-
if (params?.
|
|
2314
|
-
searchParams.set("from", params.from);
|
|
2315
|
-
if (params?.to)
|
|
2316
|
-
searchParams.set("to", params.to);
|
|
2317
|
-
if (params?.limit !== void 0)
|
|
2318
|
-
searchParams.set("limit", String(params.limit));
|
|
2319
|
-
if (params?.offset !== void 0)
|
|
2320
|
-
searchParams.set("offset", String(params.offset));
|
|
2288
|
+
if (params?.credentialId) searchParams.set("credentialId", params.credentialId);
|
|
2289
|
+
if (params?.domain) searchParams.set("domain", params.domain);
|
|
2290
|
+
if (params?.status) searchParams.set("status", params.status);
|
|
2291
|
+
if (params?.from) searchParams.set("from", params.from);
|
|
2292
|
+
if (params?.to) searchParams.set("to", params.to);
|
|
2293
|
+
if (params?.limit !== void 0) searchParams.set("limit", String(params.limit));
|
|
2294
|
+
if (params?.offset !== void 0) searchParams.set("offset", String(params.offset));
|
|
2321
2295
|
const qs = searchParams.toString();
|
|
2322
2296
|
const response = await this.makeRequest(`/api/open/audit${qs ? `?${qs}` : ""}`);
|
|
2323
2297
|
return response.data.records;
|
|
@@ -2365,12 +2339,9 @@ var AbstractClient = class {
|
|
|
2365
2339
|
*/
|
|
2366
2340
|
list: async (params) => {
|
|
2367
2341
|
const searchParams = new URLSearchParams();
|
|
2368
|
-
if (params?.tenantId)
|
|
2369
|
-
|
|
2370
|
-
if (params?.
|
|
2371
|
-
searchParams.set("limit", String(params.limit));
|
|
2372
|
-
if (params?.offset !== void 0)
|
|
2373
|
-
searchParams.set("offset", String(params.offset));
|
|
2342
|
+
if (params?.tenantId) searchParams.set("tenantId", params.tenantId);
|
|
2343
|
+
if (params?.limit !== void 0) searchParams.set("limit", String(params.limit));
|
|
2344
|
+
if (params?.offset !== void 0) searchParams.set("offset", String(params.offset));
|
|
2374
2345
|
const qs = searchParams.toString();
|
|
2375
2346
|
const response = await this.makeRequest(`/api/a2a/keys${qs ? `?${qs}` : ""}`);
|
|
2376
2347
|
return response.data;
|
|
@@ -2788,14 +2759,26 @@ var AbstractClient = class {
|
|
|
2788
2759
|
method: "POST",
|
|
2789
2760
|
body: data
|
|
2790
2761
|
});
|
|
2791
|
-
if (!response.data)
|
|
2792
|
-
throw new ApiError("Failed to create entry", 500);
|
|
2762
|
+
if (!response.data) throw new ApiError("Failed to create entry", 500);
|
|
2793
2763
|
return response.data;
|
|
2794
2764
|
},
|
|
2765
|
+
/**
|
|
2766
|
+
* Creates 1-50 entries in one all-or-nothing vector-store write.
|
|
2767
|
+
*
|
|
2768
|
+
* @param data - Batch payload with one or more entries.
|
|
2769
|
+
* @returns The created entries with generated ids.
|
|
2770
|
+
*/
|
|
2771
|
+
createMany: async (data) => {
|
|
2772
|
+
const response = await this.makeRequest(`/api/collections/${collectionName}/entries/batch`, {
|
|
2773
|
+
method: "POST",
|
|
2774
|
+
body: data
|
|
2775
|
+
});
|
|
2776
|
+
if (!response.data?.records) throw new ApiError("Failed to create entries", 500);
|
|
2777
|
+
return response.data.records;
|
|
2778
|
+
},
|
|
2795
2779
|
get: async (id) => {
|
|
2796
2780
|
const response = await this.makeRequest(`/api/collections/${collectionName}/entries/${id}`);
|
|
2797
|
-
if (!response.data)
|
|
2798
|
-
throw new ApiError("Entry not found", 404);
|
|
2781
|
+
if (!response.data) throw new ApiError("Entry not found", 404);
|
|
2799
2782
|
return response.data;
|
|
2800
2783
|
},
|
|
2801
2784
|
update: async (id, data) => {
|
|
@@ -2803,8 +2786,7 @@ var AbstractClient = class {
|
|
|
2803
2786
|
method: "PUT",
|
|
2804
2787
|
body: data
|
|
2805
2788
|
});
|
|
2806
|
-
if (!response.data)
|
|
2807
|
-
throw new ApiError("Failed to update entry", 500);
|
|
2789
|
+
if (!response.data) throw new ApiError("Failed to update entry", 500);
|
|
2808
2790
|
return response.data;
|
|
2809
2791
|
},
|
|
2810
2792
|
delete: async (id) => {
|
|
@@ -2813,6 +2795,22 @@ var AbstractClient = class {
|
|
|
2813
2795
|
{ method: "DELETE" }
|
|
2814
2796
|
);
|
|
2815
2797
|
},
|
|
2798
|
+
/**
|
|
2799
|
+
* Deletes 1-50 entries in one all-or-nothing vector-store call.
|
|
2800
|
+
*
|
|
2801
|
+
* @param entryIds - Entry IDs to delete.
|
|
2802
|
+
* @returns The number of requested entry IDs processed by the delete call.
|
|
2803
|
+
*/
|
|
2804
|
+
deleteMany: async (entryIds) => {
|
|
2805
|
+
const response = await this.makeRequest(`/api/collections/${collectionName}/entries/batch`, {
|
|
2806
|
+
method: "DELETE",
|
|
2807
|
+
body: { entryIds }
|
|
2808
|
+
});
|
|
2809
|
+
if (typeof response.data?.processed !== "number") {
|
|
2810
|
+
throw new ApiError("Failed to delete entries", 500);
|
|
2811
|
+
}
|
|
2812
|
+
return response.data.processed;
|
|
2813
|
+
},
|
|
2816
2814
|
search: async (query, opts) => {
|
|
2817
2815
|
const response = await this.makeRequest(`/api/collections/${collectionName}/search`, {
|
|
2818
2816
|
method: "POST",
|
|
@@ -3116,14 +3114,10 @@ var AbstractClient = class {
|
|
|
3116
3114
|
*/
|
|
3117
3115
|
create: async (threadId, input, options, assistantId) => {
|
|
3118
3116
|
const body = {};
|
|
3119
|
-
if (input !== void 0)
|
|
3120
|
-
|
|
3121
|
-
if (options?.
|
|
3122
|
-
|
|
3123
|
-
if (options?.config !== void 0)
|
|
3124
|
-
body.config = options.config;
|
|
3125
|
-
if (options?.mode !== void 0)
|
|
3126
|
-
body.mode = options.mode;
|
|
3117
|
+
if (input !== void 0) body.input = input;
|
|
3118
|
+
if (options?.command !== void 0) body.command = options.command;
|
|
3119
|
+
if (options?.config !== void 0) body.config = options.config;
|
|
3120
|
+
if (options?.mode !== void 0) body.mode = options.mode;
|
|
3127
3121
|
if (options?.multitaskStrategy !== void 0) {
|
|
3128
3122
|
body.multitask_strategy = options.multitaskStrategy;
|
|
3129
3123
|
}
|
|
@@ -3194,10 +3188,8 @@ var AbstractClient = class {
|
|
|
3194
3188
|
*/
|
|
3195
3189
|
cancel: async (threadId, runId, options, assistantId) => {
|
|
3196
3190
|
const params = new URLSearchParams();
|
|
3197
|
-
if (options?.action !== void 0)
|
|
3198
|
-
|
|
3199
|
-
if (options?.wait !== void 0)
|
|
3200
|
-
params.set("wait", String(options.wait));
|
|
3191
|
+
if (options?.action !== void 0) params.set("action", options.action);
|
|
3192
|
+
if (options?.wait !== void 0) params.set("wait", String(options.wait));
|
|
3201
3193
|
const query = params.toString();
|
|
3202
3194
|
const response = await this.makeRequest(
|
|
3203
3195
|
`/api/assistants/${assistantId ?? this.assistantId}/threads/${threadId}/runs/${runId}/cancel${query ? `?${query}` : ""}`,
|
|
@@ -3305,20 +3297,17 @@ var AbstractClient = class {
|
|
|
3305
3297
|
},
|
|
3306
3298
|
get: async (id) => {
|
|
3307
3299
|
const response = await this.makeRequest(`/api/tools/${id}`);
|
|
3308
|
-
if (!response.data)
|
|
3309
|
-
throw new ApiError("Tool not found", 404);
|
|
3300
|
+
if (!response.data) throw new ApiError("Tool not found", 404);
|
|
3310
3301
|
return response.data;
|
|
3311
3302
|
},
|
|
3312
3303
|
create: async (data) => {
|
|
3313
3304
|
const response = await this.makeRequest("/api/tools", { method: "POST", body: data });
|
|
3314
|
-
if (!response.data)
|
|
3315
|
-
throw new ApiError("Failed to create tool", 500);
|
|
3305
|
+
if (!response.data) throw new ApiError("Failed to create tool", 500);
|
|
3316
3306
|
return response.data;
|
|
3317
3307
|
},
|
|
3318
3308
|
update: async (id, data) => {
|
|
3319
3309
|
const response = await this.makeRequest(`/api/tools/${id}`, { method: "PUT", body: data });
|
|
3320
|
-
if (!response.data)
|
|
3321
|
-
throw new ApiError("Failed to update tool", 500);
|
|
3310
|
+
if (!response.data) throw new ApiError("Failed to update tool", 500);
|
|
3322
3311
|
return response.data;
|
|
3323
3312
|
},
|
|
3324
3313
|
delete: async (id) => {
|
|
@@ -3332,20 +3321,17 @@ var AbstractClient = class {
|
|
|
3332
3321
|
},
|
|
3333
3322
|
get: async (id) => {
|
|
3334
3323
|
const response = await this.makeRequest(`/api/database-configs/${id}`);
|
|
3335
|
-
if (!response.data)
|
|
3336
|
-
throw new ApiError("Database config not found", 404);
|
|
3324
|
+
if (!response.data) throw new ApiError("Database config not found", 404);
|
|
3337
3325
|
return response.data;
|
|
3338
3326
|
},
|
|
3339
3327
|
create: async (data) => {
|
|
3340
3328
|
const response = await this.makeRequest("/api/database-configs", { method: "POST", body: data });
|
|
3341
|
-
if (!response.data)
|
|
3342
|
-
throw new ApiError("Failed to create database config", 500);
|
|
3329
|
+
if (!response.data) throw new ApiError("Failed to create database config", 500);
|
|
3343
3330
|
return response.data;
|
|
3344
3331
|
},
|
|
3345
3332
|
update: async (id, data) => {
|
|
3346
3333
|
const response = await this.makeRequest(`/api/database-configs/${id}`, { method: "PUT", body: data });
|
|
3347
|
-
if (!response.data)
|
|
3348
|
-
throw new ApiError("Failed to update database config", 500);
|
|
3334
|
+
if (!response.data) throw new ApiError("Failed to update database config", 500);
|
|
3349
3335
|
return response.data;
|
|
3350
3336
|
},
|
|
3351
3337
|
delete: async (id) => {
|
|
@@ -3362,20 +3348,17 @@ var AbstractClient = class {
|
|
|
3362
3348
|
},
|
|
3363
3349
|
get: async (id) => {
|
|
3364
3350
|
const response = await this.makeRequest(`/api/model-providers/${encodeURIComponent(id)}`);
|
|
3365
|
-
if (!response.data)
|
|
3366
|
-
throw new ApiError("Model provider not found", 404);
|
|
3351
|
+
if (!response.data) throw new ApiError("Model provider not found", 404);
|
|
3367
3352
|
return response.data;
|
|
3368
3353
|
},
|
|
3369
3354
|
create: async (data) => {
|
|
3370
3355
|
const response = await this.makeRequest("/api/model-providers", { method: "POST", body: data });
|
|
3371
|
-
if (!response.data)
|
|
3372
|
-
throw new ApiError("Failed to create model provider", 500);
|
|
3356
|
+
if (!response.data) throw new ApiError("Failed to create model provider", 500);
|
|
3373
3357
|
return response.data;
|
|
3374
3358
|
},
|
|
3375
3359
|
update: async (id, data) => {
|
|
3376
3360
|
const response = await this.makeRequest(`/api/model-providers/${encodeURIComponent(id)}`, { method: "PUT", body: data });
|
|
3377
|
-
if (!response.data)
|
|
3378
|
-
throw new ApiError("Failed to update model provider", 500);
|
|
3361
|
+
if (!response.data) throw new ApiError("Failed to update model provider", 500);
|
|
3379
3362
|
return response.data;
|
|
3380
3363
|
},
|
|
3381
3364
|
delete: async (id) => {
|
|
@@ -3385,8 +3368,7 @@ var AbstractClient = class {
|
|
|
3385
3368
|
// provider form to validate before saving.
|
|
3386
3369
|
probe: async (data) => {
|
|
3387
3370
|
const response = await this.makeRequest("/api/model-providers/probe", { method: "POST", body: data });
|
|
3388
|
-
if (!response.data)
|
|
3389
|
-
throw new ApiError("Failed to probe model provider", 500);
|
|
3371
|
+
if (!response.data) throw new ApiError("Failed to probe model provider", 500);
|
|
3390
3372
|
return response.data;
|
|
3391
3373
|
},
|
|
3392
3374
|
// Replace this provider's model set with exactly these models, picked
|
|
@@ -3394,22 +3376,19 @@ var AbstractClient = class {
|
|
|
3394
3376
|
// model arrives as `enabled: false` rather than being dropped.
|
|
3395
3377
|
setModels: async (id, models) => {
|
|
3396
3378
|
const response = await this.makeRequest(`/api/model-providers/${encodeURIComponent(id)}/models`, { method: "PUT", body: { models } });
|
|
3397
|
-
if (!response.data)
|
|
3398
|
-
throw new ApiError("Failed to update models", 500);
|
|
3379
|
+
if (!response.data) throw new ApiError("Failed to update models", 500);
|
|
3399
3380
|
return response.data;
|
|
3400
3381
|
},
|
|
3401
3382
|
discover: async (id) => {
|
|
3402
3383
|
const response = await this.makeRequest(`/api/model-providers/${encodeURIComponent(id)}/discover`, { method: "POST", body: {} });
|
|
3403
|
-
if (!response.data)
|
|
3404
|
-
throw new ApiError("Failed to discover models", 500);
|
|
3384
|
+
if (!response.data) throw new ApiError("Failed to discover models", 500);
|
|
3405
3385
|
return response.data;
|
|
3406
3386
|
},
|
|
3407
3387
|
// The model id travels in the body because upstream ids routinely
|
|
3408
3388
|
// contain "/" (e.g. Qwen/Qwen2.5-7B-Instruct).
|
|
3409
3389
|
setModelEnabled: async (id, modelId, enabled) => {
|
|
3410
3390
|
const response = await this.makeRequest(`/api/model-providers/${encodeURIComponent(id)}/models/enabled`, { method: "POST", body: { modelId, enabled } });
|
|
3411
|
-
if (!response.data)
|
|
3412
|
-
throw new ApiError("Failed to update model", 500);
|
|
3391
|
+
if (!response.data) throw new ApiError("Failed to update model", 500);
|
|
3413
3392
|
return response.data;
|
|
3414
3393
|
}
|
|
3415
3394
|
};
|
|
@@ -3426,20 +3405,17 @@ var AbstractClient = class {
|
|
|
3426
3405
|
},
|
|
3427
3406
|
get: async (id) => {
|
|
3428
3407
|
const response = await this.makeRequest(`/api/metrics-configs/${id}`);
|
|
3429
|
-
if (!response.data)
|
|
3430
|
-
throw new ApiError("Metrics config not found", 404);
|
|
3408
|
+
if (!response.data) throw new ApiError("Metrics config not found", 404);
|
|
3431
3409
|
return response.data;
|
|
3432
3410
|
},
|
|
3433
3411
|
create: async (data) => {
|
|
3434
3412
|
const response = await this.makeRequest("/api/metrics-configs", { method: "POST", body: data });
|
|
3435
|
-
if (!response.data)
|
|
3436
|
-
throw new ApiError("Failed to create metrics config", 500);
|
|
3413
|
+
if (!response.data) throw new ApiError("Failed to create metrics config", 500);
|
|
3437
3414
|
return response.data;
|
|
3438
3415
|
},
|
|
3439
3416
|
update: async (id, data) => {
|
|
3440
3417
|
const response = await this.makeRequest(`/api/metrics-configs/${id}`, { method: "PUT", body: data });
|
|
3441
|
-
if (!response.data)
|
|
3442
|
-
throw new ApiError("Failed to update metrics config", 500);
|
|
3418
|
+
if (!response.data) throw new ApiError("Failed to update metrics config", 500);
|
|
3443
3419
|
return response.data;
|
|
3444
3420
|
},
|
|
3445
3421
|
delete: async (id) => {
|
|
@@ -3460,20 +3436,17 @@ var AbstractClient = class {
|
|
|
3460
3436
|
},
|
|
3461
3437
|
get: async (id) => {
|
|
3462
3438
|
const response = await this.makeRequest(`/api/mcp-servers/${id}`);
|
|
3463
|
-
if (!response.data)
|
|
3464
|
-
throw new ApiError("MCP server config not found", 404);
|
|
3439
|
+
if (!response.data) throw new ApiError("MCP server config not found", 404);
|
|
3465
3440
|
return response.data;
|
|
3466
3441
|
},
|
|
3467
3442
|
create: async (data) => {
|
|
3468
3443
|
const response = await this.makeRequest("/api/mcp-servers", { method: "POST", body: data });
|
|
3469
|
-
if (!response.data)
|
|
3470
|
-
throw new ApiError("Failed to create MCP server config", 500);
|
|
3444
|
+
if (!response.data) throw new ApiError("Failed to create MCP server config", 500);
|
|
3471
3445
|
return response.data;
|
|
3472
3446
|
},
|
|
3473
3447
|
update: async (id, data) => {
|
|
3474
3448
|
const response = await this.makeRequest(`/api/mcp-servers/${id}`, { method: "PUT", body: data });
|
|
3475
|
-
if (!response.data)
|
|
3476
|
-
throw new ApiError("Failed to update MCP server config", 500);
|
|
3449
|
+
if (!response.data) throw new ApiError("Failed to update MCP server config", 500);
|
|
3477
3450
|
return response.data;
|
|
3478
3451
|
},
|
|
3479
3452
|
delete: async (id) => {
|
|
@@ -3484,14 +3457,49 @@ var AbstractClient = class {
|
|
|
3484
3457
|
},
|
|
3485
3458
|
connect: async (id) => {
|
|
3486
3459
|
const response = await this.makeRequest(`/api/mcp-servers/${id}/connect`, { method: "POST" });
|
|
3487
|
-
if (!response.data)
|
|
3488
|
-
throw new ApiError("Failed to connect MCP server", 500);
|
|
3460
|
+
if (!response.data) throw new ApiError("Failed to connect MCP server", 500);
|
|
3489
3461
|
return response.data;
|
|
3490
3462
|
},
|
|
3491
3463
|
disconnect: async (id) => {
|
|
3492
3464
|
const response = await this.makeRequest(`/api/mcp-servers/${id}/disconnect`, { method: "POST" });
|
|
3493
|
-
if (!response.data)
|
|
3494
|
-
|
|
3465
|
+
if (!response.data) throw new ApiError("Failed to disconnect MCP server", 500);
|
|
3466
|
+
return response.data;
|
|
3467
|
+
}
|
|
3468
|
+
};
|
|
3469
|
+
this.personalMcpServers = {
|
|
3470
|
+
list: async () => {
|
|
3471
|
+
const response = await this.makeRequest("/api/personal-mcp-servers");
|
|
3472
|
+
return response.data.records;
|
|
3473
|
+
},
|
|
3474
|
+
get: async (keyOrId) => {
|
|
3475
|
+
const response = await this.makeRequest(`/api/personal-mcp-servers/${keyOrId}`);
|
|
3476
|
+
if (!response.data) throw new ApiError("Personal MCP server config not found", 404);
|
|
3477
|
+
return response.data;
|
|
3478
|
+
},
|
|
3479
|
+
create: async (data) => {
|
|
3480
|
+
const response = await this.makeRequest("/api/personal-mcp-servers", { method: "POST", body: data });
|
|
3481
|
+
if (!response.data) throw new ApiError("Failed to create personal MCP server config", 500);
|
|
3482
|
+
return response.data;
|
|
3483
|
+
},
|
|
3484
|
+
update: async (keyOrId, data) => {
|
|
3485
|
+
const response = await this.makeRequest(`/api/personal-mcp-servers/${keyOrId}`, { method: "PUT", body: data });
|
|
3486
|
+
if (!response.data) throw new ApiError("Failed to update personal MCP server config", 500);
|
|
3487
|
+
return response.data;
|
|
3488
|
+
},
|
|
3489
|
+
delete: async (keyOrId) => {
|
|
3490
|
+
await this.makeRequest(`/api/personal-mcp-servers/${keyOrId}`, { method: "DELETE" });
|
|
3491
|
+
},
|
|
3492
|
+
test: async (keyOrId) => {
|
|
3493
|
+
return await this.makeRequest(`/api/personal-mcp-servers/${keyOrId}/test`, { method: "POST" });
|
|
3494
|
+
},
|
|
3495
|
+
connect: async (keyOrId) => {
|
|
3496
|
+
const response = await this.makeRequest(`/api/personal-mcp-servers/${keyOrId}/connect`, { method: "POST" });
|
|
3497
|
+
if (!response.data) throw new ApiError("Failed to connect personal MCP server", 500);
|
|
3498
|
+
return response.data;
|
|
3499
|
+
},
|
|
3500
|
+
disconnect: async (keyOrId) => {
|
|
3501
|
+
const response = await this.makeRequest(`/api/personal-mcp-servers/${keyOrId}/disconnect`, { method: "POST" });
|
|
3502
|
+
if (!response.data) throw new ApiError("Failed to disconnect personal MCP server", 500);
|
|
3495
3503
|
return response.data;
|
|
3496
3504
|
}
|
|
3497
3505
|
};
|
|
@@ -3518,20 +3526,17 @@ var AbstractClient = class {
|
|
|
3518
3526
|
},
|
|
3519
3527
|
get: async (id) => {
|
|
3520
3528
|
const response = await this.makeRequest(`/api/tasks/${id}`);
|
|
3521
|
-
if (!response.data)
|
|
3522
|
-
throw new ApiError("Task not found", 404);
|
|
3529
|
+
if (!response.data) throw new ApiError("Task not found", 404);
|
|
3523
3530
|
return response.data;
|
|
3524
3531
|
},
|
|
3525
3532
|
create: async (data) => {
|
|
3526
3533
|
const response = await this.makeRequest("/api/tasks", { method: "POST", body: data });
|
|
3527
|
-
if (!response.data)
|
|
3528
|
-
throw new ApiError("Failed to create task", 500);
|
|
3534
|
+
if (!response.data) throw new ApiError("Failed to create task", 500);
|
|
3529
3535
|
return response.data;
|
|
3530
3536
|
},
|
|
3531
3537
|
update: async (id, data) => {
|
|
3532
3538
|
const response = await this.makeRequest(`/api/tasks/${id}`, { method: "PUT", body: data });
|
|
3533
|
-
if (!response.data)
|
|
3534
|
-
throw new ApiError("Failed to update task", 500);
|
|
3539
|
+
if (!response.data) throw new ApiError("Failed to update task", 500);
|
|
3535
3540
|
return response.data;
|
|
3536
3541
|
},
|
|
3537
3542
|
delete: async (id) => {
|
|
@@ -3539,25 +3544,20 @@ var AbstractClient = class {
|
|
|
3539
3544
|
},
|
|
3540
3545
|
complete: async (id, data) => {
|
|
3541
3546
|
const response = await this.makeRequest(`/api/tasks/${id}/complete`, { method: "PATCH", body: data });
|
|
3542
|
-
if (!response.data)
|
|
3543
|
-
throw new ApiError("Failed to complete task", 500);
|
|
3547
|
+
if (!response.data) throw new ApiError("Failed to complete task", 500);
|
|
3544
3548
|
return response;
|
|
3545
3549
|
},
|
|
3546
3550
|
command: async (id, input) => {
|
|
3547
3551
|
const response = await this.makeRequest(`/api/tasks/${id}/commands`, { method: "POST", body: input });
|
|
3548
|
-
if (!response.data)
|
|
3549
|
-
throw new ApiError("Failed to run task command", 500);
|
|
3552
|
+
if (!response.data) throw new ApiError("Failed to run task command", 500);
|
|
3550
3553
|
return response;
|
|
3551
3554
|
},
|
|
3552
3555
|
workItems: {
|
|
3553
3556
|
list: async (taskId, params) => {
|
|
3554
3557
|
const searchParams = new URLSearchParams();
|
|
3555
|
-
if (params?.action)
|
|
3556
|
-
|
|
3557
|
-
if (params?.
|
|
3558
|
-
searchParams.set("limit", String(params.limit));
|
|
3559
|
-
if (params?.offset)
|
|
3560
|
-
searchParams.set("offset", String(params.offset));
|
|
3558
|
+
if (params?.action) searchParams.set("action", params.action);
|
|
3559
|
+
if (params?.limit) searchParams.set("limit", String(params.limit));
|
|
3560
|
+
if (params?.offset) searchParams.set("offset", String(params.offset));
|
|
3561
3561
|
const qs = searchParams.toString();
|
|
3562
3562
|
const response = await this.makeRequest(
|
|
3563
3563
|
`/api/tasks/${taskId}/work-items${qs ? `?${qs}` : ""}`
|
|
@@ -3574,20 +3574,17 @@ var AbstractClient = class {
|
|
|
3574
3574
|
},
|
|
3575
3575
|
get: async (id) => {
|
|
3576
3576
|
const response = await this.makeRequest(`/api/menu-items/${id}`);
|
|
3577
|
-
if (!response.data)
|
|
3578
|
-
throw new Error("Menu item not found");
|
|
3577
|
+
if (!response.data) throw new Error("Menu item not found");
|
|
3579
3578
|
return response.data;
|
|
3580
3579
|
},
|
|
3581
3580
|
create: async (data) => {
|
|
3582
3581
|
const response = await this.makeRequest("/api/menu-items", { method: "POST", body: data });
|
|
3583
|
-
if (!response.data)
|
|
3584
|
-
throw new Error("Failed to create menu item");
|
|
3582
|
+
if (!response.data) throw new Error("Failed to create menu item");
|
|
3585
3583
|
return response.data;
|
|
3586
3584
|
},
|
|
3587
3585
|
update: async (id, data) => {
|
|
3588
3586
|
const response = await this.makeRequest(`/api/menu-items/${id}`, { method: "PUT", body: data });
|
|
3589
|
-
if (!response.data)
|
|
3590
|
-
throw new Error("Failed to update menu item");
|
|
3587
|
+
if (!response.data) throw new Error("Failed to update menu item");
|
|
3591
3588
|
return response.data;
|
|
3592
3589
|
},
|
|
3593
3590
|
delete: async (id) => {
|
|
@@ -3717,8 +3714,7 @@ var AbstractClient = class {
|
|
|
3717
3714
|
{ status: response.status, responseBody: errorData }
|
|
3718
3715
|
);
|
|
3719
3716
|
}
|
|
3720
|
-
if (!response.body)
|
|
3721
|
-
throw new Error("Response body is null");
|
|
3717
|
+
if (!response.body) throw new Error("Response body is null");
|
|
3722
3718
|
for await (const frame of parseSseBody(response.body, { strictJsonObject: true })) {
|
|
3723
3719
|
if (frame.event === "error") {
|
|
3724
3720
|
const data = frame.data;
|
|
@@ -3743,10 +3739,8 @@ var AbstractClient = class {
|
|
|
3743
3739
|
}
|
|
3744
3740
|
}
|
|
3745
3741
|
} catch (error) {
|
|
3746
|
-
if (controller.signal.aborted)
|
|
3747
|
-
|
|
3748
|
-
if (error instanceof DOMException && error.name === "AbortError")
|
|
3749
|
-
return;
|
|
3742
|
+
if (controller.signal.aborted) return;
|
|
3743
|
+
if (error instanceof DOMException && error.name === "AbortError") return;
|
|
3750
3744
|
if (error instanceof SseParseError) {
|
|
3751
3745
|
onError?.(Object.assign(new Error(error.message), { code: "INVALID_EVENT" }));
|
|
3752
3746
|
return;
|
|
@@ -3849,10 +3843,8 @@ var AbstractClient = class {
|
|
|
3849
3843
|
*/
|
|
3850
3844
|
async getThreadHistory(threadId, options = {}) {
|
|
3851
3845
|
const params = new URLSearchParams();
|
|
3852
|
-
if (options.limit !== void 0)
|
|
3853
|
-
|
|
3854
|
-
if (options.before !== void 0)
|
|
3855
|
-
params.append("before", options.before);
|
|
3846
|
+
if (options.limit !== void 0) params.append("limit", String(options.limit));
|
|
3847
|
+
if (options.before !== void 0) params.append("before", options.before);
|
|
3856
3848
|
const query = params.toString();
|
|
3857
3849
|
const response = await this.makeRequest(
|
|
3858
3850
|
`/api/assistants/${this.assistantId}/threads/${threadId}/history${query ? `?${query}` : ""}`
|
|
@@ -4027,8 +4019,7 @@ var ResourcesClient = class {
|
|
|
4027
4019
|
headers: { "Content-Type": "application/json", ...this.getHeaders() },
|
|
4028
4020
|
body: JSON.stringify(request)
|
|
4029
4021
|
});
|
|
4030
|
-
if (!res.ok)
|
|
4031
|
-
throw new Error(`Share failed: ${res.status}`);
|
|
4022
|
+
if (!res.ok) throw new Error(`Share failed: ${res.status}`);
|
|
4032
4023
|
return await res.json();
|
|
4033
4024
|
}
|
|
4034
4025
|
async unshare(token) {
|
|
@@ -4036,8 +4027,7 @@ var ResourcesClient = class {
|
|
|
4036
4027
|
method: "DELETE",
|
|
4037
4028
|
headers: this.getHeaders()
|
|
4038
4029
|
});
|
|
4039
|
-
if (!res.ok)
|
|
4040
|
-
throw new Error(`Unshare failed: ${res.status}`);
|
|
4030
|
+
if (!res.ok) throw new Error(`Unshare failed: ${res.status}`);
|
|
4041
4031
|
}
|
|
4042
4032
|
async updateShare(token, patch) {
|
|
4043
4033
|
const res = await fetch(`${this.baseURL}/api/resources/share/${token}`, {
|
|
@@ -4045,15 +4035,13 @@ var ResourcesClient = class {
|
|
|
4045
4035
|
headers: { "Content-Type": "application/json", ...this.getHeaders() },
|
|
4046
4036
|
body: JSON.stringify(patch)
|
|
4047
4037
|
});
|
|
4048
|
-
if (!res.ok)
|
|
4049
|
-
throw new Error(`Update failed: ${res.status}`);
|
|
4038
|
+
if (!res.ok) throw new Error(`Update failed: ${res.status}`);
|
|
4050
4039
|
}
|
|
4051
4040
|
async listShares() {
|
|
4052
4041
|
const res = await fetch(`${this.baseURL}/api/resources/shares`, {
|
|
4053
4042
|
headers: this.getHeaders()
|
|
4054
4043
|
});
|
|
4055
|
-
if (!res.ok)
|
|
4056
|
-
throw new Error(`List failed: ${res.status}`);
|
|
4044
|
+
if (!res.ok) throw new Error(`List failed: ${res.status}`);
|
|
4057
4045
|
return await res.json();
|
|
4058
4046
|
}
|
|
4059
4047
|
};
|
|
@@ -4091,8 +4079,7 @@ async function archiveToBlob(archive) {
|
|
|
4091
4079
|
};
|
|
4092
4080
|
}
|
|
4093
4081
|
function attachmentFilename(contentDisposition) {
|
|
4094
|
-
if (!contentDisposition)
|
|
4095
|
-
return "tenant-export.tar.gz";
|
|
4082
|
+
if (!contentDisposition) return "tenant-export.tar.gz";
|
|
4096
4083
|
const encoded = contentDisposition.match(/filename\*=UTF-8''([^;]+)/i)?.[1];
|
|
4097
4084
|
if (encoded) {
|
|
4098
4085
|
try {
|
|
@@ -4127,8 +4114,7 @@ var ExportImportClient = class {
|
|
|
4127
4114
|
};
|
|
4128
4115
|
if (options.body instanceof FormData) {
|
|
4129
4116
|
for (const name of Object.keys(headers)) {
|
|
4130
|
-
if (name.toLowerCase() === "content-type")
|
|
4131
|
-
delete headers[name];
|
|
4117
|
+
if (name.toLowerCase() === "content-type") delete headers[name];
|
|
4132
4118
|
}
|
|
4133
4119
|
}
|
|
4134
4120
|
const response = await fetch(`${this.baseURL}${url}`, {
|
|
@@ -4262,18 +4248,15 @@ var ProjectRoomClientError = class extends Error {
|
|
|
4262
4248
|
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4263
4249
|
var date = (value, field) => {
|
|
4264
4250
|
const result = value instanceof Date ? new Date(value.getTime()) : new Date(typeof value === "string" || typeof value === "number" ? value : Number.NaN);
|
|
4265
|
-
if (!Number.isFinite(result.getTime()))
|
|
4266
|
-
throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4251
|
+
if (!Number.isFinite(result.getTime())) throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4267
4252
|
return result;
|
|
4268
4253
|
};
|
|
4269
4254
|
var requiredString = (record3, field) => {
|
|
4270
|
-
if (typeof record3[field] !== "string")
|
|
4271
|
-
throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4255
|
+
if (typeof record3[field] !== "string") throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4272
4256
|
return record3[field];
|
|
4273
4257
|
};
|
|
4274
4258
|
var oneOf = (value, values, field) => {
|
|
4275
|
-
if (typeof value !== "string" || !values.includes(value))
|
|
4276
|
-
throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4259
|
+
if (typeof value !== "string" || !values.includes(value)) throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4277
4260
|
return value;
|
|
4278
4261
|
};
|
|
4279
4262
|
var messageSources = ["user", "agent", "task", "routine", "system"];
|
|
@@ -4282,8 +4265,7 @@ var memberStatuses = ["active", "removed"];
|
|
|
4282
4265
|
var botRoles = ["coordinator", "specialist"];
|
|
4283
4266
|
var botStatuses = ["active", "paused", "removed"];
|
|
4284
4267
|
var exactKeys = (row, required, optional = []) => {
|
|
4285
|
-
if (required.some((key) => !Object.prototype.hasOwnProperty.call(row, key)) || Object.keys(row).some((key) => !required.includes(key) && !optional.includes(key)))
|
|
4286
|
-
throw new ProjectRoomClientError("Invalid Project Room response", 500, "INVALID_RESPONSE", false);
|
|
4268
|
+
if (required.some((key) => !Object.prototype.hasOwnProperty.call(row, key)) || Object.keys(row).some((key) => !required.includes(key) && !optional.includes(key))) throw new ProjectRoomClientError("Invalid Project Room response", 500, "INVALID_RESPONSE", false);
|
|
4287
4269
|
};
|
|
4288
4270
|
var hydrateAuthor = (value) => {
|
|
4289
4271
|
const row = record(value);
|
|
@@ -4292,29 +4274,24 @@ var hydrateAuthor = (value) => {
|
|
|
4292
4274
|
exactKeys(row, ["type", "userId"]);
|
|
4293
4275
|
return { type, userId: requiredString(row, "userId") };
|
|
4294
4276
|
}
|
|
4295
|
-
if (type === "bot")
|
|
4296
|
-
|
|
4297
|
-
if (Object.keys(row).some((key) => key !== "type"))
|
|
4298
|
-
throw new ProjectRoomClientError("Invalid author", 500, "INVALID_RESPONSE", false);
|
|
4277
|
+
if (type === "bot") return { type, membershipId: requiredString(row, "membershipId") };
|
|
4278
|
+
if (Object.keys(row).some((key) => key !== "type")) throw new ProjectRoomClientError("Invalid author", 500, "INVALID_RESPONSE", false);
|
|
4299
4279
|
return { type };
|
|
4300
4280
|
};
|
|
4301
4281
|
var hydrateMentions = (value) => {
|
|
4302
|
-
if (!Array.isArray(value))
|
|
4303
|
-
throw new ProjectRoomClientError("Invalid mentions", 500, "INVALID_RESPONSE", false);
|
|
4282
|
+
if (!Array.isArray(value)) throw new ProjectRoomClientError("Invalid mentions", 500, "INVALID_RESPONSE", false);
|
|
4304
4283
|
return value.map((entry) => {
|
|
4305
4284
|
const row = record(entry);
|
|
4306
4285
|
const type = oneOf(row.type, ["bot", "team"], "mention.type");
|
|
4307
4286
|
if (type === "team") {
|
|
4308
|
-
if (Object.keys(row).length !== 1)
|
|
4309
|
-
throw new ProjectRoomClientError("Invalid mention", 500, "INVALID_RESPONSE", false);
|
|
4287
|
+
if (Object.keys(row).length !== 1) throw new ProjectRoomClientError("Invalid mention", 500, "INVALID_RESPONSE", false);
|
|
4310
4288
|
return { type };
|
|
4311
4289
|
}
|
|
4312
4290
|
return { type, membershipId: requiredString(row, "membershipId") };
|
|
4313
4291
|
});
|
|
4314
4292
|
};
|
|
4315
4293
|
var record = (value) => {
|
|
4316
|
-
if (!isRecord(value))
|
|
4317
|
-
throw new ProjectRoomClientError("Invalid Project Room response", 500, "INVALID_RESPONSE", false);
|
|
4294
|
+
if (!isRecord(value)) throw new ProjectRoomClientError("Invalid Project Room response", 500, "INVALID_RESPONSE", false);
|
|
4318
4295
|
return value;
|
|
4319
4296
|
};
|
|
4320
4297
|
var hydrateRoom = (value) => {
|
|
@@ -4326,8 +4303,7 @@ var hydrateMessage = (value) => {
|
|
|
4326
4303
|
const row = record(value);
|
|
4327
4304
|
exactKeys(row, ["id", "roomId", "author", "content", "mentions", "source", "createdAt"], ["replyToMessageId", "sourceId"]);
|
|
4328
4305
|
const content = record(row.content);
|
|
4329
|
-
if (oneOf(content.type, ["text"], "content.type") !== "text")
|
|
4330
|
-
throw new ProjectRoomClientError("Invalid content", 500, "INVALID_RESPONSE", false);
|
|
4306
|
+
if (oneOf(content.type, ["text"], "content.type") !== "text") throw new ProjectRoomClientError("Invalid content", 500, "INVALID_RESPONSE", false);
|
|
4331
4307
|
return { id: requiredString(row, "id"), roomId: requiredString(row, "roomId"), author: hydrateAuthor(row.author), content: { type: "text", text: requiredString(content, "text") }, mentions: hydrateMentions(row.mentions), ...row.replyToMessageId === void 0 ? {} : { replyToMessageId: requiredString(row, "replyToMessageId") }, ...row.sourceId === void 0 ? {} : { sourceId: requiredString(row, "sourceId") }, source: oneOf(row.source, messageSources, "source"), createdAt: date(row.createdAt, "createdAt") };
|
|
4332
4308
|
};
|
|
4333
4309
|
var hydrateMember = (value) => {
|
|
@@ -4342,8 +4318,7 @@ var hydrateBot = (value) => {
|
|
|
4342
4318
|
};
|
|
4343
4319
|
var hydrateDispatch = (value) => {
|
|
4344
4320
|
const row = record(value);
|
|
4345
|
-
if (typeof row.success !== "boolean" || row.membershipId !== void 0 && typeof row.membershipId !== "string" || row.errorCode !== void 0 && typeof row.errorCode !== "string")
|
|
4346
|
-
throw new ProjectRoomClientError("Invalid dispatch response", 500, "INVALID_RESPONSE", false);
|
|
4321
|
+
if (typeof row.success !== "boolean" || row.membershipId !== void 0 && typeof row.membershipId !== "string" || row.errorCode !== void 0 && typeof row.errorCode !== "string") throw new ProjectRoomClientError("Invalid dispatch response", 500, "INVALID_RESPONSE", false);
|
|
4347
4322
|
return { success: row.success, ...row.membershipId === void 0 ? {} : { membershipId: row.membershipId }, ...row.errorCode === void 0 ? {} : { errorCode: row.errorCode } };
|
|
4348
4323
|
};
|
|
4349
4324
|
function hydratePublicMember(value) {
|
|
@@ -4369,23 +4344,19 @@ var ProjectRoomsClient = class {
|
|
|
4369
4344
|
query.set("beforeCreatedAt", iso(options.cursor.createdAt));
|
|
4370
4345
|
query.set("beforeId", options.cursor.id);
|
|
4371
4346
|
}
|
|
4372
|
-
if (options.limit !== void 0)
|
|
4373
|
-
query.set("limit", String(options.limit));
|
|
4347
|
+
if (options.limit !== void 0) query.set("limit", String(options.limit));
|
|
4374
4348
|
const result = await this.request(`/api/projects/${encode(projectId)}/room/messages${query.toString() ? `?${query}` : ""}`);
|
|
4375
|
-
if (!Array.isArray(result))
|
|
4376
|
-
throw new ProjectRoomClientError("Invalid messages response", 500, "INVALID_RESPONSE", false);
|
|
4349
|
+
if (!Array.isArray(result)) throw new ProjectRoomClientError("Invalid messages response", 500, "INVALID_RESPONSE", false);
|
|
4377
4350
|
return result.map(hydrateMessage);
|
|
4378
4351
|
},
|
|
4379
4352
|
send: async (projectId, input) => {
|
|
4380
4353
|
const result = await this.request(`/api/projects/${encode(projectId)}/room/messages`, { method: "POST", body: { text: input.text, mentions: input.mentions, ...input.replyToMessageId === void 0 ? {} : { replyToMessageId: input.replyToMessageId } }, headers: { "Idempotency-Key": input.idempotencyKey.trim() } });
|
|
4381
|
-
if (!Array.isArray(result.dispatch) || typeof result.replayed !== "boolean")
|
|
4382
|
-
throw new ProjectRoomClientError("Invalid send response", 500, "INVALID_RESPONSE", false);
|
|
4354
|
+
if (!Array.isArray(result.dispatch) || typeof result.replayed !== "boolean") throw new ProjectRoomClientError("Invalid send response", 500, "INVALID_RESPONSE", false);
|
|
4383
4355
|
return { message: hydrateMessage(result.message), dispatch: result.dispatch.map(hydrateDispatch), replayed: result.replayed };
|
|
4384
4356
|
},
|
|
4385
4357
|
retry: async (projectId, messageId) => {
|
|
4386
4358
|
const result = await this.request(`/api/projects/${encode(projectId)}/room/messages/${encode(messageId)}/retry`, { method: "POST", body: {} });
|
|
4387
|
-
if (!Array.isArray(result))
|
|
4388
|
-
throw new ProjectRoomClientError("Invalid retry response", 500, "INVALID_RESPONSE", false);
|
|
4359
|
+
if (!Array.isArray(result)) throw new ProjectRoomClientError("Invalid retry response", 500, "INVALID_RESPONSE", false);
|
|
4389
4360
|
return result.map(hydrateDispatch);
|
|
4390
4361
|
},
|
|
4391
4362
|
markRead: async (projectId) => {
|
|
@@ -4426,8 +4397,7 @@ var ProjectRoomsClient = class {
|
|
|
4426
4397
|
}
|
|
4427
4398
|
async records(path, hydrate) {
|
|
4428
4399
|
const result = await this.request(path);
|
|
4429
|
-
if (!Array.isArray(result))
|
|
4430
|
-
throw new ProjectRoomClientError("Invalid records response", 500, "INVALID_RESPONSE", false);
|
|
4400
|
+
if (!Array.isArray(result)) throw new ProjectRoomClientError("Invalid records response", 500, "INVALID_RESPONSE", false);
|
|
4431
4401
|
return result.map(hydrate);
|
|
4432
4402
|
}
|
|
4433
4403
|
async request(path, options = {}) {
|
|
@@ -4439,8 +4409,7 @@ var ProjectRoomsClient = class {
|
|
|
4439
4409
|
const error = payload?.error;
|
|
4440
4410
|
throw new ProjectRoomClientError(typeof error?.message === "string" ? error.message : "Project Room request failed", response.status, typeof error?.code === "string" ? error.code : response.ok ? "INVALID_RESPONSE" : "HTTP_ERROR", error?.retryable === true, error?.details);
|
|
4441
4411
|
}
|
|
4442
|
-
if (!Object.prototype.hasOwnProperty.call(payload, "data"))
|
|
4443
|
-
throw new ProjectRoomClientError("Missing response data", 500, "INVALID_RESPONSE", false);
|
|
4412
|
+
if (!Object.prototype.hasOwnProperty.call(payload, "data")) throw new ProjectRoomClientError("Missing response data", 500, "INVALID_RESPONSE", false);
|
|
4444
4413
|
return payload.data;
|
|
4445
4414
|
}
|
|
4446
4415
|
};
|
|
@@ -4448,19 +4417,16 @@ var ProjectRoomsClient = class {
|
|
|
4448
4417
|
// src/workspace-rooms.ts
|
|
4449
4418
|
var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4450
4419
|
var record2 = (value) => {
|
|
4451
|
-
if (!isRecord2(value))
|
|
4452
|
-
throw new ProjectRoomClientError("Invalid workspace rooms response", 500, "INVALID_RESPONSE", false);
|
|
4420
|
+
if (!isRecord2(value)) throw new ProjectRoomClientError("Invalid workspace rooms response", 500, "INVALID_RESPONSE", false);
|
|
4453
4421
|
return value;
|
|
4454
4422
|
};
|
|
4455
4423
|
var requiredString2 = (row, field) => {
|
|
4456
|
-
if (typeof row[field] !== "string")
|
|
4457
|
-
throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4424
|
+
if (typeof row[field] !== "string") throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4458
4425
|
return row[field];
|
|
4459
4426
|
};
|
|
4460
4427
|
var date2 = (value, field) => {
|
|
4461
4428
|
const result = value instanceof Date ? new Date(value.getTime()) : new Date(typeof value === "string" ? value : Number.NaN);
|
|
4462
|
-
if (!Number.isFinite(result.getTime()))
|
|
4463
|
-
throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4429
|
+
if (!Number.isFinite(result.getTime())) throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4464
4430
|
return result;
|
|
4465
4431
|
};
|
|
4466
4432
|
var hydrateProject = (value) => {
|
|
@@ -4480,10 +4446,8 @@ var hydrateProject = (value) => {
|
|
|
4480
4446
|
var hydrateEntry = (value) => {
|
|
4481
4447
|
const row = record2(value);
|
|
4482
4448
|
const names = row.participantNames;
|
|
4483
|
-
if (!Array.isArray(names) || names.some((n) => typeof n !== "string"))
|
|
4484
|
-
|
|
4485
|
-
if (typeof row.participantCount !== "number" || typeof row.unreadCount !== "number")
|
|
4486
|
-
throw new ProjectRoomClientError("Invalid room entry counts", 500, "INVALID_RESPONSE", false);
|
|
4449
|
+
if (!Array.isArray(names) || names.some((n) => typeof n !== "string")) throw new ProjectRoomClientError("Invalid participantNames", 500, "INVALID_RESPONSE", false);
|
|
4450
|
+
if (typeof row.participantCount !== "number" || typeof row.unreadCount !== "number") throw new ProjectRoomClientError("Invalid room entry counts", 500, "INVALID_RESPONSE", false);
|
|
4487
4451
|
return {
|
|
4488
4452
|
project: hydrateProject(row.project),
|
|
4489
4453
|
room: hydrateRoom(row.room),
|
|
@@ -4508,8 +4472,7 @@ var WorkspaceRoomsClient = class {
|
|
|
4508
4472
|
const error = payload?.error;
|
|
4509
4473
|
throw new ProjectRoomClientError(typeof error?.message === "string" ? error.message : "Workspace rooms request failed", response.status, typeof error?.code === "string" ? error.code : response.ok ? "INVALID_RESPONSE" : "HTTP_ERROR", error?.retryable === true, error?.details);
|
|
4510
4474
|
}
|
|
4511
|
-
if (!payload.data || !Array.isArray(payload.data.rooms))
|
|
4512
|
-
throw new ProjectRoomClientError("Invalid workspace rooms response", 500, "INVALID_RESPONSE", false);
|
|
4475
|
+
if (!payload.data || !Array.isArray(payload.data.rooms)) throw new ProjectRoomClientError("Invalid workspace rooms response", 500, "INVALID_RESPONSE", false);
|
|
4513
4476
|
return payload.data.rooms.map(hydrateEntry);
|
|
4514
4477
|
}
|
|
4515
4478
|
};
|
|
@@ -4517,10 +4480,8 @@ var WorkspaceRoomsClient = class {
|
|
|
4517
4480
|
// src/workspace-members.ts
|
|
4518
4481
|
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4519
4482
|
var hydrateMember2 = (value) => {
|
|
4520
|
-
if (!isRecord3(value))
|
|
4521
|
-
|
|
4522
|
-
if (typeof value.userId !== "string" || typeof value.name !== "string")
|
|
4523
|
-
throw new ProjectRoomClientError("Invalid workspace member", 500, "INVALID_RESPONSE", false);
|
|
4483
|
+
if (!isRecord3(value)) throw new ProjectRoomClientError("Invalid workspace member", 500, "INVALID_RESPONSE", false);
|
|
4484
|
+
if (typeof value.userId !== "string" || typeof value.name !== "string") throw new ProjectRoomClientError("Invalid workspace member", 500, "INVALID_RESPONSE", false);
|
|
4524
4485
|
return {
|
|
4525
4486
|
userId: value.userId,
|
|
4526
4487
|
name: value.name,
|
|
@@ -4544,8 +4505,7 @@ var WorkspaceMembersClient = class {
|
|
|
4544
4505
|
throw new ProjectRoomClientError(typeof error?.message === "string" ? error.message : "Workspace members request failed", response.status, typeof error?.code === "string" ? error.code : response.ok ? "INVALID_RESPONSE" : "HTTP_ERROR", error?.retryable === true, error?.details);
|
|
4545
4506
|
}
|
|
4546
4507
|
const members = payload.data?.members;
|
|
4547
|
-
if (!Array.isArray(members))
|
|
4548
|
-
throw new ProjectRoomClientError("Invalid workspace members response", 500, "INVALID_RESPONSE", false);
|
|
4508
|
+
if (!Array.isArray(members)) throw new ProjectRoomClientError("Invalid workspace members response", 500, "INVALID_RESPONSE", false);
|
|
4549
4509
|
return members.map(hydrateMember2);
|
|
4550
4510
|
}
|
|
4551
4511
|
};
|
|
@@ -4553,76 +4513,61 @@ var WorkspaceMembersClient = class {
|
|
|
4553
4513
|
// src/room-events.ts
|
|
4554
4514
|
var invalidFrame = (message) => new ProjectRoomClientError(message, 200, "INVALID_EVENT", false);
|
|
4555
4515
|
var requiredString3 = (row, field) => {
|
|
4556
|
-
if (typeof row[field] !== "string")
|
|
4557
|
-
throw invalidFrame(`Invalid ${field}`);
|
|
4516
|
+
if (typeof row[field] !== "string") throw invalidFrame(`Invalid ${field}`);
|
|
4558
4517
|
return row[field];
|
|
4559
4518
|
};
|
|
4560
4519
|
var oneOf2 = (value, values, field) => {
|
|
4561
|
-
if (typeof value !== "string" || !values.includes(value))
|
|
4562
|
-
throw invalidFrame(`Invalid ${field}`);
|
|
4520
|
+
if (typeof value !== "string" || !values.includes(value)) throw invalidFrame(`Invalid ${field}`);
|
|
4563
4521
|
return value;
|
|
4564
4522
|
};
|
|
4565
4523
|
var hydrateScope = (value) => {
|
|
4566
|
-
if (!isRecord(value))
|
|
4567
|
-
throw invalidFrame("Invalid scope");
|
|
4524
|
+
if (!isRecord(value)) throw invalidFrame("Invalid scope");
|
|
4568
4525
|
return { tenantId: requiredString3(value, "tenantId"), roomId: requiredString3(value, "roomId"), projectId: requiredString3(value, "projectId") };
|
|
4569
4526
|
};
|
|
4570
4527
|
var hydrateControl = (event, payload) => {
|
|
4571
4528
|
if (event === "ready") {
|
|
4572
|
-
if (typeof payload.epoch !== "string" || payload.headEventId !== null && typeof payload.headEventId !== "string" || Object.keys(payload).some((key) => key !== "epoch" && key !== "headEventId"))
|
|
4573
|
-
throw invalidFrame("Invalid SSE control");
|
|
4529
|
+
if (typeof payload.epoch !== "string" || payload.headEventId !== null && typeof payload.headEventId !== "string" || Object.keys(payload).some((key) => key !== "epoch" && key !== "headEventId")) throw invalidFrame("Invalid SSE control");
|
|
4574
4530
|
return { type: "ready", data: { epoch: payload.epoch, headEventId: payload.headEventId } };
|
|
4575
4531
|
}
|
|
4576
|
-
if (Object.keys(payload).some((key) => key !== "reason"))
|
|
4577
|
-
|
|
4578
|
-
if (event === "resync")
|
|
4579
|
-
return { type: "resync", data: { reason: oneOf2(payload.reason, ["SERVER_RESTART", "CURSOR_EXPIRED", "SLOW_CONSUMER"], "reason") } };
|
|
4532
|
+
if (Object.keys(payload).some((key) => key !== "reason")) throw invalidFrame("Invalid SSE control");
|
|
4533
|
+
if (event === "resync") return { type: "resync", data: { reason: oneOf2(payload.reason, ["SERVER_RESTART", "CURSOR_EXPIRED", "SLOW_CONSUMER"], "reason") } };
|
|
4580
4534
|
return { type: "access.revoked", data: { reason: oneOf2(payload.reason, ["PROJECT_ACCESS_REVOKED", "TOKEN_EXPIRED", "CONNECTION_SUPERSEDED"], "reason") } };
|
|
4581
4535
|
};
|
|
4582
4536
|
var ROOM_SCOPED_TYPES = ["message.created", "roster.changed", "membership.changed", "task.changed"];
|
|
4583
4537
|
function hydrateWorkspaceFrame(raw) {
|
|
4584
4538
|
const payload = isRecord(raw.data) ? raw.data : void 0;
|
|
4585
4539
|
if (raw.event === "ready" || raw.event === "resync" || raw.event === "access.revoked") {
|
|
4586
|
-
if (!payload || Object.prototype.hasOwnProperty.call(payload, "type"))
|
|
4587
|
-
throw invalidFrame("Invalid SSE control");
|
|
4540
|
+
if (!payload || Object.prototype.hasOwnProperty.call(payload, "type")) throw invalidFrame("Invalid SSE control");
|
|
4588
4541
|
return hydrateControl(raw.event, payload);
|
|
4589
4542
|
}
|
|
4590
|
-
if (typeof payload?.type !== "string" || payload.type !== raw.event || typeof payload.id !== "string" || raw.id !== payload.id)
|
|
4591
|
-
throw invalidFrame("Invalid SSE business event");
|
|
4543
|
+
if (typeof payload?.type !== "string" || payload.type !== raw.event || typeof payload.id !== "string" || raw.id !== payload.id) throw invalidFrame("Invalid SSE business event");
|
|
4592
4544
|
const occurredAt = date(payload.occurredAt, "occurredAt");
|
|
4593
4545
|
const scope = payload.scope === void 0 ? void 0 : hydrateScope(payload.scope);
|
|
4594
4546
|
const roomScoped = ROOM_SCOPED_TYPES.includes(payload.type);
|
|
4595
|
-
if (roomScoped && scope === void 0)
|
|
4596
|
-
throw invalidFrame("Invalid SSE business event scope");
|
|
4547
|
+
if (roomScoped && scope === void 0) throw invalidFrame("Invalid SSE business event scope");
|
|
4597
4548
|
const data = payload.data;
|
|
4598
4549
|
if (payload.type === "message.created") {
|
|
4599
|
-
if (!isRecord(data))
|
|
4600
|
-
throw invalidFrame("Invalid SSE business event data");
|
|
4550
|
+
if (!isRecord(data)) throw invalidFrame("Invalid SSE business event data");
|
|
4601
4551
|
return { type: payload.type, id: payload.id, occurredAt, scope, data: { message: hydrateMessage(data.message) } };
|
|
4602
4552
|
}
|
|
4603
4553
|
if (payload.type === "roster.changed") {
|
|
4604
|
-
if (!isRecord(data))
|
|
4605
|
-
throw invalidFrame("Invalid SSE business event data");
|
|
4554
|
+
if (!isRecord(data)) throw invalidFrame("Invalid SSE business event data");
|
|
4606
4555
|
return { type: payload.type, id: payload.id, occurredAt, scope, data: { change: requiredString3(data, "change"), membership: hydratePublicBot(data.membership) } };
|
|
4607
4556
|
}
|
|
4608
4557
|
if (payload.type === "membership.changed") {
|
|
4609
|
-
if (!isRecord(data))
|
|
4610
|
-
throw invalidFrame("Invalid SSE business event data");
|
|
4558
|
+
if (!isRecord(data)) throw invalidFrame("Invalid SSE business event data");
|
|
4611
4559
|
return { type: payload.type, id: payload.id, occurredAt, scope, data: { change: requiredString3(data, "change"), membership: hydratePublicMember(data.membership) } };
|
|
4612
4560
|
}
|
|
4613
4561
|
if (payload.type === "task.changed") {
|
|
4614
|
-
if (!isRecord(data))
|
|
4615
|
-
throw invalidFrame("Invalid SSE business event data");
|
|
4562
|
+
if (!isRecord(data)) throw invalidFrame("Invalid SSE business event data");
|
|
4616
4563
|
return { type: payload.type, id: payload.id, occurredAt, scope, data: { taskId: requiredString3(data, "taskId"), status: requiredString3(data, "status"), ownerMembershipId: requiredString3(data, "ownerMembershipId"), updatedAt: date(data.updatedAt, "updatedAt") } };
|
|
4617
4564
|
}
|
|
4618
4565
|
if (payload.type === "read.changed") {
|
|
4619
|
-
if (!isRecord(data))
|
|
4620
|
-
throw invalidFrame("Invalid SSE business event data");
|
|
4566
|
+
if (!isRecord(data)) throw invalidFrame("Invalid SSE business event data");
|
|
4621
4567
|
return { type: payload.type, id: payload.id, occurredAt, data: { projectId: requiredString3(data, "projectId"), roomId: requiredString3(data, "roomId"), lastReadAt: date(data.lastReadAt, "lastReadAt") } };
|
|
4622
4568
|
}
|
|
4623
4569
|
if (payload.type === "membership.affected") {
|
|
4624
|
-
if (!isRecord(data))
|
|
4625
|
-
throw invalidFrame("Invalid SSE business event data");
|
|
4570
|
+
if (!isRecord(data)) throw invalidFrame("Invalid SSE business event data");
|
|
4626
4571
|
return { type: payload.type, id: payload.id, occurredAt, data: { change: oneOf2(data.change, ["added", "removed", "role_changed"], "change"), projectId: requiredString3(data, "projectId"), roomId: requiredString3(data, "roomId") } };
|
|
4627
4572
|
}
|
|
4628
4573
|
return { type: payload.type, id: payload.id, occurredAt, data: payload.data, ...scope === void 0 ? {} : { scope } };
|
|
@@ -4646,35 +4591,29 @@ var RoomEventsClient = class {
|
|
|
4646
4591
|
const error = payload?.error;
|
|
4647
4592
|
throw new ProjectRoomClientError(typeof error?.message === "string" ? error.message : "Workspace room events stream failed", response.status, typeof error?.code === "string" ? error.code : "HTTP_ERROR", error?.retryable === true, error?.details);
|
|
4648
4593
|
}
|
|
4649
|
-
if (response.headers?.get && response.headers.get("content-type")?.split(";")[0].trim() !== "text/event-stream")
|
|
4650
|
-
|
|
4651
|
-
if (!response.body)
|
|
4652
|
-
throw new ProjectRoomClientError("Workspace room events stream has no body", 500, "INVALID_RESPONSE", false);
|
|
4594
|
+
if (response.headers?.get && response.headers.get("content-type")?.split(";")[0].trim() !== "text/event-stream") throw new ProjectRoomClientError("Workspace room events stream has invalid content type", response.status, "INVALID_RESPONSE", false);
|
|
4595
|
+
if (!response.body) throw new ProjectRoomClientError("Workspace room events stream has no body", 500, "INVALID_RESPONSE", false);
|
|
4653
4596
|
resolveOpen({ status: 200 });
|
|
4654
4597
|
return response;
|
|
4655
4598
|
}).catch((error) => {
|
|
4656
4599
|
rejectOpen(error);
|
|
4657
4600
|
throw error;
|
|
4658
4601
|
});
|
|
4659
|
-
const stream = async function* () {
|
|
4602
|
+
const stream = (async function* () {
|
|
4660
4603
|
const response = await responsePromise;
|
|
4661
4604
|
const body = response.body;
|
|
4662
|
-
if (!body)
|
|
4663
|
-
throw new ProjectRoomClientError("Workspace room events stream has no body", 500, "INVALID_RESPONSE", false);
|
|
4605
|
+
if (!body) throw new ProjectRoomClientError("Workspace room events stream has no body", 500, "INVALID_RESPONSE", false);
|
|
4664
4606
|
for await (const raw of parseSseBody(body, { strictJsonObject: true })) {
|
|
4665
4607
|
try {
|
|
4666
4608
|
yield { event: hydrateWorkspaceFrame(raw), ...raw.id === void 0 ? {} : { id: raw.id }, ...raw.retry === void 0 ? {} : { retry: raw.retry } };
|
|
4667
4609
|
} catch (error) {
|
|
4668
|
-
if (error instanceof ProjectRoomClientError && error.code === "INVALID_EVENT")
|
|
4669
|
-
|
|
4670
|
-
if (error instanceof
|
|
4671
|
-
throw new ProjectRoomClientError(error.message, 400, "INVALID_EVENT", false);
|
|
4672
|
-
if (error instanceof ProjectRoomClientError)
|
|
4673
|
-
throw new ProjectRoomClientError(error.message, 400, "INVALID_EVENT", false, error.details);
|
|
4610
|
+
if (error instanceof ProjectRoomClientError && error.code === "INVALID_EVENT") throw new ProjectRoomClientError(error.message, 400, "INVALID_EVENT", false, error.details);
|
|
4611
|
+
if (error instanceof SseParseError) throw new ProjectRoomClientError(error.message, 400, "INVALID_EVENT", false);
|
|
4612
|
+
if (error instanceof ProjectRoomClientError) throw new ProjectRoomClientError(error.message, 400, "INVALID_EVENT", false, error.details);
|
|
4674
4613
|
throw new ProjectRoomClientError("Invalid SSE event", 400, "INVALID_EVENT", false);
|
|
4675
4614
|
}
|
|
4676
4615
|
}
|
|
4677
|
-
}();
|
|
4616
|
+
})();
|
|
4678
4617
|
return { opened, [Symbol.asyncIterator]: () => stream };
|
|
4679
4618
|
}
|
|
4680
4619
|
};
|
|
@@ -4695,13 +4634,11 @@ function invalidResponse(message) {
|
|
|
4695
4634
|
return new OidcProviderClientError(message, 500, "INVALID_RESPONSE", false);
|
|
4696
4635
|
}
|
|
4697
4636
|
function requiredString4(row, field) {
|
|
4698
|
-
if (typeof row[field] !== "string")
|
|
4699
|
-
throw invalidResponse(`Invalid ${field}`);
|
|
4637
|
+
if (typeof row[field] !== "string") throw invalidResponse(`Invalid ${field}`);
|
|
4700
4638
|
return row[field];
|
|
4701
4639
|
}
|
|
4702
4640
|
function hydrateSummary(value) {
|
|
4703
|
-
if (!isRecord4(value))
|
|
4704
|
-
throw invalidResponse("Invalid OIDC provider summary");
|
|
4641
|
+
if (!isRecord4(value)) throw invalidResponse("Invalid OIDC provider summary");
|
|
4705
4642
|
const source = value.source;
|
|
4706
4643
|
if (source !== "env" && source !== "store") {
|
|
4707
4644
|
throw invalidResponse("Invalid OIDC provider source");
|
|
@@ -4728,8 +4665,7 @@ function hydrateSummary(value) {
|
|
|
4728
4665
|
};
|
|
4729
4666
|
}
|
|
4730
4667
|
function hydrateTestResult(value) {
|
|
4731
|
-
if (!isRecord4(value))
|
|
4732
|
-
throw invalidResponse("Invalid OIDC test result");
|
|
4668
|
+
if (!isRecord4(value)) throw invalidResponse("Invalid OIDC test result");
|
|
4733
4669
|
const scopesSupported = Array.isArray(value.scopesSupported) ? value.scopesSupported.filter(
|
|
4734
4670
|
(scope) => typeof scope === "string"
|
|
4735
4671
|
) : void 0;
|
|
@@ -4771,8 +4707,7 @@ var OidcProvidersClient = class {
|
|
|
4771
4707
|
}
|
|
4772
4708
|
async list() {
|
|
4773
4709
|
const data = await this.request("/api/oidc-providers");
|
|
4774
|
-
if (!Array.isArray(data))
|
|
4775
|
-
throw invalidResponse("Invalid provider list");
|
|
4710
|
+
if (!Array.isArray(data)) throw invalidResponse("Invalid provider list");
|
|
4776
4711
|
return data.map(hydrateSummary);
|
|
4777
4712
|
}
|
|
4778
4713
|
async create(input) {
|
|
@@ -4847,16 +4782,13 @@ function invalidResponse2(message) {
|
|
|
4847
4782
|
return new PlatformClientError(message, 500, "INVALID_RESPONSE", false);
|
|
4848
4783
|
}
|
|
4849
4784
|
function requiredString5(row, field) {
|
|
4850
|
-
if (typeof row[field] !== "string")
|
|
4851
|
-
throw invalidResponse2(`Invalid ${field}`);
|
|
4785
|
+
if (typeof row[field] !== "string") throw invalidResponse2(`Invalid ${field}`);
|
|
4852
4786
|
return row[field];
|
|
4853
4787
|
}
|
|
4854
4788
|
function optionalNullableString(row, field) {
|
|
4855
4789
|
const value = row[field];
|
|
4856
|
-
if (value === null || value === void 0)
|
|
4857
|
-
|
|
4858
|
-
if (typeof value !== "string")
|
|
4859
|
-
throw invalidResponse2(`Invalid ${field}`);
|
|
4790
|
+
if (value === null || value === void 0) return null;
|
|
4791
|
+
if (typeof value !== "string") throw invalidResponse2(`Invalid ${field}`);
|
|
4860
4792
|
return value;
|
|
4861
4793
|
}
|
|
4862
4794
|
function hydrateSettingsSnapshot(value) {
|
|
@@ -4889,23 +4821,22 @@ var BRANDING_TEXT_KEYS = [
|
|
|
4889
4821
|
"loginSubtitle"
|
|
4890
4822
|
];
|
|
4891
4823
|
function hydrateBranding(value) {
|
|
4892
|
-
if (!isRecord5(value))
|
|
4893
|
-
throw invalidResponse2("Invalid branding");
|
|
4824
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid branding");
|
|
4894
4825
|
const branding = {};
|
|
4895
4826
|
for (const key of BRANDING_TEXT_KEYS) {
|
|
4896
4827
|
const field = value[key];
|
|
4897
|
-
if (field === void 0)
|
|
4898
|
-
continue;
|
|
4828
|
+
if (field === void 0) continue;
|
|
4899
4829
|
if (typeof field !== "string") {
|
|
4900
4830
|
throw invalidResponse2(`Invalid branding.${key}`);
|
|
4901
4831
|
}
|
|
4902
4832
|
branding[key] = field;
|
|
4903
4833
|
}
|
|
4834
|
+
const customCss = optionalString(value, "customCss");
|
|
4835
|
+
if (customCss !== void 0) branding.customCss = customCss;
|
|
4904
4836
|
return branding;
|
|
4905
4837
|
}
|
|
4906
4838
|
function hydrateBrandingDomain(value) {
|
|
4907
|
-
if (!isRecord5(value))
|
|
4908
|
-
throw invalidResponse2("Invalid branding domain");
|
|
4839
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid branding domain");
|
|
4909
4840
|
const domain = { host: requiredString5(value, "host") };
|
|
4910
4841
|
if (value.status !== void 0) {
|
|
4911
4842
|
if (value.status !== "active" && value.status !== "pending") {
|
|
@@ -4927,8 +4858,7 @@ function hydrateBrandingDomain(value) {
|
|
|
4927
4858
|
return domain;
|
|
4928
4859
|
}
|
|
4929
4860
|
function hydrateBrandingSettings(value) {
|
|
4930
|
-
if (!isRecord5(value))
|
|
4931
|
-
throw invalidResponse2("Invalid branding settings");
|
|
4861
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid branding settings");
|
|
4932
4862
|
const settings = {};
|
|
4933
4863
|
if (value.default !== void 0) {
|
|
4934
4864
|
settings.default = hydrateBranding(value.default);
|
|
@@ -4977,8 +4907,7 @@ function hydrateTenantRole(value) {
|
|
|
4977
4907
|
throw invalidResponse2("Invalid tenant role");
|
|
4978
4908
|
}
|
|
4979
4909
|
function hydrateStatus(value) {
|
|
4980
|
-
if (value === null || value === void 0)
|
|
4981
|
-
return null;
|
|
4910
|
+
if (value === null || value === void 0) return null;
|
|
4982
4911
|
if (value === "active" || value === "pending" || value === "suspended") {
|
|
4983
4912
|
return value;
|
|
4984
4913
|
}
|
|
@@ -4986,15 +4915,12 @@ function hydrateStatus(value) {
|
|
|
4986
4915
|
}
|
|
4987
4916
|
function optionalString(row, field) {
|
|
4988
4917
|
const value = row[field];
|
|
4989
|
-
if (value === null || value === void 0)
|
|
4990
|
-
|
|
4991
|
-
if (typeof value !== "string")
|
|
4992
|
-
throw invalidResponse2(`Invalid ${field}`);
|
|
4918
|
+
if (value === null || value === void 0) return void 0;
|
|
4919
|
+
if (typeof value !== "string") throw invalidResponse2(`Invalid ${field}`);
|
|
4993
4920
|
return value;
|
|
4994
4921
|
}
|
|
4995
4922
|
function hydrateInvitation(value) {
|
|
4996
|
-
if (!isRecord5(value))
|
|
4997
|
-
throw invalidResponse2("Invalid invitation");
|
|
4923
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid invitation");
|
|
4998
4924
|
const invitedBy = optionalString(value, "invitedBy");
|
|
4999
4925
|
const expiresAt = optionalString(value, "expiresAt");
|
|
5000
4926
|
const consumedAt = optionalString(value, "consumedAt");
|
|
@@ -5008,8 +4934,7 @@ function hydrateInvitation(value) {
|
|
|
5008
4934
|
};
|
|
5009
4935
|
}
|
|
5010
4936
|
function hydrateMember3(value) {
|
|
5011
|
-
if (!isRecord5(value))
|
|
5012
|
-
throw invalidResponse2("Invalid platform member");
|
|
4937
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid platform member");
|
|
5013
4938
|
return {
|
|
5014
4939
|
id: requiredString5(value, "id"),
|
|
5015
4940
|
email: optionalNullableString(value, "email"),
|
|
@@ -5021,8 +4946,7 @@ function hydrateMember3(value) {
|
|
|
5021
4946
|
};
|
|
5022
4947
|
}
|
|
5023
4948
|
function hydrateTenantMember(value) {
|
|
5024
|
-
if (!isRecord5(value))
|
|
5025
|
-
throw invalidResponse2("Invalid tenant member");
|
|
4949
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid tenant member");
|
|
5026
4950
|
return {
|
|
5027
4951
|
userId: requiredString5(value, "userId"),
|
|
5028
4952
|
tenantId: requiredString5(value, "tenantId"),
|
|
@@ -5040,8 +4964,7 @@ function hydrateOidcIdentityClaimStatus(value) {
|
|
|
5040
4964
|
throw invalidResponse2("Invalid SSO claim status");
|
|
5041
4965
|
}
|
|
5042
4966
|
function hydrateOidcIdentityClaim(value) {
|
|
5043
|
-
if (!isRecord5(value))
|
|
5044
|
-
throw invalidResponse2("Invalid SSO claim");
|
|
4967
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid SSO claim");
|
|
5045
4968
|
const name = optionalString(value, "name");
|
|
5046
4969
|
const picture = optionalString(value, "picture");
|
|
5047
4970
|
const reviewedBy = optionalString(value, "reviewedBy");
|
|
@@ -5056,8 +4979,7 @@ function hydrateOidcIdentityClaim(value) {
|
|
|
5056
4979
|
const existing = value.existingUser;
|
|
5057
4980
|
let existingUser;
|
|
5058
4981
|
if (existing !== void 0 && existing !== null) {
|
|
5059
|
-
if (!isRecord5(existing))
|
|
5060
|
-
throw invalidResponse2("Invalid existing user");
|
|
4982
|
+
if (!isRecord5(existing)) throw invalidResponse2("Invalid existing user");
|
|
5061
4983
|
const platformRole = existing.role !== void 0 ? hydratePlatformRole(existing.role) : existing.platformRole !== void 0 ? hydratePlatformRole(existing.platformRole) : void 0;
|
|
5062
4984
|
existingUser = {
|
|
5063
4985
|
id: requiredString5(existing, "id"),
|
|
@@ -5099,15 +5021,12 @@ function hydrateTenantStatus(value) {
|
|
|
5099
5021
|
}
|
|
5100
5022
|
function optionalRecord(row, field) {
|
|
5101
5023
|
const value = row[field];
|
|
5102
|
-
if (value === void 0 || value === null)
|
|
5103
|
-
|
|
5104
|
-
if (!isRecord5(value))
|
|
5105
|
-
throw invalidResponse2(`Invalid ${field}`);
|
|
5024
|
+
if (value === void 0 || value === null) return void 0;
|
|
5025
|
+
if (!isRecord5(value)) throw invalidResponse2(`Invalid ${field}`);
|
|
5106
5026
|
return value;
|
|
5107
5027
|
}
|
|
5108
5028
|
function hydrateInviteLink(value) {
|
|
5109
|
-
if (!isRecord5(value))
|
|
5110
|
-
throw invalidResponse2("Invalid invite link");
|
|
5029
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid invite link");
|
|
5111
5030
|
const scope = value.scope;
|
|
5112
5031
|
if (scope !== "platform" && scope !== "tenant") {
|
|
5113
5032
|
throw invalidResponse2("Invalid invite scope");
|
|
@@ -5133,8 +5052,7 @@ function hydrateInviteLink(value) {
|
|
|
5133
5052
|
};
|
|
5134
5053
|
}
|
|
5135
5054
|
function hydrateTenant(value) {
|
|
5136
|
-
if (!isRecord5(value))
|
|
5137
|
-
throw invalidResponse2("Invalid tenant");
|
|
5055
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid tenant");
|
|
5138
5056
|
const metadata = optionalRecord(value, "metadata");
|
|
5139
5057
|
return {
|
|
5140
5058
|
id: requiredString5(value, "id"),
|
|
@@ -5147,8 +5065,7 @@ function hydrateTenant(value) {
|
|
|
5147
5065
|
};
|
|
5148
5066
|
}
|
|
5149
5067
|
function hydrateUser(value) {
|
|
5150
|
-
if (!isRecord5(value))
|
|
5151
|
-
throw invalidResponse2("Invalid user");
|
|
5068
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid user");
|
|
5152
5069
|
const status = value.status;
|
|
5153
5070
|
if (status !== "active" && status !== "pending" && status !== "suspended") {
|
|
5154
5071
|
throw invalidResponse2("Invalid user status");
|
|
@@ -5164,6 +5081,135 @@ function hydrateUser(value) {
|
|
|
5164
5081
|
...typeof value.updatedAt === "string" ? { updatedAt: value.updatedAt } : {}
|
|
5165
5082
|
};
|
|
5166
5083
|
}
|
|
5084
|
+
function hydrateAuditInitiator(value) {
|
|
5085
|
+
if (!isRecord5(value) || typeof value.type !== "string") {
|
|
5086
|
+
throw invalidResponse2("Invalid platform audit initiator");
|
|
5087
|
+
}
|
|
5088
|
+
if (value.type === "human") {
|
|
5089
|
+
if (typeof value.userId !== "string" || value.role !== "owner" && value.role !== "admin" && value.role !== "auditor") {
|
|
5090
|
+
throw invalidResponse2("Invalid platform audit human initiator");
|
|
5091
|
+
}
|
|
5092
|
+
return { type: "human", userId: value.userId, role: value.role };
|
|
5093
|
+
}
|
|
5094
|
+
if (value.type === "bootstrap") {
|
|
5095
|
+
return { type: "bootstrap" };
|
|
5096
|
+
}
|
|
5097
|
+
if (value.type === "system") {
|
|
5098
|
+
if (typeof value.component !== "string") {
|
|
5099
|
+
throw invalidResponse2("Invalid platform audit system initiator");
|
|
5100
|
+
}
|
|
5101
|
+
return { type: "system", component: value.component };
|
|
5102
|
+
}
|
|
5103
|
+
throw invalidResponse2("Invalid platform audit initiator");
|
|
5104
|
+
}
|
|
5105
|
+
function hydrateAuditExecutor(value) {
|
|
5106
|
+
if (!isRecord5(value) || typeof value.type !== "string") {
|
|
5107
|
+
throw invalidResponse2("Invalid platform audit executor");
|
|
5108
|
+
}
|
|
5109
|
+
if (value.type === "admin_center") {
|
|
5110
|
+
if (typeof value.route !== "string") {
|
|
5111
|
+
throw invalidResponse2("Invalid platform audit admin center executor");
|
|
5112
|
+
}
|
|
5113
|
+
return { type: "admin_center", route: value.route };
|
|
5114
|
+
}
|
|
5115
|
+
if (value.type === "ops_agent") {
|
|
5116
|
+
if (value.agentId !== "platform-ops" || typeof value.threadId !== "string" || typeof value.runId !== "string" || typeof value.toolName !== "string") {
|
|
5117
|
+
throw invalidResponse2("Invalid platform audit ops agent executor");
|
|
5118
|
+
}
|
|
5119
|
+
return {
|
|
5120
|
+
type: "ops_agent",
|
|
5121
|
+
agentId: "platform-ops",
|
|
5122
|
+
threadId: value.threadId,
|
|
5123
|
+
runId: value.runId,
|
|
5124
|
+
toolName: value.toolName
|
|
5125
|
+
};
|
|
5126
|
+
}
|
|
5127
|
+
if (value.type === "bootstrap") {
|
|
5128
|
+
return { type: "bootstrap" };
|
|
5129
|
+
}
|
|
5130
|
+
if (value.type === "system") {
|
|
5131
|
+
if (typeof value.component !== "string") {
|
|
5132
|
+
throw invalidResponse2("Invalid platform audit system executor");
|
|
5133
|
+
}
|
|
5134
|
+
return { type: "system", component: value.component };
|
|
5135
|
+
}
|
|
5136
|
+
throw invalidResponse2("Invalid platform audit executor");
|
|
5137
|
+
}
|
|
5138
|
+
function hydrateAuditSource(value) {
|
|
5139
|
+
if (value === "admin_center" || value === "ops_agent" || value === "bootstrap" || value === "system") {
|
|
5140
|
+
return value;
|
|
5141
|
+
}
|
|
5142
|
+
throw invalidResponse2("Invalid platform audit source");
|
|
5143
|
+
}
|
|
5144
|
+
function hydrateAuditAction(value) {
|
|
5145
|
+
if (value === "write" || value === "playbook") return value;
|
|
5146
|
+
throw invalidResponse2("Invalid platform audit action");
|
|
5147
|
+
}
|
|
5148
|
+
function hydrateAuditStatus(value) {
|
|
5149
|
+
if (value === "ok" || value === "error" || value === "cancelled") {
|
|
5150
|
+
return value;
|
|
5151
|
+
}
|
|
5152
|
+
throw invalidResponse2("Invalid platform audit status");
|
|
5153
|
+
}
|
|
5154
|
+
function hydratePlatformAudit(value) {
|
|
5155
|
+
if (!isRecord5(value) || typeof value.id !== "string") {
|
|
5156
|
+
throw invalidResponse2("Invalid platform audit record");
|
|
5157
|
+
}
|
|
5158
|
+
const initiator = hydrateAuditInitiator(value.initiator);
|
|
5159
|
+
const executor = hydrateAuditExecutor(value.executor);
|
|
5160
|
+
const source = hydrateAuditSource(value.source);
|
|
5161
|
+
const action = hydrateAuditAction(value.action);
|
|
5162
|
+
const status = hydrateAuditStatus(value.status);
|
|
5163
|
+
const createdAt = new Date(requiredString5(value, "createdAt"));
|
|
5164
|
+
if (Number.isNaN(createdAt.getTime())) {
|
|
5165
|
+
throw invalidResponse2("Invalid platform audit timestamp");
|
|
5166
|
+
}
|
|
5167
|
+
if (!isRecord5(value.summary)) {
|
|
5168
|
+
throw invalidResponse2("Invalid platform audit summary");
|
|
5169
|
+
}
|
|
5170
|
+
if (typeof value.durationMs !== "number" || !Number.isFinite(value.durationMs)) {
|
|
5171
|
+
throw invalidResponse2("Invalid platform audit duration");
|
|
5172
|
+
}
|
|
5173
|
+
const tenantId = optionalString(value, "tenantId");
|
|
5174
|
+
const before = optionalRecord(value, "before");
|
|
5175
|
+
const after = optionalRecord(value, "after");
|
|
5176
|
+
const errorCode = optionalString(value, "errorCode");
|
|
5177
|
+
return {
|
|
5178
|
+
id: value.id,
|
|
5179
|
+
initiator,
|
|
5180
|
+
source,
|
|
5181
|
+
executor,
|
|
5182
|
+
...tenantId !== void 0 ? { tenantId } : {},
|
|
5183
|
+
action,
|
|
5184
|
+
status,
|
|
5185
|
+
summary: value.summary,
|
|
5186
|
+
...before !== void 0 ? { before } : {},
|
|
5187
|
+
...after !== void 0 ? { after } : {},
|
|
5188
|
+
...errorCode !== void 0 ? { errorCode } : {},
|
|
5189
|
+
durationMs: value.durationMs,
|
|
5190
|
+
createdAt
|
|
5191
|
+
};
|
|
5192
|
+
}
|
|
5193
|
+
function requireRecordValue(value, message) {
|
|
5194
|
+
if (!isRecord5(value)) throw invalidResponse2(message);
|
|
5195
|
+
return value;
|
|
5196
|
+
}
|
|
5197
|
+
function hydrateModelCatalog(value) {
|
|
5198
|
+
if (!isRecord5(value) || !Array.isArray(value.providers) || !Array.isArray(value.models)) {
|
|
5199
|
+
throw invalidResponse2("Invalid platform model catalog");
|
|
5200
|
+
}
|
|
5201
|
+
return value;
|
|
5202
|
+
}
|
|
5203
|
+
function hydrateOpsConfig(value) {
|
|
5204
|
+
if (!isRecord5(value) || typeof value.enabled !== "boolean" || typeof value.modelConfigured !== "boolean") {
|
|
5205
|
+
throw invalidResponse2("Invalid platform ops config");
|
|
5206
|
+
}
|
|
5207
|
+
return {
|
|
5208
|
+
enabled: value.enabled,
|
|
5209
|
+
modelKey: requiredString5(value, "modelKey"),
|
|
5210
|
+
modelConfigured: value.modelConfigured
|
|
5211
|
+
};
|
|
5212
|
+
}
|
|
5167
5213
|
function errorFromEnvelope2(payload, response) {
|
|
5168
5214
|
const raw = payload?.error;
|
|
5169
5215
|
if (typeof raw === "string") {
|
|
@@ -5190,13 +5236,113 @@ var PlatformClient = class {
|
|
|
5190
5236
|
constructor(baseURL, getHeaders) {
|
|
5191
5237
|
this.baseURL = baseURL;
|
|
5192
5238
|
this.getHeaders = getHeaders;
|
|
5239
|
+
const providerPath = (providerId) => `/api/platform/model-providers/${encodeURIComponent(providerId)}`;
|
|
5240
|
+
this.ops = {
|
|
5241
|
+
getConfig: async () => {
|
|
5242
|
+
const data = await this.request("/api/platform/ops/config");
|
|
5243
|
+
return hydrateOpsConfig(data);
|
|
5244
|
+
}
|
|
5245
|
+
};
|
|
5246
|
+
this.modelProviders = {
|
|
5247
|
+
list: async () => {
|
|
5248
|
+
const data = await this.request("/api/platform/model-providers");
|
|
5249
|
+
if (!isRecord5(data) || !Array.isArray(data.records)) {
|
|
5250
|
+
throw invalidResponse2("Invalid platform model provider list");
|
|
5251
|
+
}
|
|
5252
|
+
return data.records;
|
|
5253
|
+
},
|
|
5254
|
+
get: async (providerId) => {
|
|
5255
|
+
const data = await this.request(providerPath(providerId));
|
|
5256
|
+
return requireRecordValue(
|
|
5257
|
+
data,
|
|
5258
|
+
"Invalid platform model provider"
|
|
5259
|
+
);
|
|
5260
|
+
},
|
|
5261
|
+
create: async (input) => {
|
|
5262
|
+
const data = await this.request("/api/platform/model-providers", {
|
|
5263
|
+
method: "POST",
|
|
5264
|
+
body: JSON.stringify(input)
|
|
5265
|
+
});
|
|
5266
|
+
return requireRecordValue(
|
|
5267
|
+
data,
|
|
5268
|
+
"Invalid platform model provider"
|
|
5269
|
+
);
|
|
5270
|
+
},
|
|
5271
|
+
update: async (providerId, input) => {
|
|
5272
|
+
const data = await this.request(providerPath(providerId), {
|
|
5273
|
+
method: "PUT",
|
|
5274
|
+
body: JSON.stringify(input)
|
|
5275
|
+
});
|
|
5276
|
+
return requireRecordValue(
|
|
5277
|
+
data,
|
|
5278
|
+
"Invalid platform model provider"
|
|
5279
|
+
);
|
|
5280
|
+
},
|
|
5281
|
+
delete: async (providerId) => {
|
|
5282
|
+
await this.request(providerPath(providerId), { method: "DELETE" });
|
|
5283
|
+
},
|
|
5284
|
+
probe: async (input) => {
|
|
5285
|
+
const data = await this.request(
|
|
5286
|
+
"/api/platform/model-providers/probe",
|
|
5287
|
+
{ method: "POST", body: JSON.stringify(input) }
|
|
5288
|
+
);
|
|
5289
|
+
return requireRecordValue(
|
|
5290
|
+
data,
|
|
5291
|
+
"Invalid platform model provider probe"
|
|
5292
|
+
);
|
|
5293
|
+
},
|
|
5294
|
+
setModels: async (providerId, models) => {
|
|
5295
|
+
const data = await this.request(
|
|
5296
|
+
`${providerPath(providerId)}/models`,
|
|
5297
|
+
{ method: "PUT", body: JSON.stringify({ models }) }
|
|
5298
|
+
);
|
|
5299
|
+
return requireRecordValue(
|
|
5300
|
+
data,
|
|
5301
|
+
"Invalid platform model provider"
|
|
5302
|
+
);
|
|
5303
|
+
},
|
|
5304
|
+
discover: async (providerId) => {
|
|
5305
|
+
const data = await this.request(
|
|
5306
|
+
`${providerPath(providerId)}/discover`,
|
|
5307
|
+
{ method: "POST", body: JSON.stringify({}) }
|
|
5308
|
+
);
|
|
5309
|
+
return requireRecordValue(
|
|
5310
|
+
data,
|
|
5311
|
+
"Invalid platform model discovery result"
|
|
5312
|
+
);
|
|
5313
|
+
},
|
|
5314
|
+
setModelEnabled: async (providerId, modelId, enabled) => {
|
|
5315
|
+
const data = await this.request(
|
|
5316
|
+
`${providerPath(providerId)}/models/enabled`,
|
|
5317
|
+
{ method: "POST", body: JSON.stringify({ modelId, enabled }) }
|
|
5318
|
+
);
|
|
5319
|
+
return requireRecordValue(
|
|
5320
|
+
data,
|
|
5321
|
+
"Invalid platform model provider"
|
|
5322
|
+
);
|
|
5323
|
+
}
|
|
5324
|
+
};
|
|
5325
|
+
}
|
|
5326
|
+
/**
|
|
5327
|
+
* Reads the platform-owned model catalog (providers plus visible models).
|
|
5328
|
+
*
|
|
5329
|
+
* This is the platform-scoped counterpart of `client.tenantModels.list()`.
|
|
5330
|
+
*/
|
|
5331
|
+
async modelCatalog() {
|
|
5332
|
+
const data = await this.request("/api/platform/model-catalog");
|
|
5333
|
+
return hydrateModelCatalog(data);
|
|
5334
|
+
}
|
|
5335
|
+
async rateLimits() {
|
|
5336
|
+
const data = await this.request("/api/platform/rate-limits");
|
|
5337
|
+
if (!isRecord5(data) || !Array.isArray(data.policies)) {
|
|
5338
|
+
throw invalidResponse2("Invalid platform rate-limit view");
|
|
5339
|
+
}
|
|
5340
|
+
return data;
|
|
5193
5341
|
}
|
|
5194
5342
|
async me() {
|
|
5195
5343
|
const data = await this.request("/api/platform/me");
|
|
5196
|
-
if (!isRecord5(data))
|
|
5197
|
-
|
|
5198
|
-
if (data.role === null || data.role === void 0)
|
|
5199
|
-
return null;
|
|
5344
|
+
if (!isRecord5(data)) throw invalidResponse2("Invalid platform identity");
|
|
5345
|
+
if (data.role === null || data.role === void 0) return null;
|
|
5200
5346
|
return hydratePlatformRole(data.role);
|
|
5201
5347
|
}
|
|
5202
5348
|
/**
|
|
@@ -5247,6 +5393,39 @@ var PlatformClient = class {
|
|
|
5247
5393
|
const data = await this.request("/api/platform/environment");
|
|
5248
5394
|
return hydrateEnvironment(data);
|
|
5249
5395
|
}
|
|
5396
|
+
/**
|
|
5397
|
+
* Reads platform audit records, newest first.
|
|
5398
|
+
*
|
|
5399
|
+
* @param query Optional filters and pagination. Undefined values are omitted
|
|
5400
|
+
* from the request.
|
|
5401
|
+
* @returns Hydrated records with `createdAt` as a `Date`.
|
|
5402
|
+
*/
|
|
5403
|
+
async listAudit(query = {}) {
|
|
5404
|
+
const search = new URLSearchParams();
|
|
5405
|
+
for (const [key, value] of Object.entries(query)) {
|
|
5406
|
+
if (value !== void 0) search.set(key, String(value));
|
|
5407
|
+
}
|
|
5408
|
+
const suffix = search.toString();
|
|
5409
|
+
const data = await this.request(
|
|
5410
|
+
`/api/platform/audit${suffix ? `?${suffix}` : ""}`
|
|
5411
|
+
);
|
|
5412
|
+
if (!Array.isArray(data)) {
|
|
5413
|
+
throw invalidResponse2("Invalid platform audit list");
|
|
5414
|
+
}
|
|
5415
|
+
return data.map(hydratePlatformAudit);
|
|
5416
|
+
}
|
|
5417
|
+
/**
|
|
5418
|
+
* Reads a single platform audit record by id.
|
|
5419
|
+
*
|
|
5420
|
+
* @param auditId Audit record id.
|
|
5421
|
+
* @returns The hydrated record with `createdAt` as a `Date`.
|
|
5422
|
+
*/
|
|
5423
|
+
async getAudit(auditId) {
|
|
5424
|
+
const data = await this.request(
|
|
5425
|
+
`/api/platform/audit/${encodeURIComponent(auditId)}`
|
|
5426
|
+
);
|
|
5427
|
+
return hydratePlatformAudit(data);
|
|
5428
|
+
}
|
|
5250
5429
|
/**
|
|
5251
5430
|
* Resolves the public branding for the current gateway host.
|
|
5252
5431
|
*
|
|
@@ -5277,8 +5456,7 @@ var PlatformClient = class {
|
|
|
5277
5456
|
}
|
|
5278
5457
|
async listTenants() {
|
|
5279
5458
|
const data = await this.request("/api/tenants");
|
|
5280
|
-
if (!Array.isArray(data))
|
|
5281
|
-
throw invalidResponse2("Invalid tenant list");
|
|
5459
|
+
if (!Array.isArray(data)) throw invalidResponse2("Invalid tenant list");
|
|
5282
5460
|
return data.map(hydrateTenant);
|
|
5283
5461
|
}
|
|
5284
5462
|
async createTenant(input) {
|
|
@@ -5303,8 +5481,7 @@ var PlatformClient = class {
|
|
|
5303
5481
|
}
|
|
5304
5482
|
async listUsers() {
|
|
5305
5483
|
const data = await this.request("/api/users");
|
|
5306
|
-
if (!Array.isArray(data))
|
|
5307
|
-
throw invalidResponse2("Invalid user list");
|
|
5484
|
+
if (!Array.isArray(data)) throw invalidResponse2("Invalid user list");
|
|
5308
5485
|
return data.map(hydrateUser);
|
|
5309
5486
|
}
|
|
5310
5487
|
async createUser(input) {
|
|
@@ -5328,8 +5505,7 @@ var PlatformClient = class {
|
|
|
5328
5505
|
}
|
|
5329
5506
|
async listMembers() {
|
|
5330
5507
|
const data = await this.request("/api/platform/members");
|
|
5331
|
-
if (!Array.isArray(data))
|
|
5332
|
-
throw invalidResponse2("Invalid member list");
|
|
5508
|
+
if (!Array.isArray(data)) throw invalidResponse2("Invalid member list");
|
|
5333
5509
|
return data.map(hydrateMember3);
|
|
5334
5510
|
}
|
|
5335
5511
|
async grantMember(input) {
|
|
@@ -5337,8 +5513,7 @@ var PlatformClient = class {
|
|
|
5337
5513
|
method: "POST",
|
|
5338
5514
|
body: JSON.stringify(input)
|
|
5339
5515
|
});
|
|
5340
|
-
if (!isRecord5(data))
|
|
5341
|
-
throw invalidResponse2("Invalid platform grant");
|
|
5516
|
+
if (!isRecord5(data)) throw invalidResponse2("Invalid platform grant");
|
|
5342
5517
|
const member = data.member !== void 0 ? hydrateMember3(data.member) : void 0;
|
|
5343
5518
|
const invitation = data.invitation !== void 0 ? hydrateInvitation(data.invitation) : void 0;
|
|
5344
5519
|
if (!member && !invitation) {
|
|
@@ -5351,8 +5526,7 @@ var PlatformClient = class {
|
|
|
5351
5526
|
}
|
|
5352
5527
|
async listInvitations() {
|
|
5353
5528
|
const data = await this.request("/api/platform/invitations");
|
|
5354
|
-
if (!Array.isArray(data))
|
|
5355
|
-
throw invalidResponse2("Invalid invitation list");
|
|
5529
|
+
if (!Array.isArray(data)) throw invalidResponse2("Invalid invitation list");
|
|
5356
5530
|
return data.map(hydrateInvitation);
|
|
5357
5531
|
}
|
|
5358
5532
|
async revokeInvitation(email) {
|
|
@@ -5379,8 +5553,7 @@ var PlatformClient = class {
|
|
|
5379
5553
|
const data = await this.request(
|
|
5380
5554
|
`/api/platform/tenant-members?${query}`
|
|
5381
5555
|
);
|
|
5382
|
-
if (!Array.isArray(data))
|
|
5383
|
-
throw invalidResponse2("Invalid tenant member list");
|
|
5556
|
+
if (!Array.isArray(data)) throw invalidResponse2("Invalid tenant member list");
|
|
5384
5557
|
return data.map(hydrateTenantMember);
|
|
5385
5558
|
}
|
|
5386
5559
|
async addTenantMember(input) {
|
|
@@ -5392,8 +5565,7 @@ var PlatformClient = class {
|
|
|
5392
5565
|
}
|
|
5393
5566
|
async listInviteLinks() {
|
|
5394
5567
|
const data = await this.request("/api/platform/invite-links");
|
|
5395
|
-
if (!Array.isArray(data))
|
|
5396
|
-
throw invalidResponse2("Invalid invite link list");
|
|
5568
|
+
if (!Array.isArray(data)) throw invalidResponse2("Invalid invite link list");
|
|
5397
5569
|
return data.map(hydrateInviteLink);
|
|
5398
5570
|
}
|
|
5399
5571
|
async createInviteLink(input) {
|
|
@@ -5452,8 +5624,7 @@ var PlatformClient = class {
|
|
|
5452
5624
|
async listOidcClaims(status = "pending") {
|
|
5453
5625
|
const query = new URLSearchParams({ status }).toString();
|
|
5454
5626
|
const data = await this.request(`/api/platform/oidc-claims?${query}`);
|
|
5455
|
-
if (!Array.isArray(data))
|
|
5456
|
-
throw invalidResponse2("Invalid SSO claim list");
|
|
5627
|
+
if (!Array.isArray(data)) throw invalidResponse2("Invalid SSO claim list");
|
|
5457
5628
|
return data.map(hydrateOidcIdentityClaim);
|
|
5458
5629
|
}
|
|
5459
5630
|
async updateOidcClaimEmail(id, email) {
|
|
@@ -5478,7 +5649,10 @@ var PlatformClient = class {
|
|
|
5478
5649
|
return hydrateOidcIdentityClaim(data);
|
|
5479
5650
|
}
|
|
5480
5651
|
async request(path, init = {}) {
|
|
5481
|
-
const headers = {
|
|
5652
|
+
const headers = {
|
|
5653
|
+
...this.getHeaders(),
|
|
5654
|
+
...init.headers
|
|
5655
|
+
};
|
|
5482
5656
|
if (init.body !== void 0) {
|
|
5483
5657
|
headers["Content-Type"] = "application/json";
|
|
5484
5658
|
}
|
|
@@ -5495,7 +5669,7 @@ var PlatformClient = class {
|
|
|
5495
5669
|
};
|
|
5496
5670
|
|
|
5497
5671
|
// src/client.ts
|
|
5498
|
-
var _Client = class extends AbstractClient {
|
|
5672
|
+
var _Client = class _Client extends AbstractClient {
|
|
5499
5673
|
/**
|
|
5500
5674
|
* Creates a new Client instance
|
|
5501
5675
|
* @param config - Configuration options for the client
|
|
@@ -5798,8 +5972,7 @@ var _Client = class extends AbstractClient {
|
|
|
5798
5972
|
...this.getAllHeaders()
|
|
5799
5973
|
};
|
|
5800
5974
|
const res = await fetch(`${this.config.baseURL}${path}`, { headers, signal });
|
|
5801
|
-
if (!res.ok || !res.body)
|
|
5802
|
-
throw new Error("Stream connection failed");
|
|
5975
|
+
if (!res.ok || !res.body) throw new Error("Stream connection failed");
|
|
5803
5976
|
try {
|
|
5804
5977
|
for await (const frame of parseSseBody(res.body, { strictJsonObject: true })) {
|
|
5805
5978
|
yield { event: frame.event, data: frame.data };
|
|
@@ -5828,8 +6001,7 @@ var _Client = class extends AbstractClient {
|
|
|
5828
6001
|
return this.getAllHeaders();
|
|
5829
6002
|
}
|
|
5830
6003
|
bodyAffinityHeaders(body) {
|
|
5831
|
-
if (!body || typeof body !== "object" || body instanceof FormData)
|
|
5832
|
-
return {};
|
|
6004
|
+
if (!body || typeof body !== "object" || body instanceof FormData) return {};
|
|
5833
6005
|
const threadId = body.thread_id;
|
|
5834
6006
|
return typeof threadId === "string" ? (0, import_protocols2.threadAffinityHeaders)(threadId) : {};
|
|
5835
6007
|
}
|
|
@@ -5863,8 +6035,7 @@ var _Client = class extends AbstractClient {
|
|
|
5863
6035
|
if (!response.body) {
|
|
5864
6036
|
throw new Error("Response body is null");
|
|
5865
6037
|
}
|
|
5866
|
-
for await (const frame of parseSseBody(response.body, { strictJsonObject: true }))
|
|
5867
|
-
onEvent(frame.data);
|
|
6038
|
+
for await (const frame of parseSseBody(response.body, { strictJsonObject: true })) onEvent(frame.data);
|
|
5868
6039
|
if (onComplete) {
|
|
5869
6040
|
if (options.enableReturnStateWhenSteamCompleted) {
|
|
5870
6041
|
try {
|
|
@@ -5891,11 +6062,11 @@ var _Client = class extends AbstractClient {
|
|
|
5891
6062
|
};
|
|
5892
6063
|
}
|
|
5893
6064
|
};
|
|
6065
|
+
_Client.globalWorkspaceHeaders = {};
|
|
5894
6066
|
var Client = _Client;
|
|
5895
|
-
Client.globalWorkspaceHeaders = {};
|
|
5896
6067
|
|
|
5897
6068
|
// src/runtime-client.ts
|
|
5898
|
-
var RuntimeAxiomClient = class extends Client {
|
|
6069
|
+
var RuntimeAxiomClient = class _RuntimeAxiomClient extends Client {
|
|
5899
6070
|
constructor(config) {
|
|
5900
6071
|
super({
|
|
5901
6072
|
...config,
|
|
@@ -5922,8 +6093,7 @@ var RuntimeAxiomClient = class extends Client {
|
|
|
5922
6093
|
* priming — the first request triggers the token provider.
|
|
5923
6094
|
*/
|
|
5924
6095
|
async primeToken() {
|
|
5925
|
-
if (this.identity.mode !== "verified")
|
|
5926
|
-
return "";
|
|
6096
|
+
if (this.identity.mode !== "verified") return "";
|
|
5927
6097
|
if (!this.tokenPromise) {
|
|
5928
6098
|
this.tokenPromise = this.identity.tokenProvider().then((token) => {
|
|
5929
6099
|
this.token = token;
|
|
@@ -5972,8 +6142,7 @@ var RuntimeAxiomClient = class extends Client {
|
|
|
5972
6142
|
error.status = response.status;
|
|
5973
6143
|
throw error;
|
|
5974
6144
|
}
|
|
5975
|
-
if (response.status === 204)
|
|
5976
|
-
return void 0;
|
|
6145
|
+
if (response.status === 204) return void 0;
|
|
5977
6146
|
return await response.json();
|
|
5978
6147
|
}
|
|
5979
6148
|
getBaseUrl() {
|
|
@@ -5985,7 +6154,7 @@ var RuntimeAxiomClient = class extends Client {
|
|
|
5985
6154
|
* working (each clone carries its own resolved credential cache).
|
|
5986
6155
|
*/
|
|
5987
6156
|
createInstance(config) {
|
|
5988
|
-
return new
|
|
6157
|
+
return new _RuntimeAxiomClient({
|
|
5989
6158
|
gatewayUrl: this.gatewayUrl,
|
|
5990
6159
|
webAppId: this.webAppId,
|
|
5991
6160
|
identity: this.identity,
|
|
@@ -6004,7 +6173,7 @@ var RuntimeAxiomClient = class extends Client {
|
|
|
6004
6173
|
// src/wechat-client.ts
|
|
6005
6174
|
var import_protocols3 = require("@axiom-lattice/protocols");
|
|
6006
6175
|
var import_encoding = __toESM(require_encoding());
|
|
6007
|
-
var WeChatClient = class extends AbstractClient {
|
|
6176
|
+
var WeChatClient = class _WeChatClient extends AbstractClient {
|
|
6008
6177
|
/**
|
|
6009
6178
|
* Creates a new WeChatClient instance
|
|
6010
6179
|
* @param config - Configuration options for the client
|
|
@@ -6029,16 +6198,12 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6029
6198
|
*/
|
|
6030
6199
|
setWorkspaceContext(workspaceId, projectId) {
|
|
6031
6200
|
if (workspaceId !== void 0) {
|
|
6032
|
-
if (workspaceId)
|
|
6033
|
-
|
|
6034
|
-
else
|
|
6035
|
-
delete this.workspaceHeaders["x-workspace-id"];
|
|
6201
|
+
if (workspaceId) this.workspaceHeaders["x-workspace-id"] = workspaceId;
|
|
6202
|
+
else delete this.workspaceHeaders["x-workspace-id"];
|
|
6036
6203
|
}
|
|
6037
6204
|
if (projectId !== void 0) {
|
|
6038
|
-
if (projectId)
|
|
6039
|
-
|
|
6040
|
-
else
|
|
6041
|
-
delete this.workspaceHeaders["x-project-id"];
|
|
6205
|
+
if (projectId) this.workspaceHeaders["x-project-id"] = projectId;
|
|
6206
|
+
else delete this.workspaceHeaders["x-project-id"];
|
|
6042
6207
|
}
|
|
6043
6208
|
}
|
|
6044
6209
|
/**
|
|
@@ -6054,7 +6219,7 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6054
6219
|
* @returns A new WeChatClient instance
|
|
6055
6220
|
*/
|
|
6056
6221
|
createInstance(config) {
|
|
6057
|
-
return new
|
|
6222
|
+
return new _WeChatClient(config);
|
|
6058
6223
|
}
|
|
6059
6224
|
/**
|
|
6060
6225
|
* Implementation of the abstract makeRequest method for WeChat clients
|
|
@@ -6114,8 +6279,7 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6114
6279
|
let pending = "";
|
|
6115
6280
|
const handleLine = (line) => {
|
|
6116
6281
|
const trimmed = line.trim();
|
|
6117
|
-
if (!trimmed.startsWith("data:"))
|
|
6118
|
-
return;
|
|
6282
|
+
if (!trimmed.startsWith("data:")) return;
|
|
6119
6283
|
const payload = trimmed.slice("data:".length);
|
|
6120
6284
|
const json = payload.startsWith(" ") ? payload.slice(1) : payload;
|
|
6121
6285
|
try {
|
|
@@ -6127,8 +6291,7 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6127
6291
|
}
|
|
6128
6292
|
};
|
|
6129
6293
|
const push = (res) => {
|
|
6130
|
-
if (!res.data)
|
|
6131
|
-
return;
|
|
6294
|
+
if (!res.data) return;
|
|
6132
6295
|
pending += decoder.decode(res.data, { stream: true });
|
|
6133
6296
|
const lines = pending.split("\n");
|
|
6134
6297
|
pending = lines.pop();
|
|
@@ -6154,8 +6317,7 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6154
6317
|
errorMessageFromBody(data) {
|
|
6155
6318
|
if (typeof data === "string") {
|
|
6156
6319
|
const text = data.trim();
|
|
6157
|
-
if (!text)
|
|
6158
|
-
return void 0;
|
|
6320
|
+
if (!text) return void 0;
|
|
6159
6321
|
try {
|
|
6160
6322
|
return this.recordMessage(JSON.parse(text));
|
|
6161
6323
|
} catch {
|
|
@@ -6183,8 +6345,7 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6183
6345
|
*/
|
|
6184
6346
|
streamStatusError(res) {
|
|
6185
6347
|
const statusCode = res.statusCode;
|
|
6186
|
-
if (statusCode >= 200 && statusCode < 300)
|
|
6187
|
-
return void 0;
|
|
6348
|
+
if (statusCode >= 200 && statusCode < 300) return void 0;
|
|
6188
6349
|
const message = this.errorMessageFromBody(res.data);
|
|
6189
6350
|
if (statusCode === 401) {
|
|
6190
6351
|
return new AuthenticationError(message || "Authentication failed");
|
|
@@ -6234,26 +6395,22 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6234
6395
|
responseType: "text",
|
|
6235
6396
|
enableChunked: true,
|
|
6236
6397
|
success: (res) => {
|
|
6237
|
-
if (aborted || terminal)
|
|
6238
|
-
return;
|
|
6398
|
+
if (aborted || terminal) return;
|
|
6239
6399
|
const error = this.streamStatusError(res);
|
|
6240
6400
|
if (error) {
|
|
6241
6401
|
terminal = true;
|
|
6242
|
-
if (onError)
|
|
6243
|
-
onError(error);
|
|
6402
|
+
if (onError) onError(error);
|
|
6244
6403
|
}
|
|
6245
6404
|
},
|
|
6246
6405
|
fail: (err) => {
|
|
6247
|
-
if (aborted)
|
|
6248
|
-
return;
|
|
6406
|
+
if (aborted) return;
|
|
6249
6407
|
terminal = true;
|
|
6250
6408
|
if (onError) {
|
|
6251
6409
|
onError(new Error(`Resume stream request failed: ${err.errMsg}`));
|
|
6252
6410
|
}
|
|
6253
6411
|
},
|
|
6254
6412
|
complete: () => {
|
|
6255
|
-
if (terminal)
|
|
6256
|
-
return;
|
|
6413
|
+
if (terminal) return;
|
|
6257
6414
|
processor.flush();
|
|
6258
6415
|
if (onComplete) {
|
|
6259
6416
|
onComplete();
|
|
@@ -6261,8 +6418,7 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6261
6418
|
}
|
|
6262
6419
|
});
|
|
6263
6420
|
requestTask.onChunkReceived((res) => {
|
|
6264
|
-
if (terminal)
|
|
6265
|
-
return;
|
|
6421
|
+
if (terminal) return;
|
|
6266
6422
|
processor.push(res);
|
|
6267
6423
|
});
|
|
6268
6424
|
return () => {
|
|
@@ -6349,26 +6505,22 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6349
6505
|
responseType: "text",
|
|
6350
6506
|
enableChunked: true,
|
|
6351
6507
|
success: (res) => {
|
|
6352
|
-
if (aborted || terminal)
|
|
6353
|
-
return;
|
|
6508
|
+
if (aborted || terminal) return;
|
|
6354
6509
|
const error = this.streamStatusError(res);
|
|
6355
6510
|
if (error) {
|
|
6356
6511
|
terminal = true;
|
|
6357
|
-
if (onError)
|
|
6358
|
-
onError(error);
|
|
6512
|
+
if (onError) onError(error);
|
|
6359
6513
|
}
|
|
6360
6514
|
},
|
|
6361
6515
|
fail: (err) => {
|
|
6362
|
-
if (aborted)
|
|
6363
|
-
return;
|
|
6516
|
+
if (aborted) return;
|
|
6364
6517
|
terminal = true;
|
|
6365
6518
|
if (onError) {
|
|
6366
6519
|
onError(new Error(`Stream request failed: ${err.errMsg}`));
|
|
6367
6520
|
}
|
|
6368
6521
|
},
|
|
6369
6522
|
complete: async () => {
|
|
6370
|
-
if (terminal)
|
|
6371
|
-
return;
|
|
6523
|
+
if (terminal) return;
|
|
6372
6524
|
processor.flush();
|
|
6373
6525
|
if (onComplete) {
|
|
6374
6526
|
if (options.enableReturnStateWhenSteamCompleted) {
|
|
@@ -6385,8 +6537,7 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6385
6537
|
}
|
|
6386
6538
|
});
|
|
6387
6539
|
requestTask.onChunkReceived((res) => {
|
|
6388
|
-
if (terminal)
|
|
6389
|
-
return;
|
|
6540
|
+
if (terminal) return;
|
|
6390
6541
|
processor.push(res);
|
|
6391
6542
|
});
|
|
6392
6543
|
return () => {
|
|
@@ -6656,8 +6807,7 @@ var WorkspaceClient = class {
|
|
|
6656
6807
|
*/
|
|
6657
6808
|
async downloadFolder(workspaceId, projectId, folderPath, assistantId) {
|
|
6658
6809
|
const params = new URLSearchParams({ path: folderPath, tenantId: this.tenantId });
|
|
6659
|
-
if (assistantId)
|
|
6660
|
-
params.set("assistantId", assistantId);
|
|
6810
|
+
if (assistantId) params.set("assistantId", assistantId);
|
|
6661
6811
|
const response = await fetch(
|
|
6662
6812
|
`${this.baseURL}/api/workspaces/${workspaceId}/projects/${projectId}/downloadfolder?${params}`,
|
|
6663
6813
|
{ headers: this.headers }
|
|
@@ -6708,24 +6858,18 @@ var isObj = (v) => typeof v === "object" && v !== null;
|
|
|
6708
6858
|
var TEXT_BLOCK_TYPES = /* @__PURE__ */ new Set(["text"]);
|
|
6709
6859
|
var ARTIFACT_SENTINEL_TYPES = /* @__PURE__ */ new Set(["mcp_structured_content", "mcp_meta"]);
|
|
6710
6860
|
function asBlocks(value) {
|
|
6711
|
-
if (Array.isArray(value))
|
|
6712
|
-
|
|
6713
|
-
if (value === void 0 || value === null)
|
|
6714
|
-
return [];
|
|
6861
|
+
if (Array.isArray(value)) return value;
|
|
6862
|
+
if (value === void 0 || value === null) return [];
|
|
6715
6863
|
return [value];
|
|
6716
6864
|
}
|
|
6717
6865
|
function looksLikeResource(block) {
|
|
6718
6866
|
return typeof block.uri === "string" && ("mimeType" in block || "blob" in block || "text" in block);
|
|
6719
6867
|
}
|
|
6720
6868
|
function textOf(block, allowUntyped) {
|
|
6721
|
-
if (typeof block === "string")
|
|
6722
|
-
|
|
6723
|
-
if (
|
|
6724
|
-
|
|
6725
|
-
if (block.type === "text")
|
|
6726
|
-
return block.text;
|
|
6727
|
-
if (allowUntyped && block.type === void 0 && !looksLikeResource(block))
|
|
6728
|
-
return block.text;
|
|
6869
|
+
if (typeof block === "string") return block;
|
|
6870
|
+
if (!isObj(block) || typeof block.text !== "string") return null;
|
|
6871
|
+
if (block.type === "text") return block.text;
|
|
6872
|
+
if (allowUntyped && block.type === void 0 && !looksLikeResource(block)) return block.text;
|
|
6729
6873
|
return null;
|
|
6730
6874
|
}
|
|
6731
6875
|
function joinText(blocks, allowUntyped) {
|
|
@@ -6749,15 +6893,13 @@ function structuredFromArtifact(artifact) {
|
|
|
6749
6893
|
}
|
|
6750
6894
|
function metaFromContent(content) {
|
|
6751
6895
|
for (const block of asBlocks(content)) {
|
|
6752
|
-
if (isObj(block) && isObj(block.meta))
|
|
6753
|
-
return block.meta;
|
|
6896
|
+
if (isObj(block) && isObj(block.meta)) return block.meta;
|
|
6754
6897
|
}
|
|
6755
6898
|
return void 0;
|
|
6756
6899
|
}
|
|
6757
6900
|
function metaFromArtifact(artifact) {
|
|
6758
6901
|
for (const item of asBlocks(artifact)) {
|
|
6759
|
-
if (isObj(item) && item.type === "mcp_meta" && isObj(item.data))
|
|
6760
|
-
return item.data;
|
|
6902
|
+
if (isObj(item) && item.type === "mcp_meta" && isObj(item.data)) return item.data;
|
|
6761
6903
|
}
|
|
6762
6904
|
return void 0;
|
|
6763
6905
|
}
|
|
@@ -6785,22 +6927,17 @@ function normalizeToolResult(message) {
|
|
|
6785
6927
|
structuredContent = structuredFromArtifact(message.artifact);
|
|
6786
6928
|
}
|
|
6787
6929
|
let meta = metaFromContent(message.content);
|
|
6788
|
-
if (meta === void 0)
|
|
6789
|
-
meta = metaFromArtifact(message.artifact);
|
|
6930
|
+
if (meta === void 0) meta = metaFromArtifact(message.artifact);
|
|
6790
6931
|
const artifactBlocks = asBlocks(message.artifact).map(toUiBlock).filter(
|
|
6791
6932
|
(b) => b !== null && !ARTIFACT_SENTINEL_TYPES.has(b.type)
|
|
6792
6933
|
);
|
|
6793
6934
|
const allBlocks = [...contentBlocks, ...artifactBlocks];
|
|
6794
6935
|
let text = joinText(asBlocks(message.content), true);
|
|
6795
|
-
if (text.length === 0)
|
|
6796
|
-
text = joinText(asBlocks(message.artifact), false);
|
|
6936
|
+
if (text.length === 0) text = joinText(asBlocks(message.artifact), false);
|
|
6797
6937
|
const ui = {};
|
|
6798
|
-
if (structuredContent !== void 0)
|
|
6799
|
-
|
|
6800
|
-
if (
|
|
6801
|
-
ui.meta = meta;
|
|
6802
|
-
if (allBlocks.length > 0)
|
|
6803
|
-
ui.contentBlocks = allBlocks;
|
|
6938
|
+
if (structuredContent !== void 0) ui.structuredContent = structuredContent;
|
|
6939
|
+
if (meta !== void 0) ui.meta = meta;
|
|
6940
|
+
if (allBlocks.length > 0) ui.contentBlocks = allBlocks;
|
|
6804
6941
|
return Object.keys(ui).length > 0 ? { text, ui } : { text };
|
|
6805
6942
|
}
|
|
6806
6943
|
|
|
@@ -6864,16 +7001,14 @@ function createSimpleMessageMerger() {
|
|
|
6864
7001
|
}
|
|
6865
7002
|
function replaceMessage(id, updates) {
|
|
6866
7003
|
const index = messageMap.get(id);
|
|
6867
|
-
if (index === void 0)
|
|
6868
|
-
return null;
|
|
7004
|
+
if (index === void 0) return null;
|
|
6869
7005
|
const updated = { ...messages[index], ...updates };
|
|
6870
7006
|
messages[index] = updated;
|
|
6871
7007
|
return updated;
|
|
6872
7008
|
}
|
|
6873
7009
|
function buildToolCalls(messageId) {
|
|
6874
7010
|
const builders = toolBuilders.get(messageId);
|
|
6875
|
-
if (!builders || builders.size === 0)
|
|
6876
|
-
return null;
|
|
7011
|
+
if (!builders || builders.size === 0) return null;
|
|
6877
7012
|
const toolCalls = [];
|
|
6878
7013
|
for (const [, builder] of Array.from(builders.entries())) {
|
|
6879
7014
|
if (builder.name && builder.id) {
|
|
@@ -6896,8 +7031,7 @@ function createSimpleMessageMerger() {
|
|
|
6896
7031
|
});
|
|
6897
7032
|
}
|
|
6898
7033
|
function push(chunk) {
|
|
6899
|
-
if (chunk.type === "error")
|
|
6900
|
-
return;
|
|
7034
|
+
if (chunk.type === "error") return;
|
|
6901
7035
|
const role = normalizeRole(chunk.type);
|
|
6902
7036
|
let message = ensureMessage(chunk.data.id, role);
|
|
6903
7037
|
if (chunk.data.content && message.role !== "tool") {
|
|
@@ -6935,14 +7069,12 @@ function createSimpleMessageMerger() {
|
|
|
6935
7069
|
builder = { args: "" };
|
|
6936
7070
|
builders.set(chunk_item.index, builder);
|
|
6937
7071
|
}
|
|
6938
|
-
if (chunk_item.name)
|
|
6939
|
-
builder.name = chunk_item.name;
|
|
7072
|
+
if (chunk_item.name) builder.name = chunk_item.name;
|
|
6940
7073
|
if (chunk_item.id) {
|
|
6941
7074
|
builder.id = chunk_item.id;
|
|
6942
7075
|
toolId_MessageIdMap.set(chunk_item.id, message.id);
|
|
6943
7076
|
}
|
|
6944
|
-
if (chunk_item.args)
|
|
6945
|
-
builder.args += chunk_item.args;
|
|
7077
|
+
if (chunk_item.args) builder.args += chunk_item.args;
|
|
6946
7078
|
}
|
|
6947
7079
|
const toolCalls = buildToolCalls(message.id);
|
|
6948
7080
|
if (toolCalls) {
|
|
@@ -6952,8 +7084,7 @@ function createSimpleMessageMerger() {
|
|
|
6952
7084
|
if (message.role === "tool" && chunk.data.tool_call_id) {
|
|
6953
7085
|
const original_tool_message_id = chunk.data.id;
|
|
6954
7086
|
const messageId = toolId_MessageIdMap.get(chunk.data.tool_call_id);
|
|
6955
|
-
if (!messageId)
|
|
6956
|
-
return;
|
|
7087
|
+
if (!messageId) return;
|
|
6957
7088
|
const messageIndex = messageMap.get(messageId);
|
|
6958
7089
|
if (messageIndex !== void 0) {
|
|
6959
7090
|
const { text, ui } = normalizeToolResult({
|