doover-js 0.17.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.
Files changed (36) hide show
  1. package/dist/apis/agents-api.d.ts +47 -1
  2. package/dist/apis/agents-api.js +102 -5
  3. package/dist/client/capabilities.d.ts +1 -1
  4. package/dist/client/capabilities.js +2 -0
  5. package/dist/client/local-agent-client.js +2 -0
  6. package/dist/client/multiplex-client.js +23 -0
  7. package/dist/client/offline-cache.js +24 -0
  8. package/dist/esm/apis/agents-api.d.ts +47 -1
  9. package/dist/esm/apis/agents-api.js +100 -5
  10. package/dist/esm/client/capabilities.d.ts +1 -1
  11. package/dist/esm/client/capabilities.js +2 -0
  12. package/dist/esm/client/local-agent-client.js +2 -0
  13. package/dist/esm/client/multiplex-client.js +23 -0
  14. package/dist/esm/client/offline-cache.js +24 -0
  15. package/dist/esm/index.d.ts +2 -1
  16. package/dist/esm/index.js +1 -0
  17. package/dist/esm/package.json +1 -1
  18. package/dist/esm/react/index.d.ts +4 -0
  19. package/dist/esm/react/index.js +2 -0
  20. package/dist/esm/react/useMultiAgentConnectionHistory.d.ts +35 -0
  21. package/dist/esm/react/useMultiAgentConnectionHistory.js +49 -0
  22. package/dist/esm/react/useMultiAgentMessageCounts.d.ts +25 -0
  23. package/dist/esm/react/useMultiAgentMessageCounts.js +40 -0
  24. package/dist/esm/types/connection.d.ts +48 -0
  25. package/dist/esm/types/openapi.d.ts +25 -0
  26. package/dist/index.d.ts +2 -1
  27. package/dist/index.js +5 -2
  28. package/dist/react/index.d.ts +4 -0
  29. package/dist/react/index.js +8 -1
  30. package/dist/react/useMultiAgentConnectionHistory.d.ts +35 -0
  31. package/dist/react/useMultiAgentConnectionHistory.js +53 -0
  32. package/dist/react/useMultiAgentMessageCounts.d.ts +25 -0
  33. package/dist/react/useMultiAgentMessageCounts.js +44 -0
  34. package/dist/types/connection.d.ts +48 -0
  35. package/dist/types/openapi.d.ts +25 -0
  36. 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;
