@axiom-lattice/react-sdk 2.1.24 → 2.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -873,10 +873,6 @@ declare const ScheduleButton: React__default.FC<ScheduleButtonProps>;
873
873
  * Props for AssistantFlow component
874
874
  */
875
875
  interface AssistantFlowProps {
876
- /**
877
- * List of assistants to display
878
- */
879
- assistants: Assistant[];
880
876
  /**
881
877
  * Callback when an assistant node is clicked
882
878
  */
@@ -911,18 +907,10 @@ declare const AssistantNode: React__default.FC<NodeProps<Node<AssistantNodeData>
911
907
  * Props for SkillFlow component
912
908
  */
913
909
  interface SkillFlowProps {
914
- /**
915
- * List of skills to display
916
- */
917
- skills: Skill[];
918
910
  /**
919
911
  * Callback when a skill node is clicked
920
912
  */
921
913
  onNodeClick?: (skill: Skill) => void;
922
- /**
923
- * Callback to refresh skills list after creating a new skill
924
- */
925
- onRefresh?: () => void | Promise<void>;
926
914
  }
927
915
  /**
928
916
  * SkillFlow component - Canvas for visualizing skills
@@ -942,6 +930,10 @@ interface SkillNodeData extends Record<string, unknown> {
942
930
  * Click handler for the node
943
931
  */
944
932
  onClick?: (skill: Skill) => void;
933
+ /**
934
+ * Callback when a skill is deleted
935
+ */
936
+ onDelete?: () => void | Promise<void>;
945
937
  }
946
938
  /**
947
939
  * Custom node component for displaying skills in the flow
package/dist/index.d.ts CHANGED
@@ -873,10 +873,6 @@ declare const ScheduleButton: React__default.FC<ScheduleButtonProps>;
873
873
  * Props for AssistantFlow component
874
874
  */
875
875
  interface AssistantFlowProps {
876
- /**
877
- * List of assistants to display
878
- */
879
- assistants: Assistant[];
880
876
  /**
881
877
  * Callback when an assistant node is clicked
882
878
  */
@@ -911,18 +907,10 @@ declare const AssistantNode: React__default.FC<NodeProps<Node<AssistantNodeData>
911
907
  * Props for SkillFlow component
912
908
  */
913
909
  interface SkillFlowProps {
914
- /**
915
- * List of skills to display
916
- */
917
- skills: Skill[];
918
910
  /**
919
911
  * Callback when a skill node is clicked
920
912
  */
921
913
  onNodeClick?: (skill: Skill) => void;
922
- /**
923
- * Callback to refresh skills list after creating a new skill
924
- */
925
- onRefresh?: () => void | Promise<void>;
926
914
  }
927
915
  /**
928
916
  * SkillFlow component - Canvas for visualizing skills
@@ -942,6 +930,10 @@ interface SkillNodeData extends Record<string, unknown> {
942
930
  * Click handler for the node
943
931
  */
944
932
  onClick?: (skill: Skill) => void;
933
+ /**
934
+ * Callback when a skill is deleted
935
+ */
936
+ onDelete?: () => void | Promise<void>;
945
937
  }
