Some checks are pending
CI / test (map[image:macos-latest name:macos], 1, 4) (push) Waiting to run
CI / test (map[image:macos-latest name:macos], 2, 4) (push) Waiting to run
CI / test (map[image:macos-latest name:macos], 3, 4) (push) Waiting to run
CI / test (map[image:macos-latest name:macos], 4, 4) (push) Waiting to run
CI / test (map[image:windows-latest name:windows], 1, 4) (push) Waiting to run
CI / test (map[image:windows-latest name:windows], 2, 4) (push) Waiting to run
CI / test (map[image:windows-latest name:windows], 3, 4) (push) Waiting to run
CI / test (map[image:windows-latest name:windows], 4, 4) (push) Waiting to run
CI / merge-reports (push) Blocked by required conditions
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import log from "electron-log";
|
|
import { createLoggedHandler } from "./safe_handle";
|
|
import {
|
|
appendSnippets,
|
|
readMeta,
|
|
retrieveContext,
|
|
updateRollingSummary,
|
|
rebuildIndex,
|
|
type SmartContextSnippet,
|
|
type SmartContextMeta,
|
|
} from "../utils/smart_context_store";
|
|
|
|
const logger = log.scope("smart_context_handlers");
|
|
const handle = createLoggedHandler(logger);
|
|
|
|
export interface UpsertSnippetsParams {
|
|
chatId: number;
|
|
snippets: Array<{
|
|
text: string;
|
|
source:
|
|
| { type: "message"; messageIndex?: number }
|
|
| { type: "code"; filePath: string }
|
|
| { type: "attachment"; name: string; mime?: string }
|
|
| { type: "other"; label?: string };
|
|
}>;
|
|
}
|
|
|
|
export interface RetrieveContextParams {
|
|
chatId: number;
|
|
query: string;
|
|
budgetTokens: number;
|
|
}
|
|
|
|
export function registerSmartContextHandlers() {
|
|
handle("sc:get-meta", async (_event, chatId: number): Promise<SmartContextMeta> => {
|
|
return readMeta(chatId);
|
|
});
|
|
|
|
handle(
|
|
"sc:upsert-snippets",
|
|
async (_event, params: UpsertSnippetsParams): Promise<number> => {
|
|
const count = await appendSnippets(params.chatId, params.snippets);
|
|
return count;
|
|
},
|
|
);
|
|
|
|
handle(
|
|
"sc:update-rolling-summary",
|
|
async (_event, params: { chatId: number; summary: string }): Promise<SmartContextMeta> => {
|
|
return updateRollingSummary(params.chatId, params.summary);
|
|
},
|
|
);
|
|
|
|
handle(
|
|
"sc:retrieve-context",
|
|
async (_event, params: RetrieveContextParams) => {
|
|
return retrieveContext(params.chatId, params.query, params.budgetTokens);
|
|
},
|
|
);
|
|
|
|
handle("sc:rebuild-index", async (_event, chatId: number) => {
|
|
await rebuildIndex(chatId);
|
|
return { ok: true } as const;
|
|
});
|
|
}
|