@bikdotai/bik-component-library 0.0.824-beta.0 → 0.0.824

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.
Files changed (70) hide show
  1. package/dist/cjs/components/agent-builder/components/CreateSubAgentPanel.js +1 -1
  2. package/dist/cjs/components/agent-builder/components/CreateSubAgentPanel.js.map +1 -1
  3. package/dist/cjs/components/agent-builder/context/AgentBuilderContext.js +1 -1
  4. package/dist/cjs/components/agent-builder/context/AgentBuilderContext.js.map +1 -1
  5. package/dist/cjs/components/agent-builder/utils/mentionSerialization.js +2 -2
  6. package/dist/cjs/components/agent-builder/utils/mentionSerialization.js.map +1 -1
  7. package/dist/cjs/editor/BikEditor.js +1 -1
  8. package/dist/cjs/editor/BikEditor.js.map +1 -1
  9. package/dist/cjs/editor/BikEditor.styles.js +47 -29
  10. package/dist/cjs/editor/BikEditor.styles.js.map +1 -1
  11. package/dist/cjs/editor/extensions/jsonHighlight/JsonHighlightExtension.js +3 -2
  12. package/dist/cjs/editor/extensions/jsonHighlight/JsonHighlightExtension.js.map +1 -1
  13. package/dist/cjs/icons/Actions/Common actions/ProductTour.js +2 -0
  14. package/dist/cjs/icons/Actions/Common actions/ProductTour.js.map +1 -0
  15. package/dist/cjs/icons/Actions/Common actions/RestApi.js +2 -0
  16. package/dist/cjs/icons/Actions/Common actions/RestApi.js.map +1 -0
  17. package/dist/cjs/icons/Actions/Common actions/Save.js +2 -0
  18. package/dist/cjs/icons/Actions/Common actions/Save.js.map +1 -0
  19. package/dist/cjs/icons/Actions/Common actions/Shortcut.js +2 -0
  20. package/dist/cjs/icons/Actions/Common actions/Shortcut.js.map +1 -0
  21. package/dist/cjs/icons/BIK AI specific/Webhook.js +2 -0
  22. package/dist/cjs/icons/BIK AI specific/Webhook.js.map +1 -0
  23. package/dist/cjs/icons/Informational/Store related/TicketForm.js +2 -0
  24. package/dist/cjs/icons/Informational/Store related/TicketForm.js.map +1 -0
  25. package/dist/cjs/icons/Legacy - Bikayi specific/Services/LoudSpeaker.js +2 -0
  26. package/dist/cjs/icons/Legacy - Bikayi specific/Services/LoudSpeaker.js.map +1 -0
  27. package/dist/cjs/icons/index.js +1 -1
  28. package/dist/esm/components/agent-builder/components/CreateSubAgentPanel.js +24 -24
  29. package/dist/esm/components/agent-builder/components/CreateSubAgentPanel.js.map +1 -1
  30. package/dist/esm/components/agent-builder/context/AgentBuilderContext.js +98 -101
  31. package/dist/esm/components/agent-builder/context/AgentBuilderContext.js.map +1 -1
  32. package/dist/esm/components/agent-builder/utils/mentionSerialization.d.ts +5 -7
  33. package/dist/esm/components/agent-builder/utils/mentionSerialization.js +40 -37
  34. package/dist/esm/components/agent-builder/utils/mentionSerialization.js.map +1 -1
  35. package/dist/esm/editor/BikEditor.js +72 -79
  36. package/dist/esm/editor/BikEditor.js.map +1 -1
  37. package/dist/esm/editor/BikEditor.styles.d.ts +4 -4
  38. package/dist/esm/editor/BikEditor.styles.js +44 -26
  39. package/dist/esm/editor/BikEditor.styles.js.map +1 -1
  40. package/dist/esm/editor/extensions/jsonHighlight/JsonHighlightExtension.js +100 -32
  41. package/dist/esm/editor/extensions/jsonHighlight/JsonHighlightExtension.js.map +1 -1
  42. package/dist/esm/icons/Actions/Common actions/ProductTour.d.ts +7 -0
  43. package/dist/esm/icons/Actions/Common actions/ProductTour.js +51 -0
  44. package/dist/esm/icons/Actions/Common actions/ProductTour.js.map +1 -0
  45. package/dist/esm/icons/Actions/Common actions/RestApi.d.ts +7 -0
  46. package/dist/esm/icons/Actions/Common actions/RestApi.js +29 -0
  47. package/dist/esm/icons/Actions/Common actions/RestApi.js.map +1 -0
  48. package/dist/esm/icons/Actions/Common actions/Save.d.ts +7 -0
  49. package/dist/esm/icons/Actions/Common actions/Save.js +40 -0
  50. package/dist/esm/icons/Actions/Common actions/Save.js.map +1 -0
  51. package/dist/esm/icons/Actions/Common actions/Shortcut.d.ts +7 -0
  52. package/dist/esm/icons/Actions/Common actions/Shortcut.js +40 -0
  53. package/dist/esm/icons/Actions/Common actions/Shortcut.js.map +1 -0
  54. package/dist/esm/icons/Actions/Common actions/index.d.ts +4 -0
  55. package/dist/esm/icons/BIK AI specific/Webhook.d.ts +7 -0
  56. package/dist/esm/icons/BIK AI specific/Webhook.js +32 -0
  57. package/dist/esm/icons/BIK AI specific/Webhook.js.map +1 -0
  58. package/dist/esm/icons/BIK AI specific/index.d.ts +1 -0
  59. package/dist/esm/icons/Informational/Store related/TicketForm.d.ts +7 -0
  60. package/dist/esm/icons/Informational/Store related/TicketForm.js +65 -0
  61. package/dist/esm/icons/Informational/Store related/TicketForm.js.map +1 -0
  62. package/dist/esm/icons/Informational/Store related/index.d.ts +1 -0
  63. package/dist/esm/icons/Legacy - Bikayi specific/Services/LoudSpeaker.d.ts +7 -0
  64. package/dist/esm/icons/Legacy - Bikayi specific/Services/LoudSpeaker.js +35 -0
  65. package/dist/esm/icons/Legacy - Bikayi specific/Services/LoudSpeaker.js.map +1 -0
  66. package/dist/esm/icons/Legacy - Bikayi specific/Services/index.d.ts +1 -0
  67. package/dist/esm/icons/index.d.ts +4 -4
  68. package/dist/esm/icons/index.js +284 -270
  69. package/dist/esm/icons/index.js.map +1 -1
  70. package/package.json +1 -1
