@agimon-ai/po-core 0.0.0-alpha.103 → 0.0.0-alpha.105

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 (151) hide show
  1. package/dist/apiContracts.d.mts +159 -7
  2. package/dist/apiContracts.d.mts.map +1 -1
  3. package/dist/headlessProtocol.cjs +2 -1
  4. package/dist/headlessProtocol.cjs.map +1 -1
  5. package/dist/headlessProtocol.mjs +2 -1
  6. package/dist/headlessProtocol.mjs.map +1 -1
  7. package/dist/headlessServer.cjs +20 -1
  8. package/dist/headlessServer.cjs.map +1 -1
  9. package/dist/headlessServer.mjs +20 -1
  10. package/dist/headlessServer.mjs.map +1 -1
  11. package/dist/headlessSessionHost.d.mts +1 -1
  12. package/dist/machineApi.cjs +2 -46
  13. package/dist/machineApi.cjs.map +1 -1
  14. package/dist/machineApi.d.mts.map +1 -1
  15. package/dist/machineApi.mjs +2 -46
  16. package/dist/machineApi.mjs.map +1 -1
  17. package/dist/nodePlatform.cjs +4 -1
  18. package/dist/nodePlatform.cjs.map +1 -1
  19. package/dist/nodePlatform.d.mts +3 -0
  20. package/dist/nodePlatform.d.mts.map +1 -1
  21. package/dist/nodePlatform.mjs +4 -1
  22. package/dist/nodePlatform.mjs.map +1 -1
  23. package/dist/packageApiServer.cjs +1 -0
  24. package/dist/packageApiServer.cjs.map +1 -1
  25. package/dist/packageApiServer.d.mts +1 -0
  26. package/dist/packageApiServer.d.mts.map +1 -1
  27. package/dist/packageApiServer.mjs +1 -0
  28. package/dist/packageApiServer.mjs.map +1 -1
  29. package/dist/platform.cjs +2 -0
  30. package/dist/platform.d.mts +2 -2
  31. package/dist/platform.mjs +2 -2
  32. package/dist/providerAuth.cjs +8 -0
  33. package/dist/providerAuth.d.mts +4 -0
  34. package/dist/providerAuth.mjs +3 -0
  35. package/dist/serverPlugin.cjs +6 -0
  36. package/dist/serverPlugin.d.mts +5 -2
  37. package/dist/serverPlugin.mjs +4 -1
  38. package/dist/src/pi/piSessionRuntime.cjs +13 -2
  39. package/dist/src/pi/piSessionRuntime.cjs.map +1 -1
  40. package/dist/src/pi/piSessionRuntime.d.mts +1 -1
  41. package/dist/src/pi/piSessionRuntime.mjs +13 -2
  42. package/dist/src/pi/piSessionRuntime.mjs.map +1 -1
  43. package/dist/src/schemas/approval.cjs +4 -1
  44. package/dist/src/schemas/approval.cjs.map +1 -1
  45. package/dist/src/schemas/approval.d.mts.map +1 -1
  46. package/dist/src/schemas/approval.mjs +4 -1
  47. package/dist/src/schemas/approval.mjs.map +1 -1
  48. package/dist/src/schemas/brain.cjs +43 -0
  49. package/dist/src/schemas/brain.cjs.map +1 -0
  50. package/dist/src/schemas/brain.d.mts +105 -0
  51. package/dist/src/schemas/brain.d.mts.map +1 -0
  52. package/dist/src/schemas/brain.mjs +43 -0
  53. package/dist/src/schemas/brain.mjs.map +1 -0
  54. package/dist/src/schemas/codemode.cjs +4 -1
  55. package/dist/src/schemas/codemode.cjs.map +1 -1
  56. package/dist/src/schemas/codemode.d.mts.map +1 -1
  57. package/dist/src/schemas/codemode.mjs +4 -1
  58. package/dist/src/schemas/codemode.mjs.map +1 -1
  59. package/dist/src/schemas/globalServices.cjs.map +1 -1
  60. package/dist/src/schemas/globalServices.d.mts +2 -2
  61. package/dist/src/schemas/globalServices.d.mts.map +1 -1
  62. package/dist/src/schemas/globalServices.mjs.map +1 -1
  63. package/dist/src/schemas/headless.d.mts +1 -1
  64. package/dist/src/schemas/hostServiceContracts.cjs +34 -0
  65. package/dist/src/schemas/hostServiceContracts.cjs.map +1 -0
  66. package/dist/src/schemas/hostServiceContracts.d.mts +23 -0
  67. package/dist/src/schemas/hostServiceContracts.d.mts.map +1 -0
  68. package/dist/src/schemas/hostServiceContracts.mjs +34 -0
  69. package/dist/src/schemas/hostServiceContracts.mjs.map +1 -0
  70. package/dist/src/schemas/packageApi.cjs.map +1 -1
  71. package/dist/src/schemas/packageApi.d.mts +3 -0
  72. package/dist/src/schemas/packageApi.d.mts.map +1 -1
  73. package/dist/src/schemas/packageApi.mjs.map +1 -1
  74. package/dist/src/schemas/platform.cjs +6 -0
  75. package/dist/src/schemas/platform.cjs.map +1 -1
  76. package/dist/src/schemas/platform.d.mts +68 -0
  77. package/dist/src/schemas/platform.d.mts.map +1 -1
  78. package/dist/src/schemas/platform.mjs +5 -1
  79. package/dist/src/schemas/platform.mjs.map +1 -1
  80. package/dist/src/schemas/serverBundle.d.mts +5 -0
  81. package/dist/src/schemas/serverBundle.d.mts.map +1 -1
  82. package/dist/src/schemas/serverScope.cjs +18 -1
  83. package/dist/src/schemas/serverScope.cjs.map +1 -1
  84. package/dist/src/schemas/serverScope.d.mts +11 -0
  85. package/dist/src/schemas/serverScope.d.mts.map +1 -1
  86. package/dist/src/schemas/serverScope.mjs +18 -2
  87. package/dist/src/schemas/serverScope.mjs.map +1 -1
  88. package/dist/src/server/conversationEvents.cjs +3 -2
  89. package/dist/src/server/conversationEvents.cjs.map +1 -1
  90. package/dist/src/server/conversationEvents.mjs +3 -2
  91. package/dist/src/server/conversationEvents.mjs.map +1 -1
  92. package/dist/src/server/directHarnessRuntime.cjs +55 -5
  93. package/dist/src/server/directHarnessRuntime.cjs.map +1 -1
  94. package/dist/src/server/directHarnessRuntime.d.mts.map +1 -1
  95. package/dist/src/server/directHarnessRuntime.mjs +55 -5
  96. package/dist/src/server/directHarnessRuntime.mjs.map +1 -1
  97. package/dist/src/server/providerRoutes.cjs +58 -0
  98. package/dist/src/server/providerRoutes.cjs.map +1 -0
  99. package/dist/src/server/providerRoutes.d.mts +16 -0
  100. package/dist/src/server/providerRoutes.d.mts.map +1 -0
  101. package/dist/src/server/providerRoutes.mjs +58 -0
  102. package/dist/src/server/providerRoutes.mjs.map +1 -0
  103. package/dist/src/server/serverScope.cjs +189 -9
  104. package/dist/src/server/serverScope.cjs.map +1 -1
  105. package/dist/src/server/serverScope.d.mts +8 -3
  106. package/dist/src/server/serverScope.d.mts.map +1 -1
  107. package/dist/src/server/serverScope.mjs +191 -11
  108. package/dist/src/server/serverScope.mjs.map +1 -1
  109. package/dist/src/services/edgeModelRuntime/index.cjs +363 -0
  110. package/dist/src/services/edgeModelRuntime/index.cjs.map +1 -0
  111. package/dist/src/services/edgeModelRuntime/index.d.mts +24 -0
  112. package/dist/src/services/edgeModelRuntime/index.d.mts.map +1 -0
  113. package/dist/src/services/edgeModelRuntime/index.mjs +360 -0
  114. package/dist/src/services/edgeModelRuntime/index.mjs.map +1 -0
  115. package/dist/src/services/edgeModelRuntime/type.d.mts +32 -0
  116. package/dist/src/services/edgeModelRuntime/type.d.mts.map +1 -0
  117. package/dist/src/services/globalServices/index.cjs +12 -3
  118. package/dist/src/services/globalServices/index.cjs.map +1 -1
  119. package/dist/src/services/globalServices/index.d.mts +2 -2
  120. package/dist/src/services/globalServices/index.d.mts.map +1 -1
  121. package/dist/src/services/globalServices/index.mjs +12 -3
  122. package/dist/src/services/globalServices/index.mjs.map +1 -1
  123. package/dist/src/services/providerAuth/index.cjs +1 -4
  124. package/dist/src/services/providerAuth/index.cjs.map +1 -1
  125. package/dist/src/services/providerAuth/index.mjs +0 -1
  126. package/dist/src/services/providerAuth/index.mjs.map +1 -1
  127. package/dist/src/systems/main/adapters/headlessSessionHost.cjs +3 -0
  128. package/dist/src/systems/main/adapters/headlessSessionHost.cjs.map +1 -1
  129. package/dist/src/systems/main/adapters/headlessSessionHost.mjs +3 -0
  130. package/dist/src/systems/main/adapters/headlessSessionHost.mjs.map +1 -1
  131. package/dist/src/systems/main/types/headlessHost.d.mts +1 -1
  132. package/dist/src/types/server/auth.d.mts +99 -0
  133. package/dist/src/types/server/auth.d.mts.map +1 -0
  134. package/dist/src/types/server/directHarnessRuntime.d.mts +10 -0
  135. package/dist/src/types/server/directHarnessRuntime.d.mts.map +1 -1
  136. package/dist/src/web/hostSlots.cjs +117 -0
  137. package/dist/src/web/hostSlots.cjs.map +1 -0
  138. package/dist/src/web/hostSlots.d.mts +109 -0
  139. package/dist/src/web/hostSlots.d.mts.map +1 -0
  140. package/dist/src/web/hostSlots.mjs +114 -0
  141. package/dist/src/web/hostSlots.mjs.map +1 -0
  142. package/dist/src/web/types/webPlugin.d.mts +4 -0
  143. package/dist/src/web/types/webPlugin.d.mts.map +1 -1
  144. package/dist/web.cjs +5 -0
  145. package/dist/web.d.mts +3 -1
  146. package/dist/web.mjs +2 -1
  147. package/dist/webCompositions.cjs.map +1 -1
  148. package/dist/webCompositions.d.mts +6 -0
  149. package/dist/webCompositions.d.mts.map +1 -1
  150. package/dist/webCompositions.mjs.map +1 -1
  151. package/package.json +9 -4
@@ -1,17 +1,111 @@
1
1
  import { Static, TSchema, Type } from "typebox";
2
2
  import { Context, method } from "@earendil-works/chord";
3
3
  import { Events } from "@deepseek-ai/cordis";
4
+ import { AuthResult, ModelType, ModelsStoreEntry } from "@earendil-works/pi-ai";
4
5
  import { Storage } from "@earendil-works/pi-durable";
5
6
  import { FileSystem, Shell } from "@earendil-works/pi-durable/env";
6
7
  import { SqliteDatabase } from "@earendil-works/pi-durable/storage/sqlite";
7
8
  import "@agimon-ai/po-web-security/deviceProof";
8
9
  import { Schema } from "@earendil-works/pi-schema";
9
10
  import "@earendil-works/chord/context";
11
+ //#region src/schemas/serverBundle.d.ts
12
+ /** Every occurrence that can activate a package in this repository. */
13
+ interface PoServerBundleOwner {
14
+ readonly majorMode: string;
15
+ readonly layer: string;
16
+ }
17
+ interface PoServerBundleEntry {
18
+ readonly packageName: string;
19
+ /** Host-admitted distribution catalog origin, never inferred from a local path. */
20
+ readonly origin?: 'po' | 'personal' | 'unknown';
21
+ /** Validated additive client metadata, retained without importing browser code. */
22
+ readonly webMetadata?: PoWebBrainMetadata;
23
+ /** Parsed at package load. Missing or malformed contracts cannot authorize federation. */
24
+ readonly apiContract?: PoApiContract;
25
+ /** The declared package-relative source entry, retained for attribution. */
26
+ readonly entry: string;
27
+ /** Absolute path of the package's built module; the live loader imports it from its content URL. */
28
+ readonly module: string;
29
+ readonly scopes: readonly PoApiScope[];
30
+ readonly owners: readonly PoServerBundleOwner[];
31
+ readonly required: boolean;
32
+ }
33
+ //#endregion
34
+ //#region src/schemas/brain.d.ts
35
+ /** Detached descriptions only. No service values, fibers, paths or callbacks cross this boundary. */
36
+ interface BrainScope {
37
+ id: string;
38
+ level: PoApiScope;
39
+ }
40
+ interface BrainOwner {
41
+ kind: 'host' | 'package' | 'unknown';
42
+ packageName: string | null;
43
+ origin: NonNullable<PoServerBundleEntry['origin']>;
44
+ }
45
+ interface BrainService {
46
+ id: string;
47
+ name: string;
48
+ scope: BrainScope;
49
+ visibleFrom: BrainScope;
50
+ owner: BrainOwner;
51
+ public: boolean;
52
+ description: string | null;
53
+ }
54
+ interface BrainConsumer {
55
+ id: string;
56
+ name: string;
57
+ scope: BrainScope;
58
+ owner: BrainOwner;
59
+ }
60
+ /** Declared injections only, never inferred from ctx.get or requirePo helpers. */
61
+ interface BrainEdge {
62
+ consumer: string;
63
+ service: string | null;
64
+ name: string;
65
+ status: 'resolved' | 'waiting';
66
+ }
67
+ interface BrainPackage {
68
+ scope: BrainScope;
69
+ owner: BrainOwner;
70
+ web: PoWebBrainMetadata | null;
71
+ }
72
+ interface BrainServicesSnapshot {
73
+ scope: BrainScope;
74
+ scopes: BrainScope[];
75
+ packages: BrainPackage[];
76
+ /** Exact published browser mounts, when the host supplied every scope's inventory. */
77
+ clientPackages?: BrainPackage[];
78
+ services: BrainService[];
79
+ consumers: BrainConsumer[];
80
+ edges: BrainEdge[];
81
+ diagnostics: string[];
82
+ }
83
+ /** Additive manifest metadata. Older manifests omit this block rather than claiming no slots. */
84
+ interface PoWebBrainMetadata {
85
+ version: 1;
86
+ slots: {
87
+ name: string;
88
+ scope: PoApiScope;
89
+ description?: string;
90
+ parent?: string;
91
+ kind: 'data' | 'component';
92
+ }[];
93
+ fills: {
94
+ id: string;
95
+ slot: string | null;
96
+ scope: PoApiScope;
97
+ placement: 'verified' | 'unverified';
98
+ }[];
99
+ diagnostics: string[];
100
+ }
101
+ //#endregion
10
102
  //#region src/schemas/serverScope.d.ts
