@peers-app/peers-ui 0.27.2 → 0.27.4
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/screens/network-viewer/network-viewer-ipc.d.ts +3 -1
- package/dist/screens/network-viewer/network-viewer-ipc.js +6 -0
- package/dist/screens/network-viewer/sync-recovery.js +103 -1
- package/dist/screens/variables/variable-details.js +2 -1
- package/dist/tabs-layout/network-status-indicator.js +26 -12
- package/dist/tabs-layout/use-network-status.d.ts +6 -1
- package/dist/tabs-layout/use-network-status.js +27 -4
- package/package.json +9 -3
- package/.claude/settings.local.json +0 -34
- package/.github/README.md +0 -52
- package/.github/workflows/delete-all-artifacts.yml +0 -49
- package/.github/workflows/publish.yml +0 -51
- package/babel.config.js +0 -7
- package/biome.json +0 -198
- package/dist/app-updates/app-updates-consumer.test.d.ts +0 -1
- package/dist/app-updates/app-updates-consumer.test.js +0 -56
- package/dist/app-updates/app-updates-settings.test.d.ts +0 -1
- package/dist/app-updates/app-updates-settings.test.js +0 -93
- package/dist/app-updates/remote-app-update-panel.test.d.ts +0 -1
- package/dist/app-updates/remote-app-update-panel.test.js +0 -165
- package/dist/components/access-level-field.test.d.ts +0 -1
- package/dist/components/access-level-field.test.js +0 -28
- package/dist/components/message-logs/tool-access-approval-card.test.d.ts +0 -1
- package/dist/components/message-logs/tool-access-approval-card.test.js +0 -102
- package/dist/components/responsive-section-nav.test.d.ts +0 -1
- package/dist/components/responsive-section-nav.test.js +0 -45
- package/dist/globals-hash.test.d.ts +0 -1
- package/dist/globals-hash.test.js +0 -16
- package/dist/hooks/use-observable-state.test.d.ts +0 -1
- package/dist/hooks/use-observable-state.test.js +0 -64
- package/dist/hooks/use-observable.test.d.ts +0 -1
- package/dist/hooks/use-observable.test.js +0 -191
- package/dist/hooks/use-rows.test.d.ts +0 -1
- package/dist/hooks/use-rows.test.js +0 -175
- package/dist/hooks/use-tool.test.d.ts +0 -1
- package/dist/hooks/use-tool.test.js +0 -190
- package/dist/host-shell/host-shell-consumer.test.d.ts +0 -1
- package/dist/host-shell/host-shell-consumer.test.js +0 -28
- package/dist/root-layout/root-layout-host.test.d.ts +0 -1
- package/dist/root-layout/root-layout-host.test.js +0 -86
- package/dist/screens/account/account-screen.test.d.ts +0 -1
- package/dist/screens/account/account-screen.test.js +0 -51
- package/dist/screens/assistants/assistant-config.test.d.ts +0 -1
- package/dist/screens/assistants/assistant-config.test.js +0 -57
- package/dist/screens/contacts/contact-list.test.d.ts +0 -1
- package/dist/screens/contacts/contact-list.test.js +0 -48
- package/dist/screens/device-pairing/device-pairing.test.d.ts +0 -1
- package/dist/screens/device-pairing/device-pairing.test.js +0 -119
- package/dist/screens/devices/devices-list.test.d.ts +0 -1
- package/dist/screens/devices/devices-list.test.js +0 -53
- package/dist/screens/groups/group-list.test.d.ts +0 -1
- package/dist/screens/groups/group-list.test.js +0 -38
- package/dist/screens/identity/identity-routes.test.d.ts +0 -1
- package/dist/screens/identity/identity-routes.test.js +0 -51
- package/dist/screens/identity/identity-screen.test.d.ts +0 -1
- package/dist/screens/identity/identity-screen.test.js +0 -103
- package/dist/screens/invites/accept-invite.test.d.ts +0 -1
- package/dist/screens/invites/accept-invite.test.js +0 -103
- package/dist/screens/invites/activity-view.test.d.ts +0 -1
- package/dist/screens/invites/activity-view.test.js +0 -108
- package/dist/screens/invites/invite-classify.test.d.ts +0 -1
- package/dist/screens/invites/invite-classify.test.js +0 -115
- package/dist/screens/network-viewer/network-viewer-ipc.test.d.ts +0 -1
- package/dist/screens/network-viewer/network-viewer-ipc.test.js +0 -61
- package/dist/screens/network-viewer/network-viewer.section.test.d.ts +0 -1
- package/dist/screens/network-viewer/network-viewer.section.test.js +0 -63
- package/dist/screens/network-viewer/sync-recovery.test.d.ts +0 -1
- package/dist/screens/network-viewer/sync-recovery.test.js +0 -104
- package/dist/screens/packages/package-helpers.test.d.ts +0 -1
- package/dist/screens/packages/package-helpers.test.js +0 -53
- package/dist/screens/packages/package-runtime-status.test.d.ts +0 -1
- package/dist/screens/packages/package-runtime-status.test.js +0 -50
- package/dist/screens/packages/packages-ipc.test.d.ts +0 -1
- package/dist/screens/packages/packages-ipc.test.js +0 -43
- package/dist/screens/settings/settings-page.test.d.ts +0 -1
- package/dist/screens/settings/settings-page.test.js +0 -19
- package/dist/screens/tools/tool-access-ipc.test.d.ts +0 -1
- package/dist/screens/tools/tool-access-ipc.test.js +0 -40
- package/dist/screens/tools/tool-catalog-ipc.test.d.ts +0 -1
- package/dist/screens/tools/tool-catalog-ipc.test.js +0 -52
- package/dist/tabs-layout/network-status-indicator.test.d.ts +0 -1
- package/dist/tabs-layout/network-status-indicator.test.js +0 -665
- package/dist/tabs-layout/tabs-state.test.d.ts +0 -1
- package/dist/tabs-layout/tabs-state.test.js +0 -110
- package/dist/tabs-layout/use-network-status.test.d.ts +0 -1
- package/dist/tabs-layout/use-network-status.test.js +0 -45
- package/dist/ui-router/ui-loader.test.d.ts +0 -1
- package/dist/ui-router/ui-loader.test.js +0 -91
- package/jest.config.js +0 -25
- package/release-guard.js +0 -10
- package/src/app-updates/app-update-controls.tsx +0 -73
- package/src/app-updates/app-updates-consumer.test.ts +0 -83
- package/src/app-updates/app-updates-consumer.ts +0 -121
- package/src/app-updates/app-updates-settings.test.tsx +0 -109
- package/src/app-updates/app-updates-settings.tsx +0 -136
- package/src/app-updates/remote-app-update-panel.test.tsx +0 -205
- package/src/app-updates/remote-app-update-panel.tsx +0 -210
- package/src/app-updates/use-app-update-status.ts +0 -16
- package/src/command-palette/command-palette-ui.tsx +0 -564
- package/src/command-palette/command-palette.ts +0 -242
- package/src/components/access-level-field.test.tsx +0 -32
- package/src/components/access-level-field.tsx +0 -68
- package/src/components/checkbox.tsx +0 -25
- package/src/components/group-switcher.tsx +0 -526
- package/src/components/input-date.tsx +0 -29
- package/src/components/input-number.tsx +0 -83
- package/src/components/input.tsx +0 -25
- package/src/components/inverse-lazy-list.tsx +0 -107
- package/src/components/io-schema-values.tsx +0 -103
- package/src/components/io-schema.tsx +0 -259
- package/src/components/lazy-list.tsx +0 -115
- package/src/components/list-screen.tsx +0 -126
- package/src/components/loading-indicator.tsx +0 -7
- package/src/components/markdown-editor/autolink-plugin.tsx +0 -29
- package/src/components/markdown-editor/editor-inline.tsx +0 -9
- package/src/components/markdown-editor/editor.tsx +0 -158
- package/src/components/markdown-editor/markdown-plugin.tsx +0 -202
- package/src/components/markdown-editor/mention-node.ts +0 -204
- package/src/components/markdown-editor/mentions-plugin.tsx +0 -354
- package/src/components/markdown-editor/move-line-plugin.tsx +0 -186
- package/src/components/markdown-editor/select-line-boundary-plugin.tsx +0 -95
- package/src/components/markdown-editor/theme.ts +0 -46
- package/src/components/markdown-editor/toolbar.tsx +0 -269
- package/src/components/markdown-with-mentions.tsx +0 -198
- package/src/components/message-logs/message-logs.tsx +0 -523
- package/src/components/message-logs/tool-access-approval-card.test.tsx +0 -127
- package/src/components/message-logs/tool-access-approval-card.tsx +0 -178
- package/src/components/messages/avatar.tsx +0 -171
- package/src/components/messages/channel-message-list.tsx +0 -189
- package/src/components/messages/channel-view.tsx +0 -92
- package/src/components/messages/message-compose.tsx +0 -192
- package/src/components/messages/message-display.tsx +0 -231
- package/src/components/messages/thread-message-list.tsx +0 -135
- package/src/components/qr-scanner.tsx +0 -180
- package/src/components/responsive-section-nav.test.tsx +0 -88
- package/src/components/responsive-section-nav.tsx +0 -92
- package/src/components/router.tsx +0 -175
- package/src/components/save-button.tsx +0 -134
- package/src/components/sortable-list.tsx +0 -130
- package/src/components/tabs.tsx +0 -76
- package/src/components/tooltip.tsx +0 -43
- package/src/components/trust-level-badge.tsx +0 -44
- package/src/components/trust-level-dropdown.tsx +0 -136
- package/src/components/typeahead.tsx +0 -357
- package/src/globals-hash.test.ts +0 -19
- package/src/globals.tsx +0 -226
- package/src/hooks/index.ts +0 -8
- package/src/hooks/use-host-contract.ts +0 -75
- package/src/hooks/use-observable-state.test.tsx +0 -101
- package/src/hooks/use-observable-state.ts +0 -29
- package/src/hooks/use-observable.test.tsx +0 -258
- package/src/hooks/use-observable.ts +0 -67
- package/src/hooks/use-on-screen.ts +0 -24
- package/src/hooks/use-promise.ts +0 -34
- package/src/hooks/use-rows.test.tsx +0 -196
- package/src/hooks/use-rows.ts +0 -120
- package/src/hooks/use-subscription.ts +0 -24
- package/src/hooks/use-tool.test.tsx +0 -225
- package/src/hooks/use-tool.ts +0 -116
- package/src/host-shell/host-shell-consumer.test.ts +0 -32
- package/src/host-shell/host-shell-consumer.ts +0 -53
- package/src/index.tsx +0 -42
- package/src/mention-configs.ts +0 -185
- package/src/operator-console/operator-console-state.ts +0 -119
- package/src/operator-console/operator-console.tsx +0 -233
- package/src/peers-services-registration.ts +0 -6
- package/src/root-layout/global-overlays.ts +0 -50
- package/src/root-layout/layout-picker.tsx +0 -47
- package/src/root-layout/layouts/full-screen-layout.tsx +0 -144
- package/src/root-layout/layouts/tabs-with-console-layout.tsx +0 -260
- package/src/root-layout/root-layout-host.test.tsx +0 -108
- package/src/root-layout/root-layout-host.tsx +0 -147
- package/src/root-layout/root-layout-registry.ts +0 -51
- package/src/root-layout/root-layout-state.ts +0 -55
- package/src/root-layout/root-layout.ts +0 -32
- package/src/screens/account/account-screen.test.tsx +0 -65
- package/src/screens/account/account-screen.tsx +0 -942
- package/src/screens/assistants/assistant-config.test.tsx +0 -54
- package/src/screens/assistants/assistant-config.tsx +0 -121
- package/src/screens/assistants/assistant-details.tsx +0 -89
- package/src/screens/assistants/assistant-info.tsx +0 -66
- package/src/screens/assistants/assistant-list.tsx +0 -145
- package/src/screens/assistants/assistant-tools.tsx +0 -82
- package/src/screens/console-logs/console-logs-list.tsx +0 -374
- package/src/screens/console-logs/log-display.tsx +0 -137
- package/src/screens/console-logs/log-filters.tsx +0 -64
- package/src/screens/console-logs/mobile-log-card.tsx +0 -161
- package/src/screens/console-logs/resizable-table-header.tsx +0 -110
- package/src/screens/contacts/contact-details.tsx +0 -123
- package/src/screens/contacts/contact-list.test.tsx +0 -59
- package/src/screens/contacts/contact-list.tsx +0 -286
- package/src/screens/contacts/index.ts +0 -2
- package/src/screens/data-explorer/data-explorer.tsx +0 -633
- package/src/screens/data-explorer/index.ts +0 -6
- package/src/screens/data-explorer/query-executor.tsx +0 -520
- package/src/screens/device-pairing/device-pairing.test.tsx +0 -143
- package/src/screens/device-pairing/device-pairing.tsx +0 -461
- package/src/screens/device-pairing/identity-ipc.ts +0 -25
- package/src/screens/device-pairing/index.ts +0 -2
- package/src/screens/device-pairing/use-device-pairing-state.ts +0 -15
- package/src/screens/devices/devices-list.test.tsx +0 -68
- package/src/screens/devices/devices-list.tsx +0 -365
- package/src/screens/devices/index.ts +0 -1
- package/src/screens/groups/group-details.tsx +0 -160
- package/src/screens/groups/group-invite-panel.tsx +0 -311
- package/src/screens/groups/group-list.test.tsx +0 -44
- package/src/screens/groups/group-list.tsx +0 -317
- package/src/screens/groups/group-members.tsx +0 -343
- package/src/screens/groups/index.ts +0 -3
- package/src/screens/identity/identity-routes.test.ts +0 -70
- package/src/screens/identity/identity-routes.ts +0 -301
- package/src/screens/identity/identity-screen.test.tsx +0 -138
- package/src/screens/identity/identity-screen.tsx +0 -282
- package/src/screens/identity/index.ts +0 -2
- package/src/screens/identity/invite-contact-panel.tsx +0 -45
- package/src/screens/identity/profile-invite.tsx +0 -93
- package/src/screens/invites/accept-invite.test.tsx +0 -115
- package/src/screens/invites/accept-invite.tsx +0 -318
- package/src/screens/invites/activity-view.test.tsx +0 -127
- package/src/screens/invites/activity-view.tsx +0 -162
- package/src/screens/invites/index.ts +0 -6
- package/src/screens/invites/invite-capture.ts +0 -104
- package/src/screens/invites/invite-classify.test.ts +0 -129
- package/src/screens/invites/invite-share.tsx +0 -104
- package/src/screens/invites/invites-ipc.ts +0 -25
- package/src/screens/invites/pending-invites-list.tsx +0 -256
- package/src/screens/network-viewer/connection-troubleshooter.tsx +0 -395
- package/src/screens/network-viewer/cpu-usage-graph.tsx +0 -294
- package/src/screens/network-viewer/device-details-modal.tsx +0 -339
- package/src/screens/network-viewer/group-details-modal.tsx +0 -421
- package/src/screens/network-viewer/index.ts +0 -8
- package/src/screens/network-viewer/network-viewer-ipc.test.ts +0 -72
- package/src/screens/network-viewer/network-viewer-ipc.ts +0 -39
- package/src/screens/network-viewer/network-viewer-section.ts +0 -12
- package/src/screens/network-viewer/network-viewer.section.test.tsx +0 -68
- package/src/screens/network-viewer/network-viewer.tsx +0 -708
- package/src/screens/network-viewer/remote-logs-panel.tsx +0 -190
- package/src/screens/network-viewer/sync-recovery.test.tsx +0 -114
- package/src/screens/network-viewer/sync-recovery.tsx +0 -461
- package/src/screens/network-viewer/usage-graph.tsx +0 -455
- package/src/screens/packages/local-folder-grants-panel.tsx +0 -290
- package/src/screens/packages/local-folders-ipc.ts +0 -28
- package/src/screens/packages/package-details.tsx +0 -166
- package/src/screens/packages/package-helpers.test.ts +0 -57
- package/src/screens/packages/package-helpers.ts +0 -137
- package/src/screens/packages/package-info.tsx +0 -354
- package/src/screens/packages/package-list.tsx +0 -519
- package/src/screens/packages/package-network-panel.tsx +0 -82
- package/src/screens/packages/package-new-local.tsx +0 -100
- package/src/screens/packages/package-runtime-status.test.tsx +0 -58
- package/src/screens/packages/package-runtime-status.tsx +0 -68
- package/src/screens/packages/package-versions.tsx +0 -298
- package/src/screens/packages/packages-ipc.test.ts +0 -47
- package/src/screens/packages/packages-ipc.ts +0 -125
- package/src/screens/peer-types/peer-type-details.tsx +0 -172
- package/src/screens/peer-types/peer-type-list.tsx +0 -64
- package/src/screens/search/global-search.tsx +0 -406
- package/src/screens/settings/color-mode-dropdown.tsx +0 -82
- package/src/screens/settings/settings-page.test.tsx +0 -24
- package/src/screens/settings/settings-page.tsx +0 -426
- package/src/screens/setup-user.tsx +0 -355
- package/src/screens/tools/tool-access-ipc.test.ts +0 -55
- package/src/screens/tools/tool-access-ipc.ts +0 -27
- package/src/screens/tools/tool-catalog-ipc.test.ts +0 -52
- package/src/screens/tools/tool-catalog-ipc.ts +0 -51
- package/src/screens/tools/tool-details.tsx +0 -52
- package/src/screens/tools/tool-info.tsx +0 -45
- package/src/screens/tools/tool-list.tsx +0 -106
- package/src/screens/tools/tool-schema.tsx +0 -44
- package/src/screens/tools/tool-test-details.tsx +0 -89
- package/src/screens/tools/tool-test-list.tsx +0 -73
- package/src/screens/variables/variable-details.tsx +0 -289
- package/src/screens/variables/variable-list.tsx +0 -110
- package/src/screens/welcome-modal.tsx +0 -294
- package/src/screens/workflows/workflow-details.tsx +0 -115
- package/src/screens/workflows/workflow-info.tsx +0 -22
- package/src/screens/workflows/workflow-instructions.tsx +0 -134
- package/src/screens/workflows/workflow-list.tsx +0 -117
- package/src/setupTests.ts +0 -38
- package/src/system-apps/assistants.app.ts +0 -7
- package/src/system-apps/console-logs.app.ts +0 -7
- package/src/system-apps/data-explorer.app.ts +0 -8
- package/src/system-apps/identity.app.ts +0 -9
- package/src/system-apps/index.ts +0 -77
- package/src/system-apps/mobile-settings.app.ts +0 -7
- package/src/system-apps/network-viewer.app.ts +0 -8
- package/src/system-apps/packages.app.ts +0 -7
- package/src/system-apps/search.app.ts +0 -8
- package/src/system-apps/settings.app.ts +0 -7
- package/src/system-apps/threads.app.ts +0 -7
- package/src/system-apps/tools.app.ts +0 -7
- package/src/system-apps/types.app.ts +0 -7
- package/src/system-apps/variables.app.ts +0 -7
- package/src/system-apps/workflows.app.ts +0 -7
- package/src/tabs-layout/network-status-indicator.test.tsx +0 -799
- package/src/tabs-layout/network-status-indicator.tsx +0 -756
- package/src/tabs-layout/tabs-layout.tsx +0 -857
- package/src/tabs-layout/tabs-state.test.ts +0 -152
- package/src/tabs-layout/tabs-state.ts +0 -587
- package/src/tabs-layout/use-network-status.test.tsx +0 -58
- package/src/tabs-layout/use-network-status.ts +0 -68
- package/src/ui-defaults/index.ts +0 -2
- package/src/ui-defaults/list-screen.tsx +0 -94
- package/src/ui-defaults/markdown-field.tsx +0 -87
- package/src/ui-router/routes-loader.ts +0 -193
- package/src/ui-router/ui-loader.test.tsx +0 -108
- package/src/ui-router/ui-loader.tsx +0 -606
- package/src/utils.ts +0 -95
- package/tsconfig.json +0 -18
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AccessLevel,
|
|
3
|
-
ToolAccessApprovalScope,
|
|
4
|
-
ToolAccessApprovalStatus,
|
|
5
|
-
} from "@peers-app/peers-sdk";
|
|
6
|
-
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
7
|
-
import { ToolAccessApprovalCard } from "./tool-access-approval-card";
|
|
8
|
-
|
|
9
|
-
const approve = jest.fn(async () => ({ result: { status: "executed" } }));
|
|
10
|
-
const reject = jest.fn(async () => ({ result: { status: "rejected" } }));
|
|
11
|
-
const getDataContext = jest.fn((dataContextId: string) => ({ dataContextId }));
|
|
12
|
-
const getToolAccessControlConsumer = jest.fn(async (_dataContextId: string) => ({
|
|
13
|
-
tools: { approve, reject },
|
|
14
|
-
}));
|
|
15
|
-
|
|
16
|
-
jest.mock("../../screens/tools/tool-access-ipc", () => ({
|
|
17
|
-
getToolAccessControlConsumer: (dataContextId: string) =>
|
|
18
|
-
getToolAccessControlConsumer(dataContextId),
|
|
19
|
-
}));
|
|
20
|
-
|
|
21
|
-
jest.mock("@peers-app/peers-sdk", () => {
|
|
22
|
-
const actual = jest.requireActual("@peers-app/peers-sdk");
|
|
23
|
-
return {
|
|
24
|
-
...actual,
|
|
25
|
-
getUserContext: async () => ({
|
|
26
|
-
getDataContext,
|
|
27
|
-
}),
|
|
28
|
-
getCurrentUserAccessLevel: async () => actual.AccessLevel.Self,
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const pending = {
|
|
33
|
-
toolAccessApprovalId: "00testapproval0000000001",
|
|
34
|
-
userId: "00testuser000000000000001",
|
|
35
|
-
assistantId: "00testassistant000000001",
|
|
36
|
-
toolId: "00testtooladmin00000000",
|
|
37
|
-
toolName: "queryDatabase",
|
|
38
|
-
dataContextId: "00testdatacontext00000001",
|
|
39
|
-
argsHash: "hash",
|
|
40
|
-
argsPreview: '{"sql":"select 1"}',
|
|
41
|
-
frozenArgs: { sql: "select 1" },
|
|
42
|
-
requiredAccessLevel: AccessLevel.Owner,
|
|
43
|
-
scope: ToolAccessApprovalScope.once,
|
|
44
|
-
status: ToolAccessApprovalStatus.pending,
|
|
45
|
-
nonce: "nonce-from-table",
|
|
46
|
-
expiresAt: new Date(Date.now() + 60_000),
|
|
47
|
-
createdAt: new Date(),
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
describe("ToolAccessApprovalCard", () => {
|
|
51
|
-
beforeEach(() => {
|
|
52
|
-
approve.mockClear();
|
|
53
|
-
reject.mockClear();
|
|
54
|
-
getDataContext.mockClear();
|
|
55
|
-
getToolAccessControlConsumer.mockClear();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("renders a pending card with actions", () => {
|
|
59
|
-
render(<ToolAccessApprovalCard approval={pending as any} />);
|
|
60
|
-
expect(screen.getByText("Approval required")).toBeInTheDocument();
|
|
61
|
-
expect(screen.getByText("queryDatabase")).toBeInTheDocument();
|
|
62
|
-
expect(screen.getByText(/Owner \(80\)/)).toBeInTheDocument();
|
|
63
|
-
expect(screen.getByRole("button", { name: "Allow once" })).toBeInTheDocument();
|
|
64
|
-
expect(screen.getByRole("button", { name: "Allow in thread (15 min)" })).toBeInTheDocument();
|
|
65
|
-
expect(
|
|
66
|
-
screen.getByRole("button", { name: "Allow in this context (15 min)" }),
|
|
67
|
-
).toBeInTheDocument();
|
|
68
|
-
expect(screen.getByRole("button", { name: "Deny" })).toBeInTheDocument();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("evaluates the user role in the approval context", async () => {
|
|
72
|
-
render(<ToolAccessApprovalCard approval={pending as any} />);
|
|
73
|
-
await waitFor(() => {
|
|
74
|
-
expect(getDataContext).toHaveBeenCalledWith(pending.dataContextId);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("approves once using the table nonce", async () => {
|
|
79
|
-
render(<ToolAccessApprovalCard approval={pending as any} />);
|
|
80
|
-
fireEvent.click(screen.getByRole("button", { name: "Allow once" }));
|
|
81
|
-
await waitFor(() => {
|
|
82
|
-
expect(getToolAccessControlConsumer).toHaveBeenCalledWith(pending.dataContextId);
|
|
83
|
-
expect(approve).toHaveBeenCalledWith({
|
|
84
|
-
approvalId: pending.toolAccessApprovalId,
|
|
85
|
-
nonce: "nonce-from-table",
|
|
86
|
-
scope: "once",
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("denies using the table nonce", async () => {
|
|
92
|
-
render(<ToolAccessApprovalCard approval={pending as any} />);
|
|
93
|
-
fireEvent.click(screen.getByRole("button", { name: "Deny" }));
|
|
94
|
-
await waitFor(() => {
|
|
95
|
-
expect(reject).toHaveBeenCalledWith({
|
|
96
|
-
approvalId: pending.toolAccessApprovalId,
|
|
97
|
-
nonce: "nonce-from-table",
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("hides empty argument previews", () => {
|
|
103
|
-
render(
|
|
104
|
-
<ToolAccessApprovalCard
|
|
105
|
-
approval={{ ...pending, argsPreview: "{}", frozenArgs: {} } as any}
|
|
106
|
-
/>,
|
|
107
|
-
);
|
|
108
|
-
expect(screen.queryByText("{}")).not.toBeInTheDocument();
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("shows a decided card without actions", () => {
|
|
112
|
-
render(
|
|
113
|
-
<ToolAccessApprovalCard
|
|
114
|
-
approval={
|
|
115
|
-
{
|
|
116
|
-
...pending,
|
|
117
|
-
status: ToolAccessApprovalStatus.rejected,
|
|
118
|
-
resultSummary: "Rejected by user",
|
|
119
|
-
} as any
|
|
120
|
-
}
|
|
121
|
-
/>,
|
|
122
|
-
);
|
|
123
|
-
expect(screen.getByText("Access rejected")).toBeInTheDocument();
|
|
124
|
-
expect(screen.getByText("Rejected by user")).toBeInTheDocument();
|
|
125
|
-
expect(screen.queryByRole("button", { name: "Allow once" })).not.toBeInTheDocument();
|
|
126
|
-
});
|
|
127
|
-
});
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getAccessLevelLabel,
|
|
3
|
-
getCurrentUserAccessLevel,
|
|
4
|
-
getUserContext,
|
|
5
|
-
type IToolAccessApproval,
|
|
6
|
-
recordAccessLevel,
|
|
7
|
-
TOOL_ACCESS_GRANT_TTL_MS,
|
|
8
|
-
ToolAccessApprovalStatus,
|
|
9
|
-
} from "@peers-app/peers-sdk";
|
|
10
|
-
import { useState } from "react";
|
|
11
|
-
import { usePromise } from "../../hooks";
|
|
12
|
-
import { getToolAccessControlConsumer } from "../../screens/tools/tool-access-ipc";
|
|
13
|
-
|
|
14
|
-
const GRANT_TTL_MINUTES = TOOL_ACCESS_GRANT_TTL_MS / (60 * 1000);
|
|
15
|
-
|
|
16
|
-
/** Props for {@link ToolAccessApprovalCard}. */
|
|
17
|
-
export interface ToolAccessApprovalCardProps {
|
|
18
|
-
/** Approval or grant row to render. */
|
|
19
|
-
approval: IToolAccessApproval;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Inline thread card for a pending or decided tool-access approval.
|
|
24
|
-
*
|
|
25
|
-
* Uses Bootstrap theme tokens (`bg-body-*`, `text-body-*`) so the card follows
|
|
26
|
-
* light and dark `data-bs-theme` instead of a hardcoded `bg-light` panel.
|
|
27
|
-
*/
|
|
28
|
-
export function ToolAccessApprovalCard(props: ToolAccessApprovalCardProps) {
|
|
29
|
-
const { approval } = props;
|
|
30
|
-
const [busy, setBusy] = useState(false);
|
|
31
|
-
const [error, setError] = useState<string | undefined>();
|
|
32
|
-
const userLevel = usePromise(
|
|
33
|
-
async () => {
|
|
34
|
-
const userContext = await getUserContext();
|
|
35
|
-
return getCurrentUserAccessLevel(userContext.getDataContext(approval.dataContextId));
|
|
36
|
-
},
|
|
37
|
-
recordAccessLevel({ accessLevel: 100 }),
|
|
38
|
-
[approval.dataContextId],
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const required = approval.requiredAccessLevel;
|
|
42
|
-
const current = userLevel ?? 100;
|
|
43
|
-
const pending = approval.status === ToolAccessApprovalStatus.pending;
|
|
44
|
-
const expired = approval.expiresAt.getTime() <= Date.now();
|
|
45
|
-
const argsPreview = meaningfulArgsPreview(approval.argsPreview);
|
|
46
|
-
const statusStyle = statusAppearance(approval.status, expired);
|
|
47
|
-
|
|
48
|
-
async function decide(scope?: "once" | "thread" | "context", reject = false) {
|
|
49
|
-
setBusy(true);
|
|
50
|
-
setError(undefined);
|
|
51
|
-
try {
|
|
52
|
-
const consumer = await getToolAccessControlConsumer(approval.dataContextId);
|
|
53
|
-
if (reject) {
|
|
54
|
-
await consumer.tools.reject({
|
|
55
|
-
approvalId: approval.toolAccessApprovalId,
|
|
56
|
-
nonce: approval.nonce,
|
|
57
|
-
});
|
|
58
|
-
} else {
|
|
59
|
-
await consumer.tools.approve({
|
|
60
|
-
approvalId: approval.toolAccessApprovalId,
|
|
61
|
-
nonce: approval.nonce,
|
|
62
|
-
scope,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
} catch (err) {
|
|
66
|
-
setError(String(err));
|
|
67
|
-
} finally {
|
|
68
|
-
setBusy(false);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return (
|
|
73
|
-
<div
|
|
74
|
-
className="card my-2 bg-body-secondary border-secondary-subtle"
|
|
75
|
-
data-testid="tool-access-approval-card"
|
|
76
|
-
>
|
|
77
|
-
<div className="card-body py-2 px-3">
|
|
78
|
-
<div className="d-flex align-items-start gap-2">
|
|
79
|
-
<i
|
|
80
|
-
className={`bi ${statusStyle.icon} ${statusStyle.iconClass} mt-1`}
|
|
81
|
-
aria-hidden="true"
|
|
82
|
-
/>
|
|
83
|
-
<div className="flex-grow-1 min-w-0">
|
|
84
|
-
<div className="fw-semibold text-body">
|
|
85
|
-
{pending ? "Approval required" : `Access ${approval.status}`}
|
|
86
|
-
</div>
|
|
87
|
-
<div className="small text-body">
|
|
88
|
-
<code className="text-body">{approval.toolName}</code> needs{" "}
|
|
89
|
-
{getAccessLevelLabel(required)} ({required}). You have {getAccessLevelLabel(current)}{" "}
|
|
90
|
-
({current}).
|
|
91
|
-
</div>
|
|
92
|
-
{argsPreview && (
|
|
93
|
-
<pre
|
|
94
|
-
className="small mb-2 mt-2 p-2 bg-body-tertiary border rounded text-body"
|
|
95
|
-
style={{ whiteSpace: "pre-wrap" }}
|
|
96
|
-
>
|
|
97
|
-
{argsPreview}
|
|
98
|
-
</pre>
|
|
99
|
-
)}
|
|
100
|
-
<div className="text-body-secondary small mt-1">
|
|
101
|
-
Expires {approval.expiresAt.toLocaleTimeString()}
|
|
102
|
-
{expired ? " (expired)" : ""}
|
|
103
|
-
</div>
|
|
104
|
-
{approval.resultSummary && (
|
|
105
|
-
<div className="small text-body mt-1">{approval.resultSummary}</div>
|
|
106
|
-
)}
|
|
107
|
-
{error && <div className="text-danger small mt-1">{error}</div>}
|
|
108
|
-
{pending && !expired && (
|
|
109
|
-
<div className="d-flex flex-wrap gap-1 mt-2">
|
|
110
|
-
<button
|
|
111
|
-
type="button"
|
|
112
|
-
className="btn btn-sm btn-primary"
|
|
113
|
-
disabled={busy}
|
|
114
|
-
onClick={() => decide("once")}
|
|
115
|
-
>
|
|
116
|
-
Allow once
|
|
117
|
-
</button>
|
|
118
|
-
<button
|
|
119
|
-
type="button"
|
|
120
|
-
className="btn btn-sm btn-outline-secondary"
|
|
121
|
-
disabled={busy}
|
|
122
|
-
onClick={() => decide("thread")}
|
|
123
|
-
>
|
|
124
|
-
Allow in thread ({GRANT_TTL_MINUTES} min)
|
|
125
|
-
</button>
|
|
126
|
-
<button
|
|
127
|
-
type="button"
|
|
128
|
-
className="btn btn-sm btn-outline-secondary"
|
|
129
|
-
disabled={busy}
|
|
130
|
-
onClick={() => decide("context")}
|
|
131
|
-
>
|
|
132
|
-
Allow in this context ({GRANT_TTL_MINUTES} min)
|
|
133
|
-
</button>
|
|
134
|
-
<button
|
|
135
|
-
type="button"
|
|
136
|
-
className="btn btn-sm btn-outline-danger"
|
|
137
|
-
disabled={busy}
|
|
138
|
-
onClick={() => decide(undefined, true)}
|
|
139
|
-
>
|
|
140
|
-
Deny
|
|
141
|
-
</button>
|
|
142
|
-
</div>
|
|
143
|
-
)}
|
|
144
|
-
</div>
|
|
145
|
-
</div>
|
|
146
|
-
</div>
|
|
147
|
-
</div>
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function meaningfulArgsPreview(preview: string | undefined): string | undefined {
|
|
152
|
-
const trimmed = preview?.trim();
|
|
153
|
-
if (!trimmed || trimmed === "{}" || trimmed === "[]") {
|
|
154
|
-
return undefined;
|
|
155
|
-
}
|
|
156
|
-
return trimmed;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function statusAppearance(
|
|
160
|
-
status: ToolAccessApprovalStatus,
|
|
161
|
-
expired: boolean,
|
|
162
|
-
): { icon: string; iconClass: string } {
|
|
163
|
-
if (status === ToolAccessApprovalStatus.pending && expired) {
|
|
164
|
-
return { icon: "bi-shield-x", iconClass: "text-body-secondary" };
|
|
165
|
-
}
|
|
166
|
-
switch (status) {
|
|
167
|
-
case ToolAccessApprovalStatus.pending:
|
|
168
|
-
return { icon: "bi-shield-lock", iconClass: "text-warning" };
|
|
169
|
-
case ToolAccessApprovalStatus.approved:
|
|
170
|
-
case ToolAccessApprovalStatus.executed:
|
|
171
|
-
return { icon: "bi-shield-check", iconClass: "text-success" };
|
|
172
|
-
case ToolAccessApprovalStatus.rejected:
|
|
173
|
-
case ToolAccessApprovalStatus.failed:
|
|
174
|
-
return { icon: "bi-shield-x", iconClass: "text-danger" };
|
|
175
|
-
default:
|
|
176
|
-
return { icon: "bi-shield", iconClass: "text-body-secondary" };
|
|
177
|
-
}
|
|
178
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Assistants,
|
|
3
|
-
getUserContext,
|
|
4
|
-
getUserTrustLevel,
|
|
5
|
-
type IUser,
|
|
6
|
-
TrustLevel,
|
|
7
|
-
Users,
|
|
8
|
-
} from "@peers-app/peers-sdk";
|
|
9
|
-
import { usePromise } from "../../hooks";
|
|
10
|
-
|
|
11
|
-
interface IProps {
|
|
12
|
-
userId: string;
|
|
13
|
-
assistantId?: string;
|
|
14
|
-
setUser?: (user: IUser) => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const Avatar = (props: IProps) => {
|
|
18
|
-
const { userId, setUser: parentSetUser, assistantId } = props;
|
|
19
|
-
|
|
20
|
-
const user = usePromise(async () => {
|
|
21
|
-
const user = await Users().get(userId, { useCache: true });
|
|
22
|
-
if (user && parentSetUser) {
|
|
23
|
-
parentSetUser(user);
|
|
24
|
-
}
|
|
25
|
-
return user;
|
|
26
|
-
});
|
|
27
|
-
const assistant = usePromise(
|
|
28
|
-
async () => {
|
|
29
|
-
if (assistantId) {
|
|
30
|
-
return Assistants().get(assistantId, { useCache: true });
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
undefined,
|
|
34
|
-
[assistantId],
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
const trustLevel = usePromise(
|
|
38
|
-
async () => {
|
|
39
|
-
if (userId) {
|
|
40
|
-
const userContext = await getUserContext();
|
|
41
|
-
return await getUserTrustLevel(userContext.userDataContext, userId);
|
|
42
|
-
}
|
|
43
|
-
return TrustLevel.Unknown;
|
|
44
|
-
},
|
|
45
|
-
TrustLevel.Unknown,
|
|
46
|
-
[userId],
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
let initials = "?";
|
|
50
|
-
|
|
51
|
-
const name = assistant?.name || user?.name;
|
|
52
|
-
if (user) {
|
|
53
|
-
if (!name) {
|
|
54
|
-
initials = "!";
|
|
55
|
-
} else {
|
|
56
|
-
const words = name.split(" ");
|
|
57
|
-
const first = words[0];
|
|
58
|
-
const last = words.length > 1 ? words[words.length - 1] : words[0][1];
|
|
59
|
-
initials = first[0] + last[0];
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// TODO if user.avatarImage then get and show that
|
|
64
|
-
|
|
65
|
-
let backgroundColor = name ? stringToHslColor(name) : stringToHslColor("", 100, 100);
|
|
66
|
-
if (assistant) {
|
|
67
|
-
// backgroundColor = stringToHslColor(name || '', 100, 100);
|
|
68
|
-
backgroundColor = stringToHslColor("", 0, 70);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Get trust level config
|
|
72
|
-
const getTrustLevelConfig = (level: TrustLevel) => {
|
|
73
|
-
const configs = [
|
|
74
|
-
{ value: TrustLevel.Self, color: "#198754", icon: "bi-shield-fill-check" },
|
|
75
|
-
{ value: TrustLevel.Trusted, color: "#198754", icon: "bi-shield-fill-check" },
|
|
76
|
-
{ value: TrustLevel.Known, color: "#0d6efd", icon: "bi-shield-fill-check" },
|
|
77
|
-
{ value: TrustLevel.NewDevice, color: "#0dcaf0", icon: "bi-shield-fill-plus" },
|
|
78
|
-
{ value: TrustLevel.NewUser, color: "#0dcaf0", icon: "bi-shield-fill-plus" },
|
|
79
|
-
{ value: TrustLevel.Unknown, color: "#ffc107", icon: "bi-shield-fill-exclamation" },
|
|
80
|
-
{ value: TrustLevel.Untrusted, color: "#dc3545", icon: "bi-shield-fill-exclamation" },
|
|
81
|
-
{ value: TrustLevel.Malicious, color: "#dc3545", icon: "bi-shield-fill-x" },
|
|
82
|
-
];
|
|
83
|
-
|
|
84
|
-
const sortedConfigs = configs.sort((a, b) => a.value - b.value);
|
|
85
|
-
let config = { color: "#6c757d", icon: "bi-shield" };
|
|
86
|
-
for (const c of sortedConfigs) {
|
|
87
|
-
if (level >= c.value) {
|
|
88
|
-
config = c;
|
|
89
|
-
} else {
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return config;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const trustConfig = getTrustLevelConfig(trustLevel || TrustLevel.Unknown);
|
|
97
|
-
|
|
98
|
-
return (
|
|
99
|
-
<div className="position-relative">
|
|
100
|
-
<div
|
|
101
|
-
className="rounded-circle d-flex justify-content-center align-items-center fs-4 border"
|
|
102
|
-
style={{
|
|
103
|
-
width: "40px",
|
|
104
|
-
height: "40px",
|
|
105
|
-
color: "white",
|
|
106
|
-
backgroundColor,
|
|
107
|
-
}}
|
|
108
|
-
>
|
|
109
|
-
<span style={{ fontSize: "15pt" }}>
|
|
110
|
-
{assistant && <i className="bi bi-person-fill-gear"></i>}
|
|
111
|
-
{!assistant && initials.toUpperCase()}
|
|
112
|
-
{/* {assistant ? "ai" : initials.toUpperCase()} */}
|
|
113
|
-
</span>
|
|
114
|
-
</div>
|
|
115
|
-
{/* Trust level badge overlay */}
|
|
116
|
-
{!assistant && (
|
|
117
|
-
<div
|
|
118
|
-
className="position-absolute d-flex justify-content-center align-items-center"
|
|
119
|
-
style={{
|
|
120
|
-
bottom: "-4px",
|
|
121
|
-
right: "0px",
|
|
122
|
-
width: "18px",
|
|
123
|
-
height: "18px",
|
|
124
|
-
// backgroundColor: 'white',
|
|
125
|
-
borderRadius: "50%",
|
|
126
|
-
// border: '1px solid #dee2e6',
|
|
127
|
-
}}
|
|
128
|
-
>
|
|
129
|
-
<i
|
|
130
|
-
className={trustConfig.icon}
|
|
131
|
-
style={{
|
|
132
|
-
fontSize: "12px",
|
|
133
|
-
color: trustConfig.color,
|
|
134
|
-
}}
|
|
135
|
-
></i>
|
|
136
|
-
</div>
|
|
137
|
-
)}
|
|
138
|
-
{/* Keep this here in case we want to show the assistant icon */}
|
|
139
|
-
{/* {assistantId && (
|
|
140
|
-
<i
|
|
141
|
-
className="bi bi-gear-fill position-absolute"
|
|
142
|
-
style={{
|
|
143
|
-
bottom: '0',
|
|
144
|
-
right: '0',
|
|
145
|
-
fontSize: '12px',
|
|
146
|
-
backgroundColor: 'white',
|
|
147
|
-
borderRadius: '50%',
|
|
148
|
-
padding: '2px',
|
|
149
|
-
}}
|
|
150
|
-
title={`${user?.name}'s assistant`}
|
|
151
|
-
></i>
|
|
152
|
-
)} */}
|
|
153
|
-
</div>
|
|
154
|
-
);
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
export function stringToHslColor(
|
|
158
|
-
str: string = "",
|
|
159
|
-
saturation: number = 50,
|
|
160
|
-
lightness: number = 40,
|
|
161
|
-
) {
|
|
162
|
-
saturation = saturation % 100;
|
|
163
|
-
lightness = lightness % 100;
|
|
164
|
-
let hash = 0;
|
|
165
|
-
for (let i = 0; i < str.length; i++) {
|
|
166
|
-
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const h = hash % 360;
|
|
170
|
-
return `hsl(${h}, ${saturation}%, ${lightness}%)`;
|
|
171
|
-
}
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { type DataFilter, type IMessage, Messages } from "@peers-app/peers-sdk";
|
|
2
|
-
import { min, sortBy, uniqBy } from "lodash";
|
|
3
|
-
import React, { Fragment, useCallback, useEffect, useState } from "react";
|
|
4
|
-
import InfiniteScroll from "react-infinite-scroll-component";
|
|
5
|
-
import { me } from "../../globals";
|
|
6
|
-
import { LoadingIndicator } from "../loading-indicator";
|
|
7
|
-
import { MessageDisplay } from "./message-display";
|
|
8
|
-
|
|
9
|
-
const windowHeight = () => window.innerHeight;
|
|
10
|
-
|
|
11
|
-
interface IProps {
|
|
12
|
-
height: number | string;
|
|
13
|
-
channelId: string;
|
|
14
|
-
batchSize: number;
|
|
15
|
-
effects?: {
|
|
16
|
-
pushMessage: (message: IMessage) => void;
|
|
17
|
-
};
|
|
18
|
-
scrollChanged?: (isBottomInView: boolean) => void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const ChannelMessageList = (props: IProps) => {
|
|
22
|
-
const { height, channelId, batchSize } = props;
|
|
23
|
-
|
|
24
|
-
const [messages, setMessages] = useState<IMessage[]>([]);
|
|
25
|
-
const [allMessagesLoaded, setAllMessagesLoaded] = useState(false);
|
|
26
|
-
const messagesEndRef = React.useRef<HTMLDivElement>(null);
|
|
27
|
-
|
|
28
|
-
const scrollToBottom = useCallback((behavior: "instant" | "smooth", delay = 100) => {
|
|
29
|
-
setTimeout(() => {
|
|
30
|
-
messagesEndRef.current?.scrollIntoView({ behavior });
|
|
31
|
-
}, delay);
|
|
32
|
-
}, []);
|
|
33
|
-
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
const observer = new IntersectionObserver(
|
|
36
|
-
([entry]) => {
|
|
37
|
-
props?.scrollChanged?.(entry.isIntersecting);
|
|
38
|
-
},
|
|
39
|
-
{ threshold: 1.0 },
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
if (messagesEndRef.current) {
|
|
43
|
-
observer.observe(messagesEndRef.current);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return () => {
|
|
47
|
-
if (messagesEndRef.current) {
|
|
48
|
-
observer.unobserve(messagesEndRef.current);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}, [props?.scrollChanged]);
|
|
52
|
-
|
|
53
|
-
const prependItems = useCallback(() => {
|
|
54
|
-
const lastMessage = messages[messages.length - 1];
|
|
55
|
-
getMessages(batchSize, channelId, lastMessage).then((fetchedMessages) => {
|
|
56
|
-
if (fetchedMessages.length === 0) {
|
|
57
|
-
setAllMessagesLoaded(true);
|
|
58
|
-
} else {
|
|
59
|
-
const _messages = sortBy([...messages, ...fetchedMessages], "createdAt").reverse();
|
|
60
|
-
setMessages(uniqBy(_messages, "messageId"));
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
return false;
|
|
64
|
-
}, [messages, batchSize, channelId]);
|
|
65
|
-
|
|
66
|
-
const minHeightOfMessage = 20;
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
if (
|
|
69
|
-
!allMessagesLoaded &&
|
|
70
|
-
(!messages.length || messages.length * minHeightOfMessage < windowHeight())
|
|
71
|
-
) {
|
|
72
|
-
prependItems();
|
|
73
|
-
}
|
|
74
|
-
}, [messages, allMessagesLoaded, prependItems]);
|
|
75
|
-
|
|
76
|
-
// Shared-ref pattern: parent (ChannelMessages) passes its own `effects` object; we mutate
|
|
77
|
-
// `pushMessage` on that SAME reference so the parent's sendMessage can invoke it. Do NOT
|
|
78
|
-
// spread/clone (`{...props.effects}`) — it breaks the shared reference.
|
|
79
|
-
// biome-ignore lint/style/noNonNullAssertion: initial `{}` is populated on this same render; the `!` placates TS for the optional `IProps["effects"]` shape.
|
|
80
|
-
const [effects] = useState(() => props.effects || ({} as IProps["effects"])!);
|
|
81
|
-
effects.pushMessage = (newMessage: IMessage) => {
|
|
82
|
-
if (
|
|
83
|
-
(messages.length > batchSize &&
|
|
84
|
-
// biome-ignore lint/style/noNonNullAssertion: guarded by `messages.length > batchSize` — messages is non-empty so `min(...)` is defined.
|
|
85
|
-
min(messages.map((m) => m.createdAt))! > newMessage.createdAt) ||
|
|
86
|
-
messages.find((m) => m.messageId === newMessage.messageId)
|
|
87
|
-
) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const _messages = sortBy([newMessage, ...messages], "createdAt").reverse();
|
|
91
|
-
setMessages(_messages);
|
|
92
|
-
if (newMessage.userId === me.userId && !newMessage.assistantId) {
|
|
93
|
-
scrollToBottom("instant", 1);
|
|
94
|
-
} else {
|
|
95
|
-
scrollToBottom("smooth");
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
useEffect(() => {
|
|
100
|
-
const sub = Messages().dataChanged.subscribe((evt) => {
|
|
101
|
-
const message: IMessage = evt.dataObject;
|
|
102
|
-
if (message.channelId !== channelId || message.messageParentId) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
if (evt.op === "insert") {
|
|
106
|
-
effects.pushMessage(message);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
return () => {
|
|
110
|
-
sub.unsubscribe();
|
|
111
|
-
};
|
|
112
|
-
}, [channelId, effects.pushMessage]);
|
|
113
|
-
|
|
114
|
-
return (
|
|
115
|
-
<div
|
|
116
|
-
id="scrollableDiv"
|
|
117
|
-
style={{
|
|
118
|
-
height,
|
|
119
|
-
overflow: "auto",
|
|
120
|
-
display: "flex",
|
|
121
|
-
flexDirection: "column-reverse",
|
|
122
|
-
// marginBottom: '70px',
|
|
123
|
-
}}
|
|
124
|
-
>
|
|
125
|
-
<InfiniteScroll
|
|
126
|
-
dataLength={messages.length}
|
|
127
|
-
next={prependItems}
|
|
128
|
-
style={{ display: "flex", flexDirection: "column-reverse", overflow: "hidden" }}
|
|
129
|
-
inverse={true}
|
|
130
|
-
hasMore={!allMessagesLoaded}
|
|
131
|
-
loader={<LoadingIndicator />}
|
|
132
|
-
scrollableTarget="scrollableDiv"
|
|
133
|
-
endMessage={
|
|
134
|
-
<Fragment>
|
|
135
|
-
<div className="d-flex justify-content-center">
|
|
136
|
-
{messages[0] && (
|
|
137
|
-
<div>{new Date(messages[messages.length - 1].createdAt).toLocaleDateString()}</div>
|
|
138
|
-
)}
|
|
139
|
-
</div>
|
|
140
|
-
<div className="d-flex justify-content-center">
|
|
141
|
-
<div>
|
|
142
|
-
<i>beginning of messages</i>
|
|
143
|
-
</div>
|
|
144
|
-
</div>
|
|
145
|
-
</Fragment>
|
|
146
|
-
}
|
|
147
|
-
>
|
|
148
|
-
{/* <div style={{ marginBottom: '10px' }}></div> */}
|
|
149
|
-
<div ref={messagesEndRef} />
|
|
150
|
-
{messages.map((message, index) => {
|
|
151
|
-
return (
|
|
152
|
-
<MessageDisplay
|
|
153
|
-
key={message.messageId}
|
|
154
|
-
message={message}
|
|
155
|
-
messageAbove={messages[index + 1]}
|
|
156
|
-
index={index}
|
|
157
|
-
/>
|
|
158
|
-
);
|
|
159
|
-
})}
|
|
160
|
-
</InfiniteScroll>
|
|
161
|
-
</div>
|
|
162
|
-
);
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
export async function getMessages(
|
|
166
|
-
batchSize: number,
|
|
167
|
-
channelId: string,
|
|
168
|
-
lastMessage: IMessage | undefined,
|
|
169
|
-
): Promise<IMessage[]> {
|
|
170
|
-
const query: DataFilter<IMessage> = {
|
|
171
|
-
channelId,
|
|
172
|
-
messageParentId: null,
|
|
173
|
-
};
|
|
174
|
-
if (lastMessage) {
|
|
175
|
-
query.messageId = { $lt: lastMessage.messageId };
|
|
176
|
-
}
|
|
177
|
-
const cursor = await Messages().cursor(query, {
|
|
178
|
-
sortBy: ["-createdAt", "-messageId"],
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
const messages: IMessage[] = [];
|
|
182
|
-
for await (const message of cursor) {
|
|
183
|
-
messages.push(message);
|
|
184
|
-
if (messages.length >= batchSize) {
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
return messages;
|
|
189
|
-
}
|