@agimon-ai/po-session 0.0.0-alpha.2 → 0.0.0-alpha.200

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 (37) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +47 -1
  3. package/dist/apiContracts.cjs +34 -2
  4. package/dist/apiContracts.cjs.map +1 -1
  5. package/dist/apiContracts.d.mts +2 -2
  6. package/dist/apiContracts.d.mts.map +1 -1
  7. package/dist/apiContracts.mjs +35 -2
  8. package/dist/apiContracts.mjs.map +1 -1
  9. package/dist/extensions/native.mjs +402 -0
  10. package/dist/extensions/native.mjs.map +1 -0
  11. package/dist/extensions/server.cjs +1679 -131
  12. package/dist/extensions/server.cjs.map +1 -1
  13. package/dist/extensions/server.d.mts +2 -2
  14. package/dist/extensions/server.d.mts.map +1 -1
  15. package/dist/extensions/server.mjs +1677 -128
  16. package/dist/extensions/server.mjs.map +1 -1
  17. package/dist/extensions/web.mjs +353 -0
  18. package/dist/extensions/web.mjs.map +1 -0
  19. package/dist/index.cjs +410 -23
  20. package/dist/index.cjs.map +1 -0
  21. package/dist/index.d.mts +689 -134
  22. package/dist/index.d.mts.map +1 -1
  23. package/dist/index.mjs +358 -2
  24. package/dist/index.mjs.map +1 -0
  25. package/dist/po-runtime-identity.json +1 -0
  26. package/dist/type-BlbiS10p.mjs +2622 -0
  27. package/dist/type-BlbiS10p.mjs.map +1 -0
  28. package/dist/type-DZtqhE4a.cjs +3083 -0
  29. package/dist/type-DZtqhE4a.cjs.map +1 -0
  30. package/llms.txt +4 -1
  31. package/package.json +96 -14
  32. package/src/prompts/codemode-how-to-network/SKILL.md +49 -0
  33. package/src/prompts/codemode-how-to-session/SKILL.md +25 -0
  34. package/dist/sessionDelivery-CkuX6jlw.cjs +0 -1042
  35. package/dist/sessionDelivery-CkuX6jlw.cjs.map +0 -1
  36. package/dist/sessionDelivery-DpLWlaum.mjs +0 -875
  37. package/dist/sessionDelivery-DpLWlaum.mjs.map +0 -1
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Vuong Ngo
3
+ Copyright (c) 2026 Agimon Pty Ltd
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Shared session coordination services for Po.
4
4
 
5
- The foundation owns the session-scoped background-work coordinator used by optional execution packages. It also provides SQLite-backed delivery with host-bound sender identities, durable inbox and outbox state, acknowledgements, keyed duplicate suppression, and prompt admission that wakes idle recipients. Interrupted admission is marked for recovery and is never replayed automatically.
5
+ The foundation owns the session-scoped background-work coordinator used by optional execution packages. It also provides SQLite-backed delivery with host-bound sender identities, durable inbox and outbox state, acknowledgements, keyed duplicate suppression, and prompt admission that wakes idle recipients. An admission that a restart or a busy session interrupted is replayed under the same request ID. One that keeps failing for two minutes, or fails for any other reason, is marked for recovery, and the sender gets a notice that names the message.
6
6
 
7
7
  Its public services also include:
8
8
 
@@ -12,6 +12,18 @@ Its public services also include:
12
12
 
13
13
  Session delivery rechecks current authority before each initial send and queued retry. Removing a member therefore blocks later publication while preserving already accepted delivery evidence.
14
14
 
15
+ ## Lanes
16
+
17
+ Messages between sessions travel in three lanes, so a busy session is not interrupted for news that can wait.
18
+
19
+ - **Queued** (`network.send`, and Team `intercom` to a session): stored, then folded with other queued messages into one digest when the recipient's run ends. A digest is written once and replayed as written after a restart.
20
+ - **Urgent** (`network.send` with `urgent: true`, `network.ask`, replies): joins the recipient's running turn. `urgent` is offered only where the host has lanes.
21
+ - **Logbook** (`network.log`, stop reports): stored without a turn. A `blocked` entry wakes the coordinator. A stop report wakes it only for a session it started or messaged in the last 24 hours that is still stopped. Wakes gather for 30 seconds.
22
+
23
+ A sender may start six messages or questions to one recipient in ten minutes, two of them interrupting. Replies and notices are not counted. An unanswered question brings one reminder after three minutes, also after a restart. A session files a stop report once it has stayed stopped for 90 seconds.
24
+
25
+ `sessions.start` sends the brief as `/goal -- <brief>`, so a session with Goal keeps the brief as its goal and the result says `goal: true`. A brief over 4,000 characters is refused before the session is created.
26
+
15
27
  ## Paired hosts
16
28
 
17
29
  A paired host is configured privately in `~/.po/session/peers.json`. The file must be owner-only (`0600`). Each peer needs an HTTPS tunnel URL, a shared secret of at least 32 characters, and explicit operation-specific session allowlists. Pairing alone grants no Session or Voice access.
@@ -34,6 +46,16 @@ A paired host is configured privately in `~/.po/session/peers.json`. The file mu
34
46
 
35
47
  Use `peer/<host-id>/<session-id>` as a qualified target. `allowedSessionIds` grants durable messages and acknowledgements. `allowedVoiceSessionIds` separately grants bounded Voice client-media relay operations. Neither grant exposes owner, `/host/*`, or `/hub/*` routes.
36
48
 
