@copilotz/admin 0.9.34 → 0.9.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +77 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +70 -2
- package/dist/index.d.ts +70 -2
- package/dist/index.js +69 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -34,6 +34,14 @@ __export(index_exports, {
|
|
|
34
34
|
ADMIN_GROUP_ORDER: () => ADMIN_GROUP_ORDER,
|
|
35
35
|
CopilotzAdmin: () => CopilotzAdmin,
|
|
36
36
|
EMPTY_USAGE_TOTALS: () => EMPTY_USAGE_TOTALS,
|
|
37
|
+
EmptyState: () => EmptyState,
|
|
38
|
+
FilterBar: () => FilterBar,
|
|
39
|
+
InspectorPanel: () => InspectorPanel,
|
|
40
|
+
JsonPanel: () => JsonPanel,
|
|
41
|
+
MetricStrip: () => MetricStrip,
|
|
42
|
+
PageHeader: () => PageHeader,
|
|
43
|
+
ResourceTable: () => ResourceTable,
|
|
44
|
+
StatusBadge: () => StatusBadge,
|
|
37
45
|
addUsageTotals: () => addUsageTotals,
|
|
38
46
|
agentsModule: () => agentsModule,
|
|
39
47
|
aggregateUsageRows: () => aggregateUsageRows,
|
|
@@ -112,11 +120,44 @@ async function mergeHeaders(headers, getRequestHeaders) {
|
|
|
112
120
|
async function parseJsonResponse(response) {
|
|
113
121
|
const payload = await response.json().catch(() => null);
|
|
114
122
|
if (!response.ok) {
|
|
115
|
-
const message = payload?.message ?? payload?.data?.message ?? `Admin request failed (${response.status})`;
|
|
123
|
+
const message = payload?.message ?? payload?.data?.message ?? payload?.error?.message ?? `Admin request failed (${response.status})`;
|
|
116
124
|
throw new Error(message);
|
|
117
125
|
}
|
|
118
126
|
return payload?.data ?? payload;
|
|
119
127
|
}
|
|
128
|
+
async function parseJsonEnvelopeResponse(response) {
|
|
129
|
+
const payload = await response.json().catch(() => null);
|
|
130
|
+
if (!response.ok) {
|
|
131
|
+
const message = payload?.message ?? payload?.data?.message ?? payload?.error?.message ?? `Admin request failed (${response.status})`;
|
|
132
|
+
throw new Error(message);
|
|
133
|
+
}
|
|
134
|
+
return payload;
|
|
135
|
+
}
|
|
136
|
+
function isRecord(value) {
|
|
137
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
138
|
+
}
|
|
139
|
+
function normalizeMessagePageInfo(value, messages) {
|
|
140
|
+
const oldestFromData = messages[0]?.id ?? null;
|
|
141
|
+
const newestFromData = messages[messages.length - 1]?.id ?? null;
|
|
142
|
+
if (!isRecord(value)) {
|
|
143
|
+
return {
|
|
144
|
+
hasMoreBefore: false,
|
|
145
|
+
oldestMessageId: oldestFromData,
|
|
146
|
+
newestMessageId: newestFromData
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
hasMoreBefore: value.hasMoreBefore === true,
|
|
151
|
+
oldestMessageId: typeof value.oldestMessageId === "string" ? value.oldestMessageId : oldestFromData,
|
|
152
|
+
newestMessageId: typeof value.newestMessageId === "string" ? value.newestMessageId : newestFromData
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function normalizeMessagePage(payload) {
|
|
156
|
+
const candidate = isRecord(payload) && isRecord(payload.data) && Array.isArray(payload.data.data) ? payload.data : payload;
|
|
157
|
+
const data = isRecord(candidate) && Array.isArray(candidate.data) ? candidate.data : Array.isArray(candidate) ? candidate : [];
|
|
158
|
+
const pageInfo = isRecord(candidate) ? normalizeMessagePageInfo(candidate.pageInfo, data) : normalizeMessagePageInfo(void 0, data);
|
|
159
|
+
return { data, pageInfo };
|
|
160
|
+
}
|
|
120
161
|
function createAdminClient(options = {}) {
|
|
121
162
|
const baseUrl = resolveBaseUrl(options.baseUrl);
|
|
122
163
|
const paths = { ...DEFAULT_PATHS, ...options.paths };
|
|
@@ -127,6 +168,13 @@ function createAdminClient(options = {}) {
|
|
|
127
168
|
});
|
|
128
169
|
return await parseJsonResponse(response);
|
|
129
170
|
};
|
|
171
|
+
const requestEnvelopeJson = async (path, params) => {
|
|
172
|
+
const url = buildUrl(baseUrl, path, params);
|
|
173
|
+
const response = await fetch(url.toString(), {
|
|
174
|
+
headers: await mergeHeaders({}, options.getRequestHeaders)
|
|
175
|
+
});
|
|
176
|
+
return await parseJsonEnvelopeResponse(response);
|
|
177
|
+
};
|
|
130
178
|
const writeJson = async (method, path, data, params) => {
|
|
131
179
|
const url = buildUrl(baseUrl, path, params);
|
|
132
180
|
const response = await fetch(url.toString(), {
|
|
@@ -202,13 +250,16 @@ function createAdminClient(options = {}) {
|
|
|
202
250
|
getThread: async (threadId) => await requestJson(
|
|
203
251
|
`${paths.threadsBase}/${encodeURIComponent(threadId)}`
|
|
204
252
|
),
|
|
205
|
-
getThreadMessages: async (threadId, messageOptions = {}) =>
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
253
|
+
getThreadMessages: async (threadId, messageOptions = {}) => {
|
|
254
|
+
const payload = await requestEnvelopeJson(
|
|
255
|
+
`${paths.threadsBase}/${encodeURIComponent(threadId)}/messages`,
|
|
256
|
+
{
|
|
257
|
+
limit: messageOptions.limit ? String(messageOptions.limit) : void 0,
|
|
258
|
+
before: messageOptions.before
|
|
259
|
+
}
|
|
260
|
+
);
|
|
261
|
+
return normalizeMessagePage(payload);
|
|
262
|
+
},
|
|
212
263
|
getThreadEvent: async (threadId) => await requestJson(
|
|
213
264
|
`${paths.threadsBase}/${encodeURIComponent(threadId)}/events`
|
|
214
265
|
),
|
|
@@ -2751,7 +2802,9 @@ function ThreadsPage({ context }) {
|
|
|
2751
2802
|
align: "right",
|
|
2752
2803
|
id: "participants",
|
|
2753
2804
|
header: "Participants",
|
|
2754
|
-
render: (thread) => formatNumber(
|
|
2805
|
+
render: (thread) => formatNumber(
|
|
2806
|
+
Array.isArray(thread.participantIds) ? thread.participantIds.length : 0
|
|
2807
|
+
)
|
|
2755
2808
|
},
|
|
2756
2809
|
{
|
|
2757
2810
|
align: "right",
|
|
@@ -2802,8 +2855,8 @@ function ThreadInspector({
|
|
|
2802
2855
|
]).then(([nextThread, page]) => {
|
|
2803
2856
|
if (!active) return;
|
|
2804
2857
|
setThread(nextThread);
|
|
2805
|
-
setMessages(page.data);
|
|
2806
|
-
setPageInfo(page
|
|
2858
|
+
setMessages(Array.isArray(page?.data) ? page.data : []);
|
|
2859
|
+
setPageInfo(page?.pageInfo ?? null);
|
|
2807
2860
|
}).catch((cause) => {
|
|
2808
2861
|
if (active) setError(cause instanceof Error ? cause.message : "Failed to load thread");
|
|
2809
2862
|
}).finally(() => {
|
|
@@ -2823,8 +2876,11 @@ function ThreadInspector({
|
|
|
2823
2876
|
before: pageInfo.oldestMessageId,
|
|
2824
2877
|
limit: MESSAGE_PAGE_SIZE
|
|
2825
2878
|
});
|
|
2826
|
-
setMessages((current) => [
|
|
2827
|
-
|
|
2879
|
+
setMessages((current) => [
|
|
2880
|
+
...Array.isArray(page?.data) ? page.data : [],
|
|
2881
|
+
...current
|
|
2882
|
+
]);
|
|
2883
|
+
setPageInfo(page?.pageInfo ?? null);
|
|
2828
2884
|
} finally {
|
|
2829
2885
|
setIsLoadingMore(false);
|
|
2830
2886
|
}
|
|
@@ -3938,6 +3994,14 @@ function useCopilotzAdmin(options = {}) {
|
|
|
3938
3994
|
ADMIN_GROUP_ORDER,
|
|
3939
3995
|
CopilotzAdmin,
|
|
3940
3996
|
EMPTY_USAGE_TOTALS,
|
|
3997
|
+
EmptyState,
|
|
3998
|
+
FilterBar,
|
|
3999
|
+
InspectorPanel,
|
|
4000
|
+
JsonPanel,
|
|
4001
|
+
MetricStrip,
|
|
4002
|
+
PageHeader,
|
|
4003
|
+
ResourceTable,
|
|
4004
|
+
StatusBadge,
|
|
3941
4005
|
addUsageTotals,
|
|
3942
4006
|
agentsModule,
|
|
3943
4007
|
aggregateUsageRows,
|