@galaxycore/ai-chat 0.9.0 → 0.10.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/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  "use client";
3
- import { a as filterSkills, c as slugifySkillName, d as resolveLabels, f as zhCN, i as filterMentions, l as useComposerTrigger, n as useChatBranches, o as parseSkillMarkdown, p as useAiChat, r as detectComposerTrigger, s as replaceComposerTrigger, t as projectChatBranches, u as enUS } from "./branches-M2XjURF5.js";
4
- import { n as ChatAppearanceProvider, r as Icon, t as ChatIconButton } from "./ui-primitives-BzbdVU2_.js";
3
+ import { _ as useAiChat, a as resolveChatModelSelection, c as filterMentions, d as replaceComposerTrigger, f as slugifySkillName, g as zhCN, h as resolveLabels, i as isChatReasoningEffort, l as filterSkills, m as enUS, n as useChatBranches, o as selectChatModel, p as useComposerTrigger, r as CHAT_REASONING_EFFORTS, s as detectComposerTrigger, t as projectChatBranches, u as parseSkillMarkdown } from "./branches-CRxWPjfD.js";
4
+ import { n as ChatAppearanceProvider, r as Icon, t as ChatIconButton } from "./ui-primitives-XhFvDm8o.js";
5
5
  import { i as safeUrl, n as asError, r as getMessageText, t as acceptsFile } from "./utils-DqBGBYA1.js";
6
6
  import { SpeechInputError, createBrowserSpeechAdapter, defaultSpeechInputLabels, useSpeechInput } from "./voice.js";
7
7
  import { MarkdownResponse } from "./markdown.js";
@@ -329,12 +329,204 @@ function ChatPlusMenu({ open, onClose, actions, labels: overrides, className = "
329
329
  });
330
330
  }
331
331
  //#endregion
