@phreshos/server 0.1.12 → 0.1.14

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
@@ -149,10 +149,22 @@ rejects instead of reconfiguring the existing Process.
149
149
  `host.service(key)` creates the exact opaque service handle. The
150
150
  handler exposes its authored `name`, `enabled()`, `waitReady()`, lifecycle
151
151
  subscriptions, and channel; it does not expose its Program or Endpoint as
152
- separate fields. Services are not a second public registry: inspect Programs
153
- and their Endpoint declarations. `program.server?.hasService()` identifies a
154
- declared Service capability, while `await program.server?.docs()` reads its
155
- installed policy and API documentation before the Endpoint starts.
152
+ separate fields. Services are runtime bindings explicitly enabled by their
153
+ providing Endpoints; creating the providing Process remains the Program's
154
+ responsibility.
155
+
156
+ Readiness accepts an optional timeout directly:
157
+
158
+ ```ts
159
+ await service.waitReady(10_000)
160
+ ```
161
+
162
+ Programs may provide one agent-independent operating document. Its availability
163
+ is projected without loading it, and its content is read from the Program:
164
+
165
+ ```ts
166
+ if (program.hasAgent) console.log(await program.agent())
167
+ ```
156
168
 
157
169
  `program.icon()` requests a guaranteed PNG `Blob` in `small`, `medium`, or
158
170
  `large` form without exposing the Program's source path or the system's private
package/dist/domain.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Client as CoreClient, Endpoint as CoreEndpoint, Process as CoreProcess, Program as CoreProgram, Server as CoreServer, type AnswerCapture, type AskCapture, type Cleanup, type ClientDeclaration, type Exit, type Launch, type Position, type ProgramPermission, type ProgramProcess as CoreProgramProcess, type ProgramArea as CoreProgramArea, type Size, type TrafficMessage, type Window as CoreWindow, type WindowState } from "@phreshos/core";
2
2
  import Events from "./events.js";
3
3
  import { type ProgramStartup } from "./startup.js";
