@linxin666/dsh-remote-bridge 0.4.7 → 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 +93 -26
- package/README.zh.md +91 -26
- package/icon.svg +3 -0
- package/lib/client.js +274 -253
- package/lib/client.js.map +1 -1
- package/lib/index.js +8891 -2433
- 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/approvals.d.ts +24 -0
- package/lib/types/core/commands.d.ts +59 -0
- package/lib/types/core/connection.d.ts +124 -5
- package/lib/types/core/delta.d.ts +101 -0
- package/lib/types/core/devices.d.ts +98 -2
- package/lib/types/core/dsh-frames.d.ts +155 -4
- package/lib/types/core/envelope.d.ts +34 -0
- package/lib/types/core/extension.d.ts +144 -0
- package/lib/types/core/hub.d.ts +96 -20
- package/lib/types/core/jobs.d.ts +204 -0
- package/lib/types/core/liveactivity.d.ts +324 -0
- package/lib/types/core/protocol.d.ts +491 -2
- package/lib/types/core/push.d.ts +178 -0
- package/lib/types/core/questions.d.ts +109 -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/core/wire.d.ts +1 -1
- package/lib/types/core/ws-frames.d.ts +11 -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/host/websocket.d.ts +8 -1
- package/lib/types/index.d.ts +34 -3
- package/lib/types/mount-once.d.ts +55 -0
- package/locale/en.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +20 -14
- 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/approvals.ts +32 -1
- package/src/core/commands.ts +95 -0
- package/src/core/connection.ts +1483 -31
- package/src/core/delta.ts +204 -0
- package/src/core/devices.ts +221 -3
- package/src/core/dsh-frames.ts +365 -8
- package/src/core/envelope.ts +46 -0
- package/src/core/extension.ts +197 -0
- package/src/core/hub.ts +441 -49
- package/src/core/jobs.ts +372 -0
- package/src/core/liveactivity.ts +833 -0
- package/src/core/protocol.ts +556 -2
- package/src/core/push.ts +354 -0
- package/src/core/questions.ts +264 -17
- 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 +13 -1
- package/src/core/ws-frames.ts +14 -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/host/websocket.ts +37 -3
- package/src/index.ts +310 -9
- package/src/mount-once.ts +142 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bridge's read-only window on the host's background jobs: one minimal
|
|
3
|
+
* projection per job, and the change notification a phone's navigation bar
|
|
4
|
+
* needs to keep a count honest.
|
|
5
|
+
*
|
|
6
|
+
* There is exactly one source of truth here and it is the host's own job
|
|
7
|
+
* registry (`ctx.jobs`, the service the `dsh-api-job-controller` Remote
|
|
8
|
+
* namespace is itself a projection of). This module adds no second store, no
|
|
9
|
+
* polling loop and no invented status vocabulary: it reads `list()`, publishes
|
|
10
|
+
* the host's own `kind` and `status` strings verbatim, and hears changes from
|
|
11
|
+
* the registry's own event stream.
|
|
12
|
+
*
|
|
13
|
+
* Two shapes of the host's API matter to what a phone can be shown:
|
|
14
|
+
*
|
|
15
|
+
* - `list(caller)` is owner-fenced. Naming a session returns that session's own
|
|
16
|
+
* jobs plus every job no session owns; naming no session returns only the
|
|
17
|
+
* unowned jobs. Those are TWO truthful scopes, not one global view, and the
|
|
18
|
+
* host has no global view to offer: a job list is never "every job in the
|
|
19
|
+
* process" unless every job in the process happens to be unowned.
|
|
20
|
+
* - The event stream reports `output` appends as well as lifecycle commits. An
|
|
21
|
+
* append says nothing about the SET, so it is dropped here: this channel
|
|
22
|
+
* never publishes per output byte, which is the whole reason the roster is
|
|
23
|
+
* not a projection of `job/follow`.
|
|
24
|
+
*
|
|
25
|
+
* The types below mirror `@deepseek-ai/dsh-jobs` field for field. That package
|
|
26
|
+
* is the host's, not this one's, so the contract is declared structurally
|
|
27
|
+
* instead of imported — the same rule `questions.ts` and `wire.ts` follow, and
|
|
28
|
+
* what keeps a test double down to the two members actually called.
|
|
29
|
+
* @module dsh-remote-bridge/core/jobs
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* The slice of the host's `JobView` this bridge reads.
|
|
33
|
+
*
|
|
34
|
+
* Deliberately not the whole view: `output` (the ring's offsets and spill
|
|
35
|
+
* paths), `progress`, `detail` and `outputLimitBytes` are host bookkeeping a
|
|
36
|
+
* phone neither shows nor needs, and a projection that read them would tempt a
|
|
37
|
+
* later change into publishing bytes.
|
|
38
|
+
*/
|
|
39
|
+
export interface JobViewLike {
|
|
40
|
+
readonly id: string;
|
|
41
|
+
readonly kind: string;
|
|
42
|
+
readonly label: string;
|
|
43
|
+
/** Owning session; absent for an unowned job, which every caller can see. */
|
|
44
|
+
readonly owner?: string;
|
|
45
|
+
readonly status: string;
|
|
46
|
+
/** Epoch milliseconds. */
|
|
47
|
+
readonly startedAt: number;
|
|
48
|
+
/** Epoch milliseconds; absent while the job is live. */
|
|
49
|
+
readonly finishedAt?: number;
|
|
50
|
+
}
|
|
51
|
+
/** One lifecycle event of the host's event stream, as far as this bridge reads it. */
|
|
52
|
+
export interface JobEventLike {
|
|
53
|
+
/** `output` is the one type this bridge drops without reading further. */
|
|
54
|
+
readonly type: string;
|
|
55
|
+
/** The job's projection after the commit; absent on an `output` append. */
|
|
56
|
+
readonly job?: JobViewLike;
|
|
57
|
+
/** Owning session, carried by `output` events, which carry no projection. */
|
|
58
|
+
readonly owner?: string;
|
|
59
|
+
}
|
|
60
|
+
/** Who a subscription hears about. `all` is what a bridge serving every session asks for. */
|
|
61
|
+
export type JobEventFilterLike = {
|
|
62
|
+
readonly owners: 'all' | 'scope';
|
|
63
|
+
} | {
|
|
64
|
+
readonly owner: string;
|
|
65
|
+
};
|
|
66
|
+
/** The host registry's event stream. */
|
|
67
|
+
export interface JobEventsFace {
|
|
68
|
+
subscribe(filter: JobEventFilterLike, listener: (event: JobEventLike) => void): () => void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The slice of `ctx.jobs` this package reads.
|
|
72
|
+
*
|
|
73
|
+
* Optional in the plugin's faces for the reason the metadata faces are: the
|
|
74
|
+
* registry is not in this plugin's `inject` list, and a host that composes no
|
|
75
|
+
* job plugin answers `jobs-unavailable` instead of failing to start.
|
|
76
|
+
*/
|
|
77
|
+
export interface JobRegistryFace {
|
|
78
|
+
list(caller?: string): readonly JobViewLike[];
|
|
79
|
+
readonly events: JobEventsFace;
|
|
80
|
+
}
|
|
81
|
+
/** Which truthful scope one roster answer covers. */
|
|
82
|
+
export type JobScope = 'session' | 'unowned';
|
|
83
|
+
/**
|
|
84
|
+
* One job in protocol v1 vocabulary: the minimal, stable view.
|
|
85
|
+
*
|
|
86
|
+
* `kind` and `status` are the host's own strings, verbatim — this protocol
|
|
87
|
+
* publishes no enum of its own, so a producer kind or a lifecycle status added
|
|
88
|
+
* in the host crosses unchanged instead of being flattened into a guess.
|
|
89
|
+
* Every optional key is omitted when the host omitted it, never filled in.
|
|
90
|
+
*/
|
|
91
|
+
export interface JobRow {
|
|
92
|
+
readonly id: string;
|
|
93
|
+
readonly kind: string;
|
|
94
|
+
readonly status: string;
|
|
95
|
+
/** The host's `label`: its own one-line description, the field a phone renders as the job's title. */
|
|
96
|
+
readonly label?: string;
|
|
97
|
+
/** The host's `owner`, verbatim, under a name that cannot be read as an object. */
|
|
98
|
+
readonly ownerSessionId?: string;
|
|
99
|
+
readonly startedAt?: number;
|
|
100
|
+
readonly finishedAt?: number;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The body of one `jobs.list` answer and of one `jobs.changed` event.
|
|
104
|
+
*
|
|
105
|
+
* One box for both, so a client parses its navigation-bar count out of the same
|
|
106
|
+
* shape it refreshes through, and so a client holding two scopes open can tell
|
|
107
|
+
* whose set moved. `sessionId` is present exactly when the scope is `session`.
|
|
108
|
+
*/
|
|
109
|
+
export interface JobsPayload {
|
|
110
|
+
readonly sessionId?: string;
|
|
111
|
+
readonly scope: JobScope;
|
|
112
|
+
readonly jobs: readonly JobRow[];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Coalescing window of one roster publish, in milliseconds.
|
|
116
|
+
*
|
|
117
|
+
* The host registry announces every commit synchronously, so a job that
|
|
118
|
+
* registers, reports progress and settles in one turn is three events for one
|
|
119
|
+
* fact a phone renders as one row. This window folds a burst into a single
|
|
120
|
+
* whole-set read, which is why the topic can never turn into a stream of
|
|
121
|
+
* frames. It matches the job controller's own `observeFlushMs` default, so a
|
|
122
|
+
* browser and a phone watching the same set refresh at the same cadence.
|
|
123
|
+
*/
|
|
124
|
+
export declare const JOBS_FLUSH_MS = 100;
|
|
125
|
+
/** Largest number of job rows one payload carries before it risks the frame budget. */
|
|
126
|
+
export declare const JOBS_MAX_ROWS = 200;
|
|
127
|
+
/**
|
|
128
|
+
* Project one host job into the protocol's own fields.
|
|
129
|
+
*
|
|
130
|
+
* Explicitly field by field: an unknown key the host adds later must not reach
|
|
131
|
+
* the wire, and a value of the wrong type is dropped rather than coerced — the
|
|
132
|
+
* key is simply absent, which a client already has to handle.
|
|
133
|
+
* @param job - the host's projection.
|
|
134
|
+
* @returns the minimal row, or undefined when the host gave no usable id.
|
|
135
|
+
*/
|
|
136
|
+
export declare function projectJob(job: JobViewLike): JobRow | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* Project a whole host roster.
|
|
139
|
+
* @param jobs - the host's projections.
|
|
140
|
+
* @returns the rows, in the host's own order, bounded by {@link JOBS_MAX_ROWS}.
|
|
141
|
+
*/
|
|
142
|
+
export declare function projectJobs(jobs: readonly JobViewLike[]): readonly JobRow[];
|
|
143
|
+
/** The key one scope is subscribed and deduplicated under. */
|
|
144
|
+
export declare function scopeKey(sessionId?: string): string;
|
|
145
|
+
/**
|
|
146
|
+
* Whether one job belongs in one scope's visible set.
|
|
147
|
+
*
|
|
148
|
+
* This is the host's own fence, restated for routing events: a session sees its
|
|
149
|
+
* own jobs plus every unowned one, and the unowned scope sees exactly the jobs
|
|
150
|
+
* no session owns.
|
|
151
|
+
* @param owner - the job's owning session, when it has one.
|
|
152
|
+
* @param sessionId - the scope's session; omitted for the unowned scope.
|
|
153
|
+
*/
|
|
154
|
+
export declare function inScope(owner: string | undefined, sessionId?: string): boolean;
|
|
155
|
+
/** Everything one mount's roster was built with. */
|
|
156
|
+
export interface JobRosterOptions {
|
|
157
|
+
/** Resolves the host registry now; called per read, never captured once, so a registry that mounts later is still picked up. */
|
|
158
|
+
readonly faces: () => {
|
|
159
|
+
readonly jobs?: JobRegistryFace | undefined;
|
|
160
|
+
};
|
|
161
|
+
readonly log: (message: string) => void;
|
|
162
|
+
/** Coalescing window; the default is {@link JOBS_FLUSH_MS}. */
|
|
163
|
+
readonly flushMs?: number;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The bridge's background-job reads and change notifications.
|
|
167
|
+
*
|
|
168
|
+
* One instance is built per host mount and shared by every connection, because
|
|
169
|
+
* a job is a fact about the host, not about the device that asked. Scopes are
|
|
170
|
+
* reference-counted by their listeners: a scope nobody watches holds no timer,
|
|
171
|
+
* and the registry subscription itself exists only while at least one scope
|
|
172
|
+
* does. That is what makes "a connection that never asked receives nothing"
|
|
173
|
+
* structural rather than a filter someone has to remember to apply.
|
|
174
|
+
*/
|
|
175
|
+
export declare class JobRoster {
|
|
176
|
+
#private;
|
|
177
|
+
constructor(options: JobRosterOptions);
|
|
178
|
+
/** @returns whether this host composes a job registry at all. */
|
|
179
|
+
get available(): boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Read one scope's visible set.
|
|
182
|
+
*
|
|
183
|
+
* Synchronous, because the host registry projects in memory: no stream is
|
|
184
|
+
* opened and no socket is waited on, which is what makes this cheap enough to
|
|
185
|
+
* answer on request and again after every coalesced burst.
|
|
186
|
+
* @param sessionId - the scope's session; omitted for the unowned scope.
|
|
187
|
+
* @returns the payload, or undefined when this host has no job registry.
|
|
188
|
+
*/
|
|
189
|
+
read(sessionId?: string): JobsPayload | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* Watch one scope, and publish each coalesced change to every watcher of it.
|
|
192
|
+
*
|
|
193
|
+
* Watching is what a `jobs.list` call earns: a scope nobody listed is never
|
|
194
|
+
* read again, so a phone that declared the capability and asked for nothing
|
|
195
|
+
* receives no `jobs.changed` — the requirement that keeps N open sessions
|
|
196
|
+
* from becoming N sets streaming at a phone that asked for none.
|
|
197
|
+
* @param sessionId - the scope's session; omitted for the unowned scope.
|
|
198
|
+
* @param listener - receives one whole-set payload per coalesced change.
|
|
199
|
+
* @returns the disposer, or undefined when this host has no job registry.
|
|
200
|
+
*/
|
|
201
|
+
watch(sessionId: string | undefined, listener: (payload: JobsPayload) => void): (() => void) | undefined;
|
|
202
|
+
/** Stop every watch and clear every timer. Idempotent. */
|
|
203
|
+
dispose(): void;
|
|
204
|
+
}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Live Activity half of the push channel (protocol §29).
|
|
3
|
+
*
|
|
4
|
+
* The alert channel in `core/push.ts` tells a phone something happened; a Live
|
|
5
|
+
* Activity is the lock-screen card that keeps being right while the app is
|
|
6
|
+
* suspended, which is why it is a second payload with its own rules rather than
|
|
7
|
+
* a field on the first one:
|
|
8
|
+
*
|
|
9
|
+
* - the request is a `liveactivity` push to a per-card APNs token, under the app
|
|
10
|
+
* bundle's `.push-type.liveactivity` topic, with `apns-expiration: 0` — a card
|
|
11
|
+
* update that arrives late is a lie about the present, so it is never resent;
|
|
12
|
+
* - `content-state` is the App's own `SessionActivityState`, decoded with
|
|
13
|
+
* ActivityKit's default Codable strategy. Timestamps in it are seconds since
|
|
14
|
+
* Apple's reference date (2001-01-01T00:00:00Z), never Unix seconds: a Unix
|
|
15
|
+
* number decodes as a date decades away and the whole card fails to decode;
|
|
16
|
+
* - one card shows one session. A registered card names its session, a card
|
|
17
|
+
* without one is never pushed to, and a state is delivered to the cards whose
|
|
18
|
+
* session it is about — never to "all cards", because that is how one session's
|
|
19
|
+
* question ends up on another session's lock screen (§29.9). `runningCount` is
|
|
20
|
+
* the one bridge-wide number on a card, and it stays the total on purpose;
|
|
21
|
+
* - one card lays out at most three rows (§30). The address is still one session
|
|
22
|
+
* per card — rows say what that card has to tell, not who it is sent to — and
|
|
23
|
+
* every card is given them the same way: the sessions waiting on the user
|
|
24
|
+
* first, in the order their questions arrived, then the sessions running now,
|
|
25
|
+
* most recently updated first. A row's name is the host's own title with its
|
|
26
|
+
* trailing path group taken off, because §29.5 keeps paths off a lock screen;
|
|
27
|
+
* - a card that would say what the card before it already said is not sent, one
|
|
28
|
+
* activity takes at most one update per `LIVE_ACTIVITY_INTERVAL_MS`, and
|
|
29
|
+
* the whole bridge at most `LIVE_ACTIVITY_PER_MINUTE` a minute. What does
|
|
30
|
+
* not fit is dropped, never queued: a card is a snapshot of now, and a backlog
|
|
31
|
+
* of stale snapshots is exactly what this channel must not deliver.
|
|
32
|
+
*
|
|
33
|
+
* Nothing here is awaited by a frame path. Every entry point returns before a
|
|
34
|
+
* delivery starts, and a failure — connection, 401, 410, 5xx, timeout — is one
|
|
35
|
+
* log line and a dropped card, never a delayed or broken follow stream (§28.5).
|
|
36
|
+
* @module dsh-remote-bridge/core/liveactivity
|
|
37
|
+
*/
|
|
38
|
+
import type { PushSendResult } from './push.ts';
|
|
39
|
+
/** The phases a lock-screen card can report. */
|
|
40
|
+
export type SessionActivityPhase = 'running' | 'waitingForAnswer' | 'failed' | 'ended';
|
|
41
|
+
/** The two events one Live Activity push carries. */
|
|
42
|
+
export type LiveActivityEvent = 'update' | 'end';
|
|
43
|
+
/**
|
|
44
|
+
* Seconds from 1970-01-01T00:00:00Z to Apple's reference date, 2001-01-01T00:00:00Z.
|
|
45
|
+
*
|
|
46
|
+
* ActivityKit encodes a `Date` as a double relative to that reference date, so a
|
|
47
|
+
* value meant to decode as "now" is Unix seconds minus this offset.
|
|
48
|
+
*/
|
|
49
|
+
export declare const APPLE_REFERENCE_OFFSET_SECONDS = 978307200;
|
|
50
|
+
/** How long after delivery iOS may still treat a card as current. */
|
|
51
|
+
export declare const LIVE_ACTIVITY_STALE_SECONDS = 90;
|
|
52
|
+
/** Shortest gap between two updates of the same activity. */
|
|
53
|
+
export declare const LIVE_ACTIVITY_INTERVAL_MS = 5000;
|
|
54
|
+
/** Most Live Activity pushes this bridge sends in any rolling minute. */
|
|
55
|
+
export declare const LIVE_ACTIVITY_PER_MINUTE = 30;
|
|
56
|
+
/** Longest option list a card carries; the App shows them as the answer choices. */
|
|
57
|
+
export declare const LIVE_ACTIVITY_OPTION_LIMIT = 2;
|
|
58
|
+
/** Most rows one card lays out; a fourth is dropped, never wrapped or paged (§30.2). */
|
|
59
|
+
export declare const LIVE_ACTIVITY_ROW_LIMIT = 3;
|
|
60
|
+
/**
|
|
61
|
+
* Longest row name a card carries, in characters.
|
|
62
|
+
*
|
|
63
|
+
* A row is one line under a status phrase, so a name longer than this is cut
|
|
64
|
+
* rather than allowed to push the rest of the card off the glass.
|
|
65
|
+
*/
|
|
66
|
+
export declare const LIVE_ACTIVITY_ROW_NAME_MAX = 48;
|
|
67
|
+
/** Activity ids whose last content is remembered before the oldest is forgotten. */
|
|
68
|
+
export declare const LIVE_ACTIVITY_TRACKED = 64;
|
|
69
|
+
/**
|
|
70
|
+
* The one line a card shows per phase, in the App's own words.
|
|
71
|
+
*
|
|
72
|
+
* Fixed English strings, one per phase, and the same table the App renders
|
|
73
|
+
* (§29.7, §30.2): the words on the glass are the client's, so a bridge that sent
|
|
74
|
+
* its own would put a second language on the same card. Fixed for the second
|
|
75
|
+
* reason the alert channel's bodies are fixed too — a line built out of host text
|
|
76
|
+
* is session content on a lock screen. `core/push.ts` keeps its own localized
|
|
77
|
+
* bodies: a notification is read in the user's language, a card is the App's, and
|
|
78
|
+
* both are the same event said for two different surfaces.
|
|
79
|
+
*/
|
|
80
|
+
export declare const ACTIVITY_STATUS_LINE: {
|
|
81
|
+
readonly running: "Running";
|
|
82
|
+
readonly waitingForAnswer: "Waiting for your answer";
|
|
83
|
+
readonly failed: "Stopped";
|
|
84
|
+
readonly ended: "Turn finished";
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* The fixed line one phase shows.
|
|
88
|
+
*
|
|
89
|
+
* The one accessor the single-session field and a row both go through, so a
|
|
90
|
+
* phase cannot be named two ways on one card.
|
|
91
|
+
* @param phase - the phase whose line is wanted.
|
|
92
|
+
* @returns the App's own English phrase for it.
|
|
93
|
+
*/
|
|
94
|
+
export declare function statusLineOf(phase: SessionActivityPhase): string;
|
|
95
|
+
/**
|
|
96
|
+
* One row of the multi-session card (§30.2).
|
|
97
|
+
*
|
|
98
|
+
* Exactly three keys, all non-empty: the host's own name for the session, the
|
|
99
|
+
* same status phrase that session's own card would carry, and its phase. There
|
|
100
|
+
* is no id, no url and no count — a row is a line on a card, not a record.
|
|
101
|
+
*
|
|
102
|
+
* A row only ever carries one of the two live phases: a failed or ended turn is
|
|
103
|
+
* the card's own `phase`, and repeating it as a row would say one thing twice
|
|
104
|
+
* on a card that is already on its way out.
|
|
105
|
+
*/
|
|
106
|
+
export interface ActivityRow {
|
|
107
|
+
readonly name: string;
|
|
108
|
+
readonly status: string;
|
|
109
|
+
readonly phase: SessionActivityPhase;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* One card's state, as the App's own `SessionActivityState` decodes it.
|
|
113
|
+
*
|
|
114
|
+
* The key set is frozen (§29): no field may be added or renamed, because the
|
|
115
|
+
* App's Codable type is the other half of this contract and a key it does not
|
|
116
|
+
* declare fails the whole decode.
|
|
117
|
+
*/
|
|
118
|
+
export interface SessionActivityState {
|
|
119
|
+
readonly phase: SessionActivityPhase;
|
|
120
|
+
readonly statusLine: string;
|
|
121
|
+
readonly questionHeader?: string;
|
|
122
|
+
readonly optionLabels?: readonly string[];
|
|
123
|
+
/** Apple-reference-date seconds of the moment this bridge delivered the card. */
|
|
124
|
+
readonly asOf: number;
|
|
125
|
+
/** Sessions running right now across the whole bridge, never below 1. */
|
|
126
|
+
readonly runningCount: number;
|
|
127
|
+
/**
|
|
128
|
+
* The sessions this card lays out, most urgent first, at most
|
|
129
|
+
* {@link LIVE_ACTIVITY_ROW_LIMIT} of them (§30). Absent and empty mean the
|
|
130
|
+
* same thing to the App: it lays out one row out of the single-session keys.
|
|
131
|
+
*/
|
|
132
|
+
readonly rows?: readonly ActivityRow[];
|
|
133
|
+
}
|
|
134
|
+
/** The request body one Live Activity delivery carries (protocol §29). */
|
|
135
|
+
export interface LiveActivityNotification {
|
|
136
|
+
readonly aps: {
|
|
137
|
+
/** Unix epoch seconds of the delivery. */
|
|
138
|
+
readonly timestamp: number;
|
|
139
|
+
readonly event: LiveActivityEvent;
|
|
140
|
+
readonly 'content-state': SessionActivityState;
|
|
141
|
+
/** Unix epoch seconds after which the card is stale: the delivery plus 90. */
|
|
142
|
+
readonly 'stale-date': number;
|
|
143
|
+
readonly 'relevance-score': number;
|
|
144
|
+
/** Only an `end` for a card whose session left the roster dismisses at once. */
|
|
145
|
+
readonly 'dismissal-date'?: number;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/** What the projection of one delivery says, before it is dated. */
|
|
149
|
+
export interface LiveActivityStateInput {
|
|
150
|
+
readonly event: LiveActivityEvent;
|
|
151
|
+
readonly phase: SessionActivityPhase;
|
|
152
|
+
readonly statusLine: string;
|
|
153
|
+
readonly questionHeader?: string;
|
|
154
|
+
readonly optionLabels?: readonly string[];
|
|
155
|
+
readonly runningCount: number;
|
|
156
|
+
/** The rows this card lays out, already chosen, ordered and capped by the notifier. */
|
|
157
|
+
readonly rows?: readonly ActivityRow[];
|
|
158
|
+
/** Delivery moment, in milliseconds since the Unix epoch. */
|
|
159
|
+
readonly now: number;
|
|
160
|
+
/** Dismiss the card the moment it is delivered, instead of letting it expire. */
|
|
161
|
+
readonly dismiss?: boolean;
|
|
162
|
+
}
|
|
163
|
+
/** @returns the score iOS ranks one card of this phase by. */
|
|
164
|
+
export declare function relevanceScoreOf(phase: SessionActivityPhase): number;
|
|
165
|
+
/**
|
|
166
|
+
* The push one card gets.
|
|
167
|
+
*
|
|
168
|
+
* Pure, and exported so the shape can be asserted without a sender: the headers
|
|
169
|
+
* and this key set are the contract, and every value derived from the delivery
|
|
170
|
+
* moment is derived here, once.
|
|
171
|
+
* @param input - the projection and the delivery moment.
|
|
172
|
+
* @returns the exact body an APNs Live Activity delivery carries.
|
|
173
|
+
*/
|
|
174
|
+
export declare function buildLiveActivityNotification(input: LiveActivityStateInput): LiveActivityNotification;
|
|
175
|
+
/** One card this bridge may push to. */
|
|
176
|
+
export interface LiveActivityAddress {
|
|
177
|
+
/** The activity the App created; stable for the life of one card. */
|
|
178
|
+
readonly activityId: string;
|
|
179
|
+
/** The per-card APNs token, which is not the device's token. */
|
|
180
|
+
readonly token: string;
|
|
181
|
+
/**
|
|
182
|
+
* The session this card shows. Absent is a card this bridge never pushes to:
|
|
183
|
+
* it has no state to put on it, and borrowing another session's state is
|
|
184
|
+
* exactly what §29.9 forbids.
|
|
185
|
+
*/
|
|
186
|
+
readonly sessionId?: string;
|
|
187
|
+
readonly environment: 'sandbox' | 'production';
|
|
188
|
+
/** The app bundle id; the topic is this bundle plus the Live Activity suffix. */
|
|
189
|
+
readonly bundle: string;
|
|
190
|
+
}
|
|
191
|
+
/** Whatever actually reaches a card; the APNs client implements this. */
|
|
192
|
+
export interface LiveActivitySender {
|
|
193
|
+
sendLiveActivity(target: LiveActivityAddress, notification: LiveActivityNotification): Promise<PushSendResult>;
|
|
194
|
+
}
|
|
195
|
+
/** One row of a roster this bridge just served, as the projection reads it. */
|
|
196
|
+
export interface ActivityRosterRow {
|
|
197
|
+
readonly id: string;
|
|
198
|
+
readonly agentRunning?: boolean;
|
|
199
|
+
/** The host's own title for that session, the name a row carries (§26, §30.2). */
|
|
200
|
+
readonly title?: string;
|
|
201
|
+
/** When the host last updated the session, in milliseconds; 0 when it names none. */
|
|
202
|
+
readonly updatedAt?: number;
|
|
203
|
+
}
|
|
204
|
+
export interface LiveActivityNotifierOptions {
|
|
205
|
+
/** The cards that are alive right now, read per delivery. */
|
|
206
|
+
readonly targets: () => readonly LiveActivityAddress[];
|
|
207
|
+
/** The sender; absent is a bridge with no signing key, and then nothing happens. */
|
|
208
|
+
readonly sender?: LiveActivitySender;
|
|
209
|
+
readonly now?: () => number;
|
|
210
|
+
readonly log?: (message: string) => void;
|
|
211
|
+
/**
|
|
212
|
+
* Forget a token APNs reported dead. The roster owner removes it from the
|
|
213
|
+
* device row and persists, so a token that can never work again is not retried
|
|
214
|
+
* on every later card (§29 token lifecycle).
|
|
215
|
+
*/
|
|
216
|
+
readonly retire?: (activityId: string, token: string) => Promise<boolean> | boolean | void;
|
|
217
|
+
readonly intervalMs?: number;
|
|
218
|
+
readonly perMinute?: number;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* The bridge's Live Activity path.
|
|
222
|
+
*
|
|
223
|
+
* Deliberately inert when no sender is configured: `enabled` is false, no
|
|
224
|
+
* card is ever read and no clock is consulted, so a bridge without an Apple key
|
|
225
|
+
* behaves — byte for byte, frame for frame — exactly as it did before this
|
|
226
|
+
* channel existed, and `push.register` still answers the same acknowledgement
|
|
227
|
+
* (§28.3: registering is one thing, sending is another).
|
|
228
|
+
*/
|
|
229
|
+
export declare class LiveActivityNotifier {
|
|
230
|
+
#private;
|
|
231
|
+
constructor(options: LiveActivityNotifierOptions);
|
|
232
|
+
/** @returns whether this bridge will actually deliver anything. */
|
|
233
|
+
get enabled(): boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Take the roster this bridge just served as the current picture of what runs.
|
|
236
|
+
*
|
|
237
|
+
* A listing is the only place this bridge learns which sessions are live, so it
|
|
238
|
+
* is where each running session's own card is refreshed: that session's card is
|
|
239
|
+
* told it is running, and the number beside it is how many sessions are running
|
|
240
|
+
* in total. A card waiting on the user keeps that state — listing sessions is
|
|
241
|
+
* not an answer, and downgrading the card would hide the question still owed.
|
|
242
|
+
* @param rows - the roster rows, as this connection built them.
|
|
243
|
+
*/
|
|
244
|
+
noteRoster(rows: readonly ActivityRosterRow[]): void;
|
|
245
|
+
/**
|
|
246
|
+
* Report one turn that ended.
|
|
247
|
+
*
|
|
248
|
+
* Only that session's own card is affected: the session stops running, its
|
|
249
|
+
* pending question is gone with the turn, and its card is ended — not updated —
|
|
250
|
+
* because the turn it was about is over. A session that was listed before and
|
|
251
|
+
* is not in the roster any more has left it, so its card is dismissed on
|
|
252
|
+
* delivery instead of being left on a lock screen to describe a session that no
|
|
253
|
+
* longer exists.
|
|
254
|
+
* @param sessionId - the session whose turn ended.
|
|
255
|
+
* @param reason - the host's own reason, read exactly as the alert channel reads it.
|
|
256
|
+
*/
|
|
257
|
+
noteTurnEnd(sessionId: string, reason: string): void;
|
|
258
|
+
/**
|
|
259
|
+
* Report a question that reached a phone and is now waiting for an answer.
|
|
260
|
+
*
|
|
261
|
+
* Only the header and at most two option labels cross: they are the choices the
|
|
262
|
+
* App can offer. The question itself and its detail stay behind the wire, the
|
|
263
|
+
* same rule the alert channel follows (§28.4), and only this session's card is
|
|
264
|
+
* told — another session's card has no business showing this question (§29.9).
|
|
265
|
+
* @param sessionId - the session that asked.
|
|
266
|
+
* @param question - the first question of the claimed batch.
|
|
267
|
+
*/
|
|
268
|
+
noteQuestion(sessionId: string, question: {
|
|
269
|
+
readonly header?: string;
|
|
270
|
+
readonly optionLabels?: readonly string[];
|
|
271
|
+
}): void;
|
|
272
|
+
/**
|
|
273
|
+
* Report an approval that reached a phone and is blocking the agent.
|
|
274
|
+
*
|
|
275
|
+
* The card says what state that session is in and nothing more: an approval's
|
|
276
|
+
* own summary is a tool's reason text, which is exactly the session content a
|
|
277
|
+
* lock screen must not carry, so it gets the fixed line and no details.
|
|
278
|
+
* @param sessionId - the session whose tool is blocked.
|
|
279
|
+
*/
|
|
280
|
+
noteApproval(sessionId: string): void;
|
|
281
|
+
/**
|
|
282
|
+
* Report that the question one card was waiting on is gone — answered here, on
|
|
283
|
+
* the desktop, or expired.
|
|
284
|
+
*
|
|
285
|
+
* A card left saying "waiting for an answer" after the answer landed is the one
|
|
286
|
+
* lie a lock screen cannot afford, so that session's card goes back to whatever
|
|
287
|
+
* is true now. Nothing is sent when that session is not known to run: there is
|
|
288
|
+
* no fact to show, and the ended card already covers that case.
|
|
289
|
+
* @param sessionId - the session whose claim settled.
|
|
290
|
+
*/
|
|
291
|
+
noteSettled(sessionId: string): void;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* What identifies a content state for the dedupe.
|
|
295
|
+
*
|
|
296
|
+
* `asOf` is left out on purpose: it is the delivery moment, so it differs on
|
|
297
|
+
* every build, and including it would make "the same content was sent" impossible
|
|
298
|
+
* to observe — a card is a duplicate exactly when everything a user can read on
|
|
299
|
+
* it is unchanged. The rows are part of what a user reads (§30), so a card whose
|
|
300
|
+
* list of sessions reordered, was renamed or lost a row says something new.
|
|
301
|
+
* @param state - the content state of one delivery.
|
|
302
|
+
* @returns a stable key for the readable part of it.
|
|
303
|
+
*/
|
|
304
|
+
export declare function contentKeyOf(state: SessionActivityState): string;
|
|
305
|
+
/**
|
|
306
|
+
* The host's own title, as one row may carry it (§30.2).
|
|
307
|
+
*
|
|
308
|
+
* The same rule the App applies to a card's own name
|
|
309
|
+
* (`SessionActivityDisplayName`), so one card cannot show two versions of one
|
|
310
|
+
* name. A roster title is usually the session's first message, and those end on
|
|
311
|
+
* the absolute path the session ran in — `你是本仓 (/Users/zcl/code/x)` — while
|
|
312
|
+
* §29.5 keeps paths off a lock screen. A trailing group whose body is a path or
|
|
313
|
+
* nothing therefore comes off, brackets included, and whatever it exposed is
|
|
314
|
+
* cleaned up after it (the separator in front of it, the bracket of the group
|
|
315
|
+
* before it). A group that is part of the name, `Ship (main)`, stays. What is
|
|
316
|
+
* left is whitespace-collapsed, trimmed of the separators and dangling brackets
|
|
317
|
+
* its tail may hang on, and cut to {@link LIVE_ACTIVITY_ROW_NAME_MAX}.
|
|
318
|
+
*
|
|
319
|
+
* The rule lives here and nowhere else in this bridge, so there is one answer to
|
|
320
|
+
* "which words of a host title may reach a lock screen".
|
|
321
|
+
* @param title - the title the roster carried for that session, possibly empty.
|
|
322
|
+
* @returns a name a row can carry, and an empty string when the title held nothing else.
|
|
323
|
+
*/
|
|
324
|
+
export declare function normalizeActivityRowName(title: string): string;
|