@graineai/inapp-react-native 0.21.0 → 0.22.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/dist/client.d.ts CHANGED
@@ -17,6 +17,16 @@ export interface SessionConfig {
17
17
  appearance?: Record<string, any>;
18
18
  variables?: Record<string, string>;
19
19
  components?: any[];
20
+ appActions?: Array<{
21
+ tool_name?: string;
22
+ toolName?: string;
23
+ name?: string;
24
+ }>;
25
+ }
26
+ export interface ActionDiagnosis {
27
+ usable: string[];
28
+ undeclared: string[];
29
+ unhandled: string[];
20
30
  }
21
31
  export declare class GraineInAppClient {
22
32
  readonly opts: GraineInAppOptions;
@@ -46,6 +56,8 @@ export declare class GraineInAppClient {
46
56
  private emit;
47
57
  private get fetch();
48
58
  session(): Promise<SessionConfig>;
59
+ checkActions(): ActionDiagnosis;
60
+ private reportActionMismatch;
49
61
  private ticket;
50
62
  connect(): Promise<void>;
51
63
  private openSocket;
package/dist/client.js CHANGED
@@ -68,8 +68,37 @@ export class GraineInAppClient {
68
68
  throw new Error(data?.error || `Embed rejected (${res.status})`);
69
69
  }
70
70
  this.config = data;
71
+ this.reportActionMismatch();
71
72
  return this.config;
72
73
  }
74
+ checkActions() {
75
+ const registered = [...this.actions.keys()];
76
+ const declared = new Set((this.config?.appActions ?? [])
77
+ .map((a) => a?.tool_name || a?.toolName || a?.name)
78
+ .filter((n) => Boolean(n)));
79
+ return {
80
+ usable: registered.filter((n) => declared.has(n)),
81
+ undeclared: registered.filter((n) => !declared.has(n)),
82
+ unhandled: [...declared].filter((n) => !this.actions.has(n)),
83
+ };
84
+ }
85
+ reportActionMismatch() {
86
+ if (this.actions.size === 0)
87
+ return;
88
+ const { undeclared, unhandled } = this.checkActions();
89
+ if (!undeclared.length && !unhandled.length)
90
+ return;
91
+ this.emit("diagnostic", { type: "actions", ...this.checkActions() });
92
+ if (undeclared.length) {
93
+ console.warn(`[Graine] This app registered ${undeclared.length} action(s) the agent is not ` +
94
+ `configured to call, so the agent cannot use them: ${undeclared.join(", ")}. ` +
95
+ `Add them to the agent's app_actions in Embed & Widgets.`);
96
+ }
97
+ if (unhandled.length) {
98
+ console.warn(`[Graine] The agent is configured to call ${unhandled.length} action(s) this ` +
99
+ `build does not implement: ${unhandled.join(", ")}. It will be refused mid-sentence.`);
100
+ }
101
+ }
73
102
  async ticket() {
74
103
  try {
75
104
  const res = await this.fetch(`${this.opts.baseUrl}/api/embed/ticket`, {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type { ActionHandler, AppActionRequest, AppActionResult, AppEvent, ScreenContext, ScreenField, } from "./protocol.js";
2
- export { GraineInAppClient, type GraineInAppOptions, type SessionConfig } from "./client.js";
2
+ export { GraineInAppClient, type GraineInAppOptions, type SessionConfig, type ActionDiagnosis, } from "./client.js";
3
3
  export { VoiceSession, liveAudioStreamAdapter, base64ToPcm16, CAPTURE_SAMPLE_RATE, type AudioAdapter, type VoiceSessionOptions, } from "./voice.js";
4
4
  export { EchoGuard, decodeAgentAudio, decodeMuLaw, decodePcm16, base64ToBytes, type AudioFormat, type DecodedAudio, } from "./audio.js";
5
5
  export { addMaskRule, maskDeep, maskString } from "./mask.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { GraineInAppClient } from "./client.js";
1
+ export { GraineInAppClient, } from "./client.js";
2
2
  export { VoiceSession, liveAudioStreamAdapter, base64ToPcm16, CAPTURE_SAMPLE_RATE, } from "./voice.js";
3
3
  export { EchoGuard, decodeAgentAudio, decodeMuLaw, decodePcm16, base64ToBytes, } from "./audio.js";
4
4
  export { addMaskRule, maskDeep, maskString } from "./mask.js";
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@graineai/inapp-react-native",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "type": "module",
5
- "description": "Graine in-app agent for React Native \u2014 an agent that sees the screen your customer is on and can act on it.",
5
+ "description": "Graine in-app agent for React Native an agent that sees the screen your customer is on and can act on it.",
6
6
  "license": "MIT",
7
7
  "private": false,
8
8
  "main": "dist/index.js",