4
+ import { type ClientServiceHandler, type ServerServiceHandler } from "./service.js";
4
5
  export interface HandleAddress {
5
6
  identity: string;
6
7
  reference: string;
@@ -15,7 +16,6 @@ export interface ProgramArea extends CoreProgramArea {
15
16
  /** Client-safe Program data transported by the authoritative host. */
16
17
  export interface EndpointDeclarationRecord {
17
18
  start: boolean;
18
- hasService: boolean;
19
19
  }
20
20
  export interface ClientDeclarationRecord extends EndpointDeclarationRecord {
21
21
  title: string | null;
@@ -31,6 +31,7 @@ export interface ProgramRecord {
31
31
  name: string;
32
32
  version: string | null;
33
33
  description: string | null;
34
+ hasAgent: boolean;
34
35
  server: EndpointDeclarationRecord | null;
35
36
  client: ClientDeclarationRecord | null;
36
37
  }
@@ -104,6 +105,8 @@ export interface Endpoint<Events extends object = {}> extends CoreEndpoint<Event
104
105
  export interface Server<Events extends object = {}> extends CoreServer<Events> {
105
106
  /** Returns the Process that owns this Server. */
106
107
  process(): Promise<Process>;
108
+ /** Returns the Service currently exposed by this Server Endpoint. */
109
+ service<ServiceEvents extends object = {}>(): Promise<ServerServiceHandler<ServiceEvents> | null>;
107
110
  }
108
111
  /** Server-visible Client handle. */
109
112
  export interface Client<Events extends object = {}> extends CoreClient<Events> {
@@ -111,6 +114,8 @@ export interface Client<Events extends object = {}> extends CoreClient<Events> {
111
114
  readonly window: Window;
112
115
  /** Returns the Process that owns this Client. */
113
116
  process(): Promise<Process>;
117
+ /** Returns the Service currently exposed by this Client Endpoint. */
118
+ service<ServiceEvents extends object = {}>(): Promise<ClientServiceHandler<ServiceEvents> | null>;
114
119
  }
115
120
  /** Server-visible Client-owned Window capability. */
116
121
  export type Window = CoreWindow;
package/dist/domain.js CHANGED
@@ -43,11 +43,12 @@ class ProgramHandle extends ProgramBase {
43
43
  get name() { return this.record.name; }
44
44
  get version() { return this.record.version; }
45
45
  get description() { return this.record.description; }
46
+ get hasAgent() { return this.record.hasAgent; }
46
47
  get server() {
47
- return this.record.server ? declaration(this.address, "server", this.record.server) : null;
48
+ return this.record.server ? declaration(this.record.server) : null;
48
49
  }
49
50
  get client() {
50
- return this.record.client ? clientDeclaration(this.address, this.record.client) : null;
51
+ return this.record.client ? clientDeclaration(this.record.client) : null;
51
52
  }
52
53
  get address() { return { identity: this.identity, reference: this.reference }; }
53
54
  update(record) {
@@ -59,6 +60,12 @@ class ProgramHandle extends ProgramBase {
59
60
  const answer = await wire.request(["icon", this.address, size]);
60
61
  return new Blob([Uint8Array.from(answer[0])], { type: "image/png" });
61
62
  }
63
+ async agent() {
64
+ if (!this.hasAgent)
65
+ return null;
66
+ const answer = await wire.request(["program-agent", this.address]);
67
+ return answer[0];
68
+ }
62
69
  async installed() {
63
70
  const answer = await wire.request(["installed", this.address]);
64
71
  return answer[0];
@@ -78,16 +85,14 @@ class ProgramHandle extends ProgramBase {
78
85
  await wire.request(["forget", this.address]);
79
86
  }
80
87
  }
81
- function declaration(address, endpoint, record) {
88
+ function declaration(record) {
82
89
  return Object.freeze({
83
- start: record.start,
84
- hasService: () => record.hasService,
85
- docs: () => endpointDocs(address, endpoint, record.hasService)
90
+ start: record.start
86
91
  });
87
92
  }
88
- function clientDeclaration(address, record) {
93
+ function clientDeclaration(record) {
89
94
  return Object.freeze({
90
- ...declaration(address, "client", record),
95
+ ...declaration(record),
91
96
  title: record.title,
92
97
  size: record.size,
93
98
  position: record.position,
@@ -95,12 +100,6 @@ function clientDeclaration(address, record) {
95
100
  minimize: record.minimize
96
101
  });
97
102
  }
98
- async function endpointDocs(address, endpoint, declared) {
99
- if (!declared)
100
- return null;
101
- const answer = await wire.request(["endpoint-docs", address, endpoint]);
102
- return answer[0];
103
- }
104
103
  class ProgramProcessHandle {
105
104
  address;
106
105
  constructor(address, reference) {
package/dist/host.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { DesktopWallpaper, Exit, FileWallpaper, Layer, Position, ServedFile, ClientServiceHandler, ServerServiceHandler, ServiceKey, Size, Subscribable, ThemeProperties, WritableTheme } from "@phreshos/core";
1
+ import type { DesktopWallpaper, Exit, FileWallpaper, Layer, Position, ServedFile, ServiceKey, Size, Subscribable, ThemeProperties, WritableTheme } from "@phreshos/core";
2
+ import type { ClientServiceHandler, ServerServiceHandler } from "./service.js";
2
3
  import { type Client, type Process, type Program, type Server } from "./domain.js";
3
4
  /** Resolved production description for a Program's Server. */
4
5
  export type ServerDescription = Readonly<{
@@ -6,8 +7,6 @@ export type ServerDescription = Readonly<{
6
7
  location: string;
7
8
  /** Whether newly created Processes start this Server by default. */
8
9
  start?: boolean;
9
- /** Absolute Markdown file documenting the Service this Server may expose. */
10
- serviceDocs?: string;
11
10
  /** Command used to install the Server's production dependencies. */
12
11
  installCommand?: string;
13
12
  /** Command used to start the Server from its production directory. */
@@ -19,8 +18,6 @@ export type ClientDescription = Readonly<{
19
18
  location: string;
20
19
  /** Whether newly created Processes start this Client by default. */
21
20
  start?: boolean;
22
- /** Absolute Markdown file documenting the Service this Client may expose. */
23
- serviceDocs?: string;
24
21
  /** Default Window title. */
25
22
  title?: string;
26
23
  /** Default Window size. */
@@ -43,6 +40,8 @@ type Description = Readonly<{
43
40
  description?: string;
44
41
  /** Absolute validated PNG source used to derive the Program's hosted icon sizes. */
45
42
  icon?: string;
43
+ /** Absolute Markdown file describing Program-specific operation to agents. */
44
+ agent?: string;
46
45
  /** Absolute directory used for the Program's persistent storage. */
47
46
  storage: string;
48
47
  }>;
package/dist/main.d.ts CHANGED
@@ -2,6 +2,7 @@ export { host, type Host, type HostProcess, type HostProgram, type ClientDescrip
2
2
  export { current, type Current, type CurrentClient } from "./current.js";
3
3
  export { type Answerer, type Channel } from "./channel.js";
4
4
  export { type ProgramStartup } from "./startup.js";
5
- export { ClientServiceHandler, ServerServiceHandler, ServiceHandler, type ClientServiceChannel, type ServerServiceChannel, type ServiceChannel, type ServiceKey, type ServiceLifecycleEvents } from "@phreshos/core";
5
+ export { ClientServiceHandler, ServerServiceHandler } from "./service.js";
6
+ export { ServiceHandler, type ClientServiceChannel, type ServerServiceChannel, type ServiceChannel, type ServiceKey, type ServiceLifecycleEvents } from "@phreshos/core";
6
7
  export { Client, Endpoint, Process, Program, Server, type Window, type ProgramArea, type ProgramProcess } from "./domain.js";
7
8
  export type { AnswerCapture, AnswerMessage, AnswerObserver, Askable, AskCapture, AskMessage, AskObserver, Capture, Captures, ChannelCapture, ChannelEvents, ChannelMessage, 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, ServedFile, ServerTraffic, Size, Subscribable, SubscribableEvents, SubscribableFallback, TimedAskable, TrafficCapture, TrafficEvents, TrafficMessage, Value, Theme, ThemeEvents, ThemeProperties, WallpaperLaunch, FileWallpaper, DesktopWallpaper, WritableTheme, WindowEvents, WindowGeometry, WindowLayer, WindowState } from "@phreshos/core";
package/dist/main.js CHANGED
@@ -2,5 +2,6 @@ export { host } from "./host.js";
2
2
  export { current } from "./current.js";
3
3
  export {} from "./channel.js";
4
4
  export {} from "./startup.js";
5
- export { ClientServiceHandler, ServerServiceHandler, ServiceHandler } from "@phreshos/core";
5
+ export { ClientServiceHandler, ServerServiceHandler } from "./service.js";
6
+ export { ServiceHandler } from "@phreshos/core";
6
7
  export { Client, Endpoint, Process, Program, Server } from "./domain.js";
package/dist/service.d.ts CHANGED
@@ -1,5 +1,13 @@
1
- import { type ClientServiceHandler, type ServerServiceHandler, type ServiceHandler, type ServiceKey } from "@phreshos/core";
1
+ import { ClientServiceHandler as CoreClientServiceHandler, ServerServiceHandler as CoreServerServiceHandler, type ServiceHandler, type ServiceKey } from "@phreshos/core";
2
2
  import type { HandleAddress } from "./domain.js";
3
+ /** Server-SDK handle for a Service provided by a Server Endpoint. */
4
+ export declare class ServerServiceHandler<Events extends object = {}> extends CoreServerServiceHandler<Events> {
5
+ protected constructor();
6
+ }
7
+ /** Server-SDK handle for a Service provided by a Client Endpoint. */
8
+ export declare class ClientServiceHandler<Events extends object = {}> extends CoreClientServiceHandler<Events> {
9
+ protected constructor();
10
+ }
3
11
  export declare function prepareService<EventsMap extends object = {}>(key: ServiceKey & {
4
12
  endpoint: "server";
5
13
  }): ServerServiceHandler<EventsMap>;
package/dist/service.js CHANGED
@@ -5,8 +5,14 @@ import Events from "./events.js";
5
5
  import HandleRegistry from "./handle-registry.js";
6
6
  import wire from "./wire.js";
7
7
  const handles = new HandleRegistry();
8
- const ServerServiceBase = CoreServerServiceHandler;
9
- const ClientServiceBase = CoreClientServiceHandler;
8
+ /** Server-SDK handle for a Service provided by a Server Endpoint. */
9
+ export class ServerServiceHandler extends CoreServerServiceHandler {
10
+ constructor() { super(); }
11
+ }
12
+ /** Server-SDK handle for a Service provided by a Client Endpoint. */
13
+ export class ClientServiceHandler extends CoreClientServiceHandler {
14
+ constructor() { super(); }
15
+ }
10
16
  class ServerChannelHandle extends Events {
11
17
  key;
12
18
  constructor(key) {
@@ -45,7 +51,7 @@ class ClientChannelHandle extends Events {
45
51
  super(...serviceEvents(key, "channel"));
46
52
  }
47
53
  }
48
- class ServerHandler extends ServerServiceBase {
54
+ class ServerHandler extends ServerServiceHandler {
49
55
  key;
50
56
  name;
51
57
  channel;
@@ -64,7 +70,7 @@ class ServerHandler extends ServerServiceBase {
64
70
  await wire.request(["service-wait-ready", this.key, timeout], timeout);
65
71
  }
66
72
  }
67
- class ClientHandler extends ClientServiceBase {
73
+ class ClientHandler extends ClientServiceHandler {
68
74
  key;
69
75
  name;
70
76
  channel;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phreshos/server",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "The SDK used by a Program's server endpoint.",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",
@@ -46,13 +46,13 @@
46
46
  "prepack": "node --run build"
47
47
  },
48
48
  "peerDependencies": {
49
- "@phreshos/core": "^0.1.11"
49
+ "@phreshos/core": "^0.1.12"
50
50
  },
51
51
  "dependencies": {
52
52
  "@msgpack/msgpack": "^3.1.3"
53
53
  },
54
54
  "devDependencies": {
55
- "@phreshos/core": "^0.1.11",
55
+ "@phreshos/core": "^0.1.12",
56
56
  "@types/node": "^26.2.0",
57
57
  "typescript": "^6.0.3"
58
58
  }