@linxin666/dsh-remote-bridge 0.4.8 → 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +2 -2
- package/README.md +50 -17
- package/README.zh.md +50 -17
- package/lib/client.js +274 -253
- package/lib/client.js.map +1 -1
- package/lib/index.js +6690 -2277
- package/lib/types/client/PairEntry.d.ts +2 -2
- package/lib/types/client/PairPanel.d.ts +10 -2
- package/lib/types/client/icons.d.ts +5 -13
- package/lib/types/client/locales.d.ts +10 -14
- package/lib/types/client/semantic.d.ts +9 -5
- package/lib/types/core/commands.d.ts +59 -0
- package/lib/types/core/connection.d.ts +68 -0
- package/lib/types/core/devices.d.ts +98 -2
- package/lib/types/core/hub.d.ts +65 -15
- package/lib/types/core/liveactivity.d.ts +324 -0
- package/lib/types/core/protocol.d.ts +260 -1
- package/lib/types/core/push.d.ts +178 -0
- package/lib/types/core/questions.d.ts +61 -9
- package/lib/types/core/session-meta.d.ts +55 -1
- package/lib/types/core/squads.d.ts +130 -0
- package/lib/types/core/usage-stats.d.ts +160 -0
- package/lib/types/core/usage.d.ts +294 -0
- package/lib/types/host/apns.d.ts +151 -0
- package/lib/types/host/squads-ledger.d.ts +39 -0
- package/lib/types/host/squads.d.ts +77 -0
- package/lib/types/host/usage-stats.d.ts +75 -0
- package/lib/types/host/watchers.d.ts +88 -0
- package/lib/types/index.d.ts +18 -2
- package/package.json +13 -13
- package/src/client/PairEntry.tsx +58 -31
- package/src/client/PairPanel.tsx +181 -97
- package/src/client/icons.tsx +17 -60
- package/src/client/locales.ts +15 -23
- package/src/client/panel.module.css +239 -186
- package/src/client/semantic.ts +10 -6
- package/src/core/commands.ts +95 -0
- package/src/core/connection.ts +646 -10
- package/src/core/devices.ts +221 -3
- package/src/core/hub.ts +362 -42
- package/src/core/liveactivity.ts +833 -0
- package/src/core/protocol.ts +294 -1
- package/src/core/push.ts +354 -0
- package/src/core/questions.ts +81 -10
- package/src/core/session-meta.ts +73 -1
- package/src/core/squads.ts +345 -0
- package/src/core/usage-stats.ts +424 -0
- package/src/core/usage.ts +937 -0
- package/src/core/wire.ts +8 -0
- package/src/host/apns.ts +320 -0
- package/src/host/squads-ledger.ts +105 -0
- package/src/host/squads.ts +206 -0
- package/src/host/usage-stats.ts +155 -0
- package/src/host/watchers.ts +272 -0
- package/src/index.ts +257 -8
package/src/index.ts
CHANGED
|
@@ -16,8 +16,11 @@
|
|
|
16
16
|
* - `user-questions/request` is claimed the same way and published as
|
|
17
17
|
* `question.request` to the devices that declared `questions.v1`; their
|
|
18
18
|
* `question.answer` settles the host's own ask while it is open, or reaches a
|
|
19
|
-
* continued question through the host's Remote `answer`.
|
|
20
|
-
*
|
|
19
|
+
* continued question through the host's Remote `answer`. With no paired
|
|
20
|
+
* connection on the wire the claim is still made when a roster device registered
|
|
21
|
+
* for notifications, which is reached by the alert and holds the question for one
|
|
22
|
+
* window before it goes back to the host's chain (§11.3, §32). Every other case
|
|
23
|
+
* delegates, and a timed question keeps the Host's own deadline.
|
|
21
24
|
*
|
|
22
25
|
* The browser half lives in `src/client/` and is declared by `dsh.client`: one
|
|
23
26
|
* sidebar-foot panel that reads the same loopback-gated token route over a
|
|
@@ -40,16 +43,26 @@ import type { ConnectionAuth } from './core/connection.ts'
|
|
|
40
43
|
import { DeviceRoster } from './core/devices.ts'
|
|
41
44
|
import { createRemoteBridgeFace, RemoteBridgeRegistry, REMOTE_BRIDGE_SERVICE } from './core/extension.ts'
|
|
42
45
|
import { JobRoster, type JobRegistryFace } from './core/jobs.ts'
|
|
43
|
-
import { BridgeHub } from './core/hub.ts'
|
|
46
|
+
import { BridgeHub, OFFLINE_QUESTION_CLAIM_TTL_MS } from './core/hub.ts'
|
|
44
47
|
import { createOwnerPeer } from './core/owner-peer.ts'
|
|
45
48
|
import { PairingService } from './core/pairing.ts'
|
|
49
|
+
import { LiveActivityNotifier } from './core/liveactivity.ts'
|
|
50
|
+
import { PushNotifier } from './core/push.ts'
|
|
46
51
|
import { QuestionClaims } from './core/questions.ts'
|
|
47
52
|
import { WS_PATH } from './core/protocol.ts'
|
|
48
|
-
import { SessionMeta, type
|
|
53
|
+
import { SessionMeta, type SessionStoreFace, type SessionTitleFace, type WorkspacesFace } from './core/session-meta.ts'
|
|
49
54
|
import { SessionPermissions, type ApprovalPolicyFace, type PermissionPresetsFace, type SandboxPolicyFace } from './core/session-permissions.ts'
|
|
55
|
+
import { selectionOf, modelSelectionOf } from './core/connection.ts'
|
|
56
|
+
import { UsageService, type CredentialStoreFace, type SessionRosterFace, type SessionRouteFace, type SettingsFace } from './core/usage.ts'
|
|
57
|
+
import { UsageStatsReader } from './core/usage-stats.ts'
|
|
58
|
+
import { wireArgs, type GatewayPeer } from './core/wire.ts'
|
|
50
59
|
import { dshHome } from './host/dsh-home.ts'
|
|
60
|
+
import { ApnsSender, apnsConfigFromEnv } from './host/apns.ts'
|
|
61
|
+
import { StandingWatchers } from './host/watchers.ts'
|
|
62
|
+
import { LoopbackSquads } from './host/squads.ts'
|
|
51
63
|
import { mountOnce } from './mount-once.ts'
|
|
52
64
|
import { makePairTokenRoute } from './host/routes.ts'
|
|
65
|
+
import { hostWebOrigin, LoopbackUsage } from './host/usage-stats.ts'
|
|
53
66
|
import { isWebSocketUpgrade, presentedTokenOf, readSecWebSocketKey, refuseUpgrade, serveUpgrade } from './host/websocket.ts'
|
|
54
67
|
|
|
55
68
|
/** Loader row identity of this plugin. */
|
|
@@ -61,6 +74,24 @@ export const inject = ['typertGateway', 'webServer']
|
|
|
61
74
|
/** Where the paired-device roster lives inside the DSH home. */
|
|
62
75
|
export const ROSTER_PATH = 'remote-bridge/devices.json'
|
|
63
76
|
|
|
77
|
+
/** The environment variable that moves the offline claim window (§32.2). */
|
|
78
|
+
export const OFFLINE_CLAIM_TTL_ENV = 'DSH_REMOTE_BRIDGE_OFFLINE_CLAIM_TTL_MS'
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The offline claim window this process runs with.
|
|
82
|
+
*
|
|
83
|
+
* The window is the bridge's own constant and never a host fact, so a deployment
|
|
84
|
+
* moves it here. A value that is missing, unreadable or not positive falls back to
|
|
85
|
+
* the constant instead of closing the window: a zero window would silently switch
|
|
86
|
+
* the channel off, and an operator who wanted that would be turning off push.
|
|
87
|
+
* @param env - the process environment, injectable for a suite.
|
|
88
|
+
* @returns the window in milliseconds.
|
|
89
|
+
*/
|
|
90
|
+
export function offlineClaimTtl(env: NodeJS.ProcessEnv = process.env): number {
|
|
91
|
+
const configured = Number(env[OFFLINE_CLAIM_TTL_ENV])
|
|
92
|
+
return Number.isFinite(configured) && configured > 0 ? configured : OFFLINE_QUESTION_CLAIM_TTL_MS
|
|
93
|
+
}
|
|
94
|
+
|
|
64
95
|
/** This machine's IANA time zone, or undefined when the platform has none. */
|
|
65
96
|
function localTimeZone(): string | undefined {
|
|
66
97
|
try {
|
|
@@ -115,20 +146,130 @@ function makeUpgradeHandler(hub: BridgeHub, roster: DeviceRoster, log: (message:
|
|
|
115
146
|
/**
|
|
116
147
|
* Resolve the host services session metadata is read from, now.
|
|
117
148
|
*
|
|
118
|
-
* All
|
|
119
|
-
*
|
|
149
|
+
* All of them are read per call rather than captured at mount: none is in this
|
|
150
|
+
* plugin's `inject` list, because requiring them would let the title or
|
|
120
151
|
* workspace plugin's absence take the whole bridge down with it. An unmounted
|
|
121
152
|
* service simply reads as undefined, and the protocol degrades one key of one
|
|
122
153
|
* row instead of failing a method. The faces are structural — this package
|
|
123
154
|
* imports no part of those services' own types.
|
|
155
|
+
*
|
|
156
|
+
* One registry answers two faces: `archive` is the slice a roster row reads and
|
|
157
|
+
* `workspaces` the wider slice `workspace.list` publishes, so a single lookup
|
|
158
|
+
* serves both and a host either composes a registry or composes none.
|
|
124
159
|
* @param ctx - the plugin's context.
|
|
125
160
|
* @returns the metadata faces as they stand right now.
|
|
126
161
|
*/
|
|
127
162
|
function sessionMetaFaces(ctx: Context) {
|
|
163
|
+
const registry = ctx.get('workspaceRegistry') as WorkspacesFace | undefined
|
|
128
164
|
return {
|
|
129
165
|
sessions: ctx.get('sessions') as SessionStoreFace | undefined,
|
|
130
166
|
titles: ctx.get('sessionTitle') as SessionTitleFace | undefined,
|
|
131
|
-
archive:
|
|
167
|
+
archive: registry,
|
|
168
|
+
workspaces: registry,
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 宿主自己的会话名册,按 `usage.session` 需要的那一格读出来。
|
|
174
|
+
*
|
|
175
|
+
* 走的是 `session.list` 服务的同一个端点(`session/list`),也就是手机名册的
|
|
176
|
+
* 来源:它名下既有活的会话,也有本进程没观察过、当前也不 live 的会话,因此
|
|
177
|
+
* 那类会话不会被说成不存在。`ctx.sessions.list()` 答不了这一问——它只列已经
|
|
178
|
+
* 进入存储的会话。读失败或答不出 item 表就回 undefined,「不知道名册」由用量
|
|
179
|
+
* 服务退回活会话存储与事件折叠两条证词。
|
|
180
|
+
* @param ctx - 插件的上下文,携带网关。
|
|
181
|
+
* @param peer - 本桥自己的 owner peer,每次调用都以它发声。
|
|
182
|
+
* @param log - 读不到名册时的落点。
|
|
183
|
+
* @returns 名册 face。
|
|
184
|
+
*/
|
|
185
|
+
function sessionRoster(ctx: Context, peer: GatewayPeer, log: (message: string) => void): SessionRosterFace {
|
|
186
|
+
return {
|
|
187
|
+
ids: async (): Promise<readonly string[] | undefined> => {
|
|
188
|
+
try {
|
|
189
|
+
const value = await ctx.typertGateway.invoke({
|
|
190
|
+
namespace: 'session',
|
|
191
|
+
method: 'list',
|
|
192
|
+
args: wireArgs('session', 'list', {}),
|
|
193
|
+
peer,
|
|
194
|
+
})
|
|
195
|
+
const items = typeof value === 'object' && value !== null ? (value as { items?: unknown }).items : undefined
|
|
196
|
+
if (!Array.isArray(items)) return undefined
|
|
197
|
+
const ids: string[] = []
|
|
198
|
+
for (const item of items) {
|
|
199
|
+
const id = typeof item === 'object' && item !== null ? (item as { sessionId?: unknown }).sessionId : undefined
|
|
200
|
+
if (typeof id === 'string' && id !== '') ids.push(id)
|
|
201
|
+
}
|
|
202
|
+
return ids
|
|
203
|
+
} catch (error) {
|
|
204
|
+
log(`the host session roster could not be read: ${String(error)}`)
|
|
205
|
+
return undefined
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* 一条会话此刻的路由,按 `usage.session` 的模型窗口那一档读出来。
|
|
213
|
+
*
|
|
214
|
+
* 折叠与 `session.models` 的 `current` 逐字一致:下一步的选择、其次是用过的那个、
|
|
215
|
+
* 最后才是目录默认。两个方法读同一个折叠,就不可能出现「模型选择器说 A、模型窗口
|
|
216
|
+
* 按 B 算」这种事。每次读都走本桥自己的 owner peer;读不到任何一档就回 undefined,
|
|
217
|
+
* 那一档读数(`modelContextWindow`)因此根本不出现,而不是补一个默认值。
|
|
218
|
+
* @param ctx - 插件的上下文,携带网关。
|
|
219
|
+
* @param peer - 本桥自己的 owner peer,每次调用都以它发声。
|
|
220
|
+
* @param log - 读不到时记一行日志。
|
|
221
|
+
* @returns 路由 face。
|
|
222
|
+
*/
|
|
223
|
+
function sessionRoute(ctx: Context, peer: GatewayPeer, log: (message: string) => void): SessionRouteFace {
|
|
224
|
+
const invoke = async (method: string, args: Readonly<Record<string, unknown>>): Promise<unknown> => await ctx.typertGateway.invoke({
|
|
225
|
+
namespace: 'session',
|
|
226
|
+
method,
|
|
227
|
+
args: wireArgs('session', method, args),
|
|
228
|
+
peer,
|
|
229
|
+
})
|
|
230
|
+
return {
|
|
231
|
+
current: async (sessionId: string) => {
|
|
232
|
+
try {
|
|
233
|
+
const folded = modelSelectionOf(await invoke('projections', { sessionId }))
|
|
234
|
+
const selected = folded.next ?? folded.lastUsed
|
|
235
|
+
// 还没选过模型的会话在目录默认上——它下一步就会用那个,也正是
|
|
236
|
+
// `session.models` 对同一条会话给出的答案。
|
|
237
|
+
const fallback = selected === undefined ? selectionOf(catalogDefaultOf(await invoke('modelCatalog', {}))) : undefined
|
|
238
|
+
const answer = selected ?? fallback
|
|
239
|
+
return answer === undefined ? undefined : { provider: answer.provider, model: answer.model }
|
|
240
|
+
} catch (error) {
|
|
241
|
+
log(`the route of session ${sessionId} could not be read: ${String(error)}`)
|
|
242
|
+
return undefined
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** `session/modelCatalog` 里的 `default` 一格。 */
|
|
249
|
+
function catalogDefaultOf(value: unknown): unknown {
|
|
250
|
+
return typeof value === 'object' && value !== null ? (value as { default?: unknown }).default : undefined
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* 解析 `usage.v1` 要读的宿主服务,现在就解析一次。
|
|
255
|
+
*
|
|
256
|
+
* 与元数据的三个 face 同一条理由:四者都不在本插件的 `inject` 里,缺一个不该
|
|
257
|
+
* 让整个桥起不来。缺活会话存储,`usage.session` 就只能靠名册与本进程观察过的
|
|
258
|
+
* 事件判断会话是否存在;缺凭据服务,`usage.balance` 回 `no-credential`;缺设置
|
|
259
|
+
* 服务,路由的 `baseURL` 与 `apiKeyEnv` 读不到,origin 判定与凭据回退都退回
|
|
260
|
+
* 官方默认值。face 是结构化的:本包不导入这些服务自己的类型。
|
|
261
|
+
* @param ctx - 插件的上下文。
|
|
262
|
+
* @param peer - 本桥自己的 owner peer,名册读取以它发声。
|
|
263
|
+
* @param log - 读不到名册时的落点。
|
|
264
|
+
* @returns 这些 face 此刻的样子。
|
|
265
|
+
*/
|
|
266
|
+
function usageFaces(ctx: Context, peer: GatewayPeer, log: (message: string) => void) {
|
|
267
|
+
return {
|
|
268
|
+
sessions: ctx.get('sessions') as SessionStoreFace | undefined,
|
|
269
|
+
roster: sessionRoster(ctx, peer, log),
|
|
270
|
+
credentials: ctx.get('credentials') as CredentialStoreFace | undefined,
|
|
271
|
+
settings: ctx.get('settings') as SettingsFace | undefined,
|
|
272
|
+
route: sessionRoute(ctx, peer, log),
|
|
132
273
|
}
|
|
133
274
|
}
|
|
134
275
|
|
|
@@ -195,11 +336,103 @@ function applyImpl(ctx: Context): void {
|
|
|
195
336
|
// about the host, not about the device that asked about it.
|
|
196
337
|
const jobs = new JobRoster({ faces: () => jobFaces(ctx), log })
|
|
197
338
|
const sessionMeta = new SessionMeta(() => sessionMetaFaces(ctx), () => Date.now(), log)
|
|
339
|
+
// 用量读数:一条会话的窗口与组成靠宿主广播的事件折出来,余额靠宿主自己的
|
|
340
|
+
// 凭据与设置查出来。一个宿主一份、所有连接共享——两台手机重复问,上游也只
|
|
341
|
+
// 该收到一次请求(core/usage.ts)。
|
|
342
|
+
// 台账聚合读的是宿主上 dsh-usage 插件的两条 HTTP 路由,走本机回环 origin:那个
|
|
343
|
+
// 插件不发布任何 cordis 服务,端口从 `webServer` 来(先 getOrigin(),拿不到再退回
|
|
344
|
+
// 监听端口)。没有它时 `usage.stats` 答 no-usage-plugin,其余读数一概不变。
|
|
345
|
+
const usageRoutes = new LoopbackUsage({ origin: () => hostWebOrigin(ctx.webServer), log })
|
|
346
|
+
const usageStats = new UsageStatsReader({ transport: () => usageRoutes, now: () => Date.now(), log })
|
|
347
|
+
const usage = new UsageService({ faces: () => usageFaces(ctx, ownerPeer, log), now: () => Date.now(), stats: usageStats, log })
|
|
348
|
+
// The push channel is OFF unless this machine holds an Apple signing key: no
|
|
349
|
+
// key, no sender, and every notification path is a no-op — which is what keeps
|
|
350
|
+
// the protocol byte-identical for every deployment that has none (§28).
|
|
351
|
+
const apns = apnsConfigFromEnv()
|
|
352
|
+
// One client for both channels: an APNs provider token is minted per key and
|
|
353
|
+
// then reused, so a second client would only double the mint rate Apple
|
|
354
|
+
// throttles (core/push.ts, host/apns.ts).
|
|
355
|
+
const apnsSender = apns === undefined ? undefined : new ApnsSender({ config: apns, log })
|
|
356
|
+
const push = new PushNotifier({
|
|
357
|
+
targets: () => roster.pushTargets().map(({ push: registration }) => ({
|
|
358
|
+
deviceToken: registration.deviceToken,
|
|
359
|
+
environment: registration.environment,
|
|
360
|
+
bundle: registration.bundle,
|
|
361
|
+
...(registration.locale === undefined ? {} : { locale: registration.locale }),
|
|
362
|
+
})),
|
|
363
|
+
...(apnsSender === undefined ? {} : { sender: apnsSender }),
|
|
364
|
+
titles: id => sessionMeta.title(id),
|
|
365
|
+
now: () => Date.now(),
|
|
366
|
+
log,
|
|
367
|
+
})
|
|
368
|
+
// The lock-screen card path (§29). It reads the same roster, through the same
|
|
369
|
+
// client, and is inert for exactly the same reason: no key, no sender, no card.
|
|
370
|
+
// A token APNs reports dead is dropped from its device row here, which is the
|
|
371
|
+
// whole of the recovery — the next card registers a fresh one.
|
|
372
|
+
const liveActivity = new LiveActivityNotifier({
|
|
373
|
+
targets: () => roster.pushTargets().flatMap(({ push: registration }) => (registration.liveActivityTokens ?? []).map(({ activityId, token, sessionId }) => ({
|
|
374
|
+
activityId,
|
|
375
|
+
token,
|
|
376
|
+
// The session is the card's address (§29.9). A registration written before
|
|
377
|
+
// that field existed simply has none, and its card is never pushed to.
|
|
378
|
+
...(sessionId === undefined ? {} : { sessionId }),
|
|
379
|
+
environment: registration.environment,
|
|
380
|
+
bundle: registration.bundle,
|
|
381
|
+
}))),
|
|
382
|
+
...(apnsSender === undefined ? {} : { sender: apnsSender }),
|
|
383
|
+
now: () => Date.now(),
|
|
384
|
+
log,
|
|
385
|
+
retire: async (activityId, token) => {
|
|
386
|
+
const dropped = await roster.removeLiveActivityToken(activityId, token)
|
|
387
|
+
// A dead token is a roster change like any other: the session it named may
|
|
388
|
+
// have just lost its last card, and a watcher for it must close.
|
|
389
|
+
if (dropped) watchers.sync()
|
|
390
|
+
return dropped
|
|
391
|
+
},
|
|
392
|
+
})
|
|
393
|
+
// The bridge's own follow streams (§28/§29): a suspended phone has no socket,
|
|
394
|
+
// so the turn end its card has to show would otherwise be seen by nobody. One
|
|
395
|
+
// watcher per session that still holds a card token, armed from the roster and
|
|
396
|
+
// never from a client frame.
|
|
397
|
+
const watchedSessions = (): readonly string[] => {
|
|
398
|
+
const sessions = new Set<string>()
|
|
399
|
+
for (const { push: registration } of roster.pushTargets()) {
|
|
400
|
+
for (const token of registration.liveActivityTokens ?? []) {
|
|
401
|
+
if (token.sessionId !== undefined) sessions.add(token.sessionId)
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return [...sessions]
|
|
405
|
+
}
|
|
406
|
+
const watchers = new StandingWatchers({
|
|
407
|
+
gateway: ctx.typertGateway,
|
|
408
|
+
peer: ownerPeer,
|
|
409
|
+
sessions: watchedSessions,
|
|
410
|
+
...(apnsSender === undefined ? {} : { liveActivity, push }),
|
|
411
|
+
log,
|
|
412
|
+
})
|
|
198
413
|
const permissions = new SessionPermissions(() => permissionFaces(ctx), log)
|
|
199
414
|
// The extension seam publishes no protocol vocabulary of its own: another
|
|
200
415
|
// plugin registers the method names, payloads and topics it owns, and this
|
|
201
416
|
// package only dispatches and fans out what it was handed.
|
|
417
|
+
// The squad domain of the `dsh-agents` plugin is read over this host's own
|
|
418
|
+
// loopback origin: that plugin serves its routes on the very web server this
|
|
419
|
+
// bridge already injects. Both the origin and the ledger directory are resolved
|
|
420
|
+
// per call — the listener may not have bound a port when this row mounts, and a
|
|
421
|
+
// DSH home is not a fact to capture once.
|
|
422
|
+
const squads = new LoopbackSquads({
|
|
423
|
+
origin: () => {
|
|
424
|
+
try {
|
|
425
|
+
return ctx.webServer.getOrigin()
|
|
426
|
+
} catch {
|
|
427
|
+
return undefined
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
ledgerDirectory: () => join(dshHome(), 'dsh-agents'),
|
|
431
|
+
log,
|
|
432
|
+
})
|
|
202
433
|
const extensions = new RemoteBridgeRegistry()
|
|
434
|
+
// 离线认领的窗口归桥所有,宿主从不认识它(§32.2):常量是默认值,部署可用环境变量覆盖。
|
|
435
|
+
const offlineClaimTtlMs = offlineClaimTtl()
|
|
203
436
|
const hub = new BridgeHub({
|
|
204
437
|
extensions,
|
|
205
438
|
gateway: ctx.typertGateway,
|
|
@@ -209,8 +442,14 @@ function applyImpl(ctx: Context): void {
|
|
|
209
442
|
questions,
|
|
210
443
|
jobs,
|
|
211
444
|
sessionMeta,
|
|
445
|
+
usage,
|
|
212
446
|
permissions,
|
|
213
447
|
ownerPeer,
|
|
448
|
+
squads,
|
|
449
|
+
push,
|
|
450
|
+
liveActivity,
|
|
451
|
+
offlineClaimTtlMs,
|
|
452
|
+
onPushRegistered: () => { watchers.sync() },
|
|
214
453
|
now: () => Date.now(),
|
|
215
454
|
clientTimeZone: localTimeZone,
|
|
216
455
|
log,
|
|
@@ -224,21 +463,31 @@ function applyImpl(ctx: Context): void {
|
|
|
224
463
|
}
|
|
225
464
|
|
|
226
465
|
ctx.effect(() => {
|
|
227
|
-
|
|
466
|
+
// A registration that arrived before this row mounted is still on disk: the
|
|
467
|
+
// watchers are reconciled from what the roster holds, not from what a live
|
|
468
|
+
// connection happened to send.
|
|
469
|
+
void roster.load().then(() => { watchers.sync() }).catch(() => undefined)
|
|
228
470
|
const disposeUpgrade = ctx.webServer.registerUpgrade({
|
|
229
471
|
path: WS_PATH,
|
|
230
472
|
handler: makeUpgradeHandler(hub, roster, log),
|
|
231
473
|
})
|
|
232
474
|
const disposeRoute = ctx.webServer.register(makePairTokenRoute({ pairing, log }))
|
|
233
475
|
log(`protocol v1 listening on ${WS_PATH}`)
|
|
476
|
+
log(apns === undefined
|
|
477
|
+
? `push: off (set ${'DSH_REMOTE_BRIDGE_APNS_KEY_FILE'}, ${'DSH_REMOTE_BRIDGE_APNS_KEY_ID'} and ${'DSH_REMOTE_BRIDGE_APNS_TEAM_ID'} to enable APNs)`
|
|
478
|
+
: `push: on (APNs key ${apns.keyId} of team ${apns.teamId})`)
|
|
234
479
|
return () => {
|
|
235
480
|
disposeUpgrade()
|
|
236
481
|
disposeRoute()
|
|
482
|
+
watchers.dispose()
|
|
237
483
|
hub.dispose()
|
|
238
484
|
jobs.dispose()
|
|
239
485
|
}
|
|
240
486
|
}, 'remote-bridge: protocol v1 routes')
|
|
241
487
|
|
|
488
|
+
// 会话事件是 `usage.session` 唯一的来源:桥不读会话日志、也不回填历史,所以
|
|
489
|
+
// 这个监听器挂上之前广播的事件不会有读数,宿主没广播过的窗口也不会被编出来。
|
|
490
|
+
ctx.on('session/event', (session, event) => { usage.record(session.id, event) })
|
|
242
491
|
ctx.on('approval/request', (request, next) => hub.approve(request, next))
|
|
243
492
|
// Prepended: the host's waterfall is first-come, and the desktop client's own
|
|
244
493
|
// answerer would otherwise claim every question before this listener is
|