Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions apps/server/src/orchestration-v2/ThreadSearch.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { assert, it } from "@effect/vitest";
import {
EnvironmentId,
EventId,
MessageId,
ProjectId,
Expand All @@ -16,6 +17,7 @@ import * as Fiber from "effect/Fiber";
import * as Layer from "effect/Layer";
import * as Path from "effect/Path";
import * as SqlClient from "effect/sql/SqlClient";
import { serializeAssistantCitation } from "@t3tools/shared/assistantCitations";

import * as SqlitePersistence from "../persistence/Sqlite.ts";
import * as ProjectionStore from "./ProjectionStore.ts";
Expand Down Expand Up @@ -178,6 +180,41 @@ it.layer(layerTest)("ThreadSearch", (it) => {
assert.deepEqual((yield* search.search({ query: "ne%le" })).matches, []);
}),
);

it.effect("shows a quoted assistant message as its text in the snippet", () =>
Effect.gen(function* () {
const projections = yield* ProjectionStore.ProjectionStoreV2;
const search = yield* ThreadSearch.ThreadSearch;
const project = ProjectId.make("project:search-quote");
const threadId = ThreadId.make("thread:quote");
const quote = serializeAssistantCitation({
version: 1,
environmentId: EnvironmentId.make("environment:local"),
threadId,
messageId: MessageId.make("quote-answer"),
text: "A lighthouse guides ships safely through the darkness.",
comment: "what are you talking about",
start: 0,
end: 54,
prefix: "",
suffix: "",
});
yield* createProject(project);
yield* Effect.forEach(
[thread(threadId, project), message(threadId, "quote", "user", `Look here: ${quote}`)],
projections.apply,
{ discard: true },
);

const result = yield* search.search({ query: "talking" });
assert.deepEqual(
result.matches.map((match) => match.snippet),
[
"Look here: A lighthouse guides ships safely through the darkness. Comment: what are you talking about",
],
);
}),
);
});

it.effect("searches on the reader worker while the writer is busy", () =>
Expand Down
3 changes: 2 additions & 1 deletion apps/server/src/orchestration-v2/ThreadSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as Layer from "effect/Layer";
import * as Schema from "effect/Schema";
import * as SqlClient from "effect/sql/SqlClient";
import * as SqlSchema from "effect/sql/SqlSchema";
import { assistantCitationsToPlainText } from "@t3tools/shared/assistantCitations";
import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";

export class ThreadSearchError extends Schema.TaggedError<ThreadSearchError>()(
Expand Down Expand Up @@ -154,7 +155,7 @@ export const make = Effect.gen(function* () {
threadId: row.threadId,
projectId: row.projectId,
source: row.source,
snippet: buildSearchSnippet(row.matchText, input.query),
snippet: buildSearchSnippet(assistantCitationsToPlainText(row.matchText), input.query),
messageCreatedAt: row.messageCreatedAt,
})),
};
Expand Down
Loading