946
938
  /**
947
939
  * Custom node component for displaying skills in the flow
package/dist/index.js CHANGED
@@ -7128,18 +7128,44 @@ var AssistantNode_default = AssistantNode;
7128
7128
 
7129
7129
  // src/components/Chat/AssistantFlow.tsx
7130
7130
  var import_jsx_runtime44 = require("react/jsx-runtime");
7131
- var AssistantFlowInner = ({
7132
- assistants,
7133
- onNodeClick
7134
- }) => {
7131
+ var AssistantFlowInner = ({ onNodeClick }) => {
7135
7132
  const [nodes, setNodes, onNodesChange] = (0, import_react30.useNodesState)([]);
7136
7133
  const [edges, setEdges, onEdgesChange] = (0, import_react30.useEdgesState)([]);
7134
+ const [assistants, setAssistants] = (0, import_react29.useState)([]);
7135
+ const [assistantsLoading, setAssistantsLoading] = (0, import_react29.useState)(false);
7136
+ const { config } = useLatticeChatShellContext();
7137
7137
  const nodeTypes = (0, import_react29.useMemo)(
7138
7138
  () => ({
7139
7139
  assistant: AssistantNode_default
7140
7140
  }),
7141
7141
  []
7142
7142
  );
7143
+ const fetchAssistants = async () => {
7144
+ setAssistantsLoading(true);
7145
+ try {
7146
+ const headers = {};
7147
+ if (config.apiKey) {
7148
+ headers["Authorization"] = `Bearer ${config.apiKey}`;
7149
+ }
7150
+ const response = await fetch(`${config.baseURL}/api/assistants`, {
7151
+ headers
7152
+ });
7153
+ if (response.ok) {
7154
+ const data = await response.json();
7155
+ if (data.success && data.data && Array.isArray(data.data.records)) {
7156
+ setAssistants(data.data.records);
7157
+ }
7158
+ }
7159
+ } catch (error) {
7160
+ console.error("Failed to fetch assistants:", error);
7161
+ setAssistants([]);
7162
+ } finally {
7163
+ setAssistantsLoading(false);
7164
+ }
7165
+ };
7166
+ (0, import_react29.useEffect)(() => {
7167
+ fetchAssistants();
7168
+ }, []);
7143
7169
  (0, import_react29.useEffect)(() => {
7144
7170
  if (!assistants || assistants.length === 0) {
7145
7171
  setNodes([]);
@@ -7329,6 +7355,22 @@ var AssistantFlowInner = ({
7329
7355
  setNodes(initialNodes);
7330
7356
  setEdges(initialEdges);
7331
7357
  }, [assistants, setNodes, setEdges, onNodeClick]);
7358
+ if (assistantsLoading) {
7359
+ return /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
7360
+ "div",
7361
+ {
7362
+ style: {
7363
+ width: "100%",
7364
+ height: "100%",
7365
+ display: "flex",
7366
+ justifyContent: "center",
7367
+ alignItems: "center",
7368
+ background: "#fafafa"
7369
+ },
7370
+ children: "Loading assistants..."
7371
+ }
7372
+ );
7373
+ }
7332
7374
  return /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("div", { style: { width: "100%", height: "100%", background: "#fafafa" }, children: /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)(
7333
7375
  import_react30.ReactFlow,
7334
7376
  {
@@ -7360,6 +7402,7 @@ var import_react31 = require("react");
7360
7402
  var import_react32 = require("@xyflow/react");
7361
7403
  var import_antd29 = require("antd");
7362
7404
  var import_icons17 = require("@ant-design/icons");
7405
+ var import_client_sdk8 = require("@axiom-lattice/client-sdk");
7363
7406
  var import_jsx_runtime45 = require("react/jsx-runtime");
7364
7407
  var { Text: Text15 } = import_antd29.Typography;
7365
7408
  var { TextArea } = import_antd29.Input;
@@ -7391,10 +7434,20 @@ var getBadgeColor2 = (name) => {
7391
7434
  var SkillNode = ({ data }) => {
7392
7435
  const { token } = import_antd29.theme.useToken();
7393
7436
  const { config } = useLatticeChatShellContext();
7437
+ const client = (0, import_react31.useMemo)(
7438
+ () => new import_client_sdk8.Client({
7439
+ baseURL: config.baseURL,
7440
+ apiKey: config.apiKey || "",
7441
+ assistantId: "",
7442
+ // Not needed for skills
7443
+ transport: "sse"
7444
+ }),
7445
+ [config.baseURL, config.apiKey]
7446
+ );
7394
7447
  if (!data) {
7395
7448
  return null;
7396
7449
  }
7397
- const { skill, onClick } = data;
7450
+ const { skill, onClick, onDelete } = data;
7398
7451
  if (!skill) {
7399
7452
  return null;
7400
7453
  }
@@ -7458,45 +7511,26 @@ var SkillNode = ({ data }) => {
7458
7511
  [field]: value
7459
7512
  }));
7460
7513
  };
7461
- const handleDelete = () => {
7462
- import_antd29.Modal.confirm({
7463
- title: "Delete skill",
7464
- content: `Are you sure you want to delete "${currentSkill.name}"? This action cannot be undone.`,
7465
- okText: "Delete",
7466
- okType: "danger",
7467
- cancelText: "Cancel",
7468
- onOk: async () => {
7469
- try {
7470
- const headers = {};
7471
- if (config.apiKey) {
7472
- headers["Authorization"] = `Bearer ${config.apiKey}`;
7473
- }
7474
- const response = await fetch(
7475
- `${config.baseURL}/api/skills/${currentSkill.id}`,
7476
- {
7477
- method: "DELETE",
7478
- headers
7479
- }
7480
- );
7481
- let data2 = {};
7482
- try {
7483
- data2 = await response.json();
7484
- } catch {
7485
- }
7486
- if (response.ok && (data2.success ?? true)) {
7487
- import_antd29.message.success("Skill deleted successfully");
7488
- setIsModalOpen(false);
7489
- onClick?.(currentSkill);
7490
- } else {
7491
- import_antd29.message.error(data2.message || "Failed to delete skill");
7492
- }
7493
- } catch (error) {
7494
- import_antd29.message.error(
7495
- error?.message || "An error occurred while deleting the skill"
7496
- );
7497
- }
7514
+ const handleDelete = async (e) => {
7515
+ e?.stopPropagation();
7516
+ e?.preventDefault();
7517
+ try {
7518
+ const skillId = currentSkill.id || currentSkill.name;
7519
+ if (!skillId) {
7520
+ import_antd29.message.error("Skill ID is missing");
7521
+ return;
7498
7522
  }
7499
- });
7523
+ await client.skills.delete(skillId);
7524
+ import_antd29.message.success("Skill deleted successfully");
7525
+ setIsModalOpen(false);
7526
+ if (onDelete) {
7527
+ await onDelete();
7528
+ }
7529
+ } catch (error) {
7530
+ import_antd29.message.error(
7531
+ error?.message || "An error occurred while deleting the skill"
7532
+ );
7533
+ }
7500
7534
  };
7501
7535
  const syncMetadataRows = (rows) => {
7502
7536
  setMetadataRows(rows);
@@ -8141,7 +8175,17 @@ var SkillNode = ({ data }) => {
8141
8175
  children: "Edit Skill"
8142
8176
  }
8143
8177
  ),
8144
- /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(import_antd29.Button, { danger: true, onClick: handleDelete, children: "Delete" }),
8178
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
8179
+ import_antd29.Button,
8180
+ {
8181
+ danger: true,
8182
+ onClick: (e) => {
8183
+ e.stopPropagation();
8184
+ handleDelete(e);
8185
+ },
8186
+ children: "Delete"
8187
+ }
8188
+ ),
8145
8189
  /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
8146
8190
  import_antd29.Button,
8147
8191
  {
@@ -8807,21 +8851,46 @@ var CreateSkillModal_default = CreateSkillModal;
8807
8851
 
8808
8852
  // src/components/Chat/SkillFlow.tsx
8809
8853
  var import_jsx_runtime47 = require("react/jsx-runtime");
8810
- var SkillFlowInner = ({
8811
- skills,
8812
- onNodeClick,
8813
- onRefresh
8814
- }) => {
8854
+ var SkillFlowInner = ({ onNodeClick }) => {
8815
8855
  const [nodes, setNodes, onNodesChange] = (0, import_react35.useNodesState)([]);
8816
8856
  const [edges, setEdges, onEdgesChange] = (0, import_react35.useEdgesState)([]);
8817
8857
  const [isCreateModalOpen, setIsCreateModalOpen] = (0, import_react34.useState)(false);
8858
+ const [skills, setSkills] = (0, import_react34.useState)([]);
8859
+ const [skillsLoading, setSkillsLoading] = (0, import_react34.useState)(false);
8818
8860
  const { token } = import_antd32.theme.useToken();
8861
+ const { config } = useLatticeChatShellContext();
8819
8862
  const nodeTypes = (0, import_react34.useMemo)(
8820
8863
  () => ({
8821
8864
  skill: SkillNode_default
8822
8865
  }),
8823
8866
  []
8824
8867
  );
8868
+ const fetchSkills = async () => {
8869
+ setSkillsLoading(true);
8870
+ try {
8871
+ const headers = {};
8872
+ if (config.apiKey) {
8873
+ headers["Authorization"] = `Bearer ${config.apiKey}`;
8874
+ }
8875
+ const response = await fetch(`${config.baseURL}/api/skills`, {
8876
+ headers
8877
+ });
8878
+ if (response.ok) {
8879
+ const data = await response.json();
8880
+ if (data.success && data.data && Array.isArray(data.data.records)) {
8881
+ setSkills(data.data.records);
8882
+ }
8883
+ }
8884
+ } catch (error) {
8885
+ console.error("Failed to fetch skills:", error);
8886
+ setSkills([]);
8887
+ } finally {
8888
+ setSkillsLoading(false);
8889
+ }
8890
+ };
8891
+ (0, import_react34.useEffect)(() => {
8892
+ fetchSkills();
8893
+ }, []);
8825
8894
  (0, import_react34.useEffect)(() => {
8826
8895
  if (!skills || skills.length === 0) {
8827
8896
  setNodes([]);
@@ -8911,7 +8980,8 @@ var SkillFlowInner = ({
8911
8980
  type: "skill",
8912
8981
  data: {
8913
8982
  skill,
8914
- onClick: () => onNodeClick?.(skill)
8983
+ onClick: () => onNodeClick?.(skill),
8984
+ onDelete: fetchSkills
8915
8985
  },
8916
8986
  position: { x, y }
8917
8987
  });
@@ -8950,10 +9020,24 @@ var SkillFlowInner = ({
8950
9020
  setEdges(initialEdges);
8951
9021
  }, [skills, setNodes, setEdges, onNodeClick]);
8952
9022
  const handleSkillCreated = async () => {
8953
- if (onRefresh) {
8954
- await onRefresh();
8955
- }
9023
+ await fetchSkills();
8956
9024
  };
9025
+ if (skillsLoading) {
9026
+ return /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
9027
+ "div",
9028
+ {
9029
+ style: {
9030
+ width: "100%",
9031
+ height: "100%",
9032
+ display: "flex",
9033
+ justifyContent: "center",
9034
+ alignItems: "center",
9035
+ background: "#fafafa"
9036
+ },
9037
+ children: "Loading skills..."
9038
+ }
9039
+ );
9040
+ }
8957
9041
  return /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)("div", { style: { width: "100%", height: "100%", background: "#fafafa", position: "relative" }, children: [
8958
9042
  /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)(
8959
9043
  import_react35.ReactFlow,
@@ -8975,7 +9059,7 @@ var SkillFlowInner = ({
8975
9059
  {
8976
9060
  style: {
8977
9061
  position: "absolute",
8978
- bottom: 20,
9062
+ top: 20,
8979
9063
  right: 20,
8980
9064
  zIndex: 10
8981
9065
  },
@@ -9239,13 +9323,11 @@ var ChatSidebar = ({
9239
9323
  const { styles } = useStyles4();
9240
9324
  const { setMenuCollapsed, menuCollapsed, sideAppVisible } = useChatUIContext();
9241
9325
  const { setSettingsModalOpen, config } = useLatticeChatShellContext();
9242
- const { assistants, selectAssistant } = useAssistantContext();
9326
+ const { selectAssistant } = useAssistantContext();
9243
9327
  const [isHovered, setIsHovered] = (0, import_react36.useState)(false);
9244
9328
  const [isFirstCollapse, setIsFirstCollapse] = (0, import_react36.useState)(false);
9245
9329
  const [isFlowModalOpen, setIsFlowModalOpen] = (0, import_react36.useState)(false);
9246
9330
  const [isSkillFlowModalOpen, setIsSkillFlowModalOpen] = (0, import_react36.useState)(false);
9247
- const [skills, setSkills] = (0, import_react36.useState)([]);
9248
- const [skillsLoading, setSkillsLoading] = (0, import_react36.useState)(false);
9249
9331
  const prevIsCollapsedRef = (0, import_react36.useRef)(false);
9250
9332
  const handleToggleCollapse = () => {
9251
9333
  setMenuCollapsed(!menuCollapsed);
@@ -9254,34 +9336,8 @@ var ChatSidebar = ({
9254
9336
  setSettingsModalOpen(true);
9255
9337
  onSettingsClick?.();
9256
9338
  };
9257
- const handleSkillFlowClick = async () => {
9339
+ const handleSkillFlowClick = () => {
9258
9340
  setIsSkillFlowModalOpen(true);
9259
- if (skills.length === 0 && !skillsLoading) {
9260
- await fetchSkills();
9261
- }
9262
- };
9263
- const fetchSkills = async () => {
9264
- setSkillsLoading(true);
9265
- try {
9266
- const headers = {};
9267
- if (config.apiKey) {
9268
- headers["Authorization"] = `Bearer ${config.apiKey}`;
9269
- }
9270
- const response = await fetch(`${config.baseURL}/api/skills`, {
9271
- headers
9272
- });
9273
- if (response.ok) {
9274
- const data = await response.json();
9275
- if (data.success && data.data && Array.isArray(data.data.records)) {
9276
- setSkills(data.data.records);
9277
- }
9278
- }
9279
- } catch (error) {
9280
- console.error("Failed to fetch skills:", error);
9281
- setSkills([]);
9282
- } finally {
9283
- setSkillsLoading(false);
9284
- }
9285
9341
  };
9286
9342
  const isCollapsed = menuCollapsed || sideAppVisible;
9287
9343
  (0, import_react36.useEffect)(() => {
@@ -9460,6 +9516,7 @@ var ChatSidebar = ({
9460
9516
  /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
9461
9517
  import_antd33.Modal,
9462
9518
  {
9519
+ destroyOnHidden: true,
9463
9520
  title: "Assistant Overview",
9464
9521
  open: isFlowModalOpen,
9465
9522
  onCancel: () => setIsFlowModalOpen(false),
@@ -9473,7 +9530,6 @@ var ChatSidebar = ({
9473
9530
  children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("div", { style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
9474
9531
  AssistantFlow_default,
9475
9532
  {
9476
- assistants,
9477
9533
  onNodeClick: (assistant) => {
9478
9534
  selectAssistant(assistant.id);
9479
9535
  setIsFlowModalOpen(false);
@@ -9485,6 +9541,7 @@ var ChatSidebar = ({
9485
9541
  /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
9486
9542
  import_antd33.Modal,
9487
9543
  {
9544
+ destroyOnHidden: true,
9488
9545
  title: "Skill Overview",
9489
9546
  open: isSkillFlowModalOpen,
9490
9547
  onCancel: () => setIsSkillFlowModalOpen(false),
@@ -9495,25 +9552,12 @@ var ChatSidebar = ({
9495
9552
  height: "calc(100vh - 120px)",
9496
9553
  padding: 0
9497
9554
  },
9498
- children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("div", { style: { width: "100%", height: "100%" }, children: skillsLoading ? /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
9499
- "div",
9500
- {
9501
- style: {
9502
- display: "flex",
9503
- justifyContent: "center",
9504
- alignItems: "center",
9505
- height: "100%"
9506
- },
9507
- children: "Loading skills..."
9508
- }
9509
- ) : /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
9555
+ children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("div", { style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
9510
9556
  SkillFlow_default,
9511
9557
  {
9512
- skills,
9513
9558
  onNodeClick: (skill) => {
9514
9559
  console.log("Skill clicked:", skill);
9515
- },
9516
- onRefresh: fetchSkills
9560
+ }
9517
9561
  }
9518
9562
  ) })
9519
9563
  }