@@ -1,15 +1,15 @@
1
- import { jsx as ut } from "react/jsx-runtime";
2
- import dt, { useState as B, useRef as d, useCallback as o, useMemo as F, useContext as gt } from "react";
3
- import { AGENT_CHAR_LIMITS as mt } from "../constants/charLimits.js";
4
- import { getStepIndex as lt, STEP_KEYS as _ } from "../constants/steps.js";
5
- const nt = dt.createContext(null), Mt = () => {
6
- const n = gt(nt);
1
+ import { jsx as it } from "react/jsx-runtime";
2
+ import ut, { useState as h, useRef as d, useCallback as r, useMemo as B, useContext as dt } from "react";
3
+ import { AGENT_CHAR_LIMITS as gt } from "../constants/charLimits.js";
4
+ import { getStepIndex as mt, STEP_KEYS as _ } from "../constants/steps.js";
5
+ const nt = ut.createContext(null), _t = () => {
6
+ const n = dt(nt);
7
7
  if (!n)
8
8
  throw new Error(
9
9
  "useAgentBuilderContext must be used within an AgentBuilderProvider"
10
10
  );
11
11
  return n;
12
- }, ft = (n, s) => {
12
+ }, lt = (n, s) => {
13
13
  const g = n.trigger.mode === "custom_intent" ? (n.trigger.custom_intent ?? "").trim().length > 0 : n.trigger.intents.length > 0;
14
14
  return {
15
15
  about: n.name.trim().length > 0 && n.name.length <= s.name && n.description.length <= s.description,
@@ -19,172 +19,169 @@ const nt = dt.createContext(null), Mt = () => {
19
19
  // Optional until specced further — never blocks go-live.
20
20
  handover: !0
21
21
  };
22
- }, St = ({
22
+ }, Mt = ({
23
23
  value: n,
24
24
  onChange: s,
25
25
  activeStep: g,
26
- onStepChange: I,
27
- availableTools: m,
26
+ onStepChange: F,
27
+ availableTools: l,
28
28
  availableSubAgents: f,
29
- availableIntents: P,
30
- availableModels: A,
31
- validation: E,
32
- applicationType: $,
33
- charLimits: a,
34
- disableStepNavigation: w = !0,
35
- onCreateSubAgent: y,
29
+ availableIntents: I,
30
+ availableModels: P,
31
+ validation: A,
32
+ applicationType: E,
33
+ charLimits: T,
34
+ disableStepNavigation: $ = !0,
35
+ onCreateSubAgent: w,
36
36
  onFetchSubAgent: L,
37
- onUpdateSubAgent: T,
38
- onImproveSubAgent: V,
37
+ onUpdateSubAgent: V,
38
+ onImproveSubAgent: b,
39
39
  children: et
40
40
  }) => {
41
- const [rt, st] = B("about"), p = g ?? rt, i = lt(p), j = d(n);
41
+ const [st, rt] = h("about"), x = g ?? st, c = mt(x), j = d(n);
42
42
  j.current = n;
43
- const [K, b] = B(0), M = d({}), q = d("instructions"), G = o(
43
+ const [y, K] = h(0), M = d({}), q = d("instructions"), G = r(
44
44
  (t, e) => {
45
45
  e ? M.current[t] = e : delete M.current[t];
46
46
  },
47
47
  []
48
- ), H = o((t) => {
48
+ ), H = r((t) => {
49
49
  q.current = t;
50
- }, []), N = d(null), U = o((t) => {
50
+ }, []), N = d(null), U = r((t) => {
51
51
  N.current = t;
52
- }, []), Y = o(() => {
52
+ }, []), Y = r(() => {
53
53
  N.current?.();
54
- }, []), k = o((t, e, c) => {
55
- const l = M.current;
56
- (l[q.current] ?? l.instructions)?.(t, e, c);
57
- }, []), [z, S] = B(null), x = d(null), D = d(0), u = o(
54
+ }, []), z = r((t, e, i) => {
55
+ const m = M.current;
56
+ (m[q.current] ?? m.instructions)?.(t, e, i);
57
+ }, []), [D, S] = h(null), p = d(null), J = d(0), u = r(
58
58
  (t) => {
59
- g === void 0 && st(t), I?.(t);
59
+ g === void 0 && rt(t), F?.(t);
60
60
  },
61
- [g, I]
62
- ), J = o(() => {
63
- const t = _[Math.min(i + 1, _.length - 1)];
61
+ [g, F]
62
+ ), Q = r(() => {
63
+ const t = _[Math.min(c + 1, _.length - 1)];
64
64
  u(t);
65
- }, [i, u]), Q = o(() => {
66
- const t = _[Math.max(i - 1, 0)];
65
+ }, [c, u]), W = r(() => {
66
+ const t = _[Math.max(c - 1, 0)];
67
67
  u(t);
68
- }, [i, u]), W = o(
68
+ }, [c, u]), X = r(
69
69
  (t) => s(t),
70
70
  [s]
71
- ), X = o(
71
+ ), Z = r(
72
72
  (t, e) => s({ [t]: e }),
73
73
  [s]
74
- ), Z = o(
74
+ ), k = r(
75
75
  (t, e) => {
76
- const c = j.current;
77
- t === "tool" ? c.tools.includes(e) || s({ tools: [...c.tools, e] }) : c.subagents.includes(e) || s({ subagents: [...c.subagents, e] });
76
+ const i = j.current;
77
+ t === "tool" ? i.tools.includes(e) || s({ tools: [...i.tools, e] }) : i.subagents.includes(e) || s({ subagents: [...i.subagents, e] });
78
78
  },
79
79
  [s]
80
- ), C = o(
80
+ ), C = r(
81
81
  (t, e) => {
82
- const c = t === "tool" ? (() => {
83
- const r = m.find((it) => it.tool_id === e);
84
- return r ? `{{tool:${r.function_key}}}` : null;
85
- })() : `{{subagent:${e}}}`, l = (r) => c ? r.split(c).join("") : r;
86
- x.current = {
82
+ const i = t === "tool" ? `{{tool:${e}}}` : `{{subagent:${e}}}`, m = (o) => o.split(i).join("");
83
+ p.current = {
87
84
  tools: n.tools,
88
85
  subagents: n.subagents,
89
86
  instructions: n.instructions,
90
87
  guardrail: n.guardrail
91
88
  };
92
89
  const tt = {
93
- instructions: l(n.instructions),
94
- guardrail: l(n.guardrail ?? ""),
95
- ...t === "tool" ? { tools: n.tools.filter((r) => r !== e) } : { subagents: n.subagents.filter((r) => r !== e) }
90
+ instructions: m(n.instructions),
91
+ guardrail: m(n.guardrail ?? ""),
92
+ ...t === "tool" ? { tools: n.tools.filter((o) => o !== e) } : { subagents: n.subagents.filter((o) => o !== e) }
96
93
  };
97
- s(tt), b((r) => r + 1);
98
- const ct = t === "tool" ? m.find((r) => r.tool_id === e)?.display_name ?? "Tool" : f.find((r) => r.id === e)?.name ?? "Sub-agent";
99
- D.current += 1, S({
100
- id: D.current,
94
+ s(tt), K((o) => o + 1);
95
+ const ct = t === "tool" ? l.find((o) => o.tool_id === e)?.display_name ?? "Tool" : f.find((o) => o.id === e)?.name ?? "Sub-agent";
96
+ J.current += 1, S({
97
+ id: J.current,
101
98
  message: `${t === "tool" ? "Tool" : "Sub-agent"} "${ct}" removed`
102
99
  });
103
100
  },
104
- [m, f, n, s]
105
- ), O = o(() => {
106
- x.current && (s(x.current), x.current = null, b((t) => t + 1)), S(null);
107
- }, [s]), v = o(() => S(null), []), R = F(
108
- () => ({ ...mt, ...a }),
109
- [a]
110
- ), h = F(
111
- () => ({ ...ft(n, R), ...E }),
112
- [n, R, E]
113
- ), ot = F(
101
+ [l, f, n, s]
102
+ ), O = r(() => {
103
+ p.current && (s(p.current), p.current = null, K((t) => t + 1)), S(null);
104
+ }, [s]), v = r(() => S(null), []), R = B(
105
+ () => ({ ...gt, ...T }),
106
+ [T]
107
+ ), a = B(
108
+ () => ({ ...lt(n, R), ...A }),
109
+ [n, R, A]
110
+ ), ot = B(
114
111
  () => ({
115
112
  value: n,
116
- patch: W,
117
- updateField: X,
118
- addReference: Z,
113
+ patch: X,
114
+ updateField: Z,
115
+ addReference: k,
119
116
  removeReference: C,
120
- mentionResetKey: K,
121
- insertMention: k,
117
+ mentionResetKey: y,
118
+ insertMention: z,
122
119
  registerMentionField: G,
123
120
  notifyMentionFocus: H,
124
- undoToast: z,
121
+ undoToast: D,
125
122
  undoRemoval: O,
126
123
  dismissUndo: v,
127
- activeStep: p,
128
- activeIndex: i,
124
+ activeStep: x,
125
+ activeIndex: c,
129
126
  goToStep: u,
130
- goNext: J,
131
- goPrev: Q,
132
- isFirstStep: i === 0,
133
- isLastStep: i === _.length - 1,
134
- validation: h,
135
- isActiveStepValid: h[p],
136
- availableTools: m,
127
+ goNext: Q,
128
+ goPrev: W,
129
+ isFirstStep: c === 0,
130
+ isLastStep: c === _.length - 1,
131
+ validation: a,
132
+ isActiveStepValid: a[x],
133
+ availableTools: l,
137
134
  availableSubAgents: f,
138
- availableIntents: P,
139
- availableModels: A,
140
- applicationType: $,
135
+ availableIntents: I,
136
+ availableModels: P,
137
+ applicationType: E,
141
138
  charLimits: R,
142
- disableStepNavigation: w,
143
- onCreateSubAgent: y,
139
+ disableStepNavigation: $,
140
+ onCreateSubAgent: w,
144
141
  registerSubAgentCreator: U,
145
142
  requestCreateSubAgent: Y,
146
143
  onFetchSubAgent: L,
147
- onUpdateSubAgent: T,
148
- onImproveSubAgent: V
144
+ onUpdateSubAgent: V,
145
+ onImproveSubAgent: b
149
146
  }),
150
147
  [
151
148
  n,
152
- W,
153
149
  X,
154
150
  Z,
155
- C,
156
- K,
157
151
  k,
152
+ C,
153
+ y,
154
+ z,
158
155
  G,
159
156
  H,
160
- z,
157
+ D,
161
158
  O,
162
159
  v,
163
- p,
164
- i,
160
+ x,
161
+ c,
165
162
  u,
166
- J,
167
163
  Q,
168
- h,
169
- m,
164
+ W,
165
+ a,
166
+ l,
170
167
  f,
168
+ I,
171
169
  P,
172
- A,
173
- $,
170
+ E,
174
171
  R,
172
+ $,
175
173
  w,
176
- y,
177
174
  U,
178
175
  Y,
179
176
  L,
180
- T,
181
- V
177
+ V,
178
+ b
182
179
  ]
183
180
  );
184
- return /* @__PURE__ */ ut(nt.Provider, { value: ot, children: et });
181
+ return /* @__PURE__ */ it(nt.Provider, { value: ot, children: et });
185
182
  };
186
183
  export {
187
- St as AgentBuilderProvider,
188
- Mt as useAgentBuilderContext
184
+ Mt as AgentBuilderProvider,
185
+ _t as useAgentBuilderContext
189
186
  };
190
187
  //# sourceMappingURL=AgentBuilderContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AgentBuilderContext.js","sources":["../../../../../src/components/agent-builder/context/AgentBuilderContext.tsx"],"sourcesContent":["import type { ApplicationType } from '@bikdotai/bik-models/growth';\nimport React, {\n\tuseCallback,\n\tuseContext,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from 'react';\nimport {\n\tAgentTool,\n\tAgentValue,\n\tIntentOption,\n\tModelOption,\n\tStepKey,\n\tStepValidation,\n\tSubAgentDraft,\n\tSubAgentRef,\n} from '../AgentBuilder.model';\nimport { AGENT_CHAR_LIMITS } from '../constants/charLimits';\nimport type { AgentCharLimits } from '../constants/charLimits';\nimport { getStepIndex, STEP_KEYS } from '../constants/steps';\n\n/** Mention-capable text fields in Step 3 (both store firebase token text). */\nexport type MentionFieldKey = 'instructions' | 'guardrail';\ntype MentionInsertFn = (\n\tkind: 'tool' | 'subagent',\n\tid: string,\n\tlabel?: string,\n) => void;\n\n/** Toast shown after a tool / sub-agent is removed, offering an undo. */\nexport interface UndoToastState {\n\t/** Bumped per removal so the toast timer restarts. */\n\tid: number;\n\tmessage: string;\n}\n\nexport interface AgentBuilderContextShape {\n\t/** Controlled value relayed from props. */\n\tvalue: AgentValue;\n\t/** Patch one or more fields. */\n\tpatch: (partial: Partial<AgentValue>) => void;\n\t/** Patch a single field. */\n\tupdateField: <K extends keyof AgentValue>(key: K, val: AgentValue[K]) => void;\n\t/**\n\t * Remove a tool / sub-agent everywhere: drops it from the list AND strips ALL\n\t * its `{{tool:KEY}}` / `{{subagent:ID}}` tokens from BOTH the instructions and\n\t * the guardrails, remounts the editors, and raises an undo toast.\n\t */\n\tremoveReference: (kind: 'tool' | 'subagent', id: string) => void;\n\t/**\n\t * Append a tool / sub-agent id to its list (deduped), reading the LATEST value\n\t * via a ref. Use this instead of `patch({ tools: [...value.tools, id] })` from\n\t * any handler that may be captured with a stale `value` — notably the `@`\n\t * editor's mount-time `onSelect`, which would otherwise keep only the last pick.\n\t */\n\taddReference: (kind: 'tool' | 'subagent', id: string) => void;\n\t/** Remount signal for the mention editors after an external edit. */\n\tmentionResetKey: number;\n\t/**\n\t * Insert a tool / sub-agent mention chip at the last cursor position of\n\t * whichever mention field was focused most recently (Instructions or\n\t * Guardrails). `label` overrides the chip text (e.g. a just-created sub-agent\n\t * not yet in the available list).\n\t */\n\tinsertMention: (\n\t\tkind: 'tool' | 'subagent',\n\t\tid: string,\n\t\tlabel?: string,\n\t) => void;\n\t/** A mention field registers its editor-backed insert here (internal). */\n\tregisterMentionField: (\n\t\tfieldKey: MentionFieldKey,\n\t\tfn: MentionInsertFn | null,\n\t) => void;\n\t/** A mention field reports focus so inserts target it (internal). */\n\tnotifyMentionFocus: (fieldKey: MentionFieldKey) => void;\n\n\t// Undo (post-removal)\n\t/** Non-null while the undo toast should be visible. */\n\tundoToast: UndoToastState | null;\n\t/** Restore the last removed tool / sub-agent (list + stripped tokens). */\n\tundoRemoval: () => void;\n\t/** Dismiss the undo toast without restoring. */\n\tdismissUndo: () => void;\n\n\t// Navigation\n\tactiveStep: StepKey;\n\tactiveIndex: number;\n\tgoToStep: (step: StepKey) => void;\n\tgoNext: () => void;\n\tgoPrev: () => void;\n\tisFirstStep: boolean;\n\tisLastStep: boolean;\n\n\t// Validation\n\tvalidation: StepValidation;\n\tisActiveStepValid: boolean;\n\n\t// Reference data\n\tavailableTools: AgentTool[];\n\tavailableSubAgents: SubAgentRef[];\n\tavailableIntents: IntentOption[];\n\tavailableModels: ModelOption[];\n\t/** Host application context (e.g. MANIFEST) — drives tool-chip labelling. */\n\tapplicationType?: ApplicationType;\n\t/** Resolved per-field character limits (consumer overrides merged over defaults). */\n\tcharLimits: AgentCharLimits;\n\t/** When true, step-rail items are not clickable (Back / Next only). */\n\tdisableStepNavigation: boolean;\n\n\t// Sub-agent creation (Step 3 drawer)\n\t/** Persist a new sub-agent and resolve with its ref. Omit to hide the create flow. */\n\tonCreateSubAgent?: (draft: SubAgentDraft) => Promise<SubAgentRef>;\n\t/**\n\t * Step 3 registers its \"open create-sub-agent drawer\" action here so the `@`\n\t * picker's \"Create new\" row can trigger it. Pass `null` to unregister.\n\t */\n\tregisterSubAgentCreator: (fn: (() => void) | null) => void;\n\t/** Open the create-sub-agent drawer (no-op until Step 3 registers it). */\n\trequestCreateSubAgent: () => void;\n\t/** Fetch a sub-agent's editable data (Configure). Omit to hide Configure. */\n\tonFetchSubAgent?: (id: string) => Promise<SubAgentDraft>;\n\t/** Persist edits to an existing sub-agent. */\n\tonUpdateSubAgent?: (id: string, draft: SubAgentDraft) => Promise<SubAgentRef>;\n\t/** Optional \"Improve with AI\" for the drawer's instructions / guardrails. */\n\tonImproveSubAgent?: (\n\t\tkind: 'instructions' | 'guardrail',\n\t\ttext: string,\n\t) => Promise<string>;\n}\n\nconst AgentBuilderContext =\n\tReact.createContext<AgentBuilderContextShape | null>(null);\n\nexport const useAgentBuilderContext = (): AgentBuilderContextShape => {\n\tconst ctx = useContext(AgentBuilderContext);\n\tif (!ctx) {\n\t\tthrow new Error(\n\t\t\t'useAgentBuilderContext must be used within an AgentBuilderProvider',\n\t\t);\n\t}\n\treturn ctx;\n};\n\n/** Validity derived purely from the current value (no effects). */\nconst deriveValidation = (\n\tvalue: AgentValue,\n\tlimits: AgentCharLimits,\n): StepValidation => {\n\tconst triggerValid =\n\t\tvalue.trigger.mode === 'custom_intent'\n\t\t\t? (value.trigger.custom_intent ?? '').trim().length > 0\n\t\t\t: value.trigger.intents.length > 0;\n\n\treturn {\n\t\tabout:\n\t\t\tvalue.name.trim().length > 0 &&\n\t\t\tvalue.name.length <= limits.name &&\n\t\t\tvalue.description.length <= limits.description,\n\t\ttrigger: triggerValid,\n\t\t// At least one of Instructions / Guardrails must be filled.\n\t\tresponse:\n\t\t\tvalue.instructions.trim().length > 0 ||\n\t\t\t(value.guardrail ?? '').trim().length > 0,\n\t\t// Optional until specced further — never blocks go-live.\n\t\thandover: true,\n\t};\n};\n\ninterface ProviderProps {\n\tvalue: AgentValue;\n\tonChange: (patch: Partial<AgentValue>) => void;\n\tactiveStep?: StepKey;\n\tonStepChange?: (step: StepKey) => void;\n\tavailableTools: AgentTool[];\n\tavailableSubAgents: SubAgentRef[];\n\tavailableIntents: IntentOption[];\n\tavailableModels: ModelOption[];\n\tvalidation?: Partial<StepValidation>;\n\tapplicationType?: ApplicationType;\n\tcharLimits?: Partial<AgentCharLimits>;\n\tdisableStepNavigation?: boolean;\n\tonCreateSubAgent?: (draft: SubAgentDraft) => Promise<SubAgentRef>;\n\tonFetchSubAgent?: (id: string) => Promise<SubAgentDraft>;\n\tonUpdateSubAgent?: (id: string, draft: SubAgentDraft) => Promise<SubAgentRef>;\n\tonImproveSubAgent?: (\n\t\tkind: 'instructions' | 'guardrail',\n\t\ttext: string,\n\t) => Promise<string>;\n\tchildren: React.ReactNode;\n}\n\nexport const AgentBuilderProvider: React.FC<ProviderProps> = ({\n\tvalue,\n\tonChange,\n\tactiveStep: controlledStep,\n\tonStepChange,\n\tavailableTools,\n\tavailableSubAgents,\n\tavailableIntents,\n\tavailableModels,\n\tvalidation: validationOverride,\n\tapplicationType,\n\tcharLimits: charLimitsOverride,\n\tdisableStepNavigation = true,\n\tonCreateSubAgent,\n\tonFetchSubAgent,\n\tonUpdateSubAgent,\n\tonImproveSubAgent,\n\tchildren,\n}) => {\n\tconst [internalStep, setInternalStep] = useState<StepKey>('about');\n\tconst activeStep = controlledStep ?? internalStep;\n\tconst activeIndex = getStepIndex(activeStep);\n\n\t// Latest value, so closure-captured handlers (e.g. the `@` editor's mount-time\n\t// mention onSelect) append against the current lists, not a stale snapshot.\n\tconst valueRef = useRef(value);\n\tvalueRef.current = value;\n\n\t// Bumped when a mention field is edited from OUTSIDE its editor (removing a\n\t// tool from the side list, undo), forcing the mention editors to remount.\n\tconst [mentionResetKey, setMentionResetKey] = useState(0);\n\n\t// Each mention field registers an editor-backed insert fn + reports focus, so\n\t// side-panel adds drop a chip into the last-focused field at its cursor.\n\tconst mentionInsertersRef = useRef<\n\t\tPartial<Record<MentionFieldKey, MentionInsertFn>>\n\t>({});\n\tconst lastFocusedFieldRef = useRef<MentionFieldKey>('instructions');\n\tconst registerMentionField = useCallback(\n\t\t(fieldKey: MentionFieldKey, fn: MentionInsertFn | null) => {\n\t\t\tif (fn) {\n\t\t\t\tmentionInsertersRef.current[fieldKey] = fn;\n\t\t\t} else {\n\t\t\t\tdelete mentionInsertersRef.current[fieldKey];\n\t\t\t}\n\t\t},\n\t\t[],\n\t);\n\tconst notifyMentionFocus = useCallback((fieldKey: MentionFieldKey) => {\n\t\tlastFocusedFieldRef.current = fieldKey;\n\t}, []);\n\n\t// Step 3 registers its drawer opener here; the `@` picker's \"Create new\" calls it.\n\tconst subAgentCreatorRef = useRef<(() => void) | null>(null);\n\tconst registerSubAgentCreator = useCallback((fn: (() => void) | null) => {\n\t\tsubAgentCreatorRef.current = fn;\n\t}, []);\n\tconst requestCreateSubAgent = useCallback(() => {\n\t\tsubAgentCreatorRef.current?.();\n\t}, []);\n\tconst insertMention = useCallback<MentionInsertFn>((kind, id, label) => {\n\t\tconst inserters = mentionInsertersRef.current;\n\t\tconst target =\n\t\t\tinserters[lastFocusedFieldRef.current] ?? inserters.instructions;\n\t\ttarget?.(kind, id, label);\n\t}, []);\n\n\t// Undo state for the most recent removal.\n\tconst [undoToast, setUndoToast] = useState<UndoToastState | null>(null);\n\tconst undoSnapshotRef = useRef<Partial<AgentValue> | null>(null);\n\tconst undoIdRef = useRef(0);\n\n\tconst goToStep = useCallback(\n\t\t(step: StepKey) => {\n\t\t\tif (controlledStep === undefined) {\n\t\t\t\tsetInternalStep(step);\n\t\t\t}\n\t\t\tonStepChange?.(step);\n\t\t},\n\t\t[controlledStep, onStepChange],\n\t);\n\n\tconst goNext = useCallback(() => {\n\t\tconst next = STEP_KEYS[Math.min(activeIndex + 1, STEP_KEYS.length - 1)];\n\t\tgoToStep(next);\n\t}, [activeIndex, goToStep]);\n\n\tconst goPrev = useCallback(() => {\n\t\tconst prev = STEP_KEYS[Math.max(activeIndex - 1, 0)];\n\t\tgoToStep(prev);\n\t}, [activeIndex, goToStep]);\n\n\tconst patch = useCallback(\n\t\t(partial: Partial<AgentValue>) => onChange(partial),\n\t\t[onChange],\n\t);\n\n\tconst updateField = useCallback(\n\t\t<K extends keyof AgentValue>(key: K, val: AgentValue[K]) =>\n\t\t\tonChange({ [key]: val } as Partial<AgentValue>),\n\t\t[onChange],\n\t);\n\n\tconst addReference = useCallback(\n\t\t(kind: 'tool' | 'subagent', id: string) => {\n\t\t\tconst v = valueRef.current;\n\t\t\tif (kind === 'tool') {\n\t\t\t\tif (!v.tools.includes(id)) {\n\t\t\t\t\tonChange({ tools: [...v.tools, id] });\n\t\t\t\t}\n\t\t\t} else if (!v.subagents.includes(id)) {\n\t\t\t\tonChange({ subagents: [...v.subagents, id] });\n\t\t\t}\n\t\t},\n\t\t[onChange],\n\t);\n\n\tconst removeReference = useCallback(\n\t\t(kind: 'tool' | 'subagent', id: string) => {\n\t\t\tconst token =\n\t\t\t\tkind === 'tool'\n\t\t\t\t\t? (() => {\n\t\t\t\t\t\t\tconst tool = availableTools.find((t) => t.tool_id === id);\n\t\t\t\t\t\t\treturn tool ? `{{tool:${tool.function_key}}}` : null;\n\t\t\t\t\t })()\n\t\t\t\t\t: `{{subagent:${id}}}`;\n\t\t\tconst strip = (text: string) =>\n\t\t\t\ttoken ? text.split(token).join('') : text;\n\n\t\t\t// Snapshot the four fields a removal touches, for undo.\n\t\t\tundoSnapshotRef.current = {\n\t\t\t\ttools: value.tools,\n\t\t\t\tsubagents: value.subagents,\n\t\t\t\tinstructions: value.instructions,\n\t\t\t\tguardrail: value.guardrail,\n\t\t\t};\n\n\t\t\tconst next: Partial<AgentValue> = {\n\t\t\t\tinstructions: strip(value.instructions),\n\t\t\t\tguardrail: strip(value.guardrail ?? ''),\n\t\t\t\t...(kind === 'tool'\n\t\t\t\t\t? { tools: value.tools.filter((t) => t !== id) }\n\t\t\t\t\t: { subagents: value.subagents.filter((s) => s !== id) }),\n\t\t\t};\n\t\t\tonChange(next);\n\t\t\tsetMentionResetKey((k) => k + 1);\n\n\t\t\tconst label =\n\t\t\t\tkind === 'tool'\n\t\t\t\t\t? availableTools.find((t) => t.tool_id === id)?.display_name ?? 'Tool'\n\t\t\t\t\t: availableSubAgents.find((s) => s.id === id)?.name ?? 'Sub-agent';\n\t\t\tundoIdRef.current += 1;\n\t\t\tsetUndoToast({\n\t\t\t\tid: undoIdRef.current,\n\t\t\t\tmessage: `${kind === 'tool' ? 'Tool' : 'Sub-agent'} \"${label}\" removed`,\n\t\t\t});\n\t\t},\n\t\t[availableTools, availableSubAgents, value, onChange],\n\t);\n\n\tconst undoRemoval = useCallback(() => {\n\t\tif (undoSnapshotRef.current) {\n\t\t\tonChange(undoSnapshotRef.current);\n\t\t\tundoSnapshotRef.current = null;\n\t\t\tsetMentionResetKey((k) => k + 1);\n\t\t}\n\t\tsetUndoToast(null);\n\t}, [onChange]);\n\n\tconst dismissUndo = useCallback(() => setUndoToast(null), []);\n\n\t// Consumer overrides merged over the built-in defaults (name 60, rest 1000).\n\tconst charLimits = useMemo<AgentCharLimits>(\n\t\t() => ({ ...AGENT_CHAR_LIMITS, ...charLimitsOverride }),\n\t\t[charLimitsOverride],\n\t);\n\n\tconst validation: StepValidation = useMemo(\n\t\t() => ({ ...deriveValidation(value, charLimits), ...validationOverride }),\n\t\t[value, charLimits, validationOverride],\n\t);\n\n\tconst ctx = useMemo<AgentBuilderContextShape>(\n\t\t() => ({\n\t\t\tvalue,\n\t\t\tpatch,\n\t\t\tupdateField,\n\t\t\taddReference,\n\t\t\tremoveReference,\n\t\t\tmentionResetKey,\n\t\t\tinsertMention,\n\t\t\tregisterMentionField,\n\t\t\tnotifyMentionFocus,\n\t\t\tundoToast,\n\t\t\tundoRemoval,\n\t\t\tdismissUndo,\n\t\t\tactiveStep,\n\t\t\tactiveIndex,\n\t\t\tgoToStep,\n\t\t\tgoNext,\n\t\t\tgoPrev,\n\t\t\tisFirstStep: activeIndex === 0,\n\t\t\tisLastStep: activeIndex === STEP_KEYS.length - 1,\n\t\t\tvalidation,\n\t\t\tisActiveStepValid: validation[activeStep],\n\t\t\tavailableTools,\n\t\t\tavailableSubAgents,\n\t\t\tavailableIntents,\n\t\t\tavailableModels,\n\t\t\tapplicationType,\n\t\t\tcharLimits,\n\t\t\tdisableStepNavigation,\n\t\t\tonCreateSubAgent,\n\t\t\tregisterSubAgentCreator,\n\t\t\trequestCreateSubAgent,\n\t\t\tonFetchSubAgent,\n\t\t\tonUpdateSubAgent,\n\t\t\tonImproveSubAgent,\n\t\t}),\n\t\t[\n\t\t\tvalue,\n\t\t\tpatch,\n\t\t\tupdateField,\n\t\t\taddReference,\n\t\t\tremoveReference,\n\t\t\tmentionResetKey,\n\t\t\tinsertMention,\n\t\t\tregisterMentionField,\n\t\t\tnotifyMentionFocus,\n\t\t\tundoToast,\n\t\t\tundoRemoval,\n\t\t\tdismissUndo,\n\t\t\tactiveStep,\n\t\t\tactiveIndex,\n\t\t\tgoToStep,\n\t\t\tgoNext,\n\t\t\tgoPrev,\n\t\t\tvalidation,\n\t\t\tavailableTools,\n\t\t\tavailableSubAgents,\n\t\t\tavailableIntents,\n\t\t\tavailableModels,\n\t\t\tapplicationType,\n\t\t\tcharLimits,\n\t\t\tdisableStepNavigation,\n\t\t\tonCreateSubAgent,\n\t\t\tregisterSubAgentCreator,\n\t\t\trequestCreateSubAgent,\n\t\t\tonFetchSubAgent,\n\t\t\tonUpdateSubAgent,\n\t\t\tonImproveSubAgent,\n\t\t],\n\t);\n\n\treturn (\n\t\t<AgentBuilderContext.Provider value={ctx}>\n\t\t\t{children}\n\t\t</AgentBuilderContext.Provider>\n\t);\n};\n"],"names":["AgentBuilderContext","React","useAgentBuilderContext","ctx","useContext","deriveValidation","value","limits","triggerValid","AgentBuilderProvider","onChange","controlledStep","onStepChange","availableTools","availableSubAgents","availableIntents","availableModels","validationOverride","applicationType","charLimitsOverride","disableStepNavigation","onCreateSubAgent","onFetchSubAgent","onUpdateSubAgent","onImproveSubAgent","children","internalStep","setInternalStep","useState","activeStep","activeIndex","getStepIndex","valueRef","useRef","mentionResetKey","setMentionResetKey","mentionInsertersRef","lastFocusedFieldRef","registerMentionField","useCallback","fieldKey","fn","notifyMentionFocus","subAgentCreatorRef","registerSubAgentCreator","requestCreateSubAgent","insertMention","kind","id","label","inserters","undoToast","setUndoToast","undoSnapshotRef","undoIdRef","goToStep","step","goNext","next","STEP_KEYS","goPrev","prev","patch","partial","updateField","key","val","addReference","v","removeReference","token","tool","t","strip","text","s","k","undoRemoval","dismissUndo","charLimits","useMemo","AGENT_CHAR_LIMITS","validation"],"mappings":";;;;AAoIA,MAAMA,KACLC,GAAM,cAA+C,IAAI,GAE7CC,KAAyB,MAAgC;AACrE,QAAMC,IAAMC,GAAWJ,EAAmB;AAC1C,MAAI,CAACG;AACJ,UAAM,IAAI;AAAA,MACT;AAAA,IAAA;AAGF,SAAOA;AACR,GAGME,KAAmB,CACxBC,GACAC,MACoB;AACpB,QAAMC,IACLF,EAAM,QAAQ,SAAS,mBACnBA,EAAM,QAAQ,iBAAiB,IAAI,KAAA,EAAO,SAAS,IACpDA,EAAM,QAAQ,QAAQ,SAAS;AAEnC,SAAO;AAAA,IACN,OACCA,EAAM,KAAK,KAAA,EAAO,SAAS,KAC3BA,EAAM,KAAK,UAAUC,EAAO,QAC5BD,EAAM,YAAY,UAAUC,EAAO;AAAA,IACpC,SAASC;AAAA;AAAA,IAET,UACCF,EAAM,aAAa,KAAA,EAAO,SAAS,MAClCA,EAAM,aAAa,IAAI,K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AAAA,MACA,uBAAAC;AAAA,MACA,iBAAAvB;AAAA,MACA,kBAAAC;AAAA,MACA,mBAAAC;AAAA,IAAA;AAAA,IAED;AAAA,MACClB;AAAA,MACAwD;AAAA,MACAE;AAAA,MACAG;AAAA,MACAE;AAAA,MACAnC;AAAA,MACAY;AAAA,MACAR;AAAA,MACAI;AAAA,MACAS;AAAA,MACA0B;AAAA,MACAC;AAAA,MACAjD;AAAA,MACAC;AAAA,MACAyB;AAAA,MACAE;AAAA,MACAG;AAAA,MACAsB;AAAA,MACArE;AAAA,MACAC;AAAA,MACAC;AAAA,MACAC;AAAA,MACAE;AAAA,MACA6D;AAAA,MACA3D;AAAA,MACAC;AAAA,MACAuB;AAAA,MACAC;AAAA,MACAvB;AAAA,MACAC;AAAA,MACAC;AAAA,IAAA;AAAA,EACD;AAGD,4BACExB,GAAoB,UAApB,EAA6B,OAAOG,IACnC,UAAAsB,IACF;AAEF;"}
1
+ {"version":3,"file":"AgentBuilderContext.js","sources":["../../../../../src/components/agent-builder/context/AgentBuilderContext.tsx"],"sourcesContent":["import type { ApplicationType } from '@bikdotai/bik-models/growth';\nimport React, {\n\tuseCallback,\n\tuseContext,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from 'react';\nimport {\n\tAgentTool,\n\tAgentValue,\n\tIntentOption,\n\tModelOption,\n\tStepKey,\n\tStepValidation,\n\tSubAgentDraft,\n\tSubAgentRef,\n} from '../AgentBuilder.model';\nimport { AGENT_CHAR_LIMITS } from '../constants/charLimits';\nimport type { AgentCharLimits } from '../constants/charLimits';\nimport { getStepIndex, STEP_KEYS } from '../constants/steps';\n\n/** Mention-capable text fields in Step 3 (both store firebase token text). */\nexport type MentionFieldKey = 'instructions' | 'guardrail';\ntype MentionInsertFn = (\n\tkind: 'tool' | 'subagent',\n\tid: string,\n\tlabel?: string,\n) => void;\n\n/** Toast shown after a tool / sub-agent is removed, offering an undo. */\nexport interface UndoToastState {\n\t/** Bumped per removal so the toast timer restarts. */\n\tid: number;\n\tmessage: string;\n}\n\nexport interface AgentBuilderContextShape {\n\t/** Controlled value relayed from props. */\n\tvalue: AgentValue;\n\t/** Patch one or more fields. */\n\tpatch: (partial: Partial<AgentValue>) => void;\n\t/** Patch a single field. */\n\tupdateField: <K extends keyof AgentValue>(key: K, val: AgentValue[K]) => void;\n\t/**\n\t * Remove a tool / sub-agent everywhere: drops it from the list AND strips ALL\n\t * its `{{tool:KEY}}` / `{{subagent:ID}}` tokens from BOTH the instructions and\n\t * the guardrails, remounts the editors, and raises an undo toast.\n\t */\n\tremoveReference: (kind: 'tool' | 'subagent', id: string) => void;\n\t/**\n\t * Append a tool / sub-agent id to its list (deduped), reading the LATEST value\n\t * via a ref. Use this instead of `patch({ tools: [...value.tools, id] })` from\n\t * any handler that may be captured with a stale `value` — notably the `@`\n\t * editor's mount-time `onSelect`, which would otherwise keep only the last pick.\n\t */\n\taddReference: (kind: 'tool' | 'subagent', id: string) => void;\n\t/** Remount signal for the mention editors after an external edit. */\n\tmentionResetKey: number;\n\t/**\n\t * Insert a tool / sub-agent mention chip at the last cursor position of\n\t * whichever mention field was focused most recently (Instructions or\n\t * Guardrails). `label` overrides the chip text (e.g. a just-created sub-agent\n\t * not yet in the available list).\n\t */\n\tinsertMention: (\n\t\tkind: 'tool' | 'subagent',\n\t\tid: string,\n\t\tlabel?: string,\n\t) => void;\n\t/** A mention field registers its editor-backed insert here (internal). */\n\tregisterMentionField: (\n\t\tfieldKey: MentionFieldKey,\n\t\tfn: MentionInsertFn | null,\n\t) => void;\n\t/** A mention field reports focus so inserts target it (internal). */\n\tnotifyMentionFocus: (fieldKey: MentionFieldKey) => void;\n\n\t// Undo (post-removal)\n\t/** Non-null while the undo toast should be visible. */\n\tundoToast: UndoToastState | null;\n\t/** Restore the last removed tool / sub-agent (list + stripped tokens). */\n\tundoRemoval: () => void;\n\t/** Dismiss the undo toast without restoring. */\n\tdismissUndo: () => void;\n\n\t// Navigation\n\tactiveStep: StepKey;\n\tactiveIndex: number;\n\tgoToStep: (step: StepKey) => void;\n\tgoNext: () => void;\n\tgoPrev: () => void;\n\tisFirstStep: boolean;\n\tisLastStep: boolean;\n\n\t// Validation\n\tvalidation: StepValidation;\n\tisActiveStepValid: boolean;\n\n\t// Reference data\n\tavailableTools: AgentTool[];\n\tavailableSubAgents: SubAgentRef[];\n\tavailableIntents: IntentOption[];\n\tavailableModels: ModelOption[];\n\t/** Host application context (e.g. MANIFEST) — drives tool-chip labelling. */\n\tapplicationType?: ApplicationType;\n\t/** Resolved per-field character limits (consumer overrides merged over defaults). */\n\tcharLimits: AgentCharLimits;\n\t/** When true, step-rail items are not clickable (Back / Next only). */\n\tdisableStepNavigation: boolean;\n\n\t// Sub-agent creation (Step 3 drawer)\n\t/** Persist a new sub-agent and resolve with its ref. Omit to hide the create flow. */\n\tonCreateSubAgent?: (draft: SubAgentDraft) => Promise<SubAgentRef>;\n\t/**\n\t * Step 3 registers its \"open create-sub-agent drawer\" action here so the `@`\n\t * picker's \"Create new\" row can trigger it. Pass `null` to unregister.\n\t */\n\tregisterSubAgentCreator: (fn: (() => void) | null) => void;\n\t/** Open the create-sub-agent drawer (no-op until Step 3 registers it). */\n\trequestCreateSubAgent: () => void;\n\t/** Fetch a sub-agent's editable data (Configure). Omit to hide Configure. */\n\tonFetchSubAgent?: (id: string) => Promise<SubAgentDraft>;\n\t/** Persist edits to an existing sub-agent. */\n\tonUpdateSubAgent?: (id: string, draft: SubAgentDraft) => Promise<SubAgentRef>;\n\t/** Optional \"Improve with AI\" for the drawer's instructions / guardrails. */\n\tonImproveSubAgent?: (\n\t\tkind: 'instructions' | 'guardrail',\n\t\ttext: string,\n\t) => Promise<string>;\n}\n\nconst AgentBuilderContext =\n\tReact.createContext<AgentBuilderContextShape | null>(null);\n\nexport const useAgentBuilderContext = (): AgentBuilderContextShape => {\n\tconst ctx = useContext(AgentBuilderContext);\n\tif (!ctx) {\n\t\tthrow new Error(\n\t\t\t'useAgentBuilderContext must be used within an AgentBuilderProvider',\n\t\t);\n\t}\n\treturn ctx;\n};\n\n/** Validity derived purely from the current value (no effects). */\nconst deriveValidation = (\n\tvalue: AgentValue,\n\tlimits: AgentCharLimits,\n): StepValidation => {\n\tconst triggerValid =\n\t\tvalue.trigger.mode === 'custom_intent'\n\t\t\t? (value.trigger.custom_intent ?? '').trim().length > 0\n\t\t\t: value.trigger.intents.length > 0;\n\n\treturn {\n\t\tabout:\n\t\t\tvalue.name.trim().length > 0 &&\n\t\t\tvalue.name.length <= limits.name &&\n\t\t\tvalue.description.length <= limits.description,\n\t\ttrigger: triggerValid,\n\t\t// At least one of Instructions / Guardrails must be filled.\n\t\tresponse:\n\t\t\tvalue.instructions.trim().length > 0 ||\n\t\t\t(value.guardrail ?? '').trim().length > 0,\n\t\t// Optional until specced further — never blocks go-live.\n\t\thandover: true,\n\t};\n};\n\ninterface ProviderProps {\n\tvalue: AgentValue;\n\tonChange: (patch: Partial<AgentValue>) => void;\n\tactiveStep?: StepKey;\n\tonStepChange?: (step: StepKey) => void;\n\tavailableTools: AgentTool[];\n\tavailableSubAgents: SubAgentRef[];\n\tavailableIntents: IntentOption[];\n\tavailableModels: ModelOption[];\n\tvalidation?: Partial<StepValidation>;\n\tapplicationType?: ApplicationType;\n\tcharLimits?: Partial<AgentCharLimits>;\n\tdisableStepNavigation?: boolean;\n\tonCreateSubAgent?: (draft: SubAgentDraft) => Promise<SubAgentRef>;\n\tonFetchSubAgent?: (id: string) => Promise<SubAgentDraft>;\n\tonUpdateSubAgent?: (id: string, draft: SubAgentDraft) => Promise<SubAgentRef>;\n\tonImproveSubAgent?: (\n\t\tkind: 'instructions' | 'guardrail',\n\t\ttext: string,\n\t) => Promise<string>;\n\tchildren: React.ReactNode;\n}\n\nexport const AgentBuilderProvider: React.FC<ProviderProps> = ({\n\tvalue,\n\tonChange,\n\tactiveStep: controlledStep,\n\tonStepChange,\n\tavailableTools,\n\tavailableSubAgents,\n\tavailableIntents,\n\tavailableModels,\n\tvalidation: validationOverride,\n\tapplicationType,\n\tcharLimits: charLimitsOverride,\n\tdisableStepNavigation = true,\n\tonCreateSubAgent,\n\tonFetchSubAgent,\n\tonUpdateSubAgent,\n\tonImproveSubAgent,\n\tchildren,\n}) => {\n\tconst [internalStep, setInternalStep] = useState<StepKey>('about');\n\tconst activeStep = controlledStep ?? internalStep;\n\tconst activeIndex = getStepIndex(activeStep);\n\n\t// Latest value, so closure-captured handlers (e.g. the `@` editor's mount-time\n\t// mention onSelect) append against the current lists, not a stale snapshot.\n\tconst valueRef = useRef(value);\n\tvalueRef.current = value;\n\n\t// Bumped when a mention field is edited from OUTSIDE its editor (removing a\n\t// tool from the side list, undo), forcing the mention editors to remount.\n\tconst [mentionResetKey, setMentionResetKey] = useState(0);\n\n\t// Each mention field registers an editor-backed insert fn + reports focus, so\n\t// side-panel adds drop a chip into the last-focused field at its cursor.\n\tconst mentionInsertersRef = useRef<\n\t\tPartial<Record<MentionFieldKey, MentionInsertFn>>\n\t>({});\n\tconst lastFocusedFieldRef = useRef<MentionFieldKey>('instructions');\n\tconst registerMentionField = useCallback(\n\t\t(fieldKey: MentionFieldKey, fn: MentionInsertFn | null) => {\n\t\t\tif (fn) {\n\t\t\t\tmentionInsertersRef.current[fieldKey] = fn;\n\t\t\t} else {\n\t\t\t\tdelete mentionInsertersRef.current[fieldKey];\n\t\t\t}\n\t\t},\n\t\t[],\n\t);\n\tconst notifyMentionFocus = useCallback((fieldKey: MentionFieldKey) => {\n\t\tlastFocusedFieldRef.current = fieldKey;\n\t}, []);\n\n\t// Step 3 registers its drawer opener here; the `@` picker's \"Create new\" calls it.\n\tconst subAgentCreatorRef = useRef<(() => void) | null>(null);\n\tconst registerSubAgentCreator = useCallback((fn: (() => void) | null) => {\n\t\tsubAgentCreatorRef.current = fn;\n\t}, []);\n\tconst requestCreateSubAgent = useCallback(() => {\n\t\tsubAgentCreatorRef.current?.();\n\t}, []);\n\tconst insertMention = useCallback<MentionInsertFn>((kind, id, label) => {\n\t\tconst inserters = mentionInsertersRef.current;\n\t\tconst target =\n\t\t\tinserters[lastFocusedFieldRef.current] ?? inserters.instructions;\n\t\ttarget?.(kind, id, label);\n\t}, []);\n\n\t// Undo state for the most recent removal.\n\tconst [undoToast, setUndoToast] = useState<UndoToastState | null>(null);\n\tconst undoSnapshotRef = useRef<Partial<AgentValue> | null>(null);\n\tconst undoIdRef = useRef(0);\n\n\tconst goToStep = useCallback(\n\t\t(step: StepKey) => {\n\t\t\tif (controlledStep === undefined) {\n\t\t\t\tsetInternalStep(step);\n\t\t\t}\n\t\t\tonStepChange?.(step);\n\t\t},\n\t\t[controlledStep, onStepChange],\n\t);\n\n\tconst goNext = useCallback(() => {\n\t\tconst next = STEP_KEYS[Math.min(activeIndex + 1, STEP_KEYS.length - 1)];\n\t\tgoToStep(next);\n\t}, [activeIndex, goToStep]);\n\n\tconst goPrev = useCallback(() => {\n\t\tconst prev = STEP_KEYS[Math.max(activeIndex - 1, 0)];\n\t\tgoToStep(prev);\n\t}, [activeIndex, goToStep]);\n\n\tconst patch = useCallback(\n\t\t(partial: Partial<AgentValue>) => onChange(partial),\n\t\t[onChange],\n\t);\n\n\tconst updateField = useCallback(\n\t\t<K extends keyof AgentValue>(key: K, val: AgentValue[K]) =>\n\t\t\tonChange({ [key]: val } as Partial<AgentValue>),\n\t\t[onChange],\n\t);\n\n\tconst addReference = useCallback(\n\t\t(kind: 'tool' | 'subagent', id: string) => {\n\t\t\tconst v = valueRef.current;\n\t\t\tif (kind === 'tool') {\n\t\t\t\tif (!v.tools.includes(id)) {\n\t\t\t\t\tonChange({ tools: [...v.tools, id] });\n\t\t\t\t}\n\t\t\t} else if (!v.subagents.includes(id)) {\n\t\t\t\tonChange({ subagents: [...v.subagents, id] });\n\t\t\t}\n\t\t},\n\t\t[onChange],\n\t);\n\n\tconst removeReference = useCallback(\n\t\t(kind: 'tool' | 'subagent', id: string) => {\n\t\t\t// Tokens store the id for both kinds (a tool's id is its tool_id).\n\t\t\tconst token = kind === 'tool' ? `{{tool:${id}}}` : `{{subagent:${id}}}`;\n\t\t\tconst strip = (text: string) => text.split(token).join('');\n\n\t\t\t// Snapshot the four fields a removal touches, for undo.\n\t\t\tundoSnapshotRef.current = {\n\t\t\t\ttools: value.tools,\n\t\t\t\tsubagents: value.subagents,\n\t\t\t\tinstructions: value.instructions,\n\t\t\t\tguardrail: value.guardrail,\n\t\t\t};\n\n\t\t\tconst next: Partial<AgentValue> = {\n\t\t\t\tinstructions: strip(value.instructions),\n\t\t\t\tguardrail: strip(value.guardrail ?? ''),\n\t\t\t\t...(kind === 'tool'\n\t\t\t\t\t? { tools: value.tools.filter((t) => t !== id) }\n\t\t\t\t\t: { subagents: value.subagents.filter((s) => s !== id) }),\n\t\t\t};\n\t\t\tonChange(next);\n\t\t\tsetMentionResetKey((k) => k + 1);\n\n\t\t\tconst label =\n\t\t\t\tkind === 'tool'\n\t\t\t\t\t? availableTools.find((t) => t.tool_id === id)?.display_name ?? 'Tool'\n\t\t\t\t\t: availableSubAgents.find((s) => s.id === id)?.name ?? 'Sub-agent';\n\t\t\tundoIdRef.current += 1;\n\t\t\tsetUndoToast({\n\t\t\t\tid: undoIdRef.current,\n\t\t\t\tmessage: `${kind === 'tool' ? 'Tool' : 'Sub-agent'} \"${label}\" removed`,\n\t\t\t});\n\t\t},\n\t\t[availableTools, availableSubAgents, value, onChange],\n\t);\n\n\tconst undoRemoval = useCallback(() => {\n\t\tif (undoSnapshotRef.current) {\n\t\t\tonChange(undoSnapshotRef.current);\n\t\t\tundoSnapshotRef.current = null;\n\t\t\tsetMentionResetKey((k) => k + 1);\n\t\t}\n\t\tsetUndoToast(null);\n\t}, [onChange]);\n\n\tconst dismissUndo = useCallback(() => setUndoToast(null), []);\n\n\t// Consumer overrides merged over the built-in defaults (name 60, rest 1000).\n\tconst charLimits = useMemo<AgentCharLimits>(\n\t\t() => ({ ...AGENT_CHAR_LIMITS, ...charLimitsOverride }),\n\t\t[charLimitsOverride],\n\t);\n\n\tconst validation: StepValidation = useMemo(\n\t\t() => ({ ...deriveValidation(value, charLimits), ...validationOverride }),\n\t\t[value, charLimits, validationOverride],\n\t);\n\n\tconst ctx = useMemo<AgentBuilderContextShape>(\n\t\t() => ({\n\t\t\tvalue,\n\t\t\tpatch,\n\t\t\tupdateField,\n\t\t\taddReference,\n\t\t\tremoveReference,\n\t\t\tmentionResetKey,\n\t\t\tinsertMention,\n\t\t\tregisterMentionField,\n\t\t\tnotifyMentionFocus,\n\t\t\tundoToast,\n\t\t\tundoRemoval,\n\t\t\tdismissUndo,\n\t\t\tactiveStep,\n\t\t\tactiveIndex,\n\t\t\tgoToStep,\n\t\t\tgoNext,\n\t\t\tgoPrev,\n\t\t\tisFirstStep: activeIndex === 0,\n\t\t\tisLastStep: activeIndex === STEP_KEYS.length - 1,\n\t\t\tvalidation,\n\t\t\tisActiveStepValid: validation[activeStep],\n\t\t\tavailableTools,\n\t\t\tavailableSubAgents,\n\t\t\tavailableIntents,\n\t\t\tavailableModels,\n\t\t\tapplicationType,\n\t\t\tcharLimits,\n\t\t\tdisableStepNavigation,\n\t\t\tonCreateSubAgent,\n\t\t\tregisterSubAgentCreator,\n\t\t\trequestCreateSubAgent,\n\t\t\tonFetchSubAgent,\n\t\t\tonUpdateSubAgent,\n\t\t\tonImproveSubAgent,\n\t\t}),\n\t\t[\n\t\t\tvalue,\n\t\t\tpatch,\n\t\t\tupdateField,\n\t\t\taddReference,\n\t\t\tremoveReference,\n\t\t\tmentionResetKey,\n\t\t\tinsertMention,\n\t\t\tregisterMentionField,\n\t\t\tnotifyMentionFocus,\n\t\t\tundoToast,\n\t\t\tundoRemoval,\n\t\t\tdismissUndo,\n\t\t\tactiveStep,\n\t\t\tactiveIndex,\n\t\t\tgoToStep,\n\t\t\tgoNext,\n\t\t\tgoPrev,\n\t\t\tvalidation,\n\t\t\tavailableTools,\n\t\t\tavailableSubAgents,\n\t\t\tavailableIntents,\n\t\t\tavailableModels,\n\t\t\tapplicationType,\n\t\t\tcharLimits,\n\t\t\tdisableStepNavigation,\n\t\t\tonCreateSubAgent,\n\t\t\tregisterSubAgentCreator,\n\t\t\trequestCreateSubAgent,\n\t\t\tonFetchSubAgent,\n\t\t\tonUpdateSubAgent,\n\t\t\tonImproveSubAgent,\n\t\t],\n\t);\n\n\treturn (\n\t\t<AgentBuilderContext.Provider value={ctx}>\n\t\t\t{children}\n\t\t</AgentBuilderContext.Provider>\n\t);\n};\n"],"names":["AgentBuilderContext","React","useAgentBuilderContext","ctx","useContext","deriveValidation","value","limits","triggerValid","AgentBuilderProvider","onChange","controlledStep","onStepChange","availableTools","availableSubAgents","availableIntents","availableModels","validationOverride","applicationType","charLimitsOverride","disableStepNavigation","onCreateSubAgent","onFetchSubAgent","onUpdateSubAgent","onImproveSubAgent","children","internalStep","setInternalStep","useState","activeStep","activeIndex","getStepIndex","valueRef","useRef","mentionResetKey","setMentionResetKey","mentionInsertersRef","lastFocusedFieldRef","registerMentionField","useCallback","fieldKey","fn","notifyMentionFocus","subAgentCreatorRef","registerSubAgentCreator","requestCreateSubAgent","insertMention","kind","id","label","inserters","undoToast","setUndoToast","undoSnapshotRef","undoIdRef","goToStep","step","goNext","next","STEP_KEYS","goPrev","prev","patch","partial","updateField","key","val","addReference","v","removeReference","token","strip","text","t","s","k","undoRemoval","dismissUndo","charLimits","useMemo","AGENT_CHAR_LIMITS","validation"],"mappings":";;;;AAoIA,MAAMA,KACLC,GAAM,cAA+C,IAAI,GAE7CC,KAAyB,MAAgC;AACrE,QAAMC,IAAMC,GAAWJ,EAAmB;AAC1C,MAAI,CAACG;AACJ,UAAM,IAAI;AAAA,MACT;AAAA,IAAA;AAGF,SAAOA;AACR,GAGME,KAAmB,CACxBC,GACAC,MACoB;AACpB,QAAMC,IACLF,EAAM,QAAQ,SAAS,mBACnBA,EAAM,QAAQ,iBAAiB,IAAI,KAAA,EAAO,SAAS,IACpDA,EAAM,QAAQ,QAAQ,SAAS;AAEnC,SAAO;AAAA,IACN,OACCA,EAAM,KAAK,KAAA,EAAO,SAAS,KAC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MACA,kBAAAC;AAAA,MACA,yBAAAuB;AAAA,MACA,uBAAAC;AAAA,MACA,iBAAAvB;AAAA,MACA,kBAAAC;AAAA,MACA,mBAAAC;AAAA,IAAA;AAAA,IAED;AAAA,MACClB;AAAA,MACAwD;AAAA,MACAE;AAAA,MACAG;AAAA,MACAE;AAAA,MACAnC;AAAA,MACAY;AAAA,MACAR;AAAA,MACAI;AAAA,MACAS;AAAA,MACAyB;AAAA,MACAC;AAAA,MACAhD;AAAA,MACAC;AAAA,MACAyB;AAAA,MACAE;AAAA,MACAG;AAAA,MACAqB;AAAA,MACApE;AAAA,MACAC;AAAA,MACAC;AAAA,MACAC;AAAA,MACAE;AAAA,MACA4D;AAAA,MACA1D;AAAA,MACAC;AAAA,MACAuB;AAAA,MACAC;AAAA,MACAvB;AAAA,MACAC;AAAA,MACAC;AAAA,IAAA;AAAA,EACD;AAGD,4BACExB,GAAoB,UAApB,EAA6B,OAAOG,IACnC,UAAAsB,IACF;AAEF;"}
@@ -6,9 +6,9 @@ import { AgentTool, SubAgentRef } from '../AgentBuilder.model';
6
6
  * `instructions` string.
7
7
  *
8
8
  * Firebase stores `instructions` as PLAIN TEXT with inline reference tokens:
9
- * - `{{subagent:<agentId>}}` — hand-off to another agent
10
- * - `{{tool:<function_key>}}` — an action the agent can call
11
- * - `{{<variableName>}}` — a template variable
9
+ * - `{{subagent:<agentId>}}` — hand-off to another agent
10
+ * - `{{tool:<tool_id>}}` — an action the agent can call
11
+ * - `{{<variableName>}}` — a template variable
12
12
  *
13
13
  * In the editor those references are inserted via the `@` mention menu (which we
14
14
  * populate with BOTH tools and sub-agents). Mention nodes keep their `id` in the
@@ -18,8 +18,6 @@ import { AgentTool, SubAgentRef } from '../AgentBuilder.model';
18
18
  export interface MentionKindMeta {
19
19
  /** Distinguishes a tool reference from a sub-agent reference. */
20
20
  kind: 'tool' | 'subagent';
21
- /** For tools: the function_key used in the `{{tool:KEY}}` token. */
22
- functionKey?: string;
23
21
  /** Plain item name (no prefix) shown in the picker dropdown rows. */
24
22
  plainLabel?: string;
25
23
  /** For tools: the source bucket (manifest / shopify / …) the picker groups by. */
@@ -55,7 +53,7 @@ export declare const buildMentionHtml: (id: string, label: string, kind: 'tool'
55
53
  export declare const instructionsToEditorHtml: (text: string, mentionItems?: MentionItem[]) => string;
56
54
  /**
57
55
  * Convert a BikEditor document (from `ref.getJSON()`) into the firebase
58
- * instructions string, replacing mention nodes with `{{subagent:ID}}` /
59
- * `{{tool:KEY}}` tokens.
56
+ * instructions string, replacing mention nodes with `{{subagent:<id>}}` /
57
+ * `{{tool:<tool_id>}}` tokens.
60
58
  */
61
59
  export declare const editorDocToInstructions: (doc: Record<string, unknown> | null, tools: AgentTool[]) => string;
@@ -5,64 +5,67 @@ const d = {
5
5
  }, m = (t, e = "Manifest") => t ? d[t] ?? t : e, k = (t) => {
6
6
  const e = t ? String(t) : "";
7
7
  return e === "BIK" ? "BIK" : e === "BSP" ? "BSP" : "Manifest";
8
- }, y = (t, e, n = "Manifest") => [
8
+ }, S = (t, e, n = "Manifest") => [
9
9
  ...t.map(
10
- (i) => ({
11
- id: i.tool_id,
12
- label: `${m(i.source, n)} : ${i.display_name}`,
10
+ (a) => ({
11
+ id: a.tool_id,
12
+ label: `${m(a.source, n)} : ${a.display_name}`,
13
13
  meta: {
14
14
  kind: "tool",
15
- functionKey: i.function_key,
16
- plainLabel: i.display_name,
17
- source: i.source
15
+ plainLabel: a.display_name,
16
+ source: a.source
18
17
  }
19
18
  })
20
19
  ),
21
20
  ...e.map(
22
- (i) => ({
23
- id: i.id,
24
- label: `sub-agent: ${i.name}`,
25
- meta: { kind: "subagent", plainLabel: i.name }
21
+ (a) => ({
22
+ id: a.id,
23
+ label: `sub-agent: ${a.name}`,
24
+ meta: { kind: "subagent", plainLabel: a.name }
26
25
  })
27
26
  )
28
- ], a = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), s = (t) => a(t).replace(/"/g, "&quot;"), c = (t, e, n) => `<span data-type="mentionAgent" class="bik-mention bik-mention--agent" data-id="${s(t)}" data-label="${s(e)}" data-kind="${s(n)}">${a(e)}</span>`, $ = (t, e, n) => c(t, e, n), f = (t) => {
27
+ ], i = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), r = (t) => i(t).replace(/"/g, "&quot;"), c = (t, e, n) => `<span data-type="mentionAgent" class="bik-mention bik-mention--agent" data-id="${r(t)}" data-label="${r(e)}" data-kind="${r(n)}">${i(e)}</span>`, $ = (t, e, n) => c(t, e, n), g = (t) => {
29
28
  const e = /* @__PURE__ */ new Map();
30
29
  for (const n of t) {
31
- const i = n.meta;
32
- i?.kind === "tool" && i.functionKey ? e.set(`tool:${i.functionKey}`, n) : i?.kind === "subagent" && e.set(`subagent:${String(n.id)}`, n);
30
+ const a = n.meta;
31
+ a?.kind === "tool" ? e.set(`tool:${String(n.id)}`, n) : a?.kind === "subagent" && e.set(`subagent:${String(n.id)}`, n);
33
32
  }
34
33
  return e;
35
- }, l = /\{\{(tool:[^}]+|subagent:[^}]+)\}\}/g, g = (t, e) => {
36
- let n = "", i = 0;
34
+ }, l = /\{\{(tool:[^}]+|subagent:[^}]+)\}\}/g, b = (t, e) => {
35
+ let n = "", a = 0;
37
36
  l.lastIndex = 0;
38
37
  let o;
39
38
  for (; (o = l.exec(t)) !== null; ) {
40
- n += a(t.slice(i, o.index));
41
- const r = e.get(o[1]);
42
- if (r) {
43
- const p = r.meta.kind;
44
- n += c(String(r.id), r.label, p);
39
+ n += i(t.slice(a, o.index));
40
+ const s = e.get(o[1]);
41
+ if (s) {
42
+ const p = s.meta.kind;
43
+ n += c(String(s.id), s.label, p);
45
44
  } else
46
- n += a(o[0]);
47
- i = l.lastIndex;
45
+ n += i(o[0]);
46
+ a = l.lastIndex;
48
47
  }
49
- return n += a(t.slice(i)), n.replace(/\n/g, "<br>");
50
- }, S = (t, e = []) => {
48
+ return n += i(t.slice(a)), n.replace(/\n/g, "<br>");
49
+ }, T = (t, e = []) => {
51
50
  if (!t)
52
51
  return "";
53
- const n = f(e);
54
- return t.split(/\n{2,}/).map((i) => `<p>${g(i, n)}</p>`).join("");
55
- }, b = (t, e) => {
56
- const n = e[t];
57
- return n ? `{{tool:${n}}}` : `{{subagent:${t}}}`;
58
- }, u = (t, e) => {
52
+ const n = g(e);
53
+ return t.split(/\n{2,}/).map((a) => `<p>${b(a, n)}</p>`).join("");
54
+ }, f = (t, e, n) => (e ?? (n.has(t) ? "tool" : "subagent")) === "tool" ? `{{tool:${t}}}` : `{{subagent:${t}}}`, u = (t, e) => {
59
55
  switch (t.type) {
60
56
  case "text":
61
57
  return t.text ?? "";
62
58
  case "mentionAgent":
63
59
  case "mentionTeam": {
64
60
  const n = t.attrs?.id;
65
- return n == null ? "" : b(String(n), e);
61
+ if (n == null)
62
+ return "";
63
+ const a = t.attrs?.kind;
64
+ return f(
65
+ String(n),
66
+ a == null ? null : String(a),
67
+ e
68
+ );
66
69
  }
67
70
  case "variable":
68
71
  return `{{${String(t.attrs?.variableName ?? "")}}}`;
@@ -75,10 +78,10 @@ const d = {
75
78
  ` : n;
76
79
  }
77
80
  }
78
- }, T = (t, e) => {
81
+ }, y = (t, e) => {
79
82
  if (!t)
80
83
  return "";
81
- const n = e.reduce((i, o) => (i[o.tool_id] = o.function_key, i), {});
84
+ const n = new Set(e.map((a) => a.tool_id));
82
85
  return u(t, n).replace(
83
86
  /\n+$/,
84
87
  ""
@@ -87,10 +90,10 @@ const d = {
87
90
  export {
88
91
  d as TOOL_SOURCE_LABELS,
89
92
  k as appTypeLabel,
90
- y as buildAgentMentionItems,
93
+ S as buildAgentMentionItems,
91
94
  $ as buildMentionHtml,
92
- T as editorDocToInstructions,
93
- S as instructionsToEditorHtml,
95
+ y as editorDocToInstructions,
96
+ T as instructionsToEditorHtml,
94
97
  m as toolSourceLabel
95
98
  };
96
99
  //# sourceMappingURL=mentionSerialization.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mentionSerialization.js","sources":["../../../../../src/components/agent-builder/utils/mentionSerialization.ts"],"sourcesContent":["import type { ApplicationType } from '@bikdotai/bik-models/growth';\nimport { MentionItem } from '@src/editor';\nimport { AgentTool, SubAgentRef } from '../AgentBuilder.model';\n\n/**\n * Serialization helpers between the BikEditor document and the firebase\n * `instructions` string.\n *\n * Firebase stores `instructions` as PLAIN TEXT with inline reference tokens:\n * - `{{subagent:<agentId>}}` — hand-off to another agent\n * - `{{tool:<function_key>}}` — an action the agent can call\n * - `{{<variableName>}}` — a template variable\n *\n * In the editor those references are inserted via the `@` mention menu (which we\n * populate with BOTH tools and sub-agents). Mention nodes keep their `id` in the\n * ProseMirror doc JSON (the rendered HTML drops it), so we serialize from the doc\n * JSON — not from HTML.\n */\n\nexport interface MentionKindMeta {\n\t/** Distinguishes a tool reference from a sub-agent reference. */\n\tkind: 'tool' | 'subagent';\n\t/** For tools: the function_key used in the `{{tool:KEY}}` token. */\n\tfunctionKey?: string;\n\t/** Plain item name (no prefix) shown in the picker dropdown rows. */\n\tplainLabel?: string;\n\t/** For tools: the source bucket (manifest / shopify / …) the picker groups by. */\n\tsource?: string;\n}\n\n/** Display labels for the known tool sources (drives picker headers + chip prefix). */\nexport const TOOL_SOURCE_LABELS: Record<string, string> = {\n\tmanifest: 'Manifest',\n\tshopify: 'Shopify',\n\tintegration: 'Integration',\n};\n\n/** Human label for a tool source; falls back to the host-app label, then the raw key. */\nexport const toolSourceLabel = (\n\tsource: string | undefined,\n\tfallback = 'Manifest',\n): string => {\n\tif (!source) {\n\t\treturn fallback;\n\t}\n\treturn TOOL_SOURCE_LABELS[source] ?? source;\n};\n\n/** Human label for the host application, used as the tool-chip prefix. */\nexport const appTypeLabel = (applicationType?: ApplicationType): string => {\n\tconst key = applicationType ? String(applicationType) : '';\n\tif (key === 'BIK') {\n\t\treturn 'BIK';\n\t}\n\tif (key === 'BSP') {\n\t\treturn 'BSP';\n\t}\n\treturn 'Manifest';\n};\n\n/**\n * Build the combined `@` mention list from the available tools + sub-agents.\n *\n * The `label` is the CHIP text shown once inserted — tools read\n * `\"<App> : <tool name>\"` (e.g. \"Manifest : Look up order\"), sub-agents read\n * `\"sub-agent: <name>\"`. `meta.plainLabel` is the un-prefixed name for the\n * picker rows, and `meta.kind` drives the `{{tool}}` / `{{subagent}}` colour.\n */\nexport const buildAgentMentionItems = (\n\ttools: AgentTool[],\n\tsubAgents: SubAgentRef[],\n\tappLabel = 'Manifest',\n): MentionItem[] => [\n\t...tools.map(\n\t\t(t): MentionItem => ({\n\t\t\tid: t.tool_id,\n\t\t\tlabel: `${toolSourceLabel(t.source, appLabel)} : ${t.display_name}`,\n\t\t\tmeta: {\n\t\t\t\tkind: 'tool',\n\t\t\t\tfunctionKey: t.function_key,\n\t\t\t\tplainLabel: t.display_name,\n\t\t\t\tsource: t.source,\n\t\t\t},\n\t\t}),\n\t),\n\t...subAgents.map(\n\t\t(s): MentionItem => ({\n\t\t\tid: s.id,\n\t\t\tlabel: `sub-agent: ${s.name}`,\n\t\t\tmeta: { kind: 'subagent', plainLabel: s.name },\n\t\t}),\n\t),\n];\n\nconst escapeHtml = (raw: string): string =>\n\traw.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n\nconst escapeAttr = (raw: string): string =>\n\tescapeHtml(raw).replace(/\"/g, '&quot;');\n\n/**\n * The HTML for a single mention chip. Must round-trip through the TipTap mention\n * extension's `parseHTML` (`span[data-type=\"mentionAgent\"]`, reading\n * `data-id`/`data-label`/`data-kind`) — see MentionExtension.ts. `normalizeHtml`\n * is taught to keep `data-type=\"mention…\"` spans so this survives to the parser.\n */\nconst mentionSpanHtml = (id: string, label: string, kind: string): string =>\n\t`<span data-type=\"mentionAgent\" class=\"bik-mention bik-mention--agent\"` +\n\t` data-id=\"${escapeAttr(id)}\" data-label=\"${escapeAttr(label)}\"` +\n\t` data-kind=\"${escapeAttr(kind)}\">${escapeHtml(label)}</span>`;\n\n/**\n * Public: HTML for one mention chip, for inserting at the cursor (e.g. when a\n * tool / sub-agent is added from the Step-3 side panel). Round-trips through the\n * same parser path as the rehydrated chips.\n */\nexport const buildMentionHtml = (\n\tid: string,\n\tlabel: string,\n\tkind: 'tool' | 'subagent',\n): string => mentionSpanHtml(id, label, kind);\n\n/** `{{tool:KEY}}` / `{{subagent:ID}}` → the mention item that produced them. */\nconst buildTokenLookup = (\n\tmentionItems: MentionItem[],\n): Map<string, MentionItem> => {\n\tconst byToken = new Map<string, MentionItem>();\n\tfor (const item of mentionItems) {\n\t\tconst meta = item.meta as unknown as MentionKindMeta | undefined;\n\t\tif (meta?.kind === 'tool' && meta.functionKey) {\n\t\t\tbyToken.set(`tool:${meta.functionKey}`, item);\n\t\t} else if (meta?.kind === 'subagent') {\n\t\t\tbyToken.set(`subagent:${String(item.id)}`, item);\n\t\t}\n\t}\n\treturn byToken;\n};\n\n// Matches the reference tokens we render as chips. Other `{{var}}` tokens fall\n// through untouched (left as literal text for the variable decoration).\nconst REFERENCE_TOKEN = /\\{\\{(tool:[^}]+|subagent:[^}]+)\\}\\}/g;\n\n/** Escape plain text, swapping recognised reference tokens for mention spans. */\nconst inlineToHtml = (\n\tsegment: string,\n\tbyToken: Map<string, MentionItem>,\n): string => {\n\tlet out = '';\n\tlet lastIndex = 0;\n\tREFERENCE_TOKEN.lastIndex = 0;\n\tlet match: RegExpExecArray | null;\n\twhile ((match = REFERENCE_TOKEN.exec(segment)) !== null) {\n\t\tout += escapeHtml(segment.slice(lastIndex, match.index));\n\t\tconst item = byToken.get(match[1]);\n\t\tif (item) {\n\t\t\tconst kind = (item.meta as unknown as MentionKindMeta).kind;\n\t\t\tout += mentionSpanHtml(String(item.id), item.label, kind);\n\t\t} else {\n\t\t\t// Tool/sub-agent no longer in the available list → keep the raw token.\n\t\t\tout += escapeHtml(match[0]);\n\t\t}\n\t\tlastIndex = REFERENCE_TOKEN.lastIndex;\n\t}\n\tout += escapeHtml(segment.slice(lastIndex));\n\treturn out.replace(/\\n/g, '<br>');\n};\n\n/**\n * Convert the stored instructions string into HTML for `BikEditor.initialContent`.\n * `{{tool:KEY}}` / `{{subagent:ID}}` tokens are rehydrated into mention chips\n * (resolved via `mentionItems`); any other `{{…}}` token is left as literal text\n * for the editor's variable decoration. Newlines become paragraph / line breaks.\n */\nexport const instructionsToEditorHtml = (\n\ttext: string,\n\tmentionItems: MentionItem[] = [],\n): string => {\n\tif (!text) {\n\t\treturn '';\n\t}\n\tconst byToken = buildTokenLookup(mentionItems);\n\treturn text\n\t\t.split(/\\n{2,}/)\n\t\t.map((para) => `<p>${inlineToHtml(para, byToken)}</p>`)\n\t\t.join('');\n};\n\ninterface ProseMirrorNode {\n\ttype: string;\n\ttext?: string;\n\tattrs?: Record<string, unknown>;\n\tcontent?: ProseMirrorNode[];\n}\n\n/** Map of mention node id → token, derived from the available tools. */\nconst resolveMentionToken = (\n\tid: string,\n\ttoolKeyById: Record<string, string>,\n): string => {\n\tconst functionKey = toolKeyById[id];\n\tif (functionKey) {\n\t\treturn `{{tool:${functionKey}}}`;\n\t}\n\treturn `{{subagent:${id}}}`;\n};\n\nconst nodeToText = (\n\tnode: ProseMirrorNode,\n\ttoolKeyById: Record<string, string>,\n): string => {\n\tswitch (node.type) {\n\t\tcase 'text':\n\t\t\treturn node.text ?? '';\n\t\tcase 'mentionAgent':\n\t\tcase 'mentionTeam': {\n\t\t\tconst id = node.attrs?.['id'];\n\t\t\treturn id == null ? '' : resolveMentionToken(String(id), toolKeyById);\n\t\t}\n\t\tcase 'variable':\n\t\t\treturn `{{${String(node.attrs?.['variableName'] ?? '')}}}`;\n\t\tcase 'hardBreak':\n\t\t\treturn '\\n';\n\t\tdefault: {\n\t\t\tconst inner = (node.content ?? [])\n\t\t\t\t.map((child) => nodeToText(child, toolKeyById))\n\t\t\t\t.join('');\n\t\t\t// Block nodes terminate with a newline so paragraphs stay separated.\n\t\t\tconst BLOCK_NODES = ['paragraph', 'heading', 'listItem', 'blockquote'];\n\t\t\treturn BLOCK_NODES.includes(node.type) ? `${inner}\\n` : inner;\n\t\t}\n\t}\n};\n\n/**\n * Convert a BikEditor document (from `ref.getJSON()`) into the firebase\n * instructions string, replacing mention nodes with `{{subagent:ID}}` /\n * `{{tool:KEY}}` tokens.\n */\nexport const editorDocToInstructions = (\n\tdoc: Record<string, unknown> | null,\n\ttools: AgentTool[],\n): string => {\n\tif (!doc) {\n\t\treturn '';\n\t}\n\tconst toolKeyById = tools.reduce<Record<string, string>>((acc, t) => {\n\t\tacc[t.tool_id] = t.function_key;\n\t\treturn acc;\n\t}, {});\n\treturn nodeToText(doc as unknown as ProseMirrorNode, toolKeyById).replace(\n\t\t/\\n+$/,\n\t\t'',\n\t);\n};\n"],"names":["TOOL_SOURCE_LABELS","toolSourceLabel","source","fallback","appTypeLabel","applicationType","key","buildAgentMentionItems","tools","subAgents","appLabel","t","s","escapeHtml","raw","escapeAttr","mentionSpanHtml","id","label","kind","buildMentionHtml","buildTokenLookup","mentionItems","byToken","item","meta","REFERENCE_TOKEN","inlineToHtml","segment","out","lastIndex","match","instructionsToEditorHtml","text","para","resolveMentionToken","toolKeyById","functionKey","nodeToText","node","inner","child","editorDocToInstructions","doc","acc"],"mappings":"AA+BO,MAAMA,IAA6C;AAAA,EACzD,UAAU;AAAA,EACV,SAAS;AAAA,EACT,aAAa;AACd,GAGaC,IAAkB,CAC9BC,GACAC,IAAW,eAEND,IAGEF,EAAmBE,CAAM,KAAKA,IAF7BC,GAMIC,IAAe,CAACC,MAA8C;AAC1E,QAAMC,IAAMD,IAAkB,OAAOA,CAAe,IAAI;AACxD,SAAIC,MAAQ,QACJ,QAEJA,MAAQ,QACJ,QAED;AACR,GAUaC,IAAyB,CACrCC,GACAC,GACAC,IAAW,eACQ;AAAA,EACnB,GAAGF,EAAM;AAAA,IACR,CAACG,OAAoB;AAAA,MACpB,IAAIA,EAAE;AAAA,MACN,OAAO,GAAGV,EAAgBU,EAAE,QAAQD,CAAQ,CAAC,MAAMC,EAAE,YAAY;AAAA,MACjE,MAAM;AAA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,CAAW,CAAC,EAC7C,KAAK,EAAE;AAGT,aADoB,CAAC,aAAa,WAAW,YAAY,YAAY,EAClD,SAASG,EAAK,IAAI,IAAI,GAAGC,CAAK;AAAA,IAAOA;AAAA,IACzD;AAAA,EAAA;AAEF,GAOaE,IAA0B,CACtCC,GACAnC,MACY;AACZ,MAAI,CAACmC;AACJ,WAAO;AAER,QAAMP,IAAc5B,EAAM,OAA+B,CAACoC,GAAKjC,OAC9DiC,EAAIjC,EAAE,OAAO,IAAIA,EAAE,cACZiC,IACL,CAAA,CAAE;AACL,SAAON,EAAWK,GAAmCP,CAAW,EAAE;AAAA,IACjE;AAAA,IACA;AAAA,EAAA;AAEF;"}
1
+ {"version":3,"file":"mentionSerialization.js","sources":["../../../../../src/components/agent-builder/utils/mentionSerialization.ts"],"sourcesContent":["import type { ApplicationType } from '@bikdotai/bik-models/growth';\nimport { MentionItem } from '@src/editor';\nimport { AgentTool, SubAgentRef } from '../AgentBuilder.model';\n\n/**\n * Serialization helpers between the BikEditor document and the firebase\n * `instructions` string.\n *\n * Firebase stores `instructions` as PLAIN TEXT with inline reference tokens:\n * - `{{subagent:<agentId>}}` — hand-off to another agent\n * - `{{tool:<tool_id>}}` — an action the agent can call\n * - `{{<variableName>}}` — a template variable\n *\n * In the editor those references are inserted via the `@` mention menu (which we\n * populate with BOTH tools and sub-agents). Mention nodes keep their `id` in the\n * ProseMirror doc JSON (the rendered HTML drops it), so we serialize from the doc\n * JSON — not from HTML.\n */\n\nexport interface MentionKindMeta {\n\t/** Distinguishes a tool reference from a sub-agent reference. */\n\tkind: 'tool' | 'subagent';\n\t/** Plain item name (no prefix) shown in the picker dropdown rows. */\n\tplainLabel?: string;\n\t/** For tools: the source bucket (manifest / shopify / …) the picker groups by. */\n\tsource?: string;\n}\n\n/** Display labels for the known tool sources (drives picker headers + chip prefix). */\nexport const TOOL_SOURCE_LABELS: Record<string, string> = {\n\tmanifest: 'Manifest',\n\tshopify: 'Shopify',\n\tintegration: 'Integration',\n};\n\n/** Human label for a tool source; falls back to the host-app label, then the raw key. */\nexport const toolSourceLabel = (\n\tsource: string | undefined,\n\tfallback = 'Manifest',\n): string => {\n\tif (!source) {\n\t\treturn fallback;\n\t}\n\treturn TOOL_SOURCE_LABELS[source] ?? source;\n};\n\n/** Human label for the host application, used as the tool-chip prefix. */\nexport const appTypeLabel = (applicationType?: ApplicationType): string => {\n\tconst key = applicationType ? String(applicationType) : '';\n\tif (key === 'BIK') {\n\t\treturn 'BIK';\n\t}\n\tif (key === 'BSP') {\n\t\treturn 'BSP';\n\t}\n\treturn 'Manifest';\n};\n\n/**\n * Build the combined `@` mention list from the available tools + sub-agents.\n *\n * The `label` is the CHIP text shown once inserted — tools read\n * `\"<App> : <tool name>\"` (e.g. \"Manifest : Look up order\"), sub-agents read\n * `\"sub-agent: <name>\"`. `meta.plainLabel` is the un-prefixed name for the\n * picker rows, and `meta.kind` drives the `{{tool}}` / `{{subagent}}` colour.\n */\nexport const buildAgentMentionItems = (\n\ttools: AgentTool[],\n\tsubAgents: SubAgentRef[],\n\tappLabel = 'Manifest',\n): MentionItem[] => [\n\t...tools.map(\n\t\t(t): MentionItem => ({\n\t\t\tid: t.tool_id,\n\t\t\tlabel: `${toolSourceLabel(t.source, appLabel)} : ${t.display_name}`,\n\t\t\tmeta: {\n\t\t\t\tkind: 'tool',\n\t\t\t\tplainLabel: t.display_name,\n\t\t\t\tsource: t.source,\n\t\t\t},\n\t\t}),\n\t),\n\t...subAgents.map(\n\t\t(s): MentionItem => ({\n\t\t\tid: s.id,\n\t\t\tlabel: `sub-agent: ${s.name}`,\n\t\t\tmeta: { kind: 'subagent', plainLabel: s.name },\n\t\t}),\n\t),\n];\n\nconst escapeHtml = (raw: string): string =>\n\traw.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n\nconst escapeAttr = (raw: string): string =>\n\tescapeHtml(raw).replace(/\"/g, '&quot;');\n\n/**\n * The HTML for a single mention chip. Must round-trip through the TipTap mention\n * extension's `parseHTML` (`span[data-type=\"mentionAgent\"]`, reading\n * `data-id`/`data-label`/`data-kind`) — see MentionExtension.ts. `normalizeHtml`\n * is taught to keep `data-type=\"mention…\"` spans so this survives to the parser.\n */\nconst mentionSpanHtml = (id: string, label: string, kind: string): string =>\n\t`<span data-type=\"mentionAgent\" class=\"bik-mention bik-mention--agent\"` +\n\t` data-id=\"${escapeAttr(id)}\" data-label=\"${escapeAttr(label)}\"` +\n\t` data-kind=\"${escapeAttr(kind)}\">${escapeHtml(label)}</span>`;\n\n/**\n * Public: HTML for one mention chip, for inserting at the cursor (e.g. when a\n * tool / sub-agent is added from the Step-3 side panel). Round-trips through the\n * same parser path as the rehydrated chips.\n */\nexport const buildMentionHtml = (\n\tid: string,\n\tlabel: string,\n\tkind: 'tool' | 'subagent',\n): string => mentionSpanHtml(id, label, kind);\n\n/** `{{tool:<id>}}` / `{{subagent:<id>}}` → the mention item that produced them. */\nconst buildTokenLookup = (\n\tmentionItems: MentionItem[],\n): Map<string, MentionItem> => {\n\tconst byToken = new Map<string, MentionItem>();\n\tfor (const item of mentionItems) {\n\t\tconst meta = item.meta as unknown as MentionKindMeta | undefined;\n\t\t// Both tools and sub-agents are keyed by their id (a tool's id is its tool_id).\n\t\tif (meta?.kind === 'tool') {\n\t\t\tbyToken.set(`tool:${String(item.id)}`, item);\n\t\t} else if (meta?.kind === 'subagent') {\n\t\t\tbyToken.set(`subagent:${String(item.id)}`, item);\n\t\t}\n\t}\n\treturn byToken;\n};\n\n// Matches the reference tokens we render as chips. Other `{{var}}` tokens fall\n// through untouched (left as literal text for the variable decoration).\nconst REFERENCE_TOKEN = /\\{\\{(tool:[^}]+|subagent:[^}]+)\\}\\}/g;\n\n/** Escape plain text, swapping recognised reference tokens for mention spans. */\nconst inlineToHtml = (\n\tsegment: string,\n\tbyToken: Map<string, MentionItem>,\n): string => {\n\tlet out = '';\n\tlet lastIndex = 0;\n\tREFERENCE_TOKEN.lastIndex = 0;\n\tlet match: RegExpExecArray | null;\n\twhile ((match = REFERENCE_TOKEN.exec(segment)) !== null) {\n\t\tout += escapeHtml(segment.slice(lastIndex, match.index));\n\t\tconst item = byToken.get(match[1]);\n\t\tif (item) {\n\t\t\tconst kind = (item.meta as unknown as MentionKindMeta).kind;\n\t\t\tout += mentionSpanHtml(String(item.id), item.label, kind);\n\t\t} else {\n\t\t\t// Tool/sub-agent no longer in the available list → keep the raw token.\n\t\t\tout += escapeHtml(match[0]);\n\t\t}\n\t\tlastIndex = REFERENCE_TOKEN.lastIndex;\n\t}\n\tout += escapeHtml(segment.slice(lastIndex));\n\treturn out.replace(/\\n/g, '<br>');\n};\n\n/**\n * Convert the stored instructions string into HTML for `BikEditor.initialContent`.\n * `{{tool:KEY}}` / `{{subagent:ID}}` tokens are rehydrated into mention chips\n * (resolved via `mentionItems`); any other `{{…}}` token is left as literal text\n * for the editor's variable decoration. Newlines become paragraph / line breaks.\n */\nexport const instructionsToEditorHtml = (\n\ttext: string,\n\tmentionItems: MentionItem[] = [],\n): string => {\n\tif (!text) {\n\t\treturn '';\n\t}\n\tconst byToken = buildTokenLookup(mentionItems);\n\treturn text\n\t\t.split(/\\n{2,}/)\n\t\t.map((para) => `<p>${inlineToHtml(para, byToken)}</p>`)\n\t\t.join('');\n};\n\ninterface ProseMirrorNode {\n\ttype: string;\n\ttext?: string;\n\tattrs?: Record<string, unknown>;\n\tcontent?: ProseMirrorNode[];\n}\n\n/**\n * The token for a mention node. Both tools and sub-agents store their id in the\n * node, so the token value is just that id — the kind only picks the prefix. The\n * node's `kind` attr is authoritative; `toolIds` is a fallback for older content\n * saved before the kind attr existed.\n */\nconst resolveMentionToken = (\n\tid: string,\n\tkind: string | null,\n\ttoolIds: Set<string>,\n): string => {\n\tconst resolved = kind ?? (toolIds.has(id) ? 'tool' : 'subagent');\n\treturn resolved === 'tool' ? `{{tool:${id}}}` : `{{subagent:${id}}}`;\n};\n\nconst nodeToText = (node: ProseMirrorNode, toolIds: Set<string>): string => {\n\tswitch (node.type) {\n\t\tcase 'text':\n\t\t\treturn node.text ?? '';\n\t\tcase 'mentionAgent':\n\t\tcase 'mentionTeam': {\n\t\t\tconst id = node.attrs?.['id'];\n\t\t\tif (id == null) {\n\t\t\t\treturn '';\n\t\t\t}\n\t\t\tconst kind = node.attrs?.['kind'];\n\t\t\treturn resolveMentionToken(\n\t\t\t\tString(id),\n\t\t\t\tkind == null ? null : String(kind),\n\t\t\t\ttoolIds,\n\t\t\t);\n\t\t}\n\t\tcase 'variable':\n\t\t\treturn `{{${String(node.attrs?.['variableName'] ?? '')}}}`;\n\t\tcase 'hardBreak':\n\t\t\treturn '\\n';\n\t\tdefault: {\n\t\t\tconst inner = (node.content ?? [])\n\t\t\t\t.map((child) => nodeToText(child, toolIds))\n\t\t\t\t.join('');\n\t\t\t// Block nodes terminate with a newline so paragraphs stay separated.\n\t\t\tconst BLOCK_NODES = ['paragraph', 'heading', 'listItem', 'blockquote'];\n\t\t\treturn BLOCK_NODES.includes(node.type) ? `${inner}\\n` : inner;\n\t\t}\n\t}\n};\n\n/**\n * Convert a BikEditor document (from `ref.getJSON()`) into the firebase\n * instructions string, replacing mention nodes with `{{subagent:<id>}}` /\n * `{{tool:<tool_id>}}` tokens.\n */\nexport const editorDocToInstructions = (\n\tdoc: Record<string, unknown> | null,\n\ttools: AgentTool[],\n): string => {\n\tif (!doc) {\n\t\treturn '';\n\t}\n\tconst toolIds = new Set(tools.map((t) => t.tool_id));\n\treturn nodeToText(doc as unknown as ProseMirrorNode, toolIds).replace(\n\t\t/\\n+$/,\n\t\t'',\n\t);\n};\n"],"names":["TOOL_SOURCE_LABELS","toolSourceLabel","source","fallback","appTypeLabel","applicationType","key","buildAgentMentionItems","tools","subAgents","appLabel","t","s","escapeHtml","raw","escapeAttr","mentionSpanHtml","id","label","kind","buildMentionHtml","buildTokenLookup","mentionItems","byToken","item","meta","REFERENCE_TOKEN","inlineToHtml","segment","out","lastIndex","match","instructionsToEditorHtml","text","para","resolveMentionToken","toolIds","nod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