@rynx-ai/daemon 0.1.0 → 0.1.9

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 (89) hide show
  1. package/dist/browser-cli-args.d.ts +20 -0
  2. package/dist/browser-cli-args.js +100 -0
  3. package/dist/browser-runner-session-context.d.ts +24 -0
  4. package/dist/browser-runner-session-context.js +113 -0
  5. package/dist/cdp-keyboard-input.d.ts +6 -0
  6. package/dist/cdp-keyboard-input.js +209 -0
  7. package/dist/channel-store.d.ts +0 -6
  8. package/dist/channel-store.js +2 -18
  9. package/dist/chrome-for-testing-release-resolver.d.ts +34 -0
  10. package/dist/chrome-for-testing-release-resolver.js +214 -0
  11. package/dist/chrome-for-testing-store.d.ts +85 -0
  12. package/dist/chrome-for-testing-store.js +836 -0
  13. package/dist/cli.js +467 -30
  14. package/dist/control-client.d.ts +113 -0
  15. package/dist/control-client.js +792 -0
  16. package/dist/control-deps.js +37 -6
  17. package/dist/control-endpoint.d.ts +14 -0
  18. package/dist/control-endpoint.js +124 -0
  19. package/dist/control-link-store.d.ts +16 -0
  20. package/dist/control-link-store.js +53 -0
  21. package/dist/daemon-owner.d.ts +14 -0
  22. package/dist/daemon-owner.js +104 -0
  23. package/dist/daemon-server.d.ts +12 -2
  24. package/dist/daemon-server.js +559 -28
  25. package/dist/db.js +140 -10
  26. package/dist/desktop-browser-host-client.d.ts +34 -0
  27. package/dist/desktop-browser-host-client.js +413 -0
  28. package/dist/direct-runtime-authenticator.d.ts +13 -0
  29. package/dist/direct-runtime-authenticator.js +127 -0
  30. package/dist/direct-runtime-config.d.ts +20 -0
  31. package/dist/direct-runtime-config.js +101 -0
  32. package/dist/embedded-browser-profile-cleanup.d.ts +58 -0
  33. package/dist/embedded-browser-profile-cleanup.js +338 -0
  34. package/dist/headless-browser-host.d.ts +14 -0
  35. package/dist/headless-browser-host.js +2156 -0
  36. package/dist/index-daemon.js +28 -5
  37. package/dist/installation-id.d.ts +33 -0
  38. package/dist/installation-id.js +692 -0
  39. package/dist/migrations/cleanup-legacy-sessions.d.ts +0 -3
  40. package/dist/migrations/cleanup-legacy-sessions.js +10 -28
  41. package/dist/plugin-cli.d.ts +30 -0
  42. package/dist/plugin-cli.js +270 -0
  43. package/dist/plugin-host-rpc.d.ts +85 -0
  44. package/dist/plugin-host-rpc.js +878 -0
  45. package/dist/plugin-install-restart.d.ts +13 -0
  46. package/dist/plugin-install-restart.js +24 -0
  47. package/dist/plugin-installer.d.ts +36 -15
  48. package/dist/plugin-installer.js +420 -155
  49. package/dist/plugin-package.d.ts +38 -0
  50. package/dist/plugin-package.js +553 -0
  51. package/dist/plugin-runtime-control.d.ts +2 -0
  52. package/dist/plugin-runtime-control.js +37 -0
  53. package/dist/plugin-store.d.ts +37 -8
  54. package/dist/plugin-store.js +80 -15
  55. package/dist/plugin-supervisor.d.ts +160 -0
  56. package/dist/plugin-supervisor.js +1143 -0
  57. package/dist/pm2.d.ts +3 -1
  58. package/dist/pm2.js +55 -13
  59. package/dist/provider-cli-service.d.ts +46 -0
  60. package/dist/provider-cli-service.js +510 -0
  61. package/dist/registry.d.ts +6 -19
  62. package/dist/registry.js +22 -87
  63. package/dist/remote-runtime-access-store.d.ts +61 -0
  64. package/dist/remote-runtime-access-store.js +386 -0
  65. package/dist/remote-runtime-admin.d.ts +32 -0
  66. package/dist/remote-runtime-admin.js +107 -0
  67. package/dist/remote-runtime-connection-manager.d.ts +92 -0
  68. package/dist/remote-runtime-connection-manager.js +1409 -0
  69. package/dist/remote-runtime-credential-store.d.ts +45 -0
  70. package/dist/remote-runtime-credential-store.js +639 -0
  71. package/dist/remote-runtime-target-control.d.ts +47 -0
  72. package/dist/remote-runtime-target-control.js +433 -0
  73. package/dist/remote-runtime-target-store.d.ts +53 -0
  74. package/dist/remote-runtime-target-store.js +307 -0
  75. package/dist/runtime-share-addresses.d.ts +21 -0
  76. package/dist/runtime-share-addresses.js +50 -0
  77. package/dist/session-browser-capability-store.d.ts +13 -0
  78. package/dist/session-browser-capability-store.js +58 -0
  79. package/dist/session-emulator-binding-store.d.ts +10 -0
  80. package/dist/session-emulator-binding-store.js +61 -0
  81. package/dist/session-launch-operations.d.ts +41 -0
  82. package/dist/session-launch-operations.js +124 -0
  83. package/dist/session-meta-store.d.ts +3 -2
  84. package/dist/session-meta-store.js +57 -7
  85. package/dist/setup.js +9 -4
  86. package/dist/skills-catalog.js +8 -4
  87. package/dist/update.d.ts +11 -2
  88. package/dist/update.js +0 -27
  89. package/package.json +18 -10
