@getmateo/protocol 0.0.0-stage → 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 (179) hide show
  1. package/LICENSE +211 -0
  2. package/README.md +11 -2
  3. package/dist/addresses.d.ts +6 -0
  4. package/dist/addresses.js +2 -0
  5. package/dist/agent-attention-notification.d.ts +57 -0
  6. package/dist/agent-attention-notification.js +177 -0
  7. package/dist/agent-deep-link.d.ts +8 -0
  8. package/dist/agent-deep-link.js +49 -0
  9. package/dist/agent-labels.d.ts +14 -0
  10. package/dist/agent-labels.js +38 -0
  11. package/dist/agent-lifecycle.d.ts +3 -0
  12. package/dist/agent-lifecycle.js +8 -0
  13. package/dist/agent-message.d.ts +20 -0
  14. package/dist/agent-message.js +12 -0
  15. package/dist/agent-profile.d.ts +31 -0
  16. package/dist/agent-profile.js +32 -0
  17. package/dist/agent-runtime-config.d.ts +4 -0
  18. package/dist/agent-runtime-config.js +5 -0
  19. package/dist/agent-shells.d.ts +25 -0
  20. package/dist/agent-shells.js +17 -0
  21. package/dist/agent-state-bucket.d.ts +15 -0
  22. package/dist/agent-state-bucket.js +41 -0
  23. package/dist/agent-title-limits.d.ts +2 -0
  24. package/dist/agent-title-limits.js +2 -0
  25. package/dist/agent-types.d.ts +484 -0
  26. package/dist/agent-types.js +33 -0
  27. package/dist/binary-frames/demux.d.ts +15 -0
  28. package/dist/binary-frames/demux.js +28 -0
  29. package/dist/binary-frames/file-transfer.d.ts +51 -0
  30. package/dist/binary-frames/file-transfer.js +108 -0
  31. package/dist/binary-frames/host-route.d.ts +13 -0
  32. package/dist/binary-frames/host-route.js +39 -0
  33. package/dist/binary-frames/index.d.ts +5 -0
  34. package/dist/binary-frames/index.js +5 -0
  35. package/dist/binary-frames/terminal.d.ts +35 -0
  36. package/dist/binary-frames/terminal.js +100 -0
  37. package/dist/branch-slug.d.ts +14 -0
  38. package/dist/branch-slug.js +49 -0
  39. package/dist/browser-automation/capabilities.d.ts +7 -0
  40. package/dist/browser-automation/capabilities.js +31 -0
  41. package/dist/browser-automation/rpc-schemas.d.ts +1224 -0
  42. package/dist/browser-automation/rpc-schemas.js +497 -0
  43. package/dist/browser-download-rules.d.ts +21 -0
  44. package/dist/browser-download-rules.js +54 -0
  45. package/dist/build-metadata.d.ts +17 -0
  46. package/dist/build-metadata.js +61 -0
  47. package/dist/chat/rpc-schemas.d.ts +158 -0
  48. package/dist/chat/rpc-schemas.js +104 -0
  49. package/dist/chat/types.d.ts +30 -0
  50. package/dist/chat/types.js +23 -0
  51. package/dist/check-traits.d.ts +11 -0
  52. package/dist/check-traits.js +10 -0
  53. package/dist/chunked-transport.d.ts +42 -0
  54. package/dist/chunked-transport.js +277 -0
  55. package/dist/client-capabilities.d.ts +24 -0
  56. package/dist/client-capabilities.js +52 -0
  57. package/dist/connection-offer.d.ts +36 -0
  58. package/dist/connection-offer.js +53 -0
  59. package/dist/daemon-auth.d.ts +548 -0
  60. package/dist/daemon-auth.js +152 -0
  61. package/dist/daemon-endpoints.d.ts +54 -0
  62. package/dist/daemon-endpoints.js +243 -0
  63. package/dist/error-utils.d.ts +11 -0
  64. package/dist/error-utils.js +27 -0
  65. package/dist/fleet.d.ts +381 -0
  66. package/dist/fleet.js +134 -0
  67. package/dist/forge-manifest.d.ts +66 -0
  68. package/dist/forge-manifest.js +92 -0
  69. package/dist/generated/validation/ws-outbound-schema-metadata.d.ts +14187 -0
  70. package/dist/generated/validation/ws-outbound-schema-metadata.js +262 -0
  71. package/dist/generated/validation/ws-outbound.aot.d.ts +520 -0
  72. package/dist/generated/validation/ws-outbound.aot.js +106677 -0
  73. package/dist/git-remote.d.ts +33 -0
  74. package/dist/git-remote.js +94 -0
  75. package/dist/gitea-status.d.ts +10 -0
  76. package/dist/gitea-status.js +23 -0
  77. package/dist/gitlab-pipeline.d.ts +10 -0
  78. package/dist/gitlab-pipeline.js +17 -0
  79. package/dist/global-terminal.d.ts +3 -0
  80. package/dist/global-terminal.js +8 -0
  81. package/dist/host-connection-schema.d.ts +11 -0
  82. package/dist/host-connection-schema.js +9 -0
  83. package/dist/host-target.d.ts +20 -0
  84. package/dist/host-target.js +137 -0
  85. package/dist/hosts.d.ts +133 -0
  86. package/dist/hosts.js +82 -0
  87. package/dist/literal-union.d.ts +2 -0
  88. package/dist/literal-union.js +2 -0
  89. package/dist/loop/rpc-schemas.d.ts +636 -0
  90. package/dist/loop/rpc-schemas.js +164 -0
  91. package/dist/mateo-config-schema.d.ts +138 -0
  92. package/dist/mateo-config-schema.js +98 -0
  93. package/dist/mateo-tool-call-detail.d.ts +2 -0
  94. package/dist/mateo-tool-call-detail.js +3 -0
  95. package/dist/mateo-tool-presentation/agent-message.d.ts +10 -0
  96. package/dist/mateo-tool-presentation/agent-message.js +23 -0
  97. package/dist/mateo-tool-presentation/catalog.d.ts +321 -0
  98. package/dist/mateo-tool-presentation/catalog.js +319 -0
  99. package/dist/mateo-tool-presentation/detail-sections.d.ts +15 -0
  100. package/dist/mateo-tool-presentation/detail-sections.js +161 -0
  101. package/dist/mateo-tool-presentation/index.d.ts +22 -0
  102. package/dist/mateo-tool-presentation/index.js +62 -0
  103. package/dist/mateo-tool-presentation/summary-text.d.ts +7 -0
  104. package/dist/mateo-tool-presentation/summary-text.js +22 -0
  105. package/dist/messages.d.ts +70260 -0
  106. package/dist/messages.js +6740 -0
  107. package/dist/path-utils.d.ts +2 -0
  108. package/dist/path-utils.js +16 -0
  109. package/dist/plugin-browser-consent-copy.d.ts +193 -0
  110. package/dist/plugin-browser-consent-copy.js +109 -0
  111. package/dist/plugin-browser-grants.d.ts +48 -0
  112. package/dist/plugin-browser-grants.js +56 -0
  113. package/dist/plugin-browser.d.ts +321 -0
  114. package/dist/plugin-browser.js +109 -0
  115. package/dist/plugin-config.d.ts +18 -0
  116. package/dist/plugin-config.js +13 -0
  117. package/dist/plugin-overview.d.ts +12 -0
  118. package/dist/plugin-overview.js +50 -0
  119. package/dist/plugin-registry.d.ts +153 -0
  120. package/dist/plugin-registry.js +83 -0
  121. package/dist/plugin-requirements.d.ts +11 -0
  122. package/dist/plugin-requirements.js +26 -0
  123. package/dist/plugin-source-reference.d.ts +11 -0
  124. package/dist/plugin-source-reference.js +68 -0
  125. package/dist/provider-config.d.ts +141 -0
  126. package/dist/provider-config.js +113 -0
  127. package/dist/provider-icon-names.d.ts +5 -0
  128. package/dist/provider-icon-names.js +54 -0
  129. package/dist/provider-manifest.d.ts +30 -0
  130. package/dist/provider-manifest.js +247 -0
  131. package/dist/provider-snapshot-codec.d.ts +18 -0
  132. package/dist/provider-snapshot-codec.js +71 -0
  133. package/dist/schedule/cadence.d.ts +6 -0
  134. package/dist/schedule/cadence.js +28 -0
  135. package/dist/schedule/cron-expression.d.ts +14 -0
  136. package/dist/schedule/cron-expression.js +107 -0
  137. package/dist/schedule/rpc-schemas.d.ts +570 -0
  138. package/dist/schedule/rpc-schemas.js +158 -0
  139. package/dist/schedule/types.d.ts +201 -0
  140. package/dist/schedule/types.js +68 -0
  141. package/dist/search/text-match.d.ts +78 -0
  142. package/dist/search/text-match.js +330 -0
  143. package/dist/service-defaults.d.ts +3 -0
  144. package/dist/service-defaults.js +5 -0
  145. package/dist/ssh-transport.d.ts +11 -0
  146. package/dist/ssh-transport.js +72 -0
  147. package/dist/terminal-activity.d.ts +21 -0
  148. package/dist/terminal-activity.js +25 -0
  149. package/dist/terminal-input-mode.d.ts +30 -0
  150. package/dist/terminal-input-mode.js +180 -0
  151. package/dist/terminal-key-input.d.ts +13 -0
  152. package/dist/terminal-key-input.js +210 -0
  153. package/dist/terminal-profile.d.ts +10 -0
  154. package/dist/terminal-profile.js +11 -0
  155. package/dist/terminal-profiles.d.ts +41 -0
  156. package/dist/terminal-profiles.js +276 -0
  157. package/dist/terminal-snapshot.d.ts +4 -0
  158. package/dist/terminal-snapshot.js +220 -0
  159. package/dist/terminal-stream-protocol.d.ts +2 -0
  160. package/dist/terminal-stream-protocol.js +2 -0
  161. package/dist/terminal-subscription-key.d.ts +2 -0
  162. package/dist/terminal-subscription-key.js +9 -0
  163. package/dist/timeline-identity.d.ts +3 -0
  164. package/dist/timeline-identity.js +8 -0
  165. package/dist/tool-call-display.d.ts +13 -0
  166. package/dist/tool-call-display.js +144 -0
  167. package/dist/tool-name-normalization.d.ts +9 -0
  168. package/dist/tool-name-normalization.js +82 -0
  169. package/dist/user-agent.d.ts +26 -0
  170. package/dist/user-agent.js +101 -0
  171. package/dist/validation/ws-outbound-envelope.d.ts +13413 -0
  172. package/dist/validation/ws-outbound-envelope.js +17 -0
  173. package/dist/validation/ws-outbound.d.ts +12 -0
  174. package/dist/validation/ws-outbound.js +38 -0
  175. package/dist/websocket-message-limit.d.ts +5 -0
  176. package/dist/websocket-message-limit.js +5 -0
  177. package/dist/workspace-labels.d.ts +9 -0
  178. package/dist/workspace-labels.js +19 -0
  179. package/package.json +48 -4