332
+ //#region src/model-picker-control.tsx
333
+ function effortLabel(effort, labels) {
334
+ switch (effort) {
335
+ case "none": return labels.reasoningNone;
336
+ case "low": return labels.reasoningLow;
337
+ case "medium": return labels.reasoningMedium;
338
+ case "high": return labels.reasoningHigh;
339
+ case "xhigh": return labels.reasoningXhigh;
340
+ }
341
+ }
342
+ /**
343
+ * Compact composer selector for choosing the active AI model and reasoning effort.
344
+ * Trigger stays visually quiet (`Model Effort ⌄`) and opens an anchored popover above the composer.
345
+ */
346
+ function ChatModelPicker({ models, value, onChange, disabled = false, labels: overrides, className = "" }) {
347
+ const labels = resolveLabels(overrides);
348
+ const [open, setOpen] = useState(false);
349
+ const rootRef = useRef(null);
350
+ const triggerRef = useRef(null);
351
+ const dialogId = useId();
352
+ const resolved = resolveChatModelSelection(models, value);
353
+ const activeModel = resolved.model;
354
+ const activeEffort = resolved.reasoningEffort;
355
+ const efforts = resolved.supportedEfforts;
356
+ useEffect(() => {
357
+ if (!open) return;
358
+ function onPointerDown(event) {
359
+ if (rootRef.current && !rootRef.current.contains(event.target)) setOpen(false);
360
+ }
361
+ function onKeyDown(event) {
362
+ if (event.key === "Escape") {
363
+ event.preventDefault();
364
+ setOpen(false);
365
+ triggerRef.current?.focus();
366
+ }
367
+ }
368
+ document.addEventListener("pointerdown", onPointerDown);
369
+ document.addEventListener("keydown", onKeyDown);
370
+ return () => {
371
+ document.removeEventListener("pointerdown", onPointerDown);
372
+ document.removeEventListener("keydown", onKeyDown);
373
+ };
374
+ }, [open]);
375
+ useEffect(() => {
376
+ if (disabled && open) setOpen(false);
377
+ }, [disabled, open]);
378
+ if (!activeModel) return null;
379
+ const canInteract = !disabled && (models.length > 1 || efforts.length > 0);
380
+ const effortText = activeEffort ? effortLabel(activeEffort, labels) : void 0;
381
+ const triggerAccessibleName = effortText ? `${labels.selectModel}: ${activeModel.label} (${effortText})` : `${labels.selectModel}: ${activeModel.label}`;
382
+ function handleSelectModel(option) {
383
+ if (option.disabled) return;
384
+ onChange(selectChatModel(option, activeEffort));
385
+ if (!option.reasoningEfforts?.length) {
386
+ setOpen(false);
387
+ triggerRef.current?.focus();
388
+ }
389
+ }
390
+ function handleSelectEffort(effort) {
391
+ if (!activeModel) return;
392
+ onChange({
393
+ modelId: activeModel.id,
394
+ ...effort !== void 0 ? { reasoningEffort: effort } : {}
395
+ });
396
+ }
397
+ return /* @__PURE__ */ jsxs("div", {
398
+ ref: rootRef,
399
+ className: `gc-chat__model-picker ${className}`.trim(),
400
+ "data-open": open || void 0,
401
+ children: [/* @__PURE__ */ jsxs("button", {
402
+ ref: triggerRef,
403
+ type: "button",
404
+ className: "gc-chat__model-trigger",
405
+ disabled: disabled || !canInteract,
406
+ "aria-haspopup": "dialog",
407
+ "aria-expanded": open,
408
+ "aria-controls": open ? dialogId : void 0,
409
+ "aria-label": triggerAccessibleName,
410
+ onClick: () => setOpen((current) => !current),
411
+ children: [
412
+ /* @__PURE__ */ jsx("span", {
413
+ className: "gc-chat__model-trigger-name",
414
+ children: activeModel.label
415
+ }),
416
+ effortText ? /* @__PURE__ */ jsx("span", {
417
+ className: "gc-chat__model-trigger-effort",
418
+ children: effortText
419
+ }) : null,
420
+ canInteract ? /* @__PURE__ */ jsx("span", {
421
+ className: "gc-chat__model-trigger-chevron",
422
+ "aria-hidden": "true",
423
+ children: /* @__PURE__ */ jsx(Icon, {
424
+ name: "chevronDown",
425
+ width: 14,
426
+ height: 14
427
+ })
428
+ }) : null
429
+ ]
430
+ }), open ? /* @__PURE__ */ jsxs("div", {
431
+ id: dialogId,
432
+ role: "dialog",
433
+ "aria-label": labels.selectModel,
434
+ className: "gc-chat__popover gc-chat__model-popover",
435
+ children: [/* @__PURE__ */ jsxs("div", {
436
+ className: "gc-chat__model-section",
437
+ children: [/* @__PURE__ */ jsx("div", {
438
+ className: "gc-chat__popover-group-label",
439
+ children: labels.selectModel
440
+ }), /* @__PURE__ */ jsx("div", {
441
+ className: "gc-chat__popover-list",
442
+ role: "listbox",
443
+ "aria-label": labels.selectModel,
444
+ children: models.map((option) => {
445
+ const selected = option.id === activeModel.id;
446
+ return /* @__PURE__ */ jsxs("button", {
447
+ type: "button",
448
+ role: "option",
449
+ "aria-selected": selected,
450
+ disabled: option.disabled,
451
+ className: "gc-chat__popover-item gc-chat__model-option",
452
+ "data-selected": selected || void 0,
453
+ onClick: () => handleSelectModel(option),
454
+ children: [
455
+ option.icon ? /* @__PURE__ */ jsx("span", {
456
+ className: "gc-chat__popover-icon",
457
+ "aria-hidden": "true",
458
+ children: option.icon
459
+ }) : null,
460
+ /* @__PURE__ */ jsxs("span", {
461
+ className: "gc-chat__popover-copy",
462
+ children: [/* @__PURE__ */ jsxs("span", {
463
+ className: "gc-chat__popover-label",
464
+ children: [option.label, option.badge ? /* @__PURE__ */ jsx("span", {
465
+ className: "gc-chat__popover-badge",
466
+ children: option.badge
467
+ }) : null]
468
+ }), option.description ? /* @__PURE__ */ jsx("span", {
469
+ className: "gc-chat__popover-desc",
470
+ children: option.description
471
+ }) : null]
472
+ }),
473
+ /* @__PURE__ */ jsx("span", {
474
+ className: "gc-chat__popover-trailing",
475
+ "aria-hidden": "true",
476
+ children: selected ? /* @__PURE__ */ jsx(Icon, {
477
+ name: "check",
478
+ width: 14,
479
+ height: 14
480
+ }) : null
481
+ })
482
+ ]
483
+ }, option.id);
484
+ })
485
+ })]
486
+ }), efforts.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
487
+ className: "gc-chat__popover-divider",
488
+ role: "separator"
489
+ }), /* @__PURE__ */ jsxs("div", {
490
+ className: "gc-chat__model-section gc-chat__reasoning-section",
491
+ children: [/* @__PURE__ */ jsxs("div", {
492
+ className: "gc-chat__reasoning-header",
493
+ children: [/* @__PURE__ */ jsx("span", {
494
+ className: "gc-chat__popover-group-label",
495
+ children: labels.reasoningEffort
496
+ }), activeEffort && !activeModel.defaultReasoningEffort ? /* @__PURE__ */ jsx("button", {
497
+ type: "button",
498
+ className: "gc-chat__reasoning-reset",
499
+ onClick: () => handleSelectEffort(void 0),
500
+ children: labels.reasoningDefault
501
+ }) : null]
502
+ }), /* @__PURE__ */ jsx("div", {
503
+ className: "gc-chat__reasoning-segments",
504
+ role: "radiogroup",
505
+ "aria-label": labels.reasoningEffort,
506
+ children: efforts.map((effort) => {
507
+ const selected = activeEffort === effort;
508
+ return /* @__PURE__ */ jsx("button", {
509
+ type: "button",
510
+ role: "radio",
511
+ "aria-checked": selected,
512
+ className: "gc-chat__reasoning-segment",
513
+ "data-selected": selected || void 0,
514
+ onClick: () => handleSelectEffort(effort),
515
+ children: effortLabel(effort, labels)
516
+ }, effort);
517
+ })
518
+ })]
519
+ })] }) : null]
520
+ }) : null]
521
+ });
522
+ }
523
+ //#endregion
332
524
  //#region src/chat-composer.tsx
