@dxos/client-protocol 0.10.0 → 0.11.1
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/lib/index.mjs +590 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/lib/types.mjs +26 -0
- package/dist/lib/types.mjs.map +1 -0
- package/dist/types/src/Rpc.d.ts +41 -0
- package/dist/types/src/Rpc.d.ts.map +1 -0
- package/dist/types/src/bridge-rpc.d.ts +27 -0
- package/dist/types/src/bridge-rpc.d.ts.map +1 -0
- package/dist/types/src/config.d.ts +0 -1
- package/dist/types/src/config.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/service-rpc.d.ts +551 -0
- package/dist/types/src/service-rpc.d.ts.map +1 -0
- package/dist/types/src/service.d.ts +14 -18
- package/dist/types/src/service.d.ts.map +1 -1
- package/dist/types/src/types/SpaceProperties.d.ts +5 -11
- package/dist/types/src/types/SpaceProperties.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -14
- package/src/Rpc.ts +200 -0
- package/src/bridge-rpc.ts +114 -0
- package/src/config.ts +0 -1
- package/src/index.ts +3 -1
- package/src/service-rpc.ts +439 -0
- package/src/service.ts +17 -45
- package/src/types/SpaceProperties.ts +4 -11
- package/dist/lib/browser/chunk-3SERD2CK.mjs +0 -40
- package/dist/lib/browser/chunk-3SERD2CK.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -233
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/types/index.mjs +0 -11
- package/dist/lib/browser/types/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YDC7XBNG.mjs +0 -42
- package/dist/lib/node-esm/chunk-YDC7XBNG.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -234
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/types/index.mjs +0 -12
- package/dist/lib/node-esm/types/index.mjs.map +0 -7
- package/dist/types/src/client.d.ts +0 -2
- package/dist/types/src/client.d.ts.map +0 -1
- package/src/client.ts +0 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/Rpc.ts","../../src/config.ts","../../src/service-rpc.ts","../../src/bridge-rpc.ts","../../src/invitations/encoder.ts","../../src/invitations/invitations.ts","../../src/service.ts","../../src/space.ts","../../src/timeouts.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as BrowserWorker from '@effect/platform-browser/BrowserWorker';\nimport * as BrowserWorkerRunner from '@effect/platform-browser/BrowserWorkerRunner';\nimport * as RpcClient from '@effect/rpc/RpcClient';\nimport * as RpcServer from '@effect/rpc/RpcServer';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport * as ManagedRuntime from 'effect/ManagedRuntime';\nimport type * as Scope from 'effect/Scope';\n\nimport { RpcTiming } from '@dxos/worker-framework';\n\nexport type ServeOptions = {\n disableTracing?: boolean;\n concurrency?: number | 'unbounded';\n /**\n * When enabled, stamps each outbound RPC with a `Date.now()` send time and logs queue-wait /\n * service durations on the worker above {@link RpcTiming.Options.minLogMs} (default 100 ms).\n */\n timing?: boolean | RpcTiming.Options;\n};\n\n// A worker RPC client runs over a single MessagePort that multiplexes every request by id, so there\n// is no real per-connection concurrency limit. The `@effect/rpc` worker protocol backs the client\n// with a `Pool` that holds one worker for a request's whole lifetime — including long-lived streams.\n// The pool's default concurrency of 1 therefore lets a single open stream (e.g. a subscription) block\n// every other call. Allow effectively-unbounded concurrent requests over the one worker instead.\nconst WORKER_CLIENT_CONCURRENCY = Number.MAX_SAFE_INTEGER;\n\n// Merged rpc groups (e.g. ClientServicesRpcs) do not structurally satisfy RpcGroup<Rpc.Any>\n// in @effect/rpc's type parameter; runtime dispatch accepts any RpcGroup instance.\nconst asRpcGroup = <G>(group: G): Parameters<typeof RpcClient.make>[0] => group as Parameters<typeof RpcClient.make>[0];\n\n/**\n * Builds an effect-native RPC client over a caller-supplied {@link RpcClient.Protocol} layer.\n * Transport-agnostic: consumers provide the Worker-platform protocol (see {@link makeClient}) or a\n * byte protocol over a legacy transport (e.g. `@dxos/rpc`'s RpcPort layer for iframe/devtools bridges).\n */\nexport const makeClientOverProtocol = <G, ProtocolError, ProtocolRequirements>(\n protocol: Layer.Layer<RpcClient.Protocol, ProtocolError, ProtocolRequirements>,\n group: G,\n options?: Pick<ServeOptions, 'disableTracing' | 'timing'>,\n): Effect.Effect<unknown, never, Scope.Scope | ProtocolRequirements> =>\n Effect.gen(function* () {\n const timingEnabled = RpcTiming.isEnabled(options?.timing);\n const rpcGroup = timingEnabled ? RpcTiming.applyMiddleware(asRpcGroup(group)) : asRpcGroup(group);\n const protocolLayer = timingEnabled ? protocol.pipe(Layer.provideMerge(RpcTiming.clientLayer())) : protocol;\n\n // Build the transport into the caller's scope (extended via `Scope.extend`) rather than\n // `Effect.provide`-ing the layer directly: that would bind the transport's lifetime to this\n // construction effect, tearing the worker connection down the instant the client is returned\n // (the client is used later by the caller). `Layer.build` keeps it alive for the caller's scope.\n const context = yield* Layer.build(protocolLayer);\n return yield* RpcClient.make(asRpcGroup(rpcGroup), { disableTracing: options?.disableTracing ?? true }).pipe(\n Effect.provide(context),\n );\n }).pipe(Effect.orDie);\n\n/**\n * Builds an effect-native RPC client over a {@link MessagePort} using the native Worker platform\n * protocol (structured-clone frames, transferables supported).\n */\nexport const makeClient = <G>(\n port: MessagePort,\n group: G,\n options?: Pick<ServeOptions, 'disableTracing' | 'timing'>,\n): Effect.Effect<unknown, never, Scope.Scope> =>\n makeClientOverProtocol(\n RpcClient.layerProtocolWorker({ size: 1, concurrency: WORKER_CLIENT_CONCURRENCY }).pipe(\n Layer.provide(BrowserWorker.layerPlatform(() => port)),\n ),\n group,\n options,\n );\n\nexport type GroupServer = {\n open(): Promise<void>;\n close(): Promise<void>;\n};\n\n/**\n * Serves an {@link RpcGroup} on a {@link MessagePort} via the native Worker runner protocol.\n */\nexport const serve = <G, H extends Layer.Layer<never, never, never>>(\n port: MessagePort,\n group: G,\n handlers: H,\n options?: ServeOptions,\n): GroupServer => {\n let runtime: ManagedRuntime.ManagedRuntime<never, never> | undefined;\n\n return {\n async open(): Promise<void> {\n if (runtime) {\n return;\n }\n\n const timingEnabled = RpcTiming.isEnabled(options?.timing);\n const rpcGroup = timingEnabled ? RpcTiming.applyMiddleware(asRpcGroup(group)) : asRpcGroup(group);\n // Merge the timing middleware layer into the handler layer (rather than a conditional\n // `.pipe(...)` element) so the pipeline stays a fixed tuple.\n const handlersLayer = timingEnabled\n ? Layer.merge(handlers, RpcTiming.serverLayer(RpcTiming.resolveOptions(options?.timing)))\n : handlers;\n const serverLayer = RpcServer.layer(asRpcGroup(rpcGroup), {\n disableTracing: options?.disableTracing ?? true,\n concurrency: options?.concurrency ?? 'unbounded',\n }).pipe(\n Layer.provide(handlersLayer),\n Layer.provide(\n RpcServer.layerProtocolWorkerRunner.pipe(Layer.provide(BrowserWorkerRunner.layerMessagePort(port))),\n ),\n Layer.orDie,\n );\n\n const current = ManagedRuntime.make(serverLayer);\n try {\n await current.runPromise(Effect.void);\n } catch (error) {\n // Leave the server un-opened on startup failure so a later open() can retry rather than\n // returning early against a runtime that never started.\n await current.dispose();\n throw error;\n }\n runtime = current;\n },\n\n async close(): Promise<void> {\n const current = runtime;\n runtime = undefined;\n await current?.dispose();\n },\n };\n};\n\n/**\n * Serves an {@link RpcGroup} over a caller-supplied {@link RpcServer.Protocol} layer.\n * Transport-agnostic counterpart to {@link makeClientOverProtocol}: consumers provide a byte\n * protocol over a legacy transport (e.g. `@dxos/rpc`'s RpcPort layer for iframe/devtools bridges).\n */\nexport const serveOverProtocol = <G, H extends Layer.Layer<never, never, never>>(\n protocol: Layer.Layer<RpcServer.Protocol>,\n group: G,\n handlers: H,\n options?: ServeOptions,\n): GroupServer => {\n let runtime: ManagedRuntime.ManagedRuntime<never, never> | undefined;\n // Cache the in-flight open so concurrent opens share one initialization and a close during open\n // can await it before disposing — otherwise `runtime` is unset mid-open and a fast open/close\n // (e.g. client restart) leaks the runtime.\n let openPromise: Promise<void> | undefined;\n\n return {\n async open(): Promise<void> {\n if (openPromise) {\n return openPromise;\n }\n\n openPromise = (async () => {\n const timingEnabled = RpcTiming.isEnabled(options?.timing);\n const rpcGroup = timingEnabled ? RpcTiming.applyMiddleware(asRpcGroup(group)) : asRpcGroup(group);\n const handlersLayer = timingEnabled\n ? Layer.merge(handlers, RpcTiming.serverLayer(RpcTiming.resolveOptions(options?.timing)))\n : handlers;\n const serverLayer = RpcServer.layer(asRpcGroup(rpcGroup), {\n disableTracing: options?.disableTracing ?? true,\n concurrency: options?.concurrency ?? 'unbounded',\n }).pipe(Layer.provide(handlersLayer), Layer.provide(protocol), Layer.orDie);\n\n const current = ManagedRuntime.make(serverLayer);\n try {\n await current.runPromise(Effect.void);\n } catch (error) {\n // Leave the server un-opened on startup failure so a later open() can retry.\n openPromise = undefined;\n await current.dispose();\n throw error;\n }\n runtime = current;\n })();\n return openPromise;\n },\n\n async close(): Promise<void> {\n if (openPromise) {\n // Wait for an in-flight open so we dispose the runtime it created rather than leaking it.\n await openPromise.catch(() => {});\n openPromise = undefined;\n }\n const current = runtime;\n runtime = undefined;\n await current?.dispose();\n },\n };\n};\n","//\n// Copyright 2022 DXOS.org\n//\n\n// TODO(wittjosiah): Factor out to @dxos/config.\n\nexport const DEFAULT_CLIENT_CHANNEL = 'dxos:app';\nexport const DEFAULT_INTERNAL_CHANNEL = 'dxos:vault';\nexport const DEFAULT_SHELL_CHANNEL = 'dxos:shell';\n\n/**\n * @deprecated\n */\nexport const DEFAULT_VAULT_URL = 'https://halo.dxos.org/vault.html';\n\n/**\n * @deprecated\n */\n// TODO(burdon): Remove need (i.e., make undefined do the right thing).\nexport const DEFAULT_PROFILE = 'default';\n\nexport const EXPECTED_CONFIG_VERSION = 1;\nexport const defaultConfig = { version: 1 };\n\n// TODO(burdon): Allow override via env? Generalize since currently NodeJS only.\nconst HOME = typeof process !== 'undefined' ? (process?.env?.HOME ?? '') : '';\n\n// XDG_CONFIG_HOME (Analogous to /etc.)\nexport const DX_CONFIG = `${HOME}/.config/dx`;\n\n// XDG_CACHE_HOME (Analogous to /var/cache).\nexport const DX_CACHE = `${HOME}/.cache/dx`;\n\n// TODO(burdon): Storage should use this by default (make path optional).\n// XDG_DATA_HOME (Analogous to /usr/share).\nexport const DX_DATA = `${HOME}/.local/share/dx`;\n\n// XDG_STATE_HOME (Analogous to /var/lib).\nexport const DX_STATE = `${HOME}/.local/state/dx`;\n\n// XDG_RUNTIME_DIR (Non-essential files, sockets, etc.)\nexport const DX_RUNTIME = '/tmp/dx/run';\n\nexport enum DXEnv {\n CONFIG = 'DX_CONFIG',\n DEBUG = 'DX_DEBUG',\n NO_AGENT = 'DX_NO_AGENT',\n PROFILE = 'DX_PROFILE',\n}\n\nexport namespace DXEnv {\n /**\n * Helper to get the value from process.env\n */\n export function get(variable: DXEnv): string | undefined;\n export function get(variable: DXEnv, defaultValue: string): string;\n export function get(variable: DXEnv, defaultValue?: string): string | undefined {\n return process.env[variable] ?? defaultValue;\n }\n}\n\n// Profile layout: profile/<name> is the profile dir; profile/<name>.yml is the config file.\nexport const getProfilePath = (root: string, profile: string, file?: string) =>\n `${root}/profile/${profile}` + (file ? `/${file}` : '');\n\n/** Path to the profile config file (profile/<name>.yml). */\nexport const getProfileConfigPath = (root: string, profile: string) => `${getProfilePath(root, profile)}.yml`;\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport type * as EffectRpc from '@effect/rpc/Rpc';\nimport * as RpcGroup from '@effect/rpc/RpcGroup';\nimport * as RpcSchema from '@effect/rpc/RpcSchema';\nimport * as RpcServer from '@effect/rpc/RpcServer';\nimport * as RpcTest from '@effect/rpc/RpcTest';\nimport * as Cause from 'effect/Cause';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport * as Runtime from 'effect/Runtime';\nimport type * as Scope from 'effect/Scope';\nimport * as Stream from 'effect/Stream';\n\nimport { type RequestOptions } from '@dxos/codec-protobuf';\nimport { Stream as PbStream } from '@dxos/codec-protobuf/stream';\nimport { invariant } from '@dxos/invariant';\nimport { runServiceCall } from '@dxos/protocols';\nimport {\n ContactsService,\n DataService,\n DevicesService,\n DevtoolsHost,\n EdgeAgentService,\n FeedService,\n IdentityService,\n InvitationsService,\n LoggingService,\n NetworkService,\n QueryService,\n SpacesService,\n SystemService,\n WorkerService,\n} from '@dxos/protocols/rpc';\nimport { type RpcPort, layerProtocolRpcPortClient, layerProtocolRpcPortServer } from '@dxos/rpc';\nimport { createIFramePort } from '@dxos/rpc-tunnel';\n\nimport { DEFAULT_CLIENT_CHANNEL } from './config';\nimport * as Rpc from './Rpc';\nimport { type ClientServices } from './service';\n\nexport type MessagePortLike = MessagePort;\n\n/**\n * Transport a {@link ClientServicesRpc} can run over: the native Worker-platform {@link MessagePort}\n * (shared-worker app port) or a byte {@link RpcPort} for legacy protobuf bridges (iframe shell,\n * devtools extension).\n */\nexport type ClientServicesTransport = MessagePortLike | RpcPort;\n\n/**\n * All client service RPCs served over a single connection.\n * Rpc tags are prefixed with the {@link ClientServices} key (e.g. `DataService.subscribe`).\n *\n * {@link WorkerService} (the tab→worker control channel: `start`/`stop`) is merged in here rather\n * than served over a second port: it runs in the same tab→worker direction as the service RPCs, so\n * it multiplexes over the same app {@link MessagePort}. Only the reverse-direction `BridgeService`\n * (worker→tab) needs its own port.\n */\nexport class ClientServicesRpcs extends RpcGroup.make().merge(\n SystemService.Rpcs,\n NetworkService.Rpcs,\n LoggingService.Rpcs,\n IdentityService.Rpcs,\n InvitationsService.Rpcs,\n DevicesService.Rpcs,\n SpacesService.Rpcs,\n DataService.Rpcs,\n QueryService.Rpcs,\n FeedService.Rpcs,\n ContactsService.Rpcs,\n EdgeAgentService.Rpcs,\n DevtoolsHost.Rpcs,\n WorkerService.Rpcs,\n) {}\n\ntype ClientServicesRpcUnion = RpcGroup.Rpcs<typeof ClientServicesRpcs>;\n\n/**\n * Host-side service implementations, one per client service, each in the effect-rpc `Handlers`\n * shape (Effect/Stream-returning, tag-keyed). This is the shape service hosts provide and\n * {@link ClientRpcServer} serves directly, with no protobuf encode/decode at the boundary.\n */\nexport type ClientServicesHandlers = {\n SystemService: SystemService.Handlers;\n NetworkService: NetworkService.Handlers;\n LoggingService: LoggingService.Handlers;\n IdentityService: IdentityService.Handlers;\n InvitationsService: InvitationsService.Handlers;\n DevicesService: DevicesService.Handlers;\n SpacesService: SpacesService.Handlers;\n DataService: DataService.Handlers;\n QueryService: QueryService.Handlers;\n FeedService: FeedService.Handlers;\n ContactsService: ContactsService.Handlers;\n EdgeAgentService: EdgeAgentService.Handlers;\n DevtoolsHost: DevtoolsHost.Handlers;\n // Provided per-session by the worker session (drives readiness/origin/lock), not by the host.\n WorkerService: WorkerService.Handlers;\n};\n\nconst toError = (cause: unknown): Error => (cause instanceof Error ? cause : new Error(String(cause)));\n\nconst isVoidSchema = (schema: { ast: { _tag: string } }): boolean => schema.ast._tag === 'VoidKeyword';\n\n/** Splits an rpc tag into the {@link ClientServices} key and the service method name. */\nconst parseTag = (tag: string): [serviceKey: keyof ClientServices, methodName: string] => {\n const index = tag.indexOf('.');\n return [tag.slice(0, index) as keyof ClientServices, tag.slice(index + 1)];\n};\n\n/** Resolves a bound service method from a services provider, throwing if the service/method is absent. */\nconst resolveServiceMethod = (\n services: Partial<ClientServices>,\n serviceKey: keyof ClientServices,\n methodName: string,\n tag: string,\n): ((request: unknown) => unknown) => {\n const service = services[serviceKey] as Record<string, unknown> | undefined;\n if (!service) {\n throw new Error(`Service not available: ${serviceKey}`);\n }\n const method = service[methodName];\n if (typeof method !== 'function') {\n throw new Error(`Method not available: ${tag}`);\n }\n return (method as (request: unknown) => unknown).bind(service);\n};\n\n//\n// Server.\n//\n\nexport type ClientRpcServerParams = {\n /**\n * Native Worker-platform transport. Provide this or {@link protocol}.\n */\n port?: MessagePortLike;\n /**\n * Pre-built server protocol (the value the {@link RpcServer.Protocol} tag resolves to — e.g. handed\n * to a worker-framework session via effect context). Provide this or {@link port}.\n */\n protocol?: RpcServer.Protocol['Type'];\n /**\n * Resolved per call so the served set follows the host lifecycle (services host open/close).\n */\n services: () => Partial<ClientServicesHandlers>;\n /**\n * Awaited before dispatching each request (e.g. worker readiness); a rejection fails the call.\n */\n onRequest?: () => Promise<void>;\n};\n\n/**\n * Serves {@link ClientServices} implementations over a {@link MessagePort} via effect-rpc.\n */\nexport class ClientRpcServer {\n readonly #params: ClientRpcServerParams;\n #server?: ReturnType<typeof Rpc.serve>;\n\n constructor(params: ClientRpcServerParams) {\n this.#params = params;\n }\n\n async open(): Promise<void> {\n if (this.#server) {\n return;\n }\n\n const handlers = makeClientServicesHandlers(this.#params);\n const options = { disableTracing: true, concurrency: 'unbounded' } as const;\n if (this.#params.protocol) {\n this.#server = Rpc.serveOverProtocol(\n Layer.succeed(RpcServer.Protocol, this.#params.protocol),\n ClientServicesRpcs,\n handlers,\n options,\n );\n } else {\n invariant(this.#params.port, 'ClientRpcServer requires a port or a protocol.');\n this.#server = Rpc.serve(this.#params.port, ClientServicesRpcs, handlers, options);\n }\n await this.#server.open();\n }\n\n async close(): Promise<void> {\n const server = this.#server;\n this.#server = undefined;\n await server?.close();\n }\n}\n\nexport type ServeClientServicesOverIFrameOptions = {\n iframe: HTMLIFrameElement;\n origin: string;\n channel?: string;\n services: () => Partial<ClientServicesHandlers>;\n};\n\n/**\n * Serves {@link ClientServices} to a child iframe (e.g. the shell) over the effect-rpc byte protocol\n * and opens the connection. The iframe uses a byte {@link RpcPort} transport (not a `MessagePort`),\n * matching the shell's {@link ClientServicesProxy} consumer, so this serves over\n * {@link layerProtocolRpcPortServer} rather than the Worker-runner protocol used by\n * {@link ClientRpcServer}. Kept here — alongside the rpc definitions — so the `RpcPort` binding is\n * resolved in this package's type universe rather than in `@dxos/client`, whose merged-with-`main`\n * build resolves `ClientRpcServer.port` as a `MessagePort`.\n */\nexport const serveClientServicesOverIFrame = async ({\n iframe,\n origin,\n channel = DEFAULT_CLIENT_CHANNEL,\n services,\n}: ServeClientServicesOverIFrameOptions): Promise<Rpc.GroupServer> => {\n const server = Rpc.serveOverProtocol(\n layerProtocolRpcPortServer(createIFramePort({ channel, iframe, origin })),\n ClientServicesRpcs,\n makeClientServicesHandlers({ services }),\n { disableTracing: true, concurrency: 'unbounded' },\n );\n await server.open();\n return server;\n};\n\n/**\n * Builds handler layers for every client service RPC, dispatching to the service implementations\n * resolved from `services` on each call.\n */\nexport const makeClientServicesHandlers = ({\n services,\n onRequest,\n}: Pick<ClientRpcServerParams, 'services' | 'onRequest'>): Layer.Layer<EffectRpc.ToHandler<ClientServicesRpcUnion>> => {\n const gate = onRequest ? Effect.tryPromise({ try: onRequest, catch: toError }) : Effect.void;\n\n const handlers: Record<string, (payload: unknown) => unknown> = {};\n for (const [tag, rpc] of ClientServicesRpcs.requests) {\n const [serviceKey] = parseTag(tag);\n // The host service is itself in the Handlers shape, keyed by the full prefixed tag; invoking it\n // returns the Effect/Stream directly, so no protobuf encode/decode adapter is needed.\n const invoke = (payload: unknown) => {\n const service = services()[serviceKey] as Record<string, (payload: unknown) => unknown> | undefined;\n const handler = service?.[tag];\n if (typeof handler !== 'function') {\n throw new Error(`Service handler not available: ${tag}`);\n }\n return handler.call(service, payload);\n };\n\n if (RpcSchema.isStreamSchema(rpc.successSchema)) {\n handlers[tag] = (payload: unknown) =>\n gate.pipe(\n Effect.map(() => invoke(payload) as Stream.Stream<unknown, unknown>),\n Stream.unwrap,\n );\n } else {\n handlers[tag] = (payload: unknown) =>\n gate.pipe(Effect.flatMap(() => invoke(payload) as Effect.Effect<unknown, unknown>));\n }\n }\n\n // Handlers are dispatched dynamically across all merged service groups, so their per-method types\n // cannot be expressed statically.\n return ClientServicesRpcs.toLayer(handlers as never);\n};\n\n//\n// Client.\n//\n\n/**\n * Effect-native client for all client services, inferred from the effect-rpc definitions.\n * Nested by service key (e.g. `rpc.DataService.subscribe(req)` returns a `Stream`, unary methods\n * return an `Effect`). Each service's `Client` type already nests its methods under the service key\n * (the rpc tags are prefixed), so this is their intersection — cheaper for the type-checker than\n * re-expanding the full merged {@link RpcClient.RpcClient} mapped type over all services.\n */\nexport interface ClientServicesRpc\n extends\n SystemService.Client,\n NetworkService.Client,\n LoggingService.Client,\n IdentityService.Client,\n InvitationsService.Client,\n DevicesService.Client,\n SpacesService.Client,\n DataService.Client,\n QueryService.Client,\n FeedService.Client,\n ContactsService.Client,\n EdgeAgentService.Client,\n DevtoolsHost.Client,\n WorkerService.Client {}\n\n/**\n * Builds the effect-native {@link ClientServicesRpc} over a {@link MessagePort}.\n * The returned scope owns the connection; closing it releases the transport.\n */\nexport const makeClientServicesRpc = (\n port: ClientServicesTransport,\n): Effect.Effect<ClientServicesRpc, never, Scope.Scope> =>\n // An RpcPort (byte transport) carries the legacy iframe/devtools bridges; a MessagePort uses the\n // native Worker-platform protocol.\n ('send' in port\n ? Rpc.makeClientOverProtocol(layerProtocolRpcPortClient(port), ClientServicesRpcs, { disableTracing: true })\n : Rpc.makeClient(port, ClientServicesRpcs, { disableTracing: true })\n ).pipe(Effect.map((client) => client as ClientServicesRpc));\n\n/**\n * Builds an in-process {@link ClientServicesRpc} backed directly by host {@link ClientServicesHandlers}\n * (no wire hop or serialization). Used by host-internal consumers (diagnostics, devtools) that need\n * the client surface without a transport.\n */\nexport const makeInProcessClientServicesRpc = (\n services: () => Partial<ClientServicesHandlers>,\n): Effect.Effect<ClientServicesRpc, never, Scope.Scope> =>\n RpcTest.makeClient(ClientServicesRpcs).pipe(\n Effect.provide(makeClientServicesHandlers({ services })),\n ) as unknown as Effect.Effect<ClientServicesRpc, never, Scope.Scope>;\n\n/**\n * Derives host {@link ClientServicesHandlers} from an effect-native {@link ClientServicesRpc}, so a\n * client-side rpc surface can be re-served (e.g. the devtools bridge). Each handler delegates to the\n * corresponding client method.\n */\nexport const makeHandlersFromRpc = (rpc: ClientServicesRpc): Partial<ClientServicesHandlers> => {\n const rpcRecord = rpc as unknown as Record<string, Record<string, (...args: any[]) => unknown>>;\n const handlers: Partial<Record<keyof ClientServices, Record<string, unknown>>> = {};\n for (const [tag] of ClientServicesRpcs.requests) {\n const [serviceKey, methodName] = parseTag(tag);\n const service = (handlers[serviceKey] ??= {});\n service[tag] = (payload: unknown) => rpcRecord[serviceKey][methodName](payload);\n }\n return handlers as Partial<ClientServicesHandlers>;\n};\n\n/**\n * Derives the Promise/{@link PbStream} shaped {@link ClientServices} from an effect-native\n * {@link ClientServicesRpc}. Retained for consumers not yet migrated to the effect surface.\n */\nexport const makeServicesFromRpc = (\n rpc: ClientServicesRpc,\n runtime: Runtime.Runtime<never>,\n): Partial<ClientServices> => {\n // The rpc client is nested by service; methods are addressed dynamically from the rpc groups,\n // so the per-method types cannot be expressed statically.\n const rpcRecord = rpc as unknown as Record<string, Record<string, (...args: any[]) => unknown>>;\n const services: Partial<Record<keyof ClientServices, Record<string, unknown>>> = {};\n for (const [tag, rpcDef] of ClientServicesRpcs.requests) {\n const [serviceKey, methodName] = parseTag(tag);\n const service = (services[serviceKey] ??= {});\n const hasPayload = !isVoidSchema(rpcDef.payloadSchema);\n const invoke = (request?: unknown) => rpcRecord[serviceKey][methodName](hasPayload ? (request ?? {}) : undefined);\n\n if (RpcSchema.isStreamSchema(rpcDef.successSchema)) {\n service[methodName] = (request?: unknown) =>\n streamToPbStream(runtime, invoke(request) as Stream.Stream<unknown, unknown>);\n } else {\n service[methodName] = (request?: unknown, options?: RequestOptions) =>\n runServiceCall(runtime, invoke(request) as Effect.Effect<unknown, unknown, never>, {\n timeout: options?.timeout,\n label: tag,\n });\n }\n }\n return services as Partial<ClientServices>;\n};\n\n/**\n * Builds an effect-native {@link ClientServicesRpc} from Promise/{@link PbStream} shaped\n * {@link ClientServices} implementations, without a wire hop. Used by in-process providers\n * (e.g. `LocalClientServices`) so their consumers use the same effect surface as remote proxies.\n */\nexport const makeRpcFromServices = (services: () => Partial<ClientServices>): ClientServicesRpc => {\n const rpc: Record<string, Record<string, (...args: any[]) => unknown>> = {};\n for (const [tag, rpcDef] of ClientServicesRpcs.requests) {\n const [serviceKey, methodName] = parseTag(tag);\n const service = (rpc[serviceKey] ??= {});\n const resolveMethod = () => resolveServiceMethod(services(), serviceKey, methodName, tag);\n\n if (RpcSchema.isStreamSchema(rpcDef.successSchema)) {\n service[methodName] = (request?: unknown) =>\n pbStreamToStream(() => resolveMethod()(request) as PbStream<unknown>);\n } else {\n service[methodName] = (request?: unknown) =>\n Effect.tryPromise({ try: async () => resolveMethod()(request), catch: toError });\n }\n }\n return rpc as unknown as ClientServicesRpc;\n};\n\n//\n// Stream adapters.\n//\n\n/**\n * Adapts a protobuf service stream to an effect stream.\n * Unbounded buffering matches the push semantics of the source stream.\n */\nexport const pbStreamToStream = <T>(open: () => PbStream<T>): Stream.Stream<T, Error> =>\n Stream.asyncScoped<T, Error>(\n (emit) =>\n Effect.acquireRelease(Effect.try({ try: open, catch: toError }), (stream) =>\n Effect.promise(async () => stream.close()),\n ).pipe(\n Effect.tap((stream) =>\n Effect.sync(() => {\n stream.subscribe(\n (data) => void emit.single(data),\n (err) => void (err ? emit.fail(toError(err)) : emit.end()),\n );\n }),\n ),\n ),\n 'unbounded',\n );\n\n/**\n * Adapts an effect stream to a protobuf service stream.\n * Consumer close interrupts the underlying rpc subscription.\n */\nexport const streamToPbStream = <T>(runtime: Runtime.Runtime<never>, stream: Stream.Stream<T, unknown>): PbStream<T> =>\n new PbStream<T>(({ ready, next, close }) => {\n const fiber = stream.pipe(\n Stream.onStart(Effect.sync(ready)),\n Stream.runForEach((item) => Effect.sync(() => next(item))),\n Effect.matchCauseEffect({\n onFailure: (cause) =>\n Effect.sync(() => close(Cause.isInterruptedOnly(cause) ? undefined : toError(Cause.squash(cause)))),\n onSuccess: () => Effect.sync(() => close()),\n }),\n Runtime.runFork(runtime),\n );\n\n return () => {\n fiber.unsafeInterruptAsFork(fiber.id());\n };\n });\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as RpcClient from '@effect/rpc/RpcClient';\nimport * as Effect from 'effect/Effect';\nimport * as Exit from 'effect/Exit';\nimport * as Layer from 'effect/Layer';\nimport * as Runtime from 'effect/Runtime';\nimport * as Scope from 'effect/Scope';\n\nimport { type Stream as PbStream } from '@dxos/codec-protobuf/stream';\nimport { EffectEx } from '@dxos/effect';\nimport { type BridgeService as BridgeServiceRpc } from '@dxos/protocols/proto/dxos/mesh/bridge';\nimport { BridgeService } from '@dxos/protocols/rpc';\n\nimport * as Rpc from './Rpc';\nimport { pbStreamToStream, streamToPbStream } from './service-rpc';\n\n/**\n * The system channel runs the WebRTC {@link BridgeServiceRpc} in the worker→tab direction: the worker\n * calls the tab's network stack to proxy RTC connections. It is served over its own {@link MessagePort}\n * (the reverse of the app port) via effect-rpc, replacing the legacy protobuf duplex peer.\n *\n * `BridgeServiceRpc` is the proto-shaped interface (`Promise`/{@link PbStream}) that\n * `RtcTransportService` implements and `RtcTransportProxyFactory` consumes; the helpers below adapt\n * it to and from the effect-rpc surface.\n */\n\nconst toError = (cause: unknown): Error => (cause instanceof Error ? cause : new Error(String(cause)));\n\n/**\n * Serves a proto-shaped {@link BridgeServiceRpc} (the tab's `RtcTransportService`) over a\n * {@link MessagePort} via effect-rpc. The worker consumes it with {@link makeBridgeServiceClient}.\n */\nexport const serveBridgeService = (port: MessagePort, service: BridgeServiceRpc): Rpc.GroupServer => {\n const unary =\n <Req, Res>(method: (request: Req) => Promise<Res>) =>\n (payload: Req) =>\n Effect.tryPromise({ try: () => method(payload), catch: toError });\n\n const handlers = {\n 'BridgeService.open': (payload: Parameters<BridgeServiceRpc['open']>[0]) =>\n pbStreamToStream(() => service.open(payload)),\n 'BridgeService.sendSignal': unary((request: Parameters<BridgeServiceRpc['sendSignal']>[0]) =>\n service.sendSignal(request),\n ),\n 'BridgeService.sendData': unary((request: Parameters<BridgeServiceRpc['sendData']>[0]) =>\n service.sendData(request),\n ),\n 'BridgeService.close': unary((request: Parameters<BridgeServiceRpc['close']>[0]) => service.close(request)),\n 'BridgeService.getDetails': unary((request: Parameters<BridgeServiceRpc['getDetails']>[0]) =>\n service.getDetails(request),\n ),\n 'BridgeService.getStats': unary((request: Parameters<BridgeServiceRpc['getStats']>[0]) =>\n service.getStats(request),\n ),\n };\n\n // Dispatched dynamically across the group; per-method handler types cannot be expressed statically.\n return Rpc.serve(port, BridgeService.Rpcs, BridgeService.Rpcs.toLayer(handlers as never), {\n disableTracing: true,\n concurrency: 'unbounded',\n });\n};\n\n/**\n * Builds a proto-shaped {@link BridgeServiceRpc} backed by an effect-rpc client over a\n * {@link MessagePort}. Used in the worker to hand `RtcTransportProxyFactory` a bridge that proxies to\n * the tab. The returned `close` releases the transport scope.\n */\nexport const makeBridgeServiceClient = async (\n port: MessagePort,\n): Promise<{ bridgeService: BridgeServiceRpc; close: () => Promise<void> }> =>\n bridgeServiceClientFromEffect((scope) => Rpc.makeClient(port, BridgeService.Rpcs).pipe(Scope.extend(scope)));\n\n/**\n * Builds a proto-shaped {@link BridgeServiceRpc} over a pre-built {@link RpcClient.Protocol} (the\n * value the tag resolves to — e.g. the worker→client protocol handed to a worker-framework session\n * via effect context) rather than a raw {@link MessagePort}.\n */\nexport const makeBridgeServiceClientOverProtocol = async (\n protocol: RpcClient.Protocol['Type'],\n): Promise<{ bridgeService: BridgeServiceRpc; close: () => Promise<void> }> =>\n bridgeServiceClientFromEffect((scope) =>\n Rpc.makeClientOverProtocol(Layer.succeed(RpcClient.Protocol, protocol), BridgeService.Rpcs).pipe(\n Scope.extend(scope),\n ),\n );\n\n/** Adapts an effect-rpc {@link BridgeService.Client} (built by the caller) to the proto-shaped surface. */\nconst bridgeServiceClientFromEffect = async (\n makeClient: (scope: Scope.Scope) => Effect.Effect<unknown, never, never>,\n): Promise<{ bridgeService: BridgeServiceRpc; close: () => Promise<void> }> => {\n const scope = Effect.runSync(Scope.make());\n const client = (await EffectEx.runPromise(makeClient(scope))) as BridgeService.Client;\n\n const bridge = client.BridgeService;\n const bridgeService: BridgeServiceRpc = {\n open: (request) => streamToPbStream(Runtime.defaultRuntime, bridge.open(request)),\n sendSignal: (request) => EffectEx.runPromise(bridge.sendSignal(request)),\n sendData: (request) => EffectEx.runPromise(bridge.sendData(request)),\n close: (request) => EffectEx.runPromise(bridge.close(request)),\n getDetails: (request) => EffectEx.runPromise(bridge.getDetails(request)),\n getStats: (request) => EffectEx.runPromise(bridge.getStats(request)),\n };\n\n return {\n bridgeService,\n close: async () => {\n await EffectEx.runPromise(Scope.close(scope, Exit.void));\n },\n };\n};\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport base from 'base-x';\n\nimport { schema } from '@dxos/protocols/proto';\nimport { Invitation } from '@dxos/protocols/proto/dxos/client/services';\n\n// Encode with URL-safe alpha-numeric characters.\nconst base62 = base('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');\n\nconst codec = schema.getCodecForType('dxos.client.services.Invitation');\n\n/**\n * Encodes and decodes an invitation proto into/from alphanumeric chars.\n */\nexport class InvitationEncoder {\n static decode(text: string): Invitation {\n const decodedInvitation = codec.decode(base62.decode(text));\n if (decodedInvitation.type === Invitation.Type.MULTIUSE) {\n decodedInvitation.type = Invitation.Type.INTERACTIVE;\n decodedInvitation.multiUse = true;\n }\n return decodedInvitation;\n }\n\n static encode(invitation: Invitation): string {\n return base62.encode(\n codec.encode({\n invitationId: invitation.invitationId,\n type: invitation.type,\n kind: invitation.kind,\n authMethod: invitation.authMethod,\n swarmKey: invitation.swarmKey,\n state: invitation.state,\n timeout: invitation.timeout,\n guestKeypair: invitation.guestKeypair,\n spaceId: invitation.spaceId,\n lifetime: invitation.lifetime,\n created: invitation.created,\n // TODO(wittjosiah): Make these optional to encode for greater privacy.\n ...(invitation.spaceKey ? { spaceKey: invitation.spaceKey } : {}),\n ...(invitation.target ? { target: invitation.target } : {}),\n }),\n );\n }\n}\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { MulticastObservable, type Observable, type Subscriber } from '@dxos/async';\nimport { invariant } from '@dxos/invariant';\nimport { Invitation } from '@dxos/protocols/proto/dxos/client/services';\n\nexport const AUTHENTICATION_CODE_LENGTH = 6;\n\nexport const INVITATION_TIMEOUT = 3 * 60_000; // 3 mins.\n\nexport interface Invitations {\n created: MulticastObservable<CancellableInvitation[]>;\n accepted: MulticastObservable<AuthenticatingInvitation[]>;\n share(options?: Partial<Invitation>): CancellableInvitation;\n join(invitation: Invitation): AuthenticatingInvitation;\n}\n\n/**\n * Base class for all invitation observables and providers.\n */\nexport class CancellableInvitation extends MulticastObservable<Invitation> {\n private readonly _onCancel: () => Promise<void>;\n\n constructor({\n subscriber,\n initialInvitation,\n onCancel,\n }: {\n subscriber: Observable<Invitation> | Subscriber<Invitation>;\n initialInvitation: Invitation;\n onCancel: () => Promise<void>;\n }) {\n super(subscriber, initialInvitation);\n this._onCancel = onCancel;\n }\n\n cancel(): Promise<void> {\n return this._onCancel();\n }\n\n get expired() {\n const expiration = getExpirationTime(this.get());\n return expiration && expiration.getTime() < Date.now();\n }\n\n get expiry() {\n return getExpirationTime(this.get());\n }\n}\n\n/**\n * Cancelable observer that relays authentication requests.\n */\nexport class AuthenticatingInvitation extends CancellableInvitation {\n private readonly _onAuthenticate: (authCode: string) => Promise<void>;\n\n constructor({\n subscriber,\n initialInvitation,\n onCancel,\n onAuthenticate,\n }: {\n subscriber: Observable<Invitation> | Subscriber<Invitation>;\n initialInvitation: Invitation;\n onCancel: () => Promise<void>;\n onAuthenticate: (authCode: string) => Promise<void>;\n }) {\n super({ subscriber, initialInvitation, onCancel });\n this._onAuthenticate = onAuthenticate;\n }\n\n async authenticate(authCode: string): Promise<void> {\n return this._onAuthenticate(authCode);\n }\n}\n\n/**\n * Testing util to wrap non-authenticating observable with promise.\n * Don't use this in production code.\n * @deprecated\n */\n// TODO(wittjosiah): Move to testing.\nexport const wrapObservable = async (observable: CancellableInvitation): Promise<Invitation> => {\n return new Promise((resolve, reject) => {\n const subscription = observable.subscribe(\n (invitation: Invitation | undefined) => {\n // TODO(burdon): Throw error if auth requested.\n invariant(invitation?.state === Invitation.State.SUCCESS);\n subscription.unsubscribe();\n resolve(invitation);\n },\n (err: Error) => {\n subscription.unsubscribe();\n reject(err);\n },\n );\n });\n};\n\nexport const getExpirationTime = (invitation: Partial<Invitation>): Date | undefined => {\n if (!(invitation.created && invitation.lifetime)) {\n return;\n }\n return new Date(invitation.created.getTime() + invitation.lifetime * 1000);\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\nimport { type Event } from '@dxos/async';\nimport { schema } from '@dxos/protocols/proto';\nimport type {\n ContactsService,\n DevicesService,\n EdgeAgentService,\n FeedService,\n IdentityService,\n InvitationsService,\n LoggingService,\n NetworkService,\n SpacesService,\n SystemService,\n} from '@dxos/protocols/proto/dxos/client/services';\nimport type { DevtoolsHost } from '@dxos/protocols/proto/dxos/devtools/host';\nimport type { QueryService } from '@dxos/protocols/proto/dxos/echo/query';\nimport type { DataService } from '@dxos/protocols/proto/dxos/echo/service';\nimport type { AppService, ShellService } from '@dxos/protocols/proto/dxos/iframe';\nimport { type ServiceBundle } from '@dxos/rpc';\n\nimport { type ClientServicesRpc } from './service-rpc';\n\nexport type { FeedService } from '@dxos/protocols/proto/dxos/client/services';\n\n//\n// NOTE: Should contain client/proxy dependencies only.\n//\n\nexport type ClientServices = {\n SystemService: SystemService;\n NetworkService: NetworkService;\n LoggingService: LoggingService;\n\n IdentityService: IdentityService;\n InvitationsService: InvitationsService;\n DevicesService: DevicesService;\n SpacesService: SpacesService;\n\n DataService: DataService;\n QueryService: QueryService;\n FeedService: FeedService;\n\n ContactsService: ContactsService;\n EdgeAgentService: EdgeAgentService;\n\n // TODO(burdon): Deprecated.\n DevtoolsHost: DevtoolsHost;\n};\n\n/**\n * Provide access to client services definitions and service handler.\n */\nexport interface ClientServicesProvider {\n /**\n * The connection to the services provider was terminated.\n * This should fire if the services disconnect unexpectedly or during a client reset.\n */\n closed: Event<Error | undefined>;\n\n /**\n * The underlying service connection was re-established.\n * Fires after all reconnection callbacks have completed.\n */\n reconnected?: Event<void>;\n\n /**\n * Register a callback to be invoked when services reconnect.\n * The callback should re-establish any RPC streams.\n * Reconnection waits for all callbacks to complete before emitting `reconnected`.\n */\n onReconnect?: (callback: () => Promise<void>) => void;\n\n /**\n * Effect-native client for all client services, inferred from the effect-rpc definitions.\n * Preferred surface for new consumers; must be re-read after reconnect rather than cached.\n * Effects it produces require only the default runtime and can be run with any `Runtime<never>`.\n */\n rpc: ClientServicesRpc;\n\n /**\n * @deprecated Prefer {@link rpc}. Promise/`Stream` shaped services derived from {@link rpc}.\n */\n services: Partial<ClientServices>;\n\n // TODO(burdon): Should take context from parent?\n open(): Promise<unknown>;\n close(): Promise<unknown>;\n}\n\nexport type AppServiceBundle = {\n AppService: AppService;\n};\n\nexport const appServiceBundle: ServiceBundle<AppServiceBundle> = {\n AppService: schema.getService('dxos.iframe.AppService'),\n};\n\nexport type ShellServiceBundle = {\n ShellService: ShellService;\n};\n\nexport const shellServiceBundle: ServiceBundle<ShellServiceBundle> = {\n ShellService: schema.getService('dxos.iframe.ShellService'),\n};\n","//\n// Copyright 2021 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { type MulticastObservable } from '@dxos/async';\nimport { type SpecificCredential } from '@dxos/credentials';\nimport { type Obj } from '@dxos/echo';\nimport { type EchoDatabase, type SpaceSyncState } from '@dxos/echo-client';\nimport { type PublicKey, type SpaceId } from '@dxos/keys';\nimport { type Messenger } from '@dxos/protocols';\nimport {\n type Contact,\n type CreateEpochRequest,\n type Invitation,\n SpaceArchive,\n type Space as SpaceData,\n type SpaceMember,\n type SpaceState,\n type UpdateMemberRoleRequest,\n} from '@dxos/protocols/proto/dxos/client/services';\nimport { type EdgeReplicationSetting } from '@dxos/protocols/proto/dxos/echo/metadata';\nimport { type SpaceSnapshot } from '@dxos/protocols/proto/dxos/echo/snapshot';\nimport { type Credential, type Epoch, type MembershipPolicy } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nimport { type CancellableInvitation } from './invitations';\nimport { type SpaceProperties } from './types';\n\nexport type CreateEpochOptions = {\n migration?: CreateEpochRequest.Migration;\n automergeRootUrl?: string;\n};\n\nexport type ExportSpaceOptions = {\n /**\n * Archive format.\n * @default SpaceArchive.Format.BINARY\n */\n format?: SpaceArchive.Format;\n};\n\nexport interface SpaceInternal {\n get db(): EchoDatabase;\n get data(): SpaceData;\n\n getCredentials(): Promise<Credential[]>;\n\n getEpochs(): Promise<SpecificCredential<Epoch>[]>;\n\n // TODO(dmaretskyi): Return epoch info.\n createEpoch(options?: CreateEpochOptions): Promise<void>;\n\n // TOOD(burdon): Start to factor out credentials.\n removeMember(memberKey: PublicKey): Promise<void>;\n\n export(options?: ExportSpaceOptions): Promise<SpaceArchive>;\n\n /**\n * Migrate space data to the latest version.\n */\n migrate(): Promise<void>;\n\n setEdgeReplicationPreference(setting: EdgeReplicationSetting): Promise<void>;\n\n /**\n * Waits until the space is fully synced with EDGE.\n * @throws If the EDGE sync is disabled.\n */\n syncToEdge(opts?: {\n onProgress: (state: SpaceSyncState.PeerState | undefined) => void;\n timeout?: number;\n }): Promise<void>;\n}\n\nexport const SPACE_TAG = Symbol('dxos.client.protocol.Space');\n\nexport interface Space extends Messenger {\n readonly [SPACE_TAG]: true;\n\n /**\n * @deprecated Use `id`.\n */\n get key(): PublicKey;\n\n /**\n * Unique space identifier.\n */\n get id(): SpaceId;\n\n /**\n * Echo database.\n */\n get db(): EchoDatabase;\n\n // TODO(burdon): Replace with state?\n get isOpen(): boolean;\n\n /**\n * Immutable tags assigned at space creation time.\n * Available on closed spaces.\n */\n get tags(): string[];\n\n /**\n * Immutable membership policy assigned at space creation time.\n * Available on closed spaces.\n */\n get membershipPolicy(): MembershipPolicy;\n\n /**\n * Current state of the space.\n * The database is ready to be used in `SpaceState.SPACE_READY` state.\n * Presence is available in `SpaceState.SPACE_CONTROL_ONLY` state.\n */\n get state(): MulticastObservable<SpaceState>;\n\n /**\n * Properties object.\n */\n get properties(): Obj.OfShape<SpaceProperties>;\n\n /**\n * Current state of space pipeline.\n */\n get pipeline(): MulticastObservable<SpaceData.PipelineState>;\n\n get invitations(): MulticastObservable<CancellableInvitation[]>;\n\n get members(): MulticastObservable<SpaceMember[]>;\n\n /**\n * @deprecated\n */\n // TODO(wittjosiah): Audit and remove. This should not be exposed (or marked as internal).\n get internal(): SpaceInternal;\n\n /**\n * Activates the space enabling the use of the database and starts replication with peers.\n * The setting is persisted on the local device.\n */\n // TODO(wittjosiah): Rename activate/deactivate?\n open(): Promise<void>;\n\n /**\n * Deactivates the space stopping replication with other peers.\n * The space will not auto-open on the next app launch.\n * The setting is persisted on the local device.\n */\n close(): Promise<void>;\n\n /**\n * Tombstones (soft-deletes) the space and replicates the deletion to the user's other devices.\n * Every device stops replicating and unloads the space. Underlying data is not removed until\n * garbage collection (future work). This is terminal: the space cannot be re-opened via {@link open}.\n */\n delete(): Promise<void>;\n\n /**\n * Waits until the space is in the ready state, with database initialized.\n */\n waitUntilReady(): Promise<this>;\n\n createSnapshot(): Promise<SpaceSnapshot>;\n\n // TODO(burdon): Create invitation?\n // TODO(burdon): Factor out membership, etc.\n share(options?: Partial<Invitation>): CancellableInvitation;\n admitContact(contact: Contact): Promise<void>;\n updateMemberRole(request: Omit<UpdateMemberRoleRequest, 'spaceKey'>): Promise<void>;\n}\n\nexport const isSpace = (object: unknown): object is Space =>\n typeof object === 'object' && object != null && (object as Space)[SPACE_TAG] === true;\n\n// TODO(burdon): Create lower-level definition (HasId, db, etc.) and move to @dxos/echo.\nexport const SpaceSchema: Schema.Schema<Space> = Schema.Any.pipe(\n Schema.filter((space) => isSpace(space)),\n Schema.annotations({ title: 'Space' }),\n);\n","//\n// Copyright 2023 DXOS.org\n//\n\n/**\n * Timeout for making rpc connections from remote proxies.\n */\nexport const PROXY_CONNECTION_TIMEOUT = 30_000;\n\n/**\n * Timeout for the device to be added to the trusted set during auth.\n */\nexport const AUTH_TIMEOUT = 30_000;\n\n/**\n * Timeout for how long the remote client will wait before assuming the connection is lost.\n */\nexport const STATUS_TIMEOUT = 10_000;\n\n/**\n * Timeout for waiting before stealing resource lock.\n */\nexport const RESOURCE_LOCK_TIMEOUT = 3_000;\n\n/**\n * Timeout for space properties to be loaded in the set of tracked items.\n * Accounts for latency between SpaceService reporting the space as READY and DataService streaming the item states.\n */\nexport const LOAD_PROPERTIES_TIMEOUT = 3_000;\n\n/**\n * Timeout for creating new spaces.\n */\nexport const CREATE_SPACE_TIMEOUT = 5_000;\n\n/**\n * Timeout for creating new spaces.\n */\nexport const IMPORT_SPACE_TIMEOUT = 30_000;\n\n/**\n * Timeout for loading of control feeds.\n */\nexport const LOAD_CONTROL_FEEDS_TIMEOUT = 3_000;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAM,4BAA4B,OAAO;AAIzC,IAAM,cAAiB,UAAmD;;;;;;AAO1E,IAAa,0BACX,UACA,OACA,YAEA,OAAO,IAAI,aAAa;CACtB,MAAM,gBAAgB,UAAU,UAAU,SAAS,MAAM;CACzD,MAAM,WAAW,gBAAgB,UAAU,gBAAgB,WAAW,KAAK,CAAC,IAAI,WAAW,KAAK;CAChG,MAAM,gBAAgB,gBAAgB,SAAS,KAAK,MAAM,aAAa,UAAU,YAAY,CAAC,CAAC,IAAI;CAMnG,MAAM,UAAU,OAAO,MAAM,MAAM,aAAa;CAChD,OAAO,OAAO,UAAU,KAAK,WAAW,QAAQ,GAAG,EAAE,gBAAgB,SAAS,kBAAkB,KAAK,CAAC,CAAC,CAAC,KACtG,OAAO,QAAQ,OAAO,CACxB;AACF,CAAC,CAAC,CAAC,KAAK,OAAO,KAAK;;;;;AAMtB,IAAa,cACX,MACA,OACA,YAEA,uBACE,UAAU,oBAAoB;CAAE,MAAM;CAAG,aAA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;;ACTA,IAAa,mBAAoD,EAC/D,YAAY,OAAO,WAAW,wBAAwB,EACxD;AAMA,IAAa,qBAAwD,EACnE,cAAc,OAAO,WAAW,0BAA0B,EAC5D;;;AChCA,IAAa,YAAY,OAAO,4BAA4B;AAiG5D,IAAa,WAAW,WACtB,OAAO,WAAW,YAAY,UAAU,QAAS,OAAiB,eAAe;AAGnF,IAAa,cAAoC,OAAO,IAAI,KAC1D,OAAO,QAAQ,UAAU,QAAQ,KAAK,CAAC,GACvC,OAAO,YAAY,EAAE,OAAO,QAAQ,CAAC,CACvC;;;;;;AC5KA,IAAa,2BAA2B;;;;AAKxC,IAAa,eAAe;;;;AAK5B,IAAa,iBAAiB;;;;AAK9B,IAAa,wBAAwB;;;;;AAMrC,IAAa,0BAA0B;;;;AAKvC,IAAa,uBAAuB;;;;AAKpC,IAAa,uBAAuB;;;;AAKpC,IAAa,6BAA6B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
import { Annotation, DXN, Feed, Ref, Type } from "@dxos/echo";
|
|
3
|
+
//#region src/types/SpaceProperties.ts
|
|
4
|
+
var SpacePropertiesSchema = Schema.Struct({
|
|
5
|
+
edgeReplication: Schema.optional(Schema.Boolean),
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated
|
|
8
|
+
*/
|
|
9
|
+
invocationTraceFeed: Schema.optional(Ref.Ref(Feed.Feed)),
|
|
10
|
+
/**
|
|
11
|
+
* Space-wide kill-switch for trigger execution.
|
|
12
|
+
* When true, the local trigger dispatcher is stopped for the space (no triggers run locally).
|
|
13
|
+
* Per-trigger local/edge routing is controlled by the trigger's `remote` flag.
|
|
14
|
+
*/
|
|
15
|
+
triggersDisabled: Schema.optional(Schema.Boolean),
|
|
16
|
+
name: Schema.optional(Schema.String),
|
|
17
|
+
description: Schema.optional(Schema.String),
|
|
18
|
+
icon: Schema.optional(Schema.String),
|
|
19
|
+
iconHue: Schema.optional(Schema.String),
|
|
20
|
+
hue: Schema.optional(Schema.String)
|
|
21
|
+
});
|
|
22
|
+
var SpaceProperties = class extends Type.makeObject(DXN.make("org.dxos.type.spaceProperties", "0.1.0"))(SpacePropertiesSchema.pipe(Annotation.HiddenAnnotation.set(true))) {};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { SpaceProperties, SpacePropertiesSchema };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","names":[],"sources":["../../src/types/SpaceProperties.ts"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Annotation, DXN, Feed, Ref, Type } from '@dxos/echo';\n\nexport const SpacePropertiesSchema = Schema.Struct({\n //\n // System properties.\n //\n\n // TODO(burdon): Change to mode (no booleans?)\n // TODO(wittjosiah): Make optional with default value.\n edgeReplication: Schema.optional(Schema.Boolean),\n\n /**\n * @deprecated\n */\n invocationTraceFeed: Schema.optional(Ref.Ref(Feed.Feed)),\n\n /**\n * Space-wide kill-switch for trigger execution.\n * When true, the local trigger dispatcher is stopped for the space (no triggers run locally).\n * Per-trigger local/edge routing is controlled by the trigger's `remote` flag.\n */\n triggersDisabled: Schema.optional(Schema.Boolean),\n\n //\n // User properties.\n //\n\n name: Schema.optional(Schema.String),\n description: Schema.optional(Schema.String),\n icon: Schema.optional(Schema.String),\n iconHue: Schema.optional(Schema.String),\n hue: Schema.optional(Schema.String),\n});\n\nexport type SpacePropertiesSchema = Schema.Schema.Type<typeof SpacePropertiesSchema>;\n\n// TODO(burdon): Pipe Schem.optional, or partial to entire struct to make everything optional?\n// TODO(burdon): Is separate schema def required for forms? Can it be extracted from SpaceProperties?\nexport class SpaceProperties extends Type.makeObject<SpaceProperties>(\n DXN.make('org.dxos.type.spaceProperties', '0.1.0'),\n)(SpacePropertiesSchema.pipe(Annotation.HiddenAnnotation.set(true))) {}\n"],"mappings":";;;AAQA,IAAa,wBAAwB,OAAO,OAAO;CAOjD,iBAAiB,OAAO,SAAS,OAAO,OAAO;;;;CAK/C,qBAAqB,OAAO,SAAS,IAAI,IAAI,KAAK,IAAI,CAAC;;;;;;CAOvD,kBAAkB,OAAO,SAAS,OAAO,OAAO;CAMhD,MAAM,OAAO,SAAS,OAAO,MAAM;CACnC,aAAa,OAAO,SAAS,OAAO,MAAM;CAC1C,MAAM,OAAO,SAAS,OAAO,MAAM;CACnC,SAAS,OAAO,SAAS,OAAO,MAAM;CACtC,KAAK,OAAO,SAAS,OAAO,MAAM;AACpC,CAAC;AAMD,IAAa,kBAAb,cAAqC,KAAK,WACxC,IAAI,KAAK,iCAAiC,OAAO,CACnD,CAAC,CAAC,sBAAsB,KAAK,WAAW,iBAAiB,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as RpcClient from '@effect/rpc/RpcClient';
|
|
2
|
+
import * as RpcServer from '@effect/rpc/RpcServer';
|
|
3
|
+
import * as Effect from 'effect/Effect';
|
|
4
|
+
import * as Layer from 'effect/Layer';
|
|
5
|
+
import type * as Scope from 'effect/Scope';
|
|
6
|
+
import { RpcTiming } from '@dxos/worker-framework';
|
|
7
|
+
export type ServeOptions = {
|
|
8
|
+
disableTracing?: boolean;
|
|
9
|
+
concurrency?: number | 'unbounded';
|
|
10
|
+
/**
|
|
11
|
+
* When enabled, stamps each outbound RPC with a `Date.now()` send time and logs queue-wait /
|
|
12
|
+
* service durations on the worker above {@link RpcTiming.Options.minLogMs} (default 100 ms).
|
|
13
|
+
*/
|
|
14
|
+
timing?: boolean | RpcTiming.Options;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Builds an effect-native RPC client over a caller-supplied {@link RpcClient.Protocol} layer.
|
|
18
|
+
* Transport-agnostic: consumers provide the Worker-platform protocol (see {@link makeClient}) or a
|
|
19
|
+
* byte protocol over a legacy transport (e.g. `@dxos/rpc`'s RpcPort layer for iframe/devtools bridges).
|
|
20
|
+
*/
|
|
21
|
+
export declare const makeClientOverProtocol: <G, ProtocolError, ProtocolRequirements>(protocol: Layer.Layer<RpcClient.Protocol, ProtocolError, ProtocolRequirements>, group: G, options?: Pick<ServeOptions, 'disableTracing' | 'timing'>) => Effect.Effect<unknown, never, Scope.Scope | ProtocolRequirements>;
|
|
22
|
+
/**
|
|
23
|
+
* Builds an effect-native RPC client over a {@link MessagePort} using the native Worker platform
|
|
24
|
+
* protocol (structured-clone frames, transferables supported).
|
|
25
|
+
*/
|
|
26
|
+
export declare const makeClient: <G>(port: MessagePort, group: G, options?: Pick<ServeOptions, 'disableTracing' | 'timing'>) => Effect.Effect<unknown, never, Scope.Scope>;
|
|
27
|
+
export type GroupServer = {
|
|
28
|
+
open(): Promise<void>;
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Serves an {@link RpcGroup} on a {@link MessagePort} via the native Worker runner protocol.
|
|
33
|
+
*/
|
|
34
|
+
export declare const serve: <G, H extends Layer.Layer<never, never, never>>(port: MessagePort, group: G, handlers: H, options?: ServeOptions) => GroupServer;
|
|
35
|
+
/**
|
|
36
|
+
* Serves an {@link RpcGroup} over a caller-supplied {@link RpcServer.Protocol} layer.
|
|
37
|
+
* Transport-agnostic counterpart to {@link makeClientOverProtocol}: consumers provide a byte
|
|
38
|
+
* protocol over a legacy transport (e.g. `@dxos/rpc`'s RpcPort layer for iframe/devtools bridges).
|
|
39
|
+
*/
|
|
40
|
+
export declare const serveOverProtocol: <G, H extends Layer.Layer<never, never, never>>(protocol: Layer.Layer<RpcServer.Protocol>, group: G, handlers: H, options?: ServeOptions) => GroupServer;
|
|
41
|
+
//# sourceMappingURL=Rpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rpc.d.ts","sourceRoot":"","sources":["../../../src/Rpc.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,SAAS,MAAM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KAAK,EAAE,KAAK,CAAC,QAC3D,WAAW,SACV,CAAC,YACE,CAAC,YACD,YAAY,KACrB,WA6CF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAAE,CAAC,SAAS,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,YACnE,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,SAClC,CAAC,YACE,CAAC,YACD,YAAY,KACrB,WAiDF,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as RpcClient from '@effect/rpc/RpcClient';
|
|
2
|
+
import { type BridgeService as BridgeServiceRpc } from '@dxos/protocols/proto/dxos/mesh/bridge';
|
|
3
|
+
import * as Rpc from './Rpc';
|
|
4
|
+
/**
|
|
5
|
+
* Serves a proto-shaped {@link BridgeServiceRpc} (the tab's `RtcTransportService`) over a
|
|
6
|
+
* {@link MessagePort} via effect-rpc. The worker consumes it with {@link makeBridgeServiceClient}.
|
|
7
|
+
*/
|
|
8
|
+
export declare const serveBridgeService: (port: MessagePort, service: BridgeServiceRpc) => Rpc.GroupServer;
|
|
9
|
+
/**
|
|
10
|
+
* Builds a proto-shaped {@link BridgeServiceRpc} backed by an effect-rpc client over a
|
|
11
|
+
* {@link MessagePort}. Used in the worker to hand `RtcTransportProxyFactory` a bridge that proxies to
|
|
12
|
+
* the tab. The returned `close` releases the transport scope.
|
|
13
|
+
*/
|
|
14
|
+
export declare const makeBridgeServiceClient: (port: MessagePort) => Promise<{
|
|
15
|
+
bridgeService: BridgeServiceRpc;
|
|
16
|
+
close: () => Promise<void>;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Builds a proto-shaped {@link BridgeServiceRpc} over a pre-built {@link RpcClient.Protocol} (the
|
|
20
|
+
* value the tag resolves to — e.g. the worker→client protocol handed to a worker-framework session
|
|
21
|
+
* via effect context) rather than a raw {@link MessagePort}.
|
|
22
|
+
*/
|
|
23
|
+
export declare const makeBridgeServiceClientOverProtocol: (protocol: RpcClient.Protocol['Type']) => Promise<{
|
|
24
|
+
bridgeService: BridgeServiceRpc;
|
|
25
|
+
close: () => Promise<void>;
|
|
26
|
+
}>;
|
|
27
|
+
//# sourceMappingURL=bridge-rpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge-rpc.d.ts","sourceRoot":"","sources":["../../../src/bridge-rpc.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AASnD,OAAO,EAAE,KAAK,aAAa,IAAI,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAGhG,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAe7B;;;GAGG;AACH,eAAO,MAAM,kBAAkB,SAAU,WAAW,WAAW,gBAAgB,KAAG,GAAG,CAAC,WA6BrF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,SAC5B,WAAW,KAChB,OAAO,CAAC;IAAE,aAAa,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CACoC,CAAC;AAE/G;;;;GAIG;AACH,eAAO,MAAM,mCAAmC,aACpC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,KACnC,OAAO,CAAC;IAAE,aAAa,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAKvE,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export declare const DEFAULT_CLIENT_CHANNEL = "dxos:app";
|
|
2
2
|
export declare const DEFAULT_INTERNAL_CHANNEL = "dxos:vault";
|
|
3
3
|
export declare const DEFAULT_SHELL_CHANNEL = "dxos:shell";
|
|
4
|
-
export declare const DEFAULT_WORKER_BROADCAST_CHANNEL = "dxos:shared-worker";
|
|
5
4
|
/**
|
|
6
5
|
* @deprecated
|
|
7
6
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,sBAAsB,aAAa,CAAC;AACjD,eAAO,MAAM,wBAAwB,eAAe,CAAC;AACrD,eAAO,MAAM,qBAAqB,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,sBAAsB,aAAa,CAAC;AACjD,eAAO,MAAM,wBAAwB,eAAe,CAAC;AACrD,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAElD;;GAEG;AACH,eAAO,MAAM,iBAAiB,qCAAqC,CAAC;AAEpE;;GAEG;AAEH,eAAO,MAAM,eAAe,YAAY,CAAC;AAEzC,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,aAAa;IAAK,OAAO;CAAK,CAAC;AAM5C,eAAO,MAAM,SAAS,QAAuB,CAAC;AAG9C,eAAO,MAAM,QAAQ,QAAsB,CAAC;AAI5C,eAAO,MAAM,OAAO,QAA4B,CAAC;AAGjD,eAAO,MAAM,QAAQ,QAA4B,CAAC;AAGlD,eAAO,MAAM,UAAU,gBAAgB,CAAC;AAExC,oBAAY,KAAK;IACf,MAAM,cAAc;IACpB,KAAK,aAAa;IAClB,QAAQ,gBAAgB;IACxB,OAAO,eAAe;CACvB;AAED,yBAAiB,KAAK,CAAC,CAAC;IACtB;;OAEG;IACH,SAAgB,GAAG,CAAC,QAAQ,EAAE,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;IACzD,SAAgB,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;CAIpE;AAGD,eAAO,MAAM,cAAc,SAAU,MAAM,WAAW,MAAM,SAAS,MAAM,WAClB,CAAC;AAE1D,4DAA4D;AAC5D,eAAO,MAAM,oBAAoB,SAAU,MAAM,WAAW,MAAM,WAA2C,CAAC"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './bridge-rpc';
|
|
2
2
|
export * from './config';
|
|
3
|
+
export * as Rpc from './Rpc';
|
|
3
4
|
export type * from './echo';
|
|
4
5
|
export type * from './halo';
|
|
5
6
|
export * from './invitations';
|
|
6
7
|
export * from './service';
|
|
8
|
+
export * from './service-rpc';
|
|
7
9
|
export type * from './shell';
|
|
8
10
|
export * from './space';
|
|
9
11
|
export * from './timeouts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,mBAAmB,QAAQ,CAAC;AAC5B,mBAAmB,QAAQ,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,mBAAmB,SAAS,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
|