@charisol/plexo-sdk 1.4.41 → 1.4.42

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.
@@ -22,6 +22,10 @@ export interface AIActionResponse {
22
22
  summary: string;
23
23
  result: ElementJSON | TemplateJSON;
24
24
  }
25
+ /** Thrown when the account has run out of AI credits for SOL (HTTP 402). */
26
+ export declare class AiCreditsExhaustedError extends Error {
27
+ }
28
+ export declare function setAiCreditsExhaustedHandler(handler: (() => void) | null): void;
25
29
  /**
26
30
  * All provider-specific logic (model resolution, structured-output handling, JSON
27
31
  * validation) lives server-side now — this is a thin HTTP client. The raw provider key
@@ -166,6 +166,11 @@ export interface PlexoBuilderProps {
166
166
  * this id to know whose account to check/charge. Ignored for System AI/BYOK keys.
167
167
  */
168
168
  externalUserId?: string;
169
+ /**
170
+ * Called when an AI action (SOL) is refused because the account is out of AI credits —
171
+ * lets the host show its own top-up right away. The action still reports the error inline.
172
+ */
173
+ onAiCreditsExhausted?: () => void;
169
174
  /**
170
175
  * Subscription plan is resolved server-side from the apiKey.
171
176
  * External consumers should NOT pass this prop — it will be ignored.
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import type { PlexoNodeType } from '../store/types';
2
3
  export interface AskSolMessage {
3
4
  id: string;
4
5
  from: 'user' | 'sol';
@@ -10,10 +11,15 @@ export interface AskSolMessage {
10
11
  * a Back control that returns to the Content tab. History is host-persistable: pass
11
12
  * `history`/`onMessage` (see V2CanvasProps) and a real backend (plexo-web) can save and
12
13
  * restore the conversation per template; omit both and it's just in-memory for the
13
- * session. Replies are honestly canned/heuristic (see aiTextTransforms.ts) since no
14
- * real model is connected in this build.
14
+ * session. With `onAsk` (see V2CanvasProps.onAskSol) replies come from the host's real SOL;
15
+ * without it they're honest canned pointers to the right control.
15
16
  */
17
+ export type AskSolContext = {
18
+ nodeId?: string;
19
+ nodeType?: PlexoNodeType;
20
+ };
16
21
  export declare const AskSolPanel: React.FC<{
17
22
  history?: AskSolMessage[];
18
23
  onMessage?: (message: AskSolMessage) => void;
24
+ onAsk?: (question: string, context: AskSolContext) => Promise<string>;
19
25
  }>;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { type SaveState } from './ContextualToolbar';
3
- import type { AskSolMessage } from './AskSolPanel';
3
+ import type { AskSolContext, AskSolMessage } from './AskSolPanel';
4
4
  /**
5
5
  * Everything a host app (plexo-web in production, PlaygroundHost.tsx in dev) can hand
6
6
  * in rather than the SDK hardcoding or faking it. Persistence, uploads, and Ask SOL
@@ -39,6 +39,9 @@ export interface V2CanvasProps {
39
39
  * job. Omit both to get a normal in-memory-only conversation. */
40
40
  askSolHistory?: AskSolMessage[];
41
41
  onAskSolMessage?: (message: AskSolMessage) => void;
