Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Include a canonical web URL with each session search hit (#2365)

Regan Bellb1a53b823f1d
diff --git a/src/api/app-search.ts b/src/api/app-search.ts
index 7c2573530..605dc65d6 100644
--- a/src/api/app-search.ts
+++ b/src/api/app-search.ts
@@ -3,31 +3,36 @@ import { createCoreSearch, type BackendSearchHit, type SearchBackend } from "../
import { createIntersectionBackend } from "../search/backends.ts";
import { matchesSearchTerms, searchSnippet, searchTerms } from "../sessions/entry-search.ts";
import type { Principal } from "../types.ts";
+import { conversationWebUrl } from "../util/conversation-links.ts";
import { collectBytes } from "../util/bytes.ts";
import type { App, AppDeps } from "./app-types.ts";
import type { AppHelpers } from "./app-helpers.ts";
-function conversationBackend(app: App): SearchBackend {
+function conversationBackend(app: App, publicWebUrl: string | undefined): SearchBackend {
return createIntersectionBackend({
name: "conversations",
key: (hit) => hit.id,
searchForPrincipal: async (principal, query, limit) =>
- (await app.searchSessions(principal.id, query, limit)).map((hit) => ({
- id: `${hit.sessionId}:${hit.seq}`,
- type: "conversation" as const,
- ...(hit.title ? { title: hit.title } : {}),
- snippet: hit.snippet,
- createdAt: hit.createdAt,
- metadata: {
- sessionId: hit.sessionId,
- seq: hit.seq,
- scopeId: hit.scopeId,
- entryType: hit.entryType,
- ...(hit.surface ? { surface: hit.surface } : {}),
- ...(hit.channelName ? { channelName: hit.channelName } : {}),
- ...(hit.author ? { author: hit.author } : {}),
- },
- })),
+ (await app.searchSessions(principal.id, query, limit)).map((hit) => {
+ const url = conversationWebUrl(publicWebUrl, hit.sessionId);
+ return {
+ id: `${hit.sessionId}:${hit.seq}`,
+ type: "conversation" as const,
+ ...(hit.title ? { title: hit.title } : {}),
+ snippet: hit.snippet,
+ ...(url ? { url } : {}),
+ createdAt: hit.createdAt,
+ metadata: {
+ sessionId: hit.sessionId,
+ seq: hit.seq,
+ scopeId: hit.scopeId,
+ entryType: hit.entryType,
+ ...(hit.surface ? { surface: hit.surface } : {}),
+ ...(hit.channelName ? { channelName: hit.channelName } : {}),
+ ...(hit.author ? { author: hit.author } : {}),
+ },
+ };
+ }),
});
}
function searchableFile(mimetype: string, name: string): boolean {
@@ -140,7 +145,7 @@ export function createSearchMethods(
error instanceof Error ? error.message : String(error),
),
};
- const conversationsBackend = conversationBackend(app);
+ const conversationsBackend = conversationBackend(app, deps.publicWebUrl);
const core = createCoreSearch(
[conversationsBackend, ...(slack ? [slack] : []), fileBackend(deps, app, helpers)],
options,
diff --git a/test/session-search-tool.test.ts b/test/session-search-tool.test.ts
index 6d3b800a0..5a0aed977 100644
--- a/test/session-search-tool.test.ts
+++ b/test/session-search-tool.test.ts
@@ -17,7 +17,9 @@ const alice: Principal = { id: "[email protected]", type: "internal" };
const bob: Principal = { id: "[email protected]", type: "internal" };
test("session search reuses indexed search with audience intersection, tenure windows and bounded references", async () => {
- const { app, sessions } = buildApp(testConfig({ dataDir: mkdtempSync(join(tmpdir(), "session-search-tool-")) }));
+ const { app, sessions } = buildApp(
+ testConfig({ dataDir: mkdtempSync(join(tmpdir(), "session-search-tool-")), publicWebUrl: "https://qm.example" }),
+ );
const scope = scopeId("group", "room");
const current = await sessions.getOrCreateByThread("web:room", "group", scope);
const source = await sessions.getOrCreateByThread("web:source", "group", scopeId("group", "source"));
@@ -74,8 +76,8 @@ test("session search reuses indexed search with audience intersection, tenure wi
assert.deepEqual(result.failedBackends, []);
assert.equal(result.hits.length, 1);
assert.deepEqual(
- result.hits.map((h) => [h.metadata?.sessionId, h.metadata?.seq, h.snippet]),
- [[source.id, shared.seq, "memo shared"]],
+ result.hits.map((h) => [h.metadata?.sessionId, h.metadata?.seq, h.snippet, h.url]),
+ [[source.id, shared.seq, "memo shared", `https://qm.example/s/${source.id}`]],
);
assert.equal((await tools.search!({ query: "memo shared", limit: 1 })).hits.length, 1);
assert.deepEqual((await app.search("private-only", [bob])).hits, []);