@machinemetrics/mm-react-tools 5.2.4 → 5.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.
@@ -0,0 +1,130 @@
1
+ export declare const DATE_RANGE_PRESETS: readonly ["today", "yesterday", "last7Days", "last30Days", "last90Days", "lastWeek", "last2Weeks", "lastMonth", "lastYear", "weekToDate", "monthToDate", "quarterToDate", "yearToDate"];
2
+ export type DateRangePreset = (typeof DATE_RANGE_PRESETS)[number];
3
+ /** Offered by the host when a dateRange setting has no `options`. */
4
+ export declare const DEFAULT_DATE_RANGE_PRESETS: readonly ["today", "yesterday", "last7Days", "last30Days", "weekToDate", "monthToDate"];
5
+ /**
6
+ * `start` and `end` are ISO instants on shop-day boundaries; `end` is
7
+ * exclusive. `startDay` and `endDay` are inclusive shop-day dates
8
+ * (yyyy-MM-dd) in the company's time zone.
9
+ */
10
+ export interface DateRangeValue {
11
+ preset: DateRangePreset;
12
+ start: string;
13
+ end: string;
14
+ startDay: string;
15
+ endDay: string;
16
+ }
17
+ /** Valid: `true`, `null` or nothing. Invalid: the message, as a string or `{ message }`. */
18
+ export type MMAppSettingValidateResult = true | string | {
19
+ message: string;
20
+ } | null | undefined | void;
21
+ export interface MMAppSettingOption {
22
+ label: string;
23
+ value: unknown;
24
+ }
25
+ export type MMAppSettingOptions = readonly MMAppSettingOption[] | ((args: {
26
+ filter?: string;
27
+ }) => readonly MMAppSettingOption[] | Promise<readonly MMAppSettingOption[]>);
28
+ interface MMAppSettingBase {
29
+ label?: string;
30
+ isRequired?: boolean;
31
+ helperText?: string;
32
+ visible?: boolean;
33
+ default?: unknown;
34
+ validate?: (args: {
35
+ value: any;
36
+ }) => MMAppSettingValidateResult | Promise<MMAppSettingValidateResult>;
37
+ [key: string]: unknown;
38
+ }
39
+ export interface MMAppInputSetting extends MMAppSettingBase {
40
+ type: 'input';
41
+ default?: string | number;
42
+ }
43
+ export interface MMAppSelectSetting extends MMAppSettingBase {
44
+ type: 'select';
45
+ options?: MMAppSettingOptions;
46
+ isMulti?: boolean;
47
+ }
48
+ export interface MMAppRadioSetting extends MMAppSettingBase {
49
+ type: 'radio';
50
+ options?: MMAppSettingOptions;
51
+ }
52
+ export interface MMAppThresholdField {
53
+ name: string;
54
+ label: string;
55
+ color?: string;
56
+ description?: string;
57
+ value?: number;
58
+ min?: number;
59
+ max?: number;
60
+ }
61
+ export interface MMAppThresholdsSetting extends MMAppSettingBase {
62
+ type: 'thresholds';
63
+ fields: MMAppThresholdField[];
64
+ }
65
+ export interface MMAppCustomSetting extends MMAppSettingBase {
66
+ type: 'custom';
67
+ url: string;
68
+ isMulti?: boolean;
69
+ drawerTitle?: string;
70
+ emptyLabel?: string;
71
+ }
72
+ /** The host resolves the chosen preset and delivers a {@link DateRangeValue}. */
73
+ export interface MMAppDateRangeSetting extends MMAppSettingBase {
74
+ type: 'dateRange';
75
+ options?: readonly DateRangePreset[];
76
+ default?: DateRangePreset;
77
+ acceptGlobalOverride?: 'dateRange';
78
+ }
79
+ export type MMAppSettingConfig = MMAppInputSetting | MMAppSelectSetting | MMAppRadioSetting | MMAppThresholdsSetting | MMAppCustomSetting | MMAppDateRangeSetting;
80
+ /**
81
+ * What `useMMAppSetting` accepts for any type but `dateRange`: any config, as
82
+ * before 5.3.0. The other `MMApp*Setting` types document the shapes hosts
83
+ * read, without enforcing them.
84
+ *
85
+ * @internal Exported only so a consumer's declarations can name the hook's
86
+ * signature.
87
+ */
88
+ export interface MMAppLooseSetting {
89
+ type?: string | null | undefined;
90
+ [key: string]: any;
91
+ }
92
+ /**
93
+ * The part of every config read before its `type` is known: the `type` itself
94
+ * and the callbacks, so their parameters are typed whatever the setting.
95
+ *
96
+ * @internal Exported only so a consumer's declarations can name the hook's
97
+ * signature.
98
+ */
99
+ export interface MMAppSettingCallbacks<T extends string> {
100
+ type?: T | null | undefined;
101
+ options?: readonly any[] | ((args: {
102
+ filter?: string;
103
+ }) => any) | null | false | undefined;
104
+ validate?: ((args: {
105
+ value: any;
106
+ }) => any) | null | false | undefined;
107
+ }
108
+ /**
109
+ * The config `useMMAppSetting` checks for a given `type`.
110
+ *
111
+ * @internal Exported only so a consumer's declarations can name the hook's
112
+ * signature.
113
+ */
114
+ export type MMAppSettingConfigFor<T extends string> = T extends 'dateRange' ? MMAppDateRangeDeclaration : MMAppLooseSetting;
115
+ /**
116
+ * {@link MMAppDateRangeSetting} without the open index signature, so a
117
+ * misspelled option is caught.
118
+ */
119
+ export interface MMAppDateRangeDeclaration {
120
+ type: 'dateRange';
121
+ label?: string | undefined;
122
+ isRequired?: boolean | undefined;
123
+ helperText?: string | undefined;
124
+ visible?: boolean | undefined;
125
+ options?: readonly DateRangePreset[] | undefined;
126
+ default?: DateRangePreset | undefined;
127
+ acceptGlobalOverride?: 'dateRange' | undefined;
128
+ }
129
+ export {};
130
+ //# sourceMappingURL=settings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,yLAcpB,CAAC;AAEZ,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE,qEAAqE;AACrE,eAAO,MAAM,0BAA0B,yFAOS,CAAC;AAEjD;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,eAAe,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,4FAA4F;AAC5F,MAAM,MAAM,0BAA0B,GAClC,IAAI,GACJ,MAAM,GACN;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GACnB,IAAI,GACJ,SAAS,GACT,IAAI,CAAC;AAET,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE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EAAE,GAAG,CAAA;KAAE,KAAK,GAAG,CAAC,GAAG,IAAI,GAAG,KAAK,GAAG,SAAS,CAAC;CACvE;AAED;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,WAAW,GACvE,yBAAyB,GACzB,iBAAiB,CAAC;AAEtB;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,OAAO,CAAC,EAAE,SAAS,eAAe,EAAE,GAAG,SAAS,CAAC;IACjD,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC;IACtC,oBAAoB,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAChD"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * App → Max, through the dashboard host. Use inside MMProvider.
3
+ *
4
+ * - `report(kind, payload)`: background context for Max (`agent:event`).
5
+ * Never the user's words.
6
+ * - `ask(prompt, { newConversation })`: the user's own message to Max
7
+ * (`agent:ask`), into the open conversation or a fresh one. It says
8
+ * nothing about pages: an app that wants the page to the left of Max to
9
+ * change asks, then navigates (in that order: the host only takes
10
+ * messages from a frame that still exists, and navigating can unmount
11
+ * it). The host holds the prompt until the new page is up.
12
+ *
13
+ * `ask` only works right after a user action (a click or key press): the
14
+ * browser's transient user activation. The host checks the same on its own
15
+ * window, so this check is for a clear error, not the security boundary.
16
+ */
17
+ export declare const ASK_MAX_LENGTH = 4000;
18
+ export declare const AGENT_ASK = "agent:ask";
19
+ export declare const AGENT_ASK_CONSUMED = "agent:ask-consumed";
20
+ export declare const AGENT_ASK_SOURCES: readonly ["app-gallery-builder", "app-gallery", "cml-renderer"];
21
+ /** App-to-host request; the host supplies source and timestamp when forwarding. */
22
+ export interface AgentAskPayload {
23
+ prompt: string;
24
+ newConversation?: boolean;
25
+ }
26
+ export interface AgentHostPrompt {
27
+ at: number;
28
+ prompt: string;
29
+ source: (typeof AGENT_ASK_SOURCES)[number];
30
+ }
31
+ export interface AgentAskConsumedPayload {
32
+ kind: 'newThreadPrompt' | 'agentAsk';
33
+ at: number;
34
+ }
35
+ export type AgentEventKind = 'app.error' | 'app.event' | 'app.context';
36
+ /** Renderer event contract; threadId routes the event to its conversation. */
37
+ export interface AgentEvent {
38
+ id: string;
39
+ kind: AgentEventKind;
40
+ at: string;
41
+ threadId: string;
42
+ app?: string;
43
+ /** Legacy alias; threadId is still required. */
44
+ thread?: string;
45
+ appId?: string;
46
+ surface?: 'page' | 'sidesheet' | 'widget' | 'tab' | 'tools';
47
+ message?: string;
48
+ summary?: string;
49
+ errors?: string[];
50
+ version?: number;
51
+ data?: unknown;
52
+ }
53
+ export type AgentEventPayload = Omit<AgentEvent, 'id' | 'kind' | 'at'>;
54
+ export interface AskOptions {
55
+ /** Start a fresh conversation with this prompt as its first message. */
56
+ newConversation?: boolean;
57
+ }
58
+ export type AskResult = {
59
+ ok: true;
60
+ } | {
61
+ ok: false;
62
+ reason: 'not-embedded' | 'no-user-action' | 'empty' | 'too-long';
63
+ };
64
+ export interface MMAgent {
65
+ report: (kind: AgentEventKind, payload: AgentEventPayload) => boolean;
66
+ ask: (prompt: string, options?: AskOptions) => AskResult;
67
+ }
68
+ export declare const useMMAgent: () => MMAgent;
69
+ //# sourceMappingURL=useMMAgent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMMAgent.d.ts","sourceRoot":"","sources":["../src/useMMAgent.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,cAAc,OAAO,CAAC;AACnC,eAAO,MAAM,SAAS,cAAc,CAAC;AACrC,eAAO,MAAM,kBAAkB,uBAAuB,CAA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,MAAM,SAAS,GACjB;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GACZ;IACE,EAAE,EAAE,KAAK,CAAC;IACV,MAAM,EAAE,cAAc,GAAG,gBAAgB,GAAG,OAAO,GAAG,UAAU,CAAC;CAClE,CAAC;AAEN,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,iBAAiB,KAAK,OAAO,CAAC;IACtE,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,KAAK,SAAS,CAAC;CAC1D;AAMD,eAAO,MAAM,UAAU,QAAO,OA6C7B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machinemetrics/mm-react-tools",
3
- "version": "5.2.4",
3
+ "version": "5.4.0",
4
4
  "description": "Components, hooks, and helper functions for writing React apps using MachineMetrics APIs.",
5
5
  "author": "machinemetrics",
6
6
  "license": "MIT",
@@ -27,6 +27,7 @@
27
27
  "test:coverage": "vitest run --coverage",
28
28
  "test:watch": "vitest",
29
29
  "type-check": "tsc --noEmit",
30
+ "type-check:consumer": "node scripts/check-consumer-types.mjs",
30
31
  "lint": "eslint . --color --max-warnings 19",
31
32
  "lint:fix": "eslint --max-warnings 19 . --color --fix",
32
33
  "prettier": "prettier --list-different '{*.(js|ts),**/*.(js|ts)}'",