@bikdotai/bik-component-library 0.0.777-beta.22 → 0.0.777-beta.24

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.
@@ -71,9 +71,10 @@ export type CustomEditorProps = React.TextareaHTMLAttributes<HTMLTextAreaElement
71
71
  instructionSuggestions?: string[];
72
72
  onAnalyticsEvent?: (name: AIEventName, payload: AIEventPayload) => void;
73
73
  /**
74
- * Fires when the user **Accepts** an AI suggestion. Persist `payload.isAiTagged` (or the
75
- * full payload) in host state and send on template save the editor ref `get()` only
76
- * returns body text. See `MERCHANT_ADMIN_REACT_INTEGRATION.md` (AI tag section).
74
+ * Fires on AI-tag computations:
75
+ * - `source: "accept"` after accepting a suggestion (addition check: >=50% => true)
76
+ * - `source: "post_edit_debounce"` after edit idle/blur (retention check: <50% => true)
77
+ * Persist `payload.isAiTagged` (or full payload) in host state and send on save.
77
78
  */
78
79
  onAITagComputed?: (payload: AITagPayload) => void;
79
80
  /**
@@ -139,9 +140,10 @@ export declare const WhatsAppTextEditor: React.ForwardRefExoticComponent<React.T
139
140
  instructionSuggestions?: string[] | undefined;
140
141
  onAnalyticsEvent?: ((name: AIEventName, payload: AIEventPayload) => void) | undefined;
141
142
  /**
142
- * Fires when the user **Accepts** an AI suggestion. Persist `payload.isAiTagged` (or the
143
- * full payload) in host state and send on template save the editor ref `get()` only
144
- * returns body text. See `MERCHANT_ADMIN_REACT_INTEGRATION.md` (AI tag section).
143
+ * Fires on AI-tag computations:
144
+ * - `source: "accept"` after accepting a suggestion (addition check: >=50% => true)
145
+ * - `source: "post_edit_debounce"` after edit idle/blur (retention check: <50% => true)
146
+ * Persist `payload.isAiTagged` (or full payload) in host state and send on save.
145
147
  */
146
148
  onAITagComputed?: ((payload: AITagPayload) => void) | undefined;
147
149
  /**
@@ -1,18 +1,23 @@
1
1
  /**
2
- * AI template tag: show only when the edit distance between what the user had
3
- * (baseline) and what they accepted is at least half of the longer of the two strings.
2
+ * AI tag math shared by accept and post-edit flows.
4
3
  *
5
- * **Wiring:** `WhatsAppTextEditor` calls `onAITagComputed` with this result when the user
6
- * Accepts a suggestion — the editor does not return the tag from `ref.get()`. Host apps
7
- * should store `isAiTagged` (and optional full payload) in their own state and send it on
8
- * save. See `MERCHANT_ADMIN_REACT_INTEGRATION.md` “AI tag — where it comes from…”.
4
+ * `changePercent` is always computed as:
5
+ * levenshteinDistance(aiBaseline, currentText) / max(len(aiBaseline), len(currentText), 1)
6
+ *
7
+ * `isAiTagged` interpretation is source-specific:
8
+ * - `accept`: addition check (`>= 50%` => true)
9
+ * - `post_edit_debounce`: retention check (`< 50%` => true)
9
10
  */
10
11
  export declare const AI_TAG_CHANGE_RATIO_THRESHOLD = 0.5;