11
103
  /** An abstract service: the name every level resolves and the level that provides it. */
12
104
  interface PoServiceContract<T> {
13
105
  readonly name: string;
14
106
  readonly scope: PoApiScope;
107
+ /** What this service offers an author. Built public contracts require a nonblank description. */
108
+ readonly description?: string;
15
109
  /** Type carrier only; never set at runtime. */
16
110
  readonly _type?: T;
17
111
  }
@@ -33,6 +127,8 @@ interface PoServerPluginShare<TRoots> {
33
127
  /** What a plugin sees of the scope it is installed into. */
34
128
  interface PoServerScopeService {
35
129
  readonly level: PoApiScope;
130
+ /** Detached current scope and ancestry only, without reading service values. */
131
+ snapshot(): BrainServicesSnapshot;
36
132
  /**
37
133
  * Bind the concrete value of a contract owned by this level, visible here and in every descendant.
38
134
  * Settles once every descendant publishes it. The binding unwinds with the calling fiber; the
@@ -332,6 +428,68 @@ interface PoIsolateService {
332
428
  readonly liveObjects: boolean;
333
429
  run(request: PoIsolateRequest): Promise<PoIsolateResult>;
334
430
  }
431
+ /** An OpenAI- or Anthropic-compatible endpoint added by hand. Holds no secret: its key is a stored credential. */
432
+ interface PoCustomProviderDefinition {
433
+ readonly id: string;
434
+ readonly name: string;
435
+ /** `http:` or `https:`, without userinfo or a query string. */
436
+ readonly baseUrl: string;
437
+ readonly api: 'openai-completions' | 'openai-responses' | 'anthropic-messages';
438
+ readonly models: readonly {
439
+ readonly id: string;
440
+ readonly name?: string;
441
+ readonly reasoning?: boolean;
442
+ readonly input?: readonly ('text' | 'image')[];
443
+ readonly contextWindow?: number;
444
+ readonly maxTokens?: number;
445
+ }[];
446
+ }
447
+ /** What the credential owner tells sessions: never a key, token, header or URL secret. */
448
+ interface PoProviderAuthSnapshot {
449
+ /** Changes whenever anything below changes; compare with `!==`, as an owner restart starts afresh. */
450
+ readonly version: number;
451
+ /** Configured providers only; every other provider is unconfigured. */
452
+ readonly providers: readonly {
453
+ readonly id: string;
454
+ readonly type: 'api_key' | 'oauth';
455
+ readonly source?: string;
456
+ readonly subscription: boolean;
457
+ }[];
458
+ /** Models of every type the deployment target can use, after each provider's credential filter. */
459
+ readonly available: readonly {
460
+ readonly provider: string;
461
+ readonly id: string;
462
+ readonly type: ModelType;
463
+ }[];
464
+ /** Dynamic catalogs by provider id, with headers and URL secrets removed. */
465
+ readonly models: Readonly<Record<string, ModelsStoreEntry>>;
466
+ readonly customProviders: readonly PoCustomProviderDefinition[];
467
+ }
468
+ /**
469
+ * Provider credentials held by one owner per deployment target (the org on hosted Po), for hosts
470
+ * whose sessions must never store them. Node leaves it unbound: `auth.json` is the authority there.
471
+ */
472
+ interface PoProviderAuth {
473
+ readonly abiVersion: 1;
474
+ /**
475
+ * Provider-level auth for one request, resolved like local `Models.getAuth` (stored OAuth refreshed,
476
+ * then the stored key) and never persisted by the caller. `version` is the owner's snapshot version.
477
+ */
478
+ resolveAuth(provider: string): Promise<{
479
+ readonly version: number;
480
+ readonly auth?: AuthResult;
481
+ }>;
482
+ /** The full snapshot, or just `{ version }` while `sinceVersion` is still current. */
483
+ snapshot(sinceVersion?: number): Promise<PoProviderAuthSnapshot | {
484
+ readonly version: number;
485
+ }>;
486
+ refresh(options?: {
487
+ readonly allowNetwork?: boolean;
488
+ }): Promise<{
489
+ readonly version: number;
490
+ readonly errors: Readonly<Record<string, string>>;
491
+ }>;
492
+ }
335
493
  declare module '@deepseek-ai/cordis' {
336
494
  interface Context {
337
495
  'po/fs': FileSystem;
@@ -342,6 +500,7 @@ declare module '@deepseek-ai/cordis' {
342
500
  'po/npm': PoNpm;
343
501
  'po/electron': PoElectronService;
344
502
  'po/browser': PoBrowserService;
503
+ 'po/provider-auth': PoProviderAuth;
345
504
  'po/session-files': {
346
505
  readonly temporaryDirectory: string;
347
506
  };
@@ -689,13 +848,6 @@ declare module '@deepseek-ai/cordis' {
689
848
  }
690
849
  }
691
850
  //#endregion
692
- //#region src/schemas/serverBundle.d.ts
693
- /** Every occurrence that can activate a package in this repository. */
694
- interface PoServerBundleOwner {
695
- readonly majorMode: string;
696
- readonly layer: string;
697
- }
698
- //#endregion
699
851
  //#region src/schemas/apiContracts.d.ts
700
852
  export declare const PO_API_CONTRACT_VERSION = 1;
701
853
  export declare const PO_API_CONTRACT_FILE = "contracts.json";
@@ -1 +1 @@
1
- {"version":3,"file":"apiContracts.d.mts","names":["_0","_0","_0","IoContext","_0","_$__hubChannel0.PoHubSessionUsage","_0","_$__protocolContracts0.ChordMethods"],"sources":["../src/schemas/serverScope.ts","../src/schemas/approvalPrompt.ts","../src/schemas/approval.ts","../src/schemas/backgroundWork.ts","../src/schemas/platform.ts","../src/schemas/workflow.ts","../src/schemas/hubChannel.ts","../src/schemas/packageApi.ts","../src/schemas/serverBundle.ts","../src/schemas/apiContracts.ts","../src/services/apiContracts/index.ts","../src/schemas/builtinApiContracts.ts","../src/schemas/httpApiContracts.ts","../src/schemas/protocolContracts.ts","../src/schemas/sessionProtocol.ts","../src/schemas/sessionApiContracts.ts","../src/schemas/transportApiContracts.ts"],"mappings":";;;;;;;;;;;UAiBiB,kBAAkB;WACxB;WACA,OAAO;;WAEP,QAAQ;;;KAQP;;UAoBK,sBAAsB;WAC5B,OAAO;EAChB,WAAW;;;UAII,oBAAoB;EACnC,QAAQ,GACN,KAAK,qBACL,cAAc,IAAI,QAAQ,IAC1B,WAAW,OAAO,aAAa,gBAC9B,QAAQ,sBAAsB;;EAEjC,IAAI,OAAO;;EAEX,MAAM,MAAM,sBAAsB;;;UAInB;WACN,OAAO;;;;;;EAMhB,QAAQ,GAAG,UAAU,kBAAkB,IAAI,OAAO,IAAI,cAAc;;EAEpE,QAAQ,GAAG,UAAU,kBAAkB,KAAK;;EAE5C,KAAK,gBAAgB,QAAQ,MAAM,MAAM,MAAM,WAAW,OAAO;;EAEjE,UAAU,gBAAgB,QAAQ,MAAM,MAAM,MAAM,WAAW,OAAO;;EAEtE,OAAO,QAAQ,gBAAgB,oBAAoB;;;YAIzC;IACR,mBAAmB;;;;;;UCxEN;WACN;WACA;WACA;aAA8B;aAAwB;;;UAGhD;WACN;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QAAA,KAAA,eAAA,KAAA,QAAA,KAAA,OAAA,KAAA,QAAA,KAAA,SAAA,KAAA,aAAA,KAAA,YAAA,KAAA,OAAA,KAAA,aAAA,KAAA,QAAA,KAAA,eAAA,KAAA,OAAA,KAAA,aAAA,KAAA,QAAA,KAAA,eAAA,KAAA,UAAA,KAAA,OAAA,KAAA,QAAA,KAAA,SAAA,KAAA;;qBAqCjB,wBAAsB,KAAA,QAAA,KAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAwBtB,wBAAsB,KAAA,QAAA,KAAA"}
1
+ {"version":3,"file":"apiContracts.d.mts","names":["_0","_0","_0","IoContext","_0","_$__hubChannel0.PoHubSessionUsage","_0","_$__protocolContracts0.ChordMethods"],"sources":["../src/schemas/serverBundle.ts","../src/schemas/brain.ts","../src/schemas/serverScope.ts","../src/schemas/approvalPrompt.ts","../src/schemas/approval.ts","../src/schemas/backgroundWork.ts","../src/schemas/platform.ts","../src/schemas/workflow.ts","../src/schemas/hubChannel.ts","../src/schemas/packageApi.ts","../src/schemas/apiContracts.ts","../src/services/apiContracts/index.ts","../src/schemas/builtinApiContracts.ts","../src/schemas/httpApiContracts.ts","../src/schemas/protocolContracts.ts","../src/schemas/sessionProtocol.ts","../src/schemas/sessionApiContracts.ts","../src/schemas/transportApiContracts.ts"],"mappings":";;;;;;;;;;;;UAKiB;WACN;WACA;;UAGM;WACN;;WAEA;;WAEA,cAAc;;WAEd,cAAc;;WAEd;;WAEA;WACA,iBAAiB;WACjB,iBAAiB;WACjB;;;;;UCpBM;EACf;EACA,OAAO;;UAGQ;EACf;EACA;EACA,QAAQ,YAAY;;UAGL;EACf;EACA;EACA,OAAO;EACP,aAAa;EACb,OAAO;EACP;EACA;;UAGe;EACf;EACA;EACA,OAAO;EACP,OAAO;;;UAIQ;EACf;EACA;EACA;EACA;;UAGe;EACf,OAAO;EACP,OAAO;EACP,KAAK;;UAGU;EACf,OAAO;EACP,QAAQ;EAC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,KAAA,OAAA,KAAA,aAAA,KAAA,QAAA,KAAA,eAAA,KAAA,OAAA,KAAA,aAAA,KAAA,QAAA,KAAA,eAAA,KAAA,UAAA,KAAA,OAAA,KAAA,QAAA,KAAA,SAAA,KAAA;;qBAqCjB,wBAAsB,KAAA,QAAA,KAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAwBtB,wBAAsB,KAAA,QAAA,KAAA"}
@@ -291,7 +291,7 @@ function createHeadlessProtocol(options) {
291
291
  }
292
292
  };
293
293
  });
294
- require_piSessionRuntime.serveAgentSessions(host, { resolve(sessionId, principal) {
294
+ const clearSessionBindings = require_piSessionRuntime.serveAgentSessions(host, { resolve(sessionId, principal) {
295
295
  const connection = connectionOf(principal);
296
296
  const session = hub.session(sessionId);
297
297
  if (!session || !reachable(connection, session.id)) return void 0;
@@ -358,6 +358,7 @@ function createHeadlessProtocol(options) {
358
358
  closing ??= (async () => {
359
359
  stopClaims?.();
360
360
  threads.close();
361
+ clearSessionBindings();
361
362
  await host.close();
362
363
  })();
363
364
  return closing;
@@ -1 +1 @@
1
- {"version":3,"file":"headlessProtocol.cjs","names":["createThreadJournals","createHost","PO_SERVER_HOST","harnessErrorMessage","forbidden","PoHubContract","chordSchema","Type","SessionSummarySchema","HubWorkspaceSchema","HubNoticeSchema","HubCompositionsSchema","randomUUID","PoHubRevisionsContract","HubRevisionsSchema","PoThreadContract","PoThreadFrameSchema","PoChannelsContract","PoChannelsStateSchema","reportingLargeFrames"],"sources":["../src/server/headlessProtocol.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport { createHost, forbidden, type Link, type Subscribable } from '@earendil-works/chord';\nimport { Type } from 'typebox';\n\nimport type { PoPluginCall } from '../exports/pluginProtocol';\nimport {\n HubCompositionsSchema,\n HubNoticeSchema,\n HubRevisionsSchema,\n PO_SERVER_HOST,\n PoChannelsContract,\n PoHubContract,\n PoHubRevisionsContract,\n PoThreadContract,\n type HubNotice,\n type HubSessionView,\n type HubWorkspaceView,\n type JsonValue,\n} from '../exports/sessionProtocol';\nimport { serveAgentSessions, type AgentSessionBinding } from '../pi/piSessionRuntime';\nimport { SessionSummarySchema } from '../schemas/httpApiContracts';\nimport type { PoSocketMount } from '../schemas/packageApi';\nimport { PoChannelsStateSchema } from '../schemas/protocolChannelsContract';\nimport { chordSchema } from '../schemas/protocolContracts';\nimport { HubWorkspaceSchema } from '../schemas/protocolHubContract';\nimport { PoThreadFrameSchema } from '../schemas/protocolThreadContract';\nimport type { OpenSessionRecord } from '../services/openSessionRegistry';\nimport type { ServerTelemetry } from '../services/serverTelemetry';\nimport { harnessErrorMessage } from './harnessErrorMessage';\nimport type { HeadlessHub, HeadlessHubEvent, HeadlessHubSession } from './headlessHub';\nimport { reportingLargeFrames } from './largeFrameLink';\nimport { createThreadJournals } from './threadJournals';\n\n// ponytail: unacknowledged notices beyond this drop oldest first; raise it if a client misses dialogs.\nconst MAX_PENDING_NOTICES = 64;\n/** A browser switching back to a thread quickly keeps its tail open. */\nconst THREAD_LINGER_MS = 5_000;\n\nfunction sessionView(session: HeadlessHubSession): HubSessionView {\n return {\n id: session.id,\n ...(session.workspaceId === undefined ? {} : { workspaceId: session.workspaceId }),\n ...(session.webComposition === undefined ? {} : { webComposition: { ...session.webComposition } }),\n ...(session.nativeComposition === undefined ? {} : { nativeComposition: { ...session.nativeComposition } }),\n name: session.name,\n cwd: session.cwd,\n createdAt: session.createdAt,\n updatedAt: session.updatedAt ?? session.createdAt,\n phase: session.phase ?? 'idle',\n phaseSince: session.phaseSince ?? session.createdAt,\n attach: 'attached',\n pendingMessageCount: session.pendingMessageCount ?? 0,\n everPrompted: session.everPrompted ?? false,\n awaitingInput: session.awaitingInput ?? false,\n ...(session.lastSettledAt === undefined ? {} : { lastSettledAt: session.lastSettledAt }),\n // null: the host has not reported yet.\n ...(session.backgroundWorkActive == null ? {} : { backgroundWorkActive: session.backgroundWorkActive }),\n ...(session.git === undefined ? {} : { git: { branch: session.git.branch, dirty: session.git.dirty } }),\n ...(session.profile === undefined\n ? {}\n : {\n profile: {\n name: session.profile.name,\n ...(session.profile.displayName === undefined ? {} : { displayName: session.profile.displayName }),\n ...(session.profile.iconVersion === undefined ? {} : { iconVersion: session.profile.iconVersion }),\n },\n }),\n ...(session.parentSessionId === undefined ? {} : { parentSessionId: session.parentSessionId }),\n ...(session.sessionProvenance === undefined ? {} : { sessionProvenance: session.sessionProvenance }),\n ...(session.interaction === undefined ? {} : { interaction: session.interaction }),\n ...(session.groups === undefined || session.groups.length === 0 ? {} : { groups: [...session.groups] }),\n ...(session.pendingSetups === undefined\n ? {}\n : {\n pendingSetups: session.pendingSetups.map((setup) => ({\n id: setup.id,\n name: setup.name,\n createdAt: setup.createdAt,\n ...(setup.cwd === undefined ? {} : { cwd: setup.cwd }),\n ...(setup.setupKind === undefined ? {} : { setupKind: setup.setupKind }),\n ...(setup.status === undefined ? {} : { status: setup.status }),\n ...(setup.errorCode === undefined ? {} : { errorCode: setup.errorCode }),\n })),\n }),\n ...(session.activity === undefined\n ? {}\n : {\n activity: {\n label: session.activity.label,\n ...(session.activity.attention === true ? { attention: true } : {}),\n ...(session.activity.since === undefined ? {} : { since: session.activity.since }),\n },\n }),\n ...(session.pendingApprovalCount === undefined ? {} : { pendingApprovalCount: session.pendingApprovalCount }),\n };\n}\n\n/**\n * A recorded session with no runtime behind it yet.\n *\n * Carries the same field set as a live session so the rail keys both by id and\n * swaps one for the other in place once the server reopens the journal.\n */\nfunction dormantView(record: OpenSessionRecord, pendingApprovalCount?: number): HubSessionView {\n return {\n id: record.sessionId,\n workspaceId: record.workspaceId,\n name: record.name,\n cwd: record.cwd,\n createdAt: record.createdAt,\n updatedAt: record.createdAt,\n phase: 'idle',\n phaseSince: record.createdAt,\n attach: 'attached',\n pendingMessageCount: 0,\n everPrompted: false,\n awaitingInput: false,\n dormant: true,\n ...(pendingApprovalCount === undefined ? {} : { pendingApprovalCount }),\n ...(record.parentSessionId === undefined ? {} : { parentSessionId: record.parentSessionId }),\n ...(record.sessionProvenance === undefined ? {} : { sessionProvenance: record.sessionProvenance }),\n ...(record.interaction === undefined ? {} : { interaction: record.interaction }),\n ...(record.groups === undefined || record.groups.length === 0 ? {} : { groups: [...record.groups] }),\n };\n}\n\n/** Each restarted session host gets a new generation, so its projection starts fresh. */\nconst generations = new WeakMap<object, number>();\nlet nextGeneration = 0;\nfunction generationOf(host: object): number {\n let generation = generations.get(host);\n if (generation === undefined) {\n generation = nextGeneration++;\n generations.set(host, generation);\n }\n return generation;\n}\n\nfunction permitsSession(\n hub: HeadlessHub,\n mount: PoSocketMount,\n sessionId: string,\n authorize: (id: string) => boolean = () => true,\n): boolean {\n const session = hub.session(sessionId);\n return (\n session !== undefined &&\n authorize(sessionId) &&\n (mount.scope === 'global' ||\n (session.workspaceId === mount.workspaceId && (mount.scope === 'workspace' || mount.sessionId === sessionId)))\n );\n}\n\nfunction permitsDormant(mount: PoSocketMount, record: OpenSessionRecord): boolean {\n if (mount.scope === 'global') return true;\n if (record.workspaceId !== mount.workspaceId) return false;\n return mount.scope === 'workspace' || mount.sessionId === record.sessionId;\n}\n\n/** What one upgraded connection may reach, decided from its request when it connected. */\nexport interface ConnectionAccess {\n readonly mount: PoSocketMount;\n /** Evaluated for every call, including references taken before a Desktop claim. */\n authorizeSession(sessionId: string): boolean;\n authorizeDesktop(): boolean;\n authorizeComputerUse(sessionId: string): boolean;\n}\n\ninterface Connection extends ConnectionAccess {\n /** Sessions this connection reached, rechecked when computer-use ownership changes. */\n readonly sessions: Set<string>;\n}\n\ninterface Principal {\n connectionId: string;\n}\n\nexport interface HeadlessProtocol {\n /** Hands an authenticated link to the shared host. Without `access` it sees everything Desktop does not own. */\n accept(link: Link, access?: Partial<ConnectionAccess>): void;\n close(): Promise<void>;\n}\n\nconst eventsOf = (hub: HeadlessHub): Subscribable<HeadlessHubEvent> => ({\n subscribe: (listener) => hub.onEvent(listener),\n});\n\n/** One Chord host for every browser, native and relayed connection over the process-local hub. */\nexport function createHeadlessProtocol(options: {\n hub: HeadlessHub;\n telemetry?: ServerTelemetry;\n onNotice?: (message: string) => void;\n /** Recorded sessions the server has not reopened. */\n dormantSessions?: () => readonly OpenSessionRecord[];\n}): HeadlessProtocol {\n const hub = options.hub;\n const dormantSessions = () => (options.dormantSessions === undefined ? [] : options.dormantSessions());\n const connections = new Map<string, Connection>();\n const threads = createThreadJournals({\n resolve: (sessionId, threadId) => hub.childThread(sessionId, threadId),\n });\n const host = createHost<Principal>({\n name: PO_SERVER_HOST,\n self: { connectionId: PO_SERVER_HOST },\n principalKey: (principal) => principal.connectionId,\n onError: (error) => options.onNotice?.(`headless protocol error (${harnessErrorMessage(error)})`),\n });\n const connectionOf = (principal: Principal): Connection & { connectionId: string } => {\n const connection = connections.get(principal.connectionId);\n if (connection === undefined) throw forbidden('This connection has closed.');\n return { ...connection, connectionId: principal.connectionId };\n };\n const reachable = (connection: Connection, sessionId: string): boolean =>\n permitsSession(hub, connection.mount, sessionId, (id) => connection.authorizeSession(id));\n\n // A Desktop claim makes every reference the connection holds to that session gone at once.\n const stopClaims = hub.computerUse?.subscribe?.(() => {\n for (const [connectionId, connection] of connections) {\n let revoked = false;\n for (const sessionId of connection.sessions) if (!connection.authorizeSession(sessionId)) revoked = true;\n if (!revoked) continue;\n connection.sessions.clear();\n void host.invalidatePrincipal((principal) => principal.connectionId === connectionId);\n }\n });\n\n host.serve(PoHubContract, (_input, principal, self) => {\n const connection = connectionOf(principal);\n const { mount } = connection;\n const visibleSessions = (): Record<string, HubSessionView> => {\n const views: Record<string, HubSessionView> = {};\n for (const session of hub.snapshot())\n if (reachable(connection, session.id)) views[session.id] = sessionView(session);\n // A dormant record of a removed workspace has no HTTP list to come from, so clients would never agree on it.\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n for (const record of dormantSessions())\n if (\n views[record.sessionId] === undefined &&\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId) &&\n permitsDormant(mount, record)\n )\n views[record.sessionId] = dormantView(record, hub.sessionPendingApprovalCount?.(record.sessionId));\n return views;\n };\n const visibleWorkspaces = (): Record<string, HubWorkspaceView> => {\n const views: Record<string, HubWorkspaceView> = {};\n for (const workspace of hub.workspaces())\n if (mount.scope === 'global' || workspace.id === mount.workspaceId)\n views[workspace.id] = {\n id: workspace.id,\n root: workspace.root,\n ...(workspace.kind === undefined ? {} : { kind: workspace.kind }),\n ...(workspace.name === undefined ? {} : { name: workspace.name }),\n ...(workspace.sandbox === undefined ? {} : { sandbox: workspace.sandbox }),\n ...(workspace.sandboxState === undefined ? {} : { sandboxState: workspace.sandboxState }),\n ...(workspace.sandboxReason === undefined ? {} : { sandboxReason: workspace.sandboxReason }),\n available: workspace.available !== false,\n };\n return views;\n };\n const sessions = self.state('sessions', chordSchema(Type.Record(Type.String(), SessionSummarySchema)), {\n init: visibleSessions,\n });\n const workspaces = self.state('workspaces', chordSchema(Type.Record(Type.String(), HubWorkspaceSchema)), {\n init: visibleWorkspaces,\n });\n const pending = self.state('pending', chordSchema(Type.Array(HubNoticeSchema)), [] as HubNotice[]);\n const visibleCompositions = (): Record<string, number> => {\n const revisions = hub.compositionRevisions?.() ?? {};\n if (mount.scope === 'global') return { ...revisions };\n const own = `workspace:${mount.workspaceId}`;\n return Object.fromEntries(Object.entries(revisions).filter(([key]) => key === 'global' || key === own));\n };\n const compositions = self.state('compositions', chordSchema(HubCompositionsSchema), { init: visibleCompositions });\n self.on('hub', eventsOf(hub), (event, ctx) => {\n switch (event.kind) {\n case 'upsert':\n case 'removed':\n case 'dormant_changed':\n // Recomputed rather than patched, so an event before this listener started cannot leave a stale row.\n sessions.replace(ctx, visibleSessions(), { diff: true });\n return;\n case 'workspace_upsert':\n case 'workspace_removed':\n workspaces.replace(ctx, visibleWorkspaces(), { diff: true });\n return;\n case 'compositions':\n compositions.replace(ctx, visibleCompositions(), { diff: true });\n return;\n case 'frame':\n if (!reachable(connection, event.sessionId)) return;\n pending.change(ctx, (draft) => {\n draft.push({\n id: randomUUID(),\n sessionId: event.sessionId,\n frame: event.frame as Record<string, JsonValue>,\n });\n if (draft.length > MAX_PENDING_NOTICES) draft.splice(0, draft.length - MAX_PENDING_NOTICES);\n });\n return;\n case 'channel':\n return;\n }\n });\n return {\n variant: 'default',\n sessions,\n workspaces,\n pending,\n compositions,\n readHome: async (request) => {\n if (!hub.readHome) throw new Error('Home read is unavailable.');\n return hub.readHome(request, (id) => reachable(connection, id));\n },\n invoke: async (call: PoPluginCall, ctx) => {\n if (call.mount.scope === 'session' && !connection.authorizeSession(call.mount.sessionId))\n throw forbidden('This session belongs to its Desktop instance.');\n if (mount.scope !== 'global') {\n const permitted =\n call.mount.scope === 'session'\n ? permitsSession(hub, mount, call.mount.sessionId)\n : mount.scope === 'workspace' &&\n call.mount.scope === 'workspace' &&\n call.mount.workspaceId === mount.workspaceId;\n if (!permitted) throw forbidden('Plugin is outside this WebSocket scope.');\n }\n return (await hub.invokePlugin(call, 'client-to-server', {\n connectionId: connection.connectionId,\n signal: ctx.signal,\n })) as JsonValue;\n },\n ackNotice: async ({ id }, ctx) => {\n pending.change(ctx, (draft) => draft.filter((notice) => notice.id !== id));\n },\n };\n });\n\n host.serve(PoHubRevisionsContract, (_input, principal, self) => {\n const { mount } = connectionOf(principal);\n const visibleRevisions = (): Record<string, number> => {\n const revisions = hub.revisions?.() ?? {};\n if (mount.scope === 'global') return { ...revisions };\n const own = `workspace:${mount.workspaceId}:`;\n return Object.fromEntries(\n Object.entries(revisions).filter(([topic]) => topic.startsWith('global:') || topic.startsWith(own)),\n );\n };\n const revisions = self.state('revisions', chordSchema(HubRevisionsSchema), { init: visibleRevisions });\n self.on('hub', eventsOf(hub), (event, ctx) => {\n if (event.kind === 'revisions') revisions.replace(ctx, visibleRevisions(), { diff: true });\n });\n return { variant: 'default', revisions };\n });\n\n host.serve(\n PoThreadContract,\n ({ sessionId, threadId }, principal, self) => {\n const connection = connectionOf(principal);\n if (!reachable(connection, sessionId)) throw forbidden(`No session ${sessionId}`);\n connection.sessions.add(sessionId);\n const tail = self.resource('tail', {\n version: 1,\n open: () => threads.subscribe(sessionId, threadId),\n close: () => threads.unsubscribe(sessionId, threadId),\n });\n const frame = self.state('frame', chordSchema(PoThreadFrameSchema), {\n init: () => (tail.value?.at(-1) ?? null) as never,\n });\n self.on(\n 'frames',\n { subscribe: (listener) => threads.onFrame(listener) } as Subscribable<{\n sessionId: string;\n threadId: string;\n frame: Record<string, unknown>;\n }>,\n (event, ctx) => {\n // Each frame is a fresh wrapper around the child's state, so only an explicit diff sends ops, not the whole state.\n if (event.sessionId === sessionId && event.threadId === threadId)\n frame.replace(ctx, event.frame as never, { diff: true });\n },\n );\n return { variant: 'default', frame };\n },\n { linger: THREAD_LINGER_MS },\n );\n\n host.serve(PoChannelsContract, ({ sessionId }, principal, self) => {\n const connection = connectionOf(principal);\n if (!reachable(connection, sessionId)) throw forbidden(`No session ${sessionId}`);\n connection.sessions.add(sessionId);\n const visible = (frameType: string): boolean =>\n frameType !== 'computer_use_state' || connection.authorizeComputerUse(sessionId);\n const latest = self.state('latest', chordSchema(PoChannelsStateSchema), {\n init: () => {\n const payloads: Record<string, JsonValue> = {};\n for (const channelFrame of hub.channelFrames(sessionId))\n if (visible(channelFrame.type)) payloads[channelFrame.type] = channelFrame.payload as JsonValue;\n return payloads;\n },\n });\n // ponytail: a channel keeps only its latest payload; a package that needs every event must carry a sequence.\n self.on('hub', eventsOf(hub), (event, ctx) => {\n if (event.kind !== 'channel' || event.sessionId !== sessionId || !visible(event.frameType)) return;\n if (event.connectionId !== undefined && event.connectionId !== connection.connectionId) return;\n latest.change(ctx, (draft) => {\n draft[event.frameType] = event.payload as JsonValue;\n });\n });\n return {\n variant: 'default',\n latest,\n receive: async ({ type, payload }) => {\n if (!connection.authorizeSession(sessionId)) throw forbidden('This session belongs to Desktop.');\n hub.receiveChannel(\n sessionId,\n type,\n payload,\n connection.connectionId,\n connection.authorizeDesktop(),\n connection.authorizeComputerUse(sessionId),\n );\n },\n };\n });\n\n serveAgentSessions(host, {\n resolve(sessionId, principal): AgentSessionBinding | undefined {\n const connection = connectionOf(principal as Principal);\n const session = hub.session(sessionId);\n if (!session || !reachable(connection, session.id)) return undefined;\n connection.sessions.add(sessionId);\n const permitted = () => hub.session(session.id)?.host === session.host && connection.authorizeSession(session.id);\n // A mirror of a session another host runs forwards there; keyed by its host object, never by session id.\n const forward = session.host.agentSession;\n if (forward !== undefined)\n return { generation: generationOf(session.host), exited: session.host.runtime.exited, permitted, forward };\n return {\n generation: generationOf(session.host),\n exited: session.host.runtime.exited,\n permitted,\n options: {\n runtime: session.host.runtime,\n onPresentationFrame: (listen) =>\n session.host.onPresentationFrame((frame) => {\n if (permitted()) listen(frame);\n }),\n respondToExtensionUi: (frame) => {\n if (!permitted()) throw forbidden('This session belongs to Desktop.');\n return session.host.respondToExtensionUi(frame);\n },\n readThreadTranscript: (threadId, request, readContext) => {\n if (!permitted()) throw forbidden('This session belongs to Desktop.');\n return threads.readPage(session.id, threadId, request, readContext);\n },\n sessionId: session.id,\n sessionName: session.name,\n cwd: session.cwd,\n telemetry: options.telemetry,\n },\n };\n },\n });\n\n let closing: Promise<void> | undefined;\n return {\n accept(link, access = {}) {\n if (closing !== undefined) {\n link.close();\n return;\n }\n const connectionId = randomUUID();\n const authorizeSession = access.authorizeSession ?? ((id: string) => !hub.computerUse?.ownsSession?.(id));\n const authorizeDesktop = access.authorizeDesktop ?? (() => false);\n connections.set(connectionId, {\n mount: access.mount ?? { scope: 'global' },\n authorizeSession,\n authorizeDesktop,\n authorizeComputerUse: access.authorizeComputerUse ?? (() => authorizeDesktop()),\n sessions: new Set(),\n });\n link.onClose(() => {\n connections.delete(connectionId);\n hub.disconnectChannels(connectionId);\n });\n host.accept(reportingLargeFrames(link, options.onNotice, options.telemetry), {\n principal: { connectionId },\n kind: 'client',\n });\n },\n close() {\n closing ??= (async () => {\n stopClaims?.();\n threads.close();\n await host.close();\n })();\n return closing;\n },\n };\n}\n"],"mappings":";;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GACrC,CAAC;GACD,KAAK,OAAOO,uBAAAA,qBAAqB,MAAM,QAAQ,UAAU,QAAQ,SAAS,GAAG;IAC3E,WAAW,EAAE,aAAa;IAC1B,MAAM;GACR,CAAC;EACH;EACA,QAAQ;GACN,aAAa,YAAY;IACvB,aAAa;IACb,QAAQ,MAAM;IACd,MAAM,KAAK,MAAM;GACnB,EAAA,CAAG;GACH,OAAO;EACT;CACF;AACF"}
1
+ {"version":3,"file":"headlessProtocol.cjs","names":["createThreadJournals","createHost","PO_SERVER_HOST","harnessErrorMessage","forbidden","PoHubContract","chordSchema","Type","SessionSummarySchema","HubWorkspaceSchema","HubNoticeSchema","HubCompositionsSchema","randomUUID","PoHubRevisionsContract","HubRevisionsSchema","PoThreadContract","PoThreadFrameSchema","PoChannelsContract","PoChannelsStateSchema","serveAgentSessions","reportingLargeFrames"],"sources":["../src/server/headlessProtocol.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport { createHost, forbidden, type Link, type Subscribable } from '@earendil-works/chord';\nimport { Type } from 'typebox';\n\nimport type { PoPluginCall } from '../exports/pluginProtocol';\nimport {\n HubCompositionsSchema,\n HubNoticeSchema,\n HubRevisionsSchema,\n PO_SERVER_HOST,\n PoChannelsContract,\n PoHubContract,\n PoHubRevisionsContract,\n PoThreadContract,\n type HubNotice,\n type HubSessionView,\n type HubWorkspaceView,\n type JsonValue,\n} from '../exports/sessionProtocol';\nimport { serveAgentSessions, type AgentSessionBinding } from '../pi/piSessionRuntime';\nimport { SessionSummarySchema } from '../schemas/httpApiContracts';\nimport type { PoSocketMount } from '../schemas/packageApi';\nimport { PoChannelsStateSchema } from '../schemas/protocolChannelsContract';\nimport { chordSchema } from '../schemas/protocolContracts';\nimport { HubWorkspaceSchema } from '../schemas/protocolHubContract';\nimport { PoThreadFrameSchema } from '../schemas/protocolThreadContract';\nimport type { OpenSessionRecord } from '../services/openSessionRegistry';\nimport type { ServerTelemetry } from '../services/serverTelemetry';\nimport { harnessErrorMessage } from './harnessErrorMessage';\nimport type { HeadlessHub, HeadlessHubEvent, HeadlessHubSession } from './headlessHub';\nimport { reportingLargeFrames } from './largeFrameLink';\nimport { createThreadJournals } from './threadJournals';\n\n// ponytail: unacknowledged notices beyond this drop oldest first; raise it if a client misses dialogs.\nconst MAX_PENDING_NOTICES = 64;\n/** A browser switching back to a thread quickly keeps its tail open. */\nconst THREAD_LINGER_MS = 5_000;\n\nfunction sessionView(session: HeadlessHubSession): HubSessionView {\n return {\n id: session.id,\n ...(session.workspaceId === undefined ? {} : { workspaceId: session.workspaceId }),\n ...(session.webComposition === undefined ? {} : { webComposition: { ...session.webComposition } }),\n ...(session.nativeComposition === undefined ? {} : { nativeComposition: { ...session.nativeComposition } }),\n name: session.name,\n cwd: session.cwd,\n createdAt: session.createdAt,\n updatedAt: session.updatedAt ?? session.createdAt,\n phase: session.phase ?? 'idle',\n phaseSince: session.phaseSince ?? session.createdAt,\n attach: 'attached',\n pendingMessageCount: session.pendingMessageCount ?? 0,\n everPrompted: session.everPrompted ?? false,\n awaitingInput: session.awaitingInput ?? false,\n ...(session.lastSettledAt === undefined ? {} : { lastSettledAt: session.lastSettledAt }),\n // null: the host has not reported yet.\n ...(session.backgroundWorkActive == null ? {} : { backgroundWorkActive: session.backgroundWorkActive }),\n ...(session.git === undefined ? {} : { git: { branch: session.git.branch, dirty: session.git.dirty } }),\n ...(session.profile === undefined\n ? {}\n : {\n profile: {\n name: session.profile.name,\n ...(session.profile.displayName === undefined ? {} : { displayName: session.profile.displayName }),\n ...(session.profile.iconVersion === undefined ? {} : { iconVersion: session.profile.iconVersion }),\n },\n }),\n ...(session.parentSessionId === undefined ? {} : { parentSessionId: session.parentSessionId }),\n ...(session.sessionProvenance === undefined ? {} : { sessionProvenance: session.sessionProvenance }),\n ...(session.interaction === undefined ? {} : { interaction: session.interaction }),\n ...(session.groups === undefined || session.groups.length === 0 ? {} : { groups: [...session.groups] }),\n ...(session.pendingSetups === undefined\n ? {}\n : {\n pendingSetups: session.pendingSetups.map((setup) => ({\n id: setup.id,\n name: setup.name,\n createdAt: setup.createdAt,\n ...(setup.cwd === undefined ? {} : { cwd: setup.cwd }),\n ...(setup.setupKind === undefined ? {} : { setupKind: setup.setupKind }),\n ...(setup.status === undefined ? {} : { status: setup.status }),\n ...(setup.errorCode === undefined ? {} : { errorCode: setup.errorCode }),\n })),\n }),\n ...(session.activity === undefined\n ? {}\n : {\n activity: {\n label: session.activity.label,\n ...(session.activity.attention === true ? { attention: true } : {}),\n ...(session.activity.since === undefined ? {} : { since: session.activity.since }),\n },\n }),\n ...(session.pendingApprovalCount === undefined ? {} : { pendingApprovalCount: session.pendingApprovalCount }),\n };\n}\n\n/**\n * A recorded session with no runtime behind it yet.\n *\n * Carries the same field set as a live session so the rail keys both by id and\n * swaps one for the other in place once the server reopens the journal.\n */\nfunction dormantView(record: OpenSessionRecord, pendingApprovalCount?: number): HubSessionView {\n return {\n id: record.sessionId,\n workspaceId: record.workspaceId,\n name: record.name,\n cwd: record.cwd,\n createdAt: record.createdAt,\n updatedAt: record.createdAt,\n phase: 'idle',\n phaseSince: record.createdAt,\n attach: 'attached',\n pendingMessageCount: 0,\n everPrompted: false,\n awaitingInput: false,\n dormant: true,\n ...(pendingApprovalCount === undefined ? {} : { pendingApprovalCount }),\n ...(record.parentSessionId === undefined ? {} : { parentSessionId: record.parentSessionId }),\n ...(record.sessionProvenance === undefined ? {} : { sessionProvenance: record.sessionProvenance }),\n ...(record.interaction === undefined ? {} : { interaction: record.interaction }),\n ...(record.groups === undefined || record.groups.length === 0 ? {} : { groups: [...record.groups] }),\n };\n}\n\n/** Each restarted session host gets a new generation, so its projection starts fresh. */\nconst generations = new WeakMap<object, number>();\nlet nextGeneration = 0;\nfunction generationOf(host: object): number {\n let generation = generations.get(host);\n if (generation === undefined) {\n generation = nextGeneration++;\n generations.set(host, generation);\n }\n return generation;\n}\n\nfunction permitsSession(\n hub: HeadlessHub,\n mount: PoSocketMount,\n sessionId: string,\n authorize: (id: string) => boolean = () => true,\n): boolean {\n const session = hub.session(sessionId);\n return (\n session !== undefined &&\n authorize(sessionId) &&\n (mount.scope === 'global' ||\n (session.workspaceId === mount.workspaceId && (mount.scope === 'workspace' || mount.sessionId === sessionId)))\n );\n}\n\nfunction permitsDormant(mount: PoSocketMount, record: OpenSessionRecord): boolean {\n if (mount.scope === 'global') return true;\n if (record.workspaceId !== mount.workspaceId) return false;\n return mount.scope === 'workspace' || mount.sessionId === record.sessionId;\n}\n\n/** What one upgraded connection may reach, decided from its request when it connected. */\nexport interface ConnectionAccess {\n readonly mount: PoSocketMount;\n /** Evaluated for every call, including references taken before a Desktop claim. */\n authorizeSession(sessionId: string): boolean;\n authorizeDesktop(): boolean;\n authorizeComputerUse(sessionId: string): boolean;\n}\n\ninterface Connection extends ConnectionAccess {\n /** Sessions this connection reached, rechecked when computer-use ownership changes. */\n readonly sessions: Set<string>;\n}\n\ninterface Principal {\n connectionId: string;\n}\n\nexport interface HeadlessProtocol {\n /** Hands an authenticated link to the shared host. Without `access` it sees everything Desktop does not own. */\n accept(link: Link, access?: Partial<ConnectionAccess>): void;\n close(): Promise<void>;\n}\n\nconst eventsOf = (hub: HeadlessHub): Subscribable<HeadlessHubEvent> => ({\n subscribe: (listener) => hub.onEvent(listener),\n});\n\n/** One Chord host for every browser, native and relayed connection over the process-local hub. */\nexport function createHeadlessProtocol(options: {\n hub: HeadlessHub;\n telemetry?: ServerTelemetry;\n onNotice?: (message: string) => void;\n /** Recorded sessions the server has not reopened. */\n dormantSessions?: () => readonly OpenSessionRecord[];\n}): HeadlessProtocol {\n const hub = options.hub;\n const dormantSessions = () => (options.dormantSessions === undefined ? [] : options.dormantSessions());\n const connections = new Map<string, Connection>();\n const threads = createThreadJournals({\n resolve: (sessionId, threadId) => hub.childThread(sessionId, threadId),\n });\n const host = createHost<Principal>({\n name: PO_SERVER_HOST,\n self: { connectionId: PO_SERVER_HOST },\n principalKey: (principal) => principal.connectionId,\n onError: (error) => options.onNotice?.(`headless protocol error (${harnessErrorMessage(error)})`),\n });\n const connectionOf = (principal: Principal): Connection & { connectionId: string } => {\n const connection = connections.get(principal.connectionId);\n if (connection === undefined) throw forbidden('This connection has closed.');\n return { ...connection, connectionId: principal.connectionId };\n };\n const reachable = (connection: Connection, sessionId: string): boolean =>\n permitsSession(hub, connection.mount, sessionId, (id) => connection.authorizeSession(id));\n\n // A Desktop claim makes every reference the connection holds to that session gone at once.\n const stopClaims = hub.computerUse?.subscribe?.(() => {\n for (const [connectionId, connection] of connections) {\n let revoked = false;\n for (const sessionId of connection.sessions) if (!connection.authorizeSession(sessionId)) revoked = true;\n if (!revoked) continue;\n connection.sessions.clear();\n void host.invalidatePrincipal((principal) => principal.connectionId === connectionId);\n }\n });\n\n host.serve(PoHubContract, (_input, principal, self) => {\n const connection = connectionOf(principal);\n const { mount } = connection;\n const visibleSessions = (): Record<string, HubSessionView> => {\n const views: Record<string, HubSessionView> = {};\n for (const session of hub.snapshot())\n if (reachable(connection, session.id)) views[session.id] = sessionView(session);\n // A dormant record of a removed workspace has no HTTP list to come from, so clients would never agree on it.\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n for (const record of dormantSessions())\n if (\n views[record.sessionId] === undefined &&\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId) &&\n permitsDormant(mount, record)\n )\n views[record.sessionId] = dormantView(record, hub.sessionPendingApprovalCount?.(record.sessionId));\n return views;\n };\n const visibleWorkspaces = (): Record<string, HubWorkspaceView> => {\n const views: Record<string, HubWorkspaceView> = {};\n for (const workspace of hub.workspaces())\n if (mount.scope === 'global' || workspace.id === mount.workspaceId)\n views[workspace.id] = {\n id: workspace.id,\n root: workspace.root,\n ...(workspace.kind === undefined ? {} : { kind: workspace.kind }),\n ...(workspace.name === undefined ? {} : { name: workspace.name }),\n ...(workspace.sandbox === undefined ? {} : { sandbox: workspace.sandbox }),\n ...(workspace.sandboxState === undefined ? {} : { sandboxState: workspace.sandboxState }),\n ...(workspace.sandboxReason === undefined ? {} : { sandboxReason: workspace.sandboxReason }),\n available: workspace.available !== false,\n };\n return views;\n };\n const sessions = self.state('sessions', chordSchema(Type.Record(Type.String(), SessionSummarySchema)), {\n init: visibleSessions,\n });\n const workspaces = self.state('workspaces', chordSchema(Type.Record(Type.String(), HubWorkspaceSchema)), {\n init: visibleWorkspaces,\n });\n const pending = self.state('pending', chordSchema(Type.Array(HubNoticeSchema)), [] as HubNotice[]);\n const visibleCompositions = (): Record<string, number> => {\n const revisions = hub.compositionRevisions?.() ?? {};\n if (mount.scope === 'global') return { ...revisions };\n const own = `workspace:${mount.workspaceId}`;\n return Object.fromEntries(Object.entries(revisions).filter(([key]) => key === 'global' || key === own));\n };\n const compositions = self.state('compositions', chordSchema(HubCompositionsSchema), { init: visibleCompositions });\n self.on('hub', eventsOf(hub), (event, ctx) => {\n switch (event.kind) {\n case 'upsert':\n case 'removed':\n case 'dormant_changed':\n // Recomputed rather than patched, so an event before this listener started cannot leave a stale row.\n sessions.replace(ctx, visibleSessions(), { diff: true });\n return;\n case 'workspace_upsert':\n case 'workspace_removed':\n workspaces.replace(ctx, visibleWorkspaces(), { diff: true });\n return;\n case 'compositions':\n compositions.replace(ctx, visibleCompositions(), { diff: true });\n return;\n case 'frame':\n if (!reachable(connection, event.sessionId)) return;\n pending.change(ctx, (draft) => {\n draft.push({\n id: randomUUID(),\n sessionId: event.sessionId,\n frame: event.frame as Record<string, JsonValue>,\n });\n if (draft.length > MAX_PENDING_NOTICES) draft.splice(0, draft.length - MAX_PENDING_NOTICES);\n });\n return;\n case 'channel':\n return;\n }\n });\n return {\n variant: 'default',\n sessions,\n workspaces,\n pending,\n compositions,\n readHome: async (request) => {\n if (!hub.readHome) throw new Error('Home read is unavailable.');\n return hub.readHome(request, (id) => reachable(connection, id));\n },\n invoke: async (call: PoPluginCall, ctx) => {\n if (call.mount.scope === 'session' && !connection.authorizeSession(call.mount.sessionId))\n throw forbidden('This session belongs to its Desktop instance.');\n if (mount.scope !== 'global') {\n const permitted =\n call.mount.scope === 'session'\n ? permitsSession(hub, mount, call.mount.sessionId)\n : mount.scope === 'workspace' &&\n call.mount.scope === 'workspace' &&\n call.mount.workspaceId === mount.workspaceId;\n if (!permitted) throw forbidden('Plugin is outside this WebSocket scope.');\n }\n return (await hub.invokePlugin(call, 'client-to-server', {\n connectionId: connection.connectionId,\n signal: ctx.signal,\n })) as JsonValue;\n },\n ackNotice: async ({ id }, ctx) => {\n pending.change(ctx, (draft) => draft.filter((notice) => notice.id !== id));\n },\n };\n });\n\n host.serve(PoHubRevisionsContract, (_input, principal, self) => {\n const { mount } = connectionOf(principal);\n const visibleRevisions = (): Record<string, number> => {\n const revisions = hub.revisions?.() ?? {};\n if (mount.scope === 'global') return { ...revisions };\n const own = `workspace:${mount.workspaceId}:`;\n return Object.fromEntries(\n Object.entries(revisions).filter(([topic]) => topic.startsWith('global:') || topic.startsWith(own)),\n );\n };\n const revisions = self.state('revisions', chordSchema(HubRevisionsSchema), { init: visibleRevisions });\n self.on('hub', eventsOf(hub), (event, ctx) => {\n if (event.kind === 'revisions') revisions.replace(ctx, visibleRevisions(), { diff: true });\n });\n return { variant: 'default', revisions };\n });\n\n host.serve(\n PoThreadContract,\n ({ sessionId, threadId }, principal, self) => {\n const connection = connectionOf(principal);\n if (!reachable(connection, sessionId)) throw forbidden(`No session ${sessionId}`);\n connection.sessions.add(sessionId);\n const tail = self.resource('tail', {\n version: 1,\n open: () => threads.subscribe(sessionId, threadId),\n close: () => threads.unsubscribe(sessionId, threadId),\n });\n const frame = self.state('frame', chordSchema(PoThreadFrameSchema), {\n init: () => (tail.value?.at(-1) ?? null) as never,\n });\n self.on(\n 'frames',\n { subscribe: (listener) => threads.onFrame(listener) } as Subscribable<{\n sessionId: string;\n threadId: string;\n frame: Record<string, unknown>;\n }>,\n (event, ctx) => {\n // Each frame is a fresh wrapper around the child's state, so only an explicit diff sends ops, not the whole state.\n if (event.sessionId === sessionId && event.threadId === threadId)\n frame.replace(ctx, event.frame as never, { diff: true });\n },\n );\n return { variant: 'default', frame };\n },\n { linger: THREAD_LINGER_MS },\n );\n\n host.serve(PoChannelsContract, ({ sessionId }, principal, self) => {\n const connection = connectionOf(principal);\n if (!reachable(connection, sessionId)) throw forbidden(`No session ${sessionId}`);\n connection.sessions.add(sessionId);\n const visible = (frameType: string): boolean =>\n frameType !== 'computer_use_state' || connection.authorizeComputerUse(sessionId);\n const latest = self.state('latest', chordSchema(PoChannelsStateSchema), {\n init: () => {\n const payloads: Record<string, JsonValue> = {};\n for (const channelFrame of hub.channelFrames(sessionId))\n if (visible(channelFrame.type)) payloads[channelFrame.type] = channelFrame.payload as JsonValue;\n return payloads;\n },\n });\n // ponytail: a channel keeps only its latest payload; a package that needs every event must carry a sequence.\n self.on('hub', eventsOf(hub), (event, ctx) => {\n if (event.kind !== 'channel' || event.sessionId !== sessionId || !visible(event.frameType)) return;\n if (event.connectionId !== undefined && event.connectionId !== connection.connectionId) return;\n latest.change(ctx, (draft) => {\n draft[event.frameType] = event.payload as JsonValue;\n });\n });\n return {\n variant: 'default',\n latest,\n receive: async ({ type, payload }) => {\n if (!connection.authorizeSession(sessionId)) throw forbidden('This session belongs to Desktop.');\n hub.receiveChannel(\n sessionId,\n type,\n payload,\n connection.connectionId,\n connection.authorizeDesktop(),\n connection.authorizeComputerUse(sessionId),\n );\n },\n };\n });\n\n const clearSessionBindings = serveAgentSessions(host, {\n resolve(sessionId, principal): AgentSessionBinding | undefined {\n const connection = connectionOf(principal as Principal);\n const session = hub.session(sessionId);\n if (!session || !reachable(connection, session.id)) return undefined;\n connection.sessions.add(sessionId);\n const permitted = () => hub.session(session.id)?.host === session.host && connection.authorizeSession(session.id);\n // A mirror of a session another host runs forwards there; keyed by its host object, never by session id.\n const forward = session.host.agentSession;\n if (forward !== undefined)\n return { generation: generationOf(session.host), exited: session.host.runtime.exited, permitted, forward };\n return {\n generation: generationOf(session.host),\n exited: session.host.runtime.exited,\n permitted,\n options: {\n runtime: session.host.runtime,\n onPresentationFrame: (listen) =>\n session.host.onPresentationFrame((frame) => {\n if (permitted()) listen(frame);\n }),\n respondToExtensionUi: (frame) => {\n if (!permitted()) throw forbidden('This session belongs to Desktop.');\n return session.host.respondToExtensionUi(frame);\n },\n readThreadTranscript: (threadId, request, readContext) => {\n if (!permitted()) throw forbidden('This session belongs to Desktop.');\n return threads.readPage(session.id, threadId, request, readContext);\n },\n sessionId: session.id,\n sessionName: session.name,\n cwd: session.cwd,\n telemetry: options.telemetry,\n },\n };\n },\n });\n\n let closing: Promise<void> | undefined;\n return {\n accept(link, access = {}) {\n if (closing !== undefined) {\n link.close();\n return;\n }\n const connectionId = randomUUID();\n const authorizeSession = access.authorizeSession ?? ((id: string) => !hub.computerUse?.ownsSession?.(id));\n const authorizeDesktop = access.authorizeDesktop ?? (() => false);\n connections.set(connectionId, {\n mount: access.mount ?? { scope: 'global' },\n authorizeSession,\n authorizeDesktop,\n authorizeComputerUse: access.authorizeComputerUse ?? (() => authorizeDesktop()),\n sessions: new Set(),\n });\n link.onClose(() => {\n connections.delete(connectionId);\n hub.disconnectChannels(connectionId);\n });\n host.accept(reportingLargeFrames(link, options.onNotice, options.telemetry), {\n principal: { connectionId },\n kind: 'client',\n });\n },\n close() {\n closing ??= (async () => {\n stopClaims?.();\n threads.close();\n clearSessionBindings();\n await host.close();\n })();\n return closing;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmCA,MAAM,sBAAsB;;AAE5B,MAAM,mBAAmB;AAEzB,SAAS,YAAY,SAA6C;CAChE,OAAO;EACL,IAAI,QAAQ;EACZ,GAAI,QAAQ,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;EAChF,GAAI,QAAQ,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,gBAAgB,EAAE,GAAG,QAAQ,eAAe,EAAE;EAChG,GAAI,QAAQ,sBAAsB,KAAA,IAAY,CAAC,IAAI,EAAE,mBAAmB,EAAE,GAAG,QAAQ,kBAAkB,EAAE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U,GAAG,OAAA,GAAMf,uBAAAA,UAAAA,CAAU,kCAAkC;KACpE,OAAO,QAAQ,KAAK,qBAAqB,KAAK;IAChD;IACA,uBAAuB,UAAU,SAAS,gBAAgB;KACxD,IAAI,CAAC,UAAU,GAAG,OAAA,GAAMA,uBAAAA,UAAAA,CAAU,kCAAkC;KACpE,OAAO,QAAQ,SAAS,QAAQ,IAAI,UAAU,SAAS,WAAW;IACpE;IACA,WAAW,QAAQ;IACnB,aAAa,QAAQ;IACrB,KAAK,QAAQ;IACb,WAAW,QAAQ;GACrB;EACF;CACF,EACF,CAAC;CAED,IAAI;CACJ,OAAO;EACL,OAAO,MAAM,SAAS,CAAC,GAAG;GACxB,IAAI,YAAY,KAAA,GAAW;IACzB,KAAK,MAAM;IACX;GACF;GACA,MAAM,gBAAA,GAAeQ,YAAAA,WAAAA,CAAW;GAChC,MAAM,mBAAmB,OAAO,sBAAsB,OAAe,CAAC,IAAI,aAAa,cAAc,EAAE;GACvG,MAAM,mBAAmB,OAAO,2BAA2B;GAC3D,YAAY,IAAI,cAAc;IAC5B,OAAO,OAAO,SAAS,EAAE,OAAO,SAAS;IACzC;IACA;IACA,sBAAsB,OAAO,+BAA+B,iBAAiB;IAC7E,0BAAU,IAAI,IAAI;GACpB,CAAC;GACD,KAAK,cAAc;IACjB,YAAY,OAAO,YAAY;IAC/B,IAAI,mBAAmB,YAAY;GACrC,CAAC;GACD,KAAK,OAAOQ,uBAAAA,qBAAqB,MAAM,QAAQ,UAAU,QAAQ,SAAS,GAAG;IAC3E,WAAW,EAAE,aAAa;IAC1B,MAAM;GACR,CAAC;EACH;EACA,QAAQ;GACN,aAAa,YAAY;IACvB,aAAa;IACb,QAAQ,MAAM;IACd,qBAAqB;IACrB,MAAM,KAAK,MAAM;GACnB,EAAA,CAAG;GACH,OAAO;EACT;CACF;AACF"}
@@ -290,7 +290,7 @@ function createHeadlessProtocol(options) {
290
290
  }
291
291
  };
292
292
  });
293
- serveAgentSessions(host, { resolve(sessionId, principal) {
293
+ const clearSessionBindings = serveAgentSessions(host, { resolve(sessionId, principal) {
294
294
  const connection = connectionOf(principal);
295
295
  const session = hub.session(sessionId);
296
296
  if (!session || !reachable(connection, session.id)) return void 0;
@@ -357,6 +357,7 @@ function createHeadlessProtocol(options) {
357
357
  closing ??= (async () => {
358
358
  stopClaims?.();
359
359
  threads.close();
360
+ clearSessionBindings();
360
361
  await host.close();
361
362
  })();
362
363
  return closing;
@@ -1 +1 @@
1
- {"version":3,"file":"headlessProtocol.mjs","names":[],"sources":["../src/server/headlessProtocol.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport { createHost, forbidden, type Link, type Subscribable } from '@earendil-works/chord';\nimport { Type } from 'typebox';\n\nimport type { PoPluginCall } from '../exports/pluginProtocol';\nimport {\n HubCompositionsSchema,\n HubNoticeSchema,\n HubRevisionsSchema,\n PO_SERVER_HOST,\n PoChannelsContract,\n PoHubContract,\n PoHubRevisionsContract,\n PoThreadContract,\n type HubNotice,\n type HubSessionView,\n type HubWorkspaceView,\n type JsonValue,\n} from '../exports/sessionProtocol';\nimport { serveAgentSessions, type AgentSessionBinding } from '../pi/piSessionRuntime';\nimport { SessionSummarySchema } from '../schemas/httpApiContracts';\nimport type { PoSocketMount } from '../schemas/packageApi';\nimport { PoChannelsStateSchema } from '../schemas/protocolChannelsContract';\nimport { chordSchema } from '../schemas/protocolContracts';\nimport { HubWorkspaceSchema } from '../schemas/protocolHubContract';\nimport { PoThreadFrameSchema } from '../schemas/protocolThreadContract';\nimport type { OpenSessionRecord } from '../services/openSessionRegistry';\nimport type { ServerTelemetry } from '../services/serverTelemetry';\nimport { harnessErrorMessage } from './harnessErrorMessage';\nimport type { HeadlessHub, HeadlessHubEvent, HeadlessHubSession } from './headlessHub';\nimport { reportingLargeFrames } from './largeFrameLink';\nimport { createThreadJournals } from './threadJournals';\n\n// ponytail: unacknowledged notices beyond this drop oldest first; raise it if a client misses dialogs.\nconst MAX_PENDING_NOTICES = 64;\n/** A browser switching back to a thread quickly keeps its tail open. */\nconst THREAD_LINGER_MS = 5_000;\n\nfunction sessionView(session: HeadlessHubSession): HubSessionView {\n return {\n id: session.id,\n ...(session.workspaceId === undefined ? {} : { workspaceId: session.workspaceId }),\n ...(session.webComposition === undefined ? {} : { webComposition: { ...session.webComposition } }),\n ...(session.nativeComposition === undefined ? {} : { nativeComposition: { ...session.nativeComposition } }),\n name: session.name,\n cwd: session.cwd,\n createdAt: session.createdAt,\n updatedAt: session.updatedAt ?? session.createdAt,\n phase: session.phase ?? 'idle',\n phaseSince: session.phaseSince ?? session.createdAt,\n attach: 'attached',\n pendingMessageCount: session.pendingMessageCount ?? 0,\n everPrompted: session.everPrompted ?? false,\n awaitingInput: session.awaitingInput ?? false,\n ...(session.lastSettledAt === undefined ? {} : { lastSettledAt: session.lastSettledAt }),\n // null: the host has not reported yet.\n ...(session.backgroundWorkActive == null ? {} : { backgroundWorkActive: session.backgroundWorkActive }),\n ...(session.git === undefined ? {} : { git: { branch: session.git.branch, dirty: session.git.dirty } }),\n ...(session.profile === undefined\n ? {}\n : {\n profile: {\n name: session.profile.name,\n ...(session.profile.displayName === undefined ? {} : { displayName: session.profile.displayName }),\n ...(session.profile.iconVersion === undefined ? {} : { iconVersion: session.profile.iconVersion }),\n },\n }),\n ...(session.parentSessionId === undefined ? {} : { parentSessionId: session.parentSessionId }),\n ...(session.sessionProvenance === undefined ? {} : { sessionProvenance: session.sessionProvenance }),\n ...(session.interaction === undefined ? {} : { interaction: session.interaction }),\n ...(session.groups === undefined || session.groups.length === 0 ? {} : { groups: [...session.groups] }),\n ...(session.pendingSetups === undefined\n ? {}\n : {\n pendingSetups: session.pendingSetups.map((setup) => ({\n id: setup.id,\n name: setup.name,\n createdAt: setup.createdAt,\n ...(setup.cwd === undefined ? {} : { cwd: setup.cwd }),\n ...(setup.setupKind === undefined ? {} : { setupKind: setup.setupKind }),\n ...(setup.status === undefined ? {} : { status: setup.status }),\n ...(setup.errorCode === undefined ? {} : { errorCode: setup.errorCode }),\n })),\n }),\n ...(session.activity === undefined\n ? {}\n : {\n activity: {\n label: session.activity.label,\n ...(session.activity.attention === true ? { attention: true } : {}),\n ...(session.activity.since === undefined ? {} : { since: session.activity.since }),\n },\n }),\n ...(session.pendingApprovalCount === undefined ? {} : { pendingApprovalCount: session.pendingApprovalCount }),\n };\n}\n\n/**\n * A recorded session with no runtime behind it yet.\n *\n * Carries the same field set as a live session so the rail keys both by id and\n * swaps one for the other in place once the server reopens the journal.\n */\nfunction dormantView(record: OpenSessionRecord, pendingApprovalCount?: number): HubSessionView {\n return {\n id: record.sessionId,\n workspaceId: record.workspaceId,\n name: record.name,\n cwd: record.cwd,\n createdAt: record.createdAt,\n updatedAt: record.createdAt,\n phase: 'idle',\n phaseSince: record.createdAt,\n attach: 'attached',\n pendingMessageCount: 0,\n everPrompted: false,\n awaitingInput: false,\n dormant: true,\n ...(pendingApprovalCount === undefined ? {} : { pendingApprovalCount }),\n ...(record.parentSessionId === undefined ? {} : { parentSessionId: record.parentSessionId }),\n ...(record.sessionProvenance === undefined ? {} : { sessionProvenance: record.sessionProvenance }),\n ...(record.interaction === undefined ? {} : { interaction: record.interaction }),\n ...(record.groups === undefined || record.groups.length === 0 ? {} : { groups: [...record.groups] }),\n };\n}\n\n/** Each restarted session host gets a new generation, so its projection starts fresh. */\nconst generations = new WeakMap<object, number>();\nlet nextGeneration = 0;\nfunction generationOf(host: object): number {\n let generation = generations.get(host);\n if (generation === undefined) {\n generation = nextGeneration++;\n generations.set(host, generation);\n }\n return generation;\n}\n\nfunction permitsSession(\n hub: HeadlessHub,\n mount: PoSocketMount,\n sessionId: string,\n authorize: (id: string) => boolean = () => true,\n): boolean {\n const session = hub.session(sessionId);\n return (\n session !== undefined &&\n authorize(sessionId) &&\n (mount.scope === 'global' ||\n (session.workspaceId === mount.workspaceId && (mount.scope === 'workspace' || mount.sessionId === sessionId)))\n );\n}\n\nfunction permitsDormant(mount: PoSocketMount, record: OpenSessionRecord): boolean {\n if (mount.scope === 'global') return true;\n if (record.workspaceId !== mount.workspaceId) return false;\n return mount.scope === 'workspace' || mount.sessionId === record.sessionId;\n}\n\n/** What one upgraded connection may reach, decided from its request when it connected. */\nexport interface ConnectionAccess {\n readonly mount: PoSocketMount;\n /** Evaluated for every call, including references taken before a Desktop claim. */\n authorizeSession(sessionId: string): boolean;\n authorizeDesktop(): boolean;\n authorizeComputerUse(sessionId: string): boolean;\n}\n\ninterface Connection extends ConnectionAccess {\n /** Sessions this connection reached, rechecked when computer-use ownership changes. */\n readonly sessions: Set<string>;\n}\n\ninterface Principal {\n connectionId: string;\n}\n\nexport interface HeadlessProtocol {\n /** Hands an authenticated link to the shared host. Without `access` it sees everything Desktop does not own. */\n accept(link: Link, access?: Partial<ConnectionAccess>): void;\n close(): Promise<void>;\n}\n\nconst eventsOf = (hub: HeadlessHub): Subscribable<HeadlessHubEvent> => ({\n subscribe: (listener) => hub.onEvent(listener),\n});\n\n/** One Chord host for every browser, native and relayed connection over the process-local hub. */\nexport function createHeadlessProtocol(options: {\n hub: HeadlessHub;\n telemetry?: ServerTelemetry;\n onNotice?: (message: string) => void;\n /** Recorded sessions the server has not reopened. */\n dormantSessions?: () => readonly OpenSessionRecord[];\n}): HeadlessProtocol {\n const hub = options.hub;\n const dormantSessions = () => (options.dormantSessions === undefined ? [] : options.dormantSessions());\n const connections = new Map<string, Connection>();\n const threads = createThreadJournals({\n resolve: (sessionId, threadId) => hub.childThread(sessionId, threadId),\n });\n const host = createHost<Principal>({\n name: PO_SERVER_HOST,\n self: { connectionId: PO_SERVER_HOST },\n principalKey: (principal) => principal.connectionId,\n onError: (error) => options.onNotice?.(`headless protocol error (${harnessErrorMessage(error)})`),\n });\n const connectionOf = (principal: Principal): Connection & { connectionId: string } => {\n const connection = connections.get(principal.connectionId);\n if (connection === undefined) throw forbidden('This connection has closed.');\n return { ...connection, connectionId: principal.connectionId };\n };\n const reachable = (connection: Connection, sessionId: string): boolean =>\n permitsSession(hub, connection.mount, sessionId, (id) => connection.authorizeSession(id));\n\n // A Desktop claim makes every reference the connection holds to that session gone at once.\n const stopClaims = hub.computerUse?.subscribe?.(() => {\n for (const [connectionId, connection] of connections) {\n let revoked = false;\n for (const sessionId of connection.sessions) if (!connection.authorizeSession(sessionId)) revoked = true;\n if (!revoked) continue;\n connection.sessions.clear();\n void host.invalidatePrincipal((principal) => principal.connectionId === connectionId);\n }\n });\n\n host.serve(PoHubContract, (_input, principal, self) => {\n const connection = connectionOf(principal);\n const { mount } = connection;\n const visibleSessions = (): Record<string, HubSessionView> => {\n const views: Record<string, HubSessionView> = {};\n for (const session of hub.snapshot())\n if (reachable(connection, session.id)) views[session.id] = sessionView(session);\n // A dormant record of a removed workspace has no HTTP list to come from, so clients would never agree on it.\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n for (const record of dormantSessions())\n if (\n views[record.sessionId] === undefined &&\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId) &&\n permitsDormant(mount, record)\n )\n views[record.sessionId] = dormantView(record, hub.sessionPendingApprovalCount?.(record.sessionId));\n return views;\n };\n const visibleWorkspaces = (): Record<string, HubWorkspaceView> => {\n const views: Record<string, HubWorkspaceView> = {};\n for (const workspace of hub.workspaces())\n if (mount.scope === 'global' || workspace.id === mount.workspaceId)\n views[workspace.id] = {\n id: workspace.id,\n root: workspace.root,\n ...(workspace.kind === undefined ? {} : { kind: workspace.kind }),\n ...(workspace.name === undefined ? {} : { name: workspace.name }),\n ...(workspace.sandbox === undefined ? {} : { sandbox: workspace.sandbox }),\n ...(workspace.sandboxState === undefined ? {} : { sandboxState: workspace.sandboxState }),\n ...(workspace.sandboxReason === undefined ? {} : { sandboxReason: workspace.sandboxReason }),\n available: workspace.available !== false,\n };\n return views;\n };\n const sessions = self.state('sessions', chordSchema(Type.Record(Type.String(), SessionSummarySchema)), {\n init: visibleSessions,\n });\n const workspaces = self.state('workspaces', chordSchema(Type.Record(Type.String(), HubWorkspaceSchema)), {\n init: visibleWorkspaces,\n });\n const pending = self.state('pending', chordSchema(Type.Array(HubNoticeSchema)), [] as HubNotice[]);\n const visibleCompositions = (): Record<string, number> => {\n const revisions = hub.compositionRevisions?.() ?? {};\n if (mount.scope === 'global') return { ...revisions };\n const own = `workspace:${mount.workspaceId}`;\n return Object.fromEntries(Object.entries(revisions).filter(([key]) => key === 'global' || key === own));\n };\n const compositions = self.state('compositions', chordSchema(HubCompositionsSchema), { init: visibleCompositions });\n self.on('hub', eventsOf(hub), (event, ctx) => {\n switch (event.kind) {\n case 'upsert':\n case 'removed':\n case 'dormant_changed':\n // Recomputed rather than patched, so an event before this listener started cannot leave a stale row.\n sessions.replace(ctx, visibleSessions(), { diff: true });\n return;\n case 'workspace_upsert':\n case 'workspace_removed':\n workspaces.replace(ctx, visibleWorkspaces(), { diff: true });\n return;\n case 'compositions':\n compositions.replace(ctx, visibleCompositions(), { diff: true });\n return;\n case 'frame':\n if (!reachable(connection, event.sessionId)) return;\n pending.change(ctx, (draft) => {\n draft.push({\n id: randomUUID(),\n sessionId: event.sessionId,\n frame: event.frame as Record<string, JsonValue>,\n });\n if (draft.length > MAX_PENDING_NOTICES) draft.splice(0, draft.length - MAX_PENDING_NOTICES);\n });\n return;\n case 'channel':\n return;\n }\n });\n return {\n variant: 'default',\n sessions,\n workspaces,\n pending,\n compositions,\n readHome: async (request) => {\n if (!hub.readHome) throw new Error('Home read is unavailable.');\n return hub.readHome(request, (id) => reachable(connection, id));\n },\n invoke: async (call: PoPluginCall, ctx) => {\n if (call.mount.scope === 'session' && !connection.authorizeSession(call.mount.sessionId))\n throw forbidden('This session belongs to its Desktop instance.');\n if (mount.scope !== 'global') {\n const permitted =\n call.mount.scope === 'session'\n ? permitsSession(hub, mount, call.mount.sessionId)\n : mount.scope === 'workspace' &&\n call.mount.scope === 'workspace' &&\n call.mount.workspaceId === mount.workspaceId;\n if (!permitted) throw forbidden('Plugin is outside this WebSocket scope.');\n }\n return (await hub.invokePlugin(call, 'client-to-server', {\n connectionId: connection.connectionId,\n signal: ctx.signal,\n })) as JsonValue;\n },\n ackNotice: async ({ id }, ctx) => {\n pending.change(ctx, (draft) => draft.filter((notice) => notice.id !== id));\n },\n };\n });\n\n host.serve(PoHubRevisionsContract, (_input, principal, self) => {\n const { mount } = connectionOf(principal);\n const visibleRevisions = (): Record<string, number> => {\n const revisions = hub.revisions?.() ?? {};\n if (mount.scope === 'global') return { ...revisions };\n const own = `workspace:${mount.workspaceId}:`;\n return Object.fromEntries(\n Object.entries(revisions).filter(([topic]) => topic.startsWith('global:') || topic.startsWith(own)),\n );\n };\n const revisions = self.state('revisions', chordSchema(HubRevisionsSchema), { init: visibleRevisions });\n self.on('hub', eventsOf(hub), (event, ctx) => {\n if (event.kind === 'revisions') revisions.replace(ctx, visibleRevisions(), { diff: true });\n });\n return { variant: 'default', revisions };\n });\n\n host.serve(\n PoThreadContract,\n ({ sessionId, threadId }, principal, self) => {\n const connection = connectionOf(principal);\n if (!reachable(connection, sessionId)) throw forbidden(`No session ${sessionId}`);\n connection.sessions.add(sessionId);\n const tail = self.resource('tail', {\n version: 1,\n open: () => threads.subscribe(sessionId, threadId),\n close: () => threads.unsubscribe(sessionId, threadId),\n });\n const frame = self.state('frame', chordSchema(PoThreadFrameSchema), {\n init: () => (tail.value?.at(-1) ?? null) as never,\n });\n self.on(\n 'frames',\n { subscribe: (listener) => threads.onFrame(listener) } as Subscribable<{\n sessionId: string;\n threadId: string;\n frame: Record<string, unknown>;\n }>,\n (event, ctx) => {\n // Each frame is a fresh wrapper around the child's state, so only an explicit diff sends ops, not the whole state.\n if (event.sessionId === sessionId && event.threadId === threadId)\n frame.replace(ctx, event.frame as never, { diff: true });\n },\n );\n return { variant: 'default', frame };\n },\n { linger: THREAD_LINGER_MS },\n );\n\n host.serve(PoChannelsContract, ({ sessionId }, principal, self) => {\n const connection = connectionOf(principal);\n if (!reachable(connection, sessionId)) throw forbidden(`No session ${sessionId}`);\n connection.sessions.add(sessionId);\n const visible = (frameType: string): boolean =>\n frameType !== 'computer_use_state' || connection.authorizeComputerUse(sessionId);\n const latest = self.state('latest', chordSchema(PoChannelsStateSchema), {\n init: () => {\n const payloads: Record<string, JsonValue> = {};\n for (const channelFrame of hub.channelFrames(sessionId))\n if (visible(channelFrame.type)) payloads[channelFrame.type] = channelFrame.payload as JsonValue;\n return payloads;\n },\n });\n // ponytail: a channel keeps only its latest payload; a package that needs every event must carry a sequence.\n self.on('hub', eventsOf(hub), (event, ctx) => {\n if (event.kind !== 'channel' || event.sessionId !== sessionId || !visible(event.frameType)) return;\n if (event.connectionId !== undefined && event.connectionId !== connection.connectionId) return;\n latest.change(ctx, (draft) => {\n draft[event.frameType] = event.payload as JsonValue;\n });\n });\n return {\n variant: 'default',\n latest,\n receive: async ({ type, payload }) => {\n if (!connection.authorizeSession(sessionId)) throw forbidden('This session belongs to Desktop.');\n hub.receiveChannel(\n sessionId,\n type,\n payload,\n connection.connectionId,\n connection.authorizeDesktop(),\n connection.authorizeComputerUse(sessionId),\n );\n },\n };\n });\n\n serveAgentSessions(host, {\n resolve(sessionId, principal): AgentSessionBinding | undefined {\n const connection = connectionOf(principal as Principal);\n const session = hub.session(sessionId);\n if (!session || !reachable(connection, session.id)) return undefined;\n connection.sessions.add(sessionId);\n const permitted = () => hub.session(session.id)?.host === session.host && connection.authorizeSession(session.id);\n // A mirror of a session another host runs forwards there; keyed by its host object, never by session id.\n const forward = session.host.agentSession;\n if (forward !== undefined)\n return { generation: generationOf(session.host), exited: session.host.runtime.exited, permitted, forward };\n return {\n generation: generationOf(session.host),\n exited: session.host.runtime.exited,\n permitted,\n options: {\n runtime: session.host.runtime,\n onPresentationFrame: (listen) =>\n session.host.onPresentationFrame((frame) => {\n if (permitted()) listen(frame);\n }),\n respondToExtensionUi: (frame) => {\n if (!permitted()) throw forbidden('This session belongs to Desktop.');\n return session.host.respondToExtensionUi(frame);\n },\n readThreadTranscript: (threadId, request, readContext) => {\n if (!permitted()) throw forbidden('This session belongs to Desktop.');\n return threads.readPage(session.id, threadId, request, readContext);\n },\n sessionId: session.id,\n sessionName: session.name,\n cwd: session.cwd,\n telemetry: options.telemetry,\n },\n };\n },\n });\n\n let closing: Promise<void> | undefined;\n return {\n accept(link, access = {}) {\n if (closing !== undefined) {\n link.close();\n return;\n }\n const connectionId = randomUUID();\n const authorizeSession = access.authorizeSession ?? ((id: string) => !hub.computerUse?.ownsSession?.(id));\n const authorizeDesktop = access.authorizeDesktop ?? (() => false);\n connections.set(connectionId, {\n mount: access.mount ?? { scope: 'global' },\n authorizeSession,\n authorizeDesktop,\n authorizeComputerUse: access.authorizeComputerUse ?? (() => authorizeDesktop()),\n sessions: new Set(),\n });\n link.onClose(() => {\n connections.delete(connectionId);\n hub.disconnectChannels(connectionId);\n });\n host.accept(reportingLargeFrames(link, options.onNotice, options.telemetry), {\n principal: { connectionId },\n kind: 'client',\n });\n },\n close() {\n closing ??= (async () => {\n stopClaims?.();\n threads.close();\n await host.close();\n })();\n return closing;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAmCA,MAAM,sBAAsB;;AAE5B,MAAM,mBAAmB;AAEzB,SAAS,YAAY,SAA6C;CAChE,OAAO;EACL,IAAI,QAAQ;EACZ,GAAI,QAAQ,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;EAChF,GAAI,QAAQ,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,gBAAgB,EAAE,GAAG,QAAQ,eAAe,EAAE;EAChG,GAAI,QAAQ,sBAAsB,KAAA,IAAY,CAAC,IAAI,EAAE,mBAAmB,EAAE,GAAG,QAAQ,kBAAkB,EAAE;EACzG,MAAM,QAAQ;EACd,KAAK,QAAQ;EACb,WAAW,QAAQ;EACnB,WAAW,QAAQ,aAAa,QAAQ;EACxC,OAAO,QAAQ,SAAS;EACxB,YAAY,QAAQ,cAAc,QAAQ;EAC1C,QAAQ;EACR,qBAAqB,QAAQ,uBAAuB;EACpD,cAAc,QAAQ,gBAAgB;EACtC,eAAe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0BAAU,IAAI,IAAI;GACpB,CAAC;GACD,KAAK,cAAc;IACjB,YAAY,OAAO,YAAY;IAC/B,IAAI,mBAAmB,YAAY;GACrC,CAAC;GACD,KAAK,OAAO,qBAAqB,MAAM,QAAQ,UAAU,QAAQ,SAAS,GAAG;IAC3E,WAAW,EAAE,aAAa;IAC1B,MAAM;GACR,CAAC;EACH;EACA,QAAQ;GACN,aAAa,YAAY;IACvB,aAAa;IACb,QAAQ,MAAM;IACd,MAAM,KAAK,MAAM;GACnB,EAAA,CAAG;GACH,OAAO;EACT;CACF;AACF"}
1
+ {"version":3,"file":"headlessProtocol.mjs","names":[],"sources":["../src/server/headlessProtocol.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport { createHost, forbidden, type Link, type Subscribable } from '@earendil-works/chord';\nimport { Type } from 'typebox';\n\nimport type { PoPluginCall } from '../exports/pluginProtocol';\nimport {\n HubCompositionsSchema,\n HubNoticeSchema,\n HubRevisionsSchema,\n PO_SERVER_HOST,\n PoChannelsContract,\n PoHubContract,\n PoHubRevisionsContract,\n PoThreadContract,\n type HubNotice,\n type HubSessionView,\n type HubWorkspaceView,\n type JsonValue,\n} from '../exports/sessionProtocol';\nimport { serveAgentSessions, type AgentSessionBinding } from '../pi/piSessionRuntime';\nimport { SessionSummarySchema } from '../schemas/httpApiContracts';\nimport type { PoSocketMount } from '../schemas/packageApi';\nimport { PoChannelsStateSchema } from '../schemas/protocolChannelsContract';\nimport { chordSchema } from '../schemas/protocolContracts';\nimport { HubWorkspaceSchema } from '../schemas/protocolHubContract';\nimport { PoThreadFrameSchema } from '../schemas/protocolThreadContract';\nimport type { OpenSessionRecord } from '../services/openSessionRegistry';\nimport type { ServerTelemetry } from '../services/serverTelemetry';\nimport { harnessErrorMessage } from './harnessErrorMessage';\nimport type { HeadlessHub, HeadlessHubEvent, HeadlessHubSession } from './headlessHub';\nimport { reportingLargeFrames } from './largeFrameLink';\nimport { createThreadJournals } from './threadJournals';\n\n// ponytail: unacknowledged notices beyond this drop oldest first; raise it if a client misses dialogs.\nconst MAX_PENDING_NOTICES = 64;\n/** A browser switching back to a thread quickly keeps its tail open. */\nconst THREAD_LINGER_MS = 5_000;\n\nfunction sessionView(session: HeadlessHubSession): HubSessionView {\n return {\n id: session.id,\n ...(session.workspaceId === undefined ? {} : { workspaceId: session.workspaceId }),\n ...(session.webComposition === undefined ? {} : { webComposition: { ...session.webComposition } }),\n ...(session.nativeComposition === undefined ? {} : { nativeComposition: { ...session.nativeComposition } }),\n name: session.name,\n cwd: session.cwd,\n createdAt: session.createdAt,\n updatedAt: session.updatedAt ?? session.createdAt,\n phase: session.phase ?? 'idle',\n phaseSince: session.phaseSince ?? session.createdAt,\n attach: 'attached',\n pendingMessageCount: session.pendingMessageCount ?? 0,\n everPrompted: session.everPrompted ?? false,\n awaitingInput: session.awaitingInput ?? false,\n ...(session.lastSettledAt === undefined ? {} : { lastSettledAt: session.lastSettledAt }),\n // null: the host has not reported yet.\n ...(session.backgroundWorkActive == null ? {} : { backgroundWorkActive: session.backgroundWorkActive }),\n ...(session.git === undefined ? {} : { git: { branch: session.git.branch, dirty: session.git.dirty } }),\n ...(session.profile === undefined\n ? {}\n : {\n profile: {\n name: session.profile.name,\n ...(session.profile.displayName === undefined ? {} : { displayName: session.profile.displayName }),\n ...(session.profile.iconVersion === undefined ? {} : { iconVersion: session.profile.iconVersion }),\n },\n }),\n ...(session.parentSessionId === undefined ? {} : { parentSessionId: session.parentSessionId }),\n ...(session.sessionProvenance === undefined ? {} : { sessionProvenance: session.sessionProvenance }),\n ...(session.interaction === undefined ? {} : { interaction: session.interaction }),\n ...(session.groups === undefined || session.groups.length === 0 ? {} : { groups: [...session.groups] }),\n ...(session.pendingSetups === undefined\n ? {}\n : {\n pendingSetups: session.pendingSetups.map((setup) => ({\n id: setup.id,\n name: setup.name,\n createdAt: setup.createdAt,\n ...(setup.cwd === undefined ? {} : { cwd: setup.cwd }),\n ...(setup.setupKind === undefined ? {} : { setupKind: setup.setupKind }),\n ...(setup.status === undefined ? {} : { status: setup.status }),\n ...(setup.errorCode === undefined ? {} : { errorCode: setup.errorCode }),\n })),\n }),\n ...(session.activity === undefined\n ? {}\n : {\n activity: {\n label: session.activity.label,\n ...(session.activity.attention === true ? { attention: true } : {}),\n ...(session.activity.since === undefined ? {} : { since: session.activity.since }),\n },\n }),\n ...(session.pendingApprovalCount === undefined ? {} : { pendingApprovalCount: session.pendingApprovalCount }),\n };\n}\n\n/**\n * A recorded session with no runtime behind it yet.\n *\n * Carries the same field set as a live session so the rail keys both by id and\n * swaps one for the other in place once the server reopens the journal.\n */\nfunction dormantView(record: OpenSessionRecord, pendingApprovalCount?: number): HubSessionView {\n return {\n id: record.sessionId,\n workspaceId: record.workspaceId,\n name: record.name,\n cwd: record.cwd,\n createdAt: record.createdAt,\n updatedAt: record.createdAt,\n phase: 'idle',\n phaseSince: record.createdAt,\n attach: 'attached',\n pendingMessageCount: 0,\n everPrompted: false,\n awaitingInput: false,\n dormant: true,\n ...(pendingApprovalCount === undefined ? {} : { pendingApprovalCount }),\n ...(record.parentSessionId === undefined ? {} : { parentSessionId: record.parentSessionId }),\n ...(record.sessionProvenance === undefined ? {} : { sessionProvenance: record.sessionProvenance }),\n ...(record.interaction === undefined ? {} : { interaction: record.interaction }),\n ...(record.groups === undefined || record.groups.length === 0 ? {} : { groups: [...record.groups] }),\n };\n}\n\n/** Each restarted session host gets a new generation, so its projection starts fresh. */\nconst generations = new WeakMap<object, number>();\nlet nextGeneration = 0;\nfunction generationOf(host: object): number {\n let generation = generations.get(host);\n if (generation === undefined) {\n generation = nextGeneration++;\n generations.set(host, generation);\n }\n return generation;\n}\n\nfunction permitsSession(\n hub: HeadlessHub,\n mount: PoSocketMount,\n sessionId: string,\n authorize: (id: string) => boolean = () => true,\n): boolean {\n const session = hub.session(sessionId);\n return (\n session !== undefined &&\n authorize(sessionId) &&\n (mount.scope === 'global' ||\n (session.workspaceId === mount.workspaceId && (mount.scope === 'workspace' || mount.sessionId === sessionId)))\n );\n}\n\nfunction permitsDormant(mount: PoSocketMount, record: OpenSessionRecord): boolean {\n if (mount.scope === 'global') return true;\n if (record.workspaceId !== mount.workspaceId) return false;\n return mount.scope === 'workspace' || mount.sessionId === record.sessionId;\n}\n\n/** What one upgraded connection may reach, decided from its request when it connected. */\nexport interface ConnectionAccess {\n readonly mount: PoSocketMount;\n /** Evaluated for every call, including references taken before a Desktop claim. */\n authorizeSession(sessionId: string): boolean;\n authorizeDesktop(): boolean;\n authorizeComputerUse(sessionId: string): boolean;\n}\n\ninterface Connection extends ConnectionAccess {\n /** Sessions this connection reached, rechecked when computer-use ownership changes. */\n readonly sessions: Set<string>;\n}\n\ninterface Principal {\n connectionId: string;\n}\n\nexport interface HeadlessProtocol {\n /** Hands an authenticated link to the shared host. Without `access` it sees everything Desktop does not own. */\n accept(link: Link, access?: Partial<ConnectionAccess>): void;\n close(): Promise<void>;\n}\n\nconst eventsOf = (hub: HeadlessHub): Subscribable<HeadlessHubEvent> => ({\n subscribe: (listener) => hub.onEvent(listener),\n});\n\n/** One Chord host for every browser, native and relayed connection over the process-local hub. */\nexport function createHeadlessProtocol(options: {\n hub: HeadlessHub;\n telemetry?: ServerTelemetry;\n onNotice?: (message: string) => void;\n /** Recorded sessions the server has not reopened. */\n dormantSessions?: () => readonly OpenSessionRecord[];\n}): HeadlessProtocol {\n const hub = options.hub;\n const dormantSessions = () => (options.dormantSessions === undefined ? [] : options.dormantSessions());\n const connections = new Map<string, Connection>();\n const threads = createThreadJournals({\n resolve: (sessionId, threadId) => hub.childThread(sessionId, threadId),\n });\n const host = createHost<Principal>({\n name: PO_SERVER_HOST,\n self: { connectionId: PO_SERVER_HOST },\n principalKey: (principal) => principal.connectionId,\n onError: (error) => options.onNotice?.(`headless protocol error (${harnessErrorMessage(error)})`),\n });\n const connectionOf = (principal: Principal): Connection & { connectionId: string } => {\n const connection = connections.get(principal.connectionId);\n if (connection === undefined) throw forbidden('This connection has closed.');\n return { ...connection, connectionId: principal.connectionId };\n };\n const reachable = (connection: Connection, sessionId: string): boolean =>\n permitsSession(hub, connection.mount, sessionId, (id) => connection.authorizeSession(id));\n\n // A Desktop claim makes every reference the connection holds to that session gone at once.\n const stopClaims = hub.computerUse?.subscribe?.(() => {\n for (const [connectionId, connection] of connections) {\n let revoked = false;\n for (const sessionId of connection.sessions) if (!connection.authorizeSession(sessionId)) revoked = true;\n if (!revoked) continue;\n connection.sessions.clear();\n void host.invalidatePrincipal((principal) => principal.connectionId === connectionId);\n }\n });\n\n host.serve(PoHubContract, (_input, principal, self) => {\n const connection = connectionOf(principal);\n const { mount } = connection;\n const visibleSessions = (): Record<string, HubSessionView> => {\n const views: Record<string, HubSessionView> = {};\n for (const session of hub.snapshot())\n if (reachable(connection, session.id)) views[session.id] = sessionView(session);\n // A dormant record of a removed workspace has no HTTP list to come from, so clients would never agree on it.\n const registered = new Set(hub.workspaces().map((workspace) => workspace.id));\n for (const record of dormantSessions())\n if (\n views[record.sessionId] === undefined &&\n registered.has(record.workspaceId) &&\n connection.authorizeSession(record.sessionId) &&\n permitsDormant(mount, record)\n )\n views[record.sessionId] = dormantView(record, hub.sessionPendingApprovalCount?.(record.sessionId));\n return views;\n };\n const visibleWorkspaces = (): Record<string, HubWorkspaceView> => {\n const views: Record<string, HubWorkspaceView> = {};\n for (const workspace of hub.workspaces())\n if (mount.scope === 'global' || workspace.id === mount.workspaceId)\n views[workspace.id] = {\n id: workspace.id,\n root: workspace.root,\n ...(workspace.kind === undefined ? {} : { kind: workspace.kind }),\n ...(workspace.name === undefined ? {} : { name: workspace.name }),\n ...(workspace.sandbox === undefined ? {} : { sandbox: workspace.sandbox }),\n ...(workspace.sandboxState === undefined ? {} : { sandboxState: workspace.sandboxState }),\n ...(workspace.sandboxReason === undefined ? {} : { sandboxReason: workspace.sandboxReason }),\n available: workspace.available !== false,\n };\n return views;\n };\n const sessions = self.state('sessions', chordSchema(Type.Record(Type.String(), SessionSummarySchema)), {\n init: visibleSessions,\n });\n const workspaces = self.state('workspaces', chordSchema(Type.Record(Type.String(), HubWorkspaceSchema)), {\n init: visibleWorkspaces,\n });\n const pending = self.state('pending', chordSchema(Type.Array(HubNoticeSchema)), [] as HubNotice[]);\n const visibleCompositions = (): Record<string, number> => {\n const revisions = hub.compositionRevisions?.() ?? {};\n if (mount.scope === 'global') return { ...revisions };\n const own = `workspace:${mount.workspaceId}`;\n return Object.fromEntries(Object.entries(revisions).filter(([key]) => key === 'global' || key === own));\n };\n const compositions = self.state('compositions', chordSchema(HubCompositionsSchema), { init: visibleCompositions });\n self.on('hub', eventsOf(hub), (event, ctx) => {\n switch (event.kind) {\n case 'upsert':\n case 'removed':\n case 'dormant_changed':\n // Recomputed rather than patched, so an event before this listener started cannot leave a stale row.\n sessions.replace(ctx, visibleSessions(), { diff: true });\n return;\n case 'workspace_upsert':\n case 'workspace_removed':\n workspaces.replace(ctx, visibleWorkspaces(), { diff: true });\n return;\n case 'compositions':\n compositions.replace(ctx, visibleCompositions(), { diff: true });\n return;\n case 'frame':\n if (!reachable(connection, event.sessionId)) return;\n pending.change(ctx, (draft) => {\n draft.push({\n id: randomUUID(),\n sessionId: event.sessionId,\n frame: event.frame as Record<string, JsonValue>,\n });\n if (draft.length > MAX_PENDING_NOTICES) draft.splice(0, draft.length - MAX_PENDING_NOTICES);\n });\n return;\n case 'channel':\n return;\n }\n });\n return {\n variant: 'default',\n sessions,\n workspaces,\n pending,\n compositions,\n readHome: async (request) => {\n if (!hub.readHome) throw new Error('Home read is unavailable.');\n return hub.readHome(request, (id) => reachable(connection, id));\n },\n invoke: async (call: PoPluginCall, ctx) => {\n if (call.mount.scope === 'session' && !connection.authorizeSession(call.mount.sessionId))\n throw forbidden('This session belongs to its Desktop instance.');\n if (mount.scope !== 'global') {\n const permitted =\n call.mount.scope === 'session'\n ? permitsSession(hub, mount, call.mount.sessionId)\n : mount.scope === 'workspace' &&\n call.mount.scope === 'workspace' &&\n call.mount.workspaceId === mount.workspaceId;\n if (!permitted) throw forbidden('Plugin is outside this WebSocket scope.');\n }\n return (await hub.invokePlugin(call, 'client-to-server', {\n connectionId: connection.connectionId,\n signal: ctx.signal,\n })) as JsonValue;\n },\n ackNotice: async ({ id }, ctx) => {\n pending.change(ctx, (draft) => draft.filter((notice) => notice.id !== id));\n },\n };\n });\n\n host.serve(PoHubRevisionsContract, (_input, principal, self) => {\n const { mount } = connectionOf(principal);\n const visibleRevisions = (): Record<string, number> => {\n const revisions = hub.revisions?.() ?? {};\n if (mount.scope === 'global') return { ...revisions };\n const own = `workspace:${mount.workspaceId}:`;\n return Object.fromEntries(\n Object.entries(revisions).filter(([topic]) => topic.startsWith('global:') || topic.startsWith(own)),\n );\n };\n const revisions = self.state('revisions', chordSchema(HubRevisionsSchema), { init: visibleRevisions });\n self.on('hub', eventsOf(hub), (event, ctx) => {\n if (event.kind === 'revisions') revisions.replace(ctx, visibleRevisions(), { diff: true });\n });\n return { variant: 'default', revisions };\n });\n\n host.serve(\n PoThreadContract,\n ({ sessionId, threadId }, principal, self) => {\n const connection = connectionOf(principal);\n if (!reachable(connection, sessionId)) throw forbidden(`No session ${sessionId}`);\n connection.sessions.add(sessionId);\n const tail = self.resource('tail', {\n version: 1,\n open: () => threads.subscribe(sessionId, threadId),\n close: () => threads.unsubscribe(sessionId, threadId),\n });\n const frame = self.state('frame', chordSchema(PoThreadFrameSchema), {\n init: () => (tail.value?.at(-1) ?? null) as never,\n });\n self.on(\n 'frames',\n { subscribe: (listener) => threads.onFrame(listener) } as Subscribable<{\n sessionId: string;\n threadId: string;\n frame: Record<string, unknown>;\n }>,\n (event, ctx) => {\n // Each frame is a fresh wrapper around the child's state, so only an explicit diff sends ops, not the whole state.\n if (event.sessionId === sessionId && event.threadId === threadId)\n frame.replace(ctx, event.frame as never, { diff: true });\n },\n );\n return { variant: 'default', frame };\n },\n { linger: THREAD_LINGER_MS },\n );\n\n host.serve(PoChannelsContract, ({ sessionId }, principal, self) => {\n const connection = connectionOf(principal);\n if (!reachable(connection, sessionId)) throw forbidden(`No session ${sessionId}`);\n connection.sessions.add(sessionId);\n const visible = (frameType: string): boolean =>\n frameType !== 'computer_use_state' || connection.authorizeComputerUse(sessionId);\n const latest = self.state('latest', chordSchema(PoChannelsStateSchema), {\n init: () => {\n const payloads: Record<string, JsonValue> = {};\n for (const channelFrame of hub.channelFrames(sessionId))\n if (visible(channelFrame.type)) payloads[channelFrame.type] = channelFrame.payload as JsonValue;\n return payloads;\n },\n });\n // ponytail: a channel keeps only its latest payload; a package that needs every event must carry a sequence.\n self.on('hub', eventsOf(hub), (event, ctx) => {\n if (event.kind !== 'channel' || event.sessionId !== sessionId || !visible(event.frameType)) return;\n if (event.connectionId !== undefined && event.connectionId !== connection.connectionId) return;\n latest.change(ctx, (draft) => {\n draft[event.frameType] = event.payload as JsonValue;\n });\n });\n return {\n variant: 'default',\n latest,\n receive: async ({ type, payload }) => {\n if (!connection.authorizeSession(sessionId)) throw forbidden('This session belongs to Desktop.');\n hub.receiveChannel(\n sessionId,\n type,\n payload,\n connection.connectionId,\n connection.authorizeDesktop(),\n connection.authorizeComputerUse(sessionId),\n );\n },\n };\n });\n\n const clearSessionBindings = serveAgentSessions(host, {\n resolve(sessionId, principal): AgentSessionBinding | undefined {\n const connection = connectionOf(principal as Principal);\n const session = hub.session(sessionId);\n if (!session || !reachable(connection, session.id)) return undefined;\n connection.sessions.add(sessionId);\n const permitted = () => hub.session(session.id)?.host === session.host && connection.authorizeSession(session.id);\n // A mirror of a session another host runs forwards there; keyed by its host object, never by session id.\n const forward = session.host.agentSession;\n if (forward !== undefined)\n return { generation: generationOf(session.host), exited: session.host.runtime.exited, permitted, forward };\n return {\n generation: generationOf(session.host),\n exited: session.host.runtime.exited,\n permitted,\n options: {\n runtime: session.host.runtime,\n onPresentationFrame: (listen) =>\n session.host.onPresentationFrame((frame) => {\n if (permitted()) listen(frame);\n }),\n respondToExtensionUi: (frame) => {\n if (!permitted()) throw forbidden('This session belongs to Desktop.');\n return session.host.respondToExtensionUi(frame);\n },\n readThreadTranscript: (threadId, request, readContext) => {\n if (!permitted()) throw forbidden('This session belongs to Desktop.');\n return threads.readPage(session.id, threadId, request, readContext);\n },\n sessionId: session.id,\n sessionName: session.name,\n cwd: session.cwd,\n telemetry: options.telemetry,\n },\n };\n },\n });\n\n let closing: Promise<void> | undefined;\n return {\n accept(link, access = {}) {\n if (closing !== undefined) {\n link.close();\n return;\n }\n const connectionId = randomUUID();\n const authorizeSession = access.authorizeSession ?? ((id: string) => !hub.computerUse?.ownsSession?.(id));\n const authorizeDesktop = access.authorizeDesktop ?? (() => false);\n connections.set(connectionId, {\n mount: access.mount ?? { scope: 'global' },\n authorizeSession,\n authorizeDesktop,\n authorizeComputerUse: access.authorizeComputerUse ?? (() => authorizeDesktop()),\n sessions: new Set(),\n });\n link.onClose(() => {\n connections.delete(connectionId);\n hub.disconnectChannels(connectionId);\n });\n host.accept(reportingLargeFrames(link, options.onNotice, options.telemetry), {\n principal: { connectionId },\n kind: 'client',\n });\n },\n close() {\n closing ??= (async () => {\n stopClaims?.();\n threads.close();\n clearSessionBindings();\n await host.close();\n })();\n return closing;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAmCA,MAAM,sBAAsB;;AAE5B,MAAM,mBAAmB;AAEzB,SAAS,YAAY,SAA6C;CAChE,OAAO;EACL,IAAI,QAAQ;EACZ,GAAI,QAAQ,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;EAChF,GAAI,QAAQ,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,gBAAgB,EAAE,GAAG,QAAQ,eAAe,EAAE;EAChG,GAAI,QAAQ,sBAAsB,KAAA,IAAY,CAAC,IAAI,EAAE,mBAAmB,EAAE,GAAG,QAAQ,kBAAkB,EAAE;EACzG,MAAM,QAAQ;EACd,KAAK,QAAQ;EACb,WAAW,QAAQ;EACnB,WAAW,QAAQ,aAAa,QAAQ;EACxC,OAAO,QAAQ,SAAS;EACxB,YAAY,QAAQ,cA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