@@ -0,0 +1,152 @@
1
+ import { z } from "zod";
2
+ /** How a session reaches the host: same machine, direct network connection, relay, or Hub. */
3
+ export const DaemonAuthSessionTransportSchema = z.enum(["local", "direct", "relay", "hub"]);
4
+ /**
5
+ * What a client reports about itself so the owner can tell sessions apart. Display only; never
6
+ * used for authorization. Clients send `hello.device.name` resolved from these for older hosts,
7
+ * and newer viewers compose the name from them in their own language.
8
+ */
9
+ export const ClientDeviceDetailsSchema = z.object({
10
+ /** The name the user gave this device in the app; preferred over every automatic name. */
11
+ customName: z.string().max(256).optional(),
12
+ /**
13
+ * The name the operating system knows the device by: the computer name of a desktop or CLI
14
+ * host, or a phone's user-set name when the OS shares it.
15
+ */
16
+ computerName: z.string().max(256).optional(),
17
+ /** Hardware model, e.g. "iPhone 17 Pro". */
18
+ model: z.string().max(256).optional(),
19
+ /** Browser product name of a web client, e.g. "Chrome". */
20
+ browser: z.string().max(64).optional(),
21
+ /** Operating system product name, e.g. "iPadOS". */
22
+ os: z.string().max(64).optional(),
23
+ osVersion: z.string().max(64).optional(),
24
+ });
25
+ /** A connected client session, as shown to the owner on the Password & devices page. */
26
+ export const DaemonAuthSessionSchema = z.object({
27
+ ...ClientDeviceDetailsSchema.shape,
28
+ /**
29
+ * The last four characters of the session's client ID. The full ID resumes the session, so
30
+ * the host never lists it.
31
+ */
32
+ clientIdSuffix: z.string().optional(),
33
+ sessionId: z.string(),
34
+ clientType: z.string(),
35
+ deviceName: z.string().nullable(),
36
+ platform: z.string().nullable(),
37
+ appVersion: z.string().nullable(),
38
+ /** How the session authenticated. */
39
+ credential: z.enum(["none", "password", "localCredential", "device", "peer", "service"]),
40
+ connectedAt: z.string(),
41
+ /** The session that asked; it always stays connected. */
42
+ current: z.boolean(),
43
+ /** Stays connected without choosing: local desktop, device and service credentials. */
44
+ alwaysKept: z.boolean(),
45
+ /** The client can store a device credential, so it can be kept signed in. */
46
+ canKeep: z.boolean(),
47
+ /** Sent by hosts with `features.daemonAuthSessions`. */
48
+ transport: DaemonAuthSessionTransportSchema.optional(),
49
+ /** The peer address of a direct connection. Never set for local, relay or Hub sessions. */
50
+ remoteAddress: z.string().optional(),
51
+ /** The device credential the session connected with or was issued while connected. */
52
+ deviceCredentialId: z.string().optional(),
53
+ });
54
+ export const DaemonDeviceCredentialSummarySchema = z.object({
55
+ /** Recorded from the session the credential was issued to, by newer hosts. */
56
+ ...ClientDeviceDetailsSchema.shape,
57
+ clientType: z.string().optional(),
58
+ clientIdSuffix: z.string().optional(),
59
+ credentialId: z.string(),
60
+ deviceName: z.string().nullable(),
61
+ platform: z.string().nullable(),
62
+ createdAt: z.string(),
63
+ lastSeenAt: z.string().nullable(),
64
+ });
65
+ export const DaemonAuthStatusSchema = z.object({
66
+ passwordEnabled: z.boolean(),
67
+ /** Set when a launch environment controls the password; the app cannot change it. */
68
+ managedBy: z.enum(["environment"]).nullable(),
69
+ sessions: z.array(DaemonAuthSessionSchema),
70
+ devices: z.array(DaemonDeviceCredentialSummarySchema),
71
+ });
72
+ export const DaemonAuthStatusRequestSchema = z.object({
73
+ type: z.literal("daemon.auth.status.request"),
74
+ requestId: z.string(),
75
+ });
76
+ export const DaemonAuthPasswordSetRequestSchema = z.object({
77
+ type: z.literal("daemon.auth.password.set.request"),
78
+ requestId: z.string(),
79
+ /** Null clears the password. */
80
+ password: z.string().min(1).max(1024).nullable(),
81
+ /** Other sessions to keep signed in with a device credential. */
82
+ keepSessionIds: z.array(z.string()).max(256).optional(),
83
+ });
84
+ export const DaemonAuthDeviceRevokeRequestSchema = z.object({
85
+ type: z.literal("daemon.auth.device.revoke.request"),
86
+ requestId: z.string(),
87
+ credentialId: z.string(),
88
+ });
89
+ /** Closes another session. Refused for the caller, the local desktop, fleet peers and services. */
90
+ export const DaemonAuthSessionDisconnectRequestSchema = z.object({
91
+ type: z.literal("daemon.auth.session.disconnect.request"),
92
+ requestId: z.string(),
93
+ sessionId: z.string(),
94
+ });
95
+ /** The owner observes the status; the host pushes it again when sessions or devices change. */
96
+ export const DaemonAuthStatusSubscribeRequestSchema = z.object({
97
+ type: z.literal("daemon.auth.status.subscribe.request"),
98
+ requestId: z.string(),
99
+ });
100
+ export const DaemonAuthStatusResponseSchema = z.object({
101
+ type: z.literal("daemon.auth.status.response"),
102
+ payload: z.object({ requestId: z.string(), status: DaemonAuthStatusSchema }),
103
+ });
104
+ export const DaemonAuthPasswordSetResponseSchema = z.object({
105
+ type: z.literal("daemon.auth.password.set.response"),
106
+ payload: z.object({
107
+ requestId: z.string(),
108
+ status: DaemonAuthStatusSchema,
109
+ /** Sessions closed because they did not hold the new password or a kept credential. */
110
+ disconnected: z.number().int().nonnegative(),
111
+ }),
112
+ });
113
+ export const DaemonAuthDeviceRevokeResponseSchema = z.object({
114
+ type: z.literal("daemon.auth.device.revoke.response"),
115
+ payload: z.object({ requestId: z.string(), status: DaemonAuthStatusSchema }),
116
+ });
117
+ /** A client that can store a device credential observes this to be offered as keepable. */
118
+ export const DaemonAuthDeviceSubscribeRequestSchema = z.object({
119
+ type: z.literal("daemon.auth.device.subscribe.request"),
120
+ requestId: z.string(),
121
+ });
122
+ export const DaemonAuthDeviceSubscribeResponseSchema = z.object({
123
+ type: z.literal("daemon.auth.device.subscribe.response"),
124
+ payload: z.object({ requestId: z.string(), subscriptionId: z.string() }),
125
+ });
126
+ /** Pushed to a kept session; its client stores the credential for later connections. */
127
+ export const DaemonAuthDeviceCredentialSchema = z.object({
128
+ type: z.literal("daemon.auth.device.credential"),
129
+ payload: z.object({
130
+ subscriptionId: z.string(),
131
+ credentialId: z.string(),
132
+ credential: z.string(),
133
+ }),
134
+ });
135
+ export const DaemonAuthSessionDisconnectResponseSchema = z.object({
136
+ type: z.literal("daemon.auth.session.disconnect.response"),
137
+ payload: z.object({ requestId: z.string(), status: DaemonAuthStatusSchema }),
138
+ });
139
+ export const DaemonAuthStatusSubscribeResponseSchema = z.object({
140
+ type: z.literal("daemon.auth.status.subscribe.response"),
141
+ payload: z.object({
142
+ requestId: z.string(),
143
+ subscriptionId: z.string(),
144
+ status: DaemonAuthStatusSchema,
145
+ }),
146
+ });
147
+ /** Pushed to a status subscription after a session connects or disconnects, or devices change. */
148
+ export const DaemonAuthStatusChangedSchema = z.object({
149
+ type: z.literal("daemon.auth.status.changed"),
150
+ payload: z.object({ subscriptionId: z.string(), status: DaemonAuthStatusSchema }),
151
+ });
152
+ //# sourceMappingURL=daemon-auth.js.map
@@ -0,0 +1,54 @@
1
+ import type { ConnectionOfferV2 } from "./connection-offer.js";
2
+ export interface HostPortParts {
3
+ host: string;
4
+ port: number;
5
+ isIpv6: boolean;
6
+ }
7
+ export interface ConnectionUriParts extends HostPortParts {
8
+ useTls: boolean;
9
+ }
10
+ export interface ParsedConnectionUri extends ConnectionUriParts {
11
+ password?: string;
12
+ }
13
+ export interface ParsedRelayConnectionUri {
14
+ offer: ConnectionOfferV2;
15
+ password?: string;
16
+ }
17
+ export declare function parseRelayConnectionUri(input: string): ParsedRelayConnectionUri;
18
+ export declare function serializeRelayConnectionUri(parts: ParsedRelayConnectionUri): string;
19
+ export type RelayRole = "server" | "client";
20
+ export type RelayProtocolVersion = "1" | "2";
21
+ export declare const CURRENT_RELAY_PROTOCOL_VERSION: RelayProtocolVersion;
22
+ export { DEFAULT_RELAY_ENDPOINT } from "./service-defaults.js";
23
+ export declare function normalizeRelayProtocolVersion(value: unknown, fallback?: RelayProtocolVersion): RelayProtocolVersion;
24
+ export declare function parseHostPort(input: string): HostPortParts;
25
+ export declare function normalizeHostPort(input: string): string;
26
+ export declare function parseConnectionUri(input: string): ParsedConnectionUri;
27
+ export declare function serializeConnectionUri(parts: ConnectionUriParts): string;
28
+ export declare function serializeConnectionUriForStorage(parts: ParsedConnectionUri): string;
29
+ export declare function normalizeLoopbackToLocalhost(endpoint: string): string;
30
+ export declare function deriveLabelFromEndpoint(endpoint: string): string;
31
+ export interface WebSocketUrlOptions {
32
+ useTls: boolean;
33
+ }
34
+ export declare function buildDaemonWebSocketUrl(endpoint: string, opts: WebSocketUrlOptions): string;
35
+ export declare function buildRelayWebSocketUrl(params: {
36
+ endpoint: string;
37
+ useTls: boolean;
38
+ serverId: string;
39
+ role: RelayRole;
40
+ /**
41
+ * Per-connection routing identifier used by the daemon to open server data sockets.
42
+ * Clients should NOT provide this — the relay assigns a routing ID on connect.
43
+ */
44
+ connectionId?: string;
45
+ version?: RelayProtocolVersion | 1 | 2;
46
+ }): string;
47
+ /**
48
+ * @deprecated Migration fallback for stored relay connections/offers that predate
49
+ * explicit relay useTls. Delete after two release cycles.
50
+ */
51
+ export declare function shouldUseTlsForDefaultHostedRelay(endpoint: string): boolean;
52
+ export declare function extractHostPortFromWebSocketUrl(wsUrl: string): string;
53
+ export declare function isRelayClientWebSocketUrl(url: string): boolean;
54
+ //# sourceMappingURL=daemon-endpoints.d.ts.map
@@ -0,0 +1,243 @@
1
+ export function parseRelayConnectionUri(input) {
2
+ const trimmed = input.trim();
3
+ const connectIndex = trimmed.indexOf("#connect=");
4
+ const uri = connectIndex >= 0
5
+ ? decodeURIComponent(trimmed.slice(connectIndex + "#connect=".length))
6
+ : trimmed;
7
+ let url;
8
+ try {
9
+ url = new URL(uri);
10
+ }
11
+ catch {
12
+ throw new Error("Invalid relay connection URI");
13
+ }
14
+ if (url.protocol !== "relay:" || !url.hostname || !url.port || url.username || url.password) {
15
+ throw new Error("Invalid relay connection URI");
16
+ }
17
+ const serverId = decodeURIComponent(url.pathname.slice(1));
18
+ const key = url.searchParams.get("key");
19
+ if (!serverId || !key || serverId.includes("/")) {
20
+ throw new Error("Relay connection URI requires a server id and key");
21
+ }
22
+ const endpoint = normalizeHostPort(url.host);
23
+ const password = url.searchParams.get("password") || undefined;
24
+ return {
25
+ offer: {
26
+ v: 2,
27
+ serverId,
28
+ daemonPublicKeyB64: key,
29
+ relay: { endpoint, useTls: url.searchParams.get("ssl") === "true" },
30
+ },
31
+ ...(password ? { password } : {}),
32
+ };
33
+ }
34
+ export function serializeRelayConnectionUri(parts) {
35
+ const url = new URL(`relay://${parts.offer.relay.endpoint}/${encodeURIComponent(parts.offer.serverId)}`);
36
+ url.searchParams.set("key", parts.offer.daemonPublicKeyB64);
37
+ if (parts.offer.relay.useTls)
38
+ url.searchParams.set("ssl", "true");
39
+ if (parts.password)
40
+ url.searchParams.set("password", parts.password);
41
+ return url.toString();
42
+ }
43
+ export const CURRENT_RELAY_PROTOCOL_VERSION = "2";
44
+ export { DEFAULT_RELAY_ENDPOINT } from "./service-defaults.js";
45
+ export function normalizeRelayProtocolVersion(value, fallback = CURRENT_RELAY_PROTOCOL_VERSION) {
46
+ if (value == null) {
47
+ return fallback;
48
+ }
49
+ let normalized = "";
50
+ if (typeof value === "string") {
51
+ normalized = value.trim();
52
+ }
53
+ else if (typeof value === "number") {
54
+ normalized = String(value);
55
+ }
56
+ if (!normalized) {
57
+ return fallback;
58
+ }
59
+ if (normalized === "1" || normalized === "2") {
60
+ return normalized;
61
+ }
62
+ throw new Error('Relay version must be "1" or "2"');
63
+ }
64
+ function parsePort(portStr, context) {
65
+ const port = Number(portStr);
66
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
67
+ throw new Error(`${context}: port must be between 1 and 65535`);
68
+ }
69
+ return port;
70
+ }
71
+ export function parseHostPort(input) {
72
+ const trimmed = input.trim();
73
+ if (!trimmed) {
74
+ throw new Error("Host is required");
75
+ }
76
+ // IPv6: [::1]:8686
77
+ if (trimmed.startsWith("[")) {
78
+ const match = trimmed.match(/^\[([^\]]+)\]:(\d{1,5})$/);
79
+ if (!match) {
80
+ throw new Error("Invalid host:port (expected [::1]:8686)");
81
+ }
82
+ const host = match[1].trim();
83
+ if (!host)
84
+ throw new Error("Host is required");
85
+ const port = parsePort(match[2], "Invalid host:port");
86
+ return { host, port, isIpv6: true };
87
+ }
88
+ const match = trimmed.match(/^(.+):(\d{1,5})$/);
89
+ if (!match) {
90
+ throw new Error("Invalid host:port (expected localhost:8686)");
91
+ }
92
+ const host = match[1].trim();
93
+ if (!host)
94
+ throw new Error("Host is required");
95
+ const port = parsePort(match[2], "Invalid host:port");
96
+ return { host, port, isIpv6: false };
97
+ }
98
+ export function normalizeHostPort(input) {
99
+ const { host, port, isIpv6 } = parseHostPort(input);
100
+ return isIpv6 ? `[${host}]:${port}` : `${host}:${port}`;
101
+ }
102
+ export function parseConnectionUri(input) {
103
+ const trimmed = input.trim();
104
+ if (!trimmed) {
105
+ throw new Error("Connection URI is required");
106
+ }
107
+ let parsed;
108
+ try {
109
+ parsed = new URL(trimmed);
110
+ }
111
+ catch {
112
+ throw new Error("Invalid connection URI");
113
+ }
114
+ if (parsed.protocol !== "tcp:") {
115
+ throw new Error("Connection URI protocol must be tcp:");
116
+ }
117
+ if (!parsed.hostname) {
118
+ throw new Error("Connection URI host is required");
119
+ }
120
+ if (!parsed.port) {
121
+ throw new Error("Connection URI port is required");
122
+ }
123
+ if (parsed.username || parsed.password) {
124
+ throw new Error("Connection URI userinfo is not supported");
125
+ }
126
+ const isIpv6 = parsed.hostname.startsWith("[") && parsed.hostname.endsWith("]");
127
+ const host = isIpv6 ? parsed.hostname.slice(1, -1) : parsed.hostname;
128
+ const password = parsed.searchParams.get("password") || undefined;
129
+ return {
130
+ host,
131
+ port: parsePort(parsed.port, "Invalid connection URI"),
132
+ isIpv6,
133
+ useTls: parsed.searchParams.get("ssl") === "true",
134
+ ...(password ? { password } : {}),
135
+ };
136
+ }
137
+ export function serializeConnectionUri(parts) {
138
+ return createConnectionUri(parts).toString();
139
+ }
140
+ export function serializeConnectionUriForStorage(parts) {
141
+ const url = createConnectionUri(parts);
142
+ if (parts.password) {
143
+ url.searchParams.set("password", parts.password);
144
+ }
145
+ return url.toString();
146
+ }
147
+ function createConnectionUri(parts) {
148
+ const hostPart = parts.isIpv6 ? `[${parts.host}]` : parts.host;
149
+ const url = new URL(`tcp://${hostPart}:${parts.port}`);
150
+ if (parts.useTls) {
151
+ url.searchParams.set("ssl", "true");
152
+ }
153
+ return url;
154
+ }
155
+ export function normalizeLoopbackToLocalhost(endpoint) {
156
+ const { host, port, isIpv6 } = parseHostPort(endpoint);
157
+ if (host === "127.0.0.1" || (!isIpv6 && host === "0.0.0.0")) {
158
+ return `localhost:${port}`;
159
+ }
160
+ if (isIpv6 && (host === "::1" || host === "::")) {
161
+ return `localhost:${port}`;
162
+ }
163
+ return endpoint;
164
+ }
165
+ export function deriveLabelFromEndpoint(endpoint) {
166
+ try {
167
+ const { host } = parseHostPort(endpoint);
168
+ return host || "Unnamed Host";
169
+ }
170
+ catch {
171
+ return "Unnamed Host";
172
+ }
173
+ }
174
+ export function buildDaemonWebSocketUrl(endpoint, opts) {
175
+ const { host, port, isIpv6 } = parseHostPort(endpoint);
176
+ const protocol = opts.useTls ? "wss" : "ws";
177
+ const hostPart = isIpv6 ? `[${host}]` : host;
178
+ return new URL(`${protocol}://${hostPart}:${port}/ws`).toString();
179
+ }
180
+ export function buildRelayWebSocketUrl(params) {
181
+ const { host, port, isIpv6 } = parseHostPort(params.endpoint);
182
+ const protocol = params.useTls ? "wss" : "ws";
183
+ const hostPart = isIpv6 ? `[${host}]` : host;
184
+ const url = new URL(`${protocol}://${hostPart}:${port}/ws`);
185
+ url.searchParams.set("serverId", params.serverId);
186
+ url.searchParams.set("role", params.role);
187
+ url.searchParams.set("v", normalizeRelayProtocolVersion(params.version));
188
+ if (params.connectionId) {
189
+ url.searchParams.set("connectionId", params.connectionId);
190
+ }
191
+ return url.toString();
192
+ }
193
+ /**
194
+ * @deprecated Migration fallback for stored relay connections/offers that predate
195
+ * explicit relay useTls. Delete after two release cycles.
196
+ */
197
+ export function shouldUseTlsForDefaultHostedRelay(endpoint) {
198
+ try {
199
+ const { port } = parseHostPort(endpoint);
200
+ return port === 443;
201
+ }
202
+ catch {
203
+ return false;
204
+ }
205
+ }
206
+ export function extractHostPortFromWebSocketUrl(wsUrl) {
207
+ const parsed = new URL(wsUrl);
208
+ if (parsed.protocol !== "ws:" && parsed.protocol !== "wss:") {
209
+ throw new Error("Invalid WebSocket URL protocol");
210
+ }
211
+ if (parsed.pathname.replace(/\/+$/, "") !== "/ws") {
212
+ throw new Error("Invalid WebSocket URL (expected /ws path)");
213
+ }
214
+ const host = parsed.hostname;
215
+ let port;
216
+ if (parsed.port) {
217
+ port = Number(parsed.port);
218
+ }
219
+ else if (parsed.protocol === "wss:") {
220
+ port = 443;
221
+ }
222
+ else {
223
+ port = 80;
224
+ }
225
+ if (!host) {
226
+ throw new Error("Invalid WebSocket URL (missing hostname)");
227
+ }
228
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
229
+ throw new Error("Invalid WebSocket URL (invalid port)");
230
+ }
231
+ const isIpv6 = host.includes(":") && !host.startsWith("[") && !host.endsWith("]");
232
+ return isIpv6 ? `[${host}]:${port}` : `${host}:${port}`;
233
+ }
234
+ export function isRelayClientWebSocketUrl(url) {
235
+ try {
236
+ const parsed = new URL(url);
237
+ return parsed.searchParams.get("role") === "client" && parsed.searchParams.has("serverId");
238
+ }
239
+ catch {
240
+ return false;
241
+ }
242
+ }
243
+ //# sourceMappingURL=daemon-endpoints.js.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Extracts a human-readable error message from an unknown error value.
3
+ * Handles Error instances, string errors, and other types safely.
4
+ */
5
+ export declare function getErrorMessage(error: unknown): string;
6
+ /**
7
+ * Extracts an error message from an unknown error value, with a fallback
8
+ * for when no message can be extracted.
9
+ */
10
+ export declare function getErrorMessageOr(error: unknown, fallback: string): string;
11
+ //# sourceMappingURL=error-utils.d.ts.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Extracts a human-readable error message from an unknown error value.
3
+ * Handles Error instances, string errors, and other types safely.
4
+ */
5
+ export function getErrorMessage(error) {
6
+ if (error instanceof Error) {
7
+ return error.message;
8
+ }
9
+ if (typeof error === "string") {
10
+ return error;
11
+ }
12
+ return String(error);
13
+ }
14
+ /**
15
+ * Extracts an error message from an unknown error value, with a fallback
16
+ * for when no message can be extracted.
17
+ */
18
+ export function getErrorMessageOr(error, fallback) {
19
+ if (error instanceof Error) {
20
+ return error.message;
21
+ }
22
+ if (typeof error === "string" && error.length > 0) {
23
+ return error;
24
+ }
25
+ return fallback;
26
+ }
27
+ //# sourceMappingURL=error-utils.js.map