send-to-paseo 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,70 @@
1
+ import type { PluginHostSummary } from "@getpaseo/plugin/client";
2
+ import type { AdditionalMachine } from "../shared/contracts";
3
+
4
+ export interface DiscoveredHostRow extends PluginHostSummary {
5
+ readonly isSurfaceHost: boolean;
6
+ readonly route: AdditionalMachine | null;
7
+ }
8
+
9
+ export interface HostDiscoveryModel {
10
+ readonly hosts: readonly DiscoveredHostRow[];
11
+ /** Bridge routes retained for compatibility but absent from Paseo's configured host list. */
12
+ readonly undiscoveredRoutes: readonly AdditionalMachine[];
13
+ }
14
+
15
+ /**
16
+ * Join Paseo's live host inventory to the bridge's saved routes by serverId.
17
+ *
18
+ * Names and URLs are deliberately not fallback keys: both can change, and a
19
+ * fuzzy match here could make a later Send target the wrong daemon.
20
+ */
21
+ export function organizeDiscoveredHosts(
22
+ hosts: readonly PluginHostSummary[],
23
+ surfaceServerId: string,
24
+ routes: readonly AdditionalMachine[],
25
+ ): HostDiscoveryModel {
26
+ const routesByServerId = new Map<string, AdditionalMachine>();
27
+ for (const route of routes) {
28
+ if (route.serverId !== null && !routesByServerId.has(route.serverId)) {
29
+ routesByServerId.set(route.serverId, route);
30
+ }
31
+ }
32
+ const discoveredIds = new Set(hosts.map((host) => host.serverId));
33
+ return {
34
+ hosts: hosts.map((host) => ({
35
+ ...host,
36
+ isSurfaceHost: host.serverId === surfaceServerId,
37
+ route: routesByServerId.get(host.serverId) ?? null,
38
+ })),
39
+ undiscoveredRoutes: routes.filter(
40
+ (route) => route.serverId === null || !discoveredIds.has(route.serverId),
41
+ ),
42
+ };
43
+ }
44
+
45
+ export interface TargetedHostClient {
46
+ readonly projects: {
47
+ list(): Promise<{ projects: readonly unknown[] }>;
48
+ };
49
+ }
50
+
51
+ export type HostClientGetter = (serverId: string) => TargetedHostClient;
52
+
53
+ /**
54
+ * Perform one read through an explicitly targeted host client.
55
+ *
56
+ * The getter is called for every action instead of retaining a PaseoApi. That
57
+ * is the 0.9 lifecycle contract: a same-client reconnect remains usable, but a
58
+ * replaced connection releases the old API and the next action must reacquire
59
+ * it. Unknown and disconnected errors are intentionally allowed to escape;
60
+ * there is no selected/local-host fallback.
61
+ */
62
+ export async function checkHostAccess(
63
+ serverId: string,
64
+ getClient: HostClientGetter,
65
+ ): Promise<number> {
66
+ if (serverId.trim() === "") throw new Error("A Paseo server ID is required.");
67
+ const client = getClient(serverId);
68
+ const { projects } = await client.projects.list();
69
+ return projects.length;
70
+ }