42
+ /** Answers Ask SOL questions with the host's real SOL (the question, plus the selected
43
+ * element if the question is scoped to it). Omitted, Ask SOL gives canned pointers. */
44
+ onAskSol?: (question: string, context: AskSolContext) => Promise<string>;
42
45
  /** Left/right header slots — named to match V1's own `headerLeftContent`/
43
46
  * `headerRightContent` props (PlexoBuilder.tsx) so a host already integrating V1
44
47
  * can carry the same content over with no naming translation. The SDK renders each
@@ -8,5 +8,6 @@ export { V2Canvas } from './components/V2Canvas';
8
8
  export { useCanvasStore } from './store/createCanvasStore';
9
9
  export { useBrandStore } from './store/createBrandStore';
10
10
  export type { V2CanvasProps } from './components/V2Canvas';
11
+ export type { AskSolContext, AskSolMessage } from './components/AskSolPanel';
11
12
  export type { PlexoNode, PlexoNodeType, CanvasState, CanvasStore, SectionNode, TextNode, ImageNode, ButtonNode, ContainerNode, } from './store/types';
12
13
  export { compilePageToReact, componentNameFor, DESIGN_WIDTH, type CompileOptions, type TextStyleSlots } from "./compile/toReact";
package/dist/v2.js CHANGED
@@ -3655,31 +3655,57 @@ var hr = {
3655
3655
  background: B.bg,
3656
3656
  color: B.text,
3657
3657
  cursor: "pointer"
3658
- }, _r = ({ history: e, onMessage: t }) => {
3659
- let n = Yn(), { dark: r } = ur(), i = R((e) => e.selectedIds), a = R((e) => i.length === 1 ? e.nodes[i[0]]?.type : void 0), [o, s] = N(!0), [c, l] = N(e ?? []), [u, d] = N(""), f = o ? a : void 0, p = dr[f ?? "none"], m = (e) => {
3658
+ }, _r = ({ history: e, onMessage: t, onAsk: n }) => {
3659
+ let r = Yn(), { dark: i } = ur(), a = R((e) => e.selectedIds), o = R((e) => a.length === 1 ? e.nodes[a[0]]?.type : void 0), [s, c] = N(!0), [l, u] = N(e ?? []), [d, f] = N(""), p = s ? o : void 0, m = dr[p ?? "none"], h = (e) => {
3660
3660
  if (!e.trim()) return;
3661
- let n = {
3661
+ let r = {
3662
3662
  id: `u-${Date.now()}`,
3663
3663
  from: "user",
3664
3664
  text: e,
3665
3665
  timestamp: Date.now()
3666
- }, r = {
3667
- id: `s-${Date.now() + 1}`,
3668
- from: "sol",
3669
- text: pr(e, f),
3670
- timestamp: Date.now() + 1
3671
3666
  };
3672
- l((e) => [
3667
+ if (f(""), t?.(r), !n) {
3668
+ let n = {
3669
+ id: `s-${Date.now() + 1}`,
3670
+ from: "sol",
3671
+ text: pr(e, p),
3672
+ timestamp: Date.now() + 1
3673
+ };
3674
+ u((e) => [
3675
+ ...e,
3676
+ r,
3677
+ n
3678
+ ]), t?.(n);
3679
+ return;
3680
+ }
3681
+ let i = `s-${Date.now() + 1}`;
3682
+ u((e) => [
3673
3683
  ...e,
3674
- n,
3675
- r
3676
- ]), t?.(n), t?.(r), d("");
3684
+ r,
3685
+ {
3686
+ id: i,
3687
+ from: "sol",
3688
+ text: "Thinking…",
3689
+ timestamp: Date.now() + 1
3690
+ }
3691
+ ]), n(e, p && a.length === 1 ? {
3692
+ nodeId: a[0],
3693
+ nodeType: p
3694
+ } : {}).then((e) => e, () => "SOL couldn't answer just now. Please try again.").then((e) => {
3695
+ let n = {
3696
+ id: i,
3697
+ from: "sol",
3698
+ text: e,
3699
+ timestamp: Date.now()
3700
+ };
3701
+ u((e) => e.map((e) => e.id === i ? n : e)), t?.(n);
3702
+ });
3677
3703
  };
3678
3704
  return /* @__PURE__ */ I("div", {
3679
3705
  style: {
3680
3706
  width: "100%",
3681
3707
  height: "100%",
3682
- background: mr(r),
3708
+ background: mr(i),
3683
3709
  display: "flex",
3684
3710
  flexDirection: "column",
3685
3711
  position: "relative",
@@ -3694,7 +3720,7 @@ var hr = {
3694
3720
  height: 200,
3695
3721
  borderRadius: "50%",
3696
3722
  background: B.accent,
3697
- opacity: r ? .22 : .14,
3723
+ opacity: i ? .22 : .14,
3698
3724
  filter: "blur(50px)",
3699
3725
  pointerEvents: "none"
3700
3726
  } }),
@@ -3706,7 +3732,7 @@ var hr = {
3706
3732
  height: 180,
3707
3733
  borderRadius: "50%",
3708
3734
  background: "#c9f26c",
3709
- opacity: r ? .12 : .18,
3735
+ opacity: i ? .12 : .18,
3710
3736
  filter: "blur(55px)",
3711
3737
  pointerEvents: "none"
3712
3738
  } }),
@@ -3722,7 +3748,7 @@ var hr = {
3722
3748
  },
