@flytedan/flytebot-design-system 0.87.7 → 0.89.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -40,7 +40,7 @@ function Example() {
40
40
  **32 core components** across seven groups — actions (Button, IconButton,
41
41
  SegmentedControl, Popover, Menu, MenuButton), forms (Input, NumberInput,
42
42
  Textarea, Select, DatePicker, TimePicker, Checkbox, Radio, Switch, Slider,
43
- RangeSlider, FileGrid, Dropzone, MarkdownEditor), surfaces (Card, CardRow,
43
+ RangeSlider, FileGrid, Dropzone, MarkdownEditor, CodeEditor), surfaces (Card, CardRow,
44
44
  Collapsible, Modal, Drawer), data (DataTable, FactList, Pagination, SortMenu, StatTile,
45
45
  Meter, CsiBadge, CsiMeter, CsiHero, Markdown, CodeBlock, DiffBlock, StepList,
46
46
  SegmentedMeter, QuotaRow, Clamp, RelativeTime), feedback (Badge, Tag, Avatar,
@@ -75,6 +75,11 @@ pnpm install
75
75
  pnpm run docs
76
76
  ```
77
77
 
78
+ CodeEditor edits SQL by default; `language="json"` adds JSON highlighting, bracket
79
+ matching and indentation on Enter, shows the parser's syntax error at its line and
80
+ column, and takes `validate={(text) => diagnostics}` for the caller's own checks
81
+ (for example a schema path such as `spec.model`).
82
+
78
83
  ## Development
79
84
 
80
85
  ```bash
package/dist/index.cjs CHANGED
@@ -934,7 +934,6 @@ __export(index_exports, {
934
934
  CORNER_STACK_INSET_PROPERTY: () => CORNER_STACK_INSET_PROPERTY,
935
935
  CORNER_STACK_OFFSET_PROPERTY: () => CORNER_STACK_OFFSET_PROPERTY,
936
936
  CSV_FAILED_FALLBACK: () => CSV_FAILED_FALLBACK,
937
- CSV_KEPT_NOTE: () => CSV_KEPT_NOTE,
938
937
  Calendar: () => Calendar,
939
938
  CallDeadlineError: () => CallDeadlineError,
940
939
  Card: () => Card,
@@ -978,7 +977,6 @@ __export(index_exports, {
978
977
  ENTITY_ROW_METRIC_WIDTH: () => ENTITY_ROW_METRIC_WIDTH,
979
978
  EXPORT_FAILED_FALLBACK: () => EXPORT_FAILED_FALLBACK,
980
979
  EXPORT_IDLE_POLL_INTERVAL_MS: () => EXPORT_IDLE_POLL_INTERVAL_MS,
981
- EXPORT_KEPT_NOTE: () => EXPORT_KEPT_NOTE,
982
980
  EXPORT_POLL_INTERVAL_MS: () => EXPORT_POLL_INTERVAL_MS,
983
981
  EditableTitle: () => EditableTitle,
984
982
  EmptyState: () => EmptyState,
@@ -9970,11 +9968,59 @@ var MarkdownEditor = React60.forwardRef(function MarkdownEditor2({
9970
9968
  // src/components/forms/CodeEditor.tsx
9971
9969
  var React61 = __toESM(require("react"), 1);
9972
9970
  var import_view = require("@codemirror/view");
9973
- var import_state = require("@codemirror/state");
9971
+ var import_state2 = require("@codemirror/state");
9974
9972
  var import_commands = require("@codemirror/commands");
9975
9973
  var import_lang_sql = require("@codemirror/lang-sql");
9976
- var import_language = require("@codemirror/language");
9974
+ var import_lang_json2 = require("@codemirror/lang-json");
9975
+ var import_language2 = require("@codemirror/language");
9977
9976
  var import_highlight = require("@lezer/highlight");
9977
+
9978
+ // src/components/forms/jsonDiagnostics.ts
9979
+ var import_state = require("@codemirror/state");
9980
+ var import_lang_json = require("@codemirror/lang-json");
9981
+ var import_language = require("@codemirror/language");
9982
+ var PARSE_BUDGET_MS = 1e3;
9983
+ function firstErrorOffset(state) {
9984
+ const tree = (0, import_language.ensureSyntaxTree)(state, state.doc.length, PARSE_BUDGET_MS);
9985
+ let at = -1;
9986
+ tree?.iterate({
9987
+ enter(node) {
9988
+ if (at >= 0) return false;
9989
+ if (node.type.isError) {
9990
+ at = node.from;
9991
+ return false;
9992
+ }
9993
+ return void 0;
9994
+ }
9995
+ });
9996
+ return at;
9997
+ }
9998
+ function jsonSyntaxDiagnostics(text) {
9999
+ if (!text.trim()) return [];
10000
+ try {
10001
+ JSON.parse(text);
10002
+ return [];
10003
+ } catch (e) {
10004
+ if (!(e instanceof SyntaxError)) throw e;
10005
+ const state = import_state.EditorState.create({ doc: text, extensions: [(0, import_lang_json.json)()] });
10006
+ const offset = firstErrorOffset(state);
10007
+ const line = state.doc.lineAt(offset < 0 ? state.doc.length : offset);
10008
+ const at = offset < 0 ? state.doc.length : offset;
10009
+ return [{
10010
+ line: line.number,
10011
+ column: at - line.from + 1,
10012
+ message: e.message.replace(/, ".*" is not valid JSON$/s, ""),
10013
+ severity: "error"
10014
+ }];
10015
+ }
10016
+ }
10017
+ function jsonModeDiagnostics(text, validate) {
10018
+ const syntax = jsonSyntaxDiagnostics(text);
10019
+ if (syntax.length || !validate) return syntax;
10020
+ return validate(text);
10021
+ }
10022
+
10023
+ // src/components/forms/CodeEditor.tsx
9978
10024
  var import_jsx_runtime87 = require("react/jsx-runtime");
9979
10025
  function clampOffset(state, line, column) {
9980
10026
  const total = state.doc.lines;
@@ -9992,8 +10038,8 @@ function toCmDiagnostics(state, diags) {
9992
10038
  return { from, to, severity: d.severity || "error", message: d.message, source: void 0 };
9993
10039
  });
9994
10040
  }
9995
- var setDiagnosticsEffect = import_state.StateEffect.define();
9996
- var diagnosticsField = import_state.StateField.define({
10041
+ var setDiagnosticsEffect = import_state2.StateEffect.define();
10042
+ var diagnosticsField = import_state2.StateField.define({
9997
10043
  create: () => [],
9998
10044
  update(value, tr) {
9999
10045
  for (const e of tr.effects) if (e.is(setDiagnosticsEffect)) return e.value;
@@ -10001,7 +10047,7 @@ var diagnosticsField = import_state.StateField.define({
10001
10047
  return value.map((d) => ({ ...d, from: tr.changes.mapPos(d.from), to: tr.changes.mapPos(d.to) }));
10002
10048
  }
10003
10049
  });
10004
- var tokenHighlight = import_language.HighlightStyle.define([
10050
+ var tokenHighlight = import_language2.HighlightStyle.define([
10005
10051
  { tag: import_highlight.tags.keyword, class: "tok-kw" },
10006
10052
  { tag: import_highlight.tags.string, class: "tok-str" },
10007
10053
  { tag: [import_highlight.tags.number, import_highlight.tags.bool], class: "tok-num" },
@@ -10061,7 +10107,9 @@ function CodeEditor({
10061
10107
  disabled = false,
10062
10108
  readOnly = false,
10063
10109
  placeholder: placeholderText = "",
10064
- diagnostics = [],
10110
+ diagnostics: passedDiagnostics,
10111
+ language = "sql",
10112
+ validate,
10065
10113
  showEscapeHint = true,
10066
10114
  minHeight = 160,
10067
10115
  id,
@@ -10070,6 +10118,13 @@ function CodeEditor({
10070
10118
  autoFocus = false
10071
10119
  }) {
10072
10120
  const fieldId = useFieldId(id);
10121
+ const diagnostics = React61.useMemo(
10122
+ () => [
10123
+ ...passedDiagnostics ?? [],
10124
+ ...language === "json" ? jsonModeDiagnostics(value, validate) : []
10125
+ ],
10126
+ [passedDiagnostics, language, value, validate]
10127
+ );
10073
10128
  const descId = fieldId + "-desc";
10074
10129
  const liveId = fieldId + "-live";
10075
10130
  const hostRef = React61.useRef(null);
@@ -10077,9 +10132,10 @@ function CodeEditor({
10077
10132
  const valueRef = React61.useRef(value);
10078
10133
  const onChangeRef = React61.useRef(onChange);
10079
10134
  onChangeRef.current = onChange;
10080
- const editableCompartment = React61.useRef(new import_state.Compartment()).current;
10081
- const readOnlyCompartment = React61.useRef(new import_state.Compartment()).current;
10082
- const attributesCompartment = React61.useRef(new import_state.Compartment()).current;
10135
+ const editableCompartment = React61.useRef(new import_state2.Compartment()).current;
10136
+ const languageCompartment = React61.useRef(new import_state2.Compartment()).current;
10137
+ const readOnlyCompartment = React61.useRef(new import_state2.Compartment()).current;
10138
+ const attributesCompartment = React61.useRef(new import_state2.Compartment()).current;
10083
10139
  const errorRef = React61.useRef(error);
10084
10140
  errorRef.current = error;
10085
10141
  const diagnosticsCountRef = React61.useRef(diagnostics.length);
@@ -10101,16 +10157,16 @@ function CodeEditor({
10101
10157
  valueRef.current = next;
10102
10158
  onChangeRef.current && onChangeRef.current(next);
10103
10159
  });
10104
- const state = import_state.EditorState.create({
10160
+ const state = import_state2.EditorState.create({
10105
10161
  doc: value,
10106
10162
  extensions: [
10107
10163
  (0, import_view.lineNumbers)(),
10108
10164
  (0, import_commands.history)(),
10109
10165
  (0, import_view.drawSelection)(),
10110
- (0, import_language.indentOnInput)(),
10111
- (0, import_language.bracketMatching)(),
10112
- (0, import_lang_sql.sql)(),
10113
- (0, import_language.syntaxHighlighting)(tokenHighlight),
10166
+ (0, import_language2.indentOnInput)(),
10167
+ (0, import_language2.bracketMatching)(),
10168
+ languageCompartment.of(language === "json" ? (0, import_lang_json2.json)() : (0, import_lang_sql.sql)()),
10169
+ (0, import_language2.syntaxHighlighting)(tokenHighlight),
10114
10170
  diagnosticsField,
10115
10171
  decorationsFromDiagnostics(),
10116
10172
  editorTheme,
@@ -10121,7 +10177,7 @@ function CodeEditor({
10121
10177
  ...import_commands.historyKeymap
10122
10178
  ]),
10123
10179
  editableCompartment.of(import_view.EditorView.editable.of(!disabled)),
10124
- readOnlyCompartment.of(import_state.EditorState.readOnly.of(readOnly)),
10180
+ readOnlyCompartment.of(import_state2.EditorState.readOnly.of(readOnly)),
10125
10181
  updateListener,
10126
10182
  attributesCompartment.of(import_view.EditorView.contentAttributes.of(contentAttributes()))
10127
10183
  ]
@@ -10151,7 +10207,12 @@ function CodeEditor({
10151
10207
  React61.useEffect(() => {
10152
10208
  const view = viewRef.current;
10153
10209
  if (!view) return;
10154
- view.dispatch({ effects: readOnlyCompartment.reconfigure(import_state.EditorState.readOnly.of(readOnly)) });
10210
+ view.dispatch({ effects: languageCompartment.reconfigure(language === "json" ? (0, import_lang_json2.json)() : (0, import_lang_sql.sql)()) });
10211
+ }, [language, languageCompartment]);
10212
+ React61.useEffect(() => {
10213
+ const view = viewRef.current;
10214
+ if (!view) return;
10215
+ view.dispatch({ effects: readOnlyCompartment.reconfigure(import_state2.EditorState.readOnly.of(readOnly)) });
10155
10216
  }, [readOnly, readOnlyCompartment]);
10156
10217
  React61.useEffect(() => {
10157
10218
  const view = viewRef.current;
@@ -14636,8 +14697,9 @@ function useChatEngine(opts) {
14636
14697
  res = await apiAdapter.sendMessage(id, turn.text, ac.signal);
14637
14698
  }
14638
14699
  patch(userId, { pending: false });
14639
- const r = res || {};
14640
- if (r.dispatched && r.job_id) {
14700
+ if (!res) throw new Error("send_failed");
14701
+ const r = res;
14702
+ if (r.dispatched) {
14641
14703
  patch(holderId, { streaming: false, working: true, jobId: r.job_id, text: r.reply || "" });
14642
14704
  await pollJob(r.job_id, holderId);
14643
14705
  } else {
@@ -14652,6 +14714,7 @@ function useChatEngine(opts) {
14652
14714
  model: r.model,
14653
14715
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
14654
14716
  });
14717
+ commit(listRef.current.map((m) => m.id === userId ? { ...m, id: r.user_message_id } : m.id === holderId ? { ...m, id: r.assistant_message_id } : m));
14655
14718
  serverCount.current += 2;
14656
14719
  if (r.packet && onPacket) onPacket(r.packet);
14657
14720
  }
@@ -16004,8 +16067,7 @@ var STATE = {
16004
16067
  failed: { label: "Failed", tone: "danger" }
16005
16068
  };
16006
16069
  var CSV_FAILED_FALLBACK = "The CSV could not be made.";
16007
- var CSV_KEPT_NOTE = "Kept 24 hours";
16008
- function CsvCard({ job, onDownload }) {
16070
+ function CsvCard({ job, keptNote, onDownload }) {
16009
16071
  const [downloading, setDownloading] = React88.useState(false);
16010
16072
  const now = useExpiryClock(job);
16011
16073
  const state = exportStateOf(job, now);
@@ -16022,7 +16084,7 @@ function CsvCard({ job, onDownload }) {
16022
16084
  ] }),
16023
16085
  state === "failed" ? /* @__PURE__ */ (0, import_jsx_runtime115.jsx)("p", { className: "fd-body-sm fd-danger", children: job.failureMessage ?? CSV_FAILED_FALLBACK }) : null,
16024
16086
  facts.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime115.jsx)(FactList, { facts }),
16025
- state === "ready" ? /* @__PURE__ */ (0, import_jsx_runtime115.jsx)("p", { className: "fd-body-sm fd-muted", children: CSV_KEPT_NOTE }) : null,
16087
+ state === "ready" ? /* @__PURE__ */ (0, import_jsx_runtime115.jsx)("p", { className: "fd-body-sm fd-muted", children: keptNote }) : null,
16026
16088
  /* @__PURE__ */ (0, import_jsx_runtime115.jsx)("div", { className: "fd-row fd-wrap fd-gap-sm", children: /* @__PURE__ */ (0, import_jsx_runtime115.jsx)(
16027
16089
  Button,
16028
16090
  {
@@ -17418,7 +17480,7 @@ function createChatAdapter(transport, { onTurnStarted, deadlineMs = CHAT_CALL_DE
17418
17480
  if (err instanceof ChatUnreachableError) throw new Error(CHAT_UNAVAILABLE_MESSAGE);
17419
17481
  throw err;
17420
17482
  }
17421
- if (result.job_id) throw new Error("A streamed turn must end with its final result, not a job to poll.");
17483
+ if (result.dispatched) throw new Error("A streamed turn must end with its final result, not a job to poll.");
17422
17484
  markStarted();
17423
17485
  return result;
17424
17486
  }
@@ -17543,16 +17605,15 @@ function useExportJobs({ list, acknowledge }) {
17543
17605
  // src/kits/exports/ExportTray.tsx
17544
17606
  var React96 = __toESM(require("react"), 1);
17545
17607
  var import_jsx_runtime118 = require("react/jsx-runtime");
17546
- var EXPORT_KEPT_NOTE = "Kept for 24 hours";
17547
17608
  var EXPORT_FAILED_FALLBACK = "Unknown error.";
17548
- function exportToJob(job, onDownload) {
17609
+ function exportToJob(job, keptNote, onDownload) {
17549
17610
  const base = { id: job.id, title: job.title, note: job.note };
17550
17611
  if (job.status === "SUCCEEDED") {
17551
17612
  return {
17552
17613
  ...base,
17553
17614
  status: "done",
17554
17615
  action: { label: "Download", icon: "download-simple", onClick: () => onDownload(job.id) },
17555
- doneNote: EXPORT_KEPT_NOTE
17616
+ doneNote: keptNote
17556
17617
  };
17557
17618
  }
17558
17619
  if (job.status === "FAILED") {
@@ -17560,8 +17621,8 @@ function exportToJob(job, onDownload) {
17560
17621
  }
17561
17622
  return { ...base, status: "active" };
17562
17623
  }
17563
- function ExportTray({ exports: exports2, onDownload, onDismiss }) {
17564
- const jobs2 = React96.useMemo(() => exports2.map((job) => exportToJob(job, onDownload)), [exports2, onDownload]);
17624
+ function ExportTray({ exports: exports2, keptNote, onDownload, onDismiss }) {
17625
+ const jobs2 = React96.useMemo(() => exports2.map((job) => exportToJob(job, keptNote, onDownload)), [exports2, keptNote, onDownload]);
17565
17626
  return /* @__PURE__ */ (0, import_jsx_runtime118.jsx)(JobTray, { jobs: jobs2, onDismiss });
17566
17627
  }
17567
17628
  // Annotate the CommonJS export names for ESM import in node:
@@ -17591,7 +17652,6 @@ function ExportTray({ exports: exports2, onDownload, onDismiss }) {
17591
17652
  CORNER_STACK_INSET_PROPERTY,
17592
17653
  CORNER_STACK_OFFSET_PROPERTY,
17593
17654
  CSV_FAILED_FALLBACK,
17594
- CSV_KEPT_NOTE,
17595
17655
  Calendar,
17596
17656
  CallDeadlineError,
17597
17657
  Card,
@@ -17635,7 +17695,6 @@ function ExportTray({ exports: exports2, onDownload, onDismiss }) {
17635
17695
  ENTITY_ROW_METRIC_WIDTH,
17636
17696
  EXPORT_FAILED_FALLBACK,
17637
17697
  EXPORT_IDLE_POLL_INTERVAL_MS,
17638
- EXPORT_KEPT_NOTE,
17639
17698
  EXPORT_POLL_INTERVAL_MS,
17640
17699
  EditableTitle,
17641
17700
  EmptyState,