driverkit 0.0.0-stage → 0.1.0

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 (159) hide show
  1. package/CONTROLS.md +578 -0
  2. package/README.md +104 -2
  3. package/dist/agent/backend.d.ts +69 -0
  4. package/dist/agent/backend.d.ts.map +1 -0
  5. package/dist/agent/backend.js +130 -0
  6. package/dist/agent/backend.js.map +1 -0
  7. package/dist/agent/control.d.ts +148 -0
  8. package/dist/agent/control.d.ts.map +1 -0
  9. package/dist/agent/control.js +342 -0
  10. package/dist/agent/control.js.map +1 -0
  11. package/dist/agent/index.d.ts +9 -0
  12. package/dist/agent/index.d.ts.map +1 -0
  13. package/dist/agent/index.js +6 -0
  14. package/dist/agent/index.js.map +1 -0
  15. package/dist/agent/loop.d.ts +136 -0
  16. package/dist/agent/loop.d.ts.map +1 -0
  17. package/dist/agent/loop.js +824 -0
  18. package/dist/agent/loop.js.map +1 -0
  19. package/dist/agent/render.d.ts +173 -0
  20. package/dist/agent/render.d.ts.map +1 -0
  21. package/dist/agent/render.js +425 -0
  22. package/dist/agent/render.js.map +1 -0
  23. package/dist/agent/tools.d.ts +138 -0
  24. package/dist/agent/tools.d.ts.map +1 -0
  25. package/dist/agent/tools.js +622 -0
  26. package/dist/agent/tools.js.map +1 -0
  27. package/dist/agent/types.d.ts +566 -0
  28. package/dist/agent/types.d.ts.map +1 -0
  29. package/dist/agent/types.js +32 -0
  30. package/dist/agent/types.js.map +1 -0
  31. package/dist/browser/budget.d.ts +92 -0
  32. package/dist/browser/budget.d.ts.map +1 -0
  33. package/dist/browser/budget.js +151 -0
  34. package/dist/browser/budget.js.map +1 -0
  35. package/dist/browser/connect.d.ts +368 -0
  36. package/dist/browser/connect.d.ts.map +1 -0
  37. package/dist/browser/connect.js +1038 -0
  38. package/dist/browser/connect.js.map +1 -0
  39. package/dist/browser/elsewhere.d.ts +89 -0
  40. package/dist/browser/elsewhere.d.ts.map +1 -0
  41. package/dist/browser/elsewhere.js +91 -0
  42. package/dist/browser/elsewhere.js.map +1 -0
  43. package/dist/browser/frames.d.ts +85 -0
  44. package/dist/browser/frames.d.ts.map +1 -0
  45. package/dist/browser/frames.js +11 -0
  46. package/dist/browser/frames.js.map +1 -0
  47. package/dist/browser/index.d.ts +8 -0
  48. package/dist/browser/index.d.ts.map +1 -0
  49. package/dist/browser/index.js +9 -0
  50. package/dist/browser/index.js.map +1 -0
  51. package/dist/check/check.d.ts +171 -0
  52. package/dist/check/check.d.ts.map +1 -0
  53. package/dist/check/check.js +666 -0
  54. package/dist/check/check.js.map +1 -0
  55. package/dist/check/index.d.ts +3 -0
  56. package/dist/check/index.d.ts.map +1 -0
  57. package/dist/check/index.js +2 -0
  58. package/dist/check/index.js.map +1 -0
  59. package/dist/check/types.d.ts +149 -0
  60. package/dist/check/types.d.ts.map +1 -0
  61. package/dist/check/types.js +29 -0
  62. package/dist/check/types.js.map +1 -0
  63. package/dist/controls/controls.d.ts +198 -0
  64. package/dist/controls/controls.d.ts.map +1 -0
  65. package/dist/controls/controls.js +742 -0
  66. package/dist/controls/controls.js.map +1 -0
  67. package/dist/controls/dom.d.ts +108 -0
  68. package/dist/controls/dom.d.ts.map +1 -0
  69. package/dist/controls/dom.js +56 -0
  70. package/dist/controls/dom.js.map +1 -0
  71. package/dist/controls/index.d.ts +26 -0
  72. package/dist/controls/index.d.ts.map +1 -0
  73. package/dist/controls/index.js +23 -0
  74. package/dist/controls/index.js.map +1 -0
  75. package/dist/controls/rows.d.ts +66 -0
  76. package/dist/controls/rows.d.ts.map +1 -0
  77. package/dist/controls/rows.js +127 -0
  78. package/dist/controls/rows.js.map +1 -0
  79. package/dist/core/index.d.ts +3 -0
  80. package/dist/core/index.d.ts.map +1 -0
  81. package/dist/core/index.js +15 -0
  82. package/dist/core/index.js.map +1 -0
  83. package/dist/core/registry.d.ts +192 -0
  84. package/dist/core/registry.d.ts.map +1 -0
  85. package/dist/core/registry.js +2799 -0
  86. package/dist/core/registry.js.map +1 -0
  87. package/dist/core/types.d.ts +2468 -0
  88. package/dist/core/types.d.ts.map +1 -0
  89. package/dist/core/types.js +19 -0
  90. package/dist/core/types.js.map +1 -0
  91. package/dist/otel/index.d.ts +122 -0
  92. package/dist/otel/index.d.ts.map +1 -0
  93. package/dist/otel/index.js +157 -0
  94. package/dist/otel/index.js.map +1 -0
  95. package/dist/react/index.d.ts +191 -0
  96. package/dist/react/index.d.ts.map +1 -0
  97. package/dist/react/index.js +547 -0
  98. package/dist/react/index.js.map +1 -0
  99. package/dist/react/runtime.d.ts +95 -0
  100. package/dist/react/runtime.d.ts.map +1 -0
  101. package/dist/react/runtime.js +54 -0
  102. package/dist/react/runtime.js.map +1 -0
  103. package/dist/react/store.d.ts +333 -0
  104. package/dist/react/store.d.ts.map +1 -0
  105. package/dist/react/store.js +695 -0
  106. package/dist/react/store.js.map +1 -0
  107. package/dist/relay/auth.d.ts +244 -0
  108. package/dist/relay/auth.d.ts.map +1 -0
  109. package/dist/relay/auth.js +391 -0
  110. package/dist/relay/auth.js.map +1 -0
  111. package/dist/relay/frames.d.ts +141 -0
  112. package/dist/relay/frames.d.ts.map +1 -0
  113. package/dist/relay/frames.js +20 -0
  114. package/dist/relay/frames.js.map +1 -0
  115. package/dist/relay/index.d.ts +8 -0
  116. package/dist/relay/index.d.ts.map +1 -0
  117. package/dist/relay/index.js +4 -0
  118. package/dist/relay/index.js.map +1 -0
  119. package/dist/relay/relay.d.ts +277 -0
  120. package/dist/relay/relay.d.ts.map +1 -0
  121. package/dist/relay/relay.js +1026 -0
  122. package/dist/relay/relay.js.map +1 -0
  123. package/dist/relay/serve.d.ts +33 -0
  124. package/dist/relay/serve.d.ts.map +1 -0
  125. package/dist/relay/serve.js +86 -0
  126. package/dist/relay/serve.js.map +1 -0
  127. package/dist/widget/chat.d.ts +290 -0
  128. package/dist/widget/chat.d.ts.map +1 -0
  129. package/dist/widget/chat.js +486 -0
  130. package/dist/widget/chat.js.map +1 -0
  131. package/dist/widget/css.d.ts +49 -0
  132. package/dist/widget/css.d.ts.map +1 -0
  133. package/dist/widget/css.js +532 -0
  134. package/dist/widget/css.js.map +1 -0
  135. package/dist/widget/dom.d.ts +143 -0
  136. package/dist/widget/dom.d.ts.map +1 -0
  137. package/dist/widget/dom.js +27 -0
  138. package/dist/widget/dom.js.map +1 -0
  139. package/dist/widget/highlight.d.ts +64 -0
  140. package/dist/widget/highlight.d.ts.map +1 -0
  141. package/dist/widget/highlight.js +136 -0
  142. package/dist/widget/highlight.js.map +1 -0
  143. package/dist/widget/index.d.ts +9 -0
  144. package/dist/widget/index.d.ts.map +1 -0
  145. package/dist/widget/index.js +20 -0
  146. package/dist/widget/index.js.map +1 -0
  147. package/dist/widget/position.d.ts +166 -0
  148. package/dist/widget/position.d.ts.map +1 -0
  149. package/dist/widget/position.js +497 -0
  150. package/dist/widget/position.js.map +1 -0
  151. package/dist/widget/settings.d.ts +116 -0
  152. package/dist/widget/settings.d.ts.map +1 -0
  153. package/dist/widget/settings.js +117 -0
  154. package/dist/widget/settings.js.map +1 -0
  155. package/dist/widget/widget.d.ts +442 -0
  156. package/dist/widget/widget.d.ts.map +1 -0
  157. package/dist/widget/widget.js +2005 -0
  158. package/dist/widget/widget.js.map +1 -0
  159. package/package.json +153 -4