333
525
  /** Drafts and upload requests are isolated by conversation id. */
334
526
  function ChatComposer(props) {
335
527
  return /* @__PURE__ */ jsx(Composer, { ...props }, props.chat.id);
336
528
  }
337
- function Composer({ chat, labels: overrides, attachments, speech, skills, onSelectSkill, onAddSkill, onBrowseSkills, mentions, onSelectMention, plusMenuActions, toolbar, context, requestOptions, disabled, className = "", onActionError }) {
529
+ function Composer({ chat, labels: overrides, attachments, speech, skills, onSelectSkill, onAddSkill, onBrowseSkills, mentions, onSelectMention, plusMenuActions, modelPicker, toolbar, context, requestOptions, disabled, className = "", onActionError }) {
338
530
  const labels = resolveLabels(overrides);
339
531
  const [text, setText] = useState("");
340
532
  const [cursor, setCursor] = useState(0);
@@ -756,28 +948,36 @@ function Composer({ chat, labels: overrides, attachments, speech, skills, onSele
756
948
  ]
757
949
  }), /* @__PURE__ */ jsxs("div", {
758
950
  className: "gc-chat__composer-actions",
759
- children: [speech && /* @__PURE__ */ jsx(ChatIconButton, {
760
- label: voiceLabels.start,
761
- icon: "mic",
762
- tooltip: voice.support.reason ?? voiceLabels.start,
763
- "aria-describedby": !voice.support.supported ? `${inputId}-voice-support` : void 0,
764
- disabled: disabled || chat.isBusy || voice.isActive || voice.state === "consent" || !voice.support.supported,
765
- onClick: voice.start
766
- }), chat.isBusy ? /* @__PURE__ */ jsx(ChatIconButton, {
767
- className: "gc-chat__send",
768
- label: labels.stop,
769
- icon: "stop",
770
- onClick: (event) => {
771
- event.preventDefault();
772
- chat.stop().catch(report);
773
- }
774
- }) : /* @__PURE__ */ jsx(ChatIconButton, {
775
- className: "gc-chat__send",
776
- type: "submit",
777
- disabled: !canSend,
778
- label: labels.send,
779
- icon: "send"
780
- })]
951
+ children: [
952
+ modelPicker ? /* @__PURE__ */ jsx(ChatModelPicker, {
953
+ ...modelPicker,
954
+ labels: overrides,
955
+ disabled: disabled || chat.isBusy || modelPicker.disabled
956
+ }) : null,
957
+ speech && /* @__PURE__ */ jsx(ChatIconButton, {
958
+ label: voiceLabels.start,
959
+ icon: "mic",
960
+ tooltip: voice.support.reason ?? voiceLabels.start,
961
+ "aria-describedby": !voice.support.supported ? `${inputId}-voice-support` : void 0,
962
+ disabled: disabled || chat.isBusy || voice.isActive || voice.state === "consent" || !voice.support.supported,
963
+ onClick: voice.start
964
+ }),
965
+ chat.isBusy ? /* @__PURE__ */ jsx(ChatIconButton, {
966
+ className: "gc-chat__send",
967
+ label: labels.stop,
968
+ icon: "stop",
969
+ onClick: (event) => {
970
+ event.preventDefault();
971
+ chat.stop().catch(report);
972
+ }
973
+ }) : /* @__PURE__ */ jsx(ChatIconButton, {
974
+ className: "gc-chat__send",
975
+ type: "submit",
976
+ disabled: !canSend,
977
+ label: labels.send,
978
+ icon: "send"
979
+ })
980
+ ]
781
981
  })]
