MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / usePublishMutation

Function usePublishMutation

cli/src/hooks/use-publish-mutation.ts:23–60  ·  view source on GitHub ↗
(deps: UsePublishMutationDeps = {})

Source from the content-addressed store, hash-verified

21 * Uses TanStack Query mutation for proper state management
22 */
23export function usePublishMutation(deps: UsePublishMutationDeps = {}) {
24 const { handlePublish = defaultHandlePublish } = deps
25
26 const { setIsPublishing, setSuccessResult, setErrorResult } = usePublishStore(
27 useShallow((state) => ({
28 setIsPublishing: state.setIsPublishing,
29 setSuccessResult: state.setSuccessResult,
30 setErrorResult: state.setErrorResult,
31 })),
32 )
33
34 return useMutation({
35 mutationFn: async (agentIds: string[]) => {
36 setIsPublishing(true)
37 return handlePublish(agentIds)
38 },
39 onSuccess: (result) => {
40 if (result.success && result.publisherId && result.agents) {
41 setSuccessResult({
42 publisherId: result.publisherId,
43 agents: result.agents,
44 })
45 } else {
46 setErrorResult({
47 error: result.error || 'Unknown error',
48 details: result.details,
49 hint: result.hint,
50 })
51 }
52 },
53 onError: (error) => {
54 setErrorResult({
55 error: 'Publish failed',
56 details: error instanceof Error ? error.message : String(error),
57 })
58 },
59 })
60}

Callers 1

ChatFunction · 0.90

Calls 1

handlePublishFunction · 0.90

Tested by

no test coverage detected