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
|
@@ -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
|
+
}
|
package/dist/types/openapi.d.ts
CHANGED
|
@@ -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[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.viewAsSession = viewAsSession;
|
|
4
|
+
/** The view-as session the app started, if any (set by the site's "View as"). */
|
|
5
|
+
function viewAsSession() {
|
|
6
|
+
if (typeof sessionStorage === "undefined")
|
|
7
|
+
return null;
|
|
8
|
+
return sessionStorage.getItem("view_as_session");
|
|
9
|
+
}
|