@@ -0,0 +1,157 @@
1
+ /**
2
+ * driverkit/otel — one audit sink, for hosts that already run OpenTelemetry.
3
+ *
4
+ * WHY THIS IS A SEPARATE ENTRY POINT AND NOT A FEATURE OF THE CORE. `mount()`
5
+ * emits `AuditEvent`s and owns no sink, because the host already has somewhere
6
+ * for records to go: one adopter runs an OTel collector, the next has Datadog,
7
+ * the next a table in their own database. A library that picked the backend
8
+ * would be one you fight. So the core calls a hook, and this file is one
9
+ * implementation of that hook — nothing in `core`, `agent`, `widget`,
10
+ * `controls`, `browser` or `relay` imports it, and an app that never writes
11
+ * `driverkit/otel` never loads a byte of it.
12
+ *
13
+ * WHY IT IMPORTS `@opentelemetry/api` AND YET DEPENDS ON NOTHING. It does not
14
+ * import it. It takes a `Tracer` as an argument, typed STRUCTURALLY against the
15
+ * slice of the OTel API it uses, so the host passes
16
+ * `trace.getTracer("driverkit")` from its own installed copy and this package
17
+ * keeps its promise of zero runtime dependencies. Three things that buys, in
18
+ * the order they matter:
19
+ *
20
+ * 1. There is one OTel SDK per process, registered by the host at startup,
21
+ * and a library that imported its own `@opentelemetry/api` could get a
22
+ * SECOND copy of the global API — a different version, hoisted elsewhere,
23
+ * or duplicated by a bundler — whose `trace.getTracer` returns a no-op
24
+ * tracer because the registration happened on the other copy. Spans would
25
+ * be built and silently dropped, which is the worst failure an audit
26
+ * trail can have: it looks complete. Taking the tracer as an argument
27
+ * makes that impossible, because the only tracer that can be passed is
28
+ * one the host already got from the copy it registered.
29
+ * 2. `@opentelemetry/api` would be this package's first dependency, and the
30
+ * no-dependency rule is an argument in PROTOCOL.md rather than an
31
+ * accident. An optional peer would have kept `npm install driverkit`
32
+ * clean and would still have put an unresolvable import in the published
33
+ * `.d.ts` of anybody who did not install it.
34
+ * 3. The in-page widget — the case most likely to commit data — can use this
35
+ * too. Nothing in here is Node-specific, so `./otel` is published to a
36
+ * browser-targeted bundler like the rest of the library, and a page
37
+ * running the OTel web SDK passes its tracer in exactly as a server does.
38
+ *
39
+ * The structural types below are written to be satisfied BY `@opentelemetry/
40
+ * api`'s own `Tracer` and `Span`, not to re-describe them. They are
41
+ * deliberately the narrowest shape that works, because every field named here
42
+ * is a field a future version of that package could rename.
43
+ */
44
+ /**
45
+ * `SpanStatusCode` from `@opentelemetry/api`, as the two numbers it is.
46
+ *
47
+ * Mirrored rather than imported, and kept as plain numbers because the enum's
48
+ * values are part of its stable surface: `UNSET = 0`, `OK = 1`, `ERROR = 2`.
49
+ * A host that wants to assert on these can import the real enum and compare.
50
+ */
51
+ const STATUS_OK = 1;
52
+ const STATUS_ERROR = 2;
53
+ /**
54
+ * An `AuditHook` that turns each record into one span.
55
+ *
56
+ * ```ts
57
+ * import { trace } from "@opentelemetry/api";
58
+ * import { otelAudit } from "driverkit/otel";
59
+ *
60
+ * mount({ ..., onAudit: otelAudit(trace.getTracer("driverkit")) });
61
+ * ```
62
+ *
63
+ * ONE SPAN PER CALL, with real start and end times taken from the record, so
64
+ * the span's duration is the call's duration — approval included, which is the
65
+ * part of a gated bulk commit a reader most often wants back. The span is
66
+ * created and ended inside this function rather than wrapping the call,
67
+ * because the record arrives after the outcome is decided: there is no live
68
+ * context to parent into, and pretending otherwise would mean holding an open
69
+ * span across a verb and reporting a duration from a clock the core does not
70
+ * own.
71
+ *
72
+ * WHAT IT DOES NOT DO, and each one is a decision rather than an omission:
73
+ *
74
+ * It does not parent the span into the ambient context. A driverkit call
75
+ * arrives from a model turn, a relay frame or a click, and in the page there
76
+ * is no active span to attach to; a span nested under whatever happened to be
77
+ * active would claim a causal link the library cannot verify. An audit record
78
+ * is a standalone fact about an app, which is what a root span says.
79
+ *
80
+ * It does not mark a refusal as an error. A refusal is an ordinary outcome —
81
+ * `declined-by-user` is a person saying no and `stale-plan` is the safety
82
+ * mechanism working — and an exporter that painted those red would light up
83
+ * a dashboard for every correctly refused call, which is a warning on
84
+ * everything and therefore a warning on nothing. The slug is on the span as
85
+ * `driverkit.refused`, so filtering for one is a query. The ONE exception is
86
+ * `threw`, which is the core's word for the app's own code being broken, and
87
+ * which is an error in anybody's reading.
88
+ *
89
+ * It does not batch, retry or flush. The SDK the host registered does all
90
+ * three, and better.
91
+ */
92
+ export function otelAudit(tracer, options = {}) {
93
+ const withArgs = options.args !== false;
94
+ const prefix = options.prefix ?? "driverkit";
95
+ return (event) => {
96
+ const attributes = {
97
+ "driverkit.app": event.app,
98
+ "driverkit.verb": event.verb,
99
+ "driverkit.rev": event.rev,
100
+ "driverkit.ok": event.ok,
101
+ // On every span, including a `read` in an app with no gate, because
102
+ // "nobody was asked" is the fact an auditor is checking for and a field
103
+ // that appeared only when somebody WAS asked would make its absence
104
+ // ambiguous between "not asked" and "this exporter is out of date".
105
+ "driverkit.approval": event.approval,
106
+ "driverkit.policy": event.policy,
107
+ };
108
+ if (event.kind !== undefined)
109
+ attributes["driverkit.kind"] = event.kind;
110
+ if (event.reversible !== undefined)
111
+ attributes["driverkit.reversible"] = event.reversible;
112
+ if (event.screen !== undefined)
113
+ attributes["driverkit.screen"] = event.screen;
114
+ if (event.refused !== undefined)
115
+ attributes["driverkit.refused"] = event.refused;
116
+ if (event.count !== undefined)
117
+ attributes["driverkit.count"] = event.count;
118
+ if (event.plan !== undefined)
119
+ attributes["driverkit.plan"] = event.plan;
120
+ if (event.minted !== undefined)
121
+ attributes["driverkit.plan.minted"] = event.minted;
122
+ // What the agent CLAIMED, beside what was true. The pair is the whole of a
123
+ // `stale` or a `wrong-screen`, and a span carrying only one side cannot
124
+ // show why the call was refused.
125
+ if (event.claimed?.rev !== undefined)
126
+ attributes["driverkit.claimed.rev"] = event.claimed.rev;
127
+ if (event.claimed?.screen !== undefined) {
128
+ attributes["driverkit.claimed.screen"] = event.claimed.screen;
129
+ }
130
+ // The redacted field NAMES go on the span even when the values do not, and
131
+ // even when `args: false`. "This call carried a secret and it was replaced"
132
+ // is itself an audit fact: without it, a reader cannot tell a record that
133
+ // was cleaned from one that never had anything to clean.
134
+ if (event.redacted !== undefined)
135
+ attributes["driverkit.redacted"] = event.redacted.join(",");
136
+ if (withArgs) {
137
+ for (const [name, value] of Object.entries(event.args)) {
138
+ // `null` is a legal `Scalar` and not a legal attribute value, so it is
139
+ // written as the string the agent meant by it rather than dropped: a
140
+ // missing attribute would read as an argument that was never sent.
141
+ attributes[`driverkit.arg.${name}`] = value === null ? "null" : value;
142
+ }
143
+ }
144
+ const span = tracer.startSpan(`${prefix} ${event.verb}`, {
145
+ startTime: event.at - event.ms,
146
+ attributes,
147
+ });
148
+ if (event.refused === "threw") {
149
+ span.setStatus({ code: STATUS_ERROR, message: "the verb threw" });
150
+ }
151
+ else {
152
+ span.setStatus({ code: STATUS_OK });
153
+ }
154
+ span.end(event.at);
155
+ };
156
+ }
157
+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AM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,IAAI,KAAK,CAAC,IAAI,EAAE,EAAE;YACvD,SAAS,EAAE,KAAK,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE;YAC9B,UAAU;SACX,CAAC,CAAC;QACH,IAAI,KAAK,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;YAC9B,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC;QACpE,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QACtC,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * driverkit/otel — one audit sink, for hosts that already run OpenTelemetry.\n *\n * WHY THIS IS A SEPARATE ENTRY POINT AND NOT A FEATURE OF THE CORE. `mount()`\n * emits `AuditEvent`s and owns no sink, because the host already has somewhere\n * for records to go: one adopter runs an OTel collector, the next has Datadog,\n * the next a table in their own database. A library that picked the backend\n * would be one you fight. So the core calls a hook, and this file is one\n * implementation of that hook — nothing in `core`, `agent`, `widget`,\n * `controls`, `browser` or `relay` imports it, and an app that never writes\n * `driverkit/otel` never loads a byte of it.\n *\n * WHY IT IMPORTS `@opentelemetry/api` AND YET DEPENDS ON NOTHING. It does not\n * import it. It takes a `Tracer` as an argument, typed STRUCTURALLY against the\n * slice of the OTel API it uses, so the host passes\n * `trace.getTracer(\"driverkit\")` from its own installed copy and this package\n * keeps its promise of zero runtime dependencies. Three things that buys, in\n * the order they matter:\n *\n * 1. There is one OTel SDK per process, registered by the host at startup,\n * and a library that imported its own `@opentelemetry/api` could get a\n * SECOND copy of the global API — a different version, hoisted elsewhere,\n * or duplicated by a bundler — whose `trace.getTracer` returns a no-op\n * tracer because the registration happened on the other copy. Spans would\n * be built and silently dropped, which is the worst failure an audit\n * trail can have: it looks complete. Taking the tracer as an argument\n * makes that impossible, because the only tracer that can be passed is\n * one the host already got from the copy it registered.\n * 2. `@opentelemetry/api` would be this package's first dependency, and the\n * no-dependency rule is an argument in PROTOCOL.md rather than an\n * accident. An optional peer would have kept `npm install driverkit`\n * clean and would still have put an unresolvable import in the published\n * `.d.ts` of anybody who did not install it.\n * 3. The in-page widget — the case most likely to commit data — can use this\n * too. Nothing in here is Node-specific, so `./otel` is published to a\n * browser-targeted bundler like the rest of the library, and a page\n * running the OTel web SDK passes its tracer in exactly as a server does.\n *\n * The structural types below are written to be satisfied BY `@opentelemetry/\n * api`'s own `Tracer` and `Span`, not to re-describe them. They are\n * deliberately the narrowest shape that works, because every field named here\n * is a field a future version of that package could rename.\n */\n\nimport type { AuditEvent } from \"../core/types.ts\";\n\n/**\n * `SpanStatusCode` from `@opentelemetry/api`, as the two numbers it is.\n *\n * Mirrored rather than imported, and kept as plain numbers because the enum's\n * values are part of its stable surface: `UNSET = 0`, `OK = 1`, `ERROR = 2`.\n * A host that wants to assert on these can import the real enum and compare.\n */\nconst STATUS_OK = 1;\nconst STATUS_ERROR = 2;\n\n/** The slice of `Span` this file touches. Satisfied by the real one. */\nexport interface AuditSpan {\n setStatus(status: { code: number; message?: string }): unknown;\n end(endTime?: number): void;\n}\n\n/** The slice of `Tracer` this file touches. Satisfied by the real one. */\nexport interface AuditTracer {\n startSpan(\n name: string,\n options?: {\n startTime?: number;\n attributes?: Record<string, string | number | boolean>;\n },\n ): AuditSpan;\n}\n\nexport interface OtelAuditOptions {\n /**\n * Put each argument on the span as `driverkit.arg.<name>`. Default: true.\n *\n * Off is for a host whose tracing backend bills by attribute, or whose verbs\n * take arguments it would rather keep out of a vendor's index even after the\n * core's redaction. It is not a redaction mechanism and must not be used as\n * one: `ArgSpec.sensitive` is, and it works on every sink rather than this\n * one. See `ArgSpec.sensitive`.\n */\n args?: boolean;\n /**\n * The span name prefix. Default: `\"driverkit\"`, giving `driverkit accept-selected`.\n *\n * Prefix-and-verb rather than one constant name, because a verb list is\n * STATIC — the same handful of names for every user forever, which is the\n * whole premise of the library — so it is exactly the low-cardinality thing\n * a span name is supposed to be, and it means a trace UI's \"slowest\n * operations\" list is already a list of verbs.\n */\n prefix?: string;\n}\n\n/**\n * An `AuditHook` that turns each record into one span.\n *\n * ```ts\n * import { trace } from \"@opentelemetry/api\";\n * import { otelAudit } from \"driverkit/otel\";\n *\n * mount({ ..., onAudit: otelAudit(trace.getTracer(\"driverkit\")) });\n * ```\n *\n * ONE SPAN PER CALL, with real start and end times taken from the record, so\n * the span's duration is the call's duration — approval included, which is the\n * part of a gated bulk commit a reader most often wants back. The span is\n * created and ended inside this function rather than wrapping the call,\n * because the record arrives after the outcome is decided: there is no live\n * context to parent into, and pretending otherwise would mean holding an open\n * span across a verb and reporting a duration from a clock the core does not\n * own.\n *\n * WHAT IT DOES NOT DO, and each one is a decision rather than an omission:\n *\n * It does not parent the span into the ambient context. A driverkit call\n * arrives from a model turn, a relay frame or a click, and in the page there\n * is no active span to attach to; a span nested under whatever happened to be\n * active would claim a causal link the library cannot verify. An audit record\n * is a standalone fact about an app, which is what a root span says.\n *\n * It does not mark a refusal as an error. A refusal is an ordinary outcome —\n * `declined-by-user` is a person saying no and `stale-plan` is the safety\n * mechanism working — and an exporter that painted those red would light up\n * a dashboard for every correctly refused call, which is a warning on\n * everything and therefore a warning on nothing. The slug is on the span as\n * `driverkit.refused`, so filtering for one is a query. The ONE exception is\n * `threw`, which is the core's word for the app's own code being broken, and\n * which is an error in anybody's reading.\n *\n * It does not batch, retry or flush. The SDK the host registered does all\n * three, and better.\n */\nexport function otelAudit(\n tracer: AuditTracer,\n options: OtelAuditOptions = {},\n): (event: AuditEvent) => void {\n const withArgs = options.args !== false;\n const prefix = options.prefix ?? \"driverkit\";\n\n return (event: AuditEvent): void => {\n const attributes: Record<string, string | number | boolean> = {\n \"driverkit.app\": event.app,\n \"driverkit.verb\": event.verb,\n \"driverkit.rev\": event.rev,\n \"driverkit.ok\": event.ok,\n // On every span, including a `read` in an app with no gate, because\n // \"nobody was asked\" is the fact an auditor is checking for and a field\n // that appeared only when somebody WAS asked would make its absence\n // ambiguous between \"not asked\" and \"this exporter is out of date\".\n \"driverkit.approval\": event.approval,\n \"driverkit.policy\": event.policy,\n };\n if (event.kind !== undefined) attributes[\"driverkit.kind\"] = event.kind;\n if (event.reversible !== undefined) attributes[\"driverkit.reversible\"] = event.reversible;\n if (event.screen !== undefined) attributes[\"driverkit.screen\"] = event.screen;\n if (event.refused !== undefined) attributes[\"driverkit.refused\"] = event.refused;\n if (event.count !== undefined) attributes[\"driverkit.count\"] = event.count;\n if (event.plan !== undefined) attributes[\"driverkit.plan\"] = event.plan;\n if (event.minted !== undefined) attributes[\"driverkit.plan.minted\"] = event.minted;\n // What the agent CLAIMED, beside what was true. The pair is the whole of a\n // `stale` or a `wrong-screen`, and a span carrying only one side cannot\n // show why the call was refused.\n if (event.claimed?.rev !== undefined) attributes[\"driverkit.claimed.rev\"] = event.claimed.rev;\n if (event.claimed?.screen !== undefined) {\n attributes[\"driverkit.claimed.screen\"] = event.claimed.screen;\n }\n // The redacted field NAMES go on the span even when the values do not, and\n // even when `args: false`. \"This call carried a secret and it was replaced\"\n // is itself an audit fact: without it, a reader cannot tell a record that\n // was cleaned from one that never had anything to clean.\n if (event.redacted !== undefined) attributes[\"driverkit.redacted\"] = event.redacted.join(\",\");\n if (withArgs) {\n for (const [name, value] of Object.entries(event.args)) {\n // `null` is a legal `Scalar` and not a legal attribute value, so it is\n // written as the string the agent meant by it rather than dropped: a\n // missing attribute would read as an argument that was never sent.\n attributes[`driverkit.arg.${name}`] = value === null ? \"null\" : value;\n }\n }\n\n const span = tracer.startSpan(`${prefix} ${event.verb}`, {\n startTime: event.at - event.ms,\n attributes,\n });\n if (event.refused === \"threw\") {\n span.setStatus({ code: STATUS_ERROR, message: \"the verb threw\" });\n } else {\n span.setStatus({ code: STATUS_OK });\n }\n span.end(event.at);\n };\n}\n"]}
@@ -0,0 +1,191 @@
1
+ /**
2
+ * driverkit/react — the same panel, for a team that already has React.
3
+ *
4
+ * WHY THIS EXISTS BESIDE `driverkit/widget` AND NOT INSTEAD OF IT.
5
+ * `mountWidget` is hand-written DOM in a shadow root with zero dependencies,
6
+ * and that is the right shape for a drop-in: it goes into a Thymeleaf
7
+ * template, a Rails view or a static page, and the host owns no version of
8
+ * anything it did not pick. It is the wrong shape for a team that has React, a
9
+ * design system and an opinion about what their product looks like — for them
10
+ * the shadow root is a wall around the panel and the hand-written markup is
11
+ * something to fight. So there are two paths. **The vanilla widget's
12
+ * dependency count stays zero and its behaviour is untouched by anything in
13
+ * here.**
14
+ *
15
+ * WHAT THE PUBLIC SURFACE IS, AND WHY IT IS THIS ONE. Three things, in
16
+ * decreasing order of how much they assume:
17
+ *
18
+ * `createDriverPanel(React)` returns everything. One call, because React
19
+ * itself is an argument rather than an import — see `runtime.ts`, which is
20
+ * the file to read before judging that.
21
+ *
22
+ * `useDriver(driver, options)` is the primitive, and it is the whole
23
+ * library: the conversation, the gate, the run controls, the budget and the
24
+ * receipts, as plain data and plain functions. A host that renders none of
25
+ * our components still gets all of the behaviour. This is deliberately the
26
+ * thing the documentation leads with, because a team adopting this has a
27
+ * design system and headless-with-defaults is the only shape that respects
28
+ * one.
29
+ *
30
+ * `<DriverPanel />` is one assembly of the components, for the team that
31
+ * wants a panel today and will restyle it on Thursday. Every part of it is
32
+ * replaceable one at a time through `components`, so "restyle it" never has
33
+ * to become "fork it".
34
+ *
35
+ * Both, rather than one, because the two audiences are real and a single
36
+ * `<DriverPanel />` would make the design-system team reimplement the gate —
37
+ * which is the one thing in here nobody should be reimplementing.
38
+ *
39
+ * WHAT IS DELIBERATELY ABSENT, with the vanilla widget's own reasoning
40
+ * re-examined rather than copied; `REACT.md` has the full list:
41
+ *
42
+ * **No shadow root.** The vanilla panel needs one because it is rendering
43
+ * into an app whose CSS it has never seen. A React app has a CSS isolation
44
+ * story of its own — modules, Tailwind, styled-components, whatever it
45
+ * picked — and a shadow root would break it: the host's own class names
46
+ * would not reach inside, which is the opposite of the point.
47
+ *
48
+ * **No launcher, no drag, no corner.** Those exist because the vanilla
49
+ * widget has to place itself in a page nobody told it about. Here the host
50
+ * renders `<DriverPanel />` where it wants it, in its own layout, and a
51
+ * library that positioned itself `fixed` would be overriding a decision the
52
+ * host is better placed to make.
53
+ *
54
+ * **No `aria-live` on the transcript**, which the vanilla panel has and
55
+ * which is a bug at a 600ms pace: a live region containing the whole
56
+ * conversation is re-read as each step row lands, so the person hears a
57
+ * growing transcript from the top instead of what just changed. State is
58
+ * announced instead, through small `role="status"` regions that say one
59
+ * thing — see `ReceiptStatus` and `RunAnnouncer`.
60
+ *
61
+ * **No `textContent` discipline, because React is the discipline.** The
62
+ * vanilla file keeps `innerHTML` out of its DOM wrapper on purpose; here the
63
+ * equivalent rule is that nothing in this area calls
64
+ * `dangerouslySetInnerHTML`, including at the markdown seam, where a host
65
+ * supplies a COMPONENT and never a string of HTML.
66
+ *
67
+ * The `era` counter is kept, and that one is worth saying out loud: React does
68
+ * not help with it. A `setState` from an async callback that outlived a Clear
69
+ * is exactly as wrong as the `appendChild` it replaced. See `store.ts`.
70
+ */
71
+ import type { ApprovalRequest, Driver } from "../core/index.ts";
72
+ import type { Component, ReactRuntime } from "./runtime.ts";
73
+ import type { ApprovalEntry, Decision, PanelOptions, PanelSnapshot, PanelStore, SaidEntry, StepEntry } from "./store.ts";
74
+ export { COMMIT_ASK_ABOVE, createPanelStore, receiptLine, stepOutcome } from "./store.ts";
75
+ export type { ApprovalEntry, ApprovalPhase, Decision, Entry, Grant, PanelOptions, PanelSnapshot, PanelStore, RunControlsFactory, SaidEntry, StepEntry, StepStatus, } from "./store.ts";
76
+ export type { Component, Node, ReactRuntime } from "./runtime.ts";
77
+ /** What `useDriver` hands back: the snapshot, flattened, plus the actions. */
78
+ export interface Driving extends PanelSnapshot {
79
+ ask: (text: string) => Promise<void>;
80
+ stop: () => void;
81
+ clear: () => void;
82
+ pause: () => void;
83
+ resume: () => void;
84
+ step: () => void;
85
+ setPace: (ms: number) => void;
86
+ setStepMode: (on: boolean) => void;
87
+ setConfirmCommits: (on: boolean) => void;
88
+ decide: (id: string, decision: Decision) => void;
89
+ revoke: (verb: string) => void;
90
+ /** This panel's gate, as a `MountOptions.approve` hook. Wire it up with a
91
+ * forward reference so a commit arriving over the relay renders the same
92
+ * card. See `PanelStore.approve`. */
93
+ approve: (req: ApprovalRequest) => Promise<unknown>;
94
+ /** The store itself, for a host that wants to reach past the hook. */
95
+ store: PanelStore;
96
+ }
97
+ /**
98
+ * The markdown seam.
99
+ *
100
+ * **Markdown rendering is not built here and must not be.** It is being built
101
+ * for the vanilla widget, and when it lands this is where it plugs in: a
102
+ * component that is handed the model's prose for one turn and returns nodes.
103
+ *
104
+ * What it can rely on: `text` is the model's **complete** text for that turn.
105
+ * `onSay` delivers a whole turn at once — driverkit does not stream tokens —
106
+ * so a renderer here never sees a half-written fence, never has to parse
107
+ * incrementally, and needs none of the streaming-markdown machinery the rest
108
+ * of the world needs. It is called on render, so it must be pure and should be
109
+ * memoized by the host if its parse is expensive.
110
+ *
111
+ * What it must not do: return HTML for React to inject. The prop is a
112
+ * component precisely so that the escape hatch is not a string — a markdown
113
+ * renderer that handed us `dangerouslySetInnerHTML` would make a model's
114
+ * output into a script tag in the host's page, and the model's output is the
115
+ * least trusted thing on this screen.
116
+ */
117
+ export type ProseRenderer = Component<{
118
+ text: string;
119
+ }>;
120
+ export interface PanelComponents {
121
+ Transcript: Component<TranscriptProps>;
122
+ Said: Component<{
123
+ entry: SaidEntry;
124
+ Prose: ProseRenderer;
125
+ }>;
126
+ StepRow: Component<{
127
+ entry: StepEntry;
128
+ }>;
129
+ ApprovalCard: Component<ApprovalCardProps>;
130
+ RunControlsBar: Component<RunControlsBarProps>;
131
+ Composer: Component<ComposerProps>;
132
+ BudgetNotice: Component<{
133
+ driving: Driving;
134
+ }>;
135
+ GrantList: Component<{
136
+ driving: Driving;
137
+ }>;
138
+ Prose: ProseRenderer;
139
+ }
140
+ export interface TranscriptProps {
141
+ driving: Driving;
142
+ components: PanelComponents;
143
+ /** Whether the approval cards offer the free-text note. From
144
+ * `PanelOptions.notes`, threaded through here rather than read from the
145
+ * options by each card, so that a host replacing one component does not
146
+ * have to re-plumb an option it did not change. */
147
+ notes: boolean;
148
+ }
149
+ export interface ApprovalCardProps {
150
+ entry: ApprovalEntry;
151
+ decide: (id: string, decision: Decision) => void;
152
+ /** Whether to offer the free-text note. From `PanelOptions.notes`. */
153
+ notes: boolean;
154
+ }
155
+ export interface RunControlsBarProps {
156
+ driving: Driving;
157
+ }
158
+ export interface ComposerProps {
159
+ driving: Driving;
160
+ placeholder?: string;
161
+ }
162
+ export interface DriverPanelProps {
163
+ driver: Driver;
164
+ options: PanelOptions;
165
+ placeholder?: string;
166
+ /** Replace any part of the default assembly, one piece at a time. */
167
+ components?: Partial<PanelComponents>;
168
+ /** Render the model's prose. The markdown seam; see `ProseRenderer`. */
169
+ Prose?: ProseRenderer;
170
+ }
171
+ /**
172
+ * Bind this area to the host's React and get the panel.
173
+ *
174
+ * ```tsx
175
+ * // driver-panel.tsx — one file you own
176
+ * import * as React from "react";
177
+ * import { createDriverPanel } from "driverkit/react";
178
+ *
179
+ * export const { DriverPanel, useDriver, components } = createDriverPanel(React);
180
+ * ```
181
+ *
182
+ * Everything after that line is ordinary React. See `runtime.ts` for why the
183
+ * line is there at all.
184
+ */
185
+ export declare function createDriverPanel(react: ReactRuntime): {
186
+ useDriver: (driver: Driver, options: PanelOptions) => Driving;
187
+ DriverPanel: Component<DriverPanelProps>;
188
+ /** The default components, so a host can wrap one instead of writing it. */
189
+ components: PanelComponents;
190
+ };
191
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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