Files
multica/packages/core/onboarding/queries.ts
Jiayuan Zhang a61a8ecfed feat(onboarding): merge About-you step, collect source after agents deliver value (#5786)
Flow drops from five steps to three: role + use_case merge into a
single About-you screen (one Skip covers both; Continue stamps skip
markers on whichever group was left unanswered), and the source
question leaves onboarding entirely.

Source is now collected only by the workspace source-backfill prompt,
which additionally waits until agents/squads have completed at least
SOURCE_BACKFILL_MIN_AGENT_DONE_ISSUES (3) issues in the workspace —
attribution is asked after Multica has visibly delivered value, not
before. The count rides a limit:1 issues query keyed under
issueKeys.all so realtime invalidations keep it fresh, enabled only
for users who still owe an answer.

Server: questionnaire complete() narrows to role + use_case so the
funnel step doesn't stall on the now-deferred source; a new
metrics-only onboarding_source_submitted event (+ Prometheus counter)
tracks the backfill prompt's answer/decline transition once per user.

Co-authored-by: Lambda <lambda@multica.ai>
Co-authored-by: multica-agent <github@multica.ai>
2026-07-23 01:57:44 +08:00

35 lines
1.3 KiB
TypeScript

import { queryOptions } from "@tanstack/react-query";
import { api } from "../api";
import { issueKeys } from "../issues/queries";
/**
* Count of issues in the workspace completed by an AI assignee (agent
* or squad). Sole consumer is the source-backfill gate: the prompt
* waits until the user has watched agents finish real work before
* asking the attribution question (SOURCE_BACKFILL_MIN_AGENT_DONE_ISSUES
* in `needs-backfill.ts`).
*
* `limit: 1` because only `total` matters — the issue rows themselves
* are discarded. Keyed under `issueKeys.all(wsId)` on purpose: issue
* mutations and realtime events invalidate that prefix, so the count
* refreshes as agents complete work and the prompt can appear without
* a reload. The query is expected to be `enabled` only for the small
* cohort that still owes a source answer, so the extra refetches don't
* follow users around forever.
*/
export function agentCompletedIssueCountOptions(wsId: string) {
return queryOptions({
queryKey: [...issueKeys.all(wsId), "agent-done-count"] as const,
queryFn: async () => {
const res = await api.listIssues({
workspace_id: wsId,
statuses: ["done"],
assignee_types: ["agent", "squad"],
limit: 1,
});
return res.total;
},
staleTime: 30_000,
});
}