@qilin-agent/client-ui-session 3.1.7 → 3.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -842,6 +842,22 @@ window.__ModuleLoader__.load({
842
842
  return this.sourceFor(owner);
843
843
  }
844
844
  /**
845
+ * Keep `callback`'s effects installed while the current Peer may call
846
+ * `action` on one Session resource, with the semantics of
847
+ * `ctx.remoteAccess.whenAccess`: `useSessionAccess` answers the same
848
+ * question during render.
849
+ * @param sessionId - the Session resource the guarded effects depend on.
850
+ * @param action - endpoint action the guarded effects depend on.
851
+ * @param callback - creates one disposer or an iterable of disposers.
852
+ * @returns idempotent disposer owned by the caller's Cordis fiber.
853
+ */
854
+ whenAccess(sessionId, action, callback) {
855
+ const access = this.ctx.get("remoteAccess");
856
+ /* v8 ignore next -- this plugin injects remoteAccess, so the service is active while uiSession is reachable. */
857
+ if (access === void 0) throw new Error("ui-session: whenAccess requires the remoteAccess service");
858
+ return access.whenResourceAccess("session", sessionId, action, callback);
859
+ }
860
+ /**
845
861
  * Register one Session-scoped standard-source contribution.
846
862
  * @param descriptor - static member roster and per-binding resolver.
847
863
  * @returns disposer owned by the caller's Cordis fiber.
@@ -1101,14 +1117,22 @@ window.__ModuleLoader__.load({
1101
1117
  */
1102
1118
  function apply(ctx) {
1103
1119
  const service = new UiSession(ctx, ctx.sessions);
1120
+ const access = ctx.get("remoteAccess");
1104
1121
  ctx.slots.provideRoot({
1105
1122
  hooks: {
1106
1123
  sessions: ctx.sessions.list,
1107
1124
  sessionStatus: service.sessionStatus
1108
1125
  },
1109
- keyedHooks: { sessionRetainInfo: (key) => ctx.sessions.retainInfo(key) }
1126
+ keyedHooks: {
1127
+ sessionRetainInfo: (key) => ctx.sessions.retainInfo(key),
1128
+ ...access === void 0 ? {} : { sessionAccess: (sessionId, action) => typeof action === "string" ? access.source("session", sessionId, action) : void 0 }
1129
+ }
1110
1130
  });
1111
1131
  ctx.slots.installScope("session", service.adapter);
1132
+ if (access !== void 0) service.provide({
1133
+ keyedHooks: ["access"],
1134
+ resolve: (binding) => ({ keyedHooks: { access: (action) => access.source("session", binding.sessionId, action) } })
1135
+ });
1112
1136
  }
1113
1137
  function sameSessionStatus(left, right) {
1114
1138
  if (left.size !== right.size) return false;
@@ -3,6 +3,7 @@ import { Service, type Context } from '@qilin-agent/kylin';
3
3
  import type { ISessions, SessionBinding, SessionListState, SessionReference, SessionRetainInfo, SessionSnapshot, UseProjection } from '@qilin-agent/api-session-controller/client';
4
4
  import type { SessionId } from '@qilin-agent/session/types';
5
5
  import type { HostObservable, KeyedStandardSource, MaybeSnapshotSelectorHook, SlotScopeAdapter, SnapshotSelectorHook, StandardSourceBinding } from '@qilin-agent/client-ui-slots';
6
+ import type { AccessEffect, RemoteEndpoint } from '@qilin-agent/api-remote-access/client/types';
6
7
  /** Selector hook over the Session Controller list and current selection. */
7
8
  export type UseSessions = SnapshotSelectorHook<SessionListState>;
8
9
  /** Selector hook over one Session's lifecycle and control state. */
@@ -73,6 +74,8 @@ declare module '@qilin-agent/client-ui-slots' {
73
74
  useSessions: UseSessions;
74
75
  useSessionStatus: UseSessionStatus;
75
76
  useSessionRetainInfo: UseSessionRetainInfo;
77
+ /** Whether the current Peer may call `action` on one Session resource. */
78
+ useSessionAccess: (sessionId: SessionId, action: RemoteEndpoint) => boolean;
76
79
  }
77
80
  interface SessionStandardProps {
78
81
  /** Current Session lifecycle and control state. */
@@ -81,6 +84,8 @@ declare module '@qilin-agent/client-ui-slots' {
81
84
  sessionId: SessionId;
82
85
  /** Host-computed projection values addressed by projection key. */
83
86
  useProjection: UseProjection;
87
+ /** Whether the current Peer may call `action` on this Session resource. */
88
+ useAccess: (action: RemoteEndpoint) => boolean;
84
89
  }
85
90
  interface SessionMaybeStandardProps {
86
91
  /** Current Session state, absent while no Session is selected. */
@@ -89,6 +94,8 @@ declare module '@qilin-agent/client-ui-slots' {
89
94
  sessionId: SessionId | undefined;
90
95
  /** Host-computed projection values; every key is absent without a Session. */
91
96
  useProjection: UseProjection;
97
+ /** The bound Session's access answer; `undefined` without a Session, which callers treat as not allowed. */
98
+ useAccess: (action: RemoteEndpoint) => boolean | undefined;
92
99
  }
93
100
  }
94
101
  declare module '@qilin-agent/api-session-controller/client' {
@@ -154,6 +161,17 @@ export declare class UiSession extends Service {
154
161
  * @throws when the reference does not belong to the active Controller generation.
155
162
  */
156
163
  bindingSource(reference: SessionReference | undefined): HostObservable<StandardSourceBinding>;
164
+ /**
165
+ * Keep `callback`'s effects installed while the current Peer may call
166
+ * `action` on one Session resource, with the semantics of
167
+ * `ctx.remoteAccess.whenAccess`: `useSessionAccess` answers the same
168
+ * question during render.
169
+ * @param sessionId - the Session resource the guarded effects depend on.
170
+ * @param action - endpoint action the guarded effects depend on.
171
+ * @param callback - creates one disposer or an iterable of disposers.
172
+ * @returns idempotent disposer owned by the caller's Cordis fiber.
173
+ */
174
+ whenAccess(sessionId: SessionId, action: RemoteEndpoint, callback: () => AccessEffect): () => void;
157
175
  /**
158
176
  * Register one Session-scoped standard-source contribution.
159
177
  * @param descriptor - static member roster and per-binding resolver.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qilin-agent/client-ui-session",
3
3
  "description": "Session Controller adapter for React and session-scoped slots",
4
- "version": "3.1.7",
4
+ "version": "3.1.8",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -40,19 +40,20 @@
40
40
  },
41
41
  "license": "MIT",
42
42
  "peerDependencies": {
43
- "@qilin-agent/kylin": "~4.0.5"
43
+ "@qilin-agent/kylin": "~4.0.6-alpha.2"
44
44
  },
45
45
  "devDependencies": {
46
+ "@qilin-agent/api-remote-access": "3.1.8",
47
+ "@qilin-agent/kylin": "~4.0.6-alpha.2",
48
+ "@qilin-agent/api-remotes": "3.1.8",
49
+ "@qilin-agent/api-session-controller": "3.1.8",
50
+ "@qilin-agent/client-store": "3.1.8",
51
+ "@qilin-agent/client-ui-renderer": "3.1.8",
52
+ "@qilin-agent/client-ui-slots": "3.1.8",
53
+ "@qilin-agent/session": "3.1.8",
54
+ "@qilin-agent/util-values": "3.1.8",
46
55
  "@types/react": "~18.3.1",
47
- "react": "^18.2.0",
48
- "@qilin-agent/kylin": "~4.0.5",
49
- "@qilin-agent/api-session-controller": "3.1.7",
50
- "@qilin-agent/client-store": "3.1.7",
51
- "@qilin-agent/api-remotes": "3.1.7",
52
- "@qilin-agent/client-ui-renderer": "3.1.7",
53
- "@qilin-agent/client-ui-slots": "3.1.7",
54
- "@qilin-agent/session": "3.1.7",
55
- "@qilin-agent/util-values": "3.1.7"
56
+ "react": "^18.2.0"
56
57
  },
57
58
  "files": [
58
59
  "lib/index.js",