@@ -0,0 +1,107 @@
1
+ import { createHash } from "node:crypto";
2
+ import { DIRECT_RUNTIME_CONTROL_PATH, parsePairingOffer, } from "@rynx-ai/protocol/direct-runtime";
3
+ import { listRuntimeShareAddresses } from "./runtime-share-addresses.js";
4
+ const DEFAULT_PAIRING_TTL_MS = 5 * 60_000;
5
+ export class DaemonRemoteRuntimeAdmin {
6
+ identity;
7
+ encryption;
8
+ access;
9
+ directConfig;
10
+ connections;
11
+ constructor(identity, encryption, access, directConfig, connections) {
12
+ this.identity = identity;
13
+ this.encryption = encryption;
14
+ this.access = access;
15
+ this.directConfig = directConfig;
16
+ this.connections = connections;
17
+ }
18
+ listShareAddresses() {
19
+ return listRuntimeShareAddresses({ bindHost: this.directConfig.bindHost });
20
+ }
21
+ createPairingOffer(input = {}) {
22
+ const directEndpoint = advertisedEndpoint(input.address, this.directConfig.port);
23
+ const claim = this.access.createPairingClaim({
24
+ ttlMs: DEFAULT_PAIRING_TTL_MS,
25
+ ...(input.clientLabel ? { label: input.clientLabel } : {}),
26
+ });
27
+ return parsePairingOffer({
28
+ type: "rynx.remote-runtime.pairing-offer",
29
+ enrollmentVersion: 2,
30
+ daemonId: this.identity.installationId,
31
+ identityAlgorithm: "Ed25519",
32
+ identityPublicKey: this.identity.publicKey,
33
+ security: "e2ee-v1",
34
+ encryptionAlgorithm: "X25519",
35
+ serverEncryptionPublicKey: this.encryption.publicKey,
36
+ directEndpoint,
37
+ claimId: claim.claimId,
38
+ claimSecret: claim.claimSecret,
39
+ expiresAt: claim.expiresAt,
40
+ });
41
+ }
42
+ listClientGrants() {
43
+ return this.access.listClientGrants().map(redactGrant);
44
+ }
45
+ revokeClientGrant(grantId) {
46
+ const revoked = this.access.revokeClientGrant(grantId);
47
+ const closedConnections = revoked ? this.connections.revokeGrant(grantId) : 0;
48
+ return { revoked, closedConnections };
49
+ }
50
+ }
51
+ function advertisedEndpoint(address, listenerPort) {
52
+ const input = address?.trim() || "127.0.0.1";
53
+ let endpoint;
54
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(input)) {
55
+ try {
56
+ endpoint = new URL(input);
57
+ }
58
+ catch {
59
+ throw new Error("Direct Runtime address must be a host or ws(s) URL");
60
+ }
61
+ }
62
+ else {
63
+ if (/[/\\?#@\s]/.test(input)) {
64
+ throw new Error("Direct Runtime address must be a host or ws(s) URL");
65
+ }
66
+ const host = input.includes(":") ? `[${input}]` : input;
67
+ try {
68
+ endpoint = new URL(`ws://${host}:${listenerPort}`);
69
+ }
70
+ catch {
71
+ throw new Error("Direct Runtime address must be a host or ws(s) URL");
72
+ }
73
+ }
74
+ if ((endpoint.protocol !== "ws:" && endpoint.protocol !== "wss:") ||
75
+ endpoint.username ||
76
+ endpoint.password ||
77
+ endpoint.search ||
78
+ endpoint.hash ||
79
+ !endpoint.hostname ||
80
+ endpoint.hostname === "0.0.0.0" ||
81
+ endpoint.hostname === "[::]" ||
82
+ endpoint.hostname === "::") {
83
+ throw new Error("Direct Runtime address must be a credential-free dialable ws(s) route");
84
+ }
85
+ if (endpoint.pathname !== "/" && endpoint.pathname !== DIRECT_RUNTIME_CONTROL_PATH) {
86
+ throw new Error(`Direct Runtime address path must be / or ${DIRECT_RUNTIME_CONTROL_PATH}`);
87
+ }
88
+ endpoint.pathname = DIRECT_RUNTIME_CONTROL_PATH;
89
+ return endpoint.toString();
90
+ }
91
+ function redactGrant(grant) {
92
+ return {
93
+ grantId: grant.grantId,
94
+ clientId: grant.clientId,
95
+ clientLabel: grant.clientLabel,
96
+ clientKeyFingerprint: publicKeyFingerprint(grant.clientPublicKey),
97
+ authorities: [...grant.authorities],
98
+ createdAt: grant.createdAt,
99
+ revokedAt: grant.revokedAt,
100
+ lastUsedAt: grant.lastUsedAt,
101
+ };
102
+ }
103
+ function publicKeyFingerprint(publicKey) {
104
+ return `SHA256:${createHash("sha256")
105
+ .update(Buffer.from(publicKey, "base64url"))
106
+ .digest("base64url")}`;
107
+ }
@@ -0,0 +1,92 @@
1
+ import { type RuntimeBrowserSurfaceOpenFrame } from "@rynx-ai/protocol/runtime-browser-surface";
2
+ import { type DirectRuntimeConnection, type DirectRuntimeBrowserSurfaceConnection, type DirectRuntimeCredential } from "@rynx-ai/remote-runtime-client";
3
+ import type { DirectRuntimeBrowserSurfaceHost, DirectRuntimeEmulatorSurfaceHost, RemoteRuntimeDispatcher, RuntimeConnectionLease, RuntimeConnectionResolverHost } from "@rynx-ai/server";
4
+ import { type FileRemoteRuntimeCredentialStore, type RemoteRuntimeClientCredential } from "./remote-runtime-credential-store.js";
5
+ import { type RemoteRuntimeTarget, type RemoteRuntimeTargetStore } from "./remote-runtime-target-store.js";
6
+ export type RuntimeConnectionManagerErrorCode = "invalid_target" | "not_found" | "authentication_failed" | "identity_mismatch" | "incompatible" | "protocol_error" | "deadline_exceeded" | "outcome_unknown" | "closed" | "cancelled";
7
+ export declare class RuntimeConnectionManagerError extends Error {
8
+ readonly code: RuntimeConnectionManagerErrorCode;
9
+ readonly outcome: "not_started" | "unknown" | undefined;
10
+ constructor(code: RuntimeConnectionManagerErrorCode, message: string, options?: ErrorOptions & {
11
+ outcome?: "not_started" | "unknown";
12
+ });
13
+ }
14
+ interface RuntimeTargetReader {
15
+ get(selector: string): RemoteRuntimeTarget | undefined;
16
+ }
17
+ interface RuntimeCredentialReader {
18
+ load(credentialRef: string): Promise<RemoteRuntimeClientCredential>;
19
+ }
20
+ interface RuntimeClientAdapter {
21
+ connect(credential: DirectRuntimeCredential): Promise<DirectRuntimeConnection>;
22
+ openBrowserSurface?(credential: DirectRuntimeCredential, frame: RuntimeBrowserSurfaceOpenFrame, options?: {
23
+ timeoutMs?: number;
24
+ signal?: AbortSignal;
25
+ }): Promise<DirectRuntimeBrowserSurfaceConnection>;
26
+ }
27
+ export interface DaemonRuntimeConnectionManagerOptions {
28
+ localDaemonId: string;
29
+ dispatcher: Pick<RemoteRuntimeDispatcher, "dispatch" | "openSessionEvents" | "openSessionTerminal">;
30
+ localBrowserSurface?: DirectRuntimeBrowserSurfaceHost;
31
+ localEmulatorSurface?: DirectRuntimeEmulatorSurfaceHost;
32
+ targets: Pick<RemoteRuntimeTargetStore, "get"> | RuntimeTargetReader;
33
+ credentials: Pick<FileRemoteRuntimeCredentialStore, "load"> | RuntimeCredentialReader;
34
+ client?: RuntimeClientAdapter;
35
+ idleTtlMs?: number;
36
+ maxIdleConnections?: number;
37
+ }
38
+ /**
39
+ * Daemon-owned Local/Direct Runtime resolver.
40
+ *
41
+ * Application callers receive only a logical target and a typed call surface;
42
+ * target routes and client credentials never cross this boundary. Direct
43
+ * connections are reused while healthy, but a failed call is never retried.
44
+ */
45
+ export declare class DaemonRuntimeConnectionManager implements RuntimeConnectionResolverHost {
46
+ private readonly options;
47
+ private readonly client;
48
+ private readonly idleTtlMs;
49
+ private readonly maxIdleConnections;
50
+ private readonly slots;
51
+ private readonly generations;
52
+ private localStatusSnapshot?;
53
+ private closed;
54
+ private managerClosePromise?;
55
+ constructor(options: DaemonRuntimeConnectionManagerOptions);
56
+ acquire(selector: string, options?: {
57
+ signal?: AbortSignal;
58
+ }): Promise<RuntimeConnectionLease>;
59
+ /** Synchronously detaches the generation, then closes it asynchronously. */
60
+ invalidate(daemonId: string): Promise<void>;
61
+ close(): Promise<void>;
62
+ private localLease;
63
+ private callLocal;
64
+ private readLocalStatus;
65
+ private dispatchLocalRequest;
66
+ private rememberLocalStatus;
67
+ private assertMethodSupported;
68
+ private assertSessionEventsSupported;
69
+ private assertSessionTerminalSupported;
70
+ private directLease;
71
+ private wrapDirectSessionSubscription;
72
+ private openDedicatedDirectTerminal;
73
+ private openDedicatedDirectBrowserSurface;
74
+ private openDedicatedDirectEmulatorSurface;
75
+ private slotFor;
76
+ private openDirectConnection;
77
+ private evict;
78
+ private closeSlot;
79
+ private trackDedicatedTerminal;
80
+ private trackDedicatedBrowserSurface;
81
+ private trackDedicatedEmulatorSurface;
82
+ private registerDedicatedCloser;
83
+ private scheduleIdleClose;
84
+ private pruneIdleConnections;
85
+ private cancelIdleTimer;
86
+ private assertOpen;
87
+ private assertSlotCurrent;
88
+ private isSlotCurrent;
89
+ private generation;
90
+ private bumpGeneration;
91
+ }
92
+ export {};