reigncode-app 1.3.2
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/AGENTS.md +30 -0
- package/Dockerfile +21 -0
- package/README.md +51 -0
- package/bunfig.toml +3 -0
- package/create-effect-simplification-spec.md +515 -0
- package/e2e/AGENTS.md +226 -0
- package/e2e/actions.ts +1018 -0
- package/e2e/app/home.spec.ts +24 -0
- package/e2e/app/navigation.spec.ts +10 -0
- package/e2e/app/palette.spec.ts +20 -0
- package/e2e/app/server-default.spec.ts +58 -0
- package/e2e/app/session.spec.ts +16 -0
- package/e2e/app/titlebar-history.spec.ts +120 -0
- package/e2e/commands/input-focus.spec.ts +15 -0
- package/e2e/commands/panels.spec.ts +33 -0
- package/e2e/commands/tab-close.spec.ts +32 -0
- package/e2e/files/file-open.spec.ts +31 -0
- package/e2e/files/file-tree.spec.ts +56 -0
- package/e2e/files/file-viewer.spec.ts +156 -0
- package/e2e/fixtures.ts +154 -0
- package/e2e/models/model-picker.spec.ts +48 -0
- package/e2e/models/models-visibility.spec.ts +61 -0
- package/e2e/projects/project-edit.spec.ts +43 -0
- package/e2e/projects/projects-close.spec.ts +54 -0
- package/e2e/projects/projects-switch.spec.ts +116 -0
- package/e2e/projects/workspace-new-session.spec.ts +94 -0
- package/e2e/projects/workspaces.spec.ts +375 -0
- package/e2e/prompt/context.spec.ts +95 -0
- package/e2e/prompt/prompt-async.spec.ts +76 -0
- package/e2e/prompt/prompt-drop-file-uri.spec.ts +22 -0
- package/e2e/prompt/prompt-drop-file.spec.ts +30 -0
- package/e2e/prompt/prompt-history.spec.ts +184 -0
- package/e2e/prompt/prompt-mention.spec.ts +26 -0
- package/e2e/prompt/prompt-multiline.spec.ts +24 -0
- package/e2e/prompt/prompt-shell.spec.ts +62 -0
- package/e2e/prompt/prompt-slash-open.spec.ts +22 -0
- package/e2e/prompt/prompt-slash-share.spec.ts +64 -0
- package/e2e/prompt/prompt-slash-terminal.spec.ts +18 -0
- package/e2e/prompt/prompt.spec.ts +55 -0
- package/e2e/selectors.ts +75 -0
- package/e2e/session/session-child-navigation.spec.ts +37 -0
- package/e2e/session/session-composer-dock.spec.ts +530 -0
- package/e2e/session/session-model-persistence.spec.ts +359 -0
- package/e2e/session/session-review.spec.ts +426 -0
- package/e2e/session/session-undo-redo.spec.ts +233 -0
- package/e2e/session/session.spec.ts +174 -0
- package/e2e/settings/settings-keybinds.spec.ts +389 -0
- package/e2e/settings/settings-models.spec.ts +122 -0
- package/e2e/settings/settings-providers.spec.ts +136 -0
- package/e2e/settings/settings.spec.ts +519 -0
- package/e2e/sidebar/sidebar-popover-actions.spec.ts +118 -0
- package/e2e/sidebar/sidebar-session-links.spec.ts +30 -0
- package/e2e/sidebar/sidebar.spec.ts +40 -0
- package/e2e/status/status-popover.spec.ts +94 -0
- package/e2e/terminal/terminal-init.spec.ts +28 -0
- package/e2e/terminal/terminal-reconnect.spec.ts +46 -0
- package/e2e/terminal/terminal-tabs.spec.ts +168 -0
- package/e2e/terminal/terminal.spec.ts +18 -0
- package/e2e/thinking-level.spec.ts +25 -0
- package/e2e/tsconfig.json +9 -0
- package/e2e/utils.ts +63 -0
- package/happydom.ts +75 -0
- package/index.html +23 -0
- package/package.json +77 -0
- package/playwright.config.ts +45 -0
- package/public/_headers +17 -0
- package/public/oc-theme-preload.js +35 -0
- package/script/e2e-local.ts +180 -0
- package/src/addons/serialize.test.ts +319 -0
- package/src/addons/serialize.ts +634 -0
- package/src/app.tsx +308 -0
- package/src/components/debug-bar.tsx +443 -0
- package/src/components/dialog-connect-provider.tsx +617 -0
- package/src/components/dialog-custom-provider-form.ts +158 -0
- package/src/components/dialog-custom-provider.test.ts +80 -0
- package/src/components/dialog-custom-provider.tsx +329 -0
- package/src/components/dialog-edit-project.tsx +255 -0
- package/src/components/dialog-fork.tsx +108 -0
- package/src/components/dialog-manage-models.tsx +101 -0
- package/src/components/dialog-release-notes.tsx +144 -0
- package/src/components/dialog-select-directory.tsx +392 -0
- package/src/components/dialog-select-file.tsx +466 -0
- package/src/components/dialog-select-mcp.tsx +107 -0
- package/src/components/dialog-select-model-unpaid.tsx +137 -0
- package/src/components/dialog-select-model.tsx +220 -0
- package/src/components/dialog-select-provider.tsx +86 -0
- package/src/components/dialog-select-server.tsx +649 -0
- package/src/components/dialog-settings.tsx +73 -0
- package/src/components/file-tree.test.ts +78 -0
- package/src/components/file-tree.tsx +507 -0
- package/src/components/link.tsx +26 -0
- package/src/components/model-tooltip.tsx +91 -0
- package/src/components/prompt-input/attachments.test.ts +44 -0
- package/src/components/prompt-input/attachments.ts +201 -0
- package/src/components/prompt-input/build-request-parts.test.ts +312 -0
- package/src/components/prompt-input/build-request-parts.ts +175 -0
- package/src/components/prompt-input/context-items.tsx +88 -0
- package/src/components/prompt-input/drag-overlay.tsx +25 -0
- package/src/components/prompt-input/editor-dom.test.ts +99 -0
- package/src/components/prompt-input/editor-dom.ts +148 -0
- package/src/components/prompt-input/files.ts +66 -0
- package/src/components/prompt-input/history.test.ts +153 -0
- package/src/components/prompt-input/history.ts +256 -0
- package/src/components/prompt-input/image-attachments.tsx +58 -0
- package/src/components/prompt-input/paste.ts +24 -0
- package/src/components/prompt-input/placeholder.test.ts +48 -0
- package/src/components/prompt-input/placeholder.ts +15 -0
- package/src/components/prompt-input/slash-popover.tsx +141 -0
- package/src/components/prompt-input/submit.test.ts +346 -0
- package/src/components/prompt-input/submit.ts +579 -0
- package/src/components/prompt-input.tsx +1595 -0
- package/src/components/server/server-row.tsx +130 -0
- package/src/components/session/index.ts +5 -0
- package/src/components/session/session-context-breakdown.test.ts +61 -0
- package/src/components/session/session-context-breakdown.ts +132 -0
- package/src/components/session/session-context-format.ts +20 -0
- package/src/components/session/session-context-metrics.test.ts +101 -0
- package/src/components/session/session-context-metrics.ts +82 -0
- package/src/components/session/session-context-tab.tsx +339 -0
- package/src/components/session/session-header.tsx +486 -0
- package/src/components/session/session-new-view.tsx +91 -0
- package/src/components/session/session-sortable-tab.tsx +70 -0
- package/src/components/session/session-sortable-terminal-tab.tsx +193 -0
- package/src/components/session-context-usage.tsx +122 -0
- package/src/components/settings-general.tsx +585 -0
- package/src/components/settings-keybinds.tsx +453 -0
- package/src/components/settings-list.tsx +5 -0
- package/src/components/settings-models.tsx +137 -0
- package/src/components/settings-providers.tsx +251 -0
- package/src/components/status-popover.tsx +419 -0
- package/src/components/terminal.tsx +653 -0
- package/src/components/titlebar-history.test.ts +63 -0
- package/src/components/titlebar-history.ts +57 -0
- package/src/components/titlebar.tsx +312 -0
- package/src/constants/file-picker.ts +89 -0
- package/src/context/command-keybind.test.ts +69 -0
- package/src/context/command.test.ts +25 -0
- package/src/context/command.tsx +437 -0
- package/src/context/comments.test.ts +186 -0
- package/src/context/comments.tsx +243 -0
- package/src/context/file/content-cache.ts +88 -0
- package/src/context/file/path.test.ts +360 -0
- package/src/context/file/path.ts +151 -0
- package/src/context/file/tree-store.ts +170 -0
- package/src/context/file/types.ts +41 -0
- package/src/context/file/view-cache.ts +146 -0
- package/src/context/file/watcher.test.ts +149 -0
- package/src/context/file/watcher.ts +53 -0
- package/src/context/file-content-eviction-accounting.test.ts +65 -0
- package/src/context/file.tsx +280 -0
- package/src/context/global-sdk.tsx +232 -0
- package/src/context/global-sync/bootstrap.ts +206 -0
- package/src/context/global-sync/child-store.test.ts +38 -0
- package/src/context/global-sync/child-store.ts +281 -0
- package/src/context/global-sync/event-reducer.test.ts +552 -0
- package/src/context/global-sync/event-reducer.ts +359 -0
- package/src/context/global-sync/eviction.ts +28 -0
- package/src/context/global-sync/queue.ts +83 -0
- package/src/context/global-sync/session-cache.test.ts +102 -0
- package/src/context/global-sync/session-cache.ts +62 -0
- package/src/context/global-sync/session-load.ts +25 -0
- package/src/context/global-sync/session-prefetch.test.ts +96 -0
- package/src/context/global-sync/session-prefetch.ts +100 -0
- package/src/context/global-sync/session-trim.test.ts +59 -0
- package/src/context/global-sync/session-trim.ts +56 -0
- package/src/context/global-sync/types.ts +133 -0
- package/src/context/global-sync/utils.ts +25 -0
- package/src/context/global-sync.test.ts +122 -0
- package/src/context/global-sync.tsx +408 -0
- package/src/context/highlights.tsx +233 -0
- package/src/context/language.tsx +248 -0
- package/src/context/layout-scroll.test.ts +64 -0
- package/src/context/layout-scroll.ts +126 -0
- package/src/context/layout.test.ts +69 -0
- package/src/context/layout.tsx +937 -0
- package/src/context/local.tsx +422 -0
- package/src/context/model-variant.test.ts +86 -0
- package/src/context/model-variant.ts +52 -0
- package/src/context/models.tsx +163 -0
- package/src/context/notification.tsx +373 -0
- package/src/context/permission-auto-respond.test.ts +102 -0
- package/src/context/permission-auto-respond.ts +51 -0
- package/src/context/permission.tsx +277 -0
- package/src/context/platform.tsx +99 -0
- package/src/context/prompt.tsx +297 -0
- package/src/context/sdk.tsx +49 -0
- package/src/context/server.tsx +295 -0
- package/src/context/settings.tsx +241 -0
- package/src/context/sync-optimistic.test.ts +123 -0
- package/src/context/sync.tsx +618 -0
- package/src/context/terminal-title.ts +51 -0
- package/src/context/terminal.test.ts +82 -0
- package/src/context/terminal.tsx +437 -0
- package/src/entry.tsx +144 -0
- package/src/env.d.ts +18 -0
- package/src/hooks/use-providers.ts +44 -0
- package/src/i18n/ar.ts +855 -0
- package/src/i18n/br.ts +867 -0
- package/src/i18n/bs.ts +943 -0
- package/src/i18n/da.ts +937 -0
- package/src/i18n/de.ts +879 -0
- package/src/i18n/en.ts +948 -0
- package/src/i18n/es.ts +950 -0
- package/src/i18n/fr.ts +878 -0
- package/src/i18n/ja.ts +861 -0
- package/src/i18n/ko.ts +860 -0
- package/src/i18n/no.ts +944 -0
- package/src/i18n/parity.test.ts +32 -0
- package/src/i18n/pl.ts +865 -0
- package/src/i18n/ru.ts +946 -0
- package/src/i18n/th.ts +933 -0
- package/src/i18n/tr.ts +952 -0
- package/src/i18n/zh.ts +930 -0
- package/src/i18n/zht.ts +925 -0
- package/src/index.css +29 -0
- package/src/index.ts +6 -0
- package/src/pages/directory-layout.tsx +88 -0
- package/src/pages/error.tsx +327 -0
- package/src/pages/home.tsx +131 -0
- package/src/pages/layout/deep-links.ts +50 -0
- package/src/pages/layout/helpers.test.ts +211 -0
- package/src/pages/layout/helpers.ts +98 -0
- package/src/pages/layout/inline-editor.tsx +126 -0
- package/src/pages/layout/sidebar-items.tsx +437 -0
- package/src/pages/layout/sidebar-project.tsx +384 -0
- package/src/pages/layout/sidebar-shell.tsx +125 -0
- package/src/pages/layout/sidebar-workspace.tsx +504 -0
- package/src/pages/layout.tsx +2509 -0
- package/src/pages/session/composer/index.ts +2 -0
- package/src/pages/session/composer/session-composer-region.tsx +255 -0
- package/src/pages/session/composer/session-composer-state.test.ts +128 -0
- package/src/pages/session/composer/session-composer-state.ts +249 -0
- package/src/pages/session/composer/session-followup-dock.tsx +109 -0
- package/src/pages/session/composer/session-permission-dock.tsx +74 -0
- package/src/pages/session/composer/session-question-dock.tsx +449 -0
- package/src/pages/session/composer/session-request-tree.ts +52 -0
- package/src/pages/session/composer/session-revert-dock.tsx +99 -0
- package/src/pages/session/composer/session-todo-dock.tsx +330 -0
- package/src/pages/session/file-tab-scroll.test.ts +40 -0
- package/src/pages/session/file-tab-scroll.ts +67 -0
- package/src/pages/session/file-tabs.tsx +456 -0
- package/src/pages/session/handoff.ts +36 -0
- package/src/pages/session/helpers.test.ts +181 -0
- package/src/pages/session/helpers.ts +198 -0
- package/src/pages/session/message-gesture.test.ts +62 -0
- package/src/pages/session/message-gesture.ts +21 -0
- package/src/pages/session/message-id-from-hash.ts +6 -0
- package/src/pages/session/message-timeline.tsx +1013 -0
- package/src/pages/session/review-tab.tsx +170 -0
- package/src/pages/session/session-layout.ts +20 -0
- package/src/pages/session/session-model-helpers.test.ts +51 -0
- package/src/pages/session/session-model-helpers.ts +16 -0
- package/src/pages/session/session-side-panel.tsx +453 -0
- package/src/pages/session/terminal-label.ts +16 -0
- package/src/pages/session/terminal-panel.test.ts +25 -0
- package/src/pages/session/terminal-panel.tsx +326 -0
- package/src/pages/session/use-session-commands.tsx +495 -0
- package/src/pages/session/use-session-hash-scroll.test.ts +16 -0
- package/src/pages/session/use-session-hash-scroll.ts +197 -0
- package/src/pages/session.tsx +1841 -0
- package/src/sst-env.d.ts +12 -0
- package/src/testing/model-selection.ts +80 -0
- package/src/testing/prompt.ts +56 -0
- package/src/testing/session-composer.ts +84 -0
- package/src/testing/terminal.ts +118 -0
- package/src/theme-preload.test.ts +46 -0
- package/src/utils/agent.ts +23 -0
- package/src/utils/aim.ts +138 -0
- package/src/utils/base64.ts +10 -0
- package/src/utils/comment-note.ts +88 -0
- package/src/utils/id.ts +99 -0
- package/src/utils/notification-click.test.ts +27 -0
- package/src/utils/notification-click.ts +13 -0
- package/src/utils/persist.test.ts +115 -0
- package/src/utils/persist.ts +476 -0
- package/src/utils/prompt.test.ts +44 -0
- package/src/utils/prompt.ts +203 -0
- package/src/utils/runtime-adapters.test.ts +62 -0
- package/src/utils/runtime-adapters.ts +39 -0
- package/src/utils/same.ts +6 -0
- package/src/utils/scoped-cache.test.ts +69 -0
- package/src/utils/scoped-cache.ts +104 -0
- package/src/utils/server-errors.test.ts +131 -0
- package/src/utils/server-errors.ts +80 -0
- package/src/utils/server-health.test.ts +123 -0
- package/src/utils/server-health.ts +91 -0
- package/src/utils/server.ts +22 -0
- package/src/utils/solid-dnd.tsx +49 -0
- package/src/utils/sound.ts +117 -0
- package/src/utils/terminal-writer.test.ts +64 -0
- package/src/utils/terminal-writer.ts +65 -0
- package/src/utils/time.ts +22 -0
- package/src/utils/uuid.test.ts +78 -0
- package/src/utils/uuid.ts +12 -0
- package/src/utils/worktree.test.ts +46 -0
- package/src/utils/worktree.ts +73 -0
- package/sst-env.d.ts +10 -0
- package/tsconfig.json +26 -0
- package/vite.config.ts +15 -0
- package/vite.js +26 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { For, Show, createMemo } from "solid-js"
|
|
2
|
+
import { createStore } from "solid-js/store"
|
|
3
|
+
import { Button } from "@reign-labs/ui/button"
|
|
4
|
+
import { DockTray } from "@reign-labs/ui/dock-surface"
|
|
5
|
+
import { IconButton } from "@reign-labs/ui/icon-button"
|
|
6
|
+
import { useLanguage } from "@/context/language"
|
|
7
|
+
|
|
8
|
+
export function SessionFollowupDock(props: {
|
|
9
|
+
items: { id: string; text: string }[]
|
|
10
|
+
sending?: string
|
|
11
|
+
onSend: (id: string) => void
|
|
12
|
+
onEdit: (id: string) => void
|
|
13
|
+
}) {
|
|
14
|
+
const language = useLanguage()
|
|
15
|
+
const [store, setStore] = createStore({
|
|
16
|
+
collapsed: false,
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const toggle = () => setStore("collapsed", (value) => !value)
|
|
20
|
+
const total = createMemo(() => props.items.length)
|
|
21
|
+
const label = createMemo(() =>
|
|
22
|
+
language.t(total() === 1 ? "session.followupDock.summary.one" : "session.followupDock.summary.other", {
|
|
23
|
+
count: total(),
|
|
24
|
+
}),
|
|
25
|
+
)
|
|
26
|
+
const preview = createMemo(() => props.items[0]?.text ?? "")
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<DockTray
|
|
30
|
+
data-component="session-followup-dock"
|
|
31
|
+
style={{
|
|
32
|
+
"margin-bottom": "-0.875rem",
|
|
33
|
+
"border-bottom-left-radius": 0,
|
|
34
|
+
"border-bottom-right-radius": 0,
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
<div
|
|
38
|
+
class="pl-3 pr-2 py-2 flex items-center gap-2"
|
|
39
|
+
role="button"
|
|
40
|
+
tabIndex={0}
|
|
41
|
+
onClick={toggle}
|
|
42
|
+
onKeyDown={(event) => {
|
|
43
|
+
if (event.key !== "Enter" && event.key !== " ") return
|
|
44
|
+
event.preventDefault()
|
|
45
|
+
toggle()
|
|
46
|
+
}}
|
|
47
|
+
>
|
|
48
|
+
<span class="shrink-0 text-13-medium text-text-strong cursor-default">{label()}</span>
|
|
49
|
+
<Show when={store.collapsed && preview()}>
|
|
50
|
+
<span class="min-w-0 flex-1 truncate text-13-regular text-text-base cursor-default">{preview()}</span>
|
|
51
|
+
</Show>
|
|
52
|
+
<div class="ml-auto shrink-0">
|
|
53
|
+
<IconButton
|
|
54
|
+
data-collapsed={store.collapsed ? "true" : "false"}
|
|
55
|
+
icon="chevron-down"
|
|
56
|
+
size="normal"
|
|
57
|
+
variant="ghost"
|
|
58
|
+
style={{ transform: `rotate(${store.collapsed ? 180 : 0}deg)` }}
|
|
59
|
+
onMouseDown={(event) => {
|
|
60
|
+
event.preventDefault()
|
|
61
|
+
event.stopPropagation()
|
|
62
|
+
}}
|
|
63
|
+
onClick={(event) => {
|
|
64
|
+
event.stopPropagation()
|
|
65
|
+
toggle()
|
|
66
|
+
}}
|
|
67
|
+
aria-label={
|
|
68
|
+
store.collapsed ? language.t("session.followupDock.expand") : language.t("session.followupDock.collapse")
|
|
69
|
+
}
|
|
70
|
+
/>
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
|
|
74
|
+
<Show when={store.collapsed}>
|
|
75
|
+
<div class="h-5" aria-hidden="true" />
|
|
76
|
+
</Show>
|
|
77
|
+
|
|
78
|
+
<Show when={!store.collapsed}>
|
|
79
|
+
<div class="px-3 pb-7 flex flex-col gap-1.5 max-h-42 overflow-y-auto no-scrollbar">
|
|
80
|
+
<For each={props.items}>
|
|
81
|
+
{(item) => (
|
|
82
|
+
<div class="flex items-center gap-2 min-w-0 py-1">
|
|
83
|
+
<span class="min-w-0 flex-1 truncate text-13-regular text-text-strong">{item.text}</span>
|
|
84
|
+
<Button
|
|
85
|
+
size="small"
|
|
86
|
+
variant="secondary"
|
|
87
|
+
class="shrink-0"
|
|
88
|
+
disabled={!!props.sending}
|
|
89
|
+
onClick={() => props.onSend(item.id)}
|
|
90
|
+
>
|
|
91
|
+
{language.t("session.followupDock.sendNow")}
|
|
92
|
+
</Button>
|
|
93
|
+
<Button
|
|
94
|
+
size="small"
|
|
95
|
+
variant="ghost"
|
|
96
|
+
class="shrink-0"
|
|
97
|
+
disabled={!!props.sending}
|
|
98
|
+
onClick={() => props.onEdit(item.id)}
|
|
99
|
+
>
|
|
100
|
+
{language.t("session.followupDock.edit")}
|
|
101
|
+
</Button>
|
|
102
|
+
</div>
|
|
103
|
+
)}
|
|
104
|
+
</For>
|
|
105
|
+
</div>
|
|
106
|
+
</Show>
|
|
107
|
+
</DockTray>
|
|
108
|
+
)
|
|
109
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { For, Show } from "solid-js"
|
|
2
|
+
import type { PermissionRequest } from "@reign-labs/sdk/v2"
|
|
3
|
+
import { Button } from "@reign-labs/ui/button"
|
|
4
|
+
import { DockPrompt } from "@reign-labs/ui/dock-prompt"
|
|
5
|
+
import { Icon } from "@reign-labs/ui/icon"
|
|
6
|
+
import { useLanguage } from "@/context/language"
|
|
7
|
+
|
|
8
|
+
export function SessionPermissionDock(props: {
|
|
9
|
+
request: PermissionRequest
|
|
10
|
+
responding: boolean
|
|
11
|
+
onDecide: (response: "once" | "always" | "reject") => void
|
|
12
|
+
}) {
|
|
13
|
+
const language = useLanguage()
|
|
14
|
+
|
|
15
|
+
const toolDescription = () => {
|
|
16
|
+
const key = `settings.permissions.tool.${props.request.permission}.description`
|
|
17
|
+
const value = language.t(key as Parameters<typeof language.t>[0])
|
|
18
|
+
if (value === key) return ""
|
|
19
|
+
return value
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<DockPrompt
|
|
24
|
+
kind="permission"
|
|
25
|
+
header={
|
|
26
|
+
<div data-slot="permission-row" data-variant="header">
|
|
27
|
+
<span data-slot="permission-icon">
|
|
28
|
+
<Icon name="warning" size="normal" />
|
|
29
|
+
</span>
|
|
30
|
+
<div data-slot="permission-header-title">{language.t("notification.permission.title")}</div>
|
|
31
|
+
</div>
|
|
32
|
+
}
|
|
33
|
+
footer={
|
|
34
|
+
<>
|
|
35
|
+
<div />
|
|
36
|
+
<div data-slot="permission-footer-actions">
|
|
37
|
+
<Button variant="ghost" size="normal" onClick={() => props.onDecide("reject")} disabled={props.responding}>
|
|
38
|
+
{language.t("ui.permission.deny")}
|
|
39
|
+
</Button>
|
|
40
|
+
<Button
|
|
41
|
+
variant="secondary"
|
|
42
|
+
size="normal"
|
|
43
|
+
onClick={() => props.onDecide("always")}
|
|
44
|
+
disabled={props.responding}
|
|
45
|
+
>
|
|
46
|
+
{language.t("ui.permission.allowAlways")}
|
|
47
|
+
</Button>
|
|
48
|
+
<Button variant="primary" size="normal" onClick={() => props.onDecide("once")} disabled={props.responding}>
|
|
49
|
+
{language.t("ui.permission.allowOnce")}
|
|
50
|
+
</Button>
|
|
51
|
+
</div>
|
|
52
|
+
</>
|
|
53
|
+
}
|
|
54
|
+
>
|
|
55
|
+
<Show when={toolDescription()}>
|
|
56
|
+
<div data-slot="permission-row">
|
|
57
|
+
<span data-slot="permission-spacer" aria-hidden="true" />
|
|
58
|
+
<div data-slot="permission-hint">{toolDescription()}</div>
|
|
59
|
+
</div>
|
|
60
|
+
</Show>
|
|
61
|
+
|
|
62
|
+
<Show when={props.request.patterns.length > 0}>
|
|
63
|
+
<div data-slot="permission-row">
|
|
64
|
+
<span data-slot="permission-spacer" aria-hidden="true" />
|
|
65
|
+
<div data-slot="permission-patterns">
|
|
66
|
+
<For each={props.request.patterns}>
|
|
67
|
+
{(pattern) => <code class="text-12-regular text-text-base break-all">{pattern}</code>}
|
|
68
|
+
</For>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
</Show>
|
|
72
|
+
</DockPrompt>
|
|
73
|
+
)
|
|
74
|
+
}
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import { For, Show, createMemo, onCleanup, onMount, type Component } from "solid-js"
|
|
2
|
+
import { createStore } from "solid-js/store"
|
|
3
|
+
import { useMutation } from "@tanstack/solid-query"
|
|
4
|
+
import { Button } from "@reign-labs/ui/button"
|
|
5
|
+
import { DockPrompt } from "@reign-labs/ui/dock-prompt"
|
|
6
|
+
import { Icon } from "@reign-labs/ui/icon"
|
|
7
|
+
import { showToast } from "@reign-labs/ui/toast"
|
|
8
|
+
import type { QuestionAnswer, QuestionRequest } from "@reign-labs/sdk/v2"
|
|
9
|
+
import { useLanguage } from "@/context/language"
|
|
10
|
+
import { useSDK } from "@/context/sdk"
|
|
11
|
+
|
|
12
|
+
const cache = new Map<string, { tab: number; answers: QuestionAnswer[]; custom: string[]; customOn: boolean[] }>()
|
|
13
|
+
|
|
14
|
+
export const SessionQuestionDock: Component<{ request: QuestionRequest; onSubmit: () => void }> = (props) => {
|
|
15
|
+
const sdk = useSDK()
|
|
16
|
+
const language = useLanguage()
|
|
17
|
+
|
|
18
|
+
const questions = createMemo(() => props.request.questions)
|
|
19
|
+
const total = createMemo(() => questions().length)
|
|
20
|
+
|
|
21
|
+
const cached = cache.get(props.request.id)
|
|
22
|
+
const [store, setStore] = createStore({
|
|
23
|
+
tab: cached?.tab ?? 0,
|
|
24
|
+
answers: cached?.answers ?? ([] as QuestionAnswer[]),
|
|
25
|
+
custom: cached?.custom ?? ([] as string[]),
|
|
26
|
+
customOn: cached?.customOn ?? ([] as boolean[]),
|
|
27
|
+
editing: false,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
let root: HTMLDivElement | undefined
|
|
31
|
+
let replied = false
|
|
32
|
+
|
|
33
|
+
const question = createMemo(() => questions()[store.tab])
|
|
34
|
+
const options = createMemo(() => question()?.options ?? [])
|
|
35
|
+
const input = createMemo(() => store.custom[store.tab] ?? "")
|
|
36
|
+
const on = createMemo(() => store.customOn[store.tab] === true)
|
|
37
|
+
const multi = createMemo(() => question()?.multiple === true)
|
|
38
|
+
|
|
39
|
+
const summary = createMemo(() => {
|
|
40
|
+
const n = Math.min(store.tab + 1, total())
|
|
41
|
+
return language.t("session.question.progress", { current: n, total: total() })
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const last = createMemo(() => store.tab >= total() - 1)
|
|
45
|
+
|
|
46
|
+
const customUpdate = (value: string, selected: boolean = on()) => {
|
|
47
|
+
const prev = input().trim()
|
|
48
|
+
const next = value.trim()
|
|
49
|
+
|
|
50
|
+
setStore("custom", store.tab, value)
|
|
51
|
+
if (!selected) return
|
|
52
|
+
|
|
53
|
+
if (multi()) {
|
|
54
|
+
setStore("answers", store.tab, (current = []) => {
|
|
55
|
+
const removed = prev ? current.filter((item) => item.trim() !== prev) : current
|
|
56
|
+
if (!next) return removed
|
|
57
|
+
if (removed.some((item) => item.trim() === next)) return removed
|
|
58
|
+
return [...removed, next]
|
|
59
|
+
})
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
setStore("answers", store.tab, next ? [next] : [])
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const measure = () => {
|
|
67
|
+
if (!root) return
|
|
68
|
+
|
|
69
|
+
const scroller = document.querySelector(".scroll-view__viewport")
|
|
70
|
+
const head = scroller instanceof HTMLElement ? scroller.firstElementChild : undefined
|
|
71
|
+
const top =
|
|
72
|
+
head instanceof HTMLElement && head.classList.contains("sticky") ? head.getBoundingClientRect().bottom : 0
|
|
73
|
+
if (!top) {
|
|
74
|
+
root.style.removeProperty("--question-prompt-max-height")
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const dock = root.closest('[data-component="session-prompt-dock"]')
|
|
79
|
+
if (!(dock instanceof HTMLElement)) return
|
|
80
|
+
|
|
81
|
+
const dockBottom = dock.getBoundingClientRect().bottom
|
|
82
|
+
const below = Math.max(0, dockBottom - root.getBoundingClientRect().bottom)
|
|
83
|
+
const gap = 8
|
|
84
|
+
const max = Math.max(240, Math.floor(dockBottom - top - gap - below))
|
|
85
|
+
root.style.setProperty("--question-prompt-max-height", `${max}px`)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
onMount(() => {
|
|
89
|
+
let raf: number | undefined
|
|
90
|
+
const update = () => {
|
|
91
|
+
if (raf !== undefined) cancelAnimationFrame(raf)
|
|
92
|
+
raf = requestAnimationFrame(() => {
|
|
93
|
+
raf = undefined
|
|
94
|
+
measure()
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
update()
|
|
99
|
+
window.addEventListener("resize", update)
|
|
100
|
+
|
|
101
|
+
const dock = root?.closest('[data-component="session-prompt-dock"]')
|
|
102
|
+
const scroller = document.querySelector(".scroll-view__viewport")
|
|
103
|
+
const observer = new ResizeObserver(update)
|
|
104
|
+
if (dock instanceof HTMLElement) observer.observe(dock)
|
|
105
|
+
if (scroller instanceof HTMLElement) observer.observe(scroller)
|
|
106
|
+
|
|
107
|
+
onCleanup(() => {
|
|
108
|
+
window.removeEventListener("resize", update)
|
|
109
|
+
observer.disconnect()
|
|
110
|
+
if (raf !== undefined) cancelAnimationFrame(raf)
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
onCleanup(() => {
|
|
115
|
+
if (replied) return
|
|
116
|
+
cache.set(props.request.id, {
|
|
117
|
+
tab: store.tab,
|
|
118
|
+
answers: store.answers.map((a) => (a ? [...a] : [])),
|
|
119
|
+
custom: store.custom.map((s) => s ?? ""),
|
|
120
|
+
customOn: store.customOn.map((b) => b ?? false),
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
const fail = (err: unknown) => {
|
|
125
|
+
const message = err instanceof Error ? err.message : String(err)
|
|
126
|
+
showToast({ title: language.t("common.requestFailed"), description: message })
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const replyMutation = useMutation(() => ({
|
|
130
|
+
mutationFn: (answers: QuestionAnswer[]) => sdk.client.question.reply({ requestID: props.request.id, answers }),
|
|
131
|
+
onMutate: () => {
|
|
132
|
+
props.onSubmit()
|
|
133
|
+
},
|
|
134
|
+
onSuccess: () => {
|
|
135
|
+
replied = true
|
|
136
|
+
cache.delete(props.request.id)
|
|
137
|
+
},
|
|
138
|
+
onError: fail,
|
|
139
|
+
}))
|
|
140
|
+
|
|
141
|
+
const rejectMutation = useMutation(() => ({
|
|
142
|
+
mutationFn: () => sdk.client.question.reject({ requestID: props.request.id }),
|
|
143
|
+
onMutate: () => {
|
|
144
|
+
props.onSubmit()
|
|
145
|
+
},
|
|
146
|
+
onSuccess: () => {
|
|
147
|
+
replied = true
|
|
148
|
+
cache.delete(props.request.id)
|
|
149
|
+
},
|
|
150
|
+
onError: fail,
|
|
151
|
+
}))
|
|
152
|
+
|
|
153
|
+
const sending = createMemo(() => replyMutation.isPending || rejectMutation.isPending)
|
|
154
|
+
|
|
155
|
+
const reply = async (answers: QuestionAnswer[]) => {
|
|
156
|
+
if (sending()) return
|
|
157
|
+
await replyMutation.mutateAsync(answers)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const reject = async () => {
|
|
161
|
+
if (sending()) return
|
|
162
|
+
await rejectMutation.mutateAsync()
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const submit = () => void reply(questions().map((_, i) => store.answers[i] ?? []))
|
|
166
|
+
|
|
167
|
+
const pick = (answer: string, custom: boolean = false) => {
|
|
168
|
+
setStore("answers", store.tab, [answer])
|
|
169
|
+
if (custom) setStore("custom", store.tab, answer)
|
|
170
|
+
if (!custom) setStore("customOn", store.tab, false)
|
|
171
|
+
setStore("editing", false)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const toggle = (answer: string) => {
|
|
175
|
+
setStore("answers", store.tab, (current = []) => {
|
|
176
|
+
if (current.includes(answer)) return current.filter((item) => item !== answer)
|
|
177
|
+
return [...current, answer]
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const customToggle = () => {
|
|
182
|
+
if (sending()) return
|
|
183
|
+
|
|
184
|
+
if (!multi()) {
|
|
185
|
+
setStore("customOn", store.tab, true)
|
|
186
|
+
setStore("editing", true)
|
|
187
|
+
customUpdate(input(), true)
|
|
188
|
+
return
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const next = !on()
|
|
192
|
+
setStore("customOn", store.tab, next)
|
|
193
|
+
if (next) {
|
|
194
|
+
setStore("editing", true)
|
|
195
|
+
customUpdate(input(), true)
|
|
196
|
+
return
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const value = input().trim()
|
|
200
|
+
if (value) setStore("answers", store.tab, (current = []) => current.filter((item) => item.trim() !== value))
|
|
201
|
+
setStore("editing", false)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const customOpen = () => {
|
|
205
|
+
if (sending()) return
|
|
206
|
+
if (!on()) setStore("customOn", store.tab, true)
|
|
207
|
+
setStore("editing", true)
|
|
208
|
+
customUpdate(input(), true)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const selectOption = (optIndex: number) => {
|
|
212
|
+
if (sending()) return
|
|
213
|
+
|
|
214
|
+
if (optIndex === options().length) {
|
|
215
|
+
customOpen()
|
|
216
|
+
return
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const opt = options()[optIndex]
|
|
220
|
+
if (!opt) return
|
|
221
|
+
if (multi()) {
|
|
222
|
+
toggle(opt.label)
|
|
223
|
+
return
|
|
224
|
+
}
|
|
225
|
+
pick(opt.label)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const commitCustom = () => {
|
|
229
|
+
setStore("editing", false)
|
|
230
|
+
customUpdate(input())
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const next = () => {
|
|
234
|
+
if (sending()) return
|
|
235
|
+
if (store.editing) commitCustom()
|
|
236
|
+
|
|
237
|
+
if (store.tab >= total() - 1) {
|
|
238
|
+
submit()
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
setStore("tab", store.tab + 1)
|
|
243
|
+
setStore("editing", false)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const back = () => {
|
|
247
|
+
if (sending()) return
|
|
248
|
+
if (store.tab <= 0) return
|
|
249
|
+
setStore("tab", store.tab - 1)
|
|
250
|
+
setStore("editing", false)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const jump = (tab: number) => {
|
|
254
|
+
if (sending()) return
|
|
255
|
+
setStore("tab", tab)
|
|
256
|
+
setStore("editing", false)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return (
|
|
260
|
+
<DockPrompt
|
|
261
|
+
kind="question"
|
|
262
|
+
ref={(el) => (root = el)}
|
|
263
|
+
header={
|
|
264
|
+
<>
|
|
265
|
+
<div data-slot="question-header-title">{summary()}</div>
|
|
266
|
+
<div data-slot="question-progress">
|
|
267
|
+
<For each={questions()}>
|
|
268
|
+
{(_, i) => (
|
|
269
|
+
<button
|
|
270
|
+
type="button"
|
|
271
|
+
data-slot="question-progress-segment"
|
|
272
|
+
data-active={i() === store.tab}
|
|
273
|
+
data-answered={
|
|
274
|
+
(store.answers[i()]?.length ?? 0) > 0 ||
|
|
275
|
+
(store.customOn[i()] === true && (store.custom[i()] ?? "").trim().length > 0)
|
|
276
|
+
}
|
|
277
|
+
disabled={sending()}
|
|
278
|
+
onClick={() => jump(i())}
|
|
279
|
+
aria-label={`${language.t("ui.tool.questions")} ${i() + 1}`}
|
|
280
|
+
/>
|
|
281
|
+
)}
|
|
282
|
+
</For>
|
|
283
|
+
</div>
|
|
284
|
+
</>
|
|
285
|
+
}
|
|
286
|
+
footer={
|
|
287
|
+
<>
|
|
288
|
+
<Button variant="ghost" size="large" disabled={sending()} onClick={reject}>
|
|
289
|
+
{language.t("ui.common.dismiss")}
|
|
290
|
+
</Button>
|
|
291
|
+
<div data-slot="question-footer-actions">
|
|
292
|
+
<Show when={store.tab > 0}>
|
|
293
|
+
<Button variant="secondary" size="large" disabled={sending()} onClick={back}>
|
|
294
|
+
{language.t("ui.common.back")}
|
|
295
|
+
</Button>
|
|
296
|
+
</Show>
|
|
297
|
+
<Button variant={last() ? "primary" : "secondary"} size="large" disabled={sending()} onClick={next}>
|
|
298
|
+
{last() ? language.t("ui.common.submit") : language.t("ui.common.next")}
|
|
299
|
+
</Button>
|
|
300
|
+
</div>
|
|
301
|
+
</>
|
|
302
|
+
}
|
|
303
|
+
>
|
|
304
|
+
<div data-slot="question-text">{question()?.question}</div>
|
|
305
|
+
<Show when={multi()} fallback={<div data-slot="question-hint">{language.t("ui.question.singleHint")}</div>}>
|
|
306
|
+
<div data-slot="question-hint">{language.t("ui.question.multiHint")}</div>
|
|
307
|
+
</Show>
|
|
308
|
+
<div data-slot="question-options">
|
|
309
|
+
<For each={options()}>
|
|
310
|
+
{(opt, i) => {
|
|
311
|
+
const picked = () => store.answers[store.tab]?.includes(opt.label) ?? false
|
|
312
|
+
return (
|
|
313
|
+
<button
|
|
314
|
+
data-slot="question-option"
|
|
315
|
+
data-picked={picked()}
|
|
316
|
+
role={multi() ? "checkbox" : "radio"}
|
|
317
|
+
aria-checked={picked()}
|
|
318
|
+
disabled={sending()}
|
|
319
|
+
onClick={() => selectOption(i())}
|
|
320
|
+
>
|
|
321
|
+
<span data-slot="question-option-check" aria-hidden="true">
|
|
322
|
+
<span
|
|
323
|
+
data-slot="question-option-box"
|
|
324
|
+
data-type={multi() ? "checkbox" : "radio"}
|
|
325
|
+
data-picked={picked()}
|
|
326
|
+
>
|
|
327
|
+
<Show when={multi()} fallback={<span data-slot="question-option-radio-dot" />}>
|
|
328
|
+
<Icon name="check-small" size="small" />
|
|
329
|
+
</Show>
|
|
330
|
+
</span>
|
|
331
|
+
</span>
|
|
332
|
+
<span data-slot="question-option-main">
|
|
333
|
+
<span data-slot="option-label">{opt.label}</span>
|
|
334
|
+
<Show when={opt.description}>
|
|
335
|
+
<span data-slot="option-description">{opt.description}</span>
|
|
336
|
+
</Show>
|
|
337
|
+
</span>
|
|
338
|
+
</button>
|
|
339
|
+
)
|
|
340
|
+
}}
|
|
341
|
+
</For>
|
|
342
|
+
|
|
343
|
+
<Show
|
|
344
|
+
when={store.editing}
|
|
345
|
+
fallback={
|
|
346
|
+
<button
|
|
347
|
+
data-slot="question-option"
|
|
348
|
+
data-custom="true"
|
|
349
|
+
data-picked={on()}
|
|
350
|
+
role={multi() ? "checkbox" : "radio"}
|
|
351
|
+
aria-checked={on()}
|
|
352
|
+
disabled={sending()}
|
|
353
|
+
onClick={customOpen}
|
|
354
|
+
>
|
|
355
|
+
<span
|
|
356
|
+
data-slot="question-option-check"
|
|
357
|
+
aria-hidden="true"
|
|
358
|
+
onClick={(e) => {
|
|
359
|
+
e.preventDefault()
|
|
360
|
+
e.stopPropagation()
|
|
361
|
+
customToggle()
|
|
362
|
+
}}
|
|
363
|
+
>
|
|
364
|
+
<span data-slot="question-option-box" data-type={multi() ? "checkbox" : "radio"} data-picked={on()}>
|
|
365
|
+
<Show when={multi()} fallback={<span data-slot="question-option-radio-dot" />}>
|
|
366
|
+
<Icon name="check-small" size="small" />
|
|
367
|
+
</Show>
|
|
368
|
+
</span>
|
|
369
|
+
</span>
|
|
370
|
+
<span data-slot="question-option-main">
|
|
371
|
+
<span data-slot="option-label">{language.t("ui.messagePart.option.typeOwnAnswer")}</span>
|
|
372
|
+
<span data-slot="option-description">{input() || language.t("ui.question.custom.placeholder")}</span>
|
|
373
|
+
</span>
|
|
374
|
+
</button>
|
|
375
|
+
}
|
|
376
|
+
>
|
|
377
|
+
<form
|
|
378
|
+
data-slot="question-option"
|
|
379
|
+
data-custom="true"
|
|
380
|
+
data-picked={on()}
|
|
381
|
+
role={multi() ? "checkbox" : "radio"}
|
|
382
|
+
aria-checked={on()}
|
|
383
|
+
onMouseDown={(e) => {
|
|
384
|
+
if (sending()) {
|
|
385
|
+
e.preventDefault()
|
|
386
|
+
return
|
|
387
|
+
}
|
|
388
|
+
if (e.target instanceof HTMLTextAreaElement) return
|
|
389
|
+
const input = e.currentTarget.querySelector('[data-slot="question-custom-input"]')
|
|
390
|
+
if (input instanceof HTMLTextAreaElement) input.focus()
|
|
391
|
+
}}
|
|
392
|
+
onSubmit={(e) => {
|
|
393
|
+
e.preventDefault()
|
|
394
|
+
commitCustom()
|
|
395
|
+
}}
|
|
396
|
+
>
|
|
397
|
+
<span
|
|
398
|
+
data-slot="question-option-check"
|
|
399
|
+
aria-hidden="true"
|
|
400
|
+
onClick={(e) => {
|
|
401
|
+
e.preventDefault()
|
|
402
|
+
e.stopPropagation()
|
|
403
|
+
customToggle()
|
|
404
|
+
}}
|
|
405
|
+
>
|
|
406
|
+
<span data-slot="question-option-box" data-type={multi() ? "checkbox" : "radio"} data-picked={on()}>
|
|
407
|
+
<Show when={multi()} fallback={<span data-slot="question-option-radio-dot" />}>
|
|
408
|
+
<Icon name="check-small" size="small" />
|
|
409
|
+
</Show>
|
|
410
|
+
</span>
|
|
411
|
+
</span>
|
|
412
|
+
<span data-slot="question-option-main">
|
|
413
|
+
<span data-slot="option-label">{language.t("ui.messagePart.option.typeOwnAnswer")}</span>
|
|
414
|
+
<textarea
|
|
415
|
+
ref={(el) =>
|
|
416
|
+
setTimeout(() => {
|
|
417
|
+
el.focus()
|
|
418
|
+
el.style.height = "0px"
|
|
419
|
+
el.style.height = `${el.scrollHeight}px`
|
|
420
|
+
}, 0)
|
|
421
|
+
}
|
|
422
|
+
data-slot="question-custom-input"
|
|
423
|
+
placeholder={language.t("ui.question.custom.placeholder")}
|
|
424
|
+
value={input()}
|
|
425
|
+
rows={1}
|
|
426
|
+
disabled={sending()}
|
|
427
|
+
onKeyDown={(e) => {
|
|
428
|
+
if (e.key === "Escape") {
|
|
429
|
+
e.preventDefault()
|
|
430
|
+
setStore("editing", false)
|
|
431
|
+
return
|
|
432
|
+
}
|
|
433
|
+
if (e.key !== "Enter" || e.shiftKey) return
|
|
434
|
+
e.preventDefault()
|
|
435
|
+
commitCustom()
|
|
436
|
+
}}
|
|
437
|
+
onInput={(e) => {
|
|
438
|
+
customUpdate(e.currentTarget.value)
|
|
439
|
+
e.currentTarget.style.height = "0px"
|
|
440
|
+
e.currentTarget.style.height = `${e.currentTarget.scrollHeight}px`
|
|
441
|
+
}}
|
|
442
|
+
/>
|
|
443
|
+
</span>
|
|
444
|
+
</form>
|
|
445
|
+
</Show>
|
|
446
|
+
</div>
|
|
447
|
+
</DockPrompt>
|
|
448
|
+
)
|
|
449
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { PermissionRequest, QuestionRequest, Session } from "@reign-labs/sdk/v2/client"
|
|
2
|
+
|
|
3
|
+
function sessionTreeRequest<T>(
|
|
4
|
+
session: Session[],
|
|
5
|
+
request: Record<string, T[] | undefined>,
|
|
6
|
+
sessionID?: string,
|
|
7
|
+
include: (item: T) => boolean = () => true,
|
|
8
|
+
) {
|
|
9
|
+
if (!sessionID) return
|
|
10
|
+
|
|
11
|
+
const map = session.reduce((acc, item) => {
|
|
12
|
+
if (!item.parentID) return acc
|
|
13
|
+
const list = acc.get(item.parentID)
|
|
14
|
+
if (list) list.push(item.id)
|
|
15
|
+
if (!list) acc.set(item.parentID, [item.id])
|
|
16
|
+
return acc
|
|
17
|
+
}, new Map<string, string[]>())
|
|
18
|
+
|
|
19
|
+
const seen = new Set([sessionID])
|
|
20
|
+
const ids = [sessionID]
|
|
21
|
+
for (const id of ids) {
|
|
22
|
+
const list = map.get(id)
|
|
23
|
+
if (!list) continue
|
|
24
|
+
for (const child of list) {
|
|
25
|
+
if (seen.has(child)) continue
|
|
26
|
+
seen.add(child)
|
|
27
|
+
ids.push(child)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const id = ids.find((id) => request[id]?.some(include))
|
|
32
|
+
if (!id) return
|
|
33
|
+
return request[id]?.find(include)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function sessionPermissionRequest(
|
|
37
|
+
session: Session[],
|
|
38
|
+
request: Record<string, PermissionRequest[] | undefined>,
|
|
39
|
+
sessionID?: string,
|
|
40
|
+
include?: (item: PermissionRequest) => boolean,
|
|
41
|
+
) {
|
|
42
|
+
return sessionTreeRequest(session, request, sessionID, include)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function sessionQuestionRequest(
|
|
46
|
+
session: Session[],
|
|
47
|
+
request: Record<string, QuestionRequest[] | undefined>,
|
|
48
|
+
sessionID?: string,
|
|
49
|
+
include?: (item: QuestionRequest) => boolean,
|
|
50
|
+
) {
|
|
51
|
+
return sessionTreeRequest(session, request, sessionID, include)
|
|
52
|
+
}
|