driverkit 0.0.0-stage → 0.0.1

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 (160) hide show
  1. package/CONTROLS.md +578 -0
  2. package/REACT.md +477 -0
  3. package/README.md +104 -2
  4. package/dist/agent/backend.d.ts +69 -0
  5. package/dist/agent/backend.d.ts.map +1 -0
  6. package/dist/agent/backend.js +130 -0
  7. package/dist/agent/backend.js.map +1 -0
  8. package/dist/agent/control.d.ts +148 -0
  9. package/dist/agent/control.d.ts.map +1 -0
  10. package/dist/agent/control.js +342 -0
  11. package/dist/agent/control.js.map +1 -0
  12. package/dist/agent/index.d.ts +9 -0
  13. package/dist/agent/index.d.ts.map +1 -0
  14. package/dist/agent/index.js +6 -0
  15. package/dist/agent/index.js.map +1 -0
  16. package/dist/agent/loop.d.ts +136 -0
  17. package/dist/agent/loop.d.ts.map +1 -0
  18. package/dist/agent/loop.js +824 -0
  19. package/dist/agent/loop.js.map +1 -0
  20. package/dist/agent/render.d.ts +173 -0
  21. package/dist/agent/render.d.ts.map +1 -0
  22. package/dist/agent/render.js +425 -0
  23. package/dist/agent/render.js.map +1 -0
  24. package/dist/agent/tools.d.ts +138 -0
  25. package/dist/agent/tools.d.ts.map +1 -0
  26. package/dist/agent/tools.js +622 -0
  27. package/dist/agent/tools.js.map +1 -0
  28. package/dist/agent/types.d.ts +566 -0
  29. package/dist/agent/types.d.ts.map +1 -0
  30. package/dist/agent/types.js +32 -0
  31. package/dist/agent/types.js.map +1 -0
  32. package/dist/browser/budget.d.ts +92 -0
  33. package/dist/browser/budget.d.ts.map +1 -0
  34. package/dist/browser/budget.js +151 -0
  35. package/dist/browser/budget.js.map +1 -0
  36. package/dist/browser/connect.d.ts +368 -0
  37. package/dist/browser/connect.d.ts.map +1 -0
  38. package/dist/browser/connect.js +1038 -0
  39. package/dist/browser/connect.js.map +1 -0
  40. package/dist/browser/elsewhere.d.ts +89 -0
  41. package/dist/browser/elsewhere.d.ts.map +1 -0
  42. package/dist/browser/elsewhere.js +91 -0
  43. package/dist/browser/elsewhere.js.map +1 -0
  44. package/dist/browser/frames.d.ts +85 -0
  45. package/dist/browser/frames.d.ts.map +1 -0
  46. package/dist/browser/frames.js +11 -0
  47. package/dist/browser/frames.js.map +1 -0
  48. package/dist/browser/index.d.ts +8 -0
  49. package/dist/browser/index.d.ts.map +1 -0
  50. package/dist/browser/index.js +9 -0
  51. package/dist/browser/index.js.map +1 -0
  52. package/dist/check/check.d.ts +171 -0
  53. package/dist/check/check.d.ts.map +1 -0
  54. package/dist/check/check.js +666 -0
  55. package/dist/check/check.js.map +1 -0
  56. package/dist/check/index.d.ts +3 -0
  57. package/dist/check/index.d.ts.map +1 -0
  58. package/dist/check/index.js +2 -0
  59. package/dist/check/index.js.map +1 -0
  60. package/dist/check/types.d.ts +149 -0
  61. package/dist/check/types.d.ts.map +1 -0
  62. package/dist/check/types.js +29 -0
  63. package/dist/check/types.js.map +1 -0
  64. package/dist/controls/controls.d.ts +198 -0
  65. package/dist/controls/controls.d.ts.map +1 -0
  66. package/dist/controls/controls.js +742 -0
  67. package/dist/controls/controls.js.map +1 -0
  68. package/dist/controls/dom.d.ts +108 -0
  69. package/dist/controls/dom.d.ts.map +1 -0
  70. package/dist/controls/dom.js +56 -0
  71. package/dist/controls/dom.js.map +1 -0
  72. package/dist/controls/index.d.ts +26 -0
  73. package/dist/controls/index.d.ts.map +1 -0
  74. package/dist/controls/index.js +23 -0
  75. package/dist/controls/index.js.map +1 -0
  76. package/dist/controls/rows.d.ts +66 -0
  77. package/dist/controls/rows.d.ts.map +1 -0
  78. package/dist/controls/rows.js +127 -0
  79. package/dist/controls/rows.js.map +1 -0
  80. package/dist/core/index.d.ts +3 -0
  81. package/dist/core/index.d.ts.map +1 -0
  82. package/dist/core/index.js +15 -0
  83. package/dist/core/index.js.map +1 -0
  84. package/dist/core/registry.d.ts +192 -0
  85. package/dist/core/registry.d.ts.map +1 -0
  86. package/dist/core/registry.js +2799 -0
  87. package/dist/core/registry.js.map +1 -0
  88. package/dist/core/types.d.ts +2468 -0
  89. package/dist/core/types.d.ts.map +1 -0
  90. package/dist/core/types.js +19 -0
  91. package/dist/core/types.js.map +1 -0
  92. package/dist/otel/index.d.ts +122 -0
  93. package/dist/otel/index.d.ts.map +1 -0
  94. package/dist/otel/index.js +157 -0
  95. package/dist/otel/index.js.map +1 -0
  96. package/dist/react/index.d.ts +191 -0
  97. package/dist/react/index.d.ts.map +1 -0
  98. package/dist/react/index.js +547 -0
  99. package/dist/react/index.js.map +1 -0
  100. package/dist/react/runtime.d.ts +95 -0
  101. package/dist/react/runtime.d.ts.map +1 -0
  102. package/dist/react/runtime.js +54 -0
  103. package/dist/react/runtime.js.map +1 -0
  104. package/dist/react/store.d.ts +333 -0
  105. package/dist/react/store.d.ts.map +1 -0
  106. package/dist/react/store.js +695 -0
  107. package/dist/react/store.js.map +1 -0
  108. package/dist/relay/auth.d.ts +244 -0
  109. package/dist/relay/auth.d.ts.map +1 -0
  110. package/dist/relay/auth.js +391 -0
  111. package/dist/relay/auth.js.map +1 -0
  112. package/dist/relay/frames.d.ts +141 -0
  113. package/dist/relay/frames.d.ts.map +1 -0
  114. package/dist/relay/frames.js +20 -0
  115. package/dist/relay/frames.js.map +1 -0
  116. package/dist/relay/index.d.ts +8 -0
  117. package/dist/relay/index.d.ts.map +1 -0
  118. package/dist/relay/index.js +4 -0
  119. package/dist/relay/index.js.map +1 -0
  120. package/dist/relay/relay.d.ts +277 -0
  121. package/dist/relay/relay.d.ts.map +1 -0
  122. package/dist/relay/relay.js +1026 -0
  123. package/dist/relay/relay.js.map +1 -0
  124. package/dist/relay/serve.d.ts +33 -0
  125. package/dist/relay/serve.d.ts.map +1 -0
  126. package/dist/relay/serve.js +86 -0
  127. package/dist/relay/serve.js.map +1 -0
  128. package/dist/widget/chat.d.ts +290 -0
  129. package/dist/widget/chat.d.ts.map +1 -0
  130. package/dist/widget/chat.js +486 -0
  131. package/dist/widget/chat.js.map +1 -0
  132. package/dist/widget/css.d.ts +49 -0
  133. package/dist/widget/css.d.ts.map +1 -0
  134. package/dist/widget/css.js +532 -0
  135. package/dist/widget/css.js.map +1 -0
  136. package/dist/widget/dom.d.ts +143 -0
  137. package/dist/widget/dom.d.ts.map +1 -0
  138. package/dist/widget/dom.js +27 -0
  139. package/dist/widget/dom.js.map +1 -0
  140. package/dist/widget/highlight.d.ts +64 -0
  141. package/dist/widget/highlight.d.ts.map +1 -0
  142. package/dist/widget/highlight.js +136 -0
  143. package/dist/widget/highlight.js.map +1 -0
  144. package/dist/widget/index.d.ts +9 -0
  145. package/dist/widget/index.d.ts.map +1 -0
  146. package/dist/widget/index.js +20 -0
  147. package/dist/widget/index.js.map +1 -0
  148. package/dist/widget/position.d.ts +166 -0
  149. package/dist/widget/position.d.ts.map +1 -0
  150. package/dist/widget/position.js +497 -0
  151. package/dist/widget/position.js.map +1 -0
  152. package/dist/widget/settings.d.ts +116 -0
  153. package/dist/widget/settings.d.ts.map +1 -0
  154. package/dist/widget/settings.js +117 -0
  155. package/dist/widget/settings.js.map +1 -0
  156. package/dist/widget/widget.d.ts +442 -0
  157. package/dist/widget/widget.d.ts.map +1 -0
  158. package/dist/widget/widget.js +2005 -0
  159. package/dist/widget/widget.js.map +1 -0
  160. package/package.json +144 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/relay/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvE,YAAY,EACV,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAC3D,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,GACrE,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,OAAO,EACP,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,YAAY,GACb,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { createRelay } from "./relay.js";
