@antelopejs/dms-assistant 0.2.7-next.444.g0da96b6 → 0.2.7
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/package.json +6 -2
- package/frontend-vue/builder/tests/database-build.test.ts +0 -232
- package/frontend-vue/builder/tests/database-connect.test.ts +0 -348
- package/frontend-vue/builder/tests/database-display.test.ts +0 -112
- package/frontend-vue/builder/tests/database.test.ts +0 -138
- package/frontend-vue/builder/tests/enabled.test.ts +0 -17
- package/frontend-vue/builder/tests/owner-ui.test.ts +0 -29
- package/frontend-vue/builder/tests/stubs/frontend-module.ts +0 -63
- package/frontend-vue/builder/vitest.config.ts +0 -21
- package/frontend-vue/tests/assistant-actions.test.ts +0 -109
- package/frontend-vue/tests/assistant-activity.test.ts +0 -281
- package/frontend-vue/tests/backend-boundary.test.ts +0 -130
- package/frontend-vue/tests/backoff.test.ts +0 -40
- package/frontend-vue/tests/block-health.test.ts +0 -142
- package/frontend-vue/tests/channel-client.test.ts +0 -246
- package/frontend-vue/tests/chat/block-preview.test.ts +0 -367
- package/frontend-vue/tests/chat/block-target.test.ts +0 -133
- package/frontend-vue/tests/chat/build-view.test.ts +0 -171
- package/frontend-vue/tests/chat/chat-scroll.test.ts +0 -251
- package/frontend-vue/tests/chat/conversation-events.test.ts +0 -622
- package/frontend-vue/tests/chat/diff-and-keys.test.ts +0 -178
- package/frontend-vue/tests/chat/held-card.test.ts +0 -133
- package/frontend-vue/tests/chat/markdown-content.test.ts +0 -86
- package/frontend-vue/tests/chat/markdown.test.ts +0 -352
- package/frontend-vue/tests/chat/provider-notice.test.ts +0 -33
- package/frontend-vue/tests/chat/tool-lexicon.test.ts +0 -212
- package/frontend-vue/tests/chat/useChatChannel.test.ts +0 -124
- package/frontend-vue/tests/chat/useConversation.test.ts +0 -288
- package/frontend-vue/tests/chat-panel.test.ts +0 -300
- package/frontend-vue/tests/chat-transport.test.ts +0 -94
- package/frontend-vue/tests/embedding.test.ts +0 -10
- package/frontend-vue/tests/formal/connection-analysis-scenarios.ts +0 -130
- package/frontend-vue/tests/formal/connection-analysis-world.ts +0 -497
- package/frontend-vue/tests/formal/connection-analysis.test.ts +0 -36
- package/frontend-vue/tests/host-commands.test.ts +0 -182
- package/frontend-vue/tests/launcher-icon.test.ts +0 -62
- package/frontend-vue/tests/launcher-label.test.ts +0 -40
- package/frontend-vue/tests/launcher-state.test.ts +0 -215
- package/frontend-vue/tests/mockup-fold.test.ts +0 -95
- package/frontend-vue/tests/navigation.test.ts +0 -142
- package/frontend-vue/tests/onboarding-api.test.ts +0 -29
- package/frontend-vue/tests/onboarding-claude.test.ts +0 -144
- package/frontend-vue/tests/onboarding-connect-memory.test.ts +0 -126
- package/frontend-vue/tests/onboarding-controller-restart.test.ts +0 -134
- package/frontend-vue/tests/onboarding-controller.test.ts +0 -307
- package/frontend-vue/tests/onboarding-database-driver-install.test.ts +0 -112
- package/frontend-vue/tests/onboarding-database-engines.test.ts +0 -142
- package/frontend-vue/tests/onboarding-database-new-url.test.ts +0 -174
- package/frontend-vue/tests/onboarding-database-reload.test.ts +0 -229
- package/frontend-vue/tests/onboarding-database-tabs.test.ts +0 -184
- package/frontend-vue/tests/onboarding-database.test.ts +0 -540
- package/frontend-vue/tests/onboarding-deep-link.test.ts +0 -51
- package/frontend-vue/tests/onboarding-flow.test.ts +0 -204
- package/frontend-vue/tests/onboarding-install.test.ts +0 -62
- package/frontend-vue/tests/onboarding-mockups.test.ts +0 -86
- package/frontend-vue/tests/onboarding-scratch.test.ts +0 -70
- package/frontend-vue/tests/onboarding-widget.test.ts +0 -97
- package/frontend-vue/tests/palette-assistant.test.ts +0 -241
- package/frontend-vue/tests/panel-approvals.test.ts +0 -226
- package/frontend-vue/tests/panel-closed-conversation.test.ts +0 -53
- package/frontend-vue/tests/panel-mockup-prompt.test.ts +0 -238
- package/frontend-vue/tests/panel-modes.test.ts +0 -131
- package/frontend-vue/tests/panel-questions.test.ts +0 -151
- package/frontend-vue/tests/panel-states.test.ts +0 -252
- package/frontend-vue/tests/panel-tools.test.ts +0 -219
- package/frontend-vue/tests/session-gate.test.ts +0 -66
- package/frontend-vue/tests/sidecar-guest.test.ts +0 -81
- package/frontend-vue/tests/sidecar-status.test.ts +0 -117
- package/frontend-vue/tests/support/api-error-presenter.ts +0 -30
- package/frontend-vue/tests/support/database-connect.ts +0 -129
- package/frontend-vue/tests/support/dms-frontend-module.ts +0 -9
- package/frontend-vue/tests/support/dms-state.ts +0 -12
- package/frontend-vue/tests/support/fake-layout.ts +0 -119
- package/frontend-vue/tests/support/i18n.ts +0 -49
- package/frontend-vue/tests/support/onboarding-host.ts +0 -104
- package/frontend-vue/tests/support/onboarding.ts +0 -176
- package/frontend-vue/tests/support/panel-fixtures.ts +0 -155
- package/frontend-vue/tests/support/panel-harness.ts +0 -211
- package/frontend-vue/tests/support/setup-layout.ts +0 -3
- package/frontend-vue/tests/support/stand-ins/DmsBlockPreview.ts +0 -18
- package/frontend-vue/tests/support/stand-ins/DmsEmptyState.ts +0 -17
- package/frontend-vue/tests/support/stand-ins/DmsSegmentedControl.ts +0 -35
- package/frontend-vue/tests/support/stand-ins/DmsStatusPill.ts +0 -7
- package/frontend-vue/tests/support/stand-ins/OnboardingModal.ts +0 -13
- package/frontend-vue/tests/support/stand-ins/UBadge.ts +0 -7
- package/frontend-vue/tests/support/stand-ins/UButton.ts +0 -27
- package/frontend-vue/tests/support/stand-ins/UCheckbox.ts +0 -25
- package/frontend-vue/tests/support/stand-ins/UDropdownMenu.ts +0 -34
- package/frontend-vue/tests/support/stand-ins/UFormField.ts +0 -9
- package/frontend-vue/tests/support/stand-ins/UInput.ts +0 -16
- package/frontend-vue/tests/support/stand-ins/UKbd.ts +0 -7
- package/frontend-vue/tests/support/stand-ins/UModal.ts +0 -20
- package/frontend-vue/tests/support/stand-ins/UPopover.ts +0 -9
- package/frontend-vue/tests/support/stand-ins/UTabs.ts +0 -31
- package/frontend-vue/tests/support/stand-ins/UTextarea.ts +0 -19
- package/frontend-vue/tests/support/stubs.ts +0 -28
- package/frontend-vue/tests/views/api-data-reads.test.ts +0 -451
- package/frontend-vue/tests/views/api-error-presentation.test.ts +0 -89
- package/frontend-vue/tests/views/diff-view.test.ts +0 -167
- package/frontend-vue/tests/views/use-assistant.test.ts +0 -53
- package/frontend-vue/tests/views/view-format.test.ts +0 -59
- package/frontend-vue/vitest.config.ts +0 -33
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { computed, nextTick, type Ref, ref } from "vue";
|
|
3
|
-
import {
|
|
4
|
-
createSidecarStatusController,
|
|
5
|
-
type SidecarInfoPayload,
|
|
6
|
-
type SidecarInfoRead,
|
|
7
|
-
} from "../app/runtime/sidecar-status";
|
|
8
|
-
|
|
9
|
-
type Answer = SidecarInfoPayload | Error;
|
|
10
|
-
|
|
11
|
-
interface FakeRead extends SidecarInfoRead {
|
|
12
|
-
/** The polling interval the controller asks for. */
|
|
13
|
-
interval: Readonly<Ref<number>>;
|
|
14
|
-
reads: () => number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** `useApiData` as the controller uses it: each read takes the next answer. */
|
|
18
|
-
function fakeRead(answers: Answer[]) {
|
|
19
|
-
let opened: FakeRead | undefined;
|
|
20
|
-
const open = (interval: Readonly<Ref<number>>): SidecarInfoRead => {
|
|
21
|
-
const data = ref<SidecarInfoPayload | null>(null);
|
|
22
|
-
const error = ref<unknown>(null);
|
|
23
|
-
const status = ref<"idle" | "pending" | "done">("idle");
|
|
24
|
-
let count = 0;
|
|
25
|
-
const refresh = async (): Promise<void> => {
|
|
26
|
-
status.value = "pending";
|
|
27
|
-
await Promise.resolve();
|
|
28
|
-
const answer = answers[Math.min(count, answers.length - 1)];
|
|
29
|
-
count += 1;
|
|
30
|
-
if (answer instanceof Error) error.value = answer;
|
|
31
|
-
else {
|
|
32
|
-
data.value = answer ?? null;
|
|
33
|
-
error.value = null;
|
|
34
|
-
}
|
|
35
|
-
status.value = "done";
|
|
36
|
-
};
|
|
37
|
-
opened = {
|
|
38
|
-
data,
|
|
39
|
-
error,
|
|
40
|
-
pending: computed(() => status.value === "pending"),
|
|
41
|
-
execute: refresh,
|
|
42
|
-
refresh,
|
|
43
|
-
interval,
|
|
44
|
-
reads: () => count,
|
|
45
|
-
};
|
|
46
|
-
return opened;
|
|
47
|
-
};
|
|
48
|
-
return { open, read: () => opened! };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
describe("sidecar status", () => {
|
|
52
|
-
it("reports connected from the status alone, and keeps no port or credential", async () => {
|
|
53
|
-
const { open, read } = fakeRead([{ isRunning: true }]);
|
|
54
|
-
const controller = createSidecarStatusController(open);
|
|
55
|
-
expect(await controller.init()).toBe(true);
|
|
56
|
-
expect(controller.getStatus()).toBe("connected");
|
|
57
|
-
expect(read().interval.value).toBe(0);
|
|
58
|
-
expect(Object.keys(controller)).not.toContain("getPort");
|
|
59
|
-
expect(Object.keys(controller)).not.toContain("getClientToken");
|
|
60
|
-
controller.dispose();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("re-probes when the channel drops, and reports connected once the sidecar answers", async () => {
|
|
64
|
-
const { open, read } = fakeRead([{ isRunning: true }]);
|
|
65
|
-
const statuses: string[] = [];
|
|
66
|
-
const controller = createSidecarStatusController(open);
|
|
67
|
-
await controller.init();
|
|
68
|
-
controller.subscribe((status) => statuses.push(status));
|
|
69
|
-
controller.reportChannelDown();
|
|
70
|
-
await vi.waitFor(() => expect(statuses.at(-1)).toBe("connected"));
|
|
71
|
-
expect(statuses).toEqual(["connected", "reviving", "connected"]);
|
|
72
|
-
expect(read().reads()).toBe(2);
|
|
73
|
-
controller.dispose();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("polls through the read's interval, backing off while the sidecar comes back, and stops once it runs", async () => {
|
|
77
|
-
const { open, read } = fakeRead([
|
|
78
|
-
{ isRunning: false },
|
|
79
|
-
new Error("Bad Gateway"),
|
|
80
|
-
{ isRunning: true },
|
|
81
|
-
]);
|
|
82
|
-
const controller = createSidecarStatusController(open);
|
|
83
|
-
expect(await controller.init()).toBe(true);
|
|
84
|
-
expect(controller.getStatus()).toBe("reviving");
|
|
85
|
-
expect(read().interval.value).toBe(500);
|
|
86
|
-
await read().refresh();
|
|
87
|
-
expect(read().interval.value).toBe(1000);
|
|
88
|
-
await read().refresh();
|
|
89
|
-
await nextTick();
|
|
90
|
-
expect(controller.getStatus()).toBe("connected");
|
|
91
|
-
expect(read().interval.value).toBe(0);
|
|
92
|
-
controller.dispose();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("stops polling once the sidecar gives up", async () => {
|
|
96
|
-
const { open, read } = fakeRead([{ hasGivenUp: true }]);
|
|
97
|
-
const controller = createSidecarStatusController(open);
|
|
98
|
-
await controller.init();
|
|
99
|
-
expect(controller.getStatus()).toBe("unavailable");
|
|
100
|
-
expect(read().interval.value).toBe(0);
|
|
101
|
-
controller.dispose();
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("does not show the assistant when spawning is disabled, and polls nothing", async () => {
|
|
105
|
-
const { open, read } = fakeRead([{ disabled: true }]);
|
|
106
|
-
const controller = createSidecarStatusController(open);
|
|
107
|
-
expect(await controller.init()).toBe(false);
|
|
108
|
-
expect(read().interval.value).toBe(0);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("does not show the assistant when the first probe fails", async () => {
|
|
112
|
-
const { open, read } = fakeRead([new Error("Not Found")]);
|
|
113
|
-
const controller = createSidecarStatusController(open);
|
|
114
|
-
expect(await controller.init()).toBe(false);
|
|
115
|
-
expect(read().interval.value).toBe(0);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ref } from "vue";
|
|
2
|
-
import { afterEach, vi } from "vitest";
|
|
3
|
-
import { useApiErrorPresenter } from "../../../node_modules/@antelopejs/dms/frontend-vue/layers/dms-core/app/composables/useApiErrorPresenter";
|
|
4
|
-
|
|
5
|
-
afterEach(() => vi.unstubAllEnvs());
|
|
6
|
-
|
|
7
|
-
export function installApiErrorPresenter() {
|
|
8
|
-
vi.stubEnv("SSR", false);
|
|
9
|
-
const add = vi.fn(() => ({ id: "notice" }));
|
|
10
|
-
const messages: Record<string, string> = {
|
|
11
|
-
"error.read_only_demo": "This demo is read-only.",
|
|
12
|
-
"error.500.description": "Something went wrong.",
|
|
13
|
-
"dms_assistant.views.error.description":
|
|
14
|
-
"Could not load the assistant's data.",
|
|
15
|
-
"dms_assistant.views.unavailable.description":
|
|
16
|
-
"The assistant is not running.",
|
|
17
|
-
};
|
|
18
|
-
vi.stubGlobal("useToast", () => ({ add }));
|
|
19
|
-
vi.stubGlobal("getPluginI18n", () => ({
|
|
20
|
-
i18n: {
|
|
21
|
-
tm: (key: string) =>
|
|
22
|
-
Object.hasOwn(messages, key) ? messages[key] : null,
|
|
23
|
-
rt: (message: string) => message,
|
|
24
|
-
},
|
|
25
|
-
}));
|
|
26
|
-
const presented = ref(new WeakMap<object, string | number | null>());
|
|
27
|
-
vi.stubGlobal("useDmsState", () => presented);
|
|
28
|
-
vi.stubGlobal("useApiErrorPresenter", useApiErrorPresenter);
|
|
29
|
-
return { add };
|
|
30
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { mount, type VueWrapper } from "@vue/test-utils";
|
|
2
|
-
import { vi } from "vitest";
|
|
3
|
-
import { defineComponent } from "vue";
|
|
4
|
-
import {
|
|
5
|
-
type DatabaseConnect,
|
|
6
|
-
useDatabaseConnect,
|
|
7
|
-
} from "../../app/onboarding/connect-database";
|
|
8
|
-
import type { ConnectMemory } from "../../app/onboarding/connect-memory";
|
|
9
|
-
import type { ProjectConfigStep } from "../../builder/app/runtime/database-types";
|
|
10
|
-
import { memoryConnects } from "./onboarding";
|
|
11
|
-
|
|
12
|
-
export const URL = "postgres://app:secret@db.example.com/shop";
|
|
13
|
-
|
|
14
|
-
export const LISTED = {
|
|
15
|
-
id: "shop",
|
|
16
|
-
engine: "postgresql",
|
|
17
|
-
version: "16",
|
|
18
|
-
database: "shop",
|
|
19
|
-
role: "reader",
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const READER = {
|
|
23
|
-
reachable: true,
|
|
24
|
-
latencyMs: 4,
|
|
25
|
-
user: "reader",
|
|
26
|
-
canRead: true,
|
|
27
|
-
canWrite: false,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const WRITER = { ...READER, user: "owner", canWrite: true };
|
|
31
|
-
|
|
32
|
-
export const PROJECT = {
|
|
33
|
-
modules: [] as string[],
|
|
34
|
-
self: "dms",
|
|
35
|
-
databasePins: [],
|
|
36
|
-
dmsDatabase: "dms-database",
|
|
37
|
-
ownDatabase: "mongodb",
|
|
38
|
-
interfaceDatabase: "0.3.4",
|
|
39
|
-
drivers: {
|
|
40
|
-
postgres: { package: "@antelopejs/postgres", version: ">=0.2.6 <0.4.0" },
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export function analysisWith(open: unknown[]) {
|
|
45
|
-
return {
|
|
46
|
-
id: "job1",
|
|
47
|
-
status: "done",
|
|
48
|
-
progress: {},
|
|
49
|
-
proposal: {
|
|
50
|
-
connection: "shop",
|
|
51
|
-
module: "m",
|
|
52
|
-
database: { engine: "postgresql", role: "reader", writes: "none" },
|
|
53
|
-
resources: [],
|
|
54
|
-
excluded: [],
|
|
55
|
-
open,
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function fakeBuilder(overrides: Record<string, unknown> = {}) {
|
|
61
|
-
let analysis: unknown = null;
|
|
62
|
-
const analyseDatabase = vi.fn(
|
|
63
|
-
async (_connection: string, _module: string, _schemas?: string[]) => ({
|
|
64
|
-
ok: true,
|
|
65
|
-
data: {},
|
|
66
|
-
}),
|
|
67
|
-
);
|
|
68
|
-
const configureProject = vi.fn(
|
|
69
|
-
async (
|
|
70
|
-
_steps: ProjectConfigStep[],
|
|
71
|
-
_dryRun: boolean,
|
|
72
|
-
_variables?: unknown,
|
|
73
|
-
) => ({
|
|
74
|
-
ok: true,
|
|
75
|
-
}),
|
|
76
|
-
);
|
|
77
|
-
const api = {
|
|
78
|
-
checkConnection: vi.fn(async () => READER),
|
|
79
|
-
projectModules: async () => PROJECT,
|
|
80
|
-
configureProject,
|
|
81
|
-
failure: (error: unknown) => ({
|
|
82
|
-
detail: error instanceof Error ? error.message : String(error),
|
|
83
|
-
}),
|
|
84
|
-
databaseConnection: async () => ({ wiring: { variable: "SHOP_URL" } }),
|
|
85
|
-
databaseConnections: async () => [LISTED],
|
|
86
|
-
latestAnalysis: async () =>
|
|
87
|
-
analysis === null ? { ok: false } : { ok: true, data: analysis },
|
|
88
|
-
analyseDatabase,
|
|
89
|
-
reloadDue: async () => ({ due: false }),
|
|
90
|
-
...overrides,
|
|
91
|
-
};
|
|
92
|
-
return {
|
|
93
|
-
api,
|
|
94
|
-
analyseDatabase,
|
|
95
|
-
configureProject,
|
|
96
|
-
setAnalysis: (next: unknown) => {
|
|
97
|
-
analysis = next;
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
let wrapper: VueWrapper | undefined;
|
|
103
|
-
|
|
104
|
-
export function mountConnect(
|
|
105
|
-
api: unknown,
|
|
106
|
-
memory: ConnectMemory = memoryConnects(),
|
|
107
|
-
): DatabaseConnect {
|
|
108
|
-
let connect: DatabaseConnect | undefined;
|
|
109
|
-
wrapper = mount(
|
|
110
|
-
defineComponent({
|
|
111
|
-
setup() {
|
|
112
|
-
connect = useDatabaseConnect(api as never, memory);
|
|
113
|
-
return () => null;
|
|
114
|
-
},
|
|
115
|
-
}),
|
|
116
|
-
);
|
|
117
|
-
if (connect === undefined) throw new Error("the host did not set up");
|
|
118
|
-
return connect;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function schemaCheck(connect: DatabaseConnect) {
|
|
122
|
-
return connect.checks.value.find((check) => check.key === "schema");
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** Unmounts the host of the last `mountConnect`, as a closed popup or a reload of the page does. */
|
|
126
|
-
export function unmountConnect(): void {
|
|
127
|
-
wrapper?.unmount();
|
|
128
|
-
wrapper = undefined;
|
|
129
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// The renderer's runtime (`#dms/frontend-module`), which only the generated
|
|
2
|
-
// application provides: the suites that import a view mock what they use.
|
|
3
|
-
export function useDmsRoute(): never {
|
|
4
|
-
throw new Error("Mock #dms/frontend-module in the suite that needs it");
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function useDmsRouter(): never {
|
|
8
|
-
throw new Error("Mock #dms/frontend-module in the suite that needs it");
|
|
9
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ref } from "vue";
|
|
2
|
-
|
|
3
|
-
/** The DMS's shared state, by key, as `useDmsState` hands it out. */
|
|
4
|
-
export const dmsState = new Map<string, { value: unknown }>();
|
|
5
|
-
|
|
6
|
-
/** Stands in for `#dms/frontend-module` in a suite that starts the onboarding. */
|
|
7
|
-
export const dmsModule = {
|
|
8
|
-
useDmsState: (key: string, init: () => unknown) => {
|
|
9
|
-
if (!dmsState.has(key)) dmsState.set(key, ref(init()));
|
|
10
|
-
return dmsState.get(key);
|
|
11
|
-
},
|
|
12
|
-
};
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
type ResizeCallback = () => void;
|
|
2
|
-
|
|
3
|
-
const observers = new Set<FakeResizeObserver>();
|
|
4
|
-
const pendingScrollEvents = new Set<() => void>();
|
|
5
|
-
const layoutPasses = new Set<() => void>();
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* jsdom has no layout, so no resize ever happens by itself: a test reports
|
|
9
|
-
* one with `settleLayout`, as the browser does once per frame.
|
|
10
|
-
*/
|
|
11
|
-
class FakeResizeObserver {
|
|
12
|
-
private readonly targets = new Set<Element>();
|
|
13
|
-
|
|
14
|
-
constructor(private readonly callback: ResizeCallback) {
|
|
15
|
-
observers.add(this);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
observe(target: Element): void {
|
|
19
|
-
this.targets.add(target);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
unobserve(target: Element): void {
|
|
23
|
-
this.targets.delete(target);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
disconnect(): void {
|
|
27
|
-
this.targets.clear();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
deliver(): void {
|
|
31
|
-
if (this.targets.size > 0) this.callback();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function installResizeObserver(): void {
|
|
36
|
-
Reflect.set(globalThis, "ResizeObserver", FakeResizeObserver);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function dispatchPendingScrollEvents(): void {
|
|
40
|
-
for (const dispatch of [...pendingScrollEvents]) dispatch();
|
|
41
|
-
pendingScrollEvents.clear();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* A frame: scroll events fire first, then layout runs and the browser clamps
|
|
46
|
-
* or anchors the scroll position, then resizes are reported, and the scroll
|
|
47
|
-
* events layout caused fire at the start of the next frame.
|
|
48
|
-
*/
|
|
49
|
-
export function settleLayout(): void {
|
|
50
|
-
dispatchPendingScrollEvents();
|
|
51
|
-
for (const pass of layoutPasses) pass();
|
|
52
|
-
for (const observer of [...observers]) observer.deliver();
|
|
53
|
-
dispatchPendingScrollEvents();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface FakeScroller {
|
|
57
|
-
/** Height of what the list draws, beside one row height per message. */
|
|
58
|
-
extraContentPx: number;
|
|
59
|
-
viewportPx: number;
|
|
60
|
-
distanceFromBottom: () => number;
|
|
61
|
-
/** A scroll to `scrollTop` and the event it fires, from any source. */
|
|
62
|
-
scrollTo: (scrollTop: number) => void;
|
|
63
|
-
/**
|
|
64
|
-
* Content above the viewport shrinks by `px` at the next layout, and scroll
|
|
65
|
-
* anchoring moves the scroll position up by as much to keep the view still.
|
|
66
|
-
*/
|
|
67
|
-
collapseAbove: (px: number) => void;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const ROW_PX = 100;
|
|
71
|
-
|
|
72
|
-
/** Gives a scroll container the geometry a browser would compute. */
|
|
73
|
-
export function fakeScroller(el: HTMLElement): FakeScroller {
|
|
74
|
-
let scrollTop = 0;
|
|
75
|
-
let reportedTop = 0;
|
|
76
|
-
let anchorShiftPx = 0;
|
|
77
|
-
const dispatchScroll = (): void => {
|
|
78
|
-
el.dispatchEvent(new Event("scroll"));
|
|
79
|
-
};
|
|
80
|
-
const scroller: FakeScroller = {
|
|
81
|
-
extraContentPx: 0,
|
|
82
|
-
viewportPx: 400,
|
|
83
|
-
distanceFromBottom: () => el.scrollHeight - el.scrollTop - el.clientHeight,
|
|
84
|
-
scrollTo: (target) => {
|
|
85
|
-
dispatchPendingScrollEvents();
|
|
86
|
-
el.scrollTop = target;
|
|
87
|
-
dispatchPendingScrollEvents();
|
|
88
|
-
},
|
|
89
|
-
collapseAbove: (px) => {
|
|
90
|
-
scroller.extraContentPx -= px;
|
|
91
|
-
anchorShiftPx -= px;
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
const maxTop = (): number =>
|
|
95
|
-
Math.max(0, el.scrollHeight - scroller.viewportPx);
|
|
96
|
-
layoutPasses.add(() => {
|
|
97
|
-
scrollTop = Math.min(Math.max(0, el.scrollTop + anchorShiftPx), maxTop());
|
|
98
|
-
anchorShiftPx = 0;
|
|
99
|
-
if (scrollTop === reportedTop) return;
|
|
100
|
-
reportedTop = scrollTop;
|
|
101
|
-
pendingScrollEvents.add(dispatchScroll);
|
|
102
|
-
});
|
|
103
|
-
Object.defineProperties(el, {
|
|
104
|
-
clientHeight: { get: () => scroller.viewportPx },
|
|
105
|
-
scrollHeight: {
|
|
106
|
-
get: () =>
|
|
107
|
-
el.querySelectorAll("li").length * ROW_PX + scroller.extraContentPx,
|
|
108
|
-
},
|
|
109
|
-
scrollTop: {
|
|
110
|
-
get: () => Math.min(scrollTop, maxTop()),
|
|
111
|
-
set: (value: number) => {
|
|
112
|
-
scrollTop = Math.min(Math.max(0, value), maxTop());
|
|
113
|
-
reportedTop = scrollTop;
|
|
114
|
-
pendingScrollEvents.add(dispatchScroll);
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
return scroller;
|
|
119
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { ref } from "vue";
|
|
2
|
-
import type {
|
|
3
|
-
ChatI18n,
|
|
4
|
-
TranslateParams,
|
|
5
|
-
} from "../../app/chat/composables/useChatI18n";
|
|
6
|
-
import en from "../../i18n/locales/dms-assistant-panel-en-GB.json";
|
|
7
|
-
|
|
8
|
-
type Messages = Record<string, unknown>;
|
|
9
|
-
|
|
10
|
-
const PLURAL_SEPARATOR = " | ";
|
|
11
|
-
|
|
12
|
-
function lookup(messages: Messages, key: string): string | null {
|
|
13
|
-
const value = key
|
|
14
|
-
.split(".")
|
|
15
|
-
.reduce<unknown>(
|
|
16
|
-
(node, part) =>
|
|
17
|
-
node !== null && typeof node === "object"
|
|
18
|
-
? (node as Messages)[part]
|
|
19
|
-
: undefined,
|
|
20
|
-
messages,
|
|
21
|
-
);
|
|
22
|
-
return typeof value === "string" ? value : null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** vue-i18n's default choice: two forms are singular/plural, three add zero. */
|
|
26
|
-
function choose(forms: string[], count: number): string {
|
|
27
|
-
if (forms.length === 2) return forms[count === 1 ? 0 : 1];
|
|
28
|
-
return forms[Math.min(count, forms.length - 1)];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function interpolate(text: string, params: TranslateParams = {}): string {
|
|
32
|
-
return text.replace(/\{(\w+)\}/g, (match, name: string) =>
|
|
33
|
-
name in params ? String(params[name]) : match,
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** The panel's English strings behind the chat's translator, as in the dashboard. */
|
|
38
|
-
export function createTestI18n(messages: Messages = en): ChatI18n {
|
|
39
|
-
return {
|
|
40
|
-
t: (key, params, plural) => {
|
|
41
|
-
const text = lookup(messages, key);
|
|
42
|
-
if (text === null) return key;
|
|
43
|
-
const forms = text.split(PLURAL_SEPARATOR);
|
|
44
|
-
const form = plural === undefined ? forms[0] : choose(forms, plural);
|
|
45
|
-
return interpolate(form, params);
|
|
46
|
-
},
|
|
47
|
-
locale: ref("en-GB"),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { type Ref, ref, shallowRef } from "vue";
|
|
2
|
-
import { SERVER_EVENT_TYPES } from "../../app/chat/constants/protocol";
|
|
3
|
-
import {
|
|
4
|
-
type OnboardingHost,
|
|
5
|
-
startOnboarding,
|
|
6
|
-
} from "../../app/onboarding/install";
|
|
7
|
-
import { PREFERENCES_KEY } from "../../app/onboarding/preferences";
|
|
8
|
-
import { CHANNEL_STATUS_CONNECTED } from "../../app/runtime/constants";
|
|
9
|
-
import { dmsState } from "./dms-state";
|
|
10
|
-
import { CLAUDE_LOGIN, onboardingState } from "./onboarding";
|
|
11
|
-
|
|
12
|
-
export const WIDGET_ID = "dms-assistant:onboarding";
|
|
13
|
-
export const CONVERSATION = { id: "c1", title: "Orders", updatedAtMs: 1 };
|
|
14
|
-
|
|
15
|
-
export interface RegisteredWidget {
|
|
16
|
-
id: string;
|
|
17
|
-
onSelectEvent?: string;
|
|
18
|
-
badge?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function widget(): RegisteredWidget | undefined {
|
|
22
|
-
const widgets = dmsState.get("dms-app-widgets")?.value as
|
|
23
|
-
| RegisteredWidget[]
|
|
24
|
-
| undefined;
|
|
25
|
-
return widgets?.find((entry) => entry.id === WIDGET_ID);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface Backend {
|
|
29
|
-
stateAnswers: Array<() => Promise<unknown>>;
|
|
30
|
-
conversations: Array<typeof CONVERSATION>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function startWithBackend(
|
|
34
|
-
backend: Backend,
|
|
35
|
-
query: Record<string, string> = {},
|
|
36
|
-
) {
|
|
37
|
-
const messageListeners: Array<(message: object) => void> = [];
|
|
38
|
-
const route = ref({ path: "/", query });
|
|
39
|
-
const provided = shallowRef(null) as OnboardingHost["provided"];
|
|
40
|
-
const host: OnboardingHost = {
|
|
41
|
-
session: {
|
|
42
|
-
api: {
|
|
43
|
-
get: async (path: string) => {
|
|
44
|
-
if (path === "/ai/onboarding") {
|
|
45
|
-
const next = backend.stateAnswers.shift();
|
|
46
|
-
if (next === undefined) throw new Error("no more answers");
|
|
47
|
-
return next();
|
|
48
|
-
}
|
|
49
|
-
throw Object.assign(new Error("not found"), { statusCode: 404 });
|
|
50
|
-
},
|
|
51
|
-
post: async () => undefined,
|
|
52
|
-
},
|
|
53
|
-
chat: {
|
|
54
|
-
onMessage: (listener: (message: object) => void) => {
|
|
55
|
-
messageListeners.push(listener);
|
|
56
|
-
return () => undefined;
|
|
57
|
-
},
|
|
58
|
-
onReady: () => () => undefined,
|
|
59
|
-
getStatus: () => CHANNEL_STATUS_CONNECTED,
|
|
60
|
-
send: () => {
|
|
61
|
-
messageListeners.forEach((listener) =>
|
|
62
|
-
listener({
|
|
63
|
-
type: SERVER_EVENT_TYPES.CONVERSATION_LIST,
|
|
64
|
-
conversations: backend.conversations,
|
|
65
|
-
}),
|
|
66
|
-
);
|
|
67
|
-
return true;
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
holdStream: () => () => undefined,
|
|
71
|
-
} as unknown as OnboardingHost["session"],
|
|
72
|
-
router: {
|
|
73
|
-
currentRoute: route as Ref<{
|
|
74
|
-
path: string;
|
|
75
|
-
query: Record<string, string>;
|
|
76
|
-
}>,
|
|
77
|
-
replace: async () => undefined,
|
|
78
|
-
},
|
|
79
|
-
provided,
|
|
80
|
-
canConnectDatabase: true,
|
|
81
|
-
userId: () => "owner-1",
|
|
82
|
-
appMounted: Promise.resolve(),
|
|
83
|
-
runWithContext: (callback) => callback(),
|
|
84
|
-
};
|
|
85
|
-
const stop = startOnboarding(host);
|
|
86
|
-
return { provided, stop };
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export const UNFINISHED = async () =>
|
|
90
|
-
onboardingState({ claude: CLAUDE_LOGIN }, { bootId: "boot-1" });
|
|
91
|
-
|
|
92
|
-
/** A browser that has seen this server start's popup and asked not to see it again at startup. */
|
|
93
|
-
export function silenceStartup(): void {
|
|
94
|
-
dmsState.clear();
|
|
95
|
-
window.localStorage.setItem(
|
|
96
|
-
PREFERENCES_KEY,
|
|
97
|
-
JSON.stringify({ dontShow: true, seenBootId: "boot-1" }),
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export function resetBrowser(): void {
|
|
102
|
-
window.localStorage.clear();
|
|
103
|
-
window.history.pushState({}, "", "/");
|
|
104
|
-
}
|