@mihe-dev/js 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +114 -2
- package/dist/audio.d.ts +121 -0
- package/dist/audio.d.ts.map +1 -0
- package/dist/audio.js +377 -0
- package/dist/audio.js.map +1 -0
- package/dist/card-view.d.ts +79 -0
- package/dist/card-view.d.ts.map +1 -0
- package/dist/card-view.js +99 -0
- package/dist/card-view.js.map +1 -0
- package/dist/chart.d.ts +15 -0
- package/dist/chart.d.ts.map +1 -0
- package/dist/chart.js +58 -0
- package/dist/chart.js.map +1 -0
- package/dist/client.d.ts +226 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +358 -0
- package/dist/client.js.map +1 -0
- package/dist/commands.d.ts +70 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +295 -0
- package/dist/commands.js.map +1 -0
- package/dist/debug.d.ts +17 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +29 -0
- package/dist/debug.js.map +1 -0
- package/dist/declarations.d.ts +160 -0
- package/dist/declarations.d.ts.map +1 -0
- package/dist/declarations.js +171 -0
- package/dist/declarations.js.map +1 -0
- package/dist/highlight.d.ts +77 -0
- package/dist/highlight.d.ts.map +1 -0
- package/dist/highlight.js +233 -0
- package/dist/highlight.js.map +1 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/mihe.d.ts +364 -0
- package/dist/mihe.d.ts.map +1 -0
- package/dist/mihe.iife.min.js +217 -0
- package/dist/mihe.iife.min.js.map +7 -0
- package/dist/mihe.js +758 -0
- package/dist/mihe.js.map +1 -0
- package/dist/mihe.min.js +217 -0
- package/dist/mihe.min.js.map +7 -0
- package/dist/store.d.ts +175 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +208 -0
- package/dist/store.js.map +1 -0
- package/dist/voice.d.ts +192 -0
- package/dist/voice.d.ts.map +1 -0
- package/dist/voice.js +443 -0
- package/dist/voice.js.map +1 -0
- package/dist/widget/card.d.ts +17 -0
- package/dist/widget/card.d.ts.map +1 -0
- package/dist/widget/card.js +31 -0
- package/dist/widget/card.js.map +1 -0
- package/dist/widget/dom.d.ts +24 -0
- package/dist/widget/dom.d.ts.map +1 -0
- package/dist/widget/dom.js +49 -0
- package/dist/widget/dom.js.map +1 -0
- package/dist/widget/element.d.ts +88 -0
- package/dist/widget/element.d.ts.map +1 -0
- package/dist/widget/element.js +285 -0
- package/dist/widget/element.js.map +1 -0
- package/dist/widget/format.d.ts +24 -0
- package/dist/widget/format.d.ts.map +1 -0
- package/dist/widget/format.js +64 -0
- package/dist/widget/format.js.map +1 -0
- package/dist/widget/icons.d.ts +5 -0
- package/dist/widget/icons.d.ts.map +1 -0
- package/dist/widget/icons.js +19 -0
- package/dist/widget/icons.js.map +1 -0
- package/dist/widget/launcher.d.ts +13 -0
- package/dist/widget/launcher.d.ts.map +1 -0
- package/dist/widget/launcher.js +27 -0
- package/dist/widget/launcher.js.map +1 -0
- package/dist/widget/mark.d.ts +10 -0
- package/dist/widget/mark.d.ts.map +1 -0
- package/dist/widget/mark.js +20 -0
- package/dist/widget/mark.js.map +1 -0
- package/dist/widget/orb.d.ts +92 -0
- package/dist/widget/orb.d.ts.map +1 -0
- package/dist/widget/orb.js +500 -0
- package/dist/widget/orb.js.map +1 -0
- package/dist/widget/panel.d.ts +40 -0
- package/dist/widget/panel.d.ts.map +1 -0
- package/dist/widget/panel.js +240 -0
- package/dist/widget/panel.js.map +1 -0
- package/dist/widget/styles.d.ts +22 -0
- package/dist/widget/styles.d.ts.map +1 -0
- package/dist/widget/styles.js +192 -0
- package/dist/widget/styles.js.map +1 -0
- package/package.json +43 -4
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a confirmation card says (amendment 99), worked out once per proposal
|
|
3
|
+
* and drawn by every card Mihe has: the web component's and the React SDK's.
|
|
4
|
+
*
|
|
5
|
+
* Two sources, both trusted, neither the model:
|
|
6
|
+
*
|
|
7
|
+
* 1. **The app's own description.** `describeProposal` (an option) is handed
|
|
8
|
+
* the proposal, exactly the input that will run, and returns the lines to
|
|
9
|
+
* show: before and after, money in the store's currency, thumbnails. It is
|
|
10
|
+
* the app's code over the app's data, so it can say what a generic card
|
|
11
|
+
* can't. It must describe the input it was given, never anything else.
|
|
12
|
+
* 2. **The registry's display hints**, for an app that doesn't describe a
|
|
13
|
+
* card. They live in the action's input schema as annotations: a summary
|
|
14
|
+
* template at the root (`x-mihe-summary`), and on each field a `title`,
|
|
15
|
+
* `x-mihe-format` (`money`, `yesno`, `date`) and `x-mihe-hidden`. Fields
|
|
16
|
+
* are shown in the schema's order. Hide only an opaque id that has a
|
|
17
|
+
* readable name beside it which the app checks: everything else that will
|
|
18
|
+
* run must be on the card.
|
|
19
|
+
*
|
|
20
|
+
* With neither, the card is what it always was: every field, by its key.
|
|
21
|
+
*/
|
|
22
|
+
import type { ProposalPayload } from "./client.js";
|
|
23
|
+
/** One line of a card. */
|
|
24
|
+
export interface CardLine {
|
|
25
|
+
/** What the line is about: "Price", "Amber Soy Candle". */
|
|
26
|
+
label?: string;
|
|
27
|
+
/** The value, or what it becomes. */
|
|
28
|
+
text?: string;
|
|
29
|
+
/** What it was before, shown struck through ahead of `text`. */
|
|
30
|
+
before?: string;
|
|
31
|
+
/** A list, each entry on its own line so each can be checked. */
|
|
32
|
+
items?: string[];
|
|
33
|
+
/** Pictures of what the line is about, small. http(s), blob: and data:image only. */
|
|
34
|
+
images?: {
|
|
35
|
+
src: string;
|
|
36
|
+
alt?: string;
|
|
37
|
+
}[];
|
|
38
|
+
}
|
|
39
|
+
/** What `describeProposal` returns. */
|
|
40
|
+
export interface ProposalDescription {
|
|
41
|
+
/** One line saying what will happen: "Change Linen Shirt's price". */
|
|
42
|
+
summary?: string;
|
|
43
|
+
lines: CardLine[];
|
|
44
|
+
/** A short note under the lines: "All start as drafts." */
|
|
45
|
+
note?: string;
|
|
46
|
+
/** The confirm button's words: "Make 3 products". Defaults to "Confirm". */
|
|
47
|
+
confirmLabel?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Describes a proposal for its card, from the app's own data. Return null (or
|
|
51
|
+
* throw) to fall back to the registry's hints. Called once per proposal; the
|
|
52
|
+
* card waits for it, with Confirm disabled, for up to four seconds.
|
|
53
|
+
*/
|
|
54
|
+
export type DescribeProposal = (proposal: ProposalPayload) => ProposalDescription | null | undefined | Promise<ProposalDescription | null | undefined>;
|
|
55
|
+
/** A card ready to draw. */
|
|
56
|
+
export interface CardView extends ProposalDescription {
|
|
57
|
+
/** Where it came from: the app, the registry's hints, or neither. */
|
|
58
|
+
source: "app" | "hints" | "plain";
|
|
59
|
+
}
|
|
60
|
+
type Schema = {
|
|
61
|
+
title?: unknown;
|
|
62
|
+
properties?: Record<string, Schema>;
|
|
63
|
+
items?: Schema;
|
|
64
|
+
"x-mihe-summary"?: unknown;
|
|
65
|
+
"x-mihe-format"?: unknown;
|
|
66
|
+
"x-mihe-hidden"?: unknown;
|
|
67
|
+
};
|
|
68
|
+
/** One value, as its field's hints say to show it. */
|
|
69
|
+
export declare function formatField(value: unknown, schema: unknown): string;
|
|
70
|
+
/** `x-mihe-summary`, filled from the input: "Change {productName}" → "Change Linen Shirt". Null if a field it names is missing. */
|
|
71
|
+
export declare function fillSummary(template: unknown, input: Record<string, unknown>, schema: Schema): string | null;
|
|
72
|
+
/** The card from the registry's hints (or, with none, every field by its key). */
|
|
73
|
+
export declare function hintedView(proposal: ProposalPayload): CardView;
|
|
74
|
+
/** The app's description, made safe to draw (only plain strings, only picture addresses that can't run anything). */
|
|
75
|
+
export declare function appView(d: ProposalDescription): CardView;
|
|
76
|
+
/** How long a card waits for the app's description before drawing from the hints. */
|
|
77
|
+
export declare const DESCRIBE_TIMEOUT_MS = 4000;
|
|
78
|
+
export {};
|
|
79
|
+
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AAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAAC,eAAe,CAAC,EAAE,OAAO,CAAC;IAAC,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAKzK,sDAAsD;AACtD,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAgBnE;AAED,mIAAmI;AACnI,wBAAgB,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAS5G;AAED,kFAAkF;AAClF,wBAAgB,UAAU,CAAC,QAAQ,EAAE,eAAe,GAAG,QAAQ,CAa9D;AAID,qHAAqH;AACrH,wBAAgB,OAAO,CAAC,CAAC,EAAE,mBAAmB,GAAG,QAAQ,CAexD;AAED,qFAAqF;AACrF,eAAO,MAAM,mBAAmB,OAAO,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a confirmation card says (amendment 99), worked out once per proposal
|
|
3
|
+
* and drawn by every card Mihe has: the web component's and the React SDK's.
|
|
4
|
+
*
|
|
5
|
+
* Two sources, both trusted, neither the model:
|
|
6
|
+
*
|
|
7
|
+
* 1. **The app's own description.** `describeProposal` (an option) is handed
|
|
8
|
+
* the proposal, exactly the input that will run, and returns the lines to
|
|
9
|
+
* show: before and after, money in the store's currency, thumbnails. It is
|
|
10
|
+
* the app's code over the app's data, so it can say what a generic card
|
|
11
|
+
* can't. It must describe the input it was given, never anything else.
|
|
12
|
+
* 2. **The registry's display hints**, for an app that doesn't describe a
|
|
13
|
+
* card. They live in the action's input schema as annotations: a summary
|
|
14
|
+
* template at the root (`x-mihe-summary`), and on each field a `title`,
|
|
15
|
+
* `x-mihe-format` (`money`, `yesno`, `date`) and `x-mihe-hidden`. Fields
|
|
16
|
+
* are shown in the schema's order. Hide only an opaque id that has a
|
|
17
|
+
* readable name beside it which the app checks: everything else that will
|
|
18
|
+
* run must be on the card.
|
|
19
|
+
*
|
|
20
|
+
* With neither, the card is what it always was: every field, by its key.
|
|
21
|
+
*/
|
|
22
|
+
import { formatValue, humanizeKey } from "./widget/format.js";
|
|
23
|
+
const asSchema = (v) => (v && typeof v === "object" ? v : {});
|
|
24
|
+
const hidden = (s) => s["x-mihe-hidden"] === true;
|
|
25
|
+
const title = (key, s) => (typeof s.title === "string" && s.title.trim() ? s.title : humanizeKey(key));
|
|
26
|
+
/** One value, as its field's hints say to show it. */
|
|
27
|
+
export function formatField(value, schema) {
|
|
28
|
+
const s = asSchema(schema);
|
|
29
|
+
const fmt = s["x-mihe-format"];
|
|
30
|
+
if (fmt === "yesno" && typeof value === "boolean")
|
|
31
|
+
return value ? "Yes" : "No";
|
|
32
|
+
if (fmt === "money" && typeof value === "number")
|
|
33
|
+
return value.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
34
|
+
if (fmt === "date" && typeof value === "string" && !Number.isNaN(Date.parse(value)))
|
|
35
|
+
return new Date(value).toLocaleDateString(undefined, { day: "numeric", month: "short", year: "numeric" });
|
|
36
|
+
if (Array.isArray(value))
|
|
37
|
+
return value.map((v) => formatField(v, s.items)).join(", ") || "—";
|
|
38
|
+
if (value && typeof value === "object") {
|
|
39
|
+
const props = s.properties ?? {};
|
|
40
|
+
const keys = [...Object.keys(props).filter((k) => k in value), ...Object.keys(value).filter((k) => !(k in props))];
|
|
41
|
+
const visible = keys.filter((k) => !hidden(asSchema(props[k])));
|
|
42
|
+
// With hints, an object reads as its fields in order, labelled by their titles ("Amber Candle · Price 18").
|
|
43
|
+
if (Object.keys(props).length)
|
|
44
|
+
return visible.map((k) => (k === visible[0] && typeof value[k] === "string" ? String(value[k]) : `${title(k, asSchema(props[k]))} ${formatField(value[k], props[k])}`)).join(" · ");
|
|
45
|
+
return formatValue(value);
|
|
46
|
+
}
|
|
47
|
+
return formatValue(value);
|
|
48
|
+
}
|
|
49
|
+
/** `x-mihe-summary`, filled from the input: "Change {productName}" → "Change Linen Shirt". Null if a field it names is missing. */
|
|
50
|
+
export function fillSummary(template, input, schema) {
|
|
51
|
+
if (typeof template !== "string" || !template.trim())
|
|
52
|
+
return null;
|
|
53
|
+
let missing = false;
|
|
54
|
+
const out = template.replace(/\{([A-Za-z0-9_]+)\}/g, (_, key) => {
|
|
55
|
+
const v = input[key];
|
|
56
|
+
if (v === undefined || v === null || v === "") {
|
|
57
|
+
missing = true;
|
|
58
|
+
return "";
|
|
59
|
+
}
|
|
60
|
+
return Array.isArray(v) ? String(v.length) : formatField(v, schema.properties?.[key]);
|
|
61
|
+
});
|
|
62
|
+
return missing ? null : out;
|
|
63
|
+
}
|
|
64
|
+
/** The card from the registry's hints (or, with none, every field by its key). */
|
|
65
|
+
export function hintedView(proposal) {
|
|
66
|
+
const schema = asSchema(proposal.inputSchema);
|
|
67
|
+
const props = schema.properties ?? {};
|
|
68
|
+
const input = proposal.input ?? {};
|
|
69
|
+
const hinted = !!schema["x-mihe-summary"] || Object.values(props).some((p) => { const s = asSchema(p); return typeof s.title === "string" || hidden(s) || s["x-mihe-format"] !== undefined; });
|
|
70
|
+
const keys = [...Object.keys(props).filter((k) => k in input), ...Object.keys(input).filter((k) => !(k in props))];
|
|
71
|
+
const lines = keys.filter((k) => !hidden(asSchema(props[k]))).map((k) => {
|
|
72
|
+
const v = input[k];
|
|
73
|
+
const label = hinted ? title(k, asSchema(props[k])) : humanizeKey(k);
|
|
74
|
+
return Array.isArray(v) && v.length > 0 ? { label, items: v.map((x) => formatField(x, asSchema(props[k]).items)) } : { label, text: formatField(v, props[k]) };
|
|
75
|
+
});
|
|
76
|
+
const summary = fillSummary(schema["x-mihe-summary"], input, schema) ?? undefined;
|
|
77
|
+
return { source: hinted ? "hints" : "plain", ...(summary ? { summary } : {}), lines };
|
|
78
|
+
}
|
|
79
|
+
const SAFE_SRC = /^(https?:|blob:|data:image\/)/i;
|
|
80
|
+
/** The app's description, made safe to draw (only plain strings, only picture addresses that can't run anything). */
|
|
81
|
+
export function appView(d) {
|
|
82
|
+
const str = (v) => (typeof v === "string" ? v : v === undefined || v === null ? undefined : String(v));
|
|
83
|
+
return {
|
|
84
|
+
source: "app",
|
|
85
|
+
...(str(d.summary) ? { summary: str(d.summary) } : {}),
|
|
86
|
+
...(str(d.note) ? { note: str(d.note) } : {}),
|
|
87
|
+
...(str(d.confirmLabel) ? { confirmLabel: str(d.confirmLabel) } : {}),
|
|
88
|
+
lines: (Array.isArray(d.lines) ? d.lines : []).map((l) => ({
|
|
89
|
+
...(str(l.label) ? { label: str(l.label) } : {}),
|
|
90
|
+
...(str(l.text) !== undefined ? { text: str(l.text) } : {}),
|
|
91
|
+
...(str(l.before) !== undefined ? { before: str(l.before) } : {}),
|
|
92
|
+
...(Array.isArray(l.items) ? { items: l.items.map((x) => String(x)) } : {}),
|
|
93
|
+
...(Array.isArray(l.images) ? { images: l.images.filter((im) => im && typeof im.src === "string" && SAFE_SRC.test(im.src)).slice(0, 12).map((im) => ({ src: im.src, ...(str(im.alt) ? { alt: str(im.alt) } : {}) })) } : {}),
|
|
94
|
+
})),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** How long a card waits for the app's description before drawing from the hints. */
|
|
98
|
+
export const DESCRIBE_TIMEOUT_MS = 4000;
|
|
99
|
+
//# sourceMappingURL=card-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card-view.js","sourceRoot":"","sources":["../../../js/src/card-view.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAyC3D,MAAM,QAAQ,GAAG,CAAC,CAAU,EAAU,EAAE,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KA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,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,OAAO,EAAE,CAAC,GAAG,KAAK,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC7N,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAED,qFAAqF;AACrF,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC"}
|
package/dist/chart.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chart summaries, worked out where the numbers are (amendment 67, step 4).
|
|
3
|
+
*
|
|
4
|
+
* The model explains a trend from these figures, so it is handed the start,
|
|
5
|
+
* end, high, low, total and largest steps rather than a list to do arithmetic
|
|
6
|
+
* over, which models get wrong.
|
|
7
|
+
*/
|
|
8
|
+
import type { ChartPoint, SeriesSummary } from "@mihe-dev/protocol";
|
|
9
|
+
export declare function summarise(points: ChartPoint[], ordered: boolean): SeriesSummary | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* At most `limit` points, evenly spaced, keeping both ends. The summary
|
|
12
|
+
* already carries the high and low, which thinning could skip.
|
|
13
|
+
*/
|
|
14
|
+
export declare function thin<T>(points: T[], limit: number): T[];
|
|
15
|
+
//# sourceMappingURL=chart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart.d.ts","sourceRoot":"","sources":["../../../js/src/chart.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAa,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE/E,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,OAAO,EAAE,OAAO,GAAG,aAAa,GAAG,SAAS,CAoC3F;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,CAKvD"}
|
package/dist/chart.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chart summaries, worked out where the numbers are (amendment 67, step 4).
|
|
3
|
+
*
|
|
4
|
+
* The model explains a trend from these figures, so it is handed the start,
|
|
5
|
+
* end, high, low, total and largest steps rather than a list to do arithmetic
|
|
6
|
+
* over, which models get wrong.
|
|
7
|
+
*/
|
|
8
|
+
export function summarise(points, ordered) {
|
|
9
|
+
const [first] = points;
|
|
10
|
+
if (!first)
|
|
11
|
+
return undefined;
|
|
12
|
+
const last = points[points.length - 1];
|
|
13
|
+
let min = first;
|
|
14
|
+
let max = first;
|
|
15
|
+
let total = 0;
|
|
16
|
+
let rise;
|
|
17
|
+
let fall;
|
|
18
|
+
points.forEach((point, i) => {
|
|
19
|
+
total += point.y;
|
|
20
|
+
if (point.y < min.y)
|
|
21
|
+
min = point;
|
|
22
|
+
if (point.y > max.y)
|
|
23
|
+
max = point;
|
|
24
|
+
if (!ordered || i === 0)
|
|
25
|
+
return;
|
|
26
|
+
const previous = points[i - 1];
|
|
27
|
+
const change = point.y - previous.y;
|
|
28
|
+
if (change > 0 && (!rise || change > rise.change)) {
|
|
29
|
+
rise = { from: previous.x, to: point.x, change };
|
|
30
|
+
}
|
|
31
|
+
if (change < 0 && (!fall || change < fall.change)) {
|
|
32
|
+
fall = { from: previous.x, to: point.x, change };
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
points: points.length,
|
|
37
|
+
first,
|
|
38
|
+
last,
|
|
39
|
+
min,
|
|
40
|
+
max,
|
|
41
|
+
total: Math.round(total * 100) / 100,
|
|
42
|
+
...(rise ? { largestRise: rise } : {}),
|
|
43
|
+
...(fall ? { largestFall: fall } : {}),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* At most `limit` points, evenly spaced, keeping both ends. The summary
|
|
48
|
+
* already carries the high and low, which thinning could skip.
|
|
49
|
+
*/
|
|
50
|
+
export function thin(points, limit) {
|
|
51
|
+
if (points.length <= limit)
|
|
52
|
+
return points;
|
|
53
|
+
if (limit <= 1)
|
|
54
|
+
return points.slice(0, 1);
|
|
55
|
+
const step = (points.length - 1) / (limit - 1);
|
|
56
|
+
return Array.from({ length: limit }, (_, i) => points[Math.round(i * step)]);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=chart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart.js","sourceRoot":"","sources":["../../../js/src/chart.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,UAAU,SAAS,CAAC,MAAoB,EAAE,OAAgB;IAC9D,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC;IACvB,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC;IAExC,IAAI,GAAG,GAAG,KAAK,CAAC;IAChB,IAAI,GAAG,GAAG,KAAK,CAAC;IAChB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,IAA2B,CAAC;IAChC,IAAI,IAA2B,CAAC;IAEhC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;QAC1B,K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AI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,IAAI,CAAI,MAAW,EAAE,KAAa;IAChD,IAAI,MAAM,CAAC,MAAM,IAAI,KAAK;QAAE,OAAO,MAAM,CAAC;IAC1C,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAC/C,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAE,CAAC,CAAC;AAChF,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The WebSocket client (doc 02).
|
|
3
|
+
*
|
|
4
|
+
* One persistent socket per session carries chat, commands, and
|
|
5
|
+
* confirmations. Two properties drive the design:
|
|
6
|
+
*
|
|
7
|
+
* - A frontend action is a tool call that round-trips through the browser, so
|
|
8
|
+
* the runtime pushes a command and blocks until this client acks it. Every
|
|
9
|
+
* command MUST be answered, including on failure — an unanswered command
|
|
10
|
+
* stalls the assistant's turn until the runtime's timeout fires.
|
|
11
|
+
* - Confirming an action needs server-to-client push, which is why this is a
|
|
12
|
+
* socket rather than a request per message.
|
|
13
|
+
*
|
|
14
|
+
* The client owns transport only. It never decides what a command means; the
|
|
15
|
+
* provider does that and hands back a result.
|
|
16
|
+
*/
|
|
17
|
+
import type { ContextReport } from "./debug.js";
|
|
18
|
+
import { type AssistantCommand, type KnowledgeSourceRef, type ProposalStatus, type ScreenContext, type WidgetSettings } from "@mihe-dev/protocol";
|
|
19
|
+
export type ConnectionState = "idle" | "connecting" | "open" | "reconnecting" | "closed";
|
|
20
|
+
/** What the provider needs to react to. */
|
|
21
|
+
export type ClientEvent = {
|
|
22
|
+
type: "state";
|
|
23
|
+
state: ConnectionState;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Answered on every handshake, so it cannot drift out of step with the
|
|
27
|
+
* connection the way a one-shot probe could.
|
|
28
|
+
*/
|
|
29
|
+
| {
|
|
30
|
+
type: "voice_available";
|
|
31
|
+
available: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* What the assistant calls itself, from the app's settings.
|
|
35
|
+
*
|
|
36
|
+
* Re-sent on every handshake for the same reason `voice_available` is: a
|
|
37
|
+
* rename takes effect on the next session rather than on the next deploy of
|
|
38
|
+
* the host app.
|
|
39
|
+
*/
|
|
40
|
+
| {
|
|
41
|
+
type: "assistant_name";
|
|
42
|
+
name: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The customer's launcher icon from the app's settings, or `null` for the
|
|
46
|
+
* Mihe mark. Emitted on every handshake, absent or not: unlike the name,
|
|
47
|
+
* removing an icon has to take effect, and an absent field is how the
|
|
48
|
+
* runtime says "the default".
|
|
49
|
+
*/
|
|
50
|
+
| {
|
|
51
|
+
type: "launcher_icon";
|
|
52
|
+
url: string | null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* How the widget presents itself, from the app's settings (amendment 61).
|
|
56
|
+
* `null` from a runtime too old to send any, which leaves the SDK's own
|
|
57
|
+
* defaults and the host's props in charge.
|
|
58
|
+
*/
|
|
59
|
+
| {
|
|
60
|
+
type: "widget_settings";
|
|
61
|
+
settings: WidgetSettings | null;
|
|
62
|
+
} | {
|
|
63
|
+
type: "turn_start";
|
|
64
|
+
turnId: string;
|
|
65
|
+
} | {
|
|
66
|
+
type: "delta";
|
|
67
|
+
turnId: string;
|
|
68
|
+
text: string;
|
|
69
|
+
} | {
|
|
70
|
+
type: "complete";
|
|
71
|
+
turnId: string;
|
|
72
|
+
message: string;
|
|
73
|
+
/** Documentation the answer drew on. Empty when none was used. */
|
|
74
|
+
sources: KnowledgeSourceRef[];
|
|
75
|
+
} | {
|
|
76
|
+
type: "command";
|
|
77
|
+
commandId: string;
|
|
78
|
+
command: AssistantCommand;
|
|
79
|
+
} | {
|
|
80
|
+
type: "proposal";
|
|
81
|
+
proposal: ProposalPayload;
|
|
82
|
+
} | {
|
|
83
|
+
type: "action_status";
|
|
84
|
+
proposalId: string;
|
|
85
|
+
status: ProposalStatus;
|
|
86
|
+
result?: unknown;
|
|
87
|
+
error?: string;
|
|
88
|
+
} | {
|
|
89
|
+
type: "error";
|
|
90
|
+
code: string;
|
|
91
|
+
message: string;
|
|
92
|
+
recoverable: boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A single-use permit for the voice socket, in reply to
|
|
96
|
+
* `requestVoiceToken`. Short-lived by design — see doc 03.
|
|
97
|
+
*/
|
|
98
|
+
| {
|
|
99
|
+
type: "voice_token";
|
|
100
|
+
token: string;
|
|
101
|
+
expiresAt: string;
|
|
102
|
+
}
|
|
103
|
+
/** What one answer on this screen re-sends, when `debug` is on. */
|
|
104
|
+
| {
|
|
105
|
+
type: "context_report";
|
|
106
|
+
report: ContextReport;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* A confirmation card's contents.
|
|
110
|
+
*
|
|
111
|
+
* Every human-readable field here comes from the runtime's registry, never
|
|
112
|
+
* from model output — that is the prompt-injection firebreak, and it is why
|
|
113
|
+
* the widget renders exclusively from this payload and never from the
|
|
114
|
+
* assistant's prose.
|
|
115
|
+
*/
|
|
116
|
+
export interface ProposalPayload {
|
|
117
|
+
proposalId: string;
|
|
118
|
+
actionName: string;
|
|
119
|
+
label: string;
|
|
120
|
+
description: string;
|
|
121
|
+
risk: "low" | "medium" | "high";
|
|
122
|
+
input: Record<string, unknown>;
|
|
123
|
+
inputSchema: unknown;
|
|
124
|
+
expiresAt: string;
|
|
125
|
+
uiConfirmationRequired: boolean;
|
|
126
|
+
}
|
|
127
|
+
export interface ClientOptions {
|
|
128
|
+
/** Runtime WebSocket URL, e.g. `wss://runtime.example.com/v1/ws`. */
|
|
129
|
+
url: string;
|
|
130
|
+
publicKey: string;
|
|
131
|
+
/**
|
|
132
|
+
* Fetches a user token from the host app's own backend, which mints it
|
|
133
|
+
* signed with the app secret.
|
|
134
|
+
*
|
|
135
|
+
* Called on every connect and reconnect rather than once, so a token that
|
|
136
|
+
* expired while the tab was backgrounded is replaced rather than replayed.
|
|
137
|
+
*/
|
|
138
|
+
getUserToken: () => Promise<string>;
|
|
139
|
+
sdkVersion: string;
|
|
140
|
+
onEvent: (event: ClientEvent) => void;
|
|
141
|
+
/**
|
|
142
|
+
* Ask the runtime what each screen costs, reported after every screen
|
|
143
|
+
* update (amendment 67). For building the integration, not for production.
|
|
144
|
+
*/
|
|
145
|
+
debug?: boolean;
|
|
146
|
+
/** Injectable for tests. */
|
|
147
|
+
socketFactory?: (url: string) => WebSocketLike;
|
|
148
|
+
/** Injectable for tests; defaults to exponential backoff with jitter. */
|
|
149
|
+
reconnectDelay?: (attempt: number) => number;
|
|
150
|
+
}
|
|
151
|
+
/** The slice of `WebSocket` this client uses, so tests can supply a fake. */
|
|
152
|
+
export interface WebSocketLike {
|
|
153
|
+
send(data: string): void;
|
|
154
|
+
close(): void;
|
|
155
|
+
onopen: ((event: unknown) => void) | null;
|
|
156
|
+
onclose: ((event: unknown) => void) | null;
|
|
157
|
+
onerror: ((event: unknown) => void) | null;
|
|
158
|
+
onmessage: ((event: {
|
|
159
|
+
data: unknown;
|
|
160
|
+
}) => void) | null;
|
|
161
|
+
}
|
|
162
|
+
export declare class AssistantClient {
|
|
163
|
+
private readonly options;
|
|
164
|
+
private socket;
|
|
165
|
+
private state;
|
|
166
|
+
private attempt;
|
|
167
|
+
private reconnectTimer;
|
|
168
|
+
private heartbeatTimer;
|
|
169
|
+
/** Set when the caller closed deliberately, so we do not reconnect. */
|
|
170
|
+
private stopped;
|
|
171
|
+
private conversationId;
|
|
172
|
+
/** Re-sent after every reconnect, so the runtime is never blind to context. */
|
|
173
|
+
private lastScreen;
|
|
174
|
+
constructor(options: ClientOptions);
|
|
175
|
+
get connectionState(): ConnectionState;
|
|
176
|
+
connect(): Promise<void>;
|
|
177
|
+
close(): void;
|
|
178
|
+
/** Send a user message. Silently dropped when offline — the widget shows the state. */
|
|
179
|
+
sendMessage(text: string, clientMsgId: string): void;
|
|
180
|
+
/**
|
|
181
|
+
* Publish the current screen. Idempotent: a full snapshot that replaces
|
|
182
|
+
* whatever the runtime held.
|
|
183
|
+
*/
|
|
184
|
+
/**
|
|
185
|
+
* Tell the runtime where the user is, or that they are somewhere it does not
|
|
186
|
+
* know about.
|
|
187
|
+
*
|
|
188
|
+
* `null` matters as much as a screen. The host app registers the screens it
|
|
189
|
+
* chooses to; every other page is one the runtime must be told it cannot
|
|
190
|
+
* see. Left unsaid, the runtime keeps the last screen it heard about, and
|
|
191
|
+
* the assistant names a page the user left — which is worse than admitting
|
|
192
|
+
* it does not know, and quietly keeps that screen's scoped actions callable.
|
|
193
|
+
*/
|
|
194
|
+
updateScreen(screen: ScreenContext | null): void;
|
|
195
|
+
/**
|
|
196
|
+
* Answer a command. Must be called for every command received, including
|
|
197
|
+
* failures — the runtime is blocking a turn on this.
|
|
198
|
+
*/
|
|
199
|
+
ackCommand(commandId: string, ok: boolean, result?: unknown, error?: string): void;
|
|
200
|
+
confirmAction(proposalId: string, confirmed: boolean, editedInput?: Record<string, unknown>): void;
|
|
201
|
+
cancelTurn(turnId: string): void;
|
|
202
|
+
/**
|
|
203
|
+
* Ask for a permit to open the voice socket.
|
|
204
|
+
*
|
|
205
|
+
* Requested on the chat socket rather than fetched over HTTP because this
|
|
206
|
+
* session is what the permit is scoped to: the runtime hands back a token
|
|
207
|
+
* bound to the very session actor holding this connection, so the voice
|
|
208
|
+
* socket joins the conversation already in progress instead of starting a
|
|
209
|
+
* second one beside it.
|
|
210
|
+
*
|
|
211
|
+
* Answered by a `voice_token` event, or by an `error` when voice is not
|
|
212
|
+
* available for this app — which is the signal to hide the microphone
|
|
213
|
+
* rather than offer one that fails on the first press.
|
|
214
|
+
*/
|
|
215
|
+
requestVoiceToken(): void;
|
|
216
|
+
private open;
|
|
217
|
+
private handle;
|
|
218
|
+
private send;
|
|
219
|
+
private scheduleReconnect;
|
|
220
|
+
private startHeartbeat;
|
|
221
|
+
private clearHeartbeat;
|
|
222
|
+
private clearTimers;
|
|
223
|
+
private setState;
|
|
224
|
+
private emit;
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../js/src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAEL,KAAK,gBAAgB,EAErB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,aAAa,EAElB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,YAAY,GACZ,MAAM,GACN,cAAc,GACd,QAAQ,CAAC;AAEb,2CAA2C;AAC3C,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE;AAC3C;;;GAGG;GACD;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE;AACjD;;;;;;GAMG;GACD;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE;AAC1C;;;;;GAKG;GACD;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE;AAC/C;;;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