@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.
- package/README.md +159 -2
- package/catalog/cards/G9PilotHost.md +16 -0
- package/catalog/cards/G9PilotMask.md +10 -0
- package/catalog/cards/G9PilotPanel.md +10 -0
- package/catalog/catalog.json +420 -0
- package/catalog/index.md +7 -0
- package/check/cli.mjs +5 -0
- package/check/index.mjs +137 -0
- package/check/index.test.mjs +180 -0
- package/config/cli.mjs +31 -0
- package/config/index.d.ts +62 -0
- package/config/index.mjs +380 -0
- package/config/index.test.mjs +406 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/anchors.d.ts +39 -0
- package/dist/anchors.d.ts.map +1 -0
- package/dist/anchors.jsx +103 -0
- package/dist/bridge.d.ts +4 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.jsx +143 -0
- package/dist/busy.d.ts +4 -0
- package/dist/busy.d.ts.map +1 -0
- package/dist/busy.jsx +43 -0
- package/dist/commands.d.ts +24 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.jsx +286 -0
- package/dist/consent.d.ts +51 -0
- package/dist/consent.d.ts.map +1 -0
- package/dist/consent.jsx +131 -0
- package/dist/explore.d.ts +36 -0
- package/dist/explore.d.ts.map +1 -0
- package/dist/explore.jsx +133 -0
- package/dist/flags.d.ts +69 -0
- package/dist/flags.d.ts.map +1 -0
- package/dist/flags.jsx +81 -0
- package/dist/host-core.d.ts +36 -0
- package/dist/host-core.d.ts.map +1 -0
- package/dist/host-core.jsx +90 -0
- package/dist/host-sink.d.ts +43 -0
- package/dist/host-sink.d.ts.map +1 -0
- package/dist/host-sink.jsx +87 -0
- package/dist/index-marks.d.ts +33 -0
- package/dist/index-marks.d.ts.map +1 -0
- package/dist/index-marks.jsx +40 -0
- package/dist/index-observe.d.ts +17 -0
- package/dist/index-observe.d.ts.map +1 -0
- package/dist/index-observe.jsx +14 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.jsx +11 -0
- package/dist/info.d.ts +10 -0
- package/dist/info.d.ts.map +1 -0
- package/dist/info.jsx +9 -0
- package/dist/kit.d.ts +67 -0
- package/dist/kit.d.ts.map +1 -0
- package/dist/kit.jsx +1 -0
- package/dist/layer.d.ts +4 -0
- package/dist/layer.d.ts.map +1 -0
- package/dist/layer.jsx +10 -0
- package/dist/layers.d.ts +4 -0
- package/dist/layers.d.ts.map +1 -0
- package/dist/layers.jsx +146 -0
- package/dist/mask.d.ts +20 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/mask.jsx +35 -0
- package/dist/net.d.ts +17 -0
- package/dist/net.d.ts.map +1 -0
- package/dist/net.jsx +60 -0
- package/dist/observe.d.ts +99 -0
- package/dist/observe.d.ts.map +1 -0
- package/dist/observe.jsx +194 -0
- package/dist/off.d.ts +45 -0
- package/dist/off.d.ts.map +1 -0
- package/dist/off.jsx +81 -0
- package/dist/otlp.d.ts +61 -0
- package/dist/otlp.d.ts.map +1 -0
- package/dist/otlp.jsx +141 -0
- package/dist/panel.d.ts +13 -0
- package/dist/panel.d.ts.map +1 -0
- package/dist/panel.jsx +182 -0
- package/dist/session.d.ts +42 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.jsx +115 -0
- package/dist/types.d.ts +47 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.jsx +1 -0
- package/dist/watch.d.ts +17 -0
- package/dist/watch.d.ts.map +1 -0
- package/dist/watch.jsx +165 -0
- package/doctor/cli.mjs +5 -0
- package/doctor/index.mjs +214 -0
- package/doctor/index.test.mjs +174 -0
- package/gradle/g9pilot.app.gradle +55 -0
- package/gradle/g9pilot.settings.gradle +27 -0
- package/ios/g9pilot.rb +47 -0
- package/package.json +66 -4
- package/rspeedy/index.d.ts +40 -0
- package/rspeedy/index.mjs +100 -0
- package/rspeedy/index.test.mjs +192 -0
package/dist/otlp.jsx
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
const str = (key, value)=>({
|
|
2
|
+
key,
|
|
3
|
+
value: {
|
|
4
|
+
stringValue: value
|
|
5
|
+
}
|
|
6
|
+
});
|
|
7
|
+
const otlp_int = (key, value)=>({
|
|
8
|
+
key,
|
|
9
|
+
value: {
|
|
10
|
+
intValue: String(Math.trunc(value))
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
const nanos = (ms)=>ms > 0 ? `${Math.trunc(ms)}000000` : '0';
|
|
14
|
+
const MAX_BODY = 4000;
|
|
15
|
+
const clip = (text)=>text.length > MAX_BODY ? `${text.slice(0, MAX_BODY)}…` : text;
|
|
16
|
+
function severityOf(level) {
|
|
17
|
+
switch(level.toLowerCase()){
|
|
18
|
+
case 'fatal':
|
|
19
|
+
case 'critical':
|
|
20
|
+
return {
|
|
21
|
+
number: 21,
|
|
22
|
+
text: 'FATAL'
|
|
23
|
+
};
|
|
24
|
+
case 'error':
|
|
25
|
+
return {
|
|
26
|
+
number: 17,
|
|
27
|
+
text: 'ERROR'
|
|
28
|
+
};
|
|
29
|
+
case 'info':
|
|
30
|
+
case 'information':
|
|
31
|
+
return {
|
|
32
|
+
number: 9,
|
|
33
|
+
text: 'INFO'
|
|
34
|
+
};
|
|
35
|
+
case 'debug':
|
|
36
|
+
case 'trace':
|
|
37
|
+
return {
|
|
38
|
+
number: 5,
|
|
39
|
+
text: 'DEBUG'
|
|
40
|
+
};
|
|
41
|
+
default:
|
|
42
|
+
return {
|
|
43
|
+
number: 13,
|
|
44
|
+
text: 'WARN'
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const record = (at, level, body, attributes, observed)=>{
|
|
49
|
+
const s = severityOf(level);
|
|
50
|
+
return {
|
|
51
|
+
timeUnixNano: nanos(at),
|
|
52
|
+
observedTimeUnixNano: nanos(observed),
|
|
53
|
+
severityNumber: s.number,
|
|
54
|
+
severityText: s.text,
|
|
55
|
+
body: {
|
|
56
|
+
stringValue: clip(body)
|
|
57
|
+
},
|
|
58
|
+
attributes
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const textOf = (value)=>{
|
|
62
|
+
if ('string' == typeof value) return value;
|
|
63
|
+
try {
|
|
64
|
+
var _JSON_stringify;
|
|
65
|
+
return null != (_JSON_stringify = JSON.stringify(value)) ? _JSON_stringify : String(value);
|
|
66
|
+
} catch {
|
|
67
|
+
return String(value);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
function toOtlpLogs(report, options = {}) {
|
|
71
|
+
const taken = report.takenAt;
|
|
72
|
+
const records = [];
|
|
73
|
+
for (const f of report.findings)records.push(record(f.at, f.severity, f.message || f.rule, [
|
|
74
|
+
str('event.name', 'g9.finding'),
|
|
75
|
+
str('g9.rule', f.rule),
|
|
76
|
+
str('g9.key', f.key),
|
|
77
|
+
otlp_int('g9.count', f.count)
|
|
78
|
+
], taken));
|
|
79
|
+
for (const t of report.traces){
|
|
80
|
+
const at = 'number' == typeof (null == t ? void 0 : t.at) ? t.at : taken;
|
|
81
|
+
records.push(record(at, 'error', textOf(t), [
|
|
82
|
+
str('event.name', 'g9.trace')
|
|
83
|
+
], taken));
|
|
84
|
+
}
|
|
85
|
+
for (const line of report.log){
|
|
86
|
+
const l = null != line ? line : {};
|
|
87
|
+
const at = 'number' == typeof l.t ? l.t : 'number' == typeof l.at ? l.at : taken;
|
|
88
|
+
const attributes = [
|
|
89
|
+
str('event.name', 'g9.log')
|
|
90
|
+
];
|
|
91
|
+
if ('string' == typeof l.source) attributes.push(str('g9.source', l.source));
|
|
92
|
+
records.push(record(at, 'string' == typeof l.level ? l.level : 'info', 'string' == typeof l.message ? l.message : textOf(line), attributes, taken));
|
|
93
|
+
}
|
|
94
|
+
const resource = [
|
|
95
|
+
str('service.name', options.service || 'g9-lynx-app'),
|
|
96
|
+
str('g9.pilot.profile', report.profile)
|
|
97
|
+
];
|
|
98
|
+
if (report.environment) resource.push(str('deployment.environment.name', report.environment));
|
|
99
|
+
return {
|
|
100
|
+
resourceLogs: [
|
|
101
|
+
{
|
|
102
|
+
resource: {
|
|
103
|
+
attributes: resource
|
|
104
|
+
},
|
|
105
|
+
scopeLogs: [
|
|
106
|
+
{
|
|
107
|
+
scope: {
|
|
108
|
+
name: '@g9tm/lynxcontrols-pilot'
|
|
109
|
+
},
|
|
110
|
+
logRecords: records
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
async function sendOtlp(endpoint, logs, fetchImpl = 'function' == typeof fetch ? fetch : void 0) {
|
|
118
|
+
if (!fetchImpl) return {
|
|
119
|
+
ok: false,
|
|
120
|
+
status: 0
|
|
121
|
+
};
|
|
122
|
+
try {
|
|
123
|
+
const res = await fetchImpl(endpoint, {
|
|
124
|
+
method: 'POST',
|
|
125
|
+
headers: {
|
|
126
|
+
'Content-Type': 'application/json'
|
|
127
|
+
},
|
|
128
|
+
body: JSON.stringify(logs)
|
|
129
|
+
});
|
|
130
|
+
return {
|
|
131
|
+
ok: res.ok,
|
|
132
|
+
status: res.status
|
|
133
|
+
};
|
|
134
|
+
} catch {
|
|
135
|
+
return {
|
|
136
|
+
ok: false,
|
|
137
|
+
status: 0
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export { sendOtlp, severityOf, toOtlpLogs };
|
package/dist/panel.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ReactNode } from '@lynx-js/react';
|
|
2
|
+
/** Props of {@link G9PilotPanel}. */
|
|
3
|
+
export interface G9PilotPanelProps {
|
|
4
|
+
/** How many of the newest findings it lists (default 5). */
|
|
5
|
+
readonly findings?: number;
|
|
6
|
+
}
|
|
7
|
+
/** A finding's rule in the person's language; an unknown rule keeps its own name. */
|
|
8
|
+
export declare function findingLabel(rule: string, language: string): string;
|
|
9
|
+
/** What this device's G9AppPilot is doing, in the person's language, with «stop sharing» and «send report». */
|
|
10
|
+
export declare function G9PilotPanel(props: G9PilotPanelProps): ReactNode;
|
|
11
|
+
/** Shows {@link G9PilotPanel} in a sheet; false when the sheet service refused (throttled, or no host). */
|
|
12
|
+
export declare function openG9PilotPanel(props?: G9PilotPanelProps): boolean;
|
|
13
|
+
//# sourceMappingURL=panel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panel.d.ts","sourceRoot":"","sources":["../src/panel.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,gBAAgB,CAAC;AAOrE,qCAAqC;AACrC,MAAM,WAAW,iBAAiB;IAChC,4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAiCD,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGnE;AAED,+GAA+G;AAC/G,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,SAAS,CAsHhE;AAED,2GAA2G;AAC3G,wBAAgB,gBAAgB,CAAC,KAAK,GAAE,iBAAsB,GAAG,OAAO,CAUvE"}
|
package/dist/panel.jsx
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { dispatch } from "@g9tm/app-pilot";
|
|
2
|
+
import { G9Button } from "@g9tm/lynxcontrols/button";
|
|
3
|
+
import { useG9CultureStore } from "@g9tm/lynxcontrols/provider";
|
|
4
|
+
import { fitToContentSheetOptions, g9Sheets } from "@g9tm/lynxcontrols/sheet";
|
|
5
|
+
import { toNativeDigits } from "@g9tm/lynxcontrols-foundation/culture";
|
|
6
|
+
import { useEffect, useState } from "@lynx-js/react";
|
|
7
|
+
import { g9PilotConsent } from "./consent.jsx";
|
|
8
|
+
import { onPilotHostChange, textFor } from "./host-core.jsx";
|
|
9
|
+
import { g9Pilot } from "./info.jsx";
|
|
10
|
+
import { g9PilotSession } from "./session.jsx";
|
|
11
|
+
import { g9PilotFindings } from "./watch.jsx";
|
|
12
|
+
const box = {
|
|
13
|
+
display: 'flex',
|
|
14
|
+
flexDirection: 'column',
|
|
15
|
+
gap: '12px',
|
|
16
|
+
padding: '16px'
|
|
17
|
+
};
|
|
18
|
+
const section = {
|
|
19
|
+
display: 'flex',
|
|
20
|
+
flexDirection: 'column',
|
|
21
|
+
gap: '6px',
|
|
22
|
+
padding: '12px',
|
|
23
|
+
borderRadius: '12px',
|
|
24
|
+
backgroundColor: 'var(--g9-surface-container)'
|
|
25
|
+
};
|
|
26
|
+
const title = {
|
|
27
|
+
fontSize: '17px',
|
|
28
|
+
fontWeight: '600',
|
|
29
|
+
color: 'var(--g9-text-primary)'
|
|
30
|
+
};
|
|
31
|
+
const heading = {
|
|
32
|
+
fontSize: '14px',
|
|
33
|
+
fontWeight: '600',
|
|
34
|
+
color: 'var(--g9-text-primary)'
|
|
35
|
+
};
|
|
36
|
+
const line = {
|
|
37
|
+
fontSize: '13px',
|
|
38
|
+
color: 'var(--g9-text-secondary)'
|
|
39
|
+
};
|
|
40
|
+
const FINDINGS = {
|
|
41
|
+
'js.error': [
|
|
42
|
+
'خطای برنامه',
|
|
43
|
+
'App error'
|
|
44
|
+
],
|
|
45
|
+
'js.unhandledRejection': [
|
|
46
|
+
'کاری که بیجواب ماند',
|
|
47
|
+
'A task nobody finished'
|
|
48
|
+
],
|
|
49
|
+
'console.error': [
|
|
50
|
+
'خطای ثبتشده در برنامه',
|
|
51
|
+
'An error the app logged'
|
|
52
|
+
],
|
|
53
|
+
'log.error': [
|
|
54
|
+
'خطای ثبتشده در برنامه',
|
|
55
|
+
'An error the app logged'
|
|
56
|
+
],
|
|
57
|
+
'perf.longFrame': [
|
|
58
|
+
'صفحه لحظهای از حرکت ایستاد',
|
|
59
|
+
'The screen stopped for a moment'
|
|
60
|
+
],
|
|
61
|
+
'perf.memoryGrowth': [
|
|
62
|
+
'مصرف حافظه بالا رفت',
|
|
63
|
+
'Memory use kept growing'
|
|
64
|
+
],
|
|
65
|
+
'i18n.latinDigits': [
|
|
66
|
+
'رقم لاتین در متن فارسی',
|
|
67
|
+
'Latin digits in Persian text'
|
|
68
|
+
],
|
|
69
|
+
'i18n.rawKey': [
|
|
70
|
+
'متنی که ترجمه نشده',
|
|
71
|
+
'A text that was never translated'
|
|
72
|
+
],
|
|
73
|
+
'a11y.unlabeled': [
|
|
74
|
+
'دکمهای بینام برای صفحهخوان',
|
|
75
|
+
'A control without a name for screen readers'
|
|
76
|
+
],
|
|
77
|
+
'layout.offScreen': [
|
|
78
|
+
'بخشی بیرون از صفحه',
|
|
79
|
+
'Something drawn off the screen'
|
|
80
|
+
],
|
|
81
|
+
'busy.leak': [
|
|
82
|
+
'انتظاری که تمام نشد',
|
|
83
|
+
'A wait that never ended'
|
|
84
|
+
],
|
|
85
|
+
'sync.silentRejection': [
|
|
86
|
+
'ارسالی که بیصدا رد شد',
|
|
87
|
+
'A send the server refused silently'
|
|
88
|
+
]
|
|
89
|
+
};
|
|
90
|
+
function findingLabel(rule, language) {
|
|
91
|
+
const label = FINDINGS[rule];
|
|
92
|
+
return label ? 'fa' === language ? label[0] : label[1] : rule;
|
|
93
|
+
}
|
|
94
|
+
function G9PilotPanel(props) {
|
|
95
|
+
var _ref, _ref1, _ref2, _props_findings;
|
|
96
|
+
const culture = useG9CultureStore().getSnapshot();
|
|
97
|
+
const t = (fa, en)=>textFor(culture.language, fa, en);
|
|
98
|
+
const n = (v)=>toNativeDigits(String(v), culture.numberingSystem);
|
|
99
|
+
const [, setTick] = useState(0);
|
|
100
|
+
const [sent, setSent] = useState('idle');
|
|
101
|
+
useEffect(()=>{
|
|
102
|
+
const bump = ()=>setTick((x)=>x + 1);
|
|
103
|
+
let offs = [];
|
|
104
|
+
const attach = ()=>{
|
|
105
|
+
var _g9PilotFindings, _g9PilotSession, _g9PilotConsent;
|
|
106
|
+
for (const off of offs)null == off || off();
|
|
107
|
+
offs = [
|
|
108
|
+
null == (_g9PilotFindings = g9PilotFindings()) ? void 0 : _g9PilotFindings.subscribe(bump),
|
|
109
|
+
null == (_g9PilotSession = g9PilotSession()) ? void 0 : _g9PilotSession.subscribe(bump),
|
|
110
|
+
null == (_g9PilotConsent = g9PilotConsent()) ? void 0 : _g9PilotConsent.subscribe(bump)
|
|
111
|
+
];
|
|
112
|
+
bump();
|
|
113
|
+
};
|
|
114
|
+
attach();
|
|
115
|
+
const offHost = onPilotHostChange(attach);
|
|
116
|
+
return ()=>{
|
|
117
|
+
offHost();
|
|
118
|
+
for (const off of offs)null == off || off();
|
|
119
|
+
};
|
|
120
|
+
}, []);
|
|
121
|
+
const info = g9Pilot();
|
|
122
|
+
const findings = g9PilotFindings();
|
|
123
|
+
const session = g9PilotSession();
|
|
124
|
+
const consent = g9PilotConsent();
|
|
125
|
+
const granted = null != (_ref = null == consent ? void 0 : consent.granted()) ? _ref : [];
|
|
126
|
+
const controllers = null != (_ref1 = null == session ? void 0 : session.controllers()) ? _ref1 : [];
|
|
127
|
+
const newest = (null != (_ref2 = null == findings ? void 0 : findings.list()) ? _ref2 : []).slice(-(null != (_props_findings = props.findings) ? _props_findings : 5)).reverse();
|
|
128
|
+
const report = async ()=>{
|
|
129
|
+
setSent('sending');
|
|
130
|
+
const a = await dispatch({
|
|
131
|
+
id: 'g9.panel.report',
|
|
132
|
+
command: 'g9.report',
|
|
133
|
+
args: {},
|
|
134
|
+
kid: 'self-g9.panel',
|
|
135
|
+
scopes: [
|
|
136
|
+
'*'
|
|
137
|
+
]
|
|
138
|
+
});
|
|
139
|
+
setSent(a.ok && a.result.sent ? 'sent' : 'kept');
|
|
140
|
+
};
|
|
141
|
+
return <view style={box} id="G9Pilot.Panel">
|
|
142
|
+
<text style={title}>{t('دستیار آزمون و پشتیبانی', 'Test and support assistant')}</text>
|
|
143
|
+
<text style={line}>
|
|
144
|
+
{`${t('نسخه', 'Build')}: ${info.profile}${info.settings.environment ? ` · ${info.settings.environment}` : ''}`}
|
|
145
|
+
</text>
|
|
146
|
+
<text style={line}>{`${t('بخشها', 'Parts')}: ${info.modules.join(' · ') || '—'}`}</text>
|
|
147
|
+
|
|
148
|
+
{consent ? <view style={section}>
|
|
149
|
+
<text style={heading}>{t('اجازههایی که دادهاید', 'Who you let in')}</text>
|
|
150
|
+
{0 === granted.length ? <text style={line}>{t('هیچکس', 'Nobody')}</text> : granted.map((g)=><text key={g.kid} style={line}>
|
|
151
|
+
{`«${g.kid}»`}
|
|
152
|
+
</text>)}
|
|
153
|
+
<G9Button id="G9Pilot.Panel.StopSharing" variant="errorTonal" text={t('توقف اشتراک', 'Stop sharing')} blocked={0 === granted.length} onPress={()=>consent.revoke()}/>
|
|
154
|
+
</view> : null}
|
|
155
|
+
|
|
156
|
+
{session ? <view style={section}>
|
|
157
|
+
<text style={heading}>{t('چه کسانی وصل شدهاند', 'Who has connected')}</text>
|
|
158
|
+
{0 === controllers.length ? <text style={line}>{t('هیچکس', 'Nobody')}</text> : controllers.map((c)=><text key={c.kid} style={line}>
|
|
159
|
+
{`«${c.kid || t('بینام', 'unnamed')}» · ${n(c.commands)} ${t('درخواست', 1 === c.commands ? 'request' : 'requests')}`}
|
|
160
|
+
</text>)}
|
|
161
|
+
</view> : null}
|
|
162
|
+
|
|
163
|
+
{findings ? <view style={section}>
|
|
164
|
+
<text style={heading}>{`${t('یافتهها', 'Findings')}: ${n(findings.list().length)}`}</text>
|
|
165
|
+
{newest.map((f)=><text key={`${f.rule}:${f.key}`} style={line}>
|
|
166
|
+
{`${findingLabel(f.rule, culture.language)}${f.count > 0 ? ` ×${n(f.count + 1)}` : ''}${'fa' === culture.language ? '' : ` — ${f.message}`}`}
|
|
167
|
+
</text>)}
|
|
168
|
+
<G9Button id="G9Pilot.Panel.Report" variant="tonal" text={'sending' === sent ? t('در حال فرستادن…', 'Sending…') : 'sent' === sent ? t('فرستاده شد', 'Sent') : 'kept' === sent ? t('روی همین دستگاه ماند', 'Kept on this device') : t('فرستادن گزارش', 'Send report')} isLoading={'sending' === sent} onPress={()=>void report()}/>
|
|
169
|
+
</view> : null}
|
|
170
|
+
</view>;
|
|
171
|
+
}
|
|
172
|
+
function openG9PilotPanel(props = {}) {
|
|
173
|
+
try {
|
|
174
|
+
return null !== g9Sheets().show(<G9PilotPanel {...props}/>, {
|
|
175
|
+
...fitToContentSheetOptions(),
|
|
176
|
+
deferContent: false
|
|
177
|
+
});
|
|
178
|
+
} catch {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
export { G9PilotPanel, findingLabel, openG9PilotPanel };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** One answered request, as the audit log keeps it. */
|
|
2
|
+
export interface G9PilotAuditEntry {
|
|
3
|
+
readonly at: number;
|
|
4
|
+
readonly kid: string;
|
|
5
|
+
readonly command: string;
|
|
6
|
+
readonly ok: boolean;
|
|
7
|
+
/** The failure's code (CONSENT, SCOPE, NOT_FOUND…), when it failed. */
|
|
8
|
+
readonly code?: string;
|
|
9
|
+
readonly ms: number;
|
|
10
|
+
}
|
|
11
|
+
/** A controller this session has seen. */
|
|
12
|
+
export interface G9PilotController {
|
|
13
|
+
readonly kid: string;
|
|
14
|
+
readonly first: number;
|
|
15
|
+
readonly last: number;
|
|
16
|
+
readonly commands: number;
|
|
17
|
+
readonly failures: number;
|
|
18
|
+
/** Its most used commands, the most first (five). */
|
|
19
|
+
readonly top: ReadonlyArray<{
|
|
20
|
+
readonly command: string;
|
|
21
|
+
readonly count: number;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
/** What the bridge keeps of who has talked to this device (`g9PilotSession()`; the panel's «who has connected»). */
|
|
25
|
+
export interface G9PilotSession {
|
|
26
|
+
controllers(): readonly G9PilotController[];
|
|
27
|
+
audit(): readonly G9PilotAuditEntry[];
|
|
28
|
+
subscribe(listener: () => void): () => void;
|
|
29
|
+
stop(): void;
|
|
30
|
+
}
|
|
31
|
+
/** Starts noting every answered request; `g9PilotSession()` reads it while the bridge is installed. */
|
|
32
|
+
export declare function createSession(options?: {
|
|
33
|
+
readonly now?: () => number;
|
|
34
|
+
readonly maxAudit?: number;
|
|
35
|
+
}): G9PilotSession;
|
|
36
|
+
/** The session the bridge keeps (null without the bridge, or before it is installed). */
|
|
37
|
+
export declare function g9PilotSession(): G9PilotSession | null;
|
|
38
|
+
/** Installs the session and `g9.session`; returns the uninstaller. */
|
|
39
|
+
export declare function installSession(options?: {
|
|
40
|
+
readonly now?: () => number;
|
|
41
|
+
}): () => void;
|
|
42
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAOA,uDAAuD;AACvD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,uEAAuE;IACvE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED,0CAA0C;AAC1C,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,qDAAqD;IACrD,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACnF;AAED,oHAAoH;AACpH,MAAM,WAAW,cAAc;IAC7B,WAAW,IAAI,SAAS,iBAAiB,EAAE,CAAC;IAC5C,KAAK,IAAI,SAAS,iBAAiB,EAAE,CAAC;IACtC,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,IAAI,IAAI,IAAI,CAAC;CACd;AAaD,uGAAuG;AACvG,wBAAgB,aAAa,CAC3B,OAAO,GAAE;IAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GACxE,cAAc,CA6ChB;AAID,yFAAyF;AACzF,wBAAgB,cAAc,IAAI,cAAc,GAAG,IAAI,CAEtD;AAED,sEAAsE;AACtE,wBAAgB,cAAc,CAAC,OAAO,GAAE;IAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CAAO,GAAG,MAAM,IAAI,CAqCxF"}
|
package/dist/session.jsx
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { dispatch, onAnswer, registerCommand } from "@g9tm/app-pilot";
|
|
2
|
+
const MAX_AUDIT = 500;
|
|
3
|
+
function createSession(options = {}) {
|
|
4
|
+
var _options_now, _options_maxAudit;
|
|
5
|
+
const now = null != (_options_now = options.now) ? _options_now : Date.now;
|
|
6
|
+
const max = Math.max(1, null != (_options_maxAudit = options.maxAudit) ? _options_maxAudit : MAX_AUDIT);
|
|
7
|
+
const seen = new Map();
|
|
8
|
+
const log = [];
|
|
9
|
+
const listeners = new Set();
|
|
10
|
+
const off = onAnswer((request, answer, ms)=>{
|
|
11
|
+
var _request_kid, _seen_get, _s_byCommand_get;
|
|
12
|
+
const kid = null != (_request_kid = request.kid) ? _request_kid : '';
|
|
13
|
+
if (kid.startsWith('self-')) return;
|
|
14
|
+
const at = now();
|
|
15
|
+
const s = null != (_seen_get = seen.get(kid)) ? _seen_get : {
|
|
16
|
+
kid,
|
|
17
|
+
first: at,
|
|
18
|
+
last: at,
|
|
19
|
+
commands: 0,
|
|
20
|
+
failures: 0,
|
|
21
|
+
byCommand: new Map()
|
|
22
|
+
};
|
|
23
|
+
s.last = at;
|
|
24
|
+
s.commands += 1;
|
|
25
|
+
if (!answer.ok) s.failures += 1;
|
|
26
|
+
s.byCommand.set(request.command, (null != (_s_byCommand_get = s.byCommand.get(request.command)) ? _s_byCommand_get : 0) + 1);
|
|
27
|
+
seen.set(kid, s);
|
|
28
|
+
log.push({
|
|
29
|
+
at,
|
|
30
|
+
kid,
|
|
31
|
+
command: request.command,
|
|
32
|
+
ok: answer.ok,
|
|
33
|
+
...answer.ok ? {} : {
|
|
34
|
+
code: answer.code
|
|
35
|
+
},
|
|
36
|
+
ms
|
|
37
|
+
});
|
|
38
|
+
if (log.length > max) log.splice(0, log.length - max);
|
|
39
|
+
for (const l of [
|
|
40
|
+
...listeners
|
|
41
|
+
])l();
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
controllers: ()=>[
|
|
45
|
+
...seen.values()
|
|
46
|
+
].sort((a, b)=>b.last - a.last).map((s)=>({
|
|
47
|
+
kid: s.kid,
|
|
48
|
+
first: s.first,
|
|
49
|
+
last: s.last,
|
|
50
|
+
commands: s.commands,
|
|
51
|
+
failures: s.failures,
|
|
52
|
+
top: [
|
|
53
|
+
...s.byCommand.entries()
|
|
54
|
+
].sort((a, b)=>b[1] - a[1]).slice(0, 5).map(([command, count])=>({
|
|
55
|
+
command,
|
|
56
|
+
count
|
|
57
|
+
}))
|
|
58
|
+
})),
|
|
59
|
+
audit: ()=>log.slice(),
|
|
60
|
+
subscribe (listener) {
|
|
61
|
+
listeners.add(listener);
|
|
62
|
+
return ()=>listeners.delete(listener);
|
|
63
|
+
},
|
|
64
|
+
stop () {
|
|
65
|
+
off();
|
|
66
|
+
listeners.clear();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
let current = null;
|
|
71
|
+
function g9PilotSession() {
|
|
72
|
+
return current;
|
|
73
|
+
}
|
|
74
|
+
function installSession(options = {}) {
|
|
75
|
+
var _options_now;
|
|
76
|
+
const session = createSession(options);
|
|
77
|
+
current = session;
|
|
78
|
+
const startedAt = (null != (_options_now = options.now) ? _options_now : Date.now)();
|
|
79
|
+
const off = registerCommand('g9.session', async (args)=>{
|
|
80
|
+
const lease = await dispatch({
|
|
81
|
+
id: 'g9.session.lease',
|
|
82
|
+
command: 'lease.status',
|
|
83
|
+
args: {},
|
|
84
|
+
kid: 'self-g9.session',
|
|
85
|
+
scopes: [
|
|
86
|
+
'*'
|
|
87
|
+
]
|
|
88
|
+
});
|
|
89
|
+
const audit = session.audit();
|
|
90
|
+
const limit = 'number' == typeof args.limit && args.limit > 0 ? Math.floor(args.limit) : audit.length;
|
|
91
|
+
return {
|
|
92
|
+
startedAt,
|
|
93
|
+
controllers: session.controllers(),
|
|
94
|
+
requests: audit.length,
|
|
95
|
+
lease: lease.ok ? lease.result : null,
|
|
96
|
+
...true === args.export ? {
|
|
97
|
+
audit: audit.slice(-limit)
|
|
98
|
+
} : {}
|
|
99
|
+
};
|
|
100
|
+
}, {
|
|
101
|
+
scope: 'observe',
|
|
102
|
+
mutating: false,
|
|
103
|
+
description: 'Who has talked to this device since the page loaded: each controller (first, last, commands, failures, top commands), the lease; {export: true} adds the audit log (names and outcomes, never arguments).',
|
|
104
|
+
example: {
|
|
105
|
+
export: true,
|
|
106
|
+
limit: 100
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
return ()=>{
|
|
110
|
+
off();
|
|
111
|
+
session.stop();
|
|
112
|
+
if (current === session) current = null;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export { createSession, g9PilotSession, installSession };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { addGate, emit, onPilotFlag, PilotError, recordLog, recordNet, registerCommand, registerStore, registerTraceSection } from '@g9tm/app-pilot';
|
|
2
|
+
import type { selfCall, startSelfDrive, stopSelfDrive } from '@g9tm/app-pilot-lynx';
|
|
3
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
4
|
+
import type { aroundRequest } from './net.js';
|
|
5
|
+
import type { G9PilotReport } from './observe.js';
|
|
6
|
+
/** What the app's own commands get: the registry and the black box's doors, nothing to import. */
|
|
7
|
+
export interface G9PilotApi {
|
|
8
|
+
readonly registerCommand: typeof registerCommand;
|
|
9
|
+
readonly emit: typeof emit;
|
|
10
|
+
readonly PilotError: typeof PilotError;
|
|
11
|
+
readonly addGate: typeof addGate;
|
|
12
|
+
readonly onPilotFlag: typeof onPilotFlag;
|
|
13
|
+
readonly recordLog: typeof recordLog;
|
|
14
|
+
readonly recordNet: typeof recordNet;
|
|
15
|
+
readonly registerStore: typeof registerStore;
|
|
16
|
+
readonly registerTraceSection: typeof registerTraceSection;
|
|
17
|
+
/** Every request of the app through this: net.shape, a busy reason while it runs, a black-box line (net.ts). */
|
|
18
|
+
readonly aroundRequest: typeof aroundRequest;
|
|
19
|
+
/** Self-drive (module `selfDrive`): the page drives itself through its own gate; null when the build has none. */
|
|
20
|
+
readonly selfDrive: {
|
|
21
|
+
readonly start: typeof startSelfDrive;
|
|
22
|
+
readonly call: typeof selfCall;
|
|
23
|
+
readonly stop: typeof stopSelfDrive;
|
|
24
|
+
} | null;
|
|
25
|
+
}
|
|
26
|
+
/** Props of {@link G9PilotHost}. */
|
|
27
|
+
export interface G9PilotHostProps {
|
|
28
|
+
readonly children?: ReactNode;
|
|
29
|
+
/** The app's own commands: called once in a bridge build (never in another), returns the uninstaller. */
|
|
30
|
+
readonly commands?: ((api: G9PilotApi) => (() => void) | undefined) | undefined;
|
|
31
|
+
/** What this app is, for the bridge's manifest (an agent reads it first). */
|
|
32
|
+
readonly notes?: readonly string[];
|
|
33
|
+
/** Test ids of the bottom bar (ui.tap scrolls a control out from under it). */
|
|
34
|
+
readonly bottomBarPrefix?: string;
|
|
35
|
+
/** The «under automation» badge in the app's words (default by the culture's language). */
|
|
36
|
+
readonly badgeLabel?: string;
|
|
37
|
+
/** Where a report goes (observe `report.via: diagnostic`): G9AppDiagnostic, a file, the app's own channel. */
|
|
38
|
+
readonly onReport?: (report: G9PilotReport) => void | Promise<void>;
|
|
39
|
+
/** How consent is asked (default: a G9 confirm in the culture's language). */
|
|
40
|
+
readonly askConsent?: (request: {
|
|
41
|
+
readonly kid: string;
|
|
42
|
+
readonly reading: boolean;
|
|
43
|
+
/** The controller's own words (g9.consent.request), at most 120 characters: show them quoted, as its words. */
|
|
44
|
+
readonly reason?: string;
|
|
45
|
+
}) => Promise<boolean>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,OAAO,EACP,IAAI,EACJ,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACT,eAAe,EACf,aAAa,EACb,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,kGAAkG;AAClG,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,eAAe,EAAE,OAAO,eAAe,CAAC;IACjD,QAAQ,CAAC,IAAI,EAAE,OAAO,IAAI,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,OAAO,UAAU,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,OAAO,OAAO,CAAC;IACjC,QAAQ,CAAC,WAAW,EAAE,OAAO,WAAW,CAAC;IACzC,QAAQ,CAAC,SAAS,EAAE,OAAO,SAAS,CAAC;IACrC,QAAQ,CAAC,SAAS,EAAE,OAAO,SAAS,CAAC;IACrC,QAAQ,CAAC,aAAa,EAAE,OAAO,aAAa,CAAC;IAC7C,QAAQ,CAAC,oBAAoB,EAAE,OAAO,oBAAoB,CAAC;IAC3D,gHAAgH;IAChH,QAAQ,CAAC,aAAa,EAAE,OAAO,aAAa,CAAC;IAC7C,kHAAkH;IAClH,QAAQ,CAAC,SAAS,EAAE;QAClB,QAAQ,CAAC,KAAK,EAAE,OAAO,cAAc,CAAC;QACtC,QAAQ,CAAC,IAAI,EAAE,OAAO,QAAQ,CAAC;QAC/B,QAAQ,CAAC,IAAI,EAAE,OAAO,aAAa,CAAC;KACrC,GAAG,IAAI,CAAC;CACV;AAED,oCAAoC;AACpC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAC9B,yGAAyG;IACzG,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,UAAU,KAAK,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;IAChF,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,+EAA+E;IAC/E,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,2FAA2F;IAC3F,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,8GAA8G;IAC9G,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE;QAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;QAC1B,+GAA+G;QAC/G,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;KAC1B,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACxB"}
|
package/dist/types.jsx
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/watch.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ScreenCheck } from '@g9tm/app-pilot';
|
|
2
|
+
import { type G9PilotHostContext } from './host-core.js';
|
|
3
|
+
import { type G9FindingsBuffer } from './observe.js';
|
|
4
|
+
/** The findings this build keeps (profile `observe` and up), or null when it keeps none. */
|
|
5
|
+
export declare function g9PilotFindings(): G9FindingsBuffer | null;
|
|
6
|
+
/** The Latin-digits rule of the culture, fields left out: the screen check `g9.latinDigits`. */
|
|
7
|
+
export declare const latinDigitsOutsideFields: ScreenCheck;
|
|
8
|
+
/** The ui.* commands over the kit's layer model (ui.snapshot feeds the screen rules; with a bridge, every ui.*). */
|
|
9
|
+
export declare function installScreen(ctx: G9PilotHostContext): () => void;
|
|
10
|
+
/**
|
|
11
|
+
* The person's yes to one report leaving the device (observe `report.consent: user`): the app's own prompt, else a G9
|
|
12
|
+
* confirm in the culture's language. No host to ask on (or a failing prompt) is a no: the report stays here.
|
|
13
|
+
*/
|
|
14
|
+
export declare function askReportConsent(ctx: G9PilotHostContext): Promise<boolean>;
|
|
15
|
+
/** Installs the watch; returns the uninstaller. */
|
|
16
|
+
export declare function installWatch(ctx: G9PilotHostContext): () => void;
|
|
17
|
+
//# sourceMappingURL=watch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../src/watch.ts"],"names":[],"mappings":"AAGA,OAAO,EAQL,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAE,KAAK,kBAAkB,EAAgB,MAAM,aAAa,CAAC;AAGpE,OAAO,EAAqC,KAAK,gBAAgB,EAAiC,MAAM,WAAW,CAAC;AAKpH,4FAA4F;AAC5F,wBAAgB,eAAe,IAAI,gBAAgB,GAAG,IAAI,CAEzD;AAcD,gGAAgG;AAChG,eAAO,MAAM,wBAAwB,EAAE,WAIpC,CAAC;AAEJ,oHAAoH;AACpH,wBAAgB,aAAa,CAAC,GAAG,EAAE,kBAAkB,GAAG,MAAM,IAAI,CAUjE;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,CAoBhF;AAED,mDAAmD;AACnD,wBAAgB,YAAY,CAAC,GAAG,EAAE,kBAAkB,GAAG,MAAM,IAAI,CAoFhE"}
|