2
+ export { TabAuth, AuthError, anonPrincipalId, mintAnonCredential, credentialFrom, ANON_ID_PREFIX, ANON_PREFIX, LOCAL_PRINCIPAL, MIN_SECRET_BYTES, TOKEN_PREFIX, } from "./auth.js";
3
+ export { serve } from "./serve.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/relay/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAMzC,OAAO,EACL,OAAO,EACP,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,YAAY,GACb,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { createRelay } from \"./relay.ts\";\nexport type { Relay, RelayOptions, RelayAuditEvent } from \"./relay.ts\";\nexport type {\n CallFrame, DownFrame, HelloFrame, RelayRefusal, ResultFrame,\n SnapshotFrame, TabFocus, TabSummary, UpFrame, WatchFrame, WireResult,\n} from \"./frames.ts\";\nexport {\n TabAuth,\n AuthError,\n anonPrincipalId,\n mintAnonCredential,\n credentialFrom,\n ANON_ID_PREFIX,\n ANON_PREFIX,\n LOCAL_PRINCIPAL,\n MIN_SECRET_BYTES,\n TOKEN_PREFIX,\n} from \"./auth.ts\";\nexport type { Principal, TabAuthOptions } from \"./auth.ts\";\nexport { serve } from \"./serve.ts\";\nexport type { ServeOptions } from \"./serve.ts\";\n"]}
@@ -0,0 +1,277 @@
1
+ /**
2
+ * driverkit/relay — the one place both parties can reach.
3
+ *
4
+ * Nothing can call into a browser tab, so the tab dials out and holds a stream
5
+ * open; the agent speaks ordinary request/response HTTP. The relay's whole job
6
+ * is to turn one into the other: a `POST /dk/tabs/:tab/call` blocks on an open
7
+ * promise until a `result` frame with the matching `id` arrives on a separate
8
+ * POST from that tab, and then answers with it.
9
+ *
10
+ * Two properties are worth stating before the code, because both are easy to
11
+ * break with a change that looks like a cleanup:
12
+ *
13
+ * THE RELAY GRANTS NO AUTHORITY. It forwards a verb name to a tab that is
14
+ * already logged in as a person. It never decides whether a call is allowed,
15
+ * never rewrites args, never interprets `rev`. Every refusal it originates
16
+ * is about reachability -- "no tab", "the tab went away", "the tab never
17
+ * answered" -- and never about the verb. The moment the relay has an opinion
18
+ * about a verb, there are two sets of rules and one of them is wrong.
19
+ *
20
+ * EVERY ANSWER IS A `WireResult`, AND THE BODY IS AUTHORITATIVE. An agent
21
+ * asking for a call gets the same shape at 200 whether the tab refused, the
22
+ * tab vanished, or the tab id was a typo. A 4xx here would conflate a
23
+ * transport failure with a business rule, and those want opposite handling:
24
+ * one is retry-elsewhere, the other is rephrase-and-retry. So a non-2xx from
25
+ * this relay means no `WireResult` was produced at all -- malformed body,
26
+ * unroutable path -- and never "the app said no".
27
+ *
28
+ * A relay refusal carries NO `snapshot`. The three it can originate are a
29
+ * closed set (`RelayRefusal`), and in none of them did anything run or
30
+ * anybody look. Inventing an empty snapshot would tell an agent the app has
31
+ * no rows, which is a lie about the app rather than about the call.
32
+ *
33
+ * CHOICES PROTOCOL.md LEAVES TO THE RELAY, recorded here so the next reader
34
+ * does not have to rediscover them by experiment:
35
+ *
36
+ * - A second `/dk/events` stream for a known tab id SUPERSEDES the first.
37
+ * The id is minted by the tab so a reconnect resumes identity; treating the
38
+ * second stream as a new tab would defeat the only reason the id exists.
39
+ * - Calls in flight CARRY ACROSS that supersede. A tab that was mid-verb when
40
+ * its stream blinked can still POST the result on the new one, and failing
41
+ * those would turn a recovered hiccup into an error the agent must handle.
42
+ * - `hello` UPSERTS FIELD BY FIELD. It arrives again after every reconnect and
43
+ * the app may have navigated in between, so the later one wins on each
44
+ * field it carries and leaves the others alone.
45
+ * - Everything in `hello` but `tab` is OPTIONAL. The consequence is a real
46
+ * window: a tab enters the registry when its stream opens and `hello` lands
47
+ * a moment later on a separate POST. During it `/manifest` answers 404
48
+ * rather than an empty verb list, because an empty list is a false claim
49
+ * that the app has no verbs.
50
+ * - `attach()` is MIDDLEWARE, not a prepended listener. See the comment on it.
51
+ *
52
+ * A TAB BELONGS TO A PRINCIPAL, AND THE REGISTRY KEY SAYS SO. Tabs are
53
+ * stored under `principal\u0000tab`, not under the tab id alone. That is not a
54
+ * check, it is a shape: there is no lookup by bare tab id anywhere in this
55
+ * file, so a caller cannot reach another principal's tab through a code path
56
+ * somebody adds next year and forgets to guard. It also removes the question
57
+ * of what to do when two people mint the same tab id -- nothing, they are two
58
+ * tabs -- and with it an existence oracle for other people's ids.
59
+ *
60
+ * Isolation is NOT authorisation. A credential buys its holder nothing they
61
+ * could not already do in their own browser; it tells the relay which
62
+ * hundredth of its registry to show them. See `auth.ts`.
63
+ *
64
+ * Zero dependencies: `node:http` types and `node:crypto` only.
65
+ */
66
+ import type { IncomingMessage, Server, ServerResponse } from "node:http";
67
+ import { TabAuth } from "./auth.ts";
68
+ import type { RelayRefusal, TabSummary } from "./frames.ts";
69
+ export interface RelayOptions {
70
+ /**
71
+ * How long a `POST /dk/tabs/:tab/call` waits for the matching `result`.
72
+ * **Defaults to 60 seconds.**
73
+ *
74
+ * PROTOCOL.md has no queue on purpose: a call either reaches a connected tab
75
+ * or fails cleanly. The timeout is the other half of that promise. Without
76
+ * it a tab whose JavaScript died -- stream still open, event loop wedged --
77
+ * holds the agent's request forever, which is the one failure mode worse
78
+ * than a refusal, because an agent cannot retry what has not returned.
79
+ *
80
+ * **WHY THE DEFAULT MOVED FROM 15s TO 60s.** The old number was tuned for a
81
+ * button click, where the p99 is tens of milliseconds and 15s is a margin of
82
+ * three hundred times. It is not a margin at all for the verb an adopter
83
+ * actually reaches for this library to drive: a report fetch, an export, a
84
+ * cross-system lookup. A legitimate 20-second fetch came back `timeout`, and
85
+ * `timeout` does not mean "slow" — PROTOCOL.md defines it as **outcome
86
+ * unknown**, so a commit that came back that way may already have run and
87
+ * the agent is told not to retry it. The deadline was therefore converting
88
+ * SUCCESSES into the most expensive answer in the system. The two errors are
89
+ * not symmetric: firing late costs an agent some latency, and firing early
90
+ * costs a task it cannot safely resume.
91
+ *
92
+ * **WHY NOT MUCH LONGER.** A long deadline is also wrong, for three reasons
93
+ * that are all about what else is holding a socket.
94
+ *
95
+ * - The deadline is the only thing that answers an agent at all when a tab
96
+ * is alive but wedged -- an infinite loop in a verb body, a modal nobody
97
+ * will dismiss. `tab-went-away` covers a tab that DIED; nothing else
98
+ * covers one that is merely stuck. At five minutes the agent and the
99
+ * person both sit there with no answer and no way to tell slow from
100
+ * wedged.
101
+ * - Something in the middle will give up first. Nginx, ALBs, Cloud Run and
102
+ * the average corporate proxy cut an idle response at 30 to 60 seconds,
103
+ * so a server-side deadline above that is answered by a socket error at
104
+ * the client -- an unknown outcome with no slug, no hint and no `Result`
105
+ * shape, which is strictly worse than the `timeout` it was meant to
106
+ * avoid.
107
+ * - Each pending call holds a timer, a response and a closure.
108
+ *
109
+ * **WHAT AN ADOPTER SHOULD SET.** The p99.9 of your slowest declared verb,
110
+ * plus a second, and if the app gates commits in the page then plus however
111
+ * long a person takes to read a dialog -- that wait is inside the call. If a
112
+ * verb can legitimately exceed about a minute, raising this is the wrong
113
+ * repair: declare a `read` verb that starts the work and returns a handle,
114
+ * and another that reports whether it is done. An agent parked on one tool
115
+ * call for five minutes cannot be paced, cannot be stopped, cannot be shown
116
+ * to the person as progress, and will be cut off by something anyway.
117
+ */
118
+ timeoutMs?: number;
119
+ /** The keep-alive comment interval. PROTOCOL.md says 20s. */
120
+ pingMs?: number;
121
+ /**
122
+ * Serve requests that did not come from loopback.
123
+ *
124
+ * Off by default, and that default is the security model, not a convenience.
125
+ * A tab's own session is what the app checks, so a relay someone else can
126
+ * reach is that person driving your logged-in session -- not a scoped token
127
+ * they could be given, your actual account. There is nothing to revoke
128
+ * because nothing was ever granted. See "Who is allowed to do this".
129
+ *
130
+ * WITHOUT `auth` OR `resolvePrincipal`, THIS THROWS. That combination is the
131
+ * one the whole of `auth.ts` exists to prevent: an exposed relay with no
132
+ * notion of who is calling publishes a hundred people's logged-in sessions
133
+ * to each other and to anybody who can reach the port. It used to be
134
+ * reachable by setting one flag that reads like a convenience, so now it is
135
+ * not reachable at all -- turning on remote access means naming how callers
136
+ * are identified, in the same call.
137
+ */
138
+ allowRemote?: boolean;
139
+ /**
140
+ * How the relay learns which person a request is from.
141
+ *
142
+ * It grants nothing. See `auth.ts`: a credential buys its holder nothing
143
+ * they could not already do in their own browser, and buys the relay the
144
+ * ability to keep a hundred people's tabs apart.
145
+ */
146
+ auth?: TabAuth;
147
+ /**
148
+ * The other door: a function from request headers to a principal id.
149
+ *
150
+ * For a relay embedded in an app that already has sessions and can simply
151
+ * say who the caller is -- no secret to share, no token to mint. Consulted
152
+ * before `auth`, and returning undefined falls through, so it can handle
153
+ * logged-in users and leave anonymous visitors to the token path.
154
+ */
155
+ resolvePrincipal?: (headers: Record<string, string | string[] | undefined>) => string | undefined;
156
+ /** Called with anything thrown while writing to a stream. Default: ignore. */
157
+ onError?: (err: unknown) => void;
158
+ /**
159
+ * Where this relay's own audit records go. One per `/call` it handled; see
160
+ * `RelayAuditEvent`.
161
+ *
162
+ * WHY THE RELAY EMITS AT ALL, when `MountOptions.onAudit` already records
163
+ * every call that reaches a driver. Because of one fact the in-page hook
164
+ * cannot know and this one cannot help knowing: WHICH PRINCIPAL asked. The
165
+ * core sees a `call()` and has no idea whether it came from the panel in
166
+ * front of a person, a cron job, or somebody else's agent holding a token;
167
+ * the relay resolved the credential itself, so it is the only place in the
168
+ * library where "who" is a fact rather than a guess.
169
+ *
170
+ * AND WHY IT SAYS SO LITTLE. It does not report what the verb did. The
171
+ * driver decided that, in another process, and a copy of somebody else's
172
+ * decision is the second source of truth that can disagree with the first —
173
+ * a relay that logged `ok` for a call whose tab died mid-commit would be
174
+ * asserting an outcome nobody observed. So this records what the RELAY
175
+ * decided: that a call arrived, from whom, for which tab and verb, and
176
+ * whether it was delivered or stopped here. What happened to the data is in
177
+ * the driver's own record, where it was decided. The two are not two
178
+ * countings of one event; see `RelayAuditEvent.outcome`.
179
+ *
180
+ * Called and not awaited, like the core's hook, and a throw is passed to
181
+ * `onError` rather than allowed to fail the call: a relay that returned a
182
+ * 500 because its logging backend was down would turn an audit trail into
183
+ * an outage.
184
+ */
185
+ onAudit?: (event: RelayAuditEvent) => void;
186
+ }
187
+ /**
188
+ * One call this relay handled, and nothing about what the app did with it.
189
+ *
190
+ * The fields are the relay's own knowledge and stop there. `principal` is the
191
+ * one an in-page hook cannot have; `outcome` is the relay's own verdict and
192
+ * never the driver's.
193
+ *
194
+ * KEPT IDENTICAL IN THE PYTHON RELAY, field for field and name for name, by
195
+ * the same standing promise that governs the rest of these two files: there
196
+ * are two independent implementations of this protocol and a difference
197
+ * between them is a difference nobody finds until an operator switches.
198
+ */
199
+ export interface RelayAuditEvent {
200
+ /** `Date.now()` when the call settled, in milliseconds since the epoch. */
201
+ at: number;
202
+ /**
203
+ * How long the relay held the call, in milliseconds: the round trip to the
204
+ * tab, which on a gated commit includes the time a person spent deciding.
205
+ *
206
+ * THE TAB'S OWN `tookMs` IS DELIBERATELY NOT HERE, although the relay now
207
+ * carries one to the agent. It is a figure measured in another process, and
208
+ * copying somebody else's measurement into this record is the same mistake as
209
+ * copying their verdict -- see `outcome`, and "a relay logging `ok` for a call
210
+ * whose tab died mid-commit asserts an outcome nobody observed". The relay
211
+ * cannot check it and would be asserting it. It would also invite the one
212
+ * subtraction nobody should make: `ms - tookMs` is not "the network", it is
213
+ * the network plus however long the frame sat in the tab's event loop plus
214
+ * whatever a proxy buffered. The duration belongs in the driver's own record,
215
+ * where it was measured, and in the answer the agent gets.
216
+ */
217
+ ms: number;
218
+ /** Who asked, as the relay resolved them — a token's subject, a host's own
219
+ * session id, or `LOCAL_PRINCIPAL` on an unconfigured loopback relay, where
220
+ * everything is one principal and this field says so rather than implying
221
+ * an identity nobody established. */
222
+ principal: string;
223
+ /** The tab the call was addressed to. Present even when no such tab was
224
+ * found: an agent calling a tab id it does not own is the thing worth
225
+ * having in a log. */
226
+ tab: string;
227
+ /** The verb, as asked for. Not checked against any manifest — the relay does
228
+ * not hold one it trusts — so this is the agent's word for what it wanted. */
229
+ verb: string;
230
+ /**
231
+ * What the RELAY did with it, which is never what the app did.
232
+ *
233
+ * `delivered` the tab answered. What it answered is in the driver's
234
+ * own audit record, which is where it was decided; this
235
+ * relay deliberately does not copy it.
236
+ * `no-such-tab` no tab of this principal's by that id. Nothing ran.
237
+ * `tab-went-away` the stream was gone, or went while the call was in
238
+ * flight. The verb MAY have run; see `RelayRefusal`.
239
+ * `timeout` no answer inside the deadline. Outcome unknown.
240
+ *
241
+ * So `delivered` is the one value that means "ask the other log", and the
242
+ * other three are the cases where there is no other log to ask because the
243
+ * call never reached, or never returned from, a driver. That is the line
244
+ * that keeps the two records from being two countings of one call: COUNT
245
+ * COMMITS FROM THE DRIVER'S RECORDS, and read this one for who asked and for
246
+ * the calls that never arrived.
247
+ */
248
+ outcome: "delivered" | RelayRefusal;
249
+ }
250
+ export interface Relay {
251
+ /**
252
+ * Handle one request. Returns false if the path is not ours, so the relay
253
+ * can sit in front of an app that owns the rest of the URL space. It does
254
+ * NOT 404 on a miss: deciding that an unknown path is an error is the host
255
+ * server's business, and a relay that answers 404 for everything cannot be
256
+ * embedded in anything.
257
+ */
258
+ handler: (req: IncomingMessage, res: ServerResponse) => boolean;
259
+ /** Put the handler in front of an existing server's own routes. */
260
+ attach: (server: Server) => void;
261
+ /**
262
+ * Every connected tab, across every principal.
263
+ *
264
+ * The operator's in-process view: a process that embeds the relay may
265
+ * legitimately want to know what is connected. NOTHING REACHABLE OVER HTTP
266
+ * USES IT -- `GET /dk/tabs` serves `tabsFor` instead. The cross-principal
267
+ * listing was the inventory of other people's sessions, titles and URLs
268
+ * attached, that the split exists to remove.
269
+ */
270
+ tabs: () => TabSummary[];
271
+ /** The tabs one principal owns -- what `GET /dk/tabs` actually serves. */
272
+ tabsFor: (principal: string, tab?: string) => TabSummary[];
273
+ /** Hang up every stream and fail every call in flight. Idempotent. */
274
+ close: () => void;
275
+ }
276
+ export declare function createRelay(options?: RelayOptions): Relay;
277
+ //# sourceMappingURL=relay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../../src/relay/relay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEzE,OAAO,EAA8B,OAAO,EAAkC,MAAM,WAAW,CAAC;AAChG,OAAO,KAAK,EAIV,YAAY,EAIZ,UAAU,EAIX,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,YAAY;IAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+CG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;;;;;;;;;;;OAgBG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,KAAK,MAAM,GAAG,SAAS,CAAC;IAClG,8EAA8E;IAC9E,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IACjC;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;CAC5C;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,eAAe;IAC9B,2EAA2E;IAC3E,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;;;;;;;;;OAcG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;;0CAGsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB;;2BAEuB;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ;mFAC+E;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,EAAE,WAAW,GAAG,YAAY,CAAC;CACrC;AAED,MAAM,WAAW,KAAK;IACpB;;;;;;OAMG;IACH,OAAO,EAAE,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC;IAChE,mEAAmE;IACnE,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC;;;;;;;;OAQG;IACH,IAAI,EAAE,MAAM,UAAU,EAAE,CAAC;IACzB,0EAA0E;IAC1E,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,UAAU,EAAE,CAAC;IAC3D,sEAAsE;IACtE,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAiGD,wBAAgB,WAAW,CAAC,OAAO,GAAE,YAAiB,GAAG,KAAK,CA8wB7D"}