3723
3749
  children: [/* @__PURE__ */ I("button", {
3724
3750
  type: "button",
3725
- onClick: () => n.openTab("content"),
3751
+ onClick: () => r.openTab("content"),
3726
3752
  style: {
3727
3753
  display: "flex",
3728
3754
  alignItems: "center",
@@ -3757,7 +3783,7 @@ var hr = {
3757
3783
  display: "flex",
3758
3784
  flexDirection: "column"
3759
3785
  },
3760
- children: c.length === 0 ? /* @__PURE__ */ I("div", {
3786
+ children: l.length === 0 ? /* @__PURE__ */ I("div", {
3761
3787
  style: {
3762
3788
  display: "flex",
3763
3789
  flexDirection: "column",
@@ -3808,7 +3834,7 @@ var hr = {
3808
3834
  },
3809
3835
  children: fr.map(({ icon: e, label: t, prompt: n }) => /* @__PURE__ */ I("button", {
3810
3836
  type: "button",
3811
- onClick: () => m(n),
3837
+ onClick: () => h(n),
3812
3838
  style: hr,
3813
3839
  children: [
3814
3840
  /* @__PURE__ */ F(e, {
@@ -3828,7 +3854,7 @@ var hr = {
3828
3854
  gap: V.sm,
3829
3855
  padding: `${V.md}px 0`
3830
3856
  },
3831
- children: [c.map((e) => /* @__PURE__ */ F("div", {
3857
+ children: [l.map((e) => /* @__PURE__ */ F("div", {
3832
3858
  style: {
3833
3859
  alignSelf: e.from === "user" ? "flex-end" : "flex-start",
3834
3860
  maxWidth: "85%",
@@ -3841,9 +3867,9 @@ var hr = {
3841
3867
  boxShadow: e.from === "sol" ? B.shadow : void 0
3842
3868
  },
3843
3869
  children: e.text
3844
- }, e.id)), p.map((e) => /* @__PURE__ */ F("button", {
3870
+ }, e.id)), m.map((e) => /* @__PURE__ */ F("button", {
3845
3871
  type: "button",
3846
- onClick: () => m(e),
3872
+ onClick: () => h(e),
3847
3873
  style: gr,
3848
3874
  children: e
3849
3875
  }, e))]
@@ -3864,12 +3890,12 @@ var hr = {
3864
3890
  padding: V.sm
3865
3891
  },
3866
3892
  children: [
3867
- a && /* @__PURE__ */ F("div", {
3893
+ o && /* @__PURE__ */ F("div", {
3868
3894
  style: {
3869
3895
  display: "flex",
3870
3896
  marginBottom: V.sm
3871
3897
  },
3872
- children: o ? /* @__PURE__ */ I("span", {
3898
+ children: s ? /* @__PURE__ */ I("span", {
3873
3899
  style: {
3874
3900
  display: "flex",
3875
3901
  alignItems: "center",
@@ -3881,14 +3907,14 @@ var hr = {
3881
3907
  borderRadius: H.pill,
3882
3908
  padding: `${V.xxs}px ${V.sm}px`
3883
3909
  },
3884
- children: [a, /* @__PURE__ */ F(Je, {
3910
+ children: [o, /* @__PURE__ */ F(Je, {
3885
3911
  size: 11,
3886
3912
  style: { cursor: "pointer" },
3887
- onClick: () => s(!1)
3913
+ onClick: () => c(!1)
3888
3914
  })]
3889
3915
  }) : /* @__PURE__ */ I("button", {
3890
3916
  type: "button",
3891
- onClick: () => s(!0),
3917
+ onClick: () => c(!0),
3892
3918
  style: {
3893
3919
  fontSize: U.size.xs,
3894
3920
  fontWeight: U.weight.semibold,
@@ -3899,13 +3925,13 @@ var hr = {
3899
3925
  padding: `${V.xxs}px ${V.sm}px`,
3900
3926
  cursor: "pointer"
3901
3927
  },
3902
- children: ["+ Scope to ", a]
3928
+ children: ["+ Scope to ", o]
3903
3929
  })
3904
3930
  }),
3905
3931
  /* @__PURE__ */ F("input", {
3906
- value: u,
3907
- onChange: (e) => d(e.target.value),
3908
- onKeyDown: (e) => e.key === "Enter" && m(u),
3932
+ value: d,
3933
+ onChange: (e) => f(e.target.value),
3934
+ onKeyDown: (e) => e.key === "Enter" && h(d),
3909
3935
  placeholder: "I can design, add and regenerate",
3910
3936
  style: {
3911
3937
  width: "100%",
@@ -3966,16 +3992,16 @@ var hr = {
3966
3992
  }), /* @__PURE__ */ F("button", {
3967
3993
  type: "button",
3968
3994
  title: "Send",
3969
- onClick: () => m(u),
3970
- disabled: !u.trim(),
3995
+ onClick: () => h(d),
3996
+ disabled: !d.trim(),
3971
3997
  style: {
3972
3998
  width: 28,
3973
3999
  height: 28,
3974
4000
  border: "none",
3975
4001
  borderRadius: H.pill,
3976
- background: u.trim() ? B.accent : B.bgMuted,
3977
- color: u.trim() ? "#ffffff" : B.textFaint,
3978
- cursor: u.trim() ? "pointer" : "default",
4002
+ background: d.trim() ? B.accent : B.bgMuted,
4003
+ color: d.trim() ? "#ffffff" : B.textFaint,
4004
+ cursor: d.trim() ? "pointer" : "default",
3979
4005
  display: "flex",
3980
4006
  alignItems: "center",
3981
4007
  justifyContent: "center"
@@ -4028,15 +4054,15 @@ var hr = {
4028
4054
  label: "Brand",
4029
4055
  icon: S
4030
4056
  }
4031
- ], yr = ({ onUploadImage: e, askSolHistory: t, onAskSolMessage: n, stockImageProviders: r, onSearchStockImages: i }) => {
4032
- let a = Yn();
4057
+ ], yr = ({ onUploadImage: e, askSolHistory: t, onAskSolMessage: n, onAskSol: r, stockImageProviders: i, onSearchStockImages: a }) => {
4058
+ let o = Yn();
4033
4059
  return /* @__PURE__ */ I("aside", {
4034
4060
  style: {
4035
4061
  display: "flex",
4036
4062
  height: "100%",
4037
4063
  flexShrink: 0
4038
4064
  },
4039
- children: [a.activeTab && /* @__PURE__ */ I("div", {
4065
+ children: [o.activeTab && /* @__PURE__ */ I("div", {
4040
4066
  style: {
4041
4067
  width: 360,
4042
4068
  flexShrink: 0,
@@ -4045,25 +4071,26 @@ var hr = {
4045
4071
  overflow: "hidden"
4046
4072
  },
4047
4073
  children: [
4048
- a.activeTab === "content" && /* @__PURE__ */ F(tr, {}),
4049
- a.activeTab === "sol" && /* @__PURE__ */ F(_r, {
4074
+ o.activeTab === "content" && /* @__PURE__ */ F(tr, {}),
4075
+ o.activeTab === "sol" && /* @__PURE__ */ F(_r, {
4050
4076
  history: t,
4051
- onMessage: n
4077
+ onMessage: n,
4078
+ onAsk: r
4052
4079
  }),
4053
- a.activeTab === "images" && /* @__PURE__ */ F(sr, {
4080
+ o.activeTab === "images" && /* @__PURE__ */ F(sr, {
4054
4081
  onUploadImage: e,
4055
- stockImageProviders: r,
4056
- onSearchStockImages: i
4082
+ stockImageProviders: i,
4083
+ onSearchStockImages: a
4057
4084
  }),
4058
- a.activeTab === "layers" && /* @__PURE__ */ F(Zt, {
4085
+ o.activeTab === "layers" && /* @__PURE__ */ F(Zt, {
4059
4086
  docked: !0,
4060
- onClose: a.closeTab
4087
+ onClose: o.closeTab
4061
4088
  }),
4062
- a.activeTab === "guides" && /* @__PURE__ */ F(pn, {
4089
+ o.activeTab === "guides" && /* @__PURE__ */ F(pn, {
4063
4090
  docked: !0,
4064
- onClose: a.closeTab
4091
+ onClose: o.closeTab
4065
4092
  }),
4066
- a.activeTab === "brand" && /* @__PURE__ */ F("div", {
4093
+ o.activeTab === "brand" && /* @__PURE__ */ F("div", {
4067
4094
  style: {
4068
4095
  height: "100%",
4069
4096
  overflowY: "auto"
@@ -4084,11 +4111,11 @@ var hr = {
4084
4111
  padding: `${V.lg}px ${V.sm}px`
4085
4112
  },
4086
4113
  children: vr.map((e) => {
4087
- let t = e.icon, n = a.activeTab === e.id;
4114
+ let t = e.icon, n = o.activeTab === e.id;
4088
4115
  return /* @__PURE__ */ I("button", {
4089
4116
  type: "button",
4090
4117
  title: e.label,
4091
- onClick: () => n ? a.closeTab() : a.openTab(e.id),
4118
+ onClick: () => n ? o.closeTab() : o.openTab(e.id),
4092
4119
  style: {
4093
4120
  display: "flex",
4094
4121
  flexDirection: "column",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@charisol/plexo-sdk",
3
3
  "private": false,
4
- "version": "1.4.41",
4
+ "version": "1.4.42",
5
5
  "description": "Plexo visual email and landing page builder SDK — drag-and-drop template editor with AI integration.",
6
6
  "keywords": [
7
7
  "email-builder",