@@ -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 chunks = [];
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[];
@@ -5,6 +5,8 @@ exports.ALL_CAPABILITIES = [
5
5
  "agents.list",
6
6
  "agents.multiAgentMessages",
7
7
  "agents.multiAgentAggregates",
8
+ "agents.multiAgentConnectionHistory",
9
+ "agents.multiAgentMessageCounts",
8
10
  "agents.tokenRead",
9
11
  "agents.tokenManage",
10
12
  "channels.list",
@@ -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 chunks = [];
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[];
@@ -2,6 +2,8 @@ export const ALL_CAPABILITIES = [
2
2
  "agents.list",
3
3
  "agents.multiAgentMessages",
4
4
  "agents.multiAgentAggregates",
5
+ "agents.multiAgentConnectionHistory",
6
+ "agents.multiAgentMessageCounts",
5
7
  "agents.tokenRead",
6
8
  "agents.tokenManage",
7
9
  "channels.list",
@@ -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() {
@@ -8,7 +8,8 @@ export { DooverStatsCollector } from "./client/stats.js";
8
8
  export type { DooverStatsSnapshot, RestStatsSnapshot, GatewayStatsSnapshot, } from "./client/stats.js";
9
9
  export { AgentsApi } from "./apis/agents-api.js";
10
10
  export { policyAllows } from "./utils/policy.js";
11
- export type { AgentTokenState, AgentTokenPolicy, TokenPolicyField, AdhocTokenResponse, DeviceTokenResponse, ResourcePermission, AgentCredential, CreatedCredential, CredentialKind, KeyRestriction, KeyPolicy, } from "./apis/agents-api.js";
11
+ export { mergeConnectionHistory, mergeMessageCounts } from "./apis/agents-api.js";
12
+ export type { ConnectionHistoryParams, MultiAgentMessageCountsParams, AgentTokenState, AgentTokenPolicy, TokenPolicyField, AdhocTokenResponse, DeviceTokenResponse, ResourcePermission, AgentCredential, CreatedCredential, CredentialKind, KeyRestriction, KeyPolicy, } from "./apis/agents-api.js";
12
13
  export { AggregatesApi } from "./apis/aggregates-api.js";
13
14
  export { AlarmsApi } from "./apis/alarms-api.js";
14
15
  export { ChannelsApi } from "./apis/channels-api.js";
package/dist/esm/index.js CHANGED
@@ -5,6 +5,7 @@ export { getDooverClient, peekDooverClient, resetDooverClient, } from "./client/
5
5
  export { DooverStatsCollector } from "./client/stats.js";
6
6
  export { AgentsApi } from "./apis/agents-api.js";
7
7
  export { policyAllows } from "./utils/policy.js";
8
+ export { mergeConnectionHistory, mergeMessageCounts } from "./apis/agents-api.js";
8
9
  export { AggregatesApi } from "./apis/aggregates-api.js";
9
10
  export { AlarmsApi } from "./apis/alarms-api.js";
10
11
  export { ChannelsApi } from "./apis/channels-api.js";
@@ -1 +1 @@
1
- {"name":"doover-js","version":"0.17.0","type":"module","sideEffects":false}
1
+ {"name":"doover-js","version":"0.18.0","type":"module","sideEffects":false}
@@ -38,3 +38,7 @@ export type { UseAgentTokenStateOptions } from "./useAgentTokenState.js";
38
38
  export { useAgentCredentials, useOrganisationCredentials, organisationCredentialsQueryKey, useCreateApiKey, useAddDeviceKey, useCreateEnrolmentCode, useRevokeCredential, agentCredentialsQueryKey, } from "./useAgentCredentials.js";
39
39
  export { getSharedQueryClient, resetSharedQueryClient, } from "./sharedQueryClient.js";
40
40
  export { useServiceReachability } from "./useServiceReachability.js";
41
+ export { useMultiAgentConnectionHistory, multiAgentConnectionHistoryQueryKey, } from "./useMultiAgentConnectionHistory.js";
42
+ export type { UseMultiAgentConnectionHistoryOptions, UseMultiAgentConnectionHistoryResult, } from "./useMultiAgentConnectionHistory.js";
43
+ export { useMultiAgentMessageCounts, multiAgentMessageCountsQueryKey, } from "./useMultiAgentMessageCounts.js";
44
+ export type { UseMultiAgentMessageCountsOptions, UseMultiAgentMessageCountsResult, } from "./useMultiAgentMessageCounts.js";
@@ -21,3 +21,5 @@ export { useAgentTokenState, useSetAgentTokenPolicy, useSetAgentAuthLock, useRev
21
21
  export { useAgentCredentials, useOrganisationCredentials, organisationCredentialsQueryKey, useCreateApiKey, useAddDeviceKey, useCreateEnrolmentCode, useRevokeCredential, agentCredentialsQueryKey, } from "./useAgentCredentials.js";
22
22
  export { getSharedQueryClient, resetSharedQueryClient, } from "./sharedQueryClient.js";
23
23
  export { useServiceReachability } from "./useServiceReachability.js";
24
+ export { useMultiAgentConnectionHistory, multiAgentConnectionHistoryQueryKey, } from "./useMultiAgentConnectionHistory.js";
25
+ export { useMultiAgentMessageCounts, multiAgentMessageCountsQueryKey, } from "./useMultiAgentMessageCounts.js";
@@ -0,0 +1,35 @@
1
+ import { type UseQueryResult } from "@tanstack/react-query";
2
+ import type { AgentConnectionHistory, ConnectionHistoryResponse } from "../types/connection.js";
3
+ export interface UseMultiAgentConnectionHistoryOptions {
4
+ /** Snowflake id bounds. Defaults to the last 7 days; at most 31 days apart. */
5
+ before?: string;
6
+ after?: string;
7
+ /** Slot width in ms for the fleet `buckets` series. Omit for no buckets. */
8
+ bucketMs?: number;
9
+ /** Include each agent's state segments (at most 25 agents per call). */
10
+ includeSegments?: boolean;
11
+ /** Defaults true; the query also waits for a non-empty `agentIds`. */
12
+ enabled?: boolean;
13
+ }
14
+ export declare function multiAgentConnectionHistoryQueryKey(agentIds: string[], options?: UseMultiAgentConnectionHistoryOptions): readonly ["doover", "connection_history", string, {
15
+ readonly before: string | null;
16
+ readonly after: string | null;
17
+ readonly bucket_ms: number | null;
18
+ readonly include_segments: boolean;
19
+ }];
20
+ export interface UseMultiAgentConnectionHistoryResult {
21
+ history: ConnectionHistoryResponse | undefined;
22
+ /** Keyed by agent id for O(1) lookup. */
23
+ agentsById: Record<string, AgentConnectionHistory>;
24
+ query: UseQueryResult<ConnectionHistoryResponse>;
25
+ }
26
+ /**
27
+ * Connection state over time for a set of agents, in one request:
28
+ * per-agent summaries (and segments on request) plus an optional fleet
29
+ * series per slot. The window is part of the key, so callers that want a
30
+ * stable cache across remounts should snap `before` to a grid rather than
31
+ * pass a fresh "now" each render. Never stale on its own: history does
32
+ * not change, and the trailing edge moves only as far as the caller's
33
+ * `before` does.
34
+ */
35
+ export declare function useMultiAgentConnectionHistory(agentIds: string[], options?: UseMultiAgentConnectionHistoryOptions): UseMultiAgentConnectionHistoryResult;
@@ -0,0 +1,49 @@
1
+ import { useMemo } from "react";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { useDooverClient } from "./context.js";
4
+ export function multiAgentConnectionHistoryQueryKey(agentIds, options) {
5
+ return [
6
+ "doover",
7
+ "connection_history",
8
+ [...agentIds].sort().join(","),
9
+ {
10
+ before: options?.before ?? null,
11
+ after: options?.after ?? null,
12
+ bucket_ms: options?.bucketMs ?? null,
13
+ include_segments: options?.includeSegments ?? false,
14
+ },
15
+ ];
16
+ }
17
+ /**
18
+ * Connection state over time for a set of agents, in one request:
19
+ * per-agent summaries (and segments on request) plus an optional fleet
20
+ * series per slot. The window is part of the key, so callers that want a
21
+ * stable cache across remounts should snap `before` to a grid rather than
22
+ * pass a fresh "now" each render. Never stale on its own: history does
23
+ * not change, and the trailing edge moves only as far as the caller's
24
+ * `before` does.
25
+ */
26
+ export function useMultiAgentConnectionHistory(agentIds, options) {
27
+ const client = useDooverClient();
28
+ const key = multiAgentConnectionHistoryQueryKey(agentIds, options);
29
+ const enabled = (options?.enabled ?? true) && agentIds.length > 0;
30
+ const query = useQuery({
31
+ queryKey: key,
32
+ enabled,
33
+ staleTime: Infinity,
34
+ queryFn: () => client.agents.getMultiAgentConnectionHistory({
35
+ agent_id: agentIds,
36
+ ...(options?.before !== undefined ? { before: options.before } : {}),
37
+ ...(options?.after !== undefined ? { after: options.after } : {}),
38
+ ...(options?.bucketMs !== undefined ? { bucket_ms: options.bucketMs } : {}),
39
+ ...(options?.includeSegments ? { include_segments: true } : {}),
40
+ }),
41
+ });
42
+ const agentsById = useMemo(() => {
43
+ const map = {};
44
+ for (const agent of query.data?.agents ?? [])
45
+ map[agent.id] = agent;
46
+ return map;
47
+ }, [query.data]);
48
+ return { history: query.data, agentsById, query };
49
+ }
@@ -0,0 +1,25 @@
1
+ import { type UseQueryResult } from "@tanstack/react-query";
2
+ import type { DayCount, MessageCountsResponse } from "../types/openapi.js";
3
+ export interface UseMultiAgentMessageCountsOptions {
4
+ /** Snowflake id bounds. Defaults to the last 7 days; at most 92 days apart. */
5
+ before?: string;
6
+ after?: string;
7
+ /** Defaults true; the query also waits for a non-empty `agentIds`. */
8
+ enabled?: boolean;
9
+ }
10
+ export declare function multiAgentMessageCountsQueryKey(channelName: string, agentIds: string[], options?: UseMultiAgentMessageCountsOptions): readonly ["doover", "channel", string, "message_counts", string, {
11
+ readonly before: string | null;
12
+ readonly after: string | null;
13
+ }];
14
+ export interface UseMultiAgentMessageCountsResult {
15
+ counts: MessageCountsResponse | undefined;
16
+ /** Each agent's days, keyed by agent id. */
17
+ daysByAgent: Record<string, DayCount[]>;
18
+ query: UseQueryResult<MessageCountsResponse>;
19
+ }
20
+ /**
21
+ * Messages stored per UTC day on a channel for a set of agents, with fleet
22
+ * totals. Cheap enough for a quarter of a fleet; the window is part of
23
+ * the key, so snap `before` to a grid for a cache that survives remounts.
24
+ */
25
+ export declare function useMultiAgentMessageCounts(channelName: string, agentIds: string[], options?: UseMultiAgentMessageCountsOptions): UseMultiAgentMessageCountsResult;
@@ -0,0 +1,40 @@
1
+ import { useMemo } from "react";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { useDooverClient } from "./context.js";
4
+ export function multiAgentMessageCountsQueryKey(channelName, agentIds, options) {
5
+ return [
6
+ "doover",
7
+ "channel",
8
+ channelName,
9
+ "message_counts",
10
+ [...agentIds].sort().join(","),
11
+ { before: options?.before ?? null, after: options?.after ?? null },
12
+ ];
13
+ }
14
+ /**
15
+ * Messages stored per UTC day on a channel for a set of agents, with fleet
16
+ * totals. Cheap enough for a quarter of a fleet; the window is part of
17
+ * the key, so snap `before` to a grid for a cache that survives remounts.
18
+ */
19
+ export function useMultiAgentMessageCounts(channelName, agentIds, options) {
20
+ const client = useDooverClient();
21
+ const key = multiAgentMessageCountsQueryKey(channelName, agentIds, options);
22
+ const enabled = (options?.enabled ?? true) && agentIds.length > 0;
23
+ const query = useQuery({
24
+ queryKey: key,
25
+ enabled,
26
+ staleTime: Infinity,
27
+ queryFn: () => client.agents.getMultiAgentMessageCounts(channelName, {
28
+ agent_id: agentIds,
29
+ ...(options?.before !== undefined ? { before: options.before } : {}),
30
+ ...(options?.after !== undefined ? { after: options.after } : {}),
31
+ }),
32
+ });
33
+ const daysByAgent = useMemo(() => {
34
+ const map = {};
35
+ for (const agent of query.data?.agents ?? [])
36
+ map[agent.id] = agent.days;
37
+ return map;
38
+ }, [query.data]);
39
+ return { counts: query.data, daysByAgent, query };
40
+ }
@@ -70,3 +70,51 @@ export interface ConnectionAggregate {
70
70
  determination?: ConnectionDetermination | null;
71
71
  config?: ConnectionConfig | null;
72
72
  }
73
+ /**
74
+ * Coarse connection state over time. `Sleeping` is a `PeriodicContinuous`
75
+ * device between check-ins and counts as up; `Unknown` is before the
76
+ * agent's first message, or earlier than a truncated read reached.
77
+ */
78
+ export type ConnectionHistoryState = "Online" | "Sleeping" | "Offline" | "Unknown";
79
+ /** A stretch of one state. `start` inclusive, `end` exclusive, both epoch ms. */
80
+ export interface ConnectionSegment {
81
+ start: number;
82
+ end: number;
83
+ state: ConnectionHistoryState;
84
+ }
85
+ /** The fleet in one time slot. Counts are by the state each agent held for most of the slot. */
86
+ export interface ConnectionBucket {
87
+ /** Epoch ms, inclusive. */
88
+ start: number;
89
+ /** Epoch ms, exclusive. */
90
+ end: number;
91
+ online: number;
92
+ sleeping: number;
93
+ offline: number;
94
+ unknown: number;
95
+ /** Agents that went from down to up at least once inside the slot. */
96
+ came_up: string[];
97
+ /** Agents that went from up to down at least once inside the slot; a flapping agent is in both lists. */
98
+ went_down: string[];
99
+ }
100
+ export interface AgentConnectionHistory {
101
+ id: string;
102
+ state_at_start: ConnectionHistoryState;
103
+ state_at_end: ConnectionHistoryState;
104
+ /** Share of the known time the agent was up (online or asleep); null when nothing is known. */
105
+ uptime: number | null;
106
+ /** Some day in the window had more status changes than the server reads; its earliest stretch is unknown. */
107
+ truncated: boolean;
108
+ /** Present only when requested with `include_segments`. */
109
+ segments?: ConnectionSegment[];
110
+ }
111
+ export interface ConnectionHistoryResponse {
112
+ /** Epoch ms, inclusive. */
113
+ start: number;
114
+ /** Epoch ms, exclusive; the requested `before` clipped to now. */
115
+ end: number;
116
+ /** Sorted by id. Agents the caller cannot read are absent. */
117
+ agents: AgentConnectionHistory[];
118
+ /** Present only when requested with `bucket_ms`. */
119
+ buckets?: ConnectionBucket[];
120
+ }
@@ -33,6 +33,31 @@ export interface BatchAggregatesResponse {
33
33
  results: AgentAggregate[];
34
34
  count: number;
35
35
  }
36
+ /** Messages stored on a channel for one UTC day (`GET /agents/channels/{channel}/messages/counts`). */
37
+ export interface DayCount {
38
+ /** UTC day start, epoch ms. */
39
+ start: number;
40
+ /**
41
+ * Messages written for the day, less those deleted through the API.
42
+ * Messages expired by retention still count.
43
+ */
44
+ count: number;
45
+ }
46
+ export interface AgentMessageCounts {
47
+ id: string;
48
+ /** Oldest first; days with no messages are absent. */
49
+ days: DayCount[];
50
+ }
51
+ export interface MessageCountsResponse {
52
+ /** Epoch ms, inclusive. */
53
+ start: number;
54
+ /** Epoch ms, exclusive; the requested `before` clipped to now. */
55
+ end: number;
56
+ /** Sorted by id. Agents the caller cannot read are absent. */
57
+ agents: AgentMessageCounts[];
58
+ /** Every agent's counts summed, by day, oldest first. */
59
+ totals: DayCount[];
60
+ }
36
61
  export interface NotificationDataResponse {
37
62
  subscriptions: NotificationSubscription[];
38
63
  subscribers: NotificationSubscription[];
package/dist/index.d.ts CHANGED
@@ -8,7 +8,8 @@ export { DooverStatsCollector } from "./client/stats.js";
8
8
  export type { DooverStatsSnapshot, RestStatsSnapshot, GatewayStatsSnapshot, } from "./client/stats.js";
9
9
  export { AgentsApi } from "./apis/agents-api.js";
10
10
  export { policyAllows } from "./utils/policy.js";
11
- export type { AgentTokenState, AgentTokenPolicy, TokenPolicyField, AdhocTokenResponse, DeviceTokenResponse, ResourcePermission, AgentCredential, CreatedCredential, CredentialKind, KeyRestriction, KeyPolicy, } from "./apis/agents-api.js";
11
+ export { mergeConnectionHistory, mergeMessageCounts } from "./apis/agents-api.js";
12
+ export type { ConnectionHistoryParams, MultiAgentMessageCountsParams, AgentTokenState, AgentTokenPolicy, TokenPolicyField, AdhocTokenResponse, DeviceTokenResponse, ResourcePermission, AgentCredential, CreatedCredential, CredentialKind, KeyRestriction, KeyPolicy, } from "./apis/agents-api.js";
12
13
  export { AggregatesApi } from "./apis/aggregates-api.js";
13
14
  export { AlarmsApi } from "./apis/alarms-api.js";
14
15
  export { ChannelsApi } from "./apis/channels-api.js";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIdentifierFromPath = exports.DooverDataProvider = exports.isMfaRequiredBody = exports.DooverValidationError = exports.DooverMfaRequiredError = exports.DooverGatewayError = exports.DooverApiError = exports.RestClient = exports.GatewayClient = exports.buildAuth = exports.DooverAuthError = exports.AuthProfile = exports.DooverTokenAuth = exports.CookieAuth = exports.DooverAuth = exports.mergeBatchResponses = exports.chunkBatchItems = exports.MAX_BATCH_ITEMS = exports.splitRequestOptions = exports.isDooverRequestOptions = exports.requestOptions = exports.DEFAULT_OFFLINE_RETENTION_MS = exports.MemoryOfflineStorageAdapter = exports.OfflineDataClient = exports.DooverOfflineError = exports.AmbiguousWriteError = exports.UnsupportedCapabilityError = exports.ALL_CAPABILITIES = exports.DooverRpcError = exports.RpcDispatcher = exports.UsersApi = exports.TurnApi = exports.ProcessorsApi = exports.PermissionsApi = exports.OrganisationsApi = exports.NotificationsApi = exports.MessagesApi = exports.ConnectionsApi = exports.ChannelsApi = exports.AlarmsApi = exports.AggregatesApi = exports.policyAllows = exports.AgentsApi = exports.DooverStatsCollector = exports.resetDooverClient = exports.peekDooverClient = exports.getDooverClient = exports.MultiplexClient = exports.LocalAgentClient = exports.DooverClient = void 0;
4
- exports.createNetworkStatusStore = exports.browserNetworkStatus = exports.generateSnowflakeIdAtTime = exports.extractSnowflakeId = exports.addTimestampToMessage = exports.DV_AUDIT_CHANNEL = void 0;
3
+ exports.isMfaRequiredBody = exports.DooverValidationError = exports.DooverMfaRequiredError = exports.DooverGatewayError = exports.DooverApiError = exports.RestClient = exports.GatewayClient = exports.buildAuth = exports.DooverAuthError = exports.AuthProfile = exports.DooverTokenAuth = exports.CookieAuth = exports.DooverAuth = exports.mergeBatchResponses = exports.chunkBatchItems = exports.MAX_BATCH_ITEMS = exports.splitRequestOptions = exports.isDooverRequestOptions = exports.requestOptions = exports.DEFAULT_OFFLINE_RETENTION_MS = exports.MemoryOfflineStorageAdapter = exports.OfflineDataClient = exports.DooverOfflineError = exports.AmbiguousWriteError = exports.UnsupportedCapabilityError = exports.ALL_CAPABILITIES = exports.DooverRpcError = exports.RpcDispatcher = exports.UsersApi = exports.TurnApi = exports.ProcessorsApi = exports.PermissionsApi = exports.OrganisationsApi = exports.NotificationsApi = exports.MessagesApi = exports.ConnectionsApi = exports.ChannelsApi = exports.AlarmsApi = exports.AggregatesApi = exports.mergeMessageCounts = exports.mergeConnectionHistory = exports.policyAllows = exports.AgentsApi = exports.DooverStatsCollector = exports.resetDooverClient = exports.peekDooverClient = exports.getDooverClient = exports.MultiplexClient = exports.LocalAgentClient = exports.DooverClient = void 0;
4
+ exports.createNetworkStatusStore = exports.browserNetworkStatus = exports.generateSnowflakeIdAtTime = exports.extractSnowflakeId = exports.addTimestampToMessage = exports.DV_AUDIT_CHANNEL = exports.getIdentifierFromPath = exports.DooverDataProvider = void 0;
5
5
  var doover_client_js_1 = require("./client/doover-client.js");
6
6
  Object.defineProperty(exports, "DooverClient", { enumerable: true, get: function () { return doover_client_js_1.DooverClient; } });
7
7
  var local_agent_client_js_1 = require("./client/local-agent-client.js");
@@ -18,6 +18,9 @@ var agents_api_js_1 = require("./apis/agents-api.js");
18
18
  Object.defineProperty(exports, "AgentsApi", { enumerable: true, get: function () { return agents_api_js_1.AgentsApi; } });
19
19
  var policy_js_1 = require("./utils/policy.js");
20
20
  Object.defineProperty(exports, "policyAllows", { enumerable: true, get: function () { return policy_js_1.policyAllows; } });
21
+ var agents_api_js_2 = require("./apis/agents-api.js");
22
+ Object.defineProperty(exports, "mergeConnectionHistory", { enumerable: true, get: function () { return agents_api_js_2.mergeConnectionHistory; } });
23
+ Object.defineProperty(exports, "mergeMessageCounts", { enumerable: true, get: function () { return agents_api_js_2.mergeMessageCounts; } });
21
24
  var aggregates_api_js_1 = require("./apis/aggregates-api.js");
22
25
  Object.defineProperty(exports, "AggregatesApi", { enumerable: true, get: function () { return aggregates_api_js_1.AggregatesApi; } });
23
26
  var alarms_api_js_1 = require("./apis/alarms-api.js");
@@ -38,3 +38,7 @@ export type { UseAgentTokenStateOptions } from "./useAgentTokenState.js";
38
38
  export { useAgentCredentials, useOrganisationCredentials, organisationCredentialsQueryKey, useCreateApiKey, useAddDeviceKey, useCreateEnrolmentCode, useRevokeCredential, agentCredentialsQueryKey, } from "./useAgentCredentials.js";
39
39
  export { getSharedQueryClient, resetSharedQueryClient, } from "./sharedQueryClient.js";
40
40
  export { useServiceReachability } from "./useServiceReachability.js";
41
+ export { useMultiAgentConnectionHistory, multiAgentConnectionHistoryQueryKey, } from "./useMultiAgentConnectionHistory.js";
42
+ export type { UseMultiAgentConnectionHistoryOptions, UseMultiAgentConnectionHistoryResult, } from "./useMultiAgentConnectionHistory.js";
43
+ export { useMultiAgentMessageCounts, multiAgentMessageCountsQueryKey, } from "./useMultiAgentMessageCounts.js";
44
+ export type { UseMultiAgentMessageCountsOptions, UseMultiAgentMessageCountsResult, } from "./useMultiAgentMessageCounts.js";
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useServiceReachability = exports.resetSharedQueryClient = exports.getSharedQueryClient = exports.agentCredentialsQueryKey = exports.useRevokeCredential = exports.useCreateEnrolmentCode = exports.useAddDeviceKey = exports.useCreateApiKey = exports.organisationCredentialsQueryKey = exports.useOrganisationCredentials = exports.useAgentCredentials = exports.agentTokenStateQueryKey = exports.useCreateDeviceToken = exports.useCreateAdhocToken = exports.useSetRevocationFloor = exports.useRevokeAgentTokens = exports.useSetAgentAuthLock = exports.useSetAgentTokenPolicy = exports.useAgentTokenState = exports.useTurnCredentials = exports.useDeviceMap = exports.MULTI_AGENT_MAX_WINDOW_MS = exports.multiAgentChannelMessagesQueryKey = exports.useMultiAgentChannelMessages = exports.multiAgentAggregatesQueryKey = exports.useMultiAgentAggregates = exports.useSendRpc = exports.invocationLogsQueryKey = exports.useInvocationLogs = exports.channelMessageQueryKey = exports.useChannelMessage = exports.channelMessagesQueryKey = exports.useChannelMessages = exports.useUpdateMessage = exports.useUpdateAggregate = exports.useSendMessage = exports.useAgentChannel = exports.channelAggregateQueryKey = exports.useChannelAggregate = exports.useChannelSubscription = exports.agentConnectionsQueryKey = exports.useAgentConnections = exports.useConnectionState = exports.hasOfflineStatus = exports.useOfflineStatus = exports.useClientStatus = exports.useDooverClient = exports.DooverProvider = void 0;
3
+ exports.multiAgentConnectionHistoryQueryKey = exports.useMultiAgentConnectionHistory = exports.useServiceReachability = exports.resetSharedQueryClient = exports.getSharedQueryClient = exports.agentCredentialsQueryKey = exports.useRevokeCredential = exports.useCreateEnrolmentCode = exports.useAddDeviceKey = exports.useCreateApiKey = exports.organisationCredentialsQueryKey = exports.useOrganisationCredentials = exports.useAgentCredentials = exports.agentTokenStateQueryKey = exports.useCreateDeviceToken = exports.useCreateAdhocToken = exports.useSetRevocationFloor = exports.useRevokeAgentTokens = exports.useSetAgentAuthLock = exports.useSetAgentTokenPolicy = exports.useAgentTokenState = exports.useTurnCredentials = exports.useDeviceMap = exports.MULTI_AGENT_MAX_WINDOW_MS = exports.multiAgentChannelMessagesQueryKey = exports.useMultiAgentChannelMessages = exports.multiAgentAggregatesQueryKey = exports.useMultiAgentAggregates = exports.useSendRpc = exports.invocationLogsQueryKey = exports.useInvocationLogs = exports.channelMessageQueryKey = exports.useChannelMessage = exports.channelMessagesQueryKey = exports.useChannelMessages = exports.useUpdateMessage = exports.useUpdateAggregate = exports.useSendMessage = exports.useAgentChannel = exports.channelAggregateQueryKey = exports.useChannelAggregate = exports.useChannelSubscription = exports.agentConnectionsQueryKey = exports.useAgentConnections = exports.useConnectionState = exports.hasOfflineStatus = exports.useOfflineStatus = exports.useClientStatus = exports.useDooverClient = exports.DooverProvider = void 0;
4
+ exports.multiAgentMessageCountsQueryKey = exports.useMultiAgentMessageCounts = void 0;
4
5
  var context_js_1 = require("./context.js");
5
6
  Object.defineProperty(exports, "DooverProvider", { enumerable: true, get: function () { return context_js_1.DooverProvider; } });
6
7
  Object.defineProperty(exports, "useDooverClient", { enumerable: true, get: function () { return context_js_1.useDooverClient; } });
@@ -72,3 +73,9 @@ Object.defineProperty(exports, "getSharedQueryClient", { enumerable: true, get:
72
73
  Object.defineProperty(exports, "resetSharedQueryClient", { enumerable: true, get: function () { return sharedQueryClient_js_1.resetSharedQueryClient; } });
73
74
  var useServiceReachability_js_1 = require("./useServiceReachability.js");
74
75
  Object.defineProperty(exports, "useServiceReachability", { enumerable: true, get: function () { return useServiceReachability_js_1.useServiceReachability; } });
76
+ var useMultiAgentConnectionHistory_js_1 = require("./useMultiAgentConnectionHistory.js");
77
+ Object.defineProperty(exports, "useMultiAgentConnectionHistory", { enumerable: true, get: function () { return useMultiAgentConnectionHistory_js_1.useMultiAgentConnectionHistory; } });
78
+ Object.defineProperty(exports, "multiAgentConnectionHistoryQueryKey", { enumerable: true, get: function () { return useMultiAgentConnectionHistory_js_1.multiAgentConnectionHistoryQueryKey; } });
79
+ var useMultiAgentMessageCounts_js_1 = require("./useMultiAgentMessageCounts.js");
80
+ Object.defineProperty(exports, "useMultiAgentMessageCounts", { enumerable: true, get: function () { return useMultiAgentMessageCounts_js_1.useMultiAgentMessageCounts; } });
81
+ Object.defineProperty(exports, "multiAgentMessageCountsQueryKey", { enumerable: true, get: function () { return useMultiAgentMessageCounts_js_1.multiAgentMessageCountsQueryKey; } });
@@ -0,0 +1,35 @@
1
+ import { type UseQueryResult } from "@tanstack/react-query";
2
+ import type { AgentConnectionHistory, ConnectionHistoryResponse } from "../types/connection.js";
3
+ export interface UseMultiAgentConnectionHistoryOptions {
4
+ /** Snowflake id bounds. Defaults to the last 7 days; at most 31 days apart. */
5
+ before?: string;
6
+ after?: string;
7
+ /** Slot width in ms for the fleet `buckets` series. Omit for no buckets. */
8
+ bucketMs?: number;
9
+ /** Include each agent's state segments (at most 25 agents per call). */
10
+ includeSegments?: boolean;
11
+ /** Defaults true; the query also waits for a non-empty `agentIds`. */
12
+ enabled?: boolean;
13
+ }
14
+ export declare function multiAgentConnectionHistoryQueryKey(agentIds: string[], options?: UseMultiAgentConnectionHistoryOptions): readonly ["doover", "connection_history", string, {
15
+ readonly before: string | null;
16
+ readonly after: string | null;
17
+ readonly bucket_ms: number | null;
18
+ readonly include_segments: boolean;
19
+ }];
20
+ export interface UseMultiAgentConnectionHistoryResult {
21
+ history: ConnectionHistoryResponse | undefined;
22
+ /** Keyed by agent id for O(1) lookup. */
23
+ agentsById: Record<string, AgentConnectionHistory>;
24
+ query: UseQueryResult<ConnectionHistoryResponse>;
25
+ }
26
+ /**
27
+ * Connection state over time for a set of agents, in one request:
28
+ * per-agent summaries (and segments on request) plus an optional fleet
29
+ * series per slot. The window is part of the key, so callers that want a
30
+ * stable cache across remounts should snap `before` to a grid rather than
31
+ * pass a fresh "now" each render. Never stale on its own: history does
32
+ * not change, and the trailing edge moves only as far as the caller's
33
+ * `before` does.
34
+ */
35
+ export declare function useMultiAgentConnectionHistory(agentIds: string[], options?: UseMultiAgentConnectionHistoryOptions): UseMultiAgentConnectionHistoryResult;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.multiAgentConnectionHistoryQueryKey = multiAgentConnectionHistoryQueryKey;
4
+ exports.useMultiAgentConnectionHistory = useMultiAgentConnectionHistory;
5
+ const react_1 = require("react");
6
+ const react_query_1 = require("@tanstack/react-query");
7
+ const context_js_1 = require("./context.js");
8
+ function multiAgentConnectionHistoryQueryKey(agentIds, options) {
9
+ return [
10
+ "doover",
11
+ "connection_history",
12
+ [...agentIds].sort().join(","),
13
+ {
14
+ before: options?.before ?? null,
15
+ after: options?.after ?? null,
16
+ bucket_ms: options?.bucketMs ?? null,
17
+ include_segments: options?.includeSegments ?? false,
18
+ },
19
+ ];
20
+ }
21
+ /**
22
+ * Connection state over time for a set of agents, in one request:
23
+ * per-agent summaries (and segments on request) plus an optional fleet
24
+ * series per slot. The window is part of the key, so callers that want a
25
+ * stable cache across remounts should snap `before` to a grid rather than
26
+ * pass a fresh "now" each render. Never stale on its own: history does
27
+ * not change, and the trailing edge moves only as far as the caller's
28
+ * `before` does.
29
+ */
30
+ function useMultiAgentConnectionHistory(agentIds, options) {
31
+ const client = (0, context_js_1.useDooverClient)();
32
+ const key = multiAgentConnectionHistoryQueryKey(agentIds, options);
33
+ const enabled = (options?.enabled ?? true) && agentIds.length > 0;
34
+ const query = (0, react_query_1.useQuery)({
35
+ queryKey: key,
36
+ enabled,
37
+ staleTime: Infinity,
38
+ queryFn: () => client.agents.getMultiAgentConnectionHistory({
39
+ agent_id: agentIds,
40
+ ...(options?.before !== undefined ? { before: options.before } : {}),
41
+ ...(options?.after !== undefined ? { after: options.after } : {}),
42
+ ...(options?.bucketMs !== undefined ? { bucket_ms: options.bucketMs } : {}),
43
+ ...(options?.includeSegments ? { include_segments: true } : {}),
44
+ }),
45
+ });
46
+ const agentsById = (0, react_1.useMemo)(() => {
47
+ const map = {};
48
+ for (const agent of query.data?.agents ?? [])
49
+ map[agent.id] = agent;
50
+ return map;
51
+ }, [query.data]);
52
+ return { history: query.data, agentsById, query };
53
+ }
@@ -0,0 +1,25 @@
1
+ import { type UseQueryResult } from "@tanstack/react-query";
2
+ import type { DayCount, MessageCountsResponse } from "../types/openapi.js";
3
+ export interface UseMultiAgentMessageCountsOptions {
4
+ /** Snowflake id bounds. Defaults to the last 7 days; at most 92 days apart. */
5
+ before?: string;
6
+ after?: string;
7
+ /** Defaults true; the query also waits for a non-empty `agentIds`. */
8
+ enabled?: boolean;
9
+ }
10
+ export declare function multiAgentMessageCountsQueryKey(channelName: string, agentIds: string[], options?: UseMultiAgentMessageCountsOptions): readonly ["doover", "channel", string, "message_counts", string, {
11
+ readonly before: string | null;
12
+ readonly after: string | null;
13
+ }];
14
+ export interface UseMultiAgentMessageCountsResult {
15
+ counts: MessageCountsResponse | undefined;
16
+ /** Each agent's days, keyed by agent id. */
17
+ daysByAgent: Record<string, DayCount[]>;
18
+ query: UseQueryResult<MessageCountsResponse>;
19
+ }
20
+ /**
21
+ * Messages stored per UTC day on a channel for a set of agents, with fleet
22
+ * totals. Cheap enough for a quarter of a fleet; the window is part of
23
+ * the key, so snap `before` to a grid for a cache that survives remounts.
24
+ */
25
+ export declare function useMultiAgentMessageCounts(channelName: string, agentIds: string[], options?: UseMultiAgentMessageCountsOptions): UseMultiAgentMessageCountsResult;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.multiAgentMessageCountsQueryKey = multiAgentMessageCountsQueryKey;
4
+ exports.useMultiAgentMessageCounts = useMultiAgentMessageCounts;
5
+ const react_1 = require("react");
6
+ const react_query_1 = require("@tanstack/react-query");
7
+ const context_js_1 = require("./context.js");
8
+ function multiAgentMessageCountsQueryKey(channelName, agentIds, options) {
9
+ return [
10
+ "doover",
11
+ "channel",
12
+ channelName,
13
+ "message_counts",
14
+ [...agentIds].sort().join(","),
15
+ { before: options?.before ?? null, after: options?.after ?? null },
16
+ ];
17
+ }
18
+ /**
19
+ * Messages stored per UTC day on a channel for a set of agents, with fleet
20
+ * totals. Cheap enough for a quarter of a fleet; the window is part of
21
+ * the key, so snap `before` to a grid for a cache that survives remounts.
22
+ */
23
+ function useMultiAgentMessageCounts(channelName, agentIds, options) {
24
+ const client = (0, context_js_1.useDooverClient)();
25
+ const key = multiAgentMessageCountsQueryKey(channelName, agentIds, options);
26
+ const enabled = (options?.enabled ?? true) && agentIds.length > 0;
27
+ const query = (0, react_query_1.useQuery)({
28
+ queryKey: key,
29
+ enabled,
30
+ staleTime: Infinity,
31
+ queryFn: () => client.agents.getMultiAgentMessageCounts(channelName, {
32
+ agent_id: agentIds,
33
+ ...(options?.before !== undefined ? { before: options.before } : {}),
34
+ ...(options?.after !== undefined ? { after: options.after } : {}),
35
+ }),
36
+ });
37
+ const daysByAgent = (0, react_1.useMemo)(() => {
38
+ const map = {};
39
+ for (const agent of query.data?.agents ?? [])
40
+ map[agent.id] = agent.days;
41
+ return map;
42
+ }, [query.data]);
43
+ return { counts: query.data, daysByAgent, query };
44
+ }
@@ -70,3 +70,51 @@ export interface ConnectionAggregate {
70
70
  determination?: ConnectionDetermination | null;
71
71
  config?: ConnectionConfig | null;
72
72
  }
73
+ /**
74
+ * Coarse connection state over time. `Sleeping` is a `PeriodicContinuous`
75
+ * device between check-ins and counts as up; `Unknown` is before the
76
+ * agent's first message, or earlier than a truncated read reached.
77
+ */
78
+ export type ConnectionHistoryState = "Online" | "Sleeping" | "Offline" | "Unknown";
79
+ /** A stretch of one state. `start` inclusive, `end` exclusive, both epoch ms. */
80
+ export interface ConnectionSegment {
81
+ start: number;
82
+ end: number;
83
+ state: ConnectionHistoryState;
84
+ }
85
+ /** The fleet in one time slot. Counts are by the state each agent held for most of the slot. */
86
+ export interface ConnectionBucket {
87
+ /** Epoch ms, inclusive. */
88
+ start: number;
89
+ /** Epoch ms, exclusive. */
90
+ end: number;
91
+ online: number;
92
+ sleeping: number;
93
+ offline: number;
94
+ unknown: number;
95
+ /** Agents that went from down to up at least once inside the slot. */
96
+ came_up: string[];
97
+ /** Agents that went from up to down at least once inside the slot; a flapping agent is in both lists. */
98
+ went_down: string[];
99
+ }
100
+ export interface AgentConnectionHistory {
101
+ id: string;
102
+ state_at_start: ConnectionHistoryState;
103
+ state_at_end: ConnectionHistoryState;
104
+ /** Share of the known time the agent was up (online or asleep); null when nothing is known. */
105
+ uptime: number | null;
106
+ /** Some day in the window had more status changes than the server reads; its earliest stretch is unknown. */
107
+ truncated: boolean;
108
+ /** Present only when requested with `include_segments`. */
109
+ segments?: ConnectionSegment[];
110
+ }
111
+ export interface ConnectionHistoryResponse {
112
+ /** Epoch ms, inclusive. */
113
+ start: number;
114
+ /** Epoch ms, exclusive; the requested `before` clipped to now. */
115
+ end: number;
116
+ /** Sorted by id. Agents the caller cannot read are absent. */
117
+ agents: AgentConnectionHistory[];
118
+ /** Present only when requested with `bucket_ms`. */
119
+ buckets?: ConnectionBucket[];
120
+ }
@@ -33,6 +33,31 @@ export interface BatchAggregatesResponse {
33
33
  results: AgentAggregate[];
34
34
  count: number;
35
35
  }
36
+ /** Messages stored on a channel for one UTC day (`GET /agents/channels/{channel}/messages/counts`). */
37
+ export interface DayCount {
38
+ /** UTC day start, epoch ms. */
39
+ start: number;
40
+ /**
41
+ * Messages written for the day, less those deleted through the API.
42
+ * Messages expired by retention still count.
43
+ */
44
+ count: number;
45
+ }
46
+ export interface AgentMessageCounts {
47
+ id: string;
48
+ /** Oldest first; days with no messages are absent. */
49
+ days: DayCount[];
50
+ }
51
+ export interface MessageCountsResponse {
52
+ /** Epoch ms, inclusive. */
53
+ start: number;
54
+ /** Epoch ms, exclusive; the requested `before` clipped to now. */
55
+ end: number;
56
+ /** Sorted by id. Agents the caller cannot read are absent. */
57
+ agents: AgentMessageCounts[];
58
+ /** Every agent's counts summed, by day, oldest first. */
59
+ totals: DayCount[];
60
+ }
36
61
  export interface NotificationDataResponse {
37
62
  subscriptions: NotificationSubscription[];
38
63
  subscribers: NotificationSubscription[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doover-js",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "TypeScript client for Doover.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",