Merge branch 'fix-tests-suite-loop'
# Conflicts: # package-lock.json # packages/server/src/server/speech/speech-config-resolver.ts # packages/server/src/shared/tool-call-display.ts
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { __setAttachmentStoreForTests, getAttachmentStore } from "./store";
|
||||
|
||||
describe("attachment store", () => {
|
||||
afterEach(() => {
|
||||
__setAttachmentStoreForTests(null);
|
||||
});
|
||||
|
||||
it("creates the default web attachment store without runtime module resolution errors", async () => {
|
||||
const store = await getAttachmentStore();
|
||||
|
||||
expect(store.storageType).toBe("web-indexeddb");
|
||||
});
|
||||
});
|
||||
@@ -7,20 +7,20 @@ let attachmentStorePromise: Promise<AttachmentStore> | null = null;
|
||||
async function createAttachmentStore(): Promise<AttachmentStore> {
|
||||
if (Platform.OS === "web") {
|
||||
if (isTauriEnvironment()) {
|
||||
const { createDesktopAttachmentStore } = require(
|
||||
"@/desktop/attachments/desktop-attachment-store"
|
||||
const { createDesktopAttachmentStore } = await import(
|
||||
"../desktop/attachments/desktop-attachment-store"
|
||||
);
|
||||
return createDesktopAttachmentStore();
|
||||
}
|
||||
|
||||
const { createIndexedDbAttachmentStore } = require(
|
||||
"@/attachments/web/indexeddb-attachment-store"
|
||||
const { createIndexedDbAttachmentStore } = await import(
|
||||
"./web/indexeddb-attachment-store"
|
||||
);
|
||||
return createIndexedDbAttachmentStore();
|
||||
}
|
||||
|
||||
const { createNativeFileAttachmentStore } = require(
|
||||
"@/attachments/native/native-file-attachment-store"
|
||||
const { createNativeFileAttachmentStore } = await import(
|
||||
"./native/native-file-attachment-store"
|
||||
);
|
||||
return createNativeFileAttachmentStore();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,14 @@ export type SelectBestConnectionInput = {
|
||||
probeByConnectionId: Map<string, ConnectionProbeState>;
|
||||
};
|
||||
|
||||
function getAvailableLatency(input: {
|
||||
connectionId: string;
|
||||
probeByConnectionId: Map<string, ConnectionProbeState>;
|
||||
}): number | null {
|
||||
const probe = input.probeByConnectionId.get(input.connectionId);
|
||||
return probe?.status === "available" ? probe.latencyMs : null;
|
||||
}
|
||||
|
||||
export function selectBestConnection(
|
||||
input: SelectBestConnectionInput
|
||||
): string | null {
|
||||
@@ -23,37 +31,22 @@ export function selectBestConnection(
|
||||
return null;
|
||||
}
|
||||
|
||||
const available = candidates
|
||||
.map((candidate, index) => ({ candidate, index }))
|
||||
.filter(({ candidate }) => {
|
||||
const probe = probeByConnectionId.get(candidate.connectionId);
|
||||
return probe?.status === "available";
|
||||
let bestConnectionId: string | null = null;
|
||||
let bestLatency: number | null = null;
|
||||
|
||||
for (const candidate of candidates) {
|
||||
const latencyMs = getAvailableLatency({
|
||||
connectionId: candidate.connectionId,
|
||||
probeByConnectionId,
|
||||
});
|
||||
|
||||
const byLatency = (left: { candidate: ConnectionCandidate; index: number }, right: { candidate: ConnectionCandidate; index: number }) => {
|
||||
const leftProbe = probeByConnectionId.get(left.candidate.connectionId);
|
||||
const rightProbe = probeByConnectionId.get(right.candidate.connectionId);
|
||||
|
||||
const leftLatency =
|
||||
leftProbe && leftProbe.status === "available"
|
||||
? leftProbe.latencyMs
|
||||
: Number.POSITIVE_INFINITY;
|
||||
const rightLatency =
|
||||
rightProbe && rightProbe.status === "available"
|
||||
? rightProbe.latencyMs
|
||||
: Number.POSITIVE_INFINITY;
|
||||
|
||||
if (leftLatency === rightLatency) {
|
||||
return left.index - right.index;
|
||||
}
|
||||
|
||||
return leftLatency - rightLatency;
|
||||
};
|
||||
|
||||
if (available.length === 0) {
|
||||
return null;
|
||||
if (latencyMs === null) {
|
||||
continue;
|
||||
}
|
||||
if (bestLatency === null || latencyMs < bestLatency) {
|
||||
bestConnectionId = candidate.connectionId;
|
||||
bestLatency = latencyMs;
|
||||
}
|
||||
}
|
||||
|
||||
const sorted = available.sort(byLatency);
|
||||
return sorted[0]!.candidate.connectionId;
|
||||
return bestConnectionId;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,15 @@ export interface SidebarShortcutModel {
|
||||
shortcutIndexByWorkspaceKey: Map<string, number>
|
||||
}
|
||||
|
||||
function createShortcutTarget(
|
||||
workspace: SidebarWorkspaceEntry,
|
||||
): SidebarShortcutWorkspaceTarget {
|
||||
return {
|
||||
serverId: workspace.serverId,
|
||||
workspaceId: workspace.workspaceId,
|
||||
}
|
||||
}
|
||||
|
||||
export function buildSidebarShortcutModel(input: {
|
||||
projects: SidebarProjectEntry[]
|
||||
collapsedProjectKeys: ReadonlySet<string>
|
||||
@@ -30,19 +39,15 @@ export function buildSidebarShortcutModel(input: {
|
||||
}
|
||||
|
||||
for (const workspace of project.workspaces) {
|
||||
visibleTargets.push({
|
||||
serverId: workspace.serverId,
|
||||
workspaceId: workspace.workspaceId,
|
||||
})
|
||||
const shortcutNumber =
|
||||
shortcutTargets.length < maxShortcuts ? shortcutTargets.length + 1 : null
|
||||
if (shortcutNumber !== null) {
|
||||
shortcutTargets.push({
|
||||
serverId: workspace.serverId,
|
||||
workspaceId: workspace.workspaceId,
|
||||
})
|
||||
shortcutIndexByWorkspaceKey.set(workspace.workspaceKey, shortcutNumber)
|
||||
visibleTargets.push(createShortcutTarget(workspace))
|
||||
|
||||
if (shortcutTargets.length >= maxShortcuts) {
|
||||
continue
|
||||
}
|
||||
|
||||
const shortcutNumber = shortcutTargets.length + 1
|
||||
shortcutTargets.push(createShortcutTarget(workspace))
|
||||
shortcutIndexByWorkspaceKey.set(workspace.workspaceKey, shortcutNumber)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user