@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.mjs
CHANGED
|
@@ -89,10 +89,8 @@ var require_encoding = __commonJS({
|
|
|
89
89
|
}
|
|
90
90
|
var floor = Math.floor;
|
|
91
91
|
function ToDictionary(o) {
|
|
92
|
-
if (o === void 0)
|
|
93
|
-
|
|
94
|
-
if (o === Object(o))
|
|
95
|
-
return o;
|
|
92
|
+
if (o === void 0) return {};
|
|
93
|
+
if (o === Object(o)) return o;
|
|
96
94
|
throw TypeError("Could not convert argument to dictionary");
|
|
97
95
|
}
|
|
98
96
|
function stringToCodePoints(string) {
|
|
@@ -717,8 +715,7 @@ var require_encoding = __commonJS({
|
|
|
717
715
|
var encoders = {};
|
|
718
716
|
var decoders = {};
|
|
719
717
|
function indexCodePointFor(pointer, index2) {
|
|
720
|
-
if (!index2)
|
|
721
|
-
return null;
|
|
718
|
+
if (!index2) return null;
|
|
722
719
|
return index2[pointer] || null;
|
|
723
720
|
}
|
|
724
721
|
function indexPointerFor(code_point, index2) {
|
|
@@ -734,8 +731,7 @@ var require_encoding = __commonJS({
|
|
|
734
731
|
function indexGB18030RangesCodePointFor(pointer) {
|
|
735
732
|
if (pointer > 39419 && pointer < 189e3 || pointer > 1237575)
|
|
736
733
|
return null;
|
|
737
|
-
if (pointer === 7457)
|
|
738
|
-
return 59335;
|
|
734
|
+
if (pointer === 7457) return 59335;
|
|
739
735
|
var offset = 0;
|
|
740
736
|
var code_point_offset = 0;
|
|
741
737
|
var idx = index("gb18030-ranges");
|
|
@@ -752,8 +748,7 @@ var require_encoding = __commonJS({
|
|
|
752
748
|
return code_point_offset + pointer - offset;
|
|
753
749
|
}
|
|
754
750
|
function indexGB18030RangesPointerFor(code_point) {
|
|
755
|
-
if (code_point === 59335)
|
|
756
|
-
return 7457;
|
|
751
|
+
if (code_point === 59335) return 7457;
|
|
757
752
|
var offset = 0;
|
|
758
753
|
var pointer_offset = 0;
|
|
759
754
|
var idx = index("gb18030-ranges");
|
|
@@ -1887,8 +1882,7 @@ async function* parseSseBody(body, options = {}) {
|
|
|
1887
1882
|
} catch {
|
|
1888
1883
|
throw new SseParseError("Invalid SSE JSON");
|
|
1889
1884
|
}
|
|
1890
|
-
if (options.strictJsonObject && (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)))
|
|
1891
|
-
throw new SseParseError("SSE data must be an object");
|
|
1885
|
+
if (options.strictJsonObject && (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))) throw new SseParseError("SSE data must be an object");
|
|
1892
1886
|
const result = { event, data: parsed, ...id === void 0 ? {} : { id }, ...retry === void 0 ? {} : { retry } };
|
|
1893
1887
|
event = "";
|
|
1894
1888
|
id = void 0;
|
|
@@ -1898,25 +1892,18 @@ async function* parseSseBody(body, options = {}) {
|
|
|
1898
1892
|
};
|
|
1899
1893
|
const processLine = (raw) => {
|
|
1900
1894
|
const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
|
|
1901
|
-
if (line === "")
|
|
1902
|
-
|
|
1903
|
-
if (line.startsWith(":"))
|
|
1904
|
-
return void 0;
|
|
1895
|
+
if (line === "") return dispatch();
|
|
1896
|
+
if (line.startsWith(":")) return void 0;
|
|
1905
1897
|
const separator = line.indexOf(":");
|
|
1906
1898
|
const field = separator < 0 ? line : line.slice(0, separator);
|
|
1907
1899
|
let value = separator < 0 ? "" : line.slice(separator + 1);
|
|
1908
|
-
if (value.startsWith(" "))
|
|
1909
|
-
|
|
1910
|
-
if (field === "
|
|
1911
|
-
|
|
1912
|
-
else if (field === "data")
|
|
1913
|
-
data.push(value);
|
|
1914
|
-
else if (field === "id")
|
|
1915
|
-
id = value;
|
|
1900
|
+
if (value.startsWith(" ")) value = value.slice(1);
|
|
1901
|
+
if (field === "event") event = value;
|
|
1902
|
+
else if (field === "data") data.push(value);
|
|
1903
|
+
else if (field === "id") id = value;
|
|
1916
1904
|
else if (field === "retry") {
|
|
1917
1905
|
const parsed = Number(value);
|
|
1918
|
-
if (!Number.isInteger(parsed) || parsed < 0 || !Number.isFinite(parsed))
|
|
1919
|
-
throw new SseParseError("Invalid SSE retry");
|
|
1906
|
+
if (!Number.isInteger(parsed) || parsed < 0 || !Number.isFinite(parsed)) throw new SseParseError("Invalid SSE retry");
|
|
1920
1907
|
retry = parsed;
|
|
1921
1908
|
}
|
|
1922
1909
|
return void 0;
|
|
@@ -1931,23 +1918,19 @@ async function* parseSseBody(body, options = {}) {
|
|
|
1931
1918
|
buffer += decoder.decode(chunk.value, { stream: true });
|
|
1932
1919
|
let index = findLineBreak(buffer);
|
|
1933
1920
|
while (index >= 0) {
|
|
1934
|
-
if (buffer[index] === "\r" && index === buffer.length - 1)
|
|
1935
|
-
break;
|
|
1921
|
+
if (buffer[index] === "\r" && index === buffer.length - 1) break;
|
|
1936
1922
|
const frame2 = processLine(buffer.slice(0, index));
|
|
1937
1923
|
buffer = buffer.slice(index + lineBreakLength(buffer, index));
|
|
1938
|
-
if (frame2)
|
|
1939
|
-
yield frame2;
|
|
1924
|
+
if (frame2) yield frame2;
|
|
1940
1925
|
index = findLineBreak(buffer);
|
|
1941
1926
|
}
|
|
1942
1927
|
}
|
|
1943
1928
|
if (buffer) {
|
|
1944
1929
|
const frame2 = processLine(buffer);
|
|
1945
|
-
if (frame2)
|
|
1946
|
-
yield frame2;
|
|
1930
|
+
if (frame2) yield frame2;
|
|
1947
1931
|
}
|
|
1948
1932
|
const frame = processLine("");
|
|
1949
|
-
if (frame)
|
|
1950
|
-
yield frame;
|
|
1933
|
+
if (frame) yield frame;
|
|
1951
1934
|
} finally {
|
|
1952
1935
|
await reader.cancel().catch(() => void 0);
|
|
1953
1936
|
reader.releaseLock();
|
|
@@ -1956,10 +1939,8 @@ async function* parseSseBody(body, options = {}) {
|
|
|
1956
1939
|
function findLineBreak(value) {
|
|
1957
1940
|
const lf = value.indexOf("\n");
|
|
1958
1941
|
const cr = value.indexOf("\r");
|
|
1959
|
-
if (lf < 0)
|
|
1960
|
-
|
|
1961
|
-
if (cr < 0)
|
|
1962
|
-
return lf;
|
|
1942
|
+
if (lf < 0) return cr;
|
|
1943
|
+
if (cr < 0) return lf;
|
|
1963
1944
|
return Math.min(lf, cr);
|
|
1964
1945
|
}
|
|
1965
1946
|
function lineBreakLength(value, index) {
|
|
@@ -2268,20 +2249,13 @@ var AbstractClient = class {
|
|
|
2268
2249
|
*/
|
|
2269
2250
|
auditLogs: async (params) => {
|
|
2270
2251
|
const searchParams = new URLSearchParams();
|
|
2271
|
-
if (params?.credentialId)
|
|
2272
|
-
|
|
2273
|
-
if (params?.
|
|
2274
|
-
|
|
2275
|
-
if (params?.
|
|
2276
|
-
|
|
2277
|
-
if (params?.
|
|
2278
|
-
searchParams.set("from", params.from);
|
|
2279
|
-
if (params?.to)
|
|
2280
|
-
searchParams.set("to", params.to);
|
|
2281
|
-
if (params?.limit !== void 0)
|
|
2282
|
-
searchParams.set("limit", String(params.limit));
|
|
2283
|
-
if (params?.offset !== void 0)
|
|
2284
|
-
searchParams.set("offset", String(params.offset));
|
|
2252
|
+
if (params?.credentialId) searchParams.set("credentialId", params.credentialId);
|
|
2253
|
+
if (params?.domain) searchParams.set("domain", params.domain);
|
|
2254
|
+
if (params?.status) searchParams.set("status", params.status);
|
|
2255
|
+
if (params?.from) searchParams.set("from", params.from);
|
|
2256
|
+
if (params?.to) searchParams.set("to", params.to);
|
|
2257
|
+
if (params?.limit !== void 0) searchParams.set("limit", String(params.limit));
|
|
2258
|
+
if (params?.offset !== void 0) searchParams.set("offset", String(params.offset));
|
|
2285
2259
|
const qs = searchParams.toString();
|
|
2286
2260
|
const response = await this.makeRequest(`/api/open/audit${qs ? `?${qs}` : ""}`);
|
|
2287
2261
|
return response.data.records;
|
|
@@ -2329,12 +2303,9 @@ var AbstractClient = class {
|
|
|
2329
2303
|
*/
|
|
2330
2304
|
list: async (params) => {
|
|
2331
2305
|
const searchParams = new URLSearchParams();
|
|
2332
|
-
if (params?.tenantId)
|
|
2333
|
-
|
|
2334
|
-
if (params?.
|
|
2335
|
-
searchParams.set("limit", String(params.limit));
|
|
2336
|
-
if (params?.offset !== void 0)
|
|
2337
|
-
searchParams.set("offset", String(params.offset));
|
|
2306
|
+
if (params?.tenantId) searchParams.set("tenantId", params.tenantId);
|
|
2307
|
+
if (params?.limit !== void 0) searchParams.set("limit", String(params.limit));
|
|
2308
|
+
if (params?.offset !== void 0) searchParams.set("offset", String(params.offset));
|
|
2338
2309
|
const qs = searchParams.toString();
|
|
2339
2310
|
const response = await this.makeRequest(`/api/a2a/keys${qs ? `?${qs}` : ""}`);
|
|
2340
2311
|
return response.data;
|
|
@@ -2752,14 +2723,26 @@ var AbstractClient = class {
|
|
|
2752
2723
|
method: "POST",
|
|
2753
2724
|
body: data
|
|
2754
2725
|
});
|
|
2755
|
-
if (!response.data)
|
|
2756
|
-
throw new ApiError("Failed to create entry", 500);
|
|
2726
|
+
if (!response.data) throw new ApiError("Failed to create entry", 500);
|
|
2757
2727
|
return response.data;
|
|
2758
2728
|
},
|
|
2729
|
+
/**
|
|
2730
|
+
* Creates 1-50 entries in one all-or-nothing vector-store write.
|
|
2731
|
+
*
|
|
2732
|
+
* @param data - Batch payload with one or more entries.
|
|
2733
|
+
* @returns The created entries with generated ids.
|
|
2734
|
+
*/
|
|
2735
|
+
createMany: async (data) => {
|
|
2736
|
+
const response = await this.makeRequest(`/api/collections/${collectionName}/entries/batch`, {
|
|
2737
|
+
method: "POST",
|
|
2738
|
+
body: data
|
|
2739
|
+
});
|
|
2740
|
+
if (!response.data?.records) throw new ApiError("Failed to create entries", 500);
|
|
2741
|
+
return response.data.records;
|
|
2742
|
+
},
|
|
2759
2743
|
get: async (id) => {
|
|
2760
2744
|
const response = await this.makeRequest(`/api/collections/${collectionName}/entries/${id}`);
|
|
2761
|
-
if (!response.data)
|
|
2762
|
-
throw new ApiError("Entry not found", 404);
|
|
2745
|
+
if (!response.data) throw new ApiError("Entry not found", 404);
|
|
2763
2746
|
return response.data;
|
|
2764
2747
|
},
|
|
2765
2748
|
update: async (id, data) => {
|
|
@@ -2767,8 +2750,7 @@ var AbstractClient = class {
|
|
|
2767
2750
|
method: "PUT",
|
|
2768
2751
|
body: data
|
|
2769
2752
|
});
|
|
2770
|
-
if (!response.data)
|
|
2771
|
-
throw new ApiError("Failed to update entry", 500);
|
|
2753
|
+
if (!response.data) throw new ApiError("Failed to update entry", 500);
|
|
2772
2754
|
return response.data;
|
|
2773
2755
|
},
|
|
2774
2756
|
delete: async (id) => {
|
|
@@ -2777,6 +2759,22 @@ var AbstractClient = class {
|
|
|
2777
2759
|
{ method: "DELETE" }
|
|
2778
2760
|
);
|
|
2779
2761
|
},
|
|
2762
|
+
/**
|
|
2763
|
+
* Deletes 1-50 entries in one all-or-nothing vector-store call.
|
|
2764
|
+
*
|
|
2765
|
+
* @param entryIds - Entry IDs to delete.
|
|
2766
|
+
* @returns The number of requested entry IDs processed by the delete call.
|
|
2767
|
+
*/
|
|
2768
|
+
deleteMany: async (entryIds) => {
|
|
2769
|
+
const response = await this.makeRequest(`/api/collections/${collectionName}/entries/batch`, {
|
|
2770
|
+
method: "DELETE",
|
|
2771
|
+
body: { entryIds }
|
|
2772
|
+
});
|
|
2773
|
+
if (typeof response.data?.processed !== "number") {
|
|
2774
|
+
throw new ApiError("Failed to delete entries", 500);
|
|
2775
|
+
}
|
|
2776
|
+
return response.data.processed;
|
|
2777
|
+
},
|
|
2780
2778
|
search: async (query, opts) => {
|
|
2781
2779
|
const response = await this.makeRequest(`/api/collections/${collectionName}/search`, {
|
|
2782
2780
|
method: "POST",
|
|
@@ -3080,14 +3078,10 @@ var AbstractClient = class {
|
|
|
3080
3078
|
*/
|
|
3081
3079
|
create: async (threadId, input, options, assistantId) => {
|
|
3082
3080
|
const body = {};
|
|
3083
|
-
if (input !== void 0)
|
|
3084
|
-
|
|
3085
|
-
if (options?.
|
|
3086
|
-
|
|
3087
|
-
if (options?.config !== void 0)
|
|
3088
|
-
body.config = options.config;
|
|
3089
|
-
if (options?.mode !== void 0)
|
|
3090
|
-
body.mode = options.mode;
|
|
3081
|
+
if (input !== void 0) body.input = input;
|
|
3082
|
+
if (options?.command !== void 0) body.command = options.command;
|
|
3083
|
+
if (options?.config !== void 0) body.config = options.config;
|
|
3084
|
+
if (options?.mode !== void 0) body.mode = options.mode;
|
|
3091
3085
|
if (options?.multitaskStrategy !== void 0) {
|
|
3092
3086
|
body.multitask_strategy = options.multitaskStrategy;
|
|
3093
3087
|
}
|
|
@@ -3158,10 +3152,8 @@ var AbstractClient = class {
|
|
|
3158
3152
|
*/
|
|
3159
3153
|
cancel: async (threadId, runId, options, assistantId) => {
|
|
3160
3154
|
const params = new URLSearchParams();
|
|
3161
|
-
if (options?.action !== void 0)
|
|
3162
|
-
|
|
3163
|
-
if (options?.wait !== void 0)
|
|
3164
|
-
params.set("wait", String(options.wait));
|
|
3155
|
+
if (options?.action !== void 0) params.set("action", options.action);
|
|
3156
|
+
if (options?.wait !== void 0) params.set("wait", String(options.wait));
|
|
3165
3157
|
const query = params.toString();
|
|
3166
3158
|
const response = await this.makeRequest(
|
|
3167
3159
|
`/api/assistants/${assistantId ?? this.assistantId}/threads/${threadId}/runs/${runId}/cancel${query ? `?${query}` : ""}`,
|
|
@@ -3269,20 +3261,17 @@ var AbstractClient = class {
|
|
|
3269
3261
|
},
|
|
3270
3262
|
get: async (id) => {
|
|
3271
3263
|
const response = await this.makeRequest(`/api/tools/${id}`);
|
|
3272
|
-
if (!response.data)
|
|
3273
|
-
throw new ApiError("Tool not found", 404);
|
|
3264
|
+
if (!response.data) throw new ApiError("Tool not found", 404);
|
|
3274
3265
|
return response.data;
|
|
3275
3266
|
},
|
|
3276
3267
|
create: async (data) => {
|
|
3277
3268
|
const response = await this.makeRequest("/api/tools", { method: "POST", body: data });
|
|
3278
|
-
if (!response.data)
|
|
3279
|
-
throw new ApiError("Failed to create tool", 500);
|
|
3269
|
+
if (!response.data) throw new ApiError("Failed to create tool", 500);
|
|
3280
3270
|
return response.data;
|
|
3281
3271
|
},
|
|
3282
3272
|
update: async (id, data) => {
|
|
3283
3273
|
const response = await this.makeRequest(`/api/tools/${id}`, { method: "PUT", body: data });
|
|
3284
|
-
if (!response.data)
|
|
3285
|
-
throw new ApiError("Failed to update tool", 500);
|
|
3274
|
+
if (!response.data) throw new ApiError("Failed to update tool", 500);
|
|
3286
3275
|
return response.data;
|
|
3287
3276
|
},
|
|
3288
3277
|
delete: async (id) => {
|
|
@@ -3296,20 +3285,17 @@ var AbstractClient = class {
|
|
|
3296
3285
|
},
|
|
3297
3286
|
get: async (id) => {
|
|
3298
3287
|
const response = await this.makeRequest(`/api/database-configs/${id}`);
|
|
3299
|
-
if (!response.data)
|
|
3300
|
-
throw new ApiError("Database config not found", 404);
|
|
3288
|
+
if (!response.data) throw new ApiError("Database config not found", 404);
|
|
3301
3289
|
return response.data;
|
|
3302
3290
|
},
|
|
3303
3291
|
create: async (data) => {
|
|
3304
3292
|
const response = await this.makeRequest("/api/database-configs", { method: "POST", body: data });
|
|
3305
|
-
if (!response.data)
|
|
3306
|
-
throw new ApiError("Failed to create database config", 500);
|
|
3293
|
+
if (!response.data) throw new ApiError("Failed to create database config", 500);
|
|
3307
3294
|
return response.data;
|
|
3308
3295
|
},
|
|
3309
3296
|
update: async (id, data) => {
|
|
3310
3297
|
const response = await this.makeRequest(`/api/database-configs/${id}`, { method: "PUT", body: data });
|
|
3311
|
-
if (!response.data)
|
|
3312
|
-
throw new ApiError("Failed to update database config", 500);
|
|
3298
|
+
if (!response.data) throw new ApiError("Failed to update database config", 500);
|
|
3313
3299
|
return response.data;
|
|
3314
3300
|
},
|
|
3315
3301
|
delete: async (id) => {
|
|
@@ -3326,20 +3312,17 @@ var AbstractClient = class {
|
|
|
3326
3312
|
},
|
|
3327
3313
|
get: async (id) => {
|
|
3328
3314
|
const response = await this.makeRequest(`/api/model-providers/${encodeURIComponent(id)}`);
|
|
3329
|
-
if (!response.data)
|
|
3330
|
-
throw new ApiError("Model provider not found", 404);
|
|
3315
|
+
if (!response.data) throw new ApiError("Model provider not found", 404);
|
|
3331
3316
|
return response.data;
|
|
3332
3317
|
},
|
|
3333
3318
|
create: async (data) => {
|
|
3334
3319
|
const response = await this.makeRequest("/api/model-providers", { method: "POST", body: data });
|
|
3335
|
-
if (!response.data)
|
|
3336
|
-
throw new ApiError("Failed to create model provider", 500);
|
|
3320
|
+
if (!response.data) throw new ApiError("Failed to create model provider", 500);
|
|
3337
3321
|
return response.data;
|
|
3338
3322
|
},
|
|
3339
3323
|
update: async (id, data) => {
|
|
3340
3324
|
const response = await this.makeRequest(`/api/model-providers/${encodeURIComponent(id)}`, { method: "PUT", body: data });
|
|
3341
|
-
if (!response.data)
|
|
3342
|
-
throw new ApiError("Failed to update model provider", 500);
|
|
3325
|
+
if (!response.data) throw new ApiError("Failed to update model provider", 500);
|
|
3343
3326
|
return response.data;
|
|
3344
3327
|
},
|
|
3345
3328
|
delete: async (id) => {
|
|
@@ -3349,8 +3332,7 @@ var AbstractClient = class {
|
|
|
3349
3332
|
// provider form to validate before saving.
|
|
3350
3333
|
probe: async (data) => {
|
|
3351
3334
|
const response = await this.makeRequest("/api/model-providers/probe", { method: "POST", body: data });
|
|
3352
|
-
if (!response.data)
|
|
3353
|
-
throw new ApiError("Failed to probe model provider", 500);
|
|
3335
|
+
if (!response.data) throw new ApiError("Failed to probe model provider", 500);
|
|
3354
3336
|
return response.data;
|
|
3355
3337
|
},
|
|
3356
3338
|
// Replace this provider's model set with exactly these models, picked
|
|
@@ -3358,22 +3340,19 @@ var AbstractClient = class {
|
|
|
3358
3340
|
// model arrives as `enabled: false` rather than being dropped.
|
|
3359
3341
|
setModels: async (id, models) => {
|
|
3360
3342
|
const response = await this.makeRequest(`/api/model-providers/${encodeURIComponent(id)}/models`, { method: "PUT", body: { models } });
|
|
3361
|
-
if (!response.data)
|
|
3362
|
-
throw new ApiError("Failed to update models", 500);
|
|
3343
|
+
if (!response.data) throw new ApiError("Failed to update models", 500);
|
|
3363
3344
|
return response.data;
|
|
3364
3345
|
},
|
|
3365
3346
|
discover: async (id) => {
|
|
3366
3347
|
const response = await this.makeRequest(`/api/model-providers/${encodeURIComponent(id)}/discover`, { method: "POST", body: {} });
|
|
3367
|
-
if (!response.data)
|
|
3368
|
-
throw new ApiError("Failed to discover models", 500);
|
|
3348
|
+
if (!response.data) throw new ApiError("Failed to discover models", 500);
|
|
3369
3349
|
return response.data;
|
|
3370
3350
|
},
|
|
3371
3351
|
// The model id travels in the body because upstream ids routinely
|
|
3372
3352
|
// contain "/" (e.g. Qwen/Qwen2.5-7B-Instruct).
|
|
3373
3353
|
setModelEnabled: async (id, modelId, enabled) => {
|
|
3374
3354
|
const response = await this.makeRequest(`/api/model-providers/${encodeURIComponent(id)}/models/enabled`, { method: "POST", body: { modelId, enabled } });
|
|
3375
|
-
if (!response.data)
|
|
3376
|
-
throw new ApiError("Failed to update model", 500);
|
|
3355
|
+
if (!response.data) throw new ApiError("Failed to update model", 500);
|
|
3377
3356
|
return response.data;
|
|
3378
3357
|
}
|
|
3379
3358
|
};
|
|
@@ -3390,20 +3369,17 @@ var AbstractClient = class {
|
|
|
3390
3369
|
},
|
|
3391
3370
|
get: async (id) => {
|
|
3392
3371
|
const response = await this.makeRequest(`/api/metrics-configs/${id}`);
|
|
3393
|
-
if (!response.data)
|
|
3394
|
-
throw new ApiError("Metrics config not found", 404);
|
|
3372
|
+
if (!response.data) throw new ApiError("Metrics config not found", 404);
|
|
3395
3373
|
return response.data;
|
|
3396
3374
|
},
|
|
3397
3375
|
create: async (data) => {
|
|
3398
3376
|
const response = await this.makeRequest("/api/metrics-configs", { method: "POST", body: data });
|
|
3399
|
-
if (!response.data)
|
|
3400
|
-
throw new ApiError("Failed to create metrics config", 500);
|
|
3377
|
+
if (!response.data) throw new ApiError("Failed to create metrics config", 500);
|
|
3401
3378
|
return response.data;
|
|
3402
3379
|
},
|
|
3403
3380
|
update: async (id, data) => {
|
|
3404
3381
|
const response = await this.makeRequest(`/api/metrics-configs/${id}`, { method: "PUT", body: data });
|
|
3405
|
-
if (!response.data)
|
|
3406
|
-
throw new ApiError("Failed to update metrics config", 500);
|
|
3382
|
+
if (!response.data) throw new ApiError("Failed to update metrics config", 500);
|
|
3407
3383
|
return response.data;
|
|
3408
3384
|
},
|
|
3409
3385
|
delete: async (id) => {
|
|
@@ -3424,20 +3400,17 @@ var AbstractClient = class {
|
|
|
3424
3400
|
},
|
|
3425
3401
|
get: async (id) => {
|
|
3426
3402
|
const response = await this.makeRequest(`/api/mcp-servers/${id}`);
|
|
3427
|
-
if (!response.data)
|
|
3428
|
-
throw new ApiError("MCP server config not found", 404);
|
|
3403
|
+
if (!response.data) throw new ApiError("MCP server config not found", 404);
|
|
3429
3404
|
return response.data;
|
|
3430
3405
|
},
|
|
3431
3406
|
create: async (data) => {
|
|
3432
3407
|
const response = await this.makeRequest("/api/mcp-servers", { method: "POST", body: data });
|
|
3433
|
-
if (!response.data)
|
|
3434
|
-
throw new ApiError("Failed to create MCP server config", 500);
|
|
3408
|
+
if (!response.data) throw new ApiError("Failed to create MCP server config", 500);
|
|
3435
3409
|
return response.data;
|
|
3436
3410
|
},
|
|
3437
3411
|
update: async (id, data) => {
|
|
3438
3412
|
const response = await this.makeRequest(`/api/mcp-servers/${id}`, { method: "PUT", body: data });
|
|
3439
|
-
if (!response.data)
|
|
3440
|
-
throw new ApiError("Failed to update MCP server config", 500);
|
|
3413
|
+
if (!response.data) throw new ApiError("Failed to update MCP server config", 500);
|
|
3441
3414
|
return response.data;
|
|
3442
3415
|
},
|
|
3443
3416
|
delete: async (id) => {
|
|
@@ -3448,14 +3421,49 @@ var AbstractClient = class {
|
|
|
3448
3421
|
},
|
|
3449
3422
|
connect: async (id) => {
|
|
3450
3423
|
const response = await this.makeRequest(`/api/mcp-servers/${id}/connect`, { method: "POST" });
|
|
3451
|
-
if (!response.data)
|
|
3452
|
-
throw new ApiError("Failed to connect MCP server", 500);
|
|
3424
|
+
if (!response.data) throw new ApiError("Failed to connect MCP server", 500);
|
|
3453
3425
|
return response.data;
|
|
3454
3426
|
},
|
|
3455
3427
|
disconnect: async (id) => {
|
|
3456
3428
|
const response = await this.makeRequest(`/api/mcp-servers/${id}/disconnect`, { method: "POST" });
|
|
3457
|
-
if (!response.data)
|
|
3458
|
-
|
|
3429
|
+
if (!response.data) throw new ApiError("Failed to disconnect MCP server", 500);
|
|
3430
|
+
return response.data;
|
|
3431
|
+
}
|
|
3432
|
+
};
|
|
3433
|
+
this.personalMcpServers = {
|
|
3434
|
+
list: async () => {
|
|
3435
|
+
const response = await this.makeRequest("/api/personal-mcp-servers");
|
|
3436
|
+
return response.data.records;
|
|
3437
|
+
},
|
|
3438
|
+
get: async (keyOrId) => {
|
|
3439
|
+
const response = await this.makeRequest(`/api/personal-mcp-servers/${keyOrId}`);
|
|
3440
|
+
if (!response.data) throw new ApiError("Personal MCP server config not found", 404);
|
|
3441
|
+
return response.data;
|
|
3442
|
+
},
|
|
3443
|
+
create: async (data) => {
|
|
3444
|
+
const response = await this.makeRequest("/api/personal-mcp-servers", { method: "POST", body: data });
|
|
3445
|
+
if (!response.data) throw new ApiError("Failed to create personal MCP server config", 500);
|
|
3446
|
+
return response.data;
|
|
3447
|
+
},
|
|
3448
|
+
update: async (keyOrId, data) => {
|
|
3449
|
+
const response = await this.makeRequest(`/api/personal-mcp-servers/${keyOrId}`, { method: "PUT", body: data });
|
|
3450
|
+
if (!response.data) throw new ApiError("Failed to update personal MCP server config", 500);
|
|
3451
|
+
return response.data;
|
|
3452
|
+
},
|
|
3453
|
+
delete: async (keyOrId) => {
|
|
3454
|
+
await this.makeRequest(`/api/personal-mcp-servers/${keyOrId}`, { method: "DELETE" });
|
|
3455
|
+
},
|
|
3456
|
+
test: async (keyOrId) => {
|
|
3457
|
+
return await this.makeRequest(`/api/personal-mcp-servers/${keyOrId}/test`, { method: "POST" });
|
|
3458
|
+
},
|
|
3459
|
+
connect: async (keyOrId) => {
|
|
3460
|
+
const response = await this.makeRequest(`/api/personal-mcp-servers/${keyOrId}/connect`, { method: "POST" });
|
|
3461
|
+
if (!response.data) throw new ApiError("Failed to connect personal MCP server", 500);
|
|
3462
|
+
return response.data;
|
|
3463
|
+
},
|
|
3464
|
+
disconnect: async (keyOrId) => {
|
|
3465
|
+
const response = await this.makeRequest(`/api/personal-mcp-servers/${keyOrId}/disconnect`, { method: "POST" });
|
|
3466
|
+
if (!response.data) throw new ApiError("Failed to disconnect personal MCP server", 500);
|
|
3459
3467
|
return response.data;
|
|
3460
3468
|
}
|
|
3461
3469
|
};
|
|
@@ -3482,20 +3490,17 @@ var AbstractClient = class {
|
|
|
3482
3490
|
},
|
|
3483
3491
|
get: async (id) => {
|
|
3484
3492
|
const response = await this.makeRequest(`/api/tasks/${id}`);
|
|
3485
|
-
if (!response.data)
|
|
3486
|
-
throw new ApiError("Task not found", 404);
|
|
3493
|
+
if (!response.data) throw new ApiError("Task not found", 404);
|
|
3487
3494
|
return response.data;
|
|
3488
3495
|
},
|
|
3489
3496
|
create: async (data) => {
|
|
3490
3497
|
const response = await this.makeRequest("/api/tasks", { method: "POST", body: data });
|
|
3491
|
-
if (!response.data)
|
|
3492
|
-
throw new ApiError("Failed to create task", 500);
|
|
3498
|
+
if (!response.data) throw new ApiError("Failed to create task", 500);
|
|
3493
3499
|
return response.data;
|
|
3494
3500
|
},
|
|
3495
3501
|
update: async (id, data) => {
|
|
3496
3502
|
const response = await this.makeRequest(`/api/tasks/${id}`, { method: "PUT", body: data });
|
|
3497
|
-
if (!response.data)
|
|
3498
|
-
throw new ApiError("Failed to update task", 500);
|
|
3503
|
+
if (!response.data) throw new ApiError("Failed to update task", 500);
|
|
3499
3504
|
return response.data;
|
|
3500
3505
|
},
|
|
3501
3506
|
delete: async (id) => {
|
|
@@ -3503,25 +3508,20 @@ var AbstractClient = class {
|
|
|
3503
3508
|
},
|
|
3504
3509
|
complete: async (id, data) => {
|
|
3505
3510
|
const response = await this.makeRequest(`/api/tasks/${id}/complete`, { method: "PATCH", body: data });
|
|
3506
|
-
if (!response.data)
|
|
3507
|
-
throw new ApiError("Failed to complete task", 500);
|
|
3511
|
+
if (!response.data) throw new ApiError("Failed to complete task", 500);
|
|
3508
3512
|
return response;
|
|
3509
3513
|
},
|
|
3510
3514
|
command: async (id, input) => {
|
|
3511
3515
|
const response = await this.makeRequest(`/api/tasks/${id}/commands`, { method: "POST", body: input });
|
|
3512
|
-
if (!response.data)
|
|
3513
|
-
throw new ApiError("Failed to run task command", 500);
|
|
3516
|
+
if (!response.data) throw new ApiError("Failed to run task command", 500);
|
|
3514
3517
|
return response;
|
|
3515
3518
|
},
|
|
3516
3519
|
workItems: {
|
|
3517
3520
|
list: async (taskId, params) => {
|
|
3518
3521
|
const searchParams = new URLSearchParams();
|
|
3519
|
-
if (params?.action)
|
|
3520
|
-
|
|
3521
|
-
if (params?.
|
|
3522
|
-
searchParams.set("limit", String(params.limit));
|
|
3523
|
-
if (params?.offset)
|
|
3524
|
-
searchParams.set("offset", String(params.offset));
|
|
3522
|
+
if (params?.action) searchParams.set("action", params.action);
|
|
3523
|
+
if (params?.limit) searchParams.set("limit", String(params.limit));
|
|
3524
|
+
if (params?.offset) searchParams.set("offset", String(params.offset));
|
|
3525
3525
|
const qs = searchParams.toString();
|
|
3526
3526
|
const response = await this.makeRequest(
|
|
3527
3527
|
`/api/tasks/${taskId}/work-items${qs ? `?${qs}` : ""}`
|
|
@@ -3538,20 +3538,17 @@ var AbstractClient = class {
|
|
|
3538
3538
|
},
|
|
3539
3539
|
get: async (id) => {
|
|
3540
3540
|
const response = await this.makeRequest(`/api/menu-items/${id}`);
|
|
3541
|
-
if (!response.data)
|
|
3542
|
-
throw new Error("Menu item not found");
|
|
3541
|
+
if (!response.data) throw new Error("Menu item not found");
|
|
3543
3542
|
return response.data;
|
|
3544
3543
|
},
|
|
3545
3544
|
create: async (data) => {
|
|
3546
3545
|
const response = await this.makeRequest("/api/menu-items", { method: "POST", body: data });
|
|
3547
|
-
if (!response.data)
|
|
3548
|
-
throw new Error("Failed to create menu item");
|
|
3546
|
+
if (!response.data) throw new Error("Failed to create menu item");
|
|
3549
3547
|
return response.data;
|
|
3550
3548
|
},
|
|
3551
3549
|
update: async (id, data) => {
|
|
3552
3550
|
const response = await this.makeRequest(`/api/menu-items/${id}`, { method: "PUT", body: data });
|
|
3553
|
-
if (!response.data)
|
|
3554
|
-
throw new Error("Failed to update menu item");
|
|
3551
|
+
if (!response.data) throw new Error("Failed to update menu item");
|
|
3555
3552
|
return response.data;
|
|
3556
3553
|
},
|
|
3557
3554
|
delete: async (id) => {
|
|
@@ -3681,8 +3678,7 @@ var AbstractClient = class {
|
|
|
3681
3678
|
{ status: response.status, responseBody: errorData }
|
|
3682
3679
|
);
|
|
3683
3680
|
}
|
|
3684
|
-
if (!response.body)
|
|
3685
|
-
throw new Error("Response body is null");
|
|
3681
|
+
if (!response.body) throw new Error("Response body is null");
|
|
3686
3682
|
for await (const frame of parseSseBody(response.body, { strictJsonObject: true })) {
|
|
3687
3683
|
if (frame.event === "error") {
|
|
3688
3684
|
const data = frame.data;
|
|
@@ -3707,10 +3703,8 @@ var AbstractClient = class {
|
|
|
3707
3703
|
}
|
|
3708
3704
|
}
|
|
3709
3705
|
} catch (error) {
|
|
3710
|
-
if (controller.signal.aborted)
|
|
3711
|
-
|
|
3712
|
-
if (error instanceof DOMException && error.name === "AbortError")
|
|
3713
|
-
return;
|
|
3706
|
+
if (controller.signal.aborted) return;
|
|
3707
|
+
if (error instanceof DOMException && error.name === "AbortError") return;
|
|
3714
3708
|
if (error instanceof SseParseError) {
|
|
3715
3709
|
onError?.(Object.assign(new Error(error.message), { code: "INVALID_EVENT" }));
|
|
3716
3710
|
return;
|
|
@@ -3813,10 +3807,8 @@ var AbstractClient = class {
|
|
|
3813
3807
|
*/
|
|
3814
3808
|
async getThreadHistory(threadId, options = {}) {
|
|
3815
3809
|
const params = new URLSearchParams();
|
|
3816
|
-
if (options.limit !== void 0)
|
|
3817
|
-
|
|
3818
|
-
if (options.before !== void 0)
|
|
3819
|
-
params.append("before", options.before);
|
|
3810
|
+
if (options.limit !== void 0) params.append("limit", String(options.limit));
|
|
3811
|
+
if (options.before !== void 0) params.append("before", options.before);
|
|
3820
3812
|
const query = params.toString();
|
|
3821
3813
|
const response = await this.makeRequest(
|
|
3822
3814
|
`/api/assistants/${this.assistantId}/threads/${threadId}/history${query ? `?${query}` : ""}`
|
|
@@ -3991,8 +3983,7 @@ var ResourcesClient = class {
|
|
|
3991
3983
|
headers: { "Content-Type": "application/json", ...this.getHeaders() },
|
|
3992
3984
|
body: JSON.stringify(request)
|
|
3993
3985
|
});
|
|
3994
|
-
if (!res.ok)
|
|
3995
|
-
throw new Error(`Share failed: ${res.status}`);
|
|
3986
|
+
if (!res.ok) throw new Error(`Share failed: ${res.status}`);
|
|
3996
3987
|
return await res.json();
|
|
3997
3988
|
}
|
|
3998
3989
|
async unshare(token) {
|
|
@@ -4000,8 +3991,7 @@ var ResourcesClient = class {
|
|
|
4000
3991
|
method: "DELETE",
|
|
4001
3992
|
headers: this.getHeaders()
|
|
4002
3993
|
});
|
|
4003
|
-
if (!res.ok)
|
|
4004
|
-
throw new Error(`Unshare failed: ${res.status}`);
|
|
3994
|
+
if (!res.ok) throw new Error(`Unshare failed: ${res.status}`);
|
|
4005
3995
|
}
|
|
4006
3996
|
async updateShare(token, patch) {
|
|
4007
3997
|
const res = await fetch(`${this.baseURL}/api/resources/share/${token}`, {
|
|
@@ -4009,15 +3999,13 @@ var ResourcesClient = class {
|
|
|
4009
3999
|
headers: { "Content-Type": "application/json", ...this.getHeaders() },
|
|
4010
4000
|
body: JSON.stringify(patch)
|
|
4011
4001
|
});
|
|
4012
|
-
if (!res.ok)
|
|
4013
|
-
throw new Error(`Update failed: ${res.status}`);
|
|
4002
|
+
if (!res.ok) throw new Error(`Update failed: ${res.status}`);
|
|
4014
4003
|
}
|
|
4015
4004
|
async listShares() {
|
|
4016
4005
|
const res = await fetch(`${this.baseURL}/api/resources/shares`, {
|
|
4017
4006
|
headers: this.getHeaders()
|
|
4018
4007
|
});
|
|
4019
|
-
if (!res.ok)
|
|
4020
|
-
throw new Error(`List failed: ${res.status}`);
|
|
4008
|
+
if (!res.ok) throw new Error(`List failed: ${res.status}`);
|
|
4021
4009
|
return await res.json();
|
|
4022
4010
|
}
|
|
4023
4011
|
};
|
|
@@ -4055,8 +4043,7 @@ async function archiveToBlob(archive) {
|
|
|
4055
4043
|
};
|
|
4056
4044
|
}
|
|
4057
4045
|
function attachmentFilename(contentDisposition) {
|
|
4058
|
-
if (!contentDisposition)
|
|
4059
|
-
return "tenant-export.tar.gz";
|
|
4046
|
+
if (!contentDisposition) return "tenant-export.tar.gz";
|
|
4060
4047
|
const encoded = contentDisposition.match(/filename\*=UTF-8''([^;]+)/i)?.[1];
|
|
4061
4048
|
if (encoded) {
|
|
4062
4049
|
try {
|
|
@@ -4091,8 +4078,7 @@ var ExportImportClient = class {
|
|
|
4091
4078
|
};
|
|
4092
4079
|
if (options.body instanceof FormData) {
|
|
4093
4080
|
for (const name of Object.keys(headers)) {
|
|
4094
|
-
if (name.toLowerCase() === "content-type")
|
|
4095
|
-
delete headers[name];
|
|
4081
|
+
if (name.toLowerCase() === "content-type") delete headers[name];
|
|
4096
4082
|
}
|
|
4097
4083
|
}
|
|
4098
4084
|
const response = await fetch(`${this.baseURL}${url}`, {
|
|
@@ -4226,18 +4212,15 @@ var ProjectRoomClientError = class extends Error {
|
|
|
4226
4212
|
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4227
4213
|
var date = (value, field) => {
|
|
4228
4214
|
const result = value instanceof Date ? new Date(value.getTime()) : new Date(typeof value === "string" || typeof value === "number" ? value : Number.NaN);
|
|
4229
|
-
if (!Number.isFinite(result.getTime()))
|
|
4230
|
-
throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4215
|
+
if (!Number.isFinite(result.getTime())) throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4231
4216
|
return result;
|
|
4232
4217
|
};
|
|
4233
4218
|
var requiredString = (record3, field) => {
|
|
4234
|
-
if (typeof record3[field] !== "string")
|
|
4235
|
-
throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4219
|
+
if (typeof record3[field] !== "string") throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4236
4220
|
return record3[field];
|
|
4237
4221
|
};
|
|
4238
4222
|
var oneOf = (value, values, field) => {
|
|
4239
|
-
if (typeof value !== "string" || !values.includes(value))
|
|
4240
|
-
throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4223
|
+
if (typeof value !== "string" || !values.includes(value)) throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4241
4224
|
return value;
|
|
4242
4225
|
};
|
|
4243
4226
|
var messageSources = ["user", "agent", "task", "routine", "system"];
|
|
@@ -4246,8 +4229,7 @@ var memberStatuses = ["active", "removed"];
|
|
|
4246
4229
|
var botRoles = ["coordinator", "specialist"];
|
|
4247
4230
|
var botStatuses = ["active", "paused", "removed"];
|
|
4248
4231
|
var exactKeys = (row, required, optional = []) => {
|
|
4249
|
-
if (required.some((key) => !Object.prototype.hasOwnProperty.call(row, key)) || Object.keys(row).some((key) => !required.includes(key) && !optional.includes(key)))
|
|
4250
|
-
throw new ProjectRoomClientError("Invalid Project Room response", 500, "INVALID_RESPONSE", false);
|
|
4232
|
+
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);
|
|
4251
4233
|
};
|
|
4252
4234
|
var hydrateAuthor = (value) => {
|
|
4253
4235
|
const row = record(value);
|
|
@@ -4256,29 +4238,24 @@ var hydrateAuthor = (value) => {
|
|
|
4256
4238
|
exactKeys(row, ["type", "userId"]);
|
|
4257
4239
|
return { type, userId: requiredString(row, "userId") };
|
|
4258
4240
|
}
|
|
4259
|
-
if (type === "bot")
|
|
4260
|
-
|
|
4261
|
-
if (Object.keys(row).some((key) => key !== "type"))
|
|
4262
|
-
throw new ProjectRoomClientError("Invalid author", 500, "INVALID_RESPONSE", false);
|
|
4241
|
+
if (type === "bot") return { type, membershipId: requiredString(row, "membershipId") };
|
|
4242
|
+
if (Object.keys(row).some((key) => key !== "type")) throw new ProjectRoomClientError("Invalid author", 500, "INVALID_RESPONSE", false);
|
|
4263
4243
|
return { type };
|
|
4264
4244
|
};
|
|
4265
4245
|
var hydrateMentions = (value) => {
|
|
4266
|
-
if (!Array.isArray(value))
|
|
4267
|
-
throw new ProjectRoomClientError("Invalid mentions", 500, "INVALID_RESPONSE", false);
|
|
4246
|
+
if (!Array.isArray(value)) throw new ProjectRoomClientError("Invalid mentions", 500, "INVALID_RESPONSE", false);
|
|
4268
4247
|
return value.map((entry) => {
|
|
4269
4248
|
const row = record(entry);
|
|
4270
4249
|
const type = oneOf(row.type, ["bot", "team"], "mention.type");
|
|
4271
4250
|
if (type === "team") {
|
|
4272
|
-
if (Object.keys(row).length !== 1)
|
|
4273
|
-
throw new ProjectRoomClientError("Invalid mention", 500, "INVALID_RESPONSE", false);
|
|
4251
|
+
if (Object.keys(row).length !== 1) throw new ProjectRoomClientError("Invalid mention", 500, "INVALID_RESPONSE", false);
|
|
4274
4252
|
return { type };
|
|
4275
4253
|
}
|
|
4276
4254
|
return { type, membershipId: requiredString(row, "membershipId") };
|
|
4277
4255
|
});
|
|
4278
4256
|
};
|
|
4279
4257
|
var record = (value) => {
|
|
4280
|
-
if (!isRecord(value))
|
|
4281
|
-
throw new ProjectRoomClientError("Invalid Project Room response", 500, "INVALID_RESPONSE", false);
|
|
4258
|
+
if (!isRecord(value)) throw new ProjectRoomClientError("Invalid Project Room response", 500, "INVALID_RESPONSE", false);
|
|
4282
4259
|
return value;
|
|
4283
4260
|
};
|
|
4284
4261
|
var hydrateRoom = (value) => {
|
|
@@ -4290,8 +4267,7 @@ var hydrateMessage = (value) => {
|
|
|
4290
4267
|
const row = record(value);
|
|
4291
4268
|
exactKeys(row, ["id", "roomId", "author", "content", "mentions", "source", "createdAt"], ["replyToMessageId", "sourceId"]);
|
|
4292
4269
|
const content = record(row.content);
|
|
4293
|
-
if (oneOf(content.type, ["text"], "content.type") !== "text")
|
|
4294
|
-
throw new ProjectRoomClientError("Invalid content", 500, "INVALID_RESPONSE", false);
|
|
4270
|
+
if (oneOf(content.type, ["text"], "content.type") !== "text") throw new ProjectRoomClientError("Invalid content", 500, "INVALID_RESPONSE", false);
|
|
4295
4271
|
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") };
|
|
4296
4272
|
};
|
|
4297
4273
|
var hydrateMember = (value) => {
|
|
@@ -4306,8 +4282,7 @@ var hydrateBot = (value) => {
|
|
|
4306
4282
|
};
|
|
4307
4283
|
var hydrateDispatch = (value) => {
|
|
4308
4284
|
const row = record(value);
|
|
4309
|
-
if (typeof row.success !== "boolean" || row.membershipId !== void 0 && typeof row.membershipId !== "string" || row.errorCode !== void 0 && typeof row.errorCode !== "string")
|
|
4310
|
-
throw new ProjectRoomClientError("Invalid dispatch response", 500, "INVALID_RESPONSE", false);
|
|
4285
|
+
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);
|
|
4311
4286
|
return { success: row.success, ...row.membershipId === void 0 ? {} : { membershipId: row.membershipId }, ...row.errorCode === void 0 ? {} : { errorCode: row.errorCode } };
|
|
4312
4287
|
};
|
|
4313
4288
|
function hydratePublicMember(value) {
|
|
@@ -4333,23 +4308,19 @@ var ProjectRoomsClient = class {
|
|
|
4333
4308
|
query.set("beforeCreatedAt", iso(options.cursor.createdAt));
|
|
4334
4309
|
query.set("beforeId", options.cursor.id);
|
|
4335
4310
|
}
|
|
4336
|
-
if (options.limit !== void 0)
|
|
4337
|
-
query.set("limit", String(options.limit));
|
|
4311
|
+
if (options.limit !== void 0) query.set("limit", String(options.limit));
|
|
4338
4312
|
const result = await this.request(`/api/projects/${encode(projectId)}/room/messages${query.toString() ? `?${query}` : ""}`);
|
|
4339
|
-
if (!Array.isArray(result))
|
|
4340
|
-
throw new ProjectRoomClientError("Invalid messages response", 500, "INVALID_RESPONSE", false);
|
|
4313
|
+
if (!Array.isArray(result)) throw new ProjectRoomClientError("Invalid messages response", 500, "INVALID_RESPONSE", false);
|
|
4341
4314
|
return result.map(hydrateMessage);
|
|
4342
4315
|
},
|
|
4343
4316
|
send: async (projectId, input) => {
|
|
4344
4317
|
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() } });
|
|
4345
|
-
if (!Array.isArray(result.dispatch) || typeof result.replayed !== "boolean")
|
|
4346
|
-
throw new ProjectRoomClientError("Invalid send response", 500, "INVALID_RESPONSE", false);
|
|
4318
|
+
if (!Array.isArray(result.dispatch) || typeof result.replayed !== "boolean") throw new ProjectRoomClientError("Invalid send response", 500, "INVALID_RESPONSE", false);
|
|
4347
4319
|
return { message: hydrateMessage(result.message), dispatch: result.dispatch.map(hydrateDispatch), replayed: result.replayed };
|
|
4348
4320
|
},
|
|
4349
4321
|
retry: async (projectId, messageId) => {
|
|
4350
4322
|
const result = await this.request(`/api/projects/${encode(projectId)}/room/messages/${encode(messageId)}/retry`, { method: "POST", body: {} });
|
|
4351
|
-
if (!Array.isArray(result))
|
|
4352
|
-
throw new ProjectRoomClientError("Invalid retry response", 500, "INVALID_RESPONSE", false);
|
|
4323
|
+
if (!Array.isArray(result)) throw new ProjectRoomClientError("Invalid retry response", 500, "INVALID_RESPONSE", false);
|
|
4353
4324
|
return result.map(hydrateDispatch);
|
|
4354
4325
|
},
|
|
4355
4326
|
markRead: async (projectId) => {
|
|
@@ -4390,8 +4361,7 @@ var ProjectRoomsClient = class {
|
|
|
4390
4361
|
}
|
|
4391
4362
|
async records(path, hydrate) {
|
|
4392
4363
|
const result = await this.request(path);
|
|
4393
|
-
if (!Array.isArray(result))
|
|
4394
|
-
throw new ProjectRoomClientError("Invalid records response", 500, "INVALID_RESPONSE", false);
|
|
4364
|
+
if (!Array.isArray(result)) throw new ProjectRoomClientError("Invalid records response", 500, "INVALID_RESPONSE", false);
|
|
4395
4365
|
return result.map(hydrate);
|
|
4396
4366
|
}
|
|
4397
4367
|
async request(path, options = {}) {
|
|
@@ -4403,8 +4373,7 @@ var ProjectRoomsClient = class {
|
|
|
4403
4373
|
const error = payload?.error;
|
|
4404
4374
|
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);
|
|
4405
4375
|
}
|
|
4406
|
-
if (!Object.prototype.hasOwnProperty.call(payload, "data"))
|
|
4407
|
-
throw new ProjectRoomClientError("Missing response data", 500, "INVALID_RESPONSE", false);
|
|
4376
|
+
if (!Object.prototype.hasOwnProperty.call(payload, "data")) throw new ProjectRoomClientError("Missing response data", 500, "INVALID_RESPONSE", false);
|
|
4408
4377
|
return payload.data;
|
|
4409
4378
|
}
|
|
4410
4379
|
};
|
|
@@ -4412,19 +4381,16 @@ var ProjectRoomsClient = class {
|
|
|
4412
4381
|
// src/workspace-rooms.ts
|
|
4413
4382
|
var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4414
4383
|
var record2 = (value) => {
|
|
4415
|
-
if (!isRecord2(value))
|
|
4416
|
-
throw new ProjectRoomClientError("Invalid workspace rooms response", 500, "INVALID_RESPONSE", false);
|
|
4384
|
+
if (!isRecord2(value)) throw new ProjectRoomClientError("Invalid workspace rooms response", 500, "INVALID_RESPONSE", false);
|
|
4417
4385
|
return value;
|
|
4418
4386
|
};
|
|
4419
4387
|
var requiredString2 = (row, field) => {
|
|
4420
|
-
if (typeof row[field] !== "string")
|
|
4421
|
-
throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4388
|
+
if (typeof row[field] !== "string") throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4422
4389
|
return row[field];
|
|
4423
4390
|
};
|
|
4424
4391
|
var date2 = (value, field) => {
|
|
4425
4392
|
const result = value instanceof Date ? new Date(value.getTime()) : new Date(typeof value === "string" ? value : Number.NaN);
|
|
4426
|
-
if (!Number.isFinite(result.getTime()))
|
|
4427
|
-
throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4393
|
+
if (!Number.isFinite(result.getTime())) throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
|
|
4428
4394
|
return result;
|
|
4429
4395
|
};
|
|
4430
4396
|
var hydrateProject = (value) => {
|
|
@@ -4444,10 +4410,8 @@ var hydrateProject = (value) => {
|
|
|
4444
4410
|
var hydrateEntry = (value) => {
|
|
4445
4411
|
const row = record2(value);
|
|
4446
4412
|
const names = row.participantNames;
|
|
4447
|
-
if (!Array.isArray(names) || names.some((n) => typeof n !== "string"))
|
|
4448
|
-
|
|
4449
|
-
if (typeof row.participantCount !== "number" || typeof row.unreadCount !== "number")
|
|
4450
|
-
throw new ProjectRoomClientError("Invalid room entry counts", 500, "INVALID_RESPONSE", false);
|
|
4413
|
+
if (!Array.isArray(names) || names.some((n) => typeof n !== "string")) throw new ProjectRoomClientError("Invalid participantNames", 500, "INVALID_RESPONSE", false);
|
|
4414
|
+
if (typeof row.participantCount !== "number" || typeof row.unreadCount !== "number") throw new ProjectRoomClientError("Invalid room entry counts", 500, "INVALID_RESPONSE", false);
|
|
4451
4415
|
return {
|
|
4452
4416
|
project: hydrateProject(row.project),
|
|
4453
4417
|
room: hydrateRoom(row.room),
|
|
@@ -4472,8 +4436,7 @@ var WorkspaceRoomsClient = class {
|
|
|
4472
4436
|
const error = payload?.error;
|
|
4473
4437
|
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);
|
|
4474
4438
|
}
|
|
4475
|
-
if (!payload.data || !Array.isArray(payload.data.rooms))
|
|
4476
|
-
throw new ProjectRoomClientError("Invalid workspace rooms response", 500, "INVALID_RESPONSE", false);
|
|
4439
|
+
if (!payload.data || !Array.isArray(payload.data.rooms)) throw new ProjectRoomClientError("Invalid workspace rooms response", 500, "INVALID_RESPONSE", false);
|
|
4477
4440
|
return payload.data.rooms.map(hydrateEntry);
|
|
4478
4441
|
}
|
|
4479
4442
|
};
|
|
@@ -4481,10 +4444,8 @@ var WorkspaceRoomsClient = class {
|
|
|
4481
4444
|
// src/workspace-members.ts
|
|
4482
4445
|
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4483
4446
|
var hydrateMember2 = (value) => {
|
|
4484
|
-
if (!isRecord3(value))
|
|
4485
|
-
|
|
4486
|
-
if (typeof value.userId !== "string" || typeof value.name !== "string")
|
|
4487
|
-
throw new ProjectRoomClientError("Invalid workspace member", 500, "INVALID_RESPONSE", false);
|
|
4447
|
+
if (!isRecord3(value)) throw new ProjectRoomClientError("Invalid workspace member", 500, "INVALID_RESPONSE", false);
|
|
4448
|
+
if (typeof value.userId !== "string" || typeof value.name !== "string") throw new ProjectRoomClientError("Invalid workspace member", 500, "INVALID_RESPONSE", false);
|
|
4488
4449
|
return {
|
|
4489
4450
|
userId: value.userId,
|
|
4490
4451
|
name: value.name,
|
|
@@ -4508,8 +4469,7 @@ var WorkspaceMembersClient = class {
|
|
|
4508
4469
|
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);
|
|
4509
4470
|
}
|
|
4510
4471
|
const members = payload.data?.members;
|
|
4511
|
-
if (!Array.isArray(members))
|
|
4512
|
-
throw new ProjectRoomClientError("Invalid workspace members response", 500, "INVALID_RESPONSE", false);
|
|
4472
|
+
if (!Array.isArray(members)) throw new ProjectRoomClientError("Invalid workspace members response", 500, "INVALID_RESPONSE", false);
|
|
4513
4473
|
return members.map(hydrateMember2);
|
|
4514
4474
|
}
|
|
4515
4475
|
};
|
|
@@ -4517,76 +4477,61 @@ var WorkspaceMembersClient = class {
|
|
|
4517
4477
|
// src/room-events.ts
|
|
4518
4478
|
var invalidFrame = (message) => new ProjectRoomClientError(message, 200, "INVALID_EVENT", false);
|
|
4519
4479
|
var requiredString3 = (row, field) => {
|
|
4520
|
-
if (typeof row[field] !== "string")
|
|
4521
|
-
throw invalidFrame(`Invalid ${field}`);
|
|
4480
|
+
if (typeof row[field] !== "string") throw invalidFrame(`Invalid ${field}`);
|
|
4522
4481
|
return row[field];
|
|
4523
4482
|
};
|
|
4524
4483
|
var oneOf2 = (value, values, field) => {
|
|
4525
|
-
if (typeof value !== "string" || !values.includes(value))
|
|
4526
|
-
throw invalidFrame(`Invalid ${field}`);
|
|
4484
|
+
if (typeof value !== "string" || !values.includes(value)) throw invalidFrame(`Invalid ${field}`);
|
|
4527
4485
|
return value;
|
|
4528
4486
|
};
|
|
4529
4487
|
var hydrateScope = (value) => {
|
|
4530
|
-
if (!isRecord(value))
|
|
4531
|
-
throw invalidFrame("Invalid scope");
|
|
4488
|
+
if (!isRecord(value)) throw invalidFrame("Invalid scope");
|
|
4532
4489
|
return { tenantId: requiredString3(value, "tenantId"), roomId: requiredString3(value, "roomId"), projectId: requiredString3(value, "projectId") };
|
|
4533
4490
|
};
|
|
4534
4491
|
var hydrateControl = (event, payload) => {
|
|
4535
4492
|
if (event === "ready") {
|
|
4536
|
-
if (typeof payload.epoch !== "string" || payload.headEventId !== null && typeof payload.headEventId !== "string" || Object.keys(payload).some((key) => key !== "epoch" && key !== "headEventId"))
|
|
4537
|
-
throw invalidFrame("Invalid SSE control");
|
|
4493
|
+
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");
|
|
4538
4494
|
return { type: "ready", data: { epoch: payload.epoch, headEventId: payload.headEventId } };
|
|
4539
4495
|
}
|
|
4540
|
-
if (Object.keys(payload).some((key) => key !== "reason"))
|
|
4541
|
-
|
|
4542
|
-
if (event === "resync")
|
|
4543
|
-
return { type: "resync", data: { reason: oneOf2(payload.reason, ["SERVER_RESTART", "CURSOR_EXPIRED", "SLOW_CONSUMER"], "reason") } };
|
|
4496
|
+
if (Object.keys(payload).some((key) => key !== "reason")) throw invalidFrame("Invalid SSE control");
|
|
4497
|
+
if (event === "resync") return { type: "resync", data: { reason: oneOf2(payload.reason, ["SERVER_RESTART", "CURSOR_EXPIRED", "SLOW_CONSUMER"], "reason") } };
|
|
4544
4498
|
return { type: "access.revoked", data: { reason: oneOf2(payload.reason, ["PROJECT_ACCESS_REVOKED", "TOKEN_EXPIRED", "CONNECTION_SUPERSEDED"], "reason") } };
|
|
4545
4499
|
};
|
|
4546
4500
|
var ROOM_SCOPED_TYPES = ["message.created", "roster.changed", "membership.changed", "task.changed"];
|
|
4547
4501
|
function hydrateWorkspaceFrame(raw) {
|
|
4548
4502
|
const payload = isRecord(raw.data) ? raw.data : void 0;
|
|
4549
4503
|
if (raw.event === "ready" || raw.event === "resync" || raw.event === "access.revoked") {
|
|
4550
|
-
if (!payload || Object.prototype.hasOwnProperty.call(payload, "type"))
|
|
4551
|
-
throw invalidFrame("Invalid SSE control");
|
|
4504
|
+
if (!payload || Object.prototype.hasOwnProperty.call(payload, "type")) throw invalidFrame("Invalid SSE control");
|
|
4552
4505
|
return hydrateControl(raw.event, payload);
|
|
4553
4506
|
}
|
|
4554
|
-
if (typeof payload?.type !== "string" || payload.type !== raw.event || typeof payload.id !== "string" || raw.id !== payload.id)
|
|
4555
|
-
throw invalidFrame("Invalid SSE business event");
|
|
4507
|
+
if (typeof payload?.type !== "string" || payload.type !== raw.event || typeof payload.id !== "string" || raw.id !== payload.id) throw invalidFrame("Invalid SSE business event");
|
|
4556
4508
|
const occurredAt = date(payload.occurredAt, "occurredAt");
|
|
4557
4509
|
const scope = payload.scope === void 0 ? void 0 : hydrateScope(payload.scope);
|
|
4558
4510
|
const roomScoped = ROOM_SCOPED_TYPES.includes(payload.type);
|
|
4559
|
-
if (roomScoped && scope === void 0)
|
|
4560
|
-
throw invalidFrame("Invalid SSE business event scope");
|
|
4511
|
+
if (roomScoped && scope === void 0) throw invalidFrame("Invalid SSE business event scope");
|
|
4561
4512
|
const data = payload.data;
|
|
4562
4513
|
if (payload.type === "message.created") {
|
|
4563
|
-
if (!isRecord(data))
|
|
4564
|
-
throw invalidFrame("Invalid SSE business event data");
|
|
4514
|
+
if (!isRecord(data)) throw invalidFrame("Invalid SSE business event data");
|
|
4565
4515
|
return { type: payload.type, id: payload.id, occurredAt, scope, data: { message: hydrateMessage(data.message) } };
|
|
4566
4516
|
}
|
|
4567
4517
|
if (payload.type === "roster.changed") {
|
|
4568
|
-
if (!isRecord(data))
|
|
4569
|
-
throw invalidFrame("Invalid SSE business event data");
|
|
4518
|
+
if (!isRecord(data)) throw invalidFrame("Invalid SSE business event data");
|
|
4570
4519
|
return { type: payload.type, id: payload.id, occurredAt, scope, data: { change: requiredString3(data, "change"), membership: hydratePublicBot(data.membership) } };
|
|
4571
4520
|
}
|
|
4572
4521
|
if (payload.type === "membership.changed") {
|
|
4573
|
-
if (!isRecord(data))
|
|
4574
|
-
throw invalidFrame("Invalid SSE business event data");
|
|
4522
|
+
if (!isRecord(data)) throw invalidFrame("Invalid SSE business event data");
|
|
4575
4523
|
return { type: payload.type, id: payload.id, occurredAt, scope, data: { change: requiredString3(data, "change"), membership: hydratePublicMember(data.membership) } };
|
|
4576
4524
|
}
|
|
4577
4525
|
if (payload.type === "task.changed") {
|
|
4578
|
-
if (!isRecord(data))
|
|
4579
|
-
throw invalidFrame("Invalid SSE business event data");
|
|
4526
|
+
if (!isRecord(data)) throw invalidFrame("Invalid SSE business event data");
|
|
4580
4527
|
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") } };
|
|
4581
4528
|
}
|
|
4582
4529
|
if (payload.type === "read.changed") {
|
|
4583
|
-
if (!isRecord(data))
|
|
4584
|
-
throw invalidFrame("Invalid SSE business event data");
|
|
4530
|
+
if (!isRecord(data)) throw invalidFrame("Invalid SSE business event data");
|
|
4585
4531
|
return { type: payload.type, id: payload.id, occurredAt, data: { projectId: requiredString3(data, "projectId"), roomId: requiredString3(data, "roomId"), lastReadAt: date(data.lastReadAt, "lastReadAt") } };
|
|
4586
4532
|
}
|
|
4587
4533
|
if (payload.type === "membership.affected") {
|
|
4588
|
-
if (!isRecord(data))
|
|
4589
|
-
throw invalidFrame("Invalid SSE business event data");
|
|
4534
|
+
if (!isRecord(data)) throw invalidFrame("Invalid SSE business event data");
|
|
4590
4535
|
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") } };
|
|
4591
4536
|
}
|
|
4592
4537
|
return { type: payload.type, id: payload.id, occurredAt, data: payload.data, ...scope === void 0 ? {} : { scope } };
|
|
@@ -4610,35 +4555,29 @@ var RoomEventsClient = class {
|
|
|
4610
4555
|
const error = payload?.error;
|
|
4611
4556
|
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);
|
|
4612
4557
|
}
|
|
4613
|
-
if (response.headers?.get && response.headers.get("content-type")?.split(";")[0].trim() !== "text/event-stream")
|
|
4614
|
-
|
|
4615
|
-
if (!response.body)
|
|
4616
|
-
throw new ProjectRoomClientError("Workspace room events stream has no body", 500, "INVALID_RESPONSE", false);
|
|
4558
|
+
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);
|
|
4559
|
+
if (!response.body) throw new ProjectRoomClientError("Workspace room events stream has no body", 500, "INVALID_RESPONSE", false);
|
|
4617
4560
|
resolveOpen({ status: 200 });
|
|
4618
4561
|
return response;
|
|
4619
4562
|
}).catch((error) => {
|
|
4620
4563
|
rejectOpen(error);
|
|
4621
4564
|
throw error;
|
|
4622
4565
|
});
|
|
4623
|
-
const stream = async function* () {
|
|
4566
|
+
const stream = (async function* () {
|
|
4624
4567
|
const response = await responsePromise;
|
|
4625
4568
|
const body = response.body;
|
|
4626
|
-
if (!body)
|
|
4627
|
-
throw new ProjectRoomClientError("Workspace room events stream has no body", 500, "INVALID_RESPONSE", false);
|
|
4569
|
+
if (!body) throw new ProjectRoomClientError("Workspace room events stream has no body", 500, "INVALID_RESPONSE", false);
|
|
4628
4570
|
for await (const raw of parseSseBody(body, { strictJsonObject: true })) {
|
|
4629
4571
|
try {
|
|
4630
4572
|
yield { event: hydrateWorkspaceFrame(raw), ...raw.id === void 0 ? {} : { id: raw.id }, ...raw.retry === void 0 ? {} : { retry: raw.retry } };
|
|
4631
4573
|
} catch (error) {
|
|
4632
|
-
if (error instanceof ProjectRoomClientError && error.code === "INVALID_EVENT")
|
|
4633
|
-
|
|
4634
|
-
if (error instanceof
|
|
4635
|
-
throw new ProjectRoomClientError(error.message, 400, "INVALID_EVENT", false);
|
|
4636
|
-
if (error instanceof ProjectRoomClientError)
|
|
4637
|
-
throw new ProjectRoomClientError(error.message, 400, "INVALID_EVENT", false, error.details);
|
|
4574
|
+
if (error instanceof ProjectRoomClientError && error.code === "INVALID_EVENT") throw new ProjectRoomClientError(error.message, 400, "INVALID_EVENT", false, error.details);
|
|
4575
|
+
if (error instanceof SseParseError) throw new ProjectRoomClientError(error.message, 400, "INVALID_EVENT", false);
|
|
4576
|
+
if (error instanceof ProjectRoomClientError) throw new ProjectRoomClientError(error.message, 400, "INVALID_EVENT", false, error.details);
|
|
4638
4577
|
throw new ProjectRoomClientError("Invalid SSE event", 400, "INVALID_EVENT", false);
|
|
4639
4578
|
}
|
|
4640
4579
|
}
|
|
4641
|
-
}();
|
|
4580
|
+
})();
|
|
4642
4581
|
return { opened, [Symbol.asyncIterator]: () => stream };
|
|
4643
4582
|
}
|
|
4644
4583
|
};
|
|
@@ -4659,13 +4598,11 @@ function invalidResponse(message) {
|
|
|
4659
4598
|
return new OidcProviderClientError(message, 500, "INVALID_RESPONSE", false);
|
|
4660
4599
|
}
|
|
4661
4600
|
function requiredString4(row, field) {
|
|
4662
|
-
if (typeof row[field] !== "string")
|
|
4663
|
-
throw invalidResponse(`Invalid ${field}`);
|
|
4601
|
+
if (typeof row[field] !== "string") throw invalidResponse(`Invalid ${field}`);
|
|
4664
4602
|
return row[field];
|
|
4665
4603
|
}
|
|
4666
4604
|
function hydrateSummary(value) {
|
|
4667
|
-
if (!isRecord4(value))
|
|
4668
|
-
throw invalidResponse("Invalid OIDC provider summary");
|
|
4605
|
+
if (!isRecord4(value)) throw invalidResponse("Invalid OIDC provider summary");
|
|
4669
4606
|
const source = value.source;
|
|
4670
4607
|
if (source !== "env" && source !== "store") {
|
|
4671
4608
|
throw invalidResponse("Invalid OIDC provider source");
|
|
@@ -4692,8 +4629,7 @@ function hydrateSummary(value) {
|
|
|
4692
4629
|
};
|
|
4693
4630
|
}
|
|
4694
4631
|
function hydrateTestResult(value) {
|
|
4695
|
-
if (!isRecord4(value))
|
|
4696
|
-
throw invalidResponse("Invalid OIDC test result");
|
|
4632
|
+
if (!isRecord4(value)) throw invalidResponse("Invalid OIDC test result");
|
|
4697
4633
|
const scopesSupported = Array.isArray(value.scopesSupported) ? value.scopesSupported.filter(
|
|
4698
4634
|
(scope) => typeof scope === "string"
|
|
4699
4635
|
) : void 0;
|
|
@@ -4735,8 +4671,7 @@ var OidcProvidersClient = class {
|
|
|
4735
4671
|
}
|
|
4736
4672
|
async list() {
|
|
4737
4673
|
const data = await this.request("/api/oidc-providers");
|
|
4738
|
-
if (!Array.isArray(data))
|
|
4739
|
-
throw invalidResponse("Invalid provider list");
|
|
4674
|
+
if (!Array.isArray(data)) throw invalidResponse("Invalid provider list");
|
|
4740
4675
|
return data.map(hydrateSummary);
|
|
4741
4676
|
}
|
|
4742
4677
|
async create(input) {
|
|
@@ -4811,16 +4746,13 @@ function invalidResponse2(message) {
|
|
|
4811
4746
|
return new PlatformClientError(message, 500, "INVALID_RESPONSE", false);
|
|
4812
4747
|
}
|
|
4813
4748
|
function requiredString5(row, field) {
|
|
4814
|
-
if (typeof row[field] !== "string")
|
|
4815
|
-
throw invalidResponse2(`Invalid ${field}`);
|
|
4749
|
+
if (typeof row[field] !== "string") throw invalidResponse2(`Invalid ${field}`);
|
|
4816
4750
|
return row[field];
|
|
4817
4751
|
}
|
|
4818
4752
|
function optionalNullableString(row, field) {
|
|
4819
4753
|
const value = row[field];
|
|
4820
|
-
if (value === null || value === void 0)
|
|
4821
|
-
|
|
4822
|
-
if (typeof value !== "string")
|
|
4823
|
-
throw invalidResponse2(`Invalid ${field}`);
|
|
4754
|
+
if (value === null || value === void 0) return null;
|
|
4755
|
+
if (typeof value !== "string") throw invalidResponse2(`Invalid ${field}`);
|
|
4824
4756
|
return value;
|
|
4825
4757
|
}
|
|
4826
4758
|
function hydrateSettingsSnapshot(value) {
|
|
@@ -4853,23 +4785,22 @@ var BRANDING_TEXT_KEYS = [
|
|
|
4853
4785
|
"loginSubtitle"
|
|
4854
4786
|
];
|
|
4855
4787
|
function hydrateBranding(value) {
|
|
4856
|
-
if (!isRecord5(value))
|
|
4857
|
-
throw invalidResponse2("Invalid branding");
|
|
4788
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid branding");
|
|
4858
4789
|
const branding = {};
|
|
4859
4790
|
for (const key of BRANDING_TEXT_KEYS) {
|
|
4860
4791
|
const field = value[key];
|
|
4861
|
-
if (field === void 0)
|
|
4862
|
-
continue;
|
|
4792
|
+
if (field === void 0) continue;
|
|
4863
4793
|
if (typeof field !== "string") {
|
|
4864
4794
|
throw invalidResponse2(`Invalid branding.${key}`);
|
|
4865
4795
|
}
|
|
4866
4796
|
branding[key] = field;
|
|
4867
4797
|
}
|
|
4798
|
+
const customCss = optionalString(value, "customCss");
|
|
4799
|
+
if (customCss !== void 0) branding.customCss = customCss;
|
|
4868
4800
|
return branding;
|
|
4869
4801
|
}
|
|
4870
4802
|
function hydrateBrandingDomain(value) {
|
|
4871
|
-
if (!isRecord5(value))
|
|
4872
|
-
throw invalidResponse2("Invalid branding domain");
|
|
4803
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid branding domain");
|
|
4873
4804
|
const domain = { host: requiredString5(value, "host") };
|
|
4874
4805
|
if (value.status !== void 0) {
|
|
4875
4806
|
if (value.status !== "active" && value.status !== "pending") {
|
|
@@ -4891,8 +4822,7 @@ function hydrateBrandingDomain(value) {
|
|
|
4891
4822
|
return domain;
|
|
4892
4823
|
}
|
|
4893
4824
|
function hydrateBrandingSettings(value) {
|
|
4894
|
-
if (!isRecord5(value))
|
|
4895
|
-
throw invalidResponse2("Invalid branding settings");
|
|
4825
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid branding settings");
|
|
4896
4826
|
const settings = {};
|
|
4897
4827
|
if (value.default !== void 0) {
|
|
4898
4828
|
settings.default = hydrateBranding(value.default);
|
|
@@ -4941,8 +4871,7 @@ function hydrateTenantRole(value) {
|
|
|
4941
4871
|
throw invalidResponse2("Invalid tenant role");
|
|
4942
4872
|
}
|
|
4943
4873
|
function hydrateStatus(value) {
|
|
4944
|
-
if (value === null || value === void 0)
|
|
4945
|
-
return null;
|
|
4874
|
+
if (value === null || value === void 0) return null;
|
|
4946
4875
|
if (value === "active" || value === "pending" || value === "suspended") {
|
|
4947
4876
|
return value;
|
|
4948
4877
|
}
|
|
@@ -4950,15 +4879,12 @@ function hydrateStatus(value) {
|
|
|
4950
4879
|
}
|
|
4951
4880
|
function optionalString(row, field) {
|
|
4952
4881
|
const value = row[field];
|
|
4953
|
-
if (value === null || value === void 0)
|
|
4954
|
-
|
|
4955
|
-
if (typeof value !== "string")
|
|
4956
|
-
throw invalidResponse2(`Invalid ${field}`);
|
|
4882
|
+
if (value === null || value === void 0) return void 0;
|
|
4883
|
+
if (typeof value !== "string") throw invalidResponse2(`Invalid ${field}`);
|
|
4957
4884
|
return value;
|
|
4958
4885
|
}
|
|
4959
4886
|
function hydrateInvitation(value) {
|
|
4960
|
-
if (!isRecord5(value))
|
|
4961
|
-
throw invalidResponse2("Invalid invitation");
|
|
4887
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid invitation");
|
|
4962
4888
|
const invitedBy = optionalString(value, "invitedBy");
|
|
4963
4889
|
const expiresAt = optionalString(value, "expiresAt");
|
|
4964
4890
|
const consumedAt = optionalString(value, "consumedAt");
|
|
@@ -4972,8 +4898,7 @@ function hydrateInvitation(value) {
|
|
|
4972
4898
|
};
|
|
4973
4899
|
}
|
|
4974
4900
|
function hydrateMember3(value) {
|
|
4975
|
-
if (!isRecord5(value))
|
|
4976
|
-
throw invalidResponse2("Invalid platform member");
|
|
4901
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid platform member");
|
|
4977
4902
|
return {
|
|
4978
4903
|
id: requiredString5(value, "id"),
|
|
4979
4904
|
email: optionalNullableString(value, "email"),
|
|
@@ -4985,8 +4910,7 @@ function hydrateMember3(value) {
|
|
|
4985
4910
|
};
|
|
4986
4911
|
}
|
|
4987
4912
|
function hydrateTenantMember(value) {
|
|
4988
|
-
if (!isRecord5(value))
|
|
4989
|
-
throw invalidResponse2("Invalid tenant member");
|
|
4913
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid tenant member");
|
|
4990
4914
|
return {
|
|
4991
4915
|
userId: requiredString5(value, "userId"),
|
|
4992
4916
|
tenantId: requiredString5(value, "tenantId"),
|
|
@@ -5004,8 +4928,7 @@ function hydrateOidcIdentityClaimStatus(value) {
|
|
|
5004
4928
|
throw invalidResponse2("Invalid SSO claim status");
|
|
5005
4929
|
}
|
|
5006
4930
|
function hydrateOidcIdentityClaim(value) {
|
|
5007
|
-
if (!isRecord5(value))
|
|
5008
|
-
throw invalidResponse2("Invalid SSO claim");
|
|
4931
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid SSO claim");
|
|
5009
4932
|
const name = optionalString(value, "name");
|
|
5010
4933
|
const picture = optionalString(value, "picture");
|
|
5011
4934
|
const reviewedBy = optionalString(value, "reviewedBy");
|
|
@@ -5020,8 +4943,7 @@ function hydrateOidcIdentityClaim(value) {
|
|
|
5020
4943
|
const existing = value.existingUser;
|
|
5021
4944
|
let existingUser;
|
|
5022
4945
|
if (existing !== void 0 && existing !== null) {
|
|
5023
|
-
if (!isRecord5(existing))
|
|
5024
|
-
throw invalidResponse2("Invalid existing user");
|
|
4946
|
+
if (!isRecord5(existing)) throw invalidResponse2("Invalid existing user");
|
|
5025
4947
|
const platformRole = existing.role !== void 0 ? hydratePlatformRole(existing.role) : existing.platformRole !== void 0 ? hydratePlatformRole(existing.platformRole) : void 0;
|
|
5026
4948
|
existingUser = {
|
|
5027
4949
|
id: requiredString5(existing, "id"),
|
|
@@ -5063,15 +4985,12 @@ function hydrateTenantStatus(value) {
|
|
|
5063
4985
|
}
|
|
5064
4986
|
function optionalRecord(row, field) {
|
|
5065
4987
|
const value = row[field];
|
|
5066
|
-
if (value === void 0 || value === null)
|
|
5067
|
-
|
|
5068
|
-
if (!isRecord5(value))
|
|
5069
|
-
throw invalidResponse2(`Invalid ${field}`);
|
|
4988
|
+
if (value === void 0 || value === null) return void 0;
|
|
4989
|
+
if (!isRecord5(value)) throw invalidResponse2(`Invalid ${field}`);
|
|
5070
4990
|
return value;
|
|
5071
4991
|
}
|
|
5072
4992
|
function hydrateInviteLink(value) {
|
|
5073
|
-
if (!isRecord5(value))
|
|
5074
|
-
throw invalidResponse2("Invalid invite link");
|
|
4993
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid invite link");
|
|
5075
4994
|
const scope = value.scope;
|
|
5076
4995
|
if (scope !== "platform" && scope !== "tenant") {
|
|
5077
4996
|
throw invalidResponse2("Invalid invite scope");
|
|
@@ -5097,8 +5016,7 @@ function hydrateInviteLink(value) {
|
|
|
5097
5016
|
};
|
|
5098
5017
|
}
|
|
5099
5018
|
function hydrateTenant(value) {
|
|
5100
|
-
if (!isRecord5(value))
|
|
5101
|
-
throw invalidResponse2("Invalid tenant");
|
|
5019
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid tenant");
|
|
5102
5020
|
const metadata = optionalRecord(value, "metadata");
|
|
5103
5021
|
return {
|
|
5104
5022
|
id: requiredString5(value, "id"),
|
|
@@ -5111,8 +5029,7 @@ function hydrateTenant(value) {
|
|
|
5111
5029
|
};
|
|
5112
5030
|
}
|
|
5113
5031
|
function hydrateUser(value) {
|
|
5114
|
-
if (!isRecord5(value))
|
|
5115
|
-
throw invalidResponse2("Invalid user");
|
|
5032
|
+
if (!isRecord5(value)) throw invalidResponse2("Invalid user");
|
|
5116
5033
|
const status = value.status;
|
|
5117
5034
|
if (status !== "active" && status !== "pending" && status !== "suspended") {
|
|
5118
5035
|
throw invalidResponse2("Invalid user status");
|
|
@@ -5128,6 +5045,135 @@ function hydrateUser(value) {
|
|
|
5128
5045
|
...typeof value.updatedAt === "string" ? { updatedAt: value.updatedAt } : {}
|
|
5129
5046
|
};
|
|
5130
5047
|
}
|
|
5048
|
+
function hydrateAuditInitiator(value) {
|
|
5049
|
+
if (!isRecord5(value) || typeof value.type !== "string") {
|
|
5050
|
+
throw invalidResponse2("Invalid platform audit initiator");
|
|
5051
|
+
}
|
|
5052
|
+
if (value.type === "human") {
|
|
5053
|
+
if (typeof value.userId !== "string" || value.role !== "owner" && value.role !== "admin" && value.role !== "auditor") {
|
|
5054
|
+
throw invalidResponse2("Invalid platform audit human initiator");
|
|
5055
|
+
}
|
|
5056
|
+
return { type: "human", userId: value.userId, role: value.role };
|
|
5057
|
+
}
|
|
5058
|
+
if (value.type === "bootstrap") {
|
|
5059
|
+
return { type: "bootstrap" };
|
|
5060
|
+
}
|
|
5061
|
+
if (value.type === "system") {
|
|
5062
|
+
if (typeof value.component !== "string") {
|
|
5063
|
+
throw invalidResponse2("Invalid platform audit system initiator");
|
|
5064
|
+
}
|
|
5065
|
+
return { type: "system", component: value.component };
|
|
5066
|
+
}
|
|
5067
|
+
throw invalidResponse2("Invalid platform audit initiator");
|
|
5068
|
+
}
|
|
5069
|
+
function hydrateAuditExecutor(value) {
|
|
5070
|
+
if (!isRecord5(value) || typeof value.type !== "string") {
|
|
5071
|
+
throw invalidResponse2("Invalid platform audit executor");
|
|
5072
|
+
}
|
|
5073
|
+
if (value.type === "admin_center") {
|
|
5074
|
+
if (typeof value.route !== "string") {
|
|
5075
|
+
throw invalidResponse2("Invalid platform audit admin center executor");
|
|
5076
|
+
}
|
|
5077
|
+
return { type: "admin_center", route: value.route };
|
|
5078
|
+
}
|
|
5079
|
+
if (value.type === "ops_agent") {
|
|
5080
|
+
if (value.agentId !== "platform-ops" || typeof value.threadId !== "string" || typeof value.runId !== "string" || typeof value.toolName !== "string") {
|
|
5081
|
+
throw invalidResponse2("Invalid platform audit ops agent executor");
|
|
5082
|
+
}
|
|
5083
|
+
return {
|
|
5084
|
+
type: "ops_agent",
|
|
5085
|
+
agentId: "platform-ops",
|
|
5086
|
+
threadId: value.threadId,
|
|
5087
|
+
runId: value.runId,
|
|
5088
|
+
toolName: value.toolName
|
|
5089
|
+
};
|
|
5090
|
+
}
|
|
5091
|
+
if (value.type === "bootstrap") {
|
|
5092
|
+
return { type: "bootstrap" };
|
|
5093
|
+
}
|
|
5094
|
+
if (value.type === "system") {
|
|
5095
|
+
if (typeof value.component !== "string") {
|
|
5096
|
+
throw invalidResponse2("Invalid platform audit system executor");
|
|
5097
|
+
}
|
|
5098
|
+
return { type: "system", component: value.component };
|
|
5099
|
+
}
|
|
5100
|
+
throw invalidResponse2("Invalid platform audit executor");
|
|
5101
|
+
}
|
|
5102
|
+
function hydrateAuditSource(value) {
|
|
5103
|
+
if (value === "admin_center" || value === "ops_agent" || value === "bootstrap" || value === "system") {
|
|
5104
|
+
return value;
|
|
5105
|
+
}
|
|
5106
|
+
throw invalidResponse2("Invalid platform audit source");
|
|
5107
|
+
}
|
|
5108
|
+
function hydrateAuditAction(value) {
|
|
5109
|
+
if (value === "write" || value === "playbook") return value;
|
|
5110
|
+
throw invalidResponse2("Invalid platform audit action");
|
|
5111
|
+
}
|
|
5112
|
+
function hydrateAuditStatus(value) {
|
|
5113
|
+
if (value === "ok" || value === "error" || value === "cancelled") {
|
|
5114
|
+
return value;
|
|
5115
|
+
}
|
|
5116
|
+
throw invalidResponse2("Invalid platform audit status");
|
|
5117
|
+
}
|
|
5118
|
+
function hydratePlatformAudit(value) {
|
|
5119
|
+
if (!isRecord5(value) || typeof value.id !== "string") {
|
|
5120
|
+
throw invalidResponse2("Invalid platform audit record");
|
|
5121
|
+
}
|
|
5122
|
+
const initiator = hydrateAuditInitiator(value.initiator);
|
|
5123
|
+
const executor = hydrateAuditExecutor(value.executor);
|
|
5124
|
+
const source = hydrateAuditSource(value.source);
|
|
5125
|
+
const action = hydrateAuditAction(value.action);
|
|
5126
|
+
const status = hydrateAuditStatus(value.status);
|
|
5127
|
+
const createdAt = new Date(requiredString5(value, "createdAt"));
|
|
5128
|
+
if (Number.isNaN(createdAt.getTime())) {
|
|
5129
|
+
throw invalidResponse2("Invalid platform audit timestamp");
|
|
5130
|
+
}
|
|
5131
|
+
if (!isRecord5(value.summary)) {
|
|
5132
|
+
throw invalidResponse2("Invalid platform audit summary");
|
|
5133
|
+
}
|
|
5134
|
+
if (typeof value.durationMs !== "number" || !Number.isFinite(value.durationMs)) {
|
|
5135
|
+
throw invalidResponse2("Invalid platform audit duration");
|
|
5136
|
+
}
|
|
5137
|
+
const tenantId = optionalString(value, "tenantId");
|
|
5138
|
+
const before = optionalRecord(value, "before");
|
|
5139
|
+
const after = optionalRecord(value, "after");
|
|
5140
|
+
const errorCode = optionalString(value, "errorCode");
|
|
5141
|
+
return {
|
|
5142
|
+
id: value.id,
|
|
5143
|
+
initiator,
|
|
5144
|
+
source,
|
|
5145
|
+
executor,
|
|
5146
|
+
...tenantId !== void 0 ? { tenantId } : {},
|
|
5147
|
+
action,
|
|
5148
|
+
status,
|
|
5149
|
+
summary: value.summary,
|
|
5150
|
+
...before !== void 0 ? { before } : {},
|
|
5151
|
+
...after !== void 0 ? { after } : {},
|
|
5152
|
+
...errorCode !== void 0 ? { errorCode } : {},
|
|
5153
|
+
durationMs: value.durationMs,
|
|
5154
|
+
createdAt
|
|
5155
|
+
};
|
|
5156
|
+
}
|
|
5157
|
+
function requireRecordValue(value, message) {
|
|
5158
|
+
if (!isRecord5(value)) throw invalidResponse2(message);
|
|
5159
|
+
return value;
|
|
5160
|
+
}
|
|
5161
|
+
function hydrateModelCatalog(value) {
|
|
5162
|
+
if (!isRecord5(value) || !Array.isArray(value.providers) || !Array.isArray(value.models)) {
|
|
5163
|
+
throw invalidResponse2("Invalid platform model catalog");
|
|
5164
|
+
}
|
|
5165
|
+
return value;
|
|
5166
|
+
}
|
|
5167
|
+
function hydrateOpsConfig(value) {
|
|
5168
|
+
if (!isRecord5(value) || typeof value.enabled !== "boolean" || typeof value.modelConfigured !== "boolean") {
|
|
5169
|
+
throw invalidResponse2("Invalid platform ops config");
|
|
5170
|
+
}
|
|
5171
|
+
return {
|
|
5172
|
+
enabled: value.enabled,
|
|
5173
|
+
modelKey: requiredString5(value, "modelKey"),
|
|
5174
|
+
modelConfigured: value.modelConfigured
|
|
5175
|
+
};
|
|
5176
|
+
}
|
|
5131
5177
|
function errorFromEnvelope2(payload, response) {
|
|
5132
5178
|
const raw = payload?.error;
|
|
5133
5179
|
if (typeof raw === "string") {
|
|
@@ -5154,13 +5200,113 @@ var PlatformClient = class {
|
|
|
5154
5200
|
constructor(baseURL, getHeaders) {
|
|
5155
5201
|
this.baseURL = baseURL;
|
|
5156
5202
|
this.getHeaders = getHeaders;
|
|
5203
|
+
const providerPath = (providerId) => `/api/platform/model-providers/${encodeURIComponent(providerId)}`;
|
|
5204
|
+
this.ops = {
|
|
5205
|
+
getConfig: async () => {
|
|
5206
|
+
const data = await this.request("/api/platform/ops/config");
|
|
5207
|
+
return hydrateOpsConfig(data);
|
|
5208
|
+
}
|
|
5209
|
+
};
|
|
5210
|
+
this.modelProviders = {
|
|
5211
|
+
list: async () => {
|
|
5212
|
+
const data = await this.request("/api/platform/model-providers");
|
|
5213
|
+
if (!isRecord5(data) || !Array.isArray(data.records)) {
|
|
5214
|
+
throw invalidResponse2("Invalid platform model provider list");
|
|
5215
|
+
}
|
|
5216
|
+
return data.records;
|
|
5217
|
+
},
|
|
5218
|
+
get: async (providerId) => {
|
|
5219
|
+
const data = await this.request(providerPath(providerId));
|
|
5220
|
+
return requireRecordValue(
|
|
5221
|
+
data,
|
|
5222
|
+
"Invalid platform model provider"
|
|
5223
|
+
);
|
|
5224
|
+
},
|
|
5225
|
+
create: async (input) => {
|
|
5226
|
+
const data = await this.request("/api/platform/model-providers", {
|
|
5227
|
+
method: "POST",
|
|
5228
|
+
body: JSON.stringify(input)
|
|
5229
|
+
});
|
|
5230
|
+
return requireRecordValue(
|
|
5231
|
+
data,
|
|
5232
|
+
"Invalid platform model provider"
|
|
5233
|
+
);
|
|
5234
|
+
},
|
|
5235
|
+
update: async (providerId, input) => {
|
|
5236
|
+
const data = await this.request(providerPath(providerId), {
|
|
5237
|
+
method: "PUT",
|
|
5238
|
+
body: JSON.stringify(input)
|
|
5239
|
+
});
|
|
5240
|
+
return requireRecordValue(
|
|
5241
|
+
data,
|
|
5242
|
+
"Invalid platform model provider"
|
|
5243
|
+
);
|
|
5244
|
+
},
|
|
5245
|
+
delete: async (providerId) => {
|
|
5246
|
+
await this.request(providerPath(providerId), { method: "DELETE" });
|
|
5247
|
+
},
|
|
5248
|
+
probe: async (input) => {
|
|
5249
|
+
const data = await this.request(
|
|
5250
|
+
"/api/platform/model-providers/probe",
|
|
5251
|
+
{ method: "POST", body: JSON.stringify(input) }
|
|
5252
|
+
);
|
|
5253
|
+
return requireRecordValue(
|
|
5254
|
+
data,
|
|
5255
|
+
"Invalid platform model provider probe"
|
|
5256
|
+
);
|
|
5257
|
+
},
|
|
5258
|
+
setModels: async (providerId, models) => {
|
|
5259
|
+
const data = await this.request(
|
|
5260
|
+
`${providerPath(providerId)}/models`,
|
|
5261
|
+
{ method: "PUT", body: JSON.stringify({ models }) }
|
|
5262
|
+
);
|
|
5263
|
+
return requireRecordValue(
|
|
5264
|
+
data,
|
|
5265
|
+
"Invalid platform model provider"
|
|
5266
|
+
);
|
|
5267
|
+
},
|
|
5268
|
+
discover: async (providerId) => {
|
|
5269
|
+
const data = await this.request(
|
|
5270
|
+
`${providerPath(providerId)}/discover`,
|
|
5271
|
+
{ method: "POST", body: JSON.stringify({}) }
|
|
5272
|
+
);
|
|
5273
|
+
return requireRecordValue(
|
|
5274
|
+
data,
|
|
5275
|
+
"Invalid platform model discovery result"
|
|
5276
|
+
);
|
|
5277
|
+
},
|
|
5278
|
+
setModelEnabled: async (providerId, modelId, enabled) => {
|
|
5279
|
+
const data = await this.request(
|
|
5280
|
+
`${providerPath(providerId)}/models/enabled`,
|
|
5281
|
+
{ method: "POST", body: JSON.stringify({ modelId, enabled }) }
|
|
5282
|
+
);
|
|
5283
|
+
return requireRecordValue(
|
|
5284
|
+
data,
|
|
5285
|
+
"Invalid platform model provider"
|
|
5286
|
+
);
|
|
5287
|
+
}
|
|
5288
|
+
};
|
|
5289
|
+
}
|
|
5290
|
+
/**
|
|
5291
|
+
* Reads the platform-owned model catalog (providers plus visible models).
|
|
5292
|
+
*
|
|
5293
|
+
* This is the platform-scoped counterpart of `client.tenantModels.list()`.
|
|
5294
|
+
*/
|
|
5295
|
+
async modelCatalog() {
|
|
5296
|
+
const data = await this.request("/api/platform/model-catalog");
|
|
5297
|
+
return hydrateModelCatalog(data);
|
|
5298
|
+
}
|
|
5299
|
+
async rateLimits() {
|
|
5300
|
+
const data = await this.request("/api/platform/rate-limits");
|
|
5301
|
+
if (!isRecord5(data) || !Array.isArray(data.policies)) {
|
|
5302
|
+
throw invalidResponse2("Invalid platform rate-limit view");
|
|
5303
|
+
}
|
|
5304
|
+
return data;
|
|
5157
5305
|
}
|
|
5158
5306
|
async me() {
|
|
5159
5307
|
const data = await this.request("/api/platform/me");
|
|
5160
|
-
if (!isRecord5(data))
|
|
5161
|
-
|
|
5162
|
-
if (data.role === null || data.role === void 0)
|
|
5163
|
-
return null;
|
|
5308
|
+
if (!isRecord5(data)) throw invalidResponse2("Invalid platform identity");
|
|
5309
|
+
if (data.role === null || data.role === void 0) return null;
|
|
5164
5310
|
return hydratePlatformRole(data.role);
|
|
5165
5311
|
}
|
|
5166
5312
|
/**
|
|
@@ -5211,6 +5357,39 @@ var PlatformClient = class {
|
|
|
5211
5357
|
const data = await this.request("/api/platform/environment");
|
|
5212
5358
|
return hydrateEnvironment(data);
|
|
5213
5359
|
}
|
|
5360
|
+
/**
|
|
5361
|
+
* Reads platform audit records, newest first.
|
|
5362
|
+
*
|
|
5363
|
+
* @param query Optional filters and pagination. Undefined values are omitted
|
|
5364
|
+
* from the request.
|
|
5365
|
+
* @returns Hydrated records with `createdAt` as a `Date`.
|
|
5366
|
+
*/
|
|
5367
|
+
async listAudit(query = {}) {
|
|
5368
|
+
const search = new URLSearchParams();
|
|
5369
|
+
for (const [key, value] of Object.entries(query)) {
|
|
5370
|
+
if (value !== void 0) search.set(key, String(value));
|
|
5371
|
+
}
|
|
5372
|
+
const suffix = search.toString();
|
|
5373
|
+
const data = await this.request(
|
|
5374
|
+
`/api/platform/audit${suffix ? `?${suffix}` : ""}`
|
|
5375
|
+
);
|
|
5376
|
+
if (!Array.isArray(data)) {
|
|
5377
|
+
throw invalidResponse2("Invalid platform audit list");
|
|
5378
|
+
}
|
|
5379
|
+
return data.map(hydratePlatformAudit);
|
|
5380
|
+
}
|
|
5381
|
+
/**
|
|
5382
|
+
* Reads a single platform audit record by id.
|
|
5383
|
+
*
|
|
5384
|
+
* @param auditId Audit record id.
|
|
5385
|
+
* @returns The hydrated record with `createdAt` as a `Date`.
|
|
5386
|
+
*/
|
|
5387
|
+
async getAudit(auditId) {
|
|
5388
|
+
const data = await this.request(
|
|
5389
|
+
`/api/platform/audit/${encodeURIComponent(auditId)}`
|
|
5390
|
+
);
|
|
5391
|
+
return hydratePlatformAudit(data);
|
|
5392
|
+
}
|
|
5214
5393
|
/**
|
|
5215
5394
|
* Resolves the public branding for the current gateway host.
|
|
5216
5395
|
*
|
|
@@ -5241,8 +5420,7 @@ var PlatformClient = class {
|
|
|
5241
5420
|
}
|
|
5242
5421
|
async listTenants() {
|
|
5243
5422
|
const data = await this.request("/api/tenants");
|
|
5244
|
-
if (!Array.isArray(data))
|
|
5245
|
-
throw invalidResponse2("Invalid tenant list");
|
|
5423
|
+
if (!Array.isArray(data)) throw invalidResponse2("Invalid tenant list");
|
|
5246
5424
|
return data.map(hydrateTenant);
|
|
5247
5425
|
}
|
|
5248
5426
|
async createTenant(input) {
|
|
@@ -5267,8 +5445,7 @@ var PlatformClient = class {
|
|
|
5267
5445
|
}
|
|
5268
5446
|
async listUsers() {
|
|
5269
5447
|
const data = await this.request("/api/users");
|
|
5270
|
-
if (!Array.isArray(data))
|
|
5271
|
-
throw invalidResponse2("Invalid user list");
|
|
5448
|
+
if (!Array.isArray(data)) throw invalidResponse2("Invalid user list");
|
|
5272
5449
|
return data.map(hydrateUser);
|
|
5273
5450
|
}
|
|
5274
5451
|
async createUser(input) {
|
|
@@ -5292,8 +5469,7 @@ var PlatformClient = class {
|
|
|
5292
5469
|
}
|
|
5293
5470
|
async listMembers() {
|
|
5294
5471
|
const data = await this.request("/api/platform/members");
|
|
5295
|
-
if (!Array.isArray(data))
|
|
5296
|
-
throw invalidResponse2("Invalid member list");
|
|
5472
|
+
if (!Array.isArray(data)) throw invalidResponse2("Invalid member list");
|
|
5297
5473
|
return data.map(hydrateMember3);
|
|
5298
5474
|
}
|
|
5299
5475
|
async grantMember(input) {
|
|
@@ -5301,8 +5477,7 @@ var PlatformClient = class {
|
|
|
5301
5477
|
method: "POST",
|
|
5302
5478
|
body: JSON.stringify(input)
|
|
5303
5479
|
});
|
|
5304
|
-
if (!isRecord5(data))
|
|
5305
|
-
throw invalidResponse2("Invalid platform grant");
|
|
5480
|
+
if (!isRecord5(data)) throw invalidResponse2("Invalid platform grant");
|
|
5306
5481
|
const member = data.member !== void 0 ? hydrateMember3(data.member) : void 0;
|
|
5307
5482
|
const invitation = data.invitation !== void 0 ? hydrateInvitation(data.invitation) : void 0;
|
|
5308
5483
|
if (!member && !invitation) {
|
|
@@ -5315,8 +5490,7 @@ var PlatformClient = class {
|
|
|
5315
5490
|
}
|
|
5316
5491
|
async listInvitations() {
|
|
5317
5492
|
const data = await this.request("/api/platform/invitations");
|
|
5318
|
-
if (!Array.isArray(data))
|
|
5319
|
-
throw invalidResponse2("Invalid invitation list");
|
|
5493
|
+
if (!Array.isArray(data)) throw invalidResponse2("Invalid invitation list");
|
|
5320
5494
|
return data.map(hydrateInvitation);
|
|
5321
5495
|
}
|
|
5322
5496
|
async revokeInvitation(email) {
|
|
@@ -5343,8 +5517,7 @@ var PlatformClient = class {
|
|
|
5343
5517
|
const data = await this.request(
|
|
5344
5518
|
`/api/platform/tenant-members?${query}`
|
|
5345
5519
|
);
|
|
5346
|
-
if (!Array.isArray(data))
|
|
5347
|
-
throw invalidResponse2("Invalid tenant member list");
|
|
5520
|
+
if (!Array.isArray(data)) throw invalidResponse2("Invalid tenant member list");
|
|
5348
5521
|
return data.map(hydrateTenantMember);
|
|
5349
5522
|
}
|
|
5350
5523
|
async addTenantMember(input) {
|
|
@@ -5356,8 +5529,7 @@ var PlatformClient = class {
|
|
|
5356
5529
|
}
|
|
5357
5530
|
async listInviteLinks() {
|
|
5358
5531
|
const data = await this.request("/api/platform/invite-links");
|
|
5359
|
-
if (!Array.isArray(data))
|
|
5360
|
-
throw invalidResponse2("Invalid invite link list");
|
|
5532
|
+
if (!Array.isArray(data)) throw invalidResponse2("Invalid invite link list");
|
|
5361
5533
|
return data.map(hydrateInviteLink);
|
|
5362
5534
|
}
|
|
5363
5535
|
async createInviteLink(input) {
|
|
@@ -5416,8 +5588,7 @@ var PlatformClient = class {
|
|
|
5416
5588
|
async listOidcClaims(status = "pending") {
|
|
5417
5589
|
const query = new URLSearchParams({ status }).toString();
|
|
5418
5590
|
const data = await this.request(`/api/platform/oidc-claims?${query}`);
|
|
5419
|
-
if (!Array.isArray(data))
|
|
5420
|
-
throw invalidResponse2("Invalid SSO claim list");
|
|
5591
|
+
if (!Array.isArray(data)) throw invalidResponse2("Invalid SSO claim list");
|
|
5421
5592
|
return data.map(hydrateOidcIdentityClaim);
|
|
5422
5593
|
}
|
|
5423
5594
|
async updateOidcClaimEmail(id, email) {
|
|
@@ -5442,7 +5613,10 @@ var PlatformClient = class {
|
|
|
5442
5613
|
return hydrateOidcIdentityClaim(data);
|
|
5443
5614
|
}
|
|
5444
5615
|
async request(path, init = {}) {
|
|
5445
|
-
const headers = {
|
|
5616
|
+
const headers = {
|
|
5617
|
+
...this.getHeaders(),
|
|
5618
|
+
...init.headers
|
|
5619
|
+
};
|
|
5446
5620
|
if (init.body !== void 0) {
|
|
5447
5621
|
headers["Content-Type"] = "application/json";
|
|
5448
5622
|
}
|
|
@@ -5459,7 +5633,7 @@ var PlatformClient = class {
|
|
|
5459
5633
|
};
|
|
5460
5634
|
|
|
5461
5635
|
// src/client.ts
|
|
5462
|
-
var _Client = class extends AbstractClient {
|
|
5636
|
+
var _Client = class _Client extends AbstractClient {
|
|
5463
5637
|
/**
|
|
5464
5638
|
* Creates a new Client instance
|
|
5465
5639
|
* @param config - Configuration options for the client
|
|
@@ -5762,8 +5936,7 @@ var _Client = class extends AbstractClient {
|
|
|
5762
5936
|
...this.getAllHeaders()
|
|
5763
5937
|
};
|
|
5764
5938
|
const res = await fetch(`${this.config.baseURL}${path}`, { headers, signal });
|
|
5765
|
-
if (!res.ok || !res.body)
|
|
5766
|
-
throw new Error("Stream connection failed");
|
|
5939
|
+
if (!res.ok || !res.body) throw new Error("Stream connection failed");
|
|
5767
5940
|
try {
|
|
5768
5941
|
for await (const frame of parseSseBody(res.body, { strictJsonObject: true })) {
|
|
5769
5942
|
yield { event: frame.event, data: frame.data };
|
|
@@ -5792,8 +5965,7 @@ var _Client = class extends AbstractClient {
|
|
|
5792
5965
|
return this.getAllHeaders();
|
|
5793
5966
|
}
|
|
5794
5967
|
bodyAffinityHeaders(body) {
|
|
5795
|
-
if (!body || typeof body !== "object" || body instanceof FormData)
|
|
5796
|
-
return {};
|
|
5968
|
+
if (!body || typeof body !== "object" || body instanceof FormData) return {};
|
|
5797
5969
|
const threadId = body.thread_id;
|
|
5798
5970
|
return typeof threadId === "string" ? threadAffinityHeaders2(threadId) : {};
|
|
5799
5971
|
}
|
|
@@ -5827,8 +5999,7 @@ var _Client = class extends AbstractClient {
|
|
|
5827
5999
|
if (!response.body) {
|
|
5828
6000
|
throw new Error("Response body is null");
|
|
5829
6001
|
}
|
|
5830
|
-
for await (const frame of parseSseBody(response.body, { strictJsonObject: true }))
|
|
5831
|
-
onEvent(frame.data);
|
|
6002
|
+
for await (const frame of parseSseBody(response.body, { strictJsonObject: true })) onEvent(frame.data);
|
|
5832
6003
|
if (onComplete) {
|
|
5833
6004
|
if (options.enableReturnStateWhenSteamCompleted) {
|
|
5834
6005
|
try {
|
|
@@ -5855,11 +6026,11 @@ var _Client = class extends AbstractClient {
|
|
|
5855
6026
|
};
|
|
5856
6027
|
}
|
|
5857
6028
|
};
|
|
6029
|
+
_Client.globalWorkspaceHeaders = {};
|
|
5858
6030
|
var Client = _Client;
|
|
5859
|
-
Client.globalWorkspaceHeaders = {};
|
|
5860
6031
|
|
|
5861
6032
|
// src/runtime-client.ts
|
|
5862
|
-
var RuntimeAxiomClient = class extends Client {
|
|
6033
|
+
var RuntimeAxiomClient = class _RuntimeAxiomClient extends Client {
|
|
5863
6034
|
constructor(config) {
|
|
5864
6035
|
super({
|
|
5865
6036
|
...config,
|
|
@@ -5886,8 +6057,7 @@ var RuntimeAxiomClient = class extends Client {
|
|
|
5886
6057
|
* priming — the first request triggers the token provider.
|
|
5887
6058
|
*/
|
|
5888
6059
|
async primeToken() {
|
|
5889
|
-
if (this.identity.mode !== "verified")
|
|
5890
|
-
return "";
|
|
6060
|
+
if (this.identity.mode !== "verified") return "";
|
|
5891
6061
|
if (!this.tokenPromise) {
|
|
5892
6062
|
this.tokenPromise = this.identity.tokenProvider().then((token) => {
|
|
5893
6063
|
this.token = token;
|
|
@@ -5936,8 +6106,7 @@ var RuntimeAxiomClient = class extends Client {
|
|
|
5936
6106
|
error.status = response.status;
|
|
5937
6107
|
throw error;
|
|
5938
6108
|
}
|
|
5939
|
-
if (response.status === 204)
|
|
5940
|
-
return void 0;
|
|
6109
|
+
if (response.status === 204) return void 0;
|
|
5941
6110
|
return await response.json();
|
|
5942
6111
|
}
|
|
5943
6112
|
getBaseUrl() {
|
|
@@ -5949,7 +6118,7 @@ var RuntimeAxiomClient = class extends Client {
|
|
|
5949
6118
|
* working (each clone carries its own resolved credential cache).
|
|
5950
6119
|
*/
|
|
5951
6120
|
createInstance(config) {
|
|
5952
|
-
return new
|
|
6121
|
+
return new _RuntimeAxiomClient({
|
|
5953
6122
|
gatewayUrl: this.gatewayUrl,
|
|
5954
6123
|
webAppId: this.webAppId,
|
|
5955
6124
|
identity: this.identity,
|
|
@@ -5968,7 +6137,7 @@ var RuntimeAxiomClient = class extends Client {
|
|
|
5968
6137
|
// src/wechat-client.ts
|
|
5969
6138
|
import { threadAffinityHeaders as threadAffinityHeaders3 } from "@axiom-lattice/protocols";
|
|
5970
6139
|
var import_encoding = __toESM(require_encoding());
|
|
5971
|
-
var WeChatClient = class extends AbstractClient {
|
|
6140
|
+
var WeChatClient = class _WeChatClient extends AbstractClient {
|
|
5972
6141
|
/**
|
|
5973
6142
|
* Creates a new WeChatClient instance
|
|
5974
6143
|
* @param config - Configuration options for the client
|
|
@@ -5993,16 +6162,12 @@ var WeChatClient = class extends AbstractClient {
|
|
|
5993
6162
|
*/
|
|
5994
6163
|
setWorkspaceContext(workspaceId, projectId) {
|
|
5995
6164
|
if (workspaceId !== void 0) {
|
|
5996
|
-
if (workspaceId)
|
|
5997
|
-
|
|
5998
|
-
else
|
|
5999
|
-
delete this.workspaceHeaders["x-workspace-id"];
|
|
6165
|
+
if (workspaceId) this.workspaceHeaders["x-workspace-id"] = workspaceId;
|
|
6166
|
+
else delete this.workspaceHeaders["x-workspace-id"];
|
|
6000
6167
|
}
|
|
6001
6168
|
if (projectId !== void 0) {
|
|
6002
|
-
if (projectId)
|
|
6003
|
-
|
|
6004
|
-
else
|
|
6005
|
-
delete this.workspaceHeaders["x-project-id"];
|
|
6169
|
+
if (projectId) this.workspaceHeaders["x-project-id"] = projectId;
|
|
6170
|
+
else delete this.workspaceHeaders["x-project-id"];
|
|
6006
6171
|
}
|
|
6007
6172
|
}
|
|
6008
6173
|
/**
|
|
@@ -6018,7 +6183,7 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6018
6183
|
* @returns A new WeChatClient instance
|
|
6019
6184
|
*/
|
|
6020
6185
|
createInstance(config) {
|
|
6021
|
-
return new
|
|
6186
|
+
return new _WeChatClient(config);
|
|
6022
6187
|
}
|
|
6023
6188
|
/**
|
|
6024
6189
|
* Implementation of the abstract makeRequest method for WeChat clients
|
|
@@ -6078,8 +6243,7 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6078
6243
|
let pending = "";
|
|
6079
6244
|
const handleLine = (line) => {
|
|
6080
6245
|
const trimmed = line.trim();
|
|
6081
|
-
if (!trimmed.startsWith("data:"))
|
|
6082
|
-
return;
|
|
6246
|
+
if (!trimmed.startsWith("data:")) return;
|
|
6083
6247
|
const payload = trimmed.slice("data:".length);
|
|
6084
6248
|
const json = payload.startsWith(" ") ? payload.slice(1) : payload;
|
|
6085
6249
|
try {
|
|
@@ -6091,8 +6255,7 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6091
6255
|
}
|
|
6092
6256
|
};
|
|
6093
6257
|
const push = (res) => {
|
|
6094
|
-
if (!res.data)
|
|
6095
|
-
return;
|
|
6258
|
+
if (!res.data) return;
|
|
6096
6259
|
pending += decoder.decode(res.data, { stream: true });
|
|
6097
6260
|
const lines = pending.split("\n");
|
|
6098
6261
|
pending = lines.pop();
|
|
@@ -6118,8 +6281,7 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6118
6281
|
errorMessageFromBody(data) {
|
|
6119
6282
|
if (typeof data === "string") {
|
|
6120
6283
|
const text = data.trim();
|
|
6121
|
-
if (!text)
|
|
6122
|
-
return void 0;
|
|
6284
|
+
if (!text) return void 0;
|
|
6123
6285
|
try {
|
|
6124
6286
|
return this.recordMessage(JSON.parse(text));
|
|
6125
6287
|
} catch {
|
|
@@ -6147,8 +6309,7 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6147
6309
|
*/
|
|
6148
6310
|
streamStatusError(res) {
|
|
6149
6311
|
const statusCode = res.statusCode;
|
|
6150
|
-
if (statusCode >= 200 && statusCode < 300)
|
|
6151
|
-
return void 0;
|
|
6312
|
+
if (statusCode >= 200 && statusCode < 300) return void 0;
|
|
6152
6313
|
const message = this.errorMessageFromBody(res.data);
|
|
6153
6314
|
if (statusCode === 401) {
|
|
6154
6315
|
return new AuthenticationError(message || "Authentication failed");
|
|
@@ -6198,26 +6359,22 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6198
6359
|
responseType: "text",
|
|
6199
6360
|
enableChunked: true,
|
|
6200
6361
|
success: (res) => {
|
|
6201
|
-
if (aborted || terminal)
|
|
6202
|
-
return;
|
|
6362
|
+
if (aborted || terminal) return;
|
|
6203
6363
|
const error = this.streamStatusError(res);
|
|
6204
6364
|
if (error) {
|
|
6205
6365
|
terminal = true;
|
|
6206
|
-
if (onError)
|
|
6207
|
-
onError(error);
|
|
6366
|
+
if (onError) onError(error);
|
|
6208
6367
|
}
|
|
6209
6368
|
},
|
|
6210
6369
|
fail: (err) => {
|
|
6211
|
-
if (aborted)
|
|
6212
|
-
return;
|
|
6370
|
+
if (aborted) return;
|
|
6213
6371
|
terminal = true;
|
|
6214
6372
|
if (onError) {
|
|
6215
6373
|
onError(new Error(`Resume stream request failed: ${err.errMsg}`));
|
|
6216
6374
|
}
|
|
6217
6375
|
},
|
|
6218
6376
|
complete: () => {
|
|
6219
|
-
if (terminal)
|
|
6220
|
-
return;
|
|
6377
|
+
if (terminal) return;
|
|
6221
6378
|
processor.flush();
|
|
6222
6379
|
if (onComplete) {
|
|
6223
6380
|
onComplete();
|
|
@@ -6225,8 +6382,7 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6225
6382
|
}
|
|
6226
6383
|
});
|
|
6227
6384
|
requestTask.onChunkReceived((res) => {
|
|
6228
|
-
if (terminal)
|
|
6229
|
-
return;
|
|
6385
|
+
if (terminal) return;
|
|
6230
6386
|
processor.push(res);
|
|
6231
6387
|
});
|
|
6232
6388
|
return () => {
|
|
@@ -6313,26 +6469,22 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6313
6469
|
responseType: "text",
|
|
6314
6470
|
enableChunked: true,
|
|
6315
6471
|
success: (res) => {
|
|
6316
|
-
if (aborted || terminal)
|
|
6317
|
-
return;
|
|
6472
|
+
if (aborted || terminal) return;
|
|
6318
6473
|
const error = this.streamStatusError(res);
|
|
6319
6474
|
if (error) {
|
|
6320
6475
|
terminal = true;
|
|
6321
|
-
if (onError)
|
|
6322
|
-
onError(error);
|
|
6476
|
+
if (onError) onError(error);
|
|
6323
6477
|
}
|
|
6324
6478
|
},
|
|
6325
6479
|
fail: (err) => {
|
|
6326
|
-
if (aborted)
|
|
6327
|
-
return;
|
|
6480
|
+
if (aborted) return;
|
|
6328
6481
|
terminal = true;
|
|
6329
6482
|
if (onError) {
|
|
6330
6483
|
onError(new Error(`Stream request failed: ${err.errMsg}`));
|
|
6331
6484
|
}
|
|
6332
6485
|
},
|
|
6333
6486
|
complete: async () => {
|
|
6334
|
-
if (terminal)
|
|
6335
|
-
return;
|
|
6487
|
+
if (terminal) return;
|
|
6336
6488
|
processor.flush();
|
|
6337
6489
|
if (onComplete) {
|
|
6338
6490
|
if (options.enableReturnStateWhenSteamCompleted) {
|
|
@@ -6349,8 +6501,7 @@ var WeChatClient = class extends AbstractClient {
|
|
|
6349
6501
|
}
|
|
6350
6502
|
});
|
|
6351
6503
|
requestTask.onChunkReceived((res) => {
|
|
6352
|
-
if (terminal)
|
|
6353
|
-
return;
|
|
6504
|
+
if (terminal) return;
|
|
6354
6505
|
processor.push(res);
|
|
6355
6506
|
});
|
|
6356
6507
|
return () => {
|
|
@@ -6620,8 +6771,7 @@ var WorkspaceClient = class {
|
|
|
6620
6771
|
*/
|
|
6621
6772
|
async downloadFolder(workspaceId, projectId, folderPath, assistantId) {
|
|
6622
6773
|
const params = new URLSearchParams({ path: folderPath, tenantId: this.tenantId });
|
|
6623
|
-
if (assistantId)
|
|
6624
|
-
params.set("assistantId", assistantId);
|
|
6774
|
+
if (assistantId) params.set("assistantId", assistantId);
|
|
6625
6775
|
const response = await fetch(
|
|
6626
6776
|
`${this.baseURL}/api/workspaces/${workspaceId}/projects/${projectId}/downloadfolder?${params}`,
|
|
6627
6777
|
{ headers: this.headers }
|
|
@@ -6672,24 +6822,18 @@ var isObj = (v) => typeof v === "object" && v !== null;
|
|
|
6672
6822
|
var TEXT_BLOCK_TYPES = /* @__PURE__ */ new Set(["text"]);
|
|
6673
6823
|
var ARTIFACT_SENTINEL_TYPES = /* @__PURE__ */ new Set(["mcp_structured_content", "mcp_meta"]);
|
|
6674
6824
|
function asBlocks(value) {
|
|
6675
|
-
if (Array.isArray(value))
|
|
6676
|
-
|
|
6677
|
-
if (value === void 0 || value === null)
|
|
6678
|
-
return [];
|
|
6825
|
+
if (Array.isArray(value)) return value;
|
|
6826
|
+
if (value === void 0 || value === null) return [];
|
|
6679
6827
|
return [value];
|
|
6680
6828
|
}
|
|
6681
6829
|
function looksLikeResource(block) {
|
|
6682
6830
|
return typeof block.uri === "string" && ("mimeType" in block || "blob" in block || "text" in block);
|
|
6683
6831
|
}
|
|
6684
6832
|
function textOf(block, allowUntyped) {
|
|
6685
|
-
if (typeof block === "string")
|
|
6686
|
-
|
|
6687
|
-
if (
|
|
6688
|
-
|
|
6689
|
-
if (block.type === "text")
|
|
6690
|
-
return block.text;
|
|
6691
|
-
if (allowUntyped && block.type === void 0 && !looksLikeResource(block))
|
|
6692
|
-
return block.text;
|
|
6833
|
+
if (typeof block === "string") return block;
|
|
6834
|
+
if (!isObj(block) || typeof block.text !== "string") return null;
|
|
6835
|
+
if (block.type === "text") return block.text;
|
|
6836
|
+
if (allowUntyped && block.type === void 0 && !looksLikeResource(block)) return block.text;
|
|
6693
6837
|
return null;
|
|
6694
6838
|
}
|
|
6695
6839
|
function joinText(blocks, allowUntyped) {
|
|
@@ -6713,15 +6857,13 @@ function structuredFromArtifact(artifact) {
|
|
|
6713
6857
|
}
|
|
6714
6858
|
function metaFromContent(content) {
|
|
6715
6859
|
for (const block of asBlocks(content)) {
|
|
6716
|
-
if (isObj(block) && isObj(block.meta))
|
|
6717
|
-
return block.meta;
|
|
6860
|
+
if (isObj(block) && isObj(block.meta)) return block.meta;
|
|
6718
6861
|
}
|
|
6719
6862
|
return void 0;
|
|
6720
6863
|
}
|
|
6721
6864
|
function metaFromArtifact(artifact) {
|
|
6722
6865
|
for (const item of asBlocks(artifact)) {
|
|
6723
|
-
if (isObj(item) && item.type === "mcp_meta" && isObj(item.data))
|
|
6724
|
-
return item.data;
|
|
6866
|
+
if (isObj(item) && item.type === "mcp_meta" && isObj(item.data)) return item.data;
|
|
6725
6867
|
}
|
|
6726
6868
|
return void 0;
|
|
6727
6869
|
}
|
|
@@ -6749,22 +6891,17 @@ function normalizeToolResult(message) {
|
|
|
6749
6891
|
structuredContent = structuredFromArtifact(message.artifact);
|
|
6750
6892
|
}
|
|
6751
6893
|
let meta = metaFromContent(message.content);
|
|
6752
|
-
if (meta === void 0)
|
|
6753
|
-
meta = metaFromArtifact(message.artifact);
|
|
6894
|
+
if (meta === void 0) meta = metaFromArtifact(message.artifact);
|
|
6754
6895
|
const artifactBlocks = asBlocks(message.artifact).map(toUiBlock).filter(
|
|
6755
6896
|
(b) => b !== null && !ARTIFACT_SENTINEL_TYPES.has(b.type)
|
|
6756
6897
|
);
|
|
6757
6898
|
const allBlocks = [...contentBlocks, ...artifactBlocks];
|
|
6758
6899
|
let text = joinText(asBlocks(message.content), true);
|
|
6759
|
-
if (text.length === 0)
|
|
6760
|
-
text = joinText(asBlocks(message.artifact), false);
|
|
6900
|
+
if (text.length === 0) text = joinText(asBlocks(message.artifact), false);
|
|
6761
6901
|
const ui = {};
|
|
6762
|
-
if (structuredContent !== void 0)
|
|
6763
|
-
|
|
6764
|
-
if (
|
|
6765
|
-
ui.meta = meta;
|
|
6766
|
-
if (allBlocks.length > 0)
|
|
6767
|
-
ui.contentBlocks = allBlocks;
|
|
6902
|
+
if (structuredContent !== void 0) ui.structuredContent = structuredContent;
|
|
6903
|
+
if (meta !== void 0) ui.meta = meta;
|
|
6904
|
+
if (allBlocks.length > 0) ui.contentBlocks = allBlocks;
|
|
6768
6905
|
return Object.keys(ui).length > 0 ? { text, ui } : { text };
|
|
6769
6906
|
}
|
|
6770
6907
|
|
|
@@ -6828,16 +6965,14 @@ function createSimpleMessageMerger() {
|
|
|
6828
6965
|
}
|
|
6829
6966
|
function replaceMessage(id, updates) {
|
|
6830
6967
|
const index = messageMap.get(id);
|
|
6831
|
-
if (index === void 0)
|
|
6832
|
-
return null;
|
|
6968
|
+
if (index === void 0) return null;
|
|
6833
6969
|
const updated = { ...messages[index], ...updates };
|
|
6834
6970
|
messages[index] = updated;
|
|
6835
6971
|
return updated;
|
|
6836
6972
|
}
|
|
6837
6973
|
function buildToolCalls(messageId) {
|
|
6838
6974
|
const builders = toolBuilders.get(messageId);
|
|
6839
|
-
if (!builders || builders.size === 0)
|
|
6840
|
-
return null;
|
|
6975
|
+
if (!builders || builders.size === 0) return null;
|
|
6841
6976
|
const toolCalls = [];
|
|
6842
6977
|
for (const [, builder] of Array.from(builders.entries())) {
|
|
6843
6978
|
if (builder.name && builder.id) {
|
|
@@ -6860,8 +6995,7 @@ function createSimpleMessageMerger() {
|
|
|
6860
6995
|
});
|
|
6861
6996
|
}
|
|
6862
6997
|
function push(chunk) {
|
|
6863
|
-
if (chunk.type === "error")
|
|
6864
|
-
return;
|
|
6998
|
+
if (chunk.type === "error") return;
|
|
6865
6999
|
const role = normalizeRole(chunk.type);
|
|
6866
7000
|
let message = ensureMessage(chunk.data.id, role);
|
|
6867
7001
|
if (chunk.data.content && message.role !== "tool") {
|
|
@@ -6899,14 +7033,12 @@ function createSimpleMessageMerger() {
|
|
|
6899
7033
|
builder = { args: "" };
|
|
6900
7034
|
builders.set(chunk_item.index, builder);
|
|
6901
7035
|
}
|
|
6902
|
-
if (chunk_item.name)
|
|
6903
|
-
builder.name = chunk_item.name;
|
|
7036
|
+
if (chunk_item.name) builder.name = chunk_item.name;
|
|
6904
7037
|
if (chunk_item.id) {
|
|
6905
7038
|
builder.id = chunk_item.id;
|
|
6906
7039
|
toolId_MessageIdMap.set(chunk_item.id, message.id);
|
|
6907
7040
|
}
|
|
6908
|
-
if (chunk_item.args)
|
|
6909
|
-
builder.args += chunk_item.args;
|
|
7041
|
+
if (chunk_item.args) builder.args += chunk_item.args;
|
|
6910
7042
|
}
|
|
6911
7043
|
const toolCalls = buildToolCalls(message.id);
|
|
6912
7044
|
if (toolCalls) {
|
|
@@ -6916,8 +7048,7 @@ function createSimpleMessageMerger() {
|
|
|
6916
7048
|
if (message.role === "tool" && chunk.data.tool_call_id) {
|
|
6917
7049
|
const original_tool_message_id = chunk.data.id;
|
|
6918
7050
|
const messageId = toolId_MessageIdMap.get(chunk.data.tool_call_id);
|
|
6919
|
-
if (!messageId)
|
|
6920
|
-
return;
|
|
7051
|
+
if (!messageId) return;
|
|
6921
7052
|
const messageIndex = messageMap.get(messageId);
|
|
6922
7053
|
if (messageIndex !== void 0) {
|
|
6923
7054
|
const { text, ui } = normalizeToolResult({
|