doover-js 0.16.0 → 0.18.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/apis/agents-api.d.ts +47 -1
- package/dist/apis/agents-api.js +102 -5
- package/dist/client/capabilities.d.ts +1 -1
- package/dist/client/capabilities.js +2 -0
- package/dist/client/local-agent-client.js +2 -0
- package/dist/client/multiplex-client.js +23 -0
- package/dist/client/offline-cache.js +24 -0
- package/dist/esm/apis/agents-api.d.ts +47 -1
- package/dist/esm/apis/agents-api.js +100 -5
- package/dist/esm/client/capabilities.d.ts +1 -1
- package/dist/esm/client/capabilities.js +2 -0
- package/dist/esm/client/local-agent-client.js +2 -0
- package/dist/esm/client/multiplex-client.js +23 -0
- package/dist/esm/client/offline-cache.js +24 -0
- package/dist/esm/gateway/gateway-client.js +8 -0
- package/dist/esm/http/rest-client.d.ts +4 -0
- package/dist/esm/http/rest-client.js +20 -6
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/package.json +1 -1
- package/dist/esm/react/index.d.ts +4 -0
- package/dist/esm/react/index.js +2 -0
- package/dist/esm/react/useMultiAgentConnectionHistory.d.ts +35 -0
- package/dist/esm/react/useMultiAgentConnectionHistory.js +49 -0
- package/dist/esm/react/useMultiAgentMessageCounts.d.ts +25 -0
- package/dist/esm/react/useMultiAgentMessageCounts.js +40 -0
- package/dist/esm/types/connection.d.ts +48 -0
- package/dist/esm/types/openapi.d.ts +25 -0
- package/dist/esm/utils/view-as.d.ts +2 -0
- package/dist/esm/utils/view-as.js +6 -0
- package/dist/gateway/gateway-client.js +8 -0
- package/dist/http/rest-client.d.ts +4 -0
- package/dist/http/rest-client.js +20 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -2
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.js +8 -1
- package/dist/react/useMultiAgentConnectionHistory.d.ts +35 -0
- package/dist/react/useMultiAgentConnectionHistory.js +53 -0
- package/dist/react/useMultiAgentMessageCounts.d.ts +25 -0
- package/dist/react/useMultiAgentMessageCounts.js +44 -0
- package/dist/types/connection.d.ts +48 -0
- package/dist/types/openapi.d.ts +25 -0
- package/dist/utils/view-as.d.ts +2 -0
- package/dist/utils/view-as.js +9 -0
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { AgentAggregate, BatchMessagesResponse } from "../types/openapi.js";
|
|
1
|
+
import type { AgentAggregate, BatchMessagesResponse, MessageCountsResponse } from "../types/openapi.js";
|
|
2
|
+
import type { ConnectionHistoryResponse } from "../types/connection.js";
|
|
2
3
|
import type { AgentsResponse, GetAgentsOptions } from "../types/viewer.js";
|
|
3
4
|
import type { RestClient } from "../http/rest-client.js";
|
|
4
5
|
import type { DooverRequestOptions } from "../client/request-options.js";
|
|
@@ -146,6 +147,25 @@ export interface DeviceTokenResponse {
|
|
|
146
147
|
/** Unix-ms issuance time, which is what the revocation floor compares against. */
|
|
147
148
|
issued_at_ms: number | null;
|
|
148
149
|
}
|
|
150
|
+
export interface ConnectionHistoryParams {
|
|
151
|
+
agent_id: string[];
|
|
152
|
+
/** Snowflake id bounds. Defaults to the last 7 days; at most 31 days apart. */
|
|
153
|
+
before?: string;
|
|
154
|
+
after?: string;
|
|
155
|
+
/**
|
|
156
|
+
* Slot width in ms for the fleet `buckets` series (at least 60 000, and
|
|
157
|
+
* no more than 1000 slots across the window). Omit for no buckets.
|
|
158
|
+
*/
|
|
159
|
+
bucket_ms?: number;
|
|
160
|
+
/** Include each agent's state segments. The server allows this for at most 25 agents per call. */
|
|
161
|
+
include_segments?: boolean;
|
|
162
|
+
}
|
|
163
|
+
export interface MultiAgentMessageCountsParams {
|
|
164
|
+
agent_id: string[];
|
|
165
|
+
/** Snowflake id bounds. Defaults to the last 7 days; at most 92 days apart. */
|
|
166
|
+
before?: string;
|
|
167
|
+
after?: string;
|
|
168
|
+
}
|
|
149
169
|
export interface MultiAgentAggregatesParams {
|
|
150
170
|
agent_id: string[];
|
|
151
171
|
/**
|
|
@@ -171,6 +191,20 @@ export declare class AgentsApi {
|
|
|
171
191
|
* lexically-highest cursor across at-limit agents.
|
|
172
192
|
*/
|
|
173
193
|
getMultiAgentMessages(channelName: string, params: MultiAgentMessagesParams): Promise<BatchMessagesResponse>;
|
|
194
|
+
/**
|
|
195
|
+
* Connection state over time for many agents in one request: per-agent
|
|
196
|
+
* summaries (and segments on request) plus an optional fleet series of
|
|
197
|
+
* who was up, and who came and went, per slot. Auto-chunks `agent_id`
|
|
198
|
+
* like the other multi-agent reads; every chunk shares the window, so
|
|
199
|
+
* their buckets line up and are summed.
|
|
200
|
+
*/
|
|
201
|
+
getMultiAgentConnectionHistory(params: ConnectionHistoryParams): Promise<ConnectionHistoryResponse>;
|
|
202
|
+
/**
|
|
203
|
+
* Messages stored per UTC day on a channel for many agents, with fleet
|
|
204
|
+
* totals. Cheap enough to ask for a quarter at a time. Auto-chunks
|
|
205
|
+
* `agent_id`; totals are summed across chunks.
|
|
206
|
+
*/
|
|
207
|
+
getMultiAgentMessageCounts(channelName: string, params: MultiAgentMessageCountsParams): Promise<MessageCountsResponse>;
|
|
174
208
|
/**
|
|
175
209
|
* Batch-fetch aggregates for many agents. Auto-chunks `agent_id` so each
|
|
176
210
|
* request's URL stays under CloudFront's hard 8,192-byte URL quota — each
|
|
@@ -302,3 +336,15 @@ export declare class AgentsApi {
|
|
|
302
336
|
*/
|
|
303
337
|
revokeCredential(agentId: string, credentialId: string): Promise<void>;
|
|
304
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* Combine several connection-history responses for the same window into one:
|
|
341
|
+
* agents concatenated, and each slot's counts and movers summed across the
|
|
342
|
+
* responses. Used to reassemble a chunked request, and by `MultiplexClient`
|
|
343
|
+
* to combine members.
|
|
344
|
+
*/
|
|
345
|
+
export declare function mergeConnectionHistory(responses: ConnectionHistoryResponse[]): ConnectionHistoryResponse;
|
|
346
|
+
/**
|
|
347
|
+
* Combine several message-count responses for the same window into one:
|
|
348
|
+
* agents concatenated and totals summed by day.
|
|
349
|
+
*/
|
|
350
|
+
export declare function mergeMessageCounts(responses: MessageCountsResponse[]): MessageCountsResponse;
|
package/dist/apis/agents-api.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AgentsApi = void 0;
|
|
4
|
+
exports.mergeConnectionHistory = mergeConnectionHistory;
|
|
5
|
+
exports.mergeMessageCounts = mergeMessageCounts;
|
|
4
6
|
const snowflake_js_1 = require("../utils/snowflake.js");
|
|
5
7
|
function isPlainObject(value) {
|
|
6
8
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -201,6 +203,36 @@ class AgentsApi {
|
|
|
201
203
|
merged.at_limit_agent_ids = atLimit;
|
|
202
204
|
return merged;
|
|
203
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* Connection state over time for many agents in one request: per-agent
|
|
208
|
+
* summaries (and segments on request) plus an optional fleet series of
|
|
209
|
+
* who was up, and who came and went, per slot. Auto-chunks `agent_id`
|
|
210
|
+
* like the other multi-agent reads; every chunk shares the window, so
|
|
211
|
+
* their buckets line up and are summed.
|
|
212
|
+
*/
|
|
213
|
+
async getMultiAgentConnectionHistory(params) {
|
|
214
|
+
const path = "/agents/connection_history";
|
|
215
|
+
const { agent_id, ...rest } = params;
|
|
216
|
+
if (agent_id.length <= MULTI_AGENT_CHUNK_SIZE) {
|
|
217
|
+
return this.rest.get(path, params);
|
|
218
|
+
}
|
|
219
|
+
const responses = await Promise.all(chunkAgentIds(agent_id).map((chunk) => this.rest.get(path, { ...rest, agent_id: chunk })));
|
|
220
|
+
return mergeConnectionHistory(responses);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Messages stored per UTC day on a channel for many agents, with fleet
|
|
224
|
+
* totals. Cheap enough to ask for a quarter at a time. Auto-chunks
|
|
225
|
+
* `agent_id`; totals are summed across chunks.
|
|
226
|
+
*/
|
|
227
|
+
async getMultiAgentMessageCounts(channelName, params) {
|
|
228
|
+
const path = `/agents/channels/${channelName}/messages/counts`;
|
|
229
|
+
const { agent_id, ...rest } = params;
|
|
230
|
+
if (agent_id.length <= MULTI_AGENT_CHUNK_SIZE) {
|
|
231
|
+
return this.rest.get(path, params);
|
|
232
|
+
}
|
|
233
|
+
const responses = await Promise.all(chunkAgentIds(agent_id).map((chunk) => this.rest.get(path, { ...rest, agent_id: chunk })));
|
|
234
|
+
return mergeMessageCounts(responses);
|
|
235
|
+
}
|
|
204
236
|
/**
|
|
205
237
|
* Batch-fetch aggregates for many agents. Auto-chunks `agent_id` so each
|
|
206
238
|
* request's URL stays under CloudFront's hard 8,192-byte URL quota — each
|
|
@@ -215,11 +247,7 @@ class AgentsApi {
|
|
|
215
247
|
if (agent_id.length <= MULTI_AGENT_CHUNK_SIZE) {
|
|
216
248
|
return this.rest.get(path, params);
|
|
217
249
|
}
|
|
218
|
-
const
|
|
219
|
-
for (let i = 0; i < agent_id.length; i += MULTI_AGENT_CHUNK_SIZE) {
|
|
220
|
-
chunks.push(agent_id.slice(i, i + MULTI_AGENT_CHUNK_SIZE));
|
|
221
|
-
}
|
|
222
|
-
const responses = await Promise.all(chunks.map((chunk) => this.rest.get(path, {
|
|
250
|
+
const responses = await Promise.all(chunkAgentIds(agent_id).map((chunk) => this.rest.get(path, {
|
|
223
251
|
...rest,
|
|
224
252
|
agent_id: chunk,
|
|
225
253
|
})));
|
|
@@ -387,3 +415,72 @@ exports.AgentsApi = AgentsApi;
|
|
|
387
415
|
// is ~7.5KB of query string — comfortably under the cap with room for the
|
|
388
416
|
// base URL and any `field_name` params.
|
|
389
417
|
const MULTI_AGENT_CHUNK_SIZE = 250;
|
|
418
|
+
function chunkAgentIds(agentIds) {
|
|
419
|
+
const chunks = [];
|
|
420
|
+
for (let i = 0; i < agentIds.length; i += MULTI_AGENT_CHUNK_SIZE) {
|
|
421
|
+
chunks.push(agentIds.slice(i, i + MULTI_AGENT_CHUNK_SIZE));
|
|
422
|
+
}
|
|
423
|
+
return chunks;
|
|
424
|
+
}
|
|
425
|
+
function byId(a, b) {
|
|
426
|
+
return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Combine several connection-history responses for the same window into one:
|
|
430
|
+
* agents concatenated, and each slot's counts and movers summed across the
|
|
431
|
+
* responses. Used to reassemble a chunked request, and by `MultiplexClient`
|
|
432
|
+
* to combine members.
|
|
433
|
+
*/
|
|
434
|
+
function mergeConnectionHistory(responses) {
|
|
435
|
+
const first = responses[0];
|
|
436
|
+
if (!first)
|
|
437
|
+
return { start: 0, end: 0, agents: [] };
|
|
438
|
+
const agents = responses.flatMap((r) => r.agents).sort(byId);
|
|
439
|
+
const merged = { start: first.start, end: first.end, agents };
|
|
440
|
+
if (first.buckets) {
|
|
441
|
+
merged.buckets = first.buckets.map((slot, i) => {
|
|
442
|
+
const bucket = {
|
|
443
|
+
start: slot.start,
|
|
444
|
+
end: slot.end,
|
|
445
|
+
online: 0,
|
|
446
|
+
sleeping: 0,
|
|
447
|
+
offline: 0,
|
|
448
|
+
unknown: 0,
|
|
449
|
+
came_up: [],
|
|
450
|
+
went_down: [],
|
|
451
|
+
};
|
|
452
|
+
for (const r of responses) {
|
|
453
|
+
const b = r.buckets?.[i];
|
|
454
|
+
if (!b)
|
|
455
|
+
continue;
|
|
456
|
+
bucket.online += b.online;
|
|
457
|
+
bucket.sleeping += b.sleeping;
|
|
458
|
+
bucket.offline += b.offline;
|
|
459
|
+
bucket.unknown += b.unknown;
|
|
460
|
+
bucket.came_up.push(...b.came_up);
|
|
461
|
+
bucket.went_down.push(...b.went_down);
|
|
462
|
+
}
|
|
463
|
+
return bucket;
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
return merged;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Combine several message-count responses for the same window into one:
|
|
470
|
+
* agents concatenated and totals summed by day.
|
|
471
|
+
*/
|
|
472
|
+
function mergeMessageCounts(responses) {
|
|
473
|
+
const first = responses[0];
|
|
474
|
+
if (!first)
|
|
475
|
+
return { start: 0, end: 0, agents: [], totals: [] };
|
|
476
|
+
const agents = responses.flatMap((r) => r.agents).sort(byId);
|
|
477
|
+
const byDay = new Map();
|
|
478
|
+
for (const r of responses) {
|
|
479
|
+
for (const day of r.totals)
|
|
480
|
+
byDay.set(day.start, (byDay.get(day.start) ?? 0) + day.count);
|
|
481
|
+
}
|
|
482
|
+
const totals = [...byDay.entries()]
|
|
483
|
+
.sort(([a], [b]) => a - b)
|
|
484
|
+
.map(([start, count]) => ({ start, count }));
|
|
485
|
+
return { start: first.start, end: first.end, agents, totals };
|
|
486
|
+
}
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
* String-literal union (not a TS enum) so values serialise cleanly and can
|
|
7
7
|
* appear in error messages / debug UIs verbatim.
|
|
8
8
|
*/
|
|
9
|
-
export type Capability = "agents.list" | "agents.multiAgentMessages" | "agents.multiAgentAggregates" | "agents.tokenRead" | "agents.tokenManage" | "channels.list" | "channels.get" | "channels.create" | "channels.archive" | "channels.dataSeries" | "aggregates.get" | "aggregates.put" | "aggregates.patch" | "aggregates.attachment" | "messages.list" | "messages.listHistorical" | "messages.get" | "messages.post" | "messages.put" | "messages.delete" | "messages.attachment" | "messages.timeseries" | "messages.invocationLogs" | "gateway.subscribe" | "gateway.realtime" | "gateway.oneShot" | "rpc.send" | "alarms.read" | "alarms.write" | "connections.read" | "connections.write" | "notifications.read" | "notifications.write" | "permissions.read" | "permissions.write" | "processors.read" | "processors.write" | "turn.credentials" | "users.me";
|
|
9
|
+
export type Capability = "agents.list" | "agents.multiAgentMessages" | "agents.multiAgentAggregates" | "agents.multiAgentConnectionHistory" | "agents.multiAgentMessageCounts" | "agents.tokenRead" | "agents.tokenManage" | "channels.list" | "channels.get" | "channels.create" | "channels.archive" | "channels.dataSeries" | "aggregates.get" | "aggregates.put" | "aggregates.patch" | "aggregates.attachment" | "messages.list" | "messages.listHistorical" | "messages.get" | "messages.post" | "messages.put" | "messages.delete" | "messages.attachment" | "messages.timeseries" | "messages.invocationLogs" | "gateway.subscribe" | "gateway.realtime" | "gateway.oneShot" | "rpc.send" | "alarms.read" | "alarms.write" | "connections.read" | "connections.write" | "notifications.read" | "notifications.write" | "permissions.read" | "permissions.write" | "processors.read" | "processors.write" | "turn.credentials" | "users.me";
|
|
10
10
|
export declare const ALL_CAPABILITIES: readonly Capability[];
|
|
@@ -183,6 +183,8 @@ const METHOD_TO_CAPABILITY = {
|
|
|
183
183
|
"agents.listAgents": "agents.list",
|
|
184
184
|
"agents.getMultiAgentMessages": "agents.multiAgentMessages",
|
|
185
185
|
"agents.getMultiAgentAggregates": "agents.multiAgentAggregates",
|
|
186
|
+
"agents.getMultiAgentConnectionHistory": "agents.multiAgentConnectionHistory",
|
|
187
|
+
"agents.getMultiAgentMessageCounts": "agents.multiAgentMessageCounts",
|
|
186
188
|
"agents.getTokenState": "agents.tokenRead",
|
|
187
189
|
"agents.setTokenPolicy": "agents.tokenManage",
|
|
188
190
|
"agents.setAuthLock": "agents.tokenManage",
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MultiplexClient = void 0;
|
|
4
4
|
const multiplex_merge_js_1 = require("./multiplex-merge.js");
|
|
5
|
+
const agents_api_js_1 = require("../apis/agents-api.js");
|
|
5
6
|
const batch_js_1 = require("../types/batch.js");
|
|
6
7
|
const errors_js_1 = require("./errors.js");
|
|
7
8
|
const snowflake_js_1 = require("../utils/snowflake.js");
|
|
@@ -664,6 +665,28 @@ class MultiplexClient {
|
|
|
664
665
|
const merged = (0, multiplex_merge_js_1.dedupeBy)([].concat(...responses.map((r) => r.results)), (a) => a.agent_id);
|
|
665
666
|
return { results: merged, count: merged.length };
|
|
666
667
|
},
|
|
668
|
+
async getMultiAgentConnectionHistory(...rawArgs) {
|
|
669
|
+
const { args, sources } = self.splitSourcesOption(rawArgs);
|
|
670
|
+
self.assertSomeMemberSupports("agents.multiAgentConnectionHistory");
|
|
671
|
+
let members = self.enabledClients().filter(({ client }) => client.supports("agents.multiAgentConnectionHistory"));
|
|
672
|
+
if (sources) {
|
|
673
|
+
const allow = new Set(sources);
|
|
674
|
+
members = members.filter((m) => allow.has(m.id));
|
|
675
|
+
}
|
|
676
|
+
const responses = await Promise.all(members.map((m) => m.client.agents.getMultiAgentConnectionHistory(...args)));
|
|
677
|
+
return (0, agents_api_js_1.mergeConnectionHistory)(responses);
|
|
678
|
+
},
|
|
679
|
+
async getMultiAgentMessageCounts(channelName, ...rest) {
|
|
680
|
+
const { args, sources } = self.splitSourcesOption([channelName, ...rest]);
|
|
681
|
+
self.assertSomeMemberSupports("agents.multiAgentMessageCounts");
|
|
682
|
+
let members = self.enabledClients().filter(({ client }) => client.supports("agents.multiAgentMessageCounts"));
|
|
683
|
+
if (sources) {
|
|
684
|
+
const allow = new Set(sources);
|
|
685
|
+
members = members.filter((m) => allow.has(m.id));
|
|
686
|
+
}
|
|
687
|
+
const responses = await Promise.all(members.map((m) => m.client.agents.getMultiAgentMessageCounts(...args)));
|
|
688
|
+
return (0, agents_api_js_1.mergeMessageCounts)(responses);
|
|
689
|
+
},
|
|
667
690
|
getTokenState: self.makeFanoutFirst("agents.getTokenState", "agents.tokenRead"),
|
|
668
691
|
setTokenPolicy: self.routedWrite("agents.setTokenPolicy", "agents.tokenManage"),
|
|
669
692
|
setAuthLock: self.routedWrite("agents.setAuthLock", "agents.tokenManage"),
|
|
@@ -174,6 +174,30 @@ class OfflineDataClient {
|
|
|
174
174
|
request,
|
|
175
175
|
});
|
|
176
176
|
}),
|
|
177
|
+
getMultiAgentConnectionHistory: ((...rawArgs) => {
|
|
178
|
+
const { args, request } = (0, request_options_js_1.splitRequestOptions)(rawArgs);
|
|
179
|
+
const params = args[0];
|
|
180
|
+
return this.readCached(() => target.getMultiAgentConnectionHistory(...this.withDelegateOptions(args, request)), {
|
|
181
|
+
operation: "agents.getMultiAgentConnectionHistory",
|
|
182
|
+
kind: "agents.multiAgentConnectionHistory",
|
|
183
|
+
keyParts: ["agents", "multiAgentConnectionHistory", args],
|
|
184
|
+
channelName: "doover_connection",
|
|
185
|
+
agentId: params?.agent_id?.join(","),
|
|
186
|
+
request,
|
|
187
|
+
});
|
|
188
|
+
}),
|
|
189
|
+
getMultiAgentMessageCounts: ((channelName, ...rest) => {
|
|
190
|
+
const { args, request } = (0, request_options_js_1.splitRequestOptions)([channelName, ...rest]);
|
|
191
|
+
const params = args[1];
|
|
192
|
+
return this.readCached(() => target.getMultiAgentMessageCounts(...this.withDelegateOptions(args, request)), {
|
|
193
|
+
operation: "agents.getMultiAgentMessageCounts",
|
|
194
|
+
kind: "agents.multiAgentMessageCounts",
|
|
195
|
+
keyParts: ["agents", "multiAgentMessageCounts", args],
|
|
196
|
+
channelName: String(args[0]),
|
|
197
|
+
agentId: params?.agent_id?.join(","),
|
|
198
|
+
request,
|
|
199
|
+
});
|
|
200
|
+
}),
|
|
177
201
|
};
|
|
178
202
|
}
|
|
179
203
|
makeChannelsFacade() {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { AgentAggregate, BatchMessagesResponse } from "../types/openapi.js";
|
|
1
|
+
import type { AgentAggregate, BatchMessagesResponse, MessageCountsResponse } from "../types/openapi.js";
|
|
2
|
+
import type { ConnectionHistoryResponse } from "../types/connection.js";
|
|
2
3
|
import type { AgentsResponse, GetAgentsOptions } from "../types/viewer.js";
|
|
3
4
|
import type { RestClient } from "../http/rest-client.js";
|
|
4
5
|
import type { DooverRequestOptions } from "../client/request-options.js";
|
|
@@ -146,6 +147,25 @@ export interface DeviceTokenResponse {
|
|
|
146
147
|
/** Unix-ms issuance time, which is what the revocation floor compares against. */
|
|
147
148
|
issued_at_ms: number | null;
|
|
148
149
|
}
|
|
150
|
+
export interface ConnectionHistoryParams {
|
|
151
|
+
agent_id: string[];
|
|
152
|
+
/** Snowflake id bounds. Defaults to the last 7 days; at most 31 days apart. */
|
|
153
|
+
before?: string;
|
|
154
|
+
after?: string;
|
|
155
|
+
/**
|
|
156
|
+
* Slot width in ms for the fleet `buckets` series (at least 60 000, and
|
|
157
|
+
* no more than 1000 slots across the window). Omit for no buckets.
|
|
158
|
+
*/
|
|
159
|
+
bucket_ms?: number;
|
|
160
|
+
/** Include each agent's state segments. The server allows this for at most 25 agents per call. */
|
|
161
|
+
include_segments?: boolean;
|
|
162
|
+
}
|
|
163
|
+
export interface MultiAgentMessageCountsParams {
|
|
164
|
+
agent_id: string[];
|
|
165
|
+
/** Snowflake id bounds. Defaults to the last 7 days; at most 92 days apart. */
|
|
166
|
+
before?: string;
|
|
167
|
+
after?: string;
|
|
168
|
+
}
|
|
149
169
|
export interface MultiAgentAggregatesParams {
|
|
150
170
|
agent_id: string[];
|
|
151
171
|
/**
|
|
@@ -171,6 +191,20 @@ export declare class AgentsApi {
|
|
|
171
191
|
* lexically-highest cursor across at-limit agents.
|
|
172
192
|
*/
|
|
173
193
|
getMultiAgentMessages(channelName: string, params: MultiAgentMessagesParams): Promise<BatchMessagesResponse>;
|
|
194
|
+
/**
|
|
195
|
+
* Connection state over time for many agents in one request: per-agent
|
|
196
|
+
* summaries (and segments on request) plus an optional fleet series of
|
|
197
|
+
* who was up, and who came and went, per slot. Auto-chunks `agent_id`
|
|
198
|
+
* like the other multi-agent reads; every chunk shares the window, so
|
|
199
|
+
* their buckets line up and are summed.
|
|
200
|
+
*/
|
|
201
|
+
getMultiAgentConnectionHistory(params: ConnectionHistoryParams): Promise<ConnectionHistoryResponse>;
|
|
202
|
+
/**
|
|
203
|
+
* Messages stored per UTC day on a channel for many agents, with fleet
|
|
204
|
+
* totals. Cheap enough to ask for a quarter at a time. Auto-chunks
|
|
205
|
+
* `agent_id`; totals are summed across chunks.
|
|
206
|
+
*/
|
|
207
|
+
getMultiAgentMessageCounts(channelName: string, params: MultiAgentMessageCountsParams): Promise<MessageCountsResponse>;
|
|
174
208
|
/**
|
|
175
209
|
* Batch-fetch aggregates for many agents. Auto-chunks `agent_id` so each
|
|
176
210
|
* request's URL stays under CloudFront's hard 8,192-byte URL quota — each
|
|
@@ -302,3 +336,15 @@ export declare class AgentsApi {
|
|
|
302
336
|
*/
|
|
303
337
|
revokeCredential(agentId: string, credentialId: string): Promise<void>;
|
|
304
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* Combine several connection-history responses for the same window into one:
|
|
341
|
+
* agents concatenated, and each slot's counts and movers summed across the
|
|
342
|
+
* responses. Used to reassemble a chunked request, and by `MultiplexClient`
|
|
343
|
+
* to combine members.
|
|
344
|
+
*/
|
|
345
|
+
export declare function mergeConnectionHistory(responses: ConnectionHistoryResponse[]): ConnectionHistoryResponse;
|
|
346
|
+
/**
|
|
347
|
+
* Combine several message-count responses for the same window into one:
|
|
348
|
+
* agents concatenated and totals summed by day.
|
|
349
|
+
*/
|
|
350
|
+
export declare function mergeMessageCounts(responses: MessageCountsResponse[]): MessageCountsResponse;
|
|
@@ -198,6 +198,36 @@ export class AgentsApi {
|
|
|
198
198
|
merged.at_limit_agent_ids = atLimit;
|
|
199
199
|
return merged;
|
|
200
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Connection state over time for many agents in one request: per-agent
|
|
203
|
+
* summaries (and segments on request) plus an optional fleet series of
|
|
204
|
+
* who was up, and who came and went, per slot. Auto-chunks `agent_id`
|
|
205
|
+
* like the other multi-agent reads; every chunk shares the window, so
|
|
206
|
+
* their buckets line up and are summed.
|
|
207
|
+
*/
|
|
208
|
+
async getMultiAgentConnectionHistory(params) {
|
|
209
|
+
const path = "/agents/connection_history";
|
|
210
|
+
const { agent_id, ...rest } = params;
|
|
211
|
+
if (agent_id.length <= MULTI_AGENT_CHUNK_SIZE) {
|
|
212
|
+
return this.rest.get(path, params);
|
|
213
|
+
}
|
|
214
|
+
const responses = await Promise.all(chunkAgentIds(agent_id).map((chunk) => this.rest.get(path, { ...rest, agent_id: chunk })));
|
|
215
|
+
return mergeConnectionHistory(responses);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Messages stored per UTC day on a channel for many agents, with fleet
|
|
219
|
+
* totals. Cheap enough to ask for a quarter at a time. Auto-chunks
|
|
220
|
+
* `agent_id`; totals are summed across chunks.
|
|
221
|
+
*/
|
|
222
|
+
async getMultiAgentMessageCounts(channelName, params) {
|
|
223
|
+
const path = `/agents/channels/${channelName}/messages/counts`;
|
|
224
|
+
const { agent_id, ...rest } = params;
|
|
225
|
+
if (agent_id.length <= MULTI_AGENT_CHUNK_SIZE) {
|
|
226
|
+
return this.rest.get(path, params);
|
|
227
|
+
}
|
|
228
|
+
const responses = await Promise.all(chunkAgentIds(agent_id).map((chunk) => this.rest.get(path, { ...rest, agent_id: chunk })));
|
|
229
|
+
return mergeMessageCounts(responses);
|
|
230
|
+
}
|
|
201
231
|
/**
|
|
202
232
|
* Batch-fetch aggregates for many agents. Auto-chunks `agent_id` so each
|
|
203
233
|
* request's URL stays under CloudFront's hard 8,192-byte URL quota — each
|
|
@@ -212,11 +242,7 @@ export class AgentsApi {
|
|
|
212
242
|
if (agent_id.length <= MULTI_AGENT_CHUNK_SIZE) {
|
|
213
243
|
return this.rest.get(path, params);
|
|
214
244
|
}
|
|
215
|
-
const
|
|
216
|
-
for (let i = 0; i < agent_id.length; i += MULTI_AGENT_CHUNK_SIZE) {
|
|
217
|
-
chunks.push(agent_id.slice(i, i + MULTI_AGENT_CHUNK_SIZE));
|
|
218
|
-
}
|
|
219
|
-
const responses = await Promise.all(chunks.map((chunk) => this.rest.get(path, {
|
|
245
|
+
const responses = await Promise.all(chunkAgentIds(agent_id).map((chunk) => this.rest.get(path, {
|
|
220
246
|
...rest,
|
|
221
247
|
agent_id: chunk,
|
|
222
248
|
})));
|
|
@@ -383,3 +409,72 @@ export class AgentsApi {
|
|
|
383
409
|
// is ~7.5KB of query string — comfortably under the cap with room for the
|
|
384
410
|
// base URL and any `field_name` params.
|
|
385
411
|
const MULTI_AGENT_CHUNK_SIZE = 250;
|
|
412
|
+
function chunkAgentIds(agentIds) {
|
|
413
|
+
const chunks = [];
|
|
414
|
+
for (let i = 0; i < agentIds.length; i += MULTI_AGENT_CHUNK_SIZE) {
|
|
415
|
+
chunks.push(agentIds.slice(i, i + MULTI_AGENT_CHUNK_SIZE));
|
|
416
|
+
}
|
|
417
|
+
return chunks;
|
|
418
|
+
}
|
|
419
|
+
function byId(a, b) {
|
|
420
|
+
return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Combine several connection-history responses for the same window into one:
|
|
424
|
+
* agents concatenated, and each slot's counts and movers summed across the
|
|
425
|
+
* responses. Used to reassemble a chunked request, and by `MultiplexClient`
|
|
426
|
+
* to combine members.
|
|
427
|
+
*/
|
|
428
|
+
export function mergeConnectionHistory(responses) {
|
|
429
|
+
const first = responses[0];
|
|
430
|
+
if (!first)
|
|
431
|
+
return { start: 0, end: 0, agents: [] };
|
|
432
|
+
const agents = responses.flatMap((r) => r.agents).sort(byId);
|
|
433
|
+
const merged = { start: first.start, end: first.end, agents };
|
|
434
|
+
if (first.buckets) {
|
|
435
|
+
merged.buckets = first.buckets.map((slot, i) => {
|
|
436
|
+
const bucket = {
|
|
437
|
+
start: slot.start,
|
|
438
|
+
end: slot.end,
|
|
439
|
+
online: 0,
|
|
440
|
+
sleeping: 0,
|
|
441
|
+
offline: 0,
|
|
442
|
+
unknown: 0,
|
|
443
|
+
came_up: [],
|
|
444
|
+
went_down: [],
|
|
445
|
+
};
|
|
446
|
+
for (const r of responses) {
|
|
447
|
+
const b = r.buckets?.[i];
|
|
448
|
+
if (!b)
|
|
449
|
+
continue;
|
|
450
|
+
bucket.online += b.online;
|
|
451
|
+
bucket.sleeping += b.sleeping;
|
|
452
|
+
bucket.offline += b.offline;
|
|
453
|
+
bucket.unknown += b.unknown;
|
|
454
|
+
bucket.came_up.push(...b.came_up);
|
|
455
|
+
bucket.went_down.push(...b.went_down);
|
|
456
|
+
}
|
|
457
|
+
return bucket;
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
return merged;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Combine several message-count responses for the same window into one:
|
|
464
|
+
* agents concatenated and totals summed by day.
|
|
465
|
+
*/
|
|
466
|
+
export function mergeMessageCounts(responses) {
|
|
467
|
+
const first = responses[0];
|
|
468
|
+
if (!first)
|
|
469
|
+
return { start: 0, end: 0, agents: [], totals: [] };
|
|
470
|
+
const agents = responses.flatMap((r) => r.agents).sort(byId);
|
|
471
|
+
const byDay = new Map();
|
|
472
|
+
for (const r of responses) {
|
|
473
|
+
for (const day of r.totals)
|
|
474
|
+
byDay.set(day.start, (byDay.get(day.start) ?? 0) + day.count);
|
|
475
|
+
}
|
|
476
|
+
const totals = [...byDay.entries()]
|
|
477
|
+
.sort(([a], [b]) => a - b)
|
|
478
|
+
.map(([start, count]) => ({ start, count }));
|
|
479
|
+
return { start: first.start, end: first.end, agents, totals };
|
|
480
|
+
}
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
* String-literal union (not a TS enum) so values serialise cleanly and can
|
|
7
7
|
* appear in error messages / debug UIs verbatim.
|
|
8
8
|
*/
|
|
9
|
-
export type Capability = "agents.list" | "agents.multiAgentMessages" | "agents.multiAgentAggregates" | "agents.tokenRead" | "agents.tokenManage" | "channels.list" | "channels.get" | "channels.create" | "channels.archive" | "channels.dataSeries" | "aggregates.get" | "aggregates.put" | "aggregates.patch" | "aggregates.attachment" | "messages.list" | "messages.listHistorical" | "messages.get" | "messages.post" | "messages.put" | "messages.delete" | "messages.attachment" | "messages.timeseries" | "messages.invocationLogs" | "gateway.subscribe" | "gateway.realtime" | "gateway.oneShot" | "rpc.send" | "alarms.read" | "alarms.write" | "connections.read" | "connections.write" | "notifications.read" | "notifications.write" | "permissions.read" | "permissions.write" | "processors.read" | "processors.write" | "turn.credentials" | "users.me";
|
|
9
|
+
export type Capability = "agents.list" | "agents.multiAgentMessages" | "agents.multiAgentAggregates" | "agents.multiAgentConnectionHistory" | "agents.multiAgentMessageCounts" | "agents.tokenRead" | "agents.tokenManage" | "channels.list" | "channels.get" | "channels.create" | "channels.archive" | "channels.dataSeries" | "aggregates.get" | "aggregates.put" | "aggregates.patch" | "aggregates.attachment" | "messages.list" | "messages.listHistorical" | "messages.get" | "messages.post" | "messages.put" | "messages.delete" | "messages.attachment" | "messages.timeseries" | "messages.invocationLogs" | "gateway.subscribe" | "gateway.realtime" | "gateway.oneShot" | "rpc.send" | "alarms.read" | "alarms.write" | "connections.read" | "connections.write" | "notifications.read" | "notifications.write" | "permissions.read" | "permissions.write" | "processors.read" | "processors.write" | "turn.credentials" | "users.me";
|
|
10
10
|
export declare const ALL_CAPABILITIES: readonly Capability[];
|
|
@@ -179,6 +179,8 @@ const METHOD_TO_CAPABILITY = {
|
|
|
179
179
|
"agents.listAgents": "agents.list",
|
|
180
180
|
"agents.getMultiAgentMessages": "agents.multiAgentMessages",
|
|
181
181
|
"agents.getMultiAgentAggregates": "agents.multiAgentAggregates",
|
|
182
|
+
"agents.getMultiAgentConnectionHistory": "agents.multiAgentConnectionHistory",
|
|
183
|
+
"agents.getMultiAgentMessageCounts": "agents.multiAgentMessageCounts",
|
|
182
184
|
"agents.getTokenState": "agents.tokenRead",
|
|
183
185
|
"agents.setTokenPolicy": "agents.tokenManage",
|
|
184
186
|
"agents.setAuthLock": "agents.tokenManage",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { dedupeBy, mergeMessages } from "./multiplex-merge.js";
|
|
2
|
+
import { mergeConnectionHistory, mergeMessageCounts } from "../apis/agents-api.js";
|
|
2
3
|
import { mergeBatchResponses } from "../types/batch.js";
|
|
3
4
|
import { UnsupportedCapabilityError, AmbiguousWriteError } from "./errors.js";
|
|
4
5
|
import { extractSnowflakeId } from "../utils/snowflake.js";
|
|
@@ -661,6 +662,28 @@ export class MultiplexClient {
|
|
|
661
662
|
const merged = dedupeBy([].concat(...responses.map((r) => r.results)), (a) => a.agent_id);
|
|
662
663
|
return { results: merged, count: merged.length };
|
|
663
664
|
},
|
|
665
|
+
async getMultiAgentConnectionHistory(...rawArgs) {
|
|
666
|
+
const { args, sources } = self.splitSourcesOption(rawArgs);
|
|
667
|
+
self.assertSomeMemberSupports("agents.multiAgentConnectionHistory");
|
|
668
|
+
let members = self.enabledClients().filter(({ client }) => client.supports("agents.multiAgentConnectionHistory"));
|
|
669
|
+
if (sources) {
|
|
670
|
+
const allow = new Set(sources);
|
|
671
|
+
members = members.filter((m) => allow.has(m.id));
|
|
672
|
+
}
|
|
673
|
+
const responses = await Promise.all(members.map((m) => m.client.agents.getMultiAgentConnectionHistory(...args)));
|
|
674
|
+
return mergeConnectionHistory(responses);
|
|
675
|
+
},
|
|
676
|
+
async getMultiAgentMessageCounts(channelName, ...rest) {
|
|
677
|
+
const { args, sources } = self.splitSourcesOption([channelName, ...rest]);
|
|
678
|
+
self.assertSomeMemberSupports("agents.multiAgentMessageCounts");
|
|
679
|
+
let members = self.enabledClients().filter(({ client }) => client.supports("agents.multiAgentMessageCounts"));
|
|
680
|
+
if (sources) {
|
|
681
|
+
const allow = new Set(sources);
|
|
682
|
+
members = members.filter((m) => allow.has(m.id));
|
|
683
|
+
}
|
|
684
|
+
const responses = await Promise.all(members.map((m) => m.client.agents.getMultiAgentMessageCounts(...args)));
|
|
685
|
+
return mergeMessageCounts(responses);
|
|
686
|
+
},
|
|
664
687
|
getTokenState: self.makeFanoutFirst("agents.getTokenState", "agents.tokenRead"),
|
|
665
688
|
setTokenPolicy: self.routedWrite("agents.setTokenPolicy", "agents.tokenManage"),
|
|
666
689
|
setAuthLock: self.routedWrite("agents.setAuthLock", "agents.tokenManage"),
|
|
@@ -170,6 +170,30 @@ export class OfflineDataClient {
|
|
|
170
170
|
request,
|
|
171
171
|
});
|
|
172
172
|
}),
|
|
173
|
+
getMultiAgentConnectionHistory: ((...rawArgs) => {
|
|
174
|
+
const { args, request } = splitRequestOptions(rawArgs);
|
|
175
|
+
const params = args[0];
|
|
176
|
+
return this.readCached(() => target.getMultiAgentConnectionHistory(...this.withDelegateOptions(args, request)), {
|
|
177
|
+
operation: "agents.getMultiAgentConnectionHistory",
|
|
178
|
+
kind: "agents.multiAgentConnectionHistory",
|
|
179
|
+
keyParts: ["agents", "multiAgentConnectionHistory", args],
|
|
180
|
+
channelName: "doover_connection",
|
|
181
|
+
agentId: params?.agent_id?.join(","),
|
|
182
|
+
request,
|
|
183
|
+
});
|
|
184
|
+
}),
|
|
185
|
+
getMultiAgentMessageCounts: ((channelName, ...rest) => {
|
|
186
|
+
const { args, request } = splitRequestOptions([channelName, ...rest]);
|
|
187
|
+
const params = args[1];
|
|
188
|
+
return this.readCached(() => target.getMultiAgentMessageCounts(...this.withDelegateOptions(args, request)), {
|
|
189
|
+
operation: "agents.getMultiAgentMessageCounts",
|
|
190
|
+
kind: "agents.multiAgentMessageCounts",
|
|
191
|
+
keyParts: ["agents", "multiAgentMessageCounts", args],
|
|
192
|
+
channelName: String(args[0]),
|
|
193
|
+
agentId: params?.agent_id?.join(","),
|
|
194
|
+
request,
|
|
195
|
+
});
|
|
196
|
+
}),
|
|
173
197
|
};
|
|
174
198
|
}
|
|
175
199
|
makeChannelsFacade() {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DooverGatewayError } from "../http/errors.js";
|
|
2
2
|
import { addTimestampToMessage } from "../utils/snowflake.js";
|
|
3
|
+
import { viewAsSession } from "../utils/view-as.js";
|
|
3
4
|
const RECONNECT_BASE_MS = 1000;
|
|
4
5
|
const RECONNECT_CAP_MS = 30000;
|
|
5
6
|
/** Schemes a WebSocket can be opened on — it maps http(s) to ws(s) itself. */
|
|
@@ -132,6 +133,13 @@ export class GatewayClient {
|
|
|
132
133
|
const wsParams = this.auth
|
|
133
134
|
? await this.auth.prepareWebSocket(this.config.dataWssUrl, hasFactory)
|
|
134
135
|
: { url: this.config.dataWssUrl };
|
|
136
|
+
// A browser WebSocket can't send headers, so the session goes in the URL.
|
|
137
|
+
const viewAs = viewAsSession();
|
|
138
|
+
if (viewAs) {
|
|
139
|
+
const url = new URL(wsParams.url);
|
|
140
|
+
url.searchParams.set("view_as", viewAs);
|
|
141
|
+
wsParams.url = url.toString();
|
|
142
|
+
}
|
|
135
143
|
let socket;
|
|
136
144
|
if (this.config.webSocketFactory) {
|
|
137
145
|
socket = this.config.webSocketFactory({
|
|
@@ -40,6 +40,10 @@ export interface RequestOptions {
|
|
|
40
40
|
body?: BodyInit | object | null;
|
|
41
41
|
headers?: HeadersInit;
|
|
42
42
|
omitSharingHeader?: boolean;
|
|
43
|
+
omitOrganisationHeader?: boolean;
|
|
44
|
+
/** Read a successful response as this, whatever its content type. */
|
|
45
|
+
responseType?: "blob" | "text";
|
|
46
|
+
signal?: AbortSignal;
|
|
43
47
|
}
|
|
44
48
|
type QueryValue = string | number | boolean | null | undefined | Array<string | number | boolean>;
|
|
45
49
|
type QueryParams = Record<string, QueryValue> | object;
|