49
+ ## Host links
50
+
51
+ `po/session-peers` owns the live peer configuration and atomic private writes. Host identity is stable across tunnel URL changes. The existing version-1 format accepts optional URL generations and revocation tombstones; existing allowlist readers remain compatible.
52
+
53
+ The sealed API under `/api/plugins/session-peer` exposes `GET /links` and `POST /link/prepare`, `/link/accept`, `/link/unlink`, and `/link/hint`. Prepare, accept, and unlink require a fresh `peer.link` step-up. Quick-tunnel linking requires a native device-key session; named tunnels also accept passkeys. An invite expires after 60 seconds and is consumed once. The app relays public ECDH material, never the derived link secret.
54
+
55
+ Links begin with empty messaging and Voice allowlists. They do not chain through a third host. Peer delivery is sealed using an authenticated handshake; a URL hint cannot bypass it. Signed rebinds must name the sender itself and advance its URL generation. Unlinking stores a tombstone. Removing a paired device does not remove a host link.
56
+
57
+ Computers of the same owner on a fresh account roster link themselves. Each one offers an invitation to the others every minute through `po/host-requests`, as a `link-auto` message on `/control` carrying a host proof instead of a step-up. The computer with the smaller host identity invites; the other accepts unless it is already linked or holds a tombstone for that host, so an unlink is never undone automatically. Both computers need a public HTTPS origin. Messages stay gated on shared session groups. Removing a computer from the account does not remove a link made this way: unlink it.
58
+
37
59
  ## Development
38
60
 
39
61
  ```bash
@@ -42,3 +64,27 @@ pnpm typecheck
42
64
  pnpm test
43
65
  pnpm lint
44
66
  ```
67
+
68
+ ## Account network peer links
69
+
70
+ `createRosterPeerLink(ports)` adds direct host-key-authenticated sealed links using
71
+ an already verified C6 snapshot. Supply it as `createPeerLink({ network, ... })`
72
+ to expose it alongside the existing invite control as `control.network`.
73
+ `connect(hostId, token, exchange)` and `accept(proof, token)` sign fresh ephemeral
74
+ handshake keys with `signEnvelope` using the roster host key. The receiving host's
75
+ `authorize` port must validate the identity token's issuer, audience, current
76
+ membership, and proof-bound caller host. The `verifyRequest` port must perform
77
+ normal destination C3/C4 verification, including durable replay admission.
78
+ Neither a roster entry, an identity token alone, nor a channel grants application
79
+ permissions. Roster keys use base64url DER P-256 SPKI encoding.
80
+
81
+ Channels recheck roster epoch, membership and keys on each use. Publish C6 changes
82
+ before admitting new traffic; removal or key rotation refuses existing channels.
83
+ Fresh handshakes are required after restart. The account path does not write
84
+ legacy peer secrets or session permission lists. Existing 60-second invites and
85
+ pre-account session links retain their behavior and confer no network capability.
86
+ Direct links do not require an elected coordinator: in a two-voter network with
87
+ one down, existing direct authorized traffic can continue even though neither
88
+ roster writes nor coordinated relay service can progress. Election is CFT, not
89
+ Byzantine-safe. Actual host roster-sync and network activation are composition
90
+ responsibilities, not implicit consequences of enabling session peers.
@@ -4,11 +4,33 @@ Object.defineProperties(exports, {
4
4
  });
5
5
  let _agimon_ai_po_core_apiContracts = require("@agimon-ai/po-core/apiContracts");
6
6
  let typebox = require("typebox");
7
+ //#region src/schemas/sendToSession.ts
8
+ /** The person's own words, steered into another live session and shown there as "From you, via <from>". */
9
+ const sendToSessionMethod = (0, require("@agimon-ai/po-core/pluginProtocol").definePoPluginMethod)({
10
+ service: "sessions",
11
+ method: "sendToSession",
12
+ scope: "host",
13
+ direction: "client-to-server",
14
+ input: typebox.Type.Object({
15
+ /** The session whose composer the person typed in; it names the message, nothing more. */
16
+ from: typebox.Type.String({ minLength: 1 }),
17
+ to: typebox.Type.String({ minLength: 1 }),
18
+ text: typebox.Type.String({
19
+ minLength: 1,
20
+ maxLength: 1e5
21
+ })
22
+ }, { additionalProperties: false }),
23
+ output: typebox.Type.Object({
24
+ to: typebox.Type.String(),
25
+ name: typebox.Type.String()
26
+ })
27
+ });
28
+ //#endregion
7
29
  //#region src/schemas/apiContracts.ts
8
30
  /** The endpoint validates its own HMAC peer credential because tunnel device authentication is intentionally bypassed. */
