@g9tm/lynxcontrols-pilot 0.0.0-stage → 2.4.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 (99) hide show
  1. package/README.md +159 -2
  2. package/catalog/cards/G9PilotHost.md +16 -0
  3. package/catalog/cards/G9PilotMask.md +10 -0
  4. package/catalog/cards/G9PilotPanel.md +10 -0
  5. package/catalog/catalog.json +420 -0
  6. package/catalog/index.md +7 -0
  7. package/check/cli.mjs +5 -0
  8. package/check/index.mjs +137 -0
  9. package/check/index.test.mjs +180 -0
  10. package/config/cli.mjs +31 -0
  11. package/config/index.d.ts +62 -0
  12. package/config/index.mjs +380 -0
  13. package/config/index.test.mjs +406 -0
  14. package/dist/.tsbuildinfo +1 -0
  15. package/dist/anchors.d.ts +39 -0
  16. package/dist/anchors.d.ts.map +1 -0
  17. package/dist/anchors.jsx +103 -0
  18. package/dist/bridge.d.ts +4 -0
  19. package/dist/bridge.d.ts.map +1 -0
  20. package/dist/bridge.jsx +143 -0
  21. package/dist/busy.d.ts +4 -0
  22. package/dist/busy.d.ts.map +1 -0
  23. package/dist/busy.jsx +43 -0
  24. package/dist/commands.d.ts +24 -0
  25. package/dist/commands.d.ts.map +1 -0
  26. package/dist/commands.jsx +286 -0
  27. package/dist/consent.d.ts +51 -0
  28. package/dist/consent.d.ts.map +1 -0
  29. package/dist/consent.jsx +131 -0
  30. package/dist/explore.d.ts +36 -0
  31. package/dist/explore.d.ts.map +1 -0
  32. package/dist/explore.jsx +133 -0
  33. package/dist/flags.d.ts +69 -0
  34. package/dist/flags.d.ts.map +1 -0
  35. package/dist/flags.jsx +81 -0
  36. package/dist/host-core.d.ts +36 -0
  37. package/dist/host-core.d.ts.map +1 -0
  38. package/dist/host-core.jsx +90 -0
  39. package/dist/host-sink.d.ts +43 -0
  40. package/dist/host-sink.d.ts.map +1 -0
  41. package/dist/host-sink.jsx +87 -0
  42. package/dist/index-marks.d.ts +33 -0
  43. package/dist/index-marks.d.ts.map +1 -0
  44. package/dist/index-marks.jsx +40 -0
  45. package/dist/index-observe.d.ts +17 -0
  46. package/dist/index-observe.d.ts.map +1 -0
  47. package/dist/index-observe.jsx +14 -0
  48. package/dist/index.d.ts +18 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.jsx +11 -0
  51. package/dist/info.d.ts +10 -0
  52. package/dist/info.d.ts.map +1 -0
  53. package/dist/info.jsx +9 -0
  54. package/dist/kit.d.ts +67 -0
  55. package/dist/kit.d.ts.map +1 -0
  56. package/dist/kit.jsx +1 -0
  57. package/dist/layer.d.ts +4 -0
  58. package/dist/layer.d.ts.map +1 -0
  59. package/dist/layer.jsx +10 -0
  60. package/dist/layers.d.ts +4 -0
  61. package/dist/layers.d.ts.map +1 -0
  62. package/dist/layers.jsx +146 -0
  63. package/dist/mask.d.ts +20 -0
  64. package/dist/mask.d.ts.map +1 -0
  65. package/dist/mask.jsx +35 -0
  66. package/dist/net.d.ts +17 -0
  67. package/dist/net.d.ts.map +1 -0
  68. package/dist/net.jsx +60 -0
  69. package/dist/observe.d.ts +99 -0
  70. package/dist/observe.d.ts.map +1 -0
  71. package/dist/observe.jsx +194 -0
  72. package/dist/off.d.ts +45 -0
  73. package/dist/off.d.ts.map +1 -0
  74. package/dist/off.jsx +81 -0
  75. package/dist/otlp.d.ts +61 -0
  76. package/dist/otlp.d.ts.map +1 -0
  77. package/dist/otlp.jsx +141 -0
  78. package/dist/panel.d.ts +13 -0
  79. package/dist/panel.d.ts.map +1 -0
  80. package/dist/panel.jsx +182 -0
  81. package/dist/session.d.ts +42 -0
  82. package/dist/session.d.ts.map +1 -0
  83. package/dist/session.jsx +115 -0
  84. package/dist/types.d.ts +47 -0
  85. package/dist/types.d.ts.map +1 -0
  86. package/dist/types.jsx +1 -0
  87. package/dist/watch.d.ts +17 -0
  88. package/dist/watch.d.ts.map +1 -0
  89. package/dist/watch.jsx +165 -0
  90. package/doctor/cli.mjs +5 -0
  91. package/doctor/index.mjs +214 -0
  92. package/doctor/index.test.mjs +174 -0
  93. package/gradle/g9pilot.app.gradle +55 -0
  94. package/gradle/g9pilot.settings.gradle +27 -0
  95. package/ios/g9pilot.rb +47 -0
  96. package/package.json +66 -4
  97. package/rspeedy/index.d.ts +40 -0
  98. package/rspeedy/index.mjs +100 -0
  99. package/rspeedy/index.test.mjs +192 -0
