@phreshos/server 0.1.20 → 0.1.22

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/README.md CHANGED
@@ -42,11 +42,13 @@ await system.appearance.update({
42
42
  void bytes
43
43
  ```
44
44
 
45
- Its JavaScript entry point adapts the Process IPC boundary to these contracts.
45
+ Its JavaScript entry point adapts the Server runtime boundary to these contracts.
46
46
  The SDK owns callbacks, waits, queues, and their cleanup; the boundary owns
47
47
  only the forwarding registrations requested by the SDK.
48
48
 
49
- Importing the SDK injects no message into the child process. The endpoint may
49
+ The same SDK works in either supported Server runtime: a child process uses its
50
+ IPC channel, while a System-owned Worker uses its parent port. Importing the SDK
51
+ injects no message into either runtime. The endpoint may
50
52
  announce its readiness outward, but identity, Theme, Process, readiness,
51
53
  lifecycle, and application values enter only in response to an explicit request
52
54
  or a live registration made by Program code.
package/dist/main.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { system, type System, type SystemProcess, type SystemProgram, type ClientDescription, type SystemProcessEvents, type SystemProcessExit, type SystemProgramEvents, type SystemProgramUninstall, type ProgramDescription, type ServerDescription } from "./system.js";
1
+ export { system } from "./system.js";
2
2
  export { current, type Current, type CurrentClient } from "./current.js";
3
3
  export { type Answerer, type Channel, type ChannelCapture, type ChannelEvents, type ChannelMessage } from "./channel.js";
4
4
  export { type ProgramStartup } from "./startup.js";
@@ -6,4 +6,4 @@ export { type Storage } from "./storage.js";
6
6
  export { ClientServiceHandler, ServerServiceHandler } from "./service.js";
7
7
  export { ServiceHandler, type ClientServiceChannel, type ServerServiceChannel, type ServiceChannel, type ServiceKey, type ServiceLifecycleEvents } from "@phreshos/core";
8
8
  export { Client, Endpoint, Process, Program, Server, type Window, type ProgramProcess } from "./domain.js";
9
- export type { AnswerCapture, AnswerMessage, AnswerObserver, Askable, AskCapture, AskMessage, AskObserver, Capture, Captures, ClientTraffic, ClientDeclaration, Cleanup, DirectoryStat, EndpointDeclaration, EndpointTraffic, EntryStat, EventMessage, EventName, EventObserver, EventOptions, EventSubscriber, Exit, FileStat, Launch, LaunchClient, Layer, LogKind, LogRecord, LogSource, Message, OtherStat, Outcome, Position, ProgramEvents, ProgramPermission, ProgramProcessEvents, ProgramProcessExit, ProgramSql, ProgramStore, ProcessEvents, Publishable, SystemUploads, Upload, ServerTraffic, Size, Subscribable, SubscribableEvents, SubscribableFallback, TimedAskable, TrafficCapture, TrafficEvents, TrafficMessage, Value, Appearance, AppearanceEvents, AppearanceSource, AppearanceSurface, ThemedValue, WritableAppearance, WindowEvents, WindowGeometry, WindowLayer, WindowState } from "@phreshos/core";
9
+ export type { AnswerCapture, AnswerMessage, AnswerObserver, Askable, AskCapture, AskMessage, AskObserver, Capture, Captures, ClientTraffic, ClientDeclaration, Cleanup, DirectoryStat, EndpointDeclaration, EndpointTraffic, EntryStat, EventMessage, EventName, EventObserver, EventOptions, EventSubscriber, Exit, FileStat, Launch, LaunchClient, Layer, LogKind, LogRecord, LogSource, Message, OtherStat, Outcome, Position, ProgramEvents, ProgramPermission, ProgramProcessEvents, ProgramProcessExit, ProgramSql, ProgramStore, ProcessEvents, Publishable, SystemUploads, Upload, ServerTraffic, System, SystemProcess, SystemProcessEntity, SystemProcessEntityEvents, SystemProgram, SystemProgramEntity, SystemProgramProcess, SystemProgramProcessEvents, SystemEndpointEntity, SystemServerEntity, SystemClientEntity, ClientDescription, SystemProcessEvents, SystemProcessExit, SystemProgramEvents, SystemProgramUninstall, ProgramDescription, ServerDescription, Size, Subscribable, SubscribableEvents, SubscribableFallback, TimedAskable, TrafficCapture, TrafficEvents, TrafficMessage, Value, Appearance, AppearanceEvents, AppearanceSource, AppearanceSurface, ThemedValue, WritableAppearance, WindowEvents, WindowGeometry, WindowLayer, WindowState } from "@phreshos/core";
package/dist/system.d.ts CHANGED
@@ -1,126 +1,3 @@
1
- import type { Exit, Layer, Position, ServiceKey, Size, Subscribable, SystemUploads, WritableAppearance } from "@phreshos/core";
2
- import type { ClientServiceHandler, ServerServiceHandler } from "./service.js";
3
- import { type Client, type Process, type Program, type Server } from "./domain.js";
4
- import { type Storage } from "./storage.js";
5
- /** Resolved production description for a Program's Server. */
6
- export type ServerDescription = Readonly<{
7
- /** Absolute directory containing the production Server files. */
8
- location: string;
9
- /** Whether newly created Processes start this Server by default. */
10
- start?: boolean;
11
- /** Command used to install the Server's production dependencies. */
12
- installCommand?: string;
13
- /** Command used to start the Server from its production directory. */
14
- startCommand: string;
15
- }>;
16
- /** Resolved production description for a Program's Client and initial Window. */
17
- export type ClientDescription = Readonly<{
18
- /** Absolute directory containing the production Client files. */
19
- location: string;
20
- /** Whether newly created Processes start this Client by default. */
21
- start?: boolean;
22
- /** Default Window title. */
23
- title?: string;
24
- /** Default Window size. */
25
- size?: Size;
26
- /** Default Window position. */
27
- position?: Position;
28
- /** Default Window layer. */
29
- layer?: Layer;
30
- /** Whether the Window starts minimized. */
31
- minimize?: boolean;
32
- }>;
33
- type Description = Readonly<{
34
- /** Stable identity assigned to the Program. */
35
- identity: string;
36
- /** Human-readable Program name. */
37
- name?: string;
38
- /** Declared Program version. */
39
- version?: string;
40
- /** Short human-readable Program description. */
41
- description?: string;
42
- /** Absolute validated PNG source used to derive the Program's hosted icon sizes. */
43
- icon?: string;
44
- /** Absolute Markdown file describing Program-specific operation to agents. */
45
- agent?: string;
46
- /** Absolute directory used for the Program's persistent storage. */
47
- storage: string;
48
- }>;
49
- /** Complete runtime description used to create a Program. */
50
- export type ProgramDescription = Description & (Readonly<{
51
- /** Required Server description when no Client is described. */
52
- server: ServerDescription;
53
- /** Optional Client description. */
54
- client?: ClientDescription;
55
- }> | Readonly<{
56
- /** Optional Server description. */
57
- server?: ServerDescription;
58
- /** Required Client description when no Server is described. */
59
- client: ClientDescription;
60
- }>);
61
- /** An uninstall reported with the affected Program and removal scope. */
62
- export type SystemProgramUninstall = Readonly<{
63
- /** Program that left the installed state. */
64
- program: Program;
65
- /** Whether all installed resources, including storage, were removed. */
66
- everythingRemoved: boolean;
67
- }>;
68
- /** A Process exit reported with the Process that ended. */
69
- export type SystemProcessExit = Exit & Readonly<{
70
- /** Process that ended. */
71
- process: Process;
72
- }>;
73
- /** Authoritative lifecycle events visible to the Server system. */
74
- export type SystemProgramEvents = {
75
- /** A Program entered the runtime registry. */
76
- create: Program;
77
- /** A Program left the runtime registry. */
78
- forget: Program;
79
- /** A Program entered the installed state. */
80
- install: Program;
81
- /** A Program left the installed state. */
82
- uninstall: SystemProgramUninstall;
83
- };
84
- /** Authoritative Process lifecycle events visible to the Server system. */
85
- export type SystemProcessEvents = {
86
- /** One Process Endpoint entered a new live incarnation. */
87
- endpointStart: Server | Client;
88
- /** One Process Endpoint incarnation ended. */
89
- endpointStop: Server | Client;
90
- /** A Process entered the runtime set. */
91
- create: Process;
92
- /** A Process left the runtime set. */
93
- exit: SystemProcessExit;
94
- };
95
- /** Authoritative Program registry available to a Server endpoint. */
96
- export interface SystemProgram extends Subscribable<SystemProgramEvents, never> {
97
- list(onlyInstalled?: boolean): Promise<Program[]>;
98
- find(identity: string): Promise<Program | null>;
99
- create(source: ProgramDescription | string): Promise<Program>;
100
- }
101
- /** Authoritative Process registry available to a Server endpoint. */
102
- export interface SystemProcess extends Subscribable<SystemProcessEvents, never> {
103
- list(): Promise<Process[]>;
104
- find(identity: string): Promise<Process | null>;
105
- }
106
- /** Authoritative system capabilities available to a Server endpoint. */
107
- export interface System {
108
- /** Native operating-system home storage available to Server endpoints. */
109
- readonly storage: Storage;
110
- /** Complete unresolved Appearance authority owned by the System. */
111
- readonly appearance: WritableAppearance;
112
- readonly program: SystemProgram;
113
- readonly process: SystemProcess;
114
- /** Flat System-owned public uploads capability. */
115
- readonly uploads: SystemUploads;
116
- /** Returns a stable handle for one exact Service identity. */
117
- service<ServiceEvents extends object = {}>(key: ServiceKey & {
118
- endpoint: "server";
119
- }): ServerServiceHandler<ServiceEvents>;
120
- service<ServiceEvents extends object = {}>(key: ServiceKey & {
121
- endpoint: "client";
122
- }): ClientServiceHandler<ServiceEvents>;
123
- }
1
+ import type { System } from "@phreshos/core";
124
2
  /** Authoritative system capabilities for the currently executing Server. */
125
3
  export declare const system: System;
126
- export {};
package/dist/system.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import Events from "./events.js";
2
- import { exit, lifecycleEndpoint, process, program } from "./domain.js";
2
+ import { exit, lifecycleEndpoint, process, program, } from "./domain.js";
3
3
  import { uploads } from "./uploads.js";
4
4
  import ServerAppearance from "./appearance.js";
5
5
  import wire from "./wire.js";
package/dist/wire.d.ts CHANGED
@@ -14,6 +14,7 @@ declare class Wire {
14
14
  private readonly waiting;
15
15
  private readonly impossible;
16
16
  private identityPromise;
17
+ private readonly transport;
17
18
  constructor();
18
19
  send(route: string, ...values: unknown[]): void;
19
20
  request(values: unknown[], timeout?: number): Promise<unknown>;
package/dist/wire.js CHANGED
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
2
2
  import Deadline from "./deadline.js";
3
3
  import { defaultTimeout } from "./events.js";
4
4
  import { deserialize, serialize } from "./messagepack.js";
5
+ import { parentPort } from "node:worker_threads";
5
6
  /** The server endpoint's sole IPC adapter. */
6
7
  class Wire {
7
8
  pending = new Map();
@@ -12,8 +13,9 @@ class Wire {
12
13
  waiting = new Map();
13
14
  impossible = new Map();
14
15
  identityPromise = null;
16
+ transport = endpointTransport();
15
17
  constructor() {
16
- process.on("message", message => {
18
+ this.transport.onMessage(message => {
17
19
  if (!(message instanceof Uint8Array))
18
20
  return;
19
21
  let decoded;
@@ -50,10 +52,10 @@ class Wire {
50
52
  }
51
53
  this.deliver(route, values);
52
54
  });
53
- process.send?.(serialize(["boundary", "ready"]));
55
+ this.transport.send(serialize(["boundary", "ready"]));
54
56
  }
55
57
  send(route, ...values) {
56
- process.send?.(serialize([route, ...values]));
58
+ this.transport.send(serialize([route, ...values]));
57
59
  }
58
60
  request(values, timeout = defaultTimeout) {
59
61
  return this.requestWithin(values, new Deadline(timeout));
@@ -337,6 +339,18 @@ class Wire {
337
339
  stream.wake = null;
338
340
  }
339
341
  }
342
+ function endpointTransport() {
343
+ const worker = parentPort;
344
+ if (worker)
345
+ return {
346
+ onMessage: listener => worker.on("message", listener),
347
+ send: message => worker.postMessage(message)
348
+ };
349
+ return {
350
+ onMessage: listener => { process.on("message", listener); },
351
+ send: message => { process.send?.(message); }
352
+ };
353
+ }
340
354
  const maximumStreamQueue = 256;
341
355
  function failed(error) {
342
356
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phreshos/server",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "The SDK used by a Program's server endpoint.",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",
@@ -42,17 +42,18 @@
42
42
  "check": "tsc --noEmit",
43
43
  "build": "node --run clean && tsc --noEmit false --outDir dist --rootDir source",
44
44
  "verify:package": "node scripts/verify-package.mjs",
45
- "verify": "node --run check && node --run build && node --run verify:package",
45
+ "verify:worker": "node scripts/verify-worker.mjs",
46
+ "verify": "node --run check && node --run build && node --run verify:worker && node --run verify:package",
46
47
  "prepack": "node --run build"
47
48
  },
48
49
  "peerDependencies": {
49
- "@phreshos/core": "^0.1.19"
50
+ "@phreshos/core": "^0.1.21"
50
51
  },
51
52
  "dependencies": {
52
53
  "@msgpack/msgpack": "^3.1.3"
53
54
  },
54
55
  "devDependencies": {
55
- "@phreshos/core": "^0.1.19",
56
+ "@phreshos/core": "^0.1.21",
56
57
  "@types/node": "^26.2.0",
57
58
  "typescript": "^6.0.3"
58
59
  }