@linxin666/dsh-remote-bridge 0.4.8 → 0.4.10
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 +75 -18
- package/README.zh.md +74 -18
- package/lib/client.js +783 -260
- package/lib/client.js.map +1 -1
- package/lib/index.js +15849 -2913
- package/lib/types/client/PairEntry.d.ts +2 -2
- package/lib/types/client/PairPanel.d.ts +10 -2
- package/lib/types/client/UiPresentRow.d.ts +13 -0
- package/lib/types/client/icons.d.ts +5 -13
- package/lib/types/client/index.d.ts +4 -0
- package/lib/types/client/locales.d.ts +24 -15
- package/lib/types/client/semantic.d.ts +9 -5
- package/lib/types/client/toolview-slot.d.ts +68 -0
- package/lib/types/client/ui-card.d.ts +160 -0
- package/lib/types/core/commands.d.ts +59 -0
- package/lib/types/core/connection.d.ts +106 -0
- package/lib/types/core/devices.d.ts +102 -2
- package/lib/types/core/extension.d.ts +13 -0
- package/lib/types/core/hub.d.ts +129 -15
- package/lib/types/core/liveactivity.d.ts +324 -0
- package/lib/types/core/protocol.d.ts +328 -5
- package/lib/types/core/push.d.ts +186 -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/turn-end-quiet.d.ts +135 -0
- package/lib/types/core/ui.d.ts +238 -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/ui-tools.d.ts +80 -0
- package/lib/types/host/usage-stats.d.ts +75 -0
- package/lib/types/host/watchers.d.ts +95 -0
- package/lib/types/index.d.ts +47 -3
- package/package.json +15 -14
- package/src/client/PairEntry.tsx +58 -31
- package/src/client/PairPanel.tsx +181 -97
- package/src/client/UiPresentRow.tsx +149 -0
- package/src/client/icons.tsx +17 -60
- package/src/client/index.ts +11 -0
- package/src/client/locales.ts +36 -24
- package/src/client/panel.module.css +239 -186
- package/src/client/semantic.ts +10 -6
- package/src/client/toolview-slot.ts +84 -0
- package/src/client/ui-card.ts +368 -0
- package/src/client/ui-present.module.css +87 -0
- package/src/core/commands.ts +95 -0
- package/src/core/connection.ts +811 -12
- package/src/core/devices.ts +337 -5
- package/src/core/extension.ts +20 -0
- package/src/core/hub.ts +518 -43
- package/src/core/liveactivity.ts +833 -0
- package/src/core/protocol.ts +370 -5
- package/src/core/push.ts +385 -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/turn-end-quiet.ts +388 -0
- package/src/core/ui.ts +398 -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/ui-tools.ts +233 -0
- package/src/host/usage-stats.ts +155 -0
- package/src/host/watchers.ts +296 -0
- package/src/index.ts +327 -10
|
@@ -67,12 +67,59 @@ export interface QuestionAnswerItem {
|
|
|
67
67
|
export interface QuestionAnswer {
|
|
68
68
|
readonly answers: readonly QuestionAnswerItem[];
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* The `question.request` payload for one claim, and the `payload` of every
|
|
72
|
+
* `question.list` entry.
|
|
73
|
+
*
|
|
74
|
+
* One function for both so the card a phone was handed and the card it reads back
|
|
75
|
+
* out of a list cannot drift apart: `expiresAt` appears only once the claim
|
|
76
|
+
* learned the host's own deadline, and a blocking ask publishes no such key at
|
|
77
|
+
* all rather than an empty or null one.
|
|
78
|
+
* @param state - whether the foreground ask still holds the question.
|
|
79
|
+
* @param question - the claim being published.
|
|
80
|
+
* @returns the frozen payload body.
|
|
81
|
+
*/
|
|
82
|
+
export declare function questionPayload(state: QuestionState, question: ClaimedQuestionView): QuestionRequestPayload;
|
|
83
|
+
/**
|
|
84
|
+
* The identity a client knows one question card by.
|
|
85
|
+
*
|
|
86
|
+
* The same `sessionId/callId` pair the phone already derives for its own card,
|
|
87
|
+
* so a list entry and the card it describes are compared as one name instead of
|
|
88
|
+
* two fields that could be recombined differently on each side.
|
|
89
|
+
* @param sessionId - the session that asked.
|
|
90
|
+
* @param callId - the wire call id the client answers with.
|
|
91
|
+
* @returns the card key.
|
|
92
|
+
*/
|
|
93
|
+
export declare function questionKey(sessionId: string, callId: string): string;
|
|
94
|
+
/** One question this bridge still holds, as `question.list` publishes it. */
|
|
95
|
+
export interface ListedQuestion {
|
|
96
|
+
/** {@link questionKey}: the card identity the client holds it under. */
|
|
97
|
+
readonly key: string;
|
|
98
|
+
readonly sessionId: string;
|
|
99
|
+
/** `open` or `continued`; a settled question is not held and never listed. */
|
|
100
|
+
readonly state: QuestionState;
|
|
101
|
+
/** The `question.request` payload, byte for byte the shape that channel froze. */
|
|
102
|
+
readonly payload: QuestionRequestPayload;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The body of one `question.list` answer.
|
|
106
|
+
*
|
|
107
|
+
* `complete` is what a client is allowed to act on: only a complete list may
|
|
108
|
+
* retire a card it does not carry, so a bridge that could answer only part of the
|
|
109
|
+
* set must say `false` rather than let the difference read as "the question is
|
|
110
|
+
* over".
|
|
111
|
+
*/
|
|
112
|
+
export interface QuestionListPayload {
|
|
113
|
+
readonly questions: readonly ListedQuestion[];
|
|
114
|
+
readonly complete: boolean;
|
|
115
|
+
}
|
|
70
116
|
/** Whether a question still holds the foreground ask, or only its late reply. */
|
|
71
117
|
/**
|
|
72
118
|
* `open` while the ask is still waiting, `continued` once the host's foreground
|
|
73
119
|
* wait ended but a late answer can still be steered in, and `settled` as the
|
|
74
|
-
* one-way notice that the phone's card is over — the host's own UI answered it or
|
|
75
|
-
* the
|
|
120
|
+
* one-way notice that the phone's card is over — the host's own UI answered it, or
|
|
121
|
+
* none was left to answer it once the claim's grace window ended. `settled` is
|
|
122
|
+
* published, never held.
|
|
76
123
|
*/
|
|
77
124
|
export type QuestionState = 'open' | 'continued' | 'settled';
|
|
78
125
|
/** `question.request`'s payload, as frozen by the contract. */
|
|
@@ -260,13 +307,17 @@ export declare class QuestionClaims {
|
|
|
260
307
|
*/
|
|
261
308
|
answer(sessionId: string, callId: string, answer: QuestionAnswer): Promise<QuestionReply>;
|
|
262
309
|
/**
|
|
263
|
-
* Every
|
|
310
|
+
* Every question this bridge still holds, as `question.list` publishes it.
|
|
264
311
|
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
312
|
+
* The claim registry IS the answer: a question leaves it the moment it is
|
|
313
|
+
* answered, settled by the host's own UI, withdrawn with the last paired phone
|
|
314
|
+
* or expired, so a card missing from this list is a card no one can answer any
|
|
315
|
+
* more. Both live states are listed — `continued` is still answerable through
|
|
316
|
+
* the host's late-answer path — and a settled question is never here, because
|
|
317
|
+
* it is never held.
|
|
318
|
+
* @returns one entry per held claim, in claim order.
|
|
268
319
|
*/
|
|
269
|
-
|
|
320
|
+
listed(): readonly ListedQuestion[];
|
|
270
321
|
/**
|
|
271
322
|
* Withdraw the named questions, delegating each to the next answerer.
|
|
272
323
|
* @returns how many were still open and therefore delegated.
|
|
@@ -274,8 +325,9 @@ export declare class QuestionClaims {
|
|
|
274
325
|
withdraw(callIds: readonly string[]): number;
|
|
275
326
|
/**
|
|
276
327
|
* Withdraw every claim, delegating each open question to the next answerer.
|
|
277
|
-
* Called when the last paired phone
|
|
278
|
-
*
|
|
328
|
+
* Called when the last paired phone has been gone long enough that no grace
|
|
329
|
+
* window is still running, and when the bridge unloads: a question nobody can
|
|
330
|
+
* answer must not hold the agent until its own deadline.
|
|
279
331
|
* @returns how many questions were still open.
|
|
280
332
|
*/
|
|
281
333
|
withdrawAll(): number;
|
|
@@ -32,18 +32,56 @@ export interface SessionTitleFace {
|
|
|
32
32
|
export interface ArchiveSetFace {
|
|
33
33
|
readonly archivedSessionIds: readonly string[];
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* One workspace registration, as far as `workspace.list` publishes it.
|
|
37
|
+
*
|
|
38
|
+
* The host's entity carries more — its `sessionIds` account above all — and the
|
|
39
|
+
* face deliberately does not declare it: a row this bridge publishes must not be
|
|
40
|
+
* able to carry an array that grows with the session count.
|
|
41
|
+
*/
|
|
42
|
+
export interface WorkspaceFace {
|
|
43
|
+
readonly id: string;
|
|
44
|
+
readonly path: string;
|
|
45
|
+
readonly title: string;
|
|
46
|
+
readonly createdAt?: string;
|
|
47
|
+
readonly updatedAt?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The slice of `ctx.workspaceRegistry` `workspace.list` reads: the registry
|
|
51
|
+
* itself.
|
|
52
|
+
*
|
|
53
|
+
* Wider than {@link ArchiveSetFace} by the ordered projection and the pin set,
|
|
54
|
+
* because one method publishes all three: a client pins a session and reads
|
|
55
|
+
* both sets back in one frame. Every member is synchronous — `list()` answers a
|
|
56
|
+
* fresh array and both sets are getters over the durable registry — which is
|
|
57
|
+
* what lets the answer be built without awaiting anything.
|
|
58
|
+
*/
|
|
59
|
+
export interface WorkspacesFace extends ArchiveSetFace {
|
|
60
|
+
list(): readonly WorkspaceFace[];
|
|
61
|
+
readonly pinnedSessionIds: readonly string[];
|
|
62
|
+
}
|
|
63
|
+
/** The body `workspace.list` answers. */
|
|
64
|
+
export interface WorkspaceListAnswer {
|
|
65
|
+
readonly workspaces: readonly WorkspaceFace[];
|
|
66
|
+
readonly archivedSessionIds: readonly string[];
|
|
67
|
+
readonly pinnedSessionIds: readonly string[];
|
|
68
|
+
}
|
|
35
69
|
/**
|
|
36
70
|
* The in-process services one metadata read may use.
|
|
37
71
|
*
|
|
38
72
|
* Every field is optional on purpose. The bridge does not require the title or
|
|
39
73
|
* workspace plugins to be installed — the protocol's roster and title methods
|
|
40
74
|
* stay answerable with them absent, and a field that is missing degrades one
|
|
41
|
-
* key of one row instead of failing a method.
|
|
75
|
+
* key of one row instead of failing a method. `workspaces` is the member that
|
|
76
|
+
* breaks that rule on purpose: `workspace.list` exists only to publish the
|
|
77
|
+
* registry, so its absence is reported as a host without one rather than
|
|
78
|
+
* answered with an empty list.
|
|
42
79
|
*/
|
|
43
80
|
export interface SessionMetaFaces {
|
|
44
81
|
readonly sessions?: SessionStoreFace | undefined;
|
|
45
82
|
readonly titles?: SessionTitleFace | undefined;
|
|
46
83
|
readonly archive?: ArchiveSetFace | undefined;
|
|
84
|
+
readonly workspaces?: WorkspacesFace | undefined;
|
|
47
85
|
}
|
|
48
86
|
/** Largest id batch one `session.titles` call accepts. */
|
|
49
87
|
export declare const TITLES_MAX_IDS = 100;
|
|
@@ -102,4 +140,20 @@ export declare class SessionMeta {
|
|
|
102
140
|
* @returns the archived session ids, or undefined when the registry is unavailable.
|
|
103
141
|
*/
|
|
104
142
|
archiveSet(): ReadonlySet<string> | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* The host's workspaces and its two registry-global session sets.
|
|
145
|
+
*
|
|
146
|
+
* One synchronous projection and nothing more: `list()` already answers a
|
|
147
|
+
* fresh array in registry order, and both sets are getters over the durable
|
|
148
|
+
* registry, so this read awaits nothing, opens no follow stream and touches no
|
|
149
|
+
* persistence. Workspaces are neither sorted nor filtered — the registry's own
|
|
150
|
+
* order is the display order — and a row carries exactly the fields protocol
|
|
151
|
+
* v1 names, `sessionIds` never among them.
|
|
152
|
+
*
|
|
153
|
+
* An unmounted registry answers undefined instead of an empty list: "this host
|
|
154
|
+
* has no workspaces" and "this host has no registry to ask" are two different
|
|
155
|
+
* facts, and only the caller can say which one it must report.
|
|
156
|
+
* @returns the answer, or undefined when this host composes no workspace registry.
|
|
157
|
+
*/
|
|
158
|
+
workspaceList(): WorkspaceListAnswer | undefined;
|
|
105
159
|
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The squads channel: the squad domain of the `dsh-agents` plugin — its
|
|
3
|
+
* definitions and the runs that launch sessions — as a phone reads and drives
|
|
4
|
+
* it.
|
|
5
|
+
*
|
|
6
|
+
* Nothing about a squad is modelled here. A squad is the plugin's own team row
|
|
7
|
+
* with the definition timestamps dropped, a run is the plugin's own run record
|
|
8
|
+
* with the goal it was given dropped, and a refusal the plugin raised crosses
|
|
9
|
+
* with the plugin's own code. What this module owns is the mapping onto the
|
|
10
|
+
* frozen `squads.v1` bodies plus the transport seam a Host half implements to
|
|
11
|
+
* reach the domain.
|
|
12
|
+
*
|
|
13
|
+
* The seam answers the plugin's rows unread (`unknown`), so one mapping serves
|
|
14
|
+
* both ways a Host can reach them: the plugin's HTTP routes over loopback, and
|
|
15
|
+
* the read-only ledger fallback. A row this build cannot read is refused rather
|
|
16
|
+
* than repaired, because a repaired squad is a squad the user never wrote.
|
|
17
|
+
* @module dsh-remote-bridge/core/squads
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Every method the squads capability puts in a client's protocol. The gate in
|
|
21
|
+
* `connection.ts` reads this set once, so a method added beside these is gated
|
|
22
|
+
* by the same declaration rather than by a second list to keep in step.
|
|
23
|
+
*/
|
|
24
|
+
export declare const SQUAD_METHODS: ReadonlySet<string>;
|
|
25
|
+
/** Sandbox modes a member may pin; the DSH permission presets, as the plugin spells them. */
|
|
26
|
+
export type SquadMemberPermission = 'read-only' | 'workspace-write' | 'danger-full-access';
|
|
27
|
+
/** One member of a squad: a display name and the pins its session is composed from. */
|
|
28
|
+
export interface SquadMember {
|
|
29
|
+
id: string;
|
|
30
|
+
name: string;
|
|
31
|
+
preset?: string;
|
|
32
|
+
permission?: SquadMemberPermission;
|
|
33
|
+
model?: string;
|
|
34
|
+
reasoningEffort?: string;
|
|
35
|
+
brief?: string;
|
|
36
|
+
}
|
|
37
|
+
/** One squad: an ordered set of member definitions sharing a workspace. */
|
|
38
|
+
export interface Squad {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
workspaceId?: string;
|
|
43
|
+
leadPreset?: string;
|
|
44
|
+
order?: number;
|
|
45
|
+
members: SquadMember[];
|
|
46
|
+
}
|
|
47
|
+
/** One launched session: a member session, or the Lead session of a whole squad. */
|
|
48
|
+
export interface SquadRun {
|
|
49
|
+
id: string;
|
|
50
|
+
squadId: string;
|
|
51
|
+
kind: 'squad' | 'member';
|
|
52
|
+
memberId?: string;
|
|
53
|
+
sessionId: string;
|
|
54
|
+
createdAt: number;
|
|
55
|
+
status: 'running' | 'settled' | 'failed';
|
|
56
|
+
failure?: string;
|
|
57
|
+
}
|
|
58
|
+
/** The `squads.state` body: definitions, run history, the offered presets and the owning pid. */
|
|
59
|
+
export interface SquadsState {
|
|
60
|
+
squads: Squad[];
|
|
61
|
+
runs: SquadRun[];
|
|
62
|
+
presets?: string[];
|
|
63
|
+
host: {
|
|
64
|
+
ownerPid?: number;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** What `squads.runMember` asks the domain to launch. */
|
|
68
|
+
export interface SquadMemberRunRequest {
|
|
69
|
+
squadId: string;
|
|
70
|
+
memberId: string;
|
|
71
|
+
firstMessage?: string;
|
|
72
|
+
}
|
|
73
|
+
/** What `squads.runSquad` asks the domain to launch. */
|
|
74
|
+
export interface SquadRunRequest {
|
|
75
|
+
squadId: string;
|
|
76
|
+
goal?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A refusal this channel answers with. The transport raises it and the
|
|
80
|
+
* connection publishes its `code` and text unchanged, so a domain refusal
|
|
81
|
+
* (`team-not-found`, `preset-unknown`) and a capability refusal
|
|
82
|
+
* (`squads-unavailable`, `squads-run-unavailable`) reach the client the same way.
|
|
83
|
+
*/
|
|
84
|
+
export declare class SquadRefusal extends Error {
|
|
85
|
+
/** Stable machine code the client switches on. */
|
|
86
|
+
readonly code: string;
|
|
87
|
+
constructor(code: string, message: string);
|
|
88
|
+
}
|
|
89
|
+
/** @returns whether a caught value is this channel's own refusal. */
|
|
90
|
+
export declare function isSquadRefusal(value: unknown): value is SquadRefusal;
|
|
91
|
+
/**
|
|
92
|
+
* How a Host reaches the squad domain. Every method answers the plugin's own
|
|
93
|
+
* body unread: `state` is one `{teams, runs, host, presets?}` document, and the
|
|
94
|
+
* two run methods answer one `{run}` document.
|
|
95
|
+
*/
|
|
96
|
+
export interface SquadTransport {
|
|
97
|
+
/** Definitions, run history and the owning pid, as the domain publishes them. */
|
|
98
|
+
state(): Promise<unknown>;
|
|
99
|
+
/** Launch one member session. */
|
|
100
|
+
runMember(request: SquadMemberRunRequest): Promise<unknown>;
|
|
101
|
+
/** Launch the Lead session of one whole squad. */
|
|
102
|
+
runSquad(request: SquadRunRequest): Promise<unknown>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Map one `squads.state` answer.
|
|
106
|
+
* @param source - the domain's `{teams, runs, host, presets?}` document, from
|
|
107
|
+
* either the plugin's route or its ledger.
|
|
108
|
+
* @returns the frozen state body.
|
|
109
|
+
*/
|
|
110
|
+
export declare function squadsStateOf(source: unknown): SquadsState;
|
|
111
|
+
/**
|
|
112
|
+
* Map one run answer.
|
|
113
|
+
* @param source - the domain's `{run}` document.
|
|
114
|
+
* @returns the frozen run row.
|
|
115
|
+
*/
|
|
116
|
+
export declare function squadRunOf(source: unknown): SquadRun;
|
|
117
|
+
/**
|
|
118
|
+
* Gate `squads.runMember`'s payload. Only the two names this command needs are
|
|
119
|
+
* required; the lengths the domain accepts are the domain's own, so an oversized
|
|
120
|
+
* message is forwarded and refused there instead of being cut here.
|
|
121
|
+
* @param payload - the request's `p`.
|
|
122
|
+
* @returns the request, or undefined when it does not name a squad and a member.
|
|
123
|
+
*/
|
|
124
|
+
export declare function parseSquadMemberRun(payload: Readonly<Record<string, unknown>>): SquadMemberRunRequest | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* Gate `squads.runSquad`'s payload.
|
|
127
|
+
* @param payload - the request's `p`.
|
|
128
|
+
* @returns the request, or undefined when it does not name a squad.
|
|
129
|
+
*/
|
|
130
|
+
export declare function parseSquadRun(payload: Readonly<Record<string, unknown>>): SquadRunRequest | undefined;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When a finished turn may be announced: after the session it belongs to falls
|
|
3
|
+
* quiet, not when the frame arrives.
|
|
4
|
+
*
|
|
5
|
+
* A `turn/end` increment is a fact about one turn and nothing more. The work the
|
|
6
|
+
* user started with it may still be going: the child sessions it delegated to and
|
|
7
|
+
* the background jobs the host still holds under those sessions outlive the turn
|
|
8
|
+
* that started them. A phone told "turn finished" at the frame wakes on a session
|
|
9
|
+
* the roster still badges as running, reads a card that says ended while the work
|
|
10
|
+
* goes on, and is told again by a second turn end it never asked for. §28's
|
|
11
|
+
* notification and §29's card answer the same question — "is this session working
|
|
12
|
+
* right now" — and that question has one answer, the one the client already
|
|
13
|
+
* computes in `SessionRun`: the host's own `agentRunning` for the session, any
|
|
14
|
+
* descendant session still running, and any job the host attributes to either.
|
|
15
|
+
*
|
|
16
|
+
* So a turn end is registered here instead of sent, and sent once the host says
|
|
17
|
+
* the session is quiet. Three rules hold that together:
|
|
18
|
+
*
|
|
19
|
+
* - the answer comes from the host and nowhere else: one `session/list` read for
|
|
20
|
+
* the running flag and the parent chain, and the host's job registry for the
|
|
21
|
+
* jobs it attributes to a session. This module invents no timer-based guess and
|
|
22
|
+
* reads no client state, because a guess that says "quiet" is a lock screen
|
|
23
|
+
* saying the work finished when it did not;
|
|
24
|
+
* - nothing on the frame path waits: a registration stores five fields and arms a
|
|
25
|
+
* timer, so a follow stream still publishes its increment at the speed it did
|
|
26
|
+
* before;
|
|
27
|
+
* - the wait is bounded. At {@link TURN_END_QUIET_MAX_MS} the announcement goes
|
|
28
|
+
* out anyway and the line it logs names what was still going, because a
|
|
29
|
+
* notification that never arrives is the failure this channel exists to prevent.
|
|
30
|
+
* @module dsh-remote-bridge/core/turn-end-quiet
|
|
31
|
+
*/
|
|
32
|
+
import type { JobRoster } from './jobs.ts';
|
|
33
|
+
import type { LiveActivityNotifier } from './liveactivity.ts';
|
|
34
|
+
import { type PushNotifier } from './push.ts';
|
|
35
|
+
import { type BridgeGateway, type GatewayPeer } from './wire.ts';
|
|
36
|
+
/** Longest a registered turn end waits for its session to fall quiet, in milliseconds. */
|
|
37
|
+
export declare const TURN_END_QUIET_MAX_MS = 600000;
|
|
38
|
+
/**
|
|
39
|
+
* How long a held turn end waits before asking the host again, in milliseconds.
|
|
40
|
+
*
|
|
41
|
+
* A turn end usually finds its session already quiet — the host clears the flag
|
|
42
|
+
* as the turn finishes — so the first question is the one that matters, and five
|
|
43
|
+
* seconds is short enough that the notification a user waits for is not visibly
|
|
44
|
+
* late. The interval is also what bounds how many questions one held turn end can
|
|
45
|
+
* cost: at most one every five seconds, never more than one in flight.
|
|
46
|
+
*/
|
|
47
|
+
export declare const TURN_END_QUIET_INTERVAL_MS = 5000;
|
|
48
|
+
/** The host's answer about the work one session still holds. */
|
|
49
|
+
export interface QuietAnswer {
|
|
50
|
+
/** Whether nothing under this session is still going. */
|
|
51
|
+
readonly quiet: boolean;
|
|
52
|
+
/** What was still going when it was not, in one token for the log line. */
|
|
53
|
+
readonly busy?: string;
|
|
54
|
+
}
|
|
55
|
+
/** Whether one session is quiet right now, as the host answers it. */
|
|
56
|
+
export type QuietProbe = (sessionId: string) => Promise<QuietAnswer>;
|
|
57
|
+
export interface TurnEndQuietOptions {
|
|
58
|
+
/** The notification path of §28; absent is a bridge that sends no notification. */
|
|
59
|
+
readonly push?: PushNotifier;
|
|
60
|
+
/** The card path of §29; absent for the same reason. */
|
|
61
|
+
readonly liveActivity?: LiveActivityNotifier;
|
|
62
|
+
/**
|
|
63
|
+
* The host's own answer, asked off the frame path.
|
|
64
|
+
*
|
|
65
|
+
* Absent is a bridge assembled without one, which cannot tell a quiet session
|
|
66
|
+
* from a busy one and therefore reports at the frame rather than holding
|
|
67
|
+
* anything back.
|
|
68
|
+
*/
|
|
69
|
+
readonly probe?: QuietProbe;
|
|
70
|
+
readonly now?: () => number;
|
|
71
|
+
readonly log?: (message: string) => void;
|
|
72
|
+
/** The wait budget; the default is {@link TURN_END_QUIET_MAX_MS}, and a deployment moves it. */
|
|
73
|
+
readonly maxWaitMs?: number;
|
|
74
|
+
/** The re-check interval; the default is {@link TURN_END_QUIET_INTERVAL_MS}. */
|
|
75
|
+
readonly intervalMs?: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The bridge's outbound turn-end path: registration now, announcement when quiet.
|
|
79
|
+
*
|
|
80
|
+
* Deliberately inert when neither channel can send: {@link enabled} is false, no
|
|
81
|
+
* entry is stored and no timer is armed, so a bridge without an Apple signing key
|
|
82
|
+
* behaves — byte for byte, frame for frame — exactly as it did before this module
|
|
83
|
+
* existed, and no host call is ever made on its behalf.
|
|
84
|
+
*/
|
|
85
|
+
export declare class TurnEndQuietGate {
|
|
86
|
+
#private;
|
|
87
|
+
constructor(options: TurnEndQuietOptions);
|
|
88
|
+
/** @returns whether either channel can send, which is the only case a turn end is held at all. */
|
|
89
|
+
get enabled(): boolean;
|
|
90
|
+
/** @returns how many turn ends are held right now. */
|
|
91
|
+
get held(): number;
|
|
92
|
+
/**
|
|
93
|
+
* Hold one finished turn until its session is quiet, then announce it.
|
|
94
|
+
*
|
|
95
|
+
* Returns at once and never awaits a host read: the caller is a follow stream
|
|
96
|
+
* that has already published its increment.
|
|
97
|
+
* @param sessionId - the session the turn belonged to.
|
|
98
|
+
* @param reason - the host's own reason for ending it.
|
|
99
|
+
*/
|
|
100
|
+
noteTurnEnd(sessionId: string, reason: string): void;
|
|
101
|
+
/**
|
|
102
|
+
* Drop a held turn end because another turn is on.
|
|
103
|
+
*
|
|
104
|
+
* A caller reports this from the evidence it actually has — an increment for the
|
|
105
|
+
* session that is not a turn end — so a turn the bridge cannot see costs the user
|
|
106
|
+
* nothing: the held end is still announced, and the turn that is really running
|
|
107
|
+
* ends with its own report.
|
|
108
|
+
* @param sessionId - the session that started working again.
|
|
109
|
+
*/
|
|
110
|
+
noteTurnStarted(sessionId: string): void;
|
|
111
|
+
/** Drop every held turn end and every timer. Idempotent. */
|
|
112
|
+
dispose(): void;
|
|
113
|
+
}
|
|
114
|
+
/** What {@link sessionQuietProbe} reads the host through. */
|
|
115
|
+
export interface SessionQuietProbeOptions {
|
|
116
|
+
/** The host's gateway, the same one every connection speaks through. */
|
|
117
|
+
readonly gateway: BridgeGateway;
|
|
118
|
+
/** The in-process owner peer every call of this bridge speaks for. */
|
|
119
|
+
readonly peer: GatewayPeer;
|
|
120
|
+
/** The host's job registry, read for the jobs it attributes to a session. */
|
|
121
|
+
readonly jobs: JobRoster;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The host's answer to "is this session quiet", built from its own two facts.
|
|
125
|
+
*
|
|
126
|
+
* The session list is where the running flag and the parent chain come from, and
|
|
127
|
+
* the job registry is where a job's owner and status come from; neither is
|
|
128
|
+
* captured once, because both move while a held turn end waits. A read that cannot
|
|
129
|
+
* be made is thrown rather than answered as quiet: "the host did not answer" and
|
|
130
|
+
* "nothing is running" are different facts, and the caller retries the one and
|
|
131
|
+
* announces the other.
|
|
132
|
+
* @param options - the faces the answer is read through.
|
|
133
|
+
* @returns the probe the gate asks.
|
|
134
|
+
*/
|
|
135
|
+
export declare function sessionQuietProbe(options: SessionQuietProbeOptions): QuietProbe;
|