@machinemetrics/mm-react-tools 5.3.0 → 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.
package/README.md CHANGED
@@ -147,6 +147,51 @@ const { range } = useMMAppContext();
147
147
 
148
148
  Contact support@machinemetrics.com for a Client ID and Secret.
149
149
 
150
+ ## Hand a prompt or context to Max
151
+
152
+ Inside `MMProvider`, `useMMAgent()` exposes `ask` and `report`:
153
+
154
+ ```tsx
155
+ const agent = useMMAgent();
156
+ // The host forwards the active thread from Max's cml:current message.
157
+ const { threadId } = useMMAppContext() as { threadId?: string | null };
158
+
159
+ // Call directly from a user click or key press.
160
+ const result = agent.ask('Build a scrap log', { newConversation: true });
161
+ if (result.ok) {
162
+ // Navigate here if the app also needs to change pages.
163
+ }
164
+
165
+ // Background context does not require user activation.
166
+ if (threadId) {
167
+ agent.report('app.context', { threadId, summary: 'Scrap log selected' });
168
+ }
169
+ ```
170
+
171
+ `ask` trims the prompt and accepts up to `ASK_MAX_LENGTH` (4000) characters.
172
+ It returns `{ ok: false, reason }` for `empty`, `too-long`, `not-embedded`, or
173
+ `no-user-action`. A successful result means the message was posted to the host;
174
+ the host independently checks the source zone and user activation. With
175
+ `newConversation: true`, the prompt requests a fresh conversation's first
176
+ message. Otherwise it requests a composer prefill in the open conversation.
177
+ Ask before navigating so the source frame still exists when the host receives it.
178
+
179
+ `report` accepts `app.error`, `app.event`, or `app.context`, plus a required
180
+ `AgentEventPayload` containing `threadId` from the host context populated by
181
+ `cml:current`. Wait for that thread before reporting; do not invent a thread ID.
182
+ It posts `agent:event` with a generated unique `id`, the kind and an ISO timestamp, returning
183
+ `false` outside an embedded app or when `payload.threadId` is missing, not a string, or blank (including whitespace-only). No message is sent in those cases. It does not send a user message. Today, reports
184
+ only reach Max from the `cml-renderer` zone. Payload `type` and `instanceId`
185
+ fields are discarded so they cannot override the transport envelope.
186
+
187
+ The library exports `AGENT_ASK` (`agent:ask`), `AGENT_ASK_CONSUMED`
188
+ (`agent:ask-consumed`), and `AGENT_ASK_SOURCES` for the shared protocol.
189
+ `AgentAskPayload` describes the app-to-host `{ prompt, newConversation? }`
190
+ request. `AgentHostPrompt` describes the host-forwarded `{ at, prompt, source }`
191
+ prompt. `AgentAskConsumedPayload` is `{ kind, at }`, where `kind` is
192
+ `newThreadPrompt` or `agentAsk`. Timestamps are numbers; the host remains
193
+ responsible for checking the source frame and user activation.
194
+
150
195
  ## License
151
196
 
152
197
  MIT © [MachineMetrics](https://github.com/machinemetrics)
package/dist/index.d.ts CHANGED
@@ -10,4 +10,6 @@ export type { MMContextValue, MMAuthResult, MMUrls, MMRequest, MMRequestOptions,
10
10
  export type { MMProviderProps, MMReleaseStage } from './MMProvider';
11
11
  export type { UseApiRequestOptions, UseApiRequestResult } from './hooks';
12
12
  export type { DateRangePreset, DateRangeValue, MMAppSettingConfig, MMAppDateRangeDeclaration, MMAppSettingOption, MMAppSettingOptions, MMAppSettingValidateResult, MMAppInputSetting, MMAppSelectSetting, MMAppRadioSetting, MMAppThresholdsSetting, MMAppThresholdField, MMAppCustomSetting, MMAppDateRangeSetting, MMAppSettingCallbacks, MMAppSettingConfigFor, MMAppLooseSetting, } from './settings';
13
+ export { useMMAgent, ASK_MAX_LENGTH, AGENT_ASK, AGENT_ASK_CONSUMED, AGENT_ASK_SOURCES, } from './useMMAgent';
14
+ export type { AgentEventKind, AgentEvent, AgentEventPayload, AgentAskPayload, AgentHostPrompt, AgentAskConsumedPayload, AskOptions, AskResult, MMAgent, } from './useMMAgent';
13
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,UAAU,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,IAAI,MAAM,QAAQ,CAAC;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EACrB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,UAAU,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,eAAe,EACf,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,uBAAuB,EACvB,SAAS,EACT,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,eAAe,EACf,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,UAAU,EACV,IAAI,EACJ,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,0BAA0B,GAC3B,CAAC;AAEF,YAAY,EACV,cAAc,EACd,YAAY,EACZ,MAAM,EACN,SAAS,EACT,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,eAAe,EAAE,cAAc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