9
31
  const http = [{
10
32
  id: "peer-inbox",
11
- scope: "global",
33
+ scope: "host",
12
34
  basePath: "session-peer",
13
35
  method: "POST",
14
36
  path: "/inbox",
@@ -27,7 +49,17 @@ const http = [{
27
49
  const apiContracts = (0, _agimon_ai_po_core_apiContracts.defineApiContract)({
28
50
  version: 1,
29
51
  http,
30
- sockets: [],
52
+ sockets: [{
53
+ id: "sessions.sendToSession",
54
+ scope: "host",
55
+ service: sendToSessionMethod.service,
56
+ member: sendToSessionMethod.method,
57
+ kind: "method",
58
+ direction: "client-to-server",
59
+ description: "Steer the person's text into another live session, shown there as from them.",
60
+ input: sendToSessionMethod.input,
61
+ output: sendToSessionMethod.output
62
+ }],
31
63
  dynamic: []
32
64
  });
33
65
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"apiContracts.cjs","names":["Type","jsonApiResponses","defineApiContract"],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses, type DoomHttpContract } from '@agimon-ai/po-core/apiContracts';\nimport { Type } from 'typebox';\n\n/** The endpoint validates its own HMAC peer credential because tunnel device authentication is intentionally bypassed. */\nconst http: DoomHttpContract[] = [\n {\n id: 'peer-inbox',\n scope: 'global',\n basePath: 'session-peer',\n method: 'POST',\n path: '/inbox',\n authentication: 'none',\n description:\n 'Accept an HMAC-authenticated durable Session delivery envelope from an explicitly configured tunnel peer.',\n body: { contentType: 'application/json', required: true, schema: Type.Unknown() },\n responses: jsonApiResponses(Type.Object({ accepted: Type.Boolean(), state: Type.String() })),\n },\n];\n\nexport const apiContracts = defineApiContract({ version: 1, http, sockets: [], dynamic: [] });\nexport default apiContracts;\n"],"mappings":";;;;;;;;AAIA,MAAM,OAA2B,CAC/B;CACE,IAAI;CACJ,OAAO;CACP,UAAU;CACV,QAAQ;CACR,MAAM;CACN,gBAAgB;CAChB,aACE;CACF,MAAM;EAAE,aAAa;EAAoB,UAAU;EAAM,QAAQA,QAAAA,KAAK,QAAQ;CAAE;CAChF,YAAA,GAAWC,gCAAAA,iBAAAA,CAAiBD,QAAAA,KAAK,OAAO;EAAE,UAAUA,QAAAA,KAAK,QAAQ;EAAG,OAAOA,QAAAA,KAAK,OAAO;CAAE,CAAC,CAAC;AAC7F,CACF;AAEA,MAAa,gBAAA,GAAeE,gCAAAA,kBAAAA,CAAkB;CAAE,SAAS;CAAG;CAAM,SAAS,CAAC;CAAG,SAAS,CAAC;AAAE,CAAC"}
1
+ {"version":3,"file":"apiContracts.cjs","names":["definePoPluginMethod","Type","Type","jsonApiResponses","defineApiContract"],"sources":["../src/schemas/sendToSession.ts","../src/schemas/apiContracts.ts"],"sourcesContent":["import { definePoPluginMethod } from '@agimon-ai/po-core/pluginProtocol';\nimport { Type } from 'typebox';\n\n/** The person's own words, steered into another live session and shown there as \"From you, via <from>\". */\nexport const sendToSessionMethod = definePoPluginMethod({\n service: 'sessions',\n method: 'sendToSession',\n scope: 'host',\n direction: 'client-to-server',\n input: Type.Object(\n {\n /** The session whose composer the person typed in; it names the message, nothing more. */\n from: Type.String({ minLength: 1 }),\n to: Type.String({ minLength: 1 }),\n text: Type.String({ minLength: 1, maxLength: 100_000 }),\n },\n { additionalProperties: false },\n ),\n output: Type.Object({ to: Type.String(), name: Type.String() }),\n});\n","import { defineApiContract, jsonApiResponses, type PoHttpContract } from '@agimon-ai/po-core/apiContracts';\nimport { Type } from 'typebox';\n\nimport { sendToSessionMethod } from './sendToSession';\n\n/** The endpoint validates its own HMAC peer credential because tunnel device authentication is intentionally bypassed. */\nconst http: PoHttpContract[] = [\n {\n id: 'peer-inbox',\n scope: 'host',\n basePath: 'session-peer',\n method: 'POST',\n path: '/inbox',\n authentication: 'none',\n description:\n 'Accept an HMAC-authenticated durable Session delivery envelope from an explicitly configured tunnel peer.',\n body: { contentType: 'application/json', required: true, schema: Type.Unknown() },\n responses: jsonApiResponses(Type.Object({ accepted: Type.Boolean(), state: Type.String() })),\n },\n];\n\nexport const apiContracts = defineApiContract({\n version: 1,\n http,\n sockets: [\n {\n id: 'sessions.sendToSession',\n scope: 'host',\n service: sendToSessionMethod.service,\n member: sendToSessionMethod.method,\n kind: 'method',\n direction: 'client-to-server',\n description: \"Steer the person's text into another live session, shown there as from them.\",\n input: sendToSessionMethod.input,\n output: sendToSessionMethod.output,\n },\n ],\n dynamic: [],\n});\nexport default apiContracts;\n"],"mappings":";;;;;;;;AAIA,MAAa,uBAAA,G,2CAAsBA,CAAAA,CAAAA,qBAAAA,CAAqB;CACtD,SAAS;CACT,QAAQ;CACR,OAAO;CACP,WAAW;CACX,OAAOC,QAAAA,KAAK,OACV;;EAEE,MAAMA,QAAAA,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;EAClC,IAAIA,QAAAA,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;EAChC,MAAMA,QAAAA,KAAK,OAAO;GAAE,WAAW;GAAG,WAAW;EAAQ,CAAC;CACxD,GACA,EAAE,sBAAsB,MAAM,CAChC;CACA,QAAQA,QAAAA,KAAK,OAAO;EAAE,IAAIA,QAAAA,KAAK,OAAO;EAAG,MAAMA,QAAAA,KAAK,OAAO;CAAE,CAAC;AAChE,CAAC;;;;ACbD,MAAM,OAAyB,CAC7B;CACE,IAAI;CACJ,OAAO;CACP,UAAU;CACV,QAAQ;CACR,MAAM;CACN,gBAAgB;CAChB,aACE;CACF,MAAM;EAAE,aAAa;EAAoB,UAAU;EAAM,QAAQC,QAAAA,KAAK,QAAQ;CAAE;CAChF,YAAA,GAAWC,gCAAAA,iBAAAA,CAAiBD,QAAAA,KAAK,OAAO;EAAE,UAAUA,QAAAA,KAAK,QAAQ;EAAG,OAAOA,QAAAA,KAAK,OAAO;CAAE,CAAC,CAAC;AAC7F,CACF;AAEA,MAAa,gBAAA,GAAeE,gCAAAA,kBAAAA,CAAkB;CAC5C,SAAS;CACT;CACA,SAAS,CACP;EACE,IAAI;EACJ,OAAO;EACP,SAAS,oBAAoB;EAC7B,QAAQ,oBAAoB;EAC5B,MAAM;EACN,WAAW;EACX,aAAa;EACb,OAAO,oBAAoB;EAC3B,QAAQ,oBAAoB;CAC9B,CACF;CACA,SAAS,CAAC;AACZ,CAAC"}
@@ -5,7 +5,7 @@ export declare const apiContracts: {
5
5
  schemas?: Record<string, boolean | object> | undefined;
6
6
  http: {
7
7
  id: string;
8
- scope: "global" | "session" | "workspace";
8
+ scope: "host" | "session" | "workspace";
9
9
  basePath?: string | undefined;
10
10
  path: string;
11
11
  method: "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT";
@@ -33,7 +33,7 @@ export declare const apiContracts: {
33
33
  }[];
34
34
  sockets: {
35
35
  id: string;
36
- scope: "global" | "session" | "workspace";
36
+ scope: "host" | "session" | "workspace";
37
37
  description: string;
38
38
  availability?: string | undefined;
39
39
  service: string;
@@ -1 +1 @@
1
- {"version":3,"file":"apiContracts.d.mts","names":[],"sources":["../src/schemas/apiContracts.ts"],"mappings":";qBAmBa"}
1
+ {"version":3,"file":"apiContracts.d.mts","names":[],"sources":["../src/schemas/apiContracts.ts"],"mappings":";qBAqBa"}
@@ -1,10 +1,33 @@
1
1
  import { defineApiContract, jsonApiResponses } from "@agimon-ai/po-core/apiContracts";
2
2
  import { Type } from "typebox";
3
+ import { definePoPluginMethod } from "@agimon-ai/po-core/pluginProtocol";
4
+ //#region src/schemas/sendToSession.ts
5
+ /** The person's own words, steered into another live session and shown there as "From you, via <from>". */
6
+ const sendToSessionMethod = definePoPluginMethod({
7
+ service: "sessions",
8
+ method: "sendToSession",
9
+ scope: "host",
10
+ direction: "client-to-server",
11
+ input: Type.Object({
12
+ /** The session whose composer the person typed in; it names the message, nothing more. */
13
+ from: Type.String({ minLength: 1 }),
14
+ to: Type.String({ minLength: 1 }),
15
+ text: Type.String({
16
+ minLength: 1,
17
+ maxLength: 1e5
18
+ })
19
+ }, { additionalProperties: false }),
20
+ output: Type.Object({
21
+ to: Type.String(),
22
+ name: Type.String()
23
+ })
24
+ });
25
+ //#endregion
3
26
  //#region src/schemas/apiContracts.ts
4
27
  /** The endpoint validates its own HMAC peer credential because tunnel device authentication is intentionally bypassed. */
5
28
  const http = [{
6
29
  id: "peer-inbox",
7
- scope: "global",
30
+ scope: "host",
8
31
  basePath: "session-peer",
9
32
  method: "POST",
10
33
  path: "/inbox",
@@ -23,7 +46,17 @@ const http = [{
23
46
  const apiContracts = defineApiContract({
24
47
  version: 1,
25
48
  http,
26
- sockets: [],
49
+ sockets: [{
50
+ id: "sessions.sendToSession",
51
+ scope: "host",
52
+ service: sendToSessionMethod.service,
53
+ member: sendToSessionMethod.method,
54
+ kind: "method",
55
+ direction: "client-to-server",
56
+ description: "Steer the person's text into another live session, shown there as from them.",
57
+ input: sendToSessionMethod.input,
58
+ output: sendToSessionMethod.output
59
+ }],
27
60
  dynamic: []
28
61
  });
29
62
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"apiContracts.mjs","names":[],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses, type DoomHttpContract } from '@agimon-ai/po-core/apiContracts';\nimport { Type } from 'typebox';\n\n/** The endpoint validates its own HMAC peer credential because tunnel device authentication is intentionally bypassed. */\nconst http: DoomHttpContract[] = [\n {\n id: 'peer-inbox',\n scope: 'global',\n basePath: 'session-peer',\n method: 'POST',\n path: '/inbox',\n authentication: 'none',\n description:\n 'Accept an HMAC-authenticated durable Session delivery envelope from an explicitly configured tunnel peer.',\n body: { contentType: 'application/json', required: true, schema: Type.Unknown() },\n responses: jsonApiResponses(Type.Object({ accepted: Type.Boolean(), state: Type.String() })),\n },\n];\n\nexport const apiContracts = defineApiContract({ version: 1, http, sockets: [], dynamic: [] });\nexport default apiContracts;\n"],"mappings":";;;;AAIA,MAAM,OAA2B,CAC/B;CACE,IAAI;CACJ,OAAO;CACP,UAAU;CACV,QAAQ;CACR,MAAM;CACN,gBAAgB;CAChB,aACE;CACF,MAAM;EAAE,aAAa;EAAoB,UAAU;EAAM,QAAQ,KAAK,QAAQ;CAAE;CAChF,WAAW,iBAAiB,KAAK,OAAO;EAAE,UAAU,KAAK,QAAQ;EAAG,OAAO,KAAK,OAAO;CAAE,CAAC,CAAC;AAC7F,CACF;AAEA,MAAa,eAAe,kBAAkB;CAAE,SAAS;CAAG;CAAM,SAAS,CAAC;CAAG,SAAS,CAAC;AAAE,CAAC"}
1
+ {"version":3,"file":"apiContracts.mjs","names":[],"sources":["../src/schemas/sendToSession.ts","../src/schemas/apiContracts.ts"],"sourcesContent":["import { definePoPluginMethod } from '@agimon-ai/po-core/pluginProtocol';\nimport { Type } from 'typebox';\n\n/** The person's own words, steered into another live session and shown there as \"From you, via <from>\". */\nexport const sendToSessionMethod = definePoPluginMethod({\n service: 'sessions',\n method: 'sendToSession',\n scope: 'host',\n direction: 'client-to-server',\n input: Type.Object(\n {\n /** The session whose composer the person typed in; it names the message, nothing more. */\n from: Type.String({ minLength: 1 }),\n to: Type.String({ minLength: 1 }),\n text: Type.String({ minLength: 1, maxLength: 100_000 }),\n },\n { additionalProperties: false },\n ),\n output: Type.Object({ to: Type.String(), name: Type.String() }),\n});\n","import { defineApiContract, jsonApiResponses, type PoHttpContract } from '@agimon-ai/po-core/apiContracts';\nimport { Type } from 'typebox';\n\nimport { sendToSessionMethod } from './sendToSession';\n\n/** The endpoint validates its own HMAC peer credential because tunnel device authentication is intentionally bypassed. */\nconst http: PoHttpContract[] = [\n {\n id: 'peer-inbox',\n scope: 'host',\n basePath: 'session-peer',\n method: 'POST',\n path: '/inbox',\n authentication: 'none',\n description:\n 'Accept an HMAC-authenticated durable Session delivery envelope from an explicitly configured tunnel peer.',\n body: { contentType: 'application/json', required: true, schema: Type.Unknown() },\n responses: jsonApiResponses(Type.Object({ accepted: Type.Boolean(), state: Type.String() })),\n },\n];\n\nexport const apiContracts = defineApiContract({\n version: 1,\n http,\n sockets: [\n {\n id: 'sessions.sendToSession',\n scope: 'host',\n service: sendToSessionMethod.service,\n member: sendToSessionMethod.method,\n kind: 'method',\n direction: 'client-to-server',\n description: \"Steer the person's text into another live session, shown there as from them.\",\n input: sendToSessionMethod.input,\n output: sendToSessionMethod.output,\n },\n ],\n dynamic: [],\n});\nexport default apiContracts;\n"],"mappings":";;;;;AAIA,MAAa,sBAAsB,qBAAqB;CACtD,SAAS;CACT,QAAQ;CACR,OAAO;CACP,WAAW;CACX,OAAO,KAAK,OACV;;EAEE,MAAM,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;EAClC,IAAI,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;EAChC,MAAM,KAAK,OAAO;GAAE,WAAW;GAAG,WAAW;EAAQ,CAAC;CACxD,GACA,EAAE,sBAAsB,MAAM,CAChC;CACA,QAAQ,KAAK,OAAO;EAAE,IAAI,KAAK,OAAO;EAAG,MAAM,KAAK,OAAO;CAAE,CAAC;AAChE,CAAC;;;;ACbD,MAAM,OAAyB,CAC7B;CACE,IAAI;CACJ,OAAO;CACP,UAAU;CACV,QAAQ;CACR,MAAM;CACN,gBAAgB;CAChB,aACE;CACF,MAAM;EAAE,aAAa;EAAoB,UAAU;EAAM,QAAQ,KAAK,QAAQ;CAAE;CAChF,WAAW,iBAAiB,KAAK,OAAO;EAAE,UAAU,KAAK,QAAQ;EAAG,OAAO,KAAK,OAAO;CAAE,CAAC,CAAC;AAC7F,CACF;AAEA,MAAa,eAAe,kBAAkB;CAC5C,SAAS;CACT;CACA,SAAS,CACP;EACE,IAAI;EACJ,OAAO;EACP,SAAS,oBAAoB;EAC7B,QAAQ,oBAAoB;EAC5B,MAAM;EACN,WAAW;EACX,aAAa;EACb,OAAO,oBAAoB;EAC3B,QAAQ,oBAAoB;CAC9B,CACF;CACA,SAAS,CAAC;AACZ,CAAC"}
@@ -0,0 +1,402 @@
1
+ import { defineFill, defineHostStore, defineNativePlugin, defineToolRenderer, defineWebLifecycle, useT } from "@agimon-ai/po-core/native";
2
+ import { View } from "react-native-unistyles/components/native/View";
3
+ import { Text } from "react-native-unistyles/components/native/Text";
4
+ import { Button, Dot, EmptyState, Input, ListRow, MessageIcon, MessageItem, MessageItemBody, MessageItemHeader, MessageItemStatus, SearchIcon, SheetBody, SheetDescription, SheetFooter, fontOf, resultTextLines, toolTone } from "@agimon-ai/po-native-components";
5
+ import { useEffect, useMemo, useRef, useState } from "react";
6
+ import { StyleSheet } from "react-native-unistyles";
7
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+ //#region src/extensions/workspaces/sessions/(frontend)/_lib/sendToSessionDelivery.ts
9
+ /**
10
+ * Delivers one send through the started runtime that owns the sending session.
11
+ *
12
+ * DESIGN PATTERNS:
13
+ * - Host-neutral and stateless: the web and native request files each keep
14
+ * their own runtime list (from their own po-core entry) and pass it in.
15
+ * The phone starts one runtime per computer; a send goes through the one
16
+ * that owns the sending session, with that computer's local ids.
17
+ *
18
+ * AVOID:
19
+ * - Value imports from a po-core entry here. Native plugins may not import
20
+ * `po-core/web`, and web plugins may not import `po-core/native`.
21
+ */
22
+ /** The runtime that owns `from`, with both ids as its computer knows them; undefined when none does. */
23
+ function route(runtimes, input) {
24
+ return runtimes.flatMap((runtime) => {
25
+ try {
26
+ const from = runtime.localSessionId?.(input.from) ?? input.from;
27
+ const to = runtime.localSessionId?.(input.to) ?? input.to;
28
+ return from !== input.from || (runtime.qualifySessionId?.(input.from) ?? input.from) === input.from ? [{
29
+ runtime,
30
+ from,
31
+ to
32
+ }] : [];
33
+ } catch {
34
+ return [];
35
+ }
36
+ }).at(-1);
37
+ }
38
+ /** Steers `text` into session `to`. Resolves to the reason shown when it was refused, or undefined once delivered. */
39
+ async function deliverToSession(runtimes, input) {
40
+ const owner = route(runtimes, input);
41
+ if (!owner) return "Po is not connected. Your text is kept; try again.";
42
+ try {
43
+ await owner.runtime.invokeServerMethod({
44
+ mount: { scope: "host" },
45
+ service: "sessions",
46
+ method: "sendToSession",
47
+ input: {
48
+ from: owner.from,
49
+ to: owner.to,
50
+ text: input.text
51
+ }
52
+ });
53
+ return;
54
+ } catch (error) {
55
+ return error instanceof Error && error.message !== "" ? error.message : "The message was not delivered.";
56
+ }
57
+ }
58
+ //#endregion
59
+ //#region src/extensions/workspaces/sessions/(frontend)/_lib/sendToSessionRequest.native.ts
60
+ /**
61
+ * The phone's started runtimes, one per computer, for the send-to-session panel.
62
+ *
63
+ * DESIGN PATTERNS:
64
+ * - The native twin of sendToSessionRequest.ts: a native plugin may import
65
+ * po-core/native only. The phone has no menu-to-overlay handoff, so only the
66
+ * runtime list and the send live here.
67
+ */
68
+ const runtimes = defineHostStore([]);
69
+ function startSendToSessionRuntime(runtime) {
70
+ runtimes.update((current) => [...current, runtime]);
71
+ return () => runtimes.update((current) => current.filter((entry) => entry !== runtime));
72
+ }
73
+ /** Steers `text` into session `to`. Resolves to the reason shown when it was refused, or undefined once delivered. */
74
+ function sendToSession(input) {
75
+ return deliverToSession(runtimes.store.state, input);
76
+ }
77
+ //#endregion
78
+ //#region src/extensions/workspaces/sessions/(frontend)/fill/_components/SendToSessionPanel.native.tsx
79
+ /**
80
+ * The phone's "Send to session…" page of the composer's Insert sheet: pick a
81
+ * live session, then Send steers what the person typed into it.
82
+ *
83
+ * DESIGN PATTERNS:
84
+ * - The draft is taken only at Send, so opening and leaving the page never
85
+ * touches it. A refused send keeps the taken text for a retry and hands it
86
+ * back to the composer when the page goes away.
87
+ * - The sheet closes when the page appends to the draft; an empty append
88
+ * closes it and leaves the draft alone.
89
+ *
90
+ * AVOID:
91
+ * - Sending on a row tap. On a phone a mis-tap would send; Send is its own button.
92
+ */
93
+ const TONE = {
94
+ running: "green",
95
+ waiting: "magenta",
96
+ idle: "neutral"
97
+ };
98
+ /** The Insert sheet page: lists the computer's live sessions and steers the composer's text into one. */
99
+ function SendToSessionPanel({ sessionId, listSessions, takeComposerDraft, appendComposerDraft }) {
100
+ const t = useT();
101
+ const [sessions] = useState(() => listSessions?.() ?? []);
102
+ const [to, setTo] = useState();
103
+ const [busy, setBusy] = useState(false);
104
+ const [error, setError] = useState("");
105
+ const held = useRef({
106
+ inFlight: false,
107
+ live: true
108
+ });
109
+ const giveBack = useRef(appendComposerDraft);
110
+ useEffect(() => {
111
+ giveBack.current = appendComposerDraft;
112
+ }, [appendComposerDraft]);
113
+ useEffect(() => {
114
+ const state = held.current;
115
+ state.live = true;
116
+ return () => {
117
+ state.live = false;
118
+ if (state.text !== void 0 && !state.inFlight) giveBack.current(state.text);
119
+ };
120
+ }, []);
121
+ const send = async () => {
122
+ if (to === void 0 || sessionId === null) return;
123
+ const state = held.current;
124
+ const text = state.text ?? takeComposerDraft?.() ?? "";
125
+ if (text.trim() === "") {
126
+ setError(t("session.ui.writeSomethingToSend", "Write something to send."));
127
+ return;
128
+ }
129
+ state.text = text;
130
+ state.inFlight = true;
131
+ setBusy(true);
132
+ setError("");
133
+ const refusal = await sendToSession({
134
+ from: sessionId,
135
+ to,
136
+ text: text.trim()
137
+ });
138
+ state.inFlight = false;
139
+ if (refusal === void 0) state.text = void 0;
140
+ if (!state.live) {
141
+ if (state.text !== void 0) giveBack.current(state.text);
142
+ return;
143
+ }
144
+ if (refusal === void 0) {
145
+ giveBack.current("");
146
+ return;
147
+ }
148
+ setBusy(false);
149
+ setError(refusal);
150
+ };
151
+ return /* @__PURE__ */ jsx(SendToSessionView, {
152
+ sessions,
153
+ to,
154
+ busy,
155
+ error,
156
+ onPick: setTo,
157
+ onSend: () => void send()
158
+ });
159
+ }
160
+ function SendToSessionView({ sessions, to, busy, error, onPick, onSend }) {
161
+ const t = useT();
162
+ const [filter, setFilter] = useState("");
163
+ const shown = useMemo(() => {
164
+ const query = filter.trim().toLowerCase();
165
+ return query === "" ? sessions : sessions.filter((session) => `${session.name} ${session.detail}`.toLowerCase().includes(query));
166
+ }, [filter, sessions]);
167
+ const target = sessions.find((session) => session.id === to);
168
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(SheetBody, { children: [
169
+ /* @__PURE__ */ jsx(SheetDescription, { children: t("session.ui.sendDraftDescription", "Send what you typed to another session. It arrives there from you.") }),
170
+ error === "" ? null : /* @__PURE__ */ jsx(Text, {
171
+ accessibilityRole: "alert",
172
+ style: styles$1.alert,
173
+ children: error
174
+ }),
175
+ sessions.length === 0 ? /* @__PURE__ */ jsx(EmptyState, {
176
+ size: "compact",
177
+ icon: /* @__PURE__ */ jsx(MessageIcon, { size: 16 }),
178
+ title: t("session.ui.noOtherSessionRunning", "No other session is running"),
179
+ description: t("session.ui.openThenSend", "Open one, then send.")
180
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Input, {
181
+ accessibilityLabel: t("session.ui.filterSessions", "Filter sessions"),
182
+ placeholder: t("session.ui.filterSessions", "Filter sessions"),
183
+ value: filter,
184
+ onChangeText: setFilter
185
+ }), shown.length === 0 ? /* @__PURE__ */ jsx(EmptyState, {
186
+ size: "compact",
187
+ icon: /* @__PURE__ */ jsx(SearchIcon, { size: 16 }),
188
+ title: t("session.ui.noFilterMatches", "Nothing matches that filter"),
189
+ secondaryAction: {
190
+ label: t("session.ui.clearFilter", "Clear filter"),
191
+ onAction: () => setFilter("")
192
+ }
193
+ }) : /* @__PURE__ */ jsx(View, {
194
+ style: styles$1.rows,
195
+ children: shown.map((session, index) => /* @__PURE__ */ jsxs(View, { children: [index > 0 ? /* @__PURE__ */ jsx(View, { style: styles$1.separator }) : null, /* @__PURE__ */ jsx(ListRow, {
196
+ accessibilityLabel: `${session.name}, ${session.detail}`,
197
+ selected: session.id === to,
198
+ disabled: busy,
199
+ onPress: () => onPick(session.id),
200
+ disclosure: false,
201
+ style: styles$1.row,
202
+ leading: /* @__PURE__ */ jsx(Dot, {
203
+ tone: TONE[session.state],
204
+ size: "md"
205
+ }),
206
+ title: session.name,
207
+ description: /* @__PURE__ */ jsx(Text, {
208
+ numberOfLines: 1,
209
+ style: styles$1.detail,
210
+ children: session.detail
211
+ })
212
+ })] }, session.id))
213
+ })] })
214
+ ] }), /* @__PURE__ */ jsx(SheetFooter, { children: /* @__PURE__ */ jsx(Button, {
215
+ variant: "primary",
216
+ disabled: busy || target === void 0,
217
+ onPress: onSend,
218
+ children: busy ? t("session.ui.sending", "Sending…") : target === void 0 ? t("session.ui.pickSession", "Pick a session") : t("session.ui.sendToName", "Send to {name}", { name: target.name })
219
+ }) })] });
220
+ }
221
+ const styles$1 = StyleSheet.create((theme) => {
222
+ const small = {
223
+ fontFamily: fontOf(theme.fontFamily.sans),
224
+ fontSize: theme.fontSize.sm,
225
+ lineHeight: theme.lineHeight.sm
226
+ };
227
+ return {
228
+ rows: {
229
+ borderTopWidth: StyleSheet.hairlineWidth,
230
+ borderBottomWidth: StyleSheet.hairlineWidth,
231
+ borderColor: theme.colors["border-soft"],
232
+ uni__dependencies: [0]
233
+ },
234
+ row: {
235
+ paddingHorizontal: theme.spacing(1),
236
+ uni__dependencies: [0]
237
+ },
238
+ separator: {
239
+ height: StyleSheet.hairlineWidth,
240
+ backgroundColor: theme.colors["border-soft"],
241
+ uni__dependencies: [0]
242
+ },
243
+ detail: {
244
+ ...small,
245
+ color: theme.colors.dim,
246
+ uni__dependencies: [0]
247
+ },
248
+ alert: {
249
+ ...small,
250
+ color: theme.colors.red,
251
+ uni__dependencies: [0]
252
+ }
253
+ };
254
+ });
255
+ //#endregion
256
+ //#region src/extensions/workspaces/sessions/(frontend)/fill/SendToSession.composer-menu.native.tsx
257
+ /** The phone's Insert sheet draws `data` as the row and `component` as the page it opens. */
258
+ var SendToSession_composer_menu_native_default = defineFill({
259
+ data: {
260
+ title: "Send to session…",
261
+ hint: "Steer another session with what you typed",
262
+ translateCopy: (t) => ({
263
+ title: t("session.insert.title", "Send to session…"),
264
+ hint: t("session.insert.hint", "Steer another session with what you typed")
265
+ })
266
+ },
267
+ component: SendToSessionPanel
268
+ });
269
+ //#endregion
270
+ //#region src/extensions/workspaces/sessions/(frontend)/lifecycle/start.native.ts
271
+ var start_native_default = defineWebLifecycle(startSendToSessionRuntime);
272
+ //#endregion
273
+ //#region src/extensions/workspaces/sessions/(frontend)/tool/_lib/networkActivity.ts
274
+ const ACTIVITY_CHARS = 72;
275
+ function asString(value) {
276
+ return typeof value === "string" ? value : "";
277
+ }
278
+ function clip(text) {
279
+ const flat = text.replace(/\s+/g, " ").trim();
280
+ return flat.length > ACTIVITY_CHARS ? `${flat.slice(0, 71)}…` : flat;
281
+ }
282
+ /** Who a message is for, or what it answers. */
283
+ function networkSummary(toolName, args) {
284
+ const verb = toolName.split(".").at(-1) ?? toolName;
285
+ return toolName === "network.reply" ? "reply" : `${verb} ${asString(args.to)}`.trim();
286
+ }
287
+ /** One line per outgoing session message: who it went to and what it said. */
288
+ function networkActivity({ toolName, args, isError }) {
289
+ const text = clip(asString(args.text));
290
+ if (isError || !text) return [];
291
+ if (toolName === "network.reply") return [`Replied "${text}"`];
292
+ return [`→ ${asString(args.to) || "session"}${toolName === "network.ask" ? " asks" : ""} "${text}"`];
293
+ }
294
+ //#endregion
295
+ //#region src/extensions/workspaces/sessions/(frontend)/tool/_components/NetworkToolMessage.native.tsx
296
+ /** A network.send, network.ask or network.reply recorded inside an exec. Collapsed to its summary; the body is the result text. */
297
+ function NetworkToolMessage({ args, result, output, running, isError, toolName }) {
298
+ const t = useT();
299
+ const lines = resultTextLines(result, output);
300
+ return /* @__PURE__ */ jsx(MessageItem, {
301
+ tone: toolTone({
302
+ running,
303
+ isError
304
+ }),
305
+ expandable: lines.length > 0,
306
+ children: ({ expanded }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MessageItemHeader, {
307
+ title: "network",
308
+ children: /* @__PURE__ */ jsx(View, {
309
+ testID: "tool-call-network",
310
+ style: styles.summary,
311
+ children: /* @__PURE__ */ jsx(Text, {
312
+ numberOfLines: 1,
313
+ style: styles.primary,
314
+ children: networkSummary(toolName, args)
315
+ })
316
+ })
317
+ }), expanded ? /* @__PURE__ */ jsxs(MessageItemBody, {
318
+ testID: "tool-result-network",
319
+ style: styles.body,
320
+ children: [running ? /* @__PURE__ */ jsx(MessageItemStatus, {
321
+ tone: "running",
322
+ children: t("session.ui.working", "working")
323
+ }) : null, lines.map((line, index) => /* @__PURE__ */ jsx(Text, {
324
+ selectable: true,
325
+ style: isError ? styles.error : styles.dim,
326
+ children: line
327
+ }, `${String(index)}-${line}`))]
328
+ }) : null] })
329
+ });
330
+ }
331
+ const styles = StyleSheet.create((theme) => ({
332
+ summary: {
333
+ flex: 1,
334
+ flexDirection: "row",
335
+ alignItems: "center",
336
+ minWidth: 0
337
+ },
338
+ primary: {
339
+ flexShrink: 1,
340
+ minWidth: 0,
341
+ color: theme.colors.text,
342
+ fontFamily: fontOf(theme.fontFamily.sans),
343
+ fontSize: theme.fontSize.base,
344
+ uni__dependencies: [0]
345
+ },
346
+ body: {
347
+ gap: theme.spacing(1),
348
+ uni__dependencies: [0]
349
+ },
350
+ dim: {
351
+ color: theme.colors.dim,
352
+ fontFamily: fontOf(theme.fontFamily.sans),
353
+ fontSize: theme.fontSize.base,
354
+ uni__dependencies: [0]
355
+ },
356
+ error: {
357
+ color: theme.colors.red,
358
+ fontFamily: fontOf(theme.fontFamily.sans),
359
+ fontSize: theme.fontSize.base,
360
+ uni__dependencies: [0]
361
+ }
362
+ }));
363
+ //#endregion
364
+ //#region src/extensions/workspaces/sessions/(frontend)/tool/network.native.tsx
365
+ /** The network namespace's recorded calls. Named by hand: the dotted tool names are not a filename. */
366
+ var network_native_default = defineToolRenderer({
367
+ tools: [
368
+ "network.send",
369
+ "network.ask",
370
+ "network.reply"
371
+ ],
372
+ message: NetworkToolMessage,
373
+ activity: networkActivity
374
+ });
375
+ //#endregion
376
+ //#region generated/native.ts
377
+ const via = (identity, value) => value === void 0 ? void 0 : {
378
+ ...identity,
379
+ ...value
380
+ };
381
+ const nativePlugin = defineNativePlugin({
382
+ id: "sessions",
383
+ packageName: "@agimon-ai/po-session",
384
+ session: {
385
+ get fills() {
386
+ return [via({
387
+ slot: "composer-menu",
388
+ id: "send-to-session"
389
+ }, SendToSession_composer_menu_native_default)];
390
+ },
391
+ get start() {
392
+ return start_native_default;
393
+ },
394
+ get toolRenderers() {
395
+ return [via({ tools: ["network"] }, network_native_default)];
396
+ }
397
+ }
398
+ });
399
+ //#endregion
400
+ export { nativePlugin };
401
+
402
+ //# sourceMappingURL=native.mjs.map