diff --git a/apps/e2e/tests/spacetimedb/reducer-auth.test.ts b/apps/e2e/tests/spacetimedb/reducer-auth.test.ts index 775056d76..1498bc6cb 100644 --- a/apps/e2e/tests/spacetimedb/reducer-auth.test.ts +++ b/apps/e2e/tests/spacetimedb/reducer-auth.test.ts @@ -26,7 +26,6 @@ const ALL_MUTATING_REDUCERS: Array<{ name: string, args: unknown[] }> = [ args: ["corr", "chat", "sys", "q", "s", "model", false, opt(null), opt(null), "[]", "[]", "[]", "text", opt(null), opt(null), opt(null), opt(null), opt(null), opt(null), opt(null), 0, 0n, opt(null), opt(null)], }, { name: "update_ai_query_usage", args: ["corr", opt(null), opt(null), opt(null), opt(null), opt(null)] }, - { name: "upsert_qa_from_call", args: ["corr", "q", "a", false] }, { name: "delete_mcp_call_log", args: ["corr"] }, { name: "delete_ai_query_log", args: ["corr"] }, { name: "clear_mcp_qa_review", args: ["corr"] }, diff --git a/apps/internal-tool/scripts/pre-dev.mjs b/apps/internal-tool/scripts/pre-dev.mjs index 986288cdc..f58ad9f8c 100644 --- a/apps/internal-tool/scripts/pre-dev.mjs +++ b/apps/internal-tool/scripts/pre-dev.mjs @@ -28,7 +28,7 @@ const SIGNING_KEY_VAR = "HEXCLAVE_SPACETIMEDB_SIGNING_KEY_JWK"; async function ensureSigningKey() { const existing = existsSync(ENV_LOCAL) ? readFileSync(ENV_LOCAL, "utf8") : ""; - const line = existing.split(/\r?\n/).find((l) => l.startsWith(`${SIGNING_KEY_VAR}=`)); + const line = existing.split(/\r?\n/).filter((l) => l.startsWith(`${SIGNING_KEY_VAR}=`)).at(-1); const value = line ? line.slice(SIGNING_KEY_VAR.length + 1).trim() : ""; if (value !== "" && value !== "REPLACE_ME") return; diff --git a/apps/internal-tool/spacetimedb/src/index.ts b/apps/internal-tool/spacetimedb/src/index.ts index b73d2b693..66837f069 100644 --- a/apps/internal-tool/spacetimedb/src/index.ts +++ b/apps/internal-tool/spacetimedb/src/index.ts @@ -451,25 +451,6 @@ export const set_human_reviewed = spacetimedb.reducer( } ); -export const upsert_qa_from_call = spacetimedb.reducer( - { - correlationId: t.string(), - question: t.string(), - answer: t.string(), - publish: t.bool(), - }, - (ctx, args) => { - requireProjectMember(ctx.senderAuth); - upsertQaEntryFromCall(ctx, { - correlationId: args.correlationId, - question: args.question, - answer: args.answer, - publish: args.publish, - editedBy: actorName(ctx.senderAuth), - }); - } -); - export const upsert_qa_from_call_and_mark_reviewed = spacetimedb.reducer( { correlationId: t.string(), diff --git a/apps/internal-tool/src/lib/server/verified-qa.ts b/apps/internal-tool/src/lib/server/verified-qa.ts index 355c022e2..a9ec86c22 100644 --- a/apps/internal-tool/src/lib/server/verified-qa.ts +++ b/apps/internal-tool/src/lib/server/verified-qa.ts @@ -16,11 +16,16 @@ export async function getVerifiedQaContext(accessToken: string): Promise async function getVerifiedQaContextInner(accessToken: string): Promise { const rows = await callSql( accessToken, - "SELECT question, answer FROM published_qa" + "SELECT id, question, answer FROM published_qa" ); if (rows.length === 0) return ""; + const sorted = [...rows].sort((a, b) => { + const aId = readId(a); + const bId = readId(b); + return aId < bId ? -1 : aId > bId ? 1 : 0; + }); - const formatted = rows.map((row, i) => + const formatted = sorted.map((row, i) => `${i + 1}. Q: ${readString(row, "question")}\n A: ${readString(row, "answer")}` ).join("\n\n"); @@ -37,6 +42,14 @@ RULES: ${formatted}`; } + +function readId(row: Record): bigint { + const value = row["id"]; + if (typeof value === "number" && Number.isSafeInteger(value)) return BigInt(value); + if (typeof value === "string" && /^[0-9]+$/.test(value)) return BigInt(value); + throw new Error(`published_qa.id must be a u64 number or numeric string, got: ${typeof value}`); +} + function readString(row: Record, key: string): string { const value = row[key]; if (typeof value !== "string") { diff --git a/apps/internal-tool/src/module_bindings/index.ts b/apps/internal-tool/src/module_bindings/index.ts index f06107c98..73bf39f8d 100644 --- a/apps/internal-tool/src/module_bindings/index.ts +++ b/apps/internal-tool/src/module_bindings/index.ts @@ -46,7 +46,6 @@ import TouchSessionReducer from "./touch_session_reducer"; import UpdateAiQueryUsageReducer from "./update_ai_query_usage_reducer"; import UpdateMcpQaReviewReducer from "./update_mcp_qa_review_reducer"; import UpdateQaEntryWithPublishReducer from "./update_qa_entry_with_publish_reducer"; -import UpsertQaFromCallReducer from "./upsert_qa_from_call_reducer"; import UpsertQaFromCallAndMarkReviewedReducer from "./upsert_qa_from_call_and_mark_reviewed_reducer"; // Import all procedure arg schemas @@ -105,7 +104,6 @@ const reducersSchema = __reducers( __reducerSchema("update_ai_query_usage", UpdateAiQueryUsageReducer), __reducerSchema("update_mcp_qa_review", UpdateMcpQaReviewReducer), __reducerSchema("update_qa_entry_with_publish", UpdateQaEntryWithPublishReducer), - __reducerSchema("upsert_qa_from_call", UpsertQaFromCallReducer), __reducerSchema("upsert_qa_from_call_and_mark_reviewed", UpsertQaFromCallAndMarkReviewedReducer), ); diff --git a/apps/internal-tool/src/module_bindings/types/reducers.ts b/apps/internal-tool/src/module_bindings/types/reducers.ts index cd97b3e9e..caafc55ac 100644 --- a/apps/internal-tool/src/module_bindings/types/reducers.ts +++ b/apps/internal-tool/src/module_bindings/types/reducers.ts @@ -18,7 +18,6 @@ import TouchSessionReducer from "../touch_session_reducer"; import UpdateAiQueryUsageReducer from "../update_ai_query_usage_reducer"; import UpdateMcpQaReviewReducer from "../update_mcp_qa_review_reducer"; import UpdateQaEntryWithPublishReducer from "../update_qa_entry_with_publish_reducer"; -import UpsertQaFromCallReducer from "../upsert_qa_from_call_reducer"; import UpsertQaFromCallAndMarkReviewedReducer from "../upsert_qa_from_call_and_mark_reviewed_reducer"; export type AddManualQaParams = __Infer; @@ -33,6 +32,5 @@ export type TouchSessionParams = __Infer; export type UpdateAiQueryUsageParams = __Infer; export type UpdateMcpQaReviewParams = __Infer; export type UpdateQaEntryWithPublishParams = __Infer; -export type UpsertQaFromCallParams = __Infer; export type UpsertQaFromCallAndMarkReviewedParams = __Infer; diff --git a/apps/internal-tool/src/module_bindings/upsert_qa_from_call_reducer.ts b/apps/internal-tool/src/module_bindings/upsert_qa_from_call_reducer.ts deleted file mode 100644 index fbedc3840..000000000 --- a/apps/internal-tool/src/module_bindings/upsert_qa_from_call_reducer.ts +++ /dev/null @@ -1,18 +0,0 @@ -// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE -// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. - -/* eslint-disable */ -/* tslint:disable */ -import { - TypeBuilder as __TypeBuilder, - t as __t, - type AlgebraicTypeType as __AlgebraicTypeType, - type Infer as __Infer, -} from "spacetimedb"; - -export default { - correlationId: __t.string(), - question: __t.string(), - answer: __t.string(), - publish: __t.bool(), -};