@arbidocs/react 0.3.115 → 0.3.117
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.cjs +1675 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1170 -166
- package/dist/index.d.ts +1170 -166
- package/dist/index.js +1626 -5
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -35,6 +35,7 @@ var ReactMarkdown = require('react-markdown');
|
|
|
35
35
|
var remarkGfm = require('remark-gfm');
|
|
36
36
|
var rehypeRaw = require('rehype-raw');
|
|
37
37
|
var framerMotion = require('framer-motion');
|
|
38
|
+
var Cropper = require('react-easy-crop');
|
|
38
39
|
var agGridReact = require('ag-grid-react');
|
|
39
40
|
var agGridCommunity = require('ag-grid-community');
|
|
40
41
|
|
|
@@ -79,6 +80,7 @@ var SelectPrimitive__namespace = /*#__PURE__*/_interopNamespace(SelectPrimitive)
|
|
|
79
80
|
var ReactMarkdown__default = /*#__PURE__*/_interopDefault(ReactMarkdown);
|
|
80
81
|
var remarkGfm__default = /*#__PURE__*/_interopDefault(remarkGfm);
|
|
81
82
|
var rehypeRaw__default = /*#__PURE__*/_interopDefault(rehypeRaw);
|
|
83
|
+
var Cropper__default = /*#__PURE__*/_interopDefault(Cropper);
|
|
82
84
|
|
|
83
85
|
// src/ArbiProvider.tsx
|
|
84
86
|
var ArbiContext = React.createContext(null);
|
|
@@ -671,7 +673,13 @@ var arbiQueryKeys = {
|
|
|
671
673
|
health: () => ["arbi", "health"],
|
|
672
674
|
tasks: () => ["arbi", "tasks"],
|
|
673
675
|
memories: (workspaceId) => ["arbi", "memories", workspaceId],
|
|
674
|
-
configs: () => ["arbi", "configs"]
|
|
676
|
+
configs: () => ["arbi", "configs"],
|
|
677
|
+
activity: () => ["arbi", "activity"],
|
|
678
|
+
projects: () => ["arbi", "projects"],
|
|
679
|
+
projectUsage: (projectExtId, monthsBack) => ["arbi", "projectUsage", projectExtId, monthsBack],
|
|
680
|
+
projectInvoices: (projectExtId) => ["arbi", "projectInvoices", projectExtId],
|
|
681
|
+
userUsageToday: () => ["arbi", "userUsageToday"],
|
|
682
|
+
workspaceChronology: (workspaceId) => ["arbi", "workspaceChronology", workspaceId]
|
|
675
683
|
};
|
|
676
684
|
function useWorkspaces(options) {
|
|
677
685
|
const arbi = useArbi();
|
|
@@ -782,6 +790,119 @@ function useConfigs(options) {
|
|
|
782
790
|
enabled: options?.enabled ?? arbi.isLoggedIn
|
|
783
791
|
});
|
|
784
792
|
}
|
|
793
|
+
function useActivity(options) {
|
|
794
|
+
const arbi = useArbi();
|
|
795
|
+
return reactQuery.useQuery({
|
|
796
|
+
queryKey: arbiQueryKeys.activity(),
|
|
797
|
+
queryFn: () => arbi.dm.listActivity({ limit: options?.limit, offset: options?.offset }),
|
|
798
|
+
enabled: options?.enabled ?? arbi.isLoggedIn
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
function useProjects(options) {
|
|
802
|
+
const arbi = useArbi();
|
|
803
|
+
return reactQuery.useQuery({
|
|
804
|
+
queryKey: arbiQueryKeys.projects(),
|
|
805
|
+
queryFn: () => arbi.projects.list(),
|
|
806
|
+
enabled: options?.enabled ?? arbi.isLoggedIn
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
function useProjectUsage(projectExtId, monthsBack = 0, options) {
|
|
810
|
+
const arbi = useArbi();
|
|
811
|
+
return reactQuery.useQuery({
|
|
812
|
+
queryKey: arbiQueryKeys.projectUsage(projectExtId ?? "", monthsBack),
|
|
813
|
+
queryFn: () => arbi.projects.usage(projectExtId, monthsBack),
|
|
814
|
+
enabled: (options?.enabled ?? true) && !!projectExtId && arbi.isLoggedIn
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
function useProjectsUsage(projectExtIds, monthsBack = 0, options) {
|
|
818
|
+
const arbi = useArbi();
|
|
819
|
+
const enabled = (options?.enabled ?? true) && arbi.isLoggedIn;
|
|
820
|
+
const results = reactQuery.useQueries({
|
|
821
|
+
queries: projectExtIds.map((id) => ({
|
|
822
|
+
queryKey: arbiQueryKeys.projectUsage(id, monthsBack),
|
|
823
|
+
queryFn: () => arbi.projects.usage(id, monthsBack),
|
|
824
|
+
enabled: enabled && !!id
|
|
825
|
+
}))
|
|
826
|
+
});
|
|
827
|
+
const signature = results.map((r) => `${r.status}:${r.dataUpdatedAt ?? 0}`).join("|");
|
|
828
|
+
return React.useMemo(() => {
|
|
829
|
+
const dailyMap = /* @__PURE__ */ new Map();
|
|
830
|
+
const modelMap = /* @__PURE__ */ new Map();
|
|
831
|
+
let totalSpend = 0;
|
|
832
|
+
let totalTokens = 0;
|
|
833
|
+
let totalRequests = 0;
|
|
834
|
+
for (const r of results) {
|
|
835
|
+
const d = r.data;
|
|
836
|
+
if (!d) continue;
|
|
837
|
+
totalSpend += d.total_spend ?? 0;
|
|
838
|
+
totalTokens += d.total_tokens ?? 0;
|
|
839
|
+
totalRequests += d.total_requests ?? 0;
|
|
840
|
+
for (const day of d.daily ?? []) {
|
|
841
|
+
const cur = dailyMap.get(day.date) ?? {
|
|
842
|
+
date: day.date,
|
|
843
|
+
spend: 0,
|
|
844
|
+
totalTokens: 0,
|
|
845
|
+
apiRequests: 0
|
|
846
|
+
};
|
|
847
|
+
cur.spend += day.spend ?? 0;
|
|
848
|
+
cur.totalTokens += day.total_tokens ?? 0;
|
|
849
|
+
cur.apiRequests += day.api_requests ?? 0;
|
|
850
|
+
dailyMap.set(day.date, cur);
|
|
851
|
+
}
|
|
852
|
+
for (const [model, mg] of Object.entries(d.model_groups ?? {})) {
|
|
853
|
+
const cur = modelMap.get(model) ?? {
|
|
854
|
+
model,
|
|
855
|
+
spend: 0,
|
|
856
|
+
totalTokens: 0,
|
|
857
|
+
promptTokens: 0,
|
|
858
|
+
completionTokens: 0,
|
|
859
|
+
successfulRequests: 0
|
|
860
|
+
};
|
|
861
|
+
cur.spend += mg.spend ?? 0;
|
|
862
|
+
cur.totalTokens += mg.total_tokens ?? 0;
|
|
863
|
+
cur.promptTokens += mg.prompt_tokens ?? 0;
|
|
864
|
+
cur.completionTokens += mg.completion_tokens ?? 0;
|
|
865
|
+
cur.successfulRequests += mg.successful_requests ?? 0;
|
|
866
|
+
modelMap.set(model, cur);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
return {
|
|
870
|
+
totalSpend,
|
|
871
|
+
totalTokens,
|
|
872
|
+
totalRequests,
|
|
873
|
+
daily: [...dailyMap.values()].sort((a, b) => a.date.localeCompare(b.date)),
|
|
874
|
+
modelGroups: [...modelMap.values()].sort(
|
|
875
|
+
(a, b) => b.spend - a.spend || b.totalTokens - a.totalTokens
|
|
876
|
+
),
|
|
877
|
+
isLoading: results.some((r) => r.isLoading),
|
|
878
|
+
isError: results.some((r) => r.isError)
|
|
879
|
+
};
|
|
880
|
+
}, [signature]);
|
|
881
|
+
}
|
|
882
|
+
function useProjectInvoices(projectExtId, options) {
|
|
883
|
+
const arbi = useArbi();
|
|
884
|
+
return reactQuery.useQuery({
|
|
885
|
+
queryKey: arbiQueryKeys.projectInvoices(projectExtId ?? ""),
|
|
886
|
+
queryFn: () => arbi.projects.invoices(projectExtId),
|
|
887
|
+
enabled: (options?.enabled ?? true) && !!projectExtId && arbi.isLoggedIn
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
function useUserUsageToday(options) {
|
|
891
|
+
const arbi = useArbi();
|
|
892
|
+
return reactQuery.useQuery({
|
|
893
|
+
queryKey: arbiQueryKeys.userUsageToday(),
|
|
894
|
+
queryFn: () => arbi.user.usageToday(),
|
|
895
|
+
enabled: options?.enabled ?? arbi.isLoggedIn
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
function useWorkspaceChronology(workspaceId, options) {
|
|
899
|
+
const arbi = useArbi();
|
|
900
|
+
return reactQuery.useQuery({
|
|
901
|
+
queryKey: arbiQueryKeys.workspaceChronology(workspaceId ?? ""),
|
|
902
|
+
queryFn: () => arbi.workspaces.chronology(workspaceId),
|
|
903
|
+
enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace
|
|
904
|
+
});
|
|
905
|
+
}
|
|
785
906
|
function WorkspaceScreen({ theme, labels, onSelect }) {
|
|
786
907
|
const arbi = useArbi();
|
|
787
908
|
const { data: workspaces, isLoading } = useWorkspaces();
|
|
@@ -5166,6 +5287,1507 @@ var UserEntity = React.memo(function UserEntity2({
|
|
|
5166
5287
|
}
|
|
5167
5288
|
return avatarElement;
|
|
5168
5289
|
});
|
|
5290
|
+
var ENTITY_MAPPINGS = {
|
|
5291
|
+
PRODUCT: {
|
|
5292
|
+
NAMES: {
|
|
5293
|
+
SINGULAR: "ARBI Docs"
|
|
5294
|
+
},
|
|
5295
|
+
ICONS: {
|
|
5296
|
+
DEFAULT: lucideReact.MessageSquareLock
|
|
5297
|
+
}
|
|
5298
|
+
},
|
|
5299
|
+
SECTION: {
|
|
5300
|
+
NAMES: {
|
|
5301
|
+
SINGULAR: "Section"
|
|
5302
|
+
},
|
|
5303
|
+
ICONS: {
|
|
5304
|
+
DEFAULT: lucideReact.ChevronsDown
|
|
5305
|
+
}
|
|
5306
|
+
},
|
|
5307
|
+
WORKSPACE: {
|
|
5308
|
+
NAMES: {
|
|
5309
|
+
SINGULAR: "Workspace",
|
|
5310
|
+
PLURAL: "Workspaces"
|
|
5311
|
+
},
|
|
5312
|
+
ICONS: {
|
|
5313
|
+
DEFAULT: lucideReact.SquareM,
|
|
5314
|
+
NEW: lucideReact.SquarePlus,
|
|
5315
|
+
LIST: lucideReact.LayoutGrid,
|
|
5316
|
+
SETTINGS: lucideReact.Columns3Cog
|
|
5317
|
+
}
|
|
5318
|
+
},
|
|
5319
|
+
CONVERSATION: {
|
|
5320
|
+
NAMES: {
|
|
5321
|
+
SINGULAR: "Chat",
|
|
5322
|
+
PLURAL: "Chats",
|
|
5323
|
+
NEW: "New ARBI Chat"
|
|
5324
|
+
},
|
|
5325
|
+
ICONS: {
|
|
5326
|
+
DEFAULT: lucideReact.MessagesSquare,
|
|
5327
|
+
OFF: lucideReact.MessageSquareOff,
|
|
5328
|
+
ACTIVE: lucideReact.MessageSquareText,
|
|
5329
|
+
NEW: lucideReact.MessageSquarePlus,
|
|
5330
|
+
LIST: lucideReact.MessageSquareMore
|
|
5331
|
+
}
|
|
5332
|
+
},
|
|
5333
|
+
DOCUMENT: {
|
|
5334
|
+
NAMES: {
|
|
5335
|
+
SINGULAR: "File",
|
|
5336
|
+
PLURAL: "Files"
|
|
5337
|
+
},
|
|
5338
|
+
ICONS: {
|
|
5339
|
+
DEFAULT: lucideReact.FolderOpen,
|
|
5340
|
+
OFF: lucideReact.CaptionsOff
|
|
5341
|
+
}
|
|
5342
|
+
},
|
|
5343
|
+
VIEWER: {
|
|
5344
|
+
NAMES: {
|
|
5345
|
+
SINGULAR: "Viewer",
|
|
5346
|
+
PLURAL: "Viewers"
|
|
5347
|
+
},
|
|
5348
|
+
ICONS: {
|
|
5349
|
+
DEFAULT: lucideReact.Eye,
|
|
5350
|
+
OFF: lucideReact.EyeOff
|
|
5351
|
+
}
|
|
5352
|
+
},
|
|
5353
|
+
TAG: {
|
|
5354
|
+
NAMES: {
|
|
5355
|
+
SINGULAR: "Field",
|
|
5356
|
+
PLURAL: "Fields"
|
|
5357
|
+
},
|
|
5358
|
+
ICONS: {
|
|
5359
|
+
DEFAULT: lucideReact.Hash,
|
|
5360
|
+
NEW: lucideReact.FolderPlus
|
|
5361
|
+
}
|
|
5362
|
+
},
|
|
5363
|
+
ANNOTATION: {
|
|
5364
|
+
NAMES: {
|
|
5365
|
+
SINGULAR: "Annotation",
|
|
5366
|
+
PLURAL: "Annotations"
|
|
5367
|
+
},
|
|
5368
|
+
ICONS: {
|
|
5369
|
+
DEFAULT: lucideReact.StickyNote,
|
|
5370
|
+
NEW: lucideReact.StickyNote
|
|
5371
|
+
}
|
|
5372
|
+
},
|
|
5373
|
+
USER: {
|
|
5374
|
+
NAMES: {
|
|
5375
|
+
SINGULAR: "User",
|
|
5376
|
+
PLURAL: "Users"
|
|
5377
|
+
},
|
|
5378
|
+
ICONS: {
|
|
5379
|
+
DEFAULT: lucideReact.User,
|
|
5380
|
+
NEW: lucideReact.UserPlus,
|
|
5381
|
+
SETTINGS: lucideReact.Settings2
|
|
5382
|
+
}
|
|
5383
|
+
},
|
|
5384
|
+
WORKSPACEUSER: {
|
|
5385
|
+
NAMES: {
|
|
5386
|
+
SINGULAR: "Member",
|
|
5387
|
+
PLURAL: "Members"
|
|
5388
|
+
},
|
|
5389
|
+
ICONS: {
|
|
5390
|
+
DEFAULT: lucideReact.User,
|
|
5391
|
+
PLURAL: lucideReact.Users,
|
|
5392
|
+
NEW: lucideReact.UserPlus,
|
|
5393
|
+
SETTINGS: lucideReact.Settings2
|
|
5394
|
+
}
|
|
5395
|
+
},
|
|
5396
|
+
CONTACT: {
|
|
5397
|
+
NAMES: {
|
|
5398
|
+
SINGULAR: "Contact",
|
|
5399
|
+
PLURAL: "Contacts"
|
|
5400
|
+
},
|
|
5401
|
+
ICONS: {
|
|
5402
|
+
DEFAULT: lucideReact.Contact,
|
|
5403
|
+
NEW: lucideReact.UserPlus
|
|
5404
|
+
}
|
|
5405
|
+
},
|
|
5406
|
+
TASK: {
|
|
5407
|
+
NAMES: {
|
|
5408
|
+
SINGULAR: "Job",
|
|
5409
|
+
PLURAL: "Jobs"
|
|
5410
|
+
},
|
|
5411
|
+
ICONS: {
|
|
5412
|
+
DEFAULT: lucideReact.ClipboardList
|
|
5413
|
+
}
|
|
5414
|
+
},
|
|
5415
|
+
PROJECT: {
|
|
5416
|
+
NAMES: {
|
|
5417
|
+
SINGULAR: "Project",
|
|
5418
|
+
PLURAL: "Projects"
|
|
5419
|
+
},
|
|
5420
|
+
ICONS: {
|
|
5421
|
+
DEFAULT: lucideReact.Package
|
|
5422
|
+
}
|
|
5423
|
+
},
|
|
5424
|
+
SKILL: {
|
|
5425
|
+
NAMES: {
|
|
5426
|
+
SINGULAR: "Skill",
|
|
5427
|
+
PLURAL: "Skills"
|
|
5428
|
+
},
|
|
5429
|
+
ICONS: {
|
|
5430
|
+
DEFAULT: lucideReact.Wrench
|
|
5431
|
+
}
|
|
5432
|
+
},
|
|
5433
|
+
ACCOUNT: {
|
|
5434
|
+
NAMES: {
|
|
5435
|
+
SINGULAR: "Account"
|
|
5436
|
+
},
|
|
5437
|
+
ICONS: {
|
|
5438
|
+
DEFAULT: lucideReact.CircleUserRound
|
|
5439
|
+
}
|
|
5440
|
+
},
|
|
5441
|
+
NOTIFICATIONS: {
|
|
5442
|
+
NAMES: {
|
|
5443
|
+
SINGULAR: "Activity",
|
|
5444
|
+
PLURAL: "Activities"
|
|
5445
|
+
},
|
|
5446
|
+
ICONS: {
|
|
5447
|
+
DEFAULT: lucideReact.Bell
|
|
5448
|
+
}
|
|
5449
|
+
},
|
|
5450
|
+
MESSAGE: {
|
|
5451
|
+
NAMES: {
|
|
5452
|
+
SINGULAR: "Message",
|
|
5453
|
+
PLURAL: "Messages"
|
|
5454
|
+
},
|
|
5455
|
+
ICONS: {
|
|
5456
|
+
DEFAULT: lucideReact.MessageSquare
|
|
5457
|
+
}
|
|
5458
|
+
},
|
|
5459
|
+
NOTIFICATION: {
|
|
5460
|
+
NAMES: {
|
|
5461
|
+
SINGULAR: "Notification",
|
|
5462
|
+
PLURAL: "Notifications"
|
|
5463
|
+
},
|
|
5464
|
+
ICONS: {
|
|
5465
|
+
DEFAULT: lucideReact.Bell
|
|
5466
|
+
}
|
|
5467
|
+
},
|
|
5468
|
+
APP: {
|
|
5469
|
+
NAMES: {
|
|
5470
|
+
SINGULAR: "Application",
|
|
5471
|
+
PLURAL: "Applications"
|
|
5472
|
+
},
|
|
5473
|
+
ICONS: {
|
|
5474
|
+
DEFAULT: lucideReact.LayoutGrid,
|
|
5475
|
+
HOME: lucideReact.LayoutGrid,
|
|
5476
|
+
LOGOUT: lucideReact.LogOut,
|
|
5477
|
+
UPLOAD: lucideReact.Upload
|
|
5478
|
+
}
|
|
5479
|
+
},
|
|
5480
|
+
HELP: {
|
|
5481
|
+
NAMES: {
|
|
5482
|
+
SINGULAR: "Help",
|
|
5483
|
+
PLURAL: "Help"
|
|
5484
|
+
},
|
|
5485
|
+
ICONS: {
|
|
5486
|
+
DEFAULT: lucideReact.MessageSquareLock,
|
|
5487
|
+
DOCS: lucideReact.BookOpen,
|
|
5488
|
+
FAQ: lucideReact.FileQuestion,
|
|
5489
|
+
ABOUT: lucideReact.Info
|
|
5490
|
+
}
|
|
5491
|
+
},
|
|
5492
|
+
USERSHIELD: {
|
|
5493
|
+
NAMES: {
|
|
5494
|
+
SINGULAR: "User Shield",
|
|
5495
|
+
PLURAL: "User Shields"
|
|
5496
|
+
},
|
|
5497
|
+
ICONS: {
|
|
5498
|
+
DEFAULT: lucideReact.MessageSquareLock
|
|
5499
|
+
}
|
|
5500
|
+
}
|
|
5501
|
+
};
|
|
5502
|
+
function configureEntityRegistry(overrides) {
|
|
5503
|
+
for (const [type, def] of Object.entries(overrides)) {
|
|
5504
|
+
const target = ENTITY_MAPPINGS[type];
|
|
5505
|
+
if (!target) continue;
|
|
5506
|
+
if (def?.NAMES) Object.assign(target.NAMES, def.NAMES);
|
|
5507
|
+
if (def?.ICONS) Object.assign(target.ICONS, def.ICONS);
|
|
5508
|
+
}
|
|
5509
|
+
}
|
|
5510
|
+
var getEntityIcon = (entityType, variant = "DEFAULT") => {
|
|
5511
|
+
const icons = ENTITY_MAPPINGS[entityType]?.ICONS;
|
|
5512
|
+
return icons?.[variant] || icons?.DEFAULT;
|
|
5513
|
+
};
|
|
5514
|
+
var getEntityLabel = (entityType, form = "SINGULAR") => {
|
|
5515
|
+
const entityMapping = ENTITY_MAPPINGS[entityType];
|
|
5516
|
+
if (!entityMapping) return "";
|
|
5517
|
+
const names = entityMapping.NAMES;
|
|
5518
|
+
const singularName = names.SINGULAR || "";
|
|
5519
|
+
if (form === "NEW") return names.NEW !== void 0 ? names.NEW : "New " + singularName;
|
|
5520
|
+
if (form === "SHORT")
|
|
5521
|
+
return names.SHORT !== void 0 ? names.SHORT : singularName.substring(0, 3) + ".";
|
|
5522
|
+
if (form === "PLURAL") return names.PLURAL !== void 0 ? names.PLURAL : singularName + "s";
|
|
5523
|
+
return singularName;
|
|
5524
|
+
};
|
|
5525
|
+
var EntityIcon = ({ entityType, variant = "DEFAULT", ...props }) => {
|
|
5526
|
+
const IconComponent = getEntityIcon(entityType, variant);
|
|
5527
|
+
return IconComponent ? React__namespace.default.createElement(IconComponent, props) : null;
|
|
5528
|
+
};
|
|
5529
|
+
var VISIBILITY_ICONS = {
|
|
5530
|
+
PRIVATE: lucideReact.MessageSquareLock,
|
|
5531
|
+
SHARED: lucideReact.Users
|
|
5532
|
+
};
|
|
5533
|
+
var VisibilityIcon = ({
|
|
5534
|
+
isShared,
|
|
5535
|
+
...props
|
|
5536
|
+
}) => {
|
|
5537
|
+
const IconComponent = isShared ? VISIBILITY_ICONS.SHARED : VISIBILITY_ICONS.PRIVATE;
|
|
5538
|
+
return React__namespace.default.createElement(IconComponent, props);
|
|
5539
|
+
};
|
|
5540
|
+
|
|
5541
|
+
// src/entities/colors.ts
|
|
5542
|
+
var OPACITY_LIGHT = 0.15;
|
|
5543
|
+
var OPACITY_MEDIUM = 1;
|
|
5544
|
+
var OPACITY_BORDER = 0.3;
|
|
5545
|
+
var PLACEHOLDER_COLOR = "#9ca3af";
|
|
5546
|
+
var NEUTRAL_GRAY2 = "#64748b";
|
|
5547
|
+
var BASE_COLORS2 = {
|
|
5548
|
+
"0": "#10b981",
|
|
5549
|
+
"1": "#3b82f6",
|
|
5550
|
+
"2": "#8b5cf6",
|
|
5551
|
+
"3": "#f43f5e",
|
|
5552
|
+
"4": "#f59e0b",
|
|
5553
|
+
"5": "#84cc16",
|
|
5554
|
+
"6": "#a855f7",
|
|
5555
|
+
"7": "#06b6d4",
|
|
5556
|
+
"8": "#f97316",
|
|
5557
|
+
"9": "#14b8a6",
|
|
5558
|
+
a: "#ef4444",
|
|
5559
|
+
b: "#6366f1",
|
|
5560
|
+
c: "#ec4899",
|
|
5561
|
+
d: "#22c55e",
|
|
5562
|
+
e: "#eab308",
|
|
5563
|
+
f: "#0ea5e9"
|
|
5564
|
+
};
|
|
5565
|
+
function hexToRgba(hex, opacity) {
|
|
5566
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
5567
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
5568
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
5569
|
+
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
|
5570
|
+
}
|
|
5571
|
+
function getEntityColor2(entityId, variant = "medium") {
|
|
5572
|
+
const baseColor = BASE_COLORS2[entityId[4]] || BASE_COLORS2["0"];
|
|
5573
|
+
switch (variant) {
|
|
5574
|
+
case "light":
|
|
5575
|
+
return hexToRgba(baseColor, OPACITY_LIGHT);
|
|
5576
|
+
case "medium":
|
|
5577
|
+
return hexToRgba(baseColor, OPACITY_MEDIUM);
|
|
5578
|
+
case "text":
|
|
5579
|
+
return baseColor;
|
|
5580
|
+
}
|
|
5581
|
+
}
|
|
5582
|
+
function getEntityColorStyles(entityId) {
|
|
5583
|
+
const baseColor = BASE_COLORS2[entityId[4]] || BASE_COLORS2["0"];
|
|
5584
|
+
return {
|
|
5585
|
+
backgroundColor: getEntityColor2(entityId, "light"),
|
|
5586
|
+
color: baseColor,
|
|
5587
|
+
borderColor: hexToRgba(baseColor, OPACITY_BORDER)
|
|
5588
|
+
};
|
|
5589
|
+
}
|
|
5590
|
+
var getWorkspaceColor = (workspaceId, useWorkspaceColors) => {
|
|
5591
|
+
const shouldUseWorkspaceColors = useWorkspaceColors !== void 0 ? useWorkspaceColors : true;
|
|
5592
|
+
if (!shouldUseWorkspaceColors) return "hsl(var(--primary))";
|
|
5593
|
+
const isValidId = workspaceId && workspaceId.startsWith("wrk-") && workspaceId.length >= 5;
|
|
5594
|
+
if (!isValidId) return "hsl(var(--primary))";
|
|
5595
|
+
return getEntityColor2(workspaceId, "medium");
|
|
5596
|
+
};
|
|
5597
|
+
function getNotificationTypeMeta(type) {
|
|
5598
|
+
const WorkspaceIcon = getEntityIcon("WORKSPACE");
|
|
5599
|
+
switch (type) {
|
|
5600
|
+
case "user_message":
|
|
5601
|
+
return { Icon: lucideReact.MessageCircleMore, iconClassName: "text-primary", label: "Message" };
|
|
5602
|
+
case "workspaceuser_added_owner":
|
|
5603
|
+
case "workspaceuser_added_collaborator":
|
|
5604
|
+
case "workspaceuser_added_guest":
|
|
5605
|
+
return { Icon: WorkspaceIcon, iconClassName: "text-primary", label: "Added" };
|
|
5606
|
+
case "workspaceuser_removed":
|
|
5607
|
+
return { Icon: WorkspaceIcon, iconClassName: "text-primary", label: "Removed" };
|
|
5608
|
+
case "workspaceuser_updated_owner":
|
|
5609
|
+
case "workspaceuser_updated_collaborator":
|
|
5610
|
+
case "workspaceuser_updated_guest":
|
|
5611
|
+
return { Icon: WorkspaceIcon, iconClassName: "text-primary", label: "Role changed" };
|
|
5612
|
+
case "contact_accepted":
|
|
5613
|
+
return { Icon: lucideReact.UserCheck, iconClassName: "text-green-500", label: "Invitation" };
|
|
5614
|
+
case "signup_reward":
|
|
5615
|
+
return { Icon: lucideReact.PartyPopper, iconClassName: "text-green-600", label: "Signup bonus" };
|
|
5616
|
+
case "referral_reward":
|
|
5617
|
+
return { Icon: lucideReact.Gift, iconClassName: "text-green-600", label: "Reward earned" };
|
|
5618
|
+
case "quota_threshold_50":
|
|
5619
|
+
return { Icon: lucideReact.Gauge, iconClassName: "text-blue-500", label: "Usage 50%" };
|
|
5620
|
+
case "quota_threshold_90":
|
|
5621
|
+
return { Icon: lucideReact.Gauge, iconClassName: "text-orange-500", label: "Usage 90%" };
|
|
5622
|
+
case "quota_threshold_100":
|
|
5623
|
+
return { Icon: lucideReact.Gauge, iconClassName: "text-red-500", label: "Usage limit" };
|
|
5624
|
+
case "activity":
|
|
5625
|
+
return { Icon: lucideReact.Activity, iconClassName: "text-muted-foreground", label: "Activity" };
|
|
5626
|
+
default:
|
|
5627
|
+
return { Icon: lucideReact.Info, iconClassName: "text-blue-500", label: type || "Notification" };
|
|
5628
|
+
}
|
|
5629
|
+
}
|
|
5630
|
+
function isWorkspaceNotificationType(type) {
|
|
5631
|
+
return type.startsWith("workspaceuser_");
|
|
5632
|
+
}
|
|
5633
|
+
function getWorkspaceActionText(type) {
|
|
5634
|
+
switch (type) {
|
|
5635
|
+
case "workspaceuser_added_owner":
|
|
5636
|
+
return "added you as owner";
|
|
5637
|
+
case "workspaceuser_added_collaborator":
|
|
5638
|
+
return "added you as collaborator";
|
|
5639
|
+
case "workspaceuser_added_guest":
|
|
5640
|
+
return "added you as guest";
|
|
5641
|
+
case "workspaceuser_removed":
|
|
5642
|
+
return "removed you";
|
|
5643
|
+
case "workspaceuser_updated_owner":
|
|
5644
|
+
return "changed your role to owner";
|
|
5645
|
+
case "workspaceuser_updated_collaborator":
|
|
5646
|
+
return "changed your role to collaborator";
|
|
5647
|
+
case "workspaceuser_updated_guest":
|
|
5648
|
+
return "changed your role to guest";
|
|
5649
|
+
default:
|
|
5650
|
+
return "updated your access";
|
|
5651
|
+
}
|
|
5652
|
+
}
|
|
5653
|
+
function getWorkspaceSentPhrase(type) {
|
|
5654
|
+
switch (type) {
|
|
5655
|
+
case "workspaceuser_added_owner":
|
|
5656
|
+
return { before: "You added", after: "as owner" };
|
|
5657
|
+
case "workspaceuser_added_collaborator":
|
|
5658
|
+
return { before: "You added", after: "as collaborator" };
|
|
5659
|
+
case "workspaceuser_added_guest":
|
|
5660
|
+
return { before: "You added", after: "as guest" };
|
|
5661
|
+
case "workspaceuser_removed":
|
|
5662
|
+
return { before: "You removed", after: "" };
|
|
5663
|
+
case "workspaceuser_updated_owner":
|
|
5664
|
+
return { before: "You set", after: "as owner" };
|
|
5665
|
+
case "workspaceuser_updated_collaborator":
|
|
5666
|
+
return { before: "You set", after: "as collaborator" };
|
|
5667
|
+
case "workspaceuser_updated_guest":
|
|
5668
|
+
return { before: "You set", after: "as guest" };
|
|
5669
|
+
default:
|
|
5670
|
+
return { before: "You updated access for", after: "" };
|
|
5671
|
+
}
|
|
5672
|
+
}
|
|
5673
|
+
function parseActivityContent(content) {
|
|
5674
|
+
if (!content) return null;
|
|
5675
|
+
try {
|
|
5676
|
+
const parsed = JSON.parse(content);
|
|
5677
|
+
if (parsed && typeof parsed === "object" && typeof parsed.event === "string") {
|
|
5678
|
+
return parsed;
|
|
5679
|
+
}
|
|
5680
|
+
} catch {
|
|
5681
|
+
}
|
|
5682
|
+
return null;
|
|
5683
|
+
}
|
|
5684
|
+
function str(v) {
|
|
5685
|
+
return typeof v === "string" && v ? v : void 0;
|
|
5686
|
+
}
|
|
5687
|
+
function describeActivity(content) {
|
|
5688
|
+
const parsed = typeof content === "string" || content == null ? parseActivityContent(content) : content;
|
|
5689
|
+
if (!parsed) {
|
|
5690
|
+
return { Icon: lucideReact.Activity, iconClassName: "text-muted-foreground", title: "Activity" };
|
|
5691
|
+
}
|
|
5692
|
+
const fileName = str(parsed.file_name);
|
|
5693
|
+
switch (parsed.event) {
|
|
5694
|
+
case "workspace_opened":
|
|
5695
|
+
return {
|
|
5696
|
+
Icon: lucideReact.SquareArrowOutUpRight,
|
|
5697
|
+
iconClassName: "text-primary",
|
|
5698
|
+
title: "Opened a workspace"
|
|
5699
|
+
};
|
|
5700
|
+
case "workspace_created":
|
|
5701
|
+
return { Icon: lucideReact.FolderPlus, iconClassName: "text-green-600", title: "Created a workspace" };
|
|
5702
|
+
case "workspace_updated":
|
|
5703
|
+
return { Icon: lucideReact.Pencil, iconClassName: "text-primary", title: "Updated workspace settings" };
|
|
5704
|
+
case "workspace_deleted":
|
|
5705
|
+
return { Icon: lucideReact.Trash2, iconClassName: "text-red-500", title: "Deleted a workspace" };
|
|
5706
|
+
case "document_processing": {
|
|
5707
|
+
const failed = str(parsed.status) === "failed";
|
|
5708
|
+
const noun = fileName ? `\u201C${fileName}\u201D` : "a document";
|
|
5709
|
+
return failed ? { Icon: lucideReact.FileX2, iconClassName: "text-red-500", title: `Failed to process ${noun}` } : { Icon: lucideReact.FileCheck2, iconClassName: "text-green-600", title: `Processed ${noun}` };
|
|
5710
|
+
}
|
|
5711
|
+
default:
|
|
5712
|
+
return {
|
|
5713
|
+
Icon: parsed.workspace_ext_id ? getEntityIcon("WORKSPACE") : lucideReact.Activity,
|
|
5714
|
+
iconClassName: "text-muted-foreground",
|
|
5715
|
+
title: humaniseEvent(parsed.event)
|
|
5716
|
+
};
|
|
5717
|
+
}
|
|
5718
|
+
}
|
|
5719
|
+
function humaniseEvent(event) {
|
|
5720
|
+
const words = event.replace(/[_-]+/g, " ").trim();
|
|
5721
|
+
return words ? words.charAt(0).toUpperCase() + words.slice(1) : "Activity";
|
|
5722
|
+
}
|
|
5723
|
+
function formatRelative(iso) {
|
|
5724
|
+
const then = new Date(iso).getTime();
|
|
5725
|
+
if (Number.isNaN(then)) return "";
|
|
5726
|
+
const secs = Math.round((Date.now() - then) / 1e3);
|
|
5727
|
+
if (secs < 45) return "just now";
|
|
5728
|
+
const mins = Math.round(secs / 60);
|
|
5729
|
+
if (mins < 60) return `${mins}m`;
|
|
5730
|
+
const hours = Math.round(mins / 60);
|
|
5731
|
+
if (hours < 24) return `${hours}h`;
|
|
5732
|
+
const days = Math.round(hours / 24);
|
|
5733
|
+
if (days < 7) return `${days}d`;
|
|
5734
|
+
return new Date(iso).toLocaleDateString();
|
|
5735
|
+
}
|
|
5736
|
+
function ActivityFeed({
|
|
5737
|
+
limit = 20,
|
|
5738
|
+
className,
|
|
5739
|
+
emptyLabel = "No recent activity",
|
|
5740
|
+
enabled,
|
|
5741
|
+
"data-testid": testId = "activity-feed"
|
|
5742
|
+
}) {
|
|
5743
|
+
const { data, isLoading, isError } = useActivity({ limit, enabled });
|
|
5744
|
+
if (isLoading) {
|
|
5745
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("space-y-2", className), "data-testid": testId, "aria-busy": "true", children: Array.from({ length: 3 }).map((_, i) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3 py-1.5", children: [
|
|
5746
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-4 w-4 shrink-0 animate-pulse rounded-full bg-muted" }),
|
|
5747
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-3 flex-1 animate-pulse rounded bg-muted" })
|
|
5748
|
+
] }, i)) });
|
|
5749
|
+
}
|
|
5750
|
+
if (isError) {
|
|
5751
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("text-sm text-muted-foreground", className), "data-testid": testId, children: "Couldn\u2019t load activity." });
|
|
5752
|
+
}
|
|
5753
|
+
const items = data ?? [];
|
|
5754
|
+
if (items.length === 0) {
|
|
5755
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
5756
|
+
"div",
|
|
5757
|
+
{
|
|
5758
|
+
className: cn("flex items-center gap-2 text-sm text-muted-foreground", className),
|
|
5759
|
+
"data-testid": testId,
|
|
5760
|
+
children: [
|
|
5761
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Activity, { className: "h-4 w-4 shrink-0" }),
|
|
5762
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: emptyLabel })
|
|
5763
|
+
]
|
|
5764
|
+
}
|
|
5765
|
+
);
|
|
5766
|
+
}
|
|
5767
|
+
return /* @__PURE__ */ jsxRuntime.jsx("ul", { className: cn("divide-y divide-border", className), "data-testid": testId, children: items.map((item) => {
|
|
5768
|
+
const desc = describeActivity(item.content);
|
|
5769
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
5770
|
+
"li",
|
|
5771
|
+
{
|
|
5772
|
+
className: "flex items-center gap-3 py-2",
|
|
5773
|
+
"data-testid": "activity-feed-item",
|
|
5774
|
+
children: [
|
|
5775
|
+
/* @__PURE__ */ jsxRuntime.jsx(desc.Icon, { className: cn("h-4 w-4 shrink-0", desc.iconClassName) }),
|
|
5776
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "min-w-0 flex-1 truncate text-sm text-foreground", children: desc.title }),
|
|
5777
|
+
/* @__PURE__ */ jsxRuntime.jsx("time", { className: "shrink-0 text-xs tabular-nums text-muted-foreground", children: formatRelative(item.created_at) })
|
|
5778
|
+
]
|
|
5779
|
+
},
|
|
5780
|
+
item.external_id
|
|
5781
|
+
);
|
|
5782
|
+
}) });
|
|
5783
|
+
}
|
|
5784
|
+
var seq = 0;
|
|
5785
|
+
var uid = () => `n${Date.now().toString(36)}${(seq++).toString(36)}`;
|
|
5786
|
+
var useNotify = zustand.create((set) => ({
|
|
5787
|
+
toasts: [],
|
|
5788
|
+
notifications: [],
|
|
5789
|
+
push: (variant, title, opts = {}) => {
|
|
5790
|
+
const id = uid();
|
|
5791
|
+
const duration = opts.duration ?? (variant === "error" ? 7e3 : 4500);
|
|
5792
|
+
set((s) => {
|
|
5793
|
+
const toast = { id, title, description: opts.description, variant, duration };
|
|
5794
|
+
const next = { toasts: [...s.toasts, toast] };
|
|
5795
|
+
if (opts.record !== false) {
|
|
5796
|
+
const note = {
|
|
5797
|
+
id,
|
|
5798
|
+
title,
|
|
5799
|
+
description: opts.description,
|
|
5800
|
+
variant,
|
|
5801
|
+
ts: Date.now(),
|
|
5802
|
+
read: false,
|
|
5803
|
+
href: opts.href
|
|
5804
|
+
};
|
|
5805
|
+
next.notifications = [note, ...s.notifications].slice(0, 50);
|
|
5806
|
+
}
|
|
5807
|
+
return next;
|
|
5808
|
+
});
|
|
5809
|
+
return id;
|
|
5810
|
+
},
|
|
5811
|
+
dismiss: (id) => set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) })),
|
|
5812
|
+
markRead: (id) => set((s) => ({
|
|
5813
|
+
notifications: s.notifications.map((n) => n.id === id ? { ...n, read: true } : n)
|
|
5814
|
+
})),
|
|
5815
|
+
markAllRead: () => set((s) => ({ notifications: s.notifications.map((n) => ({ ...n, read: true })) })),
|
|
5816
|
+
removeNotification: (id) => set((s) => ({ notifications: s.notifications.filter((n) => n.id !== id) })),
|
|
5817
|
+
clearNotifications: () => set({ notifications: [] }),
|
|
5818
|
+
seed: (items) => set({ notifications: items })
|
|
5819
|
+
}));
|
|
5820
|
+
function make(variant) {
|
|
5821
|
+
return (title, opts) => useNotify.getState().push(variant, title, opts);
|
|
5822
|
+
}
|
|
5823
|
+
var notify = {
|
|
5824
|
+
success: make("success"),
|
|
5825
|
+
error: make("error"),
|
|
5826
|
+
info: make("info"),
|
|
5827
|
+
warning: make("warning")
|
|
5828
|
+
};
|
|
5829
|
+
function seedNotifications(items) {
|
|
5830
|
+
useNotify.getState().seed(items);
|
|
5831
|
+
}
|
|
5832
|
+
var selectUnread = (s) => s.notifications.filter((n) => !n.read).length;
|
|
5833
|
+
var DEFAULT_NOTIFY_TONE = {
|
|
5834
|
+
success: "text-green-600",
|
|
5835
|
+
error: "text-destructive",
|
|
5836
|
+
warning: "text-amber-500",
|
|
5837
|
+
info: "text-blue-500"
|
|
5838
|
+
};
|
|
5839
|
+
|
|
5840
|
+
// src/directmessages/utils.ts
|
|
5841
|
+
function userInitials(user) {
|
|
5842
|
+
const parts = [user.given_name, user.family_name].filter(Boolean);
|
|
5843
|
+
if (parts.length) {
|
|
5844
|
+
return parts.map((p) => p[0]?.toUpperCase() ?? "").join("").slice(0, 2);
|
|
5845
|
+
}
|
|
5846
|
+
const local = user.email?.split("@")[0] ?? "";
|
|
5847
|
+
return local.slice(0, 2).toUpperCase() || "?";
|
|
5848
|
+
}
|
|
5849
|
+
function userDisplayName(user) {
|
|
5850
|
+
const name = [user.given_name, user.family_name].filter(Boolean).join(" ").trim();
|
|
5851
|
+
return name || user.email?.split("@")[0] || "Unknown";
|
|
5852
|
+
}
|
|
5853
|
+
var RELATIVE = new Intl.RelativeTimeFormat(void 0, { numeric: "auto" });
|
|
5854
|
+
var DIVISIONS = [
|
|
5855
|
+
{ amount: 60, unit: "seconds" },
|
|
5856
|
+
{ amount: 60, unit: "minutes" },
|
|
5857
|
+
{ amount: 24, unit: "hours" },
|
|
5858
|
+
{ amount: 7, unit: "days" },
|
|
5859
|
+
{ amount: 4.34524, unit: "weeks" },
|
|
5860
|
+
{ amount: 12, unit: "months" },
|
|
5861
|
+
{ amount: Number.POSITIVE_INFINITY, unit: "years" }
|
|
5862
|
+
];
|
|
5863
|
+
function formatRelativeTime(iso) {
|
|
5864
|
+
const then = Date.parse(iso);
|
|
5865
|
+
if (Number.isNaN(then)) return "";
|
|
5866
|
+
let duration = (then - Date.now()) / 1e3;
|
|
5867
|
+
if (Math.abs(duration) < 45) return "just now";
|
|
5868
|
+
for (const division of DIVISIONS) {
|
|
5869
|
+
if (Math.abs(duration) < division.amount) {
|
|
5870
|
+
return RELATIVE.format(Math.round(duration), division.unit);
|
|
5871
|
+
}
|
|
5872
|
+
duration /= division.amount;
|
|
5873
|
+
}
|
|
5874
|
+
return "";
|
|
5875
|
+
}
|
|
5876
|
+
var GLYPH = {
|
|
5877
|
+
success: lucideReact.CheckCircle2,
|
|
5878
|
+
error: lucideReact.XCircle,
|
|
5879
|
+
warning: lucideReact.AlertTriangle,
|
|
5880
|
+
info: lucideReact.Info
|
|
5881
|
+
};
|
|
5882
|
+
function NotificationBell({
|
|
5883
|
+
onNavigate,
|
|
5884
|
+
toneClassNames,
|
|
5885
|
+
emptyText = "You're all caught up.",
|
|
5886
|
+
testId = "notifications"
|
|
5887
|
+
}) {
|
|
5888
|
+
const notifications = useNotify((s) => s.notifications);
|
|
5889
|
+
const unread = useNotify(selectUnread);
|
|
5890
|
+
const markAllRead = useNotify((s) => s.markAllRead);
|
|
5891
|
+
const markRead = useNotify((s) => s.markRead);
|
|
5892
|
+
const tone = (v) => toneClassNames?.[v] ?? DEFAULT_NOTIFY_TONE[v];
|
|
5893
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { children: [
|
|
5894
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
5895
|
+
"button",
|
|
5896
|
+
{
|
|
5897
|
+
className: "relative flex size-9 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",
|
|
5898
|
+
"data-testid": testId,
|
|
5899
|
+
"aria-label": `Notifications${unread ? ` (${unread} unread)` : ""}`,
|
|
5900
|
+
children: [
|
|
5901
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Bell, { className: "size-5" }),
|
|
5902
|
+
unread > 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
5903
|
+
"span",
|
|
5904
|
+
{
|
|
5905
|
+
className: "absolute -right-0.5 -top-0.5 flex min-w-4 items-center justify-center rounded-full bg-destructive px-1 text-[10px] font-semibold leading-4 text-white",
|
|
5906
|
+
"data-testid": `${testId}-badge`,
|
|
5907
|
+
children: unread > 9 ? "9+" : unread
|
|
5908
|
+
}
|
|
5909
|
+
)
|
|
5910
|
+
]
|
|
5911
|
+
}
|
|
5912
|
+
) }),
|
|
5913
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuContent, { align: "end", className: "w-[360px] p-0", "data-testid": `${testId}-panel`, children: [
|
|
5914
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between border-b border-border px-3.5 py-2.5", children: [
|
|
5915
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-semibold text-foreground", children: "Notifications" }),
|
|
5916
|
+
unread > 0 && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
5917
|
+
"button",
|
|
5918
|
+
{
|
|
5919
|
+
onClick: markAllRead,
|
|
5920
|
+
className: "flex items-center gap-1 text-xs font-medium text-primary transition-colors hover:opacity-80",
|
|
5921
|
+
"data-testid": `${testId}-mark-all`,
|
|
5922
|
+
children: [
|
|
5923
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.CheckCheck, { className: "size-3.5" }),
|
|
5924
|
+
" Mark all read"
|
|
5925
|
+
]
|
|
5926
|
+
}
|
|
5927
|
+
)
|
|
5928
|
+
] }),
|
|
5929
|
+
notifications.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-3.5 py-10 text-center text-sm text-muted-foreground", children: emptyText }) : /* @__PURE__ */ jsxRuntime.jsx(ScrollArea, { className: "max-h-[380px]", children: /* @__PURE__ */ jsxRuntime.jsx("ul", { "data-testid": `${testId}-list`, children: notifications.map((n) => {
|
|
5930
|
+
const Glyph = GLYPH[n.variant];
|
|
5931
|
+
return /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
5932
|
+
"button",
|
|
5933
|
+
{
|
|
5934
|
+
onClick: () => {
|
|
5935
|
+
markRead(n.id);
|
|
5936
|
+
if (n.href) onNavigate?.(n.href);
|
|
5937
|
+
},
|
|
5938
|
+
className: cn(
|
|
5939
|
+
"flex w-full items-start gap-3 border-b border-border/60 px-3.5 py-3 text-left transition-colors hover:bg-accent",
|
|
5940
|
+
!n.read && "bg-accent/40"
|
|
5941
|
+
),
|
|
5942
|
+
"data-testid": `${testId}-item`,
|
|
5943
|
+
children: [
|
|
5944
|
+
/* @__PURE__ */ jsxRuntime.jsx(Glyph, { className: cn("mt-0.5 size-4 shrink-0", tone(n.variant)) }),
|
|
5945
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
5946
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium leading-snug text-foreground", children: n.title }),
|
|
5947
|
+
n.description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-0.5 line-clamp-2 text-xs leading-relaxed text-muted-foreground", children: n.description }),
|
|
5948
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-[11px] text-muted-foreground/80", children: formatRelativeTime(new Date(n.ts).toISOString()) })
|
|
5949
|
+
] }),
|
|
5950
|
+
!n.read && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mt-1.5 size-2 shrink-0 rounded-full bg-primary" })
|
|
5951
|
+
]
|
|
5952
|
+
}
|
|
5953
|
+
) }, n.id);
|
|
5954
|
+
}) }) })
|
|
5955
|
+
] })
|
|
5956
|
+
] });
|
|
5957
|
+
}
|
|
5958
|
+
var GLYPH2 = {
|
|
5959
|
+
success: lucideReact.CheckCircle2,
|
|
5960
|
+
error: lucideReact.XCircle,
|
|
5961
|
+
warning: lucideReact.AlertTriangle,
|
|
5962
|
+
info: lucideReact.Info
|
|
5963
|
+
};
|
|
5964
|
+
function Toaster({ className, toneClassNames, testId = "toaster" }) {
|
|
5965
|
+
const toasts = useNotify((s) => s.toasts);
|
|
5966
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
5967
|
+
"div",
|
|
5968
|
+
{
|
|
5969
|
+
className: cn(
|
|
5970
|
+
"pointer-events-none fixed bottom-4 right-4 z-[100] flex w-[min(92vw,380px)] flex-col gap-2.5",
|
|
5971
|
+
className
|
|
5972
|
+
),
|
|
5973
|
+
"data-testid": testId,
|
|
5974
|
+
"aria-live": "polite",
|
|
5975
|
+
"aria-atomic": "false",
|
|
5976
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { initial: false, children: toasts.map((t) => /* @__PURE__ */ jsxRuntime.jsx(ToastCard, { toast: t, toneClassNames }, t.id)) })
|
|
5977
|
+
}
|
|
5978
|
+
);
|
|
5979
|
+
}
|
|
5980
|
+
function ToastCard({
|
|
5981
|
+
toast,
|
|
5982
|
+
toneClassNames
|
|
5983
|
+
}) {
|
|
5984
|
+
const dismiss = useNotify((s) => s.dismiss);
|
|
5985
|
+
const Glyph = GLYPH2[toast.variant];
|
|
5986
|
+
const tone = toneClassNames?.[toast.variant] ?? DEFAULT_NOTIFY_TONE[toast.variant];
|
|
5987
|
+
React.useEffect(() => {
|
|
5988
|
+
if (!toast.duration) return;
|
|
5989
|
+
const timer = setTimeout(() => dismiss(toast.id), toast.duration);
|
|
5990
|
+
return () => clearTimeout(timer);
|
|
5991
|
+
}, [toast.id, toast.duration, dismiss]);
|
|
5992
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
5993
|
+
framerMotion.motion.div,
|
|
5994
|
+
{
|
|
5995
|
+
layout: true,
|
|
5996
|
+
initial: { opacity: 0, y: 16, scale: 0.97 },
|
|
5997
|
+
animate: { opacity: 1, y: 0, scale: 1 },
|
|
5998
|
+
exit: { opacity: 0, x: 24, scale: 0.97, transition: { duration: 0.18 } },
|
|
5999
|
+
transition: { type: "spring", stiffness: 380, damping: 30 },
|
|
6000
|
+
className: "pointer-events-auto flex items-start gap-3 rounded-lg border border-border bg-card p-3.5 shadow-lg",
|
|
6001
|
+
"data-testid": `toast-${toast.variant}`,
|
|
6002
|
+
"data-toast": "",
|
|
6003
|
+
role: toast.variant === "error" ? "alert" : "status",
|
|
6004
|
+
children: [
|
|
6005
|
+
/* @__PURE__ */ jsxRuntime.jsx(Glyph, { className: cn("mt-0.5 size-[18px] shrink-0", tone) }),
|
|
6006
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
6007
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-semibold leading-snug text-foreground", children: toast.title }),
|
|
6008
|
+
toast.description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-0.5 text-xs leading-relaxed text-muted-foreground", children: toast.description })
|
|
6009
|
+
] }),
|
|
6010
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6011
|
+
"button",
|
|
6012
|
+
{
|
|
6013
|
+
onClick: () => dismiss(toast.id),
|
|
6014
|
+
className: "shrink-0 rounded p-0.5 text-muted-foreground/70 transition-colors hover:bg-accent hover:text-foreground",
|
|
6015
|
+
"aria-label": "Dismiss",
|
|
6016
|
+
"data-testid": "toast-dismiss",
|
|
6017
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "size-4" })
|
|
6018
|
+
}
|
|
6019
|
+
)
|
|
6020
|
+
]
|
|
6021
|
+
}
|
|
6022
|
+
);
|
|
6023
|
+
}
|
|
6024
|
+
var DM_QUERY_KEY = ["arbi", "directMessages"];
|
|
6025
|
+
function groupConversations(notifications, myExtId) {
|
|
6026
|
+
const messagesByPeer = /* @__PURE__ */ new Map();
|
|
6027
|
+
const peers = /* @__PURE__ */ new Map();
|
|
6028
|
+
for (const n of notifications) {
|
|
6029
|
+
if (n.type !== "user_message") continue;
|
|
6030
|
+
if (n.sender.external_id === n.recipient.external_id) continue;
|
|
6031
|
+
const isMine = n.sender.external_id === myExtId;
|
|
6032
|
+
const peer = isMine ? n.recipient : n.sender;
|
|
6033
|
+
if (!peer?.external_id) continue;
|
|
6034
|
+
const message = {
|
|
6035
|
+
externalId: n.external_id,
|
|
6036
|
+
body: n.content ?? "",
|
|
6037
|
+
createdAt: n.created_at,
|
|
6038
|
+
isMine,
|
|
6039
|
+
read: n.read,
|
|
6040
|
+
sender: n.sender,
|
|
6041
|
+
recipient: n.recipient
|
|
6042
|
+
};
|
|
6043
|
+
if (!messagesByPeer.has(peer.external_id)) {
|
|
6044
|
+
messagesByPeer.set(peer.external_id, []);
|
|
6045
|
+
peers.set(peer.external_id, peer);
|
|
6046
|
+
}
|
|
6047
|
+
messagesByPeer.get(peer.external_id).push(message);
|
|
6048
|
+
}
|
|
6049
|
+
const conversations = [];
|
|
6050
|
+
for (const [peerId, messages] of messagesByPeer) {
|
|
6051
|
+
messages.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
6052
|
+
const unreadCount = messages.filter((m) => !m.isMine && !m.read).length;
|
|
6053
|
+
conversations.push({
|
|
6054
|
+
peer: peers.get(peerId),
|
|
6055
|
+
messages,
|
|
6056
|
+
lastMessage: messages[messages.length - 1],
|
|
6057
|
+
unreadCount
|
|
6058
|
+
});
|
|
6059
|
+
}
|
|
6060
|
+
conversations.sort((a, b) => b.lastMessage.createdAt.localeCompare(a.lastMessage.createdAt));
|
|
6061
|
+
return conversations;
|
|
6062
|
+
}
|
|
6063
|
+
function useDirectMessages(options) {
|
|
6064
|
+
const arbi = useArbi();
|
|
6065
|
+
const queryClient = reactQuery.useQueryClient();
|
|
6066
|
+
const enabled = options?.enabled ?? arbi.isLoggedIn;
|
|
6067
|
+
const query = reactQuery.useQuery({
|
|
6068
|
+
queryKey: DM_QUERY_KEY,
|
|
6069
|
+
queryFn: () => arbi.dm.list(),
|
|
6070
|
+
enabled
|
|
6071
|
+
});
|
|
6072
|
+
useArbiWsMessage("user_message", () => {
|
|
6073
|
+
queryClient.invalidateQueries({ queryKey: DM_QUERY_KEY });
|
|
6074
|
+
});
|
|
6075
|
+
const myExtId = React.useMemo(() => {
|
|
6076
|
+
try {
|
|
6077
|
+
return arbi.user.identity()?.externalId ?? null;
|
|
6078
|
+
} catch {
|
|
6079
|
+
return null;
|
|
6080
|
+
}
|
|
6081
|
+
}, [arbi, query.data]);
|
|
6082
|
+
const conversations = React.useMemo(
|
|
6083
|
+
() => groupConversations(query.data ?? [], myExtId),
|
|
6084
|
+
[query.data, myExtId]
|
|
6085
|
+
);
|
|
6086
|
+
const invalidate = () => queryClient.invalidateQueries({ queryKey: DM_QUERY_KEY });
|
|
6087
|
+
const sendMutation = reactQuery.useMutation({
|
|
6088
|
+
mutationFn: (vars) => arbi.dm.sendTo(vars.recipientExtId, vars.recipientPublicKey, vars.text),
|
|
6089
|
+
onSuccess: invalidate
|
|
6090
|
+
});
|
|
6091
|
+
const sendToMutation = reactQuery.useMutation({
|
|
6092
|
+
mutationFn: (vars) => arbi.dm.send(vars.recipient, vars.text),
|
|
6093
|
+
onSuccess: invalidate
|
|
6094
|
+
});
|
|
6095
|
+
const markReadMutation = reactQuery.useMutation({
|
|
6096
|
+
mutationFn: (messageIds) => arbi.dm.markRead(messageIds),
|
|
6097
|
+
onSuccess: invalidate
|
|
6098
|
+
});
|
|
6099
|
+
return {
|
|
6100
|
+
conversations,
|
|
6101
|
+
myExtId,
|
|
6102
|
+
isLoading: query.isLoading && enabled,
|
|
6103
|
+
isError: query.isError,
|
|
6104
|
+
error: query.error,
|
|
6105
|
+
refetch: () => query.refetch(),
|
|
6106
|
+
sendMessage: (recipientExtId, recipientPublicKey, text) => sendMutation.mutateAsync({ recipientExtId, recipientPublicKey, text }),
|
|
6107
|
+
sendMessageTo: (recipient, text) => sendToMutation.mutateAsync({ recipient, text }),
|
|
6108
|
+
isSending: sendMutation.isPending || sendToMutation.isPending,
|
|
6109
|
+
markRead: (messageIds) => markReadMutation.mutateAsync(messageIds)
|
|
6110
|
+
};
|
|
6111
|
+
}
|
|
6112
|
+
function DmAvatar({ user, className }) {
|
|
6113
|
+
const name = userDisplayName(user);
|
|
6114
|
+
const tint = getEntityColorStyles(user.external_id);
|
|
6115
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Avatar, { className: cn("size-10", className), children: [
|
|
6116
|
+
user.picture ? /* @__PURE__ */ jsxRuntime.jsx(AvatarImage, { src: user.picture, alt: name }) : null,
|
|
6117
|
+
/* @__PURE__ */ jsxRuntime.jsx(AvatarFallback, { style: tint, className: "text-xs font-semibold", children: userInitials(user) })
|
|
6118
|
+
] });
|
|
6119
|
+
}
|
|
6120
|
+
function ConversationList({
|
|
6121
|
+
conversations,
|
|
6122
|
+
selectedPeerId,
|
|
6123
|
+
onSelect,
|
|
6124
|
+
classNames,
|
|
6125
|
+
emptyState
|
|
6126
|
+
}) {
|
|
6127
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6128
|
+
"aside",
|
|
6129
|
+
{
|
|
6130
|
+
className: "flex min-h-0 flex-col border-b border-border md:w-80 md:shrink-0 md:border-b-0 md:border-r",
|
|
6131
|
+
"data-testid": "arbi-dm-list",
|
|
6132
|
+
children: [
|
|
6133
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "border-b border-border px-4 py-3", children: [
|
|
6134
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-semibold text-foreground", children: "Conversations" }),
|
|
6135
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs text-muted-foreground", children: [
|
|
6136
|
+
conversations.length,
|
|
6137
|
+
" ",
|
|
6138
|
+
conversations.length === 1 ? "colleague" : "colleagues"
|
|
6139
|
+
] })
|
|
6140
|
+
] }),
|
|
6141
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-h-0 flex-1 overflow-y-auto", children: conversations.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-4 py-6 text-xs text-muted-foreground", children: emptyState ?? "No conversations yet." }) : /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "w-full", children: conversations.map((c) => {
|
|
6142
|
+
const { peer, lastMessage, unreadCount } = c;
|
|
6143
|
+
const active = peer.external_id === selectedPeerId;
|
|
6144
|
+
const preview = `${lastMessage.isMine ? "You: " : ""}${lastMessage.body}`;
|
|
6145
|
+
return /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6146
|
+
"button",
|
|
6147
|
+
{
|
|
6148
|
+
type: "button",
|
|
6149
|
+
onClick: () => onSelect(peer.external_id),
|
|
6150
|
+
"data-testid": `arbi-dm-conversation-${peer.external_id}`,
|
|
6151
|
+
className: cn(
|
|
6152
|
+
"flex w-full items-start gap-3 border-b border-border/60 px-4 py-3 text-left transition-colors",
|
|
6153
|
+
active ? "bg-accent" : "hover:bg-accent/60"
|
|
6154
|
+
),
|
|
6155
|
+
children: [
|
|
6156
|
+
/* @__PURE__ */ jsxRuntime.jsx(DmAvatar, { user: peer }),
|
|
6157
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
6158
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
6159
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate text-sm font-semibold text-foreground", children: userDisplayName(peer) }),
|
|
6160
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "shrink-0 text-[11px] text-muted-foreground", children: formatRelativeTime(lastMessage.createdAt) })
|
|
6161
|
+
] }),
|
|
6162
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-1 flex items-center gap-2", children: [
|
|
6163
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "min-w-0 flex-1 truncate text-xs text-muted-foreground", children: preview }),
|
|
6164
|
+
unreadCount > 0 ? /* @__PURE__ */ jsxRuntime.jsx(Badge, { className: cn("px-1.5 py-0 text-[10px]", classNames?.unreadBadge), children: unreadCount }) : null
|
|
6165
|
+
] })
|
|
6166
|
+
] })
|
|
6167
|
+
]
|
|
6168
|
+
}
|
|
6169
|
+
) }, peer.external_id);
|
|
6170
|
+
}) }) })
|
|
6171
|
+
]
|
|
6172
|
+
}
|
|
6173
|
+
);
|
|
6174
|
+
}
|
|
6175
|
+
function MessageBubble2({ message, classNames }) {
|
|
6176
|
+
const { isMine } = message;
|
|
6177
|
+
const who = isMine ? "You" : userDisplayName(message.sender);
|
|
6178
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6179
|
+
"div",
|
|
6180
|
+
{
|
|
6181
|
+
"data-testid": "arbi-dm-message",
|
|
6182
|
+
className: cn("flex flex-col gap-1", isMine ? "items-end" : "items-start"),
|
|
6183
|
+
children: [
|
|
6184
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 px-1", children: [
|
|
6185
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[11px] font-medium text-foreground", children: who }),
|
|
6186
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[11px] text-muted-foreground", children: formatRelativeTime(message.createdAt) })
|
|
6187
|
+
] }),
|
|
6188
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6189
|
+
"div",
|
|
6190
|
+
{
|
|
6191
|
+
className: cn(
|
|
6192
|
+
"max-w-[80%] rounded-2xl px-3.5 py-2 text-sm shadow-sm",
|
|
6193
|
+
isMine ? cn("rounded-br-sm bg-accent text-accent-foreground", classNames?.ownBubble) : cn(
|
|
6194
|
+
"rounded-bl-sm border border-border bg-card text-card-foreground",
|
|
6195
|
+
classNames?.peerBubble
|
|
6196
|
+
)
|
|
6197
|
+
),
|
|
6198
|
+
children: message.body
|
|
6199
|
+
}
|
|
6200
|
+
)
|
|
6201
|
+
]
|
|
6202
|
+
}
|
|
6203
|
+
);
|
|
6204
|
+
}
|
|
6205
|
+
function MessageThread({ conversation, classNames, emptyState }) {
|
|
6206
|
+
const bottomRef = React.useRef(null);
|
|
6207
|
+
React.useEffect(() => {
|
|
6208
|
+
bottomRef.current?.scrollIntoView({ block: "end" });
|
|
6209
|
+
}, [conversation?.peer.external_id, conversation?.messages.length]);
|
|
6210
|
+
if (!conversation) {
|
|
6211
|
+
return /* @__PURE__ */ jsxRuntime.jsx("section", { className: "flex min-h-0 flex-1 flex-col items-center justify-center gap-3 p-8 text-center", children: emptyState ?? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
6212
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-14 items-center justify-center rounded-full bg-accent", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MessagesSquare, { className: "size-6 text-muted-foreground" }) }),
|
|
6213
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
6214
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-semibold text-foreground", children: "No conversation selected" }),
|
|
6215
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "mx-auto mt-1 max-w-xs text-xs text-muted-foreground", children: "Choose a colleague from the list to read the thread and send a direct message." })
|
|
6216
|
+
] })
|
|
6217
|
+
] }) });
|
|
6218
|
+
}
|
|
6219
|
+
const { peer, messages } = conversation;
|
|
6220
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
6221
|
+
/* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex items-center gap-3 border-b border-border px-4 py-3", children: [
|
|
6222
|
+
/* @__PURE__ */ jsxRuntime.jsx(DmAvatar, { user: peer, className: "size-9" }),
|
|
6223
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0", children: [
|
|
6224
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "truncate text-sm font-semibold text-foreground", children: userDisplayName(peer) }),
|
|
6225
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "truncate text-xs text-muted-foreground", children: peer.email })
|
|
6226
|
+
] })
|
|
6227
|
+
] }),
|
|
6228
|
+
/* @__PURE__ */ jsxRuntime.jsx(ScrollArea, { className: "min-h-0 flex-1 bg-background", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 px-4 py-4", "data-testid": "arbi-dm-thread", children: [
|
|
6229
|
+
messages.map((m) => /* @__PURE__ */ jsxRuntime.jsx(MessageBubble2, { message: m, classNames }, m.externalId)),
|
|
6230
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { ref: bottomRef })
|
|
6231
|
+
] }) })
|
|
6232
|
+
] });
|
|
6233
|
+
}
|
|
6234
|
+
function DmComposer({ placeholder, disabled, onSend, classNames }) {
|
|
6235
|
+
const [draft, setDraft] = React.useState("");
|
|
6236
|
+
const submit = () => {
|
|
6237
|
+
const text = draft.trim();
|
|
6238
|
+
if (!text || disabled) return;
|
|
6239
|
+
onSend(text);
|
|
6240
|
+
setDraft("");
|
|
6241
|
+
};
|
|
6242
|
+
const onKeyDown = (e) => {
|
|
6243
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
6244
|
+
e.preventDefault();
|
|
6245
|
+
submit();
|
|
6246
|
+
}
|
|
6247
|
+
};
|
|
6248
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-t border-border p-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-end gap-2", children: [
|
|
6249
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6250
|
+
Textarea,
|
|
6251
|
+
{
|
|
6252
|
+
value: draft,
|
|
6253
|
+
onChange: (e) => setDraft(e.target.value),
|
|
6254
|
+
onKeyDown,
|
|
6255
|
+
placeholder,
|
|
6256
|
+
rows: 1,
|
|
6257
|
+
disabled,
|
|
6258
|
+
className: "max-h-40 min-h-[44px] resize-none",
|
|
6259
|
+
"data-testid": "arbi-dm-input"
|
|
6260
|
+
}
|
|
6261
|
+
),
|
|
6262
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
6263
|
+
Button,
|
|
6264
|
+
{
|
|
6265
|
+
type: "button",
|
|
6266
|
+
onClick: submit,
|
|
6267
|
+
disabled: disabled || !draft.trim(),
|
|
6268
|
+
className: cn(classNames?.sendButton),
|
|
6269
|
+
"data-testid": "arbi-dm-send",
|
|
6270
|
+
children: [
|
|
6271
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Send, { className: "size-4" }),
|
|
6272
|
+
" Send"
|
|
6273
|
+
]
|
|
6274
|
+
}
|
|
6275
|
+
)
|
|
6276
|
+
] }) });
|
|
6277
|
+
}
|
|
6278
|
+
function DirectMessages({
|
|
6279
|
+
className,
|
|
6280
|
+
classNames,
|
|
6281
|
+
emptyThread,
|
|
6282
|
+
emptyList
|
|
6283
|
+
}) {
|
|
6284
|
+
const { conversations, isLoading, sendMessage, markRead } = useDirectMessages();
|
|
6285
|
+
const [selectedPeerId, setSelectedPeerId] = React.useState(null);
|
|
6286
|
+
const selected = React.useMemo(
|
|
6287
|
+
() => conversations.find((c) => c.peer.external_id === selectedPeerId) ?? null,
|
|
6288
|
+
[conversations, selectedPeerId]
|
|
6289
|
+
);
|
|
6290
|
+
React.useEffect(() => {
|
|
6291
|
+
if (!selected || selected.unreadCount === 0) return;
|
|
6292
|
+
const unreadIds = selected.messages.filter((m) => !m.isMine && !m.read).map((m) => m.externalId);
|
|
6293
|
+
if (unreadIds.length) void markRead(unreadIds);
|
|
6294
|
+
}, [selected?.peer.external_id, selected?.unreadCount]);
|
|
6295
|
+
const handleSend = (text) => {
|
|
6296
|
+
if (!selected) return;
|
|
6297
|
+
void sendMessage(selected.peer.external_id, selected.peer.encryption_public_key, text);
|
|
6298
|
+
};
|
|
6299
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6300
|
+
"div",
|
|
6301
|
+
{
|
|
6302
|
+
"data-testid": "arbi-dm",
|
|
6303
|
+
style: { height: "calc(100vh - 16rem)", minHeight: "28rem" },
|
|
6304
|
+
className: cn(
|
|
6305
|
+
"flex flex-col overflow-hidden rounded-xl border border-border bg-card md:flex-row",
|
|
6306
|
+
className
|
|
6307
|
+
),
|
|
6308
|
+
children: [
|
|
6309
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6310
|
+
ConversationList,
|
|
6311
|
+
{
|
|
6312
|
+
conversations,
|
|
6313
|
+
selectedPeerId: selected?.peer.external_id ?? null,
|
|
6314
|
+
onSelect: setSelectedPeerId,
|
|
6315
|
+
classNames,
|
|
6316
|
+
emptyState: isLoading ? "Loading messages\u2026" : emptyList
|
|
6317
|
+
}
|
|
6318
|
+
),
|
|
6319
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-h-0 min-w-0 flex-1 flex-col", children: [
|
|
6320
|
+
/* @__PURE__ */ jsxRuntime.jsx(MessageThread, { conversation: selected, classNames, emptyState: emptyThread }),
|
|
6321
|
+
selected ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
6322
|
+
DmComposer,
|
|
6323
|
+
{
|
|
6324
|
+
placeholder: `Message ${userDisplayName(selected.peer).split(" ")[0]}\u2026`,
|
|
6325
|
+
onSend: handleSend,
|
|
6326
|
+
classNames
|
|
6327
|
+
}
|
|
6328
|
+
) : null
|
|
6329
|
+
] })
|
|
6330
|
+
]
|
|
6331
|
+
}
|
|
6332
|
+
);
|
|
6333
|
+
}
|
|
6334
|
+
var DEFAULT_ASPECT_OPTIONS = [
|
|
6335
|
+
{ label: "1:1", value: 1 },
|
|
6336
|
+
{ label: "4:3", value: 4 / 3 },
|
|
6337
|
+
{ label: "3:4", value: 3 / 4 },
|
|
6338
|
+
{ label: "16:9", value: 16 / 9 },
|
|
6339
|
+
{ label: "9:16", value: 9 / 16 }
|
|
6340
|
+
];
|
|
6341
|
+
function ImageCropper({
|
|
6342
|
+
image,
|
|
6343
|
+
aspect = 1,
|
|
6344
|
+
aspectOptions,
|
|
6345
|
+
cropShape = "rect",
|
|
6346
|
+
minZoom = 1,
|
|
6347
|
+
maxZoom = 3,
|
|
6348
|
+
className,
|
|
6349
|
+
onCropComplete
|
|
6350
|
+
}) {
|
|
6351
|
+
const [crop, setCrop] = React.useState({ x: 0, y: 0 });
|
|
6352
|
+
const [zoom, setZoom] = React.useState(1);
|
|
6353
|
+
const [activeAspect, setActiveAspect] = React.useState(aspectOptions?.[0]?.value ?? aspect);
|
|
6354
|
+
React.useEffect(() => {
|
|
6355
|
+
if (!aspectOptions) setActiveAspect(aspect);
|
|
6356
|
+
}, [aspect, aspectOptions]);
|
|
6357
|
+
const handleComplete = React.useCallback(
|
|
6358
|
+
(_, areaPixels) => {
|
|
6359
|
+
onCropComplete?.(areaPixels, activeAspect);
|
|
6360
|
+
},
|
|
6361
|
+
[onCropComplete, activeAspect]
|
|
6362
|
+
);
|
|
6363
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex flex-col gap-3", className), children: [
|
|
6364
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative h-72 w-full overflow-hidden rounded-md bg-foreground/95", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
6365
|
+
Cropper__default.default,
|
|
6366
|
+
{
|
|
6367
|
+
image,
|
|
6368
|
+
crop,
|
|
6369
|
+
zoom,
|
|
6370
|
+
aspect: activeAspect,
|
|
6371
|
+
cropShape,
|
|
6372
|
+
showGrid: cropShape === "rect",
|
|
6373
|
+
onCropChange: setCrop,
|
|
6374
|
+
onZoomChange: setZoom,
|
|
6375
|
+
onCropComplete: handleComplete,
|
|
6376
|
+
objectFit: "contain"
|
|
6377
|
+
}
|
|
6378
|
+
) }),
|
|
6379
|
+
aspectOptions && aspectOptions.length > 1 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-1", "data-testid": "image-cropper-aspects", children: [
|
|
6380
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "mr-1 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground", children: "Ratio" }),
|
|
6381
|
+
aspectOptions.map((opt) => {
|
|
6382
|
+
const on = opt.value === activeAspect;
|
|
6383
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
6384
|
+
"button",
|
|
6385
|
+
{
|
|
6386
|
+
type: "button",
|
|
6387
|
+
onClick: () => setActiveAspect(opt.value),
|
|
6388
|
+
"data-testid": `image-cropper-aspect-${opt.label}`,
|
|
6389
|
+
className: cn(
|
|
6390
|
+
"rounded-md px-2 py-1 text-xs font-medium transition-colors",
|
|
6391
|
+
on ? "bg-primary text-primary-foreground" : "text-muted-foreground hover:bg-accent hover:text-foreground"
|
|
6392
|
+
),
|
|
6393
|
+
children: opt.label
|
|
6394
|
+
},
|
|
6395
|
+
opt.label
|
|
6396
|
+
);
|
|
6397
|
+
})
|
|
6398
|
+
] }) : null,
|
|
6399
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
|
|
6400
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { className: "text-[11px] font-semibold uppercase tracking-wider text-muted-foreground", children: "Zoom" }),
|
|
6401
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6402
|
+
Slider,
|
|
6403
|
+
{
|
|
6404
|
+
value: [zoom],
|
|
6405
|
+
onValueChange: ([v]) => setZoom(v ?? 1),
|
|
6406
|
+
min: minZoom,
|
|
6407
|
+
max: maxZoom,
|
|
6408
|
+
step: 0.01
|
|
6409
|
+
}
|
|
6410
|
+
)
|
|
6411
|
+
] })
|
|
6412
|
+
] });
|
|
6413
|
+
}
|
|
6414
|
+
|
|
6415
|
+
// src/imagecrop/cropImage.ts
|
|
6416
|
+
function loadImage(src) {
|
|
6417
|
+
return new Promise((resolve, reject) => {
|
|
6418
|
+
const img = new Image();
|
|
6419
|
+
img.crossOrigin = "anonymous";
|
|
6420
|
+
img.onload = () => resolve(img);
|
|
6421
|
+
img.onerror = () => reject(new Error("Failed to load image for cropping"));
|
|
6422
|
+
img.src = src;
|
|
6423
|
+
});
|
|
6424
|
+
}
|
|
6425
|
+
async function cropImage(imageSrc, area, output = {}) {
|
|
6426
|
+
const { maxSize, mimeType = "image/jpeg", quality = 0.9, background = "#ffffff" } = output;
|
|
6427
|
+
const img = await loadImage(imageSrc);
|
|
6428
|
+
let outW = Math.max(1, Math.round(area.width));
|
|
6429
|
+
let outH = Math.max(1, Math.round(area.height));
|
|
6430
|
+
if (maxSize && Math.max(outW, outH) > maxSize) {
|
|
6431
|
+
const scale = maxSize / Math.max(outW, outH);
|
|
6432
|
+
outW = Math.max(1, Math.round(outW * scale));
|
|
6433
|
+
outH = Math.max(1, Math.round(outH * scale));
|
|
6434
|
+
}
|
|
6435
|
+
const canvas = document.createElement("canvas");
|
|
6436
|
+
canvas.width = outW;
|
|
6437
|
+
canvas.height = outH;
|
|
6438
|
+
const ctx = canvas.getContext("2d");
|
|
6439
|
+
if (!ctx) throw new Error("canvas 2d context unavailable");
|
|
6440
|
+
if (mimeType === "image/jpeg") {
|
|
6441
|
+
ctx.fillStyle = background;
|
|
6442
|
+
ctx.fillRect(0, 0, outW, outH);
|
|
6443
|
+
}
|
|
6444
|
+
ctx.drawImage(img, area.x, area.y, area.width, area.height, 0, 0, outW, outH);
|
|
6445
|
+
const dataUrl = canvas.toDataURL(mimeType, quality);
|
|
6446
|
+
const blob = await new Promise(
|
|
6447
|
+
(resolve, reject) => canvas.toBlob(
|
|
6448
|
+
(b) => b ? resolve(b) : reject(new Error("canvas toBlob returned null")),
|
|
6449
|
+
mimeType,
|
|
6450
|
+
quality
|
|
6451
|
+
)
|
|
6452
|
+
);
|
|
6453
|
+
return { dataUrl, blob, width: outW, height: outH };
|
|
6454
|
+
}
|
|
6455
|
+
function ImageCropModal({
|
|
6456
|
+
open,
|
|
6457
|
+
image,
|
|
6458
|
+
title = "Crop image",
|
|
6459
|
+
saveLabel = "Save",
|
|
6460
|
+
aspect,
|
|
6461
|
+
aspectOptions,
|
|
6462
|
+
cropShape = "rect",
|
|
6463
|
+
output,
|
|
6464
|
+
onComplete,
|
|
6465
|
+
onCancel
|
|
6466
|
+
}) {
|
|
6467
|
+
const [area, setArea] = React.useState(null);
|
|
6468
|
+
const [busy, setBusy] = React.useState(false);
|
|
6469
|
+
const handleSave = async () => {
|
|
6470
|
+
if (!image || !area) return;
|
|
6471
|
+
setBusy(true);
|
|
6472
|
+
try {
|
|
6473
|
+
const result = await cropImage(image, area, output);
|
|
6474
|
+
await onComplete(result);
|
|
6475
|
+
} finally {
|
|
6476
|
+
setBusy(false);
|
|
6477
|
+
}
|
|
6478
|
+
};
|
|
6479
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open, onOpenChange: (next) => !next ? onCancel() : void 0, children: /* @__PURE__ */ jsxRuntime.jsxs(DialogContent, { className: "sm:max-w-md", "data-testid": "image-crop-modal", children: [
|
|
6480
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { children: title }) }),
|
|
6481
|
+
image ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
6482
|
+
ImageCropper,
|
|
6483
|
+
{
|
|
6484
|
+
image,
|
|
6485
|
+
aspect,
|
|
6486
|
+
aspectOptions,
|
|
6487
|
+
cropShape,
|
|
6488
|
+
onCropComplete: setArea
|
|
6489
|
+
}
|
|
6490
|
+
) : null,
|
|
6491
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DialogFooter, { className: "gap-2 sm:gap-2", children: [
|
|
6492
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "ghost", onClick: onCancel, disabled: busy, children: "Cancel" }),
|
|
6493
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Button, { onClick: handleSave, disabled: !area || busy, "data-testid": "image-crop-save", children: [
|
|
6494
|
+
busy ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "mr-1 size-4 animate-spin" }) : null,
|
|
6495
|
+
saveLabel
|
|
6496
|
+
] })
|
|
6497
|
+
] })
|
|
6498
|
+
] }) });
|
|
6499
|
+
}
|
|
6500
|
+
var MAX_NAV = 5;
|
|
6501
|
+
var MAX_DOCS = 4;
|
|
6502
|
+
function CommandPalette({
|
|
6503
|
+
open,
|
|
6504
|
+
onOpenChange,
|
|
6505
|
+
navItems,
|
|
6506
|
+
onNavigate,
|
|
6507
|
+
buildAskPrompt = (q) => q,
|
|
6508
|
+
askDocIds = [],
|
|
6509
|
+
model,
|
|
6510
|
+
searchDocIds,
|
|
6511
|
+
onOpenDoc,
|
|
6512
|
+
placeholder = "Ask AI, or jump to a page\u2026",
|
|
6513
|
+
askHint = "Grounded in the live workspace",
|
|
6514
|
+
classNames,
|
|
6515
|
+
testId = "command-palette"
|
|
6516
|
+
}) {
|
|
6517
|
+
const task = useAiTask();
|
|
6518
|
+
const searchable = !!searchDocIds && searchDocIds.length > 0;
|
|
6519
|
+
const { results, search, status: searchStatus } = useSemanticSearch(searchDocIds ?? []);
|
|
6520
|
+
const [query, setQuery] = React.useState("");
|
|
6521
|
+
const inputRef = React.useRef(null);
|
|
6522
|
+
React.useEffect(() => {
|
|
6523
|
+
if (open) {
|
|
6524
|
+
setQuery("");
|
|
6525
|
+
task.reset();
|
|
6526
|
+
const t = setTimeout(() => inputRef.current?.focus(), 40);
|
|
6527
|
+
return () => clearTimeout(t);
|
|
6528
|
+
}
|
|
6529
|
+
}, [open]);
|
|
6530
|
+
const showingAnswer = task.status !== "idle";
|
|
6531
|
+
React.useEffect(() => {
|
|
6532
|
+
if (!searchable || showingAnswer) return;
|
|
6533
|
+
const q = query.trim();
|
|
6534
|
+
if (q.length < 2) return;
|
|
6535
|
+
const t = setTimeout(() => void search(q, "hybrid"), 300);
|
|
6536
|
+
return () => clearTimeout(t);
|
|
6537
|
+
}, [query, searchable, showingAnswer, search]);
|
|
6538
|
+
const navMatches = React.useMemo(() => {
|
|
6539
|
+
const q = query.trim().toLowerCase();
|
|
6540
|
+
if (!q) return navItems.slice(0, MAX_NAV);
|
|
6541
|
+
return navItems.filter(
|
|
6542
|
+
(i) => i.label.toLowerCase().includes(q) || (i.keywords ? i.keywords.toLowerCase().includes(q) : false)
|
|
6543
|
+
).slice(0, MAX_NAV);
|
|
6544
|
+
}, [query, navItems]);
|
|
6545
|
+
const docHits = React.useMemo(() => results.slice(0, MAX_DOCS), [results]);
|
|
6546
|
+
const go = (to) => {
|
|
6547
|
+
onOpenChange(false);
|
|
6548
|
+
onNavigate(to);
|
|
6549
|
+
};
|
|
6550
|
+
const openDoc = (docId) => {
|
|
6551
|
+
onOpenChange(false);
|
|
6552
|
+
onOpenDoc?.(docId);
|
|
6553
|
+
};
|
|
6554
|
+
const ask = () => {
|
|
6555
|
+
const q = query.trim();
|
|
6556
|
+
if (!q || task.isRunning) return;
|
|
6557
|
+
void task.run(buildAskPrompt(q), askDocIds, { model });
|
|
6558
|
+
};
|
|
6559
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6560
|
+
DialogContent,
|
|
6561
|
+
{
|
|
6562
|
+
className: cn(
|
|
6563
|
+
"top-[12%] max-w-2xl translate-y-0 gap-0 overflow-hidden p-0",
|
|
6564
|
+
classNames?.dialog
|
|
6565
|
+
),
|
|
6566
|
+
"data-testid": testId,
|
|
6567
|
+
children: [
|
|
6568
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { className: "sr-only", children: "Command palette" }),
|
|
6569
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3 border-b border-border px-4", children: [
|
|
6570
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Sparkles, { className: cn("size-4 shrink-0 text-ai-accent", classNames?.leadingIcon) }),
|
|
6571
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6572
|
+
"input",
|
|
6573
|
+
{
|
|
6574
|
+
ref: inputRef,
|
|
6575
|
+
value: query,
|
|
6576
|
+
onChange: (e) => setQuery(e.target.value),
|
|
6577
|
+
onKeyDown: (e) => {
|
|
6578
|
+
if (e.key === "Enter") {
|
|
6579
|
+
e.preventDefault();
|
|
6580
|
+
ask();
|
|
6581
|
+
}
|
|
6582
|
+
},
|
|
6583
|
+
placeholder,
|
|
6584
|
+
className: cn(
|
|
6585
|
+
"h-14 flex-1 bg-transparent text-base outline-none placeholder:text-muted-foreground",
|
|
6586
|
+
classNames?.input
|
|
6587
|
+
),
|
|
6588
|
+
"data-testid": `${testId}-input`
|
|
6589
|
+
}
|
|
6590
|
+
),
|
|
6591
|
+
/* @__PURE__ */ jsxRuntime.jsx("kbd", { className: "hidden rounded border border-border px-1.5 py-0.5 text-[10px] text-muted-foreground sm:inline", children: "\u2318K" })
|
|
6592
|
+
] }),
|
|
6593
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "max-h-[60vh] overflow-y-auto p-2", children: [
|
|
6594
|
+
query.trim() && !showingAnswer && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6595
|
+
"button",
|
|
6596
|
+
{
|
|
6597
|
+
type: "button",
|
|
6598
|
+
onClick: ask,
|
|
6599
|
+
className: cn(
|
|
6600
|
+
"mb-1 flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left hover:bg-accent",
|
|
6601
|
+
classNames?.askAction
|
|
6602
|
+
),
|
|
6603
|
+
"data-testid": `${testId}-ask`,
|
|
6604
|
+
children: [
|
|
6605
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6606
|
+
"span",
|
|
6607
|
+
{
|
|
6608
|
+
className: cn(
|
|
6609
|
+
"flex size-8 items-center justify-center rounded-md bg-ai-surface text-ai-accent",
|
|
6610
|
+
classNames?.askChip
|
|
6611
|
+
),
|
|
6612
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Sparkles, { className: "size-4" })
|
|
6613
|
+
}
|
|
6614
|
+
),
|
|
6615
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
6616
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "block truncate text-sm font-medium text-foreground", children: [
|
|
6617
|
+
"Ask AI: \u201C",
|
|
6618
|
+
query.trim(),
|
|
6619
|
+
"\u201D"
|
|
6620
|
+
] }),
|
|
6621
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "block text-xs text-muted-foreground", children: askHint })
|
|
6622
|
+
] }),
|
|
6623
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.CornerDownLeft, { className: "size-4 text-muted-foreground" })
|
|
6624
|
+
]
|
|
6625
|
+
}
|
|
6626
|
+
),
|
|
6627
|
+
showingAnswer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2", "data-testid": `${testId}-answer`, children: [
|
|
6628
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6629
|
+
AiAnswer,
|
|
6630
|
+
{
|
|
6631
|
+
status: task.status,
|
|
6632
|
+
text: task.text,
|
|
6633
|
+
stepCount: task.stepCount,
|
|
6634
|
+
error: task.error,
|
|
6635
|
+
testId: `${testId}-ai`
|
|
6636
|
+
}
|
|
6637
|
+
),
|
|
6638
|
+
task.isDone && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 flex justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
6639
|
+
Button,
|
|
6640
|
+
{
|
|
6641
|
+
variant: "outline",
|
|
6642
|
+
size: "sm",
|
|
6643
|
+
onClick: () => task.reset(),
|
|
6644
|
+
"data-testid": `${testId}-clear`,
|
|
6645
|
+
children: "Ask another"
|
|
6646
|
+
}
|
|
6647
|
+
) })
|
|
6648
|
+
] }),
|
|
6649
|
+
!showingAnswer && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
6650
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "px-3 pb-1 pt-2 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground", children: query.trim() ? "Jump to" : "Go to" }),
|
|
6651
|
+
navMatches.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "px-3 py-2 text-sm text-muted-foreground", children: "No pages match \u2014 press Enter to ask AI." }),
|
|
6652
|
+
navMatches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6653
|
+
"button",
|
|
6654
|
+
{
|
|
6655
|
+
type: "button",
|
|
6656
|
+
onClick: () => go(item.to),
|
|
6657
|
+
className: cn(
|
|
6658
|
+
"flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left hover:bg-accent",
|
|
6659
|
+
classNames?.navItem
|
|
6660
|
+
),
|
|
6661
|
+
"data-testid": `${testId}-nav-${item.id}`,
|
|
6662
|
+
children: [
|
|
6663
|
+
item.icon && /* @__PURE__ */ jsxRuntime.jsx(item.icon, { className: "size-4 text-muted-foreground" }),
|
|
6664
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 text-sm text-foreground", children: item.label }),
|
|
6665
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowRight, { className: "size-3.5 text-muted-foreground" })
|
|
6666
|
+
]
|
|
6667
|
+
},
|
|
6668
|
+
item.id
|
|
6669
|
+
)),
|
|
6670
|
+
searchable && query.trim().length >= 2 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
6671
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "px-3 pb-1 pt-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground", children: "Documents" }),
|
|
6672
|
+
searchStatus === "done" && docHits.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "px-3 py-2 text-sm text-muted-foreground", children: "No passages matched." }),
|
|
6673
|
+
docHits.map((hit, i) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6674
|
+
"button",
|
|
6675
|
+
{
|
|
6676
|
+
type: "button",
|
|
6677
|
+
onClick: () => hit.docId && openDoc(hit.docId),
|
|
6678
|
+
className: "flex w-full items-start gap-3 rounded-lg px-3 py-2 text-left hover:bg-accent",
|
|
6679
|
+
"data-testid": `${testId}-doc-${i}`,
|
|
6680
|
+
children: [
|
|
6681
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileText, { className: "mt-0.5 size-4 shrink-0 text-ai-accent" }),
|
|
6682
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
6683
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "block truncate text-sm text-foreground", children: [
|
|
6684
|
+
hit.docTitle ?? "Document",
|
|
6685
|
+
hit.page != null && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground", children: [
|
|
6686
|
+
" \xB7 p.",
|
|
6687
|
+
hit.page
|
|
6688
|
+
] })
|
|
6689
|
+
] }),
|
|
6690
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "line-clamp-1 text-xs text-muted-foreground", children: hit.content })
|
|
6691
|
+
] })
|
|
6692
|
+
]
|
|
6693
|
+
},
|
|
6694
|
+
`${hit.docId}-${hit.page}-${i}`
|
|
6695
|
+
))
|
|
6696
|
+
] })
|
|
6697
|
+
] })
|
|
6698
|
+
] })
|
|
6699
|
+
]
|
|
6700
|
+
}
|
|
6701
|
+
) });
|
|
6702
|
+
}
|
|
6703
|
+
var CommandPaletteCtx = React.createContext(null);
|
|
6704
|
+
function useCommandPalette() {
|
|
6705
|
+
const v = React.useContext(CommandPaletteCtx);
|
|
6706
|
+
if (!v) throw new Error("useCommandPalette must be used within a CommandPaletteProvider");
|
|
6707
|
+
return v;
|
|
6708
|
+
}
|
|
6709
|
+
function CommandPaletteProvider({
|
|
6710
|
+
children,
|
|
6711
|
+
hotkey = true,
|
|
6712
|
+
...paletteProps
|
|
6713
|
+
}) {
|
|
6714
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
6715
|
+
const open = React.useCallback(() => setIsOpen(true), []);
|
|
6716
|
+
const close = React.useCallback(() => setIsOpen(false), []);
|
|
6717
|
+
const toggle = React.useCallback(() => setIsOpen((o) => !o), []);
|
|
6718
|
+
React.useEffect(() => {
|
|
6719
|
+
if (!hotkey) return;
|
|
6720
|
+
const onKey = (e) => {
|
|
6721
|
+
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k") {
|
|
6722
|
+
e.preventDefault();
|
|
6723
|
+
toggle();
|
|
6724
|
+
}
|
|
6725
|
+
};
|
|
6726
|
+
window.addEventListener("keydown", onKey);
|
|
6727
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
6728
|
+
}, [hotkey, toggle]);
|
|
6729
|
+
const value = React.useMemo(() => ({ open, close, toggle, isOpen }), [open, close, toggle, isOpen]);
|
|
6730
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(CommandPaletteCtx.Provider, { value, children: [
|
|
6731
|
+
children,
|
|
6732
|
+
/* @__PURE__ */ jsxRuntime.jsx(CommandPalette, { open: isOpen, onOpenChange: setIsOpen, ...paletteProps })
|
|
6733
|
+
] });
|
|
6734
|
+
}
|
|
6735
|
+
function nameInitials(name) {
|
|
6736
|
+
const parts = name.trim().split(/\s+/).filter(Boolean);
|
|
6737
|
+
if (!parts.length) return "?";
|
|
6738
|
+
return parts.slice(0, 2).map((p) => p[0]?.toUpperCase() ?? "").join("");
|
|
6739
|
+
}
|
|
6740
|
+
function UserMenu({
|
|
6741
|
+
user,
|
|
6742
|
+
items = [],
|
|
6743
|
+
onLogout,
|
|
6744
|
+
logoutLabel = "Sign out",
|
|
6745
|
+
align = "end",
|
|
6746
|
+
classNames,
|
|
6747
|
+
testId = "user-menu",
|
|
6748
|
+
logoutTestId
|
|
6749
|
+
}) {
|
|
6750
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { children: [
|
|
6751
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6752
|
+
"button",
|
|
6753
|
+
{
|
|
6754
|
+
className: cn(
|
|
6755
|
+
"flex items-center gap-2 rounded-md px-1.5 py-1 transition-colors hover:bg-accent",
|
|
6756
|
+
classNames?.trigger
|
|
6757
|
+
),
|
|
6758
|
+
"data-testid": testId,
|
|
6759
|
+
children: [
|
|
6760
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Avatar, { className: "size-8", children: [
|
|
6761
|
+
user.picture ? /* @__PURE__ */ jsxRuntime.jsx(AvatarImage, { src: user.picture, alt: user.name }) : null,
|
|
6762
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6763
|
+
AvatarFallback,
|
|
6764
|
+
{
|
|
6765
|
+
className: cn("bg-primary text-primary-foreground", classNames?.fallback),
|
|
6766
|
+
children: nameInitials(user.name)
|
|
6767
|
+
}
|
|
6768
|
+
)
|
|
6769
|
+
] }),
|
|
6770
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDown, { className: "size-4 text-muted-foreground" })
|
|
6771
|
+
]
|
|
6772
|
+
}
|
|
6773
|
+
) }),
|
|
6774
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuContent, { align, className: "w-56", children: [
|
|
6775
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuLabel, { children: [
|
|
6776
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-medium text-foreground", children: user.name }),
|
|
6777
|
+
user.email && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs font-normal text-muted-foreground", children: user.email })
|
|
6778
|
+
] }),
|
|
6779
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}),
|
|
6780
|
+
items.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuItem, { onClick: item.onSelect, "data-testid": item.testId, children: [
|
|
6781
|
+
item.icon && /* @__PURE__ */ jsxRuntime.jsx(item.icon, { className: "size-4" }),
|
|
6782
|
+
item.label
|
|
6783
|
+
] }, item.label)),
|
|
6784
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuItem, { onClick: onLogout, "data-testid": logoutTestId ?? `${testId}-logout`, children: [
|
|
6785
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.LogOut, { className: "size-4" }),
|
|
6786
|
+
logoutLabel
|
|
6787
|
+
] })
|
|
6788
|
+
] })
|
|
6789
|
+
] });
|
|
6790
|
+
}
|
|
5169
6791
|
var useArbiUiStore = zustand.create((set) => ({
|
|
5170
6792
|
selectedDocIds: [],
|
|
5171
6793
|
setSelectedDocIds: (ids) => set({ selectedDocIds: ids }),
|
|
@@ -5746,6 +7368,7 @@ Object.defineProperty(exports, "isMessageType", {
|
|
|
5746
7368
|
enumerable: true,
|
|
5747
7369
|
get: function () { return client.isMessageType; }
|
|
5748
7370
|
});
|
|
7371
|
+
exports.ActivityFeed = ActivityFeed;
|
|
5749
7372
|
exports.AiActionCard = AiActionCard;
|
|
5750
7373
|
exports.AiAnswer = AiAnswer;
|
|
5751
7374
|
exports.AiMarkdown = AiMarkdown;
|
|
@@ -5762,6 +7385,7 @@ exports.AudIcon = AudIcon;
|
|
|
5762
7385
|
exports.Avatar = Avatar;
|
|
5763
7386
|
exports.AvatarFallback = AvatarFallback;
|
|
5764
7387
|
exports.AvatarImage = AvatarImage;
|
|
7388
|
+
exports.BASE_COLORS = BASE_COLORS2;
|
|
5765
7389
|
exports.Badge = Badge;
|
|
5766
7390
|
exports.Button = Button;
|
|
5767
7391
|
exports.Card = Card;
|
|
@@ -5784,8 +7408,13 @@ exports.CommandGroup = CommandGroup;
|
|
|
5784
7408
|
exports.CommandInput = CommandInput;
|
|
5785
7409
|
exports.CommandItem = CommandItem;
|
|
5786
7410
|
exports.CommandList = CommandList;
|
|
7411
|
+
exports.CommandPalette = CommandPalette;
|
|
7412
|
+
exports.CommandPaletteProvider = CommandPaletteProvider;
|
|
5787
7413
|
exports.CommandSeparator = CommandSeparator;
|
|
5788
7414
|
exports.CommandShortcut = CommandShortcut;
|
|
7415
|
+
exports.ConversationList = ConversationList;
|
|
7416
|
+
exports.DEFAULT_ASPECT_OPTIONS = DEFAULT_ASPECT_OPTIONS;
|
|
7417
|
+
exports.DEFAULT_NOTIFY_TONE = DEFAULT_NOTIFY_TONE;
|
|
5789
7418
|
exports.Dialog = Dialog;
|
|
5790
7419
|
exports.DialogClose = DialogClose;
|
|
5791
7420
|
exports.DialogContent = DialogContent;
|
|
@@ -5796,6 +7425,9 @@ exports.DialogOverlay = DialogOverlay;
|
|
|
5796
7425
|
exports.DialogPortal = DialogPortal;
|
|
5797
7426
|
exports.DialogTitle = DialogTitle;
|
|
5798
7427
|
exports.DialogTrigger = DialogTrigger;
|
|
7428
|
+
exports.DirectMessages = DirectMessages;
|
|
7429
|
+
exports.DmAvatar = DmAvatar;
|
|
7430
|
+
exports.DmComposer = DmComposer;
|
|
5799
7431
|
exports.DocIcon = DocIcon;
|
|
5800
7432
|
exports.DocQaPanel = DocQaPanel;
|
|
5801
7433
|
exports.DocSearch = DocSearch;
|
|
@@ -5818,7 +7450,9 @@ exports.DropdownMenuSub = DropdownMenuSub;
|
|
|
5818
7450
|
exports.DropdownMenuSubContent = DropdownMenuSubContent;
|
|
5819
7451
|
exports.DropdownMenuSubTrigger = DropdownMenuSubTrigger;
|
|
5820
7452
|
exports.DropdownMenuTrigger = DropdownMenuTrigger;
|
|
7453
|
+
exports.ENTITY_MAPPINGS = ENTITY_MAPPINGS;
|
|
5821
7454
|
exports.EmlIcon = EmlIcon;
|
|
7455
|
+
exports.EntityIcon = EntityIcon;
|
|
5822
7456
|
exports.EntityPill = EntityPill;
|
|
5823
7457
|
exports.FILE_TYPE_COLORS = FILE_TYPE_COLORS;
|
|
5824
7458
|
exports.FileIcon = FileIcon;
|
|
@@ -5830,12 +7464,19 @@ exports.HoverCard = HoverCard;
|
|
|
5830
7464
|
exports.HoverCardContent = HoverCardContent;
|
|
5831
7465
|
exports.HoverCardTrigger = HoverCardTrigger;
|
|
5832
7466
|
exports.HtmlIcon = HtmlIcon;
|
|
7467
|
+
exports.ImageCropModal = ImageCropModal;
|
|
7468
|
+
exports.ImageCropper = ImageCropper;
|
|
5833
7469
|
exports.ImgIcon = ImgIcon;
|
|
5834
7470
|
exports.Input = Input;
|
|
5835
7471
|
exports.Label = Label;
|
|
5836
7472
|
exports.LinkedInIcon = LinkedInIcon;
|
|
5837
7473
|
exports.MessageArtifactCard = MessageArtifactCard;
|
|
7474
|
+
exports.MessageBubble = MessageBubble2;
|
|
7475
|
+
exports.MessageThread = MessageThread;
|
|
7476
|
+
exports.NEUTRAL_GRAY = NEUTRAL_GRAY2;
|
|
7477
|
+
exports.NotificationBell = NotificationBell;
|
|
5838
7478
|
exports.OpenAIIcon = OpenAIIcon;
|
|
7479
|
+
exports.PLACEHOLDER_COLOR = PLACEHOLDER_COLOR;
|
|
5839
7480
|
exports.PdfIcon = PdfIcon;
|
|
5840
7481
|
exports.Popover = Popover;
|
|
5841
7482
|
exports.PopoverAnchor = PopoverAnchor;
|
|
@@ -5877,6 +7518,7 @@ exports.TabsList = TabsList;
|
|
|
5877
7518
|
exports.TabsTrigger = TabsTrigger;
|
|
5878
7519
|
exports.TagEntity = TagEntity;
|
|
5879
7520
|
exports.Textarea = Textarea;
|
|
7521
|
+
exports.Toaster = Toaster;
|
|
5880
7522
|
exports.Toggle = Toggle;
|
|
5881
7523
|
exports.ToggleGroup = ToggleGroup;
|
|
5882
7524
|
exports.ToggleGroupItem = ToggleGroupItem;
|
|
@@ -5887,20 +7529,41 @@ exports.TooltipTrigger = TooltipTrigger;
|
|
|
5887
7529
|
exports.TxtIcon = TxtIcon;
|
|
5888
7530
|
exports.TypingIndicator = TypingIndicator;
|
|
5889
7531
|
exports.UserEntity = UserEntity;
|
|
7532
|
+
exports.UserMenu = UserMenu;
|
|
7533
|
+
exports.VISIBILITY_ICONS = VISIBILITY_ICONS;
|
|
5890
7534
|
exports.VidIcon = VidIcon;
|
|
7535
|
+
exports.VisibilityIcon = VisibilityIcon;
|
|
5891
7536
|
exports.XlsIcon = XlsIcon;
|
|
5892
7537
|
exports.arbiQueryKeys = arbiQueryKeys;
|
|
5893
7538
|
exports.badgeVariants = badgeVariants;
|
|
5894
7539
|
exports.buttonVariants = buttonVariants;
|
|
5895
7540
|
exports.cardVariants = cardVariants;
|
|
5896
7541
|
exports.cn = cn;
|
|
7542
|
+
exports.configureEntityRegistry = configureEntityRegistry;
|
|
7543
|
+
exports.cropImage = cropImage;
|
|
7544
|
+
exports.describeActivity = describeActivity;
|
|
7545
|
+
exports.formatRelativeTime = formatRelativeTime;
|
|
7546
|
+
exports.getEntityColor = getEntityColor2;
|
|
7547
|
+
exports.getEntityColorStyles = getEntityColorStyles;
|
|
7548
|
+
exports.getEntityIcon = getEntityIcon;
|
|
7549
|
+
exports.getEntityLabel = getEntityLabel;
|
|
7550
|
+
exports.getNotificationTypeMeta = getNotificationTypeMeta;
|
|
5897
7551
|
exports.getTagTypeIcon = getTagTypeIcon;
|
|
5898
7552
|
exports.getTagTypeLabel = getTagTypeLabel;
|
|
7553
|
+
exports.getWorkspaceActionText = getWorkspaceActionText;
|
|
7554
|
+
exports.getWorkspaceColor = getWorkspaceColor;
|
|
7555
|
+
exports.getWorkspaceSentPhrase = getWorkspaceSentPhrase;
|
|
7556
|
+
exports.isWorkspaceNotificationType = isWorkspaceNotificationType;
|
|
5899
7557
|
exports.markdownBaseComponents = markdownBaseComponents;
|
|
7558
|
+
exports.notify = notify;
|
|
7559
|
+
exports.parseActivityContent = parseActivityContent;
|
|
5900
7560
|
exports.redlineStats = redlineStats;
|
|
7561
|
+
exports.seedNotifications = seedNotifications;
|
|
7562
|
+
exports.selectUnread = selectUnread;
|
|
5901
7563
|
exports.textToArtifact = textToArtifact;
|
|
5902
7564
|
exports.toRedlineMarkdown = toRedlineMarkdown;
|
|
5903
7565
|
exports.toggleVariants = toggleVariants;
|
|
7566
|
+
exports.useActivity = useActivity;
|
|
5904
7567
|
exports.useAgents = useAgents;
|
|
5905
7568
|
exports.useAiTask = useAiTask;
|
|
5906
7569
|
exports.useArbi = useArbi;
|
|
@@ -5915,19 +7578,30 @@ exports.useArbiWsStore = useArbiWsStore;
|
|
|
5915
7578
|
exports.useArbiWsTask = useArbiWsTask;
|
|
5916
7579
|
exports.useArbiWsTasks = useArbiWsTasks;
|
|
5917
7580
|
exports.useAssistantQuery = useAssistantQuery;
|
|
7581
|
+
exports.useCommandPalette = useCommandPalette;
|
|
5918
7582
|
exports.useConfigs = useConfigs;
|
|
5919
7583
|
exports.useConversations = useConversations;
|
|
5920
7584
|
exports.useDeleteAgents = useDeleteAgents;
|
|
7585
|
+
exports.useDirectMessages = useDirectMessages;
|
|
5921
7586
|
exports.useDocuments = useDocuments;
|
|
5922
7587
|
exports.useHealth = useHealth;
|
|
5923
7588
|
exports.useMemories = useMemories;
|
|
7589
|
+
exports.useNotify = useNotify;
|
|
5924
7590
|
exports.useParsedDocument = useParsedDocument;
|
|
7591
|
+
exports.useProjectInvoices = useProjectInvoices;
|
|
7592
|
+
exports.useProjectUsage = useProjectUsage;
|
|
7593
|
+
exports.useProjects = useProjects;
|
|
7594
|
+
exports.useProjectsUsage = useProjectsUsage;
|
|
5925
7595
|
exports.useSemanticSearch = useSemanticSearch;
|
|
5926
7596
|
exports.useSessions = useSessions;
|
|
5927
7597
|
exports.useTags = useTags;
|
|
5928
7598
|
exports.useTasks = useTasks;
|
|
5929
7599
|
exports.useThumbnails = useThumbnails;
|
|
7600
|
+
exports.useUserUsageToday = useUserUsageToday;
|
|
7601
|
+
exports.useWorkspaceChronology = useWorkspaceChronology;
|
|
5930
7602
|
exports.useWorkspaceDocs = useWorkspaceDocs;
|
|
5931
7603
|
exports.useWorkspaces = useWorkspaces;
|
|
7604
|
+
exports.userDisplayName = userDisplayName;
|
|
7605
|
+
exports.userInitials = userInitials;
|
|
5932
7606
|
//# sourceMappingURL=index.cjs.map
|
|
5933
7607
|
//# sourceMappingURL=index.cjs.map
|