11
12
  export type AITagPayload = {
12
13
  changedCharacters: number;
13
14
  templateLength: number;
14
15
  changePercent: number;
15
- /** True when changedCharacters / templateLength >= {@link AI_TAG_CHANGE_RATIO_THRESHOLD} */
16
+ /**
17
+ * Interpretation depends on source:
18
+ * - `accept`: true when changedCharacters / templateLength >= threshold.
19
+ * - `post_edit_debounce`: true when changedCharacters / templateLength < threshold.
20
+ */
16
21
  isAiTagged: boolean;
17
22
  /**
18
23
  * True when this accept occurred during the “initial AI prefill” phase: the host
@@ -51,8 +56,8 @@ export declare function levenshteinDistance(a: string, b: string): number;
51
56
  */
52
57
  export declare function computeAiTagOnAccept(input: ComputeAiTagOnAcceptInput): AITagPayload;
53
58
  /**
54
- * Computes AI tag after user edits an accepted AI suggestion.
55
- * For post-edit flow, we still apply the same tag rule:
56
- * changedCharacters / templateLength >= AI_TAG_CHANGE_RATIO_THRESHOLD => AI-tagged.
59
+ * Computes AI tag after user edits AI-derived text.
60
+ * Post-edit is a retention check: if drift from AI baseline reaches >= 50%,
61
+ * the text is treated as no longer AI-tagged.
57
62
  */
58
63
  export declare function computeAiTagOnPostEdit(input: ComputeAiTagOnPostEditInput): AITagPayload;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});function e(e,t){const n=e.length,i=t.length,a=Array(i+1).fill(0).map(((e,t)=>t));for(let r=1;r<=n;r++){let n=a[0];a[0]=r;for(let c=1;c<=i;c++){const i=a[c];e[r-1]===t[c-1]?a[c]=n:a[c]=Math.min(a[c-1],a[c],n)+1,n=i}}return a[i]}exports.AI_TAG_CHANGE_RATIO_THRESHOLD=.5,exports.computeAiTagOnAccept=function(t){const{baselineText:n,acceptedText:i,initialAiPrefillPhase:a}=t,r=e(n,i),c=Math.max(n.length,i.length,1),l=r/c;return{changedCharacters:r,templateLength:c,changePercent:l,isAiTagged:l>=.5,initialAiPrefillPhase:a}},exports.computeAiTagOnPostEdit=function(t){const{acceptedAiText:n,currentEditedText:i}=t,a=e(n,i),r=Math.max(n.length,i.length,1),c=a/r;return{changedCharacters:a,templateLength:r,changePercent:c,isAiTagged:c>=.5,initialAiPrefillPhase:!1}},exports.levenshteinDistance=e;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});function e(e,t){const n=e.length,i=t.length,a=Array(i+1).fill(0).map(((e,t)=>t));for(let r=1;r<=n;r++){let n=a[0];a[0]=r;for(let c=1;c<=i;c++){const i=a[c];e[r-1]===t[c-1]?a[c]=n:a[c]=Math.min(a[c-1],a[c],n)+1,n=i}}return a[i]}exports.AI_TAG_CHANGE_RATIO_THRESHOLD=.5,exports.computeAiTagOnAccept=function(t){const{baselineText:n,acceptedText:i,initialAiPrefillPhase:a}=t,r=e(n,i),c=Math.max(n.length,i.length,1),l=r/c;return{changedCharacters:r,templateLength:c,changePercent:l,isAiTagged:l>=.5,initialAiPrefillPhase:a}},exports.computeAiTagOnPostEdit=function(t){const{acceptedAiText:n,currentEditedText:i}=t,a=e(n,i),r=Math.max(n.length,i.length,1),c=a/r;return{changedCharacters:a,templateLength:r,changePercent:c,isAiTagged:c<.5,initialAiPrefillPhase:!1}},exports.levenshteinDistance=e;
@@ -71,9 +71,10 @@ export type CustomEditorProps = React.TextareaHTMLAttributes<HTMLTextAreaElement
71
71
  instructionSuggestions?: string[];
72
72
  onAnalyticsEvent?: (name: AIEventName, payload: AIEventPayload) => void;
73
73
  /**
74
- * Fires when the user **Accepts** an AI suggestion. Persist `payload.isAiTagged` (or the
75
- * full payload) in host state and send on template save the editor ref `get()` only
76
- * returns body text. See `MERCHANT_ADMIN_REACT_INTEGRATION.md` (AI tag section).
74
+ * Fires on AI-tag computations:
75
+ * - `source: "accept"` after accepting a suggestion (addition check: >=50% => true)
76
+ * - `source: "post_edit_debounce"` after edit idle/blur (retention check: <50% => true)
77
+ * Persist `payload.isAiTagged` (or full payload) in host state and send on save.
77
78
  */
78
79
  onAITagComputed?: (payload: AITagPayload) => void;
79
80
  /**
@@ -139,9 +140,10 @@ export declare const WhatsAppTextEditor: React.ForwardRefExoticComponent<React.T
139
140
  instructionSuggestions?: string[] | undefined;
140
141
  onAnalyticsEvent?: ((name: AIEventName, payload: AIEventPayload) => void) | undefined;
141
142
  /**
142
- * Fires when the user **Accepts** an AI suggestion. Persist `payload.isAiTagged` (or the
143
- * full payload) in host state and send on template save the editor ref `get()` only
144
- * returns body text. See `MERCHANT_ADMIN_REACT_INTEGRATION.md` (AI tag section).
143
+ * Fires on AI-tag computations:
144
+ * - `source: "accept"` after accepting a suggestion (addition check: >=50% => true)
145
+ * - `source: "post_edit_debounce"` after edit idle/blur (retention check: <50% => true)
146
+ * Persist `payload.isAiTagged` (or full payload) in host state and send on save.
145
147
  */
146
148
  onAITagComputed?: ((payload: AITagPayload) => void) | undefined;