package/dist/net.jsx ADDED
@@ -0,0 +1,60 @@
1
+ import { beginBusy, recordNet, shapeRequest } from "@g9tm/app-pilot";
2
+ function _define_property(obj, key, value) {
3
+ if (key in obj) Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ else obj[key] = value;
10
+ return obj;
11
+ }
12
+ const pathOf = (url)=>url.replace(/^https?:\/\/[^/]+/, '').split('?')[0];
13
+ const sleep = (ms)=>new Promise((done)=>setTimeout(done, ms));
14
+ class G9ShapedRequestError extends Error {
15
+ constructor(status, message){
16
+ super(message), _define_property(this, "status", void 0), this.status = status;
17
+ this.name = 'G9ShapedRequestError';
18
+ }
19
+ }
20
+ async function aroundRequest(method, url, run, options = {}) {
21
+ var _options_statusOf;
22
+ const at = Date.now();
23
+ const path = pathOf(url);
24
+ const long = options.longPoll ? options.longPoll(url) : path.endsWith('/wait');
25
+ const end = long ? null : beginBusy(`http:${method.toUpperCase()} ${path}`);
26
+ const statusOf = null != (_options_statusOf = options.statusOf) ? _options_statusOf : (r)=>{
27
+ var _ref;
28
+ return null != (_ref = null == r ? void 0 : r.status) ? _ref : null;
29
+ };
30
+ const shaped = (status, text)=>{
31
+ if (options.answer) return options.answer(status, text);
32
+ throw new G9ShapedRequestError(status, `HTTP ${status} (net.shape)`);
33
+ };
34
+ try {
35
+ const shape = shapeRequest(method, url);
36
+ if (null == shape ? void 0 : shape.delayMs) await sleep(shape.delayMs);
37
+ if (null == shape ? void 0 : shape.offline) throw new G9ShapedRequestError(null, 'offline (net.shape)');
38
+ const response = (null == shape ? void 0 : shape.replay) ? shaped(shape.replay.status, shape.replay.text) : (null == shape ? void 0 : shape.status) ? shaped(shape.status, null) : await run();
39
+ recordNet({
40
+ method,
41
+ url,
42
+ status: statusOf(response),
43
+ ms: Date.now() - at
44
+ });
45
+ return response;
46
+ } catch (error) {
47
+ var _ref;
48
+ recordNet({
49
+ method,
50
+ url,
51
+ status: error instanceof G9ShapedRequestError ? error.status : null,
52
+ ms: Date.now() - at,
53
+ error: String(null != (_ref = null == error ? void 0 : error.message) ? _ref : error)
54
+ });
55
+ throw error;
56
+ } finally{
57
+ null == end || end();
58
+ }
59
+ }
60
+ export { G9ShapedRequestError, aroundRequest };
@@ -0,0 +1,99 @@
1
+ import type { G9Preferences } from '@g9tm/lynxcontrols-foundation/services';
2
+ import type { G9PilotSettings } from './flags.js';
3
+ /** One finding the watch kept (an `oracle.violation`, or an error line). */
4
+ export interface G9PilotFinding {
5
+ readonly rule: string;
6
+ readonly severity: string;
7
+ readonly key: string;
8
+ readonly message: string;
9
+ readonly at: number;
10
+ /** How many times it came back after the first sighting. */
11
+ readonly count: number;
12
+ }
13
+ /** What the app hands to its diagnostics channel (G9AppDiagnostic, a hub, a file). */
14
+ export interface G9PilotReport {
15
+ readonly profile: string;
16
+ readonly environment: string | null;
17
+ readonly takenAt: number;
18
+ readonly findings: readonly G9PilotFinding[];
19
+ /** The page's failure traces (black box), newest first, when the build carries it. */
20
+ readonly traces: readonly unknown[];
21
+ /** The last log lines (black box), when the build carries it. */
22
+ readonly log: readonly unknown[];
23
+ /** Whether it left the device (g9.report: the build's channel and, with `consent: user`, the person's yes). */
24
+ readonly sent?: boolean;
25
+ }
26
+ export interface G9FindingsOptions {
27
+ readonly settings: G9PilotSettings['observe'];
28
+ readonly preferences?: G9Preferences | null;
29
+ /** Sampling: a number in [0, 1) (tests pass a fixed one). */
30
+ readonly random?: () => number;
31
+ readonly now?: () => number;
32
+ }
33
+ /** The bounded, sampled, persisted buffer of findings. */
34
+ export interface G9FindingsBuffer {
35
+ list(): readonly G9PilotFinding[];
36
+ clear(): void;
37
+ subscribe(listener: () => void): () => void;
38
+ /** One report: the findings and, when the black box is there, its traces and log tail. */
39
+ report(meta: {
40
+ readonly profile: string;
41
+ readonly environment: string | null;
42
+ }): Promise<G9PilotReport>;
43
+ stop(): void;
44
+ }
45
+ export declare function createFindingsBuffer(options: G9FindingsOptions): G9FindingsBuffer;
46
+ /**
47
+ * Automatic reports (observe `report.auto`): `send` runs when a finding the buffer had not held before arrives, at most
48
+ * once per `everyMs` — a burst inside the window is sent once, at its end. Findings restored from a previous run are not
49
+ * new; after `clear()` every finding is new again.
50
+ */
51
+ export declare function autoReports(buffer: Pick<G9FindingsBuffer, 'list' | 'subscribe'>, everyMs: number, send: () => unknown, now?: () => number): () => void;
52
+ /** g9.summary: what this device's watch saw, in one glance (counts, never the whole buffer). */
53
+ export interface G9PilotSummary {
54
+ readonly profile: string;
55
+ readonly environment: string | null;
56
+ readonly findings: {
57
+ /** Sightings, repeats included. */
58
+ readonly total: number;
59
+ /** Distinct findings (rule + key). */
60
+ readonly distinct: number;
61
+ readonly bySeverity: Readonly<Record<string, number>>;
62
+ /** Per rule, the most seen first. */
63
+ readonly byRule: ReadonlyArray<{
64
+ readonly rule: string;
65
+ readonly severity: string;
66
+ readonly count: number;
67
+ readonly last: number;
68
+ }>;
69
+ };
70
+ /** perf.vitals (module vitals): the threads' recent stalls and the memory series; null without it. */
71
+ readonly stalls: {
72
+ readonly count: number;
73
+ readonly worstMs: number;
74
+ readonly js: number;
75
+ readonly main: number;
76
+ } | null;
77
+ readonly memory: {
78
+ readonly currentMb: number | null;
79
+ readonly peakMb: number | null;
80
+ readonly baselineMb: number | null;
81
+ } | null;
82
+ /** The black box's failure traces, newest first (three); null without the black box. */
83
+ readonly traces: {
84
+ readonly count: number;
85
+ readonly last: readonly unknown[];
86
+ } | null;
87
+ /** The black box's log tail by level; null without it. */
88
+ readonly log: Readonly<Record<string, number>> | null;
89
+ }
90
+ /** Folds the findings and the optional readings (null: that module is not in the build) into a summary. */
91
+ export declare function summarize(meta: {
92
+ readonly profile: string;
93
+ readonly environment: string | null;
94
+ }, findings: readonly G9PilotFinding[], readings: {
95
+ readonly vitals: unknown;
96
+ readonly traces: unknown;
97
+ readonly log: unknown;
98
+ }): G9PilotSummary;
99
+ //# sourceMappingURL=observe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observe.d.ts","sourceRoot":"","sources":["../src/observe.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,4EAA4E;AAC5E,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,sFAAsF;AACtF,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,SAAS,cAAc,EAAE,CAAC;IAC7C,sFAAsF;IACtF,QAAQ,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC;IACpC,iEAAiE;IACjE,QAAQ,CAAC,GAAG,EAAE,SAAS,OAAO,EAAE,CAAC;IACjC,+GAA+G;IAC/G,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,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AAA;CAAE,EACvE,QAAQ,EAAE,SAAS,cAAc,EAAE,EACnC,QAAQ,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAA;CAAE,GACtF,cAAc,CAgDhB"}
@@ -0,0 +1,194 @@
1
+ import { dispatch, onEmit } from "@g9tm/app-pilot";
2
+ const KEY = 'findings';
3
+ const kindOf = (rule)=>rule.startsWith('perf.') ? 'vitals' : rule.startsWith('trace') ? 'traces' : 'errors';
4
+ function createFindingsBuffer(options) {
5
+ var _options_random, _options_now, _ref;
6
+ var _options_preferences;
7
+ const random = null != (_options_random = options.random) ? _options_random : Math.random;
8
+ const now = null != (_options_now = options.now) ? _options_now : Date.now;
9
+ const max = Math.max(1, options.settings.buffer.maxFindings);
10
+ const store = options.settings.buffer.persist ? null != (_ref = null == (_options_preferences = options.preferences) ? void 0 : _options_preferences.namespace('pilot')) ? _ref : null : null;
11
+ const listeners = new Set();
12
+ let items = [];
13
+ try {
14
+ var _ref1;
15
+ const saved = null != (_ref1 = null == store ? void 0 : store.getString(KEY)) ? _ref1 : null;
16
+ if (saved) items = JSON.parse(saved).slice(-max);
17
+ } catch {
18
+ items = [];
19
+ }
20
+ const save = ()=>{
21
+ if (store) store.setString(KEY, JSON.stringify(items));
22
+ for (const l of [
23
+ ...listeners
24
+ ])l();
25
+ };
26
+ const add = (f)=>{
27
+ const same = items.findIndex((i)=>i.rule === f.rule && i.key === f.key);
28
+ if (same >= 0) {
29
+ const prev = items[same];
30
+ items[same] = {
31
+ ...prev,
32
+ count: prev.count + 1
33
+ };
34
+ save();
35
+ return;
36
+ }
37
+ if (random() >= options.settings.sampling[kindOf(f.rule)]) return;
38
+ items.push({
39
+ ...f,
40
+ at: now(),
41
+ count: 0
42
+ });
43
+ if (items.length > max) items = items.slice(-max);
44
+ save();
45
+ };
46
+ const off = onEmit((kind, data)=>{
47
+ var _d_rule, _d_severity, _d_key, _d_message;
48
+ if ('oracle.violation' !== kind) return;
49
+ const d = data;
50
+ add({
51
+ rule: String(null != (_d_rule = d.rule) ? _d_rule : 'unknown'),
52
+ severity: String(null != (_d_severity = d.severity) ? _d_severity : 'warn'),
53
+ key: String(null != (_d_key = d.key) ? _d_key : ''),
54
+ message: String(null != (_d_message = d.message) ? _d_message : '')
55
+ });
56
+ });
57
+ const local = async (command, args = {})=>{
58
+ const a = await dispatch({
59
+ id: `g9.report.${now()}`,
60
+ command,
61
+ args,
62
+ kid: 'self-g9.report',
63
+ scopes: [
64
+ '*'
65
+ ]
66
+ });
67
+ return a.ok ? a.result : null;
68
+ };
69
+ return {
70
+ list: ()=>items,
71
+ clear () {
72
+ items = [];
73
+ save();
74
+ },
75
+ subscribe (listener) {
76
+ listeners.add(listener);
77
+ return ()=>listeners.delete(listener);
78
+ },
79
+ async report (meta) {
80
+ var _ref, _ref1;
81
+ const traces = await local('trace.list');
82
+ const log = await local('log.tail', {
83
+ limit: 80
84
+ });
85
+ return {
86
+ profile: meta.profile,
87
+ environment: meta.environment,
88
+ takenAt: now(),
89
+ findings: items,
90
+ traces: null != (_ref = null == traces ? void 0 : traces.traces) ? _ref : [],
91
+ log: null != (_ref1 = null == log ? void 0 : log.entries) ? _ref1 : []
92
+ };
93
+ },
94
+ stop () {
95
+ off();
96
+ listeners.clear();
97
+ }
98
+ };
99
+ }
100
+ function autoReports(buffer, everyMs, send, now = Date.now) {
101
+ const keyOf = (f)=>`${f.rule}\u0000${f.key}`;
102
+ const seen = new Set(buffer.list().map(keyOf));
103
+ let last = -1 / 0;
104
+ let timer = null;
105
+ const fire = ()=>{
106
+ timer = null;
107
+ last = now();
108
+ send();
109
+ };
110
+ const off = buffer.subscribe(()=>{
111
+ const list = buffer.list();
112
+ if (0 === list.length) seen.clear();
113
+ let fresh = false;
114
+ for (const f of list){
115
+ const k = keyOf(f);
116
+ if (!seen.has(k)) {
117
+ seen.add(k);
118
+ fresh = true;
119
+ }
120
+ }
121
+ if (!fresh || timer) return;
122
+ const wait = last + everyMs - now();
123
+ if (wait <= 0) fire();
124
+ else timer = setTimeout(fire, wait);
125
+ });
126
+ return ()=>{
127
+ off();
128
+ if (timer) clearTimeout(timer);
129
+ };
130
+ }
131
+ const num = (v)=>'number' == typeof v && Number.isFinite(v) ? v : null;
132
+ function summarize(meta, findings, readings) {
133
+ var _ref;
134
+ const bySeverity = {};
135
+ const rules = new Map();
136
+ let total = 0;
137
+ for (const f of findings){
138
+ var _bySeverity_f_severity, _rules_get;
139
+ const seen = f.count + 1;
140
+ total += seen;
141
+ bySeverity[f.severity] = (null != (_bySeverity_f_severity = bySeverity[f.severity]) ? _bySeverity_f_severity : 0) + seen;
142
+ const r = null != (_rules_get = rules.get(f.rule)) ? _rules_get : {
143
+ rule: f.rule,
144
+ severity: f.severity,
145
+ count: 0,
146
+ last: 0
147
+ };
148
+ r.count += seen;
149
+ r.last = Math.max(r.last, f.at);
150
+ rules.set(f.rule, r);
151
+ }
152
+ const v = readings.vitals;
153
+ const stallList = Array.isArray(null == v ? void 0 : v.stalls) ? v.stalls : null;
154
+ const t = readings.traces;
155
+ const l = readings.log;
156
+ const levels = {};
157
+ for (const e of null != (_ref = null == l ? void 0 : l.entries) ? _ref : []){
158
+ var _levels_level;
159
+ const level = 'string' == typeof (null == e ? void 0 : e.level) ? e.level : 'info';
160
+ levels[level] = (null != (_levels_level = levels[level]) ? _levels_level : 0) + 1;
161
+ }
162
+ return {
163
+ profile: meta.profile,
164
+ environment: meta.environment,
165
+ findings: {
166
+ total,
167
+ distinct: findings.length,
168
+ bySeverity,
169
+ byRule: [
170
+ ...rules.values()
171
+ ].sort((a, b)=>b.count - a.count || b.last - a.last)
172
+ },
173
+ stalls: stallList ? {
174
+ count: stallList.length,
175
+ worstMs: stallList.reduce((m, s)=>{
176
+ var _num;
177
+ return Math.max(m, null != (_num = num(s.ms)) ? _num : 0);
178
+ }, 0),
179
+ js: stallList.filter((s)=>'js' === s.thread).length,
180
+ main: stallList.filter((s)=>'main' === s.thread).length
181
+ } : null,
182
+ memory: (null == v ? void 0 : v.memory) ? {
183
+ currentMb: num(v.memory.currentMb),
184
+ peakMb: num(v.memory.peakMb),
185
+ baselineMb: num(v.memory.baselineMb)
186
+ } : null,
187
+ traces: Array.isArray(null == t ? void 0 : t.traces) ? {
188
+ count: t.traces.length,
189
+ last: t.traces.slice(-3).reverse()
190
+ } : null,
191
+ log: Array.isArray(null == l ? void 0 : l.entries) ? levels : null
192
+ };
193
+ }
194
+ export { autoReports, createFindingsBuffer, summarize };
package/dist/off.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { G9PilotInfo } from './info.js';
3
+ import type { G9AroundRequestOptions } from './net.js';
4
+ import type { G9PilotHostProps } from './types.js';
5
+ export type { G9ConsentAsk } from './consent.js';
6
+ export type { G9PilotModule, G9PilotProfile, G9PilotSettings } from './flags.js';
7
+ export type { G9PilotInfo } from './info.js';
8
+ export type { G9AroundRequestOptions } from './net.js';
9
+ export type { G9FindingsBuffer, G9PilotFinding, G9PilotReport, G9PilotSummary } from './observe.js';
10
+ export type { G9PilotAuditEntry, G9PilotController, G9PilotSession } from './session.js';
11
+ export type { G9PilotApi, G9PilotHostProps } from './types.js';
12
+ /** False: this build carries no G9AppPilot (an app guards its own command code with it). */
13
+ export declare const G9_PILOT_BRIDGE: boolean;
14
+ /** The request itself: this build does not watch requests (no shaping, no busy reason, no black box). */
15
+ export declare function aroundRequest<T>(_method: string, _url: string, run: () => Promise<T>, _options?: G9AroundRequestOptions<T>): Promise<T>;
16
+ /** A request net.shape failed (never thrown in this build: nothing is shaped). */
17
+ export declare class G9ShapedRequestError extends Error {
18
+ readonly status: number | null;
19
+ constructor(status: number | null, message: string);
20
+ }
21
+ /** Props of G9PilotMask (the same in every build). */
22
+ export interface G9PilotMaskProps {
23
+ readonly children?: ReactNode;
24
+ readonly id?: string;
25
+ readonly className?: string;
26
+ }
27
+ /** The masked box, as a plain box: this build takes no screenshots. */
28
+ export declare function G9PilotMask(props: G9PilotMaskProps): ReactNode;
29
+ /** Renders its children: this build carries no G9AppPilot. */
30
+ export declare function G9PilotHost(props: G9PilotHostProps): ReactNode;
31
+ /** Always null: this build keeps no findings. */
32
+ export declare function g9PilotFindings(): null;
33
+ /** Always null: only a bridge build keeps a session (who talked to this device). */
34
+ export declare function g9PilotSession(): null;
35
+ /** Always `off`: this build carries no G9AppPilot. */
36
+ export declare function g9Pilot(): G9PilotInfo;
37
+ /** Props of G9PilotPanel (this build shows none). */
38
+ export interface G9PilotPanelProps {
39
+ readonly findings?: number;
40
+ }
41
+ /** Nothing: this build carries no watch to show. */
42
+ export declare function G9PilotPanel(_props: G9PilotPanelProps): null;
43
+ /** False: this build has no panel to open. */
44
+ export declare function openG9PilotPanel(_props?: G9PilotPanelProps): boolean;
45
+ //# sourceMappingURL=off.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"off.d.ts","sourceRoot":"","sources":["../src/off.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC9E,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC1C,YAAY,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAC;AACpD,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjG,YAAY,EAAE,iBAAiB,EAAE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AE,iBAAiB,GAAG,IAAI,CAE5D;AAED,8CAA8C;AAC9C,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAEpE"}
package/dist/off.jsx ADDED
@@ -0,0 +1,81 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) Object.defineProperty(obj, key, {
3
+ value: value,
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true
7
+ });
8
+ else obj[key] = value;
9
+ return obj;
10
+ }
11
+ const G9_PILOT_BRIDGE = false;
12
+ function aroundRequest(_method, _url, run, _options) {
13
+ return run();
14
+ }
15
+ class G9ShapedRequestError extends Error {
16
+ constructor(status, message){
17
+ super(message), _define_property(this, "status", void 0), this.status = status;
18
+ this.name = 'G9ShapedRequestError';
19
+ }
20
+ }
21
+ function G9PilotMask(props) {
22
+ return <view className={`g9-pilot-mask${props.className ? ` ${props.className}` : ''}`}>{props.children}</view>;
23
+ }
24
+ function G9PilotHost(props) {
25
+ var _props_children;
26
+ return null != (_props_children = props.children) ? _props_children : null;
27
+ }
28
+ function g9PilotFindings() {
29
+ return null;
30
+ }
31
+ function g9PilotSession() {
32
+ return null;
33
+ }
34
+ const OFF = Object.freeze({
35
+ profile: 'off',
36
+ modules: [],
37
+ settings: Object.freeze({
38
+ environment: null,
39
+ profile: 'off',
40
+ distribution: 'store',
41
+ badge: 'off',
42
+ consent: 'none',
43
+ mask: 'off',
44
+ session: {
45
+ maxMinutes: 0
46
+ },
47
+ selfDrive: {
48
+ maxSeconds: 0
49
+ },
50
+ observe: {
51
+ rules: {},
52
+ sampling: {
53
+ errors: 1,
54
+ vitals: 1,
55
+ traces: 1
56
+ },
57
+ buffer: {
58
+ maxFindings: 200,
59
+ persist: true
60
+ },
61
+ report: {
62
+ via: 'local',
63
+ consent: 'build',
64
+ endpoint: null,
65
+ service: null,
66
+ auto: 0
67
+ }
68
+ },
69
+ maxScopes: []
70
+ })
71
+ });
72
+ function g9Pilot() {
73
+ return OFF;
74
+ }
75
+ function G9PilotPanel(_props) {
76
+ return null;
77
+ }
78
+ function openG9PilotPanel(_props) {
79
+ return false;
80
+ }
81
+ export { G9PilotHost, G9PilotMask, G9PilotPanel, G9ShapedRequestError, G9_PILOT_BRIDGE, aroundRequest, g9Pilot, g9PilotFindings, g9PilotSession, openG9PilotPanel };
package/dist/otlp.d.ts ADDED
@@ -0,0 +1,61 @@
1
+ import type { G9PilotReport } from './observe.js';
2
+ type AnyValue = {
3
+ stringValue: string;
4
+ } | {
5
+ intValue: string;
6
+ } | {
7
+ boolValue: boolean;
8
+ };
9
+ interface KeyValue {
10
+ readonly key: string;
11
+ readonly value: AnyValue;
12
+ }
13
+ /** One OTLP log record (the JSON encoding: 64-bit integers are strings). */
14
+ export interface OtlpLogRecord {
15
+ readonly timeUnixNano: string;
16
+ readonly observedTimeUnixNano: string;
17
+ readonly severityNumber: number;
18
+ readonly severityText: string;
19
+ readonly body: {
20
+ readonly stringValue: string;
21
+ };
22
+ readonly attributes: readonly KeyValue[];
23
+ }
24
+ /** The body of a POST to an OTLP/HTTP logs endpoint. */
25
+ export interface OtlpLogs {
26
+ readonly resourceLogs: ReadonlyArray<{
27
+ readonly resource: {
28
+ readonly attributes: readonly KeyValue[];
29
+ };
30
+ readonly scopeLogs: ReadonlyArray<{
31
+ readonly scope: {
32
+ readonly name: string;
33
+ };
34
+ readonly logRecords: readonly OtlpLogRecord[];
35
+ }>;
36
+ }>;
37
+ }
38
+ /** OTLP severity: TRACE 1 · DEBUG 5 · INFO 9 · WARN 13 · ERROR 17 · FATAL 21. */
39
+ export declare function severityOf(level: string): {
40
+ number: number;
41
+ text: string;
42
+ };
43
+ /** A report as OTLP logs: the resource names the app, the environment and the profile. */
44
+ export declare function toOtlpLogs(report: G9PilotReport, options?: {
45
+ readonly service?: string | null;
46
+ }): OtlpLogs;
47
+ type Fetch = (url: string, init: {
48
+ method: string;
49
+ headers: Record<string, string>;
50
+ body: string;
51
+ }) => Promise<{
52
+ readonly ok: boolean;
53
+ readonly status: number;
54
+ }>;
55
+ /** POSTs the logs; answers whether the collector took them (a network failure is a no, never a throw). */
56
+ export declare function sendOtlp(endpoint: string, logs: OtlpLogs, fetchImpl?: Fetch | undefined): Promise<{
57
+ readonly ok: boolean;
58
+ readonly status: number;
59
+ }>;
60
+ export {};
61
+ //# sourceMappingURL=otlp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otlp.d.ts","sourceRoot":"","sources":["../src/otlp.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,KAAK,QAAQ,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AACxF,UAAU,QAAQ;IAChB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;CAC1B;AACD,4EAA4E;AAC5E,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,QAAQ,CAAC,UAAU,EAAE,SAAS,QAAQ,EAAE,CAAC;CAC1C;AACD,wDAAwD;AACxD,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC;QACnC,QAAQ,CAAC,QAAQ,EAAE;YAAE,QAAQ,CAAC,UAAU,EAAE,SAAS,QAAQ,EAAE,CAAA;SAAE,CAAC;QAChE,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;YAChC,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