diff --git a/apps/backend/src/app/api/latest/internal/mcp-review/update-qa-entry/route.ts b/apps/backend/src/app/api/latest/internal/mcp-review/update-qa-entry/route.ts index 66bf5529d..38fb8ee7d 100644 --- a/apps/backend/src/app/api/latest/internal/mcp-review/update-qa-entry/route.ts +++ b/apps/backend/src/app/api/latest/internal/mcp-review/update-qa-entry/route.ts @@ -34,8 +34,14 @@ export const POST = createSmartRouteHandler({ const token = getEnvVariable("STACK_MCP_LOG_TOKEN"); const editor = user.display_name ?? user.primary_email ?? user.id; const qaId = BigInt(body.qaId); - await callReducerStrict("update_qa_entry", [token, qaId, body.question, body.answer, editor]); - await callReducerStrict("set_qa_published", [token, qaId, body.publish]); + await callReducerStrict("update_qa_entry_with_publish", [ + token, + qaId, + body.question, + body.answer, + body.publish, + editor, + ]); return { statusCode: 200, diff --git a/apps/internal-tool/spacetimedb/src/index.ts b/apps/internal-tool/spacetimedb/src/index.ts index 8265b5a97..d90fafbc3 100644 --- a/apps/internal-tool/spacetimedb/src/index.ts +++ b/apps/internal-tool/spacetimedb/src/index.ts @@ -491,6 +491,36 @@ export const set_qa_published = spacetimedb.reducer( } ); +export const update_qa_entry_with_publish = spacetimedb.reducer( + { + token: t.string(), + qaId: t.u64(), + question: t.string(), + answer: t.string(), + publish: t.bool(), + editedBy: t.string(), + }, + (ctx, args) => { + if (args.token !== EXPECTED_LOG_TOKEN) { + throw new SenderError('Invalid log token'); + } + const row = ctx.db.qaEntries.id.find(args.qaId); + if (row == null) { + throw new SenderError('QA entry not found for qaId: ' + args.qaId.toString()); + } + ctx.db.qaEntries.id.update({ + ...row, + question: args.question, + answer: args.answer, + lastEditedBy: args.editedBy, + lastEditedAt: ctx.timestamp, + published: args.publish, + firstPublishedAt: args.publish ? (row.firstPublishedAt ?? ctx.timestamp) : row.firstPublishedAt, + lastPublishedAt: args.publish ? ctx.timestamp : row.lastPublishedAt, + }); + } +); + // Text-only edit. Doesn't touch publish state. export const update_qa_entry = spacetimedb.reducer( { diff --git a/apps/internal-tool/src/module_bindings/index.ts b/apps/internal-tool/src/module_bindings/index.ts index c87ebba56..ccf68258e 100644 --- a/apps/internal-tool/src/module_bindings/index.ts +++ b/apps/internal-tool/src/module_bindings/index.ts @@ -50,6 +50,7 @@ import UnmarkHumanReviewedReducer from "./unmark_human_reviewed_reducer"; import UpdateAiQueryCostReducer from "./update_ai_query_cost_reducer"; import UpdateMcpQaReviewReducer from "./update_mcp_qa_review_reducer"; import UpdateQaEntryReducer from "./update_qa_entry_reducer"; +import UpdateQaEntryWithPublishReducer from "./update_qa_entry_with_publish_reducer"; import UpsertQaFromCallReducer from "./upsert_qa_from_call_reducer"; // Import all procedure arg schemas @@ -124,6 +125,7 @@ const reducersSchema = __reducers( __reducerSchema("update_ai_query_cost", UpdateAiQueryCostReducer), __reducerSchema("update_mcp_qa_review", UpdateMcpQaReviewReducer), __reducerSchema("update_qa_entry", UpdateQaEntryReducer), + __reducerSchema("update_qa_entry_with_publish", UpdateQaEntryWithPublishReducer), __reducerSchema("upsert_qa_from_call", UpsertQaFromCallReducer), ); diff --git a/apps/internal-tool/src/module_bindings/types/reducers.ts b/apps/internal-tool/src/module_bindings/types/reducers.ts index 5bd31367f..6df999db6 100644 --- a/apps/internal-tool/src/module_bindings/types/reducers.ts +++ b/apps/internal-tool/src/module_bindings/types/reducers.ts @@ -22,6 +22,7 @@ import UnmarkHumanReviewedReducer from "../unmark_human_reviewed_reducer"; import UpdateAiQueryCostReducer from "../update_ai_query_cost_reducer"; import UpdateMcpQaReviewReducer from "../update_mcp_qa_review_reducer"; import UpdateQaEntryReducer from "../update_qa_entry_reducer"; +import UpdateQaEntryWithPublishReducer from "../update_qa_entry_with_publish_reducer"; import UpsertQaFromCallReducer from "../upsert_qa_from_call_reducer"; export type AddManualQaParams = __Infer; @@ -40,5 +41,6 @@ export type UnmarkHumanReviewedParams = __Infer; export type UpdateMcpQaReviewParams = __Infer; export type UpdateQaEntryParams = __Infer; +export type UpdateQaEntryWithPublishParams = __Infer; export type UpsertQaFromCallParams = __Infer; diff --git a/apps/internal-tool/src/module_bindings/update_qa_entry_with_publish_reducer.ts b/apps/internal-tool/src/module_bindings/update_qa_entry_with_publish_reducer.ts new file mode 100644 index 000000000..c78aa1b05 --- /dev/null +++ b/apps/internal-tool/src/module_bindings/update_qa_entry_with_publish_reducer.ts @@ -0,0 +1,20 @@ +// 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 { + token: __t.string(), + qaId: __t.u64(), + question: __t.string(), + answer: __t.string(), + publish: __t.bool(), + editedBy: __t.string(), +};