147
149
  /**
@@ -1,18 +1,23 @@
1
1
  /**
2
- * AI template tag: show only when the edit distance between what the user had
3
- * (baseline) and what they accepted is at least half of the longer of the two strings.
2
+ * AI tag math shared by accept and post-edit flows.
4
3
  *
5
- * **Wiring:** `WhatsAppTextEditor` calls `onAITagComputed` with this result when the user
6
- * Accepts a suggestion — the editor does not return the tag from `ref.get()`. Host apps
7
- * should store `isAiTagged` (and optional full payload) in their own state and send it on
8
- * save. See `MERCHANT_ADMIN_REACT_INTEGRATION.md` “AI tag — where it comes from…”.
4
+ * `changePercent` is always computed as:
5
+ * levenshteinDistance(aiBaseline, currentText) / max(len(aiBaseline), len(currentText), 1)
6
+ *
7
+ * `isAiTagged` interpretation is source-specific:
8
+ * - `accept`: addition check (`>= 50%` => true)
9
+ * - `post_edit_debounce`: retention check (`< 50%` => true)
9
10
  */
10
11
  export declare const AI_TAG_CHANGE_RATIO_THRESHOLD = 0.5;
11
12
  export type AITagPayload = {
12
13
  changedCharacters: number;
13
14
  templateLength: number;
14
15
  changePercent: number;
15
- /** True when changedCharacters / templateLength >= {@link AI_TAG_CHANGE_RATIO_THRESHOLD} */
16
+ /**
17
+ * Interpretation depends on source:
18
+ * - `accept`: true when changedCharacters / templateLength >= threshold.
19
+ * - `post_edit_debounce`: true when changedCharacters / templateLength < threshold.
20
+ */
16
21
  isAiTagged: boolean;
17
22
  /**
18
23
  * True when this accept occurred during the “initial AI prefill” phase: the host
@@ -51,8 +56,8 @@ export declare function levenshteinDistance(a: string, b: string): number;
51
56
  */
52
57
  export declare function computeAiTagOnAccept(input: ComputeAiTagOnAcceptInput): AITagPayload;
53
58
  /**
54
- * Computes AI tag after user edits an accepted AI suggestion.
55
- * For post-edit flow, we still apply the same tag rule:
56
- * changedCharacters / templateLength >= AI_TAG_CHANGE_RATIO_THRESHOLD => AI-tagged.
59
+ * Computes AI tag after user edits AI-derived text.
60
+ * Post-edit is a retention check: if drift from AI baseline reaches >= 50%,
61
+ * the text is treated as no longer AI-tagged.
57
62
  */
58
63
  export declare function computeAiTagOnPostEdit(input: ComputeAiTagOnPostEditInput): AITagPayload;
@@ -1 +1 @@
1
- const e=.5;function t(e,t){const n=e.length,a=t.length,i=Array(a+1).fill(0).map(((e,t)=>t));for(let l=1;l<=n;l++){let n=i[0];i[0]=l;for(let r=1;r<=a;r++){const a=i[r];e[l-1]===t[r-1]?i[r]=n:i[r]=Math.min(i[r-1],i[r],n)+1,n=a}}return i[a]}function n(e){const{baselineText:n,acceptedText:a,initialAiPrefillPhase:i}=e,l=t(n,a),r=Math.max(n.length,a.length,1),c=l/r;return{changedCharacters:l,templateLength:r,changePercent:c,isAiTagged:c>=.5,initialAiPrefillPhase:i}}function a(e){const{acceptedAiText:n,currentEditedText:a}=e,i=t(n,a),l=Math.max(n.length,a.length,1),r=i/l;return{changedCharacters:i,templateLength:l,changePercent:r,isAiTagged:r>=.5,initialAiPrefillPhase:!1}}export{e as AI_TAG_CHANGE_RATIO_THRESHOLD,n as computeAiTagOnAccept,a as computeAiTagOnPostEdit,t as levenshteinDistance};
1
+ const e=.5;function t(e,t){const n=e.length,a=t.length,i=Array(a+1).fill(0).map(((e,t)=>t));for(let l=1;l<=n;l++){let n=i[0];i[0]=l;for(let r=1;r<=a;r++){const a=i[r];e[l-1]===t[r-1]?i[r]=n:i[r]=Math.min(i[r-1],i[r],n)+1,n=a}}return i[a]}function n(e){const{baselineText:n,acceptedText:a,initialAiPrefillPhase:i}=e,l=t(n,a),r=Math.max(n.length,a.length,1),c=l/r;return{changedCharacters:l,templateLength:r,changePercent:c,isAiTagged:c>=.5,initialAiPrefillPhase:i}}function a(e){const{acceptedAiText:n,currentEditedText:a}=e,i=t(n,a),l=Math.max(n.length,a.length,1),r=i/l;return{changedCharacters:i,templateLength:l,changePercent:r,isAiTagged:r<.5,initialAiPrefillPhase:!1}}export{e as AI_TAG_CHANGE_RATIO_THRESHOLD,n as computeAiTagOnAccept,a as computeAiTagOnPostEdit,t as levenshteinDistance};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.777-beta.22",
3
+ "version": "0.0.777-beta.24",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",