782
982
  }),
783
983
  error ? /* @__PURE__ */ jsxs("div", {
@@ -2058,6 +2258,6 @@ function ChatHistoryMenu({ conversations, currentId, onSelect, onNewChat, disabl
2058
2258
  });
2059
2259
  }
2060
2260
  //#endregion
2061
- export { AiChat, ChatAppearanceProvider, ChatBranchSwitcher, ChatCheckpointBanner, ChatComposer, ChatHistoryMenu, Icon as ChatIcon, ChatIconButton, ChatMentionMenu, ChatMessages, ChatPanel, ChatPlusMenu, ChatSlashMenu, ChatTargetingOverlay, ContextTray, SpeechInputError, createBrowserSpeechAdapter, createTextSelectionAdapter, defaultSpeechInputLabels, detectComposerTrigger, enUS, enUSTargetingLabels, filterMentions, filterSkills, getMessageText, parseSkillMarkdown, projectChatBranches, replaceComposerTrigger, slugifySkillName, toChatContextItem, useAiChat, useChatBranches, useChatContext, useChatTargeting, useComposerTrigger, useSpeechInput, zhCN, zhCNTargetingLabels };
2261
+ export { AiChat, CHAT_REASONING_EFFORTS, ChatAppearanceProvider, ChatBranchSwitcher, ChatCheckpointBanner, ChatComposer, ChatHistoryMenu, Icon as ChatIcon, ChatIconButton, ChatMentionMenu, ChatMessages, ChatModelPicker, ChatPanel, ChatPlusMenu, ChatSlashMenu, ChatTargetingOverlay, ContextTray, SpeechInputError, createBrowserSpeechAdapter, createTextSelectionAdapter, defaultSpeechInputLabels, detectComposerTrigger, enUS, enUSTargetingLabels, filterMentions, filterSkills, getMessageText, isChatReasoningEffort, parseSkillMarkdown, projectChatBranches, replaceComposerTrigger, resolveChatModelSelection, selectChatModel, slugifySkillName, toChatContextItem, useAiChat, useChatBranches, useChatContext, useChatTargeting, useComposerTrigger, useSpeechInput, zhCN, zhCNTargetingLabels };
2062
2262
 
2063
2263
  //# sourceMappingURL=index.js.map